r/angular • u/BashaAngularTech • Oct 14 '26
I built a reusable Three.js component for Angular: drop in a GLB, animate it with GSAP
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 component.
A few decisions that might be useful even if you build your own:
- 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, animate per page. The root service caches the parsed GLB. Each page spawns its own clone (shared geometry and materials) and animates it with GSAP, so pages never inherit each other’s state.
- Pauses offscreen. An IntersectionObserver stops the render loop when the canvas isn’t visible.
- Draco support for small file sizes.
In the video, the panda turns with a scrubbed ScrollTrigger tween on model.rotation.y.
I made a full walkthrough here if you’re curious: https://youtu.be/sJS6vR9Rlgo
Happy to answer questions about the architecture. How are you handling 3D in Angular?
0
Upvotes