From Text to Interactive 3D Scenes: A Code Generation Practice

    This article examines how interactive 3D web pages test code generation, using a coastal cycling scene and a volcanic eruption demo. It covers shared spatial baselines, procedural water, constrained cameras, staged eruption states, particle resource limits, frame-rate-independent timing, verifiable task specifications, and acceptance criteria.

    1. Why Interactive 3D Web Pages Test Code Generation

    Generating an image and generating an interactive 3D scene have different delivery requirements. The former is judged mainly by framing, lighting, and detail. The latter must also answer several questions: when the camera moves behind the main subject, does the geometry still make sense? After the window size changes, are the interface and scene still usable? After the animation runs for a while, do frame time and resource usage remain stable?

    The value of a 3D web page is that it puts these questions into the same runnable deliverable. The model must not only understand descriptions such as “warm coast” or “volcanic eruption,” but also turn them into scene coordinates, geometry, material parameters, time-update logic, and user interaction. Coastal cycling is suitable for observing spatial organization and animation coordination; volcanic eruption is suitable for observing event scheduling and high-frequency object updates. The two cases cover different capabilities, but both can be evaluated with explicit constraints and verification steps rather than relying on first impressions.

    2. Coastal Cycling: Establish Spatial Relationships First, Then Add Visual Detail

    2.1 Make the Road, Character, and Camera Share One Spatial Baseline

    With a pelican riding a bicycle as the main subject, the scene can be set on a coastal curve, with distant islands and a lighthouse as visual references. In implementation, first determine the road centerline, road width, sea level height, and character size. The road mesh can be extruded along the center curve; the vehicle position can be obtained by sampling the path; and the vehicle heading can be calculated from the tangent near the sample point. Guardrails, road signs, and vegetation can also be placed along the path, but a safe distance should be left on the shoulder and the inside of curves so that decorations do not intrude into the road.

    When moving along a curve, distinguish between “uniform change in parameter” and “uniform change in actual distance.” For an arbitrary curve, the same parameter increment does not necessarily correspond to the same travel distance, so the vehicle may appear to accelerate or decelerate for no reason. If stable riding speed is desired, sample the curve and build a cumulative arc-length table, then look up the vehicle position by travel distance. Acceptance should check curves and slopes, not just a straight section: do the wheels stay on the road, does the body pass through the guardrail, and after switching to a side camera, do the character’s feet still coordinate with the pedals?

    2.2 Build a Procedural Sea from Basic Lighting

    A layered sea can be constructed without external textures, but “no textures” is only a dependency constraint, not a guarantee of visual quality. Start by layering waves with different directions and scales: large-scale motion determines the swell, while small-scale disturbance affects local highlights. Then change reflection weight according to the viewing angle so that the water more clearly reflects the sky color at grazing angles. Nearshore areas can transition in color based on distance from the shoreline or simplified depth information; distant areas can use fog to reduce contrast and separate the sea, islands, and horizon.

    In implementation, prioritize aligning the sun azimuth, the bright area of the sky, and the water highlights. Compared with adding a flock of birds, a highlight band aligned with the sunset direction makes the scene more believable. Check the water from a low angle close to sea level and from a top-down view: the former easily exposes horizon seams, while the latter reveals wave repetition, abrupt nearshore transitions, or water covering the road.

    2.3 Use a Constrained Camera Instead of Letting It Clip Through Geometry

    Orbit-style viewing is sufficient for most 3D presentation needs. The camera can rotate horizontally around the subject while pitch, zoom distance, and observation target are bounded, reducing cases where the camera goes underground, passes through the character, or loses the subject. On mobile, also check whether drag and pinch gestures conflict with page scrolling. The default camera is responsible for showing the full composition; the free camera is used to verify whether the scene truly holds up. The two cannot replace each other.

    3. Volcanic Eruption: Turn the Effect Demo into a Reproducible Time System

    3.1 Control the Eruption with Stage States, Not One Global Switch

    The volcano demo can divide the eruption into preheat, burst, decay, and cooling. The preheat stage increases crater brightness and releases a small amount of smoke and dust; the burst stage increases ejection rate so lava fragments and ash clouds spread outward; the decay stage gradually reduces new particles; the cooling stage retains residual effects whose lifetimes have not ended. With this design, extending the preheat time does not require rewriting particle motion, and disabling smoke alone does not break the lava animation.

    Pause, resume, and reset must be clearly defined. On pause, freeze simulation time, not just stop drawing; otherwise, resuming may skip part of the eruption. On reset, clear live particles, restore the stage and timers, and restore the initial seed when a fixed random seed is enabled. This makes it easier to reproduce an eruption in the same runtime environment and compare behavior before and after changes.

    3.2 Split Particles by Material and Motion Characteristics

    Rock debris can use a ballistic approximation affected by gravity; lava fragments can gradually dim over their lifetime; dust can have slower upward motion and lateral drift. For a demo prototype, these approximations are enough to express layers, but they cannot be used to infer the real eruption scale or material diffusion range. If the effect is used for teaching or data presentation, clearly mark which variables have real units and which are only parameters that serve visual perception.

    The particle system should also set clear resource limits. Preallocate a pool of particle records and recycle them after they expire, avoiding repeated object creation every frame; similar particles can be considered for batch drawing to reduce submission overhead. Note that batch drawing does not eliminate the pixel-processing cost caused by many overlapping semi-transparent smoke particles. If the frame rate drops noticeably when the camera approaches the cloud, separately try reducing particle coverage area and reducing draw batches, and observe which is more effective, rather than only lowering the total particle count.

    3.3 Keep Playback Rhythm Consistent Across Refresh Rates

    Particle displacement, stage timing, and character motion should update based on elapsed time, not advance the same distance every frame. For updates sensitive to step size, such as collisions, use a fixed time step and limit the number of catch-up steps per frame. When the page resumes from the background, do not unconditionally catch up every step during the absence; decide based on interaction needs whether to keep the pre-pause progress or discard an excessively long time increment. This behavior should be explicitly tested during acceptance; otherwise, the same demo may show different eruption rhythms on different devices.

    4. How to Give Verifiable Generation Tasks

    Instead of only writing “make it more polished,” divide delivery requirements into runtime constraints, scene requirements, and acceptance conditions. For example, explicitly require a standalone web page that can be opened directly, does not access network resources, and includes camera control and reset; the coastal scene requires the character to move along the road; the volcano scene requires the demo to progress from preheat to cooling; both must remain displayed correctly after window resizing and show an understandable message when graphics capabilities are unavailable.

    Also distinguish three easily confused concepts: single-file, offline-runnable, and no third-party code are not equivalent. A web page file can load scripts from the network at startup, and it can also embed third-party code directly. If full offline operation is required, disconnect the network and reopen the file in a clean runtime environment, rather than only refreshing an already loaded page; if no third-party code is also required, the file contents must be further reviewed. For prototypes that will be maintained later, separate parameters, scene initialization, animation updates, and resource cleanup. Even if all code is eventually bundled into one file, individual modules can still be located and modified.

    Actual generation can proceed in three rounds. The first round builds only a minimal runnable version: use simple geometry to get path following working, or use a small number of particles to complete the full eruption cycle. The second round fixes position, timing, and interaction issues, especially ground contact, reset, and window changes. The third round adds materials, lighting, and decoration. This order helps localize regressions: if frame drops appear only after adding smoke, the investigation scope is much smaller than facing the entire complex scene from the start.

    5. Acceptance: Record Visual Quality, Stability, and Maintenance Cost Separately

    Acceptance can be organized by the following dimensions to avoid hiding key problems behind a single overall score:

    • Runtime integrity: Can it start when opened offline for the first time? Is there a clear message when initialization fails? Do repeated resets produce errors?
    • Spatial and motion quality: When viewed from the front, side, and low angles, are there clipping, camera boundary violations, conflicting shadow directions, or animation jumps?
    • Interaction consistency: Is progress preserved after pause? Is the initial state restored after reset? Can both touch and pointer operations complete the main tasks?
    • Performance and resources: Given the recorded device, window size, render resolution, and observation interval, focus on frame time and its variation; compare object counts and resource usage before and after repeated resets to find objects and event listeners that were not cleaned up.
    • Iteration cost: Try changing only road width or burst duration, and check whether the change requires repeated edits across multiple modules and whether other features regress.

    To compare different generation workflows, use the same requirements text, delivery constraints, and manual correction budget, and record first-runnable results and post-iteration results separately. The first output shows task understanding and basic implementation ability; post-iteration performance better shows error localization and modification ability. Mixing the two easily attributes the contribution of manual polishing to the first generation.

    The practical value of code generation in these tasks is to shorten the distance from an idea to an operable prototype. Coastal cycling tests whether space, materials, and motion can be coordinated; volcanic eruption tests whether time, state, and resources can be controlled. Write acceptance conditions before generation, then verify results with offline operation, multi-view checks, and repeated operations. Only then can you judge whether the scene in front of you is a good-looking demo or a prototype that a team can continue to develop.