What is the process for determining the vertex position of geometry in three.js after applying translate, rotate, and scale transformations?

I've recently delved into the world of three.js.

My current goal involves creating a curve within the scene and subsequently applying some transformations to it. The function responsible for generating the line is showcased below:

var random_degree = Math.round(Math.rand() * 180);
var tmp = [
    new THREE.Vector3(-5, 0, 0),
    new THREE.Vector3(0, 0, 5),
    new THREE.Vector3(5, 0, 0),
    new THREE.Vector3(0, 0, -5),
];
var canvasW = window.innerWidth;
var canvasH = window.innerHeight;
// Initially, the curve forms a circle on the x-z plane.

function get_line_geo() {
    var angle = (random_degree + 1 * 0.25) % 360 * (Math.PI / 180);
    var tx = Math.cos(angle) * canvasW * 0.25;
    angle = (random_degree + 1 * 0.3) % 360 * (Math.PI / 180);
    var ty = Math.sin(angle) * canvasH * 0.25;

    var curve = new THREE.CatmullRomCurve3(tmp);
    curve.closed = true;

    var geometry = new THREE.Geometry();
    geometry.vertices = curve.getPoints(300);
    console.log(geometry.vertices[0].x + ' ' +geometry.vertices[0].y + ' ' +geometry.vertices[0].z);
    var material = new THREE.LineBasicMaterial();
    var curveObject = new THREE.Line(geometry, material);
    curveObject.translateX((canvasW - margin * 2) / 2 + tx);
    curveObject.translateY((canvasH - margin * 2) / 2 + ty);
    curveObject.translateZ((canvasH - margin * 2) / 2 + ty);

    curveObject.rotation.x = ((random_degree + 1 * 0.25) % 360) * Math.PI / 180;
    curveObject.rotation.y = ((random_degree + 1 * 0.25) % 360) * Math.PI / 180;
    curveObject.rotation.z = ((random_degree + 1 * 0.25) % 360) * Math.PI / 180;

   curveObject.scale.x = 10;
   curveObject.scale.y = 10;
   curveObject.scale.z = 10;

   console.log(curveObject.geometry.vertices[0].x + ' ' +curveObject.geometry.vertices[0].y + ' ' +curveObject.geometry.vertices[0].z);

   return curveObject;
}

Upon closer inspection using console.log(), I noticed that the vertices' positions remained unchanged in the geometry context. Is there a method available to calculate new positions for these vertices?

Answer №1

The transformations were applied not to the geometry, but to the object.

It is highly recommended to delve into the source code of the functions you utilize in order to grasp their functionality better. This will undoubtedly enhance your understanding.

Once alterations have been made to the position, rotation, or scale attributes of the object, remember to execute

curveObject.updateMatrix();

Followed by:

var vector = new THREE.Vector3();

vector.copy( curveObject.geometry.vertices[ 0 ] );

vector.applyMatrix4( curveObject.matrix );

console.log( vector );

three.js r.75

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

Testing the updated version 18 of Create React APP index.js using Jest

Previously, I had this index.js file created for React version <= 17. import React from 'react'; import ReactDOM from 'react-dom'; import App from './views/App'; import reportWebVitals from './reportWebVitals'; im ...

Do we always need to incorporate components in Vue.js, even if there are no plans for reuse?

I've been pondering this question for some time now: is it necessary for every component to be reusable? Consider a scenario where we have HTML, CSS, and JavaScript that cannot be reused. For instance, a CRUD table designed specifically for managing u ...

Execute a node script file at random intervals

I've been utilizing forever to maintain the continuous execution of a node script: forever start script1.js However, my requirement is to run these files in a random order... For instance: Execute node script1.js Execute node script2.js Run script ...

Incorporating multiple colors into a div with jQuery: A guide

