tosijs-3d 0.12.0 → 0.12.1
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/CHANGELOG.md +3 -2
- package/changelog/v0.12.1.md +13 -0
- package/dist/character-core.d.ts.map +1 -1
- package/dist/character-core.js +2 -1
- package/dist/character-core.js.map +1 -1
- package/dist/glb-chunks.d.ts +44 -0
- package/dist/glb-chunks.d.ts.map +1 -0
- package/dist/glb-chunks.js +253 -0
- package/dist/glb-chunks.js.map +1 -0
- package/dist/skinned-glb.d.ts +101 -0
- package/dist/skinned-glb.d.ts.map +1 -0
- package/dist/skinned-glb.js +385 -0
- package/dist/skinned-glb.js.map +1 -0
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -12,13 +12,14 @@ Upgrading across a minor? Start with [Migration](/Migration/).
|
|
|
12
12
|
|
|
13
13
|
## Unreleased
|
|
14
14
|
|
|
15
|
-
## 0.12.
|
|
15
|
+
## 0.12.1
|
|
16
16
|
|
|
17
|
-
The latest release.
|
|
17
|
+
The latest release. A rigged, morphing body written out as a GLB with no engine (`tosijs-3d/skinned-glb`, with `tosijs-3d/glb-chunks`), moved here from Dramatis. See [0.12.1](/v0.12.1/).
|
|
18
18
|
|
|
19
19
|
## Every version
|
|
20
20
|
|
|
21
21
|
<!-- toc -->
|
|
22
|
+
- [0.12.1](/v0.12.1/)
|
|
22
23
|
- [0.12.0](/v0.12.0/)
|
|
23
24
|
- [0.11.6](/v0.11.6/)
|
|
24
25
|
- [0.11.5](/v0.11.5/)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# 0.12.1
|
|
2
|
+
|
|
3
|
+
<!--{ "parent": "CHANGELOG", "order": 9987999 }-->
|
|
4
|
+
|
|
5
|
+
A rigged, morphing body written out as a GLB, with no engine: the skinned GLB writer, moved here from Dramatis so other engines can use it.
|
|
6
|
+
|
|
7
|
+
Size: barrel (min, packages external) 1510.4 KB raw / 523.7 KB gz, unchanged (both modules are subpaths, not in the barrel).
|
|
8
|
+
|
|
9
|
+
## Added
|
|
10
|
+
|
|
11
|
+
- **`tosijs-3d/skinned-glb`**: `writeSkinnedGlb` writes one skeleton, meshes skinned to it (four influences each, renormalised in float32), sparse morph targets named in `extras.targetNames`, and metallic-roughness materials (plus sheen) with embedded images. The result is clean under the Khronos glTF validator and loads in Babylon.
|
|
12
|
+
- **`tosijs-3d/glb-chunks`**: a GLB's chunks read and written, and its accessors read back. New code reads and writes GLB through it.
|
|
13
|
+
- Both are in the engine-free [character core](/character-core/): no Babylon in their import graph, types included.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"character-core.d.ts","sourceRoot":"","sources":["../src/character-core.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"character-core.d.ts","sourceRoot":"","sources":["../src/character-core.ts"],"names":[],"mappings":"AAgDA,OAAO,EAAE,CAAA"}
|
package/dist/character-core.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*#
|
|
2
2
|
# character core
|
|
3
3
|
|
|
4
|
-
**The character creator's working parts, for any engine.** Twenty modules
|
|
4
|
+
**The character creator's working parts, for any engine.** Twenty-two modules
|
|
5
5
|
make a character without Babylon or a DOM: they read MakeHuman's body, shape
|
|
6
6
|
it, fit and bind a skeleton, retarget clips, fit hair and clothes, and save
|
|
7
7
|
the result. Each is its own subpath, so a three.js app (or a server, or a
|
|
@@ -31,6 +31,7 @@ import { humanBodyMaker } from 'tosijs-3d/human-rig'
|
|
|
31
31
|
| [`character-file`](/character-file/) | a character as one versioned JSON document |
|
|
32
32
|
| [`character-settings`](/character-settings/) | every setting a character has, with its default; the slots; hair colours; the body pack's URL |
|
|
33
33
|
| [`proxy-cover`](/proxy-cover/) | the skin under what is worn, tucked in and hidden |
|
|
34
|
+
| [`skinned-glb`](/skinned-glb/), [`glb-chunks`](/glb-chunks/) | a rigged, morphing body out as a GLB (validator-clean); GLB chunks read and written |
|
|
34
35
|
| [`asset-url`](/asset-url/) | where hosted assets (the body pack, the hair) are fetched from |
|
|
35
36
|
|
|
36
37
|
What makes it a promise: `pure-core.test.ts` walks their import graph, type
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"character-core.js","sourceRoot":"","sources":["../src/character-core.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"character-core.js","sourceRoot":"","sources":["../src/character-core.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA6CE;AACF,0CAA0C"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** glTF JSON, as parsed: readers look at the fields they need. */
|
|
2
|
+
export type GltfJson = Record<string, any>;
|
|
3
|
+
/** A GLB split into its JSON and (optional) binary chunk. */
|
|
4
|
+
export interface Glb {
|
|
5
|
+
json: any;
|
|
6
|
+
bin: Uint8Array | null;
|
|
7
|
+
}
|
|
8
|
+
/** 'glTF', little-endian: the first four bytes of every GLB. */
|
|
9
|
+
export declare const GLB_MAGIC = 1179937895;
|
|
10
|
+
/** Split a GLB into its JSON and binary chunk. Throws when it is not one. */
|
|
11
|
+
export declare function readGlb(bytes: Uint8Array): Glb;
|
|
12
|
+
/**
|
|
13
|
+
* A GLB from JSON and a binary chunk, padded as the spec says. A null or
|
|
14
|
+
* empty binary chunk is left out.
|
|
15
|
+
*/
|
|
16
|
+
export declare function writeGlb(json: unknown, bin: Uint8Array | null): Uint8Array;
|
|
17
|
+
/** A buffer view as `BinBuilder` writes it. */
|
|
18
|
+
export interface BinView {
|
|
19
|
+
buffer: 0;
|
|
20
|
+
byteOffset: number;
|
|
21
|
+
byteLength: number;
|
|
22
|
+
target?: number;
|
|
23
|
+
}
|
|
24
|
+
/** Builds a binary chunk: each `add` is a new buffer view, 4-byte aligned. */
|
|
25
|
+
export declare class BinBuilder {
|
|
26
|
+
private parts;
|
|
27
|
+
private length;
|
|
28
|
+
readonly views: BinView[];
|
|
29
|
+
/** Append bytes as a buffer view; returns its index. */
|
|
30
|
+
add(bytes: Uint8Array, target?: number): number;
|
|
31
|
+
/** The chunk so far. */
|
|
32
|
+
bytes(): Uint8Array;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* An accessor's bytes, tightly packed: a strided view de-interleaved, and a
|
|
36
|
+
* sparse accessor's substitutions applied (over zeros when it has no
|
|
37
|
+
* `bufferView`). May share memory with the binary chunk; copy before writing.
|
|
38
|
+
*/
|
|
39
|
+
export declare function accessorBytes(glb: Glb, index: number): Uint8Array;
|
|
40
|
+
/** An accessor's components as numbers, element by element (not normalised). */
|
|
41
|
+
export declare function accessorValues(glb: Glb, index: number): Float64Array;
|
|
42
|
+
/** A float VEC3 accessor as xyz per element, sparse or not. */
|
|
43
|
+
export declare function readVec3(glb: Glb, index: number): Float32Array;
|
|
44
|
+
//# sourceMappingURL=glb-chunks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"glb-chunks.d.ts","sourceRoot":"","sources":["../src/glb-chunks.ts"],"names":[],"mappings":"AA6BA,kEAAkE;AAClE,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;AAE1C,6DAA6D;AAC7D,MAAM,WAAW,GAAG;IAElB,IAAI,EAAE,GAAG,CAAA;IACT,GAAG,EAAE,UAAU,GAAG,IAAI,CAAA;CACvB;AAED,gEAAgE;AAChE,eAAO,MAAM,SAAS,aAAa,CAAA;AAKnC,6EAA6E;AAC7E,wBAAgB,OAAO,CAAC,KAAK,EAAE,UAAU,GAAG,GAAG,CAsC9C;AAUD;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,UAAU,GAAG,IAAI,GAAG,UAAU,CAmB1E;AAED,+CAA+C;AAC/C,MAAM,WAAW,OAAO;IACtB,MAAM,EAAE,CAAC,CAAA;IACT,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,8EAA8E;AAC9E,qBAAa,UAAU;IACrB,OAAO,CAAC,KAAK,CAAmB;IAChC,OAAO,CAAC,MAAM,CAAI;IAClB,QAAQ,CAAC,KAAK,EAAE,OAAO,EAAE,CAAK;IAE9B,wDAAwD;IACxD,GAAG,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM;IAc/C,wBAAwB;IACxB,KAAK,IAAI,UAAU;CASpB;AA6DD;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,GAAG,UAAU,CAwDjE;AAED,gFAAgF;AAChF,wBAAgB,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,GAAG,YAAY,CAiBpE;AAED,+DAA+D;AAC/D,wBAAgB,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,GAAG,YAAY,CAM9D"}
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
/*#
|
|
2
|
+
# glb-chunks
|
|
3
|
+
|
|
4
|
+
**A GLB's two chunks, read and written, and its accessors read back.** The
|
|
5
|
+
GLB container module new readers and writers use (`skinned-glb`, and
|
|
6
|
+
Dramatis's VRM writer, hair reader and gates), so a check reads exports with
|
|
7
|
+
the reader the shipped code uses. Pure: no DOM, no engine, synchronous.
|
|
8
|
+
`tosijs-3d/glb-chunks`.
|
|
9
|
+
|
|
10
|
+
Reading, `readGlb`:
|
|
11
|
+
|
|
12
|
+
- under 12 bytes, a bad magic or a version other than 2 throws "not a GLB";
|
|
13
|
+
- a file shorter than its header's length, or a chunk running past it, throws
|
|
14
|
+
"truncated GLB" (a short read, not a corrupt file);
|
|
15
|
+
- the first JSON chunk wins, and so does the first BIN chunk;
|
|
16
|
+
- the binary chunk is optional (`bin: null`); no JSON chunk throws.
|
|
17
|
+
|
|
18
|
+
Writing, `writeGlb`: the JSON padded with spaces and the binary chunk with
|
|
19
|
+
zeros, to 4 bytes; a null or empty binary chunk is left out, as the spec
|
|
20
|
+
allows a GLB with no buffer.
|
|
21
|
+
|
|
22
|
+
Accessors, `accessorBytes` / `accessorValues` / `readVec3`: tightly packed,
|
|
23
|
+
strided views de-interleaved, sparse accessors applied (one with no
|
|
24
|
+
`bufferView` starts from zeros, as glTF says), every read bounds-checked
|
|
25
|
+
against its buffer view.
|
|
26
|
+
*/
|
|
27
|
+
/*{ "parent": "character-core", "order": 31 }*/
|
|
28
|
+
/** 'glTF', little-endian: the first four bytes of every GLB. */
|
|
29
|
+
export const GLB_MAGIC = 0x46546c67;
|
|
30
|
+
const JSON_CHUNK = 0x4e4f534a; // 'JSON'
|
|
31
|
+
const BIN_CHUNK = 0x004e4942; // 'BIN\0'
|
|
32
|
+
const HEADER = 12;
|
|
33
|
+
/** Split a GLB into its JSON and binary chunk. Throws when it is not one. */
|
|
34
|
+
export function readGlb(bytes) {
|
|
35
|
+
if (bytes.byteLength < HEADER)
|
|
36
|
+
throw new Error(`not a GLB: ${bytes.byteLength} bytes, under the ${HEADER}-byte header`);
|
|
37
|
+
const dv = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
38
|
+
if (dv.getUint32(0, true) !== GLB_MAGIC)
|
|
39
|
+
throw new Error('not a GLB (bad magic)');
|
|
40
|
+
const version = dv.getUint32(4, true);
|
|
41
|
+
if (version !== 2)
|
|
42
|
+
throw new Error(`not a glTF 2.0 GLB (version ${version})`);
|
|
43
|
+
const length = dv.getUint32(8, true);
|
|
44
|
+
if (length < HEADER)
|
|
45
|
+
throw new Error(`not a GLB: its header gives a length of ${length}`);
|
|
46
|
+
if (length > bytes.byteLength)
|
|
47
|
+
throw new Error(`truncated GLB: the header says ${length} bytes, there are ${bytes.byteLength}`);
|
|
48
|
+
let offset = HEADER;
|
|
49
|
+
let json;
|
|
50
|
+
let bin = null;
|
|
51
|
+
while (offset + 8 <= length) {
|
|
52
|
+
const chunkLength = dv.getUint32(offset, true);
|
|
53
|
+
const type = dv.getUint32(offset + 4, true);
|
|
54
|
+
const start = offset + 8;
|
|
55
|
+
if (start + chunkLength > length)
|
|
56
|
+
throw new Error(`truncated GLB: the chunk at byte ${offset} runs ${start + chunkLength - length} bytes past the end`);
|
|
57
|
+
const body = bytes.subarray(start, start + chunkLength);
|
|
58
|
+
if (type === JSON_CHUNK && json === undefined)
|
|
59
|
+
json = JSON.parse(new TextDecoder().decode(body));
|
|
60
|
+
else if (type === BIN_CHUNK && bin === null)
|
|
61
|
+
bin = body;
|
|
62
|
+
offset = start + chunkLength;
|
|
63
|
+
}
|
|
64
|
+
if (json === undefined)
|
|
65
|
+
throw new Error('the GLB has no JSON chunk');
|
|
66
|
+
return { json, bin };
|
|
67
|
+
}
|
|
68
|
+
function padded(bytes, fill) {
|
|
69
|
+
const n = (4 - (bytes.byteLength % 4)) % 4;
|
|
70
|
+
if (n === 0)
|
|
71
|
+
return bytes;
|
|
72
|
+
const out = new Uint8Array(bytes.byteLength + n).fill(fill);
|
|
73
|
+
out.set(bytes);
|
|
74
|
+
return out;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* A GLB from JSON and a binary chunk, padded as the spec says. A null or
|
|
78
|
+
* empty binary chunk is left out.
|
|
79
|
+
*/
|
|
80
|
+
export function writeGlb(json, bin) {
|
|
81
|
+
const j = padded(new TextEncoder().encode(JSON.stringify(json)), 0x20);
|
|
82
|
+
const b = bin === null || bin.byteLength === 0 ? null : padded(bin, 0);
|
|
83
|
+
const total = HEADER + 8 + j.byteLength + (b === null ? 0 : 8 + b.byteLength);
|
|
84
|
+
const out = new Uint8Array(total);
|
|
85
|
+
const dv = new DataView(out.buffer);
|
|
86
|
+
dv.setUint32(0, GLB_MAGIC, true);
|
|
87
|
+
dv.setUint32(4, 2, true);
|
|
88
|
+
dv.setUint32(8, total, true);
|
|
89
|
+
dv.setUint32(12, j.byteLength, true);
|
|
90
|
+
dv.setUint32(16, JSON_CHUNK, true);
|
|
91
|
+
out.set(j, 20);
|
|
92
|
+
if (b !== null) {
|
|
93
|
+
const at = 20 + j.byteLength;
|
|
94
|
+
dv.setUint32(at, b.byteLength, true);
|
|
95
|
+
dv.setUint32(at + 4, BIN_CHUNK, true);
|
|
96
|
+
out.set(b, at + 8);
|
|
97
|
+
}
|
|
98
|
+
return out;
|
|
99
|
+
}
|
|
100
|
+
/** Builds a binary chunk: each `add` is a new buffer view, 4-byte aligned. */
|
|
101
|
+
export class BinBuilder {
|
|
102
|
+
parts = [];
|
|
103
|
+
length = 0;
|
|
104
|
+
views = [];
|
|
105
|
+
/** Append bytes as a buffer view; returns its index. */
|
|
106
|
+
add(bytes, target) {
|
|
107
|
+
const view = {
|
|
108
|
+
buffer: 0,
|
|
109
|
+
byteOffset: this.length,
|
|
110
|
+
byteLength: bytes.byteLength,
|
|
111
|
+
};
|
|
112
|
+
if (target !== undefined)
|
|
113
|
+
view.target = target;
|
|
114
|
+
this.views.push(view);
|
|
115
|
+
const p = padded(bytes, 0);
|
|
116
|
+
this.parts.push(p);
|
|
117
|
+
this.length += p.byteLength;
|
|
118
|
+
return this.views.length - 1;
|
|
119
|
+
}
|
|
120
|
+
/** The chunk so far. */
|
|
121
|
+
bytes() {
|
|
122
|
+
const out = new Uint8Array(this.length);
|
|
123
|
+
let at = 0;
|
|
124
|
+
for (const p of this.parts) {
|
|
125
|
+
out.set(p, at);
|
|
126
|
+
at += p.byteLength;
|
|
127
|
+
}
|
|
128
|
+
return out;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const FLOAT = 5126;
|
|
132
|
+
const UNSIGNED_BYTE = 5121;
|
|
133
|
+
const UNSIGNED_SHORT = 5123;
|
|
134
|
+
const UNSIGNED_INT = 5125;
|
|
135
|
+
const COMPONENT_BYTES = {
|
|
136
|
+
5120: 1,
|
|
137
|
+
5121: 1,
|
|
138
|
+
5122: 2,
|
|
139
|
+
5123: 2,
|
|
140
|
+
5125: 4,
|
|
141
|
+
5126: 4,
|
|
142
|
+
};
|
|
143
|
+
const TYPE_COUNT = {
|
|
144
|
+
SCALAR: 1,
|
|
145
|
+
VEC2: 2,
|
|
146
|
+
VEC3: 3,
|
|
147
|
+
VEC4: 4,
|
|
148
|
+
MAT4: 16,
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* `count` elements of `size` bytes from a buffer view, starting `offset`
|
|
152
|
+
* into it, tightly packed. Throws when the view or the read runs past what
|
|
153
|
+
* is there.
|
|
154
|
+
*/
|
|
155
|
+
function viewElements(glb, viewIndex, offset, count, size, what) {
|
|
156
|
+
const v = glb.json.bufferViews?.[viewIndex];
|
|
157
|
+
if (v === undefined)
|
|
158
|
+
throw new Error(`${what}: no bufferView ${viewIndex}`);
|
|
159
|
+
if (glb.bin === null)
|
|
160
|
+
throw new Error(`${what}: the GLB has no binary chunk`);
|
|
161
|
+
const viewStart = v.byteOffset ?? 0;
|
|
162
|
+
if (viewStart + v.byteLength > glb.bin.byteLength)
|
|
163
|
+
throw new Error(`${what}: bufferView ${viewIndex} runs past the binary chunk`);
|
|
164
|
+
const stride = v.byteStride ?? size;
|
|
165
|
+
if (stride < size)
|
|
166
|
+
throw new Error(`${what}: bufferView ${viewIndex}'s stride is under ${size}`);
|
|
167
|
+
if (count > 0 && offset + (count - 1) * stride + size > v.byteLength)
|
|
168
|
+
throw new Error(`${what}: runs past bufferView ${viewIndex}`);
|
|
169
|
+
const base = viewStart + offset;
|
|
170
|
+
if (stride === size)
|
|
171
|
+
return glb.bin.subarray(base, base + count * size);
|
|
172
|
+
const out = new Uint8Array(count * size);
|
|
173
|
+
for (let e = 0; e < count; e++)
|
|
174
|
+
out.set(glb.bin.subarray(base + e * stride, base + e * stride + size), e * size);
|
|
175
|
+
return out;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* An accessor's bytes, tightly packed: a strided view de-interleaved, and a
|
|
179
|
+
* sparse accessor's substitutions applied (over zeros when it has no
|
|
180
|
+
* `bufferView`). May share memory with the binary chunk; copy before writing.
|
|
181
|
+
*/
|
|
182
|
+
export function accessorBytes(glb, index) {
|
|
183
|
+
const what = `accessor ${index}`;
|
|
184
|
+
const a = glb.json.accessors?.[index];
|
|
185
|
+
if (a === undefined)
|
|
186
|
+
throw new Error(`no accessor ${index}`);
|
|
187
|
+
const component = COMPONENT_BYTES[a.componentType];
|
|
188
|
+
const n = TYPE_COUNT[a.type];
|
|
189
|
+
if (component === undefined || n === undefined)
|
|
190
|
+
throw new Error(`${what}: unsupported ${a.componentType} ${a.type}`);
|
|
191
|
+
const size = component * n;
|
|
192
|
+
const s = a.sparse;
|
|
193
|
+
const dense = a.bufferView === undefined
|
|
194
|
+
? null
|
|
195
|
+
: viewElements(glb, a.bufferView, a.byteOffset ?? 0, a.count, size, what);
|
|
196
|
+
if (s === undefined) {
|
|
197
|
+
if (dense === null)
|
|
198
|
+
return new Uint8Array(a.count * size);
|
|
199
|
+
return dense;
|
|
200
|
+
}
|
|
201
|
+
const out = new Uint8Array(a.count * size);
|
|
202
|
+
if (dense !== null)
|
|
203
|
+
out.set(dense);
|
|
204
|
+
const indexBytes = COMPONENT_BYTES[s.indices.componentType];
|
|
205
|
+
if (s.indices.componentType !== UNSIGNED_BYTE &&
|
|
206
|
+
s.indices.componentType !== UNSIGNED_SHORT &&
|
|
207
|
+
s.indices.componentType !== UNSIGNED_INT)
|
|
208
|
+
throw new Error(`${what}: bad sparse index type ${s.indices.componentType}`);
|
|
209
|
+
const raw = viewElements(glb, s.indices.bufferView, s.indices.byteOffset ?? 0, s.count, indexBytes, `${what} sparse indices`);
|
|
210
|
+
const values = viewElements(glb, s.values.bufferView, s.values.byteOffset ?? 0, s.count, size, `${what} sparse values`);
|
|
211
|
+
const iv = new DataView(raw.buffer, raw.byteOffset, raw.byteLength);
|
|
212
|
+
for (let k = 0; k < s.count; k++) {
|
|
213
|
+
const at = indexBytes === 4
|
|
214
|
+
? iv.getUint32(k * 4, true)
|
|
215
|
+
: indexBytes === 2
|
|
216
|
+
? iv.getUint16(k * 2, true)
|
|
217
|
+
: iv.getUint8(k);
|
|
218
|
+
if (at >= a.count)
|
|
219
|
+
throw new Error(`${what}: sparse index ${at} past ${a.count}`);
|
|
220
|
+
out.set(values.subarray(k * size, (k + 1) * size), at * size);
|
|
221
|
+
}
|
|
222
|
+
return out;
|
|
223
|
+
}
|
|
224
|
+
/** An accessor's components as numbers, element by element (not normalised). */
|
|
225
|
+
export function accessorValues(glb, index) {
|
|
226
|
+
const a = glb.json.accessors[index];
|
|
227
|
+
const bytes = accessorBytes(glb, index);
|
|
228
|
+
const dv = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
229
|
+
const read = {
|
|
230
|
+
5120: (o) => dv.getInt8(o),
|
|
231
|
+
5121: (o) => dv.getUint8(o),
|
|
232
|
+
5122: (o) => dv.getInt16(o, true),
|
|
233
|
+
5123: (o) => dv.getUint16(o, true),
|
|
234
|
+
5125: (o) => dv.getUint32(o, true),
|
|
235
|
+
5126: (o) => dv.getFloat32(o, true),
|
|
236
|
+
};
|
|
237
|
+
const r = read[a.componentType];
|
|
238
|
+
const step = COMPONENT_BYTES[a.componentType];
|
|
239
|
+
const out = new Float64Array(bytes.byteLength / step);
|
|
240
|
+
for (let k = 0; k < out.length; k++)
|
|
241
|
+
out[k] = r(k * step);
|
|
242
|
+
return out;
|
|
243
|
+
}
|
|
244
|
+
/** A float VEC3 accessor as xyz per element, sparse or not. */
|
|
245
|
+
export function readVec3(glb, index) {
|
|
246
|
+
const a = glb.json.accessors?.[index];
|
|
247
|
+
if (a === undefined)
|
|
248
|
+
throw new Error(`no accessor ${index}`);
|
|
249
|
+
if (a.componentType !== FLOAT || a.type !== 'VEC3')
|
|
250
|
+
throw new Error(`accessor ${index} is not a float VEC3`);
|
|
251
|
+
return new Float32Array(accessorBytes(glb, index).slice().buffer);
|
|
252
|
+
}
|
|
253
|
+
//# sourceMappingURL=glb-chunks.js.map
|
|
@@ -0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C,CAAC,aAAa,CAAE,CAAA;IAChC,MAAM,IAAI,GAAG,eAAe,CAAC,CAAC,CAAC,aAAa,CAAE,CAAA;IAC9C,MAAM,GAAG,GAAG,IAAI,YAAY,CAAC,KAAK,CAAC,UAAU,GAAG,IAAI,CAAC,CAAA;IACrD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE;QAAE,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAA;IACzD,OAAO,GAAG,CAAA;AACZ,CAAC;AAED,+DAA+D;AAC/D,MAAM,UAAU,QAAQ,CAAC,GAAQ,EAAE,KAAa;IAC9C,MAAM,CAAC,GAAG,GAAG,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,KAAK,CAAC,CAAA;IACrC,IAAI,CAAC,KAAK,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,eAAe,KAAK,EAAE,CAAC,CAAA;IAC5D,IAAI,CAAC,CAAC,aAAa,KAAK,KAAK,IAAI,CAAC,CAAC,IAAI,KAAK,MAAM;QAChD,MAAM,IAAI,KAAK,CAAC,YAAY,KAAK,sBAAsB,CAAC,CAAA;IAC1D,OAAO,IAAI,YAAY,CAAC,aAAa,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,KAAK,EAAE,CAAC,MAAM,CAAC,CAAA;AACnE,CAAC"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/** x, y, z. */
|
|
2
|
+
export type GlbVec3 = readonly [number, number, number];
|
|
3
|
+
/** x, y, z, w. */
|
|
4
|
+
export type GlbQuat = readonly [number, number, number, number];
|
|
5
|
+
export interface GlbJoint {
|
|
6
|
+
name: string;
|
|
7
|
+
/** Index of the parent in `joints`, or -1 for a top-level joint. */
|
|
8
|
+
parent: number;
|
|
9
|
+
translation: GlbVec3;
|
|
10
|
+
rotation: GlbQuat;
|
|
11
|
+
}
|
|
12
|
+
export interface GlbMorph {
|
|
13
|
+
/** xyz delta per vertex. */
|
|
14
|
+
positions: Float32Array;
|
|
15
|
+
}
|
|
16
|
+
export interface GlbPrimitive {
|
|
17
|
+
positions: Float32Array;
|
|
18
|
+
normals: Float32Array;
|
|
19
|
+
/** glTF's convention (v down from the top of the image), or omitted. */
|
|
20
|
+
uvs?: Float32Array | null;
|
|
21
|
+
/** Four joint indices (into `joints`) per vertex. */
|
|
22
|
+
joints: ArrayLike<number>;
|
|
23
|
+
/** Four weights per vertex. */
|
|
24
|
+
weights: ArrayLike<number>;
|
|
25
|
+
/** Triangles, counter-clockwise from outside. */
|
|
26
|
+
indices: ArrayLike<number>;
|
|
27
|
+
/** Index into `materials`. */
|
|
28
|
+
material: number;
|
|
29
|
+
/** One per entry of the mesh's `targetNames`. */
|
|
30
|
+
targets?: GlbMorph[];
|
|
31
|
+
}
|
|
32
|
+
export interface GlbMesh {
|
|
33
|
+
name: string;
|
|
34
|
+
primitives: GlbPrimitive[];
|
|
35
|
+
/** The morph targets' names, one per target (every primitive has them all). */
|
|
36
|
+
targetNames?: string[];
|
|
37
|
+
}
|
|
38
|
+
export interface GlbTexture {
|
|
39
|
+
/** Index into `images`. */
|
|
40
|
+
image: number;
|
|
41
|
+
}
|
|
42
|
+
export interface GlbMaterial {
|
|
43
|
+
name: string;
|
|
44
|
+
baseColorFactor: readonly [number, number, number, number];
|
|
45
|
+
baseColorTexture?: GlbTexture;
|
|
46
|
+
metallicFactor: number;
|
|
47
|
+
roughnessFactor: number;
|
|
48
|
+
metallicRoughnessTexture?: GlbTexture;
|
|
49
|
+
normalTexture?: GlbTexture & {
|
|
50
|
+
scale: number;
|
|
51
|
+
};
|
|
52
|
+
occlusionTexture?: GlbTexture & {
|
|
53
|
+
strength: number;
|
|
54
|
+
};
|
|
55
|
+
alphaMode: 'OPAQUE' | 'MASK' | 'BLEND';
|
|
56
|
+
alphaCutoff?: number;
|
|
57
|
+
doubleSided: boolean;
|
|
58
|
+
sheen?: {
|
|
59
|
+
colorFactor: readonly [number, number, number];
|
|
60
|
+
roughnessFactor: number;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
export interface GlbImage {
|
|
64
|
+
name: string;
|
|
65
|
+
mimeType: 'image/png' | 'image/jpeg';
|
|
66
|
+
bytes: Uint8Array;
|
|
67
|
+
}
|
|
68
|
+
export interface SkinnedGlb {
|
|
69
|
+
asset: {
|
|
70
|
+
generator: string;
|
|
71
|
+
copyright?: string;
|
|
72
|
+
extras?: Record<string, unknown>;
|
|
73
|
+
};
|
|
74
|
+
/** The skeleton. */
|
|
75
|
+
joints: GlbJoint[];
|
|
76
|
+
/** The skin's name. */
|
|
77
|
+
skinName: string;
|
|
78
|
+
/** Index into `joints` of the skin's `skeleton` (its common root). */
|
|
79
|
+
skeletonRoot: number;
|
|
80
|
+
/** 16 column-major numbers per joint. */
|
|
81
|
+
inverseBindMatrices: Float32Array;
|
|
82
|
+
meshes: GlbMesh[];
|
|
83
|
+
materials: GlbMaterial[];
|
|
84
|
+
images: GlbImage[];
|
|
85
|
+
}
|
|
86
|
+
/** Unit normals, float32; a zero or non-finite one becomes +Y. */
|
|
87
|
+
export declare function unitNormals(normals: ArrayLike<number>): Float32Array;
|
|
88
|
+
/**
|
|
89
|
+
* Four influences per vertex as glTF wants them: duplicate joints merged,
|
|
90
|
+
* negative or non-finite weights dropped, the rest renormalised so the
|
|
91
|
+
* float32 sum is 1 (the remainder goes to the largest), unused slots joint 0
|
|
92
|
+
* weight 0. A vertex with no weight at all is given to `fallback` wholly.
|
|
93
|
+
*/
|
|
94
|
+
export declare function normaliseInfluences(joints: ArrayLike<number>, weights: ArrayLike<number>, fallback?: number): {
|
|
95
|
+
joints: Uint8Array | Uint16Array;
|
|
96
|
+
weights: Float32Array;
|
|
97
|
+
maxJoint: number;
|
|
98
|
+
};
|
|
99
|
+
/** The GLB's bytes. Throws on input glTF could not represent. */
|
|
100
|
+
export declare function writeSkinnedGlb(g: SkinnedGlb): Uint8Array;
|
|
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AAE,YAAY,CAAA;IACjC,MAAM,EAAE,OAAO,EAAE,CAAA;IACjB,SAAS,EAAE,WAAW,EAAE,CAAA;IACxB,MAAM,EAAE,QAAQ,EAAE,CAAA;CACnB;AA0BD,kEAAkE;AAClE,wBAAgB,WAAW,CAAC,OAAO,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,YAAY,CAgBpE;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,EACzB,OAAO,EAAE,SAAS,CAAC,MAAM,CAAC,EAC1B,QAAQ,SAAI,GACX;IACD,MAAM,EAAE,UAAU,GAAG,WAAW,CAAA;IAChC,OAAO,EAAE,YAAY,CAAA;IACrB,QAAQ,EAAE,MAAM,CAAA;CACjB,CA+BA;AAED,iEAAiE;AACjE,wBAAgB,eAAe,CAAC,CAAC,EAAE,UAAU,GAAG,UAAU,CAkQzD"}
|
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
/*#
|
|
2
|
+
# skinned-glb
|
|
3
|
+
|
|
4
|
+
**A skinned, morphing mesh out as a GLB.** `writeSkinnedGlb` writes one
|
|
5
|
+
skeleton, any number of meshes skinned to it (four influences a vertex), each
|
|
6
|
+
with morph targets named in `extras.targetNames`, and plain glTF
|
|
7
|
+
metallic-roughness materials with their images embedded. Pure: no Babylon,
|
|
8
|
+
no DOM, synchronous, bytes out. It is `writeGarmentGlb`'s sibling for rigged
|
|
9
|
+
bodies, which that writer does not do (no skin, no morphs).
|
|
10
|
+
|
|
11
|
+
Part of the [character core](/character-core/): import it as
|
|
12
|
+
`tosijs-3d/skinned-glb`. Written for Dramatis's character exporter (GLB and
|
|
13
|
+
VRM), and checked against the Khronos validator and Babylon's own loader.
|
|
14
|
+
|
|
15
|
+
```javascript
|
|
16
|
+
import { writeSkinnedGlb } from 'tosijs-3d/skinned-glb'
|
|
17
|
+
const bytes = writeSkinnedGlb({ asset, joints, skinName, skeletonRoot, inverseBindMatrices, meshes, materials, images })
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
What it guarantees, so the Khronos validator is clean:
|
|
21
|
+
|
|
22
|
+
- joints are nodes `0..n-1`, in the order given, each parent before its
|
|
23
|
+
children; every mesh is its own top-level node with no transform;
|
|
24
|
+
- `POSITION` accessors (and every morph target's) carry `min` and `max`;
|
|
25
|
+
- normals are unit length (a zero normal becomes +Y); weights are
|
|
26
|
+
renormalised in float32 so each vertex's sum is 1, and a joint never
|
|
27
|
+
appears twice in one vertex's non-zero slots;
|
|
28
|
+
- indices are `UNSIGNED_SHORT` below 65,535 vertices, `UNSIGNED_INT` above;
|
|
29
|
+
- morph targets are sparse accessors over the vertices they move (a target
|
|
30
|
+
that moves nothing is the caller's to leave out; one here throws);
|
|
31
|
+
- `KHR_materials_sheen` is listed in `extensionsUsed` only when a material
|
|
32
|
+
has sheen; nothing is ever required.
|
|
33
|
+
*/
|
|
34
|
+
/*{ "parent": "character-core", "order": 30 }*/
|
|
35
|
+
import { BinBuilder, writeGlb } from './glb-chunks.js';
|
|
36
|
+
const FLOAT = 5126;
|
|
37
|
+
const UNSIGNED_BYTE = 5121;
|
|
38
|
+
const UNSIGNED_SHORT = 5123;
|
|
39
|
+
const UNSIGNED_INT = 5125;
|
|
40
|
+
const ARRAY_BUFFER = 34962;
|
|
41
|
+
const ELEMENT_ARRAY_BUFFER = 34963;
|
|
42
|
+
const asBytes = (a) => new Uint8Array(a.buffer, a.byteOffset, a.byteLength);
|
|
43
|
+
function bounds(v) {
|
|
44
|
+
const min = [Infinity, Infinity, Infinity];
|
|
45
|
+
const max = [-Infinity, -Infinity, -Infinity];
|
|
46
|
+
for (let i = 0; i < v.length; i += 3)
|
|
47
|
+
for (let k = 0; k < 3; k++) {
|
|
48
|
+
const x = v[i + k];
|
|
49
|
+
if (x < min[k])
|
|
50
|
+
min[k] = x;
|
|
51
|
+
if (x > max[k])
|
|
52
|
+
max[k] = x;
|
|
53
|
+
}
|
|
54
|
+
return { min, max };
|
|
55
|
+
}
|
|
56
|
+
/** Unit normals, float32; a zero or non-finite one becomes +Y. */
|
|
57
|
+
export function unitNormals(normals) {
|
|
58
|
+
const out = new Float32Array(normals.length);
|
|
59
|
+
for (let i = 0; i < normals.length; i += 3) {
|
|
60
|
+
const x = normals[i];
|
|
61
|
+
const y = normals[i + 1];
|
|
62
|
+
const z = normals[i + 2];
|
|
63
|
+
const l = Math.hypot(x, y, z);
|
|
64
|
+
if (!(l > 1e-12) || !Number.isFinite(l)) {
|
|
65
|
+
out[i + 1] = 1;
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
out[i] = x / l;
|
|
69
|
+
out[i + 1] = y / l;
|
|
70
|
+
out[i + 2] = z / l;
|
|
71
|
+
}
|
|
72
|
+
return out;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Four influences per vertex as glTF wants them: duplicate joints merged,
|
|
76
|
+
* negative or non-finite weights dropped, the rest renormalised so the
|
|
77
|
+
* float32 sum is 1 (the remainder goes to the largest), unused slots joint 0
|
|
78
|
+
* weight 0. A vertex with no weight at all is given to `fallback` wholly.
|
|
79
|
+
*/
|
|
80
|
+
export function normaliseInfluences(joints, weights, fallback = 0) {
|
|
81
|
+
const n = weights.length / 4;
|
|
82
|
+
let maxJoint = fallback;
|
|
83
|
+
for (let i = 0; i < joints.length; i++)
|
|
84
|
+
if (weights[i] > 0)
|
|
85
|
+
maxJoint = Math.max(maxJoint, joints[i]);
|
|
86
|
+
const j = maxJoint < 256 ? new Uint8Array(n * 4) : new Uint16Array(n * 4);
|
|
87
|
+
const w = new Float32Array(n * 4);
|
|
88
|
+
const f = new Float32Array(1);
|
|
89
|
+
for (let v = 0; v < n; v++) {
|
|
90
|
+
const acc = new Map();
|
|
91
|
+
for (let k = 0; k < 4; k++) {
|
|
92
|
+
const x = weights[v * 4 + k];
|
|
93
|
+
if (!(x > 0) || !Number.isFinite(x))
|
|
94
|
+
continue;
|
|
95
|
+
const jj = joints[v * 4 + k];
|
|
96
|
+
acc.set(jj, (acc.get(jj) ?? 0) + x);
|
|
97
|
+
}
|
|
98
|
+
const list = [...acc.entries()].sort((a, b) => b[1] - a[1]);
|
|
99
|
+
if (list.length === 0)
|
|
100
|
+
list.push([fallback, 1]);
|
|
101
|
+
const sum = list.reduce((s, [, x]) => s + x, 0);
|
|
102
|
+
let total = 0;
|
|
103
|
+
list.forEach(([jj, x], k) => {
|
|
104
|
+
j[v * 4 + k] = jj;
|
|
105
|
+
f[0] = x / sum;
|
|
106
|
+
w[v * 4 + k] = f[0];
|
|
107
|
+
total += f[0];
|
|
108
|
+
});
|
|
109
|
+
// Put the float32 rounding into the largest weight.
|
|
110
|
+
f[0] = w[v * 4] + (1 - total);
|
|
111
|
+
w[v * 4] = f[0];
|
|
112
|
+
}
|
|
113
|
+
return { joints: j, weights: w, maxJoint };
|
|
114
|
+
}
|
|
115
|
+
/** The GLB's bytes. Throws on input glTF could not represent. */
|
|
116
|
+
export function writeSkinnedGlb(g) {
|
|
117
|
+
const bin = new BinBuilder();
|
|
118
|
+
const accessors = [];
|
|
119
|
+
const accessor = (a) => {
|
|
120
|
+
accessors.push(a);
|
|
121
|
+
return accessors.length - 1;
|
|
122
|
+
};
|
|
123
|
+
const n = g.joints.length;
|
|
124
|
+
if (g.inverseBindMatrices.length !== n * 16)
|
|
125
|
+
throw new Error(`skinned-glb: ${n} joints, ${g.inverseBindMatrices.length / 16} inverse bind matrices`);
|
|
126
|
+
g.joints.forEach((jt, i) => {
|
|
127
|
+
if (jt.parent >= i)
|
|
128
|
+
throw new Error(`skinned-glb: joint ${jt.name}'s parent comes after it`);
|
|
129
|
+
});
|
|
130
|
+
// Nodes: the joints first, then one per mesh.
|
|
131
|
+
const nodes = g.joints.map((jt) => ({
|
|
132
|
+
name: jt.name,
|
|
133
|
+
translation: [...jt.translation],
|
|
134
|
+
rotation: [...jt.rotation],
|
|
135
|
+
}));
|
|
136
|
+
const children = new Map();
|
|
137
|
+
g.joints.forEach((jt, i) => {
|
|
138
|
+
if (jt.parent < 0)
|
|
139
|
+
return;
|
|
140
|
+
const list = children.get(jt.parent) ?? [];
|
|
141
|
+
list.push(i);
|
|
142
|
+
children.set(jt.parent, list);
|
|
143
|
+
});
|
|
144
|
+
for (const [p, list] of children)
|
|
145
|
+
nodes[p].children = list;
|
|
146
|
+
const topJoints = g.joints.flatMap((jt, i) => (jt.parent < 0 ? [i] : []));
|
|
147
|
+
const ibm = accessor({
|
|
148
|
+
bufferView: bin.add(asBytes(Float32Array.from(g.inverseBindMatrices))),
|
|
149
|
+
componentType: FLOAT,
|
|
150
|
+
count: n,
|
|
151
|
+
type: 'MAT4',
|
|
152
|
+
});
|
|
153
|
+
const skins = [
|
|
154
|
+
{
|
|
155
|
+
name: g.skinName,
|
|
156
|
+
inverseBindMatrices: ibm,
|
|
157
|
+
skeleton: g.skeletonRoot,
|
|
158
|
+
joints: g.joints.map((_, i) => i),
|
|
159
|
+
},
|
|
160
|
+
];
|
|
161
|
+
const meshes = g.meshes.map((mesh) => {
|
|
162
|
+
const names = mesh.targetNames ?? [];
|
|
163
|
+
const primitives = mesh.primitives.map((p) => {
|
|
164
|
+
const count = p.positions.length / 3;
|
|
165
|
+
if (p.normals.length !== count * 3)
|
|
166
|
+
throw new Error(`skinned-glb: ${mesh.name}: normals are not one per vertex`);
|
|
167
|
+
const attributes = {};
|
|
168
|
+
const pos = Float32Array.from(p.positions);
|
|
169
|
+
attributes.POSITION = accessor({
|
|
170
|
+
bufferView: bin.add(asBytes(pos), ARRAY_BUFFER),
|
|
171
|
+
componentType: FLOAT,
|
|
172
|
+
count,
|
|
173
|
+
type: 'VEC3',
|
|
174
|
+
...bounds(pos),
|
|
175
|
+
});
|
|
176
|
+
attributes.NORMAL = accessor({
|
|
177
|
+
bufferView: bin.add(asBytes(unitNormals(p.normals)), ARRAY_BUFFER),
|
|
178
|
+
componentType: FLOAT,
|
|
179
|
+
count,
|
|
180
|
+
type: 'VEC3',
|
|
181
|
+
});
|
|
182
|
+
if (p.uvs != null) {
|
|
183
|
+
if (p.uvs.length !== count * 2)
|
|
184
|
+
throw new Error(`skinned-glb: ${mesh.name}: uvs are not one per vertex`);
|
|
185
|
+
attributes.TEXCOORD_0 = accessor({
|
|
186
|
+
bufferView: bin.add(asBytes(Float32Array.from(p.uvs)), ARRAY_BUFFER),
|
|
187
|
+
componentType: FLOAT,
|
|
188
|
+
count,
|
|
189
|
+
type: 'VEC2',
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
const inf = normaliseInfluences(p.joints, p.weights);
|
|
193
|
+
if (inf.maxJoint >= n)
|
|
194
|
+
throw new Error(`skinned-glb: ${mesh.name}: joint ${inf.maxJoint} is not in the skeleton`);
|
|
195
|
+
if (inf.joints.length !== count * 4)
|
|
196
|
+
throw new Error(`skinned-glb: ${mesh.name}: influences are not four per vertex`);
|
|
197
|
+
attributes.JOINTS_0 = accessor({
|
|
198
|
+
bufferView: bin.add(asBytes(inf.joints), ARRAY_BUFFER),
|
|
199
|
+
componentType: inf.joints instanceof Uint8Array ? UNSIGNED_BYTE : UNSIGNED_SHORT,
|
|
200
|
+
count,
|
|
201
|
+
type: 'VEC4',
|
|
202
|
+
});
|
|
203
|
+
attributes.WEIGHTS_0 = accessor({
|
|
204
|
+
bufferView: bin.add(asBytes(inf.weights), ARRAY_BUFFER),
|
|
205
|
+
componentType: FLOAT,
|
|
206
|
+
count,
|
|
207
|
+
type: 'VEC4',
|
|
208
|
+
});
|
|
209
|
+
const m = g.materials[p.material];
|
|
210
|
+
if (m === undefined)
|
|
211
|
+
throw new Error(`skinned-glb: ${mesh.name}: no material ${p.material}`);
|
|
212
|
+
if (p.uvs == null &&
|
|
213
|
+
(m.baseColorTexture ||
|
|
214
|
+
m.metallicRoughnessTexture ||
|
|
215
|
+
m.normalTexture ||
|
|
216
|
+
m.occlusionTexture))
|
|
217
|
+
throw new Error(`skinned-glb: ${mesh.name}: its material is textured but has no uvs`);
|
|
218
|
+
const wide = count >= 65535;
|
|
219
|
+
const idx = wide
|
|
220
|
+
? Uint32Array.from(p.indices)
|
|
221
|
+
: Uint16Array.from(p.indices);
|
|
222
|
+
for (const i of idx)
|
|
223
|
+
if (i >= count)
|
|
224
|
+
throw new Error(`skinned-glb: ${mesh.name}: index ${i} past ${count} vertices`);
|
|
225
|
+
const prim = {
|
|
226
|
+
attributes,
|
|
227
|
+
indices: accessor({
|
|
228
|
+
bufferView: bin.add(asBytes(idx), ELEMENT_ARRAY_BUFFER),
|
|
229
|
+
componentType: wide ? UNSIGNED_INT : UNSIGNED_SHORT,
|
|
230
|
+
count: idx.length,
|
|
231
|
+
type: 'SCALAR',
|
|
232
|
+
}),
|
|
233
|
+
material: p.material,
|
|
234
|
+
mode: 4,
|
|
235
|
+
};
|
|
236
|
+
const targets = p.targets ?? [];
|
|
237
|
+
if (targets.length !== names.length)
|
|
238
|
+
throw new Error(`skinned-glb: ${mesh.name}: ${targets.length} targets, ${names.length} names`);
|
|
239
|
+
if (targets.length > 0)
|
|
240
|
+
prim.targets = targets.map((t, k) => ({
|
|
241
|
+
POSITION: sparseTarget(bin, accessor, t.positions, count, `${mesh.name}/${names[k]}`),
|
|
242
|
+
}));
|
|
243
|
+
return prim;
|
|
244
|
+
});
|
|
245
|
+
const out = { name: mesh.name, primitives };
|
|
246
|
+
if (names.length > 0) {
|
|
247
|
+
out.weights = names.map(() => 0);
|
|
248
|
+
out.extras = { targetNames: [...names] };
|
|
249
|
+
}
|
|
250
|
+
return out;
|
|
251
|
+
});
|
|
252
|
+
const meshNodes = g.meshes.map((mesh, i) => {
|
|
253
|
+
nodes.push({ name: mesh.name, mesh: i, skin: 0 });
|
|
254
|
+
return nodes.length - 1;
|
|
255
|
+
});
|
|
256
|
+
const images = g.images.map((im) => ({
|
|
257
|
+
name: im.name,
|
|
258
|
+
mimeType: im.mimeType,
|
|
259
|
+
bufferView: bin.add(im.bytes),
|
|
260
|
+
}));
|
|
261
|
+
const textures = [];
|
|
262
|
+
const textureFor = new Map();
|
|
263
|
+
const texture = (t) => {
|
|
264
|
+
if (t.image < 0 || t.image >= images.length)
|
|
265
|
+
throw new Error(`skinned-glb: no image ${t.image}`);
|
|
266
|
+
let i = textureFor.get(t.image);
|
|
267
|
+
if (i === undefined) {
|
|
268
|
+
textures.push({ source: t.image, sampler: 0 });
|
|
269
|
+
i = textures.length - 1;
|
|
270
|
+
textureFor.set(t.image, i);
|
|
271
|
+
}
|
|
272
|
+
return i;
|
|
273
|
+
};
|
|
274
|
+
let sheen = false;
|
|
275
|
+
const materials = g.materials.map((m) => {
|
|
276
|
+
const pbr = {
|
|
277
|
+
baseColorFactor: [...m.baseColorFactor],
|
|
278
|
+
metallicFactor: m.metallicFactor,
|
|
279
|
+
roughnessFactor: m.roughnessFactor,
|
|
280
|
+
};
|
|
281
|
+
if (m.baseColorTexture)
|
|
282
|
+
pbr.baseColorTexture = { index: texture(m.baseColorTexture) };
|
|
283
|
+
if (m.metallicRoughnessTexture)
|
|
284
|
+
pbr.metallicRoughnessTexture = {
|
|
285
|
+
index: texture(m.metallicRoughnessTexture),
|
|
286
|
+
};
|
|
287
|
+
const out = {
|
|
288
|
+
name: m.name,
|
|
289
|
+
pbrMetallicRoughness: pbr,
|
|
290
|
+
alphaMode: m.alphaMode,
|
|
291
|
+
doubleSided: m.doubleSided,
|
|
292
|
+
};
|
|
293
|
+
if (m.alphaMode === 'MASK')
|
|
294
|
+
out.alphaCutoff = m.alphaCutoff ?? 0.5;
|
|
295
|
+
if (m.normalTexture)
|
|
296
|
+
out.normalTexture = {
|
|
297
|
+
index: texture(m.normalTexture),
|
|
298
|
+
scale: m.normalTexture.scale,
|
|
299
|
+
};
|
|
300
|
+
if (m.occlusionTexture)
|
|
301
|
+
out.occlusionTexture = {
|
|
302
|
+
index: texture(m.occlusionTexture),
|
|
303
|
+
strength: m.occlusionTexture.strength,
|
|
304
|
+
};
|
|
305
|
+
if (m.sheen) {
|
|
306
|
+
sheen = true;
|
|
307
|
+
out.extensions = {
|
|
308
|
+
KHR_materials_sheen: {
|
|
309
|
+
sheenColorFactor: [...m.sheen.colorFactor],
|
|
310
|
+
sheenRoughnessFactor: m.sheen.roughnessFactor,
|
|
311
|
+
},
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
return out;
|
|
315
|
+
});
|
|
316
|
+
const bytes = bin.bytes();
|
|
317
|
+
const json = {
|
|
318
|
+
asset: {
|
|
319
|
+
version: '2.0',
|
|
320
|
+
generator: g.asset.generator,
|
|
321
|
+
...(g.asset.copyright ? { copyright: g.asset.copyright } : {}),
|
|
322
|
+
...(g.asset.extras ? { extras: g.asset.extras } : {}),
|
|
323
|
+
},
|
|
324
|
+
...(sheen ? { extensionsUsed: ['KHR_materials_sheen'] } : {}),
|
|
325
|
+
scene: 0,
|
|
326
|
+
scenes: [{ nodes: [...topJoints, ...meshNodes] }],
|
|
327
|
+
nodes,
|
|
328
|
+
meshes,
|
|
329
|
+
skins,
|
|
330
|
+
accessors,
|
|
331
|
+
bufferViews: bin.views,
|
|
332
|
+
buffers: [{ byteLength: bytes.byteLength }],
|
|
333
|
+
};
|
|
334
|
+
if (materials.length > 0)
|
|
335
|
+
json.materials = materials;
|
|
336
|
+
if (images.length > 0) {
|
|
337
|
+
json.images = images;
|
|
338
|
+
json.textures = textures;
|
|
339
|
+
json.samplers = [
|
|
340
|
+
{ magFilter: 9729, minFilter: 9987, wrapS: 10497, wrapT: 10497 },
|
|
341
|
+
];
|
|
342
|
+
}
|
|
343
|
+
return writeGlb(json, bytes);
|
|
344
|
+
}
|
|
345
|
+
/** A morph target's POSITION as a sparse accessor over the vertices it moves. */
|
|
346
|
+
function sparseTarget(bin, accessor, delta, count, label) {
|
|
347
|
+
if (delta.length !== count * 3)
|
|
348
|
+
throw new Error(`skinned-glb: target ${label} is not one delta per vertex`);
|
|
349
|
+
const moved = [];
|
|
350
|
+
for (let v = 0; v < count; v++)
|
|
351
|
+
if (delta[v * 3] !== 0 || delta[v * 3 + 1] !== 0 || delta[v * 3 + 2] !== 0)
|
|
352
|
+
moved.push(v);
|
|
353
|
+
if (moved.length === 0)
|
|
354
|
+
throw new Error(`skinned-glb: target ${label} moves no vertex`);
|
|
355
|
+
const values = new Float32Array(moved.length * 3);
|
|
356
|
+
moved.forEach((v, k) => {
|
|
357
|
+
values[k * 3] = delta[v * 3];
|
|
358
|
+
values[k * 3 + 1] = delta[v * 3 + 1];
|
|
359
|
+
values[k * 3 + 2] = delta[v * 3 + 2];
|
|
360
|
+
});
|
|
361
|
+
const b = bounds(values);
|
|
362
|
+
if (moved.length < count)
|
|
363
|
+
for (let k = 0; k < 3; k++) {
|
|
364
|
+
// The vertices left out are 0.
|
|
365
|
+
b.min[k] = Math.min(b.min[k], 0);
|
|
366
|
+
b.max[k] = Math.max(b.max[k], 0);
|
|
367
|
+
}
|
|
368
|
+
const wide = count > 65535;
|
|
369
|
+
const indices = wide ? Uint32Array.from(moved) : Uint16Array.from(moved);
|
|
370
|
+
return accessor({
|
|
371
|
+
componentType: FLOAT,
|
|
372
|
+
count,
|
|
373
|
+
type: 'VEC3',
|
|
374
|
+
...b,
|
|
375
|
+
sparse: {
|
|
376
|
+
count: moved.length,
|
|
377
|
+
indices: {
|
|
378
|
+
bufferView: bin.add(asBytes(indices)),
|
|
379
|
+
componentType: wide ? UNSIGNED_INT : UNSIGNED_SHORT,
|
|
380
|
+
},
|
|
381
|
+
values: { bufferView: bin.add(asBytes(values)) },
|
|
382
|
+
},
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
//# sourceMappingURL=skinned-glb.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skinned-glb.js","sourceRoot":"","sources":["../src/skinned-glb.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAgCE;AACF,+CAA+C;AAC/C,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AA4FtD,MAAM,KAAK,GAAG,IAAI,CAAA;AAClB,MAAM,aAAa,GA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C;IACH,MAAM,IAAI,GAAG,KAAK,GAAG,KAAK,CAAA;IAC1B,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACxE,OAAO,QAAQ,CAAC;QACd,aAAa,EAAE,KAAK;QACpB,KAAK;QACL,IAAI,EAAE,MAAM;QACZ,GAAG,CAAC;QACJ,MAAM,EAAE;YACN,KAAK,EAAE,KAAK,CAAC,MAAM;YACnB,OAAO,EAAE;gBACP,UAAU,EAAE,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;gBACrC,aAAa,EAAE,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,cAAc;aACpD;YACD,MAAM,EAAE,EAAE,UAAU,EAAE,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE;SACjD;KACF,CAAC,CAAA;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tosijs-3d",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.1",
|
|
4
4
|
"description": "Declarative 3D/XR components for the web — Babylon.js and tosijs, composable as custom elements.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://3d.tosijs.net",
|
|
@@ -55,6 +55,7 @@
|
|
|
55
55
|
"chokidar": "^4.0.3",
|
|
56
56
|
"eslint": "^10.6.0",
|
|
57
57
|
"globals": "^17.7.0",
|
|
58
|
+
"gltf-validator": "2.0.0-dev.3.10",
|
|
58
59
|
"haltija": "^1.12.6",
|
|
59
60
|
"happy-dom": "^21.0.4",
|
|
60
61
|
"iwer": "^2.5.0",
|