@loaders.gl/tile-converter 3.4.11 → 3.4.12

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 (53) hide show
  1. package/dist/3d-tiles-attributes-worker.js +1 -1
  2. package/dist/converter.min.js +58 -58
  3. package/dist/dist.min.js +11 -26
  4. package/dist/es5/3d-tiles-attributes-worker.js +1 -1
  5. package/dist/es5/deps-installer/deps-installer.js +1 -1
  6. package/dist/es5/i3s-attributes-worker.js +1 -1
  7. package/dist/es5/pgm-loader.js +1 -1
  8. package/dist/esm/3d-tiles-attributes-worker.js +1 -1
  9. package/dist/esm/deps-installer/deps-installer.js +1 -1
  10. package/dist/esm/i3s-attributes-worker.js +1 -1
  11. package/dist/esm/pgm-loader.js +1 -1
  12. package/package.json +15 -15
  13. package/dist/3d-tiles-converter/3d-tiles-converter.js +0 -287
  14. package/dist/3d-tiles-converter/helpers/b3dm-converter.js +0 -282
  15. package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +0 -23
  16. package/dist/3d-tiles-converter/helpers/texture-atlas.js +0 -52
  17. package/dist/3d-tiles-converter/json-templates/tileset.js +0 -43
  18. package/dist/bundle.js +0 -5
  19. package/dist/constants.js +0 -4
  20. package/dist/converter-cli.js +0 -280
  21. package/dist/deps-installer/deps-installer.js +0 -63
  22. package/dist/i3s-converter/helpers/batch-ids-extensions.js +0 -141
  23. package/dist/i3s-converter/helpers/coordinate-converter.js +0 -124
  24. package/dist/i3s-converter/helpers/create-scene-server-path.js +0 -28
  25. package/dist/i3s-converter/helpers/feature-attributes.js +0 -216
  26. package/dist/i3s-converter/helpers/geometry-attributes.js +0 -202
  27. package/dist/i3s-converter/helpers/geometry-converter.js +0 -1195
  28. package/dist/i3s-converter/helpers/gltf-attributes.js +0 -88
  29. package/dist/i3s-converter/helpers/node-debug.js +0 -120
  30. package/dist/i3s-converter/helpers/node-index-document.js +0 -250
  31. package/dist/i3s-converter/helpers/node-pages.js +0 -316
  32. package/dist/i3s-converter/i3s-converter.js +0 -890
  33. package/dist/i3s-converter/json-templates/geometry-definitions.js +0 -87
  34. package/dist/i3s-converter/json-templates/layers.js +0 -139
  35. package/dist/i3s-converter/json-templates/metadata.js +0 -25
  36. package/dist/i3s-converter/json-templates/node.js +0 -89
  37. package/dist/i3s-converter/json-templates/scene-server.js +0 -31
  38. package/dist/i3s-converter/json-templates/shared-resources.js +0 -129
  39. package/dist/i3s-converter/json-templates/store.js +0 -103
  40. package/dist/i3s-converter/types.js +0 -2
  41. package/dist/i3s-server/app.js +0 -14
  42. package/dist/i3s-server/controllers/index-controller.js +0 -23
  43. package/dist/i3s-server/routes/index.js +0 -16
  44. package/dist/index.js +0 -10
  45. package/dist/lib/utils/compress-util.js +0 -257
  46. package/dist/lib/utils/file-utils.js +0 -138
  47. package/dist/lib/utils/lod-conversion-utils.js +0 -76
  48. package/dist/lib/utils/queue.js +0 -18
  49. package/dist/lib/utils/statistic-utills.js +0 -64
  50. package/dist/lib/utils/write-queue.js +0 -80
  51. package/dist/pgm-loader.js +0 -24
  52. package/dist/workers/3d-tiles-attributes-worker.js +0 -9
  53. package/dist/workers/i3s-attributes-worker.js +0 -5
