@loaders.gl/gltf 4.0.0-alpha.23 → 4.0.0-alpha.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/dist/dist.min.js +378 -241
  2. package/dist/es5/index.js +12 -0
  3. package/dist/es5/index.js.map +1 -1
  4. package/dist/es5/lib/api/gltf-extensions.js +1 -1
  5. package/dist/es5/lib/api/gltf-extensions.js.map +1 -1
  6. package/dist/es5/lib/extensions/EXT_mesh_features.js +13 -25
  7. package/dist/es5/lib/extensions/EXT_mesh_features.js.map +1 -1
  8. package/dist/es5/lib/extensions/EXT_structural_metadata.js +152 -106
  9. package/dist/es5/lib/extensions/EXT_structural_metadata.js.map +1 -1
  10. package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js +64 -16
  11. package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -1
  12. package/dist/es5/lib/extensions/{data-processing.js → utils/3d-tiles-utils.js} +51 -24
  13. package/dist/es5/lib/extensions/utils/3d-tiles-utils.js.map +1 -0
  14. package/dist/es5/lib/gltf-utils/gltf-utils.js +29 -0
  15. package/dist/es5/lib/gltf-utils/gltf-utils.js.map +1 -1
  16. package/dist/es5/lib/types/gltf-ext-feature-metadata-schema.js +2 -0
  17. package/dist/es5/lib/types/gltf-ext-feature-metadata-schema.js.map +1 -0
  18. package/dist/es5/lib/types/gltf-ext-mesh-features-schema.js.map +1 -1
  19. package/dist/es5/lib/types/gltf-ext-structural-metadata-schema.js.map +1 -1
  20. package/dist/es5/lib/types/gltf-json-schema.js.map +1 -1
  21. package/dist/es5/lib/types/gltf-types.js.map +1 -1
  22. package/dist/es5/lib/utils/version.js +1 -1
  23. package/dist/esm/index.js +2 -0
  24. package/dist/esm/index.js.map +1 -1
  25. package/dist/esm/lib/api/gltf-extensions.js +1 -1
  26. package/dist/esm/lib/api/gltf-extensions.js.map +1 -1
  27. package/dist/esm/lib/extensions/EXT_mesh_features.js +13 -25
  28. package/dist/esm/lib/extensions/EXT_mesh_features.js.map +1 -1
  29. package/dist/esm/lib/extensions/EXT_structural_metadata.js +127 -89
  30. package/dist/esm/lib/extensions/EXT_structural_metadata.js.map +1 -1
  31. package/dist/esm/lib/extensions/deprecated/EXT_feature_metadata.js +64 -17
  32. package/dist/esm/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -1
  33. package/dist/esm/lib/extensions/{data-processing.js → utils/3d-tiles-utils.js} +50 -24
  34. package/dist/esm/lib/extensions/utils/3d-tiles-utils.js.map +1 -0
  35. package/dist/esm/lib/gltf-utils/gltf-utils.js +30 -0
  36. package/dist/esm/lib/gltf-utils/gltf-utils.js.map +1 -1
  37. package/dist/esm/lib/types/gltf-ext-feature-metadata-schema.js +2 -0
  38. package/dist/esm/lib/types/gltf-ext-feature-metadata-schema.js.map +1 -0
  39. package/dist/esm/lib/types/gltf-ext-mesh-features-schema.js.map +1 -1
  40. package/dist/esm/lib/types/gltf-ext-structural-metadata-schema.js.map +1 -1
  41. package/dist/esm/lib/types/gltf-json-schema.js.map +1 -1
  42. package/dist/esm/lib/types/gltf-types.js.map +1 -1
  43. package/dist/esm/lib/utils/version.js +1 -1
  44. package/dist/index.d.ts +6 -3
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/lib/extensions/EXT_mesh_features.d.ts.map +1 -1
  47. package/dist/lib/extensions/EXT_structural_metadata.d.ts +12 -4
  48. package/dist/lib/extensions/EXT_structural_metadata.d.ts.map +1 -1
  49. package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts +9 -0
  50. package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts.map +1 -1
  51. package/dist/lib/extensions/utils/3d-tiles-utils.d.ts +52 -0
  52. package/dist/lib/extensions/utils/3d-tiles-utils.d.ts.map +1 -0
  53. package/dist/lib/gltf-utils/gltf-utils.d.ts +2 -0
  54. package/dist/lib/gltf-utils/gltf-utils.d.ts.map +1 -1
  55. package/dist/lib/types/gltf-ext-feature-metadata-schema.d.ts +421 -0
  56. package/dist/lib/types/gltf-ext-feature-metadata-schema.d.ts.map +1 -0
  57. package/dist/lib/types/gltf-ext-mesh-features-schema.d.ts +4 -6
  58. package/dist/lib/types/gltf-ext-mesh-features-schema.d.ts.map +1 -1
  59. package/dist/lib/types/gltf-ext-structural-metadata-schema.d.ts +48 -29
  60. package/dist/lib/types/gltf-ext-structural-metadata-schema.d.ts.map +1 -1
  61. package/dist/lib/types/gltf-json-schema.d.ts +1 -420
  62. package/dist/lib/types/gltf-json-schema.d.ts.map +1 -1
  63. package/dist/lib/types/gltf-types.d.ts +3 -0
  64. package/dist/lib/types/gltf-types.d.ts.map +1 -1
  65. package/package.json +6 -6
  66. package/src/index.ts +10 -5
  67. package/src/lib/api/gltf-extensions.ts +1 -1
  68. package/src/lib/extensions/EXT_mesh_features.ts +18 -44
  69. package/src/lib/extensions/EXT_structural_metadata.ts +364 -217
  70. package/src/lib/extensions/deprecated/EXT_feature_metadata.ts +193 -30
  71. package/src/lib/extensions/{data-processing.ts → utils/3d-tiles-utils.ts} +128 -56
  72. package/src/lib/gltf-utils/gltf-utils.ts +38 -0
  73. package/src/lib/types/gltf-ext-feature-metadata-schema.ts +470 -0
  74. package/src/lib/types/gltf-ext-mesh-features-schema.ts +4 -6
  75. package/src/lib/types/gltf-ext-structural-metadata-schema.ts +52 -31
  76. package/src/lib/types/gltf-json-schema.ts +1 -468
  77. package/src/lib/types/gltf-types.ts +4 -0
  78. package/dist/bundle.js +0 -5
  79. package/dist/es5/lib/extensions/data-processing.js.map +0 -1
  80. package/dist/esm/lib/extensions/data-processing.js.map +0 -1
  81. package/dist/glb-loader.js +0 -34
  82. package/dist/glb-writer.js +0 -35
  83. package/dist/gltf-loader.js +0 -50
  84. package/dist/gltf-writer.js +0 -32
  85. package/dist/index.js +0 -34
  86. package/dist/lib/api/gltf-extensions.js +0 -88
  87. package/dist/lib/api/gltf-scenegraph.js +0 -580
  88. package/dist/lib/api/normalize-gltf-v1.js +0 -299
  89. package/dist/lib/api/post-process-gltf.js +0 -433
  90. package/dist/lib/encoders/encode-glb.js +0 -72
  91. package/dist/lib/encoders/encode-gltf.js +0 -32
  92. package/dist/lib/extensions/EXT_mesh_features.js +0 -89
  93. package/dist/lib/extensions/EXT_meshopt_compression.js +0 -41
  94. package/dist/lib/extensions/EXT_structural_metadata.js +0 -504
  95. package/dist/lib/extensions/EXT_texture_webp.js +0 -36
  96. package/dist/lib/extensions/KHR_binary_gltf.js +0 -39
  97. package/dist/lib/extensions/KHR_draco_mesh_compression.js +0 -137
  98. package/dist/lib/extensions/KHR_texture_basisu.js +0 -29
  99. package/dist/lib/extensions/KHR_texture_transform.js +0 -227
  100. package/dist/lib/extensions/data-processing.d.ts +0 -34
  101. package/dist/lib/extensions/data-processing.d.ts.map +0 -1
  102. package/dist/lib/extensions/data-processing.js +0 -212
  103. package/dist/lib/extensions/deprecated/EXT_feature_metadata.js +0 -282
  104. package/dist/lib/extensions/deprecated/KHR_lights_punctual.js +0 -59
  105. package/dist/lib/extensions/deprecated/KHR_materials_unlit.js +0 -44
  106. package/dist/lib/extensions/deprecated/KHR_techniques_webgl.js +0 -79
  107. package/dist/lib/gltf-utils/get-typed-array.js +0 -41
  108. package/dist/lib/gltf-utils/gltf-attribute-utils.js +0 -73
  109. package/dist/lib/gltf-utils/gltf-constants.js +0 -43
  110. package/dist/lib/gltf-utils/gltf-utils.js +0 -90
  111. package/dist/lib/gltf-utils/resolve-url.js +0 -18
  112. package/dist/lib/parsers/parse-glb.js +0 -166
  113. package/dist/lib/parsers/parse-gltf.js +0 -185
  114. package/dist/lib/types/glb-types.js +0 -2
  115. package/dist/lib/types/gltf-ext-mesh-features-schema.js +0 -2
  116. package/dist/lib/types/gltf-ext-structural-metadata-schema.js +0 -2
  117. package/dist/lib/types/gltf-json-schema.js +0 -4
  118. package/dist/lib/types/gltf-postprocessed-schema.js +0 -4
  119. package/dist/lib/types/gltf-types.js +0 -3
  120. package/dist/lib/utils/assert.js +0 -12
  121. package/dist/lib/utils/version.js +0 -7
  122. package/dist/meshopt/meshopt-decoder.js +0 -118
  123. package/dist/webp/webp.js +0 -38
