threedog 0.2.1 → 0.7.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 +371 -1
- package/README.md +21 -12
- package/core/Animator.js +15 -12
- package/core/Assets.js +92 -26
- package/core/Audio.js +45 -38
- package/core/Baked.js +30 -15
- package/core/Batching.js +102 -15
- package/core/Budget.js +40 -19
- package/core/Clock.js +40 -80
- package/core/DebugOverrides.js +75 -25
- package/core/Describe.js +105 -45
- package/core/Engine.js +203 -75
- package/core/Events.js +4 -1
- package/core/I18n.js +25 -13
- package/core/Input.js +175 -80
- package/core/Inspect.js +8 -5
- package/core/InspectMaterials.js +84 -0
- package/core/InspectPerf.js +68 -0
- package/core/InspectScene.js +13 -2
- package/core/Loading.js +2 -1
- package/core/MaterialInfo.js +7 -5
- package/core/Ops.js +50 -9
- package/core/Random.js +9 -2
- package/core/Rays.js +12 -7
- package/core/SaveStore.js +41 -9
- package/core/Saves.js +71 -15
- package/core/Stream.js +13 -10
- package/core/Threads.js +26 -7
- package/core/UrlState.js +69 -13
- package/core/Views.js +10 -6
- package/core/actor.js +1 -1
- package/core/adaptive.js +93 -0
- package/core/assetEntry.js +27 -7
- package/core/assetHot.js +176 -0
- package/core/assetLoad.js +44 -19
- package/core/assetManifest.js +53 -11
- package/core/assetReport.js +5 -5
- package/core/audioRules.js +13 -11
- package/core/audioVoice.js +69 -42
- package/core/batchGroups.js +9 -1
- package/core/canvasBox.js +1 -2
- package/core/catalog.js +21 -5
- package/core/cells.js +62 -0
- package/core/checks.js +10 -8
- package/core/chunkStream.js +87 -0
- package/core/control.js +149 -0
- package/core/copies.js +32 -0
- package/core/dayTime.js +12 -6
- package/core/debugView.js +85 -18
- package/core/describeRender.js +117 -21
- package/core/describeText.js +41 -21
- package/core/engineCamera.js +32 -0
- package/core/errorCodes.js +478 -32
- package/core/errorHints.js +41 -142
- package/core/errors.js +31 -8
- package/core/events.generated.js +13 -7
- package/core/gameLights.js +69 -0
- package/core/grayMap.js +20 -0
- package/core/grid.js +14 -13
- package/core/gridLoad.js +2 -1
- package/core/ground.js +6 -4
- package/core/headlessLoad.js +55 -0
- package/core/holds.js +78 -50
- package/core/inputContext.js +11 -7
- package/core/inputDefaults.js +24 -21
- package/core/inputPad.js +1 -1
- package/core/inputPointer.js +1 -1
- package/core/inputTouch.js +2 -2
- package/core/lifecycle.js +46 -12
- package/core/lightWatch.js +9 -5
- package/core/loop.js +109 -43
- package/core/math.js +18 -3
- package/core/moduleSlots.js +100 -0
- package/core/moduleTypes.js +86 -0
- package/core/modules.js +147 -29
- package/core/movement.js +2 -2
- package/core/namedModel.js +74 -0
- package/core/opsCheck.js +3 -3
- package/core/opsFail.js +15 -6
- package/core/opsGuard.js +4 -4
- package/core/opsRun.js +4 -3
- package/core/owned.js +171 -0
- package/core/page.js +44 -10
- package/core/params.js +30 -8
- package/core/pictureSlots.js +33 -0
- package/core/pictureWriters.js +343 -0
- package/core/plugins.js +245 -0
- package/core/saveApply.js +99 -17
- package/core/saveFiles.js +8 -6
- package/core/saveValues.js +46 -0
- package/core/saveVersions.js +20 -3
- package/core/scatter.js +48 -19
- package/core/sceneDelta.js +211 -0
- package/core/sceneMethods.js +31 -33
- package/core/screenToGround.js +1 -1
- package/core/services.js +27 -11
- package/core/session.js +28 -25
- package/core/shaderCost.js +78 -0
- package/core/shadowTypes.js +3 -2
- package/core/shadows.js +405 -0
- package/core/sharedPoint.js +303 -0
- package/core/skip.js +36 -28
- package/core/stackFrames.js +45 -0
- package/core/stacks.js +166 -0
- package/core/startup.js +153 -13
- package/core/streamSources.js +0 -11
- package/core/targeting.js +1 -1
- package/core/textureBytes.js +20 -0
- package/core/thingExplain.js +3 -3
- package/core/thingOps.js +29 -6
- package/core/things.js +22 -12
- package/core/threadPure.js +7 -3
- package/core/threePatches.js +47 -0
- package/core/tier.js +21 -10
- package/core/time.js +236 -0
- package/core/uiClock.js +25 -0
- package/core/util.js +8 -2
- package/core/validate.js +66 -87
- package/core/view.js +43 -0
- package/core/wrap.js +106 -0
- package/docs/AI.md +95 -104
- package/docs/API.md +35 -31
- package/docs/CODEMAP.md +231 -176
- package/docs/COMMANDS.md +63 -39
- package/docs/CONVENTIONS.md +99 -31
- package/docs/MIGRATING-0.3.md +248 -0
- package/docs/MIGRATING-0.4.md +320 -0
- package/docs/MIGRATING-0.5.md +68 -0
- package/docs/MIGRATING-0.6.md +126 -0
- package/docs/MIGRATING-0.7.md +39 -0
- package/docs/PERF.md +35 -7
- package/docs/THREE.md +82 -28
- package/docs/api/ambience.md +0 -1
- package/docs/api/assets.md +15 -11
- package/docs/api/audio.md +10 -14
- package/docs/api/budget.md +4 -0
- package/docs/api/calendar.md +41 -0
- package/docs/api/cameraRig.md +16 -5
- package/docs/api/characters.md +41 -24
- package/docs/api/clock.md +6 -5
- package/docs/api/collision.md +10 -7
- package/docs/api/content.md +6 -4
- package/docs/api/dialogue.md +9 -9
- package/docs/api/engine.md +95 -65
- package/docs/api/events.md +20 -14
- package/docs/api/grids.md +10 -3
- package/docs/api/ground.md +1 -1
- package/docs/api/hud.md +5 -2
- package/docs/api/i18n.md +1 -1
- package/docs/api/input.md +13 -7
- package/docs/api/interactions.md +10 -6
- package/docs/api/inventory.md +17 -17
- package/docs/api/level.md +0 -2
- package/docs/api/lightPool.md +3 -1
- package/docs/api/music.md +1 -1
- package/docs/api/nav.md +3 -0
- package/docs/api/occlusion.md +5 -0
- package/docs/api/openWorld.md +2 -1
- package/docs/api/particles.md +6 -3
- package/docs/api/photo.md +0 -2
- package/docs/api/pickups.md +21 -0
- package/docs/api/post.md +8 -5
- package/docs/api/quests.md +2 -3
- package/docs/api/rigid.md +16 -14
- package/docs/api/saves.md +6 -4
- package/docs/api/settings.md +2 -3
- package/docs/api/sky.md +18 -49
- package/docs/api/stream.md +1 -1
- package/docs/api/terrain.md +16 -7
- package/docs/api/terrainDraw.md +12 -0
- package/docs/api/timeline.md +3 -4
- package/docs/api/tools.md +32 -15
- package/docs/api/triggers.md +7 -10
- package/docs/api/vegetation.md +17 -9
- package/docs/api/vegetationDraw.md +10 -0
- package/docs/api/water.md +9 -21
- package/docs/api/weather.md +10 -15
- package/docs/api/weatherDraw.md +10 -0
- package/docs/api/world.md +3 -2
- package/docs/recipes/01-new-game.md +52 -42
- package/docs/recipes/02-npc.md +24 -7
- package/docs/recipes/03-items-pickups.md +57 -22
- package/docs/recipes/04-quests.md +12 -5
- package/docs/recipes/05-props-bake.md +174 -22
- package/docs/recipes/06-clock-events.md +100 -52
- package/docs/recipes/07-flow-scenes-pause.md +50 -10
- package/docs/recipes/08-weather-sky.md +134 -37
- package/docs/recipes/09-materials-lights-models.md +185 -0
- package/docs/recipes/10-blender-level.md +16 -4
- package/docs/recipes/11-vehicles.md +67 -10
- package/docs/recipes/13-animation.md +23 -9
- package/docs/recipes/14-custom-module.md +63 -29
- package/docs/recipes/15-perf.md +31 -10
- package/docs/recipes/16-dev-bridge.md +74 -40
- package/docs/recipes/18-world.md +26 -14
- package/docs/recipes/19-shooting-picking.md +12 -10
- package/docs/recipes/20-content-actions-save.md +60 -18
- package/docs/recipes/21-camera.md +55 -17
- package/docs/recipes/22-shop-gold.md +3 -3
- package/docs/recipes/23-ops.md +17 -11
- package/docs/recipes/26-ui-parts.md +86 -13
- package/docs/recipes/27-net.md +11 -5
- package/docs/recipes/28-terrain.md +36 -3
- package/docs/recipes/29-grid.md +46 -19
- package/docs/recipes/30-templates.md +72 -15
- package/docs/recipes/31-audio.md +20 -12
- package/docs/recipes/32-action-game.md +51 -4
- package/docs/recipes/34-environment-lighting.md +108 -21
- package/docs/recipes/35-picture-from-reference.md +147 -0
- package/docs/recipes/36-sky-ground-plants.md +158 -0
- package/docs/recipes/{37-terrain-look-hooks.md → 37-terrain-hooks.md} +9 -12
- package/docs/recipes/38-environment-hooks.md +67 -0
- package/docs/recipes/40-scene.md +114 -32
- package/docs/recipes/42-terrain-shape.md +2 -2
- package/docs/recipes/43-shader-patches-surfaces.md +206 -0
- package/docs/recipes/44-water-weather-hooks.md +191 -0
- package/docs/recipes/45-cascaded-shadows.md +130 -23
- package/docs/recipes/46-blender-art-route.md +17 -20
- package/docs/recipes/47-island-snow-backdrop.md +13 -15
- package/docs/recipes/49-game-module-contract.md +30 -17
- package/docs/recipes/50-own-renderer.md +4 -4
- package/docs/recipes/51-capability-catalog.md +3 -3
- package/docs/recipes/52-around-the-picture.md +181 -0
- package/docs/recipes/53-ground-up-close.md +12 -12
- package/docs/recipes/54-three-idioms.md +88 -0
- package/docs/recipes/55-mods-time-wrap.md +124 -0
- package/docs/recipes/56-webgpu-tsl.md +303 -0
- package/docs/recipes/57-control.md +104 -0
- package/docs/recipes/58-input.md +60 -0
- package/docs/recipes/59-depth-post-effects.md +83 -0
- package/docs/recipes/60-judge-the-picture.md +70 -0
- package/docs/recipes/61-deploy.md +27 -0
- package/docs/recipes/62-picture-code.md +244 -0
- package/docs/recipes/63-third-person-start.md +77 -0
- package/docs/recipes/64-particles.md +35 -0
- package/examples/action/.threedog/content-index.json +1 -0
- package/examples/action/GAMEMAP.md +20 -14
- package/examples/action/assets.js +8 -0
- package/examples/action/content/actions.js +1 -1
- package/examples/action/content/audio.js +5 -5
- package/examples/action/main.js +12 -15
- package/examples/action/models.js +23 -24
- 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/plain-picture/.threedog/content-index.json +1 -0
- package/examples/plain-picture/FINDINGS.md +53 -0
- package/examples/plain-picture/GAMEMAP.md +90 -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 +133 -0
- package/examples/rc2d/.threedog/content-index.json +1 -0
- package/examples/rc2d/GAMEMAP.md +88 -0
- package/examples/rc2d/README.md +57 -0
- package/examples/rc2d/main.js +55 -0
- 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 +187 -0
- package/examples/rc2d/shaders.js +144 -0
- package/examples/sheepisland/.threedog/content-index.json +1 -0
- package/examples/sheepisland/GAMEMAP.md +22 -17
- package/examples/sheepisland/assets.js +5 -0
- package/examples/sheepisland/content/templates.js +1 -1
- package/examples/sheepisland/content/vegetation.js +3 -1
- package/examples/sheepisland/main.js +29 -18
- package/examples/sheepisland/{style/models.js → models.js} +13 -24
- package/examples/sheepisland/picture/index.js +20 -0
- package/examples/sheepisland/picture/lights.js +34 -0
- package/examples/sheepisland/picture/materials.js +61 -0
- package/examples/sheepisland/picture/palette.js +60 -0
- package/examples/sheepisland/picture/sky.js +20 -0
- package/examples/sheepisland/views.js +1 -1
- package/examples/styletest/.threedog/content-index.json +1 -0
- package/examples/styletest/GAMEMAP.md +25 -22
- package/examples/styletest/assets.js +6 -0
- package/examples/styletest/content/templates.js +1 -1
- package/examples/styletest/content/vegetation.js +1 -1
- package/examples/styletest/main.js +25 -34
- package/examples/styletest/models.js +30 -30
- package/examples/styletest/params.js +2 -5
- 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 +91 -0
- package/examples/techniques/contact-shadows/contactShadows.js +67 -0
- package/examples/techniques/contact-shadows/main.js +55 -0
- 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 +83 -0
- package/examples/techniques/day-night-grade/main.js +41 -0
- 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 +106 -0
- package/examples/techniques/interior-light/interiorLight.js +47 -0
- package/examples/techniques/interior-light/main.js +87 -0
- 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 +126 -0
- package/examples/techniques/modular-building/kit.js +426 -0
- package/examples/techniques/modular-building/main.js +39 -0
- 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 +95 -0
- package/examples/techniques/night-lights/main.js +47 -0
- package/examples/techniques/night-lights/nightLights.js +95 -0
- 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 +59 -0
- package/examples/techniques/outlines-and-rim/main.js +61 -0
- package/examples/techniques/outlines-and-rim/outlines.js +64 -0
- 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 +79 -0
- package/examples/techniques/procedural-animation/creature.js +44 -0
- package/examples/techniques/procedural-animation/main.js +47 -0
- 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 +118 -0
- package/examples/techniques/procedural-surface/README.md +69 -0
- package/examples/techniques/procedural-surface/main.js +65 -0
- 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/procedural-surface/surface.js +120 -0
- package/examples/techniques/stylized-shading/README.md +74 -0
- package/examples/techniques/stylized-shading/main.js +62 -0
- 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 +131 -0
- package/examples/techniques/sun-and-key-light/README.md +133 -0
- package/examples/techniques/sun-and-key-light/keyLight.js +71 -0
- package/examples/techniques/sun-and-key-light/main.js +51 -0
- 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 +102 -0
- package/examples/techniques/wet-road/main.js +48 -0
- 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/techniques/wet-road/wetRoad.js +209 -0
- package/examples/webgpu-tsl/.threedog/content-index.json +1 -0
- package/examples/webgpu-tsl/GAMEMAP.md +89 -0
- package/examples/webgpu-tsl/README.md +45 -0
- package/examples/webgpu-tsl/main.js +44 -0
- 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 -0
- package/examples/world/GAMEMAP.md +31 -21
- package/examples/world/art/humanoid.js +38 -0
- package/examples/world/art/index.js +11 -0
- package/examples/world/art/models.js +57 -0
- package/examples/world/art/shapes.js +9 -0
- package/examples/world/assets.js +6 -0
- package/examples/world/content/audio.js +5 -5
- package/examples/world/content/items.js +1 -1
- package/examples/world/content/npcs.js +1 -1
- package/examples/world/content/props.js +1 -1
- package/examples/world/content/rules.js +1 -1
- package/examples/world/content/templates.js +1 -1
- package/examples/world/content/vegetation.js +1 -1
- package/examples/world/main.js +22 -18
- 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 +44 -54
- package/index.js +29 -25
- package/llms.txt +24 -15
- package/modules/ambience/Ambience.js +34 -23
- package/modules/calendar/Calendar.js +163 -0
- package/modules/calendar/contract.js +21 -0
- package/modules/calendar/index.js +82 -0
- package/modules/{sky → calendar}/schedule.js +17 -16
- package/modules/calendar/seasons.js +55 -0
- package/modules/camera/FirstPersonCamera.js +6 -15
- package/modules/camera/FixedCamera.js +33 -15
- package/modules/camera/FollowCamera.js +90 -16
- package/modules/camera/RtsCamera.js +18 -17
- package/modules/camera/common.js +73 -20
- package/modules/camera/contract.js +17 -0
- package/modules/camera/projection.js +11 -24
- package/modules/characters/Character.js +188 -48
- package/modules/characters/NPC.js +92 -41
- package/modules/characters/assetModel.js +8 -16
- package/modules/characters/behaviors.js +2 -1
- package/modules/characters/contract.js +13 -0
- package/modules/characters/footsteps.js +1 -1
- package/modules/characters/index.js +112 -49
- package/modules/characters/moveHelpers.js +4 -5
- package/modules/characters/movers/common.js +102 -19
- package/modules/characters/movers/manual.js +23 -0
- package/modules/characters/movers/rapier.js +19 -16
- package/modules/characters/movers/simple.js +14 -11
- package/modules/characters/movers/support.js +186 -0
- package/modules/characters/npcAvoid.js +47 -42
- package/modules/characters/npcSim.js +17 -9
- package/modules/characters/npcView.js +44 -16
- package/modules/characters/pathAsync.js +7 -3
- package/modules/characters/playerStrings.js +4 -3
- package/modules/characters/proceduralRig.js +19 -4
- package/modules/characters/useModel.js +2 -2
- package/modules/characters/vehicle.contract.js +21 -0
- package/modules/characters/walkTo.js +21 -7
- package/modules/collision/Collision.js +69 -27
- package/modules/collision/grid.js +8 -6
- package/modules/content/explain.js +2 -2
- package/modules/content/fields.js +102 -0
- package/modules/content/ids.js +8 -6
- package/modules/content/index.js +104 -27
- package/modules/content/loader.js +45 -33
- package/modules/content/models.js +58 -42
- package/modules/content/packs.js +6 -5
- package/modules/content/parts.js +41 -0
- package/modules/content/props.js +20 -11
- package/modules/content/rules.js +66 -0
- package/modules/content/stages.js +80 -0
- package/modules/content/templates.js +123 -30
- package/modules/debug/DebugPanel.js +24 -17
- package/modules/flow/contract.js +16 -0
- package/modules/flow/index.js +21 -15
- package/modules/gameplay/Container.js +41 -32
- package/modules/gameplay/Containers.js +30 -15
- package/modules/gameplay/Dialogue.js +113 -55
- package/modules/gameplay/Interactions.js +273 -72
- package/modules/gameplay/Inventory.js +72 -76
- package/modules/gameplay/Quests.js +75 -39
- package/modules/gameplay/boxOps.js +3 -3
- package/modules/gameplay/dialogue.contract.js +21 -0
- package/modules/gameplay/dialogueBox.js +4 -2
- package/modules/gameplay/dialogueBubbles.js +116 -0
- package/modules/gameplay/interactionPrompt.js +4 -1
- package/modules/gameplay/interactions.contract.js +16 -0
- package/modules/gameplay/inventory.contract.js +23 -0
- package/modules/gameplay/inventoryOps.js +19 -17
- package/modules/gameplay/pickups.js +306 -85
- package/modules/gameplay/questLog.js +6 -6
- package/modules/gameplay/quests.contract.js +17 -0
- package/modules/grid/Grid.js +92 -50
- package/modules/grid/Layer.js +27 -13
- package/modules/grid/index.js +96 -43
- package/modules/grid/ops.js +20 -18
- package/modules/grid/preview.js +37 -29
- package/modules/grid/strings.js +12 -0
- package/modules/grid/tiles.js +19 -22
- package/modules/hlod/index.js +52 -19
- package/modules/hud/index.js +48 -20
- package/modules/hud/parts.js +28 -13
- package/modules/level/heightfield.js +3 -1
- package/modules/level/index.js +49 -23
- package/modules/level/nodes.js +4 -3
- package/modules/lights/index.js +47 -19
- package/modules/music/Music.js +38 -21
- package/modules/music/rules.js +1 -1
- package/modules/nav/index.js +48 -42
- package/modules/net/Client.js +13 -6
- package/modules/net/Host.js +19 -5
- package/modules/net/Net.js +2 -1
- package/modules/net/index.js +13 -8
- package/modules/net/sync.js +9 -8
- package/modules/net/transports.js +77 -27
- package/modules/particles/Particles.js +58 -28
- package/modules/particles/contract.js +17 -0
- package/modules/particles/effect.js +54 -11
- package/modules/photo/Photo.js +56 -38
- package/modules/rigid/RigidBodies.js +194 -32
- package/modules/rigid/Vehicles.js +18 -15
- package/modules/rigid/sync.js +62 -17
- package/modules/settings/Settings.js +60 -55
- package/modules/settings/apply.js +38 -3
- package/modules/settings/sections.js +5 -3
- package/modules/settings/strings.js +3 -2
- package/modules/settings/view.js +5 -3
- package/modules/sky/Sky.js +132 -205
- package/modules/sky/clouds.js +37 -23
- package/modules/sky/dome.js +100 -0
- package/modules/sky/domeLayers.js +30 -15
- package/modules/sky/environment.js +45 -99
- package/modules/sky/fog.js +9 -139
- package/modules/sky/frame.js +60 -56
- package/modules/sky/season.js +21 -0
- package/modules/sky/shader.js +63 -35
- package/modules/sky/skyModule.js +52 -37
- package/modules/sky/tint.js +59 -0
- package/modules/terrain/ChunkManager.js +194 -110
- package/modules/terrain/chunkJob.js +1 -1
- package/modules/terrain/chunkQueries.js +6 -4
- package/modules/terrain/draw.js +154 -0
- package/modules/terrain/index.js +87 -54
- package/modules/terrain/terrainDefaults.js +2 -2
- package/modules/terrain/terrainEdit.js +18 -20
- package/modules/terrain/terrainGen.js +6 -4
- package/modules/terrain/terrainIsland.js +5 -4
- package/modules/terrain/terrainShape.js +12 -12
- package/modules/terrain/terrainShapeMain.js +8 -7
- package/modules/terrain/terrainTexture.js +21 -19
- package/modules/timeline/Timeline.js +95 -43
- package/modules/timeline/Tween.js +18 -10
- package/modules/timeline/letterbox.js +2 -2
- package/modules/timeline/shots.js +5 -1
- package/modules/triggers/index.js +111 -76
- package/modules/vegetation/Vegetation.js +229 -112
- package/modules/vegetation/densityMap.js +62 -0
- package/modules/vegetation/draw.js +191 -0
- package/modules/vegetation/groundChunks.js +52 -58
- package/modules/vegetation/index.js +32 -11
- package/modules/vegetation/modelGeometry.js +3 -2
- package/modules/vegetation/nearFade.js +8 -2
- package/modules/water/Water.js +157 -72
- package/modules/water/surface.js +86 -47
- package/modules/weather/Weather.js +96 -103
- package/modules/weather/particles.js +37 -14
- package/modules/weather/shaders.js +1 -1
- package/modules/weather/strings.js +2 -2
- package/modules/weather/weatherDraw.js +141 -0
- package/modules/world/World.js +26 -9
- package/modules/world/explain.js +1 -1
- package/modules/world/index.js +18 -4
- package/modules/world/persist.js +62 -2
- package/modules/world/pos.js +3 -2
- package/modules/world/records.js +8 -6
- package/modules/world/sim.js +60 -20
- package/modules/world/simFar.js +4 -3
- package/modules/world/state.js +3 -2
- package/modules/world/thingSource.js +1 -1
- package/modules/world/views.js +8 -6
- package/package.json +8 -3
- package/presets.js +43 -29
- package/render/PostFX.js +318 -135
- package/render/backend.js +486 -0
- package/render/cascades.js +195 -0
- package/render/cascades.tsl.js +96 -0
- package/render/daylight.js +39 -0
- package/render/detail.js +122 -41
- package/render/effects.js +155 -48
- package/render/engineUniforms.js +10 -1
- package/render/fuse.js +5 -4
- package/render/fx/cel.tsl.js +42 -0
- package/render/fx/cloudShadow.tsl.js +16 -0
- package/render/fx/detail.tsl.js +66 -0
- package/render/fx/index.js +28 -0
- package/render/fx/lighting.tsl.js +28 -0
- package/render/fx/nodeErrors.tsl.js +68 -0
- package/render/fx/noise.tsl.js +12 -0
- package/render/fx/objectOrigin.tsl.js +42 -0
- package/render/fx/particles.tsl.js +139 -0
- package/render/fx/patchNodes.tsl.js +403 -0
- package/render/fx/postWebGPU.tsl.js +181 -0
- package/render/fx/season.tsl.js +13 -0
- package/render/fx/sky.tsl.js +187 -0
- package/render/fx/uniforms.tsl.js +67 -0
- package/render/fx/water.tsl.js +53 -0
- package/render/fx/wind.tsl.js +22 -0
- package/render/fxNumbers.js +36 -0
- package/render/hotGlsl.js +24 -0
- package/render/layers.js +14 -0
- package/render/lighting.js +71 -18
- package/render/lightmap.js +142 -0
- package/render/lights.js +47 -6
- package/render/materials.js +55 -152
- package/render/modeling.js +73 -0
- package/render/neutral.js +23 -0
- package/render/occlusion.js +184 -0
- package/render/ownFrame.js +76 -0
- package/render/patches.js +317 -35
- package/render/postWebGL.js +205 -0
- package/render/probes.js +288 -0
- package/render/shaderErrors.js +154 -0
- package/render/slots.js +165 -0
- package/render/terms.js +163 -0
- package/render/uniformDecl.js +4 -3
- package/types/common.d.ts +2 -2
- package/types/core.d.ts +757 -346
- package/types/gameplay.d.ts +539 -330
- package/types/generated/core/Audio.d.ts +26 -42
- package/types/generated/core/Batching.d.ts +6 -2
- package/types/generated/core/Budget.d.ts +2 -8
- package/types/generated/core/DebugOverrides.d.ts +58 -9
- package/types/generated/core/I18n.d.ts +2 -2
- package/types/generated/core/Input.d.ts +110 -32
- package/types/generated/core/Ops.d.ts +31 -0
- package/types/generated/core/Random.d.ts +2 -2
- package/types/generated/core/Saves.d.ts +10 -2
- package/types/generated/core/Stream.d.ts +1 -1
- package/types/generated/core/Threads.d.ts +4 -1
- package/types/generated/core/Views.d.ts +0 -1
- package/types/generated/core/audioVoice.d.ts +17 -9
- package/types/generated/core/control.d.ts +55 -0
- package/types/generated/core/page.d.ts +9 -2
- package/types/generated/core/session.d.ts +2 -1
- package/types/generated/modules/ambience/Ambience.d.ts +0 -9
- package/types/generated/modules/calendar/Calendar.d.ts +84 -0
- package/types/generated/modules/calendar/index.d.ts +10 -0
- package/types/generated/modules/debug/DebugPanel.d.ts +2 -2
- package/types/generated/modules/grid/Grid.d.ts +61 -25
- package/types/generated/modules/grid/Layer.d.ts +13 -5
- package/types/generated/modules/grid/index.d.ts +56 -20
- package/types/generated/modules/music/Music.d.ts +5 -3
- package/types/generated/modules/net/index.d.ts +3 -3
- package/types/generated/modules/net/transports.d.ts +12 -3
- package/types/generated/modules/particles/Particles.d.ts +13 -6
- package/types/generated/modules/sky/Sky.d.ts +85 -110
- package/types/generated/modules/sky/skyModule.d.ts +1 -1
- package/types/generated/modules/timeline/Timeline.d.ts +8 -6
- package/types/generated/modules/water/Water.d.ts +50 -3
- package/types/generated/modules/weather/Weather.d.ts +44 -15
- package/types/generated/modules/weather/weatherDraw.d.ts +11 -0
- package/types/generated/modules/world/World.d.ts +20 -5
- package/types/generated/render/PostFX.d.ts +109 -29
- package/types/generated/render/lighting.d.ts +29 -0
- package/types/generated/render/materials.d.ts +31 -50
- package/types/generated/render/modeling.d.ts +30 -0
- package/types/generated/render/occlusion.d.ts +13 -0
- package/types/generated/render/patches.d.ts +16 -2
- package/types/generated/ui/UI.d.ts +6 -3
- package/types/nav.d.ts +6 -0
- package/types/physics.d.ts +140 -45
- package/types/tsl.d.ts +94 -0
- package/types/world.d.ts +489 -122
- package/ui/Focus.js +35 -14
- package/ui/LoadingScreen.js +3 -3
- package/ui/Parts.js +35 -15
- package/ui/UI.js +27 -17
- package/ui/cursor.js +115 -0
- package/ui/defaults.js +15 -11
- package/ui/theme.js +36 -27
- package/ui/touchPart.js +2 -2
- package/core/claims.js +0 -51
- package/core/look/coreParts.js +0 -112
- package/core/look/layers.js +0 -136
- package/core/look/part.js +0 -173
- package/core/look/report.js +0 -79
- package/core/look/write.js +0 -86
- package/core/renamed.js +0 -22
- package/core/styleParts.js +0 -98
- package/docs/api/entities.md +0 -61
- package/docs/api/style.md +0 -134
- package/docs/recipes/09-style-pack.md +0 -169
- package/docs/recipes/35-style-from-reference.md +0 -84
- package/docs/recipes/36-sky-ground-plant-looks.md +0 -118
- package/docs/recipes/38-environment-look-hooks.md +0 -88
- package/docs/recipes/41-thing-registry.md +0 -93
- package/docs/recipes/43-shader-patches-surface-looks.md +0 -135
- package/docs/recipes/44-water-weather-look-hooks.md +0 -135
- package/docs/recipes/48-make-material.md +0 -70
- package/docs/recipes/52-look.md +0 -146
- package/examples/action/look.js +0 -5
- package/examples/sheepisland/style/index.js +0 -79
- package/examples/styletest/look.js +0 -11
- package/examples/styletest/overrides.js +0 -33
- package/examples/styletest/panel.js +0 -135
- package/modules/entities/Entities.js +0 -243
- package/modules/entities/build.js +0 -25
- package/modules/entities/index.js +0 -4
- package/modules/sky/calendar.js +0 -80
- package/modules/sky/cascades.js +0 -125
- package/modules/sky/layers.js +0 -69
- package/modules/sky/look.js +0 -51
- package/modules/sky/lookFog.js +0 -80
- package/modules/sky/lookShadow.js +0 -50
- package/modules/sky/lookSky.js +0 -108
- package/modules/sky/shadow.js +0 -74
- package/modules/terrain/chunkLevels.js +0 -40
- package/modules/terrain/lookGround.js +0 -61
- package/modules/terrain/mountTerrain.js +0 -32
- package/modules/vegetation/lookWind.js +0 -37
- package/modules/water/look.js +0 -80
- package/modules/weather/look.js +0 -75
- package/modules/world/cells.js +0 -42
- package/render/lookSurface.js +0 -161
- package/render/postLook.js +0 -86
- package/render/surface.js +0 -69
- package/types/style.d.ts +0 -643
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
// "Who wrote this picture value": the last file:line that changed a light, the fog, tone, environment, background or a material color, and one warning
|
|
2
|
+
// when two places fight over a value inside one frame. Dev server only (npm run dev, threedog snap): see ON below. It observes; every write goes through.
|
|
3
|
+
//
|
|
4
|
+
// Why accessors and a stack, not per-hook attribution: picture/index.js calls all its parts from one engine.onRender, so "which hook was running" names the
|
|
5
|
+
// wiring file for every value. Only the call stack of the write tells parts apart. Why own accessors on r / g / b and x / y / z: Color and Vector3 are
|
|
6
|
+
// changed in place (fog.color.lerp(...), light.position.copy(...)), so watching light.color alone would see nothing.
|
|
7
|
+
//
|
|
8
|
+
// Why not a stack on every write: a stack costs 10-40 us here, and a picture that moves 100 values would pay milliseconds each frame. So a write that
|
|
9
|
+
// changes nothing is ignored, and a value written every frame is looked at every EVERY frames (staggered). What still gets a stack at once: the first
|
|
10
|
+
// frames, a value that was not written last frame (a one-shot write), and a frame with more writes to a value than its last looked-at frame had (a
|
|
11
|
+
// new writer). So `framesAgo` says how old the answer is, and `writtenSince` says the value moved after that, unseen. An answer is never presented as
|
|
12
|
+
// fresher than it is.
|
|
13
|
+
//
|
|
14
|
+
// Why two places in one function are not a fight: fog.color.copy(a) then fog.color.lerp(b, t) is a value computed in steps. A place is a file plus a
|
|
15
|
+
// function name, plus the part running it. shortcut: outside parts, two anonymous functions or two same-named methods in one file count as one place, so a fight between them goes unwarned;
|
|
16
|
+
// upgrade by comparing function start lines if an agent reports one.
|
|
17
|
+
//
|
|
18
|
+
// Parts (modules, core/pictureSlots.js): a value in a slot a part holds has a declared owner, so a write from anyone else is reported at once, naming the holder and
|
|
19
|
+
// both lines, not only when the two land in one frame (a held value written by a stray in another state would never be a fight). Who wrote it: the module running
|
|
20
|
+
// now (install, its hooks: core/moduleTypes.js ownHook), else any frame in a file that part's code ran from (an event listener, a timer). A file two parts share
|
|
21
|
+
// cannot say which of them it was, so it counts as the holder: a warning that accuses the owner would teach agents to ignore this one.
|
|
22
|
+
// What cannot be seen: a write made before the holder took the slot, and a part added under another object rather than the scene root (see added).
|
|
23
|
+
//
|
|
24
|
+
// Leftovers: three.js objects have no owner, so ctx.track only removes what it was handed. Each root a picture part adds and each post effect is remembered until it
|
|
25
|
+
// leaves; what is still there after the part is gone, and a hook that outlived it, is reported by name. It observes, like the rest: nothing is cleaned up for the part.
|
|
26
|
+
import { warnOnce, fmt } from './validate.js';
|
|
27
|
+
import { coded } from './errorHints.js';
|
|
28
|
+
import { notePatch } from './threePatches.js';
|
|
29
|
+
import { sceneVisitor } from './sceneDelta.js';
|
|
30
|
+
import { onSceneRoot } from './sceneDelta.js';
|
|
31
|
+
import { stackFrames, frameText, callerAt, engineFile } from './stackFrames.js';
|
|
32
|
+
import { slotOfValue, slotHolder } from './pictureSlots.js';
|
|
33
|
+
|
|
34
|
+
const EVERY = 30; // frames between two looks at a value written every frame: a stale answer is at most half a second old
|
|
35
|
+
const DEPTH = 10; // three's own frames above the writer: setter, Color.copy, lerpColors ... always fewer
|
|
36
|
+
const NOT = {
|
|
37
|
+
before: 'not tracked: set before it entered the scene',
|
|
38
|
+
start: 'not tracked: three.js default or set before the engine was made',
|
|
39
|
+
own: 'not tracked: this object defines the property with its own accessor',
|
|
40
|
+
none: 'not tracked: never written since tracking began',
|
|
41
|
+
noFile: 'not tracked: the last write had no source file (console, eval or the picture check)',
|
|
42
|
+
};
|
|
43
|
+
// three.js and pre-bundled libraries are never "the writer": the line that called them is
|
|
44
|
+
const SKIP = /\/deps\/|\/node_modules\/|\/three(?:\.[a-z]+)*\.js$/;
|
|
45
|
+
const SELF = /core\/pictureWriters\.js$/;
|
|
46
|
+
const CORE = /\/(?:core|render)\/[^/]+$/; // with engineFile: core and render write for the engine; modules/ count as parts, they hold slots like any other
|
|
47
|
+
const MATERIALS_MAX = 40; // describe() stays small on a big scene; explain still answers any one of them
|
|
48
|
+
const SHARED_FIX = "make it a shared value: the owner defines it with engine.stacks.define(name, { base: 1 }) and reads it where it writes three.js, the others change it with ctx.mod(name, { mul: 0.5 }); for an amount that moves, take it once, const h = ctx.mod(name, { mul: 1 }), and call h.change(x) each frame (recipes/62-picture-code.md)";
|
|
49
|
+
const STRINGS = {
|
|
50
|
+
conflict: '{value} was written twice in one frame with different results: {first}, then {second}. The later write is what is drawn. Fix, one of: (1) one place keeps the write, delete the other{claim}; (2) if both need a say, ' + SHARED_FIX,
|
|
51
|
+
claim: ", and that part declares it with provides: ['{slot}']",
|
|
52
|
+
held: "{value} is held by part '{holder}' (provides: ['{slot}'], {place}), but {at} ({who}) wrote it too. The later write is what is drawn, so one of them never shows. Fix, one of: (1) delete the write at {at}; " +
|
|
53
|
+
"(2) if that code should own it, give it provides: ['{slot}'] and install it with engine.use(thatPart(), { replaces: '{slot}' }), which unloads '{holder}'; (3) if both need a say, " + SHARED_FIX,
|
|
54
|
+
leftover: "part '{name}' is gone, but what it added is still there: {list}. Fix: in its install, hand each one to ctx.track, e.g. ctx.track({ remove() { e.scene.remove(obj); obj.geometry.dispose(); } }), or undo it in the part's dispose()",
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const page = { off: false, nextId: 0 }; // off: threePatches.off('picture-writers'), page-wide like the list
|
|
58
|
+
|
|
59
|
+
/** The writer of the running write: { at: 'picture/sky.js:12', key } or null when no frame names a source file */
|
|
60
|
+
function writerNow() {
|
|
61
|
+
const E = /** @type {ErrorConstructor & { stackTraceLimit?: number }} */ (Error); // stackTraceLimit is V8's (Chrome), not in the DOM typings
|
|
62
|
+
const lim = E.stackTraceLimit; E.stackTraceLimit = DEPTH;
|
|
63
|
+
const stack = new Error().stack; E.stackTraceLimit = lim;
|
|
64
|
+
const all = stackFrames(stack ?? '').filter(x => !SELF.test(x.file)), i = all.findIndex(x => !SKIP.test(x.file));
|
|
65
|
+
if (i < 0) return null;
|
|
66
|
+
const f = all[i];
|
|
67
|
+
// engine: the engine moved it for its own reasons (a debug view, the renderer fallback): no part's business. A frame skipped above can still be the engine's, in a game that has it in node_modules
|
|
68
|
+
return { at: frameText(f), key: `${f.file}|${f.fn}`, file: f.file, frames: all.slice(i), engine: all.slice(0, i + 1).some(x => CORE.test(x.file) && engineFile(x.file)) };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// name: the value's writers name while it can be in a slot (null: a material); ownBy / ownAt: the holder's last write; last: the slot and whether its holder wrote last
|
|
72
|
+
const newRec = (why, name = null) => ({ id: page.nextId++, at: null, why, seen: 0, wrote: -1, f: -1, n: 0, usual: 0, next: 0, sample: true, placeKey: null, placeAt: null, placeBy: null, fought: false, name, ownBy: null, ownAt: null, last: null });
|
|
73
|
+
const who = name => name ? `part '${name}'` : 'code outside any part';
|
|
74
|
+
|
|
75
|
+
class Writers {
|
|
76
|
+
constructor(e) {
|
|
77
|
+
this.e = e;
|
|
78
|
+
this.frame = 0; // 0 = setup: every write gets a stack and nothing can fight yet (a game's setup overrides engine defaults on purpose)
|
|
79
|
+
this.hooksRan = false;
|
|
80
|
+
this.drawing = false; // during the draw the engine swaps background / tone and puts them back: not a write to the picture
|
|
81
|
+
this.stacks = 0; // stacks taken, the whole cost of this file: read it to judge a slow dev frame
|
|
82
|
+
this.fights = [];
|
|
83
|
+
this.held = []; // writes to a value another part holds
|
|
84
|
+
this.leftovers = []; // what removed parts left behind
|
|
85
|
+
this.files = new Map(); // source file -> Set of the picture parts that ran from it
|
|
86
|
+
this.homes = new Map(); // part -> a 'file:line' of its code once known, before that of the engine.use that installed it
|
|
87
|
+
this.adds = new Map(); // part -> Map(thing -> { kind, name, at }), until the thing leaves
|
|
88
|
+
this.addedBy = new WeakMap(); // thing -> part
|
|
89
|
+
this.top = new Map(); // 'fog.far' -> record (scene, fog and renderer values)
|
|
90
|
+
this.parts = new WeakMap(); // light or material -> { intensity: record, ... }
|
|
91
|
+
this.done = new WeakSet(); // a Color or Vector3 already watched (a color shared by two objects answers for the first)
|
|
92
|
+
const s = e.scene, r = e.renderer;
|
|
93
|
+
this.number(r, 'toneMapping', this.named('renderer.toneMapping', NOT.start));
|
|
94
|
+
this.number(r, 'toneMappingExposure', this.named('renderer.toneMappingExposure', NOT.start));
|
|
95
|
+
for (const k of ['environmentIntensity', 'backgroundIntensity']) this.number(s, k, this.named('scene.' + k, NOT.start));
|
|
96
|
+
this.number(s, 'environment', this.named('scene.environment', NOT.none));
|
|
97
|
+
const bg = this.named('scene.background', NOT.start);
|
|
98
|
+
this.slot(s, 'background', bg, c => { if (c?.isColor) this.watch(c, 'rgb', bg); });
|
|
99
|
+
if (s.background?.isColor) this.watch(s.background, 'rgb', bg);
|
|
100
|
+
const fog = this.named('scene.fog', NOT.none);
|
|
101
|
+
this.slot(s, 'fog', fog, f => this.fog(f, fog));
|
|
102
|
+
if (s.fog) this.fog(s.fog, fog);
|
|
103
|
+
this.roots = onSceneRoot(s, o => this.added(/** @type {any} */ (o).isLight ? 'light' : 'object', o, o.name || o.type), o => this.left(o));
|
|
104
|
+
this.view = sceneVisitor(s, { enter: o => {
|
|
105
|
+
if (/** @type {any} */ (o).isLight) this.light(o);
|
|
106
|
+
const m = /** @type {any} */ (o).material;
|
|
107
|
+
if (m) for (const x of [].concat(m)) this.material(x);
|
|
108
|
+
} });
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
named(label, why) { const r = newRec(why, () => label); this.top.set(label, r); return r; }
|
|
112
|
+
|
|
113
|
+
/** Own accessor for one plain value; false when the object has none to replace. Reads and writes pass straight through */
|
|
114
|
+
slot(o, key, rec, after) {
|
|
115
|
+
const d = Object.getOwnPropertyDescriptor(o, key);
|
|
116
|
+
if (!d || !('value' in d) || !d.configurable) { if (rec.why !== NOT.none || !d) rec.why = NOT.own; return false; }
|
|
117
|
+
let v = d.value;
|
|
118
|
+
const t = this;
|
|
119
|
+
Object.defineProperty(o, key, { configurable: true, enumerable: d.enumerable, get: () => v,
|
|
120
|
+
set(x) { if (x === v) return; v = x; t.wrote(rec); after?.(x); } });
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
number(o, key, rec) { this.slot(o, key, rec); }
|
|
124
|
+
/** The components of a Color or Vector3, all reporting to one record: to the game it is one value */
|
|
125
|
+
watch(c, keys, rec) {
|
|
126
|
+
if (this.done.has(c)) return;
|
|
127
|
+
this.done.add(c);
|
|
128
|
+
for (const k of keys) this.slot(c, k, rec);
|
|
129
|
+
}
|
|
130
|
+
/** A color held in a property: the components, and the property itself (light.color = other replaces the object the components were on) */
|
|
131
|
+
color(o, key, rec) {
|
|
132
|
+
if (!o[key]?.isColor) return false;
|
|
133
|
+
this.watch(o[key], 'rgb', rec);
|
|
134
|
+
this.slot(o, key, rec, c => { if (c?.isColor) this.watch(c, 'rgb', rec); });
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** A fog assigned now: its values were set by whoever wrote scene.fog, so they start with that answer, not with "not tracked" */
|
|
139
|
+
fog(f, slotRec) {
|
|
140
|
+
for (const k of ['near', 'far', 'density', 'color']) this.top.delete('fog.' + k);
|
|
141
|
+
if (!f) return;
|
|
142
|
+
const seed = r => { r.at = slotRec.at; r.why = slotRec.why; r.seen = slotRec.seen; return r; };
|
|
143
|
+
for (const k of f.isFogExp2 ? ['density'] : ['near', 'far']) this.number(f, k, seed(this.named('fog.' + k, NOT.before)));
|
|
144
|
+
this.color(f, 'color', seed(this.named('fog.color', NOT.before)));
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
light(l) {
|
|
148
|
+
if (this.parts.has(l) || page.off) return;
|
|
149
|
+
const at = this.e._things?.entryOf(l)?.[0]?.at, why = NOT.before + (at ? ` (added at ${at})` : '');
|
|
150
|
+
const rec = k => newRec(why, () => `light:${l.name}.${k}`); // read at each write: a light can be named after it entered the scene
|
|
151
|
+
const p = { intensity: rec('intensity'), color: rec('color'), position: rec('position') };
|
|
152
|
+
this.parts.set(l, p);
|
|
153
|
+
this.number(l, 'intensity', p.intensity);
|
|
154
|
+
this.color(l, 'color', p.color);
|
|
155
|
+
this.watch(l.position, 'xyz', p.position);
|
|
156
|
+
if (l.groundColor) this.color(l, 'groundColor', p.groundColor = rec('groundColor'));
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
material(m) {
|
|
160
|
+
if (this.parts.has(m) || page.off) return;
|
|
161
|
+
const p = {};
|
|
162
|
+
this.parts.set(m, p);
|
|
163
|
+
for (const k of ['color', 'emissive']) if (m[k]?.isColor) this.color(m, k, p[k] = newRec(NOT.before));
|
|
164
|
+
for (const k of ['opacity', 'emissiveIntensity']) if (typeof m[k] === 'number') this.number(m, k, p[k] = newRec(NOT.before));
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** The hot path: runs on every write that changed a value. No stack unless the header's rules ask for one */
|
|
168
|
+
wrote(rec) {
|
|
169
|
+
if (page.off || this.drawing || this.e._probing) return;
|
|
170
|
+
const fr = this.frame;
|
|
171
|
+
rec.wrote = fr;
|
|
172
|
+
if (rec.f !== fr) {
|
|
173
|
+
const cold = fr - rec.f > 1;
|
|
174
|
+
rec.sample = fr === 0 || cold || fr >= rec.next;
|
|
175
|
+
if (rec.sample) { rec.next = fr + EVERY + (rec.id & 7); rec.usual = 0; } // & 7: values written together do not all come due in one frame
|
|
176
|
+
rec.f = fr; rec.n = 0; rec.placeKey = null;
|
|
177
|
+
}
|
|
178
|
+
rec.n++;
|
|
179
|
+
if (!rec.sample) {
|
|
180
|
+
if (rec.n <= rec.usual) return;
|
|
181
|
+
rec.sample = true; rec.next = fr + 1; // more writes than usual: this one may be a new writer; next frame sees all of them from the first
|
|
182
|
+
}
|
|
183
|
+
rec.usual = rec.n;
|
|
184
|
+
this.stacks++;
|
|
185
|
+
const w = writerNow();
|
|
186
|
+
rec.seen = fr;
|
|
187
|
+
if (!w) { rec.at = null; rec.why = NOT.noFile; rec.placeKey = null; return; }
|
|
188
|
+
const by = this.partsOf(w);
|
|
189
|
+
this.claim(rec, w, by);
|
|
190
|
+
const place = `${w.key}|${by[0] ?? ''}`; // the part too: two parts' anonymous hooks in one file are two places
|
|
191
|
+
if (fr > 0 && rec.placeKey && rec.placeKey !== place && !rec.fought) this.fight(rec, rec.placeAt, rec.placeBy, w.at, by[0]);
|
|
192
|
+
rec.at = w.at; rec.why = null; rec.placeKey = place; rec.placeAt = w.at; rec.placeBy = by[0] ?? null;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** The parts this write can be from: the running module alone, else every part that ran from a file on the stack, nearest first */
|
|
196
|
+
partsOf(w) {
|
|
197
|
+
const m = this.e._curModule;
|
|
198
|
+
if (m) { if (m.type === 'picture' && !engineFile(w.file)) this.noteFile(w.file, m.name, w.at); return [m.name]; }
|
|
199
|
+
for (const f of w.frames) { const s = this.files.get(f.file); if (s) return [...s]; }
|
|
200
|
+
return [];
|
|
201
|
+
}
|
|
202
|
+
noteFile(file, part, at) {
|
|
203
|
+
let s = this.files.get(file);
|
|
204
|
+
if (!s) this.files.set(file, s = new Set());
|
|
205
|
+
if (!s.has(part)) this.homes.set(part, at);
|
|
206
|
+
s.add(part);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** A value in a slot someone holds: a write by the holder is noted, one by anyone else is reported, once per value and place */
|
|
210
|
+
claim(rec, w, by) {
|
|
211
|
+
const label = rec.name?.(), slot = label ? slotOfValue(label) : null, holder = slot && slotHolder(this.e, slot);
|
|
212
|
+
if (!holder) { rec.last = null; return; }
|
|
213
|
+
if (rec.ownBy !== holder) { rec.ownBy = holder; rec.ownAt = null; }
|
|
214
|
+
if (w.engine) return;
|
|
215
|
+
if (by.includes(holder)) { rec.ownAt = w.at; rec.last = { slot, holder, writer: 'holder' }; return; }
|
|
216
|
+
rec.last = { slot, holder, writer: 'stray', by: by[0] ?? null };
|
|
217
|
+
rec.fought = true; // this says more than a fight would, and the holder's next write would raise one
|
|
218
|
+
const key = `${w.key}\0${label}`;
|
|
219
|
+
if (this.held.some(h => h.key === key)) return;
|
|
220
|
+
const place = rec.ownAt ? `last written at ${rec.ownAt}` : `it has not changed this value yet; its code is at ${this.homes.get(holder) ?? 'an unknown line'}`;
|
|
221
|
+
this.held.push({ key, value: label, slot, holder, holderAt: rec.ownAt ?? this.homes.get(holder) ?? null, by: by[0] ?? null, at: w.at });
|
|
222
|
+
warnOnce(coded('picture-held', fmt(STRINGS.held, { value: label, holder, slot, place, at: w.at, who: who(by[0]) })), `picture-held\0${key}`);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/** engine.use is installing m: where, for a report that has no line of the holder's yet */
|
|
226
|
+
installing(m) { if (m.provides?.length) this.homes.set(m.name, callerAt()); }
|
|
227
|
+
|
|
228
|
+
/** ctx.track called by m's own code: the caller's file is the part's, which is how a timer or a listener of the part gets attributed later */
|
|
229
|
+
learn(m) {
|
|
230
|
+
if (page.off || m.type !== 'picture') return;
|
|
231
|
+
const E = /** @type {ErrorConstructor & { stackTraceLimit?: number }} */ (Error), lim = E.stackTraceLimit;
|
|
232
|
+
E.stackTraceLimit = DEPTH;
|
|
233
|
+
const stack = new Error().stack; E.stackTraceLimit = lim;
|
|
234
|
+
const f = stackFrames(stack ?? '').find(x => !SELF.test(x.file) && !/core\/modules\.js$/.test(x.file));
|
|
235
|
+
if (f && !engineFile(f.file)) this.noteFile(f.file, m.name, frameText(f));
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* A scene root or a post effect just added: which picture part it belongs to, if any.
|
|
240
|
+
* shortcut: only scene roots are seen. A light put under the camera or under another part's group is no root and goes unreported; upgrade through the visitor's
|
|
241
|
+
* pending adds in core/sceneDelta.js if an agent reports one.
|
|
242
|
+
*/
|
|
243
|
+
added(kind, thing, name) {
|
|
244
|
+
if (page.off) return;
|
|
245
|
+
const m = this.e._curModule;
|
|
246
|
+
if (m ? m.type !== 'picture' : !this.files.size) return;
|
|
247
|
+
const w = m ? null : writerNow(), part = m?.name ?? (w && this.partsOf(w)[0]);
|
|
248
|
+
if (!part) return;
|
|
249
|
+
let mine = this.adds.get(part);
|
|
250
|
+
if (!mine) this.adds.set(part, mine = new Map());
|
|
251
|
+
mine.set(thing, { kind, name, at: callerAt() });
|
|
252
|
+
this.addedBy.set(thing, part);
|
|
253
|
+
}
|
|
254
|
+
left(thing) { this.adds.get(this.addedBy.get(thing))?.delete(thing); }
|
|
255
|
+
|
|
256
|
+
/** A module was unloaded, its tracked handles and dispose already run: name what stayed. swapping: the newcomer takes over the slots' values */
|
|
257
|
+
partGone(m, swapping) {
|
|
258
|
+
const mine = this.adds.get(m.name);
|
|
259
|
+
this.adds.delete(m.name);
|
|
260
|
+
if (page.off || m.type !== 'picture') return;
|
|
261
|
+
const left = [];
|
|
262
|
+
for (const [thing, r] of mine ?? []) if (!thing._removed) left.push(r); // _removed: a post handle; a scene root that left is already out of the map
|
|
263
|
+
const e = this.e;
|
|
264
|
+
for (const list of [e._onRender.before, e._onRender.after, e._frame, e._fixed, e._fixedLate]) for (const f of list) if (f.part === m.name) left.push({ kind: 'hook', name: 'frame callback', at: f.at });
|
|
265
|
+
if (!swapping) for (const [name, on] of [['scene.fog', e.scene], ['scene.environment', e.scene], ['scene.background', e.scene]]) {
|
|
266
|
+
const r = this.top.get(name), key = name.slice(6);
|
|
267
|
+
if (r?.last?.holder === m.name && r.last.writer === 'holder' && on[key] != null) left.push({ kind: 'value', name, at: r.at });
|
|
268
|
+
}
|
|
269
|
+
if (!left.length) return;
|
|
270
|
+
this.leftovers.push({ part: m.name, left });
|
|
271
|
+
const list = left.map(r => `${r.kind} '${r.name}'${r.at ? ` (added at ${r.at})` : ''}`).join(', ');
|
|
272
|
+
warnOnce(coded('picture-leftover', fmt(STRINGS.leftover, { name: m.name, list })), `picture-leftover\0${m.name}\0${list}`);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
fight(rec, first, firstBy, second, secondBy) {
|
|
276
|
+
rec.fought = true;
|
|
277
|
+
const label = this.labelOf(rec) ?? 'a picture value', slot = slotOfValue(label);
|
|
278
|
+
const said = (at, by) => by ? `${at} (part '${by}')` : at;
|
|
279
|
+
this.fights.push({ value: label, first, second, ...(firstBy ? { firstBy } : {}), ...(secondBy ? { secondBy } : {}) });
|
|
280
|
+
warnOnce(coded('picture-conflict', fmt(STRINGS.conflict, { value: label, first: said(first, firstBy), second: said(second, secondBy), claim: slot ? fmt(STRINGS.claim, { slot }) : '' })), `picture-conflict\0${rec.id}`);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/** Every value with a name, in one pass: lights and materials are found through the scene, so their names are the current ones */
|
|
284
|
+
everyValue() {
|
|
285
|
+
this.view.sync();
|
|
286
|
+
const out = new Map(this.top), seen = new Map();
|
|
287
|
+
const add = (prefix, o, name) => {
|
|
288
|
+
const p = this.parts.get(o);
|
|
289
|
+
if (!p) return;
|
|
290
|
+
const n = (seen.get(name) ?? 0) + 1;
|
|
291
|
+
seen.set(name, n);
|
|
292
|
+
const id = `${prefix}:${name}${n > 1 ? '#' + n : ''}`;
|
|
293
|
+
for (const k in p) out.set(`${id}.${k}`, p[k]);
|
|
294
|
+
};
|
|
295
|
+
const mats = new Set();
|
|
296
|
+
this.e.scene.traverse(o => {
|
|
297
|
+
const x = /** @type {any} */ (o);
|
|
298
|
+
if (x.isLight) add('light', x, x.name || x.type);
|
|
299
|
+
if (x.material) for (const m of [].concat(x.material)) mats.add(m);
|
|
300
|
+
});
|
|
301
|
+
for (const m of mats) add('material', m, m.name || `${m.type}-${m.uuid.slice(0, 6)}`);
|
|
302
|
+
return out;
|
|
303
|
+
}
|
|
304
|
+
labelOf(rec) { for (const [k, r] of this.everyValue()) if (r === rec) return k; return null; }
|
|
305
|
+
|
|
306
|
+
answer(r) {
|
|
307
|
+
if (!r.at) return { at: null, note: r.why };
|
|
308
|
+
return { at: r.at, framesAgo: this.frame - r.seen, ...(r.wrote > r.seen ? { writtenSince: true } : {}), ...(r.last ?? {}) };
|
|
309
|
+
}
|
|
310
|
+
/** describe('picture').writers: materials nobody wrote since they entered the scene are left out (each would say the same "not tracked") */
|
|
311
|
+
list() {
|
|
312
|
+
const values = {};
|
|
313
|
+
let mats = 0, more = 0;
|
|
314
|
+
for (const [k, r] of this.everyValue()) {
|
|
315
|
+
if (k.startsWith('material:')) { if (!r.at) continue; if (++mats > MATERIALS_MAX) { more++; continue; } }
|
|
316
|
+
values[k] = this.answer(r);
|
|
317
|
+
}
|
|
318
|
+
return { tracked: true, frame: this.frame, stacks: this.stacks, values, conflicts: this.fights, held: this.held.map(({ key, ...h }) => h), leftovers: this.leftovers, ...(more ? { moreMaterials: more } : {}) };
|
|
319
|
+
}
|
|
320
|
+
/** One value by its describe name @param {string} label */
|
|
321
|
+
why(label) {
|
|
322
|
+
const all = this.everyValue(), r = all.get(label);
|
|
323
|
+
if (!r) return { ok: false, text: `${label}: not tracked. Tracked names (describe('picture').writers): ${[...all.keys()].filter(k => !k.startsWith('material:')).join(', ')}, material:<name>.color / emissive / opacity / emissiveIntensity`, detail: null };
|
|
324
|
+
const a = this.answer(r), fight = this.fights.find(f => f.value === label);
|
|
325
|
+
const owner = !a.slot ? '' : a.writer === 'holder' ? `, by part '${a.holder}', which holds ${a.slot}` : `, by ${who(a.by)}, a stray write: part '${a.holder}' holds ${a.slot}`;
|
|
326
|
+
const age = a.framesAgo ? `, looked at ${a.framesAgo} frames ago${a.writtenSince ? ' (written since, not looked at)' : ''}` : '';
|
|
327
|
+
return { ok: !!a.at, text: `${label}: ${a.at ? `last changed at ${a.at}${owner}${age}` : a.note}${fight ? `. Two writers in one frame: ${fight.first}, then ${fight.second}` : ''}`, detail: { ...a, ...(fight ? { conflict: fight } : {}) } };
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/** Top of a frame's hooks. Two frame hooks with no draw between (engine.step many frames, one draw) are two frames: a state change between them is no fight */
|
|
331
|
+
frameStart() { this.view.sync(); if (this.hooksRan) this.frame++; this.hooksRan = true; }
|
|
332
|
+
/** After the draw. The fixed steps before the next hooks count with that next frame, which is what they lead to */
|
|
333
|
+
frameEnd() { this.drawing = false; this.frame++; this.hooksRan = false; }
|
|
334
|
+
dispose() { this.view.remove(); this.roots.remove(); }
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/** @param {any} e */
|
|
338
|
+
export function installPictureWriters(e) {
|
|
339
|
+
notePatch('picture-writers', 'dev server only: intensity, color, position of lights, scene.fog and its values, renderer.toneMapping / toneMappingExposure, scene.environment / background and their intensities, material color / emissive / opacity: an own get / set on each, and on the r g b / x y z of the Color or Vector3 (core/pictureWriters.js)',
|
|
340
|
+
() => { page.off = true; }, // accessors already placed stay and only pass values through; new objects get none
|
|
341
|
+
{ scope: 'objects in the scene', lost: "describe('picture').writers stops answering, and two writers in one frame are no longer warned about" });
|
|
342
|
+
e._picture = new Writers(e);
|
|
343
|
+
}
|
package/core/plugins.js
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
// engine.plugins: the plugins folder (docs/plans/2026-11-03-slot-map.md section 6). Each file in the game's plugins/ folder is imported at
|
|
2
|
+
// start and plugged in by WHAT it exports, through the one call a game would have written by hand:
|
|
3
|
+
// Object3D -> engine.add(obj, { id: <file name> }) (same as scene.add, plus a stable save id)
|
|
4
|
+
// three.js Pass (has render()) -> engine.post.add(pass, { name: <file name> })
|
|
5
|
+
// post effect { name, create | node | fuse } -> engine.post.add(effect) (create for WebGL, node for WebGPU: one file runs on both)
|
|
6
|
+
// module { name, type, install / init } -> engine.use(mod)
|
|
7
|
+
// an array of those -> each one, in array order
|
|
8
|
+
// anything else is a dev error naming the file and the shapes above. A function is never a plugin, on either renderer: a plugin says what it
|
|
9
|
+
// is by its shape, and a bare function says nothing (a library factory, a material maker and a node pass all look the same), so taking it
|
|
10
|
+
// as a WebGPU node pass made one file behave differently per renderer. Why only existing calls: the folder adds no new slot and no new rule,
|
|
11
|
+
// it only saves the registration lines, so everything a hand-written call gets (describe, layering, remove) a plugin gets too.
|
|
12
|
+
// Which export: the default export when there is one (named exports are then free for helpers), else every named export in order.
|
|
13
|
+
// Order: by file name (10-fog.js before 20-bloom.js), or plugins/plugins.json { "order": [...], "off": [...] }. Nothing is sorted behind
|
|
14
|
+
// the game's back: describe().slots lists the order used.
|
|
15
|
+
// Off: plugins.json "off" (no code change), or engine.plugins.off(name) at run time; on(name) plugs it again.
|
|
16
|
+
// Owners: every plugin is its own owner ('plugin:<file>'). Why: with one owner for all, B's remove dropped the key A had written too (A said on,
|
|
17
|
+
// the base came back). Two plugins writing one key on one layer is a shared-conflict naming both, unless one file says `export const replaces = '<other file>'` (then the other is unplugged while this one is on).
|
|
18
|
+
// A Material or a ShaderPatch is no plugin: it says nothing about which mesh it belongs to, so it goes on that mesh or module in plain code.
|
|
19
|
+
// Places: a post effect keeps the place it first got (its name is reserved in plugin order), so off / on never reorders the chain.
|
|
20
|
+
import { codedError } from './errorHints.js';
|
|
21
|
+
import { MODULE_TYPES } from './moduleTypes.js';
|
|
22
|
+
|
|
23
|
+
const SHAPES = 'an Object3D (goes in the scene), a three.js Pass with render() (post chain), a post effect { name, create: ctx => pass, node: (input, ctx) => node } or { name, fuse } (post chain, both renderers), ' +
|
|
24
|
+
"a module { name, type, install / init } (engine.use), or an array of these. Export it as default (export default new THREE.Mesh(...))";
|
|
25
|
+
|
|
26
|
+
/** Which slot a value plugs into, or null when it is none of the accepted shapes */
|
|
27
|
+
function shapeOf(v) {
|
|
28
|
+
if (v?.isObject3D) return 'scene';
|
|
29
|
+
if (v?.isMaterial) return null; // it has name, type and dispose(), so the module test below would take it for a module
|
|
30
|
+
if (v && typeof v === 'object') {
|
|
31
|
+
if (typeof v.render === 'function' && 'needsSwap' in v) return 'post'; // three's Pass base class sets needsSwap: a Pass, not a module with render()
|
|
32
|
+
if (typeof v.name === 'string' && v.type && (v.install || v.init || v.fixed || v.frame || v.dispose)) return 'module';
|
|
33
|
+
if (typeof v.name === 'string' && (typeof v.create === 'function' || typeof v.node === 'function' || (v.fuse && typeof v.fuse === 'object'))) return 'post';
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** The post chain name of a plugin's post value: an effect keeps its own name, a bare Pass is named by its file ('<file>/<i>' with several) */
|
|
39
|
+
const postName = (p, v, i) => (v.isPass || 'needsSwap' in v ? (p.values.length > 1 ? `${p.name}/${i}` : p.name) : v.name);
|
|
40
|
+
|
|
41
|
+
/** File name without folder and extension: './plugins/10-crate.js' -> '10-crate' */
|
|
42
|
+
const baseOf = path => path.split('/').pop().replace(/\.[cm]?[jt]s$/, '');
|
|
43
|
+
|
|
44
|
+
export class Plugins {
|
|
45
|
+
/** @param {any} e @internal */
|
|
46
|
+
constructor(e) {
|
|
47
|
+
/** @internal */ this._e = e;
|
|
48
|
+
/** @internal name -> { name, file, values, on, plugged: [{ slot, value, remove }] } in plug order */
|
|
49
|
+
this._list = new Map();
|
|
50
|
+
/** @internal set by add(); start() plugs them */
|
|
51
|
+
this._added = false;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Hand the engine a folder of plugin files: the result of Vite's import.meta.glob('./plugins/*.js', { eager: true }) or any
|
|
56
|
+
* { path: moduleNamespace } map. The vite preset does this for you (tools/vite/vite-threedog-plugins.js); call it yourself only without it.
|
|
57
|
+
* Before start() the files are plugged at start; after start() at once.
|
|
58
|
+
* @param {Record<string, any>} files @param {{ order?: string[], off?: string[] }} [o] order: file names first, in this order; off: not plugged
|
|
59
|
+
* @returns {this}
|
|
60
|
+
* @example engine.plugins.add(import.meta.glob('./plugins/*.js', { eager: true }), { off: ['20-bloom'] });
|
|
61
|
+
*/
|
|
62
|
+
add(files, { order = [], off = [] } = {}) {
|
|
63
|
+
const paths = Object.keys(files).sort((a, b) => baseOf(a) < baseOf(b) ? -1 : baseOf(a) > baseOf(b) ? 1 : 0);
|
|
64
|
+
const rank = n => { const i = order.indexOf(n); return i < 0 ? order.length : i; };
|
|
65
|
+
paths.sort((a, b) => rank(baseOf(a)) - rank(baseOf(b))); // stable sort: listed names first, the rest keep file-name order
|
|
66
|
+
for (const n of [...order, ...off]) if (!paths.some(p => baseOf(p) === n))
|
|
67
|
+
throw codedError('plugin-shape', `plugins.json names '${n}', but there is no plugins/${n}.js; files: ${paths.map(baseOf).join(', ') || 'none'}`);
|
|
68
|
+
for (const path of paths) {
|
|
69
|
+
const ns = files[path], name = baseOf(path);
|
|
70
|
+
// replaces: a word about the file, never plugged (a string is no plugin shape)
|
|
71
|
+
const named = ns && 'default' in ns ? [['default', ns.default]] : Object.entries(ns ?? {}).filter(([k]) => k !== 'replaces'), values = named.flatMap(([, v]) => [].concat(v));
|
|
72
|
+
if (!values.length) throw codedError('plugin-shape', `plugins/${baseOf(path)}.js exports nothing. Fix: export default one of: ${SHAPES}`);
|
|
73
|
+
for (const [key, x] of named) for (const v of [].concat(x)) if (!shapeOf(v)) throw codedError('plugin-shape', notAPlugin(`plugins/${baseOf(path)}.js`, key, v));
|
|
74
|
+
const file = path.replace(/^.*?(plugins\/)/, '$1');
|
|
75
|
+
const replaces = [].concat(ns?.replaces ?? []).map(String);
|
|
76
|
+
this._list.set(name, { name, file, values, replaces, replacedBy: null, on: !off.includes(name), plugged: [] });
|
|
77
|
+
}
|
|
78
|
+
for (const p of this._list.values()) for (const r of p.replaces) if (!this._list.has(r))
|
|
79
|
+
throw codedError('plugin-shape', `${p.file}: export const replaces = '${r}', but there is no plugin '${r}'; plugins: ${[...this._list.keys()].join(', ')}`);
|
|
80
|
+
this._added = true;
|
|
81
|
+
if (this._e._started) this._plugAll();
|
|
82
|
+
return this;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** @internal start(): plug every file that is on, in order (before module init, so a module from a plugin inits with the others) */
|
|
86
|
+
_plugAll() {
|
|
87
|
+
const e = this._e, all = [...this._list.values()];
|
|
88
|
+
// every post effect's place is reserved in plugin order, on or off, so one switched on later still lands where the list says (PostFX._place)
|
|
89
|
+
for (const p of all) p.values.forEach((v, i) => { if (shapeOf(v) === 'post') e.post?._place(postName(p, v, i), true); });
|
|
90
|
+
const todo = all.filter(p => p.on && !p.plugged.length && !p.replacedBy);
|
|
91
|
+
for (const p of todo) if (p.on && !p.plugged.length && !p.replacedBy) this._plug(p); // re-checked: a plug can unplug a later one it replaces
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** @internal */
|
|
95
|
+
_plug(p) {
|
|
96
|
+
const e = this._e, owner = 'plugin:' + p.name, layer = 'game';
|
|
97
|
+
let at = null; // the value being plugged, so a clash can name the other plugin
|
|
98
|
+
for (const r of p.replaces) { const q = this._list.get(r); q.replacedBy = p.name; this._unplug(q); }
|
|
99
|
+
try {
|
|
100
|
+
for (const v of p.values) {
|
|
101
|
+
at = v;
|
|
102
|
+
const slot = shapeOf(v);
|
|
103
|
+
let remove;
|
|
104
|
+
if (slot === 'scene') { e.add(v, { id: p.values.length > 1 ? `${p.name}/${p.plugged.length}` : p.name }); remove = () => { v.removeFromParent(); e._things.forget(v); e.rays.forget(v); }; } // not engine.remove: that disposes, and on() puts it back
|
|
105
|
+
// an effect keeps its own name (engine.post.get('bloom') reads the same from any source); a bare Pass is named by its file
|
|
106
|
+
else if (slot === 'post') { const h = e.post.add(v, v.isPass || 'needsSwap' in v ? { name: postName(p, v, p.plugged.length) } : {}); remove = () => h.remove(); }
|
|
107
|
+
else { e.use(v); remove = () => { if (e.modules.get(v.name) === v) e._unuse(v.name); }; }
|
|
108
|
+
p.plugged.push({ slot, value: v, remove });
|
|
109
|
+
}
|
|
110
|
+
} catch (err) {
|
|
111
|
+
this._unplug(p); // all or nothing per file: half a plugin is harder to read than none
|
|
112
|
+
this._giveBack(p);
|
|
113
|
+
err.message = `${p.file}: ${err.message}`;
|
|
114
|
+
// two plugins naming one post effect: the error comes from the post chain, which knows names and not files, so the file of the first is added here
|
|
115
|
+
const first = [...this._list.values()].find(q => q !== p && q.plugged.some(x => x.slot === 'post' && at?.name && x.value.name === at.name));
|
|
116
|
+
if (first) err.message += ` ${first.file} added it first.`;
|
|
117
|
+
if (first || /shared-conflict/.test(err.message)) err.message += ` Two plugins write the same key: keep one, or say which wins in the file that should: export const replaces = '<the other file>';`;
|
|
118
|
+
throw err;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/** @internal */
|
|
122
|
+
_unplug(p) { for (const x of p.plugged.splice(0).reverse()) x.remove(); }
|
|
123
|
+
/** @internal p is out: the plugins it replaced plug again (when they are on) */
|
|
124
|
+
_giveBack(p) {
|
|
125
|
+
for (const q of this._list.values()) if (q.replacedBy === p.name) { q.replacedBy = null; if (q.on && this._e._started && !q.plugged.length) this._plug(q); }
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Switch a plugin off: everything it plugged is taken out again (the object leaves the scene, the pass the chain,
|
|
130
|
+
* the module is unloaded). No code change: plugins.json "off" does the same at start.
|
|
131
|
+
* To pause a post effect and keep everything else, engine.post.get('<effect>').enabled = false is lighter: off unloads.
|
|
132
|
+
* @param {string} name file name without .js
|
|
133
|
+
* @returns {{ off: string[], note: string }}
|
|
134
|
+
*/
|
|
135
|
+
off(name) {
|
|
136
|
+
const p = this._get(name);
|
|
137
|
+
p.on = false; this._unplug(p);
|
|
138
|
+
this._giveBack(p);
|
|
139
|
+
return this._result('off', p);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Switch a plugin back on (plugged at once after start). @param {string} name
|
|
143
|
+
* @returns {{ on: string[], note: string }}
|
|
144
|
+
*/
|
|
145
|
+
on(name) {
|
|
146
|
+
const p = this._get(name);
|
|
147
|
+
p.on = true; if (this._e._started && !p.plugged.length && !p.replacedBy) this._plug(p);
|
|
148
|
+
return this._result('on', p);
|
|
149
|
+
}
|
|
150
|
+
/** @internal what off / on did, in words a reader can act on */
|
|
151
|
+
_result(verb, p) {
|
|
152
|
+
const notes = [];
|
|
153
|
+
const fx = p.values.map((v, i) => (shapeOf(v) === 'post' ? postName(p, v, i) : null)).filter(Boolean);
|
|
154
|
+
if (verb === 'off' && fx.length) notes.push(`plugins.off unloads; to pause an effect in its place use ${fx.map(n => `engine.post.get('${n}').enabled = false`).join('; ')}`);
|
|
155
|
+
if (p.replacedBy) notes.push(`${p.name} stays out while ${p.replacedBy} (replaces it) is on`);
|
|
156
|
+
return { [verb]: [p.name], note: notes.join('; ') };
|
|
157
|
+
}
|
|
158
|
+
/** @internal */
|
|
159
|
+
_get(name) {
|
|
160
|
+
const p = this._list.get(name);
|
|
161
|
+
if (!p) throw codedError('plugin-shape', `engine.plugins: no plugin '${name}'; plugins: ${[...this._list.keys()].join(', ') || 'none (no plugins folder)'}`);
|
|
162
|
+
return p;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* The plugins in plug order: { name, file, on, slots, replacedBy } (replacedBy: the plugin that holds it out)
|
|
167
|
+
* @returns {{ name: string, file: string, on: boolean, slots: string[], replacedBy: string | null }[]}
|
|
168
|
+
*/
|
|
169
|
+
list() { return [...this._list.values()].map(p => ({ name: p.name, file: p.file, on: p.on, slots: p.values.map(v => shapeOf(v)), replacedBy: p.replacedBy })); }
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* The plugin-shape error for one export that is not a plugin: the file, what was found, and the exact fix for that case
|
|
174
|
+
* (a factory function, a module missing its type or hooks, a post effect missing its name, anything else).
|
|
175
|
+
*/
|
|
176
|
+
function notAPlugin(file, key, v) {
|
|
177
|
+
const what = key === 'default' ? 'the default export' : `the export '${key}'`;
|
|
178
|
+
if (v?.isMaterial) return `${file}: ${what} is a Material, which says nothing about what it goes on. Fix: put it on its mesh in your picture/ code, or on a module (engine.water.material = mat)`;
|
|
179
|
+
if (v && typeof v === 'object' && !v.isObject3D && (v.slot || typeof v.glsl === 'string' || typeof v.glsl === 'object' || v.tsl))
|
|
180
|
+
return `${file}: ${what} is a ShaderPatch, which says nothing about which material it changes. Fix: applyEffects(material, { patches: [patch] }) in your picture/ code`;
|
|
181
|
+
if (typeof v === 'function') {
|
|
182
|
+
const fn = v.name && v.name !== 'default' ? v.name : 'make';
|
|
183
|
+
return `${file}: ${what} is a function (${v.name || 'anonymous'}). A function is never a plugin: it does not say where it plugs in. ` +
|
|
184
|
+
(key === 'default' ? `Fix: make it a named export and plug in what it returns: export function ${fn}(...) { ... } export default ${fn}({ ... });`
|
|
185
|
+
: `Fix: plug in what it returns, add to the file: export default ${key}({ ... }); (the default export is plugged; named exports stay helpers)`) +
|
|
186
|
+
" A post node pass: export default { name: 'glow', node: (input, ctx) => ..., create: ctx => pass }. Library code: threedog lib pull writes this wiring file for you";
|
|
187
|
+
}
|
|
188
|
+
if (v && typeof v === 'object') {
|
|
189
|
+
const keys = Object.keys(v).slice(0, 8).join(', ') || '(none)';
|
|
190
|
+
const hooks = ['install', 'init', 'fixed', 'frame', 'dispose'].filter(h => typeof v[h] === 'function');
|
|
191
|
+
if (typeof v.name === 'string' && hooks.length && !v.type)
|
|
192
|
+
return `${file}: ${what} is a module '${v.name}' (${hooks.join(', ')}) with no type. Fix: add type to it: { name: '${v.name}', type: 'rules', ${hooks[0]}(...) { ... } }; types: ${Object.keys(MODULE_TYPES).map(t => `'${t}'`).join(' | ')}`;
|
|
193
|
+
if (typeof v.name === 'string' && v.type && !hooks.length)
|
|
194
|
+
return `${file}: ${what} is a module '${v.name}' (type '${v.type}') with no install / init / fixed / frame hook (keys: ${keys}). Fix: add the hook that sets it up: { name: '${v.name}', type: '${v.type}', install(engine, ctx) { ... } }`;
|
|
195
|
+
if (typeof v.name !== 'string' && (typeof v.create === 'function' || typeof v.node === 'function' || v.fuse))
|
|
196
|
+
return `${file}: ${what} looks like a post effect (keys: ${keys}) but has no name. Fix: add one: { name: '${key === 'default' ? 'my-effect' : key}', ${typeof v.node === 'function' ? 'node' : 'create'}: ... }`;
|
|
197
|
+
return `${file}: ${what} is an object with keys ${keys}, which matches no plugin shape. Fix: export default one of: ${SHAPES}`;
|
|
198
|
+
}
|
|
199
|
+
return `${file}: ${what} is ${v == null ? String(v) : `a ${typeof v} (${String(v).slice(0, 40)})`}, which is not a plugin. Fix: export default one of: ${SHAPES}`;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Plug what the page's plugins folder gave (the vite preset puts it on globalThis.__threedogPlugins before main.js runs) and the files
|
|
204
|
+
* engine.plugins.add received. Called once by start(). @param {any} e
|
|
205
|
+
*/
|
|
206
|
+
export function plugAtStart(e) {
|
|
207
|
+
const page = typeof globalThis !== 'undefined' ? globalThis.__threedogPlugins : null;
|
|
208
|
+
if (page && !e.plugins._added) e.plugins.add(page.files, page.config ?? {});
|
|
209
|
+
e.plugins._plugAll();
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* describe().slots: one table of what is plugged in where. Each row: { slot, plugged, file, on, affects }; file is the plugin file, the
|
|
214
|
+
* file:line that called scene.add / engine.add (dev), or the call that plugged it ('engine.use', 'engine.post.add'). Why one table:
|
|
215
|
+
* a reader asking "what did this game add to the engine" had to put describe().scene, render.post and modules side by side.
|
|
216
|
+
* @param {any} e
|
|
217
|
+
*/
|
|
218
|
+
export function describeSlots(e) {
|
|
219
|
+
const rows = [], fromPlugin = new Set();
|
|
220
|
+
const passOf = v => e.post?._list.find(h => h._def === v || h._def._pass === v || h._def.node === v);
|
|
221
|
+
const affects = (slot, v) => {
|
|
222
|
+
if (slot === 'scene') { const t = e._things.byObj.get(v); return t ? [`engine.thing('${t.id}')`, `save tier ${e._things.tier(t)}`] : ['scene']; }
|
|
223
|
+
if (slot === 'post') { const h = passOf(v); return [h ? `picture: post chain ${h.slot} slot, ${h.name}` : 'picture: post chain']; }
|
|
224
|
+
if (slot === 'light') return ["budget 'lights'", ...(v.castShadow ? ["budget 'shadowLights'", 'idle shadow redraw rule'] : [])];
|
|
225
|
+
return [`engine.${v.name}`, `type ${v.type}`, ...(v.provides ?? []).map(s => `provides ${s}`)];
|
|
226
|
+
};
|
|
227
|
+
for (const p of e.plugins?._list.values() ?? []) for (const v of p.values) {
|
|
228
|
+
const slot = shapeOf(v);
|
|
229
|
+
fromPlugin.add(v);
|
|
230
|
+
const live = p.on && !p.replacedBy;
|
|
231
|
+
rows.push({ slot, plugged: (slot === 'module' ? v.name : v.name || v.type) || p.name, file: p.file, on: live,
|
|
232
|
+
affects: live ? affects(slot, v) : p.replacedBy ? [`replaced by ${p.replacedBy}`] : [] });
|
|
233
|
+
}
|
|
234
|
+
for (const o of e.scene.children) { const en = e._things.byObj.get(o); if (en?.owner === 'game' && !fromPlugin.has(o) && !o.isLight)
|
|
235
|
+
rows.push({ slot: 'scene', plugged: o.name || o.type, file: en.at ?? 'scene.add / engine.add', on: true, affects: affects('scene', o) }); }
|
|
236
|
+
for (const h of e.post?._list ?? []) if (![h._def, h._def._pass, h._def.node].some(v => v && fromPlugin.has(v)))
|
|
237
|
+
rows.push({ slot: 'post', plugged: h.name, file: 'engine.post.add', on: h.enabled, affects: [`picture: post chain ${h.slot} slot, ${h.name}`] });
|
|
238
|
+
for (const m of e.post?._plain ?? []) if (m.output)
|
|
239
|
+
rows.push({ slot: 'post', plugged: 'OutputPass (skipped: the engine tone maps; passes after it run in ldr)', file: 'engine.post.add', on: true, affects: ['picture: where display color starts'] });
|
|
240
|
+
for (const m of e.modules.values()) if (!fromPlugin.has(m))
|
|
241
|
+
rows.push({ slot: 'module', plugged: m.name, file: 'engine.use', on: true, affects: affects('module', m) });
|
|
242
|
+
for (const l of e._gameLights?.list() ?? [])
|
|
243
|
+
rows.push({ slot: 'light', plugged: l.name || l.type, file: e._things.entryOf(l)?.[0]?.at ?? 'scene.add', on: true, affects: affects('light', l) });
|
|
244
|
+
return rows;
|
|
245
|
+
}
|