threedog 0.5.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +276 -1
- package/README.md +18 -13
- package/core/{Animator.js → assets/Animator.js} +28 -18
- package/core/{Assets.js → assets/Assets.js} +116 -61
- package/core/{Baked.js → assets/Baked.js} +16 -25
- package/core/assets/assetEntry.js +237 -0
- package/core/{assetHot.js → assets/assetHot.js} +7 -6
- package/core/{assetLoad.js → assets/assetLoad.js} +66 -29
- package/core/assets/assetLod.js +113 -0
- package/core/{assetManifest.js → assets/assetManifest.js} +23 -12
- package/core/{assetReport.js → assets/assetReport.js} +9 -15
- package/core/{namedModel.js → assets/namedModel.js} +24 -16
- package/core/{Audio.js → audio/Audio.js} +27 -24
- package/core/{audioRules.js → audio/audioRules.js} +8 -5
- package/core/{audioVoice.js → audio/audioVoice.js} +17 -30
- package/core/{Events.js → base/Events.js} +3 -3
- package/core/{I18n.js → base/I18n.js} +10 -10
- package/core/{Random.js → base/Random.js} +5 -4
- package/core/{easing.js → base/easing.js} +1 -1
- package/core/{errorCodes.js → base/errorCodes.js} +154 -139
- package/core/{errorHints.js → base/errorHints.js} +9 -10
- package/core/{errors.js → base/errors.js} +9 -9
- package/core/{events.generated.js → base/events.generated.js} +2 -0
- package/core/{math.js → base/math.js} +22 -4
- package/core/{params.js → base/params.js} +3 -4
- package/core/base/util.js +32 -0
- package/core/{validate.js → base/validate.js} +29 -8
- package/core/{Engine.js → engine/Engine.js} +112 -105
- package/core/{Loading.js → engine/Loading.js} +4 -2
- package/core/{copies.js → engine/copies.js} +4 -4
- package/core/{headlessLoad.js → engine/headlessLoad.js} +4 -4
- package/core/{lifecycle.js → engine/lifecycle.js} +16 -16
- package/core/{loop.js → engine/loop.js} +80 -52
- package/core/{moduleSlots.js → engine/moduleSlots.js} +35 -10
- package/core/{moduleTypes.js → engine/moduleTypes.js} +30 -18
- package/core/{modules.js → engine/modules.js} +20 -17
- package/core/engine/page.js +125 -0
- package/core/{plugins.js → engine/plugins.js} +68 -103
- package/core/{services.js → engine/services.js} +47 -40
- package/core/{startup.js → engine/startup.js} +35 -35
- package/core/{Input.js → input/Input.js} +41 -27
- package/core/{inputContext.js → input/inputContext.js} +14 -5
- package/core/{inputPad.js → input/inputPad.js} +1 -1
- package/core/{inputPointer.js → input/inputPointer.js} +8 -2
- package/core/{inputTouch.js → input/inputTouch.js} +1 -1
- package/core/{Budget.js → inspect/Budget.js} +23 -22
- package/core/{DebugOverrides.js → inspect/DebugOverrides.js} +60 -31
- package/core/{Describe.js → inspect/Describe.js} +33 -30
- package/core/{Inspect.js → inspect/Inspect.js} +14 -9
- package/core/{InspectMaterials.js → inspect/InspectMaterials.js} +8 -10
- package/core/{InspectPerf.js → inspect/InspectPerf.js} +29 -16
- package/core/{InspectScene.js → inspect/InspectScene.js} +8 -5
- package/core/{MaterialInfo.js → inspect/MaterialInfo.js} +9 -6
- package/core/inspect/UrlState.js +182 -0
- package/core/{catalog.js → inspect/catalog.js} +18 -5
- package/core/{checks.js → inspect/checks.js} +7 -5
- package/core/{debugView.js → inspect/debugView.js} +8 -8
- package/core/inspect/describeRender.js +148 -0
- package/core/{describeText.js → inspect/describeText.js} +17 -12
- package/core/inspect/geometryWatch.js +38 -0
- package/core/{lightWatch.js → inspect/lightWatch.js} +11 -9
- package/core/inspect/pictureWriters.js +342 -0
- package/core/{shaderCost.js → inspect/shaderCost.js} +1 -1
- package/core/{Ops.js → ops/Ops.js} +16 -11
- package/core/{control.js → ops/control.js} +13 -12
- package/core/ops/holds.js +139 -0
- package/core/{opsAtomic.js → ops/opsAtomic.js} +2 -1
- package/core/{opsCheck.js → ops/opsCheck.js} +4 -5
- package/core/{opsGuard.js → ops/opsGuard.js} +3 -3
- package/core/{opsRun.js → ops/opsRun.js} +7 -4
- package/core/{owned.js → ops/owned.js} +37 -37
- package/core/{sharedPoint.js → ops/sharedPoint.js} +13 -27
- package/core/{stackFrames.js → ops/stackFrames.js} +17 -6
- package/core/{stacks.js → ops/stacks.js} +18 -20
- package/core/{wrap.js → ops/wrap.js} +8 -6
- package/core/{SaveStore.js → saves/SaveStore.js} +1 -1
- package/core/{Saves.js → saves/Saves.js} +58 -36
- package/core/{saveApply.js → saves/saveApply.js} +13 -9
- package/core/{saveFiles.js → saves/saveFiles.js} +17 -15
- package/core/{saveValues.js → saves/saveValues.js} +20 -3
- package/core/{saveVersions.js → saves/saveVersions.js} +4 -17
- package/core/{session.js → saves/session.js} +31 -17
- package/core/{Rays.js → scene/Rays.js} +27 -24
- package/core/{Views.js → scene/Views.js} +15 -6
- package/core/{adaptive.js → scene/adaptive.js} +15 -8
- package/core/{canvasBox.js → scene/canvasBox.js} +2 -3
- package/core/{engineCamera.js → scene/engineCamera.js} +1 -1
- package/core/{gameLights.js → scene/gameLights.js} +24 -7
- package/core/{grayMap.js → scene/grayMap.js} +8 -2
- package/core/{grid.js → scene/grid.js} +4 -4
- package/core/{gridLoad.js → scene/gridLoad.js} +1 -1
- package/core/{ground.js → scene/ground.js} +9 -9
- package/core/{movement.js → scene/movement.js} +3 -3
- package/core/scene/pictureSlots.js +33 -0
- package/core/{sceneDelta.js → scene/sceneDelta.js} +14 -6
- package/core/{sceneMethods.js → scene/sceneMethods.js} +36 -20
- package/core/scene/stepPoses.js +55 -0
- package/core/{targeting.js → scene/targeting.js} +4 -5
- package/core/{thingExplain.js → scene/thingExplain.js} +7 -6
- package/core/{thingOps.js → scene/thingOps.js} +4 -3
- package/core/{things.js → scene/things.js} +19 -6
- package/core/{threePatches.js → scene/threePatches.js} +1 -1
- package/core/{tier.js → scene/tier.js} +1 -1
- package/core/scene/view.js +44 -0
- package/core/{Batching.js → stream/Batching.js} +85 -27
- package/core/{Stream.js → stream/Stream.js} +62 -33
- package/core/{batchGroups.js → stream/batchGroups.js} +18 -9
- package/core/{chunkStream.js → stream/chunkStream.js} +41 -1
- package/core/{scatter.js → stream/scatter.js} +2 -2
- package/core/{streamSources.js → stream/streamSources.js} +12 -7
- package/core/{Commits.js → threads/Commits.js} +6 -5
- package/core/{Jobs.js → threads/Jobs.js} +12 -10
- package/core/{Threads.js → threads/Threads.js} +16 -16
- package/core/{threadPure.js → threads/threadPure.js} +7 -5
- package/core/{threadServe.js → threads/threadServe.js} +3 -3
- package/core/{Clock.js → time/Clock.js} +17 -10
- package/core/{dayTime.js → time/dayTime.js} +5 -1
- package/core/{skip.js → time/skip.js} +18 -17
- package/core/{time.js → time/time.js} +18 -12
- package/core/{uiClock.js → time/uiClock.js} +4 -4
- package/docs/AI.md +70 -63
- package/docs/API.md +30 -29
- package/docs/CODEMAP.md +98 -223
- package/docs/COMMANDS.md +80 -69
- package/docs/CONVENTIONS.md +87 -41
- package/docs/MIGRATING-0.7.md +39 -0
- package/docs/MIGRATING-0.8.md +169 -0
- package/docs/THREE.md +100 -49
- package/docs/api/assets.md +17 -16
- package/docs/api/audio.md +8 -7
- package/docs/api/budget.md +8 -4
- package/docs/api/calendar.md +10 -11
- package/docs/api/cameraRig.md +29 -29
- package/docs/api/characters.md +26 -19
- package/docs/api/clock.md +1 -1
- package/docs/api/collision.md +14 -11
- package/docs/api/content.md +6 -6
- package/docs/api/dialogue.md +3 -3
- package/docs/api/engine.md +82 -53
- package/docs/api/events.md +5 -3
- package/docs/api/flow.md +1 -1
- package/docs/api/grids.md +9 -2
- package/docs/api/ground.md +4 -5
- package/docs/api/hud.md +4 -1
- package/docs/api/i18n.md +6 -6
- package/docs/api/input.md +10 -9
- package/docs/api/interactions.md +6 -4
- package/docs/api/inventory.md +10 -11
- package/docs/api/jobs.md +5 -5
- package/docs/api/level.md +7 -8
- package/docs/api/lightPool.md +2 -7
- package/docs/api/music.md +3 -3
- package/docs/api/nav.md +10 -10
- package/docs/api/occlusion.md +5 -0
- package/docs/api/openWorld.md +1 -1
- package/docs/api/particles.md +8 -5
- package/docs/api/photo.md +4 -2
- package/docs/api/pickups.md +7 -1
- package/docs/api/post.md +24 -5
- package/docs/api/quests.md +3 -3
- package/docs/api/rays.md +5 -7
- package/docs/api/rigid.md +27 -18
- package/docs/api/saves.md +8 -7
- package/docs/api/settings.md +9 -8
- package/docs/api/sky.md +17 -14
- package/docs/api/stream.md +7 -7
- package/docs/api/swarm.md +34 -0
- package/docs/api/terrain.md +17 -12
- package/docs/api/terrainDraw.md +12 -0
- package/docs/api/timeline.md +2 -2
- package/docs/api/tools.md +30 -26
- package/docs/api/triggers.md +2 -0
- package/docs/api/vars.md +1 -1
- package/docs/api/vegetation.md +11 -5
- package/docs/api/vegetationDraw.md +10 -0
- package/docs/api/water.md +7 -3
- package/docs/api/weather.md +11 -6
- package/docs/api/weatherDraw.md +10 -0
- package/docs/api/world.md +6 -6
- package/docs/recipes/01-new-game.md +38 -57
- package/docs/recipes/02-npc.md +19 -20
- package/docs/recipes/03-items-pickups.md +47 -42
- package/docs/recipes/04-quests.md +3 -4
- package/docs/recipes/05-props-bake.md +72 -66
- package/docs/recipes/06-clock-events.md +30 -21
- package/docs/recipes/07-flow-scenes-pause.md +21 -17
- package/docs/recipes/08-weather-sky.md +117 -75
- package/docs/recipes/09-materials-lights-models.md +171 -0
- package/docs/recipes/10-blender-level.md +6 -7
- package/docs/recipes/11-vehicles.md +33 -25
- package/docs/recipes/12-navmesh.md +9 -8
- package/docs/recipes/13-animation.md +50 -22
- package/docs/recipes/14-custom-module.md +20 -17
- package/docs/recipes/15-perf.md +52 -29
- package/docs/recipes/16-dev-bridge.md +47 -57
- package/docs/recipes/18-world.md +45 -30
- package/docs/recipes/19-shooting-picking.md +11 -7
- package/docs/recipes/20-content-actions-save.md +36 -37
- package/docs/recipes/21-camera.md +41 -8
- package/docs/recipes/22-shop-gold.md +0 -4
- package/docs/recipes/23-ops.md +11 -11
- package/docs/recipes/26-ui-parts.md +56 -22
- package/docs/recipes/27-net.md +0 -2
- package/docs/recipes/28-terrain.md +126 -30
- package/docs/recipes/29-grid.md +16 -7
- package/docs/recipes/30-templates.md +62 -21
- package/docs/recipes/31-audio.md +9 -9
- package/docs/recipes/32-action-game.md +32 -9
- package/docs/recipes/33-stream-sources.md +2 -2
- package/docs/recipes/34-environment-lighting.md +164 -52
- package/docs/recipes/35-picture-from-reference.md +140 -0
- package/docs/recipes/36-ground-plants.md +105 -0
- package/docs/recipes/40-scene.md +105 -30
- package/docs/recipes/{43-shader-patches-surface-looks.md → 43-shader-patches-surfaces.md} +74 -106
- package/docs/recipes/44-water-weather-hooks.md +196 -0
- package/docs/recipes/45-cascaded-shadows.md +145 -25
- package/docs/recipes/46-blender-art-route.md +21 -25
- package/docs/recipes/49-game-module-contract.md +5 -5
- package/docs/recipes/50-own-renderer.md +3 -3
- package/docs/recipes/52-around-the-picture.md +137 -0
- package/docs/recipes/53-ground-up-close.md +65 -28
- package/docs/recipes/55-mods-time-wrap.md +25 -17
- package/docs/recipes/56-webgpu-tsl.md +73 -28
- package/docs/recipes/57-control.md +47 -1
- package/docs/recipes/58-input.md +3 -0
- package/docs/recipes/59-depth-post-effects.md +5 -5
- package/docs/recipes/60-judge-the-picture.md +47 -27
- package/docs/recipes/61-deploy.md +27 -0
- package/docs/recipes/62-picture-code.md +276 -0
- package/docs/recipes/63-third-person-start.md +90 -0
- package/docs/recipes/64-particles.md +35 -0
- package/docs/recipes/65-swarm.md +140 -0
- package/examples/action/.threedog/content-index.json +1 -1
- package/examples/action/GAMEMAP.md +9 -7
- package/examples/action/main.js +5 -4
- package/examples/action/models.js +12 -14
- package/examples/action/picture/index.js +13 -0
- package/examples/action/picture/lights.js +35 -0
- package/examples/action/picture/materials.js +8 -0
- package/examples/action/picture/palette.js +33 -0
- package/examples/perf-island/.threedog/content-index.json +1 -0
- package/examples/{sheepisland → perf-island}/GAMEMAP.md +18 -14
- package/examples/{sheepisland → perf-island}/assets.js +2 -2
- package/examples/{sheepisland → perf-island}/content/templates.js +1 -1
- package/examples/{sheepisland → perf-island}/content/vegetation.js +3 -1
- package/examples/{sheepisland → perf-island}/main.js +22 -16
- package/examples/{sheepisland/style → perf-island}/models.js +13 -24
- package/examples/{sheepisland → perf-island}/params.js +1 -1
- package/examples/perf-island/picture/index.js +20 -0
- package/examples/perf-island/picture/lights.js +34 -0
- package/examples/perf-island/picture/materials.js +61 -0
- package/examples/perf-island/picture/palette.js +60 -0
- package/examples/perf-island/picture/sky.js +20 -0
- package/examples/{sheepisland → perf-island}/views.js +1 -1
- package/examples/plain-picture/.threedog/content-index.json +1 -0
- package/examples/plain-picture/GAMEMAP.md +91 -0
- package/examples/plain-picture/main.js +48 -0
- package/examples/plain-picture/picture/index.js +21 -0
- package/examples/plain-picture/picture/lights.js +54 -0
- package/examples/plain-picture/picture/materials.js +24 -0
- package/examples/plain-picture/picture/palette.js +16 -0
- package/examples/plain-picture/picture/sky.js +37 -0
- package/examples/pullable.json +31 -9
- package/examples/rc2d/GAMEMAP.md +10 -4
- package/examples/rc2d/README.md +11 -6
- package/examples/rc2d/main.js +26 -36
- package/examples/rc2d/picture/index.js +18 -0
- package/examples/rc2d/picture/lights.js +11 -0
- package/examples/rc2d/picture/materials.js +18 -0
- package/examples/rc2d/picture/palette.js +15 -0
- package/examples/rc2d/picture/post.js +11 -0
- package/examples/rc2d/rc2d.js +18 -28
- package/examples/styletest/.threedog/content-index.json +1 -1
- package/examples/styletest/GAMEMAP.md +15 -10
- package/examples/styletest/main.js +20 -30
- package/examples/styletest/models.js +29 -29
- package/examples/styletest/params.js +1 -4
- package/examples/styletest/picture/env.js +38 -0
- package/examples/styletest/picture/index.js +16 -0
- package/examples/styletest/picture/lights.js +9 -0
- package/examples/styletest/picture/materials.js +28 -0
- package/examples/styletest/picture/palette.js +22 -0
- package/examples/techniques/contact-shadows/README.md +22 -23
- package/examples/techniques/contact-shadows/contactShadows.js +32 -16
- package/examples/techniques/contact-shadows/main.js +20 -18
- package/examples/techniques/contact-shadows/picture/index.js +14 -0
- package/examples/techniques/contact-shadows/picture/lights.js +34 -0
- package/examples/techniques/contact-shadows/picture/materials.js +12 -0
- package/examples/techniques/contact-shadows/picture/palette.js +17 -0
- package/examples/techniques/day-night-grade/README.md +13 -16
- package/examples/techniques/day-night-grade/main.js +15 -25
- package/examples/techniques/day-night-grade/picture/index.js +20 -0
- package/examples/techniques/day-night-grade/picture/lights.js +45 -0
- package/examples/techniques/day-night-grade/picture/materials.js +15 -0
- package/examples/techniques/day-night-grade/picture/palette.js +59 -0
- package/examples/techniques/day-night-grade/picture/post.js +25 -0
- package/examples/techniques/day-night-grade/picture/sky.js +33 -0
- package/examples/techniques/interior-light/README.md +16 -13
- package/examples/techniques/interior-light/interiorLight.js +19 -17
- package/examples/techniques/interior-light/main.js +31 -68
- package/examples/techniques/interior-light/picture/index.js +24 -0
- package/examples/techniques/interior-light/picture/lights.js +52 -0
- package/examples/techniques/interior-light/picture/materials.js +13 -0
- package/examples/techniques/interior-light/picture/palette.js +32 -0
- package/examples/techniques/interior-light/picture/sky.js +40 -0
- package/examples/techniques/modular-building/README.md +8 -6
- package/examples/techniques/modular-building/kit.js +2 -2
- package/examples/techniques/modular-building/main.js +9 -17
- package/examples/techniques/modular-building/picture/index.js +17 -0
- package/examples/techniques/modular-building/picture/lights.js +26 -0
- package/examples/techniques/modular-building/picture/materials.js +13 -0
- package/examples/techniques/modular-building/picture/palette.js +23 -0
- package/examples/techniques/night-lights/README.md +15 -14
- package/examples/techniques/night-lights/main.js +20 -43
- package/examples/techniques/night-lights/nightLights.js +25 -21
- package/examples/techniques/night-lights/picture/index.js +18 -0
- package/examples/techniques/night-lights/picture/lights.js +44 -0
- package/examples/techniques/night-lights/picture/materials.js +15 -0
- package/examples/techniques/night-lights/picture/palette.js +34 -0
- package/examples/techniques/night-lights/picture/post.js +9 -0
- package/examples/techniques/night-lights/picture/sky.js +36 -0
- package/examples/techniques/outlines-and-rim/README.md +2 -2
- package/examples/techniques/outlines-and-rim/main.js +15 -38
- package/examples/techniques/outlines-and-rim/outlines.js +3 -3
- package/examples/techniques/outlines-and-rim/picture/index.js +16 -0
- package/examples/techniques/outlines-and-rim/picture/lights.js +18 -0
- package/examples/techniques/outlines-and-rim/picture/materials.js +11 -0
- package/examples/techniques/outlines-and-rim/picture/palette.js +16 -0
- package/examples/techniques/outlines-and-rim/picture/post.js +10 -0
- package/examples/techniques/procedural-animation/README.md +6 -4
- package/examples/techniques/procedural-animation/main.js +9 -7
- package/examples/techniques/procedural-animation/picture/index.js +15 -0
- package/examples/techniques/procedural-animation/picture/lights.js +35 -0
- package/examples/techniques/procedural-animation/picture/materials.js +10 -0
- package/examples/techniques/procedural-animation/picture/palette.js +16 -0
- package/examples/techniques/procedural-animation/picture/sky.js +31 -0
- package/examples/techniques/procedural-animation/proceduralAnim.js +1 -1
- package/examples/techniques/procedural-surface/README.md +2 -0
- package/examples/techniques/procedural-surface/main.js +17 -55
- package/examples/techniques/procedural-surface/picture/index.js +14 -0
- package/examples/techniques/procedural-surface/picture/lights.js +18 -0
- package/examples/techniques/procedural-surface/picture/materials.js +34 -0
- package/examples/techniques/procedural-surface/picture/palette.js +15 -0
- package/examples/techniques/stylized-shading/README.md +13 -14
- package/examples/techniques/stylized-shading/main.js +11 -42
- package/examples/techniques/stylized-shading/picture/index.js +14 -0
- package/examples/techniques/stylized-shading/picture/lights.js +23 -0
- package/examples/techniques/stylized-shading/picture/materials.js +18 -0
- package/examples/techniques/stylized-shading/picture/palette.js +19 -0
- package/examples/techniques/stylized-shading/shading.js +2 -2
- package/examples/techniques/sun-and-key-light/README.md +20 -22
- package/examples/techniques/sun-and-key-light/keyLight.js +47 -29
- package/examples/techniques/sun-and-key-light/main.js +19 -63
- package/examples/techniques/sun-and-key-light/picture/index.js +13 -0
- package/examples/techniques/sun-and-key-light/picture/lights.js +33 -0
- package/examples/techniques/sun-and-key-light/picture/materials.js +9 -0
- package/examples/techniques/sun-and-key-light/picture/palette.js +29 -0
- package/examples/techniques/sun-and-key-light/picture/sky.js +16 -0
- package/examples/techniques/three-looks/README.md +21 -0
- package/examples/techniques/three-looks/main.js +58 -0
- package/examples/techniques/three-looks/picture/cartoon.js +23 -0
- package/examples/techniques/three-looks/picture/cinematic.js +27 -0
- package/examples/techniques/three-looks/picture/comic.js +27 -0
- package/examples/techniques/three-looks/picture/index.js +14 -0
- package/examples/techniques/three-looks/picture/sun.js +23 -0
- package/examples/techniques/wet-road/README.md +7 -4
- package/examples/techniques/wet-road/main.js +18 -38
- package/examples/techniques/wet-road/picture/index.js +17 -0
- package/examples/techniques/wet-road/picture/lights.js +57 -0
- package/examples/techniques/wet-road/picture/materials.js +16 -0
- package/examples/techniques/wet-road/picture/palette.js +24 -0
- package/examples/techniques/wet-road/picture/sky.js +46 -0
- package/examples/webgpu-tsl/GAMEMAP.md +10 -4
- package/examples/webgpu-tsl/README.md +13 -10
- package/examples/webgpu-tsl/main.js +30 -7
- package/examples/webgpu-tsl/picture/index.js +18 -0
- package/examples/webgpu-tsl/picture/lights.js +25 -0
- package/examples/webgpu-tsl/picture/materials.js +36 -0
- package/examples/webgpu-tsl/picture/palette.js +23 -0
- package/examples/webgpu-tsl/picture/post.js +16 -0
- package/examples/webgpu-tsl/picture/sky.js +30 -0
- package/examples/world/.threedog/content-index.json +1 -1
- package/examples/world/GAMEMAP.md +16 -12
- package/examples/world/art/humanoid.js +9 -13
- package/examples/world/art/index.js +2 -2
- package/examples/world/art/models.js +3 -4
- package/examples/world/art/shapes.js +2 -2
- package/examples/world/assets.js +2 -2
- package/examples/world/content/audio.js +1 -1
- package/examples/world/content/items.js +1 -1
- package/examples/world/content/props.js +1 -1
- package/examples/world/content/templates.js +1 -1
- package/examples/world/content/vegetation.js +1 -1
- package/examples/world/main.js +10 -10
- package/examples/world/models.js +17 -7
- package/examples/world/picture/index.js +20 -0
- package/examples/world/picture/lights.js +41 -0
- package/examples/world/picture/materials.js +34 -0
- package/examples/world/picture/palette.js +74 -0
- package/examples/world/picture/post.js +9 -0
- package/examples/world/picture/sky.js +39 -0
- package/index.d.ts +14 -22
- package/index.js +36 -36
- package/llms.txt +19 -21
- package/modules/ambience/Ambience.js +12 -9
- package/modules/calendar/Calendar.js +20 -20
- package/modules/calendar/index.js +14 -13
- package/modules/calendar/schedule.js +11 -6
- package/modules/calendar/seasons.js +7 -7
- package/modules/camera/FirstPersonCamera.js +2 -2
- package/modules/camera/FixedCamera.js +14 -15
- package/modules/camera/FollowCamera.js +4 -4
- package/modules/camera/RtsCamera.js +11 -11
- package/modules/camera/common.js +51 -25
- package/modules/camera/contract.js +1 -0
- package/modules/camera/projection.js +2 -2
- package/modules/characters/Character.js +47 -39
- package/modules/characters/NPC.js +30 -22
- package/modules/characters/assetModel.js +18 -13
- package/modules/characters/astar.js +7 -5
- package/modules/characters/behaviors.js +4 -5
- package/modules/characters/contract.js +2 -2
- package/modules/characters/index.js +172 -193
- package/modules/characters/moveHelpers.js +14 -3
- package/modules/characters/movers/common.js +22 -15
- package/modules/characters/movers/manual.js +4 -1
- package/modules/characters/movers/rapier.js +7 -6
- package/modules/characters/movers/simple.js +3 -3
- package/modules/characters/movers/support.js +32 -18
- package/modules/characters/npcAvoid.js +4 -4
- package/modules/characters/npcSim.js +28 -18
- package/modules/characters/npcView.js +6 -5
- package/modules/characters/pathAsync.js +12 -10
- package/modules/characters/pathWorker.js +1 -1
- package/modules/characters/player.js +108 -0
- package/modules/characters/playerStrings.js +2 -2
- package/modules/characters/proceduralRig.js +19 -5
- package/modules/characters/useModel.js +5 -5
- package/modules/characters/walkTo.js +11 -17
- package/modules/collision/Collision.js +30 -22
- package/modules/collision/contract.js +15 -0
- package/modules/content/explain.js +1 -2
- package/modules/content/fields.js +24 -3
- package/modules/content/ids.js +2 -2
- package/modules/content/index.js +68 -98
- package/modules/content/loader.js +14 -17
- package/modules/content/markers.js +25 -0
- package/modules/content/models.js +66 -18
- package/modules/content/packs.js +3 -3
- package/modules/content/parts.js +2 -2
- package/modules/content/places.js +35 -0
- package/modules/content/props.js +19 -14
- package/modules/content/rules.js +34 -22
- package/modules/content/stages.js +7 -7
- package/modules/content/templates.js +24 -22
- package/modules/content/words.js +34 -0
- package/modules/debug/DebugPanel.js +10 -43
- package/modules/flow/contract.js +1 -1
- package/modules/flow/index.js +11 -7
- package/modules/gameplay/Container.js +12 -11
- package/modules/gameplay/Containers.js +14 -5
- package/modules/gameplay/Dialogue.js +13 -11
- package/modules/gameplay/Interactions.js +115 -27
- package/modules/gameplay/Inventory.js +11 -12
- package/modules/gameplay/Quests.js +16 -9
- package/modules/gameplay/boxOps.js +1 -1
- package/modules/gameplay/dialogueBox.js +1 -1
- package/modules/gameplay/dialogueBubbles.js +4 -5
- package/modules/gameplay/interactionPrompt.js +1 -1
- package/modules/gameplay/interactions.contract.js +1 -1
- package/modules/gameplay/inventoryOps.js +2 -3
- package/modules/gameplay/pickups.js +81 -44
- package/modules/gameplay/questLog.js +2 -2
- package/modules/gameplay/questSave.js +3 -3
- package/modules/grid/Grid.js +1 -1
- package/modules/grid/Layer.js +16 -3
- package/modules/grid/index.js +47 -19
- package/modules/grid/preview.js +29 -20
- package/modules/grid/tiles.js +19 -23
- package/modules/hlod/index.js +38 -55
- package/modules/hud/index.js +27 -8
- package/modules/hud/parts.js +13 -11
- package/modules/level/contract.js +16 -0
- package/modules/level/heightfield.js +12 -10
- package/modules/level/index.js +48 -152
- package/modules/level/load.js +79 -0
- package/modules/level/meshes.js +65 -0
- package/modules/level/nodes.js +6 -7
- package/modules/lights/index.js +34 -183
- package/modules/lights/slots.js +93 -0
- package/modules/lights/sources.js +88 -0
- package/modules/music/Music.js +31 -27
- package/modules/music/rules.js +1 -1
- package/modules/nav/contract.js +14 -0
- package/modules/nav/index.js +11 -10
- package/modules/net/Client.js +7 -7
- package/modules/net/Host.js +7 -7
- package/modules/net/Net.js +1 -1
- package/modules/net/index.js +5 -4
- package/modules/net/sync.js +2 -2
- package/modules/net/transports.js +2 -2
- package/modules/particles/Particles.js +49 -25
- package/modules/particles/effect.js +27 -10
- package/modules/particles/shaders.js +2 -1
- package/modules/photo/Photo.js +26 -27
- package/modules/rigid/RigidBodies.js +66 -43
- package/modules/rigid/Vehicles.js +2 -3
- package/modules/rigid/ragdoll.js +287 -0
- package/modules/rigid/ragdollBones.js +159 -0
- package/modules/rigid/sync.js +6 -6
- package/modules/settings/Settings.js +114 -45
- package/modules/settings/apply.js +10 -10
- package/modules/settings/sections.js +16 -14
- package/modules/settings/strings.js +1 -1
- package/modules/settings/view.js +3 -3
- package/modules/sky/Sky.js +125 -103
- package/modules/sky/clouds.js +22 -23
- package/modules/sky/dome.js +113 -0
- package/modules/sky/domeLayers.js +13 -13
- package/modules/sky/environment.js +47 -171
- package/modules/sky/fog.js +5 -180
- package/modules/sky/frame.js +42 -97
- package/modules/sky/season.js +9 -3
- package/modules/sky/shader.js +49 -44
- package/modules/sky/skyModule.js +25 -35
- package/modules/sky/tint.js +9 -11
- package/modules/swarm/Swarm.js +346 -0
- package/modules/swarm/draw.js +68 -0
- package/modules/swarm/grid.js +63 -0
- package/modules/terrain/ChunkManager.js +97 -62
- package/modules/terrain/chunkQueries.js +7 -24
- package/modules/terrain/chunkWorker.js +1 -1
- package/modules/terrain/draw.js +157 -0
- package/modules/terrain/index.js +60 -88
- package/modules/terrain/terrainColorMap.js +6 -3
- package/modules/terrain/terrainDefaults.js +4 -3
- package/modules/terrain/terrainEdit.js +32 -27
- package/modules/terrain/terrainGen.js +19 -14
- package/modules/terrain/terrainIsland.js +2 -2
- package/modules/terrain/terrainMesh.js +7 -6
- package/modules/terrain/terrainShape.js +8 -10
- package/modules/terrain/terrainShapeMain.js +3 -3
- package/modules/timeline/Timeline.js +27 -19
- package/modules/timeline/Tween.js +6 -6
- package/modules/timeline/shots.js +5 -7
- package/modules/triggers/index.js +19 -15
- package/modules/vegetation/Vegetation.js +87 -39
- package/modules/vegetation/densityMap.js +4 -7
- package/modules/vegetation/draw.js +196 -0
- package/modules/vegetation/groundChunks.js +11 -31
- package/modules/vegetation/index.js +18 -16
- package/modules/vegetation/modelGeometry.js +3 -6
- package/modules/vegetation/nearFade.js +1 -1
- package/modules/water/Water.js +140 -93
- package/modules/water/surface.js +56 -56
- package/modules/weather/Weather.js +84 -38
- package/modules/weather/particles.js +18 -10
- package/modules/weather/shaders.js +1 -1
- package/modules/weather/weatherDraw.js +145 -0
- package/modules/world/World.js +10 -10
- package/modules/world/explain.js +1 -1
- package/modules/world/index.js +18 -12
- package/modules/world/persist.js +73 -25
- package/modules/world/pos.js +4 -4
- package/modules/world/records.js +28 -8
- package/modules/world/sim.js +4 -4
- package/modules/world/state.js +12 -5
- package/modules/world/thingSource.js +4 -2
- package/modules/world/views.js +12 -10
- package/package.json +44 -8
- package/presets.js +3 -5
- package/render/PostFX.js +233 -63
- package/render/backend.js +72 -32
- package/render/cascades.js +200 -0
- package/render/cascades.tsl.js +93 -0
- package/render/daylight.js +56 -0
- package/render/detail.js +13 -12
- package/render/effects.js +60 -42
- package/render/fuse.js +3 -3
- package/render/fx/cel.tsl.js +42 -0
- package/render/fx/cloudShadow.tsl.js +3 -3
- package/render/fx/detail.tsl.js +1 -1
- package/render/fx/index.js +10 -13
- package/render/fx/library.tsl.js +11 -0
- package/render/fx/lighting.tsl.js +2 -1
- package/render/fx/nodeErrors.tsl.js +2 -2
- package/render/fx/objectOrigin.tsl.js +1 -2
- package/render/fx/patchNodes.tsl.js +6 -16
- package/render/fx/postWebGPU.tsl.js +55 -28
- package/render/fx/sky.tsl.js +34 -109
- package/render/fx/uniforms.tsl.js +4 -4
- package/render/fx/water.tsl.js +1 -1
- package/render/fx/wind.tsl.js +1 -1
- package/render/fxNumbers.js +3 -0
- package/render/layers.js +14 -0
- package/render/lighting.js +11 -8
- package/render/lightmap.js +142 -0
- package/render/lights.js +26 -204
- package/render/lit.js +24 -0
- package/render/materials.js +47 -162
- package/render/mergeCommon.js +22 -0
- package/render/modeling.js +2 -2
- package/render/neutral.js +23 -0
- package/render/occlusion.js +200 -0
- package/render/ownFrame.js +5 -5
- package/render/patches.js +46 -41
- package/render/postWebGL.js +19 -9
- package/render/probes.js +182 -128
- package/render/recordSweep.js +117 -0
- package/render/shaderErrors.js +10 -9
- package/render/shadowCache.tsl.js +107 -0
- package/render/shadowTypes.js +9 -0
- package/render/shadows.js +451 -0
- package/render/slots.js +11 -11
- package/render/terms.js +63 -113
- package/render/uniformDecl.js +2 -2
- package/types/core.d.ts +489 -405
- package/types/gameplay.d.ts +225 -114
- package/types/generated/core/{Audio.d.ts → audio/Audio.d.ts} +23 -8
- package/types/generated/core/{audioVoice.d.ts → audio/audioVoice.d.ts} +2 -2
- package/types/generated/core/{Events.d.ts → base/Events.d.ts} +4 -4
- package/types/generated/core/{I18n.d.ts → base/I18n.d.ts} +7 -15
- package/types/generated/core/{Random.d.ts → base/Random.d.ts} +4 -3
- package/types/generated/core/engine/page.d.ts +24 -0
- package/types/generated/core/{Input.d.ts → input/Input.d.ts} +21 -10
- package/types/generated/core/{Budget.d.ts → inspect/Budget.d.ts} +36 -26
- package/types/generated/core/{DebugOverrides.d.ts → inspect/DebugOverrides.d.ts} +16 -8
- package/types/generated/core/{Ops.d.ts → ops/Ops.d.ts} +4 -3
- package/types/generated/core/{control.d.ts → ops/control.d.ts} +4 -10
- package/types/generated/core/{Saves.d.ts → saves/Saves.d.ts} +37 -13
- package/types/generated/core/{session.d.ts → saves/session.d.ts} +2 -1
- package/types/generated/core/{Rays.d.ts → scene/Rays.d.ts} +8 -27
- package/types/generated/core/{Views.d.ts → scene/Views.d.ts} +1 -1
- package/types/generated/core/{Batching.d.ts → stream/Batching.d.ts} +7 -7
- package/types/generated/core/{Stream.d.ts → stream/Stream.d.ts} +18 -16
- package/types/generated/core/{Commits.d.ts → threads/Commits.d.ts} +1 -1
- package/types/generated/core/{Jobs.d.ts → threads/Jobs.d.ts} +6 -6
- package/types/generated/core/{Threads.d.ts → threads/Threads.d.ts} +4 -4
- package/types/generated/modules/calendar/Calendar.d.ts +10 -11
- package/types/generated/modules/debug/DebugPanel.d.ts +1 -9
- package/types/generated/modules/grid/Layer.d.ts +9 -1
- package/types/generated/modules/grid/index.d.ts +32 -8
- package/types/generated/modules/music/Music.d.ts +7 -5
- package/types/generated/modules/particles/Particles.d.ts +14 -7
- package/types/generated/modules/sky/Sky.d.ts +101 -23
- package/types/generated/modules/sky/skyModule.d.ts +1 -1
- package/types/generated/modules/swarm/Swarm.d.ts +80 -0
- package/types/generated/modules/timeline/Timeline.d.ts +2 -1
- package/types/generated/modules/water/Water.d.ts +51 -3
- package/types/generated/modules/weather/Weather.d.ts +44 -10
- package/types/generated/modules/weather/weatherDraw.d.ts +11 -0
- package/types/generated/modules/world/World.d.ts +7 -5
- package/types/generated/render/PostFX.d.ts +69 -20
- package/types/generated/render/lighting.d.ts +29 -0
- package/types/generated/render/materials.d.ts +20 -44
- package/types/generated/render/occlusion.d.ts +22 -0
- package/types/generated/render/patches.d.ts +1 -0
- package/types/generated/ui/Focus.d.ts +1 -0
- package/types/generated/ui/UI.d.ts +1 -0
- package/types/nav.d.ts +11 -11
- package/types/physics.d.ts +104 -73
- package/types/tsl.d.ts +45 -4
- package/types/world.d.ts +372 -86
- package/ui/Focus.js +21 -10
- package/ui/LoadingScreen.js +2 -2
- package/ui/Parts.js +12 -7
- package/ui/UI.js +17 -17
- package/ui/cursor.js +1 -1
- package/ui/defaults.js +3 -2
- package/ui/theme.js +36 -28
- package/ui/touchPart.js +1 -1
- package/core/UrlState.js +0 -110
- package/core/assetEntry.js +0 -106
- package/core/describeRender.js +0 -71
- package/core/holds.js +0 -134
- package/core/look/coreParts.js +0 -219
- package/core/look/part.js +0 -253
- package/core/look/points.js +0 -255
- package/core/look/report.js +0 -96
- package/core/look/shadowPart.js +0 -63
- package/core/look/state.js +0 -45
- package/core/look/write.js +0 -70
- package/core/page.js +0 -79
- package/core/shadowTypes.js +0 -16
- package/core/styleParts.js +0 -114
- package/core/util.js +0 -17
- package/docs/MIGRATING-0.3.md +0 -248
- package/docs/MIGRATING-0.4.md +0 -228
- package/docs/MIGRATING-0.5.md +0 -68
- package/docs/PERF.md +0 -245
- package/docs/api/style.md +0 -136
- package/docs/api/terrainLook.md +0 -10
- package/docs/api/vegetationLook.md +0 -10
- package/docs/api/weatherLook.md +0 -10
- package/docs/recipes/09-style.md +0 -218
- package/docs/recipes/35-style-from-reference.md +0 -153
- package/docs/recipes/36-sky-ground-plant-looks.md +0 -118
- package/docs/recipes/37-terrain-look-hooks.md +0 -119
- package/docs/recipes/38-environment-look-hooks.md +0 -99
- package/docs/recipes/41-thing-registry.md +0 -97
- package/docs/recipes/42-terrain-shape.md +0 -64
- package/docs/recipes/44-water-weather-look-hooks.md +0 -144
- package/docs/recipes/47-island-snow-backdrop.md +0 -45
- package/docs/recipes/48-make-material.md +0 -75
- package/docs/recipes/52-look.md +0 -282
- package/docs/recipes/54-three-idioms.md +0 -88
- package/examples/action/look.js +0 -5
- package/examples/sheepisland/.threedog/content-index.json +0 -1
- package/examples/sheepisland/style/index.js +0 -79
- package/examples/styletest/look.js +0 -11
- package/examples/techniques/day-night-grade/dayNightGrade.js +0 -76
- package/examples/webgpu-tsl/tslScene.js +0 -75
- package/examples/world/style/index.js +0 -61
- package/examples/world/style/plugins/10-bloom.js +0 -5
- package/modules/sky/cascades.js +0 -186
- package/modules/sky/cascades.tsl.js +0 -82
- package/modules/sky/look.js +0 -54
- package/modules/sky/lookFog.js +0 -76
- package/modules/sky/lookShadow.js +0 -62
- package/modules/sky/lookSky.js +0 -169
- package/modules/sky/shadow.js +0 -98
- package/modules/terrain/look.js +0 -83
- package/modules/terrain/lookGround.js +0 -66
- package/modules/vegetation/look.js +0 -119
- package/modules/vegetation/lookWind.js +0 -98
- package/modules/water/look.js +0 -91
- package/modules/water/surfaceDefaults.js +0 -3
- package/modules/weather/look.js +0 -74
- package/modules/weather/weatherLook.js +0 -135
- package/render/lookGlow.js +0 -139
- package/render/lookSurface.js +0 -224
- package/render/postLook.js +0 -164
- package/render/surface.js +0 -105
- package/types/generated/core/page.d.ts +0 -18
- package/types/generated/modules/weather/weatherLook.d.ts +0 -12
- package/types/style.d.ts +0 -671
- /package/core/{Vars.js → base/Vars.js} +0 -0
- /package/core/{mulberry32.js → base/mulberry32.js} +0 -0
- /package/core/{inputDefaults.js → input/inputDefaults.js} +0 -0
- /package/core/{textureBytes.js → inspect/textureBytes.js} +0 -0
- /package/core/{actor.js → ops/actor.js} +0 -0
- /package/core/{opsFail.js → ops/opsFail.js} +0 -0
- /package/core/{opsHistory.js → ops/opsHistory.js} +0 -0
- /package/core/{saveIds.js → saves/saveIds.js} +0 -0
- /package/core/{screenToGround.js → scene/screenToGround.js} +0 -0
- /package/core/{cells.js → stream/cells.js} +0 -0
- /package/core/{streamCells.js → stream/streamCells.js} +0 -0
- /package/core/{pureWorker.js → threads/pureWorker.js} +0 -0
- /package/examples/{sheepisland → perf-island}/content/index.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/props.js +0 -0
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
# 48. `engine.makeMaterial(role, spec)`: which keys work, who wins
|
|
2
|
-
|
|
3
|
-
`engine.makeMaterial('furniture', { color: 0x8a5a36 })` returns a normal three.js material. The **role** picks the look from `engine.look.materials`,
|
|
4
|
-
the one entry for "what material a purpose gets": its style layer is the style's `materials` table (and a style plugin's Material), its game layer
|
|
5
|
-
`look.materials.set / replace` (unlisted roles use `default`); the **spec** is this call's own settings. A plain `new THREE.MeshStandardMaterial()`
|
|
6
|
-
needs none of this: it gets fog, cascaded shadows and cloud shadow by itself.
|
|
7
|
-
|
|
8
|
-
## Which spec keys are accepted
|
|
9
|
-
|
|
10
|
-
- **Any real property of the material**: `color`, `emissive`, `emissiveIntensity`, `roughness`, `metalness` (standard/physical only), `shininess` (phong),
|
|
11
|
-
`transparent`, `opacity`, `side` (`THREE.DoubleSide`), `vertexColors`, `flatShading`, `wireframe`, `alphaTest`, `depthWrite`, `fog`... Colors take
|
|
12
|
-
a hex, a CSS string or a `THREE.Color`; a Vector2 prop takes `[x, y]`.
|
|
13
|
-
- `type`: `'lambert' | 'phong' | 'standard' | 'physical' | 'toon' | 'basic'` (default `lambert`, or whatever the pack says).
|
|
14
|
-
- Texture slots by asset name (or a `THREE.Texture`): `map`, `emissiveMap` (sRGB), `normalMap`, `roughnessMap`, `metalnessMap`, `aoMap`, `bumpMap`,
|
|
15
|
-
`alphaMap`... The slot must exist on the type (`roughnessMap` needs `standard`). Plus `repeat` (number or `[x, y]`) and `wrap` (`repeat | clamp | mirror`).
|
|
16
|
-
Per slot: `aoMap: { texture: 'ao', channel: 1 }` (second uv set, uv1), also `repeat`, `wrap`, `colorSpace` ('srgb' | 'linear' | 'none') for that slot only.
|
|
17
|
-
Your own `THREE.Texture` (or one registered in code: `assets.manifest({ textures: { brick: () => makeBrick() } })`) keeps its own repeat / wrap /
|
|
18
|
-
colorSpace; only what the spec writes changes, and then on a copy, never your texture.
|
|
19
|
-
- `detail`: a shortcut that lays an engine noise, a texture or your own GLSL over the surface in world space (no UVs); its keys: recipe 43.
|
|
20
|
-
- `lighting`: a shortcut that adds engine light-shaping functions (or your own GLSL) after the light is summed, merged over `style.lighting`; `false` opts out (recipe 43).
|
|
21
|
-
- toon only: `steps` (number of bands), or `ramp` (+ `soften`). `ramp` on a non-toon type throws.
|
|
22
|
-
- A key the chosen material does not have (`roughness` on lambert) is skipped on purpose, so one spec works for any type.
|
|
23
|
-
A key that looks like a typo of a real one (`roughnes`) warns once in dev with `did you mean 'roughness'?`. Nothing is ever blocked.
|
|
24
|
-
|
|
25
|
-
## Who wins: pack or call
|
|
26
|
-
|
|
27
|
-
The pack entry is the default, the call wins. For a pack **spec** the two are merged (`default` spec, then the role's spec, then your call);
|
|
28
|
-
the same key in the call overrides the pack's:
|
|
29
|
-
|
|
30
|
-
```js
|
|
31
|
-
// pack: materials: { building: { type: 'standard', roughness: 0.8 } }
|
|
32
|
-
engine.makeMaterial('building', { roughness: 0.2 }); // roughness 0.2, still standard
|
|
33
|
-
engine.makeMaterial('building', { type: 'toon', steps: 4 }); // your type wins too
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
A pack entry that is a **Material instance** is cloned, then your keys are set on the clone (keys it lacks are skipped).
|
|
37
|
-
A pack **function** `(params, role, engine) => Material` receives your spec first and decides itself; keys it did not use are set afterwards.
|
|
38
|
-
The pack's `style.lighting` is added unless your spec says `lighting: false`.
|
|
39
|
-
|
|
40
|
-
## Tweak the returned material directly
|
|
41
|
-
|
|
42
|
-
The result is an ordinary `THREE.Material`; edit it freely. The engine does not wrap or track it, so this is not "bypassing" anything:
|
|
43
|
-
|
|
44
|
-
```js
|
|
45
|
-
const glass = engine.makeMaterial('window', { color: 0x9fd4ff, transparent: true, opacity: 0.35, side: THREE.DoubleSide });
|
|
46
|
-
glass.depthWrite = false; // plain property edit, fine
|
|
47
|
-
glass.onBeforeCompile = shader => { /* ... */ }; // allowed, but it replaces the engine's shader patches (wind, clouds, detail, lighting) on this material
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
Keep `makeMaterial` as the way to *create* materials (a style swap then restyles the game, `npm run check` flags a bare `new THREE.Mesh*Material`);
|
|
51
|
-
afterwards use three.js normally. Changing `needsUpdate`-type settings (`vertexColors`, `flatShading`, `transparent`) after first render needs `mat.needsUpdate = true`.
|
|
52
|
-
|
|
53
|
-
## Copyable examples
|
|
54
|
-
|
|
55
|
-
```js
|
|
56
|
-
// Solid prop with vertex colors (merged model)
|
|
57
|
-
engine.makeMaterial('prop', { vertexColors: true });
|
|
58
|
-
|
|
59
|
-
// Textured PBR stone
|
|
60
|
-
engine.makeMaterial('rock', { type: 'standard', map: 'rock.png', normalMap: 'rock_n.png', roughness: 0.9, repeat: 4 });
|
|
61
|
-
|
|
62
|
-
// See-through, double-sided
|
|
63
|
-
engine.makeMaterial('banner', { color: 0xd04a3a, transparent: true, opacity: 0.8, side: THREE.DoubleSide });
|
|
64
|
-
|
|
65
|
-
// Glowing lamp
|
|
66
|
-
engine.makeMaterial('lamp', { color: 0x6b5a40, emissive: 0xffc070, emissiveIntensity: 1.2 });
|
|
67
|
-
|
|
68
|
-
// Grain over the surface, no extra shading
|
|
69
|
-
engine.makeMaterial('wall', { color: 0xc9b99a, detail: { noise: 'paper' }, lighting: false });
|
|
70
|
-
|
|
71
|
-
// Toon with an explicit light ramp
|
|
72
|
-
engine.makeMaterial('character', { type: 'toon', color: 0xe8a0a0, ramp: [0.25, 0.6, 1] });
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
See also: `09-style.md` (writing the pack side), `43-shader-patches-surface-looks.md` (detail / lighting / patches).
|
package/docs/recipes/52-look.md
DELETED
|
@@ -1,282 +0,0 @@
|
|
|
1
|
-
# 52 Change any look: `engine.look`
|
|
2
|
-
|
|
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
|
|
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):
|
|
18
|
-
```js
|
|
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
|
|
24
|
-
```
|
|
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
|
-
|
|
33
|
-
- Layers, upper wins: engine default < style < game (each owner; the last one written wins) < `engine.debug.override(owner, 'look.<part>', values)`.
|
|
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.
|
|
36
|
-
- Look changes are not saved: after a load, set them again from your own state.
|
|
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.
|
|
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.
|
|
46
|
-
|
|
47
|
-
## Atmosphere parts (sky module): fog, sky, shadow
|
|
48
|
-
|
|
49
|
-
```js
|
|
50
|
-
engine.look.fog.set({ far: 220, color: '#9bb' }, { owner: 'cave' }); // kind, color, density, near, far, height, falloff, enabled
|
|
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)
|
|
53
|
-
engine.look.sky.set({ clouds: { coverage: 0.7, speed: [0.01, 0] }, backdrop: 0x335577 });
|
|
54
|
-
engine.look.sky.patch('layer:aurora', { glsl: '...threedogSkyLayer...', blend: 'add' }); // a named dome layer; patch('layer:aurora', null) removes it
|
|
55
|
-
engine.look.sky.patch('clouds', glsl); // the cloud function; replace(skyboxName | Texture | Object3D) swaps the dome
|
|
56
|
-
engine.look.shadow.set({ type: 'vsm', radius: 3, cascades: 3, maxFar: 150 }); // set only
|
|
57
|
-
```
|
|
58
|
-
|
|
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.
|
|
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()) })`.
|
|
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).
|
|
77
|
-
|
|
78
|
-
## Surface parts: `materials`, `surface`, `ground`, `wind`
|
|
79
|
-
|
|
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.
|
|
81
|
-
|
|
82
|
-
```js
|
|
83
|
-
const L = engine.look;
|
|
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)
|
|
89
|
-
L.ground.set({ shading: 'flat', colors: { grass: '#7cc06b' } }); // colors / biomeColors / steep / variation / shading rebuild the chunks
|
|
90
|
-
L.ground.set({ detail: { noise: 'paper', scale: 0.4, strength: 0.25 } }); // detail layer on the ground (style.terrain.detail)
|
|
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)
|
|
93
|
-
L.wind.set({ frequency: 1.5, amplitude: 0.5 }); // live on every plant, planted ones too
|
|
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
|
|
99
|
-
```
|
|
100
|
-
|
|
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.
|
|
103
|
-
- `surface`: `set` / `patch('lighting' | 'detail', glsl)`; no `replace` (swap a whole material with `materials.replace`). `style.lighting` is the style layer.
|
|
104
|
-
- `ground` (terrain module): `set` / `patch('detail', glsl)` / `replace`. What `terrain({ colors, shading, material })` was given shows as owner `terrain()`.
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
-
|
|
136
|
-
## Water, weather, post
|
|
137
|
-
|
|
138
|
-
```js
|
|
139
|
-
engine.look.water.set({ opacity: 0.5, waveHeight: 2 }, { owner: 'storm' }); // live, no recompile
|
|
140
|
-
engine.look.water.set({ foam: { color: 0xffffff }, depthColor: { shallow: 0x88ccdd, deep: 0x003355 } }); // rebuilds the water material once
|
|
141
|
-
engine.look.water.patch('wave', 'float threedogWaterWave(vec3 p, float t) { return sin(p.x + t) * 0.2; }'); // hooks: wave, surface
|
|
142
|
-
engine.look.water.replace((engine, { uniforms, waves, surface }) => myMaterial); // the whole surface (style.water.material)
|
|
143
|
-
|
|
144
|
-
engine.look.weather.set({ 'rain.speed': 10, 'snow.size': 8, 'lightning.brightness': 0.5, overcastColor: '#667' }); // rebuilds that field's particles once
|
|
145
|
-
engine.look.weather.patch('rain.fragment', wholeFragmentShaderText); // rain|snow . vertex|fragment: the WHOLE shader text, not a function
|
|
146
|
-
engine.look.weather.replace({ ash: { shape: 'soft', color: 0x555555 }, rain: { create } }); // null gives the fields back
|
|
147
|
-
|
|
148
|
-
engine.look.post.set({ bloom: { strength: 0.6 }, vignette: false }); // keys: '<effect>.<param>', '<effect>.enabled'
|
|
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
|
|
152
|
-
```
|
|
153
|
-
|
|
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.
|
|
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.
|
|
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`.
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
# Plain three.js in this engine
|
|
2
|
-
|
|
3
|
-
```js
|
|
4
|
-
engine.scene.add(new THREE.PointLight(0xffaa55, 2, 8)); // anything the engine does not write: just do it
|
|
5
|
-
engine.lights.sun.intensity = 3; // an engine-driven value: this write takes it over (warns once)
|
|
6
|
-
engine.look.lights.manual('sun'); // the same takeover said on purpose (no warning); manual('sun', false) gives it back
|
|
7
|
-
engine.look.sky.replace(mySky); // the one three.js thing a part draws: your sky (or env map, material role, post chain)
|
|
8
|
-
engine.onRender(({ renderer, scene, camera }) => { /* render into your own target */ });
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
The engine is three.js underneath: `engine.renderer`, `engine.scene` and `engine.camera` are the real objects, and plain three.js code works on them.
|
|
12
|
-
What you need to know is which values the engine **writes on its own** (every frame or on a timer) and how to take those over. A direct write to
|
|
13
|
-
one of them hands it to you (the engine stops writing it and warns once with the explicit call); the full list is recipe 52 "Who writes it".
|
|
14
|
-
Everything else: just do it.
|
|
15
|
-
|
|
16
|
-
Rule of thumb: write the three.js first; it works (auto-yield: the engine stops writing a value you wrote, warns once). `renderer.toneMapping =
|
|
17
|
-
THREE.ACESFilmicToneMapping` is a complete answer. The engine route is optional on top: `engine.look.<part>` (recipe 52) adds owners, layers and
|
|
18
|
-
keyframes. `set(...)` tunes and keeps the engine writing; `manual(key)` takes a value without the warning (`manual(key, false)` gives it back);
|
|
19
|
-
`replace(...)` hands a whole part your own object. `engine.describe().look` says, per value, who set it last; `describe().owned` who writes each
|
|
20
|
-
engine-driven value now.
|
|
21
|
-
|
|
22
|
-
| three.js idiom | Where it goes in the engine | Engine overwrites it? | How to take it over |
|
|
23
|
-
|---|---|---|---|
|
|
24
|
-
| `renderer.toneMapping` | Just set it: `engine.renderer.toneMapping = THREE.ACESFilmicToneMapping` (any three mapping). A curve of your own: a post stage in the `'tone'` slot, `engine.look.post.add({ name, slot: 'tone', create, node })`, which runs on both renderers (a `ShaderChunk` edit is page-wide and reaches only the default renderer) | Once, at `createEngine` (`style.toneMapping`, else AgX), never again | Nothing to take: your write stays; `describe().render.toneMapping.writer` says `game` |
|
|
25
|
-
| `renderer.toneMappingExposure` | Just set it, or `engine.look.tone.set({ exposure })` / `style.exposure` for owners, layers and day keyframes | Exposure keyframes (`style.exposure` as a list or function) are written every frame by the sky module; a number once | Your direct write takes it (auto-yield; describe tags it `three`). `look.tone.manual('exposure')` stops the keyframes without the warning. Own the whole renderer: `createEngine({ renderer })` (recipe 50) |
|
|
26
|
-
| `renderer.outputColorSpace` | Leave it at `SRGBColorSpace` (three's default) | No | Changing it makes every color wrong; `assets.report` flags it |
|
|
27
|
-
| `renderer.shadowMap` | `look.shadow.set({ enabled, type })` (a sky adds cascades, extent ...) | `enabled` / `type` on a change of look.shadow; the sky manages `needsUpdate` | Write it: the engine yields; or `createEngine({ renderer })` and run your own |
|
|
28
|
-
| `scene.environment` | A generated neutral room map under every style (`look.lights` `env.intensity` = its absolute intensity, 0 = none; under a sky `env.share` = its share of the ambient). With a sky: `look.env.replace('sky' \| assetName \| false)` | The baseline map is only written while `scene.environment` is empty or its own. A sky `'sky'` environment is rebuilt and reassigned | Assign your own `scene.environment`: with a sky the rebuilds stop (or say it first: `look.env.manual()`). Or hand it over: `look.env.replace(myTexture | myCubeTexture | myPmremTarget)` |
|
|
29
|
-
| `scene.background` | Style `background`, or `look.sky.replace(name \| Texture \| Object3D)` with a sky | The sky dome draws over it; a backdrop / skybox writes it every frame | Assign it: the dome hides and the sky stops writing it (`look.sky.manual('background')` says so first; `manual('background', false)` gives it back), or `look.sky.replace(yourTexture)` |
|
|
30
|
-
| `scene.fog` | `look.fog.set(...)` with a sky | The sky writes it every frame until you write it | Assign it: `scene.fog = new THREE.Fog(...)` (the engine yields; the one route, there is no `look.fog.replace`), or `look.fog.manual()` to keep the engine's fog and edit it yourself; `manual(false)` gives it back |
|
|
31
|
-
| Your own sky (three/addons `Sky`, a ShaderMaterial dome, a skybox) | `engine.look.sky.replace(mySky)`; feed it from `engine.uniforms` (`uSunDir`, `uDaylight`, `uTimeOfDay`, `uWind`, `uCloud`) | Never: the engine only hides its dome and adds `mySky` to the scene when it has no parent; time, lights, fog and weather keep running | `look.sky.replace(null)` gives the dome back. Per key instead of whole: `look.sky.set({ top: ({ state }) => ... })`, state from `engine.look.state({ ... })` |
|
|
32
|
-
| Lights (`DirectionalLight`, `PointLight`, ...) | Add them with `engine.scene.add(light)` before `engine.start()` (a light count change mid-play recompiles shaders; `lightPool()` for many) | Only `engine.lights.sun` / `.hemi` (driven by the sky when installed) | Write them directly (the sky stops writing what you wrote), or say so: `look.lights.manual('sun' \| 'sun.color' \| 'sun.direction' \| 'hemi')`; `look.lights.set(...)` keeps the day cycle; `sky({ sun: false })` or `createEngine({ lights: false })` and bring all your own |
|
|
33
|
-
| Shadow camera (`light.shadow.camera`, `mapSize`, `bias`) | Your own lights: just do it. Engine sun: `look.shadow.set(...)` (sky) | The engine sun's shadow box follows `engine.focus` every frame | `look.shadow.set({ follow: 'focus' \| 'camera' \| object3D \| fn \| false, extent })`, or place `sun.target` yourself (the box stops following). With `cascades > 1` built-in lit materials get the `csm` patch; a lit ShaderMaterial of yours joins with `look.shadow.include(mat)` |
|
|
34
|
-
| Materials (`new MeshStandardMaterial(...)`) | Just do it, or `makeMaterial('role', { color })` to get the style's material for a role | Your own materials: no. Role materials: `look.materials.set` live keys are written onto every material of the role | `look.materials.replace('role', material)` for a role. A key the `makeMaterial` call passed, or a value you set by hand, is never overwritten (recipe 52) |
|
|
35
|
-
| `onBeforeCompile`, `customProgramCacheKey` | Just assign them, on any material: `m.onBeforeCompile = s => { ... }`. A named, checked patch: `applyEffects(m, { patches: [...] })` | Nothing: on a material the engine patched (wind, clouds, season), your function runs first and the patches after it; your cache key is joined in front of theirs | - |
|
|
36
|
-
| Textures, `CanvasTexture`, `DataTexture` | Just do it; set `colorSpace = SRGBColorSpace` on color textures. File textures by name: `engine.assets.manifest({ textures })` then `assets.texture(name)` | No | A texture made in code gets a name too: `assets.manifest({ textures: { brick: () => makeBrick(), sign: mySignTexture } })`, then `map: 'brick'`; it keeps its own repeat / wrap / colorSpace. Baking: see recipe 05 |
|
|
37
|
-
| `EffectComposer` passes | `const h = engine.look.post.add(pass)` (`composer.addPass`; `{ order }` for `insertPass`; `h.remove()` for `removePass`): the pass joins the engine chain after the scene render, before tone mapping (FXAA / SMAA last; a pass that renders the scene replaces the scene render); a settings toggle: `add(pass, { name: 'glow' })`, then `look.post.set({ glow: false })` | The engine renders the main frame through its own composer; a composer of your own rendered to the canvas takes the frame over (the engine stops drawing, warns `[own-frame]`; delete the call to hand it back) | `look.post.replace([...effects])` for the whole chain. To read them: `engine.post.object()` (the EffectComposer, null until post first runs) and `engine.post.targets()` (`renderTarget1 / 2`, `readBuffer`, `writeBuffer`; read in `onRender(fn, { when: 'after' })`). Read-only: the engine rebuilds `passes`, resizes and disposes them |
|
|
38
|
-
| Render targets (mirror, minimap, portal, picking) | `engine.onRender(({ renderer, scene, camera, dt }) => { renderer.setRenderTarget(rt); renderer.render(scene, cam); })`; runs after the camera and batching, before the frame (`{ when: 'after' }` after it) | No; the render target is reset to the screen after each `before` callback | The main frame render itself stays the engine's |
|
|
39
|
-
| Loaders (`GLTFLoader`, `TextureLoader`, `EXRLoader`, `FBXLoader`, `FontLoader`, exporters) | glTF and png / jpg / ktx2 / hdr textures: `engine.assets.manifest(...)` gives them names, the loading screen and `describe` | No | A hand-made `GLTFLoader` / `TextureLoader` works (rule R21 warns: the asset gets no name). Formats the manifest cannot load (EXR, FBX, OBJ, typeface fonts) and exporters: just use the three.js addon |
|
|
40
|
-
| Camera (`fov`, `position`, `far`) | Camera modules (`followCamera()`, ...) or `engine.camera` with none installed | An installed camera module writes position / fov every frame; terrain view distance rewrites `camera.far` | `engine.takeCamera('me')` (gives it back on `remove()`), or just write `camera.position` (the rig stops; `look.view.manual('camera', false)` resumes). `camera.far` / `fov`: `look.view.manual('far' \| 'fov')`. Not yet: no slot to swap in a different camera object |
|
|
41
|
-
| Meshes (`scene.add(mesh)`) | `engine.add(mesh, { id })` (tracked, saveable) or plain `engine.scene.add(mesh)` | No: auto-batching only merges what the engine places (world records, stream builds, level files); your own meshes stay as you made them | Many static copies of your own mesh: `mesh.userData.batch = true` before adding (recipe 05, 2b) |
|
|
42
|
-
| `requestAnimationFrame` loop | `engine.onFrame(dt => ...)`, `engine.onFixed(dt => ...)` | The engine runs the only loop | Do not start a second loop |
|
|
43
|
-
|
|
44
|
-
Also not yet: contact shadows. WebGPU and TSL: recipe 56.
|
|
45
|
-
|
|
46
|
-
## Procedural modeling: what three.js already has
|
|
47
|
-
|
|
48
|
-
Models written in code (recipe 05, 2a) mostly need helpers three.js already ships: import them from `three` or `three/addons/...` inside the
|
|
49
|
-
model generator, so the result is cached and baked with the model. The engine adds only what three lacks (last row).
|
|
50
|
-
|
|
51
|
-
```js
|
|
52
|
-
import * as THREE from 'three';
|
|
53
|
-
import { mergeGeometries, mergeVertices } from 'three/addons/utils/BufferGeometryUtils.js';
|
|
54
|
-
import { MeshSurfaceSampler } from 'three/addons/math/MeshSurfaceSampler.js';
|
|
55
|
-
import { SimplexNoise } from 'three/addons/math/SimplexNoise.js';
|
|
56
|
-
import { bakeVertexAO } from 'threedog';
|
|
57
|
-
|
|
58
|
-
const rng = engine.random.seeded(7), simplex = new SimplexNoise({ random: () => rng.next() }); // seeded noise: the same shape every load
|
|
59
|
-
// weld first, or the noise opens cracks; mergeVertices compares every attribute, so drop normal and uv (their seams would stay unwelded)
|
|
60
|
-
const rock = mergeVertices(new THREE.IcosahedronGeometry(1, 3).deleteAttribute('normal').deleteAttribute('uv'));
|
|
61
|
-
const p = rock.attributes.position, v = new THREE.Vector3();
|
|
62
|
-
for (let i = 0; i < p.count; i++) { v.fromBufferAttribute(p, i); v.multiplyScalar(1 + 0.25 * simplex.noise3d(v.x, v.y, v.z)); p.setXYZ(i, v.x, v.y, v.z); }
|
|
63
|
-
rock.computeVertexNormals();
|
|
64
|
-
const slab = new THREE.CylinderGeometry(1.2, 1.4, 0.3).translate(0, -0.9, 0).deleteAttribute('uv');
|
|
65
|
-
const model = mergeGeometries([rock, slab]); // same attributes (position, normal), both indexed
|
|
66
|
-
bakeVertexAO(model, { samples: 32, strength: 0.7, occluders: [new THREE.PlaneGeometry(6, 6).rotateX(-Math.PI / 2).translate(0, -1.05, 0)] });
|
|
67
|
-
const sampler = new MeshSurfaceSampler(new THREE.Mesh(model)).setRandomGenerator(() => rng.next()).build();
|
|
68
|
-
const at = new THREE.Vector3(), up = new THREE.Vector3();
|
|
69
|
-
sampler.sample(at, up); // a point and its normal on the surface: where a tuft or stud goes
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
| Need | three.js answer | Engine |
|
|
73
|
-
|---|---|---|
|
|
74
|
-
| Parts into one geometry / one draw call | `BufferGeometryUtils.mergeGeometries(list, useGroups)` (same attributes on every part, all indexed or none); `BufferGeometryUtils.mergeVertices(g, tolerance)` welds; `BufferGeometryUtils.toCreasedNormals(g, angle)` keeps hard edges with smooth faces; `mergeGroups` | `mergeColored([[g, color], ...])` when each part is one flat color (vertex colors) |
|
|
75
|
-
| Revolve a profile (vase, bottle, shade) | `new LatheGeometry(points, segments)` | - |
|
|
76
|
-
| Sweep along a path (pipe, rope, rail, vine) | `new TubeGeometry(curve, ...)`; a `Shape` along a path: `new ExtrudeGeometry(shape, { extrudePath: curve, steps })`; sections that change: `new LoftGeometry(sections)` (three/addons geometries); bend a finished mesh along a curve: `Flow` (three/addons CurveModifier) | - |
|
|
77
|
-
| A 2D outline into a slab (sign, cutout, wall with holes) | `Shape` with `shape.holes`, `new ExtrudeGeometry(shape, { depth, bevelEnabled })`; flat: `ShapeGeometry` | - |
|
|
78
|
-
| Rounded box, parametric surface, 3D text | `RoundedBoxGeometry`, `ParametricGeometry`, `TextGeometry` with `FontLoader` (addons) | - |
|
|
79
|
-
| Points spread over a mesh (moss, studs, spikes, ornaments) | `new MeshSurfaceSampler(mesh).setWeightAttribute(name).setRandomGenerator(fn).build()`, then `.sample(position, normal, color, uv)` | Over the ground by height, slope and biome rules: `engine.vegetation.define(name, { rule })` (recipe 10) |
|
|
80
|
-
| A decal projected onto a mesh (stain, sticker, scorch) | `new DecalGeometry(mesh, position, orientation, size)`, material with `polygonOffset` | - |
|
|
81
|
-
| Convex hull of points (pebble, crystal, collision proxy) | `new ConvexGeometry(points)`; `ConvexHull` for the faces as data | - |
|
|
82
|
-
| Fewer triangles (a far copy of one model) | `await new SimplifyModifier().modify(geometry, count)` (async in this three version) | Far copies of whole areas: `hlod` (recipe 15) |
|
|
83
|
-
| More triangles (before noise or vertex AO) | `new TessellateModifier(maxEdge, iterations).modify(g)`, or more segments in the primitive | - |
|
|
84
|
-
| Hard edges on a smooth mesh | `new EdgeSplitModifier().modify(g, angle)` or `BufferGeometryUtils.toCreasedNormals` | - |
|
|
85
|
-
| Noise (lumpy rock, wobbly edge, color variation) | `new SimplexNoise({ random })` (2D, 3D, 4D; seeded as above); `ImprovedNoise` (3D Perlin, one fixed permutation) | Terrain heights: `@threedog/terrain-noise` (recipe 28) |
|
|
86
|
-
| A texture drawn in code (labels, stripes, gradients, pixel art) | `new CanvasTexture(canvas)` with `colorSpace = SRGBColorSpace`; `DataTexture` | Give it a name: `assets.manifest({ textures })` (table above) |
|
|
87
|
-
| Many copies | `new InstancedMesh(g, m, count)` with `setMatrixAt`; `BatchedMesh` for different geometries | Auto-batching for copies the engine places, `userData.batch` for yours (recipe 05, 2b) |
|
|
88
|
-
| Ambient occlusion in a code-built model | Not in three: `aoMap` needs a baked texture | `bakeVertexAO(geometry, { samples, radius, strength, occluders })`: hemisphere rays per vertex (three-mesh-bvh), multiplied into the vertex colors; detail is per vertex, so tessellate big faces first |
|
package/examples/action/look.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
// This example's look, its whole style (createEngine({ style: look })): the colors models.js reads. Logic never reads colors; models.js does.
|
|
2
|
-
export default {
|
|
3
|
-
name: 'action', // a part needs at least one Style field (TypeScript rejects an object that shares none), so it names itself
|
|
4
|
-
action: { floor: 0x5b6168, wall: 0x8a8f96, pillar: 0x9a8c78, enemy: 0x6fbf5a, eye: 0x1d2024 },
|
|
5
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":1,"files":{"content/props.js":{"kind":"props","mtime":1793500175294.8977,"from":0,"count":15,"indexIds":0,"positional":[]},"content/templates.js":{"kind":"templates","mtime":1793500175296.9004,"from":0,"count":2,"indexIds":0,"positional":[]},"content/vegetation.js":{"kind":"vegetation","mtime":1793500175298.9006,"from":0,"count":1,"indexIds":0,"positional":[]}},"ids":{"tree-1":[{"file":"content/props.js","kind":"props","line":4,"placed":true}],"tree-2":[{"file":"content/props.js","kind":"props","line":5,"placed":true}],"tree-3":[{"file":"content/props.js","kind":"props","line":6,"placed":true}],"tree-4":[{"file":"content/props.js","kind":"props","line":7,"placed":true}],"tree-5":[{"file":"content/props.js","kind":"props","line":8,"placed":true}],"tree-6":[{"file":"content/props.js","kind":"props","line":9,"placed":true}],"tree-7":[{"file":"content/props.js","kind":"props","line":10,"placed":true}],"sheep-1":[{"file":"content/props.js","kind":"props","line":11,"placed":true}],"sheep-2":[{"file":"content/props.js","kind":"props","line":12,"placed":true}],"sheep-3":[{"file":"content/props.js","kind":"props","line":13,"placed":true}],"sheep-4":[{"file":"content/props.js","kind":"props","line":14,"placed":true}],"sheep-5":[{"file":"content/props.js","kind":"props","line":15,"placed":true}],"sheep-6":[{"file":"content/props.js","kind":"props","line":16,"placed":true}],"sheep-7":[{"file":"content/props.js","kind":"props","line":17,"placed":true}],"sheep-8":[{"file":"content/props.js","kind":"props","line":18,"placed":true}],"tree":[{"file":"content/templates.js","kind":"templates","line":3,"placed":false}],"sheep":[{"file":"content/templates.js","kind":"templates","line":4,"placed":false}],"wheat":[{"file":"content/vegetation.js","kind":"vegetation","line":4,"placed":false}]}}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
// sheepisland: this game's style, LOOKS ONLY (recipes/09-style.md, 35-style-from-reference.md), filled in from the empty style/index.js
|
|
2
|
-
// a new game starts with. A soft painted diorama: few flat colors, round shapes, soft shadows, a pale warm background with no horizon.
|
|
3
|
-
// The world (island outline, river, wheat field) is the game's terrain() in ../main.js, never here.
|
|
4
|
-
import { makeMaterial, applyEffects } from '../../../index.js';
|
|
5
|
-
import { models, PALETTE } from './models.js';
|
|
6
|
-
|
|
7
|
-
export { models };
|
|
8
|
-
/** Asset pack of the procedural models: engine.assets.manifest(assets) registers roundTree, sheep and wheatTuft */
|
|
9
|
-
export const assets = { name: 'sheepisland', models };
|
|
10
|
-
|
|
11
|
-
// Background: zenith = horizon = fog color at every time, so the dome is one flat tone and no horizon line shows.
|
|
12
|
-
// [time 0-1, zenith, horizon (= fog), sun color, sun intensity, ambient intensity]
|
|
13
|
-
// Ground material with snow that survives shading: 'texture'. The engine's season tint runs at color_fragment, before the per-chunk color map is
|
|
14
|
-
// multiplied in, so in 'mix' mode the map paints the green back over the white. This patch repeats the season mix later (slot emissive, emissivemap_fragment,
|
|
15
|
-
// after every color patch, before lighting), reading the engine's own season uniforms under new names (the season patch declares the old ones).
|
|
16
|
-
/** @param {any} engine */
|
|
17
|
-
function snowyGround(engine) {
|
|
18
|
-
const u = engine.uniforms;
|
|
19
|
-
return applyEffects(makeMaterial('terrain', { vertexColors: true }, engine), { clouds: false, patches: [{
|
|
20
|
-
name: 'snowCover', cacheKey: 1, uniforms: { uSnowTint: u.uGroundTint, uSnowMix: u.uGroundMix },
|
|
21
|
-
pars: 'uniform vec3 uSnowTint; uniform float uSnowMix;',
|
|
22
|
-
slot: 'emissive', glsl: 'diffuseColor.rgb = mix(diffuseColor.rgb, uSnowTint, uSnowMix);' }] });
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const DAY = 0xefebe4, DUSK = 0xf0d9c4, NIGHT = 0x2c3346;
|
|
26
|
-
export default {
|
|
27
|
-
name: 'sheepisland',
|
|
28
|
-
exposure: 1,
|
|
29
|
-
toneMapping: 'neutral', // neutral keeps the painted colors close to what is written here (aces darkens and shifts them)
|
|
30
|
-
|
|
31
|
-
// no post plugins: restraint, the reference shows no outline, bloom or grain
|
|
32
|
-
|
|
33
|
-
materials: {
|
|
34
|
-
default: { type: 'lambert' },
|
|
35
|
-
leaf: { type: 'lambert' },
|
|
36
|
-
bark: { type: 'lambert' },
|
|
37
|
-
wool: { type: 'lambert' },
|
|
38
|
-
face: { type: 'lambert' },
|
|
39
|
-
cliff: { type: 'lambert' },
|
|
40
|
-
vegetation: { type: 'lambert', side: 2 }, // the wheat stalks are thin: both sides (THREE.DoubleSide = 2)
|
|
41
|
-
},
|
|
42
|
-
|
|
43
|
-
// Soft light: half-lambert wrap so the shade side of a round blob is not black, and a cool blue shade instead of a gray one
|
|
44
|
-
lighting: { wrap: 0.45, shadowTint: { color: 0x7d88b8, strength: 0.45, soft: 0.3 } },
|
|
45
|
-
|
|
46
|
-
palette: PALETTE,
|
|
47
|
-
|
|
48
|
-
sky: {
|
|
49
|
-
keyframes: [
|
|
50
|
-
[0.00, NIGHT, NIGHT, 0x9aaad8, 0.7, 0.85],
|
|
51
|
-
[0.22, NIGHT, NIGHT, 0x9aaad8, 0.7, 0.85],
|
|
52
|
-
[0.30, DAY, DAY, 0xfff0dc, 1.8, 1.0],
|
|
53
|
-
[0.50, DAY, DAY, 0xfffaf0, 2.3, 1.15],
|
|
54
|
-
[0.70, DAY, DAY, 0xffe6c8, 1.9, 1.0],
|
|
55
|
-
[0.77, DUSK, DUSK, 0xffb07a, 1.5, 0.85],
|
|
56
|
-
[0.84, NIGHT, NIGHT, 0x9aaad8, 0.7, 0.85],
|
|
57
|
-
[1.00, NIGHT, NIGHT, 0x9aaad8, 0.7, 0.85],
|
|
58
|
-
],
|
|
59
|
-
groundTint: 0xb8c49a, // ambient bounce from below: the green of the meadow, not gray
|
|
60
|
-
sunBrightness: 0, sunGlow: 0, moonBrightness: 0, starDensity: 0, // a flat painted backdrop: no disc, glow or stars
|
|
61
|
-
clouds: { coverage: 0 },
|
|
62
|
-
shadow: { type: 'pcf', radius: 4, extent: 45, mapSize: 2048 }, // soft edges; the island is small, so a tight box keeps them sharp enough
|
|
63
|
-
fog: { kind: 'exp', density: 0.0015 }, // barely there: the far rim fades a touch into the backdrop
|
|
64
|
-
},
|
|
65
|
-
|
|
66
|
-
terrain: {
|
|
67
|
-
config: { shading: 'texture', colorResolution: 256 }, // crisp river bank and field edge without more triangles (recipe 37); 128 (0.5 m pixels) shows stairs up close
|
|
68
|
-
colors: { grassA: 0x92c062, grassB: 0x86b658, river: 0x6aa6d6, riverDeep: 0x5b97ca, wheatA: 0xdcae48, wheatB: 0xd2a442,
|
|
69
|
-
earth: 0xb98d64, rock: 0x94705a },
|
|
70
|
-
biomeColors: { grass: ['grassA', 'grassB'], river: ['river', 'riverDeep'], wheat: ['wheatA', 'wheatB'], cliff: ['earth'], rock: ['rock'] },
|
|
71
|
-
variation: { blend: { size: 14, strength: 0.6 }, jitter: { size: 0.5, min: 0.97, range: 0.04 } }, // low texture: almost no grain
|
|
72
|
-
material: snowyGround,
|
|
73
|
-
},
|
|
74
|
-
|
|
75
|
-
// Snow: winter in the calendar turns foliage and ground most of the way to white ('mix', so green does not go muddy)
|
|
76
|
-
seasons: { mode: /** @type {const} */ ('mix'), strength: 0.82, winter: { foliage: 0xf6f6f8, ground: 0xf4f5f8 } },
|
|
77
|
-
// snow greys the sky towards overcastColor and dims the sun: keep the backdrop pale and the island readable
|
|
78
|
-
weather: { snow: { color: 0xffffff }, overcastColor: 0xe6e3de, types: { snow: { sun: 0.8, grey: 0.25 } } },
|
|
79
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// This example's look, a style part merged over the style under test (createEngine({ style: [worldStyle, look] }), worldStyle = ../world/style): how the test surfaces feel.
|
|
2
|
-
// The exhibits ask for roles wood / stone / metal / glass; a style that does not define them falls back to materials.default.
|
|
3
|
-
export default {
|
|
4
|
-
name: 'styletest',
|
|
5
|
-
materials: {
|
|
6
|
-
wood: { type: 'lambert' },
|
|
7
|
-
stone: { type: 'lambert', flatShading: true },
|
|
8
|
-
metal: { type: 'standard', metalness: 0.9, roughness: 0.3 }, // only looks like metal with environment light: ?env=1
|
|
9
|
-
glass: { type: 'phong', shininess: 100 },
|
|
10
|
-
},
|
|
11
|
-
};
|