Obtaining the 3D point coordinates from UV coordinates on a 3D plane object using Three.js

I am in the process of creating basic data visualizations using Three.js as my tool of choice. I have a series of PlaneGeometry meshes to which I am applying a transparent texture dynamically generated with red squares drawn at varying opacity levels. My goal is to use the coordinates of these red squares to create additional meshes (such as CylinderGeometry) and position them above the red squares based on their opacity values. I have been able to identify the UV values for each square and store them in an array, but I am facing difficulty in converting these UV coordinates to the 3D world coordinates system. While I have come across resources explaining this process for spheres, I have not been able to find similar information for other types of meshes.

How can I determine the 3D coordinates of the red squares within the texture?

Answer №1

UPDATE: I believe I have found the solution:

function convertTexturePositionToPlaneWorldCoordinates(planeObject, textureCoordinates)
{    
    var position = new THREE.Vector3();
    position.x = (textureCoordinates.x - 0.5) * PLANESIZE;
    position.y = (textureCoordinates.y - 0.5) * PLANESIZE;

    position.applyMatrix4(planeObject.matrix);
    return position;
}

This function is used in the following jsfiddle: http://jsfiddle.net/L0rdzbej/2/

var textureCoordinates = new THREE.Vector2(0.8, 0.65);
var newPosition = convertTexturePositionToPlaneWorldCoordinates(planeObject, textureCoordinates);
cubeObject.position.copy(newPosition);

Planes can be defined simply. The line between vertices A and B -- vector A to B -- determines the 'x' direction in your texture. Similarly, A to C determines the 'y' direction on the 3D plane where the texture is mapped.

If the pivot point is in the center, it is known in world space. As the UV coordinates range from 0 to 1, UV coordinate (1.0, 0.5) would correspond to the midpoint of the plane's full width in the direction of the vector from the Plane object's pivot to the edge. The midpoint otherwise corresponds to 0.5 in V (normalized texture y pixel coordinate).

To find the vertices' coordinates of the plane in world space, simply multiply them by the object's orientation.

If the size of the plane is known, there is no need to examine the vertices since the plane's orientation is already in the object matrix. Adjust the UV coordinates to the center (-0.5) and multiply by the plane size to obtain the point in plane space. Multiplying by the matrix then converts it to world space.

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

Hiding and displaying DIVs on a single HTML page using VueJs 2

I am currently working on building an application that is not a single page application. As I develop my project, I have several div elements on the page that I want to toggle visibility step by step. Below is the snippet of my code: <div v-if="sect ...

Regular expressions tailored for a precise format in JavaScript

Is it possible to create a regex that can validate a specific format? For example, if I have version numbers like v1.0 or v2.0 v1.0 or v2.0 My current regex expression only validates the existence of v, a number, or a .. How can I implement validation ...

Using Laravel to submit a form with identical input names via AJAX

Seeking assistance with my ajax function. A form I have is submitting data with the same input name. Without using JavaScript, I can insert multiple input data with the same name easily, Here is the structure of the submitted data {"_token":& ...

Is it possible for a React application to manage errors (status code 4xx) using a try-catch block

Currently delving into React (using hooks) and facing an interesting challenge. I am in the process of building a Notes Application (from FullStackOpen's learn react section). The database I'm working with only allows notes with content length gr ...

awaitMessages feature does not capture slash commands

In my development process, I have a file named botReady.js that is designed to run as soon as the bot becomes ready. In this file, there is a specific section dedicated to handling a bump bot in a designated channel obtained using the client.channels.fetch ...

It is essential for every child within an array or iterator to possess its own distinctive "key" prop when working in reactjs

Despite consulting the ReactJS documentation and various tips on StackOverflow, I am still completely confused by an error in my console. The issue arises when trying to display a list of book titles ({item.volumeInfo.title}) while encountering an error. ...

deciphering JSON objects based on specific keys

Struggling to complete a seemingly straightforward task has left me feeling frustrated. In the header of my HTML page, I have an external car dealer API being called. At the bottom of the page, there is another external .js file containing a series of if- ...

Unable to redirect page in Codeigniter after submitting button

I am facing an issue with inserting and updating data in my database using Ajax to my controller. Despite the data being inserted and updated accurately after clicking the button, the changes are not reflected on my view page until I manually refresh it. A ...

Struggling to use the innerHTML method to update a div within another div element?

<!DOCTYPE html> <html> <head> <title>Business Information Card</title> <script type="text/javascript"> window.onload = init; function init(){ var button = document.getElementById("populate ...

Is it possible to use multiple schemas for one collection name?

I am currently working on creating different schemas for a single collection, such as User or subUser. I aim to store both User and subuser data in the same collection but with different schemas. Here is an example of my schema file: export const AryaSchem ...

Is it possible to display a pdf.js page as actual HTML elements rather than as canvas or SVG?

I am in the process of creating a user-friendly mobile interface for pdf reading. However, I want to incorporate more advanced features by developing my own pdf reader instead of relying on the pdf.js team's viewer. Is there a method available to rend ...

The console is displaying a state that has not been updated in the Redux reducer yet

I am currently facing a puzzling issue that I can't quite pinpoint whether it's related to Chrome console, Redux, or JavaScript objects. Within my React + Redux application, I have the following function: function InputReducer(state = [{ }], ac ...

Issue persists: Ajax functionality remains nonfunctional, prompting the need for

My goal is to use the post input, and upon hitting enter, I want to dynamically replace <div id="mainPagePosts"></div> with new data without causing a page refresh. However, even after submitting the post, the page still refreshes, although I d ...

What is the process for setting a personalized title for error pages in Remix?

I'm currently working on setting up the 404 page for my Remix app, but I'm facing challenges when it comes to configuring the <title> meta tag for these pages. Within my root.tsx file, I have defined a MetaFunction and a CatchBoundary: exp ...

Retrieve data from API using ReactJS and passing parameters to the request

I am trying to retrieve information from the API based on the data I am sending, but encountering two issues: Initially, I hardcoded the information being sent to the API (year and term) as it should return the data I am trying to store, however, it is ...

Creating a conditional interface based on props in TypeScript: A step-by-step guide

What is the most effective way to implement conditional props in a component that can be either a view or a button based on certain props? Let's take a look at an example called CountdownButtonI: class CountDownButton extends Component<CountdownBut ...

Issue - The 'defaultValue' is failing to load the state value, and the 'value' is not being updated when changed

My current setup involves an input field in my MovieInput.tsx file: <input id="inputMovieTitle" type="text" onChange={ e => titleHandleChange(e) } value={ getTitle() }> </input> This is how the titleHandleChange function ...

Javascript animation functioning for a singular item within a list

As I continue practicing my skills in Javascript and HTML, I stumbled upon this intriguing list known as "item/adapter", similar to what we refer to as adapters in Android. While the process of adding them programmatically to my div is working smoothly, I& ...

Change a JavaScript object into an array with different options while still maintaining the keys

I am attempting to transform the following JavaScript object: image_uploads: [ 0: { upload_id: 50, }, 1: { upload_id: 51, }, 2: { upload_id: 52, }, ] Into separate entries using this structure for inclusion in the body of a POST r ...

Can Vue-router be used to load screens into Tabs?

In my setup, I have a routes file with multiple routes configured such as localhost:8000/test and localhost:8000/test2. My objective is to create a final route like localhost:8000/tabs, where I can utilize a tab library like bootstrap or Vuetify to displa ...