Object3D Hierarchy

Description

The scene is an Object3d. You add Other Object3Ds to the scene and they become children of the scene. If you rotate the scene, or scale the scene, of translate its position, it will affect all if its child objects.

You make an Object3D a child of another Object3D by using the parents add method.

1
scene.add(cube)

You can also add Object3Ds to other Object3Ds that are already part of the scene. Any changes to the Object3D such as position, scale, rotation will affect all if the children under it equally.

It is a Hierarchy of Object 3Ds.

1
2
3
4
scene
    |--ObjectA 
             |--Object B
                       |--Object C

In this example, the blue ball is a child of the green ball, which in turn is a child of the red ball.

Any changes to the red ball will effect the green and blue balls,

Any changes to the green ball, will affect the blue ball, but not its parent, the red ball.

Any changes to the blue ball, have no effect on its parent, or grand parent balls.

Any number of Object3Ds can be added as children of other Object3Ds.

An Object3D can have only 1 parent, and you can change its parent dynamically any time.

Changing an Object3Ds parent will affect the current position, scale and rotation based in the parent it has now become a child of.

1
2
3
4
5
6
scene.position.set(0, 0, 0) // this is default position of a scene, and any Object3Ds
cube.position.set(5, 0, 0) // cube is offset x = 5 from of its parent.
scene.add(cube) // add the cube to the scene. The scene becomes its parent Object3D.

sphere.position.set(3, 0, 0) // sphere is offset x = 3 from the center of its parent.
cube.add(sphere) // The spheres parent is now the cube. The sphere will be x=3 offset from the cube in local space. So that will be 8 in world space since the cube is a child of the scene and is already offset x = 5.

Getting an Object3D transform, such as position, rotation/quaternion and scale will return the values in local transform space. If the Object3D is a direct descendant of the scene, then the world space values will be identical.

If your Object3D is a child of another Object3D which is already a child of the scene, then the world transform values will also consider the transforms of its parent, grandparents, great grandparents etc.

1
2
3
obj.position    // values are local transform
obj.rotation    // values are local transform
obj.scale       // values are local transform

To get the world transforms of an object,

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
const objectsWorldPosition = new THREE.Vector3()
object.getWorldPosition(objectsWorldPosition)

const objectsWorldDirection = new THREE.Vector3()
object.getWorldDirection(objectsWorldDirection)

const objectsWorldQuaternion = new THREE.Quaternion
object.getWorldQuaternion(objectsWorldQuaternion)

const objectsWorldScale = new THREE.Vector3()
object.getWorldScale(objectsWorldScale)