@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
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
// https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/EXT_TEXTURE_WEBP
|
|
3
3
|
/* eslint-disable camelcase */
|
|
4
4
|
|
|
5
|
-
import type {GLTF, GLTF_EXT_texture_webp} from '../types/gltf-
|
|
5
|
+
import type {GLTF, GLTF_EXT_texture_webp} from '../types/gltf-json-schema';
|
|
6
6
|
import type {GLTFLoaderOptions} from '../../gltf-loader';
|
|
7
7
|
|
|
8
8
|
import {isImageFormatSupported} from '@loaders.gl/images';
|
|
9
|
-
import GLTFScenegraph from '../api/gltf-scenegraph';
|
|
9
|
+
import {GLTFScenegraph} from '../api/gltf-scenegraph';
|
|
10
10
|
|
|
11
11
|
const EXT_TEXTURE_WEBP = 'EXT_texture_webp';
|
|
12
12
|
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
// https://github.com/KhronosGroup/glTF/tree/master/extensions/1.0/Khronos/KHR_binary_glTF
|
|
3
3
|
/* eslint-disable camelcase */
|
|
4
4
|
|
|
5
|
-
import type {GLTF, GLTF_KHR_binary_glTF} from '../types/gltf-
|
|
5
|
+
import type {GLTF, GLTF_KHR_binary_glTF} from '../types/gltf-json-schema';
|
|
6
6
|
|
|
7
|
-
import GLTFScenegraph from '../api/gltf-scenegraph';
|
|
7
|
+
import {GLTFScenegraph} from '../api/gltf-scenegraph';
|
|
8
8
|
|
|
9
9
|
const KHR_BINARY_GLTF = 'KHR_binary_glTF';
|
|
10
10
|
|
|
@@ -8,14 +8,14 @@ import type {
|
|
|
8
8
|
GLTFAccessor,
|
|
9
9
|
GLTFMeshPrimitive,
|
|
10
10
|
GLTF_KHR_draco_mesh_compression
|
|
11
|
-
} from '../types/gltf-
|
|
11
|
+
} from '../types/gltf-json-schema';
|
|
12
12
|
import type {GLTFLoaderOptions} from '../../gltf-loader';
|
|
13
13
|
|
|
14
14
|
import type {LoaderContext} from '@loaders.gl/loader-utils';
|
|
15
15
|
import {DracoLoader} from '@loaders.gl/draco';
|
|
16
16
|
import {DracoLoaderOptions, DracoMesh} from '@loaders.gl/draco';
|
|
17
17
|
import {sliceArrayBuffer} from '@loaders.gl/loader-utils';
|
|
18
|
-
import {
|
|
18
|
+
import {GLTFScenegraph} from '../api/gltf-scenegraph';
|
|
19
19
|
import {getGLTFAccessors, getGLTFAccessor} from '../gltf-utils/gltf-attribute-utils';
|
|
20
20
|
|
|
21
21
|
const KHR_DRACO_MESH_COMPRESSION = 'KHR_draco_mesh_compression';
|
|
@@ -28,7 +28,7 @@ export function preprocess(
|
|
|
28
28
|
options: GLTFLoaderOptions,
|
|
29
29
|
context: LoaderContext
|
|
30
30
|
): void {
|
|
31
|
-
const scenegraph = new
|
|
31
|
+
const scenegraph = new GLTFScenegraph(gltfData);
|
|
32
32
|
for (const primitive of makeMeshPrimitiveIterator(scenegraph)) {
|
|
33
33
|
if (scenegraph.getObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION)) {
|
|
34
34
|
// TODO - Remove fallback accessors to make sure we don't load unnecessary buffers
|
|
@@ -45,7 +45,7 @@ export async function decode(
|
|
|
45
45
|
return;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
const scenegraph = new
|
|
48
|
+
const scenegraph = new GLTFScenegraph(gltfData);
|
|
49
49
|
const promises: Promise<void>[] = [];
|
|
50
50
|
for (const primitive of makeMeshPrimitiveIterator(scenegraph)) {
|
|
51
51
|
if (scenegraph.getObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION)) {
|
|
@@ -61,7 +61,7 @@ export async function decode(
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
export function encode(gltfData, options: GLTFLoaderOptions = {}): void {
|
|
64
|
-
const scenegraph = new
|
|
64
|
+
const scenegraph = new GLTFScenegraph(gltfData);
|
|
65
65
|
|
|
66
66
|
for (const mesh of scenegraph.json.meshes || []) {
|
|
67
67
|
// eslint-disable-next-line camelcase
|
|
@@ -81,7 +81,7 @@ export function encode(gltfData, options: GLTFLoaderOptions = {}): void {
|
|
|
81
81
|
// TODO - Implement fallback behavior per KHR_DRACO_MESH_COMPRESSION spec
|
|
82
82
|
|
|
83
83
|
async function decompressPrimitive(
|
|
84
|
-
scenegraph:
|
|
84
|
+
scenegraph: GLTFScenegraph,
|
|
85
85
|
primitive: GLTFMeshPrimitive,
|
|
86
86
|
options: GLTFLoaderOptions,
|
|
87
87
|
context: LoaderContext
|
|
@@ -128,7 +128,7 @@ async function decompressPrimitive(
|
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
// Extension has been processed, delete it
|
|
131
|
-
|
|
131
|
+
scenegraph.removeObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION);
|
|
132
132
|
|
|
133
133
|
checkPrimitive(primitive);
|
|
134
134
|
}
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
// https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_basisu
|
|
3
3
|
/* eslint-disable camelcase */
|
|
4
4
|
|
|
5
|
-
import type {GLTF, GLTF_KHR_texture_basisu} from '../types/gltf-
|
|
5
|
+
import type {GLTF, GLTF_KHR_texture_basisu} from '../types/gltf-json-schema';
|
|
6
6
|
import type {GLTFLoaderOptions} from '../../gltf-loader';
|
|
7
7
|
|
|
8
|
-
import GLTFScenegraph from '../api/gltf-scenegraph';
|
|
8
|
+
import {GLTFScenegraph} from '../api/gltf-scenegraph';
|
|
9
9
|
|
|
10
10
|
const KHR_TEXTURE_BASISU = 'KHR_texture_basisu';
|
|
11
11
|
|
|
@@ -28,8 +28,8 @@ export function preprocess(gltfData: {json: GLTF}, options: GLTFLoaderOptions):
|
|
|
28
28
|
if (extension) {
|
|
29
29
|
// TODO - if multiple texture extensions are present which one wins?
|
|
30
30
|
texture.source = extension.source;
|
|
31
|
+
scene.removeObjectExtension(texture, KHR_TEXTURE_BASISU);
|
|
31
32
|
}
|
|
32
|
-
scene.removeObjectExtension(texture, KHR_TEXTURE_BASISU);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
// Remove the top-level extension
|
|
@@ -3,18 +3,21 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import {Vector3, Matrix3} from '@math.gl/core';
|
|
6
|
-
import type {
|
|
6
|
+
import type {GLTFWithBuffers} from '../types/gltf-types';
|
|
7
|
+
import type {
|
|
8
|
+
GLTFMeshPrimitive,
|
|
9
|
+
GLTFAccessor,
|
|
10
|
+
GLTFBufferView,
|
|
11
|
+
GLTFMaterialNormalTextureInfo,
|
|
12
|
+
GLTFMaterialOcclusionTextureInfo,
|
|
13
|
+
GLTFTextureInfo
|
|
14
|
+
} from '../types/gltf-json-schema';
|
|
7
15
|
import type {GLTFLoaderOptions} from '../../gltf-loader';
|
|
16
|
+
|
|
8
17
|
import {getAccessorArrayTypeAndLength} from '../gltf-utils/gltf-utils';
|
|
9
18
|
import {BYTES, COMPONENTS} from '../gltf-utils/gltf-constants';
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
BufferView,
|
|
13
|
-
MaterialNormalTextureInfo,
|
|
14
|
-
MaterialOcclusionTextureInfo,
|
|
15
|
-
TextureInfo as GLTFTextureInfo
|
|
16
|
-
} from '../types/gltf-json-schema';
|
|
17
|
-
import GLTFScenegraph from '../api/gltf-scenegraph';
|
|
19
|
+
import {} from '../types/gltf-json-schema';
|
|
20
|
+
import {GLTFScenegraph} from '../api/gltf-scenegraph';
|
|
18
21
|
|
|
19
22
|
/** Extension name */
|
|
20
23
|
const EXT_MESHOPT_TRANSFORM = 'KHR_texture_transform';
|
|
@@ -38,8 +41,8 @@ type TextureInfo = {
|
|
|
38
41
|
};
|
|
39
42
|
/** Intersection of all GLTF textures */
|
|
40
43
|
type CompoundGLTFTextureInfo = GLTFTextureInfo &
|
|
41
|
-
|
|
42
|
-
|
|
44
|
+
GLTFMaterialNormalTextureInfo &
|
|
45
|
+
GLTFMaterialOcclusionTextureInfo;
|
|
43
46
|
/** Parameters for TEXCOORD transformation */
|
|
44
47
|
type TransformParameters = {
|
|
45
48
|
/** Original texCoord value https://www.khronos.org/registry/glTF/specs/2.0/glTF-2.0.html#_textureinfo_texcoord */
|
|
@@ -57,8 +60,8 @@ type TransformParameters = {
|
|
|
57
60
|
*/
|
|
58
61
|
export async function decode(gltfData: GLTFWithBuffers, options: GLTFLoaderOptions) {
|
|
59
62
|
const gltfScenegraph = new GLTFScenegraph(gltfData);
|
|
60
|
-
const
|
|
61
|
-
if (!
|
|
63
|
+
const hasExtension = gltfScenegraph.hasExtension(EXT_MESHOPT_TRANSFORM);
|
|
64
|
+
if (!hasExtension) {
|
|
62
65
|
return;
|
|
63
66
|
}
|
|
64
67
|
const materials = gltfData.json.materials || [];
|
|
@@ -220,8 +223,8 @@ function transformPrimitive(
|
|
|
220
223
|
* @param newTexcoordArray typed array with data after transformation
|
|
221
224
|
*/
|
|
222
225
|
function updateGltf(
|
|
223
|
-
accessor:
|
|
224
|
-
bufferView:
|
|
226
|
+
accessor: GLTFAccessor,
|
|
227
|
+
bufferView: GLTFBufferView,
|
|
225
228
|
buffers: {arrayBuffer: ArrayBuffer; byteOffset: number; byteLength: number}[],
|
|
226
229
|
newTexCoordArray: Float32Array
|
|
227
230
|
): void {
|
|
@@ -248,7 +251,7 @@ function updateGltf(
|
|
|
248
251
|
*/
|
|
249
252
|
function createAttribute(
|
|
250
253
|
newTexCoord: number,
|
|
251
|
-
originalAccessor:
|
|
254
|
+
originalAccessor: GLTFAccessor,
|
|
252
255
|
primitive: GLTFMeshPrimitive,
|
|
253
256
|
gltfData: GLTFWithBuffers,
|
|
254
257
|
newTexCoordArray: Float32Array
|
|
@@ -288,8 +291,8 @@ function createAttribute(
|
|
|
288
291
|
*/
|
|
289
292
|
function makeTransformationMatrix(extensionData: TextureInfo): Matrix3 {
|
|
290
293
|
const {offset = [0, 0], rotation = 0, scale = [1, 1]} = extensionData;
|
|
291
|
-
const
|
|
292
|
-
const
|
|
294
|
+
const translationMatrix = new Matrix3().set(1, 0, 0, 0, 1, 0, offset[0], offset[1], 1);
|
|
295
|
+
const rotationMatrix = scratchRotationMatrix.set(
|
|
293
296
|
Math.cos(rotation),
|
|
294
297
|
Math.sin(rotation),
|
|
295
298
|
0,
|
|
@@ -301,5 +304,5 @@ function makeTransformationMatrix(extensionData: TextureInfo): Matrix3 {
|
|
|
301
304
|
1
|
|
302
305
|
);
|
|
303
306
|
const scaleMatrix = scratchScaleMatrix.set(scale[0], 0, 0, 0, scale[1], 0, 0, 0, 1);
|
|
304
|
-
return
|
|
307
|
+
return translationMatrix.multiplyRight(rotationMatrix).multiplyRight(scaleMatrix);
|
|
305
308
|
}
|
|
@@ -1,44 +1,41 @@
|
|
|
1
1
|
/* eslint-disable camelcase */
|
|
2
|
-
import type {GLTF} from '../../types/gltf-
|
|
3
|
-
|
|
4
|
-
import
|
|
2
|
+
import type {GLTF} from '../../types/gltf-json-schema';
|
|
3
|
+
import {GLTFScenegraph} from '../../api/gltf-scenegraph';
|
|
4
|
+
import {getImageData} from '@loaders.gl/images';
|
|
5
5
|
import {
|
|
6
6
|
ClassProperty,
|
|
7
7
|
EXT_feature_metadata_class_object,
|
|
8
8
|
EXT_feature_metadata_feature_table,
|
|
9
9
|
FeatureTableProperty,
|
|
10
|
-
GLTF_EXT_feature_metadata
|
|
10
|
+
GLTF_EXT_feature_metadata,
|
|
11
|
+
EXT_feature_metadata_feature_texture,
|
|
12
|
+
FeatureTextureProperty,
|
|
13
|
+
GLTFMeshPrimitive
|
|
11
14
|
} from '../../types/gltf-json-schema';
|
|
15
|
+
import {getComponentTypeFromArray} from '../../gltf-utils/gltf-utils';
|
|
16
|
+
import {GLTFLoaderOptions} from '../../../gltf-loader';
|
|
12
17
|
|
|
13
18
|
/** Extension name */
|
|
14
19
|
const EXT_FEATURE_METADATA = 'EXT_feature_metadata';
|
|
15
20
|
|
|
16
21
|
export const name = EXT_FEATURE_METADATA;
|
|
17
22
|
|
|
18
|
-
export async function decode(gltfData: {json: GLTF}): Promise<void> {
|
|
23
|
+
export async function decode(gltfData: {json: GLTF}, options: GLTFLoaderOptions): Promise<void> {
|
|
19
24
|
const scenegraph = new GLTFScenegraph(gltfData);
|
|
20
|
-
decodeExtFeatureMetadata(scenegraph);
|
|
25
|
+
decodeExtFeatureMetadata(scenegraph, options);
|
|
21
26
|
}
|
|
22
27
|
|
|
23
28
|
/**
|
|
24
29
|
* Decodes feature metadata from extension
|
|
25
30
|
* @param scenegraph
|
|
26
31
|
*/
|
|
27
|
-
function decodeExtFeatureMetadata(scenegraph: GLTFScenegraph): void {
|
|
32
|
+
function decodeExtFeatureMetadata(scenegraph: GLTFScenegraph, options: GLTFLoaderOptions): void {
|
|
28
33
|
const extension: GLTF_EXT_feature_metadata | null = scenegraph.getExtension(EXT_FEATURE_METADATA);
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
if (featureTextures) {
|
|
34
|
-
/*
|
|
35
|
-
* TODO add support for featureTextures
|
|
36
|
-
* Spec - https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata#feature-textures
|
|
37
|
-
*/
|
|
38
|
-
// eslint-disable-next-line no-console
|
|
39
|
-
console.warn('featureTextures is not yet supported in the "EXT_feature_metadata" extension.');
|
|
40
|
-
}
|
|
34
|
+
if (!extension) return;
|
|
35
|
+
|
|
36
|
+
const schemaClasses = extension.schema?.classes;
|
|
41
37
|
|
|
38
|
+
const {featureTables} = extension;
|
|
42
39
|
if (schemaClasses && featureTables) {
|
|
43
40
|
for (const schemaName in schemaClasses) {
|
|
44
41
|
const schemaClass = schemaClasses[schemaName];
|
|
@@ -49,6 +46,18 @@ function decodeExtFeatureMetadata(scenegraph: GLTFScenegraph): void {
|
|
|
49
46
|
}
|
|
50
47
|
}
|
|
51
48
|
}
|
|
49
|
+
|
|
50
|
+
const {featureTextures} = extension;
|
|
51
|
+
if (schemaClasses && featureTextures && options.gltf?.loadImages) {
|
|
52
|
+
for (const schemaName in schemaClasses) {
|
|
53
|
+
const schemaClass = schemaClasses[schemaName];
|
|
54
|
+
const featureTexture = findFeatureTextureByName(featureTextures, schemaName);
|
|
55
|
+
|
|
56
|
+
if (featureTexture) {
|
|
57
|
+
handleFeatureTextureProperties(scenegraph, featureTexture, schemaClass);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
52
61
|
}
|
|
53
62
|
|
|
54
63
|
/**
|
|
@@ -79,6 +88,30 @@ function handleFeatureTableProperties(
|
|
|
79
88
|
}
|
|
80
89
|
}
|
|
81
90
|
|
|
91
|
+
/**
|
|
92
|
+
* Navigate throw all properies in feature texture and gets properties data.
|
|
93
|
+
* Data will be stored in featureTexture.properties[propertyName].data
|
|
94
|
+
* @param scenegraph
|
|
95
|
+
* @param featureTexture
|
|
96
|
+
* @param schemaClass
|
|
97
|
+
*/
|
|
98
|
+
function handleFeatureTextureProperties(
|
|
99
|
+
scenegraph: GLTFScenegraph,
|
|
100
|
+
featureTexture: EXT_feature_metadata_feature_texture,
|
|
101
|
+
schemaClass: EXT_feature_metadata_class_object
|
|
102
|
+
): void {
|
|
103
|
+
const attributeName = featureTexture.class;
|
|
104
|
+
|
|
105
|
+
for (const propertyName in schemaClass.properties) {
|
|
106
|
+
const featureTextureProperty = featureTexture?.properties?.[propertyName];
|
|
107
|
+
|
|
108
|
+
if (featureTextureProperty) {
|
|
109
|
+
const data = getPropertyDataFromTexture(scenegraph, featureTextureProperty, attributeName);
|
|
110
|
+
featureTextureProperty.data = data;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
82
115
|
/**
|
|
83
116
|
* Decode properties from binary sourse based on property type.
|
|
84
117
|
* @param scenegraph
|
|
@@ -94,20 +127,213 @@ function getPropertyDataFromBinarySource(
|
|
|
94
127
|
): Uint8Array | string[] {
|
|
95
128
|
const bufferView = featureTableProperty.bufferView;
|
|
96
129
|
// TODO think maybe we shouldn't get data only in Uint8Array format.
|
|
97
|
-
|
|
130
|
+
const dataArray: Uint8Array = scenegraph.getTypedArrayForBufferView(bufferView);
|
|
98
131
|
|
|
99
132
|
switch (schemaProperty.type) {
|
|
100
133
|
case 'STRING': {
|
|
101
134
|
// stringOffsetBufferView should be available for string type.
|
|
102
135
|
const stringOffsetBufferView = featureTableProperty.stringOffsetBufferView!;
|
|
103
136
|
const offsetsData = scenegraph.getTypedArrayForBufferView(stringOffsetBufferView);
|
|
104
|
-
|
|
105
|
-
break;
|
|
137
|
+
return getStringAttributes(dataArray, offsetsData, numberOfFeatures);
|
|
106
138
|
}
|
|
107
139
|
default:
|
|
108
140
|
}
|
|
109
141
|
|
|
110
|
-
return
|
|
142
|
+
return dataArray;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Get properties from texture associated with all mesh primitives.
|
|
147
|
+
* @param scenegraph
|
|
148
|
+
* @param featureTextureProperty
|
|
149
|
+
* @param attributeName
|
|
150
|
+
* @returns Feature texture data
|
|
151
|
+
*/
|
|
152
|
+
function getPropertyDataFromTexture(
|
|
153
|
+
scenegraph: GLTFScenegraph,
|
|
154
|
+
featureTextureProperty: FeatureTextureProperty,
|
|
155
|
+
attributeName: string
|
|
156
|
+
): number[] {
|
|
157
|
+
const json = scenegraph.gltf.json;
|
|
158
|
+
if (!json.meshes) {
|
|
159
|
+
return [];
|
|
160
|
+
}
|
|
161
|
+
const featureTextureTable: number[] = [];
|
|
162
|
+
for (const mesh of json.meshes) {
|
|
163
|
+
for (const primitive of mesh.primitives) {
|
|
164
|
+
processPrimitiveTextures(
|
|
165
|
+
scenegraph,
|
|
166
|
+
attributeName,
|
|
167
|
+
featureTextureProperty,
|
|
168
|
+
featureTextureTable,
|
|
169
|
+
primitive
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return featureTextureTable;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// eslint-disable-next-line max-statements
|
|
177
|
+
/**
|
|
178
|
+
* Processes data encoded in the texture associated with the primitive. This data will be accessible through the attributes.
|
|
179
|
+
* @param scenegraph
|
|
180
|
+
* @param attributeName
|
|
181
|
+
* @param featureTextureProperty
|
|
182
|
+
* @param featureTextureTable
|
|
183
|
+
* @param primitive
|
|
184
|
+
*/
|
|
185
|
+
function processPrimitiveTextures(
|
|
186
|
+
scenegraph: GLTFScenegraph,
|
|
187
|
+
attributeName: string,
|
|
188
|
+
featureTextureProperty: FeatureTextureProperty,
|
|
189
|
+
featureTextureTable: number[],
|
|
190
|
+
primitive: GLTFMeshPrimitive
|
|
191
|
+
): void {
|
|
192
|
+
/*
|
|
193
|
+
texture.index is an index for the "textures" array.
|
|
194
|
+
The texture object referenced by this index looks like this:
|
|
195
|
+
{
|
|
196
|
+
"sampler": 0,
|
|
197
|
+
"source": 0
|
|
198
|
+
}
|
|
199
|
+
"sampler" is an index for the "samplers" array
|
|
200
|
+
"source" is an index for the "images" array that contains data. These data are stored in rgba channels of the image.
|
|
201
|
+
|
|
202
|
+
texture.texCoord is a number-suffix (like 1) for an attribute like "TEXCOORD_1" in meshes.primitives
|
|
203
|
+
The value of "TEXCOORD_1" is an accessor that is used to get coordinates. These coordinates ared used to get data from the image.
|
|
204
|
+
*/
|
|
205
|
+
const json = scenegraph.gltf.json;
|
|
206
|
+
const textureData: number[] = [];
|
|
207
|
+
const texCoordAccessorKey = `TEXCOORD_${featureTextureProperty.texture.texCoord}`;
|
|
208
|
+
const texCoordAccessorIndex = primitive.attributes[texCoordAccessorKey];
|
|
209
|
+
const texCoordBufferView = scenegraph.getBufferView(texCoordAccessorIndex);
|
|
210
|
+
const texCoordArray: Uint8Array = scenegraph.getTypedArrayForBufferView(texCoordBufferView);
|
|
211
|
+
|
|
212
|
+
const textureCoordinates: Float32Array = new Float32Array(
|
|
213
|
+
texCoordArray.buffer,
|
|
214
|
+
texCoordArray.byteOffset,
|
|
215
|
+
texCoordArray.length / 4
|
|
216
|
+
);
|
|
217
|
+
// textureCoordinates contains UV coordinates of the actual data stored in the texture
|
|
218
|
+
// accessor.count is a number of UV pairs (they are stored as VEC2)
|
|
219
|
+
|
|
220
|
+
const textureIndex = featureTextureProperty.texture.index;
|
|
221
|
+
const texture = json.textures?.[textureIndex];
|
|
222
|
+
const imageIndex = texture?.source;
|
|
223
|
+
if (typeof imageIndex !== 'undefined') {
|
|
224
|
+
const image = json.images?.[imageIndex];
|
|
225
|
+
const mimeType = image?.mimeType;
|
|
226
|
+
const parsedImage = scenegraph.gltf.images?.[imageIndex];
|
|
227
|
+
if (parsedImage) {
|
|
228
|
+
for (let index = 0; index < textureCoordinates.length; index += 2) {
|
|
229
|
+
const value = getImageValueByCoordinates(
|
|
230
|
+
parsedImage,
|
|
231
|
+
mimeType,
|
|
232
|
+
textureCoordinates,
|
|
233
|
+
index,
|
|
234
|
+
featureTextureProperty.channels
|
|
235
|
+
);
|
|
236
|
+
textureData.push(value);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
/*
|
|
241
|
+
featureTextureTable will contain unique values, e.g.
|
|
242
|
+
textureData = [24, 35, 28, 24]
|
|
243
|
+
featureTextureTable = [24, 35, 28]
|
|
244
|
+
featureIndices will contain indices hat refer featureTextureTable, e.g.
|
|
245
|
+
featureIndices = [0, 1, 2, 0]
|
|
246
|
+
*/
|
|
247
|
+
const featureIndices: number[] = [];
|
|
248
|
+
for (const texelData of textureData) {
|
|
249
|
+
let index = featureTextureTable.findIndex((item) => item === texelData);
|
|
250
|
+
if (index === -1) {
|
|
251
|
+
index = featureTextureTable.push(texelData) - 1;
|
|
252
|
+
}
|
|
253
|
+
featureIndices.push(index);
|
|
254
|
+
}
|
|
255
|
+
const typedArray = new Uint32Array(featureIndices);
|
|
256
|
+
const bufferIndex =
|
|
257
|
+
scenegraph.gltf.buffers.push({
|
|
258
|
+
arrayBuffer: typedArray.buffer,
|
|
259
|
+
byteOffset: 0,
|
|
260
|
+
byteLength: typedArray.byteLength
|
|
261
|
+
}) - 1;
|
|
262
|
+
const bufferViewIndex = scenegraph.addBufferView(typedArray, bufferIndex, 0);
|
|
263
|
+
const accessorIndex = scenegraph.addAccessor(bufferViewIndex, {
|
|
264
|
+
size: 1,
|
|
265
|
+
componentType: getComponentTypeFromArray(typedArray),
|
|
266
|
+
count: typedArray.length
|
|
267
|
+
});
|
|
268
|
+
primitive.attributes[attributeName] = accessorIndex;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function getImageValueByCoordinates(
|
|
272
|
+
parsedImage: any,
|
|
273
|
+
mimeType: string | undefined,
|
|
274
|
+
textureCoordinates: Float32Array,
|
|
275
|
+
index: number,
|
|
276
|
+
channels: string
|
|
277
|
+
) {
|
|
278
|
+
const CHANNELS_MAP = {
|
|
279
|
+
r: {offset: 0, shift: 0},
|
|
280
|
+
g: {offset: 1, shift: 8},
|
|
281
|
+
b: {offset: 2, shift: 16},
|
|
282
|
+
a: {offset: 3, shift: 24}
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
const u = textureCoordinates[index];
|
|
286
|
+
const v = textureCoordinates[index + 1];
|
|
287
|
+
|
|
288
|
+
let components = 1;
|
|
289
|
+
if (mimeType && (mimeType.indexOf('image/jpeg') !== -1 || mimeType.indexOf('image/png') !== -1))
|
|
290
|
+
components = 4;
|
|
291
|
+
const offset = coordinatesToOffset(u, v, parsedImage, components);
|
|
292
|
+
let value = 0;
|
|
293
|
+
for (const c of channels) {
|
|
294
|
+
const map = CHANNELS_MAP[c];
|
|
295
|
+
const val = getVal(parsedImage, offset + map.offset);
|
|
296
|
+
value |= val << map.shift;
|
|
297
|
+
}
|
|
298
|
+
return value;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function getVal(parsedImage: any, offset: number): number {
|
|
302
|
+
const imageData = getImageData(parsedImage);
|
|
303
|
+
if (imageData.data.length <= offset) {
|
|
304
|
+
throw new Error(`${imageData.data.length} <= ${offset}`);
|
|
305
|
+
}
|
|
306
|
+
return imageData.data[offset];
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function coordinatesToOffset(
|
|
310
|
+
u: number,
|
|
311
|
+
v: number,
|
|
312
|
+
parsedImage: any,
|
|
313
|
+
componentsCount: number = 1
|
|
314
|
+
): number {
|
|
315
|
+
const w = parsedImage.width;
|
|
316
|
+
const iX = emod(u) * (w - 1);
|
|
317
|
+
const indX = Math.round(iX);
|
|
318
|
+
|
|
319
|
+
const h = parsedImage.height;
|
|
320
|
+
const iY = emod(v) * (h - 1);
|
|
321
|
+
const indY = Math.round(iY);
|
|
322
|
+
const components = parsedImage.components ? parsedImage.components : componentsCount;
|
|
323
|
+
// components is a number of channels in the image
|
|
324
|
+
const offset = (indY * w + indX) * components;
|
|
325
|
+
return offset;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// The following is taken from tile-converter\src\i3s-converter\helpers\batch-ids-extensions.ts
|
|
329
|
+
/**
|
|
330
|
+
* Handle UVs if they are out of range [0,1].
|
|
331
|
+
* @param n
|
|
332
|
+
* @param m
|
|
333
|
+
*/
|
|
334
|
+
function emod(n: number): number {
|
|
335
|
+
const a = ((n % 1) + 1) % 1;
|
|
336
|
+
return a;
|
|
111
337
|
}
|
|
112
338
|
|
|
113
339
|
/**
|
|
@@ -130,6 +356,21 @@ function findFeatureTableByName(
|
|
|
130
356
|
return null;
|
|
131
357
|
}
|
|
132
358
|
|
|
359
|
+
function findFeatureTextureByName(
|
|
360
|
+
featureTextures: {[key: string]: EXT_feature_metadata_feature_texture},
|
|
361
|
+
schemaClassName: string
|
|
362
|
+
): EXT_feature_metadata_feature_texture | null {
|
|
363
|
+
for (const featureTexturesName in featureTextures) {
|
|
364
|
+
const featureTable = featureTextures[featureTexturesName];
|
|
365
|
+
|
|
366
|
+
if (featureTable.class === schemaClassName) {
|
|
367
|
+
return featureTable;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
return null;
|
|
372
|
+
}
|
|
373
|
+
|
|
133
374
|
/**
|
|
134
375
|
* Getting string attributes from binary data.
|
|
135
376
|
* Spec - https://github.com/CesiumGS/3d-tiles/tree/main/specification/Metadata#strings
|
|
@@ -1,10 +1,10 @@
|
|
|
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 '../../types/gltf-
|
|
4
|
+
import type {GLTF} from '../../types/gltf-json-schema';
|
|
5
5
|
|
|
6
6
|
import {assert} from '../../utils/assert';
|
|
7
|
-
import GLTFScenegraph from '../../api/gltf-scenegraph';
|
|
7
|
+
import {GLTFScenegraph} from '../../api/gltf-scenegraph';
|
|
8
8
|
|
|
9
9
|
const KHR_LIGHTS_PUNCTUAL = 'KHR_lights_punctual';
|
|
10
10
|
|
|
@@ -1,9 +1,9 @@
|
|
|
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 '../../types/gltf-
|
|
4
|
+
import type {GLTF} from '../../types/gltf-json-schema';
|
|
5
5
|
|
|
6
|
-
import GLTFScenegraph from '../../api/gltf-scenegraph';
|
|
6
|
+
import {GLTFScenegraph} from '../../api/gltf-scenegraph';
|
|
7
7
|
|
|
8
8
|
const KHR_MATERIALS_UNLIT = 'KHR_materials_unlit';
|
|
9
9
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// GLTF EXTENSION: KHR_techniques_webgl
|
|
2
2
|
// https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_techniques_webgl
|
|
3
3
|
|
|
4
|
-
import type {GLTF} from '../../types/gltf-
|
|
4
|
+
import type {GLTF} from '../../types/gltf-json-schema';
|
|
5
5
|
|
|
6
|
-
import GLTFScenegraph from '../../api/gltf-scenegraph';
|
|
6
|
+
import {GLTFScenegraph} from '../../api/gltf-scenegraph';
|
|
7
7
|
|
|
8
8
|
const KHR_TECHNIQUES_WEBGL = 'KHR_techniques_webgl';
|
|
9
9
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// import type {TypedArray} from '../types/loader-utils';
|
|
2
|
-
import type {GLTFAccessor} from '../types/gltf-
|
|
2
|
+
import type {GLTFAccessor} from '../types/gltf-json-schema';
|
|
3
3
|
// TODO - remove
|
|
4
4
|
import {getAccessorTypeFromSize, getComponentTypeFromArray} from './gltf-utils';
|
|
5
5
|
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import {assert} from '../utils/assert';
|
|
2
|
+
import type {GLTFPostprocessed} from '../types/gltf-postprocessed-schema';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Memory needed to store texture and all mipmap levels 1 + 1/4 + 1/16 + 1/64 + ...
|
|
6
|
+
* Minimum 1.33, but due to GPU layout may be 1.5
|
|
7
|
+
*/
|
|
8
|
+
const MIPMAP_FACTOR = 1.33;
|
|
2
9
|
|
|
3
10
|
const TYPES = ['SCALAR', 'VEC2', 'VEC3', 'VEC4'];
|
|
4
11
|
|
|
@@ -77,3 +84,27 @@ export function getAccessorArrayTypeAndLength(accessor, bufferView) {
|
|
|
77
84
|
assert(byteLength >= 0 && byteLength <= bufferView.byteLength);
|
|
78
85
|
return {ArrayType, length, byteLength};
|
|
79
86
|
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Calculate the GPU memory used by a GLTF tile, for both buffer and texture memory
|
|
90
|
+
* @param gltf - the gltf content of a GLTF tile
|
|
91
|
+
* @returns - total memory usage in bytes
|
|
92
|
+
*/
|
|
93
|
+
export function getMemoryUsageGLTF(gltf: GLTFPostprocessed): number {
|
|
94
|
+
let {images, bufferViews} = gltf;
|
|
95
|
+
images = images || [];
|
|
96
|
+
bufferViews = bufferViews || [];
|
|
97
|
+
const imageBufferViews = images.map((i) => i.bufferView);
|
|
98
|
+
bufferViews = bufferViews.filter((view) => !imageBufferViews.includes(view as any));
|
|
99
|
+
|
|
100
|
+
const bufferMemory = bufferViews.reduce((acc, view) => acc + view.byteLength, 0);
|
|
101
|
+
|
|
102
|
+
// Assume each pixel of the texture is 4 channel with mimmaps (which add 33%)
|
|
103
|
+
// TODO correctly handle compressed textures
|
|
104
|
+
const pixelCount = images.reduce((acc, image) => {
|
|
105
|
+
// @ts-ignore
|
|
106
|
+
const {width, height} = (image as any).image;
|
|
107
|
+
return acc + width * height;
|
|
108
|
+
}, 0);
|
|
109
|
+
return bufferMemory + Math.ceil(4 * pixelCount * MIPMAP_FACTOR);
|
|
110
|
+
}
|