@fleox/agent3d 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +143 -0
- package/README.md +172 -2
- package/changelog.json +56 -0
- package/dist/agent/agent3d.mjs +11242 -0
- package/dist/agent/chunks/assets-BUUM9TUB.mjs +2448 -0
- package/dist/agent/chunks/browser-t_JL_B82.mjs +226 -0
- package/dist/agent/chunks/cdp-CaKRRzMX.mjs +177 -0
- package/dist/agent/chunks/check-CBO3Ekx1.mjs +971 -0
- package/dist/agent/chunks/export-BCI8vKw8.mjs +1130 -0
- package/dist/agent/chunks/gif-DQznzHTL.mjs +319 -0
- package/dist/agent/chunks/gltf-f_f0-OiV.mjs +207 -0
- package/dist/agent/chunks/imageCodec-BpDU9Lsq.mjs +101 -0
- package/dist/agent/chunks/jsonPath-DUCe1JpS.mjs +155 -0
- package/dist/agent/chunks/meshoptimizer-C-tN9jn5.mjs +1165 -0
- package/dist/agent/chunks/mp4-aOALfp3s.mjs +130 -0
- package/dist/agent/chunks/objects-DBAws7uf.mjs +53 -0
- package/dist/agent/chunks/optimizeSizing-CkZ3fZRp.mjs +540 -0
- package/dist/agent/chunks/package-Ck7_Nszg.mjs +75 -0
- package/dist/agent/chunks/png-DXfSGJZt.mjs +91 -0
- package/dist/agent/chunks/render-Cbuhz5uW.mjs +1511 -0
- package/dist/agent/chunks/rolldown-runtime-ebOQtxsr.mjs +18 -0
- package/dist/agent/chunks/scene-BgajNvBf.mjs +444 -0
- package/dist/agent/chunks/server-CACCerkZ.mjs +237 -0
- package/dist/agent/chunks/suggest-Cpcgv1RP.mjs +46 -0
- package/dist/agent/chunks/tools-DT2tetIK.mjs +1412 -0
- package/dist/agent/chunks/tree-BrNYGui2.mjs +75 -0
- package/dist/agent/chunks/webpAnim-qaq9YgKl.mjs +132 -0
- package/dist/runtime/agent3d-runtime.js +373 -0
- package/dist/runtime/agent3d-runtime.single.js +7360 -0
- package/dist/runtime/chunks/BufferGeometryUtils-Re3wQkXp.js +1 -0
- package/dist/runtime/chunks/EXRLoader-Bzm84si5.js +1 -0
- package/dist/runtime/chunks/FontLoader-BocwqK8V.js +2 -0
- package/dist/runtime/chunks/GLTFLoader-DHp1wv6J.js +1 -0
- package/dist/runtime/chunks/GroundedSkybox-esvlRCO0.js +1 -0
- package/dist/runtime/chunks/HDRLoader-DHrHp8fs.js +5 -0
- package/dist/runtime/chunks/OrbitControls-sjN2MF0e.js +1 -0
- package/dist/runtime/chunks/RectAreaLightUniformsLib-_mZ62yWn.js +1 -0
- package/dist/runtime/chunks/RoomEnvironment-CL4UR6ZW.js +1 -0
- package/dist/runtime/chunks/RoundedBoxGeometry-x-ot8ZSh.js +1 -0
- package/dist/runtime/chunks/SVGLoader-hRF0EwD-.js +1 -0
- package/dist/runtime/chunks/SkeletonUtils-DHlReJx3.js +1 -0
- package/dist/runtime/chunks/Sky-BrLN9Fk5.js +243 -0
- package/dist/runtime/chunks/audio-DbVNbf-r.js +1 -0
- package/dist/runtime/chunks/catalog-DL6sgPay.js +1 -0
- package/dist/runtime/chunks/easing-CXSz2e6P.js +1 -0
- package/dist/runtime/chunks/extrude-m04mghOS.js +1 -0
- package/dist/runtime/chunks/game-BoG2S6g4.js +20 -0
- package/dist/runtime/chunks/generators-OHhFCc2E.js +331 -0
- package/dist/runtime/chunks/materials-C2uffFEd.js +107 -0
- package/dist/runtime/chunks/meshGradient.glsl-BMatplLA.js +88 -0
- package/dist/runtime/chunks/meshopt_decoder.module-DXTYc6wn.js +1 -0
- package/dist/runtime/chunks/model-D-4xZz21.js +1 -0
- package/dist/runtime/chunks/params-DdApDOBw.js +1 -0
- package/dist/runtime/chunks/physicsHost-DPaVdM0R.js +1 -0
- package/dist/runtime/chunks/postfx-BpBXjLX3.js +1527 -0
- package/dist/runtime/chunks/postfx-i_J5Vf-l.js +1 -0
- package/dist/runtime/chunks/random-eeej60NW.js +1 -0
- package/dist/runtime/chunks/shaders-CmeJRio1.js +443 -0
- package/dist/runtime/chunks/svg-B3nZaQFD.js +1 -0
- package/dist/runtime/chunks/text-CmkU-b0C.js +2 -0
- package/dist/runtime/chunks/three.module-W4hp4qHb.js +4225 -0
- package/dist/runtime/chunks/toon-B5Jhf37V.js +6 -0
- package/dist/runtime/chunks/util-THUewKBk.js +1 -0
- package/dist/studio/assets/BufferGeometryUtils-wW9vV1l2.js +1 -0
- package/dist/studio/assets/EXRLoader-f8U8jnlr.js +1 -0
- package/dist/studio/assets/FontLoader-9sHudKzD.js +2 -0
- package/dist/studio/assets/GLTFLoader-C3C_3K62.js +1 -0
- package/dist/studio/assets/GroundedSkybox-BTqmv4fv.js +1 -0
- package/dist/studio/assets/HDRLoader-CkQyrTWY.js +5 -0
- package/dist/studio/assets/OrbitControls-fcOgB96a.js +1 -0
- package/dist/studio/assets/RectAreaLightUniformsLib-CZHWO9xf.js +1 -0
- package/dist/studio/assets/RoomEnvironment-BsISzuCp.js +1 -0
- package/dist/studio/assets/SVGLoader-BIkQDT66.js +1 -0
- package/dist/studio/assets/SkeletonUtils-CG5akqME.js +1 -0
- package/dist/studio/assets/Sky-C282PFL1.js +243 -0
- package/dist/studio/assets/audio-JD1kyX0A.js +1 -0
- package/dist/studio/assets/camera-BhKdE9ej.js +2 -0
- package/dist/studio/assets/editor-BgY_RoRd.js +1 -0
- package/dist/studio/assets/extrude-CnayHczh.js +1 -0
- package/dist/studio/assets/game-Dv5s4eMN.js +19 -0
- package/dist/studio/assets/generators-DVX3bAxe.js +331 -0
- package/dist/studio/assets/index-BQT0otii.css +1 -0
- package/dist/studio/assets/index-Dh-2Y34U.js +479 -0
- package/dist/studio/assets/meshopt_decoder.module-DXTYc6wn.js +1 -0
- package/dist/studio/assets/meshoptimizer-BCSwHBL3.js +1 -0
- package/dist/studio/assets/model-XZSP52pV.js +2 -0
- package/dist/studio/assets/physicsHost-C84FddIe.js +1 -0
- package/dist/studio/assets/postfx-BWWXb8i8.js +1527 -0
- package/dist/studio/assets/runtime-k_MFerbJ.js +572 -0
- package/dist/studio/assets/shaders-BEznGIct.js +443 -0
- package/dist/studio/assets/svg-DT8kx37i.js +2 -0
- package/dist/studio/assets/text-5DsJJHcj.js +3 -0
- package/dist/studio/assets/three.module-ByMn_ZTv.js +4225 -0
- package/dist/studio/index.html +16 -0
- package/library/LICENSES.md +77 -0
- package/library/fonts/LICENSES.md +42 -0
- package/library/fonts/anton.typeface.json +1 -0
- package/library/fonts/bebas-neue.typeface.json +1 -0
- package/library/fonts/display.typeface.json +1 -0
- package/library/fonts/inter-black.typeface.json +1 -0
- package/library/fonts/lobster.typeface.json +1 -0
- package/library/fonts/mono.typeface.json +1 -0
- package/library/fonts/montserrat-extrabold.typeface.json +1 -0
- package/library/fonts/pacifico.typeface.json +1 -0
- package/library/fonts/sans-bold.typeface.json +1 -0
- package/library/fonts/sans.typeface.json +1 -0
- package/library/fonts/serif-bold.typeface.json +1 -0
- package/library/fonts/serif.typeface.json +1 -0
- package/library/fonts/space-grotesk-bold.typeface.json +1 -0
- package/library/hdri/beach.hdr +0 -0
- package/library/hdri/beach.jpg +0 -0
- package/library/hdri/city.hdr +0 -0
- package/library/hdri/city.jpg +0 -0
- package/library/hdri/forest.hdr +0 -0
- package/library/hdri/forest.jpg +0 -0
- package/library/hdri/night-city.hdr +0 -0
- package/library/hdri/night-city.jpg +0 -0
- package/library/hdri/night.hdr +0 -0
- package/library/hdri/night.jpg +0 -0
- package/library/hdri/sky.hdr +0 -0
- package/library/hdri/sky.jpg +0 -0
- package/library/hdri/softbox.hdr +0 -0
- package/library/hdri/softbox.jpg +0 -0
- package/library/hdri/studio.hdr +0 -0
- package/library/hdri/studio.jpg +0 -0
- package/library/hdri/sunset.hdr +0 -0
- package/library/hdri/sunset.jpg +0 -0
- package/library/hdri/warehouse.hdr +0 -0
- package/library/hdri/warehouse.jpg +0 -0
- package/library/index.json +5510 -0
- package/library/models/animals/fish.glb +0 -0
- package/library/models/animals/fox.glb +0 -0
- package/library/models/buildings/castle.glb +0 -0
- package/library/models/buildings/house.glb +0 -0
- package/library/models/buildings/market.glb +0 -0
- package/library/models/buildings/tavern.glb +0 -0
- package/library/models/buildings/tower.glb +0 -0
- package/library/models/buildings/windmill.glb +0 -0
- package/library/models/characters/barbarian.glb +0 -0
- package/library/models/characters/knight.glb +0 -0
- package/library/models/characters/mage.glb +0 -0
- package/library/models/characters/mini-soldier.glb +0 -0
- package/library/models/characters/platformer-hero.glb +0 -0
- package/library/models/characters/robot.glb +0 -0
- package/library/models/characters/rogue.glb +0 -0
- package/library/models/characters/skeleton.glb +0 -0
- package/library/models/city/building-a.glb +0 -0
- package/library/models/city/building-b.glb +0 -0
- package/library/models/city/building-tall.glb +0 -0
- package/library/models/city/fire-hydrant.glb +0 -0
- package/library/models/city/road-corner.glb +0 -0
- package/library/models/city/road-crossing.glb +0 -0
- package/library/models/city/road-junction.glb +0 -0
- package/library/models/city/road-straight.glb +0 -0
- package/library/models/city/streetlight.glb +0 -0
- package/library/models/city/suburban-house.glb +0 -0
- package/library/models/city/traffic-light.glb +0 -0
- package/library/models/city/water-tower.glb +0 -0
- package/library/models/food/apple.glb +0 -0
- package/library/models/food/avocado.glb +0 -0
- package/library/models/food/baguette.glb +0 -0
- package/library/models/food/bread-loaf.glb +0 -0
- package/library/models/food/burger.glb +0 -0
- package/library/models/food/carrot.glb +0 -0
- package/library/models/food/cheese.glb +0 -0
- package/library/models/food/cookie.glb +0 -0
- package/library/models/food/croissant.glb +0 -0
- package/library/models/food/cupcake.glb +0 -0
- package/library/models/food/dinner-plate.glb +0 -0
- package/library/models/food/donut.glb +0 -0
- package/library/models/food/ketchup.glb +0 -0
- package/library/models/food/mug.glb +0 -0
- package/library/models/food/pain-au-chocolat.glb +0 -0
- package/library/models/food/stew.glb +0 -0
- package/library/models/food/tomato.glb +0 -0
- package/library/models/food/veggie-burger.glb +0 -0
- package/library/models/nature/bush.glb +0 -0
- package/library/models/nature/cactus.glb +0 -0
- package/library/models/nature/cloud.glb +0 -0
- package/library/models/nature/fir-tree.glb +0 -0
- package/library/models/nature/forest-patch.glb +0 -0
- package/library/models/nature/grass-small.glb +0 -0
- package/library/models/nature/grass.glb +0 -0
- package/library/models/nature/hex-grass.glb +0 -0
- package/library/models/nature/hex-water.glb +0 -0
- package/library/models/nature/hills.glb +0 -0
- package/library/models/nature/mountain.glb +0 -0
- package/library/models/nature/pine-autumn.glb +0 -0
- package/library/models/nature/pine-tree.glb +0 -0
- package/library/models/nature/pumpkin.glb +0 -0
- package/library/models/nature/rock-flat.glb +0 -0
- package/library/models/nature/rock.glb +0 -0
- package/library/models/nature/tree-dead.glb +0 -0
- package/library/models/nature/tree-slim.glb +0 -0
- package/library/models/nature/trees-cluster.glb +0 -0
- package/library/models/nature/waterlily.glb +0 -0
- package/library/models/platformer/blaster.glb +0 -0
- package/library/models/platformer/block-coin.glb +0 -0
- package/library/models/platformer/brick.glb +0 -0
- package/library/models/platformer/coin.glb +0 -0
- package/library/models/platformer/enemy-flying.glb +0 -0
- package/library/models/platformer/flag.glb +0 -0
- package/library/models/platformer/platform-falling.glb +0 -0
- package/library/models/platformer/platform-grass-round.glb +0 -0
- package/library/models/platformer/platform-large.glb +0 -0
- package/library/models/platformer/platform-medium.glb +0 -0
- package/library/models/platformer/platform.glb +0 -0
- package/library/models/platformer/target.glb +0 -0
- package/library/models/platformer/track-corner.glb +0 -0
- package/library/models/platformer/track-straight.glb +0 -0
- package/library/models/platformer/wall-low.glb +0 -0
- package/library/models/products/boombox.glb +0 -0
- package/library/models/products/iridescent-lamp.glb +0 -0
- package/library/models/products/lantern.glb +0 -0
- package/library/models/products/lounge-chair.glb +0 -0
- package/library/models/products/sneaker.glb +0 -0
- package/library/models/products/velvet-sofa.glb +0 -0
- package/library/models/products/water-bottle.glb +0 -0
- package/library/models/props/alarm-clock.glb +0 -0
- package/library/models/props/armchair.glb +0 -0
- package/library/models/props/barrel.glb +0 -0
- package/library/models/props/bench.glb +0 -0
- package/library/models/props/brass-vase.glb +0 -0
- package/library/models/props/chest.glb +0 -0
- package/library/models/props/coffee-table.glb +0 -0
- package/library/models/props/coin-stack.glb +0 -0
- package/library/models/props/coin.glb +0 -0
- package/library/models/props/couch.glb +0 -0
- package/library/models/props/crate.glb +0 -0
- package/library/models/props/flag.glb +0 -0
- package/library/models/props/gravestone.glb +0 -0
- package/library/models/props/key.glb +0 -0
- package/library/models/props/lamp.glb +0 -0
- package/library/models/props/lantern.glb +0 -0
- package/library/models/props/marble-bust.glb +0 -0
- package/library/models/props/modern-armchair.glb +0 -0
- package/library/models/props/potted-succulent.glb +0 -0
- package/library/models/props/rubber-duck.glb +0 -0
- package/library/models/props/shield.glb +0 -0
- package/library/models/props/sword-shield.glb +0 -0
- package/library/models/props/sword.glb +0 -0
- package/library/models/props/table.glb +0 -0
- package/library/models/props/tent.glb +0 -0
- package/library/models/props/torch.glb +0 -0
- package/library/models/props/trophy.glb +0 -0
- package/library/models/space/base-module.glb +0 -0
- package/library/models/space/lander.glb +0 -0
- package/library/models/space/landing-pad.glb +0 -0
- package/library/models/space/rocks.glb +0 -0
- package/library/models/space/solar-panel.glb +0 -0
- package/library/models/space/space-truck.glb +0 -0
- package/library/models/space/wind-turbine.glb +0 -0
- package/library/models/vehicles/car.glb +0 -0
- package/library/models/vehicles/hatchback.glb +0 -0
- package/library/models/vehicles/motorcycle.glb +0 -0
- package/library/models/vehicles/police-car.glb +0 -0
- package/library/models/vehicles/taxi.glb +0 -0
- package/library/models/vehicles/truck.glb +0 -0
- package/library/sources.json +2856 -0
- package/library/textures/brick-color.jpg +0 -0
- package/library/textures/brick-normal.jpg +0 -0
- package/library/textures/brick-roughness.jpg +0 -0
- package/library/textures/concrete-color.jpg +0 -0
- package/library/textures/concrete-normal.jpg +0 -0
- package/library/textures/concrete-roughness.jpg +0 -0
- package/library/textures/fabric-color.jpg +0 -0
- package/library/textures/fabric-normal.jpg +0 -0
- package/library/textures/fabric-roughness.jpg +0 -0
- package/library/textures/grass-ground-color.jpg +0 -0
- package/library/textures/grass-ground-normal.jpg +0 -0
- package/library/textures/grass-ground-roughness.jpg +0 -0
- package/library/textures/rusty-metal-color.jpg +0 -0
- package/library/textures/rusty-metal-normal.jpg +0 -0
- package/library/textures/rusty-metal-roughness.jpg +0 -0
- package/library/textures/wood-planks-color.jpg +0 -0
- package/library/textures/wood-planks-normal.jpg +0 -0
- package/library/textures/wood-planks-roughness.jpg +0 -0
- package/package.json +67 -4
- package/plugin/.claude-plugin/plugin.json +19 -0
- package/plugin/skills/agent3d-assets/SKILL.md +140 -0
- package/plugin/skills/agent3d-assets/references/sources.md +33 -0
- package/plugin/skills/agent3d-create/SKILL.md +141 -0
- package/plugin/skills/agent3d-create/references/art-direction.md +144 -0
- package/plugin/skills/agent3d-create/references/recipes.md +1357 -0
- package/plugin/skills/agent3d-edit/SKILL.md +121 -0
- package/plugin/skills/agent3d-edit/references/patch-ops.md +278 -0
- package/plugin/skills/agent3d-game/SKILL.md +111 -0
- package/plugin/skills/agent3d-game/references/game-patterns.md +262 -0
- package/plugin/skills/agent3d-game/references/script-api.md +211 -0
- package/plugin/skills/agent3d-publish/SKILL.md +161 -0
- package/plugin/skills/agent3d-publish/references/integrations.md +221 -0
- package/templates/banner-aurora-night/README.md +15 -0
- package/templates/banner-aurora-night/agent3d.json +8 -0
- package/templates/banner-aurora-night/preview.png +0 -0
- package/templates/banner-aurora-night/scene.json +327 -0
- package/templates/banner-aurora-night/template.json +24 -0
- package/templates/banner-data-bars/README.md +15 -0
- package/templates/banner-data-bars/agent3d.json +8 -0
- package/templates/banner-data-bars/preview.png +0 -0
- package/templates/banner-data-bars/scene.json +222 -0
- package/templates/banner-data-bars/template.json +25 -0
- package/templates/banner-floating-shapes/README.md +15 -0
- package/templates/banner-floating-shapes/agent3d.json +8 -0
- package/templates/banner-floating-shapes/preview.png +0 -0
- package/templates/banner-floating-shapes/scene.json +703 -0
- package/templates/banner-floating-shapes/template.json +24 -0
- package/templates/banner-gradient-blob/README.md +16 -0
- package/templates/banner-gradient-blob/agent3d.json +8 -0
- package/templates/banner-gradient-blob/preview.png +0 -0
- package/templates/banner-gradient-blob/scene.json +330 -0
- package/templates/banner-gradient-blob/template.json +21 -0
- package/templates/banner-liquid-chrome/README.md +16 -0
- package/templates/banner-liquid-chrome/agent3d.json +8 -0
- package/templates/banner-liquid-chrome/preview.png +0 -0
- package/templates/banner-liquid-chrome/scene.json +290 -0
- package/templates/banner-liquid-chrome/template.json +24 -0
- package/templates/banner-logo-extrude/README.md +24 -0
- package/templates/banner-logo-extrude/agent3d.json +8 -0
- package/templates/banner-logo-extrude/assets/logo.svg +6 -0
- package/templates/banner-logo-extrude/assets/manifest.json +13 -0
- package/templates/banner-logo-extrude/preview.png +0 -0
- package/templates/banner-logo-extrude/scene.json +332 -0
- package/templates/banner-logo-extrude/template.json +22 -0
- package/templates/banner-neon-title/README.md +18 -0
- package/templates/banner-neon-title/agent3d.json +8 -0
- package/templates/banner-neon-title/preview.png +0 -0
- package/templates/banner-neon-title/scene.json +494 -0
- package/templates/banner-neon-title/template.json +25 -0
- package/templates/banner-wave-grid/README.md +18 -0
- package/templates/banner-wave-grid/agent3d.json +8 -0
- package/templates/banner-wave-grid/preview.png +0 -0
- package/templates/banner-wave-grid/scene.json +217 -0
- package/templates/banner-wave-grid/template.json +23 -0
- package/templates/card-hover-3d/README.md +16 -0
- package/templates/card-hover-3d/agent3d.json +8 -0
- package/templates/card-hover-3d/preview.png +0 -0
- package/templates/card-hover-3d/scene.json +359 -0
- package/templates/card-hover-3d/template.json +21 -0
- package/templates/card-product-tilt/README.md +14 -0
- package/templates/card-product-tilt/agent3d.json +8 -0
- package/templates/card-product-tilt/preview.png +0 -0
- package/templates/card-product-tilt/scene.json +296 -0
- package/templates/card-product-tilt/template.json +23 -0
- package/templates/character-mascot-hero/README.md +19 -0
- package/templates/character-mascot-hero/agent3d.json +8 -0
- package/templates/character-mascot-hero/preview.png +0 -0
- package/templates/character-mascot-hero/scene.json +512 -0
- package/templates/character-mascot-hero/template.json +8 -0
- package/templates/character-showcase/README.md +27 -0
- package/templates/character-showcase/agent3d.json +8 -0
- package/templates/character-showcase/preview.png +0 -0
- package/templates/character-showcase/scene.json +440 -0
- package/templates/character-showcase/template.json +24 -0
- package/templates/diorama-city/README.md +21 -0
- package/templates/diorama-city/agent3d.json +8 -0
- package/templates/diorama-city/preview.png +0 -0
- package/templates/diorama-city/scene.json +432 -0
- package/templates/diorama-city/template.json +21 -0
- package/templates/game-basket/README.md +25 -0
- package/templates/game-basket/agent3d.json +8 -0
- package/templates/game-basket/preview.png +0 -0
- package/templates/game-basket/scene.json +640 -0
- package/templates/game-basket/scripts/basket.js +176 -0
- package/templates/game-basket/template.json +8 -0
- package/templates/game-coin-collector/README.md +28 -0
- package/templates/game-coin-collector/agent3d.json +8 -0
- package/templates/game-coin-collector/preview.png +0 -0
- package/templates/game-coin-collector/scene.json +900 -0
- package/templates/game-coin-collector/scripts/collector.js +210 -0
- package/templates/game-coin-collector/template.json +19 -0
- package/templates/game-maze/README.md +24 -0
- package/templates/game-maze/agent3d.json +8 -0
- package/templates/game-maze/preview.png +0 -0
- package/templates/game-maze/scene.json +315 -0
- package/templates/game-maze/scripts/maze.js +168 -0
- package/templates/game-maze/template.json +18 -0
- package/templates/game-physics-playground/README.md +30 -0
- package/templates/game-physics-playground/agent3d.json +8 -0
- package/templates/game-physics-playground/preview.png +0 -0
- package/templates/game-physics-playground/scene.json +1712 -0
- package/templates/game-physics-playground/scripts/playground.js +151 -0
- package/templates/game-physics-playground/template.json +19 -0
- package/templates/game-platformer/README.md +26 -0
- package/templates/game-platformer/agent3d.json +8 -0
- package/templates/game-platformer/preview.png +0 -0
- package/templates/game-platformer/scene.json +1063 -0
- package/templates/game-platformer/scripts/platformer.js +222 -0
- package/templates/game-platformer/template.json +8 -0
- package/templates/game-runner/README.md +30 -0
- package/templates/game-runner/agent3d.json +8 -0
- package/templates/game-runner/preview.png +0 -0
- package/templates/game-runner/scene.json +1317 -0
- package/templates/game-runner/scripts/runner.js +263 -0
- package/templates/game-runner/template.json +18 -0
- package/templates/game-tap-targets/README.md +21 -0
- package/templates/game-tap-targets/agent3d.json +8 -0
- package/templates/game-tap-targets/preview.png +0 -0
- package/templates/game-tap-targets/scene.json +924 -0
- package/templates/game-tap-targets/scripts/targets.js +159 -0
- package/templates/game-tap-targets/template.json +19 -0
- package/templates/hero-floating-island/README.md +18 -0
- package/templates/hero-floating-island/agent3d.json +8 -0
- package/templates/hero-floating-island/preview.png +0 -0
- package/templates/hero-floating-island/scene.json +658 -0
- package/templates/hero-floating-island/template.json +8 -0
- package/templates/hero-perfume-luxury/README.md +18 -0
- package/templates/hero-perfume-luxury/agent3d.json +8 -0
- package/templates/hero-perfume-luxury/preview.png +0 -0
- package/templates/hero-perfume-luxury/scene.json +529 -0
- package/templates/hero-perfume-luxury/template.json +27 -0
- package/templates/hero-product-turntable/README.md +16 -0
- package/templates/hero-product-turntable/agent3d.json +8 -0
- package/templates/hero-product-turntable/preview.png +0 -0
- package/templates/hero-product-turntable/scene.json +225 -0
- package/templates/hero-product-turntable/template.json +21 -0
- package/templates/hero-saas-globe/README.md +16 -0
- package/templates/hero-saas-globe/agent3d.json +8 -0
- package/templates/hero-saas-globe/preview.png +0 -0
- package/templates/hero-saas-globe/scene.json +318 -0
- package/templates/hero-saas-globe/template.json +24 -0
- package/templates/hero-scroll-story/README.md +26 -0
- package/templates/hero-scroll-story/agent3d.json +8 -0
- package/templates/hero-scroll-story/preview.png +0 -0
- package/templates/hero-scroll-story/scene.json +642 -0
- package/templates/hero-scroll-story/template.json +22 -0
- package/templates/hero-sneaker-showcase/README.md +19 -0
- package/templates/hero-sneaker-showcase/agent3d.json +8 -0
- package/templates/hero-sneaker-showcase/preview.png +0 -0
- package/templates/hero-sneaker-showcase/scene.json +523 -0
- package/templates/hero-sneaker-showcase/template.json +23 -0
- package/templates/hero-space-planet/README.md +17 -0
- package/templates/hero-space-planet/agent3d.json +8 -0
- package/templates/hero-space-planet/preview.png +0 -0
- package/templates/hero-space-planet/scene.json +330 -0
- package/templates/hero-space-planet/template.json +21 -0
- package/templates/landscape-island/README.md +21 -0
- package/templates/landscape-island/agent3d.json +8 -0
- package/templates/landscape-island/preview.png +0 -0
- package/templates/landscape-island/scene.json +716 -0
- package/templates/landscape-island/template.json +24 -0
- package/templates/landscape-night-galaxy/README.md +25 -0
- package/templates/landscape-night-galaxy/agent3d.json +8 -0
- package/templates/landscape-night-galaxy/preview.png +0 -0
- package/templates/landscape-night-galaxy/scene.json +403 -0
- package/templates/landscape-night-galaxy/template.json +8 -0
- package/templates/landscape-valley-sunset/README.md +20 -0
- package/templates/landscape-valley-sunset/agent3d.json +8 -0
- package/templates/landscape-valley-sunset/preview.png +0 -0
- package/templates/landscape-valley-sunset/scene.json +265 -0
- package/templates/landscape-valley-sunset/template.json +22 -0
- package/templates/scene-cozy-room/README.md +21 -0
- package/templates/scene-cozy-room/agent3d.json +8 -0
- package/templates/scene-cozy-room/preview.png +0 -0
- package/templates/scene-cozy-room/scene.json +728 -0
- package/templates/scene-cozy-room/template.json +8 -0
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
# Game patterns
|
|
2
|
+
|
|
3
|
+
Snippets assume `const { … } = api.data` for tuning values kept in `scene.data`.
|
|
4
|
+
|
|
5
|
+
## State machine with HUD per phase
|
|
6
|
+
|
|
7
|
+
```json
|
|
8
|
+
"ui": {
|
|
9
|
+
"elements": [
|
|
10
|
+
{ "id": "score", "type": "text", "text": "Score {score}", "anchor": "top-left", "style": "pill" },
|
|
11
|
+
{ "id": "best", "type": "text", "text": "Best {best}", "anchor": "top-right", "style": "pill" },
|
|
12
|
+
{ "id": "title", "type": "text", "text": "Lane Runner", "anchor": "center", "style": "title", "visible": "phase == 'ready'" },
|
|
13
|
+
{ "id": "start", "type": "button", "text": "Play", "anchor": "bottom", "action": "start", "visible": "phase == 'ready'" },
|
|
14
|
+
{ "id": "over", "type": "text", "text": "Game over - {score}", "anchor": "center", "style": "title", "visible": "phase == 'over'" },
|
|
15
|
+
{ "id": "retry", "type": "button", "text": "Retry", "anchor": "bottom", "action": "retry", "visible": "phase == 'over'" }
|
|
16
|
+
],
|
|
17
|
+
"color": "#ffffff",
|
|
18
|
+
"accent": "#ef476f"
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
```js
|
|
23
|
+
function reset(phase) {
|
|
24
|
+
for (const b of blocks) b.remove();
|
|
25
|
+
blocks = [];
|
|
26
|
+
api.state.phase = phase;
|
|
27
|
+
api.state.score = 0;
|
|
28
|
+
api.state.best = Number(api.storage.get("best") ?? 0);
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
start() { reset("ready"); },
|
|
32
|
+
onEvent(name) { if (name === "start" || name === "retry") reset("play"); },
|
|
33
|
+
update(dt) { if (api.state.phase === "over") return; /* … */ },
|
|
34
|
+
};
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Keyboard + touch
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
const swipe = api.input.swipe();
|
|
41
|
+
if (api.input.pressed("ArrowLeft") || api.input.pressed("KeyA") || swipe === "left") lane = Math.max(0, lane - 1);
|
|
42
|
+
if (api.input.pressed("ArrowRight") || api.input.pressed("KeyD") || swipe === "right") lane = Math.min(2, lane + 1);
|
|
43
|
+
if (api.input.pressed("Space") || api.input.pointer.justPressed || swipe === "up") jump();
|
|
44
|
+
// Smooth toward the target lane instead of teleporting:
|
|
45
|
+
player.position.x += (lanes[lane] - player.position.x) * Math.min(1, dt * 14);
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Continuous movement: `isDown` for keys, and for touch move toward `api.input.pointerWorld()` while `api.input.pointer.down`.
|
|
49
|
+
|
|
50
|
+
## Spawning by cloning
|
|
51
|
+
|
|
52
|
+
Declare the template once, hidden, with a body:
|
|
53
|
+
|
|
54
|
+
```json
|
|
55
|
+
{ "id": "block", "kind": "mesh", "geometry": { "type": "box", "width": 1.4, "height": 1, "depth": 1 }, "material": { "preset": "clay", "color": "#ef476f" }, "position": [0, 0.5, -60], "visible": false, "tags": ["template"], "body": { "type": "trigger", "shape": "box" } }
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
```js
|
|
59
|
+
let n = 0;
|
|
60
|
+
function spawn() {
|
|
61
|
+
const x = lanes[Math.floor(api.random() * lanes.length)];
|
|
62
|
+
const b = api.clone("block", { id: `block${n++}`, position: [x, 0.5, -30] });
|
|
63
|
+
b.visible = true;
|
|
64
|
+
blocks.push(b);
|
|
65
|
+
}
|
|
66
|
+
// Move and recycle:
|
|
67
|
+
for (const b of blocks.slice()) {
|
|
68
|
+
b.position.z += speed * dt;
|
|
69
|
+
if (b.position.z > 6) { b.remove(); blocks.splice(blocks.indexOf(b), 1); }
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Spawn close enough that the first obstacle appears within 2–3 seconds (a render at t = 3 should show it).
|
|
74
|
+
|
|
75
|
+
## Collisions
|
|
76
|
+
|
|
77
|
+
```js
|
|
78
|
+
if (api.state.phase === "play" && api.physics.overlaps(player, b)) gameOver();
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Dynamic bodies (balls, falling crates) use real rigid-body responses:
|
|
82
|
+
|
|
83
|
+
```js
|
|
84
|
+
start() {
|
|
85
|
+
api.physics.onCollision((a, b, info) => {
|
|
86
|
+
// info: { point, normal, impulse, speed } — only real impacts make noise
|
|
87
|
+
if ((a.id === "ball" || b.id === "ball") && info.impulse > 1) api.audio.play("hit");
|
|
88
|
+
});
|
|
89
|
+
},
|
|
90
|
+
update() {
|
|
91
|
+
if (api.input.pressed("Space")) api.physics.applyImpulse("ball", [0, 6, 0]);
|
|
92
|
+
},
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Physics recipes
|
|
96
|
+
|
|
97
|
+
Bodies are real rigid bodies (cannon-es): they rotate, tumble, stack and fall asleep. The simulation is deterministic (fixed step), so renders replay exactly.
|
|
98
|
+
|
|
99
|
+
**Platformer hero** — a capsule character controller (no tipping, no wall sticking, coyote-time jumps):
|
|
100
|
+
|
|
101
|
+
```json
|
|
102
|
+
{ "id": "hero", "kind": "model", "src": "library:models/characters/robot.glb", "scale": 0.3, "position": [0, 1, 0], "body": { "type": "dynamic", "shape": "capsule", "radius": 0.35, "height": 1.4, "character": true } }
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Size the model first: `render --isolate hero --json` returns `isolated.size` (the robot is ≈ 4.8 units tall unscaled, so `scale: 0.3` makes a 1.45-unit hero), then fit the capsule `height` / `radius` (world units) to it.
|
|
106
|
+
|
|
107
|
+
```js
|
|
108
|
+
update() {
|
|
109
|
+
const x = (api.input.isDown("ArrowRight") ? 1 : 0) - (api.input.isDown("ArrowLeft") ? 1 : 0);
|
|
110
|
+
api.physics.moveCharacter(hero, { x, z: 0 }, { speed: 6, acceleration: 40, airControl: 0.35 });
|
|
111
|
+
if (api.input.pressed("Space") && api.physics.jump(hero, 7)) api.audio.play("jump");
|
|
112
|
+
// api.physics.grounded(hero) picks the animation clip (jump / run / idle)
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
**Velocity-driven player** (roller, hover ship) — a `dynamic` body with `"fixedRotation": true` (without it, friction tips the player over as soon as it moves):
|
|
117
|
+
|
|
118
|
+
```json
|
|
119
|
+
{ "id": "hero", "kind": "mesh", "geometry": { "type": "box", "width": 0.8, "height": 0.8, "depth": 0.8 }, "material": { "preset": "plastic", "color": "#ff6b6b" }, "position": [-6, 1, 0], "body": { "type": "dynamic", "fixedRotation": true } }
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
```js
|
|
123
|
+
update() {
|
|
124
|
+
const x = (api.input.isDown("ArrowRight") ? 1 : 0) - (api.input.isDown("ArrowLeft") ? 1 : 0);
|
|
125
|
+
const v = api.physics.getVelocity(hero);
|
|
126
|
+
api.physics.setVelocity(hero, [x * 5, v[1], 0]); // keep gravity's vertical speed
|
|
127
|
+
if (api.input.pressed("Space") && api.physics.grounded(hero)) api.physics.applyImpulse(hero, [0, 6, 0]);
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
**Throw / knock things over** — clone a hidden projectile (synchronous, keeps determinism) and launch it on a ballistic arc toward the pointer (`ccd: true` on fast projectiles stops tunnelling):
|
|
132
|
+
|
|
133
|
+
```js
|
|
134
|
+
const target = api.input.pointerWorld(); // { x, y, z, objectId? }
|
|
135
|
+
const from = [0, 1.3, 7], T = 0.6, g = 9.81;
|
|
136
|
+
const ball = api.clone("ballProto", { id: "ball" + ++n, position: from });
|
|
137
|
+
ball.visible = true;
|
|
138
|
+
api.physics.setVelocity(ball, [(target.x - from[0]) / T, (target.y - from[1]) / T + 0.5 * g * T, (target.z - from[2]) / T]);
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Keep the prototype asleep out of sight: `"position": [0, -29.7, 0], "visible": false` resting on a hidden static shelf. The `game-physics-playground` template is a complete example (tower of blocks, rebuild without reload, impact sounds).
|
|
142
|
+
|
|
143
|
+
**Moving platforms** — `kinematic` bodies moved from the script (or given a velocity) push dynamic bodies and **carry characters** standing on them (sliding lifts, elevators going up or down, turntables): the engine adds the platform's motion to the hero every step, so never move the hero with the lift yourself (that would carry it twice). `grounded(hero)` stays true and `contacts(hero)` lists the lift on every step of the ride:
|
|
144
|
+
|
|
145
|
+
```js
|
|
146
|
+
lift.position.set(base + Math.sin(api.time() * 0.9) * 1.6, lift.position.y, 0); // every update
|
|
147
|
+
elevator.position.y = baseY + 1.5 - Math.cos(api.time() * 0.8) * 1.5;
|
|
148
|
+
const onLift = api.physics.grounded(hero) && api.physics.contacts(hero).some((o) => o.id === "lift");
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
**Keeping a 2.5D hero on its plane** — clamping every step is fine: small corrections keep the character's contacts and ground state (jumps still work). A respawn (a teleport of more than 0.5 m) clears them until the next step:
|
|
152
|
+
|
|
153
|
+
```js
|
|
154
|
+
hero.position.set(hero.position.x, hero.position.y, 0); // after moveCharacter, every update
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
**Platforms with decorations** — a measured collider (`box`, `auto`, `convex`, `trimesh`) uses the object's own geometry only, so a grass slab with a dirt child keeps a box centred on the slab: no explicit `size` / `offset` needed. To make the decoration solid too, use `"shape": "compound"` without `shapes` (one box per child without a body). A child with its own `body` always gets its own collider:
|
|
158
|
+
|
|
159
|
+
```json
|
|
160
|
+
{ "id": "ledge", "kind": "mesh", "geometry": { "type": "roundedBox", "width": 4, "height": 0.4, "depth": 2 }, "body": { "type": "static", "shape": "box" },
|
|
161
|
+
"children": [{ "id": "ledgeDirt", "kind": "mesh", "geometry": { "type": "roundedBox", "width": 3.8, "height": 1, "depth": 1.8 }, "position": [0, -0.6, 0] }] }
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
**Doors, pendulums, chains, wheels** — `physics.joints` (world-space pivots at scene start; omit `b` to pin to the world):
|
|
165
|
+
|
|
166
|
+
```json
|
|
167
|
+
"physics": { "joints": [
|
|
168
|
+
{ "id": "door", "type": "hinge", "a": "door", "pivot": [-1, 1.2, 0], "axis": [0, 1, 0] },
|
|
169
|
+
{ "type": "point", "a": "bob", "pivot": [0, 5, 0] },
|
|
170
|
+
{ "id": "wheel", "type": "hinge", "a": "wheel", "pivot": [2, 0.5, 0], "axis": [0, 0, 1], "motor": { "speed": 180, "maxForce": 50 } }
|
|
171
|
+
] }
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
`api.physics.setMotorSpeed("wheel", 360)` changes a motor at run time. A flipper or a door that must stop: `"limits": [-30, 30]` (degrees from its start pose). Scaling a body from a script (`obj.scale.set(…)`) resizes its collider, unless a joint holds it.
|
|
175
|
+
|
|
176
|
+
**Sensors** — `trigger` bodies: `api.physics.onTriggerEnter((zone, other) => …)` / `onTriggerExit`, or poll `api.physics.overlaps(player, coin)` (exact shapes, works between any body types).
|
|
177
|
+
|
|
178
|
+
**Layers** — `"layer": "debris", "collidesWith": ["default"]` keeps debris from blocking the player; raycasts take `{ layers: ["default"], ignore: [player], triggers: false }`.
|
|
179
|
+
|
|
180
|
+
**Shapes** — boxes from the object's own mesh bounds are the default (cheapest, stable stacks; child objects are not included). Use `sphere` for balls (they roll), `capsule` for characters, `convex` for dynamic props of irregular shape (models), `trimesh` or `auto` for static level geometry (exact, e.g. a ramp model), `heightfield` / `auto` for a terrain generator, `compound` to assemble a few primitives (a table: top box + 4 leg boxes).
|
|
181
|
+
|
|
182
|
+
**Scoring pitfalls** — `obj.rotation` is Euler XYZ in **degrees**, so one angle does not tell whether a can or a pin is down (on its side it may read x = 90 or z = 90; turned around Y after a fall, other combinations): score by height (`position.y` below the table top) or by leaving a zone (trigger `onTriggerExit`). Count only once bodies settle (velocity near 0, a short delay after the last impact), and when you restack, zero `setVelocity` / `setAngularVelocity`, reset `rotation` and remove the balls still in flight — they would knock the fresh stack over. The Physics toss recipe (skill `agent3d-create`) restacks this way.
|
|
183
|
+
|
|
184
|
+
**Debugging** — `"physics": { "debug": true }` draws every collider (green dynamic, blue static, orange kinematic, magenta trigger, grey asleep) in renders: look at it whenever something falls through, floats or collides early. Remove it before export.
|
|
185
|
+
|
|
186
|
+
## Timeline cues and interactions in a game
|
|
187
|
+
|
|
188
|
+
A timeline can stage an intro (camera move, title drop) and hand over to the game with a marker:
|
|
189
|
+
|
|
190
|
+
```json
|
|
191
|
+
"timeline": { "duration": 3, "markers": { "go": 1.5 }, "tracks": [{ "target": "title.position.y", "keys": [[0, 6], [1.5, 3, "outBack"]] }] }
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
```js
|
|
195
|
+
start() {
|
|
196
|
+
api.state.phase = "intro";
|
|
197
|
+
api.on("go", () => { api.state.phase = "play"; }); // fires when the timeline crosses 1.5 s
|
|
198
|
+
},
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
`scene.interactions` work in games too: a key or a click can `emit` an event to the scripts (`{ "on": "key", "key": "KeyR", "do": [{ "emit": "retry" }] }` → `onEvent("retry")`), play a segment or open a URL (`{ "on": "click", "target": "cta", "do": [{ "openUrl": "https://…" }] }`). The reverse works too: an event a script `api.emit`s (or a HUD button `action`) fires `{ "on": "event", "event": "<name>" }` interactions — e.g. `api.emit("win")` → `{ "on": "event", "event": "win", "do": [{ "play": "celebrate" }] }`.
|
|
202
|
+
|
|
203
|
+
## Difficulty ramp
|
|
204
|
+
|
|
205
|
+
```js
|
|
206
|
+
speed = Math.min(maxSpeed, speed + dt * 0.4);
|
|
207
|
+
spawnTimer -= dt;
|
|
208
|
+
if (spawnTimer <= 0) { spawn(); spawnTimer = spawnEvery * (startSpeed / speed); }
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## Game over and best score
|
|
212
|
+
|
|
213
|
+
```js
|
|
214
|
+
function gameOver() {
|
|
215
|
+
api.state.phase = "over";
|
|
216
|
+
api.audio.play("hit");
|
|
217
|
+
api.camera.shake(0.3, 0.4);
|
|
218
|
+
const best = Math.max(Number(api.state.best), Number(api.state.score));
|
|
219
|
+
api.state.best = best;
|
|
220
|
+
api.storage.set("best", best);
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## Sounds
|
|
225
|
+
|
|
226
|
+
```json
|
|
227
|
+
"audio": { "sounds": { "move": { "preset": "whoosh", "volume": 0.4 }, "hit": { "preset": "lose" }, "point": { "preset": "coin", "volume": 0.5 } }, "music": { "preset": "chiptune-loop", "volume": 0.3 } }
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
Play sounds only in the `play` phase (the attract mode stays silent). Music: `api.audio.music(true)` when the game starts.
|
|
231
|
+
|
|
232
|
+
## Attract mode (so renders and the poster show action)
|
|
233
|
+
|
|
234
|
+
Headless renders have no input. During `ready`, run a simple autopilot so the scene moves behind the title:
|
|
235
|
+
|
|
236
|
+
```js
|
|
237
|
+
function autopilot() {
|
|
238
|
+
const threat = blocks.find((b) => b.position.z > -8 && b.position.z < player.position.z && Math.abs(b.position.x - lanes[lane]) < 0.5);
|
|
239
|
+
if (!threat) return 0;
|
|
240
|
+
if (lane === 0) return 1;
|
|
241
|
+
if (lane === 2) return -1;
|
|
242
|
+
return api.random() < 0.5 ? -1 : 1;
|
|
243
|
+
}
|
|
244
|
+
// in update: const move = phase === "play" ? readInput() : autopilot();
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
Set `target.posterTime` to a frame where obstacles are on screen (4 s in the lane runner recipe).
|
|
248
|
+
|
|
249
|
+
## Testing
|
|
250
|
+
|
|
251
|
+
- `render --frames 0,2,4,6 --sheet` and look: obstacles appear, the autopilot dodges, the HUD shows the right phase.
|
|
252
|
+
- `data.issues` / `data.consoleErrors` show script errors (`script-error` with the script path).
|
|
253
|
+
- `render --input '[{"t": 0.5, "key": "ArrowLeft", "hold": 1}]'` plays simulated input while seeking; `data.state` (the script's `api.state` after the last frame) tells whether it worked (score, phase, lives).
|
|
254
|
+
- Timeline-driven phases: render a frame after the marker (`--frames 0,2`) and check `data.state.phase`; a blocked `openUrl` click shows up as an `openUrl` event (`api.on("openUrl", ({ url, blocked }) => …)`).
|
|
255
|
+
- Test touch controls with the same render: `{"t": 0.5, "swipe": "left"}` (→ `api.input.swipe()`), `{"t": 1, "drag": {"from": [-0.5, 0], "to": [0.5, 0], "duration": 0.3}}` (press, pointer moves, release), `{"t": 1, "pointerDown": [0, -0.5]}` … `{"t": 2, "pointerUp": true}` (hold-to-charge, slingshots).
|
|
256
|
+
- A phase that needs input (game over): put `"startPhase": "over"` in `scene.data`, call `reset(api.data.startPhase ?? "ready")` in `start`, render, then remove it.
|
|
257
|
+
- Show values you want to verify in a temporary HUD text (`"text": "speed {speed}"`) and read them on the render.
|
|
258
|
+
- Deterministic: same seed, same frames. If two renders of the same time differ, something uses `Math.random()` or wall-clock time.
|
|
259
|
+
|
|
260
|
+
## Interactive (non-game) logic
|
|
261
|
+
|
|
262
|
+
The same API drives configurators and playful banners: change a product colour from HUD buttons (`onEvent("red") → api.get("bottle").setColor("#d62828")`), count clicks on an object (`api.input.pointerWorld()?.objectId`), reveal a coupon after three taps. Keep `target.kind` as the page placement (banner, card…) rather than `game` when it is not a game.
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
# ScriptApi reference
|
|
2
|
+
|
|
3
|
+
The contract is `ScriptApi` in `src/runtime/api.ts`. A script is an ES module listed in `scene.scripts` (`"scripts/game.js"`, project-relative) whose **default export** is a factory:
|
|
4
|
+
|
|
5
|
+
```js
|
|
6
|
+
export default function (api) {
|
|
7
|
+
return {
|
|
8
|
+
start() {}, // once, after every object is built (may be async)
|
|
9
|
+
update(dt, t) {}, // every fixed step: dt = step (s), t = scene time (s)
|
|
10
|
+
onEvent(name, payload) {},// HUD button actions and api.emit()
|
|
11
|
+
dispose() {}, // scene removed
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Several scripts can run side by side; they share `api.state` and events.
|
|
17
|
+
|
|
18
|
+
## Scene graph
|
|
19
|
+
|
|
20
|
+
| Member | Description |
|
|
21
|
+
|---|---|
|
|
22
|
+
| `api.get(id)` | A `ScriptObject` for an object id (top level or nested), or `null` |
|
|
23
|
+
| `api.findByTag(tag)` | Objects whose `tags` contain `tag` |
|
|
24
|
+
| `api.spawn(objectDef, parentId?)` | Build a new object from a full definition (same shape as in `scene.json`); returns a Promise of the `ScriptObject`. Use for one-off objects |
|
|
25
|
+
| `api.clone(id, { id?, position? })` | Synchronous, cheap copy of an existing object (new id generated unless given). Use for anything spawned repeatedly |
|
|
26
|
+
| `api.camera` | The camera as a `ScriptObject` plus `lookAt(x, y, z)` and `shake(intensity, duration)` |
|
|
27
|
+
|
|
28
|
+
### ScriptObject
|
|
29
|
+
|
|
30
|
+
| Member | Description |
|
|
31
|
+
|---|---|
|
|
32
|
+
| `id`, `tags`, `userData` | From the definition (`userData` is writable) |
|
|
33
|
+
| `position`, `rotation`, `scale` | `{ x, y, z, set(x, y, z) }`; rotation in **degrees** |
|
|
34
|
+
| `velocity` | `{ x, y, z, set }` for physics bodies |
|
|
35
|
+
| `visible` | Read / write |
|
|
36
|
+
| `setColor(css)`, `setOpacity(0..1)` | Material tweaks |
|
|
37
|
+
| `playAnimation(clip, { loop?, speed?, crossfade? })` | Model clips (name or index) |
|
|
38
|
+
| `distanceTo(other)` | World distance |
|
|
39
|
+
| `remove()` | Delete it (clones and spawned objects) |
|
|
40
|
+
|
|
41
|
+
## Time and randomness
|
|
42
|
+
|
|
43
|
+
`api.time()` (scene time in seconds), `api.random()` (0..1), `api.randomRange(min, max)`. Seeded by `scene.seed`: the same seed and inputs give the same game, which is what makes headless renders reproducible. Never use `Math.random()` or `Date.now()` for gameplay.
|
|
44
|
+
|
|
45
|
+
## Input
|
|
46
|
+
|
|
47
|
+
| Member | Description |
|
|
48
|
+
|---|---|
|
|
49
|
+
| `api.input.isDown(code)` | Key held (`KeyboardEvent.code`: `"ArrowLeft"`, `"Space"`, `"KeyA"`…) |
|
|
50
|
+
| `api.input.pressed(code)` | Key went down during this step |
|
|
51
|
+
| `api.input.pointer` | `{ x, y, down, justPressed }`, normalised −1..1 over the canvas (mouse or touch) |
|
|
52
|
+
| `api.input.swipe()` | `"left" | "right" | "up" | "down" | null` for this step (touch gestures) |
|
|
53
|
+
| `api.input.pointerWorld()` | World point under the pointer on a body (its rendered mesh) or else on the y = 0 plane: `{ x, y, z, objectId? }` or `null` |
|
|
54
|
+
|
|
55
|
+
The embed takes keyboard focus when clicked (games get `tabindex="0"` and `role="application"`).
|
|
56
|
+
|
|
57
|
+
## Physics
|
|
58
|
+
|
|
59
|
+
Real rigid-body physics (cannon-es, fixed step, deterministic): bodies rotate, tumble, stack, roll and sleep. Objects take part when they have a `body`:
|
|
60
|
+
|
|
61
|
+
```json
|
|
62
|
+
"body": { "type": "dynamic", "shape": "sphere", "restitution": 0.7, "friction": 0.3, "mass": 1 }
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
`type`: `static` (walls, ground), `dynamic` (simulated), `kinematic` (moved by your script — set its position every step or give it a velocity — and pushes dynamic bodies), `trigger` (detects overlaps, no response). Shapes (`box`, `sphere`, `cylinder`, `capsule`, `convex`, `trimesh`, `heightfield`, `compound`, `auto`), materials, collision layers, joints (hinge, point, distance, lock, spring) and `physics.debug` wireframes are listed below (recipes: `game-patterns.md` → Physics recipes). Angles and angular velocities are in degrees (/ s), like rotations everywhere.
|
|
66
|
+
|
|
67
|
+
| `physics` field | Meaning |
|
|
68
|
+
|---|---|
|
|
69
|
+
| `gravity` | World gravity, default `[0, -9.81, 0]` (m/s²) |
|
|
70
|
+
| `step` | Fixed simulation step (s), default 1/60 |
|
|
71
|
+
| `substeps` | Solver sub-steps per step (1–8, default 1): stabler tall stacks, less tunnelling |
|
|
72
|
+
| `iterations` | Constraint solver iterations (default 10) |
|
|
73
|
+
| `sleep` | Resting bodies fall asleep (cheap, stable stacks); default `true` |
|
|
74
|
+
| `debug` | Draws collider wireframes on top of the scene (green dynamic, blue static, orange kinematic, magenta trigger, grey sleeping) — use it in `agent3d render` to check colliders |
|
|
75
|
+
| `materials` | Named surfaces `{ friction?, restitution? }` referenced by `body.material` |
|
|
76
|
+
| `contacts` | Per-pair overrides `{ a, b, friction?, restitution? }` between two named materials (otherwise friction = √(f₁·f₂), restitution = max) |
|
|
77
|
+
| `layers` | Collision layer names (bit order, max 16 with `"default"`); layers used by bodies are added automatically |
|
|
78
|
+
| `joints` | Constraints, see below |
|
|
79
|
+
|
|
80
|
+
**Body** (`objects#…body`):
|
|
81
|
+
|
|
82
|
+
| Field | Meaning |
|
|
83
|
+
|---|---|
|
|
84
|
+
| `type` | `dynamic` (simulated), `static` (immovable), `kinematic` (moved by scripts / velocity, pushes dynamic bodies, ignores gravity), `trigger` (detects overlaps, never pushes) |
|
|
85
|
+
| `shape` | `box` (default: the bounding box of the object's **own** geometry — never its child objects — in the object's rotated frame), `sphere`, `cylinder`, `capsule` (Y-up), `convex` (hull of the mesh / model, good for dynamic models), `trimesh` (exact triangles; static / kinematic only — level geometry, models), `heightfield` (terrain generators), `compound` (`shapes`; without `shapes`: one box for the object + one per child object without a body), `auto` (primitive geometry → matching shape, terrain → heightfield, static models / meshes → trimesh, dynamic → convex) |
|
|
86
|
+
| `size`, `radius`, `height` | Override the measured box size / sphere, cylinder, capsule radius / cylinder, capsule height (world units) |
|
|
87
|
+
| `offset` | Collider centre relative to the object origin (default: bounding-box centre) |
|
|
88
|
+
| `shapes` | `compound`: `[{ "shape": "box" \| "sphere" \| "cylinder" \| "capsule", "size"?, "radius"?, "height"?, "offset"?, "rotation"? }]` (offsets from the object origin) |
|
|
89
|
+
| `mass` | kg, default 1 (dynamic only) |
|
|
90
|
+
| `friction`, `restitution`, `material` | Surface: friction (default 0.5), bounciness 0..1 (default 0.2), or a `physics.materials` name |
|
|
91
|
+
| `velocity`, `angularVelocity` | Initial velocity (m/s) and spin (degrees / s) |
|
|
92
|
+
| `linearDamping`, `angularDamping` | 0..1, default 0.01 (air drag) |
|
|
93
|
+
| `gravityScale` | Gravity multiplier (0 = floats) |
|
|
94
|
+
| `fixedRotation` | Never rotates (players driven by velocity) |
|
|
95
|
+
| `character` | Character controller body: fixed rotation, no friction (no wall sticking), never sleeps — drive it with `api.physics.moveCharacter` / `jump` |
|
|
96
|
+
| `sleep` | `false` keeps it always awake |
|
|
97
|
+
| `ccd` | Fast object (bullets, thrown balls): extra sub-steps against tunnelling |
|
|
98
|
+
| `layer`, `collidesWith` | Collision layer name and the layers it collides with (default: all) |
|
|
99
|
+
|
|
100
|
+
Child objects never enlarge a measured collider: a child with its own `body` gets its own collider; a decorative child (a platform's dirt layer) is ignored unless the parent uses `"shape": "compound"` without `shapes`, which adds one box per such child. No explicit `size` / `offset` is needed for a platform with decorations. A `group` (no geometry of its own) measures its children.
|
|
101
|
+
|
|
102
|
+
Generators that publish collision boxes (the maze generator with `bodies: true`) get a static compound body with the generator's id.
|
|
103
|
+
|
|
104
|
+
**Joints** (`physics.joints[]`, pivots and axes in world space at scene start; omit `b` to attach `a` to the world):
|
|
105
|
+
|
|
106
|
+
| `type` | Fields |
|
|
107
|
+
|---|---|
|
|
108
|
+
| `hinge` | `pivot`, `axis` (default `[0, 1, 0]`), `motor: { speed (degrees / s), maxForce? }`, `limits: [minDeg, maxDeg]` (relative to the start pose) — doors, wheels, flippers |
|
|
109
|
+
| `point` | `pivot` — ball-and-socket: pendulums, chains, ragdoll joints |
|
|
110
|
+
| `distance` | `distance` (default: current distance between the centres) — rigid rods |
|
|
111
|
+
| `lock` | — welds two bodies together (breakable with `maxForce`) |
|
|
112
|
+
| `spring` | `restLength` (default: current distance), `stiffness` (default 50), `damping` (default 1), `pivot` = world anchor on `b` (or the world point when `b` is omitted) |
|
|
113
|
+
|
|
114
|
+
All joints take `maxForce` (default 1e6) and `collideConnected` (default `false`).
|
|
115
|
+
|
|
116
|
+
Moving a body from a script (`obj.position.set`, `obj.rotation.set`) teleports it (dynamic bodies keep their velocity; kinematic bodies sweep to the new pose so they push what they touch). A character keeps its contacts and `grounded()` state through small corrections (under 0.5 m: clamping z every step, snapping to a lane), so jumps keep working; a longer teleport (respawn) clears them until the next step. A player whose velocity you set every step should have `"fixedRotation": true` (or `"character": true`), otherwise friction makes it tumble.
|
|
117
|
+
|
|
118
|
+
**Moving platforms carry characters.** A character standing on a `kinematic` body — moved by `position.set` every step or by a velocity, sliding, lifting or turning — rides it: the platform's motion is added for the step, `moveCharacter` steering stays relative to the platform, and `grounded()` / `contacts()` report the platform every step (even while it moves down). Do not carry the hero yourself.
|
|
119
|
+
|
|
120
|
+
| Member | Description |
|
|
121
|
+
|---|---|
|
|
122
|
+
| `api.physics.overlaps(a, b)` | Exact shape overlap right now (ids or objects, any body types, no step needed) |
|
|
123
|
+
| `api.physics.contacts(a)` | Objects touching `a` during the last step (incl. triggers) |
|
|
124
|
+
| `api.physics.raycast(from, dir, maxDistance?, { ignore?, layers?, triggers? }?)` | Nearest hit on the real shapes: `{ objectId, distance, point, normal }` or `null` (triggers are hit unless `triggers: false`) |
|
|
125
|
+
| `api.physics.applyImpulse(obj, [x, y, z], point?)` | Instant velocity change; a world `point` off the centre also spins it |
|
|
126
|
+
| `api.physics.applyForce(obj, [x, y, z], point?)` / `applyTorque(obj, [x, y, z])` | Continuous push for the next step (call every update: thrusters, wind) |
|
|
127
|
+
| `api.physics.setVelocity(obj, v)` / `getVelocity(obj)` | Linear velocity (m/s) — also `obj.velocity.x = …` |
|
|
128
|
+
| `api.physics.setAngularVelocity(obj, deg)` / `getAngularVelocity(obj)` | Spin in degrees / s |
|
|
129
|
+
| `api.physics.grounded(obj)` | Standing on something (a contact pushing up; characters also count ground within a few cm under their feet, so it does not flicker on moving platforms) |
|
|
130
|
+
| `api.physics.moveCharacter(obj, { x, z } \| [x, z], { speed?, acceleration?, airControl? }?)` | Character controller: steer horizontally toward `move × speed` (move length ≤ 1, default speed 5), keeps the vertical velocity, reduced control in the air; turns the body into a character (no rotation, no friction). Call once per update |
|
|
131
|
+
| `api.physics.jump(obj, speed?)` | Jumps (default 6 m/s) when grounded or within 0.12 s of leaving the ground (coyote time); no double jump; returns `true` when it jumped |
|
|
132
|
+
| `api.physics.wake(obj)` | Wake a sleeping body |
|
|
133
|
+
| `api.physics.setMotorSpeed(jointId, deg)` | Hinge motor speed of a `physics.joints` entry |
|
|
134
|
+
| `api.physics.onCollision((a, b, info) => {})` | Contact began (also for triggers); `info = { point, normal (a → b), impulse (N·s), speed (m/s) }` — e.g. play a sound when `info.impulse > 1` (register it in `start`) |
|
|
135
|
+
| `api.physics.onCollisionEnd((a, b) => {})` | Contact ended |
|
|
136
|
+
| `api.physics.onTriggerEnter((trigger, other) => {})` / `onTriggerExit(...)` | Something entered / left a trigger body |
|
|
137
|
+
|
|
138
|
+
Platformer sketch:
|
|
139
|
+
|
|
140
|
+
```js
|
|
141
|
+
export default function (api) {
|
|
142
|
+
const hero = api.get("hero"); // body: { "type": "dynamic", "shape": "capsule", "character": true }
|
|
143
|
+
return {
|
|
144
|
+
update() {
|
|
145
|
+
const x = (api.input.isDown("ArrowRight") ? 1 : 0) - (api.input.isDown("ArrowLeft") ? 1 : 0);
|
|
146
|
+
api.physics.moveCharacter(hero, { x, z: 0 }, { speed: 6 }); // relative to a lift it stands on
|
|
147
|
+
hero.position.set(hero.position.x, hero.position.y, 0); // stay on the z = 0 plane (keeps grounded state)
|
|
148
|
+
if (api.input.pressed("Space") && api.physics.jump(hero, 7)) api.audio.play("jump");
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## HUD
|
|
155
|
+
|
|
156
|
+
Declared in `scene.ui.elements` (`type` text, button or bar; `anchor` top-left … bottom-right; `style` plain, pill (one line), title, subtitle, panel — a backdrop card, `\n` breaks lines, the first line is a heading). Text placeholders `{key}` read `api.state.key`; `visible` takes a boolean, a state key or an expression (`"phase == 'over'"`, `"lives > 0 && !paused"`); placeholders and expressions also read `timeline.time`, `timeline.progress`, `timeline.segment` and `timeline.marker` (a script's own `state.timeline` wins). A bar's `value` names a state key holding 0..1; a button's `action` is the event name sent to `onEvent`. Theme: `scene.ui.color` / `accent` / `font` (system font stacks only) / `buttonText` (default: white or near-black, whichever contrasts with the accent), and per element `color` / `background` (a bar's `color` is its fill). Patch an element by id: `ui.elements#retry.text`. Headless tests click a button with the `--input` event `{ "t": 3, "ui": "retry" }`; posters and videos never include the HUD.
|
|
157
|
+
|
|
158
|
+
| Member | Description |
|
|
159
|
+
|---|---|
|
|
160
|
+
| `api.state` | Shared state object (HUD, tests). Write plain values |
|
|
161
|
+
| `api.ui.set(id, { text?, visible?, value? })` | Override an element directly |
|
|
162
|
+
| `api.ui.toast(text, seconds?)` | Short message in the middle |
|
|
163
|
+
|
|
164
|
+
## Audio, events, storage, misc
|
|
165
|
+
|
|
166
|
+
| Member | Description |
|
|
167
|
+
|---|---|
|
|
168
|
+
| `api.audio.play(name)` | A sound from `scene.audio.sounds` (`{ "preset": "coin" }` synthesised, or `{ "src": "assets/audio/x.mp3" }`) |
|
|
169
|
+
| `api.audio.music(on)` | Start / stop `scene.audio.music` |
|
|
170
|
+
| `api.on(event, handler)`, `api.emit(event, payload?)` | Custom events between scripts (HUD buttons emit their `action`); also delivered to every script's `onEvent(name, payload)` |
|
|
171
|
+
| `api.storage.get(key)`, `api.storage.set(key, value)` | Small persistent values (best score), namespaced per scene, never throws |
|
|
172
|
+
| `api.data` | `scene.data` (tuning, levels), merged with the page's `data-*` attributes / `element.setData()` overrides |
|
|
173
|
+
| `api.restart()` | Rebuild the scene from its definition |
|
|
174
|
+
| `api.log(...args)` | Debug output (browser console) |
|
|
175
|
+
|
|
176
|
+
Audio only starts after a user gesture; the HUD shows a mute button bottom-right when the scene has sounds.
|
|
177
|
+
|
|
178
|
+
## Events in and out
|
|
179
|
+
|
|
180
|
+
| Source | Reaches scripts as |
|
|
181
|
+
|---|---|
|
|
182
|
+
| HUD button `action` | `onEvent(action)` / `api.on(action)` |
|
|
183
|
+
| Timeline marker crossed (`timeline.markers: { "peak": 1 }`) | `api.on("peak", (p) => …)` / `onEvent("peak", { marker, time })` |
|
|
184
|
+
| Interaction action `{ "emit": "name", "payload"? }` | `api.on("name")` / `onEvent` |
|
|
185
|
+
| The page: `document.querySelector("agent3d-scene").trigger("start", { level: 2 })` | `api.on("start")` / `onEvent("start", { level: 2 })` |
|
|
186
|
+
| A blocked `openUrl` in headless renders | `api.on("openUrl", ({ url, blocked }) => …)` |
|
|
187
|
+
|
|
188
|
+
Out: every `api.emit(name, payload)` and HUD action is re-dispatched on the element as an `agent3d:event` DOM event (`detail: { name, payload }`), e.g. `api.emit("score", { score: 12 })` for the page's analytics. Script-emitted events and HUD actions also fire the scene's `{ "on": "event", "event": "<name>" }` interactions (like markers, interaction `emit` actions and page `trigger()` calls): to play a timeline segment from a script, `api.emit("win")` with `{ "on": "event", "event": "win", "do": [{ "play": "celebrate" }] }` in `scene.interactions`.
|
|
189
|
+
|
|
190
|
+
Example — a timeline marker starts the round, the page learns the score:
|
|
191
|
+
|
|
192
|
+
```js
|
|
193
|
+
export default function (api) {
|
|
194
|
+
return {
|
|
195
|
+
start() {
|
|
196
|
+
api.state.phase = "intro";
|
|
197
|
+
api.on("go", () => { api.state.phase = "play"; }); // timeline.markers: { "go": 1.5 }
|
|
198
|
+
},
|
|
199
|
+
onEvent(name) {
|
|
200
|
+
if (name === "retry") { api.state.score = 0; api.state.phase = "play"; }
|
|
201
|
+
},
|
|
202
|
+
update() {
|
|
203
|
+
if (api.state.phase === "play" && api.input.pressed("Space")) {
|
|
204
|
+
api.state.score = Number(api.state.score ?? 0) + 1;
|
|
205
|
+
api.emit("score", { score: api.state.score }); // page: agent3d:event
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
```
|
|
211
|
+
|