@hypersoniclabs/helix-cli 0.1.27-helix3.661 → 0.1.27-helix3.663
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/character/stages/armBindFixRig.js +3 -0
- package/dist/character/stages/armBindFixRig.js.map +1 -1
- package/dist/character/stages/mergeSkins.d.ts +33 -0
- package/dist/character/stages/mergeSkins.js +179 -0
- package/dist/character/stages/mergeSkins.js.map +1 -0
- package/dist/character/stages/sceneOrphans.d.ts +13 -0
- package/dist/character/stages/sceneOrphans.js +50 -0
- package/dist/character/stages/sceneOrphans.js.map +1 -0
- package/dist/character/stages/unshareLodGeometry.d.ts +13 -0
- package/dist/character/stages/unshareLodGeometry.js +88 -0
- package/dist/character/stages/unshareLodGeometry.js.map +1 -0
- package/dist/character/stages/vrmLods.d.ts +7 -0
- package/dist/character/stages/vrmLods.js +19 -2
- package/dist/character/stages/vrmLods.js.map +1 -1
- package/dist/character/vrmCharacter.d.ts +14 -0
- package/dist/character/vrmCharacter.js +38 -5
- package/dist/character/vrmCharacter.js.map +1 -1
- package/dist/city/convert/stages.js +1 -1
- package/dist/cs2/convert/roadBake.js +0 -7
- package/dist/cs2/convert/roadBake.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -4,6 +4,7 @@ exports.mergeRestPose = mergeRestPose;
|
|
|
4
4
|
exports.fixRigDocument = fixRigDocument;
|
|
5
5
|
exports.fixRigFile = fixRigFile;
|
|
6
6
|
exports.describeFixRig = describeFixRig;
|
|
7
|
+
const unshareLodGeometry_1 = require("./unshareLodGeometry");
|
|
7
8
|
const core_1 = require("@gltf-transform/core");
|
|
8
9
|
const avatarExtensions_1 = require("../avatarExtensions");
|
|
9
10
|
const node_fs_1 = require("node:fs");
|
|
@@ -22,6 +23,8 @@ function mergeRestPose(a, b) {
|
|
|
22
23
|
return { ...a, ground: b.ground ?? a.ground, skipped: a.skipped && b.skipped ? a.skipped : undefined };
|
|
23
24
|
}
|
|
24
25
|
async function fixRigDocument(document, options = {}) {
|
|
26
|
+
// Per-LOD edits below must never touch geometry another scene also draws.
|
|
27
|
+
(0, unshareLodGeometry_1.unshareLodGeometry)(document);
|
|
25
28
|
const reach = options.weights === false ? false : options.weights?.armReach ?? { mode: options.weights?.mode };
|
|
26
29
|
const armReach = reach === false ? null : (0, hairWeights_1.releaseArmReach)(document, reach);
|
|
27
30
|
const restOptions = options.restPose === false ? null : options.restPose ?? {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"armBindFixRig.js","sourceRoot":"","sources":["../../../src/character/stages/armBindFixRig.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"armBindFixRig.js","sourceRoot":"","sources":["../../../src/character/stages/armBindFixRig.ts"],"names":[],"mappings":";;AA6CA,sCAIC;AAED,wCAiBC;AAED,gCAWC;AAGD,wCAsBC;AA1GD,6DAA0D;AAC1D,+CAA6D;AAC7D,0DAAwD;AACxD,qCAAoC;AACpC,yCAA6C;AAC7C,iDAA+D;AAC/D,uCAAqH;AACrH,+CAA8I;AAC9I,yCAA2H;AAC3H,6CAAgK;AAmChK,mHAAmH;AACnH,SAAgB,aAAa,CAAC,CAAwB,EAAE,CAAwB;IAC9E,IAAI,CAAC,KAAK,IAAI;QAAE,OAAO,CAAC,CAAC;IACzB,IAAI,CAAC,KAAK,IAAI;QAAE,OAAO,CAAC,CAAC;IACzB,OAAO,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;AACzG,CAAC;AAEM,KAAK,UAAU,cAAc,CAAC,QAAkB,EAAE,UAAyB,EAAE;IAClF,0EAA0E;IAC1E,IAAA,uCAAkB,EAAC,Q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oB,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,uDAAuD,CAAC,CAAC,iBAAiB,QAAQ,CAAC,CAAC,gBAAgB,aAAa,CAAC,CAAC;QACzM,CAAC;IACH,CAAC;IACD,IAAI,MAAM,CAAC,MAAM;QAAE,KAAK,CAAC,IAAI,CAAC,WAAW,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;IAC1D,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Document } from '@gltf-transform/core';
|
|
2
|
+
export interface MergeSkinsReport {
|
|
3
|
+
/** Skins folded into the first one. */
|
|
4
|
+
merged: number;
|
|
5
|
+
/** Skins whose meshes were moved by a constant bind offset before the merge (their inverse bind matrices differed by one translation). */
|
|
6
|
+
rebased: number;
|
|
7
|
+
/** Joints that were not in the first skin and were appended to it (with their own inverse bind matrix). */
|
|
8
|
+
appendedJoints: number;
|
|
9
|
+
/** Skins left alone, each with the reason. */
|
|
10
|
+
skipped: {
|
|
11
|
+
skin: string;
|
|
12
|
+
reason: string;
|
|
13
|
+
}[];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Fold every other skin into the first when they describe one skeleton: a joint both skins list must bind with the same
|
|
17
|
+
* inverse bind matrix, and a joint only the later skin lists (a tail, an accessory chain, an extra spring bone) is
|
|
18
|
+
* appended to the first with that skin's own matrix. Each primitive's JOINTS_n is rewritten to the merged index.
|
|
19
|
+
*
|
|
20
|
+
* `collapseIdenticalSkins` handles skins that are byte-for-byte the same list; this handles the next case up, which is
|
|
21
|
+
* what a real VRM export looks like (SysMocap VAL has 9 skins, a tail mesh skinned to joints the body skin does not
|
|
22
|
+
* list). `conformToHelixRest` reads `listSkins()[0]` and rebinds only its meshes; every other mesh kept its source
|
|
23
|
+
* joints, which the LOD merge then refused ("skinned to joints outside that scene").
|
|
24
|
+
*
|
|
25
|
+
* Two skins over the same joints can still bind differently by ONE constant offset (a mesh authored with an object
|
|
26
|
+
* transform: SysMocap VAL's tail and ears, neon FAST_FOOD_MAX's cylinder). `inverse(A) * B` is then the same pure
|
|
27
|
+
* translation T on every shared joint, so the mesh is rebased into the first skin's bind space (positions += T) and merged;
|
|
28
|
+
* the pose is unchanged because `J * IBM_A * T == J * IBM_B`.
|
|
29
|
+
*
|
|
30
|
+
* A skin whose shared joints differ by anything but a constant translation, whose primitives share a JOINTS accessor with another skin's, or that
|
|
31
|
+
* has no inverse bind matrices is left alone and reported: merging those changes the pose.
|
|
32
|
+
*/
|
|
33
|
+
export declare function mergeCompatibleSkins(document: Document): MergeSkinsReport;
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mergeCompatibleSkins = mergeCompatibleSkins;
|
|
4
|
+
const mat4_1 = require("../mat4");
|
|
5
|
+
// The same tolerance bakeRestSkin calls "agrees": the converter re-derives every bind matrix from the joints anyway (1 mm).
|
|
6
|
+
const IBM_TOLERANCE = 1e-3;
|
|
7
|
+
const IDENTITY = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
|
8
|
+
/**
|
|
9
|
+
* Fold every other skin into the first when they describe one skeleton: a joint both skins list must bind with the same
|
|
10
|
+
* inverse bind matrix, and a joint only the later skin lists (a tail, an accessory chain, an extra spring bone) is
|
|
11
|
+
* appended to the first with that skin's own matrix. Each primitive's JOINTS_n is rewritten to the merged index.
|
|
12
|
+
*
|
|
13
|
+
* `collapseIdenticalSkins` handles skins that are byte-for-byte the same list; this handles the next case up, which is
|
|
14
|
+
* what a real VRM export looks like (SysMocap VAL has 9 skins, a tail mesh skinned to joints the body skin does not
|
|
15
|
+
* list). `conformToHelixRest` reads `listSkins()[0]` and rebinds only its meshes; every other mesh kept its source
|
|
16
|
+
* joints, which the LOD merge then refused ("skinned to joints outside that scene").
|
|
17
|
+
*
|
|
18
|
+
* Two skins over the same joints can still bind differently by ONE constant offset (a mesh authored with an object
|
|
19
|
+
* transform: SysMocap VAL's tail and ears, neon FAST_FOOD_MAX's cylinder). `inverse(A) * B` is then the same pure
|
|
20
|
+
* translation T on every shared joint, so the mesh is rebased into the first skin's bind space (positions += T) and merged;
|
|
21
|
+
* the pose is unchanged because `J * IBM_A * T == J * IBM_B`.
|
|
22
|
+
*
|
|
23
|
+
* A skin whose shared joints differ by anything but a constant translation, whose primitives share a JOINTS accessor with another skin's, or that
|
|
24
|
+
* has no inverse bind matrices is left alone and reported: merging those changes the pose.
|
|
25
|
+
*/
|
|
26
|
+
function mergeCompatibleSkins(document) {
|
|
27
|
+
const report = { merged: 0, rebased: 0, appendedJoints: 0, skipped: [] };
|
|
28
|
+
const skins = document.getRoot().listSkins();
|
|
29
|
+
if (skins.length < 2)
|
|
30
|
+
return report;
|
|
31
|
+
const first = skins[0];
|
|
32
|
+
const firstIbm = first.getInverseBindMatrices();
|
|
33
|
+
if (firstIbm === null)
|
|
34
|
+
return report;
|
|
35
|
+
const nodes = document.getRoot().listNodes();
|
|
36
|
+
const usersOf = (skin) => nodes.filter((node) => node.getSkin() === skin);
|
|
37
|
+
// Which skins read each JOINTS / POSITION accessor, to refuse a merge that would rewrite an accessor another skin still reads.
|
|
38
|
+
const accessorSkins = new Map();
|
|
39
|
+
for (const node of nodes) {
|
|
40
|
+
const skin = node.getSkin();
|
|
41
|
+
const mesh = node.getMesh();
|
|
42
|
+
if (skin === null || mesh === null)
|
|
43
|
+
continue;
|
|
44
|
+
for (const primitive of mesh.listPrimitives())
|
|
45
|
+
for (const semantic of primitive.listSemantics().filter((s) => s.startsWith('JOINTS_') || s === 'POSITION')) {
|
|
46
|
+
const accessor = primitive.getAttribute(semantic);
|
|
47
|
+
const set = accessorSkins.get(accessor) ?? new Set();
|
|
48
|
+
set.add(skin);
|
|
49
|
+
accessorSkins.set(accessor, set);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const primitivesOf = (skinUsers) => skinUsers.flatMap((node) => node.getMesh()?.listPrimitives() ?? []);
|
|
53
|
+
/** Joint indices this skin's meshes actually weight; a bind matrix nobody skins to cannot move a vertex. */
|
|
54
|
+
const weightedIndices = (users) => {
|
|
55
|
+
const used = new Set();
|
|
56
|
+
for (const primitive of primitivesOf(users)) {
|
|
57
|
+
for (const semantic of primitive.listSemantics().filter((s) => s.startsWith('JOINTS_'))) {
|
|
58
|
+
const set = semantic.slice('JOINTS_'.length);
|
|
59
|
+
const joints = primitive.getAttribute(semantic)?.getArray();
|
|
60
|
+
const weights = primitive.getAttribute(`WEIGHTS_${set}`)?.getArray();
|
|
61
|
+
if (joints === null || joints === undefined || weights === null || weights === undefined)
|
|
62
|
+
continue;
|
|
63
|
+
for (let k = 0; k < joints.length; k++)
|
|
64
|
+
if (weights[k] > 0)
|
|
65
|
+
used.add(joints[k]);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return used;
|
|
69
|
+
};
|
|
70
|
+
let jointList = first.listJoints();
|
|
71
|
+
const ibm = Array.from(firstIbm.getArray());
|
|
72
|
+
for (const skin of skins.slice(1)) {
|
|
73
|
+
const users = usersOf(skin);
|
|
74
|
+
if (users.length === 0)
|
|
75
|
+
continue;
|
|
76
|
+
const own = skin.listJoints();
|
|
77
|
+
const ownIbm = skin.getInverseBindMatrices()?.getArray();
|
|
78
|
+
if (ownIbm === null || ownIbm === undefined) {
|
|
79
|
+
report.skipped.push({ skin: skin.getName(), reason: 'no inverse bind matrices' });
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
const where = new Map(jointList.map((joint, i) => [joint, i]));
|
|
83
|
+
// The offset between the two bind spaces: inverse(A) * B on every shared joint, which must be one constant matrix.
|
|
84
|
+
let conflict = null;
|
|
85
|
+
let offset = IDENTITY;
|
|
86
|
+
let offsetSet = false;
|
|
87
|
+
const toAppend = [];
|
|
88
|
+
const used = weightedIndices(users);
|
|
89
|
+
const close = (x, y) => x.every((v, k) => Math.abs(v - y[k]) <= IBM_TOLERANCE * Math.max(1, Math.abs(v)));
|
|
90
|
+
own.forEach((joint, i) => {
|
|
91
|
+
const at = where.get(joint);
|
|
92
|
+
if (at === undefined) {
|
|
93
|
+
toAppend.push(i);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (!used.has(i))
|
|
97
|
+
return;
|
|
98
|
+
const t = (0, mat4_1.mul4)((0, mat4_1.invert4)(ibm.slice(at * 16, at * 16 + 16)), Array.from(ownIbm.subarray(i * 16, i * 16 + 16)));
|
|
99
|
+
if (!offsetSet) {
|
|
100
|
+
offset = t;
|
|
101
|
+
offsetSet = true;
|
|
102
|
+
}
|
|
103
|
+
else if (!close(offset, t))
|
|
104
|
+
conflict ??= `joint '${joint.getName()}' binds differently from the others by a different offset`;
|
|
105
|
+
});
|
|
106
|
+
const translationOnly = close([...offset.slice(0, 12), 0, 0, 0, 1], IDENTITY) || close(offset, IDENTITY);
|
|
107
|
+
if (conflict === null && !translationOnly)
|
|
108
|
+
conflict = 'its bind space differs from the first skin by more than a translation';
|
|
109
|
+
const moved = !close(offset, IDENTITY);
|
|
110
|
+
for (const primitive of primitivesOf(users)) {
|
|
111
|
+
for (const semantic of primitive.listSemantics().filter((s) => s.startsWith('JOINTS_') || s === 'POSITION')) {
|
|
112
|
+
const accessor = primitive.getAttribute(semantic);
|
|
113
|
+
const serving = accessorSkins.get(accessor);
|
|
114
|
+
if (serving !== undefined && serving.size > 1)
|
|
115
|
+
conflict ??= `a ${semantic} accessor is shared with another skin`;
|
|
116
|
+
if (moved && semantic === 'POSITION' && !(accessor.getArray() instanceof Float32Array))
|
|
117
|
+
conflict ??= 'POSITION is not float32, so it cannot be rebased';
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (conflict !== null) {
|
|
121
|
+
report.skipped.push({ skin: skin.getName(), reason: conflict });
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
// Append the joints only this skin has, in the first skin's bind space: IBM_A = IBM_B * inverse(offset).
|
|
125
|
+
const back = (0, mat4_1.invert4)(offset);
|
|
126
|
+
const indexFor = own.map((joint) => where.get(joint) ?? -1);
|
|
127
|
+
let next = jointList.length;
|
|
128
|
+
toAppend.forEach((i) => { indexFor[i] = next++; });
|
|
129
|
+
for (const i of toAppend)
|
|
130
|
+
ibm.push(...(0, mat4_1.mul4)(Array.from(ownIbm.subarray(i * 16, i * 16 + 16)), back));
|
|
131
|
+
const appended = toAppend.map((i) => own[i]);
|
|
132
|
+
jointList = [...jointList, ...appended];
|
|
133
|
+
report.appendedJoints += appended.length;
|
|
134
|
+
const touched = new Set();
|
|
135
|
+
for (const primitive of primitivesOf(users)) {
|
|
136
|
+
for (const semantic of primitive.listSemantics().filter((s) => s.startsWith('JOINTS_') || s === 'POSITION')) {
|
|
137
|
+
const accessor = primitive.getAttribute(semantic);
|
|
138
|
+
if (touched.has(accessor))
|
|
139
|
+
continue;
|
|
140
|
+
touched.add(accessor);
|
|
141
|
+
if (semantic === 'POSITION') {
|
|
142
|
+
if (!moved)
|
|
143
|
+
continue;
|
|
144
|
+
const array = accessor.getArray();
|
|
145
|
+
for (let k = 0; k + 2 < array.length; k += 3) {
|
|
146
|
+
array[k] += offset[12];
|
|
147
|
+
array[k + 1] += offset[13];
|
|
148
|
+
array[k + 2] += offset[14];
|
|
149
|
+
}
|
|
150
|
+
accessor.setArray(array);
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
const source = accessor.getArray();
|
|
154
|
+
const out = new Uint16Array(source.length);
|
|
155
|
+
for (let k = 0; k < source.length; k++)
|
|
156
|
+
out[k] = indexFor[source[k]] ?? source[k];
|
|
157
|
+
// Keep the component type when it still fits; widen to 16 bits otherwise.
|
|
158
|
+
const fits = source instanceof Uint8Array && out.every((v) => v <= 255);
|
|
159
|
+
accessor.setArray(fits ? Uint8Array.from(out) : out);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
for (const node of users)
|
|
163
|
+
node.setSkin(first);
|
|
164
|
+
report.merged++;
|
|
165
|
+
if (moved)
|
|
166
|
+
report.rebased++;
|
|
167
|
+
}
|
|
168
|
+
if (report.appendedJoints > 0) {
|
|
169
|
+
for (const joint of jointList.slice(first.listJoints().length))
|
|
170
|
+
first.addJoint(joint);
|
|
171
|
+
}
|
|
172
|
+
firstIbm.setArray(Float32Array.from(ibm));
|
|
173
|
+
// A merged-away skin has no node left to bind; dispose so the writer does not ship it.
|
|
174
|
+
for (const skin of skins.slice(1))
|
|
175
|
+
if (usersOf(skin).length === 0)
|
|
176
|
+
skin.dispose();
|
|
177
|
+
return report;
|
|
178
|
+
}
|
|
179
|
+
//# sourceMappingURL=mergeSkins.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mergeSkins.js","sourceRoot":"","sources":["../../../src/character/stages/mergeSkins.ts"],"names":[],"mappings":";;AAoCA,oDA2HC;AA9JD,kCAAwC;AAaxC,4HAA4H;AAC5H,MAAM,aAAa,GAAG,IAAI,CAAC;AAC3B,MAAM,QAAQ,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAElE;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAgB,oBAAoB,CAAC,QAAkB;IACrD,MAAM,MAAM,GAAqB,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,cAAc,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;IAC3F,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,EAAE,CAAC,SAAS,EAAE,CAAC;IAC7C,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,MAAM,CAAC;IACpC,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAE,CAAC;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G,CAAC,EAAE,CAAC;QAC9B,KAAK,MAAM,KAAK,IAAI,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC,MAAM,CAAC;YAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACxF,CAAC;IACD,QAAQ,CAAC,QAAQ,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAC1C,uFAAuF;IACvF,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;QAAE,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC;YAAE,IAAI,CAAC,OAAO,EAAE,CAAC;IAClF,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Document } from '@gltf-transform/core';
|
|
2
|
+
/**
|
|
3
|
+
* Dispose every node that no scene reaches and no skin binds.
|
|
4
|
+
*
|
|
5
|
+
* `conformToHelixRest` rebuilds the rig and disposes only the top node of the SOURCE rig; its descendants (eye.L, head,
|
|
6
|
+
* neck, FaceFront, thumb joints ...) stay in the document with no parent and no scene. Nothing can draw, animate or look
|
|
7
|
+
* them up, but the publish gate's per-LOD draw-call projection requires every node to sit in some scene
|
|
8
|
+
* (`covered.size !== nodes.length` falls back to the SUM over the three LOD scenes). Companion-Space Mira carried 132 of
|
|
9
|
+
* them and was refused at 21 draws where each level draws 7.
|
|
10
|
+
*
|
|
11
|
+
* A node survives when a scene reaches it, a skin lists it as a joint or skeleton, or an animation channel targets it.
|
|
12
|
+
*/
|
|
13
|
+
export declare function disposeSceneOrphans(document: Document): number;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.disposeSceneOrphans = disposeSceneOrphans;
|
|
4
|
+
/**
|
|
5
|
+
* Dispose every node that no scene reaches and no skin binds.
|
|
6
|
+
*
|
|
7
|
+
* `conformToHelixRest` rebuilds the rig and disposes only the top node of the SOURCE rig; its descendants (eye.L, head,
|
|
8
|
+
* neck, FaceFront, thumb joints ...) stay in the document with no parent and no scene. Nothing can draw, animate or look
|
|
9
|
+
* them up, but the publish gate's per-LOD draw-call projection requires every node to sit in some scene
|
|
10
|
+
* (`covered.size !== nodes.length` falls back to the SUM over the three LOD scenes). Companion-Space Mira carried 132 of
|
|
11
|
+
* them and was refused at 21 draws where each level draws 7.
|
|
12
|
+
*
|
|
13
|
+
* A node survives when a scene reaches it, a skin lists it as a joint or skeleton, or an animation channel targets it.
|
|
14
|
+
*/
|
|
15
|
+
function disposeSceneOrphans(document) {
|
|
16
|
+
const root = document.getRoot();
|
|
17
|
+
const keep = new Set();
|
|
18
|
+
const reach = (node) => {
|
|
19
|
+
if (keep.has(node))
|
|
20
|
+
return;
|
|
21
|
+
keep.add(node);
|
|
22
|
+
for (const child of node.listChildren())
|
|
23
|
+
reach(child);
|
|
24
|
+
};
|
|
25
|
+
for (const scene of root.listScenes())
|
|
26
|
+
for (const child of scene.listChildren())
|
|
27
|
+
reach(child);
|
|
28
|
+
for (const skin of root.listSkins()) {
|
|
29
|
+
for (const joint of skin.listJoints())
|
|
30
|
+
reach(joint);
|
|
31
|
+
const skeleton = skin.getSkeleton();
|
|
32
|
+
if (skeleton !== null)
|
|
33
|
+
reach(skeleton);
|
|
34
|
+
}
|
|
35
|
+
for (const animation of root.listAnimations())
|
|
36
|
+
for (const channel of animation.listChannels()) {
|
|
37
|
+
const target = channel.getTargetNode();
|
|
38
|
+
if (target !== null)
|
|
39
|
+
reach(target);
|
|
40
|
+
}
|
|
41
|
+
let removed = 0;
|
|
42
|
+
for (const node of root.listNodes()) {
|
|
43
|
+
if (keep.has(node))
|
|
44
|
+
continue;
|
|
45
|
+
node.dispose();
|
|
46
|
+
removed++;
|
|
47
|
+
}
|
|
48
|
+
return removed;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=sceneOrphans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,CAAC,CAAC;QACrC,CAAC;IACH,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,SAAS,EAAE,EAAE,CAAC;QACpC,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC;YAAE,SAAS;QAC7B,IAAI,CAAC,OAAO,EAAE,CAAC;QACf,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Document } from '@gltf-transform/core';
|
|
2
|
+
/**
|
|
3
|
+
* Give every LOD scene its own vertex data.
|
|
4
|
+
*
|
|
5
|
+
* `mergeLods` folds identical accessors back together, so a level that left a primitive untouched (LOD1 of a model the
|
|
6
|
+
* ladder could not reduce, or a primitive under the per-primitive floor) points at the SAME POSITION/NORMAL/JOINTS/WEIGHTS
|
|
7
|
+
* accessors as LOD0. The rig-fix stages (`fixRig` re-binds the arms and "bakes N vertices per LOD") then walk each scene
|
|
8
|
+
* and edit those accessors in place, so shared geometry is edited once per scene it appears in: Zombie's sleeves were
|
|
9
|
+
* baked twice and splayed into wings in LOD0 and LOD1 while the unshared LOD2 stayed clean.
|
|
10
|
+
*
|
|
11
|
+
* Idempotent, and a no-op on a file whose scenes already own their data. Indices stay shared (nothing edits them).
|
|
12
|
+
*/
|
|
13
|
+
export declare function unshareLodGeometry(document: Document): number;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.unshareLodGeometry = unshareLodGeometry;
|
|
4
|
+
/**
|
|
5
|
+
* Give every LOD scene its own vertex data.
|
|
6
|
+
*
|
|
7
|
+
* `mergeLods` folds identical accessors back together, so a level that left a primitive untouched (LOD1 of a model the
|
|
8
|
+
* ladder could not reduce, or a primitive under the per-primitive floor) points at the SAME POSITION/NORMAL/JOINTS/WEIGHTS
|
|
9
|
+
* accessors as LOD0. The rig-fix stages (`fixRig` re-binds the arms and "bakes N vertices per LOD") then walk each scene
|
|
10
|
+
* and edit those accessors in place, so shared geometry is edited once per scene it appears in: Zombie's sleeves were
|
|
11
|
+
* baked twice and splayed into wings in LOD0 and LOD1 while the unshared LOD2 stayed clean.
|
|
12
|
+
*
|
|
13
|
+
* Idempotent, and a no-op on a file whose scenes already own their data. Indices stay shared (nothing edits them).
|
|
14
|
+
*/
|
|
15
|
+
function unshareLodGeometry(document) {
|
|
16
|
+
const root = document.getRoot();
|
|
17
|
+
const accessorOwner = new Map();
|
|
18
|
+
const meshOwner = new Map();
|
|
19
|
+
let cloned = 0;
|
|
20
|
+
const fresh = (accessor) => {
|
|
21
|
+
cloned++;
|
|
22
|
+
const copy = document.createAccessor(accessor.getName())
|
|
23
|
+
.setType(accessor.getType())
|
|
24
|
+
.setArray(accessor.getArray().slice())
|
|
25
|
+
.setNormalized(accessor.getNormalized())
|
|
26
|
+
.setBuffer(accessor.getBuffer());
|
|
27
|
+
return copy;
|
|
28
|
+
};
|
|
29
|
+
const own = (accessor, scene) => {
|
|
30
|
+
const owner = accessorOwner.get(accessor);
|
|
31
|
+
if (owner === undefined) {
|
|
32
|
+
accessorOwner.set(accessor, scene);
|
|
33
|
+
return accessor;
|
|
34
|
+
}
|
|
35
|
+
if (owner === scene)
|
|
36
|
+
return accessor;
|
|
37
|
+
const copy = fresh(accessor);
|
|
38
|
+
accessorOwner.set(copy, scene);
|
|
39
|
+
return copy;
|
|
40
|
+
};
|
|
41
|
+
const visit = (node, scene) => {
|
|
42
|
+
const mesh = node.getMesh();
|
|
43
|
+
if (mesh !== null) {
|
|
44
|
+
let target = mesh;
|
|
45
|
+
const owner = meshOwner.get(mesh);
|
|
46
|
+
if (owner === undefined)
|
|
47
|
+
meshOwner.set(mesh, scene);
|
|
48
|
+
else if (owner !== scene) {
|
|
49
|
+
target = document.createMesh(mesh.getName()).setExtras(mesh.getExtras()).setWeights([...mesh.getWeights()]);
|
|
50
|
+
for (const primitive of mesh.listPrimitives()) {
|
|
51
|
+
const copy = document.createPrimitive().setMode(primitive.getMode()).setMaterial(primitive.getMaterial()).setIndices(primitive.getIndices());
|
|
52
|
+
for (const semantic of primitive.listSemantics())
|
|
53
|
+
copy.setAttribute(semantic, primitive.getAttribute(semantic));
|
|
54
|
+
for (const t of primitive.listTargets()) {
|
|
55
|
+
const targetCopy = document.createPrimitiveTarget(t.getName());
|
|
56
|
+
for (const semantic of t.listSemantics())
|
|
57
|
+
targetCopy.setAttribute(semantic, t.getAttribute(semantic));
|
|
58
|
+
copy.addTarget(targetCopy);
|
|
59
|
+
}
|
|
60
|
+
target.addPrimitive(copy);
|
|
61
|
+
}
|
|
62
|
+
node.setMesh(target);
|
|
63
|
+
meshOwner.set(target, scene);
|
|
64
|
+
}
|
|
65
|
+
for (const primitive of target.listPrimitives()) {
|
|
66
|
+
for (const semantic of primitive.listSemantics()) {
|
|
67
|
+
const accessor = primitive.getAttribute(semantic);
|
|
68
|
+
const mine = own(accessor, scene);
|
|
69
|
+
if (mine !== accessor)
|
|
70
|
+
primitive.setAttribute(semantic, mine);
|
|
71
|
+
}
|
|
72
|
+
for (const t of primitive.listTargets())
|
|
73
|
+
for (const semantic of t.listSemantics()) {
|
|
74
|
+
const accessor = t.getAttribute(semantic);
|
|
75
|
+
const mine = own(accessor, scene);
|
|
76
|
+
if (mine !== accessor)
|
|
77
|
+
t.setAttribute(semantic, mine);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
for (const child of node.listChildren())
|
|
82
|
+
visit(child, scene);
|
|
83
|
+
};
|
|
84
|
+
root.listScenes().forEach((scene, index) => { for (const child of scene.listChildren())
|
|
85
|
+
visit(child, index); });
|
|
86
|
+
return cloned;
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=unshareLodGeometry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unshareLodGeometry.js","sourceRoot":"","sources":["../../../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,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,GAAG,KAAK,MAAM,KAAK,IAAI,KAAK,CAAC,YAAY,EAAE;QAAE,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAChH,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -40,6 +40,13 @@ export interface VrmLodLevel {
|
|
|
40
40
|
* whatever the budget stage left LOD0 at. Summed over the chain this is ~1.5x LOD0 against the 4x the publish gate allows.
|
|
41
41
|
*/
|
|
42
42
|
export declare function vrmLodLadder(lod0Tris: number): VrmLodLevel[];
|
|
43
|
+
/**
|
|
44
|
+
* A level must keep at most this share of the previous kept level's triangles, or it is not shipped. A "LOD" at 98% of
|
|
45
|
+
* the level above draws the same thing for more bytes and a bigger triangle sum under the publish gate (Punko6529: LOD0
|
|
46
|
+
* 24,461, LOD1 24,052, LOD2 23,867 = 72,380 against the 60,000 cap, where live shipped LOD0 alone and passed).
|
|
47
|
+
*/
|
|
48
|
+
export declare const LOD_MAX_SHARE_OF_PREVIOUS = 0.85;
|
|
49
|
+
export declare const levelPaysForItself: (tris: number, previousTris: number) => boolean;
|
|
43
50
|
export interface VrmLodReport {
|
|
44
51
|
level: number;
|
|
45
52
|
tris: number;
|
|
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.lodReportFor = void 0;
|
|
36
|
+
exports.lodReportFor = exports.levelPaysForItself = exports.LOD_MAX_SHARE_OF_PREVIOUS = void 0;
|
|
37
37
|
exports.vrmLodLadder = vrmLodLadder;
|
|
38
38
|
exports.assertMorphTargetsConsistent = assertMorphTargetsConsistent;
|
|
39
39
|
exports.reduceToTarget = reduceToTarget;
|
|
@@ -62,6 +62,14 @@ function vrmLodLadder(lod0Tris) {
|
|
|
62
62
|
{ tris: Math.max(450, Math.round(lod0Tris * 0.13)), keepMorphs: false, faceKeep: 0, error: 0.08, maxErrorMetres: 0.02 },
|
|
63
63
|
];
|
|
64
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* A level must keep at most this share of the previous kept level's triangles, or it is not shipped. A "LOD" at 98% of
|
|
67
|
+
* the level above draws the same thing for more bytes and a bigger triangle sum under the publish gate (Punko6529: LOD0
|
|
68
|
+
* 24,461, LOD1 24,052, LOD2 23,867 = 72,380 against the 60,000 cap, where live shipped LOD0 alone and passed).
|
|
69
|
+
*/
|
|
70
|
+
exports.LOD_MAX_SHARE_OF_PREVIOUS = 0.85;
|
|
71
|
+
const levelPaysForItself = (tris, previousTris) => tris <= previousTris * exports.LOD_MAX_SHARE_OF_PREVIOUS;
|
|
72
|
+
exports.levelPaysForItself = levelPaysForItself;
|
|
65
73
|
const TRIANGLES = 4;
|
|
66
74
|
function trianglePrimitives(document) {
|
|
67
75
|
return document.getRoot().listMeshes().flatMap((mesh) => mesh.listPrimitives().filter((primitive) => primitive.getMode() === TRIANGLES && primitive.getIndices() !== null));
|
|
@@ -260,6 +268,9 @@ const SCENE_ZERO_ONLY = ['helixDynamics', 'helixDynamicsCenters', 'helixConstrai
|
|
|
260
268
|
*/
|
|
261
269
|
async function mergeVrmLodChain(io, lod0, levels) {
|
|
262
270
|
const normalized = await io.readBinary(await webWriterIo(io).writeBinary(lod0));
|
|
271
|
+
// Every level was dropped (none paid for itself): the file is LOD0 alone, a single scene.
|
|
272
|
+
if (levels.length === 0)
|
|
273
|
+
return normalized;
|
|
263
274
|
return (await (0, mergeLods_1.mergeLods)([normalized, ...levels])).document;
|
|
264
275
|
}
|
|
265
276
|
/**
|
|
@@ -270,9 +281,14 @@ async function buildVrmLodDocuments(io, lod0, ladder) {
|
|
|
270
281
|
const bytes = await io.writeBinary(lod0);
|
|
271
282
|
const documents = [];
|
|
272
283
|
const reports = [reportFor(lod0, 0, 0)];
|
|
284
|
+
let previousTris = reports[0].tris;
|
|
273
285
|
for (const [index, level] of ladder.entries()) {
|
|
274
286
|
const document = await io.readBinary(bytes);
|
|
275
287
|
const errorUsed = await reduceToTarget(document, level);
|
|
288
|
+
const report = reportFor(document, documents.length + 1, errorUsed);
|
|
289
|
+
// A level that barely reduces is not shipped; the next one is judged against the last level that was.
|
|
290
|
+
if (!(0, exports.levelPaysForItself)(report.tris, previousTris))
|
|
291
|
+
continue;
|
|
276
292
|
assertMorphTargetsConsistent(document, `lod${index + 1}`);
|
|
277
293
|
for (const scene of document.getRoot().listScenes()) {
|
|
278
294
|
const extras = { ...scene.getExtras() };
|
|
@@ -281,7 +297,8 @@ async function buildVrmLodDocuments(io, lod0, ladder) {
|
|
|
281
297
|
scene.setExtras(extras);
|
|
282
298
|
}
|
|
283
299
|
documents.push(document);
|
|
284
|
-
reports.push(
|
|
300
|
+
reports.push(report);
|
|
301
|
+
previousTris = report.tris;
|
|
285
302
|
}
|
|
286
303
|
return { documents, reports };
|
|
287
304
|
}
|