The application of textures is not being done correctly

Trying to incorporate two textures - one for the wall and another for the floor. However, after rendering, only a solid color is displayed instead of the desired texture. Below is the configuration of my scene and camera:

    const tempScene = new THREE.Scene();
    tempScene.background = new THREE.Color(0x021D49);
    const ambient = new THREE.AmbientLight(0xffffff, 0.6);
    tempScene.add(ambient);
    const directionalLight = new THREE.DirectionalLight(0xfafafa, 0.6);
    directionalLight.position.set(0, 300, 300);
    tempScene.add(directionalLight);

    const tempCamera = new THREE.PerspectiveCamera(
      60,
      el.clientWidth / el.clientHeight,
      0.1,
      10000,
    );

    tempCamera.up.set(0, 0, 1);
    tempCamera.position.set(0, 300, 300);
    tempCamera.lookAt(0, 0, 0);
    const tempControls = new OrbitControls(tempCamera, el);
    tempControls.maxPolarAngle = Math.PI / 2;
    tempControls.minDistance = 10;
    tempControls.maxDistance = 500;
    tempControls.enablePan = false;

    const tempRenderer = new THREE.WebGLRenderer({ canvas: el, antialias: true });
    tempRenderer.setSize(el.clientWidth, el.clientHeight);
    tempRenderer.setPixelRatio(window.devicePixelRatio);
    tempRenderer.shadowMap.enabled = true;
    tempRenderer.shadowMap.type = THREE.PCFSoftShadowMap;
    tempRenderer.outputEncoding = THREE.sRGBEncoding;

Below is the code for applying textures:

      const floorTex = new THREE.TextureLoader().load(floorTexture);
      const wallMaterial = new THREE.MeshBasicMaterial({ map: wallTex, side: THREE.DoubleSide });
      const floorMaterial = new THREE.MeshStandardMaterial({ map: floorTex });
      const lineMaterial = new THREE.LineBasicMaterial({ color: 0x000000 });

        const wallGeometry = new THREE.BufferGeometry();
        const wallVertices = new Float32Array([
          -x1,
          y1,
          0, // vertex 1
          -x1,
          y1,
          10, // vertex 2
          -x2,
          y2,
          0, // vertex 3
          -x2,
          y2,
          10, // vertex 4
        ]);
        wallGeometry.setAttribute('position', new THREE.BufferAttribute(wallVertices, 3));
        wallGeometry.setIndex([0, 2, 1, 2, 3, 1]);
        const wall = new THREE.Mesh(wallGeometry, wallMaterial);
        const geo = new THREE.EdgesGeometry(wall.geometry);
        const wireframe = new THREE.LineSegments(geo, lineMaterial);
        wall.add(wireframe);
        wall.castShadow = true;
        wall.receiveShadow = true;
        scene!.add(wall);
        
        
       const floorGeometry = new THREE.Shape(floorPoints.map((point) => new THREE.Vector2(point[0],          point[1])));
      const shapeGeometry = new THREE.ShapeGeometry(floorGeometry);
      const floor = new THREE.Mesh(shapeGeometry, floorMaterial);
      floor.receiveShadow = true;
      scene!.add(floor);

Actual Rendering Preview

Expected Texture Appearance: floorTexture wallTexture

Answer №1

The texture for your wall is not being applied because you have not defined any texture coordinates for the wallGeometry. Make sure to include a uv buffer attribute next to the position attribute to hold this data.

It's unclear why the floor is also missing texture based on the provided code snippet. The ShapeGeometry instances typically come with texture coordinates, so it's possible there may be an issue with loading the texture.

Additionally, if you add

tempRenderer.outputEncoding = THREE.sRGBEncoding;
to your code, remember to set the encoding property of all color textures to THREE.sRGBEncoding as well. Failing to do so could result in an incomplete sRGB workflow.

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

Using Google App Script's pageToken to store attachments on Google Drive

Essentially, my goal is to save all attachments from received emails to a specific folder in Google Drive (mostly .PDF files). However, I've encountered a limitation with the search function which only allows me to retrieve up to 500 attached files. I ...

Adjust date by one day using the Datetimepicker tool

