@loaders.gl/gltf 3.1.0-alpha.5 → 3.1.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/dist/bundle.d.ts +1 -0
  2. package/dist/bundle.d.ts.map +1 -0
  3. package/dist/bundle.js +4483 -0
  4. package/dist/es5/lib/api/normalize-gltf-v1.js +8 -3
  5. package/dist/es5/lib/api/normalize-gltf-v1.js.map +1 -1
  6. package/dist/es5/lib/api/post-process-gltf.js +12 -1
  7. package/dist/es5/lib/api/post-process-gltf.js.map +1 -1
  8. package/dist/es5/lib/encoders/encode-glb.js.map +1 -1
  9. package/dist/es5/lib/encoders/encode-gltf.js.map +1 -1
  10. package/dist/es5/lib/extensions/KHR_texture_basisu.js.map +1 -1
  11. package/dist/es5/lib/utils/assert.js.map +1 -1
  12. package/dist/es5/lib/utils/version.js +1 -1
  13. package/dist/es5/lib/utils/version.js.map +1 -1
  14. package/dist/esm/lib/api/normalize-gltf-v1.js +6 -3
  15. package/dist/esm/lib/api/normalize-gltf-v1.js.map +1 -1
  16. package/dist/esm/lib/api/post-process-gltf.js +12 -1
  17. package/dist/esm/lib/api/post-process-gltf.js.map +1 -1
  18. package/dist/esm/lib/encoders/encode-glb.js.map +1 -1
  19. package/dist/esm/lib/encoders/encode-gltf.js.map +1 -1
  20. package/dist/esm/lib/extensions/KHR_texture_basisu.js.map +1 -1
  21. package/dist/esm/lib/utils/assert.js.map +1 -1
  22. package/dist/esm/lib/utils/version.js +1 -1
  23. package/dist/esm/lib/utils/version.js.map +1 -1
  24. package/dist/glb-loader.d.ts +1 -0
  25. package/dist/glb-loader.d.ts.map +1 -0
  26. package/dist/glb-loader.js +39 -0
  27. package/dist/glb-writer.d.ts +1 -0
  28. package/dist/glb-writer.d.ts.map +1 -0
  29. package/dist/glb-writer.js +37 -0
  30. package/dist/gltf-loader.d.ts +2 -1
  31. package/dist/gltf-loader.d.ts.map +1 -0
  32. package/dist/gltf-loader.js +50 -0
  33. package/dist/gltf-writer.d.ts +1 -0
  34. package/dist/gltf-writer.d.ts.map +1 -0
  35. package/dist/gltf-writer.js +32 -0
  36. package/dist/index.d.ts +1 -0
  37. package/dist/index.d.ts.map +1 -0
  38. package/dist/index.js +21 -0
  39. package/dist/lib/api/gltf-extensions.d.ts +1 -0
  40. package/dist/lib/api/gltf-extensions.d.ts.map +1 -0
  41. package/dist/lib/api/gltf-extensions.js +75 -0
  42. package/dist/lib/api/gltf-scenegraph.d.ts +1 -0
  43. package/dist/lib/api/gltf-scenegraph.d.ts.map +1 -0
  44. package/dist/lib/api/gltf-scenegraph.js +553 -0
  45. package/dist/lib/api/normalize-gltf-v1.d.ts +2 -1
  46. package/dist/lib/api/normalize-gltf-v1.d.ts.map +1 -0
  47. package/dist/lib/api/normalize-gltf-v1.js +295 -0
  48. package/dist/lib/api/post-process-gltf.d.ts +2 -1
  49. package/dist/lib/api/post-process-gltf.d.ts.map +1 -0
  50. package/dist/lib/api/post-process-gltf.js +346 -0
  51. package/dist/lib/encoders/encode-glb.d.ts +1 -0
  52. package/dist/lib/encoders/encode-glb.d.ts.map +1 -0
  53. package/dist/lib/encoders/encode-glb.js +61 -0
  54. package/dist/lib/encoders/encode-gltf.d.ts +2 -1
  55. package/dist/lib/encoders/encode-gltf.d.ts.map +1 -0
  56. package/dist/lib/encoders/encode-gltf.js +27 -0
  57. package/dist/lib/extensions/EXT_meshopt_compression.d.ts +1 -0
  58. package/dist/lib/extensions/EXT_meshopt_compression.d.ts.map +1 -0
  59. package/dist/lib/extensions/EXT_meshopt_compression.js +54 -0
  60. package/dist/lib/extensions/EXT_texture_webp.d.ts +1 -0
  61. package/dist/lib/extensions/EXT_texture_webp.d.ts.map +1 -0
  62. package/dist/lib/extensions/EXT_texture_webp.js +38 -0
  63. package/dist/lib/extensions/KHR_binary_gltf.d.ts +1 -0
  64. package/dist/lib/extensions/KHR_binary_gltf.d.ts.map +1 -0
  65. package/dist/lib/extensions/KHR_binary_gltf.js +42 -0
  66. package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts +1 -0
  67. package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts.map +1 -0
  68. package/dist/lib/extensions/KHR_draco_mesh_compression.js +141 -0
  69. package/dist/lib/extensions/KHR_texture_basisu.d.ts +1 -0
  70. package/dist/lib/extensions/KHR_texture_basisu.d.ts.map +1 -0
  71. package/dist/lib/extensions/KHR_texture_basisu.js +31 -0
  72. package/dist/lib/extensions/deprecated/KHR_lights_punctual.d.ts +1 -0
  73. package/dist/lib/extensions/deprecated/KHR_lights_punctual.d.ts.map +1 -0
  74. package/dist/lib/extensions/deprecated/KHR_lights_punctual.js +62 -0
  75. package/dist/lib/extensions/deprecated/KHR_materials_unlit.d.ts +1 -0
  76. package/dist/lib/extensions/deprecated/KHR_materials_unlit.d.ts.map +1 -0
  77. package/dist/lib/extensions/deprecated/KHR_materials_unlit.js +47 -0
  78. package/dist/lib/extensions/deprecated/KHR_techniques_webgl.d.ts +1 -0
  79. package/dist/lib/extensions/deprecated/KHR_techniques_webgl.d.ts.map +1 -0
  80. package/dist/lib/extensions/deprecated/KHR_techniques_webgl.js +81 -0
  81. package/dist/lib/gltf-utils/get-typed-array.d.ts +1 -0
  82. package/dist/lib/gltf-utils/get-typed-array.d.ts.map +1 -0
  83. package/dist/lib/gltf-utils/get-typed-array.js +41 -0
  84. package/dist/lib/gltf-utils/gltf-attribute-utils.d.ts +1 -0
  85. package/dist/lib/gltf-utils/gltf-attribute-utils.d.ts.map +1 -0
  86. package/dist/lib/gltf-utils/gltf-attribute-utils.js +73 -0
  87. package/dist/lib/gltf-utils/gltf-constants.d.ts +1 -0
  88. package/dist/lib/gltf-utils/gltf-constants.d.ts.map +1 -0
  89. package/dist/lib/gltf-utils/gltf-constants.js +43 -0
  90. package/dist/lib/gltf-utils/gltf-utils.d.ts +1 -0
  91. package/dist/lib/gltf-utils/gltf-utils.d.ts.map +1 -0
  92. package/dist/lib/gltf-utils/gltf-utils.js +63 -0
  93. package/dist/lib/gltf-utils/resolve-url.d.ts +1 -0
  94. package/dist/lib/gltf-utils/resolve-url.d.ts.map +1 -0
  95. package/dist/lib/gltf-utils/resolve-url.js +18 -0
  96. package/dist/lib/parsers/parse-glb.d.ts +1 -0
  97. package/dist/lib/parsers/parse-glb.d.ts.map +1 -0
  98. package/dist/lib/parsers/parse-glb.js +141 -0
  99. package/dist/lib/parsers/parse-gltf.d.ts +2 -1
  100. package/dist/lib/parsers/parse-gltf.d.ts.map +1 -0
  101. package/dist/lib/parsers/parse-gltf.js +189 -0
  102. package/dist/lib/types/glb-types.d.ts +1 -0
  103. package/dist/lib/types/glb-types.d.ts.map +1 -0
  104. package/dist/lib/types/glb-types.js +2 -0
  105. package/dist/lib/types/gltf-json-schema.d.ts +1 -0
  106. package/dist/lib/types/gltf-json-schema.d.ts.map +1 -0
  107. package/dist/lib/types/gltf-json-schema.js +4 -0
  108. package/dist/lib/types/gltf-postprocessed-schema.d.ts +1 -0
  109. package/dist/lib/types/gltf-postprocessed-schema.d.ts.map +1 -0
  110. package/dist/lib/types/gltf-postprocessed-schema.js +4 -0
  111. package/dist/lib/types/gltf-types.d.ts +1 -0
  112. package/dist/lib/types/gltf-types.d.ts.map +1 -0
  113. package/dist/lib/types/gltf-types.js +3 -0
  114. package/dist/lib/utils/assert.d.ts +2 -1
  115. package/dist/lib/utils/assert.d.ts.map +1 -0
  116. package/dist/lib/utils/assert.js +12 -0
  117. package/dist/lib/utils/version.d.ts +2 -1
  118. package/dist/lib/utils/version.d.ts.map +1 -0
  119. package/dist/lib/utils/version.js +7 -0
  120. package/dist/meshopt/meshopt-decoder.d.ts +1 -0
  121. package/dist/meshopt/meshopt-decoder.d.ts.map +1 -0
  122. package/dist/meshopt/meshopt-decoder.js +118 -0
  123. package/dist/webp/webp.d.ts +1 -0
  124. package/dist/webp/webp.d.ts.map +1 -0
  125. package/dist/webp/webp.js +38 -0
  126. package/package.json +8 -9
  127. package/src/lib/api/{normalize-gltf-v1.js → normalize-gltf-v1.ts} +18 -16
  128. package/src/lib/api/{post-process-gltf.js → post-process-gltf.ts} +8 -1
  129. package/src/lib/encoders/{encode-glb.js → encode-glb.ts} +0 -0
  130. package/src/lib/encoders/{encode-gltf.js → encode-gltf.ts} +0 -0
  131. package/src/lib/extensions/KHR_texture_basisu.ts +2 -2
  132. package/src/lib/utils/{assert.js → assert.ts} +1 -1
  133. package/src/lib/utils/{version.js → version.ts} +0 -0
  134. package/dist/dist.min.js +0 -2
  135. package/dist/dist.min.js.map +0 -1
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ // GLTF EXTENSION: KHR_techniques_webgl
3
+ // https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_techniques_webgl
4
+ var __importDefault = (this && this.__importDefault) || function (mod) {
5
+ return (mod && mod.__esModule) ? mod : { "default": mod };
6
+ };
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.encode = exports.decode = exports.name = void 0;
9
+ const gltf_scenegraph_1 = __importDefault(require("../../api/gltf-scenegraph"));
10
+ const KHR_TECHNIQUES_WEBGL = 'KHR_techniques_webgl';
11
+ exports.name = KHR_TECHNIQUES_WEBGL;
12
+ async function decode(gltfData) {
13
+ const gltfScenegraph = new gltf_scenegraph_1.default(gltfData);
14
+ const { json } = gltfScenegraph;
15
+ const extension = gltfScenegraph.getExtension(KHR_TECHNIQUES_WEBGL);
16
+ if (extension) {
17
+ const techniques = resolveTechniques(extension, gltfScenegraph);
18
+ for (const material of json.materials || []) {
19
+ const materialExtension = gltfScenegraph.getObjectExtension(material, KHR_TECHNIQUES_WEBGL);
20
+ if (materialExtension) {
21
+ // @ts-ignore TODO
22
+ material.technique = Object.assign({}, materialExtension,
23
+ // @ts-ignore
24
+ techniques[materialExtension.technique]);
25
+ // @ts-ignore TODO
26
+ material.technique.values = resolveValues(material.technique, gltfScenegraph);
27
+ }
28
+ gltfScenegraph.removeObjectExtension(material, KHR_TECHNIQUES_WEBGL);
29
+ }
30
+ gltfScenegraph.removeExtension(KHR_TECHNIQUES_WEBGL);
31
+ }
32
+ }
33
+ exports.decode = decode;
34
+ // eslint-disable-next-line
35
+ async function encode(gltfData, options) {
36
+ // TODO
37
+ }
38
+ exports.encode = encode;
39
+ function resolveTechniques(techniquesExtension,
40
+ // programs: {[key: string]: any}[],
41
+ // shaders: {[key: string]: any}[],
42
+ // techniques: {[key: string]: any}[]
43
+ gltfScenegraph) {
44
+ const { programs = [], shaders = [], techniques = [] } = techniquesExtension;
45
+ const textDecoder = new TextDecoder();
46
+ shaders.forEach((shader) => {
47
+ if (Number.isFinite(shader.bufferView)) {
48
+ shader.code = textDecoder.decode(gltfScenegraph.getTypedArrayForBufferView(shader.bufferView));
49
+ }
50
+ else {
51
+ // TODO: handle URI shader
52
+ throw new Error('KHR_techniques_webgl: no shader code');
53
+ }
54
+ });
55
+ programs.forEach((program) => {
56
+ program.fragmentShader = shaders[program.fragmentShader];
57
+ program.vertexShader = shaders[program.vertexShader];
58
+ });
59
+ techniques.forEach((technique) => {
60
+ technique.program = programs[technique.program];
61
+ });
62
+ return techniques;
63
+ }
64
+ function resolveValues(technique, gltfScenegraph) {
65
+ const values = Object.assign({}, technique.values);
66
+ // merge values from uniforms
67
+ Object.keys(technique.uniforms || {}).forEach((uniform) => {
68
+ if (technique.uniforms[uniform].value && !(uniform in values)) {
69
+ values[uniform] = technique.uniforms[uniform].value;
70
+ }
71
+ });
72
+ // resolve textures
73
+ Object.keys(values).forEach((uniform) => {
74
+ if (typeof values[uniform] === 'object' && values[uniform].index !== undefined) {
75
+ // Assume this is a texture
76
+ // TODO: find if there are any other types that can be referenced
77
+ values[uniform].texture = gltfScenegraph.getTexture(values[uniform].index);
78
+ }
79
+ });
80
+ return values;
81
+ }
@@ -1,2 +1,3 @@
1
1
  export declare function getTypedArrayForBufferView(json: any, buffers: any, bufferViewIndex: any): Uint8Array;
