castle-web-cli 0.4.237 → 0.4.238
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/bundle.d.ts +24 -0
- package/dist/bundle.js +447 -4
- package/dist/bundleLatin1.d.ts +6 -0
- package/dist/bundleLatin1.js +333 -0
- package/dist/castle-host/host.d.ts +10 -1
- package/dist/castle-host/host.js +78 -9
- package/dist/castleJson.d.ts +2 -0
- package/dist/castleJson.js +1 -0
- package/dist/deckExports.d.ts +35 -0
- package/dist/deckExports.js +365 -0
- package/dist/importCheckHook.d.ts +1 -0
- package/dist/importCheckHook.js +1 -1
- package/dist/index.js +5 -0
- package/dist/init.js +2 -1
- package/dist/save-deck.js +4 -0
- package/kits/base/castle.json +1 -1
- package/kits/base/sdk/README.md +47 -0
- package/kits/base/sdk/castle.d.ts +3 -1
- package/kits/base/sdk/castle.js +1 -0
- package/kits/base/sdk/commands.d.ts +25 -1
- package/kits/base/sdk/commands.js +29 -1
- package/kits/base/sdk/hub.d.ts +17 -0
- package/kits/base/sdk/hub.js +33 -9
- package/kits/base/sdk/localCache.d.ts +27 -0
- package/kits/base/sdk/localCache.js +115 -0
- package/kits/base/sdk/localCacheStore.d.ts +15 -0
- package/kits/base/sdk/localCacheStore.js +358 -0
- package/kits/base/sdk/transport.d.ts +1 -0
- package/kits/base/sdk/transport.js +4 -5
- package/kits/hub-game/CLAUDE.md +22 -2
- package/kits/hub-game/castle.json +4 -1
- package/kits/hub-game/code/client/act.js +66 -91
- package/kits/hub-game/code/client/actCore.js +134 -0
- package/kits/hub-game/code/client/car.js +35 -0
- package/kits/hub-game/code/client/chrome.js +207 -381
- package/kits/hub-game/code/client/crowdNames.js +2 -2
- package/kits/hub-game/code/client/emoteWheel.js +109 -0
- package/kits/hub-game/code/client/hats.js +2 -0
- package/kits/hub-game/code/client/hookLayer.js +99 -48
- package/kits/hub-game/code/client/hostGo.js +77 -0
- package/kits/hub-game/code/client/hubControls.js +125 -0
- package/kits/hub-game/code/client/hubEntry.js +187 -0
- package/kits/hub-game/code/client/hudSurface.js +148 -0
- package/kits/hub-game/code/client/hudTree.js +96 -0
- package/kits/hub-game/code/client/idle.js +59 -13
- package/kits/hub-game/code/client/invites.js +13 -4
- package/kits/hub-game/code/client/menuIcons.js +8 -0
- package/kits/hub-game/code/client/noTrips.js +38 -0
- package/kits/hub-game/code/client/qualityEntry.js +6 -1
- package/kits/hub-game/code/client/rehello.js +3 -1
- package/kits/hub-game/code/client/riders.js +26 -0
- package/kits/hub-game/code/client/role.js +79 -0
- package/kits/hub-game/code/client/safeLayout.js +32 -3
- package/kits/hub-game/code/client/sound.js +10 -3
- package/kits/hub-game/code/client/soundscape.js +2 -2
- package/kits/hub-game/code/client/soundscapeAmbience.js +38 -8
- package/kits/hub-game/code/client/soundscapeBaked.js +24 -5
- package/kits/hub-game/code/client/soundscapeCues.js +2 -1
- package/kits/hub-game/code/client/state.js +19 -0
- package/kits/hub-game/code/client/stuck.js +2 -1
- package/kits/hub-game/code/client/talkSurface.js +178 -0
- package/kits/hub-game/code/client/talkTree.js +238 -0
- package/kits/hub-game/code/client/tiers.js +8 -5
- package/kits/hub-game/code/client/uiDom.js +600 -0
- package/kits/hub-game/code/client/uiTree.js +359 -0
- package/kits/hub-game/code/client/vehicle.js +154 -0
- package/kits/hub-game/code/client/wear.js +27 -5
- package/kits/hub-game/code/client/worldLabels.js +3 -2
- package/kits/hub-game/code/client/yours.js +10 -3
- package/kits/hub-game/code/server/actors.js +4 -3
- package/kits/hub-game/code/server/analytics.js +56 -6
- package/kits/hub-game/code/server/decor.js +56 -16
- package/kits/hub-game/code/server/hub.js +258 -46
- package/kits/hub-game/code/server/idle.js +118 -5
- package/kits/hub-game/code/server/manifest.js +46 -4
- package/kits/hub-game/code/server/npcs.js +4 -2
- package/kits/hub-game/code/server/players.js +3 -0
- package/kits/hub-game/code/server/role.js +142 -0
- package/kits/hub-game/code/server/standing.js +6 -4
- package/kits/hub-game/code/server/vehicle.js +126 -0
- package/kits/hub-game/code/shared/car.js +52 -0
- package/kits/hub-game/code/shared/deckFlags.js +34 -0
- package/kits/hub-game/code/shared/deviceClass.js +39 -0
- package/kits/hub-game/code/shared/expression.js +9 -0
- package/kits/hub-game/code/systems/hub.js +272 -84
- package/kits/hub-game/docs/analytics.md +11 -2
- package/kits/hub-game/docs/contract.md +352 -14
- package/kits/hub-game/docs/vehicle-preset.md +132 -0
- package/kits/hub-game/models/hats/baker-cap.pxmodel +89 -0
- package/kits/hub-game/models/hats/chef-toque.pxmodel +60 -0
- package/kits/hub-game/models/hats/delivery-cap.pxmodel +105 -0
- package/kits/hub-game/models/hats/fire-helmet.pxmodel +87 -0
- package/kits/hub-game/models/hats/hard-hat.pxmodel +71 -0
- package/kits/hub-game/models/hats/nurse-cap.pxmodel +61 -0
- package/kits/hub-game/models/hats/police-cap.pxmodel +105 -0
- package/kits/hub-game/models/hats/teacher-beret.pxmodel +52 -0
- package/kits/hub-game/models/role/square/top-apron.pxmodel +109 -0
- package/kits/hub-game/models/role/square/top-cardigan.pxmodel +141 -0
- package/kits/hub-game/models/role/square/top-coat.pxmodel +157 -0
- package/kits/hub-game/models/role/square/top-scrubs.pxmodel +93 -0
- package/kits/hub-game/models/role/square/top-tabard.pxmodel +109 -0
- package/kits/hub-game/models/role/square/top-vest.pxmodel +109 -0
- package/kits/hub-game/models/role/tool-bag.pxmodel +75 -0
- package/kits/hub-game/models/role/tool-bell.pxmodel +71 -0
- package/kits/hub-game/models/role/tool-hose.pxmodel +60 -0
- package/kits/hub-game/models/role/tool-parcel.pxmodel +61 -0
- package/kits/hub-game/models/role/tool-torch.pxmodel +55 -0
- package/kits/hub-game/models/role/tool-tray.pxmodel +75 -0
- package/kits/hub-game/models/role/top-apron.pxmodel +70 -0
- package/kits/hub-game/models/role/top-cardigan.pxmodel +102 -0
- package/kits/hub-game/models/role/top-coat.pxmodel +79 -0
- package/kits/hub-game/models/role/top-scrubs.pxmodel +54 -0
- package/kits/hub-game/models/role/top-tabard.pxmodel +70 -0
- package/kits/hub-game/models/role/top-vest.pxmodel +70 -0
- package/kits/hub-game/package-lock.json +1 -1
- package/kits/hub-game/package.json +1 -1
- package/kits/hub-game/scripts/check.mjs +7 -4
- package/kits/hub-game/scripts/fixtures/car-vectors.json +279 -0
- package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +2 -1
- package/kits/hub-game/scripts/fixtures/hud-surface.json +670 -0
- package/kits/hub-game/scripts/fixtures/talk-surface.json +3930 -0
- package/kits/hub-game/scripts/gen-hats.mjs +46 -2
- package/kits/hub-game/scripts/gen-role.mjs +80 -0
- package/kits/hub-game/scripts/test-act-core.mjs +167 -0
- package/kits/hub-game/scripts/test-actions-client.mjs +34 -0
- package/kits/hub-game/scripts/test-actors.mjs +48 -0
- package/kits/hub-game/scripts/test-analytics.mjs +99 -5
- package/kits/hub-game/scripts/test-apply-deck.mjs +122 -0
- package/kits/hub-game/scripts/test-back-visibility.mjs +3 -1
- package/kits/hub-game/scripts/test-ballot.mjs +2 -0
- package/kits/hub-game/scripts/test-car.mjs +43 -0
- package/kits/hub-game/scripts/test-decor-client.mjs +2 -1
- package/kits/hub-game/scripts/test-decor.mjs +77 -0
- package/kits/hub-game/scripts/test-device-class.mjs +83 -0
- package/kits/hub-game/scripts/test-emote-wheel.mjs +374 -0
- package/kits/hub-game/scripts/test-hats.mjs +5 -4
- package/kits/hub-game/scripts/test-host-go.mjs +265 -0
- package/kits/hub-game/scripts/test-hub-controls.mjs +108 -0
- package/kits/hub-game/scripts/test-hub-entry.mjs +531 -0
- package/kits/hub-game/scripts/test-hub-ops.mjs +75 -0
- package/kits/hub-game/scripts/test-hud-clear.mjs +12 -2
- package/kits/hub-game/scripts/test-hud-rate.mjs +6 -2
- package/kits/hub-game/scripts/test-hud-surface.mjs +272 -0
- package/kits/hub-game/scripts/test-idle.mjs +347 -1
- package/kits/hub-game/scripts/test-interest-cells.mjs +8 -1
- package/kits/hub-game/scripts/test-invites-client.mjs +42 -1
- package/kits/hub-game/scripts/test-manifest.mjs +30 -0
- package/kits/hub-game/scripts/test-no-trips.mjs +42 -0
- package/kits/hub-game/scripts/test-placement-cache.mjs +1 -1
- package/kits/hub-game/scripts/test-quality.mjs +13 -0
- package/kits/hub-game/scripts/test-rehello.mjs +258 -3
- package/kits/hub-game/scripts/test-resume-pose-server.mjs +203 -0
- package/kits/hub-game/scripts/test-resync.mjs +183 -0
- package/kits/hub-game/scripts/test-role-client.mjs +421 -0
- package/kits/hub-game/scripts/test-role.mjs +350 -0
- package/kits/hub-game/scripts/test-safe-layout.mjs +50 -1
- package/kits/hub-game/scripts/test-soundscape.mjs +124 -7
- package/kits/hub-game/scripts/test-standing.mjs +15 -1
- package/kits/hub-game/scripts/test-talk-surface.mjs +296 -0
- package/kits/hub-game/scripts/test-tiers.mjs +13 -0
- package/kits/hub-game/scripts/test-ui-dom-dom.mjs +96 -0
- package/kits/hub-game/scripts/test-ui-tree.mjs +711 -0
- package/kits/hub-game/scripts/test-vehicle-client.mjs +159 -0
- package/kits/hub-game/scripts/test-vehicle.mjs +135 -0
- package/kits/hub-game/scripts/test-yours.mjs +33 -0
- package/kits/hub-game/tools/hubScene/export.mjs +613 -0
- package/kits/hub-game/tools/hubScene/hubdata.mjs +921 -0
- package/kits/hub-game/tools/hubScene/merge-root.mjs +39 -0
- package/kits/hub-game/tools/hubScene/nodeworld.mjs +227 -0
- package/kits/hub-game/tools/hubScene/test/export-fixture.mjs +798 -0
- package/kits/hub-game/tools/hubScene/test/fixture.json +637 -0
- package/kits/hub-game/tools/hubScene/test/paint-export.mjs +40 -0
- package/kits/hub-game/tools/hubScene/test/upload.test.mjs +655 -0
- package/kits/hub-game/tools/hubScene/upload.mjs +636 -0
- package/kits/hub-game/tools/hubScene/validate-manifest.mjs +291 -0
- package/kits/multiplayer-3d/castle.json +4 -4
- package/kits/multiplayer-3d/code/client/resumeGate.js +30 -2
- package/kits/multiplayer-3d/code/client/steer.js +3 -1
- package/kits/multiplayer-3d/code/systems/multiplayer.js +30 -2
- package/kits/multiplayer-3d/package-lock.json +1 -1
- package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +74 -2
- package/kits/physics-3d/CLAUDE.md +1 -1
- package/kits/physics-3d/behaviors/Player.jsx +37 -27
- package/kits/physics-3d/castle.json +2 -2
- package/kits/physics-3d/docs/engine-geometry-memory.md +23 -0
- package/kits/physics-3d/engine3d/memoryprofile.js +17 -0
- package/kits/physics-3d/engine3d/playerRun.js +6 -1
- package/kits/physics-3d/engine3d/pxmodel.js +6 -1
- package/kits/physics-3d/engine3d/world3d.js +6 -3
- package/kits/physics-3d/package.json +1 -1
- package/kits/physics-3d/play/behaviors/Player.js +40 -28
- package/kits/physics-3d/scripts/test-memory-profile.mjs +237 -0
- package/kits/physics-3d/systems/physics3d.js +5 -2
- package/kits/real-time/castle.json +2 -2
- package/kits/real-time/code/client/messages.js +5 -0
- package/kits/real-time/code/server/session.js +28 -1
- package/kits/real-time/package-lock.json +1 -1
- package/package.json +5 -4
- package/vendor/three/LICENSE +21 -0
- package/vendor/three/build/three.core.js +58773 -0
- package/vendor/three/build/three.module.js +18251 -0
- package/vendor/three/examples/jsm/controls/OrbitControls.js +1860 -0
- package/vendor/three/examples/jsm/controls/TransformControls.js +1918 -0
- package/vendor/three/examples/jsm/exporters/GLTFExporter.js +3595 -0
- package/vendor/three/examples/jsm/geometries/RoundedBoxGeometry.js +216 -0
- package/vendor/three/examples/jsm/math/MeshSurfaceSampler.js +315 -0
- package/vendor/three/examples/jsm/postprocessing/EffectComposer.js +363 -0
- package/vendor/three/examples/jsm/postprocessing/MaskPass.js +195 -0
- package/vendor/three/examples/jsm/postprocessing/OutputPass.js +139 -0
- package/vendor/three/examples/jsm/postprocessing/Pass.js +191 -0
- package/vendor/three/examples/jsm/postprocessing/RenderPass.js +183 -0
- package/vendor/three/examples/jsm/postprocessing/ShaderPass.js +135 -0
- package/vendor/three/examples/jsm/shaders/CopyShader.js +52 -0
- package/vendor/three/examples/jsm/shaders/OutputShader.js +103 -0
- package/vendor/three/examples/jsm/utils/BufferGeometryUtils.js +1435 -0
- package/vendor/three/package.json +134 -0
|
@@ -0,0 +1,921 @@
|
|
|
1
|
+
// What a hub's runtime holds, and the HubSceneManifest (v1.7) made from it. Ported from the native
|
|
2
|
+
// hub prototype's live-page and content-pack exporters; here it runs in Node over a world that
|
|
3
|
+
// nodeworld.mjs built from a deck folder (export.mjs). collectHubData still uses nothing outside
|
|
4
|
+
// itself, so it can also run in a page's frame.
|
|
5
|
+
|
|
6
|
+
const round = (n) => (typeof n === 'number' ? Math.round(n * 1e4) / 1e4 : n);
|
|
7
|
+
|
|
8
|
+
// v1.7: use the client's catalogue, fallback and converter, without running its renderer.
|
|
9
|
+
// modelFiles lists the shipped kit's wear models; files is nodeworld.mjs's keyed data reader.
|
|
10
|
+
export async function collectAvatarWear({ files, modelFiles, putShared }) {
|
|
11
|
+
const Avatar = await import('../../code/client/avatar.js');
|
|
12
|
+
const Earned = await import('../../code/client/earned.js');
|
|
13
|
+
const Role = await import('../../code/client/role.js');
|
|
14
|
+
const { buildModelNode, parseModelCached } = await import('@imports/castle.physics-3d/engine3d/pxmodel');
|
|
15
|
+
const { GLTFExporter } = globalThis.__expLib;
|
|
16
|
+
const avatarFits = Object.fromEntries(Avatar.STYLES.map((style) => [style,
|
|
17
|
+
Array.from({ length: Avatar.AVATARS }, (_, index) => {
|
|
18
|
+
const drawnFrom = Avatar.drawn(files, index, style);
|
|
19
|
+
return { drawnFrom, ...Avatar.earnedFit(index, drawnFrom), hat: Avatar.hatFit(index, drawnFrom), top: Avatar.top(index, drawnFrom) };
|
|
20
|
+
}),
|
|
21
|
+
]));
|
|
22
|
+
const wearModels = {};
|
|
23
|
+
for (const rel of modelFiles) {
|
|
24
|
+
const file = `imports/castle.hub-game/${rel}`;
|
|
25
|
+
const model = parseModelCached(files[file]);
|
|
26
|
+
if (!model) throw new Error(`wear model ${file}: not a model`);
|
|
27
|
+
// No tint or fit transform: native replaces the main colour and places the model.
|
|
28
|
+
const node = buildModelNode(model, null, files, file, [file], { optimize: true });
|
|
29
|
+
try {
|
|
30
|
+
const id = rel.slice('models/'.length, -'.pxmodel'.length).replace(/^hats\//, 'hat/');
|
|
31
|
+
wearModels[id] = putShared(Buffer.from(await new GLTFExporter().parseAsync(node, { binary: true, onlyVisible: true })), 'glb');
|
|
32
|
+
} finally {
|
|
33
|
+
const resources = new Set();
|
|
34
|
+
node.traverse((object) => {
|
|
35
|
+
for (const resource of [object.geometry, ...[object.material].flat()]) {
|
|
36
|
+
if (resource && !resources.has(resource)) { resources.add(resource); resource.dispose(); }
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const wearPieces = {};
|
|
42
|
+
const placement = {
|
|
43
|
+
badge: 'Chest position and yaw from fit; uniform scale times optional chest size; badge glow from earnedLook. Badge and pin classes may share chest shapes.',
|
|
44
|
+
pin: 'Chest position and yaw from fit; uniform scale times optional chest size. Badge and pin classes may share chest shapes.',
|
|
45
|
+
belt: 'Waist [y, rx, rz]; stretch the model ring to rx/rz, keeping its height; use square model only when fit.square.',
|
|
46
|
+
sash: 'Sash [y, a, rz, tilt]; stretch ring to a/rz, then tilt by -tilt about z; use square model only when fit.square.',
|
|
47
|
+
held: 'Hand [x, y, z] from fit; uniform scale about the model grip.',
|
|
48
|
+
top: 'Fit-dependent band from waist to just below chest; one-piece bodies get a short band below chest. Width max(waist rx, sash horizontal reach), depth max(waist rz, sash rz); stretch model as roleLook; square model only when fit.square.',
|
|
49
|
+
tool: 'Hand [x, y, z] from fit; uniform scale about the model grip.',
|
|
50
|
+
};
|
|
51
|
+
for (const shape of Earned.EARNED_SHAPES) {
|
|
52
|
+
const cls = Earned.EARNED_SHAPE_CLASS[shape];
|
|
53
|
+
const look = Earned.earnedLook({ class: cls, shape, color: Earned.EARNED_MAIN });
|
|
54
|
+
const ring = cls === 'belt' || cls === 'sash';
|
|
55
|
+
wearPieces[`earned/${shape}`] = {
|
|
56
|
+
anchor: cls === 'badge' || cls === 'pin' ? 'chest' : cls === 'held' ? 'hand' : cls === 'belt' ? 'waist' : 'sash',
|
|
57
|
+
// Rings have no uniform enlargement: their x/z scale depends on the avatar fit.
|
|
58
|
+
scale: look.scale[ring ? 1 : 0], tint: Earned.EARNED_MAIN, placement: placement[cls],
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
for (const [kind, ids] of [['top', Role.ROLE_TOPS], ['tool', Role.ROLE_TOOLS]]) {
|
|
62
|
+
for (const id of ids) {
|
|
63
|
+
const look = Role.roleLook({ class: kind, shape: id, color: Role.ROLE_MAIN });
|
|
64
|
+
wearPieces[`role/${look.shape}`] = { anchor: kind === 'top' ? 'waist' : 'hand',
|
|
65
|
+
...(kind === 'tool' ? { scale: look.scale[0] } : {}), tint: Role.ROLE_MAIN, placement: placement[kind] };
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return { avatarFits, wearModels, wearPieces };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// The manifest (SPEC.md) from what collectHubData returned. ctx: { hubId, source, hubCfg (castle.json hub,
|
|
72
|
+
// or null), deck (its client flags, shared/deckFlags.js, or null), putShared(buf, ext) -> asset, resolveDoor(door) -> target, readArt(path) -> { buf, ext } | null,
|
|
73
|
+
// avatar ({ asset, info }) to reuse, or null; wear (collectAvatarWear's three v1.7 blocks) }.
|
|
74
|
+
// Returns { manifest, avatar }.
|
|
75
|
+
// A model's paint parts the merge kept apart (a car look marks them `keep`): their material is
|
|
76
|
+
// named 'paint', which native tints in the car's colour (HubModel.Part.paint, the vehicle
|
|
77
|
+
// preset's `color`). A paint part merged into a batch keeps the batch's unnamed material.
|
|
78
|
+
export function namePaint(root) {
|
|
79
|
+
root.traverse((o) => {
|
|
80
|
+
if (!o.isMesh || !o.userData.paint || o.userData.merged !== undefined || o.userData.lookOutline) return;
|
|
81
|
+
o.material = Array.isArray(o.material)
|
|
82
|
+
? o.material.map((m) => Object.assign(m.clone(), { name: 'paint' }))
|
|
83
|
+
: Object.assign(o.material.clone(), { name: 'paint' });
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function assembleManifest(r, ctx) {
|
|
88
|
+
// Files.
|
|
89
|
+
const { putShared } = ctx;
|
|
90
|
+
const assets = {};
|
|
91
|
+
assets.scene = putShared(Buffer.from(r.sceneB64, 'base64'), 'glb');
|
|
92
|
+
assets.scene.shared = false;
|
|
93
|
+
let avatar = ctx.avatar;
|
|
94
|
+
if (r.avatarB64) avatar = { asset: putShared(Buffer.from(r.avatarB64, 'base64'), 'glb'), info: r.avatar };
|
|
95
|
+
if (avatar) assets.avatar = avatar.asset;
|
|
96
|
+
// Also register wear assets here: cache restaging and upload enumerate this table.
|
|
97
|
+
Object.assign(assets, ctx.wear.wearModels);
|
|
98
|
+
// Models built once and placed per actor (splitModels): one shared glb per distinct model.
|
|
99
|
+
const layers = [{ id: 'world', asset: 'scene', transform: null, tiers: null, role: 'scene' }];
|
|
100
|
+
for (const [i, p] of (r.props ?? []).entries()) {
|
|
101
|
+
const id = `model-${i}`;
|
|
102
|
+
assets[id] = putShared(Buffer.from(p.glbB64, 'base64'), 'glb');
|
|
103
|
+
layers.push({ id, asset: id, role: 'prop', tiers: null, model: p.file, instances: p.instances });
|
|
104
|
+
}
|
|
105
|
+
if (r.sky?.domeB64) assets['sky-dome'] = putShared(Buffer.from(r.sky.domeB64, 'base64'), 'glb');
|
|
106
|
+
const zones = [];
|
|
107
|
+
for (const z of r.sky?.zones ?? []) {
|
|
108
|
+
let image = null;
|
|
109
|
+
let buf = z.pngB64 ? Buffer.from(z.pngB64, 'base64') : null;
|
|
110
|
+
let ext = 'png';
|
|
111
|
+
if (!buf && z.art) {
|
|
112
|
+
const art = ctx.readArt?.(z.art);
|
|
113
|
+
if (art) ({ buf, ext } = art);
|
|
114
|
+
}
|
|
115
|
+
if (buf && ['png', 'webp'].includes(ext)) {
|
|
116
|
+
image = `sky-${z.id}`;
|
|
117
|
+
assets[image] = putShared(buf, ext);
|
|
118
|
+
}
|
|
119
|
+
zones.push({ id: z.id, color: z.color, image, box: z.box ?? null, art: z.art ?? null });
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const doors = r.doors.map((d) => ({ ...d, target: ctx.resolveDoor(d) }));
|
|
123
|
+
// v1.6: every sound the kit's sound.js can play (the deck's own files its castle.json names),
|
|
124
|
+
// an ordinary content-addressed asset, mapped from its castle.json-relative path.
|
|
125
|
+
// ctx.audio: [{ path, ext, buf }].
|
|
126
|
+
const audio = {};
|
|
127
|
+
for (const [i, sound] of (ctx.audio ?? []).entries()) {
|
|
128
|
+
const id = `audio-${i}`;
|
|
129
|
+
assets[id] = putShared(sound.buf, sound.ext);
|
|
130
|
+
audio[sound.path] = id;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const hubCfg = ctx.hubCfg ?? null;
|
|
134
|
+
const spawns = [];
|
|
135
|
+
const arrivalActor = hubCfg?.arrival?.actor;
|
|
136
|
+
const arrival = r.spawnCandidates.find((s) => s.actorId === arrivalActor) ?? r.spawnCandidates.find((s) => s.actorId === 'arrival') ?? r.spawnCandidates.find((s) => s.player);
|
|
137
|
+
if (arrival) {
|
|
138
|
+
const face = hubCfg?.arrival?.face;
|
|
139
|
+
spawns.push({ id: 'arrival', kind: 'arrival', actorId: arrival.actorId, position: [arrival.position[0], r.floorsByActor[arrival.actorId] ?? arrival.position[1], arrival.position[2]].map(round),
|
|
140
|
+
facingDeg: typeof face === 'number' ? face : arrival.facingDeg, face: face ?? 'actor', spread: hubCfg?.arrival?.spread ?? 0, default: true });
|
|
141
|
+
}
|
|
142
|
+
for (const s of r.starts) spawns.push({ id: `start-${s.actorId}`, kind: 'start', actorId: s.actorId, order: s.order, position: s.position.map(round), facingDeg: s.facingDeg, spread: 0, default: false });
|
|
143
|
+
for (const d of doors) if (d.exit) spawns.push({ id: d.id, kind: 'doorExit', actorId: d.actorId, position: d.exit.position.map(round), facingDeg: d.exit.facingDeg, spread: 0, default: false });
|
|
144
|
+
if (!spawns.some((s) => s.default) && spawns.length) spawns[0].default = true;
|
|
145
|
+
|
|
146
|
+
if (ctx.spawnRing) {
|
|
147
|
+
const at = ctx.spawnRing.at.map(round);
|
|
148
|
+
assets['spawn-ring'] = putShared(ctx.spawnRing.glb, 'glb');
|
|
149
|
+
layers.push({ id: 'spawn-ring', asset: 'spawn-ring', role: 'scene', tiers: null, transform: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, ...at, 1] });
|
|
150
|
+
}
|
|
151
|
+
const manifest = {
|
|
152
|
+
format: 'castle.hubScene',
|
|
153
|
+
version: 1,
|
|
154
|
+
hubId: ctx.hubId,
|
|
155
|
+
title: hubCfg?.title ?? r.title ?? ctx.hubId,
|
|
156
|
+
source: { ...ctx.source, exportedAt: new Date().toISOString(), three: r.three, profile: r.tier, notes: r.notes },
|
|
157
|
+
assets,
|
|
158
|
+
audio,
|
|
159
|
+
layers,
|
|
160
|
+
avatar: avatar ? { asset: 'avatar', rootAboveFloor: round(avatar.info.rootAboveFloor), parts: avatar.info.parts, gait: 'procedural', capsule: avatar.info.capsule } : null,
|
|
161
|
+
...ctx.wear,
|
|
162
|
+
render: r.render,
|
|
163
|
+
lights: r.lights,
|
|
164
|
+
sky: r.sky ? { dome: assets['sky-dome'] ? 'sky-dome' : null, fade: r.sky.fade, edge: r.sky.edge, below: r.sky.below, tiers: r.sky.drawnAtExport ? null : ['high'], zones } : null,
|
|
165
|
+
fog: r.fog,
|
|
166
|
+
camera: withReference(r.camera, spawns.find((sp) => sp.default), avatar?.info?.rootAboveFloor),
|
|
167
|
+
// Readability rings the hub client draws (engine.hubPadRing / hubSpawnRing / hubPadContext):
|
|
168
|
+
// the native engine draws the active ring and caption from these; the spawn ring is a layer.
|
|
169
|
+
padCues: ctx.padCues ?? null,
|
|
170
|
+
spawns,
|
|
171
|
+
doors: doors.map(({ classicDeckId, ...d }) => d),
|
|
172
|
+
characters: r.characters,
|
|
173
|
+
// v1.4: the actors the kit's talk and act find (collectHubData), and the deck's client flags
|
|
174
|
+
// (ctx.deck: shared/deckFlags.js of castle.json's hub block) for a host with no castle.json.
|
|
175
|
+
interactables: r.interactables ?? [],
|
|
176
|
+
deck: ctx.deck ?? null,
|
|
177
|
+
colliders: r.colliders,
|
|
178
|
+
ground: r.ground,
|
|
179
|
+
labels: r.labels,
|
|
180
|
+
actors: r.actors,
|
|
181
|
+
// v1.1 mergeStatic: chunk node (an `actors` entry) -> the scene actors baked into it.
|
|
182
|
+
merged: r.merged && Object.keys(r.merged).length ? r.merged : null,
|
|
183
|
+
tiers: r.tiers,
|
|
184
|
+
cells: r.cells,
|
|
185
|
+
stats: r.stats,
|
|
186
|
+
};
|
|
187
|
+
return { manifest, avatar };
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// The camera the engine's Player behaviour (physics-3d behaviors/Player.jsx) settles at after an
|
|
191
|
+
// arrival at `spawn`, with nothing in its way (its first frames ease there from wherever the camera
|
|
192
|
+
// was, unless it snaps): the orbit camera
|
|
193
|
+
// (engine.camera follow rigid, control orbit) at the start pitch and range behind the arrival
|
|
194
|
+
// facing (hub-game arrivalCamera.js: camAngle = PI - facing), else the follow camera at camDistance
|
|
195
|
+
// and camHeight. Player's constants, mirrored (test/export-fixture.mjs checks them against it).
|
|
196
|
+
export const PLAYER_CAMERA = { STUD: 1.46 / 5, LOOK_HEIGHT_STUDS: 1.5, ORBIT_START_STUDS: 12.5, ORBIT_NEAREST: 1.5, ORBIT_FARTHEST_STUDS: 128,
|
|
197
|
+
PITCH_START_DEG: 15, PITCH_LIMIT_DEG: 80, ORBIT_FOV: 70, FOLLOW_DISTANCE: 9, FOLLOW_HEIGHT: 7, FOLLOW_LOOK_ABOVE: 0.5 };
|
|
198
|
+
function withReference(camera, spawn, rootAboveFloor) {
|
|
199
|
+
if (!camera || !spawn) return camera;
|
|
200
|
+
const P = PLAYER_CAMERA;
|
|
201
|
+
const DEG = Math.PI / 180;
|
|
202
|
+
const fin = (x) => typeof x === 'number' && Number.isFinite(x);
|
|
203
|
+
const clamp = (x, lo, hi) => Math.min(hi, Math.max(lo, x));
|
|
204
|
+
const e = camera.engine ?? {};
|
|
205
|
+
const body = [spawn.position[0], spawn.position[1] + (fin(rootAboveFloor) ? rootAboveFloor : 0.707), spawn.position[2]];
|
|
206
|
+
const yaw = Math.PI - (spawn.facingDeg ?? 0) * DEG;
|
|
207
|
+
let eye; let look; let mode; let fovDeg = camera.fovDeg; let extra = {};
|
|
208
|
+
if (e.follow === 'rigid' && e.control === 'orbit') {
|
|
209
|
+
const least = clamp((fin(e.minPitch) ? e.minPitch : -P.PITCH_LIMIT_DEG) * DEG, -P.PITCH_LIMIT_DEG * DEG, P.PITCH_LIMIT_DEG * DEG);
|
|
210
|
+
const pitch = clamp(fin(e.pitch) ? e.pitch * DEG : P.PITCH_START_DEG * DEG, least, P.PITCH_LIMIT_DEG * DEG);
|
|
211
|
+
const range = clamp(fin(e.distance) ? e.distance : P.ORBIT_START_STUDS * P.STUD, P.ORBIT_NEAREST, P.ORBIT_FARTHEST_STUDS * P.STUD);
|
|
212
|
+
look = [body[0], body[1] + P.LOOK_HEIGHT_STUDS * P.STUD, body[2]];
|
|
213
|
+
const flat = Math.cos(pitch);
|
|
214
|
+
eye = [look[0] - flat * Math.sin(yaw) * range, look[1] + Math.sin(pitch) * range, look[2] + flat * Math.cos(yaw) * range];
|
|
215
|
+
mode = 'orbit';
|
|
216
|
+
fovDeg = typeof e.fov === 'number' && e.fov >= 10 && e.fov <= 120 ? e.fov : P.ORBIT_FOV;
|
|
217
|
+
extra = { pitchDeg: Math.round((pitch / DEG) * 1e4) / 1e4, range: Math.round(range * 1e4) / 1e4 };
|
|
218
|
+
} else {
|
|
219
|
+
const d = fin(camera.follow?.distance) ? camera.follow.distance : P.FOLLOW_DISTANCE;
|
|
220
|
+
const h = fin(camera.follow?.height) ? camera.follow.height : P.FOLLOW_HEIGHT;
|
|
221
|
+
eye = [body[0] - d * Math.sin(yaw), body[1] + h, body[2] + d * Math.cos(yaw)];
|
|
222
|
+
look = [body[0], body[1] + P.FOLLOW_LOOK_ABOVE, body[2]];
|
|
223
|
+
mode = 'follow';
|
|
224
|
+
}
|
|
225
|
+
// three's lookAt for a camera (it looks down its -z), as a column-major world matrix.
|
|
226
|
+
const sub = (a, b) => [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
|
|
227
|
+
const cross = (a, b) => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
|
|
228
|
+
const norm = (a) => { const l = Math.hypot(...a) || 1; return a.map((x) => x / l); };
|
|
229
|
+
// three's Matrix4.lookAt, degenerate cases included: eye on the target, or looking straight down.
|
|
230
|
+
let z = sub(eye, look);
|
|
231
|
+
if (Math.hypot(...z) === 0) z = [0, 0, 1];
|
|
232
|
+
z = norm(z);
|
|
233
|
+
let x = cross([0, 1, 0], z);
|
|
234
|
+
if (Math.hypot(...x) === 0) {
|
|
235
|
+
z = norm([z[0], z[1], z[2] + 0.0001]);
|
|
236
|
+
x = cross([0, 1, 0], z);
|
|
237
|
+
}
|
|
238
|
+
x = norm(x);
|
|
239
|
+
const y = cross(z, x);
|
|
240
|
+
const r6 = (n) => Math.round(n * 1e6) / 1e6;
|
|
241
|
+
const matrixWorld = [...x, 0, ...y, 0, ...z, 0, ...eye, 1].map(r6);
|
|
242
|
+
return { ...camera, fovDeg, reference: { ...camera.reference, matrixWorld, mode, spawn: spawn.id, look: look.map(r6), eye: eye.map(r6), ...extra,
|
|
243
|
+
note: 'where Player settles the camera after an arrival at the default spawn, with nothing in the way' } };
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// Runs in the deck's frame (export-hub.mjs, through frame.evaluate, so it may use nothing outside
|
|
247
|
+
// itself) or in Node over a world built from a content pack (pack-to-manifest.mjs), with the loop
|
|
248
|
+
// frozen. Reads globalThis.__hub and globalThis.__expLib. Everything it changes it puts back.
|
|
249
|
+
// avatarActorId: an actor built only to be the avatar (nodeworld.mjs builds the kit's platform
|
|
250
|
+
// avatar so); it is exported as the avatar and is no spawn, collider or scene node.
|
|
251
|
+
// mergeStatic: false, or { cellM, exclude } to bake still scenery into chunks (below). tierRules: null,
|
|
252
|
+
// or { tiers, weakest, lowActorDistance, sceneryNearM, npcNearM } from the deck's hub config and the kit.
|
|
253
|
+
export async function collectHubData({ exportAvatar, splitModels = false, arrivalActor = null, avatarActorId = null, mergeStatic = false, tierRules = null, soundscape = null }) {
|
|
254
|
+
// What the collection changes in the scene, put back in `finally` whether or not it throws.
|
|
255
|
+
const renamed = []; const tags = []; const matTags = []; const hidden = []; const hiddenRigs = []; const added = [];
|
|
256
|
+
// Hidden actors exported all the same (collect): [node, visible] and [node, position, quaternion].
|
|
257
|
+
const shown = []; const posed = [];
|
|
258
|
+
// Hidden actors the page took out of the scene, put in it for the export: [node, its parent then
|
|
259
|
+
// (or null), its index there, [object, matrixWorld, matrix] of its subtree].
|
|
260
|
+
const attached = [];
|
|
261
|
+
try {
|
|
262
|
+
return await collect();
|
|
263
|
+
} finally {
|
|
264
|
+
for (const o of added) o.removeFromParent();
|
|
265
|
+
// What showHidden changed first: a node the merge then hid as well is shown again after it.
|
|
266
|
+
for (const [n, was] of shown.reverse()) n.visible = was;
|
|
267
|
+
for (const n of hidden) n.visible = true;
|
|
268
|
+
for (const [rig, was] of hiddenRigs) rig.visible = was;
|
|
269
|
+
for (const [n, p, q] of posed.reverse()) { n.position.copy(p); n.quaternion.copy(q); n.updateMatrixWorld(true); }
|
|
270
|
+
for (const [n, parent, index, mats] of attached.reverse()) {
|
|
271
|
+
n.removeFromParent();
|
|
272
|
+
if (parent) { parent.add(n); const c = parent.children; c.splice(c.indexOf(n), 1); c.splice(index, 0, n); }
|
|
273
|
+
for (const [o, world, local] of mats) { o.matrixWorld.copy(world); o.matrix.copy(local); }
|
|
274
|
+
}
|
|
275
|
+
for (const [m, had, prev] of matTags) { if (had) m.userData.__three = prev; else delete m.userData.__three; }
|
|
276
|
+
for (const [n, had, prev] of tags) { if (had) n.userData.__actor = prev; else delete n.userData.__actor; }
|
|
277
|
+
for (const [n, name] of renamed) n.name = name;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
async function collect() {
|
|
281
|
+
const { THREE, GLTFExporter } = globalThis.__expLib;
|
|
282
|
+
const h = globalThis.__hub; const s = h.scene; const w = s.three;
|
|
283
|
+
const errors = []; const notes = []; const warnings = [];
|
|
284
|
+
const r4 = (n) => Math.round(n * 1e4) / 1e4;
|
|
285
|
+
const v = (x) => x.toArray().map(r4);
|
|
286
|
+
const hex = (c) => `#${c.getHexString()}`;
|
|
287
|
+
const DEG = Math.PI / 180;
|
|
288
|
+
const toB64 = async (buf) => { const url = await new Promise((res) => { const fr = new FileReader(); fr.onload = () => res(fr.result); fr.readAsDataURL(new Blob([buf])); }); return url.slice(url.indexOf(',') + 1); };
|
|
289
|
+
const effVisible = (o) => { for (let x = o; x; x = x.parent) { if (!x.visible) return false; if (x === w.scene) return true; } return false; };
|
|
290
|
+
|
|
291
|
+
// hub-game quality.js classify.
|
|
292
|
+
const GAMEPLAY = /^Hub|^Town|^Body$|^Ball$|^Player$/;
|
|
293
|
+
const DECOR = new Set(['Transform', 'Shape', 'Model']);
|
|
294
|
+
const SCENERY = new Set(['Transform', 'Shape', 'Model', 'Solid', 'Lookable']);
|
|
295
|
+
const classify = (c) => {
|
|
296
|
+
const names = Object.keys(c ?? {});
|
|
297
|
+
const solid = names.includes('Solid') || Boolean(c?.Shape?.solid);
|
|
298
|
+
if (names.includes('HubNpc')) return 'npc';
|
|
299
|
+
if (names.includes('Player')) return 'player';
|
|
300
|
+
if (names.some((n) => GAMEPLAY.test(n))) return 'game';
|
|
301
|
+
if (!solid && names.every((n) => DECOR.has(n))) return 'decor';
|
|
302
|
+
return names.every((n) => SCENERY.has(n)) ? 'static' : 'game';
|
|
303
|
+
};
|
|
304
|
+
// physics3d.js quatFromEuler: three's default XYZ order, degrees.
|
|
305
|
+
const quatOf = (t) => new THREE.Quaternion().setFromEuler(new THREE.Euler((t?.rotationX ?? 0) * DEG, (t?.rotationY ?? 0) * DEG, (t?.rotationZ ?? 0) * DEG));
|
|
306
|
+
const posOf = (t) => [t?.x ?? 0, t?.y ?? 0, t?.z ?? 0];
|
|
307
|
+
|
|
308
|
+
const actors = [...s.actors.values()];
|
|
309
|
+
const playerActor = s.actorWith?.('Player') ?? actors.find((a) => a.components.Player);
|
|
310
|
+
const avatarIds = new Set(actors.filter((a) => a.components.Player || a.id === avatarActorId).map((a) => a.id));
|
|
311
|
+
const bodyActor = (avatarActorId && s.actors.get(avatarActorId)) || playerActor;
|
|
312
|
+
for (const id of s.multiplayer?.avatars?.actors?.keys?.() ?? []) avatarIds.add(id);
|
|
313
|
+
const avatarNodes = [...avatarIds].map((id) => w.nodes.get(id)?.node).filter(Boolean);
|
|
314
|
+
const underAvatar = new Set();
|
|
315
|
+
for (const n of avatarNodes) n.traverse((o) => underAvatar.add(o));
|
|
316
|
+
|
|
317
|
+
// Hidden at export: an authored actor whose node is not drawn now, or that hub.hide dropped far
|
|
318
|
+
// below the ground (systems/hub.js HIDE_DROP_M), as a live page has its templates and look
|
|
319
|
+
// models after the place's ready code. A copy (hub.spawn), a car look and a later hub.show are
|
|
320
|
+
// all drawn from the actor's own node in the scene glb, so its meshes and split model are
|
|
321
|
+
// exported all the same, at its authored Transform (where show draws it), while it stays
|
|
322
|
+
// visibleAtExport false and in hiddenAtExport. It is never merged and no floor; its bounds are
|
|
323
|
+
// the authored pose's. Its pose here and its nodes' visibility below (showHidden) are put back.
|
|
324
|
+
const PARKED_BELOW_Y = -5000;
|
|
325
|
+
const authored = new Map();
|
|
326
|
+
for (const a of Array.isArray(s.data?.actors) ? s.data.actors : []) if (a && typeof a.id === 'string') authored.set(a.id, a);
|
|
327
|
+
// The whole set first, before any node moves: lifting a parked parent carries its children up.
|
|
328
|
+
const lifted = new Map(); // actor id -> its node, posed at its authored Transform
|
|
329
|
+
const hiddenSelf = new Set(); // of those, the nodes hidden themselves (not only through a parent)
|
|
330
|
+
const at = new THREE.Vector3();
|
|
331
|
+
for (const a of actors) {
|
|
332
|
+
const node = w.nodes.get(a.id)?.node;
|
|
333
|
+
if (!authored.has(a.id) || !node || avatarIds.has(a.id) || underAvatar.has(node) || ['npc', 'player'].includes(classify(a.components))) continue;
|
|
334
|
+
if (effVisible(node) && node.getWorldPosition(at).y >= PARKED_BELOW_Y) continue;
|
|
335
|
+
lifted.set(a.id, node);
|
|
336
|
+
if (!node.visible) hiddenSelf.add(node);
|
|
337
|
+
}
|
|
338
|
+
// Detached: the page takes a hidden node out of the scene graph rather than hiding it (hub-game
|
|
339
|
+
// tiers.js `hide`: `node.parent.remove(node)`, for the place's hidden set as for scenery and
|
|
340
|
+
// cells), or it may sit under a holder that is not in the scene. For the export it is put in
|
|
341
|
+
// the scene, top-level (a detached lifted ancestor brings its lifted children along), and posed
|
|
342
|
+
// at its authored Transform below; its parent (none, or the holder) and place there, and its
|
|
343
|
+
// subtree's matrices, are put back in `finally`.
|
|
344
|
+
const depth = (o) => { let d = 0; for (let x = o; x && x !== w.scene; x = x.parent) d += 1; return d; };
|
|
345
|
+
const inScene = (o) => { for (let x = o; x; x = x.parent) if (x === w.scene) return true; return false; };
|
|
346
|
+
for (const [, node] of [...lifted].sort(([, a], [, b]) => depth(a) - depth(b))) {
|
|
347
|
+
if (inScene(node)) continue;
|
|
348
|
+
const parent = node.parent ?? null;
|
|
349
|
+
const mats = [];
|
|
350
|
+
node.traverse((o) => mats.push([o, o.matrixWorld.clone(), o.matrix.clone()]));
|
|
351
|
+
attached.push([node, parent, parent ? parent.children.indexOf(node) : -1, mats]);
|
|
352
|
+
w.scene.add(node); node.updateMatrixWorld(true);
|
|
353
|
+
}
|
|
354
|
+
// Then posed, parents before children; a child that its parent's lift already brought back up
|
|
355
|
+
// and that was not hidden itself (parked only through its parent) keeps its own pose.
|
|
356
|
+
const liftedNodes = new Set(lifted.values());
|
|
357
|
+
for (const [id, node] of [...lifted].sort(([, a], [, b]) => depth(a) - depth(b))) {
|
|
358
|
+
let ancestorLifted = false;
|
|
359
|
+
for (let x = node.parent; x && x !== w.scene; x = x.parent) if (liftedNodes.has(x)) ancestorLifted = true;
|
|
360
|
+
if (ancestorLifted && !hiddenSelf.has(node) && node.getWorldPosition(at).y >= PARKED_BELOW_Y) continue;
|
|
361
|
+
const t = authored.get(id).components?.Transform;
|
|
362
|
+
if (!t || typeof t !== 'object') continue;
|
|
363
|
+
posed.push([node, node.position.clone(), node.quaternion.clone()]);
|
|
364
|
+
const fin = (x) => (typeof x === 'number' && Number.isFinite(x) ? x : 0);
|
|
365
|
+
node.position.set(fin(t.x), fin(t.y), fin(t.z));
|
|
366
|
+
node.quaternion.copy(quatOf({ rotationX: fin(t.rotationX), rotationY: fin(t.rotationY), rotationZ: fin(t.rotationZ) }));
|
|
367
|
+
node.updateMatrixWorld(true);
|
|
368
|
+
}
|
|
369
|
+
const underLifted = new Set();
|
|
370
|
+
for (const n of lifted.values()) n.traverse((o) => underLifted.add(o));
|
|
371
|
+
|
|
372
|
+
// Floor height under a point, from the visible non-avatar meshes.
|
|
373
|
+
const scenery = [];
|
|
374
|
+
w.scene.traverse((o) => { if (o.isMesh && !o.userData.lookOutline && !underAvatar.has(o) && !underLifted.has(o) && effVisible(o)) scenery.push(o); });
|
|
375
|
+
const rc = new THREE.Raycaster();
|
|
376
|
+
const floorY = (x, y, z) => {
|
|
377
|
+
rc.set(new THREE.Vector3(x, y + 2, z), new THREE.Vector3(0, -1, 0)); rc.far = 10;
|
|
378
|
+
const hit = rc.intersectObjects(scenery, false)[0];
|
|
379
|
+
return hit ? hit.point.y : 0;
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
// Actors: kind, tier, cell, world bounds, glb node name.
|
|
383
|
+
const actorInfo = {};
|
|
384
|
+
const box = new THREE.Box3();
|
|
385
|
+
for (const a of actors) {
|
|
386
|
+
const node = w.nodes.get(a.id)?.node;
|
|
387
|
+
if (!node || underAvatar.has(node)) continue;
|
|
388
|
+
box.setFromObject(node);
|
|
389
|
+
const info = { kind: classify(a.components), tier: a.tier ?? null, cell: a.cell ?? null, bounds: box.isEmpty() ? null : [...v(box.min), ...v(box.max)], node: a.id, visibleAtExport: effVisible(node) && !lifted.has(a.id) };
|
|
390
|
+
actorInfo[a.id] = info;
|
|
391
|
+
renamed.push([node, node.name]); node.name = a.id;
|
|
392
|
+
tags.push([node, Object.hasOwn(node.userData, '__actor'), node.userData.__actor]);
|
|
393
|
+
node.userData.__actor = { id: a.id, kind: info.kind };
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// Colliders: physics3d colliderDescFor, one per Shape actor.
|
|
397
|
+
const colliders = []; const colliderOf = new Map();
|
|
398
|
+
for (const a of actors) {
|
|
399
|
+
const sh = a.components.Shape; const t = a.components.Transform;
|
|
400
|
+
if (!sh || !t || avatarIds.has(a.id)) continue;
|
|
401
|
+
const kind = ['sphere', 'capsule', 'cylinder', 'cone'].includes(sh.kind) ? sh.kind : 'box';
|
|
402
|
+
const size = kind === 'box' ? [sh.width ?? 1, sh.height ?? 1, sh.depth ?? 1] : kind === 'sphere' ? [sh.radius ?? 0.5] : [sh.radius ?? 0.5, sh.height ?? 1];
|
|
403
|
+
const solid = Boolean(a.components.Solid) || Boolean(sh.solid);
|
|
404
|
+
colliderOf.set(a.id, colliders.length);
|
|
405
|
+
// Unrounded: the kit's own f64 center, size and quatFromEuler quaternion, so a native body
|
|
406
|
+
// starts from the same f32 bits as the kit's (a 4-decimal quaternion is not quite unit and
|
|
407
|
+
// parts native from wasm); eulerDeg is the Transform the kit derives it from (manifest v1.2).
|
|
408
|
+
colliders.push({ actorId: a.id, shape: kind, center: posOf(t), rotation: quatOf(t).toArray(), size,
|
|
409
|
+
eulerDeg: [t.rotationX ?? 0, t.rotationY ?? 0, t.rotationZ ?? 0],
|
|
410
|
+
body: a.components.Body?.type ?? 'fixed', sensor: !solid, walkSurface: Boolean(a.components.WalkSurface),
|
|
411
|
+
friction: a.components.Body?.friction ?? 0.6, restitution: a.components.Body?.restitution ?? 0,
|
|
412
|
+
// v1.1: physics3d bodyDescFor sets these only for an actor with a Body (Body.jsx defaults 0, false).
|
|
413
|
+
...(a.components.Body ? { gravityScale: a.components.Body.gravityScale ?? 0, lockRotations: Boolean(a.components.Body.lockRotations) } : {}) });
|
|
414
|
+
}
|
|
415
|
+
const ground = s.data?.ground?.none === true ? null : { actorId: null, shape: 'box', center: [0, -0.5, 0], rotation: [0, 0, 0, 1], size: [200, 1, 200], body: 'fixed', sensor: false, walkSurface: true, friction: 0.6, restitution: 0 };
|
|
416
|
+
|
|
417
|
+
// Doors and their pads.
|
|
418
|
+
const pads = new Map();
|
|
419
|
+
for (const a of actors) if (a.components.HubPad) pads.set(a.components.HubPad.door, a);
|
|
420
|
+
const doors = [];
|
|
421
|
+
for (const a of actors) {
|
|
422
|
+
const d = a.components.HubDoor; if (!d) continue;
|
|
423
|
+
const t = a.components.Transform; const pad = pads.get(d.id); const pt = pad?.components.Transform;
|
|
424
|
+
const exit = d.exitX !== undefined && d.exitZ !== undefined ? { position: [d.exitX, floorY(d.exitX, t?.y ?? 0, d.exitZ), d.exitZ].map(r4), facingDeg: d.exitFacing ?? 180 } : null;
|
|
425
|
+
let classicDeckId = null;
|
|
426
|
+
try { classicDeckId = d.kind === 'cabinet' ? h.state?.board?.(d.id)?.classic?.deckId ?? null : null; } catch {}
|
|
427
|
+
doors.push({ id: d.id, actorId: a.id, title: d.title ?? d.listTitle ?? d.id, kind: d.kind === 'cabinet' ? 'cabinet' : d.kind === 'layer' ? 'layer' : 'game', to: d.to ?? null,
|
|
428
|
+
position: posOf(t).map(r4), facingDeg: t?.rotationY ?? 0,
|
|
429
|
+
trigger: pad ? { shape: 'cylinder', center: posOf(pt).map(r4), radius: pad.components.HubPad.radius ?? pad.components.Shape?.radius ?? 1, height: pad.components.Shape?.height ?? 0.02, padActorId: pad.id } : null,
|
|
430
|
+
exit, players: { min: d.minPlayers ?? null, max: d.maxPlayers ?? null, lateJoin: d.lateJoin ?? null },
|
|
431
|
+
leafColliderIndex: colliderOf.has(a.id) ? colliderOf.get(a.id) : null, classicDeckId });
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
// Characters (HubNpc).
|
|
435
|
+
const characters = actors.filter((a) => a.components.HubNpc).map((a) => {
|
|
436
|
+
const n = a.components.HubNpc; const t = a.components.Transform; const sh = a.components.Shape;
|
|
437
|
+
return { id: a.id, actorId: a.id, name: n.name ?? a.id, characterId: n.character ?? null, role: n.role ?? null, kind: n.kind ?? null,
|
|
438
|
+
position: posOf(t).map(r4), facingDeg: t?.rotationY ?? 0, node: actorInfo[a.id] ? a.id : null,
|
|
439
|
+
capsule: sh ? { radius: sh.radius ?? 0.35, height: sh.height ?? 1.4 } : null, talkRange: n.talkRange ?? null, door: n.door ?? null,
|
|
440
|
+
label: { text: n.name ?? a.id, offsetY: r4(((sh?.height ?? 1.4) / 2) + 0.5) }, route: n.role === 'walker' ? (n.where ?? 'route') : null };
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
// v1.4 interactables: every actor the kit's talk and act find (shared/act.js interaction:
|
|
444
|
+
// HubNpc, HubAct, HubSeat), as the kit's scene has it ({ id, components }): those components
|
|
445
|
+
// whole, its Transform (x, y, z, rotationY as authored, 0 when absent) and, for a seat's
|
|
446
|
+
// footprint, its Shape. A Body "dynamic" grab target is not one: grab is not native.
|
|
447
|
+
const INTERACTION = ['HubNpc', 'HubAct', 'HubSeat'];
|
|
448
|
+
// v1.6: soundscapeMap reads these components whole, even on actors with no draw node.
|
|
449
|
+
const soundComponents = [soundscape?.zones, soundscape?.steps?.paths, ...Object.keys(soundscape?.ambience?.spots ?? {})]
|
|
450
|
+
.filter((k) => typeof k === 'string' && /^[A-Za-z][A-Za-z0-9_]*$/.test(k));
|
|
451
|
+
const components = [...new Set([...INTERACTION, ...soundComponents])];
|
|
452
|
+
// Town square.js targets the jukebox by id, not a dedicated audio component. Keep its
|
|
453
|
+
// Shape and Lookable whole plus Transform; sound.js uses that Transform for attenuation.
|
|
454
|
+
const emitters = new Set(['jukebox']);
|
|
455
|
+
const plain = (x) => JSON.parse(JSON.stringify(x ?? null));
|
|
456
|
+
const num = (x) => (typeof x === 'number' && Number.isFinite(x) ? x : 0);
|
|
457
|
+
const interactables = [];
|
|
458
|
+
for (const a of actors) {
|
|
459
|
+
const c = a.components ?? {};
|
|
460
|
+
if (avatarIds.has(a.id) || a.id === 'hub-chat-moderation' || !(emitters.has(a.id) || components.some((k) => Object.hasOwn(c, k)))) continue;
|
|
461
|
+
const out = {};
|
|
462
|
+
for (const k of components) if (Object.hasOwn(c, k)) out[k] = plain(c[k]);
|
|
463
|
+
if (emitters.has(a.id) && c.Lookable) out.Lookable = plain(c.Lookable);
|
|
464
|
+
const t = c.Transform;
|
|
465
|
+
out.Transform = { x: num(t?.x), y: num(t?.y), z: num(t?.z), rotationY: num(t?.rotationY) };
|
|
466
|
+
if ((Object.hasOwn(c, 'HubSeat') || emitters.has(a.id)) && c.Shape) out.Shape = plain(c.Shape);
|
|
467
|
+
interactables.push({ id: a.id, components: out });
|
|
468
|
+
}
|
|
469
|
+
// v1.4 also carries the chat moderation opt-in (contract: "Optional chat report and block scene
|
|
470
|
+
// marker"): the actor `hub-chat-moderation` whose HubChatModeration is exactly { v: 1 }, as that
|
|
471
|
+
// component alone (no Transform: it is a scene flag, not a place). Any other value is no opt-in,
|
|
472
|
+
// as on the web (client/chatModeration.js), so it is left out.
|
|
473
|
+
const modMarker = s.actors.get?.('hub-chat-moderation')?.components?.HubChatModeration;
|
|
474
|
+
if (modMarker?.v === 1 && Object.keys(modMarker).length === 1) {
|
|
475
|
+
interactables.push({ id: 'hub-chat-moderation', components: { HubChatModeration: { v: 1 } } });
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
// Spawn candidates: the arrival actor, the Player actor, HubStart slots.
|
|
479
|
+
const spawnCandidates = [];
|
|
480
|
+
const starts = [];
|
|
481
|
+
for (const a of actors) {
|
|
482
|
+
const t = a.components.Transform; if (!t || a.id === avatarActorId) continue;
|
|
483
|
+
if (a.id === 'arrival' || a.id === arrivalActor || a.components.Player || a === playerActor) spawnCandidates.push({ actorId: a.id, player: Boolean(a.components.Player), position: posOf(t), facingDeg: t.rotationY ?? 0 });
|
|
484
|
+
if (a.components.HubStart) starts.push({ actorId: a.id, order: a.components.HubStart.order ?? 0, position: [t.x, floorY(t.x, t.y, t.z), t.z], facingDeg: t.rotationY ?? 0 });
|
|
485
|
+
}
|
|
486
|
+
for (const c of spawnCandidates) c.floor = floorY(...c.position);
|
|
487
|
+
|
|
488
|
+
// Static labels: Lookable, TownSign and any *Sign component that has text.
|
|
489
|
+
const labels = [];
|
|
490
|
+
for (const a of actors) {
|
|
491
|
+
for (const [name, c] of Object.entries(a.components)) {
|
|
492
|
+
if (!c || typeof c.text !== 'string' || !c.text) continue;
|
|
493
|
+
if (name !== 'Lookable' && !/Sign$|Notice$/.test(name)) continue;
|
|
494
|
+
const t = a.components.Transform; const hgt = a.components.Shape?.height ?? 1;
|
|
495
|
+
labels.push({ actorId: a.id, component: name, text: c.text.slice(0, 200), style: name === 'Lookable' ? 'look' : 'sign', anchor: [t?.x ?? 0, (t?.y ?? 0) + hgt / 2 + 0.3, t?.z ?? 0].map(r4), range: c.range ?? null });
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
// Lights, fog, render, camera.
|
|
500
|
+
const lights = { hemisphere: null, ambient: null, sun: null };
|
|
501
|
+
w.scene.traverse((o) => {
|
|
502
|
+
if (!o.isLight || !o.visible) return;
|
|
503
|
+
if (o.isHemisphereLight && !lights.hemisphere) lights.hemisphere = { sky: hex(o.color), ground: hex(o.groundColor), intensity: r4(o.intensity) };
|
|
504
|
+
else if (o.isAmbientLight && !lights.ambient) lights.ambient = { color: hex(o.color), intensity: r4(o.intensity) };
|
|
505
|
+
else if (o.isDirectionalLight && !lights.sun) {
|
|
506
|
+
o.updateMatrixWorld(); o.target.updateMatrixWorld();
|
|
507
|
+
const dir = new THREE.Vector3().setFromMatrixPosition(o.target.matrixWorld).sub(new THREE.Vector3().setFromMatrixPosition(o.matrixWorld)).normalize();
|
|
508
|
+
const sc = o.shadow?.camera;
|
|
509
|
+
lights.sun = { color: hex(o.color), intensity: r4(o.intensity), direction: v(dir), castShadowAtExport: o.castShadow,
|
|
510
|
+
shadow: o.shadow ? { mapSize: o.shadow.mapSize.x, bias: o.shadow.bias, normalBias: o.shadow.normalBias, ortho: sc?.isOrthographicCamera ? [sc.left, sc.right, sc.top, sc.bottom, sc.near, sc.far] : null } : null };
|
|
511
|
+
}
|
|
512
|
+
});
|
|
513
|
+
const f = w.scene.fog;
|
|
514
|
+
const fog = !f ? null : f.isFogExp2 ? { type: 'exp2', color: hex(f.color), density: f.density } : { type: 'linear', color: hex(f.color), near: f.near, far: f.far };
|
|
515
|
+
const clear = new THREE.Color(); w.renderer.getClearColor(clear);
|
|
516
|
+
const tm = Object.entries(THREE).find(([k, val]) => /ToneMapping$/.test(k) && val === w.renderer.toneMapping)?.[0] ?? 'NoToneMapping';
|
|
517
|
+
const render = { toneMapping: tm === 'NoToneMapping' ? 'none' : tm.replace(/ToneMapping$/, '').toLowerCase(), exposure: w.renderer.toneMappingExposure, outputColorSpace: w.renderer.outputColorSpace,
|
|
518
|
+
clearColor: hex(clear), pixelRatioAtExport: w.renderer.getPixelRatio(), background: w.scene.background?.isColor ? hex(w.scene.background) : null };
|
|
519
|
+
const cam = w.camera; cam.updateMatrixWorld();
|
|
520
|
+
const pc = playerActor?.components.Player ?? {};
|
|
521
|
+
const ec = s.data?.engine?.camera;
|
|
522
|
+
const camera = { fovDeg: cam.fov, near: cam.near, far: cam.far, follow: { distance: pc.camDistance ?? null, height: pc.camHeight ?? null },
|
|
523
|
+
engine: ec && typeof ec === 'object' ? { follow: ec.follow ?? null, control: ec.control ?? null, fov: ec.fov ?? null, pitch: ec.pitch ?? null, distance: ec.distance ?? null, minPitch: ec.minPitch ?? null } : null,
|
|
524
|
+
reference: { matrixWorld: cam.matrixWorld.toArray().map((n) => Math.round(n * 1e6) / 1e6), aspect: r4(cam.aspect) } };
|
|
525
|
+
|
|
526
|
+
// Sky: the deck's engine.sky key plus the dome and every zone picture the page has.
|
|
527
|
+
let sky = null;
|
|
528
|
+
const key = s.data?.engine?.sky;
|
|
529
|
+
if (key?.zones?.length) {
|
|
530
|
+
const sprites = s.sprites ?? s.runtime?.sprites ?? null;
|
|
531
|
+
const zones = [];
|
|
532
|
+
for (const [i, z] of key.zones.entries()) {
|
|
533
|
+
let img = z.art ? sprites?.[z.art]?.image ?? null : null;
|
|
534
|
+
if (!img) img = w.sky?.textures?.get?.(i)?.texture?.image ?? null;
|
|
535
|
+
let pngB64 = null;
|
|
536
|
+
if (img && img.width && typeof document !== 'undefined') {
|
|
537
|
+
const c = document.createElement('canvas'); c.width = img.width; c.height = img.height;
|
|
538
|
+
c.getContext('2d').drawImage(img, 0, 0);
|
|
539
|
+
pngB64 = c.toDataURL('image/png').split(',')[1];
|
|
540
|
+
}
|
|
541
|
+
zones.push({ id: z.id, color: z.color, art: z.art ?? null, box: z.box ?? null, pngB64 });
|
|
542
|
+
}
|
|
543
|
+
let domeB64 = null;
|
|
544
|
+
const m = w.sky?.mesh;
|
|
545
|
+
if (m) {
|
|
546
|
+
const mesh = new THREE.Mesh(m.geometry, new THREE.MeshBasicMaterial({ color: 0xffffff, side: THREE.DoubleSide, depthWrite: false }));
|
|
547
|
+
mesh.name = 'engine.sky';
|
|
548
|
+
try { domeB64 = await toB64(await new GLTFExporter().parseAsync(mesh, { binary: true })); } catch (e) { warnings.push(`sky dome: ${e}`); }
|
|
549
|
+
}
|
|
550
|
+
sky = { fade: key.fade ?? 1.5, edge: key.edge ?? 0.75, below: key.below ?? 8, zones, domeB64, drawnAtExport: Boolean(m?.parent ?? m) && w.sky?.mesh?.visible !== false };
|
|
551
|
+
} else if (w.sky?.mesh) notes.push('sky mesh present without an engine.sky key');
|
|
552
|
+
|
|
553
|
+
// Tier profile at export.
|
|
554
|
+
const tierNow = { current: typeof h.tier?.current === 'function' ? h.tier.current() : h.tier?.current ?? null, mode: h.tier?.mode ?? null, profile: h.tier?.profile ?? null, reason: h.tier?.reason ?? null };
|
|
555
|
+
const profileName = tierNow.profile ?? tierNow.current ?? 'high';
|
|
556
|
+
const lowish = tierNow.current === 'low';
|
|
557
|
+
const hiddenAtExport = Object.entries(actorInfo).filter(([, a]) => !a.visibleAtExport).map(([id]) => id);
|
|
558
|
+
const tiers = { default: profileName, order: ['weakest', 'low', 'middle', 'high'], profiles: {
|
|
559
|
+
[profileName]: { decor: !lowish, sceneryNearM: lowish ? 30 : null, npcNearM: lowish ? 20 : null, sunShadow: Boolean(lights.sun?.castShadowAtExport), sky: Boolean(sky?.drawnAtExport), pixelRatio: w.renderer.getPixelRatio(), hiddenAtExport },
|
|
560
|
+
} };
|
|
561
|
+
if (profileName !== 'high') tiers.profiles.high = { decor: true, sceneryNearM: null, npcNearM: null, sunShadow: true, sky: true, pixelRatio: 1, note: 'not exported: the scene glb holds only what the export profile drew',
|
|
562
|
+
...(hiddenAtExport.length ? { hiddenAtExport } : {}) };
|
|
563
|
+
// tierRules (a deck with hub.tiers, exported at High): the kit's Low picture as a profile, the
|
|
564
|
+
// rules hub-game tiers.js applies on Low. The render scale is left alone there, so no pixelRatio.
|
|
565
|
+
// A weakestTier deck's middle and weakest are Low plus what a profile cannot say yet (district
|
|
566
|
+
// sleep, the cheaper look), so they get Low's rules and a note.
|
|
567
|
+
if (tierRules?.tiers && profileName === 'high') {
|
|
568
|
+
const low = { decor: false, sceneryNearM: tierRules.sceneryNearM, npcNearM: tierRules.npcNearM, sunShadow: false, sky: Boolean(sky), pixelRatio: null, hiddenAtExport };
|
|
569
|
+
tiers.order = ['weakest', 'middle', 'low', 'high'];
|
|
570
|
+
tiers.profiles.low = low;
|
|
571
|
+
if (tierRules.weakest) {
|
|
572
|
+
tiers.profiles.middle = { ...low, note: "Low's rules; hub-game's district sleep is not carried" };
|
|
573
|
+
tiers.profiles.weakest = { ...low, note: "Low's rules; hub-game's district sleep and cheaper look are not carried" };
|
|
574
|
+
}
|
|
575
|
+
if (actors.some((a) => a.tier === 'high')) notes.push('tiers: high-marked actors (hub.highOnly) are drawn on every profile');
|
|
576
|
+
}
|
|
577
|
+
// hub.lowActorDistance: an actor's own Low distance (`lowDrawDistance`) as `nearM`.
|
|
578
|
+
if (tierRules?.tiers && tierRules.lowActorDistance) {
|
|
579
|
+
for (const a of actors) if (actorInfo[a.id] && Number.isFinite(a.lowDrawDistance) && a.lowDrawDistance > 0) actorInfo[a.id].nearM = a.lowDrawDistance;
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
// Material tags glTF cannot carry (as export.mjs did), then the scene glb with avatars hidden.
|
|
583
|
+
const mats = new Map();
|
|
584
|
+
w.scene.traverse((o) => { if (o.material) for (const m of [].concat(o.material)) mats.set(m.uuid, m); });
|
|
585
|
+
for (const m of mats.values()) {
|
|
586
|
+
const props = w.renderer.properties.get(m); const u = props?.uniforms ?? {};
|
|
587
|
+
const val = (k) => (u[k] ? u[k].value : undefined);
|
|
588
|
+
const pk = m.customProgramCacheKey?.call(m);
|
|
589
|
+
matTags.push([m, Object.hasOwn(m.userData, '__three'), m.userData.__three]);
|
|
590
|
+
m.userData.__three = { threeType: m.type, side: m.side, transparent: m.transparent, opacity: m.opacity, depthWrite: m.depthWrite, vertexColors: m.vertexColors, flatShading: m.flatShading ?? false,
|
|
591
|
+
color: m.color ? hex(m.color) : null, emissive: m.emissive ? hex(m.emissive) : null, roughness: m.roughness, metalness: m.metalness,
|
|
592
|
+
programKey: typeof pk === 'string' && pk !== m.uuid && !/^[\d.]+$/.test(pk) ? pk : null,
|
|
593
|
+
lookRim: val('lookRim'), lookAo: val('lookAo'), lookOutline: val('lookOutline') };
|
|
594
|
+
}
|
|
595
|
+
// splitModels: each distinct model built once into its own glb, placed per actor and left out of
|
|
596
|
+
// the scene glb, so the same model in two hubs is one shared file and one loaded copy.
|
|
597
|
+
// Everything drawn, before the models are split out of the scene glb: nodes, meshes, triangles.
|
|
598
|
+
const drawn = { nodes: 0, meshes: 0, tris: 0 };
|
|
599
|
+
w.scene.traverse((o) => {
|
|
600
|
+
if (underAvatar.has(o) || underLifted.has(o) || !effVisible(o)) return;
|
|
601
|
+
drawn.nodes += 1;
|
|
602
|
+
if (!o.isMesh) return;
|
|
603
|
+
drawn.meshes += 1;
|
|
604
|
+
const g = o.geometry; drawn.tris += Math.floor((g.index ? g.index.count : g.attributes.position.count) / 3);
|
|
605
|
+
});
|
|
606
|
+
|
|
607
|
+
// mergeStatic: the scenery a scene marks still (physics-3d `staticActors`, `"static": true`) baked
|
|
608
|
+
// into one node per kind, tier mark and cell, each a mesh per material, so the native engine
|
|
609
|
+
// loads tens of nodes instead of an entity tree per actor. A chunk stands in for its actors in
|
|
610
|
+
// `actors` (kind, tier, cell and bounds, so tier rules still apply to it) and lists them in
|
|
611
|
+
// `merged`. An actor stays out of the merge unless it is plain scenery (classify static or
|
|
612
|
+
// decor), drawn only by meshes it can bake, and named by nothing that could address it later:
|
|
613
|
+
// another actor's component, `exclude` (ids the deck's code quotes or spawns), a template mark
|
|
614
|
+
// beside its id (`"decor": true`, the v1.137 decorative spawn template, or `spawnTemplate` /
|
|
615
|
+
// `scriptedTarget`), or the scene's `engine.hubKeepNodes` (ids, `*` matching any run of
|
|
616
|
+
// characters: what code builds at run time or reads from config). A merged actor has no node
|
|
617
|
+
// of its own, so a native client could neither hide, show nor copy it.
|
|
618
|
+
const merged = {};
|
|
619
|
+
const dropped = [];
|
|
620
|
+
// An actor drawn by nothing visible (a collider or marker whose look, if any, another actor
|
|
621
|
+
// draws) has no node in the export, as the page builds none under engine.skipEmptyNodes, or
|
|
622
|
+
// for a still actor under staticActors. NPCs and players keep theirs: modules attach to them.
|
|
623
|
+
const drawsNothing = (node) => {
|
|
624
|
+
let none = true;
|
|
625
|
+
node.traverse((o) => { if (none && (o.isMesh || o.isSprite || o.isPoints || o.isLine) && effVisible(o)) none = false; });
|
|
626
|
+
return none;
|
|
627
|
+
};
|
|
628
|
+
if (mergeStatic) {
|
|
629
|
+
const skipEmpty = s.data?.engine?.skipEmptyNodes === true;
|
|
630
|
+
const stillMarks = s.data?.engine?.staticActors === true;
|
|
631
|
+
for (const a of actors) {
|
|
632
|
+
const info = actorInfo[a.id];
|
|
633
|
+
if (!info || !info.visibleAtExport || ['npc', 'player'].includes(info.kind) || avatarIds.has(a.id)) continue;
|
|
634
|
+
if (!(skipEmpty || (stillMarks && a.static === true))) continue;
|
|
635
|
+
const node = w.nodes.get(a.id)?.node;
|
|
636
|
+
if (!node || !drawsNothing(node)) continue;
|
|
637
|
+
node.visible = false; hidden.push(node);
|
|
638
|
+
delete actorInfo[a.id];
|
|
639
|
+
dropped.push(a.id);
|
|
640
|
+
}
|
|
641
|
+
if (dropped.length) notes.push(`mergeStatic: ${dropped.length} actors draw nothing and have no node`);
|
|
642
|
+
}
|
|
643
|
+
const mergeOn = mergeStatic && s.data?.engine?.staticActors === true && typeof globalThis.__expLib.mergeGeometries === 'function';
|
|
644
|
+
if (mergeStatic && !mergeOn) notes.push('mergeStatic: the scene does not set engine.staticActors; nothing merged');
|
|
645
|
+
if (mergeOn) {
|
|
646
|
+
const { mergeGeometries } = globalThis.__expLib;
|
|
647
|
+
const cellM = mergeStatic.cellM ?? 24;
|
|
648
|
+
const exclude = new Set(mergeStatic.exclude ?? []);
|
|
649
|
+
const keepNodes = keepNodesOf(s.data?.engine?.hubKeepNodes, notes);
|
|
650
|
+
// Every string an actor's components hold: an id among them may be looked up at run time.
|
|
651
|
+
const named = new Set();
|
|
652
|
+
const strings = (x) => {
|
|
653
|
+
if (typeof x === 'string') named.add(x);
|
|
654
|
+
else if (Array.isArray(x)) x.forEach(strings);
|
|
655
|
+
else if (x && typeof x === 'object') Object.values(x).forEach(strings);
|
|
656
|
+
};
|
|
657
|
+
for (const a of actors) for (const [name, c] of Object.entries(a.components ?? {})) if (name !== 'Transform') strings(c);
|
|
658
|
+
// Two materials group only when everything three serializes of them matches (every property,
|
|
659
|
+
// which textures, userData's tags included), a superset of what the glb carries, and so does
|
|
660
|
+
// their shader program key.
|
|
661
|
+
const matKeys = new Map();
|
|
662
|
+
const matKey = (m) => {
|
|
663
|
+
let key = matKeys.get(m);
|
|
664
|
+
if (key === undefined) {
|
|
665
|
+
const json = m.toJSON();
|
|
666
|
+
delete json.uuid; delete json.name; delete json.metadata; delete json.images;
|
|
667
|
+
for (const t of json.textures ?? []) delete t.name;
|
|
668
|
+
const pk = m.customProgramCacheKey?.call(m);
|
|
669
|
+
key = `${JSON.stringify(json)}|${typeof pk === 'string' && pk !== m.uuid ? pk : ''}`;
|
|
670
|
+
matKeys.set(m, key);
|
|
671
|
+
}
|
|
672
|
+
return key;
|
|
673
|
+
};
|
|
674
|
+
const attrSig = (g) => `${g.index ? 'i' : 'n'}|${Object.entries(g.attributes).map(([k, a]) => `${k}:${a.itemSize}:${a.normalized ? 1 : 0}:${a.array.constructor.name}`).sort().join(',')}`;
|
|
675
|
+
// The meshes an actor is drawn by, each as [mesh, world matrix], or null when one cannot be baked.
|
|
676
|
+
const bakeable = (node) => {
|
|
677
|
+
const out = [];
|
|
678
|
+
let ok = true;
|
|
679
|
+
node.traverse((o) => {
|
|
680
|
+
if (!ok || !effVisible(o)) return;
|
|
681
|
+
if (o.isSprite || o.isPoints || o.isLine || o.isSkinnedMesh) { ok = false; return; }
|
|
682
|
+
if (!o.isMesh) return;
|
|
683
|
+
const g = o.geometry;
|
|
684
|
+
if (Array.isArray(o.material) || !g?.attributes?.position || Object.keys(g.morphAttributes ?? {}).length || o.instanceColor) { ok = false; return; }
|
|
685
|
+
o.updateWorldMatrix(true, false);
|
|
686
|
+
if (o.isInstancedMesh) {
|
|
687
|
+
const im = new THREE.Matrix4();
|
|
688
|
+
for (let i = 0; i < o.count; i += 1) { o.getMatrixAt(i, im); out.push([o, new THREE.Matrix4().multiplyMatrices(o.matrixWorld, im)]); }
|
|
689
|
+
} else out.push([o, o.matrixWorld.clone()]);
|
|
690
|
+
});
|
|
691
|
+
return ok ? out : null;
|
|
692
|
+
};
|
|
693
|
+
const chunks = new Map(); // chunkId -> { kind, tier, cell, ids, box, groups: Map(key -> { material, geometries, flags }) }
|
|
694
|
+
const kept = {};
|
|
695
|
+
const keep = (why) => { kept[why] = (kept[why] ?? 0) + 1; };
|
|
696
|
+
for (const a of actors) {
|
|
697
|
+
const info = actorInfo[a.id];
|
|
698
|
+
if (a.static !== true || !info) continue;
|
|
699
|
+
if (!['static', 'decor'].includes(info.kind)) { keep(`kind ${info.kind}`); continue; }
|
|
700
|
+
if (!info.visibleAtExport) { keep('hidden'); continue; }
|
|
701
|
+
if (avatarIds.has(a.id) || a.components.Body) { keep('body'); continue; }
|
|
702
|
+
if (named.has(a.id)) { keep('named by a component'); continue; }
|
|
703
|
+
if (exclude.has(a.id)) { keep('quoted in code'); continue; }
|
|
704
|
+
if (a.decor === true || a.spawnTemplate === true || a.scriptedTarget === true) { keep('template'); continue; }
|
|
705
|
+
if (keepNodes?.test(a.id)) { keep('hubKeepNodes'); continue; }
|
|
706
|
+
const node = w.nodes.get(a.id)?.node;
|
|
707
|
+
const meshes = node && bakeable(node);
|
|
708
|
+
if (!meshes) { keep('not bakeable'); continue; }
|
|
709
|
+
if (!meshes.length || !info.bounds) { keep('draws nothing'); continue; }
|
|
710
|
+
const [x0, , z0, x1, , z1] = info.bounds;
|
|
711
|
+
const cell = a.cell ?? `${Math.floor((x0 + x1) / 2 / cellM)}_${Math.floor((z0 + z1) / 2 / cellM)}`;
|
|
712
|
+
// One chunk is one tier rule: same kind, mark and own Low distance.
|
|
713
|
+
const chunkId = `merge.${info.kind}.${cell}${a.tier ? `.${a.tier}` : ''}${info.nearM ? `.n${info.nearM}` : ''}`;
|
|
714
|
+
let chunk = chunks.get(chunkId);
|
|
715
|
+
if (!chunk) { chunk = { kind: info.kind, tier: a.tier ?? null, cell: a.cell ?? null, nearM: info.nearM ?? null, ids: [], box: new THREE.Box3(), groups: new Map() }; chunks.set(chunkId, chunk); }
|
|
716
|
+
for (const [mesh, matrix] of meshes) {
|
|
717
|
+
const g = mesh.geometry.clone();
|
|
718
|
+
for (const k of Object.keys(g.attributes)) if (g.attributes[k].isInterleavedBufferAttribute) g.setAttribute(k, g.attributes[k].clone());
|
|
719
|
+
g.applyMatrix4(matrix);
|
|
720
|
+
// A mirroring matrix turns the faces inside out; put the winding back.
|
|
721
|
+
if (matrix.determinant() < 0) {
|
|
722
|
+
if (g.index) { const ix = g.index.array; for (let i = 0; i + 2 < ix.length; i += 3) { const t = ix[i + 1]; ix[i + 1] = ix[i + 2]; ix[i + 2] = t; } }
|
|
723
|
+
else for (const attr of Object.values(g.attributes)) {
|
|
724
|
+
const n = attr.itemSize; const arr = attr.array;
|
|
725
|
+
for (let v = 0; v + 2 < attr.count; v += 3) for (let c = 0; c < n; c += 1) { const t = arr[(v + 1) * n + c]; arr[(v + 1) * n + c] = arr[(v + 2) * n + c]; arr[(v + 2) * n + c] = t; }
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
g.groups = [];
|
|
729
|
+
const key = `${matKey(mesh.material)}#${attrSig(g)}#${mesh.userData.lookOutline ? 1 : 0}`;
|
|
730
|
+
let group = chunk.groups.get(key);
|
|
731
|
+
if (!group) { group = { material: mesh.material, geometries: [], outline: Boolean(mesh.userData.lookOutline) }; chunk.groups.set(key, group); }
|
|
732
|
+
group.geometries.push(g);
|
|
733
|
+
}
|
|
734
|
+
chunk.ids.push(a.id);
|
|
735
|
+
chunk.box.union(new THREE.Box3(new THREE.Vector3(x0, info.bounds[1], z0), new THREE.Vector3(x1, info.bounds[4], z1)));
|
|
736
|
+
node.visible = false; hidden.push(node);
|
|
737
|
+
delete actorInfo[a.id];
|
|
738
|
+
}
|
|
739
|
+
if (Object.keys(kept).length) notes.push(`mergeStatic: marked actors kept apart: ${Object.entries(kept).map(([k, n]) => `${n} ${k}`).join(', ')}`);
|
|
740
|
+
if (chunks.size) {
|
|
741
|
+
const mergeGroup = new THREE.Group();
|
|
742
|
+
mergeGroup.name = 'hub.merged';
|
|
743
|
+
for (const [chunkId, chunk] of chunks) {
|
|
744
|
+
const node = new THREE.Group();
|
|
745
|
+
node.name = chunkId;
|
|
746
|
+
let i = 0;
|
|
747
|
+
for (const group of chunk.groups.values()) {
|
|
748
|
+
const geometry = group.geometries.length === 1 ? group.geometries[0] : mergeGeometries(group.geometries, false);
|
|
749
|
+
if (!geometry) { errors.push(`mergeStatic: ${chunkId} could not merge a material group`); continue; }
|
|
750
|
+
const mesh = new THREE.Mesh(geometry, group.material);
|
|
751
|
+
mesh.name = `${chunkId}#${i++}`;
|
|
752
|
+
if (group.outline) mesh.userData.lookOutline = true;
|
|
753
|
+
node.add(mesh);
|
|
754
|
+
}
|
|
755
|
+
mergeGroup.add(node);
|
|
756
|
+
actorInfo[chunkId] = { kind: chunk.kind, tier: chunk.tier, cell: chunk.cell, bounds: [...v(chunk.box.min), ...v(chunk.box.max)], node: chunkId, visibleAtExport: true, merged: chunk.ids.length,
|
|
757
|
+
...(chunk.nearM ? { nearM: chunk.nearM } : {}) };
|
|
758
|
+
merged[chunkId] = chunk.ids;
|
|
759
|
+
}
|
|
760
|
+
w.scene.add(mergeGroup);
|
|
761
|
+
added.push(mergeGroup);
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
// showHidden: the hidden actors (above) drawn for the scene glb and their split models. Each
|
|
765
|
+
// node and every hidden ancestor up to the scene is shown, and from the highest one shown down
|
|
766
|
+
// every other child along the path is hidden, so nothing else those ancestors hid comes along
|
|
767
|
+
// (through a group between them that was itself visible either). Put back in
|
|
768
|
+
// `finally`. Not in `drawn` (the page draws none of it); `inventory` counts the scene glb, so it
|
|
769
|
+
// is. After the merge, which leaves them alone (visibleAtExport false).
|
|
770
|
+
if (lifted.size) {
|
|
771
|
+
const path = new Set();
|
|
772
|
+
const unreached = [];
|
|
773
|
+
for (const [id, node] of lifted) {
|
|
774
|
+
const chain = [];
|
|
775
|
+
let x = node;
|
|
776
|
+
for (; x && x !== w.scene; x = x.parent) chain.push(x);
|
|
777
|
+
if (x === w.scene) chain.forEach((o) => path.add(o));
|
|
778
|
+
else unreached.push(id);
|
|
779
|
+
}
|
|
780
|
+
const flipped = new Set();
|
|
781
|
+
for (const o of path) if (!o.visible) { shown.push([o, false]); o.visible = true; flipped.add(o); }
|
|
782
|
+
// Below a shown ancestor, every path node (down to the actor, whose own subtree is its look)
|
|
783
|
+
// keeps only its children on the path, the already visible groups between included.
|
|
784
|
+
for (const o of path) {
|
|
785
|
+
if (underLifted.has(o)) continue;
|
|
786
|
+
let exposed = false;
|
|
787
|
+
for (let x = o; x && x !== w.scene; x = x.parent) if (flipped.has(x)) exposed = true;
|
|
788
|
+
if (!exposed) continue;
|
|
789
|
+
for (const c of o.children) if (c.visible && !path.has(c)) { shown.push([c, true]); c.visible = false; }
|
|
790
|
+
}
|
|
791
|
+
notes.push(`hidden at export: ${lifted.size - unreached.length} actors exported with their meshes at their authored pose, still hidden`
|
|
792
|
+
+ (unreached.length ? `; ${unreached.length} not in the scene, not exported: ${unreached.slice(0, 8).join(', ')}` : ''));
|
|
793
|
+
}
|
|
794
|
+
const props = [];
|
|
795
|
+
if (splitModels) {
|
|
796
|
+
const byKey = new Map();
|
|
797
|
+
for (const [id, entry] of w.nodes) {
|
|
798
|
+
if (!entry?.modelKey || avatarIds.has(id) || !effVisible(entry.node)) continue;
|
|
799
|
+
const rig = entry.node.children.find((c) => c.userData.modelParts === entry.node.userData.modelParts);
|
|
800
|
+
if (!rig) continue;
|
|
801
|
+
let p = byKey.get(entry.modelKey);
|
|
802
|
+
if (!p) {
|
|
803
|
+
const copy = rig.clone(true);
|
|
804
|
+
copy.position.set(0, 0, 0); copy.quaternion.identity(); copy.scale.set(1, 1, 1); copy.name = 'model';
|
|
805
|
+
namePaint(copy);
|
|
806
|
+
let glbB64;
|
|
807
|
+
try { glbB64 = await toB64(await new GLTFExporter().parseAsync(copy, { binary: true, onlyVisible: true })); }
|
|
808
|
+
catch (e) { errors.push(`model ${entry.modelKey.split('|')[0]}: ${e}`); continue; }
|
|
809
|
+
p = { file: entry.modelKey.split('|')[0], glbB64, instances: [] };
|
|
810
|
+
byKey.set(entry.modelKey, p); props.push(p);
|
|
811
|
+
}
|
|
812
|
+
rig.updateWorldMatrix(true, false);
|
|
813
|
+
p.instances.push({ actorId: id, transform: rig.matrixWorld.toArray().map((n) => Math.round(n * 1e6) / 1e6) });
|
|
814
|
+
hiddenRigs.push([rig, rig.visible]); rig.visible = false;
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
let sceneB64 = null;
|
|
818
|
+
for (const n of avatarNodes) if (n.visible) { n.visible = false; hidden.push(n); }
|
|
819
|
+
const inventory = { meshes: 0, tris: 0, outlineHulls: 0 };
|
|
820
|
+
w.scene.traverse((o) => {
|
|
821
|
+
if (!o.isMesh || !effVisible(o)) return;
|
|
822
|
+
inventory.meshes += 1;
|
|
823
|
+
if (o.userData.lookOutline) inventory.outlineHulls += 1;
|
|
824
|
+
const g = o.geometry; inventory.tris += Math.floor((g.index ? g.index.count : g.attributes.position.count) / 3);
|
|
825
|
+
});
|
|
826
|
+
try { sceneB64 = await toB64(await new GLTFExporter().parseAsync(w.scene, { binary: true, onlyVisible: true, maxTextureSize: 2048 })); }
|
|
827
|
+
catch (e) { errors.push(`scene export: ${e?.stack ?? e}`); }
|
|
828
|
+
for (const n of hidden) n.visible = true;
|
|
829
|
+
for (const [rig, was] of hiddenRigs) rig.visible = was;
|
|
830
|
+
|
|
831
|
+
// The local player's body, at the origin, with its part names.
|
|
832
|
+
let avatarB64 = null; let avatar = null;
|
|
833
|
+
const pnode = bodyActor ? w.nodes.get(bodyActor.id)?.node : null;
|
|
834
|
+
if (exportAvatar && pnode) {
|
|
835
|
+
const parts = pnode.userData.modelParts;
|
|
836
|
+
const pathOf = (o) => { const p = []; for (let x = o; x && x !== pnode; x = x.parent) p.unshift(x.parent.children.indexOf(x)); return p; };
|
|
837
|
+
const partPaths = [];
|
|
838
|
+
if (parts) for (const [name, o] of (parts instanceof Map ? parts : Object.entries(parts))) if (o?.isObject3D) partPaths.push([name, pathOf(o)]);
|
|
839
|
+
const clone = pnode.clone(true);
|
|
840
|
+
clone.position.set(0, 0, 0); clone.quaternion.identity(); clone.visible = true; clone.name = 'hub-player';
|
|
841
|
+
delete clone.userData.__actor;
|
|
842
|
+
for (const [name, p] of partPaths) { let x = clone; for (const i of p) x = x?.children[i]; if (x) x.name = name; }
|
|
843
|
+
try { avatarB64 = await toB64(await new GLTFExporter().parseAsync(clone, { binary: true, onlyVisible: true })); } catch (e) { errors.push(`avatar export: ${e}`); }
|
|
844
|
+
pnode.updateWorldMatrix(true, false);
|
|
845
|
+
const p0 = new THREE.Vector3().setFromMatrixPosition(pnode.matrixWorld);
|
|
846
|
+
const sh = bodyActor.components.Shape;
|
|
847
|
+
avatar = { parts: partPaths.map(([n]) => n), rootAboveFloor: p0.y - floorY(p0.x, p0.y, p0.z), capsule: sh ? { radius: sh.radius ?? 0.35, height: sh.height ?? 1.4 } : { radius: 0.35, height: 1.4 } };
|
|
848
|
+
} else if (exportAvatar) notes.push('no local player node: no avatar exported');
|
|
849
|
+
|
|
850
|
+
// The arrival floor for a candidate, computed here where the meshes are.
|
|
851
|
+
const floors = Object.fromEntries(spawnCandidates.map((c) => [c.actorId, c.floor]));
|
|
852
|
+
return {
|
|
853
|
+
errors, notes, warnings, three: globalThis.__THREE__, title: s.data?.name ?? null,
|
|
854
|
+
actors: actorInfo, colliders, ground, doors, characters, interactables, labels, spawnCandidates, starts, floorsByActor: floors,
|
|
855
|
+
lights, fog, render, camera, sky: sky ? { ...sky, zones: sky.zones } : null, tier: tierNow, tiers, cells: s.data?.cells ?? null,
|
|
856
|
+
inventory, stats: { actors: actors.length, actorsWithNodes: Object.keys(actorInfo).length, mergedActors: Object.values(merged).reduce((n, ids) => n + ids.length, 0), mergedChunks: Object.keys(merged).length, droppedEmpty: dropped.length, meshes: inventory.meshes, triangles: inventory.tris, outlineHulls: inventory.outlineHulls,
|
|
857
|
+
drawnNodes: drawn.nodes, drawnMeshes: drawn.meshes, drawnTriangles: drawn.tris },
|
|
858
|
+
sceneB64, avatarB64, avatar, props, merged,
|
|
859
|
+
};
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
// v1.6: the sound files a hub block names (root `idle.sounds`, then each place's), each once, in
|
|
864
|
+
// that order: what the kit's sound.js may ask initialMedia for (`hub.place.idle.sounds`).
|
|
865
|
+
export function deckSoundPaths(block) {
|
|
866
|
+
const isObj = (v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
867
|
+
if (!isObj(block)) return [];
|
|
868
|
+
const files = new Set();
|
|
869
|
+
for (const place of [block, ...Object.values(isObj(block.places) ? block.places : {})]) {
|
|
870
|
+
const sounds = place?.idle?.sounds;
|
|
871
|
+
if (Array.isArray(sounds)) for (const file of sounds) files.add(file);
|
|
872
|
+
}
|
|
873
|
+
return [...files];
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
// v1.6: the kit's deckFlags plus the place sound declarations at their castle.json keys (root
|
|
877
|
+
// `idle`, `places[id].idle` for each place that has one), not flattened or sanitised.
|
|
878
|
+
export function audioDeckFlags(block, flags) {
|
|
879
|
+
const out = { ...flags };
|
|
880
|
+
if (block === null || typeof block !== 'object' || Array.isArray(block)) return out;
|
|
881
|
+
if (Object.hasOwn(block, 'idle')) out.idle = JSON.parse(JSON.stringify(block.idle));
|
|
882
|
+
if (block.places && typeof block.places === 'object' && !Array.isArray(block.places)) {
|
|
883
|
+
out.places = Object.fromEntries(Object.entries(block.places)
|
|
884
|
+
.filter(([, place]) => place !== null && typeof place === 'object' && Object.hasOwn(place, 'idle'))
|
|
885
|
+
.map(([id, place]) => [id, { idle: JSON.parse(JSON.stringify(place.idle)) }]));
|
|
886
|
+
}
|
|
887
|
+
return out;
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
// A scene's engine.hubKeepNodes (mergeStatic): ids or patterns, `*` matching any run of characters,
|
|
891
|
+
// as a matcher ({ test(id) }); null when the key is absent or names nothing. At most
|
|
892
|
+
// KEEP_PATTERNS_MAX patterns of at most KEEP_PATTERN_LEN characters; a value that is not a list,
|
|
893
|
+
// and entries that are not such strings, are left out with a note. Matching is the two-pointer
|
|
894
|
+
// wildcard walk (back to the last `*` only), never a RegExp: no pattern can make it backtrack.
|
|
895
|
+
const KEEP_PATTERNS_MAX = 256;
|
|
896
|
+
const KEEP_PATTERN_LEN = 128;
|
|
897
|
+
function keepNodesOf(value, notes) {
|
|
898
|
+
if (value === undefined) return null;
|
|
899
|
+
const list = Array.isArray(value) ? value : [];
|
|
900
|
+
const good = list.filter((p) => typeof p === 'string' && p.length > 0 && p.length <= KEEP_PATTERN_LEN).slice(0, KEEP_PATTERNS_MAX);
|
|
901
|
+
if (!Array.isArray(value) || good.length !== list.length) {
|
|
902
|
+
notes.push(`mergeStatic: engine.hubKeepNodes takes a list of at most ${KEEP_PATTERNS_MAX} id patterns of 1-${KEEP_PATTERN_LEN} characters; the rest was ignored`);
|
|
903
|
+
}
|
|
904
|
+
if (!good.length) return null;
|
|
905
|
+
const exact = new Set(good.filter((p) => !p.includes('*')));
|
|
906
|
+
const globs = [...new Set(good.filter((p) => p.includes('*')).map((p) => p.replace(/\*+/g, '*')))];
|
|
907
|
+
return { test: (id) => exact.has(id) || globs.some((p) => globMatch(p, id)) };
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
// `*` matches any run of characters (none included), every other character itself. O(p * s) at worst.
|
|
911
|
+
export function globMatch(pattern, s) {
|
|
912
|
+
let p = 0; let i = 0; let star = -1; let mark = 0;
|
|
913
|
+
while (i < s.length) {
|
|
914
|
+
if (p < pattern.length && pattern[p] !== '*' && pattern[p] === s[i]) { p += 1; i += 1; }
|
|
915
|
+
else if (p < pattern.length && pattern[p] === '*') { star = p; mark = i; p += 1; }
|
|
916
|
+
else if (star !== -1) { p = star + 1; mark += 1; i = mark; }
|
|
917
|
+
else return false;
|
|
918
|
+
}
|
|
919
|
+
while (p < pattern.length && pattern[p] === '*') p += 1;
|
|
920
|
+
return p === pattern.length;
|
|
921
|
+
}
|