Unusual patterns appearing on a unique mesh in Three.js

I am attempting to create a unique mesh design to incorporate multiple customizable planes within the scene.

Below is an example of the code I am using:

geometry = new THREE.BufferGeometry();

geometry.addAttribute( 'position',  new THREE.BufferAttribute( vertexPositions, 3 ).setDynamic( true ) );
geometry.addAttribute( 'color',     new THREE.BufferAttribute( colors, 3 ).setDynamic( true ) );
geometry.addAttribute( 'opacity',   new THREE.BufferAttribute( opacity, 1 ).setDynamic( true ) );

// Initialize material
var material = new THREE.ShaderMaterial( { vertexColors: THREE.VertexColors, transparent: true, vertexShader: vertexShader, fragmentShader: fragmentShader } );

// Create wireframes for the planes
var Pgeometry = new THREE.BufferGeometry();
Pgeometry.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( ApointsPositions ), 3 ).setDynamic( true ) );
var points = new THREE.LineSegments( Pgeometry, new THREE.PointsMaterial( { color: 0x353535 } ) );
scene.add( points );

// Generate planes and include them in the scene
planeMeshes = new THREE.Mesh( geometry, material );
planeMeshes.setDrawMode( THREE.TriangleStripDrawMode );
scene.add( planeMeshes );

The custom material functions correctly, enabling me to apply opacity to each vertex. All planes are successfully created without any issues.

However, upon rendering the scene, unusual diagonal lines appear on each row of planes. For a visual representation, please refer to this Codepen link: Codepen link

Have you noticed these diagonal lines? Could you provide insight into what might be causing this issue? I have been unable to identify their source.

Thank you for your help!

Answer №1

The issue with the appearance of diagonals in your rendering is due to the use of THREE.TriangleStripDrawMode, which results in vertices being shared between adjacent triangles, causing a stretched-out effect.

To address this, remove the line where you set TriangleStripDrawMode and revert to the default setting of three vertices per triangle without vertex sharing.

Another concern:

You are drawing the first triangle on each iteration in a clockwise order, while the second triangle is drawn in a counter-clockwise order. To ensure both triangles are visible, make sure to consistently follow either a clockwise or counter-clockwise vertex order throughout the code.

In your current implementation on Codepen:

// Second tri is drawn counter-clockwise
AvertexPositions.push( x,        y + 60, 0 ); //
AvertexPositions.push( x + 80,   y + 60, 0 ); // Second triangle of a plane
AvertexPositions.push( x + 80,   y,      0 );

Update the order as follows for proper alignment:

// Now, it is clockwise, matching first tri
AvertexPositions.push( x,        y + 60, 0 ); //
AvertexPositions.push( x + 80,   y,      0 ); //
AvertexPositions.push( x + 80,   y + 60, 0 ); // Second triangle of a plane

Consistency in winding order for all triangles is crucial to avoid rendering issues. You can choose whether to render one side or both sides using Materials.Side

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

Can you explain the variances between creating a new date object with input as "2017-01-01" and "2017-1-1" in JavaScript?

When I use new Date("2017-01-01") in the Chrome console, the output displays its hour as 8. However, when using new Date("2017-01-1") and new Date("2017-1-01"), the hour is shown as 0. This brings up the question of how new Date(dateString) actually pars ...

Adding a delay to your JQuery wiggle effect

Is there a way to achieve an effect similar to the JQuery wiggle plugin? Check out this demo: <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.js" type="text/javascript"></script> <script src="http://static.manpoints.u ...

Error Encountered While Creating a Polygon Wallet on Fireblocks

After following the instructions from Fireblocks Docs, I successfully created a default wallet named "BTC_TEST" like this: enter image description here. However, when attempting to create a Matic wallet, I encountered an Axios Error. Despite Matic being a ...

Using numerous textures for a single mesh in THREE.js

I am working with an OBJ file that utilizes four textures. The UV coordinates in the file range from (0, 0) to (2, 2), where (0.5, 0.5) corresponds to a coordinate in the first texture, (0.5, 1.5) is a UV coordinate in the second texture, (1.5, 0.5) repres ...

