castle-web-cli 0.4.232 → 0.4.234
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/api.d.ts +11 -0
- package/dist/api.js +43 -0
- package/dist/bundle.d.ts +64 -0
- package/dist/bundle.js +558 -2
- package/dist/castle-host/host.d.ts +18 -2
- package/dist/castle-host/host.js +844 -39
- package/dist/castleJson.d.ts +23 -2
- package/dist/castleJson.js +46 -2
- package/dist/check.d.ts +3 -1
- package/dist/check.js +20 -3
- package/dist/chunkLoader.d.ts +3 -0
- package/dist/chunkLoader.js +111 -0
- package/dist/devParty.d.ts +26 -0
- package/dist/devParty.js +231 -0
- package/dist/devSaveStorage.js +4 -0
- package/dist/devSessionStorage.js +50 -2
- package/dist/devSocial.d.ts +24 -0
- package/dist/devSocial.js +70 -0
- package/dist/ide.d.ts +2 -0
- package/dist/ide.js +119 -15
- 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 +11 -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 +25 -1
- package/dist/save-deck.js +178 -9
- package/dist/serve.js +32 -11
- package/dist/shell/assets/{index-D2tWM896.js → index-DulbYIJm.js} +97 -97
- 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/dist/vitePlugins.d.ts +2 -1
- package/dist/vitePlugins.js +13 -0
- package/kits/base/castle.json +1 -1
- package/kits/base/package-lock.json +1 -1
- package/kits/base/sdk/README.md +339 -5
- package/kits/base/sdk/avatar.d.ts +6 -2
- package/kits/base/sdk/avatar.js +12 -4
- package/kits/base/sdk/castle.d.ts +7 -3
- package/kits/base/sdk/castle.js +2 -0
- package/kits/base/sdk/commands.d.ts +176 -1
- package/kits/base/sdk/commands.js +3 -0
- package/kits/base/sdk/display.d.ts +3 -0
- package/kits/base/sdk/display.js +9 -3
- package/kits/base/sdk/hub.d.ts +37 -6
- package/kits/base/sdk/hub.js +63 -4
- package/kits/base/sdk/multiplayer.d.ts +7 -1
- package/kits/base/sdk/multiplayer.js +148 -32
- package/kits/base/sdk/multiplayerProtocol.d.ts +2 -0
- package/kits/base/sdk/party.d.ts +23 -0
- package/kits/base/sdk/party.js +91 -0
- package/kits/base/sdk/reconnectBudget.d.ts +23 -0
- package/kits/base/sdk/reconnectBudget.js +96 -0
- package/kits/base/sdk/save.d.ts +38 -1
- package/kits/base/sdk/save.js +81 -7
- package/kits/base/sdk/server/hub.d.ts +117 -0
- package/kits/base/sdk/server/hub.js +119 -2
- package/kits/base/sdk/server/platformHandle.d.ts +43 -1
- package/kits/base/sdk/server/storage.d.ts +17 -0
- package/kits/base/sdk/server/storage.js +65 -3
- package/kits/base/sdk/server/wrapper.d.ts +43 -6
- package/kits/base/sdk/server/wrapper.js +93 -9
- package/kits/base/sdk/social.d.ts +9 -0
- package/kits/base/sdk/social.js +5 -0
- package/kits/hub-game/CLAUDE.md +451 -13
- package/kits/hub-game/README.md +63 -0
- 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/castle.json +5 -5
- package/kits/hub-game/code/client/act.js +312 -0
- package/kits/hub-game/code/client/actionLayout.js +147 -0
- package/kits/hub-game/code/client/actionOverflow.js +556 -0
- package/kits/hub-game/code/client/actorBudget.js +47 -0
- package/kits/hub-game/code/client/arrivalCamera.js +50 -0
- package/kits/hub-game/code/client/askSlot.js +117 -0
- package/kits/hub-game/code/client/attention.js +11 -2
- package/kits/hub-game/code/client/avatar.js +311 -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 +253 -0
- package/kits/hub-game/code/client/backVisibility.js +13 -0
- package/kits/hub-game/code/client/ballot.js +472 -0
- package/kits/hub-game/code/client/build.js +38 -0
- package/kits/hub-game/code/client/chat.js +41 -5
- package/kits/hub-game/code/client/chatModeration.js +5 -0
- package/kits/hub-game/code/client/chrome.js +2144 -160
- 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/crowdNames.js +241 -0
- package/kits/hub-game/code/client/decor.js +515 -0
- package/kits/hub-game/code/client/defaultEnvironment.js +194 -0
- package/kits/hub-game/code/client/doorErrors.js +39 -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/fall.js +18 -0
- package/kits/hub-game/code/client/farAvatars.js +233 -0
- package/kits/hub-game/code/client/firstJoin.js +9 -2
- package/kits/hub-game/code/client/fpsTelemetry.js +50 -0
- package/kits/hub-game/code/client/frameBatch.js +5 -0
- package/kits/hub-game/code/client/grab.js +368 -29
- package/kits/hub-game/code/client/hookLayer.js +385 -20
- package/kits/hub-game/code/client/hudCopy.js +51 -0
- package/kits/hub-game/code/client/hudRate.js +20 -0
- package/kits/hub-game/code/client/idle.js +177 -24
- package/kits/hub-game/code/client/interestCap.js +81 -0
- package/kits/hub-game/code/client/invites.js +231 -0
- package/kits/hub-game/code/client/joinError.js +9 -0
- package/kits/hub-game/code/client/keys.js +36 -0
- package/kits/hub-game/code/client/labelsNear.js +234 -0
- package/kits/hub-game/code/client/landscapeLayout.js +17 -0
- package/kits/hub-game/code/client/layoutCache.js +264 -0
- package/kits/hub-game/code/client/loadTelemetry.js +20 -0
- package/kits/hub-game/code/client/loadingCover.js +148 -0
- package/kits/hub-game/code/client/loadingEntry.js +8 -0
- package/kits/hub-game/code/client/menuIcons.js +34 -0
- package/kits/hub-game/code/client/menuRows.js +43 -0
- package/kits/hub-game/code/client/modelReady.js +7 -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/padCueArrival.js +23 -0
- package/kits/hub-game/code/client/padCues.js +112 -0
- package/kits/hub-game/code/client/padOccupancy.js +88 -0
- package/kits/hub-game/code/client/padReadability.js +26 -0
- package/kits/hub-game/code/client/padRings.js +69 -0
- package/kits/hub-game/code/client/pushVisit.js +14 -0
- package/kits/hub-game/code/client/quality.js +205 -0
- package/kits/hub-game/code/client/qualityEntry.js +55 -0
- package/kits/hub-game/code/client/rehello.js +167 -0
- package/kits/hub-game/code/client/safeLayout.js +338 -0
- package/kits/hub-game/code/client/safeStyle.js +42 -0
- package/kits/hub-game/code/client/say.js +12 -3
- package/kits/hub-game/code/client/shot.js +146 -0
- package/kits/hub-game/code/client/shotFit.js +56 -0
- package/kits/hub-game/code/client/signIn.js +28 -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 +162 -1
- package/kits/hub-game/code/client/stuck.js +259 -0
- package/kits/hub-game/code/client/talk.js +714 -59
- package/kits/hub-game/code/client/tiers.js +543 -52
- package/kits/hub-game/code/client/toastBand.js +37 -0
- package/kits/hub-game/code/client/together.js +39 -2
- package/kits/hub-game/code/client/visibility.js +43 -0
- package/kits/hub-game/code/client/weakestLookBake.js +92 -0
- package/kits/hub-game/code/client/weakestTier.js +295 -0
- package/kits/hub-game/code/client/wear.js +461 -170
- package/kits/hub-game/code/client/worldLabels.js +241 -0
- package/kits/hub-game/code/client/yours.js +200 -0
- package/kits/hub-game/code/companionSpec.js +45 -0
- package/kits/hub-game/code/npcDisplayText.js +55 -0
- package/kits/hub-game/code/privateText.js +7 -0
- package/kits/hub-game/code/server/act.js +124 -0
- package/kits/hub-game/code/server/actions.js +138 -0
- package/kits/hub-game/code/server/actors.js +11 -2
- package/kits/hub-game/code/server/analytics.js +83 -0
- package/kits/hub-game/code/server/anonymousEntry.js +49 -0
- package/kits/hub-game/code/server/arrivalPose.js +36 -0
- 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 +107 -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/doorAnalytics.js +52 -0
- package/kits/hub-game/code/server/earned.js +478 -0
- package/kits/hub-game/code/server/frameBatch.js +183 -0
- package/kits/hub-game/code/server/friendBests.js +166 -0
- package/kits/hub-game/code/server/friendsAmong.js +272 -0
- package/kits/hub-game/code/server/history.js +7 -0
- package/kits/hub-game/code/server/hub.js +2510 -95
- package/kits/hub-game/code/server/idle.js +60 -12
- package/kits/hub-game/code/server/index.js +28 -6
- package/kits/hub-game/code/server/invites.js +19 -0
- package/kits/hub-game/code/server/labels.js +36 -2
- package/kits/hub-game/code/server/loadAbandon.js +106 -0
- package/kits/hub-game/code/server/manifest.js +586 -7
- package/kits/hub-game/code/server/menu.js +161 -0
- package/kits/hub-game/code/server/npcs.js +1025 -113
- package/kits/hub-game/code/server/observe.js +408 -0
- package/kits/hub-game/code/server/padOccupancy.js +85 -0
- package/kits/hub-game/code/server/party.js +2 -2
- package/kits/hub-game/code/server/players.js +30 -0
- package/kits/hub-game/code/server/resumePose.js +152 -0
- package/kits/hub-game/code/server/say.js +1 -1
- package/kits/hub-game/code/server/shot.js +110 -0
- package/kits/hub-game/code/server/standing.js +123 -0
- package/kits/hub-game/code/server/storageLimit.js +187 -0
- package/kits/hub-game/code/server/vis.js +175 -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/act.js +35 -0
- package/kits/hub-game/code/shared/cues.js +9 -0
- package/kits/hub-game/code/shared/danceIdle.js +28 -0
- package/kits/hub-game/code/shared/decor.js +41 -0
- package/kits/hub-game/code/shared/loadStages.js +12 -0
- package/kits/hub-game/code/shared/quality.js +74 -0
- package/kits/hub-game/code/shared/say.js +2 -0
- package/kits/hub-game/code/shared/shot.js +53 -0
- package/kits/hub-game/code/shared/spin.js +57 -0
- package/kits/hub-game/code/systems/hub.js +1753 -202
- package/kits/hub-game/docs/analytics.md +279 -0
- package/kits/hub-game/docs/content-pack.md +1 -1
- package/kits/hub-game/docs/contract.md +3475 -77
- package/kits/hub-game/docs/home-pieces.md +71 -0
- package/kits/hub-game/docs/observed-progress.md +252 -0
- package/kits/hub-game/main.jsx +2 -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 +10 -1
- package/kits/hub-game/package.json +6 -2
- package/kits/hub-game/play/player.js +142 -0
- package/kits/hub-game/play/registry.js +47 -0
- package/kits/hub-game/play.jsx +37 -0
- package/kits/hub-game/scripts/check.mjs +117 -16
- package/kits/hub-game/scripts/companion-follower-wire.json +1 -0
- package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +132 -0
- package/kits/hub-game/scripts/fixtures/decor-keyless.json +293 -0
- package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +26 -0
- package/kits/hub-game/scripts/fixtures/fake-dom.mjs +123 -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/pose-storage-fixture.mjs +46 -0
- package/kits/hub-game/scripts/soundscape-wave-analysis.mjs +125 -0
- package/kits/hub-game/scripts/test-act-client.mjs +186 -0
- package/kits/hub-game/scripts/test-act.mjs +171 -0
- package/kits/hub-game/scripts/test-action-layout.mjs +80 -0
- package/kits/hub-game/scripts/test-action-observers.mjs +46 -0
- package/kits/hub-game/scripts/test-actions-client.mjs +853 -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 +38 -23
- package/kits/hub-game/scripts/test-analytics.mjs +76 -0
- package/kits/hub-game/scripts/test-anonymous-entry.mjs +28 -0
- package/kits/hub-game/scripts/test-arrival-pose-server.mjs +196 -0
- package/kits/hub-game/scripts/test-arrival-pose.mjs +24 -0
- package/kits/hub-game/scripts/test-ask-client.mjs +358 -0
- package/kits/hub-game/scripts/test-ask-slot.mjs +85 -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 +792 -0
- package/kits/hub-game/scripts/test-avatar.mjs +584 -7
- package/kits/hub-game/scripts/test-back-visibility.mjs +82 -0
- package/kits/hub-game/scripts/test-ballot.mjs +1008 -0
- package/kits/hub-game/scripts/test-ban-join.mjs +121 -13
- package/kits/hub-game/scripts/test-build.mjs +49 -0
- package/kits/hub-game/scripts/test-cells.mjs +71 -0
- package/kits/hub-game/scripts/test-chat.mjs +863 -0
- package/kits/hub-game/scripts/test-classic.mjs +2 -0
- package/kits/hub-game/scripts/test-companion-chat.mjs +216 -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-control-layout-dom.mjs +120 -0
- package/kits/hub-game/scripts/test-crowd-names.mjs +205 -0
- package/kits/hub-game/scripts/test-decor-client.mjs +344 -0
- package/kits/hub-game/scripts/test-decor.mjs +464 -0
- package/kits/hub-game/scripts/test-default-environment-root.mjs +95 -0
- package/kits/hub-game/scripts/test-default-environment.mjs +267 -0
- package/kits/hub-game/scripts/test-door-analytics.mjs +58 -0
- package/kits/hub-game/scripts/test-door-jump.mjs +100 -0
- package/kits/hub-game/scripts/test-earned-client.mjs +459 -0
- package/kits/hub-game/scripts/test-earned.mjs +1224 -0
- package/kits/hub-game/scripts/test-emote-bubble.mjs +110 -0
- package/kits/hub-game/scripts/test-far-avatars.mjs +340 -0
- package/kits/hub-game/scripts/test-fps-telemetry.mjs +112 -0
- package/kits/hub-game/scripts/test-frame-batch.mjs +252 -0
- package/kits/hub-game/scripts/test-fresh-friends.mjs +118 -0
- package/kits/hub-game/scripts/test-friend-bests.mjs +435 -0
- package/kits/hub-game/scripts/test-grab-orbit.mjs +961 -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-high-only.mjs +170 -0
- package/kits/hub-game/scripts/test-hub-leaving.mjs +203 -0
- package/kits/hub-game/scripts/test-hub-ops.mjs +758 -2
- package/kits/hub-game/scripts/test-hub-trip.mjs +1594 -12
- package/kits/hub-game/scripts/test-hud-clear.mjs +484 -57
- package/kits/hub-game/scripts/test-hud-defects-dom.mjs +100 -0
- package/kits/hub-game/scripts/test-hud-rate.mjs +224 -0
- package/kits/hub-game/scripts/test-hud-safe-visibility-dom.mjs +83 -0
- package/kits/hub-game/scripts/test-idle.mjs +427 -1
- package/kits/hub-game/scripts/test-interest-cap.mjs +36 -0
- package/kits/hub-game/scripts/test-interest-cells.mjs +513 -0
- package/kits/hub-game/scripts/test-interest-client.mjs +118 -0
- package/kits/hub-game/scripts/test-interest.mjs +15 -0
- package/kits/hub-game/scripts/test-invites-client.mjs +430 -0
- package/kits/hub-game/scripts/test-invites.mjs +109 -0
- package/kits/hub-game/scripts/test-keys.mjs +46 -1
- package/kits/hub-game/scripts/test-labels.mjs +664 -0
- package/kits/hub-game/scripts/test-landscape-layout.mjs +194 -0
- package/kits/hub-game/scripts/test-list-scroll-dom.mjs +49 -0
- package/kits/hub-game/scripts/test-load-abandon.mjs +246 -0
- package/kits/hub-game/scripts/test-loading-cover.mjs +162 -0
- package/kits/hub-game/scripts/test-manifest.mjs +472 -0
- package/kits/hub-game/scripts/test-menu-client.mjs +585 -0
- package/kits/hub-game/scripts/test-menu.mjs +319 -0
- package/kits/hub-game/scripts/test-npcs.mjs +2528 -13
- package/kits/hub-game/scripts/test-object-entry.mjs +76 -0
- package/kits/hub-game/scripts/test-observed.mjs +745 -0
- package/kits/hub-game/scripts/test-pack.mjs +7 -0
- package/kits/hub-game/scripts/test-pad-cues.mjs +304 -0
- package/kits/hub-game/scripts/test-pad-occupancy.mjs +177 -0
- package/kits/hub-game/scripts/test-picker.mjs +541 -0
- package/kits/hub-game/scripts/test-placement-cache.mjs +690 -0
- package/kits/hub-game/scripts/test-progress-reset.mjs +559 -0
- package/kits/hub-game/scripts/test-push-visit.mjs +26 -0
- package/kits/hub-game/scripts/test-quality.mjs +385 -0
- package/kits/hub-game/scripts/test-rehello.mjs +1733 -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-resume-action-order.mjs +598 -0
- package/kits/hub-game/scripts/test-resume-held.mjs +239 -0
- package/kits/hub-game/scripts/test-resume-pose.mjs +142 -0
- package/kits/hub-game/scripts/test-safe-events-dom.mjs +116 -0
- package/kits/hub-game/scripts/test-safe-layout.mjs +330 -0
- package/kits/hub-game/scripts/test-say.mjs +1 -1
- package/kits/hub-game/scripts/test-shot.mjs +901 -0
- package/kits/hub-game/scripts/test-signin-client.mjs +45 -0
- package/kits/hub-game/scripts/test-soundscape.mjs +5437 -0
- package/kits/hub-game/scripts/test-spin.mjs +314 -0
- package/kits/hub-game/scripts/test-standing.mjs +449 -0
- package/kits/hub-game/scripts/test-storage-limit.mjs +333 -0
- package/kits/hub-game/scripts/test-stuck.mjs +1904 -0
- package/kits/hub-game/scripts/test-talk-overlay-dom.mjs +130 -0
- package/kits/hub-game/scripts/test-tier-cells.mjs +706 -0
- package/kits/hub-game/scripts/test-tiers-render.mjs +412 -0
- package/kits/hub-game/scripts/test-tiers.mjs +476 -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 +770 -0
- package/kits/hub-game/scripts/test-visibility.mjs +134 -0
- package/kits/hub-game/scripts/test-weakest-tier.mjs +924 -0
- package/kits/hub-game/scripts/test-world-labels.mjs +367 -0
- package/kits/hub-game/scripts/test-yours-chrome.mjs +210 -0
- package/kits/hub-game/scripts/test-yours.mjs +403 -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/joinFailure.js +27 -0
- package/kits/multiplayer-3d/code/client/nameTags.js +59 -4
- package/kits/multiplayer-3d/code/client/resumeGate.js +139 -0
- 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 +443 -34
- package/kits/multiplayer-3d/package-lock.json +8 -1
- package/kits/multiplayer-3d/package.json +3 -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-join-watchdog.mjs +436 -0
- package/kits/multiplayer-3d/scripts/test-own-name-tag.mjs +247 -0
- package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +624 -0
- package/kits/physics-2d/CLAUDE.md +19 -1
- package/kits/physics-2d/castle.json +2 -2
- package/kits/physics-2d/engine/frozenActors.js +233 -0
- package/kits/physics-2d/engine/scene.js +337 -3
- 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/eslint.config.js +1 -1
- package/kits/physics-2d/play/behaviors/AnalogStick.js +198 -0
- package/kits/physics-2d/play/behaviors/Camera.js +40 -0
- package/kits/physics-2d/play/behaviors/Collider.js +122 -0
- package/kits/physics-2d/play/behaviors/Draggable.js +115 -0
- package/kits/physics-2d/play/behaviors/Goal.js +46 -0
- package/kits/physics-2d/play/behaviors/Joints.js +126 -0
- package/kits/physics-2d/play/behaviors/Layout.js +71 -0
- package/kits/physics-2d/play/behaviors/RigidBody.js +57 -0
- package/kits/physics-2d/play/behaviors/Slingshot.js +142 -0
- package/kits/physics-2d/play/behaviors/SoundPlayer.js +263 -0
- package/kits/physics-2d/play/behaviors/Sprite.js +406 -0
- package/kits/physics-2d/play/behaviors/Style.js +209 -0
- package/kits/physics-2d/play/behaviors/Text.js +85 -0
- package/kits/physics-2d/play/behaviors/Video.js +93 -0
- package/kits/physics-2d/scripts/test-skip-unchanged.mjs +326 -1
- package/kits/physics-3d/CLAUDE.md +42 -529
- package/kits/physics-3d/behaviors/Body.jsx +3 -0
- package/kits/physics-3d/behaviors/Model.jsx +3 -0
- package/kits/physics-3d/behaviors/Player.jsx +661 -87
- package/kits/physics-3d/behaviors/Shape.jsx +3 -0
- package/kits/physics-3d/behaviors/Solid.jsx +3 -0
- package/kits/physics-3d/behaviors/Transform.jsx +3 -0
- package/kits/physics-3d/castle.json +3 -3
- package/kits/physics-3d/docs/engine-camera.md +542 -0
- package/kits/physics-3d/docs/engine-frame-cap.md +136 -0
- package/kits/physics-3d/docs/engine-load.md +149 -0
- package/kits/physics-3d/docs/engine-look.md +114 -0
- package/kits/physics-3d/docs/engine-shadows.md +372 -0
- package/kits/physics-3d/docs/engine-skip-work.md +187 -0
- package/kits/physics-3d/docs/engine-sky.md +198 -0
- package/kits/physics-3d/docs/engine-static-actors.md +226 -0
- package/kits/physics-3d/docs/engine-view.md +37 -0
- package/kits/physics-3d/docs/pxmodel-format.md +9 -1
- package/kits/physics-3d/engine3d/PlayOnly3D.jsx +5 -1
- package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +19 -277
- package/kits/physics-3d/engine3d/actornode.js +87 -0
- package/kits/physics-3d/engine3d/animationBudget.js +23 -0
- package/kits/physics-3d/engine3d/branches.js +3 -13
- package/kits/physics-3d/engine3d/cage.js +2 -7
- package/kits/physics-3d/engine3d/cageops.js +2 -17
- package/kits/physics-3d/engine3d/dataBehaviors.js +12 -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 +99 -0
- package/kits/physics-3d/engine3d/frozenphysics.js +140 -0
- package/kits/physics-3d/engine3d/frozenstatics.js +273 -0
- package/kits/physics-3d/engine3d/gait.js +126 -0
- package/kits/physics-3d/engine3d/initialModelFiles.js +18 -0
- package/kits/physics-3d/engine3d/kithooks.js +47 -0
- package/kits/physics-3d/engine3d/look.js +514 -48
- package/kits/physics-3d/engine3d/lookbake.js +208 -0
- package/kits/physics-3d/engine3d/materialpresets.js +2 -0
- package/kits/physics-3d/engine3d/modelFiles.js +3 -17
- package/kits/physics-3d/engine3d/modelMath.js +49 -0
- package/kits/physics-3d/engine3d/modelready.js +16 -0
- package/kits/physics-3d/engine3d/motion.js +39 -10
- package/kits/physics-3d/engine3d/nearshadows.js +106 -21
- package/kits/physics-3d/engine3d/optimize.js +9 -5
- package/kits/physics-3d/engine3d/orbitinput.js +522 -10
- package/kits/physics-3d/engine3d/orbitlens.js +48 -0
- package/kits/physics-3d/engine3d/ownmodel.js +213 -0
- package/kits/physics-3d/engine3d/partgeometry.js +1 -16
- package/kits/physics-3d/engine3d/paths.js +1 -9
- package/kits/physics-3d/engine3d/playTimings.js +50 -0
- package/kits/physics-3d/engine3d/playerRun.js +372 -0
- package/kits/physics-3d/engine3d/pxmodel.js +42 -11
- package/kits/physics-3d/engine3d/rapier.js +27 -0
- package/kits/physics-3d/engine3d/scatter.js +1 -11
- package/kits/physics-3d/engine3d/shadowfade.js +890 -0
- package/kits/physics-3d/engine3d/sky.js +547 -0
- package/kits/physics-3d/engine3d/skylife.js +306 -0
- package/kits/physics-3d/engine3d/squarefirst.js +177 -0
- package/kits/physics-3d/engine3d/stillshadows.js +399 -0
- package/kits/physics-3d/engine3d/sweep.js +1 -25
- 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 +1253 -76
- package/kits/physics-3d/eslint.config.js +2 -1
- package/kits/physics-3d/main.jsx +10 -2
- package/kits/physics-3d/package-lock.json +7 -0
- package/kits/physics-3d/package.json +5 -1
- package/kits/physics-3d/play/behaviors/Body.js +31 -0
- package/kits/physics-3d/play/behaviors/Door.js +37 -0
- package/kits/physics-3d/play/behaviors/Lookable.js +16 -0
- package/kits/physics-3d/play/behaviors/Model.js +23 -0
- package/kits/physics-3d/play/behaviors/Pickup.js +46 -0
- package/kits/physics-3d/play/behaviors/Player.js +1204 -0
- package/kits/physics-3d/play/behaviors/Shape.js +47 -0
- package/kits/physics-3d/play/behaviors/Solid.js +16 -0
- package/kits/physics-3d/play/behaviors/Transform.js +29 -0
- package/kits/physics-3d/pnpm-lock.yaml +8 -0
- package/kits/physics-3d/scripts/bench-shadow-fade.mjs +37 -0
- package/kits/physics-3d/scripts/build-rapier-gz.mjs +56 -0
- package/kits/physics-3d/scripts/frozen-statics-fixture.mjs +141 -0
- package/kits/physics-3d/scripts/look-baseline.mjs +155 -0
- package/kits/physics-3d/scripts/test-camera-follow.mjs +5 -1
- package/kits/physics-3d/scripts/test-camera-orbit.mjs +2613 -82
- package/kits/physics-3d/scripts/test-drop-empty-parts.mjs +2 -2
- package/kits/physics-3d/scripts/test-empty-gait-hints.mjs +89 -0
- package/kits/physics-3d/scripts/test-frame-cap-bob.mjs +438 -0
- package/kits/physics-3d/scripts/test-frame-cap.mjs +452 -0
- package/kits/physics-3d/scripts/test-frozen-nested.mjs +49 -0
- package/kits/physics-3d/scripts/test-frozen-statics-legacy-physics2d.mjs +123 -0
- package/kits/physics-3d/scripts/test-frozen-statics.mjs +434 -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 +5 -2
- package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +2001 -0
- package/kits/physics-3d/scripts/test-orbit-shift-lock.mjs +582 -0
- package/kits/physics-3d/scripts/test-orbit-shot.mjs +657 -0
- package/kits/physics-3d/scripts/test-orbit-view.mjs +230 -0
- package/kits/physics-3d/scripts/test-rapier-gz.mjs +106 -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-square-first.mjs +921 -0
- package/kits/physics-3d/scripts/test-static-actors.mjs +10 -1
- package/kits/physics-3d/scripts/test-static-physics.mjs +4 -1
- package/kits/physics-3d/scripts/test-static-scenery.mjs +2174 -0
- package/kits/physics-3d/scripts/test-steady-hover.mjs +7 -2
- package/kits/physics-3d/scripts/test-still-shadows.mjs +477 -0
- package/kits/physics-3d/scripts/test-view-range.mjs +260 -0
- package/kits/physics-3d/systems/physics3d.js +419 -9
- package/kits/real-time/castle.json +2 -2
- package/kits/real-time/code/client/connection.js +33 -10
- package/kits/real-time/code/client/gameHooks.js +2 -0
- package/kits/real-time/code/client/joinOverlay.js +9 -4
- package/kits/real-time/code/server/gameHooks.js +7 -0
- package/kits/real-time/code/server/session.js +102 -22
- package/kits/real-time/package-lock.json +1 -1
- package/package.json +2 -2
- package/dist/shell/assets/index-Cf61cNfT.css +0 -1
|
@@ -0,0 +1,1204 @@
|
|
|
1
|
+
// Generated from ../../behaviors/Player.jsx; run npm run sync:play-behaviors.
|
|
2
|
+
// The walkable player: a dynamic locked-rotation capsule driven by impulses
|
|
3
|
+
// (the vase floating-capsule controller), a faux-isometric follow camera, and
|
|
4
|
+
// the "look at things" reading of nearby Lookables into the hud.
|
|
5
|
+
//
|
|
6
|
+
// Controls: WASD / arrows move (camera-relative), Q / E orbit the camera.
|
|
7
|
+
// State lives on `actor.runtime` -- behavior instances are per-frame.
|
|
8
|
+
const DEG = Math.PI / 180;
|
|
9
|
+
function keyDown(keys, ...codes) {
|
|
10
|
+
return codes.some((code) => keys.has(code));
|
|
11
|
+
}
|
|
12
|
+
// Tank-style drive input: `forward` (-1..1) walks along the facing direction,
|
|
13
|
+
// `turn` (-1..1) steers it. W/S (and up/down arrows) drive, A/D (and
|
|
14
|
+
// left/right) turn. The pointer-drag stick maps the same way -- drag up walks,
|
|
15
|
+
// drag sideways turns, and the drag ANGLE blends the two, so a diagonal drag
|
|
16
|
+
// walks a curve and a pure sideways drag turns in place.
|
|
17
|
+
// Keys turn a bit harder than a full stick deflection -- discrete input wants
|
|
18
|
+
// the snappier response.
|
|
19
|
+
const KEY_TURN = 1.35;
|
|
20
|
+
function readDrive(keys, stick) {
|
|
21
|
+
let forward = 0;
|
|
22
|
+
let turn = 0;
|
|
23
|
+
if (keyDown(keys, 'KeyW', 'ArrowUp'))
|
|
24
|
+
forward += 1;
|
|
25
|
+
if (keyDown(keys, 'KeyS', 'ArrowDown'))
|
|
26
|
+
forward -= 1;
|
|
27
|
+
if (keyDown(keys, 'KeyD', 'ArrowRight'))
|
|
28
|
+
turn += KEY_TURN;
|
|
29
|
+
if (keyDown(keys, 'KeyA', 'ArrowLeft'))
|
|
30
|
+
turn -= KEY_TURN;
|
|
31
|
+
if (forward === 0 && turn === 0 && stick?.active && Math.hypot(stick.x, stick.y) >= 0.15) {
|
|
32
|
+
forward = -stick.y;
|
|
33
|
+
turn = stick.x;
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
forward: Math.max(-1, Math.min(1, forward)),
|
|
37
|
+
turn: Math.max(-KEY_TURN, Math.min(KEY_TURN, turn)),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
// Spring-hover the capsule a touch above the ground (smooths steps and edges);
|
|
41
|
+
// returns whether the player counts as grounded. The spring stays out of the
|
|
42
|
+
// way while the player is on the way up from a jump.
|
|
43
|
+
function applyHover(phys, actor, t, dims, dt) {
|
|
44
|
+
const hit = phys.castRay({ x: t.x, y: t.y, z: t.z }, { x: 0, y: -1, z: 0 }, dims.height, actor);
|
|
45
|
+
const hoverHeight = dims.height / 2 + 0.15;
|
|
46
|
+
const grounded = Boolean(hit && hit.distance < hoverHeight + 0.25);
|
|
47
|
+
const vel = phys.getVelocity(actor);
|
|
48
|
+
if (hit && hit.distance < hoverHeight + 0.4 && vel.y <= 1) {
|
|
49
|
+
const accel = 160 * (hoverHeight - hit.distance) - 18 * vel.y;
|
|
50
|
+
phys.applyImpulse(actor, { x: 0, y: accel * phys.mass(actor) * dt, z: 0 });
|
|
51
|
+
}
|
|
52
|
+
return grounded;
|
|
53
|
+
}
|
|
54
|
+
// The hover of a scene that set `"engine": { "camera": { "follow": "rigid" } }`
|
|
55
|
+
// (docs/engine-camera.md has the terms): the same spring, asked for as a force.
|
|
56
|
+
// `applyHover` pushes once per drawn frame while gravity pulls once per fixed
|
|
57
|
+
// physics step, and a frame takes none, one or two steps, so on a frame that
|
|
58
|
+
// is not exactly one step the player is kicked up or let drop: a bob of a
|
|
59
|
+
// centimetre or two walking, which the rigid camera would show as the view
|
|
60
|
+
// bobbing. A force acts once per step, as gravity does, so the spring and
|
|
61
|
+
// gravity balance on every step whatever the frames are.
|
|
62
|
+
//
|
|
63
|
+
// The spring rests STEADY_REST higher than applyHover's so the player stands
|
|
64
|
+
// where it does without the key. applyHover's push lands at the start of a
|
|
65
|
+
// step and gravity is spread through it, so the velocity it reads standing
|
|
66
|
+
// still is not 0 but a fraction of a step's fall (-0.123 m/s for the kit's
|
|
67
|
+
// player, whose gravity scale is 2), and the spring's damper answers that
|
|
68
|
+
// with lift: 18 * 0.123 / 160 = 1.38 cm. Under a force the velocity at rest
|
|
69
|
+
// is 0. (0.69 cm per unit of gravity scale: a player with another scale
|
|
70
|
+
// stands that much off its keyless height.) What counts as grounded is
|
|
71
|
+
// measured as it is there.
|
|
72
|
+
//
|
|
73
|
+
// The force is the physics system's to drop: `addForce` lasts this frame's
|
|
74
|
+
// physics pass and no longer, so a frame this does not run on has no lift.
|
|
75
|
+
const STEADY_REST = 0.0138;
|
|
76
|
+
function hoverSteadily(phys, actor, t, dims) {
|
|
77
|
+
const hit = phys.castRay({ x: t.x, y: t.y, z: t.z }, { x: 0, y: -1, z: 0 }, dims.height, actor);
|
|
78
|
+
const hoverHeight = dims.height / 2 + 0.15;
|
|
79
|
+
const vel = phys.getVelocity(actor);
|
|
80
|
+
if (hit && hit.distance < hoverHeight + 0.4 && vel.y <= 1) {
|
|
81
|
+
const accel = 160 * (hoverHeight + STEADY_REST - hit.distance) - 18 * vel.y;
|
|
82
|
+
phys.addForce(actor, { x: 0, y: accel * phys.mass(actor), z: 0 });
|
|
83
|
+
}
|
|
84
|
+
return Boolean(hit && hit.distance < hoverHeight + 0.25);
|
|
85
|
+
}
|
|
86
|
+
// The fall-faster pull under the same key: a force for the same reason.
|
|
87
|
+
function pullSteadily(phys, actor) {
|
|
88
|
+
phys.addForce(actor, { x: 0, y: -14 * phys.mass(actor), z: 0 });
|
|
89
|
+
}
|
|
90
|
+
function applyMove(phys, actor, move, speed, grounded, dt) {
|
|
91
|
+
const mass = phys.mass(actor);
|
|
92
|
+
const vel = phys.getVelocity(actor);
|
|
93
|
+
if (move) {
|
|
94
|
+
const factor = Math.min(1, dt * 14) * (grounded ? 1 : 0.3);
|
|
95
|
+
phys.applyImpulse(actor, {
|
|
96
|
+
x: (move.x * speed - vel.x) * mass * factor,
|
|
97
|
+
y: 0,
|
|
98
|
+
z: (move.z * speed - vel.z) * mass * factor,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
else if (grounded) {
|
|
102
|
+
const factor = Math.min(1, dt * 12);
|
|
103
|
+
phys.applyImpulse(actor, { x: -vel.x * mass * factor, y: 0, z: -vel.z * mass * factor });
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// A player moving faster than this between two frames was teleported: a scene
|
|
107
|
+
// switch, or the session placing them where they left off. Walking never covers
|
|
108
|
+
// it in one frame.
|
|
109
|
+
const TELEPORT_PER_FRAME = 3;
|
|
110
|
+
function updateCamera(scene, t, rt, props, dt) {
|
|
111
|
+
const cam = scene.three?.camera;
|
|
112
|
+
if (!cam)
|
|
113
|
+
return;
|
|
114
|
+
const targetX = t.x - props.camDistance * Math.sin(rt.camAngle);
|
|
115
|
+
const targetY = t.y + props.camHeight;
|
|
116
|
+
const targetZ = t.z + props.camDistance * Math.cos(rt.camAngle);
|
|
117
|
+
// A teleport snaps the camera instead of swooshing it across the map. The
|
|
118
|
+
// player's position from the previous frame is what detects it.
|
|
119
|
+
const last = rt.camLastAt;
|
|
120
|
+
const jumped = last && Math.hypot(t.x - last.x, t.z - last.z) > TELEPORT_PER_FRAME;
|
|
121
|
+
rt.camLastAt = { x: t.x, z: t.z };
|
|
122
|
+
if (jumped || Math.hypot(targetX - cam.position.x, targetZ - cam.position.z) > 20) {
|
|
123
|
+
cam.position.set(targetX, targetY, targetZ);
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
const lerp = 1 - Math.exp(-12 * dt);
|
|
127
|
+
cam.position.x += (targetX - cam.position.x) * lerp;
|
|
128
|
+
cam.position.y += (targetY - cam.position.y) * lerp;
|
|
129
|
+
cam.position.z += (targetZ - cam.position.z) * lerp;
|
|
130
|
+
}
|
|
131
|
+
cam.lookAt(t.x, t.y + 0.5, t.z);
|
|
132
|
+
}
|
|
133
|
+
// How fast the rigid follow camera's offset and height catch up: the rate of
|
|
134
|
+
// updateCamera's lerp, so an orbit (Q/E, or turning) swings as it does there.
|
|
135
|
+
const FOLLOW_RATE = 12;
|
|
136
|
+
// One frame of `x' = FOLLOW_RATE * (target - x)` for a target that moved from
|
|
137
|
+
// `from` to `to` at a steady rate over the frame, solved exactly. A target that
|
|
138
|
+
// moves steadily is trailed by the same distance however the frames are cut,
|
|
139
|
+
// and one that stands still is reached as updateCamera's lerp reaches it.
|
|
140
|
+
function settle(value, from, to, dt) {
|
|
141
|
+
if (!(dt > 0))
|
|
142
|
+
return value;
|
|
143
|
+
const lag = (to - from) / (dt * FOLLOW_RATE);
|
|
144
|
+
return to - lag + (value - from + lag) * Math.exp(-FOLLOW_RATE * dt);
|
|
145
|
+
}
|
|
146
|
+
// The follow camera of a scene that capped its frame rate (`"engine": {
|
|
147
|
+
// "maxFps": n }`, `scene.maxFps` above 0) and set no camera key: the camera
|
|
148
|
+
// `updateCamera` places, the same target and rate, placed differently.
|
|
149
|
+
// updateCamera eases once a frame by 1 - e^(-12 dt), from the update, toward
|
|
150
|
+
// where the player was drawn LAST frame: behind a target moving at v it trails
|
|
151
|
+
// by about v/12 + v dt/2, and the player is then drawn v dt further on. Both
|
|
152
|
+
// change with each frame's dt, and the cap hands frames of 25 to 50 ms on a
|
|
153
|
+
// slow phone, so the player would slide back and forth on screen as it walks.
|
|
154
|
+
// So under the cap the camera is placed as the rigid one is: at the end of
|
|
155
|
+
// the frame, by the physics system (`placeFollowCamera`), on the position the
|
|
156
|
+
// frame is drawn with, and each coordinate is eased as if the target moved
|
|
157
|
+
// steadily from last frame's place to this frame's (`settle`: the exact
|
|
158
|
+
// solution of x' = 12 (target - x)). A steady walk is then trailed by v/12
|
|
159
|
+
// whatever the frames; a target standing still is reached as the lerp
|
|
160
|
+
// reaches it. Last frame's target is on the actor's runtime (`camTarget`).
|
|
161
|
+
// Without the cap updateCamera runs as it always did.
|
|
162
|
+
function placeCapped(scene, id, dt) {
|
|
163
|
+
const actor = scene.getActor(id);
|
|
164
|
+
const t = actor?.components.Transform;
|
|
165
|
+
const props = actor?.components.Player;
|
|
166
|
+
const cam = scene.three?.camera;
|
|
167
|
+
if (!cam || !t || !props || props.$enabled === false)
|
|
168
|
+
return;
|
|
169
|
+
const per = persistentOf(scene);
|
|
170
|
+
const rt = actor.runtime;
|
|
171
|
+
const target = {
|
|
172
|
+
x: t.x - props.camDistance * Math.sin(per.camAngle),
|
|
173
|
+
y: t.y + props.camHeight,
|
|
174
|
+
z: t.z + props.camDistance * Math.cos(per.camAngle),
|
|
175
|
+
};
|
|
176
|
+
const last = per.camLastAt;
|
|
177
|
+
const jumped = last && Math.hypot(t.x - last.x, t.z - last.z) > TELEPORT_PER_FRAME;
|
|
178
|
+
per.camLastAt = { x: t.x, z: t.z };
|
|
179
|
+
const from = rt.camTarget ?? target;
|
|
180
|
+
rt.camTarget = target;
|
|
181
|
+
if (jumped || Math.hypot(target.x - cam.position.x, target.z - cam.position.z) > 20) {
|
|
182
|
+
cam.position.set(target.x, target.y, target.z);
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
cam.position.set(settle(cam.position.x, from.x, target.x, dt), settle(cam.position.y, from.y, target.y, dt), settle(cam.position.z, from.z, target.z, dt));
|
|
186
|
+
}
|
|
187
|
+
cam.lookAt(t.x, t.y + 0.5, t.z);
|
|
188
|
+
}
|
|
189
|
+
// The follow camera of a scene that set `"engine": { "camera": { "follow":
|
|
190
|
+
// "rigid" } }` (docs/engine-camera.md has the terms). It moves with the player
|
|
191
|
+
// as one piece: the offset from the player (its angle and height) and the
|
|
192
|
+
// player's height are eased, the player's ground position is not, so a steady
|
|
193
|
+
// walk leaves the player at one place on screen whatever the frame lengths.
|
|
194
|
+
// It is placed at the end of the frame (`placeFollowing`), on the position the
|
|
195
|
+
// frame is drawn with.
|
|
196
|
+
function followRigidly(scene, t, per, rt, props, dt) {
|
|
197
|
+
const cam = scene.three?.camera;
|
|
198
|
+
if (!cam)
|
|
199
|
+
return;
|
|
200
|
+
const ox = -props.camDistance * Math.sin(per.camAngle);
|
|
201
|
+
const oy = props.camHeight;
|
|
202
|
+
const oz = props.camDistance * Math.cos(per.camAngle);
|
|
203
|
+
const last = per.camLastAt;
|
|
204
|
+
const jumped = last && Math.hypot(t.x - last.x, t.z - last.z) > TELEPORT_PER_FRAME;
|
|
205
|
+
per.camLastAt = { x: t.x, z: t.z };
|
|
206
|
+
// The offset is read each frame from where the camera is, against the
|
|
207
|
+
// point it followed last frame, so a camera something else moved since (a
|
|
208
|
+
// trip's camera, a cutscene) is eased on from where it was left.
|
|
209
|
+
const at = cam.position;
|
|
210
|
+
const f = (rt.camFollow ??= { from: { x: t.x, y: t.y, z: t.z }, to: null });
|
|
211
|
+
let x = at.x - f.from.x;
|
|
212
|
+
let y = at.y - f.from.y;
|
|
213
|
+
let z = at.z - f.from.z;
|
|
214
|
+
let height = f.from.y;
|
|
215
|
+
const to = f.to ?? { x: ox, y: oy, z: oz, height: t.y };
|
|
216
|
+
if (jumped || Math.hypot(t.x + ox - at.x, t.z + oz - at.z) > 20) {
|
|
217
|
+
[x, y, z, height] = [ox, oy, oz, t.y];
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
x = settle(x, to.x, ox, dt);
|
|
221
|
+
y = settle(y, to.y, oy, dt);
|
|
222
|
+
z = settle(z, to.z, oz, dt);
|
|
223
|
+
height = settle(height, to.height, t.y, dt);
|
|
224
|
+
}
|
|
225
|
+
f.to = { x: ox, y: oy, z: oz, height: t.y };
|
|
226
|
+
f.from = { x: t.x, y: height, z: t.z };
|
|
227
|
+
cam.position.set(t.x + x, height + y, t.z + z);
|
|
228
|
+
cam.lookAt(t.x, t.y + 0.5, t.z);
|
|
229
|
+
}
|
|
230
|
+
// Under the key, Player.update asks for its camera by the actor's id and the
|
|
231
|
+
// scene data it was made for (`scene.followCamera`), every frame, physics
|
|
232
|
+
// ready or not; the physics system calls this at the end of the frame, after
|
|
233
|
+
// it has written this frame's positions back (or at once, when it could not
|
|
234
|
+
// step), if the same scene is still loaded. The player is looked up as the
|
|
235
|
+
// scene has it then: one despawned or turned off since gets no camera.
|
|
236
|
+
function placeFollowing(scene, id, dt) {
|
|
237
|
+
const actor = scene.getActor(id);
|
|
238
|
+
const t = actor?.components.Transform;
|
|
239
|
+
const props = actor?.components.Player;
|
|
240
|
+
if (!t || !props || props.$enabled === false)
|
|
241
|
+
return;
|
|
242
|
+
const per = (scene.persistent ??= {});
|
|
243
|
+
if (per.camAngle === undefined)
|
|
244
|
+
per.camAngle = Math.PI / 4;
|
|
245
|
+
followRigidly(scene, t, per, actor.runtime, props, dt);
|
|
246
|
+
}
|
|
247
|
+
// ---------------------------------------------------------------------------
|
|
248
|
+
// The camera the player controls: a scene that set `"engine": { "camera": {
|
|
249
|
+
// "follow": "rigid", "control": "orbit" } }` (docs/engine-camera.md has the
|
|
250
|
+
// terms). Everything from here to `hudContents` runs under that key only,
|
|
251
|
+
// from the one branch at the top of `Player.update`; nothing above this line
|
|
252
|
+
// calls into it. It restates the steps of `update` that it shares (the
|
|
253
|
+
// persistent defaults, the jump, the fall, the hud) rather than have `update`
|
|
254
|
+
// call out for them, so that without the key `update` is the code it was.
|
|
255
|
+
//
|
|
256
|
+
// Walking is camera-relative (up on the stick, or W, is away from the camera)
|
|
257
|
+
// and the character turns to face the way it walks. The camera's yaw is
|
|
258
|
+
// `scene.persistent.camAngle`, with the meaning it always had: the camera
|
|
259
|
+
// sits at player + (-d sin(yaw), h, d cos(yaw)). Its pitch and distance are
|
|
260
|
+
// the player's own and are not sent anywhere: they are kept on the runtime
|
|
261
|
+
// (`scene.cameraOrbit`), which a scene load does not replace, and never on
|
|
262
|
+
// `scene.persistent`.
|
|
263
|
+
// The numbers below are Roblox's default (Classic) third-person camera at
|
|
264
|
+
// our scale. A Roblox character is 5 studs tall; ours, the kit's
|
|
265
|
+
// player.pxmodel standing on its 1.4 m capsule (the hub's avatar), is 1.46 m
|
|
266
|
+
// from the soles of its feet (0.02 m above the model's origin) to the top of
|
|
267
|
+
// its cap (1.48 m), so one stud is 1.46 / 5 = 0.292 m here.
|
|
268
|
+
const STUD = 1.46 / 5;
|
|
269
|
+
// The camera looks at the player this far above its Transform. Roblox looks
|
|
270
|
+
// at the root part plus 1.5 studs; the root part is the torso's middle, and
|
|
271
|
+
// so is our Transform (the capsule's middle, 0.70 m above the model's origin,
|
|
272
|
+
// where the torso's middle is 0.69), so the same 1.5 studs: 0.438 m, the neck.
|
|
273
|
+
const LOOK_HEIGHT = 1.5 * STUD;
|
|
274
|
+
// How far from that point the camera starts: Roblox's 12.5 studs, 3.65 m,
|
|
275
|
+
// the same two and a half character heights.
|
|
276
|
+
const ORBIT_START = 12.5 * STUD;
|
|
277
|
+
// The nearest and farthest the player can zoom, metres from that point.
|
|
278
|
+
// Roblox lets the player in to 0.5 studs, which is first person; here the
|
|
279
|
+
// nearest keeps the camera clear of the character, which an avatar hides
|
|
280
|
+
// itself from within about 1 m. The farthest is Roblox's 128 studs, 37.4 m.
|
|
281
|
+
const ORBIT_NEAREST = 1.5;
|
|
282
|
+
const ORBIT_FARTHEST = 128 * STUD;
|
|
283
|
+
// The lowest and highest the camera tilts, above the horizontal: Roblox's 80
|
|
284
|
+
// degrees either way. Below the horizontal the camera is lower than the point
|
|
285
|
+
// it looks at, looking up, and the ground (a fixed solid, as walls are) holds
|
|
286
|
+
// it above itself as a wall holds it in front (`limitReach`, `sweep`).
|
|
287
|
+
const ORBIT_PITCH_LEAST = -80 * DEG;
|
|
288
|
+
const ORBIT_PITCH_MOST = 80 * DEG;
|
|
289
|
+
// The tilt the camera starts at, whatever the Player's camDistance and
|
|
290
|
+
// camHeight: 15 degrees down, behind the player, as Roblox starts. With the
|
|
291
|
+
// 70 degree lens (engine3d/orbitlens.js `fitOrbitLens`) the top of the frame
|
|
292
|
+
// is 20 degrees above the horizon: a world's sky shows.
|
|
293
|
+
const ORBIT_PITCH_START = 15 * DEG;
|
|
294
|
+
// How fast the camera's angle, tilt and distance catch up with what was
|
|
295
|
+
// asked: quick enough to feel direct, slow enough to take the steps out of a
|
|
296
|
+
// finger's drag.
|
|
297
|
+
const ORBIT_RATE = 20;
|
|
298
|
+
// How fast the character turns to face the way it walks.
|
|
299
|
+
const FACE_RATE = 12;
|
|
300
|
+
// The camera stays at least this far off every fixed surface: it is a ball
|
|
301
|
+
// of this radius swept out from the point it looks at (`sweep`), so it is
|
|
302
|
+
// this far off whatever stops it, square to the surface, however the line
|
|
303
|
+
// meets it (a wall met at a grazing angle, a box's edge or corner, the
|
|
304
|
+
// ground seen along at a low angle). A wider lens than the default's needs
|
|
305
|
+
// more: the lens's near plane must stay clear of the surface whichever way
|
|
306
|
+
// the camera looks, so the margin is the distance from the camera to the
|
|
307
|
+
// near plane's corners plus LENS_CLEARANCE when that is more
|
|
308
|
+
// (`lensMargin`). At the default 70 degrees on a 20:9 screen the corners
|
|
309
|
+
// are 0.198 m off and the margin is 0.25 m; at 120 degrees on 20:9, 0.484 m.
|
|
310
|
+
const CAMERA_MARGIN = 0.25;
|
|
311
|
+
const LENS_CLEARANCE = 0.05;
|
|
312
|
+
// A look point nearer fixed surfaces than the margin and START_SKIN (a
|
|
313
|
+
// player pressed against a wall, or in a corner, with a wide lens) has the
|
|
314
|
+
// ball start moved the least way that puts it that far off all of them
|
|
315
|
+
// together (`findStart`), and looked around again, START_TRIES times at
|
|
316
|
+
// most; a point within START_SETTLED of that distance is taken. A gap too
|
|
317
|
+
// narrow for that leaves the ball smaller, down to START_LEAST.
|
|
318
|
+
const START_SKIN = 0.05;
|
|
319
|
+
const START_TRIES = 8;
|
|
320
|
+
const START_SETTLED = 1e-4;
|
|
321
|
+
const START_LEAST = 0.02;
|
|
322
|
+
// Where no start is found at all (the look point inside a solid) the camera
|
|
323
|
+
// is held by a ray alone, as it was before the ball (`onRay`): a margin
|
|
324
|
+
// short of the hit, no nearer the look point than CAMERA_NEAREST, but never
|
|
325
|
+
// past a real surface: then SURFACE_GAP short of it.
|
|
326
|
+
const CAMERA_NEAREST = 0.6;
|
|
327
|
+
const SURFACE_GAP = 0.01;
|
|
328
|
+
// The lens the orbit camera is drawn with (world3d.js `orbitFov`, which sets
|
|
329
|
+
// it on the camera at the draw that follows this placement): the scene's
|
|
330
|
+
// `engine.camera.fov`, 10 to 120 degrees, else 70.
|
|
331
|
+
const ORBIT_FOV = 70;
|
|
332
|
+
function orbitFov(scene) {
|
|
333
|
+
const fov = scene.data?.engine?.camera?.fov;
|
|
334
|
+
return typeof fov === 'number' && fov >= 10 && fov <= 120 ? fov : ORBIT_FOV;
|
|
335
|
+
}
|
|
336
|
+
// The margin for this frame's lens: CAMERA_MARGIN, or the near plane's
|
|
337
|
+
// corners' distance from the camera, near * sqrt(1 + tan^2(v/2) +
|
|
338
|
+
// (aspect tan(v/2))^2), plus LENS_CLEARANCE, whichever is more. A point of
|
|
339
|
+
// the near plane is no farther from the camera than its corners, so a camera
|
|
340
|
+
// that far off a surface, square to it, has the whole near plane in front of
|
|
341
|
+
// it.
|
|
342
|
+
function lensMargin(scene, cam) {
|
|
343
|
+
const near = Number.isFinite(cam.near) && cam.near > 0 ? cam.near : 0.1;
|
|
344
|
+
const aspect = Number.isFinite(cam.aspect) && cam.aspect > 0 ? cam.aspect : 1;
|
|
345
|
+
const half = Math.tan((orbitFov(scene) * DEG) / 2);
|
|
346
|
+
const corner = near * Math.sqrt(1 + half * half + aspect * half * (aspect * half));
|
|
347
|
+
return Math.max(CAMERA_MARGIN, corner + LENS_CLEARANCE);
|
|
348
|
+
}
|
|
349
|
+
// How fast the camera moves back out once nothing is in the way.
|
|
350
|
+
const CAMERA_OUT_RATE = 6;
|
|
351
|
+
// Within this of the distance it wants, a camera let back out is let go.
|
|
352
|
+
const CAMERA_OUT_DONE = 1e-4;
|
|
353
|
+
// A camera something else placed is eased on from where it was left at this
|
|
354
|
+
// rate: a twentieth of the way is left after 0.3 s.
|
|
355
|
+
const TAKEOVER_RATE = 10;
|
|
356
|
+
// A settled shot uses its exact authored pose, avoiding round-trip drift.
|
|
357
|
+
const SHOT_SETTLED = 1e-10;
|
|
358
|
+
// Stay off the poles, where lookAt cannot retain the shot's azimuth.
|
|
359
|
+
const SHOT_PITCH_LIMIT = 89 * DEG;
|
|
360
|
+
const SHOT_YAW_EPS = 1e-8;
|
|
361
|
+
// The camera was placed on the frame before this one when the scene time it
|
|
362
|
+
// was last placed at is this frame's length ago, to within this (seconds).
|
|
363
|
+
const PLACED_WITHIN = 1e-6;
|
|
364
|
+
// A takeover blend farther than this from the camera's place has its drawn
|
|
365
|
+
// point tested for collision too (a second sweep, only while it lasts).
|
|
366
|
+
const BLEND_TESTED = 1e-4;
|
|
367
|
+
const clamp = (value, least, most) => Math.max(least, Math.min(most, value));
|
|
368
|
+
// The share of the way an easing at `rate` covers in `dt`.
|
|
369
|
+
const eased = (rate, dt) => 1 - Math.exp(-rate * dt);
|
|
370
|
+
// An angle as the shortest way round: -PI..PI.
|
|
371
|
+
function arc(angle) {
|
|
372
|
+
const turns = angle - 2 * Math.PI * Math.floor((angle + Math.PI) / (2 * Math.PI));
|
|
373
|
+
return Number.isFinite(turns) ? turns : 0;
|
|
374
|
+
}
|
|
375
|
+
function held(keys, plus, minus) {
|
|
376
|
+
return (plus.some((code) => keys.has(code)) ? 1 : 0) - (minus.some((code) => keys.has(code)) ? 1 : 0);
|
|
377
|
+
}
|
|
378
|
+
// The cross-scene store with the camera's angle in it.
|
|
379
|
+
function persistentOf(scene) {
|
|
380
|
+
const per = (scene.persistent ??= {});
|
|
381
|
+
if (per.camAngle === undefined)
|
|
382
|
+
per.camAngle = Math.PI / 4;
|
|
383
|
+
return per;
|
|
384
|
+
}
|
|
385
|
+
// This frame's walk: a direction on the ground no longer than 1, or null
|
|
386
|
+
// standing still. W/S and up/down walk away from and toward the camera, A/D
|
|
387
|
+
// strafe, the stick does both by how far it is pushed; left/right swing the
|
|
388
|
+
// camera at `turnSpeed`. Under a held shot the camera cannot swing, so
|
|
389
|
+
// left/right strafe like A/D instead. The character's facing eases toward
|
|
390
|
+
// the walk and stays put standing still.
|
|
391
|
+
function driveOrbiting(scene, per, rt, props, dt) {
|
|
392
|
+
const keys = scene.keys;
|
|
393
|
+
const shot = validOrbitShot(scene.orbitShot);
|
|
394
|
+
if (!shot)
|
|
395
|
+
per.camAngle += held(keys, ['ArrowRight'], ['ArrowLeft']) * props.turnSpeed * dt;
|
|
396
|
+
let ahead = held(keys, ['KeyW', 'ArrowUp'], ['KeyS', 'ArrowDown']);
|
|
397
|
+
let aside = shot ? held(keys, ['KeyD', 'ArrowRight'], ['KeyA', 'ArrowLeft']) : held(keys, ['KeyD'], ['KeyA']);
|
|
398
|
+
const stick = scene.moveInput;
|
|
399
|
+
if (ahead === 0 && aside === 0 && stick?.active && Math.hypot(stick.x, stick.y) >= 0.15) {
|
|
400
|
+
ahead = -stick.y;
|
|
401
|
+
aside = stick.x;
|
|
402
|
+
}
|
|
403
|
+
const length = Math.hypot(ahead, aside);
|
|
404
|
+
if (length === 0)
|
|
405
|
+
return null;
|
|
406
|
+
const scale = length > 1 ? 1 / length : 1;
|
|
407
|
+
// Keep the persistent follow heading while walking in the held view's
|
|
408
|
+
// drawn direction, including its takeover blend. Before placement, use
|
|
409
|
+
// the shot's target yaw.
|
|
410
|
+
const yaw = shot && scene.data?.engine?.camera?.walkFromShot === true
|
|
411
|
+
? (rt.orbitShot?.active && Number.isFinite(rt.orbitShot.yaw) ? rt.orbitShot.yaw : shot.yaw * DEG)
|
|
412
|
+
: per.camAngle;
|
|
413
|
+
const sin = Math.sin(yaw);
|
|
414
|
+
const cos = Math.cos(yaw);
|
|
415
|
+
const move = { x: (sin * ahead + cos * aside) * scale, z: (sin * aside - cos * ahead) * scale };
|
|
416
|
+
rt.facing += arc(Math.atan2(move.x, move.z) - rt.facing) * eased(FACE_RATE, dt);
|
|
417
|
+
return move;
|
|
418
|
+
}
|
|
419
|
+
// The jump and the fall-faster pull, as `update` has them under the camera
|
|
420
|
+
// key (the hover is a force there, and so is the pull).
|
|
421
|
+
function jumpOrbiting(phys, actor, scene, rt, grounded, jumpSpeed, dt) {
|
|
422
|
+
const tapped = scene.moveInput?.consumeJump?.();
|
|
423
|
+
rt.jumpBuffer = tapped ? 0.18 : Math.max(0, (rt.jumpBuffer ?? 0) - dt);
|
|
424
|
+
if (grounded && (rt.jumpBuffer > 0 || keyDown(scene.keys, 'Space'))) {
|
|
425
|
+
rt.jumpBuffer = 0;
|
|
426
|
+
const { x, z } = phys.getVelocity(actor);
|
|
427
|
+
phys.setVelocity(actor, { x, y: jumpSpeed, z });
|
|
428
|
+
phys.resetForces(actor);
|
|
429
|
+
}
|
|
430
|
+
if (!grounded && phys.getVelocity(actor).y < 1)
|
|
431
|
+
pullSteadily(phys, actor);
|
|
432
|
+
}
|
|
433
|
+
function hudOrbiting(scene, actor, t, per, facing) {
|
|
434
|
+
const { remaining: left, look } = hudContents(scene, actor, t, facing);
|
|
435
|
+
const all = per.score + left;
|
|
436
|
+
let score = '';
|
|
437
|
+
if (all !== 0)
|
|
438
|
+
score = left === 0 ? '◆ all shards found' : `◆ ${per.score}/${all}`;
|
|
439
|
+
scene.hud = { score, look };
|
|
440
|
+
}
|
|
441
|
+
// `Player.update` under the key.
|
|
442
|
+
function updateOrbiting(actor, scene, props, dt) {
|
|
443
|
+
scene.followCamera = { id: actor.id, data: scene.data, dt, place: placeOrbiting };
|
|
444
|
+
scene.orbitInput?.();
|
|
445
|
+
scene.lookInput?.listen?.();
|
|
446
|
+
const rt = actor.runtime;
|
|
447
|
+
// A facing asked for (`scene.faceRequest`, radians: the hub's arrival
|
|
448
|
+
// facing, a jump to a door) is taken once. Without the key the character
|
|
449
|
+
// always faces PI - camAngle, so code written for that sets camAngle;
|
|
450
|
+
// under it the camera and the character turn apart, and turning the
|
|
451
|
+
// character is asked for.
|
|
452
|
+
if (scene.faceRequest !== undefined) {
|
|
453
|
+
if (typeof scene.faceRequest === 'number' && Number.isFinite(scene.faceRequest))
|
|
454
|
+
rt.facing = scene.faceRequest;
|
|
455
|
+
scene.faceRequest = undefined;
|
|
456
|
+
}
|
|
457
|
+
const phys = scene.physics3d;
|
|
458
|
+
if (!phys?.ready())
|
|
459
|
+
return;
|
|
460
|
+
const t = actor.components.Transform;
|
|
461
|
+
const per = persistentOf(scene);
|
|
462
|
+
if (per.score === undefined)
|
|
463
|
+
per.score = 0;
|
|
464
|
+
// The first frame of an actor (actor.runtime is rebuilt on a load) faces
|
|
465
|
+
// away from the camera, as the keyless Player does.
|
|
466
|
+
if (typeof rt.facing !== 'number')
|
|
467
|
+
rt.facing = Math.PI - per.camAngle;
|
|
468
|
+
const shape = actor.components.Shape;
|
|
469
|
+
const grounded = hoverSteadily(phys, actor, t, { radius: shape?.radius ?? 0.35, height: shape?.height ?? 1.4 });
|
|
470
|
+
applyMove(phys, actor, driveOrbiting(scene, per, rt, props, dt), props.speed, grounded, dt);
|
|
471
|
+
t.rotationY = rt.facing / DEG;
|
|
472
|
+
jumpOrbiting(phys, actor, scene, rt, grounded, props.jumpSpeed, dt);
|
|
473
|
+
hudOrbiting(scene, actor, t, per, rt.facing);
|
|
474
|
+
}
|
|
475
|
+
const finiteOr = (value, otherwise) => (Number.isFinite(value) ? value : otherwise);
|
|
476
|
+
// The tilt and distance the player has chosen, on the runtime: they start
|
|
477
|
+
// at the scene's starting pitch and distance (or the defaults), and start
|
|
478
|
+
// again when those keys or camDistance/camHeight change. The latter two
|
|
479
|
+
// ask for a fresh camera but do not set its orbit distance or pitch.
|
|
480
|
+
function orbitChoice(scene, props) {
|
|
481
|
+
const distance = finiteOr(props.camDistance, 9);
|
|
482
|
+
const height = finiteOr(props.camHeight, 7);
|
|
483
|
+
// Only a finite number is a start; anything else is the default, so a
|
|
484
|
+
// copy of the same scene data (a fresh {} included) never restarts it.
|
|
485
|
+
const startDistance = finiteOr(scene.data?.engine?.camera?.distance, undefined);
|
|
486
|
+
const startPitch = finiteOr(scene.data?.engine?.camera?.pitch, undefined);
|
|
487
|
+
const minPitch = finiteOr(scene.data?.engine?.camera?.minPitch, undefined);
|
|
488
|
+
const least = clamp(finiteOr(minPitch, -80) * DEG, ORBIT_PITCH_LEAST, ORBIT_PITCH_MOST);
|
|
489
|
+
const chosen = scene.cameraOrbit;
|
|
490
|
+
if (chosen && chosen.distance === distance && chosen.height === height
|
|
491
|
+
&& Object.is(chosen.startDistance, startDistance) && Object.is(chosen.startPitch, startPitch)
|
|
492
|
+
&& Object.is(chosen.minPitch, minPitch))
|
|
493
|
+
return chosen;
|
|
494
|
+
scene.cameraOrbit = {
|
|
495
|
+
distance,
|
|
496
|
+
height,
|
|
497
|
+
startDistance,
|
|
498
|
+
startPitch,
|
|
499
|
+
minPitch,
|
|
500
|
+
least,
|
|
501
|
+
range: clamp(finiteOr(startDistance, ORBIT_START), ORBIT_NEAREST, ORBIT_FARTHEST),
|
|
502
|
+
pitch: clamp(Number.isFinite(startPitch) ? startPitch * DEG : ORBIT_PITCH_START, least, ORBIT_PITCH_MOST),
|
|
503
|
+
nearest: ORBIT_NEAREST,
|
|
504
|
+
farthest: ORBIT_FARTHEST,
|
|
505
|
+
};
|
|
506
|
+
return scene.cameraOrbit;
|
|
507
|
+
}
|
|
508
|
+
// What the player asked of the camera this frame, onto what it is aimed for.
|
|
509
|
+
function steerOrbit(per, chosen, look) {
|
|
510
|
+
per.camAngle += look.yaw;
|
|
511
|
+
chosen.pitch = clamp(chosen.pitch + look.pitch, chosen.least, ORBIT_PITCH_MOST);
|
|
512
|
+
chosen.range = clamp(chosen.range * look.zoom, chosen.nearest, chosen.farthest);
|
|
513
|
+
}
|
|
514
|
+
// The ray from the point the camera looks at (the eased one the camera is
|
|
515
|
+
// placed from) toward where it wants to be: a unit direction.
|
|
516
|
+
const ray = { from: { x: 0, y: 0, z: 0 }, dir: { x: 0, y: 0, z: 0 } };
|
|
517
|
+
// Whether this frame's camera collides: a physics world, and an api with the
|
|
518
|
+
// lens's queries (systems/physics3d.js `castBallFixed`, `nearFixed`,
|
|
519
|
+
// `castRayFixedNormal`).
|
|
520
|
+
const collides = (phys) => Boolean(phys?.castBallFixed && phys.nearFixed && phys.castRayFixedNormal && phys.ready());
|
|
521
|
+
// Where the camera's ball is swept from this frame (`findStart`), and its
|
|
522
|
+
// radius: the look point (`ray.from`) and the margin, or, near surfaces, a
|
|
523
|
+
// point moved off them (and, in a gap narrower than twice the margin, a
|
|
524
|
+
// smaller ball). `clear` is false when no start was found; then it is the
|
|
525
|
+
// look point and the camera is held by a ray alone (`sweep`).
|
|
526
|
+
const start = { x: 0, y: 0, z: 0, radius: 0, clear: true };
|
|
527
|
+
// The ball must start clear of everything (rapier does not answer a ball
|
|
528
|
+
// that starts touching a solid reliably). Every fixed surface within the
|
|
529
|
+
// radius and START_SKIN of the start (`nearFixed`) gives a plane touching
|
|
530
|
+
// its solid at its nearest point, with all of a convex solid behind it; the
|
|
531
|
+
// start is the look point moved the least way that puts it that far in
|
|
532
|
+
// front of every plane found so far, all together (`leastMove`), so in a
|
|
533
|
+
// corner the moves do not undo each other; then it is looked around again,
|
|
534
|
+
// until nothing is that near. Each plane keeps the ball off its solid, so
|
|
535
|
+
// planes found from earlier places still hold. The move grows from nothing
|
|
536
|
+
// as the look point comes nearer, so the camera does not jump. Where no
|
|
537
|
+
// place is that far off every plane (a gap narrower than twice the radius)
|
|
538
|
+
// the place that falls least short is taken with the ball made that much
|
|
539
|
+
// smaller, no smaller than START_LEAST. Then the camera point stays out of
|
|
540
|
+
// the walls but the lens does not: its near plane cuts into them (accepted,
|
|
541
|
+
// as Roblox's camera clips there; the near plane is not shrunk). One query
|
|
542
|
+
// in the open; two by a wall or in a corner.
|
|
543
|
+
function findStart(phys, margin) {
|
|
544
|
+
start.x = ray.from.x;
|
|
545
|
+
start.y = ray.from.y;
|
|
546
|
+
start.z = ray.from.z;
|
|
547
|
+
start.radius = margin;
|
|
548
|
+
start.clear = true;
|
|
549
|
+
if (!collides(phys))
|
|
550
|
+
return;
|
|
551
|
+
planes.length = 0;
|
|
552
|
+
let radius = margin;
|
|
553
|
+
for (let i = 0; i < START_TRIES; i += 1) {
|
|
554
|
+
const near = phys.nearFixed(start, radius + START_SKIN);
|
|
555
|
+
let closest = Infinity;
|
|
556
|
+
for (const n of near) {
|
|
557
|
+
if (n.inside || !n.normal || !(n.distance >= 0))
|
|
558
|
+
return giveUpStart();
|
|
559
|
+
closest = Math.min(closest, n.distance);
|
|
560
|
+
}
|
|
561
|
+
if (closest >= radius + START_SKIN - START_SETTLED) {
|
|
562
|
+
start.radius = radius;
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
for (const n of near)
|
|
566
|
+
if (n.distance < radius + START_SKIN - START_SETTLED)
|
|
567
|
+
addPlane(n);
|
|
568
|
+
const move = leastMove(radius + START_SKIN);
|
|
569
|
+
if (move.short > 0)
|
|
570
|
+
radius -= move.short;
|
|
571
|
+
if (!(radius >= START_LEAST))
|
|
572
|
+
return giveUpStart();
|
|
573
|
+
start.x = ray.from.x + move.x;
|
|
574
|
+
start.y = ray.from.y + move.y;
|
|
575
|
+
start.z = ray.from.z + move.z;
|
|
576
|
+
}
|
|
577
|
+
return giveUpStart();
|
|
578
|
+
}
|
|
579
|
+
function giveUpStart() {
|
|
580
|
+
start.x = ray.from.x;
|
|
581
|
+
start.y = ray.from.y;
|
|
582
|
+
start.z = ray.from.z;
|
|
583
|
+
start.clear = false;
|
|
584
|
+
}
|
|
585
|
+
// The planes `findStart` has found this frame: a unit normal facing the
|
|
586
|
+
// look point's side and the offset along it (n . p = d on the plane).
|
|
587
|
+
const planes = [];
|
|
588
|
+
const MOST_PLANES = 12;
|
|
589
|
+
function addPlane(near) {
|
|
590
|
+
const n = near.normal;
|
|
591
|
+
const d = n.x * near.point.x + n.y * near.point.y + n.z * near.point.z;
|
|
592
|
+
if (!Number.isFinite(d) || planes.length >= MOST_PLANES)
|
|
593
|
+
return;
|
|
594
|
+
for (const p of planes)
|
|
595
|
+
if (p.x * n.x + p.y * n.y + p.z * n.z > 1 - 1e-9 && Math.abs(p.d - d) < 1e-6)
|
|
596
|
+
return;
|
|
597
|
+
planes.push({ x: n.x, y: n.y, z: n.z, d });
|
|
598
|
+
}
|
|
599
|
+
// The least move from the look point that leaves it `gap` or more in front
|
|
600
|
+
// of every plane: the nearest point of the intersection of their
|
|
601
|
+
// half-spaces, which lies on at most three of the planes, so it is the
|
|
602
|
+
// nearest of the moves onto each set of up to three that clears them all.
|
|
603
|
+
// When none does, the one that falls least short (`short`, how much).
|
|
604
|
+
const best = { x: 0, y: 0, z: 0, short: 0 };
|
|
605
|
+
const trial = { x: 0, y: 0, z: 0 };
|
|
606
|
+
const want = [];
|
|
607
|
+
function leastMove(gap) {
|
|
608
|
+
const at = ray.from;
|
|
609
|
+
want.length = 0;
|
|
610
|
+
for (const p of planes)
|
|
611
|
+
want.push(gap - (p.x * at.x + p.y * at.y + p.z * at.z - p.d));
|
|
612
|
+
let bestShort = Infinity;
|
|
613
|
+
let bestLength = Infinity;
|
|
614
|
+
const consider = () => {
|
|
615
|
+
let short = 0;
|
|
616
|
+
for (let i = 0; i < planes.length; i += 1) {
|
|
617
|
+
const p = planes[i];
|
|
618
|
+
short = Math.max(short, want[i] - (p.x * trial.x + p.y * trial.y + p.z * trial.z));
|
|
619
|
+
}
|
|
620
|
+
const length = Math.hypot(trial.x, trial.y, trial.z);
|
|
621
|
+
const fits = short <= 1e-9;
|
|
622
|
+
const bestFits = bestShort <= 1e-9;
|
|
623
|
+
if ((fits && (!bestFits || length < bestLength)) || (!fits && !bestFits && (short < bestShort - 1e-12 || (short <= bestShort + 1e-12 && length < bestLength)))) {
|
|
624
|
+
bestShort = short;
|
|
625
|
+
bestLength = length;
|
|
626
|
+
best.x = trial.x;
|
|
627
|
+
best.y = trial.y;
|
|
628
|
+
best.z = trial.z;
|
|
629
|
+
}
|
|
630
|
+
};
|
|
631
|
+
trial.x = 0;
|
|
632
|
+
trial.y = 0;
|
|
633
|
+
trial.z = 0;
|
|
634
|
+
consider();
|
|
635
|
+
const n = planes.length;
|
|
636
|
+
for (let i = 0; i < n; i += 1) {
|
|
637
|
+
const a = planes[i];
|
|
638
|
+
trial.x = a.x * want[i];
|
|
639
|
+
trial.y = a.y * want[i];
|
|
640
|
+
trial.z = a.z * want[i];
|
|
641
|
+
consider();
|
|
642
|
+
for (let j = i + 1; j < n; j += 1) {
|
|
643
|
+
const b = planes[j];
|
|
644
|
+
const c = a.x * b.x + a.y * b.y + a.z * b.z;
|
|
645
|
+
const det = 1 - c * c;
|
|
646
|
+
if (det > 1e-9) {
|
|
647
|
+
const s = (want[i] - c * want[j]) / det;
|
|
648
|
+
const t = (want[j] - c * want[i]) / det;
|
|
649
|
+
trial.x = a.x * s + b.x * t;
|
|
650
|
+
trial.y = a.y * s + b.y * t;
|
|
651
|
+
trial.z = a.z * s + b.z * t;
|
|
652
|
+
consider();
|
|
653
|
+
}
|
|
654
|
+
for (let k = j + 1; k < n; k += 1) {
|
|
655
|
+
const e = planes[k];
|
|
656
|
+
// Cramer's rule on the rows a, b, e.
|
|
657
|
+
const bxeX = b.y * e.z - b.z * e.y;
|
|
658
|
+
const bxeY = b.z * e.x - b.x * e.z;
|
|
659
|
+
const bxeZ = b.x * e.y - b.y * e.x;
|
|
660
|
+
const exaX = e.y * a.z - e.z * a.y;
|
|
661
|
+
const exaY = e.z * a.x - e.x * a.z;
|
|
662
|
+
const exaZ = e.x * a.y - e.y * a.x;
|
|
663
|
+
const axbX = a.y * b.z - a.z * b.y;
|
|
664
|
+
const axbY = a.z * b.x - a.x * b.z;
|
|
665
|
+
const axbZ = a.x * b.y - a.y * b.x;
|
|
666
|
+
const det3 = a.x * bxeX + a.y * bxeY + a.z * bxeZ;
|
|
667
|
+
if (Math.abs(det3) <= 1e-9)
|
|
668
|
+
continue;
|
|
669
|
+
trial.x = (want[i] * bxeX + want[j] * exaX + want[k] * axbX) / det3;
|
|
670
|
+
trial.y = (want[i] * bxeY + want[j] * exaY + want[k] * axbY) / det3;
|
|
671
|
+
trial.z = (want[i] * bxeZ + want[j] * exaZ + want[k] * axbZ) / det3;
|
|
672
|
+
consider();
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
best.short = bestShort <= 1e-9 ? 0 : bestShort;
|
|
677
|
+
return best;
|
|
678
|
+
}
|
|
679
|
+
// The farthest the camera may be along a ray that met `hit`, when it is held
|
|
680
|
+
// by a ray alone: the margin short of it, never nearer than CAMERA_NEAREST,
|
|
681
|
+
// except that a hit with a normal (a real surface: systems/physics3d.js
|
|
682
|
+
// `castRayFixedNormal`) is never passed: then no farther than SURFACE_GAP
|
|
683
|
+
// short of it.
|
|
684
|
+
function onRay(hit, margin) {
|
|
685
|
+
const most = Math.max(CAMERA_NEAREST, hit.distance - margin);
|
|
686
|
+
return hit.normal ? Math.min(most, Math.max(0, hit.distance - SURFACE_GAP)) : most;
|
|
687
|
+
}
|
|
688
|
+
// How far from `start` along the unit `dir` the camera may be, looking no
|
|
689
|
+
// farther than `length`: where a ball of `start.radius` (the margin, but in
|
|
690
|
+
// a gap too narrow for it) swept that way first touches a fixed solid (its
|
|
691
|
+
// time of impact), or +Infinity when it touches nothing. The camera there
|
|
692
|
+
// is that far off what stopped it and off everything it passed, so the
|
|
693
|
+
// whole near plane is in front of every surface, at any angle. Without a
|
|
694
|
+
// start, `onRay` of a ray from the look point. One query.
|
|
695
|
+
function sweep(phys, dir, length, margin) {
|
|
696
|
+
if (start.clear) {
|
|
697
|
+
const hit = phys.castBallFixed(start, dir, length, start.radius);
|
|
698
|
+
return hit ? Math.max(0, hit.distance) : Infinity;
|
|
699
|
+
}
|
|
700
|
+
const hit = phys.castRayFixedNormal(start, dir, length + margin);
|
|
701
|
+
return hit ? onRay(hit, margin) : Infinity;
|
|
702
|
+
}
|
|
703
|
+
// The farthest the camera may be along `ray` from `start` (`state.limit`,
|
|
704
|
+
// +Infinity when nothing holds it), Roblox's Popper: the sweep toward where
|
|
705
|
+
// the camera wants to be (its distance), each frame. A nearer limit is taken
|
|
706
|
+
// at once; a farther one, or none, is eased out to at CAMERA_OUT_RATE, never
|
|
707
|
+
// past what this frame's sweep touched, and once the camera is back at its
|
|
708
|
+
// distance it is let go. The ease is measured from the look point, from how
|
|
709
|
+
// far from it the camera was drawn last frame (`state.out`), not along this
|
|
710
|
+
// frame's ray: the start moves as the player nears or leaves a wall, so a
|
|
711
|
+
// limit along the ray from last frame's start is not where the camera was
|
|
712
|
+
// (review 7: a wall 0.5 m off removed let the camera out 1.161 m in a frame
|
|
713
|
+
// where easing allows 1.139). And it eases whatever drew the camera short of
|
|
714
|
+
// its distance, a start moved off a wall too, not only a sweep that held it
|
|
715
|
+
// (review 8: a box beside the look point removed let it out 0.062 m where
|
|
716
|
+
// 0.006 m is allowed); only a zoom moves it at its own pace. The camera is drawn at the nearer of its
|
|
717
|
+
// distance and the limit, so an easing camera never passes what the sweep
|
|
718
|
+
// touches. Not asked while physics has no world.
|
|
719
|
+
// Queries a frame: one `nearFixed` in the open, two by a wall or in a corner
|
|
720
|
+
// (START_TRIES at most), and one sweep, one more while a takeover blend
|
|
721
|
+
// lasts (`holdBlend`). A sweep is three rapier queries as a rule and 25 at
|
|
722
|
+
// most (systems/physics3d.js `castBallFixed`). As a rule 4 in the open and 5
|
|
723
|
+
// by a wall; at most 8 + 2 * 25 = 58 (a blend, a slanted corner, and rapier
|
|
724
|
+
// missing solids in both sweeps). None without a world.
|
|
725
|
+
function limitReach(phys, state, margin, dt) {
|
|
726
|
+
findStart(phys, margin);
|
|
727
|
+
if (!collides(phys))
|
|
728
|
+
return;
|
|
729
|
+
const was = state.out;
|
|
730
|
+
// A camera just placed: where the sweep allows, at once.
|
|
731
|
+
if (!Number.isFinite(was) || !Number.isFinite(state.outRange)) {
|
|
732
|
+
state.limit = sweep(phys, ray.dir, state.range, margin);
|
|
733
|
+
return;
|
|
734
|
+
}
|
|
735
|
+
// How far short of its distance it was drawn last frame (held by a wall,
|
|
736
|
+
// or its start moved off one), eased away at CAMERA_OUT_RATE; and the
|
|
737
|
+
// distance itself as the player zooms, at the zoom's own pace. So it is
|
|
738
|
+
// let out at 6/s whatever drew it short, and a nearer wall takes it in at
|
|
739
|
+
// once. Along this frame's ray from this frame's start. The ball is swept
|
|
740
|
+
// only as far as the camera will be drawn, so the place drawn is the
|
|
741
|
+
// place the sweep checked (`castBallFixed` confirms its end is clear).
|
|
742
|
+
// (Zoomed in since, it is short of no more than the new distance.)
|
|
743
|
+
const short = Math.max(0, Math.min(state.outRange, state.range) - was);
|
|
744
|
+
const free = short <= CAMERA_OUT_DONE;
|
|
745
|
+
const letOut = free ? Infinity : alongRay(state.range - short * (1 - eased(CAMERA_OUT_RATE, dt)));
|
|
746
|
+
const wall = sweep(phys, ray.dir, Math.min(state.range, letOut), margin);
|
|
747
|
+
state.limit = free && wall === Infinity ? Infinity : Math.min(wall, letOut);
|
|
748
|
+
}
|
|
749
|
+
// How far along `ray` (or the unit `dir`) from `start` the camera is `out`
|
|
750
|
+
// from the look point
|
|
751
|
+
// (the farther place, where it moves away from the look point); the place
|
|
752
|
+
// nearest the look point when none is that far.
|
|
753
|
+
function alongRay(out, dir = ray.dir) {
|
|
754
|
+
const sx = start.x - ray.from.x;
|
|
755
|
+
const sy = start.y - ray.from.y;
|
|
756
|
+
const sz = start.z - ray.from.z;
|
|
757
|
+
const ahead = sx * dir.x + sy * dir.y + sz * dir.z;
|
|
758
|
+
const square = ahead * ahead - (sx * sx + sy * sy + sz * sz) + out * out;
|
|
759
|
+
return Math.max(0, -ahead + Math.sqrt(Math.max(0, square)));
|
|
760
|
+
}
|
|
761
|
+
// How far from its place (x, y, z) the camera is drawn this frame: nothing,
|
|
762
|
+
// unless something else placed it (`mine` is false), and then what is left
|
|
763
|
+
// of the way from where it was put (`at`).
|
|
764
|
+
function takenOver(off, at, x, y, z, mine, jumped, dt) {
|
|
765
|
+
if (!mine) {
|
|
766
|
+
// A teleport, or a camera more than 20 m off, snaps as the others do.
|
|
767
|
+
const snap = jumped || Math.hypot(x - at.x, z - at.z) > 20;
|
|
768
|
+
off.x = snap ? 0 : at.x - x;
|
|
769
|
+
off.y = snap ? 0 : at.y - y;
|
|
770
|
+
off.z = snap ? 0 : at.z - z;
|
|
771
|
+
}
|
|
772
|
+
const left = Math.exp(-TAKEOVER_RATE * dt);
|
|
773
|
+
off.x *= left;
|
|
774
|
+
off.y *= left;
|
|
775
|
+
off.z *= left;
|
|
776
|
+
return off;
|
|
777
|
+
}
|
|
778
|
+
// The point drawn while a takeover blend lasts (its place plus `off`) is
|
|
779
|
+
// collided as its place is: swept toward from `start`, and if the ball
|
|
780
|
+
// touches a fixed solid short of it, it is pulled in along that line to
|
|
781
|
+
// where the ball stopped, and the pull is kept in `off`, so the next frame
|
|
782
|
+
// eases on from where it was drawn. One more query, only while it lasts.
|
|
783
|
+
// Returns whether it was pulled in.
|
|
784
|
+
const drawn = { x: 0, y: 0, z: 0 };
|
|
785
|
+
function holdBlend(phys, off, x, y, z, margin) {
|
|
786
|
+
if (!collides(phys))
|
|
787
|
+
return;
|
|
788
|
+
drawn.x = x + off.x - start.x;
|
|
789
|
+
drawn.y = y + off.y - start.y;
|
|
790
|
+
drawn.z = z + off.z - start.z;
|
|
791
|
+
const length = Math.hypot(drawn.x, drawn.y, drawn.z);
|
|
792
|
+
if (!(length > 0))
|
|
793
|
+
return false;
|
|
794
|
+
drawn.x /= length;
|
|
795
|
+
drawn.y /= length;
|
|
796
|
+
drawn.z /= length;
|
|
797
|
+
const most = sweep(phys, drawn, length, margin);
|
|
798
|
+
if (most >= length)
|
|
799
|
+
return false;
|
|
800
|
+
off.x = start.x + drawn.x * most - x;
|
|
801
|
+
off.y = start.y + drawn.y * most - y;
|
|
802
|
+
off.z = start.z + drawn.z * most - z;
|
|
803
|
+
return true;
|
|
804
|
+
}
|
|
805
|
+
// While a takeover blend lasts: a blend held in last frame is let out at
|
|
806
|
+
// the collision pace (`easeBlendOut`), and the point drawn is collided
|
|
807
|
+
// (`holdBlend`). Whether a wall has held it in, this frame or before in
|
|
808
|
+
// this blend: from then on, to the blend's end, it is let out at the
|
|
809
|
+
// collision pace.
|
|
810
|
+
function blendHeldIn(phys, state, off, x, y, z, margin, dt) {
|
|
811
|
+
const was = state.blendHeld === true && Number.isFinite(state.drawnOut);
|
|
812
|
+
if (was)
|
|
813
|
+
easeBlendOut(state, off, x, y, z, dt);
|
|
814
|
+
return holdBlend(phys, off, x, y, z, margin) || was;
|
|
815
|
+
}
|
|
816
|
+
// A blend a wall held in (`holdBlend`, last frame) is let back out at the
|
|
817
|
+
// collision pace, not the blend's: no farther from the look point than
|
|
818
|
+
// easing at CAMERA_OUT_RATE from where it was drawn (`state.drawnOut`)
|
|
819
|
+
// toward where the camera rests this frame (review 10: not its distance,
|
|
820
|
+
// which a start moved off a wall can leave short of the place, holding the
|
|
821
|
+
// blend open for good), as `limitReach` lets its place out, so a
|
|
822
|
+
// wall that goes does not let the blend's TAKEOVER_RATE carry it out
|
|
823
|
+
// (review 9: 0.246 m in a frame where 0.179 m is allowed). Pulled in along
|
|
824
|
+
// its own line from `start`, and the pull kept in `off`. A blend whose own
|
|
825
|
+
// point is no farther than that goes on at its own pace. Returns whether it
|
|
826
|
+
// was held.
|
|
827
|
+
const blendDir = { x: 0, y: 0, z: 0 };
|
|
828
|
+
function easeBlendOut(state, off, x, y, z, dt) {
|
|
829
|
+
const px = x + off.x;
|
|
830
|
+
const py = y + off.y;
|
|
831
|
+
const pz = z + off.z;
|
|
832
|
+
const own = Math.hypot(px - ray.from.x, py - ray.from.y, pz - ray.from.z);
|
|
833
|
+
const was = state.drawnOut;
|
|
834
|
+
// Toward where the camera rests this frame (its place, which a start
|
|
835
|
+
// moved off a wall can put farther out than its distance), and let go
|
|
836
|
+
// within CAMERA_OUT_DONE of it, so a held blend always ends.
|
|
837
|
+
const rest = Math.hypot(x - ray.from.x, y - ray.from.y, z - ray.from.z);
|
|
838
|
+
const allowed = was + Math.max(0, rest - was) * eased(CAMERA_OUT_RATE, dt);
|
|
839
|
+
if (own <= allowed || rest - allowed <= CAMERA_OUT_DONE)
|
|
840
|
+
return false;
|
|
841
|
+
blendDir.x = px - start.x;
|
|
842
|
+
blendDir.y = py - start.y;
|
|
843
|
+
blendDir.z = pz - start.z;
|
|
844
|
+
const length = Math.hypot(blendDir.x, blendDir.y, blendDir.z);
|
|
845
|
+
if (!(length > 0))
|
|
846
|
+
return false;
|
|
847
|
+
blendDir.x /= length;
|
|
848
|
+
blendDir.y /= length;
|
|
849
|
+
blendDir.z /= length;
|
|
850
|
+
const along = Math.min(length, alongRay(allowed, blendDir));
|
|
851
|
+
off.x = start.x + blendDir.x * along - x;
|
|
852
|
+
off.y = start.y + blendDir.y * along - y;
|
|
853
|
+
off.z = start.z + blendDir.z * along - z;
|
|
854
|
+
return true;
|
|
855
|
+
}
|
|
856
|
+
// Client-side, per-player shots only belong to the orbit camera. Neither
|
|
857
|
+
// its chosen angles nor its lens are changed; the deck places the shot clear
|
|
858
|
+
// of solids. Scratch is shared, while the drawn look travels with the actor.
|
|
859
|
+
const shotPose = { x: 0, y: 0, z: 0, yaw: 0, pitch: 0 };
|
|
860
|
+
function validOrbitShot(shot) {
|
|
861
|
+
const valid = shot && shot.look && Number.isFinite(shot.look.x) && Number.isFinite(shot.look.y)
|
|
862
|
+
&& Number.isFinite(shot.look.z) && Number.isFinite(shot.distance) && shot.distance > 0
|
|
863
|
+
&& Number.isFinite(shot.pitch) && Number.isFinite(shot.yaw);
|
|
864
|
+
if (!valid)
|
|
865
|
+
return null;
|
|
866
|
+
const pitch = clamp(shot.pitch, -89, 89) * DEG;
|
|
867
|
+
const yaw = shot.yaw * DEG;
|
|
868
|
+
const flat = Math.cos(pitch);
|
|
869
|
+
shotPose.x = shot.look.x - flat * Math.sin(yaw) * shot.distance;
|
|
870
|
+
shotPose.y = shot.look.y + Math.sin(pitch) * shot.distance;
|
|
871
|
+
shotPose.z = shot.look.z + flat * Math.cos(yaw) * shot.distance;
|
|
872
|
+
shotPose.yaw = Math.atan2(flat * Math.sin(yaw), flat * Math.cos(yaw));
|
|
873
|
+
shotPose.pitch = pitch;
|
|
874
|
+
// Finite inputs can still overflow when added; treat that as absent too.
|
|
875
|
+
return Number.isFinite(shotPose.x) && Number.isFinite(shotPose.y) && Number.isFinite(shotPose.z) ? shot : null;
|
|
876
|
+
}
|
|
877
|
+
function ownsShotCamera(scene, drawnLook, cam, dt) {
|
|
878
|
+
return typeof drawnLook.placedAt === 'number' && Math.abs(scene.time - dt - drawnLook.placedAt) < PLACED_WITHIN
|
|
879
|
+
&& drawnLook.atX === cam.position.x && drawnLook.atY === cam.position.y && drawnLook.atZ === cam.position.z
|
|
880
|
+
&& drawnLook.qX === cam.quaternion.x && drawnLook.qY === cam.quaternion.y
|
|
881
|
+
&& drawnLook.qZ === cam.quaternion.z && drawnLook.qW === cam.quaternion.w;
|
|
882
|
+
}
|
|
883
|
+
function recordShotCamera(scene, drawnLook, cam) {
|
|
884
|
+
drawnLook.placedAt = scene.time;
|
|
885
|
+
drawnLook.atX = cam.position.x;
|
|
886
|
+
drawnLook.atY = cam.position.y;
|
|
887
|
+
drawnLook.atZ = cam.position.z;
|
|
888
|
+
drawnLook.qX = cam.quaternion.x;
|
|
889
|
+
drawnLook.qY = cam.quaternion.y;
|
|
890
|
+
drawnLook.qZ = cam.quaternion.z;
|
|
891
|
+
drawnLook.qW = cam.quaternion.w;
|
|
892
|
+
}
|
|
893
|
+
function placeOrbitShot(scene, cam, rt, state, before, t, shot, dt) {
|
|
894
|
+
const drawnLook = (rt.orbitShot ??= { active: false, returning: false, x: 0, y: 0, z: 0 });
|
|
895
|
+
const continuing = drawnLook.active || drawnLook.returning;
|
|
896
|
+
if (!continuing || !ownsShotCamera(scene, drawnLook, cam, dt)) {
|
|
897
|
+
// The previous orbit look point gives the focus distance. Along the
|
|
898
|
+
// actual drawn direction, so even a camera another system placed has
|
|
899
|
+
// no rotation snap on entry. No temporary vectors on the frame path.
|
|
900
|
+
const at = cam.position;
|
|
901
|
+
const distance = (continuing
|
|
902
|
+
? Math.hypot(at.x - shot.look.x, at.y - shot.look.y, at.z - shot.look.z)
|
|
903
|
+
: Math.hypot(at.x - (before?.x ?? t.x), at.y - ((state.heightTo ?? t.y) + LOOK_HEIGHT), at.z - (before?.z ?? t.z))) || shot.distance;
|
|
904
|
+
const q = cam.quaternion;
|
|
905
|
+
drawnLook.x = at.x - 2 * (q.x * q.z + q.w * q.y) * distance;
|
|
906
|
+
drawnLook.y = at.y + 2 * (q.w * q.x - q.y * q.z) * distance;
|
|
907
|
+
drawnLook.z = at.z + (2 * (q.x * q.x + q.y * q.y) - 1) * distance;
|
|
908
|
+
// The camera's right vector retains azimuth even when its forward
|
|
909
|
+
// vector is vertical. Seed it on entry or an ownership interruption.
|
|
910
|
+
drawnLook.yaw = Math.atan2(2 * (q.x * q.z - q.w * q.y), 1 - 2 * (q.y * q.y + q.z * q.z));
|
|
911
|
+
}
|
|
912
|
+
drawnLook.active = true;
|
|
913
|
+
drawnLook.returning = false;
|
|
914
|
+
const at = cam.position;
|
|
915
|
+
if (at.x === shotPose.x && at.y === shotPose.y && at.z === shotPose.z
|
|
916
|
+
&& drawnLook.x === shot.look.x && drawnLook.y === shot.look.y && drawnLook.z === shot.look.z) {
|
|
917
|
+
drawnLook.yaw = shotPose.yaw;
|
|
918
|
+
cam.lookAt(drawnLook.x, drawnLook.y, drawnLook.z);
|
|
919
|
+
recordShotCamera(scene, drawnLook, cam);
|
|
920
|
+
return;
|
|
921
|
+
}
|
|
922
|
+
const k = eased(TAKEOVER_RATE, dt);
|
|
923
|
+
// Ease around the drawn focus, so opposite shots never cross through it.
|
|
924
|
+
const dx = at.x - drawnLook.x;
|
|
925
|
+
const dy = at.y - drawnLook.y;
|
|
926
|
+
const dz = at.z - drawnLook.z;
|
|
927
|
+
const flat = Math.hypot(dx, dz);
|
|
928
|
+
const distance = Math.hypot(flat, dy);
|
|
929
|
+
const yaw = flat < SHOT_YAW_EPS * distance ? drawnLook.yaw : Math.atan2(-dx, dz);
|
|
930
|
+
const pitch = Math.atan2(dy, flat);
|
|
931
|
+
const nextYaw = yaw + arc(shotPose.yaw - yaw) * k;
|
|
932
|
+
const nextPitch = clamp(pitch + (shotPose.pitch - pitch) * k, -SHOT_PITCH_LIMIT, SHOT_PITCH_LIMIT);
|
|
933
|
+
const nextDistance = distance + (shot.distance - distance) * k;
|
|
934
|
+
drawnLook.yaw = nextYaw;
|
|
935
|
+
drawnLook.x += (shot.look.x - drawnLook.x) * k;
|
|
936
|
+
drawnLook.y += (shot.look.y - drawnLook.y) * k;
|
|
937
|
+
drawnLook.z += (shot.look.z - drawnLook.z) * k;
|
|
938
|
+
if (Math.abs(arc(shotPose.yaw - nextYaw)) < SHOT_SETTLED && Math.abs(shotPose.pitch - nextPitch) < SHOT_SETTLED
|
|
939
|
+
&& Math.abs(shot.distance - nextDistance) < SHOT_SETTLED
|
|
940
|
+
&& Math.hypot(shot.look.x - drawnLook.x, shot.look.y - drawnLook.y, shot.look.z - drawnLook.z) < SHOT_SETTLED) {
|
|
941
|
+
drawnLook.x = shot.look.x;
|
|
942
|
+
drawnLook.y = shot.look.y;
|
|
943
|
+
drawnLook.z = shot.look.z;
|
|
944
|
+
drawnLook.yaw = shotPose.yaw;
|
|
945
|
+
at.set(shotPose.x, shotPose.y, shotPose.z);
|
|
946
|
+
}
|
|
947
|
+
else {
|
|
948
|
+
const nextFlat = Math.cos(nextPitch);
|
|
949
|
+
at.set(drawnLook.x - nextFlat * Math.sin(nextYaw) * nextDistance, drawnLook.y + Math.sin(nextPitch) * nextDistance, drawnLook.z + nextFlat * Math.cos(nextYaw) * nextDistance);
|
|
950
|
+
}
|
|
951
|
+
cam.lookAt(drawnLook.x, drawnLook.y, drawnLook.z);
|
|
952
|
+
recordShotCamera(scene, drawnLook, cam);
|
|
953
|
+
}
|
|
954
|
+
// The orbit camera, placed at the end of the frame as the rigid one is
|
|
955
|
+
// (`placeFollowing`): the player's ground position is not eased, its height
|
|
956
|
+
// is, as there. What the camera is doing between frames (`actor.runtime.orbit`)
|
|
957
|
+
// goes with the actor on a scene load. The camera is the player's to steer on
|
|
958
|
+
// a frame only when this also placed it on the frame before, the camera
|
|
959
|
+
// is where this left it, the player did not teleport, and the look input is
|
|
960
|
+
// not locked (the hub locks it through a door trip). Otherwise what was asked
|
|
961
|
+
// of it is dropped; and, all but for the lock, it starts again from what was
|
|
962
|
+
// chosen and eases on from where the camera was put (a hub trip's camera, a
|
|
963
|
+
// cutscene, the first frame, a Player turned off and on).
|
|
964
|
+
function placeOrbiting(scene, id, dt) {
|
|
965
|
+
const actor = scene.getActor(id);
|
|
966
|
+
const props = actor?.components.Player;
|
|
967
|
+
const t = actor?.components.Transform;
|
|
968
|
+
const cam = scene.three?.camera;
|
|
969
|
+
if (!cam || !t || !props || props.$enabled === false)
|
|
970
|
+
return;
|
|
971
|
+
const rt = actor.runtime;
|
|
972
|
+
const per = persistentOf(scene);
|
|
973
|
+
const chosen = orbitChoice(scene, props);
|
|
974
|
+
const look = scene.lookInput?.consume?.();
|
|
975
|
+
const before = per.camLastAt;
|
|
976
|
+
const jumped = Boolean(before) && Math.hypot(t.x - before.x, t.z - before.z) > TELEPORT_PER_FRAME;
|
|
977
|
+
per.camLastAt = { x: t.x, z: t.z };
|
|
978
|
+
const at = cam.position;
|
|
979
|
+
const state = (rt.orbit ??= { off: { x: 0, y: 0, z: 0 } });
|
|
980
|
+
const shot = validOrbitShot(scene.orbitShot);
|
|
981
|
+
if (shot) {
|
|
982
|
+
placeOrbitShot(scene, cam, rt, state, before, t, shot, dt);
|
|
983
|
+
// `look` was consumed above and is deliberately dropped while held.
|
|
984
|
+
scene.orbitOwnModel = id;
|
|
985
|
+
return;
|
|
986
|
+
}
|
|
987
|
+
const drawnLook = rt.orbitShot;
|
|
988
|
+
const handBack = drawnLook?.active === true;
|
|
989
|
+
const keptShot = drawnLook && ownsShotCamera(scene, drawnLook, cam, dt);
|
|
990
|
+
if (handBack) {
|
|
991
|
+
drawnLook.active = false;
|
|
992
|
+
drawnLook.returning = keptShot;
|
|
993
|
+
drawnLook.offX = drawnLook.x - t.x;
|
|
994
|
+
drawnLook.offY = drawnLook.y - t.y - LOOK_HEIGHT;
|
|
995
|
+
drawnLook.offZ = drawnLook.z - t.z;
|
|
996
|
+
}
|
|
997
|
+
if (drawnLook && !keptShot) {
|
|
998
|
+
drawnLook.returning = false;
|
|
999
|
+
drawnLook.offX = drawnLook.offY = drawnLook.offZ = 0;
|
|
1000
|
+
}
|
|
1001
|
+
// Placed on the frame before too: a frame this did not place on (the
|
|
1002
|
+
// Player turned off, even by a collision callback after its update)
|
|
1003
|
+
// breaks the chain.
|
|
1004
|
+
const placed = typeof state.placedAt === 'number' && Math.abs(scene.time - dt - state.placedAt) < PLACED_WITHIN;
|
|
1005
|
+
const mine = !handBack && placed && !jumped && state.x === at.x && state.y === at.y && state.z === at.z;
|
|
1006
|
+
if (mine) {
|
|
1007
|
+
if (look && !look.locked)
|
|
1008
|
+
steerOrbit(per, chosen, look);
|
|
1009
|
+
const k = eased(ORBIT_RATE, dt);
|
|
1010
|
+
state.yaw += arc(per.camAngle - state.yaw) * k;
|
|
1011
|
+
state.pitch += (chosen.pitch - state.pitch) * k;
|
|
1012
|
+
state.range += (chosen.range - state.range) * k;
|
|
1013
|
+
state.height = settle(state.height, state.heightTo, t.y, dt);
|
|
1014
|
+
}
|
|
1015
|
+
else {
|
|
1016
|
+
Object.assign(state, { yaw: per.camAngle, pitch: chosen.pitch, range: chosen.range, height: t.y, limit: Infinity, out: undefined, outRange: undefined, blendHeld: false, drawnOut: undefined });
|
|
1017
|
+
}
|
|
1018
|
+
state.heightTo = t.y;
|
|
1019
|
+
const flat = Math.cos(state.pitch);
|
|
1020
|
+
ray.dir.x = -flat * Math.sin(state.yaw);
|
|
1021
|
+
ray.dir.y = Math.sin(state.pitch);
|
|
1022
|
+
ray.dir.z = flat * Math.cos(state.yaw);
|
|
1023
|
+
// From the point the camera is placed from, so what is tested is the
|
|
1024
|
+
// camera that is drawn (less the takeover blend below, which is not).
|
|
1025
|
+
ray.from.x = t.x;
|
|
1026
|
+
ray.from.y = state.height + LOOK_HEIGHT;
|
|
1027
|
+
ray.from.z = t.z;
|
|
1028
|
+
const margin = lensMargin(scene, cam);
|
|
1029
|
+
limitReach(scene.physics3d, state, margin, dt);
|
|
1030
|
+
// Drawn at the nearer of its distance and the limit, out from the ball's
|
|
1031
|
+
// start (the look point, or a point moved off a surface it is pressed to).
|
|
1032
|
+
const reach = Math.max(Math.min(state.range, state.limit), 0);
|
|
1033
|
+
const x = start.x + ray.dir.x * reach;
|
|
1034
|
+
const y = start.y + ray.dir.y * reach;
|
|
1035
|
+
const z = start.z + ray.dir.z * reach;
|
|
1036
|
+
// How far from the look point it is placed, and the distance it was
|
|
1037
|
+
// placed for, for the next frame's ease.
|
|
1038
|
+
state.out = Math.hypot(x - ray.from.x, y - ray.from.y, z - ray.from.z);
|
|
1039
|
+
state.outRange = state.range;
|
|
1040
|
+
const off = takenOver(state.off, at, x, y, z, mine, jumped, dt);
|
|
1041
|
+
state.blendHeld = Math.hypot(off.x, off.y, off.z) > BLEND_TESTED && blendHeldIn(scene.physics3d, state, off, x, y, z, margin, dt);
|
|
1042
|
+
cam.position.set(x + off.x, y + off.y, z + off.z);
|
|
1043
|
+
// How far from the look point it is drawn, for a held blend's ease.
|
|
1044
|
+
state.drawnOut = Math.hypot(x + off.x - ray.from.x, y + off.y - ray.from.y, z + off.z - ray.from.z);
|
|
1045
|
+
state.placedAt = scene.time;
|
|
1046
|
+
state.x = at.x;
|
|
1047
|
+
state.y = at.y;
|
|
1048
|
+
state.z = at.z;
|
|
1049
|
+
if (drawnLook?.returning) {
|
|
1050
|
+
// Decay the hand-back offset, rather than chasing the moving player:
|
|
1051
|
+
// walking carries the look point immediately and cannot hold it open.
|
|
1052
|
+
const left = jumped ? 0 : Math.exp(-TAKEOVER_RATE * dt);
|
|
1053
|
+
drawnLook.offX *= left;
|
|
1054
|
+
drawnLook.offY *= left;
|
|
1055
|
+
drawnLook.offZ *= left;
|
|
1056
|
+
drawnLook.x = t.x + drawnLook.offX;
|
|
1057
|
+
drawnLook.y = t.y + LOOK_HEIGHT + drawnLook.offY;
|
|
1058
|
+
drawnLook.z = t.z + drawnLook.offZ;
|
|
1059
|
+
if (Math.hypot(drawnLook.offX, drawnLook.offY, drawnLook.offZ) < BLEND_TESTED) {
|
|
1060
|
+
drawnLook.offX = drawnLook.offY = drawnLook.offZ = 0;
|
|
1061
|
+
drawnLook.returning = false;
|
|
1062
|
+
}
|
|
1063
|
+
else {
|
|
1064
|
+
cam.lookAt(drawnLook.x, drawnLook.y, drawnLook.z);
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
if (!drawnLook?.returning) {
|
|
1068
|
+
cam.lookAt(t.x, t.y + LOOK_HEIGHT, t.z);
|
|
1069
|
+
}
|
|
1070
|
+
if (drawnLook)
|
|
1071
|
+
recordShotCamera(scene, drawnLook, cam);
|
|
1072
|
+
// The actor the camera was placed for, for this frame's draw: its model is
|
|
1073
|
+
// left out of the frame if the final camera is inside it
|
|
1074
|
+
// (engine3d/ownmodel.js; the draw takes the name, a load drops it).
|
|
1075
|
+
scene.orbitOwnModel = id;
|
|
1076
|
+
}
|
|
1077
|
+
// Count awake pickups in the same pass as the nearest Lookable, preserving
|
|
1078
|
+
// getActors order for equal-distance ties without two sorted/filtered lists.
|
|
1079
|
+
function hudContents(scene, actor, t, facing) {
|
|
1080
|
+
const fx = Math.sin(facing);
|
|
1081
|
+
const fz = Math.cos(facing);
|
|
1082
|
+
let bestText = '';
|
|
1083
|
+
let bestDist = Infinity;
|
|
1084
|
+
let remaining = 0;
|
|
1085
|
+
for (const other of scene.getActors()) {
|
|
1086
|
+
const pickup = other.components?.Pickup;
|
|
1087
|
+
if (pickup && pickup.$enabled !== false)
|
|
1088
|
+
remaining += 1;
|
|
1089
|
+
const lookable = other.components?.Lookable;
|
|
1090
|
+
if (!lookable || lookable.$enabled === false)
|
|
1091
|
+
continue;
|
|
1092
|
+
if (other.id === actor.id)
|
|
1093
|
+
continue;
|
|
1094
|
+
const ot = other.components.Transform;
|
|
1095
|
+
if (!ot)
|
|
1096
|
+
continue;
|
|
1097
|
+
const dx = ot.x - t.x;
|
|
1098
|
+
const dz = ot.z - t.z;
|
|
1099
|
+
const dist = Math.hypot(dx, dz);
|
|
1100
|
+
const range = other.components.Lookable.range ?? 4;
|
|
1101
|
+
if (dist < 0.01 || dist > range || dist >= bestDist)
|
|
1102
|
+
continue;
|
|
1103
|
+
if ((dx * fx + dz * fz) / dist < 0.7)
|
|
1104
|
+
continue;
|
|
1105
|
+
bestText = other.components.Lookable.text ?? '';
|
|
1106
|
+
bestDist = dist;
|
|
1107
|
+
}
|
|
1108
|
+
return { remaining, look: bestText };
|
|
1109
|
+
}
|
|
1110
|
+
class Player {
|
|
1111
|
+
static behaviorName = 'Player';
|
|
1112
|
+
static defaultProps = { speed: 6, turnSpeed: 2.4, jumpSpeed: 8, camDistance: 9, camHeight: 7 };
|
|
1113
|
+
static propertyMeta = {
|
|
1114
|
+
speed: { min: 0, step: 0.5 },
|
|
1115
|
+
turnSpeed: { min: 0, step: 0.1 },
|
|
1116
|
+
jumpSpeed: { min: 0, step: 0.5 },
|
|
1117
|
+
camDistance: { min: 0, step: 0.5 },
|
|
1118
|
+
camHeight: { min: 0, step: 0.5 },
|
|
1119
|
+
};
|
|
1120
|
+
constructor(props) {
|
|
1121
|
+
this.props = props;
|
|
1122
|
+
}
|
|
1123
|
+
update(actor, scene, dt) {
|
|
1124
|
+
if (scene.cameraControl === 'orbit')
|
|
1125
|
+
return updateOrbiting(actor, scene, this.props, dt);
|
|
1126
|
+
if (scene.cameraFollowsRigidly === true) {
|
|
1127
|
+
scene.followCamera = { id: actor.id, data: scene.data, dt, place: placeFollowing };
|
|
1128
|
+
}
|
|
1129
|
+
const phys = scene.physics3d;
|
|
1130
|
+
if (!phys?.ready())
|
|
1131
|
+
return;
|
|
1132
|
+
const t = actor.components.Transform;
|
|
1133
|
+
// Cross-scene state (camera angle, score) lives on the runtime's
|
|
1134
|
+
// persistent store so it survives `loadFromFile`; actor.runtime is
|
|
1135
|
+
// rebuilt on every scene load.
|
|
1136
|
+
const per = (scene.persistent ??= {});
|
|
1137
|
+
const rt = actor.runtime;
|
|
1138
|
+
if (per.camAngle === undefined)
|
|
1139
|
+
per.camAngle = Math.PI / 4;
|
|
1140
|
+
if (per.score === undefined)
|
|
1141
|
+
per.score = 0;
|
|
1142
|
+
const shape = actor.components.Shape;
|
|
1143
|
+
const dims = { radius: shape?.radius ?? 0.35, height: shape?.height ?? 1.4 };
|
|
1144
|
+
// Under the camera key the player is held steady on screen: the hover
|
|
1145
|
+
// and the fall-faster pull are forces (hoverSteadily). So they are under
|
|
1146
|
+
// the frame cap (`engine.maxFps`, `scene.maxFps` above 0), whose frames
|
|
1147
|
+
// are handed what they took, 1 to 3 physics steps' worth: there an
|
|
1148
|
+
// impulse per frame against gravity per step bobs the player with the
|
|
1149
|
+
// accumulator's carry (docs/engine-frame-cap.md). Without either key
|
|
1150
|
+
// every call below is the one made before the keys had this meaning.
|
|
1151
|
+
const steady = scene.cameraFollowsRigidly === true || scene.maxFps > 0;
|
|
1152
|
+
const grounded = steady ? hoverSteadily(phys, actor, t, dims) : applyHover(phys, actor, t, dims, dt);
|
|
1153
|
+
const drive = readDrive(scene.keys, scene.moveInput);
|
|
1154
|
+
per.camAngle += drive.turn * this.props.turnSpeed * dt;
|
|
1155
|
+
rt.facing = Math.PI - per.camAngle;
|
|
1156
|
+
const move = drive.forward !== 0
|
|
1157
|
+
? {
|
|
1158
|
+
x: Math.sin(per.camAngle) * drive.forward,
|
|
1159
|
+
z: -Math.cos(per.camAngle) * drive.forward,
|
|
1160
|
+
}
|
|
1161
|
+
: null;
|
|
1162
|
+
applyMove(phys, actor, move, this.props.speed, grounded, dt);
|
|
1163
|
+
t.rotationY = rt.facing / DEG;
|
|
1164
|
+
// Jump: Space on keyboard, or a short tap anywhere on the canvas (which
|
|
1165
|
+
// works while another finger drives the drag stick). A tap is buffered
|
|
1166
|
+
// briefly so one made just before touchdown still fires.
|
|
1167
|
+
if (scene.moveInput?.consumeJump?.())
|
|
1168
|
+
rt.jumpBuffer = 0.18;
|
|
1169
|
+
else
|
|
1170
|
+
rt.jumpBuffer = Math.max(0, (rt.jumpBuffer ?? 0) - dt);
|
|
1171
|
+
if ((keyDown(scene.keys, 'Space') || rt.jumpBuffer > 0) && grounded) {
|
|
1172
|
+
rt.jumpBuffer = 0;
|
|
1173
|
+
const vel = phys.getVelocity(actor);
|
|
1174
|
+
phys.setVelocity(actor, { x: vel.x, y: this.props.jumpSpeed, z: vel.z });
|
|
1175
|
+
// The jump replaces the velocity the hover was holding; this frame's
|
|
1176
|
+
// lift goes too, or it would be added to the jump.
|
|
1177
|
+
if (steady)
|
|
1178
|
+
phys.resetForces(actor);
|
|
1179
|
+
}
|
|
1180
|
+
// Fall faster than the rise: extra downward pull past the jump apex kills
|
|
1181
|
+
// the floaty arc.
|
|
1182
|
+
if (!grounded) {
|
|
1183
|
+
const vel = phys.getVelocity(actor);
|
|
1184
|
+
if (vel.y < 1) {
|
|
1185
|
+
if (steady)
|
|
1186
|
+
pullSteadily(phys, actor);
|
|
1187
|
+
else
|
|
1188
|
+
phys.applyImpulse(actor, { x: 0, y: -14 * phys.mass(actor) * dt, z: 0 });
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
if (scene.cameraFollowsRigidly !== true) {
|
|
1192
|
+
if (scene.maxFps > 0)
|
|
1193
|
+
scene.followCamera = { id: actor.id, data: scene.data, dt, place: placeCapped };
|
|
1194
|
+
else
|
|
1195
|
+
updateCamera(scene, t, per, this.props, dt);
|
|
1196
|
+
}
|
|
1197
|
+
const { remaining, look } = hudContents(scene, actor, t, rt.facing);
|
|
1198
|
+
const total = per.score + remaining;
|
|
1199
|
+
const score = total === 0 ? '' : remaining === 0 ? '◆ all shards found' : `◆ ${per.score}/${total}`;
|
|
1200
|
+
scene.hud = { score, look };
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
export { Player };
|