Skip to content

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:

sh
./run-pocketspace.sh --scripts-dir scripts --launch avocado.js --launch panels.js

For a paired interaction example with overlapping boxes and panels, use the Step 3 headset fixtures and their documented controls.

ScriptDemonstrates
nested-containers.jsParent/child tools, recursive disposal, reparenting and subtree snapshots
asset-lifetime.jsExplicit unused-model release, fresh asset IDs and restoring a saved subtree after unload
directional-lights.jsScene-wide directional lights, rotating attachment, color/toggle controls and snapshot restore
directional-shadows.jsBounded sunlight shadows, rotating handle, resolution/enable controls and snapshot restore
point-shadows.jsOmnidirectional lamp shadows, per-face resolution, diagnostics and save/restore
shadows.jsMoving spotlight shadows, resolution/enable controls, budget diagnostics and snapshot restore
spotlights.jsGrabbable flashlight with rotating direction, adjustable cone, toggling and snapshot restore
lights.jsColored point lights attached to grabbable objects, toggling and snapshot restore
sheen.jsGrabbable fabric materials, direct/environment light switching and lighting toggle
pbr.jsOpt-in PBR lighting, environment reflections, and hand rotation
avocado.jsLoad and place one model
sample-gallery.jsMultiple assets and animated object transforms, including per-axis scale
shapes.jsA table and lamp built from generated shapes, placed at their returned center and extent, plus a recolored copy
full-sphere-gallery.jsPlacement in front, beside, and behind the viewer
grabbing.jsBoth-hand lasers, grip/trigger selection, hand rotation, distant yaw/depth controls, and reading where a grab left the box
input.jsController pose/raw input and haptics; right stick moves the box, right bumper toggles it
panels.jsRetained canvas drawing and a clickable button with a centered, measured label
blending.jsSmooth rigid, skeletal and morph transitions; bumper changes clips/phases, A/X pauses or resumes
morph.jsMorphing cube; A/X pauses or resumes, bumper restarts
animation.jsClip selection, pause/resume, stop/default pose and right-stick scrubbing
skinning.jsTwo grabbable skeletal characters with independent playback
containers.jsBumper opens/closes a tool with grabbable objects, a clickable panel and an owned callback
scene-save.jsSave model arrangements with bumper and restore with A/X; count saves with saved data
scene-import.jsImport the arrangement saved by scene-save.js into a second running script
event-bus.jsShare a trigger counter between running scripts; logs other scripts' and engine messages
physics-save.jsSave and restore bodies, hinge motors, springs, and motion
animation-save.jsPreserve independent animated poses and playback state
panel-save.jsPreserve panel pixels and layout, then edit and click the restored UI
lod.jsSixteen detailed grabbable cars with automatic LOD and full detail while held
instances.jsSixteen grabbable Avocados sharing a surface with ordered GPU instancing
grouped-stress.jsAdaptive stereo groups with splitting, merging, and rebalancing; up to 240 grabbable physics boxes
stress.jsAdd physics boxes with controllers; FPS, CPU, RAM, GPU memory, and physics timing HUD
joint-controls.jsLive spring length/response and hinge-limit changes with controller buttons
breakable-joints.jsPull suspended objects free of breakable connections; bumper reconnects
springs.jsElastic hanging weights with different damping; grip or trigger grabs, bumper resets
motors.jsMotor-driven blue and green panels; bumper changes angle, A/X toggles power
joints.jsHinged panel, tethered ball, and welded objects; grip or trigger grabs, bumper resets
mesh-colliders.jsStatic mesh platform with an opening and ramp; grabbable ball and cube
convex.jsModel-derived convex colliders, grabbing, and throwing; bumper resets unheld objects
colliders.jsExplicit box and sphere dimensions, a thin floor, and rotated walls
physics.jsGravity, grabbable boxes, throwing, and a collision event display; bumper resets unheld boxes
tracking.jsCorrected gaze, per-eye foveation centers, raw finger sensor values and the floor height
eye-calibration.jsPersonal calibration generator; requires an output path
scene-snapshot.jsIn-memory capture/restore with fresh IDs; bumper captures, A/X restores
container-transfer.jsTransfer object/panel ownership; B/Y transfers, A/X disposes left, bumper disposes right
physics-controls.jsImpulses, gravity, body removal/reattachment and a moving kinematic platform
panel-placement.jsWorld/head/arbitrary/object placement, rotation, visibility, panel removal/recreation and a label that follows a grabbed box
mesh-pointer.jsCustom 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 *-save examples.
  • 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.

Released under the GNU AGPL v3.0 only.