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
|
@@ -1,68 +1,81 @@
|
|
|
1
|
-
# Writing a game system module (
|
|
1
|
+
# Writing a game system module (a smelter, a recharging turret, growing crops) that plugs into the engine's contracts
|
|
2
2
|
|
|
3
3
|
A game system is a module (`{ name, install, ... }`) given to `engine.use(...)`. If it follows the five contracts below it saves, loads, skips time,
|
|
4
|
-
shows in `describe()` and the dev bridge, and can be driven by ops, without special cases. Read recipe 06 (clock, skip), 18 (world records), 23 (ops).
|
|
4
|
+
shows in `describe()` and the dev bridge, and can be driven by ops, without special cases. Read recipe 14 (template, hook cheat sheet), 06 (clock, skip), 18 (world records), 23 (ops).
|
|
5
5
|
|
|
6
6
|
## The five contracts
|
|
7
7
|
1. **State.** Prefer world records (`engine.world.add({ kind, ... })`, recipe 18): saved, streamed and far-simulated for you. State that is not a
|
|
8
8
|
record (a counter, a machine's queue) goes in `engine.saves.register(key, { save, load, version?, migrate? })`. Raise `version` by 1 whenever the
|
|
9
9
|
saved shape changes and add `migrate: { oldVersion: d => newData }`. Never keep game state only in a closure or module variable.
|
|
10
10
|
2. **Time, normal play.** Store *when* something happened in game seconds (`engine.clock.now`), and derive the state from `now - startedAt`. Never use
|
|
11
|
-
`Date.now`, `performance.now` or `setTimeout` for game time: they ignore pause,
|
|
12
|
-
the module `fixed(dt, e)` hook (dt is
|
|
11
|
+
`Date.now`, `performance.now` or `setTimeout` for game time: they ignore pause, time channels, `step` and saves. If you must accumulate, do it in
|
|
12
|
+
the module `fixed(dt, e)` hook (dt is real seconds; a speed several systems change goes through `engine.mod`, recipe 06).
|
|
13
13
|
3. **Time, skipped** (`engine.skip`, the op `time.skip`, recipe 06 section 2). `fixed` hooks, physics and near simulation do **not** run during a skip.
|
|
14
14
|
A state derived from `clock.now` is exact for free. A module that accumulates in `fixed` must also implement `skip(dt, e, done)` (called once per
|
|
15
15
|
segment, `done` on the last; do heavy work once when `done`), or put the logic in a world record `far(rec, dt)`, which gets one catch-up call.
|
|
16
16
|
4. **Observable.** Module hook `describe(e, ctx)` puts its return value in `describe().<module name>` (plain JSON; the bridge `describe <name>` and
|
|
17
17
|
`describeText()` show it). A game without a module uses `engine.describe.add(name, fn)`. The name must be new (it throws on a clash).
|
|
18
|
+
Every engine module has one (check rule R44 fails a module without it): keep it compact, the state an AI checks to verify the module worked.
|
|
18
19
|
5. **Actions are ops.** `engine.ops.define('noun.verb', { args, can, run, offers, reasons, desc })`. `can` is read-only and returns `true` or a reason
|
|
19
20
|
string (a key of `reasons`); `run` changes state; `offers(e, ctx)` lists the arg sets possible right now (shown by the bridge `ops` command and
|
|
20
|
-
`describe`). Call with `engine.ops.run(name, args)` -> `{ ok, value }` or `{ ok: false,
|
|
21
|
+
`describe`). Call with `engine.ops.run(name, args)` -> `{ ok, value }` or `{ ok: false, code, facts, nextActions }` (read `r.code`). Never mutate state from UI code directly.
|
|
21
22
|
|
|
22
23
|
## Declaring stage and dependencies
|
|
23
|
-
`stage` picks where the hooks run (first to last): `control,
|
|
24
|
-
(module names) only order modules inside one stage; a contradiction with the stage order throws. `requires: ['world']` must already be
|
|
25
|
-
otherwise:
|
|
24
|
+
`stage` only picks where the hooks run (first to last): `control, ground, environment, gameplay, effects, late (default), audio`; `before / after`
|
|
25
|
+
(module names) only order modules inside one stage; a contradiction with the stage order throws. `requires: ['world']` names a capability that must already be provided (throws
|
|
26
|
+
otherwise, naming both fixes: the engine's `world()` first, or your own module with `provides: ['world']`). `type` says what the module may own
|
|
27
|
+
(recipe 14: `'rules'` for game logic like this one; a `'look'` module may not define ops). `optional: { sky: 'what is lost without it' }` is a soft dependency (use `engine.sky?.`). Core never imports
|
|
26
28
|
modules. The module `name` must not clash with an existing engine property.
|
|
27
29
|
|
|
28
|
-
## One copyable module: a crop
|
|
30
|
+
## One copyable module: something that finishes after a delay (a smelter, a turret recharge, a crop)
|
|
29
31
|
```js
|
|
30
|
-
export const
|
|
31
|
-
const
|
|
32
|
+
export const machines = () => {
|
|
33
|
+
const started = new Map(); // id -> startedAt (game seconds)
|
|
32
34
|
return {
|
|
33
|
-
name: '
|
|
35
|
+
name: 'machines', type: 'rules', stage: 'gameplay', requires: ['inventory'],
|
|
34
36
|
install(e) {
|
|
35
|
-
e.saves.register('
|
|
36
|
-
save: () => [...
|
|
37
|
-
load: d => {
|
|
38
|
-
const
|
|
39
|
-
e.ops.define('
|
|
40
|
-
can: (_, { id }) => (
|
|
41
|
-
run: (_, { id }) => {
|
|
42
|
-
e.ops.define('
|
|
43
|
-
can: (_, { id }) => (!
|
|
44
|
-
offers: () => [...
|
|
45
|
-
run: (_, { id }) => {
|
|
46
|
-
reasons: {
|
|
47
|
-
return {
|
|
37
|
+
e.saves.register('machines', { version: 1, // contract 1: saved and restored
|
|
38
|
+
save: () => [...started],
|
|
39
|
+
load: d => { started.clear(); for (const [id, t] of d) started.set(id, t); } });
|
|
40
|
+
const progress = id => Math.min(1, (e.clock.now - started.get(id)) / 120); // contracts 2+3: derived from clock.now, so normal == skipped
|
|
41
|
+
e.ops.define('job.start', { args: { id: 'string' }, desc: 'Start a job on a machine', // contract 5
|
|
42
|
+
can: (_, { id }) => (started.has(id) ? 'busy' : true),
|
|
43
|
+
run: (_, { id }) => { started.set(id, e.clock.now); return id; }, reasons: { busy: 'Already running' } });
|
|
44
|
+
e.ops.define('job.collect', { args: { id: 'string' }, desc: 'Collect a finished job',
|
|
45
|
+
can: (_, { id }) => (!started.has(id) ? 'idle' : progress(id) < 1 ? 'notDone' : true),
|
|
46
|
+
offers: () => [...started.keys()].filter(id => progress(id) >= 1).map(id => ({ id })),
|
|
47
|
+
run: (_, { id }) => { started.delete(id); e.inventory.add('item', 2); return id; },
|
|
48
|
+
reasons: { idle: 'Nothing running', notDone: 'Not done yet' } });
|
|
49
|
+
return { progress }; // becomes engine.machines (engine.jobs is the engine's own job queue)
|
|
48
50
|
},
|
|
49
|
-
describe: e => ({
|
|
51
|
+
describe: e => ({ running: started.size, done: [...started.keys()].filter(id => e.machines.progress(id) >= 1) }), // contract 4
|
|
50
52
|
};
|
|
51
53
|
};
|
|
52
54
|
```
|
|
53
|
-
Needs the `inventory`
|
|
54
|
-
|
|
55
|
+
Needs an `inventory` (the engine's, or a game's own module with `provides: ['inventory']`; drop the `inventory.add` line and the requires
|
|
56
|
+
if the game has none).
|
|
55
57
|
|
|
56
58
|
## Check "advance 10h normally == skip 10h" (bridge, no new tools)
|
|
57
59
|
```
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
60
|
+
threedog op job.start id=a ; threedog step 36000 ; threedog describe machines # A: normal play
|
|
61
|
+
threedog reload ; threedog op job.start id=a ; threedog op time.skip seconds=36000 ; threedog describe machines # B: skipped
|
|
62
|
+
threedog js "JSON.stringify(engine.machines.progress('a'))" # same number both times; compare whole state with: threedog snap-describe save|diff
|
|
61
63
|
```
|
|
62
|
-
Both runs must give equal `describe
|
|
64
|
+
Both runs must give equal `describe machines` (and `describe time`); if B differs, the module accumulates in `fixed` and needs a `skip` hook or `far`.
|
|
65
|
+
|
|
66
|
+
## Checking it: a contract file and the shared contract test
|
|
67
|
+
Write the five points down as data in `contract.js` (`{ name, api, ops, events, saves: { key: version }, describe, options, probe }`, see
|
|
68
|
+
`modules/gameplay/inventory.contract.js`) and run it from your tests (works in a game installed from npm):
|
|
69
|
+
```js
|
|
70
|
+
import { runContract } from '@threedog/tools/contract';
|
|
71
|
+
runContract(contract, () => myModule(contract.options), { check }); // check(label, ok, detail?)
|
|
72
|
+
```
|
|
73
|
+
It installs the module, checks the api / ops / save versions / probe events / describe, and that the probed
|
|
74
|
+
value survives save -> fresh install -> load. `props` lists fields that must exist (`dialogue.active`), `probe.state.map` turns a non-number read
|
|
75
|
+
into a comparable value. The engine's own inventory, interactions, dialogue, quests, flow, characters and camera pass the same test (recipe 55).
|
|
63
76
|
|
|
64
77
|
## What the engine does NOT check for you
|
|
65
|
-
- That `save`
|
|
78
|
+
- That `save` includes **all** your state: the contract test only round-trips the value its probe reads.
|
|
66
79
|
- That your state is equal after skip versus step: it only skips the hooks it knows about. A `setTimeout`, a closure counter or a `fixed` accumulator
|
|
67
80
|
is silently *not* advanced during a skip.
|
|
68
81
|
- That `can` is side-effect free and that `run` does not need `can` to have passed; `offers` is not checked against `can`.
|
|
@@ -7,6 +7,6 @@ const renderer = new THREE.WebGLRenderer({ canvas, antialias: true });
|
|
|
7
7
|
const engine = createEngine({ renderer, style }); // canvas defaults to renderer.domElement
|
|
8
8
|
```
|
|
9
9
|
|
|
10
|
-
- The engine configures only a renderer it created itself. With yours it sets nothing: pixel ratio (unless `pixelRatio` is given), size, tone mapping, exposure and shadow map stay as you left them, so `style.toneMapping` / `style.exposure` do not apply. Set them yourself on the renderer.
|
|
11
|
-
- **
|
|
10
|
+
- The engine configures only a renderer it created itself. With yours it sets nothing: pixel ratio (unless `pixelRatio` is given), size, tone mapping, exposure and shadow map stay as you left them, so `style.toneMapping` / `style.exposure` do not apply. Set them yourself on the renderer. MSAA follows your renderer's `antialias` too (unless `createEngine({ antialias })` or `style.antialias` says otherwise; a value that differs from the renderer's runs the post chain's MSAA targets every frame).
|
|
11
|
+
- **WebGLRenderer or three's WebGPURenderer.** On WebGPURenderer, materials, patches and post effects take their node / TSL forms (recipe 56). Everything else (scene, modules, input, saves, ops) does not depend on the renderer.
|
|
12
12
|
- Changing the renderer, lights or post effects is yours to do at any time; the engine never warns. `engine.describe().render` (CLI: `describe render`) lists the current values and tags each `engine` / `style` / `game`, so an AI can see who set a look.
|
|
@@ -12,7 +12,7 @@ engine.catalog('shop.buy'); // one op: args schema, reasons, can / offers
|
|
|
12
12
|
engine.catalog({ find: 'throw' }); // the short list filtered by id, label, op or save name
|
|
13
13
|
engine.catalog('core'); // what the engine registered itself (time.skip, clock, random...); 'game': what game code registered outside modules
|
|
14
14
|
```
|
|
15
|
-
From the dev bridge: `
|
|
15
|
+
From the dev bridge: `threedog catalog`, `threedog catalog shop`, `threedog catalog --find buy` (`--json` for the data). The bridge prints the
|
|
16
16
|
same data and adds the files: `source` (where `name: 'shop'` or `define('shop.buy'` is written), `api` (the generated api page), `recipes` and
|
|
17
17
|
`examples` that use `engine.shop`. The MCP server has one `catalog` tool with the same arguments.
|
|
18
18
|
|
|
@@ -45,7 +45,7 @@ import { readParams } from 'threedog';
|
|
|
45
45
|
const PARAMS = { radius: { type: 'number', default: 2, min: 0, desc: 'pickup reach in m' }, sound: 'string?' };
|
|
46
46
|
export const magnet = (opts) => {
|
|
47
47
|
const o = readParams('magnet', PARAMS, opts); // wrong type / out of range throws [module-params] with the fix; an unknown key throws in dev and warns once in a release build
|
|
48
|
-
return { name: 'magnet', params: PARAMS, options: o, stage: 'gameplay', install(e) { return { radius: o.radius }; } };
|
|
48
|
+
return { name: 'magnet', type: 'rules', params: PARAMS, options: o, stage: 'gameplay', install(e) { return { radius: o.radius }; } };
|
|
49
49
|
};
|
|
50
50
|
```
|
|
51
51
|
`params` and `options` on the definition are what `engine.catalog('magnet').params` reads; `engine.use` re-checks them in dev for a definition built by hand.
|
|
@@ -57,7 +57,7 @@ The schema types are those of op args plus `object`, `array` and `function` (opt
|
|
|
57
57
|
time hooks; a `fixed` hook without `skip` is listed under problems (recipe 49).
|
|
58
58
|
|
|
59
59
|
## 5. "How do I get this effect": `threedog how`
|
|
60
|
-
`
|
|
60
|
+
`threedog how "rain"` scores the words of the task against the AI.md task rows and the recipe headings with their first sentence, and prints the
|
|
61
61
|
top five: the API in the row, the recipe path with section (`recipes/08-weather-sky.md §1`) and a one-line snippet. It reads the docs only, so it works with no page
|
|
62
62
|
and prints the same list every run. When a dev page runs it adds up to three live catalog modules whose name matches the first English word. Words match at a word
|
|
63
|
-
start (`rain` does not hit `terrain`)
|
|
63
|
+
start (`rain` does not hit `terrain`). No hit means rephrase, or read AI.md.
|
package/docs/recipes/52-look.md
CHANGED
|
@@ -1,65 +1,138 @@
|
|
|
1
1
|
# 52 Change any look: `engine.look`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**In this recipe**: Atmosphere parts · Surface parts · Water, weather, post · Post effect chain · Who writes it · How look values stack ·
|
|
4
|
+
Lower-level forms that stay
|
|
4
5
|
|
|
6
|
+
Every look part lives at `engine.look.<part>` and is changed with the same verbs. The style gives the starting values; the game changes them on top.
|
|
7
|
+
|
|
8
|
+
```js
|
|
9
|
+
const cave = engine.look.tone.set({ exposure: 0.6 }, { owner: 'cave' }); // adjust: only the keys you give; null drops a key
|
|
10
|
+
cave.remove(); // the style value shows again (every handle ends with remove())
|
|
11
|
+
engine.look.lights.manual('sun'); engine.lights.sun.intensity = 3; // take a value the engine drives; manual('sun', false) gives it back
|
|
12
|
+
engine.look.env.replace('sky'); // swap the one three.js thing a part draws (here the environment map); replace(null) gives it back
|
|
13
|
+
engine.describe().look.tone.exposure; // { value: 0.6, writer: 'game:cave', at: 'main.js:12', under: ['style'] }
|
|
14
|
+
engine.catalog('look.tone'); // params with default, why, off; hooks; what replace accepts and loses
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Sky and atmosphere, three ways (recipe 08 has the contract):
|
|
5
18
|
```js
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
engine.
|
|
11
|
-
engine.catalog('look.tone'); // params with default, why, off; hooks; what replace accepts and loses
|
|
19
|
+
// 1. keyframes (default): style.sky.keyframes / style.exposure lists drive the day; nothing to write
|
|
20
|
+
// 2. a function of the frame context, fed by one call: any key marked fn (fog color / near / far / density, sky top / horizon / backdrop, lights, exposure)
|
|
21
|
+
engine.look.fog.set({ color: ({ state }) => state.boss ? '#400' : 'horizon' }); engine.look.state({ boss: true });
|
|
22
|
+
// 3. your own three.js sky (three/addons Sky, a ShaderMaterial dome, a skybox): never written; time / weather keep flowing through engine.uniforms
|
|
23
|
+
engine.look.sky.replace(mySky); mySky.material.uniforms.sunPosition = engine.uniforms.uSunDir; // the same Vector3, refreshed every frame
|
|
12
24
|
```
|
|
13
25
|
|
|
26
|
+
Two routes, side by side (not a ladder): the **look** itself is plain three.js, any time: your own material, `ShaderMaterial`, `onBeforeCompile`,
|
|
27
|
+
textures, lights, passes, written directly (a direct write takes the value over: auto-yield). `engine.look` is the **coordination** route: owners,
|
|
28
|
+
layers, keyframes that follow time / weather / season, and `describe` saying who set what. Use either per value; the verbs here
|
|
29
|
+
are optional shortcuts, not steps to climb before three.js is allowed. When tuning params does not reach the reference, write the three.js.
|
|
30
|
+
Where looks sit among the other ways to customize: `../CONVENTIONS.md` "Customization ladder".
|
|
31
|
+
Which knob changes what on screen, and how to judge it for your style: [recipe 60](60-judge-the-picture.md).
|
|
32
|
+
|
|
14
33
|
- Layers, upper wins: engine default < style < game (each owner; the last one written wins) < `engine.debug.override(owner, 'look.<part>', values)`.
|
|
15
|
-
- `set`
|
|
16
|
-
- `
|
|
34
|
+
- <a id="verbs"></a>**The verbs, the same on every part**: `set(values)` changes values; `patch(hook, code)` swaps one named hook the part declares (that is all patch means); `add(thing)` puts one more named thing in next to the engine's (`look.post.add`, `look.materials.add`; the handle's `remove()` takes it out); `replace(thing)` swaps the one three.js thing the part draws (a texture, a sky object, a Material, an effect list; `replace(null)` gives it back); `manual(key)` stops the engine writing a value it writes on its own (the table below); `value(key)` is the one read (who set it: `describe().look`). To swap a whole module with its behaviour and saves (the sky, the ground or plant look, the weather look) use `engine.use(mine(), { replaces: '<slot>' })` instead: `replace` is for one thing, `replaces` for a module. A part offers only the verbs that make sense for it; the others throw with the call to use and the verbs it has. A part whose verb takes other arguments (`materials.replace(role, impl)`) lists the call shape in `engine.catalog('look.<part>').signatures`, and a wrong call quotes it.
|
|
35
|
+
- `writer` in describe is who set the value: the layer, `'engine'`, `'style'`, `'game'` (owner `'game'`) or `'<layer>:<owner>'` (for example game:cave or debug:probe), unless something else writes the property now: then `'three'` (a direct write) or `'manual:game'`, the same name as `describe().owned`. `describe().render` keeps only renderer facts; each value carries `look` (the path of the record to read here, `'look.tone.exposure'`) and that record's `writer`. The tone curve has no look record (the engine writes `renderer.toneMapping` once at creation; change it with plain three.js): its owned row `toneMapping` yields quietly to a direct write, and `render.toneMapping.writer` is `'engine'`, `'style'` or `'game'` directly.
|
|
17
36
|
- Look changes are not saved: after a load, set them again from your own state.
|
|
18
37
|
- Changing the three.js object directly (`engine.renderer.toneMappingExposure = 2`) still works; describe tags it `three` and you lose the owner and the debug layer.
|
|
19
|
-
-
|
|
20
|
-
|
|
38
|
+
- How bright a lit color comes out (three.js light units, AgX, exposure 1): a diffuse surface facing up receives
|
|
39
|
+
`sun.intensity × sin(sun elevation) + hemi.intensity` (the hemisphere's sky color, since it faces up), and three divides by π, so a total of
|
|
40
|
+
**about 3 (≈ π) shows mid-tone albedos (sRGB 0.35-0.65) at roughly their own value**: sun 2 high overhead + hemisphere 1, or a low sun 4 at 20° +
|
|
41
|
+
hemisphere 1.6. Measured on three's AgX curve: total 2.5 for sRGB 0.35, 2.6 for 0.5, 3.4 for 0.65, 5.5 for 0.8 (AgX darkens light colors and
|
|
42
|
+
pales saturated ones, so a pale or vivid palette needs more, or exposure). Walls and faces away from the sun get only their `N·L` share, and
|
|
43
|
+
the environment (`look.lights` `env`, `look.env`) adds on top for Standard / Physical materials; under a sky the room map follows the keyframes'
|
|
44
|
+
ambient column (recipe 08 "Day and night brightness").
|
|
45
|
+
- Your own module's part: `defineLookPart(engine, { id, params, style, apply })`. Every param declares `default`; a default that changes the picture declares `why` and `off`, or `neutral: true` (checked by `npm run check`; R36 checks that the part's `Look<Part>` type lists the same keys). Module code changes records only through `part.author` (`write`, `ownerValue`, `extend`, `retract`, `has`, `resolved`, `values`, `restyle`, `drive` / `feed`); it is kept off the part so a game's autocomplete shows only the verbs above (rule R25 flags `part._...`); `validate(key, value)` in the spec rejects a value before anything is written, and an `apply` that throws leaves no layer behind.
|
|
21
46
|
|
|
22
47
|
## Atmosphere parts (sky module): fog, sky, shadow
|
|
23
48
|
|
|
24
49
|
```js
|
|
25
50
|
engine.look.fog.set({ far: 220, color: '#9bb' }, { owner: 'cave' }); // kind, color, density, near, far, height, falloff, enabled
|
|
26
|
-
engine.look.fog.
|
|
51
|
+
engine.look.fog.manual(); // the sky stops writing scene.fog (manual(false) gives it back)
|
|
52
|
+
engine.scene.fog = new THREE.Fog(0x445566, 10, 120); // a fog of your own: plain three.js, the engine yields (there is no look.fog.replace)
|
|
27
53
|
engine.look.sky.set({ clouds: { coverage: 0.7, speed: [0.01, 0] }, backdrop: 0x335577 });
|
|
28
54
|
engine.look.sky.patch('layer:aurora', { glsl: '...threedogSkyLayer...', blend: 'add' }); // a named dome layer; patch('layer:aurora', null) removes it
|
|
29
55
|
engine.look.sky.patch('clouds', glsl); // the cloud function; replace(skyboxName | Texture | Object3D) swaps the dome
|
|
30
56
|
engine.look.shadow.set({ type: 'vsm', radius: 3, cascades: 3, maxFar: 150 }); // set only
|
|
31
57
|
```
|
|
32
58
|
|
|
33
|
-
- `fog` shows `enabled` and `far` (fog reaches full strength at `
|
|
59
|
+
- `fog` shows `enabled` and `far` (fog reaches full strength at `far`, 600 m unless a style, the terrain view or the game says otherwise, starting at 0.3 x that) as the visible defaults; turn off with `set({ enabled: false })`. Color, density, near, far, enabled and linear <-> exp2 are live; color switches freely between `'horizon'` (the default: fog matches the sky where they meet), a fixed color and a function, and the dome's lower band fades to any non-horizon fog color so no seam shows. Kind `'exp'` / `'height'`, `height`, `falloff` and the `'fog'` hook replace three's shared fog shader chunks, so they only work before the first frame (style, `sky({ fog })`, or right after `createEngine`); later they throw and say so.
|
|
34
60
|
- `sky`: `clouds.*` are live uniforms of the dome (they only draw when `clouds.coverage` > 0). A hook change recompiles the dome material once. Style `layers` arrays are named by their `name` key, else `layer0`, `layer1`.
|
|
61
|
+
- <a id="tsl-forms"></a>**tsl forms** (`renderer: 'webgpu'`): the GLSL hooks `clouds`, `layer:<name>` (and style `layers` entries) and `fog` take `{ glsl, tsl }`; each renderer draws its own form and a missing one throws by name (`[webgpu-needs-tsl]` on WebGPU). `tsl: (ctx) => vec4 node`, ctx = the GLSL function's arguments as nodes plus the value so far (`ctx.clouds` the built-in kind, `ctx.color` the sky under a layer, `ctx.fog` what the fog kind alone draws), `ctx.uniforms` (the dome's, yours included), `ctx.fx.noise` / `hash` and `ctx.tsl` (three/tsl):
|
|
62
|
+
`engine.look.sky.patch('layer:glow', { glsl, tsl: ({ dir, tsl }) => tsl.vec4(1, 0.6, 0.3, tsl.smoothstep(0.3, 0.8, dir.y).mul(0.4)), blend: 'add' })`;
|
|
63
|
+
`engine.look.fog.patch('fog', { glsl, tsl: ({ depth, tsl }) => tsl.vec4(0.3, 0.3, 0.8, tsl.exp(depth.mul(-0.02)).oneMinus()) })`.
|
|
35
64
|
- `shadow`: no `patch` (the cascade patch is internal) and no `replace` (to own the shadows, light with your own lights: `sky({ sun: false })`).
|
|
65
|
+
`engine.look.shadow.include(myLitShaderMaterial)` opts a ShaderMaterial of yours into cascaded shadows (built-in lit materials need nothing).
|
|
66
|
+
- Whether a picture reads as lit is mostly key against fill. The key (the sun or one main light) is the light that casts the shadow; the fill is
|
|
67
|
+
everything else (sky and ground light, the environment). Shadowed surfaces see only the fill while lit ones see both, so the balance sets how
|
|
68
|
+
deep the shadows look: less fill is harder and more dramatic, more fill softer and more readable, and there is no right ratio, only the one
|
|
69
|
+
the game wants. A warm key over a cool fill (or the reverse) separates lit from shaded sides without more contrast. The shot's `light:`
|
|
70
|
+
fact measures the ratio; judge the result on a shot with a known-colored object in shadow. To compare afterwards, the `sun-and-key-light`
|
|
71
|
+
technique (`threedog examples pull sun-and-key-light`) shows three routes side by side.
|
|
72
|
+
- Shadow detail is texels per meter: one shadow-map texel covers `2 x extent / mapSize` meters (for example the default `extent` 70 on a
|
|
73
|
+
2048 map is about 6.8 cm, twice that on the 1024 map of low tier and headless shots). A box much bigger than what the camera sees blurs
|
|
74
|
+
the shadows of small things; a box smaller than it cuts shadows off. `look.shadow.set({ extent })` sizes it; a depth bias scales with the
|
|
75
|
+
texel, so re-check `bias` / `normalBias` after changing either.
|
|
76
|
+
- Fog kinds and the fog hook in detail, and taking lights or fog away from the sky entirely (`look.lights.manual('sun')`, `sky({ sun: false })`, `look.fog.manual()`): [recipe 38](38-environment-look-hooks.md).
|
|
36
77
|
|
|
37
78
|
## Surface parts: `materials`, `surface`, `ground`, `wind`
|
|
38
79
|
|
|
39
|
-
A change to these parts reaches the materials made **after** it, with one exception: `look.materials.set` of the plain properties `color`, `emissive`, `emissiveIntensity`, `roughness`, `metalness`, `opacity`, `envMapIntensity`, `shininess` and `specular` also changes the materials already made for that role (no recompile; clearing the layer goes back to the style's value). Shader-changing keys (`type`, `steps`, `ramp`, `soften`, `repeat`, `wrap`, `detail`, `lighting`, `
|
|
80
|
+
A change to these parts reaches the materials made **after** it, with one exception: `look.materials.set` of the plain properties `color`, `emissive`, `emissiveIntensity`, `roughness`, `metalness`, `opacity`, `envMapIntensity`, `shininess` and `specular` also changes the materials already made for that role (no recompile; clearing the layer goes back to the style's value). Shader-changing keys (`type`, `steps`, `ramp`, `soften`, `repeat`, `wrap`, `detail`, `lighting`, `add`, `replace`) and all of `look.surface` are for new materials only (a Material already handed out, or cloned by your game, is not touched; catalog and describe say so as `appliesTo`, and a debug override warns). To bring the materials already out in line, call `engine.look.materials.rebuild()`: every material `makeMaterial` made that a mesh in the scene holds is made again from the current layers and put in its place (the call's own params, colors set by hand and wind / cloud shadow added after `makeMaterial` are kept; the old one is disposed; it returns `{ rebuilt, kept, ms }`). `engine.plugins.off / on` of a material or patch plugin calls it for you (`{ rebuild: false }` skips it, and the result then names this call), so a streamed world never mixes the old and new look; `plugins.list()` and `describe().slots` show the reach: `live` or `new materials only`. `engine.look.<part>.object` is the three.js object behind a part; for `materials` it is a function: `engine.look.materials.object('cloth')` is the last Material made for that role, `object()` all of them.
|
|
40
81
|
|
|
41
82
|
```js
|
|
42
83
|
const L = engine.look;
|
|
43
|
-
L.materials.set({
|
|
44
|
-
L.materials.
|
|
45
|
-
L.materials.replace('
|
|
46
|
-
L.surface.
|
|
47
|
-
L.surface.set({
|
|
48
|
-
L.surface.patch('lighting', glsl); // your threedogLighting(...), see recipe 43
|
|
84
|
+
L.materials.set({ cloth: { roughness: 0.4, color: 0xf2ece0 } }, { owner: 'shop' }); // on top of the style's materials.cloth (look.materials' style layer); any role name
|
|
85
|
+
L.materials.add('dim', { glsl: { fragment: { color_fragment: 'diffuseColor.rgb *= 0.8;' } } }, { roles: ['metal'] }); // one more ShaderPatch on those roles (h.remove() takes it out)
|
|
86
|
+
L.materials.replace('glass', new THREE.MeshPhysicalMaterial({ transmission: 1 })); // the role is this Material (or (params, purpose, engine) => Material)
|
|
87
|
+
L.surface.patch('lighting', glsl); // your own threedogLighting(...) on every lit material, recipe 43
|
|
88
|
+
L.surface.set({ lighting: { wrap: 0.3 }, detail: { strength: 0.15 } }); // or the spec-key shortcuts (recipe 43, last section)
|
|
49
89
|
L.ground.set({ shading: 'flat', colors: { grass: '#7cc06b' } }); // colors / biomeColors / steep / variation / shading rebuild the chunks
|
|
50
90
|
L.ground.set({ detail: { noise: 'paper', scale: 0.4, strength: 0.25 } }); // detail layer on the ground (style.terrain.detail)
|
|
51
91
|
L.ground.replace((e) => myGroundMaterial(e)); // Material or (engine) => Material; replace(null) gives it back
|
|
92
|
+
L.ground.replace(myGroundMaterial, { effects: false }); // drawn as given: no cloud shadow / season / detail patch (same word as vegetation.define)
|
|
52
93
|
L.wind.set({ frequency: 1.5, amplitude: 0.5 }); // live on every plant, planted ones too
|
|
53
|
-
L.wind.patch('sway', glsl);
|
|
94
|
+
L.wind.patch('sway', { glsl, tsl }); // threedogWind(...) / tsl: (ctx) => moved position; read when vegetation.define runs, so patch first
|
|
95
|
+
L.vegetation.patch('color', { glsl: 'diffuseColor.rgb *= 0.8;', tsl: c => c.color.mul(0.8) }); // part of the plant look, live on planted species
|
|
96
|
+
L.cloudShadow.replace({ glsl: 'reflectedLight.directDiffuse *= myShade(vThreedogWorld);', tsl: c => ({ directDiffuse: c.directDiffuse.mul(myShadeNode) }) });
|
|
97
|
+
L.cloudShadow.replace(false); // no engine cloud shadow anywhere: draw your own
|
|
98
|
+
L.season.replace(kind => ({ glsl: 'diffuseColor.rgb = mix(diffuseColor.rgb, vec3(1.0), uCover.y);', tsl: c => myTint(c, kind) })); // your own season / snow tint
|
|
54
99
|
```
|
|
55
100
|
|
|
56
|
-
- `materials`: `set` / `
|
|
101
|
+
- `materials`: `set` / `add` / `replace` all name roles (`add(name, shaderPatch, { roles })`; materials have no named hook, so no `patch`). `set` merges into spec entries; a role whose style entry is a Material or a function is changed with `replace`. Role names are free: invent new ones (`makeMaterial('lantern-glass')`); the engine only warns on a likely typo of a known role.
|
|
102
|
+
- `materials.glow(match, { night, day = 0, dusk = 0.3, owner })`: see "Night glow" below.
|
|
57
103
|
- `surface`: `set` / `patch('lighting' | 'detail', glsl)`; no `replace` (swap a whole material with `materials.replace`). `style.lighting` is the style layer.
|
|
58
104
|
- `ground` (terrain module): `set` / `patch('detail', glsl)` / `replace`. What `terrain({ colors, shading, material })` was given shows as owner `terrain()`.
|
|
59
|
-
- `wind` (vegetation module): `set` / `patch('sway', glsl)`; no `replace`. `style.wind` is the style layer.
|
|
105
|
+
- `wind` (vegetation module): `set` / `patch('sway', glsl | { glsl, tsl })`; no `replace`. `style.wind` is the style layer.
|
|
106
|
+
- `vegetation` (vegetation module): `patch('color', glsl | { glsl, tsl, uniforms })`, code in the `color` slot of every species' material, changed live. The whole plant look is replaced as a module: `engine.use(myPlants, { replaces: 'vegetation-look' })`.
|
|
107
|
+
- `cloudShadow` and `season` (core): `replace(spec)` puts your own patch (`{ glsl, tsl, uniforms?, pars?, slot? }`, slot `lighting` / `color` by default) in place of the engine's on every engine material, including ones built before the call; `replace(false)` removes the term; removing the layer gives the engine's back. The signals stay bound: `uCloud*` and `threedogCloudShadow(worldPos)`; `uFoliageTint` / `uGroundTint` / `uFoliageMix` / `uGroundMix`, `uCover` (cover amount alone, x foliage, y ground) and `threedogSeason(color, kind)`. `season` also takes `kind => spec` (kind `'foliage'` | `'ground'`). Each renderer draws its own form, and a missing one throws by name.
|
|
60
108
|
- `set({ role: { key } })` accepts a key `makeMaterial` reads (type, steps, ramp, soften, repeat, wrap, detail, lighting, or a three.js material property); a typo throws.
|
|
61
109
|
- `look.cloudShadow` (cloud shadows, core) stays its own part: its `shadow` is read by every material and by the weather, not only by surfaces.
|
|
62
110
|
|
|
111
|
+
### Night glow: emissive that follows daylight
|
|
112
|
+
|
|
113
|
+
Lit windows, neon signs, lamp bulbs, glowing mushrooms, screens: name the materials once and give the emissiveIntensity for night and day. The
|
|
114
|
+
color is yours (the material's `emissive`); the engine writes only `emissiveIntensity`, fading from `day` to `night` as daylight drops below `dusk`
|
|
115
|
+
(the calendar's daylight, else the sky's sun). `dusk` defaults to 0.3, roughly 17:00 to 18:00 and back in the morning: a starting value, not a
|
|
116
|
+
rule. Judge it in shots at dusk: a shop sign may want to come on while the sky is still bright (a higher `dusk`), a cave mushroom only in full
|
|
117
|
+
dark (a lower one).
|
|
118
|
+
```js
|
|
119
|
+
engine.look.materials.glow('window', { night: 2 }); // a material role (makeMaterial('window', { emissive: '#ffcc66' })) or material.name (a GLB's)
|
|
120
|
+
engine.look.materials.glow('neon', { night: 3, day: 0.4, dusk: 0.6 }); // signs stay faintly lit by day, full on early
|
|
121
|
+
const h = engine.look.materials.glow(m => m.name.startsWith('bulb'), { night: 1.5 }); // or a Material, or a filter
|
|
122
|
+
h.remove(); // each material gets its own emissiveIntensity back
|
|
123
|
+
```
|
|
124
|
+
**Headroom: why a glow turns into glare.** What reaches the tone curve is the emissive color times `emissiveIntensity`. A near-white color
|
|
125
|
+
(`#ffe6c0`) has no headroom: all three channels already sit near 1, so multiplied past 1 they clip to the same white under tone mapping, and
|
|
126
|
+
bloom spreads that white over what is around it (a lit sign becomes a white block with a smear). A saturated color at a lower intensity still
|
|
127
|
+
reads as light: its strongest channel carries the brightness, the others keep the hue, and bloom carries the halo. The numbers above are the
|
|
128
|
+
examples' current values, not targets. Judge the result with the look check of `threedog shot` or `threedog snap` at night: it names each
|
|
129
|
+
glowing material and light that blows pixels out, with its current emissive and intensity and how much detail is lost under it, as a fact to
|
|
130
|
+
weigh against what the game wants (some games want a blinding sign).
|
|
131
|
+
It finds models built later (templates near the player, streamed cells, a level loaded afterwards): the scene is searched again after it changed,
|
|
132
|
+
not every frame. `describe().look.materials` lists each rule (`glow:window`) and how many materials it found; a match without an emissive color or
|
|
133
|
+
with a black one warns once. For the light those windows throw on the street, add a few `lightPool` sources (recipe 09 §1b); a pool source's
|
|
134
|
+
`glow` stand-in is for one object near one light and does not follow the time of day.
|
|
135
|
+
|
|
63
136
|
## Water, weather, post
|
|
64
137
|
|
|
65
138
|
```js
|
|
@@ -70,39 +143,140 @@ engine.look.water.replace((engine, { uniforms, waves, surface }) => myMaterial);
|
|
|
70
143
|
|
|
71
144
|
engine.look.weather.set({ 'rain.speed': 10, 'snow.size': 8, 'lightning.brightness': 0.5, overcastColor: '#667' }); // rebuilds that field's particles once
|
|
72
145
|
engine.look.weather.patch('rain.fragment', wholeFragmentShaderText); // rain|snow . vertex|fragment: the WHOLE shader text, not a function
|
|
73
|
-
engine.look.weather.replace({ ash: { shape: 'soft', color: 0x555555 }, rain: { create } }); //
|
|
146
|
+
engine.look.weather.replace({ ash: { shape: 'soft', color: 0x555555 }, rain: { create } }); // null gives the fields back
|
|
74
147
|
|
|
75
148
|
engine.look.post.set({ bloom: { strength: 0.6 }, vignette: false }); // keys: '<effect>.<param>', '<effect>.enabled'
|
|
76
|
-
engine.look.post.
|
|
77
|
-
engine.look.post.add({ name: '
|
|
78
|
-
engine.look.post.replace([bloom(), grain()]); // swaps the whole chain; replace(null) gives
|
|
149
|
+
engine.look.post.add(new UnrealBloomPass(size, 0.6, 0.4, 0.85), { name: 'glow' }); // THE one way in: a Pass, a node function or an effect; returns { name, remove() }
|
|
150
|
+
engine.look.post.add({ name: 'tint', fuse: { glsl: 'color.rgb *= vec3(1.0, 0.9, 0.8);' }, slot: 'ldr', order: 5 }, { owner: 'cave' }); // a pixel snippet is an effect too
|
|
151
|
+
engine.look.post.replace([bloom(), grain()]); // swaps the whole chain; replace(null) gives back what add() put in
|
|
79
152
|
```
|
|
80
153
|
|
|
81
|
-
- Water: structural keys (`depthColor`, `foam`, the hooks, `replace`) rebuild the shared material once and hand it to every water mesh; the live keys only write a uniform. `water({ opacity
|
|
154
|
+
- Water: structural keys (`depthColor`, `foam`, the hooks, `replace`) rebuild the shared material once and hand it to every water mesh; the live keys only write a uniform. `water()` takes no look values (`water({ opacity })` throws naming `look.water.set`); `normalMap` also rebuilds once, `normalRepeat` retiles the meshes' UVs.
|
|
82
155
|
- Weather: a field the weather table lacks (`snow` in a desert) has no particles; setting it warns once. `replace({ [field]: spec })` holds one object per owner, so list every field you replace in each call; while a field is replaced, `set` on it is ignored.
|
|
83
|
-
- Post: `look.post.set` writes the `game` layer (keys `<effect>.<param>` and `<effect>.enabled`); style
|
|
84
|
-
- `describe().render.post` reads the same records (`
|
|
85
|
-
|
|
86
|
-
##
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
156
|
+
- Post: `look.post.set` writes the `game` layer (keys `<effect>.<param>` and `<effect>.enabled`); effects a style's plugins add (bloom, ao ...) sit on the style layer (owner `style:<pack>/<file>`, one per plugin); `engine.post.get(name)` only reads an effect. MSAA is `engine.post.setAntialias(on)`. Costly effects start off on low-tier devices: that is the engine layer (`describe().look.post['<effect>.enabled']` reads `writer: 'engine'` with a `why`), and `look.post` lists `<effect>.enabled` with `why` and `off`; a game's `set` turns it back on and reads `game`.
|
|
157
|
+
- `describe().render.post` reads the same records (`writer`: style, game, debug).
|
|
158
|
+
|
|
159
|
+
## Post effect chain
|
|
160
|
+
|
|
161
|
+
Post-processing is an ordered list of named effects, and **`engine.look.post.add(x, { name, slot, order, owner })` is the one way an effect gets
|
|
162
|
+
in**: game code, the game's `plugins/` folder (a file that exports the Pass or effect) and a style's `style/plugins/` all go through it, so every
|
|
163
|
+
effect has a name, an owner, on / off with `look.post.set({ <name>: false })` and a row in `describe().slots`. `x` is a plain three.js Pass (WebGL),
|
|
164
|
+
a TSL node function `(input, ctx) => node` (WebGPU), or an effect `{ name, create, node, fuse, slot, order, params }` (both renderers: give
|
|
165
|
+
`create` and `node`, or a `fuse`). Each runs in a slot, then by `order` (low first):
|
|
166
|
+
`scene` (replaces the scene render, one at a time, e.g. pixelation) -> `hdr` (linear color: outline, AO, bloom) -> tone mapping -> `ldr` (sRGB: LUT,
|
|
167
|
+
palette, grain, vignette) -> `final` (FXAA / SMAA). An effect is `{ name, slot, order, params, create(ctx) => pass, update?(pass, params) }`; under
|
|
168
|
+
WebGL the pass is any three.js postprocessing Pass, built the first time it is on (on WebGPU an effect gives `node` instead: recipe 56). To read the chain: `engine.post.object()` (the
|
|
169
|
+
EffectComposer, null until post first runs) and `engine.post.targets()` (its render targets); both stay the engine's (it rebuilds passes,
|
|
170
|
+
resizes, disposes), so change the chain through `look.post`. A plain Pass is placed by its kind: one that renders `engine.scene` itself
|
|
171
|
+
(`RenderPixelatedPass`, `SSAARenderPass`, `TAARenderPass`) goes in `scene` and replaces the engine's scene render (the scene is drawn once; a
|
|
172
|
+
second one throws), FXAA / SMAA / TAA in `final`, any other in `hdr` after the style's effects; a RenderPass of `engine.scene` and an OutputPass are
|
|
173
|
+
skipped (the engine has them). Without `{ name }` it is listed by class or shader name (`CopyShader#1`); its `remove()` does not dispose it.
|
|
174
|
+
A game that renders the canvas itself (its own composer) takes the frame: the engine stops drawing and warns once `[own-frame]`.
|
|
175
|
+
```js
|
|
176
|
+
import { bloom, outline, vignette, lut } from '@threedog/post-effects'; // shared effects come from the add-on, not from another game's style
|
|
177
|
+
import { LUTPass } from 'three/addons/postprocessing/LUTPass.js';
|
|
178
|
+
engine.look.post.add(outline({ thickness: 1.5 })); engine.look.post.add(vignette());
|
|
179
|
+
engine.look.post.add({ name: 'myLut', slot: 'ldr', params: { lut: myLut }, create: ({ params }) => new LUTPass({ lut: params.lut }) });
|
|
180
|
+
// a style brings its effects as plugin files, the same files a game's plugins/ takes: style/plugins/10-bloom.js
|
|
181
|
+
export default bloom({ strength: 0.2 }); // and in style/index.js: plugins: import.meta.glob('./plugins/*.js', { eager: true })
|
|
182
|
+
```
|
|
183
|
+
- The engine ships no effects. `@threedog/post-effects` (import only what you use) has `bloom`, `ao`, `outline`, `dof` (all `hdr`; outline and dof
|
|
184
|
+
read depth) and `lut` (contrast / saturation / warm-cool / optional 3D LUT), `grain`, `vignette`, `chromatic` (`ldr`). An added effect is on
|
|
185
|
+
(`enabled: false` adds it off, for `look.post.set({ '<name>.enabled': true })` later). The costly ones (`bloom`, `ao`, `dof`, outline
|
|
186
|
+
`normal`/`both`) a style's plugins bring start off on low-tier devices (`look.post.set({ ao: true })` turns one on; `threedog shot` renders the
|
|
187
|
+
desktop tier and names what a tier leaves out, `--tier low` checks the low one). To take one of a pack's effects out: `engine.plugins.off('<pack>/<file>')`
|
|
188
|
+
or `look.post.set({ ao: false })`; to add one on top: a game plugin file or `look.post.add`.
|
|
189
|
+
- Depth: an effect that reads scene depth (`needsDepth: true`, e.g. `outline`) must run before any pass that swaps buffers (a `ShaderPass`, a
|
|
190
|
+
scene-slot pixelation pass, the tone-mapping output). A chain that breaks this throws when the effect is added or enabled, naming both effects;
|
|
191
|
+
give the depth reader a lower `order`. `dof` keeps the scene depth (`pass.keepsDepth = true`), so `dof` and `outline` can both be on while `dof`
|
|
192
|
+
has the lower `order` (default: dof 5, outline 10). `threedog style check` reports the other order as an error.
|
|
193
|
+
- Pause or unload: `look.post.set({ bloom: false })` pauses an effect where it is (its place, params and owner stay); `engine.plugins.off('<file>')`
|
|
194
|
+
unloads the plugin (the effect leaves the chain; `on` plugs it again). Either way the effect comes back in the same place: inside a slot,
|
|
195
|
+
`order` decides, and equal orders keep the order the names were first added in (a plugin's effects are placed in plugin-list order, even
|
|
196
|
+
one that starts off), so off / on never reorders the chain.
|
|
197
|
+
- On / off is `look.post.set({ bloom: false })` for every effect, whoever added it (there is no `createEngine({ post })`: the engine ships no
|
|
198
|
+
effect to switch on, add one with `look.post.add(bloom())`). MSAA (`antialias`) works with every effect on. The settings menu shows `bloom` / `ao` toggles only when the style registers effects with those names; a toggle the player changes is written under owner `settings` (`writer: 'game:settings'`), and the menu writes nothing for a value it only re-applies unchanged.
|
|
199
|
+
- `fuse`: a light color effect can skip its own fullscreen pass by carrying a GLSL snippet instead of `create()`:
|
|
200
|
+
`fuse: { uniforms: { uMyAmount: 'float' }, values: p => ({ uMyAmount: p.amount }), glsl: 'color.rgb *= 1.0 - uMyAmount * length(vUv - 0.5);' }`.
|
|
201
|
+
Fused effects that are on and next to each other in one slot (never `scene`) compile into one shader and draw in one pass, in `order`. The
|
|
202
|
+
snippet edits `vec4 color` and may use `vUv`, `tDiffuse`, `uTime`, `uResolution`, `fxHash(vec2)`; uniform names are shared by the group, so prefix
|
|
203
|
+
them with the effect name. A snippet that samples `tDiffuse` elsewhere (blur, color fringe) sets `reads: true` and starts a new group.
|
|
204
|
+
`look.post.add({ name, fuse: { glsl }, slot: 'ldr' })` adds just a snippet.
|
|
205
|
+
- Outline: `outline({ mode: 'depth' | 'normal' | 'both' })`: `depth` (default, silhouettes), `normal` (creases; draws the scene once more with
|
|
206
|
+
normals, so it is `costly`), `both`. `fadeWithDistance: false` keeps lines at any distance; `wobble: 1.5` jitters lines by up to 1.5 px at 8 steps a
|
|
207
|
+
second. To exempt objects: `outline({ offLayer: OUTLINE_OFF_LAYER })` and `mesh.layers.enable(OUTLINE_OFF_LAYER)` (one extra render of just
|
|
208
|
+
those objects; nothing when `offLayer` is `null`).
|
|
209
|
+
- Ambient occlusion (darker creases and contact corners): `ao({ radius, intensity })` wraps three's `GTAOPass`; `radius` is in world units
|
|
210
|
+
(default 0.25), `intensity` 0..1 (default 1), both change in place: `look.post.set({ 'ao.enabled': true, 'ao.radius': 0.6 })` (with `ao()` added
|
|
211
|
+
by a style plugin or the game), or `look.post.add(ao({ enabled: true }))` at run time. Order 20 runs it before bloom and the tone mapping. It follows resize,
|
|
212
|
+
render scale and MSAA like every effect. It draws the scene once more with normals: points and lines are skipped, and a vertex-moving shader
|
|
213
|
+
patch (wind) is not applied there, so swaying leaves get the AO of their rest pose. Cost on a laptop GPU (AMD 780M, 1280x720, MSAA, a street
|
|
214
|
+
scene): about +6 ms a frame (4.4 -> 10.7 ms). Other GTAOPass settings (`samples`, `thickness`, `output`):
|
|
215
|
+
`engine.post.object().passes.find(p => p.gtaoMaterial)`.
|
|
216
|
+
|
|
217
|
+
## Who writes it: the ownership table
|
|
218
|
+
|
|
219
|
+
Some three.js values the engine writes **on its own**, every frame or on a timer: the sky drives the sun, the camera module places the camera.
|
|
220
|
+
Each of them is registered once (`core/owned.js`), and every one behaves the same way:
|
|
221
|
+
|
|
222
|
+
- **Engine** (default): the engine writes it. Adjust it while the engine keeps driving: the `set` call in the table.
|
|
223
|
+
- **Taken** (`manual`): `engine.look.<part>.manual(key)` stops the engine writing it; the three.js object is yours (`engine.lights.sun.intensity = 3` sticks).
|
|
224
|
+
`manual(key, false)` (or the handle's `remove()`) gives it back. Keys match by dotted prefix: `manual('sun')` takes `sun.intensity` and `sun.color`;
|
|
225
|
+
`manual()` takes every key of the part. This is the one takeover entry: no module option starts a value taken over (`sky({ sun: 'manual' })`
|
|
226
|
+
throws and names the call). A fog of your own is the direct write below: `scene.fog = new THREE.Fog(...)`.
|
|
227
|
+
- **Written directly** without `manual`: the engine notices, **stops writing it and keeps your value**, and warns once with the `manual` call and the
|
|
228
|
+
hand-back call. This happens in release builds too (only the warning is dev-only), so a game behaves the same with and without checks.
|
|
229
|
+
- A `timeline.tween` on an object is a temporary takeover of that object only: no warning, no hand-over (other objects stay checked).
|
|
230
|
+
|
|
231
|
+
`engine.describe().owned` lists every registered value and who writes it now, as `writer` (`engine`, `manual:game`,
|
|
232
|
+
`three (engine yielded)`); the same `writer` shows next to a look value, `describe().look.<part>.<key>.writer`. (Without a takeover it is the layer that set the value, `game` or `game:<owner>`; `owner` is only ever the name you pass.) A test (`tests/specs/owned.mjs`) runs the three
|
|
233
|
+
behaviors for every registered value and fails when one is registered without a row here.
|
|
234
|
+
|
|
235
|
+
| id | part | written when | take it | adjust while the engine drives |
|
|
236
|
+
|---|---|---|---|---|
|
|
237
|
+
| `sun.intensity` | lights | sky, every frame (keyframes, weather) | `engine.look.lights.manual('sun')` | `engine.look.lights.set({ sun: { intensity: 2 } })` |
|
|
238
|
+
| `sun.color` | lights | sky, every frame | `engine.look.lights.manual('sun.color')` | `engine.look.lights.set({ sun: { color: '#ffd9a0' } })` |
|
|
239
|
+
| `sun.direction` | lights | sky, every frame (time of day) | `engine.look.lights.manual('sun.direction')`: aim it by `sun.position` relative to `sun.target`; the shadow box still follows | - |
|
|
240
|
+
| `shadow.follow` | shadow | sky, every frame (shadow box center = `sun.target`); without a sky the baseline sun follows `engine.focus` | `engine.look.shadow.manual('follow')`; no sky: `engine.look.lights.manual('shadow.follow')` | `engine.look.shadow.set({ follow: 'focus' \| 'camera' \| object3D \| () => Vector3 \| false })`, size: `set({ extent })` |
|
|
241
|
+
| `hemi` | lights | sky, every frame | `engine.look.lights.manual('hemi')` | `engine.look.lights.set({ hemi: { intensity: 0.8 } })` |
|
|
242
|
+
| `fog` | fog | sky, every frame (color, distance) | `engine.look.fog.manual()` | `engine.look.fog.set({ color: '#cfd8e0', far: 300 })` |
|
|
243
|
+
| `toneMapping` | tone | once, at `createEngine` (`style.toneMapping`, else AgX); a direct write yields with no warning (it is the documented way) | `engine.renderer.toneMapping = THREE.ACESFilmicToneMapping`; an own curve as a post stage: `engine.look.post.add({ name, slot: 'tone', create })` (or `node` on WebGPU; replaces OutputPass / renderOutput; outputs display color), or `engine.look.tone.manual('toneMapping')`; `manual('toneMapping', false)` writes the creation curve back | - |
|
|
244
|
+
| `exposure` | tone | sky, every frame, only with exposure keyframes | `engine.look.tone.manual('exposure')` | `engine.look.tone.set({ exposure: 1.2 })` |
|
|
245
|
+
| `background` | sky | sky: a backdrop color or skybox every frame; with the dome the dome hides when you take it | `engine.look.sky.manual('background')`; whole sky: `look.sky.replace(texture \| object3D)` | `engine.look.sky.set({ backdrop: '#335577' })` |
|
|
246
|
+
| `env` | env | sky, every frame: the room map's intensity (ambient column); a `'sky'` environment is rebuilt on its interval | `engine.look.env.manual()` | `engine.look.env.set({ intensity: 0.8 })`, `look.env.replace('sky' \| 'asset' \| myTexture \| myPmremTarget)` |
|
|
247
|
+
| `camera.far` | view | fog distance / terrain view range (`terrain({ viewFog })`, `setViewChunks`) | `engine.look.view.manual('far')` | - |
|
|
248
|
+
| `camera.fov` | view | the settings menu fov slider, camera modules (first person / rts fov, fixed shots, back to the install fov on a switch) | `engine.look.view.manual('fov')` | - |
|
|
249
|
+
| `pixelRatio` | view | adaptive resolution, about once a second while slow | `engine.look.view.manual('pixelRatio')` | `engine.setPixelRatio(1.5)` |
|
|
250
|
+
| `camera` (position, rotation) | view | the camera module, every frame | `const cam = engine.takeCamera('me')` (`cam.remove()` gives it back) | - |
|
|
251
|
+
| `post.chain` | post | whenever the effect list changes (set / add / replace, MSAA): the engine rebuilds the composer passes (WebGL) or `pipeline.outputNode` (WebGPU) | `engine.look.post.manual()`: the built chain stays as you left it in `engine.post.object()`; `manual(false)` rebuilds it from the list. A write to `object()` without `manual` does not yield: the next chain change replaces it | `engine.look.post.set({ bloom: { strength: 0.6 } })` |
|
|
252
|
+
| `shadow.csm` (not a property: a list) | shadow | while `cascades > 1`: the `csm` patch goes on every built-in lit material, yours too (else N times as bright) | - (lower `cascades` to 1); your ShaderMaterial is left alone until `engine.look.shadow.include(mat)` | - |
|
|
253
|
+
|
|
254
|
+
Material live keys (`look.materials.set({ wood: { color } })` on materials already made) are per material, not one row: a key the
|
|
255
|
+
`makeMaterial('wood', { color })` call passed itself is never overwritten, and a value you set by hand afterwards (`m.color.set(...)`) is
|
|
256
|
+
skipped with one warning. Order: by hand > the call's params > `look.materials.set` > the style.
|
|
257
|
+
|
|
258
|
+
Not in this table, because the engine writes them once rather than keeps writing them: automatic batching (it moves engine-placed meshes to layer 31
|
|
259
|
+
and says so once in the dev console and in `describe().perf.batching`; turn it off per object with `userData.batch = false`, see
|
|
260
|
+
[05-props-bake.md](05-props-bake.md) §2b) and `castShadow` on generator props (set when the model is made: a generator's own flags are kept, the
|
|
261
|
+
manifest entry can set them; change it on the object afterwards).
|
|
262
|
+
|
|
263
|
+
## How look values stack
|
|
264
|
+
|
|
265
|
+
Every `look.<part>.<key>` is a shared point (recipe 55), so one rule holds for all of them: **the game sets a base value, effects multiply on top,
|
|
266
|
+
the player's settings cap it.**
|
|
267
|
+
```js
|
|
268
|
+
engine.look.lights.set({ sun: { intensity: 3 } }, { owner: 'arena' }); // the base (replaces the style / keyframes); rain still dims it: 3 × 0.6
|
|
269
|
+
engine.mod('look.lights.sun.intensity', { owner: 'cave', mul: 0.3 }); // cooperate: entries multiply; the handle's remove() ends yours
|
|
270
|
+
engine.mod('look.fog.far', { owner: 'storm', mul: 0.6, layer: 'effect' }); // an effect module writes the effect layer
|
|
271
|
+
engine.describe().shared['look.lights.sun.intensity'].how; // 'arena 3 × sky:horizon 1 × weather 0.6 × cave 0.3'
|
|
272
|
+
```
|
|
273
|
+
- `set` decides, `mul` / `add` cooperate. Two owners `set` one value on one layer is the dev error `shared-conflict`; copy one of its fixes.
|
|
274
|
+
- The exact number whatever the weather: `engine.look.lights.manual('sun')` and write the three.js light, or set on `{ layer: 'system' }`.
|
|
275
|
+
- The settings menu only restricts (`shadows` off is `look.shadow.enabled` set false on the settings layer); a game's `enabled: true` does not
|
|
276
|
+
switch them back on, and a cutscene's `false` is not undone by the menu. `describe().shared` names who decided and who is hidden.
|
|
277
|
+
- A direct three.js write (`engine.lights.hemi.intensity = 0.2`) still works: the engine yields, describe says `three (engine yielded)`.
|
|
278
|
+
- `look.sky.tint`, `look.ground.cover` (blend by amount) and `look.sky.flash` (adds) are points of the same kind, written with `engine.mod`.
|
|
279
|
+
|
|
280
|
+
## Lower-level forms that stay
|
|
281
|
+
|
|
282
|
+
Per-call `makeMaterial(role, params)` keys win for that one material; `applyEffects(mat, { patches })` is the low-level form of `look.materials.add(name, spec, { roles })`; `style.materials`, `style.terrain.*`, `style.wind.*` and `style.lighting` are the style layer of `look.materials` / `look.ground` / `look.wind` / `look.surface`.
|