2
2
  export declare function getTypedArrayForImageData(json: any, buffers: any, imageIndex: any): Uint8Array;
3
+ //# sourceMappingURL=get-typed-array.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-typed-array.d.ts","sourceRoot":"","sources":["../../../src/lib/gltf-utils/get-typed-array.ts"],"names":[],"mappings":"AAKA,wBAAgB,0BAA0B,CAAC,IAAI,KAAA,EAAE,OAAO,KAAA,EAAE,eAAe,KAAA,cAWxE;AAID,wBAAgB,yBAAyB,CAAC,IAAI,KAAA,EAAE,OAAO,KAAA,EAAE,UAAU,KAAA,cAIlE"}
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTypedArrayForImageData = exports.getTypedArrayForBufferView = void 0;
4
+ // TODO - GLTFScenegraph should use these
5
+ const assert_1 = require("../utils/assert");
6
+ // accepts buffer view index or buffer view object
7
+ // returns a `Uint8Array`
8
+ function getTypedArrayForBufferView(json, buffers, bufferViewIndex) {
9
+ const bufferView = json.bufferViews[bufferViewIndex];
10
+ (0, assert_1.assert)(bufferView);
11
+ // Get hold of the arrayBuffer
12
+ const bufferIndex = bufferView.buffer;
13
+ const binChunk = buffers[bufferIndex];
14
+ (0, assert_1.assert)(binChunk);
15
+ const byteOffset = (bufferView.byteOffset || 0) + binChunk.byteOffset;
16
+ return new Uint8Array(binChunk.arrayBuffer, byteOffset, bufferView.byteLength);
17
+ }
18
+ exports.getTypedArrayForBufferView = getTypedArrayForBufferView;
19
+ // accepts accessor index or accessor object
20
+ // returns a `Uint8Array`
21
+ function getTypedArrayForImageData(json, buffers, imageIndex) {
22
+ const image = json.images[imageIndex];
23
+ const bufferViewIndex = json.bufferViews[image.bufferView];
24
+ return getTypedArrayForBufferView(json, buffers, bufferViewIndex);
25
+ }
26
+ exports.getTypedArrayForImageData = getTypedArrayForImageData;
27
+ /*
28
+ // accepts accessor index or accessor object
29
+ // returns a typed array with type that matches the types
30
+ export function getTypedArrayForAccessor(accessor) {
31
+ accessor = this.getAccessor(accessor);
32
+ const bufferView = this.getBufferView(accessor.bufferView);
33
+ const buffer = this.getBuffer(bufferView.buffer);
34
+ const arrayBuffer = buffer.data;
35
+
36
+ // Create a new typed array as a view into the combined buffer
37
+ const {ArrayType, length} = getAccessorArrayTypeAndLength(accessor, bufferView);
38
+ const byteOffset = bufferView.byteOffset + accessor.byteOffset;
39
+ return new ArrayType(arrayBuffer, byteOffset, length);
40
+ }
41
+ */
@@ -3,3 +3,4 @@ export declare function getGLTFAccessors(attributes: any): {
3
3
  [key: string]: GLTFAccessor;
4
4
  };
