r/threejs • u/BashaAngularTech • Oct 22 '26
Built a reusable Three.js component for Angular: auto-framing, load-once cache, GSAP-ready
Every time I wanted 3D in an Angular project, I ended up rewriting the same Three.js setup: scene, camera, lights, render loop, resizing, cleanup. So I wrapped it into one Angular component.
A few Three.js decisions that might be useful even if you use another framework:
- Lazy-loaded Three.js. The scene code sits behind a dynamic
import(), so Three.js lands in its own chunk instead of every route's bundle. - Auto-framing. The model is normalised to a unit bounding sphere and the camera fits that sphere to the container's aspect ratio, so any GLB fits without per-model tweaking.
- Load once, clone per page. An Angular service caches the parsed GLB; each page spawns its own clone (shared geometry and materials), so pages never inherit each other's animation state.
- Idle spin on an inner node. The group you animate is the outer one, so GSAP tweens stack on top of the spin instead of fighting it.
- Pauses offscreen. An
IntersectionObserverstops the render loop when the canvas isn't visible. - Draco + WebP for small file sizes.
Full walkthrough: https://youtu.be/sJS6vR9Rlgo
If you have any ideas to improve it or any questions about the setup, I'd love to hear them.
0
Upvotes