@loaders.gl/tile-converter 3.1.7 → 3.2.0-alpha.2

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 (224) hide show
  1. package/dist/3d-tiles-attributes-worker.d.ts +28 -0
  2. package/dist/3d-tiles-attributes-worker.d.ts.map +1 -0
  3. package/dist/3d-tiles-attributes-worker.js +4 -0
  4. package/dist/3d-tiles-attributes-worker.js.map +7 -0
  5. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts +82 -0
  6. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts.map +1 -0
  7. package/dist/3d-tiles-converter/3d-tiles-converter.js +268 -0
  8. package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts +84 -0
  9. package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts.map +1 -0
  10. package/dist/3d-tiles-converter/helpers/b3dm-converter.js +278 -0
  11. package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.d.ts +13 -0
  12. package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.d.ts.map +1 -0
  13. package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +23 -0
  14. package/dist/3d-tiles-converter/helpers/texture-atlas.d.ts +9 -0
  15. package/dist/3d-tiles-converter/helpers/texture-atlas.d.ts.map +1 -0
  16. package/dist/3d-tiles-converter/helpers/texture-atlas.js +52 -0
  17. package/dist/3d-tiles-converter/json-templates/tileset.d.ts +15 -0
  18. package/dist/3d-tiles-converter/json-templates/tileset.d.ts.map +1 -0
  19. package/dist/3d-tiles-converter/json-templates/tileset.js +43 -0
  20. package/dist/bundle.d.ts +2 -0
  21. package/dist/bundle.d.ts.map +1 -0
  22. package/dist/bundle.js +5 -0
  23. package/dist/converter.min.js +20 -20
  24. package/dist/deps-installer/deps-installer.d.ts +4 -0
  25. package/dist/deps-installer/deps-installer.d.ts.map +1 -0
  26. package/dist/deps-installer/deps-installer.js +21 -0
  27. package/dist/dist.min.js +1082 -1131
  28. package/dist/es5/3d-tiles-attributes-worker.js +29 -0
  29. package/dist/es5/3d-tiles-attributes-worker.js.map +1 -0
  30. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js +104 -44
  31. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  32. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js +34 -43
  33. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  34. package/dist/es5/i3s-attributes-worker.js +29 -0
  35. package/dist/es5/i3s-attributes-worker.js.map +1 -0
  36. package/dist/es5/i3s-converter/helpers/coordinate-converter.js +19 -11
  37. package/dist/es5/i3s-converter/helpers/coordinate-converter.js.map +1 -1
  38. package/dist/es5/i3s-converter/helpers/geometry-attributes.js +2 -2
  39. package/dist/es5/i3s-converter/helpers/geometry-attributes.js.map +1 -1
  40. package/dist/es5/i3s-converter/helpers/geometry-converter.js +267 -178
  41. package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -1
  42. package/dist/es5/i3s-converter/helpers/gltf-attributes.js +71 -0
  43. package/dist/es5/i3s-converter/helpers/gltf-attributes.js.map +1 -0
  44. package/dist/es5/i3s-converter/helpers/node-pages.js +43 -52
  45. package/dist/es5/i3s-converter/helpers/node-pages.js.map +1 -1
  46. package/dist/es5/i3s-converter/i3s-converter.js +264 -219
  47. package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
  48. package/dist/es5/index.js +8 -0
  49. package/dist/es5/index.js.map +1 -1
  50. package/dist/es5/lib/utils/compress-util.js +14 -17
  51. package/dist/es5/lib/utils/compress-util.js.map +1 -1
  52. package/dist/es5/lib/utils/file-utils.js +39 -14
  53. package/dist/es5/lib/utils/file-utils.js.map +1 -1
  54. package/dist/es5/lib/utils/lod-conversion-utils.js.map +1 -1
  55. package/dist/es5/lib/utils/queue.js +61 -0
  56. package/dist/es5/lib/utils/queue.js.map +1 -0
  57. package/dist/es5/lib/utils/statistic-utills.js.map +1 -1
  58. package/dist/es5/lib/utils/write-queue.js +225 -0
  59. package/dist/es5/lib/utils/write-queue.js.map +1 -0
  60. package/dist/es5/pgm-loader.js +1 -1
  61. package/dist/es5/pgm-loader.js.map +1 -1
  62. package/dist/es5/workers/3d-tiles-attributes-worker.js +37 -0
  63. package/dist/es5/workers/3d-tiles-attributes-worker.js.map +1 -0
  64. package/dist/es5/workers/i3s-attributes-worker.js +40 -0
  65. package/dist/es5/workers/i3s-attributes-worker.js.map +1 -0
  66. package/dist/esm/3d-tiles-attributes-worker.js +16 -0
  67. package/dist/esm/3d-tiles-attributes-worker.js.map +1 -0
  68. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js +32 -5
  69. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  70. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js +23 -23
  71. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  72. package/dist/esm/i3s-attributes-worker.js +16 -0
  73. package/dist/esm/i3s-attributes-worker.js.map +1 -0
  74. package/dist/esm/i3s-converter/helpers/coordinate-converter.js +19 -11
  75. package/dist/esm/i3s-converter/helpers/coordinate-converter.js.map +1 -1
  76. package/dist/esm/i3s-converter/helpers/geometry-attributes.js +2 -2
  77. package/dist/esm/i3s-converter/helpers/geometry-attributes.js.map +1 -1
  78. package/dist/esm/i3s-converter/helpers/geometry-converter.js +117 -58
  79. package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -1
  80. package/dist/esm/i3s-converter/helpers/gltf-attributes.js +54 -0
  81. package/dist/esm/i3s-converter/helpers/gltf-attributes.js.map +1 -0
  82. package/dist/esm/i3s-converter/helpers/node-pages.js +12 -9
  83. package/dist/esm/i3s-converter/helpers/node-pages.js.map +1 -1
  84. package/dist/esm/i3s-converter/i3s-converter.js +115 -28
  85. package/dist/esm/i3s-converter/i3s-converter.js.map +1 -1
  86. package/dist/esm/index.js +1 -0
  87. package/dist/esm/index.js.map +1 -1
  88. package/dist/esm/lib/utils/compress-util.js +6 -8
  89. package/dist/esm/lib/utils/compress-util.js.map +1 -1
  90. package/dist/esm/lib/utils/file-utils.js +11 -1
  91. package/dist/esm/lib/utils/file-utils.js.map +1 -1
  92. package/dist/esm/lib/utils/lod-conversion-utils.js.map +1 -1
  93. package/dist/esm/lib/utils/queue.js +19 -0
  94. package/dist/esm/lib/utils/queue.js.map +1 -0
  95. package/dist/esm/lib/utils/statistic-utills.js.map +1 -1
  96. package/dist/esm/lib/utils/write-queue.js +88 -0
  97. package/dist/esm/lib/utils/write-queue.js.map +1 -0
  98. package/dist/esm/pgm-loader.js +1 -1
  99. package/dist/esm/pgm-loader.js.map +1 -1
  100. package/dist/esm/workers/3d-tiles-attributes-worker.js +5 -0
  101. package/dist/esm/workers/3d-tiles-attributes-worker.js.map +1 -0
  102. package/dist/esm/workers/i3s-attributes-worker.js +4 -0
  103. package/dist/esm/workers/i3s-attributes-worker.js.map +1 -0
  104. package/dist/i3s-attributes-worker.d.ts +33 -0
  105. package/dist/i3s-attributes-worker.d.ts.map +1 -0
  106. package/dist/i3s-attributes-worker.js +10 -0
  107. package/dist/i3s-attributes-worker.js.map +7 -0
  108. package/dist/i3s-converter/helpers/coordinate-converter.d.ts +41 -0
  109. package/dist/i3s-converter/helpers/coordinate-converter.d.ts.map +1 -0
  110. package/dist/i3s-converter/helpers/coordinate-converter.js +122 -0
  111. package/dist/i3s-converter/helpers/create-scene-server-path.d.ts +9 -0
  112. package/dist/i3s-converter/helpers/create-scene-server-path.d.ts.map +1 -0
  113. package/dist/i3s-converter/helpers/create-scene-server-path.js +28 -0
  114. package/dist/i3s-converter/helpers/geometry-attributes.d.ts +8 -0
  115. package/dist/i3s-converter/helpers/geometry-attributes.d.ts.map +1 -0
  116. package/dist/i3s-converter/helpers/geometry-attributes.js +177 -0
  117. package/dist/i3s-converter/helpers/geometry-converter.d.ts +29 -0
  118. package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -0
  119. package/dist/i3s-converter/helpers/geometry-converter.js +901 -0
  120. package/dist/i3s-converter/helpers/gltf-attributes.d.ts +9 -0
  121. package/dist/i3s-converter/helpers/gltf-attributes.d.ts.map +1 -0
  122. package/dist/i3s-converter/helpers/gltf-attributes.js +56 -0
  123. package/dist/i3s-converter/helpers/node-debug.d.ts +8 -0
  124. package/dist/i3s-converter/helpers/node-debug.d.ts.map +1 -0
  125. package/dist/i3s-converter/helpers/node-debug.js +114 -0
  126. package/dist/i3s-converter/helpers/node-pages.d.ts +117 -0
  127. package/dist/i3s-converter/helpers/node-pages.d.ts.map +1 -0
  128. package/dist/i3s-converter/helpers/node-pages.js +208 -0
  129. package/dist/i3s-converter/i3s-converter.d.ts +325 -0
  130. package/dist/i3s-converter/i3s-converter.d.ts.map +1 -0
  131. package/dist/i3s-converter/i3s-converter.js +1056 -0
  132. package/dist/i3s-converter/json-templates/layers.d.ts +95 -0
  133. package/dist/i3s-converter/json-templates/layers.d.ts.map +1 -0
  134. package/dist/i3s-converter/json-templates/layers.js +199 -0
  135. package/dist/i3s-converter/json-templates/metadata.d.ts +22 -0
  136. package/dist/i3s-converter/json-templates/metadata.d.ts.map +1 -0
  137. package/dist/i3s-converter/json-templates/metadata.js +25 -0
  138. package/dist/i3s-converter/json-templates/node.d.ts +61 -0
  139. package/dist/i3s-converter/json-templates/node.d.ts.map +1 -0
  140. package/dist/i3s-converter/json-templates/node.js +89 -0
  141. package/dist/i3s-converter/json-templates/scene-server.d.ts +28 -0
  142. package/dist/i3s-converter/json-templates/scene-server.d.ts.map +1 -0
  143. package/dist/i3s-converter/json-templates/scene-server.js +31 -0
  144. package/dist/i3s-converter/json-templates/shared-resources.d.ts +14 -0
  145. package/dist/i3s-converter/json-templates/shared-resources.d.ts.map +1 -0
  146. package/dist/i3s-converter/json-templates/shared-resources.js +129 -0
  147. package/dist/i3s-converter/json-templates/store.d.ts +95 -0
  148. package/dist/i3s-converter/json-templates/store.d.ts.map +1 -0
  149. package/dist/i3s-converter/json-templates/store.js +103 -0
  150. package/dist/i3s-converter/types.d.ts +114 -0
  151. package/dist/i3s-converter/types.d.ts.map +1 -0
  152. package/dist/i3s-converter/types.js +2 -0
  153. package/dist/i3s-server/app.d.ts +3 -0
  154. package/dist/i3s-server/app.d.ts.map +1 -0
  155. package/dist/i3s-server/app.js +14 -0
  156. package/dist/i3s-server/controllers/index-controller.d.ts +2 -0
  157. package/dist/i3s-server/controllers/index-controller.d.ts.map +1 -0
  158. package/dist/i3s-server/controllers/index-controller.js +23 -0
  159. package/dist/i3s-server/routes/index.d.ts +3 -0
  160. package/dist/i3s-server/routes/index.d.ts.map +1 -0
  161. package/dist/i3s-server/routes/index.js +16 -0
  162. package/dist/index.d.ts +6 -0
  163. package/dist/index.d.ts.map +1 -0
  164. package/dist/index.js +16 -0
  165. package/dist/lib/utils/compress-util.d.ts +45 -0
  166. package/dist/lib/utils/compress-util.d.ts.map +1 -0
  167. package/dist/lib/utils/compress-util.js +257 -0
  168. package/{src → dist}/lib/utils/file-utils.d.ts +6 -14
  169. package/dist/lib/utils/file-utils.d.ts.map +1 -0
  170. package/dist/lib/utils/file-utils.js +81 -0
  171. package/dist/lib/utils/lod-conversion-utils.d.ts +41 -0
  172. package/dist/lib/utils/lod-conversion-utils.d.ts.map +1 -0
  173. package/dist/lib/utils/lod-conversion-utils.js +76 -0
  174. package/dist/lib/utils/queue.d.ts +7 -0
  175. package/dist/lib/utils/queue.d.ts.map +1 -0
  176. package/dist/lib/utils/queue.js +18 -0
  177. package/dist/lib/utils/statistic-utills.d.ts +3 -0
  178. package/dist/lib/utils/statistic-utills.d.ts.map +1 -0
  179. package/dist/lib/utils/statistic-utills.js +64 -0
  180. package/dist/lib/utils/write-queue.d.ts +22 -0
  181. package/dist/lib/utils/write-queue.d.ts.map +1 -0
  182. package/dist/lib/utils/write-queue.js +62 -0
  183. package/dist/pgm-loader.d.ts +6 -0
  184. package/dist/pgm-loader.d.ts.map +1 -0
  185. package/dist/pgm-loader.js +23 -0
  186. package/dist/workers/3d-tiles-attributes-worker.d.ts +2 -0
  187. package/dist/workers/3d-tiles-attributes-worker.d.ts.map +1 -0
  188. package/dist/workers/3d-tiles-attributes-worker.js +9 -0
  189. package/dist/workers/i3s-attributes-worker.d.ts +2 -0
  190. package/dist/workers/i3s-attributes-worker.d.ts.map +1 -0
  191. package/dist/workers/i3s-attributes-worker.js +5 -0
  192. package/package.json +20 -18
  193. package/src/3d-tiles-attributes-worker.ts +43 -0
  194. package/src/3d-tiles-converter/3d-tiles-converter.ts +48 -5
  195. package/src/3d-tiles-converter/helpers/b3dm-converter.ts +21 -18
  196. package/src/i3s-attributes-worker.ts +46 -0
  197. package/src/i3s-converter/helpers/coordinate-converter.ts +29 -24
  198. package/src/i3s-converter/helpers/geometry-attributes.ts +4 -3
  199. package/src/i3s-converter/helpers/{geometry-converter.js → geometry-converter.ts} +421 -175
  200. package/src/i3s-converter/helpers/gltf-attributes.ts +68 -0
  201. package/src/i3s-converter/helpers/node-pages.ts +25 -17
  202. package/src/i3s-converter/i3s-converter.ts +124 -69
  203. package/src/i3s-converter/types.ts +90 -8
  204. package/src/index.ts +1 -0
  205. package/src/lib/utils/{compress-util.js → compress-util.ts} +105 -18
  206. package/src/lib/utils/file-utils.ts +84 -0
  207. package/src/lib/utils/{lod-conversion-utils.js → lod-conversion-utils.ts} +27 -5
  208. package/src/lib/utils/queue.ts +17 -0
  209. package/src/lib/utils/{statistic-utills.js → statistic-utills.ts} +0 -0
  210. package/src/lib/utils/write-queue.ts +75 -0
  211. package/src/workers/3d-tiles-attributes-worker.ts +6 -0
  212. package/src/workers/i3s-attributes-worker.ts +6 -0
  213. package/dist/es5/i3s-converter/helpers/geometry-converter.d.ts +0 -44
  214. package/dist/es5/lib/utils/compress-util.d.ts +0 -53
  215. package/dist/es5/lib/utils/file-utils.d.ts +0 -43
  216. package/dist/es5/lib/utils/lod-conversion-utils.d.ts +0 -32
  217. package/dist/esm/i3s-converter/helpers/geometry-converter.d.ts +0 -44
  218. package/dist/esm/lib/utils/compress-util.d.ts +0 -53
  219. package/dist/esm/lib/utils/file-utils.d.ts +0 -43
  220. package/dist/esm/lib/utils/lod-conversion-utils.d.ts +0 -32
  221. package/src/i3s-converter/helpers/geometry-converter.d.ts +0 -44
  222. package/src/lib/utils/compress-util.d.ts +0 -53
  223. package/src/lib/utils/file-utils.js +0 -38
  224. package/src/lib/utils/lod-conversion-utils.d.ts +0 -32
