@loaders.gl/gltf 4.3.0-alpha.7 → 4.3.0-alpha.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dist.dev.js +383 -66
- package/dist/dist.min.js +1 -1
- package/dist/glb-writer.js +1 -1
- package/dist/gltf-writer.d.ts.map +1 -1
- package/dist/gltf-writer.js +4 -2
- package/dist/index.cjs +266 -16
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/lib/api/gltf-extensions.d.ts +4 -1
- package/dist/lib/api/gltf-extensions.d.ts.map +1 -1
- package/dist/lib/api/gltf-extensions.js +11 -0
- package/dist/lib/api/gltf-scenegraph.d.ts.map +1 -1
- package/dist/lib/api/gltf-scenegraph.js +1 -2
- package/dist/lib/encoders/encode-gltf.d.ts +3 -1
- package/dist/lib/encoders/encode-gltf.d.ts.map +1 -1
- package/dist/lib/encoders/encode-gltf.js +3 -3
- package/dist/lib/extensions/EXT_mesh_features.d.ts +17 -1
- package/dist/lib/extensions/EXT_mesh_features.d.ts.map +1 -1
- package/dist/lib/extensions/EXT_mesh_features.js +109 -0
- package/dist/lib/extensions/EXT_structural_metadata.d.ts +19 -0
- package/dist/lib/extensions/EXT_structural_metadata.d.ts.map +1 -1
- package/dist/lib/extensions/EXT_structural_metadata.js +168 -0
- package/dist/lib/utils/version.js +1 -1
- package/package.json +8 -8
- package/src/glb-writer.ts +1 -1
- package/src/gltf-writer.ts +8 -4
- package/src/index.ts +6 -0
- package/src/lib/api/gltf-extensions.ts +15 -1
- package/src/lib/api/gltf-scenegraph.ts +1 -3
- package/src/lib/encoders/encode-gltf.ts +11 -4
- package/src/lib/extensions/EXT_mesh_features.ts +130 -0
- package/src/lib/extensions/EXT_structural_metadata.ts +232 -1
package/dist/index.d.ts
CHANGED
|
@@ -15,4 +15,6 @@ export { GLBWriter } from "./glb-writer.js";
|
|
|
15
15
|
export { GLTFScenegraph } from "./lib/api/gltf-scenegraph.js";
|
|
16
16
|
export { postProcessGLTF } from "./lib/api/post-process-gltf.js";
|
|
17
17
|
export { getMemoryUsageGLTF as _getMemoryUsageGLTF } from "./lib/gltf-utils/gltf-utils.js";
|
|
18
|
+
export { createExtStructuralMetadata, type PropertyAttribute } from "./lib/extensions/EXT_structural_metadata.js";
|
|
19
|
+
export { createExtMeshFeatures } from "./lib/extensions/EXT_mesh_features.js";
|
|
18
20
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,YAAY,EAAC,GAAG,EAAC,iCAA8B;AAG/C,YAAY,EACV,IAAI,EACJ,YAAY,EACZ,UAAU,EACV,cAAc,EACd,iBAAiB,EACjB,QAAQ,EACR,QAAQ,EACR,YAAY,EACZ,WAAW,EACX,SAAS,EACT,QAAQ,EACR,WAAW,EACX,SAAS,EACT,UAAU,EAEV,oBAAoB,EACpB,+BAA+B,EAC/B,uBAAuB,EACvB,4BAA4B,EAC5B,qBAAqB,EACtB,wCAAqC;AAGtC,YAAY,EACV,8BAA8B,EAC9B,gCAAgC,EAChC,+BAA+B,EAC/B,uCAAuC,EACvC,8BAA8B,EAC9B,mCAAmC,EACnC,sCAAsC,EACtC,8CAA8C,EAC9C,wCAAwC,EACxC,yCAAyC,EACzC,oCAAoC,EACpC,yCAAyC,EACzC,iDAAiD,EACjD,mCAAmC,EACnC,4CAA4C,EAC5C,sDAAsD,EACtD,0CAA0C,EAC1C,kDAAkD,EACnD,wDAAqD;AAEtD,YAAY,EACV,iCAAiC,EACjC,mCAAmC,EACnC,0CAA0C,EAC1C,4CAA4C,EAC5C,kCAAkC,EAClC,0CAA0C,EAC3C,2DAAwD;AAEzD,YAAY,EACV,sBAAsB,EACtB,gCAAgC,EACjC,qDAAkD;AAEnD,OAAO,EA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nC,4CAA4C,EAC5C,sDAAsD,EACtD,0CAA0C,EAC1C,kDAAkD,EACnD,wDAAqD;AAEtD,YAAY,EACV,iCAAiC,EACjC,mCAAmC,EACnC,0CAA0C,EAC1C,4CAA4C,EAC5C,kCAAkC,EAClC,0CAA0C,EAC3C,2DAAwD;AAEzD,YAAY,EACV,sBAAsB,EACtB,gCAAgC,EACjC,qDAAkD;AAEnD,OAAO,EAAC,IAAI,IAAI,iBAAiB,EAAC,8CAA2C;AAC7E,OAAO,EAAC,IAAI,IAAI,uBAAuB,EAAC,oDAAiD;AACzF,OAAO,EAAC,IAAI,IAAI,oBAAoB,EAAC,4DAAyD;AAG9F,YAAY,EACV,iBAAiB,EACjB,yBAAyB,EACzB,qBAAqB,EACrB,yBAAyB,EACzB,qBAAqB,EACrB,8BAA8B,EAC9B,sBAAsB,EACtB,wBAAwB,EACzB,iDAA8C;AAE/C,YAAY,EAAC,eAAe,EAAE,gBAAgB,EAAC,kCAA+B;AAG9E,OAAO,EAAC,UAAU,EAAC,yBAAsB;AACzC,OAAO,EAAC,UAAU,EAAC,yBAAsB;AAGzC,OAAO,EAAC,SAAS,EAAC,wBAAqB;AACvC,OAAO,EAAC,SAAS,EAAC,wBAAqB;AAGvC,OAAO,EAAC,cAAc,EAAC,qCAAkC;AACzD,OAAO,EAAC,eAAe,EAAC,uCAAoC;AAC5D,OAAO,EAAC,kBAAkB,IAAI,mBAAmB,EAAC,uCAAoC;AAEtF,OAAO,EACL,2BAA2B,EAC3B,KAAK,iBAAiB,EACvB,oDAAiD;AAClD,OAAO,EAAC,qBAAqB,EAAC,8CAA2C"}
|
package/dist/index.js
CHANGED
|
@@ -11,3 +11,5 @@ export { GLBWriter } from "./glb-writer.js";
|
|
|
11
11
|
export { GLTFScenegraph } from "./lib/api/gltf-scenegraph.js";
|
|
12
12
|
export { postProcessGLTF } from "./lib/api/post-process-gltf.js";
|
|
13
13
|
export { getMemoryUsageGLTF as _getMemoryUsageGLTF } from "./lib/gltf-utils/gltf-utils.js";
|
|
14
|
+
export { createExtStructuralMetadata } from "./lib/extensions/EXT_structural_metadata.js";
|
|
15
|
+
export { createExtMeshFeatures } from "./lib/extensions/EXT_mesh_features.js";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { GLTF } from "../types/gltf-json-schema.js";
|
|
2
2
|
import type { GLTFLoaderOptions } from "../../gltf-loader.js";
|
|
3
|
+
import { GLTFWriterOptions } from "../../gltf-writer.js";
|
|
3
4
|
type GLTFExtensionPlugin = {
|
|
4
5
|
name: string;
|
|
5
6
|
preprocess?: (gltfData: {
|
|
@@ -15,7 +16,7 @@ type GLTFExtensionPlugin = {
|
|
|
15
16
|
}, options: GLTFLoaderOptions, context: any) => Promise<void>;
|
|
16
17
|
encode?: (gltfData: {
|
|
17
18
|
json: GLTF;
|
|
18
|
-
}, options:
|
|
19
|
+
}, options: GLTFWriterOptions) => void;
|
|
19
20
|
};
|
|
20
21
|
/**
|
|
21
22
|
* List of extensions processed by the GLTFLoader
|
|
@@ -27,5 +28,7 @@ export declare const EXTENSIONS: GLTFExtensionPlugin[];
|
|
|
27
28
|
export declare function preprocessExtensions(gltf: any, options?: GLTFLoaderOptions, context?: any): void;
|
|
28
29
|
/** Call after resource loading */
|
|
29
30
|
export declare function decodeExtensions(gltf: any, options?: GLTFLoaderOptions, context?: any): Promise<void>;
|
|
31
|
+
/** Call before resource writing */
|
|
32
|
+
export declare function encodeExtensions(gltf: any, options?: GLTFWriterOptions): any;
|
|
30
33
|
export {};
|
|
31
34
|
//# sourceMappingURL=gltf-extensions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gltf-extensions.d.ts","sourceRoot":"","sources":["../../../src/lib/api/gltf-extensions.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,IAAI,EAAC,qCAAkC;AAC/C,OAAO,KAAK,EAAC,iBAAiB,EAAC,6BAA0B;
|
|
1
|
+
{"version":3,"file":"gltf-extensions.d.ts","sourceRoot":"","sources":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ture_transform,
|
|
38
38
|
EXT_feature_metadata
|
|
39
39
|
];
|
|
40
|
+
/**
|
|
41
|
+
* List of extensions processed by the GLTFWriter
|
|
42
|
+
*/
|
|
43
|
+
const EXTENSIONS_ENCODING = [EXT_structural_metadata, EXT_mesh_features];
|
|
40
44
|
/** Call before any resource loading starts */
|
|
41
45
|
export function preprocessExtensions(gltf, options = {}, context) {
|
|
42
46
|
const extensions = EXTENSIONS.filter((extension) => useExtension(extension.name, options));
|
|
@@ -53,6 +57,13 @@ export async function decodeExtensions(gltf, options = {}, context) {
|
|
|
53
57
|
await extension.decode?.(gltf, options, context);
|
|
54
58
|
}
|
|
55
59
|
}
|
|
60
|
+
/** Call before resource writing */
|
|
61
|
+
export function encodeExtensions(gltf, options = {}) {
|
|
62
|
+
for (const extension of EXTENSIONS_ENCODING) {
|
|
63
|
+
gltf = extension.encode?.(gltf, options) ?? gltf;
|
|
64
|
+
}
|
|
65
|
+
return gltf;
|
|
66
|
+
}
|
|
56
67
|
function useExtension(extensionName, options) {
|
|
57
68
|
const excludes = options?.gltf?.excludeExtensions || {};
|
|
58
69
|
const exclude = extensionName in excludes && !excludes[extensionName];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gltf-scenegraph.d.ts","sourceRoot":"","sources":["../../../src/lib/api/gltf-scenegraph.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,eAAe,EAAC,+BAA4B;AACzD,OAAO,KAAK,EACV,IAAI,EACJ,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,WAAW,EACX,SAAS,EACT,UAAU,EACV,cAAc,EACf,qCAAkC;AASnC,KAAK,SAAS,GAAG;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAC,CAAC;AAetC;;GAEG;AACH,qBAAa,cAAc;IAEzB,IAAI,EAAE,eAAe,CAAC;IACtB,aAAa,EAAE,GAAG,EAAE,CA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B,GAAG,MAAM;IAyBjF;;;;OAIG;IACH,WAAW,CAAC,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM;IAoB9D;;;;;;OAMG;IACH,eAAe,CAAC,YAAY,EAAE,GAAG,EAAE,QAAQ,GAAE,MAAkB,GAAG,MAAM;IAsBxE;;;;;OAKG;IACH,UAAU,CAAC,OAAO,EAAE;QAAC,UAAU,EAAE,MAAM,CAAA;KAAC,GAAG,MAAM;IAWjD,uCAAuC;IACvC,WAAW,CAAC,eAAe,EAAE,MAAM,GAAG,MAAM;IAM5C,4BAA4B;IAC5B,iBAAiB,IAAI,IAAI;IA6BzB,sBAAsB,CAAC,KAAK,KAAA,EAAE,MAAM,KAAA;IAYpC;;OAEG;IACH,cAAc,CAAC,UAAU,KAAK;IAW9B;;OAEG;IACH,WAAW,CAAC,OAAO,KAAA;IAInB;;OAEG;IACH,qBAAqB,CAAC,aAAa,KAAA;IAoBnC;;;OAGG;IACH,kBAAkB,CAAC,MAAM,KAAA,EAAE,IAAI,KAAA;;;;CAmChC"}
|
|
@@ -460,8 +460,6 @@ export class GLTFScenegraph {
|
|
|
460
460
|
}
|
|
461
461
|
/** Pack the binary chunk */
|
|
462
462
|
createBinaryChunk() {
|
|
463
|
-
// Encoder expects this array undefined or empty
|
|
464
|
-
this.gltf.buffers = [];
|
|
465
463
|
// Allocate total array
|
|
466
464
|
const totalByteLength = this.byteLength;
|
|
467
465
|
const arrayBuffer = new ArrayBuffer(totalByteLength);
|
|
@@ -482,6 +480,7 @@ export class GLTFScenegraph {
|
|
|
482
480
|
this.gltf.binary = arrayBuffer;
|
|
483
481
|
// Put arrayBuffer to sourceBuffers for possible additional writing data in the chunk
|
|
484
482
|
this.sourceBuffers = [arrayBuffer];
|
|
483
|
+
this.gltf.buffers = [{ arrayBuffer, byteOffset: 0, byteLength: arrayBuffer.byteLength }];
|
|
485
484
|
}
|
|
486
485
|
// PRIVATE
|
|
487
486
|
_removeStringFromArray(array, string) {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { GLTFWriterOptions } from "../../gltf-writer.js";
|
|
2
|
+
import { GLTFWithBuffers } from '@loaders.gl/gltf';
|
|
1
3
|
export type GLTFEncodeOptions = Record<string, any>;
|
|
2
4
|
/**
|
|
3
5
|
* Encode the full glTF file as a binary GLB file
|
|
@@ -16,5 +18,5 @@ export type GLTFEncodeOptions = Record<string, any>;
|
|
|
16
18
|
* @param options
|
|
17
19
|
* @returns
|
|
18
20
|
*/
|
|
19
|
-
export declare function encodeGLTFSync(gltf:
|
|
21
|
+
export declare function encodeGLTFSync(gltf: GLTFWithBuffers, arrayBuffer: DataView | null, byteOffset: number, options: GLTFWriterOptions): number;
|
|
20
22
|
//# sourceMappingURL=encode-gltf.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encode-gltf.d.ts","sourceRoot":"","sources":["../../../src/lib/encoders/encode-gltf.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"encode-gltf.d.ts","sourceRoot":"","sources":["../../../src/lib/encoders/encode-gltf.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,iBAAiB,EAAC,6BAA0B;AACpD,OAAO,EAAC,eAAe,EAAC,MAAM,kBAAkB,CAAC;AAEjD,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAEpD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,eAAe,EACrB,WAAW,EAAE,QAAQ,GAAG,IAAI,EAC5B,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,iBAAiB,UAO3B"}
|
|
@@ -17,12 +17,12 @@ import { encodeGLBSync } from "./encode-glb.js";
|
|
|
17
17
|
* @returns
|
|
18
18
|
*/
|
|
19
19
|
export function encodeGLTFSync(gltf, arrayBuffer, byteOffset, options) {
|
|
20
|
-
|
|
20
|
+
validateGltf(gltf);
|
|
21
21
|
// TODO: Copy buffers to binary
|
|
22
22
|
return encodeGLBSync(gltf, arrayBuffer, byteOffset, options);
|
|
23
23
|
}
|
|
24
|
-
function
|
|
25
|
-
if (gltf.buffers && gltf.buffers.length >
|
|
24
|
+
function validateGltf(gltf) {
|
|
25
|
+
if (gltf.buffers && gltf.buffers.length > 1) {
|
|
26
26
|
throw new Error('encodeGLTF: multiple buffers not yet implemented');
|
|
27
27
|
}
|
|
28
28
|
}
|
|
@@ -1,7 +1,23 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { NumericArray } from '@loaders.gl/loader-utils';
|
|
2
|
+
import type { GLTF, GLTFMeshPrimitive } from "../types/gltf-json-schema.js";
|
|
2
3
|
import { GLTFLoaderOptions } from "../../gltf-loader.js";
|
|
4
|
+
import { GLTFWriterOptions } from "../../gltf-writer.js";
|
|
5
|
+
import { GLTFScenegraph } from "../api/gltf-scenegraph.js";
|
|
3
6
|
export declare const name = "EXT_mesh_features";
|
|
4
7
|
export declare function decode(gltfData: {
|
|
5
8
|
json: GLTF;
|
|
6
9
|
}, options: GLTFLoaderOptions): Promise<void>;
|
|
10
|
+
export declare function encode(gltfData: {
|
|
11
|
+
json: GLTF;
|
|
12
|
+
}, options: GLTFWriterOptions): {
|
|
13
|
+
json: GLTF;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Creates ExtMeshFeatures, creates a featureId containing feature ids provided.
|
|
17
|
+
* @param scenegraph - Instance of the class for structured access to GLTF data.
|
|
18
|
+
* @param primitive - target primitive instance that will contain the extension
|
|
19
|
+
* @param featureIdArray - Array of feature id
|
|
20
|
+
* @param propertyTableIndex - index of the property table created by the ExtStructuralMetadata (optional).
|
|
21
|
+
*/
|
|
22
|
+
export declare function createExtMeshFeatures(scenegraph: GLTFScenegraph, primitive: GLTFMeshPrimitive, featureIdArray: NumericArray, propertyTableIndex?: number): void;
|
|
7
23
|
//# sourceMappingURL=EXT_mesh_features.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EXT_mesh_features.d.ts","sourceRoot":"","sources":["../../../src/lib/extensions/EXT_mesh_features.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"EXT_mesh_features.d.ts","sourceRoot":"","sources":["../../../src/lib/extensions/EXT_mesh_features.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,0BAA0B,CAAC;AAC3D,OAAO,KAAK,EAAC,IAAI,EAAE,iBAAiB,EAAC,qCAAkC;AACvE,OAAO,EAAC,iBAAiB,EAAC,6BAA0B;AACpD,OAAO,EAAC,iBAAiB,EAAC,6BAA0B;AAMpD,OAAO,EAAC,cAAc,EAAC,kCAA+B;AAKtD,eAAO,MAAM,IAAI,sBAAyB,CAAC;AAE3C,wBAAsB,MAAM,CAAC,QAAQ,EAAE;IAAC,IAAI,EAAE,IAAI,CAAA;CAAC,EAAE,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAG9F;AAED,wBAAgB,MAAM,CAAC,QAAQ,EAAE;IAAC,IAAI,EAAE,IAAI,CAAA;CAAC,EAAE,OAAO,EAAE,iBAAiB,GAAG;IAAC,IAAI,EAAE,IAAI,CAAA;CAAC,CAKvF;AA4FD;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,UAAU,EAAE,cAAc,EAC1B,SAAS,EAAE,iBAAiB,EAC5B,cAAc,EAAE,YAAY,EAC5B,kBAAkB,CAAC,EAAE,MAAM,QAoB5B"}
|
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import { GLTFScenegraph } from "../api/gltf-scenegraph.js";
|
|
2
2
|
import { getPrimitiveTextureData } from "./utils/3d-tiles-utils.js";
|
|
3
|
+
import { getComponentTypeFromArray } from "../gltf-utils/gltf-utils.js";
|
|
3
4
|
const EXT_MESH_FEATURES_NAME = 'EXT_mesh_features';
|
|
4
5
|
export const name = EXT_MESH_FEATURES_NAME;
|
|
5
6
|
export async function decode(gltfData, options) {
|
|
6
7
|
const scenegraph = new GLTFScenegraph(gltfData);
|
|
7
8
|
decodeExtMeshFeatures(scenegraph, options);
|
|
8
9
|
}
|
|
10
|
+
export function encode(gltfData, options) {
|
|
11
|
+
const scenegraph = new GLTFScenegraph(gltfData);
|
|
12
|
+
encodeExtMeshFeatures(scenegraph, options);
|
|
13
|
+
scenegraph.createBinaryChunk();
|
|
14
|
+
return scenegraph.gltf;
|
|
15
|
+
}
|
|
9
16
|
/**
|
|
10
17
|
* Decodes feature metadata from extension.
|
|
11
18
|
* @param {GLTFScenegraph} scenegraph - Instance of the class for structured access to GLTF data.
|
|
@@ -65,3 +72,105 @@ function processMeshPrimitiveFeatures(scenegraph, primitive, options) {
|
|
|
65
72
|
featureId.data = featureIdData;
|
|
66
73
|
}
|
|
67
74
|
}
|
|
75
|
+
/*
|
|
76
|
+
Encoding data
|
|
77
|
+
*/
|
|
78
|
+
function encodeExtMeshFeatures(scenegraph, options) {
|
|
79
|
+
const meshes = scenegraph.gltf.json.meshes;
|
|
80
|
+
if (!meshes) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
// Iterate through all meshes/primitives.
|
|
84
|
+
for (const mesh of meshes) {
|
|
85
|
+
for (const primitive of mesh.primitives) {
|
|
86
|
+
encodeExtMeshFeaturesForPrimitive(scenegraph, primitive);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Creates ExtMeshFeatures, creates a featureId containing feature ids provided.
|
|
92
|
+
* @param scenegraph - Instance of the class for structured access to GLTF data.
|
|
93
|
+
* @param primitive - target primitive instance that will contain the extension
|
|
94
|
+
* @param featureIdArray - Array of feature id
|
|
95
|
+
* @param propertyTableIndex - index of the property table created by the ExtStructuralMetadata (optional).
|
|
96
|
+
*/
|
|
97
|
+
export function createExtMeshFeatures(scenegraph, primitive, featureIdArray, propertyTableIndex) {
|
|
98
|
+
if (!primitive.extensions) {
|
|
99
|
+
primitive.extensions = {};
|
|
100
|
+
}
|
|
101
|
+
let extension = primitive.extensions[EXT_MESH_FEATURES_NAME];
|
|
102
|
+
if (!extension) {
|
|
103
|
+
extension = { featureIds: [] };
|
|
104
|
+
primitive.extensions[EXT_MESH_FEATURES_NAME] = extension;
|
|
105
|
+
}
|
|
106
|
+
const { featureIds } = extension;
|
|
107
|
+
const featureId = {
|
|
108
|
+
featureCount: featureIdArray.length,
|
|
109
|
+
propertyTable: propertyTableIndex,
|
|
110
|
+
data: featureIdArray
|
|
111
|
+
};
|
|
112
|
+
featureIds.push(featureId);
|
|
113
|
+
scenegraph.addObjectExtension(primitive, EXT_MESH_FEATURES_NAME, extension);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Encodes a feature ID set to extension.
|
|
117
|
+
* @param scenegraph - Instance of the class for structured access to GLTF data.
|
|
118
|
+
* @param primitive - Primitive that the data encoded belongs to.
|
|
119
|
+
* @see https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_mesh_features
|
|
120
|
+
*/
|
|
121
|
+
function encodeExtMeshFeaturesForPrimitive(scenegraph, primitive) {
|
|
122
|
+
const extension = primitive.extensions?.[EXT_MESH_FEATURES_NAME];
|
|
123
|
+
if (!extension) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
const featureIds = extension.featureIds;
|
|
127
|
+
featureIds.forEach((featureId, elementIndex) => {
|
|
128
|
+
if (featureId.data) {
|
|
129
|
+
const { accessorKey, index } = createAccessorKey(primitive.attributes);
|
|
130
|
+
const typedArray = new Uint32Array(featureId.data);
|
|
131
|
+
// Clean up featureId object.
|
|
132
|
+
// Everything that could come from the original extension in case of round-trip decode/encode operations should be deleted.
|
|
133
|
+
// We need make sure the featureId object is clean.
|
|
134
|
+
featureIds[elementIndex] = {
|
|
135
|
+
featureCount: typedArray.length,
|
|
136
|
+
propertyTable: featureId.propertyTable,
|
|
137
|
+
attribute: index
|
|
138
|
+
};
|
|
139
|
+
scenegraph.gltf.buffers.push({
|
|
140
|
+
arrayBuffer: typedArray.buffer,
|
|
141
|
+
byteOffset: typedArray.byteOffset,
|
|
142
|
+
byteLength: typedArray.byteLength
|
|
143
|
+
});
|
|
144
|
+
const bufferViewIndex = scenegraph.addBufferView(typedArray);
|
|
145
|
+
const accessorIndex = scenegraph.addAccessor(bufferViewIndex, {
|
|
146
|
+
size: 1,
|
|
147
|
+
componentType: getComponentTypeFromArray(typedArray),
|
|
148
|
+
count: typedArray.length
|
|
149
|
+
});
|
|
150
|
+
primitive.attributes[accessorKey] = accessorIndex;
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Creates an accessor key for the attribute array provided.
|
|
156
|
+
* The generated key has a suffix (number) that is the next consequtive in the list of existing accessors.
|
|
157
|
+
* @param attributes - attribute array
|
|
158
|
+
* @returns accessor key and the key suffix (number) used in the key.
|
|
159
|
+
*/
|
|
160
|
+
function createAccessorKey(attributes) {
|
|
161
|
+
const prefix = '_FEATURE_ID_';
|
|
162
|
+
// Search for all "_FEATURE_ID_n" attribures in the primitive provided if any.
|
|
163
|
+
// If there are some, e.g. "_FEATURE_ID_0", "_FEATURE_ID_1",
|
|
164
|
+
// we will add a new one with the name "_FEATURE_ID_2"
|
|
165
|
+
const attrs = Object.keys(attributes).filter((item) => item.indexOf(prefix) === 0);
|
|
166
|
+
let max = -1;
|
|
167
|
+
for (const a of attrs) {
|
|
168
|
+
const n = Number(a.substring(prefix.length));
|
|
169
|
+
if (n > max) {
|
|
170
|
+
max = n;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
max++;
|
|
174
|
+
const accessorKey = `${prefix}${max}`;
|
|
175
|
+
return { accessorKey, index: max };
|
|
176
|
+
}
|
|
@@ -1,7 +1,26 @@
|
|
|
1
1
|
import type { GLTF } from "../types/gltf-json-schema.js";
|
|
2
2
|
import type { GLTFLoaderOptions } from "../../gltf-loader.js";
|
|
3
|
+
import { GLTFWriterOptions } from "../../gltf-writer.js";
|
|
4
|
+
import { GLTFScenegraph } from "../api/gltf-scenegraph.js";
|
|
3
5
|
export declare const name = "EXT_structural_metadata";
|
|
4
6
|
export declare function decode(gltfData: {
|
|
5
7
|
json: GLTF;
|
|
6
8
|
}, options: GLTFLoaderOptions): Promise<void>;
|
|
9
|
+
export declare function encode(gltfData: {
|
|
10
|
+
json: GLTF;
|
|
11
|
+
}, options: GLTFWriterOptions): import("../..").GLTFWithBuffers;
|
|
12
|
+
export interface PropertyAttribute {
|
|
13
|
+
name: string;
|
|
14
|
+
elementType: string;
|
|
15
|
+
componentType?: string;
|
|
16
|
+
values: number[] | string[];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Creates ExtStructuralMetadata, creates the schema and creates a property table containing feature data provided.
|
|
20
|
+
* @param scenegraph - Instance of the class for structured access to GLTF data.
|
|
21
|
+
* @param propertyAttributes - property attributes
|
|
22
|
+
* @param classId - classId to use for encoding metadata.
|
|
23
|
+
* @returns Index of the table created.
|
|
24
|
+
*/
|
|
25
|
+
export declare function createExtStructuralMetadata(scenegraph: GLTFScenegraph, propertyAttributes: PropertyAttribute[], classId?: string): number;
|
|
7
26
|
//# sourceMappingURL=EXT_structural_metadata.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EXT_structural_metadata.d.ts","sourceRoot":"","sources":["../../../src/lib/extensions/EXT_structural_metadata.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,IAAI,EAA6C,qCAAkC;
|
|
1
|
+
{"version":3,"file":"EXT_structural_metadata.d.ts","sourceRoot":"","sources":["../../../src/lib/extensions/EXT_structural_metadata.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,IAAI,EAA6C,qCAAkC;AAahG,OAAO,KAAK,EAAC,iBAAiB,EAAC,6BAA0B;AACzD,OAAO,EAAC,iBAAiB,EAAC,6BAA0B;AAEpD,OAAO,EAAC,cAAc,EAAC,kCAA+B;AActD,eAAO,MAAM,IAAI,4BAA+B,CAAC;AAEjD,wBAAsB,MAAM,CAAC,QAAQ,EAAE;IAAC,IAAI,EAAE,IAAI,CAAA;CAAC,EAAE,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAG9F;AAED,wBAAgB,MAAM,CAAC,QAAQ,EAAE;IAAC,IAAI,EAAE,IAAI,CAAA;CAAC,EAAE,OAAO,EAAE,iBAAiB,mCAKxE;AA+pBD,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC;CAC7B;AA4CD;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CACzC,UAAU,EAAE,cAAc,EAC1B,kBAAkB,EAAE,iBAAiB,EAAE,EACvC,OAAO,GAAE,MAAgC,GACxC,MAAM,CAeR"}
|
|
@@ -6,6 +6,12 @@ export async function decode(gltfData, options) {
|
|
|
6
6
|
const scenegraph = new GLTFScenegraph(gltfData);
|
|
7
7
|
decodeExtStructuralMetadata(scenegraph, options);
|
|
8
8
|
}
|
|
9
|
+
export function encode(gltfData, options) {
|
|
10
|
+
const scenegraph = new GLTFScenegraph(gltfData);
|
|
11
|
+
encodeExtStructuralMetadata(scenegraph, options);
|
|
12
|
+
scenegraph.createBinaryChunk();
|
|
13
|
+
return scenegraph.gltf;
|
|
14
|
+
}
|
|
9
15
|
/*
|
|
10
16
|
// Example of the extension.
|
|
11
17
|
// See more info at https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_structural_metadata
|
|
@@ -484,3 +490,165 @@ function getEnumByValue(enumEntry, value) {
|
|
|
484
490
|
}
|
|
485
491
|
return null;
|
|
486
492
|
}
|
|
493
|
+
const SCHEMA_CLASS_ID_DEFAULT = 'schemaClassId';
|
|
494
|
+
function encodeExtStructuralMetadata(scenegraph, options) {
|
|
495
|
+
const extension = scenegraph.getExtension(EXT_STRUCTURAL_METADATA_NAME);
|
|
496
|
+
if (!extension) {
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
if (extension.propertyTables) {
|
|
500
|
+
for (const table of extension.propertyTables) {
|
|
501
|
+
const classId = table.class;
|
|
502
|
+
const schemaClass = extension.schema?.classes?.[classId];
|
|
503
|
+
if (table.properties && schemaClass) {
|
|
504
|
+
encodeProperties(table, schemaClass, scenegraph);
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
function encodeProperties(table, schemaClass, scenegraph) {
|
|
510
|
+
for (const propertyName in table.properties) {
|
|
511
|
+
const data = table.properties[propertyName].data;
|
|
512
|
+
if (data) {
|
|
513
|
+
const classProperty = schemaClass.properties[propertyName];
|
|
514
|
+
if (classProperty) {
|
|
515
|
+
const tableProperty = createPropertyTableProperty(data, classProperty, scenegraph);
|
|
516
|
+
// Override table property that came with "data"
|
|
517
|
+
table.properties[propertyName] = tableProperty;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
/**
|
|
523
|
+
* Creates ExtStructuralMetadata, creates the schema and creates a property table containing feature data provided.
|
|
524
|
+
* @param scenegraph - Instance of the class for structured access to GLTF data.
|
|
525
|
+
* @param propertyAttributes - property attributes
|
|
526
|
+
* @param classId - classId to use for encoding metadata.
|
|
527
|
+
* @returns Index of the table created.
|
|
528
|
+
*/
|
|
529
|
+
export function createExtStructuralMetadata(scenegraph, propertyAttributes, classId = SCHEMA_CLASS_ID_DEFAULT) {
|
|
530
|
+
let extension = scenegraph.getExtension(EXT_STRUCTURAL_METADATA_NAME);
|
|
531
|
+
if (!extension) {
|
|
532
|
+
extension = scenegraph.addExtension(EXT_STRUCTURAL_METADATA_NAME);
|
|
533
|
+
}
|
|
534
|
+
extension.schema = createSchema(propertyAttributes, classId, extension.schema);
|
|
535
|
+
const table = createPropertyTable(propertyAttributes, classId, extension.schema);
|
|
536
|
+
if (!extension.propertyTables) {
|
|
537
|
+
extension.propertyTables = [];
|
|
538
|
+
}
|
|
539
|
+
return extension.propertyTables.push(table) - 1; // index of the table
|
|
540
|
+
}
|
|
541
|
+
function createSchema(propertyAttributes, classId, schemaToUpdate) {
|
|
542
|
+
const schema = schemaToUpdate ?? {
|
|
543
|
+
id: 'schema_id'
|
|
544
|
+
};
|
|
545
|
+
const schemaClass = {
|
|
546
|
+
properties: {}
|
|
547
|
+
};
|
|
548
|
+
for (const attribute of propertyAttributes) {
|
|
549
|
+
const classProperty = {
|
|
550
|
+
type: attribute.elementType,
|
|
551
|
+
componentType: attribute.componentType
|
|
552
|
+
};
|
|
553
|
+
schemaClass.properties[attribute.name] = classProperty;
|
|
554
|
+
}
|
|
555
|
+
schema.classes = {};
|
|
556
|
+
schema.classes[classId] = schemaClass;
|
|
557
|
+
return schema;
|
|
558
|
+
}
|
|
559
|
+
function createPropertyTable(propertyAttributes, classId, schema) {
|
|
560
|
+
const table = {
|
|
561
|
+
class: classId,
|
|
562
|
+
count: 0
|
|
563
|
+
};
|
|
564
|
+
// count is a number of rows in the table
|
|
565
|
+
let count = 0;
|
|
566
|
+
const schemaClass = schema.classes?.[classId];
|
|
567
|
+
for (const attribute of propertyAttributes) {
|
|
568
|
+
if (count === 0) {
|
|
569
|
+
count = attribute.values.length;
|
|
570
|
+
}
|
|
571
|
+
// The number of elements in all propertyAttributes must be the same
|
|
572
|
+
if (count !== attribute.values.length && attribute.values.length) {
|
|
573
|
+
throw new Error('Illegal values in attributes');
|
|
574
|
+
}
|
|
575
|
+
const classProperty = schemaClass?.properties[attribute.name];
|
|
576
|
+
if (classProperty) {
|
|
577
|
+
// const tableProperty = createPropertyTableProperty(attribute, classProperty, scenegraph);
|
|
578
|
+
if (!table.properties) {
|
|
579
|
+
table.properties = {};
|
|
580
|
+
}
|
|
581
|
+
// values is a required field. Its real value will be set while encoding data
|
|
582
|
+
table.properties[attribute.name] = { values: 0, data: attribute.values };
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
table.count = count;
|
|
586
|
+
return table;
|
|
587
|
+
}
|
|
588
|
+
function createPropertyTableProperty(
|
|
589
|
+
// attribute: PropertyAttribute,
|
|
590
|
+
values, classProperty, scenegraph) {
|
|
591
|
+
const prop = { values: 0 };
|
|
592
|
+
if (classProperty.type === 'STRING') {
|
|
593
|
+
const { stringData, stringOffsets } = createPropertyDataString(values);
|
|
594
|
+
prop.stringOffsets = createBufferView(stringOffsets, scenegraph);
|
|
595
|
+
prop.values = createBufferView(stringData, scenegraph);
|
|
596
|
+
}
|
|
597
|
+
else if (classProperty.type === 'SCALAR' && classProperty.componentType) {
|
|
598
|
+
const data = createPropertyDataScalar(values, classProperty.componentType);
|
|
599
|
+
prop.values = createBufferView(data, scenegraph);
|
|
600
|
+
}
|
|
601
|
+
return prop;
|
|
602
|
+
}
|
|
603
|
+
const COMPONENT_TYPE_TO_ARRAY_CONSTRUCTOR = {
|
|
604
|
+
INT8: Int8Array,
|
|
605
|
+
UINT8: Uint8Array,
|
|
606
|
+
INT16: Int16Array,
|
|
607
|
+
UINT16: Uint16Array,
|
|
608
|
+
INT32: Int32Array,
|
|
609
|
+
UINT32: Uint32Array,
|
|
610
|
+
INT64: Int32Array,
|
|
611
|
+
UINT64: Uint32Array,
|
|
612
|
+
FLOAT32: Float32Array,
|
|
613
|
+
FLOAT64: Float64Array
|
|
614
|
+
};
|
|
615
|
+
function createPropertyDataScalar(array, componentType) {
|
|
616
|
+
const numberArray = [];
|
|
617
|
+
for (const value of array) {
|
|
618
|
+
numberArray.push(Number(value));
|
|
619
|
+
}
|
|
620
|
+
const Construct = COMPONENT_TYPE_TO_ARRAY_CONSTRUCTOR[componentType];
|
|
621
|
+
if (!Construct) {
|
|
622
|
+
throw new Error('Illegal component type');
|
|
623
|
+
}
|
|
624
|
+
return new Construct(numberArray);
|
|
625
|
+
}
|
|
626
|
+
function createPropertyDataString(strings) {
|
|
627
|
+
const utf8Encode = new TextEncoder();
|
|
628
|
+
const arr = [];
|
|
629
|
+
let len = 0;
|
|
630
|
+
for (const str of strings) {
|
|
631
|
+
const uint8Array = utf8Encode.encode(str);
|
|
632
|
+
len += uint8Array.length;
|
|
633
|
+
arr.push(uint8Array);
|
|
634
|
+
}
|
|
635
|
+
const strArray = new Uint8Array(len);
|
|
636
|
+
const strOffsets = [];
|
|
637
|
+
let offset = 0;
|
|
638
|
+
for (const str of arr) {
|
|
639
|
+
strArray.set(str, offset);
|
|
640
|
+
strOffsets.push(offset);
|
|
641
|
+
offset += str.length;
|
|
642
|
+
}
|
|
643
|
+
strOffsets.push(offset); // The last offset represents the byte offset after the last string.
|
|
644
|
+
const stringOffsetsTypedArray = new Uint32Array(strOffsets); // Its length = len+1
|
|
645
|
+
return { stringData: strArray, stringOffsets: stringOffsetsTypedArray };
|
|
646
|
+
}
|
|
647
|
+
function createBufferView(typedArray, scenegraph) {
|
|
648
|
+
scenegraph.gltf.buffers.push({
|
|
649
|
+
arrayBuffer: typedArray.buffer,
|
|
650
|
+
byteOffset: typedArray.byteOffset,
|
|
651
|
+
byteLength: typedArray.byteLength
|
|
652
|
+
});
|
|
653
|
+
return scenegraph.addBufferView(typedArray);
|
|
654
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
// Version constant cannot be imported, it needs to correspond to the build version of **this** module.
|
|
2
2
|
// __VERSION__ is injected by babel-plugin-version-inline
|
|
3
3
|
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|
|
4
|
-
export const VERSION = typeof "4.3.0-alpha.
|
|
4
|
+
export const VERSION = typeof "4.3.0-alpha.7" !== 'undefined' ? "4.3.0-alpha.7" : 'latest';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/gltf",
|
|
3
|
-
"version": "4.3.0-alpha.
|
|
3
|
+
"version": "4.3.0-alpha.8",
|
|
4
4
|
"description": "Framework-independent loader for the glTF format",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -43,15 +43,15 @@
|
|
|
43
43
|
"build-bundle-dev": "ocular-bundle ./bundle.ts --env=dev --output=dist/dist.dev.js"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@loaders.gl/draco": "4.3.0-alpha.
|
|
47
|
-
"@loaders.gl/images": "4.3.0-alpha.
|
|
48
|
-
"@loaders.gl/loader-utils": "4.3.0-alpha.
|
|
49
|
-
"@loaders.gl/schema": "4.3.0-alpha.
|
|
50
|
-
"@loaders.gl/textures": "4.3.0-alpha.
|
|
51
|
-
"@math.gl/core": "^4.
|
|
46
|
+
"@loaders.gl/draco": "4.3.0-alpha.8",
|
|
47
|
+
"@loaders.gl/images": "4.3.0-alpha.8",
|
|
48
|
+
"@loaders.gl/loader-utils": "4.3.0-alpha.8",
|
|
49
|
+
"@loaders.gl/schema": "4.3.0-alpha.8",
|
|
50
|
+
"@loaders.gl/textures": "4.3.0-alpha.8",
|
|
51
|
+
"@math.gl/core": "^4.1.0"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"@loaders.gl/core": "^4.0.0"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "c458e0c3a09543cd7c4a293d3c3f08c12acf78c0"
|
|
57
57
|
}
|
package/src/glb-writer.ts
CHANGED
|
@@ -34,7 +34,7 @@ export const GLBWriter = {
|
|
|
34
34
|
} as const satisfies WriterWithEncoder<GLB, never, GLBWriterOptions>;
|
|
35
35
|
|
|
36
36
|
function encodeSync(glb, options) {
|
|
37
|
-
const {byteOffset = 0} = options;
|
|
37
|
+
const {byteOffset = 0} = options ?? {};
|
|
38
38
|
|
|
39
39
|
// Calculate length and allocate buffer
|
|
40
40
|
const byteLength = encodeGLBSync(glb, null, byteOffset, options);
|
package/src/gltf-writer.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type {WriterOptions, WriterWithEncoder} from '@loaders.gl/loader-utils';
|
|
2
2
|
import {VERSION} from './lib/utils/version';
|
|
3
3
|
import {encodeGLTFSync} from './lib/encoders/encode-gltf';
|
|
4
|
+
import {GLTFWithBuffers} from '@loaders.gl/gltf';
|
|
5
|
+
import {encodeExtensions} from './lib/api/gltf-extensions';
|
|
4
6
|
|
|
5
7
|
export type GLTFWriterOptions = WriterOptions & {
|
|
6
8
|
gltf?: {};
|
|
@@ -26,18 +28,20 @@ export const GLTFWriter = {
|
|
|
26
28
|
gltf: {}
|
|
27
29
|
},
|
|
28
30
|
|
|
29
|
-
encode: async (gltf, options: GLTFWriterOptions = {}) =>
|
|
31
|
+
encode: async (gltf: GLTFWithBuffers, options: GLTFWriterOptions = {}) =>
|
|
32
|
+
encodeSync(gltf, options),
|
|
30
33
|
encodeSync
|
|
31
34
|
} as WriterWithEncoder<any, never, GLTFWriterOptions>;
|
|
32
35
|
|
|
33
|
-
function encodeSync(gltf, options: GLTFWriterOptions = {}) {
|
|
36
|
+
function encodeSync(gltf: GLTFWithBuffers, options: GLTFWriterOptions = {}) {
|
|
34
37
|
const {byteOffset = 0} = options;
|
|
38
|
+
const gltfToEncode = encodeExtensions(gltf);
|
|
35
39
|
|
|
36
40
|
// Calculate length, then create arraybuffer and encode
|
|
37
|
-
const byteLength = encodeGLTFSync(
|
|
41
|
+
const byteLength = encodeGLTFSync(gltfToEncode, null, byteOffset, options);
|
|
38
42
|
const arrayBuffer = new ArrayBuffer(byteLength);
|
|
39
43
|
const dataView = new DataView(arrayBuffer);
|
|
40
|
-
encodeGLTFSync(
|
|
44
|
+
encodeGLTFSync(gltfToEncode, dataView, byteOffset, options);
|
|
41
45
|
|
|
42
46
|
return arrayBuffer;
|
|
43
47
|
}
|
package/src/index.ts
CHANGED
|
@@ -91,3 +91,9 @@ export {GLBWriter} from './glb-writer';
|
|
|
91
91
|
export {GLTFScenegraph} from './lib/api/gltf-scenegraph';
|
|
92
92
|
export {postProcessGLTF} from './lib/api/post-process-gltf';
|
|
93
93
|
export {getMemoryUsageGLTF as _getMemoryUsageGLTF} from './lib/gltf-utils/gltf-utils';
|
|
94
|
+
|
|
95
|
+
export {
|
|
96
|
+
createExtStructuralMetadata,
|
|
97
|
+
type PropertyAttribute
|
|
98
|
+
} from './lib/extensions/EXT_structural_metadata';
|
|
99
|
+
export {createExtMeshFeatures} from './lib/extensions/EXT_mesh_features';
|