Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
45
rated 0 times [  52] [ 7]  / answers: 1 / hits: 17260  / 7 Years ago, wed, november 15, 2017, 12:00:00

I am new to Three.js so perhaps I am not going abut this optimally,



I have geometry which I create as follows,



const geo = new THREE.PlaneBufferGeometry(10,0);


I then apply a rotation to it



geo.applyMatrix( new THREE.Matrix4().makeRotationX( Math.PI * 0.5 ) );


then I create a Mesh from it



const open = new THREE.Mesh( geo, materialNormal);


I then apply a bunch of operations to the mesh to position it correctly, as follows:



open.position.copy(v2(10,20);
open.position.z = 0.5*10

open.position.x -= 20
open.position.y -= 10
open.rotation.z = angle;


Now what is the best way to get the vertices of the mesh both before and after it's position is changed? I was surpised to discover that the vertices of a mesh are not in-built into three.js.



Any hints and code samples would be greatly appreciated.


More From » three.js

 Answers
57

I think you're getting tripped-up by some semantics regarding three.js objects.



1) A Mesh does not have vertices. A Mesh contains references to Geometry/BufferGeometry, and Material(s). The vertices are contained in the Mesh's geometry property/object.



2) You're using PlaneBufferGeometry, which means an implementation of a BufferGeometry object. BufferGeometry keeps its vertices in the position attribute (mesh.geometry.attributes.position). Keep in mind that the vertex order may be affected by the index property (mesh.geometry.index).



Now to your question, the geometric origin is also its parent Mesh's origin, so your before mesh transformation vertex positions are exactly the same as when you created the mesh. Just read them out as-is.



To get the after mesh transformation vertex positions, you'll need to take each vertex, and convert it from the Mesh's local space, into world space. Luckily, three.js has a convenient function to do this:



var tempVertex = new THREE.Vector3();
// set tempVertex based on information from mesh.geometry.attributes.position

mesh.localToWorld(tempVertex);
// tempVertex is converted from local coordinates into world coordinates,
// which is its after mesh transformation position

[#55924] Monday, November 13, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
janjadonb

Total Points: 4
Total Questions: 114
Total Answers: 118

Location: Mali
Member since Fri, Dec 3, 2021
3 Years ago
janjadonb questions
;