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
|
@@ -11,8 +11,13 @@
|
|
|
11
11
|
// rim and the occlusion are patched into the part's own material. Occlusion
|
|
12
12
|
// is baked once per model into a vertex attribute, by marching rays through
|
|
13
13
|
// a coarse grid of the model's surfaces.
|
|
14
|
+
//
|
|
15
|
+
// A scene can ask for the baking to be done after the model is first drawn
|
|
16
|
+
// (Baking later, at the end of this file, and lookbake.js).
|
|
14
17
|
|
|
15
18
|
import * as THREE from 'three';
|
|
19
|
+
import { queueLookBake } from './lookbake';
|
|
20
|
+
import { markKitHooks } from './kithooks';
|
|
16
21
|
|
|
17
22
|
export const LOOK_DEFAULTS = {
|
|
18
23
|
outline: 0.012,
|
|
@@ -68,6 +73,12 @@ function partLooks(model) {
|
|
|
68
73
|
for (const part of model.parts) {
|
|
69
74
|
looks.set(part.id, readLook(part.look, base));
|
|
70
75
|
}
|
|
76
|
+
if (later?.queue?.skipSurfaceBakes === true) {
|
|
77
|
+
return {
|
|
78
|
+
base: { ...base, outline: 0, ao: 0 },
|
|
79
|
+
looks: new Map([...looks].map(([id, look]) => [id, look ? { ...look, outline: 0, ao: 0 } : null])),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
71
82
|
return { base, looks };
|
|
72
83
|
}
|
|
73
84
|
|
|
@@ -92,6 +103,20 @@ export function lookIsEnabled() {
|
|
|
92
103
|
}
|
|
93
104
|
|
|
94
105
|
export function applyLook(root, model) {
|
|
106
|
+
if (!later) {
|
|
107
|
+
lookNow(root, model);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
// What `lookNow` leaves to bake later, with what merging the model's parts
|
|
111
|
+
// left (optimize.js).
|
|
112
|
+
const waiting = { occlusion: null, outlines: later.merged };
|
|
113
|
+
later.waiting = waiting;
|
|
114
|
+
later.merged = [];
|
|
115
|
+
lookNow(root, model);
|
|
116
|
+
queueWaiting(waiting);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function lookNow(root, model) {
|
|
95
120
|
const settings = lookEnabled ? partLooks(model) : null;
|
|
96
121
|
const meshes = [];
|
|
97
122
|
root.traverse((object) => {
|
|
@@ -185,6 +210,7 @@ function patchMaterial(material, look, geometry) {
|
|
|
185
210
|
);
|
|
186
211
|
};
|
|
187
212
|
material.customProgramCacheKey = () => `look|${previousKey.call(material)}`;
|
|
213
|
+
markKitHooks(material, previous, previousKey);
|
|
188
214
|
material.needsUpdate = true;
|
|
189
215
|
}
|
|
190
216
|
|
|
@@ -246,7 +272,10 @@ gl_Position = projectionMatrix * mvPosition;
|
|
|
246
272
|
const viewport = new THREE.Vector4();
|
|
247
273
|
|
|
248
274
|
function makeOutline(geometry, look, partMaterial) {
|
|
249
|
-
|
|
275
|
+
const waits = later !== null && !geometry.getAttribute('lookOutlineNormal');
|
|
276
|
+
if (!waits) {
|
|
277
|
+
addOutlineAttributes(geometry);
|
|
278
|
+
}
|
|
250
279
|
const material = new THREE.MeshBasicMaterial({
|
|
251
280
|
color: new THREE.Color(look.outlineColor),
|
|
252
281
|
side: THREE.BackSide,
|
|
@@ -275,6 +304,9 @@ function makeOutline(geometry, look, partMaterial) {
|
|
|
275
304
|
renderer.getCurrentViewport(viewport);
|
|
276
305
|
uniforms.lookViewportHeight.value = Math.max(1, viewport.w / renderer.getPixelRatio());
|
|
277
306
|
};
|
|
307
|
+
if (waits) {
|
|
308
|
+
waitForOutline(geometry, material);
|
|
309
|
+
}
|
|
278
310
|
const outline = new OutlineMesh(geometry, material);
|
|
279
311
|
outline.userData.lookOutline = true;
|
|
280
312
|
outline.castShadow = false;
|
|
@@ -293,13 +325,41 @@ export function addOutlineAttributes(geometry) {
|
|
|
293
325
|
if (geometry.getAttribute('lookOutlineNormal')) {
|
|
294
326
|
return;
|
|
295
327
|
}
|
|
328
|
+
const work = outlineWork(geometry);
|
|
329
|
+
sumNormalsByPosition(work, 0, work.positions.count);
|
|
330
|
+
smoothNormals(work);
|
|
331
|
+
curvatureRadii(work, 0, work.count);
|
|
332
|
+
for (let pass = 0; pass < UNEVEN_PASSES; pass++) {
|
|
333
|
+
evenOutFolds(work, 0, work.count);
|
|
334
|
+
}
|
|
335
|
+
setOutlineAttributes(geometry, work);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// What `addOutlineAttributes` works on. Each of its loops takes the stretch
|
|
339
|
+
// to do, of vertices or of triangle corners, so that baking later can do a
|
|
340
|
+
// geometry a stretch at a time (`outlineSteps`). Vertices at the same
|
|
341
|
+
// position (to 0.1 mm) share a slot; `sums` holds each slot's summed normal,
|
|
342
|
+
// `smooth` each vertex's averaged normal and `bySlot` each slot's reach.
|
|
343
|
+
function outlineWork(geometry) {
|
|
296
344
|
if (!geometry.getAttribute('normal')) {
|
|
297
345
|
geometry.computeVertexNormals();
|
|
298
346
|
}
|
|
299
347
|
const positions = geometry.getAttribute('position');
|
|
300
|
-
const
|
|
301
|
-
|
|
302
|
-
|
|
348
|
+
const index = geometry.getIndex();
|
|
349
|
+
return {
|
|
350
|
+
positions,
|
|
351
|
+
normals: geometry.getAttribute('normal'),
|
|
352
|
+
slotOf: new Map(),
|
|
353
|
+
slots: new Uint32Array(positions.count),
|
|
354
|
+
sums: [],
|
|
355
|
+
smooth: new Float32Array(positions.count * 3),
|
|
356
|
+
bySlot: new Float32Array(positions.count).fill(1e6),
|
|
357
|
+
count: index ? index.count : positions.count,
|
|
358
|
+
corner: (n) => (index ? index.getX(n) : n),
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
function smoothNormals({ positions, normals, slots, sums, smooth }) {
|
|
303
363
|
for (let i = 0; i < positions.count; i++) {
|
|
304
364
|
const at = slots[i] * 3;
|
|
305
365
|
const length = Math.hypot(sums[at], sums[at + 1], sums[at + 2]);
|
|
@@ -312,18 +372,43 @@ export function addOutlineAttributes(geometry) {
|
|
|
312
372
|
smooth.set([sums[at] / length, sums[at + 1] / length, sums[at + 2] / length], i * 3);
|
|
313
373
|
}
|
|
314
374
|
}
|
|
315
|
-
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
function setOutlineAttributes(geometry, { positions, slots, smooth, bySlot }) {
|
|
378
|
+
const reach = new Float32Array(positions.count);
|
|
379
|
+
for (let i = 0; i < positions.count; i++) {
|
|
380
|
+
reach[i] = bySlot[slots[i]];
|
|
381
|
+
}
|
|
316
382
|
geometry.setAttribute('lookOutlineNormal', new THREE.BufferAttribute(smooth, 3));
|
|
317
383
|
geometry.setAttribute('lookOutlineReach', new THREE.BufferAttribute(reach, 1));
|
|
318
384
|
}
|
|
319
385
|
|
|
320
|
-
//
|
|
321
|
-
//
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
386
|
+
// The outline attributes of geometries about to be merged into one
|
|
387
|
+
// (optimize.js): each is given its own, so parts that touch keep an outline
|
|
388
|
+
// between them. When the baking is done later nothing is added, and what is
|
|
389
|
+
// returned says where each part will lie in the merged geometry
|
|
390
|
+
// (`outlineMergedLater`).
|
|
391
|
+
export function outlinePartByPart(geometries) {
|
|
392
|
+
if (later?.queue?.skipSurfaceBakes === true) return null;
|
|
393
|
+
if (!later) {
|
|
394
|
+
geometries.forEach(addOutlineAttributes);
|
|
395
|
+
return null;
|
|
396
|
+
}
|
|
397
|
+
const parts = [];
|
|
398
|
+
let vertex = 0;
|
|
399
|
+
let corner = 0;
|
|
400
|
+
for (const geometry of geometries) {
|
|
401
|
+
const vertices = geometry.getAttribute('position').count;
|
|
402
|
+
const corners = geometry.getIndex().count;
|
|
403
|
+
parts.push({ vertex, vertices, corner, corners });
|
|
404
|
+
vertex += vertices;
|
|
405
|
+
corner += corners;
|
|
406
|
+
}
|
|
407
|
+
return parts;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
function sumNormalsByPosition({ positions, normals, slotOf, slots, sums }, from, to) {
|
|
411
|
+
for (let i = from; i < to; i++) {
|
|
327
412
|
const key = `${Math.round(positions.getX(i) * 1e4)},${Math.round(positions.getY(i) * 1e4)},${Math.round(positions.getZ(i) * 1e4)}`;
|
|
328
413
|
let slot = slotOf.get(key);
|
|
329
414
|
if (slot === undefined) {
|
|
@@ -336,14 +421,9 @@ function sumNormalsByPosition(positions, normals) {
|
|
|
336
421
|
sums[slot * 3 + 1] += normals.getY(i);
|
|
337
422
|
sums[slot * 3 + 2] += normals.getZ(i);
|
|
338
423
|
}
|
|
339
|
-
return { slots, sums };
|
|
340
424
|
}
|
|
341
425
|
|
|
342
|
-
function curvatureRadii(
|
|
343
|
-
const index = geometry.getIndex();
|
|
344
|
-
const count = index ? index.count : positions.count;
|
|
345
|
-
const corner = (n) => (index ? index.getX(n) : n);
|
|
346
|
-
const bySlot = new Float32Array(slots.length).fill(1e6);
|
|
426
|
+
function curvatureRadii({ positions, smooth, slots, bySlot, corner }, from, to) {
|
|
347
427
|
const edge = (a, b) => {
|
|
348
428
|
const dx = positions.getX(b) - positions.getX(a);
|
|
349
429
|
const dy = positions.getY(b) - positions.getY(a);
|
|
@@ -361,7 +441,7 @@ function curvatureRadii(geometry, positions, smooth, slots) {
|
|
|
361
441
|
bySlot[slots[a]] = Math.min(bySlot[slots[a]], radius);
|
|
362
442
|
bySlot[slots[b]] = Math.min(bySlot[slots[b]], radius);
|
|
363
443
|
};
|
|
364
|
-
for (let n =
|
|
444
|
+
for (let n = from; n + 2 < to; n += 3) {
|
|
365
445
|
const a = corner(n);
|
|
366
446
|
const b = corner(n + 1);
|
|
367
447
|
const c = corner(n + 2);
|
|
@@ -374,14 +454,6 @@ function curvatureRadii(geometry, positions, smooth, slots) {
|
|
|
374
454
|
bySlot[slots[at]] = Math.min(bySlot[slots[at]], fold);
|
|
375
455
|
}
|
|
376
456
|
}
|
|
377
|
-
for (let pass = 0; pass < UNEVEN_PASSES; pass++) {
|
|
378
|
-
evenOutFolds(positions, smooth, slots, bySlot, count, corner);
|
|
379
|
-
}
|
|
380
|
-
const reach = new Float32Array(positions.count);
|
|
381
|
-
for (let i = 0; i < positions.count; i++) {
|
|
382
|
-
reach[i] = bySlot[slots[i]];
|
|
383
|
-
}
|
|
384
|
-
return reach;
|
|
385
457
|
}
|
|
386
458
|
|
|
387
459
|
// A hull triangle pushed too far turns over. Its back then faces the camera
|
|
@@ -441,8 +513,8 @@ const UNEVEN_PASSES = 3;
|
|
|
441
513
|
|
|
442
514
|
const pushed = [new THREE.Vector3(), new THREE.Vector3(), new THREE.Vector3()];
|
|
443
515
|
|
|
444
|
-
function evenOutFolds(positions, smooth, slots, bySlot,
|
|
445
|
-
for (let n =
|
|
516
|
+
function evenOutFolds({ positions, smooth, slots, bySlot, corner }, from, to) {
|
|
517
|
+
for (let n = from; n + 2 < to; n += 3) {
|
|
446
518
|
const corners = [corner(n), corner(n + 1), corner(n + 2)];
|
|
447
519
|
const reaches = corners.map((at) => bySlot[slots[at]]);
|
|
448
520
|
const least = Math.min(...reaches);
|
|
@@ -516,10 +588,12 @@ function bakeOcclusion(root, model, meshes) {
|
|
|
516
588
|
const shape = geometries.map((geometry) => geometry.getAttribute('position').count).join(',');
|
|
517
589
|
let cached = occlusionCache.get(model);
|
|
518
590
|
if (!cached || cached.shape !== shape) {
|
|
591
|
+
const firsts = geometries.map((geometry) => firstMesh.get(geometry));
|
|
592
|
+
if (later && waitForOcclusion(root, model, shape, firsts)) {
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
519
595
|
const grid = buildGrid(root);
|
|
520
|
-
const values =
|
|
521
|
-
grid ? occlusionOf(firstMesh.get(geometry), grid) : null
|
|
522
|
-
);
|
|
596
|
+
const values = firsts.map((mesh) => (grid ? occlusionOf(mesh, grid) : null));
|
|
523
597
|
cached = { shape, values };
|
|
524
598
|
occlusionCache.set(model, cached);
|
|
525
599
|
}
|
|
@@ -535,24 +609,46 @@ function bakeOcclusion(root, model, meshes) {
|
|
|
535
609
|
// grid of cells. Only surfaces are marked; rays step less than a cell at a
|
|
536
610
|
// time, so none passes through a marked cell unseen.
|
|
537
611
|
function buildGrid(root) {
|
|
538
|
-
const
|
|
539
|
-
|
|
612
|
+
const opened = openGrid(surfacesOf(root));
|
|
613
|
+
if (!opened) {
|
|
614
|
+
return null;
|
|
615
|
+
}
|
|
616
|
+
for (const surface of opened.surfaces) {
|
|
617
|
+
markTriangles(opened.grid, surface);
|
|
618
|
+
}
|
|
619
|
+
return opened.grid;
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
// The meshes whose surfaces block rays.
|
|
623
|
+
function surfacesOf(root) {
|
|
624
|
+
const meshes = [];
|
|
540
625
|
root.traverseVisible((object) => {
|
|
541
|
-
if (
|
|
542
|
-
|
|
626
|
+
if (object.isMesh && !object.userData.lookOutline) {
|
|
627
|
+
meshes.push(object);
|
|
543
628
|
}
|
|
544
|
-
|
|
545
|
-
|
|
629
|
+
});
|
|
630
|
+
return meshes;
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
// An empty grid around `meshes` (each a geometry and the matrix that places
|
|
634
|
+
// it), with each one's surface ready to be marked into it, or null when
|
|
635
|
+
// there is nothing to mark.
|
|
636
|
+
function openGrid(meshes) {
|
|
637
|
+
const surfaces = [];
|
|
638
|
+
const bounds = new THREE.Box3();
|
|
639
|
+
const point = new THREE.Vector3();
|
|
640
|
+
for (const { geometry, matrixWorld } of meshes) {
|
|
641
|
+
const positions = geometry.getAttribute('position');
|
|
642
|
+
const index = geometry.getIndex();
|
|
546
643
|
const count = index ? index.count : positions.count;
|
|
547
644
|
const world = new Float32Array(positions.count * 3);
|
|
548
|
-
const point = new THREE.Vector3();
|
|
549
645
|
for (let i = 0; i < positions.count; i++) {
|
|
550
|
-
point.fromBufferAttribute(positions, i).applyMatrix4(
|
|
646
|
+
point.fromBufferAttribute(positions, i).applyMatrix4(matrixWorld);
|
|
551
647
|
world.set([point.x, point.y, point.z], i * 3);
|
|
552
648
|
bounds.expandByPoint(point);
|
|
553
649
|
}
|
|
554
650
|
surfaces.push({ world, index, count });
|
|
555
|
-
}
|
|
651
|
+
}
|
|
556
652
|
if (bounds.isEmpty()) {
|
|
557
653
|
return null;
|
|
558
654
|
}
|
|
@@ -562,10 +658,7 @@ function buildGrid(root) {
|
|
|
562
658
|
const origin = bounds.min.clone().subScalar(cell * padding);
|
|
563
659
|
const dims = [size.x, size.y, size.z].map((extent) => Math.ceil(extent / cell) + padding * 2);
|
|
564
660
|
const grid = { origin, cell, dims, filled: new Uint8Array(dims[0] * dims[1] * dims[2]) };
|
|
565
|
-
|
|
566
|
-
markTriangles(grid, surface);
|
|
567
|
-
}
|
|
568
|
-
return grid;
|
|
661
|
+
return { grid, surfaces };
|
|
569
662
|
}
|
|
570
663
|
|
|
571
664
|
// The cell at a point given in cell units from the grid's origin, or -1
|
|
@@ -627,8 +720,16 @@ function markTriangles(grid, { world, index, count }) {
|
|
|
627
720
|
// For each vertex, the share of its outward rays that reach open air, with
|
|
628
721
|
// near hits counting more than far ones. Rays start two cells out along the
|
|
629
722
|
// normal, clear of the cells the vertex's own surface fills, and step 0.7 of
|
|
630
|
-
// a cell at a time, in cell units.
|
|
723
|
+
// a cell at a time, in cell units. `mesh` is a mesh, or its geometry and the
|
|
724
|
+
// matrix that placed it.
|
|
631
725
|
function occlusionOf(mesh, grid) {
|
|
726
|
+
const count = mesh.geometry.getAttribute('position').count;
|
|
727
|
+
return castRays(mesh, grid, new Float32Array(count), 0, count);
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
// `occlusionOf` for the vertices `from` one up to another, written into
|
|
731
|
+
// `out`: baking later does a few at a time.
|
|
732
|
+
function castRays(mesh, grid, out, from, to) {
|
|
632
733
|
const positions = mesh.geometry.getAttribute('position');
|
|
633
734
|
let normals = mesh.geometry.getAttribute('normal');
|
|
634
735
|
if (!normals) {
|
|
@@ -639,8 +740,7 @@ function occlusionOf(mesh, grid) {
|
|
|
639
740
|
const reach = GRID_CELLS * RAY_REACH;
|
|
640
741
|
const point = new THREE.Vector3();
|
|
641
742
|
const normal = new THREE.Vector3();
|
|
642
|
-
|
|
643
|
-
for (let i = 0; i < positions.count; i++) {
|
|
743
|
+
for (let i = from; i < to; i++) {
|
|
644
744
|
point.fromBufferAttribute(positions, i).applyMatrix4(mesh.matrixWorld);
|
|
645
745
|
point.sub(grid.origin).divideScalar(grid.cell);
|
|
646
746
|
normal.fromBufferAttribute(normals, i).applyMatrix3(normalMatrix).normalize();
|
|
@@ -673,3 +773,369 @@ function occlusionOf(mesh, grid) {
|
|
|
673
773
|
}
|
|
674
774
|
return out;
|
|
675
775
|
}
|
|
776
|
+
|
|
777
|
+
//
|
|
778
|
+
// Baking later
|
|
779
|
+
//
|
|
780
|
+
// For a scene that set `"engine": { "look": { "bake": "deferred" } }`
|
|
781
|
+
// (lookbake.js). A model built under `bakingLater` comes out as it does
|
|
782
|
+
// otherwise, in the same shape, with the same meshes, materials and shader
|
|
783
|
+
// programs, but for two things that are filled in when its task runs:
|
|
784
|
+
// - `lookOcclusion` is there, all 1, which is a vertex nothing occludes;
|
|
785
|
+
// - an outline hull is there, its material not `visible`, on a geometry that
|
|
786
|
+
// has no outline attributes yet.
|
|
787
|
+
// So nothing that copies, merges or instances the model afterwards
|
|
788
|
+
// (pxmodel.js, optimize.js, world3d.js) has anything to catch up on: copies
|
|
789
|
+
// share the geometry and the hull's material. Once the task has run, the
|
|
790
|
+
// attributes hold what baking at once would have put there.
|
|
791
|
+
//
|
|
792
|
+
// What the task bakes from is written down when the model is built: each
|
|
793
|
+
// surface's geometry and where it stood then. The model is moved afterwards,
|
|
794
|
+
// under a model that references it and by its own animation.
|
|
795
|
+
|
|
796
|
+
// The queue and the owner of the model being built, what its look is waiting
|
|
797
|
+
// for, and the merged geometries met since the last look was applied; null
|
|
798
|
+
// when baking is done at once.
|
|
799
|
+
let later = null;
|
|
800
|
+
|
|
801
|
+
// Runs `build`, which builds a model; the baking its look needs is queued on
|
|
802
|
+
// `queue` (lookbake.js) as `owner`'s instead of being done.
|
|
803
|
+
export function bakingLater(queue, owner, build) {
|
|
804
|
+
const outer = later;
|
|
805
|
+
later = { queue, owner, waiting: null, merged: [] };
|
|
806
|
+
try {
|
|
807
|
+
return build();
|
|
808
|
+
} finally {
|
|
809
|
+
later = outer;
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
// Geometries with an outline whose attributes are still to bake, each with
|
|
814
|
+
// the materials of the hulls drawn from it; and, for a geometry merged from
|
|
815
|
+
// parts, where each part lies in it.
|
|
816
|
+
const outlinesWaiting = new WeakMap();
|
|
817
|
+
const mergedParts = new WeakMap();
|
|
818
|
+
|
|
819
|
+
// `parts` is what `outlinePartByPart` returned for the geometries `geometry`
|
|
820
|
+
// was merged from. Its attributes are baked whether or not a hull is drawn
|
|
821
|
+
// from it, as they are when baking at once.
|
|
822
|
+
export function outlineMergedLater(geometry, parts) {
|
|
823
|
+
mergedParts.set(geometry, parts);
|
|
824
|
+
outlinesWaiting.set(geometry, []);
|
|
825
|
+
later.merged.push(geometry);
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
const placedAsNow = (mesh) => ({ geometry: mesh.geometry, matrixWorld: mesh.matrixWorld.clone() });
|
|
829
|
+
|
|
830
|
+
// Leaves the occlusion of `firsts`, one mesh per geometry, to be baked later.
|
|
831
|
+
// False when the model has no surface to bake against, which takes no time
|
|
832
|
+
// to find out at once.
|
|
833
|
+
function waitForOcclusion(root, model, shape, firsts) {
|
|
834
|
+
const surfaces = surfacesOf(root).map(placedAsNow);
|
|
835
|
+
if (!surfaces.some(({ geometry }) => geometry.getAttribute('position').count > 0)) {
|
|
836
|
+
return false;
|
|
837
|
+
}
|
|
838
|
+
const targets = firsts.map(placedAsNow);
|
|
839
|
+
for (const { geometry } of targets) {
|
|
840
|
+
if (!geometry.getAttribute('normal')) {
|
|
841
|
+
geometry.computeVertexNormals();
|
|
842
|
+
}
|
|
843
|
+
const open = new Float32Array(geometry.getAttribute('position').count).fill(1);
|
|
844
|
+
geometry.setAttribute('lookOcclusion', new THREE.BufferAttribute(open, 1));
|
|
845
|
+
}
|
|
846
|
+
later.waiting.occlusion = { model, shape, surfaces, targets };
|
|
847
|
+
return true;
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
function waitForOutline(geometry, material) {
|
|
851
|
+
let hidden = outlinesWaiting.get(geometry);
|
|
852
|
+
if (!hidden) {
|
|
853
|
+
if (!geometry.getAttribute('normal')) {
|
|
854
|
+
geometry.computeVertexNormals();
|
|
855
|
+
}
|
|
856
|
+
hidden = [];
|
|
857
|
+
outlinesWaiting.set(geometry, hidden);
|
|
858
|
+
later.waiting.outlines.push(geometry);
|
|
859
|
+
}
|
|
860
|
+
hideUntilBaked(material, hidden);
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
// A copy made of the material meanwhile (pxmodel.js gives a recolored copy
|
|
864
|
+
// of a part its own) waits with it.
|
|
865
|
+
function hideUntilBaked(material, hidden) {
|
|
866
|
+
material.visible = false;
|
|
867
|
+
hidden.push(material);
|
|
868
|
+
material.clone = function () {
|
|
869
|
+
const own = THREE.Material.prototype.clone.call(this);
|
|
870
|
+
hideUntilBaked(own, hidden);
|
|
871
|
+
return own;
|
|
872
|
+
};
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
function queueWaiting(waiting) {
|
|
876
|
+
const { queue, owner } = later;
|
|
877
|
+
later.waiting = null;
|
|
878
|
+
const geometries = new Set(waiting.outlines);
|
|
879
|
+
for (const { geometry } of waiting.occlusion?.targets ?? []) {
|
|
880
|
+
geometries.add(geometry);
|
|
881
|
+
}
|
|
882
|
+
if (geometries.size === 0) {
|
|
883
|
+
return;
|
|
884
|
+
}
|
|
885
|
+
const bake = {
|
|
886
|
+
waiting,
|
|
887
|
+
gone: null,
|
|
888
|
+
vertices: new Map([...geometries].map((geometry) => [geometry, geometry.getAttribute('position').count])),
|
|
889
|
+
copies: new Map(),
|
|
890
|
+
results: new Map(),
|
|
891
|
+
given: new WeakMap(),
|
|
892
|
+
};
|
|
893
|
+
const steps = (gone) => {
|
|
894
|
+
bake.gone = gone;
|
|
895
|
+
return bakeLater(bake);
|
|
896
|
+
};
|
|
897
|
+
queueLookBake(queue, owner, [...geometries], steps, (copy, geometry, source) => copied(bake, copy, geometry, source));
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
// One task's baking (lookbake.js states what it keeps to). Of each geometry
|
|
901
|
+
// the task was queued with:
|
|
902
|
+
// - `vertices`: how many vertices it had then;
|
|
903
|
+
// - `copies`: the copies made of it since, and of its copies;
|
|
904
|
+
// - `results`: what each stage that has finished for it gives a geometry,
|
|
905
|
+
// by the stage's name, `occlusion` or `outline`. A result is held here and
|
|
906
|
+
// not read back from a geometry, which may have been disposed unwritten.
|
|
907
|
+
// And of every geometry, copies included, `given`: the stages it holds. So a
|
|
908
|
+
// stage is given to a geometry once, whenever the two meet: when the stage
|
|
909
|
+
// finishes (`finish`) or when the copy is made (`copied`).
|
|
910
|
+
|
|
911
|
+
// The geometries the baking of `geometry` is given to: itself and its
|
|
912
|
+
// copies, in that order, leaving out every one disposed (`gone`) and any
|
|
913
|
+
// that no longer has the vertices it was built with.
|
|
914
|
+
function writtenNow(bake, geometry) {
|
|
915
|
+
const count = bake.vertices.get(geometry);
|
|
916
|
+
const held = [geometry, ...(bake.copies.get(geometry) ?? [])];
|
|
917
|
+
return held.filter((one) => !bake.gone.has(one) && one.getAttribute('position')?.count === count);
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
// Gives each of them every finished stage it does not hold. A hull is shown
|
|
921
|
+
// once something it can be drawn from has its outline attributes; while the
|
|
922
|
+
// geometry and all its copies are gone its material stays as it is, not drawn.
|
|
923
|
+
function settle(bake, geometry) {
|
|
924
|
+
const results = bake.results.get(geometry);
|
|
925
|
+
const written = results ? writtenNow(bake, geometry) : [];
|
|
926
|
+
for (const held of written) {
|
|
927
|
+
const given = bake.given.get(held) ?? new Set();
|
|
928
|
+
bake.given.set(held, given);
|
|
929
|
+
for (const [stage, give] of results) {
|
|
930
|
+
if (!given.has(stage)) {
|
|
931
|
+
give(held, held === geometry);
|
|
932
|
+
given.add(stage);
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
const hidden = outlinesWaiting.get(geometry);
|
|
937
|
+
if (hidden && written.length > 0 && results.has('outline')) {
|
|
938
|
+
for (const material of hidden) {
|
|
939
|
+
material.visible = true;
|
|
940
|
+
delete material.clone;
|
|
941
|
+
}
|
|
942
|
+
outlinesWaiting.delete(geometry);
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
// A stage has finished for `geometry`: `give(held, own)` puts its result into
|
|
947
|
+
// one geometry, `own` when that is `geometry` itself.
|
|
948
|
+
function finish(bake, geometry, stage, give) {
|
|
949
|
+
const results = bake.results.get(geometry) ?? new Map();
|
|
950
|
+
bake.results.set(geometry, results);
|
|
951
|
+
results.set(stage, give);
|
|
952
|
+
settle(bake, geometry);
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
// `copy` was made of `source`, which is `geometry` or a copy of it
|
|
956
|
+
// (lookbake.js): it holds what `source` held, and is given the rest.
|
|
957
|
+
function copied(bake, copy, geometry, source) {
|
|
958
|
+
const copies = bake.copies.get(geometry) ?? [];
|
|
959
|
+
bake.copies.set(geometry, copies);
|
|
960
|
+
copies.push(copy);
|
|
961
|
+
bake.given.set(copy, new Set(bake.given.get(source)));
|
|
962
|
+
settle(bake, geometry);
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
// Whether an outline is still to be worked out for `geometry`: nothing has
|
|
966
|
+
// been, something is left to give it to, and the geometry it is worked out
|
|
967
|
+
// from is as it was built.
|
|
968
|
+
function outlineStillWanted(bake, geometry) {
|
|
969
|
+
const asBuilt = geometry.getAttribute('position')?.count === bake.vertices.get(geometry);
|
|
970
|
+
return asBuilt && !bake.results.get(geometry)?.has('outline') && writtenNow(bake, geometry).length > 0;
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
// One model's baking, a step at a time. The outlines are gone over until
|
|
974
|
+
// none is wanted, since a copy can be made of a geometry passed over because
|
|
975
|
+
// it and its copies were gone. Returns whether every geometry of the task
|
|
976
|
+
// that is not disposed, copies included, holds every stage: false when one
|
|
977
|
+
// was left because its vertices were replaced.
|
|
978
|
+
function* bakeLater(bake) {
|
|
979
|
+
const { occlusion, outlines } = bake.waiting;
|
|
980
|
+
if (occlusion) {
|
|
981
|
+
yield* occlusionLater(occlusion, bake);
|
|
982
|
+
}
|
|
983
|
+
for (let wanted = true; wanted; ) {
|
|
984
|
+
wanted = false;
|
|
985
|
+
for (const geometry of outlines) {
|
|
986
|
+
if (outlineStillWanted(bake, geometry)) {
|
|
987
|
+
wanted = true;
|
|
988
|
+
yield* outlineLater(geometry, bake);
|
|
989
|
+
yield;
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
return everyStageGiven(bake);
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
// Whether every geometry of the task that is not disposed holds every stage
|
|
997
|
+
// of the geometry it is, or is a copy of: those finished, and an outline
|
|
998
|
+
// that was waited for and never worked out.
|
|
999
|
+
function everyStageGiven(bake) {
|
|
1000
|
+
const waited = new Set(bake.waiting.outlines);
|
|
1001
|
+
for (const [geometry] of bake.vertices) {
|
|
1002
|
+
const results = bake.results.get(geometry);
|
|
1003
|
+
const stages = (results?.size ?? 0) + (waited.has(geometry) && !results?.has('outline') ? 1 : 0);
|
|
1004
|
+
const held = [geometry, ...(bake.copies.get(geometry) ?? [])];
|
|
1005
|
+
if (held.some((one) => !bake.gone.has(one) && (bake.given.get(one)?.size ?? 0) < stages)) {
|
|
1006
|
+
return false;
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
return true;
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
// How many vertices cast their rays in one step: small beside the budget
|
|
1013
|
+
// (lookbake.js), so a long geometry does not hold a frame up.
|
|
1014
|
+
const VERTICES_A_STEP = 128;
|
|
1015
|
+
|
|
1016
|
+
// `bakeOcclusion`, from what was written down. Another build of the model
|
|
1017
|
+
// may have baked it since. The values take the place of the 1s in the
|
|
1018
|
+
// attribute that is already there, and already on the GPU, rather than in a
|
|
1019
|
+
// new one; a copy of the geometry gets values of its own, as a copy of a
|
|
1020
|
+
// baked geometry has.
|
|
1021
|
+
function* occlusionLater({ model, shape, surfaces, targets }, bake) {
|
|
1022
|
+
let cached = occlusionCache.get(model);
|
|
1023
|
+
if (!cached || cached.shape !== shape) {
|
|
1024
|
+
const opened = openGrid(surfaces);
|
|
1025
|
+
yield;
|
|
1026
|
+
for (const surface of opened?.surfaces ?? []) {
|
|
1027
|
+
markTriangles(opened.grid, surface);
|
|
1028
|
+
yield;
|
|
1029
|
+
}
|
|
1030
|
+
const values = [];
|
|
1031
|
+
for (const target of targets) {
|
|
1032
|
+
const count = target.geometry.getAttribute('position').count;
|
|
1033
|
+
const out = opened ? new Float32Array(count) : null;
|
|
1034
|
+
for (let from = 0; opened && from < count; from += VERTICES_A_STEP) {
|
|
1035
|
+
castRays(target, opened.grid, out, from, Math.min(count, from + VERTICES_A_STEP));
|
|
1036
|
+
yield;
|
|
1037
|
+
}
|
|
1038
|
+
values.push(out);
|
|
1039
|
+
}
|
|
1040
|
+
cached = { shape, values };
|
|
1041
|
+
occlusionCache.set(model, cached);
|
|
1042
|
+
}
|
|
1043
|
+
targets.forEach(({ geometry }, index) => {
|
|
1044
|
+
const values = cached.values[index];
|
|
1045
|
+
if (!values) {
|
|
1046
|
+
return;
|
|
1047
|
+
}
|
|
1048
|
+
finish(bake, geometry, 'occlusion', (held, own) => {
|
|
1049
|
+
const attribute = held.getAttribute('lookOcclusion');
|
|
1050
|
+
if (attribute) {
|
|
1051
|
+
attribute.array = own ? values : values.slice();
|
|
1052
|
+
attribute.needsUpdate = true;
|
|
1053
|
+
}
|
|
1054
|
+
});
|
|
1055
|
+
});
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
// How many vertices, or triangle corners, of a geometry's outline are done
|
|
1059
|
+
// in one step. A multiple of 3, so a stretch of corners is whole triangles.
|
|
1060
|
+
const OUTLINE_STEP = 384;
|
|
1061
|
+
|
|
1062
|
+
function* stretches(total) {
|
|
1063
|
+
for (let from = 0; from < total; from += OUTLINE_STEP) {
|
|
1064
|
+
yield [from, Math.min(total, from + OUTLINE_STEP)];
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
// `addOutlineAttributes`, a stretch at a time, in the same order, up to
|
|
1069
|
+
// setting the attributes: it returns what `setOutlineAttributes` takes.
|
|
1070
|
+
function* outlineSteps(geometry) {
|
|
1071
|
+
const work = outlineWork(geometry);
|
|
1072
|
+
for (const [from, to] of stretches(work.positions.count)) {
|
|
1073
|
+
sumNormalsByPosition(work, from, to);
|
|
1074
|
+
yield;
|
|
1075
|
+
}
|
|
1076
|
+
smoothNormals(work);
|
|
1077
|
+
for (const [from, to] of stretches(work.count)) {
|
|
1078
|
+
curvatureRadii(work, from, to);
|
|
1079
|
+
yield;
|
|
1080
|
+
}
|
|
1081
|
+
for (let pass = 0; pass < UNEVEN_PASSES; pass++) {
|
|
1082
|
+
for (const [from, to] of stretches(work.count)) {
|
|
1083
|
+
evenOutFolds(work, from, to);
|
|
1084
|
+
yield;
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
return work;
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
// The outline attributes of a waiting geometry, worked out from it as
|
|
1091
|
+
// `addOutlineAttributes` does, or for one merged from parts, part by part, as
|
|
1092
|
+
// `outlinePartByPart` does it before the merge; then given to it and its
|
|
1093
|
+
// copies (`finish`), a copy in arrays of its own. A geometry that has them
|
|
1094
|
+
// already, baked at once by another build, gives its copies those.
|
|
1095
|
+
function* outlineLater(geometry, bake) {
|
|
1096
|
+
let from = geometry;
|
|
1097
|
+
if (!geometry.getAttribute('lookOutlineNormal')) {
|
|
1098
|
+
const parts = mergedParts.get(geometry);
|
|
1099
|
+
from = yield* parts ? mergedOutline(geometry, parts) : wholeOutline(geometry);
|
|
1100
|
+
mergedParts.delete(geometry);
|
|
1101
|
+
} else if (!bake.gone.has(geometry)) {
|
|
1102
|
+
bake.given.set(geometry, new Set(bake.given.get(geometry)).add('outline'));
|
|
1103
|
+
}
|
|
1104
|
+
const normal = from.getAttribute('lookOutlineNormal').array;
|
|
1105
|
+
const reach = from.getAttribute('lookOutlineReach').array;
|
|
1106
|
+
finish(bake, geometry, 'outline', (held, own) => {
|
|
1107
|
+
held.setAttribute('lookOutlineNormal', new THREE.BufferAttribute(own ? normal : normal.slice(), 3));
|
|
1108
|
+
held.setAttribute('lookOutlineReach', new THREE.BufferAttribute(own ? reach : reach.slice(), 1));
|
|
1109
|
+
});
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
// Each returns a geometry of its own that holds the two attributes, whatever
|
|
1113
|
+
// has become of `geometry` meanwhile.
|
|
1114
|
+
function* wholeOutline(geometry) {
|
|
1115
|
+
const made = new THREE.BufferGeometry();
|
|
1116
|
+
setOutlineAttributes(made, yield* outlineSteps(geometry));
|
|
1117
|
+
return made;
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
function* mergedOutline(geometry, parts) {
|
|
1121
|
+
const positions = geometry.getAttribute('position');
|
|
1122
|
+
const normals = geometry.getAttribute('normal');
|
|
1123
|
+
const index = geometry.getIndex();
|
|
1124
|
+
const smooth = new Float32Array(positions.count * 3);
|
|
1125
|
+
const reach = new Float32Array(positions.count);
|
|
1126
|
+
for (const { vertex, vertices, corner, corners } of parts) {
|
|
1127
|
+
const part = new THREE.BufferGeometry();
|
|
1128
|
+
for (const [name, attribute] of [['position', positions], ['normal', normals]]) {
|
|
1129
|
+
const own = attribute.array.subarray(vertex * 3, (vertex + vertices) * 3);
|
|
1130
|
+
part.setAttribute(name, new THREE.BufferAttribute(own, 3));
|
|
1131
|
+
}
|
|
1132
|
+
part.setIndex(Array.from(index.array.subarray(corner, corner + corners), (at) => at - vertex));
|
|
1133
|
+
setOutlineAttributes(part, yield* outlineSteps(part));
|
|
1134
|
+
smooth.set(part.getAttribute('lookOutlineNormal').array, vertex * 3);
|
|
1135
|
+
reach.set(part.getAttribute('lookOutlineReach').array, vertex);
|
|
1136
|
+
}
|
|
1137
|
+
const made = new THREE.BufferGeometry();
|
|
1138
|
+
made.setAttribute('lookOutlineNormal', new THREE.BufferAttribute(smooth, 3));
|
|
1139
|
+
made.setAttribute('lookOutlineReach', new THREE.BufferAttribute(reach, 1));
|
|
1140
|
+
return made;
|
|
1141
|
+
}
|