threedog 0.7.0 → 1.0.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 +411 -1
- package/README.md +8 -11
- package/core/{Animator.js → assets/Animator.js} +30 -18
- package/core/{Assets.js → assets/Assets.js} +131 -56
- package/core/{Baked.js → assets/Baked.js} +4 -4
- package/core/assets/assetEntry.js +302 -0
- package/core/{assetHot.js → assets/assetHot.js} +9 -7
- package/core/{assetLoad.js → assets/assetLoad.js} +55 -16
- package/core/assets/assetLod.js +113 -0
- package/core/{assetManifest.js → assets/assetManifest.js} +19 -11
- package/core/{assetReport.js → assets/assetReport.js} +7 -14
- package/core/{namedModel.js → assets/namedModel.js} +17 -13
- package/core/{Audio.js → audio/Audio.js} +47 -25
- package/core/{audioRules.js → audio/audioRules.js} +8 -5
- package/core/{audioVoice.js → audio/audioVoice.js} +17 -30
- package/core/{Events.js → base/Events.js} +3 -3
- package/core/{I18n.js → base/I18n.js} +15 -12
- package/core/{Random.js → base/Random.js} +7 -4
- package/core/{Vars.js → base/Vars.js} +14 -4
- package/core/{easing.js → base/easing.js} +1 -1
- package/core/{errorCodes.js → base/errorCodes.js} +151 -125
- package/core/{errorHints.js → base/errorHints.js} +17 -10
- package/core/{errors.js → base/errors.js} +12 -10
- package/core/{events.generated.js → base/events.generated.js} +11 -0
- package/core/base/follows.js +26 -0
- package/core/base/math.js +66 -0
- package/core/{params.js → base/params.js} +5 -6
- package/core/base/saveValues.js +81 -0
- package/core/base/sections.js +97 -0
- package/core/base/spelling.js +32 -0
- package/core/base/util.js +32 -0
- package/core/{validate.js → base/validate.js} +34 -34
- package/core/{Engine.js → engine/Engine.js} +137 -91
- package/core/{Loading.js → engine/Loading.js} +34 -5
- package/core/{copies.js → engine/copies.js} +4 -4
- package/core/{headlessLoad.js → engine/headlessLoad.js} +32 -15
- package/core/{lifecycle.js → engine/lifecycle.js} +41 -34
- package/core/{loop.js → engine/loop.js} +88 -49
- package/core/engine/moduleSlots.js +176 -0
- package/core/{moduleTypes.js → engine/moduleTypes.js} +26 -14
- package/core/engine/modules.js +503 -0
- package/core/{page.js → engine/page.js} +59 -29
- package/core/{plugins.js → engine/plugins.js} +21 -12
- package/core/{services.js → engine/services.js} +50 -40
- package/core/{startup.js → engine/startup.js} +66 -54
- package/core/{Input.js → input/Input.js} +67 -39
- package/core/{inputContext.js → input/inputContext.js} +14 -5
- package/core/input/inputKeyboard.js +39 -0
- package/core/{inputPad.js → input/inputPad.js} +24 -3
- package/core/{inputPointer.js → input/inputPointer.js} +11 -3
- package/core/input/inputSeat.js +66 -0
- package/core/{inputTouch.js → input/inputTouch.js} +24 -7
- package/core/{Budget.js → inspect/Budget.js} +21 -20
- package/core/{DebugOverrides.js → inspect/DebugOverrides.js} +43 -18
- package/core/{Describe.js → inspect/Describe.js} +34 -26
- package/core/{Inspect.js → inspect/Inspect.js} +39 -10
- package/core/{InspectMaterials.js → inspect/InspectMaterials.js} +7 -8
- package/core/{InspectPerf.js → inspect/InspectPerf.js} +19 -13
- package/core/{InspectScene.js → inspect/InspectScene.js} +8 -5
- package/core/{MaterialInfo.js → inspect/MaterialInfo.js} +3 -2
- package/core/{UrlState.js → inspect/UrlState.js} +60 -24
- package/core/{catalog.js → inspect/catalog.js} +15 -8
- package/core/{checks.js → inspect/checks.js} +7 -5
- package/core/{debugView.js → inspect/debugView.js} +4 -4
- package/core/{describeRender.js → inspect/describeRender.js} +24 -22
- package/core/{describeText.js → inspect/describeText.js} +17 -8
- package/core/inspect/geometryWatch.js +38 -0
- package/core/{lightWatch.js → inspect/lightWatch.js} +8 -8
- package/core/inspect/metadata.generated.js +4140 -0
- package/core/{pictureWriters.js → inspect/pictureWriters.js} +130 -47
- package/core/{shaderCost.js → inspect/shaderCost.js} +1 -1
- package/core/inspect/toolDoor.js +21 -0
- package/core/inspect/valueHistory.js +35 -0
- package/core/{Ops.js → ops/Ops.js} +44 -14
- package/core/{control.js → ops/control.js} +57 -31
- package/core/ops/holds.js +140 -0
- package/core/{opsAtomic.js → ops/opsAtomic.js} +18 -5
- package/core/{opsCheck.js → ops/opsCheck.js} +11 -10
- package/core/{opsFail.js → ops/opsFail.js} +5 -7
- package/core/{opsGuard.js → ops/opsGuard.js} +3 -3
- package/core/{opsRun.js → ops/opsRun.js} +9 -6
- package/core/{owned.js → ops/owned.js} +33 -19
- package/core/{sharedPoint.js → ops/sharedPoint.js} +13 -16
- package/core/{stackFrames.js → ops/stackFrames.js} +2 -2
- package/core/{stacks.js → ops/stacks.js} +34 -15
- package/core/{wrap.js → ops/wrap.js} +8 -6
- package/core/{SaveStore.js → saves/SaveStore.js} +53 -27
- package/core/{Saves.js → saves/Saves.js} +171 -54
- package/core/saves/saveApply.js +312 -0
- package/core/{saveFiles.js → saves/saveFiles.js} +45 -38
- package/core/{saveVersions.js → saves/saveVersions.js} +24 -23
- package/core/saves/session.js +231 -0
- package/core/saves/stateReplace.js +184 -0
- package/core/{Rays.js → scene/Rays.js} +44 -30
- package/core/{Views.js → scene/Views.js} +16 -8
- package/core/{adaptive.js → scene/adaptive.js} +19 -9
- package/core/{canvasBox.js → scene/canvasBox.js} +4 -3
- package/core/scene/compositeGround.js +72 -0
- package/core/scene/floor.js +17 -0
- package/core/{gameLights.js → scene/gameLights.js} +17 -7
- package/core/{grayMap.js → scene/grayMap.js} +8 -2
- package/core/{grid.js → scene/grid.js} +6 -4
- package/core/{gridLoad.js → scene/gridLoad.js} +1 -1
- package/core/scene/ground.contract.js +14 -0
- package/core/scene/ground.js +139 -0
- package/core/{movement.js → scene/movement.js} +3 -3
- package/core/{pictureSlots.js → scene/pictureSlots.js} +2 -2
- package/core/scene/pixel.js +154 -0
- package/core/scene/pixelRatio.js +167 -0
- package/core/{sceneDelta.js → scene/sceneDelta.js} +5 -5
- package/core/{sceneMethods.js → scene/sceneMethods.js} +43 -15
- package/core/scene/stepPoses.js +60 -0
- package/core/{targeting.js → scene/targeting.js} +4 -5
- package/core/{thingExplain.js → scene/thingExplain.js} +7 -6
- package/core/{thingOps.js → scene/thingOps.js} +25 -16
- package/core/{things.js → scene/things.js} +18 -5
- package/core/{threePatches.js → scene/threePatches.js} +1 -1
- package/core/{tier.js → scene/tier.js} +10 -0
- package/core/scene/view.js +161 -0
- package/core/{Batching.js → stream/Batching.js} +85 -28
- package/core/{Stream.js → stream/Stream.js} +80 -38
- package/core/{batchGroups.js → stream/batchGroups.js} +11 -9
- package/core/{chunkStream.js → stream/chunkStream.js} +40 -0
- package/core/{scatter.js → stream/scatter.js} +7 -4
- package/core/{streamSources.js → stream/streamSources.js} +14 -8
- package/core/{Commits.js → threads/Commits.js} +17 -11
- package/core/{Jobs.js → threads/Jobs.js} +25 -13
- package/core/{Threads.js → threads/Threads.js} +21 -18
- package/core/{threadPure.js → threads/threadPure.js} +7 -5
- package/core/{threadServe.js → threads/threadServe.js} +3 -3
- package/core/{Clock.js → time/Clock.js} +20 -11
- package/core/{dayTime.js → time/dayTime.js} +5 -1
- package/core/{skip.js → time/skip.js} +28 -21
- package/core/{time.js → time/time.js} +32 -20
- package/core/{uiClock.js → time/uiClock.js} +4 -4
- package/docs/AI.md +92 -72
- package/docs/API.md +33 -28
- package/docs/CODEMAP.md +121 -200
- package/docs/COMMANDS.md +77 -70
- package/docs/CONVENTIONS.md +167 -24
- package/docs/MIGRATING-0.8.md +171 -0
- package/docs/MIGRATING-1.0.md +101 -0
- package/docs/THREE.md +140 -38
- package/docs/api/assets.md +12 -13
- package/docs/api/audio.md +6 -5
- package/docs/api/budget.md +4 -4
- package/docs/api/calendar.md +10 -11
- package/docs/api/cameraRig.md +32 -29
- package/docs/api/characters.md +35 -24
- package/docs/api/clock.md +1 -1
- package/docs/api/collider3d.md +9 -0
- package/docs/api/collision.md +12 -9
- package/docs/api/content.md +18 -17
- package/docs/api/dialogue.md +5 -4
- package/docs/api/engine.md +58 -54
- package/docs/api/events.md +17 -6
- package/docs/api/flow.md +1 -1
- package/docs/api/grids.md +1 -1
- package/docs/api/ground.md +6 -7
- package/docs/api/hud.md +2 -2
- package/docs/api/i18n.md +6 -6
- package/docs/api/input.md +9 -8
- package/docs/api/interactions.md +5 -5
- package/docs/api/inventory.md +10 -10
- package/docs/api/jobs.md +5 -5
- package/docs/api/level.md +10 -9
- package/docs/api/lightPool.md +1 -6
- package/docs/api/music.md +3 -3
- package/docs/api/nav.md +14 -12
- package/docs/api/openWorld.md +1 -1
- package/docs/api/particles.md +10 -7
- package/docs/api/photo.md +4 -2
- package/docs/api/pickups.md +3 -3
- package/docs/api/post.md +21 -5
- package/docs/api/quests.md +7 -5
- package/docs/api/rays.md +7 -7
- package/docs/api/rigid.md +29 -19
- package/docs/api/saves.md +13 -11
- package/docs/api/settings.md +9 -8
- package/docs/api/sky.md +8 -7
- package/docs/api/stream.md +8 -9
- package/docs/api/swarm.md +34 -0
- package/docs/api/terrain.md +6 -8
- package/docs/api/terrainDraw.md +2 -2
- package/docs/api/timeline.md +4 -4
- package/docs/api/tools.md +27 -22
- package/docs/api/triggers.md +2 -0
- package/docs/api/vars.md +1 -1
- package/docs/api/vegetation.md +4 -3
- package/docs/api/vegetationDraw.md +2 -2
- package/docs/api/water.md +7 -3
- package/docs/api/weather.md +27 -12
- package/docs/api/weatherDraw.md +4 -4
- package/docs/api/world.md +6 -6
- package/docs/recipes/01-new-game.md +28 -43
- package/docs/recipes/02-npc.md +21 -23
- package/docs/recipes/03-items-pickups.md +37 -53
- package/docs/recipes/04-quests.md +5 -4
- package/docs/recipes/05-props-bake.md +34 -44
- package/docs/recipes/06-clock-events.md +31 -22
- package/docs/recipes/07-flow-scenes-pause.md +30 -32
- package/docs/recipes/08-weather-sky.md +91 -37
- package/docs/recipes/09-materials-lights-models.md +25 -39
- package/docs/recipes/10-blender-level.md +22 -11
- package/docs/recipes/11-vehicles.md +44 -24
- package/docs/recipes/12-navmesh.md +60 -15
- package/docs/recipes/13-animation.md +70 -22
- package/docs/recipes/14-custom-module.md +33 -20
- package/docs/recipes/15-perf.md +51 -28
- package/docs/recipes/16-dev-bridge.md +39 -58
- package/docs/recipes/18-world.md +49 -28
- package/docs/recipes/19-shooting-picking.md +7 -4
- package/docs/recipes/20-content-actions-save.md +55 -40
- package/docs/recipes/21-camera.md +47 -25
- package/docs/recipes/22-shop-gold.md +21 -16
- package/docs/recipes/23-ops.md +28 -24
- package/docs/recipes/26-ui-parts.md +25 -14
- package/docs/recipes/27-net.md +3 -5
- package/docs/recipes/28-terrain.md +119 -23
- package/docs/recipes/29-grid.md +3 -3
- package/docs/recipes/30-templates.md +63 -30
- package/docs/recipes/31-audio.md +7 -7
- package/docs/recipes/32-action-game.md +21 -11
- package/docs/recipes/33-stream-sources.md +6 -3
- package/docs/recipes/34-environment-lighting.md +72 -25
- package/docs/recipes/35-picture-from-reference.md +20 -23
- package/docs/recipes/36-ground-plants.md +106 -0
- package/docs/recipes/40-scene.md +18 -21
- package/docs/recipes/43-shader-patches-surfaces.md +27 -48
- package/docs/recipes/44-water-weather-hooks.md +56 -50
- package/docs/recipes/45-cascaded-shadows.md +41 -20
- package/docs/recipes/46-blender-art-route.md +9 -10
- package/docs/recipes/49-game-module-contract.md +7 -6
- package/docs/recipes/50-own-renderer.md +3 -2
- package/docs/recipes/51-capability-catalog.md +14 -8
- package/docs/recipes/52-around-the-picture.md +56 -100
- package/docs/recipes/53-ground-up-close.md +61 -24
- package/docs/recipes/55-mods-time-wrap.md +17 -20
- package/docs/recipes/56-webgpu-tsl.md +28 -15
- package/docs/recipes/57-control.md +39 -12
- package/docs/recipes/58-input.md +15 -2
- package/docs/recipes/59-depth-post-effects.md +1 -1
- package/docs/recipes/60-judge-the-picture.md +30 -25
- package/docs/recipes/62-picture-code.md +129 -39
- package/docs/recipes/63-third-person-start.md +19 -5
- package/docs/recipes/64-particles.md +54 -5
- package/docs/recipes/65-swarm.md +140 -0
- package/docs/recipes/66-common-tasks.md +313 -0
- package/examples/action/.threedog/content-index.json +1 -1
- package/examples/action/GAMEMAP.md +5 -5
- package/examples/perf-island/.threedog/content-index.json +1 -0
- package/examples/{sheepisland → perf-island}/GAMEMAP.md +15 -14
- package/examples/{sheepisland → perf-island}/assets.js +1 -1
- package/examples/{sheepisland → perf-island}/main.js +8 -8
- package/examples/{sheepisland → perf-island}/models.js +1 -1
- package/examples/{sheepisland → perf-island}/params.js +1 -1
- package/examples/{sheepisland → perf-island}/picture/index.js +1 -1
- package/examples/{sheepisland → perf-island}/picture/palette.js +2 -2
- package/examples/{sheepisland → perf-island}/views.js +1 -1
- package/examples/plain-picture/GAMEMAP.md +4 -1
- package/examples/rc2d/GAMEMAP.md +4 -3
- package/examples/rc2d/main.js +1 -3
- package/examples/rc2d/rc2d.js +1 -1
- package/examples/styletest/.threedog/content-index.json +1 -1
- package/examples/styletest/GAMEMAP.md +6 -5
- package/examples/techniques/contact-shadows/contactShadows.js +1 -1
- package/examples/techniques/contact-shadows/main.js +1 -1
- package/examples/techniques/interior-light/main.js +1 -1
- package/examples/techniques/modular-building/README.md +7 -6
- package/examples/techniques/outlines-and-rim/picture/post.js +1 -1
- package/examples/techniques/procedural-animation/README.md +1 -1
- package/examples/webgpu-tsl/GAMEMAP.md +2 -1
- package/examples/world/.threedog/content-index.json +1 -1
- package/examples/world/GAMEMAP.md +9 -7
- package/examples/world/main.js +3 -3
- package/examples/world/picture/sky.js +1 -1
- package/index.d.ts +16 -12
- package/index.js +53 -32
- package/llms.txt +11 -14
- package/modules/ambience/Ambience.js +16 -11
- package/modules/calendar/Calendar.js +19 -19
- package/modules/calendar/index.js +18 -16
- package/modules/calendar/schedule.js +11 -6
- package/modules/calendar/seasons.js +7 -7
- package/modules/camera/FirstPersonCamera.js +5 -5
- package/modules/camera/FixedCamera.js +43 -30
- package/modules/camera/FollowCamera.js +24 -15
- package/modules/camera/RtsCamera.js +12 -11
- package/modules/camera/common.js +72 -37
- package/modules/camera/contract.js +1 -0
- package/modules/camera/pixelSnap.js +62 -0
- package/modules/characters/Character.js +166 -70
- package/modules/characters/NPC.js +84 -44
- package/modules/characters/assetModel.js +16 -12
- package/modules/characters/astar.js +48 -27
- package/modules/characters/behaviors.js +4 -5
- package/modules/characters/character.contract.js +21 -0
- package/modules/characters/contract.js +17 -3
- package/modules/characters/index.js +240 -226
- package/modules/characters/moveHelpers.js +88 -12
- package/modules/characters/mover.contract.js +14 -0
- package/modules/characters/movers/common.js +22 -18
- package/modules/characters/movers/manual.js +1 -1
- package/modules/characters/movers/rapier.js +18 -10
- package/modules/characters/movers/simple.js +26 -13
- package/modules/characters/movers/support.js +24 -13
- package/modules/characters/npcAvoid.js +19 -16
- package/modules/characters/npcSim.js +88 -32
- package/modules/characters/npcView.js +19 -11
- package/modules/characters/pathAsync.js +81 -29
- package/modules/characters/pathJob.js +38 -21
- package/modules/characters/pathWorker.js +1 -1
- package/modules/characters/player.js +120 -0
- package/modules/characters/playerStrings.js +2 -2
- package/modules/characters/proceduralRig.js +2 -2
- package/modules/characters/seat.js +56 -0
- package/modules/characters/useModel.js +3 -3
- package/modules/characters/vehicle.contract.js +8 -5
- package/modules/characters/walkTo.js +40 -33
- package/modules/collision/Collision.js +69 -45
- package/modules/collision/contract.js +15 -0
- package/modules/collision/grid.js +6 -1
- package/modules/content/explain.js +2 -3
- package/modules/content/fields.js +24 -3
- package/modules/content/ids.js +5 -3
- package/modules/content/index.js +132 -114
- package/modules/content/loader.js +117 -140
- package/modules/content/markers.js +25 -0
- package/modules/content/models.js +54 -17
- package/modules/content/packs.js +5 -4
- package/modules/content/parts.js +2 -2
- package/modules/content/places.js +36 -0
- package/modules/content/props.js +22 -17
- package/modules/content/rules.js +47 -61
- package/modules/content/stages.js +7 -7
- package/modules/content/templates.js +80 -49
- package/modules/content/words.js +47 -0
- package/modules/debug/DebugPanel.js +14 -45
- package/modules/flow/contract.js +2 -1
- package/modules/flow/index.js +30 -16
- package/modules/gameplay/Container.js +17 -13
- package/modules/gameplay/Containers.js +23 -6
- package/modules/gameplay/Dialogue.js +93 -34
- package/modules/gameplay/Interactions.js +93 -51
- package/modules/gameplay/Inventory.js +64 -22
- package/modules/gameplay/Quests.js +146 -30
- package/modules/gameplay/boxOps.js +8 -1
- package/modules/gameplay/dialogueBubbles.js +16 -12
- package/modules/gameplay/inventoryOps.js +11 -8
- package/modules/gameplay/pickups.js +63 -37
- package/modules/gameplay/questLog.js +4 -2
- package/modules/gameplay/questSave.js +9 -4
- package/modules/gameplay/quests.contract.js +1 -1
- package/modules/grid/Grid.js +2 -2
- package/modules/grid/Layer.js +12 -8
- package/modules/grid/index.js +28 -23
- package/modules/grid/ops.js +43 -46
- package/modules/grid/preview.js +7 -7
- package/modules/grid/tiles.js +6 -6
- package/modules/hlod/index.js +42 -57
- package/modules/hud/index.js +22 -14
- package/modules/hud/parts.js +8 -8
- package/modules/level/contract.js +16 -0
- package/modules/level/heightfield.js +29 -31
- package/modules/level/index.js +113 -161
- package/modules/level/load.js +196 -0
- package/modules/level/meshes.js +65 -0
- package/modules/level/nodes.js +40 -23
- package/modules/lights/index.js +33 -183
- package/modules/lights/slots.js +93 -0
- package/modules/lights/sources.js +90 -0
- package/modules/music/Music.js +34 -28
- package/modules/music/rules.js +1 -1
- package/modules/nav/contract.js +16 -0
- package/modules/nav/index.js +180 -49
- package/modules/nav/navPath.js +45 -10
- package/modules/net/Client.js +7 -7
- package/modules/net/Host.js +7 -7
- package/modules/net/Net.js +1 -1
- package/modules/net/index.js +6 -5
- package/modules/net/sync.js +2 -2
- package/modules/net/transports.js +2 -2
- package/modules/particles/Particles.js +95 -29
- package/modules/particles/effect.js +86 -32
- package/modules/particles/shaders.js +19 -1
- package/modules/photo/Photo.js +23 -23
- package/modules/rigid/RigidBodies.js +255 -89
- package/modules/rigid/Vehicles.js +17 -8
- package/modules/rigid/collider3d.contract.js +26 -0
- package/modules/rigid/ragdoll.js +298 -0
- package/modules/rigid/ragdollBones.js +209 -0
- package/modules/rigid/refresh.js +10 -0
- package/modules/rigid/sync.js +51 -20
- package/modules/settings/Settings.js +177 -61
- package/modules/settings/apply.js +20 -13
- package/modules/settings/sections.js +19 -14
- package/modules/settings/strings.js +2 -2
- package/modules/settings/view.js +3 -3
- package/modules/sky/Sky.js +29 -22
- package/modules/sky/clouds.js +7 -7
- package/modules/sky/dome.js +33 -20
- package/modules/sky/domeLayers.js +9 -9
- package/modules/sky/environment.js +6 -6
- package/modules/sky/frame.js +19 -10
- package/modules/sky/season.js +7 -1
- package/modules/sky/shader.js +24 -25
- package/modules/sky/skyModule.js +17 -28
- package/modules/sky/tint.js +1 -1
- package/modules/swarm/Swarm.js +356 -0
- package/modules/swarm/draw.js +68 -0
- package/modules/swarm/grid.js +63 -0
- package/modules/terrain/ChunkManager.js +71 -59
- package/modules/terrain/chunkQueries.js +7 -24
- package/modules/terrain/chunkWorker.js +1 -1
- package/modules/terrain/draw.js +14 -11
- package/modules/terrain/index.js +42 -42
- package/modules/terrain/terrainColorMap.js +6 -3
- package/modules/terrain/terrainDefaults.js +2 -1
- package/modules/terrain/terrainEdit.js +45 -29
- package/modules/terrain/terrainGen.js +19 -12
- package/modules/terrain/terrainIsland.js +2 -2
- package/modules/terrain/terrainMesh.js +7 -6
- package/modules/terrain/terrainShape.js +8 -10
- package/modules/terrain/terrainShapeMain.js +3 -3
- package/modules/timeline/Timeline.js +83 -43
- package/modules/timeline/Tween.js +25 -19
- package/modules/timeline/shots.js +24 -17
- package/modules/triggers/index.js +95 -28
- package/modules/vegetation/Vegetation.js +34 -26
- package/modules/vegetation/densityMap.js +4 -7
- package/modules/vegetation/draw.js +39 -18
- package/modules/vegetation/groundChunks.js +21 -38
- package/modules/vegetation/index.js +37 -12
- package/modules/vegetation/modelGeometry.js +3 -6
- package/modules/vegetation/nearFade.js +1 -1
- package/modules/water/Water.js +20 -16
- package/modules/water/surface.js +3 -3
- package/modules/weather/Weather.js +52 -40
- package/modules/weather/particles.js +8 -8
- package/modules/weather/weatherDraw.js +28 -23
- package/modules/world/World.js +28 -15
- package/modules/world/explain.js +1 -1
- package/modules/world/index.js +30 -17
- package/modules/world/persist.js +90 -27
- package/modules/world/pos.js +5 -5
- package/modules/world/records.js +37 -11
- package/modules/world/sim.js +78 -27
- package/modules/world/simFar.js +2 -2
- package/modules/world/state.js +43 -11
- package/modules/world/thingSource.js +20 -5
- package/modules/world/views.js +27 -14
- package/package.json +48 -7
- package/presets.js +1 -3
- package/render/PostFX.js +83 -53
- package/render/backend.js +31 -33
- package/render/cascades.js +17 -12
- package/render/cascades.tsl.js +5 -8
- package/render/daylight.js +20 -3
- package/render/detail.js +8 -7
- package/render/effects.js +28 -25
- package/render/fuse.js +3 -3
- package/render/fx/cloudShadow.tsl.js +3 -3
- package/render/fx/detail.tsl.js +1 -1
- package/render/fx/index.js +5 -10
- package/render/fx/library.tsl.js +11 -0
- package/render/fx/lighting.tsl.js +2 -1
- package/render/fx/nodeErrors.tsl.js +2 -2
- package/render/fx/objectOrigin.tsl.js +1 -2
- package/render/fx/particles.tsl.js +8 -6
- package/render/fx/patchNodes.tsl.js +5 -15
- package/render/fx/postWebGPU.tsl.js +30 -26
- package/render/fx/sky.tsl.js +15 -17
- package/render/fx/uniforms.tsl.js +4 -4
- package/render/fx/wind.tsl.js +1 -1
- package/render/fxNumbers.js +3 -0
- package/render/layers.js +2 -2
- package/render/lighting.js +5 -3
- package/render/lightmap.js +41 -21
- package/render/lights.js +6 -6
- package/render/lit.js +24 -0
- package/render/materials.js +8 -7
- package/render/mergeCommon.js +22 -0
- package/render/modeling.js +2 -2
- package/render/occlusion.js +62 -15
- package/render/ownFrame.js +4 -4
- package/render/patches.js +15 -15
- package/render/postWebGL.js +15 -12
- package/render/probes.js +41 -19
- package/render/recordSweep.js +117 -0
- package/render/shaderErrors.js +10 -9
- package/render/shadowCache.tsl.js +107 -0
- package/render/shadowTypes.js +9 -0
- package/{core → render}/shadows.js +59 -13
- package/render/slots.js +7 -7
- package/render/terms.js +22 -24
- package/render/uniformDecl.js +1 -1
- package/types/core.d.ts +336 -202
- package/types/gameplay.d.ts +254 -130
- package/types/generated/core/{Audio.d.ts → audio/Audio.d.ts} +22 -7
- package/types/generated/core/{audioVoice.d.ts → audio/audioVoice.d.ts} +2 -2
- package/types/generated/core/{Events.d.ts → base/Events.d.ts} +4 -4
- package/types/generated/core/{I18n.d.ts → base/I18n.d.ts} +8 -16
- package/types/generated/core/{Random.d.ts → base/Random.d.ts} +4 -3
- package/types/generated/core/{page.d.ts → engine/page.d.ts} +8 -9
- package/types/generated/core/{Input.d.ts → input/Input.d.ts} +28 -10
- package/types/generated/core/input/inputSeat.d.ts +26 -0
- package/types/generated/core/{Budget.d.ts → inspect/Budget.d.ts} +36 -26
- package/types/generated/core/{DebugOverrides.d.ts → inspect/DebugOverrides.d.ts} +17 -3
- package/types/generated/core/{Ops.d.ts → ops/Ops.d.ts} +6 -4
- package/types/generated/core/{control.d.ts → ops/control.d.ts} +14 -10
- package/types/generated/core/{Saves.d.ts → saves/Saves.d.ts} +62 -18
- package/types/generated/core/{session.d.ts → saves/session.d.ts} +3 -2
- package/types/generated/core/{Rays.d.ts → scene/Rays.d.ts} +8 -27
- package/types/generated/core/{Views.d.ts → scene/Views.d.ts} +2 -2
- package/types/generated/core/{Batching.d.ts → stream/Batching.d.ts} +7 -7
- package/types/generated/core/{Stream.d.ts → stream/Stream.d.ts} +22 -18
- package/types/generated/core/{Commits.d.ts → threads/Commits.d.ts} +1 -1
- package/types/generated/core/{Jobs.d.ts → threads/Jobs.d.ts} +6 -6
- package/types/generated/core/{Threads.d.ts → threads/Threads.d.ts} +4 -4
- package/types/generated/modules/calendar/Calendar.d.ts +10 -11
- package/types/generated/modules/debug/DebugPanel.d.ts +1 -9
- package/types/generated/modules/grid/Grid.d.ts +1 -0
- package/types/generated/modules/grid/Layer.d.ts +1 -1
- package/types/generated/modules/grid/index.d.ts +3 -3
- package/types/generated/modules/music/Music.d.ts +7 -5
- package/types/generated/modules/particles/Particles.d.ts +5 -4
- package/types/generated/modules/sky/Sky.d.ts +21 -10
- package/types/generated/modules/swarm/Swarm.d.ts +80 -0
- package/types/generated/modules/timeline/Timeline.d.ts +7 -5
- package/types/generated/modules/water/Water.d.ts +1 -0
- package/types/generated/modules/weather/Weather.d.ts +14 -16
- package/types/generated/modules/weather/weatherDraw.d.ts +3 -3
- package/types/generated/modules/world/World.d.ts +11 -7
- package/types/generated/render/PostFX.d.ts +21 -23
- package/types/generated/render/materials.d.ts +1 -0
- package/types/generated/render/occlusion.d.ts +9 -0
- package/types/generated/render/patches.d.ts +1 -0
- package/types/generated/ui/Focus.d.ts +1 -0
- package/types/generated/ui/UI.d.ts +1 -0
- package/types/nav.d.ts +47 -15
- package/types/physics.d.ts +150 -73
- package/types/pixel.d.ts +75 -0
- package/types/tsl.d.ts +37 -4
- package/types/world.d.ts +48 -75
- package/ui/Focus.js +10 -9
- package/ui/Parts.js +13 -5
- package/ui/UI.js +7 -7
- package/ui/defaults.js +3 -2
- package/ui/theme.js +7 -5
- package/core/assetEntry.js +0 -109
- package/core/engineCamera.js +0 -32
- package/core/ground.js +0 -104
- package/core/holds.js +0 -134
- package/core/math.js +0 -48
- package/core/moduleSlots.js +0 -100
- package/core/modules.js +0 -314
- package/core/saveApply.js +0 -210
- package/core/saveValues.js +0 -46
- package/core/session.js +0 -174
- package/core/shadowTypes.js +0 -16
- package/core/util.js +0 -17
- package/core/view.js +0 -43
- package/docs/MIGRATING-0.3.md +0 -248
- package/docs/MIGRATING-0.4.md +0 -320
- package/docs/MIGRATING-0.5.md +0 -68
- package/docs/MIGRATING-0.6.md +0 -126
- package/docs/PERF.md +0 -245
- package/docs/recipes/36-sky-ground-plants.md +0 -158
- package/docs/recipes/37-terrain-hooks.md +0 -115
- package/docs/recipes/38-environment-hooks.md +0 -67
- package/docs/recipes/42-terrain-shape.md +0 -64
- package/docs/recipes/47-island-snow-backdrop.md +0 -43
- package/docs/recipes/54-three-idioms.md +0 -88
- package/examples/plain-picture/FINDINGS.md +0 -53
- package/examples/sheepisland/.threedog/content-index.json +0 -1
- package/modules/camera/projection.js +0 -21
- /package/core/{mulberry32.js → base/mulberry32.js} +0 -0
- /package/core/{inputDefaults.js → input/inputDefaults.js} +0 -0
- /package/core/{textureBytes.js → inspect/textureBytes.js} +0 -0
- /package/core/{actor.js → ops/actor.js} +0 -0
- /package/core/{opsHistory.js → ops/opsHistory.js} +0 -0
- /package/core/{saveIds.js → saves/saveIds.js} +0 -0
- /package/core/{screenToGround.js → scene/screenToGround.js} +0 -0
- /package/core/{cells.js → stream/cells.js} +0 -0
- /package/core/{streamCells.js → stream/streamCells.js} +0 -0
- /package/core/{pureWorker.js → threads/pureWorker.js} +0 -0
- /package/examples/{sheepisland → perf-island}/content/index.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/props.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/templates.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/vegetation.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/lights.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/materials.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/sky.js +0 -0
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
//
|
|
17
17
|
// Options: skippable (default true); letterbox black bars top and bottom (default false); actors: the characters the cutscene drives (default: the
|
|
18
18
|
// player when there is one; [] leaves everyone free, e.g. a bubble scene the player walks through)
|
|
19
|
-
// Control (core/control.js): the run takes each actor's control slot on layer 'cutscene' (owner 'timeline'), and a path step takes its character too.
|
|
19
|
+
// Control (core/ops/control.js): the run takes each actor's control slot on layer 'cutscene' (owner 'timeline'), and a path step takes its character too.
|
|
20
20
|
// What they were doing pauses, not cancels: the player's keys, a walkTo, an NPC's schedule carry on when the run ends or is skipped. While the
|
|
21
21
|
// player is an actor the 'cutscene' input context is up, so gameplay keys do nothing. Every run is one owner ('timeline'), counted per character,
|
|
22
22
|
// so two overlapping cutscenes never conflict with each other; the slot goes back when the last run using that character ends.
|
|
@@ -25,21 +25,26 @@
|
|
|
25
25
|
// While frozen (engine.freeze / flow 'paused') wait, tweens, camera and paths do not advance; they resume after unfreezing.
|
|
26
26
|
// 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).
|
|
27
27
|
// 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
|
|
28
|
-
// module then resumes.
|
|
28
|
+
// module then resumes. While a newer holder has the camera, or something above the cutscene has a path's character, the step keeps its time and writes nothing (shots.js).
|
|
29
29
|
// To hand the camera back midway: { camera: { release: true } }
|
|
30
30
|
// General tween (usable anywhere in a game): await engine.timeline.tween(mesh, { 'position.y': 2, 'material.opacity': 0 }, { duration: 1, ease: 'outCubic' })
|
|
31
|
-
//
|
|
31
|
+
// Ending: a run has one, set once: 'finished', 'skipped', 'dropped' (its state is gone: a load, a new game, the engine) or 'failed' (a step threw). play() resolves with
|
|
32
|
+
// { ending, error? }, timeline:end carries the same, describe counts them. Dropped and failed run nothing more and give the screen back; a run that ends in a step of its own
|
|
33
|
+
// choosing keeps the fade it asked for. What a run holds goes back in the one finally of play().
|
|
34
|
+
// Events: timeline:start, timeline:end { id, ending, error? }
|
|
32
35
|
// Scenario param cutscene (engine.applyState / URL ?cutscene=skip): 'skip' skips the playing cutscene and all later ones, 'keep' restores normal behavior.
|
|
33
36
|
import { Tweener } from './Tween.js';
|
|
34
37
|
import { fadeScreen, uiFocus } from '../../ui/UI.js';
|
|
35
38
|
import { cameraStep, pathStep, releaseCamera } from './shots.js';
|
|
36
39
|
import { buildLetterbox } from './letterbox.js';
|
|
37
40
|
|
|
38
|
-
import { readParams, keysSchema
|
|
39
|
-
import {
|
|
41
|
+
import { readParams, keysSchema } from '../../core/base/params.js'; // isOptions: a step part can also be a shot name, a text or a point list
|
|
42
|
+
import { isOptions } from '../../core/base/util.js';
|
|
43
|
+
import { warnOnce } from '../../core/base/validate.js';
|
|
40
44
|
const TWEEN_KEYS = ['duration', 'ease'];
|
|
41
|
-
import { coded, codedError } from '../../core/errorHints.js';
|
|
42
|
-
import { reportError } from '../../core/errors.js';
|
|
45
|
+
import { coded, codedError } from '../../core/base/errorHints.js';
|
|
46
|
+
import { reportError } from '../../core/base/errors.js';
|
|
47
|
+
import { stateTurn } from '../../core/saves/stateReplace.js';
|
|
43
48
|
/** @import { ModuleDef } from '../../types/core' */
|
|
44
49
|
/** @import { Ease } from '../../types/common' */
|
|
45
50
|
/** @import { TimelineStep, TimelinePlayOptions, TimelineOptions, TweenTo, TweenPromise } from '../../types/gameplay' */
|
|
@@ -71,7 +76,8 @@ export class Timeline {
|
|
|
71
76
|
/** @internal */ this._tweener = new Tweener();
|
|
72
77
|
/** @internal */ this.runs = new Set();
|
|
73
78
|
/** @internal numbers the runs of this engine (timeline:start / timeline:end id) */ this._runSeq = 0;
|
|
74
|
-
/**
|
|
79
|
+
/** @internal how runs ended, and the last failure: describe */ this._endings = { finished: 0, skipped: 0, dropped: 0, failed: 0 }; this._failure = null;
|
|
80
|
+
/** Skip every cutscene immediately (set by scenario param cutscene=skip) @type {boolean} @experimental */
|
|
75
81
|
this.skipAll = false;
|
|
76
82
|
ctx.track(engine.input.action('skip', { context: 'cutscene', label: 'timeline.skipAction', optional: true, owner: 'timeline' })); // cancel skips anyway
|
|
77
83
|
buildLetterbox(this);
|
|
@@ -80,12 +86,13 @@ export class Timeline {
|
|
|
80
86
|
/**
|
|
81
87
|
* Whether a cutscene is playing
|
|
82
88
|
* @returns {boolean}
|
|
89
|
+
* @experimental
|
|
83
90
|
*/
|
|
84
91
|
get playing() { return this.runs.size > 0; }
|
|
85
92
|
|
|
86
93
|
/**
|
|
87
94
|
* General tween (the only entry point for tweens in the engine): await engine.timeline.tween(mesh, { 'position.y': 2 }, { duration: 1, ease: 'outCubic' }); duration in seconds (default 1), ease default 'inOutCubic'; tween(mesh, to, 1) throws in dev.
|
|
88
|
-
* Returns a Promise (with finish() / remove())
|
|
95
|
+
* Returns a Promise (with finish() / remove()); a write that throws ends the tween and rejects it
|
|
89
96
|
* @param {any} target
|
|
90
97
|
* @param {TweenTo} to
|
|
91
98
|
* @param {{ duration?: number, ease?: Ease }} [opts]
|
|
@@ -97,37 +104,46 @@ export class Timeline {
|
|
|
97
104
|
}
|
|
98
105
|
|
|
99
106
|
/**
|
|
100
|
-
* Play a timeline; resolves with {
|
|
107
|
+
* Play a timeline; resolves with { ending, error? } when it ends: 'finished', 'skipped', 'dropped' (a load, a new game or dispose took its state) or 'failed' (a step threw; error says what)
|
|
101
108
|
* @param {TimelineStep | TimelineStep[]} steps
|
|
102
109
|
* @param {TimelinePlayOptions} [opts]
|
|
103
|
-
* @returns {Promise<{
|
|
110
|
+
* @returns {Promise<{ ending: 'finished' | 'skipped' | 'dropped' | 'failed', error?: string }>}
|
|
104
111
|
*/
|
|
105
112
|
async play(steps, opts = {}) {
|
|
106
113
|
readParams('timeline.play()', keysSchema(['skippable', 'letterbox', 'actors']), opts);
|
|
107
114
|
const { skippable = true, letterbox = false } = opts, e = this.engine;
|
|
108
115
|
const actors = opts.actors ?? (e.player ? [e.player] : []);
|
|
109
116
|
if (!Array.isArray(actors)) throw codedError('module-params', `timeline.play(steps, { actors }): actors is a list of characters (or ids) the cutscene drives, e.g. [engine.player, guard]; [] drives nobody. Got ${typeof actors}`);
|
|
110
|
-
const run = { id: ++this._runSeq, skippable, letterbox,
|
|
111
|
-
|
|
117
|
+
const run = { id: ++this._runSeq, skippable, letterbox, ending: null, error: null, cancels: new Set(), cam: null, actors: new Set(), ctx: null, line: false, faded: false, duringLoad: e.saves.replacing };
|
|
118
|
+
// a bad or remote actor throws: the ones already taken go back, or the player stays in the cutscene with no run left to end it
|
|
119
|
+
try { for (const a of actors) this._take(run, a); } catch (err) { this._give(run); throw err; }
|
|
112
120
|
// enter the UI focus stack: skippable cutscenes skip on Esc, unskippable ones swallow Esc (so it does not open the settings menu)
|
|
113
121
|
run.focus = uiFocus(e).push('timeline', { cancel: skippable ? () => this.skip(run) : null });
|
|
114
122
|
this.runs.add(run);
|
|
115
123
|
this._refreshUI();
|
|
116
124
|
e.events.emit('timeline:start', { id: run.id });
|
|
117
125
|
if (this.skipAll && skippable) this.skip(run);
|
|
126
|
+
const turn = stateTurn(e); // no load could continue a run from half way: an autosave waits for its end
|
|
118
127
|
try {
|
|
119
128
|
await this._step(steps, run);
|
|
129
|
+
run.ending ??= 'finished';
|
|
120
130
|
} catch (err) {
|
|
121
131
|
reportError(this.engine, err, 'timeline step', { soft: true }); // a step that threw ends this run; the game carries on
|
|
132
|
+
run.error = err?.message ?? String(err);
|
|
133
|
+
this._stop(run, 'failed'); // a parallel branch beside the throw is still waiting
|
|
122
134
|
} finally {
|
|
135
|
+
if (run.faded && gone(run) && ![...this.runs].some(r => r !== run && r.faded)) fadeScreen(e, 0, { seconds: 0 }); // the steps that would have faded back in will not run
|
|
136
|
+
turn.remove();
|
|
123
137
|
releaseCamera(this, run);
|
|
124
138
|
run.focus.remove();
|
|
125
139
|
this._give(run);
|
|
126
140
|
this.runs.delete(run);
|
|
127
141
|
this._refreshUI();
|
|
128
|
-
|
|
142
|
+
this._endings[run.ending]++;
|
|
143
|
+
if (run.error) this._failure = run.error;
|
|
144
|
+
e.events.emit('timeline:end', { id: run.id, ...answer(run) });
|
|
129
145
|
}
|
|
130
|
-
return
|
|
146
|
+
return answer(run);
|
|
131
147
|
}
|
|
132
148
|
|
|
133
149
|
/**
|
|
@@ -136,12 +152,20 @@ export class Timeline {
|
|
|
136
152
|
* @returns {void}
|
|
137
153
|
*/
|
|
138
154
|
skip(run) {
|
|
139
|
-
for (const r of run ? [run] : [...this.runs])
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
155
|
+
for (const r of run ? [run] : [...this.runs]) if (!r.ending) this._stop(r, 'skipped');
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** @internal The one way a run stops early. The ending is set once; only a skip can still turn into a harder one, because it goes on running the steps left */
|
|
159
|
+
_stop(r, ending) {
|
|
160
|
+
if (r.ending && r.ending !== 'skipped') return;
|
|
161
|
+
r.ending = ending;
|
|
162
|
+
this._tweener.finishAll(r);
|
|
163
|
+
for (const c of [...r.cancels]) c();
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** @internal The state a run belongs to is gone: it ends without its remaining steps, whose effects would land in what replaced it. keep: a run a load started stays */
|
|
167
|
+
_drop(keep = () => false) {
|
|
168
|
+
for (const r of [...this.runs]) if (!keep(r)) this._stop(r, 'dropped');
|
|
145
169
|
}
|
|
146
170
|
|
|
147
171
|
/**
|
|
@@ -151,12 +175,16 @@ export class Timeline {
|
|
|
151
175
|
* @internal
|
|
152
176
|
*/
|
|
153
177
|
frame(dt) {
|
|
154
|
-
if (
|
|
178
|
+
if (this.engine.frozen) return; // wait and tweens do not advance while frozen, and a key pressed there is not for the cutscene
|
|
179
|
+
this._tweener.update(dt);
|
|
155
180
|
const inp = this.engine.input;
|
|
156
|
-
// skip keys other than Esc (e.g. Backspace): Esc is already dispatched by the UI focus stack, so do not handle it twice
|
|
157
|
-
// count
|
|
181
|
+
// skip keys other than Esc (e.g. Backspace): Esc is already dispatched by the UI focus stack, so do not handle it twice
|
|
158
182
|
if (!this.runs.size || !inp.pressedRaw('skip') || inp.pressedRaw('cancel')) return;
|
|
159
|
-
|
|
183
|
+
// same reach as Esc: the top of the UI focus stack only (the newest run, or the run whose line is showing), so a key typed in a window above the
|
|
184
|
+
// cutscene stays in that window; the first frame of a run does not count
|
|
185
|
+
const top = uiFocus(this.engine).top, runs = [...this.runs];
|
|
186
|
+
const r = top === 'timeline' ? runs.at(-1) : top === 'dialogue' ? runs.findLast(x => x.line) : null;
|
|
187
|
+
if (r?.skippable && !r.focus.fresh) this.skip(r);
|
|
160
188
|
}
|
|
161
189
|
|
|
162
190
|
// ---------- Control of the characters in the cutscene ----------
|
|
@@ -183,7 +211,7 @@ export class Timeline {
|
|
|
183
211
|
// ---------- Steps ----------
|
|
184
212
|
/** @internal */
|
|
185
213
|
async _step(s, run) {
|
|
186
|
-
if (s == null) return;
|
|
214
|
+
if (s == null || gone(run)) return;
|
|
187
215
|
if (Array.isArray(s)) { for (const x of s) await this._step(x, run); return; }
|
|
188
216
|
if (typeof s === 'function') { await s(this.engine, run); return; }
|
|
189
217
|
checkStep(s);
|
|
@@ -199,65 +227,66 @@ export class Timeline {
|
|
|
199
227
|
if ('fade' in s) { await this._fade(s.fade, s.to ?? 1, run); return; }
|
|
200
228
|
}
|
|
201
229
|
|
|
202
|
-
/** Full-screen fade: jumps to the target when skipped @internal */
|
|
230
|
+
/** Full-screen fade: jumps to the target when skipped. faded: the run holds the screen, so an ending that drops the later steps gives it back @internal */
|
|
203
231
|
async _fade(seconds, to, run) {
|
|
204
232
|
const now = () => fadeScreen(this.engine, to, { seconds: 0 });
|
|
205
|
-
|
|
233
|
+
run.faded = to > 0;
|
|
234
|
+
if (run.ending) return now();
|
|
206
235
|
run.cancels.add(now);
|
|
207
236
|
await fadeScreen(this.engine, to, { seconds });
|
|
208
237
|
run.cancels.delete(now);
|
|
209
238
|
}
|
|
210
239
|
|
|
211
|
-
/** @internal */
|
|
212
240
|
/**
|
|
213
241
|
* { wait: s }: a timer on the 'real' view of engine.time, so it ends inside a fixed step (game logic only in fixed steps) and counts real
|
|
214
242
|
* seconds whatever the frame rate; before it rode the frame tweener, so the step after a wait ran between frames. Skip / cancel resolve it now
|
|
215
243
|
* @internal
|
|
216
244
|
*/
|
|
217
245
|
_wait(run, seconds) {
|
|
218
|
-
if (run.
|
|
246
|
+
if (run.ending || !(seconds > 0)) return Promise.resolve();
|
|
219
247
|
return new Promise(res => {
|
|
220
248
|
const done = () => { h.remove(); run.cancels.delete(done); res(); };
|
|
221
|
-
const h = this.engine.clock.after(seconds, done,
|
|
249
|
+
const h = this.engine.clock.after(seconds, done, { channel: 'real' });
|
|
222
250
|
run.cancels.add(done);
|
|
223
251
|
});
|
|
224
252
|
}
|
|
225
253
|
/** @internal */
|
|
226
|
-
_timed(run, o) { return this._tweener.run({ ...o, duration: run.
|
|
254
|
+
_timed(run, o) { return this._tweener.run({ ...o, duration: run.ending ? 0 : o.duration, group: run }); }
|
|
227
255
|
/** @internal */
|
|
228
|
-
_tween(run, target, to, d, ease) { return this._tweener.tween(target, to, run.
|
|
256
|
+
_tween(run, target, to, d, ease) { return this._tweener.tween(target, to, run.ending ? 0 : d, ease, run); }
|
|
229
257
|
|
|
230
258
|
/** @internal */
|
|
231
259
|
_waitFor(name, timeout, run) {
|
|
232
|
-
if (run.
|
|
260
|
+
if (run.ending) return Promise.resolve();
|
|
233
261
|
return new Promise(res => {
|
|
234
262
|
let timer = null, over = false;
|
|
235
263
|
const done = () => { if (over) return; over = true; sub.remove(); timer?.remove(); run.cancels.delete(done); res(); };
|
|
236
264
|
const sub = this.engine.events.once(name, done);
|
|
237
265
|
run.cancels.add(done);
|
|
238
|
-
if (timeout) timer = this.engine.clock.after(timeout, done,
|
|
266
|
+
if (timeout) timer = this.engine.clock.after(timeout, done, { channel: 'real' }); // real seconds, ends in a fixed step like { wait }
|
|
239
267
|
});
|
|
240
268
|
}
|
|
241
269
|
|
|
242
270
|
/** Line: { speaker, text, node?, channel?: 'main' | 'bubble', at?, seconds? }. Needs the dialogue module; skipped with a warning if not installed @internal */
|
|
243
271
|
_say(s, run) {
|
|
244
272
|
const e = this.engine, d = e.dialogue;
|
|
245
|
-
if (!d) { warnOnce(coded('module-needs', '[timeline] say
|
|
246
|
-
if (run.
|
|
273
|
+
if (!d) { warnOnce(coded('module-needs', '[timeline] the say step was skipped: it needs dialogue(); add it to engine.use(...)')); return Promise.resolve(); }
|
|
274
|
+
if (run.ending) return Promise.resolve();
|
|
247
275
|
// the line is on top of the focus stack: Esc still skips the whole cutscene
|
|
248
276
|
const said = d.say(s.nodes || s.text, { speaker: s.speaker, node: s.node || 'start', channel: s.channel, at: s.at, seconds: s.seconds, onCancel: run.skippable ? () => this.skip(run) : null });
|
|
277
|
+
run.line = s.channel !== 'bubble'; // a main line sits above the run in the focus stack; a bubble takes no focus
|
|
249
278
|
return new Promise(done => {
|
|
250
279
|
// skipping the cutscene closes this line; it also settles the step when the line was dropped without ending (a new playthrough)
|
|
251
|
-
const cancel = () => { said.remove(); done(); }; // remove(): the say() handle of the dialogue contract, either channel
|
|
280
|
+
const cancel = () => { said.remove(); run.line = false; done(); }; // remove(): the say() handle of the dialogue contract, either channel
|
|
252
281
|
run.cancels.add(cancel);
|
|
253
|
-
said.then(() => { run.cancels.delete(cancel); done(); });
|
|
282
|
+
said.then(() => { run.cancels.delete(cancel); run.line = false; done(); });
|
|
254
283
|
});
|
|
255
284
|
}
|
|
256
285
|
|
|
257
286
|
// ---------- Letterbox ----------
|
|
258
287
|
/** @internal */
|
|
259
288
|
_refreshUI() {
|
|
260
|
-
const runs = [...this.runs], on = runs.some(r => r.letterbox), canSkip = runs.some(r => r.letterbox && r.skippable && !r.
|
|
289
|
+
const runs = [...this.runs], on = runs.some(r => r.letterbox), canSkip = runs.some(r => r.letterbox && r.skippable && !r.ending);
|
|
261
290
|
this.top.classList.toggle('is-on', on); this.bottom.classList.toggle('is-on', on);
|
|
262
291
|
this.skipBtn.textContent = this.engine.t('timeline.skip');
|
|
263
292
|
this.skipBtn.classList.toggle('is-on', canSkip);
|
|
@@ -265,6 +294,11 @@ export class Timeline {
|
|
|
265
294
|
}
|
|
266
295
|
}
|
|
267
296
|
|
|
297
|
+
/** The run's state is gone, or it broke: the steps left must not run. A skip does run them, so what it leaves matches a playthrough */
|
|
298
|
+
const gone = run => run.ending === 'dropped' || run.ending === 'failed';
|
|
299
|
+
/** What a run says when it ends, to play() and timeline:end alike */
|
|
300
|
+
const answer = run => ({ ending: run.ending, ...(run.error && { error: run.error }) });
|
|
301
|
+
|
|
268
302
|
const STRINGS = {
|
|
269
303
|
'zh-CN': { 'module.timeline': '时间轴', 'timeline.skip': '{key:cancel} 跳过', 'timeline.skipAction': '跳过过场' },
|
|
270
304
|
en: { 'module.timeline': 'timeline', 'timeline.skip': '{key:cancel} Skip', 'timeline.skipAction': 'Skip cutscene' },
|
|
@@ -283,15 +317,19 @@ export function timeline(opts = {}) {
|
|
|
283
317
|
readParams('timeline', TIMELINE_PARAMS, opts);
|
|
284
318
|
let t = null;
|
|
285
319
|
return {
|
|
286
|
-
name: 'timeline', type: 'rules', params: TIMELINE_PARAMS, options: opts, label: 'Timeline', stage: 'control', before: ['cameraRig'], // before the camera, so the takeover applies on the same frame
|
|
320
|
+
name: 'timeline', skipKind: 'none', type: 'rules', params: TIMELINE_PARAMS, options: opts, label: 'Timeline', stage: 'control', before: ['cameraRig'], optional: ['dialogue'], // before the camera, so the takeover applies on the same frame
|
|
287
321
|
install(e, ctx) {
|
|
288
322
|
e.i18n.add(STRINGS); t = new Timeline(e, ctx);
|
|
289
323
|
// a running cutscene ends with its playthrough (session waits one macrotask for its steps to settle)
|
|
290
|
-
ctx.track(e.events.on('session:end', () =>
|
|
324
|
+
ctx.track(e.events.on('session:end', () => t._drop()));
|
|
291
325
|
return t;
|
|
292
326
|
},
|
|
293
327
|
frame(dt) { t.frame(dt); },
|
|
328
|
+
afterLoad() { t._drop(r => r.duringLoad); },
|
|
329
|
+
// unloaded mid-cutscene: every run ends through its finally (camera, focus, actors go back); nothing else would, the frame hook is gone
|
|
330
|
+
dispose() { t._drop(); },
|
|
294
331
|
// scenario param cutscene: 'skip' | 'keep'
|
|
332
|
+
stateKeys: ['cutscene'],
|
|
295
333
|
applyState(e, p) {
|
|
296
334
|
if (p.cutscene === undefined) return;
|
|
297
335
|
t.skipAll = p.cutscene === 'skip';
|
|
@@ -299,7 +337,9 @@ export function timeline(opts = {}) {
|
|
|
299
337
|
},
|
|
300
338
|
describe(e, ctx) {
|
|
301
339
|
const runs = [...t.runs];
|
|
302
|
-
if (runs.length) ctx.out.cutscene = { count: runs.length, skippable: runs.some(r => r.skippable && !r.
|
|
340
|
+
if (runs.length || t._failure) ctx.out.cutscene = { count: runs.length, skippable: runs.some(r => r.skippable && !r.ending), letterbox: runs.some(r => r.letterbox), actors: [...t._held.keys()], endings: { ...t._endings }, ...(t._failure && { failure: t._failure }) };
|
|
303
341
|
},
|
|
304
342
|
};
|
|
305
343
|
}
|
|
344
|
+
|
|
345
|
+
export const handRolled = [{ kind: 'tween', seen: 'a tween of its own', use: 'await engine.timeline.tween(target, to, { duration, ease }): on game time, stops with pause (recipe 07)', quiet: /\b(engine|e|eng|ctx)\.timeline\b/, code: /\b(?:elapsed|time|timer|age|t)\s*\/\s*(?:\w+\.)?(?:dur|duration)\b/i, orRaw: /\bfrom\s+['"](?:gsap|@tweenjs\/tween\.js|tween\.js|animejs)['"]/ }];
|
|
@@ -6,12 +6,14 @@
|
|
|
6
6
|
// const tw = new Tweener(); call tw.update(dt) every frame
|
|
7
7
|
// await tw.tween(mesh, { 'position.y': 3, 'material.color': 0xffffff }, 1.5, 'outBack');
|
|
8
8
|
// const p = tw.tween(...); p.finish() jumps to the end; p.remove() stops where it is (the cancel convention)
|
|
9
|
+
// A task that throws (its start, a step, its end) ends there: what it holds goes back, it leaves the list, its promise rejects. The one who awaits it decides what that means (a
|
|
10
|
+
// Timeline run ends 'failed'); a tween nobody awaits is the page's unhandled rejection, which the engine reports (core/base/errors.js watchRejections). The other tasks go on.
|
|
9
11
|
import * as THREE from 'three';
|
|
10
|
-
import { ease as easing } from '../../core/easing.js';
|
|
11
|
-
import { allowOwned } from '../../core/owned.js';
|
|
12
|
-
import { getPath } from '../../core/util.js';
|
|
13
|
-
import { warnOnce } from '../../core/validate.js';
|
|
14
|
-
import { coded } from '../../core/errorHints.js';
|
|
12
|
+
import { ease as easing } from '../../core/base/easing.js';
|
|
13
|
+
import { allowOwned } from '../../core/ops/owned.js';
|
|
14
|
+
import { getPath } from '../../core/base/util.js';
|
|
15
|
+
import { warnOnce } from '../../core/base/validate.js';
|
|
16
|
+
import { coded } from '../../core/base/errorHints.js';
|
|
15
17
|
|
|
16
18
|
const COMPS = ['x', 'y', 'z', 'w'];
|
|
17
19
|
|
|
@@ -60,13 +62,13 @@ export class Tweener {
|
|
|
60
62
|
constructor() { this.list = []; }
|
|
61
63
|
|
|
62
64
|
/**
|
|
63
|
-
* General task: calls step(k) every frame, k is the eased progress. duration in seconds; returns a Promise with finish() / remove().
|
|
65
|
+
* General task: calls step(k) every frame, k is the eased progress. duration in seconds; returns a Promise with finish() / remove(), rejected if start, step or end throws.
|
|
64
66
|
* The start value is read on the first update (so a later queued tween starts from where the previous one ended).
|
|
65
67
|
*/
|
|
66
68
|
run({ duration = 0, ease = 'linear', start, step, end, group = null }) {
|
|
67
|
-
let res;
|
|
68
|
-
const p = new Promise(
|
|
69
|
-
const task = { t: 0, dur: Math.max(0, duration), ease: easing(ease), start, step, end, group, res, started: false, done: false };
|
|
69
|
+
let res, rej;
|
|
70
|
+
const p = new Promise((yes, no) => { res = yes; rej = no; });
|
|
71
|
+
const task = { t: 0, dur: Math.max(0, duration), ease: easing(ease), start, step, end, group, res, rej, started: false, done: false };
|
|
70
72
|
task.finish = () => this._complete(task, 1);
|
|
71
73
|
task.cancel = () => this._complete(task, null);
|
|
72
74
|
p.finish = task.finish; p.remove = task.cancel; p.task = task;
|
|
@@ -77,7 +79,7 @@ export class Tweener {
|
|
|
77
79
|
|
|
78
80
|
/** Property tween: to = { 'position.x': 3, 'material.color': 0xffffff }. A value may also be a function () => value (evaluated at start) */
|
|
79
81
|
// a tween is a legitimate temporary takeover of what it animates (a light, the fog): those objects only skip the engine's outside-write
|
|
80
|
-
// detection (core/owned.js) while it runs, so the engine neither warns nor yields them for good; everything else stays checked
|
|
82
|
+
// detection (core/ops/owned.js) while it runs, so the engine neither warns nor yields them for good; everything else stays checked
|
|
81
83
|
tween(target, to, duration = 1, ease = 'inOutCubic', group = null) {
|
|
82
84
|
let props = [];
|
|
83
85
|
const owner = 'tween:' + (++tweenId);
|
|
@@ -98,25 +100,29 @@ export class Tweener {
|
|
|
98
100
|
if (!this.list.length) return;
|
|
99
101
|
for (const task of [...this.list]) {
|
|
100
102
|
if (task.done) continue;
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
103
|
+
try {
|
|
104
|
+
if (!task.started) { task.started = true; task.start?.(); }
|
|
105
|
+
task.t += dt;
|
|
106
|
+
if (task.t >= task.dur) this._complete(task, 1);
|
|
107
|
+
else task.step?.(task.ease(task.t / task.dur));
|
|
108
|
+
} catch (error) { this._complete(task, null, { error }); }
|
|
105
109
|
}
|
|
106
110
|
}
|
|
107
111
|
|
|
108
112
|
/** Jump a group of tasks (or all) to their end */
|
|
109
113
|
finishAll(group) { for (const t of [...this.list]) if (group === undefined || t.group === group) t.finish(); }
|
|
110
114
|
|
|
111
|
-
|
|
115
|
+
/** The one way a task ends: k 1 jumps to the end, null stops where it is. failed { error }: a throw on the way, and the first one is the promise's answer. So finish() never throws and finishAll reaches every task */
|
|
116
|
+
_complete(task, k, failed = null) {
|
|
112
117
|
if (task.done) return;
|
|
113
118
|
task.done = true;
|
|
114
|
-
|
|
119
|
+
const guard = fn => { try { fn(); } catch (error) { failed ??= { error }; } };
|
|
120
|
+
if (k !== null) guard(() => {
|
|
115
121
|
if (!task.started) { task.started = true; task.start?.(); }
|
|
116
122
|
task.step?.(task.ease(1));
|
|
117
|
-
}
|
|
118
|
-
task.end?.(k !== null);
|
|
123
|
+
});
|
|
124
|
+
guard(() => task.end?.(k !== null && !failed)); // whatever happened above: end gives back what the task holds
|
|
119
125
|
const i = this.list.indexOf(task); if (i >= 0) this.list.splice(i, 1);
|
|
120
|
-
task.res(k !== null);
|
|
126
|
+
if (failed) task.rej(failed.error); else task.res(k !== null);
|
|
121
127
|
}
|
|
122
128
|
}
|
|
@@ -1,19 +1,28 @@
|
|
|
1
|
-
// Timeline camera and path steps (helper of Timeline.js): a shot takes the camera over with engine.takeCamera (core/holds.js) and gives it back when the run ends;
|
|
1
|
+
// Timeline camera and path steps (helper of Timeline.js): a shot takes the camera over with engine.takeCamera (core/ops/holds.js) and gives it back when the run ends;
|
|
2
2
|
// a path moves any object (a character, the camera) along a spline. Each function takes the Timeline as `t`.
|
|
3
|
+
// One writer: a step writes what it drives only while it is the holder in charge (written). Out of charge its clock runs on and it writes nothing; back in charge it writes where its
|
|
4
|
+
// clock is. So a shot under a newer holder of the camera, or a path on a character something above the cutscene has, ends on time and leaves the real owner's values alone.
|
|
3
5
|
import * as THREE from 'three';
|
|
4
|
-
import { vec3 as v3 } from '../../core/math.js';
|
|
5
|
-
import { surfaceOr } from '../../core/ground.js';
|
|
6
|
+
import { vec3 as v3 } from '../../core/base/math.js';
|
|
7
|
+
import { surfaceOr } from '../../core/scene/ground.js';
|
|
8
|
+
import { holdFov } from '../../core/scene/view.js';
|
|
9
|
+
|
|
10
|
+
/** The one check: a timed step whose step(k) runs only while mine() says it is in charge */
|
|
11
|
+
const written = (t, run, mine, o) => t._timed(run, { ...o, step: k => { if (mine()) o.step(k); } });
|
|
12
|
+
/** Holds the camera now: compared by owner, because engine.cameraOverride is a copy of what takeCamera got */
|
|
13
|
+
const onCamera = (t, st) => t.engine.cameraOverride?.owner === st.override.owner;
|
|
6
14
|
|
|
7
15
|
/** Camera: { from?, to: { position, lookAt }, duration, ease, fov } or { release: true } */
|
|
8
16
|
export function cameraStep(t, c, run) {
|
|
9
|
-
const e = t.engine
|
|
17
|
+
const e = t.engine;
|
|
10
18
|
if (c.release) { releaseCamera(t, run); return Promise.resolve(); }
|
|
11
19
|
const st = takeCamera(t, run);
|
|
12
20
|
let fromP, fromL, fromFov, toP, toL;
|
|
13
21
|
const lookOf = l => l?.isObject3D ? l.position : l; // may look at a moving object
|
|
14
|
-
return t
|
|
22
|
+
return written(t, run, () => onCamera(t, st), {
|
|
15
23
|
duration: c.duration ?? 1, ease: c.ease ?? 'inOutCubic',
|
|
16
24
|
start: () => {
|
|
25
|
+
const cam = e.camera;
|
|
17
26
|
fromP = c.from?.position ? v3(c.from.position) : cam.position.clone();
|
|
18
27
|
toP = c.to?.position ? v3(c.to.position) : fromP.clone();
|
|
19
28
|
// start look-at: use it if given, otherwise keep the current view direction at the same distance as the target
|
|
@@ -23,33 +32,30 @@ export function cameraStep(t, c, run) {
|
|
|
23
32
|
fromFov = c.from?.fov ?? cam.fov;
|
|
24
33
|
},
|
|
25
34
|
step: k => {
|
|
35
|
+
const cam = e.camera; // read here: a game may assign engine.camera during the shot
|
|
26
36
|
if (c.to?.lookAt?.isObject3D) toL.copy(c.to.lookAt.position);
|
|
27
37
|
cam.position.lerpVectors(fromP, toP, k);
|
|
28
38
|
st.look.lerpVectors(fromL, toL, k);
|
|
29
39
|
cam.lookAt(st.look);
|
|
30
|
-
if (c.fov != null) { cam.fov
|
|
40
|
+
if (c.fov != null && cam.fov !== undefined) { fromFov ??= cam.fov; holdFov(e, fromFov + (c.fov - fromFov) * k); } // a real orthographic camera has none
|
|
31
41
|
st.override.focus.copy(st.look);
|
|
32
42
|
},
|
|
33
43
|
});
|
|
34
44
|
}
|
|
35
|
-
/** */
|
|
36
45
|
function takeCamera(t, run) {
|
|
37
46
|
const e = t.engine;
|
|
38
47
|
if (!run.cam) {
|
|
39
48
|
// a claim of its own (engine.takeCamera): a named view or a game holding the camera keeps its claim and gets the camera back afterwards.
|
|
40
49
|
// The owner carries the run id so two overlapping runs are two holders, not one overwriting the other.
|
|
41
50
|
const override = { owner: 'timeline:' + run.id, id: run.id, focus: e.focus.clone() };
|
|
42
|
-
run.cam = {
|
|
51
|
+
run.cam = { look: new THREE.Vector3(), override, hold: e.takeCamera(override.owner, override) };
|
|
43
52
|
}
|
|
44
53
|
return run.cam;
|
|
45
54
|
}
|
|
46
|
-
/** */
|
|
47
55
|
export function releaseCamera(t, run) {
|
|
48
56
|
const st = run.cam; if (!st) return;
|
|
49
57
|
run.cam = null;
|
|
50
|
-
|
|
51
|
-
st.hold.remove();
|
|
52
|
-
if (e.camera.fov !== st.fov) { e.camera.fov = st.fov; e.camera.updateProjectionMatrix(); }
|
|
58
|
+
st.hold.remove(); // the view comes back with the last holder (core/scene/view.js viewHold)
|
|
53
59
|
}
|
|
54
60
|
|
|
55
61
|
/** Path: { object, points, duration, ease, lookAhead, ground, closed, curve: 'catmullrom'|'centripetal'|'chordal', tension } */
|
|
@@ -57,16 +63,17 @@ export function pathStep(t, p, run) {
|
|
|
57
63
|
// a character (Character) can be passed directly
|
|
58
64
|
const e = t.engine, chr = p.object?.root?.isObject3D ? p.object : null, obj = chr ? chr.root : p.object;
|
|
59
65
|
if (!obj || !p.points?.length) return Promise.resolve();
|
|
60
|
-
|
|
66
|
+
const pts = p.points.map(x => v3(x)); // before the character is marked: a bad point throws, and nothing would unmark it
|
|
67
|
+
// a character on a path is the cutscene's to drive until the run ends (core/ops/control.js): its keys / walk / behavior pause meanwhile
|
|
61
68
|
if (chr) { t._take(run, chr); t._pathing.set(chr.id, (t._pathing.get(chr.id) ?? 0) + 1); }
|
|
62
69
|
const unpath = () => { if (!chr) return; const n = (t._pathing.get(chr.id) ?? 1) - 1; if (n > 0) t._pathing.set(chr.id, n); else t._pathing.delete(chr.id); };
|
|
63
|
-
const pts = p.points.map(x => v3(x));
|
|
64
70
|
if (pts.length === 1) pts.unshift(obj.position.clone());
|
|
65
71
|
const curve = new THREE.CatmullRomCurve3(pts, !!p.closed, p.curve ?? 'centripetal', p.tension ?? 0.5);
|
|
66
72
|
const isCam = obj === e.camera;
|
|
67
73
|
const st = isCam ? takeCamera(t, run) : null;
|
|
68
74
|
const pos = new THREE.Vector3(), ahead = new THREE.Vector3();
|
|
69
|
-
|
|
75
|
+
const mine = isCam ? () => onCamera(t, st) : chr ? () => !!t._held.get(chr.id)?.h.placing : () => true;
|
|
76
|
+
return written(t, run, mine, {
|
|
70
77
|
duration: p.duration ?? 2, ease: p.ease ?? 'inOutSine',
|
|
71
78
|
step: k => {
|
|
72
79
|
curve.getPointAt(Math.min(1, Math.max(0, k)), pos);
|
|
@@ -86,9 +93,9 @@ export function pathStep(t, p, run) {
|
|
|
86
93
|
},
|
|
87
94
|
}).then(r => {
|
|
88
95
|
// the path moved the model, not the mover: the character's world record (the player's) catches up once, so a save right after the cutscene has the new
|
|
89
|
-
// place
|
|
96
|
+
// place. Not while another owner has it: the path wrote nothing on its last step, and the record is that owner's
|
|
90
97
|
unpath();
|
|
91
|
-
if (chr?.recordId && chr.syncRecord) e.ops.allow(() => chr.syncRecord());
|
|
98
|
+
if (chr?.recordId && chr.syncRecord && mine()) e.ops.allow(() => chr.syncRecord());
|
|
92
99
|
return r;
|
|
93
100
|
}, err => { unpath(); throw err; });
|
|
94
101
|
}
|