I have been attempting to adjust the date of my input by one day either forward or backwards, but I seem to be stuck and not making any progress. Take a look at my code: function function backDay() { var date = $('input#datetimepicker').va ...

What do you call a software application that relies on a dependency for its functioning?

As I work on updating a package, other software that relies on it as a dependency has led me to wonder what to call them from the perspective of the dependency. While not exactly peer dependencies due to the modular design of the dependency in question, I ...

Using a pre-defined function as a parameter will not function properly with the event listener

As a beginner, I recently attempted the following: ul.addEventListener("click", function(e) { console.log("Hi"); }); Surprisingly, this code worked just fine. I learned that the function used here is anonymous. However, when I tried ...

One common query is how to access an HTML element from JavaScript using its ID, particularly when the element belongs to a different HTML document

Following up on the question title: In addition, the HTML document is loaded into the parent element using AJAX in the following way: $.ajax({ url: 'calender.aspx', cache: false, dataType: "html", success: functi ...

What is the mechanism behind the workings of the requestAnimationFrame loop?

I'm currently studying the ins and outs of javascript and Three.js but I'm struggling to grasp the concept of how the requestAnimationFrame function operates. Could someone please break down the following code in simple terms for me? ( feel free ...

What could be causing my Ajax function to malfunction?

I've been attempting to incorporate a form that sends two javascript variables to a php script and displays the result in a new Div on the same page using an ajax function. Unfortunately, it's not functioning as expected. Here is the code snippe ...

What is the best way to save a token value to a JavaScript file on my local storage

Hello, I am new to Nodejs and have implemented passportjs token-based authentication. When a user logs in, a token is provided for each user. Now, I want to perform certain operations based on the users who have token values. For example, if a user wants t ...

Tips for managing multiple projects in Angular 7 simultaneously

Our team is currently working on an application with two separate workspaces. One workspace serves as the main project while the other is exported as a module to our private npm repository. To access this module, we retrieve it through our package.json f ...

Rotation of a point cloud geometry within three.js

After creating a geometry using specific x, y, z positions, I need to rotate this geometry around its own axis similar to how the earth rotates. I want the geometry to move, not the camera. Can anyone provide assistance? Here is the current code snippet: ...

Creating multiple instances of an object

When using Javascript, I am trying to create an object in the following way: var testObject = { value: "this is my initial value", setup: function() { value: "foo" } }; Now, my goal is to instantiate this object and have different val ...

Leveraging the wheelDelta property in the onmousewheel event handler with Script#

When working with Script#, I often utilize mouse events using the ElementEvent argument. However, one thing seems to be missing - the WheelDelta property for handling the onmousewheel event. Can anyone provide guidance on how to access this property in t ...

Troubleshooting the "missing checks.state argument" error in AUTH0 debugging

I recently launched my new NextJs blog application at on Vercel, but I'm encountering some issues with getting auth0 to function properly. Upon clicking the login button located in the top right corner of the screen, users are redirected to auth0 to ...

What is the process for integrating Socket io into an external JavaScript file that is connected to an HTML file?

Currently, I am utilizing node js, socket io, and express to develop a multiplayer web game. To begin, the server initiates and listens on port 2000. Upon visiting localhost:2000, the file lobby.html is transmitted using: //app.js const express = require ...

Challenges with 'this' reference in a requireif causing Vuelidate complications

     Need help with vuejs component using vuelidate and validations:     validations: {      invoice: {          dueDate: {              required,          },          tax: {              require ...

Showing a notification that is persistent and not dismissible

Hello everyone! I've been struggling with a problem on the RPS project for quite some time now. The issue arises when I try to display a message for a tie in the game, but I can't seem to find a solution to make it disappear when the round is not ...

Trigger the click event on a specific class selector to extract the corresponding ID

I have an HTML Table with each row: <table> <tr><td><a href='#' id='1' class='delete'>delete</a></td></tr> <tr><td><a href='#' id='2' class='de ...

Utilizing AngularJS to connect a dynamic result array to a table with varying layouts

I am struggling to bind a dynamic array result with a table using Angular JS in a different layout. Despite multiple attempts, I have not been successful in achieving the desired outcome. Any help or guidance would be greatly appreciated. var arr = [ ...

Use Typescript in combination with React/Redux to showcase a dynamic table on the

Looking to create a React TypeScript Redux application that showcases a table using an API endpoint provided at https://example.com/users The goal is to construct a table with 4 columns: Name, Email, City, and Company, utilizing the API response to popula ...

Occasionally, the function `Element.getElementByTag("mytag")` may come up empty

Here is the outer html of Element1 in CKeditor: <element1 id="s1"> <mytag>Test1</mytag> <span> </span> Some text <mytag>Test</mytag> <span> </span> <mytag>Test3</mytag> some text <span&g ...