I have a child object3D that is part of a group Object3D. While the child object's position is displayed relative to the parent object's space, I am trying to change the location of the child object within the 3D space. To do this, I first need to obtain the child object's position in the world space.
var worldPosition = childObject.matrixWorld.multiplyVector3(new THREE.Vector3);
This gives me a vector representing the child's position in the world space. Next, I want to manually set the position. So I create a new vector with three elements.
var newPosition = new THREE.Vector3();
newPosition.x = 1;
newPosition.y = 2;
newPosition.z = 3;
childObject.matrixWorld.setPosition(newPosition);
The setPosition function sets the last three elements of the object's world matrix to the values of the vector provided as an argument, effectively changing the object's location in the world space. To ensure the matrix updates correctly after these changes, I use the following functions.
childObject.matrixWorldNeedsUpdate = true;
childObject.updateMatrixWorld();
However, upon inspecting the updated world matrix, I noticed that the setPosition function had no effect whatsoever.
Why is this happening? If you need actual code examples, I can provide them. But the above explanation accurately reflects the domain and syntax I am working with.