Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 3.4 — Object3D and Transforms
3D Web · Example 2 of 2

One parent only: add, add twice, attach, remove

No canvas needed: these are facts about the tree. Positions come from getWorldPosition after updateMatrixWorld().

Meshes, lights, cameras and groups are all Object3Ds with a position, rotation, scale and visibility. You learn add, remove, traverse and getObjectByName, and what happens when an object is hidden, scaled to 0, placed behind the camera or added twice.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 5 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Write a function findAll(root, namePrefix) that returns every object whose name starts with a prefix.

02

A model's parent is scene. Write the line that moves it to rack but keeps it where it is on screen.

Explain it without notes

01

What is the difference between visible = false, scene.remove(obj) and scale.set(0, 0, 0)?

02

What happens if you add the same mesh to two different groups?

One parent only: add, add twice, attach, remove
Press Run to see the page.
idle

Console

Nothing logged yet.

Expected console output

in left: left has 1 | right has 0 | world x = -1.5
added to right: left has 0 | right has 1 | world x = 2.5
added twice to right: right has 1 child
moved to scene: local x stays 0.5 | world x = 0.5 (its local number now means something else)
right.attach(wheel): local x = -1.5 | world x = 0.5
after remove: parent is null | right has 0 children
scene children: left, right