5
5
  export declare function getGLTFAccessor(attribute: any): GLTFAccessor;
6
+ //# sourceMappingURL=gltf-attribute-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gltf-attribute-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/gltf-utils/gltf-attribute-utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,qBAAqB,CAAC;AAOtD,wBAAgB,gBAAgB,CAAC,UAAU,KAAA,GAAG;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,CAAA;CAAC,CAU1E;AAKD,wBAAgB,eAAe,CAAC,SAAS,KAAA,gBAmBxC"}
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getGLTFAccessor = exports.getGLTFAccessors = void 0;
4
+ // TODO - remove
5
+ const gltf_utils_1 = require("./gltf-utils");
6
+ // Returns a fresh attributes object with glTF-standardized attributes names
7
+ // Attributes that cannot be identified will not be included
8
+ // Removes `indices` if present, as it should be stored separately from the attributes
9
+ function getGLTFAccessors(attributes) {
10
+ const accessors = {};
11
+ for (const name in attributes) {
12
+ const attribute = attributes[name];
13
+ if (name !== 'indices') {
14
+ const glTFAccessor = getGLTFAccessor(attribute);
15
+ accessors[name] = glTFAccessor;
16
+ }
17
+ }
18
+ return accessors;
19
+ }
20
+ exports.getGLTFAccessors = getGLTFAccessors;
21
+ // Fix up a single accessor.
22
+ // Input: typed array or a partial accessor object
23
+ // Return: accessor object
24
+ function getGLTFAccessor(attribute) {
25
+ const { buffer, size, count } = getAccessorData(attribute);
26
+ const glTFAccessor = {
27
+ // glTF Accessor values
28
+ // TODO: Instead of a bufferView index we could have an actual buffer (typed array)
29
+ // bufferView: null,
30
+ // TODO: Deprecate `value` in favor of bufferView?
31
+ // @ts-ignore
32
+ value: buffer,
33
+ size,
34
+ byteOffset: 0,
35
+ count,
36
+ type: (0, gltf_utils_1.getAccessorTypeFromSize)(size),
37
+ componentType: (0, gltf_utils_1.getComponentTypeFromArray)(buffer)
38
+ };
39
+ return glTFAccessor;
40
+ }
41
+ exports.getGLTFAccessor = getGLTFAccessor;
42
+ // export function getGLTFAttribute(data, gltfAttributeName): GLTFAccessor {
43
+ // return data.attributes[data.glTFAttributeMap[gltfAttributeName]];
44
+ // }
45
+ function getAccessorData(attribute) {
46
+ let buffer = attribute;
47
+ let size = 1;
48
+ let count = 0;
49
+ if (attribute && attribute.value) {
50
+ buffer = attribute.value;
51
+ size = attribute.size || 1;
52
+ }
53
+ if (buffer) {
54
+ if (!ArrayBuffer.isView(buffer)) {
55
+ buffer = toTypedArray(buffer, Float32Array);
56
+ }
57
+ count = buffer.length / size;
58
+ }
59
+ return { buffer, size, count };
60
+ }
61
+ // Convert non-typed arrays to arrays of specified format
62
+ function toTypedArray(array, ArrayType, convertTypedArrays = false) {
63
+ if (!array) {
64
+ return null;
65
+ }
66
+ if (Array.isArray(array)) {
67
+ return new ArrayType(array);
68
+ }
69
+ if (convertTypedArrays && !(array instanceof ArrayType)) {
70
+ return new ArrayType(array);
71
+ }
72
+ return array;
73
+ }
@@ -1,3 +1,4 @@
1
1
  export declare function getBytesFromComponentType(componentType: any): any;