How can I use JavaScript to enable the functionality of "Open in Safari"?

On iOS, the Google app offers an "Open in Safari" option as shown in the image below. Can this be implemented using JavaScript? https://i.sstatic.net/a3DiM.png The JavaScript code I am working with will be executed on a mobile web browser. ...

Issues with Javascript's JSON.parse functionalityI'm having trouble

As a complete newcomer to the world of JavaScript, I find myself struggling with some issues regarding JSON manipulation. This is my very first attempt at working with it, and I am encountering difficulties in converting my JSON string into an object that ...

Bootstrap 4 Collapse - Ensuring that collapsed elements remain open when expanding other accordions

Can someone help me figure out how to keep an element open when another one is opened? Here is an example: https://getbootstrap.com/docs/4.0/components/collapse/ <div id="exampleAccordion" data-children=".item"> <div class="item"> & ...

Is it possible to activate the :active pseudoclass by pressing the 'enter' key on the keyboard using solely CSS?

The CSS: a:focus { opacity: .75 } a:active { transform: translateY(4px) } The purpose: When keyboard users tab to the link, the :focus style serves as a visual indicator Upon pressing the enter key to activate the link, the :active style provides ...

Create an Oval-Shaped Image Cutout

Currently, I have a fabric.JS canvas where objects can be added. However, I am interested in clipping these objects into an oval shape, similar to the clip demos on fabricjs.com. In my current project (JSFiddle), I have been able to crop the object into a ...

Having issues with angular-file-upload failing to include the file in the request

I am currently using angular-file-upload in order to upload an image to a server that is utilizing Node and Express 4.0. However, I am encountering difficulties in accessing the file data on the server. Below is the relevant code snippet: <input type= ...

preventing the ball from landing inside the container (JavaScript)

I developed a straightforward website with the following functionality: Upon entering any text into the prompt and clicking okay, a ball will drop into the 1st box, namely the Past Thoughts box. Below is the code snippet: HTML <h1> Welcome t ...

Execute angular.js as a callback function, such as within a $.ajax call

In developing my app, I am primarily working with two key JavaScript files: resources_loader.js and app.js. The role of resources_loader.js is to load some JSON files that are utilized by app.js. However, the issue arises when considering the sequence in ...

Exploring the functionality of $timeout in AngularJS

Can you explain the functionality of $timeout in AngularJS and how it sets itself apart from traditional setTimeout()? ...

Error: Angular7 Unable to locate namespace 'google'

I am currently utilizing the import { MapsAPILoader } from '@agm/core'; package to enable auto-complete address search functionality. However, I have encountered an error message stating cannot find namespace 'google'. The error occu ...

Enhanced slider functionality with the addition of multiple slick transitions

My layout features a question with 4 options. When any answer is clicked, a new slide is added and the layout transitions to that slide. $(document).on('click', '.goal1 li', function(e){ $(this).addClass('goal-selected'). ...

Tips for successfully changing the styling using CSS that was previously altered with JavaScript

I have already gone through this question but couldn't find a solution. I used JavaScript to apply the style to the element with the id "left-container" instead of using a class, and now I'm unable to override it! You can view the demo for a m ...

Using React JS: A guide to passing various props within a set of other props in a map

Query: How do I successfully pass the params array into my <Post /> component and map the data array? Within my state, I have two arrays: this.state = { data: [], params: [] };. These arrays are passed down via props to a file named PostList.js. The ...

FormKit: circumventing required fields to successfully submit form data - efficient preservation of entered information

I am currently working on a Vue3 App that utilizes the FormKit library. The form is quite extensive, with validation in place for all fields. I have added functionality to allow users to either submit all data at once if it is valid or save the data temp ...

Encountering an issue when receiving a 400 status code in axios

Currently, I am utilizing Vue along with Axios to construct a single page application frontend. In situations where the server responds with a 400 error in CROS, the browser's console displays the following: (2) POST http://dev.sportx.one/api/token/ ...

Modify the background color of React-select when it is in a disabled state

I found this interesting tip on color customization in React Select When the select field is disabled, I want to change its color to something different. isDisabled={true} To achieve this, I am modifying the code as follows: > import React from &q ...