threedog 0.7.0 → 1.0.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 +411 -1
- package/README.md +8 -11
- package/core/{Animator.js → assets/Animator.js} +30 -18
- package/core/{Assets.js → assets/Assets.js} +131 -56
- package/core/{Baked.js → assets/Baked.js} +4 -4
- package/core/assets/assetEntry.js +302 -0
- package/core/{assetHot.js → assets/assetHot.js} +9 -7
- 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} +7 -14
- package/core/{namedModel.js → assets/namedModel.js} +17 -13
- package/core/{Audio.js → audio/Audio.js} +47 -25
- 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} +15 -12
- package/core/{Random.js → base/Random.js} +7 -4
- package/core/{Vars.js → base/Vars.js} +14 -4
- package/core/{easing.js → base/easing.js} +1 -1
- package/core/{errorCodes.js → base/errorCodes.js} +151 -125
- package/core/{errorHints.js → base/errorHints.js} +17 -10
- package/core/{errors.js → base/errors.js} +12 -10
- package/core/{events.generated.js → base/events.generated.js} +11 -0
- package/core/base/follows.js +26 -0
- package/core/base/math.js +66 -0
- package/core/{params.js → base/params.js} +5 -6
- package/core/base/saveValues.js +81 -0
- package/core/base/sections.js +97 -0
- package/core/base/spelling.js +32 -0
- package/core/base/util.js +32 -0
- package/core/{validate.js → base/validate.js} +34 -34
- package/core/{Engine.js → engine/Engine.js} +137 -91
- package/core/{Loading.js → engine/Loading.js} +34 -5
- package/core/{copies.js → engine/copies.js} +4 -4
- package/core/{headlessLoad.js → engine/headlessLoad.js} +32 -15
- package/core/{lifecycle.js → engine/lifecycle.js} +41 -34
- package/core/{loop.js → engine/loop.js} +88 -49
- package/core/engine/moduleSlots.js +176 -0
- package/core/{moduleTypes.js → engine/moduleTypes.js} +26 -14
- package/core/engine/modules.js +503 -0
- package/core/{page.js → engine/page.js} +59 -29
- package/core/{plugins.js → engine/plugins.js} +21 -12
- package/core/{services.js → engine/services.js} +50 -40
- package/core/{startup.js → engine/startup.js} +66 -54
- package/core/{Input.js → input/Input.js} +67 -39
- package/core/{inputContext.js → input/inputContext.js} +14 -5
- package/core/input/inputKeyboard.js +39 -0
- package/core/{inputPad.js → input/inputPad.js} +24 -3
- package/core/{inputPointer.js → input/inputPointer.js} +11 -3
- package/core/input/inputSeat.js +66 -0
- package/core/{inputTouch.js → input/inputTouch.js} +24 -7
- package/core/{Budget.js → inspect/Budget.js} +21 -20
- package/core/{DebugOverrides.js → inspect/DebugOverrides.js} +43 -18
- package/core/{Describe.js → inspect/Describe.js} +34 -26
- package/core/{Inspect.js → inspect/Inspect.js} +39 -10
- 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} +60 -24
- package/core/{catalog.js → inspect/catalog.js} +15 -8
- 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} +24 -22
- package/core/{describeText.js → inspect/describeText.js} +17 -8
- package/core/inspect/geometryWatch.js +38 -0
- package/core/{lightWatch.js → inspect/lightWatch.js} +8 -8
- package/core/inspect/metadata.generated.js +4140 -0
- package/core/{pictureWriters.js → inspect/pictureWriters.js} +130 -47
- package/core/{shaderCost.js → inspect/shaderCost.js} +1 -1
- package/core/inspect/toolDoor.js +21 -0
- package/core/inspect/valueHistory.js +35 -0
- package/core/{Ops.js → ops/Ops.js} +44 -14
- package/core/{control.js → ops/control.js} +57 -31
- package/core/ops/holds.js +140 -0
- package/core/{opsAtomic.js → ops/opsAtomic.js} +18 -5
- package/core/{opsCheck.js → ops/opsCheck.js} +11 -10
- package/core/{opsFail.js → ops/opsFail.js} +5 -7
- package/core/{opsGuard.js → ops/opsGuard.js} +3 -3
- package/core/{opsRun.js → ops/opsRun.js} +9 -6
- package/core/{owned.js → ops/owned.js} +33 -19
- package/core/{sharedPoint.js → ops/sharedPoint.js} +13 -16
- package/core/{stackFrames.js → ops/stackFrames.js} +2 -2
- package/core/{stacks.js → ops/stacks.js} +34 -15
- package/core/{wrap.js → ops/wrap.js} +8 -6
- package/core/{SaveStore.js → saves/SaveStore.js} +53 -27
- package/core/{Saves.js → saves/Saves.js} +171 -54
- package/core/saves/saveApply.js +312 -0
- package/core/{saveFiles.js → saves/saveFiles.js} +45 -38
- package/core/{saveVersions.js → saves/saveVersions.js} +24 -23
- package/core/saves/session.js +231 -0
- package/core/saves/stateReplace.js +184 -0
- package/core/{Rays.js → scene/Rays.js} +44 -30
- package/core/{Views.js → scene/Views.js} +16 -8
- package/core/{adaptive.js → scene/adaptive.js} +19 -9
- package/core/{canvasBox.js → scene/canvasBox.js} +4 -3
- package/core/scene/compositeGround.js +72 -0
- package/core/scene/floor.js +17 -0
- 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} +6 -4
- package/core/{gridLoad.js → scene/gridLoad.js} +1 -1
- package/core/scene/ground.contract.js +14 -0
- package/core/scene/ground.js +139 -0
- package/core/{movement.js → scene/movement.js} +3 -3
- package/core/{pictureSlots.js → scene/pictureSlots.js} +2 -2
- package/core/scene/pixel.js +154 -0
- package/core/scene/pixelRatio.js +167 -0
- package/core/{sceneDelta.js → scene/sceneDelta.js} +5 -5
- package/core/{sceneMethods.js → scene/sceneMethods.js} +43 -15
- package/core/scene/stepPoses.js +60 -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} +25 -16
- package/core/{things.js → scene/things.js} +18 -5
- package/core/{threePatches.js → scene/threePatches.js} +1 -1
- package/core/{tier.js → scene/tier.js} +10 -0
- package/core/scene/view.js +161 -0
- package/core/{Batching.js → stream/Batching.js} +85 -28
- package/core/{Stream.js → stream/Stream.js} +80 -38
- package/core/{batchGroups.js → stream/batchGroups.js} +11 -9
- package/core/{chunkStream.js → stream/chunkStream.js} +40 -0
- package/core/{scatter.js → stream/scatter.js} +7 -4
- package/core/{streamSources.js → stream/streamSources.js} +14 -8
- package/core/{Commits.js → threads/Commits.js} +17 -11
- package/core/{Jobs.js → threads/Jobs.js} +25 -13
- package/core/{Threads.js → threads/Threads.js} +21 -18
- 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} +20 -11
- package/core/{dayTime.js → time/dayTime.js} +5 -1
- package/core/{skip.js → time/skip.js} +28 -21
- package/core/{time.js → time/time.js} +32 -20
- package/core/{uiClock.js → time/uiClock.js} +4 -4
- package/docs/AI.md +92 -72
- package/docs/API.md +33 -28
- package/docs/CODEMAP.md +121 -200
- package/docs/COMMANDS.md +77 -70
- package/docs/CONVENTIONS.md +167 -24
- package/docs/MIGRATING-0.8.md +171 -0
- package/docs/MIGRATING-1.0.md +101 -0
- package/docs/THREE.md +140 -38
- 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 +32 -29
- package/docs/api/characters.md +35 -24
- package/docs/api/clock.md +1 -1
- package/docs/api/collider3d.md +9 -0
- package/docs/api/collision.md +12 -9
- package/docs/api/content.md +18 -17
- package/docs/api/dialogue.md +5 -4
- package/docs/api/engine.md +58 -54
- package/docs/api/events.md +17 -6
- package/docs/api/flow.md +1 -1
- package/docs/api/grids.md +1 -1
- package/docs/api/ground.md +6 -7
- package/docs/api/hud.md +2 -2
- package/docs/api/i18n.md +6 -6
- package/docs/api/input.md +9 -8
- package/docs/api/interactions.md +5 -5
- package/docs/api/inventory.md +10 -10
- package/docs/api/jobs.md +5 -5
- package/docs/api/level.md +10 -9
- package/docs/api/lightPool.md +1 -6
- package/docs/api/music.md +3 -3
- package/docs/api/nav.md +14 -12
- package/docs/api/openWorld.md +1 -1
- package/docs/api/particles.md +10 -7
- package/docs/api/photo.md +4 -2
- package/docs/api/pickups.md +3 -3
- package/docs/api/post.md +21 -5
- package/docs/api/quests.md +7 -5
- package/docs/api/rays.md +7 -7
- package/docs/api/rigid.md +29 -19
- package/docs/api/saves.md +13 -11
- package/docs/api/settings.md +9 -8
- package/docs/api/sky.md +8 -7
- package/docs/api/stream.md +8 -9
- package/docs/api/swarm.md +34 -0
- package/docs/api/terrain.md +6 -8
- package/docs/api/terrainDraw.md +2 -2
- package/docs/api/timeline.md +4 -4
- package/docs/api/tools.md +27 -22
- package/docs/api/triggers.md +2 -0
- package/docs/api/vars.md +1 -1
- package/docs/api/vegetation.md +4 -3
- package/docs/api/vegetationDraw.md +2 -2
- package/docs/api/water.md +7 -3
- package/docs/api/weather.md +27 -12
- package/docs/api/weatherDraw.md +4 -4
- package/docs/api/world.md +6 -6
- package/docs/recipes/01-new-game.md +28 -43
- package/docs/recipes/02-npc.md +21 -23
- package/docs/recipes/03-items-pickups.md +37 -53
- package/docs/recipes/04-quests.md +5 -4
- package/docs/recipes/05-props-bake.md +34 -44
- package/docs/recipes/06-clock-events.md +31 -22
- package/docs/recipes/07-flow-scenes-pause.md +30 -32
- package/docs/recipes/08-weather-sky.md +91 -37
- package/docs/recipes/09-materials-lights-models.md +25 -39
- package/docs/recipes/10-blender-level.md +22 -11
- package/docs/recipes/11-vehicles.md +44 -24
- package/docs/recipes/12-navmesh.md +60 -15
- package/docs/recipes/13-animation.md +70 -22
- package/docs/recipes/14-custom-module.md +33 -20
- package/docs/recipes/15-perf.md +51 -28
- package/docs/recipes/16-dev-bridge.md +39 -58
- package/docs/recipes/18-world.md +49 -28
- package/docs/recipes/19-shooting-picking.md +7 -4
- package/docs/recipes/20-content-actions-save.md +55 -40
- package/docs/recipes/21-camera.md +47 -25
- package/docs/recipes/22-shop-gold.md +21 -16
- package/docs/recipes/23-ops.md +28 -24
- package/docs/recipes/26-ui-parts.md +25 -14
- package/docs/recipes/27-net.md +3 -5
- package/docs/recipes/28-terrain.md +119 -23
- package/docs/recipes/29-grid.md +3 -3
- package/docs/recipes/30-templates.md +63 -30
- package/docs/recipes/31-audio.md +7 -7
- package/docs/recipes/32-action-game.md +21 -11
- package/docs/recipes/33-stream-sources.md +6 -3
- package/docs/recipes/34-environment-lighting.md +72 -25
- package/docs/recipes/35-picture-from-reference.md +20 -23
- package/docs/recipes/36-ground-plants.md +106 -0
- package/docs/recipes/40-scene.md +18 -21
- package/docs/recipes/43-shader-patches-surfaces.md +27 -48
- package/docs/recipes/44-water-weather-hooks.md +56 -50
- package/docs/recipes/45-cascaded-shadows.md +41 -20
- package/docs/recipes/46-blender-art-route.md +9 -10
- package/docs/recipes/49-game-module-contract.md +7 -6
- package/docs/recipes/50-own-renderer.md +3 -2
- package/docs/recipes/51-capability-catalog.md +14 -8
- package/docs/recipes/52-around-the-picture.md +56 -100
- package/docs/recipes/53-ground-up-close.md +61 -24
- package/docs/recipes/55-mods-time-wrap.md +17 -20
- package/docs/recipes/56-webgpu-tsl.md +28 -15
- package/docs/recipes/57-control.md +39 -12
- package/docs/recipes/58-input.md +15 -2
- package/docs/recipes/59-depth-post-effects.md +1 -1
- package/docs/recipes/60-judge-the-picture.md +30 -25
- package/docs/recipes/62-picture-code.md +129 -39
- package/docs/recipes/63-third-person-start.md +19 -5
- package/docs/recipes/64-particles.md +54 -5
- package/docs/recipes/65-swarm.md +140 -0
- package/docs/recipes/66-common-tasks.md +313 -0
- package/examples/action/.threedog/content-index.json +1 -1
- package/examples/action/GAMEMAP.md +5 -5
- package/examples/perf-island/.threedog/content-index.json +1 -0
- package/examples/{sheepisland → perf-island}/GAMEMAP.md +15 -14
- 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 +4 -1
- package/examples/rc2d/GAMEMAP.md +4 -3
- package/examples/rc2d/main.js +1 -3
- package/examples/rc2d/rc2d.js +1 -1
- package/examples/styletest/.threedog/content-index.json +1 -1
- package/examples/styletest/GAMEMAP.md +6 -5
- 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 +2 -1
- package/examples/world/.threedog/content-index.json +1 -1
- package/examples/world/GAMEMAP.md +9 -7
- package/examples/world/main.js +3 -3
- package/examples/world/picture/sky.js +1 -1
- package/index.d.ts +16 -12
- package/index.js +53 -32
- package/llms.txt +11 -14
- package/modules/ambience/Ambience.js +16 -11
- package/modules/calendar/Calendar.js +19 -19
- package/modules/calendar/index.js +18 -16
- package/modules/calendar/schedule.js +11 -6
- package/modules/calendar/seasons.js +7 -7
- package/modules/camera/FirstPersonCamera.js +5 -5
- package/modules/camera/FixedCamera.js +43 -30
- package/modules/camera/FollowCamera.js +24 -15
- package/modules/camera/RtsCamera.js +12 -11
- package/modules/camera/common.js +72 -37
- package/modules/camera/contract.js +1 -0
- package/modules/camera/pixelSnap.js +62 -0
- package/modules/characters/Character.js +166 -70
- package/modules/characters/NPC.js +84 -44
- package/modules/characters/assetModel.js +16 -12
- package/modules/characters/astar.js +48 -27
- package/modules/characters/behaviors.js +4 -5
- package/modules/characters/character.contract.js +21 -0
- package/modules/characters/contract.js +17 -3
- package/modules/characters/index.js +240 -226
- package/modules/characters/moveHelpers.js +88 -12
- package/modules/characters/mover.contract.js +14 -0
- package/modules/characters/movers/common.js +22 -18
- package/modules/characters/movers/manual.js +1 -1
- package/modules/characters/movers/rapier.js +18 -10
- package/modules/characters/movers/simple.js +26 -13
- package/modules/characters/movers/support.js +24 -13
- package/modules/characters/npcAvoid.js +19 -16
- package/modules/characters/npcSim.js +88 -32
- package/modules/characters/npcView.js +19 -11
- package/modules/characters/pathAsync.js +81 -29
- package/modules/characters/pathJob.js +38 -21
- package/modules/characters/pathWorker.js +1 -1
- package/modules/characters/player.js +120 -0
- package/modules/characters/playerStrings.js +2 -2
- package/modules/characters/proceduralRig.js +2 -2
- package/modules/characters/seat.js +56 -0
- package/modules/characters/useModel.js +3 -3
- package/modules/characters/vehicle.contract.js +8 -5
- package/modules/characters/walkTo.js +40 -33
- package/modules/collision/Collision.js +69 -45
- package/modules/collision/contract.js +15 -0
- package/modules/collision/grid.js +6 -1
- package/modules/content/explain.js +2 -3
- package/modules/content/fields.js +24 -3
- package/modules/content/ids.js +5 -3
- package/modules/content/index.js +132 -114
- package/modules/content/loader.js +117 -140
- package/modules/content/markers.js +25 -0
- package/modules/content/models.js +54 -17
- package/modules/content/packs.js +5 -4
- package/modules/content/parts.js +2 -2
- package/modules/content/places.js +36 -0
- package/modules/content/props.js +22 -17
- package/modules/content/rules.js +47 -61
- package/modules/content/stages.js +7 -7
- package/modules/content/templates.js +80 -49
- package/modules/content/words.js +47 -0
- package/modules/debug/DebugPanel.js +14 -45
- package/modules/flow/contract.js +2 -1
- package/modules/flow/index.js +30 -16
- package/modules/gameplay/Container.js +17 -13
- package/modules/gameplay/Containers.js +23 -6
- package/modules/gameplay/Dialogue.js +93 -34
- package/modules/gameplay/Interactions.js +93 -51
- package/modules/gameplay/Inventory.js +64 -22
- package/modules/gameplay/Quests.js +146 -30
- package/modules/gameplay/boxOps.js +8 -1
- package/modules/gameplay/dialogueBubbles.js +16 -12
- package/modules/gameplay/inventoryOps.js +11 -8
- package/modules/gameplay/pickups.js +63 -37
- package/modules/gameplay/questLog.js +4 -2
- package/modules/gameplay/questSave.js +9 -4
- package/modules/gameplay/quests.contract.js +1 -1
- package/modules/grid/Grid.js +2 -2
- package/modules/grid/Layer.js +12 -8
- package/modules/grid/index.js +28 -23
- package/modules/grid/ops.js +43 -46
- package/modules/grid/preview.js +7 -7
- package/modules/grid/tiles.js +6 -6
- package/modules/hlod/index.js +42 -57
- package/modules/hud/index.js +22 -14
- package/modules/hud/parts.js +8 -8
- package/modules/level/contract.js +16 -0
- package/modules/level/heightfield.js +29 -31
- package/modules/level/index.js +113 -161
- package/modules/level/load.js +196 -0
- package/modules/level/meshes.js +65 -0
- package/modules/level/nodes.js +40 -23
- package/modules/lights/index.js +33 -183
- package/modules/lights/slots.js +93 -0
- package/modules/lights/sources.js +90 -0
- package/modules/music/Music.js +34 -28
- package/modules/music/rules.js +1 -1
- package/modules/nav/contract.js +16 -0
- package/modules/nav/index.js +180 -49
- package/modules/nav/navPath.js +45 -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 +6 -5
- package/modules/net/sync.js +2 -2
- package/modules/net/transports.js +2 -2
- package/modules/particles/Particles.js +95 -29
- package/modules/particles/effect.js +86 -32
- package/modules/particles/shaders.js +19 -1
- package/modules/photo/Photo.js +23 -23
- package/modules/rigid/RigidBodies.js +255 -89
- package/modules/rigid/Vehicles.js +17 -8
- package/modules/rigid/collider3d.contract.js +26 -0
- package/modules/rigid/ragdoll.js +298 -0
- package/modules/rigid/ragdollBones.js +209 -0
- package/modules/rigid/refresh.js +10 -0
- package/modules/rigid/sync.js +51 -20
- package/modules/settings/Settings.js +177 -61
- package/modules/settings/apply.js +20 -13
- package/modules/settings/sections.js +19 -14
- package/modules/settings/strings.js +2 -2
- 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 +17 -28
- package/modules/sky/tint.js +1 -1
- package/modules/swarm/Swarm.js +356 -0
- package/modules/swarm/draw.js +68 -0
- package/modules/swarm/grid.js +63 -0
- package/modules/terrain/ChunkManager.js +71 -59
- 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 +42 -42
- package/modules/terrain/terrainColorMap.js +6 -3
- package/modules/terrain/terrainDefaults.js +2 -1
- package/modules/terrain/terrainEdit.js +45 -29
- package/modules/terrain/terrainGen.js +19 -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 +83 -43
- package/modules/timeline/Tween.js +25 -19
- package/modules/timeline/shots.js +24 -17
- package/modules/triggers/index.js +95 -28
- package/modules/vegetation/Vegetation.js +34 -26
- package/modules/vegetation/densityMap.js +4 -7
- package/modules/vegetation/draw.js +39 -18
- package/modules/vegetation/groundChunks.js +21 -38
- package/modules/vegetation/index.js +37 -12
- package/modules/vegetation/modelGeometry.js +3 -6
- package/modules/vegetation/nearFade.js +1 -1
- package/modules/water/Water.js +20 -16
- package/modules/water/surface.js +3 -3
- package/modules/weather/Weather.js +52 -40
- package/modules/weather/particles.js +8 -8
- package/modules/weather/weatherDraw.js +28 -23
- package/modules/world/World.js +28 -15
- package/modules/world/explain.js +1 -1
- package/modules/world/index.js +30 -17
- package/modules/world/persist.js +90 -27
- package/modules/world/pos.js +5 -5
- package/modules/world/records.js +37 -11
- package/modules/world/sim.js +78 -27
- package/modules/world/simFar.js +2 -2
- package/modules/world/state.js +43 -11
- package/modules/world/thingSource.js +20 -5
- package/modules/world/views.js +27 -14
- package/package.json +48 -7
- package/presets.js +1 -3
- package/render/PostFX.js +83 -53
- package/render/backend.js +31 -33
- 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/particles.tsl.js +8 -6
- package/render/fx/patchNodes.tsl.js +5 -15
- package/render/fx/postWebGPU.tsl.js +30 -26
- 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 +2 -2
- package/render/lighting.js +5 -3
- package/render/lightmap.js +41 -21
- 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 +62 -15
- package/render/ownFrame.js +4 -4
- package/render/patches.js +15 -15
- package/render/postWebGL.js +15 -12
- package/render/probes.js +41 -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 +59 -13
- package/render/slots.js +7 -7
- package/render/terms.js +22 -24
- package/render/uniformDecl.js +1 -1
- package/types/core.d.ts +336 -202
- package/types/gameplay.d.ts +254 -130
- 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} +8 -16
- 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} +28 -10
- package/types/generated/core/input/inputSeat.d.ts +26 -0
- package/types/generated/core/{Budget.d.ts → inspect/Budget.d.ts} +36 -26
- package/types/generated/core/{DebugOverrides.d.ts → inspect/DebugOverrides.d.ts} +17 -3
- package/types/generated/core/{Ops.d.ts → ops/Ops.d.ts} +6 -4
- package/types/generated/core/{control.d.ts → ops/control.d.ts} +14 -10
- package/types/generated/core/{Saves.d.ts → saves/Saves.d.ts} +62 -18
- package/types/generated/core/{session.d.ts → saves/session.d.ts} +3 -2
- package/types/generated/core/{Rays.d.ts → scene/Rays.d.ts} +8 -27
- package/types/generated/core/{Views.d.ts → scene/Views.d.ts} +2 -2
- package/types/generated/core/{Batching.d.ts → stream/Batching.d.ts} +7 -7
- package/types/generated/core/{Stream.d.ts → stream/Stream.d.ts} +22 -18
- 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/Grid.d.ts +1 -0
- 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 +5 -4
- 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 +7 -5
- package/types/generated/modules/water/Water.d.ts +1 -0
- package/types/generated/modules/weather/Weather.d.ts +14 -16
- package/types/generated/modules/weather/weatherDraw.d.ts +3 -3
- package/types/generated/modules/world/World.d.ts +11 -7
- package/types/generated/render/PostFX.d.ts +21 -23
- 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 +47 -15
- package/types/physics.d.ts +150 -73
- package/types/pixel.d.ts +75 -0
- package/types/tsl.d.ts +37 -4
- package/types/world.d.ts +48 -75
- package/ui/Focus.js +10 -9
- package/ui/Parts.js +13 -5
- package/ui/UI.js +7 -7
- package/ui/defaults.js +3 -2
- package/ui/theme.js +7 -5
- package/core/assetEntry.js +0 -109
- package/core/engineCamera.js +0 -32
- package/core/ground.js +0 -104
- package/core/holds.js +0 -134
- package/core/math.js +0 -48
- package/core/moduleSlots.js +0 -100
- package/core/modules.js +0 -314
- package/core/saveApply.js +0 -210
- package/core/saveValues.js +0 -46
- package/core/session.js +0 -174
- package/core/shadowTypes.js +0 -16
- package/core/util.js +0 -17
- package/core/view.js +0 -43
- 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/examples/sheepisland/.threedog/content-index.json +0 -1
- package/modules/camera/projection.js +0 -21
- /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/{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
- /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
|
@@ -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,17 +23,29 @@ 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
|
+
- What a fight sets up, falling undoes. `respawn` leaves the world as it was, so a closed arena gate, a blocked area, a locked camera or a boss phase is still there when the player returns, and a spawn point can end up inside ground that is no longer walkable. Keep one function that undoes the fight and call it from `player.die`; a win calls it too.
|
|
27
|
+
- A blow that ends a contact ends it for both sides: a stomp, a dash through or a parry needs a short window in which that enemy cannot hurt the player, or its touch damage lands the step after. Each of these gets a scenario that loses as well as one that wins (recipe 16 section 2b).
|
|
28
|
+
- 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`
|
|
29
|
+
with `closable: false` (recipe 26).
|
|
30
|
+
|
|
31
|
+
## 2b. Guns: hitscan shots, spread, recoil
|
|
32
|
+
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.
|
|
33
|
+
- **The ray**: `engine.raycast(origin, direction, { far: range })` gives the nearest level or registered static mesh; `{ targets: 'all' }` adds rigid bodies.
|
|
34
|
+
An enemy that is neither: test its shape along the same ray and keep the nearer hit, so walls stop shots.
|
|
35
|
+
- **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.
|
|
36
|
+
- **Spread**: bend the direction with `engine.random`, so a replay fires the same shots.
|
|
37
|
+
- **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
38
|
|
|
28
39
|
## 3. Mouse attack and pointer lock
|
|
29
40
|
`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
|
-
|
|
41
|
+
`attack: { keys: ['Mouse0'] }` works in both states. The click that takes the lock is swallowed, so it does not swing; `swallowLockClick: false` delivers it.
|
|
42
|
+
`presets.player.aim` turns the player toward where the camera
|
|
32
43
|
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
44
|
`examples/action/picture/`.
|
|
34
45
|
|
|
35
46
|
## 4. Movement: jumps, speed effects, bullet time, platforms, falling
|
|
36
|
-
```js
|
|
37
|
-
createPlayer({ ...presets.player.thirdPerson, maxJumps: 2 });
|
|
47
|
+
```js fragment
|
|
48
|
+
engine.characters.createPlayer({ ...presets.player.thirdPerson, maxJumps: 2 }); // double jump: the same jump key twice
|
|
38
49
|
engine.player.launch(16, { owner: 'pad' }); // a jump pad / spring
|
|
39
50
|
engine.mod('move.speed', { owner: 'haste', id: 'player', mul: 1.2, for: 5 }); // haste for 5 s; no id = every character (mud, wind)
|
|
40
51
|
engine.time.channel('enemies'); // once, before anything uses it: a channel of your own
|
|
@@ -55,7 +66,7 @@ engine.player.mover = 'manual'; /* a cutscene, your own physics */ engine.player
|
|
|
55
66
|
- **Bullet time / time channels**: a character the engine drives moves and animates on `character.channel` (player `'player'`, NPCs `'world'`), so
|
|
56
67
|
`engine.mod('time.enemies', { owner: 'bullet-time', mul: 0.35 })` slows NPCs added with `npcs.add({ channel: 'enemies' })` (far ones too) and
|
|
57
68
|
`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,
|
|
69
|
+
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
70
|
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
71
|
- **Platforms**: `characters.support(object, { id?, safe?, carry?: 'position' | 'position+yaw', inherit? })` returns `{ id, remove() }`. The rider
|
|
61
72
|
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
|
|
@@ -65,15 +76,14 @@ engine.player.mover = 'manual'; /* a cutscene, your own physics */ engine.player
|
|
|
65
76
|
floor mesh, not the whole model: a group with a mast or a railing has its top up there, and the character passes under it to whatever is below (a
|
|
66
77
|
boat at sea leaves it on the sea floor). A character gets on when its feet are at most `stepHeight` below the top, or it falls or is placed onto
|
|
67
78
|
it (`placeAt` over a support stands on it). Moving the parent moves the floor mesh, so move the whole model as you like.
|
|
68
|
-
```js
|
|
79
|
+
```js fragment
|
|
69
80
|
const raft = new THREE.Group(), deck = new THREE.Mesh(new THREE.BoxGeometry(3, 0.2, 2), wood);
|
|
70
81
|
raft.add(deck, mast); engine.scene.add(raft);
|
|
71
82
|
engine.characters.support(deck, { id: 'raft' }); // the deck, not the raft with its mast
|
|
72
83
|
engine.onFixed(dt => { raft.position.x += 1.5 * dt; }); // the player on it is carried
|
|
73
84
|
```
|
|
74
85
|
A ride the player does not steer is `engine.control` instead (recipe 57, Moved by script).
|
|
75
|
-
- **Falling out**: `createPlayer({ ..., fall: { belowY: -20 } })` fires `character:fall { character, safe,
|
|
76
|
-
back on `player.safeGround` (the last spot it stood still on safe, unmoving ground; saved). Take hp in the listener; `preventDefault()` to handle it yourself.
|
|
86
|
+
- **Falling out**: `createPlayer({ ..., fall: { belowY: -20 } })` fires `character:fall { character, safe }` once. Take hp in the listener. The rule `fall` decides what happens, and the engine alone decides nothing: `engine.mod('fall', { owner: 'game', set: 'rescue' })` (or `characters({ fall: 'rescue' })`; `openWorld` and the new-game templates choose it) puts the player back on `player.safeGround`, the last spot it stood still on safe, unmoving ground (saved); `set: false` handles it yourself, a function `(facts, engine) => 'rescue' | false` decides per fall (`facts.kind` is `'character'` or `'body'`), and without `id` it covers everything that falls, rigid bodies below y = -200 too.
|
|
77
87
|
- **Your own controller**: `mover: 'manual'` = you write the position; `move()` then only updates `grounded`, `support` (platforms still carry),
|
|
78
88
|
`safeGround` and the fall check. Switch at any time (`player.mover = 'manual'` / `'simple'`): a cutscene, a grapple, a ladder.
|
|
79
89
|
- **Knockback / dashes**: `player.push(vx, vz, seconds)`. Writing `player.velocity` or `player.vy` is an impulse: the mover keeps integrating from
|
|
@@ -12,8 +12,9 @@ list, the sources of `engine.stream`:
|
|
|
12
12
|
| `engine.stream.camera` (built in: `engine.focus`) | full | no |
|
|
13
13
|
| `engine.stream.source(p, { radius, detail, physics, until })` | `detail: 'full'` (default) or `'simple'` (terrain and hlod proxies only) | `physics` (default true for `'full'`) |
|
|
14
14
|
|
|
15
|
-
```js
|
|
15
|
+
```js fragment
|
|
16
16
|
// teleport: the player moves only after the destination's terrain, collision and nearby models are ready
|
|
17
|
+
// a new game or load during the trip abandons it: it rejects with code stream-removed and the player stays
|
|
17
18
|
await engine.stream.teleport([800, 0, 300]);
|
|
18
19
|
|
|
19
20
|
// the same by hand (for a door animation or a fade while it loads)
|
|
@@ -30,8 +31,10 @@ const vista = engine.stream.source(towerTop, { detail: 'simple', radius: 600 });
|
|
|
30
31
|
```
|
|
31
32
|
- `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
33
|
- `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.
|
|
34
|
+
(collision takes effect on a tick), so do not wait while `engine.haltLoop()` is on without stepping.
|
|
35
|
+
- `ready` means nothing is pending, not that everything built: a stream entry or world model whose build failed is reported and left out, and `teleport` still lands. Need a thing built?
|
|
36
|
+
Check it yourself: `handle.built`, `engine.world.view(id)`. A failed terrain chunk (recipe 28) is different: no ground, never ready, `teleport` ends in `stream-timeout`.
|
|
34
37
|
- 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
38
|
models are rebuilt from them.
|
|
36
39
|
- 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.
|
|
40
|
+
`s.reach(range)`, and register `engine.stream.addReadyCheck(name, s => ...)`. Do not read `engine.focus` or the player position for loading.
|
|
@@ -1,8 +1,55 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Lights, fog, exposure and environment lighting
|
|
2
2
|
|
|
3
|
-
|
|
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.
|
|
4
33
|
|
|
34
|
+
- Signals to read (table in recipe 62): fog in the color of `uSkyHorizon` hides the line where the dome meets the ground; `uWeatherFog` and `uViewDistance` feed your own fog distance.
|
|
35
|
+
- 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.
|
|
36
|
+
- 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.
|
|
37
|
+
- 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`:
|
|
38
|
+
`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);' }] })`.
|
|
39
|
+
- Check the result with `engine.describe('picture').picture.fog`; `threedog shot` says how much of the picture the fog makes up.
|
|
40
|
+
|
|
41
|
+
## Exposure and the tone curve
|
|
5
42
|
```js
|
|
43
|
+
engine.renderer.toneMappingExposure = 1.3;
|
|
44
|
+
engine.onRender(() => { engine.renderer.toneMappingExposure = 1 + 0.5 * (1 - engine.uniforms.uDaylight.value); }); // over the day: your picture/ code
|
|
45
|
+
engine.renderer.toneMapping = THREE.NeutralToneMapping; // the curve; materials recompile on their next draw
|
|
46
|
+
```
|
|
47
|
+
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).
|
|
48
|
+
|
|
49
|
+
## Environment maps
|
|
50
|
+
`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.
|
|
51
|
+
|
|
52
|
+
```js fragment
|
|
6
53
|
const env = engine.sky.environment({ into: engine.scene }); // the sky as a map: follows the time of day; env.texture is the live map
|
|
7
54
|
engine.scene.environmentIntensity = 0.8; // intensity and rotation are three.js
|
|
8
55
|
engine.scene.environmentRotation.y = Math.PI / 2;
|
|
@@ -15,30 +62,26 @@ engine.scene.environment = myPmremTarget.texture;
|
|
|
15
62
|
```
|
|
16
63
|
On `renderer: 'webgpu'` take `PMREMGenerator` from `three/webgpu`. A map you made is yours to dispose.
|
|
17
64
|
|
|
18
|
-
|
|
65
|
+
### The sky as a map: `engine.sky.environment({ into?, interval? })`
|
|
19
66
|
- 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
67
|
- 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
68
|
- 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.
|
|
69
|
+
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
|
|
70
|
+
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
71
|
- 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
72
|
- 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
73
|
|
|
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).
|
|
74
|
+
### What a MeshLambertMaterial does with it (three 0.187)
|
|
75
|
+
The engine's neutral materials are Lambert, so this is what most surfaces do by default.
|
|
76
|
+
- 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
77
|
- 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
|
|
78
|
+
- The first frame with an environment recompiles every Lambert program once; do it at start-up, not mid-game.
|
|
36
79
|
- Toon, Basic and ShaderMaterial surfaces ignore it.
|
|
37
80
|
|
|
38
81
|
## Light probes (baked indirect light)
|
|
39
82
|
An environment map lights everything as seen from one point. Light probes (`engine.bakeProbes`) record how the light changes from place to place (a colored glow beside
|
|
40
83
|
a bright wall, dimmer light under a roof), and every lit pixel takes its own light from the grid, on WebGL and WebGPU, with no shader of your own.
|
|
41
|
-
```js
|
|
84
|
+
```js fragment
|
|
42
85
|
const probes = await engine.bakeProbes({ bounds: { min: [-30, 0, -30], max: [30, 8, 30] }, spacing: 4, include: o => !o.userData.moving });
|
|
43
86
|
const file = JSON.stringify(probes.toJSON()); // ship this (half precision, a few tens of KB)
|
|
44
87
|
const shipped = engine.loadProbes(json); // at start-up, instead of the bake; either renderer reads either renderer's file
|
|
@@ -59,14 +102,18 @@ probes.remove();
|
|
|
59
102
|
|
|
60
103
|
## Lightmaps (baked light on what never moves)
|
|
61
104
|
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
|
-
```js
|
|
105
|
+
```js fragment
|
|
63
106
|
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
|
-
|
|
107
|
+
// npx threedog bake light --page "/?bake=1" --out public/light/level.lightmap --size 1024
|
|
108
|
+
const baking = new URLSearchParams(location.search).has('bake'); // the bake must see the lights the map replaces
|
|
109
|
+
if (!baking) {
|
|
110
|
+
const light = await engine.loadLightmap('light/level.lightmap'); // once the level is built
|
|
111
|
+
hemi.visible = false; // the bake saw it: keep the sun, drop the ambient
|
|
112
|
+
}
|
|
67
113
|
floor.material.lightMapIntensity = 1.2; // plain three.js, yours
|
|
68
114
|
```
|
|
69
|
-
- What is baked: sky and
|
|
115
|
+
- 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.
|
|
116
|
+
- 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
117
|
- 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
118
|
- Files are large: half precision, 8 MB at 1024, 32 MB at 2048, before the server's compression. Start small.
|
|
72
119
|
- 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).
|
|
@@ -76,7 +123,7 @@ floor.material.lightMapIntensity = 1.2; // plain thre
|
|
|
76
123
|
|
|
77
124
|
Bake first when the scene holds still: probes and lightmaps match it and cost nearly nothing. Real-time bounce is for light that changes while the world stands: a sun that moves, a lamp the player carries, a door that lets a room fill. It needs `renderer: 'webgpu'` chosen when the game starts, and three's real WebGPU backend; there is no WebGL version.
|
|
78
125
|
|
|
79
|
-
```js
|
|
126
|
+
```js fragment
|
|
80
127
|
import { voxelGI, temporalAA } from '@threedog/post-effects/tsl';
|
|
81
128
|
engine.post.add(voxelGI({ bounds: new THREE.Box3(min, max), intensity: 1 }));
|
|
82
129
|
engine.post.add(temporalAA()); // clears the dots; it replaces MSAA while it is on
|
|
@@ -87,10 +134,10 @@ engine.post.add(temporalAA()); // clears the dots; it replaces MSAA while it i
|
|
|
87
134
|
- 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
135
|
- 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
136
|
- `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.
|
|
137
|
+
- 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
138
|
- 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
139
|
|
|
93
|
-
What runs where, for the
|
|
140
|
+
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
141
|
|
|
95
142
|
| Case | voxelGI | temporalAA, sunShafts, lightVolumes |
|
|
96
143
|
|---|---|---|
|
|
@@ -103,7 +150,7 @@ What runs where, for the four effects above (`voxelGI`, `temporalAA`, `sunShafts
|
|
|
103
150
|
|
|
104
151
|
Pick by the light. These two are WebGPU only; a WebGL game keeps the depth haze of recipe 59.
|
|
105
152
|
|
|
106
|
-
```js
|
|
153
|
+
```js fragment
|
|
107
154
|
import { sunShafts, lightVolumes } from '@threedog/post-effects/tsl';
|
|
108
155
|
engine.post.add(sunShafts({ light: engine.lights.sun })); // sun through gaps
|
|
109
156
|
engine.post.add(lightVolumes({ bounds: new THREE.Box3(min, max) })); // spot cones, point glows
|
|
@@ -118,6 +165,6 @@ engine.post.add(lightVolumes({ bounds: new THREE.Box3(min, max) })); // spot
|
|
|
118
165
|
`engine.occlusion.enabled = true` skips the engine's big things while something hides them: hlod cells and `engine.batching` groups. Works on both renderers. Ordinary objects are not watched. Turn it on only when heavy things stand behind others (a walled town, a building full of rooms). In a scene of many small things it is a loss: each box costs CPU, more so on WebGPU. Measure with `describe().render.occlusion` (`hidden`, `trianglesSkipped`) and the frame time, on and off.
|
|
119
166
|
|
|
120
167
|
- 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
|
-
-
|
|
168
|
+
- Culling hides things from `engine.camera` alone. Every other camera (a minimap, a mirror, a security view), shadows, `engine.rays`, a `THREE.Raycaster` of your own and `voxelGI`'s volume see them as ever; `visible` and `layers` stay yours.
|
|
169
|
+
- **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
170
|
- 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,23 +67,25 @@ 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 the differences as numbers and one sentence such as "the screenshot is darker and more broken up".
|
|
71
|
+
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
|
-
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,
|
|
77
|
+
Every `threedog shot` prints picture numbers and hints (`--no-picture` skips them). The numbers are mean luminance, contrast (std and p5-p95 range of
|
|
78
|
+
luminance), saturation, clipped-white and near-black shares, the shadow area and how much shadows darken. 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
|
-
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
|
|
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 the game added that changes
|
|
84
81
|
no pixel.
|
|
85
|
-
- **Facts**: measured, maybe wanted, with what sets them
|
|
86
|
-
|
|
87
|
-
|
|
82
|
+
- **Facts**: measured, maybe wanted, with what sets them. Each becomes a contradiction only where DESIGN.md declares the opposite (the `Picture intent:` word in brackets):
|
|
83
|
+
glare, naming each light or glowing material that blows pixels out with its current values and the detail lost under it, and large clipped areas (`no-glare`);
|
|
84
|
+
large near-black areas (`no-pitch-black`); time of day that barely changes the picture or a night not dark from lighting, and whether the brightness at 00:00 is lighting at all
|
|
85
|
+
(renders 12:00 and 00:00 when the game runs calendar + sky or the shot sets `--time`; `dark-nights`); `light:` the share of the lit brightness from the sun / key and from the fill
|
|
86
|
+
(each turned off once) and how much darker shadowed areas are (`strong-light`); the camera standing inside a closed mesh; a black frame, naming the material whose hiding alone
|
|
87
|
+
brings the picture back (newest materials first; a ShaderMaterial is told the usual NaN / Inf causes, and shader programs that failed to compile are listed); fog that is most of
|
|
88
|
+
the color in a large share of the picture, with its near / far and color.
|
|
88
89
|
- **Intent**, only against what the game declared: DESIGN.md's optional `Picture intent:` line (listed words such as `no-glare`, `dark-nights`,
|
|
89
90
|
`strong-light`, `muted`; the template lists them all; the table's free text is not read), or the reference given with `--ref`. A muted,
|
|
90
91
|
low-contrast game is told when its shot measures saturated and contrasty, never the other way round unless it said so. No declaration and
|
|
@@ -100,9 +101,8 @@ right for a given art direction.
|
|
|
100
101
|
`debug.view('lighting')`.
|
|
101
102
|
- **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
103
|
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.
|
|
104
|
+
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
|
|
105
|
+
shadow box is much bigger than the scene ([recipe 45](45-cascaded-shadows.md)).
|
|
106
106
|
- **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
107
|
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
108
|
- **Material response**: do surfaces that should differ (wood, stone, metal, cloth, skin, water) differ in roughness, specular and color, not only hue?
|
|
@@ -133,15 +133,12 @@ Same arguments, same picture, so only the picture differs. A game with many pict
|
|
|
133
133
|
wood / stone / metal surfaces, a lit room (outside and inside) and the UI parts, under named cameras.
|
|
134
134
|
- `threedog shot styletest --view <name> [--time day|dusk|night] [--weather clear|rain|snow]`; the same words work as URL parameters
|
|
135
135
|
(`?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`.
|
|
136
|
+
- 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
|
|
137
|
+
and shadow edges that flicker or crawl), `ui`.
|
|
141
138
|
- The dev panel, in any game: `if (location.search.includes('panel=1')) import('@threedog/tools/panel').then(m => m.openPanel(engine));`
|
|
142
139
|
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
140
|
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.
|
|
144
141
|
It reads the three.js objects and writes them directly: exposure, `scene.fog`, each light, `engine.water` / `terrain` / `vegetation` materials and uniforms
|
|
145
142
|
(when installed), a material picked by name, `engine.uniforms`, post effects, UI colors. "write back" saves the changes to
|
|
146
|
-
`.threedog/tune.json` on the dev server; then `threedog tune write <file>` prints the code change as a diff (one
|
|
143
|
+
`.threedog/tune.json` on the dev server; then `threedog tune write <file>` prints the code change as a diff (one block
|
|
147
144
|
of plain three.js writes) and `--apply` writes it. Review it, then keep the block or move each value where it belongs (`picture/palette.js`, the material's definition).
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# Ground color and plants
|
|
2
|
+
|
|
3
|
+
```js
|
|
4
|
+
import { terrainPreset } from '@threedog/terrain-noise';
|
|
5
|
+
engine.use(terrain({ ...terrainPreset(), colors: { grass: 0x6a8a3a, rock: 0x777066 }, biomeColors: { meadow: ['grass'], cliff: ['rock'] } }));
|
|
6
|
+
engine.terrain.material.flatShading = true; // the ground's picture is a plain three.js material
|
|
7
|
+
engine.terrain.recolor({ colors: { grass: 0xa8a050, rock: 0x777066 } }); // what the workers baked in, changed at run time
|
|
8
|
+
engine.terrain.material = applyEffects(new THREE.MeshToonMaterial({ vertexColors: true }), { patches: engine.terrain.patches }); // your own, effects kept
|
|
9
|
+
engine.vegetation.material = applyEffects(new THREE.MeshToonMaterial({ vertexColors: true }), { patches: engine.vegetation.patches });
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
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
|
|
13
|
+
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`.
|
|
14
|
+
|
|
15
|
+
## Ground color: `terrain({ colors, biomeColors, steep, variation })`
|
|
16
|
+
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.
|
|
17
|
+
`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
|
|
18
|
+
color is neutral gray. The `variation` defaults are shown (plain data, so it travels to the workers; unknown keys throw):
|
|
19
|
+
```js fragment
|
|
20
|
+
terrain({ colors: { ... }, biomeColors: { ... },
|
|
21
|
+
variation: {
|
|
22
|
+
blend: { size: 33, strength: 1 }, // wavelength in m of the two-color noise; strength > 1 = harder contrast, < 1 = flatter
|
|
23
|
+
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)
|
|
24
|
+
patches: { size: 90, strength: 0.15, levels: 0, tint: 0xb59a5a }, // optional (example values): a second, large layer of color blocks
|
|
25
|
+
} })
|
|
26
|
+
```
|
|
27
|
+
`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
|
|
28
|
+
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
|
|
29
|
+
interpolate across a chunk cell (4 m at the default resolution), so blocks smaller than that blur; for crisp blocks use `shading: 'texture'`
|
|
30
|
+
(recipe 53) or a texture (next).
|
|
31
|
+
|
|
32
|
+
### Changing it at run time: `engine.terrain.recolor`
|
|
33
|
+
```js fragment
|
|
34
|
+
engine.terrain.recolor({ colors, biomeColors, steep, variation, shading, normals }); // every chunk is rebuilt; edits stay, collision does not change
|
|
35
|
+
engine.terrain.recolor({ detail: { noise: 'paper', strength: 0.2 } }); // only the material: no chunk is rebuilt
|
|
36
|
+
```
|
|
37
|
+
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.
|
|
38
|
+
`recolor` throws under a picture that replaced `'terrain-draw'`, which draws the ground its own way.
|
|
39
|
+
|
|
40
|
+
### Your own ground material
|
|
41
|
+
`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
|
|
42
|
+
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
|
|
43
|
+
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
|
|
44
|
+
detail layer, hand it `engine.terrain.patches`. `terrain({ material })` adds them for you unless `effects: false`. After a later `recolor({ detail })`
|
|
45
|
+
patch your material again; the engine only rebuilds its own.
|
|
46
|
+
|
|
47
|
+
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
|
|
48
|
+
UVs (steep sides stretch a top-down map), project from the world position in a patch instead (`needs.patches: ['world']` gives `vThreedogWorld`):
|
|
49
|
+
```js fragment
|
|
50
|
+
engine.terrain.material = applyEffects(new THREE.MeshLambertMaterial({ vertexColors: true }), { clouds: false, patches: [{
|
|
51
|
+
name: 'triplanar', needs: { patches: ['world'] }, uniforms: { uTex: { value: groundTexture }, uTexScale: { value: 0.1 } }, // groundTexture: repeat wrapping
|
|
52
|
+
glsl: { fragment: { pars: 'uniform sampler2D uTex; uniform float uTexScale;',
|
|
53
|
+
color_fragment: `vec3 n = abs(normalize(cross(dFdx(vThreedogWorld), dFdy(vThreedogWorld)))); n /= n.x + n.y + n.z;
|
|
54
|
+
diffuseColor.rgb *= texture2D(uTex, vThreedogWorld.zy * uTexScale).rgb * n.x + texture2D(uTex, vThreedogWorld.xz * uTexScale).rgb * n.y
|
|
55
|
+
+ texture2D(uTex, vThreedogWorld.xy * uTexScale).rgb * n.z;` } } }] });
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Detail layer
|
|
59
|
+
The lighter alternative, with no material of your own: `terrain({ detail })`, or `engine.terrain.recolor({ detail })` at run time. It takes
|
|
60
|
+
`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:
|
|
61
|
+
`engine.terrain.uniforms.uDetailStrength.value = 0.2`.
|
|
62
|
+
|
|
63
|
+
## Plants and wind
|
|
64
|
+
`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
|
|
65
|
+
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`.
|
|
66
|
+
```js fragment
|
|
67
|
+
engine.vegetation.define('oak', { model: await engine.assets.model('oak'), wind: 0.02 }); // per species: its own material, wind, fade
|
|
68
|
+
engine.vegetation.define('fern', { geometry, material: new THREE.MeshToonMaterial({ vertexColors: true }), wind: 0.08 });
|
|
69
|
+
engine.vegetation.material = applyEffects(new THREE.MeshToonMaterial({ vertexColors: true }), { patches: engine.vegetation.patches }); // the shared default
|
|
70
|
+
engine.uniforms.uWindAmp.value = 0.5; engine.uniforms.uWindFreq.value = 2; // how hard and how fast: plain signals, live (uWindAmp 0 = plants stand still)
|
|
71
|
+
```
|
|
72
|
+
`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
|
|
73
|
+
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.
|
|
74
|
+
`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
|
|
75
|
+
shadows, season tint and the fade to it unless `effects: false`. Each species' live material is `engine.vegetationDraw.kind(name).material`.
|
|
76
|
+
|
|
77
|
+
The placement, rings and instancing are mechanism and stay (the whole picture is replaceable: recipe 28 section 6). The picture has three entries:
|
|
78
|
+
- **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).
|
|
79
|
+
- **Color**: `engine.vegetation.color(glsl | { glsl, tsl })` puts code in the `color` slot of every species, live.
|
|
80
|
+
- **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.
|
|
81
|
+
|
|
82
|
+
```js
|
|
83
|
+
engine.vegetation.sway({ uniforms: { uSteps: 3 }, // stepped sway: plants snap between 3 poses instead of a smooth sine
|
|
84
|
+
glsl: `void threedogWind(inout vec3 transformed, vec3 ip, vec3 position){
|
|
85
|
+
float s = floor(sin(uTime * uWindFreq + ip.x * 0.3 + ip.z * 0.2) * uSteps) / uSteps;
|
|
86
|
+
transformed.x += s * max(position.y, 0.0) * THREEDOG_WIND_AMP * uWind;
|
|
87
|
+
}` });
|
|
88
|
+
```
|
|
89
|
+
`threedogWind` receives the vertex (`transformed`, object space), `ip` (world position of this plant's origin, so each plant has its own phase) and
|
|
90
|
+
`position`; `uTime`, `uWind` (weather), `uWindFreq` and `THREEDOG_WIND_AMP` (the species' amplitude) are in scope. It applies to every material made by
|
|
91
|
+
`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 }`.
|
|
92
|
+
`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:
|
|
93
|
+
`applyEffects(mat, { wind: { amplitude: 0.03, glsl, uniforms } })`.
|
|
94
|
+
|
|
95
|
+
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
|
|
96
|
+
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.
|
|
97
|
+
|
|
98
|
+
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.
|
|
99
|
+
Grass has no billboard or blade-shape setting: give `vegetation.define` your own `geometry` or `model`.
|
|
100
|
+
|
|
101
|
+
### Near-only plants fade out by distance
|
|
102
|
+
Any `nearOnly` species (grass, flowers, pebbles, twigs, snow tufts, debris ...) is placed per chunk ring
|
|
103
|
+
(`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
|
|
104
|
+
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
|
|
105
|
+
(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
|
|
106
|
+
when `effects: false`. A larger `maxRing`, fog, or a ground color near the species' base color still help for stylized looks with strong silhouettes.
|