threedog 0.7.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 +196 -1
- package/README.md +6 -9
- package/core/{Animator.js → assets/Animator.js} +28 -18
- package/core/{Assets.js → assets/Assets.js} +98 -54
- package/core/{Baked.js → assets/Baked.js} +4 -4
- package/core/assets/assetEntry.js +237 -0
- package/core/{assetHot.js → assets/assetHot.js} +7 -6
- package/core/{assetLoad.js → assets/assetLoad.js} +55 -16
- package/core/assets/assetLod.js +113 -0
- package/core/{assetManifest.js → assets/assetManifest.js} +19 -11
- package/core/{assetReport.js → assets/assetReport.js} +6 -12
- package/core/{namedModel.js → assets/namedModel.js} +17 -13
- package/core/{Audio.js → audio/Audio.js} +26 -23
- 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} +98 -110
- package/core/{errorHints.js → base/errorHints.js} +5 -9
- package/core/{errors.js → base/errors.js} +6 -6
- package/core/{events.generated.js → base/events.generated.js} +1 -0
- package/core/{math.js → base/math.js} +15 -4
- package/core/{params.js → base/params.js} +3 -4
- package/core/base/util.js +32 -0
- package/core/{validate.js → base/validate.js} +28 -7
- package/core/{Engine.js → engine/Engine.js} +80 -77
- 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} +14 -12
- package/core/{loop.js → engine/loop.js} +68 -47
- package/core/{moduleSlots.js → engine/moduleSlots.js} +6 -6
- package/core/{moduleTypes.js → engine/moduleTypes.js} +13 -14
- package/core/{modules.js → engine/modules.js} +14 -11
- package/core/{page.js → engine/page.js} +36 -23
- package/core/{plugins.js → engine/plugins.js} +6 -9
- package/core/{services.js → engine/services.js} +47 -40
- package/core/{startup.js → engine/startup.js} +26 -24
- package/core/{Input.js → input/Input.js} +30 -22
- 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} +21 -20
- package/core/{DebugOverrides.js → inspect/DebugOverrides.js} +30 -16
- package/core/{Describe.js → inspect/Describe.js} +26 -22
- package/core/{Inspect.js → inspect/Inspect.js} +9 -7
- package/core/{InspectMaterials.js → inspect/InspectMaterials.js} +7 -8
- package/core/{InspectPerf.js → inspect/InspectPerf.js} +19 -13
- package/core/{InspectScene.js → inspect/InspectScene.js} +8 -5
- package/core/{MaterialInfo.js → inspect/MaterialInfo.js} +3 -2
- package/core/{UrlState.js → inspect/UrlState.js} +52 -20
- package/core/{catalog.js → inspect/catalog.js} +3 -3
- package/core/{checks.js → inspect/checks.js} +7 -5
- package/core/{debugView.js → inspect/debugView.js} +4 -4
- package/core/{describeRender.js → inspect/describeRender.js} +21 -20
- package/core/{describeText.js → inspect/describeText.js} +11 -6
- package/core/inspect/geometryWatch.js +38 -0
- package/core/{lightWatch.js → inspect/lightWatch.js} +8 -8
- package/core/{pictureWriters.js → inspect/pictureWriters.js} +15 -16
- 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} +14 -17
- package/core/{sharedPoint.js → ops/sharedPoint.js} +8 -8
- package/core/{stackFrames.js → ops/stackFrames.js} +2 -2
- package/core/{stacks.js → ops/stacks.js} +12 -14
- 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} +23 -25
- package/core/{Views.js → scene/Views.js} +14 -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} +17 -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/{pictureSlots.js → scene/pictureSlots.js} +2 -2
- package/core/{sceneDelta.js → scene/sceneDelta.js} +2 -2
- package/core/{sceneMethods.js → scene/sceneMethods.js} +36 -13
- package/core/scene/stepPoses.js +55 -0
- package/core/{targeting.js → scene/targeting.js} +4 -5
- package/core/{thingExplain.js → scene/thingExplain.js} +6 -5
- package/core/{thingOps.js → scene/thingOps.js} +4 -3
- package/core/{things.js → scene/things.js} +18 -5
- package/core/{threePatches.js → scene/threePatches.js} +1 -1
- package/core/{view.js → scene/view.js} +17 -16
- package/core/{Batching.js → stream/Batching.js} +85 -27
- package/core/{Stream.js → stream/Stream.js} +60 -30
- package/core/{batchGroups.js → stream/batchGroups.js} +10 -9
- package/core/{chunkStream.js → stream/chunkStream.js} +40 -0
- 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 +22 -19
- package/docs/API.md +24 -23
- package/docs/CODEMAP.md +76 -183
- package/docs/COMMANDS.md +66 -58
- package/docs/CONVENTIONS.md +54 -14
- package/docs/MIGRATING-0.8.md +169 -0
- package/docs/THREE.md +78 -29
- package/docs/api/assets.md +12 -13
- package/docs/api/audio.md +6 -5
- package/docs/api/budget.md +4 -4
- package/docs/api/calendar.md +10 -11
- package/docs/api/cameraRig.md +29 -29
- package/docs/api/characters.md +23 -18
- package/docs/api/clock.md +1 -1
- package/docs/api/collision.md +12 -9
- package/docs/api/content.md +6 -6
- package/docs/api/dialogue.md +3 -3
- package/docs/api/engine.md +45 -43
- package/docs/api/events.md +3 -2
- package/docs/api/flow.md +1 -1
- package/docs/api/grids.md +1 -1
- package/docs/api/ground.md +4 -5
- package/docs/api/hud.md +2 -2
- package/docs/api/i18n.md +6 -6
- package/docs/api/input.md +7 -7
- package/docs/api/interactions.md +4 -4
- package/docs/api/inventory.md +9 -9
- package/docs/api/jobs.md +5 -5
- package/docs/api/level.md +7 -7
- package/docs/api/lightPool.md +1 -6
- package/docs/api/music.md +3 -3
- package/docs/api/nav.md +10 -10
- package/docs/api/openWorld.md +1 -1
- package/docs/api/particles.md +2 -2
- package/docs/api/photo.md +4 -2
- package/docs/api/pickups.md +2 -2
- package/docs/api/post.md +20 -3
- 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 +8 -7
- package/docs/api/stream.md +7 -7
- package/docs/api/swarm.md +34 -0
- package/docs/api/terrain.md +7 -8
- package/docs/api/terrainDraw.md +1 -1
- package/docs/api/timeline.md +2 -2
- package/docs/api/tools.md +25 -22
- package/docs/api/vars.md +1 -1
- package/docs/api/vegetation.md +4 -3
- package/docs/api/vegetationDraw.md +1 -1
- package/docs/api/water.md +1 -1
- package/docs/api/weather.md +9 -9
- package/docs/api/weatherDraw.md +3 -3
- package/docs/api/world.md +5 -5
- package/docs/recipes/01-new-game.md +25 -40
- package/docs/recipes/02-npc.md +19 -20
- package/docs/recipes/03-items-pickups.md +27 -43
- package/docs/recipes/04-quests.md +3 -4
- package/docs/recipes/05-props-bake.md +29 -39
- package/docs/recipes/06-clock-events.md +27 -18
- package/docs/recipes/07-flow-scenes-pause.md +12 -17
- package/docs/recipes/08-weather-sky.md +88 -34
- package/docs/recipes/09-materials-lights-models.md +22 -36
- package/docs/recipes/10-blender-level.md +6 -7
- package/docs/recipes/11-vehicles.md +30 -22
- package/docs/recipes/12-navmesh.md +9 -8
- package/docs/recipes/13-animation.md +39 -17
- package/docs/recipes/14-custom-module.md +14 -13
- package/docs/recipes/15-perf.md +49 -26
- package/docs/recipes/16-dev-bridge.md +32 -52
- package/docs/recipes/18-world.md +36 -23
- package/docs/recipes/19-shooting-picking.md +4 -2
- package/docs/recipes/20-content-actions-save.md +30 -35
- package/docs/recipes/21-camera.md +33 -5
- package/docs/recipes/22-shop-gold.md +0 -4
- package/docs/recipes/23-ops.md +10 -10
- package/docs/recipes/26-ui-parts.md +22 -12
- package/docs/recipes/27-net.md +0 -2
- package/docs/recipes/28-terrain.md +117 -21
- package/docs/recipes/29-grid.md +2 -2
- package/docs/recipes/30-templates.md +55 -19
- package/docs/recipes/31-audio.md +5 -5
- package/docs/recipes/32-action-game.md +15 -6
- package/docs/recipes/33-stream-sources.md +2 -2
- package/docs/recipes/34-environment-lighting.md +67 -19
- package/docs/recipes/35-picture-from-reference.md +10 -17
- package/docs/recipes/36-ground-plants.md +105 -0
- package/docs/recipes/40-scene.md +7 -11
- package/docs/recipes/43-shader-patches-surfaces.md +20 -41
- package/docs/recipes/44-water-weather-hooks.md +48 -43
- package/docs/recipes/45-cascaded-shadows.md +39 -17
- package/docs/recipes/46-blender-art-route.md +7 -8
- package/docs/recipes/49-game-module-contract.md +5 -5
- package/docs/recipes/50-own-renderer.md +2 -2
- package/docs/recipes/52-around-the-picture.md +54 -98
- package/docs/recipes/53-ground-up-close.md +61 -24
- package/docs/recipes/55-mods-time-wrap.md +12 -16
- package/docs/recipes/56-webgpu-tsl.md +16 -14
- package/docs/recipes/57-control.md +9 -2
- package/docs/recipes/58-input.md +2 -2
- package/docs/recipes/59-depth-post-effects.md +1 -1
- package/docs/recipes/60-judge-the-picture.md +29 -24
- package/docs/recipes/62-picture-code.md +49 -17
- package/docs/recipes/63-third-person-start.md +17 -4
- package/docs/recipes/64-particles.md +1 -1
- package/docs/recipes/65-swarm.md +140 -0
- package/examples/action/.threedog/content-index.json +1 -1
- package/examples/action/GAMEMAP.md +2 -2
- package/examples/{sheepisland → perf-island}/.threedog/content-index.json +1 -1
- package/examples/{sheepisland → perf-island}/GAMEMAP.md +12 -11
- package/examples/{sheepisland → perf-island}/assets.js +1 -1
- package/examples/{sheepisland → perf-island}/main.js +8 -8
- package/examples/{sheepisland → perf-island}/models.js +1 -1
- package/examples/{sheepisland → perf-island}/params.js +1 -1
- package/examples/{sheepisland → perf-island}/picture/index.js +1 -1
- package/examples/{sheepisland → perf-island}/picture/palette.js +2 -2
- package/examples/{sheepisland → perf-island}/views.js +1 -1
- package/examples/plain-picture/GAMEMAP.md +1 -0
- package/examples/rc2d/GAMEMAP.md +3 -2
- package/examples/rc2d/main.js +1 -3
- package/examples/styletest/.threedog/content-index.json +1 -1
- package/examples/styletest/GAMEMAP.md +3 -2
- package/examples/techniques/contact-shadows/contactShadows.js +1 -1
- package/examples/techniques/contact-shadows/main.js +1 -1
- package/examples/techniques/interior-light/main.js +1 -1
- package/examples/techniques/modular-building/README.md +7 -6
- package/examples/techniques/outlines-and-rim/picture/post.js +1 -1
- package/examples/techniques/procedural-animation/README.md +1 -1
- package/examples/webgpu-tsl/GAMEMAP.md +1 -0
- package/examples/world/.threedog/content-index.json +1 -1
- package/examples/world/GAMEMAP.md +4 -3
- package/examples/world/picture/sky.js +1 -1
- package/index.d.ts +8 -7
- package/index.js +31 -31
- package/llms.txt +9 -13
- package/modules/ambience/Ambience.js +11 -8
- package/modules/calendar/Calendar.js +19 -19
- package/modules/calendar/index.js +13 -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 +48 -24
- package/modules/camera/contract.js +1 -0
- package/modules/camera/projection.js +2 -2
- package/modules/characters/Character.js +33 -30
- package/modules/characters/NPC.js +27 -19
- package/modules/characters/assetModel.js +14 -10
- 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 +168 -214
- package/modules/characters/moveHelpers.js +14 -3
- package/modules/characters/movers/common.js +16 -14
- package/modules/characters/movers/manual.js +1 -1
- package/modules/characters/movers/rapier.js +7 -6
- package/modules/characters/movers/simple.js +3 -3
- package/modules/characters/movers/support.js +8 -8
- package/modules/characters/npcAvoid.js +4 -4
- package/modules/characters/npcSim.js +23 -17
- 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 +2 -2
- package/modules/characters/useModel.js +3 -3
- package/modules/characters/walkTo.js +11 -17
- package/modules/collision/Collision.js +26 -20
- 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 +61 -99
- package/modules/content/loader.js +14 -17
- package/modules/content/markers.js +25 -0
- package/modules/content/models.js +10 -7
- 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 +17 -14
- package/modules/content/rules.js +25 -21
- package/modules/content/stages.js +7 -7
- package/modules/content/templates.js +20 -20
- 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 +37 -24
- package/modules/gameplay/Inventory.js +8 -9
- package/modules/gameplay/Quests.js +16 -9
- package/modules/gameplay/boxOps.js +1 -1
- package/modules/gameplay/dialogueBubbles.js +3 -4
- package/modules/gameplay/inventoryOps.js +0 -1
- package/modules/gameplay/pickups.js +22 -23
- package/modules/gameplay/questSave.js +3 -3
- package/modules/grid/Grid.js +1 -1
- package/modules/grid/Layer.js +4 -4
- package/modules/grid/index.js +7 -8
- package/modules/grid/preview.js +7 -7
- package/modules/grid/tiles.js +6 -6
- package/modules/hlod/index.js +37 -55
- package/modules/hud/index.js +17 -11
- package/modules/hud/parts.js +4 -4
- package/modules/level/contract.js +16 -0
- package/modules/level/heightfield.js +12 -10
- package/modules/level/index.js +47 -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 +28 -181
- package/modules/lights/slots.js +93 -0
- package/modules/lights/sources.js +88 -0
- package/modules/music/Music.js +30 -26
- 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 +11 -8
- package/modules/particles/effect.js +7 -5
- package/modules/particles/shaders.js +2 -1
- package/modules/photo/Photo.js +15 -17
- 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 +108 -39
- package/modules/settings/apply.js +6 -6
- package/modules/settings/sections.js +16 -14
- package/modules/settings/view.js +3 -3
- package/modules/sky/Sky.js +29 -22
- package/modules/sky/clouds.js +7 -7
- package/modules/sky/dome.js +33 -20
- package/modules/sky/domeLayers.js +9 -9
- package/modules/sky/environment.js +6 -6
- package/modules/sky/frame.js +19 -10
- package/modules/sky/season.js +7 -1
- package/modules/sky/shader.js +24 -25
- package/modules/sky/skyModule.js +14 -27
- package/modules/sky/tint.js +1 -1
- 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 +70 -52
- package/modules/terrain/chunkQueries.js +7 -24
- package/modules/terrain/chunkWorker.js +1 -1
- package/modules/terrain/draw.js +14 -11
- package/modules/terrain/index.js +28 -34
- package/modules/terrain/terrainColorMap.js +6 -3
- package/modules/terrain/terrainDefaults.js +2 -1
- package/modules/terrain/terrainEdit.js +32 -27
- package/modules/terrain/terrainGen.js +17 -12
- 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 +9 -9
- package/modules/vegetation/Vegetation.js +30 -23
- package/modules/vegetation/densityMap.js +4 -7
- package/modules/vegetation/draw.js +23 -18
- package/modules/vegetation/groundChunks.js +11 -31
- package/modules/vegetation/index.js +8 -6
- package/modules/vegetation/modelGeometry.js +3 -6
- package/modules/vegetation/nearFade.js +1 -1
- package/modules/water/Water.js +16 -16
- package/modules/water/surface.js +3 -3
- package/modules/weather/Weather.js +41 -30
- package/modules/weather/particles.js +8 -8
- package/modules/weather/weatherDraw.js +22 -18
- package/modules/world/World.js +8 -8
- 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 +11 -9
- package/package.json +42 -7
- package/presets.js +1 -3
- package/render/PostFX.js +39 -27
- package/render/backend.js +26 -32
- package/render/cascades.js +17 -12
- package/render/cascades.tsl.js +5 -8
- package/render/daylight.js +20 -3
- package/render/detail.js +8 -7
- package/render/effects.js +28 -25
- package/render/fuse.js +3 -3
- package/render/fx/cloudShadow.tsl.js +3 -3
- package/render/fx/detail.tsl.js +1 -1
- package/render/fx/index.js +5 -10
- 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 +5 -15
- package/render/fx/postWebGPU.tsl.js +27 -23
- package/render/fx/sky.tsl.js +15 -17
- package/render/fx/uniforms.tsl.js +4 -4
- package/render/fx/wind.tsl.js +1 -1
- package/render/fxNumbers.js +3 -0
- package/render/layers.js +1 -1
- package/render/lighting.js +5 -3
- package/render/lightmap.js +20 -20
- package/render/lights.js +6 -6
- package/render/lit.js +24 -0
- package/render/materials.js +8 -7
- package/render/mergeCommon.js +22 -0
- package/render/modeling.js +2 -2
- package/render/occlusion.js +20 -4
- package/render/ownFrame.js +4 -4
- package/render/patches.js +13 -13
- package/render/postWebGL.js +12 -10
- package/render/probes.js +16 -19
- 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/{core → render}/shadows.js +57 -11
- package/render/slots.js +7 -7
- package/render/terms.js +22 -24
- package/render/uniformDecl.js +1 -1
- package/types/core.d.ts +200 -153
- package/types/gameplay.d.ts +163 -91
- package/types/generated/core/{Audio.d.ts → audio/Audio.d.ts} +22 -7
- 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/{page.d.ts → engine/page.d.ts} +8 -9
- package/types/generated/core/{Input.d.ts → input/Input.d.ts} +12 -8
- package/types/generated/core/{Budget.d.ts → inspect/Budget.d.ts} +36 -26
- package/types/generated/core/{DebugOverrides.d.ts → inspect/DebugOverrides.d.ts} +2 -2
- 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 +1 -1
- package/types/generated/modules/grid/index.d.ts +3 -3
- package/types/generated/modules/music/Music.d.ts +7 -5
- package/types/generated/modules/particles/Particles.d.ts +1 -1
- package/types/generated/modules/sky/Sky.d.ts +21 -10
- 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 +1 -0
- package/types/generated/modules/weather/Weather.d.ts +16 -12
- package/types/generated/modules/weather/weatherDraw.d.ts +3 -3
- package/types/generated/modules/world/World.d.ts +5 -3
- package/types/generated/render/PostFX.d.ts +17 -11
- package/types/generated/render/materials.d.ts +1 -0
- package/types/generated/render/occlusion.d.ts +9 -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 +99 -70
- package/types/tsl.d.ts +37 -4
- package/types/world.d.ts +38 -71
- package/ui/Focus.js +10 -9
- package/ui/Parts.js +4 -3
- package/ui/UI.js +7 -7
- package/ui/defaults.js +3 -2
- package/ui/theme.js +5 -3
- package/core/assetEntry.js +0 -109
- package/core/holds.js +0 -134
- package/core/shadowTypes.js +0 -16
- package/core/util.js +0 -17
- package/docs/MIGRATING-0.3.md +0 -248
- package/docs/MIGRATING-0.4.md +0 -320
- package/docs/MIGRATING-0.5.md +0 -68
- package/docs/MIGRATING-0.6.md +0 -126
- package/docs/PERF.md +0 -245
- package/docs/recipes/36-sky-ground-plants.md +0 -158
- package/docs/recipes/37-terrain-hooks.md +0 -115
- package/docs/recipes/38-environment-hooks.md +0 -67
- package/docs/recipes/42-terrain-shape.md +0 -64
- package/docs/recipes/47-island-snow-backdrop.md +0 -43
- package/docs/recipes/54-three-idioms.md +0 -88
- package/examples/plain-picture/FINDINGS.md +0 -53
- /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/{tier.js → scene/tier.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/examples/{sheepisland → perf-island}/content/templates.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/vegetation.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/lights.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/materials.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/sky.js +0 -0
|
@@ -3,22 +3,24 @@
|
|
|
3
3
|
// engine.inspect('npc_3') the same for another actor (world record id): "why did this enemy not attack?"
|
|
4
4
|
// engine.inspect([x, z]) things around a spot, ops as the player
|
|
5
5
|
// engine.explain({ op: 'shop.buy', args }) why an op can / cannot run now (text: reason + fix first; detail: its last attempt and the events around it)
|
|
6
|
-
// engine.explain({ picture: 'fog.far' }) which line last changed a picture value (core/pictureWriters.js); a value not tracked says so
|
|
6
|
+
// engine.explain({ picture: 'fog.far' }) which line last changed a picture value (core/inspect/pictureWriters.js); a value not tracked says so
|
|
7
7
|
// engine.explain({ quest: 'first-light' }) any other key is answered by the module whose definition has explain: { quest(e, id) {...} }
|
|
8
8
|
// engine.pick(x, y).thing point -> thing: the world record a ray hit belongs to, else the engine.add object (thingOf; engine.thing is the same lookup)
|
|
9
9
|
// Built on ops because a failed op already carries its reason; explain turns that into a sentence instead of making the AI read can().
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
10
|
+
import { Vector3 } from 'three';
|
|
11
|
+
import { closest } from '../base/validate.js';
|
|
12
|
+
import { codedError } from '../base/errorHints.js';
|
|
13
|
+
import { findThing, hintThing } from '../scene/thingOps.js';
|
|
14
|
+
import { atomicNote } from '../ops/opsAtomic.js';
|
|
14
15
|
import { NO_WRITERS } from './describeRender.js';
|
|
16
|
+
import { r1 } from '../base/math.js';
|
|
15
17
|
|
|
16
18
|
const OPS_MAX = 8;
|
|
17
19
|
|
|
18
20
|
/** Where an actor stands: the player, or a world record */
|
|
19
21
|
function placeOf(e, actor) {
|
|
20
22
|
if (actor === 'player') return e.player?.position ?? e.focus;
|
|
21
|
-
return e._things.source(actor)?.get(actor).position ?? e._things.live(actor)?.getWorldPosition(new
|
|
23
|
+
return e._things.source(actor)?.get(actor).position ?? e._things.live(actor)?.getWorldPosition(new Vector3()) ?? null; // a record, else an engine.add object
|
|
22
24
|
}
|
|
23
25
|
const note = (e, op, reason) => e.ops.defs.get(op)?.reasons?.[reason];
|
|
24
26
|
|
|
@@ -35,7 +37,7 @@ export function inspect(e, at, { radius = 10 } = {}) {
|
|
|
35
37
|
const ops = e.ops.list({ available: true, actor }).sort((a, b) => b.ok - a.ok).slice(0, OPS_MAX)
|
|
36
38
|
.map(o => ({ op: o.name, args: o.args, ok: o.ok, ...(o.ok ? {} : { code: o.code, why: note(e, o.name, o.code) ?? null, facts: o.facts, nextActions: o.nextActions }) }));
|
|
37
39
|
const thing = typeof at === 'string' && at !== 'player' ? findThing(e, at) : null;
|
|
38
|
-
return { actor, at: { x:
|
|
40
|
+
return { actor, at: { x: r1(p.x), z: r1(p.z) }, near, ops, ...(thing && { thing }) };
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
/**
|
|
@@ -4,13 +4,11 @@
|
|
|
4
4
|
// Color space rule (three.js): textures holding colors (map, emissiveMap, ...) are SRGBColorSpace; textures holding data (normal, roughness,
|
|
5
5
|
// metalness, ao, bump, displacement, alpha) are NoColorSpace / linear. A wrong one is listed as an issue, first.
|
|
6
6
|
// Plain three.js equivalent: scene.traverse + material[slot] + texture.colorSpace / texture.image; renderer.info.memory.textures is the count.
|
|
7
|
-
import { isEngineMade, materialPatchSlots } from '
|
|
7
|
+
import { isEngineMade, materialPatchSlots } from '../../render/patches.js';
|
|
8
8
|
import { textureBytes, mb } from './textureBytes.js';
|
|
9
|
+
import { COLOR_SLOTS, DATA_SLOTS } from '../assets/assetReport.js';
|
|
9
10
|
|
|
10
|
-
const
|
|
11
|
-
const DATA_SLOTS = ['normalMap', 'roughnessMap', 'metalnessMap', 'aoMap', 'bumpMap', 'displacementMap', 'alphaMap', 'clearcoatMap', 'clearcoatNormalMap',
|
|
12
|
-
'clearcoatRoughnessMap', 'specularIntensityMap', 'transmissionMap', 'thicknessMap', 'iridescenceMap', 'anisotropyMap', 'sheenRoughnessMap'];
|
|
13
|
-
const OTHER_SLOTS = ['envMap', 'gradientMap', 'matcap', 'specularMap'];
|
|
11
|
+
const OTHER_SLOTS = ['lightMap', 'envMap', 'gradientMap', 'matcap']; // listed, with no one right color space
|
|
14
12
|
const SRGB = 'srgb';
|
|
15
13
|
|
|
16
14
|
/** Textures of a material: the standard slots, then any texture uniform of a ShaderMaterial */
|
|
@@ -25,7 +23,7 @@ function texturesOf(m) {
|
|
|
25
23
|
function spaceIssue(slot, t) {
|
|
26
24
|
if (t.isRenderTargetTexture || t.isDepthTexture) return null;
|
|
27
25
|
const name = `${slot} "${t.name || t.uuid.slice(0, 8)}"`;
|
|
28
|
-
if (COLOR_SLOTS.includes(slot) &&
|
|
26
|
+
if (COLOR_SLOTS.includes(slot) && t.colorSpace !== SRGB && !t.isDataTexture && !t.isCompressedTexture)
|
|
29
27
|
return `${name} holds colors but its colorSpace is '${t.colorSpace || 'none'}': it renders washed out. Fix: texture.colorSpace = THREE.SRGBColorSpace`;
|
|
30
28
|
if (DATA_SLOTS.includes(slot) && t.colorSpace === SRGB)
|
|
31
29
|
return `${name} holds data but is marked sRGB: values are bent (normals tilt, roughness shifts). Fix: texture.colorSpace = THREE.NoColorSpace`;
|
|
@@ -43,8 +41,9 @@ export function inspectMaterials(e, { limit = 30 } = {}) {
|
|
|
43
41
|
e.scene.traverse(o => {
|
|
44
42
|
if (!o.material) return;
|
|
45
43
|
for (const m of [].concat(o.material)) {
|
|
46
|
-
if (!m
|
|
47
|
-
const
|
|
44
|
+
if (!m) continue;
|
|
45
|
+
const real = m.userData?._dbgOf ?? m; // a debug-view stand-in: the real picture is the material behind it
|
|
46
|
+
const r = mats.get(real) ?? mats.set(real, { m: real, users: 0, first: o }).get(real);
|
|
48
47
|
r.users++;
|
|
49
48
|
}
|
|
50
49
|
});
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
import { inspectMaterials } from './InspectMaterials.js';
|
|
7
7
|
import { programCosts } from './shaderCost.js';
|
|
8
8
|
import { mb } from './textureBytes.js';
|
|
9
|
-
import { r1 } from '
|
|
10
|
-
import { stats, memory } from '
|
|
9
|
+
import { r1 } from '../base/math.js';
|
|
10
|
+
import { stats, memory } from '../../render/backend.js';
|
|
11
11
|
|
|
12
12
|
/** Reference budgets (desktop, 60 fps) used when the game set none in engine.budget */
|
|
13
13
|
const REFERENCE = { drawCalls: 300, triangles: 1_000_000, programs: 60, textureMB: 256, cpuMs: 8, compileMs: 50 };
|
|
@@ -16,7 +16,7 @@ const NEXT = {
|
|
|
16
16
|
triangles: 'LOD / hlod for far objects (THREE.LOD), lower-poly models; hlod cells or big batches behind walls: engine.occlusion.enabled = true; `threedog capture` lists the largest draws',
|
|
17
17
|
programs: 'engine.inspect.materials(): share materials instead of cloning per mesh; each distinct material setup and light setup is one program',
|
|
18
18
|
textureMB: 'engine.inspect.materials() lists the largest textures: smaller sizes, KTX2 compressed textures (KTX2Loader)',
|
|
19
|
-
cpuMs: 'engine.profile(true) then engine.profile() (ms per module), engine.cpuPhases (fixed / frame / render)',
|
|
19
|
+
cpuMs: 'engine.profile(true) then engine.profile() (ms per module), engine.inspect.perf().cpuPhases (fixed / frame / render)',
|
|
20
20
|
compileMs: 'compile before play: renderer.compileAsync(scene, camera) after adding new materials, keep the light count fixed (lightPool)',
|
|
21
21
|
lights: 'many lights: light pool, engine.use(lightPool({ point: 8 })) then engine.lightPool.add(torch, { intensity: 4, distance: 8 })',
|
|
22
22
|
shadowLights: 'set castShadow = false on the lights that can go without; a point light draws six shadow maps',
|
|
@@ -24,13 +24,13 @@ const NEXT = {
|
|
|
24
24
|
shadowMapSize: 'pick light.shadow.mapSize from engine.tier in the picture code',
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
/** @param {any} e the engine @param {{ top?: number }} [opts] top: how many costliest programs to list */
|
|
28
27
|
// "first frame 1840 ms = script 210 + construct 40 + ..." (engine.startup.phases; startup.js); empty before the first frame
|
|
29
28
|
function firstFrameLine(s) {
|
|
30
29
|
if (s?.firstFrameMs == null) return '';
|
|
31
30
|
return `first frame: ${s.firstFrameMs} ms from page open = ${Object.entries(s.phases).map(([k, v]) => `${k} ${v}`).join(' + ')}`;
|
|
32
31
|
}
|
|
33
32
|
|
|
33
|
+
/** @param {any} e the engine @param {{ top?: number }} [opts] top: how many costliest programs to list */
|
|
34
34
|
export function inspectPerf(e, { top = 5 } = {}) {
|
|
35
35
|
const r = e.renderer, s = stats(r), lim = e.budget?.limits ?? {};
|
|
36
36
|
const mats = inspectMaterials(e, { limit: 0 });
|
|
@@ -39,30 +39,36 @@ export function inspectPerf(e, { top = 5 } = {}) {
|
|
|
39
39
|
const programs = programCosts(r, e.scene); // WebGPU too: the scene's node programs (no program count there, but the costliest still listed)
|
|
40
40
|
const values = {
|
|
41
41
|
drawCalls: s.drawCalls, triangles: s.triangles, programs: s.programs, // null on WebGPU (no program list): not counted, not budgeted, rather than a 0 that always passes
|
|
42
|
-
|
|
42
|
+
// only the real-time loop times itself: halted, JS ms and fps have no value (as in describe), and a 0 would read as a good result
|
|
43
|
+
textureMB: r1(mats.textureBytes / 1048576), cpuMs: e.halted ? null : r1(e._cpuMs ?? 0), compileMs: worst,
|
|
43
44
|
};
|
|
44
45
|
const gpu = e.budget?.values() ?? {};
|
|
45
46
|
for (const k of ['lights', 'shadowLights', 'shadowMaps', 'shadowMapSize']) values[k] = gpu[k];
|
|
46
47
|
// these four have no reference: without a limit they stay out, a number with nothing to read it against
|
|
47
|
-
|
|
48
|
+
// no draw counted = no frame to judge (headless before the first frame, or a page that has not drawn yet). A 0 here is not a good result, so the frame's
|
|
49
|
+
// own metrics leave the budget list instead of showing a tick; what is true without a frame (textures, lights) stays
|
|
50
|
+
const measured = s.drawCalls > 0, frameOnly = new Set(['drawCalls', 'triangles', 'cpuMs', 'compileMs']);
|
|
51
|
+
const budgets = Object.keys(values).filter(k => values[k] != null && (measured || !frameOnly.has(k)) && (e.budget?.limitOf(k) ?? REFERENCE[k]) != null).map(k => {
|
|
48
52
|
const limit = e.budget?.limitOf(k) ?? REFERENCE[k], own = lim[k] != null;
|
|
49
53
|
const ok = values[k] <= limit;
|
|
50
54
|
return { name: k, value: values[k], budget: limit, from: own ? 'engine.budget' : 'reference', ok, ...(ok ? {} : { next: NEXT[k] }) };
|
|
51
55
|
});
|
|
52
|
-
const p = e.
|
|
56
|
+
const p = e._cpuPhases ?? {};
|
|
53
57
|
const fmtN = v => v >= 1e6 ? r1(v / 1e6) + 'M' : v >= 1e4 ? Math.round(v / 1000) + 'k' : String(v);
|
|
54
58
|
const hint = e.batching?.stats.hint;
|
|
55
|
-
|
|
59
|
+
// lights: point and spot only, what costs on every lit pixel (core/scene/gameLights.js); a sun or a hemisphere light is not in this count
|
|
60
|
+
const unit = { textureMB: ' MB', cpuMs: ' ms', compileMs: ' ms (worst stall)', lights: ' point + spot' };
|
|
56
61
|
const text = [
|
|
57
|
-
`frame: ${values.drawCalls} draw calls (incl. shadow + post passes), ${fmtN(values.triangles)} triangles, ${values.programs == null ? 'programs not counted (WebGPU)' : values.programs + ' programs'}, ~${mb(mats.textureBytes)} textures `
|
|
58
|
-
+ `(${mats.textures}), JS ${values.cpuMs} ms (fixed ${r1(p.fixed ?? 0)} / frame ${r1(p.frame ?? 0)} / render ${r1(p.render ?? 0)}), fps ${Math.round(e.fps ?? 0)}
|
|
62
|
+
measured ? `frame: ${values.drawCalls} draw calls (incl. shadow + post passes), ${fmtN(values.triangles)} triangles, ${values.programs == null ? 'programs not counted (WebGPU)' : values.programs + ' programs'}, ~${mb(mats.textureBytes)} textures `
|
|
63
|
+
+ `(${mats.textures}), ${e.halted ? 'JS ms and fps not measured (the loop is halted, only real-time running times them)' : `JS ${values.cpuMs} ms (fixed ${r1(p.fixed ?? 0)} / frame ${r1(p.frame ?? 0)} / render ${r1(p.render ?? 0)}), fps ${Math.round(e.fps ?? 0)}`}`
|
|
64
|
+
: `nothing measured yet: no draw has been counted, so draw calls, triangles, JS ms and compile stalls have no value. Draw a frame first (engine.step(1 / 60), or threedog step 1 / snap --play), then ask again. ~${mb(mats.textureBytes)} textures (${mats.textures})`,
|
|
59
65
|
firstFrameLine(e.startup),
|
|
60
66
|
`compile: startup ${e.startup?.compileMs ?? '?'} ms; ${compiles.length} stall frame${compiles.length === 1 ? '' : 's'} during play${compiles.length ? ` (worst ${worst} ms, last at ${compiles.at(-1).at} s, +${compiles.at(-1).programs} programs)` : ''}`,
|
|
61
67
|
...budgets.map(b => `${b.ok ? '✓' : '✗'} ${b.name} ${b.name === 'triangles' ? fmtN(b.value) : b.value}${unit[b.name] ?? ''} / ${b.name === 'triangles' ? fmtN(b.budget) : b.budget} (${b.from})${b.ok ? '' : ' -> ' + b.next}`),
|
|
62
|
-
// dev: many identical game meshes drawn one by one (batching leaves game objects alone unless they opt in; core/Batching.js)
|
|
68
|
+
// dev: many identical game meshes drawn one by one (batching leaves game objects alone unless they opt in; core/stream/Batching.js)
|
|
63
69
|
hint ? `batching: ${hint}` : '',
|
|
64
70
|
programs.length ? `costliest programs (fragment lines + 25 x samplers): ${programs.slice(0, top).map(c => `${c.name} ${c.score} (${c.fragmentLines} lines, ${c.samplers} samplers)`).join(', ')}; see them: engine.debug.view('shaderCost')` : '',
|
|
65
71
|
].filter(Boolean).join('\n');
|
|
66
|
-
return { ...values, cpuPhases: { ...p }, fps: r1(e.fps ?? 0), startupCompileMs: e.startup?.compileMs ?? null, compiles: compiles.slice(),
|
|
67
|
-
textureCount: mats.textures, memory: memory(r), programCosts: programs.slice(0, top), budgets, ok: budgets.every(b => b.ok), text };
|
|
72
|
+
return { ...values, cpuPhases: { ...p }, fps: e.halted ? null : r1(e.fps ?? 0), startupCompileMs: e.startup?.compileMs ?? null, compiles: compiles.slice(),
|
|
73
|
+
textureCount: mats.textures, memory: memory(r), programCosts: programs.slice(0, top), budgets, measured, ok: measured && budgets.every(b => b.ok), text };
|
|
68
74
|
}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import * as THREE from 'three';
|
|
6
6
|
import { materialInfo, infoLine } from './MaterialInfo.js';
|
|
7
7
|
import { describeRender } from './describeRender.js';
|
|
8
|
+
import { r1 } from '../base/math.js';
|
|
8
9
|
|
|
9
10
|
const KINDS = [['isMesh', 'Mesh'], ['isPoints', 'Points'], ['isLine', 'Line'], ['isSprite', 'Sprite']];
|
|
10
11
|
const kindOf = o => KINDS.find(([k]) => o[k])?.[1] ?? null;
|
|
@@ -12,7 +13,6 @@ const PLANES = ['right', 'left', 'bottom', 'top', 'far', 'near']; // order of
|
|
|
12
13
|
// reasons that are just "not in the picture right now" (the camera looks elsewhere), not a bug: listed after the other undrawn objects
|
|
13
14
|
const CULLED = new Set(['outside-frustum', 'behind-camera', 'beyond-far', 'fogged-out']);
|
|
14
15
|
const NAN_SCAN_MAX = 100000; // vertices checked for NaN per geometry: enough to find a broken generator, bounded for huge merged meshes
|
|
15
|
-
const r1 = v => Math.round(v * 10) / 10;
|
|
16
16
|
const fmt = o => o.name || '(unnamed)';
|
|
17
17
|
const why = (code, text, fix, level = 'hidden') => ({ code, level, text, ...(fix && { fix }) });
|
|
18
18
|
|
|
@@ -107,7 +107,8 @@ function viewReasons(o, type, center, radius, view, cam, fog) {
|
|
|
107
107
|
else if (radius === 0 && (type === 'Mesh' || type === 'Line')) r.push(why('radius-zero',
|
|
108
108
|
'its bounding sphere radius is 0: all vertices are at one point, nothing to see', 'check the generator (a size or radius of 0)'));
|
|
109
109
|
if (!Number.isFinite(radius)) return r;
|
|
110
|
-
if (
|
|
110
|
+
if (o.frustumCulled === false) { /* three draws it wherever its sphere is */ }
|
|
111
|
+
else if (dz < -radius) r.push(why('behind-camera', `it is behind the camera (${r1(-dz)} m behind)`,
|
|
111
112
|
'move the camera or the object; check the camera looks where you think'));
|
|
112
113
|
else if (dz - radius > cam.far) r.push(why('beyond-far', `it is beyond camera.far (${r1(dz - radius)} m away, far is ${cam.far})`,
|
|
113
114
|
'raise camera.far or bring the object closer'));
|
|
@@ -126,7 +127,7 @@ function viewReasons(o, type, center, radius, view, cam, fog) {
|
|
|
126
127
|
|
|
127
128
|
/** One object: its reasons (most likely first: switched off, wrong layer, material, transform / geometry, then where it is) and its record */
|
|
128
129
|
function checkObject(o, type, ctx) {
|
|
129
|
-
const { view, cam, scene, memo } = ctx, reasons = [], off = [];
|
|
130
|
+
const { view, cam, scene, memo, replays } = ctx, reasons = [], off = [];
|
|
130
131
|
for (let n = o; n; n = n.parent) if (n.visible === false) off.push(n);
|
|
131
132
|
if (off[0] === o) reasons.push(why('hidden-self', 'its own visible is false', `${fmt(o)}.visible = true`));
|
|
132
133
|
const anc = off.find(n => n !== o);
|
|
@@ -136,6 +137,8 @@ function checkObject(o, type, ctx) {
|
|
|
136
137
|
reasons.push(why('layers', `layers do not match the camera (object mask ${o.layers.mask}, camera mask ${cam.layers.mask}): the renderer skips it`,
|
|
137
138
|
'object.layers.enable(n) for a layer the camera sees, or camera.layers.enable(n)'));
|
|
138
139
|
}
|
|
140
|
+
// here what the state says and what draws can differ, so it comes first. Only where bundles exist: elsewhere a BundleGroup is a plain group
|
|
141
|
+
if (replays) for (let n = o.parent; n; n = n.parent) if (n.isBundleGroup) { reasons.push(why('in-bundle', `inside BundleGroup ${fmt(n)}, which replays what it recorded: a change to its visible, children or castShadow shows after a new recording`, `${fmt(n)}.needsUpdate = true`, 'maybe')); break; }
|
|
139
142
|
reasons.push(...materialReasons(o));
|
|
140
143
|
const me = o.matrixWorld.elements, sc = [Math.hypot(me[0], me[1], me[2]), Math.hypot(me[4], me[5], me[6]), Math.hypot(me[8], me[9], me[10])];
|
|
141
144
|
const shape = shapeReasons(o, type, sc, memo);
|
|
@@ -143,7 +146,7 @@ function checkObject(o, type, ctx) {
|
|
|
143
146
|
let center = new THREE.Vector3().setFromMatrixPosition(o.matrixWorld), radius = NaN;
|
|
144
147
|
if (!shape.some(x => ['geometry-nan', 'position-nan', 'geometry-empty'].includes(x.code))) {
|
|
145
148
|
let bs = o.boundingSphere ?? o.geometry.boundingSphere;
|
|
146
|
-
if (!bs) { (o.
|
|
149
|
+
if (!bs) { (o.computeBoundingSphere ? o : o.geometry).computeBoundingSphere(); bs = o.boundingSphere ?? o.geometry.boundingSphere; }
|
|
147
150
|
center = bs.center.clone().applyMatrix4(o.matrixWorld);
|
|
148
151
|
radius = bs.radius * Math.max(...sc);
|
|
149
152
|
if (view) reasons.push(...viewReasons(o, type, center, radius, view, cam, scene.fog));
|
|
@@ -171,7 +174,7 @@ function lineOf(x) {
|
|
|
171
174
|
* @param {{ hidden?: boolean, limit?: number }} [opts] hidden: list only objects that are not drawn; limit: how many to list (default 40; counts cover all)
|
|
172
175
|
*/
|
|
173
176
|
export function inspectScene(e, { hidden = false, limit = 40 } = {}) {
|
|
174
|
-
const scene = e.scene, cam = e.camera, ctx = { scene, cam, view: viewOf(cam), memo: new Map() };
|
|
177
|
+
const scene = e.scene, cam = e.camera, ctx = { scene, cam, view: viewOf(cam), memo: new Map(), replays: !!e.renderer?.backend?.beginBundle };
|
|
175
178
|
scene.updateMatrixWorld();
|
|
176
179
|
const items = [], counts = { total: 0, drawn: 0, notDrawn: 0, byType: {} };
|
|
177
180
|
scene.traverse(o => {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// Material provenance for engine.inspect.scene(): "why is this mesh the wrong colour?" Diagnostics only: reads the material, never changes it.
|
|
2
2
|
// from says who made it: 'engine' (neutralMaterial and the like, render/patches.js keeps the mark) or 'game' (any other three.js material).
|
|
3
|
-
import { isEngineMade } from '
|
|
3
|
+
import { isEngineMade } from '../../render/patches.js';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
/** A three.js color as '#rrggbb' @param {any} c */
|
|
6
|
+
export const hex = c => '#' + c.getHexString();
|
|
6
7
|
const MAPS = ['map', 'normalMap', 'bumpMap', 'roughnessMap', 'metalnessMap', 'emissiveMap', 'alphaMap', 'aoMap', 'lightMap', 'gradientMap'];
|
|
7
8
|
const SIDES = ['front', 'back', 'double'];
|
|
8
9
|
|
|
@@ -16,15 +16,20 @@
|
|
|
16
16
|
// Two phases, both called from start():
|
|
17
17
|
// early(): before modules are ready, applies save, pos, time, weather (terrain is generated directly at the new position)
|
|
18
18
|
// late(): after engine:ready, play (start a run when the title is up), at, view (engine.views), cutscene ('skip' skips the opening cutscene), sets weather once more, advances wait seconds, aligns time again, then emits state:applied
|
|
19
|
-
// In a game, await engine.applyState({...}) at any time runs both phases back to back
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
19
|
+
// In a game, await engine.applyState({...}) at any time runs both phases back to back; it resolves to { ok, refused: [{ key, value, reason }] }, because a request
|
|
20
|
+
// that did nothing (a weather name the game lacks, a key no module handles) must not read as done. A hook refuses with { refused: { key: reason } }; it names the
|
|
21
|
+
// keys it handles in its module's stateKeys (a hook without stateKeys counts for every key, so a game's own hook is never refused for it).
|
|
22
|
+
import { warnMissing, warnOnce, DEV } from '../base/validate.js';
|
|
23
|
+
import { readParams, keysSchema } from '../base/params.js';
|
|
24
|
+
import { xzOf, yOf } from '../base/math.js';
|
|
25
|
+
import { unsettled } from '../engine/headlessLoad.js';
|
|
26
|
+
import { codedError } from '../base/errorHints.js';
|
|
25
27
|
|
|
26
|
-
// fresh deletes saves, so it acts only on a clear yes
|
|
27
|
-
const
|
|
28
|
+
// fresh deletes saves, so it acts only on a clear yes (a bare ?fresh reads as ''); anything that is neither a yes nor a no is refused in _expand, never ignored
|
|
29
|
+
const FRESH_ON = [true, 1, '1', ''], FRESH_OFF = [false, 0, '0', 'false'];
|
|
30
|
+
const freshOn = v => FRESH_ON.includes(v);
|
|
31
|
+
// met without a module: play has its own core path, and skipping a cutscene in a game without any has nothing left to do
|
|
32
|
+
const NOTHING_NEEDED = ['play', 'cutscene'];
|
|
28
33
|
const KEYS = ['state', 'time', 'season', 'weather', 'pos', 'at', 'save', 'wait', 'cutscene', 'view', 'play', 'fresh'];
|
|
29
34
|
|
|
30
35
|
export class UrlState {
|
|
@@ -36,6 +41,7 @@ export class UrlState {
|
|
|
36
41
|
this.states = new Map(); // name -> params
|
|
37
42
|
this.pending = null; // URL parameters (used by start())
|
|
38
43
|
this.applied = false; // URL parameters are fully applied (npm run shot waits for it)
|
|
44
|
+
this._refused = new Map(); // key -> { key, value, reason } of the apply in progress
|
|
39
45
|
}
|
|
40
46
|
/** Returns a handle: like other registrations there is only remove() to undo; after a same-name redefinition the old handle's remove() will not delete the new one */
|
|
41
47
|
define(name, params, { owner } = {}) {
|
|
@@ -53,8 +59,10 @@ export class UrlState {
|
|
|
53
59
|
delete p.state;
|
|
54
60
|
}
|
|
55
61
|
readParams('applyState()', keysSchema(KEYS), p);
|
|
62
|
+
if (p.fresh != null && !freshOn(p.fresh) && !FRESH_OFF.includes(p.fresh)) throw codedError('state-value', `applyState({ fresh: ${JSON.stringify(p.fresh)} }): fresh takes true or 1 (delete the saves), false or 0 (keep them)`);
|
|
56
63
|
if (typeof p.pos === 'string') { const [x, z] = p.pos.split(',').map(Number); p.pos = { x, z }; }
|
|
57
64
|
if (p.wait != null) p.wait = +p.wait;
|
|
65
|
+
if (Number.isNaN(p.wait)) throw codedError('state-value', `applyState({ wait: ${JSON.stringify(params.wait)} }): wait takes seconds`);
|
|
58
66
|
if (p.at != null) p.play ??= true; // a place is somewhere in the game, never on the start screen
|
|
59
67
|
return p;
|
|
60
68
|
}
|
|
@@ -63,6 +71,16 @@ export class UrlState {
|
|
|
63
71
|
if (!Object.keys(part).length) return [];
|
|
64
72
|
return [...this.engine.modules.values()].filter(m => m.applyState).map(m => m.applyState(this.engine, part));
|
|
65
73
|
}
|
|
74
|
+
_refuse(p, key, reason) { this._refused.set(key, { key, value: p[key], reason }); }
|
|
75
|
+
/** Run the hooks for these keys and keep what they refused; a key no installed module handles is refused here, since nothing else would ever say so */
|
|
76
|
+
async _ask(p, keys) {
|
|
77
|
+
const mods = [...this.engine.modules.values()].filter(m => m.applyState);
|
|
78
|
+
for (const k of keys) this._refused.delete(k); // asked again (weather and time are, late in the setup): the last answer is the one that stands
|
|
79
|
+
for (const k of keys) if (p[k] != null && !NOTHING_NEEDED.includes(k) && !mods.some(m => !m.stateKeys || m.stateKeys.includes(k))) this._refuse(p, k, `no installed module handles ${k}`);
|
|
80
|
+
const out = await Promise.all(this._hooks(p, keys));
|
|
81
|
+
for (const r of out) for (const [k, reason] of Object.entries(r?.refused ?? {})) this._refuse(p, k, reason);
|
|
82
|
+
return out;
|
|
83
|
+
}
|
|
66
84
|
/** Wait for modules to be ready (terrain chunks must generate after a teleport); in headless mode advance frames ourselves */
|
|
67
85
|
async _settle() {
|
|
68
86
|
const e = this.engine;
|
|
@@ -92,7 +110,7 @@ export class UrlState {
|
|
|
92
110
|
if (freshOn(p.fresh)) await this._fresh();
|
|
93
111
|
if (p.save != null) await e.saves.load(String(p.save));
|
|
94
112
|
if (p.pos) this._place(p.pos);
|
|
95
|
-
await
|
|
113
|
+
await this._ask(p, ['time', 'season', 'weather']);
|
|
96
114
|
}
|
|
97
115
|
async _late(p) {
|
|
98
116
|
const e = this.engine;
|
|
@@ -101,32 +119,46 @@ export class UrlState {
|
|
|
101
119
|
const ended = this._ended; this._ended = false;
|
|
102
120
|
if (p.play != null) {
|
|
103
121
|
// ended: without a title part quit leaves nothing open to press Start on, and a run that ended must still start again (session:start)
|
|
104
|
-
|
|
105
|
-
await
|
|
122
|
+
const started = ended || e.ui.isOpen('title');
|
|
123
|
+
if (started) { await e.session.newGame(); e.ui.close('title'); }
|
|
124
|
+
await this._ask(p, ['play']);
|
|
125
|
+
// a new run puts the player at the start, which undid the pos of _early while `state` still printed Set
|
|
126
|
+
if (started && p.pos && p.at == null) { this._place(p.pos); await this._settle(); }
|
|
106
127
|
}
|
|
107
128
|
if (p.at != null) {
|
|
108
|
-
const where = (await
|
|
109
|
-
|
|
110
|
-
this._place(where);
|
|
111
|
-
|
|
129
|
+
const where = (await this._ask(p, ['at'])).find(r => r && !r.refused);
|
|
130
|
+
// save, position, time and weather are already applied, so this is a refusal like its siblings, never a throw that leaves the rest undone
|
|
131
|
+
if (where) { this._place(where); await this._settle(); } // the ground and models around the place, before wait and the picture
|
|
132
|
+
else if (!this._refused.has('at')) this._refuse(p, 'at', 'no installed module knows place names: install content(), or use pos=x,z');
|
|
112
133
|
}
|
|
113
|
-
await
|
|
134
|
+
await this._ask(p, ['cutscene', 'weather']); // set weather once more: the opening auto-weather or settings in engine:ready may have changed it
|
|
114
135
|
if (p.wait > 0) for (let s = p.wait; s > 1e-6; s -= 0.5) { // advance in small slices so Promises (the next cutscene segment) and background threads continue between them
|
|
115
136
|
e.step(Math.min(0.5, s), { render: false, describe: false });
|
|
116
137
|
await new Promise(r => setTimeout(r, 0)); // main-loop: yield to the browser (background threads, Promise continuations) without advancing game time
|
|
117
138
|
}
|
|
118
|
-
await
|
|
119
|
-
if (p.view && e.views.list().length
|
|
139
|
+
await this._ask(p, ['time', 'season']); // advancing moves time and the day, so align them last
|
|
140
|
+
if (p.view && e.views.list().length && e.views.show(p.view)) { // a page with its own ?view= (no engine.views declared) handles it itself
|
|
141
|
+
if (e.headless) e._frameHooks(0, true); // one loading frame: the modules see the new focus, so _settle has something to wait for
|
|
142
|
+
await this._settle(); // a picture of the view must not be taken before the world around it has loaded
|
|
143
|
+
}
|
|
120
144
|
this.applied = true;
|
|
121
145
|
e.events.emit('state:applied', p);
|
|
122
146
|
}
|
|
123
147
|
|
|
124
|
-
/**
|
|
148
|
+
/** What the last applyState or the URL could not do: applyState hands this back, but a URL has no caller, so a tool that built one reads it here @returns {{ key: string, value: any, reason: string }[]} */
|
|
149
|
+
get refused() { return [...this._refused.values()]; }
|
|
150
|
+
|
|
151
|
+
/** Apply a set of parameters (usable any time in a game; both phases run back to back). Resolves to { ok, refused } */
|
|
125
152
|
apply(params) {
|
|
126
153
|
const p = this._expand(params);
|
|
127
154
|
this.applied = false;
|
|
155
|
+
this._refused.clear();
|
|
128
156
|
// setting up a scenario is not a gameplay action: the ops guard lets its writes through until it finishes
|
|
129
|
-
return this.engine.ops.allow(async () => {
|
|
157
|
+
return this.engine.ops.allow(async () => {
|
|
158
|
+
await this._early(p); await this._settle(); await this._late(p);
|
|
159
|
+
const { refused } = this;
|
|
160
|
+
return { ok: !refused.length, refused };
|
|
161
|
+
}).finally(() => { this.applied = true; }); // a scenario that threw is over too: stateApplied must not wait for it
|
|
130
162
|
}
|
|
131
163
|
/** In start(), before modules are ready: read the URL parameters and apply save/pos/time/weather */
|
|
132
164
|
early() {
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
// Ownership: engine.use / module init take a snapshot of the op, save and describe names before and after (catalogSnap / catalogClaim);
|
|
10
10
|
// what existed before the first engine.use is 'core', what appeared outside any module is 'game'. An op named '<module>.verb' or a save
|
|
11
11
|
// part keyed by the module name belongs to that module even when registered later (from game code calling into the module).
|
|
12
|
-
import { parseSchema, schemaInfo } from '
|
|
13
|
-
import { ENGINE_PARAMS } from '
|
|
12
|
+
import { parseSchema, schemaInfo } from '../base/params.js';
|
|
13
|
+
import { ENGINE_PARAMS } from '../engine/Engine.js';
|
|
14
14
|
|
|
15
15
|
const TIME_HOOKS = ['fixed', 'frame', 'afterRender', 'skip', 'afterLoad'];
|
|
16
16
|
const MAX_API = 200; // the dev bridge narrows this to what the api page lists (tools/threedog/catalog.mjs)
|
|
@@ -176,7 +176,7 @@ export function catalog(e, id) {
|
|
|
176
176
|
if (e.modules.has(id)) return moduleEntry(e, e.modules.get(id));
|
|
177
177
|
if (e.ops.defs.has(id)) return opInfo(e, id, true);
|
|
178
178
|
if (id === 'core' || id === 'game') return looseEntry(e, id);
|
|
179
|
-
if (id
|
|
179
|
+
if (Object.hasOwn(CAPABILITIES, id) && e[id]) return capabilityEntry(e, id);
|
|
180
180
|
return null;
|
|
181
181
|
}
|
|
182
182
|
const list = entries(e).map(summary);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// Consistency checks a game (or an AI) can call in dev and tests, mixed into Engine.prototype. They never throw on a mismatch: they return { ok, diffs }, so a test
|
|
2
2
|
// or the dev bridge prints the first differing paths instead of a bare "false".
|
|
3
|
-
// await engine.checkSkip(600) // engine.skip(600
|
|
3
|
+
// await engine.checkSkip(600) // engine.skip(600 calendar seconds) vs stepping the same time in fixed steps: same saved state?
|
|
4
4
|
// await engine.checkSave() // save -> load: same saved state?
|
|
5
5
|
// "State" is what engine.saves.collect() returns (every save part), so a module that keeps state outside its save part is invisible here: that is the point
|
|
6
6
|
// of the check, a skip or a load that loses it shows up as a diff of the part's data.
|
|
7
|
-
import { failure } from '
|
|
7
|
+
import { failure } from '../ops/opsFail.js';
|
|
8
8
|
|
|
9
9
|
const MAX_DIFFS = 20;
|
|
10
10
|
|
|
@@ -32,9 +32,9 @@ export const checkMethods = {
|
|
|
32
32
|
* Is skipping time the same as living through it? Saves the state, runs engine.skip({ seconds }), saves it again, rewinds to the first state, steps the same
|
|
33
33
|
* span in fixed steps (engine.step, no rendering) and compares the two end states. The world is left at the stepped state, so call it on a scratch playthrough
|
|
34
34
|
* or a test, not in the middle of a real one. A diff usually means a module that keeps its own time lacks (or has a wrong) skip hook.
|
|
35
|
-
* @param {number} seconds
|
|
35
|
+
* @param {number} seconds calendar seconds, > 0
|
|
36
36
|
* @param {{ ignore?: string[] }} [opts] ignore: state paths (or their prefix, e.g. 'random') not to compare
|
|
37
|
-
* Refuses (failure: { ok: false, code: 'frozen' | 'rate0', facts, nextActions, diffs }) while gameplay is frozen
|
|
37
|
+
* Refuses (failure: { ok: false, code: 'frozen' | 'rate0', facts, nextActions, diffs }) while gameplay is frozen, or the calendar is stopped.
|
|
38
38
|
* @returns {Promise<{ ok: boolean, code?: string, diffs: { path: string, a: any, b: any }[] }>} a = after skip, b = after stepping
|
|
39
39
|
* @example const r = await engine.checkSkip(600); if (!r.ok) console.log(r.diffs);
|
|
40
40
|
*/
|
|
@@ -45,10 +45,12 @@ export const checkMethods = {
|
|
|
45
45
|
const perFixed = this.clock.speed; // calendar seconds per real second
|
|
46
46
|
if (!(perFixed > 0)) return refuse('rate0', `calendar stopped (engine.clock.rate ${this.clock.rate}, world speed ${this.time.scale('world')}); end the mod that sets it to 0, e.g. engine.mod('clock.rate', { owner: 'game', set: 1 })`);
|
|
47
47
|
this.commits.tick(Infinity); // pending background results land first, so they cannot sit in one path's state and not the other's
|
|
48
|
-
const before = JSON.parse(JSON.stringify(this.saves.collect()));
|
|
48
|
+
const before = JSON.parse(JSON.stringify(this.saves.collect())), rewind = this.time._mark();
|
|
49
49
|
await this.skip({ seconds });
|
|
50
50
|
const skipped = snapshot(this);
|
|
51
|
+
rewind(); // real too: the stepped path must start where the skip started, and no save restores this clock
|
|
51
52
|
if (!(await this.saves.apply(before, 'checkSkip'))) return { ok: false, diffs: [{ path: '(rewind)', a: 'applied', b: 'refused' }] };
|
|
53
|
+
this.commits.rebase(); // like a new playthrough: anything requested during the skip was due on the tick count just undone
|
|
52
54
|
this.step(seconds / perFixed, { render: false });
|
|
53
55
|
const diffs = diffState(skipped, snapshot(this), ignore);
|
|
54
56
|
return { ok: diffs.length === 0, diffs };
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// Why a view is an entry of the debug override chain and not its own material swap: two independent swaps on one mesh restored each other's stale
|
|
6
6
|
// material and disposed the real one (review H3). In the chain, the albedo view is a { material: 'flat' } entry on the scene and the other modes an apply()
|
|
7
7
|
// entry whose undo only puts back what it changed, and only disposes the override material it created.
|
|
8
|
-
// One view at a time, held in the stack 'debug.view' (core/stacks.js, kind top): only its owner (or force) switches it or turns it off.
|
|
8
|
+
// One view at a time, held in the stack 'debug.view' (core/ops/stacks.js, kind top): only its owner (or force) switches it or turns it off.
|
|
9
9
|
// WebGPURenderer: the same plain-three override materials, on purpose. three's renderer turns any plain material into its node twin
|
|
10
10
|
// (NodeLibrary.fromMaterial) and, for scene.overrideMaterial, copies each mesh's positionNode onto the override, so swayed meshes keep their
|
|
11
11
|
// shape; a node-material copy here would add a three/webgpu import for nothing. Per-mesh stand-ins (albedo, shaderCost) are node materials on
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
// Why one list and not a debug option per module: an AI learns one call (debug.view) for every "show me the hidden thing", the view is owner-scoped
|
|
15
15
|
// and said in describe().render like the built-in ones, and the core never names a module (check rule R27).
|
|
16
16
|
import * as THREE from 'three';
|
|
17
|
-
import { warnMissing } from '
|
|
17
|
+
import { warnMissing } from '../base/validate.js';
|
|
18
18
|
import { materialCost } from './shaderCost.js';
|
|
19
|
-
import { codedError } from '
|
|
19
|
+
import { codedError } from '../base/errorHints.js';
|
|
20
20
|
|
|
21
21
|
const VIEW_MODES = ['albedo', 'lighting', 'shadow', 'normals', 'overdraw', 'shaderCost', 'off'];
|
|
22
22
|
const EXPLAIN = {
|
|
@@ -45,7 +45,7 @@ function costColors(e) {
|
|
|
45
45
|
* scene.environment off inside each render of the scene only (the shadow view): an environment map lights the override's standard material from
|
|
46
46
|
* every side, which lifted the shadows the view shows black (both renderers read it per render: WebGL per material program, WebGPU per render object).
|
|
47
47
|
* Why around each render and not scene.environment = null for the view's lifetime: scene.environment is an owned property (the sky's env row,
|
|
48
|
-
* core/owned.js); a write that lasts across frames reads as the game taking it over. Between renders the scene keeps its real map, so nothing
|
|
48
|
+
* core/ops/owned.js); a write that lasts across frames reads as the game taking it over. Between renders the scene keeps its real map, so nothing
|
|
49
49
|
* is recorded and nothing needs restoring but the two hooks. Returns the undo (puts the scene's own hooks back exactly: an own property or the prototype's).
|
|
50
50
|
* @param {any} scene @returns {() => void}
|
|
51
51
|
*/
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
// describe().picture: what three.js holds right now, read straight off the renderer and the scene. No record, no layers: whoever wrote a value
|
|
2
|
-
// (the game's picture code, a module, a console line), this is the value the frame is drawn with. .writers says which line wrote it (core/pictureWriters.js).
|
|
2
|
+
// (the game's picture code, a module, a console line), this is the value the frame is drawn with. .writers says which line wrote it (core/inspect/pictureWriters.js).
|
|
3
3
|
// describe().render: renderer, post, lights and probes. Facts read from three.js and the post chain.
|
|
4
4
|
// This is information only: the engine never warns when a game changes the renderer or lights.
|
|
5
5
|
import { NoToneMapping, LinearToneMapping, ReinhardToneMapping, CineonToneMapping, ACESFilmicToneMapping, CustomToneMapping, AgXToneMapping, NeutralToneMapping } from 'three';
|
|
6
|
-
import { SHADOW_TYPES } from '
|
|
7
|
-
import { rv } from '
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
6
|
+
import { SHADOW_TYPES } from '../../render/shadowTypes.js';
|
|
7
|
+
import { rv } from '../base/math.js';
|
|
8
|
+
import { hex } from './MaterialInfo.js';
|
|
9
|
+
import { defineOwned } from '../ops/owned.js';
|
|
10
|
+
import { slotHolders } from '../scene/pictureSlots.js';
|
|
11
|
+
import { isShown } from '../base/util.js';
|
|
12
|
+
import { backendFacts } from '../../render/backend.js';
|
|
11
13
|
|
|
12
14
|
const shadowName = v => Object.keys(SHADOW_TYPES).find(k => SHADOW_TYPES[k].three === v) ?? String(v);
|
|
13
15
|
const TONE_NAMES = { [NoToneMapping]: 'none', [LinearToneMapping]: 'linear', [ReinhardToneMapping]: 'reinhard', [CineonToneMapping]: 'cineon',
|
|
14
16
|
[ACESFilmicToneMapping]: 'aces', [CustomToneMapping]: 'custom', [AgXToneMapping]: 'agx', [NeutralToneMapping]: 'neutral' };
|
|
15
17
|
const toneName = v => TONE_NAMES[v] ?? String(v);
|
|
16
|
-
|
|
17
|
-
/** What a build without the dev server says for every picture value (core/pictureWriters.js stays out of it) */
|
|
18
|
+
/** What a build without the dev server says for every picture value (core/inspect/pictureWriters.js stays out of it) */
|
|
18
19
|
export const NO_WRITERS = 'not tracked: source lines are only known on the dev server (threedog dev or npm run dev); a bundled build has no file:line to give';
|
|
19
20
|
|
|
20
21
|
/** scene.fog as data @param {any} f */
|
|
@@ -26,11 +27,7 @@ function backgroundOf(s) {
|
|
|
26
27
|
return b.isColor ? { type: 'Color', color: hex(b) } : { type: b.isCubeTexture ? 'CubeTexture' : 'Texture', name: b.name || null, intensity: s.backgroundIntensity };
|
|
27
28
|
}
|
|
28
29
|
/** Whether three draws with this light: every parent visible and on a layer the camera sees (the test three's renderer makes) */
|
|
29
|
-
|
|
30
|
-
if (!o.layers.test(cam.layers)) return false;
|
|
31
|
-
for (let p = o; p; p = p.parent) if (!p.visible) return false;
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
30
|
+
const lit = (o, cam) => o.layers.test(cam.layers) && isShown(o);
|
|
34
31
|
const lightOf = (l, cam) => ({ type: l.type, name: l.name, color: hex(l.color), ...(l.groundColor ? { groundColor: hex(l.groundColor) } : {}), intensity: l.intensity, castShadow: !!l.castShadow, visible: lit(l, cam) });
|
|
35
32
|
|
|
36
33
|
/**
|
|
@@ -51,7 +48,7 @@ export function describePicture(e) {
|
|
|
51
48
|
* @param {{ owned: boolean }} o owned: false when the game passed its own renderer
|
|
52
49
|
*/
|
|
53
50
|
export function recordRender(e, { owned }) {
|
|
54
|
-
// who writes tone mapping now is one owned record like every other picture value (core/owned.js),
|
|
51
|
+
// who writes tone mapping now is one owned record like every other picture value (core/ops/owned.js),
|
|
55
52
|
// not a comparison against a remembered creation value here: a direct renderer.toneMapping write yields it ('three (engine yielded)'), quietly (once),
|
|
56
53
|
// because that write is the documented way to change the curve. A game-supplied renderer (owned false) starts manual: the engine never wrote it
|
|
57
54
|
e._oTone = defineOwned(e, { id: 'toneMapping', part: 'tone', key: 'toneMapping', read: () => e.renderer.toneMapping, objects: [e.renderer], once: true,
|
|
@@ -67,7 +64,7 @@ export function recordRender(e, { owned }) {
|
|
|
67
64
|
*/
|
|
68
65
|
function engineDefaults(e) {
|
|
69
66
|
const r = e.renderer, s = e.scene, bg = s.background, rows = [];
|
|
70
|
-
if (bg && bg === e.baseBackground) rows.push({ what: 'scene.background', value: `#${bg.getHexString()}`, off: 'scene.background = your color or texture' });
|
|
67
|
+
if (bg && bg === e.baseBackground && bg.getHex() === e.baseBackgroundHex) rows.push({ what: 'scene.background', value: `#${bg.getHexString()}`, off: 'scene.background = your color or texture' });
|
|
71
68
|
for (const [name, l] of Object.entries(e.lights ?? {})) if (l.parent) rows.push({ what: `lights.${name}`, value: `${l.type} ${rv(l.intensity)}`, off: 'createEngine({ lights: false })' });
|
|
72
69
|
if (r.shadowMap.enabled) rows.push({ what: 'renderer.shadowMap', value: shadowName(r.shadowMap.type), off: 'renderer.shadowMap.enabled = false' });
|
|
73
70
|
// render/postWebGL.js direct(): only once the game has picked a tone curve, so a Color background agrees with the effect chain's OutputPass
|
|
@@ -89,12 +86,12 @@ export function describeRender(e) {
|
|
|
89
86
|
const tone = toneFx ? { value: `post effect '${toneFx.name}' (tone slot)`, ...postWho(toneFx.name) }
|
|
90
87
|
: { value: toneName(r.toneMapping), writer: e._oTone.on ? 'three default' : 'game' };
|
|
91
88
|
const exposure = { value: rv(r.toneMappingExposure) };
|
|
92
|
-
const shadows = { enabled: r.shadowMap.enabled, type: shadowName(r.shadowMap.type) };
|
|
89
|
+
const shadows = { enabled: r.shadowMap.enabled, type: shadowName(r.shadowMap.type) };
|
|
93
90
|
const post = (e.post?._list || []).map(h => { const held = e.post._held(h), facts = h._def.facts?.();
|
|
94
91
|
return { name: h.name, on: h.enabled, params: { ...h.params }, ...postWho(h.name), ...(held ? { held } : {}), ...(facts ? { facts } : {}) }; });
|
|
95
92
|
const lights = Object.entries(e.lights || {}).filter(([, l]) => l.parent)
|
|
96
93
|
.map(([name, l]) => ({ name, type: l.type, intensity: rv(l.intensity), source: 'engine-default' }));
|
|
97
|
-
// the game's own point / spot lights (core/gameLights.js): adopted like a lightPool light, listed with the line that added them
|
|
94
|
+
// the game's own point / spot lights (core/scene/gameLights.js): adopted like a lightPool light, listed with the line that added them
|
|
98
95
|
for (const l of e._gameLights?.list() ?? []) lights.push({ name: l.name || l.type, type: l.type, intensity: rv(l.intensity), castShadow: l.castShadow,
|
|
99
96
|
source: 'game', writer: 'game', at: e._things?.entryOf(l)?.[0]?.at ?? null, ...(e._gameLights.idled(l) ? { shadowIdled: true } : {}) });
|
|
100
97
|
const defaults = engineDefaults(e);
|
|
@@ -103,7 +100,7 @@ const shadows = { enabled: r.shadowMap.enabled, type: shadowName(r.shadowMap.typ
|
|
|
103
100
|
const kv = x => Object.entries(x).map(([k, v]) => `${k}=${typeof v === 'number' ? rv(v) : v}`).join(' ');
|
|
104
101
|
const srgb = r.outputColorSpace === 'srgb' ? '' : ' (WRONG: colors are encoded for srgb; color textures must be srgb, data maps linear, see assets.report)';
|
|
105
102
|
let text = [
|
|
106
|
-
`renderer: ${tone.value}${by(tone)} exposure ${exposure.value}
|
|
103
|
+
`renderer: ${tone.value}${by(tone)} exposure ${exposure.value} shadows ${shadows.enabled ? shadows.type : 'off'}${b.owned ? '' : ' [game-supplied renderer]'} output ${r.outputColorSpace}${srgb}`,
|
|
107
104
|
`post: ${post.map(x => `${x.name}${x.held ? ` held off: ${x.held}` : x.on ? '' : ' off'}${Object.keys(x.params).length ? `{${kv(x.params)}}` : ''} (${x.writer})`).join(', ') || 'none'}${antialias.samples ? ` + MSAA x${antialias.samples}` : antialias.replacedBy ? ` + ${antialias.replacedBy} in place of MSAA` : ''}`,
|
|
108
105
|
`lights: ${lights.map(l => `${l.name} ${l.type} ${l.intensity}${l.writer ? ` (${l.writer}${l.at ? ' ' + l.at : ''})` : ''}`).join(', ')}`,
|
|
109
106
|
`scene: background ${sceneWord(backgroundOf(e.scene))} fog ${sceneWord(fogOf(e.scene.fog))} environment ${e.scene.environment ? rv(e.scene.environmentIntensity) : 'none'}`,
|
|
@@ -133,11 +130,15 @@ render scale: ${scale.current} of device pixel ratio ${dpr}${scale.upscaled ? '
|
|
|
133
130
|
// occlusion culling (render/occlusion.js): what it skipped this frame, so a game can see whether it pays
|
|
134
131
|
const occlusion = e.occlusion?.enabled ? e.occlusion.stats : null;
|
|
135
132
|
if (occlusion) text += `\nocclusion: ${occlusion.hidden} of ${occlusion.watched} big things hidden, ${occlusion.trianglesSkipped} triangles skipped`;
|
|
136
|
-
|
|
133
|
+
// three's BundleGroup in the game's scene: it replays what was recorded, so an AI reading the state must know a child's visible is not what draws. A walk: describe is not per frame
|
|
134
|
+
let bundles = null;
|
|
135
|
+
e.scene.traverse(o => { if (o.isBundleGroup) { bundles ??= { groups: 0, meshes: 0, replayed: !!r.backend?.beginBundle }; bundles.groups++; o.traverse(c => { if (c.isMesh) bundles.meshes++; }); } });
|
|
136
|
+
if (bundles) text += `\nrender bundles: ${bundles.groups} BundleGroup(s), ${bundles.meshes} mesh(es), ${bundles.replayed ? 'replayed as recorded: after changing what is inside, set group.needsUpdate = true' : 'plain groups on this backend, no gain (only WebGPU has bundles)'}`;
|
|
137
|
+
return { debugView: dv, scale, toneMapping: tone, exposure, shadows, post, antialias, lights, defaults, probes, lightmap, occlusion, bundles, text };
|
|
137
138
|
}
|
|
138
139
|
|
|
139
140
|
/**
|
|
140
|
-
* Which renderer was asked for and which backend draws; reason = why not WebGPU (core/startup.js _startRenderer); the rest is what that backend can run.
|
|
141
|
+
* Which renderer was asked for and which backend draws; reason = why not WebGPU (core/engine/startup.js _startRenderer); the rest is what that backend can run.
|
|
141
142
|
* All null before start(): the facts need the started backend.
|
|
142
143
|
* @param {any} e
|
|
143
144
|
*/
|