castle-web-cli 0.4.232 → 0.4.233
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/dist/agent-failures.d.ts +8 -0
- package/dist/agent-failures.js +19 -2
- package/dist/agent-prompts.d.ts +1 -1
- package/dist/agent-prompts.js +10 -3
- package/dist/agent.d.ts +64 -3
- package/dist/agent.js +170 -81
- package/dist/castle-host/host.d.ts +1 -0
- package/dist/castle-host/host.js +51 -3
- package/dist/castleJson.d.ts +4 -2
- package/dist/castleJson.js +2 -0
- package/dist/check.d.ts +3 -1
- package/dist/check.js +11 -1
- package/dist/devSessionStorage.js +47 -1
- package/dist/importPinMismatch.d.ts +22 -0
- package/dist/importPinMismatch.js +77 -0
- package/dist/importRegression.js +3 -15
- package/dist/imports.d.ts +10 -3
- package/dist/imports.js +88 -20
- package/dist/index.js +5 -4
- package/dist/init.js +1 -1
- package/dist/platformDoc.js +22 -0
- package/dist/routerFences.d.ts +5 -0
- package/dist/routerFences.js +12 -2
- package/dist/save-deck.d.ts +5 -0
- package/dist/save-deck.js +37 -4
- package/dist/serve.js +3 -0
- package/dist/shell/assets/{index-D2tWM896.js → index-BjOxR-lW.js} +4 -4
- package/dist/shell/assets/index-MVLfNYd9.css +1 -0
- package/dist/shell/index.html +2 -2
- package/dist/taskSteer.d.ts +13 -0
- package/dist/taskSteer.js +22 -2
- package/kits/base/castle.json +1 -1
- package/kits/base/package-lock.json +1 -1
- package/kits/base/sdk/README.md +79 -2
- package/kits/base/sdk/avatar.d.ts +6 -2
- package/kits/base/sdk/avatar.js +12 -4
- package/kits/base/sdk/castle.d.ts +1 -1
- package/kits/base/sdk/commands.d.ts +14 -0
- package/kits/base/sdk/hub.d.ts +6 -2
- package/kits/base/sdk/hub.js +13 -0
- package/kits/base/sdk/multiplayer.js +17 -1
- package/kits/base/sdk/save.js +2 -1
- package/kits/base/sdk/server/hub.d.ts +87 -0
- package/kits/base/sdk/server/hub.js +70 -0
- package/kits/base/sdk/server/platformHandle.d.ts +31 -1
- package/kits/base/sdk/server/storage.d.ts +13 -0
- package/kits/base/sdk/server/storage.js +46 -0
- package/kits/base/sdk/server/wrapper.d.ts +36 -5
- package/kits/base/sdk/server/wrapper.js +83 -8
- package/kits/hub-game/CLAUDE.md +329 -11
- package/kits/hub-game/blueprints/avatar-10.scene +28 -0
- package/kits/hub-game/blueprints/avatar-11.scene +28 -0
- package/kits/hub-game/blueprints/avatar-12.scene +28 -0
- package/kits/hub-game/blueprints/avatar-13.scene +28 -0
- package/kits/hub-game/blueprints/avatar-14.scene +28 -0
- package/kits/hub-game/blueprints/avatar-15.scene +28 -0
- package/kits/hub-game/blueprints/avatar-4.scene +28 -0
- package/kits/hub-game/blueprints/avatar-5.scene +28 -0
- package/kits/hub-game/blueprints/avatar-6.scene +28 -0
- package/kits/hub-game/blueprints/avatar-7.scene +28 -0
- package/kits/hub-game/blueprints/avatar-8.scene +28 -0
- package/kits/hub-game/blueprints/avatar-9.scene +28 -0
- package/kits/hub-game/code/client/actorBudget.js +47 -0
- package/kits/hub-game/code/client/attention.js +11 -2
- package/kits/hub-game/code/client/avatar.js +309 -35
- package/kits/hub-game/code/client/avatarCap.js +228 -0
- package/kits/hub-game/code/client/avatarColors.js +70 -0
- package/kits/hub-game/code/client/avatarFaces.js +21 -0
- package/kits/hub-game/code/client/avatarShare.js +251 -0
- package/kits/hub-game/code/client/ballot.js +467 -0
- package/kits/hub-game/code/client/build.js +22 -0
- package/kits/hub-game/code/client/chrome.js +1144 -50
- package/kits/hub-game/code/client/companion.js +716 -0
- package/kits/hub-game/code/client/companionDress.js +99 -0
- package/kits/hub-game/code/client/decor.js +509 -0
- package/kits/hub-game/code/client/earned.js +131 -0
- package/kits/hub-game/code/client/emoteBubble.js +75 -0
- package/kits/hub-game/code/client/grab.js +339 -20
- package/kits/hub-game/code/client/hookLayer.js +299 -13
- package/kits/hub-game/code/client/idle.js +163 -22
- package/kits/hub-game/code/client/interestCap.js +81 -0
- package/kits/hub-game/code/client/keys.js +36 -0
- package/kits/hub-game/code/client/labelsNear.js +205 -0
- package/kits/hub-game/code/client/menuIcons.js +34 -0
- package/kits/hub-game/code/client/pack.js +6 -2
- package/kits/hub-game/code/client/packFormat.js +3 -3
- package/kits/hub-game/code/client/rehello.js +167 -0
- package/kits/hub-game/code/client/shot.js +92 -0
- package/kits/hub-game/code/client/sound.js +63 -8
- package/kits/hub-game/code/client/soundscape.js +1151 -0
- package/kits/hub-game/code/client/soundscapeActions.js +99 -0
- package/kits/hub-game/code/client/soundscapeAmbience.js +453 -0
- package/kits/hub-game/code/client/soundscapeBaked.js +143 -0
- package/kits/hub-game/code/client/soundscapeBusker.js +217 -0
- package/kits/hub-game/code/client/soundscapeCourt.js +200 -0
- package/kits/hub-game/code/client/soundscapeCrowd.js +331 -0
- package/kits/hub-game/code/client/soundscapeCues.js +362 -0
- package/kits/hub-game/code/client/soundscapeMap.js +181 -0
- package/kits/hub-game/code/client/soundscapeMarket.js +176 -0
- package/kits/hub-game/code/client/soundscapeMusic.js +126 -0
- package/kits/hub-game/code/client/soundscapeMusicEngine.js +460 -0
- package/kits/hub-game/code/client/soundscapeSimlish.js +737 -0
- package/kits/hub-game/code/client/soundscapeSongs.js +127 -0
- package/kits/hub-game/code/client/soundscapeSongsRound3.js +63 -0
- package/kits/hub-game/code/client/soundscapeSynthesis.js +168 -0
- package/kits/hub-game/code/client/soundscapeUi.js +211 -0
- package/kits/hub-game/code/client/soundscapeVoice.js +1209 -0
- package/kits/hub-game/code/client/soundscapeWaves.js +206 -0
- package/kits/hub-game/code/client/spin.js +101 -0
- package/kits/hub-game/code/client/state.js +109 -1
- package/kits/hub-game/code/client/stuck.js +259 -0
- package/kits/hub-game/code/client/talk.js +538 -47
- package/kits/hub-game/code/client/tiers.js +516 -27
- package/kits/hub-game/code/client/toastBand.js +37 -0
- package/kits/hub-game/code/client/together.js +32 -0
- package/kits/hub-game/code/client/visibility.js +43 -0
- package/kits/hub-game/code/client/wear.js +461 -170
- package/kits/hub-game/code/client/yours.js +199 -0
- package/kits/hub-game/code/companionSpec.js +45 -0
- package/kits/hub-game/code/privateText.js +7 -0
- package/kits/hub-game/code/server/actions.js +133 -0
- package/kits/hub-game/code/server/actors.js +9 -1
- package/kits/hub-game/code/server/ask.js +155 -0
- package/kits/hub-game/code/server/ballot.js +539 -0
- package/kits/hub-game/code/server/cells.js +100 -0
- package/kits/hub-game/code/server/companion.js +82 -0
- package/kits/hub-game/code/server/cues.js +70 -0
- package/kits/hub-game/code/server/decor.js +269 -0
- package/kits/hub-game/code/server/earned.js +461 -0
- package/kits/hub-game/code/server/friendBests.js +166 -0
- package/kits/hub-game/code/server/friendsAmong.js +232 -0
- package/kits/hub-game/code/server/history.js +5 -0
- package/kits/hub-game/code/server/hub.js +1254 -50
- package/kits/hub-game/code/server/idle.js +30 -11
- package/kits/hub-game/code/server/index.js +2 -2
- package/kits/hub-game/code/server/labels.js +28 -2
- package/kits/hub-game/code/server/manifest.js +378 -7
- package/kits/hub-game/code/server/menu.js +133 -0
- package/kits/hub-game/code/server/npcs.js +830 -80
- package/kits/hub-game/code/server/party.js +2 -2
- package/kits/hub-game/code/server/players.js +22 -0
- package/kits/hub-game/code/server/shot.js +110 -0
- package/kits/hub-game/code/server/standing.js +124 -0
- package/kits/hub-game/code/server/vis.js +113 -0
- package/kits/hub-game/code/server/wear.js +12 -0
- package/kits/hub-game/code/server/yours.js +59 -0
- package/kits/hub-game/code/shared/cues.js +9 -0
- package/kits/hub-game/code/shared/decor.js +41 -0
- package/kits/hub-game/code/shared/shot.js +19 -0
- package/kits/hub-game/code/shared/spin.js +57 -0
- package/kits/hub-game/code/systems/hub.js +845 -95
- package/kits/hub-game/docs/content-pack.md +1 -1
- package/kits/hub-game/docs/contract.md +2244 -61
- package/kits/hub-game/docs/home-pieces.md +64 -0
- package/kits/hub-game/models/avatar-10.pxmodel +28 -0
- package/kits/hub-game/models/avatar-11.pxmodel +28 -0
- package/kits/hub-game/models/avatar-12.pxmodel +27 -0
- package/kits/hub-game/models/avatar-13.pxmodel +24 -0
- package/kits/hub-game/models/avatar-14.pxmodel +29 -0
- package/kits/hub-game/models/avatar-15.pxmodel +24 -0
- package/kits/hub-game/models/avatar-4.pxmodel +29 -0
- package/kits/hub-game/models/avatar-5.pxmodel +27 -0
- package/kits/hub-game/models/avatar-6.pxmodel +26 -0
- package/kits/hub-game/models/avatar-7.pxmodel +25 -0
- package/kits/hub-game/models/avatar-8.pxmodel +24 -0
- package/kits/hub-game/models/avatar-9.pxmodel +30 -0
- package/kits/hub-game/models/earned/badge-round.pxmodel +100 -0
- package/kits/hub-game/models/earned/badge-shield.pxmodel +117 -0
- package/kits/hub-game/models/earned/badge-star.pxmodel +87 -0
- package/kits/hub-game/models/earned/belt-plain.pxmodel +72 -0
- package/kits/hub-game/models/earned/held-ball.pxmodel +43 -0
- package/kits/hub-game/models/earned/held-lantern.pxmodel +85 -0
- package/kits/hub-game/models/earned/held-net.pxmodel +57 -0
- package/kits/hub-game/models/earned/held-trophy.pxmodel +109 -0
- package/kits/hub-game/models/earned/pin-round.pxmodel +62 -0
- package/kits/hub-game/models/earned/sash-plain.pxmodel +66 -0
- package/kits/hub-game/models/earned/square/belt-plain.pxmodel +104 -0
- package/kits/hub-game/models/earned/square/sash-plain.pxmodel +98 -0
- package/kits/hub-game/models/hats/bat-clip.pxmodel +206 -0
- package/kits/hub-game/models/hats/beekeeper.pxmodel +149 -0
- package/kits/hub-game/models/hats/cap.pxmodel +162 -0
- package/kits/hub-game/models/hats/captain.pxmodel +178 -0
- package/kits/hub-game/models/hats/crooked-top.pxmodel +172 -0
- package/kits/hub-game/models/hats/flower-crown.pxmodel +451 -0
- package/kits/hub-game/models/hats/foam-crown.pxmodel +179 -0
- package/kits/hub-game/models/hats/lantern.pxmodel +230 -0
- package/kits/hub-game/models/hats/laurel.pxmodel +533 -0
- package/kits/hub-game/models/hats/lighthouse.pxmodel +96 -0
- package/kits/hub-game/models/hats/sailor.pxmodel +141 -0
- package/kits/hub-game/models/hats/souwester.pxmodel +131 -0
- package/kits/hub-game/models/hats/straw.pxmodel +139 -0
- package/kits/hub-game/models/hats/sunflower.pxmodel +406 -0
- package/kits/hub-game/models/hats/sweatband.pxmodel +112 -0
- package/kits/hub-game/models/hats/witch.pxmodel +147 -0
- package/kits/hub-game/package-lock.json +2 -0
- package/kits/hub-game/package.json +2 -1
- package/kits/hub-game/scripts/check.mjs +78 -11
- package/kits/hub-game/scripts/companion-follower-wire.json +1 -0
- package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +121 -0
- package/kits/hub-game/scripts/fixtures/decor-keyless.json +293 -0
- package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +23 -0
- package/kits/hub-game/scripts/fixtures/fake-dom.mjs +107 -0
- package/kits/hub-game/scripts/fixtures/interest-legacy.json +385 -0
- package/kits/hub-game/scripts/fixtures/npc-notes-v1.77.jsonl +4 -0
- package/kits/hub-game/scripts/fixtures/vis-shared-wire.json +1 -0
- package/kits/hub-game/scripts/gen-avatars.mjs +933 -16
- package/kits/hub-game/scripts/gen-earned.mjs +285 -0
- package/kits/hub-game/scripts/gen-hats.mjs +827 -0
- package/kits/hub-game/scripts/grab.before-orbit.mjs +400 -0
- package/kits/hub-game/scripts/soundscape-wave-analysis.mjs +125 -0
- package/kits/hub-game/scripts/test-actions-client.mjs +488 -0
- package/kits/hub-game/scripts/test-actions.mjs +298 -0
- package/kits/hub-game/scripts/test-actor-budget.mjs +44 -0
- package/kits/hub-game/scripts/test-actors.mjs +19 -17
- package/kits/hub-game/scripts/test-ask-client.mjs +358 -0
- package/kits/hub-game/scripts/test-ask.mjs +269 -0
- package/kits/hub-game/scripts/test-attention.mjs +10 -1
- package/kits/hub-game/scripts/test-avatar-cap.mjs +379 -0
- package/kits/hub-game/scripts/test-avatar-colors.mjs +72 -0
- package/kits/hub-game/scripts/test-avatar-models.mjs +181 -0
- package/kits/hub-game/scripts/test-avatar-share.mjs +318 -0
- package/kits/hub-game/scripts/test-avatar-wire.mjs +753 -0
- package/kits/hub-game/scripts/test-avatar.mjs +540 -7
- package/kits/hub-game/scripts/test-ballot.mjs +1001 -0
- package/kits/hub-game/scripts/test-build.mjs +31 -0
- package/kits/hub-game/scripts/test-cells.mjs +71 -0
- package/kits/hub-game/scripts/test-chat.mjs +662 -0
- package/kits/hub-game/scripts/test-classic.mjs +2 -0
- package/kits/hub-game/scripts/test-companion-chat.mjs +198 -0
- package/kits/hub-game/scripts/test-companion-client.mjs +1167 -0
- package/kits/hub-game/scripts/test-companion.mjs +259 -0
- package/kits/hub-game/scripts/test-decor-client.mjs +303 -0
- package/kits/hub-game/scripts/test-decor.mjs +457 -0
- package/kits/hub-game/scripts/test-earned-client.mjs +459 -0
- package/kits/hub-game/scripts/test-earned.mjs +1194 -0
- package/kits/hub-game/scripts/test-emote-bubble.mjs +110 -0
- package/kits/hub-game/scripts/test-friend-bests.mjs +435 -0
- package/kits/hub-game/scripts/test-grab-orbit.mjs +918 -0
- package/kits/hub-game/scripts/test-grab.mjs +7 -0
- package/kits/hub-game/scripts/test-hats.mjs +422 -168
- package/kits/hub-game/scripts/test-hub-leaving.mjs +203 -0
- package/kits/hub-game/scripts/test-hub-ops.mjs +439 -2
- package/kits/hub-game/scripts/test-hub-trip.mjs +716 -2
- package/kits/hub-game/scripts/test-hud-clear.mjs +328 -4
- package/kits/hub-game/scripts/test-idle.mjs +361 -1
- package/kits/hub-game/scripts/test-interest-cap.mjs +36 -0
- package/kits/hub-game/scripts/test-interest-cells.mjs +493 -0
- package/kits/hub-game/scripts/test-interest-client.mjs +118 -0
- package/kits/hub-game/scripts/test-keys.mjs +46 -1
- package/kits/hub-game/scripts/test-labels.mjs +596 -0
- package/kits/hub-game/scripts/test-manifest.mjs +207 -0
- package/kits/hub-game/scripts/test-menu-client.mjs +480 -0
- package/kits/hub-game/scripts/test-menu.mjs +296 -0
- package/kits/hub-game/scripts/test-npcs.mjs +1718 -12
- package/kits/hub-game/scripts/test-object-entry.mjs +76 -0
- package/kits/hub-game/scripts/test-pack.mjs +7 -0
- package/kits/hub-game/scripts/test-picker.mjs +314 -0
- package/kits/hub-game/scripts/test-rehello.mjs +1039 -0
- package/kits/hub-game/scripts/test-relations-among.mjs +222 -0
- package/kits/hub-game/scripts/test-relations-refresh.mjs +188 -0
- package/kits/hub-game/scripts/test-shot.mjs +756 -0
- package/kits/hub-game/scripts/test-soundscape.mjs +5432 -0
- package/kits/hub-game/scripts/test-spin.mjs +314 -0
- package/kits/hub-game/scripts/test-standing.mjs +416 -0
- package/kits/hub-game/scripts/test-stuck.mjs +1903 -0
- package/kits/hub-game/scripts/test-tier-cells.mjs +706 -0
- package/kits/hub-game/scripts/test-tiers-render.mjs +339 -0
- package/kits/hub-game/scripts/test-tiers.mjs +477 -2
- package/kits/hub-game/scripts/test-toast-band.mjs +61 -0
- package/kits/hub-game/scripts/test-try-on.mjs +22 -22
- package/kits/hub-game/scripts/test-vis.mjs +343 -0
- package/kits/hub-game/scripts/test-visibility.mjs +134 -0
- package/kits/hub-game/scripts/test-yours-chrome.mjs +166 -0
- package/kits/hub-game/scripts/test-yours.mjs +372 -0
- package/kits/multiplayer-3d/CLAUDE.md +50 -0
- package/kits/multiplayer-3d/castle.json +5 -5
- package/kits/multiplayer-3d/code/client/avatars.js +7 -0
- package/kits/multiplayer-3d/code/client/gait.js +65 -0
- package/kits/multiplayer-3d/code/client/nameTags.js +59 -4
- package/kits/multiplayer-3d/code/options.js +5 -0
- package/kits/multiplayer-3d/code/server/ownership.js +10 -2
- package/kits/multiplayer-3d/code/server/sceneBodies.js +12 -0
- package/kits/multiplayer-3d/code/server/world.js +7 -0
- package/kits/multiplayer-3d/code/systems/multiplayer.js +74 -4
- package/kits/multiplayer-3d/package.json +2 -1
- package/kits/multiplayer-3d/scripts/fixtures/README.md +11 -0
- package/kits/multiplayer-3d/scripts/fixtures/ownership-legacy.json +2 -0
- package/kits/multiplayer-3d/scripts/ownership-harness.mjs +102 -0
- package/kits/multiplayer-3d/scripts/ownership-loader.mjs +46 -0
- package/kits/multiplayer-3d/scripts/ownership-worker.mjs +15 -0
- package/kits/multiplayer-3d/scripts/record-ownership-session.mjs +98 -0
- package/kits/multiplayer-3d/scripts/test-eligible-claims.mjs +167 -0
- package/kits/multiplayer-3d/scripts/test-own-name-tag.mjs +247 -0
- package/kits/physics-2d/CLAUDE.md +9 -0
- package/kits/physics-2d/castle.json +2 -2
- package/kits/physics-2d/engine/scene.js +253 -1
- package/kits/physics-2d/engine/skyKey.js +129 -0
- package/kits/physics-2d/engine/stillClock.js +106 -0
- package/kits/physics-2d/engine/updateBudget.js +21 -0
- package/kits/physics-2d/scripts/test-skip-unchanged.mjs +326 -1
- package/kits/physics-3d/CLAUDE.md +1169 -30
- package/kits/physics-3d/behaviors/Player.jsx +629 -72
- package/kits/physics-3d/castle.json +3 -3
- package/kits/physics-3d/docs/pxmodel-format.md +8 -0
- package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +69 -13
- package/kits/physics-3d/engine3d/actornode.js +86 -0
- package/kits/physics-3d/engine3d/animationBudget.js +23 -0
- package/kits/physics-3d/engine3d/editorWorld.js +6 -0
- package/kits/physics-3d/engine3d/emptynodes.js +232 -0
- package/kits/physics-3d/engine3d/framecap.js +96 -0
- package/kits/physics-3d/engine3d/gait.js +118 -0
- package/kits/physics-3d/engine3d/kithooks.js +47 -0
- package/kits/physics-3d/engine3d/look.js +507 -48
- package/kits/physics-3d/engine3d/lookbake.js +208 -0
- package/kits/physics-3d/engine3d/materialpresets.js +2 -0
- package/kits/physics-3d/engine3d/motion.js +39 -10
- package/kits/physics-3d/engine3d/nearshadows.js +37 -19
- package/kits/physics-3d/engine3d/optimize.js +9 -5
- package/kits/physics-3d/engine3d/orbitinput.js +487 -9
- package/kits/physics-3d/engine3d/orbitlens.js +48 -0
- package/kits/physics-3d/engine3d/ownmodel.js +213 -0
- package/kits/physics-3d/engine3d/pxmodel.js +42 -11
- package/kits/physics-3d/engine3d/shadowfade.js +882 -0
- package/kits/physics-3d/engine3d/sky.js +547 -0
- package/kits/physics-3d/engine3d/skylife.js +306 -0
- package/kits/physics-3d/engine3d/unchanged.js +11 -0
- package/kits/physics-3d/engine3d/viewrange.js +52 -0
- package/kits/physics-3d/engine3d/world3d.js +796 -69
- package/kits/physics-3d/main.jsx +5 -0
- package/kits/physics-3d/package.json +1 -1
- package/kits/physics-3d/scripts/look-baseline.mjs +155 -0
- package/kits/physics-3d/scripts/test-camera-orbit.mjs +2563 -80
- package/kits/physics-3d/scripts/test-drop-empty-parts.mjs +1 -1
- package/kits/physics-3d/scripts/test-frame-cap-bob.mjs +435 -0
- package/kits/physics-3d/scripts/test-frame-cap.mjs +452 -0
- package/kits/physics-3d/scripts/test-gait.mjs +387 -0
- package/kits/physics-3d/scripts/test-look-bake.mjs +1056 -0
- package/kits/physics-3d/scripts/test-model-parse-cache.mjs +92 -0
- package/kits/physics-3d/scripts/test-near-shadows.mjs +3 -0
- package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +1920 -0
- package/kits/physics-3d/scripts/test-orbit-shift-lock.mjs +545 -0
- package/kits/physics-3d/scripts/test-orbit-shot.mjs +583 -0
- package/kits/physics-3d/scripts/test-orbit-view.mjs +230 -0
- package/kits/physics-3d/scripts/test-skip-empty-nodes.mjs +845 -0
- package/kits/physics-3d/scripts/test-sky.mjs +2470 -0
- package/kits/physics-3d/scripts/test-static-actors.mjs +8 -1
- package/kits/physics-3d/scripts/test-static-scenery.mjs +2171 -0
- package/kits/physics-3d/scripts/test-steady-hover.mjs +2 -0
- package/kits/physics-3d/scripts/test-view-range.mjs +260 -0
- package/kits/physics-3d/systems/physics3d.js +383 -6
- package/kits/real-time/castle.json +2 -2
- package/kits/real-time/code/server/gameHooks.js +7 -0
- package/kits/real-time/code/server/session.js +97 -19
- package/package.json +2 -2
- package/dist/shell/assets/index-Cf61cNfT.css +0 -1
|
@@ -11,8 +11,12 @@
|
|
|
11
11
|
// simulating on the first frame after init resolves.
|
|
12
12
|
import * as THREE from 'three';
|
|
13
13
|
import * as RAPIER from '@dimforge/rapier3d-compat';
|
|
14
|
-
import { remember, sameAs } from '../engine3d/unchanged.js';
|
|
14
|
+
import { remember, sameAs, noteChangedStill } from '../engine3d/unchanged.js';
|
|
15
15
|
import { isOrbitLook } from '../engine3d/orbitinput.js';
|
|
16
|
+
import { giveBackOrbitLens } from '../engine3d/orbitlens.js';
|
|
17
|
+
import { giveBackViewRange } from '../engine3d/viewrange.js';
|
|
18
|
+
import { leaveSky } from '../engine3d/skylife.js';
|
|
19
|
+
import { dropShadowFade } from '../engine3d/shadowfade.js';
|
|
16
20
|
|
|
17
21
|
const FIXED_STEP = 1 / 60;
|
|
18
22
|
const MAX_STEPS_PER_FRAME = 4;
|
|
@@ -38,13 +42,15 @@ function ensureRapierInit() {
|
|
|
38
42
|
// with (behaviors run before physics, and see last frame's). It is placed on a
|
|
39
43
|
// frame physics could not step too (rapier still loading). A request is used
|
|
40
44
|
// once, and only while the scene it was made for is loaded; a load and a
|
|
41
|
-
// dispose drop it (`reset`).
|
|
42
|
-
//
|
|
45
|
+
// dispose drop it (`reset`). A scene that capped its frame rate
|
|
46
|
+
// (`"engine": { "maxFps": n }`) asks for its keyless follow camera the same
|
|
47
|
+
// way (Player.jsx `placeCapped`). Without either key nothing is asked for, and
|
|
48
|
+
// this reads one property and returns.
|
|
43
49
|
export function placeFollowCamera(scene) {
|
|
44
50
|
const request = scene.followCamera;
|
|
45
51
|
if (!request) return;
|
|
46
52
|
scene.followCamera = null;
|
|
47
|
-
if (scene.cameraFollowsRigidly !== true || request.data !== scene.data) return;
|
|
53
|
+
if ((scene.cameraFollowsRigidly !== true && !(scene.maxFps > 0)) || request.data !== scene.data) return;
|
|
48
54
|
request.place(scene, request.id, request.dt);
|
|
49
55
|
}
|
|
50
56
|
|
|
@@ -95,6 +101,7 @@ export class Physics3DSystem {
|
|
|
95
101
|
// What a skipping pass wrote down goes with the world it was written for.
|
|
96
102
|
this.remembered = null;
|
|
97
103
|
this.rememberedIn = null;
|
|
104
|
+
if (this.stillKeeper) this.stillKeeper.interrupt();
|
|
98
105
|
// A force asked for and not yet used goes with it.
|
|
99
106
|
this.forces = null;
|
|
100
107
|
// A follow camera asked for before the load goes with the scene it was
|
|
@@ -107,6 +114,36 @@ export class Physics3DSystem {
|
|
|
107
114
|
// And a facing asked for under the key and not yet taken, whether or not
|
|
108
115
|
// the orbit input was ever made (only a keyed scene asks for one).
|
|
109
116
|
if (runtime?.faceRequest !== undefined) runtime.faceRequest = undefined;
|
|
117
|
+
// And the actor a keyed Player named for this frame's draw (engine3d/
|
|
118
|
+
// ownmodel.js): a load between its placement and the draw leaves the
|
|
119
|
+
// new scene's frame drawn whole. Only a keyed Player ever names one.
|
|
120
|
+
if (runtime?.orbitOwnModel !== undefined) runtime.orbitOwnModel = undefined;
|
|
121
|
+
// And the lens the orbit key put on the world camera (engine3d/
|
|
122
|
+
// orbitlens.js): given back here, at the start of the load, so the next
|
|
123
|
+
// scene's own code starts from the lens the camera had before the key
|
|
124
|
+
// and what it sets stands. A world that never played the key has none.
|
|
125
|
+
if (runtime?.three?.orbitLens) giveBackOrbitLens(runtime.three);
|
|
126
|
+
if (runtime?.three?.viewRange) giveBackViewRange(runtime.three);
|
|
127
|
+
// And the sky the scene being left had (engine3d/skylife.js): disposed
|
|
128
|
+
// here unless a frame of the world is being drawn, when that frame
|
|
129
|
+
// disposes it on its way out. A world that never played the key has
|
|
130
|
+
// none. Null is the only success sentinel; a falsy thrown value is still
|
|
131
|
+
// an error and stops the load after the record has been released.
|
|
132
|
+
if (runtime?.three?.sky) {
|
|
133
|
+
const failed = leaveSky(runtime.three, runtime.sky);
|
|
134
|
+
if (failed !== null) throw failed;
|
|
135
|
+
}
|
|
136
|
+
// And the materials the near shadows' far edge fades out on
|
|
137
|
+
// (engine3d/shadowfade.js): the world's variants of them are disposed.
|
|
138
|
+
// A world that never played both keys has none. Through the world's
|
|
139
|
+
// outside-call bracket (world3d.js), which every world that drew a fade
|
|
140
|
+
// made for its near shadows.
|
|
141
|
+
const world = runtime?.three;
|
|
142
|
+
if (world?.shadowFade) {
|
|
143
|
+
const call = world.nearShadowCall;
|
|
144
|
+
if (typeof call === 'function') call(() => dropShadowFade(world));
|
|
145
|
+
else dropShadowFade(world);
|
|
146
|
+
}
|
|
110
147
|
}
|
|
111
148
|
|
|
112
149
|
dispose(runtime) {
|
|
@@ -120,6 +157,27 @@ export class Physics3DSystem {
|
|
|
120
157
|
|
|
121
158
|
simulate(scene, dt) {
|
|
122
159
|
if (!rapierReady) return;
|
|
160
|
+
// A system that has held bodies still, or a scene that asks to
|
|
161
|
+
// (`"engine": { "staticActors": true }`): the same pass, whatever its
|
|
162
|
+
// kind, seen in and out by the system's keeper (`simulateKept`, below).
|
|
163
|
+
if (this.stillKeeper || scene.keepsStaticActors === true) {
|
|
164
|
+
this.simulateKept(scene, dt);
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
// Every other pass is counted while it runs, and that is all: nothing in
|
|
168
|
+
// a system without a keeper reads the count. It is what tells a keeper
|
|
169
|
+
// made from inside this pass (a collision callback that updates a scene
|
|
170
|
+
// that asks) that a pass it never saw enter is running around it.
|
|
171
|
+
this.unkept = (this.unkept ?? 0) + 1;
|
|
172
|
+
try {
|
|
173
|
+
this.simulateAsEver(scene, dt);
|
|
174
|
+
} finally {
|
|
175
|
+
this.unkept -= 1;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// `simulate` as it always was.
|
|
180
|
+
simulateAsEver(scene, dt) {
|
|
123
181
|
this.ensureWorld(scene);
|
|
124
182
|
// A force is for the frame it was asked in: one left from a frame whose
|
|
125
183
|
// pass did not run, or asked after that frame's pass (from a collision
|
|
@@ -359,6 +417,160 @@ export class Physics3DSystem {
|
|
|
359
417
|
this.dispatchCallbacks(scene);
|
|
360
418
|
}
|
|
361
419
|
|
|
420
|
+
// `simulate` for a system with a keeper, or a scene that asks for one. The
|
|
421
|
+
// invariant is the world's (world3d.js `syncActorsKept`), about entry
|
|
422
|
+
// points and not kinds of pass:
|
|
423
|
+
//
|
|
424
|
+
// From the moment a physics system has a keeper, the keeper sees EVERY
|
|
425
|
+
// entry into and exit from `simulate`, of every kind (plain, skipping,
|
|
426
|
+
// settled, ordinary; any runtime). An adoption can be recorded only by a
|
|
427
|
+
// pass that was alone from its entry to its exit, and any pass of any
|
|
428
|
+
// kind that enters, or is running, drops it.
|
|
429
|
+
//
|
|
430
|
+
// `simulate` is the one function through which this system's bodies are
|
|
431
|
+
// made, removed, pushed, stepped and written back (`reconcileBodies`,
|
|
432
|
+
// `reconcileUnchanged`, `pushTransforms`, `pushUnchanged`, `step`,
|
|
433
|
+
// `writeBack`, `dispatchCallbacks` are reached only from it); `reset`, the
|
|
434
|
+
// other, reports to the keeper, and its world's adoption is not this
|
|
435
|
+
// world's. The `scene.physics3d` calls that move one body (`setVelocity`,
|
|
436
|
+
// `applyImpulse`, `addForce`) touch the actor they are handed.
|
|
437
|
+
// - A pass that holds nothing still (its scene did not ask) is counted in,
|
|
438
|
+
// drops whatever was adopted before it does anything, runs as it always
|
|
439
|
+
// did, and never adopts on its way out.
|
|
440
|
+
// - A pass of a scene that asks is `afterBehaviorsStill`.
|
|
441
|
+
// - A pass that entered BEFORE the system had a keeper was not seen
|
|
442
|
+
// entering: `this.unkept` counts those while they run, and while it is
|
|
443
|
+
// not zero no pass is settled and none adopts.
|
|
444
|
+
simulateKept(scene, dt) {
|
|
445
|
+
const keeper = (this.stillKeeper ??= scene.newStillKeeper());
|
|
446
|
+
if (scene.keepsStaticActors === true) {
|
|
447
|
+
this.ensureWorld(scene);
|
|
448
|
+
if (this.forces && this.forcesAt !== scene.time) this.forces = null;
|
|
449
|
+
if (!this.remembered || this.rememberedIn !== this.world) {
|
|
450
|
+
this.remembered = new WeakMap();
|
|
451
|
+
this.rememberedIn = this.world;
|
|
452
|
+
}
|
|
453
|
+
this.afterBehaviorsStill(scene, dt);
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
const pass = keeper.begin(-1);
|
|
457
|
+
try {
|
|
458
|
+
this.simulateAsEver(scene, dt);
|
|
459
|
+
} finally {
|
|
460
|
+
keeper.end(pass, false);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
// `afterBehaviorsSkipping` for a scene that also set `"engine":
|
|
465
|
+
// { "staticActors": true }` (world3d.js has the rule; CLAUDE.md the terms).
|
|
466
|
+
// A pass is ordinary, every actor as above, unless this system has adopted
|
|
467
|
+
// the runtime's still set, in this same rapier world; then the still
|
|
468
|
+
// actors' bodies, which are fixed and where that pass put them, are left
|
|
469
|
+
// alone.
|
|
470
|
+
//
|
|
471
|
+
// The adoption is kept by the system's StillKeeper (physics-2d
|
|
472
|
+
// engine/stillClock.js has it and the rule it is) and nowhere else: it
|
|
473
|
+
// counts this entry before the pass does anything; it adopts only in the
|
|
474
|
+
// `finally` of a pass that ran the reconcile, the push, rapier's step, the
|
|
475
|
+
// write-back and the collision callbacks and returned, with nobody having
|
|
476
|
+
// entered, no pass the keeper never saw running (`this.unkept`), and the
|
|
477
|
+
// still set unmoved. Nothing is put back: a pass that was interrupted
|
|
478
|
+
// leaves no adoption. What this system adds to an adoption is the rapier
|
|
479
|
+
// world it was made in and how many still actors have a body. An actor is
|
|
480
|
+
// adopted only with a fixed body, so one whose body something made dynamic
|
|
481
|
+
// or kinematic is touched instead.
|
|
482
|
+
afterBehaviorsStill(scene, dt) {
|
|
483
|
+
const keeper = this.stillKeeper;
|
|
484
|
+
const set = scene.stillActors;
|
|
485
|
+
const pass = keeper.begin(scene.stillVersion);
|
|
486
|
+
if (pass.settled && !(set && keeper.adopted.world === this.world && !(this.unkept > 0))) keeper.demote(pass);
|
|
487
|
+
const bodies = pass.settled ? keeper.adopted.bodies : 0;
|
|
488
|
+
let completed = false;
|
|
489
|
+
try {
|
|
490
|
+
this.stillPass(scene, dt, pass.settled ? set : null, bodies);
|
|
491
|
+
completed = true;
|
|
492
|
+
} finally {
|
|
493
|
+
keeper.end(pass, completed && !(this.unkept > 0), scene.stillVersion, () => (set && set.size > 0 && scene.stillActors === set ? this.adoptStill(scene, set) : null));
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
// The pass itself: every actor, or, when `still` is the set a pass before
|
|
498
|
+
// adopted, every actor but those.
|
|
499
|
+
stillPass(scene, dt, still, stillBodies) {
|
|
500
|
+
const all = scene.getActors();
|
|
501
|
+
let actors = all;
|
|
502
|
+
if (still) {
|
|
503
|
+
actors = all.filter((actor) => !still.has(actor));
|
|
504
|
+
this.reconcileLive(actors, still, scene, stillBodies);
|
|
505
|
+
if (scene.three?.auditStatic > 0) this.auditStill(scene, still);
|
|
506
|
+
} else {
|
|
507
|
+
this.reconcileUnchanged(all);
|
|
508
|
+
}
|
|
509
|
+
const dynamic = this.pushUnchanged(actors);
|
|
510
|
+
this.step(dt);
|
|
511
|
+
this.writeBack({ getActors: () => dynamic });
|
|
512
|
+
this.dispatchCallbacks(scene);
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
// `reconcileUnchanged` for the actors that are not still: a body with
|
|
516
|
+
// neither this pass's mark nor a still actor has lost its actor.
|
|
517
|
+
reconcileLive(actors, still, scene, stillBodies) {
|
|
518
|
+
this.pass = (this.pass ?? 0) + 1;
|
|
519
|
+
const pass = this.pass;
|
|
520
|
+
let marked = stillBodies;
|
|
521
|
+
for (const actor of actors) {
|
|
522
|
+
if (!actor.components.Transform) continue;
|
|
523
|
+
const entry = this.bodyFor(actor);
|
|
524
|
+
if (entry.pass === pass) continue;
|
|
525
|
+
entry.pass = pass;
|
|
526
|
+
marked += 1;
|
|
527
|
+
}
|
|
528
|
+
if (marked === this.bodies.size) return;
|
|
529
|
+
for (const [id, entry] of [...this.bodies]) {
|
|
530
|
+
if (entry.pass !== pass && !still.has(scene.getActor(id))) this.removeBody(id);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
// On the way out of an ordinary pass that completed: the still actors'
|
|
535
|
+
// bodies are counted, and from the next pass on are left alone. Returns
|
|
536
|
+
// what to keep, or null when a still actor's body is not fixed (the actor
|
|
537
|
+
// is touched; the pass after that adopts the rest).
|
|
538
|
+
adoptStill(scene, set) {
|
|
539
|
+
if (!this.world) return null;
|
|
540
|
+
let bodies = 0;
|
|
541
|
+
const moved = [];
|
|
542
|
+
for (const actor of set) {
|
|
543
|
+
const entry = actor.components.Transform ? this.bodies.get(actor.id) : null;
|
|
544
|
+
if (!entry) continue;
|
|
545
|
+
if (entry.body.bodyType() === RAPIER.RigidBodyType.Fixed) bodies += 1;
|
|
546
|
+
else moved.push(actor);
|
|
547
|
+
}
|
|
548
|
+
if (moved.length > 0) {
|
|
549
|
+
for (const actor of moved) scene.touch(actor);
|
|
550
|
+
return null;
|
|
551
|
+
}
|
|
552
|
+
return { world: this.world, bodies };
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
// `world.auditStatic` (QA only; world3d.js): every still actor's body
|
|
556
|
+
// against what an ordinary pass would have found.
|
|
557
|
+
auditStill(scene, set) {
|
|
558
|
+
for (const actor of [...set]) {
|
|
559
|
+
const entry = this.bodies.get(actor.id);
|
|
560
|
+
const t = actor.components.Transform;
|
|
561
|
+
const made = entry && this.remembered.get(entry);
|
|
562
|
+
let what = null;
|
|
563
|
+
if (!t || !entry || !made) what = t || entry ? 'its Transform or its body (gone)' : null;
|
|
564
|
+
else if (!madeTheSame(made.madeFrom, actor)) what = 'a component its body is made from';
|
|
565
|
+
else if (entry.body.bodyType() !== RAPIER.RigidBodyType.Fixed) what = "its body's type";
|
|
566
|
+
else if (!alreadyPushed(entry, made, t)) what = 'its Transform (where its body is)';
|
|
567
|
+
if (!what) continue;
|
|
568
|
+
// Touched first: the note warns on the console, which is not the engine's.
|
|
569
|
+
scene.touch(actor);
|
|
570
|
+
noteChangedStill(scene.three, actor.id, what);
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
|
|
362
574
|
reconcileUnchanged(actors) {
|
|
363
575
|
// Each body whose actor is still here is marked with this pass's count; a
|
|
364
576
|
// body without the mark afterwards has lost its actor.
|
|
@@ -568,8 +780,17 @@ function makeApi(system, runtime) {
|
|
|
568
780
|
const v = bodyOf(actor)?.linvel();
|
|
569
781
|
return v ? { x: v.x, y: v.y, z: v.z } : { x: 0, y: 0, z: 0 };
|
|
570
782
|
},
|
|
571
|
-
|
|
572
|
-
|
|
783
|
+
// Each of these that moves a body says so first (`touch`: a scene that
|
|
784
|
+
// set `"engine": { "staticActors": true }` holds some actors still). An
|
|
785
|
+
// actor that is not still, or a scene without the key, is not affected.
|
|
786
|
+
setVelocity: (actor, v) => {
|
|
787
|
+
runtime.touch?.(actor);
|
|
788
|
+
return bodyOf(actor)?.setLinvel(v, true);
|
|
789
|
+
},
|
|
790
|
+
applyImpulse: (actor, v) => {
|
|
791
|
+
runtime.touch?.(actor);
|
|
792
|
+
return bodyOf(actor)?.applyImpulse(v, true);
|
|
793
|
+
},
|
|
573
794
|
// A force on the actor's body through the fixed steps of this frame's
|
|
574
795
|
// physics pass and no longer, asked from a behavior's `update`: it acts
|
|
575
796
|
// once per step, as gravity does, where an impulse acts once per frame.
|
|
@@ -580,6 +801,7 @@ function makeApi(system, runtime) {
|
|
|
580
801
|
const id = idOf(actor);
|
|
581
802
|
const body = system.world && system.bodies.get(id)?.body;
|
|
582
803
|
if (!body) return;
|
|
804
|
+
runtime.touch?.(actor);
|
|
583
805
|
if (system.forces && system.forcesAt !== runtime.time) system.forces = null;
|
|
584
806
|
system.forcesAt = runtime.time;
|
|
585
807
|
const forces = (system.forces ??= new Map());
|
|
@@ -619,5 +841,160 @@ function makeApi(system, runtime) {
|
|
|
619
841
|
const hit = system.world?.castRay(new RAPIER.Ray(origin, dir), maxToi, true, fixedSolids());
|
|
620
842
|
return hit ? { distance: hit.timeOfImpact, actorId: system.byCollider.get(hit.collider.handle) ?? null } : null;
|
|
621
843
|
},
|
|
844
|
+
// The orbit camera's lens (behaviors/Player.jsx, under the orbit key
|
|
845
|
+
// only; nothing else calls these three), against what `castRayFixed`
|
|
846
|
+
// meets. `castRayFixedNormal`: what `castRayFixed` finds, with the unit
|
|
847
|
+
// `normal` of the surface there, facing the ray's origin.
|
|
848
|
+
castRayFixedNormal: (origin, dir, maxToi) => {
|
|
849
|
+
const met = system.world?.castRayAndGetNormal(new RAPIER.Ray(origin, dir), maxToi, true, fixedSolids());
|
|
850
|
+
if (!met) return null;
|
|
851
|
+
const n = met.normal;
|
|
852
|
+
return { distance: met.timeOfImpact, actorId: system.byCollider.get(met.collider.handle) ?? null, normal: { x: n.x, y: n.y, z: n.z } };
|
|
853
|
+
},
|
|
854
|
+
// `castBallFixed`: a ball of `radius` swept from `origin` along the unit
|
|
855
|
+
// `dir`, no farther than `maxToi`; the first fixed solid it touches, as
|
|
856
|
+
// `{ distance, actorId, normal }` (how far the ball's middle got, and the
|
|
857
|
+
// surface's unit normal there, facing the ball), or null. A ball that
|
|
858
|
+
// starts touching something is not answered reliably by rapier, so the
|
|
859
|
+
// caller starts it clear (`nearFixed`). Nor is the sweep itself: where
|
|
860
|
+
// rapier stops the ball is off by an amount that changes from one place
|
|
861
|
+
// to the next (short by centimetres against the ground or tens of
|
|
862
|
+
// centimetres along a wall met at a grazing angle, past the surface by up
|
|
863
|
+
// to 2 cm when the ball starts within a few centimetres of one), in a
|
|
864
|
+
// corner it can name the second solid the ball meets instead of the
|
|
865
|
+
// first, and now and then it misses a solid outright (review 8: a box
|
|
866
|
+
// the ball passes through, at one radius and not at a millimetre more).
|
|
867
|
+
// So rapier's answer is only where to look:
|
|
868
|
+
// - the ball is put where it touches the plane that touches the solid
|
|
869
|
+
// where it was met (exact on a face; on an edge or a corner of a
|
|
870
|
+
// convex solid the solid is all behind that plane: `touchingAt`), or
|
|
871
|
+
// at `maxToi` when rapier met nothing;
|
|
872
|
+
// - a ray along the line, that far, keeps the line of sight: a solid it
|
|
873
|
+
// meets nearer brings the ball in to it;
|
|
874
|
+
// - the place is checked with an overlap query, the ball BALL_TOLERANCE
|
|
875
|
+
// smaller. Another solid in the way there is swept against alone and
|
|
876
|
+
// the ball put where it touches that one, BALL_RECHECKS times at most;
|
|
877
|
+
// - a place still not clear (rapier missed that solid again) is found by
|
|
878
|
+
// halving between the start (clear) and it with overlap queries, to
|
|
879
|
+
// BALL_BISECT or BALL_HALVINGS halvings.
|
|
880
|
+
// Queries: three as a rule (the sweep, the ray, one overlap); at most
|
|
881
|
+
// 3 + 2 * BALL_RECHECKS + BALL_HALVINGS, 25.
|
|
882
|
+
castBallFixed: (origin, dir, maxToi, radius) => {
|
|
883
|
+
if (!system.world || !(radius > 0)) return null;
|
|
884
|
+
const swept = sweepBall(system.world, origin, dir, maxToi, radius);
|
|
885
|
+
if (!swept.met) return null;
|
|
886
|
+
const n = swept.normal;
|
|
887
|
+
return { distance: swept.distance, actorId: system.byCollider.get(swept.met.handle) ?? null, normal: { x: n.x, y: n.y, z: n.z } };
|
|
888
|
+
},
|
|
889
|
+
// `nearFixed`: every fixed solid within `within` of `point`, each as
|
|
890
|
+
// `{ distance, inside, normal, point, actorId }`: its nearest point to
|
|
891
|
+
// `point` and the unit normal from there to `point` (a plane that
|
|
892
|
+
// touches the solid there and, for a convex solid, has all of it
|
|
893
|
+
// behind); `inside` (and no normal) for a point inside one. An empty
|
|
894
|
+
// list when there is none that near.
|
|
895
|
+
nearFixed: (point, within) => {
|
|
896
|
+
const found = [];
|
|
897
|
+
if (!system.world || !(within > 0)) return found;
|
|
898
|
+
system.world.intersectionsWithShape(point, UNTURNED, new RAPIER.Ball(within), (collider) => {
|
|
899
|
+
const near = collider.projectPoint(point, false);
|
|
900
|
+
if (!near) return true;
|
|
901
|
+
const actorId = system.byCollider.get(collider.handle) ?? null;
|
|
902
|
+
const at = { x: near.point.x, y: near.point.y, z: near.point.z };
|
|
903
|
+
const distance = Math.hypot(point.x - at.x, point.y - at.y, point.z - at.z);
|
|
904
|
+
const normal = near.isInside || !(distance > 0) ? null : { x: (point.x - at.x) / distance, y: (point.y - at.y) / distance, z: (point.z - at.z) / distance };
|
|
905
|
+
found.push({ distance: near.isInside ? 0 : distance, inside: near.isInside, normal, point: at, actorId });
|
|
906
|
+
return true;
|
|
907
|
+
}, fixedSolids());
|
|
908
|
+
return found;
|
|
909
|
+
},
|
|
622
910
|
};
|
|
623
911
|
}
|
|
912
|
+
|
|
913
|
+
// No rotation, for the ball `castBallFixed` sweeps; how much smaller the
|
|
914
|
+
// ball is when it checks the place it was put; and how many solids found in
|
|
915
|
+
// the way there it sweeps against alone.
|
|
916
|
+
const UNTURNED = { x: 0, y: 0, z: 0, w: 1 };
|
|
917
|
+
const BALL_TOLERANCE = 5e-5;
|
|
918
|
+
const BALL_RECHECKS = 3;
|
|
919
|
+
// How finely `castBallFixed` halves toward a clear place when rapier missed
|
|
920
|
+
// a solid: to a millimetre, in at most 16 halvings (37.4 m, the farthest
|
|
921
|
+
// the orbit camera goes, is under 2^16 mm).
|
|
922
|
+
const BALL_BISECT = 0.001;
|
|
923
|
+
const BALL_HALVINGS = 16;
|
|
924
|
+
|
|
925
|
+
// `castBallFixed`'s sweep, in `world`: `{ met, normal, distance }`, the
|
|
926
|
+
// solid met (null for none) and its normal there, and how far the ball got.
|
|
927
|
+
function sweepBall(world, origin, dir, maxToi, radius) {
|
|
928
|
+
const ball = new RAPIER.Ball(radius);
|
|
929
|
+
const inner = new RAPIER.Ball(Math.max(radius - BALL_TOLERANCE, radius / 2));
|
|
930
|
+
const at = (t) => ({ x: origin.x + dir.x * t, y: origin.y + dir.y * t, z: origin.z + dir.z * t });
|
|
931
|
+
const inTheWayAt = (t) => world.intersectionWithShape(at(t), UNTURNED, inner, fixedSolids());
|
|
932
|
+
const sweepAgainst = (only) => world.castShape(origin, UNTURNED, dir, ball, 0, maxToi, true, fixedSolids(), undefined, undefined, undefined, only);
|
|
933
|
+
const swept = { met: null, normal: null, distance: maxToi };
|
|
934
|
+
const take = (hit) => {
|
|
935
|
+
swept.met = hit.collider;
|
|
936
|
+
swept.normal = hit.normal1;
|
|
937
|
+
swept.distance = touchingAt(hit, origin, dir, radius, maxToi);
|
|
938
|
+
};
|
|
939
|
+
const first = sweepAgainst(undefined);
|
|
940
|
+
if (first) take(first);
|
|
941
|
+
// The line of sight: a solid across the line nearer than that.
|
|
942
|
+
const line = world.castRay(new RAPIER.Ray(origin, dir), swept.distance, true, fixedSolids());
|
|
943
|
+
if (line) Object.assign(swept, { met: line.collider, normal: null, distance: line.timeOfImpact });
|
|
944
|
+
for (let i = 0; ; i += 1) {
|
|
945
|
+
const inTheWay = inTheWayAt(swept.distance);
|
|
946
|
+
// Clear, or touching only the solid it was put against (the plane's own
|
|
947
|
+
// small error there).
|
|
948
|
+
if (!inTheWay || (swept.normal && inTheWay.handle === swept.met.handle)) break;
|
|
949
|
+
const alone = i < BALL_RECHECKS ? sweepAgainst((c) => c.handle === inTheWay.handle) : null;
|
|
950
|
+
if (alone && touchingAt(alone, origin, dir, radius, maxToi) < swept.distance) {
|
|
951
|
+
take(alone);
|
|
952
|
+
continue;
|
|
953
|
+
}
|
|
954
|
+
// Missed again: the farthest clear place short of this one.
|
|
955
|
+
Object.assign(swept, { met: inTheWay, normal: null, distance: clearShortOf(inTheWayAt, swept.distance) });
|
|
956
|
+
break;
|
|
957
|
+
}
|
|
958
|
+
if (swept.met && !swept.normal) swept.normal = normalFrom(swept.met, at(swept.distance), dir);
|
|
959
|
+
return swept;
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
// The farthest place short of `blocked` (a distance along the sweep whose
|
|
963
|
+
// ball is in the way) that `inTheWayAt` finds clear, halving between the
|
|
964
|
+
// start (clear) and it: to BALL_BISECT, BALL_HALVINGS halvings at most.
|
|
965
|
+
function clearShortOf(inTheWayAt, blocked) {
|
|
966
|
+
let clear = 0;
|
|
967
|
+
let far = blocked;
|
|
968
|
+
for (let k = 0; k < BALL_HALVINGS && far - clear > BALL_BISECT; k += 1) {
|
|
969
|
+
const half = (clear + far) / 2;
|
|
970
|
+
if (inTheWayAt(half)) far = half;
|
|
971
|
+
else clear = half;
|
|
972
|
+
}
|
|
973
|
+
return clear;
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
// The unit normal of `collider`'s surface nearest `point`, facing the
|
|
977
|
+
// point; against the sweep when the point is on it.
|
|
978
|
+
function normalFrom(collider, point, dir) {
|
|
979
|
+
const near = collider.projectPoint(point, false);
|
|
980
|
+
if (!near) return { x: -dir.x, y: -dir.y, z: -dir.z };
|
|
981
|
+
const dx = point.x - near.point.x;
|
|
982
|
+
const dy = point.y - near.point.y;
|
|
983
|
+
const dz = point.z - near.point.z;
|
|
984
|
+
const length = Math.hypot(dx, dy, dz);
|
|
985
|
+
return length > 0 ? { x: dx / length, y: dy / length, z: dz / length } : { x: -dir.x, y: -dir.y, z: -dir.z };
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
// How far along `dir` from `origin` a ball of `radius` touches the plane
|
|
989
|
+
// that touches the solid where rapier's sweep `met` it (its witness point
|
|
990
|
+
// and normal), no farther than `maxToi`; rapier's own answer when the ball
|
|
991
|
+
// does not move toward that plane.
|
|
992
|
+
function touchingAt(met, origin, dir, radius, maxToi) {
|
|
993
|
+
const n = met.normal1;
|
|
994
|
+
const at = met.witness1;
|
|
995
|
+
const toi = met.time_of_impact;
|
|
996
|
+
const closing = -(n.x * dir.x + n.y * dir.y + n.z * dir.z);
|
|
997
|
+
if (!(closing > 1e-9)) return toi;
|
|
998
|
+
const off = n.x * (origin.x + dir.x * toi - at.x) + n.y * (origin.y + dir.y * toi - at.y) + n.z * (origin.z + dir.z * toi - at.z);
|
|
999
|
+
return Math.min(Math.max(0, toi + (off - radius) / closing), maxToi);
|
|
1000
|
+
}
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
"imports": {
|
|
4
4
|
"castle.base": {
|
|
5
5
|
"deckId": "yRcmH4_aYllE",
|
|
6
|
-
"version": "2026-10-
|
|
6
|
+
"version": "2026-10-07T03:41:20.671Z"
|
|
7
7
|
}
|
|
8
8
|
},
|
|
9
9
|
"autoUpdateWhenImported": true,
|
|
10
10
|
"deckId": "xFVr-afOLuUQ",
|
|
11
11
|
"cardId": "w6G45sy3_P_m",
|
|
12
|
-
"publishedVersion": "2026-10-
|
|
12
|
+
"publishedVersion": "2026-10-07T03:43:17.687Z"
|
|
13
13
|
}
|
|
@@ -43,6 +43,13 @@ const bodyModules = {
|
|
|
43
43
|
// `known` is what each client was last sent
|
|
44
44
|
// (playerId -> Set), for hysteresis. A deck
|
|
45
45
|
// without the hook broadcasts one delta to all
|
|
46
|
+
// objectInterest(sim) which objects each client is sent: a Map of
|
|
47
|
+
// playerId -> Set of object ids. A missing
|
|
48
|
+
// viewer, null or a thrown hook sees all. WORLD
|
|
49
|
+
// still carries every object; deltas carry
|
|
50
|
+
// changed visible rows and full rows on entry
|
|
51
|
+
// (`oin`), with no notice on leaving. Ownership,
|
|
52
|
+
// removals, acks and deck fields stay common
|
|
46
53
|
// poseEvery, poseIntervalMs with `interest`: a client's filtered sends
|
|
47
54
|
// carry other players' rows only every
|
|
48
55
|
// `poseEvery` ticks (`poseIntervalMs` apart,
|