Building a Production React Three Fiber Meshy Pipeline
A practical guide for Malaysian businesses on creating efficient 3D web assets. Learn our React Three Fiber Meshy pipeline: from text-to-3D generation to gltfpack compression and lazy-loading for fast performance.
Adding 3D elements to a website can significantly enhance user engagement, whether for e-commerce product showcases or interactive data visualizations. The challenge has always been performance. Heavy 3D assets can cripple page load times, especially on mobile networks common across Malaysia. Generative AI tools like Meshy.ai have made creating models easier, but they don't solve the performance problem alone. A systematic process is needed.
At JRV Systems, we've developed a pipeline to take AI-generated 3D models from concept to a performant, production-ready state. This process focuses on optimization at every step, ensuring the final asset is lightweight without sacrificing quality.
The React Three Fiber Meshy Pipeline: An Overview
A successful React Three Fiber Meshy pipeline isn't just about using tools; it's about a repeatable workflow. Our approach consists of four main stages:
- Generate: Use a text-to-3D service like Meshy.ai to create the initial model from a descriptive prompt.
- Refine: Clean up the model's geometry and topology using a standard 3D editor like Blender. This step is non-negotiable for quality.
- Compress: Drastically reduce the file size using a specialized tool like
gltfpack. - Implement: Load the optimized model into a React Three Fiber scene, gated by an
IntersectionObserverto prevent it from loading until it's visible.
Following these steps allows us to consistently produce assets that are often under 100KB, a critical threshold for fast-loading web experiences.
Step 1: Generating 3D Models with Meshy.ai
Meshy.ai is a service that generates 3D models from text prompts. The process is straightforward: you describe what you want, and the AI builds it. For example, a prompt like "a minimalist wooden stool, light oak, three legs" can produce a usable base model in minutes.
The quality of the output depends heavily on the prompt's specificity. The initial model is usually delivered in GLB format. While impressive, these AI-generated models are rarely production-ready. They often have extremely high polygon counts and inefficient geometry, resulting in large file sizes (e.g., 500KB - 2MB) that are unsuitable for the web.
Meshy operates on a credit system. As of late 2023, generating a single model costs around 5 credits. A package of 1,000 credits costs about $20 USD, making it a cost-effective way to quickly prototype assets.
Step 2: Refining and Preparing the Model in Blender
This is the most crucial manual step. We import the raw GLB file from Meshy into Blender, a powerful and free open-source 3D software. The goal here is not to become a 3D artist, but to perform essential cleanup.
First, we inspect the model for geometric errors—floating vertices, non-manifold edges, or inverted faces. We then focus on reducing the polygon count using Blender's 'Decimate' modifier. The key is to find a balance: lower the polygon count as much as possible without visibly degrading the model's silhouette and key features. For a simple prop, we aim to get the polygon count down to between 5,000 and 15,000 triangles.
This manual refinement step is what separates a professional result from a raw AI output. It gives us control over the final look and is the first major step in optimization.
Step 3: Compression with gltfpack
After refining the model in Blender, we export it again as a GLB. The file size will already be smaller, but the final optimization comes from gltfpack. This is a command-line tool developed by zeux that optimizes GLTF and GLB files for web delivery.
gltfpack performs several optimizations, including mesh simplification, quantization (reducing the precision of vertex data), and texture compression using the Basis Universal format (KTX2). Running a single command can yield dramatic results.
A typical command looks like this:
gltfpack -i model_from_blender.glb -o model_production.glb -cc
The -cc flag applies a suite of compression techniques. It's common for us to see a 300KB model from Blender shrink to just 75KB after this step, with almost no perceptible difference in quality. This is how we consistently hit our sub-100KB target.
Step 4: Implementation in React Three Fiber
With our highly optimized model_production.glb file, we can now bring it into our web application. We use React Three Fiber (R3F) as it provides a declarative, component-based way to build Three.js scenes within a React app.
However, even a 100KB file can impact initial page load if it's loaded immediately. To solve this, we don't render the R3F <Canvas> component directly. Instead, we use a wrapper component that employs the IntersectionObserver API. This browser API allows us to detect when an element enters the viewport.
Our component only mounts and loads the R3F scene (and thus the 3D model) when the user scrolls it into view. This technique, known as lazy-loading, is fundamental to our work at JRV Systems. It ensures that the initial page load remains fast and light, and the 3D content is loaded only when needed.
When to Use Spline Instead
Spline is another popular tool for creating 3D web experiences. It offers an all-in-one, browser-based editor and hosting solution. So, when does it make sense to use Spline over our React Three Fiber Meshy pipeline?
Spline excels at creating complex, interactive, and animated 3D scenes, not just individual assets. If your goal is a self-contained experience with multiple objects, animations, and user interactions (like a mini-game or a detailed product configurator), Spline is often the faster and more direct tool.
However, for integrating a single, optimized product model or a decorative element into an existing website, our pipeline offers more control and better performance. A Spline embed can be significantly heavier than a single optimized GLB file, and you have less control over the loading process. We see Spline as an 'escape hatch' for complex interactive scenes, not the default choice for displaying a simple, performant 3D model.