@threenative/metahuman 0.1.0
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/LICENSE +21 -0
- package/README.md +92 -0
- package/dist/asset-contract-bodYITUR.d.ts +314 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.js +1466 -0
- package/dist/native/index.d.ts +90 -0
- package/dist/native/index.js +879 -0
- package/package.json +67 -0
- package/wasm/checksums.json +8 -0
- package/wasm/riglogic.d.mts +3 -0
- package/wasm/riglogic.mjs +2 -0
- package/wasm/riglogic.wasm +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 João Paulo Furtado
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# @threenative/metahuman
|
|
2
|
+
|
|
3
|
+
MetaHuman head expressions for ThreeNative games: a checksum-verified OpenRigLogic evaluator
|
|
4
|
+
over a browser WASM build and a native C++ one, the binding-metadata contract that keeps a
|
|
5
|
+
prepared GLB honest about the rig it claims to drive, and the Three.js handle that drives it.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { RigEvaluator, loadMetaHuman, validateMetaHumanAssets } from "@threenative/metahuman";
|
|
9
|
+
|
|
10
|
+
const evaluator = await RigEvaluator.create(dnaBytes);
|
|
11
|
+
evaluator.setLod(0);
|
|
12
|
+
evaluator.setGuiControls(new Float32Array(evaluator.counts().gui));
|
|
13
|
+
evaluator.evaluate(true);
|
|
14
|
+
const joints = evaluator.jointOutputs(); // deltas from neutral, 10 floats per joint
|
|
15
|
+
evaluator.dispose();
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
A prepared head, through the game's own asset loader:
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { loadMetaHuman } from "@threenative/metahuman";
|
|
22
|
+
|
|
23
|
+
const human = await loadMetaHuman({
|
|
24
|
+
assets: ctx.assets,
|
|
25
|
+
model: "metahuman/specimen.glb", // the prepared GLB
|
|
26
|
+
dna: "metahuman/head.dna", // its original head DNA
|
|
27
|
+
bindings: "metahuman/bindings.json", // the sidecar the preparation step wrote
|
|
28
|
+
lod: 0, // source LOD, the default
|
|
29
|
+
});
|
|
30
|
+
ctx.scene.add(human.root);
|
|
31
|
+
|
|
32
|
+
human.setControls({ jawOpen: 0.4, eyeBlinkLeft: 1 }); // the aliases this specimen declares
|
|
33
|
+
|
|
34
|
+
// In the scene update, after any base/body animation, before the renderer draws:
|
|
35
|
+
human.update();
|
|
36
|
+
|
|
37
|
+
// On teardown:
|
|
38
|
+
human.dispose();
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
`human.controls` is the declared control list (alias, GUI channel, domain, default),
|
|
42
|
+
`human.setLod(n)` switches the mesh set and the rig together, `human.animatedMaps()` reads the
|
|
43
|
+
last evaluation's animated-map weights, and `human.diagnostics()` reports the backend, the pinned
|
|
44
|
+
OpenRigLogic revision and the live LOD. An undeclared control, a value outside its domain, an
|
|
45
|
+
undeclared LOD and any call after `dispose()` throw a `MetaHumanAssetError` with a stable `code`.
|
|
46
|
+
The model is loaded through `ctx.assets` and cloned per instance, so two characters never write
|
|
47
|
+
each other's face and `dispose()` frees the rig without touching the loader's geometry or textures.
|
|
48
|
+
|
|
49
|
+
## What it does
|
|
50
|
+
|
|
51
|
+
- `loadMetaHuman` binds one prepared specimen: it validates the sidecar against the rig and the
|
|
52
|
+
loaded model, then drives the face from the aliases the sidecar declares. Every table it needs
|
|
53
|
+
is built once, so `update()` is a straight-line pass over pre-resolved joint and morph slots.
|
|
54
|
+
A LOD switch re-evaluates the current controls before the replacement mesh is shown, so it never
|
|
55
|
+
shows a neutral frame.
|
|
56
|
+
- `RigEvaluator` loads `wasm/riglogic.mjs`, verifies the binary's SHA-256 against
|
|
57
|
+
`wasm/checksums.json` before instantiating it, and returns copies of every output array.
|
|
58
|
+
A stale or disposed evaluator throws instead of reading freed memory.
|
|
59
|
+
- `validateMetaHumanAssets(bindings, dna, glb, rig, gltf)` rejects a bindings sidecar whose
|
|
60
|
+
hashes, joint names, node names, blend-shape channels, morph indices, LOD indices, control
|
|
61
|
+
domains or aliases do not hold up. Failures carry a stable `code` on `MetaHumanAssetError`.
|
|
62
|
+
The GLB's own `glbSha256` is optional: it is a preparation-time contract, and a loaded model is
|
|
63
|
+
not re-downloaded to be hashed.
|
|
64
|
+
- `assertAssetPath` keeps a caller-supplied path inside the asset directory.
|
|
65
|
+
|
|
66
|
+
## Building the WASM
|
|
67
|
+
|
|
68
|
+
The binary is committed. Rebuild it only with the Emscripten toolchain:
|
|
69
|
+
|
|
70
|
+
```sh
|
|
71
|
+
source ~/.cache/emsdk/emsdk_env.sh
|
|
72
|
+
node packages/metahuman/scripts/build-wasm.mjs
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
`wasm/checksums.json` records the pinned OpenRigLogic commit, the `emcc` version and both
|
|
76
|
+
file hashes, so a rebuilt binary is never silently swapped in.
|
|
77
|
+
|
|
78
|
+
## Tests
|
|
79
|
+
|
|
80
|
+
`pnpm exec vitest run packages/metahuman` compares the WASM evaluator against the standalone
|
|
81
|
+
upstream evaluator on the committed synthetic DNA, drives the binding and its LOD switch against
|
|
82
|
+
that rig, and proves two instances stay isolated over ten create/dispose cycles. Set
|
|
83
|
+
`TN_METAHUMAN_SAMPLE_DIR` to add the local `Sample.dna` lane; without it that lane is reported as
|
|
84
|
+
skipped, never as passed.
|
|
85
|
+
|
|
86
|
+
`TN_METAHUMAN_SPECIMEN_DIR` adds the licensed-specimen lane: every neutral joint the DNA carries
|
|
87
|
+
is converted and compared with the exported GLB's own rest transform, to 0.1 mm and 0.1°. Without
|
|
88
|
+
it that lane is skipped, never passed.
|
|
89
|
+
|
|
90
|
+
`node packages/runtime-native/scripts/verify-desktop-metahuman.mjs` builds and runs the same
|
|
91
|
+
reference vectors through the native C++ backend; add `--sanitize` for the same contract under
|
|
92
|
+
AddressSanitizer and UBSan in a build directory of its own.
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import { Object3D } from 'three';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* One error class, one code union, for both halves of the contract.
|
|
5
|
+
*
|
|
6
|
+
* The asset validator and the WASM evaluator fail the same way: a stable machine-readable
|
|
7
|
+
* `code` a caller can branch on, plus a human sentence. Codes are part of the public
|
|
8
|
+
* surface; renaming one is a breaking change.
|
|
9
|
+
*/
|
|
10
|
+
type MetaHumanErrorCode = "TN_MH_SCHEMA" | "TN_MH_HASH_MISMATCH" | "TN_MH_NON_FINITE" | "TN_MH_UNKNOWN_JOINT" | "TN_MH_UNKNOWN_NODE" | "TN_MH_UNKNOWN_CHANNEL" | "TN_MH_UNKNOWN_MAP" | "TN_MH_INDEX_RANGE" | "TN_MH_BAD_LOD" | "TN_MH_UNKNOWN_CONTROL" | "TN_MH_BAD_DOMAIN" | "TN_MH_DUPLICATE_ALIAS" | "TN_MH_PATH_ESCAPE" | "TN_MH_LENGTH" | "TN_MH_DISPOSED" | "TN_MH_ABI" | "TN_MH_WASM_LOAD" | "TN_MH_WASM_CHECKSUM";
|
|
11
|
+
/** Every rejection raised by this package carries one of these codes. */
|
|
12
|
+
declare class MetaHumanAssetError extends Error {
|
|
13
|
+
readonly code: MetaHumanErrorCode;
|
|
14
|
+
constructor(code: MetaHumanErrorCode, message: string);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Selectors the ABI exposes. The values are the wire kinds in `cpp/tn_riglogic.h`. */
|
|
18
|
+
type RigEvaluatorKind = "gui" | "raw" | "joint" | "blendShape" | "animatedMap" | "lod";
|
|
19
|
+
interface IRigEvaluatorCounts {
|
|
20
|
+
readonly gui: number;
|
|
21
|
+
readonly raw: number;
|
|
22
|
+
readonly joints: number;
|
|
23
|
+
readonly blendShapes: number;
|
|
24
|
+
readonly animatedMaps: number;
|
|
25
|
+
readonly lodCount: number;
|
|
26
|
+
}
|
|
27
|
+
interface IRigEvaluator {
|
|
28
|
+
/** Item counts, or a rejection if this evaluator is disposed. */
|
|
29
|
+
counts(): IRigEvaluatorCounts;
|
|
30
|
+
names(kind: RigEvaluatorKind): readonly string[];
|
|
31
|
+
setLod(lod: number): void;
|
|
32
|
+
setGuiControls(values: Float32Array): void;
|
|
33
|
+
setRawControls(values: Float32Array): void;
|
|
34
|
+
/**
|
|
35
|
+
* Calculate. With `useGui` the rig runs its own GUI-to-raw mapping first, so a caller
|
|
36
|
+
* that set GUI controls does not re-derive Epic's mapping; without it the raw buffer is
|
|
37
|
+
* used exactly as set.
|
|
38
|
+
*/
|
|
39
|
+
evaluate(useGui: boolean): void;
|
|
40
|
+
/** Joint deltas from neutral, `JOINT_STRIDE` floats per joint. A copy, never a view. */
|
|
41
|
+
jointOutputs(): Float32Array;
|
|
42
|
+
blendShapeOutputs(): Float32Array;
|
|
43
|
+
animatedMapOutputs(): Float32Array;
|
|
44
|
+
/** Neutral joint values in the same `JOINT_STRIDE` layout, for every LOD. */
|
|
45
|
+
neutralJoints(): Float32Array;
|
|
46
|
+
/** Idempotent. Every other call throws once this ran. */
|
|
47
|
+
dispose(): void;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* One rig instance, over the checksum-verified browser WASM build of the shared ABI.
|
|
51
|
+
*
|
|
52
|
+
* Every crossing is checked in TypeScript first (length, finiteness) because the ABI only
|
|
53
|
+
* discovers a bad buffer after it has already read it, and every returned array is a copy:
|
|
54
|
+
* a `HEAPF32` view dies with the next memory growth.
|
|
55
|
+
*/
|
|
56
|
+
declare class RigEvaluator implements IRigEvaluator {
|
|
57
|
+
#private;
|
|
58
|
+
private constructor();
|
|
59
|
+
/**
|
|
60
|
+
* Parse a DNA blob. The bytes are copied by the ABI, so the caller keeps its buffer.
|
|
61
|
+
*
|
|
62
|
+
* A native host that installed the MetaHuman resident gets the C++ evaluator and the WASM is
|
|
63
|
+
* never fetched; everywhere else the checksum-verified WASM build is loaded on first use.
|
|
64
|
+
*/
|
|
65
|
+
static create(dnaBytes: Uint8Array): Promise<IRigEvaluator>;
|
|
66
|
+
/** `"native"` when the host installed the C++ resident, otherwise `"wasm"`. */
|
|
67
|
+
static backend(): "native" | "wasm";
|
|
68
|
+
/**
|
|
69
|
+
* The pinned OpenRigLogic revision the selected backend was built from: the native host's own
|
|
70
|
+
* version string, or the commit the shipped WASM manifest records.
|
|
71
|
+
*/
|
|
72
|
+
static upstreamCommit(): Promise<string>;
|
|
73
|
+
/**
|
|
74
|
+
* Live evaluator handles in this process, across every instance of this class.
|
|
75
|
+
*
|
|
76
|
+
* The count a create/dispose cycle must return to. It reads the ABI's own registry, so a leak
|
|
77
|
+
* shows up as a number rather than as a slow death.
|
|
78
|
+
*/
|
|
79
|
+
static liveHandleCount(): number;
|
|
80
|
+
counts(): IRigEvaluatorCounts;
|
|
81
|
+
names(kind: RigEvaluatorKind): readonly string[];
|
|
82
|
+
setLod(lod: number): void;
|
|
83
|
+
setGuiControls(values: Float32Array): void;
|
|
84
|
+
setRawControls(values: Float32Array): void;
|
|
85
|
+
evaluate(useGui: boolean): void;
|
|
86
|
+
jointOutputs(): Float32Array;
|
|
87
|
+
blendShapeOutputs(): Float32Array;
|
|
88
|
+
animatedMapOutputs(): Float32Array;
|
|
89
|
+
neutralJoints(): Float32Array;
|
|
90
|
+
dispose(): void;
|
|
91
|
+
}
|
|
92
|
+
/** Every rejection the evaluator raises, for callers that narrow on `code`. */
|
|
93
|
+
type RigEvaluatorErrorCode = Extract<MetaHumanErrorCode, `TN_MH_${"WASM_LOAD" | "WASM_CHECKSUM" | "ABI" | "LENGTH" | "NON_FINITE" | "INDEX_RANGE" | "DISPOSED"}`>;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* The slice of `ctx.assets` this package uses, declared here rather than imported from core.
|
|
97
|
+
*
|
|
98
|
+
* Structural, so `ctx.assets` satisfies it without this package depending on core, and so a test
|
|
99
|
+
* can pass a fake with the same two shapes. The model goes through the loader's own cache, the
|
|
100
|
+
* way every other asset does; nothing here keeps a competing copy of a model.
|
|
101
|
+
*/
|
|
102
|
+
interface IMetaHumanAssets {
|
|
103
|
+
model<T = unknown>(path: string): Promise<T>;
|
|
104
|
+
/** Where a logical path is served from, in the order worth trying. */
|
|
105
|
+
resolve(path: string): Promise<readonly string[]>;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* What a glTF loader hands back: the scene, the JSON it was parsed from, and the association
|
|
109
|
+
* table that says which glTF mesh and primitive each scene object came from.
|
|
110
|
+
*
|
|
111
|
+
* The associations are the only authority for that mapping. A glTF mesh node is routinely
|
|
112
|
+
* unnamed — MetaHuman's own export puts its mesh on an unnamed node — so matching scene objects
|
|
113
|
+
* by name would silently bind to nothing.
|
|
114
|
+
*/
|
|
115
|
+
interface IMetaHumanModel {
|
|
116
|
+
readonly scene: Object3D;
|
|
117
|
+
readonly parser?: {
|
|
118
|
+
readonly json?: unknown;
|
|
119
|
+
readonly associations?: ReadonlyMap<unknown, {
|
|
120
|
+
meshes?: number;
|
|
121
|
+
primitives?: number;
|
|
122
|
+
}>;
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/** Which evaluator a handle crosses to, and what it was built from. */
|
|
126
|
+
interface IMetaHumanBackend {
|
|
127
|
+
/** `"wasm"` or `"native"`, reported verbatim by `diagnostics()`. */
|
|
128
|
+
readonly name: string;
|
|
129
|
+
create(dna: Uint8Array): Promise<IRigEvaluator> | IRigEvaluator;
|
|
130
|
+
/** The pinned OpenRigLogic revision this backend was built from. */
|
|
131
|
+
openRigLogic(): Promise<string> | string;
|
|
132
|
+
}
|
|
133
|
+
/** One declared control, as the specimen's sidecar pinned it. */
|
|
134
|
+
interface IMetaHumanControl {
|
|
135
|
+
readonly alias: string;
|
|
136
|
+
readonly gui: string;
|
|
137
|
+
readonly min: number;
|
|
138
|
+
readonly max: number;
|
|
139
|
+
readonly default: number;
|
|
140
|
+
}
|
|
141
|
+
/** What the handle actually is, for a diagnostics panel or a bug report. */
|
|
142
|
+
interface IMetaHumanDiagnostics {
|
|
143
|
+
readonly backend: string;
|
|
144
|
+
readonly openRigLogic: string;
|
|
145
|
+
readonly lod: number;
|
|
146
|
+
readonly joints: number;
|
|
147
|
+
readonly blendShapes: number;
|
|
148
|
+
readonly animatedMaps: number;
|
|
149
|
+
readonly controls: number;
|
|
150
|
+
}
|
|
151
|
+
interface ILoadMetaHumanOptions {
|
|
152
|
+
readonly assets: IMetaHumanAssets;
|
|
153
|
+
/** Logical path of the prepared GLB, through the asset loader. */
|
|
154
|
+
readonly model: string;
|
|
155
|
+
/** Logical path of the specimen's original head DNA. */
|
|
156
|
+
readonly dna: string;
|
|
157
|
+
/** Logical path of the binding metadata sidecar. */
|
|
158
|
+
readonly bindings: string;
|
|
159
|
+
/** Source LOD to start on. Defaults to LOD0, the authored source level. */
|
|
160
|
+
readonly lod?: number;
|
|
161
|
+
}
|
|
162
|
+
interface IMetaHuman {
|
|
163
|
+
/** Add this to a scene. It is a plain `Object3D`; its child is the model's own graph. */
|
|
164
|
+
readonly root: Object3D;
|
|
165
|
+
/** The declared controls, in the sidecar's order. Read-only. */
|
|
166
|
+
readonly controls: readonly IMetaHumanControl[];
|
|
167
|
+
/** Names of the rig's animated maps, index-aligned with `animatedMaps()`. */
|
|
168
|
+
animatedMapNames(): readonly string[];
|
|
169
|
+
/**
|
|
170
|
+
* The last evaluation's animated-map weights, a copy in the rig's own order.
|
|
171
|
+
*
|
|
172
|
+
* A getter rather than a push, because a game binds these to its own material inputs and owns
|
|
173
|
+
* that binding: the handle drives joints and morphs and never writes a material.
|
|
174
|
+
*/
|
|
175
|
+
animatedMaps(): Float32Array;
|
|
176
|
+
/**
|
|
177
|
+
* Set controls by declared alias. Applied on the next `update()`.
|
|
178
|
+
*
|
|
179
|
+
* An alias the specimen does not declare throws `TN_MH_UNKNOWN_CONTROL`; a value outside the
|
|
180
|
+
* declared domain throws `TN_MH_BAD_DOMAIN`, a non-finite one `TN_MH_NON_FINITE`. Nothing is
|
|
181
|
+
* clamped or coerced — a control reporting 1.5 for a 0..1 domain is a bug in the game, and a
|
|
182
|
+
* silently clamped face is a worse bug report than a throw.
|
|
183
|
+
*/
|
|
184
|
+
setControls(values: Readonly<Record<string, number>>): void;
|
|
185
|
+
/** Every control back to the default its bindings declared. Applied on the next `update()`. */
|
|
186
|
+
reset(): void;
|
|
187
|
+
/**
|
|
188
|
+
* Switch LOD, atomically with the rig.
|
|
189
|
+
*
|
|
190
|
+
* The evaluator's LOD, the visible mesh set, the active mappings and the current expression
|
|
191
|
+
* change together, and the replacement is evaluated *before* it is shown, so a switch never
|
|
192
|
+
* shows a neutral frame. A LOD the specimen does not declare throws `TN_MH_BAD_LOD`.
|
|
193
|
+
*/
|
|
194
|
+
setLod(lod: number): void;
|
|
195
|
+
/**
|
|
196
|
+
* Feed the effective GUI vector through the rig and apply its output to the scene.
|
|
197
|
+
*
|
|
198
|
+
* Call it once per frame, after any base/body animation and before the renderer draws: the
|
|
199
|
+
* rig writes the face joints, its output is applied, and the skeleton updates as it always
|
|
200
|
+
* does. There is deliberately no `dt` — facial evaluation has no time step, and a body
|
|
201
|
+
* mixer's update position belongs to the caller.
|
|
202
|
+
*/
|
|
203
|
+
update(): void;
|
|
204
|
+
diagnostics(): IMetaHumanDiagnostics;
|
|
205
|
+
/** Idempotent. Every other method throws `TN_MH_DISPOSED` afterwards. */
|
|
206
|
+
dispose(): void;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** The only schema version this build understands. */
|
|
210
|
+
declare const METAHUMAN_BINDINGS_SCHEMA_VERSION = 1;
|
|
211
|
+
/** What the rig actually contains, read from the DNA through the evaluator. */
|
|
212
|
+
interface IMetaHumanRigFacts {
|
|
213
|
+
readonly gui: readonly string[];
|
|
214
|
+
readonly raw: readonly string[];
|
|
215
|
+
readonly joints: readonly string[];
|
|
216
|
+
readonly blendShapes: readonly string[];
|
|
217
|
+
readonly animatedMaps: readonly string[];
|
|
218
|
+
readonly lodCount: number;
|
|
219
|
+
}
|
|
220
|
+
/** The parts of the exported GLB the bindings are allowed to point at. */
|
|
221
|
+
interface IMetaHumanGltfNode {
|
|
222
|
+
readonly name?: string;
|
|
223
|
+
}
|
|
224
|
+
interface IMetaHumanGltfPrimitive {
|
|
225
|
+
readonly targets?: readonly unknown[];
|
|
226
|
+
readonly extras?: {
|
|
227
|
+
readonly targetNames?: readonly string[];
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
interface IMetaHumanGltfMesh {
|
|
231
|
+
readonly name?: string;
|
|
232
|
+
readonly primitives: readonly IMetaHumanGltfPrimitive[];
|
|
233
|
+
}
|
|
234
|
+
interface IMetaHumanGltfFacts {
|
|
235
|
+
readonly nodes: readonly IMetaHumanGltfNode[];
|
|
236
|
+
readonly meshes: readonly IMetaHumanGltfMesh[];
|
|
237
|
+
}
|
|
238
|
+
interface IMetaHumanAssetInput {
|
|
239
|
+
/** The parsed bindings sidecar. `unknown` because it is untrusted JSON. */
|
|
240
|
+
readonly bindings: unknown;
|
|
241
|
+
readonly dnaSha256: string;
|
|
242
|
+
/**
|
|
243
|
+
* SHA-256 of the prepared GLB, when the caller has its bytes.
|
|
244
|
+
*
|
|
245
|
+
* Optional because a loaded model is not re-downloaded to be hashed: the asset pipeline
|
|
246
|
+
* already serves a content-addressed file, so the preparation step is where that hash belongs.
|
|
247
|
+
* Omitted, every other check below still runs — this weakens the tamper check, not the
|
|
248
|
+
* name, index, domain or bounds checks.
|
|
249
|
+
*/
|
|
250
|
+
readonly glbSha256?: string;
|
|
251
|
+
readonly rig: IMetaHumanRigFacts;
|
|
252
|
+
readonly gltf: IMetaHumanGltfFacts;
|
|
253
|
+
}
|
|
254
|
+
interface IMetaHumanJointBinding {
|
|
255
|
+
readonly dna: string;
|
|
256
|
+
readonly node: string;
|
|
257
|
+
}
|
|
258
|
+
interface IMetaHumanMorphBinding {
|
|
259
|
+
readonly channel: string;
|
|
260
|
+
readonly mesh: number;
|
|
261
|
+
readonly primitive: number;
|
|
262
|
+
readonly target: number;
|
|
263
|
+
}
|
|
264
|
+
interface IMetaHumanLodBinding {
|
|
265
|
+
readonly lod: number;
|
|
266
|
+
readonly meshes: readonly number[];
|
|
267
|
+
}
|
|
268
|
+
interface IMetaHumanControlBinding {
|
|
269
|
+
readonly alias: string;
|
|
270
|
+
readonly gui: string;
|
|
271
|
+
readonly min: number;
|
|
272
|
+
readonly max: number;
|
|
273
|
+
readonly default: number;
|
|
274
|
+
}
|
|
275
|
+
interface IMetaHumanAnimatedMapBinding {
|
|
276
|
+
readonly map: string;
|
|
277
|
+
}
|
|
278
|
+
/** A bindings sidecar that passed every check. Its names exist and its indices are in range. */
|
|
279
|
+
interface IMetaHumanBindings {
|
|
280
|
+
readonly schemaVersion: typeof METAHUMAN_BINDINGS_SCHEMA_VERSION;
|
|
281
|
+
readonly specimen: {
|
|
282
|
+
readonly id: string;
|
|
283
|
+
readonly source: string;
|
|
284
|
+
readonly license: string;
|
|
285
|
+
};
|
|
286
|
+
readonly hashes: {
|
|
287
|
+
readonly dna: string;
|
|
288
|
+
readonly glb: string;
|
|
289
|
+
};
|
|
290
|
+
readonly coordinates: {
|
|
291
|
+
readonly sourceUnits: "cm" | "m";
|
|
292
|
+
readonly sourceUp: "y" | "z";
|
|
293
|
+
readonly handedness: "left" | "right";
|
|
294
|
+
};
|
|
295
|
+
readonly joints: readonly IMetaHumanJointBinding[];
|
|
296
|
+
readonly morphs: readonly IMetaHumanMorphBinding[];
|
|
297
|
+
readonly lods: readonly IMetaHumanLodBinding[];
|
|
298
|
+
readonly controls: readonly IMetaHumanControlBinding[];
|
|
299
|
+
readonly animatedMaps?: readonly IMetaHumanAnimatedMapBinding[];
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Reject anything that could leave the asset directory: absolute paths, Windows drive
|
|
303
|
+
* letters, backslash separators and any `..` segment. Called on every path a game hands
|
|
304
|
+
* the loader, before the path is joined onto a root.
|
|
305
|
+
*/
|
|
306
|
+
declare function assertAssetPath(path: string): string;
|
|
307
|
+
/**
|
|
308
|
+
* Check one prepared specimen — bindings sidecar, DNA, GLB — against the rig it claims to
|
|
309
|
+
* drive. Fails closed: a missing key, a wrong type, a hash that does not match the bytes on
|
|
310
|
+
* disk and an index past the end of its array are all rejections, never warnings.
|
|
311
|
+
*/
|
|
312
|
+
declare function validateMetaHumanAssets(input: IMetaHumanAssetInput): IMetaHumanBindings;
|
|
313
|
+
|
|
314
|
+
export { type ILoadMetaHumanOptions as I, METAHUMAN_BINDINGS_SCHEMA_VERSION as M, RigEvaluator as R, type IMetaHuman as a, type IMetaHumanAnimatedMapBinding as b, type IMetaHumanAssetInput as c, type IMetaHumanAssets as d, type IMetaHumanBackend as e, type IMetaHumanBindings as f, type IMetaHumanControl as g, type IMetaHumanControlBinding as h, type IMetaHumanDiagnostics as i, type IMetaHumanGltfFacts as j, type IMetaHumanGltfMesh as k, type IMetaHumanGltfNode as l, type IMetaHumanGltfPrimitive as m, type IMetaHumanJointBinding as n, type IMetaHumanLodBinding as o, type IMetaHumanModel as p, type IMetaHumanMorphBinding as q, type IMetaHumanRigFacts as r, type IRigEvaluator as s, type IRigEvaluatorCounts as t, MetaHumanAssetError as u, type MetaHumanErrorCode as v, type RigEvaluatorErrorCode as w, type RigEvaluatorKind as x, assertAssetPath as y, validateMetaHumanAssets as z };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { I as ILoadMetaHumanOptions, a as IMetaHuman } from './asset-contract-bodYITUR.js';
|
|
2
|
+
export { b as IMetaHumanAnimatedMapBinding, c as IMetaHumanAssetInput, d as IMetaHumanAssets, e as IMetaHumanBackend, f as IMetaHumanBindings, g as IMetaHumanControl, h as IMetaHumanControlBinding, i as IMetaHumanDiagnostics, j as IMetaHumanGltfFacts, k as IMetaHumanGltfMesh, l as IMetaHumanGltfNode, m as IMetaHumanGltfPrimitive, n as IMetaHumanJointBinding, o as IMetaHumanLodBinding, p as IMetaHumanModel, q as IMetaHumanMorphBinding, r as IMetaHumanRigFacts, s as IRigEvaluator, t as IRigEvaluatorCounts, M as METAHUMAN_BINDINGS_SCHEMA_VERSION, u as MetaHumanAssetError, v as MetaHumanErrorCode, R as RigEvaluator, w as RigEvaluatorErrorCode, x as RigEvaluatorKind, y as assertAssetPath, z as validateMetaHumanAssets } from './asset-contract-bodYITUR.js';
|
|
3
|
+
import 'three';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The shared ABI's transform layout, in one place.
|
|
7
|
+
*
|
|
8
|
+
* The joint stride is a contract, not an implementation detail of either backend: ten floats per
|
|
9
|
+
* joint, `[tx, ty, tz, qx, qy, qz, qw, sx, sy, sz]`, whatever built them. Keeping the number
|
|
10
|
+
* here is what lets `metahuman.ts` read joint output without importing an evaluator — and
|
|
11
|
+
* therefore without dragging a WASM binary into a native bundle that must not carry one.
|
|
12
|
+
*/
|
|
13
|
+
declare const JOINT_STRIDE = 10;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Load a prepared MetaHuman head and drive its expression from the browser's WASM evaluator:
|
|
17
|
+
* declared faceboard controls in, joint deltas and morph weights out, applied to an ordinary
|
|
18
|
+
* Three.js object graph.
|
|
19
|
+
* @situation put a MetaHuman head in a browser game without an Unreal import or a baked clip
|
|
20
|
+
* @constraint the model is loaded through the game's own asset loader and cloned per instance, so
|
|
21
|
+
* two characters never write each other's face and nothing is disposed that `ctx.assets` still owns
|
|
22
|
+
* @constraint the rig's own GUI-to-raw mapping runs; the adapter never re-derives it, and a LOD
|
|
23
|
+
* switch re-evaluates the current controls before the replacement mesh is shown
|
|
24
|
+
* @constraint an undeclared control, an out-of-domain value, an undeclared LOD and any call after
|
|
25
|
+
* `dispose()` throw, each with a stable `code`; nothing is clamped or coerced
|
|
26
|
+
* @constraint in a native host that installed the MetaHuman resident the C++ evaluator runs and
|
|
27
|
+
* `diagnostics().backend` reads "native"; the game code does not change
|
|
28
|
+
* @requires npm i @threenative/metahuman
|
|
29
|
+
* @example const human = await loadMetaHuman({ assets: ctx.assets, model: "metahuman/head.glb",
|
|
30
|
+
* dna: "metahuman/head.dna", bindings: "metahuman/bindings.json" });
|
|
31
|
+
* human.setControls({ jawOpen: 0.4 });
|
|
32
|
+
* @example // in the scene update, after any body animation
|
|
33
|
+
* human.update();
|
|
34
|
+
*/
|
|
35
|
+
declare const loadMetaHuman: (options: ILoadMetaHumanOptions) => Promise<IMetaHuman>;
|
|
36
|
+
|
|
37
|
+
export { ILoadMetaHumanOptions, IMetaHuman, JOINT_STRIDE, loadMetaHuman };
|