Example scripts
Start with build and run if you have not set up the engine. Each script is a complete scene you can run, read and adapt. Try grabbing for interaction, panels for UI, physics for simulation, or PBR for lit models. For complete scenes that combine several features, see the demos.
Run any example with ./run-pocketspace.sh --scripts-dir scripts --launch <name>.js. The engine starts with no user scripts when no --launch entries are supplied. Repeat --launch to run multiple examples together; each has its own scene and local object/panel IDs. For example:
./run-pocketspace.sh --scripts-dir scripts --launch avocado.js --launch panels.jsFor a paired interaction example with overlapping boxes and panels, use the Step 3 headset fixtures and their documented controls.
| Script | Demonstrates |
|---|---|
| nested-containers.js | Parent/child tools, recursive disposal, reparenting and subtree snapshots |
| asset-lifetime.js | Explicit unused-model release, fresh asset IDs and restoring a saved subtree after unload |
| directional-lights.js | Scene-wide directional lights, rotating attachment, color/toggle controls and snapshot restore |
| directional-shadows.js | Bounded sunlight shadows, rotating handle, resolution/enable controls and snapshot restore |
| point-shadows.js | Omnidirectional lamp shadows, per-face resolution, diagnostics and save/restore |
| shadows.js | Moving spotlight shadows, resolution/enable controls, budget diagnostics and snapshot restore |
| spotlights.js | Grabbable flashlight with rotating direction, adjustable cone, toggling and snapshot restore |
| lights.js | Colored point lights attached to grabbable objects, toggling and snapshot restore |
| sheen.js | Grabbable fabric materials, direct/environment light switching and lighting toggle |
| pbr.js | Opt-in PBR lighting, environment reflections, and hand rotation |
| avocado.js | Load and place one model |
| sample-gallery.js | Multiple assets and animated object transforms, including per-axis scale |
| shapes.js | A table and lamp built from generated shapes, placed at their returned center and extent, plus a recolored copy |
| full-sphere-gallery.js | Placement in front, beside, and behind the viewer |
| grabbing.js | Both-hand lasers, grip/trigger selection, hand rotation, distant yaw/depth controls, and reading where a grab left the box |
| input.js | Controller pose/raw input and haptics; right stick moves the box, right bumper toggles it |
| panels.js | Retained canvas drawing and a clickable button with a centered, measured label |
| blending.js | Smooth rigid, skeletal and morph transitions; bumper changes clips/phases, A/X pauses or resumes |
| morph.js | Morphing cube; A/X pauses or resumes, bumper restarts |
| animation.js | Clip selection, pause/resume, stop/default pose and right-stick scrubbing |
| skinning.js | Two grabbable skeletal characters with independent playback |
| containers.js | Bumper opens/closes a tool with grabbable objects, a clickable panel and an owned callback |
| scene-save.js | Save model arrangements with bumper and restore with A/X; count saves with saved data |
| scene-import.js | Import the arrangement saved by scene-save.js into a second running script |
| event-bus.js | Share a trigger counter between running scripts; logs other scripts' and engine messages |
| physics-save.js | Save and restore bodies, hinge motors, springs, and motion |
| animation-save.js | Preserve independent animated poses and playback state |
| panel-save.js | Preserve panel pixels and layout, then edit and click the restored UI |
| lod.js | Sixteen detailed grabbable cars with automatic LOD and full detail while held |
| instances.js | Sixteen grabbable Avocados sharing a surface with ordered GPU instancing |
| grouped-stress.js | Adaptive stereo groups with splitting, merging, and rebalancing; up to 240 grabbable physics boxes |
| stress.js | Add physics boxes with controllers; FPS, CPU, RAM, GPU memory, and physics timing HUD |
| joint-controls.js | Live spring length/response and hinge-limit changes with controller buttons |
| breakable-joints.js | Pull suspended objects free of breakable connections; bumper reconnects |
| springs.js | Elastic hanging weights with different damping; grip or trigger grabs, bumper resets |
| motors.js | Motor-driven blue and green panels; bumper changes angle, A/X toggles power |
| joints.js | Hinged panel, tethered ball, and welded objects; grip or trigger grabs, bumper resets |
| mesh-colliders.js | Static mesh platform with an opening and ramp; grabbable ball and cube |
| convex.js | Model-derived convex colliders, grabbing, and throwing; bumper resets unheld objects |
| colliders.js | Explicit box and sphere dimensions, a thin floor, and rotated walls |
| physics.js | Gravity, grabbable boxes, throwing, and a collision event display; bumper resets unheld boxes |
| tracking.js | Corrected gaze, per-eye foveation centers, raw finger sensor values and the floor height |
| eye-calibration.js | Personal calibration generator; requires an output path |
| scene-snapshot.js | In-memory capture/restore with fresh IDs; bumper captures, A/X restores |
| container-transfer.js | Transfer object/panel ownership; B/Y transfers, A/X disposes left, bumper disposes right |
| physics-controls.js | Impulses, gravity, body removal/reattachment and a moving kinematic platform |
| panel-placement.js | World/head/arbitrary/object placement, rotation, visibility, panel removal/recreation and a label that follows a grabbed box |
| mesh-pointer.js | Custom model presses on the engine laser with a 3D hit point, plus haptics |
Functionality coverage
See performance options for optimization defaults, opt-ins and tradeoffs used by these examples.
Examples demonstrate supported workflows rather than every spelling of the API. Each script starts with its purpose and controls; inline comments explain units, ownership, input-source differences and other behavior that is easy to misread.
- Models/transforms and full-sphere placement:
avocado,sample-gallery,full-sphere-gallery. - Models built from generated shapes and material overrides:
shapes. - Grabbing, grip/trigger policies and custom model input:
grabbing,input,mesh-pointer. - Retained canvas, pointer clicks, placement and panel lifetime:
panels,panel-placement,panel-save. - Clip playback, seeking/stopping, blending, skeletal/morph instances:
animation,blending,skinning,morph,animation-save. - Box/sphere/convex/static-mesh colliders, contacts and throwing:
physics,colliders,convex,mesh-colliders. - Joint types, motors, springs, breaking and live settings/state:
joints,motors,springs,breakable-joints,joint-controls. - Gravity, impulses, kinematic targets and body lifecycle:
physics-controls. - Container ownership, callback lifetime, transfers, memory/file snapshots:
containers,nested-containers,asset-lifetime,container-transfer,scene-snapshot, and the*-saveexamples. - Scene lighting:
lights,spotlights,directional-lights,shadows,directional-shadows,point-shadows. - PBR/environment lighting, automatic LOD, instancing and adaptive grouping:
pbr,sheen,lod,instances,grouped-stress. - Engine statistics, worker policy and bounded object cleanup:
stress,grouped-stress. - Raw/corrected gaze, foveation, finger sensing and calibration generation:
tracking,eye-calibration.
Custom fonts are guide-only because font paths depend on the runtime host. Optional action input/haptics, native pointers and eye data depend on SteamVR focus, bindings and tracking availability and may be unavailable on a given runtime. Calibration requires the documented output-path setup.
The two stress scenes are interactive examples with scene-specific caps, not hardware performance guarantees. Automated harnesses and experiments live in tests.