Hi experts, I want to know the positions of the line vertices in a LineSegements object after it transforms. The property “geometry.attributes.position.array” only gives the coordinates in its original coordination system. Could you tell me how to obtain the new position info?
How to make a line (defined by two points) follow the translation/rotation/scaling of a 3D object
When you extract a vertex from the position attribute, it has indeed no transformation applied to it. If you want to transform it to model space, do this:
vertex.applyMatrix4( line.matrix );
If you need the vertex in world space, do this:
vertex.applyMatrix4( line.matrixWorld );
Mugen87, thanks a lot! Does the vertex in your reply refer to any vertex (or point) in the LineSegments (or its coordinate system)? My problem is perhaps more complicated than that I described yesterday. The LineSegements object (theChild) is actually a child of another object(theFather). when I run
vertex.applyMatrix4(theFather.theChild.matrix) — no change on the vertex
vertex.applyMatrix4(theFather.theChild.matrixWorld) — no change on the vertex
vertex.applyMatrix4(theFather.matrixWorld) — no change on the vertex
vertex.applyMatrix4(theFather.matrix) , vertex has moved to the position of theFather, and other points on theChild undergo the same translation, without scaling and rotation if we take the points as a whole.
I saw a .localToWorld method in the threejs doc, which might be useful. But it seems that it is for testing only and not in the libs.
Could you give me more suggestions?
You should definitely make sure that your matrices are actually up-to-date. Call at least
theFather.updateMatrixWorld() once before you perform any computations.
Object3D.localToWorld() also relies on a up-to-date world matrix.
Thank you for your critical advice, Mugen87. It took me quite some time to understand the sequence of updates, as the console of Chrome sometimes gives me confusing info. Anyway, I’ve got what I wanted.