2
2
  export declare function getSizeFromAccessorType(type: any): any;
3
3
  export declare function getGLEnumFromSamplerParameter(parameter: any): any;
4
+ //# sourceMappingURL=gltf-constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gltf-constants.d.ts","sourceRoot":"","sources":["../../../src/lib/gltf-utils/gltf-constants.ts"],"names":[],"mappings":"AAqBA,wBAAgB,yBAAyB,CAAC,aAAa,KAAA,OAEtD;AAED,wBAAgB,uBAAuB,CAAC,IAAI,KAAA,OAE3C;AAED,wBAAgB,6BAA6B,CAAC,SAAS,KAAA,OActD"}
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getGLEnumFromSamplerParameter = exports.getSizeFromAccessorType = exports.getBytesFromComponentType = void 0;
4
+ const COMPONENTS = {
5
+ SCALAR: 1,
6
+ VEC2: 2,
7
+ VEC3: 3,
8
+ VEC4: 4,
9
+ MAT2: 4,
10
+ MAT3: 9,
11
+ MAT4: 16
12
+ };
13
+ const BYTES = {
14
+ 5120: 1,
15
+ 5121: 1,
16
+ 5122: 2,
17
+ 5123: 2,
18
+ 5125: 4,
19
+ 5126: 4 // FLOAT
20
+ };
21
+ // ENUM LOOKUP
22
+ function getBytesFromComponentType(componentType) {
23
+ return BYTES[componentType];
24
+ }
25
+ exports.getBytesFromComponentType = getBytesFromComponentType;
26
+ function getSizeFromAccessorType(type) {
27
+ return COMPONENTS[type];
28
+ }
29
+ exports.getSizeFromAccessorType = getSizeFromAccessorType;
30
+ function getGLEnumFromSamplerParameter(parameter) {
31
+ const GL_TEXTURE_MAG_FILTER = 0x2800;
32
+ const GL_TEXTURE_MIN_FILTER = 0x2801;
33
+ const GL_TEXTURE_WRAP_S = 0x2802;
34
+ const GL_TEXTURE_WRAP_T = 0x2803;
35
+ const PARAMETER_MAP = {
36
+ magFilter: GL_TEXTURE_MAG_FILTER,
37
+ minFilter: GL_TEXTURE_MIN_FILTER,
38
+ wrapS: GL_TEXTURE_WRAP_S,
39
+ wrapT: GL_TEXTURE_WRAP_T
40
+ };
41
+ return PARAMETER_MAP[parameter];
42
+ }
43
+ exports.getGLEnumFromSamplerParameter = getGLEnumFromSamplerParameter;
@@ -5,3 +5,4 @@ export declare function getAccessorArrayTypeAndLength(accessor: any, bufferView:
5
5
  length: number;
6
6
  byteLength: number;
7
7
  };
