Setting matrixWorld and attaching to parent overwrites the rotations with [I]

I’m trying to load the helmet GLTF and replace each Mesh with its “thick” Wireframe equivalent but I end up with an unexpected 90 degree pitch in the end.

2022-11-10 13_48_42-Edit fiddle - JSFiddle - Code Playground - Brave

I traverse the node tree twice. On the first pass I run updateWorldMatrix() on each node, then create a new Wireframe node for each Mesh node I find and copy the Mesh.matrixWorld into the new Wireframe.matrixWorld. I don’t make any changes to the node tree on the first pass; the new Wireframe nodes and other bookkeeping data go into a temporary map structure.

On the second traversal pass, I assign each of the new Wireframe nodes to their proper parents in the node tree using parent.attach().

Finally, I iterate through the temporary map to delete the original Mesh nodes from the node tree.

The parent.attach() call seems to be squashing the rotations and I don’t know what I’m missing. What is the proper procedure to give a node a world rotation and then attach it to another node so that it calculates a valid local reference frame?

Before you go, let me play you something on my fiddle: Wireframe#3 - JSFiddle - Code Playground

If you want to add an object of lines to the object it was made from (a base object), then why do you apply .worldMatrix of the base object to it?

I want to attach the object of lines to the parent of the base object, not to the base object itself. I’m trying to replace the original base object with a wireframe version of itself.

Seems I succeeded with it here :thinking: LDraw-like edges - #42 by prisoner849

1 Like

Thank you. I’ll check it out.

Fixed by attaching the new node first and then copying the position and quaternion.

parent.attach(child)
child.position.copy(sibling.position)
child.quaternion.copy(sibling.quaternion)

Treat Object3D.matrixWorld as a read-only value.

have u checked the axis? make sure u are using y axis instead of the z axis