threedog 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +196 -1
- package/README.md +6 -9
- package/core/{Animator.js → assets/Animator.js} +28 -18
- package/core/{Assets.js → assets/Assets.js} +98 -54
- package/core/{Baked.js → assets/Baked.js} +4 -4
- package/core/assets/assetEntry.js +237 -0
- package/core/{assetHot.js → assets/assetHot.js} +7 -6
- package/core/{assetLoad.js → assets/assetLoad.js} +55 -16
- package/core/assets/assetLod.js +113 -0
- package/core/{assetManifest.js → assets/assetManifest.js} +19 -11
- package/core/{assetReport.js → assets/assetReport.js} +6 -12
- package/core/{namedModel.js → assets/namedModel.js} +17 -13
- package/core/{Audio.js → audio/Audio.js} +26 -23
- package/core/{audioRules.js → audio/audioRules.js} +8 -5
- package/core/{audioVoice.js → audio/audioVoice.js} +17 -30
- package/core/{Events.js → base/Events.js} +3 -3
- package/core/{I18n.js → base/I18n.js} +10 -10
- package/core/{Random.js → base/Random.js} +5 -4
- package/core/{easing.js → base/easing.js} +1 -1
- package/core/{errorCodes.js → base/errorCodes.js} +98 -110
- package/core/{errorHints.js → base/errorHints.js} +5 -9
- package/core/{errors.js → base/errors.js} +6 -6
- package/core/{events.generated.js → base/events.generated.js} +1 -0
- package/core/{math.js → base/math.js} +15 -4
- package/core/{params.js → base/params.js} +3 -4
- package/core/base/util.js +32 -0
- package/core/{validate.js → base/validate.js} +28 -7
- package/core/{Engine.js → engine/Engine.js} +80 -77
- package/core/{Loading.js → engine/Loading.js} +4 -2
- package/core/{copies.js → engine/copies.js} +4 -4
- package/core/{headlessLoad.js → engine/headlessLoad.js} +4 -4
- package/core/{lifecycle.js → engine/lifecycle.js} +14 -12
- package/core/{loop.js → engine/loop.js} +68 -47
- package/core/{moduleSlots.js → engine/moduleSlots.js} +6 -6
- package/core/{moduleTypes.js → engine/moduleTypes.js} +13 -14
- package/core/{modules.js → engine/modules.js} +14 -11
- package/core/{page.js → engine/page.js} +36 -23
- package/core/{plugins.js → engine/plugins.js} +6 -9
- package/core/{services.js → engine/services.js} +47 -40
- package/core/{startup.js → engine/startup.js} +26 -24
- package/core/{Input.js → input/Input.js} +30 -22
- package/core/{inputContext.js → input/inputContext.js} +14 -5
- package/core/{inputPad.js → input/inputPad.js} +1 -1
- package/core/{inputPointer.js → input/inputPointer.js} +8 -2
- package/core/{inputTouch.js → input/inputTouch.js} +1 -1
- package/core/{Budget.js → inspect/Budget.js} +21 -20
- package/core/{DebugOverrides.js → inspect/DebugOverrides.js} +30 -16
- package/core/{Describe.js → inspect/Describe.js} +26 -22
- package/core/{Inspect.js → inspect/Inspect.js} +9 -7
- package/core/{InspectMaterials.js → inspect/InspectMaterials.js} +7 -8
- package/core/{InspectPerf.js → inspect/InspectPerf.js} +19 -13
- package/core/{InspectScene.js → inspect/InspectScene.js} +8 -5
- package/core/{MaterialInfo.js → inspect/MaterialInfo.js} +3 -2
- package/core/{UrlState.js → inspect/UrlState.js} +52 -20
- package/core/{catalog.js → inspect/catalog.js} +3 -3
- package/core/{checks.js → inspect/checks.js} +7 -5
- package/core/{debugView.js → inspect/debugView.js} +4 -4
- package/core/{describeRender.js → inspect/describeRender.js} +21 -20
- package/core/{describeText.js → inspect/describeText.js} +11 -6
- package/core/inspect/geometryWatch.js +38 -0
- package/core/{lightWatch.js → inspect/lightWatch.js} +8 -8
- package/core/{pictureWriters.js → inspect/pictureWriters.js} +15 -16
- package/core/{shaderCost.js → inspect/shaderCost.js} +1 -1
- package/core/{Ops.js → ops/Ops.js} +16 -11
- package/core/{control.js → ops/control.js} +13 -12
- package/core/ops/holds.js +139 -0
- package/core/{opsAtomic.js → ops/opsAtomic.js} +2 -1
- package/core/{opsCheck.js → ops/opsCheck.js} +4 -5
- package/core/{opsGuard.js → ops/opsGuard.js} +3 -3
- package/core/{opsRun.js → ops/opsRun.js} +7 -4
- package/core/{owned.js → ops/owned.js} +14 -17
- package/core/{sharedPoint.js → ops/sharedPoint.js} +8 -8
- package/core/{stackFrames.js → ops/stackFrames.js} +2 -2
- package/core/{stacks.js → ops/stacks.js} +12 -14
- package/core/{wrap.js → ops/wrap.js} +8 -6
- package/core/{SaveStore.js → saves/SaveStore.js} +1 -1
- package/core/{Saves.js → saves/Saves.js} +58 -36
- package/core/{saveApply.js → saves/saveApply.js} +13 -9
- package/core/{saveFiles.js → saves/saveFiles.js} +17 -15
- package/core/{saveValues.js → saves/saveValues.js} +20 -3
- package/core/{saveVersions.js → saves/saveVersions.js} +4 -17
- package/core/{session.js → saves/session.js} +31 -17
- package/core/{Rays.js → scene/Rays.js} +23 -25
- package/core/{Views.js → scene/Views.js} +14 -6
- package/core/{adaptive.js → scene/adaptive.js} +15 -8
- package/core/{canvasBox.js → scene/canvasBox.js} +2 -3
- package/core/{engineCamera.js → scene/engineCamera.js} +1 -1
- package/core/{gameLights.js → scene/gameLights.js} +17 -7
- package/core/{grayMap.js → scene/grayMap.js} +8 -2
- package/core/{grid.js → scene/grid.js} +4 -4
- package/core/{gridLoad.js → scene/gridLoad.js} +1 -1
- package/core/{ground.js → scene/ground.js} +9 -9
- package/core/{movement.js → scene/movement.js} +3 -3
- package/core/{pictureSlots.js → scene/pictureSlots.js} +2 -2
- package/core/{sceneDelta.js → scene/sceneDelta.js} +2 -2
- package/core/{sceneMethods.js → scene/sceneMethods.js} +36 -13
- package/core/scene/stepPoses.js +55 -0
- package/core/{targeting.js → scene/targeting.js} +4 -5
- package/core/{thingExplain.js → scene/thingExplain.js} +6 -5
- package/core/{thingOps.js → scene/thingOps.js} +4 -3
- package/core/{things.js → scene/things.js} +18 -5
- package/core/{threePatches.js → scene/threePatches.js} +1 -1
- package/core/{view.js → scene/view.js} +17 -16
- package/core/{Batching.js → stream/Batching.js} +85 -27
- package/core/{Stream.js → stream/Stream.js} +60 -30
- package/core/{batchGroups.js → stream/batchGroups.js} +10 -9
- package/core/{chunkStream.js → stream/chunkStream.js} +40 -0
- package/core/{scatter.js → stream/scatter.js} +2 -2
- package/core/{streamSources.js → stream/streamSources.js} +12 -7
- package/core/{Commits.js → threads/Commits.js} +6 -5
- package/core/{Jobs.js → threads/Jobs.js} +12 -10
- package/core/{Threads.js → threads/Threads.js} +16 -16
- package/core/{threadPure.js → threads/threadPure.js} +7 -5
- package/core/{threadServe.js → threads/threadServe.js} +3 -3
- package/core/{Clock.js → time/Clock.js} +17 -10
- package/core/{dayTime.js → time/dayTime.js} +5 -1
- package/core/{skip.js → time/skip.js} +18 -17
- package/core/{time.js → time/time.js} +18 -12
- package/core/{uiClock.js → time/uiClock.js} +4 -4
- package/docs/AI.md +22 -19
- package/docs/API.md +24 -23
- package/docs/CODEMAP.md +76 -183
- package/docs/COMMANDS.md +66 -58
- package/docs/CONVENTIONS.md +54 -14
- package/docs/MIGRATING-0.8.md +169 -0
- package/docs/THREE.md +78 -29
- package/docs/api/assets.md +12 -13
- package/docs/api/audio.md +6 -5
- package/docs/api/budget.md +4 -4
- package/docs/api/calendar.md +10 -11
- package/docs/api/cameraRig.md +29 -29
- package/docs/api/characters.md +23 -18
- package/docs/api/clock.md +1 -1
- package/docs/api/collision.md +12 -9
- package/docs/api/content.md +6 -6
- package/docs/api/dialogue.md +3 -3
- package/docs/api/engine.md +45 -43
- package/docs/api/events.md +3 -2
- package/docs/api/flow.md +1 -1
- package/docs/api/grids.md +1 -1
- package/docs/api/ground.md +4 -5
- package/docs/api/hud.md +2 -2
- package/docs/api/i18n.md +6 -6
- package/docs/api/input.md +7 -7
- package/docs/api/interactions.md +4 -4
- package/docs/api/inventory.md +9 -9
- package/docs/api/jobs.md +5 -5
- package/docs/api/level.md +7 -7
- package/docs/api/lightPool.md +1 -6
- package/docs/api/music.md +3 -3
- package/docs/api/nav.md +10 -10
- package/docs/api/openWorld.md +1 -1
- package/docs/api/particles.md +2 -2
- package/docs/api/photo.md +4 -2
- package/docs/api/pickups.md +2 -2
- package/docs/api/post.md +20 -3
- package/docs/api/quests.md +3 -3
- package/docs/api/rays.md +5 -7
- package/docs/api/rigid.md +27 -18
- package/docs/api/saves.md +8 -7
- package/docs/api/settings.md +9 -8
- package/docs/api/sky.md +8 -7
- package/docs/api/stream.md +7 -7
- package/docs/api/swarm.md +34 -0
- package/docs/api/terrain.md +7 -8
- package/docs/api/terrainDraw.md +1 -1
- package/docs/api/timeline.md +2 -2
- package/docs/api/tools.md +25 -22
- package/docs/api/vars.md +1 -1
- package/docs/api/vegetation.md +4 -3
- package/docs/api/vegetationDraw.md +1 -1
- package/docs/api/water.md +1 -1
- package/docs/api/weather.md +9 -9
- package/docs/api/weatherDraw.md +3 -3
- package/docs/api/world.md +5 -5
- package/docs/recipes/01-new-game.md +25 -40
- package/docs/recipes/02-npc.md +19 -20
- package/docs/recipes/03-items-pickups.md +27 -43
- package/docs/recipes/04-quests.md +3 -4
- package/docs/recipes/05-props-bake.md +29 -39
- package/docs/recipes/06-clock-events.md +27 -18
- package/docs/recipes/07-flow-scenes-pause.md +12 -17
- package/docs/recipes/08-weather-sky.md +88 -34
- package/docs/recipes/09-materials-lights-models.md +22 -36
- package/docs/recipes/10-blender-level.md +6 -7
- package/docs/recipes/11-vehicles.md +30 -22
- package/docs/recipes/12-navmesh.md +9 -8
- package/docs/recipes/13-animation.md +39 -17
- package/docs/recipes/14-custom-module.md +14 -13
- package/docs/recipes/15-perf.md +49 -26
- package/docs/recipes/16-dev-bridge.md +32 -52
- package/docs/recipes/18-world.md +36 -23
- package/docs/recipes/19-shooting-picking.md +4 -2
- package/docs/recipes/20-content-actions-save.md +30 -35
- package/docs/recipes/21-camera.md +33 -5
- package/docs/recipes/22-shop-gold.md +0 -4
- package/docs/recipes/23-ops.md +10 -10
- package/docs/recipes/26-ui-parts.md +22 -12
- package/docs/recipes/27-net.md +0 -2
- package/docs/recipes/28-terrain.md +117 -21
- package/docs/recipes/29-grid.md +2 -2
- package/docs/recipes/30-templates.md +55 -19
- package/docs/recipes/31-audio.md +5 -5
- package/docs/recipes/32-action-game.md +15 -6
- package/docs/recipes/33-stream-sources.md +2 -2
- package/docs/recipes/34-environment-lighting.md +67 -19
- package/docs/recipes/35-picture-from-reference.md +10 -17
- package/docs/recipes/36-ground-plants.md +105 -0
- package/docs/recipes/40-scene.md +7 -11
- package/docs/recipes/43-shader-patches-surfaces.md +20 -41
- package/docs/recipes/44-water-weather-hooks.md +48 -43
- package/docs/recipes/45-cascaded-shadows.md +39 -17
- package/docs/recipes/46-blender-art-route.md +7 -8
- package/docs/recipes/49-game-module-contract.md +5 -5
- package/docs/recipes/50-own-renderer.md +2 -2
- package/docs/recipes/52-around-the-picture.md +54 -98
- package/docs/recipes/53-ground-up-close.md +61 -24
- package/docs/recipes/55-mods-time-wrap.md +12 -16
- package/docs/recipes/56-webgpu-tsl.md +16 -14
- package/docs/recipes/57-control.md +9 -2
- package/docs/recipes/58-input.md +2 -2
- package/docs/recipes/59-depth-post-effects.md +1 -1
- package/docs/recipes/60-judge-the-picture.md +29 -24
- package/docs/recipes/62-picture-code.md +49 -17
- package/docs/recipes/63-third-person-start.md +17 -4
- package/docs/recipes/64-particles.md +1 -1
- package/docs/recipes/65-swarm.md +140 -0
- package/examples/action/.threedog/content-index.json +1 -1
- package/examples/action/GAMEMAP.md +2 -2
- package/examples/{sheepisland → perf-island}/.threedog/content-index.json +1 -1
- package/examples/{sheepisland → perf-island}/GAMEMAP.md +12 -11
- package/examples/{sheepisland → perf-island}/assets.js +1 -1
- package/examples/{sheepisland → perf-island}/main.js +8 -8
- package/examples/{sheepisland → perf-island}/models.js +1 -1
- package/examples/{sheepisland → perf-island}/params.js +1 -1
- package/examples/{sheepisland → perf-island}/picture/index.js +1 -1
- package/examples/{sheepisland → perf-island}/picture/palette.js +2 -2
- package/examples/{sheepisland → perf-island}/views.js +1 -1
- package/examples/plain-picture/GAMEMAP.md +1 -0
- package/examples/rc2d/GAMEMAP.md +3 -2
- package/examples/rc2d/main.js +1 -3
- package/examples/styletest/.threedog/content-index.json +1 -1
- package/examples/styletest/GAMEMAP.md +3 -2
- package/examples/techniques/contact-shadows/contactShadows.js +1 -1
- package/examples/techniques/contact-shadows/main.js +1 -1
- package/examples/techniques/interior-light/main.js +1 -1
- package/examples/techniques/modular-building/README.md +7 -6
- package/examples/techniques/outlines-and-rim/picture/post.js +1 -1
- package/examples/techniques/procedural-animation/README.md +1 -1
- package/examples/webgpu-tsl/GAMEMAP.md +1 -0
- package/examples/world/.threedog/content-index.json +1 -1
- package/examples/world/GAMEMAP.md +4 -3
- package/examples/world/picture/sky.js +1 -1
- package/index.d.ts +8 -7
- package/index.js +31 -31
- package/llms.txt +9 -13
- package/modules/ambience/Ambience.js +11 -8
- package/modules/calendar/Calendar.js +19 -19
- package/modules/calendar/index.js +13 -13
- package/modules/calendar/schedule.js +11 -6
- package/modules/calendar/seasons.js +7 -7
- package/modules/camera/FirstPersonCamera.js +2 -2
- package/modules/camera/FixedCamera.js +14 -15
- package/modules/camera/FollowCamera.js +4 -4
- package/modules/camera/RtsCamera.js +11 -11
- package/modules/camera/common.js +48 -24
- package/modules/camera/contract.js +1 -0
- package/modules/camera/projection.js +2 -2
- package/modules/characters/Character.js +33 -30
- package/modules/characters/NPC.js +27 -19
- package/modules/characters/assetModel.js +14 -10
- package/modules/characters/astar.js +7 -5
- package/modules/characters/behaviors.js +4 -5
- package/modules/characters/contract.js +2 -2
- package/modules/characters/index.js +168 -214
- package/modules/characters/moveHelpers.js +14 -3
- package/modules/characters/movers/common.js +16 -14
- package/modules/characters/movers/manual.js +1 -1
- package/modules/characters/movers/rapier.js +7 -6
- package/modules/characters/movers/simple.js +3 -3
- package/modules/characters/movers/support.js +8 -8
- package/modules/characters/npcAvoid.js +4 -4
- package/modules/characters/npcSim.js +23 -17
- package/modules/characters/npcView.js +6 -5
- package/modules/characters/pathAsync.js +12 -10
- package/modules/characters/pathWorker.js +1 -1
- package/modules/characters/player.js +108 -0
- package/modules/characters/playerStrings.js +2 -2
- package/modules/characters/proceduralRig.js +2 -2
- package/modules/characters/useModel.js +3 -3
- package/modules/characters/walkTo.js +11 -17
- package/modules/collision/Collision.js +26 -20
- package/modules/collision/contract.js +15 -0
- package/modules/content/explain.js +1 -2
- package/modules/content/fields.js +24 -3
- package/modules/content/ids.js +2 -2
- package/modules/content/index.js +61 -99
- package/modules/content/loader.js +14 -17
- package/modules/content/markers.js +25 -0
- package/modules/content/models.js +10 -7
- package/modules/content/packs.js +3 -3
- package/modules/content/parts.js +2 -2
- package/modules/content/places.js +35 -0
- package/modules/content/props.js +17 -14
- package/modules/content/rules.js +25 -21
- package/modules/content/stages.js +7 -7
- package/modules/content/templates.js +20 -20
- package/modules/content/words.js +34 -0
- package/modules/debug/DebugPanel.js +10 -43
- package/modules/flow/contract.js +1 -1
- package/modules/flow/index.js +11 -7
- package/modules/gameplay/Container.js +12 -11
- package/modules/gameplay/Containers.js +14 -5
- package/modules/gameplay/Dialogue.js +13 -11
- package/modules/gameplay/Interactions.js +37 -24
- package/modules/gameplay/Inventory.js +8 -9
- package/modules/gameplay/Quests.js +16 -9
- package/modules/gameplay/boxOps.js +1 -1
- package/modules/gameplay/dialogueBubbles.js +3 -4
- package/modules/gameplay/inventoryOps.js +0 -1
- package/modules/gameplay/pickups.js +22 -23
- package/modules/gameplay/questSave.js +3 -3
- package/modules/grid/Grid.js +1 -1
- package/modules/grid/Layer.js +4 -4
- package/modules/grid/index.js +7 -8
- package/modules/grid/preview.js +7 -7
- package/modules/grid/tiles.js +6 -6
- package/modules/hlod/index.js +37 -55
- package/modules/hud/index.js +17 -11
- package/modules/hud/parts.js +4 -4
- package/modules/level/contract.js +16 -0
- package/modules/level/heightfield.js +12 -10
- package/modules/level/index.js +47 -152
- package/modules/level/load.js +79 -0
- package/modules/level/meshes.js +65 -0
- package/modules/level/nodes.js +6 -7
- package/modules/lights/index.js +28 -181
- package/modules/lights/slots.js +93 -0
- package/modules/lights/sources.js +88 -0
- package/modules/music/Music.js +30 -26
- package/modules/music/rules.js +1 -1
- package/modules/nav/contract.js +14 -0
- package/modules/nav/index.js +11 -10
- package/modules/net/Client.js +7 -7
- package/modules/net/Host.js +7 -7
- package/modules/net/Net.js +1 -1
- package/modules/net/index.js +5 -4
- package/modules/net/sync.js +2 -2
- package/modules/net/transports.js +2 -2
- package/modules/particles/Particles.js +11 -8
- package/modules/particles/effect.js +7 -5
- package/modules/particles/shaders.js +2 -1
- package/modules/photo/Photo.js +15 -17
- package/modules/rigid/RigidBodies.js +66 -43
- package/modules/rigid/Vehicles.js +2 -3
- package/modules/rigid/ragdoll.js +287 -0
- package/modules/rigid/ragdollBones.js +159 -0
- package/modules/rigid/sync.js +6 -6
- package/modules/settings/Settings.js +108 -39
- package/modules/settings/apply.js +6 -6
- package/modules/settings/sections.js +16 -14
- package/modules/settings/view.js +3 -3
- package/modules/sky/Sky.js +29 -22
- package/modules/sky/clouds.js +7 -7
- package/modules/sky/dome.js +33 -20
- package/modules/sky/domeLayers.js +9 -9
- package/modules/sky/environment.js +6 -6
- package/modules/sky/frame.js +19 -10
- package/modules/sky/season.js +7 -1
- package/modules/sky/shader.js +24 -25
- package/modules/sky/skyModule.js +14 -27
- package/modules/sky/tint.js +1 -1
- package/modules/swarm/Swarm.js +346 -0
- package/modules/swarm/draw.js +68 -0
- package/modules/swarm/grid.js +63 -0
- package/modules/terrain/ChunkManager.js +70 -52
- package/modules/terrain/chunkQueries.js +7 -24
- package/modules/terrain/chunkWorker.js +1 -1
- package/modules/terrain/draw.js +14 -11
- package/modules/terrain/index.js +28 -34
- package/modules/terrain/terrainColorMap.js +6 -3
- package/modules/terrain/terrainDefaults.js +2 -1
- package/modules/terrain/terrainEdit.js +32 -27
- package/modules/terrain/terrainGen.js +17 -12
- package/modules/terrain/terrainIsland.js +2 -2
- package/modules/terrain/terrainMesh.js +7 -6
- package/modules/terrain/terrainShape.js +8 -10
- package/modules/terrain/terrainShapeMain.js +3 -3
- package/modules/timeline/Timeline.js +27 -19
- package/modules/timeline/Tween.js +6 -6
- package/modules/timeline/shots.js +5 -7
- package/modules/triggers/index.js +9 -9
- package/modules/vegetation/Vegetation.js +30 -23
- package/modules/vegetation/densityMap.js +4 -7
- package/modules/vegetation/draw.js +23 -18
- package/modules/vegetation/groundChunks.js +11 -31
- package/modules/vegetation/index.js +8 -6
- package/modules/vegetation/modelGeometry.js +3 -6
- package/modules/vegetation/nearFade.js +1 -1
- package/modules/water/Water.js +16 -16
- package/modules/water/surface.js +3 -3
- package/modules/weather/Weather.js +41 -30
- package/modules/weather/particles.js +8 -8
- package/modules/weather/weatherDraw.js +22 -18
- package/modules/world/World.js +8 -8
- package/modules/world/explain.js +1 -1
- package/modules/world/index.js +18 -12
- package/modules/world/persist.js +73 -25
- package/modules/world/pos.js +4 -4
- package/modules/world/records.js +28 -8
- package/modules/world/sim.js +4 -4
- package/modules/world/state.js +12 -5
- package/modules/world/thingSource.js +4 -2
- package/modules/world/views.js +11 -9
- package/package.json +42 -7
- package/presets.js +1 -3
- package/render/PostFX.js +39 -27
- package/render/backend.js +26 -32
- package/render/cascades.js +17 -12
- package/render/cascades.tsl.js +5 -8
- package/render/daylight.js +20 -3
- package/render/detail.js +8 -7
- package/render/effects.js +28 -25
- package/render/fuse.js +3 -3
- package/render/fx/cloudShadow.tsl.js +3 -3
- package/render/fx/detail.tsl.js +1 -1
- package/render/fx/index.js +5 -10
- package/render/fx/library.tsl.js +11 -0
- package/render/fx/lighting.tsl.js +2 -1
- package/render/fx/nodeErrors.tsl.js +2 -2
- package/render/fx/objectOrigin.tsl.js +1 -2
- package/render/fx/patchNodes.tsl.js +5 -15
- package/render/fx/postWebGPU.tsl.js +27 -23
- package/render/fx/sky.tsl.js +15 -17
- package/render/fx/uniforms.tsl.js +4 -4
- package/render/fx/wind.tsl.js +1 -1
- package/render/fxNumbers.js +3 -0
- package/render/layers.js +1 -1
- package/render/lighting.js +5 -3
- package/render/lightmap.js +20 -20
- package/render/lights.js +6 -6
- package/render/lit.js +24 -0
- package/render/materials.js +8 -7
- package/render/mergeCommon.js +22 -0
- package/render/modeling.js +2 -2
- package/render/occlusion.js +20 -4
- package/render/ownFrame.js +4 -4
- package/render/patches.js +13 -13
- package/render/postWebGL.js +12 -10
- package/render/probes.js +16 -19
- package/render/recordSweep.js +117 -0
- package/render/shaderErrors.js +10 -9
- package/render/shadowCache.tsl.js +107 -0
- package/render/shadowTypes.js +9 -0
- package/{core → render}/shadows.js +57 -11
- package/render/slots.js +7 -7
- package/render/terms.js +22 -24
- package/render/uniformDecl.js +1 -1
- package/types/core.d.ts +200 -153
- package/types/gameplay.d.ts +163 -91
- package/types/generated/core/{Audio.d.ts → audio/Audio.d.ts} +22 -7
- package/types/generated/core/{audioVoice.d.ts → audio/audioVoice.d.ts} +2 -2
- package/types/generated/core/{Events.d.ts → base/Events.d.ts} +4 -4
- package/types/generated/core/{I18n.d.ts → base/I18n.d.ts} +7 -15
- package/types/generated/core/{Random.d.ts → base/Random.d.ts} +4 -3
- package/types/generated/core/{page.d.ts → engine/page.d.ts} +8 -9
- package/types/generated/core/{Input.d.ts → input/Input.d.ts} +12 -8
- package/types/generated/core/{Budget.d.ts → inspect/Budget.d.ts} +36 -26
- package/types/generated/core/{DebugOverrides.d.ts → inspect/DebugOverrides.d.ts} +2 -2
- package/types/generated/core/{Ops.d.ts → ops/Ops.d.ts} +4 -3
- package/types/generated/core/{control.d.ts → ops/control.d.ts} +4 -10
- package/types/generated/core/{Saves.d.ts → saves/Saves.d.ts} +37 -13
- package/types/generated/core/{session.d.ts → saves/session.d.ts} +2 -1
- package/types/generated/core/{Rays.d.ts → scene/Rays.d.ts} +8 -27
- package/types/generated/core/{Views.d.ts → scene/Views.d.ts} +1 -1
- package/types/generated/core/{Batching.d.ts → stream/Batching.d.ts} +7 -7
- package/types/generated/core/{Stream.d.ts → stream/Stream.d.ts} +18 -16
- package/types/generated/core/{Commits.d.ts → threads/Commits.d.ts} +1 -1
- package/types/generated/core/{Jobs.d.ts → threads/Jobs.d.ts} +6 -6
- package/types/generated/core/{Threads.d.ts → threads/Threads.d.ts} +4 -4
- package/types/generated/modules/calendar/Calendar.d.ts +10 -11
- package/types/generated/modules/debug/DebugPanel.d.ts +1 -9
- package/types/generated/modules/grid/Layer.d.ts +1 -1
- package/types/generated/modules/grid/index.d.ts +3 -3
- package/types/generated/modules/music/Music.d.ts +7 -5
- package/types/generated/modules/particles/Particles.d.ts +1 -1
- package/types/generated/modules/sky/Sky.d.ts +21 -10
- package/types/generated/modules/swarm/Swarm.d.ts +80 -0
- package/types/generated/modules/timeline/Timeline.d.ts +2 -1
- package/types/generated/modules/water/Water.d.ts +1 -0
- package/types/generated/modules/weather/Weather.d.ts +16 -12
- package/types/generated/modules/weather/weatherDraw.d.ts +3 -3
- package/types/generated/modules/world/World.d.ts +5 -3
- package/types/generated/render/PostFX.d.ts +17 -11
- package/types/generated/render/materials.d.ts +1 -0
- package/types/generated/render/occlusion.d.ts +9 -0
- package/types/generated/render/patches.d.ts +1 -0
- package/types/generated/ui/Focus.d.ts +1 -0
- package/types/generated/ui/UI.d.ts +1 -0
- package/types/nav.d.ts +11 -11
- package/types/physics.d.ts +99 -70
- package/types/tsl.d.ts +37 -4
- package/types/world.d.ts +38 -71
- package/ui/Focus.js +10 -9
- package/ui/Parts.js +4 -3
- package/ui/UI.js +7 -7
- package/ui/defaults.js +3 -2
- package/ui/theme.js +5 -3
- package/core/assetEntry.js +0 -109
- package/core/holds.js +0 -134
- package/core/shadowTypes.js +0 -16
- package/core/util.js +0 -17
- package/docs/MIGRATING-0.3.md +0 -248
- package/docs/MIGRATING-0.4.md +0 -320
- package/docs/MIGRATING-0.5.md +0 -68
- package/docs/MIGRATING-0.6.md +0 -126
- package/docs/PERF.md +0 -245
- package/docs/recipes/36-sky-ground-plants.md +0 -158
- package/docs/recipes/37-terrain-hooks.md +0 -115
- package/docs/recipes/38-environment-hooks.md +0 -67
- package/docs/recipes/42-terrain-shape.md +0 -64
- package/docs/recipes/47-island-snow-backdrop.md +0 -43
- package/docs/recipes/54-three-idioms.md +0 -88
- package/examples/plain-picture/FINDINGS.md +0 -53
- /package/core/{Vars.js → base/Vars.js} +0 -0
- /package/core/{mulberry32.js → base/mulberry32.js} +0 -0
- /package/core/{inputDefaults.js → input/inputDefaults.js} +0 -0
- /package/core/{textureBytes.js → inspect/textureBytes.js} +0 -0
- /package/core/{actor.js → ops/actor.js} +0 -0
- /package/core/{opsFail.js → ops/opsFail.js} +0 -0
- /package/core/{opsHistory.js → ops/opsHistory.js} +0 -0
- /package/core/{saveIds.js → saves/saveIds.js} +0 -0
- /package/core/{screenToGround.js → scene/screenToGround.js} +0 -0
- /package/core/{tier.js → scene/tier.js} +0 -0
- /package/core/{cells.js → stream/cells.js} +0 -0
- /package/core/{streamCells.js → stream/streamCells.js} +0 -0
- /package/core/{pureWorker.js → threads/pureWorker.js} +0 -0
- /package/examples/{sheepisland → perf-island}/content/index.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/props.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/templates.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/vegetation.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/lights.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/materials.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/sky.js +0 -0
package/docs/recipes/29-grid.md
CHANGED
|
@@ -128,7 +128,7 @@ engine.ops.define('plot.dig', { args: { cell: 'any' },
|
|
|
128
128
|
e.grids.get('plots').layer('state').set(cell, { dug: true }); // per-cell game state
|
|
129
129
|
} });
|
|
130
130
|
```
|
|
131
|
-
Undo with `paint: null` and `raise`.
|
|
131
|
+
Undo with `paint: null` and `raise`.
|
|
132
132
|
|
|
133
133
|
## 6. Verify
|
|
134
|
-
`engine.describe().grids` -> `{ room: { occupied, items: { bed: 1 }, layers: {} }, plot: { ..., layers: { soil: 30 } } }`.
|
|
134
|
+
`engine.describe().grids` -> `{ room: { occupied, items: { bed: 1 }, layers: {} }, plot: { ..., layers: { soil: 30 } } }`.
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
# Templates: reusable objects, definition vs instance state
|
|
2
2
|
|
|
3
|
-
**In this recipe**: 1. Define a template · 2. Place instances · 3. What belongs to the definition, what to the instance ·
|
|
4
|
-
5. Point -> thing · 6. When to use a template
|
|
3
|
+
**In this recipe**: 1. Define a template · 2. Place instances · 3. What belongs to the definition, what to the instance ·
|
|
4
|
+
5. Point -> thing · 6. When to use a template · 7. A group of things
|
|
5
5
|
|
|
6
6
|
Requires `world()` (in `openWorld()`); a template with `interact` needs `interactions({ ...presets.interactions.nearest })`, with `container` needs
|
|
7
|
-
`inventory()`.
|
|
7
|
+
`inventory()`.
|
|
8
8
|
|
|
9
9
|
A **template** describes one kind of object once: its model, collision, interaction, container, sound, animation and the default values of its saved
|
|
10
10
|
state. Every chest, campfire or bed you place is an **instance**: a world record that names the template (its `kind` is the template name) and holds
|
|
11
|
-
only its own state. There is no inheritance and no variant layer; a different look or behaviour is another template
|
|
11
|
+
only its own state. There is no inheritance and no variant layer; a different look or behaviour is another template, and a template is plain JS, so
|
|
12
|
+
`{ ...chest, model: 'iron-chest' }` is that other template in one line.
|
|
12
13
|
|
|
13
14
|
## 1. Define a template
|
|
14
15
|
`games/<game>/content/templates.js` (add it to `content/index.js`):
|
|
@@ -57,7 +58,7 @@ turret: { model: 'turret', state: { ammo: 30 }, fields: { ammo: { min: 0, max: 9
|
|
|
57
58
|
```
|
|
58
59
|
`npm run check` then reports a placement with `stage: 9`, `sort: 'rice'` or a misspelled `stagee` (with the closest name), and dev `engine.content.spawn`
|
|
59
60
|
throws on the same mistakes. `engine.content.fields('crop')` returns the whole table (placement fields plus state fields, with each state default),
|
|
60
|
-
in the `core/params.js` format; `fields('props')`, `fields('pickups')`, `fields('views')` and `fields('props.grid')` give the engine's own placement
|
|
61
|
+
in the `core/base/params.js` format; `fields('props')`, `fields('pickups')`, `fields('views')` and `fields('props.grid')` give the engine's own placement
|
|
61
62
|
fields, and a game kind in `content/rules.js` can declare `fields` the same way. A state field may not be named `id`, `kind` or `position`: those
|
|
62
63
|
are the record's own.
|
|
63
64
|
|
|
@@ -122,7 +123,7 @@ export default {
|
|
|
122
123
|
},
|
|
123
124
|
};
|
|
124
125
|
```
|
|
125
|
-
- `duration` is
|
|
126
|
+
- `duration` is calendar seconds (`engine.clock.now`) spent in a stage; only the last stage may leave it out (it stays there). `scale` multiplies the
|
|
126
127
|
instance's scale; `model` is a model name shown from that stage on. Stages are data: content-check validates them with the engine's own rules.
|
|
127
128
|
- Each instance gets the state field `stage` (default 0, an int 0..n-1, so a placement may write `{ template: 'crop', stage: 2 }` and
|
|
128
129
|
`content.fields('crop').stage` describes it) and `stageAt`, the clock time it entered. Both are on the world record and saved like any other field.
|
|
@@ -152,11 +153,6 @@ value on the record instead (`engine.world.set(id, { opened: true })`). Read a d
|
|
|
152
153
|
`engine.inventory.item(id)`. For your own tables of kinds (enemy types, crop types), the same split applies: keep the table in content, store `kind`
|
|
153
154
|
plus the changing values on the record, and wrap the table with `Object.freeze` if you like. <!-- r18-ignore-line -->
|
|
154
155
|
|
|
155
|
-
## 4. Tests
|
|
156
|
-
`tests/specs/templates.mjs`: two chests of one template share the model, open / goods per instance, save and reload restores each, the definition
|
|
157
|
-
never changes. `tests/specs/template-stages.mjs`: stages grow over game time near and far and survive save / load, `update` runs on the
|
|
158
|
-
fixed step, an interaction runs its op, and the engine root has no second placement path (no entities module, no root-level spawn). `tests/specs/single-source.mjs` (`npm test -- "Single source"`): ids, duplicates, baseline + diff, orphans, level nodes, source lines, pick.
|
|
159
|
-
|
|
160
156
|
## 5. Point -> thing: where is this defined
|
|
161
157
|
Runtime ops change only the current session and its saves. To change the level itself, edit the content files or the level model, then reload. To find
|
|
162
158
|
the entry, ask the engine what a thing is:
|
|
@@ -173,16 +169,56 @@ line numbers); a release build has none and pays nothing. From a terminal or an
|
|
|
173
169
|
top-left) or the MCP tool `pick { x, y }`.
|
|
174
170
|
|
|
175
171
|
## 6. When to use a template
|
|
176
|
-
|
|
177
|
-
windmill, colliders, interactions. A template plus a placement with an `id` in `content/props.js` (or `pickups`, `npcs`, `containers`, a game kind
|
|
178
|
-
from `rules.js`, the level model) is what you want when the thing must be saved with its own state, edited without touching code, or copied many
|
|
179
|
-
times. Both land in the same registry: `engine.thing(id)` answers for either and says what a save keeps (recipe 40). Game code keeps the rules: ops,
|
|
180
|
-
`world.simulate` / `world.present`, conditions and UI. Something that appears during play is created inside an op with `engine.content.spawn`.
|
|
172
|
+
Plain three.js or a template: recipe 40 sections 1 and 2 decide. Game code keeps the rules: ops, `world.simulate` / `world.present`, conditions and UI. Something that appears during play is created inside an op with `engine.content.spawn`.
|
|
181
173
|
|
|
182
|
-
`npm run check` (rule R33) flags only what
|
|
174
|
+
`npm run check` (rule R33) flags only what can break, in examples, templates and `games/*` alike. Warning, with `// runtime: <reason>` as the way to say it is fine (no saves, a new run only): `world.add` (without `{ save: false }`),
|
|
183
175
|
`engine.content.spawn`, `pickups.spawn` or `npcs.add` at module top level or in an `engine:ready` / `level:loaded` / `session:start`
|
|
184
|
-
handler, because those are saved whole and the startup code would make a second copy after every load
|
|
185
|
-
anywhere. Warning: code that `engine.add`s a `world.view(id)` model or writes its position / rotation / scale (world puts it back every frame).
|
|
176
|
+
handler, because those are saved whole and the startup code would make a second copy after every load. Error: `world.add(…, { initial: true })`
|
|
177
|
+
anywhere, which corrupts what saves compare against. Warning: code that `engine.add`s a `world.view(id)` model or writes its position / rotation / scale (world puts it back every frame).
|
|
186
178
|
The fix is a placement in content, or an op. Places computed from the seed (a flat spot for `home`) stay in code and are passed as `places` to
|
|
187
179
|
`content.load`; a mesh built in code becomes a model by name (`engine.assets.manifest({ models: { cabin } })`) when you want it as a template.
|
|
188
180
|
A line that really must do it from code at startup carries `// runtime: <reason>`.
|
|
181
|
+
|
|
182
|
+
## 7. A group of things
|
|
183
|
+
A market stall, a gun nest, a pit lane, a shop shelf, a puzzle room: several things that belong together. Content stays flat. Each thing is its own plain
|
|
184
|
+
entry with its own id, and what holds them together is the **place** they stand at. Nothing nests at runtime: there is no group object, no parent and no
|
|
185
|
+
per-part override, so `engine.thing(id)`, the save, `threedog content set` and `engine.pick` see each entry the same way as any other.
|
|
186
|
+
|
|
187
|
+
`content/places.js`, one place per group; `rot` is optional, radians about Y:
|
|
188
|
+
```js
|
|
189
|
+
export default { 'stall-1': { x: 40, z: -12 }, 'nest-1': { x: 8, z: 30, rot: 1.57 } };
|
|
190
|
+
```
|
|
191
|
+
`content/props.js`, entries around that place (`template` is the prototype, `id` the instance):
|
|
192
|
+
```js
|
|
193
|
+
export default [
|
|
194
|
+
{ id: 'stall-1-counter', model: 'counter', collide: 'box', place: 'stall-1', source: 'stall' },
|
|
195
|
+
{ id: 'stall-1-chest', template: 'chest', place: 'stall-1', x: 1, source: 'stall' },
|
|
196
|
+
{ id: 'nest-1-wall', template: 'sandbags', place: 'nest-1', z: 2, source: 'nest' },
|
|
197
|
+
{ id: 'nest-1-gun', template: 'turret', place: 'nest-1', x: 1, rot: 0.5, ammo: 5, source: 'nest' },
|
|
198
|
+
];
|
|
199
|
+
```
|
|
200
|
+
**One edit moves the group.** An entry's `x`, `z` are offsets from the place and turn with its `rot` (the same sense as a model's `rotation.y`); its own `rot` adds to
|
|
201
|
+
the place's. Change the place and every entry follows, with its model and collision. This also holds without a page reload when the place changes through a
|
|
202
|
+
second `engine.content.load(data, { places })`. What play moved or turned stays where the player left it, and a save keeps only what play changed, so an old
|
|
203
|
+
save follows the new place too. Only places in `places.js` (or the `places` of `content.load`) have `rot`; a level marker gives a position.
|
|
204
|
+
|
|
205
|
+
**`source`** (experimental, with `content stamp` and `content capture`) is a plain optional string on a model or template entry, naming what the entry was copied from. It has no effect at runtime; it is there to ask:
|
|
206
|
+
```js fragment
|
|
207
|
+
engine.world.query({ where: r => r.source === 'stall' }); // every thing copied from that arrangement
|
|
208
|
+
```
|
|
209
|
+
**Moving entries by hand.** On the dev server press F2 (or add `?edit=1` to the address), click an entry and drag its handle: letting go writes `x` and `z` into its content file, as an offset when it stands on a place. Comments and alignment stay. A value someone changed since the click is refused, and code-built entries and things added by code say why they cannot be saved.
|
|
210
|
+
|
|
211
|
+
**Arrangements.** To stamp out the same group again (`threedog content stamp <name> id=stall-1 x=20 z=5 rot=1.6`, then `threedog content set --source <name> <part> y=2` changes that part in every copy, as one explicit edit), keep it as a small file, `content/arrangements/<name>.js`: entries around zero, with a local `part` name
|
|
212
|
+
instead of an id and no place. Only the tools read it, when they copy it into `props.js`; the game never loads it, so the copies are ordinary entries from then
|
|
213
|
+
on and changing the file later changes nothing already placed.
|
|
214
|
+
```js
|
|
215
|
+
export default [
|
|
216
|
+
{ part: 'counter', model: 'counter', collide: 'box' },
|
|
217
|
+
{ part: 'chest', template: 'chest', x: 1 },
|
|
218
|
+
];
|
|
219
|
+
```
|
|
220
|
+
Copied to `stall-1`, part `chest` becomes `{ id: 'stall-1-chest', template: 'chest', place: 'stall-1', x: 1, source: 'stall' }`.
|
|
221
|
+
|
|
222
|
+
**Deleting.** Delete an entry and a save that changed it still loads: the change is an orphan, kept in the save, listed in `engine.describe().world.orphans` and warned
|
|
223
|
+
about once; the `renames` content file says where it went (`null` = deleted on purpose). Delete a place and `threedog check` names every entry still standing on it; the
|
|
224
|
+
load refuses it too (`content-place`), because an entry with no place has no position.
|
package/docs/recipes/31-audio.md
CHANGED
|
@@ -6,8 +6,7 @@ Everything you hear is the game's. The engine ships no sound files and plays not
|
|
|
6
6
|
|
|
7
7
|
## 1. Config in one place
|
|
8
8
|
Two places, one job each: **the asset manifest says what a sound is** (a file, or a synth function made in code, registered by name like a
|
|
9
|
-
model), **`audio.sounds` says how it plays** (which sound or variants, volume, bus, cooldown...).
|
|
10
|
-
(`footstep`, `shutter`, `thunder`, ambience's `wind` `rain` `water` `birds` `crickets`) as built-in sound assets that stay silent until a rule names them.
|
|
9
|
+
model), **`audio.sounds` says how it plays** (which sound or variants, volume, bus, cooldown...).
|
|
11
10
|
```js
|
|
12
11
|
const engine = createEngine({ canvas, audio: {
|
|
13
12
|
levels: { music: 0.4, voice: 1 }, // volume per bus; an extra key (voice) adds a bus
|
|
@@ -33,7 +32,8 @@ Code may hold functions (a `volume: e => ...`); the same config as data goes in
|
|
|
33
32
|
|
|
34
33
|
## 2. Buses and sounds by name
|
|
35
34
|
Buses are real Web Audio `GainNode`s: `master`, `music`, `sfx`, `ambience`, `ui`, plus the game's own (`levels: { voice: 1 }` or
|
|
36
|
-
`engine.audio.addBus('voice')`). `engine.audio.setVolume('music', 0.3)` sets one; `engine.audio.buses.sfx` is the node to connect your own nodes to.
|
|
35
|
+
`engine.audio.addBus('voice')`). `engine.audio.setVolume('music', 0.3)` sets one; `engine.audio.buses.sfx` is the node to connect your own nodes to, and `buses.master` (also `audio.master`) is the total. `buses` is empty until audio
|
|
36
|
+
unlocks on the player's first click or key: build your own nodes on the `audio:ready` event. A name that is no bus warns once and gives `master`, so the sound still plays.
|
|
37
37
|
|
|
38
38
|
```js
|
|
39
39
|
engine.audio.sfx('door'); // plays on its bus (default sfx)
|
|
@@ -50,8 +50,7 @@ Built-in synth parameters (`params`): `wind` / `water` take `freq` (filter Hz),
|
|
|
50
50
|
4300); every synth also gets `pitch`, the sfx pitch multiplier (~1). A sound whose file fails to load keeps its ambience rule silent (one warning)
|
|
51
51
|
until the rules load again, instead of refetching.
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
Connect to `out` and return the length in seconds (or `{ stop(t) }` for a loop).
|
|
53
|
+
A synth with default params is `{ build: synthFn, params }` in the manifest.
|
|
55
54
|
|
|
56
55
|
## 3. Ambience: a rule table
|
|
57
56
|
Each rule names a sound and says when and how loud. A rule with `every` is a one-shot at random gaps; without, a loop that fades in and out (and stops
|
|
@@ -84,6 +83,7 @@ engine.music.intensity = 0.8; // stems fade in as
|
|
|
84
83
|
```
|
|
85
84
|
The same `when` keys as ambience. Tracks cross-fade (`fade`, default 2 s); a new rule result must hold `hold` seconds before switching.
|
|
86
85
|
`engine.music.override('boss')` picks by hand; `override(null)` hands back to the rules. `engine.music.stinger('win')` plays a short piece over the music.
|
|
86
|
+
Decoded music is large (about 21 MB a stereo minute), so it lives like any asset: `assets.release(name)` and `assets.trim()` (a level change calls it) free it, the longest-unused long sounds go by themselves over a memory budget, sounds still playing play on, and a freed sound loads again when played; effects under 10 s stay cached, and `preload: true` keeps a track.
|
|
87
87
|
|
|
88
88
|
## 5. Footsteps by surface
|
|
89
89
|
The player's footstep rhythm follows its speed (one step per foot landing). Each step plays the sound named by `footsteps[groundType]`, else
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
# Action game wiring: hp, attacks, enemy AI, drops and
|
|
1
|
+
# Action game wiring: hp, attacks, guns, enemy AI, drops, death, win and lose without engine combat rules
|
|
2
2
|
|
|
3
3
|
The engine has no health, damage, hit detection or death. An action game writes those as its own rules on top of systems that already exist. The
|
|
4
|
-
working example is `examples/action/` (page `/action.html`,
|
|
5
|
-
`tests/specs/action.mjs`.
|
|
4
|
+
working example is `examples/action/` (page `/action.html`, the rules in `main.js`, the room in `content/`).
|
|
6
5
|
|
|
7
6
|
## 1. What goes where
|
|
8
7
|
| Piece | Built on | In the example |
|
|
@@ -24,11 +23,21 @@ working example is `examples/action/` (page `/action.html`, about 150 lines of r
|
|
|
24
23
|
or test shapes instead (recipe 19).
|
|
25
24
|
- `player.die` decides what death does. The example offers `respawn` (`player.placeAt(spawn)`, full hp), `restart` and `gameover` (both end in
|
|
26
25
|
`engine.session.newGame()`, which is async flow and so runs from the frame hook, not inside the op).
|
|
26
|
+
- Win and lose are the game's rule too: one state field, judged last in the fixed step so it sees this step's hits. The end screen is a `makeWindow`
|
|
27
|
+
with `closable: false` (recipe 26).
|
|
28
|
+
|
|
29
|
+
## 2b. Guns: hitscan shots, spread, recoil
|
|
30
|
+
A hitscan weapon fires a ray, not a projectile (many real bullets in flight are `engine.swarm`, recipe 65). The shot is an op, so a key, a test and the dev bridge fire the same one.
|
|
31
|
+
- **The ray**: `engine.raycast(origin, direction, { far: range })` gives the nearest level or registered static mesh; `{ targets: 'all' }` adds rigid bodies.
|
|
32
|
+
An enemy that is neither: test its shape along the same ray and keep the nearer hit, so walls stop shots.
|
|
33
|
+
- **Aim**: build the direction from `engine.cameraRig.yaw` / `pitch`, not from `engine.camera`: the camera's matrix is only written on a drawn frame, so a fixed step or a test would read an old aim.
|
|
34
|
+
- **Spread**: bend the direction with `engine.random`, so a replay fires the same shots.
|
|
35
|
+
- **Recoil**: in the op, add to `cameraRig.pitch` and `yaw`, and let the view settle back in `onFixed`; the next shot's aim sees the climb. A first-person rig looks up with positive pitch, the follow camera with negative. The gun model's kick and the muzzle flash read the shot from an event in `onFrame`: they show, they change no rule.
|
|
27
36
|
|
|
28
37
|
## 3. Mouse attack and pointer lock
|
|
29
38
|
`followCamera({ ...presets.camera.overShoulder })` locks the mouse on a click. While locked, mouse buttons still arrive as `Mouse0`..`Mouse4` keys, so
|
|
30
|
-
`attack: { keys: ['Mouse0'] }` works in both states. The click that takes the lock is
|
|
31
|
-
|
|
39
|
+
`attack: { keys: ['Mouse0'] }` works in both states. The click that takes the lock is swallowed, so it does not swing; `swallowLockClick: false` delivers it.
|
|
40
|
+
`presets.player.aim` turns the player toward where the camera
|
|
32
41
|
looks, so a swing goes where you aim. The rules do not need the picture: `?picture=none` runs them under the engine's placeholder lights; the whole picture is
|
|
33
42
|
`examples/action/picture/`.
|
|
34
43
|
|
|
@@ -55,7 +64,7 @@ engine.player.mover = 'manual'; /* a cutscene, your own physics */ engine.player
|
|
|
55
64
|
- **Bullet time / time channels**: a character the engine drives moves and animates on `character.channel` (player `'player'`, NPCs `'world'`), so
|
|
56
65
|
`engine.mod('time.enemies', { owner: 'bullet-time', mul: 0.35 })` slows NPCs added with `npcs.add({ channel: 'enemies' })` (far ones too) and
|
|
57
66
|
`onFixed(fn, { channel: 'enemies' })` code; world records follow only with `world.simulate(kind, { near, channel: 'enemies' })` (without it they
|
|
58
|
-
keep the 'world' pace while everything else slows); `clock.after(1, 'poison:tick', data,
|
|
67
|
+
keep the 'world' pace while everything else slows); `clock.after(1, 'poison:tick', { data, channel: 'enemies' })` slows a timer with them. The player keeps
|
|
59
68
|
full speed unless you mod `'time.player'`. Your own `player.move(x, z, run, dt)` uses the dt you pass. Effects end in any order (recipe 55).
|
|
60
69
|
- **Platforms**: `characters.support(object, { id?, safe?, carry?: 'position' | 'position+yaw', inherit? })` returns `{ id, remove() }`. The rider
|
|
61
70
|
compares the platform's matrix with the one it recorded, so it does not matter whether the platform moves in your `onFixed` before or after the
|
|
@@ -30,8 +30,8 @@ const vista = engine.stream.source(towerTop, { detail: 'simple', radius: 600 });
|
|
|
30
30
|
```
|
|
31
31
|
- `radius` caps every loader's own range around that source (terrain view distance, present radius, `stream.radius`); without it each loader uses its own.
|
|
32
32
|
- `source.ready` is checked at the end of each frame; a new source counts after one full frame, so every loader has seen it. Fixed steps must run
|
|
33
|
-
(collision takes effect on a tick), so do not wait while `engine.
|
|
33
|
+
(collision takes effect on a tick), so do not wait while `engine.haltLoop()` is on without stepping.
|
|
34
34
|
- Leaving a place and coming back is safe: models unload, but records (an opened chest, a dropped item, a removed rock) stay in `engine.world` and the
|
|
35
35
|
models are rebuilt from them.
|
|
36
36
|
- Module authors with their own distance-based loader: read `engine.stream.sources({ detail: 'full' })` / `sources({ physics: true })` and
|
|
37
|
-
`s.reach(range)`, and register `engine.stream.
|
|
37
|
+
`s.reach(range)`, and register `engine.stream.addReadyCheck(name, s => ...)`. Do not read `engine.focus` or the player position for loading.
|
|
@@ -1,5 +1,53 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Lights, fog, exposure and environment lighting
|
|
2
2
|
|
|
3
|
+
**In this recipe**: Lights · Fog · Exposure and the tone curve · The sky as a map · Light probes · Lightmaps · Real-time bounced light · Light you can see in the air · Occlusion culling
|
|
4
|
+
|
|
5
|
+
Lights, fog and exposure are your own three.js code ([recipe 62](62-picture-code.md)): the sky computes signals and draws its dome, it writes none of them. The sky itself is `08-weather-sky.md`.
|
|
6
|
+
|
|
7
|
+
## Lights: the placeholders, and your own
|
|
8
|
+
The engine has one directional light (`engine.lights.sun`) and one hemisphere (`engine.lights.hemi`): still white placeholders (sun 2 at (40, 80, 30) with soft shadows, hemi 1.2), so a scene
|
|
9
|
+
with no picture code is neutral gray and not black. Nothing moves them, with or without a sky.
|
|
10
|
+
|
|
11
|
+
```js
|
|
12
|
+
const engine = createEngine({ canvas, lights: false }); // the placeholders stay out of the scene
|
|
13
|
+
const sun = new THREE.DirectionalLight(0xffd0a0, 2); engine.scene.add(sun, sun.target); // add your own lights before engine.start()
|
|
14
|
+
engine.onRender(() => { sun.position.copy(engine.uniforms.uSunDir.value).multiplyScalar(100); sun.intensity = 2 * engine.uniforms.uDaylight.value * engine.uniforms.uWeatherLight.value; });
|
|
15
|
+
const torch = new THREE.PointLight(0xffa040, 6, 12); engine.add(torch);
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
- `createEngine({ lights: false })`: the default sun and hemisphere are never put in the scene, `engine.lights.sun` / `hemi`
|
|
19
|
+
stay as detached objects so nothing reads `undefined`. Use it for a scene lit entirely by your own lights.
|
|
20
|
+
- Shadows: only the engine sun's box is managed. Your own `castShadow` lights work as in three.js, each costing its
|
|
21
|
+
own shadow pass; `engine.shadows` (recipe 45) takes them when you hand them in, and `engine.shadows.enabled = false` turns every shadow off.
|
|
22
|
+
- Add or remove lights before `engine.start()`; what a change costs mid-play, and many lamps with `lightPool`: recipe 09 "Lights and stalls".
|
|
23
|
+
|
|
24
|
+
## Fog: plain three.js, signals, your own math
|
|
25
|
+
```js
|
|
26
|
+
const fog = engine.scene.fog = new THREE.Fog(0x99bbbb, 60, 220); // or new THREE.FogExp2(color, density)
|
|
27
|
+
engine.onRender(() => { // a fog that follows the day and the weather: your picture/ code
|
|
28
|
+
fog.color.copy(engine.uniforms.uSkyHorizon.value);
|
|
29
|
+
fog.far = 220 / engine.uniforms.uWeatherFog.value;
|
|
30
|
+
});
|
|
31
|
+
```
|
|
32
|
+
There is no fog until your code makes one, and nothing writes it after that.
|
|
33
|
+
|
|
34
|
+
- Signals to read: `uSkyHorizon` is the color at the horizon, so fog in that color hides the line where the dome meets the ground; `uWeatherFog` is what the weather asks for, a
|
|
35
|
+
multiplier your code applies; `uViewDistance` says how far the world is meant to be seen (`terrain({ viewFog: true })` writes it).
|
|
36
|
+
- A fog color of your own that differs from the horizon: the dome fades its lower band to it, so fogged ground and sky still meet without a line.
|
|
37
|
+
- Color, near, far and density are live. Adding or removing `scene.fog`, or changing its type, recompiles materials once: do it at a scene change, not every frame.
|
|
38
|
+
- Your own fog math (height fog, a warm far haze): the `fogPars` and `fog` slots on a material, WebGL only (recipe 43), or your own `ShaderMaterial`:
|
|
39
|
+
`applyEffects(material, { patches: [{ name: 'haze', slot: 'fog', glsl: 'float f = 1.0 - exp(-fogDensity * vFogDepth); gl_FragColor.rgb = mix(gl_FragColor.rgb, vec3(1.0, 0.85, 0.7), f * 0.3);' }] })`.
|
|
40
|
+
- Check the result with `engine.describe('picture').picture.fog`; `threedog shot` says how much of the picture the fog makes up.
|
|
41
|
+
|
|
42
|
+
## Exposure and the tone curve
|
|
43
|
+
```js
|
|
44
|
+
engine.renderer.toneMappingExposure = 1.3;
|
|
45
|
+
engine.onRender(() => { engine.renderer.toneMappingExposure = 1 + 0.5 * (1 - engine.uniforms.uDaylight.value); }); // over the day: your picture/ code
|
|
46
|
+
engine.renderer.toneMapping = THREE.NeutralToneMapping; // the curve; materials recompile on their next draw
|
|
47
|
+
```
|
|
48
|
+
The engine picks no curve: `renderer.toneMapping` stays three.js's default (`NoToneMapping`) until your code writes it. A curve of your own is a post effect in the `'tone'` slot (recipe 52).
|
|
49
|
+
|
|
50
|
+
## Environment maps
|
|
3
51
|
`scene.environment` is plain three.js and stays `null` until your code writes it. The background (the sky dome or a skybox) and the environment lighting are two separate fields.
|
|
4
52
|
|
|
5
53
|
```js
|
|
@@ -15,24 +63,20 @@ engine.scene.environment = myPmremTarget.texture;
|
|
|
15
63
|
```
|
|
16
64
|
On `renderer: 'webgpu'` take `PMREMGenerator` from `three/webgpu`. A map you made is yours to dispose.
|
|
17
65
|
|
|
18
|
-
|
|
66
|
+
### The sky as a map: `engine.sky.environment({ into?, interval? })`
|
|
19
67
|
- Nothing is built before this call. Without `into` nothing is written anywhere: read `handle.texture` (a live getter) and put it on the materials you choose (`material.envMap`).
|
|
20
68
|
- With `into`, that object's `.environment` gets the map at each rebuild. A map you write there yourself stays: the rebuilds go on, but only `handle.texture` follows them.
|
|
21
69
|
- The dome is rendered into a cube and prefiltered with `PMREMGenerator`. It is rebuilt only when the sky colors, sun direction or cloud
|
|
22
|
-
cover actually changed AND at least `interval` seconds (default 1, 4
|
|
23
|
-
day builds once. A call before the first frame waits for that frame, so the map uses real colors.
|
|
70
|
+
cover actually changed AND at least `interval` seconds (default 1, 4 on a low-tier device; a number the game gives stands) passed since the last check, never every frame. A fixed time of
|
|
71
|
+
day builds once. A call before the first frame waits for that frame, so the map uses real colors. One map at a time: a second call replaces the first.
|
|
24
72
|
- The cube is at least 256 px per face (PMREMGenerator's floor in 0.187), so a low tier saves time by rebuilding less often, or by your `picture/` code skipping the call on `engine.tier === 'low'`.
|
|
25
73
|
- An asset map is a fixed photo: it does not dim at night. Write `scene.environmentIntensity` from your own frame code reading `engine.uniforms.uDaylight`.
|
|
26
74
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
-
|
|
30
|
-
diffuse light. So Lambert gets soft, direction-dependent ambient light colored by the environment (sky blue from above, ground color from below).
|
|
31
|
-
- No specular: the cube reflection mix in `envmap_fragment` only runs for `ENVMAP_TYPE_CUBE`, not for a PMREM map. Lambert surfaces never get
|
|
32
|
-
reflections from the scene environment (use a Standard / Physical material for that).
|
|
33
|
-
- Intensity is `scene.environmentIntensity`, direction offset is `scene.environmentRotation` (Y only here).
|
|
75
|
+
### What a MeshLambertMaterial does with it (three 0.187)
|
|
76
|
+
The engine's neutral materials are Lambert, so this is what most surfaces do by default.
|
|
77
|
+
- A Lambert material gets soft, direction-dependent ambient light colored by the environment (sky blue from above, ground color from below), and no specular: for reflections use a Standard / Physical material.
|
|
34
78
|
- The hemisphere light stays and adds on top. When you turn the environment on, lower your hemisphere light so shadows do not wash out.
|
|
35
|
-
- The first frame with an environment recompiles every Lambert program once
|
|
79
|
+
- The first frame with an environment recompiles every Lambert program once; do it at start-up, not mid-game.
|
|
36
80
|
- Toon, Basic and ShaderMaterial surfaces ignore it.
|
|
37
81
|
|
|
38
82
|
## Light probes (baked indirect light)
|
|
@@ -61,12 +105,16 @@ probes.remove();
|
|
|
61
105
|
The best-looking baked light, and free at run time: it is plain `material.lightMap` on a second UV set, so a file baked on WebGPU draws the same on WebGL. Baking needs a real GPU and Google Chrome on the machine that bakes, not on the player's.
|
|
62
106
|
```js
|
|
63
107
|
floor.userData.static = true; wall.userData.static = true; // named meshes that never move
|
|
64
|
-
// npx threedog bake light --out public/light/level.lightmap --size 1024
|
|
65
|
-
const
|
|
66
|
-
|
|
108
|
+
// npx threedog bake light --page "/?bake=1" --out public/light/level.lightmap --size 1024
|
|
109
|
+
const baking = new URLSearchParams(location.search).has('bake'); // the bake must see the lights the map replaces
|
|
110
|
+
if (!baking) {
|
|
111
|
+
const light = await engine.loadLightmap('light/level.lightmap'); // once the level is built
|
|
112
|
+
hemi.visible = false; // the bake saw it: keep the sun, drop the ambient
|
|
113
|
+
}
|
|
67
114
|
floor.material.lightMapIntensity = 1.2; // plain three.js, yours
|
|
68
115
|
```
|
|
69
|
-
- What is baked: sky and
|
|
116
|
+
- What is baked: sky and bounced light, by rays traced from every lightmap texel through the static meshes, so light stops at walls and a pillar shades what stands behind it. The sun stays real-time where it lands, so moving things keep their shadows, and its bounce is in the map. The game's hemisphere or ambient light is the sky during the bake, at the same strength: an open floor comes out as bright as under that light.
|
|
117
|
+
- Turning the ambient off: a line that sets `intensity` once is lost if picture code writes it every frame, as the template's `picture/lights.js` does. So hide the light (`visible = false`, which that code leaves alone) or change it where it is written. Do it behind a URL flag as above, not in the palette: with the ambient gone for good, the next bake sees no sky. A bake that sees no light at all stops and writes nothing.
|
|
70
118
|
- Instanced and skinned meshes and anything moving cannot hold a lightmap: give them `engine.bakeProbes`. A grid also lights the baked meshes, so where the two overlap the light doubles; keep the grid's `bounds` to where the moving things go, or turn `lightMapIntensity` down.
|
|
71
119
|
- Files are large: half precision, 8 MB at 1024, 32 MB at 2048, before the server's compression. Start small.
|
|
72
120
|
- Check it: `engine.describe().render.lightmap` lists `skipped` (instanced), `missing` (not found, or changed since the bake: bake again), `moved`, `doubled` (ambient light or a grid on top) and `shared` (an unbaked mesh on a baked material: give it its own).
|
|
@@ -87,10 +135,10 @@ engine.post.add(temporalAA()); // clears the dots; it replaces MSAA while it i
|
|
|
87
135
|
- It bounces direct light only, so sky light stays yours: a low hemisphere or environment light, judged by eye once the bounce is on. How to judge: a colored wall should tint what stands next to it, and a sunlit floor should lift the ceiling, without the shadows turning flat. A cartoon look may want one soft bounce; a realistic interior wants more with less fill.
|
|
88
136
|
- Changing any post effect (add, remove, on / off, a setting that rebuilds) rebuilds the chain, and that voxelizes the scene again: a stall. Set the chain at a scene change, not during play.
|
|
89
137
|
- `occlusion` (0 to 1) darkens corners from the voxels. It darkens direct light too, which is why it starts at 0.
|
|
90
|
-
- It costs real frame time on weak GPUs, so it declares `skipOnLowTier` and is held off on `engine.tier === 'low'`. It is also held on a device that fell back from WebGPU and under `forceWebGL: true`. Nothing breaks, `describe().render.post` says `held` and why, so give those players probes or a lightmap as the base.
|
|
138
|
+
- It costs real frame time on weak GPUs, so it declares `skipOnLowTier` and is held off on `engine.tier === 'low'`. It is also held on a device that fell back from WebGPU and under `forceWebGL: true`. Nothing breaks, `describe().render.post` says `held` and why, so give those players probes or a lightmap as the base.
|
|
91
139
|
- Does not work: metal gets a diffuse bounce instead of a reflection; anything moving is not in the bounce; transparent things are not handled; one volume does not cover a big open world.
|
|
92
140
|
|
|
93
|
-
What runs where, for the
|
|
141
|
+
What runs where, for `voxelGI` and the three effects around it (`temporalAA`, and `sunShafts` and `lightVolumes` of the next section). Held means the game's `enabled` stays as written, the effect costs nothing, and `describe().render.post` says why:
|
|
94
142
|
|
|
95
143
|
| Case | voxelGI | temporalAA, sunShafts, lightVolumes |
|
|
96
144
|
|---|---|---|
|
|
@@ -119,5 +167,5 @@ engine.post.add(lightVolumes({ bounds: new THREE.Box3(min, max) })); // spot
|
|
|
119
167
|
|
|
120
168
|
- Three things share the word occlusion and are separate: occlusion culling (this section) skips drawing what is hidden; camera occlusion (`cameraOcclusion` of `collision()`, recipe 21) moves the camera so a wall does not stand between it and the player; `voxelGI`'s `occlusion` only darkens corners of its bounced light.
|
|
121
169
|
- Hidden things stay in shadows, in `engine.rays` and in `voxelGI`'s volume, and `visible` stays yours. Nothing else sees them while hidden: a second camera of yours and a `THREE.Raycaster` of your own do not (their layers lack it; enable `RESERVED_LAYERS.occlusionHidden` from `threedog/layers` if they must).
|
|
170
|
+
- **Step mode hides nothing.** The answers arrive over drawn frames, so under `threedog step` / `engine.step()` (no real frames) `hidden` stays 0 and `inspect perf` counts every draw. Judge occlusion with `threedog resume` and real time, never from a step-mode reading.
|
|
122
171
|
- Answers come a few frames late. Camera moves and cuts are covered. A big occluder that moves fast (a falling wall, a gate thrown open) can show a gap of a few frames.
|
|
123
|
-
|
|
@@ -18,15 +18,14 @@ yours. How the `picture/` folder is laid out and which signals it reads are in `
|
|
|
18
18
|
|
|
19
19
|
## The loop (every round, in this order)
|
|
20
20
|
Looping "edit, screenshot, read the image" costs the most tokens and fixes the least. Numbers come first, pictures last.
|
|
21
|
-
1. **Measure the reference once** (step 2 below)
|
|
21
|
+
1. **Measure the reference once** (step 2 below). Break the picture into
|
|
22
22
|
techniques (shading, one texture language, palette, edges) before choosing values.
|
|
23
23
|
2. **Change one family of values** (colors, then materials, then post). After writing or changing a model, look at it alone
|
|
24
24
|
first: `threedog gallery --shots` (every model under three lights, `.threedog/gallery/index.html`) shows wrong scale, wrong facing, holes and missing
|
|
25
25
|
faces before the level hides them.
|
|
26
26
|
3. **Shoot small and compare to the previous shot**: `threedog shot --size 480x270 --keep --compare <previous.png>`. It prints the
|
|
27
27
|
pixel diff and the picture differences. Through MCP the `snap` tool is 480 px wide by default; `picture_compare` gives the numbers.
|
|
28
|
-
4. **Read the numbers first, then at most one image per round.** Name the biggest remaining difference and fix only that.
|
|
29
|
-
--out side.png` puts both in one image. With no reference, read the shot's hints (below). Then look at the image as a player would and judge it
|
|
28
|
+
4. **Read the numbers first, then at most one image per round.** Name the biggest remaining difference and fix only that. With no reference, read the shot's hints (below). Then look at the image as a player would and judge it
|
|
30
29
|
against the picture DESIGN.md wants and its "Loved / Not for this game" list (never against a technique example): what would a player read as a
|
|
31
30
|
mistake? Typical ones are objects floating or cutting into each other, odd flat discs or blobs (a hard-edged opaque "puddle" reads as a gray ball),
|
|
32
31
|
glare, areas too dark or busy to read, placeholder-looking shapes; these are prompts, not a list to tick. Fix what you find, or note it in
|
|
@@ -68,17 +67,15 @@ world (a canyon instead of hills), say so instead of faking it with colors.
|
|
|
68
67
|
The first frame should already be close: if it is far from the reference, fix sky, exposure, palette and material type before adding anything.
|
|
69
68
|
5. **Check.** `npm run check` type-checks `picture/`, and a misspelled option or a bad call fails on the page with a line in `.threedog/errors.log`.
|
|
70
69
|
6. **Picture: the loop above.** Take pictures with the same arguments every round so only the picture differs, from named places (`shot --at <place>`), not free `--pos` shots.
|
|
71
|
-
`
|
|
72
|
-
|
|
73
|
-
deliberately no "similarity %": the numbers turn "looks dirty / fragmented / too dark" into something you can change and re-measure. Dirty = lower
|
|
74
|
-
saturation or an off hue, fragmented = fine detail ratio well above 1, dark or flat = brightness and contrast. Keep a change if its number moved toward
|
|
70
|
+
`picture compare` prints brightness, saturation, contrast, fine detail, average and main color of both and one sentence such as "the screenshot is darker and more broken up", with deliberately no
|
|
71
|
+
"similarity %". Dirty = lower saturation or an off hue, fragmented = fine detail ratio well above 1, dark or flat = brightness and contrast. Keep a change if its number moved toward
|
|
75
72
|
the reference and the picture looks better. A phone UI frame in the screenshot skews the numbers: compare a `--region`.
|
|
76
|
-
|
|
73
|
+
`--out side.png` (MCP `picture_compare` always writes `<shot>.compare.png`) is one image, reference left, screenshot right.
|
|
77
74
|
7. **Stop** when the biggest remaining difference is a silhouette or a world rule: that is the assets or the game, not the picture code.
|
|
78
75
|
|
|
79
76
|
## Picture check after every shot
|
|
80
77
|
Every `threedog shot` prints picture numbers and hints (`--no-picture` skips them). The numbers are luminance, contrast (std and p5-p95 range of
|
|
81
|
-
luminance), saturation, clipped and near-black shares, and the shadow area. Hints come in
|
|
78
|
+
luminance), saturation, clipped and near-black shares, and the shadow area. Hints come in three kinds:
|
|
82
79
|
- **Contradictions**, whatever the art direction: the settings say one thing and the pixels another. Shadows on but none measurable (with the cause it found:
|
|
83
80
|
the light's `shadow.bias` as meters of shadow depth, the view outside the shadow box, texel size, or fill light washing them out), a light that changes
|
|
84
81
|
no pixel.
|
|
@@ -100,9 +97,8 @@ right for a given art direction.
|
|
|
100
97
|
`debug.view('lighting')`.
|
|
101
98
|
- **Shadows and contact**: do objects sit on the ground (contact shadow, AO, or a dark base), are shadow edges as hard or soft as the reference, no
|
|
102
99
|
acne or peter-panning? `debug.view('shadow')`. A shadow that starts a hand's width away from a foot or a crate is peter-panning: check
|
|
103
|
-
the light's `shadow.bias` (it is in 0-1 shadow depth, so a large value over a long light range is decimeters). Faint shadows: the
|
|
104
|
-
|
|
105
|
-
scene (texel size): fit `light.shadow.camera` to the scene.
|
|
100
|
+
the light's `shadow.bias` (it is in 0-1 shadow depth, so a large value over a long light range is decimeters). Faint shadows: key against fill ([recipe 60](60-judge-the-picture.md)); small casters blur when the
|
|
101
|
+
shadow box is much bigger than the scene ([recipe 45](45-cascaded-shadows.md)).
|
|
106
102
|
- **Day / night**: shoot noon and night (`shot --time 12:00`, `--time 22:00`); is night as dark as the design wants on every material, PBR ones
|
|
107
103
|
too? A PBR material that stays bright at night is usually lit by an environment map that does not follow the time: `scene.environmentIntensity` is yours to drive from `uDaylight`.
|
|
108
104
|
- **Material response**: do surfaces that should differ (wood, stone, metal, cloth, skin, water) differ in roughness, specular and color, not only hue?
|
|
@@ -133,11 +129,8 @@ Same arguments, same picture, so only the picture differs. A game with many pict
|
|
|
133
129
|
wood / stone / metal surfaces, a lit room (outside and inside) and the UI parts, under named cameras.
|
|
134
130
|
- `threedog shot styletest --view <name> [--time day|dusk|night] [--weather clear|rain|snow]`; the same words work as URL parameters
|
|
135
131
|
(`?view=room&time=dusk&weather=rain`).
|
|
136
|
-
- Views: `overview` (
|
|
137
|
-
|
|
138
|
-
`path` (the camera moves along a fixed line at 2.5 m/s: with `--wait 4` the shot is the same frame every time; in a browser look for grass blades
|
|
139
|
-
and shadow edges that flicker or crawl), `ui` (HUD, dialogue line, bag window: the UI colors).
|
|
140
|
-
- Per round: shoot `overview`, `room` at `--time dusk`, and `character`.
|
|
132
|
+
- Views: `overview`, `character`, `water`, `room`, `path` (the camera moves along a fixed line: with `--wait 4` the shot is the same frame every time; in a browser look for grass blades
|
|
133
|
+
and shadow edges that flicker or crawl), `ui`.
|
|
141
134
|
- The dev panel, in any game: `if (location.search.includes('panel=1')) import('@threedog/tools/panel').then(m => m.openPanel(engine));`
|
|
142
135
|
It needs the optional dev package `tweakpane` (`npm install -D tweakpane`; the repository's `npm install` has it); without it the page says so.
|
|
143
136
|
A production build of the vite preset gets a stub instead (no panel, no tweakpane in the bundle); dev and test builds get the real one.
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# Ground color and plants
|
|
2
|
+
|
|
3
|
+
```js
|
|
4
|
+
engine.use(terrain({ ...terrainPreset(), colors: { grass: 0x6a8a3a, rock: 0x777066 }, biomeColors: { meadow: ['grass'], cliff: ['rock'] } }));
|
|
5
|
+
engine.terrain.material.flatShading = true; // the ground's picture is a plain three.js material
|
|
6
|
+
engine.terrain.recolor({ colors: { grass: 0xa8a050, rock: 0x777066 } }); // what the workers baked in, changed at run time
|
|
7
|
+
engine.terrain.material = applyEffects(new THREE.MeshToonMaterial({ vertexColors: true }), { patches: engine.terrain.patches }); // your own, effects kept
|
|
8
|
+
engine.vegetation.material = applyEffects(new THREE.MeshToonMaterial({ vertexColors: true }), { patches: engine.vegetation.patches });
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
For an AI that wants the ground or the plants to look a way the defaults do not. Each section lists the engine default; code that sets nothing
|
|
12
|
+
gets it. None of these settings moves a hill, a river or a species list. The order of work from a reference picture is in `35-picture-from-reference.md`; which ground picture to pick, the color map and what to do when the ground looks wrong are in `53-ground-up-close.md`; the sky and clouds in `08-weather-sky.md`.
|
|
13
|
+
|
|
14
|
+
## Ground color: `terrain({ colors, biomeColors, steep, variation })`
|
|
15
|
+
Terrain colors are baked by the (worker) generator: two colors blended by a noise, a small brightness grain, and an optional layer of large patches.
|
|
16
|
+
`colors` names the colors, `biomeColors` gives each ground type one or two of those names, `steep` overrides them on slopes. A ground type with no
|
|
17
|
+
color is neutral gray. The `variation` defaults are shown (plain data, so it travels to the workers; unknown keys throw):
|
|
18
|
+
```js fragment
|
|
19
|
+
terrain({ colors: { ... }, biomeColors: { ... },
|
|
20
|
+
variation: {
|
|
21
|
+
blend: { size: 33, strength: 1 }, // wavelength in m of the two-color noise; strength > 1 = harder contrast, < 1 = flatter
|
|
22
|
+
jitter: { size: 0.33, min: 0.92, range: 0.12 }, // grain cell in m; darkest multiplier; how much brighter it can get (0 range = no grain)
|
|
23
|
+
patches: { size: 90, strength: 0.15, levels: 0, tint: 0xb59a5a }, // optional (example values): a second, large layer of color blocks
|
|
24
|
+
} })
|
|
25
|
+
```
|
|
26
|
+
`patches` is off unless given. It is a noise much larger than `blend`; `levels: 4` snaps it to 4 flat steps (hard-edged color blocks instead of a
|
|
27
|
+
soft blend); without `tint` it lightens and darkens the ground, with `tint` it pulls the color towards the tint where the noise is high. Vertex colors
|
|
28
|
+
interpolate across a chunk cell (4 m at the default resolution), so blocks smaller than that blur; for crisp blocks use `shading: 'texture'`
|
|
29
|
+
(recipe 53) or a texture (next).
|
|
30
|
+
|
|
31
|
+
### Changing it at run time: `engine.terrain.recolor`
|
|
32
|
+
```js fragment
|
|
33
|
+
engine.terrain.recolor({ colors, biomeColors, steep, variation, shading, normals }); // every chunk is rebuilt; edits stay, collision does not change
|
|
34
|
+
engine.terrain.recolor({ detail: { noise: 'paper', strength: 0.2 } }); // only the material: no chunk is rebuilt
|
|
35
|
+
```
|
|
36
|
+
Each value is given whole, not merged, and `null` takes it out (`shading: null` goes back to what `terrain({...})` was given). Keys left out stay.
|
|
37
|
+
`recolor` throws under a picture that replaced `'terrain-draw'`, which draws the ground its own way.
|
|
38
|
+
|
|
39
|
+
### Your own ground material
|
|
40
|
+
`engine.terrain.material` is what every chunk draws with: a plain three.js material, neutral gray with vertex colors until you change it. Write to it, or
|
|
41
|
+
set your own at any time; `terrain({ material })` (a Material or `(engine) => Material`) does the same from the start. Setting it swaps the material on
|
|
42
|
+
every loaded chunk, regenerates nothing and adds nothing: a material of yours is drawn as given. To keep the cloud shadow, the season tint and the
|
|
43
|
+
detail layer, hand it `engine.terrain.patches`. `terrain({ material })` adds them for you unless `effects: false`. After a later `recolor({ detail })`
|
|
44
|
+
patch your material again; the engine only rebuilds its own.
|
|
45
|
+
|
|
46
|
+
Chunk geometry has `position`, `normal`, `color` and `uv = world xz / chunk size`, continuous across chunk borders, so a repeating texture is seamless whatever chunk it lands in. `texture.repeat.set(8, 8)` = 8 tiles per chunk. Without
|
|
47
|
+
UVs (steep sides stretch a top-down map), project from the world position in a patch instead (`needs.patches: ['world']` gives `vThreedogWorld`):
|
|
48
|
+
```js
|
|
49
|
+
engine.terrain.material = applyEffects(new THREE.MeshLambertMaterial({ vertexColors: true }), { clouds: false, patches: [{
|
|
50
|
+
name: 'triplanar', needs: { patches: ['world'] }, uniforms: { uTex: { value: groundTexture }, uTexScale: { value: 0.1 } }, // groundTexture: repeat wrapping
|
|
51
|
+
glsl: { fragment: { pars: 'uniform sampler2D uTex; uniform float uTexScale;',
|
|
52
|
+
color_fragment: `vec3 n = abs(normalize(cross(dFdx(vThreedogWorld), dFdy(vThreedogWorld)))); n /= n.x + n.y + n.z;
|
|
53
|
+
diffuseColor.rgb *= texture2D(uTex, vThreedogWorld.zy * uTexScale).rgb * n.x + texture2D(uTex, vThreedogWorld.xz * uTexScale).rgb * n.y
|
|
54
|
+
+ texture2D(uTex, vThreedogWorld.xy * uTexScale).rgb * n.z;` } } }] });
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Detail layer
|
|
58
|
+
The lighter alternative, with no material of your own: `terrain({ detail })`, or `engine.terrain.recolor({ detail })` at run time. It takes
|
|
59
|
+
`noise: 'grain' | 'paper' | 'stroke' | 'dabs'`, or `texture: 'name'`, or your own `glsl`, and `scale`, `strength`, `fade` ... (keys in recipe 43). `engine.terrain.uniforms` are its `{ value }` objects, written directly and live:
|
|
60
|
+
`engine.terrain.uniforms.uDetailStrength.value = 0.2`.
|
|
61
|
+
|
|
62
|
+
## Plants and wind
|
|
63
|
+
`vegetation.define` works at any time after `engine.use`, before or after `content.load` and `engine.start`. A species named by a model (`model: 'oak'`) appears when its promise settles, so `vegetation.list()` right after
|
|
64
|
+
that call does not show it yet. To keep plants off a road or a yard, give the species a `densityMap: (x, z) => 0..1`, or a ground type of its own that the species' `biomes` leave out. Per-species options are in `../api/vegetation.md`; `castShadow` defaults to not `nearOnly`.
|
|
65
|
+
```js
|
|
66
|
+
engine.vegetation.define('oak', { model: await engine.assets.model('oak'), wind: 0.02 }); // per species: its own material, wind, fade
|
|
67
|
+
engine.vegetation.define('fern', { geometry, material: new THREE.MeshToonMaterial({ vertexColors: true }), wind: 0.08 });
|
|
68
|
+
engine.vegetation.material = applyEffects(new THREE.MeshToonMaterial({ vertexColors: true }), { patches: engine.vegetation.patches }); // the shared default
|
|
69
|
+
engine.uniforms.uWindAmp.value = 0.5; engine.uniforms.uWindFreq.value = 2; // how hard and how fast: plain signals, live (uWindAmp 0 = plants stand still)
|
|
70
|
+
```
|
|
71
|
+
`engine.vegetation.material` is what every species with no material or model of its own draws. Set it and it is drawn as given, on plants already
|
|
72
|
+
planted too: nothing is added behind it, so hand it `engine.vegetation.patches` (season tint, sway at one amplitude, the `color()` code) to keep those.
|
|
73
|
+
`null` gives the neutral default back. A species' own amplitude and near fade need a material of its own: `define(name, { material })` adds wind, cloud
|
|
74
|
+
shadows, season tint and the fade to it unless `effects: false`. Each species' live material is `engine.vegetationDraw.kind(name).material`.
|
|
75
|
+
|
|
76
|
+
The placement, rings and instancing are mechanism and stay (the whole picture is replaceable: recipe 28 section 6). The picture has three entries:
|
|
77
|
+
- **Sway shape**: built in, two sines with a phase from each plant's origin, weighted by height, leaning with wind strength. `engine.vegetation.sway(glsl)` replaces it (below).
|
|
78
|
+
- **Color**: `engine.vegetation.color(glsl | { glsl, tsl })` puts code in the `color` slot of every species, live.
|
|
79
|
+
- **Season tint**: `engine.sky.seasonTints = { mode: 'multiply' | 'mix', strength, autumn: { foliage: 0xffb070, ground: 0xc8a060 } }`, plain data read every frame, blended to the next season over the last fifth of a season. `'multiply'` (default) multiplies the surface; `'mix'` moves it `strength` (default 0.5) of the way to the color, so orange on green leaves stays orange instead of turning muddy.
|
|
80
|
+
|
|
81
|
+
```js
|
|
82
|
+
engine.vegetation.sway({ uniforms: { uSteps: 3 }, // stepped sway: plants snap between 3 poses instead of a smooth sine
|
|
83
|
+
glsl: `void threedogWind(inout vec3 transformed, vec3 ip, vec3 position){
|
|
84
|
+
float s = floor(sin(uTime * uWindFreq + ip.x * 0.3 + ip.z * 0.2) * uSteps) / uSteps;
|
|
85
|
+
transformed.x += s * max(position.y, 0.0) * THREEDOG_WIND_AMP * uWind;
|
|
86
|
+
}` });
|
|
87
|
+
```
|
|
88
|
+
`threedogWind` receives the vertex (`transformed`, object space), `ip` (world position of this plant's origin, so each plant has its own phase) and
|
|
89
|
+
`position`; `uTime`, `uWind` (weather), `uWindFreq` and `THREEDOG_WIND_AMP` (the species' amplitude) are in scope. It applies to every material made by
|
|
90
|
+
`vegetation.define` whose `wind` is a number, planted ones too, and the shadow sways with it. A missing function throws with the signature. WebGPU needs the `tsl` form: `{ glsl, tsl }`.
|
|
91
|
+
`sway(null)` gives the built-in sway back. A shared material the game set keeps what it was built with: apply the new `engine.vegetation.patches` to it. The same object works in code:
|
|
92
|
+
`applyEffects(mat, { wind: { amplitude: 0.03, glsl, uniforms } })`.
|
|
93
|
+
|
|
94
|
+
Two entries, two scopes: `sway()` is the default shape for all plants, and `vegetation.define(name, { wind: { amplitude, glsl, tsl, uniforms } })` is one species' own
|
|
95
|
+
sway. When both are set the species' own wins, and `sway()` and `sway(null)` leave it as it is. Use one `sway()` for the world and a `wind` object for the plant that moves differently.
|
|
96
|
+
|
|
97
|
+
The sway function is not where grass time goes (vertex count and fill are): reduce grass cost with `rule.perChunk`, `maxRing` and `nearOnly`, not the wind.
|
|
98
|
+
Grass has no billboard or blade-shape setting: give `vegetation.define` your own `geometry` or `model`.
|
|
99
|
+
|
|
100
|
+
### Near-only plants fade out by distance
|
|
101
|
+
Any `nearOnly` species (grass, flowers, pebbles, twigs, snow tufts, debris ...) is placed per chunk ring
|
|
102
|
+
(`maxRing`), whose edge would be a visible line. By default instances shrink toward their base over a band that ends at `maxRing x chunk size` from the
|
|
103
|
+
player (start at 65% of it), so nothing pops per chunk. Tune with `fade: { start: 20, end: 45 }` (metres), or `fade: false` for a hard edge
|
|
104
|
+
(e.g. a species hidden in fog anyway). It is part of the species' own material (no extra draw call or program), keeps wind sway and shadows in step, and is skipped
|
|
105
|
+
when `effects: false`. A larger `maxRing`, fog, or a ground color near the species' base color still help for stylized looks with strong silhouettes.
|