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
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// The camera the player controls: `"engine": { "camera": { "follow": "rigid",
|
|
2
2
|
// "control": "orbit" } }` (behaviors/Player.jsx from `updateOrbiting` on,
|
|
3
|
-
// engine3d/orbitinput.js, `
|
|
3
|
+
// engine3d/orbitinput.js, `castBallFixed`, `nearFixed` and `castRayFixedNormal`
|
|
4
|
+
// in systems/physics3d.js).
|
|
4
5
|
//
|
|
5
6
|
// - Without the key, and with `"follow": "rigid"` alone, the Player is the
|
|
6
7
|
// Player it was: every drawn frame of a scripted run (keys, stick, taps, a
|
|
@@ -26,7 +27,8 @@
|
|
|
26
27
|
// where it was left.
|
|
27
28
|
// - The pointers' roles (stick, look, pinch, tap), the wheel, the lock, and
|
|
28
29
|
// the listeners that are only there under the key.
|
|
29
|
-
// - `castRayFixed`
|
|
30
|
+
// - `castRayFixed`, `castRayFixedNormal`, `castBallFixed` and `nearFixed`
|
|
31
|
+
// on rapier itself, when it is installed here.
|
|
30
32
|
//
|
|
31
33
|
// test-static-actors.mjs runs it (`npm run check`).
|
|
32
34
|
// node scripts/test-camera-orbit.mjs
|
|
@@ -36,6 +38,8 @@ import { register } from 'node:module';
|
|
|
36
38
|
import { dirname, join } from 'node:path';
|
|
37
39
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
38
40
|
import * as THREE from 'three';
|
|
41
|
+
import { runShiftLockChecks } from './test-orbit-shift-lock.mjs';
|
|
42
|
+
import { runOrbitShotChecks } from './test-orbit-shot.mjs';
|
|
39
43
|
|
|
40
44
|
const stub = `
|
|
41
45
|
const any = () => new Proxy(function () {}, {
|
|
@@ -89,11 +93,14 @@ const hooks = `
|
|
|
89
93
|
const real = ${JSON.stringify(realRapier)};
|
|
90
94
|
const engineStubs = ${JSON.stringify(engineStubs)};
|
|
91
95
|
export async function resolve(specifier, context, next) {
|
|
96
|
+
const isRapier = specifier === '@dimforge/rapier3d-compat' ||
|
|
97
|
+
((specifier.startsWith('.') || specifier.startsWith('file:')) &&
|
|
98
|
+
new URL(specifier, context.parentURL).href.endsWith('/kits/physics-3d/engine3d/rapier.js'));
|
|
92
99
|
const parent = context.parentURL ?? '';
|
|
93
100
|
if (parent.includes('/physics-2d/engine/') && engineStubs[specifier]) {
|
|
94
101
|
return { url: 'data:text/javascript,' + encodeURIComponent(engineStubs[specifier]) + '#orbit-' + encodeURIComponent(specifier), shortCircuit: true };
|
|
95
102
|
}
|
|
96
|
-
if (
|
|
103
|
+
if (isRapier) {
|
|
97
104
|
if (parent.endsWith('?orbit-real')) return { url: real, shortCircuit: true };
|
|
98
105
|
return { url: 'data:text/javascript,' + encodeURIComponent(${JSON.stringify(stub)}), shortCircuit: true };
|
|
99
106
|
}
|
|
@@ -121,6 +128,8 @@ const { Player: PlayerBefore } = await import('./Player.before-orbit.mjs');
|
|
|
121
128
|
const { placeFollowCamera, Physics3DSystem } = await import('../systems/physics3d.js');
|
|
122
129
|
const { makeLookGestures, attachOrbitInput, stickFrom, LOOK_RAD_PER_PX, WHEEL_ZOOM_PER_NOTCH } = await import('../engine3d/orbitinput.js');
|
|
123
130
|
const { SceneRuntime } = await import('../../physics-2d/engine/scene.js');
|
|
131
|
+
const { renderHidingOwnModel, HIDE_WITHIN, SHOW_PAST } = await import('../engine3d/ownmodel.js');
|
|
132
|
+
const { fitOrbitLens } = await import('../engine3d/orbitlens.js');
|
|
124
133
|
|
|
125
134
|
const DEG = Math.PI / 180;
|
|
126
135
|
const FIXED = 1 / 60;
|
|
@@ -128,9 +137,97 @@ const PROPS = { ...Player.defaultProps };
|
|
|
128
137
|
const FLOOR = 0.7;
|
|
129
138
|
const TUNING = { stickRadius: 56, tapSlop: 12, tapMs: 300 };
|
|
130
139
|
// The Player's own numbers, restated: a change there is a change here.
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
const
|
|
140
|
+
// Roblox's default camera at our scale: its character is 5 studs tall, the
|
|
141
|
+
// kit's avatar 1.46 m, so a stud is 0.292 m.
|
|
142
|
+
const STUD = 1.46 / 5;
|
|
143
|
+
// The look point: Roblox's root part plus 1.5 studs, 0.438 m above the
|
|
144
|
+
// Transform (the capsule's middle, the torso's).
|
|
145
|
+
const LOOK_HEIGHT = 1.5 * STUD;
|
|
146
|
+
// Where the camera starts: 12.5 studs, 3.65 m, whatever camDistance and
|
|
147
|
+
// camHeight are, 15 degrees down.
|
|
148
|
+
const RANGE0 = 12.5 * STUD;
|
|
149
|
+
const PITCH0 = 15 * DEG;
|
|
150
|
+
// The zoom: 1.5 m in (Roblox's 0.5 studs would be first person), 128 studs
|
|
151
|
+
// (37.4 m) out. The tilt: 80 degrees either way of the horizontal.
|
|
152
|
+
const NEAREST = 1.5;
|
|
153
|
+
const FARTHEST = 128 * STUD;
|
|
154
|
+
const PITCH_LEAST = -80 * DEG;
|
|
155
|
+
const PITCH_MOST = 80 * DEG;
|
|
156
|
+
|
|
157
|
+
// A query the camera asks of physics (`nearFixed`, `castBallFixed`,
|
|
158
|
+
// `castRayFixedNormal`): counted, and the frame's first sweep (the one toward
|
|
159
|
+
// where the camera wants to be; a blend's comes after) kept as `lastCast`.
|
|
160
|
+
function noteQuery(world) {
|
|
161
|
+
world.casts += 1;
|
|
162
|
+
}
|
|
163
|
+
function noteCast(world, from, dir, max, radius) {
|
|
164
|
+
noteQuery(world);
|
|
165
|
+
world.sweeps = (world.sweeps ?? 0) + 1;
|
|
166
|
+
if (world.castAt === world.scene.time) return;
|
|
167
|
+
world.castAt = world.scene.time;
|
|
168
|
+
world.lastCast = { from: { ...from }, dir: { ...dir }, max, radius };
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Stand-in fixed solids for the camera's queries: half-spaces `{ n, d }`,
|
|
172
|
+
// each the unit normal out of the solid and its face's offset along it
|
|
173
|
+
// (n . p = d on the face, less inside). A ball is never swept from a place
|
|
174
|
+
// that already touches one: the Player starts it clear (rapier does not
|
|
175
|
+
// answer such a sweep reliably).
|
|
176
|
+
function halfSpaces(world, planes) {
|
|
177
|
+
const sideOf = (p, { n, d }) => n.x * p.x + n.y * p.y + n.z * p.z - d;
|
|
178
|
+
const sweep = (from, dir, max, radius) => {
|
|
179
|
+
let best = null;
|
|
180
|
+
for (const plane of planes) {
|
|
181
|
+
const s = sideOf(from, plane);
|
|
182
|
+
if (radius > 0) assert.ok(s >= radius - 1e-9, `the ball starts clear (${s} off a face, radius ${radius})`);
|
|
183
|
+
else if (s < 0) return { distance: 0, actorId: plane.actorId ?? null, normal: { ...plane.n } };
|
|
184
|
+
const closing = -(plane.n.x * dir.x + plane.n.y * dir.y + plane.n.z * dir.z);
|
|
185
|
+
if (!(closing > 0)) continue;
|
|
186
|
+
const distance = (s - radius) / closing;
|
|
187
|
+
if (distance <= max && (!best || distance < best.distance)) best = { distance, actorId: plane.actorId ?? null, normal: { ...plane.n } };
|
|
188
|
+
}
|
|
189
|
+
return best;
|
|
190
|
+
};
|
|
191
|
+
Object.assign(world.scene.physics3d, {
|
|
192
|
+
castRayFixedNormal: (from, dir, max) => {
|
|
193
|
+
noteQuery(world);
|
|
194
|
+
return sweep(from, dir, max, 0);
|
|
195
|
+
},
|
|
196
|
+
castBallFixed: (from, dir, max, radius) => {
|
|
197
|
+
noteCast(world, from, dir, max, radius);
|
|
198
|
+
return sweep(from, dir, max, radius);
|
|
199
|
+
},
|
|
200
|
+
nearFixed: (p, within) => {
|
|
201
|
+
noteQuery(world);
|
|
202
|
+
const found = [];
|
|
203
|
+
for (const plane of planes) {
|
|
204
|
+
const s = sideOf(p, plane);
|
|
205
|
+
const point = { x: p.x - plane.n.x * s, y: p.y - plane.n.y * s, z: p.z - plane.n.z * s };
|
|
206
|
+
if (s < 0) found.push({ distance: 0, inside: true, normal: null, point, actorId: plane.actorId ?? null });
|
|
207
|
+
else if (s <= within) found.push({ distance: s, inside: false, normal: { ...plane.n }, point, actorId: plane.actorId ?? null });
|
|
208
|
+
}
|
|
209
|
+
return found;
|
|
210
|
+
},
|
|
211
|
+
});
|
|
212
|
+
return world;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// The camera's queries delegated to a physics api (rapier's own), counted:
|
|
216
|
+
// whichever of them it has.
|
|
217
|
+
const CAMERA_QUERIES = ['castRayFixed', 'castRayFixedNormal', 'castBallFixed', 'nearFixed', 'nearestFixed'];
|
|
218
|
+
function queriesOf(world, api) {
|
|
219
|
+
for (const name of CAMERA_QUERIES) {
|
|
220
|
+
if (!api[name]) continue;
|
|
221
|
+
world.scene.physics3d[name] = (...args) => {
|
|
222
|
+
if (name === 'castBallFixed') noteCast(world, ...args);
|
|
223
|
+
else noteQuery(world);
|
|
224
|
+
const hit = api[name](...args);
|
|
225
|
+
if (name === 'castBallFixed') world.lastHit = hit;
|
|
226
|
+
return hit;
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
return world;
|
|
230
|
+
}
|
|
134
231
|
|
|
135
232
|
// A world of one capsule on flat ground, stepped as systems/physics3d.js
|
|
136
233
|
// steps (test-camera-follow.mjs's, with the scene's latched keys settable
|
|
@@ -161,13 +258,22 @@ function makeWorld(mode, PlayerClass = Player) {
|
|
|
161
258
|
resetForces: logged('resetForces', () => {
|
|
162
259
|
body.force = 0;
|
|
163
260
|
}),
|
|
164
|
-
// What stands between the camera and the player: `world.wall`
|
|
165
|
-
//
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
world
|
|
261
|
+
// What stands between the camera and the player: a shell `world.wall`
|
|
262
|
+
// metres round the point the camera looks at, or nothing; the look
|
|
263
|
+
// point is never near it.
|
|
264
|
+
castRayFixedNormal: (from, dir, max) => {
|
|
265
|
+
noteQuery(world);
|
|
169
266
|
return world.wall !== null && world.wall <= max ? { distance: world.wall, actorId: 'wall' } : null;
|
|
170
267
|
},
|
|
268
|
+
castBallFixed: (from, dir, max, radius) => {
|
|
269
|
+
noteCast(world, from, dir, max, radius);
|
|
270
|
+
const distance = world.wall === null ? Infinity : Math.max(0, world.wall - radius);
|
|
271
|
+
return distance <= max ? { distance, actorId: 'wall' } : null;
|
|
272
|
+
},
|
|
273
|
+
nearFixed: () => {
|
|
274
|
+
noteQuery(world);
|
|
275
|
+
return [];
|
|
276
|
+
},
|
|
171
277
|
};
|
|
172
278
|
const stick = {
|
|
173
279
|
x: 0,
|
|
@@ -201,6 +307,7 @@ function makeWorld(mode, PlayerClass = Player) {
|
|
|
201
307
|
three: { camera },
|
|
202
308
|
time: 0,
|
|
203
309
|
actorsWith: () => [],
|
|
310
|
+
getActors: () => scene.actors,
|
|
204
311
|
getActor: (id) => scene.actors.find((a) => a.id === id),
|
|
205
312
|
};
|
|
206
313
|
world.scene = scene;
|
|
@@ -329,6 +436,12 @@ function unkeyedIsUnchanged() {
|
|
|
329
436
|
for (const mode of ['off', 'rigid']) {
|
|
330
437
|
const now = makeWorld(mode, Player);
|
|
331
438
|
const before = makeWorld(mode, PlayerBefore);
|
|
439
|
+
// These keys must never even be read without the orbit key.
|
|
440
|
+
now.scene.data = { engine: { camera: {
|
|
441
|
+
get distance() { return assert.fail(`${mode}: read engine.camera.distance`); },
|
|
442
|
+
get pitch() { return assert.fail(`${mode}: read engine.camera.pitch`); },
|
|
443
|
+
get minPitch() { return assert.fail(`${mode}: read engine.camera.minPitch`); },
|
|
444
|
+
} } };
|
|
332
445
|
const stepNow = scripted(now);
|
|
333
446
|
const stepBefore = scripted(before);
|
|
334
447
|
for (let i = 0; i < 720; i += 1) {
|
|
@@ -337,7 +450,7 @@ function unkeyedIsUnchanged() {
|
|
|
337
450
|
}
|
|
338
451
|
same(now, before, `${mode}: the Player is the one before the key`);
|
|
339
452
|
assert.ok(now.frames.some((f) => f.calls.includes(mode === 'rigid' ? 'addForce' : 'applyImpulse')), 'and the run did something');
|
|
340
|
-
assert.equal(now.casts, 0, `${mode}: nothing is asked of
|
|
453
|
+
assert.equal(now.casts, 0, `${mode}: nothing is asked of castRayFixedNormal, castBallFixed or nearFixed`);
|
|
341
454
|
assert.deepEqual(now.lookCalls(), { listens: 0, consumes: 0 }, `${mode}: the camera's input is not touched`);
|
|
342
455
|
assert.equal(now.scene.cameraOrbit, undefined, `${mode}: nothing is kept on the runtime`);
|
|
343
456
|
assert.equal(now.actor.runtime.orbit, undefined, `${mode}: nor on the actor`);
|
|
@@ -390,7 +503,7 @@ const cutAttachInput = (file) => {
|
|
|
390
503
|
assert.ok(cut.length > 1000 && cut.trimEnd().endsWith('\n}') && !/<[A-Za-z]/.test(cut), `attachInput is cut out of ${file} whole, with no JSX in it`);
|
|
391
504
|
return cut;
|
|
392
505
|
};
|
|
393
|
-
const ATTACH_NOW = cutAttachInput('../engine3d/
|
|
506
|
+
const ATTACH_NOW = cutAttachInput('../engine3d/playerRun.js');
|
|
394
507
|
const ATTACH_BEFORE = cutAttachInput('./Scene3DPlayer.before-orbit.jsx');
|
|
395
508
|
assert.ok(!ATTACH_BEFORE.includes('orbit') && ATTACH_NOW.includes('orbit'), 'the two are the two');
|
|
396
509
|
// A stand-in window whose listeners are kept, as the canvas's are.
|
|
@@ -457,6 +570,18 @@ function makeRuntime(mode, PlayerClass = Player, attachSource = PlayerClass ===
|
|
|
457
570
|
harness.casts += 1;
|
|
458
571
|
return null;
|
|
459
572
|
},
|
|
573
|
+
castRayFixedNormal: () => {
|
|
574
|
+
harness.casts += 1;
|
|
575
|
+
return null;
|
|
576
|
+
},
|
|
577
|
+
castBallFixed: () => {
|
|
578
|
+
harness.casts += 1;
|
|
579
|
+
return null;
|
|
580
|
+
},
|
|
581
|
+
nearFixed: () => {
|
|
582
|
+
harness.casts += 1;
|
|
583
|
+
return [];
|
|
584
|
+
},
|
|
460
585
|
};
|
|
461
586
|
const physics = new Physics3DSystem();
|
|
462
587
|
runtime.registerSystem({
|
|
@@ -601,6 +726,46 @@ function coldKeyless() {
|
|
|
601
726
|
// the orbit input held is gone at the load, with no event, and from the
|
|
602
727
|
// first frame the Player is the one before the key, whatever those fingers
|
|
603
728
|
// go on doing. Then the key again, with no event between.
|
|
729
|
+
// The orbit lens across a load of the runtime itself: physics-2d's
|
|
730
|
+
// SceneRuntime.load resets the physics system before the next scene's data
|
|
731
|
+
// is in, and that reset gives the world camera its lens back
|
|
732
|
+
// (engine3d/orbitlens.js), so a keyless scene's first update already sees
|
|
733
|
+
// it, and what that update sets (70, the key's own number, included) stands.
|
|
734
|
+
// The frames here are the Player's; renderWorld's part is
|
|
735
|
+
// test-orbit-view.mjs's.
|
|
736
|
+
function lensAcrossLoads() {
|
|
737
|
+
let checks = 0;
|
|
738
|
+
for (const own of [70, 85]) {
|
|
739
|
+
const h = makeRuntime('orbit');
|
|
740
|
+
const world = h.runtime.three;
|
|
741
|
+
const before = h.camera.projectionMatrix.toArray();
|
|
742
|
+
for (let i = 0; i < 5; i += 1) {
|
|
743
|
+
h.frame();
|
|
744
|
+
fitOrbitLens(world, h.runtime);
|
|
745
|
+
}
|
|
746
|
+
assert.equal(h.camera.fov, 70, 'the key took the lens');
|
|
747
|
+
h.load('off');
|
|
748
|
+
assert.equal(h.runtime.cameraControl, null);
|
|
749
|
+
assert.equal(h.camera.fov, 50, 'given back by the load, before the keyless scene runs');
|
|
750
|
+
assert.deepEqual(h.camera.projectionMatrix.toArray(), before);
|
|
751
|
+
assert.equal(world.orbitLens, null);
|
|
752
|
+
h.camera.fov = own;
|
|
753
|
+
h.camera.updateProjectionMatrix();
|
|
754
|
+
h.run(30);
|
|
755
|
+
assert.equal(h.camera.fov, own, `the keyless scene's ${own} degrees stand`);
|
|
756
|
+
h.load('rigid');
|
|
757
|
+
assert.equal(h.camera.fov, own, 'and a load of another keyless scene does not touch it');
|
|
758
|
+
h.load('orbit');
|
|
759
|
+
h.frame();
|
|
760
|
+
fitOrbitLens(world, h.runtime);
|
|
761
|
+
assert.equal(h.camera.fov, 70);
|
|
762
|
+
h.load('off');
|
|
763
|
+
assert.equal(h.camera.fov, own, 'and keyless again: the lens it had when the key met it');
|
|
764
|
+
checks += 1;
|
|
765
|
+
}
|
|
766
|
+
return checks;
|
|
767
|
+
}
|
|
768
|
+
|
|
604
769
|
function acrossLoads() {
|
|
605
770
|
let checks = 0;
|
|
606
771
|
for (const mode of ['off', 'rigid']) {
|
|
@@ -920,14 +1085,17 @@ function looking() {
|
|
|
920
1085
|
world.run(90);
|
|
921
1086
|
return world;
|
|
922
1087
|
};
|
|
923
|
-
// It starts
|
|
1088
|
+
// It starts behind the player 3.65 m from the point it looks at, 15
|
|
1089
|
+
// degrees down, nearer and lower than the fixed camera sits.
|
|
924
1090
|
{
|
|
925
1091
|
const world = settled();
|
|
926
1092
|
const t = world.actor.components.Transform;
|
|
927
1093
|
const a = world.scene.persistent.camAngle;
|
|
928
1094
|
const fixed = { x: t.x - PROPS.camDistance * Math.sin(a), y: t.y + PROPS.camHeight, z: t.z + PROPS.camDistance * Math.cos(a) };
|
|
929
|
-
assert.ok(world.off(fixed)
|
|
930
|
-
assert.ok(world.
|
|
1095
|
+
assert.ok(world.off(fixed) > 1, `not where the fixed camera sits (${world.off(fixed)} m off)`);
|
|
1096
|
+
assert.ok(world.camera.position.y < fixed.y, 'lower than it');
|
|
1097
|
+
assert.ok(world.off(world.rest(a, PITCH0, RANGE0)) < 1e-3, 'at 15 degrees, 3.65 m away');
|
|
1098
|
+
assert.ok(Math.abs(RANGE0 - 3.65) < 1e-12 && Math.abs(LOOK_HEIGHT - 0.438) < 1e-12, 'the numbers, in metres');
|
|
931
1099
|
// And looks at the player, LOOK_HEIGHT up.
|
|
932
1100
|
const look = new THREE.Vector3(0, 0, -1).applyQuaternion(world.camera.quaternion);
|
|
933
1101
|
const to = new THREE.Vector3(t.x - world.camera.position.x, t.y + LOOK_HEIGHT - world.camera.position.y, t.z - world.camera.position.z).normalize();
|
|
@@ -960,7 +1128,8 @@ function looking() {
|
|
|
960
1128
|
assert.ok(ahead.x < -0.05, `the view swung right (${ahead.x})`);
|
|
961
1129
|
checks += 1;
|
|
962
1130
|
}
|
|
963
|
-
// The tilt stays
|
|
1131
|
+
// The tilt stays within 80 degrees of the horizontal either way, the
|
|
1132
|
+
// distance between 1.5 and 37.376 m.
|
|
964
1133
|
{
|
|
965
1134
|
const world = settled();
|
|
966
1135
|
const drag = (dy) => {
|
|
@@ -971,56 +1140,86 @@ function looking() {
|
|
|
971
1140
|
world.run(90);
|
|
972
1141
|
};
|
|
973
1142
|
drag(2000);
|
|
974
|
-
assert.equal(world.scene.cameraOrbit.pitch,
|
|
975
|
-
assert.
|
|
1143
|
+
assert.equal(world.scene.cameraOrbit.pitch, PITCH_MOST, 'no steeper than 80 degrees');
|
|
1144
|
+
assert.equal(PITCH_MOST, 80 * DEG);
|
|
1145
|
+
assert.ok(world.off(world.rest(world.scene.persistent.camAngle, PITCH_MOST, RANGE0)) < 1e-4);
|
|
976
1146
|
drag(-4000);
|
|
977
|
-
assert.equal(world.scene.cameraOrbit.pitch,
|
|
978
|
-
assert.
|
|
1147
|
+
assert.equal(world.scene.cameraOrbit.pitch, PITCH_LEAST, 'no lower than 80 degrees below the horizontal');
|
|
1148
|
+
assert.equal(PITCH_LEAST, -80 * DEG);
|
|
1149
|
+
// Nothing is in the way here (no ground in this stand-in world): below
|
|
1150
|
+
// the point it looks at, looking up at it.
|
|
1151
|
+
assert.ok(world.off(world.rest(world.scene.persistent.camAngle, PITCH_LEAST, RANGE0)) < 1e-4);
|
|
1152
|
+
assert.ok(world.camera.position.y < world.actor.components.Transform.y + LOOK_HEIGHT - 3, 'below the point it looks at');
|
|
1153
|
+
const up = new THREE.Vector3(0, 0, -1).applyQuaternion(world.camera.quaternion);
|
|
1154
|
+
assert.ok(up.y > Math.sin(79 * DEG), `looking up at it (${up.y})`);
|
|
979
1155
|
for (let i = 0; i < 40; i += 1) world.gestures.wheel(-100, 0, i);
|
|
980
1156
|
world.run(90);
|
|
981
|
-
assert.equal(world.scene.cameraOrbit.range,
|
|
982
|
-
assert.
|
|
983
|
-
|
|
1157
|
+
assert.equal(world.scene.cameraOrbit.range, NEAREST, 'no nearer than 1.5 m');
|
|
1158
|
+
assert.equal(NEAREST, 1.5);
|
|
1159
|
+
assert.ok(world.off(world.rest(world.scene.persistent.camAngle, PITCH_LEAST, NEAREST)) < 1e-4);
|
|
1160
|
+
for (let i = 0; i < 60; i += 1) {
|
|
984
1161
|
world.gestures.wheel(100, 0, i);
|
|
985
1162
|
world.frame();
|
|
986
1163
|
}
|
|
987
1164
|
world.run(90);
|
|
988
|
-
assert.equal(world.scene.cameraOrbit.range,
|
|
989
|
-
assert.ok(
|
|
1165
|
+
assert.equal(world.scene.cameraOrbit.range, FARTHEST, 'no farther than 128 studs');
|
|
1166
|
+
assert.ok(Math.abs(FARTHEST - 37.376) < 1e-9);
|
|
1167
|
+
assert.ok(world.off(world.rest(world.scene.persistent.camAngle, PITCH_LEAST, FARTHEST)) < 1e-4);
|
|
990
1168
|
// One notch is a tenth.
|
|
991
1169
|
world.gestures.wheel(-100, 0, 0);
|
|
992
1170
|
world.frame();
|
|
993
|
-
assert.ok(Math.abs(world.scene.cameraOrbit.range -
|
|
1171
|
+
assert.ok(Math.abs(world.scene.cameraOrbit.range - FARTHEST / WHEEL_ZOOM_PER_NOTCH) < 1e-9, 'a notch of the wheel is a tenth nearer');
|
|
994
1172
|
// A pinch: fingers twice as far apart, half the distance.
|
|
995
1173
|
world.gestures.down(5, { x: 500, y: 300, time: 0, left: false });
|
|
996
1174
|
world.gestures.down(6, { x: 700, y: 300, time: 0, left: false });
|
|
997
1175
|
world.gestures.move(6, 900, 300, 1);
|
|
998
|
-
const from =
|
|
1176
|
+
const from = FARTHEST / WHEEL_ZOOM_PER_NOTCH;
|
|
999
1177
|
world.frame();
|
|
1000
1178
|
assert.ok(Math.abs(world.scene.cameraOrbit.range - from / 2) < 1e-9, 'fingers apart bring it nearer');
|
|
1001
1179
|
world.gestures.move(5, 880, 300, 2);
|
|
1002
1180
|
world.frame();
|
|
1003
|
-
assert.equal(world.scene.cameraOrbit.range,
|
|
1181
|
+
assert.equal(world.scene.cameraOrbit.range, FARTHEST, 'and a pinch stops at the limits too');
|
|
1004
1182
|
checks += 1;
|
|
1005
1183
|
}
|
|
1006
|
-
//
|
|
1007
|
-
// starts
|
|
1184
|
+
// camDistance and camHeight do not move the orbit camera: a Player with
|
|
1185
|
+
// any numbers starts at 3.65 m and 15 degrees, with the same limits; and a
|
|
1186
|
+
// Player with other numbers than the one before starts again from there
|
|
1187
|
+
// (a scene that changes them asks for its own camera).
|
|
1008
1188
|
{
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1189
|
+
assert.equal(PROPS.camDistance, 9);
|
|
1190
|
+
assert.equal(PROPS.camHeight, 7);
|
|
1191
|
+
for (const [camDistance, camHeight] of [[9, 7], [6, 4], [20, 30], [1, 1], [0, 20]]) {
|
|
1192
|
+
const world = makeWorld('orbit');
|
|
1193
|
+
world.actor.components.Player = { ...PROPS, camDistance, camHeight };
|
|
1194
|
+
world.run(90);
|
|
1195
|
+
const o = world.scene.cameraOrbit;
|
|
1196
|
+
assert.equal(o.pitch, PITCH0, `${camDistance}/${camHeight}: starts 15 degrees down`);
|
|
1197
|
+
assert.equal(o.range, RANGE0, `${camDistance}/${camHeight}: 3.65 m away`);
|
|
1198
|
+
assert.equal(o.nearest, NEAREST);
|
|
1199
|
+
assert.equal(o.farthest, FARTHEST);
|
|
1200
|
+
const t = world.actor.components.Transform;
|
|
1201
|
+
const at = world.camera.position;
|
|
1202
|
+
const dist = Math.hypot(at.x - t.x, at.y - (t.y + LOOK_HEIGHT), at.z - t.z);
|
|
1203
|
+
assert.ok(Math.abs(dist - RANGE0) < 1e-3, `${camDistance}/${camHeight}: the camera is ${dist} m from the look point, not ${RANGE0}`);
|
|
1204
|
+
const rise = Math.asin((at.y - (t.y + LOOK_HEIGHT)) / dist);
|
|
1205
|
+
assert.ok(Math.abs(rise - PITCH0) < 1e-3, `${camDistance}/${camHeight}: the camera sits ${rise / DEG} degrees up`);
|
|
1206
|
+
}
|
|
1207
|
+
const world = settled();
|
|
1208
|
+
world.gestures.wheel(-300, 0, 0);
|
|
1209
|
+
world.gestures.down(1, { x: 900, y: 300, time: 0, left: false });
|
|
1210
|
+
world.gestures.move(1, 900, 360, 5);
|
|
1211
|
+
world.run(10);
|
|
1212
|
+
assert.notEqual(world.scene.cameraOrbit.range, RANGE0);
|
|
1213
|
+
assert.notEqual(world.scene.cameraOrbit.pitch, PITCH0);
|
|
1214
|
+
world.run(10);
|
|
1215
|
+
const kept = { ...world.scene.cameraOrbit };
|
|
1216
|
+
world.actor.components.Player = { ...PROPS };
|
|
1018
1217
|
world.run(5);
|
|
1019
|
-
assert.
|
|
1020
|
-
|
|
1021
|
-
world.actor.components.Player = { ...PROPS, camDistance: 0, camHeight: 20 };
|
|
1218
|
+
assert.deepEqual(world.scene.cameraOrbit, kept, 'the same numbers keep what was chosen');
|
|
1219
|
+
world.actor.components.Player = { ...PROPS, camDistance: 6 };
|
|
1022
1220
|
world.run(5);
|
|
1023
|
-
assert.equal(world.scene.cameraOrbit.
|
|
1221
|
+
assert.equal(world.scene.cameraOrbit.range, RANGE0, 'other numbers start again');
|
|
1222
|
+
assert.equal(world.scene.cameraOrbit.pitch, PITCH0);
|
|
1024
1223
|
checks += 1;
|
|
1025
1224
|
}
|
|
1026
1225
|
// What the player chose is on the runtime and nowhere that is sent.
|
|
@@ -1042,6 +1241,109 @@ function looking() {
|
|
|
1042
1241
|
return checks;
|
|
1043
1242
|
}
|
|
1044
1243
|
|
|
1244
|
+
function startingValues() {
|
|
1245
|
+
let checks = 0;
|
|
1246
|
+
const cases = [
|
|
1247
|
+
[{}, RANGE0, PITCH0],
|
|
1248
|
+
[{ distance: 8, pitch: 30 }, 8, 30 * DEG],
|
|
1249
|
+
[{ distance: 0, pitch: -100 }, NEAREST, PITCH_LEAST],
|
|
1250
|
+
[{ distance: 100, pitch: 100 }, FARTHEST, PITCH_MOST],
|
|
1251
|
+
[{ distance: Number.MAX_VALUE, pitch: Number.MAX_VALUE }, FARTHEST, PITCH_MOST],
|
|
1252
|
+
[{ distance: 8 }, 8, PITCH0],
|
|
1253
|
+
[{ pitch: -30 }, RANGE0, -30 * DEG],
|
|
1254
|
+
...[NaN, Infinity, -Infinity, '8', null, {}, true].map((value) => [{ distance: value, pitch: value }, RANGE0, PITCH0]),
|
|
1255
|
+
];
|
|
1256
|
+
for (const [camera, range, pitch] of cases) {
|
|
1257
|
+
const world = makeWorld('orbit');
|
|
1258
|
+
world.scene.data = { engine: { camera } };
|
|
1259
|
+
world.frame();
|
|
1260
|
+
const chosen = world.scene.cameraOrbit;
|
|
1261
|
+
assert.equal(chosen.range, range, 'starting distance, clamped or default');
|
|
1262
|
+
assert.equal(chosen.pitch, pitch, 'starting pitch, clamped or default');
|
|
1263
|
+
assert.equal(chosen.nearest, NEAREST, 'starting keys do not change zoom limits');
|
|
1264
|
+
assert.equal(chosen.farthest, FARTHEST);
|
|
1265
|
+
world.run(90);
|
|
1266
|
+
assert.ok(world.off(world.rest(world.scene.persistent.camAngle, pitch, range)) < 1e-3, 'the camera uses the start with positive pitch looking down');
|
|
1267
|
+
world.gestures.wheel(-100, 0, 0);
|
|
1268
|
+
world.gestures.down(1, { x: 900, y: 300, time: 0, left: false });
|
|
1269
|
+
world.gestures.move(1, 900, pitch === PITCH_MOST ? 280 : 320, 5);
|
|
1270
|
+
world.frame();
|
|
1271
|
+
assert.notEqual(chosen.pitch, pitch, 'the player can tilt away from the start');
|
|
1272
|
+
const kept = { ...chosen };
|
|
1273
|
+
// A deep copy: an object-valued key is a fresh object, as a reload makes it.
|
|
1274
|
+
world.scene.data = { engine: { camera: structuredClone(camera) } };
|
|
1275
|
+
world.run(30, ['KeyW']);
|
|
1276
|
+
assert.equal(world.scene.cameraOrbit, chosen, 'unchanged values preserve the choice object, including NaN');
|
|
1277
|
+
assert.deepEqual(chosen, kept, 'no reset during play or when equal scene data replaces the object');
|
|
1278
|
+
checks += 1;
|
|
1279
|
+
}
|
|
1280
|
+
{
|
|
1281
|
+
const world = makeWorld('orbit');
|
|
1282
|
+
const camera = { distance: 8, pitch: 30 };
|
|
1283
|
+
world.scene.data = { engine: { camera } };
|
|
1284
|
+
world.run(90);
|
|
1285
|
+
const reset = (change, range, pitch, label) => {
|
|
1286
|
+
world.scene.cameraOrbit.range = 10;
|
|
1287
|
+
world.scene.cameraOrbit.pitch = 0;
|
|
1288
|
+
const before = world.scene.cameraOrbit;
|
|
1289
|
+
change();
|
|
1290
|
+
world.frame();
|
|
1291
|
+
assert.notEqual(world.scene.cameraOrbit, before, label);
|
|
1292
|
+
assert.equal(world.scene.cameraOrbit.range, range, label);
|
|
1293
|
+
assert.equal(world.scene.cameraOrbit.pitch, pitch, label);
|
|
1294
|
+
checks += 1;
|
|
1295
|
+
};
|
|
1296
|
+
reset(() => (camera.distance = 6), 6, 30 * DEG, 'distance edit resets both starts');
|
|
1297
|
+
reset(() => (camera.pitch = -20), 6, -20 * DEG, 'pitch edit resets both starts');
|
|
1298
|
+
reset(() => (world.actor.components.Player = { ...PROPS, camDistance: 6 }), 6, -20 * DEG, 'camDistance still reapplies authored starts');
|
|
1299
|
+
reset(() => (world.actor.components.Player = { ...PROPS, camDistance: 6, camHeight: 4 }), 6, -20 * DEG, 'camHeight still reapplies authored starts');
|
|
1300
|
+
reset(() => (world.scene.data = { engine: { camera: { distance: 12, pitch: 40 } } }), 12, 40 * DEG, 'different scene values reset');
|
|
1301
|
+
reset(() => (world.scene.data = {}), RANGE0, PITCH0, 'removing keys restores defaults');
|
|
1302
|
+
}
|
|
1303
|
+
// The optional floor limits both the start and every upward drag.
|
|
1304
|
+
for (const [camera, floor, start] of [
|
|
1305
|
+
[{}, PITCH_LEAST, PITCH0],
|
|
1306
|
+
[{ minPitch: 0, pitch: -30 }, 0, 0],
|
|
1307
|
+
[{ minPitch: -100 }, PITCH_LEAST, PITCH0],
|
|
1308
|
+
[{ minPitch: 100 }, PITCH_MOST, PITCH_MOST],
|
|
1309
|
+
...[NaN, Infinity, -Infinity, '0', null, {}, true].map((minPitch) => [{ minPitch }, PITCH_LEAST, PITCH0]),
|
|
1310
|
+
]) {
|
|
1311
|
+
const world = makeWorld('orbit');
|
|
1312
|
+
world.scene.data = { engine: { camera } };
|
|
1313
|
+
world.frame();
|
|
1314
|
+
assert.equal(world.scene.cameraOrbit.least, floor, 'finite floor is clamped; absent or invalid keeps -80');
|
|
1315
|
+
assert.equal(world.scene.cameraOrbit.pitch, start, 'the start is raised to the floor');
|
|
1316
|
+
world.gestures.down(1, { x: 900, y: 400, time: 0, left: false });
|
|
1317
|
+
world.gestures.move(1, 900, 380, 1);
|
|
1318
|
+
world.gestures.move(1, 900, -3600, 2);
|
|
1319
|
+
world.gestures.up(1, 500, false);
|
|
1320
|
+
world.frame();
|
|
1321
|
+
assert.equal(world.scene.cameraOrbit.pitch, floor, 'a large upward drag stops at the floor');
|
|
1322
|
+
const chosen = world.scene.cameraOrbit;
|
|
1323
|
+
world.scene.data = { engine: { camera: structuredClone(camera) } };
|
|
1324
|
+
world.frame();
|
|
1325
|
+
assert.equal(world.scene.cameraOrbit, chosen, 'unchanged floor keeps the player choice');
|
|
1326
|
+
checks += 1;
|
|
1327
|
+
}
|
|
1328
|
+
{
|
|
1329
|
+
const world = makeWorld('orbit');
|
|
1330
|
+
const camera = { pitch: -30 };
|
|
1331
|
+
world.scene.data = { engine: { camera } };
|
|
1332
|
+
world.frame();
|
|
1333
|
+
const before = world.scene.cameraOrbit;
|
|
1334
|
+
camera.minPitch = 0;
|
|
1335
|
+
world.frame();
|
|
1336
|
+
assert.notEqual(world.scene.cameraOrbit, before, 'a floor edit reapplies the start');
|
|
1337
|
+
assert.equal(world.scene.cameraOrbit.pitch, 0, 'the new floor raises the authored start');
|
|
1338
|
+
delete camera.minPitch;
|
|
1339
|
+
world.frame();
|
|
1340
|
+
assert.equal(world.scene.cameraOrbit.least, PITCH_LEAST, 'removing the floor restores -80');
|
|
1341
|
+
assert.equal(world.scene.cameraOrbit.pitch, -30 * DEG, 'removing the floor reapplies the authored start');
|
|
1342
|
+
checks += 1;
|
|
1343
|
+
}
|
|
1344
|
+
return checks;
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1045
1347
|
function blocked() {
|
|
1046
1348
|
let checks = 0;
|
|
1047
1349
|
const world = makeWorld('orbit');
|
|
@@ -1051,39 +1353,39 @@ function blocked() {
|
|
|
1051
1353
|
const t = world.actor.components.Transform;
|
|
1052
1354
|
return Math.hypot(world.camera.position.x - t.x, world.camera.position.y - (t.y + LOOK_HEIGHT), world.camera.position.z - t.z);
|
|
1053
1355
|
};
|
|
1054
|
-
// While the first frame's takeover blend lasts its drawn point is
|
|
1055
|
-
// too; settled,
|
|
1056
|
-
|
|
1356
|
+
// While the first frame's takeover blend lasts its drawn point is swept
|
|
1357
|
+
// toward too; settled, two queries a frame: whether anything is near the
|
|
1358
|
+
// look point (nothing here) and one sweep toward where the camera wants
|
|
1359
|
+
// to be.
|
|
1360
|
+
assert.ok(world.casts > 2 * 90, 'a second sweep while a blend lasts');
|
|
1057
1361
|
world.casts = 0;
|
|
1058
1362
|
world.run(30);
|
|
1059
|
-
assert.equal(world.casts, 30, '
|
|
1060
|
-
// The
|
|
1363
|
+
assert.equal(world.casts, 2 * 30, 'two queries a frame');
|
|
1364
|
+
// The ball goes from the point the camera is placed from (the player's
|
|
1061
1365
|
// eased height, LOOK_HEIGHT up) toward where the camera wants to be, as
|
|
1062
|
-
// far as it wants to be
|
|
1366
|
+
// far as it wants to be, the margin round.
|
|
1063
1367
|
const t = world.actor.components.Transform;
|
|
1064
1368
|
const eye = { x: world.camera.position.x - world.lastCast.dir.x * RANGE0, y: world.camera.position.y - world.lastCast.dir.y * RANGE0, z: world.camera.position.z - world.lastCast.dir.z * RANGE0 };
|
|
1065
1369
|
for (const k of ['x', 'y', 'z']) assert.ok(Math.abs(world.lastCast.from[k] - eye[k]) < 1e-4, `the ray starts where the camera is placed from (${k})`);
|
|
1066
1370
|
assert.ok(Math.abs(world.lastCast.from.y - (t.y + LOOK_HEIGHT)) < 1e-3);
|
|
1067
|
-
assert.ok(Math.abs(world.lastCast.max -
|
|
1371
|
+
assert.ok(Math.abs(world.lastCast.max - RANGE0) < 1e-6);
|
|
1372
|
+
assert.equal(world.lastCast.radius, 0.25, 'a ball the margin round');
|
|
1068
1373
|
const want = world.rest(a, PITCH0, 1);
|
|
1069
1374
|
for (const k of ['x', 'y', 'z']) assert.ok(Math.abs(world.lastCast.dir[k] - (want[k] - world.lastCast.from[k])) < 1e-6, `ray ${k}`);
|
|
1070
1375
|
assert.ok(Math.abs(Math.hypot(world.lastCast.dir.x, world.lastCast.dir.y, world.lastCast.dir.z) - 1) < 1e-12, 'a unit direction');
|
|
1071
1376
|
checks += 1;
|
|
1072
1377
|
// Something in the way: in front of it at once, a margin clear.
|
|
1073
|
-
world.wall =
|
|
1378
|
+
world.wall = 3;
|
|
1074
1379
|
world.frame();
|
|
1075
|
-
assert.ok(Math.abs(reach() -
|
|
1076
|
-
assert.ok(world.off(world.rest(a, PITCH0,
|
|
1380
|
+
assert.ok(Math.abs(reach() - 2.75) < 1e-5, `pulled in at once, 0.25 m clear (${reach()})`);
|
|
1381
|
+
assert.ok(world.off(world.rest(a, PITCH0, 2.75)) < 1e-5, 'along the same line');
|
|
1077
1382
|
world.wall = 2;
|
|
1078
1383
|
world.frame();
|
|
1079
1384
|
assert.ok(Math.abs(reach() - 1.75) < 1e-5, 'and in again at once');
|
|
1080
|
-
//
|
|
1385
|
+
// However near, the margin off it.
|
|
1081
1386
|
world.wall = 0.3;
|
|
1082
1387
|
world.frame();
|
|
1083
|
-
assert.ok(Math.abs(reach() - 0.
|
|
1084
|
-
world.wall = 0;
|
|
1085
|
-
world.frame();
|
|
1086
|
-
assert.ok(Math.abs(reach() - 0.6) < 1e-5);
|
|
1388
|
+
assert.ok(Math.abs(reach() - 0.05) < 1e-5, `the margin off a near wall (${reach()})`);
|
|
1087
1389
|
checks += 1;
|
|
1088
1390
|
// Out of the way: back out slowly, never past where it wants to be.
|
|
1089
1391
|
world.wall = null;
|
|
@@ -1098,14 +1400,15 @@ function blocked() {
|
|
|
1098
1400
|
assert.ok(Math.abs(reach() - RANGE0) < 1e-3, 'all the way');
|
|
1099
1401
|
checks += 1;
|
|
1100
1402
|
// Half way out, something nearer again: in at once.
|
|
1101
|
-
world.wall =
|
|
1403
|
+
world.wall = 2;
|
|
1102
1404
|
world.frame();
|
|
1103
1405
|
world.wall = null;
|
|
1104
1406
|
world.run(10);
|
|
1105
1407
|
const half = reach();
|
|
1106
|
-
|
|
1408
|
+
assert.ok(half > 2 && half < RANGE0 - 0.3, `half way out (${half})`);
|
|
1409
|
+
world.wall = half + 0.5;
|
|
1107
1410
|
world.frame();
|
|
1108
|
-
assert.ok(reach() > half && reach() <= half +
|
|
1411
|
+
assert.ok(reach() > half && reach() <= half + 0.5 - 0.25 + 1e-9, 'still easing out behind a farther wall, inside it');
|
|
1109
1412
|
world.wall = 1.5;
|
|
1110
1413
|
world.frame();
|
|
1111
1414
|
assert.ok(Math.abs(reach() - 1.25) < 1e-5);
|
|
@@ -1117,7 +1420,7 @@ function blocked() {
|
|
|
1117
1420
|
{
|
|
1118
1421
|
const held = makeWorld('orbit');
|
|
1119
1422
|
held.run(90);
|
|
1120
|
-
held.wall =
|
|
1423
|
+
held.wall = 3;
|
|
1121
1424
|
held.frame();
|
|
1122
1425
|
const at = () => {
|
|
1123
1426
|
const tt = held.actor.components.Transform;
|
|
@@ -1127,24 +1430,24 @@ function blocked() {
|
|
|
1127
1430
|
// behind the player, where the camera belongs.
|
|
1128
1431
|
return (c.x - held.lastCast.from.x) * d.x + (c.y - held.lastCast.from.y) * d.y + (c.z - held.lastCast.from.z) * d.z + 0 * tt.x;
|
|
1129
1432
|
};
|
|
1130
|
-
assert.ok(Math.abs(at() -
|
|
1433
|
+
assert.ok(Math.abs(at() - 2.75) < 1e-5);
|
|
1131
1434
|
let last = at();
|
|
1132
1435
|
for (let i = 0; i < 90; i += 1) {
|
|
1133
1436
|
if (i < 20) held.gestures.wheel(-100, 0);
|
|
1134
1437
|
held.frame();
|
|
1135
1438
|
const now = at();
|
|
1136
1439
|
assert.ok(now > 0, `frame ${i}: the camera is not through the player (${now})`);
|
|
1137
|
-
assert.ok(now <=
|
|
1440
|
+
assert.ok(now <= 2.75 + 1e-5, `frame ${i}: nor past the wall (${now})`);
|
|
1138
1441
|
assert.ok(now <= last + 1e-5, `frame ${i}: and only comes nearer (${now} after ${last})`);
|
|
1139
1442
|
assert.ok(now >= Math.min(0.6, held.scene.cameraOrbit.range) - 1e-9, `frame ${i}: no nearer than 0.6 m`);
|
|
1140
1443
|
last = now;
|
|
1141
1444
|
}
|
|
1142
|
-
assert.equal(held.scene.cameraOrbit.range,
|
|
1143
|
-
assert.ok(Math.abs(at() -
|
|
1445
|
+
assert.equal(held.scene.cameraOrbit.range, NEAREST, 'zoomed all the way in');
|
|
1446
|
+
assert.ok(Math.abs(at() - NEAREST) < 1e-3, `at the distance asked, nearer than the wall (${at()})`);
|
|
1144
1447
|
// Back out with the wall still there: no farther than in front of it.
|
|
1145
1448
|
for (let i = 0; i < 20; i += 1) held.gestures.wheel(100, 0);
|
|
1146
1449
|
held.run(90);
|
|
1147
|
-
assert.ok(Math.abs(at() -
|
|
1450
|
+
assert.ok(Math.abs(at() - 2.75) < 1e-5, `held in front of the wall again (${at()})`);
|
|
1148
1451
|
checks += 1;
|
|
1149
1452
|
}
|
|
1150
1453
|
// With nothing in the way, zooming in and out is at the zoom's own pace,
|
|
@@ -1156,13 +1459,16 @@ function blocked() {
|
|
|
1156
1459
|
free.run(30);
|
|
1157
1460
|
const tt = free.actor.components.Transform;
|
|
1158
1461
|
const dist = () => Math.hypot(free.camera.position.x - tt.x, free.camera.position.y - (tt.y + LOOK_HEIGHT), free.camera.position.z - tt.z);
|
|
1159
|
-
assert.ok(Math.abs(dist() -
|
|
1462
|
+
assert.ok(Math.abs(dist() - NEAREST) < 1e-2, `zooming in (${dist()})`);
|
|
1463
|
+
// Out in two frames' asking (a frame takes no more than 16 times).
|
|
1464
|
+
for (let i = 0; i < 40; i += 1) free.gestures.wheel(100, 0);
|
|
1465
|
+
free.frame();
|
|
1160
1466
|
for (let i = 0; i < 40; i += 1) free.gestures.wheel(100, 0);
|
|
1161
1467
|
free.run(30);
|
|
1162
|
-
assert.ok(Math.abs(dist() -
|
|
1468
|
+
assert.ok(Math.abs(dist() - FARTHEST) < 5e-2, `and out (${dist()})`);
|
|
1163
1469
|
checks += 1;
|
|
1164
1470
|
}
|
|
1165
|
-
// No physics world: no
|
|
1471
|
+
// No physics world: no query, and the camera is placed all the same.
|
|
1166
1472
|
{
|
|
1167
1473
|
const unready = makeWorld('orbit');
|
|
1168
1474
|
unready.ready = false;
|
|
@@ -1171,21 +1477,158 @@ function blocked() {
|
|
|
1171
1477
|
t0.x += 0.05;
|
|
1172
1478
|
unready.frame();
|
|
1173
1479
|
}
|
|
1174
|
-
assert.equal(unready.casts, 0, 'no
|
|
1480
|
+
assert.equal(unready.casts, 0, 'no query without a world');
|
|
1175
1481
|
assert.ok(unready.off(unready.rest(Math.PI / 4, PITCH0, RANGE0)) < 1e-2, 'placed before physics is ready');
|
|
1176
1482
|
checks += 1;
|
|
1177
1483
|
}
|
|
1178
|
-
// An api without
|
|
1179
|
-
|
|
1484
|
+
// An api without the lens's queries (an older physics system): no
|
|
1485
|
+
// collision.
|
|
1486
|
+
for (const missing of ['castBallFixed', 'nearFixed', 'castRayFixedNormal']) {
|
|
1180
1487
|
const old = makeWorld('orbit');
|
|
1181
|
-
|
|
1488
|
+
old.wall = 2;
|
|
1489
|
+
delete old.scene.physics3d[missing];
|
|
1182
1490
|
old.run(90);
|
|
1183
|
-
assert.ok(old.off(old.rest(Math.PI / 4, PITCH0, RANGE0)) < 1e-3);
|
|
1491
|
+
assert.ok(old.off(old.rest(Math.PI / 4, PITCH0, RANGE0)) < 1e-3, `without ${missing}`);
|
|
1184
1492
|
checks += 1;
|
|
1185
1493
|
}
|
|
1186
1494
|
return checks;
|
|
1187
1495
|
}
|
|
1188
1496
|
|
|
1497
|
+
// Below the horizontal the ground holds the camera above itself as a wall
|
|
1498
|
+
// holds it in front. On flat ground (a fixed solid whose top is at y = 0, as
|
|
1499
|
+
// the kit's ground is), at every tilt from 80 degrees up to 80 down and at
|
|
1500
|
+
// every zoom, walking and jumping, the camera and the whole of its near plane
|
|
1501
|
+
// (a 70 degree lens on a 20:9 screen) stay above the ground; held by it, the
|
|
1502
|
+
// camera is 0.25 m off it, square to it. The queries are the ground's: a
|
|
1503
|
+
// stand-in plane, or rapier's own (`fixedRay`).
|
|
1504
|
+
const GROUND = [{ n: { x: 0, y: 1, z: 0 }, d: 0 }];
|
|
1505
|
+
function grounded(api = null) {
|
|
1506
|
+
const world = makeWorld('orbit');
|
|
1507
|
+
const camera = world.camera;
|
|
1508
|
+
camera.fov = 70;
|
|
1509
|
+
camera.aspect = 20 / 9;
|
|
1510
|
+
camera.updateProjectionMatrix();
|
|
1511
|
+
if (api) queriesOf(world, api);
|
|
1512
|
+
else halfSpaces(world, GROUND);
|
|
1513
|
+
const corner = new THREE.Vector3();
|
|
1514
|
+
let lowest = Infinity;
|
|
1515
|
+
let frames = 0;
|
|
1516
|
+
const check = () => {
|
|
1517
|
+
camera.updateMatrixWorld();
|
|
1518
|
+
for (const [x, y] of [[-1, -1], [1, -1], [1, 1], [-1, 1], [0, 0]]) {
|
|
1519
|
+
corner.set(x, y, -1).unproject(camera);
|
|
1520
|
+
lowest = Math.min(lowest, corner.y);
|
|
1521
|
+
assert.ok(corner.y > 0, `frame ${frames}: the near plane is above the ground (${corner.y} at ${world.scene.cameraOrbit.pitch / DEG} degrees, ${world.scene.cameraOrbit.range} m)`);
|
|
1522
|
+
}
|
|
1523
|
+
frames += 1;
|
|
1524
|
+
};
|
|
1525
|
+
world.run(90);
|
|
1526
|
+
let pointer = 10;
|
|
1527
|
+
for (const zoom of [FARTHEST, 20, 8, RANGE0, NEAREST]) {
|
|
1528
|
+
world.scene.cameraOrbit.range = zoom;
|
|
1529
|
+
// Up to the top, then down to the bottom in steps of 2.5 degrees, a
|
|
1530
|
+
// drag a frame, walking and jumping.
|
|
1531
|
+
for (const [dy, steps] of [[1, 80], [-1, 80]]) {
|
|
1532
|
+
pointer += 1;
|
|
1533
|
+
world.gestures.down(pointer, { x: 900, y: 400, time: 0, left: false });
|
|
1534
|
+
let y = 400;
|
|
1535
|
+
for (let i = 0; i < steps; i += 1) {
|
|
1536
|
+
y += dy * ((2.5 * DEG) / LOOK_RAD_PER_PX);
|
|
1537
|
+
world.gestures.move(pointer, 900, y, i + 1);
|
|
1538
|
+
world.frame(UNEVEN(i), i % 40 < 20 ? ['KeyW'] : i % 40 === 25 ? ['Space'] : []);
|
|
1539
|
+
check();
|
|
1540
|
+
}
|
|
1541
|
+
world.gestures.up(pointer, 9999, false);
|
|
1542
|
+
world.run(90);
|
|
1543
|
+
check();
|
|
1544
|
+
}
|
|
1545
|
+
assert.equal(world.scene.cameraOrbit.pitch, PITCH_LEAST);
|
|
1546
|
+
// Settled at the bottom: held by the ground, 0.25 m off it.
|
|
1547
|
+
if (zoom >= RANGE0) assert.ok(Math.abs(camera.position.y - 0.25) < 1e-3, `held 0.25 m off the ground (${camera.position.y})`);
|
|
1548
|
+
}
|
|
1549
|
+
// Not held when the ground is not in the way: at the start, the camera
|
|
1550
|
+
// is where it rests.
|
|
1551
|
+
const fresh = makeWorld('orbit');
|
|
1552
|
+
if (api) queriesOf(fresh, api);
|
|
1553
|
+
else halfSpaces(fresh, GROUND);
|
|
1554
|
+
fresh.run(90);
|
|
1555
|
+
assert.ok(fresh.off(fresh.rest(fresh.scene.persistent.camAngle, PITCH0, RANGE0)) < 1e-3, 'the ground does not hold a camera above it');
|
|
1556
|
+
assert.ok(lowest > 0 && frames > 800);
|
|
1557
|
+
return 1;
|
|
1558
|
+
}
|
|
1559
|
+
|
|
1560
|
+
// A wide lens needs a wider stand-off (review 1, finding 5). A wall square
|
|
1561
|
+
// to the x axis 0.8 m from the player, a 120 degree lens: the whole near
|
|
1562
|
+
// plane stays in front of the wall on a 20:9 screen and on a 9:20 one, at
|
|
1563
|
+
// the start's tilt and the reported yaw, and across tilts, yaws and zooms.
|
|
1564
|
+
// The stand-off at 70 degrees on 20:9 is the 0.25 m it was.
|
|
1565
|
+
function wideLens() {
|
|
1566
|
+
let checks = 0;
|
|
1567
|
+
const WALL = 0.8;
|
|
1568
|
+
const corner = new THREE.Vector3();
|
|
1569
|
+
const nearestCorner = (camera) => {
|
|
1570
|
+
camera.updateMatrixWorld();
|
|
1571
|
+
let most = -Infinity;
|
|
1572
|
+
for (const [x, y] of [[-1, -1], [1, -1], [1, 1], [-1, 1]]) {
|
|
1573
|
+
corner.set(x, y, -1).unproject(camera);
|
|
1574
|
+
most = Math.max(most, corner.x);
|
|
1575
|
+
}
|
|
1576
|
+
return most;
|
|
1577
|
+
};
|
|
1578
|
+
const lensWorld = (fov, aspect, wall = WALL) => {
|
|
1579
|
+
const world = makeWorld('orbit');
|
|
1580
|
+
world.scene.data = { engine: { camera: { follow: 'rigid', control: 'orbit', fov } } };
|
|
1581
|
+
// As orbitlens.js `fitOrbitLens` sets it at the draw.
|
|
1582
|
+
world.camera.fov = fov;
|
|
1583
|
+
world.camera.aspect = aspect;
|
|
1584
|
+
world.camera.updateProjectionMatrix();
|
|
1585
|
+
return halfSpaces(world, [{ n: { x: -1, y: 0, z: 0 }, d: -wall, actorId: 'wall' }]);
|
|
1586
|
+
};
|
|
1587
|
+
// The report: 120 degrees, 20:9, the start's 15 degree tilt, yaw -20.
|
|
1588
|
+
for (const aspect of [20 / 9, 9 / 20]) {
|
|
1589
|
+
const world = lensWorld(120, aspect);
|
|
1590
|
+
world.scene.persistent.camAngle = -20 * DEG;
|
|
1591
|
+
world.run(120);
|
|
1592
|
+
assert.ok(Math.abs(world.scene.cameraOrbit.pitch - PITCH0) < 1e-12);
|
|
1593
|
+
const x = world.camera.position.x;
|
|
1594
|
+
const reach = nearestCorner(world.camera);
|
|
1595
|
+
assert.ok(reach < WALL, `aspect ${aspect.toFixed(3)}: the near plane stays in front of the wall (a corner at x = ${reach.toFixed(3)}, the camera at ${x.toFixed(3)})`);
|
|
1596
|
+
const half = Math.tan(60 * DEG);
|
|
1597
|
+
const margin = 0.1 * Math.sqrt(1 + half * half + (aspect * half) ** 2) + 0.05;
|
|
1598
|
+
assert.ok(Math.abs(WALL - x - margin) < 1e-3, `held its lens's stand-off off the wall, square to it (${(WALL - x).toFixed(4)} m, want ${margin.toFixed(4)})`);
|
|
1599
|
+
checks += 2;
|
|
1600
|
+
}
|
|
1601
|
+
// Every tilt, yaw and zoom toward the wall, at 120 degrees both ways round
|
|
1602
|
+
// and at 90 degrees on 20:9.
|
|
1603
|
+
for (const [fov, aspect] of [[120, 20 / 9], [120, 9 / 20], [90, 20 / 9]]) {
|
|
1604
|
+
const world = lensWorld(fov, aspect);
|
|
1605
|
+
world.run(30);
|
|
1606
|
+
for (const range of [NEAREST, RANGE0, 12]) {
|
|
1607
|
+
for (let pitch = -60; pitch <= 80; pitch += 20) {
|
|
1608
|
+
for (let yaw = -80; yaw <= 0; yaw += 20) {
|
|
1609
|
+
world.scene.persistent.camAngle = yaw * DEG;
|
|
1610
|
+
world.scene.cameraOrbit.pitch = pitch * DEG;
|
|
1611
|
+
world.scene.cameraOrbit.range = range;
|
|
1612
|
+
world.run(60);
|
|
1613
|
+
const reach = nearestCorner(world.camera);
|
|
1614
|
+
assert.ok(reach < WALL, `${fov} degrees, aspect ${aspect.toFixed(3)}, tilt ${pitch}, yaw ${yaw}, ${range} m: a corner at x = ${reach.toFixed(3)}`);
|
|
1615
|
+
checks += 1;
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
}
|
|
1620
|
+
// The default lens: 0.25 m, as before.
|
|
1621
|
+
const world = lensWorld(70, 20 / 9, 2);
|
|
1622
|
+
world.scene.data = {};
|
|
1623
|
+
world.scene.persistent.camAngle = -90 * DEG;
|
|
1624
|
+
world.scene.cameraOrbit = null;
|
|
1625
|
+
world.run(120);
|
|
1626
|
+
world.scene.cameraOrbit.pitch = 0;
|
|
1627
|
+
world.run(120);
|
|
1628
|
+
assert.ok(Math.abs(2 - world.camera.position.x - 0.25) < 1e-6, `0.25 m off the wall at 70 degrees (${2 - world.camera.position.x})`);
|
|
1629
|
+
return checks + 1;
|
|
1630
|
+
}
|
|
1631
|
+
|
|
1189
1632
|
// Without the key the character always faces PI - camAngle, so code that
|
|
1190
1633
|
// turns it sets camAngle. Under the key turning the character is asked for
|
|
1191
1634
|
// (`scene.faceRequest`, as the hub asks beside its camAngle write); a
|
|
@@ -1808,6 +2251,650 @@ function listeners() {
|
|
|
1808
2251
|
return checks;
|
|
1809
2252
|
}
|
|
1810
2253
|
|
|
2254
|
+
// Desktop mouse capture under the key: a stand-in document and window
|
|
2255
|
+
// (pointerLockElement, exitPointerLock, the lock's events, blur and
|
|
2256
|
+
// visibilitychange) behind a stand-in canvas that can ask for the lock.
|
|
2257
|
+
// `mode` is how requestPointerLock answers: 'promise' (a promise settled
|
|
2258
|
+
// by `grant`/`deny`), 'none' (returns nothing, as old Safari: the events
|
|
2259
|
+
// only), 'throw', or 'missing' (no requestPointerLock at all).
|
|
2260
|
+
// `exit` is how exitPointerLock ends the lock: 'webkit' clears
|
|
2261
|
+
// pointerLockElement and sends pointerlockchange later (`flush`);
|
|
2262
|
+
// 'chromium' clears it inside the call and sends the event later.
|
|
2263
|
+
function makeLockDom(mode = 'promise', canvas = makeCanvas(), exit = 'webkit') {
|
|
2264
|
+
const doc = makeCanvas();
|
|
2265
|
+
const win = makeCanvas();
|
|
2266
|
+
doc.defaultView = win;
|
|
2267
|
+
doc.pointerLockElement = null;
|
|
2268
|
+
doc.visibilityState = 'visible';
|
|
2269
|
+
doc.exits = 0;
|
|
2270
|
+
doc.exitPointerLock = () => {
|
|
2271
|
+
doc.exits += 1;
|
|
2272
|
+
if (exit === 'chromium') {
|
|
2273
|
+
if (doc.pointerLockElement === null) return;
|
|
2274
|
+
doc.pointerLockElement = null;
|
|
2275
|
+
dom.later.push(() => doc.fire('pointerlockchange'));
|
|
2276
|
+
return;
|
|
2277
|
+
}
|
|
2278
|
+
// The browser exits after the call returns.
|
|
2279
|
+
dom.later.push(() => {
|
|
2280
|
+
if (doc.pointerLockElement === null) return;
|
|
2281
|
+
doc.pointerLockElement = null;
|
|
2282
|
+
doc.fire('pointerlockchange');
|
|
2283
|
+
});
|
|
2284
|
+
};
|
|
2285
|
+
canvas.ownerDocument = doc;
|
|
2286
|
+
canvas.requests = 0;
|
|
2287
|
+
// Which pointers are captured now: a lock that lands takes every capture
|
|
2288
|
+
// away (the Pointer Events spec's implicit release), and a capture cannot
|
|
2289
|
+
// be taken while the lock is on.
|
|
2290
|
+
canvas.holding = new Set();
|
|
2291
|
+
// Pointers that came up beyond the canvas: no longer active.
|
|
2292
|
+
canvas.gone = new Set();
|
|
2293
|
+
canvas.hasPointerCapture = (id) => canvas.holding.has(id);
|
|
2294
|
+
canvas.setPointerCapture = (id) => {
|
|
2295
|
+
if (canvas.gone.has(id)) throw Object.assign(new Error('not active'), { name: 'NotFoundError' });
|
|
2296
|
+
if (doc.pointerLockElement === canvas) throw Object.assign(new Error('locked'), { name: 'InvalidStateError' });
|
|
2297
|
+
canvas.captured.push(id);
|
|
2298
|
+
canvas.holding.add(id);
|
|
2299
|
+
};
|
|
2300
|
+
const dom = { canvas, doc, win, later: [], waiting: [] };
|
|
2301
|
+
if (mode !== 'missing') {
|
|
2302
|
+
canvas.requestPointerLock = () => {
|
|
2303
|
+
canvas.requests += 1;
|
|
2304
|
+
if (mode === 'throw') throw new Error('no lock here');
|
|
2305
|
+
let settle;
|
|
2306
|
+
const promise = new Promise((resolve, reject) => (settle = { resolve, reject }));
|
|
2307
|
+
dom.waiting.push(settle);
|
|
2308
|
+
return mode === 'promise' ? promise : undefined;
|
|
2309
|
+
};
|
|
2310
|
+
}
|
|
2311
|
+
// The lock lands (pointerlockchange, then the promise).
|
|
2312
|
+
dom.grant = async () => {
|
|
2313
|
+
const settle = dom.waiting.shift();
|
|
2314
|
+
doc.pointerLockElement = canvas;
|
|
2315
|
+
canvas.holding.clear();
|
|
2316
|
+
doc.fire('pointerlockchange');
|
|
2317
|
+
settle.resolve();
|
|
2318
|
+
await tick();
|
|
2319
|
+
};
|
|
2320
|
+
// Refused: pointerlockerror and a rejection (a SecurityError in Chrome).
|
|
2321
|
+
dom.deny = async () => {
|
|
2322
|
+
const settle = dom.waiting.shift();
|
|
2323
|
+
doc.fire('pointerlockerror');
|
|
2324
|
+
settle.reject(Object.assign(new Error('refused'), { name: 'SecurityError' }));
|
|
2325
|
+
await tick();
|
|
2326
|
+
};
|
|
2327
|
+
// The browser ends the lock itself (Escape, the host taking focus).
|
|
2328
|
+
dom.escape = () => {
|
|
2329
|
+
doc.pointerLockElement = null;
|
|
2330
|
+
doc.fire('pointerlockchange');
|
|
2331
|
+
};
|
|
2332
|
+
dom.flush = () => {
|
|
2333
|
+
for (const fn of dom.later.splice(0)) fn();
|
|
2334
|
+
};
|
|
2335
|
+
dom.locked = () => doc.pointerLockElement === canvas;
|
|
2336
|
+
// This trace covers mouse-lock ownership. Keyboard/touch modality observers
|
|
2337
|
+
// live for the keyed scene and have their own lifecycle checks in shift-lock.
|
|
2338
|
+
dom.watched = () => [...doc.types(), ...win.types().filter((t) => !['keydown', 'pointerdown'].includes(t)).map((t) => `window:${t}`)];
|
|
2339
|
+
return dom;
|
|
2340
|
+
}
|
|
2341
|
+
const tick = () => new Promise((resolve) => setTimeout(resolve, 0));
|
|
2342
|
+
|
|
2343
|
+
async function mouseLock() {
|
|
2344
|
+
let checks = 0;
|
|
2345
|
+
const make = (mode) => {
|
|
2346
|
+
const dom = makeLockDom(mode);
|
|
2347
|
+
const runtime = { cameraControl: 'orbit', taps: 0 };
|
|
2348
|
+
const stick = { x: 0, y: 0, active: false };
|
|
2349
|
+
const orbit = attachOrbitInput(dom.canvas, runtime, stick, () => (runtime.taps += 1), TUNING);
|
|
2350
|
+
runtime.lookInput.listen();
|
|
2351
|
+
const ev = (id, x, y, more = {}) => ({ pointerId: id, clientX: x, clientY: y, pointerType: 'mouse', button: -1, buttons: 1, ...more });
|
|
2352
|
+
const take = () => ({ ...runtime.lookInput.consume() });
|
|
2353
|
+
return { ...dom, dom, runtime, stick, orbit, ev, take };
|
|
2354
|
+
};
|
|
2355
|
+
const near = (a, b) => Math.abs(a - b) < 1e-12;
|
|
2356
|
+
|
|
2357
|
+
// A left drag: no lock at the press or inside the slop; once past it the
|
|
2358
|
+
// lock is asked for, once. Locked, the turn is movementX/Y (the client
|
|
2359
|
+
// position stands still); the pointerup lets go of it and the listeners.
|
|
2360
|
+
{
|
|
2361
|
+
const h = make('promise');
|
|
2362
|
+
h.orbit.down(h.ev(1, 700, 300, { button: 0 }));
|
|
2363
|
+
assert.equal(h.canvas.requests, 0, 'a left press does not ask');
|
|
2364
|
+
assert.deepEqual(h.watched().sort(), ['visibilitychange', 'window:blur'], 'it listens for a blur or the page hidden only, while the button is down');
|
|
2365
|
+
h.orbit.move(h.ev(1, 705, 304));
|
|
2366
|
+
assert.equal(h.canvas.requests, 0, 'nor a move inside the slop');
|
|
2367
|
+
h.orbit.move(h.ev(1, 720, 300));
|
|
2368
|
+
assert.equal(h.canvas.requests, 1, 'past the slop it asks');
|
|
2369
|
+
assert.deepEqual(h.watched().sort(), ['pointercancel', 'pointerlockchange', 'pointerup', 'visibilitychange', 'window:blur'], 'and for the lock coming and going (the promise says how the request went), and for lifts beyond the canvas while it may take captures');
|
|
2370
|
+
assert.ok(near(h.take().yaw, 15 * LOOK_RAD_PER_PX), 'before the lock lands the client position turns');
|
|
2371
|
+
h.orbit.move(h.ev(1, 730, 300));
|
|
2372
|
+
assert.equal(h.canvas.requests, 1, 'once per drag');
|
|
2373
|
+
h.take();
|
|
2374
|
+
await h.grant();
|
|
2375
|
+
assert.equal(h.locked(), true);
|
|
2376
|
+
assert.equal(h.orbit.move(h.ev(1, 730, 300, { movementX: 40, movementY: -10 })), true);
|
|
2377
|
+
let got = h.take();
|
|
2378
|
+
assert.ok(near(got.yaw, 40 * LOOK_RAD_PER_PX) && near(got.pitch, -10 * LOOK_RAD_PER_PX), 'locked: movementX/Y at the same scale');
|
|
2379
|
+
h.orbit.move(h.ev(1, 730, 300, { movementX: -5, movementY: 0 }));
|
|
2380
|
+
h.orbit.move(h.ev(1, 730, 300, { movementX: undefined, movementY: undefined }));
|
|
2381
|
+
got = h.take();
|
|
2382
|
+
assert.ok(near(got.yaw, -5 * LOOK_RAD_PER_PX) && got.pitch === 0, 'and only them');
|
|
2383
|
+
assert.equal(h.orbit.up(h.ev(1, 730, 300, { button: 0, buttons: 0, type: 'pointerup' })), true);
|
|
2384
|
+
assert.equal(h.doc.exits, 1, 'the release lets go of the lock');
|
|
2385
|
+
h.flush();
|
|
2386
|
+
assert.equal(h.locked(), false);
|
|
2387
|
+
assert.deepEqual(h.watched(), [], 'and every listener once it is gone');
|
|
2388
|
+
assert.equal(h.runtime.taps, 0, 'a drag does not jump');
|
|
2389
|
+
assert.equal(h.orbit.busy, false);
|
|
2390
|
+
checks += 1;
|
|
2391
|
+
}
|
|
2392
|
+
// A left tap still jumps, and is never locked, quick clicks one after
|
|
2393
|
+
// another included.
|
|
2394
|
+
{
|
|
2395
|
+
const h = make('promise');
|
|
2396
|
+
for (let i = 0; i < 3; i += 1) {
|
|
2397
|
+
h.orbit.down(h.ev(1, 700, 300, { button: 0 }));
|
|
2398
|
+
h.orbit.move(h.ev(1, 703, 302));
|
|
2399
|
+
h.orbit.up(h.ev(1, 703, 302, { button: 0, buttons: 0, type: 'pointerup' }));
|
|
2400
|
+
}
|
|
2401
|
+
assert.equal(h.runtime.taps, 3, 'every left tap jumps');
|
|
2402
|
+
assert.equal(h.canvas.requests, 0, 'none asks for the lock');
|
|
2403
|
+
assert.deepEqual(h.watched(), []);
|
|
2404
|
+
assert.deepEqual(h.canvas.captured, [1, 1, 1], 'the capture at the press, as before');
|
|
2405
|
+
checks += 1;
|
|
2406
|
+
}
|
|
2407
|
+
// A right drag asks at the press; a right click alone does not jump, and
|
|
2408
|
+
// the context menu is kept off the canvas.
|
|
2409
|
+
{
|
|
2410
|
+
const h = make('promise');
|
|
2411
|
+
h.orbit.down(h.ev(1, 700, 300, { button: 2, buttons: 2 }));
|
|
2412
|
+
assert.equal(h.canvas.requests, 1, 'a right press asks at once');
|
|
2413
|
+
await h.grant();
|
|
2414
|
+
assert.equal(h.canvas.fire('contextmenu'), true, 'the context menu is prevented');
|
|
2415
|
+
h.orbit.move(h.ev(1, 700, 300, { buttons: 2, movementX: 6, movementY: 0 }));
|
|
2416
|
+
assert.deepEqual(h.take(), { yaw: 0, pitch: 0, zoom: 1, locked: false }, 'inside the slop nothing turns');
|
|
2417
|
+
h.orbit.move(h.ev(1, 700, 300, { buttons: 2, movementX: 10, movementY: 0 }));
|
|
2418
|
+
assert.ok(h.take().yaw > 0, 'past it (counted from movement) it does');
|
|
2419
|
+
h.orbit.up(h.ev(1, 700, 300, { button: 2, buttons: 0, type: 'pointerup' }));
|
|
2420
|
+
h.flush();
|
|
2421
|
+
assert.equal(h.locked(), false);
|
|
2422
|
+
h.orbit.down(h.ev(1, 700, 300, { button: 2, buttons: 2 }));
|
|
2423
|
+
h.orbit.up(h.ev(1, 700, 300, { button: 2, buttons: 0, type: 'pointerup' }));
|
|
2424
|
+
assert.equal(h.runtime.taps, 0, 'a right click does not jump');
|
|
2425
|
+
// That click's lock lands after its release: let go of at once.
|
|
2426
|
+
await h.grant();
|
|
2427
|
+
assert.equal(h.doc.exits, 2, 'a lock that lands after the release is let go of');
|
|
2428
|
+
h.flush();
|
|
2429
|
+
assert.equal(h.locked(), false);
|
|
2430
|
+
assert.deepEqual(h.watched(), []);
|
|
2431
|
+
checks += 1;
|
|
2432
|
+
}
|
|
2433
|
+
// A lock arriving after the release, by the events alone (old Safari:
|
|
2434
|
+
// no promise), and one landing while the next press is still a tap.
|
|
2435
|
+
{
|
|
2436
|
+
const h = make('none');
|
|
2437
|
+
h.orbit.down(h.ev(1, 700, 300, { button: 0 }));
|
|
2438
|
+
h.orbit.move(h.ev(1, 740, 300));
|
|
2439
|
+
h.orbit.up(h.ev(1, 740, 300, { button: 0, buttons: 0, type: 'pointerup' }));
|
|
2440
|
+
h.orbit.down(h.ev(1, 700, 300, { button: 0 }));
|
|
2441
|
+
await h.grant();
|
|
2442
|
+
assert.equal(h.doc.exits, 1, 'landing on a tap: let go of');
|
|
2443
|
+
h.flush();
|
|
2444
|
+
h.orbit.up(h.ev(1, 700, 300, { button: 0, buttons: 0, type: 'pointerup' }));
|
|
2445
|
+
assert.equal(h.runtime.taps, 1, 'and the tap still jumps');
|
|
2446
|
+
assert.deepEqual(h.watched(), []);
|
|
2447
|
+
// With the events alone, a refusal is pointerlockerror; it does not say
|
|
2448
|
+
// whose it is, so ours is watched for a while after it.
|
|
2449
|
+
h.take();
|
|
2450
|
+
h.orbit.down(h.ev(1, 700, 300, { button: 2, buttons: 2 }));
|
|
2451
|
+
h.doc.fire('pointerlockerror');
|
|
2452
|
+
h.dom.waiting.shift();
|
|
2453
|
+
h.orbit.move(h.ev(1, 760, 300, { buttons: 2, movementX: 999 }));
|
|
2454
|
+
assert.ok(near(h.take().yaw, 60 * LOOK_RAD_PER_PX), 'refused: the client position turns, not movement');
|
|
2455
|
+
h.orbit.up(h.ev(1, 760, 300, { button: 2, buttons: 0, type: 'pointerup' }));
|
|
2456
|
+
assert.deepEqual(h.watched().sort(), ['pointercancel', 'pointerlockchange', 'pointerlockerror', 'pointerup'], 'the request is still watched');
|
|
2457
|
+
await new Promise((resolve) => setTimeout(resolve, 1100));
|
|
2458
|
+
assert.deepEqual(h.watched(), [], 'and not after a second');
|
|
2459
|
+
checks += 1;
|
|
2460
|
+
}
|
|
2461
|
+
// Another element's pointerlockerror while ours is on its way (old
|
|
2462
|
+
// Safari: no promise, so an error does not say whose it is): our lock,
|
|
2463
|
+
// landing after the release, is still let go of.
|
|
2464
|
+
{
|
|
2465
|
+
const h = make('none');
|
|
2466
|
+
h.orbit.down(h.ev(1, 700, 300, { button: 2, buttons: 2 }));
|
|
2467
|
+
assert.equal(h.canvas.requests, 1);
|
|
2468
|
+
h.doc.fire('pointerlockerror');
|
|
2469
|
+
h.orbit.up(h.ev(1, 700, 300, { button: 2, buttons: 0, type: 'pointerup' }));
|
|
2470
|
+
await h.grant();
|
|
2471
|
+
assert.equal(h.doc.exits, 1, 'a lock of ours landing after a foreign error is let go of');
|
|
2472
|
+
h.flush();
|
|
2473
|
+
assert.equal(h.locked(), false);
|
|
2474
|
+
assert.deepEqual(h.watched(), [], 'and nothing is left listening once it is gone');
|
|
2475
|
+
checks += 1;
|
|
2476
|
+
}
|
|
2477
|
+
// With a promise, a pointerlockerror is never taken for ours: the promise
|
|
2478
|
+
// says how our request went.
|
|
2479
|
+
{
|
|
2480
|
+
const h = make('promise');
|
|
2481
|
+
h.orbit.down(h.ev(1, 700, 300, { button: 2, buttons: 2 }));
|
|
2482
|
+
h.doc.fire('pointerlockerror');
|
|
2483
|
+
await h.grant();
|
|
2484
|
+
h.orbit.move(h.ev(1, 700, 300, { buttons: 2, movementX: 30 }));
|
|
2485
|
+
assert.ok(near(h.take().yaw, 30 * LOOK_RAD_PER_PX), 'a foreign error leaves our lock and its movement');
|
|
2486
|
+
h.orbit.up(h.ev(1, 700, 300, { button: 2, buttons: 0, type: 'pointerup' }));
|
|
2487
|
+
h.flush();
|
|
2488
|
+
assert.equal(h.locked(), false);
|
|
2489
|
+
assert.deepEqual(h.watched(), []);
|
|
2490
|
+
checks += 1;
|
|
2491
|
+
}
|
|
2492
|
+
// A late lock landing during the next left tap takes that tap's capture
|
|
2493
|
+
// (the spec's implicit release); once it is let go of, the capture is
|
|
2494
|
+
// given back, so a release beyond the canvas still ends the tap, a jump.
|
|
2495
|
+
for (const mode of ['promise', 'none']) {
|
|
2496
|
+
const h = make(mode);
|
|
2497
|
+
h.orbit.down(h.ev(1, 700, 300, { button: 2, buttons: 2 }));
|
|
2498
|
+
h.orbit.up(h.ev(1, 700, 300, { button: 2, buttons: 0, type: 'pointerup' }));
|
|
2499
|
+
h.canvas.holding.clear();
|
|
2500
|
+
h.orbit.down(h.ev(1, 995, 300, { button: 0 }));
|
|
2501
|
+
await h.grant();
|
|
2502
|
+
assert.equal(h.canvas.holding.has(1), false, `${mode}: the lock took the capture`);
|
|
2503
|
+
h.flush();
|
|
2504
|
+
assert.equal(h.locked(), false);
|
|
2505
|
+
assert.equal(h.canvas.holding.has(1), true, `${mode}: and it is given back`);
|
|
2506
|
+
assert.equal(h.orbit.move(h.ev(1, 1001, 300)), true);
|
|
2507
|
+
h.orbit.up(h.ev(1, 1001, 300, { button: 0, buttons: 0, type: 'pointerup' }));
|
|
2508
|
+
assert.deepEqual({ busy: h.orbit.busy, taps: h.runtime.taps }, { busy: false, taps: 1 }, `${mode}: the tap ends, a jump`);
|
|
2509
|
+
assert.deepEqual(h.watched(), []);
|
|
2510
|
+
checks += 1;
|
|
2511
|
+
}
|
|
2512
|
+
// A lost pointerup never leaves a mouse pointer held: the next press, a
|
|
2513
|
+
// move with no button down, or a blur ends it.
|
|
2514
|
+
for (const how of ['press', 'buttons0', 'blur']) {
|
|
2515
|
+
const h = make('missing');
|
|
2516
|
+
h.orbit.down(h.ev(1, 700, 300, { button: 0 }));
|
|
2517
|
+
if (how === 'press') {
|
|
2518
|
+
h.orbit.down(h.ev(2, 700, 300, { button: 0 }));
|
|
2519
|
+
h.orbit.up(h.ev(2, 700, 300, { button: 0, buttons: 0, type: 'pointerup' }));
|
|
2520
|
+
}
|
|
2521
|
+
if (how === 'buttons0') h.orbit.move(h.ev(1, 700, 300, { buttons: 0 }));
|
|
2522
|
+
if (how === 'blur') h.win.fire('blur');
|
|
2523
|
+
assert.equal(h.orbit.busy, false, `${how}: nothing is held`);
|
|
2524
|
+
assert.equal(h.runtime.taps, how === 'press' ? 1 : 0, `${how}: only a real tap jumps`);
|
|
2525
|
+
assert.deepEqual(h.watched(), []);
|
|
2526
|
+
checks += 1;
|
|
2527
|
+
}
|
|
2528
|
+
// Each way a held, locked drag is let go of: the drag ends with no tap and
|
|
2529
|
+
// no look or stick left held, the lock is let go of, and so are the
|
|
2530
|
+
// listeners.
|
|
2531
|
+
for (const how of ['blur', 'hidden', 'escape', 'buttons0', 'reset', 'detach', 'cancel']) {
|
|
2532
|
+
const h = make('promise');
|
|
2533
|
+
h.orbit.down(h.ev(1, 700, 300, { button: 0 }));
|
|
2534
|
+
h.orbit.move(h.ev(1, 740, 300));
|
|
2535
|
+
await h.grant();
|
|
2536
|
+
h.take();
|
|
2537
|
+
if (how === 'blur') h.win.fire('blur');
|
|
2538
|
+
if (how === 'hidden') {
|
|
2539
|
+
h.doc.fire('visibilitychange');
|
|
2540
|
+
assert.equal(h.orbit.busy, true, `${how}: a visibilitychange to visible is nothing`);
|
|
2541
|
+
h.doc.visibilityState = 'hidden';
|
|
2542
|
+
h.doc.fire('visibilitychange');
|
|
2543
|
+
}
|
|
2544
|
+
if (how === 'escape') h.escape();
|
|
2545
|
+
if (how === 'buttons0') assert.equal(h.orbit.move(h.ev(1, 740, 300, { buttons: 0, movementX: 50 })), true);
|
|
2546
|
+
if (how === 'reset') h.runtime.lookInput.reset();
|
|
2547
|
+
if (how === 'detach') h.orbit.detach();
|
|
2548
|
+
if (how === 'cancel') h.orbit.up(h.ev(1, 740, 300, { type: 'pointercancel', buttons: 0 }));
|
|
2549
|
+
assert.equal(h.orbit.busy, false, `${how}: the drag is over`);
|
|
2550
|
+
assert.equal(h.doc.exits, how === 'escape' ? 0 : 1, `${how}: the lock is let go of`);
|
|
2551
|
+
h.flush();
|
|
2552
|
+
assert.equal(h.locked(), false, how);
|
|
2553
|
+
assert.deepEqual(h.watched(), [], `${how}: no listener is left`);
|
|
2554
|
+
assert.equal(h.orbit.move(h.ev(1, 900, 300, { movementX: 80 })), false, `${how}: its later moves are not this file's`);
|
|
2555
|
+
assert.deepEqual(h.take(), { yaw: 0, pitch: 0, zoom: 1, locked: false }, `${how}: nothing turns after it`);
|
|
2556
|
+
assert.equal(h.orbit.up(h.ev(1, 900, 300, { button: 0, buttons: 0, type: 'pointerup' })), false);
|
|
2557
|
+
assert.equal(h.runtime.taps, 0, `${how}: no tap`);
|
|
2558
|
+
assert.equal(h.stick.active, false);
|
|
2559
|
+
checks += 1;
|
|
2560
|
+
}
|
|
2561
|
+
// Escape, then a drag at once: Chrome refuses the re-lock (a rejection)
|
|
2562
|
+
// and the drag goes on, on the capture, with nothing thrown.
|
|
2563
|
+
{
|
|
2564
|
+
const h = make('promise');
|
|
2565
|
+
h.orbit.down(h.ev(1, 700, 300, { button: 2, buttons: 2 }));
|
|
2566
|
+
await h.grant();
|
|
2567
|
+
h.escape();
|
|
2568
|
+
h.orbit.down(h.ev(1, 700, 300, { button: 2, buttons: 2 }));
|
|
2569
|
+
assert.equal(h.canvas.requests, 2);
|
|
2570
|
+
await h.deny();
|
|
2571
|
+
// Out of the frame and back: the capture keeps the moves coming.
|
|
2572
|
+
h.orbit.move(h.ev(1, -200, 300, { buttons: 2 }));
|
|
2573
|
+
assert.ok(near(h.take().yaw, -900 * LOOK_RAD_PER_PX), 'refused: the drag turns on the client position, beyond the frame');
|
|
2574
|
+
h.orbit.up(h.ev(1, -200, 300, { button: 2, buttons: 0, type: 'pointerup' }));
|
|
2575
|
+
assert.equal(h.orbit.busy, false, 'and a release outside ends it');
|
|
2576
|
+
assert.deepEqual(h.watched(), []);
|
|
2577
|
+
assert.equal(h.doc.exits, 0);
|
|
2578
|
+
// The next drag asks again.
|
|
2579
|
+
h.orbit.down(h.ev(1, 700, 300, { button: 2, buttons: 2 }));
|
|
2580
|
+
assert.equal(h.canvas.requests, 3);
|
|
2581
|
+
await h.grant();
|
|
2582
|
+
h.orbit.up(h.ev(1, 700, 300, { button: 2, buttons: 0, type: 'pointerup' }));
|
|
2583
|
+
h.flush();
|
|
2584
|
+
assert.deepEqual(h.watched(), []);
|
|
2585
|
+
checks += 1;
|
|
2586
|
+
}
|
|
2587
|
+
// A requestPointerLock that throws, or none at all: the drag as before.
|
|
2588
|
+
for (const mode of ['throw', 'missing']) {
|
|
2589
|
+
const h = make(mode);
|
|
2590
|
+
h.orbit.down(h.ev(1, 700, 300, { button: 2, buttons: 2 }));
|
|
2591
|
+
h.orbit.move(h.ev(1, 740, 300, { buttons: 2 }));
|
|
2592
|
+
assert.ok(near(h.take().yaw, 40 * LOOK_RAD_PER_PX), `${mode}: the drag turns`);
|
|
2593
|
+
h.orbit.up(h.ev(1, 740, 300, { button: 2, buttons: 0, type: 'pointerup' }));
|
|
2594
|
+
assert.equal(h.orbit.busy, false);
|
|
2595
|
+
assert.deepEqual(h.canvas.captured, [1], `${mode}: on the capture`);
|
|
2596
|
+
assert.deepEqual(h.watched(), [], `${mode}: nothing left listening`);
|
|
2597
|
+
assert.equal(h.canvas.requests, mode === 'throw' ? 1 : 0);
|
|
2598
|
+
checks += 1;
|
|
2599
|
+
}
|
|
2600
|
+
// A second button during a drag: pointer events send it as a pointermove.
|
|
2601
|
+
// Pressed during a left tap it makes a look (no jump) and asks; during a
|
|
2602
|
+
// locked drag it changes nothing; the lock ends with the last button.
|
|
2603
|
+
{
|
|
2604
|
+
const h = make('promise');
|
|
2605
|
+
h.orbit.down(h.ev(1, 700, 300, { button: 0 }));
|
|
2606
|
+
h.orbit.move(h.ev(1, 700, 300, { button: 2, buttons: 3 }));
|
|
2607
|
+
assert.equal(h.canvas.requests, 1, 'a chord asks');
|
|
2608
|
+
await h.grant();
|
|
2609
|
+
h.orbit.move(h.ev(1, 700, 300, { button: 0, buttons: 2, movementX: 3 }));
|
|
2610
|
+
assert.equal(h.orbit.busy, true, 'letting go of one button keeps the drag');
|
|
2611
|
+
assert.equal(h.doc.exits, 0);
|
|
2612
|
+
h.orbit.move(h.ev(1, 700, 300, { buttons: 2, movementX: 7 }));
|
|
2613
|
+
assert.ok(near(h.take().yaw, 10 * LOOK_RAD_PER_PX), 'a chord is a look from its press');
|
|
2614
|
+
h.orbit.up(h.ev(1, 700, 300, { button: 2, buttons: 0, type: 'pointerup' }));
|
|
2615
|
+
assert.equal(h.runtime.taps, 0, 'and does not jump');
|
|
2616
|
+
assert.equal(h.doc.exits, 1);
|
|
2617
|
+
h.flush();
|
|
2618
|
+
assert.deepEqual(h.watched(), []);
|
|
2619
|
+
checks += 1;
|
|
2620
|
+
}
|
|
2621
|
+
// Touch and pen are untouched: no lock, no listeners, as before.
|
|
2622
|
+
for (const pointerType of ['touch', 'pen']) {
|
|
2623
|
+
const h = make('promise');
|
|
2624
|
+
h.orbit.down({ pointerId: 1, clientX: 700, clientY: 300, pointerType, button: 0, buttons: 1 });
|
|
2625
|
+
h.orbit.move({ pointerId: 1, clientX: 760, clientY: 300, pointerType, buttons: 1, movementX: 500 });
|
|
2626
|
+
assert.ok(near(h.take().yaw, 60 * LOOK_RAD_PER_PX), `${pointerType}: the client position, as always`);
|
|
2627
|
+
h.orbit.move({ pointerId: 1, clientX: 760, clientY: 300, pointerType, buttons: 0 });
|
|
2628
|
+
assert.equal(h.orbit.busy, true, `${pointerType}: buttons 0 is not a lift`);
|
|
2629
|
+
h.orbit.up({ pointerId: 1, clientX: 760, clientY: 300, pointerType, type: 'pointerup' });
|
|
2630
|
+
h.orbit.down({ pointerId: 2, clientX: 700, clientY: 300, pointerType, button: 0 });
|
|
2631
|
+
h.orbit.up({ pointerId: 2, clientX: 700, clientY: 300, pointerType, type: 'pointerup' });
|
|
2632
|
+
assert.equal(h.runtime.taps, 1, `${pointerType}: a tap jumps`);
|
|
2633
|
+
assert.equal(h.canvas.requests, 0);
|
|
2634
|
+
assert.deepEqual(h.watched(), []);
|
|
2635
|
+
checks += 1;
|
|
2636
|
+
}
|
|
2637
|
+
// A scene without the key loaded while a right press's request is on its
|
|
2638
|
+
// way: at the load the canvas has the keyless listeners only, and with a
|
|
2639
|
+
// promise nothing at all on the document or window (old Safari's
|
|
2640
|
+
// event-only request keeps its two lock listeners until it is answered);
|
|
2641
|
+
// the grant that lands in the keyless scene is let go of at once, after
|
|
2642
|
+
// which nothing is left, and the keyless scene runs as before the key.
|
|
2643
|
+
for (const lockMode of ['promise', 'none']) {
|
|
2644
|
+
for (const mode of ['off', 'rigid']) {
|
|
2645
|
+
const h = makeRuntime('orbit');
|
|
2646
|
+
const dom = makeLockDom(lockMode, h.canvas);
|
|
2647
|
+
h.run(30);
|
|
2648
|
+
h.canvas.fire('pointerdown', { pointerId: 1, clientX: 800, clientY: 300, pointerType: 'mouse', button: 2, buttons: 2 });
|
|
2649
|
+
assert.equal(dom.canvas.requests, 1);
|
|
2650
|
+
h.load(mode);
|
|
2651
|
+
const what = `${lockMode}, orbit then ${mode}`;
|
|
2652
|
+
assert.deepEqual(h.canvas.types(), ['pointercancel', 'pointerdown', 'pointermove', 'pointerup'], `${what}: the keyless listeners only`);
|
|
2653
|
+
// Only lifts beyond the canvas (a grant would take captures) and, with
|
|
2654
|
+
// no promise, the request's own two.
|
|
2655
|
+
assert.deepEqual(dom.watched().sort(), lockMode === 'promise' ? ['pointercancel', 'pointerup'] : ['pointercancel', 'pointerlockchange', 'pointerlockerror', 'pointerup'], `${what}: on the document and window`);
|
|
2656
|
+
await dom.grant();
|
|
2657
|
+
assert.equal(dom.doc.exits, 1, `${what}: the late grant is let go of`);
|
|
2658
|
+
dom.flush();
|
|
2659
|
+
assert.equal(dom.locked(), false);
|
|
2660
|
+
assert.deepEqual(dom.watched(), [], `${what}: and nothing is left listening`);
|
|
2661
|
+
const twin = makeRuntime(mode, PlayerBefore);
|
|
2662
|
+
h.copyTo(twin);
|
|
2663
|
+
twin.load(mode);
|
|
2664
|
+
h.frames.length = 0;
|
|
2665
|
+
h.calls.length = 0;
|
|
2666
|
+
const input = keylessInput(h, twin);
|
|
2667
|
+
for (let i = 1; i < 200; i += 1) {
|
|
2668
|
+
// The right button held from the keyed scene, moved and let go of here only.
|
|
2669
|
+
if (i < 50) h.canvas.fire('pointermove', { pointerId: 1, clientX: 800 + i, clientY: 300, pointerType: 'mouse', button: -1, buttons: 2, movementX: 9 });
|
|
2670
|
+
if (i === 50) h.canvas.fire('pointerup', { pointerId: 1, clientX: 850, clientY: 300, pointerType: 'mouse', button: 2, buttons: 0 });
|
|
2671
|
+
const keys = input(i);
|
|
2672
|
+
h.frame(UNEVEN(i), keys);
|
|
2673
|
+
twin.frame(UNEVEN(i), keys);
|
|
2674
|
+
}
|
|
2675
|
+
sameFrames(h.frames, twin.frames, `${what}: the Player before the key`);
|
|
2676
|
+
assert.equal(dom.canvas.requests, 1, `${what}: no lock asked for in the keyless scene`);
|
|
2677
|
+
assert.deepEqual(dom.watched(), []);
|
|
2678
|
+
checks += 1;
|
|
2679
|
+
}
|
|
2680
|
+
}
|
|
2681
|
+
// Every pointer down on the canvas gets back the capture a lock of ours
|
|
2682
|
+
// took from it (the spec's implicit release), keyless or under the key,
|
|
2683
|
+
// mouse or touch: a release beyond the canvas still reaches it, so the
|
|
2684
|
+
// stick is let go of and a tap jumps.
|
|
2685
|
+
{
|
|
2686
|
+
const fire = (h, type, id, x, y, pointerType, button = 0, buttons = type === 'pointerup' ? 0 : 1) =>
|
|
2687
|
+
h.canvas.fire(type, { pointerId: id, clientX: x, clientY: y, pointerType, button, buttons });
|
|
2688
|
+
// Beyond the canvas, the lift reaches it only through a capture.
|
|
2689
|
+
const outsideUp = (h, id, x, y, pointerType) => {
|
|
2690
|
+
if (h.canvas.holding.has(id)) fire(h, 'pointerup', id, x, y, pointerType);
|
|
2691
|
+
};
|
|
2692
|
+
// A late grant landing in a keyless scene, on a keyless mouse stick and
|
|
2693
|
+
// a keyless touch tap that went down after the load.
|
|
2694
|
+
for (const lockMode of ['promise', 'none']) {
|
|
2695
|
+
for (const mode of ['off', 'rigid']) {
|
|
2696
|
+
const what = `${lockMode}, orbit then ${mode}`;
|
|
2697
|
+
const h = makeRuntime('orbit');
|
|
2698
|
+
const dom = makeLockDom(lockMode, h.canvas);
|
|
2699
|
+
h.run(10);
|
|
2700
|
+
fire(h, 'pointerdown', 1, 800, 300, 'mouse', 2, 2);
|
|
2701
|
+
h.load(mode);
|
|
2702
|
+
fire(h, 'pointerup', 1, 800, 300, 'mouse', 2);
|
|
2703
|
+
fire(h, 'pointerdown', 1, 300, 400, 'mouse');
|
|
2704
|
+
fire(h, 'pointermove', 1, 300, 330, 'mouse');
|
|
2705
|
+
fire(h, 'pointerdown', 6, 700, 300, 'touch');
|
|
2706
|
+
assert.equal(h.stick().active, true);
|
|
2707
|
+
await dom.grant();
|
|
2708
|
+
assert.deepEqual([...h.canvas.holding], [], 'the grant took every capture');
|
|
2709
|
+
assert.equal(dom.doc.exits, 1);
|
|
2710
|
+
dom.flush();
|
|
2711
|
+
assert.deepEqual([...h.canvas.holding].sort(), [1, 6], `${what}: each is given back`);
|
|
2712
|
+
outsideUp(h, 1, -50, 330, 'mouse');
|
|
2713
|
+
assert.equal(h.stick().active, false, `${what}: a release beyond the canvas lets go of the stick`);
|
|
2714
|
+
outsideUp(h, 6, 700, 300, 'touch');
|
|
2715
|
+
assert.equal(h.jumped(), true, `${what}: and a tap jumps`);
|
|
2716
|
+
assert.deepEqual(dom.watched(), [], `${what}: nothing is left listening`);
|
|
2717
|
+
checks += 1;
|
|
2718
|
+
}
|
|
2719
|
+
}
|
|
2720
|
+
// Under the key: a touch stick held while a mouse lock lands and ends;
|
|
2721
|
+
// and a touch put down while the lock is on, which cannot be captured
|
|
2722
|
+
// then (no throw), and is once it ends.
|
|
2723
|
+
for (const when of ['before', 'during']) {
|
|
2724
|
+
const h = makeRuntime('orbit');
|
|
2725
|
+
const dom = makeLockDom('promise', h.canvas);
|
|
2726
|
+
h.run(10);
|
|
2727
|
+
if (when === 'before') {
|
|
2728
|
+
fire(h, 'pointerdown', 7, 300, 400, 'touch');
|
|
2729
|
+
fire(h, 'pointermove', 7, 300, 330, 'touch');
|
|
2730
|
+
}
|
|
2731
|
+
fire(h, 'pointerdown', 1, 800, 300, 'mouse', 2, 2);
|
|
2732
|
+
await dom.grant();
|
|
2733
|
+
if (when === 'during') {
|
|
2734
|
+
fire(h, 'pointerdown', 7, 300, 400, 'touch');
|
|
2735
|
+
fire(h, 'pointermove', 7, 300, 330, 'touch');
|
|
2736
|
+
}
|
|
2737
|
+
assert.equal(h.stick().active, true, `${when}: the touch walks`);
|
|
2738
|
+
assert.equal(h.canvas.holding.has(7), false);
|
|
2739
|
+
fire(h, 'pointerup', 1, 800, 300, 'mouse', 2);
|
|
2740
|
+
dom.flush();
|
|
2741
|
+
assert.equal(h.canvas.holding.has(7), true, `${when}: the touch gets its capture once the lock ends`);
|
|
2742
|
+
outsideUp(h, 7, -10, 330, 'touch');
|
|
2743
|
+
assert.equal(h.stick().active, false, `${when}: and its release beyond the canvas lets go of the stick`);
|
|
2744
|
+
assert.equal(h.runtime.orbitInput().busy, false);
|
|
2745
|
+
assert.deepEqual(dom.watched(), []);
|
|
2746
|
+
checks += 1;
|
|
2747
|
+
}
|
|
2748
|
+
}
|
|
2749
|
+
// A finger lifted beyond the canvas while a lock of ours had its capture:
|
|
2750
|
+
// its pointerup never reaches the canvas, and once the lock ends it is
|
|
2751
|
+
// let go of as a pointercancel would be, as origin/main's capture would
|
|
2752
|
+
// have: the stick idles, nothing is held, the next finger takes the
|
|
2753
|
+
// stick. Under the key, and keyless (a late grant after a scene load).
|
|
2754
|
+
{
|
|
2755
|
+
const fire = (h, type, id, x, y, pointerType, button = 0, buttons = type === 'pointerup' ? 0 : 1) =>
|
|
2756
|
+
h.canvas.fire(type, { pointerId: id, clientX: x, clientY: y, pointerType, button, buttons });
|
|
2757
|
+
for (const scene of ['orbit', 'off', 'rigid']) {
|
|
2758
|
+
const h = makeRuntime('orbit');
|
|
2759
|
+
const dom = makeLockDom('promise', h.canvas);
|
|
2760
|
+
h.run(10);
|
|
2761
|
+
if (scene !== 'orbit') {
|
|
2762
|
+
fire(h, 'pointerdown', 1, 800, 300, 'mouse', 2, 2);
|
|
2763
|
+
h.load(scene);
|
|
2764
|
+
fire(h, 'pointerup', 1, 800, 300, 'mouse', 2);
|
|
2765
|
+
}
|
|
2766
|
+
fire(h, 'pointerdown', 7, 300, 400, 'touch');
|
|
2767
|
+
fire(h, 'pointermove', 7, 300, 330, 'touch');
|
|
2768
|
+
if (scene === 'orbit') fire(h, 'pointerdown', 1, 800, 300, 'mouse', 2, 2);
|
|
2769
|
+
await dom.grant();
|
|
2770
|
+
// The finger lifts beyond the canvas: its pointerup goes elsewhere.
|
|
2771
|
+
h.canvas.gone.add(7);
|
|
2772
|
+
if (scene === 'orbit') fire(h, 'pointerup', 1, 800, 300, 'mouse', 2);
|
|
2773
|
+
assert.equal(h.stick().active, true, `${scene}: walking until the lock ends`);
|
|
2774
|
+
dom.flush();
|
|
2775
|
+
assert.equal(dom.locked(), false);
|
|
2776
|
+
assert.equal(h.stick().active, false, `${scene}: the finger lifted beyond the canvas lets go of the stick`);
|
|
2777
|
+
assert.equal(h.runtime.orbitInput().busy, false, `${scene}: nothing is held`);
|
|
2778
|
+
assert.equal(h.jumped(), false, `${scene}: and it is no tap`);
|
|
2779
|
+
fire(h, 'pointerdown', 8, 300, 400, 'touch');
|
|
2780
|
+
fire(h, 'pointermove', 8, 300, 340, 'touch');
|
|
2781
|
+
assert.equal(h.stick().active, true, `${scene}: the next finger takes the stick`);
|
|
2782
|
+
fire(h, 'pointerup', 8, 300, 340, 'touch');
|
|
2783
|
+
assert.equal(h.stick().active, false);
|
|
2784
|
+
assert.deepEqual(dom.watched(), []);
|
|
2785
|
+
checks += 1;
|
|
2786
|
+
}
|
|
2787
|
+
}
|
|
2788
|
+
// A late grant crossing into a keyless scene, under both unlock timings:
|
|
2789
|
+
// Chromium clears pointerLockElement inside exitPointerLock and sends
|
|
2790
|
+
// pointerlockchange later; WebKit does both later. A touch stick and a
|
|
2791
|
+
// touch tap that went down in the keyless scene lose their captures to
|
|
2792
|
+
// the grant. Lifted beyond the canvas before the unlock event: the
|
|
2793
|
+
// document catches each lift and hands it to the keyless handler, so the
|
|
2794
|
+
// stick stops and the tap jumps. Lifted beyond it after: the capture
|
|
2795
|
+
// given back at the unlock event brings it to the canvas.
|
|
2796
|
+
{
|
|
2797
|
+
const fire = (h, type, id, x, y, pointerType, button = 0, buttons = type === 'pointerup' ? 0 : 1) =>
|
|
2798
|
+
h.canvas.fire(type, { pointerId: id, clientX: x, clientY: y, pointerType, button, buttons });
|
|
2799
|
+
// A lift beyond the canvas: to the canvas if it holds the capture, else
|
|
2800
|
+
// to the document (capture phase), aimed at something else.
|
|
2801
|
+
const liftOutside = (h, dom, id, x, y) => {
|
|
2802
|
+
const event = { pointerId: id, clientX: x, clientY: y, pointerType: 'touch', button: 0, buttons: 0 };
|
|
2803
|
+
if (h.canvas.holding.has(id)) h.canvas.fire('pointerup', event);
|
|
2804
|
+
else {
|
|
2805
|
+
h.canvas.gone.add(id);
|
|
2806
|
+
dom.doc.fire('pointerup', { ...event, target: 'elsewhere' });
|
|
2807
|
+
}
|
|
2808
|
+
};
|
|
2809
|
+
for (const exit of ['chromium', 'webkit']) {
|
|
2810
|
+
for (const lift of ['before', 'after']) {
|
|
2811
|
+
const what = `${exit}, lifted ${lift} the unlock event`;
|
|
2812
|
+
const h = makeRuntime('orbit');
|
|
2813
|
+
const dom = makeLockDom('promise', h.canvas, exit);
|
|
2814
|
+
h.run(10);
|
|
2815
|
+
fire(h, 'pointerdown', 1, 800, 300, 'mouse', 2, 2);
|
|
2816
|
+
h.load('off');
|
|
2817
|
+
fire(h, 'pointerup', 1, 800, 300, 'mouse', 2);
|
|
2818
|
+
fire(h, 'pointerdown', 7, 300, 400, 'touch');
|
|
2819
|
+
fire(h, 'pointermove', 7, 300, 330, 'touch');
|
|
2820
|
+
fire(h, 'pointerdown', 6, 700, 300, 'touch');
|
|
2821
|
+
await dom.grant();
|
|
2822
|
+
assert.equal(dom.doc.exits, 1, `${what}: the late grant is let go of`);
|
|
2823
|
+
assert.equal(h.canvas.holding.size, 0);
|
|
2824
|
+
if (lift === 'before') {
|
|
2825
|
+
liftOutside(h, dom, 7, -10, 330);
|
|
2826
|
+
liftOutside(h, dom, 6, 700, 300);
|
|
2827
|
+
dom.flush();
|
|
2828
|
+
} else {
|
|
2829
|
+
dom.flush();
|
|
2830
|
+
assert.deepEqual([...h.canvas.holding].sort(), [6, 7], `${what}: the captures are given back at the event`);
|
|
2831
|
+
liftOutside(h, dom, 7, -10, 330);
|
|
2832
|
+
liftOutside(h, dom, 6, 700, 300);
|
|
2833
|
+
}
|
|
2834
|
+
assert.equal(h.stick().active, false, `${what}: the stick stops`);
|
|
2835
|
+
assert.equal(h.jumped(), true, `${what}: the tap jumps`);
|
|
2836
|
+
assert.equal(dom.locked(), false);
|
|
2837
|
+
assert.deepEqual(dom.watched(), [], `${what}: nothing is left listening`);
|
|
2838
|
+
// The next finger takes the stick.
|
|
2839
|
+
fire(h, 'pointerdown', 8, 300, 400, 'touch');
|
|
2840
|
+
fire(h, 'pointermove', 8, 300, 340, 'touch');
|
|
2841
|
+
assert.equal(h.stick().active, true, `${what}: the next finger walks`);
|
|
2842
|
+
checks += 1;
|
|
2843
|
+
}
|
|
2844
|
+
}
|
|
2845
|
+
// Under the key, Chromium's timing: a touch stick lifted beyond the
|
|
2846
|
+
// canvas between the exit call and its event.
|
|
2847
|
+
{
|
|
2848
|
+
const h = makeRuntime('orbit');
|
|
2849
|
+
const dom = makeLockDom('promise', h.canvas, 'chromium');
|
|
2850
|
+
h.run(10);
|
|
2851
|
+
fire(h, 'pointerdown', 7, 300, 400, 'touch');
|
|
2852
|
+
fire(h, 'pointermove', 7, 300, 330, 'touch');
|
|
2853
|
+
fire(h, 'pointerdown', 1, 800, 300, 'mouse', 2, 2);
|
|
2854
|
+
await dom.grant();
|
|
2855
|
+
fire(h, 'pointerup', 1, 800, 300, 'mouse', 2);
|
|
2856
|
+
assert.equal(dom.locked(), false, 'chromium: cleared inside the call');
|
|
2857
|
+
liftOutside(h, dom, 7, -10, 330);
|
|
2858
|
+
dom.flush();
|
|
2859
|
+
assert.equal(h.stick().active, false, 'chromium, under the key: the stick stops');
|
|
2860
|
+
assert.equal(h.runtime.orbitInput().busy, false);
|
|
2861
|
+
assert.deepEqual(dom.watched(), []);
|
|
2862
|
+
checks += 1;
|
|
2863
|
+
}
|
|
2864
|
+
}
|
|
2865
|
+
// Keyless, through Scene3DPlayer's attachInput on a canvas that can lock:
|
|
2866
|
+
// mouse drags and clicks of every button are the stick and jumps they
|
|
2867
|
+
// were, frame for frame, with no lock asked for and nothing added to the
|
|
2868
|
+
// document or the window.
|
|
2869
|
+
for (const mode of ['off', 'rigid']) {
|
|
2870
|
+
const now = makeRuntime(mode, Player);
|
|
2871
|
+
const before = makeRuntime(mode, PlayerBefore);
|
|
2872
|
+
const dom = makeLockDom('promise');
|
|
2873
|
+
Object.assign(now.canvas, { ownerDocument: dom.doc, requestPointerLock: dom.canvas.requestPointerLock });
|
|
2874
|
+
const mouse = (h, type, id, x, y, button) => h.canvas.fire(type, { pointerId: id, clientX: x, clientY: y, pointerType: 'mouse', button, buttons: type === 'pointerup' ? 0 : 1 << button, movementX: 30, movementY: 30 });
|
|
2875
|
+
for (let i = 0; i < 300; i += 1) {
|
|
2876
|
+
const phase = i % 50;
|
|
2877
|
+
const button = [0, 2, 1][Math.floor(i / 50) % 3];
|
|
2878
|
+
for (const h of [now, before]) {
|
|
2879
|
+
if (phase === 0) mouse(h, 'pointerdown', 1, 700, 300, button);
|
|
2880
|
+
if (phase > 0 && phase < 20) mouse(h, 'pointermove', 1, 700 + phase * 5, 300 - phase * 3, -1);
|
|
2881
|
+
if (phase === 20) mouse(h, 'pointerup', 1, 800, 240, button);
|
|
2882
|
+
if (phase === 30) mouse(h, 'pointerdown', 1, 600, 300, button);
|
|
2883
|
+
if (phase === 32) mouse(h, 'pointerup', 1, 601, 300, button);
|
|
2884
|
+
h.frame(FIXED);
|
|
2885
|
+
}
|
|
2886
|
+
}
|
|
2887
|
+
sameFrames(now.frames, before.frames, `${mode}: mouse drags on a canvas that can lock, as before the key`);
|
|
2888
|
+
assert.ok(now.frames.some((f) => f.stick.active) && now.frames.some((f) => f.calls.includes('setVelocity')), 'and the mouse walked and jumped');
|
|
2889
|
+
assert.equal(dom.canvas.requests, 0, `${mode}: no lock is asked for`);
|
|
2890
|
+
assert.deepEqual(dom.watched(), [], `${mode}: nothing listens on the document or window`);
|
|
2891
|
+
assert.deepEqual(now.canvas.types(), ['pointercancel', 'pointerdown', 'pointermove', 'pointerup']);
|
|
2892
|
+
assert.equal(now.runtime.lookInput, undefined);
|
|
2893
|
+
checks += 1;
|
|
2894
|
+
}
|
|
2895
|
+
return checks;
|
|
2896
|
+
}
|
|
2897
|
+
|
|
1811
2898
|
// attachInput before the key and now, keyless and with `"follow": "rigid"`
|
|
1812
2899
|
// alone: the same pointer and key events, one by one, leave the same stick,
|
|
1813
2900
|
// the same jumps, the same keys, and the same listeners on the canvas and
|
|
@@ -1994,7 +3081,7 @@ function blendHeld() {
|
|
|
1994
3081
|
world.frame();
|
|
1995
3082
|
const from = { ...world.lastCast.from };
|
|
1996
3083
|
const dir = { ...world.lastCast.dir };
|
|
1997
|
-
world.wall =
|
|
3084
|
+
world.wall = 3;
|
|
1998
3085
|
world.camera.position.set(from.x + dir.x * 8, from.y + dir.y * 8, from.z + dir.z * 8);
|
|
1999
3086
|
const out = () => {
|
|
2000
3087
|
const c = world.camera.position;
|
|
@@ -2005,22 +3092,501 @@ function blendHeld() {
|
|
|
2005
3092
|
for (let i = 0; i < 60; i += 1) {
|
|
2006
3093
|
world.frame(UNEVEN(i));
|
|
2007
3094
|
const now = out();
|
|
2008
|
-
assert.ok(now <=
|
|
3095
|
+
assert.ok(now <= 2.75 + 1e-9, `frame ${i}: drawn no farther than the wall allows (${now})`);
|
|
2009
3096
|
assert.ok(now <= last + 1e-9, `frame ${i}: and only nearer (${now} after ${last})`);
|
|
2010
3097
|
last = now;
|
|
2011
3098
|
}
|
|
2012
|
-
assert.ok(Math.abs(out() -
|
|
3099
|
+
assert.ok(Math.abs(out() - 2.75) < 1e-3, 'settled in front of the wall');
|
|
2013
3100
|
// A blend from beside the wall's ray, not along it, is held too.
|
|
2014
3101
|
world.camera.position.set(from.x + 6, from.y + 3, from.z - 5);
|
|
2015
3102
|
for (let i = 0; i < 30; i += 1) {
|
|
2016
3103
|
world.frame();
|
|
2017
|
-
assert.ok(out() <=
|
|
3104
|
+
assert.ok(out() <= 2.75 + 1e-9, `beside: frame ${i} (${out()})`);
|
|
2018
3105
|
}
|
|
2019
3106
|
checks += 1;
|
|
2020
3107
|
return checks;
|
|
2021
3108
|
}
|
|
2022
3109
|
|
|
2023
|
-
//
|
|
3110
|
+
// A stand-in for an actor's three node: a real Group whose `visible` is an
|
|
3111
|
+
// accessor on its class, so every write to it is counted, the ones made
|
|
3112
|
+
// after ownmodel.js has put the node back included.
|
|
3113
|
+
class CountedGroup extends THREE.Group {
|
|
3114
|
+
constructor() {
|
|
3115
|
+
super();
|
|
3116
|
+
this.writes = 0;
|
|
3117
|
+
}
|
|
3118
|
+
get visible() {
|
|
3119
|
+
return this.shown;
|
|
3120
|
+
}
|
|
3121
|
+
set visible(value) {
|
|
3122
|
+
this.writes = (this.writes ?? 0) + 1;
|
|
3123
|
+
this.shown = value;
|
|
3124
|
+
}
|
|
3125
|
+
}
|
|
3126
|
+
function countedNode(x = 0, y = 1, z = 0) {
|
|
3127
|
+
const node = new CountedGroup();
|
|
3128
|
+
node.position.set(x, y, z);
|
|
3129
|
+
return node;
|
|
3130
|
+
}
|
|
3131
|
+
|
|
3132
|
+
// What the play loop draws with (Scene3DPlayer's `startLoop`), its own
|
|
3133
|
+
// line; `render` stands in for world3d.js `renderWorld`, recording what
|
|
3134
|
+
// each draw saw.
|
|
3135
|
+
const DRAW_LINE = 'if (runtime.orbitOwnModel !== undefined) renderHidingOwnModel(world, runtime, renderWorld);\n else renderWorld(world, runtime);';
|
|
3136
|
+
assert.ok(readFileSync(new URL('../engine3d/playerRun.js', import.meta.url), 'utf8').includes(DRAW_LINE), 'the play loop draws as drawFrame does');
|
|
3137
|
+
function drawFrame(world, runtime, render) {
|
|
3138
|
+
if (runtime.orbitOwnModel !== undefined) renderHidingOwnModel(world, runtime, render);
|
|
3139
|
+
else render(world, runtime);
|
|
3140
|
+
}
|
|
3141
|
+
function makeDraws(nodeOf) {
|
|
3142
|
+
const seen = [];
|
|
3143
|
+
const render = (world, runtime) => seen.push({ world, runtime, visible: nodeOf()?.visible });
|
|
3144
|
+
return { seen, render };
|
|
3145
|
+
}
|
|
3146
|
+
|
|
3147
|
+
// The camera inside or against the player's own model leaves it out of
|
|
3148
|
+
// that one draw and nothing else: within the threshold hidden, beyond it
|
|
3149
|
+
// shown, with a margin between; a node something else hid is not touched;
|
|
3150
|
+
// a node replaced is judged afresh; a throw still gives it back.
|
|
3151
|
+
function ownModel() {
|
|
3152
|
+
let checks = 0;
|
|
3153
|
+
const camera = new THREE.PerspectiveCamera(50, 1.6, 0.1, 1000);
|
|
3154
|
+
let node = countedNode();
|
|
3155
|
+
const scene = new THREE.Scene();
|
|
3156
|
+
scene.add(node);
|
|
3157
|
+
const world = { camera, scene, nodes: new Map([['player', { node }]]) };
|
|
3158
|
+
const runtime = {};
|
|
3159
|
+
const { seen, render } = makeDraws(() => node);
|
|
3160
|
+
const draw = (x, y, z) => {
|
|
3161
|
+
camera.position.set(x, y, z);
|
|
3162
|
+
runtime.orbitOwnModel = 'player';
|
|
3163
|
+
drawFrame(world, runtime, render);
|
|
3164
|
+
assert.equal(runtime.orbitOwnModel, undefined, 'the draw takes the name');
|
|
3165
|
+
assert.equal(node.visible, true, 'and every draw ends with the node shown');
|
|
3166
|
+
return seen.at(-1).visible;
|
|
3167
|
+
};
|
|
3168
|
+
// Over the head, as the orbit camera sits: 0.8 m up is the look point.
|
|
3169
|
+
assert.equal(draw(0, 1.8 + 0.6, 0), false, 'at the 0.6 m floor: hidden');
|
|
3170
|
+
assert.equal(node.writes, 2, 'hidden for the draw (one write) and given back (one)');
|
|
3171
|
+
assert.equal(draw(0, 1.8 + HIDE_WITHIN + 0.1, 0), false, 'between the lines it stays hidden');
|
|
3172
|
+
assert.equal(draw(0, 1.8 + SHOW_PAST + 0.01, 0), true, 'past SHOW_PAST: shown');
|
|
3173
|
+
assert.equal(draw(0, 1.8 + HIDE_WITHIN + 0.1, 0), true, 'between the lines from outside: shown');
|
|
3174
|
+
assert.equal(draw(HIDE_WITHIN - 0.05, 1.3, 0), false, 'level with the chest, within: hidden');
|
|
3175
|
+
assert.equal(draw(9, 8, 0), true, 'at rest far out: shown');
|
|
3176
|
+
const writes = node.writes;
|
|
3177
|
+
draw(30, 30, 30);
|
|
3178
|
+
assert.equal(node.writes, writes, 'a draw that shows it writes nothing');
|
|
3179
|
+
checks += 1;
|
|
3180
|
+
// A deck's own hide is kept, and never set back to true.
|
|
3181
|
+
node.visible = false;
|
|
3182
|
+
const before = node.writes;
|
|
3183
|
+
camera.position.set(0, 2.3, 0);
|
|
3184
|
+
runtime.orbitOwnModel = 'player';
|
|
3185
|
+
drawFrame(world, runtime, render);
|
|
3186
|
+
assert.equal(seen.at(-1).visible, false, 'drawn hidden, as the deck has it');
|
|
3187
|
+
assert.equal(node.visible, false, "the deck's hide is still there after the draw");
|
|
3188
|
+
assert.equal(node.writes, before, 'and the node was not written');
|
|
3189
|
+
node.visible = true;
|
|
3190
|
+
checks += 1;
|
|
3191
|
+
// The node replaced between frames (a new look): the old one is never
|
|
3192
|
+
// touched again, the new one is judged without the old one's margin.
|
|
3193
|
+
draw(0, 2.4, 0);
|
|
3194
|
+
const old = node;
|
|
3195
|
+
const oldWrites = old.writes;
|
|
3196
|
+
node = countedNode();
|
|
3197
|
+
scene.add(node);
|
|
3198
|
+
world.nodes.set('player', { node });
|
|
3199
|
+
assert.equal(draw(0, 1.8 + HIDE_WITHIN + 0.1, 0), true, 'a new node between the lines is shown');
|
|
3200
|
+
assert.equal(draw(0, 2.4, 0), false, 'and hidden within');
|
|
3201
|
+
assert.equal(old.writes, oldWrites, 'the old node is left as it was');
|
|
3202
|
+
checks += 1;
|
|
3203
|
+
// No node, an instanced rig, another actor's name, no name: drawn whole.
|
|
3204
|
+
for (const [what, entry, name] of [
|
|
3205
|
+
['no node', null, 'player'],
|
|
3206
|
+
['an instanced rig', { node, instancedRig: new THREE.Group() }, 'player'],
|
|
3207
|
+
['another actor', { node }, 'other'],
|
|
3208
|
+
]) {
|
|
3209
|
+
if (entry) world.nodes.set('player', entry);
|
|
3210
|
+
else world.nodes.delete('player');
|
|
3211
|
+
camera.position.set(0, 2.4, 0);
|
|
3212
|
+
runtime.orbitOwnModel = name;
|
|
3213
|
+
const writes = node.writes;
|
|
3214
|
+
drawFrame(world, runtime, render);
|
|
3215
|
+
assert.equal(node.writes, writes, `${what}: nothing hidden`);
|
|
3216
|
+
}
|
|
3217
|
+
world.nodes.set('player', { node });
|
|
3218
|
+
const count = seen.length;
|
|
3219
|
+
const plain = [];
|
|
3220
|
+
drawFrame(world, runtime, (w, r) => plain.push([w, r, node.visible]));
|
|
3221
|
+
assert.deepEqual(plain, [[world, runtime, true]], 'no name: the render, once, with the same arguments');
|
|
3222
|
+
assert.equal(seen.length, count);
|
|
3223
|
+
checks += 1;
|
|
3224
|
+
// A render that throws still gives the node back.
|
|
3225
|
+
camera.position.set(0, 2.4, 0);
|
|
3226
|
+
runtime.orbitOwnModel = 'player';
|
|
3227
|
+
assert.throws(() =>
|
|
3228
|
+
drawFrame(world, runtime, () => {
|
|
3229
|
+
assert.equal(node.visible, false);
|
|
3230
|
+
throw new Error('render failed');
|
|
3231
|
+
})
|
|
3232
|
+
);
|
|
3233
|
+
assert.equal(node.visible, true, 'shown after a throw');
|
|
3234
|
+
checks += 1;
|
|
3235
|
+
// Extras follow the same one-render contract, even if detached or removed
|
|
3236
|
+
// from the registration set by the render. Other hides are never undone.
|
|
3237
|
+
{
|
|
3238
|
+
const extra = countedNode();
|
|
3239
|
+
const alreadyHidden = countedNode();
|
|
3240
|
+
const detached = countedNode();
|
|
3241
|
+
const readOnly = new THREE.Group();
|
|
3242
|
+
Object.defineProperty(readOnly, 'visible', { value: true, writable: false });
|
|
3243
|
+
alreadyHidden.visible = false;
|
|
3244
|
+
const hiddenWrites = alreadyHidden.writes;
|
|
3245
|
+
scene.add(extra, alreadyHidden, readOnly);
|
|
3246
|
+
world.ownModelWith = new Set([extra, alreadyHidden, detached, readOnly, node]);
|
|
3247
|
+
const drawExtras = (during) => {
|
|
3248
|
+
camera.position.set(0, 2.4, 0);
|
|
3249
|
+
drawFrame(world, { orbitOwnModel: 'player' }, () => {
|
|
3250
|
+
assert.equal(node.visible, false, 'the own model is hidden');
|
|
3251
|
+
assert.equal(extra.visible, false, 'the registered extra is hidden with it');
|
|
3252
|
+
assert.equal(alreadyHidden.visible, false, 'a preexisting hide stays hidden');
|
|
3253
|
+
assert.equal(detached.visible, true, 'an extra outside the scene stays shown');
|
|
3254
|
+
assert.equal(readOnly.visible, true, 'a read-only extra stays shown');
|
|
3255
|
+
during();
|
|
3256
|
+
});
|
|
3257
|
+
};
|
|
3258
|
+
drawExtras(() => {});
|
|
3259
|
+
assert.equal(extra.visible, true, 'extra restored after a normal render');
|
|
3260
|
+
assert.equal(extra.writes, 2, 'only the hide and restore were written');
|
|
3261
|
+
assert.equal(alreadyHidden.writes, hiddenWrites, 'a preexisting hide was never written');
|
|
3262
|
+
assert.equal(detached.writes, 0, 'a detached extra was never written');
|
|
3263
|
+
const failure = new Error('extra render failed');
|
|
3264
|
+
assert.throws(() => drawExtras(() => {
|
|
3265
|
+
scene.remove(extra, node);
|
|
3266
|
+
world.ownModelWith.delete(extra);
|
|
3267
|
+
throw failure;
|
|
3268
|
+
}), (error) => error === failure);
|
|
3269
|
+
assert.equal(extra.visible, true, 'extra restored after detach, unregister and throw');
|
|
3270
|
+
assert.equal(node.visible, true, 'model restored after detach and throw');
|
|
3271
|
+
scene.add(node, extra);
|
|
3272
|
+
world.ownModelWith.add(extra);
|
|
3273
|
+
const before = extra.writes;
|
|
3274
|
+
drawExtras(() => { extra.visible = true; });
|
|
3275
|
+
assert.equal(extra.writes, before + 2, 'a true written during render is kept without another write');
|
|
3276
|
+
delete world.ownModelWith;
|
|
3277
|
+
checks += 1;
|
|
3278
|
+
}
|
|
3279
|
+
// Throwing restore setters cannot strand later extras or replace the first error.
|
|
3280
|
+
{
|
|
3281
|
+
for (const target of ['model', 'extra']) {
|
|
3282
|
+
const model = countedNode();
|
|
3283
|
+
const extra = new THREE.Group();
|
|
3284
|
+
const later = new THREE.Group();
|
|
3285
|
+
const tag = new THREE.Sprite();
|
|
3286
|
+
const scene = new THREE.Scene();
|
|
3287
|
+
scene.add(model, extra, later, tag);
|
|
3288
|
+
const world = {
|
|
3289
|
+
camera, scene, nodes: new Map([['player', { node: model }]]),
|
|
3290
|
+
ownModelWith: new Set([extra, later, tag]),
|
|
3291
|
+
};
|
|
3292
|
+
const objects = [['model', model], ['extra', extra], ['later', later], ['tag', tag]];
|
|
3293
|
+
const restored = [];
|
|
3294
|
+
const firstError = new Error(`${target} restore failed`);
|
|
3295
|
+
const laterError = new Error('later restore failed');
|
|
3296
|
+
camera.position.set(0, 2.4, 0);
|
|
3297
|
+
assert.throws(() => renderHidingOwnModel(world, { orbitOwnModel: 'player' }, () => {
|
|
3298
|
+
for (const [name, object] of objects) {
|
|
3299
|
+
assert.equal(object.visible, false, `${target}: ${name} hidden during render`);
|
|
3300
|
+
let visible = object.visible;
|
|
3301
|
+
Object.defineProperty(object, 'visible', {
|
|
3302
|
+
configurable: true,
|
|
3303
|
+
get: () => visible,
|
|
3304
|
+
set(value) {
|
|
3305
|
+
visible = value;
|
|
3306
|
+
if (value !== true) return;
|
|
3307
|
+
restored.push(name);
|
|
3308
|
+
if (name === target) throw firstError;
|
|
3309
|
+
if (name === 'later') throw laterError;
|
|
3310
|
+
},
|
|
3311
|
+
});
|
|
3312
|
+
}
|
|
3313
|
+
}), (error) => error === firstError, `${target}: the first restore error propagates`);
|
|
3314
|
+
assert.deepEqual(restored, ['model', 'extra', 'later', 'tag'], `${target}: model restored first, then every extra`);
|
|
3315
|
+
for (const [name, object] of objects) {
|
|
3316
|
+
assert.equal(object.visible, true, `${target}: ${name} restored despite throwing setters`);
|
|
3317
|
+
}
|
|
3318
|
+
renderHidingOwnModel(world, {}, () => {
|
|
3319
|
+
for (const [name, object] of objects) {
|
|
3320
|
+
assert.equal(object.visible, true, `${target}: ${name} visible in a later keyless frame`);
|
|
3321
|
+
}
|
|
3322
|
+
});
|
|
3323
|
+
}
|
|
3324
|
+
checks += 1;
|
|
3325
|
+
}
|
|
3326
|
+
// Keyless draws and keyed draws that show the model never read the set.
|
|
3327
|
+
{
|
|
3328
|
+
Object.defineProperty(world, 'ownModelWith', {
|
|
3329
|
+
configurable: true,
|
|
3330
|
+
get() { throw new Error('ownModelWith must not be read'); },
|
|
3331
|
+
});
|
|
3332
|
+
let renders = 0;
|
|
3333
|
+
drawFrame(world, {}, () => { renders += 1; });
|
|
3334
|
+
camera.position.set(30, 30, 30);
|
|
3335
|
+
drawFrame(world, { orbitOwnModel: 'player' }, () => { renders += 1; });
|
|
3336
|
+
camera.position.set(0, 2.4, 0);
|
|
3337
|
+
node.visible = false;
|
|
3338
|
+
drawFrame(world, { orbitOwnModel: 'player' }, () => { renders += 1; });
|
|
3339
|
+
assert.equal(node.visible, false, 'the model hidden elsewhere remains hidden');
|
|
3340
|
+
node.visible = true;
|
|
3341
|
+
assert.equal(renders, 3, 'all draws render without reading the set');
|
|
3342
|
+
delete world.ownModelWith;
|
|
3343
|
+
checks += 1;
|
|
3344
|
+
}
|
|
3345
|
+
// What is written to `visible` during the render: a `true` is kept; a
|
|
3346
|
+
// pass that saves it and puts it back leaves the node shown (the value it
|
|
3347
|
+
// saved was this file's false); a `false` cannot be told from this file's
|
|
3348
|
+
// and is shown again (the accepted trade-off), a throw or not; reads
|
|
3349
|
+
// during it are false; a plain Group's own data property is as it was.
|
|
3350
|
+
{
|
|
3351
|
+
const plain = new THREE.Group();
|
|
3352
|
+
plain.position.set(0, 1, 0);
|
|
3353
|
+
const plainScene = new THREE.Scene();
|
|
3354
|
+
plainScene.add(plain);
|
|
3355
|
+
const w = { camera, scene: plainScene, nodes: new Map([['player', { node: plain }]]) };
|
|
3356
|
+
const own = () => Object.getOwnPropertyDescriptor(plain, 'visible');
|
|
3357
|
+
const want = own();
|
|
3358
|
+
const drawWith = (during) => {
|
|
3359
|
+
camera.position.set(0, 2.4, 0);
|
|
3360
|
+
const r = { orbitOwnModel: 'player' };
|
|
3361
|
+
drawFrame(w, r, () => during(plain));
|
|
3362
|
+
};
|
|
3363
|
+
drawWith((n) => assert.equal(n.visible, false, 'read as false during the render'));
|
|
3364
|
+
assert.deepEqual(own(), want, 'the own data property as it was');
|
|
3365
|
+
drawWith((n) => {
|
|
3366
|
+
const saved = n.visible;
|
|
3367
|
+
n.visible = false;
|
|
3368
|
+
n.visible = saved;
|
|
3369
|
+
});
|
|
3370
|
+
assert.deepEqual(own(), want, 'a pass that saves and restores visible: shown after it');
|
|
3371
|
+
// And a later keyless scene reusing the node draws it shown.
|
|
3372
|
+
let keyless;
|
|
3373
|
+
drawFrame(w, {}, () => (keyless = plain.visible));
|
|
3374
|
+
assert.equal(keyless, true, 'a keyless frame after it draws the node shown');
|
|
3375
|
+
drawWith((n) => (n.visible = true));
|
|
3376
|
+
assert.equal(plain.visible, true, 'a true written during the render is kept');
|
|
3377
|
+
drawWith((n) => (n.visible = false));
|
|
3378
|
+
assert.equal(plain.visible, true, 'a false written during the render: shown again (accepted)');
|
|
3379
|
+
assert.throws(() =>
|
|
3380
|
+
drawWith(() => {
|
|
3381
|
+
throw new Error('callback threw');
|
|
3382
|
+
})
|
|
3383
|
+
);
|
|
3384
|
+
assert.deepEqual(own(), want, 'shown after a throw');
|
|
3385
|
+
// Accepted: a copy of the node taken during the hidden render (clone,
|
|
3386
|
+
// a parent's clone, toJSON) copies it hidden, as for any node hidden
|
|
3387
|
+
// for a frame; the node itself is shown after the render.
|
|
3388
|
+
const parent = new THREE.Group();
|
|
3389
|
+
plainScene.add(parent);
|
|
3390
|
+
parent.add(plain);
|
|
3391
|
+
const got = {};
|
|
3392
|
+
drawWith((n) => {
|
|
3393
|
+
got.clone = n.clone();
|
|
3394
|
+
got.parentClone = parent.clone();
|
|
3395
|
+
got.json = n.toJSON();
|
|
3396
|
+
});
|
|
3397
|
+
assert.equal(got.clone.visible, false, 'a clone made during the hidden render copies visible: false');
|
|
3398
|
+
assert.equal(got.parentClone.children[0].visible, false, "and one made by a parent's clone");
|
|
3399
|
+
assert.equal(got.json.object.visible, false, 'toJSON during it writes visible: false');
|
|
3400
|
+
assert.deepEqual(own(), want, 'the node itself shown after the render');
|
|
3401
|
+
assert.ok(!Object.hasOwn(plain, 'clone') && !Object.hasOwn(plain, 'toJSON'), 'nothing put on the node');
|
|
3402
|
+
plainScene.add(plain);
|
|
3403
|
+
checks += 1;
|
|
3404
|
+
// A node that cannot be extended (preventExtensions) is hidden for the
|
|
3405
|
+
// render and shown after it, the render run, nothing thrown.
|
|
3406
|
+
{
|
|
3407
|
+
const sealed = new THREE.Group();
|
|
3408
|
+
sealed.position.set(0, 1, 0);
|
|
3409
|
+
const s2 = new THREE.Scene();
|
|
3410
|
+
s2.add(sealed);
|
|
3411
|
+
Object.preventExtensions(sealed);
|
|
3412
|
+
const w2 = { camera, scene: s2, nodes: new Map([['player', { node: sealed }]]) };
|
|
3413
|
+
camera.position.set(0, 2.4, 0);
|
|
3414
|
+
let ran;
|
|
3415
|
+
drawFrame(w2, { orbitOwnModel: 'player' }, () => (ran = sealed.visible));
|
|
3416
|
+
assert.equal(ran, false, 'a non-extensible node: the render ran with it hidden');
|
|
3417
|
+
assert.equal(sealed.visible, true, 'and it is shown after');
|
|
3418
|
+
// A render that throws on it still gives it back.
|
|
3419
|
+
assert.throws(() =>
|
|
3420
|
+
drawFrame(w2, { orbitOwnModel: 'player' }, () => {
|
|
3421
|
+
throw new Error('render failed');
|
|
3422
|
+
})
|
|
3423
|
+
);
|
|
3424
|
+
assert.equal(sealed.visible, true, 'shown after a throwing render');
|
|
3425
|
+
checks += 1;
|
|
3426
|
+
}
|
|
3427
|
+
// A `visible` that cannot be written is left alone.
|
|
3428
|
+
Object.defineProperty(plain, 'visible', { value: true, writable: false, enumerable: true, configurable: true });
|
|
3429
|
+
let saw;
|
|
3430
|
+
drawWith((n) => (saw = n.visible));
|
|
3431
|
+
assert.equal(saw, true, 'a read-only visible: drawn as is');
|
|
3432
|
+
checks += 1;
|
|
3433
|
+
}
|
|
3434
|
+
// Measured in the world: a node a deck keeps under a group of its own.
|
|
3435
|
+
{
|
|
3436
|
+
const root = new THREE.Scene();
|
|
3437
|
+
const group = new THREE.Group();
|
|
3438
|
+
const n = countedNode(0, 1, 0);
|
|
3439
|
+
root.add(group);
|
|
3440
|
+
group.add(n);
|
|
3441
|
+
root.add(camera);
|
|
3442
|
+
const w = { camera, scene: root, nodes: new Map([['player', { node: n }]]) };
|
|
3443
|
+
const drawAt = (gx, cx) => {
|
|
3444
|
+
group.position.set(gx, 0, 0);
|
|
3445
|
+
camera.position.set(cx, 2.4, 0);
|
|
3446
|
+
let saw;
|
|
3447
|
+
drawFrame(w, { orbitOwnModel: 'player' }, () => (saw = n.visible));
|
|
3448
|
+
return saw;
|
|
3449
|
+
};
|
|
3450
|
+
root.updateMatrixWorld();
|
|
3451
|
+
const before = n.matrixWorld.clone();
|
|
3452
|
+
const camBefore = camera.matrixWorld.clone();
|
|
3453
|
+
assert.equal(drawAt(5, 5), false, 'near in the world, 5 m off locally: hidden');
|
|
3454
|
+
assert.ok(before.equals(n.matrixWorld) && camBefore.equals(camera.matrixWorld), 'measuring writes no matrix');
|
|
3455
|
+
assert.equal(drawAt(5, 0), true, 'near locally, 5 m off in the world: shown');
|
|
3456
|
+
assert.equal(drawAt(-3, -3), false, 'the group moved since the last render: still measured where it is');
|
|
3457
|
+
// The scene not updating its matrices (matrixWorldAutoUpdate off): the
|
|
3458
|
+
// render draws the cached ones, and the choice is made on those, which
|
|
3459
|
+
// are not brought up to date.
|
|
3460
|
+
root.matrixWorldAutoUpdate = false;
|
|
3461
|
+
const cache = (gx, cx) => {
|
|
3462
|
+
group.position.set(gx, 0, 0);
|
|
3463
|
+
camera.position.set(cx, 2.4, 0);
|
|
3464
|
+
root.updateMatrixWorld(true);
|
|
3465
|
+
return [n.matrixWorld.clone(), camera.matrixWorld.clone()];
|
|
3466
|
+
};
|
|
3467
|
+
const [cachedNode, cachedCam] = cache(20, 20);
|
|
3468
|
+
assert.equal(drawAt(0, 50), false, 'drawn next to it (cached), 50 m off locally: hidden');
|
|
3469
|
+
assert.ok(n.matrixWorld.equals(cachedNode) && camera.matrixWorld.equals(cachedCam), 'the cached matrices are not updated');
|
|
3470
|
+
cache(20, 0);
|
|
3471
|
+
assert.equal(drawAt(0, 0), true, 'drawn 20 m off (cached), next to it locally: shown');
|
|
3472
|
+
// A camera with no parent is brought up to date by the renderer itself
|
|
3473
|
+
// (its own matrixWorldAutoUpdate), whatever the scene's.
|
|
3474
|
+
root.remove(camera);
|
|
3475
|
+
cache(0, 50);
|
|
3476
|
+
camera.updateMatrixWorld();
|
|
3477
|
+
assert.equal(drawAt(0, 0), false, 'a parentless camera moved next to it: measured where it is now');
|
|
3478
|
+
root.add(camera);
|
|
3479
|
+
root.matrixWorldAutoUpdate = true;
|
|
3480
|
+
checks += 1;
|
|
3481
|
+
root.remove(camera);
|
|
3482
|
+
checks += 1;
|
|
3483
|
+
}
|
|
3484
|
+
// The rendered scene under a parent of its own whose
|
|
3485
|
+
// matrixWorldAutoUpdate is off, the scene's own on: the renderer updates
|
|
3486
|
+
// from the scene (the parent's cached matrixWorld included), so that is
|
|
3487
|
+
// where the node is measured.
|
|
3488
|
+
{
|
|
3489
|
+
const outer = new THREE.Group();
|
|
3490
|
+
outer.matrixWorldAutoUpdate = false;
|
|
3491
|
+
const sc = new THREE.Scene();
|
|
3492
|
+
outer.add(sc);
|
|
3493
|
+
const n = countedNode(0, 1, 0);
|
|
3494
|
+
sc.add(n);
|
|
3495
|
+
outer.updateMatrixWorld(true);
|
|
3496
|
+
const w = { camera, scene: sc, nodes: new Map([['player', { node: n }]]) };
|
|
3497
|
+
camera.position.set(0, 2.4, 0);
|
|
3498
|
+
const drawn = () => {
|
|
3499
|
+
let saw;
|
|
3500
|
+
drawFrame(w, { orbitOwnModel: 'player' }, () => (saw = n.visible));
|
|
3501
|
+
return saw;
|
|
3502
|
+
};
|
|
3503
|
+
sc.position.set(10, 0, 0);
|
|
3504
|
+
assert.equal(drawn(), true, 'the scene moved to x=10 (the node cached at the origin): shown');
|
|
3505
|
+
sc.updateMatrixWorld();
|
|
3506
|
+
assert.ok(Math.abs(n.matrixWorld.elements[12] - 10) < 1e-9, 'the renderer does draw it at x=10');
|
|
3507
|
+
outer.matrixWorld.makeTranslation(-10, 0, 0);
|
|
3508
|
+
assert.equal(drawn(), false, "the scene's parent's cached matrix brings it back to the origin: hidden");
|
|
3509
|
+
sc.updateMatrixWorld();
|
|
3510
|
+
assert.ok(Math.abs(n.matrixWorld.elements[12]) < 1e-9, 'where the renderer draws it');
|
|
3511
|
+
// A node not in the rendered scene is not drawn, so not hidden.
|
|
3512
|
+
const elsewhere = countedNode(0, 1, 0);
|
|
3513
|
+
new THREE.Scene().add(elsewhere);
|
|
3514
|
+
const w2 = { camera, scene: sc, nodes: new Map([['player', { node: elsewhere }]]) };
|
|
3515
|
+
camera.position.set(0, 2.4, 0);
|
|
3516
|
+
let saw;
|
|
3517
|
+
drawFrame(w2, { orbitOwnModel: 'player' }, () => (saw = elsewhere.visible));
|
|
3518
|
+
assert.equal(saw, true, 'a node outside the rendered scene: not hidden');
|
|
3519
|
+
assert.equal(elsewhere.writes, 0, 'and not written');
|
|
3520
|
+
checks += 1;
|
|
3521
|
+
}
|
|
3522
|
+
// Through the runtime: the keyed Player names its actor each frame it
|
|
3523
|
+
// places the camera; a frame it does not (turned off, removed) names
|
|
3524
|
+
// none; a load drops a name not yet drawn. Keyless runtimes never name.
|
|
3525
|
+
const hidden = (mode) => {
|
|
3526
|
+
const h = makeRuntime(mode);
|
|
3527
|
+
const n = countedNode();
|
|
3528
|
+
const scene = new THREE.Scene();
|
|
3529
|
+
scene.add(n);
|
|
3530
|
+
const w = { camera: h.camera, scene, nodes: new Map([['player', { node: n }]]) };
|
|
3531
|
+
// A shell `h.wall` round the look point, as makeWorld's.
|
|
3532
|
+
h.runtime.physics3d.castRayFixedNormal = () => (h.wall ? { distance: h.wall, actorId: 'wall' } : null);
|
|
3533
|
+
h.runtime.physics3d.castBallFixed = (from, dir, max, radius) => (h.wall && h.wall - radius <= max ? { distance: Math.max(0, h.wall - radius), actorId: 'wall' } : null);
|
|
3534
|
+
h.runtime.physics3d.nearFixed = () => [];
|
|
3535
|
+
const d = makeDraws(() => n);
|
|
3536
|
+
h.draw = () => {
|
|
3537
|
+
const t = h.player()?.components.Transform;
|
|
3538
|
+
if (t) n.position.set(t.x, t.y, t.z);
|
|
3539
|
+
drawFrame(w, h.runtime, d.render);
|
|
3540
|
+
return d.seen.at(-1).visible;
|
|
3541
|
+
};
|
|
3542
|
+
h.step = () => {
|
|
3543
|
+
h.frame();
|
|
3544
|
+
return h.draw();
|
|
3545
|
+
};
|
|
3546
|
+
return { h, n };
|
|
3547
|
+
};
|
|
3548
|
+
{
|
|
3549
|
+
const { h, n } = hidden('orbit');
|
|
3550
|
+
for (let i = 0; i < 30; i += 1) assert.equal(h.step(), true, 'far out: shown');
|
|
3551
|
+
h.wall = 1.2;
|
|
3552
|
+
assert.equal(h.step(), false, 'a wall close behind (the camera at 0.95 m): hidden');
|
|
3553
|
+
assert.equal(n.visible, true);
|
|
3554
|
+
h.frame();
|
|
3555
|
+
assert.equal(h.runtime.orbitOwnModel, 'player', 'named by the placement');
|
|
3556
|
+
h.load('orbit');
|
|
3557
|
+
assert.equal(h.runtime.orbitOwnModel, undefined, 'a load drops the name');
|
|
3558
|
+
assert.equal(h.draw(), true, 'and that frame is drawn whole');
|
|
3559
|
+
assert.equal(h.step(), false, 'the next keyed frame names it again');
|
|
3560
|
+
h.player().components.Player.$enabled = false;
|
|
3561
|
+
assert.equal(h.step(), true, 'a Player turned off hides nothing');
|
|
3562
|
+
h.player().components.Player.$enabled = true;
|
|
3563
|
+
assert.equal(h.step(), false);
|
|
3564
|
+
delete h.player().components.Player;
|
|
3565
|
+
assert.equal(h.step(), true, 'a Player removed hides nothing');
|
|
3566
|
+
assert.equal(h.runtime.orbitOwnModel, undefined);
|
|
3567
|
+
h.load('off');
|
|
3568
|
+
h.wall = 0.5;
|
|
3569
|
+
h.camera.position.set(0, 1.5, 0);
|
|
3570
|
+
for (let i = 0; i < 10; i += 1) assert.equal(h.step(), true, 'a keyless scene after it: drawn whole');
|
|
3571
|
+
checks += 1;
|
|
3572
|
+
}
|
|
3573
|
+
for (const mode of ['off', 'rigid']) {
|
|
3574
|
+
const { h, n } = hidden(mode);
|
|
3575
|
+
const step = keylessInput(h);
|
|
3576
|
+
for (let i = 0; i < 240; i += 1) {
|
|
3577
|
+
h.frame(UNEVEN(i), [...step(i), ...(i % 90 < 40 ? ['KeyW'] : [])]);
|
|
3578
|
+
assert.equal(h.runtime.orbitOwnModel, undefined, `${mode}: never named`);
|
|
3579
|
+
h.draw();
|
|
3580
|
+
}
|
|
3581
|
+
assert.ok(!('orbitOwnModel' in h.runtime), `${mode}: the field is never written`);
|
|
3582
|
+
assert.equal(n.writes, 0, `${mode}: the node is never written`);
|
|
3583
|
+
checks += 1;
|
|
3584
|
+
}
|
|
3585
|
+
return checks;
|
|
3586
|
+
}
|
|
3587
|
+
|
|
3588
|
+
// `castRayFixed` on rapier itself: fixed bodies' solid colliders only, and
|
|
3589
|
+
// the orbit camera's own queries beside it.
|
|
2024
3590
|
async function fixedRay() {
|
|
2025
3591
|
if (!realRapier) return 0;
|
|
2026
3592
|
const { Physics3DSystem } = await import('../systems/physics3d.js?orbit-real');
|
|
@@ -2064,18 +3630,945 @@ async function fixedRay() {
|
|
|
2064
3630
|
// The ground is fixed and solid.
|
|
2065
3631
|
const down = scene.physics3d.castRayFixed(from, { x: 0, y: -1, z: 0 }, 20);
|
|
2066
3632
|
assert.ok(down && down.actorId === null && Math.abs(down.distance - 5) < 1e-3, 'the ground blocks');
|
|
3633
|
+
// Its result is what it always was, `{ distance, actorId }` and nothing
|
|
3634
|
+
// else (review 6: the orbit camera's normal is `castRayFixedNormal`'s).
|
|
3635
|
+
assert.deepEqual(Object.keys(hit), ['distance', 'actorId'], 'castRayFixed: distance and actorId only');
|
|
3636
|
+
assert.deepEqual(hit, { distance: hit.distance, actorId: 'wall' });
|
|
3637
|
+
assert.deepEqual(Object.keys(down), ['distance', 'actorId']);
|
|
2067
3638
|
// From inside a wall: at once.
|
|
2068
3639
|
assert.equal(scene.physics3d.castRayFixed({ x: 8, y: 5, z: 0 }, dir, 20).distance, 0);
|
|
3640
|
+
// `castRayFixedNormal`: the same hits, with the surface's normal facing
|
|
3641
|
+
// back along the ray.
|
|
3642
|
+
const hitN = scene.physics3d.castRayFixedNormal(from, dir, 20);
|
|
3643
|
+
assert.ok(hitN.actorId === 'wall' && hitN.distance === hit.distance, 'the same hit');
|
|
3644
|
+
const n = hitN.normal;
|
|
3645
|
+
assert.ok(Math.abs(n.x + 1) < 1e-6 && Math.abs(n.y) < 1e-6 && Math.abs(n.z) < 1e-6, `the wall faces the ray (${JSON.stringify(n)})`);
|
|
3646
|
+
assert.deepEqual(scene.physics3d.castRayFixedNormal(from, { x: 0, y: -1, z: 0 }, 20).normal, { x: 0, y: 1, z: 0 }, 'the ground faces up');
|
|
3647
|
+
assert.equal(scene.physics3d.castRayFixedNormal(from, dir, 7), null, 'nothing within reach');
|
|
3648
|
+
// The ball: the same filter, stopped its radius short of the wall's face
|
|
3649
|
+
// (to within 0.1 mm, rapier's own answer taken on to the face), and the
|
|
3650
|
+
// ground under it at a slant.
|
|
3651
|
+
const ball = scene.physics3d.castBallFixed(from, dir, 20, 0.5);
|
|
3652
|
+
assert.equal(ball.actorId, 'wall', 'castBallFixed passes the sensor, the dynamic and the kinematic body');
|
|
3653
|
+
assert.ok(Math.abs(ball.distance - 7) < 1e-4, `the ball's middle its radius off the face (${ball.distance})`);
|
|
3654
|
+
assert.ok(Math.abs(ball.normal.x + 1) < 1e-6, 'the face faces the ball');
|
|
3655
|
+
assert.equal(scene.physics3d.castBallFixed(from, dir, 6.9, 0.5), null, 'nothing within reach');
|
|
3656
|
+
assert.equal(scene.physics3d.castBallFixed(from, { x: -1, y: 0, z: 0 }, 20, 0.5), null, 'nothing that way');
|
|
3657
|
+
for (const pitch of [-80, -45, -20, -5]) {
|
|
3658
|
+
const slant = { x: 0, y: Math.sin(pitch * DEG), z: Math.cos(pitch * DEG) };
|
|
3659
|
+
const down = scene.physics3d.castBallFixed({ x: -5, y: 1.2, z: 0 }, slant, 40, 0.484);
|
|
3660
|
+
const y = 1.2 + slant.y * down.distance;
|
|
3661
|
+
assert.ok(down.actorId === null && Math.abs(y - 0.484) < 1e-4, `the ground at ${pitch} degrees: the ball's middle ${y} m up`);
|
|
3662
|
+
}
|
|
3663
|
+
assert.equal(scene.physics3d.castBallFixed(from, dir, 20, 0), null, 'no ball without a radius');
|
|
3664
|
+
// The fixed solids near a point: within reach or not, the dynamic body
|
|
3665
|
+
// passed, a point inside one, and an edge.
|
|
3666
|
+
const [nearWall, ...more] = scene.physics3d.nearFixed({ x: 7, y: 5, z: 0 }, 1);
|
|
3667
|
+
assert.equal(more.length, 0);
|
|
3668
|
+
assert.ok(nearWall.actorId === 'wall' && Math.abs(nearWall.distance - 0.5) < 1e-6 && Math.abs(nearWall.normal.x + 1) < 1e-6 && Math.abs(nearWall.point.x - 7.5) < 1e-6, `0.5 m off the wall's face (${JSON.stringify(nearWall)})`);
|
|
3669
|
+
assert.deepEqual(scene.physics3d.nearFixed({ x: 7, y: 5, z: 0 }, 0.4), [], 'nothing within 0.4 m');
|
|
3670
|
+
assert.deepEqual(scene.physics3d.nearFixed({ x: 4, y: 5, z: 0 }, 0.4), [], 'the dynamic body is passed');
|
|
3671
|
+
const inside = scene.physics3d.nearFixed({ x: 8, y: 5, z: 0 }, 1).find((f) => f.actorId === 'wall');
|
|
3672
|
+
assert.ok(inside.inside && inside.distance === 0 && inside.normal === null, 'inside the wall');
|
|
3673
|
+
// Below the wall's bottom edge: its nearest point is on the edge, and the
|
|
3674
|
+
// normal points from there to the point.
|
|
3675
|
+
const [edge] = scene.physics3d.nearFixed({ x: 7, y: 2.8, z: 0 }, 0.6);
|
|
3676
|
+
const r = Math.hypot(0.5, 0.2);
|
|
3677
|
+
assert.ok(edge.actorId === 'wall' && Math.abs(edge.distance - r) < 1e-5 && Math.abs(edge.normal.x + 0.5 / r) < 1e-5 && Math.abs(edge.normal.y + 0.2 / r) < 1e-5, `the wall's edge (${JSON.stringify(edge)})`);
|
|
3678
|
+
// The orbit camera on rapier's own ground.
|
|
3679
|
+
grounded(scene.physics3d);
|
|
2069
3680
|
system.dispose(scene);
|
|
2070
3681
|
assert.equal(scene.physics3d.castRayFixed(from, dir, 20), null, 'null after the world is gone');
|
|
3682
|
+
assert.equal(scene.physics3d.castBallFixed(from, dir, 20, 0.5), null);
|
|
3683
|
+
assert.deepEqual(scene.physics3d.nearFixed(from, 20), []);
|
|
3684
|
+
assert.equal(scene.physics3d.castRayFixedNormal(from, dir, 20), null);
|
|
2071
3685
|
return 1;
|
|
2072
3686
|
}
|
|
2073
3687
|
|
|
3688
|
+
// Rapier itself with these actors (boxes: a Transform at the middle, a
|
|
3689
|
+
// Shape `width` x `height` x `depth`) and its own ground, top at y = 0.
|
|
3690
|
+
export async function rapierWorld(actors) {
|
|
3691
|
+
const { Physics3DSystem } = await import('../systems/physics3d.js?orbit-real');
|
|
3692
|
+
const scene = { time: 0, data: {}, getActors: () => actors, getActor: (id) => actors.find((a) => a.id === id), forEachBehavior: () => {} };
|
|
3693
|
+
const system = new Physics3DSystem();
|
|
3694
|
+
system.attach(scene);
|
|
3695
|
+
for (let i = 0; i < 200 && !scene.physics3d.ready(); i += 1) {
|
|
3696
|
+
await new Promise((resolve) => setTimeout(resolve, 5));
|
|
3697
|
+
scene.time += FIXED;
|
|
3698
|
+
system.afterBehaviors(scene, FIXED);
|
|
3699
|
+
}
|
|
3700
|
+
assert.ok(scene.physics3d.ready(), 'rapier loaded');
|
|
3701
|
+
for (let i = 0; i < 3; i += 1) system.afterBehaviors(scene, FIXED);
|
|
3702
|
+
return { scene, system };
|
|
3703
|
+
}
|
|
3704
|
+
const wallBox = (id, x, z, width, depth) => ({
|
|
3705
|
+
id,
|
|
3706
|
+
components: {
|
|
3707
|
+
Transform: { x, y: 5, z, rotationX: 0, rotationY: 0, rotationZ: 0 },
|
|
3708
|
+
Shape: { kind: 'box', width, height: 200, depth, solid: true },
|
|
3709
|
+
},
|
|
3710
|
+
runtime: {},
|
|
3711
|
+
});
|
|
3712
|
+
|
|
3713
|
+
// A keyed world with this lens (near 0.1), its queries `api`'s.
|
|
3714
|
+
export function lensOn(api, fov, aspect) {
|
|
3715
|
+
const world = makeWorld('orbit');
|
|
3716
|
+
world.scene.data = { engine: { camera: { follow: 'rigid', control: 'orbit', fov } } };
|
|
3717
|
+
world.camera.fov = fov;
|
|
3718
|
+
world.camera.aspect = aspect;
|
|
3719
|
+
world.camera.near = 0.1;
|
|
3720
|
+
world.camera.updateProjectionMatrix();
|
|
3721
|
+
return queriesOf(world, api);
|
|
3722
|
+
}
|
|
3723
|
+
// The lens's stand-off, as Player.jsx `lensMargin` has it.
|
|
3724
|
+
function marginOf(fov, aspect) {
|
|
3725
|
+
const half = Math.tan((fov * DEG) / 2);
|
|
3726
|
+
return Math.max(0.25, 0.1 * Math.sqrt(1 + half * half + (aspect * half) ** 2) + 0.05);
|
|
3727
|
+
}
|
|
3728
|
+
|
|
3729
|
+
// Grazing lines (review 3): the camera stays its lens's margin off a surface
|
|
3730
|
+
// however flat its line meets it, at every lens and zoom, in a corner of two
|
|
3731
|
+
// walls and where the ground meets a wall, on rapier itself. The near
|
|
3732
|
+
// plane's corners (and middle) never cross a wall's face or the ground.
|
|
3733
|
+
async function grazing() {
|
|
3734
|
+
if (!realRapier) return 0;
|
|
3735
|
+
let checks = 0;
|
|
3736
|
+
const corner = new THREE.Vector3();
|
|
3737
|
+
// The near plane's farthest reach toward +x, +z and -y.
|
|
3738
|
+
const reachOf = (camera) => {
|
|
3739
|
+
camera.updateMatrixWorld();
|
|
3740
|
+
const most = { x: -Infinity, z: -Infinity, y: Infinity };
|
|
3741
|
+
for (const [x, y] of [[-1, -1], [1, -1], [1, 1], [-1, 1], [0, 0]]) {
|
|
3742
|
+
corner.set(x, y, -1).unproject(camera);
|
|
3743
|
+
most.x = Math.max(most.x, corner.x);
|
|
3744
|
+
most.z = Math.max(most.z, corner.z);
|
|
3745
|
+
most.y = Math.min(most.y, corner.y);
|
|
3746
|
+
}
|
|
3747
|
+
return most;
|
|
3748
|
+
};
|
|
3749
|
+
// One wall, its face at x = 0.8, 200 m long.
|
|
3750
|
+
{
|
|
3751
|
+
const { scene, system } = await rapierWorld([wallBox('wall', 1.3, 0, 1, 200)]);
|
|
3752
|
+
// The report: 120 degrees on 20:9, near 0.1, level, yaw -3, the
|
|
3753
|
+
// farthest zoom. It was at x = 0.546819 with a corner at 0.925958.
|
|
3754
|
+
{
|
|
3755
|
+
const world = lensOn(scene.physics3d, 120, 20 / 9);
|
|
3756
|
+
world.run(30);
|
|
3757
|
+
world.scene.persistent.camAngle = -3 * DEG;
|
|
3758
|
+
world.scene.cameraOrbit.pitch = 0;
|
|
3759
|
+
world.scene.cameraOrbit.range = FARTHEST;
|
|
3760
|
+
world.run(600);
|
|
3761
|
+
const reach = reachOf(world.camera);
|
|
3762
|
+
const x = world.camera.position.x;
|
|
3763
|
+
assert.ok(reach.x < 0.8, `the report: the near plane stays in front of the wall (a corner at x = ${reach.x.toFixed(6)}, the camera at ${x.toFixed(6)})`);
|
|
3764
|
+
assert.ok(Math.abs(0.8 - x - marginOf(120, 20 / 9)) < 1e-3, `held its margin off the wall, square to it (${(0.8 - x).toFixed(4)})`);
|
|
3765
|
+
checks += 1;
|
|
3766
|
+
}
|
|
3767
|
+
// Near grazing both ways round (and square on, pressed close), every
|
|
3768
|
+
// tilt, four zooms, two lenses on a wide and a tall screen, with the
|
|
3769
|
+
// player 0.8 m from the wall and with it against the wall (its capsule's
|
|
3770
|
+
// 0.35 m off, nearer than the widest lens's margin): every frame of the
|
|
3771
|
+
// sweep, settling included.
|
|
3772
|
+
const yaws = [...Array.from({ length: 21 }, (_, i) => i - 10), -30, -60, -90];
|
|
3773
|
+
for (const [fov, aspect, x0] of [[70, 20 / 9, 0], [70, 9 / 20, 0], [120, 20 / 9, 0], [120, 9 / 20, 0], [120, 20 / 9, 0.45], [70, 9 / 20, 0.45]]) {
|
|
3774
|
+
const world = lensOn(scene.physics3d, fov, aspect);
|
|
3775
|
+
world.body.pos.x = x0;
|
|
3776
|
+
world.actor.components.Transform.x = x0;
|
|
3777
|
+
world.run(30);
|
|
3778
|
+
for (const range of [NEAREST, RANGE0, 12, FARTHEST]) {
|
|
3779
|
+
for (let pitch = -80; pitch <= 80; pitch += 20) {
|
|
3780
|
+
for (const yaw of yaws) {
|
|
3781
|
+
world.scene.persistent.camAngle = yaw * DEG;
|
|
3782
|
+
world.scene.cameraOrbit.pitch = pitch * DEG;
|
|
3783
|
+
world.scene.cameraOrbit.range = range;
|
|
3784
|
+
for (let i = 0; i < 12; i += 1) {
|
|
3785
|
+
world.frame(UNEVEN(i));
|
|
3786
|
+
const reach = reachOf(world.camera);
|
|
3787
|
+
const where = `${fov} degrees, aspect ${aspect.toFixed(3)}, player at x = ${x0}, tilt ${pitch}, yaw ${yaw}, ${range} m, frame ${i}`;
|
|
3788
|
+
assert.ok(reach.x < 0.8, `${where}: a corner at x = ${reach.x.toFixed(4)}`);
|
|
3789
|
+
assert.ok(reach.y > 0, `${where}: a corner at y = ${reach.y.toFixed(4)}`);
|
|
3790
|
+
}
|
|
3791
|
+
checks += 1;
|
|
3792
|
+
}
|
|
3793
|
+
}
|
|
3794
|
+
}
|
|
3795
|
+
}
|
|
3796
|
+
system.dispose(scene);
|
|
3797
|
+
}
|
|
3798
|
+
// A corner: a second wall with its face at z = 3 across the first one's
|
|
3799
|
+
// end, and the ground under both. Toward the corner at every tilt.
|
|
3800
|
+
{
|
|
3801
|
+
const { scene, system } = await rapierWorld([wallBox('wall', 1.3, 0, 1, 200), wallBox('end', 0, 3.5, 200, 1)]);
|
|
3802
|
+
for (const [fov, aspect] of [[70, 20 / 9], [120, 20 / 9], [120, 9 / 20]]) {
|
|
3803
|
+
const world = lensOn(scene.physics3d, fov, aspect);
|
|
3804
|
+
world.run(30);
|
|
3805
|
+
for (const range of [RANGE0, FARTHEST]) {
|
|
3806
|
+
for (let pitch = -80; pitch <= 80; pitch += 10) {
|
|
3807
|
+
for (let yaw = -88; yaw <= -1; yaw += 3) {
|
|
3808
|
+
world.scene.persistent.camAngle = yaw * DEG;
|
|
3809
|
+
world.scene.cameraOrbit.pitch = pitch * DEG;
|
|
3810
|
+
world.scene.cameraOrbit.range = range;
|
|
3811
|
+
for (let i = 0; i < 12; i += 1) {
|
|
3812
|
+
world.frame(UNEVEN(i));
|
|
3813
|
+
const reach = reachOf(world.camera);
|
|
3814
|
+
const where = `corner: ${fov} degrees, aspect ${aspect.toFixed(3)}, tilt ${pitch}, yaw ${yaw}, ${range} m, frame ${i}`;
|
|
3815
|
+
assert.ok(reach.x < 0.8 && reach.z < 3 && reach.y > 0, `${where}: the near plane reaches ${JSON.stringify(reach)}`);
|
|
3816
|
+
}
|
|
3817
|
+
checks += 1;
|
|
3818
|
+
}
|
|
3819
|
+
}
|
|
3820
|
+
}
|
|
3821
|
+
}
|
|
3822
|
+
system.dispose(scene);
|
|
3823
|
+
}
|
|
3824
|
+
// Review 4: the camera held off the wall must not be behind something
|
|
3825
|
+
// else. The review's case: 120 degrees on 20:9, level, yaw -3, 12 m, the
|
|
3826
|
+
// wall's face at x = 0.8 and a thin post (x 0.1 to 0.22, z 5.75 to 6.25)
|
|
3827
|
+
// beside the camera's line (the axis-ray push of review 3 moved the camera
|
|
3828
|
+
// to x = 0.316 at z = 12, behind it). Settled, for 240 frames, the line
|
|
3829
|
+
// from the look point to the camera meets nothing, and the camera does
|
|
3830
|
+
// not move.
|
|
3831
|
+
{
|
|
3832
|
+
const { scene, system } = await rapierWorld([wallBox('wall', 1.3, 0, 1, 200), wallBox('post', 0.16, 6, 0.12, 0.5)]);
|
|
3833
|
+
const cast = scene.physics3d.castRayFixed;
|
|
3834
|
+
const world = lensOn(scene.physics3d, 120, 20 / 9);
|
|
3835
|
+
world.run(30);
|
|
3836
|
+
world.scene.persistent.camAngle = -3 * DEG;
|
|
3837
|
+
world.scene.cameraOrbit.pitch = 0;
|
|
3838
|
+
world.scene.cameraOrbit.range = 12;
|
|
3839
|
+
world.run(600);
|
|
3840
|
+
const settled = { ...world.camera.position };
|
|
3841
|
+
const dir = { x: 0, y: 0, z: 0 };
|
|
3842
|
+
for (let i = 0; i < 240; i += 1) {
|
|
3843
|
+
world.frame(FIXED);
|
|
3844
|
+
const t = world.actor.components.Transform;
|
|
3845
|
+
const from = { x: t.x, y: t.y + LOOK_HEIGHT, z: t.z };
|
|
3846
|
+
const p = world.camera.position;
|
|
3847
|
+
const length = Math.hypot(p.x - from.x, p.y - from.y, p.z - from.z);
|
|
3848
|
+
dir.x = (p.x - from.x) / length;
|
|
3849
|
+
dir.y = (p.y - from.y) / length;
|
|
3850
|
+
dir.z = (p.z - from.z) / length;
|
|
3851
|
+
const hit = cast(from, dir, length);
|
|
3852
|
+
const where = `the post: frame ${i}, the camera at (${p.x.toFixed(4)}, ${p.y.toFixed(4)}, ${p.z.toFixed(4)})`;
|
|
3853
|
+
assert.ok(!hit, `${where}: its line to the player meets ${hit?.actorId} at ${hit?.distance?.toFixed(4)} m`);
|
|
3854
|
+
const moved = Math.hypot(p.x - settled.x, p.y - settled.y, p.z - settled.z);
|
|
3855
|
+
assert.ok(moved < 1e-9, `${where}: moved ${moved} from where it settled`);
|
|
3856
|
+
assert.ok(reachOf(world.camera).x < 0.8, `${where}: the near plane stays in front of the wall`);
|
|
3857
|
+
}
|
|
3858
|
+
checks += 1;
|
|
3859
|
+
system.dispose(scene);
|
|
3860
|
+
}
|
|
3861
|
+
return checks;
|
|
3862
|
+
}
|
|
3863
|
+
|
|
3864
|
+
// A box `min` to `max`, fixed and solid, and how far a point is from it.
|
|
3865
|
+
const solidBox = ({ id, min, max }) => ({
|
|
3866
|
+
id,
|
|
3867
|
+
components: {
|
|
3868
|
+
Transform: { x: (min.x + max.x) / 2, y: (min.y + max.y) / 2, z: (min.z + max.z) / 2, rotationX: 0, rotationY: 0, rotationZ: 0 },
|
|
3869
|
+
Shape: { kind: 'box', width: max.x - min.x, height: max.y - min.y, depth: max.z - min.z, solid: true },
|
|
3870
|
+
},
|
|
3871
|
+
runtime: {},
|
|
3872
|
+
});
|
|
3873
|
+
const boxGap = (p, { min, max }) =>
|
|
3874
|
+
Math.hypot(Math.max(min.x - p.x, 0, p.x - max.x), Math.max(min.y - p.y, 0, p.y - max.y), Math.max(min.z - p.z, 0, p.z - max.z));
|
|
3875
|
+
|
|
3876
|
+
// Review 5: the camera let back out once what held it is gone. 120 degrees
|
|
3877
|
+
// on 20:9, level, yaw -3, 12 m; two separate boxes beside the camera's line
|
|
3878
|
+
// and a third across it that holds the camera in, settled, then removed.
|
|
3879
|
+
// `popRun` records every frame after the removal: where the camera is, how
|
|
3880
|
+
// far out from the look point, and how far it is from each box and the
|
|
3881
|
+
// ground, measured on the boxes themselves. The first record is the
|
|
3882
|
+
// settled frame before the removal.
|
|
3883
|
+
export const POP_LAYOUT = {
|
|
3884
|
+
boxes: [
|
|
3885
|
+
{ id: 'a', min: { x: 0.42, y: 0, z: 4.56 }, max: { x: 1.6, y: 2.43, z: 7.27 } },
|
|
3886
|
+
{ id: 'b', min: { x: -1.6, y: 0, z: 5.2 }, max: { x: 0.06, y: 1.33, z: 7.72 } },
|
|
3887
|
+
],
|
|
3888
|
+
blocker: { id: 'blocker', min: { x: -1, y: 0, z: 2.03 }, max: { x: 1, y: 3, z: 2.43 } },
|
|
3889
|
+
};
|
|
3890
|
+
export async function popRun(layout = POP_LAYOUT, frames = 240) {
|
|
3891
|
+
const actors = [...layout.boxes, layout.blocker].map(solidBox);
|
|
3892
|
+
const { scene, system } = await rapierWorld(actors);
|
|
3893
|
+
const world = lensOn(scene.physics3d, 120, 20 / 9);
|
|
3894
|
+
world.run(30);
|
|
3895
|
+
world.scene.persistent.camAngle = -3 * DEG;
|
|
3896
|
+
world.scene.cameraOrbit.pitch = 0;
|
|
3897
|
+
world.scene.cameraOrbit.range = 12;
|
|
3898
|
+
world.run(600);
|
|
3899
|
+
const t = world.actor.components.Transform;
|
|
3900
|
+
const p = world.camera.position;
|
|
3901
|
+
const note = () => {
|
|
3902
|
+
const out = Math.hypot(p.x - t.x, p.y - (t.y + LOOK_HEIGHT), p.z - t.z);
|
|
3903
|
+
const gaps = Object.fromEntries(layout.boxes.map((box) => [box.id, boxGap(p, box)]));
|
|
3904
|
+
return { p: { x: p.x, y: p.y, z: p.z }, out, gaps: { ...gaps, ground: p.y } };
|
|
3905
|
+
};
|
|
3906
|
+
const seen = [note()];
|
|
3907
|
+
actors.splice(actors.findIndex((a) => a.id === layout.blocker.id), 1);
|
|
3908
|
+
system.afterBehaviors(scene, FIXED);
|
|
3909
|
+
for (let i = 0; i < frames; i += 1) {
|
|
3910
|
+
world.frame(FIXED);
|
|
3911
|
+
seen.push(note());
|
|
3912
|
+
}
|
|
3913
|
+
system.dispose(scene);
|
|
3914
|
+
return seen;
|
|
3915
|
+
}
|
|
3916
|
+
const popAt = (f, i) => `review 5: ${i === 0 ? 'settled, before the removal' : `frame ${i} after the removal`}, the camera at (${f.p.x.toFixed(6)}, ${f.p.y.toFixed(6)}, ${f.p.z.toFixed(6)})`;
|
|
3917
|
+
|
|
3918
|
+
// P1: the camera is its lens's margin off both boxes and the ground on
|
|
3919
|
+
// every frame (the review's case left it 8 mm off one; on 38441228 this
|
|
3920
|
+
// one comes within 34 mm of a box).
|
|
3921
|
+
export async function popClear(seen = null) {
|
|
3922
|
+
if (!realRapier) return 0;
|
|
3923
|
+
const frames = seen ?? (await popRun());
|
|
3924
|
+
const margin = marginOf(120, 20 / 9);
|
|
3925
|
+
let worst = null;
|
|
3926
|
+
frames.forEach((f, i) => {
|
|
3927
|
+
for (const [id, gap] of Object.entries(f.gaps)) if (!worst || gap < worst.gap) worst = { f, i, id, gap };
|
|
3928
|
+
});
|
|
3929
|
+
const { f, i, id, gap } = worst;
|
|
3930
|
+
assert.ok(gap >= margin - 1e-3, `${popAt(f, i)}: ${(gap * 1000).toFixed(2)} mm off ${id}, want the margin, ${(margin * 1000).toFixed(2)} mm`);
|
|
3931
|
+
return 1;
|
|
3932
|
+
}
|
|
3933
|
+
|
|
3934
|
+
// P2: no frame moves the camera farther than easing out at 6/s takes it
|
|
3935
|
+
// from where it was drawn (the review's case jumped 3.985 m in a frame; on
|
|
3936
|
+
// 38441228 this one jumps 2.231 m, 1.6 m more than easing allows, once the
|
|
3937
|
+
// pull that held it stops); a snap in is allowed, and the camera stays on
|
|
3938
|
+
// its line meanwhile.
|
|
3939
|
+
export async function popSteady(seen = null) {
|
|
3940
|
+
if (!realRapier) return 0;
|
|
3941
|
+
const frames = seen ?? (await popRun());
|
|
3942
|
+
let worst = null;
|
|
3943
|
+
for (let i = 1; i < frames.length; i += 1) {
|
|
3944
|
+
const [was, now] = [frames[i - 1], frames[i]];
|
|
3945
|
+
const easing = Math.max(0, 12 - was.out) * (1 - Math.exp(-6 * FIXED));
|
|
3946
|
+
const step = Math.hypot(now.p.x - was.p.x, now.p.y - was.p.y, now.p.z - was.p.z);
|
|
3947
|
+
// Past what easing out allows: outward, or sideways beyond a snap in.
|
|
3948
|
+
const over = Math.max(now.out - was.out - easing, step - easing - Math.max(0, was.out - now.out));
|
|
3949
|
+
if (!worst || over > worst.over) worst = { i, now, step, easing, over };
|
|
3950
|
+
}
|
|
3951
|
+
const { i, now, step, easing, over } = worst;
|
|
3952
|
+
assert.ok(over <= 1e-6, `${popAt(now, i)}: moved ${step.toFixed(6)} m in a frame, ${over.toFixed(6)} m past what easing out at 6/s allows (${easing.toFixed(6)})`);
|
|
3953
|
+
return 1;
|
|
3954
|
+
}
|
|
3955
|
+
|
|
3956
|
+
// Review 6: corners. A slab of rapier (a box `half` its size each way,
|
|
3957
|
+
// turned `turn` degrees about y, its middle at `middle`) and how far a point
|
|
3958
|
+
// is from it, measured on the box itself; `inside` when a point is in it.
|
|
3959
|
+
const slab = (id, middle, half, turn = 0) => {
|
|
3960
|
+
const c = Math.cos(turn * DEG);
|
|
3961
|
+
const s = Math.sin(turn * DEG);
|
|
3962
|
+
const local = (p) => {
|
|
3963
|
+
const x = p.x - middle.x;
|
|
3964
|
+
const z = p.z - middle.z;
|
|
3965
|
+
return { x: x * c - z * s, y: p.y - middle.y, z: x * s + z * c };
|
|
3966
|
+
};
|
|
3967
|
+
return {
|
|
3968
|
+
id,
|
|
3969
|
+
actor: {
|
|
3970
|
+
id,
|
|
3971
|
+
components: {
|
|
3972
|
+
Transform: { ...middle, rotationX: 0, rotationY: turn, rotationZ: 0 },
|
|
3973
|
+
Shape: { kind: 'box', width: 2 * half.x, height: 2 * half.y, depth: 2 * half.z, solid: true },
|
|
3974
|
+
},
|
|
3975
|
+
runtime: {},
|
|
3976
|
+
},
|
|
3977
|
+
gap: (p) => {
|
|
3978
|
+
const l = local(p);
|
|
3979
|
+
return Math.hypot(Math.max(Math.abs(l.x) - half.x, 0), Math.max(Math.abs(l.y) - half.y, 0), Math.max(Math.abs(l.z) - half.z, 0));
|
|
3980
|
+
},
|
|
3981
|
+
inside: (p) => {
|
|
3982
|
+
const l = local(p);
|
|
3983
|
+
return Math.abs(l.x) < half.x && Math.abs(l.y) < half.y && Math.abs(l.z) < half.z;
|
|
3984
|
+
},
|
|
3985
|
+
};
|
|
3986
|
+
};
|
|
3987
|
+
// A wall 1 m thick, 200 m long and high, its face 0.35 m from the player at
|
|
3988
|
+
// the origin (its capsule's radius: the player pressed to it), the face's
|
|
3989
|
+
// outward normal at `angle` degrees round from +x toward +z.
|
|
3990
|
+
const wallFacing = (id, angle) => {
|
|
3991
|
+
const n = { x: Math.cos(angle * DEG), z: Math.sin(angle * DEG) };
|
|
3992
|
+
return slab(id, { x: -0.85 * n.x, y: 5, z: -0.85 * n.z }, { x: 0.5, y: 100, z: 100 }, 180 - angle);
|
|
3993
|
+
};
|
|
3994
|
+
// A ceiling over the player's head, its underside 0.35 m above the look
|
|
3995
|
+
// point.
|
|
3996
|
+
const ceiling = () => slab('ceiling', { x: 0, y: FLOOR + LOOK_HEIGHT + 0.35 + 0.5, z: 0 }, { x: 100, y: 0.5, z: 100 });
|
|
3997
|
+
|
|
3998
|
+
// The player pressed into a corner, the camera turned every way round it,
|
|
3999
|
+
// up and down, near and far, at 120 degrees on 20:9: on every frame the
|
|
4000
|
+
// camera is its lens's margin (less 0.1 mm) off every slab and the ground,
|
|
4001
|
+
// and no corner
|
|
4002
|
+
// of the near plane (nor its middle) is inside a slab or under the ground.
|
|
4003
|
+
// Returns the nearest it came, less the margin, for the report.
|
|
4004
|
+
async function cornered(slabs, label) {
|
|
4005
|
+
const { scene, system } = await rapierWorld(slabs.map((x) => x.actor));
|
|
4006
|
+
const world = lensOn(scene.physics3d, 120, 20 / 9);
|
|
4007
|
+
const margin = marginOf(120, 20 / 9);
|
|
4008
|
+
const camera = world.camera;
|
|
4009
|
+
const near = new THREE.Vector3();
|
|
4010
|
+
world.run(30);
|
|
4011
|
+
let least = Infinity;
|
|
4012
|
+
for (const range of [12, RANGE0]) {
|
|
4013
|
+
for (const pitch of [-30, 0, 40]) {
|
|
4014
|
+
for (let yaw = -150; yaw <= 180; yaw += 30) {
|
|
4015
|
+
world.scene.persistent.camAngle = yaw * DEG;
|
|
4016
|
+
world.scene.cameraOrbit.pitch = pitch * DEG;
|
|
4017
|
+
world.scene.cameraOrbit.range = range;
|
|
4018
|
+
for (let i = 0; i < 20; i += 1) {
|
|
4019
|
+
world.frame(UNEVEN(i));
|
|
4020
|
+
const p = camera.position;
|
|
4021
|
+
const where = `${label}: tilt ${pitch}, yaw ${yaw}, ${range} m, frame ${i}, the camera at (${p.x.toFixed(4)}, ${p.y.toFixed(4)}, ${p.z.toFixed(4)})`;
|
|
4022
|
+
for (const x of slabs) {
|
|
4023
|
+
const gap = x.gap(p);
|
|
4024
|
+
least = Math.min(least, gap - margin);
|
|
4025
|
+
assert.ok(gap >= margin - 1e-4, `${where}: ${(gap * 1000).toFixed(2)} mm off ${x.id}, want ${(margin * 1000).toFixed(2)}`);
|
|
4026
|
+
}
|
|
4027
|
+
least = Math.min(least, p.y - margin);
|
|
4028
|
+
assert.ok(p.y >= margin - 1e-4, `${where}: ${p.y} m off the ground`);
|
|
4029
|
+
camera.updateMatrixWorld();
|
|
4030
|
+
for (const [cx, cy] of [[-1, -1], [1, -1], [1, 1], [-1, 1], [0, 0]]) {
|
|
4031
|
+
near.set(cx, cy, -1).unproject(camera);
|
|
4032
|
+
const into = slabs.find((x) => x.inside(near));
|
|
4033
|
+
assert.ok(!into && near.y > 0, `${where}: the near plane's corner (${cx}, ${cy}) is inside ${into?.id ?? 'the ground'}`);
|
|
4034
|
+
}
|
|
4035
|
+
}
|
|
4036
|
+
}
|
|
4037
|
+
}
|
|
4038
|
+
}
|
|
4039
|
+
system.dispose(scene);
|
|
4040
|
+
return least;
|
|
4041
|
+
}
|
|
4042
|
+
|
|
4043
|
+
// Two walls meeting at every angle from 30 to 150 degrees, the player in the
|
|
4044
|
+
// corner (review 6's case is 60: the moves off each wall undid each other
|
|
4045
|
+
// and the camera was left 8.66 mm off a wall); and three surfaces at once:
|
|
4046
|
+
// two walls square to each other under a ceiling, and the 60 degree corner
|
|
4047
|
+
// under it.
|
|
4048
|
+
export async function corners() {
|
|
4049
|
+
if (!realRapier) return 0;
|
|
4050
|
+
let checks = 0;
|
|
4051
|
+
corners.least = {};
|
|
4052
|
+
for (let wedge = 30; wedge <= 150; wedge += 15) {
|
|
4053
|
+
corners.least[wedge] = await cornered([wallFacing('a', 180), wallFacing('b', 360 - wedge)], `a ${wedge} degree corner`);
|
|
4054
|
+
checks += 1;
|
|
4055
|
+
}
|
|
4056
|
+
corners.least.square = await cornered([wallFacing('a', 180), wallFacing('b', 270), ceiling()], 'two square walls and a ceiling');
|
|
4057
|
+
corners.least.sixty = await cornered([wallFacing('a', 180), wallFacing('b', 300), ceiling()], 'a 60 degree corner and a ceiling');
|
|
4058
|
+
return checks + 2;
|
|
4059
|
+
}
|
|
4060
|
+
|
|
4061
|
+
// A gap narrower than twice the margin (two walls 0.7 m apart, the player
|
|
4062
|
+
// between them, 120 degrees on 20:9). No place there keeps the lens's near
|
|
4063
|
+
// plane out of both walls, and it is accepted that the lens cuts into them
|
|
4064
|
+
// (Roblox's camera clips there too; the near plane is not shrunk). What is
|
|
4065
|
+
// guaranteed, and all this asserts: the camera point itself is never inside
|
|
4066
|
+
// a wall, nothing is NaN, and a settled camera stays where it is.
|
|
4067
|
+
async function narrowGapStable() {
|
|
4068
|
+
if (!realRapier) return 0;
|
|
4069
|
+
const walls = [wallFacing('a', 180), wallFacing('b', 0)];
|
|
4070
|
+
const { scene, system } = await rapierWorld(walls.map((x) => x.actor));
|
|
4071
|
+
const world = lensOn(scene.physics3d, 120, 20 / 9);
|
|
4072
|
+
const p = world.camera.position;
|
|
4073
|
+
world.run(30);
|
|
4074
|
+
for (const pitch of [-30, 0, 40]) {
|
|
4075
|
+
for (let yaw = -150; yaw <= 180; yaw += 30) {
|
|
4076
|
+
world.scene.persistent.camAngle = yaw * DEG;
|
|
4077
|
+
world.scene.cameraOrbit.pitch = pitch * DEG;
|
|
4078
|
+
world.scene.cameraOrbit.range = 12;
|
|
4079
|
+
const where = (i) => `a narrow gap: tilt ${pitch}, yaw ${yaw}, frame ${i}, the camera at (${p.x}, ${p.y}, ${p.z})`;
|
|
4080
|
+
for (let i = 0; i < 120; i += 1) {
|
|
4081
|
+
world.frame(UNEVEN(i));
|
|
4082
|
+
assert.ok([p.x, p.y, p.z, ...world.camera.quaternion.toArray()].every(Number.isFinite), `${where(i)}: not a number`);
|
|
4083
|
+
for (const x of walls) assert.ok(!x.inside(p) && x.gap(p) > 0, `${where(i)}: inside ${x.id}`);
|
|
4084
|
+
}
|
|
4085
|
+
const settled = { x: p.x, y: p.y, z: p.z };
|
|
4086
|
+
for (let i = 0; i < 60; i += 1) {
|
|
4087
|
+
world.frame(FIXED);
|
|
4088
|
+
const moved = Math.hypot(p.x - settled.x, p.y - settled.y, p.z - settled.z);
|
|
4089
|
+
assert.ok(moved < 1e-9, `${where(120 + i)}: moved ${moved} after settling`);
|
|
4090
|
+
}
|
|
4091
|
+
}
|
|
4092
|
+
}
|
|
4093
|
+
system.dispose(scene);
|
|
4094
|
+
return 1;
|
|
4095
|
+
}
|
|
4096
|
+
|
|
4097
|
+
// Review 7: a wall the player stands near is removed. The camera, held by
|
|
4098
|
+
// it, eases back out measured from the look point: no frame takes it
|
|
4099
|
+
// farther out than easing at 6/s from where it was drawn allows, though the
|
|
4100
|
+
// ball's start moves back to the look point as the wall goes. The review's
|
|
4101
|
+
// case is a wall face 0.5 m off with the camera at -60 degrees (it went out
|
|
4102
|
+
// 1.161 m in the first frame where 1.139 is allowed); also nearer and
|
|
4103
|
+
// farther faces and other angles.
|
|
4104
|
+
export async function releaseEase() {
|
|
4105
|
+
if (!realRapier) return 0;
|
|
4106
|
+
let checks = 0;
|
|
4107
|
+
for (const face of [0.36, 0.42, 0.5, 0.6]) {
|
|
4108
|
+
for (const yaw of [-30, -45, -60, -80]) {
|
|
4109
|
+
const walls = [wallFacing('a', 180)];
|
|
4110
|
+
walls[0].actor.components.Transform.x += face - 0.35;
|
|
4111
|
+
const actors = walls.map((x) => x.actor);
|
|
4112
|
+
const { scene, system } = await rapierWorld(actors);
|
|
4113
|
+
const world = lensOn(scene.physics3d, 120, 20 / 9);
|
|
4114
|
+
world.run(30);
|
|
4115
|
+
world.scene.cameraOrbit.pitch = 0;
|
|
4116
|
+
world.scene.cameraOrbit.range = 12;
|
|
4117
|
+
world.scene.persistent.camAngle = yaw * DEG;
|
|
4118
|
+
world.run(600);
|
|
4119
|
+
const t = world.actor.components.Transform;
|
|
4120
|
+
const p = world.camera.position;
|
|
4121
|
+
const out = () => Math.hypot(p.x - t.x, p.y - (t.y + LOOK_HEIGHT), p.z - t.z);
|
|
4122
|
+
actors.length = 0;
|
|
4123
|
+
system.afterBehaviors(scene, FIXED);
|
|
4124
|
+
let before = out();
|
|
4125
|
+
for (let i = 0; i < 90; i += 1) {
|
|
4126
|
+
world.frame(FIXED);
|
|
4127
|
+
const now = out();
|
|
4128
|
+
const allowed = Math.max(0, 12 - before) * (1 - Math.exp(-6 * FIXED));
|
|
4129
|
+
assert.ok(now - before <= allowed + 1e-9, `review 7: a face ${face} m off, yaw ${yaw}, frame ${i} after the removal: out ${(now - before).toFixed(6)} m, easing at 6/s allows ${allowed.toFixed(6)}`);
|
|
4130
|
+
before = now;
|
|
4131
|
+
}
|
|
4132
|
+
assert.ok(Math.abs(out() - 12) < 0.05, `review 7: a face ${face} m off, yaw ${yaw}: back out (${out()})`);
|
|
4133
|
+
system.dispose(scene);
|
|
4134
|
+
checks += 1;
|
|
4135
|
+
}
|
|
4136
|
+
}
|
|
4137
|
+
return checks;
|
|
4138
|
+
}
|
|
4139
|
+
|
|
4140
|
+
// Review 8, P2: a box beside the look point (its face 0.35 m off, the
|
|
4141
|
+
// camera not held by it but its start moved off it) is removed. The camera,
|
|
4142
|
+
// drawn short of its distance by that move, eases back out at 6/s too (it
|
|
4143
|
+
// went out 0.0616 m in a frame where 0.0059 m is allowed); at a few angles
|
|
4144
|
+
// and with the box nearer and farther.
|
|
4145
|
+
export async function releaseBeside() {
|
|
4146
|
+
if (!realRapier) return 0;
|
|
4147
|
+
let checks = 0;
|
|
4148
|
+
for (const face of [0.35, 0.42, 0.5]) {
|
|
4149
|
+
for (const yaw of [-160, -120, 170, 135]) {
|
|
4150
|
+
const actors = [solidBox({ id: 'box', min: { x: face, y: 0, z: 0 }, max: { x: face + 1, y: 5, z: 2 } })];
|
|
4151
|
+
const { scene, system } = await rapierWorld(actors);
|
|
4152
|
+
const world = lensOn(scene.physics3d, 120, 20 / 9);
|
|
4153
|
+
world.run(30);
|
|
4154
|
+
world.scene.persistent.camAngle = yaw * DEG;
|
|
4155
|
+
world.scene.cameraOrbit.pitch = 0;
|
|
4156
|
+
world.scene.cameraOrbit.range = 12;
|
|
4157
|
+
world.run(600);
|
|
4158
|
+
const t = world.actor.components.Transform;
|
|
4159
|
+
const p = world.camera.position;
|
|
4160
|
+
const out = () => Math.hypot(p.x - t.x, p.y - (t.y + LOOK_HEIGHT), p.z - t.z);
|
|
4161
|
+
actors.length = 0;
|
|
4162
|
+
system.afterBehaviors(scene, FIXED);
|
|
4163
|
+
let before = out();
|
|
4164
|
+
for (let i = 0; i < 90; i += 1) {
|
|
4165
|
+
world.frame(FIXED);
|
|
4166
|
+
const now = out();
|
|
4167
|
+
const allowed = Math.max(0, 12 - before) * (1 - Math.exp(-6 * FIXED));
|
|
4168
|
+
// (The last 0.1 mm is let go at once: CAMERA_OUT_DONE.)
|
|
4169
|
+
assert.ok(now - before <= allowed + 1e-4, `review 8: a box ${face} m off, yaw ${yaw}, frame ${i} after the removal: out ${(now - before).toFixed(6)} m, easing at 6/s allows ${allowed.toFixed(6)}`);
|
|
4170
|
+
before = now;
|
|
4171
|
+
}
|
|
4172
|
+
system.dispose(scene);
|
|
4173
|
+
checks += 1;
|
|
4174
|
+
}
|
|
4175
|
+
}
|
|
4176
|
+
return checks;
|
|
4177
|
+
}
|
|
4178
|
+
|
|
4179
|
+
// A seeded random number source (mulberry32).
|
|
4180
|
+
function seeded(seed) {
|
|
4181
|
+
let state = seed >>> 0;
|
|
4182
|
+
return () => {
|
|
4183
|
+
state = (state + 0x6d2b79f5) | 0;
|
|
4184
|
+
let t = Math.imul(state ^ (state >>> 15), 1 | state);
|
|
4185
|
+
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
|
|
4186
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
4187
|
+
};
|
|
4188
|
+
}
|
|
4189
|
+
|
|
4190
|
+
// Review 8, P1: rapier's sweep can miss a box outright. Random boxes, one or
|
|
4191
|
+
// two, turned any way about y, around a player whose look point is its
|
|
4192
|
+
// lens's margin clear of them; random yaws (mostly toward a box) and tilts, 70 and 120 degree
|
|
4193
|
+
// lenses on 16:9 and 20:9 screens, every frame as the camera swings round
|
|
4194
|
+
// to them: the camera is the margin (less 1 mm) off every box and the
|
|
4195
|
+
// ground, and no point of a 21 x 21 grid over the near plane is inside a
|
|
4196
|
+
// box. Seeded, so the same cases run every time. The review's case (one box,
|
|
4197
|
+
// yaw 5.0856, tilt 0.5191, 120 degrees on 20:9, 47 frames) is the first.
|
|
4198
|
+
export async function randomBoxes(cases = 120, seed = 8, withReview = true) {
|
|
4199
|
+
if (!realRapier) return 0;
|
|
4200
|
+
const random = seeded(seed);
|
|
4201
|
+
const between = (a, b) => a + (b - a) * random();
|
|
4202
|
+
const grid = new THREE.Vector3();
|
|
4203
|
+
const lookAt = { x: 0, y: FLOOR + LOOK_HEIGHT, z: 0 };
|
|
4204
|
+
const review = {
|
|
4205
|
+
slabs: [slab('box', { x: 2.31591782, y: 1.5, z: 0.14141787 }, { x: 0.12034748, y: 1.5, z: 0.52895252 })],
|
|
4206
|
+
fov: 120,
|
|
4207
|
+
aspect: 20 / 9,
|
|
4208
|
+
yaw: 5.085648783239423,
|
|
4209
|
+
pitch: 0.5191120134075965,
|
|
4210
|
+
};
|
|
4211
|
+
let checks = 0;
|
|
4212
|
+
for (let n = 0; n < cases; n += 1) {
|
|
4213
|
+
let setup = n === 0 && withReview ? review : null;
|
|
4214
|
+
while (!setup) {
|
|
4215
|
+
const fov = random() < 0.5 ? 70 : 120;
|
|
4216
|
+
const aspect = random() < 0.5 ? 16 / 9 : 20 / 9;
|
|
4217
|
+
const slabs = [];
|
|
4218
|
+
const count = random() < 0.5 ? 1 : 2;
|
|
4219
|
+
for (let k = 0; k < count; k += 1) {
|
|
4220
|
+
const away = between(0.8, 5);
|
|
4221
|
+
const angle = between(0, 2 * Math.PI);
|
|
4222
|
+
const half = { x: between(0.05, 0.8), y: between(0.3, 2), z: between(0.05, 0.8) };
|
|
4223
|
+
slabs.push(slab(`box${k}`, { x: away * Math.cos(angle), y: half.y, z: away * Math.sin(angle) }, half, between(-90, 90)));
|
|
4224
|
+
}
|
|
4225
|
+
if (slabs.every((x) => x.gap(lookAt) >= marginOf(fov, aspect) + 0.06)) {
|
|
4226
|
+
// Mostly toward a box, where the sweep passes its edges.
|
|
4227
|
+
const aim = slabs[0].actor.components.Transform;
|
|
4228
|
+
const yaw = random() < 0.75 ? Math.atan2(-aim.x, aim.z) + between(-0.5, 0.5) : between(-Math.PI, Math.PI);
|
|
4229
|
+
setup = { slabs, fov, aspect, yaw, pitch: between(-0.6, 0.9) };
|
|
4230
|
+
}
|
|
4231
|
+
}
|
|
4232
|
+
const { slabs, fov, aspect, yaw, pitch } = setup;
|
|
4233
|
+
const { scene, system } = await rapierWorld(slabs.map((x) => x.actor));
|
|
4234
|
+
const world = lensOn(scene.physics3d, fov, aspect);
|
|
4235
|
+
const margin = marginOf(fov, aspect);
|
|
4236
|
+
const camera = world.camera;
|
|
4237
|
+
const p = camera.position;
|
|
4238
|
+
world.run(30);
|
|
4239
|
+
world.scene.persistent.camAngle = yaw;
|
|
4240
|
+
world.scene.cameraOrbit.pitch = pitch;
|
|
4241
|
+
world.scene.cameraOrbit.range = 12;
|
|
4242
|
+
for (let i = 0; i < 90; i += 1) {
|
|
4243
|
+
world.frame(FIXED);
|
|
4244
|
+
const where = `random boxes, case ${n} (${fov} degrees, aspect ${aspect.toFixed(3)}, yaw ${yaw}, tilt ${pitch}), frame ${i}, the camera at (${p.x.toFixed(4)}, ${p.y.toFixed(4)}, ${p.z.toFixed(4)})`;
|
|
4245
|
+
for (const x of slabs) {
|
|
4246
|
+
const gap = x.gap(p);
|
|
4247
|
+
assert.ok(gap >= margin - 1e-3, `${where}: ${(gap * 1000).toFixed(2)} mm off ${x.id}, want ${(margin * 1000).toFixed(2)}`);
|
|
4248
|
+
}
|
|
4249
|
+
assert.ok(p.y >= margin - 1e-3, `${where}: ${p.y} m off the ground`);
|
|
4250
|
+
camera.updateMatrixWorld();
|
|
4251
|
+
for (let a = 0; a <= 20; a += 1) {
|
|
4252
|
+
for (let b = 0; b <= 20; b += 1) {
|
|
4253
|
+
grid.set(a / 10 - 1, b / 10 - 1, -1).unproject(camera);
|
|
4254
|
+
const into = slabs.find((x) => x.inside(grid));
|
|
4255
|
+
assert.ok(!into, `${where}: the near plane at (${grid.x.toFixed(4)}, ${grid.y.toFixed(4)}, ${grid.z.toFixed(4)}) is inside ${into?.id}`);
|
|
4256
|
+
}
|
|
4257
|
+
}
|
|
4258
|
+
}
|
|
4259
|
+
system.dispose(scene);
|
|
4260
|
+
checks += 1;
|
|
4261
|
+
}
|
|
4262
|
+
return checks;
|
|
4263
|
+
}
|
|
4264
|
+
|
|
4265
|
+
// Rapier's misses, made to happen: a sweep that reports nothing, every
|
|
4266
|
+
// time or only when every solid is asked at once, still stops the ball its
|
|
4267
|
+
// radius off the wall (to within a millimetre, by halving, or by sweeping
|
|
4268
|
+
// against the solid alone), and a ball whose line ends inside a wall is
|
|
4269
|
+
// brought out of it.
|
|
4270
|
+
export async function ballMisses() {
|
|
4271
|
+
if (!realRapier) return 0;
|
|
4272
|
+
const { scene, system } = await rapierWorld([wallBox('wall', 8, 0, 1, 4)]);
|
|
4273
|
+
const world = system.world;
|
|
4274
|
+
const real = world.castShape.bind(world);
|
|
4275
|
+
const from = { x: 0, y: 5, z: 0 };
|
|
4276
|
+
const dir = { x: 1, y: 0, z: 0 };
|
|
4277
|
+
const sure = scene.physics3d.castBallFixed(from, dir, 20, 0.5);
|
|
4278
|
+
assert.ok(Math.abs(sure.distance - 7) < 1e-4, `rapier itself (${sure.distance})`);
|
|
4279
|
+
world.castShape = () => null;
|
|
4280
|
+
const blind = scene.physics3d.castBallFixed(from, dir, 20, 0.5);
|
|
4281
|
+
assert.ok(blind && blind.actorId === 'wall' && blind.distance <= 7 + 1e-4 && blind.distance > 7 - 2e-3, `missed every time: halved to ${blind?.distance}`);
|
|
4282
|
+
assert.ok(Math.abs(blind.normal.x + 1) < 1e-3, `facing the ball (${JSON.stringify(blind.normal)})`);
|
|
4283
|
+
world.castShape = (...args) => (args[11] ? real(...args) : null);
|
|
4284
|
+
const alone = scene.physics3d.castBallFixed(from, dir, 20, 0.5);
|
|
4285
|
+
assert.ok(Math.abs(alone.distance - 7) < 1e-4, `missed with every solid, met alone (${alone.distance})`);
|
|
4286
|
+
// Short of the wall the end is clear: nothing to find, as rapier says.
|
|
4287
|
+
world.castShape = () => null;
|
|
4288
|
+
assert.equal(scene.physics3d.castBallFixed(from, dir, 6.9, 0.5), null);
|
|
4289
|
+
// Beside the wall's line, ending inside it: out of it.
|
|
4290
|
+
const slant = { x: Math.cos(0.2), y: 0, z: Math.sin(0.2) };
|
|
4291
|
+
const side = scene.physics3d.castBallFixed({ x: 0, y: 5, z: -2.2 }, slant, 9, 0.5);
|
|
4292
|
+
const end = { x: side.distance * slant.x, z: -2.2 + side.distance * slant.z };
|
|
4293
|
+
const gap = Math.hypot(Math.max(7.5 - end.x, 0, end.x - 8.5), Math.max(-2 - end.z, 0, end.z - 2));
|
|
4294
|
+
assert.ok(gap >= 0.5 - 1e-3, `a slant missed: the ball ends ${gap} m off the wall`);
|
|
4295
|
+
world.castShape = real;
|
|
4296
|
+
system.dispose(scene);
|
|
4297
|
+
return 1;
|
|
4298
|
+
}
|
|
4299
|
+
|
|
4300
|
+
// Review 9: a takeover blend a wall holds in, the wall then removed. The
|
|
4301
|
+
// blend is let out at the collision pace: no frame takes the camera
|
|
4302
|
+
// farther from the look point than easing at 6/s toward its distance allows
|
|
4303
|
+
// (the blend's own 10/s carried it 0.246 m where 0.179 m is allowed), and
|
|
4304
|
+
// it still ends where the camera rests. The review's case (a wall at x = 1,
|
|
4305
|
+
// 70 degrees on 16:9, the camera handed back at (8, 8, 8)) and others; with
|
|
4306
|
+
// the wall kept the blend ends held by it and stays; with no wall the blend
|
|
4307
|
+
// is never held and ends in about 0.3 s, as before. Review 10: a wall near
|
|
4308
|
+
// the look point (its face 0.4 m off, so the start is moved off it and the
|
|
4309
|
+
// camera rests farther out than its distance) and a corner of two such
|
|
4310
|
+
// walls, at 70 and 120 degrees: the blend held there ends too (it was held
|
|
4311
|
+
// open for good, 0.093 m short, after 20 s). Every blend ends: what is
|
|
4312
|
+
// left of it 0.1 mm or less, no longer held, and one sweep a frame.
|
|
4313
|
+
const nearWall = (id, axis) => solidBox({ id, min: { x: -20, y: 0, z: -20, [axis]: 0.4 }, max: { x: 20, y: 20, z: 20, [axis]: 0.5 } });
|
|
4314
|
+
export async function blendRelease() {
|
|
4315
|
+
if (!realRapier) return 0;
|
|
4316
|
+
let checks = 0;
|
|
4317
|
+
const handBacks = [{ x: 8, y: 8, z: 8 }, { x: 6, y: 3, z: -2 }, { x: 4, y: 6, z: 5 }];
|
|
4318
|
+
const cases = [];
|
|
4319
|
+
for (const wallAt of [1, 1.5, null]) {
|
|
4320
|
+
for (const remove of wallAt === null ? [false] : [true, false]) {
|
|
4321
|
+
const walls = () => (wallAt === null ? [] : [solidBox({ id: 'wall', min: { x: wallAt, y: 0, z: -10 }, max: { x: wallAt + 0.1, y: 20, z: 20 } })]);
|
|
4322
|
+
cases.push({ walls, wallAt, remove, fov: 70, aspect: 16 / 9, label: wallAt === null ? 'no wall' : `a wall at x = ${wallAt}${remove ? ', removed' : ', kept'}` });
|
|
4323
|
+
}
|
|
4324
|
+
}
|
|
4325
|
+
for (const [fov, aspect] of [[70, 16 / 9], [120, 20 / 9]]) {
|
|
4326
|
+
for (const remove of [false, true]) {
|
|
4327
|
+
cases.push({ walls: () => [nearWall('near', 'x')], remove, fov, aspect, label: `a wall 0.4 m off${remove ? ', removed' : ', kept'}, ${fov} degrees` });
|
|
4328
|
+
cases.push({ walls: () => [nearWall('near', 'x'), nearWall('side', 'z')], remove, fov, aspect, label: `a corner 0.4 m off${remove ? ', removed' : ', kept'}, ${fov} degrees` });
|
|
4329
|
+
}
|
|
4330
|
+
}
|
|
4331
|
+
for (const c of cases) {
|
|
4332
|
+
for (const from of handBacks) {
|
|
4333
|
+
const actors = c.walls();
|
|
4334
|
+
const { scene, system } = await rapierWorld(actors);
|
|
4335
|
+
const world = lensOn(scene.physics3d, c.fov, c.aspect);
|
|
4336
|
+
const t = world.actor.components.Transform;
|
|
4337
|
+
const p = world.camera.position;
|
|
4338
|
+
const out = () => Math.hypot(p.x - t.x, p.y - (t.y + LOOK_HEIGHT), p.z - t.z);
|
|
4339
|
+
const label = `blend: ${c.label}, handed back at (${from.x}, ${from.y}, ${from.z})`;
|
|
4340
|
+
world.run(120);
|
|
4341
|
+
const whole = world.off(from);
|
|
4342
|
+
p.set(from.x, from.y, from.z);
|
|
4343
|
+
world.frame();
|
|
4344
|
+
if (c.wallAt) assert.ok(p.x <= c.wallAt - marginOf(c.fov, c.aspect) + 1e-3, `${label}: the wall holds the blend (x = ${p.x})`);
|
|
4345
|
+
if (c.remove) {
|
|
4346
|
+
actors.length = 0;
|
|
4347
|
+
system.afterBehaviors(scene, FIXED);
|
|
4348
|
+
}
|
|
4349
|
+
let before = out();
|
|
4350
|
+
let last = { x: p.x, y: p.y, z: p.z };
|
|
4351
|
+
let moved = Infinity;
|
|
4352
|
+
for (let i = 0; i < 300; i += 1) {
|
|
4353
|
+
world.frame(FIXED);
|
|
4354
|
+
const now = out();
|
|
4355
|
+
const allowed = Math.max(0, RANGE0 - before) * (1 - Math.exp(-6 * FIXED));
|
|
4356
|
+
if (c.remove) assert.ok(now - before <= allowed + 1e-4, `${label}, frame ${i}: out ${(now - before).toFixed(6)} m, easing at 6/s allows ${allowed.toFixed(6)}`);
|
|
4357
|
+
moved = Math.hypot(p.x - last.x, p.y - last.y, p.z - last.z);
|
|
4358
|
+
last = { x: p.x, y: p.y, z: p.z };
|
|
4359
|
+
before = now;
|
|
4360
|
+
if (c.walls().length === 0 && i === 16) assert.ok(world.off(world.rest(world.scene.persistent.camAngle, PITCH0, RANGE0)) < whole * 0.06, `${label}: about there in 0.3 s`);
|
|
4361
|
+
}
|
|
4362
|
+
const state = world.actor.runtime.orbit;
|
|
4363
|
+
assert.ok(Math.hypot(state.off.x, state.off.y, state.off.z) <= 1e-4, `${label}: the blend ended (${Math.hypot(state.off.x, state.off.y, state.off.z)} left)`);
|
|
4364
|
+
assert.ok(state.blendHeld !== true, `${label}: no longer held`);
|
|
4365
|
+
assert.ok(moved < 1e-9, `${label}: and the camera stays (${moved})`);
|
|
4366
|
+
world.sweeps = 0;
|
|
4367
|
+
world.run(60);
|
|
4368
|
+
assert.equal(world.sweeps, 60, `${label}: one sweep a frame once settled`);
|
|
4369
|
+
if (c.walls().length === 0 || c.remove) assert.ok(world.off(world.rest(world.scene.persistent.camAngle, PITCH0, RANGE0)) < 1e-3, `${label}: where it rests`);
|
|
4370
|
+
system.dispose(scene);
|
|
4371
|
+
checks += 1;
|
|
4372
|
+
}
|
|
4373
|
+
}
|
|
4374
|
+
return checks;
|
|
4375
|
+
}
|
|
4376
|
+
|
|
4377
|
+
// Compact copies of the preview world's blockers at the reported seats,
|
|
4378
|
+
// plus bench-8's grazing cylinder. Held Transforms must stay steady even
|
|
4379
|
+
// near blockers; body/hold fighting is checked separately below.
|
|
4380
|
+
// Each box: id, centre x/y/z, width/height/depth, yaw. No models or hub code.
|
|
4381
|
+
const seatedBoxes = [
|
|
4382
|
+
['bench-8', -5.198, .25, 7.602, 2.4, .5, .6, 180],
|
|
4383
|
+
['bench-23', 12.6, .25, 67.16, 2.4, .5, .6, 270],
|
|
4384
|
+
['set-board-S6L', 16.88, 1.7, 66.433, 1.6, 1.1, .14, 270],
|
|
4385
|
+
['bench-25', 12.6, .25, 78.6, 2.4, .5, .6, 270],
|
|
4386
|
+
['stall-harbour-2', 12.2, .5, 74.767, 2.4, 1, .9, 270],
|
|
4387
|
+
['set-S7L', 20.5, 1.8, 78, 8.667, 3.6, 7, 270],
|
|
4388
|
+
['set-board-S7L', 16.88, 1.7, 75.1, 1.6, 1.1, .14, 270],
|
|
4389
|
+
['harbour-far-l', 13.1, .7, 83.4, 21.8, 1.4, .8, 0],
|
|
4390
|
+
['quay-crate-4', 12.3, .45, 79.2, .9, .9, .9, 0],
|
|
4391
|
+
];
|
|
4392
|
+
function seatedSolids() {
|
|
4393
|
+
const boxes = seatedBoxes.map(([id, x, y, z, width, height, depth, rotationY]) => ({
|
|
4394
|
+
id, components: {
|
|
4395
|
+
Transform: { x, y, z, rotationX: 0, rotationY, rotationZ: 0 },
|
|
4396
|
+
Shape: { kind: 'box', width, height, depth }, Solid: {},
|
|
4397
|
+
}, runtime: {},
|
|
4398
|
+
}));
|
|
4399
|
+
for (const [id, x, y, z, radius, height] of [
|
|
4400
|
+
['tree-9', -3.896, 1, 9.643, .9, 2],
|
|
4401
|
+
['quay-barrel-3', 11.5, .45, 78.5, .42, .9],
|
|
4402
|
+
]) boxes.push({ id, components: {
|
|
4403
|
+
Transform: { x, y, z, rotationX: 0, rotationY: 0, rotationZ: 0 },
|
|
4404
|
+
Shape: { kind: 'cylinder', radius, height }, Solid: {},
|
|
4405
|
+
}, runtime: {} });
|
|
4406
|
+
return boxes;
|
|
4407
|
+
}
|
|
4408
|
+
// Advance the real Player and its camera while holding the Transform, as
|
|
4409
|
+
// a seat does. Unlike makeWorld.frame, this does not simulate stand-in physics.
|
|
4410
|
+
function seatedFrame(world, height, dt = FIXED) {
|
|
4411
|
+
world.actor.components.Transform.y = height;
|
|
4412
|
+
world.scene.time += dt;
|
|
4413
|
+
new Player(world.actor.components.Player).update(world.actor, world.scene, dt);
|
|
4414
|
+
placeFollowCamera(world.scene);
|
|
4415
|
+
}
|
|
4416
|
+
|
|
4417
|
+
export async function seatedJitter() {
|
|
4418
|
+
if (!realRapier) return 0;
|
|
4419
|
+
const actors = seatedSolids();
|
|
4420
|
+
const { scene, system } = await rapierWorld(actors);
|
|
4421
|
+
let checks = 0;
|
|
4422
|
+
try {
|
|
4423
|
+
for (const id of ['bench-8', 'bench-23', 'bench-25']) {
|
|
4424
|
+
const seat = actors.find((a) => a.id === id).components.Transform;
|
|
4425
|
+
for (const yaw of [0, 45, 90, 135, 160, 180, 225, 270, 315, 345]) {
|
|
4426
|
+
for (const pitch of [-20, 0, 15, 35, 60]) {
|
|
4427
|
+
const world = lensOn(scene.physics3d, 70, 1.6);
|
|
4428
|
+
Object.assign(world.actor.components.Transform, seat, { y: 1.35 });
|
|
4429
|
+
world.scene.persistent.camAngle = yaw * DEG;
|
|
4430
|
+
world.scene.data.engine.camera.pitch = pitch;
|
|
4431
|
+
for (let i = 0; i < 240; i += 1) seatedFrame(world, 1.35);
|
|
4432
|
+
const at = world.camera.position.clone();
|
|
4433
|
+
const aim = world.camera.quaternion.toArray();
|
|
4434
|
+
const from = { ...world.lastCast.from };
|
|
4435
|
+
const limit = world.actor.runtime.orbit.limit;
|
|
4436
|
+
const label = `${id}, yaw ${yaw}, pitch ${pitch}`;
|
|
4437
|
+
for (let i = 0; i < 120; i += 1) {
|
|
4438
|
+
seatedFrame(world, 1.35);
|
|
4439
|
+
const p = world.camera.position;
|
|
4440
|
+
assert.ok(p.distanceTo(at) < 1e-8, `${label}, held Transform, frame ${i}: camera moved ${p.distanceTo(at)} m`);
|
|
4441
|
+
assert.ok(world.camera.quaternion.toArray().every((v, j) => Math.abs(v - aim[j]) < 1e-8), `${label}: the aim stays steady`);
|
|
4442
|
+
for (const k of ['x', 'y', 'z']) assert.ok(Math.abs(world.lastCast.from[k] - from[k]) < 1e-8, `${label}: sweep start ${k} stays steady`);
|
|
4443
|
+
const now = world.actor.runtime.orbit.limit;
|
|
4444
|
+
assert.ok(now === limit || Math.abs(now - limit) < 1e-8, `${label}: the pop-in limit stays steady`);
|
|
4445
|
+
assert.deepEqual(scene.physics3d.nearFixed(p, .25 - 2e-4), [], `${label}: the camera ball stays clear of every solid`);
|
|
4446
|
+
}
|
|
4447
|
+
checks += 1;
|
|
4448
|
+
}
|
|
4449
|
+
}
|
|
4450
|
+
}
|
|
4451
|
+
// A still Transform must still take a new blocker in at once and
|
|
4452
|
+
// let it out at 6/s. No camera filtering is justified by these seats.
|
|
4453
|
+
const world = lensOn(scene.physics3d, 70, 1.6);
|
|
4454
|
+
world.scene.persistent.camAngle = 0;
|
|
4455
|
+
for (let i = 0; i < 240; i += 1) seatedFrame(world, 1.35);
|
|
4456
|
+
const wall = wallBox('new-seat-wall', 0, 2, 20, .5);
|
|
4457
|
+
actors.push(wall);
|
|
4458
|
+
system.afterBehaviors(scene, FIXED);
|
|
4459
|
+
seatedFrame(world, 1.35);
|
|
4460
|
+
assert.ok(world.camera.position.z <= 1.5 + 1e-4, 'a new wall snaps the camera in, including its margin');
|
|
4461
|
+
assert.deepEqual(scene.physics3d.nearFixed(world.camera.position, .25 - 2e-4), [], 'stationary camera stays outside the new wall');
|
|
4462
|
+
actors.pop();
|
|
4463
|
+
system.afterBehaviors(scene, FIXED);
|
|
4464
|
+
for (let i = 0; i < 180; i += 1) {
|
|
4465
|
+
const was = world.actor.runtime.orbit.out;
|
|
4466
|
+
seatedFrame(world, 1.35);
|
|
4467
|
+
const out = world.actor.runtime.orbit.out;
|
|
4468
|
+
assert.ok(out - was <= (RANGE0 - was) * (1 - Math.exp(-6 * FIXED)) + 1e-4, 'stationary camera eases out at 6/s (with its 0.1 mm completion tolerance)');
|
|
4469
|
+
}
|
|
4470
|
+
checks += 1;
|
|
4471
|
+
// Keep nearFixed's displaced start stable too (a look point 0.1 m
|
|
4472
|
+
// from a wall), including a wider lens that needs a larger ball.
|
|
4473
|
+
for (const [fov, aspect] of [[70, 1.6], [120, 20 / 9]]) {
|
|
4474
|
+
const w = lensOn(scene.physics3d, fov, aspect);
|
|
4475
|
+
const wall = wallBox('beside-seat', .6, 0, 1, 20);
|
|
4476
|
+
actors.push(wall);
|
|
4477
|
+
system.afterBehaviors(scene, FIXED);
|
|
4478
|
+
w.scene.persistent.camAngle = Math.PI / 2;
|
|
4479
|
+
for (let i = 0; i < 240; i += 1) seatedFrame(w, 1.35);
|
|
4480
|
+
const at = w.camera.position.clone();
|
|
4481
|
+
assert.ok(w.lastCast.from.x < -.1, 'the near wall displaces the sweep start');
|
|
4482
|
+
for (let i = 0; i < 120; i += 1) {
|
|
4483
|
+
seatedFrame(w, 1.35);
|
|
4484
|
+
assert.ok(w.camera.position.distanceTo(at) < 1e-8, 'the displaced start stays steady');
|
|
4485
|
+
assert.deepEqual(scene.physics3d.nearFixed(w.camera.position, marginOf(fov, aspect) - 2e-4), [], 'the wider lens stays clear');
|
|
4486
|
+
}
|
|
4487
|
+
actors.pop();
|
|
4488
|
+
system.afterBehaviors(scene, FIXED);
|
|
4489
|
+
checks += 1;
|
|
4490
|
+
}
|
|
4491
|
+
return checks;
|
|
4492
|
+
} finally {
|
|
4493
|
+
system.dispose(scene);
|
|
4494
|
+
}
|
|
4495
|
+
}
|
|
4496
|
+
|
|
4497
|
+
// Bench-25's held capsule overlaps the adjacent crate. Exercise the real
|
|
4498
|
+
// controller, physics, interpolation and camera with a 50 ms server-style
|
|
4499
|
+
// clamp (5 cm horizontal / 50 cm vertical slack). Keep this as a body-fight
|
|
4500
|
+
// reproducer, not a reason to suppress correct camera motion in Player.
|
|
4501
|
+
async function seatedBodyRun(clearCrate) {
|
|
4502
|
+
const actors = seatedSolids();
|
|
4503
|
+
if (clearCrate) actors.find((a) => a.id === 'quay-crate-4').components.Transform.z = 79.45;
|
|
4504
|
+
const at = { x: 12.6, y: 1.35, z: 78.6 };
|
|
4505
|
+
const player = {
|
|
4506
|
+
id: 'sitter', components: {
|
|
4507
|
+
Transform: { ...at, rotationX: 0, rotationY: 270, rotationZ: 0 },
|
|
4508
|
+
Shape: { kind: 'capsule', height: 1.4, radius: .35 },
|
|
4509
|
+
Body: { type: 'dynamic', gravityScale: 2, lockRotations: true, friction: 0 },
|
|
4510
|
+
Solid: {}, Player: { ...PROPS },
|
|
4511
|
+
}, runtime: {},
|
|
4512
|
+
};
|
|
4513
|
+
actors.push(player);
|
|
4514
|
+
const { scene, system } = await rapierWorld(actors);
|
|
4515
|
+
const world = lensOn(scene.physics3d, 70, 1.6);
|
|
4516
|
+
Object.assign(scene, { cameraFollowsRigidly: true, cameraControl: 'orbit',
|
|
4517
|
+
persistent: { camAngle: Math.PI / 4 }, keys: new Set(), actorsWith: () => [],
|
|
4518
|
+
three: { camera: world.camera }, lookInput: world.gestures.look, moveInput: world.stick });
|
|
4519
|
+
scene.data = { engine: { camera: { follow: 'rigid', control: 'orbit' } } };
|
|
4520
|
+
const body = scene.physics3d.bodyOf(player);
|
|
4521
|
+
body.setTranslation(at, true);
|
|
4522
|
+
body.setLinvel({ x: 0, y: 0, z: 0 }, true);
|
|
4523
|
+
Object.assign(player.components.Transform, at);
|
|
4524
|
+
let last = null;
|
|
4525
|
+
const result = { body: 0, camera: 0, clamps: 0 };
|
|
4526
|
+
try {
|
|
4527
|
+
for (let i = 0; i < 600; i += 1) {
|
|
4528
|
+
scene.time += FIXED;
|
|
4529
|
+
new Player(player.components.Player).update(player, scene, FIXED);
|
|
4530
|
+
system.afterBehaviors(scene, FIXED);
|
|
4531
|
+
// Multiplayer accepts the clamp after physics. The rendered Transform
|
|
4532
|
+
// catches up in the next physics pass; preserve that interpolation.
|
|
4533
|
+
if (i % 3 === 0) {
|
|
4534
|
+
const p = body.translation();
|
|
4535
|
+
if (Math.hypot(p.x - at.x, p.z - at.z) > .05 || Math.abs(p.y - at.y) > .5) {
|
|
4536
|
+
body.setTranslation(at, true);
|
|
4537
|
+
if (i >= 300) result.clamps += 1;
|
|
4538
|
+
}
|
|
4539
|
+
}
|
|
4540
|
+
placeFollowCamera(scene);
|
|
4541
|
+
const p = { ...body.translation() };
|
|
4542
|
+
const cam = world.camera.position.clone();
|
|
4543
|
+
if (i >= 300 && last) {
|
|
4544
|
+
result.body = Math.max(result.body, Math.hypot(p.x - last.p.x, p.y - last.p.y, p.z - last.p.z));
|
|
4545
|
+
result.camera = Math.max(result.camera, cam.distanceTo(last.cam));
|
|
4546
|
+
}
|
|
4547
|
+
last = { p, cam };
|
|
4548
|
+
}
|
|
4549
|
+
return result;
|
|
4550
|
+
} finally {
|
|
4551
|
+
system.dispose(scene);
|
|
4552
|
+
}
|
|
4553
|
+
}
|
|
4554
|
+
async function seatedBodyClamp() {
|
|
4555
|
+
if (!realRapier) return 0;
|
|
4556
|
+
const blocked = await seatedBodyRun(false);
|
|
4557
|
+
assert.equal(blocked.clamps, 100, 'the overlapping seat triggers a clamp every 50 ms over five measured seconds');
|
|
4558
|
+
assert.ok(blocked.body > .05, 'the held body repeatedly depenetrates and is corrected');
|
|
4559
|
+
assert.ok(blocked.camera > .05, 'the camera follows the actual body jitter');
|
|
4560
|
+
const clear = await seatedBodyRun(true);
|
|
4561
|
+
assert.equal(clear.clamps, 0, 'moving the crate in the fixture removes the clamp cycle');
|
|
4562
|
+
assert.ok(clear.body < 1e-8 && clear.camera < 1e-8, 'clear held body and its camera both stay still');
|
|
4563
|
+
return 2;
|
|
4564
|
+
}
|
|
4565
|
+
|
|
2074
4566
|
export async function run() {
|
|
2075
4567
|
const parts = {
|
|
2076
4568
|
unchanged: unkeyedIsUnchanged(),
|
|
2077
4569
|
cold: coldKeyless(),
|
|
2078
4570
|
loads: acrossLoads(),
|
|
4571
|
+
lens: lensAcrossLoads(),
|
|
2079
4572
|
offAndOn: offAndOn(),
|
|
2080
4573
|
lockedTrip: lockedTrip(),
|
|
2081
4574
|
locking: locking(),
|
|
@@ -2084,21 +4577,59 @@ export async function run() {
|
|
|
2084
4577
|
ownInputOnly: ownInputOnly(),
|
|
2085
4578
|
offByCallback: offByCallback(),
|
|
2086
4579
|
blendHeld: blendHeld(),
|
|
4580
|
+
ownModel: ownModel(),
|
|
2087
4581
|
walking: walking(),
|
|
2088
4582
|
looking: looking(),
|
|
4583
|
+
startingValues: startingValues(),
|
|
2089
4584
|
blocked: blocked(),
|
|
4585
|
+
grounded: grounded(),
|
|
4586
|
+
wideLens: wideLens(),
|
|
2090
4587
|
facing: facing(),
|
|
2091
4588
|
takenOver: takenOver(),
|
|
2092
4589
|
roles: pointerRoles(),
|
|
2093
4590
|
listeners: listeners(),
|
|
4591
|
+
mouseLock: await mouseLock(),
|
|
4592
|
+
shiftLock: await runShiftLockChecks(),
|
|
4593
|
+
orbitShot: await runOrbitShotChecks(),
|
|
2094
4594
|
rapier: await fixedRay(),
|
|
4595
|
+
grazing: await grazing(),
|
|
4596
|
+
popClear: await popClear(),
|
|
4597
|
+
popSteady: await popSteady(),
|
|
4598
|
+
corners: await corners(),
|
|
4599
|
+
narrowGapStable: await narrowGapStable(),
|
|
4600
|
+
releaseEase: await releaseEase(),
|
|
4601
|
+
releaseBeside: await releaseBeside(),
|
|
4602
|
+
randomBoxes: await randomBoxes(),
|
|
4603
|
+
ballMisses: await ballMisses(),
|
|
4604
|
+
blendRelease: await blendRelease(),
|
|
4605
|
+
seatedJitter: await seatedJitter(),
|
|
4606
|
+
seatedBodyClamp: await seatedBodyClamp(),
|
|
2095
4607
|
};
|
|
2096
4608
|
const checks = Object.values(parts).reduce((a, b) => a + b, 0);
|
|
2097
4609
|
return { checks, real: parts.rapier > 0 };
|
|
2098
4610
|
}
|
|
2099
4611
|
|
|
2100
4612
|
export const summary = ({ checks, real }) =>
|
|
2101
|
-
`${checks} orbit-camera checks (${real ? 'castRayFixed on rapier itself' : 'rapier itself is not installed here, so
|
|
4613
|
+
`${checks} orbit-camera checks (${real ? 'castRayFixed, castRayFixedNormal, castBallFixed and nearFixed on rapier itself' : 'rapier itself is not installed here, so the camera\'s queries were not run on it'})`;
|
|
4614
|
+
|
|
4615
|
+
// The world starts keyless; loading orbit creates extras before returning to
|
|
4616
|
+
// scene client code, and later loads preserve the registrations.
|
|
4617
|
+
{
|
|
4618
|
+
const runtime = new SceneRuntime(sceneData('off', { x: 0, y: 1, z: 0 }), [Player], {}, {});
|
|
4619
|
+
runtime.three = {};
|
|
4620
|
+
runtime.load(sceneData('off', { x: 0, y: 1, z: 0 }));
|
|
4621
|
+
assert.equal(runtime.three.ownModelWith, undefined);
|
|
4622
|
+
runtime.load(sceneData('orbit', { x: 0, y: 1, z: 0 }));
|
|
4623
|
+
assert.ok(runtime.three.ownModelWith instanceof Set);
|
|
4624
|
+
const extras = runtime.three.ownModelWith;
|
|
4625
|
+
const tag = new THREE.Object3D();
|
|
4626
|
+
extras.add(tag);
|
|
4627
|
+
for (const mode of ['off', 'orbit']) {
|
|
4628
|
+
runtime.load(sceneData(mode, { x: 0, y: 1, z: 0 }));
|
|
4629
|
+
assert.equal(runtime.three.ownModelWith, extras);
|
|
4630
|
+
assert.ok(extras.has(tag));
|
|
4631
|
+
}
|
|
4632
|
+
}
|
|
2102
4633
|
|
|
2103
4634
|
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
2104
4635
|
console.log(`camera orbit: ${summary(await run())}`);
|