@loaders.gl/gltf 3.0.12 → 3.1.0-alpha.4
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 +1 -1
- package/dist/dist.min.js.map +1 -1
- package/dist/es5/bundle.js +2 -4
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/gltf-loader.js.map +1 -1
- package/dist/es5/index.js +0 -8
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/api/gltf-extensions.js +146 -0
- package/dist/es5/lib/api/gltf-extensions.js.map +1 -0
- package/dist/es5/lib/api/gltf-scenegraph.js.map +1 -1
- package/dist/es5/lib/api/normalize-gltf-v1.js +1 -1
- package/dist/es5/lib/api/normalize-gltf-v1.js.map +1 -1
- package/dist/es5/lib/extensions/EXT_meshopt_compression.js +32 -21
- package/dist/es5/lib/extensions/EXT_meshopt_compression.js.map +1 -1
- package/dist/es5/lib/extensions/EXT_texture_webp.js +60 -0
- package/dist/es5/lib/extensions/EXT_texture_webp.js.map +1 -0
- package/dist/es5/lib/extensions/KHR_binary_gltf.js +13 -13
- package/dist/es5/lib/extensions/KHR_binary_gltf.js.map +1 -1
- package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js +55 -32
- package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js.map +1 -1
- package/dist/es5/lib/extensions/KHR_texture_basisu.js +49 -0
- package/dist/es5/lib/extensions/KHR_texture_basisu.js.map +1 -0
- package/dist/es5/lib/extensions/{KHR_lights_punctual.js → deprecated/KHR_lights_punctual.js} +13 -10
- package/dist/es5/lib/extensions/deprecated/KHR_lights_punctual.js.map +1 -0
- package/dist/es5/lib/extensions/{KHR_materials_unlit.js → deprecated/KHR_materials_unlit.js} +10 -7
- package/dist/es5/lib/extensions/deprecated/KHR_materials_unlit.js.map +1 -0
- package/dist/es5/lib/extensions/{KHR_techniques_webgl.js → deprecated/KHR_techniques_webgl.js} +10 -7
- package/dist/es5/lib/extensions/deprecated/KHR_techniques_webgl.js.map +1 -0
- package/dist/es5/lib/gltf-utils/gltf-constants.js +0 -13
- package/dist/es5/lib/gltf-utils/gltf-constants.js.map +1 -1
- package/dist/es5/lib/parsers/parse-gltf.js +71 -28
- package/dist/es5/lib/parsers/parse-gltf.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/es5/webp/webp.js +104 -0
- package/dist/es5/webp/webp.js.map +1 -0
- package/dist/esm/bundle.js +2 -4
- package/dist/esm/bundle.js.map +1 -1
- package/dist/esm/gltf-loader.js.map +1 -1
- package/dist/esm/index.js +0 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/api/gltf-extensions.js +35 -0
- package/dist/esm/lib/api/gltf-extensions.js.map +1 -0
- package/dist/esm/lib/api/gltf-scenegraph.js.map +1 -1
- package/dist/esm/lib/api/normalize-gltf-v1.js +1 -1
- package/dist/esm/lib/api/normalize-gltf-v1.js.map +1 -1
- package/dist/esm/lib/extensions/EXT_meshopt_compression.js +16 -8
- package/dist/esm/lib/extensions/EXT_meshopt_compression.js.map +1 -1
- package/dist/esm/lib/extensions/EXT_texture_webp.js +32 -0
- package/dist/esm/lib/extensions/EXT_texture_webp.js.map +1 -0
- package/dist/esm/lib/extensions/KHR_binary_gltf.js +8 -8
- package/dist/esm/lib/extensions/KHR_binary_gltf.js.map +1 -1
- package/dist/esm/lib/extensions/KHR_draco_mesh_compression.js +9 -1
- package/dist/esm/lib/extensions/KHR_draco_mesh_compression.js.map +1 -1
- package/dist/esm/lib/extensions/KHR_texture_basisu.js +22 -0
- package/dist/esm/lib/extensions/KHR_texture_basisu.js.map +1 -0
- package/dist/esm/lib/extensions/{KHR_lights_punctual.js → deprecated/KHR_lights_punctual.js} +4 -3
- package/dist/esm/lib/extensions/deprecated/KHR_lights_punctual.js.map +1 -0
- package/dist/esm/lib/extensions/{KHR_materials_unlit.js → deprecated/KHR_materials_unlit.js} +3 -2
- package/dist/esm/lib/extensions/deprecated/KHR_materials_unlit.js.map +1 -0
- package/dist/esm/lib/extensions/{KHR_techniques_webgl.js → deprecated/KHR_techniques_webgl.js} +3 -2
- package/dist/esm/lib/extensions/deprecated/KHR_techniques_webgl.js.map +1 -0
- package/dist/esm/lib/gltf-utils/gltf-constants.js +0 -6
- package/dist/esm/lib/gltf-utils/gltf-constants.js.map +1 -1
- package/dist/esm/lib/parsers/parse-gltf.js +23 -5
- package/dist/esm/lib/parsers/parse-gltf.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/esm/webp/webp.js +29 -0
- package/dist/esm/webp/webp.js.map +1 -0
- package/package.json +6 -6
- package/src/bundle.ts +2 -3
- package/src/gltf-loader.ts +7 -4
- package/src/index.ts +8 -4
- package/src/lib/api/gltf-extensions.ts +71 -0
- package/src/lib/api/gltf-scenegraph.ts +4 -6
- package/src/lib/api/normalize-gltf-v1.js +2 -1
- package/src/lib/extensions/EXT_meshopt_compression.ts +32 -23
- package/src/lib/extensions/EXT_texture_webp.ts +45 -0
- package/src/lib/extensions/KHR_binary_gltf.ts +19 -10
- package/src/lib/extensions/KHR_draco_mesh_compression.ts +31 -11
- package/src/lib/extensions/KHR_texture_basisu.ts +36 -0
- package/src/lib/extensions/{KHR_lights_punctual.ts → deprecated/KHR_lights_punctual.ts} +7 -4
- package/src/lib/extensions/{KHR_materials_unlit.ts → deprecated/KHR_materials_unlit.ts} +6 -3
- package/src/lib/extensions/{KHR_techniques_webgl.ts → deprecated/KHR_techniques_webgl.ts} +6 -3
- package/src/lib/gltf-utils/gltf-constants.ts +0 -12
- package/src/lib/parsers/parse-gltf.ts +55 -19
- package/src/lib/types/gltf-json-schema.ts +96 -3
- package/src/lib/types/gltf-types.ts +19 -21
- package/src/webp/webp.ts +41 -0
- package/dist/dist.es5.min.js +0 -2
- package/dist/dist.es5.min.js.map +0 -1
- package/dist/es5/lib/extensions/KHR_lights_punctual.js.map +0 -1
- package/dist/es5/lib/extensions/KHR_materials_unlit.js.map +0 -1
- package/dist/es5/lib/extensions/KHR_techniques_webgl.js.map +0 -1
- package/dist/es5/lib/extensions/gltf-extensions.js +0 -92
- package/dist/es5/lib/extensions/gltf-extensions.js.map +0 -1
- package/dist/esm/lib/extensions/KHR_lights_punctual.js.map +0 -1
- package/dist/esm/lib/extensions/KHR_materials_unlit.js.map +0 -1
- package/dist/esm/lib/extensions/KHR_techniques_webgl.js.map +0 -1
- package/dist/esm/lib/extensions/gltf-extensions.js +0 -24
- package/dist/esm/lib/extensions/gltf-extensions.js.map +0 -1
- package/src/lib/extensions/gltf-extensions.ts +0 -48
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/* eslint-disable camelcase */
|
|
2
|
+
import {GLTF} from '../types/gltf-types';
|
|
3
|
+
import type {GLTFLoaderOptions} from '../../gltf-loader';
|
|
4
|
+
|
|
5
|
+
// GLTF 1.0 extensions (decode only)
|
|
6
|
+
// import * as KHR_binary_gltf from './KHR_draco_mesh_compression';
|
|
7
|
+
|
|
8
|
+
// GLTF 2.0 Khronos extensions (decode/encode)
|
|
9
|
+
import * as EXT_meshopt_compression from '../extensions/EXT_meshopt_compression';
|
|
10
|
+
import * as EXT_texture_webp from '../extensions/EXT_texture_webp';
|
|
11
|
+
import * as KHR_texture_basisu from '../extensions/KHR_texture_basisu';
|
|
12
|
+
import * as KHR_draco_mesh_compression from '../extensions/KHR_draco_mesh_compression';
|
|
13
|
+
|
|
14
|
+
// Deprecated. These should be handled by rendering library (e.g. luma.gl), not the loader.
|
|
15
|
+
import * as KHR_lights_punctual from '../extensions/deprecated/KHR_lights_punctual';
|
|
16
|
+
import * as KHR_materials_unlit from '../extensions/deprecated/KHR_materials_unlit';
|
|
17
|
+
import * as KHR_techniques_webgl from '../extensions/deprecated/KHR_techniques_webgl';
|
|
18
|
+
|
|
19
|
+
// Vendor extensions
|
|
20
|
+
|
|
21
|
+
type GLTFExtensionPlugin = {
|
|
22
|
+
name: string;
|
|
23
|
+
preprocess?: (gltfData: {json: GLTF}, options: GLTFLoaderOptions, context) => void;
|
|
24
|
+
decode?: (gltfData: {json: GLTF}, options: GLTFLoaderOptions, context) => Promise<void>;
|
|
25
|
+
encode?: (gltfData: {json: GLTF}, options: GLTFLoaderOptions) => void;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* List of extensions processed by the GLTFLoader
|
|
30
|
+
* Note that may extensions can only be handled on the rendering stage and are left out here
|
|
31
|
+
* These are just extensions that can be handled fully or partially during loading.
|
|
32
|
+
*/
|
|
33
|
+
export const EXTENSIONS: GLTFExtensionPlugin[] = [
|
|
34
|
+
// 1.0
|
|
35
|
+
// KHR_binary_gltf is handled separately - must be processed before other parsing starts
|
|
36
|
+
// KHR_binary_gltf,
|
|
37
|
+
|
|
38
|
+
// 2.0
|
|
39
|
+
EXT_meshopt_compression,
|
|
40
|
+
EXT_texture_webp,
|
|
41
|
+
// Basisu should come after webp, we want basisu to be preferred if both are provided
|
|
42
|
+
KHR_texture_basisu,
|
|
43
|
+
KHR_draco_mesh_compression,
|
|
44
|
+
KHR_lights_punctual,
|
|
45
|
+
KHR_materials_unlit,
|
|
46
|
+
KHR_techniques_webgl
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
/** Call before any resource loading starts */
|
|
50
|
+
export function preprocessExtensions(gltf, options: GLTFLoaderOptions = {}, context?) {
|
|
51
|
+
const extensions = EXTENSIONS.filter((extension) => useExtension(extension.name, options));
|
|
52
|
+
for (const extension of extensions) {
|
|
53
|
+
extension.preprocess?.(gltf, options, context);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Call after resource loading */
|
|
58
|
+
export async function decodeExtensions(gltf, options: GLTFLoaderOptions = {}, context?) {
|
|
59
|
+
const extensions = EXTENSIONS.filter((extension) => useExtension(extension.name, options));
|
|
60
|
+
for (const extension of extensions) {
|
|
61
|
+
// Note: We decode async extensions sequentially, this might not be necessary
|
|
62
|
+
// Currently we only have Draco, but when we add Basis we may revisit
|
|
63
|
+
await extension.decode?.(gltf, options, context);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function useExtension(extensionName: string, options: GLTFLoaderOptions) {
|
|
68
|
+
const excludes = options?.gltf?.excludeExtensions || {};
|
|
69
|
+
const exclude = extensionName in excludes && !excludes[extensionName];
|
|
70
|
+
return !exclude;
|
|
71
|
+
}
|
|
@@ -36,6 +36,7 @@ const DEFAULT_GLTF_JSON: GLTF = {
|
|
|
36
36
|
buffers: []
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
+
type Extension = {[key: string]: any};
|
|
39
40
|
/**
|
|
40
41
|
* Class for structured access to GLTF data
|
|
41
42
|
*/
|
|
@@ -79,13 +80,13 @@ export default class GLTFScenegraph {
|
|
|
79
80
|
return extras[key];
|
|
80
81
|
}
|
|
81
82
|
|
|
82
|
-
getExtension(extensionName: string):
|
|
83
|
+
getExtension<T = Extension>(extensionName: string): T | null {
|
|
83
84
|
const isExtension = this.getUsedExtensions().find((name) => name === extensionName);
|
|
84
85
|
const extensions = this.json.extensions || {};
|
|
85
86
|
return isExtension ? extensions[extensionName] || true : null;
|
|
86
87
|
}
|
|
87
88
|
|
|
88
|
-
getRequiredExtension(extensionName: string):
|
|
89
|
+
getRequiredExtension<T = Extension>(extensionName: string): T | null {
|
|
89
90
|
const isRequired = this.getRequiredExtensions().find((name) => name === extensionName);
|
|
90
91
|
return isRequired ? this.getExtension(extensionName) : null;
|
|
91
92
|
}
|
|
@@ -98,10 +99,7 @@ export default class GLTFScenegraph {
|
|
|
98
99
|
return this.json.extensionsUsed || [];
|
|
99
100
|
}
|
|
100
101
|
|
|
101
|
-
getObjectExtension(
|
|
102
|
-
object: {[key: string]: any},
|
|
103
|
-
extensionName: string
|
|
104
|
-
): {[key: string]: any} | null {
|
|
102
|
+
getObjectExtension<T = Extension>(object: {[key: string]: any}, extensionName: string): T | null {
|
|
105
103
|
const extensions = object.extensions || {};
|
|
106
104
|
return extensions[extensionName];
|
|
107
105
|
}
|
|
@@ -139,7 +139,8 @@ class GLTFV1Normalizer {
|
|
|
139
139
|
|
|
140
140
|
// Extract bufferView indices for images
|
|
141
141
|
// (this extension needs to be invoked early in the normalization process)
|
|
142
|
-
|
|
142
|
+
// TODO can this be handled by standard extension processing instead of called explicitly?
|
|
143
|
+
KHR_binary_glTF.preprocess(gltf);
|
|
143
144
|
|
|
144
145
|
// Convert object references from ids to indices
|
|
145
146
|
this._convertObjectIdsToArrayIndices(json);
|
|
@@ -1,19 +1,9 @@
|
|
|
1
1
|
/* eslint-disable camelcase */
|
|
2
|
+
import type {GLTF, GLTFBufferView, GLTF_EXT_meshopt_compression} from '../types/gltf-types';
|
|
2
3
|
import type {GLTFLoaderOptions} from '../../gltf-loader';
|
|
3
4
|
import GLTFScenegraph from '../api/gltf-scenegraph';
|
|
4
|
-
import {EXT_MESHOPT_COMPRESSION} from '../gltf-utils/gltf-constants';
|
|
5
5
|
import {isMeshoptSupported, meshoptDecodeGltfBuffer} from '../../meshopt/meshopt-decoder';
|
|
6
6
|
|
|
7
|
-
type GLTF_EXT_meshopt_compression = {
|
|
8
|
-
buffer: number;
|
|
9
|
-
byteOffset?: number;
|
|
10
|
-
byteLength: number;
|
|
11
|
-
byteStride: number;
|
|
12
|
-
count: number;
|
|
13
|
-
mode: 'ATTRIBUTES' | 'TRIANGLES' | 'INDICES';
|
|
14
|
-
filter?: 'NONE' | 'OCTAHEDRAL' | 'QUATERNION' | 'EXPONENTIAL';
|
|
15
|
-
};
|
|
16
|
-
|
|
17
7
|
// @ts-ignore
|
|
18
8
|
// eslint-disable-next-line
|
|
19
9
|
const DEFAULT_MESHOPT_OPTIONS = {
|
|
@@ -21,34 +11,51 @@ const DEFAULT_MESHOPT_OPTIONS = {
|
|
|
21
11
|
filter: 'NONE'
|
|
22
12
|
};
|
|
23
13
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
14
|
+
/** Extension name */
|
|
15
|
+
const EXT_MESHOPT_COMPRESSION = 'EXT_meshopt_compression';
|
|
16
|
+
|
|
17
|
+
export const name = EXT_MESHOPT_COMPRESSION;
|
|
18
|
+
|
|
19
|
+
export function preprocess(gltfData: {json: GLTF}) {
|
|
20
|
+
const scenegraph = new GLTFScenegraph(gltfData);
|
|
21
|
+
if (
|
|
22
|
+
scenegraph.getRequiredExtensions().includes(EXT_MESHOPT_COMPRESSION) &&
|
|
23
|
+
!isMeshoptSupported()
|
|
24
|
+
) {
|
|
25
|
+
throw new Error(`gltf: Required extension ${EXT_MESHOPT_COMPRESSION} not supported by browser`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function decode(gltfData: {json: GLTF}, options: GLTFLoaderOptions) {
|
|
30
|
+
const scenegraph = new GLTFScenegraph(gltfData);
|
|
31
|
+
|
|
32
|
+
if (!options?.gltf?.decompressMeshes) {
|
|
27
33
|
return;
|
|
28
34
|
}
|
|
29
35
|
|
|
30
36
|
const promises: Promise<any>[] = [];
|
|
31
37
|
for (const bufferViewIndex of gltfData.json.bufferViews || []) {
|
|
32
|
-
promises.push(decodeMeshoptBufferView(
|
|
38
|
+
promises.push(decodeMeshoptBufferView(scenegraph, bufferViewIndex));
|
|
33
39
|
}
|
|
34
40
|
|
|
35
41
|
// Decompress meshes in parallel
|
|
36
42
|
await Promise.all(promises);
|
|
37
43
|
|
|
38
44
|
// We have now decompressed all primitives, so remove the top-level extensions
|
|
39
|
-
const scenegraph = new GLTFScenegraph(gltfData);
|
|
40
45
|
scenegraph.removeExtension(EXT_MESHOPT_COMPRESSION);
|
|
41
46
|
}
|
|
42
47
|
|
|
43
48
|
/** Decode one meshopt buffer view */
|
|
44
|
-
async function decodeMeshoptBufferView(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
async function decodeMeshoptBufferView(
|
|
50
|
+
scenegraph: GLTFScenegraph,
|
|
51
|
+
bufferView: GLTFBufferView
|
|
52
|
+
): Promise<ArrayBuffer | null> {
|
|
53
|
+
const meshoptExtension = scenegraph.getObjectExtension<GLTF_EXT_meshopt_compression>(
|
|
54
|
+
bufferView,
|
|
55
|
+
EXT_MESHOPT_COMPRESSION
|
|
56
|
+
);
|
|
50
57
|
if (meshoptExtension) {
|
|
51
|
-
const buffer =
|
|
58
|
+
const buffer = bufferView.buffer;
|
|
52
59
|
|
|
53
60
|
const {
|
|
54
61
|
byteOffset = 0,
|
|
@@ -58,6 +65,8 @@ async function decodeMeshoptBufferView(json, index: number): Promise<ArrayBuffer
|
|
|
58
65
|
mode,
|
|
59
66
|
filter = 'NONE'
|
|
60
67
|
} = meshoptExtension;
|
|
68
|
+
|
|
69
|
+
// @ts-expect-error TODO - fix buffer handling
|
|
61
70
|
const source = new Uint8Array(buffer, byteOffset, byteLength);
|
|
62
71
|
const result = new ArrayBuffer(count * byteStride);
|
|
63
72
|
await meshoptDecodeGltfBuffer(new Uint8Array(result), count, byteStride, source, mode, filter);
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// GLTF EXTENSION: EXT_TEXTURE_WEBP
|
|
2
|
+
// https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/EXT_TEXTURE_WEBP
|
|
3
|
+
/* eslint-disable camelcase */
|
|
4
|
+
|
|
5
|
+
import type {GLTF, GLTF_EXT_texture_webp} from '../types/gltf-types';
|
|
6
|
+
import type {GLTFLoaderOptions} from '../../gltf-loader';
|
|
7
|
+
|
|
8
|
+
import {_isImageFormatSupported} from '@loaders.gl/images';
|
|
9
|
+
import GLTFScenegraph from '../api/gltf-scenegraph';
|
|
10
|
+
|
|
11
|
+
const EXT_TEXTURE_WEBP = 'EXT_texture_webp';
|
|
12
|
+
|
|
13
|
+
/** Extension name */
|
|
14
|
+
export const name = EXT_TEXTURE_WEBP;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Replaces a texture source reference with the extension texture
|
|
18
|
+
* Done in preprocess() to prevent load of default image
|
|
19
|
+
*/
|
|
20
|
+
export function preprocess(gltfData: {json: GLTF}, options: GLTFLoaderOptions): void {
|
|
21
|
+
const scenegraph = new GLTFScenegraph(gltfData);
|
|
22
|
+
|
|
23
|
+
if (!_isImageFormatSupported('image/webp')) {
|
|
24
|
+
if (scenegraph.getRequiredExtensions().includes(EXT_TEXTURE_WEBP)) {
|
|
25
|
+
throw new Error(`gltf: Required extension ${EXT_TEXTURE_WEBP} not supported by browser`);
|
|
26
|
+
}
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const {json} = scenegraph;
|
|
31
|
+
|
|
32
|
+
for (const texture of json.textures || []) {
|
|
33
|
+
const extension = scenegraph.getObjectExtension<GLTF_EXT_texture_webp>(
|
|
34
|
+
texture,
|
|
35
|
+
EXT_TEXTURE_WEBP
|
|
36
|
+
);
|
|
37
|
+
if (extension) {
|
|
38
|
+
texture.source = extension.source;
|
|
39
|
+
}
|
|
40
|
+
scenegraph.removeObjectExtension(texture, EXT_TEXTURE_WEBP);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Remove the top-level extension
|
|
44
|
+
scenegraph.removeExtension(EXT_TEXTURE_WEBP);
|
|
45
|
+
}
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
// GLTF 1.0 EXTENSION: KHR_binary_glTF
|
|
2
2
|
// https://github.com/KhronosGroup/glTF/tree/master/extensions/1.0/Khronos/KHR_binary_glTF
|
|
3
|
+
/* eslint-disable camelcase */
|
|
3
4
|
|
|
4
|
-
import type {GLTF} from '../types/gltf-types';
|
|
5
|
+
import type {GLTF, GLTF_KHR_binary_glTF} from '../types/gltf-types';
|
|
5
6
|
|
|
6
7
|
import GLTFScenegraph from '../api/gltf-scenegraph';
|
|
7
|
-
import {KHR_BINARY_GLTF} from '../gltf-utils/gltf-constants';
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
const KHR_BINARY_GLTF = 'KHR_binary_glTF';
|
|
10
|
+
|
|
11
|
+
/** Extension name */
|
|
12
|
+
export const name = KHR_BINARY_GLTF;
|
|
13
|
+
|
|
14
|
+
export function preprocess(gltfData: {json: GLTF}): void {
|
|
10
15
|
const gltfScenegraph = new GLTFScenegraph(gltfData);
|
|
11
16
|
const {json} = gltfScenegraph;
|
|
12
17
|
|
|
@@ -15,15 +20,19 @@ export function decode(gltfData: {json: GLTF}): void {
|
|
|
15
20
|
|
|
16
21
|
// Image and shader nodes can have the extension
|
|
17
22
|
// https://github.com/KhronosGroup/glTF/blob/master/extensions/1.0/Khronos/KHR_binary_glTF/schema/image.KHR_binary_glTF.schema.json
|
|
18
|
-
for (const
|
|
19
|
-
const extension = gltfScenegraph.
|
|
23
|
+
for (const image of json.images || []) {
|
|
24
|
+
const extension = gltfScenegraph.getObjectExtension<GLTF_KHR_binary_glTF>(
|
|
25
|
+
image,
|
|
26
|
+
KHR_BINARY_GLTF
|
|
27
|
+
);
|
|
20
28
|
// The data in the extension is valid as glTF 2.0 data inside the object, so just copy it in
|
|
21
29
|
if (extension) {
|
|
22
|
-
Object.assign(
|
|
30
|
+
Object.assign(image, extension);
|
|
23
31
|
}
|
|
32
|
+
gltfScenegraph.removeObjectExtension(image, KHR_BINARY_GLTF);
|
|
24
33
|
}
|
|
25
34
|
|
|
26
|
-
// TODO shaders
|
|
35
|
+
// TODO shaders - At least traverse and throw error if used?
|
|
27
36
|
// https://github.com/KhronosGroup/glTF/blob/master/extensions/1.0/Khronos/KHR_binary_glTF/schema/shader.KHR_binary_glTF.schema.json
|
|
28
37
|
|
|
29
38
|
// glTF v1 one files have a partially formed URI field that is not expected in (and causes problems in) 2.0
|
|
@@ -36,6 +45,6 @@ export function decode(gltfData: {json: GLTF}): void {
|
|
|
36
45
|
}
|
|
37
46
|
|
|
38
47
|
// KHR_binary_gltf is a 1.0 extension that is supported natively by 2.0
|
|
39
|
-
export function encode() {
|
|
40
|
-
|
|
41
|
-
}
|
|
48
|
+
// export function encode() {
|
|
49
|
+
// throw new Error(KHR_BINARY_GLTF);
|
|
50
|
+
// }
|
|
@@ -1,19 +1,41 @@
|
|
|
1
1
|
// https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression
|
|
2
2
|
// Only TRIANGLES: 0x0004 and TRIANGLE_STRIP: 0x0005 are supported
|
|
3
|
+
/* eslint-disable camelcase */
|
|
3
4
|
|
|
4
5
|
/* eslint-disable camelcase */
|
|
5
|
-
import type {
|
|
6
|
+
import type {
|
|
7
|
+
GLTF,
|
|
8
|
+
GLTFAccessor,
|
|
9
|
+
GLTFMeshPrimitive,
|
|
10
|
+
GLTF_KHR_draco_mesh_compression
|
|
11
|
+
} from '../types/gltf-types';
|
|
6
12
|
import type {GLTFLoaderOptions} from '../../gltf-loader';
|
|
7
13
|
|
|
8
14
|
import type {LoaderContext} from '@loaders.gl/loader-utils';
|
|
9
15
|
import {DracoLoader} from '@loaders.gl/draco';
|
|
10
|
-
import {DracoLoaderOptions,
|
|
16
|
+
import {DracoLoaderOptions, DracoMesh} from '@loaders.gl/draco';
|
|
11
17
|
import {sliceArrayBuffer} from '@loaders.gl/loader-utils';
|
|
12
18
|
import {default as Scenegraph} from '../api/gltf-scenegraph';
|
|
13
|
-
import {KHR_DRACO_MESH_COMPRESSION} from '../gltf-utils/gltf-constants';
|
|
14
19
|
import {getGLTFAccessors, getGLTFAccessor} from '../gltf-utils/gltf-attribute-utils';
|
|
15
20
|
|
|
16
|
-
|
|
21
|
+
const KHR_DRACO_MESH_COMPRESSION = 'KHR_draco_mesh_compression';
|
|
22
|
+
|
|
23
|
+
/** Extension name */
|
|
24
|
+
export const name = KHR_DRACO_MESH_COMPRESSION;
|
|
25
|
+
|
|
26
|
+
export function preprocess(
|
|
27
|
+
gltfData: {json: GLTF},
|
|
28
|
+
options: GLTFLoaderOptions,
|
|
29
|
+
context: LoaderContext
|
|
30
|
+
): void {
|
|
31
|
+
const scenegraph = new Scenegraph(gltfData);
|
|
32
|
+
for (const primitive of makeMeshPrimitiveIterator(scenegraph)) {
|
|
33
|
+
if (scenegraph.getObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION)) {
|
|
34
|
+
// TODO - Remove fallback accessors to make sure we don't load unnecessary buffers
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
17
39
|
export async function decode(
|
|
18
40
|
gltfData: {json: GLTF},
|
|
19
41
|
options: GLTFLoaderOptions,
|
|
@@ -64,7 +86,10 @@ async function decompressPrimitive(
|
|
|
64
86
|
options: GLTFLoaderOptions,
|
|
65
87
|
context: LoaderContext
|
|
66
88
|
): Promise<void> {
|
|
67
|
-
const dracoExtension = scenegraph.getObjectExtension(
|
|
89
|
+
const dracoExtension = scenegraph.getObjectExtension<GLTF_KHR_draco_mesh_compression>(
|
|
90
|
+
primitive,
|
|
91
|
+
KHR_DRACO_MESH_COMPRESSION
|
|
92
|
+
);
|
|
68
93
|
if (!dracoExtension) {
|
|
69
94
|
return;
|
|
70
95
|
}
|
|
@@ -79,12 +104,7 @@ async function decompressPrimitive(
|
|
|
79
104
|
|
|
80
105
|
// TODO - remove hack: The entire tileset might be included, too expensive to serialize
|
|
81
106
|
delete dracoOptions['3d-tiles'];
|
|
82
|
-
const decodedData = (await parse(
|
|
83
|
-
bufferCopy,
|
|
84
|
-
DracoLoader,
|
|
85
|
-
dracoOptions,
|
|
86
|
-
context
|
|
87
|
-
)) as DracoMeshData;
|
|
107
|
+
const decodedData = (await parse(bufferCopy, DracoLoader, dracoOptions, context)) as DracoMesh;
|
|
88
108
|
|
|
89
109
|
const decodedAttributes: {[key: string]: GLTFAccessor} = getGLTFAccessors(decodedData.attributes);
|
|
90
110
|
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// GLTF EXTENSION: EXT_TEXTURE_WEBP
|
|
2
|
+
// https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/EXT_TEXTURE_WEBP
|
|
3
|
+
/* eslint-disable camelcase */
|
|
4
|
+
|
|
5
|
+
import type {GLTF, GLTF_KHR_texture_basisu} from '../types/gltf-types';
|
|
6
|
+
import type {GLTFLoaderOptions} from '../../gltf-loader';
|
|
7
|
+
|
|
8
|
+
import GLTFScenegraph from '../api/gltf-scenegraph';
|
|
9
|
+
|
|
10
|
+
const KHR_TEXTURE_BASISU = 'KHR_texture_basisu';
|
|
11
|
+
|
|
12
|
+
/** Extension name */
|
|
13
|
+
export const name = KHR_TEXTURE_BASISU;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Replaces a texture source reference with the extension texture
|
|
17
|
+
* Done in preprocess() to prevent load of default image
|
|
18
|
+
*/
|
|
19
|
+
export function preprocess(gltfData: {json: GLTF}, options: GLTFLoaderOptions): void {
|
|
20
|
+
const scene = new GLTFScenegraph(gltfData);
|
|
21
|
+
const {json} = scene;
|
|
22
|
+
|
|
23
|
+
for (const texture of json.textures || []) {
|
|
24
|
+
const extension = scene.getObjectExtension<GLTF_KHR_texture_basisu>(
|
|
25
|
+
texture,
|
|
26
|
+
KHR_TEXTURE_BASISU
|
|
27
|
+
);
|
|
28
|
+
if (extension) {
|
|
29
|
+
texture.source = extension.source;
|
|
30
|
+
}
|
|
31
|
+
scene.removeObjectExtension(texture, KHR_TEXTURE_BASISU);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Remove the top-level extension
|
|
35
|
+
scene.removeExtension(KHR_TEXTURE_BASISU);
|
|
36
|
+
}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
// GLTF EXTENSION: KHR_lights_punctual
|
|
2
2
|
// https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_lights_punctual
|
|
3
3
|
|
|
4
|
-
import type {GLTF} from '
|
|
4
|
+
import type {GLTF} from '../../types/gltf-types';
|
|
5
5
|
|
|
6
|
-
import {assert} from '
|
|
7
|
-
import GLTFScenegraph from '
|
|
8
|
-
|
|
6
|
+
import {assert} from '../../utils/assert';
|
|
7
|
+
import GLTFScenegraph from '../../api/gltf-scenegraph';
|
|
8
|
+
|
|
9
|
+
const KHR_LIGHTS_PUNCTUAL = 'KHR_lights_punctual';
|
|
10
|
+
|
|
11
|
+
export const name = KHR_LIGHTS_PUNCTUAL;
|
|
9
12
|
|
|
10
13
|
export async function decode(gltfData: {json: GLTF}): Promise<void> {
|
|
11
14
|
const gltfScenegraph = new GLTFScenegraph(gltfData);
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
// GLTF EXTENSION: KHR_materials_unlit
|
|
2
2
|
// https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit
|
|
3
3
|
|
|
4
|
-
import type {GLTF} from '
|
|
4
|
+
import type {GLTF} from '../../types/gltf-types';
|
|
5
5
|
|
|
6
|
-
import GLTFScenegraph from '
|
|
7
|
-
|
|
6
|
+
import GLTFScenegraph from '../../api/gltf-scenegraph';
|
|
7
|
+
|
|
8
|
+
const KHR_MATERIALS_UNLIT = 'KHR_materials_unlit';
|
|
9
|
+
|
|
10
|
+
export const name = KHR_MATERIALS_UNLIT;
|
|
8
11
|
|
|
9
12
|
export async function decode(gltfData: {json: GLTF}): Promise<void> {
|
|
10
13
|
const gltfScenegraph = new GLTFScenegraph(gltfData);
|