Three.js AI Studio is a modern, web-based development environment designed to accelerate the creation and testing of Three.js scenes. It leverages AI to generate, debug, and fix code, providing a seamless workflow from idea to interactive 3D preview.
The studio is built as a single-page application with a backend powered by Cloudflare Workers, making it fast, scalable, and easy to deploy.
- AI Code Generation: Describe a 3D scene in plain English and let the AI generate the complete Three.js code for you.
- AI-Powered Debugging: When your code has an error, the AI can analyze the error message and the code to provide a fix.
- Rich IDE Experience: A Firebase Studio-inspired layout with a code editor, file explorer, and interactive panel controls.
- Live Preview: Instantly see the results of your code in a live preview tab.
- Off-canvas Navigation: A clean, spacious interface with collapsible sidebars for main navigation and file management.
- Cloud-Based Workspace: User authentication and file storage are handled in the cloud (using Cloudflare R2), so your projects are saved and accessible.
-
Frontend:
- HTML5
- Bootstrap 5 for layout and components.
- vanilla-js for all client-side logic.
- Font Awesome for icons.
-
Backend:
- Cloudflare Workers for serverless application logic.
- Cloudflare R2 for file storage.
- Cloudflare KV for user authentication storage.
- Cloudflare Workers AI for AI-powered code generation and fixing (via the Llama 3 model).
- Wrangler CLI for development and deployment.
.
├── backend/ # Cloudflare Worker code
│ ├── src/
│ │ ├── auth.js
│ │ ├── code-generator.js
│ │ ├── index.js # Main worker entrypoint
│ │ └── workspace.js
│ ├── package.json
│ └── wrangler.toml # Worker configuration
│
└── frontend/ # SPA frontend
└── index.html # The entire frontend application
- Node.js and npm.
- Wrangler CLI installed and authenticated with your Cloudflare account.
-
Navigate to the
backenddirectory:cd backend -
Install dependencies:
npm install
-
Configure
wrangler.toml: This file is crucial. You must create the necessary Cloudflare services and link them in this file.- AI: Enable the Workers AI add-on for your account. The binding is already named
AI. - R2 Buckets: Create two R2 buckets (e.g.,
three-ai-workspacesandthree-ai-files) and update theirbucket_namein the[[r2_buckets]]sections. - KV Namespace: Create a KV namespace (e.g.,
THREE_AI_USERS) and update itsidin the[[kv_namespaces]]section.
- AI: Enable the Workers AI add-on for your account. The binding is already named
-
Run the worker locally for development:
wrangler dev
This will start a local server, typically at
http://localhost:8787.
- The frontend is a single static file:
frontend/index.html. - For local development, you can open it directly in your browser. However, due to CORS policies, it is recommended to serve it via a simple local HTTP server. A tool like
http-servercan be used:# install it if you don't have it npm install -g http-server # from the project root, run: http-server frontend
- IMPORTANT: In
frontend/index.html, find theAPI_BASEconstant and ensure its URL points to your running backend (e.g.,http://localhost:8787for local development or your deployed worker URL for production).
- Register/Login: Create an account or log in. Your session is persisted in local storage.
- Generate Code: Use the AI Assistant panel on the right. Type a prompt (e.g., "create a spinning red cube") and click "Generate". The AI will generate the code and it will appear in the editor, with the preview tab automatically opening.
- Manage Files: Use the "Files" button in the header to open the file explorer. You can create new files, open existing ones, and delete them.
- Edit and Preview: Manually edit code in the "Editor" tab. Click the "Preview" tab to see your changes live.
- Fix Errors: If the preview shows an error, a "Fix with AI" button will appear. Click it, and the AI will attempt to fix your code based on the error message.
- Save Your Work: Click the "Save" button in the header to save the currently open file.