8
+ //# sourceMappingURL=gltf-utils.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAccessorArrayTypeAndLength = exports.getComponentTypeFromArray = exports.getAccessorTypeFromSize = void 0;
4
+ const assert_1 = require("../utils/assert");
5
+ const TYPES = ['SCALAR', 'VEC2', 'VEC3', 'VEC4'];
6
+ const ARRAY_CONSTRUCTOR_TO_WEBGL_CONSTANT = [
7
+ [Int8Array, 5120],
8
+ [Uint8Array, 5121],
9
+ [Int16Array, 5122],
10
+ [Uint16Array, 5123],
11
+ [Uint32Array, 5125],
12
+ [Float32Array, 5126],
13
+ [Float64Array, 5130]
14
+ ];
15
+ const ARRAY_TO_COMPONENT_TYPE = new Map(ARRAY_CONSTRUCTOR_TO_WEBGL_CONSTANT);
16
+ const ATTRIBUTE_TYPE_TO_COMPONENTS = {
17
+ SCALAR: 1,
18
+ VEC2: 2,
19
+ VEC3: 3,
20
+ VEC4: 4,
21
+ MAT2: 4,
22
+ MAT3: 9,
23
+ MAT4: 16
24
+ };
25
+ const ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE = {
26
+ 5120: 1,
27
+ 5121: 1,
28
+ 5122: 2,
29
+ 5123: 2,
30
+ 5125: 4,
31
+ 5126: 4
32
+ };
33
+ const ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY = {
34
+ 5120: Int8Array,
35
+ 5121: Uint8Array,
36
+ 5122: Int16Array,
37
+ 5123: Uint16Array,
38
+ 5125: Uint32Array,
39
+ 5126: Float32Array
40
+ };
41
+ function getAccessorTypeFromSize(size) {
42
+ const type = TYPES[size - 1];
43
+ return type || TYPES[0];
44
+ }
45
+ exports.getAccessorTypeFromSize = getAccessorTypeFromSize;
46
+ function getComponentTypeFromArray(typedArray) {
47
+ const componentType = ARRAY_TO_COMPONENT_TYPE.get(typedArray.constructor);
48
+ if (!componentType) {
49
+ throw new Error('Illegal typed array');
50
+ }
51
+ return componentType;
52
+ }
53
+ exports.getComponentTypeFromArray = getComponentTypeFromArray;
54
+ function getAccessorArrayTypeAndLength(accessor, bufferView) {
55
+ const ArrayType = ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY[accessor.componentType];
56
+ const components = ATTRIBUTE_TYPE_TO_COMPONENTS[accessor.type];
57
+ const bytesPerComponent = ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE[accessor.componentType];
58
+ const length = accessor.count * components;
59
+ const byteLength = accessor.count * components * bytesPerComponent;
60
+ (0, assert_1.assert)(byteLength >= 0 && byteLength <= bufferView.byteLength);
61
+ return { ArrayType, length, byteLength };
62
+ }
63
+ exports.getAccessorArrayTypeAndLength = getAccessorArrayTypeAndLength;
@@ -1 +1,2 @@
1
1
  export declare function resolveUrl(url: any, options: any): any;
