Back to Blog
January 17, 20267 min readAI Code Generation

AI Code Generation for Three.js Experiences from Video

R
Replay Team
Developer Advocates

TL;DR: Replay leverages AI to reconstruct interactive Three.js experiences directly from video recordings, enabling rapid prototyping and iterative design without manual coding.

Forget screenshots. Forget static mocks. The future of UI development is understanding behavior, not just appearance. Current AI code generation tools fall short because they treat UI as a static image. They miss the crucial element: user interaction. We need to move beyond pixel-perfect replicas and embrace behavior-driven reconstruction. This is where Replay shines.

The Problem: Static UIs Don't Tell the Whole Story#

Traditional "AI" code generation tools, often based on image analysis, can create a basic UI shell. But they fail to capture the intent behind user actions. What happens when a user clicks a button? How does the scene change? These dynamic elements are lost in translation.

Consider a complex Three.js scene: a rotating 3D model, interactive controls, and dynamic textures. Simply generating code from a screenshot will only produce a static image, not a functional, interactive experience. This is a massive bottleneck for developers.

Replay: Behavior-Driven Reconstruction for Interactive 3D#

Replay approaches code generation from a fundamentally different angle: video analysis. By analyzing video recordings of user interactions, Replay's AI engine, powered by Gemini, understands the behavior driving the UI. This allows it to reconstruct working, interactive Three.js experiences directly from video.

Think of it as "video-to-code" rather than "screenshot-to-code." We're not just capturing pixels; we're capturing intention.

Key Advantages of Replay:#

  • Interactive 3D Scene Generation: Replay can reconstruct complex Three.js scenes, including models, lights, cameras, and interactive controls.
  • Behavior Analysis: It understands user actions and translates them into code, creating a truly interactive experience.
  • Rapid Prototyping: Generate a functional prototype in seconds, allowing you to iterate quickly and test your ideas.
  • Reduced Development Time: Automate the tedious task of manually coding UI elements, freeing up developers to focus on higher-level logic.
  • Supabase Integration: Seamlessly integrate your Three.js experience with Supabase for data persistence and real-time updates.

How Replay Works: A Step-by-Step Guide#

Let's walk through a simple example of using Replay to generate a basic interactive Three.js scene from a video.

Step 1: Record Your Interaction#

Record a short video of yourself interacting with a desired Three.js experience (even a rough prototype). Focus on demonstrating the key interactions and behaviors you want to capture. For example, rotating a 3D model by dragging the mouse.

Step 2: Upload to Replay#

Upload the video to the Replay platform. Replay's AI engine will begin analyzing the video, identifying the key UI elements and user interactions.

Step 3: Code Generation#

Replay generates clean, functional Three.js code based on the video analysis. You can then download the code and integrate it into your project.

Step 4: Customization and Refinement#

The generated code provides a solid foundation for your project. You can then customize and refine the code to meet your specific requirements.

Example: Rotating a Cube#

Let's say your video shows a user rotating a cube by dragging the mouse. Replay might generate code similar to this:

typescript
// Three.js code for rotating a cube import * as THREE from 'three'; import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls'; const scene = new THREE.Scene(); const camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 ); const renderer = new THREE.WebGLRenderer(); renderer.setSize( window.innerWidth, window.innerHeight ); document.body.appendChild( renderer.domElement ); const geometry = new THREE.BoxGeometry( 1, 1, 1 ); const material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } ); const cube = new THREE.Mesh( geometry, material ); scene.add( cube ); camera.position.z = 5; const controls = new OrbitControls( camera, renderer.domElement ); controls.enableDamping = true; // an animation loop is required when either damping or auto-rotation are enabled controls.dampingFactor = 0.05; controls.screenSpacePanning = false; controls.minDistance = 1; controls.maxDistance = 10; controls.maxPolarAngle = Math.PI / 2; function animate() { requestAnimationFrame( animate ); controls.update(); renderer.render( scene, camera ); } animate();

💡 Pro Tip: The generated code will include comments explaining the different parts of the scene and how they interact.

This is a simplified example, but it illustrates the power of Replay. It can automatically generate the necessary Three.js code to create an interactive 3D scene based on a simple video recording.

Replay vs. Traditional Methods: A Comparison#

FeatureScreenshot-to-CodeManual CodingReplay
Video Input
Behavior Analysis
Interactive 3DLimitedTime-Consuming
SpeedFastSlowFast
Accuracy (Behavior)LowHighHigh
Supabase IntegrationOften Requires Manual SetupOften Requires Manual SetupStreamlined

As you can see, Replay offers a unique combination of speed, accuracy, and behavior analysis that traditional methods simply cannot match.

📝 Note: Replay is not intended to replace developers. Instead, it's designed to augment their capabilities, allowing them to focus on the more creative and challenging aspects of UI development.

Beyond the Basics: Advanced Features#

Replay offers a range of advanced features that make it even more powerful:

  • Multi-Page Generation: Reconstruct entire application flows from multiple video recordings.
  • Style Injection: Apply custom styles to the generated UI to match your brand.
  • Product Flow Maps: Visualize the user flow through your application, making it easier to understand and optimize.
  • Supabase Integration: Quickly connect your generated UI to a Supabase backend for data storage and real-time updates.

Code Example: Supabase Integration#

Here's an example of how Replay can generate code that integrates with Supabase:

typescript
// Example of Supabase integration import { createClient } from '@supabase/supabase-js' const supabaseUrl = 'YOUR_SUPABASE_URL' const supabaseKey = 'YOUR_SUPABASE_ANON_KEY' const supabase = createClient(supabaseUrl, supabaseKey) async function getMessages() { const { data, error } = await supabase .from('messages') .select('*') if (error) { console.error('Error fetching messages:', error) return [] } return data } // Use the getMessages function to display messages in your Three.js scene

⚠️ Warning: Remember to replace

text
YOUR_SUPABASE_URL
and
text
YOUR_SUPABASE_ANON_KEY
with your actual Supabase credentials.

Challenging the Status Quo#

Many developers are skeptical of AI code generation, and for good reason. Existing tools often produce buggy, unreadable code that requires significant manual cleanup. Replay addresses these concerns by focusing on behavior-driven reconstruction, generating clean, functional code that is easy to understand and maintain.

Frequently Asked Questions#

Is Replay free to use?#

Replay offers a free tier with limited features. Paid plans are available for more advanced features and usage. Check the Replay website for the most up-to-date pricing information.

How is Replay different from v0.dev?#

While both aim to accelerate UI development, Replay uniquely analyzes video to understand user behavior, leading to more accurate and interactive code generation, especially for complex Three.js experiences. v0.dev relies on text prompts and existing code snippets, which can miss the nuances of user interaction.

What types of Three.js experiences can Replay generate?#

Replay can generate a wide range of Three.js experiences, including interactive 3D models, games, data visualizations, and more. The complexity of the generated code depends on the complexity of the video recording.

How accurate is Replay's code generation?#

Replay's code generation accuracy is constantly improving. However, it's important to remember that it's not perfect. You may need to make some manual adjustments to the generated code to meet your specific requirements.


Ready to try behavior-driven code generation? Get started with Replay - transform any video into working code in seconds.

Ready to try Replay?

Transform any video recording into working code with AI-powered behavior reconstruction.

Launch Replay Free