@loaders.gl/gltf 4.0.0-alpha.6 → 4.0.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.min.js +1661 -1459
- package/dist/es5/glb-loader.js +2 -2
- package/dist/es5/glb-loader.js.map +1 -1
- package/dist/es5/glb-writer.js +3 -4
- package/dist/es5/glb-writer.js.map +1 -1
- package/dist/es5/gltf-loader.js +3 -3
- package/dist/es5/gltf-loader.js.map +1 -1
- package/dist/es5/index.js +9 -3
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/api/gltf-extensions.js.map +1 -1
- package/dist/es5/lib/api/gltf-scenegraph.js +52 -32
- package/dist/es5/lib/api/gltf-scenegraph.js.map +1 -1
- package/dist/es5/lib/api/post-process-gltf.js +164 -116
- package/dist/es5/lib/api/post-process-gltf.js.map +1 -1
- package/dist/es5/lib/encoders/encode-glb.js +1 -1
- package/dist/es5/lib/encoders/encode-glb.js.map +1 -1
- package/dist/es5/lib/encoders/encode-gltf.js +2 -3
- package/dist/es5/lib/encoders/encode-gltf.js.map +1 -1
- package/dist/es5/lib/extensions/EXT_meshopt_compression.js +3 -5
- package/dist/es5/lib/extensions/EXT_meshopt_compression.js.map +1 -1
- package/dist/es5/lib/extensions/EXT_texture_webp.js +2 -3
- package/dist/es5/lib/extensions/EXT_texture_webp.js.map +1 -1
- package/dist/es5/lib/extensions/KHR_binary_gltf.js +2 -3
- package/dist/es5/lib/extensions/KHR_binary_gltf.js.map +1 -1
- package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js +6 -5
- package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js.map +1 -1
- package/dist/es5/lib/extensions/KHR_texture_basisu.js +3 -4
- package/dist/es5/lib/extensions/KHR_texture_basisu.js.map +1 -1
- package/dist/es5/lib/extensions/KHR_texture_transform.js +9 -8
- package/dist/es5/lib/extensions/KHR_texture_transform.js.map +1 -1
- package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js +195 -17
- package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -1
- package/dist/es5/lib/extensions/deprecated/KHR_lights_punctual.js +3 -3
- package/dist/es5/lib/extensions/deprecated/KHR_lights_punctual.js.map +1 -1
- package/dist/es5/lib/extensions/deprecated/KHR_materials_unlit.js +3 -3
- package/dist/es5/lib/extensions/deprecated/KHR_materials_unlit.js.map +1 -1
- package/dist/es5/lib/extensions/deprecated/KHR_techniques_webgl.js +2 -2
- package/dist/es5/lib/extensions/deprecated/KHR_techniques_webgl.js.map +1 -1
- package/dist/es5/lib/gltf-utils/gltf-attribute-utils.js.map +1 -1
- package/dist/es5/lib/gltf-utils/gltf-utils.js +24 -0
- package/dist/es5/lib/gltf-utils/gltf-utils.js.map +1 -1
- package/dist/es5/lib/parsers/parse-glb.js +10 -10
- package/dist/es5/lib/parsers/parse-glb.js.map +1 -1
- package/dist/es5/lib/parsers/parse-gltf.js +18 -25
- package/dist/es5/lib/parsers/parse-gltf.js.map +1 -1
- package/dist/es5/lib/types/gltf-json-schema.js.map +1 -1
- package/dist/es5/lib/types/gltf-postprocessed-schema.js.map +1 -1
- package/dist/es5/lib/types/gltf-types.js.map +1 -1
- package/dist/es5/lib/utils/version.js +1 -1
- package/dist/esm/glb-loader.js +1 -1
- package/dist/esm/glb-loader.js.map +1 -1
- package/dist/esm/glb-writer.js +1 -1
- package/dist/esm/glb-writer.js.map +1 -1
- package/dist/esm/gltf-loader.js +3 -3
- package/dist/esm/gltf-loader.js.map +1 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/api/gltf-extensions.js.map +1 -1
- package/dist/esm/lib/api/gltf-scenegraph.js +45 -31
- package/dist/esm/lib/api/gltf-scenegraph.js.map +1 -1
- package/dist/esm/lib/api/post-process-gltf.js +167 -112
- package/dist/esm/lib/api/post-process-gltf.js.map +1 -1
- package/dist/esm/lib/encoders/encode-glb.js +1 -1
- package/dist/esm/lib/encoders/encode-glb.js.map +1 -1
- package/dist/esm/lib/encoders/encode-gltf.js +1 -1
- package/dist/esm/lib/encoders/encode-gltf.js.map +1 -1
- package/dist/esm/lib/extensions/EXT_meshopt_compression.js +2 -3
- package/dist/esm/lib/extensions/EXT_meshopt_compression.js.map +1 -1
- package/dist/esm/lib/extensions/EXT_texture_webp.js +1 -1
- package/dist/esm/lib/extensions/EXT_texture_webp.js.map +1 -1
- package/dist/esm/lib/extensions/KHR_binary_gltf.js +1 -1
- package/dist/esm/lib/extensions/KHR_binary_gltf.js.map +1 -1
- package/dist/esm/lib/extensions/KHR_draco_mesh_compression.js +5 -4
- package/dist/esm/lib/extensions/KHR_draco_mesh_compression.js.map +1 -1
- package/dist/esm/lib/extensions/KHR_texture_basisu.js +2 -2
- package/dist/esm/lib/extensions/KHR_texture_basisu.js.map +1 -1
- package/dist/esm/lib/extensions/KHR_texture_transform.js +7 -6
- package/dist/esm/lib/extensions/KHR_texture_transform.js.map +1 -1
- package/dist/esm/lib/extensions/deprecated/EXT_feature_metadata.js +161 -15
- package/dist/esm/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -1
- package/dist/esm/lib/extensions/deprecated/KHR_lights_punctual.js +1 -1
- package/dist/esm/lib/extensions/deprecated/KHR_lights_punctual.js.map +1 -1
- package/dist/esm/lib/extensions/deprecated/KHR_materials_unlit.js +1 -1
- package/dist/esm/lib/extensions/deprecated/KHR_materials_unlit.js.map +1 -1
- package/dist/esm/lib/extensions/deprecated/KHR_techniques_webgl.js +1 -1
- package/dist/esm/lib/extensions/deprecated/KHR_techniques_webgl.js.map +1 -1
- package/dist/esm/lib/gltf-utils/gltf-attribute-utils.js.map +1 -1
- package/dist/esm/lib/gltf-utils/gltf-utils.js +20 -0
- package/dist/esm/lib/gltf-utils/gltf-utils.js.map +1 -1
- package/dist/esm/lib/parsers/parse-glb.js +10 -10
- package/dist/esm/lib/parsers/parse-glb.js.map +1 -1
- package/dist/esm/lib/parsers/parse-gltf.js +7 -12
- package/dist/esm/lib/parsers/parse-gltf.js.map +1 -1
- package/dist/esm/lib/types/gltf-json-schema.js.map +1 -1
- package/dist/esm/lib/types/gltf-postprocessed-schema.js.map +1 -1
- package/dist/esm/lib/types/gltf-types.js.map +1 -1
- package/dist/esm/lib/utils/version.js +1 -1
- package/dist/glb-loader.d.ts +2 -2
- package/dist/glb-loader.js +2 -5
- package/dist/glb-writer.d.ts.map +1 -1
- package/dist/glb-writer.js +4 -6
- package/dist/gltf-loader.d.ts +5 -5
- package/dist/gltf-loader.d.ts.map +1 -1
- package/dist/gltf-loader.js +3 -3
- package/dist/index.d.ts +8 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -5
- package/dist/lib/api/gltf-extensions.d.ts +1 -1
- package/dist/lib/api/gltf-extensions.d.ts.map +1 -1
- package/dist/lib/api/gltf-extensions.js +1 -1
- package/dist/lib/api/gltf-scenegraph.d.ts +8 -5
- package/dist/lib/api/gltf-scenegraph.d.ts.map +1 -1
- package/dist/lib/api/gltf-scenegraph.js +47 -33
- package/dist/lib/api/post-process-gltf.d.ts +4 -1
- package/dist/lib/api/post-process-gltf.d.ts.map +1 -1
- package/dist/lib/api/post-process-gltf.js +186 -123
- package/dist/lib/encoders/encode-glb.d.ts +13 -1
- package/dist/lib/encoders/encode-glb.d.ts.map +1 -1
- package/dist/lib/encoders/encode-glb.js +15 -4
- package/dist/lib/encoders/encode-gltf.js +2 -5
- package/dist/lib/extensions/EXT_meshopt_compression.d.ts +1 -1
- package/dist/lib/extensions/EXT_meshopt_compression.d.ts.map +1 -1
- package/dist/lib/extensions/EXT_meshopt_compression.js +3 -7
- package/dist/lib/extensions/EXT_texture_webp.d.ts +1 -1
- package/dist/lib/extensions/EXT_texture_webp.d.ts.map +1 -1
- package/dist/lib/extensions/EXT_texture_webp.js +2 -5
- 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 +2 -5
- package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts +1 -1
- package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts.map +1 -1
- package/dist/lib/extensions/KHR_draco_mesh_compression.js +5 -8
- package/dist/lib/extensions/KHR_texture_basisu.d.ts +1 -1
- package/dist/lib/extensions/KHR_texture_basisu.d.ts.map +1 -1
- package/dist/lib/extensions/KHR_texture_basisu.js +3 -6
- package/dist/lib/extensions/KHR_texture_transform.d.ts.map +1 -1
- package/dist/lib/extensions/KHR_texture_transform.js +7 -10
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts +3 -2
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts.map +1 -1
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.js +195 -23
- 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 +3 -6
- 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 +3 -6
- 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 +2 -5
- 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-utils.d.ts +7 -0
- package/dist/lib/gltf-utils/gltf-utils.d.ts.map +1 -1
- package/dist/lib/gltf-utils/gltf-utils.js +28 -1
- package/dist/lib/parsers/parse-glb.d.ts +15 -3
- package/dist/lib/parsers/parse-glb.d.ts.map +1 -1
- package/dist/lib/parsers/parse-glb.js +43 -18
- package/dist/lib/parsers/parse-gltf.d.ts +8 -4
- package/dist/lib/parsers/parse-gltf.d.ts.map +1 -1
- package/dist/lib/parsers/parse-gltf.js +17 -41
- package/dist/lib/types/gltf-json-schema.d.ts +153 -139
- package/dist/lib/types/gltf-json-schema.d.ts.map +1 -1
- package/dist/lib/types/gltf-postprocessed-schema.d.ts +174 -209
- package/dist/lib/types/gltf-postprocessed-schema.d.ts.map +1 -1
- package/dist/lib/types/gltf-postprocessed-schema.js +1 -1
- package/dist/lib/types/gltf-types.d.ts +18 -6
- package/dist/lib/types/gltf-types.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/glb-loader.ts +3 -3
- package/src/glb-writer.ts +3 -1
- package/src/gltf-loader.ts +12 -8
- package/src/index.ts +32 -13
- package/src/lib/api/gltf-extensions.ts +1 -1
- package/src/lib/api/gltf-scenegraph.ts +60 -41
- package/src/lib/api/post-process-gltf.ts +275 -150
- package/src/lib/encoders/encode-glb.ts +15 -5
- package/src/lib/encoders/encode-gltf.ts +1 -1
- package/src/lib/extensions/EXT_meshopt_compression.ts +4 -6
- package/src/lib/extensions/EXT_texture_webp.ts +2 -2
- package/src/lib/extensions/KHR_binary_gltf.ts +2 -2
- package/src/lib/extensions/KHR_draco_mesh_compression.ts +7 -7
- package/src/lib/extensions/KHR_texture_basisu.ts +3 -3
- package/src/lib/extensions/KHR_texture_transform.ts +22 -19
- package/src/lib/extensions/deprecated/EXT_feature_metadata.ts +264 -23
- package/src/lib/extensions/deprecated/KHR_lights_punctual.ts +2 -2
- package/src/lib/extensions/deprecated/KHR_materials_unlit.ts +2 -2
- package/src/lib/extensions/deprecated/KHR_techniques_webgl.ts +2 -2
- package/src/lib/gltf-utils/gltf-attribute-utils.ts +1 -1
- package/src/lib/gltf-utils/gltf-utils.ts +31 -0
- package/src/lib/parsers/parse-glb.ts +50 -24
- package/src/lib/parsers/parse-gltf.ts +26 -25
- package/src/lib/types/gltf-json-schema.ts +168 -138
- package/src/lib/types/gltf-postprocessed-schema.ts +289 -212
- package/src/lib/types/gltf-types.ts +35 -59
|
@@ -1,3 +1,15 @@
|
|
|
1
1
|
export type GLBEncodeOptions = {};
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Encode the full GLB buffer with header etc
|
|
4
|
+
*
|
|
5
|
+
* @param glb
|
|
6
|
+
* @param dataView - if `null`, does not encode but just calculates length
|
|
7
|
+
* @param byteOffset
|
|
8
|
+
* @param options
|
|
9
|
+
* @returns
|
|
10
|
+
*
|
|
11
|
+
* @see https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#glb-file-format-specification
|
|
12
|
+
* @todo type GLB argument
|
|
13
|
+
*/
|
|
14
|
+
export declare function encodeGLBSync(glb: any, dataView: DataView | null, byteOffset?: number, options?: GLBEncodeOptions): number;
|
|
3
15
|
//# sourceMappingURL=encode-glb.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encode-glb.d.ts","sourceRoot":"","sources":["../../../src/lib/encoders/encode-glb.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"encode-glb.d.ts","sourceRoot":"","sources":["../../../src/lib/encoders/encode-glb.ts"],"names":[],"mappings":"AAaA,MAAM,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAElC;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAC3B,GAAG,KAAA,EACH,QAAQ,EAAE,QAAQ,GAAG,IAAI,EACzB,UAAU,SAAI,EACd,OAAO,GAAE,gBAAqB,UA4D/B"}
|
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.encodeGLBSync = void 0;
|
|
3
4
|
/* eslint-disable camelcase, max-statements */
|
|
4
5
|
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
6
|
+
// import type {GLB} from '../types/glb-types';
|
|
5
7
|
const MAGIC_glTF = 0x46546c67; // glTF in ASCII
|
|
6
8
|
const MAGIC_JSON = 0x4e4f534a; // JSON in ASCII
|
|
7
9
|
const MAGIC_BIN = 0x004e4942; // BIN\0 in ASCII
|
|
8
10
|
const LE = true; // Binary GLTF is little endian.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Encode the full GLB buffer with header etc
|
|
13
|
+
*
|
|
14
|
+
* @param glb
|
|
15
|
+
* @param dataView - if `null`, does not encode but just calculates length
|
|
16
|
+
* @param byteOffset
|
|
17
|
+
* @param options
|
|
18
|
+
* @returns
|
|
19
|
+
*
|
|
20
|
+
* @see https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#glb-file-format-specification
|
|
21
|
+
* @todo type GLB argument
|
|
22
|
+
*/
|
|
12
23
|
function encodeGLBSync(glb, dataView, byteOffset = 0, options = {}) {
|
|
13
24
|
const { magic = MAGIC_glTF, version = 2, json = {}, binary } = glb;
|
|
14
25
|
const byteOffsetStart = byteOffset;
|
|
@@ -58,4 +69,4 @@ function encodeGLBSync(glb, dataView, byteOffset = 0, options = {}) {
|
|
|
58
69
|
}
|
|
59
70
|
return byteOffset;
|
|
60
71
|
}
|
|
61
|
-
exports.
|
|
72
|
+
exports.encodeGLBSync = encodeGLBSync;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.encodeGLTFSync = void 0;
|
|
7
|
-
const encode_glb_1 =
|
|
4
|
+
const encode_glb_1 = require("./encode-glb");
|
|
8
5
|
/**
|
|
9
6
|
* Encode the full glTF file as a binary GLB file
|
|
10
7
|
* Returns an ArrayBuffer that represents the complete GLB image that can be saved to file
|
|
@@ -25,7 +22,7 @@ const encode_glb_1 = __importDefault(require("./encode-glb"));
|
|
|
25
22
|
function encodeGLTFSync(gltf, arrayBuffer, byteOffset, options) {
|
|
26
23
|
convertBuffersToBase64(gltf);
|
|
27
24
|
// TODO: Copy buffers to binary
|
|
28
|
-
return (0, encode_glb_1.
|
|
25
|
+
return (0, encode_glb_1.encodeGLBSync)(gltf, arrayBuffer, byteOffset, options);
|
|
29
26
|
}
|
|
30
27
|
exports.encodeGLTFSync = encodeGLTFSync;
|
|
31
28
|
function convertBuffersToBase64(gltf, { firstBuffer = 0 } = {}) {
|
|
@@ -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,MAAM,
|
|
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,MAAM,2BAA2B,CAAC;AAClG,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,mBAAmB,CAAC;AAczD,eAAO,MAAM,IAAI,4BAA0B,CAAC;AAE5C,wBAAsB,MAAM,CAAC,QAAQ,EAAE;IAAC,IAAI,EAAE,IAAI,CAAA;CAAC,EAAE,OAAO,EAAE,iBAAiB,iBAiB9E"}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.decode = exports.name = void 0;
|
|
7
|
-
const gltf_scenegraph_1 =
|
|
4
|
+
const gltf_scenegraph_1 = require("../api/gltf-scenegraph");
|
|
8
5
|
const meshopt_decoder_1 = require("../../meshopt/meshopt-decoder");
|
|
9
6
|
// @ts-ignore
|
|
10
7
|
// eslint-disable-next-line
|
|
@@ -16,7 +13,7 @@ const DEFAULT_MESHOPT_OPTIONS = {
|
|
|
16
13
|
const EXT_MESHOPT_COMPRESSION = 'EXT_meshopt_compression';
|
|
17
14
|
exports.name = EXT_MESHOPT_COMPRESSION;
|
|
18
15
|
async function decode(gltfData, options) {
|
|
19
|
-
const scenegraph = new gltf_scenegraph_1.
|
|
16
|
+
const scenegraph = new gltf_scenegraph_1.GLTFScenegraph(gltfData);
|
|
20
17
|
if (!options?.gltf?.decompressMeshes) {
|
|
21
18
|
return;
|
|
22
19
|
}
|
|
@@ -39,7 +36,6 @@ async function decodeMeshoptBufferView(scenegraph, bufferView) {
|
|
|
39
36
|
const source = new Uint8Array(buffer.arrayBuffer, buffer.byteOffset + byteOffset, byteLength);
|
|
40
37
|
const result = new Uint8Array(scenegraph.gltf.buffers[bufferView.buffer].arrayBuffer, bufferView.byteOffset, bufferView.byteLength);
|
|
41
38
|
await (0, meshopt_decoder_1.meshoptDecodeGltfBuffer)(result, count, byteStride, source, mode, filter);
|
|
42
|
-
|
|
39
|
+
scenegraph.removeObjectExtension(bufferView, EXT_MESHOPT_COMPRESSION);
|
|
43
40
|
}
|
|
44
|
-
return null;
|
|
45
41
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EXT_texture_webp.d.ts","sourceRoot":"","sources":["../../../src/lib/extensions/EXT_texture_webp.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,IAAI,EAAwB,MAAM,
|
|
1
|
+
{"version":3,"file":"EXT_texture_webp.d.ts","sourceRoot":"","sources":["../../../src/lib/extensions/EXT_texture_webp.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,IAAI,EAAwB,MAAM,2BAA2B,CAAC;AAC3E,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,mBAAmB,CAAC;AAOzD,qBAAqB;AACrB,eAAO,MAAM,IAAI,qBAAmB,CAAC;AAErC;;;GAGG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE;IAAC,IAAI,EAAE,IAAI,CAAA;CAAC,EAAE,OAAO,EAAE,iBAAiB,GAAG,IAAI,CA0BnF"}
|
|
@@ -2,13 +2,10 @@
|
|
|
2
2
|
// GLTF EXTENSION: EXT_TEXTURE_WEBP
|
|
3
3
|
// https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/EXT_TEXTURE_WEBP
|
|
4
4
|
/* eslint-disable camelcase */
|
|
5
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
-
};
|
|
8
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
6
|
exports.preprocess = exports.name = void 0;
|
|
10
7
|
const images_1 = require("@loaders.gl/images");
|
|
11
|
-
const gltf_scenegraph_1 =
|
|
8
|
+
const gltf_scenegraph_1 = require("../api/gltf-scenegraph");
|
|
12
9
|
const EXT_TEXTURE_WEBP = 'EXT_texture_webp';
|
|
13
10
|
/** Extension name */
|
|
14
11
|
exports.name = EXT_TEXTURE_WEBP;
|
|
@@ -17,7 +14,7 @@ exports.name = EXT_TEXTURE_WEBP;
|
|
|
17
14
|
* Done in preprocess() to prevent load of default image
|
|
18
15
|
*/
|
|
19
16
|
function preprocess(gltfData, options) {
|
|
20
|
-
const scenegraph = new gltf_scenegraph_1.
|
|
17
|
+
const scenegraph = new gltf_scenegraph_1.GLTFScenegraph(gltfData);
|
|
21
18
|
if (!(0, images_1.isImageFormatSupported)('image/webp')) {
|
|
22
19
|
if (scenegraph.getRequiredExtensions().includes(EXT_TEXTURE_WEBP)) {
|
|
23
20
|
throw new Error(`gltf: Required extension ${EXT_TEXTURE_WEBP} not supported by browser`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KHR_binary_gltf.d.ts","sourceRoot":"","sources":["../../../src/lib/extensions/KHR_binary_gltf.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,IAAI,EAAuB,MAAM,
|
|
1
|
+
{"version":3,"file":"KHR_binary_gltf.d.ts","sourceRoot":"","sources":["../../../src/lib/extensions/KHR_binary_gltf.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,IAAI,EAAuB,MAAM,2BAA2B,CAAC;AAM1E,qBAAqB;AACrB,eAAO,MAAM,IAAI,oBAAkB,CAAC;AAEpC,wBAAgB,UAAU,CAAC,QAAQ,EAAE;IAAC,IAAI,EAAE,IAAI,CAAA;CAAC,GAAG,IAAI,CA+BvD"}
|
|
@@ -2,17 +2,14 @@
|
|
|
2
2
|
// GLTF 1.0 EXTENSION: KHR_binary_glTF
|
|
3
3
|
// https://github.com/KhronosGroup/glTF/tree/master/extensions/1.0/Khronos/KHR_binary_glTF
|
|
4
4
|
/* eslint-disable camelcase */
|
|
5
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
-
};
|
|
8
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
6
|
exports.preprocess = exports.name = void 0;
|
|
10
|
-
const gltf_scenegraph_1 =
|
|
7
|
+
const gltf_scenegraph_1 = require("../api/gltf-scenegraph");
|
|
11
8
|
const KHR_BINARY_GLTF = 'KHR_binary_glTF';
|
|
12
9
|
/** Extension name */
|
|
13
10
|
exports.name = KHR_BINARY_GLTF;
|
|
14
11
|
function preprocess(gltfData) {
|
|
15
|
-
const gltfScenegraph = new gltf_scenegraph_1.
|
|
12
|
+
const gltfScenegraph = new gltf_scenegraph_1.GLTFScenegraph(gltfData);
|
|
16
13
|
const { json } = gltfScenegraph;
|
|
17
14
|
// Note: json.buffers.binary_glTF also needs to be replaced
|
|
18
15
|
// This is currently done during gltf normalization
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KHR_draco_mesh_compression.d.ts","sourceRoot":"","sources":["../../../src/lib/extensions/KHR_draco_mesh_compression.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,IAAI,EAIL,MAAM,
|
|
1
|
+
{"version":3,"file":"KHR_draco_mesh_compression.d.ts","sourceRoot":"","sources":["../../../src/lib/extensions/KHR_draco_mesh_compression.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,IAAI,EAIL,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,mBAAmB,CAAC;AAEzD,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAS5D,qBAAqB;AACrB,eAAO,MAAM,IAAI,+BAA6B,CAAC;AAE/C,wBAAgB,UAAU,CACxB,QAAQ,EAAE;IAAC,IAAI,EAAE,IAAI,CAAA;CAAC,EACtB,OAAO,EAAE,iBAAiB,EAC1B,OAAO,EAAE,aAAa,GACrB,IAAI,CAON;AAED,wBAAsB,MAAM,CAC1B,QAAQ,EAAE;IAAC,IAAI,EAAE,IAAI,CAAA;CAAC,EACtB,OAAO,EAAE,iBAAiB,EAC1B,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,IAAI,CAAC,CAkBf;AAED,wBAAgB,MAAM,CAAC,QAAQ,KAAA,EAAE,OAAO,GAAE,iBAAsB,GAAG,IAAI,CAUtE"}
|
|
@@ -2,20 +2,17 @@
|
|
|
2
2
|
// https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression
|
|
3
3
|
// Only TRIANGLES: 0x0004 and TRIANGLE_STRIP: 0x0005 are supported
|
|
4
4
|
/* eslint-disable camelcase */
|
|
5
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
-
};
|
|
8
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
6
|
exports.encode = exports.decode = exports.preprocess = exports.name = void 0;
|
|
10
7
|
const draco_1 = require("@loaders.gl/draco");
|
|
11
8
|
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
12
|
-
const gltf_scenegraph_1 =
|
|
9
|
+
const gltf_scenegraph_1 = require("../api/gltf-scenegraph");
|
|
13
10
|
const gltf_attribute_utils_1 = require("../gltf-utils/gltf-attribute-utils");
|
|
14
11
|
const KHR_DRACO_MESH_COMPRESSION = 'KHR_draco_mesh_compression';
|
|
15
12
|
/** Extension name */
|
|
16
13
|
exports.name = KHR_DRACO_MESH_COMPRESSION;
|
|
17
14
|
function preprocess(gltfData, options, context) {
|
|
18
|
-
const scenegraph = new gltf_scenegraph_1.
|
|
15
|
+
const scenegraph = new gltf_scenegraph_1.GLTFScenegraph(gltfData);
|
|
19
16
|
for (const primitive of makeMeshPrimitiveIterator(scenegraph)) {
|
|
20
17
|
if (scenegraph.getObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION)) {
|
|
21
18
|
// TODO - Remove fallback accessors to make sure we don't load unnecessary buffers
|
|
@@ -27,7 +24,7 @@ async function decode(gltfData, options, context) {
|
|
|
27
24
|
if (!options?.gltf?.decompressMeshes) {
|
|
28
25
|
return;
|
|
29
26
|
}
|
|
30
|
-
const scenegraph = new gltf_scenegraph_1.
|
|
27
|
+
const scenegraph = new gltf_scenegraph_1.GLTFScenegraph(gltfData);
|
|
31
28
|
const promises = [];
|
|
32
29
|
for (const primitive of makeMeshPrimitiveIterator(scenegraph)) {
|
|
33
30
|
if (scenegraph.getObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION)) {
|
|
@@ -41,7 +38,7 @@ async function decode(gltfData, options, context) {
|
|
|
41
38
|
}
|
|
42
39
|
exports.decode = decode;
|
|
43
40
|
function encode(gltfData, options = {}) {
|
|
44
|
-
const scenegraph = new gltf_scenegraph_1.
|
|
41
|
+
const scenegraph = new gltf_scenegraph_1.GLTFScenegraph(gltfData);
|
|
45
42
|
for (const mesh of scenegraph.json.meshes || []) {
|
|
46
43
|
// eslint-disable-next-line camelcase
|
|
47
44
|
// @ts-ignore
|
|
@@ -89,7 +86,7 @@ async function decompressPrimitive(scenegraph, primitive, options, context) {
|
|
|
89
86
|
primitive.indices = (0, gltf_attribute_utils_1.getGLTFAccessor)(decodedData.indices);
|
|
90
87
|
}
|
|
91
88
|
// Extension has been processed, delete it
|
|
92
|
-
|
|
89
|
+
scenegraph.removeObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION);
|
|
93
90
|
checkPrimitive(primitive);
|
|
94
91
|
}
|
|
95
92
|
// ENCODE
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KHR_texture_basisu.d.ts","sourceRoot":"","sources":["../../../src/lib/extensions/KHR_texture_basisu.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,IAAI,EAA0B,MAAM,
|
|
1
|
+
{"version":3,"file":"KHR_texture_basisu.d.ts","sourceRoot":"","sources":["../../../src/lib/extensions/KHR_texture_basisu.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,IAAI,EAA0B,MAAM,2BAA2B,CAAC;AAC7E,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,mBAAmB,CAAC;AAMzD,qBAAqB;AACrB,eAAO,MAAM,IAAI,uBAAqB,CAAC;AAEvC;;;GAGG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE;IAAC,IAAI,EAAE,IAAI,CAAA;CAAC,EAAE,OAAO,EAAE,iBAAiB,GAAG,IAAI,CAkBnF"}
|
|
@@ -2,12 +2,9 @@
|
|
|
2
2
|
// GLTF EXTENSION: KHR_texture_basisu
|
|
3
3
|
// https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_basisu
|
|
4
4
|
/* eslint-disable camelcase */
|
|
5
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
-
};
|
|
8
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
6
|
exports.preprocess = exports.name = void 0;
|
|
10
|
-
const gltf_scenegraph_1 =
|
|
7
|
+
const gltf_scenegraph_1 = require("../api/gltf-scenegraph");
|
|
11
8
|
const KHR_TEXTURE_BASISU = 'KHR_texture_basisu';
|
|
12
9
|
/** Extension name */
|
|
13
10
|
exports.name = KHR_TEXTURE_BASISU;
|
|
@@ -16,15 +13,15 @@ exports.name = KHR_TEXTURE_BASISU;
|
|
|
16
13
|
* Done in preprocess() to prevent load of default image
|
|
17
14
|
*/
|
|
18
15
|
function preprocess(gltfData, options) {
|
|
19
|
-
const scene = new gltf_scenegraph_1.
|
|
16
|
+
const scene = new gltf_scenegraph_1.GLTFScenegraph(gltfData);
|
|
20
17
|
const { json } = scene;
|
|
21
18
|
for (const texture of json.textures || []) {
|
|
22
19
|
const extension = scene.getObjectExtension(texture, KHR_TEXTURE_BASISU);
|
|
23
20
|
if (extension) {
|
|
24
21
|
// TODO - if multiple texture extensions are present which one wins?
|
|
25
22
|
texture.source = extension.source;
|
|
23
|
+
scene.removeObjectExtension(texture, KHR_TEXTURE_BASISU);
|
|
26
24
|
}
|
|
27
|
-
scene.removeObjectExtension(texture, KHR_TEXTURE_BASISU);
|
|
28
25
|
}
|
|
29
26
|
// Remove the top-level extension
|
|
30
27
|
scene.removeExtension(KHR_TEXTURE_BASISU);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KHR_texture_transform.d.ts","sourceRoot":"","sources":["../../../src/lib/extensions/KHR_texture_transform.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"KHR_texture_transform.d.ts","sourceRoot":"","sources":["../../../src/lib/extensions/KHR_texture_transform.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,qBAAqB,CAAC;AASzD,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,mBAAmB,CAAC;AAUzD,eAAO,MAAM,IAAI,0BAAwB,CAAC;AA+B1C;;;;GAIG;AACH,wBAAsB,MAAM,CAAC,QAAQ,EAAE,eAAe,EAAE,OAAO,EAAE,iBAAiB,iBAUjF"}
|
|
@@ -2,15 +2,12 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_texture_transform/README.md
|
|
4
4
|
*/
|
|
5
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
-
};
|
|
8
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
6
|
exports.decode = exports.name = void 0;
|
|
10
7
|
const core_1 = require("@math.gl/core");
|
|
11
8
|
const gltf_utils_1 = require("../gltf-utils/gltf-utils");
|
|
12
9
|
const gltf_constants_1 = require("../gltf-utils/gltf-constants");
|
|
13
|
-
const gltf_scenegraph_1 =
|
|
10
|
+
const gltf_scenegraph_1 = require("../api/gltf-scenegraph");
|
|
14
11
|
/** Extension name */
|
|
15
12
|
const EXT_MESHOPT_TRANSFORM = 'KHR_texture_transform';
|
|
16
13
|
exports.name = EXT_MESHOPT_TRANSFORM;
|
|
@@ -23,9 +20,9 @@ const scratchScaleMatrix = new core_1.Matrix3();
|
|
|
23
20
|
* @param options GLTFLoader options
|
|
24
21
|
*/
|
|
25
22
|
async function decode(gltfData, options) {
|
|
26
|
-
const gltfScenegraph = new gltf_scenegraph_1.
|
|
27
|
-
const
|
|
28
|
-
if (!
|
|
23
|
+
const gltfScenegraph = new gltf_scenegraph_1.GLTFScenegraph(gltfData);
|
|
24
|
+
const hasExtension = gltfScenegraph.hasExtension(EXT_MESHOPT_TRANSFORM);
|
|
25
|
+
if (!hasExtension) {
|
|
29
26
|
return;
|
|
30
27
|
}
|
|
31
28
|
const materials = gltfData.json.materials || [];
|
|
@@ -223,8 +220,8 @@ function createAttribute(newTexCoord, originalAccessor, primitive, gltfData, new
|
|
|
223
220
|
*/
|
|
224
221
|
function makeTransformationMatrix(extensionData) {
|
|
225
222
|
const { offset = [0, 0], rotation = 0, scale = [1, 1] } = extensionData;
|
|
226
|
-
const
|
|
227
|
-
const
|
|
223
|
+
const translationMatrix = new core_1.Matrix3().set(1, 0, 0, 0, 1, 0, offset[0], offset[1], 1);
|
|
224
|
+
const rotationMatrix = scratchRotationMatrix.set(Math.cos(rotation), Math.sin(rotation), 0, -Math.sin(rotation), Math.cos(rotation), 0, 0, 0, 1);
|
|
228
225
|
const scaleMatrix = scratchScaleMatrix.set(scale[0], 0, 0, 0, scale[1], 0, 0, 0, 1);
|
|
229
|
-
return
|
|
226
|
+
return translationMatrix.multiplyRight(rotationMatrix).multiplyRight(scaleMatrix);
|
|
230
227
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { GLTF } from '../../types/gltf-
|
|
1
|
+
import type { GLTF } from '../../types/gltf-json-schema';
|
|
2
|
+
import { GLTFLoaderOptions } from '../../../gltf-loader';
|
|
2
3
|
export declare const name = "EXT_feature_metadata";
|
|
3
4
|
export declare function decode(gltfData: {
|
|
4
5
|
json: GLTF;
|
|
5
|
-
}): Promise<void>;
|
|
6
|
+
}, options: GLTFLoaderOptions): Promise<void>;
|
|
6
7
|
//# sourceMappingURL=EXT_feature_metadata.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EXT_feature_metadata.d.ts","sourceRoot":"","sources":["../../../../src/lib/extensions/deprecated/EXT_feature_metadata.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"EXT_feature_metadata.d.ts","sourceRoot":"","sources":["../../../../src/lib/extensions/deprecated/EXT_feature_metadata.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,8BAA8B,CAAC;AAcvD,OAAO,EAAC,iBAAiB,EAAC,MAAM,sBAAsB,CAAC;AAKvD,eAAO,MAAM,IAAI,yBAAuB,CAAC;AAEzC,wBAAsB,MAAM,CAAC,QAAQ,EAAE;IAAC,IAAI,EAAE,IAAI,CAAA;CAAC,EAAE,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAG9F"}
|
|
@@ -1,35 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.decode = exports.name = void 0;
|
|
7
|
-
const gltf_scenegraph_1 =
|
|
4
|
+
const gltf_scenegraph_1 = require("../../api/gltf-scenegraph");
|
|
5
|
+
const images_1 = require("@loaders.gl/images");
|
|
6
|
+
const gltf_utils_1 = require("../../gltf-utils/gltf-utils");
|
|
8
7
|
/** Extension name */
|
|
9
8
|
const EXT_FEATURE_METADATA = 'EXT_feature_metadata';
|
|
10
9
|
exports.name = EXT_FEATURE_METADATA;
|
|
11
|
-
async function decode(gltfData) {
|
|
12
|
-
const scenegraph = new gltf_scenegraph_1.
|
|
13
|
-
decodeExtFeatureMetadata(scenegraph);
|
|
10
|
+
async function decode(gltfData, options) {
|
|
11
|
+
const scenegraph = new gltf_scenegraph_1.GLTFScenegraph(gltfData);
|
|
12
|
+
decodeExtFeatureMetadata(scenegraph, options);
|
|
14
13
|
}
|
|
15
14
|
exports.decode = decode;
|
|
16
15
|
/**
|
|
17
16
|
* Decodes feature metadata from extension
|
|
18
17
|
* @param scenegraph
|
|
19
18
|
*/
|
|
20
|
-
function decodeExtFeatureMetadata(scenegraph) {
|
|
19
|
+
function decodeExtFeatureMetadata(scenegraph, options) {
|
|
21
20
|
const extension = scenegraph.getExtension(EXT_FEATURE_METADATA);
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
/*
|
|
27
|
-
* TODO add support for featureTextures
|
|
28
|
-
* Spec - https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata#feature-textures
|
|
29
|
-
*/
|
|
30
|
-
// eslint-disable-next-line no-console
|
|
31
|
-
console.warn('featureTextures is not yet supported in the "EXT_feature_metadata" extension.');
|
|
32
|
-
}
|
|
21
|
+
if (!extension)
|
|
22
|
+
return;
|
|
23
|
+
const schemaClasses = extension.schema?.classes;
|
|
24
|
+
const { featureTables } = extension;
|
|
33
25
|
if (schemaClasses && featureTables) {
|
|
34
26
|
for (const schemaName in schemaClasses) {
|
|
35
27
|
const schemaClass = schemaClasses[schemaName];
|
|
@@ -39,6 +31,16 @@ function decodeExtFeatureMetadata(scenegraph) {
|
|
|
39
31
|
}
|
|
40
32
|
}
|
|
41
33
|
}
|
|
34
|
+
const { featureTextures } = extension;
|
|
35
|
+
if (schemaClasses && featureTextures && options.gltf?.loadImages) {
|
|
36
|
+
for (const schemaName in schemaClasses) {
|
|
37
|
+
const schemaClass = schemaClasses[schemaName];
|
|
38
|
+
const featureTexture = findFeatureTextureByName(featureTextures, schemaName);
|
|
39
|
+
if (featureTexture) {
|
|
40
|
+
handleFeatureTextureProperties(scenegraph, featureTexture, schemaClass);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
42
44
|
}
|
|
43
45
|
/**
|
|
44
46
|
* Navigate throw all properies in feature table and gets properties data.
|
|
@@ -57,6 +59,23 @@ function handleFeatureTableProperties(scenegraph, featureTable, schemaClass) {
|
|
|
57
59
|
}
|
|
58
60
|
}
|
|
59
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Navigate throw all properies in feature texture and gets properties data.
|
|
64
|
+
* Data will be stored in featureTexture.properties[propertyName].data
|
|
65
|
+
* @param scenegraph
|
|
66
|
+
* @param featureTexture
|
|
67
|
+
* @param schemaClass
|
|
68
|
+
*/
|
|
69
|
+
function handleFeatureTextureProperties(scenegraph, featureTexture, schemaClass) {
|
|
70
|
+
const attributeName = featureTexture.class;
|
|
71
|
+
for (const propertyName in schemaClass.properties) {
|
|
72
|
+
const featureTextureProperty = featureTexture?.properties?.[propertyName];
|
|
73
|
+
if (featureTextureProperty) {
|
|
74
|
+
const data = getPropertyDataFromTexture(scenegraph, featureTextureProperty, attributeName);
|
|
75
|
+
featureTextureProperty.data = data;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
60
79
|
/**
|
|
61
80
|
* Decode properties from binary sourse based on property type.
|
|
62
81
|
* @param scenegraph
|
|
@@ -67,18 +86,162 @@ function handleFeatureTableProperties(scenegraph, featureTable, schemaClass) {
|
|
|
67
86
|
function getPropertyDataFromBinarySource(scenegraph, schemaProperty, numberOfFeatures, featureTableProperty) {
|
|
68
87
|
const bufferView = featureTableProperty.bufferView;
|
|
69
88
|
// TODO think maybe we shouldn't get data only in Uint8Array format.
|
|
70
|
-
|
|
89
|
+
const dataArray = scenegraph.getTypedArrayForBufferView(bufferView);
|
|
71
90
|
switch (schemaProperty.type) {
|
|
72
91
|
case 'STRING': {
|
|
73
92
|
// stringOffsetBufferView should be available for string type.
|
|
74
93
|
const stringOffsetBufferView = featureTableProperty.stringOffsetBufferView;
|
|
75
94
|
const offsetsData = scenegraph.getTypedArrayForBufferView(stringOffsetBufferView);
|
|
76
|
-
|
|
77
|
-
break;
|
|
95
|
+
return getStringAttributes(dataArray, offsetsData, numberOfFeatures);
|
|
78
96
|
}
|
|
79
97
|
default:
|
|
80
98
|
}
|
|
81
|
-
return
|
|
99
|
+
return dataArray;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Get properties from texture associated with all mesh primitives.
|
|
103
|
+
* @param scenegraph
|
|
104
|
+
* @param featureTextureProperty
|
|
105
|
+
* @param attributeName
|
|
106
|
+
* @returns Feature texture data
|
|
107
|
+
*/
|
|
108
|
+
function getPropertyDataFromTexture(scenegraph, featureTextureProperty, attributeName) {
|
|
109
|
+
const json = scenegraph.gltf.json;
|
|
110
|
+
if (!json.meshes) {
|
|
111
|
+
return [];
|
|
112
|
+
}
|
|
113
|
+
const featureTextureTable = [];
|
|
114
|
+
for (const mesh of json.meshes) {
|
|
115
|
+
for (const primitive of mesh.primitives) {
|
|
116
|
+
processPrimitiveTextures(scenegraph, attributeName, featureTextureProperty, featureTextureTable, primitive);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return featureTextureTable;
|
|
120
|
+
}
|
|
121
|
+
// eslint-disable-next-line max-statements
|
|
122
|
+
/**
|
|
123
|
+
* Processes data encoded in the texture associated with the primitive. This data will be accessible through the attributes.
|
|
124
|
+
* @param scenegraph
|
|
125
|
+
* @param attributeName
|
|
126
|
+
* @param featureTextureProperty
|
|
127
|
+
* @param featureTextureTable
|
|
128
|
+
* @param primitive
|
|
129
|
+
*/
|
|
130
|
+
function processPrimitiveTextures(scenegraph, attributeName, featureTextureProperty, featureTextureTable, primitive) {
|
|
131
|
+
/*
|
|
132
|
+
texture.index is an index for the "textures" array.
|
|
133
|
+
The texture object referenced by this index looks like this:
|
|
134
|
+
{
|
|
135
|
+
"sampler": 0,
|
|
136
|
+
"source": 0
|
|
137
|
+
}
|
|
138
|
+
"sampler" is an index for the "samplers" array
|
|
139
|
+
"source" is an index for the "images" array that contains data. These data are stored in rgba channels of the image.
|
|
140
|
+
|
|
141
|
+
texture.texCoord is a number-suffix (like 1) for an attribute like "TEXCOORD_1" in meshes.primitives
|
|
142
|
+
The value of "TEXCOORD_1" is an accessor that is used to get coordinates. These coordinates ared used to get data from the image.
|
|
143
|
+
*/
|
|
144
|
+
const json = scenegraph.gltf.json;
|
|
145
|
+
const textureData = [];
|
|
146
|
+
const texCoordAccessorKey = `TEXCOORD_${featureTextureProperty.texture.texCoord}`;
|
|
147
|
+
const texCoordAccessorIndex = primitive.attributes[texCoordAccessorKey];
|
|
148
|
+
const texCoordBufferView = scenegraph.getBufferView(texCoordAccessorIndex);
|
|
149
|
+
const texCoordArray = scenegraph.getTypedArrayForBufferView(texCoordBufferView);
|
|
150
|
+
const textureCoordinates = new Float32Array(texCoordArray.buffer, texCoordArray.byteOffset, texCoordArray.length / 4);
|
|
151
|
+
// textureCoordinates contains UV coordinates of the actual data stored in the texture
|
|
152
|
+
// accessor.count is a number of UV pairs (they are stored as VEC2)
|
|
153
|
+
const textureIndex = featureTextureProperty.texture.index;
|
|
154
|
+
const texture = json.textures?.[textureIndex];
|
|
155
|
+
const imageIndex = texture?.source;
|
|
156
|
+
if (typeof imageIndex !== 'undefined') {
|
|
157
|
+
const image = json.images?.[imageIndex];
|
|
158
|
+
const mimeType = image?.mimeType;
|
|
159
|
+
const parsedImage = scenegraph.gltf.images?.[imageIndex];
|
|
160
|
+
if (parsedImage) {
|
|
161
|
+
for (let index = 0; index < textureCoordinates.length; index += 2) {
|
|
162
|
+
const value = getImageValueByCoordinates(parsedImage, mimeType, textureCoordinates, index, featureTextureProperty.channels);
|
|
163
|
+
textureData.push(value);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/*
|
|
168
|
+
featureTextureTable will contain unique values, e.g.
|
|
169
|
+
textureData = [24, 35, 28, 24]
|
|
170
|
+
featureTextureTable = [24, 35, 28]
|
|
171
|
+
featureIndices will contain indices hat refer featureTextureTable, e.g.
|
|
172
|
+
featureIndices = [0, 1, 2, 0]
|
|
173
|
+
*/
|
|
174
|
+
const featureIndices = [];
|
|
175
|
+
for (const texelData of textureData) {
|
|
176
|
+
let index = featureTextureTable.findIndex((item) => item === texelData);
|
|
177
|
+
if (index === -1) {
|
|
178
|
+
index = featureTextureTable.push(texelData) - 1;
|
|
179
|
+
}
|
|
180
|
+
featureIndices.push(index);
|
|
181
|
+
}
|
|
182
|
+
const typedArray = new Uint32Array(featureIndices);
|
|
183
|
+
const bufferIndex = scenegraph.gltf.buffers.push({
|
|
184
|
+
arrayBuffer: typedArray.buffer,
|
|
185
|
+
byteOffset: 0,
|
|
186
|
+
byteLength: typedArray.byteLength
|
|
187
|
+
}) - 1;
|
|
188
|
+
const bufferViewIndex = scenegraph.addBufferView(typedArray, bufferIndex, 0);
|
|
189
|
+
const accessorIndex = scenegraph.addAccessor(bufferViewIndex, {
|
|
190
|
+
size: 1,
|
|
191
|
+
componentType: (0, gltf_utils_1.getComponentTypeFromArray)(typedArray),
|
|
192
|
+
count: typedArray.length
|
|
193
|
+
});
|
|
194
|
+
primitive.attributes[attributeName] = accessorIndex;
|
|
195
|
+
}
|
|
196
|
+
function getImageValueByCoordinates(parsedImage, mimeType, textureCoordinates, index, channels) {
|
|
197
|
+
const CHANNELS_MAP = {
|
|
198
|
+
r: { offset: 0, shift: 0 },
|
|
199
|
+
g: { offset: 1, shift: 8 },
|
|
200
|
+
b: { offset: 2, shift: 16 },
|
|
201
|
+
a: { offset: 3, shift: 24 }
|
|
202
|
+
};
|
|
203
|
+
const u = textureCoordinates[index];
|
|
204
|
+
const v = textureCoordinates[index + 1];
|
|
205
|
+
let components = 1;
|
|
206
|
+
if (mimeType && (mimeType.indexOf('image/jpeg') !== -1 || mimeType.indexOf('image/png') !== -1))
|
|
207
|
+
components = 4;
|
|
208
|
+
const offset = coordinatesToOffset(u, v, parsedImage, components);
|
|
209
|
+
let value = 0;
|
|
210
|
+
for (const c of channels) {
|
|
211
|
+
const map = CHANNELS_MAP[c];
|
|
212
|
+
const val = getVal(parsedImage, offset + map.offset);
|
|
213
|
+
value |= val << map.shift;
|
|
214
|
+
}
|
|
215
|
+
return value;
|
|
216
|
+
}
|
|
217
|
+
function getVal(parsedImage, offset) {
|
|
218
|
+
const imageData = (0, images_1.getImageData)(parsedImage);
|
|
219
|
+
if (imageData.data.length <= offset) {
|
|
220
|
+
throw new Error(`${imageData.data.length} <= ${offset}`);
|
|
221
|
+
}
|
|
222
|
+
return imageData.data[offset];
|
|
223
|
+
}
|
|
224
|
+
function coordinatesToOffset(u, v, parsedImage, componentsCount = 1) {
|
|
225
|
+
const w = parsedImage.width;
|
|
226
|
+
const iX = emod(u) * (w - 1);
|
|
227
|
+
const indX = Math.round(iX);
|
|
228
|
+
const h = parsedImage.height;
|
|
229
|
+
const iY = emod(v) * (h - 1);
|
|
230
|
+
const indY = Math.round(iY);
|
|
231
|
+
const components = parsedImage.components ? parsedImage.components : componentsCount;
|
|
232
|
+
// components is a number of channels in the image
|
|
233
|
+
const offset = (indY * w + indX) * components;
|
|
234
|
+
return offset;
|
|
235
|
+
}
|
|
236
|
+
// The following is taken from tile-converter\src\i3s-converter\helpers\batch-ids-extensions.ts
|
|
237
|
+
/**
|
|
238
|
+
* Handle UVs if they are out of range [0,1].
|
|
239
|
+
* @param n
|
|
240
|
+
* @param m
|
|
241
|
+
*/
|
|
242
|
+
function emod(n) {
|
|
243
|
+
const a = ((n % 1) + 1) % 1;
|
|
244
|
+
return a;
|
|
82
245
|
}
|
|
83
246
|
/**
|
|
84
247
|
* Find the feature table by class name.
|
|
@@ -94,6 +257,15 @@ function findFeatureTableByName(featureTables, schemaClassName) {
|
|
|
94
257
|
}
|
|
95
258
|
return null;
|
|
96
259
|
}
|
|
260
|
+
function findFeatureTextureByName(featureTextures, schemaClassName) {
|
|
261
|
+
for (const featureTexturesName in featureTextures) {
|
|
262
|
+
const featureTable = featureTextures[featureTexturesName];
|
|
263
|
+
if (featureTable.class === schemaClassName) {
|
|
264
|
+
return featureTable;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
return null;
|
|
268
|
+
}
|
|
97
269
|
/**
|
|
98
270
|
* Getting string attributes from binary data.
|
|
99
271
|
* Spec - https://github.com/CesiumGS/3d-tiles/tree/main/specification/Metadata#strings
|