Creating a unique texture for a custom geometry mesh using Three.js

I'm currently working on constructing a house geometry and applying various textures to the faces of the geometry. The framework I'm using is r55. However, I'm facing an issue where faces with materials generated from textures are not appearing, while those with simple color materials are showing up correctly. When I switch the material created from my roofTexture to a basic color material, the corresponding faces display as expected.

Highlighted below is the relevant section of my code:

var geom = new THREE.Geometry();

// Load the roof texture
var roofTexture = new THREE.ImageUtils.loadTexture('gfx/textures/roof.jpg');

// Configure the roof texture to repeat
roofTexture.wrapS = roofTexture.wrapT = THREE.RepeatWrapping;
roofTexture.repeat.set(10, 10);

// Materials
var materialArray = [];
materialArray.push(new THREE.MeshLambertMaterial({color: 0xD3E3F0 }));
materialArray.push(new THREE.MeshLambertMaterial({map: roofTexture}));

// Define base edges
var edge0 = new THREE.Vector2(obj.ridgeLength/2, -obj.buildingDepth/2);
var edge1 = new THREE.Vector2(obj.ridgeLength/2, obj.buildingDepth/2);
var edge2 = new THREE.Vector2(-obj.ridgeLength/2, obj.buildingDepth/2);
var edge3 = new THREE.Vector2(-obj.ridgeLength/2, -obj.buildingDepth/2);

// Floor
geom.vertices.push(new THREE.Vector3(edge0.x, -1, edge0.y));
geom.vertices.push(new THREE.Vector3(edge1.x, -1, edge1.y));
geom.vertices.push(new THREE.Vector3(edge2.x, -1, edge2.y));
geom.vertices.push(new THREE.Vector3(edge3.x, -1, edge3.y));

// Eave
geom.vertices.push(new THREE.Vector3(edge0.x, obj.eaveHeight, edge0.y));
geom.vertices.push(new THREE.Vector3(edge1.x, obj.eaveHeight, edge1.y));
geom.vertices.push(new THREE.Vector3(edge2.x, obj.eaveHeight, edge2.y));
geom.vertices.push(new THREE.Vector3(edge3.x, obj.eaveHeight, edge3.y));

// Ridge
geom.vertices.push(new THREE.Vector3(obj.ridgeLength/2, obj.ridgeHeight, 0));
geom.vertices.push(new THREE.Vector3(-obj.ridgeLength/2, obj.ridgeHeight, 0));


// Ground
geom.faces.push( new THREE.Face4(0, 0, 0, 0) );

// Front
geom.faces.push( new THREE.Face4(0, 3, 7, 4) );

// Left side
geom.faces.push( new THREE.Face4(0, 4, 5, 1) );

// Back
geom.faces.push( new THREE.Face4(1, 5, 6, 2) );

// Right side
geom.faces.push( new THREE.Face4(2, 6, 7, 3) );

// Left triangle
geom.faces.push( new THREE.Face3(4, 8, 5));

// Right triangle
geom.faces.push( new THREE.Face3(6, 9, 7));

// Front roof
geom.faces.push( new THREE.Face4(7, 9, 8, 4) );

// Back roof
geom.faces.push( new THREE.Face4(5, 8, 9, 6) );

// Assign materials to the faces
geom.faces[0].materialIndex = 0;
geom.faces[1].materialIndex = 0;
geom.faces[2].materialIndex = 0;
geom.faces[3].materialIndex = 0;
geom.faces[4].materialIndex = 0;
geom.faces[5].materialIndex = 0;
geom.faces[6].materialIndex = 0;
geom.faces[7].materialIndex = 1;
geom.faces[8].materialIndex = 1;

geom.computeFaceNormals();

obj.house = new THREE.Mesh( geom, new THREE.MeshFaceMaterial(materialArray) );
obj.house.doubleSided = true;
obj.house.castShadow = true;
obj.sun.shadowDarkness = 1.0;
obj.scene.add(obj.house);

Can you identify any errors in my approach?

Answer №1

It appears that the UV coordinates for your geometry are not properly set. Make sure to assign UV coordinates ranging from 0 to 1 when creating your own geometry. For example, you can assign UVs of (0.0, 0.0) to the lower left corner, (1.0, 0.0) to the lower right, (0.0, 1.0) to the top left, and (1.0, 1.0) to the top right. Referencing the PlaneGeometry.js file might help you understand how to correctly assign UVs.

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

What is the best way to link the :style attribute with object syntax and incorporate multiple background images?

I'm experiencing an issue trying to bind CSS style with the object syntax to an image. The style object includes the CSS property background which refers to multiple background images, but unfortunately, these images are not showing up. Template < ...

Adding a unique value to an array using JQuery when it does not already exist

