@loaders.gl/gltf 4.0.2 → 4.0.3

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.dev.js CHANGED
@@ -97,7 +97,7 @@ var __exports__ = (() => {
97
97
  var nodeVersion = matches && parseFloat(matches[1]) || 0;
98
98
 
99
99
  // ../worker-utils/src/lib/env-utils/version.ts
100
- var NPM_TAG = "beta";
100
+ var NPM_TAG = "latest";
101
101
  function getVersion() {
102
102
  if (!globalThis._loadersgl_?.version) {
103
103
  globalThis._loadersgl_ = globalThis._loadersgl_ || {};
@@ -424,7 +424,10 @@ var __exports__ = (() => {
424
424
  return await new Promise((resolve, reject) => {
425
425
  try {
426
426
  image.onload = () => resolve(image);
427
- image.onerror = (err) => reject(new Error(`Could not load image ${url}: ${err}`));
427
+ image.onerror = (error) => {
428
+ const message = error instanceof Error ? error.message : "error";
429
+ reject(new Error(message));
430
+ };
428
431
  } catch (error) {
429
432
  reject(error);
430
433
  }
@@ -833,7 +836,7 @@ var __exports__ = (() => {
833
836
  function getTypedArrayForAccessor(json, buffers, accessor) {
834
837
  const gltfAccessor = typeof accessor === "number" ? json.accessors?.[accessor] : accessor;
835
838
  if (!gltfAccessor) {
836
- throw new Error(`No gltf accessor ${accessor}`);
839
+ throw new Error(`No gltf accessor ${JSON.stringify(accessor)}`);
837
840
  }
838
841
  const bufferView = json.bufferViews?.[gltfAccessor.bufferView || 0];
839
842
  if (!bufferView) {
@@ -3162,7 +3165,7 @@ var __exports__ = (() => {
3162
3165
  var VERSION3 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
3163
3166
 
3164
3167
  // ../textures/src/lib/utils/version.ts
3165
- var VERSION4 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "beta";
3168
+ var VERSION4 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
3166
3169
 
3167
3170
  // ../textures/src/lib/parsers/basis-module-loader.ts
3168
3171
  var BASIS_EXTERNAL_LIBRARIES = {
@@ -1,4 +1,4 @@
1
- import type { Writer, WriterOptions } from '@loaders.gl/loader-utils';
1
+ import type { WriterWithEncoder, WriterOptions } from '@loaders.gl/loader-utils';
2
2
  import type { GLB } from './lib/types/glb-types';
3
3
  import type { GLBEncodeOptions } from './lib/encoders/encode-glb';
4
4
  export type GLBWriterOptions = WriterOptions & {
@@ -8,6 +8,5 @@ export type GLBWriterOptions = WriterOptions & {
8
8
  * GLB exporter
9
9
  * GLB is the binary container format for GLTF
10
10
  */
11
- export declare const GLBWriter: Writer<GLB, never, GLBWriterOptions>;
12
- export declare const _TypecheckGLBLoader: Writer;
11
+ export declare const GLBWriter: WriterWithEncoder<GLB, never, GLBWriterOptions>;
13
12
  //# sourceMappingURL=glb-writer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"glb-writer.d.ts","sourceRoot":"","sources":["../src/glb-writer.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,MAAM,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AACpE,OAAO,KAAK,EAAC,GAAG,EAAC,MAAM,uBAAuB,CAAC;AAC/C,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,2BAA2B,CAAC;AAIhE,MAAM,MAAM,gBAAgB,GAAG,aAAa,GAAG;IAC7C,GAAG,CAAC,EAAE,gBAAgB,CAAC;CACxB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,GAAG,EAAE,KAAK,EAAE,gBAAgB,CAe1D,CAAC;AAiBF,eAAO,MAAM,mBAAmB,EAAE,MAAkB,CAAC"}
1
+ {"version":3,"file":"glb-writer.d.ts","sourceRoot":"","sources":["../src/glb-writer.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,iBAAiB,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAC/E,OAAO,KAAK,EAAC,GAAG,EAAC,MAAM,uBAAuB,CAAC;AAC/C,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,2BAA2B,CAAC;AAIhE,MAAM,MAAM,gBAAgB,GAAG,aAAa,GAAG;IAC7C,GAAG,CAAC,EAAE,gBAAgB,CAAC;CACxB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,SAAS,EAAE,iBAAiB,CAAC,GAAG,EAAE,KAAK,EAAE,gBAAgB,CAerE,CAAC"}
@@ -27,5 +27,4 @@ function encodeSync(glb, options) {
27
27
  encodeGLBSync(glb, dataView, byteOffset, options);
28
28
  return arrayBuffer;
29
29
  }
30
- export const _TypecheckGLBLoader = GLBWriter;
31
30
  //# sourceMappingURL=glb-writer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"glb-writer.js","names":["encodeGLBSync","VERSION","GLBWriter","name","id","module","version","extensions","mimeTypes","binary","options","glb","encode","arguments","length","undefined","encodeSync","byteOffset","byteLength","arrayBuffer","ArrayBuffer","dataView","DataView","_TypecheckGLBLoader"],"sources":["../src/glb-writer.ts"],"sourcesContent":["// loaders.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport type {Writer, WriterOptions} from '@loaders.gl/loader-utils';\nimport type {GLB} from './lib/types/glb-types';\nimport type {GLBEncodeOptions} from './lib/encoders/encode-glb';\nimport {encodeGLBSync} from './lib/encoders/encode-glb';\nimport {VERSION} from './lib/utils/version';\n\nexport type GLBWriterOptions = WriterOptions & {\n glb?: GLBEncodeOptions;\n};\n\n/**\n * GLB exporter\n * GLB is the binary container format for GLTF\n */\nexport const GLBWriter: Writer<GLB, never, GLBWriterOptions> = {\n name: 'GLB',\n id: 'glb',\n module: 'gltf',\n version: VERSION,\n\n extensions: ['glb'],\n mimeTypes: ['model/gltf-binary'],\n binary: true,\n options: {\n glb: {}\n },\n\n encode: async (glb, options: GLBWriterOptions = {}) => encodeSync(glb, options),\n encodeSync\n};\n\nfunction encodeSync(glb, options) {\n const {byteOffset = 0} = options;\n\n // Calculate length and allocate buffer\n const byteLength = encodeGLBSync(glb, null, byteOffset, options);\n const arrayBuffer = new ArrayBuffer(byteLength);\n\n // Encode into buffer\n const dataView = new DataView(arrayBuffer);\n encodeGLBSync(glb, dataView, byteOffset, options);\n\n return arrayBuffer;\n}\n\n// TYPE TESTS - TODO find a better way than exporting junk\nexport const _TypecheckGLBLoader: Writer = GLBWriter;\n"],"mappings":"SAMQA,aAAa;AAAA,SACbC,OAAO;AAUf,OAAO,MAAMC,SAA+C,GAAG;EAC7DC,IAAI,EAAE,KAAK;EACXC,EAAE,EAAE,KAAK;EACTC,MAAM,EAAE,MAAM;EACdC,OAAO,EAAEL,OAAO;EAEhBM,UAAU,EAAE,CAAC,KAAK,CAAC;EACnBC,SAAS,EAAE,CAAC,mBAAmB,CAAC;EAChCC,MAAM,EAAE,IAAI;EACZC,OAAO,EAAE;IACPC,GAAG,EAAE,CAAC;EACR,CAAC;EAEDC,MAAM,EAAE,eAAAA,CAAOD,GAAG;IAAA,IAAED,OAAyB,GAAAG,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;IAAA,OAAKG,UAAU,CAACL,GAAG,EAAED,OAAO,CAAC;EAAA;EAC/EM;AACF,CAAC;AAED,SAASA,UAAUA,CAACL,GAAG,EAAED,OAAO,EAAE;EAChC,MAAM;IAACO,UAAU,GAAG;EAAC,CAAC,GAAGP,OAAO;EAGhC,MAAMQ,UAAU,GAAGlB,aAAa,CAACW,GAAG,EAAE,IAAI,EAAEM,UAAU,EAAEP,OAAO,CAAC;EAChE,MAAMS,WAAW,GAAG,IAAIC,WAAW,CAACF,UAAU,CAAC;EAG/C,MAAMG,QAAQ,GAAG,IAAIC,QAAQ,CAACH,WAAW,CAAC;EAC1CnB,aAAa,CAACW,GAAG,EAAEU,QAAQ,EAAEJ,UAAU,EAAEP,OAAO,CAAC;EAEjD,OAAOS,WAAW;AACpB;AAGA,OAAO,MAAMI,mBAA2B,GAAGrB,SAAS"}
1
+ {"version":3,"file":"glb-writer.js","names":["encodeGLBSync","VERSION","GLBWriter","name","id","module","version","extensions","mimeTypes","binary","options","glb","encode","arguments","length","undefined","encodeSync","byteOffset","byteLength","arrayBuffer","ArrayBuffer","dataView","DataView"],"sources":["../src/glb-writer.ts"],"sourcesContent":["// loaders.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport type {WriterWithEncoder, WriterOptions} from '@loaders.gl/loader-utils';\nimport type {GLB} from './lib/types/glb-types';\nimport type {GLBEncodeOptions} from './lib/encoders/encode-glb';\nimport {encodeGLBSync} from './lib/encoders/encode-glb';\nimport {VERSION} from './lib/utils/version';\n\nexport type GLBWriterOptions = WriterOptions & {\n glb?: GLBEncodeOptions;\n};\n\n/**\n * GLB exporter\n * GLB is the binary container format for GLTF\n */\nexport const GLBWriter: WriterWithEncoder<GLB, never, GLBWriterOptions> = {\n name: 'GLB',\n id: 'glb',\n module: 'gltf',\n version: VERSION,\n\n extensions: ['glb'],\n mimeTypes: ['model/gltf-binary'],\n binary: true,\n options: {\n glb: {}\n },\n\n encode: async (glb, options: GLBWriterOptions = {}) => encodeSync(glb, options),\n encodeSync\n};\n\nfunction encodeSync(glb, options) {\n const {byteOffset = 0} = options;\n\n // Calculate length and allocate buffer\n const byteLength = encodeGLBSync(glb, null, byteOffset, options);\n const arrayBuffer = new ArrayBuffer(byteLength);\n\n // Encode into buffer\n const dataView = new DataView(arrayBuffer);\n encodeGLBSync(glb, dataView, byteOffset, options);\n\n return arrayBuffer;\n}\n"],"mappings":"SAMQA,aAAa;AAAA,SACbC,OAAO;AAUf,OAAO,MAAMC,SAA0D,GAAG;EACxEC,IAAI,EAAE,KAAK;EACXC,EAAE,EAAE,KAAK;EACTC,MAAM,EAAE,MAAM;EACdC,OAAO,EAAEL,OAAO;EAEhBM,UAAU,EAAE,CAAC,KAAK,CAAC;EACnBC,SAAS,EAAE,CAAC,mBAAmB,CAAC;EAChCC,MAAM,EAAE,IAAI;EACZC,OAAO,EAAE;IACPC,GAAG,EAAE,CAAC;EACR,CAAC;EAEDC,MAAM,EAAE,eAAAA,CAAOD,GAAG;IAAA,IAAED,OAAyB,GAAAG,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;IAAA,OAAKG,UAAU,CAACL,GAAG,EAAED,OAAO,CAAC;EAAA;EAC/EM;AACF,CAAC;AAED,SAASA,UAAUA,CAACL,GAAG,EAAED,OAAO,EAAE;EAChC,MAAM;IAACO,UAAU,GAAG;EAAC,CAAC,GAAGP,OAAO;EAGhC,MAAMQ,UAAU,GAAGlB,aAAa,CAACW,GAAG,EAAE,IAAI,EAAEM,UAAU,EAAEP,OAAO,CAAC;EAChE,MAAMS,WAAW,GAAG,IAAIC,WAAW,CAACF,UAAU,CAAC;EAG/C,MAAMG,QAAQ,GAAG,IAAIC,QAAQ,CAACH,WAAW,CAAC;EAC1CnB,aAAa,CAACW,GAAG,EAAEU,QAAQ,EAAEJ,UAAU,EAAEP,OAAO,CAAC;EAEjD,OAAOS,WAAW;AACpB"}
package/dist/index.cjs CHANGED
@@ -166,7 +166,7 @@ function getTypedArrayForAccessor(json, buffers, accessor) {
166
166
  var _a, _b;
167
167
  const gltfAccessor = typeof accessor === "number" ? (_a = json.accessors) == null ? void 0 : _a[accessor] : accessor;
168
168
  if (!gltfAccessor) {
169
- throw new Error(`No gltf accessor ${accessor}`);
169
+ throw new Error(`No gltf accessor ${JSON.stringify(accessor)}`);
170
170
  }
171
171
  const bufferView = (_b = json.bufferViews) == null ? void 0 : _b[gltfAccessor.bufferView || 0];
172
172
  if (!bufferView) {
@@ -18,7 +18,7 @@ export function getTypedArrayForAccessor(json, buffers, accessor) {
18
18
  var _json$accessors, _json$bufferViews;
19
19
  const gltfAccessor = typeof accessor === 'number' ? (_json$accessors = json.accessors) === null || _json$accessors === void 0 ? void 0 : _json$accessors[accessor] : accessor;
20
20
  if (!gltfAccessor) {
21
- throw new Error(`No gltf accessor ${accessor}`);
21
+ throw new Error(`No gltf accessor ${JSON.stringify(accessor)}`);
22
22
  }
23
23
  const bufferView = (_json$bufferViews = json.bufferViews) === null || _json$bufferViews === void 0 ? void 0 : _json$bufferViews[gltfAccessor.bufferView || 0];
24
24
  if (!bufferView) {
@@ -1 +1 @@
1
- {"version":3,"file":"get-typed-array.js","names":["assert","getAccessorArrayTypeAndLength","getTypedArrayForBufferView","json","buffers","bufferViewIndex","bufferView","bufferViews","bufferIndex","buffer","binChunk","byteOffset","Uint8Array","arrayBuffer","byteLength","getTypedArrayForImageData","imageIndex","image","images","getTypedArrayForAccessor","accessor","_json$accessors","_json$bufferViews","gltfAccessor","accessors","Error","bufferByteOffset","ArrayType","length","componentByteSize","numberOfComponentsInElement","elementByteSize","elementAddressScale","byteStride","result","i","count","values","set"],"sources":["../../../src/lib/gltf-utils/get-typed-array.ts"],"sourcesContent":["// TODO - GLTFScenegraph should use these\nimport {assert} from '../utils/assert';\nimport type {TypedArray} from '@loaders.gl/schema';\nimport type {GLTF, GLTFExternalBuffer, GLTFAccessor} from '../types/gltf-types';\nimport {getAccessorArrayTypeAndLength} from './gltf-utils';\n\n// accepts buffer view index or buffer view object\n// returns a `Uint8Array`\nexport function getTypedArrayForBufferView(json, buffers, bufferViewIndex) {\n const bufferView = json.bufferViews[bufferViewIndex];\n assert(bufferView);\n\n // Get hold of the arrayBuffer\n const bufferIndex = bufferView.buffer;\n const binChunk = buffers[bufferIndex];\n assert(binChunk);\n\n const byteOffset = (bufferView.byteOffset || 0) + binChunk.byteOffset;\n return new Uint8Array(binChunk.arrayBuffer, byteOffset, bufferView.byteLength);\n}\n\n// accepts accessor index or accessor object\n// returns a `Uint8Array`\nexport function getTypedArrayForImageData(json, buffers, imageIndex) {\n const image = json.images[imageIndex];\n const bufferViewIndex = json.bufferViews[image.bufferView];\n return getTypedArrayForBufferView(json, buffers, bufferViewIndex);\n}\n\n/**\n * Gets data pointed by the accessor.\n * @param json - json part of gltf content of a GLTF tile.\n * @param buffers - Array containing buffers of data.\n * @param accessor - accepts accessor index or accessor object.\n * @returns {TypedArray} Typed array with type matching the type of data poited by the accessor.\n */\n// eslint-disable-next-line complexity\nexport function getTypedArrayForAccessor(\n json: GLTF,\n buffers: GLTFExternalBuffer[],\n accessor: GLTFAccessor | number\n): TypedArray {\n const gltfAccessor = typeof accessor === 'number' ? json.accessors?.[accessor] : accessor;\n if (!gltfAccessor) {\n throw new Error(`No gltf accessor ${accessor}`);\n }\n const bufferView = json.bufferViews?.[gltfAccessor.bufferView || 0];\n if (!bufferView) {\n throw new Error(`No gltf buffer view for accessor ${bufferView}`);\n }\n // Get `arrayBuffer` the `bufferView` looks at\n const {arrayBuffer, byteOffset: bufferByteOffset} = buffers[bufferView.buffer];\n // Resulting byteOffset is sum of the buffer, accessor and bufferView byte offsets\n const byteOffset =\n (bufferByteOffset || 0) + (gltfAccessor.byteOffset || 0) + (bufferView.byteOffset || 0);\n // Deduce TypedArray type and its length from `accessor` and `bufferView` data\n const {ArrayType, length, componentByteSize, numberOfComponentsInElement} =\n getAccessorArrayTypeAndLength(gltfAccessor, bufferView);\n // 'length' is a whole number of components of all elements in the buffer pointed by the accessor\n // Multiplier to calculate the address of the element in the arrayBuffer\n const elementByteSize = componentByteSize * numberOfComponentsInElement;\n const elementAddressScale = bufferView.byteStride || elementByteSize;\n // Creare an array of component's type where all components (not just elements) will reside\n if (typeof bufferView.byteStride === 'undefined' || bufferView.byteStride === elementByteSize) {\n // No iterleaving\n const result: TypedArray = new ArrayType(arrayBuffer, byteOffset, length);\n return result;\n }\n // Iterleaving\n const result: TypedArray = new ArrayType(length);\n for (let i = 0; i < gltfAccessor.count; i++) {\n const values = new ArrayType(\n arrayBuffer,\n byteOffset + i * elementAddressScale,\n numberOfComponentsInElement\n );\n result.set(values, i * numberOfComponentsInElement);\n }\n return result;\n}\n"],"mappings":"SACQA,MAAM;AAAA,SAGNC,6BAA6B;AAIrC,OAAO,SAASC,0BAA0BA,CAACC,IAAI,EAAEC,OAAO,EAAEC,eAAe,EAAE;EACzE,MAAMC,UAAU,G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CAAE,oCAAmCnB,UAAW,EAAC,CAAC;EACnE;EAEA,MAAM;IAACO,WAAW;IAAEF,UAAU,EAAEe;EAAgB,CAAC,GAAGtB,OAAO,CAACE,UAAU,CAACG,MAAM,CAAC;EAE9E,MAAME,UAAU,GACd,CAACe,gBAAgB,IAAI,CAAC,KAAKH,YAAY,CAACZ,UAAU,IAAI,CAAC,CAAC,IAAIL,UAAU,CAACK,UAAU,IAAI,CAAC,CAAC;EAEzF,MAAM;IAACgB,SAAS;IAAEC,MAAM;IAAEC,iBAAiB;IAAEC;EAA2B,CAAC,GACvE7B,6BAA6B,CAACsB,YAAY,EAAEjB,UAAU,CAAC;EAGzD,MAAMyB,eAAe,GAAGF,iBAAiB,GAAGC,2BAA2B;EACvE,MAAME,mBAAmB,GAAG1B,UAAU,CAAC2B,UAAU,IAAIF,eAAe;EAEpE,IAAI,OAAOzB,UAAU,CAAC2B,UAAU,KAAK,WAAW,IAAI3B,UAAU,CAAC2B,UAAU,KAAKF,eAAe,EAAE;IAE7F,MAAMG,MAAkB,GAAG,IAAIP,SAAS,CAACd,WAAW,EAAEF,UAAU,EAAEiB,MAAM,CAAC;IACzE,OAAOM,MAAM;EACf;EAEA,MAAMA,MAAkB,GAAG,IAAIP,SAAS,CAACC,MAAM,CAAC;EAChD,KAAK,IAAIO,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGZ,YAAY,CAACa,KAAK,EAAED,CAAC,EAAE,EAAE;IAC3C,MAAME,MAAM,GAAG,IAAIV,SAAS,CAC1Bd,WAAW,EACXF,UAAU,GAAGwB,CAAC,GAAGH,mBAAmB,EACpCF,2BACF,CAAC;IACDI,MAAM,CAACI,GAAG,CAACD,MAAM,EAAEF,CAAC,GAAGL,2BAA2B,CAAC;EACrD;EACA,OAAOI,MAAM;AACf"}
1
+ {"version":3,"file":"get-typed-array.js","names":["assert","getAccessorArrayTypeAndLength","getTypedArrayForBufferView","json","buffers","bufferViewIndex","bufferView","bufferViews","bufferIndex","buffer","binChunk","byteOffset","Uint8Array","arrayBuffer","byteLength","getTypedArrayForImageData","imageIndex","image","images","getTypedArrayForAccessor","accessor","_json$accessors","_json$bufferViews","gltfAccessor","accessors","Error","JSON","stringify","bufferByteOffset","ArrayType","length","componentByteSize","numberOfComponentsInElement","elementByteSize","elementAddressScale","byteStride","result","i","count","values","set"],"sources":["../../../src/lib/gltf-utils/get-typed-array.ts"],"sourcesContent":["// TODO - GLTFScenegraph should use these\nimport {assert} from '../utils/assert';\nimport type {TypedArray} from '@loaders.gl/schema';\nimport type {GLTF, GLTFExternalBuffer, GLTFAccessor} from '../types/gltf-types';\nimport {getAccessorArrayTypeAndLength} from './gltf-utils';\n\n// accepts buffer view index or buffer view object\n// returns a `Uint8Array`\nexport function getTypedArrayForBufferView(json, buffers, bufferViewIndex) {\n const bufferView = json.bufferViews[bufferViewIndex];\n assert(bufferView);\n\n // Get hold of the arrayBuffer\n const bufferIndex = bufferView.buffer;\n const binChunk = buffers[bufferIndex];\n assert(binChunk);\n\n const byteOffset = (bufferView.byteOffset || 0) + binChunk.byteOffset;\n return new Uint8Array(binChunk.arrayBuffer, byteOffset, bufferView.byteLength);\n}\n\n// accepts accessor index or accessor object\n// returns a `Uint8Array`\nexport function getTypedArrayForImageData(json, buffers, imageIndex) {\n const image = json.images[imageIndex];\n const bufferViewIndex = json.bufferViews[image.bufferView];\n return getTypedArrayForBufferView(json, buffers, bufferViewIndex);\n}\n\n/**\n * Gets data pointed by the accessor.\n * @param json - json part of gltf content of a GLTF tile.\n * @param buffers - Array containing buffers of data.\n * @param accessor - accepts accessor index or accessor object.\n * @returns {TypedArray} Typed array with type matching the type of data poited by the accessor.\n */\n// eslint-disable-next-line complexity\nexport function getTypedArrayForAccessor(\n json: GLTF,\n buffers: GLTFExternalBuffer[],\n accessor: GLTFAccessor | number\n): TypedArray {\n const gltfAccessor = typeof accessor === 'number' ? json.accessors?.[accessor] : accessor;\n if (!gltfAccessor) {\n throw new Error(`No gltf accessor ${JSON.stringify(accessor)}`);\n }\n const bufferView = json.bufferViews?.[gltfAccessor.bufferView || 0];\n if (!bufferView) {\n throw new Error(`No gltf buffer view for accessor ${bufferView}`);\n }\n // Get `arrayBuffer` the `bufferView` looks at\n const {arrayBuffer, byteOffset: bufferByteOffset} = buffers[bufferView.buffer];\n // Resulting byteOffset is sum of the buffer, accessor and bufferView byte offsets\n const byteOffset =\n (bufferByteOffset || 0) + (gltfAccessor.byteOffset || 0) + (bufferView.byteOffset || 0);\n // Deduce TypedArray type and its length from `accessor` and `bufferView` data\n const {ArrayType, length, componentByteSize, numberOfComponentsInElement} =\n getAccessorArrayTypeAndLength(gltfAccessor, bufferView);\n // 'length' is a whole number of components of all elements in the buffer pointed by the accessor\n // Multiplier to calculate the address of the element in the arrayBuffer\n const elementByteSize = componentByteSize * numberOfComponentsInElement;\n const elementAddressScale = bufferView.byteStride || elementByteSize;\n // Creare an array of component's type where all components (not just elements) will reside\n if (typeof bufferView.byteStride === 'undefined' || bufferView.byteStride === elementByteSize) {\n // No iterleaving\n const result: TypedArray = new ArrayType(arrayBuffer, byteOffset, length);\n return result;\n }\n // Iterleaving\n const result: TypedArray = new ArrayType(length);\n for (let i = 0; i < gltfAccessor.count; i++) {\n const values = new ArrayType(\n arrayBuffer,\n byteOffset + i * elementAddressScale,\n numberOfComponentsInElement\n );\n result.set(values, i * numberOfComponentsInElement);\n }\n return result;\n}\n"],"mappings":"SACQA,MAAM;AAAA,SAGNC,6BAA6B;AAIrC,OAAO,SAASC,0BAA0BA,CAACC,IAAI,EAAEC,OAAO,EAAEC,eAAe,EAAE;EACzE,MAAMC,UAAU,GAAGH,IAAI,CAACI,WAAW,CAACF,eAAe,CAAC;EACpDL,MAAM,CAACM,UAAU,CAAC;EAGlB,MAAME,WAAW,GAAGF,UAAU,CAACG,MAAM;EACrC,MAAMC,QAAQ,GAAGN,OAAO,CAACI,WAAW,CAAC;EACrCR,MAAM,CAACU,QAAQ,CAAC;EAEhB,MAAMC,UAAU,GAAG,CAACL,UAA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Y,CAACZ,UAAU,IAAI,CAAC,CAAC,IAAIL,UAAU,CAACK,UAAU,IAAI,CAAC,CAAC;EAEzF,MAAM;IAACkB,SAAS;IAAEC,MAAM;IAAEC,iBAAiB;IAAEC;EAA2B,CAAC,GACvE/B,6BAA6B,CAACsB,YAAY,EAAEjB,UAAU,CAAC;EAGzD,MAAM2B,eAAe,GAAGF,iBAAiB,GAAGC,2BAA2B;EACvE,MAAME,mBAAmB,GAAG5B,UAAU,CAAC6B,UAAU,IAAIF,eAAe;EAEpE,IAAI,OAAO3B,UAAU,CAAC6B,UAAU,KAAK,WAAW,IAAI7B,UAAU,CAAC6B,UAAU,KAAKF,eAAe,EAAE;IAE7F,MAAMG,MAAkB,GAAG,IAAIP,SAAS,CAAChB,WAAW,EAAEF,UAAU,EAAEmB,MAAM,CAAC;IACzE,OAAOM,MAAM;EACf;EAEA,MAAMA,MAAkB,GAAG,IAAIP,SAAS,CAACC,MAAM,CAAC;EAChD,KAAK,IAAIO,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGd,YAAY,CAACe,KAAK,EAAED,CAAC,EAAE,EAAE;IAC3C,MAAME,MAAM,GAAG,IAAIV,SAAS,CAC1BhB,WAAW,EACXF,UAAU,GAAG0B,CAAC,GAAGH,mBAAmB,EACpCF,2BACF,CAAC;IACDI,MAAM,CAACI,GAAG,CAACD,MAAM,EAAEF,CAAC,GAAGL,2BAA2B,CAAC;EACrD;EACA,OAAOI,MAAM;AACf"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/gltf",
3
- "version": "4.0.2",
3
+ "version": "4.0.3",
4
4
  "description": "Framework-independent loader for the glTF format",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -42,11 +42,11 @@
42
42
  "build-bundle": "ocular-bundle ./src/index.ts"
43
43
  },
44
44
  "dependencies": {
45
- "@loaders.gl/draco": "4.0.2",
46
- "@loaders.gl/images": "4.0.2",
47
- "@loaders.gl/loader-utils": "4.0.2",
48
- "@loaders.gl/textures": "4.0.2",
45
+ "@loaders.gl/draco": "4.0.3",
46
+ "@loaders.gl/images": "4.0.3",
47
+ "@loaders.gl/loader-utils": "4.0.3",
48
+ "@loaders.gl/textures": "4.0.3",
49
49
  "@math.gl/core": "^4.0.0"
50
50
  },
51
- "gitHead": "471058d109d5652f28c32c1f296fd632f9a5c806"
51
+ "gitHead": "03c871839b36c997249dabae1844df53a35d3760"
52
52
  }
package/src/glb-writer.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  // loaders.gl, MIT license
2
2
  // Copyright (c) vis.gl contributors
3
3
 
4
- import type {Writer, WriterOptions} from '@loaders.gl/loader-utils';
4
+ import type {WriterWithEncoder, WriterOptions} from '@loaders.gl/loader-utils';
5
5
  import type {GLB} from './lib/types/glb-types';
6
6
  import type {GLBEncodeOptions} from './lib/encoders/encode-glb';
7
7
  import {encodeGLBSync} from './lib/encoders/encode-glb';
@@ -15,7 +15,7 @@ export type GLBWriterOptions = WriterOptions & {
15
15
  * GLB exporter
16
16
  * GLB is the binary container format for GLTF
17
17
  */
18
- export const GLBWriter: Writer<GLB, never, GLBWriterOptions> = {
18
+ export const GLBWriter: WriterWithEncoder<GLB, never, GLBWriterOptions> = {
19
19
  name: 'GLB',
20
20
  id: 'glb',
21
21
  module: 'gltf',
@@ -45,6 +45,3 @@ function encodeSync(glb, options) {
45
45
 
46
46
  return arrayBuffer;
47
47
  }
48
-
49
- // TYPE TESTS - TODO find a better way than exporting junk
50
- export const _TypecheckGLBLoader: Writer = GLBWriter;
@@ -42,7 +42,7 @@ export function getTypedArrayForAccessor(
42
42
  ): TypedArray {
43
43
  const gltfAccessor = typeof accessor === 'number' ? json.accessors?.[accessor] : accessor;
44
44
  if (!gltfAccessor) {
45
- throw new Error(`No gltf accessor ${accessor}`);
45
+ throw new Error(`No gltf accessor ${JSON.stringify(accessor)}`);
46
46
  }
47
47
  const bufferView = json.bufferViews?.[gltfAccessor.bufferView || 0];
48
48
  if (!bufferView) {