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/recipes/31-audio.md
CHANGED
|
@@ -6,13 +6,8 @@ Everything you hear is the game's. The engine ships no sound files and plays not
|
|
|
6
6
|
|
|
7
7
|
## 1. Config in one place
|
|
8
8
|
Two places, one job each: **the asset manifest says what a sound is** (a file, or a synth function made in code, registered by name like a
|
|
9
|
-
model), **`audio.sounds` says how it plays** (which sound or variants, volume, bus, cooldown...).
|
|
10
|
-
(`footstep`, `shutter`, `thunder`, ambience's `wind` `rain` `water` `birds` `crickets`) as built-in sound assets that stay silent until a rule names them.
|
|
9
|
+
model), **`audio.sounds` says how it plays** (which sound or variants, volume, bus, cooldown...).
|
|
11
10
|
```js
|
|
12
|
-
engine.assets.manifest({ name: 'sfx', sounds: {
|
|
13
|
-
door: '/sfx/door.ogg', hit1: '/sfx/hit1.ogg', hit2: '/sfx/hit2.ogg', shot: '/sfx/shot.ogg',
|
|
14
|
-
ding: (a, p, out) => { a.tone({ freq: 880 * p.pitch, dur: 0.2, out }); return 0.2; }, // a synth: connect to out, return seconds (or { stop(t) })
|
|
15
|
-
} });
|
|
16
11
|
const engine = createEngine({ canvas, audio: {
|
|
17
12
|
levels: { music: 0.4, voice: 1 }, // volume per bus; an extra key (voice) adds a bus
|
|
18
13
|
sounds: {
|
|
@@ -27,13 +22,18 @@ const engine = createEngine({ canvas, audio: {
|
|
|
27
22
|
music: { tracks: { /* section 4 */ }, rules: [] },
|
|
28
23
|
footsteps: { beach: 'step.sand', default: 'footstep' }, // section 5
|
|
29
24
|
} });
|
|
25
|
+
engine.assets.manifest({ name: 'sfx', sounds: {
|
|
26
|
+
door: '/sfx/door.ogg', hit1: '/sfx/hit1.ogg', hit2: '/sfx/hit2.ogg', shot: '/sfx/shot.ogg',
|
|
27
|
+
ding: (a, p, out) => { a.tone({ freq: 880 * p.pitch, dur: 0.2, out }); return 0.2; }, // a synth: connect to out, return seconds (or { stop(t) })
|
|
28
|
+
} });
|
|
30
29
|
```
|
|
31
30
|
Code may hold functions (a `volume: e => ...`); the same config as data goes in a content pack (section 8). A full working one:
|
|
32
31
|
`examples/world/content/audio.js`.
|
|
33
32
|
|
|
34
33
|
## 2. Buses and sounds by name
|
|
35
34
|
Buses are real Web Audio `GainNode`s: `master`, `music`, `sfx`, `ambience`, `ui`, plus the game's own (`levels: { voice: 1 }` or
|
|
36
|
-
`engine.audio.addBus('voice')`). `engine.audio.setVolume('music', 0.3)` sets one; `engine.audio.buses.sfx` is the node to connect your own nodes to.
|
|
35
|
+
`engine.audio.addBus('voice')`). `engine.audio.setVolume('music', 0.3)` sets one; `engine.audio.buses.sfx` is the node to connect your own nodes to, and `buses.master` (also `audio.master`) is the total. `buses` is empty until audio
|
|
36
|
+
unlocks on the player's first click or key: build your own nodes on the `audio:ready` event. A name that is no bus warns once and gives `master`, so the sound still plays.
|
|
37
37
|
|
|
38
38
|
```js
|
|
39
39
|
engine.audio.sfx('door'); // plays on its bus (default sfx)
|
|
@@ -50,8 +50,7 @@ Built-in synth parameters (`params`): `wind` / `water` take `freq` (filter Hz),
|
|
|
50
50
|
4300); every synth also gets `pitch`, the sfx pitch multiplier (~1). A sound whose file fails to load keeps its ambience rule silent (one warning)
|
|
51
51
|
until the rules load again, instead of refetching.
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
Connect to `out` and return the length in seconds (or `{ stop(t) }` for a loop).
|
|
53
|
+
A synth with default params is `{ build: synthFn, params }` in the manifest.
|
|
55
54
|
|
|
56
55
|
## 3. Ambience: a rule table
|
|
57
56
|
Each rule names a sound and says when and how loud. A rule with `every` is a one-shot at random gaps; without, a loop that fades in and out (and stops
|
|
@@ -84,6 +83,7 @@ engine.music.intensity = 0.8; // stems fade in as
|
|
|
84
83
|
```
|
|
85
84
|
The same `when` keys as ambience. Tracks cross-fade (`fade`, default 2 s); a new rule result must hold `hold` seconds before switching.
|
|
86
85
|
`engine.music.override('boss')` picks by hand; `override(null)` hands back to the rules. `engine.music.stinger('win')` plays a short piece over the music.
|
|
86
|
+
Decoded music is large (about 21 MB a stereo minute), so it lives like any asset: `assets.release(name)` and `assets.trim()` (a level change calls it) free it, the longest-unused long sounds go by themselves over a memory budget, sounds still playing play on, and a freed sound loads again when played; effects under 10 s stay cached, and `preload: true` keeps a track.
|
|
87
87
|
|
|
88
88
|
## 5. Footsteps by surface
|
|
89
89
|
The player's footstep rhythm follows its speed (one step per foot landing). Each step plays the sound named by `footsteps[groundType]`, else
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
# Action game wiring: hp, attacks, enemy AI, drops and
|
|
1
|
+
# Action game wiring: hp, attacks, guns, enemy AI, drops, death, win and lose without engine combat rules
|
|
2
2
|
|
|
3
3
|
The engine has no health, damage, hit detection or death. An action game writes those as its own rules on top of systems that already exist. The
|
|
4
|
-
working example is `examples/action/` (page `/action.html`,
|
|
5
|
-
`tests/specs/action.mjs`.
|
|
4
|
+
working example is `examples/action/` (page `/action.html`, the rules in `main.js`, the room in `content/`).
|
|
6
5
|
|
|
7
6
|
## 1. What goes where
|
|
8
7
|
| Piece | Built on | In the example |
|
|
@@ -10,7 +9,7 @@ working example is `examples/action/` (page `/action.html`, about 150 lines of r
|
|
|
10
9
|
| The room, the enemy and its stats (hp, damage, drop) | content `templates` + `props` with ids (recipe 30) | `content/templates.js` `slime: { model, static: false, state: { hp, maxHp, damage, cooldown, drop } }` |
|
|
11
10
|
| Player hp, attack cooldown, game over | plain object + `engine.describe.add` + `engine.saves.register` | `const game = fresh()` |
|
|
12
11
|
| Attack, damage, enemy hit, death | ops with `can` / `run` (recipe 23), so keys, the dev bridge, MCP, tests and the AI run one rule | `player.attack`, `enemy.damage`, `enemy.attack`, `player.die` |
|
|
13
|
-
| Enemy AI (chase, face, strike) | `engine.world.simulate(kind, { near })
|
|
12
|
+
| Enemy AI (chase, face, strike) | `engine.world.simulate(kind, { near, channel? })` (channel: bullet time reaches it, section 4), a fixed step per near record; it strikes with `ops.run(..., { actor: rec.id })` | `world.simulate('slime', ...)` |
|
|
14
13
|
| Gameplay keys | content `actions` (`attack: { keys: ['Mouse0', 'KeyF'] }`), read with `input.pressed` in `onFixed` | `onFixed` runs `player.attack` |
|
|
15
14
|
| Drop | `engine.pickups.spawn(at, { give: item, id })` inside the death op; E picks it up through `interactions`, into the bag of whoever presses | `${id}-drop` |
|
|
16
15
|
| HUD, death screen, retry, save keys | `onFrame`: `hud.bar`, `toast`, `engine.session.newGame()` | the frame hook |
|
|
@@ -24,20 +23,32 @@ working example is `examples/action/` (page `/action.html`, about 150 lines of r
|
|
|
24
23
|
or test shapes instead (recipe 19).
|
|
25
24
|
- `player.die` decides what death does. The example offers `respawn` (`player.placeAt(spawn)`, full hp), `restart` and `gameover` (both end in
|
|
26
25
|
`engine.session.newGame()`, which is async flow and so runs from the frame hook, not inside the op).
|
|
26
|
+
- Win and lose are the game's rule too: one state field, judged last in the fixed step so it sees this step's hits. The end screen is a `makeWindow`
|
|
27
|
+
with `closable: false` (recipe 26).
|
|
28
|
+
|
|
29
|
+
## 2b. Guns: hitscan shots, spread, recoil
|
|
30
|
+
A hitscan weapon fires a ray, not a projectile (many real bullets in flight are `engine.swarm`, recipe 65). The shot is an op, so a key, a test and the dev bridge fire the same one.
|
|
31
|
+
- **The ray**: `engine.raycast(origin, direction, { far: range })` gives the nearest level or registered static mesh; `{ targets: 'all' }` adds rigid bodies.
|
|
32
|
+
An enemy that is neither: test its shape along the same ray and keep the nearer hit, so walls stop shots.
|
|
33
|
+
- **Aim**: build the direction from `engine.cameraRig.yaw` / `pitch`, not from `engine.camera`: the camera's matrix is only written on a drawn frame, so a fixed step or a test would read an old aim.
|
|
34
|
+
- **Spread**: bend the direction with `engine.random`, so a replay fires the same shots.
|
|
35
|
+
- **Recoil**: in the op, add to `cameraRig.pitch` and `yaw`, and let the view settle back in `onFixed`; the next shot's aim sees the climb. A first-person rig looks up with positive pitch, the follow camera with negative. The gun model's kick and the muzzle flash read the shot from an event in `onFrame`: they show, they change no rule.
|
|
27
36
|
|
|
28
37
|
## 3. Mouse attack and pointer lock
|
|
29
38
|
`followCamera({ ...presets.camera.overShoulder })` locks the mouse on a click. While locked, mouse buttons still arrive as `Mouse0`..`Mouse4` keys, so
|
|
30
|
-
`attack: { keys: ['Mouse0'] }` works in both states. The click that takes the lock is
|
|
31
|
-
|
|
32
|
-
looks, so a swing goes where you aim.
|
|
33
|
-
|
|
39
|
+
`attack: { keys: ['Mouse0'] }` works in both states. The click that takes the lock is swallowed, so it does not swing; `swallowLockClick: false` delivers it.
|
|
40
|
+
`presets.player.aim` turns the player toward where the camera
|
|
41
|
+
looks, so a swing goes where you aim. The rules do not need the picture: `?picture=none` runs them under the engine's placeholder lights; the whole picture is
|
|
42
|
+
`examples/action/picture/`.
|
|
34
43
|
|
|
35
44
|
## 4. Movement: jumps, speed effects, bullet time, platforms, falling
|
|
36
45
|
```js
|
|
37
46
|
createPlayer({ ...presets.player.thirdPerson, maxJumps: 2 }); // double jump: the same jump key twice
|
|
38
47
|
engine.player.launch(16, { owner: 'pad' }); // a jump pad / spring
|
|
39
48
|
engine.mod('move.speed', { owner: 'haste', id: 'player', mul: 1.2, for: 5 }); // haste for 5 s; no id = every character (mud, wind)
|
|
49
|
+
engine.time.channel('enemies'); // once, before anything uses it: a channel of your own
|
|
40
50
|
engine.mod('time.enemies', { owner: 'bullet-time', mul: 0.35, for: 2 }); // bullet time: enemies on channel 'enemies' at 35%
|
|
51
|
+
engine.world.simulate('slime', { near: chase, channel: 'enemies' }); // world records (the enemy AI above) get the slowed dt
|
|
41
52
|
engine.onFixed(dt => moveShots(dt), { channel: 'enemies' }); // your own enemy logic on the same slowed dt
|
|
42
53
|
engine.characters.support(liftMesh); // a moving platform: move liftMesh any way, riders follow
|
|
43
54
|
engine.player.mover = 'manual'; /* a cutscene, your own physics */ engine.player.mover = 'simple'; // take over, give back
|
|
@@ -52,12 +63,24 @@ engine.player.mover = 'manual'; /* a cutscene, your own physics */ engine.player
|
|
|
52
63
|
'player', set: 0, for: 0.8 })`. `move()` takes no speed argument; the direction's length (0-1) scales the speed.
|
|
53
64
|
- **Bullet time / time channels**: a character the engine drives moves and animates on `character.channel` (player `'player'`, NPCs `'world'`), so
|
|
54
65
|
`engine.mod('time.enemies', { owner: 'bullet-time', mul: 0.35 })` slows NPCs added with `npcs.add({ channel: 'enemies' })` (far ones too) and
|
|
55
|
-
`onFixed(fn, { channel: 'enemies' })` code; `
|
|
66
|
+
`onFixed(fn, { channel: 'enemies' })` code; world records follow only with `world.simulate(kind, { near, channel: 'enemies' })` (without it they
|
|
67
|
+
keep the 'world' pace while everything else slows); `clock.after(1, 'poison:tick', { data, channel: 'enemies' })` slows a timer with them. The player keeps
|
|
56
68
|
full speed unless you mod `'time.player'`. Your own `player.move(x, z, run, dt)` uses the dt you pass. Effects end in any order (recipe 55).
|
|
57
69
|
- **Platforms**: `characters.support(object, { id?, safe?, carry?: 'position' | 'position+yaw', inherit? })` returns `{ id, remove() }`. The rider
|
|
58
70
|
compares the platform's matrix with the one it recorded, so it does not matter whether the platform moves in your `onFixed` before or after the
|
|
59
71
|
player, in a timeline or in physics. `player.support` says what it stands on (`kind: 'ground' | 'platform' | 'collider' | 'water' | null`, the
|
|
60
72
|
platform's `velocity`); jumping off keeps the platform's speed until landing. With `mover: 'rapier'` give the platform a collider as well.
|
|
73
|
+
**What it needs**: the standing height is the top of the bounding box of every mesh under the object you pass, over that box's footprint. Pass the
|
|
74
|
+
floor mesh, not the whole model: a group with a mast or a railing has its top up there, and the character passes under it to whatever is below (a
|
|
75
|
+
boat at sea leaves it on the sea floor). A character gets on when its feet are at most `stepHeight` below the top, or it falls or is placed onto
|
|
76
|
+
it (`placeAt` over a support stands on it). Moving the parent moves the floor mesh, so move the whole model as you like.
|
|
77
|
+
```js
|
|
78
|
+
const raft = new THREE.Group(), deck = new THREE.Mesh(new THREE.BoxGeometry(3, 0.2, 2), wood);
|
|
79
|
+
raft.add(deck, mast); engine.scene.add(raft);
|
|
80
|
+
engine.characters.support(deck, { id: 'raft' }); // the deck, not the raft with its mast
|
|
81
|
+
engine.onFixed(dt => { raft.position.x += 1.5 * dt; }); // the player on it is carried
|
|
82
|
+
```
|
|
83
|
+
A ride the player does not steer is `engine.control` instead (recipe 57, Moved by script).
|
|
61
84
|
- **Falling out**: `createPlayer({ ..., fall: { belowY: -20 } })` fires `character:fall { character, safe, preventDefault() }` once and puts the player
|
|
62
85
|
back on `player.safeGround` (the last spot it stood still on safe, unmoving ground; saved). Take hp in the listener; `preventDefault()` to handle it yourself.
|
|
63
86
|
- **Your own controller**: `mover: 'manual'` = you write the position; `move()` then only updates `grounded`, `support` (platforms still carry),
|
|
@@ -30,8 +30,8 @@ const vista = engine.stream.source(towerTop, { detail: 'simple', radius: 600 });
|
|
|
30
30
|
```
|
|
31
31
|
- `radius` caps every loader's own range around that source (terrain view distance, present radius, `stream.radius`); without it each loader uses its own.
|
|
32
32
|
- `source.ready` is checked at the end of each frame; a new source counts after one full frame, so every loader has seen it. Fixed steps must run
|
|
33
|
-
(collision takes effect on a tick), so do not wait while `engine.
|
|
33
|
+
(collision takes effect on a tick), so do not wait while `engine.haltLoop()` is on without stepping.
|
|
34
34
|
- Leaving a place and coming back is safe: models unload, but records (an opened chest, a dropped item, a removed rock) stay in `engine.world` and the
|
|
35
35
|
models are rebuilt from them.
|
|
36
36
|
- Module authors with their own distance-based loader: read `engine.stream.sources({ detail: 'full' })` / `sources({ physics: true })` and
|
|
37
|
-
`s.reach(range)`, and register `engine.stream.
|
|
37
|
+
`s.reach(range)`, and register `engine.stream.addReadyCheck(name, s => ...)`. Do not read `engine.focus` or the player position for loading.
|
|
@@ -1,59 +1,171 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
engine.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
engine
|
|
13
|
-
engine.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
-
|
|
1
|
+
# Lights, fog, exposure and environment lighting
|
|
2
|
+
|
|
3
|
+
**In this recipe**: Lights · Fog · Exposure and the tone curve · The sky as a map · Light probes · Lightmaps · Real-time bounced light · Light you can see in the air · Occlusion culling
|
|
4
|
+
|
|
5
|
+
Lights, fog and exposure are your own three.js code ([recipe 62](62-picture-code.md)): the sky computes signals and draws its dome, it writes none of them. The sky itself is `08-weather-sky.md`.
|
|
6
|
+
|
|
7
|
+
## Lights: the placeholders, and your own
|
|
8
|
+
The engine has one directional light (`engine.lights.sun`) and one hemisphere (`engine.lights.hemi`): still white placeholders (sun 2 at (40, 80, 30) with soft shadows, hemi 1.2), so a scene
|
|
9
|
+
with no picture code is neutral gray and not black. Nothing moves them, with or without a sky.
|
|
10
|
+
|
|
11
|
+
```js
|
|
12
|
+
const engine = createEngine({ canvas, lights: false }); // the placeholders stay out of the scene
|
|
13
|
+
const sun = new THREE.DirectionalLight(0xffd0a0, 2); engine.scene.add(sun, sun.target); // add your own lights before engine.start()
|
|
14
|
+
engine.onRender(() => { sun.position.copy(engine.uniforms.uSunDir.value).multiplyScalar(100); sun.intensity = 2 * engine.uniforms.uDaylight.value * engine.uniforms.uWeatherLight.value; });
|
|
15
|
+
const torch = new THREE.PointLight(0xffa040, 6, 12); engine.add(torch);
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
- `createEngine({ lights: false })`: the default sun and hemisphere are never put in the scene, `engine.lights.sun` / `hemi`
|
|
19
|
+
stay as detached objects so nothing reads `undefined`. Use it for a scene lit entirely by your own lights.
|
|
20
|
+
- Shadows: only the engine sun's box is managed. Your own `castShadow` lights work as in three.js, each costing its
|
|
21
|
+
own shadow pass; `engine.shadows` (recipe 45) takes them when you hand them in, and `engine.shadows.enabled = false` turns every shadow off.
|
|
22
|
+
- Add or remove lights before `engine.start()`; what a change costs mid-play, and many lamps with `lightPool`: recipe 09 "Lights and stalls".
|
|
23
|
+
|
|
24
|
+
## Fog: plain three.js, signals, your own math
|
|
25
|
+
```js
|
|
26
|
+
const fog = engine.scene.fog = new THREE.Fog(0x99bbbb, 60, 220); // or new THREE.FogExp2(color, density)
|
|
27
|
+
engine.onRender(() => { // a fog that follows the day and the weather: your picture/ code
|
|
28
|
+
fog.color.copy(engine.uniforms.uSkyHorizon.value);
|
|
29
|
+
fog.far = 220 / engine.uniforms.uWeatherFog.value;
|
|
30
|
+
});
|
|
31
|
+
```
|
|
32
|
+
There is no fog until your code makes one, and nothing writes it after that.
|
|
33
|
+
|
|
34
|
+
- Signals to read: `uSkyHorizon` is the color at the horizon, so fog in that color hides the line where the dome meets the ground; `uWeatherFog` is what the weather asks for, a
|
|
35
|
+
multiplier your code applies; `uViewDistance` says how far the world is meant to be seen (`terrain({ viewFog: true })` writes it).
|
|
36
|
+
- A fog color of your own that differs from the horizon: the dome fades its lower band to it, so fogged ground and sky still meet without a line.
|
|
37
|
+
- Color, near, far and density are live. Adding or removing `scene.fog`, or changing its type, recompiles materials once: do it at a scene change, not every frame.
|
|
38
|
+
- Your own fog math (height fog, a warm far haze): the `fogPars` and `fog` slots on a material, WebGL only (recipe 43), or your own `ShaderMaterial`:
|
|
39
|
+
`applyEffects(material, { patches: [{ name: 'haze', slot: 'fog', glsl: 'float f = 1.0 - exp(-fogDensity * vFogDepth); gl_FragColor.rgb = mix(gl_FragColor.rgb, vec3(1.0, 0.85, 0.7), f * 0.3);' }] })`.
|
|
40
|
+
- Check the result with `engine.describe('picture').picture.fog`; `threedog shot` says how much of the picture the fog makes up.
|
|
41
|
+
|
|
42
|
+
## Exposure and the tone curve
|
|
43
|
+
```js
|
|
44
|
+
engine.renderer.toneMappingExposure = 1.3;
|
|
45
|
+
engine.onRender(() => { engine.renderer.toneMappingExposure = 1 + 0.5 * (1 - engine.uniforms.uDaylight.value); }); // over the day: your picture/ code
|
|
46
|
+
engine.renderer.toneMapping = THREE.NeutralToneMapping; // the curve; materials recompile on their next draw
|
|
47
|
+
```
|
|
48
|
+
The engine picks no curve: `renderer.toneMapping` stays three.js's default (`NoToneMapping`) until your code writes it. A curve of your own is a post effect in the `'tone'` slot (recipe 52).
|
|
49
|
+
|
|
50
|
+
## Environment maps
|
|
51
|
+
`scene.environment` is plain three.js and stays `null` until your code writes it. The background (the sky dome or a skybox) and the environment lighting are two separate fields.
|
|
52
|
+
|
|
53
|
+
```js
|
|
54
|
+
const env = engine.sky.environment({ into: engine.scene }); // the sky as a map: follows the time of day; env.texture is the live map
|
|
55
|
+
engine.scene.environmentIntensity = 0.8; // intensity and rotation are three.js
|
|
56
|
+
engine.scene.environmentRotation.y = Math.PI / 2;
|
|
57
|
+
env.remove(); // takes the map off, frees it
|
|
58
|
+
// an asset panorama: plain PMREMGenerator
|
|
59
|
+
const pmrem = new THREE.PMREMGenerator(engine.renderer);
|
|
60
|
+
engine.assets.useTexture('hdr/studio.hdr', t => { t.mapping = THREE.EquirectangularReflectionMapping; engine.scene.environment = pmrem.fromEquirectangular(t).texture; });
|
|
61
|
+
// a PMREM result of your own is used as it is
|
|
62
|
+
engine.scene.environment = myPmremTarget.texture;
|
|
63
|
+
```
|
|
64
|
+
On `renderer: 'webgpu'` take `PMREMGenerator` from `three/webgpu`. A map you made is yours to dispose.
|
|
65
|
+
|
|
66
|
+
### The sky as a map: `engine.sky.environment({ into?, interval? })`
|
|
67
|
+
- Nothing is built before this call. Without `into` nothing is written anywhere: read `handle.texture` (a live getter) and put it on the materials you choose (`material.envMap`).
|
|
68
|
+
- With `into`, that object's `.environment` gets the map at each rebuild. A map you write there yourself stays: the rebuilds go on, but only `handle.texture` follows them.
|
|
69
|
+
- The dome is rendered into a cube and prefiltered with `PMREMGenerator`. It is rebuilt only when the sky colors, sun direction or cloud
|
|
70
|
+
cover actually changed AND at least `interval` seconds (default 1, 4 on a low-tier device; a number the game gives stands) passed since the last check, never every frame. A fixed time of
|
|
71
|
+
day builds once. A call before the first frame waits for that frame, so the map uses real colors. One map at a time: a second call replaces the first.
|
|
72
|
+
- The cube is at least 256 px per face (PMREMGenerator's floor in 0.187), so a low tier saves time by rebuilding less often, or by your `picture/` code skipping the call on `engine.tier === 'low'`.
|
|
73
|
+
- An asset map is a fixed photo: it does not dim at night. Write `scene.environmentIntensity` from your own frame code reading `engine.uniforms.uDaylight`.
|
|
74
|
+
|
|
75
|
+
### What a MeshLambertMaterial does with it (three 0.187)
|
|
76
|
+
The engine's neutral materials are Lambert, so this is what most surfaces do by default.
|
|
77
|
+
- A Lambert material gets soft, direction-dependent ambient light colored by the environment (sky blue from above, ground color from below), and no specular: for reflections use a Standard / Physical material.
|
|
78
|
+
- The hemisphere light stays and adds on top. When you turn the environment on, lower your hemisphere light so shadows do not wash out.
|
|
79
|
+
- The first frame with an environment recompiles every Lambert program once; do it at start-up, not mid-game.
|
|
38
80
|
- Toon, Basic and ShaderMaterial surfaces ignore it.
|
|
39
81
|
|
|
40
82
|
## Light probes (baked indirect light)
|
|
41
|
-
An environment map lights everything as seen from one point. Light probes record how the light changes from place to place (a colored glow beside
|
|
42
|
-
a bright wall, dimmer light under a roof) and
|
|
83
|
+
An environment map lights everything as seen from one point. Light probes (`engine.bakeProbes`) record how the light changes from place to place (a colored glow beside
|
|
84
|
+
a bright wall, dimmer light under a roof), and every lit pixel takes its own light from the grid, on WebGL and WebGPU, with no shader of your own.
|
|
43
85
|
```js
|
|
44
86
|
const probes = await engine.bakeProbes({ bounds: { min: [-30, 0, -30], max: [30, 8, 30] }, spacing: 4, include: o => !o.userData.moving });
|
|
45
|
-
const file = JSON.stringify(probes.toJSON()); // ship this
|
|
46
|
-
const shipped = engine.loadProbes(json
|
|
47
|
-
probes.sample(cart.position
|
|
87
|
+
const file = JSON.stringify(probes.toJSON()); // ship this (half precision, a few tens of KB)
|
|
88
|
+
const shipped = engine.loadProbes(json); // at start-up, instead of the bake; either renderer reads either renderer's file
|
|
89
|
+
probes.sample(cart.position); // the SH at any point, for a "how dark is it here"
|
|
48
90
|
probes.remove();
|
|
49
91
|
```
|
|
50
|
-
- What it builds:
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
92
|
+
- What it builds: three's probe grid over `bounds` (`LightProbeGridWebGL` or `LightProbeGrid`; step at most `spacing`, at least 2 layers per axis), in the scene as
|
|
93
|
+
`probes.grid`, a plain three.js light: `priority` and `visible` are yours; `intensity` works on WebGPU only, three's WebGL shader ignores it. The light costs almost nothing per frame.
|
|
94
|
+
- **Outside the grid there is no probe light**, and with no other ambient light a mesh goes black there. The light reaches half a step past `bounds`, so a roof on the edge is fine.
|
|
95
|
+
Size `bounds` to where things are.
|
|
96
|
+
- **Light counted twice**: the bake saw the hemisphere light and the environment, and they still add at run time. Lower them where the probes take over, or bake without them.
|
|
97
|
+
A `material.lightMap` inside the grid doubles the same way. A warning says so when the set is added, and describe keeps saying it.
|
|
98
|
+
- Dark bake indoors: `scene.background` is a display color, far weaker than the sun, so a room lit by the sky comes out black. Raise the sky just for the bake
|
|
99
|
+
(a brighter `scene.background` or `backgroundIntensity`, put back after), and keep a little fill for walls that face away from every window.
|
|
100
|
+
- Cost: 6 renders per probe at load time, a few probes per task, so the page keeps drawing (`probes.bakeMs` says how long). Bake once and ship the JSON: phones often cannot bake, but
|
|
101
|
+
they all read the file. Meshes `include` rejects are hidden only while the cubes render. Adding a grid recompiles lit materials once, so do it at start-up.
|
|
102
|
+
- Check it: `engine.describe().render.probes` (count, step, source, owner, `outside`: lit objects the grid does not hold, `doubled`: what counts twice) and `engine.debug.view('probes')` (a dot per probe in its average color).
|
|
103
|
+
|
|
104
|
+
## Lightmaps (baked light on what never moves)
|
|
105
|
+
The best-looking baked light, and free at run time: it is plain `material.lightMap` on a second UV set, so a file baked on WebGPU draws the same on WebGL. Baking needs a real GPU and Google Chrome on the machine that bakes, not on the player's.
|
|
106
|
+
```js
|
|
107
|
+
floor.userData.static = true; wall.userData.static = true; // named meshes that never move
|
|
108
|
+
// npx threedog bake light --page "/?bake=1" --out public/light/level.lightmap --size 1024
|
|
109
|
+
const baking = new URLSearchParams(location.search).has('bake'); // the bake must see the lights the map replaces
|
|
110
|
+
if (!baking) {
|
|
111
|
+
const light = await engine.loadLightmap('light/level.lightmap'); // once the level is built
|
|
112
|
+
hemi.visible = false; // the bake saw it: keep the sun, drop the ambient
|
|
113
|
+
}
|
|
114
|
+
floor.material.lightMapIntensity = 1.2; // plain three.js, yours
|
|
115
|
+
```
|
|
116
|
+
- What is baked: sky and bounced light, by rays traced from every lightmap texel through the static meshes, so light stops at walls and a pillar shades what stands behind it. The sun stays real-time where it lands, so moving things keep their shadows, and its bounce is in the map. The game's hemisphere or ambient light is the sky during the bake, at the same strength: an open floor comes out as bright as under that light.
|
|
117
|
+
- Turning the ambient off: a line that sets `intensity` once is lost if picture code writes it every frame, as the template's `picture/lights.js` does. So hide the light (`visible = false`, which that code leaves alone) or change it where it is written. Do it behind a URL flag as above, not in the palette: with the ambient gone for good, the next bake sees no sky. A bake that sees no light at all stops and writes nothing.
|
|
118
|
+
- Instanced and skinned meshes and anything moving cannot hold a lightmap: give them `engine.bakeProbes`. A grid also lights the baked meshes, so where the two overlap the light doubles; keep the grid's `bounds` to where the moving things go, or turn `lightMapIntensity` down.
|
|
119
|
+
- Files are large: half precision, 8 MB at 1024, 32 MB at 2048, before the server's compression. Start small.
|
|
120
|
+
- Check it: `engine.describe().render.lightmap` lists `skipped` (instanced), `missing` (not found, or changed since the bake: bake again), `moved`, `doubled` (ambient light or a grid on top) and `shared` (an unbaked mesh on a baked material: give it its own).
|
|
121
|
+
- WebGPU and TSL: nothing changes. `material.lightMap` is read by node materials too, so there is no separate form.
|
|
122
|
+
|
|
123
|
+
## Real-time bounced light (WebGPU games only)
|
|
124
|
+
|
|
125
|
+
Bake first when the scene holds still: probes and lightmaps match it and cost nearly nothing. Real-time bounce is for light that changes while the world stands: a sun that moves, a lamp the player carries, a door that lets a room fill. It needs `renderer: 'webgpu'` chosen when the game starts, and three's real WebGPU backend; there is no WebGL version.
|
|
126
|
+
|
|
127
|
+
```js
|
|
128
|
+
import { voxelGI, temporalAA } from '@threedog/post-effects/tsl';
|
|
129
|
+
engine.post.add(voxelGI({ bounds: new THREE.Box3(min, max), intensity: 1 }));
|
|
130
|
+
engine.post.add(temporalAA()); // clears the dots; it replaces MSAA while it is on
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
- `bounds` is the world box to voxelize. Keep it tight: the same voxels spread over a town are too coarse for a room. `describe().render.post` gives `voxelSize`; judge it against the smallest thing that should throw color.
|
|
134
|
+
- Lights can move every frame. Geometry cannot: moving things go outside the volume (`setup: gi => gi.volume.layers...`), and a rare change (a wall falls) calls `gi.needsUpdate = true`, a stall of many milliseconds.
|
|
135
|
+
- It bounces direct light only, so sky light stays yours: a low hemisphere or environment light, judged by eye once the bounce is on. How to judge: a colored wall should tint what stands next to it, and a sunlit floor should lift the ceiling, without the shadows turning flat. A cartoon look may want one soft bounce; a realistic interior wants more with less fill.
|
|
136
|
+
- Changing any post effect (add, remove, on / off, a setting that rebuilds) rebuilds the chain, and that voxelizes the scene again: a stall. Set the chain at a scene change, not during play.
|
|
137
|
+
- `occlusion` (0 to 1) darkens corners from the voxels. It darkens direct light too, which is why it starts at 0.
|
|
138
|
+
- It costs real frame time on weak GPUs, so it declares `skipOnLowTier` and is held off on `engine.tier === 'low'`. It is also held on a device that fell back from WebGPU and under `forceWebGL: true`. Nothing breaks, `describe().render.post` says `held` and why, so give those players probes or a lightmap as the base.
|
|
139
|
+
- Does not work: metal gets a diffuse bounce instead of a reflection; anything moving is not in the bounce; transparent things are not handled; one volume does not cover a big open world.
|
|
140
|
+
|
|
141
|
+
What runs where, for `voxelGI` and the three effects around it (`temporalAA`, and `sunShafts` and `lightVolumes` of the next section). Held means the game's `enabled` stays as written, the effect costs nothing, and `describe().render.post` says why:
|
|
142
|
+
|
|
143
|
+
| Case | voxelGI | temporalAA, sunShafts, lightVolumes |
|
|
144
|
+
|---|---|---|
|
|
145
|
+
| Real WebGPU | runs (held on `engine.tier` 'low') | run |
|
|
146
|
+
| WebGL2 backend (no WebGPU in the browser, or `forceWebGL: true`) | held | run |
|
|
147
|
+
| Fell back to `WebGLRenderer` (`start()` found no WebGPU) | held | held |
|
|
148
|
+
| Game chose WebGL (`--webgl`, `WebGLRenderer`) | throws by name | throw by name |
|
|
149
|
+
|
|
150
|
+
## Light you can see in the air
|
|
151
|
+
|
|
152
|
+
Pick by the light. These two are WebGPU only; a WebGL game keeps the depth haze of recipe 59.
|
|
153
|
+
|
|
154
|
+
```js
|
|
155
|
+
import { sunShafts, lightVolumes } from '@threedog/post-effects/tsl';
|
|
156
|
+
engine.post.add(sunShafts({ light: engine.lights.sun })); // sun through gaps
|
|
157
|
+
engine.post.add(lightVolumes({ bounds: new THREE.Box3(min, max) })); // spot cones, point glows
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
- `sunShafts` (three's `GodraysNode`) marches the sun's shadow map, so the sun and whatever makes the gaps must cast shadows. It is made for air that is mostly in shadow: a room with a window, a forest. In open daylight every pixel of air is lit and it reads as haze; there, lower `density` or leave it out. Raise `density` until the beam reads against the dark behind it, and stop before the far wall washes out. A misty horror game and a clean sunny one will end far apart.
|
|
161
|
+
- `lightVolumes` (three's `VolumeNodeMaterial`) fills a box of air and lights it from point and spot lights, shadows included. **The sun does nothing here**, three skips lights at infinity. It is dithered, so run `temporalAA` after it. `scattering: (tsl, { positionRay, density }) => ...` gives density per point for smoke or ground fog; multiply by `uniforms(engine).uWeatherFog` from `threedog/tsl` to follow the weather.
|
|
162
|
+
- Does not work: shafts from more than one light at once, cones through transparent glass, and either effect on WebGLRenderer (`engine.post.add` throws by name there). If you need crisp sun beams in open air, a spot light aimed along the sun with `lightVolumes` gives a shaft you can place by hand.
|
|
163
|
+
|
|
164
|
+
## Occlusion culling
|
|
165
|
+
|
|
166
|
+
`engine.occlusion.enabled = true` skips the engine's big things while something hides them: hlod cells and `engine.batching` groups. Works on both renderers. Ordinary objects are not watched. Turn it on only when heavy things stand behind others (a walled town, a building full of rooms). In a scene of many small things it is a loss: each box costs CPU, more so on WebGPU. Measure with `describe().render.occlusion` (`hidden`, `trianglesSkipped`) and the frame time, on and off.
|
|
167
|
+
|
|
168
|
+
- Three things share the word occlusion and are separate: occlusion culling (this section) skips drawing what is hidden; camera occlusion (`cameraOcclusion` of `collision()`, recipe 21) moves the camera so a wall does not stand between it and the player; `voxelGI`'s `occlusion` only darkens corners of its bounced light.
|
|
169
|
+
- Hidden things stay in shadows, in `engine.rays` and in `voxelGI`'s volume, and `visible` stays yours. Nothing else sees them while hidden: a second camera of yours and a `THREE.Raycaster` of your own do not (their layers lack it; enable `RESERVED_LAYERS.occlusionHidden` from `threedog/layers` if they must).
|
|
170
|
+
- **Step mode hides nothing.** The answers arrive over drawn frames, so under `threedog step` / `engine.step()` (no real frames) `hidden` stays 0 and `inspect perf` counts every draw. Judge occlusion with `threedog resume` and real time, never from a step-mode reading.
|
|
171
|
+
- Answers come a few frames late. Camera moves and cuts are covered. A big occluder that moves fast (a falling wall, a gate thrown open) can show a gap of a few frames.
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# Making a new picture from a reference picture
|
|
2
|
+
|
|
3
|
+
**In this recipe**: Example · The loop · What picture code can change, and what it cannot · Steps · Picture check after every shot · Picture questions ·
|
|
4
|
+
Guard rails · A fixed scene to judge by
|
|
5
|
+
|
|
6
|
+
```sh
|
|
7
|
+
threedog picture palette art/reference/ref.png --n 8 --average # the colors: they go in picture/palette.js
|
|
8
|
+
threedog shot --size 480x270 --out now.png # your picture, with its picture numbers
|
|
9
|
+
threedog picture compare art/reference/ref.png .threedog/shots/now.png --out side.png # what differs, as numbers and one image
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
No reference picture? Skip the measuring (step 2, `picture palette`, `picture compare` against a reference); judge each shot against DESIGN.md and
|
|
13
|
+
its "Loved / Not for this game" list, and use the rest: the loop, the picture check after every shot and the picture questions.
|
|
14
|
+
|
|
15
|
+
For an AI that is given one picture ("make it look like this") and has to turn it into the game's picture. The tools keep the work measurable: `threedog picture palette`
|
|
16
|
+
and `picture compare` measure pictures, your game's `picture/` folder holds the result in plain three.js (recipe 62). They never say which colors are right; the taste is
|
|
17
|
+
yours. How the `picture/` folder is laid out and which signals it reads are in `62-picture-code.md`; this page is the order of work.
|
|
18
|
+
|
|
19
|
+
## The loop (every round, in this order)
|
|
20
|
+
Looping "edit, screenshot, read the image" costs the most tokens and fixes the least. Numbers come first, pictures last.
|
|
21
|
+
1. **Measure the reference once** (step 2 below). Break the picture into
|
|
22
|
+
techniques (shading, one texture language, palette, edges) before choosing values.
|
|
23
|
+
2. **Change one family of values** (colors, then materials, then post). After writing or changing a model, look at it alone
|
|
24
|
+
first: `threedog gallery --shots` (every model under three lights, `.threedog/gallery/index.html`) shows wrong scale, wrong facing, holes and missing
|
|
25
|
+
faces before the level hides them.
|
|
26
|
+
3. **Shoot small and compare to the previous shot**: `threedog shot --size 480x270 --keep --compare <previous.png>`. It prints the
|
|
27
|
+
pixel diff and the picture differences. Through MCP the `snap` tool is 480 px wide by default; `picture_compare` gives the numbers.
|
|
28
|
+
4. **Read the numbers first, then at most one image per round.** Name the biggest remaining difference and fix only that. With no reference, read the shot's hints (below). Then look at the image as a player would and judge it
|
|
29
|
+
against the picture DESIGN.md wants and its "Loved / Not for this game" list (never against a technique example): what would a player read as a
|
|
30
|
+
mistake? Typical ones are objects floating or cutting into each other, odd flat discs or blobs (a hard-edged opaque "puddle" reads as a gray ball),
|
|
31
|
+
glare, areas too dark or busy to read, placeholder-looking shapes; these are prompts, not a list to tick. Fix what you find, or note it in
|
|
32
|
+
STATUS.md with why it stays. Before calling a picture done, go through the "Picture questions" below that matter for this game.
|
|
33
|
+
5. **Wrong in a way the numbers do not explain?** Diagnose before guessing: `engine.debug.view('albedo' | 'lighting' | 'shadow' | 'normals')` shows which
|
|
34
|
+
layer is off, and every value has one writer, a line in your `picture/` code. Nothing drawn: `threedog scene --hidden` (reasons per mesh).
|
|
35
|
+
Washed-out or too-dark textures, odd normals: `threedog inspect materials` (wrong color spaces first, sizes, who made each material).
|
|
36
|
+
6. **If the biggest difference stops shrinking over a few rounds, change approach** (in this order) and tell the user which and why:
|
|
37
|
+
painted textures (`map`, `normalMap`) -> `onBeforeCompile` on your own material -> your own `ShaderMaterial`.
|
|
38
|
+
Never call it "close" to stop tuning.
|
|
39
|
+
7. **Every few rounds show the user the shot and the numbers.**
|
|
40
|
+
|
|
41
|
+
The loop is the same for every art direction; only what you measure and which value you move differ: flat (palette share, hard edges, no shading), painterly
|
|
42
|
+
(soft edges, texture, low contrast), low-poly (few flat colors, faceted light), realistic (exposure, tone mapping, lighting, material roughness). None is the default.
|
|
43
|
+
|
|
44
|
+
## What picture code can change, and what it cannot
|
|
45
|
+
Can change (all in `picture/`, plain three.js): colors (`picture/palette.js`, `scene.background`), every material (matte `MeshLambertMaterial`, banded `MeshToonMaterial`,
|
|
46
|
+
PBR `MeshStandardMaterial`, your own shader), the engine's big parts through their own `.material` and `.uniforms` (ground, plants, water, sky dome), lights, fog,
|
|
47
|
+
`renderer.toneMapping` and `toneMappingExposure`, post passes (the effects in `@threedog/post-effects`), UI colors and fonts, and the colors
|
|
48
|
+
of the procedural models.
|
|
49
|
+
|
|
50
|
+
Cannot change by picture code: the **silhouette of models**. A tree stays the shape its model has; a new shape means a new asset (code-built models
|
|
51
|
+
or `.glb` files, recipes `05-props-bake.md` and `10-blender-level.md`). And the **world rules**: water level, terrain shape, what
|
|
52
|
+
exists where, timing and gameplay belong to the modules' options and the game's content. If the reference shows a different
|
|
53
|
+
world (a canyon instead of hills), say so instead of faking it with colors.
|
|
54
|
+
|
|
55
|
+
## Steps
|
|
56
|
+
1. **Keep the picture.** Put it in the game's `art/reference/` (one file per style, with a few lines of notes beside it on what to copy:
|
|
57
|
+
palette, mood, line work, light direction). Use the highest-resolution picture you have: a small or compressed one gives wrong detail and brightness numbers.
|
|
58
|
+
2. **Measure it.** `threedog picture palette art/reference/ref.png --n 8 --average` (MCP: `picture_palette`) prints the colors (`--json`: JSON only) with share, hue, saturation,
|
|
59
|
+
brightness, and role hints: largest block = ground / environment candidate, brightest = highlight / sky candidate, most saturated = accent candidate,
|
|
60
|
+
darkest = shadow or outline candidate, and one summary line such as `warm colors, mostly sand, low saturation, medium brightness, weak light/dark contrast`.
|
|
61
|
+
It reads pixels in a headless browser (png, jpg, webp, gif, svg). The overall mean (`--average`) sets exposure and tint; the clusters pick the named
|
|
62
|
+
palette entries. A phone screenshot with a dark UI frame needs `--ignore-ui` or `--region x,y,w,h`; `--crop cut.png` saves exactly what was measured.
|
|
63
|
+
3. **Write them down.** The colors you measured go in `picture/palette.js`, snapped to a few named ones (a reference usually has 5 to 8 that matter). Procedural
|
|
64
|
+
models the picture needs go in the game's `art/` folder, registered with `engine.assets.manifest({ name: 'mygame', models })`.
|
|
65
|
+
4. **Fill it in, in this order** (each step changes the picture most for the least work): sky colors and `scene.background` (light and mood), `renderer.toneMapping` and
|
|
66
|
+
exposure, the lights in `picture/lights.js`, the ground's colors, the materials in `picture/materials.js` (matte, banded, shiny, PBR, unlit), post, then UI.
|
|
67
|
+
The first frame should already be close: if it is far from the reference, fix sky, exposure, palette and material type before adding anything.
|
|
68
|
+
5. **Check.** `npm run check` type-checks `picture/`, and a misspelled option or a bad call fails on the page with a line in `.threedog/errors.log`.
|
|
69
|
+
6. **Picture: the loop above.** Take pictures with the same arguments every round so only the picture differs, from named places (`shot --at <place>`), not free `--pos` shots.
|
|
70
|
+
`picture compare` prints brightness, saturation, contrast, fine detail, average and main color of both and one sentence such as "the screenshot is darker and more broken up", with deliberately no
|
|
71
|
+
"similarity %". Dirty = lower saturation or an off hue, fragmented = fine detail ratio well above 1, dark or flat = brightness and contrast. Keep a change if its number moved toward
|
|
72
|
+
the reference and the picture looks better. A phone UI frame in the screenshot skews the numbers: compare a `--region`.
|
|
73
|
+
`--out side.png` (MCP `picture_compare` always writes `<shot>.compare.png`) is one image, reference left, screenshot right.
|
|
74
|
+
7. **Stop** when the biggest remaining difference is a silhouette or a world rule: that is the assets or the game, not the picture code.
|
|
75
|
+
|
|
76
|
+
## Picture check after every shot
|
|
77
|
+
Every `threedog shot` prints picture numbers and hints (`--no-picture` skips them). The numbers are luminance, contrast (std and p5-p95 range of
|
|
78
|
+
luminance), saturation, clipped and near-black shares, and the shadow area. Hints come in three kinds:
|
|
79
|
+
- **Contradictions**, whatever the art direction: the settings say one thing and the pixels another. Shadows on but none measurable (with the cause it found:
|
|
80
|
+
the light's `shadow.bias` as meters of shadow depth, the view outside the shadow box, texel size, or fill light washing them out), a light that changes
|
|
81
|
+
no pixel.
|
|
82
|
+
- **Facts**: measured, maybe wanted, with what sets them: glare, large clipped or near-black areas, a night that is not dark from lighting (and
|
|
83
|
+
whether the brightness at 00:00 is lighting at all), the key / fill balance. Each becomes a contradiction only where DESIGN.md declares the
|
|
84
|
+
opposite.
|
|
85
|
+
- **Intent**, only against what the game declared: DESIGN.md's optional `Picture intent:` line (listed words such as `no-glare`, `dark-nights`,
|
|
86
|
+
`strong-light`, `muted`; the template lists them all; the table's free text is not read), or the reference given with `--ref`. A muted,
|
|
87
|
+
low-contrast game is told when its shot measures saturated and contrasty, never the other way round unless it said so. No declaration and
|
|
88
|
+
no reference: numbers only, no judgement.
|
|
89
|
+
|
|
90
|
+
A hint is a fact plus the parameter and its current value, not a target. It never says what value is right for an art direction; decide that from
|
|
91
|
+
the reference, DESIGN.md or the user. A deliberate choice (a night meant to be pitch black) makes a hint something to note, not to fix.
|
|
92
|
+
|
|
93
|
+
## Picture questions
|
|
94
|
+
Pick the ones that matter for this game, before calling a picture done and when a round stalls. They name what to look at, not which answer is
|
|
95
|
+
right for a given art direction.
|
|
96
|
+
- **Light roles**: is there one clear key light (direction, color), a fill that keeps shadows readable, and does the sky / ambient color agree with it?
|
|
97
|
+
`debug.view('lighting')`.
|
|
98
|
+
- **Shadows and contact**: do objects sit on the ground (contact shadow, AO, or a dark base), are shadow edges as hard or soft as the reference, no
|
|
99
|
+
acne or peter-panning? `debug.view('shadow')`. A shadow that starts a hand's width away from a foot or a crate is peter-panning: check
|
|
100
|
+
the light's `shadow.bias` (it is in 0-1 shadow depth, so a large value over a long light range is decimeters). Faint shadows: key against fill ([recipe 60](60-judge-the-picture.md)); small casters blur when the
|
|
101
|
+
shadow box is much bigger than the scene ([recipe 45](45-cascaded-shadows.md)).
|
|
102
|
+
- **Day / night**: shoot noon and night (`shot --time 12:00`, `--time 22:00`); is night as dark as the design wants on every material, PBR ones
|
|
103
|
+
too? A PBR material that stays bright at night is usually lit by an environment map that does not follow the time: `scene.environmentIntensity` is yours to drive from `uDaylight`.
|
|
104
|
+
- **Material response**: do surfaces that should differ (wood, stone, metal, cloth, skin, water) differ in roughness, specular and color, not only hue?
|
|
105
|
+
A plastic-looking surface is a shading problem, not a color problem.
|
|
106
|
+
Metals have something to reflect (environment). A glossy flat decal (puddle, spill, polished floor) reflects only the environment map, never the
|
|
107
|
+
street around it: a hard-edged dark or bright ellipse then reads as a hole or a blob. Give it soft alpha edges and a color close to the surface
|
|
108
|
+
under it, or darken / smooth the ground's own material (roughness map) instead of laying a disc on it; check it at noon and at night.
|
|
109
|
+
- **Texture scale and detail**: is texel density similar across neighbors, no obvious tiling at the usual camera distance, detail matching how close the
|
|
110
|
+
camera gets? Color spaces right (`inspect materials`).
|
|
111
|
+
- **Color and grading**: value range (darkest / brightest), saturation and the overall hue shift match the reference (`picture compare`); exposure and
|
|
112
|
+
tone mapping chosen, not left at whatever was there.
|
|
113
|
+
- **Atmosphere and depth**: fog, haze or color shift with distance as the reference shows; the background separates from the play space.
|
|
114
|
+
- **Readability of gameplay elements**: the player, interactables, hazards and pickups stand out by value or color from the ground at play distance and
|
|
115
|
+
under every time of day / weather the game uses (shoot them at dusk and in rain too).
|
|
116
|
+
- **Consistency**: does any asset step out of the overall art direction (outline weight, shading model, texture language) where DESIGN.md did not
|
|
117
|
+
intend it? A deliberate mix is a choice, not a mistake.
|
|
118
|
+
|
|
119
|
+
## Guard rails
|
|
120
|
+
- Restraint: for each post effect, say which difference in the shot it fixes. Start with none, add one for a visible difference you named, and
|
|
121
|
+
measure again after each one.
|
|
122
|
+
- Never put gameplay or world values in `picture/` to match a picture.
|
|
123
|
+
- Fonts and textures are assets: register the file in an asset pack and name it, the picture code does not carry files.
|
|
124
|
+
- Keep `npm run check` at 0 errors; a new picture adds no warnings.
|
|
125
|
+
|
|
126
|
+
## A fixed scene to judge by
|
|
127
|
+
Same arguments, same picture, so only the picture differs. A game with many pictures to judge gives itself a small page with one of everything; `/styletest.html`
|
|
128
|
+
(`examples/styletest`) is the engine's own, a pattern to copy: a character, trees, rock, grass, flowers, water, terrain, glass, a shadow receiver,
|
|
129
|
+
wood / stone / metal surfaces, a lit room (outside and inside) and the UI parts, under named cameras.
|
|
130
|
+
- `threedog shot styletest --view <name> [--time day|dusk|night] [--weather clear|rain|snow]`; the same words work as URL parameters
|
|
131
|
+
(`?view=room&time=dusk&weather=rain`).
|
|
132
|
+
- Views: `overview`, `character`, `water`, `room`, `path` (the camera moves along a fixed line: with `--wait 4` the shot is the same frame every time; in a browser look for grass blades
|
|
133
|
+
and shadow edges that flicker or crawl), `ui`.
|
|
134
|
+
- The dev panel, in any game: `if (location.search.includes('panel=1')) import('@threedog/tools/panel').then(m => m.openPanel(engine));`
|
|
135
|
+
It needs the optional dev package `tweakpane` (`npm install -D tweakpane`; the repository's `npm install` has it); without it the page says so.
|
|
136
|
+
A production build of the vite preset gets a stub instead (no panel, no tweakpane in the bundle); dev and test builds get the real one.
|
|
137
|
+
It reads the three.js objects and writes them directly: exposure, `scene.fog`, each light, `engine.water` / `terrain` / `vegetation` materials and uniforms
|
|
138
|
+
(when installed), a material picked by name, `engine.uniforms`, post effects, UI colors. "write back" saves the changes to
|
|
139
|
+
`.threedog/tune.json` on the dev server; then `threedog tune write <file>` prints the code change as a diff (one `// threedog:tune begin ... end` block
|
|
140
|
+
of plain three.js writes) and `--apply` writes it. Review it, then keep the block or move each value where it belongs (`picture/palette.js`, the material's definition).
|