A cube created in Three.js featuring a unique texture on each of its six faces

I'm attempting to generate a cube using three.js with unique textures on each face, resembling a dice. This is being developed in a sandbox environment where a rotating cube with dice images (1-6) on each side will be created. Once completed, I plan to integrate this into a browser-based game. While I have only tested this example in Chrome, I am considering switching to a canvas renderer for wider browser compatibility.

After exploring various questions on Stack Overflow and conducting extensive research online, I thought I had the solution (which seemed relatively straightforward), but I am struggling to make it work.

Although I am new to three.js, I have prior experience with JavaScript.

Some of the resources I consulted include:

Stack Overflow - three.js cube with different texture on each face

Stack Overflow - three.js cube with different texture faces

evanz - Test three.js cube

and enriquemorenotent.com - three.js building a cube with different materials on each face

Here is my code:

[Insert code snippet here]

The error I am encountering is:

Uncaught TypeError: Cannot read property 'map' of undefined 

on line 19546 of three.js (non-minified version) which refers to the bufferGuessUVType(material) function where 'material' is undefined. This suggests that there might be an issue with one or more of my material definitions.

I am using three.js r58.

Currently, there is only JavaScript code without any HTML or CSS components.

While I can successfully create a rotating cube with the same image on all sides, I am facing difficulties in assigning different images to each face, specifically images of dice dots from 1 to 6.

If necessary, I can create a fiddle with more time.

Answer №1

UPDATE: THREE.MultiMaterial is no longer recommended. Instead, you can now directly pass the materials array into the constructor. Here's how:

const box = new THREE.Mesh( new THREE.BoxGeometry( 562, 562, 562, 1, 1, 1 ), materials );

scene.add( box );

When using code snippets from the internet, exercise caution.

Always refer to the Migration Wiki for guidance on upgrading to the latest version.

Current version: three.js r.85

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

SyntaxError: End of input caught unexpectedly (NodeJS TCP server)

My simple tcp server has the capability to send and receive json data. Here is a snippet of my code: // Handling incoming messages from clients. socket.on('data', function (data) { var obj = JSON.parse(data); if(obj.type == "regis ...

Query key array failing to update when key is modified

Encountering an issue with the query key array not updating when the selected warehouse ID is changed. This causes useQuery to use outdated data instead of fetching new data for the updated warehouse ID. Struggling to figure out how to update the query k ...

What is the best way to organize and structure a node.js project for modularity?

In the process of developing a node.js project, I am adhering to the class constructor pattern as shown below: function my_class(x,y){ this.x = x; this.y = y; } The foundation of the project lies within the main.js file. It is imperative that any ...

What is the best way to include an icon before each option in a VuetifyJS combobox?

I'm looking to enhance the combobox feature in VuetifyJS by adding an icon before each option in the dropdown menu. Can someone guide me on how to achieve this functionality? You can check out a sample of the combobox on CodePen here: https://codepen. ...

Leveraging the power of the JQuery on and off function to add and delete specific event listeners

In my current code, I am utilizing the JQuery on method to link an event handler to the window object: $(window).on('resize', function(e){ /** my functional code goes here **/ e.stopPropagation(); }); The issue I am facing is that this ...

Sequential execution of multiple useState updates when an update triggers a re-render

Can you explain why the function setPeople is being executed after setFirstName, setEmail, and after the event handler has been exited? const [firstName, setFirstName] = useState(''); const [email, setEmail] = useState(''); const [peopl ...

Create an Interactive Menu Using JSON Data

Looking for guidance with angularjs as a beginner, I'm interested in creating a dynamic menu using JSON array. { "Pages": [{ "PageId": 1, "PageTitle": "Home", "PageContent": "Home Page Content", "MenuType": "MainMenu", "ParentMenu": null, "PageStatu ...

Adjust the hue as you scroll

I've been searching for a solution to this issue, but I haven't been able to make it work. My goal is to have the page header change from a transparent background to a red background as the user starts scrolling down the page. $(window).on("s ...

Using Jquery to loop through various select options within a designated container div

I am seeking a way to loop through multiple select options within a specific div using the jQuery each function. If any field is left empty during this iteration, I would like the loop to break and set the reqCourseFlag variable to 0. The current implement ...

What is the best way to solve the problem of Chrome auto-complete overlapping with labels in Vuetify?

When attempting to make a login form using outlined text fields in Vutify, there is an issue with Chrome autocomplete overlapping the labels. <v-text-field v-model="email" label="e-mail" name="email" outlined prep ...

Identify duplicate values in an array by comparing pairs of elements

If the array contains the data shown below: let array = [{ name: "Ramesh", SalseVersion: 10, MarketingCode: 11 }, { name: "Suresh", SalseVersion: 12, MarketingCode: 13 }, { name: "Siva", SalseVersion: 10, MarketingCode: 14 }, { na ...

Switch out a visual element for Dropzone.js

During my recent project, I utilized Dropzone.js for image uploads. However, I am now interested in transforming the dropzone area into an actual image. For instance, if there is a "featured image" attached to an article, users should be able to drag and ...

Unlimited Cycle using Vue Router Global Precautionary Measures

Currently, I am facing an issue with redirecting users using Firebase Auth and Vue Router. The problem arises when the Router redirects the user to '/' as it results in a blank white screen on the website. I am aware that there is an error in m ...

Is tsconfig.json Utilized by Gatsby When Using Typescript?

Many blog posts and the example on Gatsby JS's website demonstrate the use of a tsconfig.json file alongside the gatsby-plugin-typescript for TypeScript support in Gatsby. However, it seems like the tsconfig.json file is not actually utilized for conf ...

Parsing error: Unexpected character found at line 238, column 16. Consider using a loader suitable for this file format

Currently, I am attempting to integrate ArcballControls.js controls into my Vue.js application. I've noticed that this particular class contains functions that utilize arrow syntax, whereas every other class in the controls does not. This seems to be ...

How can a JavaScript function be imported into a React component from a location outside the src folder?

I have a utility function in my JavaScript utils.js file within the Django static files. I am looking to make this file accessible for use with React as well. I would like to import this file along with its functions into a React component. Here is an ex ...

In search of a resolution for the error message "multipart: NextPart: bufio: buffer full" while attempting to upload an image via a fetch post request. Can anyone provide guidance

What steps can be taken to resolve the issue "multipart: NextPart: bufio: buffer full" when using a fetch post request to upload an image? I have a feature on my website that allows users to upload profile pictures. I use a fetch post request for this pur ...

How can I ensure that the 'popover' remains visible when hovering over both the anchorEl and the popover itself?

Check out this example of using material-ui at https://material-ui.com/utils/popover/#mouse-over-interaction Follow the steps outlined in the example above for material-ui at https://material-ui.com/utils/popover/#mouse-over-interaction When testing t ...

Attempting to prevent the use of the <p> tag solely before the text

My toggle function is not working correctly in my FaQ section. When a user clicks on a topic, the bottom section should appear, but the <p> tag is being displayed across the entire line instead of just one word.. Here is an image to help illustrate ...

Navigating the waters of adding a CSS property to a jQuery variable pseudo selector

Is there a way to adjust the top position for $myClass both before and after? I attempted to do so with the following code: var $myClass = $(".myclass"); $myClass.filter(":before,:after").css("top",-23); ...