2
+ //# sourceMappingURL=resolve-url.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-url.d.ts","sourceRoot":"","sources":["../../../src/lib/gltf-utils/resolve-url.ts"],"names":[],"mappings":"AAEA,wBAAgB,UAAU,CAAC,GAAG,KAAA,EAAE,OAAO,KAAA,OAWtC"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveUrl = void 0;
4
+ // Resolves a relative url against a baseUrl
5
+ // If url is absolute, return it unchanged
6
+ function resolveUrl(url, options) {
7
+ // TODO: Use better logic to handle all protocols plus not delay on data
8
+ const absolute = url.startsWith('data:') || url.startsWith('http:') || url.startsWith('https:');
9
+ if (absolute) {
10
+ return url;
11
+ }
12
+ const baseUrl = options.baseUri || options.uri;
13
+ if (!baseUrl) {
14
+ throw new Error(`'baseUri' must be provided to resolve relative url ${url}`);
15
+ }
16
+ return baseUrl.substr(0, baseUrl.lastIndexOf('/') + 1) + url;
17
+ }
18
+ exports.resolveUrl = resolveUrl;
@@ -5,3 +5,4 @@ export declare type GLBParseOptions = {
5
5
  };
6
6
  export declare function isGLB(arrayBuffer: ArrayBuffer, byteOffset?: number, options?: GLBParseOptions): boolean;
7
7
  export default function parseGLBSync(glb: GLB, arrayBuffer: ArrayBuffer, byteOffset?: number, options?: GLBParseOptions): number;
