@loaders.gl/gltf 3.4.0-alpha.4 → 3.4.0-alpha.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
@@ -1368,6 +1368,19 @@
1368
1368
  assert3(byteLength >= 0 && byteLength <= bufferView.byteLength);
1369
1369
  return { ArrayType, length, byteLength };
1370
1370
  }
1371
+ function getMemoryUsageGLTF(gltf) {
1372
+ let { images, bufferViews } = gltf;
1373
+ images = images || [];
1374
+ bufferViews = bufferViews || [];
1375
+ const imageBufferViews = images.map((i2) => i2.bufferView);
1376
+ bufferViews = bufferViews.filter((view) => !imageBufferViews.includes(view));
1377
+ const bufferMemory = bufferViews.reduce((acc, view) => acc + view.byteLength, 0);
1378
+ const pixelCount = images.reduce((acc, image) => {
1379
+ const { width, height } = image.image;
1380
+ return acc + width * height;
1381
+ }, 0);
1382
+ return bufferMemory + Math.ceil(4 * pixelCount * 1.33);
1383
+ }
1371
1384
  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;
1372
1385
  var init_gltf_utils = __esm({
1373
1386
  "src/lib/gltf-utils/gltf-utils.ts"() {
@@ -6019,6 +6032,7 @@
6019
6032
  GLTFLoader: () => GLTFLoader,
6020
6033
  GLTFScenegraph: () => GLTFScenegraph,
6021
6034
  GLTFWriter: () => GLTFWriter,
6035
+ _getMemoryUsageGLTF: () => getMemoryUsageGLTF,
6022
6036
  postProcessGLTF: () => postProcessGLTF
6023
6037
  });
6024
6038
  var init_src7 = __esm({
@@ -6029,6 +6043,7 @@
6029
6043
  init_glb_writer();
6030
6044
  init_gltf_scenegraph();
6031
6045
  init_post_process_gltf();
6046
+ init_gltf_utils();
6032
6047
  }
6033
6048
  });
6034
6049
 
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":["_gltfLoader","require","_gltfWriter","_glbLoader","_glbWriter","_gltfScenegraph","_interopRequireDefault","_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,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AAGA,IAAAE,UAAA,GAAAF,OAAA;AACA,IAAAG,UAAA,GAAAH,OAAA;AAGA,IAAAI,eAAA,GAAAC,sBAAA,CAAAL,OAAA;AACA,IAAAM,gBAAA,GAAAN,OAAA"}
1
+ {"version":3,"file":"index.js","names":["_gltfLoader","require","_gltfWriter","_glbLoader","_glbWriter","_gltfScenegraph","_interopRequireDefault","_postProcessGltf","_gltfUtils"],"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,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AAGA,IAAAE,UAAA,GAAAF,OAAA;AACA,IAAAG,UAAA,GAAAH,OAAA;AAGA,IAAAI,eAAA,GAAAC,sBAAA,CAAAL,OAAA;AACA,IAAAM,gBAAA,GAAAN,OAAA;AACA,IAAAO,UAAA,GAAAP,OAAA"}
@@ -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,26 @@ function getAccessorArrayTypeAndLength(accessor, bufferView) {
59
60
  byteLength: byteLength
60
61
  };
61
62
  }
63
+ function getMemoryUsageGLTF(gltf) {
64
+ var images = gltf.images,
65
+ bufferViews = gltf.bufferViews;
66
+ images = images || [];
67
+ bufferViews = bufferViews || [];
68
+ var imageBufferViews = images.map(function (i) {
69
+ return i.bufferView;
70
+ });
71
+ bufferViews = bufferViews.filter(function (view) {
72
+ return !imageBufferViews.includes(view);
73
+ });
74
+ var bufferMemory = bufferViews.reduce(function (acc, view) {
75
+ return acc + view.byteLength;
76
+ }, 0);
77
+ var pixelCount = images.reduce(function (acc, image) {
78
+ var _image = image.image,
79
+ width = _image.width,
80
+ height = _image.height;
81
+ return acc + width * height;
82
+ }, 0);
83
+ return bufferMemory + Math.ceil(4 * pixelCount * 1.33);
84
+ }
62
85
  //# sourceMappingURL=gltf-utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"gltf-utils.js","names":["_assert","require","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,IAAAA,OAAA,GAAAC,OAAA;AAEA,IAAMC,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,mCACF,CAAC;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,IAAMC,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;AAEM,SAASc,uBAAuBA,CAACC,IAAI,EAAE;EAC5C,IAAMC,IAAI,GAAGvB,KAAK,CAACsB,IAAI,GAAG,CAAC,CAAC;EAC5B,OAAOC,IAAI,IAAIvB,KAAK,CAAC,CAAC,CAAC;AACzB;AAEO,SAASwB,yBAAyBA,CAACC,UAAU,EAAE;EACpD,IAAMC,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;AAEO,SAASI,6BAA6BA,CAACC,QAAQ,EAAEC,UAAU,EAAE;EAClE,IAAMC,SAAS,GAAGb,iCAAiC,CAACW,QAAQ,CAACL,aAAa,CAAC;EAC3E,IAAMQ,UAAU,GAAGvB,4BAA4B,CAACoB,QAAQ,CAACR,IAAI,CAAC;EAC9D,IAAMY,iBAAiB,GAAGhB,qCAAqC,CAACY,QAAQ,CAACL,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":["_assert","require","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","_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,IAAAA,OAAA,GAAAC,OAAA;AAGA,IAAMC,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,EA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CAASA,KAAK;MAArCE,KAAK,GAAAD,MAAA,CAALC,KAAK;MAAEC,MAAM,GAAAF,MAAA,CAANE,MAAM;IACpB,OAAOL,GAAG,GAAGI,KAAK,GAAGC,MAAM;EAC7B,CAAC,EAAE,CAAC,CAAC;EACL,OAAOP,YAAY,GAAGQ,IAAI,CAACC,IAAI,CAAC,CAAC,GAAGN,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.4.0-alpha.4" !== 'undefined' ? "3.4.0-alpha.4" : 'latest';