@@ -0,0 +1,278 @@
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);
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) {
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
+ if (attributes.normals && !this._checkNormals(attributes.normals.value)) {
49
+ delete attributes.normals;
50
+ }
51
+ const indices = originalIndices || this._generateSynteticIndices(positionsValue.length / positions.size);
52
+ const meshIndex = gltfBuilder.addMesh({
53
+ attributes,
54
+ indices,
55
+ material: materialIndex,
56
+ mode: 4
57
+ });
58
+ const transformMatrix = this._generateTransformMatrix(cartesianOrigin);
59
+ const nodeIndex = gltfBuilder.addNode({ meshIndex, matrix: transformMatrix });
60
+ const sceneIndex = gltfBuilder.addScene({ nodeIndices: [nodeIndex] });
61
+ gltfBuilder.setDefaultScene(sceneIndex);
62
+ gltfBuilder.createBinaryChunk();
63
+ const gltfBuffer = (0, core_1.encodeSync)(gltfBuilder.gltf, gltf_1.GLTFWriter);
64
+ return gltfBuffer;
65
+ }
66
+ /**
67
+ * Update gltfBuilder with texture from I3S tile
68
+ * @param {object} i3sTile - Tile3D object
69
+ * @param {GLTFScenegraph} gltfBuilder - gltfScenegraph instance to construct GLTF
70
+ * @returns {Promise<number | null>} - GLTF texture index
71
+ */
72
+ async _addI3sTextureToGltf(tileContent, textureFormat, gltfBuilder) {
73
+ const { texture, material, attributes } = tileContent;
74
+ let textureIndex = null;
75
+ let selectedTexture = texture;
76
+ if (!texture && material) {
77
+ selectedTexture =
78
+ material.pbrMetallicRoughness &&
79
+ material.pbrMetallicRoughness.baseColorTexture &&
80
+ material.pbrMetallicRoughness.baseColorTexture.texture.source.image;
81
+ }
82
+ if (selectedTexture) {
83
+ const mimeType = this._deduceMimeTypeFromFormat(textureFormat);
84
+ const imageIndex = gltfBuilder.addImage(selectedTexture, mimeType);
85
+ textureIndex = gltfBuilder.addTexture({ imageIndex });
86
+ delete attributes.colors;
87
+ }
88
+ return textureIndex;
89
+ }
90
+ /**
91
+ * Generate a positions array which is correct for 3DTiles/GLTF format
92
+ * @param {Float64Array} positionsValue - the input geometry positions array
93
+ * @param {number[]} cartesianOrigin - the tile center in the cartesian coordinate system
94
+ * @param {number[]} cartographicOrigin - the tile center in the cartographic coordinate system
95
+ * @param {number[]} modelMatrix - the model matrix of geometry
96
+ * @returns {Float32Array} - the output geometry positions array
97
+ */
98
+ _normalizePositions(positionsValue, cartesianOrigin, cartographicOrigin, modelMatrix) {
99
+ const newPositionsValue = new Float32Array(positionsValue.length);
100
+ for (let index = 0; index < positionsValue.length; index += 3) {
101
+ const vertex = positionsValue.subarray(index, index + 3);
102
+ const cartesianOriginVector = new core_2.Vector3(cartesianOrigin);
103
+ let vertexVector = new core_2.Vector3(Array.from(vertex))
104
+ .transform(modelMatrix)
105
+ .add(cartographicOrigin);
106
+ geospatial_1.Ellipsoid.WGS84.cartographicToCartesian(vertexVector, scratchVector);
107
+ vertexVector = scratchVector.subtract(cartesianOriginVector);
108
+ newPositionsValue.set(vertexVector, index);
109
+ }
110
+ return newPositionsValue;
111
+ }
112
+ /**
113
+ * Generate the transformation matrix for GLTF node:
114
+ * https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#reference-node
115
+ * 1. Create the translate transformation from cartesianOrigin (the positions array stores offsets from this cartesianOrigin)
116
+ * 2. Create the rotation transformation to rotate model from z-up coordinates (I3S specific) to y-up coordinates (GLTF specific)
117
+ * @param {number[]} cartesianOrigin - the tile center in the cartesian coordinate system
118
+ * @returns {Matrix4} - an array of 16 numbers (4x4 matrix)
119
+ */
120
+ _generateTransformMatrix(cartesianOrigin) {
121
+ const translateOriginMatrix = new core_2.Matrix4().translate(cartesianOrigin);
122
+ const result = translateOriginMatrix.multiplyLeft(Z_UP_TO_Y_UP_MATRIX);
123
+ return result;
124
+ }
125
+ /**
126
+ * Generate batchId attribute from faceRanges.
127
+ * @param {Uint32Array} faceRanges - the source array
128
+ * @returns {Float32Array} batchId list.
129
+ */
130
+ _generateBatchId(faceRanges) {
131
+ const batchIdArraySize = (faceRanges[faceRanges.length - 1] + 1) * 3;
132
+ const batchId = new Float32Array(batchIdArraySize);
133
+ let rangeIndex = 0;
134
+ let currentBatchId = 0;
135
+ for (let index = 0; index < faceRanges.length / 2; index++) {
136
+ const fromIndex = faceRanges[rangeIndex] * 3;
137
+ const untilPosition = (faceRanges[rangeIndex + 1] + 1) * 3;
138
+ batchId.fill(currentBatchId, fromIndex, untilPosition);
139
+ rangeIndex += 2;
140
+ currentBatchId += 1;
141
+ }
142
+ return batchId;
143
+ }
144
+ /**
145
+ * luma.gl can not work without indices now:
146
+ * https://github.com/visgl/luma.gl/blob/d8cad75b9f8ca3e578cf078ed9d19e619c2ddbc9/modules/experimental/src/gltf/gltf-instantiator.js#L115
147
+ * This method generates syntetic indices array: [0, 1, 2, 3, .... , vertexCount-1]
148
+ * @param {number} vertexCount - vertex count in the geometry
149
+ * @returns {Uint32Array} indices array.
150
+ */
151
+ _generateSynteticIndices(vertexCount) {
152
+ const result = new Uint32Array(vertexCount);
153
+ for (let index = 0; index < vertexCount; index++) {
154
+ result.set([index], index);
155
+ }
156
+ return result;
157
+ }
158
+ /**
159
+ * Deduce mime type by format from `textureSetDefinition.formats[0].format`
160
+ * https://github.com/Esri/i3s-spec/blob/master/docs/1.7/textureSetDefinitionFormat.cmn.md
161
+ * @param {string} format - format name
162
+ * @returns {string} mime type.
163
+ */
164
+ _deduceMimeTypeFromFormat(format) {
165
+ switch (format) {
166
+ case 'jpg':
167
+ return 'image/jpeg';
168
+ case 'png':
169
+ return 'image/png';
170
+ case 'ktx2':
171
+ return 'image/ktx2';
172
+ default:
173
+ console.warn(`Unexpected texture format in I3S: ${format}`); // eslint-disable-line no-console, no-undef
174
+ return 'image/jpeg';
175
+ }
176
+ }
177
+ /**
178
+ * Convert i3s material to GLTF compatible material
179
+ * @param {object} material - i3s material definition
180
+ * @param {number | null} textureIndex - texture index in GLTF
181
+ * @returns {object} GLTF material
182
+ */
183
+ _convertI3sMaterialToGltfMaterial(material, textureIndex) {
184
+ const isTextureIndexExists = textureIndex !== null;
185
+ if (!material) {
186
+ material = {
187
+ alphaMode: 'OPAQUE',
188
+ doubleSided: false,
189
+ pbrMetallicRoughness: {
190
+ metallicFactor: 0,
191
+ roughnessFactor: 1
192
+ }
193
+ };
194
+ if (isTextureIndexExists) {
195
+ material.pbrMetallicRoughness.baseColorTexture = {
196
+ index: textureIndex,
197
+ texCoord: 0
198
+ };
199
+ }
200
+ else {
201
+ material.pbrMetallicRoughness.baseColorFactor = [1, 1, 1, 1];
202
+ }
203
+ return material;
204
+ }
205
+ if (textureIndex !== null) {
206
+ material = this._setGltfTexture(material, textureIndex);
207
+ }
208
+ return material;
209
+ }
210
+ /**
211
+ * Set texture properties in material with GLTF textureIndex
212
+ * @param {object} materialDefinition - i3s material definition
213
+ * @param {number} textureIndex - texture index in GLTF
214
+ * @returns {void}
215
+ */
216
+ _setGltfTexture(materialDefinition, textureIndex) {
217
+ const material = {
218
+ ...materialDefinition,
219
+ pbrMetallicRoughness: { ...materialDefinition.pbrMetallicRoughness }
220
+ };
221
+ // I3SLoader now support loading only one texture. This elseif sequence will assign this texture to one of
222
+ // properties defined in materialDefinition
223
+ if (materialDefinition.pbrMetallicRoughness &&
224
+ materialDefinition.pbrMetallicRoughness.baseColorTexture) {
225
+ material.pbrMetallicRoughness.baseColorTexture = {
226
+ index: textureIndex,
227
+ texCoord: 0
228
+ };
229
+ }
230
+ else if (materialDefinition.emissiveTexture) {
231
+ material.emissiveTexture = {
232
+ index: textureIndex,
233
+ texCoord: 0
234
+ };
235
+ }
236
+ else if (materialDefinition.pbrMetallicRoughness &&
237
+ materialDefinition.pbrMetallicRoughness.metallicRoughnessTexture) {
238
+ material.pbrMetallicRoughness.metallicRoughnessTexture = {
239
+ index: textureIndex,
240
+ texCoord: 0
241
+ };
242
+ }
243
+ else if (materialDefinition.normalTexture) {
244
+ material.normalTexture = {
245
+ index: textureIndex,
246
+ texCoord: 0
247
+ };
248
+ }
249
+ else if (materialDefinition.occlusionTexture) {
250
+ material.occlusionTexture = {
251
+ index: textureIndex,
252
+ texCoord: 0
253
+ };
254
+ }
255
+ return material;
256
+ }
257
+ /*
258
+ * Returns Features length based on attribute array in attribute object.
259
+ * @param {Object} attributes
260
+ * @returns {Number} Features length .
261
+ */
262
+ _getFeaturesLength(attributes) {
263
+ if (!attributes) {
264
+ return 0;
265
+ }
266
+ const firstKey = Object.keys(attributes)[0];
267
+ return firstKey ? attributes[firstKey].length : 0;
268
+ }
269
+ /* Checks that normals buffer is correct
270
+ * @param {TypedArray} normals
271
+ * @returns {boolean} true - normals are correct; false - normals are incorrect
272
+ */
273
+ _checkNormals(normals) {
274
+ // If all normals === 0, the resulting tileset is all in black colors on Cesium
275
+ return normals.find((value) => value);
276
+ }
277
+ }
278
+ exports.default = B3dmConverter;
@@ -0,0 +1,13 @@
1
+ import { GeoidHeightModel } from '@loaders.gl/tile-converter/lib/geoid-height-model';
2
+ /**
3
+ * Convert quaternion-based OBB to half-axes-based OBB
4
+ * @param i3SObb quaternion based OBB
5
+ * @param geoidHeightModel the Earth Gravity Model instance
6
+ * @returns number[12] 3DTiles OBB https://github.com/CesiumGS/3d-tiles/tree/master/specification#box
7
+ */
8
+ export declare function i3sObbTo3dTilesObb(i3SObb: {
9
+ center: number[];
10
+ halfSize: number[];
11
+ quaternion: number[];
12
+ }, geoidHeightModel: GeoidHeightModel): number[];
13
+ //# sourceMappingURL=i3s-obb-to-3d-tiles-obb.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"i3s-obb-to-3d-tiles-obb.d.ts","sourceRoot":"","sources":["../../../src/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,gBAAgB,EAAC,MAAM,mDAAmD,CAAC;AAEnF;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE;IACN,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB,EACD,gBAAgB,EAAE,gBAAgB,GACjC,MAAM,EAAE,CAaV"}
@@ -0,0 +1,23 @@
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;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Apply uvRegions to texture coordinates.
3
+ * Spec - https://github.com/Esri/i3s-spec/blob/master/docs/1.7/geometryUVRegion.cmn.md
4
+ * Shader formula vec2 uv = fract(texCoords) * (uvRegions.zw - uvRegions.xy) + uvRegions.xy;
5
+ * @param texCoords
6
+ * @param uvRegions
7
+ */
8
+ export declare function convertTextureAtlas(texCoords: Float32Array, uvRegions: Uint16Array): Float32Array;
9
+ //# sourceMappingURL=texture-atlas.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"texture-atlas.d.ts","sourceRoot":"","sources":["../../../src/3d-tiles-converter/helpers/texture-atlas.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,YAAY,EAAE,SAAS,EAAE,WAAW,GAAG,YAAY,CAwBjG"}
@@ -0,0 +1,52 @@
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
+ }
@@ -0,0 +1,15 @@
1
+ export declare const TILESET: () => {
2
+ asset: {
3
+ path: string;
4
+ transform: (val: any) => any;
5
+ };
6
+ geometricError: {
7
+ path: string;
8
+ transform: (val: any) => any;
9
+ };
10
+ root: {
11
+ path: string;
12
+ transform: (val: any) => any;
13
+ };
14
+ };
15
+ //# sourceMappingURL=tileset.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tileset.d.ts","sourceRoot":"","sources":["../../../src/3d-tiles-converter/json-templates/tileset.ts"],"names":[],"mappings":"AAyBA,eAAO,MAAM,OAAO;;;;;;;;;;;;;CAalB,CAAC"}
@@ -0,0 +1,43 @@
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;
@@ -0,0 +1,2 @@
1
+ declare const moduleExports: any;
2
+ //# sourceMappingURL=bundle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../src/bundle.ts"],"names":[],"mappings":"AACA,QAAA,MAAM,aAAa,KAAqB,CAAC"}
package/dist/bundle.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ // @ts-nocheck
3
+ const moduleExports = require('./index');
4
+ globalThis.loaders = globalThis.loaders || {};
5
+ module.exports = Object.assign(globalThis.loaders, moduleExports);