Ways to resolve the Face4 to Face3 issue

After stumbling across some old code, I discovered that it was mostly functional.

var geom = new THREE.Geometry();
geom.vertices = testRect.verts();

for ( var i = 0; i < verts.length; i+=4 ) {
    geom.faceVertexUvs[0].push([
        new THREE.Vector2(1.0 - ((verts[i].x - testRect.x) / testRect.width), 1.0 - ((verts[i].z - testRect.y) / testRect.height)),
        new THREE.Vector2(1.0 - ((verts[i+1].x - testRect.x) / testRect.width), 1.0 - ((verts[i+1].z - testRect.y) / testRect.height)),
        new THREE.Vector2(1.0 - ((verts[i+2].x - testRect.x) / testRect.width), 1.0 - ((verts[i+2].z - testRect.y) / testRect.height)),
        new THREE.Vector2(1.0 - ((verts[i+3].x - testRect.x) / testRect.width), 1.0 - ((verts[i+3].z - testRect.y) / testRect.height))
    ]);
}
for ( var i=0, vl=verts.length; i<vl; i+=4) {

    geom.faces.push(new THREE.Face4(i, i+1, i+2, i+3));
}

Figured out what needed to be fixed (Face4 changed to Face3)

THREE.Face4 = function ( a, b, c, d, normal, color, materialIndex ) {

    return new THREE.Face3( a, b, c, normal, color, materialIndex );

};

However, I noticed that there were insufficient polygons in the model

Attempted to address this issue

for ( var i=0, vl=verts.length; i<vl; i+=4) {
    geom.faces.push(new THREE.Face4(i, i+1, i+2, i+3));
    geom.faces.push(new THREE.Face4(i, i+3, i+2, i+1));
}

Unfortunately, no progress was made with this approach (

Looking for assistance in solving this problem)

Answer №1

When considering the geometry defined by the quad (A, B, C, D), it is interesting to note that the same geometry can also be represented by the combination of two triangles: (A, B, C) and (A, C, D).

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

To adapt the code for this scenario, you can make adjustments like so:

for (let i = 0; i < verts.length; i += 4) {
    geom.faces.push(new THREE.Face3(i, i + 1, i + 2));
    geom.faces.push(new THREE.Face3(i, i + 2, i + 3));
}

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

Prevent popup content from refreshing: Tips for creating a dynamic user experience

Currently, I am working on a website that is similar to Facebook. One of the features I am implementing is the ability for users to like posts or photos and see who has liked them. However, I am facing an issue with the popup that shows the list of people ...

Is there a way to spin around the focal point of an item in three.js?

In my current project, I am dynamically adding various objects of different sizes into a scene, one per click. My goal is to scale and position these objects accurately. Now, I am facing the challenge of rotating the objects around the Y axis at their cent ...

Trigger a function in jQuery when the DOM undergoes changes

Up until now, I have been utilizing livequery which has served its purpose. However, it tends to slow down the page browsing experience, so I am in search of an alternative solution. I have a function that performs ajax on elements with a specific class l ...

Adding animation to the initial loading process of a Vue application

I want to include an animation when the application's modules are loading for the first time. I have attempted to use an image, but I am unable to add an animation to it. Adding a CSS file did not always work as expected. I then tried utilizi ...

Encountering a series of frustrating 404 errors when attempting to submit a React form multiple times

I've been working on developing a new forum using Express and React, but I'm facing challenges with saving form data to the database. Currently, my goal is to store topic titles in a MongoDB collection, with plans to expand to include message con ...

What is the best way to implement the settimeout method in react?

I need assistance on how to effectively utilize the setTimeout() method in my code. Specifically, I am looking to trigger a click event on an element after a certain delay and execute a function afterwards. Here is the current implementation of my code: ...

Swap out the image source when the mouse hovers over it and revert back to the original when

Here is my HTML code for one larger image with two smaller thumbnails beneath it: <img src="../images/image.jpg" class="left main" alt="main image" /> <img src="../images/image2-thumb.jpg" class="left mainthumb" alt="image two" /> <img sr ...

Using local variables in NodeJS callbacks

Despite the abundance of information on SO, I have yet to find a suitable answer to my particular situation. The following code snippet is causing me issues: for(var i=0; i < shop.collections.length; i++){ if(!shop.collection[i].active){ var dat ...

What is the best way to interpret the JavaScript code within a Vue/Quasar project?

Sample Code: <script type="text/javascript" src="https://widget.example.com/widgets/<example_id>.js" async defer></script> I am looking to integrate this code into Quasar Framework and utilize it with Vue.js. Do you have any suggesti ...

Typescript is throwing a fit over namespaces

My development environment consists of node v6.8.0, TypeScript v2.0.3, gulp v3.9.1, and gulp-typescript v3.0.2. However, I encounter an error when building with gulp. Below is the code snippet that is causing the issue: /// <reference path="../_all.d. ...

How to display the total of specific values on the screen using React

Looking to create an app that displays 9 boxes, each with 4 select options: close successful, close unsuccessful, callback, and open. The goal is to count the number of closed successful and unsuccessful boxes and display the total count at the top of the ...

What is the best approach to establish the right 'this' Lexical Scope while utilizing Promises in ES6/React?

I've been exploring the use of the FourSquare API to retrieve location data within my React App. To achieve this, I'm leveraging a convenient package available here: https://www.npmjs.com/package/foursquarevenues The package employs promises to ...

navigating a pointer graphic within a container

I've been working on creating a sniper game, but I've run into an issue with moving the sniper image inside the div. My main objective is to change the image to the sniper image when the mouse hovers over the div. Here's what I have tried so ...

Is it possible to integrate the extension library of three.js (including OBJLoader, SceneUtils, etc.) with Angular 6?

Attempting to implement the below code, however, it is not functioning as expected. npm install --save three-obj-loader import * as ThreeObjLoader from 'three-obj-loader'; const OBJLoader = ThreeObjLoader(THREE); let loader = new OBJLoader(): ...

How can I showcase images stored in an array using JavaScript?

I am currently developing a role-playing game (RPG). In order to enhance the gameplay experience, I am trying to implement a for loop that will dynamically generate buttons on the screen. Here is the code snippet I have created so far: $(document).ready(f ...

Having trouble testing firebase messaging on my local server

I've encountered an issue while trying to retrieve a token from firebase/messaging for use in notifications. The error message "messaging/unsupported-browser" (FirebaseError: Messaging: This browser doesn't support the API's required to use ...

What is the best way to utilize typed variables as types with identical names in Typescript?

Utilizing THREE.js with Typescript allows you to use identical names for types and code. For instance: import * as THREE from '/build/three.module.js' // The following line employs THREE.Scene as type and code const scene: THREE.Scene = new THRE ...

Firebase will automatically log users out after one hour of inactivity

After conducting thorough research, I have learned that Firebase updates a refresh token every hour because Firebase ID tokens expire after one hour. It is mentioned that the automatic refreshing of tokens by Firebase occurs without any action required fro ...

Error: React cannot render objects as children

I am encountering an error that I cannot seem to figure out. The issue seems to be with the following line of code: <p className="bold blue padding-left-30">{question}</p> Specifically, it does not like the usage of {question} in the above pa ...

The React Component is limited to updating once

Exploring the React Native code below: import React from 'react'; import {Text, View, StyleSheet, Button} from 'react-native'; export default class Target extends React.Component { constructor(props){ super(props); ...