@loaders.gl/gltf 3.1.0-alpha.5 → 3.1.0-beta.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/bundle.d.ts +1 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +4518 -0
- package/dist/es5/lib/api/normalize-gltf-v1.js +8 -3
- package/dist/es5/lib/api/normalize-gltf-v1.js.map +1 -1
- package/dist/es5/lib/api/post-process-gltf.js +30 -3
- package/dist/es5/lib/api/post-process-gltf.js.map +1 -1
- package/dist/es5/lib/encoders/encode-glb.js.map +1 -1
- package/dist/es5/lib/encoders/encode-gltf.js.map +1 -1
- package/dist/es5/lib/extensions/KHR_texture_basisu.js.map +1 -1
- package/dist/es5/lib/utils/assert.js.map +1 -1
- package/dist/es5/lib/utils/version.js +1 -1
- package/dist/es5/lib/utils/version.js.map +1 -1
- package/dist/esm/lib/api/normalize-gltf-v1.js +6 -3
- package/dist/esm/lib/api/normalize-gltf-v1.js.map +1 -1
- package/dist/esm/lib/api/post-process-gltf.js +30 -3
- package/dist/esm/lib/api/post-process-gltf.js.map +1 -1
- package/dist/esm/lib/encoders/encode-glb.js.map +1 -1
- package/dist/esm/lib/encoders/encode-gltf.js.map +1 -1
- package/dist/esm/lib/extensions/KHR_texture_basisu.js.map +1 -1
- package/dist/esm/lib/utils/assert.js.map +1 -1
- package/dist/esm/lib/utils/version.js +1 -1
- package/dist/esm/lib/utils/version.js.map +1 -1
- package/dist/glb-loader.d.ts +1 -0
- package/dist/glb-loader.d.ts.map +1 -0
- package/dist/glb-loader.js +39 -0
- package/dist/glb-writer.d.ts +1 -0
- package/dist/glb-writer.d.ts.map +1 -0
- package/dist/glb-writer.js +37 -0
- package/dist/gltf-loader.d.ts +2 -1
- package/dist/gltf-loader.d.ts.map +1 -0
- package/dist/gltf-loader.js +50 -0
- package/dist/gltf-writer.d.ts +1 -0
- package/dist/gltf-writer.d.ts.map +1 -0
- package/dist/gltf-writer.js +32 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/lib/api/gltf-extensions.d.ts +1 -0
- package/dist/lib/api/gltf-extensions.d.ts.map +1 -0
- package/dist/lib/api/gltf-extensions.js +75 -0
- package/dist/lib/api/gltf-scenegraph.d.ts +1 -0
- package/dist/lib/api/gltf-scenegraph.d.ts.map +1 -0
- package/dist/lib/api/gltf-scenegraph.js +553 -0
- package/dist/lib/api/normalize-gltf-v1.d.ts +2 -1
- package/dist/lib/api/normalize-gltf-v1.d.ts.map +1 -0
- package/dist/lib/api/normalize-gltf-v1.js +295 -0
- package/dist/lib/api/post-process-gltf.d.ts +2 -1
- package/dist/lib/api/post-process-gltf.d.ts.map +1 -0
- package/dist/lib/api/post-process-gltf.js +367 -0
- package/dist/lib/encoders/encode-glb.d.ts +1 -0
- package/dist/lib/encoders/encode-glb.d.ts.map +1 -0
- package/dist/lib/encoders/encode-glb.js +61 -0
- package/dist/lib/encoders/encode-gltf.d.ts +2 -1
- package/dist/lib/encoders/encode-gltf.d.ts.map +1 -0
- package/dist/lib/encoders/encode-gltf.js +27 -0
- package/dist/lib/extensions/EXT_meshopt_compression.d.ts +1 -0
- package/dist/lib/extensions/EXT_meshopt_compression.d.ts.map +1 -0
- package/dist/lib/extensions/EXT_meshopt_compression.js +54 -0
- package/dist/lib/extensions/EXT_texture_webp.d.ts +1 -0
- package/dist/lib/extensions/EXT_texture_webp.d.ts.map +1 -0
- package/dist/lib/extensions/EXT_texture_webp.js +38 -0
- package/dist/lib/extensions/KHR_binary_gltf.d.ts +1 -0
- package/dist/lib/extensions/KHR_binary_gltf.d.ts.map +1 -0
- package/dist/lib/extensions/KHR_binary_gltf.js +42 -0
- package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts +1 -0
- package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts.map +1 -0
- package/dist/lib/extensions/KHR_draco_mesh_compression.js +141 -0
- package/dist/lib/extensions/KHR_texture_basisu.d.ts +1 -0
- package/dist/lib/extensions/KHR_texture_basisu.d.ts.map +1 -0
- package/dist/lib/extensions/KHR_texture_basisu.js +31 -0
- package/dist/lib/extensions/deprecated/KHR_lights_punctual.d.ts +1 -0
- package/dist/lib/extensions/deprecated/KHR_lights_punctual.d.ts.map +1 -0
- package/dist/lib/extensions/deprecated/KHR_lights_punctual.js +62 -0
- package/dist/lib/extensions/deprecated/KHR_materials_unlit.d.ts +1 -0
- package/dist/lib/extensions/deprecated/KHR_materials_unlit.d.ts.map +1 -0
- package/dist/lib/extensions/deprecated/KHR_materials_unlit.js +47 -0
- package/dist/lib/extensions/deprecated/KHR_techniques_webgl.d.ts +1 -0
- package/dist/lib/extensions/deprecated/KHR_techniques_webgl.d.ts.map +1 -0
- package/dist/lib/extensions/deprecated/KHR_techniques_webgl.js +81 -0
- package/dist/lib/gltf-utils/get-typed-array.d.ts +1 -0
- package/dist/lib/gltf-utils/get-typed-array.d.ts.map +1 -0
- package/dist/lib/gltf-utils/get-typed-array.js +41 -0
- package/dist/lib/gltf-utils/gltf-attribute-utils.d.ts +1 -0
- package/dist/lib/gltf-utils/gltf-attribute-utils.d.ts.map +1 -0
- package/dist/lib/gltf-utils/gltf-attribute-utils.js +73 -0
- package/dist/lib/gltf-utils/gltf-constants.d.ts +1 -0
- package/dist/lib/gltf-utils/gltf-constants.d.ts.map +1 -0
- package/dist/lib/gltf-utils/gltf-constants.js +43 -0
- package/dist/lib/gltf-utils/gltf-utils.d.ts +1 -0
- package/dist/lib/gltf-utils/gltf-utils.d.ts.map +1 -0
- package/dist/lib/gltf-utils/gltf-utils.js +63 -0
- package/dist/lib/gltf-utils/resolve-url.d.ts +1 -0
- package/dist/lib/gltf-utils/resolve-url.d.ts.map +1 -0
- package/dist/lib/gltf-utils/resolve-url.js +18 -0
- package/dist/lib/parsers/parse-glb.d.ts +1 -0
- package/dist/lib/parsers/parse-glb.d.ts.map +1 -0
- package/dist/lib/parsers/parse-glb.js +141 -0
- package/dist/lib/parsers/parse-gltf.d.ts +2 -1
- package/dist/lib/parsers/parse-gltf.d.ts.map +1 -0
- package/dist/lib/parsers/parse-gltf.js +189 -0
- package/dist/lib/types/glb-types.d.ts +1 -0
- package/dist/lib/types/glb-types.d.ts.map +1 -0
- package/dist/lib/types/glb-types.js +2 -0
- package/dist/lib/types/gltf-json-schema.d.ts +1 -0
- package/dist/lib/types/gltf-json-schema.d.ts.map +1 -0
- package/dist/lib/types/gltf-json-schema.js +4 -0
- package/dist/lib/types/gltf-postprocessed-schema.d.ts +1 -0
- package/dist/lib/types/gltf-postprocessed-schema.d.ts.map +1 -0
- package/dist/lib/types/gltf-postprocessed-schema.js +4 -0
- package/dist/lib/types/gltf-types.d.ts +1 -0
- package/dist/lib/types/gltf-types.d.ts.map +1 -0
- package/dist/lib/types/gltf-types.js +3 -0
- package/dist/lib/utils/assert.d.ts +2 -1
- package/dist/lib/utils/assert.d.ts.map +1 -0
- package/dist/lib/utils/assert.js +12 -0
- package/dist/lib/utils/version.d.ts +2 -1
- package/dist/lib/utils/version.d.ts.map +1 -0
- package/dist/lib/utils/version.js +7 -0
- package/dist/meshopt/meshopt-decoder.d.ts +1 -0
- package/dist/meshopt/meshopt-decoder.d.ts.map +1 -0
- package/dist/meshopt/meshopt-decoder.js +118 -0
- package/dist/webp/webp.d.ts +1 -0
- package/dist/webp/webp.d.ts.map +1 -0
- package/dist/webp/webp.js +38 -0
- package/package.json +8 -9
- package/src/lib/api/{normalize-gltf-v1.js → normalize-gltf-v1.ts} +18 -16
- package/src/lib/api/{post-process-gltf.js → post-process-gltf.ts} +41 -3
- package/src/lib/encoders/{encode-glb.js → encode-glb.ts} +0 -0
- package/src/lib/encoders/{encode-gltf.js → encode-gltf.ts} +0 -0
- package/src/lib/extensions/KHR_texture_basisu.ts +2 -2
- package/src/lib/utils/{assert.js → assert.ts} +1 -1
- package/src/lib/utils/{version.js → version.ts} +0 -0
- package/dist/dist.min.js +0 -2
- 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
|
+
}
|
|
@@ -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
|
+
*/
|
|
@@ -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
|
+
}
|
|
@@ -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;
|
|
@@ -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;
|
|
@@ -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"}
|