@@ -1,282 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.decode = exports.name = void 0;
4
- const gltf_scenegraph_1 = require("../../api/gltf-scenegraph");
5
- const images_1 = require("@loaders.gl/images");
6
- const gltf_utils_1 = require("../../gltf-utils/gltf-utils");
7
- const math_1 = require("@loaders.gl/math");
8
- /** Extension name */
9
- const EXT_FEATURE_METADATA_NAME = 'EXT_feature_metadata';
10
- exports.name = EXT_FEATURE_METADATA_NAME;
11
- async function decode(gltfData, options) {
12
- const scenegraph = new gltf_scenegraph_1.GLTFScenegraph(gltfData);
13
- decodeExtFeatureMetadata(scenegraph, options);
14
- }
15
- exports.decode = decode;
16
- /**
17
- * Decodes feature metadata from extension
18
- * @param scenegraph
19
- */
20
- function decodeExtFeatureMetadata(scenegraph, options) {
21
- const extension = scenegraph.getExtension(EXT_FEATURE_METADATA_NAME);
22
- if (!extension)
23
- return;
24
- const schemaClasses = extension.schema?.classes;
25
- const { featureTables } = extension;
26
- if (schemaClasses && featureTables) {
27
- for (const schemaName in schemaClasses) {
28
- const schemaClass = schemaClasses[schemaName];
29
- const featureTable = findFeatureTableByName(featureTables, schemaName);
30
- if (featureTable) {
31
- handleFeatureTableProperties(scenegraph, featureTable, schemaClass);
32
- }
33
- }
34
- }
35
- const { featureTextures } = extension;
36
- if (schemaClasses && featureTextures && options.gltf?.loadImages) {
37
- for (const schemaName in schemaClasses) {
38
- const schemaClass = schemaClasses[schemaName];
39
- const featureTexture = findFeatureTextureByName(featureTextures, schemaName);
40
- if (featureTexture) {
41
- handleFeatureTextureProperties(scenegraph, featureTexture, schemaClass);
42
- }
43
- }
44
- }
45
- }
46
- /**
47
- * Navigates through all properies in feature table and gets properties data.
48
- * @param scenegraph
49
- * @param featureTable
50
- * @param schemaClass
51
- */
52
- function handleFeatureTableProperties(scenegraph, featureTable, schemaClass) {
53
- for (const propertyName in schemaClass.properties) {
54
- const schemaProperty = schemaClass.properties[propertyName];
55
- const featureTableProperty = featureTable?.properties?.[propertyName];
56
- const numberOfFeatures = featureTable.count;
57
- if (featureTableProperty) {
58
- const data = getPropertyDataFromBinarySource(scenegraph, schemaProperty, numberOfFeatures, featureTableProperty);
59
- featureTableProperty.data = data;
60
- }
61
- }
62
- }
63
- /**
64
- * Navigates through all properies in feature texture and gets properties data.
65
- * Data will be stored in featureTexture.properties[propertyName].data
66
- * @param scenegraph
67
- * @param featureTexture
68
- * @param schemaClass
69
- */
70
- function handleFeatureTextureProperties(scenegraph, featureTexture, schemaClass) {
71
- const attributeName = featureTexture.class;
72
- for (const propertyName in schemaClass.properties) {
73
- const featureTextureProperty = featureTexture?.properties?.[propertyName];
74
- if (featureTextureProperty) {
75
- const data = getPropertyDataFromTexture(scenegraph, featureTextureProperty, attributeName);
76
- featureTextureProperty.data = data;
77
- }
78
- }
79
- }
80
- /**
81
- * Decode properties from binary sourse based on property type.
82
- * @param scenegraph
83
- * @param schemaProperty
84
- * @param numberOfFeatures
85
- * @param featureTableProperty
86
- */
87
- function getPropertyDataFromBinarySource(scenegraph, schemaProperty, numberOfFeatures, featureTableProperty) {
88
- const bufferView = featureTableProperty.bufferView;
89
- // TODO think maybe we shouldn't get data only in Uint8Array format.
90
- const dataArray = scenegraph.getTypedArrayForBufferView(bufferView);
91
- switch (schemaProperty.type) {
92
- case 'STRING': {
93
- // stringOffsetBufferView should be available for string type.
94
- const stringOffsetBufferView = featureTableProperty.stringOffsetBufferView;
95
- const offsetsData = scenegraph.getTypedArrayForBufferView(stringOffsetBufferView);
96
- return getStringAttributes(dataArray, offsetsData, numberOfFeatures);
97
- }
98
- default:
99
- }
100
- return dataArray;
101
- }
102
- /**
103
- * Get properties from texture associated with all mesh primitives.
104
- * @param scenegraph
105
- * @param featureTextureProperty
106
- * @param attributeName
107
- * @returns Feature texture data
108
- */
109
- function getPropertyDataFromTexture(scenegraph, featureTextureProperty, attributeName) {
110
- const json = scenegraph.gltf.json;
111
- if (!json.meshes) {
112
- return [];
113
- }
114
- const featureTextureTable = [];
115
- for (const mesh of json.meshes) {
116
- for (const primitive of mesh.primitives) {
117
- processPrimitiveTextures(scenegraph, attributeName, featureTextureProperty, featureTextureTable, primitive);
118
- }
119
- }
120
- return featureTextureTable;
121
- }
122
- // eslint-disable-next-line max-statements
123
- /**
124
- * Processes data encoded in the texture associated with the primitive. This data will be accessible through the attributes.
125
- * @param scenegraph
126
- * @param attributeName
127
- * @param featureTextureProperty
128
- * @param featureTextureTable
129
- * @param primitive
130
- */
131
- // eslint-disable-next-line max-statements
132
- function processPrimitiveTextures(scenegraph, attributeName, featureTextureProperty, featureTextureTable, primitive) {
133
- /*
134
- texture.index is an index for the "textures" array.
135
- The texture object referenced by this index looks like this:
136
- {
137
- "sampler": 0,
138
- "source": 0
139
- }
140
- "sampler" is an index for the "samplers" array
141
- "source" is an index for the "images" array that contains data. These data are stored in rgba channels of the image.
142
-
143
- texture.texCoord is a number-suffix (like 1) for an attribute like "TEXCOORD_1" in meshes.primitives
144
- The value of "TEXCOORD_1" is an accessor that is used to get coordinates. These coordinates ared used to get data from the image.
145
- */
146
- const json = scenegraph.gltf.json;
147
- const textureData = [];
148
- const texCoordAccessorKey = `TEXCOORD_${featureTextureProperty.texture.texCoord}`;
149
- const texCoordAccessorIndex = primitive.attributes[texCoordAccessorKey];
150
- const texCoordBufferView = scenegraph.getBufferView(texCoordAccessorIndex);
151
- const texCoordArray = scenegraph.getTypedArrayForBufferView(texCoordBufferView);
152
- const textureCoordinates = new Float32Array(texCoordArray.buffer, texCoordArray.byteOffset, texCoordArray.length / 4);
153
- // textureCoordinates contains UV coordinates of the actual data stored in the texture
154
- // accessor.count is a number of UV pairs (they are stored as VEC2)
155
- const textureIndex = featureTextureProperty.texture.index;
156
- const texture = json.textures?.[textureIndex];
157
- const imageIndex = texture?.source;
158
- if (typeof imageIndex !== 'undefined') {
159
- const image = json.images?.[imageIndex];
160
- const mimeType = image?.mimeType;
161
- const parsedImage = scenegraph.gltf.images?.[imageIndex];
162
- if (parsedImage) {
163
- for (let index = 0; index < textureCoordinates.length; index += 2) {
164
- const value = getImageValueByCoordinates(parsedImage, mimeType, textureCoordinates, index, featureTextureProperty.channels);
165
- textureData.push(value);
166
- }
167
- }
168
- }
169
- /*
170
- featureTextureTable will contain unique values, e.g.
171
- textureData = [24, 35, 28, 24]
172
- featureTextureTable = [24, 35, 28]
173
- featureIndices will contain indices hat refer featureTextureTable, e.g.
174
- featureIndices = [0, 1, 2, 0]
175
- */
176
- const featureIndices = [];
177
- for (const texelData of textureData) {
178
- let index = featureTextureTable.findIndex((item) => item === texelData);
179
- if (index === -1) {
180
- index = featureTextureTable.push(texelData) - 1;
181
- }
182
- featureIndices.push(index);
183
- }
184
- const typedArray = new Uint32Array(featureIndices);
185
- const bufferIndex = scenegraph.gltf.buffers.push({
186
- arrayBuffer: typedArray.buffer,
187
- byteOffset: 0,
188
- byteLength: typedArray.byteLength
189
- }) - 1;
190
- const bufferViewIndex = scenegraph.addBufferView(typedArray, bufferIndex, 0);
191
- const accessorIndex = scenegraph.addAccessor(bufferViewIndex, {
192
- size: 1,
193
- componentType: (0, gltf_utils_1.getComponentTypeFromArray)(typedArray),
194
- count: typedArray.length
195
- });
196
- primitive.attributes[attributeName] = accessorIndex;
197
- }
198
- function getImageValueByCoordinates(parsedImage, mimeType, textureCoordinates, index, channels) {
199
- const CHANNELS_MAP = {
200
- r: { offset: 0, shift: 0 },
201
- g: { offset: 1, shift: 8 },
202
- b: { offset: 2, shift: 16 },
203
- a: { offset: 3, shift: 24 }
204
- };
205
- const u = textureCoordinates[index];
206
- const v = textureCoordinates[index + 1];
207
- let components = 1;
208
- if (mimeType && (mimeType.indexOf('image/jpeg') !== -1 || mimeType.indexOf('image/png') !== -1))
209
- components = 4;
210
- const offset = coordinatesToOffset(u, v, parsedImage, components);
211
- let value = 0;
212
- for (const c of channels) {
213
- const map = CHANNELS_MAP[c];
214
- const val = getVal(parsedImage, offset + map.offset);
215
- value |= val << map.shift;
216
- }
217
- return value;
218
- }
219
- function getVal(parsedImage, offset) {
220
- const imageData = (0, images_1.getImageData)(parsedImage);
221
- if (imageData.data.length <= offset) {
222
- throw new Error(`${imageData.data.length} <= ${offset}`);
223
- }
224
- return imageData.data[offset];
225
- }
226
- function coordinatesToOffset(u, v, parsedImage, componentsCount = 1) {
227
- const w = parsedImage.width;
228
- const iX = (0, math_1.emod)(u) * (w - 1);
229
- const indX = Math.round(iX);
230
- const h = parsedImage.height;
231
- const iY = (0, math_1.emod)(v) * (h - 1);
232
- const indY = Math.round(iY);
233
- const components = parsedImage.components ? parsedImage.components : componentsCount;
234
- // components is a number of channels in the image
235
- const offset = (indY * w + indX) * components;
236
- return offset;
237
- }
238
- /**
239
- * Find the feature table by class name.
240
- * @param featureTables
241
- * @param schemaClassName
242
- */
243
- function findFeatureTableByName(featureTables, schemaClassName) {
244
- for (const featureTableName in featureTables) {
245
- const featureTable = featureTables[featureTableName];
246
- if (featureTable.class === schemaClassName) {
247
- return featureTable;
248
- }
249
- }
250
- return null;
251
- }
252
- function findFeatureTextureByName(featureTextures, schemaClassName) {
253
- for (const featureTexturesName in featureTextures) {
254
- const featureTable = featureTextures[featureTexturesName];
255
- if (featureTable.class === schemaClassName) {
256
- return featureTable;
257
- }
258
- }
259
- return null;
260
- }
261
- /**
262
- * Getting string attributes from binary data.
263
- * Spec - https://github.com/CesiumGS/3d-tiles/tree/main/specification/Metadata#strings
264
- * @param data
265
- * @param offsetsData
266
- * @param stringsCount
267
- */
268
- function getStringAttributes(data, offsetsData, stringsCount) {
269
- const stringsArray = [];
270
- const textDecoder = new TextDecoder('utf8');
271
- let stringOffset = 0;
272
- const bytesPerStringSize = 4;
273
- for (let index = 0; index < stringsCount; index++) {
274
- // TODO check if it is multiplication on bytesPerStringSize is valid operation?
275
- const stringByteSize = offsetsData[(index + 1) * bytesPerStringSize] - offsetsData[index * bytesPerStringSize];
276
- const stringData = data.subarray(stringOffset, stringByteSize + stringOffset);
277
- const stringAttribute = textDecoder.decode(stringData);
278
- stringsArray.push(stringAttribute);
279
- stringOffset += stringByteSize;
280
- }
281
- return stringsArray;
282
- }
@@ -1,59 +0,0 @@
1
- "use strict";
2
- // GLTF EXTENSION: KHR_lights_punctual
3
- // https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_lights_punctual
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.encode = exports.decode = exports.name = void 0;
6
- const assert_1 = require("../../utils/assert");
7
- const gltf_scenegraph_1 = require("../../api/gltf-scenegraph");
8
- const KHR_LIGHTS_PUNCTUAL = 'KHR_lights_punctual';
9
- exports.name = KHR_LIGHTS_PUNCTUAL;
10
- async function decode(gltfData) {
11
- const gltfScenegraph = new gltf_scenegraph_1.GLTFScenegraph(gltfData);
12
- const { json } = gltfScenegraph;
13
- // Move the light array out of the extension and remove the extension
14
- const extension = gltfScenegraph.getExtension(KHR_LIGHTS_PUNCTUAL);
15
- if (extension) {
16
- // @ts-ignore
17
- gltfScenegraph.json.lights = extension.lights;
18
- gltfScenegraph.removeExtension(KHR_LIGHTS_PUNCTUAL);
19
- }
20
- // Any nodes that have the extension, add lights field pointing to light object
21
- // and remove the extension
22
- for (const node of json.nodes || []) {
23
- const nodeExtension = gltfScenegraph.getObjectExtension(node, KHR_LIGHTS_PUNCTUAL);
24
- if (nodeExtension) {
25
- // @ts-ignore
26
- node.light = nodeExtension.light;
27
- }
28
- gltfScenegraph.removeObjectExtension(node, KHR_LIGHTS_PUNCTUAL);
29
- }
30
- }
31
- exports.decode = decode;
32
- // Move the light ar ray out of the extension and remove the extension
33
- async function encode(gltfData) {
34
- const gltfScenegraph = new gltf_scenegraph_1.GLTFScenegraph(gltfData);
35
- const { json } = gltfScenegraph;
36
- // @ts-ignore
37
- if (json.lights) {
38
- const extension = gltfScenegraph.addExtension(KHR_LIGHTS_PUNCTUAL);
39
- // @ts-ignore
40
- (0, assert_1.assert)(!extension.lights);
41
- // @ts-ignore
42
- extension.lights = json.lights;
43
- // @ts-ignore
44
- delete json.lights;
45
- }
46
- // Any nodes that have lights field pointing to light object
47
- // add the extension
48
- // @ts-ignore
49
- if (gltfScenegraph.json.lights) {
50
- // @ts-ignore
51
- for (const light of gltfScenegraph.json.lights) {
52
- const node = light.node;
53
- gltfScenegraph.addObjectExtension(node, KHR_LIGHTS_PUNCTUAL, light);
54
- }
55
- // @ts-ignore
56
- delete gltfScenegraph.json.lights;
57
- }
58
- }
59
- exports.encode = encode;
@@ -1,44 +0,0 @@
1
- "use strict";
2
- // GLTF EXTENSION: KHR_materials_unlit
3
- // https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.encode = exports.decode = exports.name = void 0;
6
- const gltf_scenegraph_1 = require("../../api/gltf-scenegraph");
7
- const KHR_MATERIALS_UNLIT = 'KHR_materials_unlit';
8
- exports.name = KHR_MATERIALS_UNLIT;
9
- async function decode(gltfData) {
10
- const gltfScenegraph = new gltf_scenegraph_1.GLTFScenegraph(gltfData);
11
- const { json } = gltfScenegraph;
12
- // Any nodes that have the extension, add lights field pointing to light object
13
- // and remove the extension
14
- for (const material of json.materials || []) {
15
- const extension = material.extensions && material.extensions.KHR_materials_unlit;
16
- if (extension) {
17
- // @ts-ignore TODO
18
- material.unlit = true;
19
- }
20
- gltfScenegraph.removeObjectExtension(material, KHR_MATERIALS_UNLIT);
21
- }
22
- // Remove the top-level extension
23
- gltfScenegraph.removeExtension(KHR_MATERIALS_UNLIT);
24
- }
25
- exports.decode = decode;
26
- function encode(gltfData) {
27
- const gltfScenegraph = new gltf_scenegraph_1.GLTFScenegraph(gltfData);
28
- const { json } = gltfScenegraph;
29
- // Any nodes that have lights field pointing to light object
30
- // add the extension
31
- // @ts-ignore
32
- if (gltfScenegraph.materials) {
33
- for (const material of json.materials || []) {
34
- // @ts-ignore
35
- if (material.unlit) {
36
- // @ts-ignore
37
- delete material.unlit;
38
- gltfScenegraph.addObjectExtension(material, KHR_MATERIALS_UNLIT, {});
39
- gltfScenegraph.addExtension(KHR_MATERIALS_UNLIT);
40
- }
41
- }
42
- }
43
- }
44
- exports.encode = encode;
@@ -1,79 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.encode = exports.decode = exports.name = void 0;
6
- const gltf_scenegraph_1 = require("../../api/gltf-scenegraph");
7
- const KHR_TECHNIQUES_WEBGL = 'KHR_techniques_webgl';
8
- exports.name = KHR_TECHNIQUES_WEBGL;
9
- async function decode(gltfData) {
10
- const gltfScenegraph = new gltf_scenegraph_1.GLTFScenegraph(gltfData);
11
- const { json } = gltfScenegraph;
12
- const extension = gltfScenegraph.getExtension(KHR_TECHNIQUES_WEBGL);
13
- if (extension) {
14
- const techniques = resolveTechniques(extension, gltfScenegraph);
15
- for (const material of json.materials || []) {
16
- const materialExtension = gltfScenegraph.getObjectExtension(material, KHR_TECHNIQUES_WEBGL);
17
- if (materialExtension) {
18
- // @ts-ignore TODO
19
- material.technique = Object.assign({}, materialExtension,
20
- // @ts-ignore
21
- techniques[materialExtension.technique]);
22
- // @ts-ignore TODO
23
- material.technique.values = resolveValues(material.technique, gltfScenegraph);
24
- }
25
- gltfScenegraph.removeObjectExtension(material, KHR_TECHNIQUES_WEBGL);
26
- }
27
- // Remove the top-level extension
28
- gltfScenegraph.removeExtension(KHR_TECHNIQUES_WEBGL);
29
- }
30
- }
31
- exports.decode = decode;
32
- // eslint-disable-next-line
33
- async function encode(gltfData, options) {
34
- // TODO
35
- }
36
- exports.encode = encode;
37
- function resolveTechniques(techniquesExtension,
38
- // programs: {[key: string]: any}[],
39
- // shaders: {[key: string]: any}[],
40
- // techniques: {[key: string]: any}[]
41
- gltfScenegraph) {
42
- const { programs = [], shaders = [], techniques = [] } = techniquesExtension;
43
- const textDecoder = new TextDecoder();
44
- shaders.forEach((shader) => {
45
- if (Number.isFinite(shader.bufferView)) {
46
- shader.code = textDecoder.decode(gltfScenegraph.getTypedArrayForBufferView(shader.bufferView));
47
- }
48
- else {
49
- // TODO: handle URI shader
50
- throw new Error('KHR_techniques_webgl: no shader code');
51
- }
52
- });
53
- programs.forEach((program) => {
54
- program.fragmentShader = shaders[program.fragmentShader];
55
- program.vertexShader = shaders[program.vertexShader];
56
- });
57
- techniques.forEach((technique) => {
58
- technique.program = programs[technique.program];
59
- });
60
- return techniques;
61
- }
62
- function resolveValues(technique, gltfScenegraph) {
63
- const values = Object.assign({}, technique.values);
64
- // merge values from uniforms
65
- Object.keys(technique.uniforms || {}).forEach((uniform) => {
66
- if (technique.uniforms[uniform].value && !(uniform in values)) {
67
- values[uniform] = technique.uniforms[uniform].value;
68
- }
69
- });
70
- // resolve textures
71
- Object.keys(values).forEach((uniform) => {
72
- if (typeof values[uniform] === 'object' && values[uniform].index !== undefined) {
73
- // Assume this is a texture
74
- // TODO: find if there are any other types that can be referenced
75
- values[uniform].texture = gltfScenegraph.getTexture(values[uniform].index);
76
- }
77
- });
78
- return values;
79
- }
@@ -1,41 +0,0 @@
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
- */
@@ -1,73 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getGLTFAccessor = exports.getGLTFAccessors = void 0;
4
- // TODO - remove
5
- const gltf_utils_1 = require("./gltf-utils");
6
- // Returns a fresh attributes object with glTF-standardized attributes names
7
- // Attributes that cannot be identified will not be included
8
- // Removes `indices` if present, as it should be stored separately from the attributes
9
- function getGLTFAccessors(attributes) {
10
- const accessors = {};
11
- for (const name in attributes) {
12
- const attribute = attributes[name];
13
- if (name !== 'indices') {
14
- const glTFAccessor = getGLTFAccessor(attribute);
15
- accessors[name] = glTFAccessor;
16
- }
17
- }
18
- return accessors;
19
- }
20
- exports.getGLTFAccessors = getGLTFAccessors;
21
- // Fix up a single accessor.
22
- // Input: typed array or a partial accessor object
23
- // Return: accessor object
24
- function getGLTFAccessor(attribute) {
25
- const { buffer, size, count } = getAccessorData(attribute);
26
- const glTFAccessor = {
27
- // glTF Accessor values
28
- // TODO: Instead of a bufferView index we could have an actual buffer (typed array)
29
- // bufferView: null,
30
- // TODO: Deprecate `value` in favor of bufferView?
31
- // @ts-ignore
32
- value: buffer,
33
- size,
34
- byteOffset: 0,
35
- count,
36
- type: (0, gltf_utils_1.getAccessorTypeFromSize)(size),
37
- componentType: (0, gltf_utils_1.getComponentTypeFromArray)(buffer)
38
- };
39
- return glTFAccessor;
40
- }
41
- exports.getGLTFAccessor = getGLTFAccessor;
42
- // export function getGLTFAttribute(data, gltfAttributeName): GLTFAccessor {
43
- // return data.attributes[data.glTFAttributeMap[gltfAttributeName]];
44
- // }
45
- function getAccessorData(attribute) {
46
- let buffer = attribute;
47
- let size = 1;
48
- let count = 0;
49
- if (attribute && attribute.value) {
50
- buffer = attribute.value;
51
- size = attribute.size || 1;
52
- }
53
- if (buffer) {
54
- if (!ArrayBuffer.isView(buffer)) {
55
- buffer = toTypedArray(buffer, Float32Array);
56
- }
57
- count = buffer.length / size;
58
- }
59
- return { buffer, size, count };
60
- }
61
- // Convert non-typed arrays to arrays of specified format
62
- function toTypedArray(array, ArrayType, convertTypedArrays = false) {
63
- if (!array) {
64
- return null;
65
- }
66
- if (Array.isArray(array)) {
67
- return new ArrayType(array);
68
- }
69
- if (convertTypedArrays && !(array instanceof ArrayType)) {
70
- return new ArrayType(array);
71
- }
72
- return array;
73
- }
@@ -1,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getGLEnumFromSamplerParameter = exports.getSizeFromAccessorType = exports.getBytesFromComponentType = exports.BYTES = exports.COMPONENTS = void 0;
4
- exports.COMPONENTS = {
5
- SCALAR: 1,
6
- VEC2: 2,
7
- VEC3: 3,
8
- VEC4: 4,
9
- MAT2: 4,
10
- MAT3: 9,
11
- MAT4: 16
12
- };
13
- exports.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 exports.BYTES[componentType];
24
- }
25
- exports.getBytesFromComponentType = getBytesFromComponentType;
26
- function getSizeFromAccessorType(type) {
27
- return exports.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;