AI Coding in Practice: Building 3D Games From Scratch End to End
This article walks through building three browser-based 3D games with AI coding tools, covering the full pipeline from structured requirements and asset generation to interaction design, performance budgets, and deployment. It explains why 3D games are a demanding test of AI development tools, which technology layers are involved, and where these tools still fall short, along with practical collaboration practices for keeping generated code maintainable.
1. Why 3D Games Are a Hard Test for AI Coding Tools
When people ask how complex a codebase an AI coding tool can produce, most evaluations stop at algorithm puzzles and single-file scripts. Real engineering capability shows a dividing line on graphical, highly interactive, resource-heavy projects, and 3D games have all three traits at once: the code has to be correct, and the visuals have to be correct too; the logic has to close the loop, and the asset pipeline has to stay unblocked.
A worthwhile hands-on exercise therefore covers three stylistically distinct games: a tower defense game (multi-unit pathfinding and wave management), a driving game (vehicle dynamics and scene scrolling), and a shooter (first-person controls and hit detection). These map to three typical workloads: state-machine-heavy, physics-and-input-heavy, and rendering-and-performance-heavy. Together they expose toolchain weaknesses fairly comprehensively.
The value of this kind of practice is not a benchmark score. It is verifying that one complete chain can be walked through: requirements description → code generation → tool invocation → local debugging → build and deployment.
2. The Technical Foundation: Turning “It Runs” Into “It’s Maintainable”
The stack involved can be summarized as a common combination:
- Rendering layer: a lightweight 3D rendering library built on the browser’s native graphics interfaces, handling the scene graph, camera, lighting, and materials;
- Asset layer: headless 3D modeling with batch export, used to generate reusable model assets;
- Materials and animation: a physically based rendering (PBR) workflow with skeletal animation;
- Engineering layer: modern frontend build tooling with modular management, supporting hot reload and bundle compression;
- Delivery layer: static asset hosting plus object storage working with a content delivery network.
The key point: AI coding tools are good at generating a minimal working implementation, but architectural layering, asset naming conventions, and directory structure must be defined by the developer first. Otherwise the code decays quickly after three rounds of iteration.
3. Step 1: Translating Vague Requirements Into Executable Engineering Constraints
The biggest risk with natural language prompts is ambiguity. The effective approach is to describe in layers:
[Goal] Browser-runnable tower defense prototype, 60-second rounds[Scene] 3 paths, 8 build slots, 1 base[Entities] Enemies (pathfinding + health), towers (range + cooldown), bullets (straight-line flight)[Rules] Waves escalate, leaked enemies cost health, game over at zero health[Constraints] No external assets, assemble from primitives; single-file scene config externalized to JSON
This four-part goal–entity–rule–constraint structure significantly reduces rework on generated code. In practice, externalizing numeric configuration into a structured data file is the most effective maintainability investment: rebalancing requires no changes to logic code.
4. Step 2: Scene and Asset Pipeline, Solve “Visible” First
Debugging a graphics project costs far more than debugging pure logic, so the order should be rendering first, gameplay second.
- Build a grey-box scene from basic primitives first, confirming the camera, scale, and axis orientation;
- Then bring in headless modeling scripts to produce assets in batch, with a unified export format and axis convention;
- Finally wire up PBR materials, tuning metalness and roughness as a pair to avoid a plastic look or overexposure.
A sketch of the asset generation and loading flow:
# Batch generate and export models in headless mode (illustrative)for i in range(3):build_tower(level=i)export(f"assets/tower_{i}.glb", axis="Y_UP")
// Load from a manifest on the frontend instead of hardcoding pathsconst manifest = await fetch('/assets/manifest.json').then(r => r.json());const tower = await loader.loadAsync(manifest.tower[0]);scene.add(tower);
Engineering experience: give every asset a unique identifier and metadata (triangle count, dimensions, collider type). The cost of later performance investigation and asset replacement drops sharply.
5. Step 3: Interaction and Animation, Input Abstraction Is the Key
The three games have very different controls, but they can be unified into one abstraction: input intent layer → state machine → presentation layer. Keyboard, mouse, and touch are all first mapped to intents (move forward, aim, fire, build), the state machine then decides behavior, and the presentation layer only plays animations and sounds.
Common skeletal animation pitfalls include pose snapping during animation blending, position drift caused by root motion, and inconsistent speed from frame rate fluctuation. The reliable approach is to disable root motion, advance displacement from the logic layer, and update physics with a fixed timestep:
const FIXED = 1 / 60;let acc = 0;function loop(dt) {acc += Math.min(dt, 0.1); // prevent a jump after returning from backgroundwhile (acc >= FIXED) { step(FIXED); acc -= FIXED; }render();}
For hit detection, a shooter project should separate the visual model from the hit volume and test against simplified bounding volumes, avoiding the performance collapse that per-triangle computation causes.
6. Step 4: Performance Budget and Observability
The bottleneck in browser 3D is usually not code quality but draw calls and GPU memory. Three enforceable disciplines:
- Budget up front: set hard caps on draw batches, total triangles, and texture size; optimize when a budget is exceeded rather than patching after release;
- Batching and reuse: send identical materials and geometry through instanced rendering to reduce state changes;
- Observability: hook up frontend monitoring and logging services to collect frame time distribution, load times, and exception stacks, and judge experience by real percentiles rather than averages.
7. Step 5: Build, Deployment, and Gradual Rollout
The engineering stage should guarantee one-click publishing: the build tool emits hashed static assets with code splitting and compression configured; artifacts are uploaded to object storage and served through a content delivery network; an entry point is provided via a container platform or static hosting service, with one rollback-able historical version retained.
A gradual rollout is the recommended release strategy: start at 5% traffic and watch crash rate and first-screen time, then ramp to full. On cloud resources, monitoring alerts with threshold notifications help surface problems before users report them.
8. Capability Boundaries and Collaboration Advice
It has to be said objectively: AI coding tools are still unreliable at cross-file refactoring, complex state synchronization, and diagnosing difficult graphics issues, and they tend to produce code that looks reasonable but silently fails. Three principles for effective collaboration:
- Commit in small steps, solving one verifiable goal per round;
- Have the tool produce testable units rather than one large implementation;
- Keep architectural decision-making and code review authority with the developer, treating the tool as a fast implementer rather than a designer.
9. Conclusion
Building three 3D games from scratch shows that the real payoff of AI-assisted development comes from connecting the whole chain, not from a single impressive moment. When requirements can be described structurally, the asset pipeline is standardized, performance has a budget, and releases can be rolled back, AI coding tools reliably multiply a developer’s output. Without engineering constraints, automation only accelerates technical debt. Baidu AI Cloud’s work on static hosting, object storage, and monitoring alerts offers a reference engineering pattern for delivering graphics-heavy applications reliably.
