@fleox/agent3d 0.0.0-stage → 0.2.1
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 +396 -2
- package/changelog.json +68 -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-Bdtm4fBN.mjs +178 -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-Dz9PFxi9.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-BOIyp_2B.mjs +75 -0
- package/dist/agent/chunks/png-DXfSGJZt.mjs +91 -0
- package/dist/agent/chunks/render-CN4mgGLQ.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-XmME4f7Z.js +1 -0
- package/dist/runtime/chunks/EXRLoader-CBdIpBMT.js +1 -0
- package/dist/runtime/chunks/FontLoader-dVu9WH2X.js +2 -0
- package/dist/runtime/chunks/GLTFLoader-Z9Inv-Xm.js +1 -0
- package/dist/runtime/chunks/GroundedSkybox-g1ASZWNu.js +1 -0
- package/dist/runtime/chunks/HDRLoader-DBOMWa7O.js +5 -0
- package/dist/runtime/chunks/OrbitControls-BIpWXK4x.js +1 -0
- package/dist/runtime/chunks/RectAreaLightUniformsLib-4ZzgX9vp.js +1 -0
- package/dist/runtime/chunks/RoomEnvironment-CXgfLJdO.js +1 -0
- package/dist/runtime/chunks/RoundedBoxGeometry-BViRogcJ.js +1 -0
- package/dist/runtime/chunks/SVGLoader-CV0U1EIF.js +1 -0
- package/dist/runtime/chunks/SkeletonUtils-DHlReJx3.js +1 -0
- package/dist/runtime/chunks/Sky-DGJXlPb_.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-D6WnITQq.js +1 -0
- package/dist/runtime/chunks/game-BoEiyZrL.js +20 -0
- package/dist/runtime/chunks/generators-D5JUo0jp.js +331 -0
- package/dist/runtime/chunks/materials-Dn-bYrZd.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-BCVF3QzB.js +1 -0
- package/dist/runtime/chunks/params-C2uoUDJ0.js +1 -0
- package/dist/runtime/chunks/physicsHost-ChPgysMQ.js +1 -0
- package/dist/runtime/chunks/postfx-UgKCbmZs.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-Dw6zHdu_.js +443 -0
- package/dist/runtime/chunks/svg-CmlFY_8O.js +1 -0
- package/dist/runtime/chunks/text-D1EQpdSU.js +2 -0
- package/dist/runtime/chunks/three.module-DnaBiDAJ.js +4225 -0
- package/dist/runtime/chunks/toon-BsvVk_nK.js +6 -0
- package/dist/runtime/chunks/util-CyaW1fcW.js +1 -0
- package/dist/studio/assets/BufferGeometryUtils-CAlXAboW.js +1 -0
- package/dist/studio/assets/EXRLoader-BKkzlNd8.js +1 -0
- package/dist/studio/assets/FontLoader-Bzjx8mXt.js +2 -0
- package/dist/studio/assets/GLTFLoader-1Zd9N406.js +1 -0
- package/dist/studio/assets/GroundedSkybox-BEMqNCBD.js +1 -0
- package/dist/studio/assets/HDRLoader-DxB0kxPH.js +5 -0
- package/dist/studio/assets/OrbitControls-MlE9XiCg.js +1 -0
- package/dist/studio/assets/RectAreaLightUniformsLib-ClHrtYY6.js +1 -0
- package/dist/studio/assets/RoomEnvironment-MJ-jIEC8.js +1 -0
- package/dist/studio/assets/SVGLoader-CIYl0nEy.js +1 -0
- package/dist/studio/assets/SkeletonUtils-CG5akqME.js +1 -0
- package/dist/studio/assets/Sky-DNMfpp92.js +243 -0
- package/dist/studio/assets/audio-JD1kyX0A.js +1 -0
- package/dist/studio/assets/camera-7sEn13L-.js +2 -0
- package/dist/studio/assets/editor-CnbvVkhU.js +53 -0
- package/dist/studio/assets/extrude-9bG8hr2C.js +1 -0
- package/dist/studio/assets/game-B04KGAK0.js +19 -0
- package/dist/studio/assets/generators-LSni1Yfc.js +331 -0
- package/dist/studio/assets/index-3LL5NEIH.js +479 -0
- package/dist/studio/assets/index-BQT0otii.css +1 -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-CNddhwmA.js +2 -0
- package/dist/studio/assets/physicsHost-hMU_SDiX.js +1 -0
- package/dist/studio/assets/postfx-BcCZS0Bq.js +1527 -0
- package/dist/studio/assets/runtime-DY_KqD1x.js +572 -0
- package/dist/studio/assets/shaders-BhMCstyv.js +443 -0
- package/dist/studio/assets/svg-CNKK-h7H.js +2 -0
- package/dist/studio/assets/text-BSPI7dk1.js +3 -0
- package/dist/studio/assets/three.module-CnI50X0U.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,1511 @@
|
|
|
1
|
+
import { createRequire as __a3dRequire } from "node:module";
|
|
2
|
+
import { fileURLToPath as __a3dPath } from "node:url";
|
|
3
|
+
import { dirname as __a3dDirname, isAbsolute, join, relative, resolve } from "node:path";
|
|
4
|
+
__a3dRequire(import.meta.url);
|
|
5
|
+
const __filename = __a3dPath(import.meta.url);
|
|
6
|
+
__a3dDirname(__filename);
|
|
7
|
+
import { t as closest } from "./suggest-Cpcgv1RP.mjs";
|
|
8
|
+
import { n as findObject, o as walkObjects } from "./tree-BrNYGui2.mjs";
|
|
9
|
+
import { I as libraryDir, L as runtimeBuilt, R as runtimeDir, n as startLocalServer, t as sendText, z as CliError } from "../agent3d.mjs";
|
|
10
|
+
import { launchBrowser, requireBrowser } from "./browser-t_JL_B82.mjs";
|
|
11
|
+
import { t as CdpClient } from "./cdp-Bdtm4fBN.mjs";
|
|
12
|
+
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
13
|
+
// agent/render/preview.ts
|
|
14
|
+
var RUNTIME_URL = "/__runtime/agent3d-runtime.js";
|
|
15
|
+
function previewHtml(opts = {}) {
|
|
16
|
+
const pr = opts.pixelRatio ?? 1;
|
|
17
|
+
return `<!doctype html>
|
|
18
|
+
<html lang="en">
|
|
19
|
+
<head>
|
|
20
|
+
<meta charset="utf-8">
|
|
21
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
22
|
+
<title>Agent3D render</title>
|
|
23
|
+
<style>html,body{margin:0;padding:0;overflow:hidden;background:${opts.transparent ? "transparent" : "#000"}}#stage{position:fixed;inset:0;width:100vw;height:100vh}</style>
|
|
24
|
+
</head>
|
|
25
|
+
<body>
|
|
26
|
+
<div id="stage"></div>
|
|
27
|
+
<script type="module">
|
|
28
|
+
const handle = { player: null, issues: [], ready: false, error: null, webgl: false };
|
|
29
|
+
window.__agent3d = handle;
|
|
30
|
+
try {
|
|
31
|
+
const c = document.createElement("canvas");
|
|
32
|
+
handle.webgl = !!(c.getContext("webgl2") || c.getContext("webgl"));
|
|
33
|
+
} catch (e) { handle.webgl = false; }
|
|
34
|
+
|
|
35
|
+
const loadImage = (src) => new Promise((resolve, reject) => { const img = new Image(); img.onload = () => resolve(img); img.onerror = () => reject(new Error("image decode failed")); img.src = src; });
|
|
36
|
+
|
|
37
|
+
window.__agent3dFrame = async (t, type, quality) => {
|
|
38
|
+
const p = handle.player;
|
|
39
|
+
if (!p) throw new Error("player not mounted");
|
|
40
|
+
await p.seek(t);
|
|
41
|
+
return p.snapshot(type || "image/png", quality);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// Background under transparent frames: "checker" (grey / white squares) or a CSS colour.
|
|
45
|
+
const paintBg = (g, x, y, w, h, bg) => {
|
|
46
|
+
if (!bg) return;
|
|
47
|
+
if (bg !== "checker") { g.fillStyle = bg; g.fillRect(x, y, w, h); return; }
|
|
48
|
+
const s = Math.max(8, Math.round(Math.min(w, h) / 32));
|
|
49
|
+
g.fillStyle = "#ffffff"; g.fillRect(x, y, w, h);
|
|
50
|
+
g.fillStyle = "#d9d9de";
|
|
51
|
+
for (let j = 0; j * s < h; j++) for (let i = j % 2; i * s < w; i += 2) g.fillRect(x + i * s, y + j * s, Math.min(s, w - i * s), Math.min(s, h - j * s));
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
window.__agent3dComposite = async (url, bg) => {
|
|
55
|
+
const img = await loadImage(url);
|
|
56
|
+
const cv = document.createElement("canvas");
|
|
57
|
+
cv.width = img.naturalWidth; cv.height = img.naturalHeight;
|
|
58
|
+
const g = cv.getContext("2d");
|
|
59
|
+
paintBg(g, 0, 0, cv.width, cv.height, bg);
|
|
60
|
+
g.drawImage(img, 0, 0);
|
|
61
|
+
return cv.toDataURL("image/png");
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
window.__agent3dSheet = async (urls, labels, cols, bg) => {
|
|
65
|
+
const imgs = await Promise.all(urls.map(loadImage));
|
|
66
|
+
const n = imgs.length;
|
|
67
|
+
const w0 = imgs[0].naturalWidth, h0 = imgs[0].naturalHeight;
|
|
68
|
+
const aspect = w0 / h0;
|
|
69
|
+
cols = Math.max(1, Math.min(n, cols || Math.round(Math.sqrt(n / aspect)) || 1));
|
|
70
|
+
const rows = Math.ceil(n / cols);
|
|
71
|
+
const cellW = Math.min(w0, Math.floor(2400 / cols));
|
|
72
|
+
const cellH = Math.round(cellW / aspect);
|
|
73
|
+
const gap = 8;
|
|
74
|
+
const cv = document.createElement("canvas");
|
|
75
|
+
cv.width = cols * cellW + (cols + 1) * gap;
|
|
76
|
+
cv.height = rows * cellH + (rows + 1) * gap;
|
|
77
|
+
const g = cv.getContext("2d");
|
|
78
|
+
g.fillStyle = "#1b1b1f"; g.fillRect(0, 0, cv.width, cv.height);
|
|
79
|
+
// Small, semi-transparent time label in the bottom-left corner: the top
|
|
80
|
+
// corners are where HUDs (score, lives) usually sit.
|
|
81
|
+
const fs = Math.max(10, Math.round(Math.min(cellH, cellW * 0.6) / 24));
|
|
82
|
+
g.font = "600 " + fs + "px system-ui, -apple-system, Segoe UI, sans-serif";
|
|
83
|
+
g.textBaseline = "middle";
|
|
84
|
+
imgs.forEach((img, i) => {
|
|
85
|
+
const x = gap + (i % cols) * (cellW + gap), y = gap + Math.floor(i / cols) * (cellH + gap);
|
|
86
|
+
paintBg(g, x, y, cellW, cellH, bg);
|
|
87
|
+
g.drawImage(img, x, y, cellW, cellH);
|
|
88
|
+
const label = labels[i] || "";
|
|
89
|
+
if (label) {
|
|
90
|
+
const tw = g.measureText(label).width;
|
|
91
|
+
const pad = Math.round(fs * 0.45), bh = Math.round(fs * 1.5), m = Math.round(fs * 0.4);
|
|
92
|
+
const bx = x + m, by = y + cellH - m - bh;
|
|
93
|
+
g.fillStyle = "rgba(0,0,0,0.42)"; g.fillRect(bx, by, tw + pad * 2, bh);
|
|
94
|
+
g.fillStyle = "rgba(255,255,255,0.85)"; g.fillText(label, bx + pad, by + bh / 2);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
return cv.toDataURL("image/png");
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
// ─── Supersampled capture ───
|
|
101
|
+
let grabCanvas = null;
|
|
102
|
+
const sourceFor = (ss, bg) => {
|
|
103
|
+
const p = handle.player;
|
|
104
|
+
const src = p.canvas;
|
|
105
|
+
if ((!ss || ss <= 1) && !bg) return src;
|
|
106
|
+
const w = Math.max(1, Math.round(src.width / (ss || 1))), h = Math.max(1, Math.round(src.height / (ss || 1)));
|
|
107
|
+
if (!grabCanvas) grabCanvas = document.createElement("canvas");
|
|
108
|
+
let from = src, fw = src.width, fh = src.height;
|
|
109
|
+
// Halve in steps (box filter) down to the target size: clean supersampling.
|
|
110
|
+
while (fw / 2 >= w * 1.5) {
|
|
111
|
+
const tmp = document.createElement("canvas");
|
|
112
|
+
tmp.width = Math.round(fw / 2); tmp.height = Math.round(fh / 2);
|
|
113
|
+
const tg = tmp.getContext("2d"); tg.imageSmoothingEnabled = true; tg.imageSmoothingQuality = "high";
|
|
114
|
+
tg.drawImage(from, 0, 0, tmp.width, tmp.height);
|
|
115
|
+
from = tmp; fw = tmp.width; fh = tmp.height;
|
|
116
|
+
}
|
|
117
|
+
grabCanvas.width = w; grabCanvas.height = h;
|
|
118
|
+
const g = grabCanvas.getContext("2d");
|
|
119
|
+
g.clearRect(0, 0, w, h);
|
|
120
|
+
if (bg) paintBg(g, 0, 0, w, h, bg);
|
|
121
|
+
g.imageSmoothingEnabled = true; g.imageSmoothingQuality = "high";
|
|
122
|
+
g.drawImage(from, 0, 0, w, h);
|
|
123
|
+
return grabCanvas;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const toB64 = (buf) => {
|
|
127
|
+
let out = "";
|
|
128
|
+
for (let i = 0; i < buf.length; i += 0x8000) out += String.fromCharCode.apply(null, buf.subarray(i, i + 0x8000));
|
|
129
|
+
return btoa(out);
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
window.__agent3dGrab = async (t, o) => {
|
|
133
|
+
o = o || {};
|
|
134
|
+
const p = handle.player;
|
|
135
|
+
if (!p) throw new Error("player not mounted");
|
|
136
|
+
await p.seek(t);
|
|
137
|
+
// seek() rendered the frame (deterministic players preserve the drawing buffer).
|
|
138
|
+
if (typeof p.renderHighQuality === "function" && o.hq) { try { await p.renderHighQuality(); } catch (e) {} }
|
|
139
|
+
const c = sourceFor(o.ss, o.bg);
|
|
140
|
+
if (o.raw) {
|
|
141
|
+
let g2 = c.getContext && c === grabCanvas ? grabCanvas.getContext("2d") : null;
|
|
142
|
+
if (!g2) { const tmp = document.createElement("canvas"); tmp.width = c.width; tmp.height = c.height; g2 = tmp.getContext("2d"); g2.drawImage(c, 0, 0); }
|
|
143
|
+
const d = g2.getImageData(0, 0, c.width, c.height);
|
|
144
|
+
return { width: c.width, height: c.height, rgba: toB64(new Uint8Array(d.data.buffer)) };
|
|
145
|
+
}
|
|
146
|
+
return c.toDataURL(o.type || "image/png", o.quality);
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
window.__agent3dSocial = async (url, w, h) => {
|
|
150
|
+
const img = await loadImage(url);
|
|
151
|
+
const cv = document.createElement("canvas"); cv.width = w; cv.height = h;
|
|
152
|
+
const g = cv.getContext("2d");
|
|
153
|
+
const iw = img.naturalWidth, ih = img.naturalHeight;
|
|
154
|
+
const cover = Math.max(w / iw, h / ih), contain = Math.min(w / iw, h / ih);
|
|
155
|
+
g.filter = "blur(" + Math.round(Math.min(w, h) / 18) + "px) brightness(0.8) saturate(1.1)";
|
|
156
|
+
g.drawImage(img, (w - iw * cover) / 2 - 20, (h - ih * cover) / 2 - 20, iw * cover + 40, ih * cover + 40);
|
|
157
|
+
g.filter = "none";
|
|
158
|
+
g.imageSmoothingQuality = "high";
|
|
159
|
+
g.shadowColor = "rgba(0,0,0,0.35)"; g.shadowBlur = Math.round(h / 30);
|
|
160
|
+
g.drawImage(img, (w - iw * contain) / 2, (h - ih * contain) / 2, iw * contain, ih * contain);
|
|
161
|
+
return cv.toDataURL("image/png");
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
// ─── Frame-exact video (WebCodecs) ───
|
|
165
|
+
let video = null;
|
|
166
|
+
window.__agent3dVideoSupport = async (codecs, w, h, fps) => {
|
|
167
|
+
if (typeof VideoEncoder === "undefined") return null;
|
|
168
|
+
for (const codec of codecs) {
|
|
169
|
+
try {
|
|
170
|
+
const r = await VideoEncoder.isConfigSupported({ codec, width: w, height: h, framerate: fps, bitrate: 4e6, ...(codec.startsWith("avc1") ? { avc: { format: "avc" } } : {}) });
|
|
171
|
+
if (r.supported) return codec;
|
|
172
|
+
} catch (e) {}
|
|
173
|
+
}
|
|
174
|
+
return null;
|
|
175
|
+
};
|
|
176
|
+
window.__agent3dVideoStart = async (cfg) => {
|
|
177
|
+
const chunks = [];
|
|
178
|
+
let description = null, error = null;
|
|
179
|
+
const encoder = new VideoEncoder({
|
|
180
|
+
output: (chunk, meta) => {
|
|
181
|
+
const b = new Uint8Array(chunk.byteLength); chunk.copyTo(b);
|
|
182
|
+
chunks.push({ b64: toB64(b), key: chunk.type === "key" });
|
|
183
|
+
if (meta && meta.decoderConfig && meta.decoderConfig.description && !description) description = toB64(new Uint8Array(meta.decoderConfig.description instanceof ArrayBuffer ? meta.decoderConfig.description : meta.decoderConfig.description.buffer));
|
|
184
|
+
},
|
|
185
|
+
error: (e) => { error = String(e); },
|
|
186
|
+
});
|
|
187
|
+
encoder.configure({ codec: cfg.codec, width: cfg.width, height: cfg.height, framerate: cfg.fps, bitrate: cfg.bitrate, bitrateMode: "variable", latencyMode: "quality", ...(cfg.codec.startsWith("avc1") ? { avc: { format: "avc" } } : {}) });
|
|
188
|
+
video = { encoder, chunks, cfg, get description() { return description; }, get error() { return error; } };
|
|
189
|
+
return true;
|
|
190
|
+
};
|
|
191
|
+
window.__agent3dVideoFrame = async (t, i) => {
|
|
192
|
+
const v = video;
|
|
193
|
+
if (v.error) throw new Error(v.error);
|
|
194
|
+
await handle.player.seek(t);
|
|
195
|
+
const src = sourceFor(v.cfg.ss, v.cfg.bg);
|
|
196
|
+
const frame = new VideoFrame(src, { timestamp: Math.round((i * 1e6) / v.cfg.fps), duration: Math.round(1e6 / v.cfg.fps) });
|
|
197
|
+
v.encoder.encode(frame, { keyFrame: i % v.cfg.keyInterval === 0 });
|
|
198
|
+
frame.close();
|
|
199
|
+
while (v.encoder.encodeQueueSize > 4) await new Promise((r) => setTimeout(r, 5));
|
|
200
|
+
return true;
|
|
201
|
+
};
|
|
202
|
+
window.__agent3dVideoDrain = () => { const out = video.chunks.splice(0); return out; };
|
|
203
|
+
window.__agent3dVideoEnd = async () => {
|
|
204
|
+
await video.encoder.flush();
|
|
205
|
+
const out = { chunks: video.chunks.splice(0), description: video.description, error: video.error };
|
|
206
|
+
video.encoder.close();
|
|
207
|
+
video = null;
|
|
208
|
+
return out;
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
// Click a HUD button (scene.ui element of type "button") by id: false when it is missing or hidden.
|
|
212
|
+
window.__agent3dUi = (id) => {
|
|
213
|
+
const b = Array.from(document.querySelectorAll(".a3d-hud [data-id]")).find((el) => el.dataset.id === id);
|
|
214
|
+
if (!b || !b.getClientRects().length) return false;
|
|
215
|
+
b.click();
|
|
216
|
+
return true;
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
window.__agent3dInfo = () => {
|
|
220
|
+
const p = handle.player;
|
|
221
|
+
const safe = (f) => { try { return f(); } catch (e) { return null; } };
|
|
222
|
+
return { stats: p ? safe(() => p.stats()) : null, inspect: p ? safe(() => p.inspect()) : null, issues: handle.issues, state: p ? safe(() => p.state()) : null };
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
window.__agent3dRender = async (times, sheet, cols) => {
|
|
226
|
+
const frames = [];
|
|
227
|
+
for (const t of times) frames.push(await window.__agent3dFrame(t));
|
|
228
|
+
const out = { frames, ...window.__agent3dInfo() };
|
|
229
|
+
if (sheet && frames.length) out.sheet = await window.__agent3dSheet(frames, times.map((t) => "t = " + (+t).toFixed(2) + " s"), cols);
|
|
230
|
+
return out;
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
try {
|
|
234
|
+
const mod = await import(${JSON.stringify(RUNTIME_URL)});
|
|
235
|
+
const res = await fetch("/__scene.json", { cache: "no-store" });
|
|
236
|
+
if (!res.ok) throw new Error("scene.json: HTTP " + res.status);
|
|
237
|
+
const scene = await res.json();
|
|
238
|
+
const player = mod.mountScene(document.getElementById("stage"), scene, {
|
|
239
|
+
deterministic: true,
|
|
240
|
+
assetBase: "/project/",
|
|
241
|
+
libraryBase: "/__library/",
|
|
242
|
+
pixelRatio: ${JSON.stringify(pr)},
|
|
243
|
+
reducedMotion: ${opts.reducedMotion ? "true" : "false"},
|
|
244
|
+
onError: (issue) => handle.issues.push(issue),
|
|
245
|
+
});
|
|
246
|
+
handle.player = player;
|
|
247
|
+
await player.ready;
|
|
248
|
+
handle.ready = true;
|
|
249
|
+
} catch (e) {
|
|
250
|
+
handle.error = String((e && e.stack) || e);
|
|
251
|
+
}
|
|
252
|
+
<\/script>
|
|
253
|
+
</body>
|
|
254
|
+
</html>
|
|
255
|
+
`;
|
|
256
|
+
}
|
|
257
|
+
// agent/render/webm.ts
|
|
258
|
+
var enc = new TextEncoder();
|
|
259
|
+
function vintSize(n) {
|
|
260
|
+
const out = /* @__PURE__ */ new Uint8Array(8);
|
|
261
|
+
out[0] = 1;
|
|
262
|
+
let v = n;
|
|
263
|
+
for (let i = 7; i >= 1; i--) {
|
|
264
|
+
out[i] = v % 256;
|
|
265
|
+
v = Math.floor(v / 256);
|
|
266
|
+
}
|
|
267
|
+
return out;
|
|
268
|
+
}
|
|
269
|
+
function idBytes(id) {
|
|
270
|
+
const bytes = [];
|
|
271
|
+
let v = id;
|
|
272
|
+
while (v > 0) {
|
|
273
|
+
bytes.unshift(v & 255);
|
|
274
|
+
v = Math.floor(v / 256);
|
|
275
|
+
}
|
|
276
|
+
return new Uint8Array(bytes);
|
|
277
|
+
}
|
|
278
|
+
function uintBytes(n) {
|
|
279
|
+
const bytes = [];
|
|
280
|
+
let v = Math.floor(n);
|
|
281
|
+
do {
|
|
282
|
+
bytes.unshift(v & 255);
|
|
283
|
+
v = Math.floor(v / 256);
|
|
284
|
+
} while (v > 0);
|
|
285
|
+
return new Uint8Array(bytes);
|
|
286
|
+
}
|
|
287
|
+
function floatBytes(n) {
|
|
288
|
+
const b = /* @__PURE__ */ new Uint8Array(8);
|
|
289
|
+
new DataView(b.buffer).setFloat64(0, n);
|
|
290
|
+
return b;
|
|
291
|
+
}
|
|
292
|
+
function concat(parts) {
|
|
293
|
+
const total = parts.reduce((a, p) => a + p.byteLength, 0);
|
|
294
|
+
const out = new Uint8Array(total);
|
|
295
|
+
let o = 0;
|
|
296
|
+
for (const p of parts) {
|
|
297
|
+
out.set(p, o);
|
|
298
|
+
o += p.byteLength;
|
|
299
|
+
}
|
|
300
|
+
return out;
|
|
301
|
+
}
|
|
302
|
+
function encodeEl([id, value]) {
|
|
303
|
+
let data;
|
|
304
|
+
if (Array.isArray(value)) data = concat(value.map(encodeEl));
|
|
305
|
+
else if (value instanceof Uint8Array) data = value;
|
|
306
|
+
else if (typeof value === "number") data = uintBytes(value);
|
|
307
|
+
else if (typeof value === "string") data = enc.encode(value);
|
|
308
|
+
else data = floatBytes(value.float);
|
|
309
|
+
return concat([
|
|
310
|
+
idBytes(id),
|
|
311
|
+
vintSize(data.byteLength),
|
|
312
|
+
data
|
|
313
|
+
]);
|
|
314
|
+
}
|
|
315
|
+
function webpToVp8(webp) {
|
|
316
|
+
const dv = new DataView(webp.buffer, webp.byteOffset, webp.byteLength);
|
|
317
|
+
const tag = (o) => String.fromCharCode(webp[o], webp[o + 1], webp[o + 2], webp[o + 3]);
|
|
318
|
+
if (webp.byteLength < 20 || tag(0) !== "RIFF" || tag(8) !== "WEBP") throw new Error("not a WebP image");
|
|
319
|
+
let o = 12;
|
|
320
|
+
while (o + 8 <= webp.byteLength) {
|
|
321
|
+
const t = tag(o);
|
|
322
|
+
const size = dv.getUint32(o + 4, true);
|
|
323
|
+
if (t === "VP8 ") {
|
|
324
|
+
const data = webp.subarray(o + 8, o + 8 + size);
|
|
325
|
+
if (data[3] !== 157 || data[4] !== 1 || data[5] !== 42) throw new Error("WebP VP8 chunk is not a key frame");
|
|
326
|
+
return {
|
|
327
|
+
data,
|
|
328
|
+
width: (data[6] | data[7] << 8) & 16383,
|
|
329
|
+
height: (data[8] | data[9] << 8) & 16383
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
if (t === "VP8L") throw new Error("lossless WebP frame (use a quality below 1)");
|
|
333
|
+
o += 8 + size + (size & 1);
|
|
334
|
+
}
|
|
335
|
+
throw new Error("no VP8 data in the WebP image");
|
|
336
|
+
}
|
|
337
|
+
function muxWebm(frames, fps, opts = {}) {
|
|
338
|
+
const codec = opts.codec ?? "V_VP8";
|
|
339
|
+
if (!frames.length) throw new Error("no frames");
|
|
340
|
+
const { width, height } = frames[0];
|
|
341
|
+
const frameMs = 1e3 / fps;
|
|
342
|
+
const durationMs = frames.length * frameMs;
|
|
343
|
+
const clusters = [];
|
|
344
|
+
const CLUSTER_MS = 5e3;
|
|
345
|
+
let i = 0;
|
|
346
|
+
while (i < frames.length) {
|
|
347
|
+
const start = Math.round(i * frameMs);
|
|
348
|
+
const blocks = [[231, start]];
|
|
349
|
+
let first = true;
|
|
350
|
+
while (i < frames.length && Math.round(i * frameMs) - start < CLUSTER_MS && (first || frames[i].key === false || Math.round(i * frameMs) - start < 2e3)) {
|
|
351
|
+
first = false;
|
|
352
|
+
const rel = Math.round(i * frameMs) - start;
|
|
353
|
+
const header = new Uint8Array([
|
|
354
|
+
129,
|
|
355
|
+
rel >> 8 & 255,
|
|
356
|
+
rel & 255,
|
|
357
|
+
frames[i].key === false ? 0 : 128
|
|
358
|
+
]);
|
|
359
|
+
blocks.push([163, concat([header, frames[i].data])]);
|
|
360
|
+
i++;
|
|
361
|
+
}
|
|
362
|
+
clusters.push([524531317, blocks]);
|
|
363
|
+
}
|
|
364
|
+
const ebml = [440786851, [
|
|
365
|
+
[17030, 1],
|
|
366
|
+
[17143, 1],
|
|
367
|
+
[17138, 4],
|
|
368
|
+
[17139, 8],
|
|
369
|
+
[17026, "webm"],
|
|
370
|
+
[17031, 2],
|
|
371
|
+
[17029, 2]
|
|
372
|
+
]];
|
|
373
|
+
const segment = [408125543, [
|
|
374
|
+
[357149030, [
|
|
375
|
+
[2807729, 1e6],
|
|
376
|
+
[19840, "agent3d"],
|
|
377
|
+
[22337, "agent3d"],
|
|
378
|
+
[17545, { float: durationMs }]
|
|
379
|
+
]],
|
|
380
|
+
[374648427, [[174, [
|
|
381
|
+
[215, 1],
|
|
382
|
+
[29637, 1],
|
|
383
|
+
[156, 0],
|
|
384
|
+
[2274716, "und"],
|
|
385
|
+
[134, codec],
|
|
386
|
+
[2459272, codec === "V_VP9" ? "VP9" : "VP8"],
|
|
387
|
+
[131, 1],
|
|
388
|
+
[2352003, Math.round(1e9 / fps)],
|
|
389
|
+
[224, [[176, width], [186, height]]]
|
|
390
|
+
]]]],
|
|
391
|
+
...clusters
|
|
392
|
+
]];
|
|
393
|
+
return concat([encodeEl(ebml), encodeEl(segment)]);
|
|
394
|
+
}
|
|
395
|
+
// agent/render/render.ts
|
|
396
|
+
function parseAspect(aspect) {
|
|
397
|
+
const m = /^\s*(\d+(?:\.\d+)?)\s*[:/x]\s*(\d+(?:\.\d+)?)\s*$/.exec(aspect ?? "");
|
|
398
|
+
if (!m) return 16 / 9;
|
|
399
|
+
const r = Number(m[1]) / Number(m[2]);
|
|
400
|
+
return Number.isFinite(r) && r > 0 ? r : 16 / 9;
|
|
401
|
+
}
|
|
402
|
+
function viewportFor(scene, opts = {}) {
|
|
403
|
+
const deviceScaleFactor = opts.scale ?? 1;
|
|
404
|
+
if (opts.size) {
|
|
405
|
+
const m = /^(\d+)\s*x\s*(\d+)$/i.exec(opts.size.trim());
|
|
406
|
+
if (!m) throw new CliError("usage", `--size must be WIDTHxHEIGHT (e.g. 1200x300), got "${opts.size}".`, void 0, 2);
|
|
407
|
+
const width = Number(m[1]);
|
|
408
|
+
const height = Number(m[2]);
|
|
409
|
+
if (width < 16 || height < 16 || width > 4096 || height > 4096) throw new CliError("usage", "--size must be between 16 and 4096 pixels per side.", void 0, 2);
|
|
410
|
+
return {
|
|
411
|
+
width,
|
|
412
|
+
height,
|
|
413
|
+
deviceScaleFactor
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
const width = Math.round(opts.width ?? 1200);
|
|
417
|
+
const fixed = /^(\d+)px$/.exec(scene?.target?.height ?? "");
|
|
418
|
+
return {
|
|
419
|
+
width,
|
|
420
|
+
height: fixed ? Number(fixed[1]) : Math.max(16, Math.round(width / parseAspect(scene?.target?.aspect))),
|
|
421
|
+
deviceScaleFactor
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
function frameTimes(scene, opts) {
|
|
425
|
+
if (opts.frames) {
|
|
426
|
+
const ts = opts.frames.split(",").map((s) => Number(s.trim()));
|
|
427
|
+
if (!ts.length || ts.some((t) => !Number.isFinite(t) || t < 0)) throw new CliError("usage", `--frames must be comma-separated times in seconds (e.g. 0,1.5,3), got "${opts.frames}".`, void 0, 2);
|
|
428
|
+
return ts;
|
|
429
|
+
}
|
|
430
|
+
const count = Math.max(1, Math.min(64, Math.round(opts.count ?? 4)));
|
|
431
|
+
if (count === 1) return [scene?.target?.posterTime ?? 0];
|
|
432
|
+
const duration = scene?.timeline?.duration && scene.timeline.duration > 0 ? scene.timeline.duration : 4;
|
|
433
|
+
const step = (scene?.timeline ? !!scene.timeline.loop : true) ? duration / count : duration / (count - 1);
|
|
434
|
+
return Array.from({ length: count }, (_, i) => Math.round(i * step * 1e3) / 1e3);
|
|
435
|
+
}
|
|
436
|
+
var pair = (v) => Array.isArray(v) && v.length === 2 && v.every((n) => typeof n === "number" && Number.isFinite(n));
|
|
437
|
+
var SWIPES = [
|
|
438
|
+
"left",
|
|
439
|
+
"right",
|
|
440
|
+
"up",
|
|
441
|
+
"down"
|
|
442
|
+
];
|
|
443
|
+
var INPUT_SHAPES = "Events: {\"t\": 0.5, \"key\": \"ArrowRight\", \"down\": true} | {\"t\": 0.5, \"key\": \"Space\", \"hold\": 0.3} | {\"t\": 1, \"click\": [0, 0]} | {\"t\": 1, \"pointer\": [0.5, -0.2], \"down\"?: true} | {\"t\": 1, \"pointerDown\": [0, 0]} | {\"t\": 2, \"pointerUp\": [0.4, 0]} | {\"t\": 1, \"drag\": {\"from\": [-0.5, 0], \"to\": [0.5, 0], \"duration\": 0.4}} | {\"t\": 1, \"swipe\": \"left\"|\"right\"|\"up\"|\"down\"} | {\"t\": 1, \"scroll\": 0.5} | {\"t\": 2, \"emit\": \"retry\", \"payload\"?: …} | {\"t\": 2, \"ui\": \"<HUD button id>\"} | {\"t\": 0, \"segment\": \"<timeline segment>\", \"reverse\"?: true} (coordinates -1..1, y up; key = KeyboardEvent.code).";
|
|
444
|
+
var FIELDS = {
|
|
445
|
+
key: [
|
|
446
|
+
"t",
|
|
447
|
+
"key",
|
|
448
|
+
"down",
|
|
449
|
+
"hold"
|
|
450
|
+
],
|
|
451
|
+
click: ["t", "click"],
|
|
452
|
+
pointer: [
|
|
453
|
+
"t",
|
|
454
|
+
"pointer",
|
|
455
|
+
"down"
|
|
456
|
+
],
|
|
457
|
+
pointerDown: ["t", "pointerDown"],
|
|
458
|
+
pointerUp: ["t", "pointerUp"],
|
|
459
|
+
drag: ["t", "drag"],
|
|
460
|
+
swipe: ["t", "swipe"],
|
|
461
|
+
scroll: ["t", "scroll"],
|
|
462
|
+
emit: [
|
|
463
|
+
"t",
|
|
464
|
+
"emit",
|
|
465
|
+
"payload"
|
|
466
|
+
],
|
|
467
|
+
ui: ["t", "ui"],
|
|
468
|
+
segment: [
|
|
469
|
+
"t",
|
|
470
|
+
"segment",
|
|
471
|
+
"reverse"
|
|
472
|
+
]
|
|
473
|
+
};
|
|
474
|
+
function parseInputScript(raw) {
|
|
475
|
+
const bad = (i, why) => new CliError("usage", `--input event #${i}: ${why}.`, INPUT_SHAPES, 2);
|
|
476
|
+
if (!Array.isArray(raw)) throw new CliError("usage", "--input must be a JSON array of events.", `e.g. --input '[{"t": 0.5, "key": "ArrowRight", "hold": 1}]' or --input @inputs.json. ${INPUT_SHAPES}`, 2);
|
|
477
|
+
const out = [];
|
|
478
|
+
raw.forEach((e, i) => {
|
|
479
|
+
if (!e || typeof e !== "object" || Array.isArray(e)) throw bad(i, "not an object");
|
|
480
|
+
const ev = e;
|
|
481
|
+
const t = ev.t;
|
|
482
|
+
if (typeof t !== "number" || !Number.isFinite(t) || t < 0) throw bad(i, "\"t\" must be a time in seconds ≥ 0");
|
|
483
|
+
const kind = Object.keys(FIELDS).find((k) => k in ev);
|
|
484
|
+
if (!kind) throw bad(i, `needs one of ${Object.keys(FIELDS).map((k) => `"${k}"`).join(", ")}`);
|
|
485
|
+
const extra = Object.keys(ev).filter((k) => !FIELDS[kind].includes(k));
|
|
486
|
+
if (extra.length) throw bad(i, `unknown field${extra.length > 1 ? "s" : ""} ${extra.map((k) => `"${k}"`).join(", ")} for a "${kind}" event (allowed: ${FIELDS[kind].join(", ")})`);
|
|
487
|
+
if (kind === "key") {
|
|
488
|
+
if (typeof ev.key !== "string" || !ev.key) throw bad(i, "\"key\" must be a KeyboardEvent.code, e.g. \"ArrowLeft\", \"Space\", \"KeyA\"");
|
|
489
|
+
if (ev.hold !== void 0) {
|
|
490
|
+
if (typeof ev.hold !== "number" || !(ev.hold > 0)) throw bad(i, "\"hold\" must be a duration in seconds > 0");
|
|
491
|
+
out.push({
|
|
492
|
+
t,
|
|
493
|
+
key: ev.key,
|
|
494
|
+
down: true
|
|
495
|
+
}, {
|
|
496
|
+
t: t + ev.hold,
|
|
497
|
+
key: ev.key,
|
|
498
|
+
down: false
|
|
499
|
+
});
|
|
500
|
+
} else out.push({
|
|
501
|
+
t,
|
|
502
|
+
key: ev.key,
|
|
503
|
+
down: ev.down !== false
|
|
504
|
+
});
|
|
505
|
+
} else if (kind === "click") {
|
|
506
|
+
if (!pair(ev.click)) throw bad(i, "\"click\" must be [x, y] in -1..1");
|
|
507
|
+
out.push({
|
|
508
|
+
t,
|
|
509
|
+
click: ev.click
|
|
510
|
+
});
|
|
511
|
+
} else if (kind === "pointer") {
|
|
512
|
+
if (!pair(ev.pointer)) throw bad(i, "\"pointer\" must be [x, y] in -1..1");
|
|
513
|
+
if (ev.down !== void 0 && typeof ev.down !== "boolean") throw bad(i, "\"down\" must be true (press) or false (release)");
|
|
514
|
+
out.push(ev.down === void 0 ? {
|
|
515
|
+
t,
|
|
516
|
+
pointer: ev.pointer
|
|
517
|
+
} : {
|
|
518
|
+
t,
|
|
519
|
+
pointer: ev.pointer,
|
|
520
|
+
down: ev.down
|
|
521
|
+
});
|
|
522
|
+
} else if (kind === "pointerDown") {
|
|
523
|
+
if (!pair(ev.pointerDown)) throw bad(i, "\"pointerDown\" must be [x, y] in -1..1");
|
|
524
|
+
out.push({
|
|
525
|
+
t,
|
|
526
|
+
pointerDown: ev.pointerDown
|
|
527
|
+
});
|
|
528
|
+
} else if (kind === "pointerUp") {
|
|
529
|
+
if (ev.pointerUp !== true && !pair(ev.pointerUp)) throw bad(i, "\"pointerUp\" must be [x, y] in -1..1 (or true: where the pointer is)");
|
|
530
|
+
out.push({
|
|
531
|
+
t,
|
|
532
|
+
pointerUp: ev.pointerUp === true ? null : ev.pointerUp
|
|
533
|
+
});
|
|
534
|
+
} else if (kind === "drag") {
|
|
535
|
+
const d = ev.drag;
|
|
536
|
+
if (!d || typeof d !== "object" || !pair(d.from) || !pair(d.to)) throw bad(i, "\"drag\" must be {\"from\": [x, y], \"to\": [x, y], \"duration\"?: seconds}");
|
|
537
|
+
const unknown = Object.keys(d).filter((k) => ![
|
|
538
|
+
"from",
|
|
539
|
+
"to",
|
|
540
|
+
"duration"
|
|
541
|
+
].includes(k));
|
|
542
|
+
if (unknown.length) throw bad(i, `unknown drag field${unknown.length > 1 ? "s" : ""} ${unknown.map((k) => `"${k}"`).join(", ")} (allowed: from, to, duration)`);
|
|
543
|
+
const duration = d.duration === void 0 ? .3 : d.duration;
|
|
544
|
+
if (typeof duration !== "number" || !(duration > 0) || duration > 30) throw bad(i, "\"drag.duration\" must be seconds in (0, 30]");
|
|
545
|
+
const [from, to] = [d.from, d.to];
|
|
546
|
+
const steps = Math.max(1, Math.round(duration * 30));
|
|
547
|
+
out.push({
|
|
548
|
+
t,
|
|
549
|
+
pointerDown: from
|
|
550
|
+
});
|
|
551
|
+
for (let k = 1; k <= steps; k++) {
|
|
552
|
+
const f = k / steps;
|
|
553
|
+
out.push({
|
|
554
|
+
t: Math.round((t + duration * f) * 1e6) / 1e6,
|
|
555
|
+
pointer: [from[0] + (to[0] - from[0]) * f, from[1] + (to[1] - from[1]) * f]
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
out.push({
|
|
559
|
+
t: Math.round((t + duration) * 1e6) / 1e6,
|
|
560
|
+
pointerUp: to
|
|
561
|
+
});
|
|
562
|
+
} else if (kind === "scroll") {
|
|
563
|
+
if (ev.scroll !== null && (typeof ev.scroll !== "number" || !(ev.scroll >= 0 && ev.scroll <= 1))) throw bad(i, "\"scroll\" must be a progress between 0 and 1 (or null)");
|
|
564
|
+
out.push({
|
|
565
|
+
t,
|
|
566
|
+
scroll: ev.scroll
|
|
567
|
+
});
|
|
568
|
+
} else if (kind === "emit") {
|
|
569
|
+
if (typeof ev.emit !== "string" || !ev.emit) throw bad(i, "\"emit\" must be an event name, e.g. \"retry\"");
|
|
570
|
+
out.push(ev.payload === void 0 ? {
|
|
571
|
+
t,
|
|
572
|
+
emit: ev.emit
|
|
573
|
+
} : {
|
|
574
|
+
t,
|
|
575
|
+
emit: ev.emit,
|
|
576
|
+
payload: ev.payload
|
|
577
|
+
});
|
|
578
|
+
} else if (kind === "ui") {
|
|
579
|
+
if (typeof ev.ui !== "string" || !ev.ui) throw bad(i, "\"ui\" must be the id of a HUD button (scene.ui.elements, type \"button\")");
|
|
580
|
+
out.push({
|
|
581
|
+
t,
|
|
582
|
+
ui: ev.ui
|
|
583
|
+
});
|
|
584
|
+
} else if (kind === "segment") {
|
|
585
|
+
if (typeof ev.segment !== "string" || !ev.segment) throw bad(i, "\"segment\" must be a timeline segment name (timeline.segments) or \"timeline\"");
|
|
586
|
+
if (ev.reverse !== void 0 && typeof ev.reverse !== "boolean") throw bad(i, "\"reverse\" must be true or false");
|
|
587
|
+
out.push(ev.reverse ? {
|
|
588
|
+
t,
|
|
589
|
+
segment: ev.segment,
|
|
590
|
+
reverse: true
|
|
591
|
+
} : {
|
|
592
|
+
t,
|
|
593
|
+
segment: ev.segment
|
|
594
|
+
});
|
|
595
|
+
} else {
|
|
596
|
+
if (typeof ev.swipe !== "string" || !SWIPES.includes(ev.swipe)) throw bad(i, "\"swipe\" must be \"left\", \"right\", \"up\" or \"down\"");
|
|
597
|
+
out.push({
|
|
598
|
+
t,
|
|
599
|
+
swipe: ev.swipe
|
|
600
|
+
});
|
|
601
|
+
}
|
|
602
|
+
});
|
|
603
|
+
return out.map((e, i) => ({
|
|
604
|
+
e,
|
|
605
|
+
i
|
|
606
|
+
})).sort((a, b) => a.e.t - b.e.t || a.i - b.i).map((x) => x.e);
|
|
607
|
+
}
|
|
608
|
+
function checkInputsForScene(scene, events) {
|
|
609
|
+
const buttons = (scene.ui?.elements ?? []).filter((e) => e.type === "button").map((e) => e.id);
|
|
610
|
+
const segments = ["timeline", ...Object.keys(scene.timeline?.segments ?? {})];
|
|
611
|
+
for (const ev of events) {
|
|
612
|
+
if ("ui" in ev && !buttons.includes(ev.ui)) {
|
|
613
|
+
const s = closest(ev.ui, buttons);
|
|
614
|
+
throw new CliError("usage", `--input: no HUD button "${ev.ui}" in scene.ui.elements.`, buttons.length ? `${s ? `Did you mean "${s}"? ` : ""}Buttons: ${buttons.join(", ")}.` : "The scene has no ui button — use {\"t\": …, \"emit\": \"<action>\"} to emit the event directly.", 2);
|
|
615
|
+
}
|
|
616
|
+
if ("segment" in ev) {
|
|
617
|
+
if (!scene.timeline) throw new CliError("usage", `--input / --segment "${ev.segment}": the scene has no timeline.`, "Add a timeline with segments (timeline set), or drop --segment.", 2);
|
|
618
|
+
if (!segments.includes(ev.segment)) {
|
|
619
|
+
const s = closest(ev.segment, segments);
|
|
620
|
+
throw new CliError("usage", `--input / --segment: no timeline segment "${ev.segment}".`, `${s ? `Did you mean "${s}"? ` : ""}Segments: ${segments.join(", ")}.`, 2);
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
function inputCall(ev) {
|
|
626
|
+
const p = (pt) => `${pt[0]}, ${pt[1]}`;
|
|
627
|
+
if ("emit" in ev) return `p.emit?.(${JSON.stringify(ev.emit)}${ev.payload === void 0 ? "" : `, ${JSON.stringify(ev.payload)}`})`;
|
|
628
|
+
if ("ui" in ev) return `window.__agent3dUi(${JSON.stringify(ev.ui)})`;
|
|
629
|
+
if ("segment" in ev) return `p.playSegment?.(${JSON.stringify(ev.segment)}${ev.reverse ? ", { reverse: true }" : ""})`;
|
|
630
|
+
if ("key" in ev) return `i.key(${JSON.stringify(ev.key)}, ${ev.down})`;
|
|
631
|
+
if ("click" in ev) return `i.click(${p(ev.click)})`;
|
|
632
|
+
if ("pointerDown" in ev) return `(i.pointer(${p(ev.pointerDown)}), i.down?.(${p(ev.pointerDown)}))`;
|
|
633
|
+
if ("pointerUp" in ev) return ev.pointerUp ? `(i.pointer(${p(ev.pointerUp)}), i.up?.(${p(ev.pointerUp)}))` : "i.up?.()";
|
|
634
|
+
if ("swipe" in ev) return `i.swipe?.(${JSON.stringify(ev.swipe)})`;
|
|
635
|
+
if ("scroll" in ev) return `i.scroll?.(${JSON.stringify(ev.scroll)})`;
|
|
636
|
+
return ev.down === void 0 ? `i.pointer(${p(ev.pointer)})` : `(i.pointer(${p(ev.pointer)}), ${ev.down ? "i.down?.()" : "i.up?.()"})`;
|
|
637
|
+
}
|
|
638
|
+
function projectPath(projectDir, abs) {
|
|
639
|
+
const rel = relative(resolve(projectDir), abs);
|
|
640
|
+
return rel && !rel.startsWith("..") && !isAbsolute(rel) ? rel.split("\\").join("/") : abs;
|
|
641
|
+
}
|
|
642
|
+
function dataUrlBytes(url, what) {
|
|
643
|
+
if (typeof url !== "string" || !url.startsWith("data:")) throw new CliError("render-failed", `The page returned no image for ${what}.`, "The runtime's snapshot() failed — see consoleErrors; `agent3d doctor` runs a test render.");
|
|
644
|
+
const comma = url.indexOf(",");
|
|
645
|
+
return new Uint8Array(Buffer.from(url.slice(comma + 1), "base64"));
|
|
646
|
+
}
|
|
647
|
+
function b64(bytes) {
|
|
648
|
+
return Buffer.from(bytes).toString("base64");
|
|
649
|
+
}
|
|
650
|
+
function readScene(projectDir) {
|
|
651
|
+
try {
|
|
652
|
+
return JSON.parse(readFileSync(join(projectDir, "scene.json"), "utf8"));
|
|
653
|
+
} catch (e) {
|
|
654
|
+
throw new CliError("no-project", `Cannot read ${join(projectDir, "scene.json")}: ${e.message}`, "Pass --project <dir> (a folder with scene.json), or create one with `agent3d new <dir>`.");
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
async function openRenderSession(opts) {
|
|
658
|
+
if (!runtimeBuilt()) throw new CliError("runtime-missing", `The runtime build is missing (${join(runtimeDir(), "agent3d-runtime.js")}).`, "Use the npm package (it ships dist/runtime), or run `npm run build:runtime` in a clone. AGENT3D_DIST can point at another dist/ folder.");
|
|
659
|
+
const browserInfo = requireBrowser();
|
|
660
|
+
const scene = opts.scene ?? readScene(opts.projectDir);
|
|
661
|
+
const timeoutMs = opts.timeoutMs ?? (Number(process.env.AGENT3D_CDP_TIMEOUT_MS) || 6e4);
|
|
662
|
+
const log = opts.log ?? (() => void 0);
|
|
663
|
+
const t0 = Date.now();
|
|
664
|
+
const html = previewHtml({
|
|
665
|
+
pixelRatio: opts.viewport.deviceScaleFactor,
|
|
666
|
+
transparent: !!scene.target?.transparent,
|
|
667
|
+
reducedMotion: !!opts.reducedMotion
|
|
668
|
+
});
|
|
669
|
+
let server = null;
|
|
670
|
+
let browser = null;
|
|
671
|
+
let client = null;
|
|
672
|
+
const cleanup = async () => {
|
|
673
|
+
try {
|
|
674
|
+
client?.close();
|
|
675
|
+
} catch {}
|
|
676
|
+
await browser?.close().catch(() => void 0);
|
|
677
|
+
await server?.close().catch(() => void 0);
|
|
678
|
+
};
|
|
679
|
+
try {
|
|
680
|
+
server = await startLocalServer({
|
|
681
|
+
mounts: {
|
|
682
|
+
"/__runtime/": runtimeDir(),
|
|
683
|
+
"/__library/": libraryDir(),
|
|
684
|
+
"/project/": resolve(opts.projectDir)
|
|
685
|
+
},
|
|
686
|
+
routes: [(_req, res, url) => {
|
|
687
|
+
if (url.pathname === "/__preview.html") return sendText(res, 200, html, "text/html; charset=utf-8"), true;
|
|
688
|
+
if (url.pathname === "/__scene.json") return sendText(res, 200, JSON.stringify(scene), "application/json; charset=utf-8"), true;
|
|
689
|
+
return false;
|
|
690
|
+
}]
|
|
691
|
+
});
|
|
692
|
+
log(`[agent3d render] ${browserInfo.name}: ${browserInfo.path}`);
|
|
693
|
+
browser = await launchBrowser(browserInfo);
|
|
694
|
+
client = await CdpClient.connect(browser.wsUrl);
|
|
695
|
+
const page = await client.newPage();
|
|
696
|
+
const launchMs = Date.now() - t0;
|
|
697
|
+
const consoleErrors = [];
|
|
698
|
+
const pushErr = (s) => {
|
|
699
|
+
if (consoleErrors.length < 50) consoleErrors.push(s.slice(0, 2e3));
|
|
700
|
+
};
|
|
701
|
+
page.on("Runtime.consoleAPICalled", (p) => {
|
|
702
|
+
if (p.type !== "error" && p.type !== "assert") return;
|
|
703
|
+
const args = p.args ?? [];
|
|
704
|
+
pushErr(args.map((a) => a.value !== void 0 ? String(a.value) : a.description ?? "").join(" "));
|
|
705
|
+
});
|
|
706
|
+
page.on("Runtime.exceptionThrown", (p) => {
|
|
707
|
+
const d = p.exceptionDetails;
|
|
708
|
+
pushErr(d?.exception?.description ?? d?.text ?? "Uncaught exception");
|
|
709
|
+
});
|
|
710
|
+
page.on("Log.entryAdded", (p) => {
|
|
711
|
+
const e = p.entry;
|
|
712
|
+
if (e?.level === "error") pushErr(`${e.text ?? ""}${e.url ? ` (${e.url})` : ""}`);
|
|
713
|
+
});
|
|
714
|
+
await page.send("Runtime.enable");
|
|
715
|
+
await page.send("Page.enable");
|
|
716
|
+
await page.send("Log.enable");
|
|
717
|
+
await page.send("Emulation.setDeviceMetricsOverride", {
|
|
718
|
+
width: opts.viewport.width,
|
|
719
|
+
height: opts.viewport.height,
|
|
720
|
+
deviceScaleFactor: opts.viewport.deviceScaleFactor,
|
|
721
|
+
mobile: false
|
|
722
|
+
});
|
|
723
|
+
if (scene.target?.transparent) await page.send("Emulation.setDefaultBackgroundColorOverride", { color: {
|
|
724
|
+
r: 0,
|
|
725
|
+
g: 0,
|
|
726
|
+
b: 0,
|
|
727
|
+
a: 0
|
|
728
|
+
} });
|
|
729
|
+
await page.send("Page.navigate", { url: `${server.url}/__preview.html` });
|
|
730
|
+
const deadline = Date.now() + timeoutMs;
|
|
731
|
+
let state = null;
|
|
732
|
+
for (;;) {
|
|
733
|
+
state = await page.evaluate("window.__agent3d ? { ready: window.__agent3d.ready, error: window.__agent3d.error, webgl: window.__agent3d.webgl, issues: window.__agent3d.issues } : null", 1e4).catch(() => null);
|
|
734
|
+
if (state?.ready || state?.error) break;
|
|
735
|
+
if (Date.now() > deadline) break;
|
|
736
|
+
await new Promise((r) => setTimeout(r, 100));
|
|
737
|
+
}
|
|
738
|
+
if (!state?.ready) {
|
|
739
|
+
const webglIssue = state?.issues?.find((i) => i.code === "webgl-unavailable");
|
|
740
|
+
if (state && (!state.webgl || webglIssue)) throw new CliError("webgl-unavailable", `WebGL is not available in headless ${browserInfo.name}${webglIssue ? `: ${webglIssue.message}` : ""}.`, "The render uses SwiftShader (software WebGL): update the browser, or point AGENT3D_CHROME at Google Chrome / Chromium (`npx playwright install chromium`). `agent3d doctor` tests it.", 1, {
|
|
741
|
+
consoleErrors,
|
|
742
|
+
issues: state?.issues ?? []
|
|
743
|
+
});
|
|
744
|
+
if (state?.error) throw new CliError("render-failed", `The scene failed to mount: ${state.error.split("\n")[0]}`, /import|module|Failed to fetch/i.test(state.error) ? "The runtime could not be loaded: rebuild it (`npm run build:runtime`) or check AGENT3D_DIST." : "Run `agent3d scene validate` and `agent3d check`, fix the reported issues, then render again.", 1, {
|
|
745
|
+
error: state.error,
|
|
746
|
+
consoleErrors,
|
|
747
|
+
issues: state.issues
|
|
748
|
+
});
|
|
749
|
+
throw new CliError("render-timeout", `The scene was not ready after ${Math.round(timeoutMs / 1e3)} s.`, "Something is still loading (large models / textures?) or a script never resolves. See details.consoleErrors / issues; raise --timeout <s>, or simplify the scene.", 1, {
|
|
750
|
+
consoleErrors,
|
|
751
|
+
issues: state?.issues ?? []
|
|
752
|
+
});
|
|
753
|
+
}
|
|
754
|
+
const readyMs = Date.now() - t0 - launchMs;
|
|
755
|
+
log(`[agent3d render] ready in ${readyMs} ms`);
|
|
756
|
+
return {
|
|
757
|
+
browser: browserInfo,
|
|
758
|
+
viewport: opts.viewport,
|
|
759
|
+
page,
|
|
760
|
+
consoleErrors,
|
|
761
|
+
timings: {
|
|
762
|
+
launchMs,
|
|
763
|
+
readyMs
|
|
764
|
+
},
|
|
765
|
+
async frame(t, type = "image/png", quality) {
|
|
766
|
+
return dataUrlBytes(await page.evaluate(`window.__agent3dFrame(${JSON.stringify(t)}, ${JSON.stringify(type)}, ${quality === void 0 ? "undefined" : JSON.stringify(quality)})`, timeoutMs), `t=${t}`);
|
|
767
|
+
},
|
|
768
|
+
async screenshot(t, format = "png", quality) {
|
|
769
|
+
await page.evaluate(`window.__agent3d.player.seek(${JSON.stringify(t)}).then(() => new Promise((r) => requestAnimationFrame(() => r(true))))`, timeoutMs);
|
|
770
|
+
const r = await page.send("Page.captureScreenshot", {
|
|
771
|
+
format,
|
|
772
|
+
...quality !== void 0 && format !== "png" ? { quality: Math.round(quality * 100) } : {},
|
|
773
|
+
fromSurface: true,
|
|
774
|
+
captureBeyondViewport: false
|
|
775
|
+
}, timeoutMs);
|
|
776
|
+
return new Uint8Array(Buffer.from(r.data, "base64"));
|
|
777
|
+
},
|
|
778
|
+
async sheet(frames, labels, cols, bg) {
|
|
779
|
+
const urls = frames.map((f) => `data:image/png;base64,${b64(f)}`);
|
|
780
|
+
const r = await page.send("Runtime.callFunctionOn", {
|
|
781
|
+
functionDeclaration: "function (u, l, c, b) { return window.__agent3dSheet(u, l, c, b); }",
|
|
782
|
+
executionContextId: void 0,
|
|
783
|
+
objectId: await globalObjectId(page),
|
|
784
|
+
arguments: [
|
|
785
|
+
{ value: urls },
|
|
786
|
+
{ value: labels },
|
|
787
|
+
{ value: cols ?? 0 },
|
|
788
|
+
{ value: bg ?? null }
|
|
789
|
+
],
|
|
790
|
+
awaitPromise: true,
|
|
791
|
+
returnByValue: true
|
|
792
|
+
}, timeoutMs);
|
|
793
|
+
if (r.exceptionDetails) throw new CliError("render-failed", "Could not compose the contact sheet.", "Render without --sheet, or with fewer frames.");
|
|
794
|
+
return dataUrlBytes(r.result.value, "the contact sheet");
|
|
795
|
+
},
|
|
796
|
+
async composite(png, bg) {
|
|
797
|
+
const r = await page.send("Runtime.callFunctionOn", {
|
|
798
|
+
functionDeclaration: "function (u, b) { return window.__agent3dComposite(u, b); }",
|
|
799
|
+
objectId: await globalObjectId(page),
|
|
800
|
+
arguments: [{ value: `data:image/png;base64,${b64(png)}` }, { value: bg }],
|
|
801
|
+
awaitPromise: true,
|
|
802
|
+
returnByValue: true
|
|
803
|
+
}, timeoutMs);
|
|
804
|
+
if (r.exceptionDetails) throw new CliError("render-failed", "Could not draw the frame over the background.", "Render without --bg.");
|
|
805
|
+
return dataUrlBytes(r.result.value, "the composited frame");
|
|
806
|
+
},
|
|
807
|
+
async update(next) {
|
|
808
|
+
await page.evaluate(`window.__agent3d.player.update(${JSON.stringify(next)}).then(() => true)`, timeoutMs);
|
|
809
|
+
},
|
|
810
|
+
async scale(png, maxWidth, o = {}) {
|
|
811
|
+
const r = await page.send("Runtime.callFunctionOn", {
|
|
812
|
+
functionDeclaration: `async function (u, w, type, q, bg) {
|
|
813
|
+
const img = new Image(); img.src = u; await img.decode();
|
|
814
|
+
if (img.naturalWidth <= w && !type) return null;
|
|
815
|
+
w = Math.min(w, img.naturalWidth);
|
|
816
|
+
const h = Math.max(1, Math.round(img.naturalHeight * w / img.naturalWidth));
|
|
817
|
+
const c = document.createElement("canvas"); c.width = w; c.height = h;
|
|
818
|
+
const g = c.getContext("2d");
|
|
819
|
+
if (bg) { g.fillStyle = bg; g.fillRect(0, 0, w, h); }
|
|
820
|
+
g.imageSmoothingQuality = "high"; g.drawImage(img, 0, 0, w, h);
|
|
821
|
+
return c.toDataURL(type || "image/png", q);
|
|
822
|
+
}`,
|
|
823
|
+
objectId: await globalObjectId(page),
|
|
824
|
+
arguments: [
|
|
825
|
+
{ value: `data:image/png;base64,${b64(png)}` },
|
|
826
|
+
{ value: Math.round(Math.min(maxWidth, 16384)) },
|
|
827
|
+
{ value: o.type ?? null },
|
|
828
|
+
{ value: o.quality ?? null },
|
|
829
|
+
{ value: o.bg ?? null }
|
|
830
|
+
],
|
|
831
|
+
awaitPromise: true,
|
|
832
|
+
returnByValue: true
|
|
833
|
+
}, timeoutMs);
|
|
834
|
+
if (r.exceptionDetails || !r.result.value) return png;
|
|
835
|
+
return dataUrlBytes(r.result.value, "the preview");
|
|
836
|
+
},
|
|
837
|
+
async seek(t) {
|
|
838
|
+
await page.evaluate(`window.__agent3d.player.seek(${JSON.stringify(t)}).then(() => true)`, timeoutMs);
|
|
839
|
+
},
|
|
840
|
+
async input(ev) {
|
|
841
|
+
return await page.evaluate(`((p) => { const i = p.input; const r = ${inputCall(ev)}; return r === false ? false : true; })(window.__agent3d.player)`, timeoutMs) !== false;
|
|
842
|
+
},
|
|
843
|
+
async info() {
|
|
844
|
+
return await page.evaluate("window.__agent3dInfo()", timeoutMs) ?? {
|
|
845
|
+
stats: null,
|
|
846
|
+
inspect: null,
|
|
847
|
+
issues: [],
|
|
848
|
+
state: null
|
|
849
|
+
};
|
|
850
|
+
},
|
|
851
|
+
async grab(t, o = {}) {
|
|
852
|
+
return dataUrlBytes(await page.evaluate(`window.__agent3dGrab(${JSON.stringify(t)}, ${JSON.stringify(o)})`, timeoutMs), `t=${t}`);
|
|
853
|
+
},
|
|
854
|
+
async grabRgba(t, o = {}) {
|
|
855
|
+
const r = await page.evaluate(`window.__agent3dGrab(${JSON.stringify(t)}, ${JSON.stringify({
|
|
856
|
+
...o,
|
|
857
|
+
raw: true
|
|
858
|
+
})})`, timeoutMs);
|
|
859
|
+
if (!r?.rgba) throw new CliError("render-failed", `The page returned no pixels for t=${t}.`, "See consoleErrors; `agent3d doctor` runs a test render.");
|
|
860
|
+
return {
|
|
861
|
+
width: r.width,
|
|
862
|
+
height: r.height,
|
|
863
|
+
rgba: new Uint8Array(Buffer.from(r.rgba, "base64"))
|
|
864
|
+
};
|
|
865
|
+
},
|
|
866
|
+
async social(png, width, height) {
|
|
867
|
+
const r = await page.send("Runtime.callFunctionOn", {
|
|
868
|
+
functionDeclaration: "function (u, w, h) { return window.__agent3dSocial(u, w, h); }",
|
|
869
|
+
objectId: await globalObjectId(page),
|
|
870
|
+
arguments: [
|
|
871
|
+
{ value: `data:image/png;base64,${b64(png)}` },
|
|
872
|
+
{ value: width },
|
|
873
|
+
{ value: height }
|
|
874
|
+
],
|
|
875
|
+
awaitPromise: true,
|
|
876
|
+
returnByValue: true
|
|
877
|
+
}, timeoutMs);
|
|
878
|
+
if (r.exceptionDetails) throw new CliError("render-failed", "Could not compose the social preview image.", "Export with --no-og.");
|
|
879
|
+
return dataUrlBytes(r.result.value, "the social preview");
|
|
880
|
+
},
|
|
881
|
+
async setScroll(progress) {
|
|
882
|
+
return !!await page.evaluate(`(() => { const p = window.__agent3d.player; if (typeof p.setScrollProgress !== "function") return false; p.setScrollProgress(${JSON.stringify(progress)}); return true; })()`, timeoutMs);
|
|
883
|
+
},
|
|
884
|
+
evaluate: (expression) => page.evaluate(expression, timeoutMs),
|
|
885
|
+
close: cleanup
|
|
886
|
+
};
|
|
887
|
+
} catch (e) {
|
|
888
|
+
await cleanup();
|
|
889
|
+
throw e;
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
async function globalObjectId(page) {
|
|
893
|
+
return (await page.send("Runtime.evaluate", { expression: "window" })).result.objectId;
|
|
894
|
+
}
|
|
895
|
+
function timestamp(d = /* @__PURE__ */ new Date()) {
|
|
896
|
+
const p = (n) => String(n).padStart(2, "0");
|
|
897
|
+
return `${d.getFullYear()}${p(d.getMonth() + 1)}${p(d.getDate())}-${p(d.getHours())}${p(d.getMinutes())}${p(d.getSeconds())}`;
|
|
898
|
+
}
|
|
899
|
+
function parseBg(bg) {
|
|
900
|
+
if (bg === void 0) return void 0;
|
|
901
|
+
const v = bg.trim();
|
|
902
|
+
if (v === "checker" || v === "none") return v;
|
|
903
|
+
if (/^#([0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(v) || /^(rgb|rgba|hsl|hsla)\([^)]*\)$/i.test(v) || /^[a-z]{3,20}$/i.test(v)) return v;
|
|
904
|
+
throw new CliError("usage", `--bg must be "checker", "none" or a CSS colour, got "${bg}".`, "e.g. --bg checker, --bg \"#ffffff\", --bg \"rgb(20, 20, 30)\", --bg white.", 2);
|
|
905
|
+
}
|
|
906
|
+
function isolateScene(scene, id) {
|
|
907
|
+
const found = findObject(scene.objects, id);
|
|
908
|
+
if (!found) {
|
|
909
|
+
const ids = [];
|
|
910
|
+
walkObjects(scene.objects, (o) => void ids.push(o.id));
|
|
911
|
+
const s = closest(id, ids);
|
|
912
|
+
throw new CliError("notFound", `No object "${id}" to isolate.`, `${s ? `Did you mean "${s}"? ` : ""}\`agent3d object list\` lists the ids.`, 1);
|
|
913
|
+
}
|
|
914
|
+
const strip = (o) => {
|
|
915
|
+
const { behaviours: _b, ...rest } = o;
|
|
916
|
+
const children = rest.children;
|
|
917
|
+
return {
|
|
918
|
+
...rest,
|
|
919
|
+
...children ? { children: children.map(strip) } : {}
|
|
920
|
+
};
|
|
921
|
+
};
|
|
922
|
+
const obj = {
|
|
923
|
+
...strip(found.object),
|
|
924
|
+
position: [
|
|
925
|
+
0,
|
|
926
|
+
0,
|
|
927
|
+
0
|
|
928
|
+
],
|
|
929
|
+
visible: true
|
|
930
|
+
};
|
|
931
|
+
return {
|
|
932
|
+
version: scene.version,
|
|
933
|
+
id: `${scene.id ?? "scene"}-isolate`,
|
|
934
|
+
title: `${id} (isolated)`,
|
|
935
|
+
target: {
|
|
936
|
+
kind: "square",
|
|
937
|
+
aspect: "1:1"
|
|
938
|
+
},
|
|
939
|
+
camera: {
|
|
940
|
+
type: "perspective",
|
|
941
|
+
fov: 35,
|
|
942
|
+
position: [
|
|
943
|
+
3,
|
|
944
|
+
2.5,
|
|
945
|
+
5
|
|
946
|
+
],
|
|
947
|
+
target: [
|
|
948
|
+
0,
|
|
949
|
+
.5,
|
|
950
|
+
0
|
|
951
|
+
]
|
|
952
|
+
},
|
|
953
|
+
environment: {
|
|
954
|
+
background: "#dfe2e8",
|
|
955
|
+
lighting: "studio"
|
|
956
|
+
},
|
|
957
|
+
lights: [{
|
|
958
|
+
id: "fill",
|
|
959
|
+
type: "hemisphere",
|
|
960
|
+
skyColor: "#ffffff",
|
|
961
|
+
groundColor: "#8c8f99",
|
|
962
|
+
intensity: 1.1
|
|
963
|
+
}, {
|
|
964
|
+
id: "key",
|
|
965
|
+
type: "directional",
|
|
966
|
+
position: [
|
|
967
|
+
4,
|
|
968
|
+
8,
|
|
969
|
+
6
|
|
970
|
+
],
|
|
971
|
+
intensity: 2.2
|
|
972
|
+
}],
|
|
973
|
+
objects: [obj]
|
|
974
|
+
};
|
|
975
|
+
}
|
|
976
|
+
function frameBox(min, max, fov = 35, aspect = 1) {
|
|
977
|
+
const c = [
|
|
978
|
+
0,
|
|
979
|
+
1,
|
|
980
|
+
2
|
|
981
|
+
].map((i) => (min[i] + max[i]) / 2);
|
|
982
|
+
const r = Math.max(.01, Math.hypot(max[0] - min[0], max[1] - min[1], max[2] - min[2]) / 2);
|
|
983
|
+
const half = fov / 2 * Math.PI / 180;
|
|
984
|
+
const fit = Math.min(half, Math.atan(Math.tan(half) * aspect));
|
|
985
|
+
const d = r / Math.sin(fit) * 1;
|
|
986
|
+
const dir = [
|
|
987
|
+
.45,
|
|
988
|
+
.35,
|
|
989
|
+
1
|
|
990
|
+
];
|
|
991
|
+
const n = Math.hypot(...dir);
|
|
992
|
+
const round = (v) => Math.round(v * 1e3) / 1e3;
|
|
993
|
+
return {
|
|
994
|
+
position: [
|
|
995
|
+
0,
|
|
996
|
+
1,
|
|
997
|
+
2
|
|
998
|
+
].map((i) => round(c[i] + dir[i] / n * d)),
|
|
999
|
+
target: c.map(round)
|
|
1000
|
+
};
|
|
1001
|
+
}
|
|
1002
|
+
async function applyInputsUpTo(session, inputs, cursor, t) {
|
|
1003
|
+
for (; cursor.next < inputs.length && inputs[cursor.next].t <= t + 1e-9; cursor.next++) {
|
|
1004
|
+
const ev = inputs[cursor.next];
|
|
1005
|
+
await session.seek(ev.t);
|
|
1006
|
+
const ok = await session.input(ev);
|
|
1007
|
+
if ("scroll" in ev) cursor.scroll = ev.scroll === null ? void 0 : ev.scroll;
|
|
1008
|
+
if (!ok && "ui" in ev && cursor.warnings.length < 20) cursor.warnings.push(`t=${ev.t}: HUD button "${ev.ui}" is not shown at that time (its "visible" condition is false, or the HUD is not mounted) — nothing was clicked.`);
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
function segmentInputs(segment, start = 0) {
|
|
1012
|
+
return segment ? [{
|
|
1013
|
+
t: start,
|
|
1014
|
+
segment
|
|
1015
|
+
}] : [];
|
|
1016
|
+
}
|
|
1017
|
+
function frameSuffix(t, scroll, scrollOnly) {
|
|
1018
|
+
const f = (v) => String(Math.round(v * 1e3) / 1e3).replace(/\./g, "_");
|
|
1019
|
+
if (scroll === void 0) return `t${f(t)}`;
|
|
1020
|
+
return scrollOnly ? `s${f(scroll)}` : `s${f(scroll)}-t${f(t)}`;
|
|
1021
|
+
}
|
|
1022
|
+
async function renderProject(opts) {
|
|
1023
|
+
const t0 = Date.now();
|
|
1024
|
+
const original = sceneForRender(opts.scene ?? readScene(opts.projectDir), { transparent: opts.transparent });
|
|
1025
|
+
const scene = opts.isolate ? isolateScene(original, opts.isolate) : original;
|
|
1026
|
+
const bgOpt = parseBg(opts.bg);
|
|
1027
|
+
const transparent = !!scene.target?.transparent;
|
|
1028
|
+
const frameBg = bgOpt && bgOpt !== "none" ? bgOpt : void 0;
|
|
1029
|
+
const sheetBg = bgOpt === "none" ? void 0 : bgOpt ?? (transparent ? "checker" : void 0);
|
|
1030
|
+
const outViewport = viewportFor(scene, {
|
|
1031
|
+
size: opts.size ?? (opts.isolate ? "800x800" : void 0),
|
|
1032
|
+
width: opts.width,
|
|
1033
|
+
scale: opts.scale
|
|
1034
|
+
});
|
|
1035
|
+
const ss = clampSs(QUALITY_SS[opts.quality ?? "standard"], outViewport);
|
|
1036
|
+
const viewport = {
|
|
1037
|
+
...outViewport,
|
|
1038
|
+
deviceScaleFactor: outViewport.deviceScaleFactor * ss
|
|
1039
|
+
};
|
|
1040
|
+
if (opts.scroll !== void 0 && !(opts.scroll >= 0 && opts.scroll <= 1)) throw new CliError("usage", "--scroll must be a progress between 0 and 1.", "e.g. --scroll 0.5 (half-way through the page scroll).", 2);
|
|
1041
|
+
const inputs = [...segmentInputs(opts.segment), ...opts.input ?? []].map((e, i) => ({
|
|
1042
|
+
e,
|
|
1043
|
+
i
|
|
1044
|
+
})).sort((a, b) => a.e.t - b.e.t || a.i - b.i).map((x) => x.e);
|
|
1045
|
+
if (!opts.isolate) checkInputsForScene(scene, inputs);
|
|
1046
|
+
let times = frameTimes(scene, {
|
|
1047
|
+
frames: opts.frames,
|
|
1048
|
+
count: opts.count ?? (opts.isolate ? 1 : void 0)
|
|
1049
|
+
});
|
|
1050
|
+
if (inputs.length) times = [...times].sort((a, b) => a - b);
|
|
1051
|
+
const capture = !opts.capture || opts.capture === "auto" ? scene.ui?.elements?.length ? "page" : "canvas" : opts.capture;
|
|
1052
|
+
const outDir = resolve(opts.outDir ?? join(opts.projectDir, "renders"));
|
|
1053
|
+
const session = await openRenderSession({
|
|
1054
|
+
projectDir: opts.projectDir,
|
|
1055
|
+
scene,
|
|
1056
|
+
viewport,
|
|
1057
|
+
reducedMotion: opts.reducedMotion,
|
|
1058
|
+
timeoutMs: opts.timeoutMs,
|
|
1059
|
+
log: opts.log
|
|
1060
|
+
});
|
|
1061
|
+
try {
|
|
1062
|
+
if (opts.scroll !== void 0 && !await session.setScroll(opts.scroll) && !opts.frames) times = [scrollTime(scene, opts.scroll)];
|
|
1063
|
+
const scrollOnly = opts.scroll !== void 0 && times.length === 1 && (!opts.frames || opts.frames.trim() === "0") && !inputs.some((e) => "scroll" in e);
|
|
1064
|
+
let isolated;
|
|
1065
|
+
if (opts.isolate) {
|
|
1066
|
+
const first = (await session.info()).inspect?.objects.find((o) => o.id === opts.isolate);
|
|
1067
|
+
if (first) {
|
|
1068
|
+
const cam = frameBox(first.min, first.max, 35, viewport.width / viewport.height);
|
|
1069
|
+
await session.update({
|
|
1070
|
+
...scene,
|
|
1071
|
+
camera: {
|
|
1072
|
+
...scene.camera,
|
|
1073
|
+
...cam
|
|
1074
|
+
}
|
|
1075
|
+
});
|
|
1076
|
+
const r = (v) => Math.round(v * 1e3) / 1e3;
|
|
1077
|
+
isolated = {
|
|
1078
|
+
id: opts.isolate,
|
|
1079
|
+
size: first.max.map((v, i) => r(v - first.min[i])),
|
|
1080
|
+
center: first.max.map((v, i) => r((v + first.min[i]) / 2)),
|
|
1081
|
+
note: "Front three-quarter view with the object's scene rotation and scale: the camera looks from +Z (front), slightly right (+X) and above (+Y). A model facing the camera faces +Z."
|
|
1082
|
+
};
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
const tf = Date.now();
|
|
1086
|
+
const shots = [];
|
|
1087
|
+
const cursor = {
|
|
1088
|
+
next: 0,
|
|
1089
|
+
scroll: opts.scroll,
|
|
1090
|
+
warnings: []
|
|
1091
|
+
};
|
|
1092
|
+
const frameScroll = [];
|
|
1093
|
+
for (const t of times) {
|
|
1094
|
+
await applyInputsUpTo(session, inputs, cursor, t);
|
|
1095
|
+
frameScroll.push(cursor.scroll);
|
|
1096
|
+
const shot = capture === "page" ? ss > 1 ? await session.scale(await session.screenshot(t), Math.round(outViewport.width * outViewport.deviceScaleFactor)) : await session.screenshot(t) : ss > 1 ? await session.grab(t, { ss }) : await session.frame(t);
|
|
1097
|
+
shots.push(frameBg ? await session.composite(shot, frameBg) : shot);
|
|
1098
|
+
}
|
|
1099
|
+
const framesMs = Date.now() - tf;
|
|
1100
|
+
const info = await session.info();
|
|
1101
|
+
mkdirSync(outDir, { recursive: true });
|
|
1102
|
+
const stamp = timestamp();
|
|
1103
|
+
const frames = times.map((t, i) => {
|
|
1104
|
+
const path = join(outDir, `${stamp}-${frameSuffix(t, frameScroll[i], scrollOnly)}.png`);
|
|
1105
|
+
writeFileSync(path, shots[i]);
|
|
1106
|
+
return {
|
|
1107
|
+
t,
|
|
1108
|
+
path,
|
|
1109
|
+
...frameScroll[i] !== void 0 ? { scroll: frameScroll[i] } : {}
|
|
1110
|
+
};
|
|
1111
|
+
});
|
|
1112
|
+
let sheet;
|
|
1113
|
+
if (opts.sheet) {
|
|
1114
|
+
const label = (t, i) => frameScroll[i] === void 0 ? `t = ${t.toFixed(2)} s` : scrollOnly ? `scroll = ${frameScroll[i].toFixed(2)}` : `scroll ${frameScroll[i].toFixed(2)} · t = ${t.toFixed(2)} s`;
|
|
1115
|
+
const bytes = await session.sheet(shots, times.map(label), opts.cols, frameBg ? void 0 : sheetBg);
|
|
1116
|
+
sheet = join(outDir, `${stamp}-sheet.png`);
|
|
1117
|
+
writeFileSync(sheet, bytes);
|
|
1118
|
+
}
|
|
1119
|
+
let preview;
|
|
1120
|
+
if (opts.previewWidth !== void 0) {
|
|
1121
|
+
const src = sheet ? readFileSync(sheet) : shots[0];
|
|
1122
|
+
const small = await session.scale(src, opts.previewWidth > 0 ? opts.previewWidth : 1e9, {
|
|
1123
|
+
type: "image/jpeg",
|
|
1124
|
+
quality: .82,
|
|
1125
|
+
bg: transparent ? "#ffffff" : void 0
|
|
1126
|
+
});
|
|
1127
|
+
preview = join(outDir, `${stamp}-preview.jpg`);
|
|
1128
|
+
writeFileSync(preview, small);
|
|
1129
|
+
}
|
|
1130
|
+
const projectDir = resolve(opts.projectDir);
|
|
1131
|
+
return {
|
|
1132
|
+
dir: projectDir,
|
|
1133
|
+
frames: frames.map((f) => ({
|
|
1134
|
+
...f,
|
|
1135
|
+
path: projectPath(projectDir, f.path)
|
|
1136
|
+
})),
|
|
1137
|
+
...opts.scroll !== void 0 ? { scroll: opts.scroll } : {},
|
|
1138
|
+
...opts.reducedMotion ? { reducedMotion: true } : {},
|
|
1139
|
+
...cursor.warnings.length ? { inputWarnings: cursor.warnings } : {},
|
|
1140
|
+
...sheet ? { sheet: projectPath(projectDir, sheet) } : {},
|
|
1141
|
+
...preview ? { preview: projectPath(projectDir, preview) } : {},
|
|
1142
|
+
...isolated ? { isolated } : {},
|
|
1143
|
+
size: outViewport,
|
|
1144
|
+
...ss > 1 ? { supersampling: ss } : {},
|
|
1145
|
+
capture,
|
|
1146
|
+
stats: info.stats,
|
|
1147
|
+
inspect: info.inspect,
|
|
1148
|
+
state: info.state ?? null,
|
|
1149
|
+
...inputs.length ? { inputs: inputs.length } : {},
|
|
1150
|
+
issues: info.issues ?? [],
|
|
1151
|
+
consoleErrors: session.consoleErrors,
|
|
1152
|
+
browser: {
|
|
1153
|
+
name: session.browser.name,
|
|
1154
|
+
path: session.browser.path
|
|
1155
|
+
},
|
|
1156
|
+
timings: {
|
|
1157
|
+
...session.timings,
|
|
1158
|
+
framesMs,
|
|
1159
|
+
totalMs: Date.now() - t0
|
|
1160
|
+
}
|
|
1161
|
+
};
|
|
1162
|
+
} finally {
|
|
1163
|
+
await session.close();
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
async function renderPoster(opts) {
|
|
1167
|
+
const scene = sceneForRender(opts.scene ?? readScene(opts.projectDir), { transparent: opts.transparent });
|
|
1168
|
+
const viewport = viewportFor(scene, {
|
|
1169
|
+
size: opts.size,
|
|
1170
|
+
width: opts.width,
|
|
1171
|
+
scale: opts.scale
|
|
1172
|
+
});
|
|
1173
|
+
const ss = clampSs(QUALITY_SS[opts.quality ?? "standard"], viewport);
|
|
1174
|
+
let t = opts.time ?? scene.target?.posterTime ?? 0;
|
|
1175
|
+
const format = opts.format ?? "webp";
|
|
1176
|
+
const bg = parseBg(opts.bg);
|
|
1177
|
+
const session = await openRenderSession({
|
|
1178
|
+
projectDir: opts.projectDir,
|
|
1179
|
+
scene,
|
|
1180
|
+
viewport: {
|
|
1181
|
+
...viewport,
|
|
1182
|
+
deviceScaleFactor: viewport.deviceScaleFactor * ss
|
|
1183
|
+
},
|
|
1184
|
+
timeoutMs: opts.timeoutMs,
|
|
1185
|
+
log: opts.log
|
|
1186
|
+
});
|
|
1187
|
+
try {
|
|
1188
|
+
if (opts.scroll !== void 0 && !await session.setScroll(opts.scroll) && opts.time === void 0) t = scrollTime(scene, opts.scroll);
|
|
1189
|
+
const type = format === "webp" ? "image/webp" : format === "jpeg" ? "image/jpeg" : "image/png";
|
|
1190
|
+
const q = format === "png" ? void 0 : opts.quality === "ultra" || opts.quality === "high" ? .92 : .85;
|
|
1191
|
+
const fill = bg && bg !== "none" ? bg : format === "jpeg" && scene.target?.transparent ? "#ffffff" : void 0;
|
|
1192
|
+
return {
|
|
1193
|
+
bytes: ss > 1 || fill || type === "image/jpeg" ? await session.grab(t, {
|
|
1194
|
+
ss,
|
|
1195
|
+
type,
|
|
1196
|
+
quality: q,
|
|
1197
|
+
bg: fill
|
|
1198
|
+
}) : await session.frame(t, type, q),
|
|
1199
|
+
t,
|
|
1200
|
+
format,
|
|
1201
|
+
size: viewport,
|
|
1202
|
+
supersampling: ss
|
|
1203
|
+
};
|
|
1204
|
+
} finally {
|
|
1205
|
+
await session.close();
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
async function renderVideo(opts) {
|
|
1209
|
+
const format = opts.format ?? "webm";
|
|
1210
|
+
const r = await renderMedia({
|
|
1211
|
+
projectDir: opts.projectDir,
|
|
1212
|
+
scene: opts.scene,
|
|
1213
|
+
out: `video.${format}`,
|
|
1214
|
+
format,
|
|
1215
|
+
size: opts.size,
|
|
1216
|
+
width: opts.width ?? 960,
|
|
1217
|
+
duration: opts.duration,
|
|
1218
|
+
fps: opts.fps,
|
|
1219
|
+
quality: opts.quality,
|
|
1220
|
+
write: false,
|
|
1221
|
+
timeoutMs: opts.timeoutMs,
|
|
1222
|
+
log: opts.log
|
|
1223
|
+
});
|
|
1224
|
+
return {
|
|
1225
|
+
bytes: r.data,
|
|
1226
|
+
frames: r.frames,
|
|
1227
|
+
fps: r.fps,
|
|
1228
|
+
duration: r.duration,
|
|
1229
|
+
size: {
|
|
1230
|
+
...r.size,
|
|
1231
|
+
deviceScaleFactor: 1
|
|
1232
|
+
},
|
|
1233
|
+
ms: r.ms,
|
|
1234
|
+
codec: r.codec
|
|
1235
|
+
};
|
|
1236
|
+
}
|
|
1237
|
+
var QUALITY_SS = {
|
|
1238
|
+
draft: 1,
|
|
1239
|
+
standard: 1,
|
|
1240
|
+
high: 2,
|
|
1241
|
+
ultra: 3
|
|
1242
|
+
};
|
|
1243
|
+
function parseQuality(q, fallback = "standard") {
|
|
1244
|
+
if (q === void 0) return fallback;
|
|
1245
|
+
if (q in QUALITY_SS) return q;
|
|
1246
|
+
throw new CliError("usage", `--quality must be draft, standard, high or ultra, got "${q}".`, "high = 2× supersampling, ultra = 3× (slower, smoother edges and fine detail).", 2);
|
|
1247
|
+
}
|
|
1248
|
+
function clampSs(ss, viewport) {
|
|
1249
|
+
const max = Math.floor(4096 / (Math.max(viewport.width, viewport.height) * viewport.deviceScaleFactor));
|
|
1250
|
+
return Math.max(1, Math.min(ss, max));
|
|
1251
|
+
}
|
|
1252
|
+
function mediaFormatFromPath(path) {
|
|
1253
|
+
const m = /\.(mp4|m4v|webm|gif|webp)$/i.exec(path);
|
|
1254
|
+
if (!m) return null;
|
|
1255
|
+
const ext = m[1].toLowerCase();
|
|
1256
|
+
return ext === "m4v" ? "mp4" : ext;
|
|
1257
|
+
}
|
|
1258
|
+
function sceneForRender(scene, opts) {
|
|
1259
|
+
if (!opts.transparent || scene.target?.transparent) return scene;
|
|
1260
|
+
return {
|
|
1261
|
+
...scene,
|
|
1262
|
+
target: {
|
|
1263
|
+
...scene.target,
|
|
1264
|
+
transparent: true
|
|
1265
|
+
}
|
|
1266
|
+
};
|
|
1267
|
+
}
|
|
1268
|
+
function scrollTime(scene, progress) {
|
|
1269
|
+
const tl = scene.timeline;
|
|
1270
|
+
const d = tl?.trigger === "scroll" && tl.duration > 0 ? tl.duration : 4;
|
|
1271
|
+
return Math.round(Math.min(Math.max(progress, 0), 1) * d * 1e3) / 1e3;
|
|
1272
|
+
}
|
|
1273
|
+
var even = (n) => n - n % 2;
|
|
1274
|
+
async function renderMedia(opts) {
|
|
1275
|
+
const t0 = Date.now();
|
|
1276
|
+
const format = opts.format ?? mediaFormatFromPath(opts.out);
|
|
1277
|
+
if (!format) throw new CliError("usage", `Unknown video / animation format for "${opts.out}".`, "Use a .mp4, .webm, .gif or .webp file name (or --format).", 2);
|
|
1278
|
+
const animated = format === "gif" || format === "webp";
|
|
1279
|
+
const scene = sceneForRender(opts.scene ?? readScene(opts.projectDir), { transparent: opts.transparent && animated });
|
|
1280
|
+
const fps = Math.max(1, Math.min(60, Math.round(opts.fps ?? (format === "gif" ? 15 : format === "webp" ? 20 : 30))));
|
|
1281
|
+
const duration = opts.duration ?? (scene.timeline?.duration && scene.timeline.duration > 0 ? scene.timeline.duration : 5);
|
|
1282
|
+
if (!(duration > 0) || duration > 300) throw new CliError("usage", "--duration must be between 0 and 300 seconds.", void 0, 2);
|
|
1283
|
+
const count = Math.max(1, Math.round(duration * fps));
|
|
1284
|
+
if (animated && count > 900) throw new CliError("usage", `${count} frames is too many for a ${format.toUpperCase()} (max 900).`, "Lower --fps or --duration, or render a video (.mp4 / .webm).", 2);
|
|
1285
|
+
const base = viewportFor(scene, {
|
|
1286
|
+
size: opts.size,
|
|
1287
|
+
width: opts.width ?? (format === "gif" ? 640 : format === "webp" ? 800 : 1280),
|
|
1288
|
+
scale: opts.scale ?? 1
|
|
1289
|
+
});
|
|
1290
|
+
const out = {
|
|
1291
|
+
width: even(Math.round(base.width * base.deviceScaleFactor)),
|
|
1292
|
+
height: even(Math.round(base.height * base.deviceScaleFactor))
|
|
1293
|
+
};
|
|
1294
|
+
const ss = clampSs(QUALITY_SS[opts.quality ?? "standard"], base);
|
|
1295
|
+
const viewport = {
|
|
1296
|
+
width: out.width / base.deviceScaleFactor,
|
|
1297
|
+
height: out.height / base.deviceScaleFactor,
|
|
1298
|
+
deviceScaleFactor: base.deviceScaleFactor * ss
|
|
1299
|
+
};
|
|
1300
|
+
const transparentScene = !!scene.target?.transparent;
|
|
1301
|
+
const bg = parseBg(opts.bg);
|
|
1302
|
+
const bgFill = bg && bg !== "none" ? bg : !animated && transparentScene ? "#ffffff" : void 0;
|
|
1303
|
+
const start = Math.max(0, opts.start ?? 0);
|
|
1304
|
+
const inputs = [...segmentInputs(opts.segment, start), ...opts.input ?? []].map((e, i) => ({
|
|
1305
|
+
e,
|
|
1306
|
+
i
|
|
1307
|
+
})).sort((a, b) => a.e.t - b.e.t || a.i - b.i).map((x) => x.e);
|
|
1308
|
+
checkInputsForScene(scene, inputs);
|
|
1309
|
+
if (opts.scroll !== void 0 && !(opts.scroll >= 0 && opts.scroll <= 1)) throw new CliError("usage", "--scroll must be a progress between 0 and 1.", void 0, 2);
|
|
1310
|
+
const session = await openRenderSession({
|
|
1311
|
+
projectDir: opts.projectDir,
|
|
1312
|
+
scene,
|
|
1313
|
+
viewport,
|
|
1314
|
+
reducedMotion: opts.reducedMotion,
|
|
1315
|
+
timeoutMs: opts.timeoutMs,
|
|
1316
|
+
log: opts.log
|
|
1317
|
+
});
|
|
1318
|
+
const cursor = {
|
|
1319
|
+
next: 0,
|
|
1320
|
+
warnings: []
|
|
1321
|
+
};
|
|
1322
|
+
const due = (t) => inputs.length ? applyInputsUpTo(session, inputs, cursor, t) : Promise.resolve();
|
|
1323
|
+
const progress = (i) => {
|
|
1324
|
+
if (i % Math.max(1, fps) === 0) opts.log?.(`[agent3d render] ${format} frame ${i + 1}/${count}`);
|
|
1325
|
+
};
|
|
1326
|
+
try {
|
|
1327
|
+
if (opts.scroll !== void 0) await session.setScroll(opts.scroll);
|
|
1328
|
+
let data;
|
|
1329
|
+
let codec;
|
|
1330
|
+
if (format === "gif") {
|
|
1331
|
+
const frames = [];
|
|
1332
|
+
for (let i = 0; i < count; i++) {
|
|
1333
|
+
await due(start + i / fps);
|
|
1334
|
+
const f = await session.grabRgba(start + i / fps, {
|
|
1335
|
+
ss,
|
|
1336
|
+
bg: bgFill
|
|
1337
|
+
});
|
|
1338
|
+
frames.push({ rgba: f.rgba });
|
|
1339
|
+
progress(i);
|
|
1340
|
+
}
|
|
1341
|
+
const { encodeGif } = await import("./gif-DQznzHTL.mjs");
|
|
1342
|
+
data = encodeGif(frames, {
|
|
1343
|
+
width: out.width,
|
|
1344
|
+
height: out.height,
|
|
1345
|
+
fps,
|
|
1346
|
+
loop: opts.loop ?? 0
|
|
1347
|
+
});
|
|
1348
|
+
codec = "gif";
|
|
1349
|
+
} else if (format === "webp") {
|
|
1350
|
+
const frames = [];
|
|
1351
|
+
for (let i = 0; i < count; i++) {
|
|
1352
|
+
await due(start + i / fps);
|
|
1353
|
+
frames.push(await session.grab(start + i / fps, {
|
|
1354
|
+
ss,
|
|
1355
|
+
bg: bgFill,
|
|
1356
|
+
type: "image/webp",
|
|
1357
|
+
quality: opts.quality === "ultra" || opts.quality === "high" ? .92 : .85
|
|
1358
|
+
}));
|
|
1359
|
+
progress(i);
|
|
1360
|
+
}
|
|
1361
|
+
const { muxAnimatedWebp } = await import("./webpAnim-qaq9YgKl.mjs");
|
|
1362
|
+
data = muxAnimatedWebp(frames, {
|
|
1363
|
+
fps,
|
|
1364
|
+
loop: opts.loop ?? 0
|
|
1365
|
+
});
|
|
1366
|
+
codec = "webp";
|
|
1367
|
+
} else {
|
|
1368
|
+
const { avcCodecFor, muxMp4 } = await import("./mp4-aOALfp3s.mjs");
|
|
1369
|
+
const candidates = format === "mp4" ? [
|
|
1370
|
+
avcCodecFor(out.width, out.height, fps),
|
|
1371
|
+
"avc1.640033",
|
|
1372
|
+
"avc1.4d0033",
|
|
1373
|
+
"avc1.42e033"
|
|
1374
|
+
] : [
|
|
1375
|
+
"vp09.00.40.08",
|
|
1376
|
+
"vp09.00.31.08",
|
|
1377
|
+
"vp8"
|
|
1378
|
+
];
|
|
1379
|
+
const chosen = await session.evaluate(`window.__agent3dVideoSupport(${JSON.stringify(candidates)}, ${out.width}, ${out.height}, ${fps})`);
|
|
1380
|
+
if (!chosen && format === "mp4") throw new CliError("video-unsupported", `This browser (${session.browser.name}) cannot encode H.264 at ${out.width}x${out.height} (WebCodecs).`, "Render a WebM instead (--video out.webm), use Google Chrome (AGENT3D_CHROME), or a smaller --size.");
|
|
1381
|
+
if (!chosen) {
|
|
1382
|
+
const frames = [];
|
|
1383
|
+
for (let i = 0; i < count; i++) {
|
|
1384
|
+
await due(start + i / fps);
|
|
1385
|
+
frames.push(webpToVp8(await session.grab(start + i / fps, {
|
|
1386
|
+
ss,
|
|
1387
|
+
bg: bgFill ?? "#000000",
|
|
1388
|
+
type: "image/webp",
|
|
1389
|
+
quality: .9
|
|
1390
|
+
})));
|
|
1391
|
+
progress(i);
|
|
1392
|
+
}
|
|
1393
|
+
data = muxWebm(frames, fps);
|
|
1394
|
+
codec = "vp8 (key frames)";
|
|
1395
|
+
} else {
|
|
1396
|
+
const pixels = out.width * out.height * fps;
|
|
1397
|
+
const bitrate = Math.round(opts.bitrate ?? Math.min(4e7, Math.max(1e6, pixels * (opts.quality === "ultra" ? .16 : opts.quality === "high" ? .12 : .08))));
|
|
1398
|
+
await session.evaluate(`window.__agent3dVideoStart(${JSON.stringify({
|
|
1399
|
+
codec: chosen,
|
|
1400
|
+
width: out.width,
|
|
1401
|
+
height: out.height,
|
|
1402
|
+
fps,
|
|
1403
|
+
bitrate,
|
|
1404
|
+
keyInterval: fps * 2,
|
|
1405
|
+
ss,
|
|
1406
|
+
bg: bgFill ?? (transparentScene ? "#000000" : void 0)
|
|
1407
|
+
})})`);
|
|
1408
|
+
const chunks = [];
|
|
1409
|
+
for (let i = 0; i < count; i++) {
|
|
1410
|
+
await due(start + i / fps);
|
|
1411
|
+
await session.evaluate(`window.__agent3dVideoFrame(${JSON.stringify(start + i / fps)}, ${i})`);
|
|
1412
|
+
if (i % 30 === 29) chunks.push(...await session.evaluate("window.__agent3dVideoDrain()") ?? []);
|
|
1413
|
+
progress(i);
|
|
1414
|
+
}
|
|
1415
|
+
const end = await session.evaluate("window.__agent3dVideoEnd()");
|
|
1416
|
+
if (end.error) throw new CliError("render-failed", `The video encoder failed: ${end.error}`, "Try a smaller --size, another --fps, or a .webm file.");
|
|
1417
|
+
chunks.push(...end.chunks);
|
|
1418
|
+
const encoded = chunks.map((c) => ({
|
|
1419
|
+
data: new Uint8Array(Buffer.from(c.b64, "base64")),
|
|
1420
|
+
key: c.key
|
|
1421
|
+
}));
|
|
1422
|
+
if (encoded.length !== count) throw new CliError("render-failed", `The encoder returned ${encoded.length} frames for ${count}.`, "Render again; if it persists, use a .webm file.");
|
|
1423
|
+
if (format === "mp4") {
|
|
1424
|
+
if (!end.description) throw new CliError("render-failed", "The H.264 encoder returned no decoder configuration (avcC).", "Use a .webm file.");
|
|
1425
|
+
data = muxMp4(encoded, {
|
|
1426
|
+
width: out.width,
|
|
1427
|
+
height: out.height,
|
|
1428
|
+
fps,
|
|
1429
|
+
avcC: new Uint8Array(Buffer.from(end.description, "base64"))
|
|
1430
|
+
});
|
|
1431
|
+
} else data = muxWebm(encoded.map((e) => ({
|
|
1432
|
+
...e,
|
|
1433
|
+
width: out.width,
|
|
1434
|
+
height: out.height
|
|
1435
|
+
})), fps, { codec: chosen.startsWith("vp09") ? "V_VP9" : "V_VP8" });
|
|
1436
|
+
codec = chosen;
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1439
|
+
if (opts.write !== false) {
|
|
1440
|
+
mkdirSync(join(opts.out, ".."), { recursive: true });
|
|
1441
|
+
writeFileSync(opts.out, data);
|
|
1442
|
+
}
|
|
1443
|
+
const state = inputs.length ? (await session.info()).state ?? null : void 0;
|
|
1444
|
+
return {
|
|
1445
|
+
path: opts.out,
|
|
1446
|
+
format,
|
|
1447
|
+
codec,
|
|
1448
|
+
frames: count,
|
|
1449
|
+
fps,
|
|
1450
|
+
duration,
|
|
1451
|
+
size: out,
|
|
1452
|
+
supersampling: ss,
|
|
1453
|
+
bytes: data.byteLength,
|
|
1454
|
+
ms: Date.now() - t0,
|
|
1455
|
+
...inputs.length ? {
|
|
1456
|
+
inputs: inputs.length,
|
|
1457
|
+
state
|
|
1458
|
+
} : {},
|
|
1459
|
+
...cursor.warnings.length ? { inputWarnings: cursor.warnings } : {},
|
|
1460
|
+
data
|
|
1461
|
+
};
|
|
1462
|
+
} finally {
|
|
1463
|
+
await session.close();
|
|
1464
|
+
}
|
|
1465
|
+
}
|
|
1466
|
+
async function renderExportImages(opts) {
|
|
1467
|
+
const scene = opts.scene ?? readScene(opts.projectDir);
|
|
1468
|
+
const base = viewportFor(scene, {
|
|
1469
|
+
width: opts.width ?? 1200,
|
|
1470
|
+
scale: 1
|
|
1471
|
+
});
|
|
1472
|
+
const ss = clampSs(2, base);
|
|
1473
|
+
const t = opts.time ?? scene.target?.posterTime ?? 0;
|
|
1474
|
+
const session = await openRenderSession({
|
|
1475
|
+
projectDir: opts.projectDir,
|
|
1476
|
+
scene,
|
|
1477
|
+
viewport: {
|
|
1478
|
+
...base,
|
|
1479
|
+
deviceScaleFactor: ss
|
|
1480
|
+
},
|
|
1481
|
+
timeoutMs: opts.timeoutMs,
|
|
1482
|
+
log: opts.log
|
|
1483
|
+
});
|
|
1484
|
+
try {
|
|
1485
|
+
const poster = await session.grab(t, {
|
|
1486
|
+
ss,
|
|
1487
|
+
type: "image/webp",
|
|
1488
|
+
quality: .86
|
|
1489
|
+
});
|
|
1490
|
+
let og;
|
|
1491
|
+
if (opts.og !== false) {
|
|
1492
|
+
const png = await session.grab(t, {
|
|
1493
|
+
ss,
|
|
1494
|
+
bg: scene.target?.transparent ? "#ffffff" : void 0
|
|
1495
|
+
});
|
|
1496
|
+
og = await session.social(png, 1200, 630);
|
|
1497
|
+
}
|
|
1498
|
+
return {
|
|
1499
|
+
poster,
|
|
1500
|
+
posterSize: {
|
|
1501
|
+
width: base.width,
|
|
1502
|
+
height: base.height
|
|
1503
|
+
},
|
|
1504
|
+
og,
|
|
1505
|
+
t
|
|
1506
|
+
};
|
|
1507
|
+
} finally {
|
|
1508
|
+
await session.close();
|
|
1509
|
+
}
|
|
1510
|
+
}
|
|
1511
|
+
export { INPUT_SHAPES, QUALITY_SS, applyInputsUpTo, checkInputsForScene, clampSs, frameBox, frameSuffix, frameTimes, inputCall, isolateScene, mediaFormatFromPath, openRenderSession, parseAspect, parseBg, parseInputScript, parseQuality, projectPath, renderExportImages, renderMedia, renderPoster, renderProject, renderVideo, sceneForRender, scrollTime, segmentInputs, timestamp, viewportFor };
|