I am looking for a way to create a legend by merging a specified number of colors within a div. I came across this useful Sample code that I have referenced. $.each(Array(50), function() { $("<div>").appendTo(document.body); }); var divs = $(&a ...

How can the vertical scroll bar position be reset in Material-Table when pagination is activated?

Whenever I scroll up or down in my Material-Table, and then switch pages, the vertical scroll bar doesn't reset to the top of the table. Instead, it stays where it was before changing the page, causing confusion for users. The only mention of scroll ...

ReactJS form example: utilizing two separate submit buttons to perform distinct actions on the same form

I need to implement two submit buttons in my form. Both buttons should utilize the same inputs and form validation, but trigger different actions. export default function FormWithTwoSubmits() { function handleSubmitTask1(){ } function handleSub ...

Using Three.js to rotate a camera-followed sphere in the scene

Currently, I'm developing a Three.js scene with a toy concept where I aim to track a sphere using a camera [demo]. However, I am facing an issue wherein I can't seem to get the sphere to "roll" without causing the camera to also rotate along with ...

Generating an error during mongoose callback

Currently, I am in the process of developing a Node.js + Express application. The database I am working with is Mongo, and I have integrated Mongoose to establish a connection with this database. In my code, I am attempting to handle exceptions within a M ...

Creating a nested tree structure array from a flat array in Node.js

I have an array structure that I need to convert into a tree array using node.js. The current array looks like this: var data= [ { "id1": 1001, "id2": 1002, "id3": 1004, ... } ...

Once this code is executed, Javascript ceases to function

I have developed a code snippet to create a typing effect similar to a command console. While the code is functioning well on its own, any additional code I add after it seems to malfunction. I've spent quite some time troubleshooting this issue witho ...

A proven method for distinguishing between desktop and mobile browsers

Similar Question: Exploring Browser Detection Methods in Javascript I am interested in finding an efficient way to differentiate between desktop and mobile browsers, either using JavaScript or PHP. if (desktop browser) { do x; } else { // mobi ...

Using AngularJS and ServiceStack webservice, perform the "get('url')" operation

I'm completely new to AngularJS and I'm attempting to retrieve some JSON items from a webservice I quickly set up using ServiceStack. When I enter the URL in the browser, I can see the JSON object without any issues. However, for some reason Angu ...

Resolved issue with maintaining scroll position after adjustments to scroll height

Currently, I am in the process of creating a chatroom that includes pagination. The issue I am encountering is related to loading old messages when the scroll height reaches 0. However, unlike platforms such as Facebook and Slack, even when the scroll he ...

When should CSS compression and combining / JS minification be performed - at runtime or during build time?

I need to find a way to compress, version (for caching reasons), and possibly combine our JS and CSS files. I've come across two main approaches so far: 1) During the build process: Using an MSBuild task or similar. 2) Dynamically at runtime: Through ...

Loop through the JSON object at a depth of three levels

Can someone please help me with this issue that's been bothering me? I'm currently working with Facebook's Graph API to access data. I need to find out how to retrieve the application name. { "data": [ { "messag ...

Change the class of each item in a list individually by hovering over them with the mouse using JavaScript

How to toggle classes in a list item one by one using the mouseover event in JavaScript? const items = document.querySelectorAll("ul li"); let currentItem; for (const item of items) { item.addEventListener("mouseover", e => { currentItem &am ...

What is the best way to access all of the "a" elements contained within this specific div?

Chrome websites are built using the following structure: <div class="divClass"> <a class="aClass"></a> <a class="aClass"></a> <a class="aClass"></a> </div> Utili ...

Tips for eliminating flicker upon the initial loading of a webpage caused by dynamic changes in CSS styles through JavaScript

Struggling with the load order of my CSS and JavaScript... Currently, I have a div with a blue background that is styled to appear sliced diagonally. However, upon initial page load (or CTRL+SHIFT+R), there's a brief moment where the slice effect doe ...

Authenticating with passportjs using a Google Apps email address for verification

I am currently experimenting with using Passport.js along with a Google Apps email ID. I have successfully been able to authenticate using a gmail.com email ID, however, I am facing challenges when attempting to authenticate if the email ID is associated w ...

The measurement of a HTML window's entire content height (not just the visible viewport height)

Currently, I am attempting to determine the total height of a webpage's content, not just what is visible. In my efforts, I have managed to achieve some success in FireFox using: document.getElementsByTagName('html')[0].offsetHeight. Howeve ...