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
|
@@ -16,7 +16,7 @@ Rules (correctness, not taste): `import 'threedog/tsl'` comes first in `main.js`
|
|
|
16
16
|
`threedog new-game` and `threedog init` start a game on WebGPU with TSL (`main.js` imports `threedog/tsl` first and calls `createEngine({ renderer: 'webgpu' })`). `--webgl` starts it on GLSL instead. `createEngine` called without `renderer` still builds a WebGL renderer. When the browser has no WebGPU the game keeps running on three's WebGL2 backend, and `engine.describe().renderer` says why. How to decide:
|
|
17
17
|
- WebGPU + TSL (the default for a new game): the picture is built from TSL, you write shaders in JavaScript and compose them as functions, or start from a three.js WebGPU example, and effects that exist only as node materials are open to you.
|
|
18
18
|
- `--webgl` + GLSL: the game already has GLSL (ShaderMaterials, `onBeforeCompile`, a three.js `Pass`), or must run best on modest hardware where plain WebGL draws a frame fastest, or start-up time matters more than the shading style. Recipe 43 is the GLSL route for the same tasks.
|
|
19
|
-
- Check on the hardware you care about: `threedog inspect perf` on both routes, same scene.
|
|
19
|
+
- Check on the hardware you care about: `threedog inspect perf` on both routes, same scene. On an integrated GPU expect WebGPU to take longer per frame than plain WebGL, the WebGL2 backend longer still, and the first WebGPU frame to come later (shader compilation).
|
|
20
20
|
|
|
21
21
|
## Turning it on
|
|
22
22
|
```js
|
|
@@ -50,16 +50,10 @@ engine.add(new THREE.Mesh(new THREE.TorusKnotGeometry(0.6, 0.2, 128, 16), mat));
|
|
|
50
50
|
A node material is lit, shadowed and fogged by three like its plain twin; you replace only the inputs you set (`colorNode`, `positionNode`,
|
|
51
51
|
`normalNode`, `emissiveNode`, `roughnessNode`, `opacityNode` ...).
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
Everything is imported from `three/tsl`; a name you do not find here is almost always there too (`Object.keys(await import('three/tsl'))` lists them, `node_modules/three/src/nodes/` has the source).
|
|
55
|
-
- Values: `float`, `vec2`, `vec3`, `vec4`, `color`, `uniform`, `texture`, `attribute`, `varying`.
|
|
56
|
-
- Where am I: `positionLocal`, `positionWorld`, `positionGeometry`, `normalLocal`, `normalWorld`, `normalView`, `uv`, `screenUV`, `cameraPosition`, `instanceIndex`, `vertexColor`, `time`.
|
|
57
|
-
- Math: `sin`, `cos`, `abs`, `fract`, `floor`, `pow`, `length`, `dot`, `normalize`, `min`, `max`, `clamp`, `mix`, `step`, `smoothstep`, `oneMinus`, `select`; chain the operators as methods (`.add`, `.mul`, `.sub`, `.div`).
|
|
58
|
-
- Noise: `mx_noise_float`, `mx_fractal_noise_float` (MaterialX, also `_vec3`).
|
|
59
|
-
- Your own function and branches: `Fn`, `If`, `Loop`.
|
|
53
|
+
Node names come from `three/tsl` (`Object.keys(await import('three/tsl'))` lists them, `node_modules/three/src/nodes/` has the source). Noise: `mx_noise_float`, `mx_fractal_noise_float` (MaterialX, also `_vec3`), or `noise` / `hash` below.
|
|
60
54
|
|
|
61
55
|
## The engine's values as nodes: `uniforms(engine)`
|
|
62
|
-
`uniforms(engine)` returns `engine.uniforms` as TSL nodes with the same names: `uTime`, `uWind`, `
|
|
56
|
+
`uniforms(engine)` returns `engine.uniforms` as TSL nodes with the same names: `uTime`, `uWind`, `uWeatherCloud`, `uSunDir`, `uSunColor`, `uDaylight`
|
|
63
57
|
(0 at night, 1 at noon), `uTimeOfDay`, `uFoliageTint`, `uGroundTint` ... (the list: `uniforms` in [the engine API](../api/engine.md)). The node reads the
|
|
64
58
|
engine's value each render, so weather, the calendar and the sky move your material with no per-frame code.
|
|
65
59
|
```js
|
|
@@ -84,6 +78,8 @@ in the package's `types/tsl.d.ts`. Call them on nodes, put the result where it b
|
|
|
84
78
|
|---|---|---|
|
|
85
79
|
| `wind(positionGeometry, objectOrigin(), amplitude)` | object-space offset (vec3) | `positionNode = positionLocal.add(...)`: grass, leaves, flags, hanging cloth |
|
|
86
80
|
| `objectOrigin()` | world origin of the object or instance (vec3) | a per-object phase or random seed |
|
|
81
|
+
| `instanceOffset(offset)` | the offset turned and scaled by the drawn instance (vec3) | `wind` on an `InstancedMesh` with rotated instances |
|
|
82
|
+
| `noise(p)`, `hash(p)` | smooth value noise / a random number, 0-1 | your own patterns; the same ones the engine's clouds use |
|
|
87
83
|
| `cloudShadow(positionWorld)` | 0-1 light factor under drifting clouds | multiply into the color or the direct light |
|
|
88
84
|
| `season(color, 0 \| 1)` | the color moved by the calendar's tint (0 foliage, 1 ground) | `colorNode` |
|
|
89
85
|
| `detailNoise(p, kind, octaves)` / `detailBump(...)` | gray noise + height / a bumped normal | breaking up flat color; `normalNode` |
|
|
@@ -204,6 +200,15 @@ emissive lines; a storybook is soft ramp edges (`rampTexture(ramp, soften)`) wit
|
|
|
204
200
|
many stray colors has something running after the `lut`; grain and vignette belong before it there.
|
|
205
201
|
- Put an effect in the stage that matches what it reads. A grade written for finished colors looks wrong before the tone curve, and a glow after it stops glowing.
|
|
206
202
|
|
|
203
|
+
## Dropping a mesh whose material lives on
|
|
204
|
+
A game has nothing to do here. WebGPURenderer keeps a record of every mesh it drew, and neither `scene.remove` nor `geometry.dispose()` frees it while the material stays in use. So every few seconds the engine looks for meshes that have left every Scene and frees theirs, after 4 to 8 seconds out. Adding such a mesh back is fine: its record is rebuilt.
|
|
205
|
+
|
|
206
|
+
Two things stay yours:
|
|
207
|
+
- Call `geometry.dispose()` (or use `engine.remove`) when a mesh is gone for good. Only you know it will not come back. A steady climb of unused geometries warns in dev, with the code `geometry-undisposed`.
|
|
208
|
+
- A pool that sits out for more than a few seconds pays a rebuild on return. Keep such a pool in the scene with `visible = false` and it pays nothing.
|
|
209
|
+
|
|
210
|
+
A record of a mesh in a Scene you no longer draw stays, because a Scene may be drawn again. Send `mesh.dispatchEvent({ type: 'dispose' })` if you throw such a Scene away.
|
|
211
|
+
|
|
207
212
|
## Mistakes, each with the fix
|
|
208
213
|
Each block shows the mistake as a comment and the working line under it.
|
|
209
214
|
```js
|
|
@@ -282,22 +287,19 @@ Many materials, many programs: WebGPURenderer builds one program per distinct se
|
|
|
282
287
|
to every material shares too, a fresh patch object per material builds one program each.
|
|
283
288
|
|
|
284
289
|
## GLSL to TSL
|
|
290
|
+
The language itself is in three's TSL guide. The lines that catch a port:
|
|
291
|
+
|
|
285
292
|
| GLSL | TSL (`three/tsl`) |
|
|
286
293
|
|---|---|
|
|
287
|
-
| `float x = 1.0;` / `vec3(1.0, 0.5, 0.0)` | `float(1)` / `vec3(1, 0.5, 0)`, `color(0xff8000)` for a hex color |
|
|
288
294
|
| `a + b`, `a * b`, `-a`, `1.0 - a` | `a.add(b)`, `a.mul(b)`, `a.negate()`, `a.oneMinus()` |
|
|
289
295
|
| `x += y;` | `x.addAssign(y)` (x made with `.toVar()`) |
|
|
290
|
-
| `mix(a, b, t)`, `smoothstep(e0, e1, x)`, `clamp(x, 0.0, 1.0)` | `mix(a, b, t)`, `smoothstep(e0, e1, x)`, `x.clamp(0, 1)` |
|
|
291
296
|
| `uniform float uAmount;` | `const uAmount = uniform(0.5)`, changed by `uAmount.value = 1` |
|
|
292
297
|
| the engine's `uTime`, `uWind`, `uDaylight` | `uniforms(engine).uTime` ... (the clock every engine effect reads, not three's own `time`) |
|
|
293
298
|
| `varying vec3 vPos;` | built in: `positionWorld`, `normalView`...; your own: `node.toVarying()` |
|
|
294
|
-
| `vec4 c = texture2D(map, vUv);` | `const c = texture(map, uv())` |
|
|
295
299
|
| `gl_FragCoord.xy` | `screenCoordinate.xy` (pixels), `screenUV` (0-1) |
|
|
296
300
|
| `position`, `normal`, `uv` attributes | `positionGeometry`, `normalGeometry`, `const st = uv()` |
|
|
297
301
|
| moving vertices (`transformed`, `gl_Position`) | `material.positionNode` (object space), `vertexNode` (clip space) |
|
|
298
302
|
| `gl_FragColor = ...` | `colorNode` (lit surface color), `emissiveNode`, `outputNode` (final color) |
|
|
299
303
|
| `if (c) {...} else {...}` | `const v = select(c, a, b)`; inside `Fn`, `If` / `Else` blocks |
|
|
300
|
-
| `for (int i = 0; i < 4; i++)` | `Loop` with a count and a callback, inside `Fn` |
|
|
301
|
-
| `float f(vec3 p) {...}` | `const f = Fn(([p]) => ...)` |
|
|
302
304
|
| `discard;` | `Discard` inside `Fn`, or `alphaTest` with `opacityNode` |
|
|
303
305
|
| `#include <threedog_wind>`, `threedogWind(...)` | `import { wind } from 'threedog/tsl'`, `wind(...)` |
|
|
@@ -22,7 +22,7 @@ engine.describe().control; // the same for every held character, by id
|
|
|
22
22
|
|
|
23
23
|
What to remember:
|
|
24
24
|
- **Layers, lowest first**: `base` (the character's own driver: the player's keys, an NPC's behaviour) < `script` (walkTo, quest scripts, AI
|
|
25
|
-
orders; the default) < `cutscene` (timeline) < `net` (another machine drives it). The highest holder is in charge.
|
|
25
|
+
orders; the default) < `cutscene` (timeline) < `physics` (a ragdoll: nothing can steer a limp body) < `net` (another machine drives it). The highest holder is in charge.
|
|
26
26
|
- **A higher holder pauses the lower one, it does not cancel it.** When the cutscene ends, the walk it interrupted goes on; when the walk
|
|
27
27
|
arrives, the keys work again. Nobody has to remember what to restore.
|
|
28
28
|
- **One owner per layer.** Two different owners on the same layer is `[control-conflict]` in development, naming both: end the old one first
|
|
@@ -74,7 +74,7 @@ const ride = engine.control.take(engine.player, { owner: 'boat', layer: 'script'
|
|
|
74
74
|
return false; // placed by hand this step
|
|
75
75
|
} });
|
|
76
76
|
```
|
|
77
|
-
To lock the player's input during a scripted ride, one line: `const lock = engine.input.push('ride');` and `lock.remove()` at the end.
|
|
77
|
+
To lock the player's input during a scripted ride, one line: `const lock = engine.input.push('ride');` and `lock.remove()` at the end.
|
|
78
78
|
Gravity comes back the moment the hold ends, so end a ride where the character can stand: `player.placeAt(pier)` then `ride.remove()`, both in a
|
|
79
79
|
fixed step or an op. The camera and saves follow the position as usual.
|
|
80
80
|
|
|
@@ -98,6 +98,13 @@ function climb(player, top) { // top: { x, y, z }, where it ste
|
|
|
98
98
|
Getting into a vehicle does not change who controls the character: the player's input (`'player-input'`) drives the car while seated. A
|
|
99
99
|
cutscene that takes the player while driving stops the steering; the rider stays on its seat.
|
|
100
100
|
|
|
101
|
+
Holding a car on the grid (a countdown, after the finish) is the same take, plus the brake, since a released pedal only rolls:
|
|
102
|
+
```js
|
|
103
|
+
const hold = engine.control.take(engine.player, { owner: 'race', layer: 'script', step: () => null }); // the keys stop driving
|
|
104
|
+
engine.onFixed(() => { if (hold.active) car.drive(0, 0, 1); }); // throttle, steer, brake
|
|
105
|
+
hold.remove(); // go
|
|
106
|
+
```
|
|
107
|
+
|
|
101
108
|
## Saves
|
|
102
109
|
|
|
103
110
|
Holds are not saved: they are running code (a walk, a cutscene, a quest step), and that code takes control again after a load. A walk is
|
package/docs/recipes/58-input.md
CHANGED
|
@@ -47,8 +47,8 @@ Everything a module declares or binds through `ctx.input` leaves with it (rollba
|
|
|
47
47
|
## 4. What the engine tells you
|
|
48
48
|
- **`input-unbound`** (dev, once per action): a module needs an action nobody bound. The message names the action, its context and the bind line.
|
|
49
49
|
`engine.input.isUnbound('interact')` asks the same thing: true for no key at all, false for any key, an optional action or `[]` (no key on purpose).
|
|
50
|
-
- **`interaction-no-key`** (dev
|
|
51
|
-
`
|
|
50
|
+
- **`interaction-no-key`** (dev warning, once per action): interactions were added to an action with no key. Rule R51 warns in `check`, `describe` calls the thing `no key bound`,
|
|
51
|
+
and `ops` does not offer it, but `interaction.use` still runs when code asks: a click-only or touch-only game is right. `engine.input.bind('interact', [])` says so and ends the warning.
|
|
52
52
|
- **`input-bound-twice`** (dev throws; release: the later wins): two owners bind one action, e.g. the game's `createEngine({ bindings })` and a
|
|
53
53
|
module's `ctx.input.bind` for the same action. Keep one. The same owner binding again only replaces its keys.
|
|
54
54
|
- **`input-action-context`**: two owners declare one action in different contexts. Rename one, or use the same context to share it.
|
|
@@ -4,7 +4,7 @@ Fog you march through, light shafts, haze that thickens with distance, edge or f
|
|
|
4
4
|
and turn it into a distance or a world position. This recipe writes one such effect with both forms, a three.js `Pass` (GLSL) for
|
|
5
5
|
WebGLRenderer and a TSL node for WebGPURenderer, in one effect object. How effects are ordered, switched and tuned is recipe 52's
|
|
6
6
|
[Post effect chain](52-around-the-picture.md#post-effect-chain); the TSL side in general is [recipe 56](56-webgpu-tsl.md#post-effects-as-nodes).
|
|
7
|
-
For plain distance or height fog on materials, `engine.scene.fog` is enough (recipe
|
|
7
|
+
For plain distance or height fog on materials, `engine.scene.fog` is enough (recipe 34).
|
|
8
8
|
|
|
9
9
|
## One effect, both renderers
|
|
10
10
|
`needsDepth: true` gives the WebGL pass the scene depth as `readBuffer.depthTexture`; on WebGPU the same depth is `ctx.scenePass.getTextureNode('depth')`.
|
|
@@ -7,7 +7,7 @@ time of day, so every row says what to look for instead.
|
|
|
7
7
|
|
|
8
8
|
Where the rest lives (one home each, this page only points there):
|
|
9
9
|
- the calls, their parameters and who writes what: [recipe 52](52-around-the-picture.md) (reading the picture, the post chain, the ownership table);
|
|
10
|
-
- the plain three.js way and how the engine yields to it: [THREE.md](../THREE.md)
|
|
10
|
+
- the plain three.js way and how the engine yields to it: [THREE.md](../THREE.md);
|
|
11
11
|
- questions about the whole picture (light roles, readability, consistency) and the numbers each shot prints: [recipe 35](35-picture-from-reference.md) "Picture questions" and "Picture check after every shot";
|
|
12
12
|
- a whole picture: the game's `picture/` code ([recipe 62](62-picture-code.md), materials and lights in [recipe 09](09-materials-lights-models.md)).
|
|
13
13
|
|
|
@@ -16,31 +16,36 @@ Change one knob, take a shot (`threedog shot`, or `threedog snap` on a running p
|
|
|
16
16
|
times and weathers the game really shows (`threedog shot --time`), not only noon. A knob is right when the difference you wanted is visible
|
|
17
17
|
and nothing else got worse; when you cannot say what difference a knob should make, leave it at the style's value.
|
|
18
18
|
|
|
19
|
+
Whether a picture reads as lit is mostly key against fill. The key (the sun or one main light) casts the shadow; the fill is everything else (sky and ground light, the environment). Shadowed
|
|
20
|
+
surfaces see only the fill while lit ones see both, so the balance sets how deep the shadows look: less fill is harder, more fill softer and more readable, and there is no right ratio, only the one the
|
|
21
|
+
game wants. A warm key over a cool fill (or the reverse) separates lit from shaded sides without more contrast. The shot's `light:` fact measures the ratio; judge it on a shot with a known-colored object in
|
|
22
|
+
shadow. `threedog examples pull sun-and-key-light` shows three routes side by side.
|
|
23
|
+
|
|
19
24
|
## The knobs
|
|
20
25
|
|
|
21
|
-
| Knob | What it changes on screen | It is right when |
|
|
22
|
-
|
|
23
|
-
| Sky gradient, horizon | the color from the top of the sky down to where it meets the ground | the horizon band and the fog agree where they meet; the top-to-horizon change matches the hour and mood; no visible seam | `engine.sky.top`, `engine.sky.horizon` ([08 §3](08-weather-sky.md#3-changing-sky-colors-sun-stars)); own shader: share `engine.uniforms.uSkyHorizon` / `uSkyTop` ([08](08-weather-sky.md#sky-color-for-my-shader-horizon-color-zenith-color))
|
|
24
|
-
| Fog near / far | how fast distant things fade | the play space stays clear, the far edge of the world dissolves instead of ending in a line, landmarks you want seen still read |
|
|
25
|
-
| Fog color vs sky | whether the distance melts into the sky or into its own haze | distant hills fade toward the sky behind them; a fog color of its own is a choice you can name (smoke, mist, a dream) | your `picture/` code reads `uSkyHorizon` ([
|
|
26
|
-
| Exposure | overall brightness after lighting | the brightest things you care about keep detail and the darkest still read; a night is dark because the lights are, not because exposure hides it | `engine.renderer.toneMappingExposure
|
|
27
|
-
| Tone mapping curve | how highlights roll off and how saturated bright colors stay | bright colors keep their hue where the style wants color, highlights soften where it wants film; flat-color styles may want almost no curve |
|
|
28
|
-
| Sun direction | where shadows fall and which faces are lit | shapes read from the camera (lit side and shaded side both visible), shadows point somewhere useful, the hour looks like the hour | time of day (`engine.calendar`, [06](06-clock-events.md)); sun path: `engine.sky.orbit.tilt`; the lights do not move on their own: aim yours from `engine.uniforms.uSunDir` ([62](62-picture-code.md)) |
|
|
29
|
-
| Sun color, intensity | the key light: color and strength of lit faces | lit and shaded sides separate; whites under the sun are the white the style wants (warm, neutral, cool) | your `picture/` code writes the light ([62](62-picture-code.md)) |
|
|
30
|
-
| Ambient / hemisphere, environment | the fill: how bright and what color the shaded side is | shadows are as deep as the style wants and still show shape; up-facing and down-facing faces differ; metals have something to reflect | your `picture/` code writes the hemisphere light and `scene.environment` ([34](34-environment-lighting.md), [08 brightness](08-weather-sky.md#3-changing-sky-colors-sun-stars)) |
|
|
31
|
-
| Shadow softness | hard or blurred shadow edges | edges match the light (crisp under a clear sun, soft under cloud or for a gentle style); no stair-steps or speckle | `renderer.shadowMap.type`, `light.shadow.radius` ([
|
|
32
|
-
| Shadow distance, detail | how far shadows reach and how sharp small ones are | the area the player looks at has shadows; small props keep theirs; objects touch the ground (no gap under a foot) | `engine.shadows.box(sun, { extent })`, `engine.shadows.cascades(sun, { count, maxFar })`, `
|
|
33
|
-
| Bloom | light bleeding around bright pixels | the bright things you meant (sun, lamps, magic) glow and nothing else does; the picture does not turn milky | `engine.post.add(bloom())` from `@threedog/post-effects`,
|
|
34
|
-
| Light glow / halo | lamps, windows, signs that read as lit | a glowing object keeps its hue at the center (it is not a white block), has a halo where bloom is on, and lights its surroundings if it should | `engine.uniforms.uNight` ([09 §1b](09-materials-lights-models.md#night-glow-emissive-that-follows-daylight)); many lamps: `lightPool` ([09 §1b](09-materials-lights-models.md#1b-lights-and-stalls)) |
|
|
35
|
-
| Water, sea | color with depth, waves, foam, what it reflects | shallow and deep read differently, the far sea meets the sky without a seam, foam sits where waves break | `engine.water.shader({ depthColor, foam })`, `engine.water.uniforms.uWave` ([44](44-water-weather-hooks.md))
|
|
36
|
-
| Wet ground | streets and stone after rain | wet is darker and glossier together, gloss shows reflections of something bright, puddles have soft edges | no engine picture: read `engine.uniforms.uRain`, then write `material.color`, `material.roughness` ([08 §7](08-weather-sky.md#7-wet-roads-and-puddles-after-rain)) |
|
|
37
|
-
| Color grading | contrast, saturation and warm / cool shift of the whole frame | the frame has the mood you named; skin, foliage and the player's colors still read | `engine.post.add(lut())` from `@threedog/post-effects` ([52 Post chain](52-around-the-picture.md#post-effect-chain)) |
|
|
38
|
-
| Cloud shadow | moving dark patches on the ground | the patches drift slowly enough to read as clouds, are as dark as the sky is cloudy, and do not hide gameplay | `engine.uniforms.uCloudShadow`, `
|
|
39
|
-
| Grain, vignette | film noise; darker frame corners | you notice the mood, not the effect; text and the HUD stay clean | `engine.post.add(grain())`, `engine.post.add(vignette())
|
|
40
|
-
| Ambient occlusion | darker creases and contact corners | objects sit on the ground and corners have weight; no dark halo around thin things | `engine.post.add(ao())` ([52 Post chain](52-around-the-picture.md#post-effect-chain)) |
|
|
41
|
-
| Outline | lines around shapes | lines help read shapes at play distance and match the style's line weight | `engine.post.add(outline())` ([52 Post chain](52-around-the-picture.md#post-effect-chain))
|
|
42
|
-
| Surface shading | how light falls across a surface (smooth, banded, flat) | materials that should differ (wood, stone, metal, cloth) differ in response, not only in color | `applyEffects(mat, { lighting })`, `rampTexture` ([43](43-shader-patches-surfaces.md), [09](09-materials-lights-models.md)) |
|
|
43
|
-
| God rays, volumetric fog | light shafts, fog thick in the air | shafts come from where the light is and fade when it leaves the screen | your own depth effect ([59](59-depth-post-effects.md)) |
|
|
26
|
+
| Knob | What it changes on screen | It is right when | How (details) |
|
|
27
|
+
|---|---|---|---|
|
|
28
|
+
| Sky gradient, horizon | the color from the top of the sky down to where it meets the ground | the horizon band and the fog agree where they meet; the top-to-horizon change matches the hour and mood; no visible seam | `engine.sky.top`, `engine.sky.horizon` ([08 §3](08-weather-sky.md#3-changing-sky-colors-sun-stars)); own shader: share `engine.uniforms.uSkyHorizon` / `uSkyTop` ([08](08-weather-sky.md#sky-color-for-my-shader-horizon-color-zenith-color)); own sky: `engine.sky.replace(mySky)` |
|
|
29
|
+
| Fog near / far | how fast distant things fade | the play space stays clear, the far edge of the world dissolves instead of ending in a line, landmarks you want seen still read | `engine.scene.fog = new THREE.Fog(color, near, far)` ([34 Fog](34-environment-lighting.md#fog-plain-threejs-signals-your-own-math)) |
|
|
30
|
+
| Fog color vs sky | whether the distance melts into the sky or into its own haze | distant hills fade toward the sky behind them; a fog color of its own is a choice you can name (smoke, mist, a dream) | `scene.fog.color`, your `picture/` code reads `uSkyHorizon` ([34 Fog](34-environment-lighting.md#fog-plain-threejs-signals-your-own-math)) |
|
|
31
|
+
| Exposure | overall brightness after lighting | the brightest things you care about keep detail and the darkest still read; a night is dark because the lights are, not because exposure hides it | `engine.renderer.toneMappingExposure` ([34 Exposure](34-environment-lighting.md#exposure-and-the-tone-curve)) |
|
|
32
|
+
| Tone mapping curve | how highlights roll off and how saturated bright colors stay | bright colors keep their hue where the style wants color, highlights soften where it wants film; flat-color styles may want almost no curve | `engine.renderer.toneMapping = THREE.AgXToneMapping` (or ACESFilmic, Neutral, No) ([52 Who writes it](52-around-the-picture.md#who-writes-it-the-ownership-table)) |
|
|
33
|
+
| Sun direction | where shadows fall and which faces are lit | shapes read from the camera (lit side and shaded side both visible), shadows point somewhere useful, the hour looks like the hour | time of day (`engine.calendar`, [06](06-clock-events.md)); sun path: `engine.sky.orbit.tilt`; the lights do not move on their own: aim yours from `engine.uniforms.uSunDir` ([62](62-picture-code.md)) |
|
|
34
|
+
| Sun color, intensity | the key light: color and strength of lit faces | lit and shaded sides separate; whites under the sun are the white the style wants (warm, neutral, cool) | your `picture/` code writes the light ([62](62-picture-code.md)) |
|
|
35
|
+
| Ambient / hemisphere, environment | the fill: how bright and what color the shaded side is | shadows are as deep as the style wants and still show shape; up-facing and down-facing faces differ; metals have something to reflect | your `picture/` code writes the hemisphere light and `scene.environment`, `scene.environmentIntensity` ([34](34-environment-lighting.md), [08 brightness](08-weather-sky.md#3-changing-sky-colors-sun-stars)) |
|
|
36
|
+
| Shadow softness | hard or blurred shadow edges | edges match the light (crisp under a clear sun, soft under cloud or for a gentle style); no stair-steps or speckle | `renderer.shadowMap.type`, `light.shadow.radius` ([45](45-cascaded-shadows.md)) |
|
|
37
|
+
| Shadow distance, detail | how far shadows reach and how sharp small ones are | the area the player looks at has shadows; small props keep theirs; objects touch the ground (no gap under a foot) | `engine.shadows.box(sun, { extent })`, `engine.shadows.cascades(sun, { count, maxFar })`, `light.shadow.bias`, `mapSize` ([45](45-cascaded-shadows.md)) |
|
|
38
|
+
| Bloom | light bleeding around bright pixels | the bright things you meant (sun, lamps, magic) glow and nothing else does; the picture does not turn milky | `engine.post.add(bloom())` from `@threedog/post-effects`, or three's `UnrealBloomPass` through `engine.post.add(pass)` ([52 Post chain](52-around-the-picture.md#post-effect-chain)) |
|
|
39
|
+
| Light glow / halo | lamps, windows, signs that read as lit | a glowing object keeps its hue at the center (it is not a white block), has a halo where bloom is on, and lights its surroundings if it should | `material.emissive`, `engine.uniforms.uNight` ([09 §1b](09-materials-lights-models.md#night-glow-emissive-that-follows-daylight)); many lamps: `lightPool` ([09 §1b](09-materials-lights-models.md#1b-lights-and-stalls)) |
|
|
40
|
+
| Water, sea | color with depth, waves, foam, what it reflects | shallow and deep read differently, the far sea meets the sky without a seam, foam sits where waves break | `engine.water.shader({ depthColor, foam })`, `engine.water.uniforms.uWave` ([44](44-water-weather-hooks.md)); own: three/addons `Water`, a `ShaderMaterial` ([44 own material](44-water-weather-hooks.md#water-your-own-material-reflections-refraction)) |
|
|
41
|
+
| Wet ground | streets and stone after rain | wet is darker and glossier together, gloss shows reflections of something bright, puddles have soft edges | no engine picture: read `engine.uniforms.uRain`, then write `material.color`, `material.roughness` ([08 §7](08-weather-sky.md#7-wet-roads-and-puddles-after-rain)) |
|
|
42
|
+
| Color grading | contrast, saturation and warm / cool shift of the whole frame | the frame has the mood you named; skin, foliage and the player's colors still read | `engine.post.add(lut())` from `@threedog/post-effects`, or `new LUTPass({ lut })` ([52 Post chain](52-around-the-picture.md#post-effect-chain)) |
|
|
43
|
+
| Cloud shadow | moving dark patches on the ground | the patches drift slowly enough to read as clouds, are as dark as the sky is cloudy, and do not hide gameplay | `engine.uniforms.uCloudShadow`, `uCloudShadowScale`, `uCloudShadowSpeed`; clouds in the sky: `uCloudCover`, `uSkyCloudScale`, `uSkyCloudSpeed` on the dome ([08](08-weather-sky.md)); your own: `engine.shaderTerms.cloudShadow(spec)` ([52](52-around-the-picture.md)) |
|
|
44
|
+
| Grain, vignette | film noise; darker frame corners | you notice the mood, not the effect; text and the HUD stay clean | `engine.post.add(grain())`, `engine.post.add(vignette())`; a pixel snippet: `engine.post.add({ name, fuse: { glsl }, slot: 'ldr' })` ([52 Post chain](52-around-the-picture.md#post-effect-chain)) |
|
|
45
|
+
| Ambient occlusion | darker creases and contact corners | objects sit on the ground and corners have weight; no dark halo around thin things | `engine.post.add(ao())` ([52 Post chain](52-around-the-picture.md#post-effect-chain)) |
|
|
46
|
+
| Outline | lines around shapes | lines help read shapes at play distance and match the style's line weight | `engine.post.add(outline())` ([52 Post chain](52-around-the-picture.md#post-effect-chain)), or three/addons `OutlinePass` |
|
|
47
|
+
| Surface shading | how light falls across a surface (smooth, banded, flat) | materials that should differ (wood, stone, metal, cloth) differ in response, not only in color | `new THREE.MeshToonMaterial({ gradientMap })` or any material of yours; `applyEffects(mat, { lighting })`, `rampTexture` ([43](43-shader-patches-surfaces.md), [09](09-materials-lights-models.md)) |
|
|
48
|
+
| God rays, volumetric fog | light shafts, fog thick in the air | shafts come from where the light is and fade when it leaves the screen | your own depth effect ([59](59-depth-post-effects.md)) |
|
|
44
49
|
|
|
45
50
|
## When the picture check names a feature
|
|
46
51
|
The check printed after every shot states a fact and, where the engine has a feature for it, one line of usage. Each is a way out, not a request: a
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# The whole picture in plain three.js: signals in, picture out
|
|
2
2
|
|
|
3
|
-
**In this recipe**: the `picture/` folder (0), setup (1), signals (2), the hook (3), rules for a bigger game (3b), wiring and who wrote a value (3c), the library (3d), shared values (
|
|
4
|
-
picture parts: code from different sources in one game (
|
|
3
|
+
**In this recipe**: the `picture/` folder (0), setup (1), signals (2), the hook (3), rules for a bigger game (3b), wiring and who wrote a value (3c), the library (3d), shared values (3e),
|
|
4
|
+
picture parts: code from different sources in one game (3f), a flat look (4), pixel art (4b), what the engine still does (5), checking (6).
|
|
5
5
|
|
|
6
6
|
Any picture (flat illustration, toon, painterly, realistic) can be written as plain three.js in one folder of the game, the picture code: its own
|
|
7
7
|
lights, materials, fog, sky colors and post passes. The engine hands it signals (time of day, weather) and keeps doing the engineering
|
|
8
8
|
(streaming, shadows, saves, tests); it writes none of the picture's values. Working example: `examples/plain-picture/` (page `/plain-picture.html`,
|
|
9
|
-
a night street in a flat-illustration look; `picture/` is the whole picture
|
|
9
|
+
a night street in a flat-illustration look; `picture/` is the whole picture). Every value has one writer, a line in your code, so
|
|
10
10
|
"why is this wall black" has one place to look.
|
|
11
11
|
|
|
12
12
|
## 0. The `picture/` folder
|
|
@@ -56,18 +56,19 @@ Without `calendar` and `sky()` there is no day and night: `uDaylight` stays 1 an
|
|
|
56
56
|
| `uSunDir` | unit `Vector3` toward the sun | sky |
|
|
57
57
|
| `uSunColor` | `Color` of the sun now, from the keyframes (white with no sky): `sun.color.copy(...)` | sky |
|
|
58
58
|
| `uTimeOfDay` | 0-1 (0 midnight, 0.5 noon) | calendar, else the sky's fixed time |
|
|
59
|
-
| `uRain`, `uSnow`, `
|
|
59
|
+
| `uRain`, `uSnow`, `uWeatherCloud` | 0-1 | weather state |
|
|
60
60
|
| `uWind` | wind multiplier (1 = calm) | weather state |
|
|
61
61
|
| `uWeatherLight`, `uWeatherFog` | multipliers (1 = clear): apply them to your own light and fog distance | weather state |
|
|
62
62
|
| `uViewDistance` | how far the world is meant to be seen, meters (default 600): your fog's far; the stream radius without terrain | `terrain({ viewFog: true })` |
|
|
63
|
-
| `uFoliageTint`, `uGroundTint`, `
|
|
63
|
+
| `uFoliageTint`, `uGroundTint`, `uGroundCover` | season tints, snow cover | sky + calendar |
|
|
64
64
|
| `uSkyTop`, `uSkyHorizon` | the engine dome's colors (its neutral keyframes unless the game sets them) | sky |
|
|
65
65
|
|
|
66
66
|
Read `.value` in JS, or share the object in a shader (`uniforms: { uDaylight: engine.uniforms.uDaylight }`): one object, no copy. The sky
|
|
67
|
-
colors are the engine dome's picture, not physics: a styled game keeps its own palette and mixes them in only if it wants (the
|
|
68
|
-
of the horizon). Gameplay that should change the picture (a cutscene dims the world, a status effect tints it) goes through a signal of your
|
|
67
|
+
colors are the engine dome's picture, not physics: a styled game keeps its own palette and mixes them in only if it wants. Gameplay that should change the picture (a cutscene dims the world, a status effect tints it) goes through a signal of your
|
|
69
68
|
own, read by the picture code, so the picture still has one writer.
|
|
70
69
|
|
|
70
|
+
Written every frame: `uSkyTop` and `uSkyHorizon` take `engine.sky.top` / `engine.sky.horizon`, `uDaylight` and `uTimeOfDay` take a `daylight` / `timeOfDay` measure; a direct write is lost and warns once (`signal-overwritten`). `uSunDir` (the same vector as `engine.sky.sunDir`) and `camera.aspect` stay as written: `engine.autoView.manual('sunDir', false)` gives one back.
|
|
71
|
+
|
|
71
72
|
## 3. The hook: `engine.onRender`, not `onFrame`
|
|
72
73
|
```js
|
|
73
74
|
const sun = new THREE.DirectionalLight(0xffffff, 2), hemi = new THREE.HemisphereLight(); // made once in picture/lights.js
|
|
@@ -82,7 +83,7 @@ engine.onRender(() => {
|
|
|
82
83
|
`onRender` (default `'before'`) runs once per drawn frame after every module updated, so it reads this frame's signals. `onFrame` runs before
|
|
83
84
|
the modules' frame hooks: it would read last frame's values (and noon on the very first frame). Picture code uses `onRender` only.
|
|
84
85
|
|
|
85
|
-
## 3b.
|
|
86
|
+
## 3b. Rules that keep the folder working in a bigger game
|
|
86
87
|
- **One object's state goes through a name `picture/` exports.** Signals are global, but one street lamp shot out or one flickering sign is not. Gameplay calls
|
|
87
88
|
a name of your own and never touches the light or the material:
|
|
88
89
|
```js
|
|
@@ -96,7 +97,6 @@ the modules' frame hooks: it would read last frame's values (and noon on the ver
|
|
|
96
97
|
on WebGPU stops at start and names itself. A `--webgl` game writes GLSL (recipe 43).
|
|
97
98
|
- **The picture reads the quality tier.** The engine cannot hold your code to it, so read `engine.tier` (`'low'` | `'high'`) for what costs: shadow map size,
|
|
98
99
|
real light count, post effects. The generated `lights.js` sizes its shadow map this way.
|
|
99
|
-
- **A large world:** `engine.shadows.cascades(sun, { count: 3 })` on your own light gives sharp near shadows and wide far ones (recipe 45); low tier falls back to one map.
|
|
100
100
|
|
|
101
101
|
## 3c. Wiring `picture/` parts
|
|
102
102
|
- **One `engine.onRender`, in `picture/index.js`.** It calls each part's `update(signals)` and holds no values. A part never adds its own hook: two hooks hide the order.
|
|
@@ -128,8 +128,7 @@ threedog lib list flat # next game: look b
|
|
|
128
128
|
threedog lib pull flat-materials # lands in picture/ (a .glsl lands in picture/shaders/)
|
|
129
129
|
```
|
|
130
130
|
A picture entry is **one plain three.js file that exports a function**, so it has to stand alone. `lib add` refuses a file that imports its siblings
|
|
131
|
-
(`./palette.js`) and names them; the entry would arrive as a half. Take the numbers as parameters instead
|
|
132
|
-
`palette.js`; as an entry it reads like this (a flat material family):
|
|
131
|
+
(`./palette.js`) and names them; the entry would arrive as a half. Take the numbers as parameters instead:
|
|
133
132
|
```js
|
|
134
133
|
/** Flat materials by name: a flat color plus an emissive copy of it that rises at night.
|
|
135
134
|
* @param {object} THREE three.js @param {Record<string, number>} palette name → hex @param {number} nightGlow emissive at full night */
|
|
@@ -142,10 +141,9 @@ export function flatMaterials(THREE, palette, nightGlow = 0.2) {
|
|
|
142
141
|
} };
|
|
143
142
|
}
|
|
144
143
|
```
|
|
145
|
-
A day-and-night light group is the same shape: `dayNightLights(THREE, scene, { day, night })
|
|
146
|
-
hemisphere light, and its `update(signals)` blends them by `uDaylight`. The copy in your game is yours: pull, then adapt it to that game's picture.
|
|
144
|
+
A day-and-night light group is the same shape: `dayNightLights(THREE, scene, { day, night })`. The copy in your game is yours: pull, then adapt it to that game's picture.
|
|
147
145
|
|
|
148
|
-
##
|
|
146
|
+
## 3e. Several parts change one picture value
|
|
149
147
|
A sunset and a cutscene both dim the sun. If each writes the light, the second one's end brings back a value that is already wrong. Make the value a shared point
|
|
150
148
|
(recipe 55): everyone changes it with `engine.mod`, and one place in `picture/` reads the result and writes three.js once.
|
|
151
149
|
```js
|
|
@@ -162,7 +160,7 @@ dusk.remove();
|
|
|
162
160
|
An amount that moves takes one entry and changes it: `const wet = ctx.mod('sun.level', { mul: 1 });` once in the install, then `wet.change(1 - 0.5 * rain)` each frame. Calling `ctx.mod` every frame would pile up entries. In a module use `ctx.mod`, not `engine.mod`: the change then goes with the module.
|
|
163
161
|
`describe().shared` shows who holds it and why it reads what it reads. A value only one part writes needs none of this: write the light.
|
|
164
162
|
|
|
165
|
-
##
|
|
163
|
+
## 3f. Picture parts: three.js code from different sources in one game
|
|
166
164
|
Code you write alone stays the plain functions of section 0, and pays nothing for this section. Use a part when code has to live beside code you did not write: an entry from the library,
|
|
167
165
|
another agent's sky, a rain from an old game. A part is an ordinary module with `type: 'picture'`. There is no new layer and no new way to write a picture: inside it is plain three.js.
|
|
168
166
|
```js
|
|
@@ -190,7 +188,7 @@ export const harborFog = ({ near = 10, far = 200 } = {}) => ({
|
|
|
190
188
|
| Kind | Example | Rule | On a collision |
|
|
191
189
|
|---|---|---|---|
|
|
192
190
|
| Only one can exist | the fog, the tone curve, the main light | take a slot: `provides: ['fog']` | a second claim stops at install (`shared-taken`); `{ replaces: 'fog' }` swaps on purpose |
|
|
193
|
-
| Several parties change it | rain and a cutscene both dim the sun | a shared value: `engine.stacks.define` and `engine.mod` (
|
|
191
|
+
| Several parties change it | rain and a cutscene both dim the sun | a shared value: `engine.stacks.define` and `engine.mod` (3e), one place writes three.js | combined by the formula |
|
|
194
192
|
| Just more things | another lamp, another mesh | add it | none, it only costs budget |
|
|
195
193
|
|
|
196
194
|
**The slot names**, so two sources spell a claim the same way (`PICTURE_SLOTS`, type `PictureSlot`). Slot names are free text, and a near miss of these in a picture module is warned about:
|
|
@@ -219,7 +217,7 @@ not named `'sun'`. Nothing here sees that a warm lamp clashes with a cold sea: t
|
|
|
219
217
|
|
|
220
218
|
## 4. A flat illustration (one way among many)
|
|
221
219
|
Light alone turns a warm wall under a cool night fill into mud. An illustrator keeps each surface its own color and only shifts it:
|
|
222
|
-
- `MeshLambertMaterial({ color: c, emissive: c, emissiveIntensity: 0 })`: raise the emissive copy at night
|
|
220
|
+
- `MeshLambertMaterial({ color: c, emissive: c, emissiveIntensity: 0 })`: raise the emissive copy at night, so faces
|
|
223
221
|
keep their hue; or `MeshBasicMaterial` and pick each face's shade yourself (vertex colors by normal); or `MeshToonMaterial` with a `gradientMap`.
|
|
224
222
|
- A warm `HemisphereLight` at night instead of a blue one; the night reads from the sky, the windows and the lamps, not from tinting walls blue.
|
|
225
223
|
- `NoToneMapping` so the colors come out as written.
|
|
@@ -229,6 +227,40 @@ Light alone turns a warm wall under a cool night fill into mud. An illustrator k
|
|
|
229
227
|
environment map comes out too dark on faces away from the sun: raise the ambient, add an `AmbientLight`, or generate an environment (`engine.sky.environment()`).
|
|
230
228
|
`uWeatherLight` is sized for the sun: multiplying ambient by it as well darkens rain more than the sun alone does, so give ambient a share of it.
|
|
231
229
|
|
|
230
|
+
## 4b. Pixel art: low-resolution rendering with sharp scaling
|
|
231
|
+
Pixel art means drawing fewer pixels and then keeping every edge hard when they are enlarged. It takes two engine options and plain three.js and CSS:
|
|
232
|
+
- **Render fewer pixels.** `pixelRatio` below 1 makes the drawing buffer smaller than the canvas on the page. Pick it from the art resolution you want against the canvas
|
|
233
|
+
size, and call `engine.setPixelRatio(p)` again when the size changes. A value that makes one art pixel a whole number of screen pixels keeps them all the same size.
|
|
234
|
+
- **Turn adaptive resolution off.** `adaptiveResolution: false`: it changes the render scale with frame cost, so the size of a pixel would drift during play.
|
|
235
|
+
`antialias: false` too, since it blends the edges you want hard.
|
|
236
|
+
- **Scale sharply.** The browser smooths an enlarged canvas unless told otherwise: CSS `image-rendering: pixelated` on it.
|
|
237
|
+
- **Leave the menu rows that fight it out.** The settings menu's render scale, anti-aliasing and adaptive rows and its quality presets would change the pixel size. Leave those rows out where the game lists its tabs, `settings({ sections: [{ id: 'graphics', omit: ['pixelRatio', 'antialias', 'adaptive'] }, 'audio', 'controls', 'language', 'saves'] })`: an omitted row stays your value, and no preset or stored value moves it.
|
|
238
|
+
- **Sample sharply.** `engine.assets.texture(name, { pixelated: true })` sets `NearestFilter` for enlarging and `NearestMipmapNearestFilter` for shrinking. On a texture of
|
|
239
|
+
your own, set `magFilter` and `minFilter` to `THREE.NearestFilter`.
|
|
240
|
+
```js
|
|
241
|
+
const canvas = document.querySelector('canvas');
|
|
242
|
+
canvas.style.imageRendering = 'pixelated';
|
|
243
|
+
const engine = createEngine({ canvas, pixelRatio: artHeight / canvas.clientHeight, adaptiveResolution: false, antialias: false });
|
|
244
|
+
```
|
|
245
|
+
Whatever blends neighbouring pixels works against the look, so judge each post effect and any tone curve (section 4) by eye. Text and panels under `engine.uiRoot` are page elements and stay at screen
|
|
246
|
+
resolution. Objects that move by less than an art pixel shimmer; if that shows, round their drawn position to the art grid in `onRender`. `describe().render.scale` reports `upscaled: true` here, which is what you asked for.
|
|
247
|
+
|
|
248
|
+
**A following camera without jitter.** Jitter comes from rounding the camera and the character on their own: each lands on a different pixel from frame to frame. Keep one exact position and round once:
|
|
249
|
+
- Draw the character with `engine.stepBlend` (recipe 06 section 1b), in `onFrame`.
|
|
250
|
+
- Make the camera follow that drawn position. The camera module runs after the `onFrame` list, so it moves after the character in the same frame.
|
|
251
|
+
- Round only the final position relative to the camera, in `onRender`, which runs after the camera has moved. Never round the camera and the character separately.
|
|
252
|
+
```js
|
|
253
|
+
const drawn = new THREE.Object3D(); // the exact drawn position; the sprite is its rounded copy
|
|
254
|
+
engine.cameraRig.follow(drawn);
|
|
255
|
+
engine.onFrame(() => { drawn.position.lerpVectors(body.last, body.now, engine.stepBlend); }); // body: what onFixed moves
|
|
256
|
+
engine.onRender(({ camera }) => { // side view, where screen x and y are world x and y; pixel: the world size of one art pixel
|
|
257
|
+
const snap = (v, c) => c + Math.round((v - c) / pixel) * pixel;
|
|
258
|
+
sprite.position.set(snap(drawn.position.x, camera.position.x), snap(drawn.position.y, camera.position.y), drawn.position.z);
|
|
259
|
+
});
|
|
260
|
+
```
|
|
261
|
+
A dead zone keeps small moves from shifting the camera: have it follow a separate object that the game moves only when the character leaves an area around it.
|
|
262
|
+
For smooth scrolling of the whole picture, render with the camera on a whole pixel, draw slightly larger than the screen, and slide the final image by the leftover fraction. Nothing in this repository shows that step yet: it is untested.
|
|
263
|
+
|
|
232
264
|
## 5. What the engine still does with all of this off
|
|
233
265
|
- `scene.background` starts as a neutral gray: write your own color or sky.
|
|
234
266
|
- `renderer.shadowMap.enabled` is on; nothing casts until your lights do.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Third-person start: walking, camera, save, pause, menu
|
|
2
2
|
|
|
3
|
-
**In this recipe**: 1. About twenty lines · 2. What each line gives · 3. Where it stops · 4. Talk, press E, a quest, a counter · 5. Not worth it for a small game
|
|
3
|
+
**In this recipe**: 1. About twenty lines · 2. What each line gives · 3. Where it stops · 4. Talk, press E, a quest, a counter · 5. Not worth it for a small game · 6. A model made in code, placed in content
|
|
4
4
|
|
|
5
5
|
The shortest working path for a game where a character walks around a place you built yourself. It is the blank template's `main.js` plus a few lines, on any
|
|
6
6
|
ground (`--open-world` adds generated terrain and a sky on top of the same parts). The picture stays plain three.js in `picture/`; nothing here touches it.
|
|
@@ -20,7 +20,7 @@ engine.saves.autosave(0.5);
|
|
|
20
20
|
const picture = createPicture(engine);
|
|
21
21
|
engine.collision.addBlocked((x, z) => Math.abs(x) > 3 || Math.abs(z) > 20); // the walkable shape: here a pier 6 m by 40 m
|
|
22
22
|
engine.characters.createPlayer({ ...presets.player.thirdPerson, spawn: [0, 0, 0] });
|
|
23
|
-
engine.content.load(data
|
|
23
|
+
engine.content.load(data);
|
|
24
24
|
|
|
25
25
|
const game = { score: 0 }; // the game's own state: plain values
|
|
26
26
|
engine.saves.register('game', { version: 1, save: () => ({ ...game }), load: d => { Object.assign(game, d); } });
|
|
@@ -49,7 +49,7 @@ Each part is one line to swap and none of them holds the rest back:
|
|
|
49
49
|
- Pictures past the start screen: `threedog shot --play`.
|
|
50
50
|
|
|
51
51
|
## 4. Talk, press E, a quest, a counter
|
|
52
|
-
Add `THREE, interactions, dialogue, quests` to the import and `interactions({ ...presets.interactions.nearest }), dialogue(), quests()` to `engine.use`; E is already bound in section 1 (any other key works: `interact: ['KeyF']`; with no key at all
|
|
52
|
+
Add `THREE, interactions, dialogue, quests` to the import and `interactions({ ...presets.interactions.nearest }), dialogue(), quests()` to `engine.use`; E is already bound in section 1 (any other key works: `interact: ['KeyF']`; with no key at all dev warns with the line to add). Then, before `engine.start()`:
|
|
53
53
|
```js
|
|
54
54
|
const guide = new THREE.Mesh(new THREE.CapsuleGeometry(0.4, 1, 4, 8), new THREE.MeshStandardMaterial({ color: 0xc89a5a })); // any three.js object
|
|
55
55
|
guide.position.set(0, 0.9, -8); engine.scene.add(guide);
|
|
@@ -65,7 +65,7 @@ engine.quests.define('pier', { title: 'The pier', steps: [
|
|
|
65
65
|
engine.quests.start('pier');
|
|
66
66
|
engine.hud.counter('coins', { label: 'Coins', value: 0 }); // call again with a new value to update it
|
|
67
67
|
```
|
|
68
|
-
Dialogue flags, quest progress and what `once` and `counter` did are saved by the modules: no `register` for them. An interaction's `counter` adds 1 to the HUD counter of that name (`hud.
|
|
68
|
+
Dialogue flags, quest progress and what `once` and `counter` did are saved by the modules: no `register` for them. An interaction's `counter` adds 1 to the HUD counter of that name (`hud.bump`); read the total with `engine.hud.value('coins')`, the one place it lives. A short popup message: `toast(engine, 'Picked up a shell')` (import `toast` from `threedog`; recipe 26 §3).
|
|
69
69
|
|
|
70
70
|
A content prop with `collide` blocks the follow camera with its whole mesh; a hand-written mesh blocks it only after `engine.rays.addStatic(mesh, { occluder: true })` (recipe 21).
|
|
71
71
|
|
|
@@ -75,3 +75,16 @@ Plain three.js and `engine.setGround` are the shorter road for the things below;
|
|
|
75
75
|
- Full terrain: a flat or gently rolling island is `engine.setGround({ height: (x, z) => ... })` plus meshes. `terrain()` is for large streamed worlds.
|
|
76
76
|
- The sky module for a fixed time of day: a background color or a gradient mesh and your own lights. `sky()` is for a day that changes.
|
|
77
77
|
- Rigid vehicles: a mesh that moves by your own rule needs no physics. `rigid()` is for things that must push, roll and collide.
|
|
78
|
+
|
|
79
|
+
## 6. A model made in code, placed in content
|
|
80
|
+
Any game, any genre: the shape is code, where it stands is content. The blank game ships one example, and it is neutral gray on purpose.
|
|
81
|
+
```js
|
|
82
|
+
// assets.js: a generator returns a geometry (drawn gray) or an Object3D; it runs once per name, every placement is a clone
|
|
83
|
+
const marker = () => new THREE.CylinderGeometry(0.2, 0.25, 1.2, 12).translate(0, 0.6, 0);
|
|
84
|
+
export default [{ name: 'starter', models: { marker } }];
|
|
85
|
+
```
|
|
86
|
+
```js
|
|
87
|
+
// content/props.js: placements, each with a stable id (saved with the game)
|
|
88
|
+
export default [{ id: 'marker-1', model: 'marker', x: 0, z: -2 }, { id: 'marker-2', model: 'marker', x: 3, z: -5 }];
|
|
89
|
+
```
|
|
90
|
+
`scene.add` at startup also works, but the model stays out of GAMEMAP and the save. `world.add` at startup makes a second copy after each load unless it has `{ save: false }`, and `npm run check` warns about that. A `.glb` registered under the same name later replaces the generator with no other change (recipe 05). Before building a model or an effect from scratch, `threedog lib list` and `threedog how "<words>"` also search the library.
|
|
@@ -11,7 +11,7 @@ engine.particles.define('smoke', { gravity: 0.4, size: [0.5, 2] });
|
|
|
11
11
|
const chimneySmoke = engine.particles.attach('smoke', chimney, { rate: 8, offset: [0, 2, 0] });
|
|
12
12
|
chimneySmoke.remove();
|
|
13
13
|
```
|
|
14
|
-
One effect is one `THREE.Points`, one draw call. Parameters and their fallbacks
|
|
14
|
+
One effect is one `THREE.Points`, one draw call. Parameters and their fallbacks: `api/particles.md`.
|
|
15
15
|
With no options an effect is a soft gray dot.
|
|
16
16
|
|
|
17
17
|
## Where a value comes from
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# Swarm: shots, crowds, pickups, debris by the thousand
|
|
2
|
+
|
|
3
|
+
```js
|
|
4
|
+
import * as THREE from 'three';
|
|
5
|
+
import { swarm } from 'threedog';
|
|
6
|
+
engine.use(swarm());
|
|
7
|
+
const bullets = engine.swarm({
|
|
8
|
+
name: 'bullets', capacity: 4096,
|
|
9
|
+
geometry: new THREE.SphereGeometry(0.1, 6, 4),
|
|
10
|
+
material: new THREE.MeshBasicMaterial({ color: 0xffffff }),
|
|
11
|
+
fields: ['vx', 'vz', 'life'], // your own number columns, beside x, y, z
|
|
12
|
+
});
|
|
13
|
+
bullets.onStep((d, i, dt) => { // set once; runs every fixed step, for each live object
|
|
14
|
+
d.x[i] += d.vx[i] * dt;
|
|
15
|
+
d.z[i] += d.vz[i] * dt;
|
|
16
|
+
return (d.life[i] -= dt) > 0; // false removes it; anything else keeps it
|
|
17
|
+
});
|
|
18
|
+
engine.onFixed(() => {
|
|
19
|
+
if (engine.input.pressed('fire')) bullets.spawn({ x: 0, y: 1, z: 0, vx: 20, life: 2 });
|
|
20
|
+
});
|
|
21
|
+
```
|
|
22
|
+
One swarm is a set of same-kind objects that the game plays with: they spawn, die, move, collide and get asked about. Their data sits in typed arrays, one
|
|
23
|
+
array per field, and they draw as one plain `THREE.InstancedMesh`: one draw call, nothing allocated per object. The geometry and material are yours and work
|
|
24
|
+
on WebGL and WebGPU alike. There is no framework behind it: a game that does not call `engine.use(swarm())` pays nothing.
|
|
25
|
+
|
|
26
|
+
## Which tool for many things
|
|
27
|
+
| The things | Use | Why |
|
|
28
|
+
|---|---|---|
|
|
29
|
+
| Hit, are hit, get counted, saved or asked about: bullets, enemies in a horde, coins, crops | `engine.swarm` | spawn, die, move and query, on the fixed step |
|
|
30
|
+
| Only seen, short-lived, no rules: dust, sparks, smoke | `engine.particles` (recipe 64) | emitters, fades and sizes over a lifetime |
|
|
31
|
+
| Placed once, do not move: fences, rocks, a crop field's scenery | `engine.batching` or `props` (recipe 05) | no per-frame work at all |
|
|
32
|
+
| Only seen, a very great number, and the game runs on WebGPU: snow, ash, star fields | GPU compute, last section | the CPU never touches them |
|
|
33
|
+
| A few dozen that each need their own logic, animation or a skeleton | one object each (`engine.characters`, plain meshes) | a swarm is same-kind objects, one geometry, no skeleton |
|
|
34
|
+
|
|
35
|
+
The test: if game rules read the thing, it is a swarm; if only eyes do, it is one of the visual tools.
|
|
36
|
+
|
|
37
|
+
## The id rule: handles and rows
|
|
38
|
+
Two numbers, never mixed up.
|
|
39
|
+
|
|
40
|
+
- A **handle** is what `spawn` returns and what `d.id[i]` holds. It names one object for as long as it lives and never names another afterwards. Keep these, in a variable or in a
|
|
41
|
+
field of any swarm: a turret's target, a homing missile's prey. A handle in a save stays good after loading that save.
|
|
42
|
+
- A **row** `i` is where the object sits now: what `onStep` and `near` pass, what `d.x[i]` reads. Removing an object moves the last row into the gap, so a
|
|
43
|
+
row means something only inside one callback or one plain loop. Never store a row.
|
|
44
|
+
|
|
45
|
+
`swarm.row(handle)` turns a handle into today's row, -1 when it is gone. `free` takes a handle; given a row by mistake it throws `[swarm-handle]`.
|
|
46
|
+
```js
|
|
47
|
+
const enemies = engine.swarm({ name: 'enemies', capacity: 2000, fields: ['hp'] });
|
|
48
|
+
let target = enemies.spawn({ x: 5, z: 2, hp: 3 }); // a handle: safe to keep
|
|
49
|
+
engine.onFixed(() => {
|
|
50
|
+
const i = enemies.row(target); // today's row, -1 once it died
|
|
51
|
+
if (i < 0) return;
|
|
52
|
+
enemies.data.hp[i] -= 1;
|
|
53
|
+
if (enemies.data.hp[i] <= 0) enemies.free(target);
|
|
54
|
+
});
|
|
55
|
+
```
|
|
56
|
+
Inside `onStep` and `near` you may `free` and `spawn` freely. A freed object counts as gone at once (`row` and `near` skip it, `count` drops), and rows only move
|
|
57
|
+
when the walk ends, so nothing is skipped or run twice. An object spawned during a walk first moves in the next step. To walk every object outside a callback:
|
|
58
|
+
`for (let i = 0; i < s.count; i++)` reading `s.data`, without removing; collect handles and free them afterwards.
|
|
59
|
+
|
|
60
|
+
## Hits: `near`
|
|
61
|
+
```js
|
|
62
|
+
const shots = engine.swarm({ name: 'shots', capacity: 1024, fields: ['vx', 'vz'] });
|
|
63
|
+
const crowd = engine.swarm({ name: 'crowd', capacity: 8000, cell: 2, fields: ['hp'] });
|
|
64
|
+
shots.onStep((d, i, dt) => {
|
|
65
|
+
d.x[i] += d.vx[i] * dt;
|
|
66
|
+
d.z[i] += d.vz[i] * dt;
|
|
67
|
+
let hit = false;
|
|
68
|
+
crowd.near(d.x[i], d.z[i], 0.6, (c, j) => {
|
|
69
|
+
hit = true;
|
|
70
|
+
if ((c.hp[j] -= 1) <= 0) crowd.free(c.id[j]);
|
|
71
|
+
return false; // false stops the query: this shot is spent
|
|
72
|
+
});
|
|
73
|
+
return !hit;
|
|
74
|
+
});
|
|
75
|
+
```
|
|
76
|
+
`near(x, z, r, cb)` calls `cb(d, i, dist2)` for each live object within `r` meters on the ground plane; height is ignored, so a game that needs it compares `d.y[i]`
|
|
77
|
+
itself. It returns how many it visited, and the order is the same every run. The grid behind it is built on the first query after things moved, once per step
|
|
78
|
+
when you only ask at one point in the step, and not at all if nobody asks. `cell` is about your usual query radius.
|
|
79
|
+
|
|
80
|
+
Inside `onStep`, `near` on the same swarm sees cells from the start of the step, with live positions for the distance. Fine for crowds keeping apart; for exact
|
|
81
|
+
answers query after the step (`engine.onFixed(fn, { phase: 'late' })`). A bullet faster than its radius per step can jump over a target: use a radius of at least
|
|
82
|
+
speed x dt / 2, or check along the path yourself. Rays: `engine.rays` does not hit instances; three's `Raycaster` on `swarm.mesh` gives `instanceId`, which is a row.
|
|
83
|
+
|
|
84
|
+
## The same thing in other games
|
|
85
|
+
Tower defence: enemies walk a path, each tower holds one handle and keeps it until `row` says -1.
|
|
86
|
+
```js
|
|
87
|
+
const creeps = engine.swarm({ name: 'creeps', capacity: 500, fields: ['along', 'hp', 'yaw'] });
|
|
88
|
+
const towers = [{ x: 4, z: 4, target: -1 }];
|
|
89
|
+
engine.onFixed(() => {
|
|
90
|
+
for (const t of towers) {
|
|
91
|
+
if (creeps.row(t.target) >= 0) continue; // still alive: keep shooting it
|
|
92
|
+
t.target = -1;
|
|
93
|
+
creeps.near(t.x, t.z, 8, (d, i) => { t.target = d.id[i]; return false; });
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
```
|
|
97
|
+
Farm game: crops grow slowly, stay where they are, and belong in the save.
|
|
98
|
+
```js
|
|
99
|
+
const crops = engine.swarm({ name: 'crops', capacity: 5000, fields: ['age', 'scale'], save: true, color: true });
|
|
100
|
+
crops.spawn({ x: 2, z: 3, scale: 0.2, color: 0x88cc44 });
|
|
101
|
+
crops.onStep((d, i, dt) => {
|
|
102
|
+
d.age[i] += dt;
|
|
103
|
+
d.scale[i] = Math.min(1, 0.2 + d.age[i] / 300);
|
|
104
|
+
});
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Drawing
|
|
108
|
+
- Matrices are written once per rendered frame, between the last two fixed steps (`engine.stepBlend`), so motion stays smooth at any frame rate. Writing `d.x[i]` from
|
|
109
|
+
`onFixed` is smoothed the same way.
|
|
110
|
+
- Fields named `yaw`, `pitch`, `roll` (radians, three's order `'YXZ'`) and `scale` are drawn when you list them. Without them only the position is written, which is cheapest.
|
|
111
|
+
- `color: true` adds columns `r`, `g`, `b` (linear) and the spawn key `color: 0xff8800`. Your material's colour multiplies it.
|
|
112
|
+
- `swarm.mesh` is plain three.js: set `castShadow`, `layers`, `renderOrder` on it. The instance index is the row, and `mesh.count` follows the live count.
|
|
113
|
+
- Bounds are kept up to date while matrices are written, so culling is right for the whole swarm; it is one object to the camera, so it is drawn whole or not at all.
|
|
114
|
+
- Leave out `geometry` and `material` for a swarm that only holds data, and draw it your own way from `swarm.data`.
|
|
115
|
+
|
|
116
|
+
## Time, saves, limits
|
|
117
|
+
- `onStep`'s function runs on the fixed step with the `dt` of the swarm's time channel, default `'world'`; `{ channel: 'enemies' }` joins bullet time (recipe 55). It does not run while
|
|
118
|
+
frozen, or while that channel stands still. `engine.skip` does not run it either: nothing in a swarm ages during a skip.
|
|
119
|
+
- `{ save: true }` keeps a swarm in saves, handles included. Any swarm without it is emptied by a load or a new game, so last round's bullets do not stay on the field. A saved
|
|
120
|
+
swarm with objects at start returns to them on `engine.session.newGame()`. A saved field added in a later game version starts at its default.
|
|
121
|
+
- Saves write every number of every object: fine for crops, wasteful for 50,000 bullets, which is why it is opt-in.
|
|
122
|
+
- `capacity` is fixed and all memory is taken at once. A full swarm refuses the spawn: `spawn` returns -1, `dropped` counts it, one `[swarm-full]` warning names it, and `free(-1)` is
|
|
123
|
+
harmless. `describe().swarm`, `engine.explain({ swarm: 'name' })` and `engine.counts().swarm` show the numbers. Your own `fields` are `Float64Array`, so a handle kept in one stays exact. `x`, `y`, `z` and `r`, `g`, `b` are `Float32Array`: fine for a position or a colour, not for a handle.
|
|
124
|
+
- `swarm.dispose()` removes the mesh and its GPU buffers; so do `engine.unuse('swarm')` and `engine.dispose()`. Geometry and material stay yours to dispose.
|
|
125
|
+
- A swarm is for one shape. Three enemy kinds are three swarms, or one swarm when they differ only in colour and scale.
|
|
126
|
+
|
|
127
|
+
## Pure picture: GPU compute
|
|
128
|
+
When nothing in the rules reads the things, and the game runs on WebGPU, they need not touch the CPU at all. This is plain three.js with no engine API. It needs a real
|
|
129
|
+
WebGPU device to be worth it: without one, use `engine.particles` or a swarm. Pick it over a swarm when the count is far past what the CPU should write per frame and no game
|
|
130
|
+
code needs an answer back: reading a GPU buffer takes frames, so `near` and hits are out.
|
|
131
|
+
Build it with three's TSL as in three's own compute examples (an `instancedArray` buffer, compute nodes, a `SpriteNodeMaterial` reading the buffer through `positionNode`). What the engine adds is where each call goes:
|
|
132
|
+
```js fragment
|
|
133
|
+
import 'threedog/tsl'; // before createEngine
|
|
134
|
+
const gpu = /** @type {any} */ (engine.renderer); // a WebGPURenderer: the engine's type also covers WebGL
|
|
135
|
+
await gpu.computeAsync(seed); // once, to fill the buffer
|
|
136
|
+
engine.onFrame(d => { dt.value = engine.frozen ? 0 : d; }); // time as a uniform set here, so a freeze stops the snow
|
|
137
|
+
engine.onRender(() => { gpu.compute(fall); }); // the shader here, so it runs once per drawn frame
|
|
138
|
+
snow.frustumCulled = false; // the sprite's own bounds know nothing of the flakes
|
|
139
|
+
```
|
|
140
|
+
A full page: `tests/compute-snow` in the engine repository.
|