@@ -1,282 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const core_1 = require("@loaders.gl/core");
4
- const gltf_1 = require("@loaders.gl/gltf");
5
- const _3d_tiles_1 = require("@loaders.gl/3d-tiles");
6
- const core_2 = require("@math.gl/core");
7
- const geospatial_1 = require("@math.gl/geospatial");
8
- const texture_atlas_1 = require("./texture-atlas");
9
- const Z_UP_TO_Y_UP_MATRIX = new core_2.Matrix4([1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1]);
10
- const scratchVector = new core_2.Vector3();
11
- /**
12
- * Converts content of an I3S node to *.b3dm's file content
13
- */
14
- class B3dmConverter {
15
- /**
16
- * The starter of content conversion
17
- * @param i3sTile - Tile3D instance for I3S node
18
- * @returns - encoded content
19
- */
20
- async convert(i3sAttributesData, featureAttributes = null) {
21
- const gltf = await this.buildGltf(i3sAttributesData, featureAttributes);
22
- const b3dm = (0, core_1.encodeSync)({
23
- gltfEncoded: new Uint8Array(gltf),
24
- type: 'b3dm',
25
- featuresLength: this._getFeaturesLength(featureAttributes),
26
- batchTable: featureAttributes
27
- }, _3d_tiles_1.Tile3DWriter);
28
- return b3dm;
29
- }
30
- /**
31
- * Build and encode gltf
32
- * @param i3sTile - Tile3D instance for I3S node
33
- * @returns - encoded glb content
34
- */
35
- async buildGltf(i3sAttributesData, featureAttributes) {
36
- const { tileContent, textureFormat } = i3sAttributesData;
37
- const { material, attributes, indices: originalIndices, cartesianOrigin, cartographicOrigin, modelMatrix } = tileContent;
38
- const gltfBuilder = new gltf_1.GLTFScenegraph();
39
- const textureIndex = await this._addI3sTextureToGltf(tileContent, textureFormat, gltfBuilder);
40
- const pbrMaterialInfo = this._convertI3sMaterialToGltfMaterial(material, textureIndex);
41
- const materialIndex = gltfBuilder.addMaterial(pbrMaterialInfo);
42
- const positions = attributes.positions;
43
- const positionsValue = positions.value;
44
- if (attributes.uvRegions && attributes.texCoords) {
45
- attributes.texCoords.value = (0, texture_atlas_1.convertTextureAtlas)(attributes.texCoords.value, attributes.uvRegions.value);
46
- }
47
- attributes.positions.value = this._normalizePositions(positionsValue, cartesianOrigin, cartographicOrigin, modelMatrix);
48
- this._createBatchIds(tileContent, featureAttributes);
49
- if (attributes.normals && !this._checkNormals(attributes.normals.value)) {
50
- delete attributes.normals;
51
- }
52
- const indices = originalIndices || this._generateSynteticIndices(positionsValue.length / positions.size);
53
- const meshIndex = gltfBuilder.addMesh({
54
- attributes,
55
- indices,
56
- material: materialIndex,
57
- mode: 4
58
- });
59
- const transformMatrix = this._generateTransformMatrix(cartesianOrigin);
60
- const nodeIndex = gltfBuilder.addNode({ meshIndex, matrix: transformMatrix });
61
- const sceneIndex = gltfBuilder.addScene({ nodeIndices: [nodeIndex] });
62
- gltfBuilder.setDefaultScene(sceneIndex);
63
- gltfBuilder.createBinaryChunk();
64
- const gltfBuffer = (0, core_1.encodeSync)(gltfBuilder.gltf, gltf_1.GLTFWriter);
65
- return gltfBuffer;
66
- }
67
- /**
68
- * Update gltfBuilder with texture from I3S tile
69
- * @param {object} i3sTile - Tile3D object
70
- * @param {GLTFScenegraph} gltfBuilder - gltfScenegraph instance to construct GLTF
71
- * @returns {Promise<number | null>} - GLTF texture index
72
- */
73
- async _addI3sTextureToGltf(tileContent, textureFormat, gltfBuilder) {
74
- const { texture, material, attributes } = tileContent;
75
- let textureIndex = null;
76
- let selectedTexture = texture;
77
- if (!texture && material) {
78
- selectedTexture =
79
- material.pbrMetallicRoughness &&
80
- material.pbrMetallicRoughness.baseColorTexture &&
81
- material.pbrMetallicRoughness.baseColorTexture.texture.source.image;
82
- }
83
- if (selectedTexture) {
84
- const mimeType = this._deduceMimeTypeFromFormat(textureFormat);
85
- const imageIndex = gltfBuilder.addImage(selectedTexture, mimeType);
86
- textureIndex = gltfBuilder.addTexture({ imageIndex });
87
- delete attributes.colors;
88
- }
89
- return textureIndex;
90
- }
91
- /**
92
- * Generate a positions array which is correct for 3DTiles/GLTF format
93
- * @param {Float64Array} positionsValue - the input geometry positions array
94
- * @param {number[]} cartesianOrigin - the tile center in the cartesian coordinate system
95
- * @param {number[]} cartographicOrigin - the tile center in the cartographic coordinate system
96
- * @param {number[]} modelMatrix - the model matrix of geometry
97
- * @returns {Float32Array} - the output geometry positions array
98
- */
99
- _normalizePositions(positionsValue, cartesianOrigin, cartographicOrigin, modelMatrix) {
100
- const newPositionsValue = new Float32Array(positionsValue.length);
101
- for (let index = 0; index < positionsValue.length; index += 3) {
102
- const vertex = positionsValue.subarray(index, index + 3);
103
- const cartesianOriginVector = new core_2.Vector3(cartesianOrigin);
104
- let vertexVector = new core_2.Vector3(Array.from(vertex))
105
- .transform(modelMatrix)
106
- .add(cartographicOrigin);
107
- geospatial_1.Ellipsoid.WGS84.cartographicToCartesian(vertexVector, scratchVector);
108
- vertexVector = scratchVector.subtract(cartesianOriginVector);
109
- newPositionsValue.set(vertexVector, index);
110
- }
111
- return newPositionsValue;
112
- }
113
- /**
114
- * Generate the transformation matrix for GLTF node:
115
- * https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#reference-node
116
- * 1. Create the translate transformation from cartesianOrigin (the positions array stores offsets from this cartesianOrigin)
117
- * 2. Create the rotation transformation to rotate model from z-up coordinates (I3S specific) to y-up coordinates (GLTF specific)
118
- * @param {number[]} cartesianOrigin - the tile center in the cartesian coordinate system
119
- * @returns {Matrix4} - an array of 16 numbers (4x4 matrix)
120
- */
121
- _generateTransformMatrix(cartesianOrigin) {
122
- const translateOriginMatrix = new core_2.Matrix4().translate(cartesianOrigin);
123
- const result = translateOriginMatrix.multiplyLeft(Z_UP_TO_Y_UP_MATRIX);
124
- return result;
125
- }
126
- /**
127
- * Create _BATCHID attribute
128
- * @param {Object} i3sContent - the source object
129
- * @returns {void}
130
- */
131
- _createBatchIds(i3sContent, featureAttributes) {
132
- const { featureIds } = i3sContent;
133
- const { OBJECTID: objectIds } = featureAttributes || {};
134
- if (!featureIds || !objectIds) {
135
- return;
136
- }
137
- for (let i = 0; i < featureIds.length; i++) {
138
- const featureId = featureIds[i];
139
- const batchId = objectIds.indexOf(featureId);
140
- featureIds[i] = batchId;
141
- }
142
- i3sContent.attributes._BATCHID = {
143
- size: 1,
144
- byteOffset: 0,
145
- value: featureIds
146
- };
147
- }
148
- /**
149
- * luma.gl can not work without indices now:
150
- * https://github.com/visgl/luma.gl/blob/d8cad75b9f8ca3e578cf078ed9d19e619c2ddbc9/modules/experimental/src/gltf/gltf-instantiator.js#L115
151
- * This method generates syntetic indices array: [0, 1, 2, 3, .... , vertexCount-1]
152
- * @param {number} vertexCount - vertex count in the geometry
153
- * @returns {Uint32Array} indices array.
154
- */
155
- _generateSynteticIndices(vertexCount) {
156
- const result = new Uint32Array(vertexCount);
157
- for (let index = 0; index < vertexCount; index++) {
158
- result.set([index], index);
159
- }
160
- return result;
161
- }
162
- /**
163
- * Deduce mime type by format from `textureSetDefinition.formats[0].format`
164
- * https://github.com/Esri/i3s-spec/blob/master/docs/1.7/textureSetDefinitionFormat.cmn.md
165
- * @param {string} format - format name
166
- * @returns {string} mime type.
167
- */
168
- _deduceMimeTypeFromFormat(format) {
169
- switch (format) {
170
- case 'jpg':
171
- return 'image/jpeg';
172
- case 'png':
173
- return 'image/png';
174
- case 'ktx2':
175
- return 'image/ktx2';
176
- default:
177
- console.warn(`Unexpected texture format in I3S: ${format}`); // eslint-disable-line no-console, no-undef
178
- return 'image/jpeg';
179
- }
180
- }
181
- /**
182
- * Convert i3s material to GLTF compatible material
183
- * @param {object} material - i3s material definition
184
- * @param {number | null} textureIndex - texture index in GLTF
185
- * @returns {object} GLTF material
186
- */
187
- _convertI3sMaterialToGltfMaterial(material, textureIndex) {
188
- const isTextureIndexExists = textureIndex !== null;
189
- if (!material) {
190
- material = {
191
- alphaMode: 'OPAQUE',
192
- doubleSided: false,
193
- pbrMetallicRoughness: {
194
- metallicFactor: 0,
195
- roughnessFactor: 1
196
- }
197
- };
198
- if (isTextureIndexExists) {
199
- material.pbrMetallicRoughness.baseColorTexture = {
200
- index: textureIndex,
201
- texCoord: 0
202
- };
203
- }
204
- else {
205
- material.pbrMetallicRoughness.baseColorFactor = [1, 1, 1, 1];
206
- }
207
- return material;
208
- }
209
- if (textureIndex !== null) {
210
- material = this._setGltfTexture(material, textureIndex);
211
- }
212
- return material;
213
- }
214
- /**
215
- * Set texture properties in material with GLTF textureIndex
216
- * @param {object} materialDefinition - i3s material definition
217
- * @param {number} textureIndex - texture index in GLTF
218
- * @returns {void}
219
- */
220
- _setGltfTexture(materialDefinition, textureIndex) {
221
- const material = {
222
- ...materialDefinition,
223
- pbrMetallicRoughness: { ...materialDefinition.pbrMetallicRoughness }
224
- };
225
- // I3SLoader now support loading only one texture. This elseif sequence will assign this texture to one of
226
- // properties defined in materialDefinition
227
- if (materialDefinition.pbrMetallicRoughness &&
228
- materialDefinition.pbrMetallicRoughness.baseColorTexture) {
229
- material.pbrMetallicRoughness.baseColorTexture = {
230
- index: textureIndex,
231
- texCoord: 0
232
- };
233
- }
234
- else if (materialDefinition.emissiveTexture) {
235
- material.emissiveTexture = {
236
- index: textureIndex,
237
- texCoord: 0
238
- };
239
- }
240
- else if (materialDefinition.pbrMetallicRoughness &&
241
- materialDefinition.pbrMetallicRoughness.metallicRoughnessTexture) {
242
- material.pbrMetallicRoughness.metallicRoughnessTexture = {
243
- index: textureIndex,
244
- texCoord: 0
245
- };
246
- }
247
- else if (materialDefinition.normalTexture) {
248
- material.normalTexture = {
249
- index: textureIndex,
250
- texCoord: 0
251
- };
252
- }
253
- else if (materialDefinition.occlusionTexture) {
254
- material.occlusionTexture = {
255
- index: textureIndex,
256
- texCoord: 0
257
- };
258
- }
259
- return material;
260
- }
261
- /*
262
- * Returns Features length based on attribute array in attribute object.
263
- * @param {Object} attributes
264
- * @returns {Number} Features length .
265
- */
266
- _getFeaturesLength(attributes) {
267
- if (!attributes) {
268
- return 0;
269
- }
270
- const firstKey = Object.keys(attributes)[0];
271
- return firstKey ? attributes[firstKey].length : 0;
272
- }
273
- /* Checks that normals buffer is correct
274
- * @param {TypedArray} normals
275
- * @returns {boolean} true - normals are correct; false - normals are incorrect
276
- */
277
- _checkNormals(normals) {
278
- // If all normals === 0, the resulting tileset is all in black colors on Cesium
279
- return normals.find((value) => value);
280
- }
281
- }
282
- exports.default = B3dmConverter;
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.i3sObbTo3dTilesObb = void 0;
4
- const core_1 = require("@math.gl/core");
5
- const geospatial_1 = require("@math.gl/geospatial");
6
- const culling_1 = require("@math.gl/culling");
7
- /**
8
- * Convert quaternion-based OBB to half-axes-based OBB
9
- * @param i3SObb quaternion based OBB
10
- * @param geoidHeightModel the Earth Gravity Model instance
11
- * @returns number[12] 3DTiles OBB https://github.com/CesiumGS/3d-tiles/tree/master/specification#box
12
- */
13
- function i3sObbTo3dTilesObb(i3SObb, geoidHeightModel) {
14
- const tiles3DCenter = [
15
- i3SObb.center[0],
16
- i3SObb.center[1],
17
- i3SObb.center[2] + geoidHeightModel.getHeight(i3SObb.center[1], i3SObb.center[0])
18
- ];
19
- const cartesianCenter = geospatial_1.Ellipsoid.WGS84.cartographicToCartesian(tiles3DCenter, new core_1.Vector3());
20
- const tiles3DObb = new culling_1.OrientedBoundingBox().fromCenterHalfSizeQuaternion(cartesianCenter, i3SObb.halfSize, i3SObb.quaternion);
21
- return [...tiles3DObb.center, ...tiles3DObb.halfAxes.toArray()];
22
- }
23
- exports.i3sObbTo3dTilesObb = i3sObbTo3dTilesObb;
@@ -1,52 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.convertTextureAtlas = void 0;
4
- /**
5
- * Apply uvRegions to texture coordinates.
6
- * Spec - https://github.com/Esri/i3s-spec/blob/master/docs/1.7/geometryUVRegion.cmn.md
7
- * Shader formula vec2 uv = fract(texCoords) * (uvRegions.zw - uvRegions.xy) + uvRegions.xy;
8
- * @param texCoords
9
- * @param uvRegions
10
- */
11
- function convertTextureAtlas(texCoords, uvRegions) {
12
- const convertedTexCoords = new Float32Array(texCoords.length);
13
- const normalisedRegions = normalizeRegions(uvRegions);
14
- for (let index = 0; index < texCoords.length; index += 2) {
15
- const uv = texCoords.subarray(index, index + 2);
16
- const regions = normalisedRegions.slice(index * 2, index * 2 + 4);
17
- // fract(texCoords)
18
- const fractatedUV = fract([uv[0], uv[1]]);
19
- // (uvRegions.zw - uvRegions.xy)
20
- const subtracted = [regions[2] - regions[0], regions[3] - regions[1]];
21
- // fract(texCoords) * (uvRegions.zw - uvRegions.xy)
22
- const multiplicationResult = [fractatedUV[0] * subtracted[0], fractatedUV[1] * subtracted[1]];
23
- // fract(texCoords) * (uvRegions.zw - uvRegions.xy) + uvRegions.xy;
24
- const convertedUV = [
25
- multiplicationResult[0] + regions[0],
26
- multiplicationResult[1] + regions[1]
27
- ];
28
- convertedTexCoords[index] = convertedUV[0];
29
- convertedTexCoords[index + 1] = convertedUV[1];
30
- }
31
- return convertedTexCoords;
32
- }
33
- exports.convertTextureAtlas = convertTextureAtlas;
34
- /**
35
- * Do fractation of UV array.
36
- * @param uv
37
- */
38
- function fract(uv) {
39
- return [uv[0] - Math.floor(uv[0]), uv[1] - Math.floor(uv[1])];
40
- }
41
- /**
42
- * Normalize uvRegions by dividing by the maximum Uint16 value
43
- * @param regions
44
- */
45
- function normalizeRegions(regions) {
46
- const MAX_UINT_16_VALUE = 65535;
47
- const normalizedRegions = [];
48
- for (let index = 0; index < regions.length; index++) {
49
- normalizedRegions[index] = regions[index] / MAX_UINT_16_VALUE;
50
- }
51
- return normalizedRegions;
52
- }
@@ -1,43 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.TILESET = void 0;
7
- const json_map_transform_1 = __importDefault(require("json-map-transform"));
8
- const ASSET = () => ({
9
- version: {
10
- path: 'version',
11
- default: '1.0'
12
- }
13
- });
14
- const TILE = () => ({
15
- boundingVolume: {
16
- path: 'boundingVolume'
17
- },
18
- geometricError: {
19
- path: 'geometricError'
20
- },
21
- content: {
22
- path: 'content'
23
- },
24
- children: {
25
- path: 'children',
26
- transform: (val) => val.map((tile) => (0, json_map_transform_1.default)(tile, TILE()))
27
- }
28
- });
29
- const TILESET = () => ({
30
- asset: {
31
- path: 'asset',
32
- transform: (val) => (0, json_map_transform_1.default)(val, ASSET())
33
- },
34
- geometricError: {
35
- path: 'root',
36
- transform: (val) => val.geometricError
37
- },
38
- root: {
39
- path: 'root',
40
- transform: (val) => (0, json_map_transform_1.default)(val, TILE())
41
- }
42
- });
43
- exports.TILESET = TILESET;
package/dist/bundle.js DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
- // @ts-nocheck
3
- const moduleExports = require('./index');
4
- globalThis.loaders = globalThis.loaders || {};
5
- module.exports = Object.assign(globalThis.loaders, moduleExports);
package/dist/constants.js DELETED
@@ -1,4 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BROWSER_ERROR_MESSAGE = void 0;
4
- exports.BROWSER_ERROR_MESSAGE = 'Tile converter does not work in browser, only in node js environment';