@loaders.gl/gltf 3.3.0-alpha.4 → 3.3.0-alpha.6
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 +104 -124
- package/dist/es5/bundle.js +0 -1
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/glb-loader.js +2 -13
- package/dist/es5/glb-loader.js.map +1 -1
- package/dist/es5/glb-writer.js +3 -6
- package/dist/es5/glb-writer.js.map +1 -1
- package/dist/es5/gltf-loader.js +11 -23
- package/dist/es5/gltf-loader.js.map +1 -1
- package/dist/es5/gltf-writer.js +2 -5
- package/dist/es5/gltf-writer.js.map +1 -1
- package/dist/es5/index.js +10 -17
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/api/gltf-extensions.js +14 -48
- package/dist/es5/lib/api/gltf-extensions.js.map +1 -1
- package/dist/es5/lib/api/gltf-scenegraph.js +113 -96
- package/dist/es5/lib/api/gltf-scenegraph.js.map +1 -1
- package/dist/es5/lib/api/normalize-gltf-v1.js +32 -70
- package/dist/es5/lib/api/normalize-gltf-v1.js.map +1 -1
- package/dist/es5/lib/api/post-process-gltf.js +26 -89
- package/dist/es5/lib/api/post-process-gltf.js.map +1 -1
- package/dist/es5/lib/encoders/encode-glb.js +10 -8
- package/dist/es5/lib/encoders/encode-glb.js.map +1 -1
- package/dist/es5/lib/encoders/encode-gltf.js +3 -6
- package/dist/es5/lib/encoders/encode-gltf.js.map +1 -1
- package/dist/es5/lib/extensions/EXT_meshopt_compression.js +2 -28
- package/dist/es5/lib/extensions/EXT_meshopt_compression.js.map +1 -1
- package/dist/es5/lib/extensions/EXT_texture_webp.js +5 -18
- package/dist/es5/lib/extensions/EXT_texture_webp.js.map +1 -1
- package/dist/es5/lib/extensions/KHR_binary_gltf.js +5 -12
- package/dist/es5/lib/extensions/KHR_binary_gltf.js.map +1 -1
- package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js +11 -79
- package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js.map +1 -1
- package/dist/es5/lib/extensions/KHR_texture_basisu.js +5 -14
- package/dist/es5/lib/extensions/KHR_texture_basisu.js.map +1 -1
- package/dist/es5/lib/extensions/KHR_texture_transform.js +17 -72
- package/dist/es5/lib/extensions/KHR_texture_transform.js.map +1 -1
- package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js +0 -21
- package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -1
- package/dist/es5/lib/extensions/deprecated/KHR_lights_punctual.js +0 -24
- package/dist/es5/lib/extensions/deprecated/KHR_lights_punctual.js.map +1 -1
- package/dist/es5/lib/extensions/deprecated/KHR_materials_unlit.js +2 -19
- package/dist/es5/lib/extensions/deprecated/KHR_materials_unlit.js.map +1 -1
- package/dist/es5/lib/extensions/deprecated/KHR_techniques_webgl.js +11 -29
- package/dist/es5/lib/extensions/deprecated/KHR_techniques_webgl.js.map +1 -1
- package/dist/es5/lib/gltf-utils/get-typed-array.js +1 -1
- package/dist/es5/lib/gltf-utils/get-typed-array.js.map +1 -1
- package/dist/es5/lib/gltf-utils/gltf-attribute-utils.js +5 -17
- package/dist/es5/lib/gltf-utils/gltf-attribute-utils.js.map +1 -1
- package/dist/es5/lib/gltf-utils/gltf-constants.js +3 -4
- package/dist/es5/lib/gltf-utils/gltf-constants.js.map +1 -1
- package/dist/es5/lib/gltf-utils/gltf-utils.js +1 -8
- package/dist/es5/lib/gltf-utils/gltf-utils.js.map +1 -1
- package/dist/es5/lib/gltf-utils/resolve-url.js +0 -5
- package/dist/es5/lib/gltf-utils/resolve-url.js.map +1 -1
- package/dist/es5/lib/parsers/parse-glb.js +11 -17
- package/dist/es5/lib/parsers/parse-glb.js.map +1 -1
- package/dist/es5/lib/parsers/parse-gltf.js +12 -73
- package/dist/es5/lib/parsers/parse-gltf.js.map +1 -1
- package/dist/es5/lib/types/glb-types.js.map +1 -1
- package/dist/es5/lib/types/gltf-json-schema.js.map +1 -1
- package/dist/es5/lib/types/gltf-postprocessed-schema.js.map +1 -1
- package/dist/es5/lib/types/gltf-types.js.map +1 -1
- package/dist/es5/lib/utils/assert.js +0 -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/es5/meshopt/meshopt-decoder.js +10 -47
- package/dist/es5/meshopt/meshopt-decoder.js.map +1 -1
- package/dist/es5/webp/webp.js +3 -19
- package/dist/es5/webp/webp.js.map +1 -1
- package/dist/esm/bundle.js +1 -1
- package/dist/esm/bundle.js.map +1 -1
- package/dist/esm/glb-loader.js +0 -1
- package/dist/esm/glb-loader.js.map +1 -1
- package/dist/esm/glb-writer.js +3 -1
- package/dist/esm/glb-writer.js.map +1 -1
- package/dist/esm/gltf-loader.js +9 -3
- package/dist/esm/gltf-loader.js.map +1 -1
- package/dist/esm/gltf-writer.js +3 -2
- package/dist/esm/gltf-writer.js.map +1 -1
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/api/gltf-extensions.js +16 -9
- package/dist/esm/lib/api/gltf-extensions.js.map +1 -1
- package/dist/esm/lib/api/gltf-scenegraph.js +27 -68
- package/dist/esm/lib/api/gltf-scenegraph.js.map +1 -1
- package/dist/esm/lib/api/normalize-gltf-v1.js +3 -34
- package/dist/esm/lib/api/normalize-gltf-v1.js.map +1 -1
- package/dist/esm/lib/api/post-process-gltf.js +26 -93
- package/dist/esm/lib/api/post-process-gltf.js.map +1 -1
- package/dist/esm/lib/encoders/encode-glb.js +9 -2
- package/dist/esm/lib/encoders/encode-glb.js.map +1 -1
- package/dist/esm/lib/encoders/encode-gltf.js +6 -4
- package/dist/esm/lib/encoders/encode-gltf.js.map +1 -1
- package/dist/esm/lib/extensions/EXT_meshopt_compression.js +5 -6
- package/dist/esm/lib/extensions/EXT_meshopt_compression.js.map +1 -1
- package/dist/esm/lib/extensions/EXT_texture_webp.js +4 -6
- package/dist/esm/lib/extensions/EXT_texture_webp.js.map +1 -1
- package/dist/esm/lib/extensions/KHR_binary_gltf.js +3 -2
- package/dist/esm/lib/extensions/KHR_binary_gltf.js.map +1 -1
- package/dist/esm/lib/extensions/KHR_draco_mesh_compression.js +18 -17
- package/dist/esm/lib/extensions/KHR_draco_mesh_compression.js.map +1 -1
- package/dist/esm/lib/extensions/KHR_texture_basisu.js +4 -3
- package/dist/esm/lib/extensions/KHR_texture_basisu.js.map +1 -1
- package/dist/esm/lib/extensions/KHR_texture_transform.js +8 -34
- package/dist/esm/lib/extensions/KHR_texture_transform.js.map +1 -1
- package/dist/esm/lib/extensions/deprecated/EXT_feature_metadata.js +2 -13
- package/dist/esm/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -1
- package/dist/esm/lib/extensions/deprecated/KHR_lights_punctual.js +4 -4
- package/dist/esm/lib/extensions/deprecated/KHR_lights_punctual.js.map +1 -1
- package/dist/esm/lib/extensions/deprecated/KHR_materials_unlit.js +3 -2
- package/dist/esm/lib/extensions/deprecated/KHR_materials_unlit.js.map +1 -1
- package/dist/esm/lib/extensions/deprecated/KHR_techniques_webgl.js +10 -10
- package/dist/esm/lib/extensions/deprecated/KHR_techniques_webgl.js.map +1 -1
- package/dist/esm/lib/gltf-utils/get-typed-array.js +4 -0
- package/dist/esm/lib/gltf-utils/get-typed-array.js.map +1 -1
- package/dist/esm/lib/gltf-utils/gltf-attribute-utils.js +7 -11
- package/dist/esm/lib/gltf-utils/gltf-attribute-utils.js.map +1 -1
- package/dist/esm/lib/gltf-utils/gltf-constants.js +1 -0
- package/dist/esm/lib/gltf-utils/gltf-constants.js.map +1 -1
- package/dist/esm/lib/gltf-utils/gltf-utils.js +0 -2
- package/dist/esm/lib/gltf-utils/gltf-utils.js.map +1 -1
- package/dist/esm/lib/gltf-utils/resolve-url.js +1 -4
- package/dist/esm/lib/gltf-utils/resolve-url.js.map +1 -1
- package/dist/esm/lib/parsers/parse-glb.js +19 -16
- package/dist/esm/lib/parsers/parse-glb.js.map +1 -1
- package/dist/esm/lib/parsers/parse-gltf.js +11 -16
- package/dist/esm/lib/parsers/parse-gltf.js.map +1 -1
- package/dist/esm/lib/types/glb-types.js.map +1 -1
- package/dist/esm/lib/types/gltf-json-schema.js.map +1 -1
- package/dist/esm/lib/types/gltf-postprocessed-schema.js.map +1 -1
- package/dist/esm/lib/types/gltf-types.js.map +1 -1
- package/dist/esm/lib/utils/assert.js +1 -0
- package/dist/esm/lib/utils/assert.js.map +1 -1
- package/dist/esm/lib/utils/version.js +2 -1
- package/dist/esm/lib/utils/version.js.map +1 -1
- package/dist/esm/meshopt/meshopt-decoder.js +11 -15
- package/dist/esm/meshopt/meshopt-decoder.js.map +1 -1
- package/dist/esm/webp/webp.js +3 -5
- package/dist/esm/webp/webp.js.map +1 -1
- package/dist/lib/api/gltf-extensions.js +5 -1
- package/dist/lib/api/normalize-gltf-v1.js +5 -1
- package/dist/lib/parsers/parse-gltf.js +5 -1
- package/package.json +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"KHR_texture_basisu.js","names":["GLTFScenegraph","KHR_TEXTURE_BASISU","name","preprocess","gltfData","options","scene","json","texture","textures","extension","getObjectExtension","source","removeObjectExtension","removeExtension"],"sources":["../../../../src/lib/extensions/KHR_texture_basisu.ts"],"sourcesContent":["// GLTF EXTENSION: KHR_texture_basisu\n// https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_basisu\n/* eslint-disable camelcase */\n\nimport type {GLTF, GLTF_KHR_texture_basisu} from '../types/gltf-types';\nimport type {GLTFLoaderOptions} from '../../gltf-loader';\n\nimport GLTFScenegraph from '../api/gltf-scenegraph';\n\nconst KHR_TEXTURE_BASISU = 'KHR_texture_basisu';\n\n/** Extension name */\nexport const name = KHR_TEXTURE_BASISU;\n\n/**\n * Replaces a texture source reference with the extension texture\n * Done in preprocess() to prevent load of default image\n */\nexport function preprocess(gltfData: {json: GLTF}, options: GLTFLoaderOptions): void {\n const scene = new GLTFScenegraph(gltfData);\n const {json} = scene;\n\n for (const texture of json.textures || []) {\n const extension = scene.getObjectExtension<GLTF_KHR_texture_basisu>(\n texture,\n KHR_TEXTURE_BASISU\n );\n if (extension) {\n texture.source = extension.source;\n }\n scene.removeObjectExtension(texture, KHR_TEXTURE_BASISU);\n }\n\n // Remove the top-level extension\n scene.removeExtension(KHR_TEXTURE_BASISU);\n}\n"],"mappings":";;AAOA,OAAOA,cAAc,MAAM,wBAAwB;AAEnD,MAAMC,kBAAkB,GAAG,oBAAoB;;AAG/C,OAAO,MAAMC,IAAI,GAAGD,kBAAkB;;AAMtC,OAAO,SAASE,UAAU,CAACC,QAAsB,EAAEC,OAA0B,EAAQ;EACnF,MAAMC,KAAK,GAAG,IAAIN,cAAc,CAACI,QAAQ,CAAC;EAC1C,MAAM;IAACG;EAAI,CAAC,GAAGD,KAAK;EAEpB,KAAK,MAAME,OAAO,IAAID,IAAI,CAACE,QAAQ,IAAI,EAAE,EAAE;IACzC,MAAMC,SAAS,GAAGJ,KAAK,CAACK,kBAAkB,CACxCH,OAAO,EACPP,kBAAkB,CACnB;IACD,IAAIS,SAAS,EAAE;MACbF,OAAO,CAACI,MAAM,GAAGF,SAAS,CAACE,MAAM;IACnC;IACAN,KAAK,CAACO,qBAAqB,CAACL,OAAO,EAAEP,kBAAkB,CAAC;EAC1D;;EAGAK,KAAK,CAACQ,eAAe,CAACb,kBAAkB,CAAC;AAC3C"}
|
|
@@ -1,22 +1,23 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
1
3
|
import { Vector3, Matrix3 } from '@math.gl/core';
|
|
2
4
|
import { getAccessorArrayTypeAndLength } from '../gltf-utils/gltf-utils';
|
|
3
5
|
import { BYTES, COMPONENTS } from '../gltf-utils/gltf-constants';
|
|
4
6
|
import GLTFScenegraph from '../api/gltf-scenegraph';
|
|
7
|
+
|
|
5
8
|
const EXT_MESHOPT_TRANSFORM = 'KHR_texture_transform';
|
|
6
9
|
export const name = EXT_MESHOPT_TRANSFORM;
|
|
7
10
|
const scratchVector = new Vector3();
|
|
8
11
|
const scratchRotationMatrix = new Matrix3();
|
|
9
12
|
const scratchScaleMatrix = new Matrix3();
|
|
13
|
+
|
|
10
14
|
export async function decode(gltfData, options) {
|
|
11
15
|
const gltfScenegraph = new GLTFScenegraph(gltfData);
|
|
12
16
|
const extension = gltfScenegraph.getExtension(EXT_MESHOPT_TRANSFORM);
|
|
13
|
-
|
|
14
17
|
if (!extension) {
|
|
15
18
|
return;
|
|
16
19
|
}
|
|
17
|
-
|
|
18
20
|
const materials = gltfData.json.materials || [];
|
|
19
|
-
|
|
20
21
|
for (let i = 0; i < materials.length; i++) {
|
|
21
22
|
transformTexCoords(i, gltfData);
|
|
22
23
|
}
|
|
@@ -24,35 +25,25 @@ export async function decode(gltfData, options) {
|
|
|
24
25
|
|
|
25
26
|
function transformTexCoords(materialIndex, gltfData) {
|
|
26
27
|
var _gltfData$json$materi, _material$pbrMetallic, _material$pbrMetallic2;
|
|
27
|
-
|
|
28
28
|
const processedTexCoords = [];
|
|
29
29
|
const material = (_gltfData$json$materi = gltfData.json.materials) === null || _gltfData$json$materi === void 0 ? void 0 : _gltfData$json$materi[materialIndex];
|
|
30
30
|
const baseColorTexture = material === null || material === void 0 ? void 0 : (_material$pbrMetallic = material.pbrMetallicRoughness) === null || _material$pbrMetallic === void 0 ? void 0 : _material$pbrMetallic.baseColorTexture;
|
|
31
|
-
|
|
32
31
|
if (baseColorTexture) {
|
|
33
32
|
transformPrimitives(gltfData, materialIndex, baseColorTexture, processedTexCoords);
|
|
34
33
|
}
|
|
35
|
-
|
|
36
34
|
const emisiveTexture = material === null || material === void 0 ? void 0 : material.emissiveTexture;
|
|
37
|
-
|
|
38
35
|
if (emisiveTexture) {
|
|
39
36
|
transformPrimitives(gltfData, materialIndex, emisiveTexture, processedTexCoords);
|
|
40
37
|
}
|
|
41
|
-
|
|
42
38
|
const normalTexture = material === null || material === void 0 ? void 0 : material.normalTexture;
|
|
43
|
-
|
|
44
39
|
if (normalTexture) {
|
|
45
40
|
transformPrimitives(gltfData, materialIndex, normalTexture, processedTexCoords);
|
|
46
41
|
}
|
|
47
|
-
|
|
48
42
|
const occlusionTexture = material === null || material === void 0 ? void 0 : material.occlusionTexture;
|
|
49
|
-
|
|
50
43
|
if (occlusionTexture) {
|
|
51
44
|
transformPrimitives(gltfData, materialIndex, occlusionTexture, processedTexCoords);
|
|
52
45
|
}
|
|
53
|
-
|
|
54
46
|
const metallicRoughnessTexture = material === null || material === void 0 ? void 0 : (_material$pbrMetallic2 = material.pbrMetallicRoughness) === null || _material$pbrMetallic2 === void 0 ? void 0 : _material$pbrMetallic2.metallicRoughnessTexture;
|
|
55
|
-
|
|
56
47
|
if (metallicRoughnessTexture) {
|
|
57
48
|
transformPrimitives(gltfData, materialIndex, metallicRoughnessTexture, processedTexCoords);
|
|
58
49
|
}
|
|
@@ -60,17 +51,13 @@ function transformTexCoords(materialIndex, gltfData) {
|
|
|
60
51
|
|
|
61
52
|
function transformPrimitives(gltfData, materialIndex, texture, processedTexCoords) {
|
|
62
53
|
const transformParameters = getTransformParameters(texture, processedTexCoords);
|
|
63
|
-
|
|
64
54
|
if (!transformParameters) {
|
|
65
55
|
return;
|
|
66
56
|
}
|
|
67
|
-
|
|
68
57
|
const meshes = gltfData.json.meshes || [];
|
|
69
|
-
|
|
70
58
|
for (const mesh of meshes) {
|
|
71
59
|
for (const primitive of mesh.primitives) {
|
|
72
60
|
const material = primitive.material;
|
|
73
|
-
|
|
74
61
|
if (Number.isFinite(material) && materialIndex === material) {
|
|
75
62
|
transformPrimitive(gltfData, primitive, transformParameters);
|
|
76
63
|
}
|
|
@@ -80,7 +67,6 @@ function transformPrimitives(gltfData, materialIndex, texture, processedTexCoord
|
|
|
80
67
|
|
|
81
68
|
function getTransformParameters(texture, processedTexCoords) {
|
|
82
69
|
var _texture$extensions;
|
|
83
|
-
|
|
84
70
|
const textureInfo = (_texture$extensions = texture.extensions) === null || _texture$extensions === void 0 ? void 0 : _texture$extensions[EXT_MESHOPT_TRANSFORM];
|
|
85
71
|
const {
|
|
86
72
|
texCoord: originalTexCoord = 0
|
|
@@ -88,15 +74,15 @@ function getTransformParameters(texture, processedTexCoords) {
|
|
|
88
74
|
const {
|
|
89
75
|
texCoord = originalTexCoord
|
|
90
76
|
} = textureInfo;
|
|
91
|
-
const isProcessed = processedTexCoords.findIndex(
|
|
92
|
-
|
|
77
|
+
const isProcessed = processedTexCoords.findIndex(_ref => {
|
|
78
|
+
let [original, newTexCoord] = _ref;
|
|
79
|
+
return original === originalTexCoord && newTexCoord === texCoord;
|
|
80
|
+
}) !== -1;
|
|
93
81
|
if (!isProcessed) {
|
|
94
82
|
const matrix = makeTransformationMatrix(textureInfo);
|
|
95
|
-
|
|
96
83
|
if (originalTexCoord !== texCoord) {
|
|
97
84
|
texture.texCoord = texCoord;
|
|
98
85
|
}
|
|
99
|
-
|
|
100
86
|
processedTexCoords.push([originalTexCoord, texCoord]);
|
|
101
87
|
return {
|
|
102
88
|
originalTexCoord,
|
|
@@ -104,7 +90,6 @@ function getTransformParameters(texture, processedTexCoords) {
|
|
|
104
90
|
matrix
|
|
105
91
|
};
|
|
106
92
|
}
|
|
107
|
-
|
|
108
93
|
return null;
|
|
109
94
|
}
|
|
110
95
|
|
|
@@ -115,17 +100,12 @@ function transformPrimitive(gltfData, primitive, transformParameters) {
|
|
|
115
100
|
matrix
|
|
116
101
|
} = transformParameters;
|
|
117
102
|
const texCoordAccessor = primitive.attributes["TEXCOORD_".concat(originalTexCoord)];
|
|
118
|
-
|
|
119
103
|
if (Number.isFinite(texCoordAccessor)) {
|
|
120
104
|
var _gltfData$json$access;
|
|
121
|
-
|
|
122
105
|
const accessor = (_gltfData$json$access = gltfData.json.accessors) === null || _gltfData$json$access === void 0 ? void 0 : _gltfData$json$access[texCoordAccessor];
|
|
123
|
-
|
|
124
106
|
if (accessor && accessor.bufferView) {
|
|
125
107
|
var _gltfData$json$buffer;
|
|
126
|
-
|
|
127
108
|
const bufferView = (_gltfData$json$buffer = gltfData.json.bufferViews) === null || _gltfData$json$buffer === void 0 ? void 0 : _gltfData$json$buffer[accessor.bufferView];
|
|
128
|
-
|
|
129
109
|
if (bufferView) {
|
|
130
110
|
const {
|
|
131
111
|
arrayBuffer,
|
|
@@ -140,14 +120,12 @@ function transformPrimitive(gltfData, primitive, transformParameters) {
|
|
|
140
120
|
const components = COMPONENTS[accessor.type];
|
|
141
121
|
const elementAddressScale = bufferView.byteStride || bytes * components;
|
|
142
122
|
const result = new Float32Array(length);
|
|
143
|
-
|
|
144
123
|
for (let i = 0; i < accessor.count; i++) {
|
|
145
124
|
const uv = new ArrayType(arrayBuffer, byteOffset + i * elementAddressScale, 2);
|
|
146
125
|
scratchVector.set(uv[0], uv[1], 1);
|
|
147
126
|
scratchVector.transformByMatrix3(matrix);
|
|
148
127
|
result.set([scratchVector[0], scratchVector[1]], i * components);
|
|
149
128
|
}
|
|
150
|
-
|
|
151
129
|
if (originalTexCoord === texCoord) {
|
|
152
130
|
updateGltf(accessor, bufferView, gltfData.buffers, result);
|
|
153
131
|
} else {
|
|
@@ -178,22 +156,18 @@ function createAttribute(newTexCoord, originalAccessor, primitive, gltfData, new
|
|
|
178
156
|
byteLength: newTexCoordArray.buffer.byteLength
|
|
179
157
|
});
|
|
180
158
|
const bufferViews = gltfData.json.bufferViews;
|
|
181
|
-
|
|
182
159
|
if (!bufferViews) {
|
|
183
160
|
return;
|
|
184
161
|
}
|
|
185
|
-
|
|
186
162
|
bufferViews.push({
|
|
187
163
|
buffer: gltfData.buffers.length - 1,
|
|
188
164
|
byteLength: newTexCoordArray.buffer.byteLength,
|
|
189
165
|
byteOffset: 0
|
|
190
166
|
});
|
|
191
167
|
const accessors = gltfData.json.accessors;
|
|
192
|
-
|
|
193
168
|
if (!accessors) {
|
|
194
169
|
return;
|
|
195
170
|
}
|
|
196
|
-
|
|
197
171
|
accessors.push({
|
|
198
172
|
bufferView: (bufferViews === null || bufferViews === void 0 ? void 0 : bufferViews.length) - 1,
|
|
199
173
|
byteOffset: 0,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/extensions/KHR_texture_transform.ts"],"names":["Vector3","Matrix3","getAccessorArrayTypeAndLength","BYTES","COMPONENTS","GLTFScenegraph","EXT_MESHOPT_TRANSFORM","name","scratchVector","scratchRotationMatrix","scratchScaleMatrix","decode","gltfData","options","gltfScenegraph","extension","getExtension","materials","json","i","length","transformTexCoords","materialIndex","processedTexCoords","material","baseColorTexture","pbrMetallicRoughness","transformPrimitives","emisiveTexture","emissiveTexture","normalTexture","occlusionTexture","metallicRoughnessTexture","texture","transformParameters","getTransformParameters","meshes","mesh","primitive","primitives","Number","isFinite","transformPrimitive","textureInfo","extensions","texCoord","originalTexCoord","isProcessed","findIndex","original","newTexCoord","matrix","makeTransformationMatrix","push","texCoordAccessor","attributes","accessor","accessors","bufferView","bufferViews","arrayBuffer","byteOffset","bufferByteOffset","buffers","buffer","ArrayType","bytes","componentType","components","type","elementAddressScale","byteStride","result","Float32Array","count","uv","set","transformByMatrix3","updateGltf","createAttribute","newTexCoordArray","byteLength","originalAccessor","extensionData","offset","rotation","scale","translationMatirx","rotationMatirx","Math","cos","sin","scaleMatrix","multiplyRight"],"mappings":"AAIA,SAAQA,OAAR,EAAiBC,OAAjB,QAA+B,eAA/B;AAGA,SAAQC,6BAAR,QAA4C,0BAA5C;AACA,SAAQC,KAAR,EAAeC,UAAf,QAAgC,8BAAhC;AAQA,OAAOC,cAAP,MAA2B,wBAA3B;AAGA,MAAMC,qBAAqB,GAAG,uBAA9B;AAEA,OAAO,MAAMC,IAAI,GAAGD,qBAAb;AAEP,MAAME,aAAa,GAAG,IAAIR,OAAJ,EAAtB;AACA,MAAMS,qBAAqB,GAAG,IAAIR,OAAJ,EAA9B;AACA,MAAMS,kBAAkB,GAAG,IAAIT,OAAJ,EAA3B;AAgCA,OAAO,eAAeU,MAAf,CAAsBC,QAAtB,E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,CAACmE,GAAtB,CACrBa,IAAI,CAACC,GAAL,CAASL,QAAT,CADqB,EAErBI,IAAI,CAACE,GAAL,CAASN,QAAT,CAFqB,EAGrB,CAHqB,EAIrB,CAACI,IAAI,CAACE,GAAL,CAASN,QAAT,CAJoB,EAKrBI,IAAI,CAACC,GAAL,CAASL,QAAT,CALqB,EAMrB,CANqB,EAOrB,CAPqB,EAQrB,CARqB,EASrB,CATqB,CAAvB;AAWA,QAAMO,WAAW,GAAGlF,kBAAkB,CAACkE,GAAnB,CAAuBU,KAAK,CAAC,CAAD,CAA5B,EAAiC,CAAjC,EAAoC,CAApC,EAAuC,CAAvC,EAA0CA,KAAK,CAAC,CAAD,CAA/C,EAAoD,CAApD,EAAuD,CAAvD,EAA0D,CAA1D,EAA6D,CAA7D,CAApB;AACA,SAAOC,iBAAiB,CAACM,aAAlB,CAAgCL,cAAhC,EAAgDK,aAAhD,CAA8DD,WAA9D,CAAP;AACD","sourcesContent":["/**\n * https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_texture_transform/README.md\n */\n\nimport {Vector3, Matrix3} from '@math.gl/core';\nimport type {GLTFMeshPrimitive, GLTFWithBuffers} from '../types/gltf-types';\nimport type {GLTFLoaderOptions} from '../../gltf-loader';\nimport {getAccessorArrayTypeAndLength} from '../gltf-utils/gltf-utils';\nimport {BYTES, COMPONENTS} from '../gltf-utils/gltf-constants';\nimport {\n Accessor,\n BufferView,\n MaterialNormalTextureInfo,\n MaterialOcclusionTextureInfo,\n TextureInfo as GLTFTextureInfo\n} from '../types/gltf-json-schema';\nimport GLTFScenegraph from '../api/gltf-scenegraph';\n\n/** Extension name */\nconst EXT_MESHOPT_TRANSFORM = 'KHR_texture_transform';\n\nexport const name = EXT_MESHOPT_TRANSFORM;\n\nconst scratchVector = new Vector3();\nconst scratchRotationMatrix = new Matrix3();\nconst scratchScaleMatrix = new Matrix3();\n\n/** Extension textureInfo https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_transform#gltf-schema-updates */\ntype TextureInfo = {\n /** The offset of the UV coordinate origin as a factor of the texture dimensions. */\n offset?: [number, number];\n /** Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise. */\n rotation?: number;\n /** The scale factor applied to the components of the UV coordinates. */\n scale?: [number, number];\n /** Overrides the textureInfo texCoord value if supplied, and if this extension is supported. */\n texCoord?: number;\n};\n/** Intersection of all GLTF textures */\ntype CompoundGLTFTextureInfo = GLTFTextureInfo &\n MaterialNormalTextureInfo &\n MaterialOcclusionTextureInfo;\n/** Parameters for TEXCOORD transformation */\ntype TransformParameters = {\n /** Original texCoord value https://www.khronos.org/registry/glTF/specs/2.0/glTF-2.0.html#_textureinfo_texcoord */\n originalTexCoord: number;\n /** New texCoord value from extension https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_transform#gltf-schema-updates */\n texCoord: number;\n /** Transformation matrix */\n matrix: Matrix3;\n};\n\n/**\n * The extension entry to process the transformation\n * @param gltfData gltf buffers and json\n * @param options GLTFLoader options\n */\nexport async function decode(gltfData: GLTFWithBuffers, options: GLTFLoaderOptions) {\n const gltfScenegraph = new GLTFScenegraph(gltfData);\n const extension = gltfScenegraph.getExtension(EXT_MESHOPT_TRANSFORM);\n if (!extension) {\n return;\n }\n const materials = gltfData.json.materials || [];\n for (let i = 0; i < materials.length; i++) {\n transformTexCoords(i, gltfData);\n }\n}\n\n/**\n * Transform TEXCOORD by material\n * @param materialIndex processing material index\n * @param gltfData gltf buffers and json\n */\nfunction transformTexCoords(materialIndex: number, gltfData: GLTFWithBuffers): void {\n // Save processed texCoords in order no to process the same twice\n const processedTexCoords: [number, number][] = [];\n const material = gltfData.json.materials?.[materialIndex];\n const baseColorTexture = material?.pbrMetallicRoughness?.baseColorTexture;\n if (baseColorTexture) {\n transformPrimitives(gltfData, materialIndex, baseColorTexture, processedTexCoords);\n }\n const emisiveTexture = material?.emissiveTexture;\n if (emisiveTexture) {\n transformPrimitives(gltfData, materialIndex, emisiveTexture, processedTexCoords);\n }\n const normalTexture = material?.normalTexture;\n if (normalTexture) {\n transformPrimitives(gltfData, materialIndex, normalTexture, processedTexCoords);\n }\n const occlusionTexture = material?.occlusionTexture;\n if (occlusionTexture) {\n transformPrimitives(gltfData, materialIndex, occlusionTexture, processedTexCoords);\n }\n const metallicRoughnessTexture = material?.pbrMetallicRoughness?.metallicRoughnessTexture;\n if (metallicRoughnessTexture) {\n transformPrimitives(gltfData, materialIndex, metallicRoughnessTexture, processedTexCoords);\n }\n}\n\n/**\n * Transform primitives of the particular material\n * @param gltfData gltf data\n * @param materialIndex primitives with this material will be transformed\n * @param texture texture object\n * @param processedTexCoords storage to save already processed texCoords\n */\nfunction transformPrimitives(\n gltfData: GLTFWithBuffers,\n materialIndex: number,\n texture: CompoundGLTFTextureInfo,\n processedTexCoords: [number, number][]\n) {\n const transformParameters = getTransformParameters(texture, processedTexCoords);\n if (!transformParameters) {\n return;\n }\n const meshes = gltfData.json.meshes || [];\n for (const mesh of meshes) {\n for (const primitive of mesh.primitives) {\n const material = primitive.material;\n if (Number.isFinite(material) && materialIndex === material) {\n transformPrimitive(gltfData, primitive, transformParameters);\n }\n }\n }\n}\n\n/**\n * Get parameters for TEXCOORD transformation\n * @param texture texture object\n * @param processedTexCoords storage to save already processed texCoords\n * @returns texCoord couple and transformation matrix\n */\nfunction getTransformParameters(\n texture: CompoundGLTFTextureInfo,\n processedTexCoords: [number, number][]\n): TransformParameters | null {\n const textureInfo = texture.extensions?.[EXT_MESHOPT_TRANSFORM];\n const {texCoord: originalTexCoord = 0} = texture;\n // If texCoord is not set in the extension, original attribute data will be replaced\n const {texCoord = originalTexCoord} = textureInfo;\n // Make sure that couple [originalTexCoord, extensionTexCoord] is not processed twice\n const isProcessed =\n processedTexCoords.findIndex(\n ([original, newTexCoord]) => original === originalTexCoord && newTexCoord === texCoord\n ) !== -1;\n if (!isProcessed) {\n const matrix = makeTransformationMatrix(textureInfo);\n if (originalTexCoord !== texCoord) {\n texture.texCoord = texCoord;\n }\n processedTexCoords.push([originalTexCoord, texCoord]);\n return {originalTexCoord, texCoord, matrix};\n }\n return null;\n}\n\n/**\n * Transform `TEXCOORD_0` attribute in the primitive\n * @param gltfData gltf data\n * @param primitive primitive object\n * @param transformParameters texCoord couple and transformation matrix\n */\nfunction transformPrimitive(\n gltfData: GLTFWithBuffers,\n primitive: GLTFMeshPrimitive,\n transformParameters: TransformParameters\n) {\n const {originalTexCoord, texCoord, matrix} = transformParameters;\n const texCoordAccessor = primitive.attributes[`TEXCOORD_${originalTexCoord}`];\n if (Number.isFinite(texCoordAccessor)) {\n // Get accessor of the `TEXCOORD_0` attribute\n const accessor = gltfData.json.accessors?.[texCoordAccessor];\n if (accessor && accessor.bufferView) {\n // Get `bufferView` of the `accessor`\n const bufferView = gltfData.json.bufferViews?.[accessor.bufferView];\n if (bufferView) {\n // Get `arrayBuffer` the `bufferView` look at\n const {arrayBuffer, byteOffset: bufferByteOffset} = gltfData.buffers[bufferView.buffer];\n // Resulting byteOffset is sum of the buffer, accessor and bufferView byte offsets\n const byteOffset =\n (bufferByteOffset || 0) + (accessor.byteOffset || 0) + (bufferView.byteOffset || 0);\n // Deduce TypedArray type and its length from `accessor` and `bufferView` data\n const {ArrayType, length} = getAccessorArrayTypeAndLength(accessor, bufferView);\n // Number of bytes each component occupies\n const bytes = BYTES[accessor.componentType];\n // Number of components. For the `TEXCOORD_0` with `VEC2` type, it must return 2\n const components = COMPONENTS[accessor.type];\n // Multiplier to calculate the address of the `TEXCOORD_0` element in the arrayBuffer\n const elementAddressScale = bufferView.byteStride || bytes * components;\n // Data transform to Float32Array\n const result = new Float32Array(length);\n for (let i = 0; i < accessor.count; i++) {\n // Take [u, v] couple from the arrayBuffer\n const uv = new ArrayType(arrayBuffer, byteOffset + i * elementAddressScale, 2);\n // Set and transform Vector3 per https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_transform#overview\n scratchVector.set(uv[0], uv[1], 1);\n scratchVector.transformByMatrix3(matrix);\n // Save result in Float32Array\n result.set([scratchVector[0], scratchVector[1]], i * components);\n }\n // If texCoord the same, replace gltf structural data\n if (originalTexCoord === texCoord) {\n updateGltf(accessor, bufferView, gltfData.buffers, result);\n } else {\n // If texCoord change, create new attribute\n createAttribute(texCoord, accessor, primitive, gltfData, result);\n }\n }\n }\n }\n}\n\n/**\n * Update GLTF structural objects with new data as we create new `Float32Array` for `TEXCOORD_0`.\n * @param accessor accessor to change\n * @param bufferView bufferView to change\n * @param buffers binary buffers\n * @param newTexcoordArray typed array with data after transformation\n */\nfunction updateGltf(\n accessor: Accessor,\n bufferView: BufferView,\n buffers: {arrayBuffer: ArrayBuffer; byteOffset: number; byteLength: number}[],\n newTexCoordArray: Float32Array\n): void {\n accessor.componentType = 5126;\n buffers.push({\n arrayBuffer: newTexCoordArray.buffer,\n byteOffset: 0,\n byteLength: newTexCoordArray.buffer.byteLength\n });\n bufferView.buffer = buffers.length - 1;\n bufferView.byteLength = newTexCoordArray.buffer.byteLength;\n bufferView.byteOffset = 0;\n delete bufferView.byteStride;\n}\n\n/**\n *\n * @param newTexCoord new `texCoord` value\n * @param originalAccessor original accessor object, that store data before transformation\n * @param primitive primitive object\n * @param gltfData gltf data\n * @param newTexCoordArray typed array with data after transformation\n * @returns\n */\nfunction createAttribute(\n newTexCoord: number,\n originalAccessor: Accessor,\n primitive: GLTFMeshPrimitive,\n gltfData: GLTFWithBuffers,\n newTexCoordArray: Float32Array\n) {\n gltfData.buffers.push({\n arrayBuffer: newTexCoordArray.buffer,\n byteOffset: 0,\n byteLength: newTexCoordArray.buffer.byteLength\n });\n const bufferViews = gltfData.json.bufferViews;\n if (!bufferViews) {\n return;\n }\n bufferViews.push({\n buffer: gltfData.buffers.length - 1,\n byteLength: newTexCoordArray.buffer.byteLength,\n byteOffset: 0\n });\n const accessors = gltfData.json.accessors;\n if (!accessors) {\n return;\n }\n accessors.push({\n bufferView: bufferViews?.length - 1,\n byteOffset: 0,\n componentType: 5126,\n count: originalAccessor.count,\n type: 'VEC2'\n });\n primitive.attributes[`TEXCOORD_${newTexCoord}`] = accessors.length - 1;\n}\n\n/**\n * Construct transformation matrix from the extension data (transition, rotation, scale)\n * @param extensionData extension data\n * @returns transformation matrix\n */\nfunction makeTransformationMatrix(extensionData: TextureInfo): Matrix3 {\n const {offset = [0, 0], rotation = 0, scale = [1, 1]} = extensionData;\n const translationMatirx = new Matrix3().set(1, 0, 0, 0, 1, 0, offset[0], offset[1], 1);\n const rotationMatirx = scratchRotationMatrix.set(\n Math.cos(rotation),\n Math.sin(rotation),\n 0,\n -Math.sin(rotation),\n Math.cos(rotation),\n 0,\n 0,\n 0,\n 1\n );\n const scaleMatrix = scratchScaleMatrix.set(scale[0], 0, 0, 0, scale[1], 0, 0, 0, 1);\n return translationMatirx.multiplyRight(rotationMatirx).multiplyRight(scaleMatrix);\n}\n"],"file":"KHR_texture_transform.js"}
|
|
1
|
+
{"version":3,"file":"KHR_texture_transform.js","names":["Vector3","Matrix3","getAccessorArrayTypeAndLength","BYTES","COMPONENTS","GLTFScenegraph","EXT_MESHOPT_TRANSFORM","name","scratchVector","scratchRotationMatrix","scratchScaleMatrix","decode","gltfData","options","gltfScenegraph","extension","getExtension","materials","json","i","length","transformTexCoords","materialIndex","processedTexCoords","material","baseColorTexture","pbrMetallicRoughness","transformPrimitives","emisiveTexture","emissiveTexture","normalTexture","occlusionTexture","metallicRoughnessTexture","texture","transformParameters","getTransformParameters","meshes","mesh","primitive","primitives","Number","isFinite","transformPrimitive","textureInfo","extensions","texCoord","originalTexCoord","isProcessed","findIndex","original","newTexCoord","matrix","makeTransformationMatrix","push","texCoordAccessor","attributes","accessor","accessors","bufferView","bufferViews","arrayBuffer","byteOffset","bufferByteOffset","buffers","buffer","ArrayType","bytes","componentType","components","type","elementAddressScale","byteStride","result","Float32Array","count","uv","set","transformByMatrix3","updateGltf","createAttribute","newTexCoordArray","byteLength","originalAccessor","extensionData","offset","rotation","scale","translationMatirx","rotationMatirx","Math","cos","sin","scaleMatrix","multiplyRight"],"sources":["../../../../src/lib/extensions/KHR_texture_transform.ts"],"sourcesContent":["/**\n * https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_texture_transform/README.md\n */\n\nimport {Vector3, Matrix3} from '@math.gl/core';\nimport type {GLTFMeshPrimitive, GLTFWithBuffers} from '../types/gltf-types';\nimport type {GLTFLoaderOptions} from '../../gltf-loader';\nimport {getAccessorArrayTypeAndLength} from '../gltf-utils/gltf-utils';\nimport {BYTES, COMPONENTS} from '../gltf-utils/gltf-constants';\nimport {\n Accessor,\n BufferView,\n MaterialNormalTextureInfo,\n MaterialOcclusionTextureInfo,\n TextureInfo as GLTFTextureInfo\n} from '../types/gltf-json-schema';\nimport GLTFScenegraph from '../api/gltf-scenegraph';\n\n/** Extension name */\nconst EXT_MESHOPT_TRANSFORM = 'KHR_texture_transform';\n\nexport const name = EXT_MESHOPT_TRANSFORM;\n\nconst scratchVector = new Vector3();\nconst scratchRotationMatrix = new Matrix3();\nconst scratchScaleMatrix = new Matrix3();\n\n/** Extension textureInfo https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_transform#gltf-schema-updates */\ntype TextureInfo = {\n /** The offset of the UV coordinate origin as a factor of the texture dimensions. */\n offset?: [number, number];\n /** Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise. */\n rotation?: number;\n /** The scale factor applied to the components of the UV coordinates. */\n scale?: [number, number];\n /** Overrides the textureInfo texCoord value if supplied, and if this extension is supported. */\n texCoord?: number;\n};\n/** Intersection of all GLTF textures */\ntype CompoundGLTFTextureInfo = GLTFTextureInfo &\n MaterialNormalTextureInfo &\n MaterialOcclusionTextureInfo;\n/** Parameters for TEXCOORD transformation */\ntype TransformParameters = {\n /** Original texCoord value https://www.khronos.org/registry/glTF/specs/2.0/glTF-2.0.html#_textureinfo_texcoord */\n originalTexCoord: number;\n /** New texCoord value from extension https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_transform#gltf-schema-updates */\n texCoord: number;\n /** Transformation matrix */\n matrix: Matrix3;\n};\n\n/**\n * The extension entry to process the transformation\n * @param gltfData gltf buffers and json\n * @param options GLTFLoader options\n */\nexport async function decode(gltfData: GLTFWithBuffers, options: GLTFLoaderOptions) {\n const gltfScenegraph = new GLTFScenegraph(gltfData);\n const extension = gltfScenegraph.getExtension(EXT_MESHOPT_TRANSFORM);\n if (!extension) {\n return;\n }\n const materials = gltfData.json.materials || [];\n for (let i = 0; i < materials.length; i++) {\n transformTexCoords(i, gltfData);\n }\n}\n\n/**\n * Transform TEXCOORD by material\n * @param materialIndex processing material index\n * @param gltfData gltf buffers and json\n */\nfunction transformTexCoords(materialIndex: number, gltfData: GLTFWithBuffers): void {\n // Save processed texCoords in order no to process the same twice\n const processedTexCoords: [number, number][] = [];\n const material = gltfData.json.materials?.[materialIndex];\n const baseColorTexture = material?.pbrMetallicRoughness?.baseColorTexture;\n if (baseColorTexture) {\n transformPrimitives(gltfData, materialIndex, baseColorTexture, processedTexCoords);\n }\n const emisiveTexture = material?.emissiveTexture;\n if (emisiveTexture) {\n transformPrimitives(gltfData, materialIndex, emisiveTexture, processedTexCoords);\n }\n const normalTexture = material?.normalTexture;\n if (normalTexture) {\n transformPrimitives(gltfData, materialIndex, normalTexture, processedTexCoords);\n }\n const occlusionTexture = material?.occlusionTexture;\n if (occlusionTexture) {\n transformPrimitives(gltfData, materialIndex, occlusionTexture, processedTexCoords);\n }\n const metallicRoughnessTexture = material?.pbrMetallicRoughness?.metallicRoughnessTexture;\n if (metallicRoughnessTexture) {\n transformPrimitives(gltfData, materialIndex, metallicRoughnessTexture, processedTexCoords);\n }\n}\n\n/**\n * Transform primitives of the particular material\n * @param gltfData gltf data\n * @param materialIndex primitives with this material will be transformed\n * @param texture texture object\n * @param processedTexCoords storage to save already processed texCoords\n */\nfunction transformPrimitives(\n gltfData: GLTFWithBuffers,\n materialIndex: number,\n texture: CompoundGLTFTextureInfo,\n processedTexCoords: [number, number][]\n) {\n const transformParameters = getTransformParameters(texture, processedTexCoords);\n if (!transformParameters) {\n return;\n }\n const meshes = gltfData.json.meshes || [];\n for (const mesh of meshes) {\n for (const primitive of mesh.primitives) {\n const material = primitive.material;\n if (Number.isFinite(material) && materialIndex === material) {\n transformPrimitive(gltfData, primitive, transformParameters);\n }\n }\n }\n}\n\n/**\n * Get parameters for TEXCOORD transformation\n * @param texture texture object\n * @param processedTexCoords storage to save already processed texCoords\n * @returns texCoord couple and transformation matrix\n */\nfunction getTransformParameters(\n texture: CompoundGLTFTextureInfo,\n processedTexCoords: [number, number][]\n): TransformParameters | null {\n const textureInfo = texture.extensions?.[EXT_MESHOPT_TRANSFORM];\n const {texCoord: originalTexCoord = 0} = texture;\n // If texCoord is not set in the extension, original attribute data will be replaced\n const {texCoord = originalTexCoord} = textureInfo;\n // Make sure that couple [originalTexCoord, extensionTexCoord] is not processed twice\n const isProcessed =\n processedTexCoords.findIndex(\n ([original, newTexCoord]) => original === originalTexCoord && newTexCoord === texCoord\n ) !== -1;\n if (!isProcessed) {\n const matrix = makeTransformationMatrix(textureInfo);\n if (originalTexCoord !== texCoord) {\n texture.texCoord = texCoord;\n }\n processedTexCoords.push([originalTexCoord, texCoord]);\n return {originalTexCoord, texCoord, matrix};\n }\n return null;\n}\n\n/**\n * Transform `TEXCOORD_0` attribute in the primitive\n * @param gltfData gltf data\n * @param primitive primitive object\n * @param transformParameters texCoord couple and transformation matrix\n */\nfunction transformPrimitive(\n gltfData: GLTFWithBuffers,\n primitive: GLTFMeshPrimitive,\n transformParameters: TransformParameters\n) {\n const {originalTexCoord, texCoord, matrix} = transformParameters;\n const texCoordAccessor = primitive.attributes[`TEXCOORD_${originalTexCoord}`];\n if (Number.isFinite(texCoordAccessor)) {\n // Get accessor of the `TEXCOORD_0` attribute\n const accessor = gltfData.json.accessors?.[texCoordAccessor];\n if (accessor && accessor.bufferView) {\n // Get `bufferView` of the `accessor`\n const bufferView = gltfData.json.bufferViews?.[accessor.bufferView];\n if (bufferView) {\n // Get `arrayBuffer` the `bufferView` look at\n const {arrayBuffer, byteOffset: bufferByteOffset} = gltfData.buffers[bufferView.buffer];\n // Resulting byteOffset is sum of the buffer, accessor and bufferView byte offsets\n const byteOffset =\n (bufferByteOffset || 0) + (accessor.byteOffset || 0) + (bufferView.byteOffset || 0);\n // Deduce TypedArray type and its length from `accessor` and `bufferView` data\n const {ArrayType, length} = getAccessorArrayTypeAndLength(accessor, bufferView);\n // Number of bytes each component occupies\n const bytes = BYTES[accessor.componentType];\n // Number of components. For the `TEXCOORD_0` with `VEC2` type, it must return 2\n const components = COMPONENTS[accessor.type];\n // Multiplier to calculate the address of the `TEXCOORD_0` element in the arrayBuffer\n const elementAddressScale = bufferView.byteStride || bytes * components;\n // Data transform to Float32Array\n const result = new Float32Array(length);\n for (let i = 0; i < accessor.count; i++) {\n // Take [u, v] couple from the arrayBuffer\n const uv = new ArrayType(arrayBuffer, byteOffset + i * elementAddressScale, 2);\n // Set and transform Vector3 per https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_transform#overview\n scratchVector.set(uv[0], uv[1], 1);\n scratchVector.transformByMatrix3(matrix);\n // Save result in Float32Array\n result.set([scratchVector[0], scratchVector[1]], i * components);\n }\n // If texCoord the same, replace gltf structural data\n if (originalTexCoord === texCoord) {\n updateGltf(accessor, bufferView, gltfData.buffers, result);\n } else {\n // If texCoord change, create new attribute\n createAttribute(texCoord, accessor, primitive, gltfData, result);\n }\n }\n }\n }\n}\n\n/**\n * Update GLTF structural objects with new data as we create new `Float32Array` for `TEXCOORD_0`.\n * @param accessor accessor to change\n * @param bufferView bufferView to change\n * @param buffers binary buffers\n * @param newTexcoordArray typed array with data after transformation\n */\nfunction updateGltf(\n accessor: Accessor,\n bufferView: BufferView,\n buffers: {arrayBuffer: ArrayBuffer; byteOffset: number; byteLength: number}[],\n newTexCoordArray: Float32Array\n): void {\n accessor.componentType = 5126;\n buffers.push({\n arrayBuffer: newTexCoordArray.buffer,\n byteOffset: 0,\n byteLength: newTexCoordArray.buffer.byteLength\n });\n bufferView.buffer = buffers.length - 1;\n bufferView.byteLength = newTexCoordArray.buffer.byteLength;\n bufferView.byteOffset = 0;\n delete bufferView.byteStride;\n}\n\n/**\n *\n * @param newTexCoord new `texCoord` value\n * @param originalAccessor original accessor object, that store data before transformation\n * @param primitive primitive object\n * @param gltfData gltf data\n * @param newTexCoordArray typed array with data after transformation\n * @returns\n */\nfunction createAttribute(\n newTexCoord: number,\n originalAccessor: Accessor,\n primitive: GLTFMeshPrimitive,\n gltfData: GLTFWithBuffers,\n newTexCoordArray: Float32Array\n) {\n gltfData.buffers.push({\n arrayBuffer: newTexCoordArray.buffer,\n byteOffset: 0,\n byteLength: newTexCoordArray.buffer.byteLength\n });\n const bufferViews = gltfData.json.bufferViews;\n if (!bufferViews) {\n return;\n }\n bufferViews.push({\n buffer: gltfData.buffers.length - 1,\n byteLength: newTexCoordArray.buffer.byteLength,\n byteOffset: 0\n });\n const accessors = gltfData.json.accessors;\n if (!accessors) {\n return;\n }\n accessors.push({\n bufferView: bufferViews?.length - 1,\n byteOffset: 0,\n componentType: 5126,\n count: originalAccessor.count,\n type: 'VEC2'\n });\n primitive.attributes[`TEXCOORD_${newTexCoord}`] = accessors.length - 1;\n}\n\n/**\n * Construct transformation matrix from the extension data (transition, rotation, scale)\n * @param extensionData extension data\n * @returns transformation matrix\n */\nfunction makeTransformationMatrix(extensionData: TextureInfo): Matrix3 {\n const {offset = [0, 0], rotation = 0, scale = [1, 1]} = extensionData;\n const translationMatirx = new Matrix3().set(1, 0, 0, 0, 1, 0, offset[0], offset[1], 1);\n const rotationMatirx = scratchRotationMatrix.set(\n Math.cos(rotation),\n Math.sin(rotation),\n 0,\n -Math.sin(rotation),\n Math.cos(rotation),\n 0,\n 0,\n 0,\n 1\n );\n const scaleMatrix = scratchScaleMatrix.set(scale[0], 0, 0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AC,EAAEA,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;EACtF,MAAMI,cAAc,GAAG/E,qBAAqB,CAACmE,GAAG,CAC9Ca,IAAI,CAACC,GAAG,CAACL,QAAQ,CAAC,EAClBI,IAAI,CAACE,GAAG,CAACN,QAAQ,CAAC,EAClB,CAAC,EACD,CAACI,IAAI,CAACE,GAAG,CAACN,QAAQ,CAAC,EACnBI,IAAI,CAACC,GAAG,CAACL,QAAQ,CAAC,EAClB,CAAC,EACD,CAAC,EACD,CAAC,EACD,CAAC,CACF;EACD,MAAMO,WAAW,GAAGlF,kBAAkB,CAACkE,GAAG,CAACU,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAEA,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;EACnF,OAAOC,iBAAiB,CAACM,aAAa,CAACL,cAAc,CAAC,CAACK,aAAa,CAACD,WAAW,CAAC;AACnF"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
1
3
|
import GLTFScenegraph from '../../api/gltf-scenegraph';
|
|
2
4
|
const EXT_FEATURE_METADATA = 'EXT_feature_metadata';
|
|
3
5
|
export const name = EXT_FEATURE_METADATA;
|
|
@@ -8,21 +10,17 @@ export async function decode(gltfData) {
|
|
|
8
10
|
|
|
9
11
|
function decodeExtFeatureMetadata(scenegraph) {
|
|
10
12
|
var _extension$schema;
|
|
11
|
-
|
|
12
13
|
const extension = scenegraph.getExtension(EXT_FEATURE_METADATA);
|
|
13
14
|
const schemaClasses = extension === null || extension === void 0 ? void 0 : (_extension$schema = extension.schema) === null || _extension$schema === void 0 ? void 0 : _extension$schema.classes;
|
|
14
15
|
const featureTables = extension === null || extension === void 0 ? void 0 : extension.featureTables;
|
|
15
16
|
const featureTextures = extension === null || extension === void 0 ? void 0 : extension.featureTextures;
|
|
16
|
-
|
|
17
17
|
if (featureTextures) {
|
|
18
18
|
console.warn('featureTextures is not yet supported in the "EXT_feature_metadata" extension.');
|
|
19
19
|
}
|
|
20
|
-
|
|
21
20
|
if (schemaClasses && featureTables) {
|
|
22
21
|
for (const schemaName in schemaClasses) {
|
|
23
22
|
const schemaClass = schemaClasses[schemaName];
|
|
24
23
|
const featureTable = findFeatureTableByName(featureTables, schemaName);
|
|
25
|
-
|
|
26
24
|
if (featureTable) {
|
|
27
25
|
handleFeatureTableProperties(scenegraph, featureTable, schemaClass);
|
|
28
26
|
}
|
|
@@ -33,11 +31,9 @@ function decodeExtFeatureMetadata(scenegraph) {
|
|
|
33
31
|
function handleFeatureTableProperties(scenegraph, featureTable, schemaClass) {
|
|
34
32
|
for (const propertyName in schemaClass.properties) {
|
|
35
33
|
var _featureTable$propert;
|
|
36
|
-
|
|
37
34
|
const schemaProperty = schemaClass.properties[propertyName];
|
|
38
35
|
const featureTableProperty = featureTable === null || featureTable === void 0 ? void 0 : (_featureTable$propert = featureTable.properties) === null || _featureTable$propert === void 0 ? void 0 : _featureTable$propert[propertyName];
|
|
39
36
|
const numberOfFeatures = featureTable.count;
|
|
40
|
-
|
|
41
37
|
if (featureTableProperty) {
|
|
42
38
|
const data = getPropertyDataFromBinarySource(scenegraph, schemaProperty, numberOfFeatures, featureTableProperty);
|
|
43
39
|
featureTableProperty.data = data;
|
|
@@ -48,7 +44,6 @@ function handleFeatureTableProperties(scenegraph, featureTable, schemaClass) {
|
|
|
48
44
|
function getPropertyDataFromBinarySource(scenegraph, schemaProperty, numberOfFeatures, featureTableProperty) {
|
|
49
45
|
const bufferView = featureTableProperty.bufferView;
|
|
50
46
|
let data = scenegraph.getTypedArrayForBufferView(bufferView);
|
|
51
|
-
|
|
52
47
|
switch (schemaProperty.type) {
|
|
53
48
|
case 'STRING':
|
|
54
49
|
{
|
|
@@ -57,22 +52,18 @@ function getPropertyDataFromBinarySource(scenegraph, schemaProperty, numberOfFea
|
|
|
57
52
|
data = getStringAttributes(data, offsetsData, numberOfFeatures);
|
|
58
53
|
break;
|
|
59
54
|
}
|
|
60
|
-
|
|
61
55
|
default:
|
|
62
56
|
}
|
|
63
|
-
|
|
64
57
|
return data;
|
|
65
58
|
}
|
|
66
59
|
|
|
67
60
|
function findFeatureTableByName(featureTables, schemaClassName) {
|
|
68
61
|
for (const featureTableName in featureTables) {
|
|
69
62
|
const featureTable = featureTables[featureTableName];
|
|
70
|
-
|
|
71
63
|
if (featureTable.class === schemaClassName) {
|
|
72
64
|
return featureTable;
|
|
73
65
|
}
|
|
74
66
|
}
|
|
75
|
-
|
|
76
67
|
return null;
|
|
77
68
|
}
|
|
78
69
|
|
|
@@ -81,7 +72,6 @@ function getStringAttributes(data, offsetsData, stringsCount) {
|
|
|
81
72
|
const textDecoder = new TextDecoder('utf8');
|
|
82
73
|
let stringOffset = 0;
|
|
83
74
|
const bytesPerStringSize = 4;
|
|
84
|
-
|
|
85
75
|
for (let index = 0; index < stringsCount; index++) {
|
|
86
76
|
const stringByteSize = offsetsData[(index + 1) * bytesPerStringSize] - offsetsData[index * bytesPerStringSize];
|
|
87
77
|
const stringData = data.subarray(stringOffset, stringByteSize + stringOffset);
|
|
@@ -89,7 +79,6 @@ function getStringAttributes(data, offsetsData, stringsCount) {
|
|
|
89
79
|
stringsArray.push(stringAttribute);
|
|
90
80
|
stringOffset += stringByteSize;
|
|
91
81
|
}
|
|
92
|
-
|
|
93
82
|
return stringsArray;
|
|
94
83
|
}
|
|
95
84
|
//# sourceMappingURL=EXT_feature_metadata.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"EXT_feature_metadata.js","names":["GLTFScenegraph","EXT_FEATURE_METADATA","name","decode","gltfData","scenegraph","decodeExtFeatureMetadata","extension","getExtension","schemaClasses","schema","classes","featureTables","featureTextures","console","warn","schemaName","schemaClass","featureTable","findFeatureTableByName","handleFeatureTableProperties","propertyName","properties","schemaProperty","featureTableProperty","numberOfFeatures","count","data","getPropertyDataFromBinarySource","bufferView","getTypedArrayForBufferView","type","stringOffsetBufferView","offsetsData","getStringAttributes","schemaClassName","featureTableName","class","stringsCount","stringsArray","textDecoder","TextDecoder","stringOffset","bytesPerStringSize","index","stringByteSize","stringData","subarray","stringAttribute","push"],"sources":["../../../../../src/lib/extensions/deprecated/EXT_feature_metadata.ts"],"sourcesContent":["/* eslint-disable camelcase */\nimport type {GLTF} from '../../types/gltf-types';\n\nimport GLTFScenegraph from '../../api/gltf-scenegraph';\nimport {\n ClassProperty,\n EXT_feature_metadata_class_object,\n EXT_feature_metadata_feature_table,\n FeatureTableProperty,\n GLTF_EXT_feature_metadata\n} from '../../types/gltf-json-schema';\n\n/** Extension name */\nconst EXT_FEATURE_METADATA = 'EXT_feature_metadata';\n\nexport const name = EXT_FEATURE_METADATA;\n\nexport async function decode(gltfData: {json: GLTF}): Promise<void> {\n const scenegraph = new GLTFScenegraph(gltfData);\n decodeExtFeatureMetadata(scenegraph);\n}\n\n/**\n * Decodes feature metadata from extension\n * @param scenegraph\n */\nfunction decodeExtFeatureMetadata(scenegraph: GLTFScenegraph): void {\n const extension: GLTF_EXT_feature_metadata | null = scenegraph.getExtension(EXT_FEATURE_METADATA);\n const schemaClasses = extension?.schema?.classes;\n const featureTables = extension?.featureTables;\n const featureTextures = extension?.featureTextures;\n\n if (featureTextures) {\n /*\n * TODO add support for featureTextures\n * Spec - https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata#feature-textures\n */\n // eslint-disable-next-line no-console\n console.warn('featureTextures is not yet supported in the \"EXT_feature_metadata\" extension.');\n }\n\n if (schemaClasses && featureTables) {\n for (const schemaName in schemaClasses) {\n const schemaClass = schemaClasses[schemaName];\n const featureTable = findFeatureTableByName(featureTables, schemaName);\n\n if (featureTable) {\n handleFeatureTableProperties(scenegraph, featureTable, schemaClass);\n }\n }\n }\n}\n\n/**\n * Navigate throw all properies in feature table and gets properties data.\n * @param scenegraph\n * @param featureTable\n * @param schemaClass\n */\nfunction handleFeatureTableProperties(\n scenegraph: GLTFScenegraph,\n featureTable: EXT_feature_metadata_feature_table,\n schemaClass: EXT_feature_metadata_class_object\n): void {\n for (const propertyName in schemaClass.properties) {\n const schemaProperty = schemaClass.properties[propertyName];\n const featureTableProperty = featureTable?.properties?.[propertyName];\n const numberOfFeatures = featureTable.count;\n\n if (featureTableProperty) {\n const data = getPropertyDataFromBinarySource(\n scenegraph,\n schemaProperty,\n numberOfFeatures,\n featureTableProperty\n );\n featureTableProperty.data = data;\n }\n }\n}\n\n/**\n * Decode properties from binary sourse based on property type.\n * @param scenegraph\n * @param schemaProperty\n * @param numberOfFeatures\n * @param featureTableProperty\n */\nfunction getPropertyDataFromBinarySource(\n scenegraph: GLTFScenegraph,\n schemaProperty: ClassProperty,\n numberOfFeatures: number,\n featureTableProperty: FeatureTableProperty\n): Uint8Array | string[] {\n const bufferView = featureTableProperty.bufferView;\n // TODO think maybe we shouldn't get data only in Uint8Array format.\n let data: Uint8Array | string[] = scenegraph.getTypedArrayForBufferView(bufferView);\n\n switch (schemaProperty.type) {\n case 'STRING': {\n // stringOffsetBufferView should be available for string type.\n const stringOffsetBufferView = featureTableProperty.stringOffsetBufferView!;\n const offsetsData = scenegraph.getTypedArrayForBufferView(stringOffsetBufferView);\n data = getStringAttributes(data, offsetsData, numberOfFeatures);\n break;\n }\n default:\n }\n\n return data;\n}\n\n/**\n * Find the feature table by class name.\n * @param featureTables\n * @param schemaClassName\n */\nfunction findFeatureTableByName(\n featureTables: {[key: string]: EXT_feature_metadata_feature_table},\n schemaClassName: string\n): EXT_feature_metadata_feature_table | null {\n for (const featureTableName in featureTables) {\n const featureTable = featureTables[featureTableName];\n\n if (featureTable.class === schemaClassName) {\n return featureTable;\n }\n }\n\n return null;\n}\n\n/**\n * Getting string attributes from binary data.\n * Spec - https://github.com/CesiumGS/3d-tiles/tree/main/specification/Metadata#strings\n * @param data\n * @param offsetsData\n * @param stringsCount\n */\nfunction getStringAttributes(\n data: Uint8Array,\n offsetsData: Uint8Array,\n stringsCount: number\n): string[] {\n const stringsArray: string[] = [];\n const textDecoder = new TextDecoder('utf8');\n\n let stringOffset = 0;\n const bytesPerStringSize = 4;\n\n for (let index = 0; index < stringsCount; index++) {\n // TODO check if it is multiplication on bytesPerStringSize is valid operation?\n const stringByteSize =\n offsetsData[(index + 1) * bytesPerStringSize] - offsetsData[index * bytesPerStringSize];\n const stringData = data.subarray(stringOffset, stringByteSize + stringOffset);\n const stringAttribute = textDecoder.decode(stringData);\n\n stringsArray.push(stringAttribute);\n stringOffset += stringByteSize;\n }\n\n return stringsArray;\n}\n"],"mappings":";;AAGA,OAAOA,cAAc,MAAM,2BAA2B;AAUtD,MAAMC,oBAAoB,GAAG,sBAAsB;AAEnD,OAAO,MAAMC,IAAI,GAAGD,oBAAoB;AAExC,OAAO,eAAeE,MAAM,CAACC,QAAsB,EAAiB;EAClE,MAAMC,UAAU,GAAG,IAAIL,cAAc,CAACI,QAAQ,CAAC;EAC/CE,wBAAwB,CAACD,UAAU,CAAC;AACtC;;AAMA,SAASC,wBAAwB,CAACD,UAA0B,EAAQ;EAAA;EAClE,MAAME,SAA2C,GAAGF,UAAU,CAACG,YAAY,CAACP,oBAAoB,CAAC;EACjG,MAAMQ,aAAa,GAAGF,SAAS,aAATA,SAAS,4CAATA,SAAS,CAAEG,MAAM,sDAAjB,kBAAmBC,OAAO;EAChD,MAAMC,aAAa,GAAGL,SAAS,aAATA,SAAS,uBAATA,SAAS,CAAEK,aAAa;EAC9C,MAAMC,eAAe,GAAGN,SAAS,aAATA,SAAS,uBAATA,SAAS,CAAEM,eAAe;EAElD,IAAIA,eAAe,EAAE;IAMnBC,OAAO,CAACC,IAAI,CAAC,+EAA+E,CAAC;EAC/F;EAEA,IAAIN,aAAa,IAAIG,aAAa,EAAE;IAClC,KAAK,MAAMI,UAAU,IAAIP,aAAa,EAAE;MACtC,MAAMQ,WAAW,GAAGR,aAAa,CAACO,UAAU,CAAC;MAC7C,M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sB,CAC7BP,aAAkE,EAClEuB,eAAuB,EACoB;EAC3C,KAAK,MAAMC,gBAAgB,IAAIxB,aAAa,EAAE;IAC5C,MAAMM,YAAY,GAAGN,aAAa,CAACwB,gBAAgB,CAAC;IAEpD,IAAIlB,YAAY,CAACmB,KAAK,KAAKF,eAAe,EAAE;MAC1C,OAAOjB,YAAY;IACrB;EACF;EAEA,OAAO,IAAI;AACb;;AASA,SAASgB,mBAAmB,CAC1BP,IAAgB,EAChBM,WAAuB,EACvBK,YAAoB,EACV;EACV,MAAMC,YAAsB,GAAG,EAAE;EACjC,MAAMC,WAAW,GAAG,IAAIC,WAAW,CAAC,MAAM,CAAC;EAE3C,IAAIC,YAAY,GAAG,CAAC;EACpB,MAAMC,kBAAkB,GAAG,CAAC;EAE5B,KAAK,IAAIC,KAAK,GAAG,CAAC,EAAEA,KAAK,GAAGN,YAAY,EAAEM,KAAK,EAAE,EAAE;IAEjD,MAAMC,cAAc,GAClBZ,WAAW,CAAC,CAACW,KAAK,GAAG,CAAC,IAAID,kBAAkB,CAAC,GAAGV,WAAW,CAACW,KAAK,GAAGD,kBAAkB,CAAC;IACzF,MAAMG,UAAU,GAAGnB,IAAI,CAACoB,QAAQ,CAACL,YAAY,EAAEG,cAAc,GAAGH,YAAY,CAAC;IAC7E,MAAMM,eAAe,GAAGR,WAAW,CAACrC,MAAM,CAAC2C,UAAU,CAAC;IAEtDP,YAAY,CAACU,IAAI,CAACD,eAAe,CAAC;IAClCN,YAAY,IAAIG,cAAc;EAChC;EAEA,OAAON,YAAY;AACrB"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
1
3
|
import { assert } from '../../utils/assert';
|
|
2
4
|
import GLTFScenegraph from '../../api/gltf-scenegraph';
|
|
3
5
|
const KHR_LIGHTS_PUNCTUAL = 'KHR_lights_punctual';
|
|
@@ -7,8 +9,8 @@ export async function decode(gltfData) {
|
|
|
7
9
|
const {
|
|
8
10
|
json
|
|
9
11
|
} = gltfScenegraph;
|
|
10
|
-
const extension = gltfScenegraph.getExtension(KHR_LIGHTS_PUNCTUAL);
|
|
11
12
|
|
|
13
|
+
const extension = gltfScenegraph.getExtension(KHR_LIGHTS_PUNCTUAL);
|
|
12
14
|
if (extension) {
|
|
13
15
|
gltfScenegraph.json.lights = extension.lights;
|
|
14
16
|
gltfScenegraph.removeExtension(KHR_LIGHTS_PUNCTUAL);
|
|
@@ -16,14 +18,13 @@ export async function decode(gltfData) {
|
|
|
16
18
|
|
|
17
19
|
for (const node of json.nodes || []) {
|
|
18
20
|
const nodeExtension = gltfScenegraph.getObjectExtension(node, KHR_LIGHTS_PUNCTUAL);
|
|
19
|
-
|
|
20
21
|
if (nodeExtension) {
|
|
21
22
|
node.light = nodeExtension.light;
|
|
22
23
|
}
|
|
23
|
-
|
|
24
24
|
gltfScenegraph.removeObjectExtension(node, KHR_LIGHTS_PUNCTUAL);
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
+
|
|
27
28
|
export async function encode(gltfData) {
|
|
28
29
|
const gltfScenegraph = new GLTFScenegraph(gltfData);
|
|
29
30
|
const {
|
|
@@ -42,7 +43,6 @@ export async function encode(gltfData) {
|
|
|
42
43
|
const node = light.node;
|
|
43
44
|
gltfScenegraph.addObjectExtension(node, KHR_LIGHTS_PUNCTUAL, light);
|
|
44
45
|
}
|
|
45
|
-
|
|
46
46
|
delete gltfScenegraph.json.lights;
|
|
47
47
|
}
|
|
48
48
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"KHR_lights_punctual.js","names":["assert","GLTFScenegraph","KHR_LIGHTS_PUNCTUAL","name","decode","gltfData","gltfScenegraph","json","extension","getExtension","lights","removeExtension","node","nodes","nodeExtension","getObjectExtension","light","removeObjectExtension","encode","addExtension","addObjectExtension"],"sources":["../../../../../src/lib/extensions/deprecated/KHR_lights_punctual.ts"],"sourcesContent":["// GLTF EXTENSION: KHR_lights_punctual\n// https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_lights_punctual\n\nimport type {GLTF} from '../../types/gltf-types';\n\nimport {assert} from '../../utils/assert';\nimport GLTFScenegraph from '../../api/gltf-scenegraph';\n\nconst KHR_LIGHTS_PUNCTUAL = 'KHR_lights_punctual';\n\nexport const name = KHR_LIGHTS_PUNCTUAL;\n\nexport async function decode(gltfData: {json: GLTF}): Promise<void> {\n const gltfScenegraph = new GLTFScenegraph(gltfData);\n const {json} = gltfScenegraph;\n\n // Move the light array out of the extension and remove the extension\n const extension = gltfScenegraph.getExtension(KHR_LIGHTS_PUNCTUAL);\n if (extension) {\n // @ts-ignore\n gltfScenegraph.json.lights = extension.lights;\n gltfScenegraph.removeExtension(KHR_LIGHTS_PUNCTUAL);\n }\n\n // Any nodes that have the extension, add lights field pointing to light object\n // and remove the extension\n for (const node of json.nodes || []) {\n const nodeExtension = gltfScenegraph.getObjectExtension(node, KHR_LIGHTS_PUNCTUAL);\n if (nodeExtension) {\n // @ts-ignore\n node.light = nodeExtension.light;\n }\n gltfScenegraph.removeObjectExtension(node, KHR_LIGHTS_PUNCTUAL);\n }\n}\n\n// Move the light ar ray out of the extension and remove the extension\nexport async function encode(gltfData): Promise<void> {\n const gltfScenegraph = new GLTFScenegraph(gltfData);\n const {json} = gltfScenegraph;\n\n // @ts-ignore\n if (json.lights) {\n const extension = gltfScenegraph.addExtension(KHR_LIGHTS_PUNCTUAL);\n // @ts-ignore\n assert(!extension.lights);\n // @ts-ignore\n extension.lights = json.lights;\n // @ts-ignore\n delete json.lights;\n }\n\n // Any nodes that have lights field pointing to light object\n // add the extension\n // @ts-ignore\n if (gltfScenegraph.json.lights) {\n // @ts-ignore\n for (const light of gltfScenegraph.json.lights) {\n const node = light.node;\n gltfScenegraph.addObjectExtension(node, KHR_LIGHTS_PUNCTUAL, light);\n }\n // @ts-ignore\n delete gltfScenegraph.json.lights;\n }\n}\n"],"mappings":";;AAKA,SAAQA,MAAM,QAAO,oBAAoB;A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AAMM,KAAK,IAAIV,cAAc,CAACC,IAAI,CAACG,MAAM,EAAE;MAC9C,MAAME,IAAI,GAAGI,KAAK,CAACJ,IAAI;MACvBN,cAAc,CAACc,kBAAkB,CAACR,IAAI,EAAEV,mBAAmB,EAAEc,KAAK,CAAC;IACrE;IAEA,OAAOV,cAAc,CAACC,IAAI,CAACG,MAAM;EACnC;AACF"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
1
3
|
import GLTFScenegraph from '../../api/gltf-scenegraph';
|
|
2
4
|
const KHR_MATERIALS_UNLIT = 'KHR_materials_unlit';
|
|
3
5
|
export const name = KHR_MATERIALS_UNLIT;
|
|
@@ -6,15 +8,14 @@ export async function decode(gltfData) {
|
|
|
6
8
|
const {
|
|
7
9
|
json
|
|
8
10
|
} = gltfScenegraph;
|
|
11
|
+
|
|
9
12
|
gltfScenegraph.removeExtension(KHR_MATERIALS_UNLIT);
|
|
10
13
|
|
|
11
14
|
for (const material of json.materials || []) {
|
|
12
15
|
const extension = material.extensions && material.extensions.KHR_materials_unlit;
|
|
13
|
-
|
|
14
16
|
if (extension) {
|
|
15
17
|
material.unlit = true;
|
|
16
18
|
}
|
|
17
|
-
|
|
18
19
|
gltfScenegraph.removeObjectExtension(material, KHR_MATERIALS_UNLIT);
|
|
19
20
|
}
|
|
20
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"KHR_materials_unlit.js","names":["GLTFScenegraph","KHR_MATERIALS_UNLIT","name","decode","gltfData","gltfScenegraph","json","removeExtension","material","materials","extension","extensions","KHR_materials_unlit","unlit","removeObjectExtension","encode","addObjectExtension","addExtension"],"sources":["../../../../../src/lib/extensions/deprecated/KHR_materials_unlit.ts"],"sourcesContent":["// GLTF EXTENSION: KHR_materials_unlit\n// https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit\n\nimport type {GLTF} from '../../types/gltf-types';\n\nimport GLTFScenegraph from '../../api/gltf-scenegraph';\n\nconst KHR_MATERIALS_UNLIT = 'KHR_materials_unlit';\n\nexport const name = KHR_MATERIALS_UNLIT;\n\nexport async function decode(gltfData: {json: GLTF}): Promise<void> {\n const gltfScenegraph = new GLTFScenegraph(gltfData);\n const {json} = gltfScenegraph;\n\n // Remove the top-level extension\n gltfScenegraph.removeExtension(KHR_MATERIALS_UNLIT);\n\n // Any nodes that have the extension, add lights field pointing to light object\n // and remove the extension\n for (const material of json.materials || []) {\n const extension = material.extensions && material.extensions.KHR_materials_unlit;\n if (extension) {\n // @ts-ignore TODO\n material.unlit = true;\n }\n gltfScenegraph.removeObjectExtension(material, KHR_MATERIALS_UNLIT);\n }\n}\n\nexport function encode(gltfData) {\n const gltfScenegraph = new GLTFScenegraph(gltfData);\n const {json} = gltfScenegraph;\n\n // Any nodes that have lights field pointing to light object\n // add the extension\n // @ts-ignore\n if (gltfScenegraph.materials) {\n for (const material of json.materials || []) {\n // @ts-ignore\n if (material.unlit) {\n // @ts-ignore\n delete material.unlit;\n gltfScenegraph.addObjectExtension(material, KHR_MATERIALS_UNLIT, {});\n gltfScenegraph.addExtension(KHR_MATERIALS_UNLIT);\n }\n }\n }\n}\n"],"mappings":";;AAKA,OAAOA,cAAc,MAAM,2BAA2B;AAEtD,MAAMC,mBAAmB,GAAG,qBAAqB;AAEjD,OAAO,MAAMC,IAAI,GAAGD,mBAAmB;AAEvC,OAAO,eAAeE,MAAM,CAACC,QAAsB,EAAiB;EAClE,MAAMC,cAAc,GAAG,IAAIL,cAAc,CAACI,QAAQ,CAAC;EACnD,MAAM;IAACE;EAAI,CAAC,GAAGD,cAAc;;EAG7BA,cAAc,CAACE,eAAe,CAACN,mBAAmB,CAAC;;EAInD,KAAK,MAAMO,QAAQ,IAAIF,IAAI,CAACG,SAAS,IAAI,EAAE,EAAE;IAC3C,MAAMC,SAAS,GAAGF,QAAQ,CAACG,UAAU,IAAIH,QAAQ,CAACG,UAAU,CAACC,mBAAmB;IAChF,IAAIF,SAAS,EAAE;MAEbF,QAAQ,CAACK,KAAK,GAAG,IAAI;IACvB;IACAR,cAAc,CAACS,qBAAqB,CAACN,QAAQ,EAAEP,mBAAmB,CAAC;EACrE;AACF;AAEA,OAAO,SAASc,MAAM,CAACX,QAAQ,EAAE;EAC/B,MAAMC,cAAc,GAAG,IAAIL,cAAc,CAACI,QAAQ,CAAC;EACnD,MAAM;IAACE;EAAI,CAAC,GAAGD,cAAc;;EAK7B,IAAIA,cAAc,CAACI,SAAS,EAAE;IAC5B,KAAK,MAAMD,QAAQ,IAAIF,IAAI,CAACG,SAAS,IAAI,EAAE,EAAE;MAE3C,IAAID,QAAQ,CAACK,KAAK,EAAE;QAElB,OAAOL,QAAQ,CAACK,KAAK;QACrBR,cAAc,CAACW,kBAAkB,CAACR,QAAQ,EAAEP,mBAAmB,EAAE,CAAC,CAAC,CAAC;QACpEI,cAAc,CAACY,YAAY,CAAChB,mBAAmB,CAAC;MAClD;IACF;EACF;AACF"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
1
3
|
import GLTFScenegraph from '../../api/gltf-scenegraph';
|
|
2
4
|
const KHR_TECHNIQUES_WEBGL = 'KHR_techniques_webgl';
|
|
3
5
|
export const name = KHR_TECHNIQUES_WEBGL;
|
|
@@ -7,27 +9,24 @@ export async function decode(gltfData) {
|
|
|
7
9
|
json
|
|
8
10
|
} = gltfScenegraph;
|
|
9
11
|
const extension = gltfScenegraph.getExtension(KHR_TECHNIQUES_WEBGL);
|
|
10
|
-
|
|
11
12
|
if (extension) {
|
|
12
13
|
const techniques = resolveTechniques(extension, gltfScenegraph);
|
|
13
|
-
|
|
14
14
|
for (const material of json.materials || []) {
|
|
15
15
|
const materialExtension = gltfScenegraph.getObjectExtension(material, KHR_TECHNIQUES_WEBGL);
|
|
16
|
-
|
|
17
16
|
if (materialExtension) {
|
|
18
|
-
material.technique = Object.assign({}, materialExtension,
|
|
17
|
+
material.technique = Object.assign({}, materialExtension,
|
|
18
|
+
techniques[materialExtension.technique]);
|
|
19
19
|
material.technique.values = resolveValues(material.technique, gltfScenegraph);
|
|
20
20
|
}
|
|
21
|
-
|
|
22
21
|
gltfScenegraph.removeObjectExtension(material, KHR_TECHNIQUES_WEBGL);
|
|
23
22
|
}
|
|
24
|
-
|
|
25
23
|
gltfScenegraph.removeExtension(KHR_TECHNIQUES_WEBGL);
|
|
26
24
|
}
|
|
27
25
|
}
|
|
28
|
-
export async function encode(gltfData, options) {
|
|
29
|
-
|
|
30
|
-
function resolveTechniques(techniquesExtension,
|
|
26
|
+
export async function encode(gltfData, options) {
|
|
27
|
+
}
|
|
28
|
+
function resolveTechniques(techniquesExtension,
|
|
29
|
+
gltfScenegraph) {
|
|
31
30
|
const {
|
|
32
31
|
programs = [],
|
|
33
32
|
shaders = [],
|
|
@@ -50,14 +49,15 @@ function resolveTechniques(techniquesExtension, gltfScenegraph) {
|
|
|
50
49
|
});
|
|
51
50
|
return techniques;
|
|
52
51
|
}
|
|
53
|
-
|
|
54
52
|
function resolveValues(technique, gltfScenegraph) {
|
|
55
53
|
const values = Object.assign({}, technique.values);
|
|
54
|
+
|
|
56
55
|
Object.keys(technique.uniforms || {}).forEach(uniform => {
|
|
57
56
|
if (technique.uniforms[uniform].value && !(uniform in values)) {
|
|
58
57
|
values[uniform] = technique.uniforms[uniform].value;
|
|
59
58
|
}
|
|
60
59
|
});
|
|
60
|
+
|
|
61
61
|
Object.keys(values).forEach(uniform => {
|
|
62
62
|
if (typeof values[uniform] === 'object' && values[uniform].index !== undefined) {
|
|
63
63
|
values[uniform].texture = gltfScenegraph.getTexture(values[uniform].index);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"KHR_techniques_webgl.js","names":["GLTFScenegraph","KHR_TECHNIQUES_WEBGL","name","decode","gltfData","gltfScenegraph","json","extension","getExtension","techniques","resolveTechniques","material","materials","materialExtension","getObjectExtension","technique","Object","assign","values","resolveValues","removeObjectExtension","removeExtension","encode","options","techniquesExtension","programs","shaders","textDecoder","TextDecoder","forEach","shader","Number","isFinite","bufferView","code","getTypedArrayForBufferView","Error","program","fragmentShader","vertexShader","keys","uniforms","uniform","value","index","undefined","texture","getTexture"],"sources":["../../../../../src/lib/extensions/deprecated/KHR_techniques_webgl.ts"],"sourcesContent":["// GLTF EXTENSION: KHR_techniques_webgl\n// https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_techniques_webgl\n\nimport type {GLTF} from '../../types/gltf-types';\n\nimport GLTFScenegraph from '../../api/gltf-scenegraph';\n\nconst KHR_TECHNIQUES_WEBGL = 'KHR_techniques_webgl';\n\nexport const name = KHR_TECHNIQUES_WEBGL;\n\nexport async function decode(gltfData: {json: GLTF}): Promise<void> {\n const gltfScenegraph = new GLTFScenegraph(gltfData);\n const {json} = gltfScenegraph;\n\n const extension = gltfScenegraph.getExtension(KHR_TECHNIQUES_WEBGL);\n if (extension) {\n const techniques = resolveTechniques(extension, gltfScenegraph);\n\n for (const material of json.materials || []) {\n const materialExtension = gltfScenegraph.getObjectExtension(material, KHR_TECHNIQUES_WEBGL);\n if (materialExtension) {\n // @ts-ignore TODO\n material.technique = Object.assign(\n {},\n materialExtension,\n // @ts-ignore\n techniques[materialExtension.technique]\n );\n // @ts-ignore TODO\n material.technique.values = resolveValues(material.technique, gltfScenegraph);\n }\n gltfScenegraph.removeObjectExtension(material, KHR_TECHNIQUES_WEBGL);\n }\n\n gltfScenegraph.removeExtension(KHR_TECHNIQUES_WEBGL);\n }\n}\n// eslint-disable-next-line\nexport async function encode(gltfData, options): Promise<void> {\n // TODO\n}\n\nfunction resolveTechniques(\n techniquesExtension: {[key: string]: any},\n // programs: {[key: string]: any}[],\n // shaders: {[key: string]: any}[],\n // techniques: {[key: string]: any}[]\n gltfScenegraph\n) {\n const {programs = [], shaders = [], techniques = []} = techniquesExtension;\n const textDecoder = new TextDecoder();\n\n shaders.forEach((shader) => {\n if (Number.isFinite(shader.bufferView)) {\n shader.code = textDecoder.decode(\n gltfScenegraph.getTypedArrayForBufferView(shader.bufferView)\n );\n } else {\n // TODO: handle URI shader\n throw new Error('KHR_techniques_webgl: no shader code');\n }\n });\n\n programs.forEach((program) => {\n program.fragmentShader = shaders[program.fragmentShader];\n program.vertexShader = shaders[program.vertexShader];\n });\n\n techniques.forEach((technique) => {\n technique.program = programs[technique.program];\n });\n\n return techniques;\n}\n\nfunction resolveValues(technique, gltfScenegraph) {\n const values = Object.assign({}, technique.values);\n\n // merge values from uniforms\n Object.keys(technique.uniforms || {}).forEach((uniform) => {\n if (technique.uniforms[uniform].value && !(uniform in values)) {\n values[uniform] = technique.uniforms[uniform].value;\n }\n });\n\n // resolve textures\n Object.keys(values).forEach((uniform) => {\n if (typeof values[uniform] === 'object' && values[uniform].index !== undefined) {\n // Assume this is a texture\n // TODO: find if there are any other types that can be referenced\n values[uniform].texture = gltfScenegraph.getTexture(values[uniform].index);\n }\n });\n\n return values;\n}\n"],"mappings":";;AAKA,OAAOA,cAAc,MAAM,2BAA2B;AAEtD,MAAMC,oBAAoB,GAAG,sBAAsB;AAEnD,OAAO,MAAMC,IAAI,GAAGD,oBAAoB;AAExC,OAAO,eAAeE,MAAM,CAACC,QAAsB,EAAiB;EAClE,MAAMC,cAAc,GAAG,IAAIL,cAAc,CAACI,QAAQ,CAAC;EACnD,MAAM;IAACE;EAAI,CAAC,GAAGD,cAAc;EAE7B,MAAME,SAAS,GAAGF,cAAc,CAACG,YAAY,CAACP,oBAAoB,CAAC;EACnE,IAAIM,SAAS,EAAE;IACb,MAAME,UAAU,GAAGC,iBAAiB,CAACH,SAAS,EAAEF,cAAc,CAAC;IAE/D,KAAK,MAAMM,QAAQ,IAAIL,IAAI,CAACM,SAAS,IAAI,EAAE,EAAE;MAC3C,MAAMC,iBAAiB,GAAGR,cAAc,CAACS,kBAAkB,CAACH,QAAQ,EAAEV,oBAAoB,CAAC;MAC3F,IAAIY,iBAAiB,EAAE;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