When working in three.js, it's important to remember that geometry.faceVertexUvs[0][0][index] does not equate to geometry.vertices

From what I gather, the uv coords ("texels") of each vertex in a mesh can be accessed using:

geometry.faceVertexUvs[ materialIndex ][ faceIndex ][ vertexIndex ]

The issue I'm facing is that the vertexIndex seems to have a different mapping order compared to

geometry.vertices[ vertexIndex ]

An example showcasing this problem has been created:

Source:

The provided code carries out the following actions:

  • Generates a plane
  • Displays a sphere at the position of the plane's vertex with index 1 using a utility function called dot:

    dot( floor.localToWorld( floor.geometry.vertices[1].clone() ) );

  • Alters the texel at faceVertexUvs[0][0][1] to visualize the location of texel 1

    floor.geometry.faceVertexUvs[0][0][1].add( new THREE.Vector2( 0.4, 0 ) );

In the example page, it can be observed that the sphere is drawn on the top right of the plane (vertex 1), while the texel being manipulated is situated on the bottom left of the plane. The vertex indices do not align! Is this an issue with three.js, or am I overlooking something regarding texels?

I've noticed that the vertices seem to correspond as follows:

texel index | vertex index
0           | 3
1           | 1
2           | 0
3           | 2

However, some unexpected behavior arises when attempting a related uv mapping task, which leads me to question if the mapping is indeed the root cause of my error.

Answer №1

There may be other methods, but it seems the mapping is functioning like this:

geometry.faceVertexUvs[ 0 ][ faceIndex ][ vertexIndex ]

vertexIndex corresponds to the vertex index of the face, rather than the geometry vertex array. Although it's portrayed as a number from 0-3 (for a quad), the face itself labels them as a-d (referencing Face4 docs):

Face4( a, b, c, d ... )

> geometry.faces[0] // if faceIndex is 0
THREE.Face4 {a: 0, b: 2, c: 3, d: 1, normal: THREE.Vector3…}

Voila, there's our connection!

To establish the correspondence between them, we should locate the face at that index, match 0 with a, 1 with b, and so forth, then refer back to the geometry.vertices array. An unorthodox yet effective method could look something like:

geometry.vertices[
    geometry.faces[faceIndex][ String.fromCharCode(97 + vertexIndex) ]
];

Here, the vertexIndex comes from

faceVertexUvs[0][faceIndex][vertexIndex]
. The fromCharCode function maps a to 0 and similar matches. Thus, we obtain each uv texel's corresponding vertex (including its position)! Hooray!

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

Execute a function within useEffect continuously until the contract is fully loaded

When I make the call contract?.methods.name().call() within the same scope as loading providers, everything works perfectly fine. It also works fine when I do a page reload. However, if I make the call contract?.methods.name().call() in another useEffect, ...

Hiding Certain Words on a Website

Is there a way to hide specific text strings on a website? For instance, suppose I want the string "hxxp://nullrefer.com/?" to be invisible whenever it appears on my page. If a URL like "hxxp://nullrefer.com/?hxxp://www.Amazon.com" is mentioned, I only w ...

An unexpected problem with text redirection that should not be happening

I am facing an issue with my HTML text field and post button on my website. Whenever I click the post button to make a post, it redirects to a separate PHP file called post.php which handles PHP and MySQL code for posting. However, I want to avoid this red ...

Regular expressions work when used on the internet, but they don't seem to

I'm encountering a peculiar situation with a regular expression. Here is the expression in question: const csrfRegex = /"csrf_token": "((\\"|[^"])*)"/ig; The main objective is to extract the CSRF token from a Javascript object on a website ...

Using Vue: Save user information in the Vuex store prior to registration

Hello fellow members of the Stackoverflow Community, I am currently working on a Vue.js application that involves user registration. The registration process is divided into three components: Register 1 (email, password), Register 2 (personal information) ...

Tips for restricting access to specific routes in VueJS using Store state

