threedog 0.2.0 → 0.5.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 +290 -0
- package/README.md +9 -8
- package/core/Animator.js +15 -12
- package/core/Assets.js +83 -16
- package/core/Audio.js +45 -38
- package/core/Baked.js +32 -8
- package/core/Batching.js +102 -15
- package/core/Budget.js +39 -18
- package/core/Clock.js +40 -80
- package/core/DebugOverrides.js +45 -10
- package/core/Describe.js +104 -43
- package/core/Engine.js +190 -57
- package/core/Events.js +4 -1
- package/core/I18n.js +25 -13
- package/core/Input.js +168 -79
- package/core/Inspect.js +2 -2
- package/core/InspectMaterials.js +85 -0
- package/core/InspectPerf.js +61 -0
- package/core/InspectScene.js +13 -2
- package/core/Loading.js +2 -1
- package/core/Ops.js +50 -9
- package/core/Random.js +9 -2
- package/core/Rays.js +5 -5
- package/core/SaveStore.js +41 -9
- package/core/Saves.js +71 -15
- package/core/Stream.js +14 -10
- package/core/Threads.js +26 -7
- package/core/UrlState.js +25 -9
- package/core/Views.js +9 -6
- package/core/actor.js +1 -1
- package/core/adaptive.js +93 -0
- package/core/assetEntry.js +22 -5
- package/core/assetHot.js +176 -0
- package/core/assetLoad.js +38 -11
- package/core/assetManifest.js +48 -9
- package/core/assetReport.js +1 -1
- package/core/audioRules.js +13 -11
- package/core/audioVoice.js +69 -42
- package/core/canvasBox.js +1 -2
- package/core/catalog.js +5 -2
- 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 +82 -15
- package/core/describeRender.js +43 -17
- package/core/describeText.js +41 -21
- package/core/engineCamera.js +32 -0
- package/core/errorCodes.js +438 -19
- package/core/errorHints.js +37 -141
- package/core/errors.js +31 -8
- package/core/events.generated.js +12 -7
- package/core/gameLights.js +62 -0
- package/core/grayMap.js +20 -0
- package/core/grid.js +128 -0
- package/core/gridLoad.js +20 -0
- 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 +48 -12
- package/core/lightWatch.js +6 -4
- package/core/look/coreParts.js +137 -30
- package/core/look/part.js +175 -95
- package/core/look/points.js +255 -0
- package/core/look/report.js +34 -17
- package/core/look/shadowPart.js +63 -0
- package/core/look/state.js +45 -0
- package/core/look/write.js +12 -28
- package/core/loop.js +101 -37
- package/core/math.js +11 -3
- package/core/moduleSlots.js +75 -0
- package/core/moduleTypes.js +73 -0
- package/core/modules.js +145 -27
- package/core/movement.js +2 -2
- package/core/namedModel.js +70 -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 +168 -0
- package/core/page.js +2 -1
- package/core/params.js +30 -8
- package/core/plugins.js +277 -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 +203 -0
- package/core/sceneMethods.js +35 -30
- 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 +2 -1
- package/core/sharedPoint.js +317 -0
- package/core/skip.js +36 -28
- package/core/stackFrames.js +34 -0
- package/core/stacks.js +166 -0
- package/core/startup.js +153 -11
- package/core/streamSources.js +0 -11
- package/core/styleParts.js +65 -47
- package/core/targeting.js +1 -1
- package/core/textureBytes.js +20 -0
- package/core/thingExplain.js +2 -2
- package/core/thingOps.js +29 -6
- package/core/things.js +21 -11
- 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 +7 -1
- package/core/validate.js +65 -86
- package/core/wrap.js +106 -0
- package/docs/AI.md +89 -97
- package/docs/API.md +32 -28
- package/docs/CODEMAP.md +224 -149
- package/docs/COMMANDS.md +57 -34
- package/docs/CONVENTIONS.md +92 -30
- package/docs/MIGRATING-0.3.md +248 -0
- package/docs/MIGRATING-0.4.md +228 -0
- package/docs/MIGRATING-0.5.md +68 -0
- package/docs/PERF.md +35 -7
- package/docs/THREE.md +79 -27
- package/docs/api/ambience.md +0 -1
- package/docs/api/assets.md +12 -9
- package/docs/api/audio.md +10 -14
- package/docs/api/calendar.md +41 -0
- package/docs/api/cameraRig.md +16 -5
- package/docs/api/characters.md +41 -25
- package/docs/api/clock.md +6 -5
- package/docs/api/collision.md +9 -6
- package/docs/api/content.md +6 -4
- package/docs/api/dialogue.md +9 -9
- package/docs/api/engine.md +65 -62
- package/docs/api/events.md +19 -14
- package/docs/api/grids.md +3 -3
- package/docs/api/ground.md +1 -1
- package/docs/api/hud.md +2 -2
- package/docs/api/i18n.md +1 -1
- package/docs/api/input.md +11 -6
- package/docs/api/interactions.md +7 -5
- package/docs/api/inventory.md +17 -16
- package/docs/api/level.md +0 -1
- package/docs/api/lightPool.md +3 -1
- package/docs/api/music.md +1 -1
- package/docs/api/nav.md +3 -0
- package/docs/api/openWorld.md +2 -1
- package/docs/api/particles.md +2 -2
- package/docs/api/photo.md +0 -2
- package/docs/api/pickups.md +15 -0
- package/docs/api/post.md +5 -4
- 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 +11 -44
- package/docs/api/stream.md +1 -1
- package/docs/api/style.md +31 -29
- package/docs/api/terrain.md +9 -6
- package/docs/api/terrainLook.md +10 -0
- package/docs/api/timeline.md +3 -4
- package/docs/api/tools.md +30 -13
- package/docs/api/triggers.md +5 -10
- package/docs/api/vegetation.md +12 -8
- package/docs/api/vegetationLook.md +10 -0
- package/docs/api/water.md +4 -20
- package/docs/api/weather.md +5 -15
- package/docs/api/weatherLook.md +10 -0
- package/docs/api/world.md +2 -1
- package/docs/recipes/01-new-game.md +71 -59
- package/docs/recipes/02-npc.md +46 -29
- package/docs/recipes/03-items-pickups.md +38 -24
- package/docs/recipes/04-quests.md +34 -27
- package/docs/recipes/05-props-bake.md +154 -18
- package/docs/recipes/06-clock-events.md +100 -52
- package/docs/recipes/07-flow-scenes-pause.md +41 -10
- package/docs/recipes/08-weather-sky.md +146 -37
- package/docs/recipes/09-style.md +218 -0
- package/docs/recipes/10-blender-level.md +14 -2
- package/docs/recipes/11-vehicles.md +64 -7
- package/docs/recipes/13-animation.md +34 -10
- package/docs/recipes/14-custom-module.md +65 -34
- package/docs/recipes/15-perf.md +35 -6
- package/docs/recipes/16-dev-bridge.md +65 -41
- package/docs/recipes/18-world.md +21 -8
- package/docs/recipes/19-shooting-picking.md +12 -11
- package/docs/recipes/20-content-actions-save.md +63 -25
- package/docs/recipes/21-camera.md +49 -16
- package/docs/recipes/22-shop-gold.md +18 -18
- package/docs/recipes/23-ops.md +17 -11
- package/docs/recipes/26-ui-parts.md +61 -12
- package/docs/recipes/27-net.md +12 -6
- package/docs/recipes/28-terrain.md +35 -2
- package/docs/recipes/29-grid.md +71 -33
- package/docs/recipes/30-templates.md +64 -12
- package/docs/recipes/31-audio.md +20 -12
- package/docs/recipes/32-action-game.md +35 -2
- package/docs/recipes/34-environment-lighting.md +27 -4
- package/docs/recipes/35-style-from-reference.md +115 -51
- package/docs/recipes/36-sky-ground-plant-looks.md +37 -35
- package/docs/recipes/37-terrain-look-hooks.md +37 -15
- package/docs/recipes/38-environment-look-hooks.md +64 -48
- package/docs/recipes/40-scene.md +16 -13
- package/docs/recipes/41-thing-registry.md +11 -7
- package/docs/recipes/42-terrain-shape.md +3 -3
- package/docs/recipes/43-shader-patches-surface-looks.md +171 -74
- package/docs/recipes/44-water-weather-look-hooks.md +30 -21
- package/docs/recipes/45-cascaded-shadows.md +17 -8
- package/docs/recipes/46-blender-art-route.md +4 -4
- package/docs/recipes/47-island-snow-backdrop.md +11 -10
- package/docs/recipes/48-make-material.md +11 -6
- package/docs/recipes/49-game-module-contract.md +46 -33
- package/docs/recipes/50-own-renderer.md +2 -2
- package/docs/recipes/51-capability-catalog.md +4 -4
- package/docs/recipes/52-look.md +228 -54
- package/docs/recipes/53-ground-up-close.md +58 -0
- package/docs/recipes/54-three-idioms.md +88 -0
- package/docs/recipes/55-mods-time-wrap.md +112 -0
- package/docs/recipes/56-webgpu-tsl.md +260 -0
- package/docs/recipes/57-control.md +65 -0
- package/docs/recipes/58-input.md +57 -0
- package/docs/recipes/59-depth-post-effects.md +83 -0
- package/docs/recipes/60-judge-the-picture.md +55 -0
- package/examples/action/.threedog/content-index.json +1 -0
- package/examples/action/GAMEMAP.md +17 -13
- 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/look.js +1 -1
- package/examples/action/main.js +10 -13
- package/examples/action/models.js +24 -23
- package/examples/pullable.json +111 -0
- package/examples/rc2d/.threedog/content-index.json +1 -0
- package/examples/rc2d/GAMEMAP.md +83 -0
- package/examples/rc2d/README.md +52 -0
- package/examples/rc2d/main.js +63 -0
- package/examples/rc2d/rc2d.js +197 -0
- package/examples/rc2d/shaders.js +144 -0
- package/examples/sheepisland/.threedog/content-index.json +1 -0
- package/examples/sheepisland/GAMEMAP.md +13 -11
- package/examples/sheepisland/assets.js +5 -0
- package/examples/sheepisland/main.js +17 -12
- package/examples/sheepisland/style/index.js +6 -6
- package/examples/styletest/.threedog/content-index.json +1 -0
- package/examples/styletest/GAMEMAP.md +15 -16
- package/examples/styletest/assets.js +6 -0
- package/examples/styletest/content/npcs.js +1 -1
- package/examples/styletest/content/templates.js +1 -1
- package/examples/styletest/content/vegetation.js +1 -1
- package/examples/styletest/look.js +1 -1
- package/examples/styletest/main.js +18 -17
- package/examples/styletest/models.js +1 -1
- package/examples/styletest/params.js +3 -3
- package/examples/techniques/contact-shadows/README.md +92 -0
- package/examples/techniques/contact-shadows/contactShadows.js +51 -0
- package/examples/techniques/contact-shadows/main.js +53 -0
- package/examples/techniques/day-night-grade/README.md +86 -0
- package/examples/techniques/day-night-grade/dayNightGrade.js +76 -0
- package/examples/techniques/day-night-grade/main.js +51 -0
- package/examples/techniques/interior-light/README.md +103 -0
- package/examples/techniques/interior-light/interiorLight.js +45 -0
- package/examples/techniques/interior-light/main.js +124 -0
- package/examples/techniques/modular-building/README.md +125 -0
- package/examples/techniques/modular-building/kit.js +426 -0
- package/examples/techniques/modular-building/main.js +47 -0
- package/examples/techniques/night-lights/README.md +94 -0
- package/examples/techniques/night-lights/main.js +70 -0
- package/examples/techniques/night-lights/nightLights.js +91 -0
- package/examples/techniques/outlines-and-rim/README.md +59 -0
- package/examples/techniques/outlines-and-rim/main.js +84 -0
- package/examples/techniques/outlines-and-rim/outlines.js +64 -0
- package/examples/techniques/procedural-animation/README.md +77 -0
- package/examples/techniques/procedural-animation/creature.js +44 -0
- package/examples/techniques/procedural-animation/main.js +45 -0
- package/examples/techniques/procedural-animation/proceduralAnim.js +118 -0
- package/examples/techniques/procedural-surface/README.md +67 -0
- package/examples/techniques/procedural-surface/main.js +103 -0
- package/examples/techniques/procedural-surface/surface.js +120 -0
- package/examples/techniques/stylized-shading/README.md +75 -0
- package/examples/techniques/stylized-shading/main.js +93 -0
- package/examples/techniques/stylized-shading/shading.js +131 -0
- package/examples/techniques/sun-and-key-light/README.md +135 -0
- package/examples/techniques/sun-and-key-light/keyLight.js +53 -0
- package/examples/techniques/sun-and-key-light/main.js +95 -0
- package/examples/techniques/wet-road/README.md +99 -0
- package/examples/techniques/wet-road/main.js +68 -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 +84 -0
- package/examples/webgpu-tsl/README.md +42 -0
- package/examples/webgpu-tsl/main.js +21 -0
- package/examples/webgpu-tsl/tslScene.js +75 -0
- package/examples/world/.threedog/content-index.json +1 -0
- package/examples/world/GAMEMAP.md +22 -15
- package/examples/world/art/humanoid.js +42 -0
- package/examples/world/art/index.js +11 -0
- package/examples/world/art/models.js +58 -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/npcs.js +2 -2
- 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 +17 -13
- package/examples/world/style/index.js +61 -0
- package/examples/world/style/plugins/10-bloom.js +5 -0
- package/index.d.ts +50 -45
- package/index.js +27 -22
- package/llms.txt +20 -12
- 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 +81 -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 +70 -19
- package/modules/camera/contract.js +17 -0
- package/modules/camera/projection.js +11 -24
- package/modules/characters/Character.js +196 -59
- package/modules/characters/NPC.js +87 -36
- package/modules/characters/assetModel.js +27 -8
- 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 +87 -49
- package/modules/characters/moveHelpers.js +4 -5
- package/modules/characters/movers/common.js +97 -19
- package/modules/characters/movers/manual.js +20 -0
- package/modules/characters/movers/rapier.js +19 -16
- package/modules/characters/movers/simple.js +14 -11
- package/modules/characters/movers/support.js +172 -0
- package/modules/characters/npcAvoid.js +47 -42
- package/modules/characters/npcSim.js +12 -8
- 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 +46 -10
- package/modules/characters/useModel.js +1 -1
- package/modules/characters/vehicle.contract.js +21 -0
- package/modules/characters/walkTo.js +21 -7
- package/modules/collision/Collision.js +65 -25
- 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 +97 -28
- package/modules/content/loader.js +45 -33
- package/modules/content/models.js +11 -40
- package/modules/content/packs.js +6 -5
- package/modules/content/parts.js +41 -0
- package/modules/content/props.js +16 -9
- package/modules/content/rules.js +58 -0
- package/modules/content/stages.js +80 -0
- package/modules/content/templates.js +121 -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 +193 -67
- package/modules/gameplay/Inventory.js +69 -73
- 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 +18 -16
- package/modules/gameplay/pickups.js +268 -85
- package/modules/gameplay/questLog.js +4 -4
- package/modules/gameplay/quests.contract.js +17 -0
- package/modules/grid/Grid.js +92 -50
- package/modules/grid/Layer.js +14 -13
- package/modules/grid/index.js +60 -36
- package/modules/grid/ops.js +20 -18
- package/modules/grid/preview.js +15 -16
- package/modules/grid/strings.js +12 -0
- package/modules/grid/tiles.js +6 -5
- package/modules/hlod/index.js +51 -19
- package/modules/hud/index.js +35 -20
- package/modules/hud/parts.js +20 -7
- package/modules/level/heightfield.js +3 -1
- package/modules/level/index.js +45 -20
- package/modules/level/nodes.js +4 -3
- package/modules/lights/index.js +42 -18
- 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 +23 -14
- package/modules/particles/contract.js +17 -0
- package/modules/particles/effect.js +39 -11
- package/modules/photo/Photo.js +53 -36
- 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 +57 -52
- 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 +88 -176
- package/modules/sky/cascades.js +86 -25
- package/modules/sky/cascades.tsl.js +82 -0
- package/modules/sky/clouds.js +34 -19
- package/modules/sky/domeLayers.js +30 -15
- package/modules/sky/environment.js +83 -13
- package/modules/sky/fog.js +140 -95
- package/modules/sky/frame.js +112 -44
- package/modules/sky/look.js +22 -19
- package/modules/sky/lookFog.js +48 -52
- package/modules/sky/lookShadow.js +53 -41
- package/modules/sky/lookSky.js +82 -21
- package/modules/sky/season.js +21 -0
- package/modules/sky/shader.js +41 -19
- package/modules/sky/shadow.js +44 -20
- package/modules/sky/skyModule.js +45 -33
- package/modules/sky/tint.js +61 -0
- package/modules/terrain/ChunkManager.js +175 -108
- package/modules/terrain/chunkJob.js +1 -1
- package/modules/terrain/chunkQueries.js +6 -4
- package/modules/terrain/index.js +105 -50
- package/modules/terrain/look.js +83 -0
- package/modules/terrain/lookGround.js +21 -16
- package/modules/terrain/terrainDefaults.js +1 -1
- package/modules/terrain/terrainEdit.js +18 -20
- package/modules/terrain/terrainGen.js +5 -3
- 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 +107 -76
- package/modules/vegetation/Vegetation.js +190 -102
- package/modules/vegetation/densityMap.js +62 -0
- package/modules/vegetation/groundChunks.js +52 -58
- package/modules/vegetation/index.js +31 -10
- package/modules/vegetation/look.js +119 -0
- package/modules/vegetation/lookWind.js +71 -10
- package/modules/vegetation/modelGeometry.js +3 -2
- package/modules/vegetation/nearFade.js +45 -0
- package/modules/water/Water.js +65 -27
- package/modules/water/look.js +29 -18
- package/modules/water/surface.js +64 -25
- package/modules/water/surfaceDefaults.js +3 -0
- package/modules/weather/Weather.js +62 -104
- package/modules/weather/look.js +1 -2
- package/modules/weather/particles.js +24 -9
- package/modules/weather/strings.js +2 -2
- package/modules/weather/weatherLook.js +135 -0
- package/modules/world/World.js +24 -7
- 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 +7 -5
- package/package.json +8 -3
- package/presets.js +41 -27
- package/render/PostFX.js +145 -120
- package/render/backend.js +440 -0
- package/render/detail.js +150 -45
- package/render/effects.js +130 -38
- package/render/engineUniforms.js +10 -1
- package/render/fuse.js +5 -4
- package/render/fx/cloudShadow.tsl.js +16 -0
- package/render/fx/detail.tsl.js +66 -0
- package/render/fx/index.js +26 -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 +158 -0
- package/render/fx/season.tsl.js +13 -0
- package/render/fx/sky.tsl.js +260 -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/lighting.js +66 -14
- package/render/lights.js +223 -4
- package/render/lookGlow.js +139 -0
- package/render/lookSurface.js +99 -36
- package/render/materials.js +71 -52
- package/render/modeling.js +73 -0
- package/render/ownFrame.js +76 -0
- package/render/patches.js +311 -34
- package/render/postLook.js +124 -46
- package/render/postWebGL.js +197 -0
- package/render/probes.js +231 -0
- package/render/shaderErrors.js +154 -0
- package/render/slots.js +165 -0
- package/render/surface.js +53 -17
- package/render/terms.js +211 -0
- package/render/uniformDecl.js +3 -2
- package/types/common.d.ts +2 -2
- package/types/core.d.ts +620 -244
- package/types/gameplay.d.ts +494 -318
- 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 +44 -3
- package/types/generated/core/I18n.d.ts +2 -2
- package/types/generated/core/Input.d.ts +102 -31
- 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/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 +5 -5
- package/types/generated/modules/grid/index.d.ts +29 -17
- 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 +1 -1
- package/types/generated/modules/sky/Sky.d.ts +12 -104
- package/types/generated/modules/sky/skyModule.d.ts +1 -1
- package/types/generated/modules/timeline/Timeline.d.ts +8 -6
- package/types/generated/modules/weather/Weather.d.ts +17 -18
- package/types/generated/modules/weather/weatherLook.d.ts +12 -0
- package/types/generated/modules/world/World.d.ts +18 -3
- package/types/generated/render/PostFX.d.ts +67 -30
- package/types/generated/render/materials.d.ts +26 -20
- package/types/generated/render/modeling.d.ts +30 -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 +137 -44
- package/types/style.d.ts +125 -92
- package/types/tsl.d.ts +86 -0
- package/types/world.d.ts +164 -110
- package/ui/Focus.js +25 -14
- package/ui/LoadingScreen.js +1 -1
- package/ui/Parts.js +27 -11
- package/ui/UI.js +20 -10
- package/ui/cursor.js +115 -0
- package/ui/defaults.js +15 -11
- package/ui/theme.js +9 -6
- package/ui/touchPart.js +1 -1
- package/core/claims.js +0 -51
- package/core/look/layers.js +0 -136
- package/core/renamed.js +0 -21
- package/docs/api/entities.md +0 -61
- package/docs/recipes/09-style-pack.md +0 -234
- 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/layers.js +0 -69
- package/modules/terrain/chunkLevels.js +0 -40
- package/modules/terrain/mountTerrain.js +0 -32
- package/modules/world/cells.js +0 -42
package/core/opsRun.js
CHANGED
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
import { DEV } from './validate.js';
|
|
4
4
|
import { devError, fmt, argRange } from './opsCheck.js';
|
|
5
5
|
import { reportError } from './errors.js';
|
|
6
|
-
import { failure, isRunFailure } from './opsFail.js';
|
|
6
|
+
import { failure, isRunFailure, opsBlocked } from './opsFail.js';
|
|
7
7
|
import { snapshot, rollback, markRolledBack } from './opsAtomic.js';
|
|
8
8
|
import { withDefaults } from './params.js';
|
|
9
9
|
|
|
10
10
|
const MAX_DEPTH = 16;
|
|
11
|
-
|
|
11
|
+
const RUN_STRINGS = {
|
|
12
12
|
canRun: "{name}'s can called ops.run('{inner}'). can is read-only; call other ops from run",
|
|
13
13
|
loop: 'ops call each other in a loop (deeper than ' + MAX_DEPTH + '): {chain}',
|
|
14
14
|
};
|
|
@@ -31,7 +31,8 @@ export function runOp(ops, name, args, opts) {
|
|
|
31
31
|
const parent = ops._stack.length ? ops._last : null;
|
|
32
32
|
const ctx = ops._ctx(name, args, opts, parent);
|
|
33
33
|
const depth = ops._stack.length, ev = e.events, where = `ops.run('${name}')`;
|
|
34
|
-
|
|
34
|
+
const blocked = opsBlocked(e);
|
|
35
|
+
if (blocked) { ops._log(name, args, ctx, false, blocked, depth); return ops._res(failure(blocked)); }
|
|
35
36
|
if (DEV && args && typeof args === 'object') Object.freeze(args);
|
|
36
37
|
const failed = (f, h) => { // a failed run: log it, trace it with its code
|
|
37
38
|
if (h) { h.ok = false; h.code = f.code; } else ops._log(name, args, ctx, false, f.code, depth);
|
package/core/owned.js
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
// One ownership model for every property the engine writes on its own (sky lights, fog, exposure, background, camera, pixel ratio ...).
|
|
2
|
+
//
|
|
3
|
+
// const o = defineOwned(engine, { id: 'sun.intensity', part: 'lights', key: 'sun.intensity', read: () => sun.intensity,
|
|
4
|
+
// levels: { manual: "engine.look.lights.manual('sun')", set: "engine.look.lights.set({ sun: { intensity: 2 } })" } });
|
|
5
|
+
// per frame: o.check(); if (o.on) sun.intensity = v; o.mark(); (or o.drive(v) when the write is one value: needs write)
|
|
6
|
+
//
|
|
7
|
+
// Why "the engine yields" (user decision 1, 2026-11-02): a game that writes engine.lights.sun.intensity directly means it. Silently writing the old value
|
|
8
|
+
// back every frame is the "my change does nothing" bug; warning and still overwriting only moves it. So the first outside write hands the property
|
|
9
|
+
// to the game (mode 'yielded'), the value stays, and one warning names the explicit takeover and the hand-back. Detection runs in release builds too
|
|
10
|
+
// (a few number compares per frame), so the game behaves the same with and without dev checks; only the warning text is dev-only.
|
|
11
|
+
//
|
|
12
|
+
// Modes per property: 'engine' (the engine writes it) | 'manual' (look.<part>.manual(key), look.<part>.replace(...) where it hands the value to the game) | 'yielded'
|
|
13
|
+
// (the game wrote it directly). look.<part>.manual(key, false) hands any of them back. describe().owned lists them all.
|
|
14
|
+
import { warnOnce, DEV } from './validate.js';
|
|
15
|
+
import { codedError, coded } from './errorHints.js';
|
|
16
|
+
|
|
17
|
+
const STRINGS = { // yielded: the prefix up to "stopped writing it" is matched by tests (the owned-prop tag carries the fix); the rest leads with the next calls
|
|
18
|
+
yielded: '{id} was changed outside the engine, so the engine stopped writing it (your value stays). Next: {manual} to own it on purpose (no warning);{set} ' +
|
|
19
|
+
'{back} to give it back to the engine',
|
|
20
|
+
set: ' {set} to let the engine drive it and only adjust it;',
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// Page-wide like the rest of the dev checks (validate.js): a tween anywhere names the objects it animates, and only properties on those objects
|
|
24
|
+
// skip detection. Why per object, not per owner: one owner-wide exemption would switch every check off (a tween on a door would turn off the sky guard).
|
|
25
|
+
const exempt = new Map(); // owner -> Set of ids (strings) and objects
|
|
26
|
+
const live = new Set(); // every registered property on the page: ending an exemption re-reads the ones it covered
|
|
27
|
+
/**
|
|
28
|
+
* Exempt properties from outside-write detection while owner animates them (a timeline tweening a light): neither a warning nor a yield.
|
|
29
|
+
* @param {string} owner @param {Iterable<any> | false} [what] owned ids ('sun.intensity') or the three.js objects being animated; false ends it
|
|
30
|
+
*/
|
|
31
|
+
export function allowOwned(owner, what) {
|
|
32
|
+
if (what === false || what == null) {
|
|
33
|
+
// the animation's last value is the game's choice, not an outside write: take it as the new reference
|
|
34
|
+
const s = exempt.get(owner); exempt.delete(owner);
|
|
35
|
+
if (s) for (const o of live) if (o._snap && covers(s, o)) o.mark();
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
exempt.set(owner, new Set(what));
|
|
39
|
+
}
|
|
40
|
+
const covers = (s, entry) => s.has(entry.id) || entry.objects.some(o => s.has(o));
|
|
41
|
+
function isExempt(entry) {
|
|
42
|
+
for (const s of exempt.values()) if (covers(s, entry)) return true;
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const flat = v => [].concat(v);
|
|
47
|
+
const differs = (a, b) => a.length !== b.length || a.some((x, i) => x !== b[i]);
|
|
48
|
+
|
|
49
|
+
class Owned {
|
|
50
|
+
constructor(e, spec) {
|
|
51
|
+
/** @type {string} */ this.id = spec.id;
|
|
52
|
+
/** @type {string} */ this.part = spec.part;
|
|
53
|
+
/** @type {string} */ this.key = spec.key ?? spec.id;
|
|
54
|
+
/** @type {{ set?: string, manual?: string, back?: string }} */ this.levels = spec.levels ?? {};
|
|
55
|
+
this._read = spec.read; this._write = spec.write; this._e = e;
|
|
56
|
+
/** objects this property lives on (allowOwned matches them) */ this.objects = spec.objects ?? [];
|
|
57
|
+
/** 'engine' | 'manual' | 'yielded' */ this.mode = 'engine';
|
|
58
|
+
/** who took it: 'game' (manual()), or 'three' for a direct write */ this.by = 'engine';
|
|
59
|
+
this._snap = null;
|
|
60
|
+
this._onChange = spec.onChange;
|
|
61
|
+
// once: the engine writes it once, at creation (renderer.toneMapping), and no look.<part>.set ever writes it. So a direct write is the documented
|
|
62
|
+
// way to change it (yielding warns nothing), markOwned after a set of the same part must not re-read it (that swallowed a game's direct
|
|
63
|
+
// write: describe said 'style' for a curve the game had set), and handing it back writes the creation value again (spec.write)
|
|
64
|
+
this._once = spec.once ? { value: this._read() } : null;
|
|
65
|
+
}
|
|
66
|
+
/** Does the engine write this property now */
|
|
67
|
+
get on() { return this.mode === 'engine'; }
|
|
68
|
+
/** Before the engine writes: a value different from the last mark() was written by someone else, so yield to it (once per takeover) */
|
|
69
|
+
check() {
|
|
70
|
+
if (this.mode !== 'engine' || !this._snap) return;
|
|
71
|
+
const v = flat(this._read());
|
|
72
|
+
if (!differs(v, this._snap) || isExempt(this)) return;
|
|
73
|
+
this._set('yielded', 'three');
|
|
74
|
+
if (DEV && this._e.validate && !this._once) {
|
|
75
|
+
const L = this.levels, back = L.back ?? L.manual.replace(/\(([^()]*)\)\s*$/, (_, a) => `(${a ? a + ', ' : ''}false)`);
|
|
76
|
+
warnOnce(coded('owned-prop', STRINGS.yielded.replace('{id}', this.id).replace('{manual}', L.manual)
|
|
77
|
+
.replace('{set}', L.set ? STRINGS.set.replace('{set}', L.set) : '').replace('{back}', back)));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/** After the engine wrote (or chose not to): remember what is there now */
|
|
81
|
+
mark() { this._snap = flat(this._read()); }
|
|
82
|
+
/** check, write when the engine owns it, mark. Needs spec.write */
|
|
83
|
+
drive(v) { this.check(); if (this.on) this._write(v); this.mark(); }
|
|
84
|
+
/** Take over (on) or hand back (false). Hand-back forgets the snapshot so the engine's next write is not mistaken for an outside one */
|
|
85
|
+
manual(on = true, by = 'game') {
|
|
86
|
+
if (on) this._set('manual', by);
|
|
87
|
+
else if (this._once) { this._write?.(this._once.value); this._set('engine', 'engine'); this.mark(); } // nothing writes it per frame: write it back now
|
|
88
|
+
else { this._snap = null; this._set('engine', 'engine'); }
|
|
89
|
+
}
|
|
90
|
+
_set(mode, by) {
|
|
91
|
+
const was = this.mode;
|
|
92
|
+
this.mode = mode; this.by = by; this.at = this._e.time?.frame ?? null;
|
|
93
|
+
if (was !== mode) { this._onChange?.(this); this._point(mode); }
|
|
94
|
+
}
|
|
95
|
+
/** @internal tell the look value's shared point (look.<part>.<key>, prefix match: 'sun' covers sun.intensity): a direct write or a manual()
|
|
96
|
+
* takes it from the layers, so describe().shared says writer 'three (engine yielded)'; handing it back reclaims it */
|
|
97
|
+
_point(mode) {
|
|
98
|
+
const S = this._e.stacks, pre = `look.${this.part}.${this.key}`;
|
|
99
|
+
if (!S) return;
|
|
100
|
+
for (const n of S.list()) if (n === pre || n.startsWith(pre + '.')) mode === 'engine' ? S.get(n).reclaim() : S.get(n).yieldToThree(mode === 'manual' ? `manual:${this.by}` : null);
|
|
101
|
+
}
|
|
102
|
+
/** describe().owned row: writer = who writes it now ('engine' | 'manual:<who>' | 'three (engine yielded)'); the old field name `by` throws */
|
|
103
|
+
info() { return ({ part: this.part, key: this.key, writer: this.mode === 'engine' ? 'engine' : this.mode === 'yielded' ? 'three (engine yielded)' : `manual:${this.by}`, ...(this.levels.manual ? { manual: this.levels.manual } : {}) }); }
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Register one engine-written property. The id is unique per engine (a second defineOwned with the same id replaces the first: a module reinstalled).
|
|
108
|
+
* @param {any} engine
|
|
109
|
+
* @param {{ id: string, part: string, key?: string, read: () => any, write?: (v: any) => void, objects?: any[],
|
|
110
|
+
* levels: { manual: string, set?: string, replace?: string, back?: string }, onChange?: (o: Owned) => void, once?: boolean }} spec
|
|
111
|
+
* part: the look part whose manual() takes it (engine.look.<part>.manual(key)); key: the name manual() matches (prefix match on dots: 'sun' takes
|
|
112
|
+
* 'sun.intensity' and 'sun.color'); once: written only at creation (read now is the creation value; needs write for the hand-back); levels: the copyable calls the warning quotes (manual is required); onChange: mode changed (the sky hides its dome when the game
|
|
113
|
+
* takes scene.background)
|
|
114
|
+
* @returns {Owned}
|
|
115
|
+
*/
|
|
116
|
+
export function defineOwned(engine, spec) {
|
|
117
|
+
if (!spec?.id || !spec.part || typeof spec.read !== 'function') throw codedError('owned-misuse', 'defineOwned(engine, { id, part, read, write?, levels }): id, part and read are required');
|
|
118
|
+
// the yield warning leads with this call, so a property nobody can take on purpose cannot be registered
|
|
119
|
+
if (typeof spec.levels?.manual !== 'string' || !spec.levels.manual) throw codedError('owned-misuse', `defineOwned(engine, { id: '${spec.id}', levels: { manual } }): levels.manual is required, the copyable takeover call the warning quotes, e.g. levels: { manual: "engine.look.${spec.part}.manual('${spec.key ?? spec.id}')" }`);
|
|
120
|
+
const reg = engine._owned ??= new Map();
|
|
121
|
+
const o = new Owned(engine, spec);
|
|
122
|
+
const old = reg.get(spec.id); if (old) live.delete(old);
|
|
123
|
+
reg.set(spec.id, o); live.add(o);
|
|
124
|
+
return o;
|
|
125
|
+
}
|
|
126
|
+
/** Remove registrations (a module disposed) @param {any} engine @param {Iterable<{ id: string }>} list */
|
|
127
|
+
export function dropOwned(engine, list) { for (const o of list) { live.delete(o); if (engine._owned?.get(o.id) === o) engine._owned.delete(o.id); } }
|
|
128
|
+
|
|
129
|
+
/** Re-read every registered property of a part (after a look.<part>.set wrote them on the game's request) */
|
|
130
|
+
export function markOwned(engine, part) { for (const o of engine._owned?.values() ?? []) if (o.part === part && o._snap && !o._once) o.mark(); }
|
|
131
|
+
|
|
132
|
+
/** Registered properties of one part whose key is `key` or starts with `key.` (no keys: all of the part) */
|
|
133
|
+
export function ownedOf(engine, part, keys) {
|
|
134
|
+
const all = [...(engine._owned?.values() ?? [])].filter(o => o.part === part);
|
|
135
|
+
if (keys == null) return all;
|
|
136
|
+
return all.filter(o => [].concat(keys).some(k => o.key === k || o.key.startsWith(k + '.')));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* look.<part>.manual(keys?, on?): the game takes these properties (the engine stops writing them) or hands them back (on false).
|
|
141
|
+
* Throws with the part's takeable keys when nothing matches, so a typo does not silently do nothing.
|
|
142
|
+
* @returns {{ remove(): void }} remove() hands them back
|
|
143
|
+
*/
|
|
144
|
+
export function manualVerb(engine, part, keys, on = true, by = 'game') {
|
|
145
|
+
if (typeof keys === 'boolean') { on = keys; keys = undefined; }
|
|
146
|
+
const hit = ownedOf(engine, part, keys);
|
|
147
|
+
if (!hit.length) {
|
|
148
|
+
const known = [...new Set(ownedOf(engine, part).map(o => o.key))];
|
|
149
|
+
throw codedError('owned-misuse', `engine.look.${part}.manual(${keys === undefined ? '' : JSON.stringify(keys)}): ${known.length ? `no engine-written key matches; keys: ${known.join(', ')}` : 'the engine writes nothing of this part on its own right now (nothing to take over)'}`);
|
|
150
|
+
}
|
|
151
|
+
for (const o of hit) o.manual(on, by);
|
|
152
|
+
return { remove: () => { for (const o of hit) o.manual(false); } };
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** describe().owned: { id: { part, key, writer, manual? } } (undefined when nothing is registered) */
|
|
156
|
+
export function describeOwned(engine) {
|
|
157
|
+
const extra = Object.entries(engine._ownedRows ?? {}).map(([id, f]) => [id, f()]).filter(([, r]) => r);
|
|
158
|
+
if (!engine._owned?.size && !extra.length) return undefined;
|
|
159
|
+
return Object.fromEntries([...[...engine._owned ?? []].map(([id, o]) => [id, o.info()]), ...extra]);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* A describe().owned row that is not one property: the engine changing things the game made (the cascades' csm patch on game materials, the one
|
|
163
|
+
* named exception to "the engine does not change what it did not create"). row() returns undefined while there is nothing to show.
|
|
164
|
+
* @param {any} engine @param {string} id @param {() => (object | undefined)} row
|
|
165
|
+
*/
|
|
166
|
+
export function ownedRow(engine, id, row) { (engine._ownedRows ??= {})[id] = row; }
|
|
167
|
+
/** Remove an ownedRow (its module disposed) @param {any} engine @param {string} id */
|
|
168
|
+
export function dropOwnedRow(engine, id) { if (engine._ownedRows) delete engine._ownedRows[id]; }
|
package/core/page.js
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
// WebGL context lost (driver reset, GPU memory pressure): gameplay waits and the player sees a message; three.js restores the context itself and play resumes.
|
|
10
10
|
import { coded } from './errorHints.js';
|
|
11
11
|
import { toast } from '../ui/UI.js';
|
|
12
|
+
import { warnOnce } from './validate.js';
|
|
12
13
|
|
|
13
14
|
const STRINGS = {
|
|
14
15
|
'zh-CN': { 'page.gpuLost': '图形设备暂时不可用,正在恢复……如果画面一直不恢复,请刷新页面', 'page.gpuBack': '画面已恢复' },
|
|
@@ -45,7 +46,7 @@ export class Page {
|
|
|
45
46
|
canvas.addEventListener('webglcontextlost', ev => {
|
|
46
47
|
ev.preventDefault(); // tells the browser we want the context back
|
|
47
48
|
this.contextLost = true;
|
|
48
|
-
|
|
49
|
+
warnOnce(coded('webgl-lost', DEV.lost));
|
|
49
50
|
toast(engine, engine.t('page.gpuLost'), { kind: 'error', ms: 8000 });
|
|
50
51
|
engine.events.emit('page:contextlost');
|
|
51
52
|
}, { signal });
|
package/core/params.js
CHANGED
|
@@ -3,26 +3,39 @@
|
|
|
3
3
|
// catalog and the dev bridge cannot disagree about a field (no second copy in docs or TypeScript).
|
|
4
4
|
// short form: 'int' / 'int?' (type, ? = optional)
|
|
5
5
|
// full form: { type: 'int', default: 1, min: 1, max: 99, values: [...], desc: 'how many', optional: true } (default implies optional)
|
|
6
|
+
// several shapes: 'bool|object' (any of them; e.g. createEngine's batching: false or { ... }), checked like one type
|
|
6
7
|
import { closest, fmt, DEV, warnOnce, unknownOptionText } from './validate.js';
|
|
7
8
|
import { codedError, coded } from './errorHints.js';
|
|
8
9
|
|
|
9
10
|
/** Types an op arg may use: plain data only. Two meanings of 'id' on purpose: as a module param it is any string; as an op arg it must also be a world record id (checked in dev by opsCheck) */
|
|
10
11
|
export const OP_TYPES = ['string', 'number', 'int', 'bool', 'position', 'id', 'any'];
|
|
11
|
-
|
|
12
|
+
// 'color': 0xRRGGBB or '#rrggbb' (a model generator's params, shown as a color picker in the dev panel); not an op arg type
|
|
13
|
+
const TYPES = ['string', 'number', 'int', 'bool', 'position', 'id', 'any', 'object', 'array', 'function', 'color'];
|
|
12
14
|
const SPEC_KEYS = ['type', 'default', 'min', 'max', 'values', 'desc', 'optional'];
|
|
13
15
|
const isPos = v => Array.isArray(v) && (v.length === 2 || v.length === 3) && v.every(Number.isFinite);
|
|
14
16
|
/** type name -> value check (op args use the first seven: plain data only) */
|
|
15
|
-
|
|
17
|
+
const CHECK = {
|
|
16
18
|
string: v => typeof v === 'string', number: v => Number.isFinite(v), int: v => Number.isInteger(v), bool: v => typeof v === 'boolean',
|
|
17
19
|
position: isPos, id: v => typeof v === 'string', any: () => true, object: v => !!v && typeof v === 'object' && !Array.isArray(v),
|
|
18
20
|
array: Array.isArray, function: v => typeof v === 'function',
|
|
21
|
+
color: v => (Number.isInteger(v) && v >= 0 && v <= 0xffffff) || (typeof v === 'string' && /^#[0-9a-f]{6}$/i.test(v)),
|
|
19
22
|
};
|
|
23
|
+
const unions = new Map();
|
|
24
|
+
/** The value check of a type name or a 'a|b' union (one cached function per union) */
|
|
25
|
+
export const checkOf = type => CHECK[type] ?? unions.get(type) ?? (unions.set(type, (fs => v => fs.some(f => f(v)))(type.split('|').map(t => CHECK[t]))), unions.get(type));
|
|
20
26
|
const STRINGS = {
|
|
21
27
|
badType: "{where}: {key} has type '{type}'; use one of {list} (add ? for optional, e.g. 'int?', or { type: 'int', default: 1 })",
|
|
22
28
|
badSpec: '{where}: {key} has unknown schema field {field}{hint}; schema fields: ' + SPEC_KEYS.join(', '),
|
|
23
29
|
badDefault: '{where}: the default of {key} ({got}) does not fit its own schema: {why}',
|
|
24
30
|
wrong: '{where}: {key} {why}',
|
|
31
|
+
notOptions: '{where}: the options argument must be an object { … }, got {got}. API convention: a position is one argument, and size and the like go in the options object',
|
|
25
32
|
};
|
|
33
|
+
// Why cache: public APIs (collision.addCircle, particles.emit ...) call readParams on every call; the same schema object is parsed once;
|
|
34
|
+
// a literal schema written fresh each call is not cached (WeakMap keys by object, collected after use), it is just parsed once more
|
|
35
|
+
const parsed = new WeakMap(), keyCache = new WeakMap();
|
|
36
|
+
/** Is o an options object (not a number, string, array, Three.js object or vector)? Data checks use it where a field may also be a name or a list */
|
|
37
|
+
export const isOptions = o => !!o && typeof o === 'object' && !Array.isArray(o) && !o.isObject3D && !o.isVector3 && !o.isColor;
|
|
38
|
+
const parsedOf = (where, schema) => { let s = parsed.get(schema); if (!s) { s = parseSchema(where, schema); parsed.set(schema, s); } return s; };
|
|
26
39
|
|
|
27
40
|
/** Parse one field spec ('int?' or { type, default, ... }) into { type, optional, default?, min?, max?, values?, desc? }; throws on a bad spec */
|
|
28
41
|
export function parseSpec(where, key, spec, err = codedError.bind(null, 'engine-misuse')) {
|
|
@@ -34,7 +47,7 @@ export function parseSpec(where, key, spec, err = codedError.bind(null, 'engine-
|
|
|
34
47
|
}
|
|
35
48
|
s.optional = !!s.optional || 'default' in s;
|
|
36
49
|
}
|
|
37
|
-
if (!TYPES.includes(
|
|
50
|
+
if (typeof s.type !== 'string' || !s.type.split('|').every(t => TYPES.includes(t))) throw err(fmt(STRINGS.badType, { where, key, type: String(s.type ?? spec), list: TYPES.join(' ') }));
|
|
38
51
|
if ('default' in s) { const why = whyBad(s, s.default); if (why) throw err(fmt(STRINGS.badDefault, { where, key, got: JSON.stringify(s.default), why })); }
|
|
39
52
|
return s;
|
|
40
53
|
}
|
|
@@ -49,7 +62,7 @@ export function parseSchema(where, schema, err) {
|
|
|
49
62
|
|
|
50
63
|
/** Why v does not fit the parsed spec s (type, range, allowed values), or null when it does */
|
|
51
64
|
export function whyBad(s, v) {
|
|
52
|
-
if (!
|
|
65
|
+
if (!checkOf(s.type)(v)) return `should be ${s.type === 'position' ? '[x, y, z]' : s.type.replaceAll('|', ' or ')}, got ${JSON.stringify(v) ?? typeof v}`;
|
|
53
66
|
if (s.min != null && v < s.min) return `must be >= ${s.min}, got ${v}`;
|
|
54
67
|
if (s.max != null && v > s.max) return `must be <= ${s.max}, got ${v}`;
|
|
55
68
|
if (s.values && !s.values.includes(v)) return `must be one of ${s.values.map(x => JSON.stringify(x)).join(', ')}, got ${JSON.stringify(v)}`;
|
|
@@ -76,7 +89,7 @@ export function schemaInfo(shape) {
|
|
|
76
89
|
if (!shape) return null;
|
|
77
90
|
const out = {};
|
|
78
91
|
for (const key in shape) {
|
|
79
|
-
const s = shape[key], o = { type: s.type };
|
|
92
|
+
const s = shape[key], o = /** @type {Record<string, any>} */ ({ type: s.type });
|
|
80
93
|
if (s.optional) o.optional = true;
|
|
81
94
|
for (const f of ['default', 'min', 'max', 'values', 'desc']) if (s[f] !== undefined && typeof s[f] !== 'function') o[f] = s[f];
|
|
82
95
|
out[key] = o;
|
|
@@ -95,11 +108,17 @@ export function schemaInfo(shape) {
|
|
|
95
108
|
* const PARAMS = { radius: { type: 'number', default: 2, min: 0, desc: 'pickup reach in m' }, sound: 'string?' };
|
|
96
109
|
* export const magnet = (opts) => {
|
|
97
110
|
* const o = readParams('magnet', PARAMS, opts);
|
|
98
|
-
* return { name: 'magnet', params: PARAMS, options: o, install(e) { return { radius: o.radius }; } };
|
|
111
|
+
* return { name: 'magnet', type: 'rules', params: PARAMS, options: o, install(e) { return { radius: o.radius }; } };
|
|
99
112
|
* };
|
|
100
113
|
*/
|
|
101
114
|
export function readParams(where, schema, opts = {}) {
|
|
102
|
-
const shape =
|
|
115
|
+
const shape = parsedOf(where, schema), err = msg => codedError('module-params', msg);
|
|
116
|
+
if (opts != null && !isOptions(opts)) {
|
|
117
|
+
// A number / string / array in the options slot: most likely the old positional-argument style. Same rule as unknown keys (throw in dev, warn once in release and treat as not passed)
|
|
118
|
+
const msg = fmt(STRINGS.notOptions, { where, got: JSON.stringify(opts) ?? typeof opts });
|
|
119
|
+
if (DEV) throw err(msg);
|
|
120
|
+
warnOnce(coded('module-params', msg)); opts = {};
|
|
121
|
+
}
|
|
103
122
|
const out = withDefaults(defaultsOf(shape), opts ?? {}); // checked in every build: it runs once per factory call, and a wrong option is a bug anywhere
|
|
104
123
|
const keys = Object.keys(shape);
|
|
105
124
|
for (const key of Object.keys(out)) if (!shape[key]) {
|
|
@@ -125,7 +144,10 @@ export function readParams(where, schema, opts = {}) {
|
|
|
125
144
|
* @param {Record<string, any>} [defaults] defaults shown in the catalog (not applied: the module's own code still does that)
|
|
126
145
|
* @param {Record<string, any>} [specs]
|
|
127
146
|
*/
|
|
128
|
-
export function keysSchema(keys, defaults
|
|
147
|
+
export function keysSchema(keys, defaults, specs) {
|
|
148
|
+
// With only a key table, cache by the array object: a module-level KEYS constant gives the same schema on every call, so the readParams parse cache hits too (hot paths like particles.emit do not re-parse)
|
|
149
|
+
if (!defaults && !specs) { let s = keyCache.get(keys); if (!s) keyCache.set(keys, s = keysSchema(keys, {}, {})); return s; }
|
|
150
|
+
defaults ??= {}; specs ??= {};
|
|
129
151
|
const out = {};
|
|
130
152
|
for (const k of keys) out[k] = specs[k] ?? (defaults[k] !== undefined ? { type: 'any', default: defaults[k] } : 'any?');
|
|
131
153
|
return out;
|
package/core/plugins.js
ADDED
|
@@ -0,0 +1,277 @@
|
|
|
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.look.post.add(pass, { name: <file name> })
|
|
5
|
+
// post effect { name, create | node | fuse } -> engine.look.post.add(effect) (create for WebGL, node for WebGPU: one file runs on both)
|
|
6
|
+
// Material -> engine.look.materials.replace(role, mat) role = mat.name, else the file name
|
|
7
|
+
// ShaderPatch { slot, glsl|tsl } -> engine.look.materials.add(<file>, spec, { roles })
|
|
8
|
+
// module { name, type, install / init } -> engine.use(mod)
|
|
9
|
+
// an array of those -> each one, in array order
|
|
10
|
+
// 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
|
|
11
|
+
// 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
|
|
12
|
+
// 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,
|
|
13
|
+
// it only saves the registration lines, so everything a hand-written call gets (describe, layering, remove) a plugin gets too.
|
|
14
|
+
// Which export: the default export when there is one (named exports are then free for helpers), else every named export in order.
|
|
15
|
+
// Order: by file name (10-fog.js before 20-bloom.js), or plugins/plugins.json { "order": [...], "off": [...] }. Nothing is sorted behind
|
|
16
|
+
// the game's back: describe().slots lists the order used.
|
|
17
|
+
// Off: plugins.json "off" (no code change), or engine.plugins.off(name) at run time; on(name) plugs it again.
|
|
18
|
+
// A style pack is a bundle of the same plugins (style.plugins, core/styleParts.js stylePlugins): plugged here first, through this same code, named
|
|
19
|
+
// '<pack>/<file>', with materials and material patches on the style layer so the game, effects and settings still win; off('<pack>') takes the pack's out
|
|
20
|
+
// (its plugins only: the pack's starting values, style.exposure / fog / materials table, are the style itself and stay).
|
|
21
|
+
// Owners: every plugin is its own owner ('plugin:<file>', 'style:<pack>/<file>'); the pack only groups them. Why: with one owner per pack, B's
|
|
22
|
+
// remove dropped the key A had written too (A said on, the base came back). Two plugins writing one key on one layer is a shared-conflict naming
|
|
23
|
+
// both, unless one file says `export const replaces = '<other file>'` (then the other is unplugged while this one is on).
|
|
24
|
+
// Reach: a post effect, an object, a module change the picture at once ('live'); a material / material patch changes what makeMaterial makes
|
|
25
|
+
// NEXT ('new materials only'), so off / on rebuilds the materials already made (engine.look.materials.rebuild(); { rebuild: false } skips it).
|
|
26
|
+
// Places: a post effect keeps the place it first got (its name is reserved in plugin order), so off / on never reorders the chain.
|
|
27
|
+
// Why not a second loader for styles: one path means a plugin file works alone in plugins/ or inside any number of style packs, unchanged.
|
|
28
|
+
import { codedError } from './errorHints.js';
|
|
29
|
+
import { stylePlugins } from './styleParts.js';
|
|
30
|
+
import { MODULE_TYPES } from './moduleTypes.js';
|
|
31
|
+
|
|
32
|
+
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), ' +
|
|
33
|
+
'a Material (look.materials role = material.name or the file name), a ShaderPatch { slot, glsl | tsl, roles? } (look.materials.add), ' +
|
|
34
|
+
"a module { name, type, install / init } (engine.use), or an array of these. Export it as default (export default new THREE.Mesh(...))";
|
|
35
|
+
|
|
36
|
+
/** Which slot a value plugs into, or null when it is none of the accepted shapes */
|
|
37
|
+
function shapeOf(v) {
|
|
38
|
+
if (v?.isObject3D) return 'scene';
|
|
39
|
+
if (v?.isMaterial) return 'material';
|
|
40
|
+
if (v && typeof v === 'object') {
|
|
41
|
+
if (typeof v.render === 'function' && 'needsSwap' in v) return 'post'; // three's Pass base class sets needsSwap: a Pass, not a module with render()
|
|
42
|
+
if (typeof v.name === 'string' && v.type && (v.install || v.init || v.fixed || v.frame || v.dispose)) return 'module';
|
|
43
|
+
if (typeof v.name === 'string' && (typeof v.create === 'function' || typeof v.node === 'function' || (v.fuse && typeof v.fuse === 'object'))) return 'post';
|
|
44
|
+
if (typeof v.glsl === 'string' || typeof v.glsl === 'object' || v.tsl) return 'patch';
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const NEW = 'new materials only';
|
|
50
|
+
/** How far a slot reaches: a material or patch changes what makeMaterial makes next; everything else changes the picture at once */
|
|
51
|
+
const slotReach = slot => (slot === 'material' || slot === 'patch' ? NEW : 'live');
|
|
52
|
+
/** A plugin's reach: NEW when any of its values is a material / patch */
|
|
53
|
+
const reachOf = p => (p.values.some(v => slotReach(shapeOf(v)) === NEW) ? NEW : 'live');
|
|
54
|
+
/** 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) */
|
|
55
|
+
const postName = (p, v, i) => (v.isPass || 'needsSwap' in v ? (p.values.length > 1 ? `${p.name}/${i}` : p.name) : v.name);
|
|
56
|
+
|
|
57
|
+
/** File name without folder and extension: './plugins/10-crate.js' -> '10-crate' */
|
|
58
|
+
const baseOf = path => path.split('/').pop().replace(/\.[cm]?[jt]s$/, '');
|
|
59
|
+
|
|
60
|
+
export class Plugins {
|
|
61
|
+
/** @param {any} e @internal */
|
|
62
|
+
constructor(e) {
|
|
63
|
+
/** @internal */ this._e = e;
|
|
64
|
+
/** @internal name -> { name, file, values, on, plugged: [{ slot, value, remove }] } in plug order */
|
|
65
|
+
this._list = new Map();
|
|
66
|
+
/** @internal set by add(); start() plugs them */
|
|
67
|
+
this._added = false;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Hand the engine a folder of plugin files: the result of Vite's import.meta.glob('./plugins/*.js', { eager: true }) or any
|
|
72
|
+
* { path: moduleNamespace } map. The vite preset does this for you (tools/vite/vite-threedog-plugins.js); call it yourself only without it.
|
|
73
|
+
* Before start() the files are plugged at start; after start() at once.
|
|
74
|
+
* @param {Record<string, any>} files @param {{ order?: string[], off?: string[] }} [o] order: file names first, in this order; off: not plugged
|
|
75
|
+
* @returns {this}
|
|
76
|
+
* @example engine.plugins.add(import.meta.glob('./plugins/*.js', { eager: true }), { off: ['20-bloom'] });
|
|
77
|
+
*/
|
|
78
|
+
add(files, { order = [], off = [] } = {}) { return this._add(files, { order, off }); }
|
|
79
|
+
|
|
80
|
+
/** @internal the one loader: the game's folder (group null) and each style pack's plugins (group = the pack's name, style layer) */
|
|
81
|
+
_add(files, { order = [], off = [], group = null }) {
|
|
82
|
+
const paths = Object.keys(files).sort((a, b) => baseOf(a) < baseOf(b) ? -1 : baseOf(a) > baseOf(b) ? 1 : 0);
|
|
83
|
+
const rank = n => { const i = order.indexOf(n); return i < 0 ? order.length : i; };
|
|
84
|
+
paths.sort((a, b) => rank(baseOf(a)) - rank(baseOf(b))); // stable sort: listed names first, the rest keep file-name order
|
|
85
|
+
for (const n of [...order, ...off]) if (!paths.some(p => baseOf(p) === n))
|
|
86
|
+
throw codedError('plugin-shape', `plugins.json names '${n}', but there is no plugins/${n}.js; files: ${paths.map(baseOf).join(', ') || 'none'}`);
|
|
87
|
+
const where = group ? `style ${group}: plugins/` : 'plugins/';
|
|
88
|
+
for (const path of paths) {
|
|
89
|
+
const ns = files[path], name = group ? `${group}/${baseOf(path)}` : baseOf(path);
|
|
90
|
+
// replaces: a word about the file, never plugged (a string is no plugin shape)
|
|
91
|
+
const named = ns && 'default' in ns ? [['default', ns.default]] : Object.entries(ns ?? {}).filter(([k]) => k !== 'replaces'), values = named.flatMap(([, v]) => [].concat(v));
|
|
92
|
+
if (!values.length) throw codedError('plugin-shape', `${where}${baseOf(path)}.js exports nothing. Fix: export default one of: ${SHAPES}`);
|
|
93
|
+
for (const [key, x] of named) for (const v of [].concat(x)) if (!shapeOf(v)) throw codedError('plugin-shape', notAPlugin(`${where}${baseOf(path)}.js`, key, v));
|
|
94
|
+
const file = group ? `${where}${baseOf(path)}.js` : path.replace(/^.*?(plugins\/)/, '$1');
|
|
95
|
+
const replaces = [].concat(ns?.replaces ?? []).map(r => (group && !String(r).includes('/') ? `${group}/${r}` : String(r)));
|
|
96
|
+
this._list.set(name, { name, group, file, values, replaces, replacedBy: null, on: !off.includes(name), plugged: [] });
|
|
97
|
+
}
|
|
98
|
+
for (const p of this._list.values()) for (const r of p.replaces) if (!this._list.has(r))
|
|
99
|
+
throw codedError('plugin-shape', `${p.file}: export const replaces = '${r}', but there is no plugin '${r}'; plugins: ${[...this._list.keys()].join(', ')}`);
|
|
100
|
+
if (!group) this._added = true;
|
|
101
|
+
if (this._e._started) this._plugAll();
|
|
102
|
+
return this;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** @internal start(): plug every file that is on, in order (before module init, so a module from a plugin inits with the others) */
|
|
106
|
+
_plugAll() {
|
|
107
|
+
const e = this._e, all = [...this._list.values()];
|
|
108
|
+
// 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)
|
|
109
|
+
for (const p of all) p.values.forEach((v, i) => { if (shapeOf(v) === 'post') e.post?._place(postName(p, v, i), true); });
|
|
110
|
+
const todo = all.filter(p => p.on && !p.plugged.length && !p.replacedBy);
|
|
111
|
+
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
|
|
112
|
+
if (e._started && todo.some(p => reachOf(p) === NEW)) e.look?.materials?.rebuild?.();
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** @internal */
|
|
116
|
+
_plug(p) {
|
|
117
|
+
const e = this._e, owner = (p.group ? 'style:' : 'plugin:') + p.name, layer = p.group ? 'style' : 'game'; // a style's plugins sit under the game
|
|
118
|
+
for (const r of p.replaces) { const q = this._list.get(r); q.replacedBy = p.name; this._unplug(q); }
|
|
119
|
+
try {
|
|
120
|
+
for (const v of p.values) {
|
|
121
|
+
const slot = shapeOf(v);
|
|
122
|
+
let remove;
|
|
123
|
+
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
|
|
124
|
+
// an effect keeps its own name (look.post.set({ bloom: false }) reads the same from any source); a bare Pass is named by its file
|
|
125
|
+
else if (slot === 'post') { const h = e.look.post.add(v, { owner, layer, ...(v.isPass || 'needsSwap' in v ? { name: postName(p, v, p.plugged.length) } : {}) }); remove = () => h.remove(); }
|
|
126
|
+
else if (slot === 'material') { const h = e.look.materials.replace(v.name || baseOf(p.name), v, { owner, layer }); remove = () => h.remove(); }
|
|
127
|
+
else if (slot === 'patch') { const { roles, ...spec } = v, h = e.look.materials.add(p.name, spec, { roles, owner, layer }); remove = () => h.remove(); }
|
|
128
|
+
else { e.use(v); remove = () => { if (e.modules.get(v.name) === v) e._unuse(v.name); }; }
|
|
129
|
+
p.plugged.push({ slot, value: v, remove });
|
|
130
|
+
}
|
|
131
|
+
} catch (err) {
|
|
132
|
+
this._unplug(p); // all or nothing per file: half a plugin is harder to read than none
|
|
133
|
+
this._giveBack(p);
|
|
134
|
+
err.message = `${p.file}: ${err.message}`;
|
|
135
|
+
if (/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>';`;
|
|
136
|
+
throw err;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/** @internal */
|
|
140
|
+
_unplug(p) { for (const x of p.plugged.splice(0).reverse()) x.remove(); }
|
|
141
|
+
/** @internal p is out: the plugins it replaced plug again (when they are on) */
|
|
142
|
+
_giveBack(p) {
|
|
143
|
+
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); }
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Switch a plugin off: everything it plugged is taken out again (the object leaves the scene, the pass the chain, the patch its layer,
|
|
148
|
+
* the module is unloaded). No code change: plugins.json "off" does the same at start. A style pack's name switches off all of that pack's
|
|
149
|
+
* plugins ('ink'), '<pack>/<file>' one of them; the pack's starting values (style fields) stay. A material / patch plugin also rebuilds the
|
|
150
|
+
* materials already made (engine.look.materials.rebuild()), unless { rebuild: false }.
|
|
151
|
+
* To pause a post effect and keep everything else, look.post.set({ <effect>: false }) is lighter: off unloads.
|
|
152
|
+
* @param {string} name file name without .js, or a style pack's name @param {{ rebuild?: boolean }} [o]
|
|
153
|
+
* @returns {{ off: string[], reach: string[], rebuilt: number | null, note: string }}
|
|
154
|
+
*/
|
|
155
|
+
off(name, { rebuild = true } = {}) {
|
|
156
|
+
const ps = this._get(name);
|
|
157
|
+
for (const p of ps) { p.on = false; this._unplug(p); }
|
|
158
|
+
for (const p of ps) this._giveBack(p);
|
|
159
|
+
return this._result('off', name, ps, rebuild);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Switch a plugin (or a style pack's plugins) back on (plugged at once after start); a material / patch plugin rebuilds the made materials
|
|
163
|
+
* as off does. @param {string} name @param {{ rebuild?: boolean }} [o]
|
|
164
|
+
* @returns {{ on: string[], reach: string[], rebuilt: number | null, note: string }}
|
|
165
|
+
*/
|
|
166
|
+
on(name, { rebuild = true } = {}) {
|
|
167
|
+
const ps = this._get(name);
|
|
168
|
+
for (const p of ps) { p.on = true; if (this._e._started && !p.plugged.length && !p.replacedBy) this._plug(p); }
|
|
169
|
+
return this._result('on', name, ps, rebuild);
|
|
170
|
+
}
|
|
171
|
+
/** @internal what off / on did, in words a reader can act on */
|
|
172
|
+
_result(verb, name, ps, rebuild) {
|
|
173
|
+
const e = this._e, reach = [...new Set(ps.map(reachOf))], notes = [];
|
|
174
|
+
let rebuilt = null;
|
|
175
|
+
if (reach.includes(NEW) && e._started) {
|
|
176
|
+
if (rebuild && e.look?.materials?.rebuild) rebuilt = e.look.materials.rebuild().rebuilt;
|
|
177
|
+
else notes.push('materials made before keep the old look until engine.look.materials.rebuild() (new ones follow at once)');
|
|
178
|
+
}
|
|
179
|
+
const fx = ps.flatMap(p => p.values.map((v, i) => (shapeOf(v) === 'post' ? postName(p, v, i) : null))).filter(Boolean);
|
|
180
|
+
if (verb === 'off' && fx.length) notes.push(`plugins.off unloads; to pause an effect in its place use engine.look.post.set({ ${fx.map(n => `${/^[\w$]+$/.test(n) ? n : `'${n}'`}: false`).join(', ')} })`);
|
|
181
|
+
if (verb === 'off' && ps.some(p => p.group === name)) notes.push(`style '${name}': its plugins are off; the pack's starting values (exposure, fog, its materials table ...) stay, they are the style itself`);
|
|
182
|
+
const replaced = ps.filter(p => p.replacedBy).map(p => `${p.name} stays out while ${p.replacedBy} (replaces it) is on`);
|
|
183
|
+
return { [verb]: ps.map(p => p.name), reach, rebuilt, note: [...notes, ...replaced].join('; ') };
|
|
184
|
+
}
|
|
185
|
+
/** @internal the plugin by name, or every plugin of the style pack by that name */
|
|
186
|
+
_get(name) {
|
|
187
|
+
const p = this._list.get(name), pack = p ? [p] : [...this._list.values()].filter(x => x.group === name);
|
|
188
|
+
if (!pack.length) throw codedError('plugin-shape', `engine.plugins: no plugin '${name}' (nor a style pack by that name); plugins: ${[...this._list.keys()].join(', ') || 'none (no plugins folder, no style plugins)'}`);
|
|
189
|
+
return pack;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* The plugins in plug order (a style's first): { name, file, on, slots, reach, style, replacedBy } (style: the pack's name, null for the game's
|
|
194
|
+
* folder; reach per slot: 'live', or 'new materials only' for a material / patch, which off / on rebuilds; replacedBy: the plugin that holds it out)
|
|
195
|
+
* @returns {{ name: string, file: string, on: boolean, slots: string[], reach: string[], style: string | null, replacedBy: string | null }[]}
|
|
196
|
+
*/
|
|
197
|
+
list() { return [...this._list.values()].map(p => ({ name: p.name, file: p.file, on: p.on, slots: p.values.map(v => shapeOf(v)), reach: [...new Set(p.values.map(v => slotReach(shapeOf(v))))], style: p.group, replacedBy: p.replacedBy })); }
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* The plugin-shape error for one export that is not a plugin: the file, what was found, and the exact fix for that case
|
|
202
|
+
* (a factory function, a module missing its type or hooks, a post effect missing its name, anything else).
|
|
203
|
+
*/
|
|
204
|
+
function notAPlugin(file, key, v) {
|
|
205
|
+
const what = key === 'default' ? 'the default export' : `the export '${key}'`;
|
|
206
|
+
if (typeof v === 'function') {
|
|
207
|
+
const fn = v.name && v.name !== 'default' ? v.name : 'make';
|
|
208
|
+
return `${file}: ${what} is a function (${v.name || 'anonymous'}). A function is never a plugin: it does not say where it plugs in. ` +
|
|
209
|
+
(key === 'default' ? `Fix: make it a named export and plug in what it returns: export function ${fn}(...) { ... } export default ${fn}({ ... });`
|
|
210
|
+
: `Fix: plug in what it returns, add to the file: export default ${key}({ ... }); (the default export is plugged; named exports stay helpers)`) +
|
|
211
|
+
" 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";
|
|
212
|
+
}
|
|
213
|
+
if (v && typeof v === 'object') {
|
|
214
|
+
const keys = Object.keys(v).slice(0, 8).join(', ') || '(none)';
|
|
215
|
+
const hooks = ['install', 'init', 'fixed', 'frame', 'dispose'].filter(h => typeof v[h] === 'function');
|
|
216
|
+
if (typeof v.name === 'string' && hooks.length && !v.type)
|
|
217
|
+
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(' | ')}`;
|
|
218
|
+
if (typeof v.name === 'string' && v.type && !hooks.length)
|
|
219
|
+
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) { ... } }`;
|
|
220
|
+
if (typeof v.name !== 'string' && (typeof v.create === 'function' || typeof v.node === 'function' || v.fuse))
|
|
221
|
+
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'}: ... }`;
|
|
222
|
+
return `${file}: ${what} is an object with keys ${keys}, which matches no plugin shape. Fix: export default one of: ${SHAPES}`;
|
|
223
|
+
}
|
|
224
|
+
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}`;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Plug the style's plugins (style layer), then what the page's plugins folder gave (the vite preset puts it on globalThis.__threedogPlugins
|
|
229
|
+
* before main.js runs) and the files engine.plugins.add received. Called once by start(). @param {any} e
|
|
230
|
+
*/
|
|
231
|
+
export function plugAtStart(e) {
|
|
232
|
+
// the style's first, so their list order (and describe().slots) reads base look, then the game's additions
|
|
233
|
+
const before = [...e.plugins._list.entries()];
|
|
234
|
+
e.plugins._list.clear();
|
|
235
|
+
for (const { group, files } of stylePlugins(e.style)) e.plugins._add(files, { group });
|
|
236
|
+
for (const [k, v] of before) e.plugins._list.set(k, v);
|
|
237
|
+
const page = typeof globalThis !== 'undefined' ? globalThis.__threedogPlugins : null;
|
|
238
|
+
if (page && !e.plugins._added) e.plugins.add(page.files, page.config ?? {});
|
|
239
|
+
e.plugins._plugAll();
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* describe().slots: one table of what is plugged in where. Each row: { slot, plugged, file, on, affects }; file is the plugin file, the
|
|
244
|
+
* file:line that called scene.add / engine.add (dev), or the call that plugged it ('engine.use', 'look.post.add'). Why one table:
|
|
245
|
+
* a reader asking "what did this game add to the engine" had to put describe().scene, render.post, look and modules side by side.
|
|
246
|
+
* @param {any} e
|
|
247
|
+
*/
|
|
248
|
+
export function describeSlots(e) {
|
|
249
|
+
const rows = [], fromPlugin = new Set();
|
|
250
|
+
const passOf = v => e.post?._list.find(h => h._def === v || h._def._pass === v || h._def.node === v);
|
|
251
|
+
const affects = (slot, v, name) => {
|
|
252
|
+
if (slot === 'scene') { const t = e._things.byObj.get(v); return t ? [`engine.thing('${t.id}')`, `save tier ${e._things.tier(t)}`] : ['scene']; }
|
|
253
|
+
if (slot === 'post') { const h = passOf(v); return [h ? `picture: post chain ${h.slot} slot, ${h.name}` : 'picture: post chain']; }
|
|
254
|
+
if (slot === 'material') { const r = v.name || baseOf(name); return [`look.materials replace:${r}`, `makeMaterial('${r}')`]; }
|
|
255
|
+
if (slot === 'patch') return [`look.materials hook:${name}`, v.roles ? `materials of roles ${v.roles.join(', ')}` : 'every makeMaterial material', `shader slot ${v.slot ?? '?'}`];
|
|
256
|
+
if (slot === 'light') return ["budget 'lights'", ...(v.castShadow ? ["budget 'shadowLights'", 'idle shadow redraw rule'] : [])];
|
|
257
|
+
return [`engine.${v.name}`, `type ${v.type}`, ...(v.provides ?? []).map(s => `provides ${s}`)];
|
|
258
|
+
};
|
|
259
|
+
for (const p of e.plugins?._list.values() ?? []) for (const v of p.values) {
|
|
260
|
+
const slot = shapeOf(v);
|
|
261
|
+
fromPlugin.add(v);
|
|
262
|
+
const live = p.on && !p.replacedBy;
|
|
263
|
+
rows.push({ slot, plugged: (slot === 'module' ? v.name : v.name || v.type) || p.name, file: p.file, on: live, reach: slotReach(slot),
|
|
264
|
+
affects: live ? affects(slot, v, p.name) : p.replacedBy ? [`replaced by ${p.replacedBy}`] : p.group ? [`off; style '${p.group}' starting values stay`] : [] });
|
|
265
|
+
}
|
|
266
|
+
for (const o of e.scene.children) { const en = e._things.byObj.get(o); if (en?.owner === 'game' && !fromPlugin.has(o) && !o.isLight)
|
|
267
|
+
rows.push({ slot: 'scene', plugged: o.name || o.type, file: en.at ?? 'scene.add / engine.add', on: true, affects: affects('scene', o) }); }
|
|
268
|
+
for (const h of e.post?._list ?? []) if (![h._def, h._def._pass, h._def.node].some(v => v && fromPlugin.has(v)))
|
|
269
|
+
rows.push({ slot: 'post', plugged: h.name, file: 'look.post.add', on: h.enabled, affects: [`picture: post chain ${h.slot} slot, ${h.name}`] });
|
|
270
|
+
for (const m of e.post?._plain ?? []) if (m.output)
|
|
271
|
+
rows.push({ slot: 'post', plugged: 'OutputPass (skipped: the engine tone maps; passes after it run in ldr)', file: 'look.post.add', on: true, affects: ['picture: where display color starts'] });
|
|
272
|
+
for (const m of e.modules.values()) if (!fromPlugin.has(m))
|
|
273
|
+
rows.push({ slot: 'module', plugged: m.name, file: 'engine.use', on: true, affects: affects('module', m) });
|
|
274
|
+
for (const l of e._gameLights?.list() ?? [])
|
|
275
|
+
rows.push({ slot: 'light', plugged: l.name || l.type, file: e._things.entryOf(l)?.[0]?.at ?? 'scene.add', on: true, affects: affects('light', l) });
|
|
276
|
+
return rows;
|
|
277
|
+
}
|