motionary 10.4.0 → 10.5.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/CHANGELOG.md +18 -0
- package/README.md +37 -0
- package/dist/chunks/{anim-image-DDdb9q3X.js → anim-image-BlNPv4JG.js} +2 -2
- package/dist/chunks/{anim-image-DDdb9q3X.js.map → anim-image-BlNPv4JG.js.map} +1 -1
- package/dist/chunks/{anim-image-blQgPFFS.cjs → anim-image-DuxvYhq6.cjs} +2 -2
- package/dist/chunks/{anim-image-blQgPFFS.cjs.map → anim-image-DuxvYhq6.cjs.map} +1 -1
- package/dist/chunks/{keyframes-B5PWe5bU.js → keyframes-B8ITIAVa.js} +2 -2
- package/dist/chunks/{keyframes-B5PWe5bU.js.map → keyframes-B8ITIAVa.js.map} +1 -1
- package/dist/chunks/{keyframes-tC3I7anQ.cjs → keyframes-Ce1s05n3.cjs} +2 -2
- package/dist/chunks/{keyframes-tC3I7anQ.cjs.map → keyframes-Ce1s05n3.cjs.map} +1 -1
- package/dist/chunks/{registry-CT-TT_bx.js → registry-DXdFb2fJ.js} +2 -2
- package/dist/chunks/{registry-CT-TT_bx.js.map → registry-DXdFb2fJ.js.map} +1 -1
- package/dist/chunks/{registry-tzwKkldE.cjs → registry-VhfPSI0v.cjs} +2 -2
- package/dist/chunks/{registry-tzwKkldE.cjs.map → registry-VhfPSI0v.cjs.map} +1 -1
- package/dist/chunks/{ticker-C8lSGml9.js → ticker-C5RMHMW7.js} +2 -2
- package/dist/chunks/{ticker-C8lSGml9.js.map → ticker-C5RMHMW7.js.map} +1 -1
- package/dist/chunks/{ticker-Un0bvTWR.cjs → ticker-DvmC6WLS.cjs} +2 -2
- package/dist/chunks/{ticker-Un0bvTWR.cjs.map → ticker-DvmC6WLS.cjs.map} +1 -1
- package/dist/chunks/{tween-BcejKpsx.js → tween-CPtm-EdT.js} +2 -2
- package/dist/chunks/{tween-BcejKpsx.js.map → tween-CPtm-EdT.js.map} +1 -1
- package/dist/chunks/{tween-CwLLC3Ko.cjs → tween-_BGIl6hK.cjs} +2 -2
- package/dist/chunks/{tween-CwLLC3Ko.cjs.map → tween-_BGIl6hK.cjs.map} +1 -1
- package/dist/components/widgets.cjs +745 -212
- package/dist/components/widgets.cjs.map +1 -1
- package/dist/components/widgets.d.cts +202 -2
- package/dist/components/widgets.d.ts +202 -2
- package/dist/components/widgets.js +738 -213
- package/dist/components/widgets.js.map +1 -1
- package/dist/llms-full.txt +150 -1
- package/dist/llms.txt +9 -2
- package/dist/manifest.json +394 -1
- package/dist/runtime/format-apng.cjs +4 -4
- package/dist/runtime/format-apng.js +4 -4
- package/dist/runtime/format-css.cjs +4 -4
- package/dist/runtime/format-css.js +4 -4
- package/dist/runtime/format-gif.cjs +4 -4
- package/dist/runtime/format-gif.js +4 -4
- package/dist/runtime/format-gltf.cjs +207 -0
- package/dist/runtime/format-gltf.cjs.map +1 -0
- package/dist/runtime/format-gltf.d.cts +251 -0
- package/dist/runtime/format-gltf.d.ts +251 -0
- package/dist/runtime/format-gltf.iife.js +2 -0
- package/dist/runtime/format-gltf.iife.js.map +1 -0
- package/dist/runtime/format-gltf.js +200 -0
- package/dist/runtime/format-gltf.js.map +1 -0
- package/dist/runtime/format-motion.cjs +4 -4
- package/dist/runtime/format-motion.js +4 -4
- package/dist/runtime/format-obj.cjs +181 -0
- package/dist/runtime/format-obj.cjs.map +1 -0
- package/dist/runtime/format-obj.d.cts +176 -0
- package/dist/runtime/format-obj.d.ts +176 -0
- package/dist/runtime/format-obj.iife.js +2 -0
- package/dist/runtime/format-obj.iife.js.map +1 -0
- package/dist/runtime/format-obj.js +174 -0
- package/dist/runtime/format-obj.js.map +1 -0
- package/dist/runtime/format-sprite.cjs +3 -3
- package/dist/runtime/format-sprite.js +3 -3
- package/dist/runtime/format-svg.cjs +3 -3
- package/dist/runtime/format-svg.js +3 -3
- package/dist/runtime/format-webp.cjs +4 -4
- package/dist/runtime/format-webp.js +4 -4
- package/dist/runtime/gl.cjs +763 -0
- package/dist/runtime/gl.cjs.map +1 -0
- package/dist/runtime/gl.d.cts +260 -0
- package/dist/runtime/gl.d.ts +260 -0
- package/dist/runtime/gl.iife.js +2 -0
- package/dist/runtime/gl.iife.js.map +1 -0
- package/dist/runtime/gl.js +739 -0
- package/dist/runtime/gl.js.map +1 -0
- package/dist/runtime/scroll.cjs +2 -2
- package/dist/runtime/scroll.js +2 -2
- package/dist/runtime/smooth.cjs +1 -1
- package/dist/runtime/smooth.js +1 -1
- package/dist/runtime/text.cjs +1 -1
- package/dist/runtime/text.js +1 -1
- package/dist/runtime.cjs +3 -3
- package/dist/runtime.d.cts +1 -1
- package/dist/runtime.d.ts +1 -1
- package/dist/runtime.iife.js +1 -1
- package/dist/runtime.iife.js.map +1 -1
- package/dist/runtime.js +5 -5
- package/dist/widgets.umd.js +1 -1
- package/dist/widgets.umd.js.map +1 -1
- package/docs/ROADMAP.md +1 -1
- package/docs/components/README.md +8 -1
- package/docs/components/usa-gl-scene.md +66 -0
- package/docs/components/usa-gpu-particles.md +32 -0
- package/docs/components/usa-shader-backdrop.md +36 -0
- package/docs/components/usa-three-scene.md +20 -0
- package/docs/components.md +48 -0
- package/docs/runtime/format-gltf.md +63 -0
- package/docs/runtime/format-obj.md +59 -0
- package/docs/runtime/gl.md +62 -0
- package/package.json +32 -2
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var registry = require('../chunks/registry-VhfPSI0v.cjs');
|
|
4
|
+
var runtime_gl = require('./gl.cjs');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* `motionary/runtime/format-gltf` (10.5) — glTF 2.0 / GLB loader for
|
|
8
|
+
* `motionary/runtime/gl` (own implementation):
|
|
9
|
+
*
|
|
10
|
+
* - `.gltf` (JSON + external or `data:` buffers / images) and `.glb`
|
|
11
|
+
* (binary container: JSON + BIN chunks);
|
|
12
|
+
* - scenes and the node hierarchy (TRS or `matrix`), meshes with several
|
|
13
|
+
* primitives (POSITION, NORMAL, TEXCOORD_0, indices; any component type,
|
|
14
|
+
* normalised integers, interleaved `byteStride`; modes points, lines,
|
|
15
|
+
* triangles, strips, fans);
|
|
16
|
+
* - PBR metallic-roughness materials (base colour factor + texture,
|
|
17
|
+
* metallic / roughness factors, emissive factor, alpha modes, double-sided);
|
|
18
|
+
* images from buffer views or URIs (decoded with `createImageBitmap`);
|
|
19
|
+
* - files that *require* an extension we do not implement (e.g. Draco /
|
|
20
|
+
* KTX2 compression) fail with a clear error naming it.
|
|
21
|
+
*
|
|
22
|
+
* Skins, morph targets and animations arrive in 10.8. `parseGlb()` /
|
|
23
|
+
* `gltfToNode()` with an `images` override are pure (SSR / workers).
|
|
24
|
+
*/
|
|
25
|
+
/** Extensions this loader understands (others that a file *requires* make it fail clearly). */
|
|
26
|
+
const SUPPORTED_EXTENSIONS = ['KHR_materials_emissive_strength', 'KHR_materials_unlit'];
|
|
27
|
+
/** Split a GLB container into its JSON and BIN chunk (pure). */
|
|
28
|
+
function parseGlb(input) {
|
|
29
|
+
const b = input instanceof Uint8Array ? input : new Uint8Array(input);
|
|
30
|
+
const v = new DataView(b.buffer, b.byteOffset, b.byteLength);
|
|
31
|
+
if (v.getUint32(0, true) !== 0x46546c67)
|
|
32
|
+
throw new Error('[motionary] format-gltf: not a GLB file');
|
|
33
|
+
if (v.getUint32(4, true) !== 2)
|
|
34
|
+
throw new Error('[motionary] format-gltf: only glTF 2.0 GLB is supported');
|
|
35
|
+
const len = Math.min(v.getUint32(8, true), b.byteLength);
|
|
36
|
+
let p = 12, json = null, bin = null;
|
|
37
|
+
while (p + 8 <= len) {
|
|
38
|
+
const cl = v.getUint32(p, true), ct = v.getUint32(p + 4, true);
|
|
39
|
+
const data = b.subarray(p + 8, p + 8 + cl);
|
|
40
|
+
if (ct === 0x4e4f534a)
|
|
41
|
+
json = JSON.parse(new TextDecoder().decode(data));
|
|
42
|
+
else if (ct === 0x004e4942 && !bin)
|
|
43
|
+
bin = data;
|
|
44
|
+
p += 8 + cl;
|
|
45
|
+
}
|
|
46
|
+
if (!json)
|
|
47
|
+
throw new Error('[motionary] format-gltf: GLB without a JSON chunk');
|
|
48
|
+
return { json, bin };
|
|
49
|
+
}
|
|
50
|
+
const COMP = {
|
|
51
|
+
5120: [1, Int8Array, 127], 5121: [1, Uint8Array, 255], 5122: [2, Int16Array, 32767], 5123: [2, Uint16Array, 65535], 5125: [4, Uint32Array, 0], 5126: [4, Float32Array, 0],
|
|
52
|
+
};
|
|
53
|
+
const SIZE = { SCALAR: 1, VEC2: 2, VEC3: 3, VEC4: 4, MAT2: 4, MAT3: 9, MAT4: 16 };
|
|
54
|
+
/** Read an accessor into a flat typed array (floats are de-interleaved; normalised ints become floats). */
|
|
55
|
+
function readAccessor(json, buffers, index, asFloat = true) {
|
|
56
|
+
const a = json.accessors?.[index];
|
|
57
|
+
if (!a)
|
|
58
|
+
throw new Error(`[motionary] format-gltf: accessor ${index} missing`);
|
|
59
|
+
const [bytes, Ctor, max] = COMP[a.componentType] || [];
|
|
60
|
+
if (!Ctor)
|
|
61
|
+
throw new Error(`[motionary] format-gltf: component type ${a.componentType} unsupported`);
|
|
62
|
+
const n = SIZE[a.type], count = a.count * n;
|
|
63
|
+
const isFloat = Ctor === Float32Array;
|
|
64
|
+
const out = asFloat || isFloat ? new Float32Array(count) : new Ctor(count);
|
|
65
|
+
if (a.bufferView === undefined)
|
|
66
|
+
return out; // all zeros (sparse-only accessors)
|
|
67
|
+
const bv = json.bufferViews[a.bufferView];
|
|
68
|
+
const buf = buffers[bv.buffer];
|
|
69
|
+
const base = (bv.byteOffset || 0) + (a.byteOffset || 0);
|
|
70
|
+
const stride = bv.byteStride || bytes * n;
|
|
71
|
+
const dv = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
72
|
+
const get = (o) => (bytes === 4 ? (isFloat ? dv.getFloat32(o, true) : dv.getUint32(o, true)) : bytes === 2 ? (Ctor === Int16Array ? dv.getInt16(o, true) : dv.getUint16(o, true)) : Ctor === Int8Array ? dv.getInt8(o) : dv.getUint8(o));
|
|
73
|
+
for (let i = 0; i < a.count; i++)
|
|
74
|
+
for (let k = 0; k < n; k++) {
|
|
75
|
+
let x = get(base + i * stride + k * bytes);
|
|
76
|
+
if (a.normalized && max)
|
|
77
|
+
x = Math.max(x / max, -1);
|
|
78
|
+
out[i * n + k] = x;
|
|
79
|
+
}
|
|
80
|
+
return out;
|
|
81
|
+
}
|
|
82
|
+
function toTriangles(idx, mode) {
|
|
83
|
+
const out = [];
|
|
84
|
+
if (mode === 5)
|
|
85
|
+
for (let i = 0; i + 2 < idx.length; i++)
|
|
86
|
+
out.push(...(i % 2 ? [idx[i + 1], idx[i], idx[i + 2]] : [idx[i], idx[i + 1], idx[i + 2]]));
|
|
87
|
+
else
|
|
88
|
+
for (let i = 1; i + 1 < idx.length; i++)
|
|
89
|
+
out.push(idx[0], idx[i], idx[i + 1]);
|
|
90
|
+
return new Uint32Array(out);
|
|
91
|
+
}
|
|
92
|
+
/** Build a runtime/gl node tree from parsed glTF (pure, given buffers and decoded images). */
|
|
93
|
+
function gltfToNode(json, buffers, images = {}, sceneIndex) {
|
|
94
|
+
if (!json.asset || !/^2\./.test(json.asset.version))
|
|
95
|
+
throw new Error('[motionary] format-gltf: only glTF 2.0 is supported');
|
|
96
|
+
const missing = (json.extensionsRequired || []).filter((e) => !SUPPORTED_EXTENSIONS.includes(e));
|
|
97
|
+
if (missing.length)
|
|
98
|
+
throw new Error(`[motionary] format-gltf: this file requires ${missing.join(', ')}, which motionary/runtime/format-gltf does not implement${missing.some((e) => /draco|KHR_texture_basisu|meshopt/i.test(e)) ? ' (compressed geometry / textures need the official decoders — re-export the model without compression, or use the decoder hooks planned for 10.9)' : ''}`);
|
|
99
|
+
const mats = (json.materials || []).map((m) => {
|
|
100
|
+
const pbr = m.pbrMetallicRoughness || {};
|
|
101
|
+
const cf = pbr.baseColorFactor || [1, 1, 1, 1];
|
|
102
|
+
// glTF factors are linear; the shader linearises colour input → convert the factor to sRGB space
|
|
103
|
+
const toS = (x) => Math.pow(Math.max(0, x), 1 / 2.2);
|
|
104
|
+
const strength = m.extensions?.KHR_materials_emissive_strength?.emissiveStrength ?? 1;
|
|
105
|
+
const mat = runtime_gl.standardMaterial({ color: [toS(cf[0]), toS(cf[1]), toS(cf[2]), cf[3] ?? 1], metallic: pbr.metallicFactor ?? 1, roughness: pbr.roughnessFactor ?? 1, emissive: (m.emissiveFactor || [0, 0, 0]).map((x) => x * strength), doubleSided: !!m.doubleSided, transparent: m.alphaMode === 'BLEND' });
|
|
106
|
+
if (m.extensions?.KHR_materials_unlit)
|
|
107
|
+
mat.type = 'unlit';
|
|
108
|
+
const ti = pbr.baseColorTexture?.index;
|
|
109
|
+
const src = ti !== undefined ? json.textures?.[ti]?.source : undefined;
|
|
110
|
+
if (src !== undefined && images[src])
|
|
111
|
+
mat.map = runtime_gl.texture(images[src]);
|
|
112
|
+
return mat;
|
|
113
|
+
});
|
|
114
|
+
const meshes = (json.meshes || []).map((m) => m.primitives.map((p) => {
|
|
115
|
+
const mode = p.mode ?? 4;
|
|
116
|
+
let g = {
|
|
117
|
+
positions: readAccessor(json, buffers, p.attributes.POSITION),
|
|
118
|
+
normals: p.attributes.NORMAL !== undefined ? readAccessor(json, buffers, p.attributes.NORMAL) : undefined,
|
|
119
|
+
uvs: p.attributes.TEXCOORD_0 !== undefined ? readAccessor(json, buffers, p.attributes.TEXCOORD_0) : undefined,
|
|
120
|
+
mode: mode === 0 ? 'points' : mode >= 1 && mode <= 3 ? 'lines' : 'triangles',
|
|
121
|
+
};
|
|
122
|
+
if (p.indices !== undefined) {
|
|
123
|
+
let idx = readAccessor(json, buffers, p.indices, false);
|
|
124
|
+
if (mode === 5 || mode === 6)
|
|
125
|
+
idx = toTriangles(Uint32Array.from(idx), mode);
|
|
126
|
+
g.indices = idx instanceof Uint8Array || (idx instanceof Uint32Array && g.positions.length / 3 <= 65535) ? Uint16Array.from(idx) : idx;
|
|
127
|
+
}
|
|
128
|
+
else if (mode === 5 || mode === 6)
|
|
129
|
+
g.indices = toTriangles(Uint32Array.from({ length: g.positions.length / 3 }, (_, i) => i), mode);
|
|
130
|
+
if (!g.normals && g.mode === 'triangles')
|
|
131
|
+
g = runtime_gl.computeNormals(g);
|
|
132
|
+
return { geometry: g, material: p.material !== undefined ? mats[p.material] : runtime_gl.standardMaterial({ metallic: 0, roughness: 0.6 }) };
|
|
133
|
+
}));
|
|
134
|
+
const nodes = (json.nodes || []).map((n, i) => {
|
|
135
|
+
const node = new runtime_gl.GlNode(n.name || `node${i}`, n.mesh !== undefined ? meshes[n.mesh] : null);
|
|
136
|
+
if (n.matrix)
|
|
137
|
+
node.matrix = new Float32Array(n.matrix);
|
|
138
|
+
if (n.translation)
|
|
139
|
+
node.position = n.translation.slice(0, 3);
|
|
140
|
+
if (n.rotation)
|
|
141
|
+
node.rotation = n.rotation.slice(0, 4);
|
|
142
|
+
if (n.scale)
|
|
143
|
+
node.scale = n.scale.slice(0, 3);
|
|
144
|
+
node.extras.gltfIndex = i;
|
|
145
|
+
return node;
|
|
146
|
+
});
|
|
147
|
+
(json.nodes || []).forEach((n, i) => (n.children || []).forEach((c) => nodes[i].add(nodes[c])));
|
|
148
|
+
const root = new runtime_gl.GlNode('gltf');
|
|
149
|
+
const sc = json.scenes?.[sceneIndex ?? json.scene ?? 0];
|
|
150
|
+
const tops = sc?.nodes ?? nodes.map((_, i) => i).filter((i) => !nodes[i].parent);
|
|
151
|
+
tops.forEach((i) => root.add(nodes[i]));
|
|
152
|
+
root.extras = { gltf: json, nodes };
|
|
153
|
+
return root;
|
|
154
|
+
}
|
|
155
|
+
const dataUri = (u) => {
|
|
156
|
+
const [, meta, data] = /^data:([^,]*),(.*)$/s.exec(u) || [];
|
|
157
|
+
if (meta === undefined)
|
|
158
|
+
throw new Error('[motionary] format-gltf: bad data URI');
|
|
159
|
+
if (/;base64/.test(meta)) {
|
|
160
|
+
const s = atob(data);
|
|
161
|
+
return Uint8Array.from(s, (c) => c.charCodeAt(0));
|
|
162
|
+
}
|
|
163
|
+
return new TextEncoder().encode(decodeURIComponent(data));
|
|
164
|
+
};
|
|
165
|
+
/** Load a `.gltf` / `.glb` (URL or bytes) with its buffers and images and build a node tree. */
|
|
166
|
+
async function loadGltf(src, o = {}) {
|
|
167
|
+
const base = o.baseUrl || (typeof src === 'string' ? new URL(src, typeof location !== 'undefined' ? location.href : 'file:///').href : typeof location !== 'undefined' ? location.href : 'file:///');
|
|
168
|
+
const get = async (u) => {
|
|
169
|
+
if (u.startsWith('data:'))
|
|
170
|
+
return dataUri(u);
|
|
171
|
+
const r = await fetch(new URL(u, base).href);
|
|
172
|
+
if (!r.ok)
|
|
173
|
+
throw new Error(`[motionary] format-gltf: could not load ${u} (${r.status})`);
|
|
174
|
+
return new Uint8Array(await r.arrayBuffer());
|
|
175
|
+
};
|
|
176
|
+
const bytes = typeof src === 'string' ? await get(src) : src instanceof Uint8Array ? src : new Uint8Array(src);
|
|
177
|
+
let json, bin = null;
|
|
178
|
+
if (bytes[0] === 0x67 && bytes[1] === 0x6c && bytes[2] === 0x54 && bytes[3] === 0x46)
|
|
179
|
+
({ json, bin } = parseGlb(bytes));
|
|
180
|
+
else
|
|
181
|
+
json = JSON.parse(new TextDecoder().decode(bytes));
|
|
182
|
+
const buffers = await Promise.all((json.buffers || []).map((b, i) => (b.uri ? get(b.uri) : i === 0 && bin ? Promise.resolve(bin) : Promise.reject(new Error('[motionary] format-gltf: buffer without data')))));
|
|
183
|
+
const images = {};
|
|
184
|
+
await Promise.all((json.images || []).map(async (im, i) => {
|
|
185
|
+
let data;
|
|
186
|
+
if (im.bufferView !== undefined) {
|
|
187
|
+
const bv = json.bufferViews[im.bufferView];
|
|
188
|
+
data = buffers[bv.buffer].subarray(bv.byteOffset || 0, (bv.byteOffset || 0) + bv.byteLength);
|
|
189
|
+
}
|
|
190
|
+
else if (im.uri)
|
|
191
|
+
data = await get(im.uri);
|
|
192
|
+
else
|
|
193
|
+
return;
|
|
194
|
+
images[i] = await createImageBitmap(new Blob([data], { type: im.mimeType || (im.uri && /\.jpe?g$/i.test(im.uri) ? 'image/jpeg' : 'image/png') }));
|
|
195
|
+
}));
|
|
196
|
+
return gltfToNode(json, buffers, images, o.scene);
|
|
197
|
+
}
|
|
198
|
+
/** The module object for `use(formatGltf)` (needs `gl`). */
|
|
199
|
+
const formatGltf = { id: 'format-gltf', version: registry.RUNTIME_VERSION, requires: ['core', 'gl'], api: { parseGlb, readAccessor, gltfToNode, loadGltf, SUPPORTED_EXTENSIONS } };
|
|
200
|
+
|
|
201
|
+
exports.SUPPORTED_EXTENSIONS = SUPPORTED_EXTENSIONS;
|
|
202
|
+
exports.formatGltf = formatGltf;
|
|
203
|
+
exports.gltfToNode = gltfToNode;
|
|
204
|
+
exports.loadGltf = loadGltf;
|
|
205
|
+
exports.parseGlb = parseGlb;
|
|
206
|
+
exports.readAccessor = readAccessor;
|
|
207
|
+
//# sourceMappingURL=format-gltf.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format-gltf.cjs","sources":["../../src/runtime/format-gltf.ts"],"sourcesContent":["/**\n * `motionary/runtime/format-gltf` (10.5) — glTF 2.0 / GLB loader for\n * `motionary/runtime/gl` (own implementation):\n *\n * - `.gltf` (JSON + external or `data:` buffers / images) and `.glb`\n * (binary container: JSON + BIN chunks);\n * - scenes and the node hierarchy (TRS or `matrix`), meshes with several\n * primitives (POSITION, NORMAL, TEXCOORD_0, indices; any component type,\n * normalised integers, interleaved `byteStride`; modes points, lines,\n * triangles, strips, fans);\n * - PBR metallic-roughness materials (base colour factor + texture,\n * metallic / roughness factors, emissive factor, alpha modes, double-sided);\n * images from buffer views or URIs (decoded with `createImageBitmap`);\n * - files that *require* an extension we do not implement (e.g. Draco /\n * KTX2 compression) fail with a clear error naming it.\n *\n * Skins, morph targets and animations arrive in 10.8. `parseGlb()` /\n * `gltfToNode()` with an `images` override are pure (SSR / workers).\n */\nimport { RUNTIME_VERSION, type RuntimeModule } from './registry';\nimport { GlNode, standardMaterial, computeNormals, texture, type Geometry, type Material, type Mesh, type Quat, type Vec3 } from './gl';\n\nexport interface GltfJson {\n asset: { version: string; generator?: string };\n scene?: number;\n scenes?: { nodes?: number[]; name?: string }[];\n nodes?: { name?: string; children?: number[]; mesh?: number; matrix?: number[]; translation?: number[]; rotation?: number[]; scale?: number[]; skin?: number; camera?: number }[];\n meshes?: { name?: string; primitives: { attributes: Record<string, number>; indices?: number; material?: number; mode?: number; targets?: Record<string, number>[] }[]; weights?: number[] }[];\n accessors?: { bufferView?: number; byteOffset?: number; componentType: number; normalized?: boolean; count: number; type: string; min?: number[]; max?: number[]; sparse?: unknown }[];\n bufferViews?: { buffer: number; byteOffset?: number; byteLength: number; byteStride?: number }[];\n buffers?: { uri?: string; byteLength: number }[];\n materials?: { name?: string; pbrMetallicRoughness?: { baseColorFactor?: number[]; baseColorTexture?: { index: number }; metallicFactor?: number; roughnessFactor?: number }; emissiveFactor?: number[]; alphaMode?: string; doubleSided?: boolean; extensions?: Record<string, any> }[];\n textures?: { source?: number; sampler?: number }[];\n images?: { uri?: string; bufferView?: number; mimeType?: string }[];\n extensionsUsed?: string[];\n extensionsRequired?: string[];\n animations?: unknown[];\n skins?: unknown[];\n}\n\n/** Extensions this loader understands (others that a file *requires* make it fail clearly). */\nexport const SUPPORTED_EXTENSIONS = ['KHR_materials_emissive_strength', 'KHR_materials_unlit'];\n\n/** Split a GLB container into its JSON and BIN chunk (pure). */\nexport function parseGlb(input: ArrayBuffer | Uint8Array): { json: GltfJson; bin: Uint8Array | null } {\n const b = input instanceof Uint8Array ? input : new Uint8Array(input);\n const v = new DataView(b.buffer, b.byteOffset, b.byteLength);\n if (v.getUint32(0, true) !== 0x46546c67) throw new Error('[motionary] format-gltf: not a GLB file');\n if (v.getUint32(4, true) !== 2) throw new Error('[motionary] format-gltf: only glTF 2.0 GLB is supported');\n const len = Math.min(v.getUint32(8, true), b.byteLength);\n let p = 12, json: GltfJson | null = null, bin: Uint8Array | null = null;\n while (p + 8 <= len) {\n const cl = v.getUint32(p, true), ct = v.getUint32(p + 4, true);\n const data = b.subarray(p + 8, p + 8 + cl);\n if (ct === 0x4e4f534a) json = JSON.parse(new TextDecoder().decode(data));\n else if (ct === 0x004e4942 && !bin) bin = data;\n p += 8 + cl;\n }\n if (!json) throw new Error('[motionary] format-gltf: GLB without a JSON chunk');\n return { json, bin };\n}\n\nconst COMP: Record<number, [number, any, number]> = {\n 5120: [1, Int8Array, 127], 5121: [1, Uint8Array, 255], 5122: [2, Int16Array, 32767], 5123: [2, Uint16Array, 65535], 5125: [4, Uint32Array, 0], 5126: [4, Float32Array, 0],\n};\nconst SIZE: Record<string, number> = { SCALAR: 1, VEC2: 2, VEC3: 3, VEC4: 4, MAT2: 4, MAT3: 9, MAT4: 16 };\n\n/** Read an accessor into a flat typed array (floats are de-interleaved; normalised ints become floats). */\nexport function readAccessor(json: GltfJson, buffers: Uint8Array[], index: number, asFloat = true): Float32Array | Uint16Array | Uint32Array | Uint8Array {\n const a = json.accessors?.[index];\n if (!a) throw new Error(`[motionary] format-gltf: accessor ${index} missing`);\n const [bytes, Ctor, max] = COMP[a.componentType] || [];\n if (!Ctor) throw new Error(`[motionary] format-gltf: component type ${a.componentType} unsupported`);\n const n = SIZE[a.type], count = a.count * n;\n const isFloat = Ctor === Float32Array;\n const out = asFloat || isFloat ? new Float32Array(count) : new Ctor(count);\n if (a.bufferView === undefined) return out; // all zeros (sparse-only accessors)\n const bv = json.bufferViews![a.bufferView];\n const buf = buffers[bv.buffer];\n const base = (bv.byteOffset || 0) + (a.byteOffset || 0);\n const stride = bv.byteStride || bytes * n;\n const dv = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);\n const get = (o: number): number => (bytes === 4 ? (isFloat ? dv.getFloat32(o, true) : dv.getUint32(o, true)) : bytes === 2 ? (Ctor === Int16Array ? dv.getInt16(o, true) : dv.getUint16(o, true)) : Ctor === Int8Array ? dv.getInt8(o) : dv.getUint8(o));\n for (let i = 0; i < a.count; i++)\n for (let k = 0; k < n; k++) {\n let x = get(base + i * stride + k * bytes);\n if (a.normalized && max) x = Math.max(x / max, -1);\n out[i * n + k] = x;\n }\n return out;\n}\n\nfunction toTriangles(idx: Uint32Array, mode: number): Uint32Array {\n const out: number[] = [];\n if (mode === 5) for (let i = 0; i + 2 < idx.length; i++) out.push(...(i % 2 ? [idx[i + 1], idx[i], idx[i + 2]] : [idx[i], idx[i + 1], idx[i + 2]]));\n else for (let i = 1; i + 1 < idx.length; i++) out.push(idx[0], idx[i], idx[i + 1]);\n return new Uint32Array(out);\n}\n\nexport interface GltfImages {\n /** Decoded images by glTF image index (pass your own for SSR / tests). */\n [index: number]: TexImageSource | undefined;\n}\n\n/** Build a runtime/gl node tree from parsed glTF (pure, given buffers and decoded images). */\nexport function gltfToNode(json: GltfJson, buffers: Uint8Array[], images: GltfImages = {}, sceneIndex?: number): GlNode {\n if (!json.asset || !/^2\\./.test(json.asset.version)) throw new Error('[motionary] format-gltf: only glTF 2.0 is supported');\n const missing = (json.extensionsRequired || []).filter((e) => !SUPPORTED_EXTENSIONS.includes(e));\n if (missing.length) throw new Error(`[motionary] format-gltf: this file requires ${missing.join(', ')}, which motionary/runtime/format-gltf does not implement${missing.some((e) => /draco|KHR_texture_basisu|meshopt/i.test(e)) ? ' (compressed geometry / textures need the official decoders — re-export the model without compression, or use the decoder hooks planned for 10.9)' : ''}`);\n const mats: Material[] = (json.materials || []).map((m) => {\n const pbr = m.pbrMetallicRoughness || {};\n const cf = pbr.baseColorFactor || [1, 1, 1, 1];\n // glTF factors are linear; the shader linearises colour input → convert the factor to sRGB space\n const toS = (x: number) => Math.pow(Math.max(0, x), 1 / 2.2);\n const strength = m.extensions?.KHR_materials_emissive_strength?.emissiveStrength ?? 1;\n const mat = standardMaterial({ color: [toS(cf[0]), toS(cf[1]), toS(cf[2]), cf[3] ?? 1], metallic: pbr.metallicFactor ?? 1, roughness: pbr.roughnessFactor ?? 1, emissive: ((m.emissiveFactor || [0, 0, 0]).map((x) => x * strength) as Vec3), doubleSided: !!m.doubleSided, transparent: m.alphaMode === 'BLEND' });\n if (m.extensions?.KHR_materials_unlit) mat.type = 'unlit';\n const ti = pbr.baseColorTexture?.index;\n const src = ti !== undefined ? json.textures?.[ti]?.source : undefined;\n if (src !== undefined && images[src]) mat.map = texture(images[src]!);\n return mat;\n });\n const meshes: Mesh[][] = (json.meshes || []).map((m) =>\n m.primitives.map((p) => {\n const mode = p.mode ?? 4;\n let g: Geometry = {\n positions: readAccessor(json, buffers, p.attributes.POSITION) as Float32Array,\n normals: p.attributes.NORMAL !== undefined ? (readAccessor(json, buffers, p.attributes.NORMAL) as Float32Array) : undefined,\n uvs: p.attributes.TEXCOORD_0 !== undefined ? (readAccessor(json, buffers, p.attributes.TEXCOORD_0) as Float32Array) : undefined,\n mode: mode === 0 ? 'points' : mode >= 1 && mode <= 3 ? 'lines' : 'triangles',\n };\n if (p.indices !== undefined) {\n let idx = readAccessor(json, buffers, p.indices, false) as Uint32Array | Uint16Array | Uint8Array;\n if (mode === 5 || mode === 6) idx = toTriangles(Uint32Array.from(idx), mode);\n g.indices = idx instanceof Uint8Array || (idx instanceof Uint32Array && g.positions.length / 3 <= 65535) ? Uint16Array.from(idx) : (idx as Uint16Array | Uint32Array);\n } else if (mode === 5 || mode === 6) g.indices = toTriangles(Uint32Array.from({ length: g.positions.length / 3 }, (_, i) => i), mode);\n if (!g.normals && g.mode === 'triangles') g = computeNormals(g);\n return { geometry: g, material: p.material !== undefined ? mats[p.material] : standardMaterial({ metallic: 0, roughness: 0.6 }) };\n })\n );\n const nodes = (json.nodes || []).map((n, i) => {\n const node = new GlNode(n.name || `node${i}`, n.mesh !== undefined ? meshes[n.mesh] : null);\n if (n.matrix) node.matrix = new Float32Array(n.matrix);\n if (n.translation) node.position = n.translation.slice(0, 3) as Vec3;\n if (n.rotation) node.rotation = n.rotation.slice(0, 4) as Quat;\n if (n.scale) node.scale = n.scale.slice(0, 3) as Vec3;\n node.extras.gltfIndex = i;\n return node;\n });\n (json.nodes || []).forEach((n, i) => (n.children || []).forEach((c) => nodes[i].add(nodes[c])));\n const root = new GlNode('gltf');\n const sc = json.scenes?.[sceneIndex ?? json.scene ?? 0];\n const tops = sc?.nodes ?? nodes.map((_, i) => i).filter((i) => !nodes[i].parent);\n tops.forEach((i) => root.add(nodes[i]));\n root.extras = { gltf: json, nodes };\n return root;\n}\n\nconst dataUri = (u: string): Uint8Array => {\n const [, meta, data] = /^data:([^,]*),(.*)$/s.exec(u) || [];\n if (meta === undefined) throw new Error('[motionary] format-gltf: bad data URI');\n if (/;base64/.test(meta)) {\n const s = atob(data);\n return Uint8Array.from(s, (c) => c.charCodeAt(0));\n }\n return new TextEncoder().encode(decodeURIComponent(data));\n};\n\n/** Load a `.gltf` / `.glb` (URL or bytes) with its buffers and images and build a node tree. */\nexport async function loadGltf(src: string | ArrayBuffer | Uint8Array, o: { baseUrl?: string; scene?: number } = {}): Promise<GlNode> {\n const base = o.baseUrl || (typeof src === 'string' ? new URL(src, typeof location !== 'undefined' ? location.href : 'file:///').href : typeof location !== 'undefined' ? location.href : 'file:///');\n const get = async (u: string) => {\n if (u.startsWith('data:')) return dataUri(u);\n const r = await fetch(new URL(u, base).href);\n if (!r.ok) throw new Error(`[motionary] format-gltf: could not load ${u} (${r.status})`);\n return new Uint8Array(await r.arrayBuffer());\n };\n const bytes = typeof src === 'string' ? await get(src) : src instanceof Uint8Array ? src : new Uint8Array(src);\n let json: GltfJson, bin: Uint8Array | null = null;\n if (bytes[0] === 0x67 && bytes[1] === 0x6c && bytes[2] === 0x54 && bytes[3] === 0x46) ({ json, bin } = parseGlb(bytes));\n else json = JSON.parse(new TextDecoder().decode(bytes));\n const buffers = await Promise.all((json.buffers || []).map((b, i) => (b.uri ? get(b.uri) : i === 0 && bin ? Promise.resolve(bin) : Promise.reject(new Error('[motionary] format-gltf: buffer without data')))));\n const images: GltfImages = {};\n await Promise.all((json.images || []).map(async (im, i) => {\n let data: Uint8Array;\n if (im.bufferView !== undefined) {\n const bv = json.bufferViews![im.bufferView];\n data = buffers[bv.buffer].subarray(bv.byteOffset || 0, (bv.byteOffset || 0) + bv.byteLength);\n } else if (im.uri) data = await get(im.uri);\n else return;\n images[i] = await createImageBitmap(new Blob([data as BlobPart], { type: im.mimeType || (im.uri && /\\.jpe?g$/i.test(im.uri) ? 'image/jpeg' : 'image/png') }));\n }));\n return gltfToNode(json, buffers, images, o.scene);\n}\n\nexport interface FormatGltfApi {\n parseGlb: typeof parseGlb;\n readAccessor: typeof readAccessor;\n gltfToNode: typeof gltfToNode;\n loadGltf: typeof loadGltf;\n SUPPORTED_EXTENSIONS: typeof SUPPORTED_EXTENSIONS;\n}\n\n/** The module object for `use(formatGltf)` (needs `gl`). */\nexport const formatGltf: RuntimeModule<FormatGltfApi> = { id: 'format-gltf', version: RUNTIME_VERSION, requires: ['core', 'gl'], api: { parseGlb, readAccessor, gltfToNode, loadGltf, SUPPORTED_EXTENSIONS } };\n"],"names":["standardMaterial","texture","computeNormals","GlNode","RUNTIME_VERSION"],"mappings":";;;;;AAAA;;;;;;;;;;;;;;;;;;AAkBG;AAsBH;MACa,oBAAoB,GAAG,CAAC,iCAAiC,EAAE,qBAAqB;AAE7F;AACM,SAAU,QAAQ,CAAC,KAA+B,EAAA;AACtD,IAAA,MAAM,CAAC,GAAG,KAAK,YAAY,UAAU,GAAG,KAAK,GAAG,IAAI,UAAU,CAAC,KAAK,CAAC;AACrE,IAAA,MAAM,CAAC,GAAG,IAAI,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC,UAAU,CAAC;IAC5D,IAAI,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,UAAU;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC;IACnG,IAAI,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,KA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AAI,IAAI,CAAC,CAAC,IAAgB,CAAC,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,QAAQ,KAAK,EAAE,CAAC,GAAG,IAAI,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,YAAY,GAAG,WAAW,CAAC,EAAE,CAAC,CAAC;IAC/J,CAAC,CAAC,CAAC;AACH,IAAA,OAAO,UAAU,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC;AACnD;AAUA;AACO,MAAM,UAAU,GAAiC,EAAE,EAAE,EAAE,aAAa,EAAE,OAAO,EAAEC,wBAAe,EAAE,QAAQ,EAAE,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,EAAE,QAAQ,EAAE,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,oBAAoB,EAAE;;;;;;;"}
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
/** A runtime module: `{ id, version, api }`, registered with `use()`. */
|
|
2
|
+
interface RuntimeModule<A = unknown> {
|
|
3
|
+
/** Module id: 'core', 'format-css', 'scroll', … (import path `motionary/runtime/<id>`). */
|
|
4
|
+
id: string;
|
|
5
|
+
version: string;
|
|
6
|
+
/** Other modules this one needs (registered first by `use()` callers). */
|
|
7
|
+
requires?: string[];
|
|
8
|
+
/** The module's public API (what `requireModule(id)` returns). */
|
|
9
|
+
api: A;
|
|
10
|
+
/** Optional one-time setup, called on first registration. */
|
|
11
|
+
setup?(registry: RuntimeRegistry): void;
|
|
12
|
+
}
|
|
13
|
+
interface RuntimeRegistry {
|
|
14
|
+
version: string;
|
|
15
|
+
modules: Map<string, RuntimeModule>;
|
|
16
|
+
/** Shared per-page state slots (the ticker lives here). */
|
|
17
|
+
slots: Record<string, unknown>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* `motionary/runtime/gl` (10.5) — a small WebGL2 scene renderer written for
|
|
22
|
+
* Motionary (not a Three.js clone; own API, own shaders):
|
|
23
|
+
*
|
|
24
|
+
* - **math** (`mat4`, quaternions — column-major `Float32Array`s), pure;
|
|
25
|
+
* - **scene graph**: `GlNode` (position / rotation quaternion / scale,
|
|
26
|
+
* children, optional mesh), `Camera` (perspective, `lookAt`), lights
|
|
27
|
+
* (`ambient`, up to 4 directional / point), `bounds()` + `frameNode()`;
|
|
28
|
+
* - **geometry** builders (`box`, `plane`, `sphere`, `torus`) and custom
|
|
29
|
+
* geometry from typed arrays (indexed 16 / 32-bit or not);
|
|
30
|
+
* - **materials**: `standard` (metallic-roughness PBR approximation, base
|
|
31
|
+
* colour texture, emissive, ACES-free Reinhard tone mapping, sRGB),
|
|
32
|
+
* `unlit`, and `shader` (your GLSL ES 3.00 fragment with the standard
|
|
33
|
+
* varyings + your uniforms);
|
|
34
|
+
* - **textures** from images, canvases, bitmaps and **videos** (updated per
|
|
35
|
+
* decoded frame with `requestVideoFrameCallback`; `scrubVideo()` seeks a
|
|
36
|
+
* video from a 0–1 progress, e.g. a scroll scene);
|
|
37
|
+
* - `orbitControls()` — drag / wheel / pinch / arrow keys, damping, optional
|
|
38
|
+
* auto-rotate (off under reduced motion).
|
|
39
|
+
*
|
|
40
|
+
* Math, geometry and the scene graph are pure (SSR / workers); rendering
|
|
41
|
+
* needs WebGL2 (`createRenderer()` throws a clear error without it). Model
|
|
42
|
+
* loaders live in `motionary/runtime/format-gltf` and `format-obj`.
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
type Vec3 = [number, number, number];
|
|
46
|
+
type Quat = [number, number, number, number];
|
|
47
|
+
type Mat4 = Float32Array;
|
|
48
|
+
interface Geometry {
|
|
49
|
+
positions: Float32Array;
|
|
50
|
+
normals?: Float32Array;
|
|
51
|
+
uvs?: Float32Array;
|
|
52
|
+
indices?: Uint16Array | Uint32Array;
|
|
53
|
+
/** 'triangles' (default), 'lines', 'points'. */
|
|
54
|
+
mode?: 'triangles' | 'lines' | 'points';
|
|
55
|
+
/** Renderer cache. */
|
|
56
|
+
_gpu?: unknown;
|
|
57
|
+
}
|
|
58
|
+
interface GlTexture {
|
|
59
|
+
source: TexImageSource | {
|
|
60
|
+
width: number;
|
|
61
|
+
height: number;
|
|
62
|
+
data: Uint8Array | Uint8ClampedArray;
|
|
63
|
+
};
|
|
64
|
+
/** sRGB colour data (default true for colour maps). */
|
|
65
|
+
srgb?: boolean;
|
|
66
|
+
repeat?: boolean;
|
|
67
|
+
flipY?: boolean;
|
|
68
|
+
/** Re-upload every frame a new video frame is ready. */
|
|
69
|
+
video?: boolean;
|
|
70
|
+
needsUpdate?: boolean;
|
|
71
|
+
_gpu?: unknown;
|
|
72
|
+
}
|
|
73
|
+
interface Material {
|
|
74
|
+
type: 'standard' | 'unlit' | 'shader';
|
|
75
|
+
/** Linear RGBA multiplier (sRGB input converted by the shader). */
|
|
76
|
+
color: [number, number, number, number];
|
|
77
|
+
map?: GlTexture | null;
|
|
78
|
+
metallic: number;
|
|
79
|
+
roughness: number;
|
|
80
|
+
emissive: Vec3;
|
|
81
|
+
doubleSided?: boolean;
|
|
82
|
+
transparent?: boolean;
|
|
83
|
+
wireframe?: boolean;
|
|
84
|
+
/** 'shader' materials: GLSL ES 3.00 fragment body + uniforms. */
|
|
85
|
+
fragment?: string;
|
|
86
|
+
uniforms?: Record<string, number | number[] | Float32Array | GlTexture>;
|
|
87
|
+
_gpu?: unknown;
|
|
88
|
+
}
|
|
89
|
+
interface Mesh {
|
|
90
|
+
geometry: Geometry;
|
|
91
|
+
material: Material;
|
|
92
|
+
}
|
|
93
|
+
declare class GlNode {
|
|
94
|
+
name: string;
|
|
95
|
+
position: Vec3;
|
|
96
|
+
rotation: Quat;
|
|
97
|
+
scale: Vec3;
|
|
98
|
+
/** Set to use a fixed local matrix instead of position / rotation / scale (glTF `matrix`). */
|
|
99
|
+
matrix: Mat4 | null;
|
|
100
|
+
children: GlNode[];
|
|
101
|
+
parent: GlNode | null;
|
|
102
|
+
mesh: Mesh | Mesh[] | null;
|
|
103
|
+
visible: boolean;
|
|
104
|
+
/** Free-form data (loaders put source info here). */
|
|
105
|
+
extras: Record<string, unknown>;
|
|
106
|
+
readonly world: Mat4;
|
|
107
|
+
constructor(name?: string, mesh?: Mesh | Mesh[] | null);
|
|
108
|
+
add(...nodes: GlNode[]): this;
|
|
109
|
+
remove(n: GlNode): void;
|
|
110
|
+
setEuler(x: number, y: number, z: number): this;
|
|
111
|
+
local(): Mat4;
|
|
112
|
+
/** Recompute world matrices of this subtree. */
|
|
113
|
+
updateWorld(parent?: Mat4): void;
|
|
114
|
+
traverse(fn: (n: GlNode) => void): void;
|
|
115
|
+
find(name: string): GlNode | null;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* `motionary/runtime/format-gltf` (10.5) — glTF 2.0 / GLB loader for
|
|
120
|
+
* `motionary/runtime/gl` (own implementation):
|
|
121
|
+
*
|
|
122
|
+
* - `.gltf` (JSON + external or `data:` buffers / images) and `.glb`
|
|
123
|
+
* (binary container: JSON + BIN chunks);
|
|
124
|
+
* - scenes and the node hierarchy (TRS or `matrix`), meshes with several
|
|
125
|
+
* primitives (POSITION, NORMAL, TEXCOORD_0, indices; any component type,
|
|
126
|
+
* normalised integers, interleaved `byteStride`; modes points, lines,
|
|
127
|
+
* triangles, strips, fans);
|
|
128
|
+
* - PBR metallic-roughness materials (base colour factor + texture,
|
|
129
|
+
* metallic / roughness factors, emissive factor, alpha modes, double-sided);
|
|
130
|
+
* images from buffer views or URIs (decoded with `createImageBitmap`);
|
|
131
|
+
* - files that *require* an extension we do not implement (e.g. Draco /
|
|
132
|
+
* KTX2 compression) fail with a clear error naming it.
|
|
133
|
+
*
|
|
134
|
+
* Skins, morph targets and animations arrive in 10.8. `parseGlb()` /
|
|
135
|
+
* `gltfToNode()` with an `images` override are pure (SSR / workers).
|
|
136
|
+
*/
|
|
137
|
+
|
|
138
|
+
interface GltfJson {
|
|
139
|
+
asset: {
|
|
140
|
+
version: string;
|
|
141
|
+
generator?: string;
|
|
142
|
+
};
|
|
143
|
+
scene?: number;
|
|
144
|
+
scenes?: {
|
|
145
|
+
nodes?: number[];
|
|
146
|
+
name?: string;
|
|
147
|
+
}[];
|
|
148
|
+
nodes?: {
|
|
149
|
+
name?: string;
|
|
150
|
+
children?: number[];
|
|
151
|
+
mesh?: number;
|
|
152
|
+
matrix?: number[];
|
|
153
|
+
translation?: number[];
|
|
154
|
+
rotation?: number[];
|
|
155
|
+
scale?: number[];
|
|
156
|
+
skin?: number;
|
|
157
|
+
camera?: number;
|
|
158
|
+
}[];
|
|
159
|
+
meshes?: {
|
|
160
|
+
name?: string;
|
|
161
|
+
primitives: {
|
|
162
|
+
attributes: Record<string, number>;
|
|
163
|
+
indices?: number;
|
|
164
|
+
material?: number;
|
|
165
|
+
mode?: number;
|
|
166
|
+
targets?: Record<string, number>[];
|
|
167
|
+
}[];
|
|
168
|
+
weights?: number[];
|
|
169
|
+
}[];
|
|
170
|
+
accessors?: {
|
|
171
|
+
bufferView?: number;
|
|
172
|
+
byteOffset?: number;
|
|
173
|
+
componentType: number;
|
|
174
|
+
normalized?: boolean;
|
|
175
|
+
count: number;
|
|
176
|
+
type: string;
|
|
177
|
+
min?: number[];
|
|
178
|
+
max?: number[];
|
|
179
|
+
sparse?: unknown;
|
|
180
|
+
}[];
|
|
181
|
+
bufferViews?: {
|
|
182
|
+
buffer: number;
|
|
183
|
+
byteOffset?: number;
|
|
184
|
+
byteLength: number;
|
|
185
|
+
byteStride?: number;
|
|
186
|
+
}[];
|
|
187
|
+
buffers?: {
|
|
188
|
+
uri?: string;
|
|
189
|
+
byteLength: number;
|
|
190
|
+
}[];
|
|
191
|
+
materials?: {
|
|
192
|
+
name?: string;
|
|
193
|
+
pbrMetallicRoughness?: {
|
|
194
|
+
baseColorFactor?: number[];
|
|
195
|
+
baseColorTexture?: {
|
|
196
|
+
index: number;
|
|
197
|
+
};
|
|
198
|
+
metallicFactor?: number;
|
|
199
|
+
roughnessFactor?: number;
|
|
200
|
+
};
|
|
201
|
+
emissiveFactor?: number[];
|
|
202
|
+
alphaMode?: string;
|
|
203
|
+
doubleSided?: boolean;
|
|
204
|
+
extensions?: Record<string, any>;
|
|
205
|
+
}[];
|
|
206
|
+
textures?: {
|
|
207
|
+
source?: number;
|
|
208
|
+
sampler?: number;
|
|
209
|
+
}[];
|
|
210
|
+
images?: {
|
|
211
|
+
uri?: string;
|
|
212
|
+
bufferView?: number;
|
|
213
|
+
mimeType?: string;
|
|
214
|
+
}[];
|
|
215
|
+
extensionsUsed?: string[];
|
|
216
|
+
extensionsRequired?: string[];
|
|
217
|
+
animations?: unknown[];
|
|
218
|
+
skins?: unknown[];
|
|
219
|
+
}
|
|
220
|
+
/** Extensions this loader understands (others that a file *requires* make it fail clearly). */
|
|
221
|
+
declare const SUPPORTED_EXTENSIONS: string[];
|
|
222
|
+
/** Split a GLB container into its JSON and BIN chunk (pure). */
|
|
223
|
+
declare function parseGlb(input: ArrayBuffer | Uint8Array): {
|
|
224
|
+
json: GltfJson;
|
|
225
|
+
bin: Uint8Array | null;
|
|
226
|
+
};
|
|
227
|
+
/** Read an accessor into a flat typed array (floats are de-interleaved; normalised ints become floats). */
|
|
228
|
+
declare function readAccessor(json: GltfJson, buffers: Uint8Array[], index: number, asFloat?: boolean): Float32Array | Uint16Array | Uint32Array | Uint8Array;
|
|
229
|
+
interface GltfImages {
|
|
230
|
+
/** Decoded images by glTF image index (pass your own for SSR / tests). */
|
|
231
|
+
[index: number]: TexImageSource | undefined;
|
|
232
|
+
}
|
|
233
|
+
/** Build a runtime/gl node tree from parsed glTF (pure, given buffers and decoded images). */
|
|
234
|
+
declare function gltfToNode(json: GltfJson, buffers: Uint8Array[], images?: GltfImages, sceneIndex?: number): GlNode;
|
|
235
|
+
/** Load a `.gltf` / `.glb` (URL or bytes) with its buffers and images and build a node tree. */
|
|
236
|
+
declare function loadGltf(src: string | ArrayBuffer | Uint8Array, o?: {
|
|
237
|
+
baseUrl?: string;
|
|
238
|
+
scene?: number;
|
|
239
|
+
}): Promise<GlNode>;
|
|
240
|
+
interface FormatGltfApi {
|
|
241
|
+
parseGlb: typeof parseGlb;
|
|
242
|
+
readAccessor: typeof readAccessor;
|
|
243
|
+
gltfToNode: typeof gltfToNode;
|
|
244
|
+
loadGltf: typeof loadGltf;
|
|
245
|
+
SUPPORTED_EXTENSIONS: typeof SUPPORTED_EXTENSIONS;
|
|
246
|
+
}
|
|
247
|
+
/** The module object for `use(formatGltf)` (needs `gl`). */
|
|
248
|
+
declare const formatGltf: RuntimeModule<FormatGltfApi>;
|
|
249
|
+
|
|
250
|
+
export { SUPPORTED_EXTENSIONS, formatGltf, gltfToNode, loadGltf, parseGlb, readAccessor };
|
|
251
|
+
export type { FormatGltfApi, GltfImages, GltfJson };
|