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,108 @@
|
|
|
1
|
+
// World outline (terrain({ shape })): which grid points have ground, the marching-squares cut of a boundary cell, and the side / bottom depths.
|
|
2
|
+
// Pure computation, no three.js: the Worker builds island chunks with it and the main thread answers engine.ground.has / surface with the same
|
|
3
|
+
// code, so a query and the drawn mesh never disagree about where the edge is. Only created when a game passes shape (the default ground never
|
|
4
|
+
// runs any of this).
|
|
5
|
+
//
|
|
6
|
+
// The mask lives on grid points (like heights): its value there is the game's mask (function or gray image) plus the edge noise and jitter.
|
|
7
|
+
// A cell with all four corners > 0 is ground, all four <= 0 is void; a mixed cell is cut along straight lines whose ends sit where the mask
|
|
8
|
+
// crosses 0 on the cell edges (linear interpolation). Two chunks compute a shared edge from the same two grid values, so the cut is seamless.
|
|
9
|
+
import { compilePure } from '../../core/threadPure.js';
|
|
10
|
+
|
|
11
|
+
// corner loop a(0,0) b(1,0) d(1,1) c(0,1): counter-clockwise in (x, z); polygons keep that winding
|
|
12
|
+
const LX = [0, 1, 1, 0], LZ = [0, 0, 1, 1];
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @param {any} S the shape config (functions already source text or functions; an image mask carries data)
|
|
16
|
+
* @param {{ CELL: number, NOISE: any, key: (i: number, j: number) => number, hash: Function, fbm: Function }} ctx
|
|
17
|
+
*/
|
|
18
|
+
export function makeShape(S, { CELL, NOISE, key, hash, fbm }) {
|
|
19
|
+
const pure = (v, label) => (typeof v === 'function' || typeof v === 'string' ? compilePure(v, label).call : null);
|
|
20
|
+
const userMask = pure(S.mask, 'terrain({ shape: { mask } })');
|
|
21
|
+
const img = !userMask && S.mask?.data ? S.mask : null;
|
|
22
|
+
// an image mask still loading (main thread before init): ground everywhere, so nothing falls before the real outline arrives
|
|
23
|
+
const raw = userMask ? (x, z) => userMask(x, z, NOISE) : img ? (x, z) => sample(img, x, z) : () => 1;
|
|
24
|
+
const E = S.edge || {}, amp = E.noise ?? 0, freq = 1 / (E.size ?? 16), jit = E.jitter ?? 0, round = E.round ?? 0;
|
|
25
|
+
const side = S.side ?? {}, bottom = S.bottom ?? null;
|
|
26
|
+
const sideFn = pure(side.depth, 'terrain({ shape: { side: { depth } } })'), sideNum = sideFn ? 0 : side.depth ?? 2;
|
|
27
|
+
const botFn = bottom && pure(bottom.depth, 'terrain({ shape: { bottom: { depth } } })'), botNum = botFn ? 0 : bottom?.depth ?? 4;
|
|
28
|
+
|
|
29
|
+
const cache = new Map();
|
|
30
|
+
/** mask value at grid point (i, j): > 0 ground */
|
|
31
|
+
function maskG(i, j) {
|
|
32
|
+
const k = key(i, j);
|
|
33
|
+
let m = cache.get(k);
|
|
34
|
+
if (m === undefined) {
|
|
35
|
+
const x = i * CELL, z = j * CELL;
|
|
36
|
+
m = raw(x, z);
|
|
37
|
+
// own offsets so the rim noise is not the height noise; jitter is per grid point (deterministic: a hash of the indices)
|
|
38
|
+
if (amp) m += amp * (2 * fbm(x * freq + 31.7, z * freq - 11.3, 3) - 1);
|
|
39
|
+
if (jit) m += jit * (2 * hash(i, j, 911) - 1);
|
|
40
|
+
if (cache.size > 400000) cache.clear();
|
|
41
|
+
cache.set(k, m);
|
|
42
|
+
}
|
|
43
|
+
return m;
|
|
44
|
+
}
|
|
45
|
+
/** edge.round: the top bends down by up to `round` meters towards the rim (soft edge); 0 keeps a hard cliff edge */
|
|
46
|
+
const drop = round ? (i, j) => { const t = Math.min(1, Math.max(0, maskG(i, j)) / round); return round * (1 - t) * (1 - t); } : null;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Cut of cell (i, j): null = all ground, [] = all void, else convex polygons as flat [fx, fz, crossing, ...] in cell units (0..1),
|
|
50
|
+
* counter-clockwise in (x, z); crossing = 1 marks a point on the rim (where the mask is 0)
|
|
51
|
+
*/
|
|
52
|
+
function cut(i, j) {
|
|
53
|
+
const v = [maskG(i, j), maskG(i + 1, j), maskG(i + 1, j + 1), maskG(i, j + 1)];
|
|
54
|
+
const ins = (v[0] > 0) + (v[1] > 0) + (v[2] > 0) + (v[3] > 0);
|
|
55
|
+
if (ins === 4) return null;
|
|
56
|
+
if (ins === 0) return [];
|
|
57
|
+
const L = [];
|
|
58
|
+
for (let k = 0; k < 4; k++) {
|
|
59
|
+
const n = (k + 1) & 3;
|
|
60
|
+
if (v[k] > 0) L.push(LX[k], LZ[k], 0);
|
|
61
|
+
if ((v[k] > 0) !== (v[n] > 0)) { const t = v[k] / (v[k] - v[n]); L.push(LX[k] + (LX[n] - LX[k]) * t, LZ[k] + (LZ[n] - LZ[k]) * t, 1); }
|
|
62
|
+
}
|
|
63
|
+
// saddle (opposite corners ground) with a void center: two separate corners instead of one hexagon
|
|
64
|
+
if (ins === 2 && (v[0] > 0) === (v[2] > 0) && v[0] + v[1] + v[2] + v[3] <= 0) {
|
|
65
|
+
const s = L[2] ? 3 : 0; // the list starts with a crossing when corner a is void
|
|
66
|
+
const rot = L.slice(s).concat(L.slice(0, s)); // now [corner, X, X, corner, X, X]
|
|
67
|
+
return [rot.slice(15).concat(rot.slice(0, 6)), rot.slice(6, 15)];
|
|
68
|
+
}
|
|
69
|
+
return [L];
|
|
70
|
+
}
|
|
71
|
+
function inPoly(P, fx, fz) {
|
|
72
|
+
const n = P.length;
|
|
73
|
+
for (let k = 0; k < n; k += 3) {
|
|
74
|
+
const ax = P[k], az = P[k + 1], bx = P[(k + 3) % n], bz = P[(k + 4) % n];
|
|
75
|
+
if ((bx - ax) * (fz - az) - (bz - az) * (fx - ax) < -1e-9) return false;
|
|
76
|
+
}
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
/** Is there ground at (x, z) (the same cut the mesh is built from) */
|
|
80
|
+
function has(x, z) {
|
|
81
|
+
const gx = x / CELL, gz = z / CELL, i = Math.floor(gx), j = Math.floor(gz);
|
|
82
|
+
const polys = cut(i, j);
|
|
83
|
+
if (polys === null) return true;
|
|
84
|
+
for (const P of polys) if (inPoly(P, gx - i, gz - j)) return true;
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
/** mask between grid points (bilinear), for bottom.depth's m */
|
|
88
|
+
function maskAt(i, j, fx, fz) {
|
|
89
|
+
return (maskG(i, j) * (1 - fx) + maskG(i + 1, j) * fx) * (1 - fz) + (maskG(i, j + 1) * (1 - fx) + maskG(i + 1, j + 1) * fx) * fz;
|
|
90
|
+
}
|
|
91
|
+
const sideDepth = sideFn ? (x, z) => sideFn(x, z, NOISE) : () => sideNum;
|
|
92
|
+
const bottomDepth = !bottom ? null : botFn ? (x, z, m) => botFn(x, z, NOISE, m) : () => botNum;
|
|
93
|
+
return { maskG, cut, has, maskAt, drop, sideDepth, bottomDepth, sideGround: side.ground ?? 'cliff', bottomGround: bottom?.ground ?? 'rock', voidY: S.voidY ?? null };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// gray image mask: value = gray - threshold (outside the image: no ground)
|
|
97
|
+
function sample(M, x, z) {
|
|
98
|
+
const [sx, sz] = M.size, [cx0, cz0] = M.center || [0, 0], th = M.threshold ?? 0.5;
|
|
99
|
+
const u = (x - cx0) / sx + 0.5, v = (z - cz0) / sz + 0.5;
|
|
100
|
+
if (u < 0 || u > 1 || v < 0 || v > 1) return -th;
|
|
101
|
+
return grayAt(M, u, v) - th;
|
|
102
|
+
}
|
|
103
|
+
/** Bilinear read of a gray image { data, width, height } at u, v in 0..1 (height maps share it) */
|
|
104
|
+
export function grayAt(M, u, v) {
|
|
105
|
+
const fx = u * (M.width - 1), fz = v * (M.height - 1), i = Math.floor(fx), j = Math.floor(fz), tx = fx - i, tz = fz - j;
|
|
106
|
+
const at = (a, b) => M.data[Math.min(M.height - 1, b) * M.width + Math.min(M.width - 1, a)];
|
|
107
|
+
return at(i, j) * (1 - tx) * (1 - tz) + at(i + 1, j) * tx * (1 - tz) + at(i, j + 1) * (1 - tx) * tz + at(i + 1, j + 1) * tx * tz;
|
|
108
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Main-thread side of terrain({ shape }): checks the options and turns its functions into source text for the workers (the same rules as
|
|
2
|
+
// height / groundType), keeps the side material out of the worker config, and watches for things falling out of the world (terrain:void).
|
|
3
|
+
// The engine does not respawn anything: what falling off means (respawn, damage, a cutscene) is the game's choice.
|
|
4
|
+
import { checkOptions } from '../../core/validate.js';
|
|
5
|
+
import { compilePure } from '../../core/threadPure.js';
|
|
6
|
+
|
|
7
|
+
const NO_MASK = 'terrain({ shape }): mask is required, a pure (x, z, n) => number that is > 0 where there is ground, '
|
|
8
|
+
+ 'e.g. mask: (x, z) => 40 - Math.hypot(x, z), or a gray image { url, size: [200, 200], threshold: 0.5 }';
|
|
9
|
+
const src = (v, label) => (typeof v === 'function' ? compilePure(v, label).src : v);
|
|
10
|
+
|
|
11
|
+
/** Validate cfg.shape and replace it with its worker-safe form (in place). Returns side.material (main thread only) or null */
|
|
12
|
+
export function prepareShape(cfg) {
|
|
13
|
+
const s = cfg.shape;
|
|
14
|
+
checkOptions('terrain({ shape })', s, ['mask', 'edge', 'side', 'bottom', 'voidY']);
|
|
15
|
+
if (s.mask == null) throw new Error(NO_MASK);
|
|
16
|
+
if (typeof s.mask === 'object') checkOptions('terrain({ shape: { mask } })', s.mask, ['url', 'data', 'width', 'height', 'size', 'center', 'threshold']);
|
|
17
|
+
checkOptions('terrain({ shape: { edge } })', s.edge || {}, ['noise', 'size', 'jitter', 'round']);
|
|
18
|
+
checkOptions('terrain({ shape: { side } })', s.side || {}, ['depth', 'ground', 'material']);
|
|
19
|
+
if (s.bottom) checkOptions('terrain({ shape: { bottom } })', s.bottom, ['depth', 'ground']);
|
|
20
|
+
const { material = null, ...side } = s.side || {};
|
|
21
|
+
side.depth = src(side.depth, 'terrain({ shape: { side: { depth } } })');
|
|
22
|
+
cfg.shape = { ...s, mask: src(s.mask, 'terrain({ shape: { mask } })'), side,
|
|
23
|
+
bottom: s.bottom ? { ...s.bottom, depth: src(s.bottom.depth, 'terrain({ shape: { bottom: { depth } } })') } : null };
|
|
24
|
+
return material;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Each fixed step: the player gets one terrain:void event per fall below engine.terrain.voidY. Rigid bodies are reported by the physics
|
|
29
|
+
* module itself (it reads engine.ground.voidY), so terrain does not reach into another module
|
|
30
|
+
*/
|
|
31
|
+
export function voidWatcher(e, w) {
|
|
32
|
+
let fallen = false;
|
|
33
|
+
return () => {
|
|
34
|
+
const p = e.player?.position;
|
|
35
|
+
if (!p) return;
|
|
36
|
+
if (p.y >= w.voidY) { fallen = false; return; } // back above (the game moved it): the next fall reports again
|
|
37
|
+
if (fallen) return;
|
|
38
|
+
fallen = true;
|
|
39
|
+
e.events.emit('terrain:void', { who: e.player, position: { x: p.x, y: p.y, z: p.z } });
|
|
40
|
+
};
|
|
41
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Main-thread side of terrain({ shading: 'texture' }): turns the worker's color map into a DataTexture and a per-chunk material that samples it.
|
|
2
|
+
// Each chunk gets its own material (a clone of the terrain material with the same patches plus 'terrainColorMap'), because a patch uniform
|
|
3
|
+
// is uploaded when the material changes, not per object; clones share one compiled program (same cacheKey), so this costs no shader compile.
|
|
4
|
+
// The map is sampled by world xz (the 'world' patch), not by uv, so the mesh uv stays free for the game's own textures.
|
|
5
|
+
import * as THREE from 'three';
|
|
6
|
+
import { applyEffects } from '../../render/materials.js';
|
|
7
|
+
import { copyPatches } from '../../render/patches.js';
|
|
8
|
+
|
|
9
|
+
/** Material for one chunk: `base` plus the color map `tex` ({ data, size }) of the chunk whose origin is (ox, oz) and edge length `chunk` */
|
|
10
|
+
export function mountColorMap(m, c, t, ox, oz) {
|
|
11
|
+
const { data, size } = t, R = size - 2, chunk = m.T.CHUNK;
|
|
12
|
+
const tex = new THREE.DataTexture(data, size, size, THREE.RGBAFormat, THREE.UnsignedByteType);
|
|
13
|
+
tex.colorSpace = THREE.SRGBColorSpace; // stored sRGB-encoded: the GPU decodes on sampling, 8 bits keep dark colors smooth
|
|
14
|
+
tex.minFilter = THREE.LinearMipmapLinearFilter; tex.magFilter = THREE.LinearFilter; tex.generateMipmaps = true;
|
|
15
|
+
tex.wrapS = tex.wrapT = THREE.ClampToEdgeWrapping;
|
|
16
|
+
tex.anisotropy = Math.min(4, m.engine.renderer.capabilities.getMaxAnisotropy?.() ?? 1); // ground is seen at grazing angles
|
|
17
|
+
tex.needsUpdate = true;
|
|
18
|
+
// world xz -> texture uv: pixel k is centered (k - 0.5) * chunk / R from the origin (see terrainColorMap.js); .zw = scale, offset
|
|
19
|
+
const rect = new THREE.Vector4(ox, oz, R / (chunk * size), 1 / size);
|
|
20
|
+
const mat = copyPatches(m.terrainMat, m.terrainMat.clone());
|
|
21
|
+
applyEffects(mat, { clouds: false, patches: [{
|
|
22
|
+
name: 'terrainColorMap', cacheKey: 1, needs: { patches: ['world'] },
|
|
23
|
+
uniforms: { uTColorMap: { value: tex }, uTColorRect: { value: rect } },
|
|
24
|
+
glsl: { fragment: {
|
|
25
|
+
pars: 'uniform sampler2D uTColorMap; uniform vec4 uTColorRect;',
|
|
26
|
+
// before the vertex colors (white on a textured top): every after-patch on color_fragment, such as the season tint in 'mix'
|
|
27
|
+
// mode, then sees the mapped color instead of having it multiplied back over its result
|
|
28
|
+
color_fragment: { before: 'diffuseColor.rgb *= texture2D(uTColorMap, (vThreedogWorld.xz - uTColorRect.xy) * uTColorRect.z + uTColorRect.w).rgb;' },
|
|
29
|
+
} },
|
|
30
|
+
}] });
|
|
31
|
+
c.colorTex = tex; c.colorMat = mat;
|
|
32
|
+
return mat;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** An edit rebuilt the chunk: upload the new pixels into the same texture */
|
|
36
|
+
export function updateColorMap(c, t) {
|
|
37
|
+
c.colorTex.image.data.set(t.data);
|
|
38
|
+
c.colorTex.needsUpdate = true;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function disposeColorMap(c) {
|
|
42
|
+
c.colorTex?.dispose();
|
|
43
|
+
c.colorMat?.dispose();
|
|
44
|
+
}
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
// Timeline: cutscenes, camera moves, scripted movement. Runs a list of steps in order and returns a Promise.
|
|
2
|
+
//
|
|
3
|
+
// await engine.timeline.play([
|
|
4
|
+
// { camera: { to: { position: [10, 6, 10], lookAt: [0, 1, 0] }, duration: 2, ease: 'inOutSine', fov: 45 } },
|
|
5
|
+
// { parallel: [ // run at the same time; continue only when all finish
|
|
6
|
+
// { tween: { target: door, to: { 'rotation.y': 1.6 }, duration: 1, ease: 'outBack' } },
|
|
7
|
+
// { path: { object: npc, points: [[0,0,0], [4,0,2], [8,0,0]], duration: 3, lookAhead: 0.05, ground: true } },
|
|
8
|
+
// ] },
|
|
9
|
+
// { say: { speaker: '老渔夫', text: '你来了。' } }, // needs the dialogue module; waits for the dialogue to end
|
|
10
|
+
// { wait: 0.5 }, // wait 0.5 seconds
|
|
11
|
+
// { waitFor: 'quest:done' }, // wait for an event
|
|
12
|
+
// { do: engine => engine.events.emit('door:open') }, // run code (may be async)
|
|
13
|
+
// { fade: 1 }, { fade: 0.5, to: 0 }, // fade the screen to black over 1 second, then back in over 0.5 s (fadeScreen)
|
|
14
|
+
// ], { skippable: true, letterbox: true, lockInput: true });
|
|
15
|
+
//
|
|
16
|
+
// Options: skippable (default true); letterbox black bars top and bottom (default false); lockInput locks player controls (default true)
|
|
17
|
+
// Skip: the back key Esc (the cutscene is in the UI focus stack, Esc goes only to the top; see ui/Focus.js), the action 'skip' (default Esc / Backspace; not
|
|
18
|
+
// Space, which is dialogue "continue"), or click the hint on the letterbox.
|
|
19
|
+
// While frozen (engine.freeze / flow 'paused') wait, tweens, camera and paths do not advance; they resume after unfreezing.
|
|
20
|
+
// On skip all running tweens jump to their end and the remaining steps finish instantly (do steps still run, so state matches a normal playthrough).
|
|
21
|
+
// Camera takeover: a camera step takes the camera (engine.takeCamera, see camera/common.js) and releases its claim and restores the view after the whole run; the camera
|
|
22
|
+
// module then resumes.
|
|
23
|
+
// To hand the camera back midway: { camera: { release: true } }
|
|
24
|
+
// General tween (usable anywhere in a game): await engine.timeline.tween(mesh, { 'position.y': 2, 'material.opacity': 0 }, 1, 'outCubic')
|
|
25
|
+
// Events: timeline:start, timeline:end { skipped }
|
|
26
|
+
// Scenario param cutscene (engine.applyState / URL ?cutscene=skip): 'skip' skips the playing cutscene and all later ones, 'keep' restores normal behavior.
|
|
27
|
+
import { Tweener } from './Tween.js';
|
|
28
|
+
import { fadeScreen, uiFocus } from '../../ui/UI.js';
|
|
29
|
+
import { cameraStep, pathStep, releaseCamera } from './shots.js';
|
|
30
|
+
import { buildLetterbox } from './letterbox.js';
|
|
31
|
+
import { checkOptions } from '../../core/validate.js';
|
|
32
|
+
import { readParams, keysSchema } from '../../core/params.js';
|
|
33
|
+
/** @import { ModuleDef } from '../../types/core' */
|
|
34
|
+
/** @import { Ease } from '../../types/common' */
|
|
35
|
+
/** @import { TimelineStep, TimelinePlayOptions, TimelineOptions, TweenTo, TweenPromise } from '../../types/gameplay' */
|
|
36
|
+
|
|
37
|
+
// Keys recognized by steps and their params
|
|
38
|
+
const STEP_KEYS = {
|
|
39
|
+
step: ['parallel', 'sequence', 'wait', 'waitFor', 'timeout', 'do', 'tween', 'camera', 'path', 'say', 'fade', 'to'],
|
|
40
|
+
tween: ['target', 'to', 'duration', 'ease'],
|
|
41
|
+
camera: ['from', 'to', 'duration', 'ease', 'fov', 'release'],
|
|
42
|
+
path: ['object', 'points', 'duration', 'ease', 'lookAhead', 'ground', 'closed', 'curve', 'tension', 'upright'],
|
|
43
|
+
say: ['speaker', 'text', 'nodes', 'node'],
|
|
44
|
+
};
|
|
45
|
+
const SHOT_KEYS = ['position', 'lookAt', 'fov'];
|
|
46
|
+
function checkStep(s) {
|
|
47
|
+
checkOptions('timeline step', s, STEP_KEYS.step);
|
|
48
|
+
for (const k of ['tween', 'camera', 'path', 'say']) if (s[k]) checkOptions(`timeline ${k}`, s[k], STEP_KEYS[k]);
|
|
49
|
+
if (s.camera) for (const k of ['from', 'to']) checkOptions(`timeline camera.${k}`, s.camera[k], SHOT_KEYS);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** engine.timeline */
|
|
53
|
+
export class Timeline {
|
|
54
|
+
/** @internal */
|
|
55
|
+
constructor(engine, { skipKeys = ['Escape', 'Backspace'] } = {}) {
|
|
56
|
+
/** @internal */ this.engine = engine;
|
|
57
|
+
/** @internal */ this._tweener = new Tweener();
|
|
58
|
+
/** @internal */ this.runs = new Set();
|
|
59
|
+
/** @internal numbers the runs of this engine (timeline:start / timeline:end id) */ this._runSeq = 0;
|
|
60
|
+
/** Skip every cutscene immediately (set by scenario param cutscene=skip) @type {boolean} */
|
|
61
|
+
this.skipAll = false;
|
|
62
|
+
engine.input.define('skip', skipKeys, 'timeline.skipAction');
|
|
63
|
+
buildLetterbox(this);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Whether a cutscene is playing
|
|
68
|
+
* @returns {boolean}
|
|
69
|
+
*/
|
|
70
|
+
get playing() { return this.runs.size > 0; }
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* General tween (the only entry point for tweens in the engine): await engine.timeline.tween(mesh, { 'position.y': 2 }, 1, 'outCubic'); duration in seconds.
|
|
74
|
+
* Returns a Promise (with finish()/cancel())
|
|
75
|
+
* @param {any} target
|
|
76
|
+
* @param {TweenTo} to
|
|
77
|
+
* @param {number} [duration]
|
|
78
|
+
* @param {Ease} [ease]
|
|
79
|
+
* @returns {TweenPromise}
|
|
80
|
+
*/
|
|
81
|
+
tween(target, to, duration = 1, ease = 'inOutCubic') { return this._tweener.tween(target, to, duration, ease); }
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Play a timeline; resolves with { skipped } when it ends
|
|
85
|
+
* @param {TimelineStep | TimelineStep[]} steps
|
|
86
|
+
* @param {TimelinePlayOptions} [opts]
|
|
87
|
+
* @returns {Promise<{ skipped: boolean }>}
|
|
88
|
+
*/
|
|
89
|
+
async play(steps, opts = {}) {
|
|
90
|
+
checkOptions('timeline.play()', opts, ['skippable', 'letterbox', 'lockInput']);
|
|
91
|
+
const { skippable = true, letterbox = false, lockInput = true } = opts;
|
|
92
|
+
const e = this.engine;
|
|
93
|
+
const run = { id: ++this._runSeq, skippable, letterbox, lockInput, skipping: false, cancels: new Set(), cam: null };
|
|
94
|
+
// enter the UI focus stack: skippable cutscenes skip on Esc, unskippable ones swallow Esc (so it does not open the settings menu)
|
|
95
|
+
run.focus = uiFocus(e).push('timeline', { cancel: skippable ? () => this.skip(run) : null });
|
|
96
|
+
this.runs.add(run);
|
|
97
|
+
run.ctx = lockInput ? e.input.push('cutscene') : null;
|
|
98
|
+
this._refreshUI();
|
|
99
|
+
e.events.emit('timeline:start', { id: run.id });
|
|
100
|
+
if (this.skipAll && skippable) this.skip(run);
|
|
101
|
+
try {
|
|
102
|
+
await this._step(steps, run);
|
|
103
|
+
} catch (err) {
|
|
104
|
+
console.error('[timeline] step failed', err);
|
|
105
|
+
} finally {
|
|
106
|
+
releaseCamera(this, run);
|
|
107
|
+
run.focus.remove();
|
|
108
|
+
run.ctx?.remove();
|
|
109
|
+
this.runs.delete(run);
|
|
110
|
+
this._refreshUI();
|
|
111
|
+
e.events.emit('timeline:end', { id: run.id, skipped: run.skipping });
|
|
112
|
+
}
|
|
113
|
+
return { skipped: run.skipping };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Skip all (or one) playing timelines
|
|
118
|
+
* @param {any} [run]
|
|
119
|
+
* @returns {void}
|
|
120
|
+
*/
|
|
121
|
+
skip(run) {
|
|
122
|
+
for (const r of run ? [run] : [...this.runs]) {
|
|
123
|
+
if (r.skipping) continue;
|
|
124
|
+
r.skipping = true;
|
|
125
|
+
this._tweener.finishAll(r);
|
|
126
|
+
for (const c of [...r.cancels]) c();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Update every frame (called by the module each frame)
|
|
132
|
+
* @param {number} dt
|
|
133
|
+
* @returns {void}
|
|
134
|
+
* @internal
|
|
135
|
+
*/
|
|
136
|
+
frame(dt) {
|
|
137
|
+
if (!this.engine.frozen) this._tweener.update(dt); // wait and tweens do not advance while frozen
|
|
138
|
+
const inp = this.engine.input;
|
|
139
|
+
// skip keys other than Esc (e.g. Backspace): Esc is already dispatched by the UI focus stack, so do not handle it twice; the first frame of a run does not
|
|
140
|
+
// count
|
|
141
|
+
if (!this.runs.size || !inp.pressedRaw('skip') || inp.pressedRaw('cancel')) return;
|
|
142
|
+
for (const r of this.runs) if (r.skippable && !r.focus.fresh) this.skip(r);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// ---------- Steps ----------
|
|
146
|
+
/** @internal */
|
|
147
|
+
async _step(s, run) {
|
|
148
|
+
if (s == null) return;
|
|
149
|
+
if (Array.isArray(s)) { for (const x of s) await this._step(x, run); return; }
|
|
150
|
+
if (typeof s === 'function') { await s(this.engine, run); return; }
|
|
151
|
+
checkStep(s);
|
|
152
|
+
if (s.parallel) { await Promise.all(s.parallel.map(x => this._step(x, run))); return; }
|
|
153
|
+
if (s.sequence) { await this._step(s.sequence, run); return; }
|
|
154
|
+
if ('wait' in s) { await this._timed(run, { duration: s.wait }); return; }
|
|
155
|
+
if (s.waitFor) { await this._waitFor(s.waitFor, s.timeout, run); return; }
|
|
156
|
+
if (s.do) { await s.do(this.engine, run); return; }
|
|
157
|
+
if (s.tween) { const t = s.tween; await this._tween(run, t.target, t.to, t.duration ?? 1, t.ease ?? 'inOutCubic'); return; }
|
|
158
|
+
if (s.camera) { await cameraStep(this, s.camera, run); return; }
|
|
159
|
+
if (s.path) { await pathStep(this, s.path, run); return; }
|
|
160
|
+
if (s.say) { await this._say(s.say, run); return; }
|
|
161
|
+
if ('fade' in s) { await this._fade(s.fade, s.to ?? 1, run); return; }
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** Full-screen fade: jumps to the target when skipped @internal */
|
|
165
|
+
async _fade(seconds, to, run) {
|
|
166
|
+
const now = () => fadeScreen(this.engine, to, 0);
|
|
167
|
+
if (run.skipping) return now();
|
|
168
|
+
run.cancels.add(now);
|
|
169
|
+
await fadeScreen(this.engine, to, seconds);
|
|
170
|
+
run.cancels.delete(now);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** @internal */
|
|
174
|
+
_timed(run, o) { return this._tweener.run({ ...o, duration: run.skipping ? 0 : o.duration, group: run }); }
|
|
175
|
+
/** @internal */
|
|
176
|
+
_tween(run, target, to, d, ease) { return this._tweener.tween(target, to, run.skipping ? 0 : d, ease, run); }
|
|
177
|
+
|
|
178
|
+
/** @internal */
|
|
179
|
+
_waitFor(name, timeout, run) {
|
|
180
|
+
if (run.skipping) return Promise.resolve();
|
|
181
|
+
return new Promise(res => {
|
|
182
|
+
let timer = null, over = false;
|
|
183
|
+
const done = () => { if (over) return; over = true; sub.remove(); timer?.cancel(); run.cancels.delete(done); res(); };
|
|
184
|
+
const sub = this.engine.events.once(name, done);
|
|
185
|
+
run.cancels.add(done);
|
|
186
|
+
if (timeout) (timer = this._tweener.run({ duration: timeout })).then(done); // timeout counts in game time
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** Line: { speaker, text, node? }. Needs the dialogue module; skipped with a warning if not installed @internal */
|
|
191
|
+
_say(s, run) {
|
|
192
|
+
const e = this.engine, d = e.dialogue;
|
|
193
|
+
if (!d) { console.warn('[timeline] say requires the dialogue module to be installed'); return Promise.resolve(); }
|
|
194
|
+
if (run.skipping) return Promise.resolve();
|
|
195
|
+
// the line is on top of the focus stack: Esc still skips the whole cutscene
|
|
196
|
+
const said = d.say(s.nodes || s.text, { speaker: s.speaker, node: s.node || 'start', onCancel: run.skippable ? () => this.skip(run) : null });
|
|
197
|
+
return new Promise(done => {
|
|
198
|
+
// skipping the cutscene closes this line; it also settles the step when the line was dropped without ending (a new playthrough)
|
|
199
|
+
const cancel = () => { if (d.speaking === said.id) d.end(); done(); };
|
|
200
|
+
run.cancels.add(cancel);
|
|
201
|
+
said.then(() => { run.cancels.delete(cancel); done(); });
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// ---------- Letterbox ----------
|
|
206
|
+
/** @internal */
|
|
207
|
+
_refreshUI() {
|
|
208
|
+
const runs = [...this.runs], on = runs.some(r => r.letterbox), canSkip = runs.some(r => r.letterbox && r.skippable && !r.skipping);
|
|
209
|
+
this.top.classList.toggle('is-on', on); this.bottom.classList.toggle('is-on', on);
|
|
210
|
+
this.skipBtn.textContent = this.engine.t('timeline.skip');
|
|
211
|
+
this.skipBtn.classList.toggle('is-on', canSkip);
|
|
212
|
+
this.skipBtn.hidden = !canSkip;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const STRINGS = {
|
|
217
|
+
'zh-CN': { 'timeline.skip': '{key:skip} 跳过', 'timeline.skipAction': '跳过过场' },
|
|
218
|
+
en: { 'timeline.skip': '{key:skip} Skip', 'timeline.skipAction': 'Skip cutscene' },
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
const TIMELINE_PARAMS = keysSchema(['skipKeys']);
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Timeline (cutscenes, tweens) -> engine.timeline.
|
|
225
|
+
* timeline({ skipKeys: ['Escape', 'Backspace'] })(timeline({ skipKeys: ['Escape', 'Backspace'] }) (Esc is the back key, dispatched by the UI focus stack)
|
|
226
|
+
* Optional dependency: dialogue (say step). The camera module cooperates with engine.cameraOverride automatically.
|
|
227
|
+
* @param {TimelineOptions} [opts]
|
|
228
|
+
* @returns {ModuleDef<Timeline>}
|
|
229
|
+
*/
|
|
230
|
+
export function timeline(opts = {}) {
|
|
231
|
+
readParams('timeline', TIMELINE_PARAMS, opts);
|
|
232
|
+
let t = null;
|
|
233
|
+
return {
|
|
234
|
+
name: 'timeline', params: TIMELINE_PARAMS, options: opts, label: 'Timeline', stage: 'control', before: ['cameraRig'], // before the camera, so the takeover applies on the same frame
|
|
235
|
+
install(e) {
|
|
236
|
+
e.i18n.add(STRINGS); t = new Timeline(e, opts);
|
|
237
|
+
// a running cutscene ends with its playthrough (session waits one macrotask for its steps to settle)
|
|
238
|
+
e.events.on('session:end', () => { if (t.runs.size) t.skip(); });
|
|
239
|
+
return t;
|
|
240
|
+
},
|
|
241
|
+
frame(dt) { t.frame(dt); },
|
|
242
|
+
// scenario param cutscene: 'skip' | 'keep'
|
|
243
|
+
applyState(e, p) {
|
|
244
|
+
if (p.cutscene === undefined) return;
|
|
245
|
+
t.skipAll = p.cutscene === 'skip';
|
|
246
|
+
if (t.skipAll) t.skip();
|
|
247
|
+
},
|
|
248
|
+
describe(e, ctx) {
|
|
249
|
+
const runs = [...t.runs];
|
|
250
|
+
if (runs.length) ctx.out.cutscene = { count: runs.length, skippable: runs.some(r => r.skippable && !r.skipping), letterbox: runs.some(r => r.letterbox) };
|
|
251
|
+
},
|
|
252
|
+
};
|
|
253
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// Tween: smoothly change a value from its current value to a target over time.
|
|
2
|
+
// Targets use a dot path: 'position.x', 'material.opacity', 'scale' (whole vector), 'material.color' (color).
|
|
3
|
+
// Supported values: numbers; THREE.Vector2/3/4, Euler (give an array [x,y,z], {x,y,z} or Vector3); THREE.Color (give 0xff8800, '#f80' or Color); Quaternion (slerp)
|
|
4
|
+
// Note: material.opacity only shows when the material has transparent: true
|
|
5
|
+
//
|
|
6
|
+
// const tw = new Tweener(); call tw.update(dt) every frame
|
|
7
|
+
// await tw.tween(mesh, { 'position.y': 3, 'material.color': 0xffffff }, 1.5, 'outBack');
|
|
8
|
+
// const p = tw.tween(...); p.finish() jumps to the end; p.cancel() stops where it is
|
|
9
|
+
import * as THREE from 'three';
|
|
10
|
+
import { ease as easing } from '../../core/easing.js';
|
|
11
|
+
import { allowOwned } from '../../core/validate.js';
|
|
12
|
+
import { getPath } from '../../core/util.js';
|
|
13
|
+
|
|
14
|
+
const COMPS = ['x', 'y', 'z', 'w'];
|
|
15
|
+
|
|
16
|
+
/** 'material.color' → { obj: target.material, key: 'color' } */
|
|
17
|
+
function resolve(target, path) {
|
|
18
|
+
const i = path.lastIndexOf('.'), obj = i < 0 ? target : getPath(target, path.slice(0, i));
|
|
19
|
+
return obj == null ? null : { obj, key: path.slice(i + 1) };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Build an interpolator for a property: returns k => apply progress k (0..1) */
|
|
23
|
+
function makeProp(target, path, toValue) {
|
|
24
|
+
const r = resolve(target, path);
|
|
25
|
+
if (!r) { console.warn(`[tween] property not found: ${path}`); return null; }
|
|
26
|
+
const { obj, key } = r, cur = obj[key];
|
|
27
|
+
if (typeof cur === 'number') {
|
|
28
|
+
const from = cur, to = +toValue;
|
|
29
|
+
return k => { obj[key] = from + (to - from) * k; };
|
|
30
|
+
}
|
|
31
|
+
if (cur?.isColor) {
|
|
32
|
+
const from = cur.clone(), to = toValue?.isColor ? toValue.clone() : new THREE.Color(toValue);
|
|
33
|
+
return k => { cur.copy(from).lerp(to, k); };
|
|
34
|
+
}
|
|
35
|
+
if (cur?.isQuaternion) {
|
|
36
|
+
const from = cur.clone(), to = toValue?.isQuaternion ? toValue.clone()
|
|
37
|
+
: toValue?.isEuler ? new THREE.Quaternion().setFromEuler(toValue) : new THREE.Quaternion(...(Array.isArray(toValue) ? toValue : [toValue.x, toValue.y, toValue.z, toValue.w ?? 1]));
|
|
38
|
+
return k => { cur.slerpQuaternions(from, to, k); };
|
|
39
|
+
}
|
|
40
|
+
if (cur && typeof cur === 'object') {
|
|
41
|
+
// vector / Euler: interpolate per component
|
|
42
|
+
const comps = COMPS.filter(c => typeof cur[c] === 'number');
|
|
43
|
+
if (!comps.length) { console.warn(`[tween] unsupported property type: ${path}`); return null; }
|
|
44
|
+
const from = comps.map(c => cur[c]);
|
|
45
|
+
const to = comps.map((c, i) => Array.isArray(toValue) ? (toValue[i] ?? from[i]) : typeof toValue === 'number' ? toValue : (toValue?.[c] ?? from[i]));
|
|
46
|
+
const at = (i, k) => from[i] + (to[i] - from[i]) * k;
|
|
47
|
+
// Euler: one set() so the object's quaternion follows once per step (its public setters keep it in sync)
|
|
48
|
+
if (cur.isEuler) return k => { cur.set(at(0, k), at(1, k), at(2, k), cur.order); };
|
|
49
|
+
return k => { for (let i = 0; i < comps.length; i++) cur[comps[i]] = at(i, k); };
|
|
50
|
+
}
|
|
51
|
+
console.warn(`[tween] unsupported property type: ${path}`);
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
let tweenId = 0; // page-wide on purpose: the owner names go into validate.js allowOwned, whose exemption set is shared by every engine on the page
|
|
56
|
+
|
|
57
|
+
export class Tweener {
|
|
58
|
+
constructor() { this.list = []; }
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* General task: calls step(k) every frame, k is the eased progress. duration in seconds; returns a Promise with finish()/cancel().
|
|
62
|
+
* The start value is read on the first update (so a later queued tween starts from where the previous one ended).
|
|
63
|
+
*/
|
|
64
|
+
run({ duration = 0, ease = 'linear', start, step, end, group = null }) {
|
|
65
|
+
let res;
|
|
66
|
+
const p = new Promise(r => { res = r; });
|
|
67
|
+
const task = { t: 0, dur: Math.max(0, duration), ease: easing(ease), start, step, end, group, res, started: false, done: false };
|
|
68
|
+
task.finish = () => this._complete(task, 1);
|
|
69
|
+
task.cancel = () => this._complete(task, null);
|
|
70
|
+
p.finish = task.finish; p.cancel = task.cancel; p.task = task;
|
|
71
|
+
this.list.push(task);
|
|
72
|
+
if (task.dur === 0) this._complete(task, 1);
|
|
73
|
+
return p;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Property tween: to = { 'position.x': 3, 'material.color': 0xffffff }. A value may also be a function () => value (evaluated at start) */
|
|
77
|
+
// tweens are exempt from the "per-frame overwritten property" warning (tweening lights and fog is a legitimate takeover)
|
|
78
|
+
tween(target, to, duration = 1, ease = 'inOutCubic', group = null) {
|
|
79
|
+
let props = [];
|
|
80
|
+
const owner = 'tween:' + (++tweenId);
|
|
81
|
+
return this.run({
|
|
82
|
+
duration, ease, group,
|
|
83
|
+
start: () => { allowOwned(owner); props = Object.entries(to).map(([path, v]) => makeProp(target, path, typeof v === 'function' ? v() : v)).filter(Boolean); },
|
|
84
|
+
step: k => { for (const f of props) f(k); },
|
|
85
|
+
end: () => allowOwned(owner, false),
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
update(dt) {
|
|
90
|
+
if (!this.list.length) return;
|
|
91
|
+
for (const task of [...this.list]) {
|
|
92
|
+
if (task.done) continue;
|
|
93
|
+
if (!task.started) { task.started = true; task.start?.(); }
|
|
94
|
+
task.t += dt;
|
|
95
|
+
if (task.t >= task.dur) this._complete(task, 1);
|
|
96
|
+
else task.step?.(task.ease(task.t / task.dur));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Jump a group of tasks (or all) to their end */
|
|
101
|
+
finishAll(group) { for (const t of [...this.list]) if (group === undefined || t.group === group) t.finish(); }
|
|
102
|
+
|
|
103
|
+
_complete(task, k) {
|
|
104
|
+
if (task.done) return;
|
|
105
|
+
task.done = true;
|
|
106
|
+
if (k !== null) {
|
|
107
|
+
if (!task.started) { task.started = true; task.start?.(); }
|
|
108
|
+
task.step?.(task.ease(1));
|
|
109
|
+
}
|
|
110
|
+
task.end?.(k !== null);
|
|
111
|
+
const i = this.list.indexOf(task); if (i >= 0) this.list.splice(i, 1);
|
|
112
|
+
task.res(k !== null);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Timeline letterbox bars and skip button (helper of Timeline.js): built once when the module installs; Timeline._refreshUI() toggles them per run.
|
|
2
|
+
import { injectUICSS } from '../../ui/UI.js';
|
|
3
|
+
|
|
4
|
+
export function buildLetterbox(t) {
|
|
5
|
+
injectUICSS(`
|
|
6
|
+
.threedog-letterbox{position:fixed;left:0;right:0;height:0;background:var(--threedog-letterbox-bg,var(--threedog-loading-bg));z-index:18;pointer-events:none;transition:height var(--threedog-letterbox-speed,.5s) ease}
|
|
7
|
+
.threedog-letterbox-top{top:0}.threedog-letterbox-bottom{bottom:0}
|
|
8
|
+
.threedog-letterbox.is-on{height:var(--threedog-letterbox-size,11%)}
|
|
9
|
+
.threedog-letterbox-skip{position:absolute;right:calc(16px + env(safe-area-inset-right,0px));bottom:12px;font:12px var(--threedog-font);color:var(--threedog-muted);
|
|
10
|
+
background:none;border:0;cursor:pointer;pointer-events:auto;opacity:0;transition:opacity .4s}
|
|
11
|
+
.threedog-letterbox.is-on .threedog-letterbox-skip.is-on{opacity:.8}
|
|
12
|
+
.threedog-letterbox-skip:hover,.threedog-letterbox-skip:focus-visible{color:var(--threedog-fg);outline:none}
|
|
13
|
+
@media (prefers-reduced-motion:reduce){.threedog-letterbox{transition:none}}
|
|
14
|
+
`);
|
|
15
|
+
const bar = cls => { const b = document.createElement('div'); b.className = `threedog-ui threedog-letterbox ${cls}`; t.engine.uiRoot.appendChild(b); return b; };
|
|
16
|
+
/** @internal */ t.top = bar('threedog-letterbox-top');
|
|
17
|
+
/** @internal */ t.bottom = bar('threedog-letterbox-bottom');
|
|
18
|
+
/** @internal */ t.skipBtn = document.createElement('button');
|
|
19
|
+
t.skipBtn.type = 'button'; t.skipBtn.className = 'threedog-letterbox-skip';
|
|
20
|
+
t.skipBtn.addEventListener('click', () => { for (const r of t.runs) if (r.skippable) t.skip(r); });
|
|
21
|
+
t.bottom.appendChild(t.skipBtn);
|
|
22
|
+
t.engine.events.on('i18n:change', () => t._refreshUI());
|
|
23
|
+
t.engine.events.on('input:rebind', () => t._refreshUI());
|
|
24
|
+
}
|