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,159 @@
|
|
|
1
|
+
# Props and baking
|
|
2
|
+
|
|
3
|
+
**Props** are a small number of hand-placed objects (a tree next to a cabin, rocks, street lamps). Write them as data; each entry becomes an ordinary
|
|
4
|
+
`kind: 'prop'` record in `engine.world` (needs `world()`, which `openWorld()` already includes). The model is created only when the player gets close
|
|
5
|
+
(within terrain view distance), and **the collision body and ray registration are built with the model and removed when the player leaves** (only
|
|
6
|
+
things near the player need to block the way).
|
|
7
|
+
Large repeated areas (forests, grass) don't use this; use `content/vegetation.js` (instanced vegetation).
|
|
8
|
+
|
|
9
|
+
## 1. Prop data
|
|
10
|
+
`games/<game>/content/props.js` (a list; remember to add it to `content/index.js`):
|
|
11
|
+
```js
|
|
12
|
+
export default [
|
|
13
|
+
{ model: 'pine', place: 'home', x: -8, z: -6, scale: 1.2, collide: 'circle' }, // an asset name (here a generator of the lowpoly asset pack)
|
|
14
|
+
{ model: ['flower', 0xf2d16b], place: 'home', x: 1.6, z: 3.4 }, // a generator with arguments, use an array: flower(0xf2d16b)
|
|
15
|
+
{ model: 'rock', x: 120, z: -40, rot: 0.6, scale: 0.8, collide: 'box' }, // no place = world coordinates; rot in radians
|
|
16
|
+
{ model: 'well', place: 'home', x: 4, z: -4, y: 0, collide: 'box' }, // a file asset: assets.model('well')
|
|
17
|
+
{ model: 'crate', place: 'tower', x: 1, floor: 6, y: 0.5 }, // on the tower's second floor (not its roof), half a meter up
|
|
18
|
+
];
|
|
19
|
+
```
|
|
20
|
+
Fields: `id` (stable id, see below), `model`, `place` + `x/z` (relative to the place), `floor` (on multi-layer ground — a second storey, a bridge
|
|
21
|
+
deck, a lower dungeon level — the reference height of the layer it stands on; a level-marker place lends its own height), `y` (height above that
|
|
22
|
+
ground), `rot`, `scale`, `collide` (`'box'` / `'circle'` / omitted = does not block), `static: false` (do not register for rays), `batch: false` (see 2b).
|
|
23
|
+
An entry with `template` instead of `model` (`{ template: 'chest', x: 3, z: 1 }`) places an instance of a content template: a reusable object with
|
|
24
|
+
interaction, container and saved state (recipe 30).
|
|
25
|
+
A model is always an **asset name**, never a path or a function (`npm run check` reports both): register it in a manifest or asset pack first. A
|
|
26
|
+
generator entry is built through `engine.assets.cached` (params from the array), a file entry through `engine.assets.model`:
|
|
27
|
+
```js
|
|
28
|
+
import { assets as lowpolyAssets } from '@threedog/style-lowpoly';
|
|
29
|
+
engine.assets.manifest(lowpolyAssets); // pine, rock, ['flower', color]...
|
|
30
|
+
engine.assets.manifest({ name: 'props', models: { well: '/models/well.glb' } });
|
|
31
|
+
```
|
|
32
|
+
Props with the same model share one prototype (geometry and material are built once); each spot gets a clone.
|
|
33
|
+
|
|
34
|
+
**Stable ids and saves**: if you write an `id` it is used; otherwise the id is `prop:<model name>:<index in the props array>` (for a model with
|
|
35
|
+
arguments, the name is used, e.g. `prop:flower:5`). The same content gives the same ids on every load, with no collisions (two colliding ids throw
|
|
36
|
+
during development and say how to fix it).
|
|
37
|
+
Inserting a new entry in the middle shifts the later indexes, so moves / deletions in old saves no longer match. **Give an `id` to any prop whose
|
|
38
|
+
content may still change.**
|
|
39
|
+
Get them in code, move or delete them (all saved with the game):
|
|
40
|
+
```js
|
|
41
|
+
engine.world.query({ kind: 'prop' }); // all prop data { id, position, model, rot, scale, collide ... }
|
|
42
|
+
engine.world.move('prop:rock:3', { x: 12, z: -4 }); // move: model, collision and ray registration follow; height is recomputed from the ground
|
|
43
|
+
engine.world.set('prop:rock:3', { rot: 1.2, scale: 1.5 }); // change rotation / size
|
|
44
|
+
engine.world.remove('prop:pine:0'); // delete (model and collision are removed together)
|
|
45
|
+
engine.world.view('prop:rock:3'); // the current model (null when the player is not near)
|
|
46
|
+
```
|
|
47
|
+
Props are the world's **initial data**: a save records only moves, changes and deletions, so the result is the same whether `content.load` runs before
|
|
48
|
+
or after loading a save (a deleted prop never reappears); props added to the content in a game update also show up when an old save is loaded.
|
|
49
|
+
A prop whose position uses a level marker carries a `zone` (= level name): changing level only removes the model, and moves / deletions are still
|
|
50
|
+
there when you come back.
|
|
51
|
+
Procedural models of an asset pack (both props and vegetation) go through `engine.assets.cached(modelName, generator, args)`: if baked, the file in
|
|
52
|
+
`public/models/baked/` is read; during development the result is cached automatically.
|
|
53
|
+
Models are obtained asynchronously and the loading screen waits for them (`engine.world.ready`: every model that should exist nearby at the start is
|
|
54
|
+
built); `world.view(id)` works after `start()`; a model built later when the player walks up appears one or two frames late (to wait,
|
|
55
|
+
`await engine.world.whenReady`).
|
|
56
|
+
If a model fails to generate, world reports it once in the console, does not block loading, and retries when the player walks away and comes back.
|
|
57
|
+
|
|
58
|
+
## 2. Large code-generated models and baking
|
|
59
|
+
Big things assembled in code, such as a city block or a whole house, are written as a function, registered in the manifest and fetched by name. During
|
|
60
|
+
development they are cached automatically (.threedog/cache) and recomputed when the code changes:
|
|
61
|
+
```js
|
|
62
|
+
import { buildBlock } from './block.js';
|
|
63
|
+
engine.assets.manifest({ models: { 'city-block': buildBlock } }); // the function returns an Object3D or a geometry
|
|
64
|
+
const block = await engine.assets.model('city-block');
|
|
65
|
+
engine.use(level({ url: 'city-block' })); // a level reads it by name (the city example does this): baked file and cache both apply, and loading a save can switch back to this map
|
|
66
|
+
```
|
|
67
|
+
To package a release or edit it in Blender, create `bake.js` in the game folder (`npm run bake -- -w <game>` looks for `bake.js` in that game's folder
|
|
68
|
+
and for the `assets` export of each style pack's `index.js`: `packages/styles/*` in the monorepo, `node_modules/@threedog/style-*` in a game's own repository):
|
|
69
|
+
```js
|
|
70
|
+
// games/<game>/bake.js
|
|
71
|
+
import { buildBlock } from './block.js';
|
|
72
|
+
export const bake = { 'city-block': () => buildBlock() };
|
|
73
|
+
```
|
|
74
|
+
`npm run bake` exports to this game's `public/models/baked/<name>.glb` and writes `index.json`; afterwards `assets.model('city-block')` with the same
|
|
75
|
+
name reads the file.
|
|
76
|
+
If the generating code changes again: during development you are told to "switch to computing it live", and `npm run build` fails to remind you to
|
|
77
|
+
bake again. To keep editing in Blender, write that entry in `bake.js` as `{ build, source: 'file' }`; it is never overwritten afterwards.
|
|
78
|
+
|
|
79
|
+
## 2b. Many copies of one model: automatic batching
|
|
80
|
+
Nothing to write: the engine (`engine.batching`, core) watches what is added to the scene, so props, `world.present` views, grid items, `stream`
|
|
81
|
+
builds and anything you `engine.add` are covered. When the same geometry + material (+ shadow flags) appears at least 8 times in one 64 m cell, those
|
|
82
|
+
meshes are drawn by one real `THREE.InstancedMesh` per cell; fewer stay plain meshes. Each placed object stays in the scene with its own userData,
|
|
83
|
+
record, collision and interactions; only its meshes are moved to layer 31 (not drawn), so `engine.raycast` / `pick` / photo return the original
|
|
84
|
+
object, not an instance index.
|
|
85
|
+
```js
|
|
86
|
+
const crate = engine.world.view('crate_3');
|
|
87
|
+
if (crate) {
|
|
88
|
+
engine.batching.tint(crate, 0xff8080); // recolor one copy (instance color; null restores)
|
|
89
|
+
engine.batching.of(crate); // [{ mesh: InstancedMesh, index }], [] when drawn on its own
|
|
90
|
+
}
|
|
91
|
+
engine.batching.batches; // [{ mesh, cell, count, items }] for inspection
|
|
92
|
+
engine.batching.stats; // { batches, instances, saved } (also describe().perf.batching)
|
|
93
|
+
engine.batching.enabled = false; // global switch; createEngine({ batching: false }) never starts it, { minCount, cell } tunes it
|
|
94
|
+
```
|
|
95
|
+
- Move / hide / remove a copy as usual (`world.move`, `obj.visible = false`, `engine.remove`): its instance follows next frame; unloading a cell frees
|
|
96
|
+
its batch.
|
|
97
|
+
- Opt out: `batch: false` on a prop entry, or `userData.batch = false` on a model (clones inherit it, so set it on the prototype). Do this for models
|
|
98
|
+
whose parts you animate or whose materials you swap; if you forget, the copy is taken out of its batch automatically with a one-time dev warning.
|
|
99
|
+
- Never batched: skinned, morphing or animated models, multi-material or transparent meshes, `ShaderMaterial`, meshes with children, and level
|
|
100
|
+
geometry `hlod` registered (hlod owns far, batching owns near).
|
|
101
|
+
|
|
102
|
+
## 3. Loading: what is it waiting for, what failed, does it block the start
|
|
103
|
+
Every asset load is a task in `engine.loading` (so are module init / `isReady`, the stream's nearby builds and the game's own steps). Each task has a
|
|
104
|
+
phase (`queued` → `download` → `decode` → `upload` / `build` → `done` | `failed`), progress, the error (file, HTTP status, a texture or `.bin` the
|
|
105
|
+
model references but could not load) and its source (which manifest, which path, file version, animation names).
|
|
106
|
+
Decide per entry what a failure means:
|
|
107
|
+
```js
|
|
108
|
+
engine.assets.manifest({
|
|
109
|
+
name: 'forest', // the source label in engine.loading (default 'manifest#1')
|
|
110
|
+
models: {
|
|
111
|
+
hero: { url: '/models/hero.glb', critical: true }, // the game cannot start without it: start() stops and says why
|
|
112
|
+
bush: '/models/bush.glb', // degradable (default): a gray placeholder, the game continues
|
|
113
|
+
fern: { url: '/models/fern.glb', fallback: 'bush' }, // degradable, shows another entry instead
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
const level = await engine.loading.track('level-data', () => fetch('/levels/1.json').then(r => r.json())); // the game's own step, critical by default
|
|
117
|
+
```
|
|
118
|
+
- Finished is not succeeded: `describe().loading` has `done` (nothing pending) and `ok` (nothing failed, no missing references); `blocked` is true
|
|
119
|
+
when a critical item failed before the start. `waiting` names the current item, e.g. `decoding model "hero" (/models/hero.glb, manifest "forest")`.
|
|
120
|
+
- `threedog loading` prints the same view (it answers while `start()` is still running or stuck); `threedog loading hero` shows one task with its
|
|
121
|
+
source. Failures also go to `.threedog/errors.log` with the likely cause.
|
|
122
|
+
- The loading-screen part gets the current item as `text`; when a critical item fails it gets `failed` and stays up (class `.threedog-loading-failed`).
|
|
123
|
+
- Unregistered paths (`assets.model('/x.glb')`) and code-generated models do not fall back: the error goes to the caller, and the task shows it.
|
|
124
|
+
|
|
125
|
+
## 3b. Asset packs (a folder or npm package of files)
|
|
126
|
+
An asset pack is a manifest someone else wrote: `{ name, base, models, textures, sounds, fonts }`, names only, no code that runs at load. `base`
|
|
127
|
+
resolves the pack's relative paths (`'/x'` and full URLs stay as written), so the same pack works from `public/`, a CDN or `node_modules`:
|
|
128
|
+
```js
|
|
129
|
+
// public/packs/forest/pack.js, or the main file of an npm package `forest-assets`
|
|
130
|
+
export default { name: 'forest', base: '/packs/forest/', models: { oak: 'oak.glb', fern: { url: 'fern.glb', fallback: 'oak' } }, sounds: { creek: 'creek.ogg' } };
|
|
131
|
+
// an npm package lets vite find and emit each file: models: { oak: new URL('./oak.glb', import.meta.url).href }
|
|
132
|
+
// (keep such a package out of vite's dependency pre-bundling: optimizeDeps: { exclude: ['forest-assets'] })
|
|
133
|
+
import forest from 'forest-assets';
|
|
134
|
+
engine.assets.manifest(forest); // content and code now say 'oak', 'creek'
|
|
135
|
+
engine.assets.manifest({ name: 'mine', models: { oak: '/models/my-oak.glb' } }); // a later pack replaces a name it shares
|
|
136
|
+
```
|
|
137
|
+
A generator function is also an entry (`models: { pine: () => geometry }`): the lowpoly package exports its procedural models this way as `assets`.
|
|
138
|
+
|
|
139
|
+
Fonts are entries too, and a style names them instead of holding the file (a style is looks only):
|
|
140
|
+
```js
|
|
141
|
+
const engine = createEngine({ canvas, style: [lowpoly, { ui: { fonts: ['pixel', 'pixelBold'], font: '"pixel", system-ui' } }] });
|
|
142
|
+
engine.assets.manifest({ name: 'ui-fonts', base: '/fonts/', fonts: { pixel: 'pixel.woff2', pixelBold: { url: 'pixel-bold.woff2', family: 'pixel', weight: 700 } } });
|
|
143
|
+
```
|
|
144
|
+
`family` defaults to the asset name; the other keys are FontFace descriptors (`weight`, `style`, `unicodeRange`, ...). `start()` loads the fonts
|
|
145
|
+
`style.ui.fonts` lists (an unknown name stops it with the line to add); other font entries load only on `engine.assets.font(name)` or with
|
|
146
|
+
`preload: true`. A file that fails falls back to the next family of `style.ui.font` unless it is `critical`.
|
|
147
|
+
|
|
148
|
+
## 4. Verify
|
|
149
|
+
- `npm run check`: prop model names and place names are validated. After `npm run map`, GAMEMAP.md has a props table.
|
|
150
|
+
- Loading: `engine.loading.list({ phase: 'failed' })` should be empty; related test `npm test -- 加载可观察`.
|
|
151
|
+
- `describe().content.props` is the number of prop entries; when the player is near, named objects appear in `nearby`
|
|
152
|
+
(`npm run shot -- / --pos x,z --describe-only`).
|
|
153
|
+
- Collision: `engine.collision.walkable({ x, z })` should be false at a prop's position.
|
|
154
|
+
- Baking: `npm run bake` prints each item's size; related test `npm test -- 烘焙`. To look at the picture: `npm run shot -- / --pos x,z`.
|
|
155
|
+
|
|
156
|
+
## 5. Deleting objects
|
|
157
|
+
`engine.remove(obj)` deletes an object and frees its GPU memory; `engine.detach(obj)` only takes it off for a while (add it back with `engine.add`).
|
|
158
|
+
Don't call `obj.removeFromParent()` or `scene.remove()` on meshes you built: their geometry and materials would leak.
|
|
159
|
+
(`thing.remove` (`41-thing-registry.md`) deletes a registered object so that an undo can bring it back; `engine.remove` is final.)
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# Scheduling events on the game clock
|
|
2
|
+
|
|
3
|
+
## The time table (the single source; other docs link here)
|
|
4
|
+
Two fixed names: **fixed seconds** (fixed-step seconds: the `dt` of `onFixed` / module `fixed` / `world.simulate`, the N of `engine.step(N)`,
|
|
5
|
+
`engine.elapsed`; never multiplied by the time scale) and **game seconds** (`engine.clock.now` = fixed seconds x `clock.timeScale`). "Game time" is
|
|
6
|
+
not a unit: always say one of the two. A third ruler, **sky time of day** (`engine.sky.timeOfDay`, 0-1), is derived from game seconds: one day =
|
|
7
|
+
`sky.dayLength` game seconds. **Frame seconds** (the `dt` of `onFrame` / module `frame`) are for presentation only.
|
|
8
|
+
|
|
9
|
+
| Use it for | Time to use | Paused / frozen | `timeScale = 2` (one real second at 60 Hz) |
|
|
10
|
+
|---|---|---|---|
|
|
11
|
+
| Movement, camera follow, physics (Rapier), AI steering | fixed seconds (`dt` in `onFixed` / `fixed`) | stops | unchanged: speed in m/s stays the same |
|
|
12
|
+
| Action judgement and action timelines (hit windows, invulnerability, "finish the swing"), cooldowns, hit-stop | fixed seconds: accumulate `dt` in `onFixed`, or a per-entity fixed-step counter | stops | unchanged: a 0.6 s swing is still 0.6 s |
|
|
13
|
+
| `world.simulate` near / far, dialogue typing, cutscenes, `engine.step(N)` | fixed seconds | stops | unchanged |
|
|
14
|
+
| Crop / entity growth, vegetation and pickup respawn, "ripe after 10 minutes" | game seconds (`clock.now`, `clock.after / every`; saved) | stops | twice as fast: growth that needs 600 game seconds is ripe after 300 fixed seconds |
|
|
15
|
+
| Calendar, day, season, clock hours, lamps and shop doors (`sky.at / between / daily / onSeason`) | sky time of day (derived from game seconds) | stops | twice as fast: with `dayLength = 360` one sky hour (15 game seconds) passes in 7.5 fixed seconds |
|
|
16
|
+
| UI animation and effects that follow the game (bobbing, sway) | `engine.elapsed` (fixed seconds) | stops | unchanged |
|
|
17
|
+
| Menu / HUD animation that must keep running while paused | frame seconds (`onFrame` `dt`) | keeps running | unchanged |
|
|
18
|
+
| Toast and loading fade-out, music volume fades | real time (they never affect gameplay) | keeps running | unchanged |
|
|
19
|
+
| `saves.autosave(minutes)` | fixed seconds of play (only while a playthrough runs: not on the title screen, not during newGame / load) | stops | unchanged |
|
|
20
|
+
|
|
21
|
+
Rules that follow: gameplay timing is in fixed seconds unless it is a thing the world does by itself over days (growth, respawn, calendar), which is
|
|
22
|
+
in game seconds. At `timeScale = 0` game seconds stop (no `clock.after` fires, crops stop), but movement and cooldowns still run; a game that freezes
|
|
23
|
+
the sky time of day (e.g. `clock.timeScale = 0`) must not use `clock.after` for gameplay delays. Conversion: 1 sky hour = `dayLength / 24` game
|
|
24
|
+
seconds, 1 sky minute = `dayLength / 1440` game seconds (with `dayLength = 360`, as in `presets.calendar.cycle`: 1 sky hour = 15 game seconds). With
|
|
25
|
+
`timeScale = 10`, `step(10)` advances 100 game seconds = 6.7 sky hours. The docs say "game seconds" and "N sky hours/minutes", never "game minutes".
|
|
26
|
+
Neither fixed seconds nor `engine.elapsed` is saved; to keep a cooldown across a save, store it in a world record. Don't use `setTimeout` /
|
|
27
|
+
`setInterval` / `performance.now()` (they ignore pause, are not saved, and can't be tested with fast-forward). The engine itself runs on the fixed
|
|
28
|
+
step except the real-time items in the last table row.
|
|
29
|
+
"After how long / every how long" uses `engine.clock` (part of the core); "at what time every day / within a time window / when the season changes"
|
|
30
|
+
uses `engine.sky` (needs the `sky()` module with a `dayLength`; at a fixed time of day these never fire).
|
|
31
|
+
|
|
32
|
+
## 1. Where to write it
|
|
33
|
+
Game logic goes in `games/<game>/main.js` (or the game's own module); a one-off story timer can also be started by a dialogue / quest effect and then
|
|
34
|
+
call `after` in code.
|
|
35
|
+
|
|
36
|
+
```js
|
|
37
|
+
import { parseClock, formatClock } from 'threedog';
|
|
38
|
+
|
|
39
|
+
// Time-window switch: lamps on from 18:00 to 06:00 (crosses midnight). On registration, at start, after loading a save, applyState, or turning the time back, it aligns to the current time immediately (returns a handle; lampHours.remove() cancels)
|
|
40
|
+
const lampHours = engine.sky.between('18:00', '06:00', { on: () => lamp.visible = true, off: () => lamp.visible = false });
|
|
41
|
+
|
|
42
|
+
// An event when a clock time is crossed (an "action" once per day): open the market at 12:00
|
|
43
|
+
engine.sky.at('12:00', day => market.open(), { days: [1, 3, 5] }); // only on days 1, 3, 5; a function also works: day => day % 7 === 6
|
|
44
|
+
|
|
45
|
+
// After how long: pass an event name to make it saveable (still fires after loading a save); a function cannot be saved
|
|
46
|
+
engine.clock.after(120, 'bread:ready', { oven: 1 });
|
|
47
|
+
engine.events.on('bread:ready', ({ oven }) => engine.inventory?.add('bread', 1));
|
|
48
|
+
|
|
49
|
+
engine.clock.every(30, () => spawnBird()); // every 30 game seconds (not 30 sky seconds)
|
|
50
|
+
engine.sky.daily(day => console.log('day', day)); // every day at 00:00
|
|
51
|
+
engine.sky.onSeason('winter', () => engine.weather?.set('snow', 20)); // needs seasons (presets.calendar.fourSeasons) and a 'snow' weather (presets.weather.temperate)
|
|
52
|
+
|
|
53
|
+
// Clock conversion: 'HH:MM' <-> fraction of a day 0-1
|
|
54
|
+
engine.sky.timeOfDay = parseClock('17:30'); // jump straight to 17:30 (see the catch-up rules below)
|
|
55
|
+
formatClock(engine.sky.timeOfDay); // '17:30'
|
|
56
|
+
```
|
|
57
|
+
**Use between for states, at for actions.** "The lamp is on, the shop is open, the NPC is home" are states, so use `between`: it checks the current
|
|
58
|
+
time every step, and no way of jumping the time can leave the state wrong.
|
|
59
|
+
`at` is an event for "crossing a clock time", with these catch-up rules:
|
|
60
|
+
- It fires only when time moves **forward** across the time: walking naturally, `step` fast-forward, or setting `sky.timeOfDay` later (17:00 -> 19:00
|
|
61
|
+
on the same day). When several trigger points are crossed at once, `catchUp` decides: `'once'` fires once (default), `'all'` fires them all,
|
|
62
|
+
`'skip'` fires none.
|
|
63
|
+
- Turning time **back** does not fire; it only resets the baseline: `applyState({ time })` to an earlier time, or lowering `sky.timeOfDay` (19:00 ->
|
|
64
|
+
05:50 is going back within the same day, not "a night passed").
|
|
65
|
+
- Loading a save does not fire; it only resets the baseline (trigger points between the save and the load are not made up).
|
|
66
|
+
So "applyState to 05:50, then wait until 06:00" fires the 06:00 `at`, but after "applyState back to 17:50" the lamp will not switch itself off: use
|
|
67
|
+
`between` for states like a lamp.
|
|
68
|
+
Length of a day: `openWorld({ camera: 'follow', dayLength: 600 })` / `sky({ dayLength })` (game seconds; without it the time of day never moves,
|
|
69
|
+
`presets.calendar.cycle` is 360); `engine.clock.timeScale` speeds things up temporarily (see the table above).
|
|
70
|
+
For "which time" or "has this been done" in a story, use `engine.vars.bump / setFlag`; don't keep your own variables (vars are saved automatically).
|
|
71
|
+
|
|
72
|
+
## 2. Skipping time (sleep until morning, wait an hour)
|
|
73
|
+
`engine.skip` moves game seconds and the sky clock forward without running every fixed step, so even a game with a real-length day can sleep through
|
|
74
|
+
the night instantly.
|
|
75
|
+
```js
|
|
76
|
+
await engine.skip({ to: '06:00' }); // until the sky clock next reads 06:00 (at 06:00 exactly: a full day; throws when sky has no dayLength)
|
|
77
|
+
engine.skip({ seconds: 600 }); // 600 game seconds
|
|
78
|
+
await engine.skip({ to: '06:00', fade: 0.6, save: 'auto' }); // fade out, jump, save, fade in (through flow.transition when flow is installed)
|
|
79
|
+
engine.events.on('time:skip', ({ seconds }) => engine.vars.bump('restSeconds', seconds)); // after the jump
|
|
80
|
+
```
|
|
81
|
+
What catches up, and how:
|
|
82
|
+
- `clock.after / every`, `sky.at / daily / between`, `day:start`, `season:change` fire **in time order, once per crossing, as if stepped** (a 3-day
|
|
83
|
+
sleep fires `daily` 3 times; `catchUp` does not apply). Inside a callback `clock.now` and `sky.timeOfDay` already read the callback's own moment.
|
|
84
|
+
- World records with `far` catch up the whole span in **one** `far(rec, dt)` at the end (dt in fixed seconds = game seconds / `timeScale`), near ones
|
|
85
|
+
included; kinds with only `near` are not made up. Growth and respawns measured with `clock.now` (entities, pickups, vegetation, the crop example in
|
|
86
|
+
recipe 18) are exact; a far function that accumulates dt matches stepping within one far turn (`world.farEvery`); schedule NPCs end at the same
|
|
87
|
+
place within one far turn of walking.
|
|
88
|
+
- Not run while skipping: `onFixed`, module `fixed` hooks, physics, near simulation. Fixed seconds (`engine.elapsed`, `engine.tick`, cooldowns) do not
|
|
89
|
+
move. So anything that must advance during a sleep is measured in game seconds (`clock.now`) or lives in a world record with `far`.
|
|
90
|
+
- Input is locked and gameplay frozen for the whole skip (keys pressed during the fade do nothing). With `fade: 0` (default) the time has moved when
|
|
91
|
+
`skip` returns; with a fade the Promise resolves after the fade in, which needs frames (in a paused test keep calling `engine.step`).
|
|
92
|
+
- `timeScale = 0` skips as if at 1x. The jump itself is the op `time.skip { seconds }` (logged and replayable; it refuses `seconds <= 0`).
|
|
93
|
+
- A module that keeps its own time implements the hook `skip(dt, e, done)` (called once per segment; `done` on the last one).
|
|
94
|
+
|
|
95
|
+
### Order inside one frame
|
|
96
|
+
Each rendered frame runs: input poll -> the fixed steps due (`commits` applied first, then `onFixed`, module `fixed` hooks, clock timers) -> `onFrame`
|
|
97
|
+
callbacks **in the order they were registered** -> module `frame` hooks -> stream / jobs / batching -> render -> `afterRender` hooks. The animation of a model
|
|
98
|
+
from `engine.assets.animate` (and a Character's model) is itself an `onFrame` callback registered when the animator was created, so your `onFrame` runs
|
|
99
|
+
before it if you registered first (you see last frame's pose) and after it if you registered later. To read or override a pose after animation, register
|
|
100
|
+
the callback after the model is created, or use an `afterRender` hook.
|
|
101
|
+
|
|
102
|
+
## 3. Verify
|
|
103
|
+
- Without waiting real time: in a test or the console, `engine.sky.timeOfDay = parseClock('17:59'); engine.step(5)`, then look at the result (`step`
|
|
104
|
+
returns the describe).
|
|
105
|
+
Time-window switch: after `await engine.applyState({ time: '17:50' })` read the state immediately (between has already aligned), then
|
|
106
|
+
`engine.step(...)` across the boundary.
|
|
107
|
+
The length of a day is `describe().time.dayLength` (game seconds); with `timeScale` 1, `step(1 sky minute)` = `step(dayLength / 1440)`; if the time
|
|
108
|
+
scale is not 1, divide by `timeScale` as well.
|
|
109
|
+
- Reproduce a scenario: `npm run shot -- / --time 17:58 --wait 10 --describe-only`, then look at the time (18:0x) and your effect (lamps, NPCs, items).
|
|
110
|
+
- After `npm run map`, the "timed events" section of GAMEMAP.md lists every `sky.at/between/daily/onSeason` and `clock.after/every`.
|
|
111
|
+
- Is skip the same as living through it? `const r = await engine.checkSkip(600)` skips 600 game seconds, rewinds, steps the same span and compares the
|
|
112
|
+
saved state: `{ ok, diffs: [{ path, a, b }] }` (refuses with `reason: 'frozen'` / `'timeScale0'` while gameplay is frozen or the clock stopped; pending background results are applied first) (a = skip, b = step; `{ ignore: ['parts.world', 'parts.random'] }` drops paths). Skip does not run near simulation (the weather module has a skip hook, so its timers do advance), so a moving player/NPC
|
|
113
|
+
always differs: ignore those parts and read the rest. It leaves the world at the stepped state, so run
|
|
114
|
+
it on a scratch playthrough or in a test. A diff usually means a module with its own time lacks a `skip` hook. `await engine.checkSave()` does the same
|
|
115
|
+
for save -> load (a diff names a save part whose `load` does not restore what `save` wrote).
|
|
116
|
+
- Why did it fire (or not)? `engine.events.traceSize = 200` records each event with the event or op that caused it: `events.trace('item:add').at(-1).chain`. Failed ops, sight queries and NPC state changes are entries too (with `code`); `events.note(name, { obj, code, data })` adds your own and `events.traceFocus(id)` makes one object verbose (the ring is bounded; size 0 costs nothing). Details: recipe 23 section 12.
|
|
117
|
+
- Related tests: `npm test -- 游戏时钟 SKIP`.
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# Scene transitions and pause (flow)
|
|
2
|
+
|
|
3
|
+
Needs the module `flow()` (not in openWorld; add it yourself: `engine.use(openWorld({ camera: 'follow', ...}), flow())`).
|
|
4
|
+
- **Flow states**: title, playing (built-in `playing`), paused (built-in `paused`: freezes gameplay + locks input), ending, ... Only one is active at a time.
|
|
5
|
+
- **Scene transition** `transition(fn)`: lock input -> fade to black -> fade music out -> (with `{ autosave: 'auto' }` save slot 'auto'; off by
|
|
6
|
+
default) -> run fn -> wait until every module is ready -> fade in -> unlock. Repeated calls queue up automatically.
|
|
7
|
+
|
|
8
|
+
## 1. Pause / title / ending (in main.js)
|
|
9
|
+
```js
|
|
10
|
+
import { flow, toast } from 'threedog';
|
|
11
|
+
const titleEl = document.getElementById('title'), startBtn = document.getElementById('start'); // elements you wrote in the page html
|
|
12
|
+
engine.use(flow({ start: 'title' })); // start in the title state (entered after engine:ready)
|
|
13
|
+
|
|
14
|
+
engine.flow.define('title', {
|
|
15
|
+
freeze: true, lockInput: true, music: 'title', // music: the track to play on entry (music module), null = stop
|
|
16
|
+
enter: (e, from) => { titleEl.hidden = false; },
|
|
17
|
+
exit: (e, to) => { titleEl.hidden = true; },
|
|
18
|
+
});
|
|
19
|
+
engine.flow.define('ending', { freeze: true, lockInput: true, enter: () => toast(engine, '完') });
|
|
20
|
+
startBtn.onclick = () => engine.flow.go('playing');
|
|
21
|
+
|
|
22
|
+
engine.input.define('pause', ['KeyO'], '暂停'); // read by action name; Esc is the back key (see below); presets.keys / presets.interactions bind P, I, J, E (see the key table in GAMEMAP)
|
|
23
|
+
engine.onFrame(() => {
|
|
24
|
+
if (engine.input.pressedRaw('pause')) engine.flow.go(engine.flow.state === 'paused' ? 'playing' : 'paused'); // paused pushes an opaque input context, so use pressedRaw
|
|
25
|
+
});
|
|
26
|
+
engine.events.on('flow:change', ({ from, to }) => console.log(from, '->', to));
|
|
27
|
+
```
|
|
28
|
+
**Pausing has a single entry point: flow's `'paused'`** (internally `engine.freeze('flow')`: the picture keeps rendering and the UI keeps working).
|
|
29
|
+
**Don't use `engine.pause()`** (it stops even rendering and is for tests).
|
|
30
|
+
The settings menu also pauses while open: `settings({ freezeWorld: true })`. With flow installed it switches to `'paused'` and returns to the previous
|
|
31
|
+
state when the menu closes; without flow it calls `engine.freeze('settings')` directly.
|
|
32
|
+
Stopped while frozen: the fixed step (movement, physics), module `fixed`, the game clock `clock`, quest checks (they run in the fixed step), timeline
|
|
33
|
+
`wait` / tweens / camera / paths. Still running: rendering, UI, `onFrame`, the fade-to-black `fadeScreen`.
|
|
34
|
+
|
|
35
|
+
Restarting a run from a UI button (retry, "play again"): do not reset positions, health and spawns inside the click handler or an `onFrame` callback; that is
|
|
36
|
+
mid-frame and can leave half the world on the old tick. Apply it on a fixed tick: `engine.nextFixed(resetRun)`
|
|
37
|
+
(runs at the start of the next fixed step, in a stable order), or set a flag in the handler and reset in `onFixed`.
|
|
38
|
+
|
|
39
|
+
### Back key (Esc): the UI focus stack
|
|
40
|
+
Windows (inventory, quests, settings), dialogue and cutscenes are pushed onto the stack in the order they open (`uiFocus(engine)` in `ui/Focus.js`),
|
|
41
|
+
and Esc goes **only to the top one**:
|
|
42
|
+
cutscene -> skip; window -> close; dialogue -> swallow (do nothing); empty stack -> open the settings menu. So one Esc never both skips a cutscene and
|
|
43
|
+
opens the menu, and no patch like "ignore keys for 0.15 s after opening" is needed.
|
|
44
|
+
A game's own windows made with `makeWindow` are pushed automatically (`onCancel` changes what Esc does); UI you draw yourself must be pushed:
|
|
45
|
+
```js
|
|
46
|
+
import { uiFocus } from 'threedog';
|
|
47
|
+
const h = uiFocus(engine).push('myMap', { cancel: () => closeMap() }); // call h.remove() when closing; h.fresh = opened this very frame
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## 2. Changing scene / teleporting
|
|
51
|
+
```js
|
|
52
|
+
// A level-based game: switch to another map
|
|
53
|
+
await engine.flow.transition(async () => {
|
|
54
|
+
await engine.level.load('/models/town2.glb'); // or a name from the assets manifest
|
|
55
|
+
engine.player.placeAt(engine.level.spawn);
|
|
56
|
+
engine.cameraRig.follow(engine.player.root); // the camera jumps straight there instead of flying from far away
|
|
57
|
+
}, { fade: 0.6, autosave: 'auto' }); // also save slot 'auto' before switching
|
|
58
|
+
|
|
59
|
+
// Teleport within the same map (the city test page's teleport pad): no save, music keeps playing
|
|
60
|
+
engine.flow.transition(() => engine.player.placeAt([40, 0, -20]), { music: 'keep' });
|
|
61
|
+
```
|
|
62
|
+
When the level changes, the old level's things are cleared automatically: trigger zones built by `triggers.fromMarkers`, and pickups / trigger zones /
|
|
63
|
+
props in content whose position uses a level marker.
|
|
64
|
+
An NPC like that is not deleted: its data (in `engine.world`, with zone = level name) stays and only the model is removed; it is rebuilt automatically
|
|
65
|
+
when you return to this map, with its state intact.
|
|
66
|
+
Things the game builds itself that belong to this map are registered with `engine.level.track(handle)` (`{ remove() }`) and deleted together when the
|
|
67
|
+
map changes.
|
|
68
|
+
Loading a save across levels: the save records the level name, so `await engine.saves.load('slot1')` first switches back to that map, waits for it to
|
|
69
|
+
finish loading, and then puts the player and everything else back (the level must be loaded by name, `level({ url })`; a code-built `level({ scene })`
|
|
70
|
+
can't be recorded).
|
|
71
|
+
|
|
72
|
+
Saves live in the browser's IndexedDB (no 5 MB limit; when it is unavailable it falls back to localStorage and tells you once; old localStorage saves
|
|
73
|
+
are moved over on first launch). `save()` / `remove()` / `load()` return a Promise (awaiting is optional; a failed write shows a notice), while
|
|
74
|
+
`list()` / `export()` are synchronous (saves are read into memory at startup). Photos are stored separately as Blobs and are not part of the world save.
|
|
75
|
+
Backup: `engine.saves.exportFile('slot1')` downloads a .json (including all binary attachments such as photos; `{ files: false }` gives only the world
|
|
76
|
+
save), and `await engine.saves.importFile(file)` restores it into a save slot (without a file, a file picker opens); the "Saves" page of the settings
|
|
77
|
+
menu has matching buttons.
|
|
78
|
+
For just a fade-to-black, without locking input or saving: `await fadeScreen(engine, 1, 0.5); ...; await fadeScreen(engine, 0, 0.5);` (import from `threedog`).
|
|
79
|
+
Fades inside a cutscene use the timeline steps `{ fade: 0.5 }`, `{ fade: 0.5, to: 0 }`.
|
|
80
|
+
|
|
81
|
+
## 2b. Input contexts (menus, vehicles, build mode)
|
|
82
|
+
Actions are grouped into **contexts**, a stack like Unity's Action Maps. `input.push(name)` returns a handle; `h.remove()` pops it. The top context
|
|
83
|
+
shadows lower actions bound to the same key; an opaque context (the default) blocks everything below it, `{ pass: true }` lets unrelated actions
|
|
84
|
+
through. Dialogue, windows, full-screen UI parts, cutscenes, paused and transitions each push an opaque one: that is what "locks input" means
|
|
85
|
+
(`input.enabled` is false while one is on the stack).
|
|
86
|
+
```js
|
|
87
|
+
engine.input.define('exit', 'KeyF', 'Get out', { context: 'vehicle' }); // 'interact' has E; give the vehicle its own keys
|
|
88
|
+
engine.input.define('inspect', 'KeyF', 'Inspect'); // gameplay action on the same key
|
|
89
|
+
const h = engine.input.push('vehicle', { pass: true }); // now F means exit, inspect is shadowed, WASD still works
|
|
90
|
+
h.remove(); // back on foot
|
|
91
|
+
engine.input.define('menuConfirm', 'Space', 'OK', { context: 'menu' }); // readable only while a window / menu is open
|
|
92
|
+
```
|
|
93
|
+
- A switch applies at the start of the next fixed step (the input snapshot), so the press that boarded cannot also get out in the same step. Actions
|
|
94
|
+
the switch blocks lose their held state, and a key cleared this way stays dead until released: closing a menu never leaves a key "still held" and
|
|
95
|
+
keyboard auto-repeat does not bring it back.
|
|
96
|
+
- Losing focus (`blur`, tab hidden) releases every held key.
|
|
97
|
+
- `describe().ui.inputContexts` lists the stack; the event `input:context { stack }` fires on every change. `characters()` pushes `'vehicle'` while
|
|
98
|
+
the player drives (its `brake` action lives there).
|
|
99
|
+
- Test: `engine.input.push('menu'); engine.step(1 / 60);` then `input.pressed('attack')` is false.
|
|
100
|
+
|
|
101
|
+
## 3. Verify
|
|
102
|
+
- `describe().flow`: `{ state: 'paused', transitioning: false }`; when `describe().time.frozen` is true gameplay is frozen; `ui.inputLocked` shows
|
|
103
|
+
whether input is locked.
|
|
104
|
+
- In tests: after `engine.flow.go('paused'); engine.step(1)` the player position, `engine.clock.now`, quest progress and timelines are unchanged;
|
|
105
|
+
after `await engine.flow.transition(fn)` returns, `transitioning` is false (if fn throws, the error goes to the caller and the screen still fades back in).
|
|
106
|
+
- Related tests: `npm test -- 游戏流程` (city: transition fade and input lock, paused freeze), `npm test -- 接缝` (Esc focus stack, quests/timelines frozen
|
|
107
|
+
while frozen, screen fades back in when transition fails).
|
|
108
|
+
|
|
109
|
+
## 4. New game / continue / back to title / retry (engine.session)
|
|
110
|
+
Every playthrough starts from a clean slate, so a second new game is exactly like the first:
|
|
111
|
+
```js
|
|
112
|
+
await engine.session.newGame(); // the state right after start(): world, containers, vars, quests, clock, sky, weather, random
|
|
113
|
+
await engine.session.load('slot1'); // continue (title "Continue", settings "Load"); retry: engine.session.load('checkpoint')
|
|
114
|
+
await engine.session.quit(); // back to the title (settings "Back to title"); the title's Start calls newGame
|
|
115
|
+
engine.session.track(engine.events.once('npc:talk', onTalk)); // anything the game adds during play: removed when the playthrough ends
|
|
116
|
+
```
|
|
117
|
+
Ending a playthrough skips a running cutscene, removes tracked handles, drops clock timers added after start(), drops background results not yet
|
|
118
|
+
applied (commits), stops the music, applies the start state and snaps the camera to the player. flow goes back to its start state, then to
|
|
119
|
+
`'playing'`. Events: `session:end`, `session:start { kind: 'new' | 'load', slot? }` (play an intro per new game there, not on `engine:ready`).
|
|
120
|
+
- `saves.load(slot)` is a quick load onto the running playthrough (keeps what the game added); `session.load(slot)` ends the playthrough first and
|
|
121
|
+
refuses an unreadable save without touching the game. Deleting a save is `saves.remove(slot)`.
|
|
122
|
+
- Listeners and hooks registered at boot stay (they are the game); register play-time ones with `session.track`.
|
|
123
|
+
|
|
124
|
+
## 5. Window and device (engine.page)
|
|
125
|
+
One place listens to window focus, tab visibility, mouse lock and the WebGL context; modules never add their own listeners.
|
|
126
|
+
- Window in the background / tab hidden: gameplay waits (no fixed steps; rendering and UI go on). `createEngine({ pauseOnBlur: false })` or
|
|
127
|
+
`engine.page.pauseOnBlur = false` keeps playing. Coming back resumes with no catch-up burst; a long frame turns into at most 0.1 s of fixed steps.
|
|
128
|
+
- `engine.events.on('page:blur', () => engine.flow?.go('paused'))` also opens the pause menu. Other events: `page:focus`,
|
|
129
|
+
`page:pointerlock { locked }` (cameras lock again on the next click), `page:contextlost` / `page:contextrestored` (gameplay waits and the player
|
|
130
|
+
sees a message; three.js restores the context).
|
|
131
|
+
- `engine.step()` still advances while away (tests, dev bridge). Held keys are released by Input.
|
|
132
|
+
- Tests: `npm test -- "Session:" "Window:"`.
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Add weather or change the sky
|
|
2
|
+
|
|
3
|
+
Modules: `sky()` (day/night, sun and moon, fog, calendar), `weather()` (needs sky; the game's weather types, smooth transitions, rain and snow,
|
|
4
|
+
lightning). All look data lives in the style pack; the engine has only a neutral fallback.
|
|
5
|
+
|
|
6
|
+
## 1. Switching weather / automatic weather (main.js)
|
|
7
|
+
```js
|
|
8
|
+
engine.weather.set('rain', 20); // transition to rain over 20 seconds (a type of the game's table, see 2)
|
|
9
|
+
engine.weather.setAuto(true); // change weather at random (openWorld({ camera: 'follow', autoWeather: true }) also works)
|
|
10
|
+
engine.events.on('weather:lightning', () => { /* thunder */ });
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## 2. The game's own weather table (example: a desert)
|
|
14
|
+
`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
|
+
ones (clear cloudy overcast rain storm snow fog) are an opt-in preset: `weather(presets.weather.temperate)`; extend with
|
|
16
|
+
`types: { ...presets.weather.temperate.types, dust: {...} }`.
|
|
17
|
+
Left-out fields are calm (no cloud, rain, snow, grey, lightning; sun, fog, wind 1). The style pack's `style.weather.types` only retunes types the game has.
|
|
18
|
+
```js
|
|
19
|
+
import { createEngine, presets, sky, weather } from 'threedog';
|
|
20
|
+
engine.use(sky(), weather({
|
|
21
|
+
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
|
+
autoPool: ['clear', 'clear', 'dust'], // candidates for automatic weather (repeats = higher probability; default: each type once)
|
|
23
|
+
}));
|
|
24
|
+
engine.weather.set('dust', 15); engine.weather.current.heat; // 0..1 during the change
|
|
25
|
+
```
|
|
26
|
+
Fields: `cloud` cloud cover 0-1, `sun` sunlight multiplier, `fog` fog distance multiplier (smaller = denser fog), `wind` wind strength, `rain`/`snow`
|
|
27
|
+
0-1, `grey` how gray the sky turns, `lightning` lightning. A table where nothing rains or snows builds no particles.
|
|
28
|
+
With openWorld the weather module is already installed; pass its options through the preset: `openWorld({ camera: 'follow', weather: { types, autoPool } })`.
|
|
29
|
+
|
|
30
|
+
## 3. Changing sky colors, sun, stars (style pack)
|
|
31
|
+
`sky.keyframes` in the style pack (lowpoly: its `index.js`):
|
|
32
|
+
`[time 0-1, zenith color, horizon color (= fog color), sunlight color, sunlight intensity, ambient intensity]`, interpolated by time;
|
|
33
|
+
also `sunSize sunGlow moonSize starDensity clouds skybox shadow` (see the comments in lowpoly for what they mean; `hoursPerDay` is timing, so it is a
|
|
34
|
+
`sky()` option, not a style key). The look of rain and snow is in `style.weather.rain / snow` (shape, density, shaders, the game's own particles: recipe 44).
|
|
35
|
+
|
|
36
|
+
## 4. Time and brightness (game code)
|
|
37
|
+
```js
|
|
38
|
+
engine.sky.timeOfDay = parseClock('19:30'); // jump to a time (0-1)
|
|
39
|
+
engine.clock.timeScale = 0; // sky and game seconds stop together (2 = double speed); game seconds per day: sky({ dayLength: 600 }); the three kinds of time are in recipe 06
|
|
40
|
+
engine.setFogFar(300); // base fog distance (meters); weather scales it
|
|
41
|
+
```
|
|
42
|
+
Fixed dusk: `openWorld({ time: 18.5 / 24, ... })` (a 0-1 fraction of the day) and do not pass `sky: presets.calendar.cycle` (the template does; the cycle
|
|
43
|
+
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.
|
|
44
|
+
The calendar is the game's: `sky()` alone keeps one time of day (dungeon, arena, space); a day-night cycle is `sky({ dayLength: 360 })` or
|
|
45
|
+
`sky(presets.calendar.cycle)` (`presets.calendar.fourSeasons` includes it); `hoursPerDay` changes the clock face. An audio rule's `time` condition
|
|
46
|
+
takes `'day'`, `'night'` or a range `['18:00', '06:00']`; anything else warns once.
|
|
47
|
+
Seasons are off by default (`engine.sky.season` is `null`, no `season:change`); name them to turn them on:
|
|
48
|
+
```js
|
|
49
|
+
sky({ seasons: ['spring', 'summer', 'autumn', 'winter'], daysPerSeason: 28, dayLength: 360 }); // days advance only with a dayLength; or the preset: openWorld({ camera: 'follow', sky: presets.calendar.fourSeasons })
|
|
50
|
+
sky({ seasons: [{ name: 'wet', days: 10 }, { name: 'dry', days: 20 }], dayLength: 360 }); // seasons of their own length
|
|
51
|
+
```
|
|
52
|
+
**Don't modify directly** `sky.sun.intensity / color`, `sky.hemi`, `scene.fog`: the sky recomputes them every frame and overwrites your change (the
|
|
53
|
+
console warns about it during development).
|
|
54
|
+
To darken or tint everything (a cave, a horror segment), write a modifier layer of your own; it stacks with the weather's 'weather' layer without
|
|
55
|
+
overwriting it (multiplier layers vs `look.lights` overrides: [recipe 52](52-look.md#skymodify-vs-looklights)):
|
|
56
|
+
```js
|
|
57
|
+
engine.sky.modify('cave', { sun: 0.3, ambient: 0.4, fog: 0.5 }); // enter the cave: layers multiply
|
|
58
|
+
engine.sky.modify('cave', { tint: 0x402030, tintAmount: 0.5 }); // changes only the given fields (this layer's sun/ambient stay)
|
|
59
|
+
engine.sky.modify('cave', null); // leave the cave: remove this layer
|
|
60
|
+
```
|
|
61
|
+
`sun / ambient / fog` multiply across layers, `tint` is blended weighted by `tintAmount` (zenith) / `horizonTintAmount` (horizon), and `flash` takes
|
|
62
|
+
the maximum.
|
|
63
|
+
Write once and it stays in effect; no need to write every frame. For a gradual change, write a new value every frame. `engine.sky.modifiers` is the
|
|
64
|
+
combined result and is read-only (changing it directly triggers a warning during development).
|
|
65
|
+
|
|
66
|
+
## 5. Verify
|
|
67
|
+
- 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 timeScale`.
|
|
69
|
+
- Take a screenshot only after the look changed: `npm run shot -- / --time 19:30 --weather dust`. Related test: `npm test -- 现场参数`.
|
|
70
|
+
|
|
71
|
+
## 6. Day and night in game logic
|
|
72
|
+
Day and night come only from the sky: test `engine.sky.isDay`, and fade with `engine.sky.daylight` (0-1). Don't decide it from the clock time
|
|
73
|
+
yourself, so a game with different day lengths or seasons stays right. Lights and shop doors that follow the time of day use `engine.sky.between(...)`
|
|
74
|
+
(its page: `api/sky.md`).
|