Low-Cost 3D Interactive Web Pages: Building an Interactive Prototype from Scratch with LLM Help
This article explains how to build a 3D interactive web page from zero at low cost by treating it as an iterable prototype rather than a one-shot generation. It covers freezing requirements up front, splitting the page into independently checkable modules, defining scene data before rendering code, modeling pointer interaction as an explicit state machine, keeping the render loop minimal, writing prompts that save rounds, controlling token and human cost, implementing a clean lifecycle, and verifying the result with an observable checklist. It also lists common failures such as inconsistent coordinate systems, duplicate event binding, pick-versus-orbit conflicts, and high-DPI blur, along with how to handle each, plus the order in which to move from prototype to a maintainable page.
3D interactive web pages are often treated as “effects engineering”: they need spatial depth, they must support clicking, dragging, and state changes, and they still have to run in an ordinary browser. The traditional approach fixes the graphics pipeline first, then hand-writes the scene graph, camera, materials, and event handling, and the schedule easily stretches out through repeated trial and error. What a large language model is well suited to is translating explicit constraints into a runnable skeleton, not making visual decisions or performance promises on your behalf. Framing the goal as “a low-cost, verifiable, iterable prototype” fits engineering reality better than trying to generate a final version in one pass.
Write the problem down first
Before starting, freeze the scope on a single page of requirements so the model does not diverge against a vague goal. At minimum, state five things.
First, scene objects: which entities exist, their relative positions, whether they are clickable, and whether they animate. Describe them as a list, not as “build a cool 3D page.”
Second, the interaction contract: how mouse or touch maps to rotation, zoom, and picking; whether the keyboard participates; and which text or panels in the UI must stay in sync after a state change.
Third, the runtime environment: modern desktop browsers only, or touch screens as well; whether native browser 3D drawing capabilities may be used; and what first-load behavior is acceptable.
Fourth, non-goals: no real business APIs, no account system, no cinematic lighting. Writing non-goals down significantly reduces useless code.
Fifth, acceptance criteria: for example, “loads a scene made of several primitives, drag rotates the view, clicking an object highlights it and shows its name in a side panel.” Criteria must be observable; “feels smooth” is not enough.
Once the scope is frozen, every later generation round changes exactly one failing point. This is the first principle of cost control.
Why this suits model assistance, and where the boundary is
The code structure of such pages is highly repetitive: initialize the canvas, create the scene and camera, add lights and a grid, register pointer events, update matrices and draw inside the animation frame. Repetitive structure is exactly what a language model is good at completing. What it is not good at: frame-rate numbers you have not measured, compatibility conclusions for specific hardware, and art assets you did not provide.
So the division of labor should be: the human owns constraints, sample data, and final acceptance; the model drafts modules against those constraints, fills in boilerplate, and patches local spots based on errors. Do not treat “build me a complete product” as a single instruction. The longer a single instruction is, the more likely it contradicts itself, and the higher the rework cost.
Recommended module split
Split the page into modules that can be checked separately, and ask for code module by module instead of requesting a whole file at once.
- Scene description: a plain data structure listing each object’s identifier, geometry type, size, position, color, and whether it is interactive. This is the single “content source”; the render layer only reads it.
- Viewport: canvas size, camera position, field of view, near and far clipping planes, and how the aspect ratio is updated when the window resizes.
- Interaction state machine: a finite set of states such as idle, drag-orbit, and pick-highlight. Transitions live in one place, so assignments are not scattered across event callbacks.
- Render loop: each frame reads state, updates camera or object matrices, then draws. The loop itself does not parse business copy.
- UI layer: the 2D overlay only consumes the identifier and display fields of the “currently selected object” and never modifies 3D matrices directly.
With this split, when one layer breaks you can regenerate only that layer and have the model work against the error message and the relevant functions you paste, instead of rewriting every file.
Scene data before drawing code
Write the data by hand first, or have the model generate only data and no drawing. For example, represent objects with an array:
const sceneObjects = [{ id: "base", shape: "box", size: [2, 0.2, 2], position: [0, 0, 0], color: "#6b7280", pickable: false },{ id: "node-a", shape: "sphere", size: [0.35], position: [-0.6, 0.55, 0.2], color: "#2563eb", pickable: true, label: "Node A" },{ id: "node-b", shape: "sphere", size: [0.35], position: [0.7, 0.55, -0.3], color: "#059669", pickable: true, label: "Node B" }];
Once the data is stable, ask the model to “create meshes only from the array above, without adding or removing objects.” That constraint prevents the model from inventing decorative geometry on its own, which would leave you nothing to check acceptance against. Identifiers must be stable: the pick result returns that identifier, and the UI layer looks up the label by identifier rather than relying on the mesh’s index in the array.
Write interaction as a state machine
Pointer interaction is easiest to write as unmaintainable callbacks. Explicit states make it easier for the model to modify:
- idle: if the pointer goes down and hits empty space, enter orbiting and record the start point; if it hits a pickable object, set selectedId to that object’s identifier and do not enter orbit.
- orbiting: on pointer move, update yaw and pitch from the delta and clamp pitch to prevent the camera from flipping; on pointer up, return to idle.
- Wheel or two-finger gesture: change camera distance only, clamped between a minimum and maximum.
Picking and rotation are separated so the view does not jump around while selecting. When implementing picking, prefer a method consistent with your drawing approach: if you intersect a ray with bounding volumes, document the coordinate system, meaning how screen coordinates are unprojected into a world ray. If the coordinate system is not written down, the model readily mixes left- and right-handed conventions or confuses CSS pixels with drawing-buffer pixels. For acceptance, click-test two objects at known positions; that is more reliable than looking at screenshots.
The render loop does only three things
Each frame should do only: update camera parameters from the interaction state; update the highlight of the material or outline based on selectedId; submit the draw. Business copy, network requests, and heavy string concatenation do not belong in the frame loop. Highlighting can be implemented in the simplest way, “the selected object uses a different color set”; no complex post-processing is needed. In the prototype stage, simple highlighting is enough to prove the interaction loop is closed.
When the window size changes, update the canvas width and height and the camera aspect ratio, and let it take effect on the next frame. If you forget device pixel ratio, the page looks blurry on high-DPI screens; you can state in the constraints that “canvas pixel size equals CSS size multiplied by device pixel ratio, with an upper cap so memory does not blow up.” Use a cap value acceptable on your own machine, and do not accept unverified performance numbers from the model.
How to write prompts that save rounds
Effective prompts are short but hard-constrained. Each round contains only:
- Role and scope: you are a front-end implementer, modifying only the viewport module.
- Frozen data and interfaces: paste the scene array and function signatures, for example
createViewport(canvas, sceneObjects)returning{ start, setSelected, dispose }. - This round’s failure symptom: paste the console output verbatim and the behavior you expect, each within three to five lines.
- Prohibitions: no unexplained remote scripts, no changes to scene data, no removal of existing identifiers.
Name the interfaces yourself first. If you let the model invent a new set of function names, the next round often will not line up. Keeping functions few and stable lowers cost, because context can be reused and you do not have to re-explain the whole project every round.
If the conversation grows long, compress “the file tree of the current runnable version plus each file’s exported functions” into a summary and continue, discarding stale errors. Outdated error messages are a main source of repeated generation.
Concrete cost-control practices
Low cost does not mean succeeding on the first generation; it means reducing wasted tokens and wasted human time.
- Fixed context: put scene data and interface signatures at the front of every request and append only the diff at the end. Reference the previous version of the code instead of re-pasting unrelated files in full.
- Smaller output: state “output only the function that needs replacing” and give start and end markers, which reduces the model restating the whole HTML page.
- Local loop: after generation, save files locally and verify in the browser console. A one-line typo you can fix yourself does not need another generation round.
- Failure classification: classify syntax errors, coordinate-system errors, unbound events, and unreset state, then ask about them. Merge the same class of error into one question.
- Stop condition: stop once the acceptance criteria are met. Continuing to ask for “more flashy” usually inflates materials and post-processing for very little prototype value.
Billing and unit prices vary by service, so this article gives no specific prices. The actionable metric is: record the approximate input and output length of each round and whether it passed acceptance. If several consecutive rounds are still changing the same coordinate-system problem, stop generating and draw a coordinate diagram yourself before continuing. At that point, ten minutes of human time is often cheaper than more rounds.
Lifecycle a runnable skeleton should include
Whatever the drawing details, the page needs a clear lifecycle; otherwise refreshes and route changes leak animation frames and event listeners.
- Create: get the canvas, initialize the drawing context, and build the pickable-object table from the scene data.
- Start: register pointer, wheel, and resize events, and request an animation frame.
- Update selection: expose a method for setting the selected identifier so the 2D UI can call it and keep the 3D view and the panel consistent.
- Dispose: cancel the animation frame, remove events, and release geometry and material references. In a single-page app, missing this step makes the page progressively slower.
A schematic signature looks like this; implementation details can be filled in according to your drawing approach:
function mountInteractiveScene(canvas, sceneObjects) {const state = { yaw: 0.6, pitch: 0.4, distance: 4, selectedId: null, dragging: false };let frame = 0;function loop() { updateCamera(state); render(state, sceneObjects); frame = requestAnimationFrame(loop); }const dispose = () => { cancelAnimationFrame(frame); unbind(canvas); };return { dispose, select(id) { state.selectedId = id; } };}
The above only expresses responsibility boundaries; it is not the API of any specific graphics library. For actual drawing, replace updateCamera and render with the browser 3D capability you choose. Do not introduce multiple drawing paths in the prototype at the same time.
Acceptance checklist
Tick these off one by one before delivery, to avoid “it looks like it rotates” while the interaction is wrong.
- Object count and identifiers match the scene data, with no extra meshes.
- Dragging changes only the view, not object identifiers or business data.
- Clicking a pickable object selects it reliably; clicking empty space does not mis-select a distant object. If the intersection error is large, enlarge the pick radius first and note it on the checklist instead of pretending to pixel-level accuracy.
- The selected state persists until another valid click, and survives a refresh.
- After resizing the window, the image is not stretched and rendering does not stop.
- After leaving the page or calling dispose, animation frames are no longer requested continuously.
- The console shows no persistent errors; occasional resource warnings need a human explanation and must not be ignored.
Visual style is not a gate at this stage. Color contrast only needs to distinguish selected from unselected.
Common failures and how to handle them
Inconsistent coordinate systems: objects appear behind the camera or zoom in the opposite direction. The fix is to fix three sentences, “up direction, forward direction, positive yaw direction,” and let the model change only the camera function. Verify with a reference object at a known coordinate, and do not change data and camera at the same time.
Duplicate event binding: after hot reload or repeated calls to the create function, dragging becomes overly sensitive. The create function must be idempotent, or you must guarantee dispose runs before create.
Pick versus orbit conflict: rotating on pointer-down makes clicks fail. Use a movement threshold to distinguish click from drag, for example a displacement below a small number of pixels within a short time counts as a click. Put the threshold in a constant so you can change it, rather than making the model guess each time.
High-DPI blur or an oversized canvas: set both CSS size and buffer size, and cap the maximum buffer edge. For memory problems, lower resolution first rather than adding complex shaders.
The model adds external scripts or remote model files on its own: state in the prohibitions that only inline geometry may be used. A prototype that does not depend on external meshes can be verified offline and avoids uncontrollable load failures.
From prototype to maintainable page
Only after the prototype passes should you consider engineering it, instead of demanding build configuration, a design system, and a full component library in the first round. The suggested order is: move the scene data into its own file; add a minimal set of hand-written tests for the state machine, for example “given a start point and a delta, yaw increases”; wire the dispose path to page unload; and only then talk about asset compression and loading indicators.
If you later connect real data, keep the “identifier plus display fields” boundary so the 3D layer knows only identifiers and geometry. Business fields stay in the 2D layer. Then interface changes will not force you to rewrite the render loop, and local modifications with the model stay easy.
Performance optimization is likewise deferred. First use the browser’s own performance panel to see whether scripts are too long or draw calls too many, then decide whether to merge geometry or reduce lighting computation. Without measurement, asking the model to “optimize to N frames” only yields changes you cannot verify.
Summary
The key to building a 3D interactive web page at low cost is not how clever any single generation is, but whether the constraints are executable: freeze the scene data, fix narrow interfaces, describe interaction with a state machine, make small changes by failure type, and accept against an observable checklist. The model turns repetitive structure into readable code; the human owns the coordinate conventions, the stop condition, and whether to accept the result. Following the order above, you can usually get a page that rotates, selects, and disposes in relatively few rounds, with clear boundaries for swapping data or connecting business logic later.
