@loaders.gl/gltf 3.4.11 → 3.4.13

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.
Files changed (40) hide show
  1. package/dist/es5/lib/utils/version.js +1 -1
  2. package/dist/esm/lib/utils/version.js +1 -1
  3. package/package.json +6 -6
  4. package/dist/bundle.js +0 -5
  5. package/dist/glb-loader.js +0 -39
  6. package/dist/glb-writer.js +0 -37
  7. package/dist/gltf-loader.js +0 -50
  8. package/dist/gltf-writer.js +0 -32
  9. package/dist/index.js +0 -23
  10. package/dist/lib/api/gltf-extensions.js +0 -83
  11. package/dist/lib/api/gltf-scenegraph.js +0 -566
  12. package/dist/lib/api/normalize-gltf-v1.js +0 -299
  13. package/dist/lib/api/post-process-gltf.js +0 -370
  14. package/dist/lib/encoders/encode-glb.js +0 -61
  15. package/dist/lib/encoders/encode-gltf.js +0 -27
  16. package/dist/lib/extensions/EXT_meshopt_compression.js +0 -45
  17. package/dist/lib/extensions/EXT_texture_webp.js +0 -39
  18. package/dist/lib/extensions/KHR_binary_gltf.js +0 -42
  19. package/dist/lib/extensions/KHR_draco_mesh_compression.js +0 -141
  20. package/dist/lib/extensions/KHR_texture_basisu.js +0 -32
  21. package/dist/lib/extensions/KHR_texture_transform.js +0 -230
  22. package/dist/lib/extensions/deprecated/EXT_feature_metadata.js +0 -118
  23. package/dist/lib/extensions/deprecated/KHR_lights_punctual.js +0 -62
  24. package/dist/lib/extensions/deprecated/KHR_materials_unlit.js +0 -47
  25. package/dist/lib/extensions/deprecated/KHR_techniques_webgl.js +0 -82
  26. package/dist/lib/gltf-utils/get-typed-array.js +0 -41
  27. package/dist/lib/gltf-utils/gltf-attribute-utils.js +0 -73
  28. package/dist/lib/gltf-utils/gltf-constants.js +0 -43
  29. package/dist/lib/gltf-utils/gltf-utils.js +0 -85
  30. package/dist/lib/gltf-utils/resolve-url.js +0 -18
  31. package/dist/lib/parsers/parse-glb.js +0 -141
  32. package/dist/lib/parsers/parse-gltf.js +0 -203
  33. package/dist/lib/types/glb-types.js +0 -2
  34. package/dist/lib/types/gltf-json-schema.js +0 -4
  35. package/dist/lib/types/gltf-postprocessed-schema.js +0 -4
  36. package/dist/lib/types/gltf-types.js +0 -3
  37. package/dist/lib/utils/assert.js +0 -12
  38. package/dist/lib/utils/version.js +0 -7
  39. package/dist/meshopt/meshopt-decoder.js +0 -118
  40. package/dist/webp/webp.js +0 -38
