threedog 0.2.1 → 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 +71 -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 +183 -59
- 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 +37 -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 +14 -13
- package/core/gridLoad.js +2 -1
- 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 +100 -41
- 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 +63 -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 +87 -100
- package/docs/API.md +32 -28
- package/docs/CODEMAP.md +220 -147
- package/docs/COMMANDS.md +56 -35
- package/docs/CONVENTIONS.md +90 -28
- 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 +11 -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 +38 -23
- 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 +63 -60
- 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 +28 -26
- 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 +29 -13
- package/docs/api/triggers.md +5 -10
- package/docs/api/vegetation.md +11 -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 +48 -34
- package/docs/recipes/02-npc.md +24 -7
- package/docs/recipes/03-items-pickups.md +35 -21
- package/docs/recipes/04-quests.md +12 -5
- package/docs/recipes/05-props-bake.md +151 -15
- package/docs/recipes/06-clock-events.md +100 -52
- package/docs/recipes/07-flow-scenes-pause.md +40 -9
- package/docs/recipes/08-weather-sky.md +145 -36
- package/docs/recipes/{09-style-pack.md → 09-style.md} +101 -52
- package/docs/recipes/10-blender-level.md +14 -2
- package/docs/recipes/11-vehicles.md +64 -7
- package/docs/recipes/13-animation.md +14 -6
- package/docs/recipes/14-custom-module.md +61 -29
- package/docs/recipes/15-perf.md +30 -9
- package/docs/recipes/16-dev-bridge.md +61 -37
- package/docs/recipes/18-world.md +16 -6
- package/docs/recipes/19-shooting-picking.md +6 -6
- package/docs/recipes/20-content-actions-save.md +55 -17
- package/docs/recipes/21-camera.md +49 -16
- package/docs/recipes/22-shop-gold.md +3 -3
- package/docs/recipes/23-ops.md +16 -10
- package/docs/recipes/26-ui-parts.md +61 -12
- package/docs/recipes/27-net.md +11 -5
- package/docs/recipes/28-terrain.md +34 -1
- package/docs/recipes/29-grid.md +34 -16
- 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 +26 -3
- package/docs/recipes/35-style-from-reference.md +88 -19
- package/docs/recipes/36-sky-ground-plant-looks.md +18 -18
- package/docs/recipes/37-terrain-look-hooks.md +3 -2
- package/docs/recipes/38-environment-look-hooks.md +37 -26
- package/docs/recipes/40-scene.md +16 -13
- package/docs/recipes/41-thing-registry.md +11 -7
- package/docs/recipes/42-terrain-shape.md +2 -2
- package/docs/recipes/43-shader-patches-surface-looks.md +158 -76
- package/docs/recipes/44-water-weather-look-hooks.md +26 -17
- package/docs/recipes/45-cascaded-shadows.md +16 -7
- package/docs/recipes/47-island-snow-backdrop.md +7 -7
- package/docs/recipes/48-make-material.md +11 -6
- package/docs/recipes/49-game-module-contract.md +30 -17
- package/docs/recipes/50-own-renderer.md +2 -2
- package/docs/recipes/51-capability-catalog.md +3 -3
- package/docs/recipes/52-look.md +197 -61
- package/docs/recipes/53-ground-up-close.md +1 -1
- 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 -14
- 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/templates.js +1 -1
- package/examples/styletest/content/vegetation.js +1 -1
- package/examples/styletest/look.js +1 -1
- package/examples/styletest/main.js +17 -16
- 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 +1 -1
- 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 +44 -45
- package/index.js +26 -22
- package/llms.txt +11 -4
- 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 +177 -42
- package/modules/characters/NPC.js +87 -36
- package/modules/characters/assetModel.js +4 -13
- 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 +2 -1
- 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 +96 -27
- 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 +186 -110
- package/modules/vegetation/densityMap.js +62 -0
- package/modules/vegetation/groundChunks.js +52 -58
- package/modules/vegetation/index.js +32 -11
- 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 +8 -2
- 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 +7 -3
- package/presets.js +41 -27
- package/render/PostFX.js +145 -120
- package/render/backend.js +440 -0
- package/render/detail.js +120 -39
- 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 +614 -240
- package/types/gameplay.d.ts +482 -312
- 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 +109 -81
- package/types/tsl.d.ts +86 -0
- package/types/world.d.ts +158 -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 -22
- package/docs/api/entities.md +0 -61
- 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
|
@@ -1,11 +1,72 @@
|
|
|
1
1
|
# Add weather or change the sky
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
**In this recipe**: 1. Switching weather · 2. The game's own weather table · 3. Sky colors, sun, stars (and the sky color for your own shader) · 4. Time and brightness (how a game's value and the weather multiply) · 5. Verify · 6. Day and night in game logic · 7. Wet roads
|
|
4
|
+
|
|
5
|
+
Modules: `sky()` (draws day/night from `engine.calendar`, sun and moon, fog; the time itself is `calendar()`, recipe 06), `weather()` (needs sky; the game's weather types, smooth transitions, rain and snow,
|
|
6
|
+
lightning). All look data lives in the style; the engine has only a neutral fallback.
|
|
7
|
+
|
|
8
|
+
```js
|
|
9
|
+
// 1. keyframes (default): style.sky.keyframes / style.exposure lists drive the day; nothing to write
|
|
10
|
+
// 2. a function of the frame context, fed by one call: any key marked fn (fog color / near / far / density, sky top / horizon / backdrop, lights, exposure)
|
|
11
|
+
engine.look.fog.set({ color: ({ state }) => state.boss ? '#400' : 'horizon' }); engine.look.state({ boss: true });
|
|
12
|
+
// 3. your own three.js sky (three/addons Sky, a ShaderMaterial dome, a skybox): never written; time / weather keep flowing through engine.uniforms
|
|
13
|
+
engine.look.sky.replace(mySky); mySky.material.uniforms.sunPosition = engine.uniforms.uSunDir; // the same Vector3, refreshed every frame
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
WebGPU (recipe 56): same dome and fog kinds as node materials. Hooks take `{ glsl, tsl: (ctx) => vec4 }` ([52](52-look.md#tsl-forms)); GLSL alone throws `[webgpu-needs-tsl]`. Own sky: three's `SkyMesh` via `look.sky.replace`.
|
|
17
|
+
|
|
18
|
+
The sky follows one contract: **inputs** `{ time, weather, season, day, state, sky }` (state = what the game gave `engine.look.state(...)`),
|
|
19
|
+
**outputs** sun direction / color / intensity, hemisphere, fog, environment, exposure and background, plus the shared `engine.uniforms`
|
|
20
|
+
(`uSunDir`, `uDaylight`, `uTimeOfDay`, `uWind`, `uCloud`, season tints) and events (`day:start`, `season:change`, `weather:change`) that wind,
|
|
21
|
+
rain and vegetation read. The keyframes are only the default implementation: a function replaces one key, `replace` the whole dome, and
|
|
22
|
+
everything else keeps running (`replace` swaps the one thing a part draws; the whole sky module with time, lights and fog is
|
|
23
|
+
`engine.use(mySky(), { replaces: 'sky' })`, recipe 52 [verbs](52-look.md#verbs)). The function gets `{ time, weather, season, day, state, sky }`: write `({ sky }) => sky.isDay ? ...`.
|
|
24
|
+
|
|
25
|
+
### Your own sky object: what `look.sky.replace(obj)` does with it
|
|
26
|
+
The engine hides its dome, adds `obj` to the scene root when it has no parent yet (and removes it again on `replace(null)` only then), and from
|
|
27
|
+
then on **never moves, scales or writes it**: it does not follow the camera, is not scaled to the far plane and is not exempted from culling.
|
|
28
|
+
(The built-in dome does all three itself: an `onBeforeRender` copies the camera position and scales it to `0.9 × camera.far`.) So a dome of
|
|
29
|
+
your own must, on its own:
|
|
30
|
+
|
|
31
|
+
- **contain the camera and stay inside the far plane**: either a fixed sphere big enough for everywhere the camera goes (radius < `camera.far`,
|
|
32
|
+
which the engine pulls in to the view range unless you take it: `engine.look.view.manual('far')`), or one that follows the camera; or skip
|
|
33
|
+
depth altogether as below, so the radius no longer matters;
|
|
34
|
+
- **compute the view direction per pixel from world space**: pass `worldPosition - cameraPosition` (linear, safe to interpolate) as the
|
|
35
|
+
varying and do every non-linear step (normalize, `atan`, projecting onto a cloud plane, noise) in the fragment shader. A direction taken from
|
|
36
|
+
the vertex's local `position`, or a non-linear value computed per vertex, is wrong once the dome is off-centre or its triangles are big:
|
|
37
|
+
that is where arcs bend and seams show at the corners of the sphere's faces;
|
|
38
|
+
- draw behind everything: `gl_Position = clip.xyww` (depth 1), `depthWrite: false`, `frustumCulled = false`, `renderOrder` well below the scene,
|
|
39
|
+
`side: THREE.BackSide`, `fog: false`.
|
|
40
|
+
|
|
41
|
+
```js
|
|
42
|
+
const sky = new THREE.Mesh(new THREE.SphereGeometry(1, 32, 16), new THREE.ShaderMaterial({
|
|
43
|
+
side: THREE.BackSide, depthWrite: false, depthTest: false, fog: false,
|
|
44
|
+
uniforms: { uTop: { value: new THREE.Color('#3b6fb6') }, uLow: { value: new THREE.Color('#cfe3f2') } },
|
|
45
|
+
vertexShader: /* glsl */`
|
|
46
|
+
varying vec3 vDir;
|
|
47
|
+
void main() {
|
|
48
|
+
vec4 w = modelMatrix * vec4(position, 1.0);
|
|
49
|
+
vDir = w.xyz - cameraPosition; // linear: interpolates correctly; normalize in the fragment shader
|
|
50
|
+
gl_Position = (projectionMatrix * viewMatrix * w).xyww; // depth 1: never clipped by far, never in front of anything
|
|
51
|
+
}`,
|
|
52
|
+
fragmentShader: /* glsl */`
|
|
53
|
+
uniform vec3 uTop, uLow; varying vec3 vDir;
|
|
54
|
+
void main() {
|
|
55
|
+
vec3 d = normalize(vDir);
|
|
56
|
+
gl_FragColor = vec4(mix(uLow, uTop, smoothstep(0.0, 0.6, d.y)), 1.0);
|
|
57
|
+
#include <colorspace_fragment>
|
|
58
|
+
}`,
|
|
59
|
+
}));
|
|
60
|
+
sky.frustumCulled = false; sky.renderOrder = -1000;
|
|
61
|
+
sky.onBeforeRender = (r, s, cam) => { sky.position.copy(cam.position); sky.updateMatrixWorld(); }; // centred on the camera: any radius works
|
|
62
|
+
engine.look.sky.replace(sky);
|
|
63
|
+
```
|
|
64
|
+
Time of day still reaches it through `engine.uniforms` (`uSunDir`, `uDaylight`, `uTimeOfDay` ...): put them in its `uniforms` to follow the day.
|
|
5
65
|
|
|
6
66
|
## 1. Switching weather / automatic weather (main.js)
|
|
7
67
|
```js
|
|
8
|
-
engine.weather.set('rain', 20); // transition to rain over 20 seconds (a type of the game's table, see 2)
|
|
68
|
+
engine.weather.set('rain', { seconds: 20 }); // transition to rain over 20 seconds (a type of the game's table, see 2)
|
|
69
|
+
engine.weather.set('storm', { seconds: 0 }); // at once: the full storm before the next step (a screenshot or test right after the call)
|
|
9
70
|
engine.weather.setAuto(true); // change weather at random (openWorld({ camera: 'follow', autoWeather: true }) also works)
|
|
10
71
|
engine.events.on('weather:lightning', () => { /* thunder */ });
|
|
11
72
|
```
|
|
@@ -14,61 +75,109 @@ engine.events.on('weather:lightning', () => { /* thunder */ });
|
|
|
14
75
|
`weather({ types })` is the whole list of the game's weather; without it there is only a calm `clear` (the engine assumes no climate). Seven temperate
|
|
15
76
|
ones (clear cloudy overcast rain storm snow fog) are an opt-in preset: `weather(presets.weather.temperate)`; extend with
|
|
16
77
|
`types: { ...presets.weather.temperate.types, dust: {...} }`.
|
|
17
|
-
|
|
78
|
+
The preset supplies types and an `autoPool`; the weather changes by itself only with `auto: true` (or `engine.weather.setAuto(true)`). To pin one
|
|
79
|
+
for a picture: `engine.weather.set('clear')`, or a shot's `--weather clear` (it also turns `auto` off); a shot prints the weather under the picture.
|
|
80
|
+
Left-out fields are calm (no cloud, rain, snow, grey, lightning; sun, fog, wind 1). The style's `style.weather.types` only fills fields the game's
|
|
81
|
+
table leaves out, for types the game has (the table's own numbers win, a preset counts as the game's). There is no patch option for one field
|
|
82
|
+
of a preset type: spread that one type, `const T = presets.weather.temperate.types; weather({ types: { ...T, rain: { ...T.rain, fog: 0.5 } } })`.
|
|
18
83
|
```js
|
|
19
84
|
import { createEngine, presets, sky, weather } from 'threedog';
|
|
20
85
|
engine.use(sky(), weather({
|
|
21
86
|
types: { clear: { cloud: 0.1 }, dust: { cloud: 0.5, sun: 0.6, fog: 0.35, wind: 2.2, grey: 0.4, heat: 1 } }, // heat: a field of the game's own, blends too
|
|
22
87
|
autoPool: ['clear', 'clear', 'dust'], // candidates for automatic weather (repeats = higher probability; default: each type once)
|
|
23
88
|
}));
|
|
24
|
-
engine.weather.set('dust', 15); engine.weather.current.heat; // 0..1 during the change
|
|
89
|
+
engine.weather.set('dust', { seconds: 15 }); engine.weather.current.heat; // 0..1 during the change
|
|
25
90
|
```
|
|
26
91
|
Fields: `cloud` cloud cover 0-1, `sun` sunlight multiplier, `fog` fog distance multiplier (smaller = denser fog), `wind` wind strength, `rain`/`snow`
|
|
27
92
|
0-1, `grey` how gray the sky turns, `lightning` lightning. A table where nothing rains or snows builds no particles.
|
|
28
93
|
With openWorld the weather module is already installed; pass its options through the preset: `openWorld({ camera: 'follow', weather: { types, autoPool } })`.
|
|
29
94
|
|
|
30
|
-
## 3. Changing sky colors, sun, stars (style
|
|
31
|
-
`sky.keyframes` in the style
|
|
32
|
-
`[time 0-1, zenith color, horizon color (= fog color), sunlight color, sunlight intensity, ambient intensity]`, interpolated by time;
|
|
33
|
-
|
|
34
|
-
|
|
95
|
+
## 3. Changing sky colors, sun, stars (style)
|
|
96
|
+
`sky.keyframes` in the style (your pack's `index.js`):
|
|
97
|
+
`[time 0-1, zenith color, horizon color (= fog color), sunlight color, sunlight intensity, ambient intensity]`, interpolated by time; the rows
|
|
98
|
+
run from time 0 to time 1 (both midnight: the first row at 0, the last at 1 with the same values), else the sky throws. What each column drives
|
|
99
|
+
(and which light carries the moonlight) is in `api/style.md` under `keyframes`;
|
|
100
|
+
also `sunSize sunGlow moonSize starDensity clouds skybox shadow` (defaults and ranges in `api/style.md` too; `hoursPerDay` is timing, so it is a
|
|
101
|
+
`calendar()` option, not a style key). At run time every look key of `style.sky` is a `look.sky` param, one entry per value:
|
|
102
|
+
`engine.look.sky.set({ keyframes, moonSize, starScale, orbitTilt, dim: { stars: false } })`, a panorama is `engine.look.sky.replace('pano')`.
|
|
103
|
+
`sky()` takes only how the game lights its world (`time`, `fog`, `sun`, `hemisphere`, plus the `shadow` / `environment` blocks); `sky({ moonSize })`
|
|
104
|
+
throws naming the `look.sky.set` call.
|
|
105
|
+
**Day and night brightness** come from two columns: sunlight intensity and ambient intensity. With no `sky.keyframes` the sky uses a neutral gray
|
|
106
|
+
curve (night from 19:12 to 04:48, moonlight 0.4, ambient 0.35 against 3 / 1.2 at noon). The ambient column is the whole diffuse fill: the engine's neutral room
|
|
107
|
+
environment (the light Standard / Lambert / Phong materials get from `scene.environment`) takes the share `look.lights` `env.share` (0..1) of
|
|
108
|
+
it and the hemisphere light the rest, so a dark-night pack is dark on PBR surfaces too and the sun keeps its contrast by day. `env.intensity` keeps
|
|
109
|
+
one meaning, the absolute `scene.environmentIntensity`: a game or pack that writes it under a sky gets that value as written (fixed, not following
|
|
110
|
+
the day; the hemisphere light then keeps the whole budget, `describe().look.env.source.mode` `'absolute'`). `describe().look.env.source` says which map lights
|
|
111
|
+
them (`room` / `sky` / `asset:<name>` / `game`) and `followsTime`; `look.env.replace('sky')` builds it from the dome instead (outdoor reflections
|
|
112
|
+
show the sky, not a studio; it darkens by itself), an asset map is a fixed photo and does not follow. Check with `shot --time 12:00` and `--time 22:00`.
|
|
113
|
+
The look of rain and snow is in `style.weather.rain / snow` (shape, density, shaders, the game's own particles: recipe 44).
|
|
114
|
+
|
|
115
|
+
### Sky color for my shader (horizon color, zenith color)
|
|
116
|
+
A shader of your own that should meet the sky (a sea fading to the horizon, distant cards, a reflection) reads the colors the sky draws this frame:
|
|
117
|
+
`engine.uniforms.uSkyHorizon` and `engine.uniforms.uSkyTop` (`THREE.Color`, linear). They hold the keyframes, a `look.sky.set({ top, horizon })`,
|
|
118
|
+
the weather's grey tint and lightning; with `style.sky.backdrop` the horizon is the backdrop color. The fog in its default color (`'horizon'`) is
|
|
119
|
+
this same color every frame, at night and in rain too; it differs only when the game sets `look.fog.set({ color })`, or takes the fog
|
|
120
|
+
(`look.fog.manual()`, `scene.fog = ...`). Share the object, do not copy it in `onFrame`: `onFrame` runs before the sky updates, so a copy is one
|
|
121
|
+
frame old (after a time jump, the first picture shows the old hour's color).
|
|
122
|
+
```js
|
|
123
|
+
const sea = new THREE.ShaderMaterial({ uniforms: { uHorizon: engine.uniforms.uSkyHorizon, uTop: engine.uniforms.uSkyTop, uSunDir: engine.uniforms.uSunDir },
|
|
124
|
+
fragmentShader: '... gl_FragColor = vec4(mix(base, uHorizon, fresnel), 1.0); #include <tonemapping_fragment> #include <colorspace_fragment>' /* ... */ });
|
|
125
|
+
engine.uniforms.uSkyHorizon.value.getHexString(); // read it in JS too (game logic, a HUD swatch)
|
|
126
|
+
```
|
|
127
|
+
`look.sky.value('horizon')` is the override a game set (`null` = the keyframes), not the drawn color.
|
|
35
128
|
|
|
36
129
|
## 4. Time and brightness (game code)
|
|
37
130
|
```js
|
|
38
|
-
engine.
|
|
39
|
-
engine.clock.
|
|
40
|
-
engine.look.fog.set({ far: 300 }); // base fog distance (meters); weather
|
|
131
|
+
await engine.skip({ to: '19:30' }); // jump forward to a time: timers, calendar.at / daily, day:start fire on the way (needs a calendar dayLength; recipe 06)
|
|
132
|
+
engine.mod('clock.rate', { owner: 'game', set: 0 }); // the calendar and calendar seconds stop together, so the sky stops moving (set: 2 = double speed; remove() undoes it); game seconds per day: calendar({ dayLength: 600 }); the three kinds of time are in recipe 06
|
|
133
|
+
engine.look.fog.set({ far: 300 }); // base fog distance (meters); weather multiplies it; terrain({ viewFog: true }) writes the layer below
|
|
41
134
|
```
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
`sky(
|
|
46
|
-
|
|
47
|
-
|
|
135
|
+
**The sky draws the calendar's time; it does not own it.** Day, time of day and seasons are the `calendar()` module (recipe 06 "The time table");
|
|
136
|
+
the sky reads `engine.calendar.timeOfDay` each frame to place the sun and blend the keyframes, and `engine.calendar.season` for the season tint.
|
|
137
|
+
Without a calendar, `sky({ time: '18:30' })` draws that one fixed time (an arena, a museum diorama, a space station window); with a calendar,
|
|
138
|
+
`sky({ time })` throws (start the day with `calendar({ time })`). A game that draws its own sky (a skybox shader, a 2D painted backdrop) keeps the
|
|
139
|
+
calendar and reads it the same way; a game indoors keeps the calendar and installs no sky.
|
|
140
|
+
Fixed dusk in an open world: `openWorld({ time: 18.5 / 24, ... })` (a 0-1 fraction of the day; goes to the calendar) and do not pass
|
|
141
|
+
`calendar: presets.calendar.cycle` (the template does; the cycle is what moves the clock). `engine.sky.isDay` is `sunHeight > 0` with `sunHeight = sin((timeOfDay - 0.25) * 2π)`: true strictly between timeOfDay 0.25 and 0.75 (06:00 to 18:00 on the default 24-hour face; with `hoursPerDay: H` the same fractions, 0.25H to 0.75H), false at exactly 06:00 and 18:00, so 18:30 already reads as "night" in `describe().time.isDay`. `daylight` = `max(0, sunHeight)`. Keyframes only change colors, not this flip.
|
|
142
|
+
`engine.calendar.isDay` / `daylight` are the same formula from the clock (they work with no sky); the sky's are what it draws (its fixed time without a calendar).
|
|
143
|
+
A day-night cycle is `calendar({ dayLength: 360 })` or `calendar(presets.calendar.cycle)` (`presets.calendar.fourSeasons` includes it);
|
|
144
|
+
`hoursPerDay` changes the clock face. An audio rule's `time` condition (from the calendar) takes `'day'`, `'night'` or a range `['18:00', '06:00']`;
|
|
145
|
+
anything else warns once.
|
|
146
|
+
Seasons are off by default (`engine.calendar.season` is `null`, no `season:change`); name them to turn them on:
|
|
48
147
|
```js
|
|
49
|
-
|
|
50
|
-
|
|
148
|
+
calendar({ seasons: ['spring', 'summer', 'autumn', 'winter'], daysPerSeason: 28, dayLength: 360 }); // days advance only with a dayLength; or the preset: openWorld({ camera: 'follow', calendar: presets.calendar.fourSeasons })
|
|
149
|
+
calendar({ seasons: [{ name: 'wet', days: 10 }, { name: 'dry', days: 20 }], dayLength: 360 }); // seasons of their own length
|
|
51
150
|
```
|
|
52
|
-
**
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
151
|
+
**A direct write to** `engine.lights.sun.intensity / color`, `engine.lights.hemi` or `scene.fog` **takes that value over**: the sky stops writing it and
|
|
152
|
+
keeps yours, so the day cycle no longer changes it (warned once). To adjust and keep the cycle: `engine.look.lights.set(...)` / `look.fog.set(...)` or a
|
|
153
|
+
modifier layer below; to take it on purpose: `engine.look.lights.manual('sun')` (recipe 52 "Who writes it").
|
|
154
|
+
To darken or tint everything (a cave, a horror segment), add multipliers of your own on the look values; they stack with the weather's without
|
|
155
|
+
overwriting it ([recipe 52](52-look.md#how-look-values-stack)):
|
|
56
156
|
```js
|
|
57
|
-
engine.
|
|
58
|
-
engine.
|
|
59
|
-
engine.sky.
|
|
157
|
+
const cave = [engine.mod('look.lights.sun.intensity', { owner: 'cave', mul: 0.3 }), engine.mod('look.lights.hemi.intensity', { owner: 'cave', mul: 0.4 }),
|
|
158
|
+
engine.mod('look.fog.far', { owner: 'cave', mul: 0.5 }), // enter the cave: entries multiply
|
|
159
|
+
engine.mod('look.sky.tint', { owner: 'cave', value: { color: 0x402030, amount: 0.5 } })]; // amount = zenith, horizon: = horizon
|
|
160
|
+
cave.forEach(h => h.remove()); // leave the cave
|
|
60
161
|
```
|
|
61
|
-
|
|
62
|
-
the
|
|
63
|
-
|
|
64
|
-
|
|
162
|
+
These are ordinary shared points (recipe 55): the light and fog values multiply, `look.sky.flash` adds, `look.sky.tint` / `look.ground.cover`
|
|
163
|
+
entries blend weighted by their amount, `{ for: 3 }` ends one by itself. A game's own `look.lights.set({ sun: { intensity: 3 } })` is the base they
|
|
164
|
+
multiply: rain still dims it and the sunset still fades it (`engine.describe().shared['look.lights.sun.intensity'].how` says `arena 3 × weather 0.6`).
|
|
165
|
+
Write once and it stays in effect; no need to write every frame. For a gradual change, write a new value every frame.
|
|
65
166
|
|
|
66
167
|
## 5. Verify
|
|
67
168
|
- Text: `npm run shot -- / --time 19:30 --weather dust --wait 2 --describe-only`, then look for "Time: 19:30..." and "Weather: dust (rain 0, snow 0, fog 0.35)".
|
|
68
|
-
`describe().weather` has `name progress rain snow fog wind cloud`; `describe().time` has `clock day season isDay dayLength
|
|
169
|
+
`describe().weather` has `name progress rain snow fog wind cloud`; `describe().time` has `clock day season isDay dayLength rate`.
|
|
69
170
|
- Take a screenshot only after the look changed: `npm run shot -- / --time 19:30 --weather dust`.
|
|
70
171
|
|
|
71
172
|
## 6. Day and night in game logic
|
|
72
|
-
|
|
73
|
-
yourself, so a game with different day lengths or
|
|
74
|
-
(its page: `api/
|
|
173
|
+
Gameplay reads day and night from the calendar: test `engine.calendar.isDay`, and fade with `engine.calendar.daylight` (0-1); they work with or
|
|
174
|
+
without a sky. Don't decide it from the clock text yourself, so a game with different day lengths or hours stays right. Lights and shop doors that
|
|
175
|
+
follow the time of day use `engine.calendar.between(...)` (its page: `api/calendar.md`).
|
|
176
|
+
|
|
177
|
+
## 7. Wet roads and puddles after rain
|
|
178
|
+
The engine gives the rain, not the wet look: `engine.weather.current.rain` (0-1) is the signal; what gets wet, how fast it dries and where
|
|
179
|
+
puddles collect are the game's decisions. Water fills the pores of a rough surface, so wet reads as darker and glossier together (lower `color`
|
|
180
|
+
and `roughness`); darker alone reads as dirt or shadow. Gloss only shows when there is something bright to reflect: the sky by day, at night
|
|
181
|
+
the lamps and windows as long streaks. A puddle needs a soft-rimmed mask; a hard cut-off makes opaque discs that read as holes. Judge it on a
|
|
182
|
+
shot at noon and at night, in rain and after. To compare with your own result afterwards, the technique example `wet-road`
|
|
183
|
+
(`threedog examples pull wet-road`) shows one way, with a dry-out delay in game time.
|
|
@@ -1,73 +1,103 @@
|
|
|
1
|
-
#
|
|
1
|
+
# The game's style folder: changing the art
|
|
2
2
|
|
|
3
|
-
**
|
|
3
|
+
**In this recipe**: 0. Using a style · 0b. Composing a style from parts · 0c. What a style may not hold · 0d. Look plugins in a style folder · 1. Creating a new style ·
|
|
4
|
+
1b. Lights and stalls · 2. Using your own models instead of procedural ones · 2b. Wind, cloud shadows and season tint on your own… ·
|
|
5
|
+
3. When the engine gets a new "look parameter" · 4. Verify · 5. Sounds and music
|
|
6
|
+
|
|
7
|
+
**The engine ships no art.** No default style, character model, terrain look or terrain generator: with no style and no model everything is a
|
|
4
8
|
plain neutral placeholder (a gray capsule for characters, a gray box for props and pickups, flat gray ground at y = 0, one white hemisphere light plus
|
|
5
9
|
one neutral directional light without shadows or tone mapping), and the console says once in dev what is missing and how to fix it.
|
|
6
10
|
|
|
7
|
-
A style
|
|
11
|
+
A game's style is a plain object its `style/` folder exports, passed in as `createEngine({ style })`. It holds **looks only**: colors,
|
|
8
12
|
materials and shaders, sky and lighting, post effects, UI look. Not part of it: model / texture / sound files and procedural models content names (an
|
|
9
13
|
**asset pack**, `engine.assets.manifest`, recipe 05 "Asset packs"), sounds (section 5), gameplay data and timing (a **content pack**, recipe 20;
|
|
10
|
-
`
|
|
11
|
-
entry can be omitted; omitted entries are the neutral placeholders above (the city example passes no style
|
|
14
|
+
`calendar({ hoursPerDay })`). Which key is read by whom is in the "style keys" table of `../CODEMAP.md`; the field list is in `../api/style.md`. Every
|
|
15
|
+
entry can be omitted; omitted entries are the neutral placeholders above (the city example passes no style at all). Write it as a plain object literal, no `@type` or `as const`: fields with a fixed set of words (`shading`, `mode`, `type` …) accept any string in the types, and a wrong word is reported by `threedog style check` with the fix.
|
|
12
16
|
|
|
13
|
-
## 0. Using a style
|
|
14
|
-
A
|
|
15
|
-
realistic, toon, pixel, painterly, flat, noir. The engine ships none
|
|
17
|
+
## 0. Using a style
|
|
18
|
+
A game keeps its style in its `style/` folder (`style/index.js`; a new game starts with an empty one). Any art
|
|
19
|
+
direction fits: realistic, toon, pixel, painterly, flat, noir. The engine ships none (section 1).
|
|
16
20
|
```js
|
|
17
21
|
import { createEngine, presets, openWorld } from 'threedog';
|
|
18
|
-
import
|
|
22
|
+
import style from './style/index.js'; // the game's own look
|
|
19
23
|
import { terrainPreset, terrainStrings } from '@threedog/terrain-noise'; // the world shape is not a look: its own package
|
|
20
|
-
const engine = createEngine({ canvas, style
|
|
24
|
+
const engine = createEngine({ canvas, style, strings: terrainStrings }); // terrainStrings: names of the preset's ground types
|
|
21
25
|
engine.use(openWorld({ camera: 'follow', seed: 7, terrain: terrainPreset() })); // noise terrain (hills, rivers, biomes) that your pack colors, see recipes/28
|
|
22
26
|
```
|
|
23
|
-
|
|
24
|
-
`@threedog/post-effects
|
|
25
|
-
`terrainStrings` is a separate package, `@threedog/terrain-noise`: the shape of the world is gameplay, so a style
|
|
27
|
+
Procedural models are an asset pack, not part of the style (`engine.assets.manifest(assets)`; the world example keeps its in `examples/world/art/`). Post effects such as `bloom` / `ao` / `outline` come from
|
|
28
|
+
`@threedog/post-effects`. The terrain generator `terrainPreset` / `riverAt` / `BIOMES` /
|
|
29
|
+
`terrainStrings` is a separate package, `@threedog/terrain-noise`: the shape of the world is gameplay, so a style keeps only the colors of its
|
|
26
30
|
ground types (`terrain.colors`, `biomeColors`).
|
|
27
31
|
|
|
28
32
|
## 0b. Composing a style from parts
|
|
29
33
|
`style` may be a list of parts, deep-merged left to right into `engine.style`, so one pack's materials, another pack's sky and the game's own colors
|
|
30
34
|
mix without copying whole packs:
|
|
31
35
|
```js
|
|
32
|
-
import
|
|
36
|
+
import base from './style/index.js';
|
|
33
37
|
const dusk = { sky: { sunSize: 600, keyframes: myDuskKeyframes } }; // only these two sky fields change
|
|
34
|
-
const engine = createEngine({ canvas, style: [
|
|
38
|
+
const engine = createEngine({ canvas, style: [base, dusk, { ui: { accent: '#7fd3ff' }, post: null }] });
|
|
35
39
|
```
|
|
36
40
|
Rules (`core/styleParts.js`): plain `{ }` objects merge key by key at every depth; everything else replaces whole (arrays such as `sky.keyframes` and
|
|
37
41
|
`post`, functions, three.js objects); a key set to `null` removes it; `undefined` is ignored; nested lists flatten, so a pack can itself be a list of
|
|
38
42
|
parts; parts are never mutated. One object (not a list) is used as it is.
|
|
43
|
+
The merged style is the **style layer** of every look value (recipe 52 "How look values stack"): later parts win there and two parts never
|
|
44
|
+
conflict; a game's `look.<part>.set(...)` sits on top of it, and the weather and the sunset multiply whichever decides. A style starts the fog
|
|
45
|
+
distance (`sky.fog.far`) and the shadow filter (`sky.shadow.type`); there are no `createEngine` options for them.
|
|
39
46
|
|
|
40
|
-
**Post effects
|
|
41
|
-
(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
import { bloom } from '@threedog/post-effects';
|
|
46
|
-
createEngine({ canvas, style: [basePack, postAdd(myGrain, bloom({ strength: 0.6 })), postRemove('ao')] });
|
|
47
|
-
```
|
|
48
|
-
`postAdd(...effects)` appends; an effect whose `name` is already in the list (`'bloom'`, `'ao'`, `'outline'`) replaces that one in place.
|
|
49
|
-
`postRemove(...names)` drops effects by name. `{ post: null }` still clears the list; `{ post: [...] }` still replaces it whole.
|
|
47
|
+
**Post effects are plugins.** A style brings each post effect as a file in its `style/plugins/` folder (`10-bloom.js: export default bloom()`,
|
|
48
|
+
listed with `plugins: import.meta.glob('./plugins/*.js', { eager: true })`), the same file a game's `plugins/` folder takes: both go through
|
|
49
|
+
`engine.look.post.add`, the one way into the chain (recipe 52). Each part's plugins stay grouped under the part's name, so one pack's effect is
|
|
50
|
+
switched off with `engine.plugins.off('<pack>/<file>')` or `look.post.set({ bloom: false })`, and `plugins: null` drops the earlier parts' plugins.
|
|
51
|
+
There is no `style.post` list (it was a second way in, with its own on / off rules).
|
|
50
52
|
|
|
51
53
|
**Retinting the procedural models.** `style.palette` holds the colors the trees, rocks, grass and flowers are built from (the keys are the pack's own, e.g. `bark`, `leaf`, `rock`,
|
|
52
|
-
`grassTip`...; see `
|
|
53
|
-
`style: [
|
|
54
|
+
`grassTip`...; see `base.palette`). One part changes them all:
|
|
55
|
+
`style: [base, { palette: { leaf: 0xd98a3a } }]` (autumn); keys left out keep the base colors. A generator of your own written
|
|
54
56
|
with `function` (not an arrow) reads `this.palette`; the palette is part of the model cache key, so a changed palette rebuilds. `.glb` files and
|
|
55
57
|
models baked earlier keep their colors.
|
|
56
58
|
|
|
57
59
|
## 0c. What a style may not hold
|
|
58
60
|
Swapping the style must never change the map or the rules, only how they look. So these are **not** style fields, and a dev run throws an error
|
|
59
61
|
naming where each goes:
|
|
60
|
-
- water level, whether there is a sea, the water mesh size: `style.water.level / sea / size` -> `engine.use(water({ level, sea, size }))
|
|
62
|
+
- water level, whether there is a sea, the water mesh size: `style.water.level / sea / size` -> `engine.use(water({ level, sea, size }))`.
|
|
63
|
+
The other way round, a look value is never a module option: water color, waves, normal map (`style.water.*`), sky keyframes, sun, moon, stars
|
|
64
|
+
(`style.sky.*`) and terrain `normals` (`style.terrain.config.normals`) are set in the style, and at run time with `engine.look.water` /
|
|
65
|
+
`look.sky` / `look.ground` `.set(...)`; `water({ color })`, `sky({ moonSize })`, `terrain({ normals })` throw naming that call
|
|
61
66
|
- terrain shape and size (seed, chunk size, resolution, water level, height functions): `style.terrain.config.*` -> `terrain({ ... })`. The looks
|
|
62
67
|
in `terrain.config` are `shading` (`'smooth'` | `'texture'` | `'flat'`), `colorResolution`, `normals` and `normalFn` (recipe 37); at run time
|
|
63
68
|
`engine.look.ground.set({ shading, colors, variation, detail })` (recipe 52)
|
|
64
69
|
Quality settings are not world state and may stay in a style (shadow `mapSize` and `low` overrides, water `segments`); players can override them in
|
|
65
|
-
settings.
|
|
70
|
+
settings. A game's `style/` folder is also checked by `threedog check` (R34).
|
|
66
71
|
|
|
67
|
-
##
|
|
68
|
-
|
|
72
|
+
## 0d. Look plugins in a style folder
|
|
73
|
+
One folder = one style: starting values, the material per role, and optional look plugins. A plugin is a file exporting the same shapes as the
|
|
74
|
+
game's `plugins/` folder (recipe 40 §1): a three.js `Pass`, a `Material` (its `name` is the role), a material patch `{ slot, glsl, roles }` (plugged with `look.materials.add`),
|
|
75
|
+
an `Object3D`, or a look module (a sky or vegetation look with `replaces`). The style lists them in `plugins`, and the engine plugs them through
|
|
76
|
+
`engine.plugins`, the same loader as the game's folder, so a plugin file works alone in `plugins/` or inside any number of style folders unchanged:
|
|
77
|
+
```js
|
|
78
|
+
// style/index.js style/plugins/10-paper.js: export default new ShaderPass(PaperShader)
|
|
79
|
+
export default { // style/plugins/20-stone.js: export default Object.assign(new THREE.MeshToonMaterial({ color: 0x777777 }), { name: 'stone' })
|
|
80
|
+
name: 'ink', exposure: 1.1, materials: { wood: { type: 'lambert', color: 0x8a5a36 } },
|
|
81
|
+
plugins: import.meta.glob('./plugins/*.js', { eager: true }), // without Vite: { paper: { default: paperPass } }
|
|
82
|
+
};
|
|
83
|
+
```
|
|
84
|
+
They sit **under** the game: a style plugin's material and patch are on the style layer of `engine.look.materials`, so the game's
|
|
85
|
+
`look.materials.set / replace` and the game's own plugins win. Names are `<style>/<file>` (`ink/10-paper`); `engine.plugins.off('ink')` takes
|
|
86
|
+
all of the style's plugins out, `off('ink/10-paper')` one; `describe().slots` lists them with `style ink: plugins/...`. `off('ink')` turns off
|
|
87
|
+
the pack's **plugins only**: its starting values (`exposure`, `fog`, the `materials` table and the other fields of `style/index.js`) are the
|
|
88
|
+
style itself and stay; the `off()` result and the off rows of `describe().slots` say so. To drop those too, start with another style.
|
|
89
|
+
Each plugin is its own owner (`style:ink/10-paper`), the pack only groups them: switching one off takes out only what that file wrote, and
|
|
90
|
+
the others keep theirs. Two plugins that write the same key on the same layer (two Materials named `stone`) are a `shared-conflict` naming
|
|
91
|
+
both files in development; to let one win on purpose, say so in that file: `export const replaces = '10-stone';` (the other is unplugged
|
|
92
|
+
while this one is on, and comes back when it goes off; `plugins.list()` shows `replacedBy`). In a list of parts each
|
|
93
|
+
part's plugins stay under that part's name, and `{ plugins: null }` drops the earlier parts'. The personal library (`threedog lib`) stores a
|
|
94
|
+
plugin once; `lib pull` puts its code in `plugins/<name>/` with the wiring file `plugins/<name>.js`, and copying both into a style folder's `plugins/` is all it takes to bundle it.
|
|
95
|
+
|
|
96
|
+
## 1. Creating a new style
|
|
97
|
+
Edit your game's `style/index.js` (`threedog new-game` makes it empty, every key commented out; fill one section at a time). To try a second look,
|
|
98
|
+
copy the folder (`style-toon/`) and point `createEngine` at it; `threedog style check style-toon` (a folder path; with no argument it checks the game's `style/`) finds mistakes before you look at pixels:
|
|
69
99
|
```js
|
|
70
|
-
import toon from './style/index.js';
|
|
100
|
+
import toon from './style-toon/index.js';
|
|
71
101
|
const engine = createEngine({ canvas, style: toon });
|
|
72
102
|
```
|
|
73
103
|
**A material role is a free label inside the style, not a fixed list.** `makeMaterial('anything', { color })` is always legal: a role the style does not
|
|
@@ -77,20 +107,21 @@ warns only when a name looks like a typo of a known role (`'buidling'`).
|
|
|
77
107
|
Keys you will change most often:
|
|
78
108
|
| Key | What it controls |
|
|
79
109
|
|---|---|
|
|
80
|
-
| `materials` | The material per role. Three forms: a spec `{ default: { type: 'toon', steps: 3 }, water: { type: 'phong', shininess: 90 } }` (lambert / phong / standard / physical / toon / basic; a wrong type throws), any three.js material instance `water: new THREE.MeshMatcapMaterial({ matcap })` (cloned per use), or a function `prop: (params, role) => new THREE.ShaderMaterial({...})`.
|
|
110
|
+
| `materials` | The material per role. Three forms: a spec `{ default: { type: 'toon', steps: 3 }, water: { type: 'phong', shininess: 90 } }` (lambert / phong / standard / physical / toon / basic; a wrong type throws), any three.js material instance `water: new THREE.MeshMatcapMaterial({ matcap })` (cloned per use), or a function `prop: (params, role) => new THREE.ShaderMaterial({...})`. The table is the style layer of `engine.look.materials`, the one entry `makeMaterial(role)` reads: the game changes a role with `look.materials.set / replace` (recipe 52), never by editing `engine.style.materials` |
|
|
81
111
|
| `antialias` | `false` for sharp pixel edges; omitted = on for desktop, off for phones (players can switch it in settings) |
|
|
82
112
|
| `post` | List of post effects (e.g. `[outline(), ao(), bloom()]`; `outline({ enabled: true })` draws edge lines); slots, the effects package, `fuse`, outline modes: [recipe 52](52-look.md#post-effect-chain) |
|
|
83
113
|
| `sky` `weather` `water` `terrain` `seasons` `clouds` | Sky keyframes (sun color and intensity over the day, fog color, shadows), rain and snow, water, terrain colors (`terrain.colors` palette, `terrain.biomeColors` ground type -> palette names, `terrain.steep` slope colors; a type with no color is gray; `terrain.config`: `shading` `'smooth'` (engine default) | `'texture'` (per-chunk color map) | `'flat'` (facets), `colorResolution`, `normals`, `normalFn`, recipe 37; `terrain.detail` a detail layer, recipe 53; `terrain.material` swaps the whole ground material, chunks have `uv` = world xz / chunk size; `water.material: (engine, { uniforms, waves, normalMap }) => Material` swaps the whole water surface, e.g. `applyEffects(new THREE.MeshToonMaterial({ color }), { clouds: false, patches: [waves] })` keeps the built-in waves), seasonal tints |
|
|
84
114
|
| `character` | `animation.fade`: skeletal animation transition seconds. Bodies are assets, not style: `createPlayer({ model })` with a registered model, a GLB asset name or `{ rig }`; part colors are material roles or `{ colors }` per character (recipe 13). Without a model a gray capsule |
|
|
85
|
-
| `pickup` `particles` | Items on the ground (`
|
|
115
|
+
| `pickup` `particles` | Items on the ground: look values only (`color`, `size`, `lift`; the shape is an asset model name, recipe 03), particle presets (dust smoke leaves splash sparks...) |
|
|
86
116
|
| `triggers` `grid` | Tool colors, not art: trigger zone wireframe (`debugColor`), grid placement preview (`ok` / `bad`). The engine has neutral defaults (gray; light = can place, dark = cannot); a pack may recolor them |
|
|
87
117
|
| `ui` | UI colors, `font` (a CSS font-family list), `fonts` (font asset names to load at start, the files in an asset pack: recipes/05 §3b), extra `css`, `templates` that replace a whole UI piece |
|
|
88
118
|
|
|
89
119
|
## 1b. Lights and stalls
|
|
90
|
-
Every engine has `engine.lights = { sun, hemi }`, plain three.js lights. Without a style
|
|
120
|
+
Every engine has `engine.lights = { sun, hemi }`, plain three.js lights. Without a style they are a neutral placeholder (white
|
|
91
121
|
hemisphere + neutral directional light, no shadows); the look (sun color and intensity curves, sky colors, fog, shadow softness, exposure, tone
|
|
92
|
-
mapping) comes from the style
|
|
93
|
-
`engine.look.lights.set(...)` (recipe 52); to light the world yourself: recipe 38.
|
|
122
|
+
mapping) comes from the style's `sky`, `exposure` and `toneMapping`, and the sky module drives the same two lights. At run time:
|
|
123
|
+
`engine.look.lights.set(...)` (recipe 52); to light the world yourself: recipe 38. `toneMapping` is read once, when the engine creates its
|
|
124
|
+
renderer; later the curve is plain three.js (`engine.renderer.toneMapping = ...`).
|
|
94
125
|
|
|
95
126
|
three.js builds one shader program per material for each light setup. `engine.start()` compiles everything visible behind the
|
|
96
127
|
loading screen (`engine.startup.compileMs`), but adding or removing a light later, or toggling `visible` on one, changes the setup and compiles again:
|
|
@@ -112,7 +143,11 @@ const flash = engine.lightPool.add(gun.muzzle, { intensity: 0, priority: 5, dist
|
|
|
112
143
|
flash.set({ intensity: 8 }); /* next frame */ flash.set({ intensity: 0 }); // muzzle flash: no light is created
|
|
113
144
|
```
|
|
114
145
|
`engine.lightPool.usage()` (and `describe().lightPool`) lists which source each real light holds; `focus` measures from the player instead of the
|
|
115
|
-
camera. Options and handle: `../api/lightPool.md`.
|
|
146
|
+
camera. Options and handle: `../api/lightPool.md`. Windows and signs that light up at night (many materials, no real light each):
|
|
147
|
+
`engine.look.materials.glow('window', { night: 2 })` (recipe 52 "Night glow").
|
|
148
|
+
|
|
149
|
+
Top-down or side-view games whose light should spread over the floor and stop at walls (soft shadows, any number or shape of emissive
|
|
150
|
+
lights) can copy the optional 2D radiance cascades example instead: `examples/rc2d/` (README there: when it fits, cost, limits). It is not a module.
|
|
116
151
|
|
|
117
152
|
## 2. Using your own models instead of procedural ones
|
|
118
153
|
Models are assets, not style keys: content names them, an asset pack maps the names to files or generators. Register a later manifest with the same
|
|
@@ -123,17 +158,31 @@ engine.assets.manifest({ name: 'mine', models: { pine: () => myPineGeometry(), w
|
|
|
123
158
|
```
|
|
124
159
|
Vegetation takes a geometry (`geometry: await engine.assets.geometry('pine')`, the first mesh in the model) or a whole model with one material per
|
|
125
160
|
mesh, e.g. bark trunk + alpha-cut leaf cards:
|
|
126
|
-
`engine.vegetation.
|
|
161
|
+
`engine.vegetation.define('oak', { model: await engine.assets.model('oak'), wind: 0.02 })` (still one draw call per part; felling hides every part). For
|
|
127
162
|
the import workflow see `10-blender-level.md`.
|
|
128
163
|
`mergeColored(parts, { flat: false })` keeps smooth normals; UVs survive when every part has them.
|
|
129
164
|
A generator in `models` may also return an Object3D with its own materials; those are used as they are.
|
|
130
165
|
|
|
166
|
+
### 2a. Reusing art from somewhere else: copy it in, do not depend on it
|
|
167
|
+
Art code you already have (generator modules such as `art/my-crate.js` from an earlier game, a folder of your own, files someone gave you, a package
|
|
168
|
+
you installed) is reused by **copying** it into this game. The copy is the game's own: edit it freely; nothing links back and nothing updates it.
|
|
169
|
+
```sh
|
|
170
|
+
threedog art list ../earlier-game # modules, exported functions with their first JSDoc line, asset files (uses its art/ folder)
|
|
171
|
+
threedog art copy ../earlier-game crate lamp # by file or function name; none = every module
|
|
172
|
+
threedog art copy ../earlier-game crate --dry # what would be written, nothing written
|
|
173
|
+
```
|
|
174
|
+
It copies the named modules, every local file they import and every texture / model file they name ('./wood.png', `new URL(...)`, '/models/x.glb'
|
|
175
|
+
from the source's `public/`), rewrites relative import paths to the new layout (outside-the-art-folder helpers land in `art/shared/`), keeps package
|
|
176
|
+
imports and lists them, and prints the `engine.assets.manifest` lines to register the generators. An existing file with different content stops the
|
|
177
|
+
whole copy (nothing written) unless `--force`. The engine ships no art library and names no source: which art to reuse is yours to choose.
|
|
178
|
+
GLB files from Blender are copied the same way and checked with recipe 46 section 3.
|
|
179
|
+
|
|
131
180
|
## 2b. Wind, cloud shadows and season tint on your own materials
|
|
132
181
|
The engine's shader effects are named patches that work on any material that has the usual three.js chunks (WebGL only):
|
|
133
182
|
```js
|
|
134
183
|
import { applyEffects } from 'threedog';
|
|
135
184
|
const leaves = applyEffects(new THREE.MeshToonMaterial({ color: 0x5a8a3a }), { wind: 0.03, season: 'foliage' }); // clouds default on
|
|
136
|
-
engine.vegetation.
|
|
185
|
+
engine.vegetation.define('bush', { geometry, material: leaves }); // vegetation adds them itself; effects: false keeps the material untouched
|
|
137
186
|
```
|
|
138
187
|
The shadow sways with the wind automatically. Your own effect (pixel snapping, dissolve...) is a patch too, and stacks with the built-in ones and with
|
|
139
188
|
the material's own `onBeforeCompile`:
|
|
@@ -143,27 +192,27 @@ A missing `#include` anchor throws. A hand-written `ShaderMaterial` can `#includ
|
|
|
143
192
|
`render/effects.js`) with `engine.uniforms` as its uniforms.
|
|
144
193
|
`material.clone()` does not carry patches (three's `Material.copy` skips `onBeforeCompile`): a pack's Material instance in `materials` is fine
|
|
145
194
|
(`makeMaterial` keeps its patches); when you clone one yourself, apply the effects to the clone again.
|
|
146
|
-
What a patch declares (`needs`, `conflicts`, `shadow`, `cacheKey`) and the chunk names: recipe 43,
|
|
147
|
-
|
|
195
|
+
What a patch declares (`needs`, `conflicts`, `shadow`, `cacheKey`) and the chunk names: recipe 43, "Patch a slot". Textures by asset name are
|
|
196
|
+
material spec keys (recipe 48); the engine GLSL functions you can call in your own shader, and the spec keys that wire some of them in as a shortcut: recipe 43.
|
|
148
197
|
|
|
149
198
|
## 3. When the engine gets a new "look parameter"
|
|
150
|
-
Hard rule 1: a module only writes a neutral gray fallback and reads `engine.style.xxx ?? fallback`, **and the real value is added to a style
|
|
199
|
+
Hard rule 1: a module only writes a neutral gray fallback and reads `engine.style.xxx ?? fallback`, **and the real value is added to a style
|
|
151
200
|
(its `index.js`) at the same time** (with a one-line comment saying what it means),
|
|
152
201
|
and the new field gets a doc comment in `types/style.d.ts` (`docs/api/` is generated from there). Materials always go through
|
|
153
|
-
`makeMaterial('role', { color })`, leaving the surface feel to `
|
|
154
|
-
engine's pack; the free `makeMaterial()` uses the first engine created (fine for one engine, a dev warning when two packs run). Engine code and
|
|
155
|
-
go through the engine (`
|
|
202
|
+
`makeMaterial('role', { color })`, leaving the surface feel to the role in `engine.look.materials` (the style's `materials` table is its style layer). Whose style: `engine.makeMaterial('role', { color })` uses that
|
|
203
|
+
engine's pack; the free `makeMaterial()` uses the first engine created (fine for one engine, a dev warning when two packs run). Engine code and styles always
|
|
204
|
+
go through the engine (`water.material(engine, ...)`, a generator's `this.engine`), so two engines never share materials.
|
|
156
205
|
Look parameters only: a field that changes the world (a level, a size, a seed) goes to the module's options, not the style (section 0c).
|
|
157
206
|
|
|
158
207
|
## 4. Verify
|
|
159
|
-
- `npm run check`:
|
|
160
|
-
"non-gray fallback color"; the type check catches misspelled keys in the style
|
|
161
|
-
- `npm run map`: the "style
|
|
208
|
+
- `npm run check`: R14 reports "creates a material directly" in engine code (games, examples and styles are plain three.js and not checked) and R39
|
|
209
|
+
"non-gray fallback color"; the type check catches misspelled keys in the style.
|
|
210
|
+
- `npm run map`: the "style keys" table in CODEMAP is updated.
|
|
162
211
|
- Take screenshots only when the look changed, and compare two times of day: `npm run shot -- / --time 12:00`, `npm run shot -- / --time 18:30`
|
|
163
212
|
(images go to .threedog/shots/).
|
|
164
|
-
- It must still run without a style
|
|
213
|
+
- It must still run without a style: start once with `createEngine({ canvas })` and no `style` (gray placeholders, one console note per missing piece).
|
|
165
214
|
|
|
166
|
-
## 5. Sounds and music (the game's, not the style
|
|
215
|
+
## 5. Sounds and music (the game's, not the style's)
|
|
167
216
|
Sounds are game config, passed to `createEngine({ audio: { sounds, ambience, music, footsteps, levels } })` and read back as `engine.audio.config`; a
|
|
168
|
-
style
|
|
217
|
+
style carries none. The engine plays nothing the game did not name. Buses, sounds by name, the ambience rule table, music rules, footsteps and
|
|
169
218
|
ducking: `recipes/31-audio.md`.
|
|
@@ -49,8 +49,8 @@ the flat default. Rules read `engine.surface / slope / groundType`, so pick the
|
|
|
49
49
|
property, else its material name) with `rule.biomes`, and limit the scatter with `area`:
|
|
50
50
|
```js
|
|
51
51
|
engine.use(level({ url: '/models/town.glb' }), vegetation({ area: { min: [-80, -80], max: [80, 80] }, viewChunks: 3 }), collision());
|
|
52
|
-
engine.vegetation.
|
|
53
|
-
engine.vegetation.
|
|
52
|
+
engine.vegetation.define('grass', { geometry: grassGeo, nearOnly: true, rule: { perChunk: 500, biomes: { lawn: 1 } } });
|
|
53
|
+
engine.vegetation.define('tree', { model: oak, rule: { perChunk: 6, biomes: { lawn: 0.6, park: 1 }, maxSlope: 0.4, collider: 0.4 } });
|
|
54
54
|
```
|
|
55
55
|
Chunks stream around `engine.stream` sources and stay one InstancedMesh per species per chunk (LOD, shadows and felling work as on terrain:
|
|
56
56
|
`instanceAt` / `removeInstance`, saved). Collision and path planning see the trees through `engine.ground.forEachCollider`; a new level or `setGround`
|
|
@@ -58,6 +58,18 @@ re-places them; after changing a ground function behind the same provider call `
|
|
|
58
58
|
sets `minHeight / maxHeight`. Content `vegetation` works the same way. With `terrain()` installed, `vegetation()` takes no options (density and view
|
|
59
59
|
distance are terrain options). Rapier (`rigid()`) bodies collide with them too (cylinders from `engine.ground.forEachCollider`, gone when felled).
|
|
60
60
|
|
|
61
|
+
Where a species grows is decided in the same `add()` call, with up to three parts (on a level, a code-built ground or terrain alike):
|
|
62
|
+
```js
|
|
63
|
+
// rule: random scatter per chunk (above). positions: the game's own spots instead, [x, z] or [x, z, scale, yaw], planted at the ground height
|
|
64
|
+
engine.vegetation.define('hedge', { model: hedge, positions: hedgeSpots /* [[x, z], ...] from your level data */, rule: { collider: 0.5 } });
|
|
65
|
+
// densityMap: thins the rule's or the positions' result, 0..1 per spot -- a function of game data, or a gray image with the heightmap keys
|
|
66
|
+
engine.vegetation.define('weeds', { geometry: weedGeo, rule: { perChunk: 300 }, densityMap: (x, z) => farm.neglect(x, z) });
|
|
67
|
+
engine.vegetation.define('flowers', { geometry: flowerGeo, rule: { perChunk: 200 }, densityMap: { url: '/maps/flowers.png', size: [256, 256] } });
|
|
68
|
+
```
|
|
69
|
+
With `positions`, the rule keeps only what shapes an instance (`scale`, `stretch`, `sink`, `tints`, `tintJitter`, `collider`); the scatter filters
|
|
70
|
+
are refused. The id of a listed plant is its index in the list. After what a density function reads changes, call `engine.vegetation.rebuild()`.
|
|
71
|
+
A game that wants every instance under its own code still builds a plain `THREE.InstancedMesh` and adds it to the scene.
|
|
72
|
+
|
|
61
73
|
## 5. Verify
|
|
62
74
|
- `npm run assets` prints each file's size before and after compression; a browser 404 appears in `.threedog/errors.log` (asset load failure).
|
|
63
75
|
- `describe()`: `ready` is true and `loading` is empty; the player's coordinates are at the spawn point; `nearby` contains trigger zones
|