@loaders.gl/gltf 3.1.0-alpha.5 → 3.1.0-beta.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/bundle.d.ts +1 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +4518 -0
- package/dist/es5/lib/api/normalize-gltf-v1.js +8 -3
- package/dist/es5/lib/api/normalize-gltf-v1.js.map +1 -1
- package/dist/es5/lib/api/post-process-gltf.js +30 -3
- package/dist/es5/lib/api/post-process-gltf.js.map +1 -1
- package/dist/es5/lib/encoders/encode-glb.js.map +1 -1
- package/dist/es5/lib/encoders/encode-gltf.js.map +1 -1
- package/dist/es5/lib/extensions/KHR_texture_basisu.js.map +1 -1
- package/dist/es5/lib/utils/assert.js.map +1 -1
- package/dist/es5/lib/utils/version.js +1 -1
- package/dist/es5/lib/utils/version.js.map +1 -1
- package/dist/esm/lib/api/normalize-gltf-v1.js +6 -3
- package/dist/esm/lib/api/normalize-gltf-v1.js.map +1 -1
- package/dist/esm/lib/api/post-process-gltf.js +30 -3
- package/dist/esm/lib/api/post-process-gltf.js.map +1 -1
- package/dist/esm/lib/encoders/encode-glb.js.map +1 -1
- package/dist/esm/lib/encoders/encode-gltf.js.map +1 -1
- package/dist/esm/lib/extensions/KHR_texture_basisu.js.map +1 -1
- package/dist/esm/lib/utils/assert.js.map +1 -1
- package/dist/esm/lib/utils/version.js +1 -1
- package/dist/esm/lib/utils/version.js.map +1 -1
- package/dist/glb-loader.d.ts +1 -0
- package/dist/glb-loader.d.ts.map +1 -0
- package/dist/glb-loader.js +39 -0
- package/dist/glb-writer.d.ts +1 -0
- package/dist/glb-writer.d.ts.map +1 -0
- package/dist/glb-writer.js +37 -0
- package/dist/gltf-loader.d.ts +2 -1
- package/dist/gltf-loader.d.ts.map +1 -0
- package/dist/gltf-loader.js +50 -0
- package/dist/gltf-writer.d.ts +1 -0
- package/dist/gltf-writer.d.ts.map +1 -0
- package/dist/gltf-writer.js +32 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/lib/api/gltf-extensions.d.ts +1 -0
- package/dist/lib/api/gltf-extensions.d.ts.map +1 -0
- package/dist/lib/api/gltf-extensions.js +75 -0
- package/dist/lib/api/gltf-scenegraph.d.ts +1 -0
- package/dist/lib/api/gltf-scenegraph.d.ts.map +1 -0
- package/dist/lib/api/gltf-scenegraph.js +553 -0
- package/dist/lib/api/normalize-gltf-v1.d.ts +2 -1
- package/dist/lib/api/normalize-gltf-v1.d.ts.map +1 -0
- package/dist/lib/api/normalize-gltf-v1.js +295 -0
- package/dist/lib/api/post-process-gltf.d.ts +2 -1
- package/dist/lib/api/post-process-gltf.d.ts.map +1 -0
- package/dist/lib/api/post-process-gltf.js +367 -0
- package/dist/lib/encoders/encode-glb.d.ts +1 -0
- package/dist/lib/encoders/encode-glb.d.ts.map +1 -0
- package/dist/lib/encoders/encode-glb.js +61 -0
- package/dist/lib/encoders/encode-gltf.d.ts +2 -1
- package/dist/lib/encoders/encode-gltf.d.ts.map +1 -0
- package/dist/lib/encoders/encode-gltf.js +27 -0
- package/dist/lib/extensions/EXT_meshopt_compression.d.ts +1 -0
- package/dist/lib/extensions/EXT_meshopt_compression.d.ts.map +1 -0
- package/dist/lib/extensions/EXT_meshopt_compression.js +54 -0
- package/dist/lib/extensions/EXT_texture_webp.d.ts +1 -0
- package/dist/lib/extensions/EXT_texture_webp.d.ts.map +1 -0
- package/dist/lib/extensions/EXT_texture_webp.js +38 -0
- package/dist/lib/extensions/KHR_binary_gltf.d.ts +1 -0
- package/dist/lib/extensions/KHR_binary_gltf.d.ts.map +1 -0
- package/dist/lib/extensions/KHR_binary_gltf.js +42 -0
- package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts +1 -0
- package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts.map +1 -0
- package/dist/lib/extensions/KHR_draco_mesh_compression.js +141 -0
- package/dist/lib/extensions/KHR_texture_basisu.d.ts +1 -0
- package/dist/lib/extensions/KHR_texture_basisu.d.ts.map +1 -0
- package/dist/lib/extensions/KHR_texture_basisu.js +31 -0
- package/dist/lib/extensions/deprecated/KHR_lights_punctual.d.ts +1 -0
- package/dist/lib/extensions/deprecated/KHR_lights_punctual.d.ts.map +1 -0
- package/dist/lib/extensions/deprecated/KHR_lights_punctual.js +62 -0
- package/dist/lib/extensions/deprecated/KHR_materials_unlit.d.ts +1 -0
- package/dist/lib/extensions/deprecated/KHR_materials_unlit.d.ts.map +1 -0
- package/dist/lib/extensions/deprecated/KHR_materials_unlit.js +47 -0
- package/dist/lib/extensions/deprecated/KHR_techniques_webgl.d.ts +1 -0
- package/dist/lib/extensions/deprecated/KHR_techniques_webgl.d.ts.map +1 -0
- package/dist/lib/extensions/deprecated/KHR_techniques_webgl.js +81 -0
- package/dist/lib/gltf-utils/get-typed-array.d.ts +1 -0
- package/dist/lib/gltf-utils/get-typed-array.d.ts.map +1 -0
- package/dist/lib/gltf-utils/get-typed-array.js +41 -0
- package/dist/lib/gltf-utils/gltf-attribute-utils.d.ts +1 -0
- package/dist/lib/gltf-utils/gltf-attribute-utils.d.ts.map +1 -0
- package/dist/lib/gltf-utils/gltf-attribute-utils.js +73 -0
- package/dist/lib/gltf-utils/gltf-constants.d.ts +1 -0
- package/dist/lib/gltf-utils/gltf-constants.d.ts.map +1 -0
- package/dist/lib/gltf-utils/gltf-constants.js +43 -0
- package/dist/lib/gltf-utils/gltf-utils.d.ts +1 -0
- package/dist/lib/gltf-utils/gltf-utils.d.ts.map +1 -0
- package/dist/lib/gltf-utils/gltf-utils.js +63 -0
- package/dist/lib/gltf-utils/resolve-url.d.ts +1 -0
- package/dist/lib/gltf-utils/resolve-url.d.ts.map +1 -0
- package/dist/lib/gltf-utils/resolve-url.js +18 -0
- package/dist/lib/parsers/parse-glb.d.ts +1 -0
- package/dist/lib/parsers/parse-glb.d.ts.map +1 -0
- package/dist/lib/parsers/parse-glb.js +141 -0
- package/dist/lib/parsers/parse-gltf.d.ts +2 -1
- package/dist/lib/parsers/parse-gltf.d.ts.map +1 -0
- package/dist/lib/parsers/parse-gltf.js +189 -0
- package/dist/lib/types/glb-types.d.ts +1 -0
- package/dist/lib/types/glb-types.d.ts.map +1 -0
- package/dist/lib/types/glb-types.js +2 -0
- package/dist/lib/types/gltf-json-schema.d.ts +1 -0
- package/dist/lib/types/gltf-json-schema.d.ts.map +1 -0
- package/dist/lib/types/gltf-json-schema.js +4 -0
- package/dist/lib/types/gltf-postprocessed-schema.d.ts +1 -0
- package/dist/lib/types/gltf-postprocessed-schema.d.ts.map +1 -0
- package/dist/lib/types/gltf-postprocessed-schema.js +4 -0
- package/dist/lib/types/gltf-types.d.ts +1 -0
- package/dist/lib/types/gltf-types.d.ts.map +1 -0
- package/dist/lib/types/gltf-types.js +3 -0
- package/dist/lib/utils/assert.d.ts +2 -1
- package/dist/lib/utils/assert.d.ts.map +1 -0
- package/dist/lib/utils/assert.js +12 -0
- package/dist/lib/utils/version.d.ts +2 -1
- package/dist/lib/utils/version.d.ts.map +1 -0
- package/dist/lib/utils/version.js +7 -0
- package/dist/meshopt/meshopt-decoder.d.ts +1 -0
- package/dist/meshopt/meshopt-decoder.d.ts.map +1 -0
- package/dist/meshopt/meshopt-decoder.js +118 -0
- package/dist/webp/webp.d.ts +1 -0
- package/dist/webp/webp.d.ts.map +1 -0
- package/dist/webp/webp.js +38 -0
- package/package.json +8 -9
- package/src/lib/api/{normalize-gltf-v1.js → normalize-gltf-v1.ts} +18 -16
- package/src/lib/api/{post-process-gltf.js → post-process-gltf.ts} +41 -3
- package/src/lib/encoders/{encode-glb.js → encode-glb.ts} +0 -0
- package/src/lib/encoders/{encode-gltf.js → encode-gltf.ts} +0 -0
- package/src/lib/extensions/KHR_texture_basisu.ts +2 -2
- package/src/lib/utils/{assert.js → assert.ts} +1 -1
- package/src/lib/utils/{version.js → version.ts} +0 -0
- package/dist/dist.min.js +0 -2
- package/dist/dist.min.js.map +0 -1
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/* eslint-disable camelcase, max-statements */
|
|
4
|
+
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
5
|
+
const MAGIC_glTF = 0x46546c67; // glTF in ASCII
|
|
6
|
+
const MAGIC_JSON = 0x4e4f534a; // JSON in ASCII
|
|
7
|
+
const MAGIC_BIN = 0x004e4942; // BIN\0 in ASCII
|
|
8
|
+
const LE = true; // Binary GLTF is little endian.
|
|
9
|
+
// Encode the full GLB buffer with header etc
|
|
10
|
+
// https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#
|
|
11
|
+
// glb-file-format-specification
|
|
12
|
+
function encodeGLBSync(glb, dataView, byteOffset = 0, options = {}) {
|
|
13
|
+
const { magic = MAGIC_glTF, version = 2, json = {}, binary } = glb;
|
|
14
|
+
const byteOffsetStart = byteOffset;
|
|
15
|
+
// Write GLB Header
|
|
16
|
+
if (dataView) {
|
|
17
|
+
dataView.setUint32(byteOffset + 0, magic, LE); // Magic number (the ASCII string 'glTF').
|
|
18
|
+
dataView.setUint32(byteOffset + 4, version, LE); // Version 2 of binary glTF container format uint32
|
|
19
|
+
dataView.setUint32(byteOffset + 8, 0, LE); // Total byte length of generated file (uint32), will be set last
|
|
20
|
+
}
|
|
21
|
+
const byteOffsetFileLength = byteOffset + 8;
|
|
22
|
+
byteOffset += 12; // GLB_FILE_HEADER_SIZE
|
|
23
|
+
// Write the JSON chunk header
|
|
24
|
+
const byteOffsetJsonHeader = byteOffset;
|
|
25
|
+
if (dataView) {
|
|
26
|
+
dataView.setUint32(byteOffset + 0, 0, LE); // Byte length of json chunk (will be written later)
|
|
27
|
+
dataView.setUint32(byteOffset + 4, MAGIC_JSON, LE); // Chunk type
|
|
28
|
+
}
|
|
29
|
+
byteOffset += 8; // GLB_CHUNK_HEADER_SIZE
|
|
30
|
+
// Write the JSON chunk
|
|
31
|
+
const jsonString = JSON.stringify(json);
|
|
32
|
+
byteOffset = (0, loader_utils_1.copyPaddedStringToDataView)(dataView, byteOffset, jsonString, 4);
|
|
33
|
+
// Now we know the JSON chunk length so we can write it.
|
|
34
|
+
if (dataView) {
|
|
35
|
+
const jsonByteLength = byteOffset - byteOffsetJsonHeader - 8; // GLB_CHUNK_HEADER_SIZE
|
|
36
|
+
dataView.setUint32(byteOffsetJsonHeader + 0, jsonByteLength, LE); // Byte length of json chunk (uint32)
|
|
37
|
+
}
|
|
38
|
+
// Write the BIN chunk if present. The BIN chunk is optional.
|
|
39
|
+
if (binary) {
|
|
40
|
+
const byteOffsetBinHeader = byteOffset;
|
|
41
|
+
// Write the BIN chunk header
|
|
42
|
+
if (dataView) {
|
|
43
|
+
dataView.setUint32(byteOffset + 0, 0, LE); // Byte length BIN (uint32)
|
|
44
|
+
dataView.setUint32(byteOffset + 4, MAGIC_BIN, LE); // Chunk type
|
|
45
|
+
}
|
|
46
|
+
byteOffset += 8; // GLB_CHUNK_HEADER_SIZE
|
|
47
|
+
byteOffset = (0, loader_utils_1.copyPaddedArrayBufferToDataView)(dataView, byteOffset, binary, 4);
|
|
48
|
+
// Now we know the BIN chunk length so we can write it.
|
|
49
|
+
if (dataView) {
|
|
50
|
+
const binByteLength = byteOffset - byteOffsetBinHeader - 8; // GLB_CHUNK_HEADER_SIZE
|
|
51
|
+
dataView.setUint32(byteOffsetBinHeader + 0, binByteLength, LE); // Byte length BIN (uint32)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// Now we know the glb file length so we can write it.
|
|
55
|
+
if (dataView) {
|
|
56
|
+
const fileByteLength = byteOffset - byteOffsetStart;
|
|
57
|
+
dataView.setUint32(byteOffsetFileLength, fileByteLength, LE); // Total byte length of generated file (uint32)
|
|
58
|
+
}
|
|
59
|
+
return byteOffset;
|
|
60
|
+
}
|
|
61
|
+
exports.default = encodeGLBSync;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export function encodeGLTFSync(gltf: any, arrayBuffer: any, byteOffset: any, options: any): number;
|
|
1
|
+
export declare function encodeGLTFSync(gltf: any, arrayBuffer: any, byteOffset: any, options: any): number;
|
|
2
|
+
//# sourceMappingURL=encode-gltf.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encode-gltf.d.ts","sourceRoot":"","sources":["../../../src/lib/encoders/encode-gltf.ts"],"names":[],"mappings":"AAYA,wBAAgB,cAAc,CAAC,IAAI,KAAA,EAAE,WAAW,KAAA,EAAE,UAAU,KAAA,EAAE,OAAO,KAAA,UAMpE"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.encodeGLTFSync = void 0;
|
|
7
|
+
const encode_glb_1 = __importDefault(require("./encode-glb"));
|
|
8
|
+
// Encode the full glTF file as a binary GLB file
|
|
9
|
+
// Returns an ArrayBuffer that represents the complete GLB image that can be saved to file
|
|
10
|
+
//
|
|
11
|
+
// TODO - Does not support encoding to non-GLB versions of glTF format
|
|
12
|
+
// - Encode as a textual JSON file with binary data in base64 data URLs.
|
|
13
|
+
// - Encode as a JSON with all images (and buffers?) in separate binary files
|
|
14
|
+
//
|
|
15
|
+
// glb-file-format-specification
|
|
16
|
+
// https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#
|
|
17
|
+
function encodeGLTFSync(gltf, arrayBuffer, byteOffset, options) {
|
|
18
|
+
convertBuffersToBase64(gltf);
|
|
19
|
+
// TODO: Copy buffers to binary
|
|
20
|
+
return (0, encode_glb_1.default)(gltf, arrayBuffer, byteOffset, options);
|
|
21
|
+
}
|
|
22
|
+
exports.encodeGLTFSync = encodeGLTFSync;
|
|
23
|
+
function convertBuffersToBase64(gltf, { firstBuffer = 0 } = {}) {
|
|
24
|
+
if (gltf.buffers && gltf.buffers.length > firstBuffer) {
|
|
25
|
+
throw new Error('encodeGLTF: multiple buffers not yet implemented');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +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,qBAAqB,CAAC;AAC5F,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,mBAAmB,CAAC;AAczD,eAAO,MAAM,IAAI,4BAA0B,CAAC;AAE5C,wBAAgB,UAAU,CAAC,QAAQ,EAAE;IAAC,IAAI,EAAE,IAAI,CAAA;CAAC,QAQhD;AAED,wBAAsB,MAAM,CAAC,QAAQ,EAAE;IAAC,IAAI,EAAE,IAAI,CAAA;CAAC,EAAE,OAAO,EAAE,iBAAiB,iBAiB9E"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.decode = exports.preprocess = exports.name = void 0;
|
|
7
|
+
const gltf_scenegraph_1 = __importDefault(require("../api/gltf-scenegraph"));
|
|
8
|
+
const meshopt_decoder_1 = require("../../meshopt/meshopt-decoder");
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
// eslint-disable-next-line
|
|
11
|
+
const DEFAULT_MESHOPT_OPTIONS = {
|
|
12
|
+
byteOffset: 0,
|
|
13
|
+
filter: 'NONE'
|
|
14
|
+
};
|
|
15
|
+
/** Extension name */
|
|
16
|
+
const EXT_MESHOPT_COMPRESSION = 'EXT_meshopt_compression';
|
|
17
|
+
exports.name = EXT_MESHOPT_COMPRESSION;
|
|
18
|
+
function preprocess(gltfData) {
|
|
19
|
+
const scenegraph = new gltf_scenegraph_1.default(gltfData);
|
|
20
|
+
if (scenegraph.getRequiredExtensions().includes(EXT_MESHOPT_COMPRESSION) &&
|
|
21
|
+
!(0, meshopt_decoder_1.isMeshoptSupported)()) {
|
|
22
|
+
throw new Error(`gltf: Required extension ${EXT_MESHOPT_COMPRESSION} not supported by browser`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.preprocess = preprocess;
|
|
26
|
+
async function decode(gltfData, options) {
|
|
27
|
+
const scenegraph = new gltf_scenegraph_1.default(gltfData);
|
|
28
|
+
if (!options?.gltf?.decompressMeshes) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const promises = [];
|
|
32
|
+
for (const bufferViewIndex of gltfData.json.bufferViews || []) {
|
|
33
|
+
promises.push(decodeMeshoptBufferView(scenegraph, bufferViewIndex));
|
|
34
|
+
}
|
|
35
|
+
// Decompress meshes in parallel
|
|
36
|
+
await Promise.all(promises);
|
|
37
|
+
// We have now decompressed all primitives, so remove the top-level extensions
|
|
38
|
+
scenegraph.removeExtension(EXT_MESHOPT_COMPRESSION);
|
|
39
|
+
}
|
|
40
|
+
exports.decode = decode;
|
|
41
|
+
/** Decode one meshopt buffer view */
|
|
42
|
+
async function decodeMeshoptBufferView(scenegraph, bufferView) {
|
|
43
|
+
const meshoptExtension = scenegraph.getObjectExtension(bufferView, EXT_MESHOPT_COMPRESSION);
|
|
44
|
+
if (meshoptExtension) {
|
|
45
|
+
const buffer = bufferView.buffer;
|
|
46
|
+
const { byteOffset = 0, byteLength = 0, byteStride, count, mode, filter = 'NONE' } = meshoptExtension;
|
|
47
|
+
// @ts-expect-error TODO - fix buffer handling
|
|
48
|
+
const source = new Uint8Array(buffer, byteOffset, byteLength);
|
|
49
|
+
const result = new ArrayBuffer(count * byteStride);
|
|
50
|
+
await (0, meshopt_decoder_1.meshoptDecodeGltfBuffer)(new Uint8Array(result), count, byteStride, source, mode, filter);
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
@@ -0,0 +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,qBAAqB,CAAC;AACrE,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,CAyBnF"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// GLTF EXTENSION: EXT_TEXTURE_WEBP
|
|
3
|
+
// https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/EXT_TEXTURE_WEBP
|
|
4
|
+
/* eslint-disable camelcase */
|
|
5
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.preprocess = exports.name = void 0;
|
|
10
|
+
const images_1 = require("@loaders.gl/images");
|
|
11
|
+
const gltf_scenegraph_1 = __importDefault(require("../api/gltf-scenegraph"));
|
|
12
|
+
const EXT_TEXTURE_WEBP = 'EXT_texture_webp';
|
|
13
|
+
/** Extension name */
|
|
14
|
+
exports.name = EXT_TEXTURE_WEBP;
|
|
15
|
+
/**
|
|
16
|
+
* Replaces a texture source reference with the extension texture
|
|
17
|
+
* Done in preprocess() to prevent load of default image
|
|
18
|
+
*/
|
|
19
|
+
function preprocess(gltfData, options) {
|
|
20
|
+
const scenegraph = new gltf_scenegraph_1.default(gltfData);
|
|
21
|
+
if (!(0, images_1._isImageFormatSupported)('image/webp')) {
|
|
22
|
+
if (scenegraph.getRequiredExtensions().includes(EXT_TEXTURE_WEBP)) {
|
|
23
|
+
throw new Error(`gltf: Required extension ${EXT_TEXTURE_WEBP} not supported by browser`);
|
|
24
|
+
}
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const { json } = scenegraph;
|
|
28
|
+
for (const texture of json.textures || []) {
|
|
29
|
+
const extension = scenegraph.getObjectExtension(texture, EXT_TEXTURE_WEBP);
|
|
30
|
+
if (extension) {
|
|
31
|
+
texture.source = extension.source;
|
|
32
|
+
}
|
|
33
|
+
scenegraph.removeObjectExtension(texture, EXT_TEXTURE_WEBP);
|
|
34
|
+
}
|
|
35
|
+
// Remove the top-level extension
|
|
36
|
+
scenegraph.removeExtension(EXT_TEXTURE_WEBP);
|
|
37
|
+
}
|
|
38
|
+
exports.preprocess = preprocess;
|
|
@@ -0,0 +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,qBAAqB,CAAC;AAMpE,qBAAqB;AACrB,eAAO,MAAM,IAAI,oBAAkB,CAAC;AAEpC,wBAAgB,UAAU,CAAC,QAAQ,EAAE;IAAC,IAAI,EAAE,IAAI,CAAA;CAAC,GAAG,IAAI,CA+BvD"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// GLTF 1.0 EXTENSION: KHR_binary_glTF
|
|
3
|
+
// https://github.com/KhronosGroup/glTF/tree/master/extensions/1.0/Khronos/KHR_binary_glTF
|
|
4
|
+
/* eslint-disable camelcase */
|
|
5
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.preprocess = exports.name = void 0;
|
|
10
|
+
const gltf_scenegraph_1 = __importDefault(require("../api/gltf-scenegraph"));
|
|
11
|
+
const KHR_BINARY_GLTF = 'KHR_binary_glTF';
|
|
12
|
+
/** Extension name */
|
|
13
|
+
exports.name = KHR_BINARY_GLTF;
|
|
14
|
+
function preprocess(gltfData) {
|
|
15
|
+
const gltfScenegraph = new gltf_scenegraph_1.default(gltfData);
|
|
16
|
+
const { json } = gltfScenegraph;
|
|
17
|
+
// Note: json.buffers.binary_glTF also needs to be replaced
|
|
18
|
+
// This is currently done during gltf normalization
|
|
19
|
+
// Image and shader nodes can have the extension
|
|
20
|
+
// https://github.com/KhronosGroup/glTF/blob/master/extensions/1.0/Khronos/KHR_binary_glTF/schema/image.KHR_binary_glTF.schema.json
|
|
21
|
+
for (const image of json.images || []) {
|
|
22
|
+
const extension = gltfScenegraph.getObjectExtension(image, KHR_BINARY_GLTF);
|
|
23
|
+
// The data in the extension is valid as glTF 2.0 data inside the object, so just copy it in
|
|
24
|
+
if (extension) {
|
|
25
|
+
Object.assign(image, extension);
|
|
26
|
+
}
|
|
27
|
+
gltfScenegraph.removeObjectExtension(image, KHR_BINARY_GLTF);
|
|
28
|
+
}
|
|
29
|
+
// TODO shaders - At least traverse and throw error if used?
|
|
30
|
+
// https://github.com/KhronosGroup/glTF/blob/master/extensions/1.0/Khronos/KHR_binary_glTF/schema/shader.KHR_binary_glTF.schema.json
|
|
31
|
+
// glTF v1 one files have a partially formed URI field that is not expected in (and causes problems in) 2.0
|
|
32
|
+
if (json.buffers && json.buffers[0]) {
|
|
33
|
+
delete json.buffers[0].uri;
|
|
34
|
+
}
|
|
35
|
+
// Remove the top-level extension as it has now been removed from all nodes
|
|
36
|
+
gltfScenegraph.removeExtension(KHR_BINARY_GLTF);
|
|
37
|
+
}
|
|
38
|
+
exports.preprocess = preprocess;
|
|
39
|
+
// KHR_binary_gltf is a 1.0 extension that is supported natively by 2.0
|
|
40
|
+
// export function encode() {
|
|
41
|
+
// throw new Error(KHR_BINARY_GLTF);
|
|
42
|
+
// }
|
|
@@ -10,3 +10,4 @@ export declare function decode(gltfData: {
|
|
|
10
10
|
json: GLTF;
|
|
11
11
|
}, options: GLTFLoaderOptions, context: LoaderContext): Promise<void>;
|
|
12
12
|
export declare function encode(gltfData: any, options?: GLTFLoaderOptions): void;
|
|
13
|
+
//# sourceMappingURL=KHR_draco_mesh_compression.d.ts.map
|
|
@@ -0,0 +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,qBAAqB,CAAC;AAC7B,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"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression
|
|
3
|
+
// Only TRIANGLES: 0x0004 and TRIANGLE_STRIP: 0x0005 are supported
|
|
4
|
+
/* eslint-disable camelcase */
|
|
5
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.encode = exports.decode = exports.preprocess = exports.name = void 0;
|
|
10
|
+
const draco_1 = require("@loaders.gl/draco");
|
|
11
|
+
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
12
|
+
const gltf_scenegraph_1 = __importDefault(require("../api/gltf-scenegraph"));
|
|
13
|
+
const gltf_attribute_utils_1 = require("../gltf-utils/gltf-attribute-utils");
|
|
14
|
+
const KHR_DRACO_MESH_COMPRESSION = 'KHR_draco_mesh_compression';
|
|
15
|
+
/** Extension name */
|
|
16
|
+
exports.name = KHR_DRACO_MESH_COMPRESSION;
|
|
17
|
+
function preprocess(gltfData, options, context) {
|
|
18
|
+
const scenegraph = new gltf_scenegraph_1.default(gltfData);
|
|
19
|
+
for (const primitive of makeMeshPrimitiveIterator(scenegraph)) {
|
|
20
|
+
if (scenegraph.getObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION)) {
|
|
21
|
+
// TODO - Remove fallback accessors to make sure we don't load unnecessary buffers
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.preprocess = preprocess;
|
|
26
|
+
async function decode(gltfData, options, context) {
|
|
27
|
+
if (!options?.gltf?.decompressMeshes) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const scenegraph = new gltf_scenegraph_1.default(gltfData);
|
|
31
|
+
const promises = [];
|
|
32
|
+
for (const primitive of makeMeshPrimitiveIterator(scenegraph)) {
|
|
33
|
+
if (scenegraph.getObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION)) {
|
|
34
|
+
promises.push(decompressPrimitive(scenegraph, primitive, options, context));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
// Decompress meshes in parallel
|
|
38
|
+
await Promise.all(promises);
|
|
39
|
+
// We have now decompressed all primitives, so remove the top-level extensions
|
|
40
|
+
scenegraph.removeExtension(KHR_DRACO_MESH_COMPRESSION);
|
|
41
|
+
}
|
|
42
|
+
exports.decode = decode;
|
|
43
|
+
function encode(gltfData, options = {}) {
|
|
44
|
+
const scenegraph = new gltf_scenegraph_1.default(gltfData);
|
|
45
|
+
for (const mesh of scenegraph.json.meshes || []) {
|
|
46
|
+
// eslint-disable-next-line camelcase
|
|
47
|
+
// @ts-ignore
|
|
48
|
+
compressMesh(mesh, options);
|
|
49
|
+
// NOTE: Only add the extension if something was actually compressed
|
|
50
|
+
scenegraph.addRequiredExtension(KHR_DRACO_MESH_COMPRESSION);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.encode = encode;
|
|
54
|
+
// DECODE
|
|
55
|
+
// Unpacks one mesh primitive and removes the extension from the primitive
|
|
56
|
+
// DracoDecoder needs to be imported and registered by app
|
|
57
|
+
// Returns: Promise that resolves when all pending draco decoder jobs for this mesh complete
|
|
58
|
+
// TODO - Implement fallback behavior per KHR_DRACO_MESH_COMPRESSION spec
|
|
59
|
+
async function decompressPrimitive(scenegraph, primitive, options, context) {
|
|
60
|
+
const dracoExtension = scenegraph.getObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION);
|
|
61
|
+
if (!dracoExtension) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const buffer = scenegraph.getTypedArrayForBufferView(dracoExtension.bufferView);
|
|
65
|
+
// TODO - parse does not yet deal well with byte offsets embedded in typed arrays. Copy buffer
|
|
66
|
+
// TODO - remove when `parse` is fixed to handle `byteOffset`s
|
|
67
|
+
const bufferCopy = (0, loader_utils_1.sliceArrayBuffer)(buffer.buffer, buffer.byteOffset); // , buffer.byteLength);
|
|
68
|
+
const { parse } = context;
|
|
69
|
+
const dracoOptions = { ...options };
|
|
70
|
+
// TODO - remove hack: The entire tileset might be included, too expensive to serialize
|
|
71
|
+
delete dracoOptions['3d-tiles'];
|
|
72
|
+
const decodedData = (await parse(bufferCopy, draco_1.DracoLoader, dracoOptions, context));
|
|
73
|
+
const decodedAttributes = (0, gltf_attribute_utils_1.getGLTFAccessors)(decodedData.attributes);
|
|
74
|
+
// Restore min/max values
|
|
75
|
+
for (const [attributeName, decodedAttribute] of Object.entries(decodedAttributes)) {
|
|
76
|
+
if (attributeName in primitive.attributes) {
|
|
77
|
+
const accessorIndex = primitive.attributes[attributeName];
|
|
78
|
+
const accessor = scenegraph.getAccessor(accessorIndex);
|
|
79
|
+
if (accessor?.min && accessor?.max) {
|
|
80
|
+
decodedAttribute.min = accessor.min;
|
|
81
|
+
decodedAttribute.max = accessor.max;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
// @ts-ignore
|
|
86
|
+
primitive.attributes = decodedAttributes;
|
|
87
|
+
if (decodedData.indices) {
|
|
88
|
+
// @ts-ignore
|
|
89
|
+
primitive.indices = (0, gltf_attribute_utils_1.getGLTFAccessor)(decodedData.indices);
|
|
90
|
+
}
|
|
91
|
+
// Extension has been processed, delete it
|
|
92
|
+
// delete primitive.extensions[KHR_DRACO_MESH_COMPRESSION];
|
|
93
|
+
checkPrimitive(primitive);
|
|
94
|
+
}
|
|
95
|
+
// ENCODE
|
|
96
|
+
// eslint-disable-next-line max-len
|
|
97
|
+
// Only TRIANGLES: 0x0004 and TRIANGLE_STRIP: 0x0005 are supported
|
|
98
|
+
function compressMesh(attributes, indices, mode = 4, options, context) {
|
|
99
|
+
if (!options.DracoWriter) {
|
|
100
|
+
throw new Error('options.gltf.DracoWriter not provided');
|
|
101
|
+
}
|
|
102
|
+
// TODO - use DracoWriter using encode w/ registered DracoWriter...
|
|
103
|
+
const compressedData = options.DracoWriter.encodeSync({ attributes });
|
|
104
|
+
// Draco compression may change the order and number of vertices in a mesh.
|
|
105
|
+
// To satisfy the requirement that accessors properties be correct for both
|
|
106
|
+
// compressed and uncompressed data, generators should create uncompressed
|
|
107
|
+
// attributes and indices using data that has been decompressed from the Draco buffer,
|
|
108
|
+
// rather than the original source data.
|
|
109
|
+
// @ts-ignore TODO this needs to be fixed
|
|
110
|
+
const decodedData = context?.parseSync?.({ attributes });
|
|
111
|
+
const fauxAccessors = options._addFauxAttributes(decodedData.attributes);
|
|
112
|
+
const bufferViewIndex = options.addBufferView(compressedData);
|
|
113
|
+
const glTFMesh = {
|
|
114
|
+
primitives: [
|
|
115
|
+
{
|
|
116
|
+
attributes: fauxAccessors,
|
|
117
|
+
mode,
|
|
118
|
+
extensions: {
|
|
119
|
+
[KHR_DRACO_MESH_COMPRESSION]: {
|
|
120
|
+
bufferView: bufferViewIndex,
|
|
121
|
+
attributes: fauxAccessors // TODO - verify with spec
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
]
|
|
126
|
+
};
|
|
127
|
+
return glTFMesh;
|
|
128
|
+
}
|
|
129
|
+
// UTILS
|
|
130
|
+
function checkPrimitive(primitive) {
|
|
131
|
+
if (!primitive.attributes && Object.keys(primitive.attributes).length > 0) {
|
|
132
|
+
throw new Error('glTF: Empty primitive detected: Draco decompression failure?');
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function* makeMeshPrimitiveIterator(scenegraph) {
|
|
136
|
+
for (const mesh of scenegraph.json.meshes || []) {
|
|
137
|
+
for (const primitive of mesh.primitives) {
|
|
138
|
+
yield primitive;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
@@ -0,0 +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,qBAAqB,CAAC;AACvE,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,CAiBnF"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// GLTF EXTENSION: KHR_texture_basisu
|
|
3
|
+
// https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_basisu
|
|
4
|
+
/* eslint-disable camelcase */
|
|
5
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.preprocess = exports.name = void 0;
|
|
10
|
+
const gltf_scenegraph_1 = __importDefault(require("../api/gltf-scenegraph"));
|
|
11
|
+
const KHR_TEXTURE_BASISU = 'KHR_texture_basisu';
|
|
12
|
+
/** Extension name */
|
|
13
|
+
exports.name = KHR_TEXTURE_BASISU;
|
|
14
|
+
/**
|
|
15
|
+
* Replaces a texture source reference with the extension texture
|
|
16
|
+
* Done in preprocess() to prevent load of default image
|
|
17
|
+
*/
|
|
18
|
+
function preprocess(gltfData, options) {
|
|
19
|
+
const scene = new gltf_scenegraph_1.default(gltfData);
|
|
20
|
+
const { json } = scene;
|
|
21
|
+
for (const texture of json.textures || []) {
|
|
22
|
+
const extension = scene.getObjectExtension(texture, KHR_TEXTURE_BASISU);
|
|
23
|
+
if (extension) {
|
|
24
|
+
texture.source = extension.source;
|
|
25
|
+
}
|
|
26
|
+
scene.removeObjectExtension(texture, KHR_TEXTURE_BASISU);
|
|
27
|
+
}
|
|
28
|
+
// Remove the top-level extension
|
|
29
|
+
scene.removeExtension(KHR_TEXTURE_BASISU);
|
|
30
|
+
}
|
|
31
|
+
exports.preprocess = preprocess;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KHR_lights_punctual.d.ts","sourceRoot":"","sources":["../../../../src/lib/extensions/deprecated/KHR_lights_punctual.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,wBAAwB,CAAC;AAOjD,eAAO,MAAM,IAAI,wBAAsB,CAAC;AAExC,wBAAsB,MAAM,CAAC,QAAQ,EAAE;IAAC,IAAI,EAAE,IAAI,CAAA;CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAsBlE;AAGD,wBAAsB,MAAM,CAAC,QAAQ,KAAA,GAAG,OAAO,CAAC,IAAI,CAAC,CA2BpD"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// GLTF EXTENSION: KHR_lights_punctual
|
|
3
|
+
// https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_lights_punctual
|
|
4
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
|
+
};
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.encode = exports.decode = exports.name = void 0;
|
|
9
|
+
const assert_1 = require("../../utils/assert");
|
|
10
|
+
const gltf_scenegraph_1 = __importDefault(require("../../api/gltf-scenegraph"));
|
|
11
|
+
const KHR_LIGHTS_PUNCTUAL = 'KHR_lights_punctual';
|
|
12
|
+
exports.name = KHR_LIGHTS_PUNCTUAL;
|
|
13
|
+
async function decode(gltfData) {
|
|
14
|
+
const gltfScenegraph = new gltf_scenegraph_1.default(gltfData);
|
|
15
|
+
const { json } = gltfScenegraph;
|
|
16
|
+
// Move the light array out of the extension and remove the extension
|
|
17
|
+
const extension = gltfScenegraph.getExtension(KHR_LIGHTS_PUNCTUAL);
|
|
18
|
+
if (extension) {
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
gltfScenegraph.json.lights = extension.lights;
|
|
21
|
+
gltfScenegraph.removeExtension(KHR_LIGHTS_PUNCTUAL);
|
|
22
|
+
}
|
|
23
|
+
// Any nodes that have the extension, add lights field pointing to light object
|
|
24
|
+
// and remove the extension
|
|
25
|
+
for (const node of json.nodes || []) {
|
|
26
|
+
const nodeExtension = gltfScenegraph.getObjectExtension(node, KHR_LIGHTS_PUNCTUAL);
|
|
27
|
+
if (nodeExtension) {
|
|
28
|
+
// @ts-ignore
|
|
29
|
+
node.light = nodeExtension.light;
|
|
30
|
+
}
|
|
31
|
+
gltfScenegraph.removeObjectExtension(node, KHR_LIGHTS_PUNCTUAL);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.decode = decode;
|
|
35
|
+
// Move the light ar ray out of the extension and remove the extension
|
|
36
|
+
async function encode(gltfData) {
|
|
37
|
+
const gltfScenegraph = new gltf_scenegraph_1.default(gltfData);
|
|
38
|
+
const { json } = gltfScenegraph;
|
|
39
|
+
// @ts-ignore
|
|
40
|
+
if (json.lights) {
|
|
41
|
+
const extension = gltfScenegraph.addExtension(KHR_LIGHTS_PUNCTUAL);
|
|
42
|
+
// @ts-ignore
|
|
43
|
+
(0, assert_1.assert)(!extension.lights);
|
|
44
|
+
// @ts-ignore
|
|
45
|
+
extension.lights = json.lights;
|
|
46
|
+
// @ts-ignore
|
|
47
|
+
delete json.lights;
|
|
48
|
+
}
|
|
49
|
+
// Any nodes that have lights field pointing to light object
|
|
50
|
+
// add the extension
|
|
51
|
+
// @ts-ignore
|
|
52
|
+
if (gltfScenegraph.json.lights) {
|
|
53
|
+
// @ts-ignore
|
|
54
|
+
for (const light of gltfScenegraph.json.lights) {
|
|
55
|
+
const node = light.node;
|
|
56
|
+
gltfScenegraph.addObjectExtension(node, KHR_LIGHTS_PUNCTUAL, light);
|
|
57
|
+
}
|
|
58
|
+
// @ts-ignore
|
|
59
|
+
delete gltfScenegraph.json.lights;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.encode = encode;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KHR_materials_unlit.d.ts","sourceRoot":"","sources":["../../../../src/lib/extensions/deprecated/KHR_materials_unlit.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,wBAAwB,CAAC;AAMjD,eAAO,MAAM,IAAI,wBAAsB,CAAC;AAExC,wBAAsB,MAAM,CAAC,QAAQ,EAAE;IAAC,IAAI,EAAE,IAAI,CAAA;CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAiBlE;AAED,wBAAgB,MAAM,CAAC,QAAQ,KAAA,QAkB9B"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// GLTF EXTENSION: KHR_materials_unlit
|
|
3
|
+
// https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit
|
|
4
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
|
+
};
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.encode = exports.decode = exports.name = void 0;
|
|
9
|
+
const gltf_scenegraph_1 = __importDefault(require("../../api/gltf-scenegraph"));
|
|
10
|
+
const KHR_MATERIALS_UNLIT = 'KHR_materials_unlit';
|
|
11
|
+
exports.name = KHR_MATERIALS_UNLIT;
|
|
12
|
+
async function decode(gltfData) {
|
|
13
|
+
const gltfScenegraph = new gltf_scenegraph_1.default(gltfData);
|
|
14
|
+
const { json } = gltfScenegraph;
|
|
15
|
+
// Remove the top-level extension
|
|
16
|
+
gltfScenegraph.removeExtension(KHR_MATERIALS_UNLIT);
|
|
17
|
+
// Any nodes that have the extension, add lights field pointing to light object
|
|
18
|
+
// and remove the extension
|
|
19
|
+
for (const material of json.materials || []) {
|
|
20
|
+
const extension = material.extensions && material.extensions.KHR_materials_unlit;
|
|
21
|
+
if (extension) {
|
|
22
|
+
// @ts-ignore TODO
|
|
23
|
+
material.unlit = true;
|
|
24
|
+
}
|
|
25
|
+
gltfScenegraph.removeObjectExtension(material, KHR_MATERIALS_UNLIT);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.decode = decode;
|
|
29
|
+
function encode(gltfData) {
|
|
30
|
+
const gltfScenegraph = new gltf_scenegraph_1.default(gltfData);
|
|
31
|
+
const { json } = gltfScenegraph;
|
|
32
|
+
// Any nodes that have lights field pointing to light object
|
|
33
|
+
// add the extension
|
|
34
|
+
// @ts-ignore
|
|
35
|
+
if (gltfScenegraph.materials) {
|
|
36
|
+
for (const material of json.materials || []) {
|
|
37
|
+
// @ts-ignore
|
|
38
|
+
if (material.unlit) {
|
|
39
|
+
// @ts-ignore
|
|
40
|
+
delete material.unlit;
|
|
41
|
+
gltfScenegraph.addObjectExtension(material, KHR_MATERIALS_UNLIT, {});
|
|
42
|
+
gltfScenegraph.addExtension(KHR_MATERIALS_UNLIT);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.encode = encode;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KHR_techniques_webgl.d.ts","sourceRoot":"","sources":["../../../../src/lib/extensions/deprecated/KHR_techniques_webgl.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,wBAAwB,CAAC;AAMjD,eAAO,MAAM,IAAI,yBAAuB,CAAC;AAEzC,wBAAsB,MAAM,CAAC,QAAQ,EAAE;IAAC,IAAI,EAAE,IAAI,CAAA;CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CA0BlE;AAED,wBAAsB,MAAM,CAAC,QAAQ,KAAA,EAAE,OAAO,KAAA,GAAG,OAAO,CAAC,IAAI,CAAC,CAE7D"}
|