Challenges with custom geometry rotation in Three.js

Recently, I've delved into Javascript and started exploring three.js. I created a custom Geometry to form a triangular prism, which looks correct initially. However, upon rotation, some of the faces appear distorted. Interestingly, the pre-built geometries like CubeGeometry and CylinderGeometry behave as expected. Is this issue related to my custom Geometry, lighting setup, or perhaps the Mesh or Material configuration?

For reference, here's a fiddle demonstrating the problem: 3D Shapes Fiddle

Below is the key code snippet:

function getTriPrismGeometry(){
    // Custom Geometry creation
}

function init(geometry, isCustom) {
    // Initialization function for rendering
}

function animate() {
    // Animation loop using requestAnimationFrame
}

function render(){
    // Logic for rendering with rotation and position adjustments
}

I'm relatively new to three.js and 3D rendering in general, any guidance or suggestions on resolving this issue would be greatly appreciated. Many thanks in advance!

Answer №1

If you're creating your own geometry, make sure to define the face vertices in a counter-clockwise order.

After making that adjustment, your custom geometry will be good to go.

It's beneficial to study the current examples provided by three.js. Your code is using outdated practices, such as using the deprecated Vertex. The new recommended pattern is:

geometry.vertices.push( new THREE.Vector3( -100, 100, 0 ) ); 

Check out this example on jsfiddle: http://jsfiddle.net/JLKCU/3/ - version: three.js r.54

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

provide a hyperlink to the icon located in front of the navigation bar

I'm struggling to come up with a suitable title for this issue. What I am trying to achieve is placing a small icon in front of the navbar so that visitors can click on it and be directed to another site. Initially, I attempted to place the icon using ...

"Creating multiple circles on an HTML5 canvas using an iPad: A step-by-step guide

My current code is only drawing one circle at a time on an iPad view, but I want to be able to draw multiple circles simultaneously. How can I achieve this? // Setting up touch events for drawing circles var canvas = document.getElementById('pain ...

Exploring JS Object Property Access and Iteration with an Illustrative Example

Something strange is happening... the code snippet below generates a table displaying a list of SNMP object/values from any OID provided for walking. Strangely, the variable 'jason' is not behaving as expected. Initially, I am unable to access t ...

The ethereal glow of physical light in Three.js pierces through the

Just starting out with Three.js and experimenting with physical lighting. I followed this example: threejs_physical_light One issue I encountered is that the light seems to extend beyond the brick wall. Is there a way to prevent this from happening? (I ad ...

Styling AngularJS Pie Charts

Is it possible to customize the appearance of a pie chart created with angularjs-chart in order to achieve a design similar to this: https://i.sstatic.net/xYcu9.png While there are some examples available on the angularjs-chart website, one particular ex ...

Is it possible to dynamically override inline styles?

My HTML code is as follows: <div title="remove css"style="position:relative;">Remove my style</div> After the page loads, I need to completely remove the position style attribute. Due to limitations, I cannot override the CSS. Is there a way ...

Creating a Kendo UI grid within a Kendo UI window and utilizing Knockout JS bindings

I'm encountering an unusual issue while working with Kendo UI and Knockout JS libraries. When attempting to display a kendo grid within a kendo window, the rows inside the grid are being duplicated. Below is a snippet of the code I'm using: JS: ...

"Discover the best way to sort through an array of complex objects with varying levels of nesting using a specified search

I have come across similar answers, but none of them go beyond two levels deep. Therefore, I believe this is not a duplicate problem. My task is to filter an array of objects where each object may contain nested objects of unknown depth. In my data structu ...

Is it better to have a single object with all required modules in NodeJS, or follow the "standard" paths in the code?

Being a fan of creating global namespaces in javascript, I often use this approach in my app development. For instance, if my application is named Xyz, I typically create an object called XYZ to organize properties and nested objects like so: XYZ.Resource ...

Troubleshooting Angular: Implementing scrollIntoView on route change without using setTimeout within ngAfterViewInit

I am currently working on an Angular component where I need to implement scrollIntoView functionality when the route changes. Below is a snippet of the relevant code from my component: @ViewChild('structure') structure: ElementRef | undefined; le ...

Implementing Bootstrap modal functionality in PHP

I'm attempting to trigger a hidden modal from an HTML file using PHP as part of a verification process. One modal is displayed when a button is clicked, while the other is meant to be called by PHP. Below is my PHP code: $File = include("index2.html ...

Is there a way to identify when the back button on an Android device is pressed while using a

I am currently working on a Progressive Web App with Vue.js. I am aware that Cordova has the capability to handle the back button on Android/iOS devices (not the browser's back button) which is good news. Does anyone know how I can detect this in Vue ...

I am interested in setting up a horizontal image slider using three.js for my project

I am looking to create a unique horizontal image slider using three.js. Although the example provided is for a vertical slider, I am interested in implementing a horizontal slider. Here is an example of a horizontal slider. https://i.sstatic.net/Wyez3.pn ...

Exploring AngularJS $compile and the concept of scoping within JavaScript windows

I've encountered a scoping issue with the use of this inside an angular-ui bootstrap modal. The code below functions perfectly outside of a modal, but encounters problems when run within one: var GlobalVariable = GlobalVariable || {}; (fun ...

Using MaterialUI to create a GridListTile with two IconButtons

I'm working with a GridListTile and trying to add a second button, but I'm having trouble getting both buttons to display. Even though I've attempted to include two ActionIcons, only one of them is showing up. Here's the code snippet: ...

"angular-seed's web-script.js and cross-origin resource sharing (cors

I'm having trouble for the second day... I'm attempting to retrieve some json from an external domain, but I'm facing CORS issues. I believe that the problem lies with my node.js server not sending Origin: http://api.bob.com I've res ...

What are some ways to provide the find() method in JavaScript with a specific search argument?

I've been exploring ways to search within an array while iterating through it. One method I stumbled upon is the find() method. Take a look at this example: var inventory = [ {name: 'apples', quantity: 2}, {name: 'bananas&apos ...

How to retrieve the output of a nested function in Node.js

I have been attempting to retrieve a value from a function nested inside another function in my Node.js application, but it always seems to return undefined. var geo = { list: function(callback){ var returnval; gapi.getcodes(function(e ...

Is there a way to restrict the number of checkboxes selected based on the values of radio buttons?

I am currently working with a group of radio buttons: <input type="radio" name="attending_days" value="06-18-13"/>Tuesday June 18, 2013 <input type="radio" name="attending_days" value="06-18-13"/>Wednesday June 19, 2013 <input type="radio" ...

React is indicating that returning functions is not appropriate as a React child. This issue may arise if you accidentally return a component instead of <Component /> within the render method

Check out the main game.js and app.js files: //Here is the code in game.js// import React, { Component } from "react"; class Game extends Component { constructor(props) { super(props); this.state = { num: 0 }; this.numPicker = this.numPi ...