Skip to main content
This example demonstrates how to build a 3D reconstruction pipeline that streams voxel data in real-time during diffusion. Watch your 3D models take shape progressively as geometry and appearance diffusion stages run.

🚀 Try this Example

View the complete source code on GitHub. Live Demo: manifold-jet.vercel.app Steps to run:
  1. Install fal:
  1. Authenticate:
  1. Clone the repository with submodules:
  1. Set up the frontend:
  1. Configure environment variables in frontend/.env.local:
  1. Run the development server:
Open http://localhost:3000 to see the demo.
You can use the hosted endpoint rehan/sam-3d-stream directly, or deploy your own custom endpoint to modify the reconstruction pipeline.

How it Works

  1. Prompt Enhancement — Groq LLM (llama-3.3-70b) rewrites your text into an optimized image prompt + segmentation label
  2. Image Generationfal-ai/z-image/turbo generates a 3D-ready image in ~1s
  3. 3D Reconstruction — SAM-3D runs geometry and appearance diffusion on H100, streaming voxel data via SSE callbacks at each denoising step
  4. Live Visualization — React Three Fiber renders voxels/mesh/GLB in real-time as data streams in
For image-to-3D, a vision model analyzes the uploaded image to generate the segmentation prompt.

Deploy Your Own Endpoint

To customize the SAM-3D backend, deploy your own:
Then update FAL_ENDPOINT_ID in .env.local with your new endpoint ID.

Key Features

  • Progressive Rendering: See voxels appear during both geometry and appearance diffusion stages
  • Binary Streaming Protocol: Efficient base64-encoded voxel data (xyz + rgb per voxel)
  • Multiple Output Formats: Voxels, vertex-colored mesh preview, and final GLB model
  • Custom Container: Complex CUDA dependencies handled via Dockerfile
  • H100 GPU: High-performance inference for fast reconstruction

Backend Architecture

The serverless endpoint uses Server-Sent Events (SSE) for streaming progressive updates:

SSE Event Types

The streaming endpoint emits these event types:

Binary Voxel Encoding

Voxels are packed as uint8 arrays for efficient streaming:

Frontend Integration

The React frontend uses a custom hook to consume the SSE stream:

Voxel Rendering with Three.js

Use React Three Fiber to render the streaming voxels:

Custom Container Image

The backend requires complex CUDA dependencies. Use a Dockerfile for full control:

Input Parameters

Project Structure

Performance Considerations

Streaming Frequency

Control the streaming frequency to balance smoothness vs. performance:

Binary Encoding

The binary encoding reduces payload size significantly compared to JSON:
  • 6 bytes per voxel (xyz + rgb as uint8)
  • ~10,000 voxels = ~60KB per frame
  • Base64 encoding adds ~33% overhead

Key Takeaways

  • SSE streaming enables real-time visualization of long-running 3D reconstruction
  • Binary encoding makes voxel streaming efficient over HTTP
  • Custom containers handle complex GPU dependencies (CUDA, PyTorch3D, kaolin)
  • Progressive rendering gives users immediate visual feedback during generation
  • H100 GPUs provide the compute power needed for fast 3D diffusion
This pattern demonstrates how to build interactive 3D AI applications that provide real-time feedback, combining the power of diffusion models with efficient streaming protocols and modern web rendering.