@loaders.gl/gltf 3.3.4 → 3.3.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/dist.min.js CHANGED
@@ -1316,6 +1316,19 @@
1316
1316
  assert3(byteLength >= 0 && byteLength <= bufferView.byteLength);
1317
1317
  return { ArrayType, length, byteLength };
1318
1318
  }
1319
+ function getMemoryUsageGLTF(gltf) {
1320
+ let { images, bufferViews } = gltf;
1321
+ images = images || [];
1322
+ bufferViews = bufferViews || [];
1323
+ const imageBufferViews = images.map((i2) => i2.bufferView);
1324
+ bufferViews = bufferViews.filter((view) => !imageBufferViews.includes(view));
1325
+ const bufferMemory = bufferViews.reduce((acc, view) => acc + view.byteLength, 0);
1326
+ const pixelCount = images.reduce((acc, image) => {
1327
+ const { width, height } = image.image;
1328
+ return acc + width * height;
1329
+ }, 0);
1330
+ return bufferMemory + Math.ceil(4 * pixelCount * 1.33);
1331
+ }
1319
1332
  var TYPES, ARRAY_CONSTRUCTOR_TO_WEBGL_CONSTANT, ARRAY_TO_COMPONENT_TYPE, ATTRIBUTE_TYPE_TO_COMPONENTS, ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE, ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY;
1320
1333
  var init_gltf_utils = __esm({
1321
1334
  "src/lib/gltf-utils/gltf-utils.ts"() {
@@ -5967,6 +5980,7 @@
5967
5980
  GLTFLoader: () => GLTFLoader,
5968
5981
  GLTFScenegraph: () => GLTFScenegraph,
5969
5982
  GLTFWriter: () => GLTFWriter,
5983
+ _getMemoryUsageGLTF: () => getMemoryUsageGLTF,
5970
5984
  postProcessGLTF: () => postProcessGLTF
5971
5985
  });
5972
5986
  var init_src7 = __esm({
@@ -5977,6 +5991,7 @@
5977
5991
  init_glb_writer();
5978
5992
  init_gltf_scenegraph();
5979
5993
  init_post_process_gltf();
5994
+ init_gltf_utils();
5980
5995
  }
5981
5996
  });
5982
5997
 
package/dist/es5/index.js CHANGED
@@ -34,6 +34,12 @@ Object.defineProperty(exports, "GLTFWriter", {
34
34
  return _gltfWriter.GLTFWriter;
35
35
  }
36
36
  });