8
+ //# sourceMappingURL=parse-glb.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-glb.d.ts","sourceRoot":"","sources":["../../../src/lib/parsers/parse-glb.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,GAAG,EAAC,MAAM,oBAAoB,CAAC;AAG5C,oBAAY,eAAe,GAAG;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC;AAyBF,wBAAgB,KAAK,CACnB,WAAW,EAAE,WAAW,EACxB,UAAU,GAAE,MAAU,EACtB,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAMT;AAED,MAAM,CAAC,OAAO,UAAU,YAAY,CAClC,GAAG,EAAE,GAAG,EACR,WAAW,EAAE,WAAW,EACxB,UAAU,GAAE,MAAU,EACtB,OAAO,GAAE,eAAoB,UAqC9B"}
@@ -0,0 +1,141 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isGLB = void 0;
4
+ const loader_utils_1 = require("@loaders.gl/loader-utils");
5
+ const MAGIC_glTF = 0x676c5446; // glTF in Big-Endian ASCII
6
+ const GLB_FILE_HEADER_SIZE = 12;
7
+ const GLB_CHUNK_HEADER_SIZE = 8;
8
+ const GLB_CHUNK_TYPE_JSON = 0x4e4f534a;
9
+ const GLB_CHUNK_TYPE_BIN = 0x004e4942;
10
+ const GLB_CHUNK_TYPE_JSON_XVIZ_DEPRECATED = 0; // DEPRECATED - Backward compatibility for old xviz files
11
+ const GLB_CHUNK_TYPE_BIX_XVIZ_DEPRECATED = 1; // DEPRECATED - Backward compatibility for old xviz files
12
+ const GLB_V1_CONTENT_FORMAT_JSON = 0x0;
13
+ const LE = true; // Binary GLTF is little endian.
14
+ function getMagicString(dataView, byteOffset = 0) {
15
+ return `\
16
+ ${String.fromCharCode(dataView.getUint8(byteOffset + 0))}\
17
+ ${String.fromCharCode(dataView.getUint8(byteOffset + 1))}\
18
+ ${String.fromCharCode(dataView.getUint8(byteOffset + 2))}\
19
+ ${String.fromCharCode(dataView.getUint8(byteOffset + 3))}`;
20
+ }
21
+ // Check if a data view is a GLB
22
+ function isGLB(arrayBuffer, byteOffset = 0, options = {}) {
23
+ const dataView = new DataView(arrayBuffer);
24
+ // Check that GLB Header starts with the magic number
25
+ const { magic = MAGIC_glTF } = options;
26
+ const magic1 = dataView.getUint32(byteOffset, false);
27
+ return magic1 === magic || magic1 === MAGIC_glTF;
28
+ }
29
+ exports.isGLB = isGLB;
30
+ function parseGLBSync(glb, arrayBuffer, byteOffset = 0, options = {}) {
31
+ // Check that GLB Header starts with the magic number
32
+ const dataView = new DataView(arrayBuffer);
33
+ // Compare format with GLBLoader documentation
34
+ const type = getMagicString(dataView, byteOffset + 0);
35
+ const version = dataView.getUint32(byteOffset + 4, LE); // Version 2 of binary glTF container format
36
+ const byteLength = dataView.getUint32(byteOffset + 8, LE); // Total byte length of binary file
37
+ Object.assign(glb, {
38
+ // Put less important stuff in a header, to avoid clutter
39
+ header: {
40
+ byteOffset,
41
+ byteLength,
42
+ hasBinChunk: false
43
+ },
44
+ type,
45
+ version,
46
+ json: {},
47
+ binChunks: []
48
+ });
49
+ byteOffset += GLB_FILE_HEADER_SIZE;
50
+ switch (glb.version) {
51
+ case 1:
52
+ // eslint-disable-next-line
53
+ return parseGLBV1(glb, dataView, byteOffset);
54
+ case 2:
55
+ // eslint-disable-next-line
56
+ return parseGLBV2(glb, dataView, byteOffset, (options = {}));
57
+ default:
58
+ throw new Error(`Invalid GLB version ${glb.version}. Only supports v1 and v2.`);
59
+ }
60
+ }
61
+ exports.default = parseGLBSync;
62
+ function parseGLBV1(glb, dataView, byteOffset) {
63
+ // Sanity: ensure file is big enough to hold at least the headers
64
+ (0, loader_utils_1.assert)(glb.header.byteLength > GLB_FILE_HEADER_SIZE + GLB_CHUNK_HEADER_SIZE);
65
+ // Explanation of GLB structure:
66
+ // https://cloud.githubusercontent.com/assets/3479527/22600725/36b87122-ea55-11e6-9d40-6fd42819fcab.png
67
+ const contentLength = dataView.getUint32(byteOffset + 0, LE); // Byte length of chunk
68
+ const contentFormat = dataView.getUint32(byteOffset + 4, LE); // Chunk format as uint32
69
+ byteOffset += GLB_CHUNK_HEADER_SIZE;
70
+ // GLB v1 only supports a single chunk type
71
+ (0, loader_utils_1.assert)(contentFormat === GLB_V1_CONTENT_FORMAT_JSON);
72
+ parseJSONChunk(glb, dataView, byteOffset, contentLength);
73
+ // No need to call the function padToBytes() from parseJSONChunk()
74
+ byteOffset += contentLength;
75
+ byteOffset += parseBINChunk(glb, dataView, byteOffset, glb.header.byteLength);
76
+ return byteOffset;
77
+ }
78
+ function parseGLBV2(glb, dataView, byteOffset, options) {
79
+ // Sanity: ensure file is big enough to hold at least the first chunk header
80
+ (0, loader_utils_1.assert)(glb.header.byteLength > GLB_FILE_HEADER_SIZE + GLB_CHUNK_HEADER_SIZE);
81
+ parseGLBChunksSync(glb, dataView, byteOffset, options);
82
+ return byteOffset + glb.header.byteLength;
83
+ }
84
+ function parseGLBChunksSync(glb, dataView, byteOffset, options) {
85
+ // Per spec we must iterate over chunks, ignoring all except JSON and BIN
86
+ // Iterate as long as there is space left for another chunk header
87
+ while (byteOffset + 8 <= glb.header.byteLength) {
88
+ const chunkLength = dataView.getUint32(byteOffset + 0, LE); // Byte length of chunk
89
+ const chunkFormat = dataView.getUint32(byteOffset + 4, LE); // Chunk format as uint32
90
+ byteOffset += GLB_CHUNK_HEADER_SIZE;
91
+ // Per spec we must iterate over chunks, ignoring all except JSON and BIN
92
+ switch (chunkFormat) {
93
+ case GLB_CHUNK_TYPE_JSON:
94
+ parseJSONChunk(glb, dataView, byteOffset, chunkLength);
95
+ break;
96
+ case GLB_CHUNK_TYPE_BIN:
97
+ parseBINChunk(glb, dataView, byteOffset, chunkLength);
98
+ break;
99
+ // Backward compatibility for very old xviz files
100
+ case GLB_CHUNK_TYPE_JSON_XVIZ_DEPRECATED:
101
+ if (!options.strict) {
102
+ parseJSONChunk(glb, dataView, byteOffset, chunkLength);
103
+ }
104
+ break;
105
+ case GLB_CHUNK_TYPE_BIX_XVIZ_DEPRECATED:
106
+ if (!options.strict) {
107
+ parseBINChunk(glb, dataView, byteOffset, chunkLength);
108
+ }
109
+ break;
110
+ default:
111
+ // Ignore, per spec
112
+ // console.warn(`Unknown GLB chunk type`); // eslint-disable-line
113
+ break;
114
+ }
115
+ byteOffset += (0, loader_utils_1.padToNBytes)(chunkLength, 4);
116
+ }
117
+ return byteOffset;
118
+ }
119
+ // Parse a GLB JSON chunk
120
+ function parseJSONChunk(glb, dataView, byteOffset, chunkLength) {
121
+ // 1. Create a "view" of the binary encoded JSON data inside the GLB
122
+ const jsonChunk = new Uint8Array(dataView.buffer, byteOffset, chunkLength);
123
+ // 2. Decode the JSON binary array into clear text
124
+ const textDecoder = new TextDecoder('utf8');
125
+ const jsonText = textDecoder.decode(jsonChunk);
126
+ // 3. Parse the JSON text into a JavaScript data structure
127
+ glb.json = JSON.parse(jsonText);
128
+ return (0, loader_utils_1.padToNBytes)(chunkLength, 4);
129
+ }
130
+ // Parse a GLB BIN chunk
131
+ function parseBINChunk(glb, dataView, byteOffset, chunkLength) {
132
+ // Note: BIN chunk can be optional
133
+ glb.header.hasBinChunk = true;
134
+ glb.binChunks.push({
135
+ byteOffset,
136
+ byteLength: chunkLength,
137
+ arrayBuffer: dataView.buffer
138
+ // TODO - copy, or create typed array view?
139
+ });
140
+ return (0, loader_utils_1.padToNBytes)(chunkLength, 4);
141
+ }
@@ -10,4 +10,5 @@ export declare type GLTFParseOptions = {
10
10
  excludeExtensions?: string[];
11
11
  };
