threedog 0.0.0-stage → 0.2.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 +5 -0
- package/LICENSE +21 -0
- package/README.md +39 -2
- package/core/Animator.js +268 -0
- package/core/Assets.js +256 -0
- package/core/Audio.js +267 -0
- package/core/Baked.js +72 -0
- package/core/Batching.js +247 -0
- package/core/Budget.js +221 -0
- package/core/Clock.js +94 -0
- package/core/Commits.js +77 -0
- package/core/DebugOverrides.js +143 -0
- package/core/Describe.js +145 -0
- package/core/Engine.js +184 -0
- package/core/Events.js +153 -0
- package/core/I18n.js +94 -0
- package/core/Input.js +245 -0
- package/core/Inspect.js +77 -0
- package/core/InspectScene.js +191 -0
- package/core/Jobs.js +146 -0
- package/core/Loading.js +149 -0
- package/core/MaterialInfo.js +32 -0
- package/core/Ops.js +256 -0
- package/core/Random.js +52 -0
- package/core/Rays.js +160 -0
- package/core/SaveStore.js +85 -0
- package/core/Saves.js +254 -0
- package/core/Stream.js +279 -0
- package/core/Threads.js +158 -0
- package/core/UrlState.js +94 -0
- package/core/Vars.js +35 -0
- package/core/Views.js +49 -0
- package/core/actor.js +23 -0
- package/core/assetEntry.js +89 -0
- package/core/assetLoad.js +190 -0
- package/core/assetManifest.js +35 -0
- package/core/assetReport.js +83 -0
- package/core/audioRules.js +121 -0
- package/core/audioVoice.js +225 -0
- package/core/batchGroups.js +116 -0
- package/core/canvasBox.js +63 -0
- package/core/catalog.js +169 -0
- package/core/checks.js +67 -0
- package/core/claims.js +51 -0
- package/core/dayTime.js +15 -0
- package/core/debugView.js +76 -0
- package/core/describeRender.js +45 -0
- package/core/describeText.js +143 -0
- package/core/easing.js +34 -0
- package/core/errorCodes.js +205 -0
- package/core/errorHints.js +208 -0
- package/core/errors.js +40 -0
- package/core/events.generated.js +84 -0
- package/core/ground.js +102 -0
- package/core/holds.js +106 -0
- package/core/inputContext.js +69 -0
- package/core/inputDefaults.js +22 -0
- package/core/inputPad.js +35 -0
- package/core/inputPointer.js +48 -0
- package/core/inputTouch.js +48 -0
- package/core/lifecycle.js +69 -0
- package/core/lightWatch.js +56 -0
- package/core/look/coreParts.js +112 -0
- package/core/look/layers.js +136 -0
- package/core/look/part.js +173 -0
- package/core/look/report.js +79 -0
- package/core/look/write.js +86 -0
- package/core/loop.js +200 -0
- package/core/math.js +33 -0
- package/core/modules.js +196 -0
- package/core/movement.js +19 -0
- package/core/mulberry32.js +14 -0
- package/core/opsAtomic.js +31 -0
- package/core/opsCheck.js +97 -0
- package/core/opsFail.js +20 -0
- package/core/opsGuard.js +26 -0
- package/core/opsHistory.js +27 -0
- package/core/opsRun.js +77 -0
- package/core/page.js +78 -0
- package/core/params.js +132 -0
- package/core/pureWorker.js +5 -0
- package/core/renamed.js +21 -0
- package/core/saveApply.js +128 -0
- package/core/saveFiles.js +139 -0
- package/core/saveIds.js +53 -0
- package/core/saveVersions.js +97 -0
- package/core/scatter.js +92 -0
- package/core/sceneMethods.js +100 -0
- package/core/screenToGround.js +39 -0
- package/core/services.js +73 -0
- package/core/session.js +171 -0
- package/core/shadowTypes.js +15 -0
- package/core/skip.js +104 -0
- package/core/startup.js +135 -0
- package/core/streamCells.js +24 -0
- package/core/streamSources.js +73 -0
- package/core/styleParts.js +96 -0
- package/core/targeting.js +64 -0
- package/core/thingExplain.js +68 -0
- package/core/thingOps.js +168 -0
- package/core/things.js +212 -0
- package/core/threadPure.js +120 -0
- package/core/threadServe.js +25 -0
- package/core/tier.js +11 -0
- package/core/util.js +11 -0
- package/core/validate.js +204 -0
- package/docs/AI.md +123 -0
- package/docs/API.md +83 -0
- package/docs/CODEMAP.md +347 -0
- package/docs/COMMANDS.md +108 -0
- package/docs/CONVENTIONS.md +145 -0
- package/docs/PERF.md +217 -0
- package/docs/THREE.md +86 -0
- package/docs/api/ambience.md +15 -0
- package/docs/api/assets.md +62 -0
- package/docs/api/audio.md +53 -0
- package/docs/api/budget.md +40 -0
- package/docs/api/cameraRig.md +120 -0
- package/docs/api/characters.md +144 -0
- package/docs/api/clock.md +7 -0
- package/docs/api/collision.md +39 -0
- package/docs/api/content.md +64 -0
- package/docs/api/dialogue.md +39 -0
- package/docs/api/engine.md +199 -0
- package/docs/api/entities.md +61 -0
- package/docs/api/events.md +95 -0
- package/docs/api/flow.md +27 -0
- package/docs/api/grids.md +11 -0
- package/docs/api/ground.md +16 -0
- package/docs/api/hlod.md +34 -0
- package/docs/api/hud.md +31 -0
- package/docs/api/i18n.md +10 -0
- package/docs/api/input.md +24 -0
- package/docs/api/interactions.md +31 -0
- package/docs/api/inventory.md +66 -0
- package/docs/api/jobs.md +10 -0
- package/docs/api/level.md +41 -0
- package/docs/api/lightPool.md +56 -0
- package/docs/api/music.md +34 -0
- package/docs/api/nav.md +26 -0
- package/docs/api/net.md +14 -0
- package/docs/api/openWorld.md +24 -0
- package/docs/api/particles.md +41 -0
- package/docs/api/photo.md +15 -0
- package/docs/api/post.md +10 -0
- package/docs/api/quests.md +36 -0
- package/docs/api/rays.md +26 -0
- package/docs/api/rigid.md +84 -0
- package/docs/api/saves.md +32 -0
- package/docs/api/settings.md +36 -0
- package/docs/api/sky.md +58 -0
- package/docs/api/stream.md +31 -0
- package/docs/api/style.md +134 -0
- package/docs/api/terrain.md +34 -0
- package/docs/api/timeline.md +39 -0
- package/docs/api/tools.md +57 -0
- package/docs/api/triggers.md +56 -0
- package/docs/api/vars.md +9 -0
- package/docs/api/vegetation.md +52 -0
- package/docs/api/water.md +48 -0
- package/docs/api/weather.md +29 -0
- package/docs/api/world.md +30 -0
- package/docs/recipes/01-new-game.md +148 -0
- package/docs/recipes/02-npc.md +167 -0
- package/docs/recipes/03-items-pickups.md +158 -0
- package/docs/recipes/04-quests.md +83 -0
- package/docs/recipes/05-props-bake.md +159 -0
- package/docs/recipes/06-clock-events.md +117 -0
- package/docs/recipes/07-flow-scenes-pause.md +132 -0
- package/docs/recipes/08-weather-sky.md +74 -0
- package/docs/recipes/09-style-pack.md +234 -0
- package/docs/recipes/10-blender-level.md +67 -0
- package/docs/recipes/11-vehicles.md +55 -0
- package/docs/recipes/12-navmesh.md +79 -0
- package/docs/recipes/13-animation.md +149 -0
- package/docs/recipes/14-custom-module.md +91 -0
- package/docs/recipes/15-perf.md +78 -0
- package/docs/recipes/16-dev-bridge.md +180 -0
- package/docs/recipes/18-world.md +185 -0
- package/docs/recipes/19-shooting-picking.md +76 -0
- package/docs/recipes/20-content-actions-save.md +176 -0
- package/docs/recipes/21-camera.md +153 -0
- package/docs/recipes/22-shop-gold.md +107 -0
- package/docs/recipes/23-ops.md +175 -0
- package/docs/recipes/26-ui-parts.md +138 -0
- package/docs/recipes/27-net.md +96 -0
- package/docs/recipes/28-terrain.md +80 -0
- package/docs/recipes/29-grid.md +87 -0
- package/docs/recipes/30-templates.md +131 -0
- package/docs/recipes/31-audio.md +126 -0
- package/docs/recipes/32-action-game.md +33 -0
- package/docs/recipes/33-stream-sources.md +37 -0
- package/docs/recipes/34-environment-lighting.md +36 -0
- package/docs/recipes/35-style-from-reference.md +89 -0
- package/docs/recipes/36-sky-ground-plant-looks.md +116 -0
- package/docs/recipes/37-terrain-look-hooks.md +97 -0
- package/docs/recipes/38-environment-look-hooks.md +83 -0
- package/docs/recipes/40-scene.md +108 -0
- package/docs/recipes/41-thing-registry.md +93 -0
- package/docs/recipes/42-terrain-shape.md +64 -0
- package/docs/recipes/43-shader-patches-surface-looks.md +120 -0
- package/docs/recipes/44-water-weather-look-hooks.md +135 -0
- package/docs/recipes/45-cascaded-shadows.md +51 -0
- package/docs/recipes/46-blender-art-route.md +114 -0
- package/docs/recipes/47-island-snow-backdrop.md +44 -0
- package/docs/recipes/48-make-material.md +70 -0
- package/docs/recipes/49-game-module-contract.md +71 -0
- package/docs/recipes/50-own-renderer.md +12 -0
- package/docs/recipes/51-capability-catalog.md +63 -0
- package/docs/recipes/52-look.md +108 -0
- package/examples/action/DESIGN.md +3 -0
- package/examples/action/GAMEMAP.md +127 -0
- package/examples/action/content/actions.js +8 -0
- package/examples/action/content/audio.js +9 -0
- package/examples/action/content/index.js +10 -0
- package/examples/action/content/items.js +4 -0
- package/examples/action/content/places.js +4 -0
- package/examples/action/content/props.js +11 -0
- package/examples/action/content/templates.js +10 -0
- package/examples/action/content/views.js +6 -0
- package/examples/action/look.js +5 -0
- package/examples/action/main.js +137 -0
- package/examples/action/models.js +25 -0
- package/examples/sheepisland/GAMEMAP.md +107 -0
- package/examples/sheepisland/content/index.js +6 -0
- package/examples/sheepisland/content/props.js +19 -0
- package/examples/sheepisland/content/templates.js +5 -0
- package/examples/sheepisland/content/vegetation.js +8 -0
- package/examples/sheepisland/main.js +71 -0
- package/examples/sheepisland/params.js +25 -0
- package/examples/sheepisland/style/index.js +79 -0
- package/examples/sheepisland/style/models.js +59 -0
- package/examples/sheepisland/views.js +9 -0
- package/examples/styletest/GAMEMAP.md +135 -0
- package/examples/styletest/content/index.js +9 -0
- package/examples/styletest/content/items.js +8 -0
- package/examples/styletest/content/npcs.js +8 -0
- package/examples/styletest/content/places.js +5 -0
- package/examples/styletest/content/props.js +16 -0
- package/examples/styletest/content/templates.js +9 -0
- package/examples/styletest/content/vegetation.js +31 -0
- package/examples/styletest/look.js +11 -0
- package/examples/styletest/main.js +95 -0
- package/examples/styletest/models.js +87 -0
- package/examples/styletest/overrides.js +33 -0
- package/examples/styletest/panel.js +135 -0
- package/examples/styletest/params.js +32 -0
- package/examples/styletest/views.js +31 -0
- package/examples/world/DESIGN.md +5 -0
- package/examples/world/GAMEMAP.md +171 -0
- package/examples/world/content/actions.js +8 -0
- package/examples/world/content/audio.js +25 -0
- package/examples/world/content/bodies.js +12 -0
- package/examples/world/content/containers.js +4 -0
- package/examples/world/content/dialogues.js +33 -0
- package/examples/world/content/index.js +17 -0
- package/examples/world/content/items.js +10 -0
- package/examples/world/content/npcs.js +14 -0
- package/examples/world/content/pickups.js +11 -0
- package/examples/world/content/places.js +6 -0
- package/examples/world/content/props.js +12 -0
- package/examples/world/content/quests.js +15 -0
- package/examples/world/content/rules.js +23 -0
- package/examples/world/content/templates.js +5 -0
- package/examples/world/content/vegetation.js +32 -0
- package/examples/world/main.js +168 -0
- package/examples/world/models.js +28 -0
- package/index.d.ts +306 -0
- package/index.js +122 -0
- package/llms.txt +61 -0
- package/modules/ambience/Ambience.js +186 -0
- package/modules/camera/FirstPersonCamera.js +131 -0
- package/modules/camera/FixedCamera.js +162 -0
- package/modules/camera/FollowCamera.js +91 -0
- package/modules/camera/RtsCamera.js +132 -0
- package/modules/camera/common.js +182 -0
- package/modules/camera/index.js +11 -0
- package/modules/camera/projection.js +34 -0
- package/modules/characters/Character.js +235 -0
- package/modules/characters/NPC.js +242 -0
- package/modules/characters/assetModel.js +42 -0
- package/modules/characters/astar.js +66 -0
- package/modules/characters/behaviors.js +72 -0
- package/modules/characters/footsteps.js +13 -0
- package/modules/characters/index.js +215 -0
- package/modules/characters/moveHelpers.js +29 -0
- package/modules/characters/movers/common.js +62 -0
- package/modules/characters/movers/rapier.js +74 -0
- package/modules/characters/movers/simple.js +43 -0
- package/modules/characters/npcAvoid.js +129 -0
- package/modules/characters/npcSim.js +150 -0
- package/modules/characters/npcView.js +42 -0
- package/modules/characters/pathAsync.js +113 -0
- package/modules/characters/pathJob.js +62 -0
- package/modules/characters/pathWorker.js +7 -0
- package/modules/characters/playerStrings.js +12 -0
- package/modules/characters/proceduralRig.js +58 -0
- package/modules/characters/useModel.js +22 -0
- package/modules/characters/walkTo.js +58 -0
- package/modules/collision/Collision.js +274 -0
- package/modules/collision/grid.js +63 -0
- package/modules/content/explain.js +13 -0
- package/modules/content/ids.js +95 -0
- package/modules/content/index.js +154 -0
- package/modules/content/loader.js +190 -0
- package/modules/content/models.js +69 -0
- package/modules/content/packs.js +69 -0
- package/modules/content/props.js +89 -0
- package/modules/content/rules.js +134 -0
- package/modules/content/templates.js +189 -0
- package/modules/debug/DebugPanel.js +174 -0
- package/modules/entities/Entities.js +243 -0
- package/modules/entities/build.js +25 -0
- package/modules/entities/index.js +4 -0
- package/modules/flow/index.js +101 -0
- package/modules/gameplay/Container.js +227 -0
- package/modules/gameplay/Containers.js +89 -0
- package/modules/gameplay/Dialogue.js +219 -0
- package/modules/gameplay/Interactions.js +253 -0
- package/modules/gameplay/Inventory.js +224 -0
- package/modules/gameplay/Quests.js +205 -0
- package/modules/gameplay/boxOps.js +60 -0
- package/modules/gameplay/dialogueBox.js +48 -0
- package/modules/gameplay/interactionPrompt.js +28 -0
- package/modules/gameplay/inventoryOps.js +137 -0
- package/modules/gameplay/pickups.js +115 -0
- package/modules/gameplay/questLog.js +54 -0
- package/modules/gameplay/questSave.js +71 -0
- package/modules/grid/Grid.js +184 -0
- package/modules/grid/Layer.js +142 -0
- package/modules/grid/index.js +236 -0
- package/modules/grid/ops.js +73 -0
- package/modules/grid/preview.js +85 -0
- package/modules/grid/tiles.js +79 -0
- package/modules/hlod/index.js +167 -0
- package/modules/hud/index.js +167 -0
- package/modules/hud/parts.js +80 -0
- package/modules/level/geometry.js +46 -0
- package/modules/level/heightfield.js +160 -0
- package/modules/level/index.js +233 -0
- package/modules/level/nodes.js +84 -0
- package/modules/lights/index.js +227 -0
- package/modules/music/Music.js +294 -0
- package/modules/music/index.js +2 -0
- package/modules/music/rules.js +28 -0
- package/modules/nav/index.js +156 -0
- package/modules/nav/navPath.js +17 -0
- package/modules/net/Client.js +137 -0
- package/modules/net/Host.js +117 -0
- package/modules/net/Net.js +49 -0
- package/modules/net/index.js +77 -0
- package/modules/net/sync.js +114 -0
- package/modules/net/transports.js +118 -0
- package/modules/particles/Particles.js +179 -0
- package/modules/particles/effect.js +112 -0
- package/modules/particles/shaders.js +28 -0
- package/modules/photo/Photo.js +146 -0
- package/modules/rigid/RigidBodies.js +265 -0
- package/modules/rigid/Vehicles.js +97 -0
- package/modules/rigid/sync.js +158 -0
- package/modules/settings/Settings.js +297 -0
- package/modules/settings/apply.js +21 -0
- package/modules/settings/index.js +3 -0
- package/modules/settings/sections.js +156 -0
- package/modules/settings/strings.js +53 -0
- package/modules/settings/view.js +65 -0
- package/modules/sky/Sky.js +259 -0
- package/modules/sky/calendar.js +80 -0
- package/modules/sky/cascades.js +125 -0
- package/modules/sky/clouds.js +79 -0
- package/modules/sky/domeLayers.js +33 -0
- package/modules/sky/environment.js +141 -0
- package/modules/sky/fog.js +139 -0
- package/modules/sky/frame.js +77 -0
- package/modules/sky/layers.js +69 -0
- package/modules/sky/look.js +51 -0
- package/modules/sky/lookFog.js +80 -0
- package/modules/sky/lookShadow.js +50 -0
- package/modules/sky/lookSky.js +108 -0
- package/modules/sky/schedule.js +80 -0
- package/modules/sky/shader.js +96 -0
- package/modules/sky/shadow.js +74 -0
- package/modules/sky/skyModule.js +60 -0
- package/modules/terrain/ChunkManager.js +260 -0
- package/modules/terrain/chunkJob.js +19 -0
- package/modules/terrain/chunkLevels.js +40 -0
- package/modules/terrain/chunkQueries.js +42 -0
- package/modules/terrain/chunkWorker.js +5 -0
- package/modules/terrain/index.js +118 -0
- package/modules/terrain/lookGround.js +61 -0
- package/modules/terrain/mountTerrain.js +32 -0
- package/modules/terrain/terrainColorMap.js +41 -0
- package/modules/terrain/terrainDefaults.js +39 -0
- package/modules/terrain/terrainEdit.js +139 -0
- package/modules/terrain/terrainGen.js +155 -0
- package/modules/terrain/terrainIsland.js +131 -0
- package/modules/terrain/terrainMesh.js +92 -0
- package/modules/terrain/terrainShape.js +108 -0
- package/modules/terrain/terrainShapeMain.js +41 -0
- package/modules/terrain/terrainTexture.js +44 -0
- package/modules/timeline/Timeline.js +253 -0
- package/modules/timeline/Tween.js +114 -0
- package/modules/timeline/letterbox.js +24 -0
- package/modules/timeline/shots.js +90 -0
- package/modules/triggers/index.js +268 -0
- package/modules/vegetation/Vegetation.js +256 -0
- package/modules/vegetation/groundChunks.js +177 -0
- package/modules/vegetation/index.js +43 -0
- package/modules/vegetation/lookWind.js +37 -0
- package/modules/vegetation/modelGeometry.js +21 -0
- package/modules/water/Water.js +160 -0
- package/modules/water/look.js +80 -0
- package/modules/water/surface.js +88 -0
- package/modules/weather/Weather.js +242 -0
- package/modules/weather/look.js +75 -0
- package/modules/weather/particles.js +92 -0
- package/modules/weather/shaders.js +49 -0
- package/modules/weather/strings.js +15 -0
- package/modules/world/World.js +231 -0
- package/modules/world/cells.js +42 -0
- package/modules/world/explain.js +11 -0
- package/modules/world/index.js +71 -0
- package/modules/world/persist.js +107 -0
- package/modules/world/pos.js +20 -0
- package/modules/world/records.js +89 -0
- package/modules/world/sim.js +175 -0
- package/modules/world/simFar.js +82 -0
- package/modules/world/state.js +115 -0
- package/modules/world/thingSource.js +44 -0
- package/modules/world/views.js +182 -0
- package/package.json +66 -4
- package/presets.js +96 -0
- package/render/PostFX.js +240 -0
- package/render/detail.js +105 -0
- package/render/effects.js +144 -0
- package/render/engineUniforms.js +23 -0
- package/render/fuse.js +84 -0
- package/render/lighting.js +100 -0
- package/render/lights.js +18 -0
- package/render/lookSurface.js +161 -0
- package/render/materials.js +220 -0
- package/render/patches.js +252 -0
- package/render/postLook.js +86 -0
- package/render/surface.js +69 -0
- package/render/uniformDecl.js +29 -0
- package/types/common.d.ts +34 -0
- package/types/core.d.ts +1965 -0
- package/types/gameplay.d.ts +1822 -0
- package/types/generated/core/Audio.d.ts +200 -0
- package/types/generated/core/Batching.d.ts +47 -0
- package/types/generated/core/Budget.d.ts +90 -0
- package/types/generated/core/Commits.d.ts +31 -0
- package/types/generated/core/DebugOverrides.d.ts +52 -0
- package/types/generated/core/Events.d.ts +89 -0
- package/types/generated/core/I18n.d.ts +30 -0
- package/types/generated/core/Input.d.ts +118 -0
- package/types/generated/core/Jobs.d.ts +41 -0
- package/types/generated/core/Ops.d.ts +203 -0
- package/types/generated/core/Random.d.ts +49 -0
- package/types/generated/core/Rays.d.ts +49 -0
- package/types/generated/core/Saves.d.ts +162 -0
- package/types/generated/core/Stream.d.ts +93 -0
- package/types/generated/core/Threads.d.ts +82 -0
- package/types/generated/core/Views.d.ts +33 -0
- package/types/generated/core/audioVoice.d.ts +47 -0
- package/types/generated/core/page.d.ts +18 -0
- package/types/generated/core/session.d.ts +48 -0
- package/types/generated/modules/ambience/Ambience.d.ts +48 -0
- package/types/generated/modules/debug/DebugPanel.d.ts +24 -0
- package/types/generated/modules/flow/index.d.ts +10 -0
- package/types/generated/modules/grid/Grid.d.ts +151 -0
- package/types/generated/modules/grid/Layer.d.ts +65 -0
- package/types/generated/modules/grid/index.d.ts +86 -0
- package/types/generated/modules/hlod/index.d.ts +11 -0
- package/types/generated/modules/hud/index.d.ts +10 -0
- package/types/generated/modules/lights/index.d.ts +13 -0
- package/types/generated/modules/music/Music.d.ts +111 -0
- package/types/generated/modules/net/Net.d.ts +34 -0
- package/types/generated/modules/net/index.d.ts +53 -0
- package/types/generated/modules/net/transports.d.ts +58 -0
- package/types/generated/modules/particles/Particles.d.ts +69 -0
- package/types/generated/modules/sky/Sky.d.ts +145 -0
- package/types/generated/modules/sky/skyModule.d.ts +10 -0
- package/types/generated/modules/timeline/Timeline.d.ts +51 -0
- package/types/generated/modules/water/Water.d.ts +29 -0
- package/types/generated/modules/weather/Weather.d.ts +62 -0
- package/types/generated/modules/world/World.d.ts +242 -0
- package/types/generated/modules/world/index.d.ts +15 -0
- package/types/generated/render/PostFX.d.ts +125 -0
- package/types/generated/render/materials.d.ts +100 -0
- package/types/generated/render/patches.d.ts +41 -0
- package/types/generated/ui/Focus.d.ts +11 -0
- package/types/generated/ui/LoadingScreen.d.ts +2 -0
- package/types/generated/ui/UI.d.ts +57 -0
- package/types/nav.d.ts +52 -0
- package/types/physics.d.ts +592 -0
- package/types/style.d.ts +638 -0
- package/types/worker.d.ts +11 -0
- package/types/world.d.ts +772 -0
- package/ui/Focus.js +51 -0
- package/ui/LoadingScreen.js +42 -0
- package/ui/Parts.js +199 -0
- package/ui/UI.js +167 -0
- package/ui/defaults.js +85 -0
- package/ui/theme.js +124 -0
- package/ui/touchPart.js +49 -0
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# Templates: reusable objects, definition vs instance state
|
|
2
|
+
|
|
3
|
+
Requires `world()` (in `openWorld()`); a template with `interact` needs `interactions({ ...presets.interactions.nearest })`, with `container` needs
|
|
4
|
+
`inventory({ ...presets.keys.inventory })`. The code is `modules/content/templates.js`.
|
|
5
|
+
|
|
6
|
+
A **template** describes one kind of object once: its model, collision, interaction, container, sound, animation and the default values of its saved
|
|
7
|
+
state. Every chest, campfire or bed you place is an **instance**: a world record that names the template (its `kind` is the template name) and holds
|
|
8
|
+
only its own state. There is no inheritance and no variant layer; a different look or behaviour is another template.
|
|
9
|
+
|
|
10
|
+
## 1. Define a template
|
|
11
|
+
`games/<game>/content/templates.js` (add it to `content/index.js`):
|
|
12
|
+
```js
|
|
13
|
+
export default {
|
|
14
|
+
chest: {
|
|
15
|
+
model: 'chest', // an asset name (file or generator of an asset pack); every chest clones one shared prototype (geometry and material built once)
|
|
16
|
+
collide: 'box', // 'box' / 'circle' from the model's bounds; omitted = does not block
|
|
17
|
+
state: { opened: false }, // instance fields and their defaults, copied onto each record and saved
|
|
18
|
+
interact: { label: rec => rec.opened ? '关上' : '打开', op: 'chest.toggle', radius: 2 }, // using it runs the op with { id }
|
|
19
|
+
container: { capacity: 6, items: { berry: 2 } }, // each chest gets a container whose id is the record id; items = starting goods (placed once)
|
|
20
|
+
sound: { use: 'chest' }, // engine.audio.sfx after a successful use
|
|
21
|
+
animate: (rec, obj, dt) => { obj.children[0].rotation.x = rec.opened ? -1.1 : 0; }, // per-frame look from the record, only while the model exists
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
```
|
|
25
|
+
The action itself is an op in main.js (recipes/23-ops.md), so every open is logged and testable:
|
|
26
|
+
```js
|
|
27
|
+
engine.ops.define('chest.toggle', { run: (e, { id }) => e.world.set(id, { opened: !e.world.get(id).opened }) });
|
|
28
|
+
```
|
|
29
|
+
`interact` fields: `op` (required), `label` (text, i18n key, or `(rec, engine) => text`), `radius` (default 2.5), `height`, `action`,
|
|
30
|
+
`enabled: (rec, engine) => boolean`.
|
|
31
|
+
|
|
32
|
+
## 2. Place instances
|
|
33
|
+
In `content/props.js`, an entry with `template` instead of `model` places an instance. It takes a position and a few explicit overrides:
|
|
34
|
+
```js
|
|
35
|
+
export default [
|
|
36
|
+
{ template: 'chest', id: 'chest-home', place: 'home', x: 3, z: 1 },
|
|
37
|
+
{ template: 'chest', id: 'chest-cave', place: 'cave', x: 0, z: 2, opened: true, items: { film: 2 }, rot: 1.6 },
|
|
38
|
+
];
|
|
39
|
+
```
|
|
40
|
+
Allowed per instance: `id`, `place` / `x` / `z`, `y` (height above the ground), `rot`, `scale`, `items` (replaces the starting goods) and the
|
|
41
|
+
template's **state fields**. Writing a definition field (`model`, `collide`, `interact`...) throws and says to define another template.
|
|
42
|
+
|
|
43
|
+
**Ids.** An entry with state (a template with `state`, `container`, `interact` or `body`, every pickup, every grid item) gets a written id: saves find
|
|
44
|
+
its changes by id, and an index id (`<template>:<index>`, `pickup:<item>:<index>`) moves to another entry when one is inserted above it. Without one,
|
|
45
|
+
dev warns once per load and names the id to write. Pure decoration may keep its index id. Two entries with the same id in one load throw with the fix;
|
|
46
|
+
an authored id may not contain `#` or `/` (those are kept for records made during play and for level nodes). Places computed from the seed (a flat
|
|
47
|
+
spot near the river) stay in code and come in through `content.load(data, { places })`. Records made during play are numbered `<kind>#<n>`
|
|
48
|
+
(`chest#4`), so they never meet an authored id.
|
|
49
|
+
|
|
50
|
+
**Writing the ids, renaming them.** `npx threedog content ids [-w game]` lists each stateful entry that still relies on its index id with the id it
|
|
51
|
+
has now (`-`/`+` lines, dry run); `--write` writes them into the content files. Writing today's id changes nothing for old saves. To give an entry a
|
|
52
|
+
readable id later, change it and add the pair to `content/renames.js`: <!-- r18-ignore-line -->
|
|
53
|
+
```js
|
|
54
|
+
export default { 'chest:3': 'chest-home', 'prop:rock:12': null }; // old id -> new id; null = deleted on purpose
|
|
55
|
+
```
|
|
56
|
+
Loading a save then moves its changes, removal, owed time and container goods from `chest:3` to `chest-home` (save loaded before or after content),
|
|
57
|
+
and drops `prop:rock:12`'s data quietly. `npm run check` errors on a target no entry defines and on a source content still defines; dev warns about an
|
|
58
|
+
orphan near an existing id with the exact pair to add.
|
|
59
|
+
|
|
60
|
+
**Physics props.** `body: { shape: 'box' | 'ball' | 'hull', mass, friction?, restitution?, damping?, angularDamping? }` in a definition makes each
|
|
61
|
+
copy a rigid body (needs `rigid()`). The copy rests on the ground asleep until something hits it; then the record follows the model, so a pushed
|
|
62
|
+
crate's place is saved like any other change.
|
|
63
|
+
```js
|
|
64
|
+
// content/templates.js
|
|
65
|
+
export default { crate: { model: 'crate', body: { shape: 'box', mass: 2 } } };
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
**Grid items and level nodes.** A props entry `{ id: 'bed-home', grid: 'farm', item: 'bed', cell: [4, 4], rotation: 1 }` is the record `grid.place`
|
|
69
|
+
would make, as authored data (the grid comes from the content key `grids`, `{ farm: { cell: 1, origin: [0, 0], size: [16, 12] } }`, or
|
|
70
|
+
`engine.grids.add`). In a level model, a node with the Blender custom property `template = 'door'` becomes an instance of that template (its other
|
|
71
|
+
custom properties fill the template's state), and one with `id = true` becomes a record of kind `levelNode` whose model is the node itself. Their id
|
|
72
|
+
is `<level file name>/<node name>`, for example `town/door_front` (recipe 10).
|
|
73
|
+
|
|
74
|
+
At runtime (inside an op or a fixed step), `engine.spawn(name, at, fields)` places a new instance and returns its record:
|
|
75
|
+
```js
|
|
76
|
+
engine.ops.define('chest.build', {
|
|
77
|
+
run: (e, { x, z }) => e.spawn('chest', { x, z }, { items: { stick: 3 } }).id,
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
Instances from `props.js` are initial records (a save stores only their changes); spawned ones are saved whole. Use `engine.world.get(id)`, `set`,
|
|
81
|
+
`move`, `remove` and `query({ kind: 'chest' })` as for any record (recipe 18). Removing a record does not remove its container (the game decides what
|
|
82
|
+
happens to the goods).
|
|
83
|
+
|
|
84
|
+
## 3. What belongs to the definition, what to the instance
|
|
85
|
+
| | Definition (shared, read-only) | Instance (per object, saved) |
|
|
86
|
+
|---|---|---|
|
|
87
|
+
| Template | model, collide, static, interact, container capacity and starting goods, sound, animate, state defaults, body | world record: id, kind, position, rot, scale, state fields (`opened`) |
|
|
88
|
+
| Container | capacity, maxWeight | the goods in `engine.inventory.container(id)` |
|
|
89
|
+
| Item (`inventory.define`) | name, icon, stack, weight, use | count and per-piece `data` (durability, ammo): `add('sword', 1, { data: { durability: 40 } })` |
|
|
90
|
+
| Entity type (`entities.define`) | create, stages, interact, collider, state defaults | `ent.state` (stage, watered) on its world record |
|
|
91
|
+
| Crop / enemy kind (your own table) | grow time, max hp, drops | `plantedAt`, `hp` on the record |
|
|
92
|
+
|
|
93
|
+
Definitions are frozen when registered (`content/templates.js`, `inventory.define`, `entities.define`):
|
|
94
|
+
`engine.content.template('chest').state.opened = true` throws `Cannot assign to read only property`, and the engine's error hint says to keep the
|
|
95
|
+
value on the record instead (`engine.world.set(id, { opened: true })`). Read a definition with `engine.content.template(name)` or
|
|
96
|
+
`engine.inventory.item(id)`. For your own tables of kinds (enemy types, crop types), the same split applies: keep the table in content, store `kind`
|
|
97
|
+
plus the changing values on the record, and wrap the table with `Object.freeze` if you like. <!-- r18-ignore-line -->
|
|
98
|
+
|
|
99
|
+
## 4. Tests
|
|
100
|
+
`tests/specs/templates.mjs`: two chests of one template share the model, open / goods per instance, save and reload restores each, the definition
|
|
101
|
+
never changes. `tests/specs/single-source.mjs` (`npm test -- "Single source"`): ids, duplicates, baseline + diff, orphans, level nodes, source lines, pick.
|
|
102
|
+
|
|
103
|
+
## 5. Point -> thing: where is this defined
|
|
104
|
+
Runtime ops change only the current session and its saves. To change the level itself, edit the content files or the level model, then reload. To find
|
|
105
|
+
the entry, ask the engine what a thing is:
|
|
106
|
+
```js
|
|
107
|
+
const t = engine.pick(0, 0)?.thing; // what is in the middle of the screen
|
|
108
|
+
// { id: 'chest-home', kind: 'chest', template: 'chest', definedAt: 'content/props.js:14', templateAt: 'content/templates.js:3', fields: { opened: false }, edit: 'defined in content/props.js:14: …' }
|
|
109
|
+
engine.world.origin('chest-home'); // the same source info for an id
|
|
110
|
+
```
|
|
111
|
+
`hit.thing` is on every `engine.pick` / `engine.raycast` hit (computed when read); a hit on a batched copy resolves to its original object.
|
|
112
|
+
`engine.inspect(id).thing` and `engine.explain({ op, args: { id } })` say the same. A hit on a plain object added with `engine.add` gets its
|
|
113
|
+
`hit.thing` from the registry (id, `at` = the file:line of the add, `saved`, `edit`; recipe 41). A record made during play shows the op and tick that spawned it
|
|
114
|
+
(`spawned`), a level node its level and node name. Source lines exist in dev and test builds only (a Vite transform tags `content/*.js` with their
|
|
115
|
+
line numbers); a release build has none and pays nothing. From a terminal or an MCP client: `npx threedog pick 480,270` (screen pixels from the canvas
|
|
116
|
+
top-left) or the MCP tool `pick { x, y }`.
|
|
117
|
+
|
|
118
|
+
## 6. When to use a template
|
|
119
|
+
Two doors lead into one scene. Plain three.js, `engine.add(mesh, { id })`, is fine for anything your code rebuilds on every start: a code-built
|
|
120
|
+
windmill, colliders, interactions. A template plus a placement with an `id` in `content/props.js` (or `pickups`, `npcs`, `containers`, a game kind
|
|
121
|
+
from `rules.js`, the level model) is what you want when the thing must be saved with its own state, edited without touching code, or copied many
|
|
122
|
+
times. Both land in the same registry: `engine.thing(id)` answers for either and says what a save keeps (recipe 41). Game code keeps the rules: ops,
|
|
123
|
+
`world.simulate` / `world.present`, conditions and UI. Something that appears during play is created inside an op with `engine.spawn`.
|
|
124
|
+
|
|
125
|
+
`npm run check` (rule R33) flags only what breaks, in examples, templates and `games/*` alike. Error: `world.add` (without `{ save: false }`),
|
|
126
|
+
`engine.spawn`, `spawnPickup`, `npcs.add` or `entities.spawn` at module top level or in an `engine:ready` / `level:loaded` / `session:start`
|
|
127
|
+
handler, because those are saved whole and the startup code would make a second copy after every load; and `world.add(…, { initial: true })`
|
|
128
|
+
anywhere. Warning: code that `engine.add`s a `world.view(id)` model or writes its position / rotation / scale (world puts it back every frame).
|
|
129
|
+
The fix is a placement in content, or an op. Places computed from the seed (a flat spot for `home`) stay in code and are passed as `places` to
|
|
130
|
+
`content.load`; a mesh built in code becomes a model by name (`engine.assets.manifest({ models: { cabin } })`) when you want it as a template.
|
|
131
|
+
A line that really must do it from code at startup carries `// runtime: <reason>`.
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# Sound: buses, sounds by name, ambience rules, music, footsteps, ducking
|
|
2
|
+
|
|
3
|
+
Everything you hear is the game's. The engine ships no sound files and plays nothing the game did not name; built-in synths (`footstep`, `shutter`,
|
|
4
|
+
`thunder`, `wind`, `rain`, `water`, `birds`, `crickets`) stay silent until `audio.sounds` asks for them. Signatures: `api/audio.md`,
|
|
5
|
+
`api/ambience.md`, `api/music.md`.
|
|
6
|
+
|
|
7
|
+
## 1. Config in one place
|
|
8
|
+
```js
|
|
9
|
+
const engine = createEngine({ canvas, audio: {
|
|
10
|
+
levels: { music: 0.4, voice: 1 }, // volume per bus; an extra key (voice) adds a bus
|
|
11
|
+
sounds: {
|
|
12
|
+
door: '/sfx/door.ogg', // a file
|
|
13
|
+
hit: ['/sfx/hit1.ogg', '/sfx/hit2.ogg', '/sfx/hit3.ogg'], // variants: random, never the same one twice in a row
|
|
14
|
+
shot: { src: '/sfx/shot.ogg', jitter: { pitch: 0.08, volume: 0.1 }, cooldown: 0.05, voices: 4, distance: { ref: 3, max: 80 } },
|
|
15
|
+
footstep: 'synth', // the engine's synthesized one
|
|
16
|
+
'step.sand': { synth: 'footstep', params: { surface: 'sand' } }, // a synth with parameters
|
|
17
|
+
wind: 'synth', birds: 'synth',
|
|
18
|
+
},
|
|
19
|
+
ambience: [ /* rule table, section 3 */ ],
|
|
20
|
+
music: { tracks: { /* section 4 */ }, rules: [] },
|
|
21
|
+
footsteps: { beach: 'step.sand', default: 'footstep' }, // section 5
|
|
22
|
+
} });
|
|
23
|
+
```
|
|
24
|
+
Code may hold functions (a `volume: e => ...`); the same config as data goes in a content pack (section 8). A full working one:
|
|
25
|
+
`examples/world/content/audio.js`.
|
|
26
|
+
|
|
27
|
+
## 2. Buses and sounds by name
|
|
28
|
+
Buses are real Web Audio `GainNode`s: `master`, `music`, `sfx`, `ambience`, `ui`, plus the game's own (`levels: { voice: 1 }` or
|
|
29
|
+
`engine.audio.addBus('voice')`). `engine.audio.setVolume('music', 0.3)` sets one; `engine.audio.buses.sfx` is the node to connect your own nodes to.
|
|
30
|
+
|
|
31
|
+
```js
|
|
32
|
+
engine.audio.sfx('door'); // plays on its bus (default sfx)
|
|
33
|
+
const h = engine.audio.sfx('shot', { at: enemy.root }); // 3D: a PannerNode that follows the Object3D every frame
|
|
34
|
+
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)
|
|
36
|
+
engine.audio.sfx('click', { bus: 'ui' });
|
|
37
|
+
```
|
|
38
|
+
`sfx` returns `null` when the sound is silent: not in `audio.sounds`, audio still locked (before the first click), or inside its `cooldown`. Over its
|
|
39
|
+
`voices` limit the oldest voice stops. Files by path without an entry: `await engine.audio.play(url, { bus, loop, fadeIn })`.
|
|
40
|
+
|
|
41
|
+
Built-in synth parameters (`params`): `wind` / `water` take `freq` (filter Hz), `birds` `range: [low, high]` Hz, `crickets` `freq` (chirp Hz, default
|
|
42
|
+
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
|
+
until the rules load again, instead of refetching.
|
|
44
|
+
|
|
45
|
+
Your own synth: `engine.audio.register('ding', (a, p, out) => { a.tone({ freq: 880 * p.pitch, dur: 0.2, out }); return 0.2; })`. Connect to `out` and
|
|
46
|
+
return the length in seconds (or `{ stop(t) }` for a loop).
|
|
47
|
+
|
|
48
|
+
## 3. Ambience: a rule table
|
|
49
|
+
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
|
|
50
|
+
when silent, so idle rules cost nothing).
|
|
51
|
+
```js
|
|
52
|
+
ambience: [
|
|
53
|
+
{ sound: 'wind', volume: e => 0.05 + (e.weather?.current.wind ?? 0) * 0.08 }, // volume can follow the moment
|
|
54
|
+
{ sound: 'river', volume: (e, a) => a.nearWater(12) * 0.12 }, // a = engine.ambience (position, nearWater)
|
|
55
|
+
{ sound: 'cave-drip', when: { zone: 'cave' }, volume: 0.6, fade: 2 },
|
|
56
|
+
{ sound: 'birds', when: { time: 'day', weather: ['clear', 'cloudy'] }, every: [2, 7] },
|
|
57
|
+
{ sound: 'war-drums', when: { state: 'combat' }, volume: 0.5 },
|
|
58
|
+
]
|
|
59
|
+
```
|
|
60
|
+
Condition keys (all must hold): `state` (`engine.audio.state = 'combat'`, set by the game), `time` (`'day'`, `'night'` or `['18:00', '06:00']`, needs
|
|
61
|
+
`sky()`), `weather` (a name or a list, needs `weather()`), `zone` (a trigger-zone tag the player is in, needs `triggers()`). Measures compare a
|
|
62
|
+
number: `{ daylight: { gt: 0.15 }, rain: { lt: 0.2 } }` (keys `gt gte lt lte`; section 8 lists them). Anything else: a function `when: e => ...`, or
|
|
63
|
+
add a key: `engine.audio.condition('inside', v => engine.vars.flag('indoors') === v)`. Add or swap rules at run time with `engine.ambience.add(rule)`
|
|
64
|
+
(returns a handle) and `engine.ambience.rules(list)`.
|
|
65
|
+
|
|
66
|
+
## 4. Music: rules, cross-fade, stems
|
|
67
|
+
```js
|
|
68
|
+
engine.use(music({ tracks: {
|
|
69
|
+
explore: '/music/explore.ogg',
|
|
70
|
+
combat: { url: '/music/combat.ogg', stems: [{ url: '/music/combat-drums.ogg', at: [0.3, 0.7] }] },
|
|
71
|
+
}, rules: [
|
|
72
|
+
{ track: 'combat', when: { state: 'combat' }, priority: 10 },
|
|
73
|
+
{ track: 'explore' }, // no when: the fallback
|
|
74
|
+
] }));
|
|
75
|
+
engine.music.intensity = 0.8; // stems fade in as it rises through their at range
|
|
76
|
+
```
|
|
77
|
+
The same `when` keys as ambience. Tracks cross-fade (`fade`, default 2 s); a new rule result must hold `hold` seconds before switching.
|
|
78
|
+
`engine.music.override('boss')` picks by hand; `override(null)` hands back to the rules. `engine.music.stinger('win')` plays a short piece over the music.
|
|
79
|
+
|
|
80
|
+
## 5. Footsteps by surface
|
|
81
|
+
The player's footstep rhythm follows its speed (one step per foot landing). Each step plays the sound named by `footsteps[groundType]`, else
|
|
82
|
+
`footsteps.default`, else `footstep`. The ground type is the terrain's `groundType` or, in a Blender level, the material name (or `groundType` custom
|
|
83
|
+
property); `water` while swimming.
|
|
84
|
+
|
|
85
|
+
## 6. Ducking
|
|
86
|
+
```js
|
|
87
|
+
const d = engine.audio.duck({ music: 0.3, ambience: 0.5 }, { fade: 0.3 }); // lower these buses
|
|
88
|
+
engine.events.once('dialogue:end', () => d.remove()); // restore
|
|
89
|
+
```
|
|
90
|
+
Ducks stack (levels multiply) and never touch the player's volume setting. `music({ duckDialogue: 0.35 })` ducks the music bus during dialogue for
|
|
91
|
+
you; it is off by default (whether talking lowers the music is the game's choice).
|
|
92
|
+
|
|
93
|
+
## 7. Settings
|
|
94
|
+
The default settings menu has a volume slider per bus, the game's own buses included, saved with the other settings. A game bus's label is the text
|
|
95
|
+
key `settings.vol.<bus>` (`engine.i18n.add({ en: { 'settings.vol.voice': 'Voices' } })`).
|
|
96
|
+
|
|
97
|
+
## 8. Sounds as content data
|
|
98
|
+
A content pack carries the game's audio the way it carries items: data only, sounds by name.
|
|
99
|
+
```js
|
|
100
|
+
// content/audio.js (export it from content/index.js like any content file)
|
|
101
|
+
export default {
|
|
102
|
+
sounds: { wind: 'synth', door: 'door', hit: ['hit1', 'hit2'], shot: { src: 'shot', cooldown: 0.05 } }, // 'synth' or asset pack sound names
|
|
103
|
+
ambience: [
|
|
104
|
+
{ sound: 'wind', volume: { base: 0.05, add: { wind: 0.08, altitude: 0.00375 }, max: 0.5 } }, // base + measure x factor, clamped
|
|
105
|
+
{ sound: 'rain', volume: { add: { rain: 0.22 } } },
|
|
106
|
+
{ sound: 'birds', when: { daylight: { gt: 0.15 }, rain: { lt: 0.2 } }, every: [1.5, 6.5] },
|
|
107
|
+
],
|
|
108
|
+
music: { tracks: { day: 'music-day' }, rules: [{ track: 'day', when: { time: 'day' } }] },
|
|
109
|
+
footsteps: { beach: 'step.sand', default: 'footstep' },
|
|
110
|
+
};
|
|
111
|
+
```
|
|
112
|
+
```js
|
|
113
|
+
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
|
+
engine.content.load([base, forest]); // each pack's audio merges in
|
|
115
|
+
```
|
|
116
|
+
- **Names, never paths or code.** A sounds string other than `'synth'` is a sound name from an asset pack (`engine.audio.load` and music resolve it
|
|
117
|
+
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
|
+
table drops that rule with a dev warning. `npm run check` reports both as errors.
|
|
119
|
+
- **Measures** are the numbers data compares and adds up. Built in: `daylight` (sky, 0 at night), `rain` / `snow` / `wind` (weather), `nearWater`
|
|
120
|
+
(share of water within 12 m, 0-1) and `altitude` (ground height under the listener, 0 below sea level) from ambience. Add your own:
|
|
121
|
+
`engine.audio.measure('danger', e => e.vars.counter('alarm') / 10)`; read one with `engine.audio.value('danger')`. A name is a condition key or a
|
|
122
|
+
measure, not both.
|
|
123
|
+
- **Merging.** `sounds`, `footsteps` and `music.tracks` are ids: two packs in one load with the same name is an error naming both; a name also in
|
|
124
|
+
`createEngine({ audio })` or `music({ tracks })` is an error (`[audio-name-clash]`). `ambience` and `music.rules` concatenate after the game's own.
|
|
125
|
+
Loading a named pack again replaces its rules (hot reload).
|
|
126
|
+
- `levels` (bus volumes) stay in `createEngine({ audio })`: they are settings, not content.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Action game wiring: hp, attacks, enemy AI, drops and death without engine combat rules
|
|
2
|
+
|
|
3
|
+
The engine has no health, damage, hit detection or death. An action game writes those as its own rules on top of systems that already exist. The
|
|
4
|
+
working example is `examples/action/` (page `/action.html`, about 150 lines of rules in `main.js`, the room in `content/`); its test is
|
|
5
|
+
`tests/specs/action.mjs`.
|
|
6
|
+
|
|
7
|
+
## 1. What goes where
|
|
8
|
+
| Piece | Built on | In the example |
|
|
9
|
+
|---|---|---|
|
|
10
|
+
| The room, the enemy and its stats (hp, damage, drop) | content `templates` + `props` with ids (recipe 30) | `content/templates.js` `slime: { model, static: false, state: { hp, maxHp, damage, cooldown, drop } }` |
|
|
11
|
+
| Player hp, attack cooldown, game over | plain object + `engine.describe.add` + `engine.saves.register` | `const game = fresh()` |
|
|
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
|
+
| 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
|
+
| Gameplay keys | content `actions` (`attack: { keys: ['Mouse0', 'KeyF'] }`), read with `input.pressed` in `onFixed` | `onFixed` runs `player.attack` |
|
|
15
|
+
| Drop | `engine.inventory.spawnPickup(item, at, { id })` inside the death op; E picks it up through `interactions` | `${id}-drop` |
|
|
16
|
+
| HUD, death screen, retry, save keys | `onFrame`: `hud.bar`, `toast`, `engine.session.newGame()` | the frame hook |
|
|
17
|
+
|
|
18
|
+
## 2. Rules that keep it replayable
|
|
19
|
+
- Damage, cooldowns and AI run in fixed steps or ops only (`onFixed`, `world.simulate`, `ops.run`), never in `onFrame`, so the result is the same at
|
|
20
|
+
any frame rate and a save loads bit-identical.
|
|
21
|
+
- An enemy that dies is `world.remove(id)`: the save remembers it is gone. A per-step value (the enemy's cooldown) is written straight onto the record
|
|
22
|
+
inside `simulate` or an op; a discrete one (its hp) goes through `world.set`.
|
|
23
|
+
- Hit detection is the game's: the example tests distance and the angle against the actor record's `facing`; a game with swords on bones would raycast
|
|
24
|
+
or test shapes instead (recipe 19).
|
|
25
|
+
- `player.die` decides what death does. The example offers `respawn` (`player.placeAt(spawn)`, full hp), `restart` and `gameover` (both end in
|
|
26
|
+
`engine.session.newGame()`, which is async flow and so runs from the frame hook, not inside the op).
|
|
27
|
+
|
|
28
|
+
## 3. Mouse attack and pointer lock
|
|
29
|
+
`followCamera({ ...presets.camera.overShoulder })` locks the mouse on a click. While locked, mouse buttons still arrive as `Mouse0`..`Mouse4` keys, so
|
|
30
|
+
`attack: { keys: ['Mouse0'] }` works in both states. The click that takes the lock is itself a `Mouse0` press and swings once; a game that does not
|
|
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 pack the room and enemy are gray (`?style=none`); colors come from a style part
|
|
33
|
+
(`examples/action/look.js`).
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Stream sources: what is loaded where (teleport, far camera)
|
|
2
|
+
|
|
3
|
+
Part of the world data recipe (`18-world.md`): world records never unload, this page is about the models, terrain and colliders built around them.
|
|
4
|
+
|
|
5
|
+
Three things are kept apart: **what is shown** (terrain chunks, models, stream entries, hlod), **what has colliders** (rigid terrain colliders, chunk
|
|
6
|
+
collision), and **world data** (records and their near / far simulation, which follows `world.anchor` and never unloads). Every loader reads the same
|
|
7
|
+
list, the sources of `engine.stream`:
|
|
8
|
+
|
|
9
|
+
| Source | Shows | Colliders |
|
|
10
|
+
|---|---|---|
|
|
11
|
+
| `engine.stream.player` (built in: `world.anchor`, else the player, else `engine.focus`) | full | yes |
|
|
12
|
+
| `engine.stream.camera` (built in: `engine.focus`) | full | no |
|
|
13
|
+
| `engine.stream.source(p, { radius, detail, physics, until })` | `detail: 'full'` (default) or `'simple'` (terrain and hlod proxies only) | `physics` (default true for `'full'`) |
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
// teleport: the player moves only after the destination's terrain, collision and nearby models are ready
|
|
17
|
+
await engine.stream.teleport([800, 0, 300]);
|
|
18
|
+
|
|
19
|
+
// the same by hand (for a door animation or a fade while it loads)
|
|
20
|
+
const dest = engine.stream.source([800, 0, 300], { radius: 64 });
|
|
21
|
+
await dest.whenReady;
|
|
22
|
+
engine.player.placeAt([800, 0, 300]);
|
|
23
|
+
dest.remove();
|
|
24
|
+
|
|
25
|
+
// a photo camera far away: a picture, no colliders; removed when photo mode ends
|
|
26
|
+
engine.stream.source(photoCam, { physics: false, until: () => !photoMode.active });
|
|
27
|
+
|
|
28
|
+
// a far view from a tower: terrain and hlod proxies only
|
|
29
|
+
const vista = engine.stream.source(towerTop, { detail: 'simple', radius: 600 });
|
|
30
|
+
```
|
|
31
|
+
- `radius` caps every loader's own range around that source (terrain view distance, present radius, `stream.radius`); without it each loader uses its own.
|
|
32
|
+
- `source.ready` is checked at the end of each frame; a new source counts after one full frame, so every loader has seen it. Fixed steps must run
|
|
33
|
+
(collision takes effect on a tick), so do not wait while `engine.pause()` is on without stepping.
|
|
34
|
+
- Leaving a place and coming back is safe: models unload, but records (an opened chest, a dropped item, a removed rock) stay in `engine.world` and the
|
|
35
|
+
models are rebuilt from them.
|
|
36
|
+
- Module authors with their own distance-based loader: read `engine.stream.sources({ detail: 'full' })` / `sources({ physics: true })` and
|
|
37
|
+
`s.reach(range)`, and register `engine.stream.readyCheck(name, s => ...)`. Do not read `engine.focus` or the player position for loading.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Environment lighting
|
|
2
|
+
|
|
3
|
+
The engine gives the mechanism and sets nothing: `scene.environment` is `null` until a style pack or the game asks for one, so the plain low-poly
|
|
4
|
+
Lambert look is unchanged. The background (the sky dome or `sky.skybox`) and the environment lighting are two separate fields.
|
|
5
|
+
|
|
6
|
+
```js
|
|
7
|
+
engine.look.env.replace('sky'); // lit by the procedural sky; follows the time of day
|
|
8
|
+
engine.look.env.set({ intensity: 0.8 });
|
|
9
|
+
engine.look.env.replace('hdr/studio.hdr'); engine.look.env.set({ intensity: 1, rotation: Math.PI / 2 }); // an HDR / panorama asset (equirectangular)
|
|
10
|
+
engine.look.env.set({ intensity: 0.5 }); // fields given change, the rest stay
|
|
11
|
+
engine.look.env.replace(false); // off, GPU memory released
|
|
12
|
+
engine.sky.environment; // { source, intensity, rotation, interval, builds } or null
|
|
13
|
+
```
|
|
14
|
+
A pack gives defaults in `sky.environment` (same fields, plus `low`), the game overrides with `sky({ environment: {...} })` or at run time with
|
|
15
|
+
`look.env.replace(...)` / `look.env.set(...)`. `low: false` turns it off on low-tier devices; any other `low` object replaces fields there.
|
|
16
|
+
|
|
17
|
+
## Sources
|
|
18
|
+
- `'sky'`: the dome is rendered into a cube and prefiltered with `PMREMGenerator`. It is rebuilt only when the sky colors, sun direction or cloud
|
|
19
|
+
cover actually changed AND at least `interval` seconds (default 1, low tier 4x) passed since the last check, never every frame. A fixed time of
|
|
20
|
+
day builds once. The first build waits for the first frame so it uses real colors. With `sky.skybox` use the skybox asset name as `source`.
|
|
21
|
+
- an asset name or path: `.hdr` loads through three's `HDRLoader` (float, linear), `.jpg` / `.png` / `.ktx2` as ordinary textures. The asset system
|
|
22
|
+
owns the texture; the engine owns only the prefiltered copy and disposes it on `look.env.replace(false)`, on a new source and on `engine.dispose()`.
|
|
23
|
+
- The cube is at least 256 px per face (PMREMGenerator's floor in 0.187), so a low tier saves time by rebuilding less often or by turning it off, not
|
|
24
|
+
by a smaller cube.
|
|
25
|
+
|
|
26
|
+
## What a MeshLambertMaterial does with it (three 0.187 source, not memory)
|
|
27
|
+
- `WebGLPrograms` hands `scene.environment` to Standard, Lambert and Phong materials; a Lambert material without its own `envMap` uses the PMREM path.
|
|
28
|
+
- `lights_fragment_maps` adds the shader function getIBLIrradiance = PI x (the blurriest PMREM mip in the direction of the world normal) x intensity to the
|
|
29
|
+
diffuse light. So Lambert gets soft, direction-dependent ambient light colored by the environment (sky blue from above, ground color from below).
|
|
30
|
+
- No specular: the cube reflection mix in `envmap_fragment` only runs for `ENVMAP_TYPE_CUBE`, not for a PMREM map. Lambert surfaces never get
|
|
31
|
+
reflections from the scene environment (use a Standard / Physical material for that).
|
|
32
|
+
- Intensity is `scene.environmentIntensity`, direction offset is `scene.environmentRotation` (Y only here).
|
|
33
|
+
- The hemisphere light stays and adds on top. When you turn the environment on, lower the ambient column of `sky.keyframes` (or
|
|
34
|
+
`sky.modify('env', { ambient: 0.5 })`, [recipe 52](52-look.md#skymodify-vs-looklights)) so shadows do not wash out.
|
|
35
|
+
- 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
|
+
- Toon, Basic and ShaderMaterial surfaces ignore it.
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# Making a new look from a reference picture
|
|
2
|
+
|
|
3
|
+
For an AI that is given one picture ("make it look like this") and has to turn it into a style pack. Three commands do the mechanical parts:
|
|
4
|
+
`threedog style palette` measures the picture, `npm run new-style` makes the pack, `threedog style check` finds mistakes before you look at pixels.
|
|
5
|
+
The taste is yours: the tools never say which colors are right, they only keep the work measurable and repeatable. What a style is and the
|
|
6
|
+
composing rules are in `09-style-pack.md`; this page is the order of work.
|
|
7
|
+
|
|
8
|
+
## What a style can change, and what it cannot
|
|
9
|
+
Can change (all in the style pack): colors (`palette`, `terrain.colors`, `background`, `water.color`, season tints), material types per role
|
|
10
|
+
(`materials`: matte `lambert`, `toon` bands, `standard`...), lights and sky (`sky.keyframes`, sun, clouds, shadows, `exposure`, `toneMapping`), post
|
|
11
|
+
effects (`post`: outline, bloom, grain, vignette, color grading from `@threedog/post-effects`), UI colors and fonts, particle looks, and the colors
|
|
12
|
+
of the procedural models (`palette` read by `models.js`).
|
|
13
|
+
|
|
14
|
+
Cannot change by a style: the **silhouette of models**. A tree stays the shape its model has; a new shape means a new asset pack (code-built models
|
|
15
|
+
in `models.js`, or `.glb` files, recipes `05-props-bake.md` and `10-blender-level.md`). And the **world rules**: water level, terrain shape, what
|
|
16
|
+
exists where, timing and gameplay are not in a style (a dev run throws, `style check` and R34 report it). If the reference shows a different
|
|
17
|
+
world (a canyon instead of hills), say so instead of faking it with colors.
|
|
18
|
+
|
|
19
|
+
## Steps
|
|
20
|
+
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 JSON (colors with share, hue, saturation, brightness, and role hints:
|
|
23
|
+
largest block = ground / environment candidate, brightest = highlight / sky candidate, most saturated = accent candidate, darkest = shadow or
|
|
24
|
+
outline candidate) and one summary line such as `warm colors, mostly sand, low saturation, medium brightness, weak light/dark contrast`. It
|
|
25
|
+
reads pixels in a headless browser (png, jpg, webp, gif, svg). It is a measurement: a picture's biggest block may be a wall you do not want as the
|
|
26
|
+
ground, so look at the picture too. A phone screenshot of a game usually has a dark UI frame that becomes "the biggest block": add
|
|
27
|
+
`--ignore-ui` (cuts a flat frame around the picture) or `--region x,y,w,h` (only that rectangle), `--crop cut.png` to save exactly what was
|
|
28
|
+
measured and open it, and `--average` for the overall mean color (HSL). The output says what area was measured.
|
|
29
|
+
3. **Make the pack.** `npm run new-style sand-dune` creates `packages/styles/sand-dune` from a clean template (gray neutral materials, a sky, one
|
|
30
|
+
palette, no post effects, one palette-colored example model) and links it as `@threedog/style-sand-dune`. Import it in the game:
|
|
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).
|
|
33
|
+
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), `materials` (flat `lambert` for
|
|
35
|
+
a paper look, `toon` for bands, `phong` for shine), `post` (outline for ink lines, bloom for glow, color grading for the final tint), then `ui`.
|
|
36
|
+
Use few colors on purpose: a reference usually has 5 to 8 that matter.
|
|
37
|
+
5. **Check.** `threedog style check sand-dune` (or the folder / file of a game's own style). It checks the final merged style, not each part:
|
|
38
|
+
unknown fields (with "did you mean"), world-state fields, palette keys a model reads but the style does not define, color formats (`'ff8800'`
|
|
39
|
+
without `#`, a float, a string `'0xff8800'`), post-effect conflicts (same name twice, two `scene` effects, a depth reader after a buffer-swapping
|
|
40
|
+
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
|
+
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
|
+
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
|
+
`threedog shot styletest --view overview --time day` (add `--weather rain` or another `--time` for the second shot). Use the style test page's
|
|
45
|
+
named camera positions (see "The style test page" below), not free `--pos` shots.
|
|
46
|
+
Read the two images side by side: reference first, then yours; name the three biggest differences (usually: overall brightness, ground color,
|
|
47
|
+
shadow darkness) and fix those only. Then put numbers on them: `threedog style compare art/reference/ref.png .threedog/shots/styletest.png
|
|
48
|
+
[--region x,y,w,h]` prints brightness, saturation, contrast, fine detail, average and main color of both and one sentence such as "the
|
|
49
|
+
screenshot is 18% darker and 2.3x more broken up". It is an aid to judging, not a replacement for looking: no single number is a quality
|
|
50
|
+
score (there is deliberately no "similarity %"); it turns "looks dirty / fragmented / too dark" into something you can change and re-measure.
|
|
51
|
+
7. **Iterate.** Change one family of values per round (colors, then materials, then post), re-run `style check`, shoot again. Stop when the
|
|
52
|
+
biggest remaining difference is a silhouette or a world rule: that is the asset pack or the game, not the style.
|
|
53
|
+
|
|
54
|
+
## Method lessons (from matching a reference picture)
|
|
55
|
+
- **Measure first, then build.** Run `style palette --average` and `style compare` before touching values; guessing by eye and getting "close" rejected
|
|
56
|
+
several times costs more than ten minutes of measuring.
|
|
57
|
+
- **Take the overall average, not clustered colors.** The tone of a picture is its mean (`--average`), not the 8 colors a median cut finds; a few
|
|
58
|
+
bright accents can dominate the clusters and say little about the look. Use clusters for picking named palette entries, the mean for exposure and tint.
|
|
59
|
+
- **Use the highest-resolution reference you have**, and crop away phone UI (`--ignore-ui` / `--region`). A small, compressed or UI-framed picture
|
|
60
|
+
gives wrong fine-detail and brightness numbers.
|
|
61
|
+
- **Restraint: an effect the reference does not show is not added.** Smudge filters, AO and tone changes stacked together made a picture worse with every
|
|
62
|
+
layer. Start with no post effects, add one only for a visible difference you named, and measure again after each one. `style check` warns when more than 2 are on.
|
|
63
|
+
- **The first frame should already be close.** Get sky, exposure, palette and material type right in the first round; if the first screenshot is far
|
|
64
|
+
from the reference, fix that (one family of values at a time) before adding anything.
|
|
65
|
+
- **Quantify "dirty / fragmented / dark".** Dirty = lower saturation or an off hue (average color), fragmented = fine detail ratio well above 1,
|
|
66
|
+
dark or flat = brightness and contrast. Change one thing, run `style compare` again, keep it if the number moved toward the reference and the picture looks better.
|
|
67
|
+
- **Nothing drawn?** Do not bisect with screenshots: `threedog scene --hidden` lists every mesh that exists but is not drawn and why (hidden parent, layers, scale 0,
|
|
68
|
+
empty geometry, behind the camera...). A mesh that is drawn but far too small is not an error there, but its position and bounding radius are listed:
|
|
69
|
+
compare them with what you meant (`scene` without `--hidden`).
|
|
70
|
+
|
|
71
|
+
## Guard rails
|
|
72
|
+
- Never put gameplay or world values in the pack to match a picture; `style check` reports them as errors.
|
|
73
|
+
- Fonts and textures are asset-pack entries; the style names them (`ui.fonts: ['pixel']`, `terrain.detail.texture`), it does not carry files.
|
|
74
|
+
- Keep `npm run check` at 0 errors; a new pack adds no warnings.
|
|
75
|
+
|
|
76
|
+
## The style test page
|
|
77
|
+
`/styletest.html` (`examples/styletest`) is the one fixed scene a style is judged by: a character, trees, rock, grass, flowers, water, terrain, glass,
|
|
78
|
+
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
|
+
- `threedog shot styletest --view <name> [--time day|dusk|night] [--weather clear|rain|snow]`; the same words work as URL parameters
|
|
80
|
+
(`?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, read overall brightness, ground color, shadow darkness), `character` (close-up: character colors, outline, shadow on
|
|
82
|
+
the ground), `water` (water color, shore, fog at distance), `room` (the lamp and window light against the dark corners: ambient level, `ao`, bloom),
|
|
83
|
+
`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
|
+
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`; compare with the reference, name the three biggest differences, fix those.
|
|
86
|
+
- `?panel=1` opens the workbench (needs the dev package `tweakpane`, installed with the repository's `npm install`; without it the page says so).
|
|
87
|
+
Live sliders change exposure, sky time, environment lighting, water color, post effects and UI colors at once; palette, terrain and wave values
|
|
88
|
+
are marked "needs rebuild" and only apply after "apply and rebuild". "export overrides" prints an object literal to paste into
|
|
89
|
+
`style: [lowpoly, { ... }]`; the original pack is never written, so the paste is the one place the change becomes real.
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# Sky, ground and plant looks: what a style can change
|
|
2
|
+
|
|
3
|
+
For an AI turning a reference picture into a style pack and hitting "the engine draws it this way". Colors and materials are in `09-style-pack.md`, the
|
|
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. Every default below is the original look, bit for bit; a style that sets nothing here draws what it always drew. Style packs hold looks only
|
|
6
|
+
(rule R34): none of these settings move a hill, a river or a species list.
|
|
7
|
+
|
|
8
|
+
## Sky clouds: `style.sky.clouds`
|
|
9
|
+
| Key | Meaning | Default |
|
|
10
|
+
|---|---|---|
|
|
11
|
+
| `color`, `shade`, `coverage`, `scale`, `speed` | as before; coverage multiplies the weather's cloud amount | |
|
|
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
|
+
| `horizon` | added to `dir.y` before projecting; smaller = clouds shrink and crowd more towards the horizon | plane 0.08, cumulus 0.5 |
|
|
14
|
+
| `fade` | `[from, to]` in `dir.y`: invisible below `from`, full above `to` | plane `[0, 0.18]`, cumulus `[0, 0.12]` |
|
|
15
|
+
| `opacity`, `softness` | cloud alpha; width of the cloud edge | 0.9 / 0.3 (cumulus 0.95 / 0.35) |
|
|
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
|
+
| `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
|
+
|
|
20
|
+
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
|
+
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
|
|
22
|
+
`kind: 'cumulus'`, or raise `horizon` (0.3-0.6) and lower `scale`. Cost: both are one 2D pass over the dome (no ray marching); cumulus is about
|
|
23
|
+
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
|
+
(`style.clouds.shadow`, a separate setting) follow the same weather cover, so more clouds still means more shadow.
|
|
25
|
+
|
|
26
|
+
```js
|
|
27
|
+
sky: { clouds: { kind: 'cumulus', coverage: 1, scale: 0.45, color: 0xfff4e4, shade: 0x8a9cb8, speed: [0.003, 0.001] } }
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Your own cloud function
|
|
31
|
+
`clouds.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
|
+
```glsl
|
|
33
|
+
vec4 threedogClouds(vec3 dir, float time, vec3 sunDir, float night, vec3 lit, vec3 shade, float cover)
|
|
34
|
+
// dir: unit view direction, dir.y > 0. sunDir: towards the sun (the moon is opposite). night: 0 day .. 1 night.
|
|
35
|
+
// lit / shade: clouds.color / clouds.shade. cover: weather cloud amount * clouds.coverage.
|
|
36
|
+
// return: rgb = final cloud color (dim it at night yourself), a = opacity (apply your own horizon fade).
|
|
37
|
+
```
|
|
38
|
+
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
|
+
your `clouds.uniforms` (declared for you; number, `THREE.Color`, `THREE.Vector2/3/4`, array of 2-4 numbers, or `THREE.Texture`). Change one later
|
|
40
|
+
with `engine.sky.dome.material.uniforms.uBrush.value = 0.5`. A bad `kind`, a `glsl` without the function, or an unsupported uniform value throws with the fix.
|
|
41
|
+
Gouache-style flat cloud blobs with a paper texture:
|
|
42
|
+
```js
|
|
43
|
+
clouds: { color: 0xfff1dc, shade: 0x9aa8c4, uniforms: { uPaper: paperTexture, uEdge: 0.06 }, // paperTexture: any THREE.Texture, repeat wrapping
|
|
44
|
+
glsl: `vec4 threedogClouds(vec3 d, float time, vec3 sunDir, float night, vec3 lit, vec3 shade, float cover){
|
|
45
|
+
vec2 p = d.xz / (d.y + 0.5) * 0.4 + vec2(0.004, 0.002) * time;
|
|
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, painted edge
|
|
48
|
+
float up = clamp(0.5 + (n - threedogNoise(p + sunDir.xz * 0.1)) * 6.0, 0.0, 1.0); // sun side
|
|
49
|
+
vec3 c = mix(shade, lit, up) * texture2D(uPaper, p * 3.0).rgb * (0.35 + 0.65 * (1.0 - night));
|
|
50
|
+
return vec4(c, a * smoothstep(0.0, 0.1, d.y));
|
|
51
|
+
}` }
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Ground color: `style.terrain.variation`
|
|
55
|
+
Terrain colors are baked per vertex by the (worker) generator from the palette. Before, two palette colors were blended by a noise of about 30 m
|
|
56
|
+
wavelength and every 1/3 m cell got a 0.92-1.04 brightness grain, both fixed. Now (plain data, so it travels to the workers; unknown keys throw):
|
|
57
|
+
```js
|
|
58
|
+
terrain: { colors: { ... }, biomeColors: { ... },
|
|
59
|
+
variation: {
|
|
60
|
+
blend: { size: 33, strength: 1 }, // wavelength in m of the two-color noise; strength > 1 = harder contrast, < 1 = flatter
|
|
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: painted color blocks
|
|
63
|
+
} }
|
|
64
|
+
```
|
|
65
|
+
`patches` is off unless given. It is a noise much larger than `blend`; `levels: 4` snaps it to 4 flat steps (brush-stroke blocks instead of soft
|
|
66
|
+
clouds); 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 strokes use a texture (next).
|
|
68
|
+
|
|
69
|
+
### A texture on the ground (brush strokes, paper, grain)
|
|
70
|
+
`style.terrain.material` (a Material or `(engine) => Material`) replaces the ground material. Chunk geometry has `uv = world xz / chunk size`, continuous
|
|
71
|
+
across chunk borders (checked by `tests/specs/appearance.mjs`), so a repeating texture is seamless whatever chunk it lands in; cloud shadows and
|
|
72
|
+
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
|
+
from the world position in a patch instead (`needs.patches: ['world']` gives `vThreedogWorld`):
|
|
74
|
+
```js
|
|
75
|
+
material: engine => applyEffects(new THREE.MeshLambertMaterial({ vertexColors: true }), { clouds: false, patches: [{
|
|
76
|
+
name: 'triplanar', needs: { patches: ['world'] }, uniforms: { uBrush: { value: brushTexture }, uBrushScale: { value: 0.1 } }, // brushTexture: repeat wrapping
|
|
77
|
+
glsl: { fragment: { pars: 'uniform sampler2D uBrush; uniform float uBrushScale;',
|
|
78
|
+
color_fragment: `vec3 n = abs(normalize(cross(dFdx(vThreedogWorld), dFdy(vThreedogWorld)))); n /= n.x + n.y + n.z;
|
|
79
|
+
diffuseColor.rgb *= texture2D(uBrush, vThreedogWorld.zy * uBrushScale).rgb * n.x + texture2D(uBrush, vThreedogWorld.xz * uBrushScale).rgb * n.y
|
|
80
|
+
+ texture2D(uBrush, vThreedogWorld.xy * uBrushScale).rgb * n.z;` } } }] })
|
|
81
|
+
```
|
|
82
|
+
A procedural noise texture is a `THREE.DataTexture` filled in a loop (`wrapS = wrapT = THREE.RepeatWrapping`, `colorSpace = THREE.SRGBColorSpace`,
|
|
83
|
+
`needsUpdate = true`); `style.terrain.detail` (an asset texture multiplied in, `strength` 0-1) is the lighter alternative when the grain is a picture; on any other surface use the
|
|
84
|
+
`detail` key of a material spec (recipe 37).
|
|
85
|
+
|
|
86
|
+
## Plants and wind
|
|
87
|
+
Audit of what the vegetation code fixes, split into mechanism (stays) and look (made a setting):
|
|
88
|
+
|
|
89
|
+
| Where | What | Kind |
|
|
90
|
+
|---|---|---|
|
|
91
|
+
| `Vegetation.add` | per species: `wind` amplitude, `rule`, `lodRing`, `maxRing`, `nearOnly`, `castShadow`, `shadowRing`, `material`, `effects` | already options (game content) |
|
|
92
|
+
| `GroundChunks`, `Vegetation.levelOf` | one InstancedMesh per species per chunk; rings decide LOD swap, draw distance, shadow distance; 3 ms placement budget; collision lag | mechanism, stays |
|
|
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: **`style.wind.glsl`** replaces it |
|
|
94
|
+
| 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 37 |
|
|
96
|
+
| defaults | `castShadow` = not `nearOnly`, `shadowRing` 1, `lodRing` 1 | per-species options, set them in the species |
|
|
97
|
+
|
|
98
|
+
```js
|
|
99
|
+
wind: { frequency: 1, uniforms: { uSteps: 3 }, // pose-to-pose sway for a painted look: 3 poses instead of a smooth sine
|
|
100
|
+
glsl: `void threedogWind(inout vec3 transformed, vec3 ip, vec3 position){
|
|
101
|
+
float s = floor(sin(uTime * uWindFreq + ip.x * 0.3 + ip.z * 0.2) * uSteps) / uSteps;
|
|
102
|
+
transformed.x += s * max(position.y, 0.0) * THREEDOG_WIND_AMP * uWind;
|
|
103
|
+
}` }
|
|
104
|
+
```
|
|
105
|
+
`threedogWind` receives the vertex (`transformed`, object space), `ip` (world position of this plant's origin, so each plant has its own phase) and
|
|
106
|
+
`position`; `uTime`, `uWind` (weather), `uWindFreq` and `THREEDOG_WIND_AMP` (the species' amplitude) are in scope. It applies to every material made by
|
|
107
|
+
`vegetation.add` that has `wind` set, and the shadow sways with it. A missing function throws with the signature. The same object works in code:
|
|
108
|
+
`applyEffects(mat, { wind: { amplitude: 0.03, glsl, uniforms } })`.
|
|
109
|
+
|
|
110
|
+
Cost, measured with software rendering (relative numbers only): 10,000 grass blades of 6 triangles in one InstancedMesh draw in 1 call; per frame
|
|
111
|
+
about 120 ms with no wind, default wind and a custom sway alike, so the sway function is not where grass time goes (vertex count and fill are).
|
|
112
|
+
Reduce grass cost with `rule.perChunk`, `maxRing` and `nearOnly`, not the wind.
|
|
113
|
+
|
|
114
|
+
## What is still fixed
|
|
115
|
+
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.add` your own `geometry` or `model`.
|