37
+ Object.defineProperty(exports, "_getMemoryUsageGLTF", {
38
+ enumerable: true,
39
+ get: function get() {
40
+ return _gltfUtils.getMemoryUsageGLTF;
41
+ }
42
+ });
37
43
  Object.defineProperty(exports, "postProcessGLTF", {
38
44
  enumerable: true,
39
45
  get: function get() {
@@ -46,4 +52,5 @@ var _glbLoader = require("./glb-loader");
46
52
  var _glbWriter = require("./glb-writer");
47
53
  var _gltfScenegraph = _interopRequireDefault(require("./lib/api/gltf-scenegraph"));
48
54
  var _postProcessGltf = require("./lib/api/post-process-gltf");
55
+ var _gltfUtils = require("./lib/gltf-utils/gltf-utils");
49
56
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["/* eslint-disable camelcase, indent */\nexport type {GLB} from './lib/types/glb-types';\nexport type {\n GLTF,\n GLTFAccessor,\n GLTFBuffer,\n GLTFBufferView,\n GLTFMeshPrimitive,\n GLTFMesh,\n GLTFNode,\n GLTFMaterial,\n GLTFSampler,\n GLTFScene,\n GLTFSkin,\n GLTFTexture,\n GLTFImage,\n GLTFPostprocessed,\n GLTFAccessorPostprocessed,\n GLTFNodePostprocessed,\n GLTFMaterialPostprocessed,\n GLTFMeshPostprocessed,\n GLTFMeshPrimitivePostprocessed,\n GLTFImagePostprocessed,\n GLTFTexturePostprocessed,\n // The following extensions are handled by the GLTFLoader and removed from the parsed glTF (disable via options.gltf.excludeExtensions)\n GLTF_KHR_binary_glTF,\n GLTF_KHR_draco_mesh_compression,\n GLTF_KHR_texture_basisu,\n GLTF_EXT_meshopt_compression,\n GLTF_EXT_texture_webp,\n GLTF_EXT_feature_metadata\n} from './lib/types/gltf-types';\n\n// glTF loader/writer definition objects\nexport {GLTFLoader} from './gltf-loader';\nexport {GLTFWriter} from './gltf-writer';\n\n// GLB Loader & Writer (for custom formats that want to leverage the GLB binary \"envelope\")\nexport {GLBLoader} from './glb-loader';\nexport {GLBWriter} from './glb-writer';\n\n// glTF Data Access Helper Class\nexport {default as GLTFScenegraph} from './lib/api/gltf-scenegraph';\nexport {postProcessGLTF} from './lib/api/post-process-gltf';\nexport type {Mesh} from './lib/types/gltf-json-schema';\nexport type {GLTFObject} from './lib/types/gltf-types';\nexport type {Node, Accessor, Image} from './lib/types/gltf-postprocessed-schema';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA;AACA;AAGA;AACA;AAGA;AACA"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["/* eslint-disable camelcase, indent */\nexport type {GLB} from './lib/types/glb-types';\nexport type {\n GLTF,\n GLTFAccessor,\n GLTFBuffer,\n GLTFBufferView,\n GLTFMeshPrimitive,\n GLTFMesh,\n GLTFNode,\n GLTFMaterial,\n GLTFSampler,\n GLTFScene,\n GLTFSkin,\n GLTFTexture,\n GLTFImage,\n GLTFPostprocessed,\n GLTFAccessorPostprocessed,\n GLTFNodePostprocessed,\n GLTFMaterialPostprocessed,\n GLTFMeshPostprocessed,\n GLTFMeshPrimitivePostprocessed,\n GLTFImagePostprocessed,\n GLTFTexturePostprocessed,\n // The following extensions are handled by the GLTFLoader and removed from the parsed glTF (disable via options.gltf.excludeExtensions)\n GLTF_KHR_binary_glTF,\n GLTF_KHR_draco_mesh_compression,\n GLTF_KHR_texture_basisu,\n GLTF_EXT_meshopt_compression,\n GLTF_EXT_texture_webp,\n GLTF_EXT_feature_metadata\n} from './lib/types/gltf-types';\n\n// glTF loader/writer definition objects\nexport {GLTFLoader} from './gltf-loader';\nexport {GLTFWriter} from './gltf-writer';\n\n// GLB Loader & Writer (for custom formats that want to leverage the GLB binary \"envelope\")\nexport {GLBLoader} from './glb-loader';\nexport {GLBWriter} from './glb-writer';\n\n// glTF Data Access Helper Class\nexport {default as GLTFScenegraph} from './lib/api/gltf-scenegraph';\nexport {postProcessGLTF} from './lib/api/post-process-gltf';\nexport {getMemoryUsageGLTF as _getMemoryUsageGLTF} from './lib/gltf-utils/gltf-utils';\nexport type {Mesh} from './lib/types/gltf-json-schema';\nexport type {GLTFObject} from './lib/types/gltf-types';\nexport type {Node, Accessor, Image} from './lib/types/gltf-postprocessed-schema';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA;AACA;AAGA;AACA;AAGA;AACA;AACA"}
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.getAccessorArrayTypeAndLength = getAccessorArrayTypeAndLength;
7
7
  exports.getAccessorTypeFromSize = getAccessorTypeFromSize;
8
8
  exports.getComponentTypeFromArray = getComponentTypeFromArray;
9
+ exports.getMemoryUsageGLTF = getMemoryUsageGLTF;
9
10
  var _assert = require("../utils/assert");
10
11
  var TYPES = ['SCALAR', 'VEC2', 'VEC3', 'VEC4'];
11
12
  var ARRAY_CONSTRUCTOR_TO_WEBGL_CONSTANT = [[Int8Array, 5120], [Uint8Array, 5121], [Int16Array, 5122], [Uint16Array, 5123], [Uint32Array, 5125], [Float32Array, 5126], [Float64Array, 5130]];
@@ -59,4 +60,28 @@ function getAccessorArrayTypeAndLength(accessor, bufferView) {
59
60
  byteLength: byteLength
60
61
  };
61
62
  }
63
+
64
+ function getMemoryUsageGLTF(gltf) {
65
+ var images = gltf.images,
66
+ bufferViews = gltf.bufferViews;
67
+ images = images || [];
68
+ bufferViews = bufferViews || [];
69
+ var imageBufferViews = images.map(function (i) {
70
+ return i.bufferView;
71
+ });
72
+ bufferViews = bufferViews.filter(function (view) {
73
+ return !imageBufferViews.includes(view);
74
+ });
75
+ var bufferMemory = bufferViews.reduce(function (acc, view) {
76
+ return acc + view.byteLength;
77
+ }, 0);
78
+
79
+ var pixelCount = images.reduce(function (acc, image) {
80
+ var _image = image.image,
81
+ width = _image.width,
82
+ height = _image.height;
83
+ return acc + width * height;
84
+ }, 0);
85
+ return bufferMemory + Math.ceil(4 * pixelCount * 1.33);
86
+ }
62
87
  //# sourceMappingURL=gltf-utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"gltf-utils.js","names":["TYPES","ARRAY_CONSTRUCTOR_TO_WEBGL_CONSTANT","Int8Array","Uint8Array","Int16Array","Uint16Array","Uint32Array","Float32Array","Float64Array","ARRAY_TO_COMPONENT_TYPE","Map","ATTRIBUTE_TYPE_TO_COMPONENTS","SCALAR","VEC2","VEC3","VEC4","MAT2","MAT3","MAT4","ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE","ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY","getAccessorTypeFromSize","size","type","getComponentTypeFromArray","typedArray","componentType","get","constructor","Error","getAccessorArrayTypeAndLength","accessor","bufferView","ArrayType","components","bytesPerComponent","length","count","byteLength","assert"],"sources":["../../../../src/lib/gltf-utils/gltf-utils.ts"],"sourcesContent":["import {assert} from '../utils/assert';\n\nconst TYPES = ['SCALAR', 'VEC2', 'VEC3', 'VEC4'];\n\ntype TypedArrayConstructor =\n | Int8ArrayConstructor\n | Uint8ArrayConstructor\n | Int16ArrayConstructor\n | Uint16ArrayConstructor\n | Int32ArrayConstructor\n | Uint32ArrayConstructor\n | Int32ArrayConstructor\n | Uint32ArrayConstructor\n | Float32ArrayConstructor\n | Float64ArrayConstructor;\n\nconst ARRAY_CONSTRUCTOR_TO_WEBGL_CONSTANT: [TypedArrayConstructor, number][] = [\n [Int8Array, 5120],\n [Uint8Array, 5121],\n [Int16Array, 5122],\n [Uint16Array, 5123],\n [Uint32Array, 5125],\n [Float32Array, 5126],\n [Float64Array, 5130]\n];\nconst ARRAY_TO_COMPONENT_TYPE = new Map<TypedArrayConstructor, number>(\n ARRAY_CONSTRUCTOR_TO_WEBGL_CONSTANT\n);\n\nconst ATTRIBUTE_TYPE_TO_COMPONENTS = {\n SCALAR: 1,\n VEC2: 2,\n VEC3: 3,\n VEC4: 4,\n MAT2: 4,\n MAT3: 9,\n MAT4: 16\n};\n\nconst ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE = {\n 5120: 1,\n 5121: 1,\n 5122: 2,\n 5123: 2,\n 5125: 4,\n 5126: 4\n};\n\nconst ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY = {\n 5120: Int8Array,\n 5121: Uint8Array,\n 5122: Int16Array,\n 5123: Uint16Array,\n 5125: Uint32Array,\n 5126: Float32Array\n};\n\nexport function getAccessorTypeFromSize(size) {\n const type = TYPES[size - 1];\n return type || TYPES[0];\n}\n\nexport function getComponentTypeFromArray(typedArray) {\n const componentType = ARRAY_TO_COMPONENT_TYPE.get(typedArray.constructor);\n if (!componentType) {\n throw new Error('Illegal typed array');\n }\n return componentType;\n}\n\nexport function getAccessorArrayTypeAndLength(accessor, bufferView) {\n const ArrayType = ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY[accessor.componentType];\n const components = ATTRIBUTE_TYPE_TO_COMPONENTS[accessor.type];\n const bytesPerComponent = ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE[accessor.componentType];\n const length = accessor.count * components;\n const byteLength = accessor.count * components * bytesPerComponent;\n assert(byteLength >= 0 && byteLength <= bufferView.byteLength);\n return {ArrayType, length, byteLength};\n}\n"],"mappings":";;;;;;;;AAAA;AAEA,IAAMA,KAAK,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;AAchD,IAAMC,mCAAsE,GAAG,CAC7E,CAACC,SAAS,EAAE,IAAI,CAAC,EACjB,CAACC,UAAU,EAAE,IAAI,CAAC,EAClB,CAACC,UAAU,EAAE,IAAI,CAAC,EAClB,CAACC,WAAW,EAAE,IAAI,CAAC,EACnB,CAACC,WAAW,EAAE,IAAI,CAAC,EACnB,CAACC,YAAY,EAAE,IAAI,CAAC,EACpB,CAACC,YAAY,EAAE,IAAI,CAAC,CACrB;AACD,IAAMC,uBAAu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L,aAAa,CAAC;EACvF,IAAMU,MAAM,GAAGL,QAAQ,CAACM,KAAK,GAAGH,UAAU;EAC1C,IAAMI,UAAU,GAAGP,QAAQ,CAACM,KAAK,GAAGH,UAAU,GAAGC,iBAAiB;EAClE,IAAAI,cAAM,EAACD,UAAU,IAAI,CAAC,IAAIA,UAAU,IAAIN,UAAU,CAACM,UAAU,CAAC;EAC9D,OAAO;IAACL,SAAS,EAATA,SAAS;IAAEG,MAAM,EAANA,MAAM;IAAEE,UAAU,EAAVA;EAAU,CAAC;AACxC"}
1
+ {"version":3,"file":"gltf-utils.js","names":["TYPES","ARRAY_CONSTRUCTOR_TO_WEBGL_CONSTANT","Int8Array","Uint8Array","Int16Array","Uint16Array","Uint32Array","Float32Array","Float64Array","ARRAY_TO_COMPONENT_TYPE","Map","ATTRIBUTE_TYPE_TO_COMPONENTS","SCALAR","VEC2","VEC3","VEC4","MAT2","MAT3","MAT4","ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE","ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY","getAccessorTypeFromSize","size","type","getComponentTypeFromArray","typedArray","componentType","get","constructor","Error","getAccessorArrayTypeAndLength","accessor","bufferView","ArrayType","components","bytesPerComponent","length","count","byteLength","assert","getMemoryUsageGLTF","gltf","images","bufferViews","imageBufferViews","map","i","filter","view","includes","bufferMemory","reduce","acc","pixelCount","image","width","height","Math","ceil"],"sources":["../../../../src/lib/gltf-utils/gltf-utils.ts"],"sourcesContent":["import {assert} from '../utils/assert';\nimport {GLTF} from '../types/gltf-types';\n\nconst TYPES = ['SCALAR', 'VEC2', 'VEC3', 'VEC4'];\n\ntype TypedArrayConstructor =\n | Int8ArrayConstructor\n | Uint8ArrayConstructor\n | Int16ArrayConstructor\n | Uint16ArrayConstructor\n | Int32ArrayConstructor\n | Uint32ArrayConstructor\n | Int32ArrayConstructor\n | Uint32ArrayConstructor\n | Float32ArrayConstructor\n | Float64ArrayConstructor;\n\nconst ARRAY_CONSTRUCTOR_TO_WEBGL_CONSTANT: [TypedArrayConstructor, number][] = [\n [Int8Array, 5120],\n [Uint8Array, 5121],\n [Int16Array, 5122],\n [Uint16Array, 5123],\n [Uint32Array, 5125],\n [Float32Array, 5126],\n [Float64Array, 5130]\n];\nconst ARRAY_TO_COMPONENT_TYPE = new Map<TypedArrayConstructor, number>(\n ARRAY_CONSTRUCTOR_TO_WEBGL_CONSTANT\n);\n\nconst ATTRIBUTE_TYPE_TO_COMPONENTS = {\n SCALAR: 1,\n VEC2: 2,\n VEC3: 3,\n VEC4: 4,\n MAT2: 4,\n MAT3: 9,\n MAT4: 16\n};\n\nconst ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE = {\n 5120: 1,\n 5121: 1,\n 5122: 2,\n 5123: 2,\n 5125: 4,\n 5126: 4\n};\n\nconst ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY = {\n 5120: Int8Array,\n 5121: Uint8Array,\n 5122: Int16Array,\n 5123: Uint16Array,\n 5125: Uint32Array,\n 5126: Float32Array\n};\n\nexport function getAccessorTypeFromSize(size) {\n const type = TYPES[size - 1];\n return type || TYPES[0];\n}\n\nexport function getComponentTypeFromArray(typedArray) {\n const componentType = ARRAY_TO_COMPONENT_TYPE.get(typedArray.constructor);\n if (!componentType) {\n throw new Error('Illegal typed array');\n }\n return componentType;\n}\n\nexport function getAccessorArrayTypeAndLength(accessor, bufferView) {\n const ArrayType = ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY[accessor.componentType];\n const components = ATTRIBUTE_TYPE_TO_COMPONENTS[accessor.type];\n const bytesPerComponent = ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE[accessor.componentType];\n const length = accessor.count * components;\n const byteLength = accessor.count * components * bytesPerComponent;\n assert(byteLength >= 0 && byteLength <= bufferView.byteLength);\n return {ArrayType, length, byteLength};\n}\n\n/**\n * Calculate the GPU memory used by a GLTF tile, for both buffer and texture memory\n * @param gltf - the gltf content of a GLTF tile\n * @returns - total memory usage in bytes\n */\nexport function getMemoryUsageGLTF(gltf: GLTF): number {\n let {images, bufferViews} = gltf;\n images = images || [];\n bufferViews = bufferViews || [];\n const imageBufferViews = images.map((i) => i.bufferView);\n bufferViews = bufferViews.filter((view) => !imageBufferViews.includes(view as any));\n\n const bufferMemory = bufferViews.reduce((acc, view) => acc + view.byteLength, 0);\n\n // Assume each pixel of the texture is 4 channel with mimmaps (which add 33%)\n // TODO correctly handle compressed textures\n const pixelCount = images.reduce((acc, image) => {\n // @ts-ignore\n const {width, height} = (image as any).image;\n return acc + width * height;\n }, 0);\n return bufferMemory + Math.ceil(4 * pixelCount * 1.33);\n}\n"],"mappings":";;;;;;;;;AAAA;AAGA,IAAMA,KAAK,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;AAchD,IAAMC,mCAAsE,GAAG,CAC7E,CAACC,SAAS,EAAE,IAAI,CAAC,EACjB,CAACC,UAAU,EAAE,IAAI,CAAC,EAClB,CAACC,UAAU,EAAE,IAAI,CAAC,EAClB,CAACC,WAAW,EAAE,IAAI,CAAC,EACnB,CAACC,WAAW,EAAE,IAAI,CAAC,EACnB,CAACC,YAAY,EAAE,IAAI,CAAC,EACpB,CAACC,YAAY,EAAE,IAAI,CAAC,CACrB;AACD,IAAMC,uBAAuB,GAAG,IAAIC,GAAG,CACrCT,mCAAmC,CACpC;AAED,IAAMU,4BAA4B,GAAG;EACnCC,MAAM,EAAE,CAAC;EACTC,IAAI,EAAE,CAAC;EACPC,IAAI,EAAE,CAAC;EACPC,IAAI,EAAE,CAAC;EACPC,IAAI,EAAE,CAAC;EACPC,IAAI,EAAE,CAAC;EACPC,IAAI,EAAE;AACR,CAAC;AAED,IAAMC,qCAAqC,GAAG;EAC5C,IAAI,EAAE,CAAC;EACP,IAAI,EAAE,CAAC;EACP,IAAI,EAAE,CAAC;EACP,IAAI,EAAE,CAAC;EACP,IAAI,EAAE,CAAC;EACP,IAAI,EAAE;AACR,CAAC;AAED,IAAM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;IAAEC,WAAW,GAAIF,IAAI,CAAnBE,WAAW;EACxBD,MAAM,GAAGA,MAAM,IAAI,EAAE;EACrBC,WAAW,GAAGA,WAAW,IAAI,EAAE;EAC/B,IAAMC,gBAAgB,GAAGF,MAAM,CAACG,GAAG,CAAC,UAACC,CAAC;IAAA,OAAKA,CAAC,CAACd,UAAU;EAAA,EAAC;EACxDW,WAAW,GAAGA,WAAW,CAACI,MAAM,CAAC,UAACC,IAAI;IAAA,OAAK,CAACJ,gBAAgB,CAACK,QAAQ,CAACD,IAAI,CAAQ;EAAA,EAAC;EAEnF,IAAME,YAAY,GAAGP,WAAW,CAACQ,MAAM,CAAC,UAACC,GAAG,EAAEJ,IAAI;IAAA,OAAKI,GAAG,GAAGJ,IAAI,CAACV,UAAU;EAAA,GAAE,CAAC,CAAC;;EAIhF,IAAMe,UAAU,GAAGX,MAAM,CAACS,MAAM,CAAC,UAACC,GAAG,EAAEE,KAAK,EAAK;IAE/C,aAAyBA,KAAK,CAASA,KAAK;MAArCC,KAAK,UAALA,KAAK;MAAEC,MAAM,UAANA,MAAM;IACpB,OAAOJ,GAAG,GAAGG,KAAK,GAAGC,MAAM;EAC7B,CAAC,EAAE,CAAC,CAAC;EACL,OAAON,YAAY,GAAGO,IAAI,CAACC,IAAI,CAAC,CAAC,GAAGL,UAAU,GAAG,IAAI,CAAC;AACxD"}
@@ -4,6 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.VERSION = void 0;
7
- var VERSION = typeof "3.3.4" !== 'undefined' ? "3.3.4" : 'latest';
7
+ var VERSION = typeof "3.3.5" !== 'undefined' ? "3.3.5" : 'latest';
8
8
  exports.VERSION = VERSION;
9
9
  //# sourceMappingURL=version.js.map
package/dist/esm/index.js CHANGED
@@ -8,4 +8,5 @@ export { GLBWriter } from './glb-writer';
8
8
 
9
9
  export { default as GLTFScenegraph } from './lib/api/gltf-scenegraph';
10
10
  export { postProcessGLTF } from './lib/api/post-process-gltf';
11
+ export { getMemoryUsageGLTF as _getMemoryUsageGLTF } from './lib/gltf-utils/gltf-utils';
11
12
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["GLTFLoader","GLTFWriter","GLBLoader","GLBWriter","default","GLTFScenegraph","postProcessGLTF"],"sources":["../../src/index.ts"],"sourcesContent":["/* eslint-disable camelcase, indent */\nexport type {GLB} from './lib/types/glb-types';\nexport type {\n GLTF,\n GLTFAccessor,\n GLTFBuffer,\n GLTFBufferView,\n GLTFMeshPrimitive,\n GLTFMesh,\n GLTFNode,\n GLTFMaterial,\n GLTFSampler,\n GLTFScene,\n GLTFSkin,\n GLTFTexture,\n GLTFImage,\n GLTFPostprocessed,\n GLTFAccessorPostprocessed,\n GLTFNodePostprocessed,\n GLTFMaterialPostprocessed,\n GLTFMeshPostprocessed,\n GLTFMeshPrimitivePostprocessed,\n GLTFImagePostprocessed,\n GLTFTexturePostprocessed,\n // The following extensions are handled by the GLTFLoader and removed from the parsed glTF (disable via options.gltf.excludeExtensions)\n GLTF_KHR_binary_glTF,\n GLTF_KHR_draco_mesh_compression,\n GLTF_KHR_texture_basisu,\n GLTF_EXT_meshopt_compression,\n GLTF_EXT_texture_webp,\n GLTF_EXT_feature_metadata\n} from './lib/types/gltf-types';\n\n// glTF loader/writer definition objects\nexport {GLTFLoader} from './gltf-loader';\nexport {GLTFWriter} from './gltf-writer';\n\n// GLB Loader & Writer (for custom formats that want to leverage the GLB binary \"envelope\")\nexport {GLBLoader} from './glb-loader';\nexport {GLBWriter} from './glb-writer';\n\n// glTF Data Access Helper Class\nexport {default as GLTFScenegraph} from './lib/api/gltf-scenegraph';\nexport {postProcessGLTF} from './lib/api/post-process-gltf';\nexport type {Mesh} from './lib/types/gltf-json-schema';\nexport type {GLTFObject} from './lib/types/gltf-types';\nexport type {Node, Accessor, Image} from './lib/types/gltf-postprocessed-schema';\n"],"mappings":";;AAkCA,SAAQA,UAAU,QAAO,eAAe;AACxC,SAAQC,UAAU,QAAO,eAAe;;AAGxC,SAAQC,SAAS,QAAO,cAAc;AACtC,SAAQC,SAAS,QAAO,cAAc;;AAGtC,SAAQC,OAAO,IAAIC,cAAc,QAAO,2BAA2B;AACnE,SAAQC,eAAe,QAAO,6BAA6B"}
1
+ {"version":3,"file":"index.js","names":["GLTFLoader","GLTFWriter","GLBLoader","GLBWriter","default","GLTFScenegraph","postProcessGLTF","getMemoryUsageGLTF","_getMemoryUsageGLTF"],"sources":["../../src/index.ts"],"sourcesContent":["/* eslint-disable camelcase, indent */\nexport type {GLB} from './lib/types/glb-types';\nexport type {\n GLTF,\n GLTFAccessor,\n GLTFBuffer,\n GLTFBufferView,\n GLTFMeshPrimitive,\n GLTFMesh,\n GLTFNode,\n GLTFMaterial,\n GLTFSampler,\n GLTFScene,\n GLTFSkin,\n GLTFTexture,\n GLTFImage,\n GLTFPostprocessed,\n GLTFAccessorPostprocessed,\n GLTFNodePostprocessed,\n GLTFMaterialPostprocessed,\n GLTFMeshPostprocessed,\n GLTFMeshPrimitivePostprocessed,\n GLTFImagePostprocessed,\n GLTFTexturePostprocessed,\n // The following extensions are handled by the GLTFLoader and removed from the parsed glTF (disable via options.gltf.excludeExtensions)\n GLTF_KHR_binary_glTF,\n GLTF_KHR_draco_mesh_compression,\n GLTF_KHR_texture_basisu,\n GLTF_EXT_meshopt_compression,\n GLTF_EXT_texture_webp,\n GLTF_EXT_feature_metadata\n} from './lib/types/gltf-types';\n\n// glTF loader/writer definition objects\nexport {GLTFLoader} from './gltf-loader';\nexport {GLTFWriter} from './gltf-writer';\n\n// GLB Loader & Writer (for custom formats that want to leverage the GLB binary \"envelope\")\nexport {GLBLoader} from './glb-loader';\nexport {GLBWriter} from './glb-writer';\n\n// glTF Data Access Helper Class\nexport {default as GLTFScenegraph} from './lib/api/gltf-scenegraph';\nexport {postProcessGLTF} from './lib/api/post-process-gltf';\nexport {getMemoryUsageGLTF as _getMemoryUsageGLTF} from './lib/gltf-utils/gltf-utils';\nexport type {Mesh} from './lib/types/gltf-json-schema';\nexport type {GLTFObject} from './lib/types/gltf-types';\nexport type {Node, Accessor, Image} from './lib/types/gltf-postprocessed-schema';\n"],"mappings":";;AAkCA,SAAQA,UAAU,QAAO,eAAe;AACxC,SAAQC,UAAU,QAAO,eAAe;;AAGxC,SAAQC,SAAS,QAAO,cAAc;AACtC,SAAQC,SAAS,QAAO,cAAc;;AAGtC,SAAQC,OAAO,IAAIC,cAAc,QAAO,2BAA2B;AACnE,SAAQC,eAAe,QAAO,6BAA6B;AAC3D,SAAQC,kBAAkB,IAAIC,mBAAmB,QAAO,6BAA6B"}
@@ -51,4 +51,25 @@ export function getAccessorArrayTypeAndLength(accessor, bufferView) {
51
51
  byteLength
52
52
  };
53
53
  }
54
+
55
+ export function getMemoryUsageGLTF(gltf) {
56
+ let {
57
+ images,
58
+ bufferViews
59
+ } = gltf;
60
+ images = images || [];
61
+ bufferViews = bufferViews || [];
62
+ const imageBufferViews = images.map(i => i.bufferView);
63
+ bufferViews = bufferViews.filter(view => !imageBufferViews.includes(view));
64
+ const bufferMemory = bufferViews.reduce((acc, view) => acc + view.byteLength, 0);
65
+
66
+ const pixelCount = images.reduce((acc, image) => {
67
+ const {
68
+ width,
69
+ height
70
+ } = image.image;
71
+ return acc + width * height;
72
+ }, 0);
73
+ return bufferMemory + Math.ceil(4 * pixelCount * 1.33);
74
+ }
54
75
  //# sourceMappingURL=gltf-utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"gltf-utils.js","names":["assert","TYPES","ARRAY_CONSTRUCTOR_TO_WEBGL_CONSTANT","Int8Array","Uint8Array","Int16Array","Uint16Array","Uint32Array","Float32Array","Float64Array","ARRAY_TO_COMPONENT_TYPE","Map","ATTRIBUTE_TYPE_TO_COMPONENTS","SCALAR","VEC2","VEC3","VEC4","MAT2","MAT3","MAT4","ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE","ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY","getAccessorTypeFromSize","size","type","getComponentTypeFromArray","typedArray","componentType","get","constructor","Error","getAccessorArrayTypeAndLength","accessor","bufferView","ArrayType","components","bytesPerComponent","length","count","byteLength"],"sources":["../../../../src/lib/gltf-utils/gltf-utils.ts"],"sourcesContent":["import {assert} from '../utils/assert';\n\nconst TYPES = ['SCALAR', 'VEC2', 'VEC3', 'VEC4'];\n\ntype TypedArrayConstructor =\n | Int8ArrayConstructor\n | Uint8ArrayConstructor\n | Int16ArrayConstructor\n | Uint16ArrayConstructor\n | Int32ArrayConstructor\n | Uint32ArrayConstructor\n | Int32ArrayConstructor\n | Uint32ArrayConstructor\n | Float32ArrayConstructor\n | Float64ArrayConstructor;\n\nconst ARRAY_CONSTRUCTOR_TO_WEBGL_CONSTANT: [TypedArrayConstructor, number][] = [\n [Int8Array, 5120],\n [Uint8Array, 5121],\n [Int16Array, 5122],\n [Uint16Array, 5123],\n [Uint32Array, 5125],\n [Float32Array, 5126],\n [Float64Array, 5130]\n];\nconst ARRAY_TO_COMPONENT_TYPE = new Map<TypedArrayConstructor, number>(\n ARRAY_CONSTRUCTOR_TO_WEBGL_CONSTANT\n);\n\nconst ATTRIBUTE_TYPE_TO_COMPONENTS = {\n SCALAR: 1,\n VEC2: 2,\n VEC3: 3,\n VEC4: 4,\n MAT2: 4,\n MAT3: 9,\n MAT4: 16\n};\n\nconst ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE = {\n 5120: 1,\n 5121: 1,\n 5122: 2,\n 5123: 2,\n 5125: 4,\n 5126: 4\n};\n\nconst ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY = {\n 5120: Int8Array,\n 5121: Uint8Array,\n 5122: Int16Array,\n 5123: Uint16Array,\n 5125: Uint32Array,\n 5126: Float32Array\n};\n\nexport function getAccessorTypeFromSize(size) {\n const type = TYPES[size - 1];\n return type || TYPES[0];\n}\n\nexport function getComponentTypeFromArray(typedArray) {\n const componentType = ARRAY_TO_COMPONENT_TYPE.get(typedArray.constructor);\n if (!componentType) {\n throw new Error('Illegal typed array');\n }\n return componentType;\n}\n\nexport function getAccessorArrayTypeAndLength(accessor, bufferView) {\n const ArrayType = ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY[accessor.componentType];\n const components = ATTRIBUTE_TYPE_TO_COMPONENTS[accessor.type];\n const bytesPerComponent = ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE[accessor.componentType];\n const length = accessor.count * components;\n const byteLength = accessor.count * components * bytesPerComponent;\n assert(byteLength >= 0 && byteLength <= bufferView.byteLength);\n return {ArrayType, length, byteLength};\n}\n"],"mappings":"AAAA,SAAQA,MAAM,QAAO,iBAAiB;AAEtC,MAAMC,KAAK,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;AAchD,MAAMC,mCAAsE,GAAG,CAC7E,CAACC,SAAS,EAAE,IAAI,CAAC,EACjB,CAACC,UAAU,EAAE,IAAI,CAAC,EAClB,CAACC,UAAU,EAAE,IAAI,CAAC,EAClB,CAACC,WAAW,EAAE,IAAI,CAAC,EACnB,CAACC,WAAW,EAAE,IAAI,CAAC,EACnB,CAACC,YAAY,EAAE,IAAI,CAAC,EACpB,CAACC,YAAY,EAAE,IAAI,CAAC,CACrB;AACD,MAAMC,uBAAuB,GAAG,IAAIC,GAAG,CACrCT,mCAAmC,CACpC;AAED,MAAMU,4BAA4B,GAAG;EACnCC,MAAM,EAAE,CAAC;EACTC,IAAI,EAAE,CAAC;EACPC,IAAI,EAAE,CAAC;EACPC,IAAI,EAAE,CAAC;EACPC,IAAI,EAAE,CAAC;EACPC,IAAI,EAAE,CAAC;EACPC,IAAI,EAAE;AACR,CAAC;AAED,MAAMC,qCAAqC,GAAG;EAC5C,IAAI,EAAE,CAAC;EACP,IAAI,EAAE,CAAC;EACP,IAAI,EAAE,CAAC;EACP,IAAI,EAAE,CAAC;EACP,IAAI,EAAE,CAAC;EACP,IAAI,EAAE;AACR,CAAC;AAED,MAAMC,iCAAiC,GAAG;EACxC,IAAI,EAAElB,SAAS;EACf,IAAI,EAAEC,UAAU;EAChB,IAAI,EAAEC,UAAU;EAChB,IAAI,EAAEC,WAAW;EACjB,IAAI,EAAEC,WAAW;EACjB,IAAI,EAAEC;AACR,CAAC;AAED,OAAO,SAASc,uBAAuB,CAACC,IAAI,EAAE;EAC5C,MAAMC,IAAI,GAAGvB,KAAK,CAACsB,IAAI,GAAG,CAAC,CAAC;EAC5B,OAAOC,IAAI,IAAIvB,KAAK,CAAC,CAAC,CAAC;AACzB;AAEA,OAAO,SAASwB,yBAAyB,CAACC,UAAU,EAAE;EACpD,MAAMC,aAAa,GAAGjB,uBAAuB,CAACkB,GAAG,CAACF,UAAU,CAACG,WAAW,CAAC;EACzE,IAAI,CAACF,aAAa,EAAE;IAClB,MAAM,IAAIG,KAAK,CAAC,qBAAqB,CAAC;EACxC;EACA,OAAOH,aAAa;AACtB;AAEA,OAAO,SAASI,6BAA6B,CAACC,QAAQ,EAAEC,UAAU,EAAE;EAClE,MAAMC,SAAS,GAAGb,iCAAiC,CAACW,QAAQ,CAACL,aAAa,CAAC;EAC3E,MAAMQ,UAAU,GAAGvB,4BAA4B,CAACoB,QAAQ,CAACR,IAAI,CAAC;EAC9D,MAAMY,iBAAiB,GAAGhB,qCAAqC,CAACY,QAAQ,CAACL,aAAa,CAAC;EACvF,MAAMU,MAAM,GAAGL,QAAQ,CAACM,KAAK,GAAGH,UAAU;EAC1C,MAAMI,UAAU,GAAGP,QAAQ,CAACM,KAAK,GAAGH,UAAU,GAAGC,iBAAiB;EAClEpC,MAAM,CAACuC,UAAU,IAAI,CAAC,IAAIA,UAAU,IAAIN,UAAU,CAACM,UAAU,CAAC;EAC9D,OAAO;IAACL,SAAS;IAAEG,MAAM;IAAEE;EAAU,CAAC;AACxC"}
1
+ {"version":3,"file":"gltf-utils.js","names":["assert","TYPES","ARRAY_CONSTRUCTOR_TO_WEBGL_CONSTANT","Int8Array","Uint8Array","Int16Array","Uint16Array","Uint32Array","Float32Array","Float64Array","ARRAY_TO_COMPONENT_TYPE","Map","ATTRIBUTE_TYPE_TO_COMPONENTS","SCALAR","VEC2","VEC3","VEC4","MAT2","MAT3","MAT4","ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE","ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY","getAccessorTypeFromSize","size","type","getComponentTypeFromArray","typedArray","componentType","get","constructor","Error","getAccessorArrayTypeAndLength","accessor","bufferView","ArrayType","components","bytesPerComponent","length","count","byteLength","getMemoryUsageGLTF","gltf","images","bufferViews","imageBufferViews","map","i","filter","view","includes","bufferMemory","reduce","acc","pixelCount","image","width","height","Math","ceil"],"sources":["../../../../src/lib/gltf-utils/gltf-utils.ts"],"sourcesContent":["import {assert} from '../utils/assert';\nimport {GLTF} from '../types/gltf-types';\n\nconst TYPES = ['SCALAR', 'VEC2', 'VEC3', 'VEC4'];\n\ntype TypedArrayConstructor =\n | Int8ArrayConstructor\n | Uint8ArrayConstructor\n | Int16ArrayConstructor\n | Uint16ArrayConstructor\n | Int32ArrayConstructor\n | Uint32ArrayConstructor\n | Int32ArrayConstructor\n | Uint32ArrayConstructor\n | Float32ArrayConstructor\n | Float64ArrayConstructor;\n\nconst ARRAY_CONSTRUCTOR_TO_WEBGL_CONSTANT: [TypedArrayConstructor, number][] = [\n [Int8Array, 5120],\n [Uint8Array, 5121],\n [Int16Array, 5122],\n [Uint16Array, 5123],\n [Uint32Array, 5125],\n [Float32Array, 5126],\n [Float64Array, 5130]\n];\nconst ARRAY_TO_COMPONENT_TYPE = new Map<TypedArrayConstructor, number>(\n ARRAY_CONSTRUCTOR_TO_WEBGL_CONSTANT\n);\n\nconst ATTRIBUTE_TYPE_TO_COMPONENTS = {\n SCALAR: 1,\n VEC2: 2,\n VEC3: 3,\n VEC4: 4,\n MAT2: 4,\n MAT3: 9,\n MAT4: 16\n};\n\nconst ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE = {\n 5120: 1,\n 5121: 1,\n 5122: 2,\n 5123: 2,\n 5125: 4,\n 5126: 4\n};\n\nconst ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY = {\n 5120: Int8Array,\n 5121: Uint8Array,\n 5122: Int16Array,\n 5123: Uint16Array,\n 5125: Uint32Array,\n 5126: Float32Array\n};\n\nexport function getAccessorTypeFromSize(size) {\n const type = TYPES[size - 1];\n return type || TYPES[0];\n}\n\nexport function getComponentTypeFromArray(typedArray) {\n const componentType = ARRAY_TO_COMPONENT_TYPE.get(typedArray.constructor);\n if (!componentType) {\n throw new Error('Illegal typed array');\n }\n return componentType;\n}\n\nexport function getAccessorArrayTypeAndLength(accessor, bufferView) {\n const ArrayType = ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY[accessor.componentType];\n const components = ATTRIBUTE_TYPE_TO_COMPONENTS[accessor.type];\n const bytesPerComponent = ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE[accessor.componentType];\n const length = accessor.count * components;\n const byteLength = accessor.count * components * bytesPerComponent;\n assert(byteLength >= 0 && byteLength <= bufferView.byteLength);\n return {ArrayType, length, byteLength};\n}\n\n/**\n * Calculate the GPU memory used by a GLTF tile, for both buffer and texture memory\n * @param gltf - the gltf content of a GLTF tile\n * @returns - total memory usage in bytes\n */\nexport function getMemoryUsageGLTF(gltf: GLTF): number {\n let {images, bufferViews} = gltf;\n images = images || [];\n bufferViews = bufferViews || [];\n const imageBufferViews = images.map((i) => i.bufferView);\n bufferViews = bufferViews.filter((view) => !imageBufferViews.includes(view as any));\n\n const bufferMemory = bufferViews.reduce((acc, view) => acc + view.byteLength, 0);\n\n // Assume each pixel of the texture is 4 channel with mimmaps (which add 33%)\n // TODO correctly handle compressed textures\n const pixelCount = images.reduce((acc, image) => {\n // @ts-ignore\n const {width, height} = (image as any).image;\n return acc + width * height;\n }, 0);\n return bufferMemory + Math.ceil(4 * pixelCount * 1.33);\n}\n"],"mappings":"AAAA,SAAQA,MAAM,QAAO,iBAAiB;AAGtC,MAAMC,KAAK,GAAG,CAAC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AAM,CAAC,CAACC,GAAG,EAAEE,KAAK,KAAK;IAE/C,MAAM;MAACC,KAAK;MAAEC;IAAM,CAAC,GAAIF,KAAK,CAASA,KAAK;IAC5C,OAAOF,GAAG,GAAGG,KAAK,GAAGC,MAAM;EAC7B,CAAC,EAAE,CAAC,CAAC;EACL,OAAON,YAAY,GAAGO,IAAI,CAACC,IAAI,CAAC,CAAC,GAAGL,UAAU,GAAG,IAAI,CAAC;AACxD"}
@@ -1,3 +1,3 @@
1
1
 
2
- export const VERSION = typeof "3.3.4" !== 'undefined' ? "3.3.4" : 'latest';
2
+ export const VERSION = typeof "3.3.5" !== 'undefined' ? "3.3.5" : 'latest';
3
3
  //# sourceMappingURL=version.js.map
package/dist/index.d.ts CHANGED
@@ -6,6 +6,7 @@ export { GLBLoader } from './glb-loader';
6
6
  export { GLBWriter } from './glb-writer';
7
7
  export { default as GLTFScenegraph } from './lib/api/gltf-scenegraph';
8
8
  export { postProcessGLTF } from './lib/api/post-process-gltf';
9
+ export { getMemoryUsageGLTF as _getMemoryUsageGLTF } from './lib/gltf-utils/gltf-utils';
9
10
  export type { Mesh } from './lib/types/gltf-json-schema';
10
11
  export type { GLTFObject } from './lib/types/gltf-types';
11
12
  export type { Node, Accessor, Image } from './lib/types/gltf-postprocessed-schema';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,YAAY,EAAC,GAAG,EAAC,MAAM,uBAAuB,CAAC;AAC/C,YAAY,EACV,IAAI,EACJ,YAAY,EACZ,UAAU,EACV,cAAc,EACd,iBAAiB,EACjB,QAAQ,EACR,QAAQ,EACR,YAAY,EACZ,WAAW,EACX,SAAS,EACT,QAAQ,EACR,WAAW,EACX,SAAS,EACT,iBAAiB,EACjB,yBAAyB,EACzB,qBAAqB,EACrB,yBAAyB,EACzB,qBAAqB,EACrB,8BAA8B,EAC9B,sBAAsB,EACtB,wBAAwB,EAExB,oBAAoB,EACpB,+BAA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,CAAC;AACvC,OAAO,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AAGvC,OAAO,EAAC,OAAO,IAAI,cAAc,EAAC,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAC,eAAe,EAAC,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAC,kBAAkB,IAAI,mBAAmB,EAAC,MAAM,6BAA6B,CAAC;AACtF,YAAY,EAAC,IAAI,EAAC,MAAM,8BAA8B,CAAC;AACvD,YAAY,EAAC,UAAU,EAAC,MAAM,wBAAwB,CAAC;AACvD,YAAY,EAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAC,MAAM,uCAAuC,CAAC"}
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.postProcessGLTF = exports.GLTFScenegraph = exports.GLBWriter = exports.GLBLoader = exports.GLTFWriter = exports.GLTFLoader = void 0;
6
+ exports._getMemoryUsageGLTF = exports.postProcessGLTF = exports.GLTFScenegraph = exports.GLBWriter = exports.GLBLoader = exports.GLTFWriter = exports.GLTFLoader = void 0;
7
7
  // glTF loader/writer definition objects
8
8
  var gltf_loader_1 = require("./gltf-loader");
9
9
  Object.defineProperty(exports, "GLTFLoader", { enumerable: true, get: function () { return gltf_loader_1.GLTFLoader; } });
@@ -19,3 +19,5 @@ var gltf_scenegraph_1 = require("./lib/api/gltf-scenegraph");
19
19
  Object.defineProperty(exports, "GLTFScenegraph", { enumerable: true, get: function () { return __importDefault(gltf_scenegraph_1).default; } });
20
20
  var post_process_gltf_1 = require("./lib/api/post-process-gltf");
21
21
  Object.defineProperty(exports, "postProcessGLTF", { enumerable: true, get: function () { return post_process_gltf_1.postProcessGLTF; } });
22
+ var gltf_utils_1 = require("./lib/gltf-utils/gltf-utils");
23
+ Object.defineProperty(exports, "_getMemoryUsageGLTF", { enumerable: true, get: function () { return gltf_utils_1.getMemoryUsageGLTF; } });
@@ -1,3 +1,4 @@
1
+ import { GLTF } from '../types/gltf-types';
1
2
  export declare function getAccessorTypeFromSize(size: any): string;
2
3
  export declare function getComponentTypeFromArray(typedArray: any): number;
3
4
  export declare function getAccessorArrayTypeAndLength(accessor: any, bufferView: any): {
@@ -5,4 +6,10 @@ export declare function getAccessorArrayTypeAndLength(accessor: any, bufferView:
5
6
  length: number;
6
7
  byteLength: number;
7
8
  };
9
+ /**
10
+ * Calculate the GPU memory used by a GLTF tile, for both buffer and texture memory
11
+ * @param gltf - the gltf content of a GLTF tile
12
+ * @returns - total memory usage in bytes
13
+ */
14
+ export declare function getMemoryUsageGLTF(gltf: GLTF): number;
8
15
  //# sourceMappingURL=gltf-utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"gltf-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/gltf-utils/gltf-utils.ts"],"names":[],"mappings":"AAyDA,wBAAgB,uBAAuB,CAAC,IAAI,KAAA,UAG3C;AAED,wBAAgB,yBAAyB,CAAC,UAAU,KAAA,UAMnD;AAED,wBAAgB,6BAA6B,CAAC,QAAQ,KAAA,EAAE,UAAU,KAAA;;;;EAQjE"}
1
+ {"version":3,"file":"gltf-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/gltf-utils/gltf-utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,IAAI,EAAC,MAAM,qBAAqB,CAAC;AAyDzC,wBAAgB,uBAAuB,CAAC,IAAI,KAAA,UAG3C;AAED,wBAAgB,yBAAyB,CAAC,UAAU,KAAA,UAMnD;AAED,wBAAgB,6BAA6B,CAAC,QAAQ,KAAA,EAAE,UAAU,KAAA;;;;EAQjE;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAiBrD"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAccessorArrayTypeAndLength = exports.getComponentTypeFromArray = exports.getAccessorTypeFromSize = void 0;
3
+ exports.getMemoryUsageGLTF = exports.getAccessorArrayTypeAndLength = exports.getComponentTypeFromArray = exports.getAccessorTypeFromSize = void 0;
4
4
  const assert_1 = require("../utils/assert");
5
5
  const TYPES = ['SCALAR', 'VEC2', 'VEC3', 'VEC4'];
6
6
  const ARRAY_CONSTRUCTOR_TO_WEBGL_CONSTANT = [
@@ -61,3 +61,25 @@ function getAccessorArrayTypeAndLength(accessor, bufferView) {
61
61
  return { ArrayType, length, byteLength };
62
62
  }
63
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/gltf",
3
- "version": "3.3.4",
3
+ "version": "3.3.5",
4
4
  "description": "Framework-independent loader for the glTF format",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -34,11 +34,11 @@
34
34
  "build-bundle": "esbuild src/bundle.ts --bundle --outfile=dist/dist.min.js"
35
35
  },
36
36
  "dependencies": {
37
- "@loaders.gl/draco": "3.3.4",
38
- "@loaders.gl/images": "3.3.4",
39
- "@loaders.gl/loader-utils": "3.3.4",
40
- "@loaders.gl/textures": "3.3.4",
37
+ "@loaders.gl/draco": "3.3.5",
38
+ "@loaders.gl/images": "3.3.5",
39
+ "@loaders.gl/loader-utils": "3.3.5",
40
+ "@loaders.gl/textures": "3.3.5",
41
41
  "@math.gl/core": "^3.5.1"
42
42
  },
43
- "gitHead": "1d1a722ea9a04665acbe41359dfd01bf6d43a214"
43
+ "gitHead": "8aaa7fea4b7d72536d9d1f7d79688ec6702b2904"
44
44
  }
package/src/index.ts CHANGED
@@ -42,6 +42,7 @@ export {GLBWriter} from './glb-writer';
42
42
  // glTF Data Access Helper Class
43
43
  export {default as GLTFScenegraph} from './lib/api/gltf-scenegraph';
44
44
  export {postProcessGLTF} from './lib/api/post-process-gltf';
45
+ export {getMemoryUsageGLTF as _getMemoryUsageGLTF} from './lib/gltf-utils/gltf-utils';
45
46
  export type {Mesh} from './lib/types/gltf-json-schema';
46
47
  export type {GLTFObject} from './lib/types/gltf-types';
47
48
  export type {Node, Accessor, Image} from './lib/types/gltf-postprocessed-schema';
@@ -1,4 +1,5 @@
1
1
  import {assert} from '../utils/assert';
2
+ import {GLTF} from '../types/gltf-types';
2
3
 
3
4
  const TYPES = ['SCALAR', 'VEC2', 'VEC3', 'VEC4'];
4
5
 
@@ -77,3 +78,27 @@ export function getAccessorArrayTypeAndLength(accessor, bufferView) {
77
78
  assert(byteLength >= 0 && byteLength <= bufferView.byteLength);
78
79
  return {ArrayType, length, byteLength};
79
80
  }
81
+
82
+ /**
83
+ * Calculate the GPU memory used by a GLTF tile, for both buffer and texture memory
84
+ * @param gltf - the gltf content of a GLTF tile
85
+ * @returns - total memory usage in bytes
86
+ */
87
+ export function getMemoryUsageGLTF(gltf: GLTF): number {
88
+ let {images, bufferViews} = gltf;
89
+ images = images || [];
90
+ bufferViews = bufferViews || [];
91
+ const imageBufferViews = images.map((i) => i.bufferView);
92
+ bufferViews = bufferViews.filter((view) => !imageBufferViews.includes(view as any));
93
+
94
+ const bufferMemory = bufferViews.reduce((acc, view) => acc + view.byteLength, 0);
95
+
96
+ // Assume each pixel of the texture is 4 channel with mimmaps (which add 33%)
97
+ // TODO correctly handle compressed textures
98
+ const pixelCount = images.reduce((acc, image) => {
99
+ // @ts-ignore
100
+ const {width, height} = (image as any).image;
101
+ return acc + width * height;
102
+ }, 0);
103
+ return bufferMemory + Math.ceil(4 * pixelCount * 1.33);
104
+ }