10,000 objects: how many questions does a pick ask?
Ten clickable parts and 9,990 hidden pieces of scenery. The ray ignores visible, so hidden pieces still cost. Timings are never printed: they differ on every machine.
A ray asks every object in its list if it was hit. With 10,000 objects that is 10,000 questions per pick. You count the questions, cut them with layers and a short list, and meet GPU picking, which reads one pixel instead.
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 4 hands-on exercises with automatic checks.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Write pickableList(root) that returns every mesh under root whose userData.pickable is true.
Write idToColor(id) and colorToId(r, g, b) for GPU picking that can encode ids 1 to 16,777,215 in 3 bytes (0 means nothing).
Explain it without notes
A scene has 10,000 meshes and the customer can click 12 of them. Describe two ways to make picking cheaper without changing what the customer sees.
Why can GPU picking be faster than raycasting for a huge model, and what are its costs?
Console
Nothing logged yet.Expected console output
everything, layer 0 meshes asked: 10000 | first hit: part-3
only layer 1 (the 10 parts) meshes asked: 10 | first hit: part-3
only the list of 10 parts: meshes asked: 10