3D Particle Gesture Interaction in the Browser

    A practical guide to building a 3D particle scene in a single-page web app, mapping camera-based hand gestures to scale, spread, rotation, and explosion while keeping shapes, smoothing, performance, and camera fallback testable.

    3D particle interaction binds visible form and operable input on one real-time path. Particles form hearts, trees, rings, fireworks, and similar outlines in 3D space. A camera captures two-hand open/close and rotation, then maps those motions to scale, spread, spin, and explosion. Graphics and vision used to be long separate tracks. A common approach now is to write constraints in plain language, then run the scene in a single-page browser script for demo and iteration. The sections below follow an engineering order for a complete, maintainable web practice.

    Write requirements as verifiable constraints

    Particle systems usually fail on untestable constraints, not on flash. Fix at least four kinds of conditions: input (front camera, two-hand open/close, optional rotation); output (particle scale, spread radius, angular velocity, explosion); shape set (heart, flower, ring, statue outline, fireworks, and other switchable models); appearance (color picker, particle size and lifetime). Each item should be checkable on the page: opening the hands should expand the cloud; closing should densify it; shape changes should interpolate, not jump; new particles should pick up a new hue immediately. A checklist gives acceptance criteria whether you write the code by hand or with an AI coding tool.

    A 3D particle pipeline in the browser

    Web pages typically draw point sprites or small geometry with WebGL. Core objects: scene, perspective camera, render loop, particle buffers (position, velocity, lifetime, color). Position defines the outline: hearts from parametric sampling, trees from layered cones plus noise, rings from a torus plus thickness noise, fireworks by writing radial velocity at explosion. Each frame: update global scale and disturbance from gesture state; integrate velocity; decay lifetime and respawn on the shape surface; upload buffers to the GPU. Particle count should adapt to the device—thousands on mobile, higher density on desktop. A single HTML file with inline styles, scripts, and shaders avoids a heavy build chain and suits fast demos.

    Gesture detection and control mapping

    The camera-to-gesture path is usually: stream, frames, keypoints, geometric features, smoothing, mapping to particle parameters. Open/close can use palm distance or fingertip bounding-box diagonal; relative twist can map to rotation; a sudden open can trigger explosion. Time smoothing is required or the cloud will jitter. Exponential moving average on open/close, plus a threshold and cooldown on explosion, reduces false triggers. Handle permission and fallback: if the user denies the camera, sliders or buttons should still simulate open/close and explosion. Gestures should own continuous and trigger values; shape switching belongs on panel buttons so misrecognition does not swap models.

    Shape library, color, and explosion

    Shape switching is replacement of a target point cloud. Each shape precomputes target coordinates; particles spring or interpolate toward them. On switch, replace the target set and briefly raise disturbance so the cloud melts and reconverges. A color picker writes a global hue; new particles inherit it; existing ones can fade by lifetime so the whole screen does not snap. Explosion adds radial impulse on the velocity buffer, damps back, then re-attaches to the surface. Photo cards around a tree should be separate meshes, with click-to-zoom via camera interpolation—do not pack large images into particle textures. Rings, hearts, statues, and fireworks can share one buffer and only swap the target generator, which keeps panel switches cheap.

    Prompts and iteration (model-agnostic)

    These scenes are rarely correct on the first pass. Give an AI coding tool a structured brief (engine, gestures, panel, color, real-time response), then iterate on one defect at a time: weak open/close, explosion that never returns, holes on shape change. If you have a reference image, have the tool describe it in neutral terms (point density, radial blast, orbital ring, panel layout) and fold those nouns into the next constraints. Prefer a single HTML file that opens in the browser; leave bundlers and component frameworks until the effect is stable. Iteration should track the acceptance list, not extra unrelated effects.

    Performance, privacy, and delivery

    Vision plus rendering can saturate the main thread. Drop vision frame rate (for example 60 Hz render, 15–20 Hz recognition); offload particle updates to a Worker or GPU when possible; stop the camera track on unload. Process video frames locally; do not upload frames. Deliverables: single-page source, shape list, gesture-and-panel map, no-camera fallback notes. If logs go to the cloud, static pages on object storage and a log service for errors are enough—no need to bind a vendor-specific API name.

    Common issues and acceptance

    Empty frame: particles clipped by the camera or too small. No gesture: permissions, mirrored coordinates, filter coefficients. Flicker on shape change: resample when target counts differ. Mobile heat: fewer particles, no antialiasing, lower recognition resolution. Walk through open/close, rotation, explosion, recolor, shape change, and camera fallback; if all repeat, the skeleton is acceptable before visual polish.

    Conclusion

    The core is not stacking effects. It is writing shape, input, state machine, and performance budget as testable clauses and closing the loop in a single page. Hearts, trees, rings, and fireworks are different target functions on the same buffers. Solid constraints, smoothing, and fallback make the demo stable, repeatable, and easier to extend.