@hypersoniclabs/helix-cli 0.1.27-helix3.663 → 0.1.27-helix3.665
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.d.ts +2 -0
- package/dist/character/stages/armBindFixRig.js +5 -1
- package/dist/character/stages/armBindFixRig.js.map +1 -1
- package/dist/character/stages/constraintRest.d.ts +41 -0
- package/dist/character/stages/constraintRest.js +155 -0
- package/dist/character/stages/constraintRest.js.map +1 -0
- package/dist/character/stages/firstPersonHide.d.ts +8 -0
- package/dist/character/stages/firstPersonHide.js +1 -0
- package/dist/character/stages/firstPersonHide.js.map +1 -1
- package/dist/character/stages/joinDraws.d.ts +44 -0
- package/dist/character/stages/joinDraws.js +377 -0
- package/dist/character/stages/joinDraws.js.map +1 -0
- package/dist/character/vrmCharacter.d.ts +3 -0
- package/dist/character/vrmCharacter.js +7 -0
- package/dist/character/vrmCharacter.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type ConstraintRestReport } from './constraintRest';
|
|
1
2
|
import { type Document } from '@gltf-transform/core';
|
|
2
3
|
import { type BindNormalizeOptions, type BindNormalizeReport } from './armBind';
|
|
3
4
|
import { type ArmReachReport, type StaticWeightsOptions, type StaticWeightsReport } from './hairWeights';
|
|
@@ -42,6 +43,7 @@ export declare function fixRigDocument(document: Document, options?: FixRigOptio
|
|
|
42
43
|
limbBridges: LimbBridgeReport | null;
|
|
43
44
|
bind: BindNormalizeReport | null;
|
|
44
45
|
restPose: RestPoseReport | null;
|
|
46
|
+
constraints: ConstraintRestReport;
|
|
45
47
|
}>;
|
|
46
48
|
export declare function fixRigFile(inputPath: string, outputPath: string, options?: FixRigOptions): Promise<FixRigReport>;
|
|
47
49
|
/** Human-readable lines for a fix-rig report (also used by the importer log). */
|
|
@@ -5,6 +5,7 @@ exports.fixRigDocument = fixRigDocument;
|
|
|
5
5
|
exports.fixRigFile = fixRigFile;
|
|
6
6
|
exports.describeFixRig = describeFixRig;
|
|
7
7
|
const unshareLodGeometry_1 = require("./unshareLodGeometry");
|
|
8
|
+
const constraintRest_1 = require("./constraintRest");
|
|
8
9
|
const core_1 = require("@gltf-transform/core");
|
|
9
10
|
const avatarExtensions_1 = require("../avatarExtensions");
|
|
10
11
|
const node_fs_1 = require("node:fs");
|
|
@@ -25,6 +26,8 @@ function mergeRestPose(a, b) {
|
|
|
25
26
|
async function fixRigDocument(document, options = {}) {
|
|
26
27
|
// Per-LOD edits below must never touch geometry another scene also draws.
|
|
27
28
|
(0, unshareLodGeometry_1.unshareLodGeometry)(document);
|
|
29
|
+
// Constraint destinations and their recorded rest numbers follow whatever the re-pose below does to their sources.
|
|
30
|
+
const constraintRest = (0, constraintRest_1.captureConstraintRest)(document);
|
|
28
31
|
const reach = options.weights === false ? false : options.weights?.armReach ?? { mode: options.weights?.mode };
|
|
29
32
|
const armReach = reach === false ? null : (0, hairWeights_1.releaseArmReach)(document, reach);
|
|
30
33
|
const restOptions = options.restPose === false ? null : options.restPose ?? {};
|
|
@@ -37,8 +40,9 @@ async function fixRigDocument(document, options = {}) {
|
|
|
37
40
|
const unguardedSides = preview !== null && limbBridges !== null && (lb?.mode ?? 'repair') === 'repair' ? (0, limbBridge_1.bridgeVerdict)(limbBridges, preview.sides) : [];
|
|
38
41
|
const bind = options.bind === false ? null : (0, armBind_1.normalizeBindPose)(document, { ...(options.bind ?? {}), unguardedSides: options.bind?.unguardedSides ?? unguardedSides });
|
|
39
42
|
const weights = options.weights === false ? null : (0, hairWeights_1.cleanStaticWeights)(document, options.weights ?? {});
|
|
43
|
+
const constraints = (0, constraintRest_1.followConstraintRest)(document, constraintRest);
|
|
40
44
|
const restGround = restOptions === null ? null : (0, restPose_1.groundSoles)(document, restOptions);
|
|
41
|
-
return { weights, armReach, limbBridges, bind, restPose: mergeRestPose(restJoints, restGround) };
|
|
45
|
+
return { weights, armReach, limbBridges, bind, restPose: mergeRestPose(restJoints, restGround), constraints };
|
|
42
46
|
}
|
|
43
47
|
async function fixRigFile(inputPath, outputPath, options = {}) {
|
|
44
48
|
await Promise.all([meshoptimizer_1.MeshoptDecoder.ready, meshoptimizer_1.MeshoptEncoder.ready]);
|
|
@@ -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":";;AA8CA,sCAIC;AAED,wCAoBC;AAED,gCAWC;AAGD,wCAsBC;AA9GD,6DAA0D;AAC1D,qDAA0G;AAC1G,+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,QAAQ,CAAC,CAAC;IAC7B,mHAAmH;IACnH,MAAM,cAAc,GAAG,IAAA,sCAAqB,EAAC,QAAQ,CAAC,CAAC;IACvD,MAAM,KAAK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Aa,CAAC,MAAM;gBAAE,KAAK,CAAC,IAAI,CAAC,oBAAoB,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,41 @@
|
|
|
1
|
+
import type { Document, Scene } from '@gltf-transform/core';
|
|
2
|
+
import { type HelixConstraint } from './vrmConstraints';
|
|
3
|
+
/**
|
|
4
|
+
* Keep `helixConstraints` true across the rig-fix's re-pose.
|
|
5
|
+
*
|
|
6
|
+
* The importer records every constraint against the pose the file was authored in: a rotation constraint carries the
|
|
7
|
+
* source and destination WORLD rest orientations (`srcRest`, `dstRest`), a roll constraint a world axis. The rig-fix then
|
|
8
|
+
* re-binds the arms onto the platform A-pose (`normalizeBindPose`) and may move joints (`normalizeRestJoints`): the
|
|
9
|
+
* source joint's world rest turns by some D and the numbers recorded above go stale. Two things then break.
|
|
10
|
+
*
|
|
11
|
+
* - A destination that rides the SAME limb (a roll helper under the forearm) turns with it, but its recorded axis does
|
|
12
|
+
* not, so the twist is taken about a stale direction.
|
|
13
|
+
* - A destination that is NOT under the source (Seed-san's robot arm: `robo_upper_armL` copies `upperarm_l`, and hangs
|
|
14
|
+
* off the back, not the arm) keeps its authored pose. Its skinned geometry still stands out in a T while the
|
|
15
|
+
* body's arm hangs, and, because a rotation constraint applies only the source's CHANGE from rest, it stays that way
|
|
16
|
+
* for every clip.
|
|
17
|
+
*
|
|
18
|
+
* So: capture the world rest of every node a constraint names before the re-pose, and after it (a) turn each rotation
|
|
19
|
+
* destination by the same D as its source, then bake the skins whose bind no longer equals rest (`bakeRestSkin`) so the
|
|
20
|
+
* geometry follows, and (b) rotate `srcRest`, `dstRest` and `axis` by the D of the node they describe, which keeps the
|
|
21
|
+
* runtime's frame algebra (all conjugation by `srcRest⁻¹ · rigRest`) exactly as it was before the re-pose.
|
|
22
|
+
*/
|
|
23
|
+
type Q = [number, number, number, number];
|
|
24
|
+
export interface ConstraintRestSnapshot {
|
|
25
|
+
/** Per scene that carries the block (and every other scene, by name): world rest of each constraint-named node. */
|
|
26
|
+
worlds: Map<Scene, Map<string, Q>>;
|
|
27
|
+
constraints: HelixConstraint[];
|
|
28
|
+
}
|
|
29
|
+
export interface ConstraintRestReport {
|
|
30
|
+
/** Constraints whose recorded rest numbers were rotated by their node's re-pose. */
|
|
31
|
+
updated: number;
|
|
32
|
+
/** Destination nodes turned to follow their source (across every scene that has them). */
|
|
33
|
+
followed: number;
|
|
34
|
+
/** Skins baked so geometry weighted to a followed destination moves with it. */
|
|
35
|
+
skinsBaked: number;
|
|
36
|
+
}
|
|
37
|
+
/** Call before any stage that re-poses joints. `null` when the document carries no constraints. */
|
|
38
|
+
export declare function captureConstraintRest(document: Document): ConstraintRestSnapshot | null;
|
|
39
|
+
/** Call after the re-pose (and before anything that only translates, like the ground lift). */
|
|
40
|
+
export declare function followConstraintRest(document: Document, snapshot: ConstraintRestSnapshot | null): ConstraintRestReport;
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.captureConstraintRest = captureConstraintRest;
|
|
4
|
+
exports.followConstraintRest = followConstraintRest;
|
|
5
|
+
const bakeRestSkin_1 = require("./bakeRestSkin");
|
|
6
|
+
const vrmConstraints_1 = require("./vrmConstraints");
|
|
7
|
+
const qmul = (a, b) => [
|
|
8
|
+
a[3] * b[0] + a[0] * b[3] + a[1] * b[2] - a[2] * b[1],
|
|
9
|
+
a[3] * b[1] - a[0] * b[2] + a[1] * b[3] + a[2] * b[0],
|
|
10
|
+
a[3] * b[2] + a[0] * b[1] - a[1] * b[0] + a[2] * b[3],
|
|
11
|
+
a[3] * b[3] - a[0] * b[0] - a[1] * b[1] - a[2] * b[2],
|
|
12
|
+
];
|
|
13
|
+
const qinv = (a) => [-a[0], -a[1], -a[2], a[3]];
|
|
14
|
+
const qnorm = (a) => {
|
|
15
|
+
const l = Math.hypot(a[0], a[1], a[2], a[3]) || 1;
|
|
16
|
+
return [a[0] / l, a[1] / l, a[2] / l, a[3] / l];
|
|
17
|
+
};
|
|
18
|
+
/** Rotation angle (radians) of a unit quaternion. */
|
|
19
|
+
const qangle = (a) => 2 * Math.acos(Math.min(1, Math.abs(a[3])));
|
|
20
|
+
const rotate = (q, v) => {
|
|
21
|
+
const p = qmul(qmul(q, [v[0], v[1], v[2], 0]), qinv(q));
|
|
22
|
+
return [p[0], p[1], p[2]];
|
|
23
|
+
};
|
|
24
|
+
const worldQuat = (node) => qnorm((0, vrmConstraints_1.quatFromMatrix)(node.getWorldMatrix()));
|
|
25
|
+
/** Below this a re-pose is not a re-pose: leave the file byte for byte alone. */
|
|
26
|
+
const MOVED = 1e-3;
|
|
27
|
+
function constraintBlock(document) {
|
|
28
|
+
for (const scene of document.getRoot().listScenes()) {
|
|
29
|
+
const block = scene.getExtras().helixConstraints;
|
|
30
|
+
if (Array.isArray(block?.constraints) && block.constraints.length > 0)
|
|
31
|
+
return { holder: scene, constraints: block.constraints };
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
function namedIn(scene) {
|
|
36
|
+
const out = new Map();
|
|
37
|
+
const walk = (node) => {
|
|
38
|
+
const name = node.getName();
|
|
39
|
+
if (name !== '' && !out.has(name))
|
|
40
|
+
out.set(name, node);
|
|
41
|
+
for (const child of node.listChildren())
|
|
42
|
+
walk(child);
|
|
43
|
+
};
|
|
44
|
+
for (const child of scene.listChildren())
|
|
45
|
+
walk(child);
|
|
46
|
+
return out;
|
|
47
|
+
}
|
|
48
|
+
/** Call before any stage that re-poses joints. `null` when the document carries no constraints. */
|
|
49
|
+
function captureConstraintRest(document) {
|
|
50
|
+
const block = constraintBlock(document);
|
|
51
|
+
if (block === null)
|
|
52
|
+
return null;
|
|
53
|
+
const names = new Set();
|
|
54
|
+
for (const c of block.constraints) {
|
|
55
|
+
names.add(c.node);
|
|
56
|
+
names.add(c.source);
|
|
57
|
+
}
|
|
58
|
+
const worlds = new Map();
|
|
59
|
+
for (const scene of document.getRoot().listScenes()) {
|
|
60
|
+
const nodes = namedIn(scene);
|
|
61
|
+
const map = new Map();
|
|
62
|
+
for (const name of names) {
|
|
63
|
+
const node = nodes.get(name);
|
|
64
|
+
if (node !== undefined)
|
|
65
|
+
map.set(name, worldQuat(node));
|
|
66
|
+
}
|
|
67
|
+
worlds.set(scene, map);
|
|
68
|
+
}
|
|
69
|
+
return { worlds, constraints: block.constraints.map((c) => ({ ...c })) };
|
|
70
|
+
}
|
|
71
|
+
/** Call after the re-pose (and before anything that only translates, like the ground lift). */
|
|
72
|
+
function followConstraintRest(document, snapshot) {
|
|
73
|
+
const report = { updated: 0, followed: 0, skinsBaked: 0 };
|
|
74
|
+
const block = constraintBlock(document);
|
|
75
|
+
if (snapshot === null || block === null)
|
|
76
|
+
return report;
|
|
77
|
+
// The D of each node a constraint names, taken in the block's own scene (scene 0, the LOD0 rig).
|
|
78
|
+
const holderNodes = namedIn(block.holder);
|
|
79
|
+
const holderOld = snapshot.worlds.get(block.holder) ?? new Map();
|
|
80
|
+
const deltaOf = (name) => {
|
|
81
|
+
const node = holderNodes.get(name), old = holderOld.get(name);
|
|
82
|
+
if (node === undefined || old === undefined)
|
|
83
|
+
return null;
|
|
84
|
+
return qnorm(qmul(worldQuat(node), qinv(old)));
|
|
85
|
+
};
|
|
86
|
+
const srcDelta = new Map();
|
|
87
|
+
for (const c of block.constraints) {
|
|
88
|
+
const d = deltaOf(c.source);
|
|
89
|
+
if (d !== null && qangle(d) > MOVED)
|
|
90
|
+
srcDelta.set(c.source, d);
|
|
91
|
+
}
|
|
92
|
+
if (srcDelta.size === 0)
|
|
93
|
+
return report;
|
|
94
|
+
// 1. Rotation destinations follow their source, in every scene that has both nodes (each LOD rig is its own skeleton).
|
|
95
|
+
// Shallow destinations first, so a child is solved against its parent's new world.
|
|
96
|
+
const depth = (node) => { let n = 0; for (let p = node.getParentNode(); p !== null; p = p.getParentNode())
|
|
97
|
+
n++; return n; };
|
|
98
|
+
for (const scene of document.getRoot().listScenes()) {
|
|
99
|
+
const nodes = namedIn(scene);
|
|
100
|
+
const old = snapshot.worlds.get(scene) ?? new Map();
|
|
101
|
+
const order = block.constraints
|
|
102
|
+
.filter((c) => c.kind === 'rotation' && srcDelta.has(c.source) && nodes.has(c.node) && old.has(c.node))
|
|
103
|
+
.sort((a, b) => depth(nodes.get(a.node)) - depth(nodes.get(b.node)));
|
|
104
|
+
for (const c of order) {
|
|
105
|
+
const dst = nodes.get(c.node), parent = dst.getParentNode();
|
|
106
|
+
const src = nodes.get(c.source), oldSrc = old.get(c.source);
|
|
107
|
+
if (src === undefined || oldSrc === undefined)
|
|
108
|
+
continue;
|
|
109
|
+
// This scene's own D for the source (LOD rigs are re-bound independently but identically).
|
|
110
|
+
const d = qnorm(qmul(worldQuat(src), qinv(oldSrc)));
|
|
111
|
+
const target = qnorm(qmul(d, old.get(c.node)));
|
|
112
|
+
const now = worldQuat(dst);
|
|
113
|
+
if (qangle(qmul(target, qinv(now))) <= MOVED)
|
|
114
|
+
continue;
|
|
115
|
+
const parentWorld = parent === null ? [0, 0, 0, 1] : worldQuat(parent);
|
|
116
|
+
dst.setRotation(qnorm(qmul(qinv(parentWorld), target)));
|
|
117
|
+
report.followed++;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (report.followed > 0)
|
|
121
|
+
report.skinsBaked = (0, bakeRestSkin_1.bakeRestSkin)(document).skins;
|
|
122
|
+
// 2. The recorded numbers follow the nodes they describe. Each is rotated by its own node's D (a destination that
|
|
123
|
+
// just followed its source has the source's D; one that rode its limb already has it).
|
|
124
|
+
block.constraints.forEach((c, i) => {
|
|
125
|
+
const dSrc = deltaOf(c.source);
|
|
126
|
+
if (dSrc === null)
|
|
127
|
+
return;
|
|
128
|
+
const recorded = block.holder.getExtras().helixConstraints;
|
|
129
|
+
const target = recorded.constraints[i];
|
|
130
|
+
let changed = false;
|
|
131
|
+
if (c.kind === 'roll' && target.kind === 'roll' && qangle(dSrc) > MOVED) {
|
|
132
|
+
const a = rotate(dSrc, [c.axis[0], c.axis[1], c.axis[2]]);
|
|
133
|
+
target.axis = [a[0], a[1], a[2]];
|
|
134
|
+
changed = true;
|
|
135
|
+
}
|
|
136
|
+
else if (c.kind === 'rotation' && target.kind === 'rotation') {
|
|
137
|
+
const dDst = deltaOf(c.node);
|
|
138
|
+
if (qangle(dSrc) > MOVED) {
|
|
139
|
+
target.srcRest = qnorm(qmul(dSrc, c.srcRest));
|
|
140
|
+
changed = true;
|
|
141
|
+
}
|
|
142
|
+
if (dDst !== null && qangle(dDst) > MOVED) {
|
|
143
|
+
target.dstRest = qnorm(qmul(dDst, c.dstRest));
|
|
144
|
+
changed = true;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (changed)
|
|
148
|
+
report.updated++;
|
|
149
|
+
});
|
|
150
|
+
// Scenes hold their own extras objects: write the updated block back through setExtras.
|
|
151
|
+
const recorded = block.holder.getExtras().helixConstraints;
|
|
152
|
+
block.holder.setExtras({ ...block.holder.getExtras(), helixConstraints: { ...recorded, constraints: recorded.constraints } });
|
|
153
|
+
return report;
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=constraintRest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constraintRest.js","sourceRoot":"","sources":["../../../src/character/stages/constraintRest.ts"],"names":[],"mappings":";;AAqFA,sDAgBC;AAGD,oDAoEC;AA3KD,iDAA8C;AAC9C,qDAAwE;AAyBxE,MAAM,IAAI,GAAG,CAAC,CAAI,EAAE,CAAI,EAAK,EAAE,CAAC;IA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C,EAAE,GAAG,KAAK,CAAC,MAAM,CAAC,SAAS,EAAE,EAAE,gBAAgB,EAAE,EAAE,GAAG,QAAQ,EAAE,WAAW,EAAE,QAAQ,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IAC9H,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -48,6 +48,14 @@ export interface FirstPersonHideResult {
|
|
|
48
48
|
export type FirstPersonAnnotation = 'thirdPersonOnly' | 'firstPersonOnly' | 'both' | 'auto';
|
|
49
49
|
/** VRM 0.x spells the flag PascalCase (`ThirdPersonOnly`), 1.0 camelCase; anything else is not an annotation. */
|
|
50
50
|
export declare function firstPersonAnnotation(value: unknown): FirstPersonAnnotation | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* Runtime names for a mesh's primitives.
|
|
53
|
+
*
|
|
54
|
+
* `GLTFLoader` splits a multi-primitive mesh into one `Mesh` per primitive, naming the first after the mesh and
|
|
55
|
+
* suffixing the rest `_1`, `_2`… Matching is by substring, so the base name alone would hide every primitive in
|
|
56
|
+
* the mesh — which is wrong for a body mesh that carries the ears as one primitive among many.
|
|
57
|
+
*/
|
|
58
|
+
export declare function runtimeName(meshName: string, primitiveIndex: number): string;
|
|
51
59
|
/**
|
|
52
60
|
* Find every primitive the first-person camera sits inside, and write the list into each scene's extras.
|
|
53
61
|
*
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.primitiveVertices = primitiveVertices;
|
|
4
4
|
exports.firstPersonAnnotation = firstPersonAnnotation;
|
|
5
|
+
exports.runtimeName = runtimeName;
|
|
5
6
|
exports.declareFirstPersonHide = declareFirstPersonHide;
|
|
6
7
|
/**
|
|
7
8
|
* WHICH SURFACES THE CAMERA IS INSIDE, DECLARED BY THE AVATAR.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"firstPersonHide.js","sourceRoot":"","sources":["../../../src/character/stages/firstPersonHide.ts"],"names":[],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AAe,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACpD,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,UAAU,EAAE,EAAE,CAAC;YACtC,MAAM,MAAM,GAAG,KAAK,CAAC,SAAS,EAA6B,CAAC;YAC5D,MAAM,MAAM,GAAI,MAAM,CAAC,WAAmD,IAAI,EAAE,CAAC;YACjF,KAAK,CAAC,SAAS,CAAC;gBACd,GAAG,MAAM;gBACT,WAAW,EAAE;oBACX,GAAG,MAAM;oBACT,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,eAAe,EAAE,MAAM,EAAE,CAAC;oBACrD,GAAG,CAAC,eAAe,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,eAAe,EAAE,CAAC;iBACvD;aACF,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,QAAQ,EAAE,CAAC;AAC/C,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { Document } from '@gltf-transform/core';
|
|
2
|
+
/**
|
|
3
|
+
* DRAW-CALL JOIN FOR AN IMPORTED AVATAR.
|
|
4
|
+
*
|
|
5
|
+
* The publish gate counts one draw per primitive per node, and caps an avatar at `AVATAR_MAX_DRAW_CALLS` (12). A
|
|
6
|
+
* VRoid export is one primitive per surface spread over several skinned meshes, so after the material atlas an avatar
|
|
7
|
+
* with 8 materials still arrives at 13-33 draws. The web import joined them in the backend (`avatar-import.fit.ts`)
|
|
8
|
+
* after this converter had finished; the Creator Tools path (`helix bridge import`) never did, and 101 of the 273 corpus
|
|
9
|
+
* VRMs were refused at publish on draws alone. This is the same pass, run INSIDE the converter and BEFORE the LOD
|
|
10
|
+
* ladder, so LOD0 and every level derived from it are already within budget and both paths ship the same file.
|
|
11
|
+
*
|
|
12
|
+
* Joining primitives that share a material, skin and attribute layout changes no geometry, weight or material. What
|
|
13
|
+
* can go wrong, and what each step below does about it:
|
|
14
|
+
* - Blend shapes. `joinPrimitives` writes no morph targets, so a face joined naively loses every viseme. Morphed
|
|
15
|
+
* meshes are joined here, per mesh, rebuilding each target through the exact vertex order the joiner uses.
|
|
16
|
+
* - The first-/third-person hide lists name primitives (`Hair001baked_12`). The join renames everything it touches, so
|
|
17
|
+
* the lists are re-declared from the surviving primitives, and a view class never merges with another one.
|
|
18
|
+
* - Skins. The joiner groups by skin OBJECT. Morphed meshes and each view class get a clone over the same joints and
|
|
19
|
+
* inverse bind matrices for the duration of the join; identical skins are collapsed back to one afterwards, so the
|
|
20
|
+
* rig the next stages (LODs, preview) and the runtime see is the one that came in.
|
|
21
|
+
*/
|
|
22
|
+
/** The platform's `AVATAR_MAX_DRAW_CALLS`: the wall a published avatar may not cross. */
|
|
23
|
+
export declare const AVATAR_MAX_DRAW_CALLS = 12;
|
|
24
|
+
export interface JoinDrawsReport {
|
|
25
|
+
/** Draw calls (primitives over every mesh-bearing node) before and after. */
|
|
26
|
+
before: number;
|
|
27
|
+
after: number;
|
|
28
|
+
joined: boolean;
|
|
29
|
+
/** Why nothing was joined, when that is not simply "already within budget". */
|
|
30
|
+
skipped?: string;
|
|
31
|
+
/** Surfaces re-declared for the first-/third-person views after the join renamed them. */
|
|
32
|
+
viewHide?: {
|
|
33
|
+
firstPersonHide: number;
|
|
34
|
+
thirdPersonHide: number;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/** What the publish gate counts for a single-scene avatar: primitives over every node that bears a mesh. */
|
|
38
|
+
export declare function countDraws(document: Document): number;
|
|
39
|
+
/**
|
|
40
|
+
* Bring a single-scene avatar within the draw-call budget by joining same-material primitives. A no-op (the document
|
|
41
|
+
* is not touched) when it is already within `limit`. Never throws on a join it cannot do: it leaves those primitives
|
|
42
|
+
* as they were and the publish gate states the real number.
|
|
43
|
+
*/
|
|
44
|
+
export declare function joinDraws(document: Document, limit?: number): JoinDrawsReport;
|