Function setParent
-
Parameters
- child: Mesh
The node to reparent (mesh, transform node, camera, light, or any SceneNode).
- parent: IWorldMatrixProvider | null
The new parent (any world-matrix provider), or
nullto detach to world space.
Returns void
- child: Mesh
-
Reparents
childwhile preserving its current world-space transform, mirroring Babylon.jsTransformNode.setParent(). Also keeps the scene-graphchildrenarrays consistent: the child is removed from its previous parent'schildrenand appended to the new parent's, so traversal helpers see the new hierarchy.The world transform is preserved exactly, mirrors included:
decomposeMat4keeps a negative determinant (as a negative Y scale), and a node created from a raw matrix (createSceneNodeFromMatrix, used for glTFmatrixnodes) is switched to TRS so the new local transform actually takes effect.Preservation is impossible when
parent's world matrix is singular — a collapsed axis has no inverse, so no local transform can reproduce the child's world. In that case the child keeps the parent link and its world position is copied into its local position, but its rotation and scale are not compensated.child.parentlinks are only established byaddToScene, so when reparenting a node from inside a freshly loaded asset, add the container first — otherwise the child's "world" matrix is just its local one and the reparent is computed against the wrong space.Parameters
- child: SceneNode
The node to reparent (mesh, transform node, camera, light, or any SceneNode).
- parent: IWorldMatrixProvider | null
The new parent (any world-matrix provider), or
nullto detach to world space.
Returns void
- child: SceneNode
Reparents
childwhile preserving its current world-space transform, mirroring Babylon.jsTransformNode.setParent(). Also keeps the scene-graphchildrenarrays consistent: the child is removed from its previous parent'schildrenand appended to the new parent's, so traversal helpers see the new hierarchy.The world transform is preserved exactly, mirrors included:
decomposeMat4keeps a negative determinant (as a negative Y scale), and a node created from a raw matrix (createSceneNodeFromMatrix, used for glTFmatrixnodes) is switched to TRS so the new local transform actually takes effect.Preservation is impossible when
parent's world matrix is singular — a collapsed axis has no inverse, so no local transform can reproduce the child's world. In that case the child keeps the parent link and its world position is copied into its local position, but its rotation and scale are not compensated.child.parentlinks are only established byaddToScene, so when reparenting a node from inside a freshly loaded asset, add the container first — otherwise the child's "world" matrix is just its local one and the reparent is computed against the wrong space.