Home / Guides / Browser game with three.js and AI

How to make a browser game with three.js and AI

Short answer: create a Vite project, install three.js, and let an AI coding agent (Claude Code, Codex or Cursor) write the game one small feature at a time while you run the dev server and playtest in your browser. Load AI generated 3D models as GLB files with three.js's GLTFLoader, then host the built dist/ folder free on itch.io or Cloudflare Pages. Versions and limits below were checked against official docs on October 19, 2026.

What you are using

three.js

Free, open source (MIT) JavaScript 3D library for WebGL and WebGPU that runs games and scenes directly in the browser.

Pricing: Free. Beginner rating: 3/5. A code library, not an editor, but AI coding agents write three.js well and you test in any browser.

Free forever. Works in any modern browser, so playtesting is just a page refresh.

Pick an AI coding tool

All three work with a plain Vite folder. Pricing is from our directory entries (checked October 2026); confirm on each vendor page before paying.

Claude

AI assistant that writes game code, explains bugs and builds playable prototypes.

Pricing: Freemium, from $20/mo. Beginner rating: 5/5. Explains code clearly to beginners.

Good at explaining the code it writes, which helps you learn three.js as you go.

OpenAI Codex

OpenAI's coding agent for the desktop app, terminal, IDE and web. It can read your project, write code and use MCP servers.

Pricing: Freemium, from $8/mo (Go, desktop app only). Beginner rating: 3/5. Very capable, but you work in a terminal or IDE.

Terminal or desktop app agent that edits your project directly.

Cursor

AI code editor with a built-in agent, plus a CLI and cloud agents, that writes and edits game code from plain English requests.

Pricing: Freemium, from $8/mo (Plus, Grok models only). Beginner rating: 3/5. Very capable but assumes some coding.

A full editor, handy if you also want to read and tweak the code by hand.

Not sure which one? Our Claude Code vs Codex vs Cursor for game dev guide compares them.

The realistic beginner workflow

  1. Set up Vite and three.js once (commands below).
  2. Ask the AI for one small feature: a player cube that moves, a camera that follows, a coin to collect.
  3. Run the dev server with npm run dev and keep the browser tab open. Vite reloads on every save.
  4. Playtest in the browser. Open the developer console (F12) and look for red errors.
  5. Fix and repeat. Paste the exact error text, or describe what feels wrong, back to the agent. Commit to git when something works.

No agent can tell whether your jump feels good. That part is your job, and it is most of the fun.

Setup, step by step

1. Create the project

Install Node.js (20.19+ or 22.12+ for Vite 8). Then, using the commands from the Vite guide and the three.js manual:

npm create vite@latest my-3d-game -- --template vanilla
cd my-3d-game
npm install
npm install three
npm run dev

