WebGL Tip: With THREE.MeshFaceMaterial, each face can have its own unique orientation

I am currently exploring the world of 3D graphics by creating a building in WebGL using the THREE.js framework.

Having no prior experience with tools like DX or OpenGL, I dove right into the project with the following code snippet.

var windowTexture = THREE.ImageUtils.loadTexture('./images/windowside.png');

windowTexture.repeat.set(1,2);

var windowMaterial = new THREE.MeshBasicMaterial({ map: windowTexture});

var buildingMaterial = new THREE.MeshFaceMaterial([
    windowMaterial,
    windowMaterial,
    windowMaterial,
    windowMaterial,
    topMaterial,
    new THREE.MeshBasicMaterial({color: 0xffff00})
]);

Next, I created a BoxGeometry for my building.

var geometry = new THREE.BoxGeometry(0.3, 0.3, 1);
var building = new THREE.Mesh(geometry, buildingMaterial);

After adding it to the scene, I noticed that the texture on the box was not as expected. The orientation seemed off, resulting in an incorrect display:

https://i.sstatic.net/t9dN0.png

It appears that each face has a different orientation, prompting me to question if I am employing the correct technique for applying multiple textures to a Box.

Is there a more optimal approach for achieving this?

How can I rectify this issue and ensure the textures align correctly?

Any guidance would be greatly appreciated. Thank you!

Answer №1

In order to achieve a different texture arrangement, you can try the following:

var buildingMaterials = new THREE.MeshFaceMaterial([
    doorMaterial,
    wallMaterial,
    new THREE.MeshBasicMaterial({color: 0x00ff00}),
    new THREE.MeshBasicMaterial({color: 0xffff00}),
    roofMaterial,    
    windowMaterial
]);

http://jsfiddle.net/abc123/

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

The Formik form is not being populated with data from the API

While working on a functional component in ReactJS, I created a simple form using Formik. The input fields in my form are supposed to fetch data from an API when the component mounts. To achieve this, I utilized fetch and useEffect. However, after fetching ...

Is there a way to prevent scrolling back up a webpage after reaching the end of the page?

Creating a new webpage and looking to prevent users from scrolling back up once they've reached the bottom of the page. While allowing vertical scrolling as usual, I want to restrict their ability to scroll back to the top after reaching the end of th ...

Is there a way to remove the initial word from a sentence?

Tue 26-Jul-2011 Looking to remove the initial word "Mon" using javascript with jQuery. Any suggestions on accomplishing this task? ...

Looking to personalize the MUI - datatable's toolbar and place the pagination at the top?

I successfully managed to hide the toolbar icon, but I am struggling with positioning pagination from bottom to top. Additionally, I am attempting to add two buttons (reset and apply) in the view-Column toolbar without any success in customizing the class. ...

Web Security Vulnerability: Cross Site Scripting Detected

In our code, we are aiming to prevent XSS (Cross Site Scripting) attacks. However, the solution may involve a combination of JS (JavaScript) and HTML escaping, which could prove to be quite challenging. Below is a snippet that closely resembles our code: ...

An issue arising from code in Python, JavaScript, HTML, and CSS

I am currently studying JavaScript and Python and have encountered an issue with my code. I wrote a script that is supposed to create a file and input data into it, but the recv_data function is not functioning correctly - the file is not being created. Ca ...

Caution notification using Javascript

Currently, I have integrated simple JavaScript code into my PHP code to show an alert message: <script type="text/javascript"> window.alert("Can not Send Messages ") </script> However, when the alert pops up, the original page vanishes. A ...

Is it true that all events in JavaScript go through capturing and bubbling phases?

My current project involves binding one eventListener to an <audio> element for the play event and another eventListener to its parent element for the same event. I've observed that the callback for the child element always gets executed, while ...

Mastering the art of redirection in Node.js

Encountering an issue with redirecting between directories - having trouble directing to another file in a different directory. Here is my directory structure: -views -add_user.jade -routes -index.js Attempting to redirect to add_user.jade from inde ...

What is the proper way to combine two arrays containing objects together?

I am faced with the challenge of merging arrays and objects. Here is an example array I am working with: [ { name: "test", sub: { name: "asdf", sub: {} } }, { name: "models", sub: {} } ] ...

Combining three APIs within an HTML website

Hey there! Currently, I am in the process of combining three APIs into my HTML website. However, there seems to be an issue where each subsequent API integration overrides the previous one, and only the final one functions properly. In the code snippet b ...

Issue with Javascript Promise causing failure to populate list with objects

app.get('/zones/:id/experiences', function(req,res) { var zone_key = req.params.id; var recent = []; var ref = firebase.database().ref('participants/'+zone_key+'/experiences'); ref.on("value", function(snapshot) { ...

Activate the Masterpage menu to emphasize its current state

I am currently utilizing the AdminLTE template on my website. One issue I have encountered is with the menu and its child menus. When redirecting to different pages using image buttons, the menu collapses back to its original state. While navigating throu ...

The textarea field activates a select event listener whenever a button or link is clicked within the DOM

My DOM structure is pretty straightforward, consisting of a textarea, some buttons, and links. I've attached a select eventlistener to the textarea to monitor text selection by the user. const summary = document.getElementById("summary"); summary?. ...

Is there a way for me to utilize the imported data from one component in the context API using an arrow function?

I am trying to utilize placeInfo, reviews, detailsInfo, news from a data file. Instead of using value='hello', I am unsure if I can directly use it like this: value={placeInfo, reviews, detailsInfo, news}, as it is producing an error. Should I st ...

What is the best way to alter the header in Django when a user is authenticated?

In my project, I have two headers: header.html and headersuccess.html. When a user is logged in, I need to change the header from header.html to headersuccess.html. How can I implement that? Here is an excerpt from my views.py file where I render loginsuc ...

Enhancing Three.js interaction with the DOM (using linkify.js)

Having trouble making the click event work and linking a sphere with a URL using the latest version of three.js. Here is my code: // Code snippet will be here Any help or suggestions would be greatly appreciated. I'm still new to this! ...

Managing numerous requests simultaneously without causing one to delay or block the others

I am facing challenges when it comes to managing multiple client requests. Ideally, each route should be handled asynchronously, but I am struggling to handle one request after another without the previous one interfering with the next one. In the code sni ...

Ways to detect if there is a new database record and display it in the notification bar with an alert

In the Django framework, I am retrieving data through an AJAX request from a database like this: $.ajax({ url: '/activity/', type: 'GET', data:{}, success: function(data) { // alert(data); var div1 = doc ...

Loading and linking JavaScript and JSX files

Working with ReactJS has been smooth sailing when it's all contained in one file. I've been loading it using the code <script type="text/babel" src="js/test.js"></script>. For some reason, using "text/javascript" causes issues with r ...