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
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// pixelSnap on a camera rig (followCamera, fixedCamera). The rig places the camera as it likes, then rigModule calls apply() once (common.js): that one call site is why the
|
|
2
|
+
// rigs carry no copy of this, and the math itself is pixelGrid's. While it is on, the view height belongs here: buffer rows / pixelsPerMeter, so a resize or
|
|
3
|
+
// engine.setPixelSize keeps the same world-to-pixel scale. A `size` of the game's would make the grid and the picture disagree, so options refuse it and a later write is
|
|
4
|
+
// reported by name.
|
|
5
|
+
import { pixelGrid } from '../../core/scene/pixel.js';
|
|
6
|
+
import { setProjection } from '../../core/scene/view.js';
|
|
7
|
+
import { codedError, coded } from '../../core/base/errorHints.js';
|
|
8
|
+
import { warnOnce } from '../../core/base/validate.js';
|
|
9
|
+
import { readParams, keysSchema } from '../../core/base/params.js';
|
|
10
|
+
|
|
11
|
+
const KEYS = keysSchema(['pixelsPerMeter', 'bounds']);
|
|
12
|
+
|
|
13
|
+
class RigPixelSnap {
|
|
14
|
+
constructor(engine, { pixelsPerMeter, bounds = null }) {
|
|
15
|
+
this.engine = engine; this.bounds = bounds;
|
|
16
|
+
this.grid = pixelGrid({ camera: engine.camera, pixelsPerMeter });
|
|
17
|
+
/** False while something else changed the view height (camera.zoom, the frustum): nothing is rounded then, a grid that does not match the picture means nothing */
|
|
18
|
+
this.agrees = true;
|
|
19
|
+
/** The last rounding, in art pixels on the screen axes */
|
|
20
|
+
this.error = { x: 0, y: 0 };
|
|
21
|
+
this._wrote = null; // the view height this rig last set: anything else showing means an outside write
|
|
22
|
+
}
|
|
23
|
+
_write() { this._wrote = this.grid.viewHeight(this.engine.renderer.domElement.height); setProjection(this.engine, 'orthographic', this._wrote); }
|
|
24
|
+
/** The rig became the camera */
|
|
25
|
+
enter() { this._write(); this.grid.camera = this.engine.camera; }
|
|
26
|
+
/** After the rig's update: view height, bounds, rounding */
|
|
27
|
+
apply() {
|
|
28
|
+
const cam = this.engine.camera, c = this.engine.renderer.domElement, g = this.grid;
|
|
29
|
+
// engine.camera was assigned: the same grid goes on (sprites hold it), and the view height the new camera came with is no outside write
|
|
30
|
+
if (g.camera !== cam) { g.camera = cam; if (cam.isOrthographicCamera) this._wrote = null; }
|
|
31
|
+
this.agrees = !!cam.isOrthographicCamera && (this._wrote == null || g.agrees(this._wrote * g.pixelsPerMeter));
|
|
32
|
+
if (!this.agrees) {
|
|
33
|
+
warnOnce(coded('pixel-conflict', `pixelSnap: something else set the view height (camera.zoom, the frustum or a perspective view), so the camera no longer shows the ${this._wrote} world units `
|
|
34
|
+
+ `that pixelsPerMeter ${g.pixelsPerMeter} needs and rounding has stopped. Keep pixelSnap and put them back (to zoom, use engine.setPixelSize), or drop pixelSnap`));
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
this._write();
|
|
38
|
+
const r = g.place(cam.position, { columns: c.width, rows: c.height, bounds: this.bounds });
|
|
39
|
+
cam.position.copy(r.position);
|
|
40
|
+
this.error.x = r.error.x; this.error.y = r.error.y;
|
|
41
|
+
}
|
|
42
|
+
describe() { return { pixelsPerMeter: this.grid.pixelsPerMeter, viewHeight: this._wrote, agrees: this.agrees, error: { ...this.error } }; }
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* A view pixelSnap can own: orthographic, with no size of its own. Thrown here, named, at the option that is wrong.
|
|
47
|
+
* @param {string} who the rig or shot, for the message @param {{ projection?: string, size?: number | null }} view
|
|
48
|
+
*/
|
|
49
|
+
export function checkPixelView(who, { projection, size }) {
|
|
50
|
+
if (projection !== 'orthographic') throw codedError('camera-option', `${who}: pixelSnap works on an orthographic camera only, a perspective view has no single art pixel size. Add projection: 'orthographic', or drop pixelSnap`);
|
|
51
|
+
if (size != null) throw codedError('pixel-conflict', `${who}: size ${size} with pixelSnap, which decides the view height itself (buffer height / pixelsPerMeter). Drop size, or drop pixelSnap`);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The pixelSnap option of a rig: null when not asked for. Each rig calls this from its constructor, and enter() from onEnter.
|
|
56
|
+
* @param {any} engine @param {any} opts the pixelSnap option @param {string} who the rig's name, for messages
|
|
57
|
+
*/
|
|
58
|
+
export function rigPixelSnap(engine, opts, who) {
|
|
59
|
+
if (!opts) return null;
|
|
60
|
+
readParams(`${who} pixelSnap`, KEYS, opts);
|
|
61
|
+
return new RigPixelSnap(engine, opts);
|
|
62
|
+
}
|
|
@@ -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';
|
|
@@ -21,11 +20,15 @@ import { stateOf, detach, registry, placeAtHeight } from './movers/support.js';
|
|
|
21
20
|
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';
|
|
23
|
+
import { seatsOf } from './seat.js';
|
|
24
24
|
import { useModel } from './useModel.js';
|
|
25
|
-
import { codedError, coded } from '../../core/errorHints.js';
|
|
25
|
+
import { codedError, coded } from '../../core/base/errorHints.js';
|
|
26
|
+
import { isModelName } from '../../core/base/util.js';
|
|
26
27
|
|
|
28
|
+
// 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
|
|
29
|
+
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
30
|
const STRINGS = { noClip: 'character has no skeletal animation; playAction(\'{name}\') skipped (the model needs this action)' };
|
|
28
|
-
const
|
|
31
|
+
const BUILT_IN = { simple: simpleMover, rapier: rapierMover, manual: manualMover };
|
|
29
32
|
|
|
30
33
|
// Options Character understands (shared by player and NPC)
|
|
31
34
|
export const CHARACTER_KEYS = ['colors', 'speed', 'runSpeed', 'radius', 'water', 'states', 'swimDepth', 'swimSpeed', 'turnSpeed', 'acceleration', 'gravity',
|
|
@@ -35,7 +38,7 @@ const FACE_MODES = ['move', 'camera', 'target', 'manual'];
|
|
|
35
38
|
export class Character {
|
|
36
39
|
/**
|
|
37
40
|
* @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
|
|
41
|
+
* @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
42
|
* engine.assets.model() returned; without model and rig a gray capsule (warned once). rig: a ready body (proceduralRig.js format)
|
|
40
43
|
* colors: { body, skin, legs, hair } per-character part colors (meshes marked userData.part; a capsule takes colors.body)
|
|
41
44
|
* speed walk speed, runSpeed run speed (m/s), radius collision radius
|
|
@@ -50,13 +53,14 @@ export class Character {
|
|
|
50
53
|
* coyoteTime how long after leaving a ledge a jump is still allowed, canJump, jumpBuffer how long a jump() pressed early
|
|
51
54
|
* waits for the ground (s), maxJumps jumps before landing again (2 = double jump), airJumpSpeed takeoff speed of an air jump
|
|
52
55
|
* (default jumpSpeed). These are the base values and belong to the game; modules change them with engine.mod('move.<stat>').
|
|
53
|
-
* fall: { belowY } a height (or (character) => boolean): below it character:fall fires and
|
|
54
|
-
*
|
|
56
|
+
* fall: { belowY } a height (or (character) => boolean): below it character:fall fires and the rule 'fall' decides (no rule: nothing happens;
|
|
57
|
+
* engine.mod('fall', { owner: 'game', set: 'rescue' }) goes back to safeGround). false (default) = off
|
|
55
58
|
* channel: the time channel its movement and animation follow when the engine drives it (player 'player', others 'world')
|
|
56
59
|
* 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;
|
|
60
|
+
* animation: animation state machine config (see core/assets/Animator.js), state names are character state names;
|
|
58
61
|
* without walk/run, move (blend tree, param speed) is used
|
|
59
|
-
* mover:
|
|
62
|
+
* mover: (character, engine) => ({ name, move(x, z, run, dt, y) }) your own (flight, wall running: mover.contract.js, recipe 57) |
|
|
63
|
+
* 'simple' (default) | 'rapier' (Rapier character controller, needs the rigid module) | 'manual' (the game writes the position;
|
|
60
64
|
* move() only updates grounded / support / safeGround / fall, movers/manual.js); assign at any time: player.mover = 'manual'
|
|
61
65
|
* faceMode which way it turns each move: 'move' (default, toward its velocity) | 'camera' (along cameraRig.forward(), over-the-shoulder aiming)
|
|
62
66
|
* | 'target' (toward faceTarget: Object3D / Vector3 / { x, z }, lock-on strafing) | 'manual' (only face() turns it);
|
|
@@ -67,7 +71,7 @@ export class Character {
|
|
|
67
71
|
turnSpeed = 10, acceleration = 12, gravity = -24, jumpSpeed = 8, stepHeight = engine.movement.stepHeight, airControl = 0.35, coyoteTime = 0.12,
|
|
68
72
|
canJump = true, maxJumps = 1, airJumpSpeed = null, jumpBuffer = 0.12, fall = false, channel = 'world',
|
|
69
73
|
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;
|
|
74
|
+
/** @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
75
|
/** @internal true for a world NPC's model (npcView.js): disposing it keeps the NPC's control slot */ this.npcModel = false;
|
|
72
76
|
this.engine = engine;
|
|
73
77
|
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,30 +91,34 @@ export class Character {
|
|
|
87
91
|
// 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
92
|
// launch(), full control is mover 'manual'.
|
|
89
93
|
this.vy = 0; this.grounded = true; this._push = 0;
|
|
90
|
-
this.
|
|
94
|
+
this.limp = null; this.disposed = false; // limp: the ragdoll that has the body (rigid/ragdoll.js)
|
|
91
95
|
this.root = new THREE.Group();
|
|
96
|
+
engine._poses.add(this.root);
|
|
92
97
|
this.velocity = new THREE.Vector2();
|
|
93
98
|
this.facing = 0; this.phase = 0; this.moveAmount = 0;
|
|
94
99
|
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;
|
|
100
|
+
/** Action state the animation plays: 'idle' | 'walk' | 'run' | 'jump' | 'fall' | 'swim' | 'drive' | 'ragdoll', or what the states option returned. Read it freely;
|
|
96
101
|
* 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
|
-
* actions, mover 'manual' to own it).
|
|
98
|
-
this.state = this.
|
|
102
|
+
* actions, mover 'manual' to own it). stateMark: the engine's last write @type {string} */
|
|
103
|
+
this.state = this.stateMark = 'idle';
|
|
99
104
|
/** The vehicle it sits in (null on foot) and its seat there (0 = driver, null on foot) */
|
|
100
|
-
|
|
105
|
+
/** @internal the seat relation (seat.js), null on foot */ this._ride = null; this.anim = null;
|
|
101
106
|
/** false while a model named by asset loads (placeholder shows); await whenReady */
|
|
102
107
|
this.ready = true;
|
|
103
108
|
/**
|
|
104
109
|
* id of the world record ('player' for the player); once set, position, facing and motion state are written back to it.
|
|
105
|
-
*
|
|
110
|
+
* A write to that record's position (world.move, world.set, thing.set) is a placeAt
|
|
106
111
|
* @type {string | null}
|
|
107
112
|
*/
|
|
108
113
|
this.recordId = null;
|
|
109
|
-
/** @internal
|
|
114
|
+
/** @internal where a write to its record's position goes (world.move): placeAt; an NPC's model goes through npc.placeAt, which drops its path too */ this.placeRecord = p => this.placeAt(p);
|
|
115
|
+
/** @internal where a turn written to its record goes; an NPC's facing is saved in its motion */ this._turnRecord = yaw => { this.face(yaw); this._store(); };
|
|
116
|
+
/** @internal each mover built once, kept while switching (rapier keeps its native body), by name or by the game's function */ this._movers = new Map([['simple', simpleMover(this)]]);
|
|
117
|
+
/** @internal the rule character.mover: an entry there wins over this character's own mover and ends with its owner, so a ladder puts back what was there */ this._moverRule = engine.stacks.rule('character.mover', null);
|
|
110
118
|
this.mover = mover;
|
|
111
119
|
this._colors = colors;
|
|
112
120
|
// 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 =
|
|
121
|
+
const now = isModelName(model) ? buildNow(engine, model) : model;
|
|
114
122
|
if (now) { this._useModel(now, clips, animation); return; }
|
|
115
123
|
if (!rig && !model) warnOnce(NO_CHARACTER);
|
|
116
124
|
useRig(this, rig || capsule(colors.body, engine));
|
|
@@ -133,13 +141,11 @@ export class Character {
|
|
|
133
141
|
/**
|
|
134
142
|
* 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
143
|
* record id), else the id option you gave it (new Character(e, { id: 'knight-1' })), else a fixed generated one.
|
|
136
|
-
* Why one form:
|
|
144
|
+
* Why one form: a misspelled id silently mods nobody.
|
|
137
145
|
* @example engine.mod('move.speed', { owner: 'haste', id: 'player', mul: 1.2, for: 5 })
|
|
138
146
|
* @readonly @type {string}
|
|
139
147
|
*/
|
|
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; }
|
|
148
|
+
get id() { return this.recordId ?? (this._ownId ??= `character#${++registry(this.engine).n}`); }
|
|
143
149
|
/**
|
|
144
150
|
* A movement stat as the mover uses it now: the base field with every engine.mod('move.<name>') entry applied (speed / runSpeed / gravity /
|
|
145
151
|
* jumpSpeed / canJump (1 or 0)). Read-only; the base is the plain field (player.speed = 6), modifiers go through engine.mod.
|
|
@@ -152,7 +158,7 @@ export class Character {
|
|
|
152
158
|
* 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
159
|
* @example createPlayer({ ..., maxJumps: 2 }); // double jump: the same jump key twice
|
|
154
160
|
*/
|
|
155
|
-
jump({ air = true } = {}) { const j = jumpOf(this); j.buffer = this.jumpBuffer; j.air = air; return this; }
|
|
161
|
+
jump({ air = true } = {}) { const j = jumpOf(this); j.buffer = this.jumpBuffer || 1e-6; j.fresh = true; j.air = air; return this; }
|
|
156
162
|
/** Give back n jumps for this airtime (a pickup, a wall touch) @param {number} [n] */
|
|
157
163
|
addJumps(n = 1) { const j = jumpOf(this); j.used = Math.max(0, j.used - n); return this; }
|
|
158
164
|
/** All jumps back, as if it had landed */
|
|
@@ -193,27 +199,76 @@ export class Character {
|
|
|
193
199
|
/** Settles (never rejects) once a model named by asset is swapped in or failed; already settled otherwise */
|
|
194
200
|
get whenReady() { return this._whenReady ?? Promise.resolve(); }
|
|
195
201
|
get position() { return this.root.position; }
|
|
196
|
-
/**
|
|
197
|
-
get
|
|
198
|
-
|
|
202
|
+
/** What it rides now (the vehicle contract object), null on foot */
|
|
203
|
+
get vehicle() { return this._ride?.vehicle ?? null; }
|
|
204
|
+
/** @internal Something other than a holder has the body: a ragdoll (rigid/ragdoll.js) or a seat (seat.js). Nothing may move or place it meanwhile */
|
|
205
|
+
get bodyHeld() { return !!(this.limp || this._ride); }
|
|
206
|
+
/** Its seat in that vehicle (0 = driver), null on foot */
|
|
207
|
+
get seat() { return this._ride?.seat ?? null; }
|
|
208
|
+
// 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
|
|
209
|
+
// 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
210
|
/**
|
|
200
211
|
* 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
212
|
* 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.
|
|
213
|
+
* A rider gets out first (exit: vehicle:exit fires, the vehicle brakes): the seat would otherwise pull it back on the next step.
|
|
214
|
+
* A ragdoll goes there whole, at rest, and stays limp. A walk ends: the game said where it is, so the old order no longer applies.
|
|
202
215
|
*/
|
|
203
216
|
placeAt(position) {
|
|
204
|
-
|
|
217
|
+
this.engine.control?.endTasks(this, 'placed');
|
|
218
|
+
if (this.vehicle) this.exit({ force: true });
|
|
219
|
+
else if (this.recordId && this.engine.world?.get(this.recordId)?.vehicle != null) this._writeSeat(null, null); // its record waited for a vehicle not built yet: the game put it elsewhere
|
|
220
|
+
return this._place(position);
|
|
221
|
+
}
|
|
222
|
+
/** @internal Put it there with no ending of its own: a link crossing, a step out of a vehicle */
|
|
223
|
+
_place(position) {
|
|
224
|
+
const [x, z] = xzOf(position), at = placeAtHeight(this.engine, 'character.placeAt()', x, z, yOf(position), this.stepHeight, this.root.position.y), was = this.root.position;
|
|
225
|
+
this.limp?.shift(x - was.x, at.y - was.y, z - was.z); // limp, root follows the body: the body goes first, or the next step puts root back on it
|
|
205
226
|
this.root.position.set(x, at.y, z);
|
|
206
227
|
detach(this);
|
|
207
228
|
// ground is a safe spot. A support may be unsafe or moving, which only a step can tell: the next mover step applies the rule in endMove
|
|
208
229
|
if (!at.on) (this.safeGround ??= new THREE.Vector3()).copy(this.root.position);
|
|
209
230
|
this._store(); return this;
|
|
210
231
|
}
|
|
211
|
-
/**
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
if (
|
|
216
|
-
|
|
232
|
+
/** @internal Why it could not keep this rot, or null: facing is about Y only, and a seat turns its rider every step. thing.set answers with it, world.set throws it */
|
|
233
|
+
poseProblem({ rot, scale }) {
|
|
234
|
+
const bad = v => v !== undefined && !Number.isFinite(v) && !(Array.isArray(v) && v.length === 3 && v.every(Number.isFinite));
|
|
235
|
+
if (bad(rot) || bad(scale)) return `character '${this.id}': rot and scale on its record are the character's turn and size, a number or [x, y, z]; got ${JSON.stringify({ rot, scale })}`;
|
|
236
|
+
if (rot === undefined) return null;
|
|
237
|
+
if (Array.isArray(rot) && (rot[0] || rot[2])) return `rot ${JSON.stringify(rot)} on character '${this.id}': a character stays upright and turns about Y only, so a tilt about x or z cannot apply. Write a number or [0, yaw, 0]; to lean its picture, turn a child of root`;
|
|
238
|
+
return this.vehicle ? `rot on character '${this.id}': it sits in a vehicle and the seat turns it. Turn the vehicle, or exit() first` : null;
|
|
239
|
+
}
|
|
240
|
+
/** @internal A write to its record's rot / scale (world.set, thing.set): the character owns both, as it owns its position. scale is the picture: radius and height stay */
|
|
241
|
+
takePose(pose) {
|
|
242
|
+
const problem = this.poseProblem(pose), { rot, scale } = pose;
|
|
243
|
+
if (problem) throw codedError('character-option', problem);
|
|
244
|
+
if (rot !== undefined) this._turnRecord(Array.isArray(rot) ? rot[1] : rot);
|
|
245
|
+
if (scale !== undefined) { if (Array.isArray(scale)) this.root.scale.fromArray(scale); else this.root.scale.setScalar(scale); this._scaled = true; }
|
|
246
|
+
}
|
|
247
|
+
/** @internal Built or loaded from its record: scale stays there; rot is a write made while it had no character, taken once. A record without scale takes back one written before */
|
|
248
|
+
_fromRecord(rec) {
|
|
249
|
+
const { rot } = rec, scale = rec.scale ?? (this._scaled ? 1 : undefined);
|
|
250
|
+
delete rec.rot;
|
|
251
|
+
this.takePose({ rot, scale });
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* How it walks now: the mover object ({ name, move, controller? }). Assign a built-in name or (character, engine) => mover to switch for good: c.mover = 'manual'.
|
|
255
|
+
* For a while, use the rule: engine.mod('character.mover', { owner: 'ladder', id: c.id, set: 'manual' }) and remove the handle after. false in the rule means 'manual'
|
|
256
|
+
*/
|
|
257
|
+
get mover() { return this._moverOf(this._moverRule.value(this.id) ?? this._ownMover); }
|
|
258
|
+
set mover(v) { this._moverOf(v); this._ownMover = v; }
|
|
259
|
+
/** @internal the mover for a rule value or an assignment, built the first time */
|
|
260
|
+
_moverOf(v) {
|
|
261
|
+
const key = v === false ? 'manual' : v;
|
|
262
|
+
let m = this._movers.get(key);
|
|
263
|
+
if (m) return m;
|
|
264
|
+
if (typeof key === 'function') {
|
|
265
|
+
m = key(this, this.engine);
|
|
266
|
+
if (typeof m === 'string' || m === false) return this._movers.set(key, this._moverOf(m)).get(key); // the function chose a built-in, once for this character
|
|
267
|
+
if (typeof m?.move !== 'function') throw codedError('character-option', `the mover function for '${this.id}' must return { name, move(x, z, run, dt, y) } (mover.contract.js) or a built-in name, got ${JSON.stringify(m)}`);
|
|
268
|
+
} else if (BUILT_IN[key]) m = BUILT_IN[key](this, this._movers.get('simple'));
|
|
269
|
+
else throw codedError('character-option', `mover ${JSON.stringify(key)}: use 'simple', 'rapier', 'manual' or your own (character, engine) => ({ name, move(x, z, run, dt, y) }). Recipe 57`);
|
|
270
|
+
this._movers.set(key, m);
|
|
271
|
+
return m;
|
|
217
272
|
}
|
|
218
273
|
_store() { const id = this.recordId; if (id) { const W = this.engine.world; this.saveMotion(W.get(id)); W.move(id, this.root.position); } }
|
|
219
274
|
/** After moving root yourself (a cutscene path, a scripted pose): write position and motion back to the world record, so a save right after has it */
|
|
@@ -221,21 +276,17 @@ export class Character {
|
|
|
221
276
|
|
|
222
277
|
/**
|
|
223
278
|
* Move along a direction (call once per fixed step). dirX/dirZ is a world-space direction (length 0-1), run toggles running.
|
|
224
|
-
* How it walks is decided by this.mover ('simple' default / 'rapier');
|
|
279
|
+
* How it walks is decided by this.mover ('simple' default / 'rapier'); on a seat nothing moves it here (seat.js holds it). dt is used as given (the engine's own
|
|
225
280
|
* 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
281
|
*/
|
|
227
|
-
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,
|
|
282
|
+
move(dirX, dirZ, run, dt, dirY = 0) {
|
|
283
|
+
// 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
284
|
// a walk and a cutscene all pushed the player and the last one won
|
|
230
285
|
if (DEV) this.engine.control?.checkMove(this);
|
|
231
|
-
if (this.
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
if (this.root.visible) { v.object.getWorldQuaternion(this.root.quaternion); this.facing = this.root.rotation.y; }
|
|
236
|
-
this.moveAmount = Math.abs(v.speed); this.state = this._stateMark = 'drive';
|
|
237
|
-
}
|
|
238
|
-
else this.mover.move(dirX, dirZ, run, dt);
|
|
286
|
+
if (this.bodyHeld) return; // release builds skip the check above, so nothing may move it here either
|
|
287
|
+
const m = this.mover;
|
|
288
|
+
if (m !== this._moving) { this._moving?.leave?.(); this._moving = m; } // once per change: what the last mover left standing in the world must not block this one
|
|
289
|
+
m.move(dirX, dirZ, run, dt, dirY);
|
|
239
290
|
this._store();
|
|
240
291
|
}
|
|
241
292
|
|
|
@@ -246,46 +297,89 @@ export class Character {
|
|
|
246
297
|
* follows vehicle.object. No-op when every seat is taken
|
|
247
298
|
*/
|
|
248
299
|
enter(vehicle) {
|
|
249
|
-
if (this.vehicle) return;
|
|
250
|
-
const
|
|
300
|
+
if (this.vehicle || this.limp) return;
|
|
301
|
+
const ride = vehicle.passengers ??= [];
|
|
251
302
|
let seat = 0;
|
|
252
303
|
if (vehicle.driver) {
|
|
253
304
|
const taken = new Set(ride.map(c => c.seat));
|
|
254
305
|
for (seat = 1; seat < (vehicle.seats ?? 1) && taken.has(seat); seat++);
|
|
255
306
|
if (seat >= (vehicle.seats ?? 1)) return;
|
|
256
307
|
}
|
|
257
|
-
this.vehicle
|
|
258
|
-
|
|
308
|
+
this._sit(vehicle, seat);
|
|
309
|
+
}
|
|
310
|
+
/** @internal Why it cannot go back to this seat, or null (it may be there already). Undo of a placement that ended a ride asks this first */
|
|
311
|
+
seatProblem({ vehicle, seat }) {
|
|
312
|
+
if (this.vehicle === vehicle && this.seat === seat) return null;
|
|
313
|
+
if (vehicle.gone || !vehicle.object.parent) return `character '${this.id}': the vehicle it sat in is gone, so it cannot go back to its seat`;
|
|
314
|
+
if (this.vehicle) return `character '${this.id}': it sits in another vehicle now. exit() first`;
|
|
315
|
+
if (this.limp) return `character '${this.id}': it is a ragdoll now. remove() it first`;
|
|
316
|
+
return (seat === 0 ? vehicle.driver : vehicle.passengers.some(c => c.seat === seat)) ? `character '${this.id}': seat ${seat} is taken now` : null;
|
|
317
|
+
}
|
|
318
|
+
/** @internal Back on the seat a placement took it from; seatProblem said it can */
|
|
319
|
+
backInSeat({ vehicle, seat }) {
|
|
320
|
+
if (this.vehicle) return;
|
|
321
|
+
this._sit(vehicle, seat);
|
|
322
|
+
}
|
|
323
|
+
/** @internal Take this seat: enter chose it, or an undo names it */
|
|
324
|
+
_sit(vehicle, seat) {
|
|
325
|
+
const e = this.engine;
|
|
326
|
+
e.control?.endTasks(this, 'seated');
|
|
327
|
+
this._ride = { rider: this, vehicle, id: vehicle.id ?? null, seat, pedal: false };
|
|
328
|
+
const book = seatsOf(e); book.rides.add(this._ride); if (vehicle.id != null) book.vehicles.add(vehicle);
|
|
329
|
+
this.root.position.copy(vehicle.seatPosition(seat)); // the record says the seat at once, not on the next step
|
|
330
|
+
this._writeSeat(this._ride.id, seat);
|
|
331
|
+
if (seat === 0) vehicle.driver = this; else vehicle.passengers.push(this);
|
|
259
332
|
if (e.player === this) this._driveCtx = e.input.push('vehicle', { pass: true }); // driving: brake lives in this context, walking-only keys are shadowed
|
|
260
333
|
if (e.player === this && !e.input.keysOf('brake').length) warnOnce(coded('input-keys', "the player drives without a brake key: no module binds one by itself. engine.input.bind(presets.bindings.brake) (B / gamepad LT) or engine.input.bind('brake', ['KeyX'])"));
|
|
261
|
-
this.root.visible = vehicle.hideDriver === false; this.velocity.set(0, 0); this.vy = 0; this.swimming = false; this.state = this.
|
|
334
|
+
this.root.visible = vehicle.hideDriver === false; this.velocity.set(0, 0); this.vy = 0; this.swimming = false; this.state = this.stateMark = 'drive'; this._store();
|
|
262
335
|
// only when the game asked the camera to follow the player (createPlayer({ cameraFollow }))
|
|
263
336
|
if (e.player === this && this.cameraFollow) e.cameraRig?.follow(vehicle.object, vehicle.camera);
|
|
264
337
|
e.events.emit('vehicle:enter', { character: this, vehicle });
|
|
265
338
|
}
|
|
266
|
-
/**
|
|
267
|
-
|
|
339
|
+
/** @internal The relation's half in the record, saved with it. A load writes nothing: recordId is null while it places */
|
|
340
|
+
_writeSeat(vehicle, seat) { const id = this.recordId; if (id) this.engine.ops.allow(() => this.engine.world.set(id, { vehicle, seat })); }
|
|
341
|
+
/** @internal The first exit the vehicle offers that a body of this size can stand on, or null. Without collision nothing can say no */
|
|
342
|
+
_exitSpot(v, seat) {
|
|
343
|
+
for (let n = 0; n < 8; n++) { // bounded: a vehicle with one exit answers the same point for every n
|
|
344
|
+
const p = v.exitPosition(seat, n);
|
|
345
|
+
if (!p) return null;
|
|
346
|
+
if (this.engine.collision?.walkableAt(p.x, p.z, this.radius, p.y) ?? true) return p;
|
|
347
|
+
}
|
|
348
|
+
return null;
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Exit: step out at the first exit the vehicle offers that is walkable, camera returns to the character. With none it refuses and the rider stays seated.
|
|
352
|
+
* force: true gets out anyway, at the first exit: the vehicle is going, or the rider is being placed elsewhere.
|
|
353
|
+
* @param {{ force?: boolean }} [o]
|
|
354
|
+
* @returns {boolean} whether it got out
|
|
355
|
+
*/
|
|
356
|
+
exit({ force = false } = {}) {
|
|
268
357
|
const v = this.vehicle, e = this.engine;
|
|
269
|
-
if (!v) return;
|
|
270
|
-
const seat = this.seat;
|
|
358
|
+
if (!v) return false;
|
|
359
|
+
const seat = this.seat, at = this._exitSpot(v, seat) ?? (force ? v.exitPosition(seat) : null);
|
|
360
|
+
if (!at) return false;
|
|
271
361
|
if (seat === 0) { v.drive(0, 0, 1); v.driver = null; } else v.passengers.splice(v.passengers.indexOf(this), 1);
|
|
272
|
-
this.
|
|
362
|
+
seatsOf(e).rides.delete(this._ride); this._ride = null;
|
|
363
|
+
this._writeSeat(null, null);
|
|
273
364
|
this._driveCtx?.remove(); this._driveCtx = null;
|
|
274
365
|
this.root.quaternion.identity(); this.root.rotation.y = this.facing;
|
|
275
|
-
this.
|
|
366
|
+
this._place(at); this.root.visible = true; this.grounded = true; this.state = this.stateMark = 'idle';
|
|
276
367
|
if (e.player === this && this.cameraFollow) e.cameraRig?.follow(this.root);
|
|
277
368
|
e.events.emit('vehicle:exit', { character: this, vehicle: v });
|
|
369
|
+
return true;
|
|
278
370
|
}
|
|
279
371
|
/** Dispose this character completely: exit the vehicle first, release animation and mover, remove from the scene and dispose geometries and materials */
|
|
280
372
|
dispose() {
|
|
281
|
-
this.
|
|
282
|
-
this.
|
|
373
|
+
this.disposed = true; // a model still loading by asset name is dropped on arrival
|
|
374
|
+
this.engine.control?.endTasks(this, 'gone');
|
|
283
375
|
// a character without a world record or NPC id has nothing to come back as: its control slot goes with it (records drop theirs on world:remove,
|
|
284
376
|
// an NPC model torn down when far keeps its slot, the NPC lives on)
|
|
285
377
|
if (!this.recordId && !this.npcModel) this.engine.control?.forget(this.id);
|
|
286
|
-
this.exit();
|
|
378
|
+
this.exit({ force: true });
|
|
379
|
+
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
|
|
380
|
+
this.engine._poses.remove(this.root);
|
|
287
381
|
this.anim?.dispose();
|
|
288
|
-
for (const m of
|
|
382
|
+
for (const m of new Set(this._movers.values())) m.dispose?.();
|
|
289
383
|
this.engine.characters?._capsules.delete(this._rig?.capsule);
|
|
290
384
|
this.engine.remove(this.root);
|
|
291
385
|
}
|
|
@@ -299,8 +393,8 @@ export class Character {
|
|
|
299
393
|
out.vx = this.velocity.x; out.vz = this.velocity.y; out.vy = this.vy; out.facing = this.facing; out.amount = this.moveAmount;
|
|
300
394
|
out.grounded = this.grounded; out.swimming = this.swimming;
|
|
301
395
|
// 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
|
|
396
|
+
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;
|
|
397
|
+
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
398
|
out.support = stateOf(this).on?.id ?? null;
|
|
305
399
|
return out;
|
|
306
400
|
}
|
|
@@ -310,7 +404,7 @@ export class Character {
|
|
|
310
404
|
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
405
|
this.moveAmount = m.amount ?? 0; this.grounded = m.grounded ?? true; this.swimming = !!m.swimming;
|
|
312
406
|
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;
|
|
407
|
+
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
408
|
// ride the saved support again (found by id) from its current matrix; no support id = rides nothing
|
|
315
409
|
detach(this);
|
|
316
410
|
const en = m.support != null ? registry(this.engine).list.get(m.support) : null;
|
|
@@ -320,14 +414,14 @@ export class Character {
|
|
|
320
414
|
/** 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
415
|
playAction(name) {
|
|
322
416
|
if (this.anim) this.anim.action(name);
|
|
323
|
-
else warnOnce(STRINGS.noClip
|
|
417
|
+
else warnOnce(fmt(STRINGS.noClip, { name: String(name) }));
|
|
324
418
|
}
|
|
325
419
|
|
|
326
420
|
/** Ground type under the feet (terrain groundType or level material name); 'water' while swimming. Footstep sounds map it via audio.footsteps */
|
|
327
421
|
groundType() {
|
|
328
422
|
if (this.swimming) return 'water';
|
|
329
423
|
const p = this.root.position;
|
|
330
|
-
return this.engine.groundType(p.x, p.z);
|
|
424
|
+
return this.engine.groundType(p.x, p.z, p.y);
|
|
331
425
|
}
|
|
332
426
|
|
|
333
427
|
/**
|
|
@@ -346,15 +440,16 @@ export class Character {
|
|
|
346
440
|
* or adjust bones on top of the pose. Returns a handle; h.remove() stops it. Presentation only: never read it for gameplay timing.
|
|
347
441
|
* @param {(character: Character, dt: number) => void} fn
|
|
348
442
|
* @returns {{ remove(): void }}
|
|
349
|
-
* @example const h = player.onPose(() => sword.position.copy(player.
|
|
443
|
+
* @example const h = player.onPose(() => sword.position.copy(player.root.getObjectByName('Hand_R').getWorldPosition(v)));
|
|
350
444
|
*/
|
|
351
445
|
onPose(fn) { (this._poseFns ??= new Set()).add(fn); return { remove: () => this._poseFns.delete(fn) }; }
|
|
352
446
|
/** @internal */
|
|
353
447
|
_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
448
|
/** @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
449
|
animate(dt) {
|
|
356
|
-
|
|
357
|
-
|
|
450
|
+
dt *= this.engine.still ? 0 : this.engine.time.scale(this.channel, this.id);
|
|
451
|
+
if (!this.limp) this._animate(dt);
|
|
452
|
+
if (!this.anim) this._firePose(dt);
|
|
358
453
|
}
|
|
359
454
|
/** @internal */
|
|
360
455
|
_animate(dt) {
|
|
@@ -362,7 +457,8 @@ export class Character {
|
|
|
362
457
|
this.phase += dt * (2.2 + sp * 1.25);
|
|
363
458
|
const s = Math.sin(this.phase);
|
|
364
459
|
// footstep event: fires once per foot landing (swing direction flips); model and procedural animation share this rhythm
|
|
365
|
-
|
|
460
|
+
// 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
|
|
461
|
+
if (this.grounded && sp > 0.4 && Math.sign(s) !== Math.sign(this._lastS ?? s)) this.engine.events.emit('character:step', { character: this });
|
|
366
462
|
this._lastS = s;
|
|
367
463
|
if (this.anim) {
|
|
368
464
|
const a = this.anim;
|