Howto move a node retrieved with getNodeByName()

I loaded a scene with glTF
I want to move some nodes,
I can retrieve nodes using getNodeByName() but how to move these nodes ???


it depends what you mean by move , do you mean setting transform properties or do you mean reparenting?

if you mean re-parenting then first make sure your node is of type TransformNode , then there are two ways , if you use the getter/setter then the transform properties will be affected by the new parent transform properties :

if you use the setParent function it will keep its transform properties in regards to global space and the local transform properties will be updated to be relevant to the new parent :


I mean transform properties (rotation/translation)
In my blender file exported to gltf, I setted up empty axes to do this

I would like to use GetNodeByName(“axe1”) and then set transforms on this axis

just scroll up in the same documentation page , you will see the transform node has position , rotation and scaling getters/setters. All three use a Vector3 object :

so for example :

myTransformNode.position =  new BABYLON.Vector3(0, 0, 0);
myTransformNode.rotation=  new BABYLON.Vector3(0, 0, 0);
myTransformNode.scaling=  new BABYLON.Vector3(1,1, 1);

the babylon vector class has some helpers for common vectors like these above , as do most other 3D engines , so above could be :

myTransformNode.position =  BABYLON.Vector3.Zero();
myTransformNode.rotation=  BABYLON.Vector3.Zero();
myTransformNode.scaling=  BABYLON.Vector3.One();

I managed doing it using the Node retrieved by getNodeByName()

node.rotation =  new Vector3(0,0,0);
node.rotation.y = wantedrotation

great glad to help , not sure why you did not just use the variable in the vector creation , eg

node.rotation = new Vector3(0,wantedrotation,0);

anyway you should definitely make it a habit to use the documentation pages to try to find out how to do things , it is great at overall faster turn around time in your developments.


1 Like