Once a user is authorized, their user type is saved to the state. Based on this type, I need to dynamically show or hide specific routes. src/store/index.js: import Vue from "vue"; import Vuex from "vuex"; import getters from "./getters"; import user from ...

What is the best way to link objectID, name, phone, and other fields from one collection(schema) to a different one in MongoDB

Is there a way to create a form for customizing cakes where the user's information is automatically saved in the database along with their cake preferences? I'm looking to mimic the order model used in e-commerce websites, but I'm strugglin ...

PlateJS: Transforming HTML into data

Trying to implement a functionality where clicking on a button retrieves an HTML string. The objective is to have this rich text editor within React-Hook-Form, and upon form submission, the value will be saved as HTML for database storage. Below is the pr ...

There was an uncaught error in AngularJS stating that the URL in the HTTP request configuration must be a string

I've been working on a web application and have encountered some challenges. One particular issue I'm struggling with is related to the following code snippet: this.bookSpace = function (date, spaceId) { swal({ title: "Are you sure?", t ...

Tips for executing flushall just once across various clusters with Node.js and Redis

Whenever my server starts up, I find myself needing to clear out the Redis memory. However, each time a new cluster is formed, it triggers a flushall command that wipes out everything in memory. Is there a way to only run flushall once on the very first se ...

Changing selections in jQuery may not work properly on certain mobile and IE browsers

I am currently working on creating a dependency between two select boxes. The jQuery code I have implemented works perfectly on most common browsers such as Chrome and Firefox, but it seems to have some issues with Internet Explorer, Edge, and some mobile ...

Skip ahead button for fast forwarding html5 video

One of the features in my video player is a skip button that allows users to jump to the end of the video. Below is the HTML code for the video player: <video id="video1" style="height: 100%" class="video-js vjs-default-skin" controls muted autoplay=" ...

Efficiently refresh several DIV elements with a single JSON request

After extensive searching, I've come to the conclusion that due to my limited proficiency in javascript, I need some help. The issue at hand is with a json format output produced by an ASP page on a separate webserver, which looks something like this: ...

ajax is not functioning properly on scrolling div

I recently created a 1 on 1 support chat using ajax and it's been working well. However, I've encountered an issue where the div expands indefinitely when refreshed by ajax and is taller than its original height. I've tried using overflow: a ...

Having trouble with WordPress jQuery Click function. Would greatly appreciate some assistance :)

There seems to be a mix of working and non-working jQuery code. Specifically, the click function is not functioning properly in this case. Here is an example of the code that works: $j=jQuery.noConflict(); // Using jQuery with $j(...) $j(document ...

Is the functionality of defineProperty for elements malfunctioning on iOS6?

There seems to be an issue with JavaScript's defineProperty and __defineSetter not working on elements in iOS6. It functions correctly on all other browsers and earlier versions of iOS. Does anyone have more information on this? <input id='Bu ...

Issues with MC-Cordova-Plugin on Ionic and Angular Setup

Recently, I integrated a plugin for Ionic from this repository: https://github.com/salesforce-marketingcloud/MC-Cordova-Plugin After successfully configuring it for iOS, I encountered difficulties on Android where the plugin seems to be non-existent. It ...

What is the best way to incorporate an AppBar featuring a Back to Top button from Material UI for React into my application?

While exploring the Material UI documentation, I came across this interesting code snippet: import React from 'react'; import PropTypes from 'prop-types'; import AppBar from '@material-ui/core/AppBar'; import Toolbar from &ap ...

Securing nested routes in NextJs with authentication

Is there a way to authenticate all nested routes in my project? Some routes require authentication, while others can be accessed without it. For example: /admin => requires authentication /admin/posts => requires authentication /admin/posts/1 = ...

Turn off interpolation during the scaling of a <canvas> tag

Important: The issue at hand pertains to the rendering of existing canvas elements when scaled up, rather than how lines or graphics are rendered onto a canvas surface. In simpler terms, this revolves around the interpolation of scaled elements, not the an ...