@@ -1,118 +0,0 @@
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.name = void 0;
7
- const gltf_scenegraph_1 = __importDefault(require("../../api/gltf-scenegraph"));
8
- /** Extension name */
9
- const EXT_FEATURE_METADATA = 'EXT_feature_metadata';
10
- exports.name = EXT_FEATURE_METADATA;
11
- async function decode(gltfData) {
12
- const scenegraph = new gltf_scenegraph_1.default(gltfData);
13
- decodeExtFeatureMetadata(scenegraph);
14
- }
15
- exports.decode = decode;
16
- /**
17
- * Decodes feature metadata from extension
18
- * @param scenegraph
19
- */
20
- function decodeExtFeatureMetadata(scenegraph) {
21
- const extension = scenegraph.getExtension(EXT_FEATURE_METADATA);
22
- const schemaClasses = extension?.schema?.classes;
23
- const featureTables = extension?.featureTables;
24
- const featureTextures = extension?.featureTextures;
25
- if (featureTextures) {
26
- /*
27
- * TODO add support for featureTextures
28
- * Spec - https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata#feature-textures
29
- */
30
- // eslint-disable-next-line no-console
31
- console.warn('featureTextures is not yet supported in the "EXT_feature_metadata" extension.');
32
- }
33
- if (schemaClasses && featureTables) {
34
- for (const schemaName in schemaClasses) {
35
- const schemaClass = schemaClasses[schemaName];
36
- const featureTable = findFeatureTableByName(featureTables, schemaName);
37
- if (featureTable) {
38
- handleFeatureTableProperties(scenegraph, featureTable, schemaClass);
39
- }
40
- }
41
- }
42
- }
43
- /**
44
- * Navigate throw all properies in feature table and gets properties data.
45
- * @param scenegraph
46
- * @param featureTable
47
- * @param schemaClass
48
- */
49
- function handleFeatureTableProperties(scenegraph, featureTable, schemaClass) {
50
- for (const propertyName in schemaClass.properties) {
51
- const schemaProperty = schemaClass.properties[propertyName];
52
- const featureTableProperty = featureTable?.properties?.[propertyName];
53
- const numberOfFeatures = featureTable.count;
54
- if (featureTableProperty) {
55
- const data = getPropertyDataFromBinarySource(scenegraph, schemaProperty, numberOfFeatures, featureTableProperty);
56
- featureTableProperty.data = data;
57
- }
58
- }
59
- }
60
- /**
61
- * Decode properties from binary sourse based on property type.
62
- * @param scenegraph
63
- * @param schemaProperty
64
- * @param numberOfFeatures
65
- * @param featureTableProperty
66
- */
67
- function getPropertyDataFromBinarySource(scenegraph, schemaProperty, numberOfFeatures, featureTableProperty) {
68
- const bufferView = featureTableProperty.bufferView;
69
- // TODO think maybe we shouldn't get data only in Uint8Array format.
70
- let data = scenegraph.getTypedArrayForBufferView(bufferView);
71
- switch (schemaProperty.type) {
72
- case 'STRING': {
73
- // stringOffsetBufferView should be available for string type.
74
- const stringOffsetBufferView = featureTableProperty.stringOffsetBufferView;
75
- const offsetsData = scenegraph.getTypedArrayForBufferView(stringOffsetBufferView);
76
- data = getStringAttributes(data, offsetsData, numberOfFeatures);
77
- break;
78
- }
79
- default:
80
- }
81
- return data;
82
- }
83
- /**
84
- * Find the feature table by class name.
85
- * @param featureTables
86
- * @param schemaClassName
87
- */
88
- function findFeatureTableByName(featureTables, schemaClassName) {
89
- for (const featureTableName in featureTables) {
90
- const featureTable = featureTables[featureTableName];
91
- if (featureTable.class === schemaClassName) {
92
- return featureTable;
93
- }
94
- }
95
- return null;
96
- }
97
- /**
98
- * Getting string attributes from binary data.
99
- * Spec - https://github.com/CesiumGS/3d-tiles/tree/main/specification/Metadata#strings
100
- * @param data
101
- * @param offsetsData
102
- * @param stringsCount
103
- */
104
- function getStringAttributes(data, offsetsData, stringsCount) {
105
- const stringsArray = [];
106
- const textDecoder = new TextDecoder('utf8');
107
- let stringOffset = 0;
108
- const bytesPerStringSize = 4;
109
- for (let index = 0; index < stringsCount; index++) {
110
- // TODO check if it is multiplication on bytesPerStringSize is valid operation?
111
- const stringByteSize = offsetsData[(index + 1) * bytesPerStringSize] - offsetsData[index * bytesPerStringSize];
112
- const stringData = data.subarray(stringOffset, stringByteSize + stringOffset);
113
- const stringAttribute = textDecoder.decode(stringData);
114
- stringsArray.push(stringAttribute);
115
- stringOffset += stringByteSize;
116
- }
117
- return stringsArray;
118
- }
@@ -1,62 +0,0 @@
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;
@@ -1,47 +0,0 @@
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
- // Any nodes that have the extension, add lights field pointing to light object
16
- // and remove the extension
17
- for (const material of json.materials || []) {
18
- const extension = material.extensions && material.extensions.KHR_materials_unlit;
19
- if (extension) {
20
- // @ts-ignore TODO
21
- material.unlit = true;
22
- }
23
- gltfScenegraph.removeObjectExtension(material, KHR_MATERIALS_UNLIT);
24
- }
25
- // Remove the top-level extension
26
- gltfScenegraph.removeExtension(KHR_MATERIALS_UNLIT);
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;
@@ -1,82 +0,0 @@
1
- "use strict";
2
- // GLTF EXTENSION: KHR_techniques_webgl
3
- // https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_techniques_webgl
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_TECHNIQUES_WEBGL = 'KHR_techniques_webgl';
11
- exports.name = KHR_TECHNIQUES_WEBGL;
12
- async function decode(gltfData) {
13
- const gltfScenegraph = new gltf_scenegraph_1.default(gltfData);
14
- const { json } = gltfScenegraph;
15
- const extension = gltfScenegraph.getExtension(KHR_TECHNIQUES_WEBGL);
16
- if (extension) {
17
- const techniques = resolveTechniques(extension, gltfScenegraph);
18
- for (const material of json.materials || []) {
19
- const materialExtension = gltfScenegraph.getObjectExtension(material, KHR_TECHNIQUES_WEBGL);
20
- if (materialExtension) {
21
- // @ts-ignore TODO
22
- material.technique = Object.assign({}, materialExtension,
23
- // @ts-ignore
24
- techniques[materialExtension.technique]);
25
- // @ts-ignore TODO
26
- material.technique.values = resolveValues(material.technique, gltfScenegraph);
27
- }
28
- gltfScenegraph.removeObjectExtension(material, KHR_TECHNIQUES_WEBGL);
29
- }
30
- // Remove the top-level extension
31
- gltfScenegraph.removeExtension(KHR_TECHNIQUES_WEBGL);
32
- }
33
- }
34
- exports.decode = decode;
35
- // eslint-disable-next-line
36
- async function encode(gltfData, options) {
37
- // TODO
38
- }
39
- exports.encode = encode;
40
- function resolveTechniques(techniquesExtension,
41
- // programs: {[key: string]: any}[],
42
- // shaders: {[key: string]: any}[],
43
- // techniques: {[key: string]: any}[]
44
- gltfScenegraph) {
45
- const { programs = [], shaders = [], techniques = [] } = techniquesExtension;
46
- const textDecoder = new TextDecoder();
47
- shaders.forEach((shader) => {
48
- if (Number.isFinite(shader.bufferView)) {
49
- shader.code = textDecoder.decode(gltfScenegraph.getTypedArrayForBufferView(shader.bufferView));
50
- }
51
- else {
52
- // TODO: handle URI shader
53
- throw new Error('KHR_techniques_webgl: no shader code');
54
- }
55
- });
56
- programs.forEach((program) => {
57
- program.fragmentShader = shaders[program.fragmentShader];
58
- program.vertexShader = shaders[program.vertexShader];
59
- });
60
- techniques.forEach((technique) => {
61
- technique.program = programs[technique.program];
62
- });
63
- return techniques;
64
- }
65
- function resolveValues(technique, gltfScenegraph) {
66
- const values = Object.assign({}, technique.values);
67
- // merge values from uniforms
68
- Object.keys(technique.uniforms || {}).forEach((uniform) => {
69
- if (technique.uniforms[uniform].value && !(uniform in values)) {
70
- values[uniform] = technique.uniforms[uniform].value;
71
- }
72
- });
73
- // resolve textures
74
- Object.keys(values).forEach((uniform) => {
75
- if (typeof values[uniform] === 'object' && values[uniform].index !== undefined) {
76
- // Assume this is a texture
77
- // TODO: find if there are any other types that can be referenced
78
- values[uniform].texture = gltfScenegraph.getTexture(values[uniform].index);
79
- }
80
- });
81
- return values;
82
- }
@@ -1,41 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTypedArrayForImageData = exports.getTypedArrayForBufferView = void 0;
4
- // TODO - GLTFScenegraph should use these
5
- const assert_1 = require("../utils/assert");
6
- // accepts buffer view index or buffer view object
7
- // returns a `Uint8Array`
8
- function getTypedArrayForBufferView(json, buffers, bufferViewIndex) {
9
- const bufferView = json.bufferViews[bufferViewIndex];
10
- (0, assert_1.assert)(bufferView);
11
- // Get hold of the arrayBuffer
12
- const bufferIndex = bufferView.buffer;
13
- const binChunk = buffers[bufferIndex];
14
- (0, assert_1.assert)(binChunk);
15
- const byteOffset = (bufferView.byteOffset || 0) + binChunk.byteOffset;
16
- return new Uint8Array(binChunk.arrayBuffer, byteOffset, bufferView.byteLength);
17
- }
18
- exports.getTypedArrayForBufferView = getTypedArrayForBufferView;
19
- // accepts accessor index or accessor object
20
- // returns a `Uint8Array`
21
- function getTypedArrayForImageData(json, buffers, imageIndex) {
22
- const image = json.images[imageIndex];
23
- const bufferViewIndex = json.bufferViews[image.bufferView];
24
- return getTypedArrayForBufferView(json, buffers, bufferViewIndex);
25
- }
26
- exports.getTypedArrayForImageData = getTypedArrayForImageData;
27
- /*
28
- // accepts accessor index or accessor object
29
- // returns a typed array with type that matches the types
30
- export function getTypedArrayForAccessor(accessor) {
31
- accessor = this.getAccessor(accessor);
32
- const bufferView = this.getBufferView(accessor.bufferView);
33
- const buffer = this.getBuffer(bufferView.buffer);
34
- const arrayBuffer = buffer.data;
35
-
36
- // Create a new typed array as a view into the combined buffer
37
- const {ArrayType, length} = getAccessorArrayTypeAndLength(accessor, bufferView);
38
- const byteOffset = bufferView.byteOffset + accessor.byteOffset;
39
- return new ArrayType(arrayBuffer, byteOffset, length);
40
- }
41
- */
@@ -1,73 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getGLTFAccessor = exports.getGLTFAccessors = void 0;
4
- // TODO - remove
5
- const gltf_utils_1 = require("./gltf-utils");
6
- // Returns a fresh attributes object with glTF-standardized attributes names
7
- // Attributes that cannot be identified will not be included
8
- // Removes `indices` if present, as it should be stored separately from the attributes
9
- function getGLTFAccessors(attributes) {
10
- const accessors = {};
11
- for (const name in attributes) {
12
- const attribute = attributes[name];
13
- if (name !== 'indices') {
14
- const glTFAccessor = getGLTFAccessor(attribute);
15
- accessors[name] = glTFAccessor;
16
- }
17
- }
18
- return accessors;
19
- }
20
- exports.getGLTFAccessors = getGLTFAccessors;
21
- // Fix up a single accessor.
22
- // Input: typed array or a partial accessor object
23
- // Return: accessor object
24
- function getGLTFAccessor(attribute) {
25
- const { buffer, size, count } = getAccessorData(attribute);
26
- const glTFAccessor = {
27
- // glTF Accessor values
28
- // TODO: Instead of a bufferView index we could have an actual buffer (typed array)
29
- // bufferView: null,
30
- // TODO: Deprecate `value` in favor of bufferView?
31
- // @ts-ignore
32
- value: buffer,
33
- size,
34
- byteOffset: 0,
35
- count,
36
- type: (0, gltf_utils_1.getAccessorTypeFromSize)(size),
37
- componentType: (0, gltf_utils_1.getComponentTypeFromArray)(buffer)
38
- };
39
- return glTFAccessor;
40
- }
41
- exports.getGLTFAccessor = getGLTFAccessor;
42
- // export function getGLTFAttribute(data, gltfAttributeName): GLTFAccessor {
43
- // return data.attributes[data.glTFAttributeMap[gltfAttributeName]];
44
- // }
45
- function getAccessorData(attribute) {
46
- let buffer = attribute;
47
- let size = 1;
48
- let count = 0;
49
- if (attribute && attribute.value) {
50
- buffer = attribute.value;
51
- size = attribute.size || 1;
52
- }
53
- if (buffer) {
54
- if (!ArrayBuffer.isView(buffer)) {
55
- buffer = toTypedArray(buffer, Float32Array);
56
- }
57
- count = buffer.length / size;
58
- }
59
- return { buffer, size, count };
60
- }
61
- // Convert non-typed arrays to arrays of specified format
62
- function toTypedArray(array, ArrayType, convertTypedArrays = false) {
63
- if (!array) {
64
- return null;
65
- }
66
- if (Array.isArray(array)) {
67
- return new ArrayType(array);
68
- }
69
- if (convertTypedArrays && !(array instanceof ArrayType)) {
70
- return new ArrayType(array);
71
- }
72
- return array;
73
- }
@@ -1,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getGLEnumFromSamplerParameter = exports.getSizeFromAccessorType = exports.getBytesFromComponentType = exports.BYTES = exports.COMPONENTS = void 0;
4
- exports.COMPONENTS = {
5
- SCALAR: 1,
6
- VEC2: 2,
7
- VEC3: 3,
8
- VEC4: 4,
9
- MAT2: 4,
10
- MAT3: 9,
11
- MAT4: 16
12
- };
13
- exports.BYTES = {
14
- 5120: 1,
15
- 5121: 1,
16
- 5122: 2,
17
- 5123: 2,
18
- 5125: 4,
19
- 5126: 4 // FLOAT
20
- };
21
- // ENUM LOOKUP
22
- function getBytesFromComponentType(componentType) {
23
- return exports.BYTES[componentType];
24
- }
25
- exports.getBytesFromComponentType = getBytesFromComponentType;
26
- function getSizeFromAccessorType(type) {
27
- return exports.COMPONENTS[type];
28
- }
29
- exports.getSizeFromAccessorType = getSizeFromAccessorType;
30
- function getGLEnumFromSamplerParameter(parameter) {
31
- const GL_TEXTURE_MAG_FILTER = 0x2800;
32
- const GL_TEXTURE_MIN_FILTER = 0x2801;
33
- const GL_TEXTURE_WRAP_S = 0x2802;
34
- const GL_TEXTURE_WRAP_T = 0x2803;
35
- const PARAMETER_MAP = {
36
- magFilter: GL_TEXTURE_MAG_FILTER,
37
- minFilter: GL_TEXTURE_MIN_FILTER,
38
- wrapS: GL_TEXTURE_WRAP_S,
39
- wrapT: GL_TEXTURE_WRAP_T
40
- };
41
- return PARAMETER_MAP[parameter];
42
- }
43
- exports.getGLEnumFromSamplerParameter = getGLEnumFromSamplerParameter;
@@ -1,85 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getMemoryUsageGLTF = exports.getAccessorArrayTypeAndLength = exports.getComponentTypeFromArray = exports.getAccessorTypeFromSize = void 0;
4
- const assert_1 = require("../utils/assert");
5
- const TYPES = ['SCALAR', 'VEC2', 'VEC3', 'VEC4'];
6
- const ARRAY_CONSTRUCTOR_TO_WEBGL_CONSTANT = [
7
- [Int8Array, 5120],
8
- [Uint8Array, 5121],
9
- [Int16Array, 5122],
10
- [Uint16Array, 5123],
11
- [Uint32Array, 5125],
12
- [Float32Array, 5126],
13
- [Float64Array, 5130]
14
- ];
15
- const ARRAY_TO_COMPONENT_TYPE = new Map(ARRAY_CONSTRUCTOR_TO_WEBGL_CONSTANT);
16
- const ATTRIBUTE_TYPE_TO_COMPONENTS = {
17
- SCALAR: 1,
18
- VEC2: 2,
19
- VEC3: 3,
20
- VEC4: 4,
21
- MAT2: 4,
22
- MAT3: 9,
23
- MAT4: 16
24
- };
25
- const ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE = {
26
- 5120: 1,
27
- 5121: 1,
28
- 5122: 2,
29
- 5123: 2,
30
- 5125: 4,
31
- 5126: 4
32
- };
33
- const ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY = {
34
- 5120: Int8Array,
35
- 5121: Uint8Array,
36
- 5122: Int16Array,
37
- 5123: Uint16Array,
38
- 5125: Uint32Array,
39
- 5126: Float32Array
40
- };
41
- function getAccessorTypeFromSize(size) {
42
- const type = TYPES[size - 1];
43
- return type || TYPES[0];
44
- }
45
- exports.getAccessorTypeFromSize = getAccessorTypeFromSize;
46
- function getComponentTypeFromArray(typedArray) {
47
- const componentType = ARRAY_TO_COMPONENT_TYPE.get(typedArray.constructor);
48
- if (!componentType) {
49
- throw new Error('Illegal typed array');
50
- }
51
- return componentType;
52
- }
53
- exports.getComponentTypeFromArray = getComponentTypeFromArray;
54
- function getAccessorArrayTypeAndLength(accessor, bufferView) {
55
- const ArrayType = ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY[accessor.componentType];
56
- const components = ATTRIBUTE_TYPE_TO_COMPONENTS[accessor.type];
57
- const bytesPerComponent = ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE[accessor.componentType];
58
- const length = accessor.count * components;
59
- const byteLength = accessor.count * components * bytesPerComponent;
60
- (0, assert_1.assert)(byteLength >= 0 && byteLength <= bufferView.byteLength);
61
- return { ArrayType, length, byteLength };
62
- }
63
- exports.getAccessorArrayTypeAndLength = getAccessorArrayTypeAndLength;
64
- /**
65
- * Calculate the GPU memory used by a GLTF tile, for both buffer and texture memory
66
- * @param gltf - the gltf content of a GLTF tile
67
- * @returns - total memory usage in bytes
68
- */
69
- function getMemoryUsageGLTF(gltf) {
70
- let { images, bufferViews } = gltf;
71
- images = images || [];
72
- bufferViews = bufferViews || [];
73
- const imageBufferViews = images.map((i) => i.bufferView);
74
- bufferViews = bufferViews.filter((view) => !imageBufferViews.includes(view));
75
- const bufferMemory = bufferViews.reduce((acc, view) => acc + view.byteLength, 0);
76
- // Assume each pixel of the texture is 4 channel with mimmaps (which add 33%)
77
- // TODO correctly handle compressed textures
78
- const pixelCount = images.reduce((acc, image) => {
79
- // @ts-ignore
80
- const { width, height } = image.image;
81
- return acc + width * height;
82
- }, 0);
83
- return bufferMemory + Math.ceil(4 * pixelCount * 1.33);
84
- }
85
- exports.getMemoryUsageGLTF = getMemoryUsageGLTF;
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolveUrl = void 0;
4
- // Resolves a relative url against a baseUrl
5
- // If url is absolute, return it unchanged
6
- function resolveUrl(url, options) {
7
- // TODO: Use better logic to handle all protocols plus not delay on data
8
- const absolute = url.startsWith('data:') || url.startsWith('http:') || url.startsWith('https:');
9
- if (absolute) {
10
- return url;
11
- }
12
- const baseUrl = options.baseUri || options.uri;
13
- if (!baseUrl) {
14
- throw new Error(`'baseUri' must be provided to resolve relative url ${url}`);
15
- }
16
- return baseUrl.substr(0, baseUrl.lastIndexOf('/') + 1) + url;
17
- }
18
- exports.resolveUrl = resolveUrl;