Obtaining the world position of vertices after the parent mesh has been scaled

I am working on a code to retrieve the world position of faces in a mesh. Here is my implementation:

var newReference = this,
    addPointCords,
    targetGeometry = currentMesh.geometry,
    finalPosition = currentMesh.getWorldPosition();

newReference.allMeshes[currentMesh.uuid] = {
    mesh: currentMesh,
    points: {}
};

addPointCords = function (currentPoint, face) {
    var calculatedPoint = newReference.octree.add([finalPosition.x + currentPoint.x, finalPosition.y + currentPoint.y, finalPosition.z + currentPoint.z], {mesh: currentMesh, geometry: targetGeometry, face: face});
    newReference.allMeshes[currentMesh.uuid].points[calculatedPoint.id] = calculatedPoint;
};

targetGeometry.faces.forEach(function(face) {

    //Retrieve the coordinates of the face's points
    addPointCords(targetGeometry.vertices[face.a], face);
    addPointCords(targetGeometry.vertices[face.b], face);
    addPointCords(targetGeometry.vertices[face.c], face);

}, this);

Everything works smoothly but encounters issues when the parent mesh is scaled. Any suggestions on addressing this challenge?

Answer №1

Many thanks to @TheJim01 for guiding me towards this solution.

var that = this,
    addPoint,
    geometry = mesh.geometry;

that.allMeshes[mesh.uuid] = {
    mesh: mesh,
    points: {}
};

addPoint = function (currPoint, face) {

    //Retrieve the world position in this manner.
    var vector = currPoint.clone();
    mesh.localToWorld(vector);

    var point = that.octree.add([vector.x, vector.y, vector.z], {mesh: mesh, geometry: geometry, face: face});
    that.allMeshes[mesh.uuid].points[point.id] = point;
};

//Execute this on the mesh
mesh.updateMatrixWorld();


geometry.faces.forEach(function(face) {

    //Fetch the coordinates of the faces' points
    addPoint(geometry.vertices[face.a], face);
    addPoint(geometry.vertices[face.b], face);
    addPoint(geometry.vertices[face.c], face);

}, this);

If you're interested, here's a related query: How to get the absolute position of a vertex in three.js?

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

Text inside the placeholder is not displaying correctly in the React.js user interface

When passing placeholder text as a prop to the <FormField/> component from the <CreatePost/>, I encountered an issue where the placeholder text was not displaying in the form. Interestingly, when I used console.log within the <FormField/> ...

Unable to receive notifications within an AngularJS service

<!DOCTYPE html> <html> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script> <body> <div ng-app="canerApp" ng-controller="canerCtrl"> <button ng-click="click()"> ...

Modify Bootstrap TouchSpin's initial value

Struggling to update the initial value displayed in TouchSpin, it seems like there is no direct way to do it. While it's possible to change other values like the maximum value, attempts to set the initval directly have failed. $("input[name=&apos ...

Guide to spinning a CannonJS RigidBody

Has anyone found a way to rotate a CANNON.RigidBody object in CannonJS (the physics library)? I'm attempting to align the object's rotation with that of the camera, so they both face the same direction. I understand that I need to adjust the quat ...

Avoiding do/while loop

Hey everyone, I'm currently working on an algorithm designed to remove concrete branches, similar to Depth-First Search (DSF), from a NodeTree. Basically, the algorithm checks if a specific node is acting as a parent for other nodes; if so, it grabs t ...

What steps do I need to take in order to integrate an mpg video onto my

I am in need of embedding mpg (dvd compliant mpeg2) movie files onto my webpage. Unfortunately, I do not have the ability to convert these videos into any other format. This webpage is solely for personal use, so any solution would be greatly appreciated. ...

the event listener for xmlhttprequest on load is not functioning as expected

I am facing an issue with validating a form using JavaScript and XMLHttpRequest. The onload function is supposed to display an alert, but it only works sometimes. I'm struggling to identify my mistake. document.getElementById("button").addEventListen ...

Choosing options from two separate dropdown menus with the same CSS class name using JavaScript or jQuery: A guide

I am looking to update the values of two dropdowns using the same CSS properties, similar to the design shown in the attached image. Here is the HTML code snippet for reference: <div class="container-fluid" role="main" style="margin-top: 100px;"> ...

Sending a document to a REST API with the fetch function in pure NodeJS

I am facing an issue while trying to utilize the native fetch() API in NodeJS for uploading a file to a REST API. Although I have successfully executed other GET and POST requests, this particular file upload operation is proving to be quite challenging. ...

Error: The variable "email" is not defined

Hey there, I could really use some assistance as a struggling developer. I've been at it all day trying to resolve this issue with no luck. It should be a simple task of posting from my AddUsers class and storing it in my SQL database. The state upda ...

Is there a way to make sure that my submit button aligns perfectly with the text beneath it

I am new to coding and I need help aligning my submit button with the text "You can contact Armando through his freelance portfolio on Upwork by clicking...". Can anyone assist me with this? .topnav { background-color: #333; overflow: hidden; } .to ...

How can I effectively manage shaders in the most recent version of three.js?

My attempts to use the latest version of Three.js for a simple example have not been successful. The older examples I found on Google were working with specific versions of Three.js: function shaders() { var vShader = [ 'void main() {&apo ...

Combining Multiple Arrays into One | Node.js

Can someone explain how to merge an array of arrays to me? For instance, I have the following array: [ [ {brand: 'fiat', model: 'palio'} ], [ {brand: 'nissan', model: 'march'} ] ] I want to transform this array int ...

What is the process for extracting context or span from an incoming http request in NodeJS without relying on automated tools

I am currently in the process of transitioning my Node.js application from using jaeger-client to @opentelemetry/* packages. Within my Node.js application, I have a basic http server and I aim to generate a span for each response. Previously, with jaeger ...

What is the best way to transfer a value from one HTML element to a child component in React using JSX?

I have a JSX code snippet that looks like this: import TableCell from '@mui/material/TableCell'; import TableCell from '@mui/material/TableRow'; <TableRow> <TableCell sx={{minWidth:45,width:45,maxWidth:45,backgroundColor ...

Utilize server-side scripting when JavaScript is not functioning

I am currently handling some application logic on the client side using JavaScript. How can I transition to server-side processing if JavaScript is disabled? For example: if(javascript.isdisabled) { //execute server code } ...

Sort through the data that is already populated and proceed to paginate within Mongodb

Hey there, I'm currently working on populating some data and then implementing pagination for that data. Take a look at this example: Schema A (Users) { name: 'Demo', postId: 'someObjectId', } Schema B (Posts) { id: 's ...

Is there a way to execute numerous queries upon the loading of a functional component with UseEffect, and then display the results within the render method

I've created a functional component that loops through an array on load to run async queries and populate a new array for display in the render method. import React, { useEffect, useState, useContext } from 'react'; import { AccountContext ...

The Bootstrap modals seem to be invisible within the Rails application

Currently, I am integrating jquery into the devise views of a sample rails application. My intention is to test it on a sample app before implementing it in a production code. The controller and view for welcome are already set up. The routes.rb file loo ...

Explain what mongoose and Schema are at the beginning, just once

Hello, I am currently working on a Node.js application using Express and MongoDB. In order to utilize MongoDB and schema, I have to define Mongoose and schema in all of my routing JavaScript files. However, I would like to only define them once. As I am ne ...