In need of assistance with a function that is supposed to add values to an array if they do not already exist. var category_json = new Array(); $.ajax({ type: 'POST', url: "<?php ech ...

Using the Gmail API to retrieve the access token details by extracting the "code" parameter from the URL of a pop-up window

I am currently in the process of authenticating Gmail using OAuth2 for my web application. Upon receiving a URL from the server, the client opens a pop-up window with the following code: var win = window.open(data.google_oauth_url, `<h1>Gmail ...

The bespoke node package does not have an available export titled

No matter what I do, nothing seems to be effective. I have successfully developed and launched the following module: Index.ts : import ContentIOService from "./IOServices/ContentIOService"; export = { ContentIOService: ContentIOService, } ...

Steps for setting up single sign on in an Angular 2 application

Currently, I am working on a web application that has been developed using angular2. One of the requirements for this application is to incorporate a single sign-on feature, where users do not have to manually input their login credentials. Instead, the ap ...

React Modals: Only the modal component triggered by the first click will open, with no other modals opening

As a newcomer to StackOverflow, I apologize if my problem description is not clear. I am currently learning React and working on a course-search app as a project. The app filters courses based on user input from a JSON file and displays them in cards with ...

Using React.js to dynamically change a CSS class depending on a certain condition

I am trying to assign a CSS class to a div based on a specific condition. The issue I am facing is that it always takes the last condition. Below is the code snippet: When I run the code, I receive logos.length as 3 <div className= "${ (this.state. ...

NextAuth: JWT callback that returns an object

I've been working on a project using Next.js (11.1.2) + NextAuth (^4.0.5) + Strapi(3.6.8). The Next Auth credentials provider is functioning correctly. However, I need to access certain user information using the session. I attempted to do this by ut ...

I'm having trouble getting rid of this stubborn loader on the website

I am currently utilizing the following template: . My objective is to eliminate the preloader progress bar that displays the loading progress of the page in percentage. The files associated with this preloader are as follows: Loader CSS File - www[dot]the ...

The website displays perfectly in Atom, however, it is not functional in any web browser

My website is currently in the development phase, and I'm experiencing issues with certain div elements not positioning correctly once the site goes live. Specifically, the "Follow Us" tab at the bottom of the site, among other divs, has been affecte ...

Erase the white backdrop from the dragImage

Is there a way to remove the white outline that appears when dragging a draggable element from a dark background? I want to make it completely transparent. Here is a visual representation: https://i.sstatic.net/Eywf9.png Here is the code snippet: docume ...

What is the process for changing a DynamoDB table from PROVISIONED to PAY_PER_REQUEST using Node.js?

Currently, I have a DDB table set up with BillingMode: PROVISIONED and ProvisionedThroughput:{...}. My goal is to switch it to BillingMode: PAY_PER_REQUEST, but every time I attempt this change, I encounter the following error: TypeError: Cannot read prop ...

What is causing jQuery toggleClass to fail in removing a class?

I have successfully implemented a Skills accordion feature, but I am now trying to add a button that toggles all the skill sections at once. However, I am facing issues with jQuery not correctly adding or removing classes on the .accordion-trigger-all elem ...

Detection of numerous Google Analytics tags

To troubleshoot a client's Google Analytics account connected to their website, I decided to utilize the Tag assistant by Google extension. Upon running it, an alert popped up displaying "Multiple Google Analytics tags detected." One tag was the one I ...

Manipulating State in React: How to add a property to an object within an array within a component's state

Currently, I am retrieving an array of objects stored in the state, and I am attempting to include a new property to each of these objects. However, I am encountering a problem where even though I can see the new property being added to each object, when ...

Transmit blob information to node server using fetch, multer, and express

Currently facing an issue with sending a blob object to my node server. The scenario is that on the client side, I am recording some audio using MediaRecorder and then attempting to transmit the file to my server for further processing. saveButton.o ...

Simultaneous malfunction of two ajax forms

I have a dilemma with two boxes: one is called "min amount" and the other is called "max amount." Currently, if I input 100 in the max amount box, it will display products that are priced at less than $100. However, when I input an amount like $50 in the m ...

Sleek camera motion in three.js

I want to enhance the panorama equirectangular player by adding smooth camera movements. Is it possible to achieve a similar effect as in the cube example while maintaining the smooth transition without disrupting the movement when the mouse is clicked? ...

Is there a way to alter the camera's focal point in THREEJS to focus on a specific object already in the scene?

Currently, I am working with a scene extracted from a THREEJS example (https://threejs.org/examples/webgl_loader_fbx.html) that involves importing and displaying a threejs.json scene. The rendering of the scene works perfectly; I have a grid in place with ...

Creating a map with just a Button Click in React

I'm currently working on a weather app and making good progress. Now, I'm looking to display additional information when a button is clicked. I have a 5-day forecast and want to show the details for each day. I've managed to filter the data ...