You can get a 3D product viewer working locally in an afternoon. In production, problems show up that the demo never reveals: file size, inconsistent export scales, lighting, scroll trapping and analytics. This article covers how I handle them with React Three FiberGlosarioReact Three Fiber (R3F)React Three Fiber (R3F) es un renderizador declarativo de Three.js para React. Permite construir escenas 3D interactivas utilizando componentes React reutilizables con gestión de estado nativa y ciclo de vida de React., based on the viewer for the official t-shirt of a 10K race, a real case in production.
The page first, the 3D after
Three.js, its helpers and the model add up to hundreds of kilobytes the first paint doesn't need. Importing the viewer with lazy moves all of that into a separate chunk that's only downloaded when the page mounts it.
const TShirtViewer = lazy(() => import('../components/3d/TShirtViewer'));
export const TShirt3DPage = () => (
<>
{/* Title, copy and details render without waiting for WebGL */}
<Suspense fallback={<Loader />}>
<TShirtViewer color="#ffffff" />
</Suspense>
</>
);The page content renders first and the viewer loads in when it's ready. With that split, it doesn't block the page's FCPGlosarioFCP (First Contentful Paint)First Contentful Paint (FCP) es una métrica de rendimiento que mide el tiempo transcurrido desde que el usuario inicia la carga de la página hasta que el navegador dibuja el primer fragmento de contenido (texto, imagen o gráfico vectorial) en la pantalla. or LCPGlosarioLCP (Largest Contentful Paint)Largest Contentful Paint (LCP) es una métrica clave de Core Web Vitals que mide el tiempo necesario para renderizar y pintar el elemento visual o bloque de texto más grande en la pantalla (usualmente la imagen Hero o banner principal)..
The model in this case shipped as an OBJ of about 1.7 MB, with a 380 KB JPG texture. A GLB compressed with Draco or meshopt is much smaller, and it's the quickest win if the model gets heavier.
One fixed size for any model
Every designer exports at a different scale. Rather than tweaking each model by hand, the viewer reads its bounding box and normalises it to a fixed size, centred on the origin. Only visible meshes are counted.
const { positionOffset, scale } = useMemo(() => {
scene.updateMatrixWorld(true);
const box = new THREE.Box3();
scene.traverse((child) => {
if (child.isMesh) box.expandByObject(child);
});
const center = box.getCenter(new THREE.Vector3());
const size = box.getSize(new THREE.Vector3());
const maxDim = Math.max(size.x, size.y, size.z);
const targetSize = 2.2;
return {
positionOffset: new THREE.Vector3(-center.x, -center.y + yOffset, -center.z),
scale: maxDim > 0 ? targetSize / maxDim : 1,
};
}, [scene, yOffset]);The yOffset parameter nudges the model up or down from the centre, which helps when most of a garment's visual weight sits in the top half.
OBJ and GLTF don't read textures the same way
OBJ and GLTF disagree on texture orientation: OBJ needs the vertical axis flipped, GLTF doesn't. A small factory picks the right loader from the file extension, so the rest of the viewer never has to care about the format.
function ModelFactory({ url, color, textureUrl, yOffset = 0 }) {
const extension = url.split('.').pop().toLowerCase();
if (extension === 'glb' || extension === 'gltf') {
return <GltfModel url={url} color={color} textureUrl={textureUrl} flipY={false} yOffset={yOffset} />;
}
return <ObjModel url={url} color={color} textureUrl={textureUrl} flipY={true} yOffset={yOffset} />;
}Set the texture's colour space to sRGB. Without it, brand colours come out washed out.
texture.colorSpace = THREE.SRGBColorSpace;
texture.flipY = flipY;
texture.needsUpdate = true;Lights that rotate like in a shop window
A fixed light makes fabric look flat. A group of directional lights slowly orbiting the model shifts the shadows and brings out the folds, like a shop-window display. Using useFrame with each frame's delta keeps the speed independent of the device's refresh rate.
function RotatingLights() {
const groupRef = useRef();
useFrame((state, delta) => {
if (groupRef.current) groupRef.current.rotation.y += delta * 0.4;
});
return (
<group ref={groupRef}>
<directionalLight position={[4, 2, 4]} intensity={3} color="#C4AA93" />
<directionalLight position={[-4, 1, -4]} intensity={5} color="#5A2030" />
<directionalLight position={[0, 4, 0]} intensity={3} color="#ffffff" />
</group>
);
}The light colours come from the brand palette, so the model feels like part of the site.
Nobody gets trapped in the viewer
Dragging a 3D model on a touchscreen, or scrolling the mouse wheel over it, can leave users stuck in the viewer, unable to scroll on down the page. The fix: start the viewer paused, with pointer events disabled, and let users switch it on with a button.
const [isActive, setIsActive] = useState(false);
<div className={isActive ? 'pointer-events-auto cursor-grab' : 'pointer-events-none'}>
<Canvas camera={{ position: [0, 0, 4], fov: 40 }}>
<OrbitControls
enabled={isActive}
enableZoom={isActive}
enablePan={false}
minDistance={1.5}
maxDistance={4}
minPolarAngle={Math.PI / 6}
maxPolarAngle={Math.PI / 1.5}
/>
{/* model and lights */}
</Canvas>
</div>
{!isActive && <button onClick={() => setIsActive(true)}>Activate 3D view</button>}Distance and polar-angle limits keep the camera in a useful range, so users can't end up underneath the garment or zoom out until it disappears. With enablePan off, the model always stays centred. In this case the paused state applied on desktop as well as mobile, because the mouse wheel hijacks scrolling too.
No WebGL? No empty box
Two checks prevent an empty frame. First, if the browser can't create a WebGL context, show a message instead of the viewer.
useEffect(() => {
try {
const canvas = document.createElement('canvas');
const gl = canvas.getContext('webgl') || canvas.getContext('experimental-webgl');
if (!gl) setWebGLSupported(false);
} catch {
setWebGLSupported(false);
}
}, []);Second, and this is what I do on my own site, serve a still image on mobile or when the user prefers reduced motion.
const reduced = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
const showStatic = isMobile || reduced;
return showStatic ? <img src={STATIC_IMAGE} alt="3D t-shirt" width="800" height="600" /> : <ShirtScene />;An image with explicit width and height reserves its space and avoids layout shifts (CLSGlosarioCLS (Cumulative Layout Shift)Cumulative Layout Shift (CLS) es una métrica de Core Web Vitals que mide la frecuencia y la magnitud con la que los elementos visibles en la pantalla cambian de posición de forma inesperada durante la carga de la página.).
Every spin becomes an Analytics event
If you don't measure a 3D viewer, you can't prove it's worth having. Turn every gesture into a Google Analytics event and the team can see how many people activate it, spin it and zoom in.
trackEvent('activate_3d', { category: 'T-Shirt 3D', label: 'Desktop Activation' });
<OrbitControls
onStart={() => trackEvent('interact_3d_tshirt', { category: 'T-Shirt 3D', label: 'Orbit Start' })}
/>The zoom buttons fire their own events, and so does closing the viewer. That separates people who glance from people who explore. Turning those events into reports you can compare across editions and sponsors is covered in SEO for a sports event website.
Seven checks before you publish
- The viewer is lazy-loaded and the page content doesn't wait for it.
- Scale and centring are computed from the model, not tweaked by hand.
- Textures in sRGB, with orientation set per format.
- Lights in brand colours, with speed based on
delta. - The viewer stays paused until the user activates it, with camera limits in place.
- A fallback message without WebGL and a still image for reduced motion.
- One analytics event per meaningful gesture.
A viewer that ticks these seven boxes won't drag down page performance, and it produces data a sponsor can actually use.