threedog 0.5.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +276 -1
- package/README.md +18 -13
- package/core/{Animator.js → assets/Animator.js} +28 -18
- package/core/{Assets.js → assets/Assets.js} +116 -61
- package/core/{Baked.js → assets/Baked.js} +16 -25
- package/core/assets/assetEntry.js +237 -0
- package/core/{assetHot.js → assets/assetHot.js} +7 -6
- package/core/{assetLoad.js → assets/assetLoad.js} +66 -29
- package/core/assets/assetLod.js +113 -0
- package/core/{assetManifest.js → assets/assetManifest.js} +23 -12
- package/core/{assetReport.js → assets/assetReport.js} +9 -15
- package/core/{namedModel.js → assets/namedModel.js} +24 -16
- package/core/{Audio.js → audio/Audio.js} +27 -24
- package/core/{audioRules.js → audio/audioRules.js} +8 -5
- package/core/{audioVoice.js → audio/audioVoice.js} +17 -30
- package/core/{Events.js → base/Events.js} +3 -3
- package/core/{I18n.js → base/I18n.js} +10 -10
- package/core/{Random.js → base/Random.js} +5 -4
- package/core/{easing.js → base/easing.js} +1 -1
- package/core/{errorCodes.js → base/errorCodes.js} +154 -139
- package/core/{errorHints.js → base/errorHints.js} +9 -10
- package/core/{errors.js → base/errors.js} +9 -9
- package/core/{events.generated.js → base/events.generated.js} +2 -0
- package/core/{math.js → base/math.js} +22 -4
- package/core/{params.js → base/params.js} +3 -4
- package/core/base/util.js +32 -0
- package/core/{validate.js → base/validate.js} +29 -8
- package/core/{Engine.js → engine/Engine.js} +112 -105
- package/core/{Loading.js → engine/Loading.js} +4 -2
- package/core/{copies.js → engine/copies.js} +4 -4
- package/core/{headlessLoad.js → engine/headlessLoad.js} +4 -4
- package/core/{lifecycle.js → engine/lifecycle.js} +16 -16
- package/core/{loop.js → engine/loop.js} +80 -52
- package/core/{moduleSlots.js → engine/moduleSlots.js} +35 -10
- package/core/{moduleTypes.js → engine/moduleTypes.js} +30 -18
- package/core/{modules.js → engine/modules.js} +20 -17
- package/core/engine/page.js +125 -0
- package/core/{plugins.js → engine/plugins.js} +68 -103
- package/core/{services.js → engine/services.js} +47 -40
- package/core/{startup.js → engine/startup.js} +35 -35
- package/core/{Input.js → input/Input.js} +41 -27
- package/core/{inputContext.js → input/inputContext.js} +14 -5
- package/core/{inputPad.js → input/inputPad.js} +1 -1
- package/core/{inputPointer.js → input/inputPointer.js} +8 -2
- package/core/{inputTouch.js → input/inputTouch.js} +1 -1
- package/core/{Budget.js → inspect/Budget.js} +23 -22
- package/core/{DebugOverrides.js → inspect/DebugOverrides.js} +60 -31
- package/core/{Describe.js → inspect/Describe.js} +33 -30
- package/core/{Inspect.js → inspect/Inspect.js} +14 -9
- package/core/{InspectMaterials.js → inspect/InspectMaterials.js} +8 -10
- package/core/{InspectPerf.js → inspect/InspectPerf.js} +29 -16
- package/core/{InspectScene.js → inspect/InspectScene.js} +8 -5
- package/core/{MaterialInfo.js → inspect/MaterialInfo.js} +9 -6
- package/core/inspect/UrlState.js +182 -0
- package/core/{catalog.js → inspect/catalog.js} +18 -5
- package/core/{checks.js → inspect/checks.js} +7 -5
- package/core/{debugView.js → inspect/debugView.js} +8 -8
- package/core/inspect/describeRender.js +148 -0
- package/core/{describeText.js → inspect/describeText.js} +17 -12
- package/core/inspect/geometryWatch.js +38 -0
- package/core/{lightWatch.js → inspect/lightWatch.js} +11 -9
- package/core/inspect/pictureWriters.js +342 -0
- package/core/{shaderCost.js → inspect/shaderCost.js} +1 -1
- package/core/{Ops.js → ops/Ops.js} +16 -11
- package/core/{control.js → ops/control.js} +13 -12
- package/core/ops/holds.js +139 -0
- package/core/{opsAtomic.js → ops/opsAtomic.js} +2 -1
- package/core/{opsCheck.js → ops/opsCheck.js} +4 -5
- package/core/{opsGuard.js → ops/opsGuard.js} +3 -3
- package/core/{opsRun.js → ops/opsRun.js} +7 -4
- package/core/{owned.js → ops/owned.js} +37 -37
- package/core/{sharedPoint.js → ops/sharedPoint.js} +13 -27
- package/core/{stackFrames.js → ops/stackFrames.js} +17 -6
- package/core/{stacks.js → ops/stacks.js} +18 -20
- package/core/{wrap.js → ops/wrap.js} +8 -6
- package/core/{SaveStore.js → saves/SaveStore.js} +1 -1
- package/core/{Saves.js → saves/Saves.js} +58 -36
- package/core/{saveApply.js → saves/saveApply.js} +13 -9
- package/core/{saveFiles.js → saves/saveFiles.js} +17 -15
- package/core/{saveValues.js → saves/saveValues.js} +20 -3
- package/core/{saveVersions.js → saves/saveVersions.js} +4 -17
- package/core/{session.js → saves/session.js} +31 -17
- package/core/{Rays.js → scene/Rays.js} +27 -24
- package/core/{Views.js → scene/Views.js} +15 -6
- package/core/{adaptive.js → scene/adaptive.js} +15 -8
- package/core/{canvasBox.js → scene/canvasBox.js} +2 -3
- package/core/{engineCamera.js → scene/engineCamera.js} +1 -1
- package/core/{gameLights.js → scene/gameLights.js} +24 -7
- package/core/{grayMap.js → scene/grayMap.js} +8 -2
- package/core/{grid.js → scene/grid.js} +4 -4
- package/core/{gridLoad.js → scene/gridLoad.js} +1 -1
- package/core/{ground.js → scene/ground.js} +9 -9
- package/core/{movement.js → scene/movement.js} +3 -3
- package/core/scene/pictureSlots.js +33 -0
- package/core/{sceneDelta.js → scene/sceneDelta.js} +14 -6
- package/core/{sceneMethods.js → scene/sceneMethods.js} +36 -20
- package/core/scene/stepPoses.js +55 -0
- package/core/{targeting.js → scene/targeting.js} +4 -5
- package/core/{thingExplain.js → scene/thingExplain.js} +7 -6
- package/core/{thingOps.js → scene/thingOps.js} +4 -3
- package/core/{things.js → scene/things.js} +19 -6
- package/core/{threePatches.js → scene/threePatches.js} +1 -1
- package/core/{tier.js → scene/tier.js} +1 -1
- package/core/scene/view.js +44 -0
- package/core/{Batching.js → stream/Batching.js} +85 -27
- package/core/{Stream.js → stream/Stream.js} +62 -33
- package/core/{batchGroups.js → stream/batchGroups.js} +18 -9
- package/core/{chunkStream.js → stream/chunkStream.js} +41 -1
- package/core/{scatter.js → stream/scatter.js} +2 -2
- package/core/{streamSources.js → stream/streamSources.js} +12 -7
- package/core/{Commits.js → threads/Commits.js} +6 -5
- package/core/{Jobs.js → threads/Jobs.js} +12 -10
- package/core/{Threads.js → threads/Threads.js} +16 -16
- package/core/{threadPure.js → threads/threadPure.js} +7 -5
- package/core/{threadServe.js → threads/threadServe.js} +3 -3
- package/core/{Clock.js → time/Clock.js} +17 -10
- package/core/{dayTime.js → time/dayTime.js} +5 -1
- package/core/{skip.js → time/skip.js} +18 -17
- package/core/{time.js → time/time.js} +18 -12
- package/core/{uiClock.js → time/uiClock.js} +4 -4
- package/docs/AI.md +70 -63
- package/docs/API.md +30 -29
- package/docs/CODEMAP.md +98 -223
- package/docs/COMMANDS.md +80 -69
- package/docs/CONVENTIONS.md +87 -41
- package/docs/MIGRATING-0.7.md +39 -0
- package/docs/MIGRATING-0.8.md +169 -0
- package/docs/THREE.md +100 -49
- package/docs/api/assets.md +17 -16
- package/docs/api/audio.md +8 -7
- package/docs/api/budget.md +8 -4
- package/docs/api/calendar.md +10 -11
- package/docs/api/cameraRig.md +29 -29
- package/docs/api/characters.md +26 -19
- package/docs/api/clock.md +1 -1
- package/docs/api/collision.md +14 -11
- package/docs/api/content.md +6 -6
- package/docs/api/dialogue.md +3 -3
- package/docs/api/engine.md +82 -53
- package/docs/api/events.md +5 -3
- package/docs/api/flow.md +1 -1
- package/docs/api/grids.md +9 -2
- package/docs/api/ground.md +4 -5
- package/docs/api/hud.md +4 -1
- package/docs/api/i18n.md +6 -6
- package/docs/api/input.md +10 -9
- package/docs/api/interactions.md +6 -4
- package/docs/api/inventory.md +10 -11
- package/docs/api/jobs.md +5 -5
- package/docs/api/level.md +7 -8
- package/docs/api/lightPool.md +2 -7
- package/docs/api/music.md +3 -3
- package/docs/api/nav.md +10 -10
- package/docs/api/occlusion.md +5 -0
- package/docs/api/openWorld.md +1 -1
- package/docs/api/particles.md +8 -5
- package/docs/api/photo.md +4 -2
- package/docs/api/pickups.md +7 -1
- package/docs/api/post.md +24 -5
- package/docs/api/quests.md +3 -3
- package/docs/api/rays.md +5 -7
- package/docs/api/rigid.md +27 -18
- package/docs/api/saves.md +8 -7
- package/docs/api/settings.md +9 -8
- package/docs/api/sky.md +17 -14
- package/docs/api/stream.md +7 -7
- package/docs/api/swarm.md +34 -0
- package/docs/api/terrain.md +17 -12
- package/docs/api/terrainDraw.md +12 -0
- package/docs/api/timeline.md +2 -2
- package/docs/api/tools.md +30 -26
- package/docs/api/triggers.md +2 -0
- package/docs/api/vars.md +1 -1
- package/docs/api/vegetation.md +11 -5
- package/docs/api/vegetationDraw.md +10 -0
- package/docs/api/water.md +7 -3
- package/docs/api/weather.md +11 -6
- package/docs/api/weatherDraw.md +10 -0
- package/docs/api/world.md +6 -6
- package/docs/recipes/01-new-game.md +38 -57
- package/docs/recipes/02-npc.md +19 -20
- package/docs/recipes/03-items-pickups.md +47 -42
- package/docs/recipes/04-quests.md +3 -4
- package/docs/recipes/05-props-bake.md +72 -66
- package/docs/recipes/06-clock-events.md +30 -21
- package/docs/recipes/07-flow-scenes-pause.md +21 -17
- package/docs/recipes/08-weather-sky.md +117 -75
- package/docs/recipes/09-materials-lights-models.md +171 -0
- package/docs/recipes/10-blender-level.md +6 -7
- package/docs/recipes/11-vehicles.md +33 -25
- package/docs/recipes/12-navmesh.md +9 -8
- package/docs/recipes/13-animation.md +50 -22
- package/docs/recipes/14-custom-module.md +20 -17
- package/docs/recipes/15-perf.md +52 -29
- package/docs/recipes/16-dev-bridge.md +47 -57
- package/docs/recipes/18-world.md +45 -30
- package/docs/recipes/19-shooting-picking.md +11 -7
- package/docs/recipes/20-content-actions-save.md +36 -37
- package/docs/recipes/21-camera.md +41 -8
- package/docs/recipes/22-shop-gold.md +0 -4
- package/docs/recipes/23-ops.md +11 -11
- package/docs/recipes/26-ui-parts.md +56 -22
- package/docs/recipes/27-net.md +0 -2
- package/docs/recipes/28-terrain.md +126 -30
- package/docs/recipes/29-grid.md +16 -7
- package/docs/recipes/30-templates.md +62 -21
- package/docs/recipes/31-audio.md +9 -9
- package/docs/recipes/32-action-game.md +32 -9
- package/docs/recipes/33-stream-sources.md +2 -2
- package/docs/recipes/34-environment-lighting.md +164 -52
- package/docs/recipes/35-picture-from-reference.md +140 -0
- package/docs/recipes/36-ground-plants.md +105 -0
- package/docs/recipes/40-scene.md +105 -30
- package/docs/recipes/{43-shader-patches-surface-looks.md → 43-shader-patches-surfaces.md} +74 -106
- package/docs/recipes/44-water-weather-hooks.md +196 -0
- package/docs/recipes/45-cascaded-shadows.md +145 -25
- package/docs/recipes/46-blender-art-route.md +21 -25
- package/docs/recipes/49-game-module-contract.md +5 -5
- package/docs/recipes/50-own-renderer.md +3 -3
- package/docs/recipes/52-around-the-picture.md +137 -0
- package/docs/recipes/53-ground-up-close.md +65 -28
- package/docs/recipes/55-mods-time-wrap.md +25 -17
- package/docs/recipes/56-webgpu-tsl.md +73 -28
- package/docs/recipes/57-control.md +47 -1
- package/docs/recipes/58-input.md +3 -0
- package/docs/recipes/59-depth-post-effects.md +5 -5
- package/docs/recipes/60-judge-the-picture.md +47 -27
- package/docs/recipes/61-deploy.md +27 -0
- package/docs/recipes/62-picture-code.md +276 -0
- package/docs/recipes/63-third-person-start.md +90 -0
- package/docs/recipes/64-particles.md +35 -0
- package/docs/recipes/65-swarm.md +140 -0
- package/examples/action/.threedog/content-index.json +1 -1
- package/examples/action/GAMEMAP.md +9 -7
- package/examples/action/main.js +5 -4
- package/examples/action/models.js +12 -14
- package/examples/action/picture/index.js +13 -0
- package/examples/action/picture/lights.js +35 -0
- package/examples/action/picture/materials.js +8 -0
- package/examples/action/picture/palette.js +33 -0
- package/examples/perf-island/.threedog/content-index.json +1 -0
- package/examples/{sheepisland → perf-island}/GAMEMAP.md +18 -14
- package/examples/{sheepisland → perf-island}/assets.js +2 -2
- package/examples/{sheepisland → perf-island}/content/templates.js +1 -1
- package/examples/{sheepisland → perf-island}/content/vegetation.js +3 -1
- package/examples/{sheepisland → perf-island}/main.js +22 -16
- package/examples/{sheepisland/style → perf-island}/models.js +13 -24
- package/examples/{sheepisland → perf-island}/params.js +1 -1
- package/examples/perf-island/picture/index.js +20 -0
- package/examples/perf-island/picture/lights.js +34 -0
- package/examples/perf-island/picture/materials.js +61 -0
- package/examples/perf-island/picture/palette.js +60 -0
- package/examples/perf-island/picture/sky.js +20 -0
- package/examples/{sheepisland → perf-island}/views.js +1 -1
- package/examples/plain-picture/.threedog/content-index.json +1 -0
- package/examples/plain-picture/GAMEMAP.md +91 -0
- package/examples/plain-picture/main.js +48 -0
- package/examples/plain-picture/picture/index.js +21 -0
- package/examples/plain-picture/picture/lights.js +54 -0
- package/examples/plain-picture/picture/materials.js +24 -0
- package/examples/plain-picture/picture/palette.js +16 -0
- package/examples/plain-picture/picture/sky.js +37 -0
- package/examples/pullable.json +31 -9
- package/examples/rc2d/GAMEMAP.md +10 -4
- package/examples/rc2d/README.md +11 -6
- package/examples/rc2d/main.js +26 -36
- package/examples/rc2d/picture/index.js +18 -0
- package/examples/rc2d/picture/lights.js +11 -0
- package/examples/rc2d/picture/materials.js +18 -0
- package/examples/rc2d/picture/palette.js +15 -0
- package/examples/rc2d/picture/post.js +11 -0
- package/examples/rc2d/rc2d.js +18 -28
- package/examples/styletest/.threedog/content-index.json +1 -1
- package/examples/styletest/GAMEMAP.md +15 -10
- package/examples/styletest/main.js +20 -30
- package/examples/styletest/models.js +29 -29
- package/examples/styletest/params.js +1 -4
- package/examples/styletest/picture/env.js +38 -0
- package/examples/styletest/picture/index.js +16 -0
- package/examples/styletest/picture/lights.js +9 -0
- package/examples/styletest/picture/materials.js +28 -0
- package/examples/styletest/picture/palette.js +22 -0
- package/examples/techniques/contact-shadows/README.md +22 -23
- package/examples/techniques/contact-shadows/contactShadows.js +32 -16
- package/examples/techniques/contact-shadows/main.js +20 -18
- package/examples/techniques/contact-shadows/picture/index.js +14 -0
- package/examples/techniques/contact-shadows/picture/lights.js +34 -0
- package/examples/techniques/contact-shadows/picture/materials.js +12 -0
- package/examples/techniques/contact-shadows/picture/palette.js +17 -0
- package/examples/techniques/day-night-grade/README.md +13 -16
- package/examples/techniques/day-night-grade/main.js +15 -25
- package/examples/techniques/day-night-grade/picture/index.js +20 -0
- package/examples/techniques/day-night-grade/picture/lights.js +45 -0
- package/examples/techniques/day-night-grade/picture/materials.js +15 -0
- package/examples/techniques/day-night-grade/picture/palette.js +59 -0
- package/examples/techniques/day-night-grade/picture/post.js +25 -0
- package/examples/techniques/day-night-grade/picture/sky.js +33 -0
- package/examples/techniques/interior-light/README.md +16 -13
- package/examples/techniques/interior-light/interiorLight.js +19 -17
- package/examples/techniques/interior-light/main.js +31 -68
- package/examples/techniques/interior-light/picture/index.js +24 -0
- package/examples/techniques/interior-light/picture/lights.js +52 -0
- package/examples/techniques/interior-light/picture/materials.js +13 -0
- package/examples/techniques/interior-light/picture/palette.js +32 -0
- package/examples/techniques/interior-light/picture/sky.js +40 -0
- package/examples/techniques/modular-building/README.md +8 -6
- package/examples/techniques/modular-building/kit.js +2 -2
- package/examples/techniques/modular-building/main.js +9 -17
- package/examples/techniques/modular-building/picture/index.js +17 -0
- package/examples/techniques/modular-building/picture/lights.js +26 -0
- package/examples/techniques/modular-building/picture/materials.js +13 -0
- package/examples/techniques/modular-building/picture/palette.js +23 -0
- package/examples/techniques/night-lights/README.md +15 -14
- package/examples/techniques/night-lights/main.js +20 -43
- package/examples/techniques/night-lights/nightLights.js +25 -21
- package/examples/techniques/night-lights/picture/index.js +18 -0
- package/examples/techniques/night-lights/picture/lights.js +44 -0
- package/examples/techniques/night-lights/picture/materials.js +15 -0
- package/examples/techniques/night-lights/picture/palette.js +34 -0
- package/examples/techniques/night-lights/picture/post.js +9 -0
- package/examples/techniques/night-lights/picture/sky.js +36 -0
- package/examples/techniques/outlines-and-rim/README.md +2 -2
- package/examples/techniques/outlines-and-rim/main.js +15 -38
- package/examples/techniques/outlines-and-rim/outlines.js +3 -3
- package/examples/techniques/outlines-and-rim/picture/index.js +16 -0
- package/examples/techniques/outlines-and-rim/picture/lights.js +18 -0
- package/examples/techniques/outlines-and-rim/picture/materials.js +11 -0
- package/examples/techniques/outlines-and-rim/picture/palette.js +16 -0
- package/examples/techniques/outlines-and-rim/picture/post.js +10 -0
- package/examples/techniques/procedural-animation/README.md +6 -4
- package/examples/techniques/procedural-animation/main.js +9 -7
- package/examples/techniques/procedural-animation/picture/index.js +15 -0
- package/examples/techniques/procedural-animation/picture/lights.js +35 -0
- package/examples/techniques/procedural-animation/picture/materials.js +10 -0
- package/examples/techniques/procedural-animation/picture/palette.js +16 -0
- package/examples/techniques/procedural-animation/picture/sky.js +31 -0
- package/examples/techniques/procedural-animation/proceduralAnim.js +1 -1
- package/examples/techniques/procedural-surface/README.md +2 -0
- package/examples/techniques/procedural-surface/main.js +17 -55
- package/examples/techniques/procedural-surface/picture/index.js +14 -0
- package/examples/techniques/procedural-surface/picture/lights.js +18 -0
- package/examples/techniques/procedural-surface/picture/materials.js +34 -0
- package/examples/techniques/procedural-surface/picture/palette.js +15 -0
- package/examples/techniques/stylized-shading/README.md +13 -14
- package/examples/techniques/stylized-shading/main.js +11 -42
- package/examples/techniques/stylized-shading/picture/index.js +14 -0
- package/examples/techniques/stylized-shading/picture/lights.js +23 -0
- package/examples/techniques/stylized-shading/picture/materials.js +18 -0
- package/examples/techniques/stylized-shading/picture/palette.js +19 -0
- package/examples/techniques/stylized-shading/shading.js +2 -2
- package/examples/techniques/sun-and-key-light/README.md +20 -22
- package/examples/techniques/sun-and-key-light/keyLight.js +47 -29
- package/examples/techniques/sun-and-key-light/main.js +19 -63
- package/examples/techniques/sun-and-key-light/picture/index.js +13 -0
- package/examples/techniques/sun-and-key-light/picture/lights.js +33 -0
- package/examples/techniques/sun-and-key-light/picture/materials.js +9 -0
- package/examples/techniques/sun-and-key-light/picture/palette.js +29 -0
- package/examples/techniques/sun-and-key-light/picture/sky.js +16 -0
- package/examples/techniques/three-looks/README.md +21 -0
- package/examples/techniques/three-looks/main.js +58 -0
- package/examples/techniques/three-looks/picture/cartoon.js +23 -0
- package/examples/techniques/three-looks/picture/cinematic.js +27 -0
- package/examples/techniques/three-looks/picture/comic.js +27 -0
- package/examples/techniques/three-looks/picture/index.js +14 -0
- package/examples/techniques/three-looks/picture/sun.js +23 -0
- package/examples/techniques/wet-road/README.md +7 -4
- package/examples/techniques/wet-road/main.js +18 -38
- package/examples/techniques/wet-road/picture/index.js +17 -0
- package/examples/techniques/wet-road/picture/lights.js +57 -0
- package/examples/techniques/wet-road/picture/materials.js +16 -0
- package/examples/techniques/wet-road/picture/palette.js +24 -0
- package/examples/techniques/wet-road/picture/sky.js +46 -0
- package/examples/webgpu-tsl/GAMEMAP.md +10 -4
- package/examples/webgpu-tsl/README.md +13 -10
- package/examples/webgpu-tsl/main.js +30 -7
- package/examples/webgpu-tsl/picture/index.js +18 -0
- package/examples/webgpu-tsl/picture/lights.js +25 -0
- package/examples/webgpu-tsl/picture/materials.js +36 -0
- package/examples/webgpu-tsl/picture/palette.js +23 -0
- package/examples/webgpu-tsl/picture/post.js +16 -0
- package/examples/webgpu-tsl/picture/sky.js +30 -0
- package/examples/world/.threedog/content-index.json +1 -1
- package/examples/world/GAMEMAP.md +16 -12
- package/examples/world/art/humanoid.js +9 -13
- package/examples/world/art/index.js +2 -2
- package/examples/world/art/models.js +3 -4
- package/examples/world/art/shapes.js +2 -2
- package/examples/world/assets.js +2 -2
- package/examples/world/content/audio.js +1 -1
- package/examples/world/content/items.js +1 -1
- package/examples/world/content/props.js +1 -1
- package/examples/world/content/templates.js +1 -1
- package/examples/world/content/vegetation.js +1 -1
- package/examples/world/main.js +10 -10
- package/examples/world/models.js +17 -7
- package/examples/world/picture/index.js +20 -0
- package/examples/world/picture/lights.js +41 -0
- package/examples/world/picture/materials.js +34 -0
- package/examples/world/picture/palette.js +74 -0
- package/examples/world/picture/post.js +9 -0
- package/examples/world/picture/sky.js +39 -0
- package/index.d.ts +14 -22
- package/index.js +36 -36
- package/llms.txt +19 -21
- package/modules/ambience/Ambience.js +12 -9
- package/modules/calendar/Calendar.js +20 -20
- package/modules/calendar/index.js +14 -13
- package/modules/calendar/schedule.js +11 -6
- package/modules/calendar/seasons.js +7 -7
- package/modules/camera/FirstPersonCamera.js +2 -2
- package/modules/camera/FixedCamera.js +14 -15
- package/modules/camera/FollowCamera.js +4 -4
- package/modules/camera/RtsCamera.js +11 -11
- package/modules/camera/common.js +51 -25
- package/modules/camera/contract.js +1 -0
- package/modules/camera/projection.js +2 -2
- package/modules/characters/Character.js +47 -39
- package/modules/characters/NPC.js +30 -22
- package/modules/characters/assetModel.js +18 -13
- package/modules/characters/astar.js +7 -5
- package/modules/characters/behaviors.js +4 -5
- package/modules/characters/contract.js +2 -2
- package/modules/characters/index.js +172 -193
- package/modules/characters/moveHelpers.js +14 -3
- package/modules/characters/movers/common.js +22 -15
- package/modules/characters/movers/manual.js +4 -1
- package/modules/characters/movers/rapier.js +7 -6
- package/modules/characters/movers/simple.js +3 -3
- package/modules/characters/movers/support.js +32 -18
- package/modules/characters/npcAvoid.js +4 -4
- package/modules/characters/npcSim.js +28 -18
- package/modules/characters/npcView.js +6 -5
- package/modules/characters/pathAsync.js +12 -10
- package/modules/characters/pathWorker.js +1 -1
- package/modules/characters/player.js +108 -0
- package/modules/characters/playerStrings.js +2 -2
- package/modules/characters/proceduralRig.js +19 -5
- package/modules/characters/useModel.js +5 -5
- package/modules/characters/walkTo.js +11 -17
- package/modules/collision/Collision.js +30 -22
- package/modules/collision/contract.js +15 -0
- package/modules/content/explain.js +1 -2
- package/modules/content/fields.js +24 -3
- package/modules/content/ids.js +2 -2
- package/modules/content/index.js +68 -98
- package/modules/content/loader.js +14 -17
- package/modules/content/markers.js +25 -0
- package/modules/content/models.js +66 -18
- package/modules/content/packs.js +3 -3
- package/modules/content/parts.js +2 -2
- package/modules/content/places.js +35 -0
- package/modules/content/props.js +19 -14
- package/modules/content/rules.js +34 -22
- package/modules/content/stages.js +7 -7
- package/modules/content/templates.js +24 -22
- package/modules/content/words.js +34 -0
- package/modules/debug/DebugPanel.js +10 -43
- package/modules/flow/contract.js +1 -1
- package/modules/flow/index.js +11 -7
- package/modules/gameplay/Container.js +12 -11
- package/modules/gameplay/Containers.js +14 -5
- package/modules/gameplay/Dialogue.js +13 -11
- package/modules/gameplay/Interactions.js +115 -27
- package/modules/gameplay/Inventory.js +11 -12
- package/modules/gameplay/Quests.js +16 -9
- package/modules/gameplay/boxOps.js +1 -1
- package/modules/gameplay/dialogueBox.js +1 -1
- package/modules/gameplay/dialogueBubbles.js +4 -5
- package/modules/gameplay/interactionPrompt.js +1 -1
- package/modules/gameplay/interactions.contract.js +1 -1
- package/modules/gameplay/inventoryOps.js +2 -3
- package/modules/gameplay/pickups.js +81 -44
- package/modules/gameplay/questLog.js +2 -2
- package/modules/gameplay/questSave.js +3 -3
- package/modules/grid/Grid.js +1 -1
- package/modules/grid/Layer.js +16 -3
- package/modules/grid/index.js +47 -19
- package/modules/grid/preview.js +29 -20
- package/modules/grid/tiles.js +19 -23
- package/modules/hlod/index.js +38 -55
- package/modules/hud/index.js +27 -8
- package/modules/hud/parts.js +13 -11
- package/modules/level/contract.js +16 -0
- package/modules/level/heightfield.js +12 -10
- package/modules/level/index.js +48 -152
- package/modules/level/load.js +79 -0
- package/modules/level/meshes.js +65 -0
- package/modules/level/nodes.js +6 -7
- package/modules/lights/index.js +34 -183
- package/modules/lights/slots.js +93 -0
- package/modules/lights/sources.js +88 -0
- package/modules/music/Music.js +31 -27
- package/modules/music/rules.js +1 -1
- package/modules/nav/contract.js +14 -0
- package/modules/nav/index.js +11 -10
- package/modules/net/Client.js +7 -7
- package/modules/net/Host.js +7 -7
- package/modules/net/Net.js +1 -1
- package/modules/net/index.js +5 -4
- package/modules/net/sync.js +2 -2
- package/modules/net/transports.js +2 -2
- package/modules/particles/Particles.js +49 -25
- package/modules/particles/effect.js +27 -10
- package/modules/particles/shaders.js +2 -1
- package/modules/photo/Photo.js +26 -27
- package/modules/rigid/RigidBodies.js +66 -43
- package/modules/rigid/Vehicles.js +2 -3
- package/modules/rigid/ragdoll.js +287 -0
- package/modules/rigid/ragdollBones.js +159 -0
- package/modules/rigid/sync.js +6 -6
- package/modules/settings/Settings.js +114 -45
- package/modules/settings/apply.js +10 -10
- package/modules/settings/sections.js +16 -14
- package/modules/settings/strings.js +1 -1
- package/modules/settings/view.js +3 -3
- package/modules/sky/Sky.js +125 -103
- package/modules/sky/clouds.js +22 -23
- package/modules/sky/dome.js +113 -0
- package/modules/sky/domeLayers.js +13 -13
- package/modules/sky/environment.js +47 -171
- package/modules/sky/fog.js +5 -180
- package/modules/sky/frame.js +42 -97
- package/modules/sky/season.js +9 -3
- package/modules/sky/shader.js +49 -44
- package/modules/sky/skyModule.js +25 -35
- package/modules/sky/tint.js +9 -11
- package/modules/swarm/Swarm.js +346 -0
- package/modules/swarm/draw.js +68 -0
- package/modules/swarm/grid.js +63 -0
- package/modules/terrain/ChunkManager.js +97 -62
- package/modules/terrain/chunkQueries.js +7 -24
- package/modules/terrain/chunkWorker.js +1 -1
- package/modules/terrain/draw.js +157 -0
- package/modules/terrain/index.js +60 -88
- package/modules/terrain/terrainColorMap.js +6 -3
- package/modules/terrain/terrainDefaults.js +4 -3
- package/modules/terrain/terrainEdit.js +32 -27
- package/modules/terrain/terrainGen.js +19 -14
- package/modules/terrain/terrainIsland.js +2 -2
- package/modules/terrain/terrainMesh.js +7 -6
- package/modules/terrain/terrainShape.js +8 -10
- package/modules/terrain/terrainShapeMain.js +3 -3
- package/modules/timeline/Timeline.js +27 -19
- package/modules/timeline/Tween.js +6 -6
- package/modules/timeline/shots.js +5 -7
- package/modules/triggers/index.js +19 -15
- package/modules/vegetation/Vegetation.js +87 -39
- package/modules/vegetation/densityMap.js +4 -7
- package/modules/vegetation/draw.js +196 -0
- package/modules/vegetation/groundChunks.js +11 -31
- package/modules/vegetation/index.js +18 -16
- package/modules/vegetation/modelGeometry.js +3 -6
- package/modules/vegetation/nearFade.js +1 -1
- package/modules/water/Water.js +140 -93
- package/modules/water/surface.js +56 -56
- package/modules/weather/Weather.js +84 -38
- package/modules/weather/particles.js +18 -10
- package/modules/weather/shaders.js +1 -1
- package/modules/weather/weatherDraw.js +145 -0
- package/modules/world/World.js +10 -10
- package/modules/world/explain.js +1 -1
- package/modules/world/index.js +18 -12
- package/modules/world/persist.js +73 -25
- package/modules/world/pos.js +4 -4
- package/modules/world/records.js +28 -8
- package/modules/world/sim.js +4 -4
- package/modules/world/state.js +12 -5
- package/modules/world/thingSource.js +4 -2
- package/modules/world/views.js +12 -10
- package/package.json +44 -8
- package/presets.js +3 -5
- package/render/PostFX.js +233 -63
- package/render/backend.js +72 -32
- package/render/cascades.js +200 -0
- package/render/cascades.tsl.js +93 -0
- package/render/daylight.js +56 -0
- package/render/detail.js +13 -12
- package/render/effects.js +60 -42
- package/render/fuse.js +3 -3
- package/render/fx/cel.tsl.js +42 -0
- package/render/fx/cloudShadow.tsl.js +3 -3
- package/render/fx/detail.tsl.js +1 -1
- package/render/fx/index.js +10 -13
- package/render/fx/library.tsl.js +11 -0
- package/render/fx/lighting.tsl.js +2 -1
- package/render/fx/nodeErrors.tsl.js +2 -2
- package/render/fx/objectOrigin.tsl.js +1 -2
- package/render/fx/patchNodes.tsl.js +6 -16
- package/render/fx/postWebGPU.tsl.js +55 -28
- package/render/fx/sky.tsl.js +34 -109
- package/render/fx/uniforms.tsl.js +4 -4
- package/render/fx/water.tsl.js +1 -1
- package/render/fx/wind.tsl.js +1 -1
- package/render/fxNumbers.js +3 -0
- package/render/layers.js +14 -0
- package/render/lighting.js +11 -8
- package/render/lightmap.js +142 -0
- package/render/lights.js +26 -204
- package/render/lit.js +24 -0
- package/render/materials.js +47 -162
- package/render/mergeCommon.js +22 -0
- package/render/modeling.js +2 -2
- package/render/neutral.js +23 -0
- package/render/occlusion.js +200 -0
- package/render/ownFrame.js +5 -5
- package/render/patches.js +46 -41
- package/render/postWebGL.js +19 -9
- package/render/probes.js +182 -128
- package/render/recordSweep.js +117 -0
- package/render/shaderErrors.js +10 -9
- package/render/shadowCache.tsl.js +107 -0
- package/render/shadowTypes.js +9 -0
- package/render/shadows.js +451 -0
- package/render/slots.js +11 -11
- package/render/terms.js +63 -113
- package/render/uniformDecl.js +2 -2
- package/types/core.d.ts +489 -405
- package/types/gameplay.d.ts +225 -114
- package/types/generated/core/{Audio.d.ts → audio/Audio.d.ts} +23 -8
- package/types/generated/core/{audioVoice.d.ts → audio/audioVoice.d.ts} +2 -2
- package/types/generated/core/{Events.d.ts → base/Events.d.ts} +4 -4
- package/types/generated/core/{I18n.d.ts → base/I18n.d.ts} +7 -15
- package/types/generated/core/{Random.d.ts → base/Random.d.ts} +4 -3
- package/types/generated/core/engine/page.d.ts +24 -0
- package/types/generated/core/{Input.d.ts → input/Input.d.ts} +21 -10
- package/types/generated/core/{Budget.d.ts → inspect/Budget.d.ts} +36 -26
- package/types/generated/core/{DebugOverrides.d.ts → inspect/DebugOverrides.d.ts} +16 -8
- package/types/generated/core/{Ops.d.ts → ops/Ops.d.ts} +4 -3
- package/types/generated/core/{control.d.ts → ops/control.d.ts} +4 -10
- package/types/generated/core/{Saves.d.ts → saves/Saves.d.ts} +37 -13
- package/types/generated/core/{session.d.ts → saves/session.d.ts} +2 -1
- package/types/generated/core/{Rays.d.ts → scene/Rays.d.ts} +8 -27
- package/types/generated/core/{Views.d.ts → scene/Views.d.ts} +1 -1
- package/types/generated/core/{Batching.d.ts → stream/Batching.d.ts} +7 -7
- package/types/generated/core/{Stream.d.ts → stream/Stream.d.ts} +18 -16
- package/types/generated/core/{Commits.d.ts → threads/Commits.d.ts} +1 -1
- package/types/generated/core/{Jobs.d.ts → threads/Jobs.d.ts} +6 -6
- package/types/generated/core/{Threads.d.ts → threads/Threads.d.ts} +4 -4
- package/types/generated/modules/calendar/Calendar.d.ts +10 -11
- package/types/generated/modules/debug/DebugPanel.d.ts +1 -9
- package/types/generated/modules/grid/Layer.d.ts +9 -1
- package/types/generated/modules/grid/index.d.ts +32 -8
- package/types/generated/modules/music/Music.d.ts +7 -5
- package/types/generated/modules/particles/Particles.d.ts +14 -7
- package/types/generated/modules/sky/Sky.d.ts +101 -23
- package/types/generated/modules/sky/skyModule.d.ts +1 -1
- package/types/generated/modules/swarm/Swarm.d.ts +80 -0
- package/types/generated/modules/timeline/Timeline.d.ts +2 -1
- package/types/generated/modules/water/Water.d.ts +51 -3
- package/types/generated/modules/weather/Weather.d.ts +44 -10
- package/types/generated/modules/weather/weatherDraw.d.ts +11 -0
- package/types/generated/modules/world/World.d.ts +7 -5
- package/types/generated/render/PostFX.d.ts +69 -20
- package/types/generated/render/lighting.d.ts +29 -0
- package/types/generated/render/materials.d.ts +20 -44
- package/types/generated/render/occlusion.d.ts +22 -0
- package/types/generated/render/patches.d.ts +1 -0
- package/types/generated/ui/Focus.d.ts +1 -0
- package/types/generated/ui/UI.d.ts +1 -0
- package/types/nav.d.ts +11 -11
- package/types/physics.d.ts +104 -73
- package/types/tsl.d.ts +45 -4
- package/types/world.d.ts +372 -86
- package/ui/Focus.js +21 -10
- package/ui/LoadingScreen.js +2 -2
- package/ui/Parts.js +12 -7
- package/ui/UI.js +17 -17
- package/ui/cursor.js +1 -1
- package/ui/defaults.js +3 -2
- package/ui/theme.js +36 -28
- package/ui/touchPart.js +1 -1
- package/core/UrlState.js +0 -110
- package/core/assetEntry.js +0 -106
- package/core/describeRender.js +0 -71
- package/core/holds.js +0 -134
- package/core/look/coreParts.js +0 -219
- package/core/look/part.js +0 -253
- package/core/look/points.js +0 -255
- package/core/look/report.js +0 -96
- package/core/look/shadowPart.js +0 -63
- package/core/look/state.js +0 -45
- package/core/look/write.js +0 -70
- package/core/page.js +0 -79
- package/core/shadowTypes.js +0 -16
- package/core/styleParts.js +0 -114
- package/core/util.js +0 -17
- package/docs/MIGRATING-0.3.md +0 -248
- package/docs/MIGRATING-0.4.md +0 -228
- package/docs/MIGRATING-0.5.md +0 -68
- package/docs/PERF.md +0 -245
- package/docs/api/style.md +0 -136
- package/docs/api/terrainLook.md +0 -10
- package/docs/api/vegetationLook.md +0 -10
- package/docs/api/weatherLook.md +0 -10
- package/docs/recipes/09-style.md +0 -218
- package/docs/recipes/35-style-from-reference.md +0 -153
- package/docs/recipes/36-sky-ground-plant-looks.md +0 -118
- package/docs/recipes/37-terrain-look-hooks.md +0 -119
- package/docs/recipes/38-environment-look-hooks.md +0 -99
- package/docs/recipes/41-thing-registry.md +0 -97
- package/docs/recipes/42-terrain-shape.md +0 -64
- package/docs/recipes/44-water-weather-look-hooks.md +0 -144
- package/docs/recipes/47-island-snow-backdrop.md +0 -45
- package/docs/recipes/48-make-material.md +0 -75
- package/docs/recipes/52-look.md +0 -282
- package/docs/recipes/54-three-idioms.md +0 -88
- package/examples/action/look.js +0 -5
- package/examples/sheepisland/.threedog/content-index.json +0 -1
- package/examples/sheepisland/style/index.js +0 -79
- package/examples/styletest/look.js +0 -11
- package/examples/techniques/day-night-grade/dayNightGrade.js +0 -76
- package/examples/webgpu-tsl/tslScene.js +0 -75
- package/examples/world/style/index.js +0 -61
- package/examples/world/style/plugins/10-bloom.js +0 -5
- package/modules/sky/cascades.js +0 -186
- package/modules/sky/cascades.tsl.js +0 -82
- package/modules/sky/look.js +0 -54
- package/modules/sky/lookFog.js +0 -76
- package/modules/sky/lookShadow.js +0 -62
- package/modules/sky/lookSky.js +0 -169
- package/modules/sky/shadow.js +0 -98
- package/modules/terrain/look.js +0 -83
- package/modules/terrain/lookGround.js +0 -66
- package/modules/vegetation/look.js +0 -119
- package/modules/vegetation/lookWind.js +0 -98
- package/modules/water/look.js +0 -91
- package/modules/water/surfaceDefaults.js +0 -3
- package/modules/weather/look.js +0 -74
- package/modules/weather/weatherLook.js +0 -135
- package/render/lookGlow.js +0 -139
- package/render/lookSurface.js +0 -224
- package/render/postLook.js +0 -164
- package/render/surface.js +0 -105
- package/types/generated/core/page.d.ts +0 -18
- package/types/generated/modules/weather/weatherLook.d.ts +0 -12
- package/types/style.d.ts +0 -671
- /package/core/{Vars.js → base/Vars.js} +0 -0
- /package/core/{mulberry32.js → base/mulberry32.js} +0 -0
- /package/core/{inputDefaults.js → input/inputDefaults.js} +0 -0
- /package/core/{textureBytes.js → inspect/textureBytes.js} +0 -0
- /package/core/{actor.js → ops/actor.js} +0 -0
- /package/core/{opsFail.js → ops/opsFail.js} +0 -0
- /package/core/{opsHistory.js → ops/opsHistory.js} +0 -0
- /package/core/{saveIds.js → saves/saveIds.js} +0 -0
- /package/core/{screenToGround.js → scene/screenToGround.js} +0 -0
- /package/core/{cells.js → stream/cells.js} +0 -0
- /package/core/{streamCells.js → stream/streamCells.js} +0 -0
- /package/core/{pureWorker.js → threads/pureWorker.js} +0 -0
- /package/examples/{sheepisland → perf-island}/content/index.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/props.js +0 -0
package/docs/THREE.md
CHANGED
|
@@ -2,30 +2,58 @@
|
|
|
2
2
|
|
|
3
3
|
The scene, camera, lights, characters and models in the engine are **plain three.js objects** (three 0.187). Write the three.js you already
|
|
4
4
|
know: what the engine can see, it plugs in with no extra call. Only where it cannot know your intent do you write one line.
|
|
5
|
-
|
|
6
|
-
This is the one place that order is stated: a material is `new THREE.*Material` / `ShaderMaterial` before a slot patch
|
|
7
|
-
pass is a three.js Pass (`engine.
|
|
5
|
+
Picture work (materials, shaders, textures, lights, post passes) always take this route first; engine picture features are optional conveniences on top.
|
|
6
|
+
This is the one place that order is stated: a material is `new THREE.*Material` / `ShaderMaterial` before a slot patch, a post
|
|
7
|
+
pass is a three.js Pass (`engine.post.add(pass)`) before a ready-made effect.
|
|
8
8
|
|
|
9
9
|
| You write (plain three.js) | The engine does | The one line, only when you mean it |
|
|
10
10
|
|---|---|---|
|
|
11
11
|
| `engine.scene.add(obj)` / `group.add(obj)` | registers each root under the scene like `engine.add`: `engine.thing`, `describe().scene`, `thing.set` / `thing.remove` | a stable id so a save finds it: `engine.add(obj, { id: 'mill' })` |
|
|
12
|
-
| `new THREE.PointLight(...)` / `SpotLight` added to the scene | a real light, adopted as a thing; counted by `engine.budget` `lights` / `shadowLights`, listed in `describe().render.lights`; a casting light at intensity 0 stops redrawing its shadow map; weather and day-night leave its values alone | many sources, few real lights: `lightPool` (recipe
|
|
12
|
+
| `new THREE.PointLight(...)` / `SpotLight` added to the scene | a real light, adopted as a thing; counted by `engine.budget` `lights` / `shadowLights`, listed in `describe().render.lights`; a casting light at intensity 0 stops redrawing its shadow map; weather and day-night leave its values alone | many sources, few real lights: `lightPool` (recipe 09) |
|
|
13
13
|
| `new THREE.MeshStandardMaterial(...)` | scene fog (height fog too), cascaded shadows | wind sway: `applyEffects(mat, { wind: 0.03 })` |
|
|
14
|
-
| `engine.
|
|
14
|
+
| `engine.post.add(pass)`, the one way into the chain (the other renderer's form: recipe 56) | slots it after the scene render and before tone mapping (FXAA / SMAA last), or after tone mapping when you added it after an OutputPass; a pass that renders `engine.scene` itself (RenderPixelatedPass, SSAA, TAA) replaces the scene render, so the scene is drawn once; skips a RenderPass / OutputPass it already has; listed in `post.list()`; `remove()` leaves it undisposed | a settings name and position: `add(pass, { name: 'glow', order })`, then `engine.post.get('glow').enabled = false` |
|
|
15
15
|
| your own `EffectComposer` / `renderer.render` of the whole canvas, every frame | yields the frame (stops drawing its own, warns once `[own-frame]`); delete your render call to hand it back. A minimap / HUD layer on top (scissor, smaller viewport, or `autoClear = false` with another scene) is not a takeover | - |
|
|
16
16
|
| `renderer.setSize` / `setPixelRatio` yourself | the post chain follows on its next draw | - |
|
|
17
|
-
| `scene.fog.far = 80`, `sun.intensity = 3`, `renderer.toneMappingExposure = 1.4` |
|
|
18
|
-
| one file per piece in `plugins/` next to index.html (`export default mesh`, a Pass, a post effect such as `grain()`, a
|
|
17
|
+
| `scene.fog.far = 80`, `sun.intensity = 3`, `renderer.toneMappingExposure = 1.4` | stays: the engine never writes these on its own | - |
|
|
18
|
+
| one file per piece in `plugins/` next to index.html (`export default mesh`, a Pass, a post effect such as `grain()`, a module; never a bare function; a Material goes on its mesh in `picture/`) | plugs each at `engine.start()` by what it exports, through the same calls as above (`scene.add`, `engine.post.add`, `engine.use`); order by file name or a `plugins.json` beside them; anything else is a `[plugin-shape]` error naming the file, what it found and the fix (a factory: `export default makeIt({ ... })`; a module with no `type`: add one) | switch one off: `plugins.json` `"off": ["20-bloom"]` or `engine.plugins.off('20-bloom')` |
|
|
19
19
|
| a static mesh you want `engine.pick` to hit | - | `engine.rays.addStatic(obj)` (a BVH only pays off for things that do not move) |
|
|
20
20
|
|
|
21
21
|
`describe().slots` is the one table of what is plugged in where: each row is `{ slot, plugged, file, on, affects }`, for the plugins folder,
|
|
22
|
-
`scene.add` roots (with the file:line that added them), `
|
|
22
|
+
`scene.add` roots (with the file:line that added them), `engine.post.add` effects, modules and plain lights. Without the vite preset, hand the folder over
|
|
23
23
|
yourself: `engine.plugins.add(import.meta.glob('./plugins/*.js', { eager: true }))` before `engine.start()`.
|
|
24
24
|
|
|
25
|
+
## three.js idioms and who writes the value
|
|
26
|
+
|
|
27
|
+
Write the three.js first; it works. `renderer.toneMapping = THREE.ACESFilmicToneMapping` is a complete answer. What you need to know is which values the
|
|
28
|
+
engine **writes on its own** (every frame or on a timer): a direct write to one of those hands it to you (the engine stops writing it and warns once with the
|
|
29
|
+
explicit call); the full list is recipe 52 "Who writes it". The engine route is optional on top: `engine.mod(point, ...)` adds owners and layers where several
|
|
30
|
+
systems share a value (recipe 55); `engine.autoView.manual(key)` takes a value without the warning (`manual(key, false)` gives it back);
|
|
31
|
+
`engine.describe('picture').picture` says what three.js holds now; `describe().owned` who writes each engine-driven value now.
|
|
32
|
+
|
|
33
|
+
| three.js idiom | Where it goes in the engine | Engine writes it? | How to take it over |
|
|
34
|
+
|---|---|---|---|
|
|
35
|
+
| `renderer.toneMapping` | Just set it: `engine.renderer.toneMapping = THREE.ACESFilmicToneMapping` (any three mapping). A curve of your own: a post stage in the `'tone'` slot, `engine.post.add({ name, slot: 'tone', create, node })`, which runs on both renderers (a `ShaderChunk` edit is page-wide and reaches only WebGLRenderer) | Never: three's default (none) stands until you write it | Nothing to take: `describe().render.toneMapping.writer` then says `game` |
|
|
36
|
+
| `renderer.outputColorSpace` | Leave it at `SRGBColorSpace` (three's default) | No | Changing it makes every color wrong; `assets.report` flags it |
|
|
37
|
+
| `renderer.shadowMap` | On at start on a renderer the engine built; the switch is `engine.shadows.enabled`; `type` is yours | `enabled` when the switch changes | `createEngine({ renderer })` and run your own |
|
|
38
|
+
| `scene.environment` | None by default. The sky as a map: `engine.sky.environment({ into: engine.scene })` | Only after that call; a map you write stays | Write it; recipe 34 |
|
|
39
|
+
| `scene.background` | Starts neutral gray; assign yours, or `engine.sky.replace(name \| Texture \| Object3D)` with a sky | The sky dome draws over it; a backdrop / skybox writes it every frame | Assign it: the dome hides and the sky stops writing it |
|
|
40
|
+
| Your own sky (three/addons `Sky`, a ShaderMaterial dome, a skybox) | `engine.sky.replace(mySky)`; feed it from `engine.uniforms` (`uSunDir`, `uDaylight`, `uTimeOfDay`, `uWind`, `uWeatherCloud`) | Never: the engine only hides its dome and adds `mySky` to the scene when it has no parent; time, lights, fog and weather keep running | `engine.sky.replace(null)` gives the dome back. Per key instead of whole: write `engine.sky.top` and friends in your frame code |
|
|
41
|
+
| Lights (`DirectionalLight`, `PointLight`, ...) | `engine.scene.add(light)` before `engine.start()` (a light count change mid-play recompiles shaders; `lightPool()` for many) | Never; `engine.lights.sun` / `.hemi` are placeholders that nothing writes but you | `createEngine({ lights: false })` leaves the placeholders out |
|
|
42
|
+
| Shadow camera (`light.shadow.camera`, `mapSize`, `bias`) | Your own lights: just do it. Engine sun: the same, plus `engine.shadows.box(engine.lights.sun, ...)` | The engine sun's shadow box follows `engine.focus` every frame | `engine.shadows.box(sun, { follow: 'focus' \| 'camera' \| object3D \| fn \| false, extent })`, or place `sun.target` yourself (the box stops following); recipe 45 |
|
|
43
|
+
| `onBeforeCompile`, `customProgramCacheKey` | On the WebGL route just assign them, on any material: `m.onBeforeCompile = s => { ... }`. On WebGPU neither works and it stops with an error: write a node material (recipe 56). A named, checked patch: `applyEffects(m, { patches: [...] })` | Nothing: on a material the engine patched (wind, clouds, season), your function runs first and the patches after it; your cache key is joined in front of theirs | - |
|
|
44
|
+
| Textures, `CanvasTexture`, `DataTexture` | Just do it; set `colorSpace = SRGBColorSpace` on color textures. File textures by name: `engine.assets.manifest({ textures })` then `assets.texture(name)` | No | A texture made in code gets a name too: `assets.manifest({ textures: { brick: () => makeBrick(), sign: mySignTexture } })`, then `map: 'brick'`; it keeps its own repeat / wrap / colorSpace. Baking: recipe 05 |
|
|
45
|
+
| `EffectComposer` passes | `const h = engine.post.add(pass)` (`composer.addPass`; `{ order }` for `insertPass`; `h.remove()` for `removePass`) | The engine renders the main frame through its own composer | `engine.post.own()` for the whole chain. To read them: `engine.post.object()` (the EffectComposer, null until post first runs) and `engine.post.targets()` (`renderTarget1 / 2`, `readBuffer`, `writeBuffer`; read in `onRender(fn, { when: 'after' })`). Read-only: the engine rebuilds `passes`, resizes and disposes them |
|
|
46
|
+
| Render targets (mirror, minimap, portal, picking) | `engine.onRender(({ renderer, scene, camera, dt }) => { renderer.setRenderTarget(rt); renderer.render(scene, cam); })`; runs after the camera and batching, before the frame (`{ when: 'after' }` after it) | No; the render target is reset to the screen after each `before` callback | The main frame render itself stays the engine's |
|
|
47
|
+
| Loaders (`GLTFLoader`, `TextureLoader`, `EXRLoader`, `FBXLoader`, `FontLoader`, exporters) | glTF and png / jpg / ktx2 / hdr textures: `engine.assets.manifest(...)` gives them names, the loading screen and `describe` | No | A hand-made `GLTFLoader` / `TextureLoader` works (rule R21 warns: the asset gets no name). Formats the manifest cannot load (EXR, FBX, OBJ, typeface fonts) and exporters: just use the three.js addon |
|
|
48
|
+
| Camera (`fov`, `position`, `far`) | Camera modules (`followCamera()`, ...) or `engine.camera` with none installed | An installed camera module writes position / fov every frame; terrain view distance rewrites `camera.far` | `engine.takeCamera('me')` (gives it back on `remove()`), or just write `camera.position` (the rig stops; `engine.autoView.manual('camera', false)` resumes). `camera.far` / `fov`: `engine.autoView.manual('far' \| 'fov')` |
|
|
49
|
+
| Meshes (`scene.add(mesh)`) | `engine.add(mesh, { id })` (tracked, saveable) or plain `engine.scene.add(mesh)` | No: auto-batching only merges what the engine places (world records, stream builds, level files); your own meshes stay as you made them | Many static copies of your own mesh: `mesh.userData.batch = true` before adding (recipe 05, 2b) |
|
|
50
|
+
|
|
51
|
+
Contact shadows are no engine feature: `threedog examples pull contact-shadows` copies one way in. WebGPU and TSL: recipe 56.
|
|
52
|
+
|
|
25
53
|
## What the engine changes in three.js (Global changes)
|
|
26
54
|
Everything else in three is untouched. Every change below is listed in `describe().threePatches` (`{ id, what, scope, on, offable, lost }`);
|
|
27
55
|
an offable one is undone page-wide with `threePatches.off(id)` (`import { threePatches } from 'threedog'`), call it before creating the objects
|
|
28
|
-
that should not see it. `lost` says what stops working; a change that cannot be undone says why and `off` throws.
|
|
56
|
+
that should not see it. It is page-wide: every engine on the page loses the change, and `engine.dispose()` does not undo it (disposing one engine never touches a change another engine or library relies on). A wrapper another library put on `Object3D.prototype.add` stays when `scene-add-hook` is turned off. `lost` says what stops working; a change that cannot be undone says why and `off` throws.
|
|
29
57
|
|
|
30
58
|
| id | Change | Effect on your code | Off |
|
|
31
59
|
|---|---|---|---|
|
|
@@ -33,71 +61,71 @@ that should not see it. `lost` says what stops working; a change that cannot be
|
|
|
33
61
|
| `node-setup-position` | `NodeMaterial.prototype.setupPosition` wrapped | WebGPU only: runs the engine's vertex-moving patches (wind) first; other node materials unchanged | yes |
|
|
34
62
|
| `scene-add-hook` | `Object3D.prototype.add / remove` wrapped (page-wide) | None to the call itself; the engine sees what enters and leaves its scene at any depth (adopting `scene.add`, fog, cascades, cloud shadow, light counts). Another library wrapping the same methods stacks with it | yes (`scene.add` no longer adopted) |
|
|
35
63
|
| `mesh-material-accessor` | `material` on each object entering the engine's scene: an own get / set on that object (a class accessor, e.g. troika text, still runs) | In devtools `mesh.material` shows as an accessor; `mesh.material = other` works as in three and is seen | yes (new objects) |
|
|
36
|
-
| `material-compile-accessor` | `onBeforeCompile` / `customProgramCacheKey` on each material the engine patches (
|
|
64
|
+
| `material-compile-accessor` | `onBeforeCompile` / `customProgramCacheKey` on each material the engine patches (what applyEffects was asked for, wind, fog) | Your own hook, assigned before or after, runs first, then the engine's | yes (new materials) |
|
|
37
65
|
| `renderer-render` | `engine.renderer.render` (that instance only) wrapped | Counts your full-canvas draws so the engine yields the frame; a scissored / smaller-viewport / `autoClear = false` layer (minimap, HUD) does not count | yes |
|
|
38
66
|
| `shader-chunks` | `THREE.ShaderChunk.threedog_*` added (new names, nothing replaced) | None until you `#include` one | no (the engine's patches include them) |
|
|
39
67
|
| `light-idle-shadow` | `shadow.autoUpdate` of your shadow-casting point / spot lights: off while intensity is 0, back on when lit | Only lights whose autoUpdate was on; writing autoUpdate yourself hands the light back; `light.userData.idleShadow = false` opts one out; `describe().render.lights` shows `shadowIdled` | yes |
|
|
40
|
-
| `
|
|
68
|
+
| `shadow-cache` | `light.shadow.shadowNode` of a light handed to `engine.shadows.cache`: a `ShadowNode` subclass with float depth, a second depth map and a draw filter | Only that light, only after the call; the handle's `remove()` puts three's node back |
|
|
69
|
+
| `batching-draw-walk` | `children` of a parent holding batched meshes: those meshes leave the array during the engine's own draw and come back right after | None outside the draw: your code, raycasts and `scene.traverse` see the scene as built. A scene change made inside a render (`onBeforeRender`) on such a parent is lost | yes (three walks every batched original twice a frame again) |
|
|
70
|
+
| `picture-writers` | Dev server only (absent from bundles and release builds): an own get / set on the picture values of objects in the engine's scene (light intensity / color / position, `scene.fog` and its values, tone and exposure, environment, background, material color / emissive / opacity), and on the `r g b` / `x y z` of those colors and positions | Every read and write goes through unchanged; in devtools these show as accessors. A write records who made it for `describe('picture').writers` and `engine.explain({ picture })` | yes: `threePatches.off('picture-writers')`, accessors stay and only pass values through |
|
|
71
|
+
| `post-shadow-hold` | `render` of the first pass of the WebGL post chain wrapped (it may be your own Pass) | None to what the pass draws; shadow maps redraw once a frame | yes |
|
|
72
|
+
| `post-background-tone` | `onBeforeRender` of three's own background mesh, while the engine draws straight to the canvas | A texture background is tone-mapped as it is through the post chain; your own `renderer.render` keeps three's rule | yes |
|
|
73
|
+
| `node-twin-dress` | `renderer.library.fromMaterial` of a WebGPURenderer wrapped | WebGPU only: the node twin of a classic material gets its patches | no (patched materials would lose their picture on WebGPU) |
|
|
74
|
+
| `node-builder-hook` | `renderer.debug.onNodeBuilderCreated` of a WebGPURenderer wrapped | WebGPU only: your own hook still runs; a later write of yours replaces the engine's | yes |
|
|
75
|
+
| `device-lost-hook` | `renderer.onDeviceLost` of a WebGPURenderer wrapped | WebGPU only: three's hook still runs; a later write of yours replaces the engine's | yes |
|
|
76
|
+
| `lod-view-camera` | `update` and `clone` of the `THREE.LOD` objects `assets.lod` and a prop's `lod` make | Only the engine camera moves the level, and far off the full model waits on the batch layer with `visible` still true, so rays reach it | yes |
|
|
77
|
+
| `webgpu-record-sweep` | A `'dispose'` event sent to objects drawn earlier that have left every Scene for a few seconds, found through WebGPURenderer's private record list | WebGPU only: your `'dispose'` listener on such an object runs; drawing it again rebuilds its record | yes |
|
|
41
78
|
|
|
42
79
|
|
|
43
80
|
## Getting three.js objects from the engine
|
|
44
81
|
|
|
45
82
|
| You want | Use |
|
|
46
83
|
|---|---|
|
|
47
|
-
| THREE itself | `import { THREE } from 'threedog'`
|
|
48
|
-
| Scene / camera / renderer | `engine.scene`, `engine.camera` (PerspectiveCamera), `engine.renderer` (WebGLRenderer) |
|
|
49
|
-
| Player, NPCs | `engine.player.
|
|
84
|
+
| THREE itself | `import { THREE } from 'threedog'` (the same copy the engine uses) |
|
|
85
|
+
| Scene / camera / renderer | `engine.scene`, `engine.camera` (PerspectiveCamera), `engine.renderer` (WebGPURenderer on the default route of a new game, WebGLRenderer on `--webgl`) |
|
|
86
|
+
| Player, NPCs | `engine.player.root`, `engine.npcs.get('name').root` (Group); position `.position` (Vector3) |
|
|
50
87
|
| Pickups, template instances | `pickups.spawn(...)` returns a handle with `.object` (Mesh); a template instance's model is `engine.world.view(id)` (exists only near) |
|
|
51
88
|
| Level | `engine.level.root`; markers `engine.level.marker('spawn').object / .position` |
|
|
52
89
|
| Sun, ambient light, sky dome, fog | `engine.lights.sun` (DirectionalLight), `engine.lights.hemi` (HemisphereLight), `engine.sky.dome`, `engine.scene.fog` |
|
|
53
|
-
| Water | `engine.water.sea` (Mesh; null when the game sets no water level), `water.material`, `water.bodies.get(body)` |
|
|
54
|
-
| Particles, weather particles | `.points`
|
|
90
|
+
| Water | `engine.water.sea` (Mesh; null when the game sets no water level), `water.material` (get / set), `water.uniforms`, `water.bodies.get(body)` |
|
|
91
|
+
| Particles, weather particles | `.points` and `.material` of the value returned by `particles.define(...)`; `engine.weather.particles[field].material` (the plain material of a weather field) |
|
|
55
92
|
| Rigid bodies | `engine.rigid.addBox(mesh)` returns a handle `{ object, body, remove() }`, or null before Rapier is ready (object is your mesh; `castShadow` / `receiveShadow` keep the values you set, the engine does not change them) |
|
|
56
|
-
| Terrain chunks | `engine.terrain.chunks` (Map of chunk data); a chunk's three.js objects: `engine.
|
|
93
|
+
| Terrain chunks | `engine.terrain.chunks` (Map of chunk data); a chunk's three.js objects: `engine.terrainDraw.meshes.get(chunk)` (`{ group, mesh }`) |
|
|
57
94
|
| Models, textures, animation | `await engine.assets.model('name or path')` (an Object3D copy), `assets.texture(...)`, `assets.animate(model).mixer` |
|
|
58
95
|
| Vehicles, navigation, character controller | `engine.rigid.addWheeled(mesh, ...)` returns `{ body, controller }`; `engine.nav.navMesh / query / tileCache / crowd` (they are destroyed and replaced on rebuild; code that caches them compares `engine.nav.version`); `engine.player.mover.controller` (mover: 'rapier') |
|
|
59
96
|
| glTF / compression decoders | `engine.assets.gltf` (GLTFLoader, Meshopt installed), `assets.draco` (DRACOLoader), `assets.ktx2` (KTX2Loader); the last two are created the first time compressed data is met and are null before that |
|
|
60
97
|
| Rays | `engine.raycast(origin, direction)` / `engine.pick(ndcX, ndcY)` return three hits (`object` is the mesh, `face` and `point` unchanged); `{ targets: 'all' }` hits rigid bodies too (the hit carries `entry` and `kind: 'rigid'`); the underlying `engine.rays.ray` (THREE.Raycaster, `firstHitOnly` on) |
|
|
61
|
-
| Ray acceleration (BVH) | three-mesh-bvh, without touching three's prototypes: a static mesh the engine registers (from 256 triangles up) gets `mesh.geometry.boundsTree` and its own `mesh.raycast`, so
|
|
98
|
+
| Ray acceleration (BVH) | three-mesh-bvh, without touching three's prototypes: a static mesh the engine registers (from 256 triangles up) gets `mesh.geometry.boundsTree` and its own `mesh.raycast`, so any ray on that mesh is fast, your own `new THREE.Raycaster()` too; every other mesh is plain three. Page-wide BVH for your rays: three-mesh-bvh's documented setup (`Mesh.prototype.raycast = acceleratedRaycast`, ...) |
|
|
62
99
|
| Streamed-in objects | `.object` of the handle returned by `engine.stream.add({ position, build })` (the Object3D that build returned; null before it is built) |
|
|
63
|
-
| Post-processing | `engine.
|
|
100
|
+
| Post-processing | `engine.post.add(pass)`, the one way in (a Pass, or an effect `{ name, slot, create: ctx => pass }` plus its twin for the other renderer, recipe 56; slots `scene` / `hdr` / `tone` / `ldr` / `final`; on / off and params with its handle); `engine.post.own()` hands over the whole chain |
|
|
64
101
|
| Where the mouse points | Ground: `screenToGround(engine, input.pointer.ndcX, ndcY)` -> Vector3; objects: `engine.pick(input.pointer.ndcX, ndcY)` (registered static objects; for any object pass `{ targets: [object] }`) |
|
|
65
102
|
|
|
66
103
|
Returned positions are all `THREE.Vector3` (the camera's `forward()/right()` are planar directions `{x, z}`; positions in photo records are saveable `{x, z}`).
|
|
67
|
-
Anywhere a position is accepted it is **one argument**: Vector3 / Object3D / `[x, y, z]` / `{ x, z }` all work, and sizes go in an options object (
|
|
68
|
-
"Interface conventions" in `CONVENTIONS.md`):
|
|
69
|
-
`collision.addCircle(mesh, { radius: 1 })`, `collision.addBox(mesh.position, { halfWidth: 2, halfDepth: 1 })`, `particles.emit('dust', mesh, { count: 20 })`,
|
|
70
|
-
`triggers.add({ position: mesh })`, `content.spawn(name, v)`, `npcs.add({ position: v })`, `pickups.spawn(v, { give })`, `interactions.add(v or mesh, ...)`,
|
|
71
|
-
`rigid.impulse(entry, [0, 3, 5])`, `player.placeAt(v)`. Ground sampling `engine.surface(x, z)` also accepts `engine.surface(mesh.position)`.
|
|
104
|
+
Anywhere a position is accepted it is **one argument**: Vector3 / Object3D / `[x, y, z]` / `{ x, z }` all work, and sizes go in an options object ("Interface conventions" in `CONVENTIONS.md`).
|
|
72
105
|
|
|
73
106
|
## Engine conventions when using three.js
|
|
74
107
|
|
|
75
|
-
1. **Materials**: `new THREE.MeshStandardMaterial(...)` is
|
|
76
|
-
for a role (it returns a real three material; the type is decided by the style); afterwards change `.map`, `.transparent` as usual.
|
|
108
|
+
1. **Materials**: `new THREE.MeshStandardMaterial(...)` is the way; afterwards change `.map`, `.transparent` as usual.
|
|
77
109
|
Your own shader code works as in three.js: `ShaderMaterial`, `onBeforeCompile` (also on an engine material: yours runs first, the engine's
|
|
78
110
|
wind / clouds / season patches after it). The engine adds effects only to materials it made; yours opt in with `applyEffects(mat, { wind: 0.03 })`.
|
|
79
|
-
One exception, named: with cascaded shadows on (`
|
|
80
|
-
be lit N times; a lit `ShaderMaterial` of yours joins with `engine.
|
|
111
|
+
One exception, named: with cascaded shadows on (`engine.shadows.cascades(light)`) every built-in lit material gets the `csm` patch, or it would
|
|
112
|
+
be lit N times; a lit `ShaderMaterial` of yours joins with `engine.shadows.include(mat)` (recipe 45).
|
|
81
113
|
2. **Adding to the scene**: `engine.scene.add(obj)` is all it takes: every root under the scene is registered (`engine.thing(obj)` says what it
|
|
82
114
|
is and what a save keeps). `engine.add(obj, { id })` is only for a stable id, so `thing.set` changes to it are saved. Plain three.js and
|
|
83
|
-
templates (`engine.content.spawn`, content props) are two doors into one scene (`recipes/40-scene.md`). To attach to a character use `player.
|
|
115
|
+
templates (`engine.content.spawn`, content props) are two doors into one scene (`recipes/40-scene.md`). To attach to a character use `player.root.add(hat)`.
|
|
84
116
|
3. **Per-frame logic goes in `engine.onFrame(dt => ...)`** (movement and timing use `engine.onFixed`); it returns a handle, cancel with `h.remove()`.
|
|
85
117
|
Don't start your own `requestAnimationFrame` loop: the engine owns pausing, fast-forward in tests and ordering. Rendering the canvas
|
|
86
118
|
yourself (own `EffectComposer`) takes the frame over: the engine stops drawing it and its post chain, adaptive resolution and photo mode stop applying. Rendering into your own render target is fine (mirror, minimap, portal, picking): do it in
|
|
87
119
|
`engine.onRender(({ renderer, scene, camera, dt }) => ...)`, which runs after the camera update and batching, just before the frame
|
|
88
|
-
(`{ when: 'after' }` runs right after it).
|
|
120
|
+
(`{ when: 'after' }` runs right after it).
|
|
89
121
|
4. **Snap to ground**: get ground height with `engine.surface(x, z)`, or `engine.snapToGround(obj, heightAboveGround)`. Don't raycast the terrain.
|
|
90
122
|
**Rays** always go through `engine.raycast / pick`: level meshes are registered automatically; register your own static objects with
|
|
91
123
|
`engine.rays.addStatic(obj)` or `assets.model(name, { static: true })`.
|
|
92
|
-
When you need a plain `THREE.Raycaster`, it also uses the BVH automatically (as long as the geometry has a boundsTree).
|
|
93
124
|
5. **Deleting**: when you no longer need an object use `engine.remove(obj)`: it removes it, unregisters it from `engine.rays` and frees the geometry
|
|
94
125
|
and materials (`obj.removeFromParent()` / `scene.remove` leak GPU memory). To take it off only temporarily and `add` it back later use
|
|
95
126
|
`engine.detach(obj)`. A copy from `assets.model()` shares resources with other copies (`remove` skips them); they are freed together by
|
|
96
127
|
`assets.release(name)`.
|
|
97
|
-
6. **
|
|
98
|
-
`engine.mod('look.lights.sun.intensity', { owner: 'cave', mul: 0.3 })` (also `look.lights.hemi.intensity` / `look.fog.far`; entries multiply; `remove()` ends it) or `look.lights.set(...)` as the base they multiply;
|
|
99
|
-
take a value with `engine.look.lights.manual('sun')` and then set `engine.lights.sun.intensity` yourself (`manual('sun', false)` gives it back).
|
|
100
|
-
Writing it directly without `manual` also takes it (the engine stops writing it and warns once). Every engine-written value: recipe 52
|
|
128
|
+
6. **The sky lights nothing**: it computes signals and draws the dome, and your `picture/` code writes the lights, the fog and the exposure (recipe 62); weather gives `uWeatherLight` / `uWeatherFog` to multiply in. Every engine-written value: recipe 52
|
|
101
129
|
"Who writes it". Adding your own point lights (street lamps, campfires) is fine.
|
|
102
130
|
7. **Camera**: only change properties of `engine.camera`, never replace the object (post-processing is bound to it; `engine.setCamera('follow')` swaps the camera *module*, not the object). When a camera
|
|
103
131
|
module is installed it places the camera every frame; to control the view yourself take it with `const cam = engine.takeCamera('me')` and `cam.remove()` it
|
|
@@ -108,31 +136,54 @@ Anywhere a position is accepted it is **one argument**: Vector3 / Object3D / `[x
|
|
|
108
136
|
`npm run bake` it reads the file.
|
|
109
137
|
Things needed only nearby use `engine.stream.add({ position, build })`; put long loops in `engine.jobs.add(function* () { ...; yield; })` so they
|
|
110
138
|
are spread over frames and the start does not stall.
|
|
111
|
-
Smooth normals on built shapes: a non-indexed geometry (`geometry.toNonIndexed()`, a `mergeGeometries` result where one part has no index) gives
|
|
112
|
-
every triangle its own vertices, so `geometry.computeVertexNormals()` shades each face flat (a low-poly look). Weld first with `mergeVertices` from
|
|
113
|
-
`three/addons/utils/BufferGeometryUtils.js` (per part, so hard edges between parts stay), then compute the normals.
|
|
114
139
|
10. **One copy of the engine and of three per page**: `resolve: { dedupe: ['threedog', 'three'] }` in vite.config.js. A second engine copy
|
|
115
140
|
(a pack that lists threedog under `dependencies` instead of `peerDependencies`, a linked plus an installed copy) breaks shadows of wind and
|
|
116
141
|
cascaded-shadow materials; the engine warns once at load, naming both paths [engine-two-copies].
|
|
117
142
|
|
|
118
143
|
## Example: a spinning windmill (plain three.js + engine conventions)
|
|
119
|
-
|
|
144
|
+
The same windmill as a template with an id, saved and editable without code, is in `recipes/40-scene.md` §1.
|
|
120
145
|
|
|
121
146
|
```js
|
|
122
147
|
import { THREE } from 'threedog';
|
|
123
|
-
const mill = new THREE.Group(),
|
|
124
|
-
|
|
125
|
-
const tower = new THREE.Mesh(new THREE.CylinderGeometry(0.8, 1.2, 6, 6), wood);
|
|
126
|
-
tower.position.y = 3; tower.castShadow = true;
|
|
127
|
-
const blades = new THREE.Group(); blades.position.set(0, 5.5, 1.3);
|
|
128
|
-
for (let i = 0; i < 4; i++) {
|
|
129
|
-
const arm = new THREE.Group(), sail = new THREE.Mesh(new THREE.BoxGeometry(0.5, 4, 0.08), cloth);
|
|
130
|
-
sail.position.y = 2; sail.castShadow = true; arm.rotation.z = i * Math.PI / 2; arm.add(sail); blades.add(arm);
|
|
131
|
-
}
|
|
132
|
-
mill.add(tower, blades);
|
|
148
|
+
const mill = new THREE.Group(), blades = new THREE.Group(); // plain three.js: meshes and materials as usual
|
|
149
|
+
mill.add(blades);
|
|
133
150
|
mill.position.set(20, 0, -10);
|
|
134
151
|
engine.snapToGround(mill); // snap to ground
|
|
135
152
|
engine.scene.add(mill); // registered like engine.add; engine.add(mill, { id: 'mill' }) also keeps thing.set changes in saves
|
|
136
153
|
engine.collision?.addCircle(mill, { radius: 1.3 }); // block the player (when the collision module is installed)
|
|
137
154
|
engine.onFrame(dt => { blades.rotation.z += dt * 1.5; });
|
|
138
155
|
```
|
|
156
|
+
|
|
157
|
+
## Code-built models: what three.js already has
|
|
158
|
+
Models written in code (recipe 05, 2a) mostly need helpers three.js ships; import them inside the model generator, so the result is cached and baked with the model.
|
|
159
|
+
`three`: `LatheGeometry`, `TubeGeometry`, `ExtrudeGeometry` (`extrudePath`), `ShapeGeometry`, `InstancedMesh`, `BatchedMesh`, `CanvasTexture`. `three/addons`: `BufferGeometryUtils` (`mergeGeometries`, `mergeVertices`, `toCreasedNormals`),
|
|
160
|
+
`LoftGeometry`, `RoundedBoxGeometry`, `ParametricGeometry`, `TextGeometry`, `DecalGeometry`, `ConvexGeometry`, `Flow` (CurveModifier), `MeshSurfaceSampler`, `SimplifyModifier`, `TessellateModifier`, `EdgeSplitModifier`, `SimplexNoise`, `ImprovedNoise`.
|
|
161
|
+
|
|
162
|
+
```js
|
|
163
|
+
import * as THREE from 'three';
|
|
164
|
+
import { mergeGeometries, mergeVertices } from 'three/addons/utils/BufferGeometryUtils.js';
|
|
165
|
+
import { SimplexNoise } from 'three/addons/math/SimplexNoise.js';
|
|
166
|
+
import { bakeVertexAO } from 'threedog';
|
|
167
|
+
|
|
168
|
+
const rng = engine.random.seeded(7), simplex = new SimplexNoise({ random: () => rng.next() }); // seeded noise: the same shape every load
|
|
169
|
+
// weld first, or the noise opens cracks; mergeVertices compares every attribute, so drop normal and uv (their seams would stay unwelded)
|
|
170
|
+
const rock = mergeVertices(new THREE.IcosahedronGeometry(1, 3).deleteAttribute('normal').deleteAttribute('uv'));
|
|
171
|
+
const p = rock.attributes.position, v = new THREE.Vector3();
|
|
172
|
+
for (let i = 0; i < p.count; i++) { v.fromBufferAttribute(p, i); v.multiplyScalar(1 + 0.25 * simplex.noise3d(v.x, v.y, v.z)); p.setXYZ(i, v.x, v.y, v.z); }
|
|
173
|
+
rock.computeVertexNormals();
|
|
174
|
+
const slab = new THREE.CylinderGeometry(1.2, 1.4, 0.3).translate(0, -0.9, 0).deleteAttribute('uv');
|
|
175
|
+
const model = mergeGeometries([rock, slab]); // same attributes (position, normal), both indexed
|
|
176
|
+
bakeVertexAO(model, { samples: 32, strength: 0.7, occluders: [new THREE.PlaneGeometry(6, 6).rotateX(-Math.PI / 2).translate(0, -1.05, 0)] });
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Traps: `mergeGeometries` needs the same attributes on every part, all indexed or none. A non-indexed geometry (`geometry.toNonIndexed()`, a merge where one part has no index) gives every triangle its own
|
|
180
|
+
vertices, so `geometry.computeVertexNormals()` shades each face flat: weld first with `mergeVertices` (per part, so hard edges between parts stay). `SimplifyModifier.modify` is async in this three version.
|
|
181
|
+
|
|
182
|
+
| Need | Engine, only what three lacks |
|
|
183
|
+
|---|---|
|
|
184
|
+
| Parts of one flat color each, into one geometry | `mergeColored([[g, color], ...])` (vertex colors) |
|
|
185
|
+
| Ambient occlusion in a code-built model (three's `aoMap` needs a baked texture) | `bakeVertexAO(geometry, { samples, radius, strength, occluders })`: hemisphere rays per vertex (three-mesh-bvh), multiplied into the vertex colors; detail is per vertex, so tessellate big faces first |
|
|
186
|
+
| Points over the ground by height, slope and biome | `engine.vegetation.define(name, { rule })` (recipe 36) |
|
|
187
|
+
| Far copies of whole areas | `hlod` (recipe 15) |
|
|
188
|
+
| Terrain heights | `@threedog/terrain-noise` (recipe 28) |
|
|
189
|
+
| Many copies | Auto-batching for copies the engine places, `userData.batch` for yours (recipe 05, 2b) |
|
package/docs/api/assets.md
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
# engine.assets (Assets)
|
|
2
2
|
|
|
3
3
|
- `assets.manifest(m: AssetManifest | AssetManifest[])` — Register an asset manifest or asset pack (can be called several times; a later entry with the same name replaces the earlier one). Its name labels it in engine.loading, base resolves its relative paths
|
|
4
|
-
- `assets.builder(name: string) → ((...args: any[]) => any) | null` — The generator function registered under a model name, null for a file model or an unknown name (content builds [name, ...params] models with it)
|
|
5
|
-
- `assets.paramsOf(name: string) → { schema, values, tuned } | null` — The params of a generator registered with a params schema: { schema, values (built with now), tuned (from setParams) }, or null
|
|
4
|
+
- `assets.builder(name: string) → ((...args: any[]) => any) | null` — (experimental) The generator function registered under a model name, null for a file model or an unknown name (content builds [name, ...params] models with it)
|
|
5
|
+
- `assets.paramsOf(name: string) → { schema, values, tuned } | null` — (experimental) The params of a generator registered with a params schema: { schema, values (built with now), tuned (from setParams) }, or null
|
|
6
6
|
- `assets.setParams(name: string, values: Record<string, any>) → Promise<{ why: string; names: str…` — Dev tuning: build a generator with these params (replacing its defaults) and swap every live copy in place; the dev panel's models folder calls it
|
|
7
|
-
- `assets.preload(onProgress?: (p: number, name: string) => void, opts?: { onlyMarked?: boolean }) → Promise<{ loaded: number; failed:…` — Preload (onProgress(0–1, current name)). Code-generated models and fonts are only loaded up front if marked preload. failed includes entries now showing their fallback
|
|
8
|
-
- `assets.font(name: string) → Promise<FontFace | null>` — A font from an asset pack by name: downloaded once, added to document.fonts; null when the file failed and it is not critical.
|
|
7
|
+
- `assets.preload(onProgress?: (p: number, name: string) => void, opts?: { onlyMarked?: boolean }) → Promise<{ loaded: number; failed:…` — (experimental) Preload (onProgress(0–1, current name)). Code-generated models and fonts are only loaded up front if marked preload. failed includes entries now showing their fallback
|
|
8
|
+
- `assets.font(name: string) → Promise<FontFace | null>` — A font from an asset pack by name: downloaded once, added to document.fonts; null when the file failed and it is not critical. ui.fonts calls it at start()
|
|
9
9
|
- `assets.model(nameOrUrl: string, opts?: { castShadow?, receiveShadow?, static? }) → Promise<Object3D>` — Get a model copy (name or path; geometry and materials are shared with other copies). static: true registers it in engine.rays (builds ray acceleration)
|
|
10
|
-
- `assets.
|
|
10
|
+
- `assets.lod(nameOrUrl: string, opts?: { distances?, hysteresis?, castShadow?, receiveShadow?, static? }) → Promise<import('three').LOD>` — (experimental) A model copy as a plain THREE.LOD: the full model near, the levels of `threedog assets optimize --lod` far away. Default distances follow the model's size; distances (rising meters) replace them, hysteresis is the share of a distance that stops flicker at the line (default 0.1). Rays, collision and saves keep using the full model. A LOD object is never batched. Without levels it warns in dev and draws in full. Example: `const tower = await engine.assets.lod('tower', { distances: [40, 120] }); engine.add(tower); tower.levels[1].object;`
|
|
11
|
+
- `assets.modelNow(nameOrUrl: string, opts?: { castShadow?, receiveShadow?, static? }) → Object3D | null` — (experimental) A model copy right now if it has already loaded, else null (never starts a load, never waits): lets code that rebuilds often skip the frame an await costs. Code-built models (a build function in the manifest) count too: they are null until one await model(name) or an entry with preload: true ran (dev warns [asset-not-loaded]). Example: `const m = engine.assets.modelNow('villager') ?? await engine.assets.model('villager');`
|
|
11
12
|
- `assets.geometry(nameOrUrl: string) → Promise<BufferGeometry>` — Get the geometry of the first mesh in a model
|
|
12
13
|
- `assets.gridFromImage(nameOrUrl: string, opts?: { channel?, range?, bits? }) → Promise<{ data: Float32Array; wid…` — An image as grid data for sampleGrid: PNG at 8 or 16 bits (jpg / webp 8). channel 'r' (default) 'g' 'b' 'a' or 0-3; range maps pixels to [min, max] (default [0, 1])
|
|
13
14
|
- `assets.texture(nameOrUrl: string, opts?: { color?, pixelated?, repeat? }) → Promise<Texture>` — Get a texture (.ktx2 compressed textures also work)
|
|
14
|
-
- `assets.useTexture(nameOrUrl: string, use: (texture: Texture) => void, o?: { where?, instead?, opts? }) → Promise<boolean>` — Fetch a texture for something that already shows a stand-in: use(texture) runs when it arrives; a failed load is one load
|
|
15
|
-
- `assets.release(name: string)` — Release a resource and return
|
|
16
|
-
- `assets.trim() → string[]` — Release every model that has no copy in use (called automatically after level changes). Models whose shared geometry was taken by geometry() and code-generated models are not released automatically. Returns the released names
|
|
17
|
-
- `assets.
|
|
18
|
-
- `assets.forget(obj: Object3D)` — Called when an object is fully removed (engine.remove already calls it, normally you don't need to): decrements the use count of the model copies under it
|
|
15
|
+
- `assets.useTexture(nameOrUrl: string, use: (texture: Texture) => void, o?: { where?, instead?, opts? }) → Promise<boolean>` — Fetch a texture for something that already shows a stand-in: use(texture) runs when it arrives; a failed load is one asset-load dev warning naming `where` and what shows `instead`, and resolves false (an error inside use() is not swallowed). opts are texture()'s options
|
|
16
|
+
- `assets.release(name: string)` — Release a resource and return its memory. Not released while copies of the model are still in the scene; it is released when the last copy is removed with engine.remove. A sound (name or path) plays on where it is playing and loads again on next use. A load still running ends and its result is thrown away; code awaiting it gets a fresh load, never freed data. A name that fell back holds no data of its own: release the name it fell back to
|
|
17
|
+
- `assets.trim() → string[]` — Release every model that has no copy in use and every long decoded sound (music, long loops; short effects stay; a sound still playing plays on), unless marked preload (called automatically after level changes). Models whose shared geometry was taken by geometry() and code-generated models are not released automatically. Returns the released names
|
|
18
|
+
- `assets.forget(obj: Object3D)` — (experimental) Called when an object is fully removed (engine.remove already calls it, normally you don't need to): decrements the use count of the model copies under it
|
|
19
19
|
- `assets.animate(root: Object3D, config?: AnimatorOptions) → Animator` — Create an animation state machine for a skinned model (without config it is simple play-by-name). A copy of a manifest model whose entry has `animation` starts from that mapping; config wins per state
|
|
20
20
|
- `assets.mapping(root: Object3D) → AnimatorOptions | null` — The manifest entry's animation mapping for a model copy, or null (not a manifest copy, or no mapping)
|
|
21
21
|
- `assets.report(nameOrRoot: string | Object3D) → AssetReport` — Import report of a loaded model (by name, or a copy from model()): materials, textures with colorSpace, clips, colliders, templates, and issues for what the file has but the scene lost
|
|
22
|
-
- `assets.reportText(nameOrRoot: string | Object3D) → string` — assets.report as text for the console / describe
|
|
23
22
|
- Properties:
|
|
24
23
|
- `cacheMinMs: number` Generations faster than this many milliseconds are not written to the automatic cache (reading the file would be slower), default 20
|
|
24
|
+
- `palette: Record<string, any>` Named colors for what is made in code: a generator written with `function` reads this.palette. Plain data, read, write or replace it freely: it is part of the cache key, so a model or texture asked for after a write is built from the new colors. Copies already placed keep theirs. Example: `engine.assets.palette = { leaf: 0xd98a3a, bark: 0x6b4a30 };`
|
|
25
25
|
- `shared: WeakSet<object>` Geometry and materials shared by model copies (engine.remove does not release them, use release)
|
|
26
26
|
- `memory: { geometries: number; textures: number }` Current GPU memory usage (number of geometries and textures)
|
|
27
|
-
- `gltf: any` three.js GLTFLoader (Meshopt installed; Draco and KTX2 are installed the first time they are needed)
|
|
28
|
-
- `draco: any` three.js DRACOLoader (created only the first time Draco compression is met, null before; the decoder defaults to the one bundled with three, vite packs it automatically)
|
|
29
|
-
- `ktx2: any` three.js KTX2Loader (created only the first time a KTX2 texture is met, null before)
|
|
27
|
+
- `gltf: any` (experimental) three.js GLTFLoader (Meshopt installed; Draco and KTX2 are installed the first time they are needed)
|
|
28
|
+
- `draco: any` (experimental) three.js DRACOLoader (created only the first time Draco compression is met, null before; the decoder defaults to the one bundled with three, vite packs it automatically)
|
|
29
|
+
- `ktx2: any` (experimental) three.js KTX2Loader (created only the first time a KTX2 texture is met, null before)
|
|
30
30
|
|
|
31
31
|
## Data structures
|
|
32
32
|
- **AssetManifest** An asset manifest, also the shape of an asset pack (a folder or npm package exporting one): names -> files or generators; content and code use the names only
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
- `models?: Record<string, AssetEntry>` Models (.glb / .gltf, Draco/Meshopt compression also works): name -> path or generator function
|
|
36
36
|
- `textures?: Record<string, AssetEntry | Texture | (() => Texture | Prom…` Textures: name -> path, or a texture made in code: a function returning a THREE.Texture (run once, on first use) or the Texture itself. Code textures come back as made (their colorSpace / wrap / repeat are yours) and are never disposed by the engine if passed as a Texture. Example: textures: { brick: () => makeBrickTexture(), sign: mySignTexture }
|
|
37
37
|
- `sounds?: Record<string, AssetEntry | SynthFn | { build: SynthFn; par…` Sounds: name -> file path, or a sound made in code: a synth function (SynthFn) or { build: synthFn, params } (params: its defaults). Used by name like a file: audio.sfx(name), audio.sounds rules (src / variants), music and ambience. Example: sounds: { step: '/sfx/step.ogg', ding: dingSynth }
|
|
38
|
-
- `fonts?: Record<string, string | FontAssetEntry>` Fonts: name -> file, or { url, family, weight, style, ... } (family defaults to the name).
|
|
38
|
+
- `fonts?: Record<string, string | FontAssetEntry>` Fonts: name -> file, or { url, family, weight, style, ... } (family defaults to the name). ui.fonts lists the names the UI uses
|
|
39
39
|
- **AnimatorOptions** Animation state machine parameters
|
|
40
|
-
- `fade?: number` Default transition seconds, default 0.25 (
|
|
40
|
+
- `fade?: number` Default transition seconds, default 0.25 (characters({ animation: { fade } }) for every character)
|
|
41
41
|
- `states?: Record<string, AnimatorState>` States: name → state
|
|
42
42
|
- `transitions?: Record<string, number>` Transition seconds for specific pairs: { 'jump>fall': 0.1, '*>idle': 0.3 }
|
|
43
43
|
- `params?: Record<string, number>` Initial parameter values
|
|
@@ -51,6 +51,7 @@
|
|
|
51
51
|
- `lock?: boolean` go() cannot interrupt it while playing
|
|
52
52
|
- `timing?: number | [number, number][]` For sync(): gameplay seconds -> clip seconds. A number = the gameplay length the whole clip is stretched over; [[gameT, clipT], ...] = piecewise linear (land the swing on the hit phase). Without it clip seconds = t
|
|
53
53
|
- **Animator** Skeletal animation state machine (returned by engine.assets.animate(model, config))
|
|
54
|
+
- `root: Object3D` The animated object
|
|
54
55
|
- `mixer: any` three.js AnimationMixer
|
|
55
56
|
- `actions: Map<string, any>` clip name → three.js AnimationAction
|
|
56
57
|
- `state: string | null` Current state name
|
package/docs/api/audio.md
CHANGED
|
@@ -4,26 +4,27 @@
|
|
|
4
4
|
- `audio.setVolume(bus: string, v: number)` — Set a bus volume 0-1 ('master' for the total). Example: `engine.audio.setVolume('music', 0.3);`
|
|
5
5
|
- `audio.duck(levels: Record<string, number>, opts?: { fade?: number }) → { remove(fade?: number): void }` — Lower buses until the handle is removed (dialogue, pause menu, a cutscene). Several ducks stack (their levels multiply). Example: `const d = engine.audio.duck({ music: 0.3, ambience: 0.5 }); engine.events.once('dialogue:end', () => d.remove());`
|
|
6
6
|
- `audio.condition(name: string, test: (value: any, e: any) => boolean) → { remove(): void }` — Add a condition key for music / ambience rule lists: `when: { [name]: value }` calls test(value, engine). Modules add theirs (calendar: time, weather: weather, triggers: zone); the engine has `state` (engine.audio.state). Example: `engine.audio.condition('inside', v => engine.vars.flag('indoors') === v);`
|
|
7
|
-
- `audio.measure(name: string, fn: (e: any) => number) → { remove(): void }` — Add a measure: a number rule data compares (`when: { daylight: { gt: 0.15 } }`; gt / gte / lt / lte) and adds up (`volume: { add: { wind: 0.08 } }`). calendar adds daylight, weather rain / snow / wind, ambience nearWater / altitude. A name is a condition or a measure, not both. Example: `engine.audio.measure('danger', e => e.vars.counter('alarm') / 10); // data: when: { danger: { gt: 0.5 } } Measures are not only for sound: render/
|
|
7
|
+
- `audio.measure(name: string, fn: (e: any) => number) → { remove(): void }` — Add a measure: a number rule data compares (`when: { daylight: { gt: 0.15 } }`; gt / gte / lt / lte) and adds up (`volume: { add: { wind: 0.08 } }`). calendar adds daylight, weather rain / snow / wind, ambience nearWater / altitude. A name is a condition or a measure, not both. Example: `engine.audio.measure('danger', e => e.vars.counter('alarm') / 10); // data: when: { danger: { gt: 0.5 } } Measures are not only for sound: render/daylight.js reads 'daylight' for night glow, so the calendar (or the sky without one) registers it once and nothing else has to know which module tells day from night. remove() drops only this registration (a later one under the name stays).`
|
|
8
8
|
- `audio.value(name: string) → number | undefined` — The current value of a measure (debug, tests); undefined when none is registered under that name
|
|
9
|
-
- `audio.matches(when: AudioCondition | undefined, ...extra: any[]) → boolean` — Does a rule's `when` hold now? An object needs every key to hold (condition keys, or measure comparisons); a function gets (engine, ...extra); missing = always. Example: `engine.audio.matches({ time: 'night', zone: 'forest', rain: { lt: 0.2 } });`
|
|
10
|
-
- `audio.volumeOf(volume: AudioVolume | undefined, ...extra: any[]) → number` — A rule's volume now: a number, a function (engine, ...extra), or data { base, add: { measure: factor }, min, max }; missing = 1. Example: `engine.audio.volumeOf({ base: 0, add: { rain: 0.22 } }); // 0.22 in full rain`
|
|
9
|
+
- `audio.matches(when: AudioCondition | undefined, ...extra: any[]) → boolean` — (experimental) Does a rule's `when` hold now? An object needs every key to hold (condition keys, or measure comparisons); a function gets (engine, ...extra); missing = always. Example: `engine.audio.matches({ time: 'night', zone: 'forest', rain: { lt: 0.2 } });`
|
|
10
|
+
- `audio.volumeOf(volume: AudioVolume | undefined, ...extra: any[]) → number` — (experimental) A rule's volume now: a number, a function (engine, ...extra), or data { base, add: { measure: factor }, min, max }; missing = 1. Example: `engine.audio.volumeOf({ base: 0, add: { rain: 0.22 } }); // 0.22 in full rain`
|
|
11
11
|
- `audio.sfx(name: string, opts?: { volume?, pitch?, at?, bus?, loop?, params?, … }) → SoundHandle | null` — Play a sound by name: its audio.sounds rule (src / variants, volume, bus...), or with no rule the asset pack sound of that name (file or synth function from assets.manifest({ sounds })). Returns a SoundHandle (stop, fade, setPosition), or null when it is silent: not configured, a built-in synth the game did not name, audio still locked, or held back by the sound's cooldown. Over its `voices` limit the oldest voice stops. Example: `engine.audio.sfx('hit', { at: enemy.root, volume: 0.8 });`
|
|
12
12
|
- `audio.noiseBurst(opts?: { dur?, type?, freq?, vol?, bus?, out?, … })` — Synth building block: a burst of filtered noise (footsteps, shutter, rain, thunder). dur seconds, freq Hz, vol 0-1; out: the node to connect to (a synth's `out`), else the named bus
|
|
13
13
|
- `audio.tone(opts?: { freq?, to?, dur?, vol?, type?, bus?, … })` — Synth building block: a short tone (bird call, notification). freq/to Hz, dur seconds, pan -1..1; out as in noiseBurst. Example: `engine.audio.tone({ freq: 660, to: 880, dur: 0.15, bus: 'ui' });`
|
|
14
|
-
- `audio.load(url: string) → Promise<any>` — Download and decode an audio file
|
|
14
|
+
- `audio.load(url: string) → Promise<any>` — Download and decode an audio file, as an engine.loading task: a path or a sound name from an asset pack (manifest sounds), so sounds entries and music tracks may name assets instead of paths. engine.assets caches it: short effects stay; long sounds go with assets.release / trim or over a memory budget, and load again on next use
|
|
15
15
|
- `audio.play(url: string, opts?: { bus?, volume?, loop?, fadeIn?, pitch?, at? }) → Promise<SoundHandle | null>` — Play an audio file by path (no sounds entry needed); resolves to a SoundHandle once the file is decoded. Example: `const h = await engine.audio.play('/sfx/door.ogg', { bus: 'ui' }); h.stop({ fade: 0.5 });`
|
|
16
16
|
- Properties:
|
|
17
17
|
- `ctx: any` The browser AudioContext (exists only after the first click)
|
|
18
18
|
- `levels: Record<string, number>` Volume per bus 0-1 ('master' is the total). Every key is a bus: levels: { voice: 1 } adds a 'voice' bus
|
|
19
|
-
- `buses: Record<string, any>` Bus input GainNodes by name (connect your own nodes here); empty until audio unlocks
|
|
19
|
+
- `buses: Record<string, any>` Bus input GainNodes by name, 'master' included (connect your own nodes here); empty until audio unlocks. A name that is no bus warns and gives master: node.connect(undefined) would throw, and in dev a throw freezes gameplay
|
|
20
20
|
- `state: string | null` The game's current mode for rule lists, e.g. 'combat' / 'explore' (condition `state` in music and ambience rules)
|
|
21
21
|
- `master: any` The master GainNode (every bus ends here)
|
|
22
22
|
- `noise: any` 2 s of white noise, reused by synthesized sounds
|
|
23
|
-
- `running: boolean` Is audio usable (the player has clicked/pressed a key)?
|
|
23
|
+
- `running: boolean` (experimental) Is audio usable (the player has clicked/pressed a key)?
|
|
24
|
+
- `info: { running, state, levels, ducks, voices }` What is playing (describe().audio shows it while something is ducked or playing): bus levels, the duck multiplier per bus, live voices per sound name. ducks is the level the active ducks ask for (1 = not lowered), read at once even while a fade is still ramping or the audio clock does not run (headless page). Example: `engine.audio.duck({ music: 0.3 }); engine.audio.info.ducks.music // 0.3`
|
|
24
25
|
|
|
25
26
|
## Data structures
|
|
26
|
-
- **AudioConfig** The game's sound config: createEngine({ audio }), read back as engine.audio.config (merged with content packs' ContentAudio).
|
|
27
|
+
- **AudioConfig** The game's sound config: createEngine({ audio }), read back as engine.audio.config (merged with content packs' ContentAudio).
|
|
27
28
|
- `sounds?: Record<string, SoundSource>` Sound name -> play rule: an asset sound name / path, variants, or SoundDef
|
|
28
29
|
- `ambience?: AmbienceRule[]` ambience() rule table
|
|
29
30
|
- `music?: { tracks?, rules?, fade?, duckDialogue?, duckFade?, hold?, … }` music() defaults: tracks, rules, fade seconds, duckDialogue (how low the music bus ducks during dialogue; default false = no duck)
|
package/docs/api/budget.md
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
# engine.budget (Budget) — engine.budget: performance budget (turned on by createEngine({ budget }) or enable(); off by default, costs nothing)
|
|
2
2
|
|
|
3
3
|
- `budget.enable(limits?: BudgetLimits)` — Turn on and set limits (only categories given are checked). Example: `engine.budget.enable({ drawCalls: 250, fps: 55 });`
|
|
4
|
-
- `budget.disable()` — Turn off
|
|
4
|
+
- `budget.disable()` — (experimental) Turn off
|
|
5
5
|
- `budget.metric(name: string, read: () => number, opts?: { limit?: number }) → Handle` — Module-defined category: read() returns the current value, opts.limit is the limit (the game's enable() takes precedence). Returns a handle { remove() }
|
|
6
|
-
- `budget.limitOf(name: string) → number | undefined` — Limit of a category; undefined if none was given (not checked)
|
|
6
|
+
- `budget.limitOf(name: string) → number | undefined` — (experimental) Limit of a category; undefined if none was given (not checked)
|
|
7
7
|
- `budget.report() → BudgetReport | null` — Budget report; null when off. In the real-time loop it returns the last second's result; in step() mode it is computed on demand
|
|
8
|
-
- `budget.checkStartup(s: { totalMs, modules }) → { category, value, limit, top }[]` — Called by the engine when startup finishes: warns if startupMs / moduleMs is exceeded and returns the offenders (empty array if none)
|
|
8
|
+
- `budget.checkStartup(s: { totalMs, modules }) → { category, value, limit, top }[]` — (experimental) Called by the engine when startup finishes: warns if startupMs / moduleMs is exceeded and returns the offenders (empty array if none)
|
|
9
9
|
- `budget.values() → Record<string, number>` — Current value per category (fps/low1/cpuMs exist only once there are frame times)
|
|
10
10
|
- `budget.byTag() → BudgetTagStat[]` — Estimate draw calls and triangles by userData.budgetTag (visible meshes inside the frustum; shadow casters count a second shadow draw). Returns [{ tag, drawCalls, triangles }], largest first. Called only on overrun (at most once a second) or when debugging
|
|
11
11
|
- Properties:
|
|
12
12
|
- `enabled: boolean` Is it on?
|
|
13
|
-
- `limits: BudgetLimits` Current limits
|
|
13
|
+
- `limits: BudgetLimits` (experimental) Current limits
|
|
14
14
|
- `cost: ApplyCost` Cost of applying background results, split in stages (see ApplyCost)
|
|
15
15
|
|
|
16
16
|
## Data structures
|
|
@@ -23,6 +23,10 @@
|
|
|
23
23
|
- `textures?: number` Texture count
|
|
24
24
|
- `chunkApplyMs?: number` Terrain chunk upload milliseconds per frame
|
|
25
25
|
- `rigidBodies?: number` Rigid body count
|
|
26
|
+
- `lights?: number` Lit point + spot lights, a game's own and pooled ones (default limit 8)
|
|
27
|
+
- `shadowLights?: number` Lit point + spot lights that cast shadows
|
|
28
|
+
- `shadowMaps?: number` Shadow maps drawn each frame, sun and cascades included, a point light counts six
|
|
29
|
+
- `shadowMapSize?: number` The largest side of a shadow map, in pixels
|
|
26
30
|
- `applyTransitMs?: number` Per-frame cost of applying background results, by stage (engine.budget.cost): worker transit (approximate), creating three.js objects, colliders, GPU upload (approximate), stream build()
|
|
27
31
|
- `applyBuildMs?: number`
|
|
28
32
|
- `applyColliderMs?: number`
|
package/docs/api/calendar.md
CHANGED
|
@@ -4,7 +4,7 @@ Time of day, day, seasons and clock-time timers (calendar() module); NPC schedul
|
|
|
4
4
|
|
|
5
5
|
- Options `CalendarOptions`:
|
|
6
6
|
- `time?: string | number` Time of day at start: 'HH:MM' or fraction of a day 0–1 (0.5 noon), default 0.33 (afterwards read / write engine.calendar.timeOfDay)
|
|
7
|
-
- `dayLength?: number`
|
|
7
|
+
- `dayLength?: number` Calendar seconds per day, default Infinity: the time of day never moves until the game sets a length (presets.calendar.cycle has 360) (one hour = dayLength / hoursPerDay calendar seconds; with clock.rate 1 calendar seconds are real seconds)
|
|
8
8
|
- `hoursPerDay?: number` Hours per day of the displayed clock and of clock notation ('18:30'), default 24
|
|
9
9
|
- `day?: number` Which day to start from, default 1
|
|
10
10
|
- `daysPerSeason?: number` Days of each season given by name only, default 7
|
|
@@ -15,22 +15,21 @@ Time of day, day, seasons and clock-time timers (calendar() module); NPC schedul
|
|
|
15
15
|
- `calendar.between(from: string | number, to: string | number, opts: CalendarBetweenOptions) → Handle` — Time-range switch: on() while clock time is in [from, to), otherwise off() (from > to wraps midnight). Aligns once immediately on registration, new game, load, applying a scenario and time rewind; afterwards it calls on/off when crossing a boundary. Example: `engine.calendar.between('09:00', '17:00', { on: () => shop.open(), off: () => shop.close() })`
|
|
16
16
|
- `calendar.daily(fn: (day: number) => void, opts?: CalendarAtOptions) → Handle` — Call fn(day) at the start of each day (00:00)
|
|
17
17
|
- `calendar.onSeason(name: string, fn: (season: string) => void) → Handle` — Call fn(seasonName) on entering season name
|
|
18
|
-
- `calendar.untilMark() → number` —
|
|
18
|
+
- `calendar.untilMark() → number` — (experimental) Calendar seconds until the next clock mark (midnight, at times, between edges); engine.skip ends a segment there; Infinity when the time of day never moves
|
|
19
19
|
- Properties:
|
|
20
|
-
- `hoursPerDay: number` Hours per day (clock notation 'HH:MM', schedules, at / between)
|
|
21
|
-
- `
|
|
22
|
-
- `
|
|
23
|
-
- `timeOfDay: number` Time of day: 0-1 (0 midnight, 0.25 6am, 0.5 noon, 0.75 6pm); one day = dayLength game seconds (the unit of engine.clock.now). Writing it later in the day counts as time passing (at timers crossed fire); writing it earlier only resets the timers' baseline
|
|
20
|
+
- `hoursPerDay: number` (experimental) Hours per day (clock notation 'HH:MM', schedules, at / between)
|
|
21
|
+
- `seasons: string[]` (experimental) Season names, [] when the game has no seasons (the default)
|
|
22
|
+
- `timeOfDay: number` Time of day: 0-1 (0 midnight, 0.25 6am, 0.5 noon, 0.75 6pm); one day = dayLength calendar seconds (the unit of engine.clock.now). Writing it later in the day counts as time passing (at timers crossed fire); writing it earlier only resets the timers' baseline
|
|
24
23
|
- `day: number` Day number (1-based); writing it fires no day:start
|
|
25
|
-
- `dayLength: number`
|
|
24
|
+
- `dayLength: number` Calendar seconds per day (1 hour = dayLength / hoursPerDay calendar seconds; at clock.rate 1 calendar seconds equal real seconds); Infinity = the time of day never moves. Changing it keeps the current time of day
|
|
26
25
|
- `clock: string` Clock text, e.g. "18:00"
|
|
27
26
|
- `daylight: number` Daylight from the clock 0-1 (0 from 18:00 to 06:00, 1 at noon; a sine over the day). Audio rules { daylight }, ambience and the sky's default sun read it
|
|
28
27
|
- `isDay: boolean` Whether it is daytime by the clock (06:00-18:00 of the day's hours)
|
|
29
|
-
- `seasonIndex: number` Current season index, -1 without seasons
|
|
28
|
+
- `seasonIndex: number` (experimental) Current season index, -1 without seasons
|
|
30
29
|
- `season: string | null` Current season name, e.g. 'spring'; null without seasons
|
|
31
|
-
- `dayOfSeason: number` Day within the season (1-based); 0 without seasons
|
|
32
|
-
- `seasonProgress: number` Fraction of the season elapsed, 0-1 (includes time of day); 0 without seasons
|
|
33
|
-
- `totalDays: number` Total game time in days (fractional), for growth, cooldowns and the like
|
|
30
|
+
- `dayOfSeason: number` (experimental) Day within the season (1-based); 0 without seasons
|
|
31
|
+
- `seasonProgress: number` (experimental) Fraction of the season elapsed, 0-1 (includes time of day); 0 without seasons
|
|
32
|
+
- `totalDays: number` (experimental) Total game time in days (fractional), for growth, cooldowns and the like
|
|
34
33
|
|
|
35
34
|
## Data structures
|
|
36
35
|
- **CalendarAtOptions** Parameters of calendar.at() / daily()
|
package/docs/api/cameraRig.md
CHANGED
|
@@ -6,18 +6,18 @@ Current camera (one of followCamera / firstPersonCamera / fixedCamera / rtsCamer
|
|
|
6
6
|
- `projection?: 'perspective' | 'orthographic'` 'orthographic' draws without perspective (isometric / 2.5D; the wheel then changes size); default 'perspective'
|
|
7
7
|
- `size?: number` With projection 'orthographic': world units of view height, default 20
|
|
8
8
|
- `yaw?: number` Which side of the focus the camera sits on (radians), default 0.8: camera = focus + (sin yaw, cos yaw) × distance, it looks along forward() = -(sin yaw, cos yaw). Behind a character facing f: yaw = f + PI
|
|
9
|
-
- `pitch?: number` Pitch angle (radians), default 0.42
|
|
9
|
+
- `pitch?: number` Pitch angle (radians), default 0.42. Positive = camera above the look point, looking down: the opposite of firstPersonCamera's pitch
|
|
10
10
|
- `distance?: number` Distance (meters), default 13
|
|
11
11
|
- `minDistance?: number` Zoom range (meters)
|
|
12
12
|
- `maxDistance?: number`
|
|
13
13
|
- `height?: number` How high above the character to look at (meters), default 1.4
|
|
14
|
-
- `smoothing?: number` Follow smoothing, default 10
|
|
14
|
+
- `smoothing?: number` (experimental) Follow smoothing, default 10
|
|
15
15
|
- `sensitivity?: number` Drag sensitivity, default 1
|
|
16
16
|
- `minPitch?: number` Pitch range (radians)
|
|
17
|
-
- `maxPitch?: number`
|
|
18
|
-
- `zoomStep?: number` Zoom ratio per wheel notch, default 0.1
|
|
19
|
-
- `groundClearance?: number` Minimum camera height above the ground (meters), default 1.2
|
|
20
|
-
- `invertY?: boolean` Invert vertical
|
|
17
|
+
- `maxPitch?: number` (experimental)
|
|
18
|
+
- `zoomStep?: number` (experimental) Zoom ratio per wheel notch, default 0.1
|
|
19
|
+
- `groundClearance?: number` (experimental) Minimum camera height above the ground (meters), default 1.2
|
|
20
|
+
- `invertY?: boolean` (experimental) Invert vertical
|
|
21
21
|
- `lockPitch?: boolean` Lock the pitch angle (top-down games)
|
|
22
22
|
- `shoulder?: number` Over-the-shoulder offset: meters to the right of the target the camera aims (negative = left shoulder), default 0
|
|
23
23
|
- `pointerLock?: boolean` Click locks the mouse; mouse motion turns the view without dragging (Esc releases), default false
|
|
@@ -31,46 +31,46 @@ Current camera (one of followCamera / firstPersonCamera / fixedCamera / rtsCamer
|
|
|
31
31
|
- `sensitivity?: number` Mouse sensitivity, default 1
|
|
32
32
|
- `fov?: number | null` Field of view (degrees); unchanged if omitted
|
|
33
33
|
- `headBob?: number` Walking bob amplitude (meters), 0 off, default 0.04
|
|
34
|
-
- `bobFrequency?: number` Bobs per meter
|
|
35
|
-
- `hideTarget?: boolean` Hide the character itself (its shadow remains), default true
|
|
34
|
+
- `bobFrequency?: number` (experimental) Bobs per meter
|
|
35
|
+
- `hideTarget?: boolean` (experimental) Hide the character itself (its shadow remains), default true
|
|
36
36
|
- `hideLayer?: number` Layer number used for hiding 0–31
|
|
37
37
|
- `pointerLock?: boolean` Click to lock the mouse, default true
|
|
38
38
|
- `swallowLockClick?: boolean` The press that locks the mouse is not delivered as Mouse0 / a click (default true); false delivers it too
|
|
39
39
|
- `yaw?: number` Initial heading (radians)
|
|
40
|
-
- `pitch?: number`
|
|
41
|
-
- `minPitch?: number` Look down / up limit (radians)
|
|
42
|
-
- `maxPitch?: number`
|
|
43
|
-
- `yawLimits?: number[] | null` Turn range left / right [min, max] (radians), unlimited by default
|
|
44
|
-
- `smoothing?: number` Smoothing of the camera following the body
|
|
45
|
-
- `invertY?: boolean` Invert vertical
|
|
40
|
+
- `pitch?: number` Initial look angle (radians), default 0 = level. Positive looks up, negative down: the opposite of followCamera's pitch
|
|
41
|
+
- `minPitch?: number` Look down / up limit (radians), default -1.45 / 1.45
|
|
42
|
+
- `maxPitch?: number` (experimental)
|
|
43
|
+
- `yawLimits?: number[] | null` (experimental) Turn range left / right [min, max] (radians), unlimited by default
|
|
44
|
+
- `smoothing?: number` (experimental) Smoothing of the camera following the body
|
|
45
|
+
- `invertY?: boolean` (experimental) Invert vertical
|
|
46
46
|
- fixedCamera options `FixedCameraOptions` (also includes the fields of Partial<CameraShot>):
|
|
47
47
|
- `shots?: Record<string, CameraShot>` Shots: name → shot
|
|
48
48
|
- `start?: string | null` Initial shot name
|
|
49
49
|
- `auto?: false | 'nearest'` Automatic switching: false / 'nearest' (pick the one nearest to the player)
|
|
50
|
-
- `autoInterval?: number` Check interval for automatic switching (seconds)
|
|
50
|
+
- `autoInterval?: number` (experimental) Check interval for automatic switching (seconds)
|
|
51
51
|
- `hysteresis?: number` How many meters closer a new shot must be to switch (prevents flipping back and forth)
|
|
52
|
-
- `triggerBlend?: number` Transition seconds for trigger-zone switches (0 = hard cut)
|
|
53
|
-
- `trackHeight?: number` How high above the character a track shot looks (meters)
|
|
54
|
-
- `trackSmoothing?: number` Head-follow smoothing
|
|
55
|
-
- `holdDirection?: boolean` Keep the direction when switching shots until the direction key is released
|
|
52
|
+
- `triggerBlend?: number` (experimental) Transition seconds for trigger-zone switches (0 = hard cut)
|
|
53
|
+
- `trackHeight?: number` (experimental) How high above the character a track shot looks (meters)
|
|
54
|
+
- `trackSmoothing?: number` (experimental) Head-follow smoothing
|
|
55
|
+
- `holdDirection?: boolean` (experimental) Keep the direction when switching shots until the direction key is released
|
|
56
56
|
- `ease?: Ease` Transition easing
|
|
57
57
|
- rtsCamera options `RtsCameraOptions`:
|
|
58
58
|
- `height?: number` Camera height above the focus (meters), default 30
|
|
59
59
|
- `minHeight?: number` Zoom range (meters)
|
|
60
60
|
- `maxHeight?: number`
|
|
61
|
-
- `
|
|
61
|
+
- `pitch?: number` Pitch down angle (radians, π/2 = straight down), default 0.95
|
|
62
62
|
- `yaw?: number` Initial horizontal heading (radians)
|
|
63
|
-
- `panSpeed?: number` Pan speed multiplier
|
|
64
|
-
- `dragPan?: boolean` Drag with the mouse to pan, default true
|
|
65
|
-
- `edgePan?: boolean` Pan at the screen edge, default false
|
|
66
|
-
- `edgeSize?: number` Edge width (fraction of the screen)
|
|
63
|
+
- `panSpeed?: number` (experimental) Pan speed multiplier
|
|
64
|
+
- `dragPan?: boolean` (experimental) Drag with the mouse to pan, default true
|
|
65
|
+
- `edgePan?: boolean` (experimental) Pan at the screen edge, default false
|
|
66
|
+
- `edgeSize?: number` (experimental) Edge width (fraction of the screen)
|
|
67
67
|
- `bounds?: { minX?, maxX?, minZ?, maxZ? } | null` Focus range (meters)
|
|
68
68
|
- `rotate?: boolean` false: no turning. Default true: declares the actions rotateLeft / rotateRight (no keys; presets.bindings.rtsRotate binds Q / R)
|
|
69
|
-
- `rotateSpeed?: number` Rotation speed (radians/second)
|
|
70
|
-
- `zoomStep?: number` Zoom ratio per wheel notch
|
|
71
|
-
- `smoothing?: number` Smoothing
|
|
69
|
+
- `rotateSpeed?: number` (experimental) Rotation speed (radians/second)
|
|
70
|
+
- `zoomStep?: number` (experimental) Zoom ratio per wheel notch
|
|
71
|
+
- `smoothing?: number` (experimental) Smoothing
|
|
72
72
|
- `fov?: number | null` Field of view (degrees); unchanged if omitted
|
|
73
|
-
- `followLock?: boolean` Manual panning is not allowed while following
|
|
73
|
+
- `followLock?: boolean` (experimental) Manual panning is not allowed while following
|
|
74
74
|
- `start?: PositionLike | null` Initial focus (position)
|
|
75
75
|
|
|
76
76
|
## Methods and properties
|
|
@@ -103,7 +103,7 @@ Current camera (one of followCamera / firstPersonCamera / fixedCamera / rtsCamer
|
|
|
103
103
|
- `cam.cut(name: string)` — Cut to a shot immediately
|
|
104
104
|
- `cam.blend(name: string, opts?: { seconds?: number; ease?: Ease }) → Promise<void>` — Transition smoothly to a shot ({ seconds = 1, ease }); the Promise resolves when done
|
|
105
105
|
- `cam.nearest(p: Vector3) → string | null` — Name of the shot nearest to a point
|
|
106
|
-
- `shots: Record<string, any>` All shots
|
|
106
|
+
- `shots: Record<string, any>` All shots. A shot stays where it was placed: for a view that pans at a fixed angle use followCamera({ mouseLook: false }) (recipe 21 section 6)
|
|
107
107
|
- `current: string | null` Current shot name
|
|
108
108
|
- `auto: false | 'nearest'`
|
|
109
109
|
- `autoInterval: number`
|