@loaders.gl/gltf 4.2.0-alpha.4 → 4.2.0-alpha.5
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 +1049 -517
- package/dist/dist.min.js +9 -0
- package/dist/glb-loader.d.ts +2 -2
- package/dist/glb-loader.d.ts.map +1 -1
- package/dist/glb-loader.js +22 -21
- package/dist/glb-writer.d.ts +2 -2
- package/dist/glb-writer.d.ts.map +1 -1
- package/dist/glb-writer.js +27 -24
- package/dist/gltf-loader.d.ts +3 -3
- package/dist/gltf-loader.d.ts.map +1 -1
- package/dist/gltf-loader.js +31 -36
- package/dist/gltf-writer.js +24 -26
- package/dist/index.cjs +95 -284
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +17 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/lib/api/gltf-extensions.d.ts +2 -2
- package/dist/lib/api/gltf-extensions.d.ts.map +1 -1
- package/dist/lib/api/gltf-extensions.js +45 -22
- package/dist/lib/api/gltf-scenegraph.d.ts +2 -2
- package/dist/lib/api/gltf-scenegraph.d.ts.map +1 -1
- package/dist/lib/api/gltf-scenegraph.js +561 -438
- package/dist/lib/api/normalize-gltf-v1.js +250 -181
- package/dist/lib/api/post-process-gltf.d.ts +3 -3
- package/dist/lib/api/post-process-gltf.d.ts.map +1 -1
- package/dist/lib/api/post-process-gltf.js +375 -339
- package/dist/lib/encoders/encode-glb.js +62 -48
- package/dist/lib/encoders/encode-gltf.js +24 -10
- package/dist/lib/extensions/EXT_mesh_features.d.ts +2 -2
- package/dist/lib/extensions/EXT_mesh_features.d.ts.map +1 -1
- package/dist/lib/extensions/EXT_mesh_features.js +55 -33
- package/dist/lib/extensions/EXT_meshopt_compression.d.ts +2 -2
- package/dist/lib/extensions/EXT_meshopt_compression.d.ts.map +1 -1
- package/dist/lib/extensions/EXT_meshopt_compression.js +27 -31
- package/dist/lib/extensions/EXT_structural_metadata.d.ts +2 -2
- package/dist/lib/extensions/EXT_structural_metadata.d.ts.map +1 -1
- package/dist/lib/extensions/EXT_structural_metadata.js +434 -230
- package/dist/lib/extensions/EXT_texture_webp.d.ts +2 -2
- package/dist/lib/extensions/EXT_texture_webp.d.ts.map +1 -1
- package/dist/lib/extensions/EXT_texture_webp.js +24 -17
- package/dist/lib/extensions/KHR_binary_gltf.d.ts +1 -1
- package/dist/lib/extensions/KHR_binary_gltf.d.ts.map +1 -1
- package/dist/lib/extensions/KHR_binary_gltf.js +29 -15
- package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts +2 -2
- package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts.map +1 -1
- package/dist/lib/extensions/KHR_draco_mesh_compression.js +110 -87
- package/dist/lib/extensions/KHR_texture_basisu.d.ts +2 -2
- package/dist/lib/extensions/KHR_texture_basisu.d.ts.map +1 -1
- package/dist/lib/extensions/KHR_texture_basisu.js +19 -12
- package/dist/lib/extensions/KHR_texture_transform.d.ts +2 -2
- package/dist/lib/extensions/KHR_texture_transform.d.ts.map +1 -1
- package/dist/lib/extensions/KHR_texture_transform.js +194 -154
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts +2 -2
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts.map +1 -1
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.js +263 -143
- package/dist/lib/extensions/deprecated/KHR_lights_punctual.d.ts +1 -1
- package/dist/lib/extensions/deprecated/KHR_lights_punctual.d.ts.map +1 -1
- package/dist/lib/extensions/deprecated/KHR_lights_punctual.js +44 -32
- package/dist/lib/extensions/deprecated/KHR_materials_unlit.d.ts +1 -1
- package/dist/lib/extensions/deprecated/KHR_materials_unlit.d.ts.map +1 -1
- package/dist/lib/extensions/deprecated/KHR_materials_unlit.js +30 -24
- package/dist/lib/extensions/deprecated/KHR_techniques_webgl.d.ts +1 -1
- package/dist/lib/extensions/deprecated/KHR_techniques_webgl.d.ts.map +1 -1
- package/dist/lib/extensions/deprecated/KHR_techniques_webgl.js +65 -52
- package/dist/lib/extensions/utils/3d-tiles-utils.d.ts +2 -2
- package/dist/lib/extensions/utils/3d-tiles-utils.d.ts.map +1 -1
- package/dist/lib/extensions/utils/3d-tiles-utils.js +298 -181
- package/dist/lib/gltf-utils/get-typed-array.d.ts +1 -1
- package/dist/lib/gltf-utils/get-typed-array.d.ts.map +1 -1
- package/dist/lib/gltf-utils/get-typed-array.js +54 -42
- package/dist/lib/gltf-utils/gltf-attribute-utils.d.ts +1 -1
- package/dist/lib/gltf-utils/gltf-attribute-utils.d.ts.map +1 -1
- package/dist/lib/gltf-utils/gltf-attribute-utils.js +58 -52
- package/dist/lib/gltf-utils/gltf-constants.js +27 -27
- package/dist/lib/gltf-utils/gltf-utils.d.ts +1 -1
- package/dist/lib/gltf-utils/gltf-utils.d.ts.map +1 -1
- package/dist/lib/gltf-utils/gltf-utils.js +67 -60
- package/dist/lib/gltf-utils/resolve-url.js +12 -10
- package/dist/lib/parsers/parse-glb.d.ts +1 -1
- package/dist/lib/parsers/parse-glb.d.ts.map +1 -1
- package/dist/lib/parsers/parse-glb.js +132 -89
- package/dist/lib/parsers/parse-gltf.d.ts +3 -3
- package/dist/lib/parsers/parse-gltf.d.ts.map +1 -1
- package/dist/lib/parsers/parse-gltf.js +155 -126
- package/dist/lib/types/glb-types.js +0 -1
- package/dist/lib/types/gltf-ext-feature-metadata-schema.d.ts +1 -1
- package/dist/lib/types/gltf-ext-feature-metadata-schema.d.ts.map +1 -1
- package/dist/lib/types/gltf-ext-feature-metadata-schema.js +0 -1
- package/dist/lib/types/gltf-ext-mesh-features-schema.d.ts +1 -1
- package/dist/lib/types/gltf-ext-mesh-features-schema.d.ts.map +1 -1
- package/dist/lib/types/gltf-ext-mesh-features-schema.js +0 -1
- package/dist/lib/types/gltf-ext-structural-metadata-schema.d.ts +1 -1
- package/dist/lib/types/gltf-ext-structural-metadata-schema.d.ts.map +1 -1
- package/dist/lib/types/gltf-ext-structural-metadata-schema.js +0 -1
- package/dist/lib/types/gltf-json-schema.js +2 -1
- package/dist/lib/types/gltf-postprocessed-schema.js +2 -1
- package/dist/lib/types/gltf-types.d.ts +3 -3
- package/dist/lib/types/gltf-types.d.ts.map +1 -1
- package/dist/lib/types/gltf-types.js +1 -1
- package/dist/lib/utils/assert.js +6 -4
- package/dist/lib/utils/version.js +3 -1
- package/dist/meshopt/meshopt-decoder.js +86 -67
- package/dist/webp/webp.js +28 -19
- package/package.json +12 -8
- package/dist/glb-loader.js.map +0 -1
- package/dist/glb-writer.js.map +0 -1
- package/dist/gltf-loader.js.map +0 -1
- package/dist/gltf-writer.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/api/gltf-extensions.js.map +0 -1
- package/dist/lib/api/gltf-scenegraph.js.map +0 -1
- package/dist/lib/api/normalize-gltf-v1.js.map +0 -1
- package/dist/lib/api/post-process-gltf.js.map +0 -1
- package/dist/lib/encoders/encode-glb.js.map +0 -1
- package/dist/lib/encoders/encode-gltf.js.map +0 -1
- package/dist/lib/extensions/EXT_mesh_features.js.map +0 -1
- package/dist/lib/extensions/EXT_meshopt_compression.js.map +0 -1
- package/dist/lib/extensions/EXT_structural_metadata.js.map +0 -1
- package/dist/lib/extensions/EXT_texture_webp.js.map +0 -1
- package/dist/lib/extensions/KHR_binary_gltf.js.map +0 -1
- package/dist/lib/extensions/KHR_draco_mesh_compression.js.map +0 -1
- package/dist/lib/extensions/KHR_texture_basisu.js.map +0 -1
- package/dist/lib/extensions/KHR_texture_transform.js.map +0 -1
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.js.map +0 -1
- package/dist/lib/extensions/deprecated/KHR_lights_punctual.js.map +0 -1
- package/dist/lib/extensions/deprecated/KHR_materials_unlit.js.map +0 -1
- package/dist/lib/extensions/deprecated/KHR_techniques_webgl.js.map +0 -1
- package/dist/lib/extensions/utils/3d-tiles-utils.js.map +0 -1
- package/dist/lib/gltf-utils/get-typed-array.js.map +0 -1
- package/dist/lib/gltf-utils/gltf-attribute-utils.js.map +0 -1
- package/dist/lib/gltf-utils/gltf-constants.js.map +0 -1
- package/dist/lib/gltf-utils/gltf-utils.js.map +0 -1
- package/dist/lib/gltf-utils/resolve-url.js.map +0 -1
- package/dist/lib/parsers/parse-glb.js.map +0 -1
- package/dist/lib/parsers/parse-gltf.js.map +0 -1
- package/dist/lib/types/glb-types.js.map +0 -1
- package/dist/lib/types/gltf-ext-feature-metadata-schema.js.map +0 -1
- package/dist/lib/types/gltf-ext-mesh-features-schema.js.map +0 -1
- package/dist/lib/types/gltf-ext-structural-metadata-schema.js.map +0 -1
- package/dist/lib/types/gltf-json-schema.js.map +0 -1
- package/dist/lib/types/gltf-postprocessed-schema.js.map +0 -1
- package/dist/lib/types/gltf-types.js.map +0 -1
- package/dist/lib/utils/assert.js.map +0 -1
- package/dist/lib/utils/version.js.map +0 -1
- package/dist/meshopt/meshopt-decoder.js.map +0 -1
- package/dist/meshopt/meshopt-encoder.ts.disabled +0 -409
- package/dist/webp/webp.js.map +0 -1
|
@@ -1,54 +1,68 @@
|
|
|
1
|
+
/* eslint-disable camelcase, max-statements */
|
|
1
2
|
import { copyPaddedStringToDataView, copyPaddedArrayBufferToDataView } from '@loaders.gl/loader-utils';
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const byteOffsetJsonHeader = byteOffset;
|
|
24
|
-
if (dataView) {
|
|
25
|
-
dataView.setUint32(byteOffset + 0, 0, LE);
|
|
26
|
-
dataView.setUint32(byteOffset + 4, MAGIC_JSON, LE);
|
|
27
|
-
}
|
|
28
|
-
byteOffset += 8;
|
|
29
|
-
const jsonString = JSON.stringify(json);
|
|
30
|
-
byteOffset = copyPaddedStringToDataView(dataView, byteOffset, jsonString, 4);
|
|
31
|
-
if (dataView) {
|
|
32
|
-
const jsonByteLength = byteOffset - byteOffsetJsonHeader - 8;
|
|
33
|
-
dataView.setUint32(byteOffsetJsonHeader + 0, jsonByteLength, LE);
|
|
34
|
-
}
|
|
35
|
-
if (binary) {
|
|
36
|
-
const byteOffsetBinHeader = byteOffset;
|
|
3
|
+
// import type {GLB} from '../types/glb-types';
|
|
4
|
+
const MAGIC_glTF = 0x46546c67; // glTF in ASCII
|
|
5
|
+
const MAGIC_JSON = 0x4e4f534a; // JSON in ASCII
|
|
6
|
+
const MAGIC_BIN = 0x004e4942; // BIN\0 in ASCII
|
|
7
|
+
const LE = true; // Binary GLTF is little endian.
|
|
8
|
+
/**
|
|
9
|
+
* Encode the full GLB buffer with header etc
|
|
10
|
+
*
|
|
11
|
+
* @param glb
|
|
12
|
+
* @param dataView - if `null`, does not encode but just calculates length
|
|
13
|
+
* @param byteOffset
|
|
14
|
+
* @param options
|
|
15
|
+
* @returns
|
|
16
|
+
*
|
|
17
|
+
* @see https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#glb-file-format-specification
|
|
18
|
+
* @todo type GLB argument
|
|
19
|
+
*/
|
|
20
|
+
export function encodeGLBSync(glb, dataView, byteOffset = 0, options = {}) {
|
|
21
|
+
const { magic = MAGIC_glTF, version = 2, json = {}, binary } = glb;
|
|
22
|
+
const byteOffsetStart = byteOffset;
|
|
23
|
+
// Write GLB Header
|
|
37
24
|
if (dataView) {
|
|
38
|
-
|
|
39
|
-
|
|
25
|
+
dataView.setUint32(byteOffset + 0, magic, LE); // Magic number (the ASCII string 'glTF').
|
|
26
|
+
dataView.setUint32(byteOffset + 4, version, LE); // Version 2 of binary glTF container format uint32
|
|
27
|
+
dataView.setUint32(byteOffset + 8, 0, LE); // Total byte length of generated file (uint32), will be set last
|
|
40
28
|
}
|
|
41
|
-
byteOffset
|
|
42
|
-
byteOffset
|
|
29
|
+
const byteOffsetFileLength = byteOffset + 8;
|
|
30
|
+
byteOffset += 12; // GLB_FILE_HEADER_SIZE
|
|
31
|
+
// Write the JSON chunk header
|
|
32
|
+
const byteOffsetJsonHeader = byteOffset;
|
|
43
33
|
if (dataView) {
|
|
44
|
-
|
|
45
|
-
|
|
34
|
+
dataView.setUint32(byteOffset + 0, 0, LE); // Byte length of json chunk (will be written later)
|
|
35
|
+
dataView.setUint32(byteOffset + 4, MAGIC_JSON, LE); // Chunk type
|
|
46
36
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
dataView
|
|
51
|
-
|
|
52
|
-
|
|
37
|
+
byteOffset += 8; // GLB_CHUNK_HEADER_SIZE
|
|
38
|
+
// Write the JSON chunk
|
|
39
|
+
const jsonString = JSON.stringify(json);
|
|
40
|
+
byteOffset = copyPaddedStringToDataView(dataView, byteOffset, jsonString, 4);
|
|
41
|
+
// Now we know the JSON chunk length so we can write it.
|
|
42
|
+
if (dataView) {
|
|
43
|
+
const jsonByteLength = byteOffset - byteOffsetJsonHeader - 8; // GLB_CHUNK_HEADER_SIZE
|
|
44
|
+
dataView.setUint32(byteOffsetJsonHeader + 0, jsonByteLength, LE); // Byte length of json chunk (uint32)
|
|
45
|
+
}
|
|
46
|
+
// Write the BIN chunk if present. The BIN chunk is optional.
|
|
47
|
+
if (binary) {
|
|
48
|
+
const byteOffsetBinHeader = byteOffset;
|
|
49
|
+
// Write the BIN chunk header
|
|
50
|
+
if (dataView) {
|
|
51
|
+
dataView.setUint32(byteOffset + 0, 0, LE); // Byte length BIN (uint32)
|
|
52
|
+
dataView.setUint32(byteOffset + 4, MAGIC_BIN, LE); // Chunk type
|
|
53
|
+
}
|
|
54
|
+
byteOffset += 8; // GLB_CHUNK_HEADER_SIZE
|
|
55
|
+
byteOffset = copyPaddedArrayBufferToDataView(dataView, byteOffset, binary, 4);
|
|
56
|
+
// Now we know the BIN chunk length so we can write it.
|
|
57
|
+
if (dataView) {
|
|
58
|
+
const binByteLength = byteOffset - byteOffsetBinHeader - 8; // GLB_CHUNK_HEADER_SIZE
|
|
59
|
+
dataView.setUint32(byteOffsetBinHeader + 0, binByteLength, LE); // Byte length BIN (uint32)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// Now we know the glb file length so we can write it.
|
|
63
|
+
if (dataView) {
|
|
64
|
+
const fileByteLength = byteOffset - byteOffsetStart;
|
|
65
|
+
dataView.setUint32(byteOffsetFileLength, fileByteLength, LE); // Total byte length of generated file (uint32)
|
|
66
|
+
}
|
|
67
|
+
return byteOffset;
|
|
53
68
|
}
|
|
54
|
-
//# sourceMappingURL=encode-glb.js.map
|
|
@@ -1,14 +1,28 @@
|
|
|
1
1
|
import { encodeGLBSync } from "./encode-glb.js";
|
|
2
|
+
/**
|
|
3
|
+
* Encode the full glTF file as a binary GLB file
|
|
4
|
+
* Returns an ArrayBuffer that represents the complete GLB image that can be saved to file
|
|
5
|
+
*
|
|
6
|
+
* @todo - Does not support encoding to non-GLB versions of glTF format. Other formats
|
|
7
|
+
* - Encode as a textual JSON file with binary data in base64 data URLs.
|
|
8
|
+
* - Encode as a JSON with all images (and buffers?) in separate binary files
|
|
9
|
+
*
|
|
10
|
+
* glb-file-format-specification
|
|
11
|
+
* @see https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#
|
|
12
|
+
*
|
|
13
|
+
* @param gltf
|
|
14
|
+
* @param arrayBuffer
|
|
15
|
+
* @param byteOffset
|
|
16
|
+
* @param options
|
|
17
|
+
* @returns
|
|
18
|
+
*/
|
|
2
19
|
export function encodeGLTFSync(gltf, arrayBuffer, byteOffset, options) {
|
|
3
|
-
|
|
4
|
-
|
|
20
|
+
convertBuffersToBase64(gltf);
|
|
21
|
+
// TODO: Copy buffers to binary
|
|
22
|
+
return encodeGLBSync(gltf, arrayBuffer, byteOffset, options);
|
|
5
23
|
}
|
|
6
|
-
function convertBuffersToBase64(gltf) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (gltf.buffers && gltf.buffers.length > firstBuffer) {
|
|
11
|
-
throw new Error('encodeGLTF: multiple buffers not yet implemented');
|
|
12
|
-
}
|
|
24
|
+
function convertBuffersToBase64(gltf, { firstBuffer = 0 } = {}) {
|
|
25
|
+
if (gltf.buffers && gltf.buffers.length > firstBuffer) {
|
|
26
|
+
throw new Error('encodeGLTF: multiple buffers not yet implemented');
|
|
27
|
+
}
|
|
13
28
|
}
|
|
14
|
-
//# sourceMappingURL=encode-gltf.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { GLTF } from
|
|
2
|
-
import { GLTFLoaderOptions } from
|
|
1
|
+
import type { GLTF } from "../types/gltf-json-schema.js";
|
|
2
|
+
import { GLTFLoaderOptions } from "../../gltf-loader.js";
|
|
3
3
|
export declare const name = "EXT_mesh_features";
|
|
4
4
|
export declare function decode(gltfData: {
|
|
5
5
|
json: GLTF;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EXT_mesh_features.d.ts","sourceRoot":"","sources":["../../../src/lib/extensions/EXT_mesh_features.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,IAAI,EAAoB,
|
|
1
|
+
{"version":3,"file":"EXT_mesh_features.d.ts","sourceRoot":"","sources":["../../../src/lib/extensions/EXT_mesh_features.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,IAAI,EAAoB,qCAAkC;AACvE,OAAO,EAAC,iBAAiB,EAAC,6BAA0B;AAUpD,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"}
|
|
@@ -3,43 +3,65 @@ import { getPrimitiveTextureData } from "./utils/3d-tiles-utils.js";
|
|
|
3
3
|
const EXT_MESH_FEATURES_NAME = 'EXT_mesh_features';
|
|
4
4
|
export const name = EXT_MESH_FEATURES_NAME;
|
|
5
5
|
export async function decode(gltfData, options) {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const scenegraph = new GLTFScenegraph(gltfData);
|
|
7
|
+
decodeExtMeshFeatures(scenegraph, options);
|
|
8
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Decodes feature metadata from extension.
|
|
11
|
+
* @param {GLTFScenegraph} scenegraph - Instance of the class for structured access to GLTF data.
|
|
12
|
+
* @param {GLTFLoaderOptions} options - GLTFLoader options.
|
|
13
|
+
*/
|
|
9
14
|
function decodeExtMeshFeatures(scenegraph, options) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
for (const
|
|
16
|
-
|
|
15
|
+
const json = scenegraph.gltf.json;
|
|
16
|
+
if (!json.meshes) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
// Iterate through all meshes/primitives.
|
|
20
|
+
for (const mesh of json.meshes) {
|
|
21
|
+
for (const primitive of mesh.primitives) {
|
|
22
|
+
processMeshPrimitiveFeatures(scenegraph, primitive, options);
|
|
23
|
+
}
|
|
17
24
|
}
|
|
18
|
-
}
|
|
19
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Takes data from EXT_mesh_features and store it in 'data' property of featureIds.
|
|
28
|
+
* If combined with EXT_structural_metadata, corresponding data are taken from the property tables of that extension.
|
|
29
|
+
* @param {GLTFScenegraph} scenegraph - Instance of the class for structured access to GLTF data.
|
|
30
|
+
* @param {GLTFMeshPrimitive} primitive - Primitive that contains extensions.
|
|
31
|
+
* @param {GLTFLoaderOptions} options - GLTFLoader options.
|
|
32
|
+
*/
|
|
20
33
|
function processMeshPrimitiveFeatures(scenegraph, primitive, options) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
34
|
+
// Processing of mesh primitive features requires buffers to be loaded.
|
|
35
|
+
if (!options?.gltf?.loadBuffers) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const extension = primitive.extensions?.[EXT_MESH_FEATURES_NAME];
|
|
39
|
+
const featureIds = extension?.featureIds;
|
|
40
|
+
if (!featureIds) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
for (const featureId of featureIds) {
|
|
44
|
+
let featureIdData;
|
|
45
|
+
// Process "Feature ID by Vertex"
|
|
46
|
+
if (typeof featureId.attribute !== 'undefined') {
|
|
47
|
+
const accessorKey = `_FEATURE_ID_${featureId.attribute}`;
|
|
48
|
+
const accessorIndex = primitive.attributes[accessorKey];
|
|
49
|
+
featureIdData = scenegraph.getTypedArrayForAccessor(accessorIndex);
|
|
50
|
+
}
|
|
51
|
+
// Process "Feature ID by Texture Coordinates"
|
|
52
|
+
else if (typeof featureId.texture !== 'undefined' && options?.gltf?.loadImages) {
|
|
53
|
+
featureIdData = getPrimitiveTextureData(scenegraph, featureId.texture, primitive);
|
|
54
|
+
}
|
|
55
|
+
// Process "Feature ID by Index"
|
|
56
|
+
else {
|
|
57
|
+
/*
|
|
58
|
+
When both featureId.attribute and featureId.texture are undefined,
|
|
59
|
+
then the feature ID value for each vertex is given implicitly, via the index of the vertex.
|
|
60
|
+
In this case, the featureCount must match the number of vertices of the mesh primitive.
|
|
61
|
+
*/
|
|
62
|
+
// TODO: At the moment of writing we don't have a tileset with the data of that kind. Implement it later.
|
|
63
|
+
featureIdData = [];
|
|
64
|
+
}
|
|
65
|
+
featureId.data = featureIdData;
|
|
41
66
|
}
|
|
42
|
-
featureId.data = featureIdData;
|
|
43
|
-
}
|
|
44
67
|
}
|
|
45
|
-
//# sourceMappingURL=EXT_mesh_features.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { GLTF } from
|
|
2
|
-
import type { GLTFLoaderOptions } from
|
|
1
|
+
import type { GLTF } from "../types/gltf-json-schema.js";
|
|
2
|
+
import type { GLTFLoaderOptions } from "../../gltf-loader.js";
|
|
3
3
|
export declare const name = "EXT_meshopt_compression";
|
|
4
4
|
export declare function decode(gltfData: {
|
|
5
5
|
json: GLTF;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EXT_meshopt_compression.d.ts","sourceRoot":"","sources":["../../../src/lib/extensions/EXT_meshopt_compression.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,IAAI,EAA+C,
|
|
1
|
+
{"version":3,"file":"EXT_meshopt_compression.d.ts","sourceRoot":"","sources":["../../../src/lib/extensions/EXT_meshopt_compression.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,IAAI,EAA+C,qCAAkC;AAClG,OAAO,KAAK,EAAC,iBAAiB,EAAC,6BAA0B;AAczD,eAAO,MAAM,IAAI,4BAA0B,CAAC;AAE5C,wBAAsB,MAAM,CAAC,QAAQ,EAAE;IAAC,IAAI,EAAE,IAAI,CAAA;CAAC,EAAE,OAAO,EAAE,iBAAiB,iBAiB9E"}
|
|
@@ -1,41 +1,37 @@
|
|
|
1
1
|
import { GLTFScenegraph } from "../api/gltf-scenegraph.js";
|
|
2
2
|
import { meshoptDecodeGltfBuffer } from "../../meshopt/meshopt-decoder.js";
|
|
3
|
+
// @ts-ignore
|
|
4
|
+
// eslint-disable-next-line
|
|
3
5
|
const DEFAULT_MESHOPT_OPTIONS = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
+
byteOffset: 0,
|
|
7
|
+
filter: 'NONE'
|
|
6
8
|
};
|
|
9
|
+
/** Extension name */
|
|
7
10
|
const EXT_MESHOPT_COMPRESSION = 'EXT_meshopt_compression';
|
|
8
11
|
export const name = EXT_MESHOPT_COMPRESSION;
|
|
9
12
|
export async function decode(gltfData, options) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
const scenegraph = new GLTFScenegraph(gltfData);
|
|
14
|
+
if (!options?.gltf?.decompressMeshes || !options.gltf?.loadBuffers) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const promises = [];
|
|
18
|
+
for (const bufferViewIndex of gltfData.json.bufferViews || []) {
|
|
19
|
+
promises.push(decodeMeshoptBufferView(scenegraph, bufferViewIndex));
|
|
20
|
+
}
|
|
21
|
+
// Decompress meshes in parallel
|
|
22
|
+
await Promise.all(promises);
|
|
23
|
+
// We have now decompressed all primitives, so remove the top-level extension
|
|
24
|
+
scenegraph.removeExtension(EXT_MESHOPT_COMPRESSION);
|
|
21
25
|
}
|
|
26
|
+
/** Decode one meshopt buffer view */
|
|
22
27
|
async function decodeMeshoptBufferView(scenegraph, bufferView) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
buffer: bufferIndex
|
|
33
|
-
} = meshoptExtension;
|
|
34
|
-
const buffer = scenegraph.gltf.buffers[bufferIndex];
|
|
35
|
-
const source = new Uint8Array(buffer.arrayBuffer, buffer.byteOffset + byteOffset, byteLength);
|
|
36
|
-
const result = new Uint8Array(scenegraph.gltf.buffers[bufferView.buffer].arrayBuffer, bufferView.byteOffset, bufferView.byteLength);
|
|
37
|
-
await meshoptDecodeGltfBuffer(result, count, byteStride, source, mode, filter);
|
|
38
|
-
scenegraph.removeObjectExtension(bufferView, EXT_MESHOPT_COMPRESSION);
|
|
39
|
-
}
|
|
28
|
+
const meshoptExtension = scenegraph.getObjectExtension(bufferView, EXT_MESHOPT_COMPRESSION);
|
|
29
|
+
if (meshoptExtension) {
|
|
30
|
+
const { byteOffset = 0, byteLength = 0, byteStride, count, mode, filter = 'NONE', buffer: bufferIndex } = meshoptExtension;
|
|
31
|
+
const buffer = scenegraph.gltf.buffers[bufferIndex];
|
|
32
|
+
const source = new Uint8Array(buffer.arrayBuffer, buffer.byteOffset + byteOffset, byteLength);
|
|
33
|
+
const result = new Uint8Array(scenegraph.gltf.buffers[bufferView.buffer].arrayBuffer, bufferView.byteOffset, bufferView.byteLength);
|
|
34
|
+
await meshoptDecodeGltfBuffer(result, count, byteStride, source, mode, filter);
|
|
35
|
+
scenegraph.removeObjectExtension(bufferView, EXT_MESHOPT_COMPRESSION);
|
|
36
|
+
}
|
|
40
37
|
}
|
|
41
|
-
//# sourceMappingURL=EXT_meshopt_compression.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { GLTF } from
|
|
2
|
-
import type { GLTFLoaderOptions } from
|
|
1
|
+
import type { GLTF } from "../types/gltf-json-schema.js";
|
|
2
|
+
import type { GLTFLoaderOptions } from "../../gltf-loader.js";
|
|
3
3
|
export declare const name = "EXT_structural_metadata";
|
|
4
4
|
export declare function decode(gltfData: {
|
|
5
5
|
json: GLTF;
|
|
@@ -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,
|
|
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;AAYhG,OAAO,KAAK,EAAC,iBAAiB,EAAC,6BAA0B;AAgBzD,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"}
|