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
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
// engine.setCamera('follow'); // switch back to third person at runtime (mouse lock releases, body shows again); see recipes/21-camera.md
|
|
12
12
|
import * as THREE from 'three';
|
|
13
13
|
import { rigModule, defineRig, YAW_RIG, HIDE_RIG, clickToLock, releaseLock } from './common.js';
|
|
14
|
-
import { vec3 } from '../../core/math.js';
|
|
15
|
-
import { setFov } from '../../core/view.js';
|
|
14
|
+
import { vec3 } from '../../core/base/math.js';
|
|
15
|
+
import { setFov } from '../../core/scene/view.js';
|
|
16
16
|
|
|
17
17
|
export class FirstPersonCamera {
|
|
18
18
|
/**
|
|
@@ -100,13 +100,13 @@ export class FirstPersonCamera {
|
|
|
100
100
|
cam.rotation.set(this.pitch, this.yaw, Math.sin(this._bob * 0.5) * this._bobAmp * 0.15, 'YXZ');
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
/**
|
|
103
|
+
/** Someone else's view shows while the camera is held: the mouse goes free and the body is back, since the eye it would block is no longer where the camera is */
|
|
104
104
|
onOverride(on) {
|
|
105
|
-
if (on) releaseLock(this, true);
|
|
105
|
+
if (on) { releaseLock(this, true); this._unhide(); } else this._hide();
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
// also on every child added to the target (a held item, a swapped model): hide what is new
|
|
109
|
-
_hide() { if (this.hideTarget && this.target) this._hideTarget(); }
|
|
109
|
+
_hide() { if (this.hideTarget && this.target && !this.engine.cameraOverride) this._hideTarget(); }
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
Object.assign(FirstPersonCamera.prototype, YAW_RIG, HIDE_RIG); // forward / right / focusPoint; _hideTarget / _unhide / _shadowLayers
|
|
@@ -16,14 +16,14 @@
|
|
|
16
16
|
// engine.cameraRig.blend('garden', { seconds: 1.5 });
|
|
17
17
|
import * as THREE from 'three';
|
|
18
18
|
import { rigModule, defineRig, viewForward, rightOf, rigPlaced } from './common.js';
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import { vec3 } from '../../core/math.js';
|
|
22
|
-
import { ease as easing } from '../../core/easing.js';
|
|
23
|
-
import { warnMissing } from '../../core/validate.js';
|
|
24
|
-
import { readParams, keysSchema } from '../../core/params.js';
|
|
19
|
+
import { rigPixelSnap, checkPixelView } from './pixelSnap.js';
|
|
20
|
+
import { baseFov, shotFov, setProjection } from '../../core/scene/view.js';
|
|
21
|
+
import { vec3 } from '../../core/base/math.js';
|
|
22
|
+
import { ease as easing } from '../../core/base/easing.js';
|
|
23
|
+
import { warnMissing } from '../../core/base/validate.js';
|
|
24
|
+
import { readParams, keysSchema } from '../../core/base/params.js';
|
|
25
25
|
const BLEND_KEYS = ['seconds', 'ease'];
|
|
26
|
-
import { codedError } from '../../core/errorHints.js';
|
|
26
|
+
import { codedError } from '../../core/base/errorHints.js';
|
|
27
27
|
|
|
28
28
|
const SHOT_KEYS = ['position', 'lookAt', 'track', 'fov', 'at', 'trackHeight', 'projection', 'size'];
|
|
29
29
|
|
|
@@ -33,22 +33,25 @@ export class FixedCamera {
|
|
|
33
33
|
* single-shot shorthand: fixedCamera({ position, lookAt, projection, size }); start initial shot;
|
|
34
34
|
* auto false | 'nearest' (every autoInterval seconds pick the nearest shot); hysteresis how many meters closer a new shot must be to win (avoids flip-flopping);
|
|
35
35
|
* triggerBlend transition seconds for trigger-zone switches (0 = hard cut); trackHeight how high on the character a track shot looks; trackSmoothing head-tracking smoothness;
|
|
36
|
-
* holdDirection keep the direction at a shot change until the key is released (classic fixed-camera controls)
|
|
36
|
+
* holdDirection keep the direction at a shot change until the key is released (classic fixed-camera controls);
|
|
37
|
+
* pixelSnap { pixelsPerMeter, bounds } art-pixel rounding: every shot is orthographic with no size, pixelSnap decides the view height (pixelSnap.js)
|
|
37
38
|
*/
|
|
38
39
|
constructor(engine, { shots = {}, start = null, auto = false, autoInterval = 0.25, hysteresis = 2, triggerBlend = 0,
|
|
39
|
-
trackHeight = 1.2, trackSmoothing = 8, holdDirection = true, ease = 'inOutCubic', ...rest } = {}) {
|
|
40
|
+
trackHeight = 1.2, trackSmoothing = 8, holdDirection = true, ease = 'inOutCubic', pixelSnap = null, ...rest } = {}) {
|
|
40
41
|
readParams('fixedCamera()', keysSchema(SHOT_KEYS), rest); // top-level shot fields: the one-shot form setCamera('fixed', { position, lookAt, projection, size })
|
|
41
42
|
if (!Object.keys(shots).length && rest.position) shots = { main: rest };
|
|
42
43
|
else if (Object.keys(rest).length) throw codedError('camera-option', `fixedCamera(): top-level ${Object.keys(rest).join(', ')} are the one-shot form `
|
|
43
44
|
+ `(no shots, with position); with shots put them in shots.<name>`);
|
|
44
45
|
Object.assign(this, { engine, auto, autoInterval, hysteresis, triggerBlend, trackHeight, trackSmoothing, holdDirection, ease });
|
|
46
|
+
/** Art-pixel rounding (.grid, .error, .agrees) or null */
|
|
47
|
+
this.pixelSnap = rigPixelSnap(engine, pixelSnap, 'fixedCamera');
|
|
48
|
+
this._shown = undefined; // the size last asked of engine.camera (null: a perspective shot)
|
|
45
49
|
this.shots = {};
|
|
46
50
|
for (const [n, s] of Object.entries(shots)) this.add(n, s);
|
|
47
51
|
this.target = null;
|
|
48
52
|
this.current = null;
|
|
49
53
|
this._blend = null; this._autoT = 0; this._held = null;
|
|
50
54
|
this._look = new THREE.Vector3();
|
|
51
|
-
this._baseFov = engine.camera.fov;
|
|
52
55
|
this._dir = { f: { x: 0, z: -1 }, r: { x: 1, z: 0 } };
|
|
53
56
|
this._onZone = null; // trigger:enter listener, only while this rig is the active camera (onEnter / onExit)
|
|
54
57
|
const first = start || Object.keys(this.shots)[0];
|
|
@@ -57,25 +60,34 @@ export class FixedCamera {
|
|
|
57
60
|
|
|
58
61
|
/** @internal the camera module switched to this rig: camera:<shot> trigger zones cut to their shot from now on */
|
|
59
62
|
onEnter() {
|
|
63
|
+
this._shown = undefined; // the switch of rigs put the camera back to perspective: the next _place asks for this shot's view again
|
|
64
|
+
this.pixelSnap?.enter();
|
|
60
65
|
this._onZone ??= this.engine.events.on('trigger:enter', p => {
|
|
61
66
|
const tag = p.tag;
|
|
62
67
|
const m = typeof tag === 'string' && tag.match(/^camera:(.+)$/);
|
|
63
|
-
if (m && this.shots[m[1]]) this.
|
|
68
|
+
if (m && this.shots[m[1]]) this._moveOn(m[1]);
|
|
64
69
|
});
|
|
65
70
|
}
|
|
66
71
|
/** @internal switched away (or replaced on a new playthrough): a rig that is not the camera never moves it (review 0.4 modules-a B1) */
|
|
67
|
-
onExit() { this._onZone?.remove(); this._onZone = null; }
|
|
72
|
+
onExit() { this._onZone?.remove(); this._onZone = null; this._blend?.res(); this._blend = null; shotFov(this.engine, null); } // await blend() never hangs: no update runs here any more; a shot's fov is this rig's, the base view stays
|
|
68
73
|
|
|
69
74
|
/** Add or replace a shot */
|
|
70
75
|
add(name, s) {
|
|
71
76
|
readParams(`fixedCamera shots.${name}`, keysSchema(SHOT_KEYS), s);
|
|
72
|
-
if (
|
|
73
|
-
|
|
77
|
+
if (this.pixelSnap) checkPixelView(`fixedCamera shots.${name}`, s);
|
|
78
|
+
else if (s.projection === 'orthographic' && !(s.size > 0)) throw codedError('camera-option', `fixedCamera shots.${name}: projection 'orthographic' needs size > 0 (world units of view height)`);
|
|
79
|
+
const shot = {
|
|
74
80
|
position: vec3(s.position), lookAt: s.lookAt ? vec3(s.lookAt) : null, track: !!s.track || !s.lookAt,
|
|
75
81
|
fov: s.fov ?? null, size: s.projection === 'orthographic' ? s.size : null, at: s.at ? vec3(s.at) : null, trackHeight: s.trackHeight,
|
|
76
82
|
};
|
|
83
|
+
this.shots[name] = shot;
|
|
77
84
|
return this;
|
|
78
85
|
}
|
|
86
|
+
/** A switch that comes by itself (a trigger zone, the nearest shot) */
|
|
87
|
+
_moveOn(name) {
|
|
88
|
+
if (this.triggerBlend > 0) this.blend(name, { seconds: this.triggerBlend });
|
|
89
|
+
else this.cut(name);
|
|
90
|
+
}
|
|
79
91
|
follow(obj) { this.target = obj; }
|
|
80
92
|
/** Cut to a shot at once */
|
|
81
93
|
cut(name) {
|
|
@@ -84,7 +96,7 @@ export class FixedCamera {
|
|
|
84
96
|
this.current = name;
|
|
85
97
|
this._blend?.res(); this._blend = null; // interrupt a running blend: its Promise still resolves (await blend() never hangs)
|
|
86
98
|
this._lookTarget(s, this._look);
|
|
87
|
-
this._place(s.position, this._look, s.fov ??
|
|
99
|
+
this._place(s.position, this._look, s.fov ?? null, s.size);
|
|
88
100
|
if (changed) { this._latchDirection(); this.engine.events.emit('camera:shot', { name }); }
|
|
89
101
|
}
|
|
90
102
|
/** Blend smoothly to a shot ({ seconds = 1, ease }); returns a Promise that resolves when the blend ends. blend(name, 1.5) throws in dev
|
|
@@ -92,11 +104,11 @@ export class FixedCamera {
|
|
|
92
104
|
blend(name, opts) {
|
|
93
105
|
const { seconds = 1, ease = this.ease } = readParams('cameraRig.blend()', keysSchema(BLEND_KEYS), opts);
|
|
94
106
|
const s = this.shots[name]; if (!s) { warnMissing('shot', name, Object.keys(this.shots)); return Promise.resolve(); }
|
|
95
|
-
if (seconds <= 0 || !this.current) { this.cut(name); return Promise.resolve(); }
|
|
107
|
+
if (seconds <= 0 || !this.current || this.engine.cameraOverride) { this.cut(name); return Promise.resolve(); } // held: nothing to blend from, the shot lands at release
|
|
96
108
|
const cam = this.engine.camera;
|
|
97
109
|
return new Promise(res => {
|
|
98
110
|
this._blend?.res();
|
|
99
|
-
this._blend = { from: cam.position.clone(), fromLook: this._look.clone(), fromFov: cam.fov, fromSize: cam.
|
|
111
|
+
this._blend = { from: cam.position.clone(), fromLook: this._look.clone(), fromFov: cam.fov, fromSize: cam.isOrthographicCamera ? cam.top - cam.bottom : null, t: 0, dur: seconds, ease, res };
|
|
100
112
|
this.current = name;
|
|
101
113
|
this._latchDirection();
|
|
102
114
|
this.engine.events.emit('camera:shot', { name });
|
|
@@ -109,31 +121,30 @@ export class FixedCamera {
|
|
|
109
121
|
focusPoint() { return this.target ? this.target.position : this._look; }
|
|
110
122
|
|
|
111
123
|
update(dt, input) {
|
|
112
|
-
|
|
113
|
-
if (!s) return;
|
|
124
|
+
if (!this.shots[this.current]) return;
|
|
114
125
|
if (this.auto === 'nearest' && this.target && (this._autoT -= dt) <= 0) {
|
|
115
126
|
this._autoT = this.autoInterval;
|
|
116
127
|
const n = this.nearest(this.target.position);
|
|
117
128
|
if (n && n !== this.current) {
|
|
118
129
|
const p = this.target.position, d = k => (this.shots[k].at || this.shots[k].position).distanceTo(p);
|
|
119
|
-
if (d(n) + this.hysteresis < d(this.current)) this.
|
|
130
|
+
if (d(n) + this.hysteresis < d(this.current)) this._moveOn(n);
|
|
120
131
|
}
|
|
121
132
|
}
|
|
122
|
-
const
|
|
123
|
-
const
|
|
133
|
+
const sh = this.shots[this.current]; // after the auto switch: the shot this frame shows
|
|
134
|
+
const want = this._lookTarget(sh, this._want ??= new THREE.Vector3()); // scratch vectors: no per-frame allocation
|
|
124
135
|
if (this._blend) {
|
|
136
|
+
const fov = sh.fov ?? baseFov(this.engine);
|
|
125
137
|
const b = this._blend; b.t += dt;
|
|
126
138
|
const k = easing(b.ease)(Math.min(1, b.t / b.dur));
|
|
127
|
-
const sh = this.shots[this.current];
|
|
128
139
|
const pos = (this._bp ??= new THREE.Vector3()).copy(b.from).lerp(sh.position, k), look = (this._bl ??= new THREE.Vector3()).copy(b.fromLook).lerp(want, k);
|
|
129
140
|
this._look.copy(look);
|
|
130
141
|
// size blends only between two orthographic shots; a perspective/orthographic mix switches to the target's mode at once
|
|
131
|
-
this._place(pos, look, b.fromFov + (fov - b.fromFov) * k, sh.size && b.fromSize ? b.fromSize + (sh.size - b.fromSize) * k : sh.size);
|
|
142
|
+
this._place(pos, look, (b.fromFov ?? fov) + (fov - (b.fromFov ?? fov)) * k, sh.size && b.fromSize ? b.fromSize + (sh.size - b.fromSize) * k : sh.size);
|
|
132
143
|
if (b.t >= b.dur) { this._blend = null; b.res(); }
|
|
133
144
|
} else {
|
|
134
|
-
if (
|
|
145
|
+
if (sh.track) this._look.lerp(want, 1 - Math.exp(-this.trackSmoothing * dt));
|
|
135
146
|
else this._look.copy(want);
|
|
136
|
-
this._place(
|
|
147
|
+
this._place(sh.position, this._look, sh.fov ?? null, sh.size);
|
|
137
148
|
}
|
|
138
149
|
// Direction: release the hold once no direction key is pressed
|
|
139
150
|
const a = input.axis;
|
|
@@ -155,10 +166,12 @@ export class FixedCamera {
|
|
|
155
166
|
return s.lookAt ? out.copy(s.lookAt) : out.set(s.position.x, s.position.y, s.position.z - 1);
|
|
156
167
|
}
|
|
157
168
|
_place(pos, look, fov, size = null) {
|
|
158
|
-
|
|
169
|
+
if (this.engine.cameraOverride) return; // a held camera has one writer: current and _look are what lands at release (common.js)
|
|
170
|
+
shotFov(this.engine, size ? null : fov); // before the projection: a hold would keep a swap waiting
|
|
171
|
+
// the view is asked for when it changes, so a perspective camera the game assigned during a shot stays until the next one; a height goes on any orthographic camera
|
|
172
|
+
if (!this.pixelSnap && (size !== this._shown || this.engine.camera.isOrthographicCamera)) { this._shown = size; setProjection(this.engine, size ? 'orthographic' : 'perspective', size); }
|
|
173
|
+
const cam = this.engine.camera; // read after the view: it may have just swapped
|
|
159
174
|
cam.position.copy(pos); cam.lookAt(look);
|
|
160
|
-
setProjection(cam, size ? 'orthographic' : 'perspective', size);
|
|
161
|
-
if (Math.abs(cam.fov - fov) > 1e-3) setFov(this.engine, fov); // yields to a fov the game set itself (engine.view 'fov')
|
|
162
175
|
rigPlaced(this.engine); // a cut between frames is the engine's own write (common.js)
|
|
163
176
|
}
|
|
164
177
|
_latchDirection() {
|
|
@@ -177,4 +190,4 @@ export function fixedCamera(opts = {}) { return rigModule('fixed', opts); }
|
|
|
177
190
|
defineRig('fixed', (e, opts) => {
|
|
178
191
|
return new FixedCamera(e, opts);
|
|
179
192
|
}, ['shots', 'start', 'auto', 'autoInterval', 'hysteresis', 'triggerBlend', 'trackHeight', 'trackSmoothing', 'holdDirection', 'ease',
|
|
180
|
-
'position', 'lookAt', 'track', 'fov', 'projection', 'size', 'at']); // the last row: setCamera('fixed', { position, lookAt }) is a one-shot form
|
|
193
|
+
'pixelSnap', 'position', 'lookAt', 'track', 'fov', 'projection', 'size', 'at']); // the last row: setCamera('fixed', { position, lookAt }) is a one-shot form
|
|
@@ -11,8 +11,10 @@
|
|
|
11
11
|
// Other cameras: firstPersonCamera, fixedCamera, rtsCamera (top-down strategy); all are engine.cameraRig; switch at runtime with engine.setCamera('firstPerson').
|
|
12
12
|
import * as THREE from 'three';
|
|
13
13
|
import { rigModule, defineRig, YAW_RIG, HIDE_RIG, clickToLock, releaseLock } from './common.js';
|
|
14
|
-
import { setProjection } from '
|
|
15
|
-
import {
|
|
14
|
+
import { setProjection } from '../../core/scene/view.js';
|
|
15
|
+
import { rigPixelSnap, checkPixelView } from './pixelSnap.js';
|
|
16
|
+
import { codedError } from '../../core/base/errorHints.js';
|
|
17
|
+
import { wrapAngle } from '../../core/base/math.js';
|
|
16
18
|
|
|
17
19
|
const GROUND = ['raise', 'shorten', 'none'];
|
|
18
20
|
// ground: 'shorten' sampling. 0.2 m: narrower than this the ground height rarely has a feature that blocks the view (posts and walls are colliders,
|
|
@@ -25,11 +27,16 @@ export class FollowCamera {
|
|
|
25
27
|
* shoulder meters to the right of the target the camera aims (over-the-shoulder; negative = left shoulder, 0 = centered);
|
|
26
28
|
* pointerLock click locks the mouse (no dragging; the press that locks is swallowed, swallowLockClick: false delivers it);
|
|
27
29
|
* ground 'raise' | 'shorten' | 'none' | fn (see the top of this file); mouseLook false = the game drives yaw / pitch (setView);
|
|
28
|
-
* hideTargetNear hide the followed object when the camera is closer than this (m, 0 = never); hideLayer layer used for hiding
|
|
30
|
+
* hideTargetNear hide the followed object when the camera is closer than this (m, 0 = never); hideLayer layer used for hiding;
|
|
31
|
+
* pixelSnap { pixelsPerMeter, bounds } orthographic only: art-pixel rounding, and it decides the view height (pixelSnap.js) */
|
|
29
32
|
constructor(engine, { yaw = 0.8, pitch = 0.42, distance = 13, minDistance = 4, maxDistance = 45, height = 1.4, smoothing = 10,
|
|
30
|
-
sensitivity = 1, minPitch = 0.05, maxPitch = 1.35, zoomStep = 0.1, groundClearance = 1.2, invertY = false, shoulder = 0, pointerLock = false, swallowLockClick = true, projection = 'perspective', size =
|
|
31
|
-
ground = null, mouseLook = true, hideTargetNear = 0.9, hideLayer = 30 } = {}) {
|
|
33
|
+
sensitivity = 1, minPitch = 0.05, maxPitch = 1.35, zoomStep = 0.1, groundClearance = 1.2, invertY = false, shoulder = 0, pointerLock = false, swallowLockClick = true, projection = 'perspective', size = null,
|
|
34
|
+
ground = null, mouseLook = true, hideTargetNear = 0.9, hideLayer = 30, pixelSnap = null } = {}) {
|
|
32
35
|
if (ground != null && typeof ground !== 'function' && !GROUND.includes(ground)) throw codedError('camera-option', `followCamera({ ground: '${ground}' }): use ${GROUND.map(g => `'${g}'`).join(' | ')} or a function (facts) => position`);
|
|
36
|
+
if (pixelSnap) checkPixelView('followCamera', { projection, size });
|
|
37
|
+
/** Art-pixel rounding (.grid, .error, .agrees) or null */
|
|
38
|
+
this.pixelSnap = rigPixelSnap(engine, pixelSnap, 'followCamera');
|
|
39
|
+
size ??= 20;
|
|
33
40
|
this.projection = projection; this.size = size; // 'orthographic': size = world units of view height (the wheel changes size there, clamped to the min/max distance ratio)
|
|
34
41
|
this.size0 = size; this.distance0 = distance;
|
|
35
42
|
Object.assign(this, { engine, yaw, pitch, distance, minDistance, maxDistance, height, smoothing, sensitivity, minPitch, maxPitch, zoomStep, groundClearance });
|
|
@@ -53,7 +60,7 @@ export class FollowCamera {
|
|
|
53
60
|
/**
|
|
54
61
|
* Lock-on framing: each frame turn yaw toward "behind the followed object, looking at target" (forward() turns with it, so camera-relative movement strafes around the target).
|
|
55
62
|
* Mouse / stick yaw is ignored while framing; frame(null) hands yaw back. strength: how fast it turns (1/s). Set it once when the lock starts, not every frame
|
|
56
|
-
* @example engine.cameraRig.frame(enemy.
|
|
63
|
+
* @example engine.cameraRig.frame(enemy.root); player.faceMode = 'target'; player.faceTarget = enemy.root;
|
|
57
64
|
*/
|
|
58
65
|
frame(target, { strength = 6 } = {}) { this.framing = target ? { target, strength } : null; }
|
|
59
66
|
/**
|
|
@@ -72,25 +79,27 @@ export class FollowCamera {
|
|
|
72
79
|
const look = this.engine.camera.getWorldDirection(new THREE.Vector3()), p = this._pivot ?? this.focus;
|
|
73
80
|
return { yaw: this.yaw, pitch: this.pitch, distance: this.distance, arm: this.arm, lookPoint: { x: p.x, y: p.y, z: p.z }, look: { x: look.x, y: look.y, z: look.z } };
|
|
74
81
|
}
|
|
75
|
-
onEnter(switched) { clickToLock(this, switched); setProjection(this.engine
|
|
82
|
+
onEnter(switched) { clickToLock(this, switched); if (this.pixelSnap) this.pixelSnap.enter(); else setProjection(this.engine, this.projection, this.size); this._shadowLayers(); }
|
|
76
83
|
onExit() { releaseLock(this); this._unhide(); }
|
|
77
|
-
onOverride(on) { if (on) releaseLock(this, true); }
|
|
84
|
+
onOverride(on) { if (on) { releaseLock(this, true); this._unhide(); } } // the close-up hide is about this rig's view; update() decides it again at release
|
|
78
85
|
|
|
79
86
|
update(dt, input) {
|
|
80
87
|
const cam = this.engine.camera, fr = this.framing;
|
|
81
88
|
if (fr && this.target) {
|
|
82
89
|
const t = fr.target.position ?? fr.target, p = this.target.position;
|
|
83
|
-
|
|
84
|
-
this.yaw += d * Math.min(1, dt * fr.strength);
|
|
90
|
+
this.yaw += wrapAngle(Math.atan2(p.x - t.x, p.z - t.z) - this.yaw) * Math.min(1, dt * fr.strength);
|
|
85
91
|
}
|
|
86
92
|
if (input.enabled && this.mouseLook !== false) {
|
|
87
93
|
if (!fr) this.yaw -= input.look.dx * 0.005 * this.sensitivity;
|
|
88
94
|
if (!this.lockPitch) this.pitch = Math.min(this.maxPitch, Math.max(this.minPitch, this.pitch + input.look.dy * 0.004 * this.sensitivity * (this.invertY ? -1 : 1)));
|
|
89
|
-
if (input.look.zoom && this.
|
|
90
|
-
|
|
95
|
+
if (input.look.zoom && this.pixelSnap) { /* the view height is pixelSnap's; the art-pixel zoom is engine.setPixelSize */ }
|
|
96
|
+
else if (input.look.zoom && cam.isOrthographicCamera) {
|
|
97
|
+
// distance shows nothing in an orthographic view, whichever the rig asked for: zoom `size`, clamped to the same min/max ratio as distance, same wheel feel.
|
|
98
|
+
// A camera the game assigned counts from the height it came with
|
|
99
|
+
if (this._zoomed !== cam) { this._zoomed = cam; this.size = this.size0 = cam.top - cam.bottom; }
|
|
91
100
|
const lo = this.size0 * this.minDistance / this.distance0, hi = this.size0 * this.maxDistance / this.distance0;
|
|
92
101
|
this.size = Math.min(hi, Math.max(lo, this.size * (1 + input.look.zoom * this.zoomStep)));
|
|
93
|
-
|
|
102
|
+
setProjection(this.engine, 'orthographic', this.size);
|
|
94
103
|
} else if (input.look.zoom) this.distance = Math.min(this.maxDistance, Math.max(this.minDistance, this.distance * (1 + input.look.zoom * this.zoomStep)));
|
|
95
104
|
}
|
|
96
105
|
if (!this.target) return;
|
|
@@ -113,7 +122,7 @@ export class FollowCamera {
|
|
|
113
122
|
if (mode === 'shorten') arm = this._shorten(fx, fy, fz, ux, uy, uz, arm, surf);
|
|
114
123
|
place(arm);
|
|
115
124
|
if (mode === 'raise') {
|
|
116
|
-
const g =
|
|
125
|
+
const g = surf(cam.position.x, cam.position.z) + clear; // the layer the player is on: a floor above must not lift the camera out of a cellar
|
|
117
126
|
if (cam.position.y < g) cam.position.y = g;
|
|
118
127
|
} else if (typeof mode === 'function') {
|
|
119
128
|
const r = mode({ position: cam.position.clone(), lookPoint: pivot.clone(), dir: { x: ux, y: uy, z: uz }, arm, distance: this.distance,
|
|
@@ -162,4 +171,4 @@ defineRig('follow', (e, opts) => {
|
|
|
162
171
|
const c = new FollowCamera(e, opts); if (opts.lockPitch) c.lockPitch = true; return c;
|
|
163
172
|
}, ['yaw', 'pitch', 'distance', 'minDistance', 'maxDistance', 'height', 'smoothing', 'sensitivity', 'minPitch', 'maxPitch',
|
|
164
173
|
'zoomStep', 'groundClearance', 'invertY', 'lockPitch', 'shoulder', 'pointerLock', 'swallowLockClick', 'projection', 'size',
|
|
165
|
-
'ground', 'mouseLook', 'hideTargetNear', 'hideLayer']);
|
|
174
|
+
'ground', 'mouseLook', 'hideTargetNear', 'hideLayer', 'pixelSnap']);
|
|
@@ -7,27 +7,27 @@
|
|
|
7
7
|
// To not follow: call engine.cameraRig.follow(null) after creating the player, and WASD pans the camera
|
|
8
8
|
// Cutscene takeover: while someone holds engine.takeCamera (engine.cameraOverride is not null) the camera is left alone (see common.js).
|
|
9
9
|
//
|
|
10
|
-
// engine.use(rtsCamera({ height: 30,
|
|
10
|
+
// engine.use(rtsCamera({ height: 30, pitch: 0.95, panSpeed: 1, edgePan: true, bounds: { minX: -100, maxX: 100, minZ: -100, maxZ: 100 } }));
|
|
11
11
|
// const p = engine.cameraRig.screenToGround(engine.input.pointer.ndcX, engine.input.pointer.ndcY);
|
|
12
12
|
// engine.cameraRig.moveTo(position); // move the view somewhere; { instant: true } skips smoothing
|
|
13
13
|
import * as THREE from 'three';
|
|
14
14
|
import { rigModule, defineRig, CAMERA_STRINGS, YAW_RIG, rigPlaced } from './common.js';
|
|
15
|
-
import { xzOf } from '../../core/math.js';
|
|
16
|
-
import { setFov } from '../../core/view.js';
|
|
17
|
-
import { surfaceOr } from '../../core/ground.js';
|
|
15
|
+
import { xzOf } from '../../core/base/math.js';
|
|
16
|
+
import { setFov } from '../../core/scene/view.js';
|
|
17
|
+
import { surfaceOr } from '../../core/scene/ground.js';
|
|
18
18
|
|
|
19
19
|
export class RtsCamera {
|
|
20
20
|
/**
|
|
21
|
-
* height camera height above the focus (zoom changes this); minHeight/maxHeight zoom range;
|
|
21
|
+
* height camera height above the focus (zoom changes this); minHeight/maxHeight zoom range; pitch pitch-down angle (radians, pi/2 = straight down);
|
|
22
22
|
* yaw initial horizontal facing; panSpeed pan speed multiplier (actual speed scales with height); dragPan drag-to-pan with the mouse;
|
|
23
23
|
* edgePan pan at screen edges; edgeSize edge width (fraction of the screen); bounds { minX, maxX, minZ, maxZ } focus range;
|
|
24
24
|
* rotate false: no turning (default true: the camera module declares the actions rotateLeft / rotateRight, which the game binds); rotateSpeed rotation speed (radians/second);
|
|
25
25
|
* zoomStep zoom ratio per wheel notch; smoothing smoothness; fov field of view (unchanged if omitted); followLock disallow manual pan while following; start initial focus (position)
|
|
26
26
|
*/
|
|
27
|
-
constructor(engine, { height = 30, minHeight = 8, maxHeight = 90,
|
|
27
|
+
constructor(engine, { height = 30, minHeight = 8, maxHeight = 90, pitch = 0.95, yaw = 0, panSpeed = 1, dragPan = true, edgePan = false, edgeSize = 0.02,
|
|
28
28
|
bounds = null, rotate = true, rotateSpeed = 1.8, zoomStep = 0.12, smoothing = 10, fov = null,
|
|
29
29
|
followLock = false, start = null } = {}) {
|
|
30
|
-
Object.assign(this, { engine, height, minHeight, maxHeight,
|
|
30
|
+
Object.assign(this, { engine, height, minHeight, maxHeight, pitch, yaw, panSpeed, dragPan, edgePan, edgeSize, bounds, rotateSpeed, zoomStep, smoothing, followLock });
|
|
31
31
|
this.target = null;
|
|
32
32
|
this.following = false;
|
|
33
33
|
const [sx, sz] = start ? xzOf(start) : [0, 0];
|
|
@@ -42,9 +42,9 @@ export class RtsCamera {
|
|
|
42
42
|
this._place();
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
/** Follow an object (called automatically when the player is created). While following, WASD moves the character; manual drag/edge pan drops the follow (not with followLock) */
|
|
46
45
|
/** Called when this camera is switched in (module install, setCamera): applies fov */
|
|
47
46
|
onEnter() { if (this.fov) setFov(this.engine, this.fov); }
|
|
47
|
+
/** Follow an object (called automatically when the player is created). While following, WASD moves the character; manual drag/edge pan drops the follow (not with followLock) */
|
|
48
48
|
follow(obj) { this.target = obj; this.following = !!obj; if (obj) this.moveTo(obj); }
|
|
49
49
|
/** Move the view somewhere; with instant true there is no smoothing */
|
|
50
50
|
moveTo(position, { instant = false } = {}) { const [x, z] = xzOf(position); this.focus.set(x, 0, z); this._clamp(); if (instant) { this._f.copy(this.focus); this._place(); } }
|
|
@@ -101,10 +101,11 @@ export class RtsCamera {
|
|
|
101
101
|
if (b) { this.focus.x = Math.min(b.maxX ?? Infinity, Math.max(b.minX ?? -Infinity, this.focus.x)); this.focus.z = Math.min(b.maxZ ?? Infinity, Math.max(b.minZ ?? -Infinity, this.focus.z)); }
|
|
102
102
|
}
|
|
103
103
|
_place() {
|
|
104
|
+
if (this.engine.cameraOverride) return; // a held camera has one writer: focus and _f are what lands at release (common.js)
|
|
104
105
|
const cam = this.engine.camera, f = this._f;
|
|
105
106
|
const g = this.engine.surface(f.x, f.z);
|
|
106
107
|
if (g > -Infinity) f.y = g; // focus sticks to the ground; over the void of terrain({ shape }) it keeps its last height
|
|
107
|
-
const a = Math.min(Math.PI / 2 - 1e-3, Math.max(0.05, this.
|
|
108
|
+
const a = Math.min(Math.PI / 2 - 1e-3, Math.max(0.05, this.pitch));
|
|
108
109
|
const back = this._h / Math.tan(a); // horizontal back-off distance
|
|
109
110
|
cam.position.set(f.x + Math.sin(this._yaw) * back, f.y + this._h, f.z + Math.cos(this._yaw) * back);
|
|
110
111
|
cam.lookAt(f);
|
|
@@ -117,7 +118,7 @@ for (const k of ['forward', 'right']) RtsCamera.prototype[k] = YAW_RIG[k];
|
|
|
117
118
|
|
|
118
119
|
/**
|
|
119
120
|
* Strategy top-down camera module. Installs engine.cameraRig (pick it or followCamera).
|
|
120
|
-
* rtsCamera({ height: 30,
|
|
121
|
+
* rtsCamera({ height: 30, pitch: 0.95, panSpeed: 1, edgePan: true, bounds }) + createEngine({ bindings: { ...presets.bindings.rtsRotate } })
|
|
121
122
|
* Actions: rotateLeft / rotateRight (no keys of their own)
|
|
122
123
|
*/
|
|
123
124
|
export function rtsCamera(opts = {}) { return rigModule('rts', opts); }
|
|
@@ -129,5 +130,5 @@ defineRig('rts', (e, opts, input) => {
|
|
|
129
130
|
input.action('rotateRight', { label: 'camera.rotateRight', optional: true });
|
|
130
131
|
}
|
|
131
132
|
return new RtsCamera(e, opts);
|
|
132
|
-
}, ['height', 'minHeight', 'maxHeight', '
|
|
133
|
+
}, ['height', 'minHeight', 'maxHeight', 'pitch', 'yaw', 'panSpeed', 'dragPan', 'edgePan', 'edgeSize', 'bounds', 'rotate',
|
|
133
134
|
'rotateSpeed', 'zoomStep', 'smoothing', 'fov', 'followLock', 'start']);
|
package/modules/camera/common.js
CHANGED
|
@@ -9,20 +9,21 @@
|
|
|
9
9
|
// update(dt, input) per-frame camera update
|
|
10
10
|
// What a game's own camera module must provide instead (what control: 'camera', characters, photo, grid placement read): camera/contract.js.
|
|
11
11
|
//
|
|
12
|
-
// Cutscene takeover contract: engine.takeCamera(owner, { focus? }) -> { remove() } (core/holds.js); engine.cameraOverride is the holder in charge.
|
|
12
|
+
// Cutscene takeover contract: engine.takeCamera(owner, { focus? }) -> { remove() } (core/ops/holds.js); engine.cameraOverride is the holder in charge.
|
|
13
13
|
// A cutscene, a named view or a photo mode that places the camera itself takes it; several can hold it, the latest is in charge.
|
|
14
14
|
// While anyone holds it the camera module leaves the camera alone; with a focus, engine.focus is set to it (the world loads around it).
|
|
15
|
+
// A rig told to move meanwhile (cut, moveTo, a switch of rigs) only records it: its fields change, the camera does not, and its next update after the release lands it.
|
|
16
|
+
// onOverride undoes what the rig did to the view for its own sake (the hidden body, the mouse lock).
|
|
15
17
|
// When the last holder removes its claim the camera module resumes from its previous state. cameraOverride itself is read-only.
|
|
16
18
|
import * as THREE from 'three';
|
|
17
|
-
import { defineOwned } from '../../core/owned.js';
|
|
18
|
-
import { readParams, keysSchema } from '../../core/params.js';
|
|
19
|
-
import { setProjection } from '
|
|
20
|
-
import {
|
|
21
|
-
import { codedError } from '../../core/errorHints.js';
|
|
19
|
+
import { defineOwned, dropOwned } from '../../core/ops/owned.js';
|
|
20
|
+
import { readParams, keysSchema } from '../../core/base/params.js';
|
|
21
|
+
import { setFov, setProjection } from '../../core/scene/view.js';
|
|
22
|
+
import { codedError } from '../../core/base/errorHints.js';
|
|
22
23
|
|
|
23
|
-
// the takeover calls the owned-camera warning quotes (core/owned.js): takeCamera is the one explicit entry (its remove() gives the camera back);
|
|
24
|
+
// the takeover calls the owned-camera warning quotes (core/ops/owned.js): takeCamera is the one explicit entry (its remove() gives the camera back);
|
|
24
25
|
// back is the hand-back for a camera the engine yielded to a direct write (that takeover has no handle)
|
|
25
|
-
const LEVELS = { manual: "const cam = engine.takeCamera('me') (cam.remove() gives it back)", back: "engine.
|
|
26
|
+
const LEVELS = { manual: "const cam = engine.takeCamera('me') (cam.remove() gives it back)", back: "engine.autoView.manual('camera', false)" };
|
|
26
27
|
|
|
27
28
|
/** True during a cutscene takeover, and updates engine.focus from the focus the owner supplied */
|
|
28
29
|
function applyOverride(e) {
|
|
@@ -61,7 +62,7 @@ export const HIDE_RIG = {
|
|
|
61
62
|
if ((o.isMesh || o.isSkinnedMesh || o.isPoints || o.isLine) && !o.layers.isEnabled(this.hideLayer)) { this._hidden.push([o, o.layers.mask]); o.layers.set(this.hideLayer); }
|
|
62
63
|
});
|
|
63
64
|
},
|
|
64
|
-
_unhide() { for (const [o, mask] of this._hidden) o.layers.mask = mask; this._hidden =
|
|
65
|
+
_unhide() { for (const [o, mask] of this._hidden) o.layers.mask = mask; this._hidden.length = 0; }, // follow calls it every frame
|
|
65
66
|
// Lights present now (the sky module has built them by onEnter); a light added later calls shadow.camera.layers.enable(hideLayer) itself
|
|
66
67
|
_shadowLayers() { this.engine.scene.traverse(o => { if (o.isLight && o.shadow?.camera) o.shadow.camera.layers.enable(this.hideLayer); }); },
|
|
67
68
|
};
|
|
@@ -87,7 +88,8 @@ export function clickToLock(rig, switched) {
|
|
|
87
88
|
};
|
|
88
89
|
rig._off = new AbortController();
|
|
89
90
|
const sig = { signal: AbortSignal.any([e.signal, rig._off.signal]) };
|
|
90
|
-
|
|
91
|
+
const change = e.events.on('page:pointerlock', ({ locked }) => { st.locked = locked; if (locked) st.lastError = null; else st.requested = false; });
|
|
92
|
+
sig.signal.addEventListener('abort', change.remove);
|
|
91
93
|
document.addEventListener('pointerlockerror', () => fail('pointerlockerror (browser refused: needs a user gesture, or the page lost focus)'), sig);
|
|
92
94
|
const swallow = () => rig.swallowLockClick !== false && wouldLock();
|
|
93
95
|
e.input.swallowLockClick = swallow; rig._swallow = swallow;
|
|
@@ -101,11 +103,11 @@ export function clickToLock(rig, switched) {
|
|
|
101
103
|
*/
|
|
102
104
|
function lockView(e, st) {
|
|
103
105
|
if (!st?.configured) return { state: 'off' };
|
|
104
|
-
const state = !st.
|
|
106
|
+
const state = !st.supported ? 'unsupported' : st.locked ? 'locked' : st.lastError ? 'refused' : st.requested ? 'requesting' : 'waiting-click';
|
|
105
107
|
const c = e.renderer.domElement, r = c.getBoundingClientRect();
|
|
106
108
|
const top = typeof document.elementFromPoint === 'function' ? document.elementFromPoint(r.left + r.width / 2, r.top + r.height / 2) : null;
|
|
107
109
|
return { ...st, state, covered: top && top !== c ? (top.id ? '#' + top.id : top.className ? '.' + String(top.className).split(' ')[0] : top.tagName.toLowerCase()) : null,
|
|
108
|
-
cameraOverride: e.cameraOverride?.owner ?? null, lastFailure: st
|
|
110
|
+
cameraOverride: e.cameraOverride?.owner ?? null, lastFailure: st.lastError ? { reason: st.lastError, agoSec: Math.round((e.time.now('real') - st.failedAt) / 100) / 10 } : null };
|
|
109
111
|
}
|
|
110
112
|
/** Release the mouse lock; stop listening for clicks too when switched away (call from onExit; from onOverride with keepListening) */
|
|
111
113
|
export function releaseLock(rig, keepListening = false) {
|
|
@@ -122,11 +124,12 @@ export function viewForward(camera, fallback) {
|
|
|
122
124
|
return planar(_v, fallback);
|
|
123
125
|
}
|
|
124
126
|
|
|
125
|
-
|
|
127
|
+
import { screenToGround } from '../../core/scene/screenToGround.js'; // shared with grid placement and click-to-move; lives in core
|
|
128
|
+
export { screenToGround };
|
|
126
129
|
|
|
127
130
|
/**
|
|
128
131
|
* A rig placed the camera outside its update (fixedCamera cut, rtsCamera moveTo instant): that write is the engine's, not the game's, so the
|
|
129
|
-
* next frame's single ownership check (core/owned.js) must not take it for an outside write and stop the rig. Rigs call this from the one
|
|
132
|
+
* next frame's single ownership check (core/ops/owned.js) must not take it for an outside write and stop the rig. Rigs call this from the one
|
|
130
133
|
* method that writes the pose (their _place), instead of the module wrapping every rig method with a pose compare (that ran on every
|
|
131
134
|
* forward() / right() read, several times per fixed step).
|
|
132
135
|
* @internal
|
|
@@ -148,8 +151,11 @@ export function defineRig(kind, build, keys = []) { RIGS.set(kind, build); RIG_P
|
|
|
148
151
|
* kind: 'follow' | 'firstPerson' | 'fixed' | 'rts', reported in describe()
|
|
149
152
|
*/
|
|
150
153
|
export function rigModule(kind, opts) {
|
|
151
|
-
let c = null, was = false, owned = null, fresh = true, engine = null
|
|
154
|
+
let c = null, home = null, was = false, owned = null, hold = null, fresh = true, engine = null; // home: the rig install built; every new playthrough goes back to this same object
|
|
155
|
+
// the fov a switch of rigs goes back to, per camera: the value it had when first asked, so a camera the game assigned keeps its own
|
|
156
|
+
const fovs = new WeakMap(), fov0 = () => { const m = engine.camera; if (!fovs.has(m)) fovs.set(m, m.fov); return fovs.get(m); };
|
|
152
157
|
const cache = new Map(); // kind -> camera instance: params like distance and pitch survive switching away and back
|
|
158
|
+
const builtWith = new WeakMap(); // rig -> the options it was built with
|
|
153
159
|
let modInput = null; const declared = new Set();
|
|
154
160
|
const input = { action: (n, o) => { if (!declared.has(n)) { declared.add(n); modInput.action(n, o); } } };
|
|
155
161
|
const make = (k, o) => {
|
|
@@ -157,7 +163,7 @@ export function rigModule(kind, opts) {
|
|
|
157
163
|
if (!build) throw codedError('camera-kind', `setCamera() has no camera kind '${k}'; available: ${[...RIGS.keys()].join(', ')}`);
|
|
158
164
|
readParams(`${k}Camera`, RIG_PARAMS.get(k), o); // also covers setCamera(kind, options)
|
|
159
165
|
const r = build(engine, o ?? {}, input);
|
|
160
|
-
r.kind = k; cache.set(k, r);
|
|
166
|
+
r.kind = k; cache.set(k, r); builtWith.set(r, o);
|
|
161
167
|
// every kind answers the contract's screenToGround (click-to-move and placement work under any camera, not only the strategy one)
|
|
162
168
|
if (typeof r.screenToGround !== 'function') r.screenToGround = (x, y) => screenToGround(engine, x, y);
|
|
163
169
|
return r;
|
|
@@ -166,11 +172,16 @@ export function rigModule(kind, opts) {
|
|
|
166
172
|
if (k === c.kind && !o) return c;
|
|
167
173
|
const old = c, target = old.target;
|
|
168
174
|
old.onExit?.();
|
|
169
|
-
setProjection(engine
|
|
170
|
-
setFov(engine, fov0); // fov returns to the value at install; each camera applies its own in onEnter / constructor
|
|
171
|
-
|
|
175
|
+
setProjection(engine); // back to perspective; an orthographic rig sets its own in onEnter / constructor
|
|
176
|
+
setFov(engine, fov0()); // fov returns to the value at install; each camera applies its own in onEnter / constructor
|
|
177
|
+
let next;
|
|
178
|
+
// a bad kind or option throws, or a view engine.camera cannot show (onEnter): the old rig goes back on, or the game keeps a rig that let go of its target and of the mouse
|
|
179
|
+
const back = err => { cache.set(old.kind, old); c = engine.cameraRig = old; old.onEnter?.(false); old.follow(target ?? null); throw err; };
|
|
180
|
+
try { next = o || !cache.has(k) ? make(k, o) : cache.get(k); } catch (err) { back(err); }
|
|
172
181
|
c = engine.cameraRig = next;
|
|
173
|
-
next.onEnter?.(true);
|
|
182
|
+
try { next.onEnter?.(true); } catch (err) { next.onExit?.(); back(err); }
|
|
183
|
+
// set up before play (boot code, the title up): this is the game's camera, so the playthrough starts from it, not from the module's options
|
|
184
|
+
if (!engine.session.playing) { home = next; kind = k; opts = builtWith.get(next); }
|
|
174
185
|
if (old.yaw !== undefined && next.yaw !== undefined && !(o && o.yaw != null)) next.yaw = old.yaw; // keep turning from the same heading, no sudden spin
|
|
175
186
|
next.follow(target ?? null);
|
|
176
187
|
fresh = true; // the camera position was changed here, not counted as "the game moved the camera"
|
|
@@ -178,31 +189,49 @@ export function rigModule(kind, opts) {
|
|
|
178
189
|
return c;
|
|
179
190
|
}
|
|
180
191
|
return {
|
|
181
|
-
name: 'cameraRig', type: 'picture', label: 'Camera', params: RIG_PARAMS.get(kind), options: opts, optional: ['collision'], stage: 'control',
|
|
192
|
+
name: 'cameraRig', skipKind: 'none', type: 'picture', provides: ['cameraRig'], label: 'Camera', params: RIG_PARAMS.get(kind), options: opts, optional: ['collision', 'characters'], stage: 'control',
|
|
182
193
|
install(e, ctx) { e.i18n.add({ 'zh-CN': { 'module.cameraRig': '相机' }, en: { 'module.cameraRig': 'camera' } });
|
|
183
|
-
engine = e; fov0
|
|
194
|
+
engine = e; fov0(); modInput = ctx.input; declared.clear();
|
|
184
195
|
e.setCamera = setCamera;
|
|
185
|
-
c = make(kind, opts);
|
|
196
|
+
c = home = make(kind, opts);
|
|
186
197
|
c.onEnter?.(false);
|
|
187
|
-
//
|
|
198
|
+
// The view the player had is save data. Written to a rig of the saved kind only: a follow rig's pitch means the opposite of a first-person one's, so across kinds
|
|
199
|
+
// only the heading carries (as in setCamera). A kind switched to at runtime is not restored: its options are the game's and are not save data
|
|
200
|
+
ctx.saves.register('cameraRig', { notAtomic: 'the view is output: no game rule reads it, and a rollback must not move the camera',
|
|
201
|
+
save: () => ({ kind: c.kind, yaw: c.yaw, pitch: c.pitch }),
|
|
202
|
+
load: d => {
|
|
203
|
+
const r = d.kind === c.kind ? c : home;
|
|
204
|
+
if (r.yaw !== undefined && Number.isFinite(d.yaw)) r.yaw = d.yaw;
|
|
205
|
+
if (r.pitch !== undefined && r.kind === d.kind && Number.isFinite(d.pitch)) r.pitch = d.pitch;
|
|
206
|
+
},
|
|
207
|
+
});
|
|
208
|
+
// a new playthrough (newGame / load) starts with the camera as installed (kind, distance, every option), placed at the player instead of flying across the map.
|
|
209
|
+
// The same object, so a rig the game kept at boot stays the camera; its view is what the load just left on it (the part above, or a game part's load() writing the rig)
|
|
188
210
|
ctx.track(e.events.on('session:start', () => {
|
|
189
|
-
|
|
211
|
+
// a hold made by writing the camera has no handle and no one who will end it: it belonged to the playthrough that is over. A manual() hold is on purpose and stays
|
|
212
|
+
if (owned.mode === 'yielded') owned.manual(false);
|
|
213
|
+
// the view the load left is on the rig of the saved kind, and that may be a rig switched to at runtime (the cameraRig part above)
|
|
214
|
+
const old = c, { yaw, pitch } = c.kind === kind ? c : home;
|
|
190
215
|
old.onExit?.(); cache.clear();
|
|
191
|
-
setProjection(e
|
|
192
|
-
setFov(e, fov0);
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
e.
|
|
216
|
+
setProjection(e);
|
|
217
|
+
setFov(e, fov0());
|
|
218
|
+
const built = make(kind, opts);
|
|
219
|
+
for (const k of Object.keys(home)) delete home[k];
|
|
220
|
+
c = e.cameraRig = Object.assign(home, built, yaw !== undefined && { yaw, pitch });
|
|
221
|
+
cache.set(kind, home);
|
|
222
|
+
// follows the player only if the game asked (createPlayer({ cameraFollow })), through the seat the load put it in: the rig was rebuilt after that seat was taken
|
|
223
|
+
const P = e.player, car = P?.cameraFollow ? P.vehicle : null;
|
|
224
|
+
c.onEnter?.(false); c.follow(car ? car.object : P?.cameraFollow ? P.root : null, car?.camera); fresh = true;
|
|
225
|
+
e.events.emit('camera:change', { kind, previous: old.kind }); // settings re-apply the player's sensitivity / fov to the rebuilt rig
|
|
196
226
|
}));
|
|
197
227
|
// a scenario put the player somewhere else (?at, ?pos): a rig that eases would open on a glide across the map; follow() puts it there at once
|
|
198
228
|
ctx.track(e.events.on('state:placed', () => { if (c.target) { c.follow(c.target); fresh = true; } }));
|
|
199
229
|
// The camera module places position / orientation every frame: a game that moves the camera directly takes it (the rig stops), warned once
|
|
200
|
-
const cam = e.camera
|
|
201
|
-
// One camera state: takeCamera's 'camera' stack. engine.
|
|
230
|
+
const cam = e.camera;
|
|
231
|
+
// One camera state: takeCamera's 'camera' stack. engine.autoView.manual('camera') and a direct write become a takeCamera hold too (owner
|
|
202
232
|
// 'manual:<who>' / 'three'), so cameraOverride, describe().holds and the rig's onOverride see every takeover the same way; handing back
|
|
203
233
|
// (manual('camera', false)) removes that hold. Why: four entries with four states meant a pointer lock or focus that only one of them reset.
|
|
204
|
-
|
|
205
|
-
owned = defineOwned(e, { id: 'camera', part: 'view', key: 'camera', read: () => [p.x, p.y, p.z, q.x, q.y, q.z, q.w], objects: [cam, p, q], levels: LEVELS,
|
|
234
|
+
owned = defineOwned(e, { id: 'camera', part: 'view', key: 'camera', read: () => { const { position: p, quaternion: q } = e.camera; return [p.x, p.y, p.z, q.x, q.y, q.z, q.w]; }, objects: [cam, cam.position, cam.quaternion], levels: LEVELS,
|
|
206
235
|
onChange: o => {
|
|
207
236
|
if (o.mode === 'engine') { hold?.remove(); hold = null; }
|
|
208
237
|
// focus: the rig's live focus point (its target's position), so the world keeps loading around the player while the game moves the camera
|
|
@@ -216,15 +245,19 @@ export function rigModule(kind, opts) {
|
|
|
216
245
|
if (over !== was) { was = over; c.onOverride?.(over); }
|
|
217
246
|
if (applyOverride(e)) { fresh = true; return; } // not checked during takeover; re-record afterwards
|
|
218
247
|
if (!fresh) owned.check();
|
|
219
|
-
|
|
248
|
+
// a platform moved this frame (onFrame, a timeline tween before this hook): the rider goes with it first, so the rig does not read last frame's position.
|
|
249
|
+
// Here and not by moving rigs after characters: prompts, markers, bubbles and chunk culling run in between and must see this frame's camera
|
|
250
|
+
e.characters?.carryRiders?.();
|
|
251
|
+
if (owned.on) { e._poses.around(c.target, () => c.update(dt, e.input)); c.pixelSnap?.apply(); } // the rig follows what is drawn this frame; pixelSnap rounds what the rig decided, whichever rig it is
|
|
220
252
|
e.focus.copy(c.focusPoint()); // decides only where the view (terrain, models) loads; the gameplay simulation center is world.anchor (default the player), so moving the camera away changes nothing
|
|
221
253
|
owned.mark(); fresh = false;
|
|
222
254
|
},
|
|
223
255
|
describe(e, ctx) { ctx.out.camera ??= {}; ctx.out.camera.type = c.kind; if (c.current !== undefined) ctx.out.camera.shot = c.current;
|
|
224
|
-
ctx.out.camera.pointerLock = lockView(e, c.lockState); },
|
|
256
|
+
ctx.out.camera.pointerLock = lockView(e, c.lockState); if (c.pixelSnap) ctx.out.camera.pixelSnap = c.pixelSnap.describe(); },
|
|
225
257
|
// the active rig lets go of what it holds (pointer lock, a fixed rig's zone listener); engine.setCamera falls back to the core stand-in,
|
|
226
258
|
// so a rolled-back install leaves no camera function behind that drives a rig nobody owns
|
|
227
|
-
|
|
259
|
+
// a hold this rig opened on a write or a manual('camera') ends with it: the next rig has its own state, and nothing it hears could hand this hold back
|
|
260
|
+
dispose(e) { c?.onExit?.(); hold?.remove(); hold = null; dropOwned(e, [owned]); setProjection(e); setFov(e, fov0()); delete e.setCamera; RIG_OWNED.delete(e); },
|
|
228
261
|
};
|
|
229
262
|
}
|
|
230
263
|
|
|
@@ -233,3 +266,5 @@ export const CAMERA_STRINGS = {
|
|
|
233
266
|
'zh-CN': { 'camera.rotateLeft': '视角左转', 'camera.rotateRight': '视角右转' },
|
|
234
267
|
en: { 'camera.rotateLeft': 'Rotate view left', 'camera.rotateRight': 'Rotate view right' },
|
|
235
268
|
};
|
|
269
|
+
|
|
270
|
+
export const handRolled = [{ kind: 'follow', seen: 'a camera follow of its own', use: 'followCamera() or openWorld({ camera }): collision, smoothing and switching are handled; a shot of your own: engine.takeCamera(owner) (recipe 21)', quiet: /\b(?:follow|firstPerson|fixed|rts)Camera\(|\bopenWorld\(|\b(engine|e|eng|ctx)\.(takeCamera|cameraRig|setCamera)\b/, code: /\bcamera\.position\.(?:lerp|copy|set)\s*\(/, raw: /player|hero|target|character|avatar/i, near: [{ re: /\bonFrame\b|\bonRender\b|\bonFixed\b|requestAnimationFrame|\bupdate\b|\btick\b|\banimate\b/, lines: 12 }] }];
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
export default {
|
|
7
7
|
name: 'cameraRig',
|
|
8
8
|
api: ['forward', 'right', 'follow', 'focusPoint', 'screenToGround'],
|
|
9
|
+
fields: ['target'], // what follow() follows: a ragdoll checks it before borrowing the camera, and leaves a camera the game moved elsewhere
|
|
9
10
|
ops: [],
|
|
10
11
|
events: [],
|
|
11
12
|
saves: {},
|