threedog 0.2.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +290 -0
- package/README.md +9 -8
- package/core/Animator.js +15 -12
- package/core/Assets.js +83 -16
- package/core/Audio.js +45 -38
- package/core/Baked.js +32 -8
- package/core/Batching.js +102 -15
- package/core/Budget.js +39 -18
- package/core/Clock.js +40 -80
- package/core/DebugOverrides.js +45 -10
- package/core/Describe.js +104 -43
- package/core/Engine.js +190 -57
- package/core/Events.js +4 -1
- package/core/I18n.js +25 -13
- package/core/Input.js +168 -79
- package/core/Inspect.js +2 -2
- package/core/InspectMaterials.js +85 -0
- package/core/InspectPerf.js +61 -0
- package/core/InspectScene.js +13 -2
- package/core/Loading.js +2 -1
- package/core/Ops.js +50 -9
- package/core/Random.js +9 -2
- package/core/Rays.js +5 -5
- package/core/SaveStore.js +41 -9
- package/core/Saves.js +71 -15
- package/core/Stream.js +14 -10
- package/core/Threads.js +26 -7
- package/core/UrlState.js +25 -9
- package/core/Views.js +9 -6
- package/core/actor.js +1 -1
- package/core/adaptive.js +93 -0
- package/core/assetEntry.js +22 -5
- package/core/assetHot.js +176 -0
- package/core/assetLoad.js +38 -11
- package/core/assetManifest.js +48 -9
- package/core/assetReport.js +1 -1
- package/core/audioRules.js +13 -11
- package/core/audioVoice.js +69 -42
- package/core/canvasBox.js +1 -2
- package/core/catalog.js +5 -2
- package/core/cells.js +62 -0
- package/core/checks.js +10 -8
- package/core/chunkStream.js +87 -0
- package/core/control.js +149 -0
- package/core/copies.js +32 -0
- package/core/dayTime.js +12 -6
- package/core/debugView.js +82 -15
- package/core/describeRender.js +43 -17
- package/core/describeText.js +41 -21
- package/core/engineCamera.js +32 -0
- package/core/errorCodes.js +438 -19
- package/core/errorHints.js +37 -141
- package/core/errors.js +31 -8
- package/core/events.generated.js +12 -7
- package/core/gameLights.js +62 -0
- package/core/grayMap.js +20 -0
- package/core/grid.js +128 -0
- package/core/gridLoad.js +20 -0
- package/core/ground.js +6 -4
- package/core/headlessLoad.js +55 -0
- package/core/holds.js +78 -50
- package/core/inputContext.js +11 -7
- package/core/inputDefaults.js +24 -21
- package/core/inputPad.js +1 -1
- package/core/inputPointer.js +1 -1
- package/core/inputTouch.js +2 -2
- package/core/lifecycle.js +48 -12
- package/core/lightWatch.js +6 -4
- package/core/look/coreParts.js +137 -30
- package/core/look/part.js +175 -95
- package/core/look/points.js +255 -0
- package/core/look/report.js +34 -17
- package/core/look/shadowPart.js +63 -0
- package/core/look/state.js +45 -0
- package/core/look/write.js +12 -28
- package/core/loop.js +101 -37
- package/core/math.js +11 -3
- package/core/moduleSlots.js +75 -0
- package/core/moduleTypes.js +73 -0
- package/core/modules.js +145 -27
- package/core/movement.js +2 -2
- package/core/namedModel.js +70 -0
- package/core/opsCheck.js +3 -3
- package/core/opsFail.js +15 -6
- package/core/opsGuard.js +4 -4
- package/core/opsRun.js +4 -3
- package/core/owned.js +168 -0
- package/core/page.js +2 -1
- package/core/params.js +30 -8
- package/core/plugins.js +277 -0
- package/core/saveApply.js +99 -17
- package/core/saveFiles.js +8 -6
- package/core/saveValues.js +46 -0
- package/core/saveVersions.js +20 -3
- package/core/scatter.js +48 -19
- package/core/sceneDelta.js +203 -0
- package/core/sceneMethods.js +35 -30
- package/core/screenToGround.js +1 -1
- package/core/services.js +27 -11
- package/core/session.js +28 -25
- package/core/shaderCost.js +78 -0
- package/core/shadowTypes.js +2 -1
- package/core/sharedPoint.js +317 -0
- package/core/skip.js +36 -28
- package/core/stackFrames.js +34 -0
- package/core/stacks.js +166 -0
- package/core/startup.js +153 -11
- package/core/streamSources.js +0 -11
- package/core/styleParts.js +65 -47
- package/core/targeting.js +1 -1
- package/core/textureBytes.js +20 -0
- package/core/thingExplain.js +2 -2
- package/core/thingOps.js +29 -6
- package/core/things.js +21 -11
- package/core/threadPure.js +7 -3
- package/core/threePatches.js +47 -0
- package/core/tier.js +21 -10
- package/core/time.js +236 -0
- package/core/uiClock.js +25 -0
- package/core/util.js +7 -1
- package/core/validate.js +65 -86
- package/core/wrap.js +106 -0
- package/docs/AI.md +89 -97
- package/docs/API.md +32 -28
- package/docs/CODEMAP.md +224 -149
- package/docs/COMMANDS.md +57 -34
- package/docs/CONVENTIONS.md +92 -30
- package/docs/MIGRATING-0.3.md +248 -0
- package/docs/MIGRATING-0.4.md +228 -0
- package/docs/MIGRATING-0.5.md +68 -0
- package/docs/PERF.md +35 -7
- package/docs/THREE.md +79 -27
- package/docs/api/ambience.md +0 -1
- package/docs/api/assets.md +12 -9
- package/docs/api/audio.md +10 -14
- package/docs/api/calendar.md +41 -0
- package/docs/api/cameraRig.md +16 -5
- package/docs/api/characters.md +41 -25
- package/docs/api/clock.md +6 -5
- package/docs/api/collision.md +9 -6
- package/docs/api/content.md +6 -4
- package/docs/api/dialogue.md +9 -9
- package/docs/api/engine.md +65 -62
- package/docs/api/events.md +19 -14
- package/docs/api/grids.md +3 -3
- package/docs/api/ground.md +1 -1
- package/docs/api/hud.md +2 -2
- package/docs/api/i18n.md +1 -1
- package/docs/api/input.md +11 -6
- package/docs/api/interactions.md +7 -5
- package/docs/api/inventory.md +17 -16
- package/docs/api/level.md +0 -1
- package/docs/api/lightPool.md +3 -1
- package/docs/api/music.md +1 -1
- package/docs/api/nav.md +3 -0
- package/docs/api/openWorld.md +2 -1
- package/docs/api/particles.md +2 -2
- package/docs/api/photo.md +0 -2
- package/docs/api/pickups.md +15 -0
- package/docs/api/post.md +5 -4
- package/docs/api/quests.md +2 -3
- package/docs/api/rigid.md +16 -14
- package/docs/api/saves.md +6 -4
- package/docs/api/settings.md +2 -3
- package/docs/api/sky.md +11 -44
- package/docs/api/stream.md +1 -1
- package/docs/api/style.md +31 -29
- package/docs/api/terrain.md +9 -6
- package/docs/api/terrainLook.md +10 -0
- package/docs/api/timeline.md +3 -4
- package/docs/api/tools.md +30 -13
- package/docs/api/triggers.md +5 -10
- package/docs/api/vegetation.md +12 -8
- package/docs/api/vegetationLook.md +10 -0
- package/docs/api/water.md +4 -20
- package/docs/api/weather.md +5 -15
- package/docs/api/weatherLook.md +10 -0
- package/docs/api/world.md +2 -1
- package/docs/recipes/01-new-game.md +71 -59
- package/docs/recipes/02-npc.md +46 -29
- package/docs/recipes/03-items-pickups.md +38 -24
- package/docs/recipes/04-quests.md +34 -27
- package/docs/recipes/05-props-bake.md +154 -18
- package/docs/recipes/06-clock-events.md +100 -52
- package/docs/recipes/07-flow-scenes-pause.md +41 -10
- package/docs/recipes/08-weather-sky.md +146 -37
- package/docs/recipes/09-style.md +218 -0
- package/docs/recipes/10-blender-level.md +14 -2
- package/docs/recipes/11-vehicles.md +64 -7
- package/docs/recipes/13-animation.md +34 -10
- package/docs/recipes/14-custom-module.md +65 -34
- package/docs/recipes/15-perf.md +35 -6
- package/docs/recipes/16-dev-bridge.md +65 -41
- package/docs/recipes/18-world.md +21 -8
- package/docs/recipes/19-shooting-picking.md +12 -11
- package/docs/recipes/20-content-actions-save.md +63 -25
- package/docs/recipes/21-camera.md +49 -16
- package/docs/recipes/22-shop-gold.md +18 -18
- package/docs/recipes/23-ops.md +17 -11
- package/docs/recipes/26-ui-parts.md +61 -12
- package/docs/recipes/27-net.md +12 -6
- package/docs/recipes/28-terrain.md +35 -2
- package/docs/recipes/29-grid.md +71 -33
- package/docs/recipes/30-templates.md +64 -12
- package/docs/recipes/31-audio.md +20 -12
- package/docs/recipes/32-action-game.md +35 -2
- package/docs/recipes/34-environment-lighting.md +27 -4
- package/docs/recipes/35-style-from-reference.md +115 -51
- package/docs/recipes/36-sky-ground-plant-looks.md +37 -35
- package/docs/recipes/37-terrain-look-hooks.md +37 -15
- package/docs/recipes/38-environment-look-hooks.md +64 -48
- package/docs/recipes/40-scene.md +16 -13
- package/docs/recipes/41-thing-registry.md +11 -7
- package/docs/recipes/42-terrain-shape.md +3 -3
- package/docs/recipes/43-shader-patches-surface-looks.md +171 -74
- package/docs/recipes/44-water-weather-look-hooks.md +30 -21
- package/docs/recipes/45-cascaded-shadows.md +17 -8
- package/docs/recipes/46-blender-art-route.md +4 -4
- package/docs/recipes/47-island-snow-backdrop.md +11 -10
- package/docs/recipes/48-make-material.md +11 -6
- package/docs/recipes/49-game-module-contract.md +46 -33
- package/docs/recipes/50-own-renderer.md +2 -2
- package/docs/recipes/51-capability-catalog.md +4 -4
- package/docs/recipes/52-look.md +228 -54
- package/docs/recipes/53-ground-up-close.md +58 -0
- package/docs/recipes/54-three-idioms.md +88 -0
- package/docs/recipes/55-mods-time-wrap.md +112 -0
- package/docs/recipes/56-webgpu-tsl.md +260 -0
- package/docs/recipes/57-control.md +65 -0
- package/docs/recipes/58-input.md +57 -0
- package/docs/recipes/59-depth-post-effects.md +83 -0
- package/docs/recipes/60-judge-the-picture.md +55 -0
- package/examples/action/.threedog/content-index.json +1 -0
- package/examples/action/GAMEMAP.md +17 -13
- package/examples/action/assets.js +8 -0
- package/examples/action/content/actions.js +1 -1
- package/examples/action/content/audio.js +5 -5
- package/examples/action/look.js +1 -1
- package/examples/action/main.js +10 -13
- package/examples/action/models.js +24 -23
- package/examples/pullable.json +111 -0
- package/examples/rc2d/.threedog/content-index.json +1 -0
- package/examples/rc2d/GAMEMAP.md +83 -0
- package/examples/rc2d/README.md +52 -0
- package/examples/rc2d/main.js +63 -0
- package/examples/rc2d/rc2d.js +197 -0
- package/examples/rc2d/shaders.js +144 -0
- package/examples/sheepisland/.threedog/content-index.json +1 -0
- package/examples/sheepisland/GAMEMAP.md +13 -11
- package/examples/sheepisland/assets.js +5 -0
- package/examples/sheepisland/main.js +17 -12
- package/examples/sheepisland/style/index.js +6 -6
- package/examples/styletest/.threedog/content-index.json +1 -0
- package/examples/styletest/GAMEMAP.md +15 -16
- package/examples/styletest/assets.js +6 -0
- package/examples/styletest/content/npcs.js +1 -1
- package/examples/styletest/content/templates.js +1 -1
- package/examples/styletest/content/vegetation.js +1 -1
- package/examples/styletest/look.js +1 -1
- package/examples/styletest/main.js +18 -17
- package/examples/styletest/models.js +1 -1
- package/examples/styletest/params.js +3 -3
- package/examples/techniques/contact-shadows/README.md +92 -0
- package/examples/techniques/contact-shadows/contactShadows.js +51 -0
- package/examples/techniques/contact-shadows/main.js +53 -0
- package/examples/techniques/day-night-grade/README.md +86 -0
- package/examples/techniques/day-night-grade/dayNightGrade.js +76 -0
- package/examples/techniques/day-night-grade/main.js +51 -0
- package/examples/techniques/interior-light/README.md +103 -0
- package/examples/techniques/interior-light/interiorLight.js +45 -0
- package/examples/techniques/interior-light/main.js +124 -0
- package/examples/techniques/modular-building/README.md +125 -0
- package/examples/techniques/modular-building/kit.js +426 -0
- package/examples/techniques/modular-building/main.js +47 -0
- package/examples/techniques/night-lights/README.md +94 -0
- package/examples/techniques/night-lights/main.js +70 -0
- package/examples/techniques/night-lights/nightLights.js +91 -0
- package/examples/techniques/outlines-and-rim/README.md +59 -0
- package/examples/techniques/outlines-and-rim/main.js +84 -0
- package/examples/techniques/outlines-and-rim/outlines.js +64 -0
- package/examples/techniques/procedural-animation/README.md +77 -0
- package/examples/techniques/procedural-animation/creature.js +44 -0
- package/examples/techniques/procedural-animation/main.js +45 -0
- package/examples/techniques/procedural-animation/proceduralAnim.js +118 -0
- package/examples/techniques/procedural-surface/README.md +67 -0
- package/examples/techniques/procedural-surface/main.js +103 -0
- package/examples/techniques/procedural-surface/surface.js +120 -0
- package/examples/techniques/stylized-shading/README.md +75 -0
- package/examples/techniques/stylized-shading/main.js +93 -0
- package/examples/techniques/stylized-shading/shading.js +131 -0
- package/examples/techniques/sun-and-key-light/README.md +135 -0
- package/examples/techniques/sun-and-key-light/keyLight.js +53 -0
- package/examples/techniques/sun-and-key-light/main.js +95 -0
- package/examples/techniques/wet-road/README.md +99 -0
- package/examples/techniques/wet-road/main.js +68 -0
- package/examples/techniques/wet-road/wetRoad.js +209 -0
- package/examples/webgpu-tsl/.threedog/content-index.json +1 -0
- package/examples/webgpu-tsl/GAMEMAP.md +84 -0
- package/examples/webgpu-tsl/README.md +42 -0
- package/examples/webgpu-tsl/main.js +21 -0
- package/examples/webgpu-tsl/tslScene.js +75 -0
- package/examples/world/.threedog/content-index.json +1 -0
- package/examples/world/GAMEMAP.md +22 -15
- package/examples/world/art/humanoid.js +42 -0
- package/examples/world/art/index.js +11 -0
- package/examples/world/art/models.js +58 -0
- package/examples/world/art/shapes.js +9 -0
- package/examples/world/assets.js +6 -0
- package/examples/world/content/audio.js +5 -5
- package/examples/world/content/npcs.js +2 -2
- package/examples/world/content/props.js +1 -1
- package/examples/world/content/rules.js +1 -1
- package/examples/world/content/templates.js +1 -1
- package/examples/world/content/vegetation.js +1 -1
- package/examples/world/main.js +17 -13
- package/examples/world/style/index.js +61 -0
- package/examples/world/style/plugins/10-bloom.js +5 -0
- package/index.d.ts +50 -45
- package/index.js +27 -22
- package/llms.txt +20 -12
- package/modules/ambience/Ambience.js +34 -23
- package/modules/calendar/Calendar.js +163 -0
- package/modules/calendar/contract.js +21 -0
- package/modules/calendar/index.js +81 -0
- package/modules/{sky → calendar}/schedule.js +17 -16
- package/modules/calendar/seasons.js +55 -0
- package/modules/camera/FirstPersonCamera.js +6 -15
- package/modules/camera/FixedCamera.js +33 -15
- package/modules/camera/FollowCamera.js +90 -16
- package/modules/camera/RtsCamera.js +18 -17
- package/modules/camera/common.js +70 -19
- package/modules/camera/contract.js +17 -0
- package/modules/camera/projection.js +11 -24
- package/modules/characters/Character.js +196 -59
- package/modules/characters/NPC.js +87 -36
- package/modules/characters/assetModel.js +27 -8
- package/modules/characters/behaviors.js +2 -1
- package/modules/characters/contract.js +13 -0
- package/modules/characters/footsteps.js +1 -1
- package/modules/characters/index.js +87 -49
- package/modules/characters/moveHelpers.js +4 -5
- package/modules/characters/movers/common.js +97 -19
- package/modules/characters/movers/manual.js +20 -0
- package/modules/characters/movers/rapier.js +19 -16
- package/modules/characters/movers/simple.js +14 -11
- package/modules/characters/movers/support.js +172 -0
- package/modules/characters/npcAvoid.js +47 -42
- package/modules/characters/npcSim.js +12 -8
- package/modules/characters/npcView.js +44 -16
- package/modules/characters/pathAsync.js +7 -3
- package/modules/characters/playerStrings.js +4 -3
- package/modules/characters/proceduralRig.js +46 -10
- package/modules/characters/useModel.js +1 -1
- package/modules/characters/vehicle.contract.js +21 -0
- package/modules/characters/walkTo.js +21 -7
- package/modules/collision/Collision.js +65 -25
- package/modules/collision/grid.js +8 -6
- package/modules/content/explain.js +2 -2
- package/modules/content/fields.js +102 -0
- package/modules/content/ids.js +8 -6
- package/modules/content/index.js +97 -28
- package/modules/content/loader.js +45 -33
- package/modules/content/models.js +11 -40
- package/modules/content/packs.js +6 -5
- package/modules/content/parts.js +41 -0
- package/modules/content/props.js +16 -9
- package/modules/content/rules.js +58 -0
- package/modules/content/stages.js +80 -0
- package/modules/content/templates.js +121 -30
- package/modules/debug/DebugPanel.js +24 -17
- package/modules/flow/contract.js +16 -0
- package/modules/flow/index.js +21 -15
- package/modules/gameplay/Container.js +41 -32
- package/modules/gameplay/Containers.js +30 -15
- package/modules/gameplay/Dialogue.js +113 -55
- package/modules/gameplay/Interactions.js +193 -67
- package/modules/gameplay/Inventory.js +69 -73
- package/modules/gameplay/Quests.js +75 -39
- package/modules/gameplay/boxOps.js +3 -3
- package/modules/gameplay/dialogue.contract.js +21 -0
- package/modules/gameplay/dialogueBox.js +4 -2
- package/modules/gameplay/dialogueBubbles.js +116 -0
- package/modules/gameplay/interactionPrompt.js +4 -1
- package/modules/gameplay/interactions.contract.js +16 -0
- package/modules/gameplay/inventory.contract.js +23 -0
- package/modules/gameplay/inventoryOps.js +18 -16
- package/modules/gameplay/pickups.js +268 -85
- package/modules/gameplay/questLog.js +4 -4
- package/modules/gameplay/quests.contract.js +17 -0
- package/modules/grid/Grid.js +92 -50
- package/modules/grid/Layer.js +14 -13
- package/modules/grid/index.js +60 -36
- package/modules/grid/ops.js +20 -18
- package/modules/grid/preview.js +15 -16
- package/modules/grid/strings.js +12 -0
- package/modules/grid/tiles.js +6 -5
- package/modules/hlod/index.js +51 -19
- package/modules/hud/index.js +35 -20
- package/modules/hud/parts.js +20 -7
- package/modules/level/heightfield.js +3 -1
- package/modules/level/index.js +45 -20
- package/modules/level/nodes.js +4 -3
- package/modules/lights/index.js +42 -18
- package/modules/music/Music.js +38 -21
- package/modules/music/rules.js +1 -1
- package/modules/nav/index.js +48 -42
- package/modules/net/Client.js +13 -6
- package/modules/net/Host.js +19 -5
- package/modules/net/Net.js +2 -1
- package/modules/net/index.js +13 -8
- package/modules/net/sync.js +9 -8
- package/modules/net/transports.js +77 -27
- package/modules/particles/Particles.js +23 -14
- package/modules/particles/contract.js +17 -0
- package/modules/particles/effect.js +39 -11
- package/modules/photo/Photo.js +53 -36
- package/modules/rigid/RigidBodies.js +194 -32
- package/modules/rigid/Vehicles.js +18 -15
- package/modules/rigid/sync.js +62 -17
- package/modules/settings/Settings.js +57 -52
- package/modules/settings/apply.js +38 -3
- package/modules/settings/sections.js +5 -3
- package/modules/settings/strings.js +3 -2
- package/modules/settings/view.js +5 -3
- package/modules/sky/Sky.js +88 -176
- package/modules/sky/cascades.js +86 -25
- package/modules/sky/cascades.tsl.js +82 -0
- package/modules/sky/clouds.js +34 -19
- package/modules/sky/domeLayers.js +30 -15
- package/modules/sky/environment.js +83 -13
- package/modules/sky/fog.js +140 -95
- package/modules/sky/frame.js +112 -44
- package/modules/sky/look.js +22 -19
- package/modules/sky/lookFog.js +48 -52
- package/modules/sky/lookShadow.js +53 -41
- package/modules/sky/lookSky.js +82 -21
- package/modules/sky/season.js +21 -0
- package/modules/sky/shader.js +41 -19
- package/modules/sky/shadow.js +44 -20
- package/modules/sky/skyModule.js +45 -33
- package/modules/sky/tint.js +61 -0
- package/modules/terrain/ChunkManager.js +175 -108
- package/modules/terrain/chunkJob.js +1 -1
- package/modules/terrain/chunkQueries.js +6 -4
- package/modules/terrain/index.js +105 -50
- package/modules/terrain/look.js +83 -0
- package/modules/terrain/lookGround.js +21 -16
- package/modules/terrain/terrainDefaults.js +1 -1
- package/modules/terrain/terrainEdit.js +18 -20
- package/modules/terrain/terrainGen.js +5 -3
- package/modules/terrain/terrainIsland.js +5 -4
- package/modules/terrain/terrainShape.js +12 -12
- package/modules/terrain/terrainShapeMain.js +8 -7
- package/modules/terrain/terrainTexture.js +21 -19
- package/modules/timeline/Timeline.js +95 -43
- package/modules/timeline/Tween.js +18 -10
- package/modules/timeline/letterbox.js +2 -2
- package/modules/timeline/shots.js +5 -1
- package/modules/triggers/index.js +107 -76
- package/modules/vegetation/Vegetation.js +190 -102
- package/modules/vegetation/densityMap.js +62 -0
- package/modules/vegetation/groundChunks.js +52 -58
- package/modules/vegetation/index.js +31 -10
- package/modules/vegetation/look.js +119 -0
- package/modules/vegetation/lookWind.js +71 -10
- package/modules/vegetation/modelGeometry.js +3 -2
- package/modules/vegetation/nearFade.js +45 -0
- package/modules/water/Water.js +65 -27
- package/modules/water/look.js +29 -18
- package/modules/water/surface.js +64 -25
- package/modules/water/surfaceDefaults.js +3 -0
- package/modules/weather/Weather.js +62 -104
- package/modules/weather/look.js +1 -2
- package/modules/weather/particles.js +24 -9
- package/modules/weather/strings.js +2 -2
- package/modules/weather/weatherLook.js +135 -0
- package/modules/world/World.js +24 -7
- package/modules/world/explain.js +1 -1
- package/modules/world/index.js +18 -4
- package/modules/world/persist.js +62 -2
- package/modules/world/pos.js +3 -2
- package/modules/world/records.js +8 -6
- package/modules/world/sim.js +60 -20
- package/modules/world/simFar.js +4 -3
- package/modules/world/state.js +3 -2
- package/modules/world/thingSource.js +1 -1
- package/modules/world/views.js +7 -5
- package/package.json +8 -3
- package/presets.js +41 -27
- package/render/PostFX.js +145 -120
- package/render/backend.js +440 -0
- package/render/detail.js +150 -45
- package/render/effects.js +130 -38
- package/render/engineUniforms.js +10 -1
- package/render/fuse.js +5 -4
- package/render/fx/cloudShadow.tsl.js +16 -0
- package/render/fx/detail.tsl.js +66 -0
- package/render/fx/index.js +26 -0
- package/render/fx/lighting.tsl.js +28 -0
- package/render/fx/nodeErrors.tsl.js +68 -0
- package/render/fx/noise.tsl.js +12 -0
- package/render/fx/objectOrigin.tsl.js +42 -0
- package/render/fx/particles.tsl.js +139 -0
- package/render/fx/patchNodes.tsl.js +403 -0
- package/render/fx/postWebGPU.tsl.js +158 -0
- package/render/fx/season.tsl.js +13 -0
- package/render/fx/sky.tsl.js +260 -0
- package/render/fx/uniforms.tsl.js +67 -0
- package/render/fx/water.tsl.js +53 -0
- package/render/fx/wind.tsl.js +22 -0
- package/render/fxNumbers.js +36 -0
- package/render/hotGlsl.js +24 -0
- package/render/lighting.js +66 -14
- package/render/lights.js +223 -4
- package/render/lookGlow.js +139 -0
- package/render/lookSurface.js +99 -36
- package/render/materials.js +71 -52
- package/render/modeling.js +73 -0
- package/render/ownFrame.js +76 -0
- package/render/patches.js +311 -34
- package/render/postLook.js +124 -46
- package/render/postWebGL.js +197 -0
- package/render/probes.js +231 -0
- package/render/shaderErrors.js +154 -0
- package/render/slots.js +165 -0
- package/render/surface.js +53 -17
- package/render/terms.js +211 -0
- package/render/uniformDecl.js +3 -2
- package/types/common.d.ts +2 -2
- package/types/core.d.ts +620 -244
- package/types/gameplay.d.ts +494 -318
- package/types/generated/core/Audio.d.ts +26 -42
- package/types/generated/core/Batching.d.ts +6 -2
- package/types/generated/core/Budget.d.ts +2 -8
- package/types/generated/core/DebugOverrides.d.ts +44 -3
- package/types/generated/core/I18n.d.ts +2 -2
- package/types/generated/core/Input.d.ts +102 -31
- package/types/generated/core/Ops.d.ts +31 -0
- package/types/generated/core/Random.d.ts +2 -2
- package/types/generated/core/Saves.d.ts +10 -2
- package/types/generated/core/Stream.d.ts +1 -1
- package/types/generated/core/Threads.d.ts +4 -1
- package/types/generated/core/Views.d.ts +0 -1
- package/types/generated/core/audioVoice.d.ts +17 -9
- package/types/generated/core/control.d.ts +55 -0
- package/types/generated/core/session.d.ts +2 -1
- package/types/generated/modules/ambience/Ambience.d.ts +0 -9
- package/types/generated/modules/calendar/Calendar.d.ts +84 -0
- package/types/generated/modules/calendar/index.d.ts +10 -0
- package/types/generated/modules/debug/DebugPanel.d.ts +2 -2
- package/types/generated/modules/grid/Grid.d.ts +61 -25
- package/types/generated/modules/grid/Layer.d.ts +5 -5
- package/types/generated/modules/grid/index.d.ts +29 -17
- package/types/generated/modules/music/Music.d.ts +5 -3
- package/types/generated/modules/net/index.d.ts +3 -3
- package/types/generated/modules/net/transports.d.ts +12 -3
- package/types/generated/modules/particles/Particles.d.ts +1 -1
- package/types/generated/modules/sky/Sky.d.ts +12 -104
- package/types/generated/modules/sky/skyModule.d.ts +1 -1
- package/types/generated/modules/timeline/Timeline.d.ts +8 -6
- package/types/generated/modules/weather/Weather.d.ts +17 -18
- package/types/generated/modules/weather/weatherLook.d.ts +12 -0
- package/types/generated/modules/world/World.d.ts +18 -3
- package/types/generated/render/PostFX.d.ts +67 -30
- package/types/generated/render/materials.d.ts +26 -20
- package/types/generated/render/modeling.d.ts +30 -0
- package/types/generated/render/patches.d.ts +16 -2
- package/types/generated/ui/UI.d.ts +6 -3
- package/types/nav.d.ts +6 -0
- package/types/physics.d.ts +137 -44
- package/types/style.d.ts +125 -92
- package/types/tsl.d.ts +86 -0
- package/types/world.d.ts +164 -110
- package/ui/Focus.js +25 -14
- package/ui/LoadingScreen.js +1 -1
- package/ui/Parts.js +27 -11
- package/ui/UI.js +20 -10
- package/ui/cursor.js +115 -0
- package/ui/defaults.js +15 -11
- package/ui/theme.js +9 -6
- package/ui/touchPart.js +1 -1
- package/core/claims.js +0 -51
- package/core/look/layers.js +0 -136
- package/core/renamed.js +0 -21
- package/docs/api/entities.md +0 -61
- package/docs/recipes/09-style-pack.md +0 -234
- package/examples/styletest/overrides.js +0 -33
- package/examples/styletest/panel.js +0 -135
- package/modules/entities/Entities.js +0 -243
- package/modules/entities/build.js +0 -25
- package/modules/entities/index.js +0 -4
- package/modules/sky/calendar.js +0 -80
- package/modules/sky/layers.js +0 -69
- package/modules/terrain/chunkLevels.js +0 -40
- package/modules/terrain/mountTerrain.js +0 -32
- package/modules/world/cells.js +0 -42
package/docs/recipes/31-audio.md
CHANGED
|
@@ -5,16 +5,23 @@ Everything you hear is the game's. The engine ships no sound files and plays not
|
|
|
5
5
|
`api/ambience.md`, `api/music.md`.
|
|
6
6
|
|
|
7
7
|
## 1. Config in one place
|
|
8
|
+
Two places, one job each: **the asset manifest says what a sound is** (a file, or a synth function made in code, registered by name like a
|
|
9
|
+
model), **`audio.sounds` says how it plays** (which sound or variants, volume, bus, cooldown...). Engine modules register their own synths
|
|
10
|
+
(`footstep`, `shutter`, `thunder`, ambience's `wind` `rain` `water` `birds` `crickets`) as built-in sound assets that stay silent until a rule names them.
|
|
8
11
|
```js
|
|
12
|
+
engine.assets.manifest({ name: 'sfx', sounds: {
|
|
13
|
+
door: '/sfx/door.ogg', hit1: '/sfx/hit1.ogg', hit2: '/sfx/hit2.ogg', shot: '/sfx/shot.ogg',
|
|
14
|
+
ding: (a, p, out) => { a.tone({ freq: 880 * p.pitch, dur: 0.2, out }); return 0.2; }, // a synth: connect to out, return seconds (or { stop(t) })
|
|
15
|
+
} });
|
|
9
16
|
const engine = createEngine({ canvas, audio: {
|
|
10
17
|
levels: { music: 0.4, voice: 1 }, // volume per bus; an extra key (voice) adds a bus
|
|
11
18
|
sounds: {
|
|
12
|
-
door:
|
|
13
|
-
hit: ['
|
|
14
|
-
shot: { src: '
|
|
15
|
-
footstep:
|
|
16
|
-
'step.sand': {
|
|
17
|
-
wind:
|
|
19
|
+
door: {}, // the asset of the same name, default rules
|
|
20
|
+
hit: ['hit1', 'hit2'], // variants: random, never the same one twice in a row
|
|
21
|
+
shot: { src: 'shot', jitter: { pitch: 0.08, volume: 0.1 }, cooldown: 0.05, voices: 4, distance: { ref: 3, max: 80 } },
|
|
22
|
+
footstep: {}, // a built-in synth asset, named so it plays
|
|
23
|
+
'step.sand': { src: 'footstep', params: { surface: 'sand' } }, // a synth source with parameters
|
|
24
|
+
wind: {}, birds: {}, ding: { volume: 0.6 },
|
|
18
25
|
},
|
|
19
26
|
ambience: [ /* rule table, section 3 */ ],
|
|
20
27
|
music: { tracks: { /* section 4 */ }, rules: [] },
|
|
@@ -32,18 +39,19 @@ Buses are real Web Audio `GainNode`s: `master`, `music`, `sfx`, `ambience`, `ui`
|
|
|
32
39
|
engine.audio.sfx('door'); // plays on its bus (default sfx)
|
|
33
40
|
const h = engine.audio.sfx('shot', { at: enemy.root }); // 3D: a PannerNode that follows the Object3D every frame
|
|
34
41
|
const hum = engine.audio.sfx('engine-hum', { loop: true, at: [4, 0, 2] });
|
|
35
|
-
hum?.fade(0.2, 1.5); hum?.stop(1); // the handle (null while silent, see below): fade(to, seconds), stop(fade), setPosition(at)
|
|
42
|
+
hum?.fade({ to: 0.2, seconds: 1.5 }); hum?.stop({ fade: 1 }); // the handle (null while silent, see below): fade({ to, seconds }), stop({ fade }), remove(), setPosition(at)
|
|
36
43
|
engine.audio.sfx('click', { bus: 'ui' });
|
|
37
44
|
```
|
|
38
|
-
`sfx` returns `null` when the sound is silent:
|
|
45
|
+
`sfx` returns `null` when the sound is silent: neither a rule nor an asset of that name, a built-in synth no rule names, audio still locked (before
|
|
46
|
+
the first click), or inside its `cooldown`. A manifest sound with no rule plays by its name with default rules. Over its
|
|
39
47
|
`voices` limit the oldest voice stops. Files by path without an entry: `await engine.audio.play(url, { bus, loop, fadeIn })`.
|
|
40
48
|
|
|
41
49
|
Built-in synth parameters (`params`): `wind` / `water` take `freq` (filter Hz), `birds` `range: [low, high]` Hz, `crickets` `freq` (chirp Hz, default
|
|
42
50
|
4300); every synth also gets `pitch`, the sfx pitch multiplier (~1). A sound whose file fails to load keeps its ambience rule silent (one warning)
|
|
43
51
|
until the rules load again, instead of refetching.
|
|
44
52
|
|
|
45
|
-
Your own synth
|
|
46
|
-
return the length in seconds (or `{ stop(t) }` for a loop).
|
|
53
|
+
Your own synth is a sound asset: `engine.assets.manifest({ sounds: { ding: synthFn } })` (or `{ build: synthFn, params }` for default params).
|
|
54
|
+
Connect to `out` and return the length in seconds (or `{ stop(t) }` for a loop).
|
|
47
55
|
|
|
48
56
|
## 3. Ambience: a rule table
|
|
49
57
|
Each rule names a sound and says when and how loud. A rule with `every` is a one-shot at random gaps; without, a loop that fades in and out (and stops
|
|
@@ -99,7 +107,7 @@ A content pack carries the game's audio the way it carries items: data only, sou
|
|
|
99
107
|
```js
|
|
100
108
|
// content/audio.js (export it from content/index.js like any content file)
|
|
101
109
|
export default {
|
|
102
|
-
sounds: { wind:
|
|
110
|
+
sounds: { wind: {}, door: 'door', hit: ['hit1', 'hit2'], shot: { src: 'shot', cooldown: 0.05 } }, // asset pack sound names (files or synths)
|
|
103
111
|
ambience: [
|
|
104
112
|
{ sound: 'wind', volume: { base: 0.05, add: { wind: 0.08, altitude: 0.00375 }, max: 0.5 } }, // base + measure x factor, clamped
|
|
105
113
|
{ sound: 'rain', volume: { add: { rain: 0.22 } } },
|
|
@@ -113,7 +121,7 @@ export default {
|
|
|
113
121
|
engine.assets.manifest({ name: 'sfx', base: '/sounds/', sounds: { door: 'door.ogg', hit1: 'hit1.ogg', hit2: 'hit2.ogg', shot: 'shot.ogg', 'music-day': 'day.ogg' } });
|
|
114
122
|
engine.content.load([base, forest]); // each pack's audio merges in
|
|
115
123
|
```
|
|
116
|
-
- **Names, never paths or code.** A sounds string
|
|
124
|
+
- **Names, never paths or code.** A sounds string is a sound name from an asset pack, a file or a synth (`engine.audio.load` and music resolve it
|
|
117
125
|
through `engine.assets`, so a missing file falls back to silence as an `engine.loading` task). A file path warns in dev; a function anywhere in the
|
|
118
126
|
table drops that rule with a dev warning. `npm run check` reports both as errors.
|
|
119
127
|
- **Measures** are the numbers data compares and adds up. Built in: `daylight` (sky, 0 at night), `rain` / `snow` / `wind` (weather), `nearWater`
|
|
@@ -12,7 +12,7 @@ working example is `examples/action/` (page `/action.html`, about 150 lines of r
|
|
|
12
12
|
| Attack, damage, enemy hit, death | ops with `can` / `run` (recipe 23), so keys, the dev bridge, MCP, tests and the AI run one rule | `player.attack`, `enemy.damage`, `enemy.attack`, `player.die` |
|
|
13
13
|
| Enemy AI (chase, face, strike) | `engine.world.simulate(kind, { near })`, a fixed step per near record; it strikes with `ops.run(..., { actor: rec.id })` | `world.simulate('slime', ...)` |
|
|
14
14
|
| Gameplay keys | content `actions` (`attack: { keys: ['Mouse0', 'KeyF'] }`), read with `input.pressed` in `onFixed` | `onFixed` runs `player.attack` |
|
|
15
|
-
| Drop | `engine.
|
|
15
|
+
| Drop | `engine.pickups.spawn(at, { give: item, id })` inside the death op; E picks it up through `interactions`, into the bag of whoever presses | `${id}-drop` |
|
|
16
16
|
| HUD, death screen, retry, save keys | `onFrame`: `hud.bar`, `toast`, `engine.session.newGame()` | the frame hook |
|
|
17
17
|
|
|
18
18
|
## 2. Rules that keep it replayable
|
|
@@ -29,5 +29,38 @@ working example is `examples/action/` (page `/action.html`, about 150 lines of r
|
|
|
29
29
|
`followCamera({ ...presets.camera.overShoulder })` locks the mouse on a click. While locked, mouse buttons still arrive as `Mouse0`..`Mouse4` keys, so
|
|
30
30
|
`attack: { keys: ['Mouse0'] }` works in both states. The click that takes the lock is itself a `Mouse0` press and swings once; a game that does not
|
|
31
31
|
want that ignores attacks until the `page:pointerlock` event reports `locked: true`. `presets.player.aim` turns the player toward where the camera
|
|
32
|
-
looks, so a swing goes where you aim. Without a style
|
|
32
|
+
looks, so a swing goes where you aim. Without a style the room and enemy are gray (`?style=none`); colors come from a style part
|
|
33
33
|
(`examples/action/look.js`).
|
|
34
|
+
|
|
35
|
+
## 4. Movement: jumps, speed effects, bullet time, platforms, falling
|
|
36
|
+
```js
|
|
37
|
+
createPlayer({ ...presets.player.thirdPerson, maxJumps: 2 }); // double jump: the same jump key twice
|
|
38
|
+
engine.player.launch(16, { owner: 'pad' }); // a jump pad / spring
|
|
39
|
+
engine.mod('move.speed', { owner: 'haste', id: 'player', mul: 1.2, for: 5 }); // haste for 5 s; no id = every character (mud, wind)
|
|
40
|
+
engine.mod('time.enemies', { owner: 'bullet-time', mul: 0.35, for: 2 }); // bullet time: enemies on channel 'enemies' at 35%
|
|
41
|
+
engine.onFixed(dt => moveShots(dt), { channel: 'enemies' }); // your own enemy logic on the same slowed dt
|
|
42
|
+
engine.characters.support(liftMesh); // a moving platform: move liftMesh any way, riders follow
|
|
43
|
+
engine.player.mover = 'manual'; /* a cutscene, your own physics */ engine.player.mover = 'simple'; // take over, give back
|
|
44
|
+
```
|
|
45
|
+
- **Jumps** (all public, no private fields): `jump()` is buffered for `jumpBuffer` s (default 0.12) and uses coyote time (`coyoteTime`); in the air it is an
|
|
46
|
+
air jump while `maxJumps` allows, at `airJumpSpeed` (default `jumpSpeed`). `jump({ air: false })` = ground only. `addJumps(n)` / `resetJumps()` for
|
|
47
|
+
pickups and wall touches, `launch(speed, { owner })` for jump pads (emits `character:launch`), `jumpState()` reads `{ grounded, coyoteLeft,
|
|
48
|
+
bufferLeft, jumpsUsed, jumpsLeft, vy }`. `character:jump` carries `{ air, index }`. Writing `player.vy` yourself is fine: it is an impulse.
|
|
49
|
+
- **Speed, gravity, jump height, can-jump**: the fields (`player.speed = 6`) are the game's base values; effects go through `engine.mod('move.speed' |
|
|
50
|
+
'move.runSpeed' | 'move.gravity' | 'move.jumpSpeed' | 'move.canJump', { owner, id?, set | add | mul | clamp, for? })`, so stamina (run = walk), haste
|
|
51
|
+
x1.2 and mud x0.6 combine and end in any order. `player.stat('speed')` reads the result. A stun: `engine.mod('move.canJump', { owner: 'stun', id:
|
|
52
|
+
'player', set: 0, for: 0.8 })`. `move()` takes no speed argument; the direction's length (0-1) scales the speed.
|
|
53
|
+
- **Bullet time / time channels**: a character the engine drives moves and animates on `character.channel` (player `'player'`, NPCs `'world'`), so
|
|
54
|
+
`engine.mod('time.enemies', { owner: 'bullet-time', mul: 0.35 })` slows NPCs added with `npcs.add({ channel: 'enemies' })` (far ones too) and
|
|
55
|
+
`onFixed(fn, { channel: 'enemies' })` code; `clock.after(1, 'poison:tick', data, { channel: 'enemies' })` slows a timer with them. The player keeps
|
|
56
|
+
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).
|
|
57
|
+
- **Platforms**: `characters.support(object, { id?, safe?, carry?: 'position' | 'position+yaw', inherit? })` returns `{ id, remove() }`. The rider
|
|
58
|
+
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
|
|
59
|
+
player, in a timeline or in physics. `player.support` says what it stands on (`kind: 'ground' | 'platform' | 'collider' | 'water' | null`, the
|
|
60
|
+
platform's `velocity`); jumping off keeps the platform's speed until landing. With `mover: 'rapier'` give the platform a collider as well.
|
|
61
|
+
- **Falling out**: `createPlayer({ ..., fall: { belowY: -20 } })` fires `character:fall { character, safe, preventDefault() }` once and puts the player
|
|
62
|
+
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.
|
|
63
|
+
- **Your own controller**: `mover: 'manual'` = you write the position; `move()` then only updates `grounded`, `support` (platforms still carry),
|
|
64
|
+
`safeGround` and the fall check. Switch at any time (`player.mover = 'manual'` / `'simple'`): a cutscene, a grapple, a ladder.
|
|
65
|
+
- **Knockback / dashes**: `player.push(vx, vz, seconds)`. Writing `player.velocity` or `player.vy` is an impulse: the mover keeps integrating from
|
|
66
|
+
it next step (horizontal velocity is then steered back toward the input), so it never fights you; for full control use `mover: 'manual'`.
|
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
# Environment lighting
|
|
2
2
|
|
|
3
|
-
The engine gives the mechanism and sets nothing: `scene.environment` is `null` until a style
|
|
4
|
-
|
|
3
|
+
The engine gives the mechanism and sets nothing: `scene.environment` is `null` until a style or the game asks for one, so the default look
|
|
4
|
+
(lit by the sun and hemisphere lights only) is unchanged. The background (the sky dome or `sky.skybox`) and the environment lighting are two separate fields.
|
|
5
5
|
|
|
6
6
|
```js
|
|
7
7
|
engine.look.env.replace('sky'); // lit by the procedural sky; follows the time of day
|
|
8
8
|
engine.look.env.set({ intensity: 0.8 });
|
|
9
9
|
engine.look.env.replace('hdr/studio.hdr'); engine.look.env.set({ intensity: 1, rotation: Math.PI / 2 }); // an HDR / panorama asset (equirectangular)
|
|
10
10
|
engine.look.env.set({ intensity: 0.5 }); // fields given change, the rest stay
|
|
11
|
-
engine.look.env.replace(
|
|
11
|
+
engine.look.env.replace(myPmremTarget); // your own map: a PMREM target / texture is used as is, a Texture (equirect) or CubeTexture is prefiltered; never disposed by the engine
|
|
12
|
+
engine.look.env.replace(false); // sky map off, GPU memory released; the room map of look.lights env.share (under a sky; env.intensity without one, 0 = none) is back
|
|
12
13
|
engine.sky.environment; // { source, intensity, rotation, interval, builds } or null
|
|
13
14
|
```
|
|
14
15
|
A pack gives defaults in `sky.environment` (same fields, plus `low`), the game overrides with `sky({ environment: {...} })` or at run time with
|
|
15
16
|
`look.env.replace(...)` / `look.env.set(...)`. `low: false` turns it off on low-tier devices; any other `low` object replaces fields there.
|
|
17
|
+
Removing a game layer (`h.remove()`) falls back to the pack's env, and with none to the render baseline's neutral room map (`look.lights` `env.share` of the ambient under a sky, `env.intensity` without one; 0.5 under every pack), not to no environment; a pack that wants none sets `env.share: 0` and `env.intensity: 0`.
|
|
16
18
|
|
|
17
19
|
## Sources
|
|
18
20
|
- `'sky'`: the dome is rendered into a cube and prefiltered with `PMREMGenerator`. It is rebuilt only when the sky colors, sun direction or cloud
|
|
@@ -31,6 +33,27 @@ A pack gives defaults in `sky.environment` (same fields, plus `low`), the game o
|
|
|
31
33
|
reflections from the scene environment (use a Standard / Physical material for that).
|
|
32
34
|
- Intensity is `scene.environmentIntensity`, direction offset is `scene.environmentRotation` (Y only here).
|
|
33
35
|
- The hemisphere light stays and adds on top. When you turn the environment on, lower the ambient column of `sky.keyframes` (or
|
|
34
|
-
`
|
|
36
|
+
`engine.mod('look.lights.hemi.intensity', { owner: 'env', mul: 0.5 })`, [recipe 52](52-look.md#how-look-values-stack)) so shadows do not wash out.
|
|
35
37
|
- The first frame with an environment recompiles every Lambert program once (the program key gains the env map); do it at start-up, not mid-game.
|
|
36
38
|
- Toon, Basic and ShaderMaterial surfaces ignore it.
|
|
39
|
+
|
|
40
|
+
## Light probes (baked indirect light)
|
|
41
|
+
An environment map lights everything as seen from one point. Light probes record how the light changes from place to place (a colored glow beside
|
|
42
|
+
a bright wall, dimmer light under a roof) and feed it to the same lit materials, with no shader of their own.
|
|
43
|
+
```js
|
|
44
|
+
const probes = await engine.bakeProbes({ bounds: { min: [-30, 0, -30], max: [30, 8, 30] }, spacing: 4, include: o => !o.userData.moving });
|
|
45
|
+
const file = JSON.stringify(probes.toJSON()); // ship this; at start-up engine.loadProbes(json) replaces the bake
|
|
46
|
+
const shipped = engine.loadProbes(json, { follow: engine.player.root }); // follow: 'focus' (default) | 'camera' | an Object3D | () => position | false
|
|
47
|
+
probes.sample(cart.position, cartProbe); // the SH at any point, into a LightProbe of your own
|
|
48
|
+
probes.remove();
|
|
49
|
+
```
|
|
50
|
+
- What it builds: a grid over `bounds` (step at most `spacing`; `height: 1.5` instead gives one layer that far above the ground), one cube render
|
|
51
|
+
per point turned into spherical harmonics by three's `LightProbeGenerator`, and one scene `LightProbe` whose SH is interpolated at the `follow`
|
|
52
|
+
point every frame. `probes.probe` is that LightProbe; its `intensity` is yours (three's default 1). Writing its `sh` yourself takes it over
|
|
53
|
+
(the engine yields; `look.lights.manual('probes')` says so first).
|
|
54
|
+
- The probe light adds to the hemisphere light and the environment, which the bake also saw: lower those yourself where the probes take over.
|
|
55
|
+
- One SH for the whole scene at a time: objects far from the follow point get that point's light. For per-object light, feed your own probes
|
|
56
|
+
from `sample(pos)`.
|
|
57
|
+
- Cost: 6 renders and a GPU read back per probe, at load time (one probe at a time, so the page keeps drawing; `probes.bakeMs` says how long).
|
|
58
|
+
Bake once and ship the JSON. Meshes `include` rejects are hidden only while each cube renders; no render target is left afterwards.
|
|
59
|
+
- Check it: `engine.describe().render.probes` (count, step, source, owner, follow, writer) and `engine.debug.view('probes')` (a dot per probe in its average color).
|
|
@@ -1,12 +1,43 @@
|
|
|
1
1
|
# Making a new look from a reference picture
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
**In this recipe**: The loop · What a style can change, and what it cannot · Steps · Look check after every shot · Look questions · Guard rails ·
|
|
4
|
+
The style test page
|
|
5
|
+
|
|
6
|
+
No reference picture? Skip the measuring (step 2, `style palette`, `style compare` against a reference); judge each shot against DESIGN.md and
|
|
7
|
+
its "Loved / Not for this game" list, and use the rest: the loop, `style check`, the look check after every shot and the look questions.
|
|
8
|
+
|
|
9
|
+
For an AI that is given one picture ("make it look like this") and has to turn it into a style. The tools keep the work measurable: `threedog style palette`
|
|
10
|
+
and `style compare` measure pictures, your game's `style/index.js` holds the result, `threedog style check` finds mistakes before you look at pixels. They never say which
|
|
11
|
+
colors are right; the taste is yours. What a style is and the composing rules are in `09-style.md`; this page is the order of work.
|
|
12
|
+
|
|
13
|
+
## The loop (every round, in this order)
|
|
14
|
+
Looping "edit, screenshot, read the image" costs the most tokens and fixes the least. Numbers come first, pictures last.
|
|
15
|
+
1. **Measure the reference once** (step 2 below): `style palette <ref> --average`, then `style compare <ref> <your shot>`. Break the picture into
|
|
16
|
+
techniques (shading, one texture language, palette, edges) before choosing values.
|
|
17
|
+
2. **Change one family of values** (colors, then materials, then post). Art code hot-swaps on save. After writing or changing a model, look at it alone
|
|
18
|
+
first: `threedog gallery --shots` (every model under three lights, `.threedog/gallery/index.html`) shows wrong scale, wrong facing, holes and missing
|
|
19
|
+
faces before the level hides them.
|
|
20
|
+
3. **Shoot small and compare to the previous shot**: `threedog shot styletest --view overview --size 480x270 --keep --compare <previous.png>`. It prints the
|
|
21
|
+
pixel diff and the look differences. Through MCP the `snap` tool is 480 px wide by default; `style_compare` gives the numbers.
|
|
22
|
+
4. **Read the numbers first, then at most one image per round.** Name the biggest remaining difference and fix only that. `style compare <ref> <shot>
|
|
23
|
+
--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
|
|
24
|
+
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
|
|
25
|
+
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),
|
|
26
|
+
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
|
|
27
|
+
STATUS.md with why it stays. Before calling a look done, go through the "Look questions" below that matter for this game.
|
|
28
|
+
5. **Wrong in a way the numbers do not explain?** Diagnose before guessing: `engine.debug.view('albedo' | 'lighting' | 'shadow' | 'normals')` shows which
|
|
29
|
+
layer is off, `engine.describe().look` shows who set each value and where (recipe 52). Nothing drawn: `threedog scene --hidden` (reasons per mesh).
|
|
30
|
+
Washed-out or too-dark textures, odd normals: `threedog inspect materials` (wrong color spaces first, sizes, who made each material).
|
|
31
|
+
6. **If the biggest difference stops shrinking over a few rounds, change approach** (in this order) and tell the user which and why:
|
|
32
|
+
`look.surface.patch('detail' | 'lighting', glsl)` -> painted textures (`map`, `normalMap`) -> `look.materials.replace` -> plain three.js
|
|
33
|
+
(recipe 40 section 8). Never call it "close" to stop tuning.
|
|
34
|
+
7. **Every few rounds show the user the shot and the numbers.**
|
|
35
|
+
|
|
36
|
+
The loop is the same for every art direction; only what you measure and which value you move differ: flat (palette share, hard edges, no shading), painterly
|
|
37
|
+
(soft edges, texture, low contrast), low-poly (few flat colors, faceted light), realistic (exposure, tone mapping, lighting, material roughness). None is the default.
|
|
7
38
|
|
|
8
39
|
## What a style can change, and what it cannot
|
|
9
|
-
Can change (all in the style
|
|
40
|
+
Can change (all in the style): colors (`palette`, `terrain.colors`, `background`, `water.color`, season tints), material types per role
|
|
10
41
|
(`materials`: matte `lambert`, `toon` bands, `standard`...), lights and sky (`sky.keyframes`, sun, clouds, shadows, `exposure`, `toneMapping`), post
|
|
11
42
|
effects (`post`: outline, bloom, grain, vignette, color grading from `@threedog/post-effects`), UI colors and fonts, particle looks, and the colors
|
|
12
43
|
of the procedural models (`palette` read by `models.js`).
|
|
@@ -18,57 +49,83 @@ world (a canyon instead of hills), say so instead of faking it with colors.
|
|
|
18
49
|
|
|
19
50
|
## Steps
|
|
20
51
|
1. **Keep the picture.** Put it in the game's `art/reference/` (one file per look, with a few lines of notes beside it on what to copy:
|
|
21
|
-
palette, mood, line work, light direction).
|
|
22
|
-
2. **Measure it.** `threedog style palette art/reference/ref.png --n 8` prints
|
|
23
|
-
largest block = ground / environment candidate, brightest = highlight / sky candidate, most saturated = accent candidate,
|
|
24
|
-
outline candidate
|
|
25
|
-
reads pixels in a headless browser (png, jpg, webp, gif, svg).
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
`import style, { assets } from '@threedog/style-sand-dune'`, `createEngine({ canvas, style })`, `engine.assets.manifest(assets)`.
|
|
32
|
-
To start from another pack's strengths instead, compose: `style: [lowpoly, sandDune]` (later parts win key by key).
|
|
52
|
+
palette, mood, line work, light direction). Use the highest-resolution picture you have: a small or compressed one gives wrong detail and brightness numbers.
|
|
53
|
+
2. **Measure it.** `threedog style palette art/reference/ref.png --n 8 --average` (MCP: `style_palette`) prints the colors (`--json`: JSON only) with share, hue, saturation,
|
|
54
|
+
brightness, and role hints: largest block = ground / environment candidate, brightest = highlight / sky candidate, most saturated = accent candidate,
|
|
55
|
+
darkest = shadow or outline candidate, and one summary line such as `warm colors, mostly sand, low saturation, medium brightness, weak light/dark contrast`.
|
|
56
|
+
It reads pixels in a headless browser (png, jpg, webp, gif, svg). The overall mean (`--average`) sets exposure and tint; the clusters pick the named
|
|
57
|
+
palette entries. A phone screenshot with a dark UI frame needs `--ignore-ui` or `--region x,y,w,h`; `--crop cut.png` saves exactly what was measured.
|
|
58
|
+
3. **Open the style.** Edit your game's `style/index.js` (a new game has one with every key commented out, so the engine shows gray placeholders).
|
|
59
|
+
It is already passed in: `import style from './style/index.js'`, `createEngine({ canvas, style })`. Procedural models the look needs go in the same
|
|
60
|
+
folder (`style/models.js`, registered with `engine.assets.manifest({ name: 'mygame', models })`).
|
|
61
|
+
To start from another pack's strengths instead, compose: `style: [basePack, style]` (later parts win key by key).
|
|
33
62
|
4. **Fill it in, in this order** (each step changes the picture most for the least work): `sky` and `background` (light and mood), `exposure` and
|
|
34
|
-
`toneMapping`, `palette` and `terrain.colors` / `biomeColors` (the measured colors, snapped to a few named ones
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
5. **Check.** `threedog style check
|
|
63
|
+
`toneMapping`, `palette` and `terrain.colors` / `biomeColors` (the measured colors, snapped to a few named ones; a reference usually has 5 to 8 that
|
|
64
|
+
matter), `materials` (`lambert` matte, `toon` banded, `phong` shiny, `standard` PBR, `basic` unlit), `post`, then `ui`. The first frame should already be close:
|
|
65
|
+
if it is far from the reference, fix sky, exposure, palette and material type before adding anything.
|
|
66
|
+
5. **Check.** `threedog style check` (the game's `style/` folder; or give a folder, a file or a game name). It checks the final merged style, not each part:
|
|
38
67
|
unknown fields (with "did you mean"), world-state fields, palette keys a model reads but the style does not define, color formats (`'ff8800'`
|
|
39
68
|
without `#`, a float, a string `'0xff8800'`), post-effect conflicts (same name twice, two `scene` effects, a depth reader after a buffer-swapping
|
|
40
69
|
effect, `dof` ordered after `outline`), misspelled material roles and types, and asset names the pack does not register. `--json` gives the same list for
|
|
41
70
|
tools, `--assets file.js` adds another pack's names. Exit code 1 on errors. It is static: it cannot prove a pack holds no gameplay logic, only
|
|
42
71
|
the patterns R34 can see (`npm run check` runs R34).
|
|
43
|
-
6. **Look.** Take pictures with the same arguments every round so only the style differs
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
72
|
+
6. **Look: the loop above.** Take pictures with the same arguments every round so only the style differs, and use the style test page's named camera
|
|
73
|
+
views (below), not free `--pos` shots. `threedog style compare art/reference/ref.png .threedog/shots/styletest.png [--region x,y,w,h]` prints brightness,
|
|
74
|
+
saturation, contrast, fine detail, average and main color of both and one sentence such as "the screenshot is 18% darker and 2.3x more broken up". There is
|
|
75
|
+
deliberately no "similarity %": the numbers turn "looks dirty / fragmented / too dark" into something you can change and re-measure. Dirty = lower
|
|
76
|
+
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
|
|
77
|
+
the reference and the picture looks better. A phone UI frame in the screenshot skews the numbers: compare a `--region`.
|
|
78
|
+
Add `--out side.png` (MCP `style_compare` always writes `<shot>.compare.png`) and open that one image: reference left, screenshot right; look at both.
|
|
79
|
+
7. **Stop** when the biggest remaining difference is a silhouette or a world rule: that is the asset pack or the game, not the style.
|
|
80
|
+
|
|
81
|
+
## Look check after every shot
|
|
82
|
+
Every `threedog shot` prints look numbers and hints (`--no-look` skips them). The numbers are luminance, contrast (std and p5-p95 range of
|
|
83
|
+
luminance), saturation, clipped and near-black shares, and the shadow area. Hints come in two kinds:
|
|
84
|
+
- **Contradictions**, whatever the style: the settings say one thing and the pixels another. Shadows on but none measurable (with the cause it found:
|
|
85
|
+
`look.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
|
|
86
|
+
no pixel.
|
|
87
|
+
- **Facts**: measured, maybe wanted, with what sets them: glare, large clipped or near-black areas, a night that is not dark from lighting (and
|
|
88
|
+
whether the brightness at 00:00 is lighting at all), the key / fill balance. Each becomes a contradiction only where DESIGN.md declares the
|
|
89
|
+
opposite.
|
|
90
|
+
- **Intent**, only against what the game declared: DESIGN.md's optional `Look intent:` line (listed words such as `no-glare`, `dark-nights`,
|
|
91
|
+
`strong-light`, `muted`; the template lists them all; the table's free text is not read), or the reference given with `--ref`. A muted,
|
|
92
|
+
low-contrast game is told when its shot measures saturated and contrasty, never the other way round unless it said so. No declaration and
|
|
93
|
+
no reference: numbers only, no judgement.
|
|
94
|
+
|
|
95
|
+
A hint is a fact plus the parameter and its current value, not a target. It never says what value is right for an art direction; decide that from
|
|
96
|
+
the reference, DESIGN.md or the user. A deliberate choice (a night meant to be pitch black) makes a hint something to note, not to fix.
|
|
53
97
|
|
|
54
|
-
##
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
- **
|
|
58
|
-
|
|
59
|
-
- **
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
- **
|
|
68
|
-
|
|
69
|
-
|
|
98
|
+
## Look questions
|
|
99
|
+
Pick the ones that matter for this game, before calling a look done and when a round stalls. They name what to look at, not which answer is
|
|
100
|
+
right for a given art direction.
|
|
101
|
+
- **Light roles**: is there one clear key light (direction, color), a fill that keeps shadows readable, and does the sky / ambient color agree with it?
|
|
102
|
+
`debug.view('lighting')`.
|
|
103
|
+
- **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
|
|
104
|
+
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
|
|
105
|
+
`look.shadow` `bias` (it is in 0-1 shadow depth, so a large value over a long light range is decimeters). Faint shadows: the shadowed ground gets
|
|
106
|
+
only hemi + environment, so their sum against the sun sets the contrast; small casters blur when the shadow box is much bigger than the
|
|
107
|
+
scene (texel size: recipe 52, "Atmosphere parts"); a compact scene fits it, for example `look.shadow.set({ extent: 30 })`.
|
|
108
|
+
- **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
|
|
109
|
+
too? A PBR material that stays bright at night is usually lit by an environment map that does not follow the time (`describe().look.env.source`
|
|
110
|
+
says which map lights it and whether it follows).
|
|
111
|
+
- **Material response**: do surfaces that should differ (wood, stone, metal, cloth, skin, water) differ in roughness, specular and color, not only hue?
|
|
112
|
+
A plastic-looking surface is a shading problem, not a color problem.
|
|
113
|
+
Metals have something to reflect (environment). A glossy flat decal (puddle, spill, polished floor) reflects only the environment map, never the
|
|
114
|
+
street around it: a hard-edged dark or bright ellipse then reads as a hole or a blob. Give it soft alpha edges and a color close to the surface
|
|
115
|
+
under it, or darken / smooth the ground's own material (roughness map) instead of laying a disc on it; check it at noon and at night.
|
|
116
|
+
- **Texture scale and detail**: is texel density similar across neighbors, no obvious tiling at the usual camera distance, detail matching how close the
|
|
117
|
+
camera gets? Color spaces right (`inspect materials`).
|
|
118
|
+
- **Color and grading**: value range (darkest / brightest), saturation and the overall hue shift match the reference (`style compare`); exposure and
|
|
119
|
+
tone mapping chosen, not left at whatever was there.
|
|
120
|
+
- **Atmosphere and depth**: fog, haze or color shift with distance as the reference shows; the background separates from the play space.
|
|
121
|
+
- **Readability of gameplay elements**: the player, interactables, hazards and pickups stand out by value or color from the ground at play distance and
|
|
122
|
+
under every time of day / weather the game uses (shoot them at dusk and in rain too).
|
|
123
|
+
- **Consistency**: does any asset step out of the overall style (outline weight, shading model, texture language) where DESIGN.md did not
|
|
124
|
+
intend it? A deliberate mix of styles is a choice, not a mistake.
|
|
70
125
|
|
|
71
126
|
## Guard rails
|
|
127
|
+
- Restraint: for each post effect, say which difference in the shot it fixes. Start with none, add one for a visible difference you named, and
|
|
128
|
+
measure again after each one; `style check` lists which are on and how to see what each costs.
|
|
72
129
|
- Never put gameplay or world values in the pack to match a picture; `style check` reports them as errors.
|
|
73
130
|
- Fonts and textures are asset-pack entries; the style names them (`ui.fonts: ['pixel']`, `terrain.detail.texture`), it does not carry files.
|
|
74
131
|
- Keep `npm run check` at 0 errors; a new pack adds no warnings.
|
|
@@ -78,12 +135,19 @@ world (a canyon instead of hills), say so instead of faking it with colors.
|
|
|
78
135
|
a shadow receiver, wood / stone / metal surfaces, a lit room (outside and inside) and the UI parts. Same arguments, same picture, so only the style differs.
|
|
79
136
|
- `threedog shot styletest --view <name> [--time day|dusk|night] [--weather clear|rain|snow]`; the same words work as URL parameters
|
|
80
137
|
(`?view=room&time=dusk&weather=rain`; also `style=none` for the engine's gray placeholders, `env=1` for environment lighting from the sky).
|
|
81
|
-
- Views: `overview` (everything
|
|
138
|
+
- Views: `overview` (everything: overall brightness, ground color, shadow darkness), `character` (close-up: character colors, outline, shadow on
|
|
82
139
|
the ground), `water` (water color, shore, fog at distance), `room` (the lamp and window light against the dark corners: ambient level, `ao`, bloom),
|
|
83
140
|
`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
|
|
84
141
|
and shadow edges that flicker or crawl), `ui` (HUD, dialogue line, bag window: the `ui` colors).
|
|
85
|
-
- Per round: shoot `overview`, `room` at `--time dusk`, and `character
|
|
86
|
-
-
|
|
142
|
+
- Per round: shoot `overview`, `room` at `--time dusk`, and `character`.
|
|
143
|
+
- The dev panel (workbench + tune), in any game: `if (location.search.includes('panel=1')) import('@threedog/tools/panel').then(m => m.openPanel(engine));`
|
|
144
|
+
It needs the optional dev package `tweakpane` (`npm install -D tweakpane`; the repository's `npm install` has it); without it the page says so.
|
|
145
|
+
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.
|
|
146
|
+
`/styletest.html?panel=1` opens it on the style test, which also passes `{ overrides }` (its `?ov=` style part) for "apply and rebuild".
|
|
87
147
|
Live sliders change exposure, sky time, environment lighting, water color, post effects and UI colors at once; palette, terrain and wave values
|
|
88
148
|
are marked "needs rebuild" and only apply after "apply and rebuild". "export overrides" prints an object literal to paste into
|
|
89
|
-
`style: [
|
|
149
|
+
`style: [yourPack, { ... }]`; the original pack is never written, so the paste is the one place the change becomes real.
|
|
150
|
+
The "tune" folder drags any look part value (`engine.look.<part>.set`), a material picked by name (color, roughness, metalness, emissive...) and
|
|
151
|
+
numeric `engine.uniforms`. "write back" saves them (with the style changes) to `.threedog/tune.json` on the dev server; then
|
|
152
|
+
`threedog tune write <file>` prints the code change as a diff (one `// threedog:tune begin ... end` block of plain calls) and `--apply` writes it.
|
|
153
|
+
Review it, then keep the block or move each value where it belongs (the pack, the material's definition).
|
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
# Sky, ground and plant looks: what a style can change
|
|
2
2
|
|
|
3
|
-
For an AI turning a reference picture into a style
|
|
3
|
+
For an AI turning a reference picture into a style and hitting "the engine draws it this way". Colors and materials are in `09-style.md`, the
|
|
4
4
|
order of work in `35-style-from-reference.md`. This page lists the places where the *shape* of a look was fixed in engine code and is now a style
|
|
5
|
-
setting.
|
|
5
|
+
setting. Each table lists the engine default; a style that sets nothing here gets those defaults. Styles hold looks only
|
|
6
6
|
(rule R34): none of these settings move a hill, a river or a species list.
|
|
7
7
|
|
|
8
|
-
## Sky clouds: `style.sky.clouds`
|
|
8
|
+
## Sky clouds: `style.sky.clouds` (at run time `engine.look.sky.set({ clouds: { coverage, color } })`; not a `sky()` option)
|
|
9
9
|
| Key | Meaning | Default |
|
|
10
10
|
|---|---|---|
|
|
11
|
-
| `color`, `shade`, `coverage`, `scale`, `speed` |
|
|
11
|
+
| `color`, `shade`, `coverage`, `scale`, `speed` | lit color, shaded color, cover (multiplies the weather's cloud amount), size, drift speed | |
|
|
12
12
|
| `kind` | `'plane'` cheap, 3 noise samples. `'cumulus'` billowy, 8 noise samples per cloudy sky pixel, flatter projection (clouds fill the whole sky instead of crowding at the horizon), the sun side of each cloud is lit and the underside shaded | `'plane'` |
|
|
13
13
|
| `horizon` | added to `dir.y` before projecting; smaller = clouds shrink and crowd more towards the horizon | plane 0.08, cumulus 0.5 |
|
|
14
14
|
| `fade` | `[from, to]` in `dir.y`: invisible below `from`, full above `to` | plane `[0, 0.18]`, cumulus `[0, 0.12]` |
|
|
15
15
|
| `opacity`, `softness` | cloud alpha; width of the cloud edge | 0.9 / 0.3 (cumulus 0.95 / 0.35) |
|
|
16
16
|
| `noise` | plane only: `{ scales: [2.7, 6.1], weights: [0.6, 0.3, 0.1] }`, the two finer layers' frequency and the mix of the three | as shown |
|
|
17
17
|
| `relief` | cumulus only: contrast of the sun-side light | 5 |
|
|
18
|
-
| `glsl`, `uniforms` | replace the cloud function with your own (below); overrides `kind` | none |
|
|
19
18
|
|
|
20
19
|
Why a thin band at the horizon with `plane`: the plane projection divides by height, so near the horizon one screen pixel covers a lot of cloud plane
|
|
21
20
|
and the noise is dense and small; overhead one pixel covers little and the same coverage looks sparse. For a sky full of big clouds use
|
|
@@ -23,12 +22,12 @@ and the noise is dense and small; overhead one pixel covers little and the same
|
|
|
23
22
|
2.7x the noise work of plane on the cloudy pixels (pixels below the horizon or with no cloud cover skip it). Cloud shadows on the ground
|
|
24
23
|
(`style.clouds.shadow`, a separate setting) follow the same weather cover, so more clouds still means more shadow.
|
|
25
24
|
|
|
26
|
-
```js
|
|
25
|
+
```js fragment
|
|
27
26
|
sky: { clouds: { kind: 'cumulus', coverage: 1, scale: 0.45, color: 0xfff4e4, shade: 0x8a9cb8, speed: [0.003, 0.001] } }
|
|
28
27
|
```
|
|
29
28
|
|
|
30
29
|
### Your own cloud function
|
|
31
|
-
`clouds
|
|
30
|
+
`engine.look.sky.patch('clouds', glsl | { glsl, uniforms })` is the one way in (a `glsl` key in `style.sky.clouds` throws and names it). The GLSL must define this function; the dome calls it for every upper-hemisphere pixel with cover above 0.01, then does `mix(sky, rgb, a)`:
|
|
32
31
|
```glsl
|
|
33
32
|
vec4 threedogClouds(vec3 dir, float time, vec3 sunDir, float night, vec3 lit, vec3 shade, float cover)
|
|
34
33
|
// dir: unit view direction, dir.y > 0. sunDir: towards the sun (the moon is opposite). night: 0 day .. 1 night.
|
|
@@ -36,75 +35,78 @@ vec4 threedogClouds(vec3 dir, float time, vec3 sunDir, float night, vec3 lit, ve
|
|
|
36
35
|
// return: rgb = final cloud color (dim it at night yourself), a = opacity (apply your own horizon fade).
|
|
37
36
|
```
|
|
38
37
|
In scope: the GLSL noise helpers `float threedogHash(vec2 p)` and `float threedogNoise(vec2 p)`, the built-in cloud uniforms (`uCloudScale`, `uCloudSpeed`, `uCloudHorizon`, `uCloudFade`...) and
|
|
39
|
-
|
|
40
|
-
with `engine.sky.dome.material.uniforms.
|
|
41
|
-
|
|
38
|
+
the patch's `uniforms` (declared for you; number, `THREE.Color`, `THREE.Vector2/3/4`, array of 2-4 numbers, or `THREE.Texture`). Change one later
|
|
39
|
+
with `engine.sky.dome.material.uniforms.uEdge.value = 0.1`. A bad `kind`, GLSL without the function, or an unsupported uniform value throws with the fix.
|
|
40
|
+
Flat painted cloud blobs with a hard edge, multiplied by a texture:
|
|
42
41
|
```js
|
|
43
|
-
clouds: { color: 0xfff1dc, shade: 0x9aa8c4
|
|
42
|
+
// style: clouds: { color: 0xfff1dc, shade: 0x9aa8c4 }; the function goes through the hook
|
|
43
|
+
engine.look.sky.patch('clouds', { uniforms: { uPaper: paperTexture, uEdge: 0.06 }, // paperTexture: any THREE.Texture, repeat wrapping
|
|
44
44
|
glsl: `vec4 threedogClouds(vec3 d, float time, vec3 sunDir, float night, vec3 lit, vec3 shade, float cover){
|
|
45
45
|
vec2 p = d.xz / (d.y + 0.5) * 0.4 + vec2(0.004, 0.002) * time;
|
|
46
46
|
float n = threedogNoise(p) * 0.65 + threedogNoise(p * 2.3 + 5.0) * 0.35;
|
|
47
|
-
float a = smoothstep(1.0 - cover, 1.0 - cover + uEdge, n); // hard
|
|
47
|
+
float a = smoothstep(1.0 - cover, 1.0 - cover + uEdge, n); // hard edge
|
|
48
48
|
float up = clamp(0.5 + (n - threedogNoise(p + sunDir.xz * 0.1)) * 6.0, 0.0, 1.0); // sun side
|
|
49
49
|
vec3 c = mix(shade, lit, up) * texture2D(uPaper, p * 3.0).rgb * (0.35 + 0.65 * (1.0 - night));
|
|
50
50
|
return vec4(c, a * smoothstep(0.0, 0.1, d.y));
|
|
51
|
-
}` }
|
|
51
|
+
}` });
|
|
52
52
|
```
|
|
53
53
|
|
|
54
54
|
## Ground color: `style.terrain.variation`
|
|
55
|
-
Terrain colors are baked
|
|
56
|
-
|
|
57
|
-
```js
|
|
55
|
+
Terrain colors are baked by the (worker) generator from the palette: two palette colors blended by a noise, a small brightness grain, and an
|
|
56
|
+
optional layer of large patches. The defaults are shown (plain data, so it travels to the workers; unknown keys throw):
|
|
57
|
+
```js fragment
|
|
58
58
|
terrain: { colors: { ... }, biomeColors: { ... },
|
|
59
59
|
variation: {
|
|
60
60
|
blend: { size: 33, strength: 1 }, // wavelength in m of the two-color noise; strength > 1 = harder contrast, < 1 = flatter
|
|
61
61
|
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)
|
|
62
|
-
patches: { size: 90, strength: 0.15, levels: 0, tint: 0xb59a5a }, // optional second, large layer
|
|
62
|
+
patches: { size: 90, strength: 0.15, levels: 0, tint: 0xb59a5a }, // optional (example values): a second, large layer of color blocks
|
|
63
63
|
} }
|
|
64
64
|
```
|
|
65
|
-
`patches` is off unless given. It is a noise much larger than `blend`; `levels: 4` snaps it to 4 flat steps (
|
|
66
|
-
|
|
67
|
-
interpolate across a chunk cell (4 m at the default resolution), so blocks smaller than that blur; for crisp
|
|
65
|
+
`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
|
|
66
|
+
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
|
|
67
|
+
interpolate across a chunk cell (4 m at the default resolution), so blocks smaller than that blur; for crisp blocks use `shading: 'texture'`
|
|
68
|
+
(recipe 37) or a texture (next). Which combination fits which look, and ground that looks wrong up close: recipe 53.
|
|
68
69
|
|
|
69
|
-
###
|
|
70
|
+
### Your own ground material
|
|
70
71
|
`style.terrain.material` (a Material or `(engine) => Material`) replaces the ground material. Chunk geometry has `uv = world xz / chunk size`, continuous
|
|
71
72
|
across chunk borders (checked by `tests/specs/appearance.mjs`), so a repeating texture is seamless whatever chunk it lands in; cloud shadows and
|
|
72
73
|
season tint are added to your material. `texture.repeat.set(8, 8)` = 8 tiles per chunk. Without UVs (steep sides stretch a top-down map), project
|
|
73
74
|
from the world position in a patch instead (`needs.patches: ['world']` gives `vThreedogWorld`):
|
|
74
75
|
```js
|
|
75
76
|
material: engine => applyEffects(new THREE.MeshLambertMaterial({ vertexColors: true }), { clouds: false, patches: [{
|
|
76
|
-
name: 'triplanar', needs: { patches: ['world'] }, uniforms: {
|
|
77
|
-
glsl: { fragment: { pars: 'uniform sampler2D
|
|
77
|
+
name: 'triplanar', needs: { patches: ['world'] }, uniforms: { uTex: { value: groundTexture }, uTexScale: { value: 0.1 } }, // groundTexture: repeat wrapping
|
|
78
|
+
glsl: { fragment: { pars: 'uniform sampler2D uTex; uniform float uTexScale;',
|
|
78
79
|
color_fragment: `vec3 n = abs(normalize(cross(dFdx(vThreedogWorld), dFdy(vThreedogWorld)))); n /= n.x + n.y + n.z;
|
|
79
|
-
diffuseColor.rgb *= texture2D(
|
|
80
|
-
+ texture2D(
|
|
80
|
+
diffuseColor.rgb *= texture2D(uTex, vThreedogWorld.zy * uTexScale).rgb * n.x + texture2D(uTex, vThreedogWorld.xz * uTexScale).rgb * n.y
|
|
81
|
+
+ texture2D(uTex, vThreedogWorld.xy * uTexScale).rgb * n.z;` } } }] })
|
|
81
82
|
```
|
|
82
83
|
A procedural noise texture is a `THREE.DataTexture` filled in a loop (`wrapS = wrapT = THREE.RepeatWrapping`, `colorSpace = THREE.SRGBColorSpace`,
|
|
83
|
-
`needsUpdate = true`)
|
|
84
|
-
`detail`
|
|
84
|
+
`needsUpdate = true`). The lighter alternative is a detail layer, `style.terrain.detail` / `look.ground.set({ detail })`: the same object as a
|
|
85
|
+
material spec's `detail` (`noise: 'grain' | 'paper' | 'stroke' | 'dabs'`, or `texture: 'name'`, or your own `glsl`; `scale`, `strength`, `fade`
|
|
86
|
+
...; keys in recipe 43), with no material of your own. Which to pick: recipe 53.
|
|
85
87
|
|
|
86
88
|
## Plants and wind
|
|
87
89
|
Audit of what the vegetation code fixes, split into mechanism (stays) and look (made a setting):
|
|
88
90
|
|
|
89
91
|
| Where | What | Kind |
|
|
90
92
|
|---|---|---|
|
|
91
|
-
| `Vegetation.
|
|
92
|
-
| `GroundChunks`, `
|
|
93
|
-
| wind sway shape | two sines (speed `1.2 + 0.6*uWind` and `2.9`, spatial phase from the instance origin), height-weighted, lean with wind strength | look: **`
|
|
93
|
+
| `Vegetation.define` | per species: `wind` amplitude, `rule`, `positions`, `densityMap`, `lodRing`, `maxRing`, `nearOnly`, `castShadow`, `shadowRing`, `material`, `effects` | already options (game content) |
|
|
94
|
+
| `GroundChunks`, `VegetationLook` (`modules/vegetation/look.js`) | one InstancedMesh per species per chunk; rings decide LOD swap, draw distance, shadow distance; 3 ms placement budget; collision lag | mechanism, stays (the whole look is replaceable: recipe 28 section 6) |
|
|
95
|
+
| wind sway shape | two sines (speed `1.2 + 0.6*uWind` and `2.9`, spatial phase from the instance origin), height-weighted, lean with wind strength | look: **`engine.look.wind.patch('sway', glsl)`** replaces it |
|
|
94
96
|
| wind speed | `uWindFreq` | already `style.wind.frequency` |
|
|
95
|
-
| season tint | `diffuseColor.rgb *= tint` (default) or a blend towards the tint; colors from `style.seasons` | look, both settings: `style.seasons.mode: 'multiply' \| 'mix'` (+ `strength`); see recipe
|
|
97
|
+
| season tint | `diffuseColor.rgb *= tint` (default) or a blend towards the tint; colors from `style.seasons` | look, both settings: `style.seasons.mode: 'multiply' \| 'mix'` (+ `strength`); see recipe 43 |
|
|
96
98
|
| defaults | `castShadow` = not `nearOnly`, `shadowRing` 1, `lodRing` 1 | per-species options, set them in the species |
|
|
97
99
|
|
|
98
100
|
```js
|
|
99
|
-
wind
|
|
101
|
+
engine.look.wind.patch('sway', { uniforms: { uSteps: 3 }, // stepped sway: plants snap between 3 poses instead of a smooth sine; before vegetation.define
|
|
100
102
|
glsl: `void threedogWind(inout vec3 transformed, vec3 ip, vec3 position){
|
|
101
103
|
float s = floor(sin(uTime * uWindFreq + ip.x * 0.3 + ip.z * 0.2) * uSteps) / uSteps;
|
|
102
104
|
transformed.x += s * max(position.y, 0.0) * THREEDOG_WIND_AMP * uWind;
|
|
103
|
-
}` }
|
|
105
|
+
}` });
|
|
104
106
|
```
|
|
105
107
|
`threedogWind` receives the vertex (`transformed`, object space), `ip` (world position of this plant's origin, so each plant has its own phase) and
|
|
106
108
|
`position`; `uTime`, `uWind` (weather), `uWindFreq` and `THREEDOG_WIND_AMP` (the species' amplitude) are in scope. It applies to every material made by
|
|
107
|
-
`vegetation.
|
|
109
|
+
`vegetation.define` that has `wind` set, and the shadow sways with it. A missing function throws with the signature. The same object works in code:
|
|
108
110
|
`applyEffects(mat, { wind: { amplitude: 0.03, glsl, uniforms } })`.
|
|
109
111
|
|
|
110
112
|
Cost, measured with software rendering (relative numbers only): 10,000 grass blades of 6 triangles in one InstancedMesh draw in 1 call; per frame
|
|
@@ -113,4 +115,4 @@ Reduce grass cost with `rule.perChunk`, `maxRing` and `nearOnly`, not the wind.
|
|
|
113
115
|
|
|
114
116
|
## What is still fixed
|
|
115
117
|
Season tint is multiplicative. Cloud *shadows* on the ground (`threedog_clouds_pars_fragment`) keep their two-noise shape; only strength, scale and
|
|
116
|
-
speed are style settings. Grass has no billboard or blade-shape setting: give `vegetation.
|
|
118
|
+
speed are style settings. Grass has no billboard or blade-shape setting: give `vegetation.define` your own `geometry` or `model`.
|