@loaders.gl/tile-converter 4.2.0-alpha.4 → 4.2.0-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts +3 -3
  2. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts.map +1 -1
  3. package/dist/3d-tiles-converter/3d-tiles-converter.js +329 -293
  4. package/dist/3d-tiles-converter/helpers/b3dm-converter.js +257 -200
  5. package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +14 -5
  6. package/dist/3d-tiles-converter/helpers/load-i3s.js +106 -75
  7. package/dist/3d-tiles-converter/helpers/texture-atlas.js +44 -21
  8. package/dist/3d-tiles-converter/json-templates/tileset.js +32 -33
  9. package/dist/constants.js +0 -1
  10. package/dist/converter-cli.js +255 -234
  11. package/dist/converter.min.cjs +80 -90
  12. package/dist/deps-installer/deps-installer.js +72 -58
  13. package/dist/i3s-converter/helpers/attribute-metadata-info.js +207 -153
  14. package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts +1 -1
  15. package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts.map +1 -1
  16. package/dist/i3s-converter/helpers/batch-ids-extensions.js +145 -103
  17. package/dist/i3s-converter/helpers/coordinate-converter.js +100 -65
  18. package/dist/i3s-converter/helpers/create-scene-server-path.js +14 -9
  19. package/dist/i3s-converter/helpers/feature-attributes.js +168 -105
  20. package/dist/i3s-converter/helpers/geometry-attributes.d.ts +1 -1
  21. package/dist/i3s-converter/helpers/geometry-attributes.d.ts.map +1 -1
  22. package/dist/i3s-converter/helpers/geometry-attributes.js +204 -212
  23. package/dist/i3s-converter/helpers/geometry-converter.d.ts +2 -2
  24. package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -1
  25. package/dist/i3s-converter/helpers/geometry-converter.js +1148 -829
  26. package/dist/i3s-converter/helpers/gltf-attributes.d.ts +1 -1
  27. package/dist/i3s-converter/helpers/gltf-attributes.d.ts.map +1 -1
  28. package/dist/i3s-converter/helpers/gltf-attributes.js +111 -97
  29. package/dist/i3s-converter/helpers/load-3d-tiles.js +103 -66
  30. package/dist/i3s-converter/helpers/node-debug.js +98 -54
  31. package/dist/i3s-converter/helpers/node-index-document.d.ts +3 -3
  32. package/dist/i3s-converter/helpers/node-index-document.d.ts.map +1 -1
  33. package/dist/i3s-converter/helpers/node-index-document.js +248 -177
  34. package/dist/i3s-converter/helpers/node-pages.d.ts +1 -1
  35. package/dist/i3s-converter/helpers/node-pages.d.ts.map +1 -1
  36. package/dist/i3s-converter/helpers/node-pages.js +299 -194
  37. package/dist/i3s-converter/helpers/preprocess-3d-tiles.d.ts +1 -1
  38. package/dist/i3s-converter/helpers/preprocess-3d-tiles.d.ts.map +1 -1
  39. package/dist/i3s-converter/helpers/preprocess-3d-tiles.js +92 -60
  40. package/dist/i3s-converter/helpers/progress.js +134 -83
  41. package/dist/i3s-converter/helpers/tileset-traversal.d.ts +1 -1
  42. package/dist/i3s-converter/helpers/tileset-traversal.d.ts.map +1 -1
  43. package/dist/i3s-converter/helpers/tileset-traversal.js +24 -13
  44. package/dist/i3s-converter/i3s-converter.d.ts +7 -7
  45. package/dist/i3s-converter/i3s-converter.d.ts.map +1 -1
  46. package/dist/i3s-converter/i3s-converter.js +1044 -898
  47. package/dist/i3s-converter/json-templates/geometry-definitions.js +70 -79
  48. package/dist/i3s-converter/json-templates/layers.js +120 -121
  49. package/dist/i3s-converter/json-templates/metadata.js +19 -20
  50. package/dist/i3s-converter/json-templates/node.js +73 -71
  51. package/dist/i3s-converter/json-templates/scene-server.js +25 -26
  52. package/dist/i3s-converter/json-templates/shared-resources.js +107 -108
  53. package/dist/i3s-converter/json-templates/store.js +96 -94
  54. package/dist/i3s-converter/types.js +35 -23
  55. package/dist/i3s-server/app.js +15 -12
  56. package/dist/i3s-server/bin/www.js +14 -7
  57. package/dist/i3s-server/controllers/index-controller.js +18 -15
  58. package/dist/i3s-server/controllers/slpk-controller.js +22 -11
  59. package/dist/i3s-server/routes/index.js +9 -8
  60. package/dist/i3s-server/routes/slpk-router.js +18 -17
  61. package/dist/i3s-server/utils/create-scene-server.js +15 -10
  62. package/dist/i3s-server/utils/server-utils.js +49 -32
  63. package/dist/index.cjs +292 -851
  64. package/dist/index.cjs.map +7 -0
  65. package/dist/index.d.ts +2 -2
  66. package/dist/index.d.ts.map +1 -1
  67. package/dist/index.js +0 -1
  68. package/dist/lib/json-schemas/conversion-dump-json-schema.js +243 -421
  69. package/dist/lib/utils/cli-utils.js +63 -36
  70. package/dist/lib/utils/compress-util.js +20 -15
  71. package/dist/lib/utils/conversion-dump.d.ts +1 -1
  72. package/dist/lib/utils/conversion-dump.d.ts.map +1 -1
  73. package/dist/lib/utils/conversion-dump.js +209 -187
  74. package/dist/lib/utils/file-utils.js +122 -74
  75. package/dist/lib/utils/geometry-utils.js +13 -7
  76. package/dist/lib/utils/lod-conversion-utils.js +65 -33
  77. package/dist/lib/utils/queue.js +12 -13
  78. package/dist/lib/utils/statistic-utills.d.ts +6 -23
  79. package/dist/lib/utils/statistic-utills.js +64 -59
  80. package/dist/lib/utils/write-queue.d.ts +2 -2
  81. package/dist/lib/utils/write-queue.d.ts.map +1 -1
  82. package/dist/lib/utils/write-queue.js +68 -86
  83. package/dist/pgm-loader.js +16 -12
  84. package/dist/slpk-extractor/slpk-extractor.js +59 -50
  85. package/dist/slpk-extractor-cli.js +82 -59
  86. package/package.json +18 -18
  87. package/dist/3d-tiles-converter/3d-tiles-converter.js.map +0 -1
  88. package/dist/3d-tiles-converter/helpers/b3dm-converter.js.map +0 -1
  89. package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +0 -1
  90. package/dist/3d-tiles-converter/helpers/load-i3s.js.map +0 -1
  91. package/dist/3d-tiles-converter/helpers/texture-atlas.js.map +0 -1
  92. package/dist/3d-tiles-converter/json-templates/tileset.js.map +0 -1
  93. package/dist/constants.js.map +0 -1
  94. package/dist/converter-cli.js.map +0 -1
  95. package/dist/deps-installer/deps-installer.js.map +0 -1
  96. package/dist/i3s-converter/helpers/attribute-metadata-info.js.map +0 -1
  97. package/dist/i3s-converter/helpers/batch-ids-extensions.js.map +0 -1
  98. package/dist/i3s-converter/helpers/coordinate-converter.js.map +0 -1
  99. package/dist/i3s-converter/helpers/create-scene-server-path.js.map +0 -1
  100. package/dist/i3s-converter/helpers/feature-attributes.js.map +0 -1
  101. package/dist/i3s-converter/helpers/geometry-attributes.js.map +0 -1
  102. package/dist/i3s-converter/helpers/geometry-converter.js.map +0 -1
  103. package/dist/i3s-converter/helpers/gltf-attributes.js.map +0 -1
  104. package/dist/i3s-converter/helpers/load-3d-tiles.js.map +0 -1
  105. package/dist/i3s-converter/helpers/node-debug.js.map +0 -1
  106. package/dist/i3s-converter/helpers/node-index-document.js.map +0 -1
  107. package/dist/i3s-converter/helpers/node-pages.js.map +0 -1
  108. package/dist/i3s-converter/helpers/preprocess-3d-tiles.js.map +0 -1
  109. package/dist/i3s-converter/helpers/progress.js.map +0 -1
  110. package/dist/i3s-converter/helpers/tileset-traversal.js.map +0 -1
  111. package/dist/i3s-converter/i3s-converter.js.map +0 -1
  112. package/dist/i3s-converter/json-templates/geometry-definitions.js.map +0 -1
  113. package/dist/i3s-converter/json-templates/layers.js.map +0 -1
  114. package/dist/i3s-converter/json-templates/metadata.js.map +0 -1
  115. package/dist/i3s-converter/json-templates/node.js.map +0 -1
  116. package/dist/i3s-converter/json-templates/scene-server.js.map +0 -1
  117. package/dist/i3s-converter/json-templates/shared-resources.js.map +0 -1
  118. package/dist/i3s-converter/json-templates/store.js.map +0 -1
  119. package/dist/i3s-converter/types.js.map +0 -1
  120. package/dist/i3s-server/README.md +0 -63
  121. package/dist/i3s-server/app.js.map +0 -1
  122. package/dist/i3s-server/bin/www.js.map +0 -1
  123. package/dist/i3s-server/certs/cert.pem +0 -19
  124. package/dist/i3s-server/certs/key.pem +0 -27
  125. package/dist/i3s-server/controllers/index-controller.js.map +0 -1
  126. package/dist/i3s-server/controllers/slpk-controller.js.map +0 -1
  127. package/dist/i3s-server/routes/index.js.map +0 -1
  128. package/dist/i3s-server/routes/slpk-router.js.map +0 -1
  129. package/dist/i3s-server/utils/create-scene-server.js.map +0 -1
  130. package/dist/i3s-server/utils/server-utils.js.map +0 -1
  131. package/dist/index.js.map +0 -1
  132. package/dist/lib/json-schemas/conversion-dump-json-schema.js.map +0 -1
  133. package/dist/lib/utils/cli-utils.js.map +0 -1
  134. package/dist/lib/utils/compress-util.js.map +0 -1
  135. package/dist/lib/utils/conversion-dump.js.map +0 -1
  136. package/dist/lib/utils/file-utils.js.map +0 -1
  137. package/dist/lib/utils/geometry-utils.js.map +0 -1
  138. package/dist/lib/utils/lod-conversion-utils.js.map +0 -1
  139. package/dist/lib/utils/queue.js.map +0 -1
  140. package/dist/lib/utils/statistic-utills.js.map +0 -1
  141. package/dist/lib/utils/write-queue.js.map +0 -1
  142. package/dist/pgm-loader.js.map +0 -1
  143. package/dist/slpk-extractor/slpk-extractor.js.map +0 -1
  144. package/dist/slpk-extractor-cli.js.map +0 -1
