threedog 0.7.0 → 0.8.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 +196 -1
- package/README.md +6 -9
- package/core/{Animator.js → assets/Animator.js} +28 -18
- package/core/{Assets.js → assets/Assets.js} +98 -54
- package/core/{Baked.js → assets/Baked.js} +4 -4
- package/core/assets/assetEntry.js +237 -0
- package/core/{assetHot.js → assets/assetHot.js} +7 -6
- 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} +6 -12
- package/core/{namedModel.js → assets/namedModel.js} +17 -13
- package/core/{Audio.js → audio/Audio.js} +26 -23
- 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} +10 -10
- package/core/{Random.js → base/Random.js} +5 -4
- package/core/{easing.js → base/easing.js} +1 -1
- package/core/{errorCodes.js → base/errorCodes.js} +98 -110
- package/core/{errorHints.js → base/errorHints.js} +5 -9
- package/core/{errors.js → base/errors.js} +6 -6
- package/core/{events.generated.js → base/events.generated.js} +1 -0
- package/core/{math.js → base/math.js} +15 -4
- package/core/{params.js → base/params.js} +3 -4
- package/core/base/util.js +32 -0
- package/core/{validate.js → base/validate.js} +28 -7
- package/core/{Engine.js → engine/Engine.js} +80 -77
- package/core/{Loading.js → engine/Loading.js} +4 -2
- package/core/{copies.js → engine/copies.js} +4 -4
- package/core/{headlessLoad.js → engine/headlessLoad.js} +4 -4
- package/core/{lifecycle.js → engine/lifecycle.js} +14 -12
- package/core/{loop.js → engine/loop.js} +68 -47
- package/core/{moduleSlots.js → engine/moduleSlots.js} +6 -6
- package/core/{moduleTypes.js → engine/moduleTypes.js} +13 -14
- package/core/{modules.js → engine/modules.js} +14 -11
- package/core/{page.js → engine/page.js} +36 -23
- package/core/{plugins.js → engine/plugins.js} +6 -9
- package/core/{services.js → engine/services.js} +47 -40
- package/core/{startup.js → engine/startup.js} +26 -24
- package/core/{Input.js → input/Input.js} +30 -22
- package/core/{inputContext.js → input/inputContext.js} +14 -5
- package/core/{inputPad.js → input/inputPad.js} +1 -1
- package/core/{inputPointer.js → input/inputPointer.js} +8 -2
- package/core/{inputTouch.js → input/inputTouch.js} +1 -1
- package/core/{Budget.js → inspect/Budget.js} +21 -20
- package/core/{DebugOverrides.js → inspect/DebugOverrides.js} +30 -16
- package/core/{Describe.js → inspect/Describe.js} +26 -22
- package/core/{Inspect.js → inspect/Inspect.js} +9 -7
- 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} +52 -20
- package/core/{catalog.js → inspect/catalog.js} +3 -3
- 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} +21 -20
- package/core/{describeText.js → inspect/describeText.js} +11 -6
- package/core/inspect/geometryWatch.js +38 -0
- package/core/{lightWatch.js → inspect/lightWatch.js} +8 -8
- package/core/{pictureWriters.js → inspect/pictureWriters.js} +15 -16
- package/core/{shaderCost.js → inspect/shaderCost.js} +1 -1
- package/core/{Ops.js → ops/Ops.js} +16 -11
- package/core/{control.js → ops/control.js} +13 -12
- package/core/ops/holds.js +139 -0
- package/core/{opsAtomic.js → ops/opsAtomic.js} +2 -1
- package/core/{opsCheck.js → ops/opsCheck.js} +4 -5
- package/core/{opsGuard.js → ops/opsGuard.js} +3 -3
- package/core/{opsRun.js → ops/opsRun.js} +7 -4
- package/core/{owned.js → ops/owned.js} +14 -17
- package/core/{sharedPoint.js → ops/sharedPoint.js} +8 -8
- package/core/{stackFrames.js → ops/stackFrames.js} +2 -2
- package/core/{stacks.js → ops/stacks.js} +12 -14
- package/core/{wrap.js → ops/wrap.js} +8 -6
- package/core/{SaveStore.js → saves/SaveStore.js} +1 -1
- package/core/{Saves.js → saves/Saves.js} +58 -36
- package/core/{saveApply.js → saves/saveApply.js} +13 -9
- package/core/{saveFiles.js → saves/saveFiles.js} +17 -15
- package/core/{saveValues.js → saves/saveValues.js} +20 -3
- package/core/{saveVersions.js → saves/saveVersions.js} +4 -17
- package/core/{session.js → saves/session.js} +31 -17
- package/core/{Rays.js → scene/Rays.js} +23 -25
- package/core/{Views.js → scene/Views.js} +14 -6
- package/core/{adaptive.js → scene/adaptive.js} +15 -8
- package/core/{canvasBox.js → scene/canvasBox.js} +2 -3
- package/core/{engineCamera.js → scene/engineCamera.js} +1 -1
- 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} +4 -4
- package/core/{gridLoad.js → scene/gridLoad.js} +1 -1
- package/core/{ground.js → scene/ground.js} +9 -9
- package/core/{movement.js → scene/movement.js} +3 -3
- package/core/{pictureSlots.js → scene/pictureSlots.js} +2 -2
- package/core/{sceneDelta.js → scene/sceneDelta.js} +2 -2
- package/core/{sceneMethods.js → scene/sceneMethods.js} +36 -13
- package/core/scene/stepPoses.js +55 -0
- package/core/{targeting.js → scene/targeting.js} +4 -5
- package/core/{thingExplain.js → scene/thingExplain.js} +6 -5
- package/core/{thingOps.js → scene/thingOps.js} +4 -3
- package/core/{things.js → scene/things.js} +18 -5
- package/core/{threePatches.js → scene/threePatches.js} +1 -1
- package/core/{view.js → scene/view.js} +17 -16
- package/core/{Batching.js → stream/Batching.js} +85 -27
- package/core/{Stream.js → stream/Stream.js} +60 -30
- package/core/{batchGroups.js → stream/batchGroups.js} +10 -9
- package/core/{chunkStream.js → stream/chunkStream.js} +40 -0
- package/core/{scatter.js → stream/scatter.js} +2 -2
- package/core/{streamSources.js → stream/streamSources.js} +12 -7
- package/core/{Commits.js → threads/Commits.js} +6 -5
- package/core/{Jobs.js → threads/Jobs.js} +12 -10
- package/core/{Threads.js → threads/Threads.js} +16 -16
- 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} +17 -10
- package/core/{dayTime.js → time/dayTime.js} +5 -1
- package/core/{skip.js → time/skip.js} +18 -17
- package/core/{time.js → time/time.js} +18 -12
- package/core/{uiClock.js → time/uiClock.js} +4 -4
- package/docs/AI.md +22 -19
- package/docs/API.md +24 -23
- package/docs/CODEMAP.md +76 -183
- package/docs/COMMANDS.md +66 -58
- package/docs/CONVENTIONS.md +54 -14
- package/docs/MIGRATING-0.8.md +169 -0
- package/docs/THREE.md +78 -29
- 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 +29 -29
- package/docs/api/characters.md +23 -18
- package/docs/api/clock.md +1 -1
- package/docs/api/collision.md +12 -9
- package/docs/api/content.md +6 -6
- package/docs/api/dialogue.md +3 -3
- package/docs/api/engine.md +45 -43
- package/docs/api/events.md +3 -2
- package/docs/api/flow.md +1 -1
- package/docs/api/grids.md +1 -1
- package/docs/api/ground.md +4 -5
- package/docs/api/hud.md +2 -2
- package/docs/api/i18n.md +6 -6
- package/docs/api/input.md +7 -7
- package/docs/api/interactions.md +4 -4
- package/docs/api/inventory.md +9 -9
- package/docs/api/jobs.md +5 -5
- package/docs/api/level.md +7 -7
- package/docs/api/lightPool.md +1 -6
- package/docs/api/music.md +3 -3
- package/docs/api/nav.md +10 -10
- package/docs/api/openWorld.md +1 -1
- package/docs/api/particles.md +2 -2
- package/docs/api/photo.md +4 -2
- package/docs/api/pickups.md +2 -2
- package/docs/api/post.md +20 -3
- package/docs/api/quests.md +3 -3
- package/docs/api/rays.md +5 -7
- package/docs/api/rigid.md +27 -18
- package/docs/api/saves.md +8 -7
- package/docs/api/settings.md +9 -8
- package/docs/api/sky.md +8 -7
- package/docs/api/stream.md +7 -7
- package/docs/api/swarm.md +34 -0
- package/docs/api/terrain.md +7 -8
- package/docs/api/terrainDraw.md +1 -1
- package/docs/api/timeline.md +2 -2
- package/docs/api/tools.md +25 -22
- package/docs/api/vars.md +1 -1
- package/docs/api/vegetation.md +4 -3
- package/docs/api/vegetationDraw.md +1 -1
- package/docs/api/water.md +1 -1
- package/docs/api/weather.md +9 -9
- package/docs/api/weatherDraw.md +3 -3
- package/docs/api/world.md +5 -5
- package/docs/recipes/01-new-game.md +25 -40
- package/docs/recipes/02-npc.md +19 -20
- package/docs/recipes/03-items-pickups.md +27 -43
- package/docs/recipes/04-quests.md +3 -4
- package/docs/recipes/05-props-bake.md +29 -39
- package/docs/recipes/06-clock-events.md +27 -18
- package/docs/recipes/07-flow-scenes-pause.md +12 -17
- package/docs/recipes/08-weather-sky.md +88 -34
- package/docs/recipes/09-materials-lights-models.md +22 -36
- package/docs/recipes/10-blender-level.md +6 -7
- package/docs/recipes/11-vehicles.md +30 -22
- package/docs/recipes/12-navmesh.md +9 -8
- package/docs/recipes/13-animation.md +39 -17
- package/docs/recipes/14-custom-module.md +14 -13
- package/docs/recipes/15-perf.md +49 -26
- package/docs/recipes/16-dev-bridge.md +32 -52
- package/docs/recipes/18-world.md +36 -23
- package/docs/recipes/19-shooting-picking.md +4 -2
- package/docs/recipes/20-content-actions-save.md +30 -35
- package/docs/recipes/21-camera.md +33 -5
- package/docs/recipes/22-shop-gold.md +0 -4
- package/docs/recipes/23-ops.md +10 -10
- package/docs/recipes/26-ui-parts.md +22 -12
- package/docs/recipes/27-net.md +0 -2
- package/docs/recipes/28-terrain.md +117 -21
- package/docs/recipes/29-grid.md +2 -2
- package/docs/recipes/30-templates.md +55 -19
- package/docs/recipes/31-audio.md +5 -5
- package/docs/recipes/32-action-game.md +15 -6
- package/docs/recipes/33-stream-sources.md +2 -2
- package/docs/recipes/34-environment-lighting.md +67 -19
- package/docs/recipes/35-picture-from-reference.md +10 -17
- package/docs/recipes/36-ground-plants.md +105 -0
- package/docs/recipes/40-scene.md +7 -11
- package/docs/recipes/43-shader-patches-surfaces.md +20 -41
- package/docs/recipes/44-water-weather-hooks.md +48 -43
- package/docs/recipes/45-cascaded-shadows.md +39 -17
- package/docs/recipes/46-blender-art-route.md +7 -8
- package/docs/recipes/49-game-module-contract.md +5 -5
- package/docs/recipes/50-own-renderer.md +2 -2
- package/docs/recipes/52-around-the-picture.md +54 -98
- package/docs/recipes/53-ground-up-close.md +61 -24
- package/docs/recipes/55-mods-time-wrap.md +12 -16
- package/docs/recipes/56-webgpu-tsl.md +16 -14
- package/docs/recipes/57-control.md +9 -2
- package/docs/recipes/58-input.md +2 -2
- package/docs/recipes/59-depth-post-effects.md +1 -1
- package/docs/recipes/60-judge-the-picture.md +29 -24
- package/docs/recipes/62-picture-code.md +49 -17
- package/docs/recipes/63-third-person-start.md +17 -4
- package/docs/recipes/64-particles.md +1 -1
- package/docs/recipes/65-swarm.md +140 -0
- package/examples/action/.threedog/content-index.json +1 -1
- package/examples/action/GAMEMAP.md +2 -2
- package/examples/{sheepisland → perf-island}/.threedog/content-index.json +1 -1
- package/examples/{sheepisland → perf-island}/GAMEMAP.md +12 -11
- 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 +1 -0
- package/examples/rc2d/GAMEMAP.md +3 -2
- package/examples/rc2d/main.js +1 -3
- package/examples/styletest/.threedog/content-index.json +1 -1
- package/examples/styletest/GAMEMAP.md +3 -2
- 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 +1 -0
- package/examples/world/.threedog/content-index.json +1 -1
- package/examples/world/GAMEMAP.md +4 -3
- package/examples/world/picture/sky.js +1 -1
- package/index.d.ts +8 -7
- package/index.js +31 -31
- package/llms.txt +9 -13
- package/modules/ambience/Ambience.js +11 -8
- package/modules/calendar/Calendar.js +19 -19
- package/modules/calendar/index.js +13 -13
- package/modules/calendar/schedule.js +11 -6
- package/modules/calendar/seasons.js +7 -7
- package/modules/camera/FirstPersonCamera.js +2 -2
- package/modules/camera/FixedCamera.js +14 -15
- package/modules/camera/FollowCamera.js +4 -4
- package/modules/camera/RtsCamera.js +11 -11
- package/modules/camera/common.js +48 -24
- package/modules/camera/contract.js +1 -0
- package/modules/camera/projection.js +2 -2
- package/modules/characters/Character.js +33 -30
- package/modules/characters/NPC.js +27 -19
- package/modules/characters/assetModel.js +14 -10
- package/modules/characters/astar.js +7 -5
- package/modules/characters/behaviors.js +4 -5
- package/modules/characters/contract.js +2 -2
- package/modules/characters/index.js +168 -214
- package/modules/characters/moveHelpers.js +14 -3
- package/modules/characters/movers/common.js +16 -14
- package/modules/characters/movers/manual.js +1 -1
- package/modules/characters/movers/rapier.js +7 -6
- package/modules/characters/movers/simple.js +3 -3
- package/modules/characters/movers/support.js +8 -8
- package/modules/characters/npcAvoid.js +4 -4
- package/modules/characters/npcSim.js +23 -17
- package/modules/characters/npcView.js +6 -5
- package/modules/characters/pathAsync.js +12 -10
- package/modules/characters/pathWorker.js +1 -1
- package/modules/characters/player.js +108 -0
- package/modules/characters/playerStrings.js +2 -2
- package/modules/characters/proceduralRig.js +2 -2
- package/modules/characters/useModel.js +3 -3
- package/modules/characters/walkTo.js +11 -17
- package/modules/collision/Collision.js +26 -20
- package/modules/collision/contract.js +15 -0
- package/modules/content/explain.js +1 -2
- package/modules/content/fields.js +24 -3
- package/modules/content/ids.js +2 -2
- package/modules/content/index.js +61 -99
- package/modules/content/loader.js +14 -17
- package/modules/content/markers.js +25 -0
- package/modules/content/models.js +10 -7
- package/modules/content/packs.js +3 -3
- package/modules/content/parts.js +2 -2
- package/modules/content/places.js +35 -0
- package/modules/content/props.js +17 -14
- package/modules/content/rules.js +25 -21
- package/modules/content/stages.js +7 -7
- package/modules/content/templates.js +20 -20
- package/modules/content/words.js +34 -0
- package/modules/debug/DebugPanel.js +10 -43
- package/modules/flow/contract.js +1 -1
- package/modules/flow/index.js +11 -7
- package/modules/gameplay/Container.js +12 -11
- package/modules/gameplay/Containers.js +14 -5
- package/modules/gameplay/Dialogue.js +13 -11
- package/modules/gameplay/Interactions.js +37 -24
- package/modules/gameplay/Inventory.js +8 -9
- package/modules/gameplay/Quests.js +16 -9
- package/modules/gameplay/boxOps.js +1 -1
- package/modules/gameplay/dialogueBubbles.js +3 -4
- package/modules/gameplay/inventoryOps.js +0 -1
- package/modules/gameplay/pickups.js +22 -23
- package/modules/gameplay/questSave.js +3 -3
- package/modules/grid/Grid.js +1 -1
- package/modules/grid/Layer.js +4 -4
- package/modules/grid/index.js +7 -8
- package/modules/grid/preview.js +7 -7
- package/modules/grid/tiles.js +6 -6
- package/modules/hlod/index.js +37 -55
- package/modules/hud/index.js +17 -11
- package/modules/hud/parts.js +4 -4
- package/modules/level/contract.js +16 -0
- package/modules/level/heightfield.js +12 -10
- package/modules/level/index.js +47 -152
- package/modules/level/load.js +79 -0
- package/modules/level/meshes.js +65 -0
- package/modules/level/nodes.js +6 -7
- package/modules/lights/index.js +28 -181
- package/modules/lights/slots.js +93 -0
- package/modules/lights/sources.js +88 -0
- package/modules/music/Music.js +30 -26
- package/modules/music/rules.js +1 -1
- package/modules/nav/contract.js +14 -0
- package/modules/nav/index.js +11 -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 +5 -4
- package/modules/net/sync.js +2 -2
- package/modules/net/transports.js +2 -2
- package/modules/particles/Particles.js +11 -8
- package/modules/particles/effect.js +7 -5
- package/modules/particles/shaders.js +2 -1
- package/modules/photo/Photo.js +15 -17
- package/modules/rigid/RigidBodies.js +66 -43
- package/modules/rigid/Vehicles.js +2 -3
- package/modules/rigid/ragdoll.js +287 -0
- package/modules/rigid/ragdollBones.js +159 -0
- package/modules/rigid/sync.js +6 -6
- package/modules/settings/Settings.js +108 -39
- package/modules/settings/apply.js +6 -6
- package/modules/settings/sections.js +16 -14
- 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 +14 -27
- package/modules/sky/tint.js +1 -1
- package/modules/swarm/Swarm.js +346 -0
- package/modules/swarm/draw.js +68 -0
- package/modules/swarm/grid.js +63 -0
- package/modules/terrain/ChunkManager.js +70 -52
- 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 +28 -34
- package/modules/terrain/terrainColorMap.js +6 -3
- package/modules/terrain/terrainDefaults.js +2 -1
- package/modules/terrain/terrainEdit.js +32 -27
- package/modules/terrain/terrainGen.js +17 -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 +27 -19
- package/modules/timeline/Tween.js +6 -6
- package/modules/timeline/shots.js +5 -7
- package/modules/triggers/index.js +9 -9
- package/modules/vegetation/Vegetation.js +30 -23
- package/modules/vegetation/densityMap.js +4 -7
- package/modules/vegetation/draw.js +23 -18
- package/modules/vegetation/groundChunks.js +11 -31
- package/modules/vegetation/index.js +8 -6
- package/modules/vegetation/modelGeometry.js +3 -6
- package/modules/vegetation/nearFade.js +1 -1
- package/modules/water/Water.js +16 -16
- package/modules/water/surface.js +3 -3
- package/modules/weather/Weather.js +41 -30
- package/modules/weather/particles.js +8 -8
- package/modules/weather/weatherDraw.js +22 -18
- package/modules/world/World.js +8 -8
- package/modules/world/explain.js +1 -1
- package/modules/world/index.js +18 -12
- package/modules/world/persist.js +73 -25
- package/modules/world/pos.js +4 -4
- package/modules/world/records.js +28 -8
- package/modules/world/sim.js +4 -4
- package/modules/world/state.js +12 -5
- package/modules/world/thingSource.js +4 -2
- package/modules/world/views.js +11 -9
- package/package.json +42 -7
- package/presets.js +1 -3
- package/render/PostFX.js +39 -27
- package/render/backend.js +26 -32
- 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/patchNodes.tsl.js +5 -15
- package/render/fx/postWebGPU.tsl.js +27 -23
- 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 +1 -1
- package/render/lighting.js +5 -3
- package/render/lightmap.js +20 -20
- 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 +20 -4
- package/render/ownFrame.js +4 -4
- package/render/patches.js +13 -13
- package/render/postWebGL.js +12 -10
- package/render/probes.js +16 -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 +57 -11
- package/render/slots.js +7 -7
- package/render/terms.js +22 -24
- package/render/uniformDecl.js +1 -1
- package/types/core.d.ts +200 -153
- package/types/gameplay.d.ts +163 -91
- 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} +7 -15
- 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} +12 -8
- package/types/generated/core/{Budget.d.ts → inspect/Budget.d.ts} +36 -26
- package/types/generated/core/{DebugOverrides.d.ts → inspect/DebugOverrides.d.ts} +2 -2
- package/types/generated/core/{Ops.d.ts → ops/Ops.d.ts} +4 -3
- package/types/generated/core/{control.d.ts → ops/control.d.ts} +4 -10
- package/types/generated/core/{Saves.d.ts → saves/Saves.d.ts} +37 -13
- package/types/generated/core/{session.d.ts → saves/session.d.ts} +2 -1
- package/types/generated/core/{Rays.d.ts → scene/Rays.d.ts} +8 -27
- package/types/generated/core/{Views.d.ts → scene/Views.d.ts} +1 -1
- package/types/generated/core/{Batching.d.ts → stream/Batching.d.ts} +7 -7
- package/types/generated/core/{Stream.d.ts → stream/Stream.d.ts} +18 -16
- 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/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 +1 -1
- 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 +2 -1
- package/types/generated/modules/water/Water.d.ts +1 -0
- package/types/generated/modules/weather/Weather.d.ts +16 -12
- package/types/generated/modules/weather/weatherDraw.d.ts +3 -3
- package/types/generated/modules/world/World.d.ts +5 -3
- package/types/generated/render/PostFX.d.ts +17 -11
- 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 +11 -11
- package/types/physics.d.ts +99 -70
- package/types/tsl.d.ts +37 -4
- package/types/world.d.ts +38 -71
- package/ui/Focus.js +10 -9
- package/ui/Parts.js +4 -3
- package/ui/UI.js +7 -7
- package/ui/defaults.js +3 -2
- package/ui/theme.js +5 -3
- package/core/assetEntry.js +0 -109
- package/core/holds.js +0 -134
- package/core/shadowTypes.js +0 -16
- package/core/util.js +0 -17
- 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/core/{Vars.js → base/Vars.js} +0 -0
- /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/{opsFail.js → ops/opsFail.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/{tier.js → scene/tier.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
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
import * as THREE from 'three';
|
|
13
13
|
import { rigModule, defineRig, YAW_RIG, HIDE_RIG, clickToLock, releaseLock } from './common.js';
|
|
14
14
|
import { setProjection } from './projection.js';
|
|
15
|
-
import { codedError } from '../../core/errorHints.js';
|
|
15
|
+
import { codedError } from '../../core/base/errorHints.js';
|
|
16
|
+
import { wrapAngle } from '../../core/base/math.js';
|
|
16
17
|
|
|
17
18
|
const GROUND = ['raise', 'shorten', 'none'];
|
|
18
19
|
// 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,
|
|
@@ -53,7 +54,7 @@ export class FollowCamera {
|
|
|
53
54
|
/**
|
|
54
55
|
* 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
56
|
* 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.
|
|
57
|
+
* @example engine.cameraRig.frame(enemy.root); player.faceMode = 'target'; player.faceTarget = enemy.root;
|
|
57
58
|
*/
|
|
58
59
|
frame(target, { strength = 6 } = {}) { this.framing = target ? { target, strength } : null; }
|
|
59
60
|
/**
|
|
@@ -80,8 +81,7 @@ export class FollowCamera {
|
|
|
80
81
|
const cam = this.engine.camera, fr = this.framing;
|
|
81
82
|
if (fr && this.target) {
|
|
82
83
|
const t = fr.target.position ?? fr.target, p = this.target.position;
|
|
83
|
-
|
|
84
|
-
this.yaw += d * Math.min(1, dt * fr.strength);
|
|
84
|
+
this.yaw += wrapAngle(Math.atan2(p.x - t.x, p.z - t.z) - this.yaw) * Math.min(1, dt * fr.strength);
|
|
85
85
|
}
|
|
86
86
|
if (input.enabled && this.mouseLook !== false) {
|
|
87
87
|
if (!fr) this.yaw -= input.look.dx * 0.005 * this.sensitivity;
|
|
@@ -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(); } }
|
|
@@ -104,7 +104,7 @@ export class RtsCamera {
|
|
|
104
104
|
const cam = this.engine.camera, f = this._f;
|
|
105
105
|
const g = this.engine.surface(f.x, f.z);
|
|
106
106
|
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.
|
|
107
|
+
const a = Math.min(Math.PI / 2 - 1e-3, Math.max(0.05, this.pitch));
|
|
108
108
|
const back = this._h / Math.tan(a); // horizontal back-off distance
|
|
109
109
|
cam.position.set(f.x + Math.sin(this._yaw) * back, f.y + this._h, f.z + Math.cos(this._yaw) * back);
|
|
110
110
|
cam.lookAt(f);
|
|
@@ -117,7 +117,7 @@ for (const k of ['forward', 'right']) RtsCamera.prototype[k] = YAW_RIG[k];
|
|
|
117
117
|
|
|
118
118
|
/**
|
|
119
119
|
* Strategy top-down camera module. Installs engine.cameraRig (pick it or followCamera).
|
|
120
|
-
* rtsCamera({ height: 30,
|
|
120
|
+
* rtsCamera({ height: 30, pitch: 0.95, panSpeed: 1, edgePan: true, bounds }) + createEngine({ bindings: { ...presets.bindings.rtsRotate } })
|
|
121
121
|
* Actions: rotateLeft / rotateRight (no keys of their own)
|
|
122
122
|
*/
|
|
123
123
|
export function rtsCamera(opts = {}) { return rigModule('rts', opts); }
|
|
@@ -129,5 +129,5 @@ defineRig('rts', (e, opts, input) => {
|
|
|
129
129
|
input.action('rotateRight', { label: 'camera.rotateRight', optional: true });
|
|
130
130
|
}
|
|
131
131
|
return new RtsCamera(e, opts);
|
|
132
|
-
}, ['height', 'minHeight', 'maxHeight', '
|
|
132
|
+
}, ['height', 'minHeight', 'maxHeight', 'pitch', 'yaw', 'panSpeed', 'dragPan', 'edgePan', 'edgeSize', 'bounds', 'rotate',
|
|
133
133
|
'rotateSpeed', 'zoomStep', 'smoothing', 'fov', 'followLock', 'start']);
|
package/modules/camera/common.js
CHANGED
|
@@ -9,20 +9,20 @@
|
|
|
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
15
|
// When the last holder removes its claim the camera module resumes from its previous state. cameraOverride itself is read-only.
|
|
16
16
|
import * as THREE from 'three';
|
|
17
|
-
import { defineOwned } from '../../core/owned.js';
|
|
18
|
-
import { readParams, keysSchema } from '../../core/params.js';
|
|
17
|
+
import { defineOwned } from '../../core/ops/owned.js';
|
|
18
|
+
import { readParams, keysSchema } from '../../core/base/params.js';
|
|
19
19
|
import { setProjection } from './projection.js';
|
|
20
|
-
import { setFov } from '../../core/view.js';
|
|
21
|
-
import { codedError } from '../../core/errorHints.js';
|
|
20
|
+
import { setFov } from '../../core/scene/view.js';
|
|
21
|
+
import { codedError } from '../../core/base/errorHints.js';
|
|
22
22
|
|
|
23
|
-
// the takeover calls the owned-camera warning quotes (core/owned.js): takeCamera is the one explicit entry (its remove() gives the camera back);
|
|
23
|
+
// 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
24
|
// 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.
|
|
25
|
+
const LEVELS = { manual: "const cam = engine.takeCamera('me') (cam.remove() gives it back)", back: "engine.autoView.manual('camera', false)" };
|
|
26
26
|
|
|
27
27
|
/** True during a cutscene takeover, and updates engine.focus from the focus the owner supplied */
|
|
28
28
|
function applyOverride(e) {
|
|
@@ -61,7 +61,7 @@ export const HIDE_RIG = {
|
|
|
61
61
|
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
62
|
});
|
|
63
63
|
},
|
|
64
|
-
_unhide() { for (const [o, mask] of this._hidden) o.layers.mask = mask; this._hidden =
|
|
64
|
+
_unhide() { for (const [o, mask] of this._hidden) o.layers.mask = mask; this._hidden.length = 0; }, // follow calls it every frame
|
|
65
65
|
// Lights present now (the sky module has built them by onEnter); a light added later calls shadow.camera.layers.enable(hideLayer) itself
|
|
66
66
|
_shadowLayers() { this.engine.scene.traverse(o => { if (o.isLight && o.shadow?.camera) o.shadow.camera.layers.enable(this.hideLayer); }); },
|
|
67
67
|
};
|
|
@@ -87,7 +87,8 @@ export function clickToLock(rig, switched) {
|
|
|
87
87
|
};
|
|
88
88
|
rig._off = new AbortController();
|
|
89
89
|
const sig = { signal: AbortSignal.any([e.signal, rig._off.signal]) };
|
|
90
|
-
|
|
90
|
+
const change = e.events.on('page:pointerlock', ({ locked }) => { st.locked = locked; if (locked) st.lastError = null; else st.requested = false; });
|
|
91
|
+
sig.signal.addEventListener('abort', change.remove);
|
|
91
92
|
document.addEventListener('pointerlockerror', () => fail('pointerlockerror (browser refused: needs a user gesture, or the page lost focus)'), sig);
|
|
92
93
|
const swallow = () => rig.swallowLockClick !== false && wouldLock();
|
|
93
94
|
e.input.swallowLockClick = swallow; rig._swallow = swallow;
|
|
@@ -101,11 +102,11 @@ export function clickToLock(rig, switched) {
|
|
|
101
102
|
*/
|
|
102
103
|
function lockView(e, st) {
|
|
103
104
|
if (!st?.configured) return { state: 'off' };
|
|
104
|
-
const state = !st.
|
|
105
|
+
const state = !st.supported ? 'unsupported' : st.locked ? 'locked' : st.lastError ? 'refused' : st.requested ? 'requesting' : 'waiting-click';
|
|
105
106
|
const c = e.renderer.domElement, r = c.getBoundingClientRect();
|
|
106
107
|
const top = typeof document.elementFromPoint === 'function' ? document.elementFromPoint(r.left + r.width / 2, r.top + r.height / 2) : null;
|
|
107
108
|
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
|
|
109
|
+
cameraOverride: e.cameraOverride?.owner ?? null, lastFailure: st.lastError ? { reason: st.lastError, agoSec: Math.round((e.time.now('real') - st.failedAt) / 100) / 10 } : null };
|
|
109
110
|
}
|
|
110
111
|
/** Release the mouse lock; stop listening for clicks too when switched away (call from onExit; from onOverride with keepListening) */
|
|
111
112
|
export function releaseLock(rig, keepListening = false) {
|
|
@@ -122,11 +123,12 @@ export function viewForward(camera, fallback) {
|
|
|
122
123
|
return planar(_v, fallback);
|
|
123
124
|
}
|
|
124
125
|
|
|
125
|
-
|
|
126
|
+
import { screenToGround } from '../../core/scene/screenToGround.js'; // shared with grid placement and click-to-move; lives in core
|
|
127
|
+
export { screenToGround };
|
|
126
128
|
|
|
127
129
|
/**
|
|
128
130
|
* 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
|
|
131
|
+
* 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
132
|
* method that writes the pose (their _place), instead of the module wrapping every rig method with a pose compare (that ran on every
|
|
131
133
|
* forward() / right() read, several times per fixed step).
|
|
132
134
|
* @internal
|
|
@@ -148,8 +150,9 @@ export function defineRig(kind, build, keys = []) { RIGS.set(kind, build); RIG_P
|
|
|
148
150
|
* kind: 'follow' | 'firstPerson' | 'fixed' | 'rts', reported in describe()
|
|
149
151
|
*/
|
|
150
152
|
export function rigModule(kind, opts) {
|
|
151
|
-
let c = null, was = false, owned = null, fresh = true, engine = null, fov0 = 50;
|
|
153
|
+
let c = null, home = null, was = false, owned = null, fresh = true, engine = null, fov0 = 50; // home: the rig install built; every new playthrough goes back to this same object
|
|
152
154
|
const cache = new Map(); // kind -> camera instance: params like distance and pitch survive switching away and back
|
|
155
|
+
const builtWith = new WeakMap(); // rig -> the options it was built with
|
|
153
156
|
let modInput = null; const declared = new Set();
|
|
154
157
|
const input = { action: (n, o) => { if (!declared.has(n)) { declared.add(n); modInput.action(n, o); } } };
|
|
155
158
|
const make = (k, o) => {
|
|
@@ -157,7 +160,7 @@ export function rigModule(kind, opts) {
|
|
|
157
160
|
if (!build) throw codedError('camera-kind', `setCamera() has no camera kind '${k}'; available: ${[...RIGS.keys()].join(', ')}`);
|
|
158
161
|
readParams(`${k}Camera`, RIG_PARAMS.get(k), o); // also covers setCamera(kind, options)
|
|
159
162
|
const r = build(engine, o ?? {}, input);
|
|
160
|
-
r.kind = k; cache.set(k, r);
|
|
163
|
+
r.kind = k; cache.set(k, r); builtWith.set(r, o);
|
|
161
164
|
// every kind answers the contract's screenToGround (click-to-move and placement work under any camera, not only the strategy one)
|
|
162
165
|
if (typeof r.screenToGround !== 'function') r.screenToGround = (x, y) => screenToGround(engine, x, y);
|
|
163
166
|
return r;
|
|
@@ -168,8 +171,12 @@ export function rigModule(kind, opts) {
|
|
|
168
171
|
old.onExit?.();
|
|
169
172
|
setProjection(engine.camera); // back to perspective; an orthographic rig sets its own in onEnter / constructor
|
|
170
173
|
setFov(engine, fov0); // fov returns to the value at install; each camera applies its own in onEnter / constructor
|
|
171
|
-
|
|
174
|
+
let next;
|
|
175
|
+
// a bad kind or option throws here: the old rig goes back on, or the game keeps a rig that let go of its target and of the mouse
|
|
176
|
+
try { next = o || !cache.has(k) ? make(k, o) : cache.get(k); } catch (err) { old.onEnter?.(false); old.follow(target ?? null); throw err; }
|
|
172
177
|
c = engine.cameraRig = next;
|
|
178
|
+
// 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
|
|
179
|
+
if (!engine.session.playing) { home = next; kind = k; opts = builtWith.get(next); }
|
|
173
180
|
next.onEnter?.(true);
|
|
174
181
|
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
182
|
next.follow(target ?? null);
|
|
@@ -178,27 +185,41 @@ export function rigModule(kind, opts) {
|
|
|
178
185
|
return c;
|
|
179
186
|
}
|
|
180
187
|
return {
|
|
181
|
-
name: 'cameraRig', type: 'picture', label: 'Camera', params: RIG_PARAMS.get(kind), options: opts, optional: ['collision'], stage: 'control',
|
|
188
|
+
name: 'cameraRig', type: 'picture', provides: ['cameraRig'], label: 'Camera', params: RIG_PARAMS.get(kind), options: opts, optional: ['collision', 'characters'], stage: 'control',
|
|
182
189
|
install(e, ctx) { e.i18n.add({ 'zh-CN': { 'module.cameraRig': '相机' }, en: { 'module.cameraRig': 'camera' } });
|
|
183
190
|
engine = e; fov0 = e.camera.fov; modInput = ctx.input; declared.clear();
|
|
184
191
|
e.setCamera = setCamera;
|
|
185
|
-
c = make(kind, opts);
|
|
192
|
+
c = home = make(kind, opts);
|
|
186
193
|
c.onEnter?.(false);
|
|
187
|
-
//
|
|
194
|
+
// 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
|
|
195
|
+
// 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
|
|
196
|
+
e.saves.register('cameraRig', {
|
|
197
|
+
save: () => ({ kind: c.kind, yaw: c.yaw, pitch: c.pitch }),
|
|
198
|
+
load: d => {
|
|
199
|
+
const r = d.kind === c.kind ? c : home;
|
|
200
|
+
if (r.yaw !== undefined && Number.isFinite(d.yaw)) r.yaw = d.yaw;
|
|
201
|
+
if (r.pitch !== undefined && r.kind === d.kind && Number.isFinite(d.pitch)) r.pitch = d.pitch;
|
|
202
|
+
},
|
|
203
|
+
});
|
|
204
|
+
// 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.
|
|
205
|
+
// 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
206
|
ctx.track(e.events.on('session:start', () => {
|
|
189
|
-
const old = c;
|
|
207
|
+
const old = c, { yaw, pitch } = home;
|
|
190
208
|
old.onExit?.(); cache.clear();
|
|
191
209
|
setProjection(e.camera);
|
|
192
210
|
setFov(e, fov0);
|
|
193
|
-
|
|
211
|
+
const built = make(kind, opts);
|
|
212
|
+
for (const k of Object.keys(home)) delete home[k];
|
|
213
|
+
c = e.cameraRig = Object.assign(home, built, yaw !== undefined && { yaw, pitch });
|
|
214
|
+
cache.set(kind, home);
|
|
194
215
|
c.onEnter?.(false); c.follow(e.player?.cameraFollow ? e.player.root : null); fresh = true; // follows the player only if the game asked (createPlayer({ cameraFollow }))
|
|
195
|
-
e.events.emit('camera:change', { kind, previous: old.kind }); // settings re-apply the player's sensitivity / fov to the
|
|
216
|
+
e.events.emit('camera:change', { kind, previous: old.kind }); // settings re-apply the player's sensitivity / fov to the rebuilt rig
|
|
196
217
|
}));
|
|
197
218
|
// 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
219
|
ctx.track(e.events.on('state:placed', () => { if (c.target) { c.follow(c.target); fresh = true; } }));
|
|
199
220
|
// The camera module places position / orientation every frame: a game that moves the camera directly takes it (the rig stops), warned once
|
|
200
221
|
const cam = e.camera, p = cam.position, q = cam.quaternion;
|
|
201
|
-
// One camera state: takeCamera's 'camera' stack. engine.
|
|
222
|
+
// One camera state: takeCamera's 'camera' stack. engine.autoView.manual('camera') and a direct write become a takeCamera hold too (owner
|
|
202
223
|
// 'manual:<who>' / 'three'), so cameraOverride, describe().holds and the rig's onOverride see every takeover the same way; handing back
|
|
203
224
|
// (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
225
|
let hold = null;
|
|
@@ -216,7 +237,10 @@ export function rigModule(kind, opts) {
|
|
|
216
237
|
if (over !== was) { was = over; c.onOverride?.(over); }
|
|
217
238
|
if (applyOverride(e)) { fresh = true; return; } // not checked during takeover; re-record afterwards
|
|
218
239
|
if (!fresh) owned.check();
|
|
219
|
-
|
|
240
|
+
// 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.
|
|
241
|
+
// Here and not by moving rigs after characters: prompts, markers, bubbles and chunk culling run in between and must see this frame's camera
|
|
242
|
+
e.characters?.carryRiders?.();
|
|
243
|
+
if (owned.on) e._poses.around(c.target, () => c.update(dt, e.input)); // the rig follows what is drawn this frame
|
|
220
244
|
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
245
|
owned.mark(); fresh = false;
|
|
222
246
|
},
|
|
@@ -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: {},
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { codedError } from '../../core/errorHints.js';
|
|
2
|
-
// Orthographic projection for engine.camera, without replacing the camera object: engine.camera is an EngineCamera (core/engineCamera.js), whose
|
|
1
|
+
import { codedError } from '../../core/base/errorHints.js';
|
|
2
|
+
// Orthographic projection for engine.camera, without replacing the camera object: engine.camera is an EngineCamera (core/scene/engineCamera.js), whose
|
|
3
3
|
// own updateProjectionMatrix draws orthographic while orthoSize is set. Nothing is patched on the instance; describe().camera.projection reports it.
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -8,11 +8,10 @@
|
|
|
8
8
|
// Radius and step height default to engine.movement (the single source of "can walk through" parameters); passing radius / stepHeight overrides it for this character only.
|
|
9
9
|
// How to walk is decided by the mover (movers/: 'simple' default, 'rapier' character controller); feel parameters are identical for both.
|
|
10
10
|
// The procedural body (capsule, rig read from a model asset, limb swing) is in proceduralRig.js; loading a body by asset name in assetModel.js.
|
|
11
|
-
import { engineOwned } from '../../core/things.js';
|
|
12
11
|
import * as THREE from 'three';
|
|
13
|
-
import { xzOf, yOf } from '../../core/math.js';
|
|
14
|
-
import { warnOnce, warnMissing, DEV } from '../../core/validate.js';
|
|
15
|
-
import { reportError } from '../../core/errors.js';
|
|
12
|
+
import { xzOf, yOf } from '../../core/base/math.js';
|
|
13
|
+
import { warnOnce, warnMissing, DEV, fmt } from '../../core/base/validate.js';
|
|
14
|
+
import { reportError } from '../../core/base/errors.js';
|
|
16
15
|
import { simpleMover } from './movers/simple.js';
|
|
17
16
|
import { rapierMover } from './movers/rapier.js';
|
|
18
17
|
import { manualMover } from './movers/manual.js';
|
|
@@ -22,8 +21,11 @@ import { loadAssetModel, buildNow } from './assetModel.js';
|
|
|
22
21
|
import { NO_CHARACTER, capsule, useRig, animateRig, rigFromObject, tintParts } from './proceduralRig.js';
|
|
23
22
|
import { walkTo } from './walkTo.js';
|
|
24
23
|
import { useModel } from './useModel.js';
|
|
25
|
-
import { codedError, coded } from '../../core/errorHints.js';
|
|
24
|
+
import { codedError, coded } from '../../core/base/errorHints.js';
|
|
25
|
+
import { isModelName } from '../../core/base/util.js';
|
|
26
26
|
|
|
27
|
+
// A record whose jump / safe is the wrong kind of thing (a damaged or hand-edited save) is repaired so the game keeps running, but said out loud once: bad data is reported, not quietly fixed
|
|
28
|
+
function badField(v, name, want) { if (v != null) warnOnce(`[threedog] character motion: the world record's '${name}' is ${JSON.stringify(v)} but should be ${want}; it was replaced with a fresh one. Check the save or the code that writes the record`); return undefined; }
|
|
27
29
|
const STRINGS = { noClip: 'character has no skeletal animation; playAction(\'{name}\') skipped (the model needs this action)' };
|
|
28
30
|
const MOVERS = { simple: simpleMover, rapier: rapierMover, manual: manualMover };
|
|
29
31
|
|
|
@@ -35,7 +37,7 @@ const FACE_MODES = ['move', 'camera', 'target', 'manual'];
|
|
|
35
37
|
export class Character {
|
|
36
38
|
/**
|
|
37
39
|
* @param engine
|
|
38
|
-
* @param o model: the body, one path for all: a model asset name (a procedural builder from an asset pack, or a GLB name), or what
|
|
40
|
+
* @param o model: the body, one path for all: a model asset name (a procedural builder from an asset pack, or a GLB name), [name, ...args] for a generator, or what
|
|
39
41
|
* engine.assets.model() returned; without model and rig a gray capsule (warned once). rig: a ready body (proceduralRig.js format)
|
|
40
42
|
* colors: { body, skin, legs, hair } per-character part colors (meshes marked userData.part; a capsule takes colors.body)
|
|
41
43
|
* speed walk speed, runSpeed run speed (m/s), radius collision radius
|
|
@@ -54,7 +56,7 @@ export class Character {
|
|
|
54
56
|
* the character goes back to safeGround. false (default) = off
|
|
55
57
|
* channel: the time channel its movement and animation follow when the engine drives it (player 'player', others 'world')
|
|
56
58
|
* model + clips: optional glTF model and action-name map { idle, walk, run, swim, jump, fall, drive } (shorthand for animation)
|
|
57
|
-
* animation: animation state machine config (see core/Animator.js), state names are character state names;
|
|
59
|
+
* animation: animation state machine config (see core/assets/Animator.js), state names are character state names;
|
|
58
60
|
* without walk/run, move (blend tree, param speed) is used
|
|
59
61
|
* mover: 'simple' (default) | 'rapier' (Rapier character controller, needs the rigid module) | 'manual' (the game writes the position;
|
|
60
62
|
* move() only updates grounded / support / safeGround / fall, movers/manual.js); assign at any time: player.mover = 'manual'
|
|
@@ -67,7 +69,7 @@ export class Character {
|
|
|
67
69
|
turnSpeed = 10, acceleration = 12, gravity = -24, jumpSpeed = 8, stepHeight = engine.movement.stepHeight, airControl = 0.35, coyoteTime = 0.12,
|
|
68
70
|
canJump = true, maxJumps = 1, airJumpSpeed = null, jumpBuffer = 0.12, fall = false, channel = 'world',
|
|
69
71
|
model = null, clips = null, animation = null, mover = 'simple', faceMode = 'move', faceTarget = null, rig = null, id = null } = {}) {
|
|
70
|
-
/** @internal the id option (a character without a world record); the getter id below is the one public form */ this._ownId = id;
|
|
72
|
+
/** @internal the id option, else the generated one (a character without a world record); the getter id below is the one public form */ this._ownId = id;
|
|
71
73
|
/** @internal true for a world NPC's model (npcView.js): disposing it keeps the NPC's control slot */ this.npcModel = false;
|
|
72
74
|
this.engine = engine;
|
|
73
75
|
if (typeof water !== 'function' && !WATER_MODES.includes(water)) throw codedError('character-option', `character option water: 'swim' | 'block' | 'wade' or (character, { depth }) => one of them; got ${JSON.stringify(water)}`, TypeError);
|
|
@@ -87,12 +89,12 @@ export class Character {
|
|
|
87
89
|
// toward the input, vy falls with gravity). Nobody owns them and nothing auto-yields: a knockback that should last is push(), a jump pad is
|
|
88
90
|
// launch(), full control is mover 'manual'.
|
|
89
91
|
this.vy = 0; this.grounded = true; this._push = 0;
|
|
90
|
-
this.onStep = null; this.onLand = null;
|
|
91
92
|
this.root = new THREE.Group();
|
|
93
|
+
engine._poses.add(this.root);
|
|
92
94
|
this.velocity = new THREE.Vector2();
|
|
93
95
|
this.facing = 0; this.phase = 0; this.moveAmount = 0;
|
|
94
96
|
this.swimming = false;
|
|
95
|
-
/** Action state the animation plays: 'idle' | 'walk' | 'run' | 'jump' | 'fall' | 'swim' | 'drive', or what the states option returned. Read it freely;
|
|
97
|
+
/** Action state the animation plays: 'idle' | 'walk' | 'run' | 'jump' | 'fall' | 'swim' | 'drive' | 'ragdoll', or what the states option returned. Read it freely;
|
|
96
98
|
* the engine mover recomputes it every step, so a direct write warns once (states option for own states, character.playAction(name) for one-shot
|
|
97
99
|
* actions, mover 'manual' to own it). _stateMark: the engine's last write @type {string} */
|
|
98
100
|
this.state = this._stateMark = 'idle';
|
|
@@ -110,7 +112,7 @@ export class Character {
|
|
|
110
112
|
this.mover = mover;
|
|
111
113
|
this._colors = colors;
|
|
112
114
|
// one path for every body: an object, a procedural builder built now (joints exist at once), or a file asset loaded behind a capsule
|
|
113
|
-
const now =
|
|
115
|
+
const now = isModelName(model) ? buildNow(engine, model) : model;
|
|
114
116
|
if (now) { this._useModel(now, clips, animation); return; }
|
|
115
117
|
if (!rig && !model) warnOnce(NO_CHARACTER);
|
|
116
118
|
useRig(this, rig || capsule(colors.body, engine));
|
|
@@ -133,13 +135,11 @@ export class Character {
|
|
|
133
135
|
/**
|
|
134
136
|
* The character's id, the one form engine.mod / time.local take for its entries: its world record id ('player' for the player, an NPC's
|
|
135
137
|
* record id), else the id option you gave it (new Character(e, { id: 'knight-1' })), else a fixed generated one.
|
|
136
|
-
* Why one form:
|
|
138
|
+
* Why one form: a misspelled id silently mods nobody.
|
|
137
139
|
* @example engine.mod('move.speed', { owner: 'haste', id: 'player', mul: 1.2, for: 5 })
|
|
138
140
|
* @readonly @type {string}
|
|
139
141
|
*/
|
|
140
|
-
get id() { return this.recordId ?? this._ownId
|
|
141
|
-
/** @internal the engine's own spelling of id (movers, walkTo, time channels) */
|
|
142
|
-
get modId() { return this.id; }
|
|
142
|
+
get id() { return this.recordId ?? (this._ownId ??= `character#${++registry(this.engine).n}`); }
|
|
143
143
|
/**
|
|
144
144
|
* A movement stat as the mover uses it now: the base field with every engine.mod('move.<name>') entry applied (speed / runSpeed / gravity /
|
|
145
145
|
* jumpSpeed / canJump (1 or 0)). Read-only; the base is the plain field (player.speed = 6), modifiers go through engine.mod.
|
|
@@ -152,7 +152,7 @@ export class Character {
|
|
|
152
152
|
* on the ground or in coyote time it is the ground jump, otherwise an air jump while maxJumps allows. air: false = only a ground jump.
|
|
153
153
|
* @example createPlayer({ ..., maxJumps: 2 }); // double jump: the same jump key twice
|
|
154
154
|
*/
|
|
155
|
-
jump({ air = true } = {}) { const j = jumpOf(this); j.buffer = this.jumpBuffer; j.air = air; return this; }
|
|
155
|
+
jump({ air = true } = {}) { const j = jumpOf(this); j.buffer = this.jumpBuffer || 1e-6; j.fresh = true; j.air = air; return this; }
|
|
156
156
|
/** Give back n jumps for this airtime (a pickup, a wall touch) @param {number} [n] */
|
|
157
157
|
addJumps(n = 1) { const j = jumpOf(this); j.used = Math.max(0, j.used - n); return this; }
|
|
158
158
|
/** All jumps back, as if it had landed */
|
|
@@ -193,9 +193,8 @@ export class Character {
|
|
|
193
193
|
/** Settles (never rejects) once a model named by asset is swapped in or failed; already settled otherwise */
|
|
194
194
|
get whenReady() { return this._whenReady ?? Promise.resolve(); }
|
|
195
195
|
get position() { return this.root.position; }
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
addTo(scene = this.engine.scene) { scene.add(engineOwned('characters', this.root)); return this; }
|
|
196
|
+
// Why write-only accessors: these were plain slots until 0.8. A game still assigning one got no error and no sound, because the plain write just
|
|
197
|
+
// made a property nothing reads. The write stays harmless (no throw), only the silence goes. No getter: the old names still read as undefined.
|
|
199
198
|
/**
|
|
200
199
|
* Place at a position (Vector3 / Object3D / [x, y, z] / { x, z }). With a y it stands on what a character at that height stands on: the floor there, or a
|
|
201
200
|
* registered support within step height above it, so a place under a deck stays under it. With { x, z } it stands on the highest support there, else the ground.
|
|
@@ -208,7 +207,6 @@ export class Character {
|
|
|
208
207
|
if (!at.on) (this.safeGround ??= new THREE.Vector3()).copy(this.root.position);
|
|
209
208
|
this._store(); return this;
|
|
210
209
|
}
|
|
211
|
-
/** Write position and motion state back to the world record (only if recordId is set; saveMotion writes into the record without allocating) @internal */
|
|
212
210
|
/** How it walks now: the mover object ({ name, move, controller? }). Assign a name to switch at any time: c.mover = 'manual' ... c.mover = 'simple' */
|
|
213
211
|
get mover() { return this._mover; }
|
|
214
212
|
set mover(name) {
|
|
@@ -225,9 +223,10 @@ export class Character {
|
|
|
225
223
|
* drivers pass the character's channel dt); speed comes from the stats (character.stat, engine.mod('move.speed')), the direction's length scales it.
|
|
226
224
|
*/
|
|
227
225
|
move(dirX, dirZ, run, dt) {
|
|
228
|
-
// a held character moves only through its holder (core/control.js): a second driver calling move() in the same step is the bug where keys,
|
|
226
|
+
// a held character moves only through its holder (core/ops/control.js): a second driver calling move() in the same step is the bug where keys,
|
|
229
227
|
// a walk and a cutscene all pushed the player and the last one won
|
|
230
228
|
if (DEV) this.engine.control?.checkMove(this);
|
|
229
|
+
if (this._limp) return; // a ragdoll (rigid/ragdoll.js) has the body: release builds skip the check above, so nothing may move it here either
|
|
231
230
|
if (this.vehicle) {
|
|
232
231
|
const v = this.vehicle;
|
|
233
232
|
this.root.position.copy(v.seatPosition(this.seat));
|
|
@@ -246,7 +245,7 @@ export class Character {
|
|
|
246
245
|
* follows vehicle.object. No-op when every seat is taken
|
|
247
246
|
*/
|
|
248
247
|
enter(vehicle) {
|
|
249
|
-
if (this.vehicle) return;
|
|
248
|
+
if (this.vehicle || this._limp) return;
|
|
250
249
|
const e = this.engine, ride = vehicle.passengers ??= [];
|
|
251
250
|
let seat = 0;
|
|
252
251
|
if (vehicle.driver) {
|
|
@@ -284,6 +283,8 @@ export class Character {
|
|
|
284
283
|
// an NPC model torn down when far keeps its slot, the NPC lives on)
|
|
285
284
|
if (!this.recordId && !this.npcModel) this.engine.control?.forget(this.id);
|
|
286
285
|
this.exit();
|
|
286
|
+
detach(this); // a disposed rider must leave the platform's rider list, or it is carried and kept alive for as long as the platform lives
|
|
287
|
+
this.engine._poses.remove(this.root);
|
|
287
288
|
this.anim?.dispose();
|
|
288
289
|
for (const m of Object.values(this._movers)) m.dispose?.();
|
|
289
290
|
this.engine.characters?._capsules.delete(this._rig?.capsule);
|
|
@@ -299,8 +300,8 @@ export class Character {
|
|
|
299
300
|
out.vx = this.velocity.x; out.vz = this.velocity.y; out.vy = this.vy; out.facing = this.facing; out.amount = this.moveAmount;
|
|
300
301
|
out.grounded = this.grounded; out.swimming = this.swimming;
|
|
301
302
|
// motion format 2 (world part version 4): jump state nested, safe spot and the support's id; written in place so a per-step store allocates nothing
|
|
302
|
-
const j = jumpOf(this), jo = out.jump
|
|
303
|
-
const g = this.safeGround; if (g) { const a = out.safe
|
|
303
|
+
const j = jumpOf(this), jo = (out.jump !== null && typeof out.jump === 'object') ? out.jump : (out.jump = badField(out.jump, 'jump', 'an object { coyote, used }') ?? {}); jo.coyote = j.coyote; jo.used = j.used;
|
|
304
|
+
const g = this.safeGround; if (g) { const a = Array.isArray(out.safe) ? out.safe : (out.safe = badField(out.safe, 'safe', 'an array [x, y, z]') ?? [0, 0, 0]); a[0] = g.x; a[1] = g.y; a[2] = g.z; } else out.safe = null;
|
|
304
305
|
out.support = stateOf(this).on?.id ?? null;
|
|
305
306
|
return out;
|
|
306
307
|
}
|
|
@@ -310,7 +311,7 @@ export class Character {
|
|
|
310
311
|
this.velocity.set(m.vx ?? 0, m.vz ?? 0); this.vy = m.vy ?? 0; this.facing = m.facing ?? 0; this.root.rotation.y = this.facing;
|
|
311
312
|
this.moveAmount = m.amount ?? 0; this.grounded = m.grounded ?? true; this.swimming = !!m.swimming;
|
|
312
313
|
const j = jumpOf(this); j.coyote = m.jump?.coyote ?? 0; j.used = m.jump?.used ?? 0; j.buffer = 0;
|
|
313
|
-
this.safeGround = m.safe ? new THREE.Vector3(m.safe[0], m.safe[1], m.safe[2]) : this.safeGround;
|
|
314
|
+
this.safeGround = (Array.isArray(m.safe) && m.safe.length === 3 && m.safe.every(Number.isFinite)) ? new THREE.Vector3(m.safe[0], m.safe[1], m.safe[2]) : this.safeGround;
|
|
314
315
|
// ride the saved support again (found by id) from its current matrix; no support id = rides nothing
|
|
315
316
|
detach(this);
|
|
316
317
|
const en = m.support != null ? registry(this.engine).list.get(m.support) : null;
|
|
@@ -320,7 +321,7 @@ export class Character {
|
|
|
320
321
|
/** Play a one-shot action (e.g. 'wave', returns to the previous state when done); procedural characters have no actions, warn once and skip */
|
|
321
322
|
playAction(name) {
|
|
322
323
|
if (this.anim) this.anim.action(name);
|
|
323
|
-
else warnOnce(STRINGS.noClip
|
|
324
|
+
else warnOnce(fmt(STRINGS.noClip, { name: String(name) }));
|
|
324
325
|
}
|
|
325
326
|
|
|
326
327
|
/** Ground type under the feet (terrain groundType or level material name); 'water' while swimming. Footstep sounds map it via audio.footsteps */
|
|
@@ -346,15 +347,16 @@ export class Character {
|
|
|
346
347
|
* or adjust bones on top of the pose. Returns a handle; h.remove() stops it. Presentation only: never read it for gameplay timing.
|
|
347
348
|
* @param {(character: Character, dt: number) => void} fn
|
|
348
349
|
* @returns {{ remove(): void }}
|
|
349
|
-
* @example const h = player.onPose(() => sword.position.copy(player.
|
|
350
|
+
* @example const h = player.onPose(() => sword.position.copy(player.root.getObjectByName('Hand_R').getWorldPosition(v)));
|
|
350
351
|
*/
|
|
351
352
|
onPose(fn) { (this._poseFns ??= new Set()).add(fn); return { remove: () => this._poseFns.delete(fn) }; }
|
|
352
353
|
/** @internal */
|
|
353
354
|
_firePose(dt) { if (this._poseFns?.size) for (const f of [...this._poseFns]) { try { f(this, dt); } catch (err) { reportError(this.engine, err, 'character.onPose callback'); } } }
|
|
354
355
|
/** @internal Call every frame: play animation, at the speed of the character's time channel (bullet time on 'enemies' slows their walk cycle too) */
|
|
355
356
|
animate(dt) {
|
|
356
|
-
|
|
357
|
-
|
|
357
|
+
dt *= this.engine.still ? 0 : this.engine.time.scale(this.channel, this.id);
|
|
358
|
+
if (!this._limp) this._animate(dt);
|
|
359
|
+
if (!this.anim) this._firePose(dt);
|
|
358
360
|
}
|
|
359
361
|
/** @internal */
|
|
360
362
|
_animate(dt) {
|
|
@@ -362,7 +364,8 @@ export class Character {
|
|
|
362
364
|
this.phase += dt * (2.2 + sp * 1.25);
|
|
363
365
|
const s = Math.sin(this.phase);
|
|
364
366
|
// footstep event: fires once per foot landing (swing direction flips); model and procedural animation share this rhythm
|
|
365
|
-
|
|
367
|
+
// the payload stays { character }: a crowd of NPCs steps all the time, and only a listener that wants the ground should pay for reading it
|
|
368
|
+
if (this.grounded && sp > 0.4 && Math.sign(s) !== Math.sign(this._lastS ?? s)) this.engine.events.emit('character:step', { character: this });
|
|
366
369
|
this._lastS = s;
|
|
367
370
|
if (this.anim) {
|
|
368
371
|
const a = this.anim;
|