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
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// Ground API (part of Engine, mixed into Engine.prototype): whoever provides ground height is the "terrain" -- a procedural terrain module, a hand-made level, or a flat plane.
|
|
2
2
|
// The queries below take (x, z), or a Vector3 / Object3D directly: engine.surface(mesh.position)
|
|
3
|
-
import { xzOf } from '
|
|
4
|
-
import {
|
|
5
|
-
import { readParams, keysSchema } from '
|
|
6
|
-
import {
|
|
3
|
+
import { xzOf } from '../base/math.js';
|
|
4
|
+
import { warnOnce, fmt } from '../base/validate.js';
|
|
5
|
+
import { readParams, keysSchema } from '../base/params.js';
|
|
6
|
+
import { coded } from '../base/errorHints.js';
|
|
7
7
|
|
|
8
8
|
// Default ground: an infinite flat plane at y = 0. A terrain or level module replaces it
|
|
9
9
|
export const flatGround = {
|
|
@@ -14,16 +14,16 @@ export const flatGround = {
|
|
|
14
14
|
voidY: () => -Infinity,
|
|
15
15
|
};
|
|
16
16
|
const NO_GROUND = '{who}: there is no ground at ({x}, {z}) (outside terrain({ shape })){left}; check engine.ground.has(x, z) first';
|
|
17
|
-
const noGround = (who, x, z, left = '') => NO_GROUND
|
|
17
|
+
const noGround = (who, x, z, left = '') => fmt(NO_GROUND, { who, x: x.toFixed(1), z: z.toFixed(1), left });
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* Ground height for a place-it-here entry (spawn, props, pickups, npcs, placeAt). Beyond terrain({ shape }) surface() is -Infinity, and that must never
|
|
21
|
-
* reach a position (a save turns it into null / NaN and the object vanishes):
|
|
21
|
+
* reach a position (a save turns it into null / NaN and the object vanishes): a warning with the fix (once per caller), and `fallback` is used. @internal
|
|
22
22
|
*/
|
|
23
23
|
export function placeY(e, who, x, z, refY, fallback = 0) {
|
|
24
24
|
const y = e.surface(x, z, refY);
|
|
25
25
|
if (y !== -Infinity) return y;
|
|
26
|
-
|
|
26
|
+
warnOnce(coded('ground-missing', noGround(who, x, z)), `ground-missing:${who}`); // a warning: the fallback is safe, and a prop at the island's edge is legal game code
|
|
27
27
|
return fallback;
|
|
28
28
|
}
|
|
29
29
|
/** Ground height for a visual-only reader (hud anchor, grid tiles, camera start, shot path): off the island use `fallback`, never throw. @internal */
|
|
@@ -69,12 +69,12 @@ export const groundMethods = {
|
|
|
69
69
|
snapToGround(obj, offset = 0) {
|
|
70
70
|
const p = obj.position, y = this.surface(p.x, p.z, p.y);
|
|
71
71
|
if (y === -Infinity) { // never write an infinite y: the object would vanish and poison bounds and physics
|
|
72
|
-
|
|
72
|
+
warnOnce(coded('ground-missing', noGround('engine.snapToGround()', p.x, p.z, ', so the object was left where it is')), 'ground-missing:snapToGround');
|
|
73
73
|
return obj;
|
|
74
74
|
}
|
|
75
75
|
p.y = y + offset; return obj;
|
|
76
76
|
},
|
|
77
|
-
/** Water surface height at a point: water bodies (lake, pond, river segment)
|
|
77
|
+
/** Water surface height at a point: the highest of the global water level and the water bodies (lake, pond, river segment) there; -Infinity if there is no water */
|
|
78
78
|
waterAt(x, z) {
|
|
79
79
|
if (typeof x === 'object') [x, z] = xzOf(x);
|
|
80
80
|
let lv = this.ground.waterLevel;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
// One shared definition of "can walk there": character radius, height, max slope and step height are defined only here
|
|
1
|
+
// One shared definition of "can walk there": character radius, height, max slope and step height are defined only here.
|
|
2
2
|
// Lightweight collision (resolve / walkable / maxClimb), the Rapier capsule, navigation (Recast agentRadius / agentHeight / maxClimb / maxSlope),
|
|
3
3
|
// the A* fallback pathfinding, the level heightfield step height and Character's default radius / step all read engine.movement by default, so no one keeps a private number.
|
|
4
4
|
// Core only holds this data and depends on no module (hard rule 2); a module's same-named option can still be passed and acts as an override.
|
|
5
5
|
// createEngine({ movement: { radius: 0.5 } }) -> engine.movement.radius === 0.5 (read-only, never changed at runtime)
|
|
6
|
-
import { readParams, keysSchema } from '
|
|
7
|
-
import { codedError } from '
|
|
6
|
+
import { readParams, keysSchema } from '../base/params.js';
|
|
7
|
+
import { codedError } from '../base/errorHints.js';
|
|
8
8
|
|
|
9
9
|
/** Defaults (meters / degrees): radius is the character radius, height the character height, maxSlope the steepest walkable slope (degrees), stepHeight the step it can climb directly. */
|
|
10
10
|
export const MOVEMENT_DEFAULTS = { radius: 0.4, height: 1.8, maxSlope: 48, stepHeight: 0.45 };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// The names of the picture values only one writer may hold: the one table a module's provides, the picture writers tool (core/inspect/pictureWriters.js),
|
|
2
|
+
// describe('picture').picture.slots and the PictureSlot type all read. A name here is a convention, nothing more: provides: ['fog'] takes it like any other
|
|
3
|
+
// exclusive slot (core/engine/moduleSlots.js), so a second claim is shared-taken and { replaces: 'fog' } swaps the holder.
|
|
4
|
+
// Why a table at all: two parts from different sources only collide on a claim when they spell the slot the same way, and the writers tool can only tell
|
|
5
|
+
// "the holder wrote fog.far" from a stray write when it knows fog.far belongs to 'fog'. Why this small: every extra row is a rule for code that never asked.
|
|
6
|
+
// values: names in describe('picture').picture.writers; one ending in '.' covers everything under it ('fog.' = fog.near, fog.far ...)
|
|
7
|
+
// sun is the light named 'sun': the name is how another source finds the main light (scene.getObjectByName('sun')), so it is how this table finds it too.
|
|
8
|
+
// sky has no values: a dome or a skybox is an object, not one value three.js holds. A sky drawn through scene.background also takes 'background'.
|
|
9
|
+
const row = (what, ...values) => Object.freeze({ what, values: Object.freeze(values) });
|
|
10
|
+
export const PICTURE_SLOTS = Object.freeze({
|
|
11
|
+
sky: row('the sky drawn behind everything: a dome, a skybox'),
|
|
12
|
+
fog: row('scene.fog and its values', 'scene.fog', 'fog.'),
|
|
13
|
+
tone: row('tone mapping and exposure', 'renderer.toneMapping', 'renderer.toneMappingExposure'),
|
|
14
|
+
environment: row('the environment map and its strength', 'scene.environment', 'scene.environmentIntensity'),
|
|
15
|
+
background: row('scene.background and its strength', 'scene.background', 'scene.backgroundIntensity'),
|
|
16
|
+
sun: row("the main light: the light named 'sun'", 'light:sun.'),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
/** The slot a writers value name belongs to, or null ('fog.far' -> 'fog', 'light:lamp.color' -> null) @param {string} label */
|
|
20
|
+
export function slotOfValue(label) {
|
|
21
|
+
for (const slot in PICTURE_SLOTS) for (const v of PICTURE_SLOTS[slot].values) if (v.endsWith('.') ? label.startsWith(v) : label === v) return slot;
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Who holds a slot now, or null. A name the game defined as a shared value of another kind is no slot @param {any} e @param {string} slot */
|
|
26
|
+
export function slotHolder(e, slot) {
|
|
27
|
+
if (!e.stacks.has(slot)) return null;
|
|
28
|
+
const s = e.stacks.get(slot);
|
|
29
|
+
return s.kind === 'one' ? s.value() ?? null : null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** describe('picture').picture.slots: slot -> the module holding it, or null @param {any} e */
|
|
33
|
+
export const slotHolders = e => Object.fromEntries(Object.keys(PICTURE_SLOTS).map(slot => [slot, slotHolder(e, slot)]));
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
// Swapping an entry inside a material array in place (mesh.material[1] = m) is not seen; assign a new array instead.
|
|
15
15
|
// A visitor keeps its own per-object / per-material state (Maps, WeakMaps); nothing here holds an object after it left the scene.
|
|
16
16
|
import * as THREE from 'three';
|
|
17
|
-
import { useSceneVisitor } from '
|
|
17
|
+
import { useSceneVisitor } from '../../render/backend.js';
|
|
18
18
|
import { notePatch, patchOn } from './threePatches.js';
|
|
19
19
|
|
|
20
20
|
const KEY = Symbol.for('threedog.sceneDelta');
|
|
@@ -35,6 +35,7 @@ if (!P[KEY]) {
|
|
|
35
35
|
Object.defineProperty(P, KEY, { value: true, configurable: true });
|
|
36
36
|
Object.defineProperty(P, ORIG, { value: { add, remove }, configurable: true });
|
|
37
37
|
P.add = function (...a) {
|
|
38
|
+
if (!patchOn('scene-add-hook')) return add.apply(this, a); // switched off while another library's wrapper sits on top of ours: pass through
|
|
38
39
|
const out = add.apply(this, a); // three detaches each child from its old parent first (through remove below), then attaches
|
|
39
40
|
const t = trackerOf(this);
|
|
40
41
|
if (t) for (const c of a) if (c?.parent === this) t.pending.add(c);
|
|
@@ -44,23 +45,30 @@ if (!P[KEY]) {
|
|
|
44
45
|
return out;
|
|
45
46
|
};
|
|
46
47
|
P.remove = function (...a) {
|
|
47
|
-
const t = trackerOf(this);
|
|
48
|
+
const t = patchOn('scene-add-hook') ? trackerOf(this) : null;
|
|
48
49
|
if (!t) return remove.apply(this, a);
|
|
49
50
|
let gone = null, roots = null;
|
|
50
|
-
for (const c of a) if (c?.parent === this
|
|
51
|
+
for (const c of a) if (c?.parent === this) (gone ??= []).push(c); // not only seen ones: a material swap unmarks the root, its children stay counted (left checks each)
|
|
51
52
|
if (t.rootLeaves.size && this === t.scene) for (const c of a) if (c?.parent === this) (roots ??= []).push(c);
|
|
52
53
|
const out = remove.apply(this, a);
|
|
53
54
|
if (gone) for (const c of gone) t.left(c);
|
|
54
55
|
if (roots) for (const c of roots) if (c.parent !== this) for (const f of t.rootLeaves) f(c);
|
|
55
56
|
return out;
|
|
56
57
|
};
|
|
58
|
+
P[ORIG].ours = { add: P.add, remove: P.remove }; // to tell at off() whether they are still the outermost
|
|
57
59
|
}
|
|
58
60
|
notePatch('scene-add-hook', 'Object3D.prototype.add / remove: wrapped once per page to see what enters and leaves a watched scene at any depth (three\'s childadded fires on the direct parent only)',
|
|
59
|
-
() => {
|
|
60
|
-
|
|
61
|
+
() => {
|
|
62
|
+
// a wrapper another library put on top of ours stays: taking it off would undo that library too. Ours then only passes calls through (patchOn above).
|
|
63
|
+
const o = P[ORIG]; if (!o?.ours) return;
|
|
64
|
+
if (P.add === o.ours.add) P.add = o.add;
|
|
65
|
+
if (P.remove === o.ours.remove) P.remove = o.remove;
|
|
66
|
+
if (P.add === o.add && P.remove === o.remove) { delete P[KEY]; delete P[ORIG]; }
|
|
67
|
+
},
|
|
68
|
+
{ lost: 'plain scene.add is no longer adopted like engine.add, and fog, cascades, night glow and light counts miss objects added later' });
|
|
61
69
|
notePatch('mesh-material-accessor', 'mesh.material on each object with a material that enters a watched scene: an own get / set on that object (the class accessor still runs) so a material swap is seen',
|
|
62
70
|
() => {}, // off: objects entering from now on keep a plain material (_walk asks patchOn)
|
|
63
|
-
{ scope: 'objects in the scene', lost: 'mesh.material = other on objects entering from now on is not seen: the new material misses fog
|
|
71
|
+
{ scope: 'objects in the scene', lost: 'mesh.material = other on objects entering from now on is not seen: the new material misses fog and cascades until the object re-enters' });
|
|
64
72
|
|
|
65
73
|
/** The accessor (get / set) `material` resolves to on this object or up its prototype chain, or null when it is a plain value */
|
|
66
74
|
function materialAccessor(o) {
|
|
@@ -1,17 +1,31 @@
|
|
|
1
|
-
// Scene and render settings on the engine (split out of Engine.js): add / detach / remove objects, pixel ratio,
|
|
2
|
-
// tone mapping and exposure, one-off renders (renderOnce).
|
|
1
|
+
// Scene and render settings on the engine (split out of Engine.js): add / detach / remove objects, pixel ratio, one-off renders (renderOnce).
|
|
3
2
|
// add registers each root in the thing registry (things.js) so engine.thing / hit.thing can say what it is and what a save keeps. A plain
|
|
4
3
|
// engine.scene.add(obj) is registered the same way (things.js adopts roots added under the scene), so both ways in give the same answer.
|
|
5
|
-
import { DEV } from '
|
|
6
|
-
import {
|
|
4
|
+
import { DEV } from '../base/validate.js';
|
|
5
|
+
import { writeRatio } from './adaptive.js';
|
|
6
|
+
import { codedError } from '../base/errorHints.js';
|
|
7
7
|
import { thing } from './thingOps.js';
|
|
8
|
-
import {
|
|
9
|
-
import { freshFrame, renderOnce as drawOnce } from '
|
|
8
|
+
import { isUnder } from '../base/util.js';
|
|
9
|
+
import { freshFrame, renderOnce as drawOnce } from '../../render/backend.js';
|
|
10
10
|
|
|
11
|
-
/** The
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
|
|
11
|
+
/** The geometry and materials of one object */
|
|
12
|
+
const parts = o => [o.geometry, ...[].concat(o.material)].filter(Boolean);
|
|
13
|
+
/**
|
|
14
|
+
* How many objects in the scene use each geometry and material. Why remove asks: disposing a kit that other streamed blocks still draw makes the renderer
|
|
15
|
+
* rebuild all of them (worst frame 270 ms against 79 in the city stress run). One walk per task, so removing ten thousand objects in a loop walks once; an object
|
|
16
|
+
* added later in that task is not counted, so its geometry may be disposed and uploaded again, which costs time and nothing else; one that left by plain scene.remove
|
|
17
|
+
* in that task still counts, so its model waits for the next engine.remove. Batches are left out:
|
|
18
|
+
* batching.held speaks for them, and it lets go when a batch dissolves in the same task.
|
|
19
|
+
* shortcut: one walk of the scene per frame that removes something (not measured at 100k objects); if it shows up in a profile, keep the counts on the scene-add hook instead.
|
|
20
|
+
*/
|
|
21
|
+
function sceneUsers(e) {
|
|
22
|
+
if (e._users) return e._users;
|
|
23
|
+
const users = e._users = new Map(), skip = e.batching.root;
|
|
24
|
+
const walk = o => { if (o === skip) return; for (const x of parts(o)) users.set(x, (users.get(x) ?? 0) + 1); for (const c of o.children) walk(c); };
|
|
25
|
+
walk(e.scene);
|
|
26
|
+
queueMicrotask(() => { e._users = null; });
|
|
27
|
+
return users;
|
|
28
|
+
}
|
|
15
29
|
|
|
16
30
|
/** A short stack for "added at main.js:50" (dev): 4 frames are enough (this, add, its caller) and keep the cost low; it is formatted only when read */
|
|
17
31
|
function captureStack() {
|
|
@@ -50,7 +64,7 @@ export const sceneMethods = {
|
|
|
50
64
|
* @example engine.thing('windmill').saved // 'code': rebuilt by code each start, thing.set changes saved
|
|
51
65
|
* @example engine.thing(engine.pick(0, 0).object).edit
|
|
52
66
|
* @param {string | import('three').Object3D} idOrObj
|
|
53
|
-
* @returns {import('
|
|
67
|
+
* @returns {import('../../types/core').Thing}
|
|
54
68
|
*/
|
|
55
69
|
thing(idOrObj) { return thing(this, idOrObj); },
|
|
56
70
|
/** @internal Dev: a module found two systems managing one object; listed in describe().scene.conflicts and warned once (code thing-owned) */
|
|
@@ -58,20 +72,21 @@ export const sceneMethods = {
|
|
|
58
72
|
/** Detach from the parent only (no GPU release; use when you will add it back). Use remove for objects you are done with */
|
|
59
73
|
detach(...objs) { for (const o of objs) o.removeFromParent(); },
|
|
60
74
|
/**
|
|
61
|
-
* Delete an object for good: detach it, unregister its rays and dispose geometries and materials (textures are kept).
|
|
62
|
-
* model clones are only decremented in use count (see Assets.js)
|
|
75
|
+
* Delete an object for good: detach it, unregister its rays and dispose the geometries and materials nothing else in the scene uses (textures are kept).
|
|
76
|
+
* One still used by another object stays, and goes with its last user. Geometry and materials shared by assets model clones are only decremented in use count (see Assets.js)
|
|
63
77
|
*/
|
|
64
78
|
remove(...objs) {
|
|
65
79
|
for (const o of objs) {
|
|
80
|
+
const counted = isUnder(o, this.scene) && !!this._users; // the count was made while this object was still in the scene
|
|
66
81
|
o.removeFromParent();
|
|
67
82
|
this._things.forget(o);
|
|
68
83
|
this.rays.forget(o);
|
|
69
84
|
this.assets.forget(o);
|
|
70
85
|
const shared = this.assets.shared, held = this.batching.held; // a batch still drawing the same geometry / material keeps it alive
|
|
71
|
-
o.traverse(c => {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
86
|
+
if (counted) o.traverse(c => { for (const x of parts(c)) this._users.set(x, (this._users.get(x) ?? 0) - 1); });
|
|
87
|
+
// The whole-scene count only for a part nothing else keeps: unloading a streamed block whose kit is all held by batches walked every object of the district for nothing (7 ms in one frame of the city run)
|
|
88
|
+
const free = []; o.traverse(c => { for (const x of parts(c)) if (!shared.has(x) && !held.has(x)) free.push(x); });
|
|
89
|
+
if (free.length) { const users = sceneUsers(this); for (const x of free) if (!(users.get(x) > 0)) x.dispose(); }
|
|
75
90
|
}
|
|
76
91
|
},
|
|
77
92
|
/**
|
|
@@ -95,9 +110,10 @@ export const sceneMethods = {
|
|
|
95
110
|
drawOnce(this.renderer, this.scene, camera, target);
|
|
96
111
|
} finally { if (own) own.inside--; }
|
|
97
112
|
},
|
|
98
|
-
// an engine.setPixelRatio call is the game's (or settings') request: written even when the game took the ratio
|
|
99
|
-
|
|
100
|
-
|
|
113
|
+
// an engine.setPixelRatio call is the game's (or settings') request: written even when the game took the ratio. It is also the new ceiling, or adaptive
|
|
114
|
+
// resolution would climb back to the old one and undo the engine's own named entry where the raw three.js call stays. Adaptive writes through writeRatio
|
|
115
|
+
setPixelRatio(p) { writeRatio(this, p); Object.assign(this.adaptive, { max: p, lowered: false, from: null, good: 0 }); },
|
|
116
|
+
/** Raise camera.far to at least far (terrain view range). Goes through ownership: a game that owns camera.far (engine.autoView.manual('far')) keeps its value. @param {number} far */
|
|
101
117
|
viewFar(far) {
|
|
102
118
|
if (this.camera.far >= far) return;
|
|
103
119
|
if (this._oFar) this._oFar.drive(far); else { this.camera.far = far; this.camera.updateProjectionMatrix(); }
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// Drawing moving things between fixed steps. Characters and rigid bodies move on the 60 Hz fixed step, and their root.position / mesh.position stays the truth
|
|
2
|
+
// that gameplay reads. A screen faster than that (or a frame that ran zero or two steps) would otherwise draw the same pose twice and then jump.
|
|
3
|
+
// Each entry keeps the object's pose at the end of the last two steps; a drawn frame shows the pose engine.stepBlend of the way between them (one step behind, like a swarm).
|
|
4
|
+
// Why the matrix and not position / quaternion: the blended pose exists for one draw only, so nothing gameplay reads ever holds it, and writing a quaternion
|
|
5
|
+
// would rewrite the Euler the mover keeps facing in. The object's own matrix is composed here and matrixAutoUpdate is off just for that draw.
|
|
6
|
+
// Anything that placed the object outside a step (a tween, a frame-driven mover, a platform carried in frame) leaves it different from the step's end: it is then drawn as it stands.
|
|
7
|
+
import * as THREE from 'three';
|
|
8
|
+
|
|
9
|
+
/** Farther than this in one step (squared meters) is a teleport, not motion: drawn at once, never swept across the map */
|
|
10
|
+
const JUMP2 = 16;
|
|
11
|
+
const _v = new THREE.Vector3(), _q = new THREE.Quaternion(), _keep = new THREE.Vector3();
|
|
12
|
+
|
|
13
|
+
/** @internal engine._poses */
|
|
14
|
+
export class StepPoses {
|
|
15
|
+
constructor(engine) {
|
|
16
|
+
this.engine = engine;
|
|
17
|
+
/** object -> { o, last, lastRot, pos, rot, moved } */ this.map = new Map();
|
|
18
|
+
/** objects whose matrix is held for this draw */ this.held = [];
|
|
19
|
+
engine.time.onMove(() => this.end());
|
|
20
|
+
}
|
|
21
|
+
add(o) { this.map.set(o, { o, last: o.position.clone(), lastRot: o.quaternion.clone(), pos: o.position.clone(), rot: o.quaternion.clone(), moved: false }); }
|
|
22
|
+
remove(o) { this.map.delete(o); }
|
|
23
|
+
/** End of a fixed step: the latest pose becomes the start of the blend */
|
|
24
|
+
end() {
|
|
25
|
+
for (const p of this.map.values()) {
|
|
26
|
+
const { o, last, lastRot, pos, rot } = p;
|
|
27
|
+
last.copy(pos); lastRot.copy(rot); pos.copy(o.position); rot.copy(o.quaternion);
|
|
28
|
+
p.moved = !last.equals(pos) || !lastRot.equals(rot);
|
|
29
|
+
if (p.moved && last.distanceToSquared(pos) > JUMP2) { last.copy(pos); lastRot.copy(rot); p.moved = false; }
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/** The entry if it should blend now, else null: nothing to blend, or the object was placed outside a step */
|
|
33
|
+
live(p) { return p?.moved && this.engine.stepBlend < 1 && p.o.position.equals(p.pos) && p.o.quaternion.equals(p.rot) ? p : null; }
|
|
34
|
+
/** Before a draw: every moving object draws at its blended pose */
|
|
35
|
+
draw() {
|
|
36
|
+
const a = this.engine.stepBlend;
|
|
37
|
+
if (a >= 1) return;
|
|
38
|
+
for (const p of this.map.values()) {
|
|
39
|
+
if (!this.live(p) || !p.o.matrixAutoUpdate) continue;
|
|
40
|
+
const o = p.o;
|
|
41
|
+
o.matrix.compose(_v.lerpVectors(p.last, p.pos, a), _q.slerpQuaternions(p.lastRot, p.rot, a), o.scale);
|
|
42
|
+
o.matrixAutoUpdate = false; o.matrixWorldNeedsUpdate = true;
|
|
43
|
+
this.held.push(o);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/** After a draw: the objects go back to their own pose */
|
|
47
|
+
undraw() { for (const o of this.held) o.matrixAutoUpdate = true; this.held.length = 0; }
|
|
48
|
+
/** Run fn with o standing at its blended position: a camera follows what is drawn, or the view would step while the body glides */
|
|
49
|
+
around(o, fn) {
|
|
50
|
+
const p = this.live(this.map.get(o));
|
|
51
|
+
if (!p) return fn();
|
|
52
|
+
_keep.copy(o.position); o.position.lerpVectors(p.last, p.pos, this.engine.stepBlend);
|
|
53
|
+
try { return fn(); } finally { o.position.copy(_keep); }
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
// Target selection: pure functions (no camera, input or engine state), for lock-on, aim assist, "talk to whoever I'm facing", select the nearest unit.
|
|
2
2
|
// Why a score and not just "nearest": the player wants what they are looking at; an enemy pressed against their back should not steal the lock.
|
|
3
3
|
// The caller keeps the current target (in a world record, a module, a variable) and decides when to pick; these functions only answer "which one".
|
|
4
|
-
import { xzOf } from '
|
|
5
|
-
import { codedError } from '
|
|
4
|
+
import { xzOf, wrapAngle } from '../base/math.js';
|
|
5
|
+
import { codedError } from '../base/errorHints.js';
|
|
6
6
|
|
|
7
|
-
const wrap = a => Math.atan2(Math.sin(a), Math.cos(a));
|
|
8
7
|
const KEYS = ['radius', 'cone', 'close', 'angleWeight', 'blocked', 'at'];
|
|
9
8
|
const yawOf = view => typeof view === 'number' ? view : Math.atan2(view.x, view.z);
|
|
10
9
|
/** Candidate position: an Object3D / NPC / Character / world record has .position; a Vector3 / { x, z } / [x, y, z] is the position itself */
|
|
@@ -33,7 +32,7 @@ export function pickTarget(from, view, candidates, opts = {}) {
|
|
|
33
32
|
for (const c of candidates) {
|
|
34
33
|
const [x, z] = xzOf(at(c)), d = Math.hypot(x - fx, z - fz);
|
|
35
34
|
if (d > radius) continue;
|
|
36
|
-
const off = Math.abs(
|
|
35
|
+
const off = Math.abs(wrapAngle(Math.atan2(x - fx, z - fz) - yaw));
|
|
37
36
|
if (off > cone && d > close) continue;
|
|
38
37
|
const score = d + off * angleWeight;
|
|
39
38
|
if (score < bestScore && !blocked?.(c)) { bestScore = score; best = c; }
|
|
@@ -55,7 +54,7 @@ export function switchTarget(from, view, current, candidates, side, opts = {}) {
|
|
|
55
54
|
const list = [];
|
|
56
55
|
for (const c of candidates) {
|
|
57
56
|
const [x, z] = xzOf(at(c));
|
|
58
|
-
if (Math.hypot(x - fx, z - fz) <= radius && !blocked?.(c)) list.push({ c, a: -
|
|
57
|
+
if (Math.hypot(x - fx, z - fz) <= radius && !blocked?.(c)) list.push({ c, a: -wrapAngle(Math.atan2(x - fx, z - fz) - yaw) });
|
|
59
58
|
}
|
|
60
59
|
if (!list.length) return null;
|
|
61
60
|
list.sort((p, q) => p.a - q.a);
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// engine.thing(id).explain(): everything known about one id in one plain object (JSON-able, same for the CLI `threedog thing <id>`, MCP and tests).
|
|
2
2
|
// Why one object: an AI asked "why is this crate here, blocking me, and how do I change it?" otherwise joins thing(), world.origin, material info, the
|
|
3
3
|
// template, collision settings and the op list by hand. Each part reads an existing source; nothing here is stored or changes any state.
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { Box3, Vector3 } from 'three';
|
|
5
|
+
import { materialInfo } from '../inspect/MaterialInfo.js';
|
|
6
|
+
import { orNull } from '../base/util.js';
|
|
6
7
|
|
|
7
8
|
const MAT_MAX = 8;
|
|
8
9
|
|
|
@@ -13,7 +14,7 @@ function materialsOf(obj) {
|
|
|
13
14
|
for (const m of [o.material].flat()) {
|
|
14
15
|
if (!m || seen.has(m)) continue;
|
|
15
16
|
seen.add(m);
|
|
16
|
-
if (out.length < MAT_MAX) { const i = materialInfo(m, o); out.push({ role: i.role, name: m.name || null, from: i.from,
|
|
17
|
+
if (out.length < MAT_MAX) { const i = materialInfo(m, o); out.push({ role: i.role, name: m.name || null, from: i.from, type: i.type, color: i.color, mesh: o.name || null }); }
|
|
17
18
|
}
|
|
18
19
|
});
|
|
19
20
|
if (seen.size > MAT_MAX) out.push({ more: seen.size - MAT_MAX });
|
|
@@ -28,10 +29,10 @@ function opsFor(e, t) {
|
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
/** What core knows about how the thing takes part in movement / picking: the size of its model. Template and record rules come from a module's explainer (below) */
|
|
31
|
-
function rulesOf(
|
|
32
|
+
function rulesOf(obj) {
|
|
32
33
|
const out = {};
|
|
33
34
|
if (obj) {
|
|
34
|
-
const
|
|
35
|
+
const size = new Box3().setFromObject(obj).getSize(new Vector3());
|
|
35
36
|
if (isFinite(size.y)) out.height = Math.round(size.y * 100) / 100;
|
|
36
37
|
}
|
|
37
38
|
return out;
|
|
@@ -51,7 +52,7 @@ export function explainThing(e, t) {
|
|
|
51
52
|
model: t.model ?? null,
|
|
52
53
|
materials: materialsOf(obj),
|
|
53
54
|
state,
|
|
54
|
-
rules: rulesOf(
|
|
55
|
+
rules: rulesOf(obj),
|
|
55
56
|
ops: opsFor(e, t),
|
|
56
57
|
saved,
|
|
57
58
|
change: {
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
// For a record the ops turn into world.set / world.move / world.remove (the model follows the record); for a plain object they write the transform and,
|
|
5
5
|
// when the object has a stable id and is rebuilt by code at setup, record it as an override in the 'scene' save part (things.js).
|
|
6
6
|
import { Things, snap, write, moduleOwnerOf } from './things.js';
|
|
7
|
-
import { closest, DEV } from '
|
|
7
|
+
import { closest, DEV, goodPos } from '../base/validate.js';
|
|
8
8
|
import { onSceneRoot } from './sceneDelta.js';
|
|
9
|
-
import { codedError } from '
|
|
9
|
+
import { codedError } from '../base/errorHints.js';
|
|
10
10
|
import { explainThing } from './thingExplain.js';
|
|
11
11
|
|
|
12
12
|
const SAY = {
|
|
@@ -120,12 +120,13 @@ export function installThings(e) {
|
|
|
120
120
|
noThing: 'no world record or engine.add object has this id (engine.thing(id) suggests the closest one)',
|
|
121
121
|
engineOwned: 'an engine module manages this object (water, particles, physics…); change it through that module',
|
|
122
122
|
recordVisible: 'a world record has no visible flag: hide its model with present({ show: rec => … }) and a field set by world.set',
|
|
123
|
+
badPosition: 'position takes [x, y, z] or { x, y, z } with finite numbers (y may be left out of the object)',
|
|
123
124
|
};
|
|
124
125
|
e.ops.define('thing.set', {
|
|
125
126
|
targets: '*',
|
|
126
127
|
desc: 'Move / turn / scale / show or hide a thing: a world record (via world.set / move) or an engine.add object (saved as an override when it has an id)',
|
|
127
128
|
args: { id: 'string', position: 'any?', rotation: 'any?', scale: 'any?', visible: 'bool?' },
|
|
128
|
-
can: (_, a) => { const k = kindOf(a.id); return !k ? 'noThing' : k === 'engine' ? 'engineOwned' : k === 'record' && a.visible != null ? 'recordVisible' : true; },
|
|
129
|
+
can: (_, a) => { const k = kindOf(a.id); return !k ? 'noThing' : k === 'engine' ? 'engineOwned' : k === 'record' && a.visible != null ? 'recordVisible' : a.position != null && !goodPos(a.position) ? 'badPosition' : true; },
|
|
129
130
|
run(eng, a) {
|
|
130
131
|
if (kindOf(a.id) === 'record') {
|
|
131
132
|
const patch = { ...(a.position && { position: xyz(a.position) }), ...(a.rotation != null && { rot: yaw(a.rotation) }), ...(a.scale != null && { scale: uni(a.scale) }) };
|
|
@@ -4,9 +4,21 @@
|
|
|
4
4
|
// The WeakMap does not keep objects alive and the id map holds only WeakRefs, so a game that drops an object without engine.remove leaks nothing.
|
|
5
5
|
// Overrides (thing.set / thing.remove on objects the game's code rebuilds each start) live here too and are the 'scene' save part (version 1):
|
|
6
6
|
// { set: { id: { position?, rotation?, scale?, visible? } }, removed: [id] }; ids a save names before the object exists wait in pending.
|
|
7
|
-
import { DEV, warnOnce } from '
|
|
8
|
-
import { codedError, coded } from '
|
|
9
|
-
import { stackFrames, frameText } from '
|
|
7
|
+
import { DEV, warnOnce } from '../base/validate.js';
|
|
8
|
+
import { codedError, coded } from '../base/errorHints.js';
|
|
9
|
+
import { stackFrames, frameText } from '../ops/stackFrames.js';
|
|
10
|
+
import { isPlainObject } from '../base/util.js';
|
|
11
|
+
import { refuseSave } from '../saves/saveValues.js';
|
|
12
|
+
|
|
13
|
+
/** Throw save-bad-record when the 'scene' part is not { set: { id: { prop: value } }, removed: [id] } (same refusal as the world part, world/persist.js) */
|
|
14
|
+
function checkSceneSave(d) {
|
|
15
|
+
const bad = (path, want, got) => refuseSave('scene', path, `must be ${want}`, got);
|
|
16
|
+
if (d == null) return;
|
|
17
|
+
if (!isPlainObject(d)) bad('the scene part', 'a plain object', d);
|
|
18
|
+
if (d.set !== undefined && !isPlainObject(d.set)) bad('set', 'a plain object of id -> properties', d.set);
|
|
19
|
+
for (const [id, p] of Object.entries(d.set ?? {})) if (!isPlainObject(p)) bad(`set.${id}`, 'a plain object of properties', p);
|
|
20
|
+
if (d.removed !== undefined && !(Array.isArray(d.removed) && d.removed.every(id => typeof id === 'string'))) bad('removed', 'an array of ids', d.removed);
|
|
21
|
+
}
|
|
10
22
|
|
|
11
23
|
/** Stacks taken per session in dev: bullets or debris added every frame must not slow dev builds down for a file:line nobody reads */
|
|
12
24
|
const STACK_CAP = 2000;
|
|
@@ -109,7 +121,7 @@ export class Things {
|
|
|
109
121
|
}
|
|
110
122
|
/** [entry, root] for obj or its nearest registered ancestor */
|
|
111
123
|
entryOf(obj) { for (let o = obj; o; o = o.parent) { const en = this.byObj.get(o); if (en) return [en, o]; } return null; }
|
|
112
|
-
/** Save tier, judged in order (recipe
|
|
124
|
+
/** Save tier, judged in order (recipe 40) */
|
|
113
125
|
tier(en) { return en.owner === 'world' ? 'record' : en.owner !== 'game' ? 'engine' : en.stable && en.phase === 'setup' ? 'code' : 'session'; }
|
|
114
126
|
|
|
115
127
|
/**
|
|
@@ -123,7 +135,7 @@ export class Things {
|
|
|
123
135
|
if (stable && owner !== 'world') claimId(this.e, id, obj);
|
|
124
136
|
if (!stable) id = `obj#${++this.n}`;
|
|
125
137
|
const e = this.e, play = e.ready && !this.setup;
|
|
126
|
-
const en = new Entry(id, stable, owner, play ? 'play' : 'setup', play ? e.ops.running : null, play ? e.tick : null, opts?.save, stack);
|
|
138
|
+
const en = new Entry(id, stable, owner, play ? 'play' : 'setup', play ? e.ops.running : null, play ? e.time.tick : null, opts?.save, stack);
|
|
127
139
|
this.byObj.set(obj, en); this.byId.set(id, new WeakRef(obj));
|
|
128
140
|
if (owner === 'game') this.adopt(obj, en);
|
|
129
141
|
return en;
|
|
@@ -139,7 +151,7 @@ export class Things {
|
|
|
139
151
|
adopt(obj, en) {
|
|
140
152
|
const tier = this.tier(en);
|
|
141
153
|
if (tier === 'session' && (en.save === true || en.op)) {
|
|
142
|
-
this.unsaved.add(new WeakRef(obj));
|
|
154
|
+
if (DEV) this.unsaved.add(new WeakRef(obj)); // only the dev reports read it, and they alone prune it
|
|
143
155
|
if (DEV && en.save === true) warnOnce(coded('thing-unsaved', `engine.add(obj, { save: true })${en.at ? ` at ${en.at}` : ''}: this object cannot be saved (${en.stable ? 'it was made during play' : 'it has no stable id'}), so it will not come back after a load. Give it an id and add it at setup (engine.add(obj, { id: 'name' })), or make it a template and create it inside an op with engine.content.spawn(name, at)`));
|
|
144
156
|
}
|
|
145
157
|
if (tier === 'code') this.applySaved(obj, en.id);
|
|
@@ -184,6 +196,7 @@ export class Things {
|
|
|
184
196
|
}
|
|
185
197
|
/** Replace overrides with the save's: undo the current ones first (newGame applies an empty part), then apply to live objects, keep the rest pending */
|
|
186
198
|
load(d) {
|
|
199
|
+
checkSceneSave(d); // before anything is touched: a damaged save is refused (save-bad-record) like a damaged world part, not a code error that freezes the game
|
|
187
200
|
for (const [id, o] of this.over) { const obj = this.live(id); if (obj) write(obj, pick(o.orig, Object.keys(o.cur))); }
|
|
188
201
|
this.over.clear();
|
|
189
202
|
for (const id of [...this.removed]) this.unhide(id);
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
// threePatches.list() // [{ id, what, scope, on, offable, lost }]
|
|
8
8
|
// threePatches.off('shadow-accessors') // three's own behavior again (moving patches then cast still shadows)
|
|
9
9
|
// Page-wide on purpose: a prototype is shared by every engine on the page, so the switch is too.
|
|
10
|
-
import { codedError } from '
|
|
10
|
+
import { codedError } from '../base/errorHints.js';
|
|
11
11
|
|
|
12
12
|
const KEY = Symbol.for('threedog.threePatches'); // global: a second copy of a file (hot reload) re-registers the same id instead of a second entry
|
|
13
13
|
/** @typedef {{ id: string, what: string, scope: string, on: boolean, offable: boolean, lost: string, off: (() => void) | null }} PatchEntry */
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
//
|
|
3
3
|
// Headless tool pages (shot, gallery, capture) pass ?threedog-tier=high|low. Why: the headless browser reports SwiftShader or the machine's
|
|
4
4
|
// integrated GPU, so detection called every tool page "low" and costly post (ao, bloom) silently dropped out of the picture, which then did not
|
|
5
|
-
// show the game's
|
|
5
|
+
// show the game's picture. The tool says which tier it rendered at; tests pass nothing and keep their detected (deterministic) tier.
|
|
6
6
|
const TIERS = ['low', 'high'];
|
|
7
7
|
|
|
8
8
|
/** The tier a headless tool page asks for (?threedog-tier=low|high), or null (the tools check the value: shot --tier fails on anything else). */
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// engine.autoView: the camera and drawing-buffer values the engine changes on its own (camera.far for the view range, camera.fov for the settings slider and camera
|
|
2
|
+
// modules, the pixel ratio for adaptive resolution). Each is an owned property (core/ops/owned.js): a game's direct write wins, manual() takes one on purpose.
|
|
3
|
+
import { codedError } from '../base/errorHints.js';
|
|
4
|
+
import { defineOwned, manualVerb } from '../ops/owned.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Every engine write of camera.fov (settings menu slider, camera modules) goes through here: it yields to a fov the game set itself.
|
|
8
|
+
* @param {any} e @param {number} v
|
|
9
|
+
*/
|
|
10
|
+
export function setFov(e, v) { e._oFov.drive(v); }
|
|
11
|
+
|
|
12
|
+
/** @param {any} e */
|
|
13
|
+
export function defineView(e) {
|
|
14
|
+
const cam = () => e.camera;
|
|
15
|
+
e._oFar = defineOwned(e, { id: 'view.far', part: 'view', key: 'far', read: () => cam().far, objects: [e.camera],
|
|
16
|
+
write: v => { cam().far = v; cam().updateProjectionMatrix(); }, levels: { manual: "engine.autoView.manual('far')" } });
|
|
17
|
+
e._oPixelRatio = defineOwned(e, { id: 'view.pixelRatio', part: 'view', key: 'pixelRatio', read: () => e.renderer.getPixelRatio(), objects: [e.renderer],
|
|
18
|
+
levels: { manual: "engine.autoView.manual('pixelRatio')", set: 'engine.setPixelRatio(1.5)' } });
|
|
19
|
+
// fov: the settings menu slider and camera modules (first person / rts / fixed shots, and restoring the fov at uninstall) write it.
|
|
20
|
+
// They all go through setFov, so a game that sets camera.fov itself (a zoom, a cutscene) is not undone by the next camera switch.
|
|
21
|
+
e._oFov = defineOwned(e, { id: 'view.fov', part: 'view', key: 'fov', read: () => cam().fov, objects: [e.camera],
|
|
22
|
+
write: v => { if (cam().fov !== v) { cam().fov = v; cam().updateProjectionMatrix(); } }, levels: { manual: "engine.autoView.manual('fov')" } });
|
|
23
|
+
// aspect: the engine writes it on every resize. A game's own (letterbox, split view) stays, the same as far and fov
|
|
24
|
+
e._oAspect = defineOwned(e, { id: 'view.aspect', part: 'view', key: 'aspect', read: () => cam().aspect, objects: [e.camera],
|
|
25
|
+
write: v => { cam().aspect = v; cam().updateProjectionMatrix(); }, levels: { manual: "engine.autoView.manual('aspect')" } });
|
|
26
|
+
e._oFar.mark(); e._oPixelRatio.mark(); e._oFov.mark(); e._oAspect.mark();
|
|
27
|
+
e.autoView = {
|
|
28
|
+
/**
|
|
29
|
+
* Stop the engine changing a camera or drawing-buffer value: the value is yours until you hand it back. A direct write takes it too; this says so on purpose,
|
|
30
|
+
* with no warning. 'camera' hands the pose back after a direct write (take it with engine.takeCamera(owner)).
|
|
31
|
+
* @example
|
|
32
|
+
* const mine = engine.autoView.manual('far');
|
|
33
|
+
* engine.camera.far = 5000;
|
|
34
|
+
* mine.remove();
|
|
35
|
+
* @param {'far' | 'fov' | 'aspect' | 'pixelRatio' | 'sunDir' | 'camera'} key
|
|
36
|
+
* @param {boolean} [on] false hands it back
|
|
37
|
+
* @returns {{ remove(): void }} remove() hands it back
|
|
38
|
+
*/
|
|
39
|
+
manual(key, on = true) {
|
|
40
|
+
if (typeof key !== 'string') throw codedError('owned-misuse', `engine.autoView.manual(key): key must be 'far', 'fov', 'aspect', 'pixelRatio', 'sunDir' or 'camera'; got ${JSON.stringify(key)}`);
|
|
41
|
+
return manualVerb(e, 'view', key, on);
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|