12
12
  export declare function isGLTF(arrayBuffer: any, options?: any): boolean;
13
- export declare function parseGLTF(gltf: GLTFWithBuffers, arrayBufferOrString: any, byteOffset: number | undefined, options: GLTFLoaderOptions, context: LoaderContext): Promise<any>;
13
+ export declare function parseGLTF(gltf: GLTFWithBuffers, arrayBufferOrString: any, byteOffset: number | undefined, options: GLTFLoaderOptions, context: LoaderContext): Promise<Record<string, any>>;
14
+ //# sourceMappingURL=parse-gltf.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-gltf.d.ts","sourceRoot":"","sources":["../../../src/lib/parsers/parse-gltf.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAE5D,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,mBAAmB,CAAC;AAEzD,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,qBAAqB,CAAC;AAYzD,oBAAY,gBAAgB,GAAG;IAC7B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC9B,CAAC;AAMF,wBAAgB,MAAM,CAAC,WAAW,KAAA,EAAE,OAAO,CAAC,KAAA,GAAG,OAAO,CAGrD;AAED,wBAAsB,SAAS,CAC7B,IAAI,EAAE,eAAe,EACrB,mBAAmB,KAAA,EACnB,UAAU,oBAAI,EACd,OAAO,EAAE,iBAAiB,EAC1B,OAAO,EAAE,aAAa,gCA4BvB"}