{"slug": "turn-ai-generated-three-js-into-3d-and-ar-with-google-s-three-live", "title": "Turn AI-generated Three.js into 3D and AR with Google's Three-Live", "summary": "Google released Three-Live on November 3, 2026, an open source Apache 2.0 library in Developer Preview that sandboxes LLM-written Three.js scripts and compiles them to .glb (binary glTF 2.0) and .usdz for rendering on the web via WebGL2, Android via Google Filament, and iOS via RealityKit. The sandbox runs scripts in a Web Worker or an optional opaque-origin iframe, strips network primitives such as fetch, XMLHttpRequest, WebSocket and dynamic import(), and on Android, iOS, macOS and the command line compiles inside an embedded Rust compiler powered by the Boa JavaScript engine; scenes are capped at 1,000 meshes, 100,000 vertices, 300,000 indices and 16 textures. The npm package stood at version 1.2.1 and the latest CLI release at v1.2.0 on November 4, 2026, and the library is still alpha and not an officially supported Google product.", "body_md": "# Turn AI-generated Three.js into 3D and AR with Google's Three-Live\n\nBy [Flavio](https://flaviocopes.com/about/)\n\nTagged: [AI](https://flaviocopes.com/tags/ai/)\n\nGoogle's Three-Live sandboxes an LLM-written Three.js script and compiles it to glTF and USDZ for the web, Android, and iOS.\n\nGoogle released **Three-Live** on November 3, 2026. It’s an open source library (Apache 2.0, Developer Preview) that takes Three.js code, usually written by an LLM, and runs it safely on the web, Android, and iOS.\n\nThe problem it solves is easy to see. LLMs are already pretty good at writing Three.js scenes.\n\nBut code generated at runtime is untrusted, and you don’t want to `eval` it inside your page. On top of that, phones have native 3D and AR engines that a regular WebView can’t touch.\n\nSo Three-Live treats a subset of the Three.js API as a scene description language. It runs the script inside a sandbox and compiles the output into standard `.glb` (binary glTF 2.0) and `.usdz` files.\n\nFrom there, each platform renders the scene with its own engine: a small WebGL2 renderer on the web, Google Filament on Android, and RealityKit on iOS. Here is how that pipeline flows:\n\nThree-Live is still alpha and not an officially supported Google product. On November 4, 2026, the npm package was at `1.2.1` and the latest CLI release was `v1.2.0`.\n\n## The sandbox\n\nHow does Three-Live keep untrusted JavaScript from doing damage?\n\nOn the web, it runs your script in a Web Worker or an optional opaque-origin `<iframe sandbox=\"allow-scripts\">`, which isolates it from your site’s storage and cookies. Before your code executes, it strips out network primitives like `fetch`, `XMLHttpRequest`, `WebSocket`, and dynamic `import()`.\n\nOn Android, iOS, macOS, and the command line, there is no browser at all. Instead, Three-Live compiles scripts inside an embedded Rust compiler powered by the Boa JavaScript engine.\n\nBoth runtimes enforce strict execution time limits and geometry quotas. According to the LLM guide, a single scene caps out at 1,000 meshes, 100,000 vertices, 300,000 indices, and 16 textures.\n\n## Your first scene in HTML\n\nInside a Three-Live script, we only get two globals: `THREE` and `scene`. You build objects and pass them to `scene.add()`, without ever creating a renderer or calling `requestAnimationFrame`.\n\nHere is a minimal HTML page that renders a rotating torus knot with orbit controls and an AR button:\n\n```\n<!doctype html>\n<html>\n  <body>\n    <script src=\"https://cdn.jsdelivr.net/npm/three-live@1.2.1/dist/three-live.min.js\"></script>\n\n    <three-live\n      allow-client-scripts\n      camera-controls\n      ar\n      shadow-intensity=\"1\"\n      environment-image=\"studio\"\n      style=\"width: 100%; height: 480px; display: block;\">\n      <script type=\"text/three\">\n        const knot = new THREE.Mesh(\n          new THREE.TorusKnotGeometry(0.6, 0.2, 128, 32),\n          new THREE.MeshStandardMaterial({ color: 0x4285f4, metalness: 0.85, roughness: 0.15 })\n        )\n        scene.add(knot)\n\n        scene.userData.animate = (t) => {\n          knot.rotation.y = t * (Math.PI / 2)\n        }\n      </script>\n    </three-live>\n  </body>\n</html>\n```\n\nTake a close look at `scene.userData.animate`. Instead of running that callback every frame in your browser, Three-Live bakes it into a looping glTF animation (4 seconds by default).\n\nI really like that design choice, because the motion survives the jump into AR Quick Look on iOS or Scene Viewer on Android.\n\nAfter adding ambient and directional light, I loaded this scene in Chrome. Here is the torus knot running inside `<three-live>`, complete with the built-in **View in AR** button in the corner:\n\nOne detail can trip you up at first: inline scripts require the `allow-client-scripts` attribute. If you leave it out, the element refuses to compile and renders nothing.\n\nBecause anyone can edit an inline script right in the browser, Three-Live makes you opt in explicitly. For the script tag type, you can use either `text/three` (shown in the README) or `text/three-live` (shown in the announcement post), since the element accepts both.\n\n## Loading AI-generated scripts from your server\n\nIn a real app, the scene usually comes from an LLM on your backend rather than an inline tag. You point the `<three-live>` element to a URL with `script-src`:\n\n```\n<three-live script-src=\"https://flaviocopes.com/scenes/planet.js\" camera-controls ar></three-live>\n```\n\nServer-generated scripts don’t need `allow-client-scripts`, and they still run in the sandbox.\n\nTo test this flow, I put together `planet.js`, a small scene with a planet, a tilted ring, two lights, and a slow rotation:\n\n``` js\nconst planet = new THREE.Mesh(\n  new THREE.SphereGeometry(0.5, 48, 32),\n  new THREE.MeshStandardMaterial({ color: 0xf59e0b, roughness: 0.6 })\n)\n\nconst ring = new THREE.Mesh(\n  new THREE.TorusGeometry(0.8, 0.04, 16, 96),\n  new THREE.MeshStandardMaterial({ color: 0xe5e7eb, metalness: 0.3, roughness: 0.4 })\n)\nring.rotation.x = Math.PI / 2.4\n\nconst system = new THREE.Group()\nsystem.add(planet)\nsystem.add(ring)\nscene.add(system)\n\nscene.add(new THREE.AmbientLight(0xffffff, 0.4))\nconst sun = new THREE.DirectionalLight(0xffffff, 1.2)\nsun.position.set(2, 3, 2)\nscene.add(sun)\n\nscene.userData.animate = (t) => {\n  system.rotation.y = t * (Math.PI / 2)\n}\n```\n\nWhen we serve that file over `script-src=\"https://flaviocopes.com/planet.js\"`, Chrome renders the orange planet and metallic ring right in WebGL2:\n\n## Getting good scripts out of an LLM\n\nLLMs know far more Three.js than Three-Live supports, so you need to set boundaries in your system prompt. The repository already includes a copy-paste guide in `docs/llm-guide.md`, along with `llms.txt` and `llms-full.txt` feeds you can drop straight into a context window.\n\nIf you write your own prompt, include these core rules from the guide:\n\n- Only use the `THREE` and`scene` globals, and attach everything through`scene.add()` .\n- Skip `GLTFLoader` ,`OBJLoader` ,`TextureLoader` ,`EffectComposer` ,`ShaderMaterial` ,`RawShaderMaterial` , and`requestAnimationFrame` .\n- Don’t instantiate `THREE.WebGLRenderer` or access`window` and`document` .\n- Limit objects to the allowed constructors.\n\nHere is the full list of constructors Three-Live supports:\n\n| Kind | Constructors | \n|---|---|\n| Geometries | `BoxGeometry` ,`PlaneGeometry` ,`SphereGeometry` ,`CylinderGeometry` ,`ConeGeometry` ,`TorusGeometry` ,`TorusKnotGeometry` ,`BufferGeometry` ,`BufferAttribute` | \n| Materials | `MeshStandardMaterial` ,`MeshBasicMaterial` ,`MeshLambertMaterial` ,`MeshPhongMaterial` ,`MeshPhysicalMaterial` | \n| Scene graph | `Scene` ,`Group` ,`Mesh` ,`Object3D` | \n| Lights and cameras | `AmbientLight` ,`DirectionalLight` ,`PointLight` ,`Camera` ,`PerspectiveCamera` | \n| Math | `Vector2` ,`Vector3` ,`Vector4` ,`Euler` ,`Quaternion` ,`Matrix3` ,`Matrix4` ,`Color` ,`MathUtils` ,`Clock` | \n\nWhat if the model slips up anyway? The compiler ships with fallback shims, so something like a `ShaderMaterial` gets downgraded to a `MeshStandardMaterial` instead of crashing the whole scene.\n\n## Compile scenes from the command line\n\nYou don’t need a browser to compile a scene. That makes Three-Live handy in a backend or CI job, where an LLM generates the script, your server compiles it, and you store the resulting `.glb`.\n\nYou can grab the `three-live-cli` binary from the [GitHub releases](https://github.com/google/three-live/releases) page, with builds for Linux (x86_64 and aarch64), macOS (arm64 and x86_64), and Windows. Here is a quick look at the repo layout on GitHub:\n\nOn my Apple Silicon Mac, I downloaded the CLI like this:\n\n```\ncurl -L -o three-live-cli https://github.com/google/three-live/releases/download/v1.2.0/three-live-cli-macos-arm64\nchmod +x three-live-cli\n```\n\nThen I compiled `planet.js` into a binary `.glb` file:\n\n```\n./three-live-cli convert planet.js -o planet.glb\n# Successfully compiled \"planet.js\" -> \"planet.glb\" (179316 bytes)\n```\n\nIf you want a file ready for Apple’s AR Quick Look, pass `-f usdz` instead:\n\n```\n./three-live-cli convert planet.js -f usdz -o planet.usdz\n# Successfully compiled \"planet.js\" -> \"planet.usdz\" (374790 bytes)\n```\n\nOnce you have a precompiled `.glb`, you can ship the lighter viewer-only build on your frontend without bundling the script compiler:\n\n```\n<script src=\"https://cdn.jsdelivr.net/npm/three-live@1.2.1/dist/three-live-viewer.min.js\"></script>\n\n<three-live src=\"planet.glb\" camera-controls auto-rotate></three-live>\n```\n\n## Watching the sandbox say no\n\nI wanted to see how well the sandbox holds up, so let’s feed the CLI a few hostile scripts.\n\nFirst, we save `bad.js`, which tries to make a network call:\n\n```\nfetch('https://flaviocopes.com')\n```\n\nWhen I ran the compiler on it, the sandbox blocked `fetch` immediately:\n\n```\n./three-live-cli convert bad.js -o bad.glb\n# Transcoding error: Three.js script error: ReferenceError: fetch is not defined\n```\n\nNext up is `loop.js`, a classic infinite loop:\n\n```\nwhile (true) {}\n```\n\nInstead of hanging the process, Boa stops execution once it hits the loop iteration cap:\n\n```\n./three-live-cli convert loop.js -o loop.glb\n# Transcoding error: Three.js script error: RuntimeLimit: Maximum loop iteration limit 250000 exceeded\n```\n\nFinally, let’s try `big.js`, which attempts to add 100,000 boxes to the scene:\n\n``` js\nfor (let i = 0; i < 100000; i++) {\n  scene.add(new THREE.Mesh(new THREE.BoxGeometry(1, 1, 1), new THREE.MeshStandardMaterial()))\n}\n```\n\nThe compiler kills that one too as soon as it crosses the 250 ms execution ceiling:\n\n```\n./three-live-cli convert big.js -o big.glb\n# Transcoding error: 3D execution time (255.2 ms) exceeded SECURITY_3D_EXECUTION_CEILING_MS (250 ms)\n```\n\nEvery single one of these tests exits with code 1, never hangs, and writes no output file. In a real app, your backend can catch that failure and ask the LLM to try again.\n\n## Native apps\n\nYou can also compile those scripts right on the device inside native apps.\n\nOn Android, Google provides a Kotlin SDK (`com.google.threelive:compiler`) that renders through Google Filament. On iOS and macOS, we get a Swift package (`ThreeLiveCompiler`) built for RealityKit, which you can add in Xcode using `https://github.com/google/three-live.git`.\n\nHere is how the Swift integration looks, straight from the README:\n\n``` python\nimport ThreeLiveCompiler\nimport RealityKit\n\nlet glb = try ThreeCompiler.compileToGLB(script: script)\nlet entity = try await RealityKitHelper.loadEntity(fromGLB: glb)\n```\n\nThere is also a companion `<xr-live>` element for WebXR headsets with hand tracking, spatial HTML cards, and plugins. That’s a big enough topic that I’ll save it for another post.\n\nIf you want to try Three-Live right now without installing anything, open the [Three-Live Studio playground](https://google.github.io/three-live/three/). You can edit a script there and watch it compile live in your browser.\n\n## Sources\n\nWant me to talk about your product? You can [sponsor this site](https://flaviocopes.com/sponsor/).", "url": "https://wpnews.pro/news/turn-ai-generated-three-js-into-3d-and-ar-with-google-s-three-live", "canonical_source": "https://flaviocopes.com/three-live-ai-generated-3d/", "published_at": "2026-12-03 14:00:00+00:00", "updated_at": "2026-12-03 14:44:45.031490+00:00", "lang": "en", "topics": ["artificial-intelligence", "generative-ai", "ai-tools", "developer-tools", "large-language-models"], "entities": ["Google", "Three-Live", "Three.js", "Boa", "Google Filament", "RealityKit", "WebGL2", "glTF"], "also_reported_by": [], "takeaway": "Three-Live compiles sandboxed Three.js scripts to .glb and .usdz so one scene renders on web, Android and iOS, with inline scripts requiring the allow-client-scripts attribute and scenes capped at 1,000 meshes, 100,000 vertices, 300,000 indices and 16 textures.", "recommendation": null, "alternates": {"html": "https://wpnews.pro/news/turn-ai-generated-three-js-into-3d-and-ar-with-google-s-three-live", "markdown": "https://wpnews.pro/news/turn-ai-generated-three-js-into-3d-and-ar-with-google-s-three-live.md", "text": "https://wpnews.pro/news/turn-ai-generated-three-js-into-3d-and-ar-with-google-s-three-live.txt", "jsonld": "https://wpnews.pro/news/turn-ai-generated-three-js-into-3d-and-ar-with-google-s-three-live.jsonld"}}