Issue with texturing custom geometries in three.js: custom geometries are

There are two custom geometries that I created: Box2Geometry and StaticTestPentagonPlaneGeometry.

The Box2Geometry JSFiddle shows that the first geometry texturizes perfectly, while the StaticTestPentagonPlaneGeometry JSFiddle does not texturize properly. The fiddles are very similar, with the only difference being the geometries used. Despite trying to remove the emissive: 0xffffff property from the second geometry, the texturization issue remains.

In an attempt to showcase both geometries simultaneously, a third fiddle was created. However, this fiddle fails to render anything, leaving me to believe that the computing gods find it amusing.

Rendering result from the Box2Geometry fiddle:

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

Rendering result from the StaticTestPentagonPlaneGeometry fiddle:

https://i.sstatic.net/2Q1bY.png

Code snippet from the Box2Geometry JSFiddle:

"use strict";

// Code for Box2Geometry
// Includes scene setup, geometry creation, texture loading, material setup, and rendering logic
// Meticulously crafted by a diligent developer
<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
  </head>
  <body>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r73/three.js"></script>
    <script src="main.js"></script>
  </body>
</html>

Code snippet from the StaticTestPentagonPlaneGeometry JSFiddle:

"use strict";

// Code for StaticTestPentagonPlaneGeometry
// Includes scene setup, geometry creation, texture loading, material setup, and rendering logic
// Unfortunately facing texturization issues
// Will require divine intervention to rectify
<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
  </head>
  <body>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r73/three.js"></script>
    <script src="main.js"></script>
  </body>
</html>

Answer №1

Your facial normals are oriented in the incorrect direction (0, 0, -1). To rectify this, adjust the calculation for the normal like so:

normal.z *= -1;

Alternatively, for a more universal solution, you can switch the parameters when calling the .cross function. The code:

var normal    = planeVec1.cross(planeVec2).normalize();

Would then transform into:

var normal    = planeVec2.cross(planeVec1).normalize();

Lastly, you can simply request three.js to compute the face normals for you:

constructee.computeFaceNormals ();

It is necessary to eliminate the emissive component in order for this to function properly.

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

Troubles arising when trying to import a CSS file into a React Component without resorting to

https://i.sstatic.net/fNEuU.png After exploring the latest version of create-react-app, I discovered that there is no need to use the "npm run eject" command. When I tried that in the past, I struggled to locate the webpack.js file for modifications. htt ...

Ways to conceal the jqgrid thumbnail

I have a jqgrid that displays a large amount of dynamic data. I am looking for a way to hide the thumb of the vertical scrollbar in the jqgrid when scrolling using the mousewheel. Here is a basic example: var data = [ [48803, "DSK1", "", "02200220", "O ...

Execute supplementary build scripts during the angular build process

I've developed an Angular application that loads an iframe containing a basic html page (iframe.html) and a Vanilla JavaScript file (iframe.js). To facilitate this, I've placed these 2 files in the assets folder so that they are automatically cop ...

Guide on building a Vue Js input name field with string-variable schema

I have a project using VueJs and I am looking to extract JavaScript variables to create hidden fields. My goal is to set the name of the field based on the index of the variable, following a zig-zag naming schema. For example: <input type="text" nam ...

What is the best location to create the content for a sidebar?

Currently in the process of building my new website using express. The layout consists of various "sections" such as a blog, project information, and more. I want to have a unique sidebar next to the main content for each section. For instance, in the "blo ...

Troubleshooting: Issue with Passing Variable from Controller to Partial in Rails with AJAX

I am facing an issue with passing a variable from my controller to a partial asynchronously. My goal is to render a form on my view after the user selects an option from a drop-down menu. However, I keep encountering the following error: undefined local v ...

Issue arises after injecting HTML element into the DOM due to memory constraints and display inconsistencies

Upon executing the following script in Firefox... var d = $("<div class='test'></div>"); d.hide(); $("body").prepend(d); d.show(); ...and examining the HTML, the inserted element will have the style attribute: style="display: blo ...

What are some ways to enhance the opacity of a Material UI backdrop?

I'm looking to enhance the darkness of the material UI backdrop as its default appearance is not very dark. My goal is to make it dimmer and closer to black in color. ...

Troubles arising while using ng serve in Angular 2

I'm currently facing an issue during the installation process of an existing Angular application. When trying to run the application using the ng serve command, I encounter the following error message: The "@angular/compiler-cli" package was not prope ...

Can you explain the distinction between Array() and [] in Javascript, and when would it be preferable to use one over the other?

Similar Question: Understanding the difference between "new Array()" and "[]" in JavaScript array declaration When working with JavaScript, you have the option to create a new array using: var arr = new Array(); or simply using: var arr2 = []; Wha ...

The parent's setState does not trigger the child's componentWillReceiveProps

Within my application, there is a parent component and a child component with props connected to the parent's state. When I call setState in the parent component, the componentWillReceiveProps function of the child component does not always get trigg ...

Fluid Grid System with columns of specific dimensions

Recently delving into the world of Foundation Framework, I've just begun utilizing it for my projects. My current task involves crafting a responsive design with the help of the Foundation Grid system. Specifically, I've set up a grid layout for ...

Creating interactive textures using shaders in ThreeJS

In the shader code provided below, I am aiming to introduce a new uniform for an additional texture and apply it exclusively to vertices that are evenly divisible by 4. uniform vec3 color; uniform sampler2D texture; varying vec4 vColor; void main() { ...

Is there a way to organize items in an array alphabetically according to a predetermined key value?

I have an array of objects containing countries with various values for each country. My goal is to list them alphabetically. // globalBrands { [ { id: 1, title: 'Argentina', content: [{url: 'w ...

Protractor is unable to locate the password input field on Gmail using its ID

Currently, I am in the process of configuring Protractor to test my application. However, I am encountering a roadblock as it requires authentication through Gmail and I am struggling with the login process: describe('Vivace Home page', function ...

Is there a way to enlarge an iFrame to fill the entire screen with just a button click, without using JavaScript

I am currently attempting to achieve full screen mode for an iFrame upon clicking a button, similar to the functionality on this site. On that website, there is a bar that expands to full screen along with the embedded game, which is what I am aiming for. ...

Include the distribution file from the npm package in the final build

Working on my react-based project, I've integrated the node-poweredup npm package to enhance functionality. This useful library comes in both a nodejs and browser version. To include the browser version in my app, I simply link the script located at j ...

Arrange and display similar objects together

I have a list of items in a listView that need to be visually grouped based on their class, displayed within boxes. For example, I have 5 items with the following classes: <div class="1"></div> <div class="1"></div> <div class= ...

The most efficient method for handling a vast amount of data in NodeJS

My database consists of 4 million numbers and I need to quickly check if a specific number exists in it. Example of the database: [177,219,245,309,348,436,...] I initially tried using a MySQL table for this task, but it took a lengthy 1300ms just to chec ...

Is it possible to transform a Vuejs project into Vue-Native?

I recently completed a Vue.js project and now I'm interested in turning it into a native app. I'm wondering if I'll need to completely rewrite the application using Vue-Native components, or if there is a way to convert my existing project i ...