16

I load a lot of random glTF models and half of them arrived either microscopic or filling the whole viewport. I kept manually tweaking camera distance per model like an animal.

So I wrote a prompt that computes the bounding sphere and derives the camera position, near/far planes, and OrbitControls min/max distance from it. The key insight I had to spell out was to set controls.target to the bounding-sphere center, otherwise rotation pivots around origin and the model swings out of frame.

Still undecided on damping factor. What feels right to you for inspection-type scenes?

THE PROMPT
Given a three.js scene where I load a glTF via GLTFLoader, write a `frameObject(object3d, camera, controls)` helper. Requirements:
- Compute a `Box3().setFromObject` then its bounding sphere (center + radius).
- Position the camera along the current view direction at distance `radius / sin(fov/2 * DEG2RAD)` times a 1.4 padding factor so the model fills ~70% of the frame.
- Set `camera.near = radius/100`, `camera.far = radius*100`, then `updateProjectionMatrix()`.
- Set `controls.target` to the sphere center; set `controls.minDistance = radius*1.1` (can't fly inside the mesh) and `controls.maxDistance = radius*10`.
- Enable `enableDamping` with `dampingFactor = 0.08` and call `controls.update()` each frame.
- Return the computed radius so I can scale a ground grid to match.
No magic numbers without a comment explaining the geometry. Assume three r160+ module syntax.
20.08 damping feels great for inspection. i go up to 0.12 for tiny jewelry-scale models so the rotation doesn't overshoot.coffee_compiler 2 months ago
add a comment

0 Answers

Your Answer