3D Interactive Scenes with Gemini 3 + Three.js
A tutorial by el.cine. Featured in the OTF curated resource library.
Why Gemini for 3D Development
Three.js has a notoriously steep learning curve. The API surface is vast—hundreds of classes for geometries, materials, lights, cameras, and post-processing effects. Even experienced developers spend hours consulting documentation.
Gemini 3 changes this equation dramatically. Its multimodal capabilities mean you can describe a scene in natural language, sketch it on a napkin, or show a reference image—and get working Three.js code in return. Gemini understands spatial relationships, lighting physics, and material properties at a level that produces surprisingly sophisticated scenes.
The workflow is especially powerful with React Three Fiber (@react-three/fiber), which wraps Three.js in React's declarative paradigm. Gemini generates clean, component-based 3D code that's easy to iterate on.
Setting Up Your First Scene
Let's build an interactive 3D scene from scratch using Gemini as your co-pilot.
Bootstrap the project
Start with a React + Vite project and install the Three.js ecosystem packages. React Three Fiber provides the React bridge, and Drei adds useful helpers.
npm install three @react-three/fiber @react-three/drei
Create the canvas component
Set up the basic scene with a Canvas component, ambient lighting, and orbit controls. This gives you an interactive 3D viewport.
import { Canvas } from '@react-three/fiber'
import { OrbitControls, Environment } from '@react-three/drei'
export function Scene() {
return (
<Canvas camera={{ position: [3, 3, 3], fov: 50 }}>
<ambientLight intensity={0.5} />
<directionalLight position={[5, 5, 5]} />
<OrbitControls />
<Environment preset="sunset" />
{/* Your 3D objects go here */}
</Canvas>
)
}Prompt Gemini for geometry
Describe the scene you want: "Create a floating island with low-poly terrain, a small cabin, and animated clouds." Gemini generates the Three.js geometry, materials, and animations—ready to drop into your Canvas.
Materials, Lighting, and Textures
Gemini excels at generating realistic material configurations. Instead of manually tweaking roughness, metalness, and normal maps, describe the look you want:
"Create a glass material with slight refraction and frosted edges" — Gemini outputs a MeshPhysicalMaterial with correct transmission, roughness, ior, and thickness parameters.
"Add dramatic studio lighting with a warm key light and cool fill" — You get a three-point lighting setup with properly configured DirectionalLight, SpotLight, and RectAreaLight components.
For textures, Gemini can generate procedural textures using shaders or suggest appropriate texture maps from common sources. The key is being specific about the visual effect you want rather than the technical implementation.
Adding Interactivity
Static scenes are impressive, but interactive ones are memorable. Here's how to add user interaction.
Click and hover events
React Three Fiber makes 3D interaction as simple as React event handlers. Add `onClick`, `onPointerOver`, and `onPointerOut` to any mesh to respond to user input.
function InteractiveBox() {
const [hovered, setHovered] = useState(false)
return (
<mesh
onPointerOver={() => setHovered(true)}
onPointerOut={() => setHovered(false)}
scale={hovered ? 1.2 : 1}
>
<boxGeometry />
<meshStandardMaterial
color={hovered ? '#ff6b6b' : '#4ecdc4'}
/>
</mesh>
)
}Physics integration
Ask Gemini to add physics: "Make the objects respond to gravity and collide with each other." It'll integrate `@react-three/rapier` or `@react-three/cannon` with proper rigid body configurations.
Animation loops
Use the `useFrame` hook for per-frame animations. Gemini generates smooth rotation, oscillation, and path-following animations with proper delta-time handling for consistent speed across frame rates.
Performance Optimization
Instanced Meshes for Repeated Objects
If your scene has many identical objects (trees, particles, buildings), use `InstancedMesh` instead of individual meshes. This reduces draw calls from thousands to one.
Level of Detail (LOD)
Implement LOD for complex scenes—show high-detail models when close, simplified versions when far. Drei's `<Detailed>` component makes this straightforward.
Lazy Loading with Suspense
Wrap heavy 3D models in React's `<Suspense>` with a loading fallback. This prevents the scene from freezing while large assets download and parse.
Monitor with Stats
Add Drei's `<Stats>` component during development to track FPS, draw calls, and memory. Remove it in production but use it to identify bottlenecks early.