7
+ var VERSION = typeof "3.4.0-alpha.5" !== 'undefined' ? "3.4.0-alpha.5" : 'latest';
8
8
  exports.VERSION = VERSION;
9
9
  //# sourceMappingURL=version.js.map
package/dist/esm/index.js CHANGED
@@ -4,4 +4,5 @@ export { GLBLoader } from './glb-loader';
4
4
  export { GLBWriter } from './glb-writer';
5
5
  export { default as GLTFScenegraph } from './lib/api/gltf-scenegraph';
6
6
  export { postProcessGLTF } from './lib/api/post-process-gltf';
7
+ export { getMemoryUsageGLTF as _getMemoryUsageGLTF } from './lib/gltf-utils/gltf-utils';
7
8
  //# 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,23 @@ export function getAccessorArrayTypeAndLength(accessor, bufferView) {
51
51
  byteLength
52
52
  };
53
53
  }
54
+ export function getMemoryUsageGLTF(gltf) {
55
+ let {
56
+ images,
57
+ bufferViews
58
+ } = gltf;
59
+ images = images || [];
60
+ bufferViews = bufferViews || [];
61
+ const imageBufferViews = images.map(i => i.bufferView);
62
+ bufferViews = bufferViews.filter(view => !imageBufferViews.includes(view));
63
+ const bufferMemory = bufferViews.reduce((acc, view) => acc + view.byteLength, 0);
64
+ const pixelCount = images.reduce((acc, image) => {
65
+ const {
66
+ width,
67
+ height
68
+ } = image.image;
69
+ return acc + width * height;
70
+ }, 0);
71
+ return bufferMemory + Math.ceil(4 * pixelCount * 1.33);
72
+ }
54
73
  //# 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,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AEA,OAAO,SAASI,6BAA6BA,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,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,mCACF,CAAC;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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,IAAI,CAAC,IAAIA,UAAU,IAAIN,UAAU,CAACM,UAAU,CAAC;EAC9D,OAAO;IAACL,SAAS;IAAEG,MAAM;IAAEE;EAAU,CAAC;AACxC;AAOA,OAAO,SAASC,kBAAkBA,CAACC,IAAU,EAAU;EACrD,IAAI;IAACC,MAAM;IAAEC;EAAW,CAAC,GAAGF,IAAI;EAChCC,MAAM,GAAGA,MAAM,IAAI,EAAE;EACrBC,WAAW,GAAGA,WAAW,IAAI,EAAE;EAC/B,MAAMC,gBAAgB,GAAGF,MAAM,CAACG,GAAG,CAAEC,CAAC,IAAKA,CAAC,CAACb,UAAU,CAAC;EACxDU,WAAW,GAAGA,WAAW,CAACI,MAAM,CAAEC,IAAI,IAAK,CAACJ,gBAAgB,CAACK,QAAQ,CAACD,IAAW,CAAC,CAAC;EAEnF,MAAME,YAAY,GAAGP,WAAW,CAACQ,MAAM,CAAC,CAACC,GAAG,EAAEJ,IAAI,KAAKI,GAAG,GAAGJ,IAAI,CAACT,UAAU,EAAE,CAAC,CAAC;EAIhF,MAAMc,UAAU,GAAGX,MAAM,CAACS,MAAM,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,2 +1,2 @@
1
- export const VERSION = typeof "3.4.0-alpha.4" !== 'undefined' ? "3.4.0-alpha.4" : 'latest';
1
+ export const VERSION = typeof "3.4.0-alpha.5" !== 'undefined' ? "3.4.0-alpha.5" : 'latest';
2
2
  //# 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+B,EAC/B,uBAAuB,EACvB,4BAA4B,EAC5B,qBAAqB,EACrB,yBAAyB,EAC1B,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;AACzC,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;AAGzC,OAAO,EAAC,SAAS,EAAC,MAAM,cAAc,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,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"}
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+B,EAC/B,uBAAuB,EACvB,4BAA4B,EAC5B,qBAAqB,EACrB,yBAAyB,EAC1B,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;AACzC,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;AAGzC,OAAO,EAAC,SAAS,EAAC,MAAM,cAAc,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.4.0-alpha.4",
3
+ "version": "3.4.0-alpha.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.4.0-alpha.4",
38
- "@loaders.gl/images": "3.4.0-alpha.4",
39
- "@loaders.gl/loader-utils": "3.4.0-alpha.4",
40
- "@loaders.gl/textures": "3.4.0-alpha.4",
37
+ "@loaders.gl/draco": "3.4.0-alpha.5",
38
+ "@loaders.gl/images": "3.4.0-alpha.5",
39
+ "@loaders.gl/loader-utils": "3.4.0-alpha.5",
40
+ "@loaders.gl/textures": "3.4.0-alpha.5",
41
41
  "@math.gl/core": "^3.5.1"
42
42
  },
43
- "gitHead": "f039a523df8b908a91f26c5ba8c4cfc1924b6140"
43
+ "gitHead": "686929f85b3420c15df051eab769942b260dd242"
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
+ }