@@ -10,217 +10,274 @@ const scratchVector = new Vector3();
10
10
  const KHR_MATERIALS_UNLIT = 'KHR_materials_unlit';
11
11
  const METALLIC_FACTOR_DEFAULT = 1.0;
12
12
  const ROUGHNESS_FACTOR_DEFAULT = 1.0;
13
+ /**
14
+ * Converts content of an I3S node to *.b3dm's file content
15
+ */
13
16
  export default class B3dmConverter {
14
- constructor() {
15
- this.rtcCenter = void 0;
16
- this.i3sTile = void 0;
17
- }
18
- async convert(i3sAttributesData) {
19
- let featureAttributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
20
- const gltf = await this.buildGLTF(i3sAttributesData, featureAttributes);
21
- const b3dm = encodeSync({
22
- gltfEncoded: new Uint8Array(gltf),
23
- type: 'b3dm',
24
- featuresLength: this._getFeaturesLength(featureAttributes),
25
- batchTable: featureAttributes
26
- }, Tile3DWriter);
27
- return b3dm;
28
- }
29
- async buildGLTF(i3sAttributesData, featureAttributes) {
30
- const {
31
- tileContent,
32
- textureFormat,
33
- box
34
- } = i3sAttributesData;
35
- const {
36
- material,
37
- attributes,
38
- indices: originalIndices,
39
- modelMatrix
40
- } = tileContent;
41
- const gltfBuilder = new GLTFScenegraph();
42
- const textureIndex = await this._addI3sTextureToGLTF(tileContent, textureFormat, gltfBuilder);
43
- const pbrMetallicRoughness = material === null || material === void 0 ? void 0 : material.pbrMetallicRoughness;
44
- if (pbrMetallicRoughness && (pbrMetallicRoughness.metallicFactor === undefined || pbrMetallicRoughness.metallicFactor === METALLIC_FACTOR_DEFAULT) && (pbrMetallicRoughness.roughnessFactor === undefined || pbrMetallicRoughness.roughnessFactor === ROUGHNESS_FACTOR_DEFAULT)) {
45
- gltfBuilder.addObjectExtension(material, KHR_MATERIALS_UNLIT, {});
46
- gltfBuilder.addExtension(KHR_MATERIALS_UNLIT);
17
+ /**
18
+ * The starter of content conversion
19
+ * @param i3sTile - Tile3D instance for I3S node
20
+ * @returns - encoded content
21
+ */
22
+ async convert(i3sAttributesData, featureAttributes = null) {
23
+ const gltf = await this.buildGLTF(i3sAttributesData, featureAttributes);
24
+ const b3dm = encodeSync({
25
+ gltfEncoded: new Uint8Array(gltf),
26
+ type: 'b3dm',
27
+ featuresLength: this._getFeaturesLength(featureAttributes),
28
+ batchTable: featureAttributes
29
+ }, Tile3DWriter);
30
+ return b3dm;
47
31
  }
48
- const pbrMaterialInfo = this._convertI3sMaterialToGLTFMaterial(material, textureIndex);
49
- const materialIndex = gltfBuilder.addMaterial(pbrMaterialInfo);
50
- const positions = attributes.positions;
51
- const positionsValue = positions.value;
52
- if (attributes.uvRegions && attributes.texCoords) {
53
- attributes.texCoords.value = convertTextureAtlas(attributes.texCoords.value, attributes.uvRegions.value);
54
- }
55
- const cartesianOrigin = new Vector3(box);
56
- const cartographicOrigin = Ellipsoid.WGS84.cartesianToCartographic(cartesianOrigin, new Vector3());
57
- attributes.positions.value = this._normalizePositions(positionsValue, cartesianOrigin, cartographicOrigin, modelMatrix);
58
- this._createBatchIds(tileContent, featureAttributes);
59
- if (attributes.normals && !this._checkNormals(attributes.normals.value)) {
60
- delete attributes.normals;
32
+ /**
33
+ * Build and encode gltf
34
+ * @param i3sTile - Tile3D instance for I3S node
35
+ * @returns - encoded glb content
36
+ */
37
+ async buildGLTF(i3sAttributesData, featureAttributes) {
38
+ const { tileContent, textureFormat, box } = i3sAttributesData;
39
+ const { material, attributes, indices: originalIndices, modelMatrix } = tileContent;
40
+ const gltfBuilder = new GLTFScenegraph();
41
+ const textureIndex = await this._addI3sTextureToGLTF(tileContent, textureFormat, gltfBuilder);
42
+ // Add KHR_MATERIALS_UNLIT extension in the following cases:
43
+ // - metallicFactor or roughnessFactor are set to default values
44
+ // - metallicFactor or roughnessFactor are not set
45
+ const pbrMetallicRoughness = material?.pbrMetallicRoughness;
46
+ if (pbrMetallicRoughness &&
47
+ (pbrMetallicRoughness.metallicFactor === undefined ||
48
+ pbrMetallicRoughness.metallicFactor === METALLIC_FACTOR_DEFAULT) &&
49
+ (pbrMetallicRoughness.roughnessFactor === undefined ||
50
+ pbrMetallicRoughness.roughnessFactor === ROUGHNESS_FACTOR_DEFAULT)) {
51
+ gltfBuilder.addObjectExtension(material, KHR_MATERIALS_UNLIT, {});
52
+ gltfBuilder.addExtension(KHR_MATERIALS_UNLIT);
53
+ }
54
+ const pbrMaterialInfo = this._convertI3sMaterialToGLTFMaterial(material, textureIndex);
55
+ const materialIndex = gltfBuilder.addMaterial(pbrMaterialInfo);
56
+ const positions = attributes.positions;
57
+ const positionsValue = positions.value;
58
+ if (attributes.uvRegions && attributes.texCoords) {
59
+ attributes.texCoords.value = convertTextureAtlas(attributes.texCoords.value, attributes.uvRegions.value);
60
+ }
61
+ const cartesianOrigin = new Vector3(box);
62
+ const cartographicOrigin = Ellipsoid.WGS84.cartesianToCartographic(cartesianOrigin, new Vector3());
63
+ attributes.positions.value = this._normalizePositions(positionsValue, cartesianOrigin, cartographicOrigin, modelMatrix);
64
+ this._createBatchIds(tileContent, featureAttributes);
65
+ if (attributes.normals && !this._checkNormals(attributes.normals.value)) {
66
+ delete attributes.normals;
67
+ }
68
+ const indices = originalIndices || generateSyntheticIndices(positionsValue.length / positions.size);
69
+ const meshIndex = gltfBuilder.addMesh({
70
+ attributes,
71
+ indices,
72
+ material: materialIndex,
73
+ mode: 4
74
+ });
75
+ const transformMatrix = this._generateTransformMatrix(cartesianOrigin);
76
+ const nodeIndex = gltfBuilder.addNode({ meshIndex, matrix: transformMatrix });
77
+ const sceneIndex = gltfBuilder.addScene({ nodeIndices: [nodeIndex] });
78
+ gltfBuilder.setDefaultScene(sceneIndex);
79
+ gltfBuilder.createBinaryChunk();
80
+ const gltfBuffer = encodeSync(gltfBuilder.gltf, GLTFWriter);
81
+ return gltfBuffer;
61
82
  }
62
- const indices = originalIndices || generateSyntheticIndices(positionsValue.length / positions.size);
63
- const meshIndex = gltfBuilder.addMesh({
64
- attributes,
65
- indices,
66
- material: materialIndex,
67
- mode: 4
68
- });
69
- const transformMatrix = this._generateTransformMatrix(cartesianOrigin);
70
- const nodeIndex = gltfBuilder.addNode({
71
- meshIndex,
72
- matrix: transformMatrix
73
- });
74
- const sceneIndex = gltfBuilder.addScene({
75
- nodeIndices: [nodeIndex]
76
- });
77
- gltfBuilder.setDefaultScene(sceneIndex);
78
- gltfBuilder.createBinaryChunk();
79
- const gltfBuffer = encodeSync(gltfBuilder.gltf, GLTFWriter);
80
- return gltfBuffer;
81
- }
82
- async _addI3sTextureToGLTF(tileContent, textureFormat, gltfBuilder) {
83
- const {
84
- texture,
85
- material,
86
- attributes
87
- } = tileContent;
88
- let textureIndex = null;
89
- let selectedTexture = texture;
90
- if (!texture && material) {
91
- selectedTexture = material.pbrMetallicRoughness && material.pbrMetallicRoughness.baseColorTexture && material.pbrMetallicRoughness.baseColorTexture.texture.source.image;
83
+ /**
84
+ * Update gltfBuilder with texture from I3S tile
85
+ * @param {object} i3sTile - Tile3D object
86
+ * @param {GLTFScenegraph} gltfBuilder - gltfScenegraph instance to construct GLTF
87
+ * @returns {Promise<number | null>} - GLTF texture index
88
+ */
89
+ async _addI3sTextureToGLTF(tileContent, textureFormat, gltfBuilder) {
90
+ const { texture, material, attributes } = tileContent;
91
+ let textureIndex = null;
92
+ let selectedTexture = texture;
93
+ if (!texture && material) {
94
+ selectedTexture =
95
+ material.pbrMetallicRoughness &&
96
+ material.pbrMetallicRoughness.baseColorTexture &&
97
+ material.pbrMetallicRoughness.baseColorTexture.texture.source.image;
98
+ }
99
+ if (selectedTexture) {
100
+ const mimeType = this._deduceMimeTypeFromFormat(textureFormat);
101
+ const imageIndex = gltfBuilder.addImage(selectedTexture, mimeType);
102
+ textureIndex = gltfBuilder.addTexture({ imageIndex });
103
+ delete attributes.colors;
104
+ }
105
+ return textureIndex;
92
106
  }
93
- if (selectedTexture) {
94
- const mimeType = this._deduceMimeTypeFromFormat(textureFormat);
95
- const imageIndex = gltfBuilder.addImage(selectedTexture, mimeType);
96
- textureIndex = gltfBuilder.addTexture({
97
- imageIndex
98
- });
99
- delete attributes.colors;
107
+ /**
108
+ * Generate a positions array which is correct for 3DTiles/GLTF format
109
+ * @param {Float64Array} positionsValue - the input geometry positions array
110
+ * @param {number[]} cartesianOrigin - the tile center in the cartesian coordinate system
111
+ * @param {number[]} cartographicOrigin - the tile center in the cartographic coordinate system
112
+ * @param {number[]} modelMatrix - the model matrix of geometry
113
+ * @returns {Float32Array} - the output geometry positions array
114
+ */
115
+ _normalizePositions(positionsValue, cartesianOrigin, cartographicOrigin, modelMatrix) {
116
+ const newPositionsValue = new Float32Array(positionsValue.length);
117
+ for (let index = 0; index < positionsValue.length; index += 3) {
118
+ const vertex = positionsValue.subarray(index, index + 3);
119
+ const cartesianOriginVector = new Vector3(cartesianOrigin);
120
+ let vertexVector = new Vector3(Array.from(vertex))
121
+ .transform(modelMatrix)
122
+ .add(cartographicOrigin);
123
+ Ellipsoid.WGS84.cartographicToCartesian(vertexVector, scratchVector);
124
+ vertexVector = scratchVector.subtract(cartesianOriginVector);
125
+ newPositionsValue.set(vertexVector, index);
126
+ }
127
+ return newPositionsValue;
100
128
  }
101
- return textureIndex;
102
- }
103
- _normalizePositions(positionsValue, cartesianOrigin, cartographicOrigin, modelMatrix) {
104
- const newPositionsValue = new Float32Array(positionsValue.length);
105
- for (let index = 0; index < positionsValue.length; index += 3) {
106
- const vertex = positionsValue.subarray(index, index + 3);
107
- const cartesianOriginVector = new Vector3(cartesianOrigin);
108
- let vertexVector = new Vector3(Array.from(vertex)).transform(modelMatrix).add(cartographicOrigin);
109
- Ellipsoid.WGS84.cartographicToCartesian(vertexVector, scratchVector);
110
- vertexVector = scratchVector.subtract(cartesianOriginVector);
111
- newPositionsValue.set(vertexVector, index);
129
+ /**
130
+ * Generate the transformation matrix for GLTF node:
131
+ * https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#reference-node
132
+ * 1. Create the translate transformation from cartesianOrigin (the positions array stores offsets from this cartesianOrigin)
133
+ * 2. Create the rotation transformation to rotate model from z-up coordinates (I3S specific) to y-up coordinates (GLTF specific)
134
+ * @param {number[]} cartesianOrigin - the tile center in the cartesian coordinate system
135
+ * @returns {Matrix4} - an array of 16 numbers (4x4 matrix)
136
+ */
137
+ _generateTransformMatrix(cartesianOrigin) {
138
+ const translateOriginMatrix = new Matrix4().translate(cartesianOrigin);
139
+ const result = translateOriginMatrix.multiplyLeft(Z_UP_TO_Y_UP_MATRIX);
140
+ return result;
112
141
  }
113
- return newPositionsValue;
114
- }
115
- _generateTransformMatrix(cartesianOrigin) {
116
- const translateOriginMatrix = new Matrix4().translate(cartesianOrigin);
117
- const result = translateOriginMatrix.multiplyLeft(Z_UP_TO_Y_UP_MATRIX);
118
- return result;
119
- }
120
- _createBatchIds(i3sContent, featureAttributes) {
121
- const {
122
- featureIds
123
- } = i3sContent;
124
- const {
125
- OBJECTID: objectIds
126
- } = featureAttributes || {};
127
- if (!featureIds || !objectIds) {
128
- return;
142
+ /**
143
+ * Create _BATCHID attribute
144
+ * @param {Object} i3sContent - the source object
145
+ * @returns {void}
146
+ */
147
+ _createBatchIds(i3sContent, featureAttributes) {
148
+ const { featureIds } = i3sContent;
149
+ const { OBJECTID: objectIds } = featureAttributes || {};
150
+ if (!featureIds || !objectIds) {
151
+ return;
152
+ }
153
+ for (let i = 0; i < featureIds.length; i++) {
154
+ const featureId = featureIds[i];
155
+ const batchId = objectIds.indexOf(featureId);
156
+ featureIds[i] = batchId;
157
+ }
158
+ i3sContent.attributes._BATCHID = {
159
+ size: 1,
160
+ byteOffset: 0,
161
+ value: featureIds
162
+ };
129
163
  }
130
- for (let i = 0; i < featureIds.length; i++) {
131
- const featureId = featureIds[i];
132
- const batchId = objectIds.indexOf(featureId);
133
- featureIds[i] = batchId;
164
+ /**
165
+ * Deduce mime type by format from `textureSetDefinition.formats[0].format`
166
+ * https://github.com/Esri/i3s-spec/blob/master/docs/1.7/textureSetDefinitionFormat.cmn.md
167
+ * @param {string} format - format name
168
+ * @returns {string} mime type.
169
+ */
170
+ _deduceMimeTypeFromFormat(format) {
171
+ switch (format) {
172
+ case 'jpg':
173
+ return 'image/jpeg';
174
+ case 'png':
175
+ return 'image/png';
176
+ case 'ktx2':
177
+ return 'image/ktx2';
178
+ default:
179
+ console.warn(`Unexpected texture format in I3S: ${format}`); // eslint-disable-line no-console, no-undef
180
+ return 'image/jpeg';
181
+ }
134
182
  }
135
- i3sContent.attributes._BATCHID = {
136
- size: 1,
137
- byteOffset: 0,
138
- value: featureIds
139
- };
140
- }
141
- _deduceMimeTypeFromFormat(format) {
142
- switch (format) {
143
- case 'jpg':
144
- return 'image/jpeg';
145
- case 'png':
146
- return 'image/png';
147
- case 'ktx2':
148
- return 'image/ktx2';
149
- default:
150
- console.warn(`Unexpected texture format in I3S: ${format}`);
151
- return 'image/jpeg';
183
+ /**
184
+ * Convert i3s material to GLTF compatible material
185
+ * @param {object} material - i3s material definition
186
+ * @param {number | null} textureIndex - texture index in GLTF
187
+ * @returns {object} GLTF material
188
+ */
189
+ _convertI3sMaterialToGLTFMaterial(material, textureIndex) {
190
+ const isTextureIndexExists = textureIndex !== null;
191
+ if (!material) {
192
+ material = {
193
+ alphaMode: 'OPAQUE',
194
+ doubleSided: false,
195
+ pbrMetallicRoughness: {
196
+ metallicFactor: 0,
197
+ roughnessFactor: 1
198
+ }
199
+ };
200
+ if (isTextureIndexExists) {
201
+ material.pbrMetallicRoughness.baseColorTexture = {
202
+ index: textureIndex,
203
+ texCoord: 0
204
+ };
205
+ }
206
+ else {
207
+ material.pbrMetallicRoughness.baseColorFactor = [1, 1, 1, 1];
208
+ }
209
+ return material;
210
+ }
211
+ if (textureIndex !== null) {
212
+ material = this._setGLTFTexture(material, textureIndex);
213
+ }
214
+ return material;
152
215
  }
153
- }
154
- _convertI3sMaterialToGLTFMaterial(material, textureIndex) {
155
- const isTextureIndexExists = textureIndex !== null;
156
- if (!material) {
157
- material = {
158
- alphaMode: 'OPAQUE',
159
- doubleSided: false,
160
- pbrMetallicRoughness: {
161
- metallicFactor: 0,
162
- roughnessFactor: 1
163
- }
164
- };
165
- if (isTextureIndexExists) {
166
- material.pbrMetallicRoughness.baseColorTexture = {
167
- index: textureIndex,
168
- texCoord: 0
216
+ /**
217
+ * Set texture properties in material with GLTF textureIndex
218
+ * @param {object} materialDefinition - i3s material definition
219
+ * @param {number} textureIndex - texture index in GLTF
220
+ * @returns {void}
221
+ */
222
+ _setGLTFTexture(materialDefinition, textureIndex) {
223
+ const material = {
224
+ ...materialDefinition,
225
+ pbrMetallicRoughness: { ...materialDefinition.pbrMetallicRoughness }
169
226
  };
170
- } else {
171
- material.pbrMetallicRoughness.baseColorFactor = [1, 1, 1, 1];
172
- }
173
- return material;
174
- }
175
- if (textureIndex !== null) {
176
- material = this._setGLTFTexture(material, textureIndex);
227
+ // I3SLoader now support loading only one texture. This elseif sequence will assign this texture to one of
228
+ // properties defined in materialDefinition
229
+ if (materialDefinition.pbrMetallicRoughness &&
230
+ materialDefinition.pbrMetallicRoughness.baseColorTexture) {
231
+ material.pbrMetallicRoughness.baseColorTexture = {
232
+ index: textureIndex,
233
+ texCoord: 0
234
+ };
235
+ }
236
+ else if (materialDefinition.emissiveTexture) {
237
+ material.emissiveTexture = {
238
+ index: textureIndex,
239
+ texCoord: 0
240
+ };
241
+ }
242
+ else if (materialDefinition.pbrMetallicRoughness &&
243
+ materialDefinition.pbrMetallicRoughness.metallicRoughnessTexture) {
244
+ material.pbrMetallicRoughness.metallicRoughnessTexture = {
245
+ index: textureIndex,
246
+ texCoord: 0
247
+ };
248
+ }
249
+ else if (materialDefinition.normalTexture) {
250
+ material.normalTexture = {
251
+ index: textureIndex,
252
+ texCoord: 0
253
+ };
254
+ }
255
+ else if (materialDefinition.occlusionTexture) {
256
+ material.occlusionTexture = {
257
+ index: textureIndex,
258
+ texCoord: 0
259
+ };
260
+ }
261
+ return material;
177
262
  }
178
- return material;
179
- }
180
- _setGLTFTexture(materialDefinition, textureIndex) {
181
- const material = {
182
- ...materialDefinition,
183
- pbrMetallicRoughness: {
184
- ...materialDefinition.pbrMetallicRoughness
185
- }
186
- };
187
- if (materialDefinition.pbrMetallicRoughness && materialDefinition.pbrMetallicRoughness.baseColorTexture) {
188
- material.pbrMetallicRoughness.baseColorTexture = {
189
- index: textureIndex,
190
- texCoord: 0
191
- };
192
- } else if (materialDefinition.emissiveTexture) {
193
- material.emissiveTexture = {
194
- index: textureIndex,
195
- texCoord: 0
196
- };
197
- } else if (materialDefinition.pbrMetallicRoughness && materialDefinition.pbrMetallicRoughness.metallicRoughnessTexture) {
198
- material.pbrMetallicRoughness.metallicRoughnessTexture = {
199
- index: textureIndex,
200
- texCoord: 0
201
- };
202
- } else if (materialDefinition.normalTexture) {
203
- material.normalTexture = {
204
- index: textureIndex,
205
- texCoord: 0
206
- };
207
- } else if (materialDefinition.occlusionTexture) {
208
- material.occlusionTexture = {
209
- index: textureIndex,
210
- texCoord: 0
211
- };
263
+ /*
264
+ * Returns Features length based on attribute array in attribute object.
265
+ * @param {Object} attributes
266
+ * @returns {Number} Features length .
267
+ */
268
+ _getFeaturesLength(attributes) {
269
+ if (!attributes) {
270
+ return 0;
271
+ }
272
+ const firstKey = Object.keys(attributes)[0];
273
+ return firstKey ? attributes[firstKey].length : 0;
212
274
  }
213
- return material;
214
- }
215
- _getFeaturesLength(attributes) {
216
- if (!attributes) {
217
- return 0;
275
+ /* Checks that normals buffer is correct
276
+ * @param {TypedArray} normals
277
+ * @returns {boolean} true - normals are correct; false - normals are incorrect
278
+ */
279
+ _checkNormals(normals) {
280
+ // If all normals === 0, the resulting tileset is all in black colors on Cesium
281
+ return normals.find((value) => value);
218
282
  }
219
- const firstKey = Object.keys(attributes)[0];
220
- return firstKey ? attributes[firstKey].length : 0;
221
- }
222
- _checkNormals(normals) {
223
- return normals.find(value => value);
224
- }
225
283
  }
226
- //# sourceMappingURL=b3dm-converter.js.map
@@ -1,10 +1,19 @@
1
1
  import { Vector3 } from '@math.gl/core';
2
2
  import { Ellipsoid } from '@math.gl/geospatial';
3
3
  import { OrientedBoundingBox } from '@math.gl/culling';
4
+ /**
5
+ * Convert quaternion-based OBB to half-axes-based OBB
6
+ * @param i3SObb quaternion based OBB
7
+ * @param geoidHeightModel the Earth Gravity Model instance
8
+ * @returns number[12] 3DTiles OBB https://github.com/CesiumGS/3d-tiles/tree/master/specification#box
9
+ */
4
10
  export function i3sObbTo3dTilesObb(i3SObb, geoidHeightModel) {
5
- const tiles3DCenter = [i3SObb.center[0], i3SObb.center[1], i3SObb.center[2] + geoidHeightModel.getHeight(i3SObb.center[1], i3SObb.center[0])];
6
- const cartesianCenter = Ellipsoid.WGS84.cartographicToCartesian(tiles3DCenter, new Vector3());
7
- const tiles3DObb = new OrientedBoundingBox().fromCenterHalfSizeQuaternion(cartesianCenter, i3SObb.halfSize, i3SObb.quaternion);
8
- return [...tiles3DObb.center, ...tiles3DObb.halfAxes.toArray()];
11
+ const tiles3DCenter = [
12
+ i3SObb.center[0],
13
+ i3SObb.center[1],
14
+ i3SObb.center[2] + geoidHeightModel.getHeight(i3SObb.center[1], i3SObb.center[0])
15
+ ];
16
+ const cartesianCenter = Ellipsoid.WGS84.cartographicToCartesian(tiles3DCenter, new Vector3());
17
+ const tiles3DObb = new OrientedBoundingBox().fromCenterHalfSizeQuaternion(cartesianCenter, i3SObb.halfSize, i3SObb.quaternion);
18
+ return [...tiles3DObb.center, ...tiles3DObb.halfAxes.toArray()];
9
19
  }
10
- //# sourceMappingURL=i3s-obb-to-3d-tiles-obb.js.map