[Solved] Group Mesh Recalculation

Hello,

I am trying to update a Mesh in a group.
If I create a new Mesh and add it to the group, the hierarchy is preserved but the recalculation is slightly off.

let sp = new THREE.Mesh(connector_geometry, backbone_materials[Math.floor(current_nuc.my_strand % backbone_materials.length)]);
sp.applyMatrix(new THREE.Matrix4().makeScale(1.0, sp_len, 1.0));
sp.applyMatrix(rotation_sp);
sp.position.set(x_sp, y_sp, z_sp);
current_nuc.visual_object.add(sp);

If I simply recalculate using the current Mesh, either the Mesh continues to rotate and grow in size.

let sp = current_nuc.visual_object.children[4];
sp.applyMatrix(new THREE.Matrix4().makeScale(1.0, sp_len, 1.0));
sp.applyMatrix(rotation_sp);
sp.position.set(x_sp, y_sp, z_sp); 

If I create a new Mesh and push it to the children array of the group or set it to the current Mesh, the new Mesh is correct but the the parent hierarchy is deleted.

let sp = new THREE.Mesh(connector_geometry, backbone_materials[Math.floor(current_nuc.my_strand % backbone_materials.length)]);
sp.applyMatrix(new THREE.Matrix4().makeScale(1.0, sp_len, 1.0));
sp.applyMatrix(rotation_sp);
sp.position.set(x_sp, y_sp, z_sp);
current_nuc.visual_object.children[4] = sp;

How do I get the correct calculations and maintain the hierarchy?

Thank you for all of your help!

Can you please illustrate the problem with a simple live example? You don’t have to post your entire code, just focus on the part that messes up your hierarchy.

Thank you for your response! I figured out the problem was that when I add the Mesh to the group and use DragControls to move the group, the Mesh’s world position is a sum of the new group position and its recalculated position, causing it to be incorrect. However, if I subtract the group position from the recalculated position before resetting the positions x_sp, y_xp, and z_sp, it works properly.