This course was updated in 2024. For the newer content, please visit Object3D Hierarchy
Video Lecture
Description
The scene is an Object3D. You can add other Object3Ds to the scene and they become children of the scene. The scene itself is derived from the Object3D base class.
If you rotate the scene, or scale the scene, or 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.
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 of the children under the same parent equally.
It is possible to create a Hierarchy of Object3Ds by continually adding new objects to any existing objects.
scene
|--object1 (Red Ball)
|--object2 (Green Ball)
|--object3 (Blue Ball)
In this example, the blue ball is a child of the green ball, which 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.
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.
obj.position// values are local transformobj.rotation// values are local transformobj.quaternion// values are local transformobj.scale// values are local transform
<!DOCTYPE html><htmllang="en"><head><metacharset="utf-8"/><metaname="viewport"content="width=device-width, initial-scale=1"/><title>Three.js TypeScript Tutorials by Sean Bradley : https://sbcode.net/threejs</title><style>body{overflow:hidden;margin:0px;}#debug1{font-family:monospace;font-size:larger;position:absolute;left:0px;top:50px;border:1pxsolidred;width:180px;height:220px;color:white;pointer-events:none;}</style></head><body><divid="debug1"></div><scripttype="module"src="bundle.js"></script></body></html>