The three.js manual installs with npm install --save three and npm install --save-dev vite; the Vite template above already includes Vite, so npm install three is all you add. Open the URL Vite prints (usually http://localhost:5173).

2. Give the agent project notes

Claude Code reads CLAUDE.md; Codex reads AGENTS.md; Cursor supports project rules. A short notes file stops the agent from adding random frameworks. Example:

# Game project notes

- Stack: Vite (vanilla JavaScript) + three.js (npm package "three", r186 at time of writing).
- Entry: index.html loads src/main.js. Game code lives in src/.
- Models, textures and sounds live in public/ (for example public/models/crate.glb).
- Import addons from 'three/addons/...', for example GLTFLoader and OrbitControls.
- Run: npm run dev (http://localhost:5173). Build: npm run build (outputs dist/).
- Keep one feature per change. Do not add frameworks or new npm packages without asking.
- Use relative asset paths so the build works on itch.io.

3. Start the agent and ask for a first scene

Open the project folder in your tool (for example run claude or codex in the folder, or open it in Cursor) and ask something like: Replace src/main.js with a three.js scene: a green ground plane, a blue cube player that moves with WASD, a camera that follows it, and a resize handler. Remove the Vite template counter code.

4. Playtest, then one feature at a time

Good next prompts: add five coins that disappear when the player touches them and a score in the corner, then add a 60 second timer and a restart button. Keep each request small enough that you can test it in under a minute.

Loading AI generated 3D models (GLB)

three.js loads glTF and GLB files with GLTFLoader, an addon that ships inside the three package. The installation manual shows the import as three/addons/loaders/GLTFLoader.js. Put models in public/models/ so Vite copies them to the build unchanged. A minimal example:

import * as THREE from 'three';
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';

const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(60, innerWidth / innerHeight, 0.1, 100);
camera.position.set(0, 2, 5);

const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(innerWidth, innerHeight);
document.body.appendChild(renderer.domElement);

scene.add(new THREE.HemisphereLight(0xffffff, 0x444444, 2));

const loader = new GLTFLoader();
loader.load('./models/crate.glb', (gltf) => {
  scene.add(gltf.scene);
}, undefined, (err) => console.error('Model failed to load', err));

addEventListener('resize', () => {
  camera.aspect = innerWidth / innerHeight;
  camera.updateProjectionMatrix();
  renderer.setSize(innerWidth, innerHeight);
});

renderer.setAnimationLoop(() => renderer.render(scene, camera));

Where to get models:

Meshy

Turns text or images into textured 3D models ready for game engines.

Pricing: Freemium, from $20/mo. Beginner rating: 5/5. Very easy text or image to 3D workflow.

Fast text or image to 3D. Check download rules for your plan before you build around a model.

Tips: AI models are often large. Keep each file small for quick loading, check the scale (scale gltf.scene if it is huge or tiny), and ask the agent to log the model's bounding box if you cannot see it.

Build and host for free

Make the build portable

Vite's default base is /. Vite's config docs list an empty string or ./ for embedded deployment, which is what itch.io needs because it serves your game from a subfolder:

// vite.config.js
import { defineConfig } from 'vite';

export default defineConfig({
  base: './', // relative paths, needed for itch.io's subfolder hosting
});

Then run npm run build (or npx vite build, as the three.js manual puts it). Everything lands in dist/. Preview it with npm run preview.

Option 1: itch.io HTML5 upload

From itch.io's HTML5 docs (checked October 19, 2026):

Option 2: Cloudflare Pages

Cloudflare Pages Direct Upload lets you drag and drop a folder or ZIP in the dashboard, or deploy from a terminal with npx wrangler pages deploy dist (per the Direct Upload docs). The free plan allows up to 20,000 files per site and 25 MiB per file, per the Pages limits page (last updated September 5, 2026). Keep big GLB files under that 25 MiB cap.

No code alternatives, and when Phaser fits better

Common pitfalls

Sources (checked October 19, 2026)

FAQ

Is three.js free?

Yes. three.js is open source under the MIT license (per its npm package). The latest release when we checked on October 19, 2026 was r186, published on npm as three 0.186.1.

Do I need to know JavaScript?

It helps a lot. An AI coding agent such as Claude Code, Codex or Cursor can write most of the code, but you still read errors in the browser console, describe bugs clearly, and decide what feels fun. If you want zero code, try Rosebud AI instead.

Which AI coding tool should I use?

Any of the three works with a plain Vite project. Claude Code needs Claude Pro ($20/mo monthly) or higher; Codex has limited access on ChatGPT Free and Go and full CLI access from Plus ($20/mo); Cursor has a limited free plan. Prices are from our directory entries, checked October 2026. See our Claude Code vs Codex vs Cursor guide.

Can I use Meshy models for free?

You can generate with Meshy's free 100 monthly credits, but Meshy's help center says free accounts cannot download models made with Meshy 6 or Meshy 7. Free plan outputs are licensed CC BY 4.0, so credit Meshy. Pro is $20/mo per meshy.ai/pricing (October 2026).

Where can I host a three.js game for free?

Two easy options: upload the Vite dist folder as a ZIP to itch.io as an HTML game, or deploy dist to Cloudflare Pages (free plan allows up to 20,000 files and 25 MiB per file, per Cloudflare's limits page, last updated September 5, 2026).

Should I use Phaser instead?

If your game is 2D (platformer, top down, puzzle), Phaser is usually the simpler pick because it ships sprites, tilemaps, input and physics for 2D. three.js is a 3D rendering library, so you add game structure yourself.

Related

Get one new free AI game dev tool every week

One short email each week: a free or freemium tool a beginner can use, what it is good for, and where it fits in your game. No spam, unsubscribe any time.

Past issues