Object3D
Quick answer
Object3D is the scene-graph node base class, supplying position, rotation, quaternion, scale, parent, children, and world matrix transforms. Nearly everything added to a scene inherits from it, so understanding add(), traverse(), getWorldPosition(), and matrix updates is essential. Set name for lookup, and layers for selective camera rendering.
new THREE.Object3D ()
Key points
- position is local to the parent; use getWorldPosition() for absolute coordinates.
- add() reparents an object automatically, removing it from its previous parent.
- matrixAutoUpdate false lets static objects skip per-frame matrix rebuilds.
Example
const building = new THREE.Group();
building.position.set(120, 0, -40);
const floor = new THREE.Mesh(floorGeometry, floorMaterial);
floor.position.y = 3;
building.add(floor);
const roof = new THREE.Mesh(roofGeometry, roofMaterial);
roof.position.y = 9;
floor.add(roof); // 挂在地板下,跟随地板的变换
scene.add(building);
const worldPos = roof.getWorldPosition(new THREE.Vector3());
console.log(worldPos);
building.traverse(function (obj) {
if (obj.isMesh) {
obj.castShadow = true;
}
});
Notes
- remove() does not dispose geometry or materials, so GPU memory stays allocated.
- Reading matrixWorld before updateMatrixWorld() yields a stale transform.
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Atlaslog (2026). Object3D. https://www.jingweizhi.com/en/three/api/object3d.html (accessed 2026-11-03).