"Creating a unique Three.js cube by applying different textures on each face. Learn how to conceal edges and vertices for

I'm currently working on a project using Three.js where I want to create a Cube with unique images as textures on each face.

Is there a way for me to conceal the edges and vertices of the mesh?

Here's the code snippet:

var container, camera, scene, renderer, cube;

init();
animate();

function init(){
    container = document.getElementById('container');
    scene = new THREE.Scene();
    camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 1000);
    camera.position.y = 150;
    camera.position.z = 500;
    scene.add( camera );

    var materials = [];
    for ( var i = 0; i < 6; i ++ ) {
        materials.push( new THREE.MeshBasicMaterial( { map: THREE.ImageUtils.loadTexture( 'img/' + i + '.png') } ) );
    }

    cube = new THREE.Mesh( new THREE.CubeGeometry( 200, 200, 200, 5,5,5, materials ), new THREE.MeshFaceMaterial() );
    cube.position.y = 150;
    scene.add( cube );
    renderer = new THREE.CanvasRenderer();
    renderer.setSize( window.innerWidth, window.innerHeight);
    container.appendChild( renderer.domElement );
    }

function animate() {
    requestAnimationFrame( animate );
    render();
}

function render(){
    cube.rotation.y += 0.005;
    renderer.render( scene, camera );
}

Answer №1

modify the following code:

for ( var i = 0; i < 6; i ++ ) {
    materials.push( new THREE.MeshBasicMaterial( { map: THREE.ImageUtils.loadTexture( 'img/' + i + '.jpg') } ) );
}

by changing it to:

for ( var i = 0; i < 6; i ++ ) {
    materials.push( new THREE.MeshBasicMaterial( { map: THREE.ImageUtils.loadTexture( 'img/' + i + '.jpg'), overdraw: true } ) );
}

Answer №2

Modify the following line:

cube = new THREE.Mesh( new THREE.CubeGeometry( 200, 200, 200, 5,5,5, materials ), new THREE.MeshFaceMaterial() );

to this:

cube = new THREE.Mesh( new THREE.CubeGeometry( 200, 200, 200, 1,1,1, materials ), new THREE.MeshFaceMaterial() );

Answer №3

Consider utilizing a different render engine. Update the following line:

 renderer = new THREE.CanvasRenderer();

to this one:

 renderer = new THREE.WebGLRenderer();

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Rotating a sphere on an axis with Three.js by leveraging camera rotation values

I designed a unique control named SphericalControls. It is similar to the OrbitControls, but it maintains the camera at position 0,0,0 and instead rotates the camera on the x and y axes to explore a scene. This control is situated in the center of a Sphere ...

The Bootstrap navigation menu is functioning properly when opening, but has an issue when attempting

Creating a mirrored version of an HTML file using NuxtJS, I've included the following code snippet in the Navbar component for my NuxtJS project. <template> <section id="navigation-menu" class="menu menu3 cid-sLhoPz7Ycg" ...

The $scope variable is not retaining the value for the ng-repeat directive

I'm struggling to implement an ng-repeat on data fetched from an API in JSON format. The issue I'm facing is that even though I can see the data in $scope.wines when I console.log() before the function ends, the data seems to disappear by the end ...

Steps for retrieving the URL after redirecting from the current page to another with Puppeteer

My name is Aadarshvelu and I have recently started testing my web application code using Jest with Puppeteer. I have a page where all credentials are filled using Puppeteer. However, when the 'signBtn' button is clicked, the POST process starts. ...

What are some effective techniques for working with data in d3/Canvas JS?

In my work on a visualization dashboard, I am currently facing some challenges. I am torn between choosing d3js and canvasjs. While d3js offers great visuals and rich functionality, I lean towards canvas because of how easy it is to create charts. If you ...

Develop a custom autocomplete feature using Formik in React for selecting values from an array of objects

Looking to Add Autocomplete Functionality in Your React Application Using Formik for Seamless Selection of Single and Multiple Values from an Array of Objects? Take a Look at this Code snippet! [see image below] (https://i.stack.imgur.com/ekkAi.png) arra ...

What causes the JavaScript function to have an undefined return value?

I have written a function that is designed to determine the size of an image and return an object containing both the width and height. However, I am encountering an issue where the values for sz.width and sz.height are defined within the function but beco ...

Converting table rows into an array that consists of arrays of table data using jQuery

I want to form a list of table rows with each cell being represented as an element in an array of strings. ...

jquery survey quiz

Currently, I am attempting to develop a jQuery questionnaire, but my limited knowledge in the area is proving to be quite inadequate. So far, here is what I have: Upon clicking on "Questions," a pop-up window will appear with two questions. My goal is t ...

How can I recreate this image in 3D using three.js?

I have a tower image' - but i don't know how to replicate this for3dview using thethree.js` any assistance would be greatly appreciated! Here is the image : This is my attempt : $(function () { "use strict"; var container, scene, cam ...

The isotope plugin import failed, displaying the error message "The function $(container).isotope does not exist."

I've been struggling to get the Metafizzy Isotope plugin to work, but I'm having no success. The Network tab indicates that it's not loading properly. After installing isotope-layout and requiring it in my main-file.js, the code still doesn ...

When I use Console.log(appointment[0].apps.date), I receive a date as expected. However, when I attempt to use this date in my function, I encounter the error 'Cannot read property 'date' of undefined'

Every time I try to call my getDataPrevDay function, I keep getting the error message "Cannot read property 'date' of undefined." Strangely enough, when I log console.log(appointment[0].apps.date), it shows the correct date. const admin = ({data} ...

Dynamically load select options using Ajax

I'm a newcomer to javascript and ajax, and I'm working on implementing Ajax to display the current category on my HTML select in a CodeIgniter project. Below is the code snippet: HTML: <select class="form-control" name="category" id="categor ...

Accessing the session object within an Express middleware function is crucial for

This is my unique Express middleware setup: var app = express() .use(express.cookieParser()) .use(express.session({secret: 'HiddenSecret'})) .use(express.bodyParser()) .use(function displaySession(req, res, next) { consol ...

Navbar not displaying output in React JS

I followed a tutorial on YouTube to create a navbar using Bootstrap and React, but I'm facing issues with the output. The YouTube tutorial used HTML along with Bootstrap to make the navbar. Even though the classes are similar, all I can see is a small ...

Deactivate particular JavaScript when displaying a Bootstrap modal

On mobile devices, I have JavaScript that is preventing vertical panning on modals, resulting in users not being able to see all the modal content. Is there a way to disable this JavaScript when a modal is displayed? The following snippet of JavaScript a ...

Having difficulties implementing horizontal scrolling for the Tabs component in Material UI

I can't seem to enable horizontal scrolling for the Tabs in material UI. Here is the version of Material UI I am using: As the number of Tabs increases, they are becoming wider. I tried to set the width, but it ends up affecting the entire Tabs tab ...

Add a value in front of switchMap along with a Promise

Whenever a new value is emitted by this.selectedLanguage$, I need to emit a value that is calculated asynchronously. My current approach to this requirement involves the following code: public readonly languageCategories$ = this.selectedLanguage$.pipe( ...

Problem with communication between Android and JavaScript

Having an issue with my Android method that is being called from JavaScript to retrieve selected file path information from the phone gallery. The problem arises when I try to send the file path name back to the JavaScript method, as it always returns the ...

Efficiently uploading numerous SVGs in vue.js using vue-svg-loader

Is there a more efficient way to import multiple SVGs in a Vue component without having to individually import each one as suggested in the documentation? Check out vue-svg-loader documentation: <script> import Info from "@/assets/svgs/info.svg"; ...