@ifc-lite/cache 3.3.0 → 3.4.2
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/README.md +23 -0
- package/dist/glb-accessor.d.ts +6 -0
- package/dist/glb-accessor.d.ts.map +1 -0
- package/dist/glb-accessor.js +157 -0
- package/dist/glb-accessor.js.map +1 -0
- package/dist/glb-images.d.ts +6 -0
- package/dist/glb-images.d.ts.map +1 -0
- package/dist/glb-images.js +91 -0
- package/dist/glb-images.js.map +1 -0
- package/dist/glb-transform.d.ts +15 -0
- package/dist/glb-transform.d.ts.map +1 -0
- package/dist/glb-transform.js +59 -0
- package/dist/glb-transform.js.map +1 -0
- package/dist/glb-types.d.ts +111 -0
- package/dist/glb-types.d.ts.map +1 -0
- package/dist/glb-types.js +5 -0
- package/dist/glb-types.js.map +1 -0
- package/dist/glb.d.ts +1 -71
- package/dist/glb.d.ts.map +1 -1
- package/dist/glb.js +61 -192
- package/dist/glb.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/sections/appearance-provenance.d.ts +11 -0
- package/dist/sections/appearance-provenance.d.ts.map +1 -0
- package/dist/sections/appearance-provenance.js +113 -0
- package/dist/sections/appearance-provenance.js.map +1 -0
- package/dist/sections/geometry-chunks.d.ts +3 -30
- package/dist/sections/geometry-chunks.d.ts.map +1 -1
- package/dist/sections/geometry-chunks.js +43 -7
- package/dist/sections/geometry-chunks.js.map +1 -1
- package/dist/sections/geometry.d.ts +6 -5
- package/dist/sections/geometry.d.ts.map +1 -1
- package/dist/sections/geometry.js +12 -7
- package/dist/sections/geometry.js.map +1 -1
- package/dist/sections/relationships.js +2 -0
- package/dist/sections/relationships.js.map +1 -1
- package/dist/types.d.ts +6 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +4 -1
- package/dist/types.js.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -89,6 +89,10 @@ The cache keys models by the xxHash64 of the source IFC, and `reader.validate(ca
|
|
|
89
89
|
|
|
90
90
|
The binary layout is versioned via the exported `FORMAT_VERSION` constant. Readers accept entries written by the current or an older format version (with backward-compatible decoding, e.g. the per-mesh geometry-class byte added in v5) and reject entries written by a newer one, so mixed-version deployments fail safely toward a cold parse.
|
|
91
91
|
|
|
92
|
+
Version 19 preserves explicitly supplied canonical `MeshData.appearanceSource` provenance. Fresh canonical meshes store an identity marker; fragmented or expanded meshes reference a geometry-header source-index pool, shared across spatial chunks, plus their corner mapping. Restored metadata points to the restored mesh indices, preserving the topology identity fence required by appearance preview. Invalid identities, source lengths, pool references and corner ranges fail cache reading/writing instead of enabling an unsafe preview. Unmarked meshes remain unmarked; old records never acquire inferred canonical identity.
|
|
93
|
+
|
|
94
|
+
The viewer includes `FORMAT_VERSION` in its cache key, so older entries reparse once and receive real provenance from the canonical geometry pipeline. Direct readers can still decode v13–v18 records for viewing, with appearance provenance absent. When reading an older geometry header directly, pass its version as the second argument to `readGeometryHeadV13(reader, version)`; it defaults to the current format. Keep the returned chunk metadata when calling `decodeGeometryChunk`, since it carries the shared source-index pool. This does not add UV/image caching: texture-carrying viewer models retain their existing cache bypass.
|
|
95
|
+
|
|
92
96
|
## Source-hash contract (and `omitSourceHash`)
|
|
93
97
|
|
|
94
98
|
By default the header stores the full-file `xxhash64` of the source in `sourceHash`, and `reader.validate()` / `read({ sourceBuffer })` compare against it. Hashing a large source can be a multi-second main-thread cost, so a caller that validates the source **another way** (e.g. an application-layer content hash plus a file modified-time guard, as the viewer's source-decoupled cache tier does) can pass `omitSourceHash: true`:
|
|
@@ -136,3 +140,22 @@ Serialization borrows valid sorted columns synchronously, preserving stable dupl
|
|
|
136
140
|
`BinaryCacheWriter.write` accepts `compressGeometryChunksInWorker: true` to run geometry chunk compression in one lazily created browser module worker. The viewer enables it to keep codec work off the UI thread. The default is `false`, preserving workerless SDK and Node use. The existing compression size floor and four-chunk concurrency limit remain in effect; disabling `compressGeometryChunks` creates no worker. Cache format, chunk order, compressed-versus-raw selection and readers are unchanged.
|
|
137
141
|
|
|
138
142
|
The browser application must bundle the package worker asset and permit module workers. Worker startup, codec and transport failures reject the cache write; there is no silent main-thread retry. Only newly serialized chunk buffers cross the worker boundary, and the worker terminates after geometry serialization succeeds or fails. Source/model data stay with the caller. This moves compression CPU rather than eliminating it; include cache completion when measuring cold loads.
|
|
143
|
+
|
|
144
|
+
### Textured GLB capture import
|
|
145
|
+
|
|
146
|
+
`parseGLBToMeshData` and `loadGLBToMeshData` preserve base-colour `TEXCOORD_0`
|
|
147
|
+
coordinates (including normalized integer UVs and `KHR_texture_transform`),
|
|
148
|
+
texture references, node TRS/matrices and mirrored winding. UV vertices remain
|
|
149
|
+
separate across seams. Node translation stays in the double-precision `origin`.
|
|
150
|
+
Use `parseGLBImageResources(parsed.json, parsed.bin)` to obtain original encoded
|
|
151
|
+
PNG/JPEG images keyed by each mesh's `textureRef.url`. Decode these at the host
|
|
152
|
+
boundary; this package never allocates browser image objects. Embedded PNG/JPEG
|
|
153
|
+
magic bytes must match the declared MIME type before geometry or resources are
|
|
154
|
+
returned; MIME labels cannot bypass the host opacity checks.
|
|
155
|
+
|
|
156
|
+
This is opaque captured-albedo import. Embedded base-colour PNG/JPEG images and
|
|
157
|
+
repeat/clamp samplers are supported. External images/buffers, other UV sets,
|
|
158
|
+
mirrored repeat, sparse accessors, compression, skinning/morphs, vertex colours,
|
|
159
|
+
additional material maps, and textured MASK/BLEND produce explicit errors.
|
|
160
|
+
The viewer also refuses transparent image pixels, retains original bytes with
|
|
161
|
+
the model, and releases images on removal. It does not claim full PBR fidelity.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { GLTFDocument } from './glb-types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Read accessor data as a typed array
|
|
4
|
+
*/
|
|
5
|
+
export declare function readAccessorData(gltf: GLTFDocument, bin: Uint8Array, accessorIdx: number, expectedType?: string): Float32Array | Uint32Array | Uint16Array | Uint8Array;
|
|
6
|
+
//# sourceMappingURL=glb-accessor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"glb-accessor.d.ts","sourceRoot":"","sources":["../src/glb-accessor.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAoDnD;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,YAAY,EAClB,GAAG,EAAE,UAAU,EACf,WAAW,EAAE,MAAM,EACnB,YAAY,CAAC,EAAE,MAAM,GACpB,YAAY,GAAG,WAAW,GAAG,WAAW,GAAG,UAAU,CAkHvD"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
2
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
4
|
+
// Component types
|
|
5
|
+
const COMPONENT_BYTE = 5120;
|
|
6
|
+
const COMPONENT_UNSIGNED_BYTE = 5121;
|
|
7
|
+
const COMPONENT_SHORT = 5122;
|
|
8
|
+
const COMPONENT_UNSIGNED_SHORT = 5123;
|
|
9
|
+
const COMPONENT_UNSIGNED_INT = 5125;
|
|
10
|
+
const COMPONENT_FLOAT = 5126;
|
|
11
|
+
/**
|
|
12
|
+
* Get the byte size for a glTF component type
|
|
13
|
+
*/
|
|
14
|
+
function getComponentSize(componentType) {
|
|
15
|
+
switch (componentType) {
|
|
16
|
+
case COMPONENT_BYTE:
|
|
17
|
+
case COMPONENT_UNSIGNED_BYTE:
|
|
18
|
+
return 1;
|
|
19
|
+
case COMPONENT_SHORT:
|
|
20
|
+
case COMPONENT_UNSIGNED_SHORT:
|
|
21
|
+
return 2;
|
|
22
|
+
case COMPONENT_UNSIGNED_INT:
|
|
23
|
+
case COMPONENT_FLOAT:
|
|
24
|
+
return 4;
|
|
25
|
+
default:
|
|
26
|
+
throw new Error(`Unknown component type: ${componentType}`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Get the number of components for an accessor type
|
|
31
|
+
*/
|
|
32
|
+
function getComponentCount(type) {
|
|
33
|
+
switch (type) {
|
|
34
|
+
case 'SCALAR':
|
|
35
|
+
return 1;
|
|
36
|
+
case 'VEC2':
|
|
37
|
+
return 2;
|
|
38
|
+
case 'VEC3':
|
|
39
|
+
return 3;
|
|
40
|
+
case 'VEC4':
|
|
41
|
+
return 4;
|
|
42
|
+
case 'MAT2':
|
|
43
|
+
return 4;
|
|
44
|
+
case 'MAT3':
|
|
45
|
+
return 9;
|
|
46
|
+
case 'MAT4':
|
|
47
|
+
return 16;
|
|
48
|
+
default:
|
|
49
|
+
throw new Error(`Unknown accessor type: ${type}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Read accessor data as a typed array
|
|
54
|
+
*/
|
|
55
|
+
export function readAccessorData(gltf, bin, accessorIdx, expectedType) {
|
|
56
|
+
const accessor = gltf.accessors?.[accessorIdx];
|
|
57
|
+
if (!accessor) {
|
|
58
|
+
throw new Error(`Accessor ${accessorIdx} not found`);
|
|
59
|
+
}
|
|
60
|
+
if (expectedType && accessor.type !== expectedType)
|
|
61
|
+
throw new Error(`GLB: accessor ${accessorIdx} must be ${expectedType}`);
|
|
62
|
+
if (accessor.sparse)
|
|
63
|
+
throw new Error('GLB: sparse accessors are not supported');
|
|
64
|
+
const bufferView = gltf.bufferViews?.[accessor.bufferView];
|
|
65
|
+
if (!bufferView) {
|
|
66
|
+
throw new Error(`BufferView ${accessor.bufferView} not found`);
|
|
67
|
+
}
|
|
68
|
+
if (bufferView.buffer !== 0 || gltf.buffers?.[0]?.uri)
|
|
69
|
+
throw new Error('GLB: external buffers are not supported');
|
|
70
|
+
const componentSize = getComponentSize(accessor.componentType);
|
|
71
|
+
const componentCount = getComponentCount(accessor.type);
|
|
72
|
+
const elementSize = componentSize * componentCount;
|
|
73
|
+
const byteStride = bufferView.byteStride ?? elementSize;
|
|
74
|
+
const bufferOffset = (bufferView.byteOffset ?? 0) + (accessor.byteOffset ?? 0);
|
|
75
|
+
// `accessor.count` comes straight from the (untrusted) GLB JSON chunk and
|
|
76
|
+
// is REQUIRED by the glTF spec, but nothing here enforced that at runtime:
|
|
77
|
+
// a missing/non-numeric `count` makes it `undefined`/NaN, and `NaN * x` is
|
|
78
|
+
// NaN. Every arithmetic bounds comparison below (`< 0`, `> bin.byteLength`)
|
|
79
|
+
// is false against NaN, so the bounds check was silently bypassed rather
|
|
80
|
+
// than rejecting the malformed accessor. Control then fell through to a
|
|
81
|
+
// typed-array constructor built from that same NaN count, which coerces to
|
|
82
|
+
// an element count of 0 (ToIndex(NaN) === 0) — producing a silently EMPTY
|
|
83
|
+
// mesh reported as a successful import instead of throwing.
|
|
84
|
+
if (!Number.isInteger(accessor.count) || accessor.count < 0) {
|
|
85
|
+
throw new Error(`GLB: accessor ${accessorIdx} has an invalid count: ${accessor.count}`);
|
|
86
|
+
}
|
|
87
|
+
// Bounds-check the full byte range this accessor claims against the actual
|
|
88
|
+
// BIN chunk BEFORE slicing/constructing anything. `accessor.count` /
|
|
89
|
+
// `byteOffset` come straight from the (untrusted) GLB JSON chunk; without
|
|
90
|
+
// this, `bin.slice()` below silently CLAMPS on a truncated/malformed BIN
|
|
91
|
+
// (fewer bytes than asked), and the typed-array constructor that follows
|
|
92
|
+
// still requests the ORIGINALLY declared element count against that
|
|
93
|
+
// shorter buffer — a raw `RangeError: Invalid typed array length` (or
|
|
94
|
+
// "range consisting of offset and length are out of bounds", depending on
|
|
95
|
+
// engine) escapes instead of a diagnosable domain error.
|
|
96
|
+
const neededBytes = byteStride === elementSize
|
|
97
|
+
? accessor.count * elementSize
|
|
98
|
+
: accessor.count > 0
|
|
99
|
+
? (accessor.count - 1) * byteStride + elementSize
|
|
100
|
+
: 0;
|
|
101
|
+
if (![bufferOffset, neededBytes, byteStride, bufferView.byteLength, accessor.byteOffset ?? 0, bufferView.byteOffset ?? 0].every(Number.isSafeInteger) || byteStride < elementSize || (accessor.byteOffset ?? 0) < 0 || (bufferView.byteOffset ?? 0) < 0 || (accessor.byteOffset ?? 0) + neededBytes > bufferView.byteLength || bufferOffset < 0 || neededBytes < 0 || bufferOffset + neededBytes > bin.byteLength) {
|
|
102
|
+
throw new Error(`GLB: accessor ${accessorIdx} reads bytes [${bufferOffset}, ${bufferOffset + neededBytes}) ` +
|
|
103
|
+
`but the BIN chunk is only ${bin.byteLength} bytes`);
|
|
104
|
+
}
|
|
105
|
+
// If data is tightly packed, we can use a view directly
|
|
106
|
+
if (byteStride === elementSize) {
|
|
107
|
+
const byteLength = accessor.count * elementSize;
|
|
108
|
+
const slice = bin.slice(bufferOffset, bufferOffset + byteLength);
|
|
109
|
+
switch (accessor.componentType) {
|
|
110
|
+
case COMPONENT_FLOAT:
|
|
111
|
+
return new Float32Array(slice.buffer, slice.byteOffset, accessor.count * componentCount);
|
|
112
|
+
case COMPONENT_UNSIGNED_INT:
|
|
113
|
+
return new Uint32Array(slice.buffer, slice.byteOffset, accessor.count * componentCount);
|
|
114
|
+
case COMPONENT_UNSIGNED_SHORT:
|
|
115
|
+
return new Uint16Array(slice.buffer, slice.byteOffset, accessor.count * componentCount);
|
|
116
|
+
case COMPONENT_UNSIGNED_BYTE:
|
|
117
|
+
return slice;
|
|
118
|
+
default:
|
|
119
|
+
throw new Error(`Unsupported component type for reading: ${accessor.componentType}`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
// Handle strided data
|
|
123
|
+
const result = accessor.componentType === COMPONENT_FLOAT
|
|
124
|
+
? new Float32Array(accessor.count * componentCount)
|
|
125
|
+
: accessor.componentType === COMPONENT_UNSIGNED_INT
|
|
126
|
+
? new Uint32Array(accessor.count * componentCount)
|
|
127
|
+
: accessor.componentType === COMPONENT_UNSIGNED_SHORT
|
|
128
|
+
? new Uint16Array(accessor.count * componentCount)
|
|
129
|
+
: new Uint8Array(accessor.count * componentCount);
|
|
130
|
+
const dataView = new DataView(bin.buffer, bin.byteOffset, bin.byteLength);
|
|
131
|
+
for (let i = 0; i < accessor.count; i++) {
|
|
132
|
+
const elementOffset = bufferOffset + i * byteStride;
|
|
133
|
+
for (let c = 0; c < componentCount; c++) {
|
|
134
|
+
const byteOffset = elementOffset + c * componentSize;
|
|
135
|
+
let value;
|
|
136
|
+
switch (accessor.componentType) {
|
|
137
|
+
case COMPONENT_FLOAT:
|
|
138
|
+
value = dataView.getFloat32(byteOffset, true);
|
|
139
|
+
break;
|
|
140
|
+
case COMPONENT_UNSIGNED_INT:
|
|
141
|
+
value = dataView.getUint32(byteOffset, true);
|
|
142
|
+
break;
|
|
143
|
+
case COMPONENT_UNSIGNED_SHORT:
|
|
144
|
+
value = dataView.getUint16(byteOffset, true);
|
|
145
|
+
break;
|
|
146
|
+
case COMPONENT_UNSIGNED_BYTE:
|
|
147
|
+
value = dataView.getUint8(byteOffset);
|
|
148
|
+
break;
|
|
149
|
+
default:
|
|
150
|
+
throw new Error(`Unsupported component type: ${accessor.componentType}`);
|
|
151
|
+
}
|
|
152
|
+
result[i * componentCount + c] = value;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return result;
|
|
156
|
+
}
|
|
157
|
+
//# sourceMappingURL=glb-accessor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"glb-accessor.js","sourceRoot":"","sources":["../src/glb-accessor.ts"],"names":[],"mappings":"AAAA;;+DAE+D;AAG/D,kBAAkB;AAClB,MAAM,cAAc,GAAG,IAAI,CAAC;AAC5B,MAAM,uBAAuB,GAAG,IAAI,CAAC;AACrC,MAAM,eAAe,GAAG,IAAI,CAAC;AAC7B,MAAM,wBAAwB,GAAG,IAAI,CAAC;AACtC,MAAM,sBAAsB,GAAG,IAAI,CAAC;AACpC,MAAM,eAAe,GAAG,IAAI,CAAC;AAE7B;;GAEG;AACH,SAAS,gBAAgB,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AAG,QAAQ,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC;QACxC,MAAM,aAAa,GAAG,YAAY,GAAG,CAAC,GAAG,UAAU,CAAC;QACpD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,cAAc,EAAE,CAAC,EAAE,EAAE,CAAC;YACxC,MAAM,UAAU,GAAG,aAAa,GAAG,CAAC,GAAG,aAAa,CAAC;YACrD,IAAI,KAAa,CAAC;YAElB,QAAQ,QAAQ,CAAC,aAAa,EAAE,CAAC;gBAC/B,KAAK,eAAe;oBAClB,KAAK,GAAG,QAAQ,CAAC,UAAU,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;oBAC9C,MAAM;gBACR,KAAK,sBAAsB;oBACzB,KAAK,GAAG,QAAQ,CAAC,SAAS,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;oBAC7C,MAAM;gBACR,KAAK,wBAAwB;oBAC3B,KAAK,GAAG,QAAQ,CAAC,SAAS,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;oBAC7C,MAAM;gBACR,KAAK,uBAAuB;oBAC1B,KAAK,GAAG,QAAQ,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;oBACtC,MAAM;gBACR;oBACE,MAAM,IAAI,KAAK,CAAC,+BAA+B,QAAQ,CAAC,aAAa,EAAE,CAAC,CAAC;YAC7E,CAAC;YAED,MAAM,CAAC,CAAC,GAAG,cAAc,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC;QACzC,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { MeshData } from '@ifc-lite/geometry';
|
|
2
|
+
import type { GLTFDocument, GLTFPrimitive } from './glb-types.js';
|
|
3
|
+
export declare function primitiveTexture(gltf: GLTFDocument, bin: Uint8Array, primitive: GLTFPrimitive, vertexCount: number): Pick<MeshData, 'uvs' | 'textureRef'>;
|
|
4
|
+
export declare function parseGLBImageResources(gltf: GLTFDocument, bin: Uint8Array): Map<string, Uint8Array>;
|
|
5
|
+
export declare function validateGLBImages(gltf: GLTFDocument, bin: Uint8Array): void;
|
|
6
|
+
//# sourceMappingURL=glb-images.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"glb-images.d.ts","sourceRoot":"","sources":["../src/glb-images.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAwClE,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,YAAY,EAAE,GAAG,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC,QAAQ,EAAE,KAAK,GAAG,YAAY,CAAC,CAsCzJ;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,YAAY,EAAE,GAAG,EAAE,UAAU,GAAG,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAA4C;AAChJ,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,YAAY,EAAE,GAAG,EAAE,UAAU,GAAG,IAAI,CAAsC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { readAccessorData } from './glb-accessor.js';
|
|
2
|
+
function imagePath(index, mime) {
|
|
3
|
+
return `textures/glb-image-${index}.${mime === 'image/png' ? 'png' : 'jpg'}`;
|
|
4
|
+
}
|
|
5
|
+
/** Encoded embedded base-colour images. Browser decoding belongs to the host. */
|
|
6
|
+
function imageResources(gltf, bin, copy) {
|
|
7
|
+
const resources = new Map();
|
|
8
|
+
let total = 0;
|
|
9
|
+
for (const material of gltf.materials ?? []) {
|
|
10
|
+
const reference = material.pbrMetallicRoughness?.baseColorTexture;
|
|
11
|
+
if (!reference)
|
|
12
|
+
continue;
|
|
13
|
+
const index = gltf.textures?.[reference.index]?.source;
|
|
14
|
+
const image = index === undefined ? undefined : gltf.images?.[index];
|
|
15
|
+
if (!image || index === undefined || image.bufferView === undefined || image.uri !== undefined) {
|
|
16
|
+
throw new Error('GLB: base-colour textures require embedded PNG/JPEG buffer views');
|
|
17
|
+
}
|
|
18
|
+
if (image.mimeType !== 'image/png' && image.mimeType !== 'image/jpeg')
|
|
19
|
+
throw new Error('GLB: unsupported image MIME type');
|
|
20
|
+
const path = imagePath(index, image.mimeType);
|
|
21
|
+
if (resources.has(path))
|
|
22
|
+
continue;
|
|
23
|
+
const view = gltf.bufferViews?.[image.bufferView];
|
|
24
|
+
const start = view?.byteOffset ?? 0, length = view?.byteLength;
|
|
25
|
+
if (!view || view.buffer !== 0 || length === undefined || !Number.isSafeInteger(start) || !Number.isSafeInteger(length) || start < 0 || length <= 0 || start + length > bin.byteLength) {
|
|
26
|
+
throw new Error('GLB: image buffer view exceeds the embedded buffer');
|
|
27
|
+
}
|
|
28
|
+
// The host can skip alpha readback for JPEG paths only when the encoded
|
|
29
|
+
// payload really is JPEG. Do not derive that guarantee from untrusted MIME.
|
|
30
|
+
const signature = image.mimeType === 'image/png' ? [137, 80, 78, 71, 13, 10, 26, 10] : [255, 216, 255];
|
|
31
|
+
if (length < signature.length || signature.some((value, offset) => bin[start + offset] !== value)) {
|
|
32
|
+
throw new Error('GLB: image signature does not match its declared MIME type');
|
|
33
|
+
}
|
|
34
|
+
total += length;
|
|
35
|
+
if (resources.size >= 256 || total > 256 * 1024 * 1024)
|
|
36
|
+
throw new Error('GLB: embedded images exceed the 256-image / 256 MiB limit');
|
|
37
|
+
resources.set(path, copy ? bin.slice(start, start + length) : bin.subarray(start, start + length));
|
|
38
|
+
}
|
|
39
|
+
return resources;
|
|
40
|
+
}
|
|
41
|
+
export function primitiveTexture(gltf, bin, primitive, vertexCount) {
|
|
42
|
+
const material = primitive.material === undefined ? undefined : gltf.materials?.[primitive.material];
|
|
43
|
+
if (primitive.material !== undefined && !material)
|
|
44
|
+
throw new Error('GLB: material index does not exist');
|
|
45
|
+
const reference = material?.pbrMetallicRoughness?.baseColorTexture;
|
|
46
|
+
if (!reference) {
|
|
47
|
+
if (primitive.attributes.COLOR_0 !== undefined) {
|
|
48
|
+
throw new Error('GLB: vertex-colour-only appearance is unavailable; export a base-colour texture.');
|
|
49
|
+
}
|
|
50
|
+
return {};
|
|
51
|
+
}
|
|
52
|
+
const transform = reference.extensions?.KHR_texture_transform;
|
|
53
|
+
const texCoord = transform?.texCoord ?? reference.texCoord ?? 0;
|
|
54
|
+
if (!Number.isSafeInteger(texCoord) || texCoord < 0)
|
|
55
|
+
throw new Error('GLB: invalid base-colour texture coordinate set');
|
|
56
|
+
const attribute = `TEXCOORD_${texCoord}`;
|
|
57
|
+
const accessor = primitive.attributes[attribute];
|
|
58
|
+
if (accessor === undefined || gltf.accessors?.[accessor]?.type !== 'VEC2')
|
|
59
|
+
throw new Error(`GLB: textured primitive requires ${attribute} VEC2`);
|
|
60
|
+
const raw = readAccessorData(gltf, bin, accessor);
|
|
61
|
+
const declaration = gltf.accessors[accessor];
|
|
62
|
+
const divisor = raw instanceof Float32Array ? 1 : declaration.normalized && raw instanceof Uint16Array ? 65535 : declaration.normalized && raw instanceof Uint8Array ? 255 : 0;
|
|
63
|
+
if (!divisor || raw.length !== vertexCount * 2)
|
|
64
|
+
throw new Error('GLB: texture coordinates must match every vertex and use float or normalized unsigned components');
|
|
65
|
+
const offset = transform?.offset ?? [0, 0], scale = transform?.scale ?? [1, 1], rotation = transform?.rotation ?? 0;
|
|
66
|
+
if (offset.length !== 2 || scale.length !== 2 || ![...offset, ...scale, rotation].every(Number.isFinite))
|
|
67
|
+
throw new Error('GLB: invalid texture transform');
|
|
68
|
+
const uvs = new Float32Array(raw.length), c = Math.cos(rotation), s = Math.sin(rotation);
|
|
69
|
+
for (let i = 0; i < raw.length; i += 2) {
|
|
70
|
+
const u = raw[i] / divisor * scale[0], v = raw[i + 1] / divisor * scale[1];
|
|
71
|
+
uvs[i] = offset[0] + c * u - s * v;
|
|
72
|
+
uvs[i + 1] = offset[1] + s * u + c * v;
|
|
73
|
+
if (!Number.isFinite(uvs[i]) || !Number.isFinite(uvs[i + 1]))
|
|
74
|
+
throw new Error('GLB: non-finite texture coordinates');
|
|
75
|
+
}
|
|
76
|
+
const texture = gltf.textures?.[reference.index], image = texture?.source === undefined ? undefined : gltf.images?.[texture.source];
|
|
77
|
+
if (!texture || texture.source === undefined || !image?.mimeType)
|
|
78
|
+
throw new Error('GLB: texture image does not exist');
|
|
79
|
+
const sampler = texture.sampler === undefined ? undefined : gltf.samplers?.[texture.sampler];
|
|
80
|
+
if (texture.sampler !== undefined && !sampler)
|
|
81
|
+
throw new Error('GLB: sampler does not exist');
|
|
82
|
+
const wrap = (value = 10497) => {
|
|
83
|
+
if (value !== 10497 && value !== 33071)
|
|
84
|
+
throw new Error('GLB: mirrored texture repeat is not supported');
|
|
85
|
+
return value === 10497;
|
|
86
|
+
};
|
|
87
|
+
return { uvs, textureRef: { textureId: reference.index + 1, url: imagePath(texture.source, image.mimeType), repeatS: wrap(sampler?.wrapS), repeatT: wrap(sampler?.wrapT) } };
|
|
88
|
+
}
|
|
89
|
+
export function parseGLBImageResources(gltf, bin) { return imageResources(gltf, bin, true); }
|
|
90
|
+
export function validateGLBImages(gltf, bin) { imageResources(gltf, bin, false); }
|
|
91
|
+
//# sourceMappingURL=glb-images.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"glb-images.js","sourceRoot":"","sources":["../src/glb-images.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAErD,SAAS,SAAS,CAAC,KAAa,EAAE,IAAY;IAC5C,OAAO,sBAAsB,KAAK,IAAI,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC;AAC/E,CAAC;AAED,iFAAiF;AACjF,SAAS,cAAc,CAAC,IAAkB,EAAE,GAAe,EAA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,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;IAC9F,MAAM,IAAI,GAAG,CAAC,KAAK,GAAG,KAAK,EAAE,EAAE;QAC7B,IAAI,KAAK,KAAK,KAAK,IAAI,KAAK,KAAK,KAAK;YAAE,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;QACzG,OAAO,KAAK,KAAK,KAAK,CAAC;IACzB,CAAC,CAAC;IACF,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,EAAE,SAAS,EAAE,SAAS,CAAC,KAAK,GAAG,CAAC,EAAE,GAAG,EAAE,SAAS,CAAC,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC;AAC/K,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,IAAkB,EAAE,GAAe,IAA6B,OAAO,cAAc,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;AAChJ,MAAM,UAAU,iBAAiB,CAAC,IAAkB,EAAE,GAAe,IAAU,cAAc,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { GLTFNode } from './glb-types.js';
|
|
2
|
+
/** Column-major 4x4 (glTF node-transform convention). */
|
|
3
|
+
export type Mat4 = number[];
|
|
4
|
+
export declare const MAT4_IDENTITY: Mat4;
|
|
5
|
+
/** Column-major 4x4 multiply `a * b`. */
|
|
6
|
+
export declare function mat4Mul(a: Mat4, b: Mat4): Mat4;
|
|
7
|
+
/** A node's local transform: its `matrix` (column-major) or a translation matrix. */
|
|
8
|
+
export declare function nodeLocalMat4(nd: GLTFNode): Mat4;
|
|
9
|
+
/** True when a 4x4's upper-left 3x3 is the identity (within epsilon) — i.e. the
|
|
10
|
+
* node carries pure translation, so vertices need no rotation/scale baking. */
|
|
11
|
+
export declare function linearIsIdentity(m: Mat4): boolean;
|
|
12
|
+
/** Inverse transpose for normals, including nonuniform scale. */
|
|
13
|
+
export declare function normalMatrix(m: Mat4): number[];
|
|
14
|
+
export declare function mirrored(m: Mat4): boolean;
|
|
15
|
+
//# sourceMappingURL=glb-transform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"glb-transform.d.ts","sourceRoot":"","sources":["../src/glb-transform.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,yDAAyD;AACzD,MAAM,MAAM,IAAI,GAAG,MAAM,EAAE,CAAC;AAE5B,eAAO,MAAM,aAAa,EAAE,IAAuD,CAAC;AAEpF,yCAAyC;AACzC,wBAAgB,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,GAAG,IAAI,CAU9C;AAED,qFAAqF;AACrF,wBAAgB,aAAa,CAAC,EAAE,EAAE,QAAQ,GAAG,IAAI,CAiBhD;AAED;gFACgF;AAChF,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,IAAI,GAAG,OAAO,CAOjD;AAGD,iEAAiE;AACjE,wBAAgB,YAAY,CAAC,CAAC,EAAE,IAAI,GAAG,MAAM,EAAE,CAK9C;AACD,wBAAgB,QAAQ,CAAC,CAAC,EAAE,IAAI,GAAG,OAAO,CAEzC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
2
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
4
|
+
export const MAT4_IDENTITY = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
|
5
|
+
/** Column-major 4x4 multiply `a * b`. */
|
|
6
|
+
export function mat4Mul(a, b) {
|
|
7
|
+
const out = new Array(16);
|
|
8
|
+
for (let col = 0; col < 4; col++) {
|
|
9
|
+
for (let row = 0; row < 4; row++) {
|
|
10
|
+
let s = 0;
|
|
11
|
+
for (let k = 0; k < 4; k++)
|
|
12
|
+
s += a[k * 4 + row] * b[col * 4 + k];
|
|
13
|
+
out[col * 4 + row] = s;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return out;
|
|
17
|
+
}
|
|
18
|
+
/** A node's local transform: its `matrix` (column-major) or a translation matrix. */
|
|
19
|
+
export function nodeLocalMat4(nd) {
|
|
20
|
+
const finite = (values, count) => values === undefined || (values.length === count && values.every(Number.isFinite));
|
|
21
|
+
if (!finite(nd.matrix, 16) || !finite(nd.translation, 3) || !finite(nd.rotation, 4) || !finite(nd.scale, 3))
|
|
22
|
+
throw new Error('GLB: invalid node transform');
|
|
23
|
+
if (nd.matrix) {
|
|
24
|
+
if (nd.translation || nd.rotation || nd.scale || nd.matrix[3] !== 0 || nd.matrix[7] !== 0 || nd.matrix[11] !== 0 || nd.matrix[15] !== 1)
|
|
25
|
+
throw new Error('GLB: invalid affine node matrix');
|
|
26
|
+
return nd.matrix;
|
|
27
|
+
}
|
|
28
|
+
const [x, y, z, w] = nd.rotation ?? [0, 0, 0, 1];
|
|
29
|
+
if (Math.abs(Math.hypot(x, y, z, w) - 1) > 1e-5)
|
|
30
|
+
throw new Error('GLB: rotation quaternion must be normalized');
|
|
31
|
+
const [sx, sy, sz] = nd.scale ?? [1, 1, 1];
|
|
32
|
+
const t = nd.translation ?? [0, 0, 0];
|
|
33
|
+
return [
|
|
34
|
+
(1 - 2 * (y * y + z * z)) * sx, 2 * (x * y + z * w) * sx, 2 * (x * z - y * w) * sx, 0,
|
|
35
|
+
2 * (x * y - z * w) * sy, (1 - 2 * (x * x + z * z)) * sy, 2 * (y * z + x * w) * sy, 0,
|
|
36
|
+
2 * (x * z + y * w) * sz, 2 * (y * z - x * w) * sz, (1 - 2 * (x * x + y * y)) * sz, 0,
|
|
37
|
+
t[0], t[1], t[2], 1,
|
|
38
|
+
];
|
|
39
|
+
}
|
|
40
|
+
/** True when a 4x4's upper-left 3x3 is the identity (within epsilon) — i.e. the
|
|
41
|
+
* node carries pure translation, so vertices need no rotation/scale baking. */
|
|
42
|
+
export function linearIsIdentity(m) {
|
|
43
|
+
const e = 1e-6;
|
|
44
|
+
return (Math.abs(m[0] - 1) < e && Math.abs(m[1]) < e && Math.abs(m[2]) < e &&
|
|
45
|
+
Math.abs(m[4]) < e && Math.abs(m[5] - 1) < e && Math.abs(m[6]) < e &&
|
|
46
|
+
Math.abs(m[8]) < e && Math.abs(m[9]) < e && Math.abs(m[10] - 1) < e);
|
|
47
|
+
}
|
|
48
|
+
/** Inverse transpose for normals, including nonuniform scale. */
|
|
49
|
+
export function normalMatrix(m) {
|
|
50
|
+
const a = m[0], b = m[4], c = m[8], d = m[1], e = m[5], f = m[9], g = m[2], h = m[6], i = m[10];
|
|
51
|
+
const det = a * (e * i - f * h) - b * (d * i - f * g) + c * (d * h - e * g);
|
|
52
|
+
if (!Number.isFinite(det) || Math.abs(det) < 1e-15)
|
|
53
|
+
throw new Error('GLB: singular node scale cannot preserve surface normals');
|
|
54
|
+
return [(e * i - f * h) / det, (c * h - b * i) / det, (b * f - c * e) / det, (f * g - d * i) / det, (a * i - c * g) / det, (c * d - a * f) / det, (d * h - e * g) / det, (b * g - a * h) / det, (a * e - b * d) / det];
|
|
55
|
+
}
|
|
56
|
+
export function mirrored(m) {
|
|
57
|
+
return m[0] * (m[5] * m[10] - m[9] * m[6]) - m[4] * (m[1] * m[10] - m[9] * m[2]) + m[8] * (m[1] * m[6] - m[5] * m[2]) < 0;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=glb-transform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"glb-transform.js","sourceRoot":"","sources":["../src/glb-transform.ts"],"names":[],"mappings":"AAAA;;+DAE+D;AAM/D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CAAC,CAAC,CAAC,GAAC,CAAC,CAAC,CAAC,CAAC,GAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAC,CAAC,CAAC,CAAC,CAAC,GAAC,CAAC,CAAC,CAAC,CAAC,GAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AAChG,CAAC"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
export interface GLTFDocument {
|
|
2
|
+
asset: {
|
|
3
|
+
version: string;
|
|
4
|
+
generator?: string;
|
|
5
|
+
};
|
|
6
|
+
extensionsRequired?: string[];
|
|
7
|
+
scene?: number;
|
|
8
|
+
scenes?: Array<{
|
|
9
|
+
nodes?: number[];
|
|
10
|
+
}>;
|
|
11
|
+
nodes?: GLTFNode[];
|
|
12
|
+
meshes?: GLTFMesh[];
|
|
13
|
+
materials?: GLTFMaterial[];
|
|
14
|
+
accessors?: GLTFAccessor[];
|
|
15
|
+
bufferViews?: GLTFBufferView[];
|
|
16
|
+
buffers?: GLTFBuffer[];
|
|
17
|
+
images?: Array<{
|
|
18
|
+
bufferView?: number;
|
|
19
|
+
mimeType?: string;
|
|
20
|
+
uri?: string;
|
|
21
|
+
}>;
|
|
22
|
+
textures?: Array<{
|
|
23
|
+
source?: number;
|
|
24
|
+
sampler?: number;
|
|
25
|
+
}>;
|
|
26
|
+
samplers?: Array<{
|
|
27
|
+
wrapS?: number;
|
|
28
|
+
wrapT?: number;
|
|
29
|
+
}>;
|
|
30
|
+
}
|
|
31
|
+
export interface GLTFNode {
|
|
32
|
+
mesh?: number;
|
|
33
|
+
name?: string;
|
|
34
|
+
extras?: {
|
|
35
|
+
expressId?: number;
|
|
36
|
+
};
|
|
37
|
+
children?: number[];
|
|
38
|
+
/** Node-local translation (xyz). The from-meshes exporter places all geometry
|
|
39
|
+
* under a single translated root node, so this is composed down the hierarchy. */
|
|
40
|
+
translation?: number[];
|
|
41
|
+
rotation?: number[];
|
|
42
|
+
scale?: number[];
|
|
43
|
+
skin?: number;
|
|
44
|
+
/** Node-local column-major 4x4 (glTF convention). The from-bytes instanced
|
|
45
|
+
* exporter places each shared-template occurrence with a node MATRIX (rotation +
|
|
46
|
+
* translation); mutually exclusive with `translation` per the glTF spec. */
|
|
47
|
+
matrix?: number[];
|
|
48
|
+
}
|
|
49
|
+
export interface GLTFMesh {
|
|
50
|
+
primitives: GLTFPrimitive[];
|
|
51
|
+
name?: string;
|
|
52
|
+
}
|
|
53
|
+
export interface GLTFPrimitive {
|
|
54
|
+
attributes: {
|
|
55
|
+
POSITION: number;
|
|
56
|
+
NORMAL?: number;
|
|
57
|
+
TEXCOORD_0?: number;
|
|
58
|
+
[name: string]: number | undefined;
|
|
59
|
+
};
|
|
60
|
+
targets?: unknown[];
|
|
61
|
+
extensions?: Record<string, unknown>;
|
|
62
|
+
indices?: number;
|
|
63
|
+
mode?: number;
|
|
64
|
+
material?: number;
|
|
65
|
+
}
|
|
66
|
+
export interface GLTFMaterial {
|
|
67
|
+
pbrMetallicRoughness?: {
|
|
68
|
+
baseColorTexture?: {
|
|
69
|
+
index: number;
|
|
70
|
+
texCoord?: number;
|
|
71
|
+
extensions?: {
|
|
72
|
+
KHR_texture_transform?: {
|
|
73
|
+
offset?: number[];
|
|
74
|
+
scale?: number[];
|
|
75
|
+
rotation?: number;
|
|
76
|
+
texCoord?: number;
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
metallicRoughnessTexture?: unknown;
|
|
81
|
+
baseColorFactor?: [number, number, number, number] | number[];
|
|
82
|
+
};
|
|
83
|
+
normalTexture?: unknown;
|
|
84
|
+
emissiveTexture?: unknown;
|
|
85
|
+
occlusionTexture?: unknown;
|
|
86
|
+
extensions?: Record<string, unknown>;
|
|
87
|
+
alphaMode?: 'OPAQUE' | 'MASK' | 'BLEND';
|
|
88
|
+
}
|
|
89
|
+
export interface GLTFAccessor {
|
|
90
|
+
sparse?: unknown;
|
|
91
|
+
normalized?: boolean;
|
|
92
|
+
bufferView: number;
|
|
93
|
+
byteOffset?: number;
|
|
94
|
+
componentType: number;
|
|
95
|
+
count: number;
|
|
96
|
+
type: 'SCALAR' | 'VEC2' | 'VEC3' | 'VEC4' | 'MAT2' | 'MAT3' | 'MAT4';
|
|
97
|
+
min?: number[];
|
|
98
|
+
max?: number[];
|
|
99
|
+
}
|
|
100
|
+
export interface GLTFBufferView {
|
|
101
|
+
buffer: number;
|
|
102
|
+
byteOffset?: number;
|
|
103
|
+
byteLength: number;
|
|
104
|
+
byteStride?: number;
|
|
105
|
+
target?: number;
|
|
106
|
+
}
|
|
107
|
+
export interface GLTFBuffer {
|
|
108
|
+
byteLength: number;
|
|
109
|
+
uri?: string;
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=glb-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"glb-types.d.ts","sourceRoot":"","sources":["../src/glb-types.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC/C,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,KAAK,CAAC;QAAE,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC,CAAC;IACrC,KAAK,CAAC,EAAE,QAAQ,EAAE,CAAC;IACnB,MAAM,CAAC,EAAE,QAAQ,EAAE,CAAC;IACpB,SAAS,CAAC,EAAE,YAAY,EAAE,CAAC;IAC3B,SAAS,CAAC,EAAE,YAAY,EAAE,CAAC;IAC3B,WAAW,CAAC,EAAE,cAAc,EAAE,CAAC;IAC/B,OAAO,CAAC,EAAE,UAAU,EAAE,CAAC;IACvB,MAAM,CAAC,EAAE,KAAK,CAAC;QAAE,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,E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AE,MAAM,EAAE,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC;CAChB;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,UAAU;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"glb-types.js","sourceRoot":"","sources":["../src/glb-types.ts"],"names":[],"mappings":"AAAA;;+DAE+D"}
|
package/dist/glb.d.ts
CHANGED
|
@@ -16,76 +16,7 @@ export interface GLBMapping {
|
|
|
16
16
|
expressIdToMesh: Map<number, number>;
|
|
17
17
|
nodeToExpressId: Map<number, number>;
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
asset: {
|
|
21
|
-
version: string;
|
|
22
|
-
generator?: string;
|
|
23
|
-
};
|
|
24
|
-
scene?: number;
|
|
25
|
-
scenes?: Array<{
|
|
26
|
-
nodes?: number[];
|
|
27
|
-
}>;
|
|
28
|
-
nodes?: GLTFNode[];
|
|
29
|
-
meshes?: GLTFMesh[];
|
|
30
|
-
materials?: GLTFMaterial[];
|
|
31
|
-
accessors?: GLTFAccessor[];
|
|
32
|
-
bufferViews?: GLTFBufferView[];
|
|
33
|
-
buffers?: GLTFBuffer[];
|
|
34
|
-
}
|
|
35
|
-
interface GLTFNode {
|
|
36
|
-
mesh?: number;
|
|
37
|
-
name?: string;
|
|
38
|
-
extras?: {
|
|
39
|
-
expressId?: number;
|
|
40
|
-
};
|
|
41
|
-
children?: number[];
|
|
42
|
-
/** Node-local translation (xyz). The from-meshes exporter places all geometry
|
|
43
|
-
* under a single translated root node, so this is composed down the hierarchy. */
|
|
44
|
-
translation?: number[];
|
|
45
|
-
/** Node-local column-major 4x4 (glTF convention). The from-bytes instanced
|
|
46
|
-
* exporter places each shared-template occurrence with a node MATRIX (rotation +
|
|
47
|
-
* translation); mutually exclusive with `translation` per the glTF spec. */
|
|
48
|
-
matrix?: number[];
|
|
49
|
-
}
|
|
50
|
-
interface GLTFMesh {
|
|
51
|
-
primitives: GLTFPrimitive[];
|
|
52
|
-
name?: string;
|
|
53
|
-
}
|
|
54
|
-
interface GLTFPrimitive {
|
|
55
|
-
attributes: {
|
|
56
|
-
POSITION: number;
|
|
57
|
-
NORMAL?: number;
|
|
58
|
-
};
|
|
59
|
-
indices?: number;
|
|
60
|
-
mode?: number;
|
|
61
|
-
material?: number;
|
|
62
|
-
}
|
|
63
|
-
interface GLTFMaterial {
|
|
64
|
-
pbrMetallicRoughness?: {
|
|
65
|
-
baseColorFactor?: [number, number, number, number] | number[];
|
|
66
|
-
};
|
|
67
|
-
alphaMode?: 'OPAQUE' | 'MASK' | 'BLEND';
|
|
68
|
-
}
|
|
69
|
-
interface GLTFAccessor {
|
|
70
|
-
bufferView: number;
|
|
71
|
-
byteOffset?: number;
|
|
72
|
-
componentType: number;
|
|
73
|
-
count: number;
|
|
74
|
-
type: 'SCALAR' | 'VEC2' | 'VEC3' | 'VEC4' | 'MAT2' | 'MAT3' | 'MAT4';
|
|
75
|
-
min?: number[];
|
|
76
|
-
max?: number[];
|
|
77
|
-
}
|
|
78
|
-
interface GLTFBufferView {
|
|
79
|
-
buffer: number;
|
|
80
|
-
byteOffset?: number;
|
|
81
|
-
byteLength: number;
|
|
82
|
-
byteStride?: number;
|
|
83
|
-
target?: number;
|
|
84
|
-
}
|
|
85
|
-
interface GLTFBuffer {
|
|
86
|
-
byteLength: number;
|
|
87
|
-
uri?: string;
|
|
88
|
-
}
|
|
19
|
+
import type { GLTFDocument } from './glb-types.js';
|
|
89
20
|
/**
|
|
90
21
|
* Parse a GLB (binary glTF) file
|
|
91
22
|
*
|
|
@@ -118,5 +49,4 @@ export declare function parseGLBToMeshData(gltf: GLTFDocument, bin: Uint8Array):
|
|
|
118
49
|
* @returns Array of MeshData objects
|
|
119
50
|
*/
|
|
120
51
|
export declare function loadGLBToMeshData(data: Uint8Array): MeshData[];
|
|
121
|
-
export {};
|
|
122
52
|
//# sourceMappingURL=glb.d.ts.map
|