@loaders.gl/tile-converter 3.1.8 → 3.2.0-alpha.3

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 (238) 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-cli.d.ts +2 -0
  24. package/dist/converter-cli.d.ts.map +1 -0
  25. package/dist/converter-cli.js +232 -0
  26. package/dist/converter.min.js +68 -68
  27. package/dist/deps-installer/deps-installer.d.ts +14 -0
  28. package/dist/deps-installer/deps-installer.d.ts.map +1 -0
  29. package/dist/deps-installer/deps-installer.js +31 -0
  30. package/dist/dist.min.js +1151 -1264
  31. package/dist/es5/3d-tiles-attributes-worker.js +29 -0
  32. package/dist/es5/3d-tiles-attributes-worker.js.map +1 -0
  33. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js +104 -44
  34. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  35. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js +34 -43
  36. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  37. package/dist/es5/converter-cli.js +306 -0
  38. package/dist/es5/converter-cli.js.map +1 -0
  39. package/dist/es5/deps-installer/deps-installer.js.map +1 -1
  40. package/dist/es5/i3s-attributes-worker.js +29 -0
  41. package/dist/es5/i3s-attributes-worker.js.map +1 -0
  42. package/dist/es5/i3s-converter/helpers/coordinate-converter.js +19 -11
  43. package/dist/es5/i3s-converter/helpers/coordinate-converter.js.map +1 -1
  44. package/dist/es5/i3s-converter/helpers/geometry-attributes.js +2 -2
  45. package/dist/es5/i3s-converter/helpers/geometry-attributes.js.map +1 -1
  46. package/dist/es5/i3s-converter/helpers/geometry-converter.js +271 -182
  47. package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -1
  48. package/dist/es5/i3s-converter/helpers/gltf-attributes.js +71 -0
  49. package/dist/es5/i3s-converter/helpers/gltf-attributes.js.map +1 -0
  50. package/dist/es5/i3s-converter/helpers/node-pages.js +47 -99
  51. package/dist/es5/i3s-converter/helpers/node-pages.js.map +1 -1
  52. package/dist/es5/i3s-converter/i3s-converter.js +311 -245
  53. package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
  54. package/dist/es5/index.js +0 -16
  55. package/dist/es5/index.js.map +1 -1
  56. package/dist/es5/lib/utils/compress-util.js +14 -17
  57. package/dist/es5/lib/utils/compress-util.js.map +1 -1
  58. package/dist/es5/lib/utils/file-utils.js +39 -14
  59. package/dist/es5/lib/utils/file-utils.js.map +1 -1
  60. package/dist/es5/lib/utils/lod-conversion-utils.js.map +1 -1
  61. package/dist/es5/lib/utils/queue.js +61 -0
  62. package/dist/es5/lib/utils/queue.js.map +1 -0
  63. package/dist/es5/lib/utils/statistic-utills.js.map +1 -1
  64. package/dist/es5/lib/utils/write-queue.js +225 -0
  65. package/dist/es5/lib/utils/write-queue.js.map +1 -0
  66. package/dist/es5/pgm-loader.js +1 -1
  67. package/dist/es5/pgm-loader.js.map +1 -1
  68. package/dist/es5/workers/3d-tiles-attributes-worker.js +37 -0
  69. package/dist/es5/workers/3d-tiles-attributes-worker.js.map +1 -0
  70. package/dist/es5/workers/i3s-attributes-worker.js +40 -0
  71. package/dist/es5/workers/i3s-attributes-worker.js.map +1 -0
  72. package/dist/esm/3d-tiles-attributes-worker.js +16 -0
  73. package/dist/esm/3d-tiles-attributes-worker.js.map +1 -0
  74. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js +32 -5
  75. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  76. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js +23 -23
  77. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  78. package/dist/esm/converter-cli.js +230 -0
  79. package/dist/esm/converter-cli.js.map +1 -0
  80. package/dist/esm/deps-installer/deps-installer.js.map +1 -1
  81. package/dist/esm/i3s-attributes-worker.js +16 -0
  82. package/dist/esm/i3s-attributes-worker.js.map +1 -0
  83. package/dist/esm/i3s-converter/helpers/coordinate-converter.js +19 -11
  84. package/dist/esm/i3s-converter/helpers/coordinate-converter.js.map +1 -1
  85. package/dist/esm/i3s-converter/helpers/geometry-attributes.js +2 -2
  86. package/dist/esm/i3s-converter/helpers/geometry-attributes.js.map +1 -1
  87. package/dist/esm/i3s-converter/helpers/geometry-converter.js +121 -62
  88. package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -1
  89. package/dist/esm/i3s-converter/helpers/gltf-attributes.js +54 -0
  90. package/dist/esm/i3s-converter/helpers/gltf-attributes.js.map +1 -0
  91. package/dist/esm/i3s-converter/helpers/node-pages.js +12 -4
  92. package/dist/esm/i3s-converter/helpers/node-pages.js.map +1 -1
  93. package/dist/esm/i3s-converter/i3s-converter.js +155 -50
  94. package/dist/esm/i3s-converter/i3s-converter.js.map +1 -1
  95. package/dist/esm/index.js +0 -2
  96. package/dist/esm/index.js.map +1 -1
  97. package/dist/esm/lib/utils/compress-util.js +6 -8
  98. package/dist/esm/lib/utils/compress-util.js.map +1 -1
  99. package/dist/esm/lib/utils/file-utils.js +11 -1
  100. package/dist/esm/lib/utils/file-utils.js.map +1 -1
  101. package/dist/esm/lib/utils/lod-conversion-utils.js.map +1 -1
  102. package/dist/esm/lib/utils/queue.js +19 -0
  103. package/dist/esm/lib/utils/queue.js.map +1 -0
  104. package/dist/esm/lib/utils/statistic-utills.js.map +1 -1
  105. package/dist/esm/lib/utils/write-queue.js +88 -0
  106. package/dist/esm/lib/utils/write-queue.js.map +1 -0
  107. package/dist/esm/pgm-loader.js +1 -1
  108. package/dist/esm/pgm-loader.js.map +1 -1
  109. package/dist/esm/workers/3d-tiles-attributes-worker.js +5 -0
  110. package/dist/esm/workers/3d-tiles-attributes-worker.js.map +1 -0
  111. package/dist/esm/workers/i3s-attributes-worker.js +4 -0
  112. package/dist/esm/workers/i3s-attributes-worker.js.map +1 -0
  113. package/dist/i3s-attributes-worker.d.ts +33 -0
  114. package/dist/i3s-attributes-worker.d.ts.map +1 -0
  115. package/dist/i3s-attributes-worker.js +10 -0
  116. package/dist/i3s-attributes-worker.js.map +7 -0
  117. package/dist/i3s-converter/helpers/coordinate-converter.d.ts +41 -0
  118. package/dist/i3s-converter/helpers/coordinate-converter.d.ts.map +1 -0
  119. package/dist/i3s-converter/helpers/coordinate-converter.js +122 -0
  120. package/dist/i3s-converter/helpers/create-scene-server-path.d.ts +9 -0
  121. package/dist/i3s-converter/helpers/create-scene-server-path.d.ts.map +1 -0
  122. package/dist/i3s-converter/helpers/create-scene-server-path.js +28 -0
  123. package/dist/i3s-converter/helpers/geometry-attributes.d.ts +8 -0
  124. package/dist/i3s-converter/helpers/geometry-attributes.d.ts.map +1 -0
  125. package/dist/i3s-converter/helpers/geometry-attributes.js +177 -0
  126. package/dist/i3s-converter/helpers/geometry-converter.d.ts +29 -0
  127. package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -0
  128. package/dist/i3s-converter/helpers/geometry-converter.js +901 -0
  129. package/dist/i3s-converter/helpers/gltf-attributes.d.ts +9 -0
  130. package/dist/i3s-converter/helpers/gltf-attributes.d.ts.map +1 -0
  131. package/dist/i3s-converter/helpers/gltf-attributes.js +56 -0
  132. package/dist/i3s-converter/helpers/node-debug.d.ts +8 -0
  133. package/dist/i3s-converter/helpers/node-debug.d.ts.map +1 -0
  134. package/dist/i3s-converter/helpers/node-debug.js +114 -0
  135. package/dist/i3s-converter/helpers/node-pages.d.ts +117 -0
  136. package/dist/i3s-converter/helpers/node-pages.d.ts.map +1 -0
  137. package/dist/i3s-converter/helpers/node-pages.js +208 -0
  138. package/dist/i3s-converter/i3s-converter.d.ts +323 -0
  139. package/dist/i3s-converter/i3s-converter.d.ts.map +1 -0
  140. package/dist/i3s-converter/i3s-converter.js +1074 -0
  141. package/dist/i3s-converter/json-templates/layers.d.ts +95 -0
  142. package/dist/i3s-converter/json-templates/layers.d.ts.map +1 -0
  143. package/dist/i3s-converter/json-templates/layers.js +199 -0
  144. package/dist/i3s-converter/json-templates/metadata.d.ts +22 -0
  145. package/dist/i3s-converter/json-templates/metadata.d.ts.map +1 -0
  146. package/dist/i3s-converter/json-templates/metadata.js +25 -0
  147. package/dist/i3s-converter/json-templates/node.d.ts +61 -0
  148. package/dist/i3s-converter/json-templates/node.d.ts.map +1 -0
  149. package/dist/i3s-converter/json-templates/node.js +89 -0
  150. package/dist/i3s-converter/json-templates/scene-server.d.ts +28 -0
  151. package/dist/i3s-converter/json-templates/scene-server.d.ts.map +1 -0
  152. package/dist/i3s-converter/json-templates/scene-server.js +31 -0
  153. package/dist/i3s-converter/json-templates/shared-resources.d.ts +14 -0
  154. package/dist/i3s-converter/json-templates/shared-resources.d.ts.map +1 -0
  155. package/dist/i3s-converter/json-templates/shared-resources.js +129 -0
  156. package/dist/i3s-converter/json-templates/store.d.ts +95 -0
  157. package/dist/i3s-converter/json-templates/store.d.ts.map +1 -0
  158. package/dist/i3s-converter/json-templates/store.js +103 -0
  159. package/dist/i3s-converter/types.d.ts +114 -0
  160. package/dist/i3s-converter/types.d.ts.map +1 -0
  161. package/dist/i3s-converter/types.js +2 -0
  162. package/dist/i3s-server/app.d.ts +3 -0
  163. package/dist/i3s-server/app.d.ts.map +1 -0
  164. package/dist/i3s-server/app.js +14 -0
  165. package/dist/i3s-server/controllers/index-controller.d.ts +2 -0
  166. package/dist/i3s-server/controllers/index-controller.d.ts.map +1 -0
  167. package/dist/i3s-server/controllers/index-controller.js +23 -0
  168. package/dist/i3s-server/routes/index.d.ts +3 -0
  169. package/dist/i3s-server/routes/index.d.ts.map +1 -0
  170. package/dist/i3s-server/routes/index.js +16 -0
  171. package/dist/index.d.ts +3 -0
  172. package/dist/index.d.ts.map +1 -0
  173. package/dist/index.js +10 -0
  174. package/dist/lib/utils/compress-util.d.ts +45 -0
  175. package/dist/lib/utils/compress-util.d.ts.map +1 -0
  176. package/dist/lib/utils/compress-util.js +257 -0
  177. package/dist/{esm/lib → lib}/utils/file-utils.d.ts +6 -14
  178. package/dist/lib/utils/file-utils.d.ts.map +1 -0
  179. package/dist/lib/utils/file-utils.js +81 -0
  180. package/dist/lib/utils/lod-conversion-utils.d.ts +41 -0
  181. package/dist/lib/utils/lod-conversion-utils.d.ts.map +1 -0
  182. package/dist/lib/utils/lod-conversion-utils.js +76 -0
  183. package/dist/lib/utils/queue.d.ts +7 -0
  184. package/dist/lib/utils/queue.d.ts.map +1 -0
  185. package/dist/lib/utils/queue.js +18 -0
  186. package/dist/lib/utils/statistic-utills.d.ts +3 -0
  187. package/dist/lib/utils/statistic-utills.d.ts.map +1 -0
  188. package/dist/lib/utils/statistic-utills.js +64 -0
  189. package/dist/lib/utils/write-queue.d.ts +22 -0
  190. package/dist/lib/utils/write-queue.d.ts.map +1 -0
  191. package/dist/lib/utils/write-queue.js +62 -0
  192. package/dist/pgm-loader.d.ts +6 -0
  193. package/dist/pgm-loader.d.ts.map +1 -0
  194. package/dist/pgm-loader.js +23 -0
  195. package/dist/workers/3d-tiles-attributes-worker.d.ts +2 -0
  196. package/dist/workers/3d-tiles-attributes-worker.d.ts.map +1 -0
  197. package/dist/workers/3d-tiles-attributes-worker.js +9 -0
  198. package/dist/workers/i3s-attributes-worker.d.ts +2 -0
  199. package/dist/workers/i3s-attributes-worker.d.ts.map +1 -0
  200. package/dist/workers/i3s-attributes-worker.js +5 -0
  201. package/package.json +19 -18
  202. package/src/3d-tiles-attributes-worker.ts +43 -0
  203. package/src/3d-tiles-converter/3d-tiles-converter.ts +49 -6
  204. package/src/3d-tiles-converter/helpers/b3dm-converter.ts +21 -18
  205. package/src/converter-cli.ts +310 -0
  206. package/src/deps-installer/{deps-installer.js → deps-installer.ts} +11 -1
  207. package/src/i3s-attributes-worker.ts +46 -0
  208. package/src/i3s-converter/helpers/coordinate-converter.ts +29 -24
  209. package/src/i3s-converter/helpers/geometry-attributes.ts +4 -3
  210. package/src/i3s-converter/helpers/{geometry-converter.js → geometry-converter.ts} +425 -179
  211. package/src/i3s-converter/helpers/gltf-attributes.ts +68 -0
  212. package/src/i3s-converter/helpers/node-pages.ts +25 -17
  213. package/src/i3s-converter/i3s-converter.ts +154 -87
  214. package/src/i3s-converter/types.ts +90 -8
  215. package/src/index.ts +0 -4
  216. package/src/lib/utils/{compress-util.js → compress-util.ts} +105 -18
  217. package/src/lib/utils/file-utils.ts +84 -0
  218. package/src/lib/utils/{lod-conversion-utils.js → lod-conversion-utils.ts} +27 -5
  219. package/src/lib/utils/queue.ts +17 -0
  220. package/src/lib/utils/{statistic-utills.js → statistic-utills.ts} +0 -0
  221. package/src/lib/utils/write-queue.ts +75 -0
  222. package/src/workers/3d-tiles-attributes-worker.ts +6 -0
  223. package/src/workers/i3s-attributes-worker.ts +6 -0
  224. package/dist/es5/deps-installer/deps-installer.d.ts +0 -10
  225. package/dist/es5/i3s-converter/helpers/geometry-converter.d.ts +0 -44
  226. package/dist/es5/lib/utils/compress-util.d.ts +0 -53
  227. package/dist/es5/lib/utils/file-utils.d.ts +0 -43
  228. package/dist/es5/lib/utils/lod-conversion-utils.d.ts +0 -32
  229. package/dist/esm/deps-installer/deps-installer.d.ts +0 -10
  230. package/dist/esm/i3s-converter/helpers/geometry-converter.d.ts +0 -44
  231. package/dist/esm/lib/utils/compress-util.d.ts +0 -53
  232. package/dist/esm/lib/utils/lod-conversion-utils.d.ts +0 -32
  233. package/src/deps-installer/deps-installer.d.ts +0 -10
  234. package/src/i3s-converter/helpers/geometry-converter.d.ts +0 -44
  235. package/src/lib/utils/compress-util.d.ts +0 -53
  236. package/src/lib/utils/file-utils.d.ts +0 -43
  237. package/src/lib/utils/file-utils.js +0 -38
  238. package/src/lib/utils/lod-conversion-utils.d.ts +0 -32
@@ -0,0 +1,230 @@
1
+ import '@loaders.gl/polyfills';
2
+ import { join } from 'path';
3
+ import { I3SConverter, Tiles3DConverter } from '@loaders.gl/tile-converter';
4
+ import { DepsInstaller } from './deps-installer/deps-installer';
5
+ const TILESET_TYPE = {
6
+ I3S: 'I3S',
7
+ _3DTILES: '3DTILES'
8
+ };
9
+
10
+ async function main() {
11
+ const [,, ...args] = process.argv;
12
+
13
+ if (args.length === 0) {
14
+ printHelp();
15
+ }
16
+
17
+ const options = parseOptions(args);
18
+
19
+ if (options.installDependencies) {
20
+ const depthInstaller = new DepsInstaller();
21
+ depthInstaller.install('deps');
22
+ return;
23
+ }
24
+
25
+ const validatedOptions = validateOptions(options);
26
+ await convert(validatedOptions);
27
+ }
28
+
29
+ main().catch(error => {
30
+ console.log(error);
31
+ process.exit(1);
32
+ });
33
+
34
+ function printHelp() {
35
+ console.log('cli: converter 3dTiles to I3S or I3S to 3dTiles...');
36
+ console.log('--install-dependencies [Run the script for installing dependencies. Run this options separate from others. Now "*.pgm" file installation is implemented]');
37
+ console.log('--max-depth [Maximal depth of hierarchical tiles tree traversal, default: infinite]');
38
+ console.log('--name [Tileset name]');
39
+ console.log('--output [Output folder, default: "data" folder]');
40
+ console.log('--slpk [Generate slpk (Scene Layer Packages) I3S output file]');
41
+ console.log('--tileset [tileset.json file (3DTiles) / http://..../SceneServer/layers/0 resource (I3S)]');
42
+ console.log('--input-type [tileset input type: I3S or 3DTILES]');
43
+ console.log('--7zExe [location of 7z.exe archiver to create slpk on Windows, default: "C:\\Program Files\\7-Zip\\7z.exe"]');
44
+ console.log('--egm [location of Earth Gravity Model *.pgm file to convert heights from ellipsoidal to gravity-related format. A model file can be loaded from GeographicLib https://geographiclib.sourceforge.io/html/geoid.html], default: "./deps/egm2008-5.zip"');
45
+ console.log('--token [Token for Cesium ION tilesets authentication]');
46
+ console.log('--no-draco [Disable draco compression for geometry]');
47
+ console.log('--generate-textures [Enable KTX2 textures generation if only one of (JPG, PNG) texture is provided or generate JPG texture if only KTX2 is provided]');
48
+ console.log('--generate-bounding-volumes [Will generate obb and mbs bounding volumes from geometry]');
49
+ console.log('--validate [Enable validation]');
50
+ process.exit(0);
51
+ }
52
+
53
+ async function convert(options) {
54
+ console.log("------------------------------------------------");
55
+ console.log("Starting conversion of ".concat(options.inputType));
56
+ console.log("------------------------------------------------");
57
+ const inputType = options.inputType.toUpperCase();
58
+
59
+ switch (inputType) {
60
+ case TILESET_TYPE.I3S:
61
+ const tiles3DConverter = new Tiles3DConverter();
62
+ tiles3DConverter.convert({
63
+ inputUrl: options.tileset,
64
+ outputPath: options.output,
65
+ tilesetName: options.name,
66
+ maxDepth: options.maxDepth,
67
+ egmFilePath: options.egm
68
+ });
69
+ break;
70
+
71
+ case TILESET_TYPE._3DTILES:
72
+ const converter = new I3SConverter();
73
+ await converter.convert({
74
+ inputUrl: options.tileset,
75
+ outputPath: options.output,
76
+ tilesetName: options.name,
77
+ maxDepth: options.maxDepth,
78
+ slpk: options.slpk,
79
+ sevenZipExe: options.sevenZipExe,
80
+ egmFilePath: options.egm,
81
+ token: options.token,
82
+ draco: options.draco,
83
+ generateTextures: options.generateTextures,
84
+ generateBoundingVolumes: options.generateBoundingVolumes,
85
+ validate: options.validate
86
+ });
87
+ break;
88
+
89
+ default:
90
+ printHelp();
91
+ }
92
+ }
93
+
94
+ function validateOptions(options) {
95
+ const mandatoryOptionsWithExceptions = {
96
+ name: () => console.log('Missed: --name [Tileset name]'),
97
+ output: () => console.log('Missed: --output [Output path name]'),
98
+ sevenZipExe: () => console.log('Missed: --7zExe [7z archiver executable path]'),
99
+ egm: () => console.log('Missed: --egm [*.pgm earth gravity model file path]'),
100
+ tileset: () => console.log('Missed: --tileset [tileset.json file]'),
101
+ inputType: () => console.log('Missed/Incorrect: --input-type [tileset input type: I3S or 3DTILES]')
102
+ };
103
+ const exceptions = [];
104
+
105
+ for (const mandatoryOption in mandatoryOptionsWithExceptions) {
106
+ const optionValue = options[mandatoryOption];
107
+ const isWrongInputType = Boolean(optionValue) && mandatoryOption === 'inputType' && !Object.values(TILESET_TYPE).includes(optionValue.toUpperCase());
108
+
109
+ if (!optionValue || isWrongInputType) {
110
+ exceptions.push(mandatoryOptionsWithExceptions[mandatoryOption]);
111
+ }
112
+ }
113
+
114
+ if (exceptions.length) {
115
+ exceptions.forEach(exeption => exeption());
116
+ process.exit(0);
117
+ }
118
+
119
+ return options;
120
+ }
121
+
122
+ function parseOptions(args) {
123
+ const opts = {
124
+ output: 'data',
125
+ sevenZipExe: 'C:\\Program Files\\7-Zip\\7z.exe',
126
+ egm: join(process.cwd(), 'deps', 'egm2008-5.pgm'),
127
+ draco: true,
128
+ installDependencies: false,
129
+ generateTextures: false,
130
+ generateBoundingVolumes: false,
131
+ validate: false,
132
+ slpk: false
133
+ };
134
+ args.forEach((arg, index) => {
135
+ if (arg.indexOf('--') === 0) {
136
+ switch (arg) {
137
+ case '--input-type':
138
+ opts.inputType = getStringValue(index, args);
139
+ break;
140
+
141
+ case '--tileset':
142
+ opts.tileset = getStringValue(index, args);
143
+ break;
144
+
145
+ case '--name':
146
+ opts.name = getStringValue(index, args);
147
+ break;
148
+
149
+ case '--output':
150
+ opts.output = getStringValue(index, args);
151
+ break;
152
+
153
+ case '--max-depth':
154
+ opts.maxDepth = getIntegerValue(index, args);
155
+ break;
156
+
157
+ case '--slpk':
158
+ opts.slpk = true;
159
+ break;
160
+
161
+ case '--7zExe':
162
+ opts.sevenZipExe = getStringValue(index, args);
163
+ break;
164
+
165
+ case '--egm':
166
+ opts.egm = getStringValue(index, args);
167
+ break;
168
+
169
+ case '--token':
170
+ opts.token = getStringValue(index, args);
171
+ break;
172
+
173
+ case '--no-draco':
174
+ opts.draco = false;
175
+ break;
176
+
177
+ case '--validate':
178
+ opts.validate = true;
179
+ break;
180
+
181
+ case '--install-dependencies':
182
+ opts.installDependencies = true;
183
+ break;
184
+
185
+ case '--generate-textures':
186
+ opts.generateTextures = true;
187
+ break;
188
+
189
+ case '--generate-bounding-volumes':
190
+ opts.generateBoundingVolumes = true;
191
+ break;
192
+
193
+ case '--help':
194
+ printHelp();
195
+ break;
196
+
197
+ default:
198
+ console.warn("Unknown option ".concat(arg));
199
+ process.exit(0);
200
+ }
201
+ }
202
+ });
203
+ return opts;
204
+ }
205
+
206
+ function getStringValue(index, args) {
207
+ if (index + 1 >= args.length) {
208
+ return '';
209
+ }
210
+
211
+ const value = args[index + 1];
212
+
213
+ if (value.indexOf('--') === 0) {
214
+ return '';
215
+ }
216
+
217
+ return value;
218
+ }
219
+
220
+ function getIntegerValue(index, args) {
221
+ const stringValue = getStringValue(index, args);
222
+ const result = Number.parseInt(stringValue);
223
+
224
+ if (isFinite(result)) {
225
+ return result;
226
+ }
227
+
228
+ return NaN;
229
+ }
230
+ //# sourceMappingURL=converter-cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/converter-cli.ts"],"names":["join","I3SConverter","Tiles3DConverter","DepsInstaller","TILESET_TYPE","I3S","_3DTILES","main","args","process","argv","length","printHelp","options","parseOptions","installDependencies","depthInstaller","install","validatedOptions","validateOptions","convert","catch","error","console","log","exit","inputType","toUpperCase","tiles3DConverter","inputUrl","tileset","outputPath","output","tilesetName","name","maxDepth","egmFilePath","egm","converter","slpk","sevenZipExe","token","draco","generateTextures","generateBoundingVolumes","validate","mandatoryOptionsWithExceptions","exceptions","mandatoryOption","optionValue","isWrongInputType","Boolean","Object","values","includes","push","forEach","exeption","opts","cwd","arg","index","indexOf","getStringValue","getIntegerValue","warn","value","stringValue","result","Number","parseInt","isFinite","NaN"],"mappings":"AACA,OAAO,uBAAP;AACA,SAAQA,IAAR,QAAmB,MAAnB;AACA,SAAQC,YAAR,EAAsBC,gBAAtB,QAA6C,4BAA7C;AACA,SAAQC,aAAR,QAA4B,iCAA5B;AAgDA,MAAMC,YAAY,GAAG;AACnBC,EAAAA,GAAG,EAAE,KADc;AAEnBC,EAAAA,QAAQ,EAAE;AAFS,CAArB;;AASA,eAAeC,IAAf,GAAsB;AACpB,QAAM,IAAK,GAAGC,IAAR,IAAgBC,OAAO,CAACC,IAA9B;;AAEA,MAAIF,IAAI,CAACG,MAAL,KAAgB,CAApB,EAAuB;AACrBC,IAAAA,SAAS;AACV;;AAED,QAAMC,OAA8B,GAAGC,YAAY,CAACN,IAAD,CAAnD;;AAEA,MAAIK,OAAO,CAACE,mBAAZ,EAAiC;AAC/B,UAAMC,cAAc,GAAG,IAAIb,aAAJ,EAAvB;AACAa,IAAAA,cAAc,CAACC,OAAf,CAAuB,MAAvB;AACA;AACD;;AAED,QAAMC,gBAAgD,GAAGC,eAAe,CAACN,OAAD,CAAxE;AAEA,QAAMO,OAAO,CAACF,gBAAD,CAAb;AACD;;AAEDX,IAAI,GAAGc,KAAP,CAAcC,KAAD,IAAW;AACtBC,EAAAA,OAAO,CA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;;AACF,aAAK,YAAL;AACEkD,UAAAA,IAAI,CAAChB,KAAL,GAAa,KAAb;AACA;;AACF,aAAK,YAAL;AACEgB,UAAAA,IAAI,CAACb,QAAL,GAAgB,IAAhB;AACA;;AACF,aAAK,wBAAL;AACEa,UAAAA,IAAI,CAAC3C,mBAAL,GAA2B,IAA3B;AACA;;AACF,aAAK,qBAAL;AACE2C,UAAAA,IAAI,CAACf,gBAAL,GAAwB,IAAxB;AACA;;AACF,aAAK,6BAAL;AACEe,UAAAA,IAAI,CAACd,uBAAL,GAA+B,IAA/B;AACA;;AACF,aAAK,QAAL;AACEhC,UAAAA,SAAS;AACT;;AACF;AACEW,UAAAA,OAAO,CAAC0C,IAAR,0BAA+BL,GAA/B;AACAnD,UAAAA,OAAO,CAACgB,IAAR,CAAa,CAAb;AAhDJ;AAkDD;AACF,GArDD;AAsDA,SAAOiC,IAAP;AACD;;AASD,SAASK,cAAT,CAAwBF,KAAxB,EAAuCrD,IAAvC,EAA+D;AAC7D,MAAIqD,KAAK,GAAG,CAAR,IAAarD,IAAI,CAACG,MAAtB,EAA8B;AAC5B,WAAO,EAAP;AACD;;AACD,QAAMuD,KAAK,GAAG1D,IAAI,CAACqD,KAAK,GAAG,CAAT,CAAlB;;AACA,MAAIK,KAAK,CAACJ,OAAN,CAAc,IAAd,MAAwB,CAA5B,EAA+B;AAC7B,WAAO,EAAP;AACD;;AACD,SAAOI,KAAP;AACD;;AASD,SAASF,eAAT,CAAyBH,KAAzB,EAAwCrD,IAAxC,EAAgE;AAC9D,QAAM2D,WAAmB,GAAGJ,cAAc,CAACF,KAAD,EAAQrD,IAAR,CAA1C;AACA,QAAM4D,MAAc,GAAGC,MAAM,CAACC,QAAP,CAAgBH,WAAhB,CAAvB;;AACA,MAAII,QAAQ,CAACH,MAAD,CAAZ,EAAsB;AACpB,WAAOA,MAAP;AACD;;AACD,SAAOI,GAAP;AACD","sourcesContent":["/* eslint-disable no-console */\nimport '@loaders.gl/polyfills';\nimport {join} from 'path';\nimport {I3SConverter, Tiles3DConverter} from '@loaders.gl/tile-converter';\nimport {DepsInstaller} from './deps-installer/deps-installer';\n\ntype TileConversionOptions = {\n /** \"I3S\" - for I3S to 3DTiles conversion, \"3DTILES\" for 3DTiles to I3S conversion */\n inputType?: string;\n /** \"tileset.json\" file (3DTiles) / \"http://..../SceneServer/layers/0\" resource (I3S) */\n tileset?: string;\n /** Tileset name. This option is used for naming in resulting json resouces and for resulting path/*.slpk file naming */\n name?: string;\n /** Output folder. This folder will be created by converter if doesn't exist. It is relative to the converter path.\n * Default: \"data\" folder */\n output: string;\n /** 3DTiles->I3S only. location of 7z.exe archiver to create slpk on Windows OS, default: \"C:\\Program Files\\7-Zip\\7z.exe\" */\n sevenZipExe: string;\n /** location of the Earth Gravity Model (*.pgm) file to convert heights from ellipsoidal to gravity-related format,\n * default: \"./deps/egm2008-5.pgm\". A model file can be loaded from GeographicLib\n * https://geographiclib.sourceforge.io/html/geoid.html */\n egm: string;\n /** 3DTile->I3S only. Token for Cesium ION tileset authentication. */\n token?: string;\n /** 3DTiles->I3S only. Enable draco compression for geometry. Default: true */\n draco: boolean;\n /** Run the script for installing dependencies. Run this options separate from others. Now \"*.pgm\" file installation is\n * implemented */\n installDependencies: boolean;\n /** 3DTile->I3S only. Enable KTX2 textures generation if only one of (JPG, PNG) texture is provided or generate JPG texture\n * if only KTX2 is provided */\n generateTextures: boolean;\n /** 3DTile->I3S only. Will generate obb and mbs bounding volumes from geometry */\n generateBoundingVolumes: boolean;\n /** Validate the dataset during conversion. Validation messages will be posted in the console output */\n validate: boolean;\n /** Maximal depth of the hierarchical tiles tree traversal, default: infinite */\n maxDepth?: number;\n /** 3DTiles->I3S only. Whether the converter generates *.slpk (Scene Layer Package) I3S output file */\n slpk: boolean;\n};\n\n/* During validation we check that particular options are defined so they can't be undefined */\ntype ValidatedTileConversionOptions = TileConversionOptions & {\n /** \"I3S\" - for I3S to 3DTiles conversion, \"3DTILES\" for 3DTiles to I3S conversion */\n inputType: string;\n /** \"tileset.json\" file (3DTiles) / \"http://..../SceneServer/layers/0\" resource (I3S) */\n tileset: string;\n /** Tileset name. This option is used for naming in resulting json resouces and for resulting path/*.slpk file naming */\n name: string;\n};\n\nconst TILESET_TYPE = {\n I3S: 'I3S',\n _3DTILES: '3DTILES'\n};\n\n/**\n * CLI entry\n * @returns\n */\nasync function main() {\n const [, , ...args] = process.argv;\n\n if (args.length === 0) {\n printHelp();\n }\n\n const options: TileConversionOptions = parseOptions(args);\n\n if (options.installDependencies) {\n const depthInstaller = new DepsInstaller();\n depthInstaller.install('deps');\n return;\n }\n\n const validatedOptions: ValidatedTileConversionOptions = validateOptions(options);\n\n await convert(validatedOptions);\n}\n\nmain().catch((error) => {\n console.log(error);\n process.exit(1); // eslint-disable-line\n});\n\n/**\n * Output for `npx tile-converter --help`\n */\nfunction printHelp(): void {\n console.log('cli: converter 3dTiles to I3S or I3S to 3dTiles...');\n console.log(\n '--install-dependencies [Run the script for installing dependencies. Run this options separate from others. Now \"*.pgm\" file installation is implemented]'\n );\n console.log(\n '--max-depth [Maximal depth of hierarchical tiles tree traversal, default: infinite]'\n );\n console.log('--name [Tileset name]');\n console.log('--output [Output folder, default: \"data\" folder]');\n console.log('--slpk [Generate slpk (Scene Layer Packages) I3S output file]');\n console.log(\n '--tileset [tileset.json file (3DTiles) / http://..../SceneServer/layers/0 resource (I3S)]'\n );\n console.log('--input-type [tileset input type: I3S or 3DTILES]');\n console.log(\n '--7zExe [location of 7z.exe archiver to create slpk on Windows, default: \"C:\\\\Program Files\\\\7-Zip\\\\7z.exe\"]'\n );\n console.log(\n '--egm [location of Earth Gravity Model *.pgm file to convert heights from ellipsoidal to gravity-related format. A model file can be loaded from GeographicLib https://geographiclib.sourceforge.io/html/geoid.html], default: \"./deps/egm2008-5.zip\"'\n );\n console.log('--token [Token for Cesium ION tilesets authentication]');\n console.log('--no-draco [Disable draco compression for geometry]');\n console.log(\n '--generate-textures [Enable KTX2 textures generation if only one of (JPG, PNG) texture is provided or generate JPG texture if only KTX2 is provided]'\n );\n console.log(\n '--generate-bounding-volumes [Will generate obb and mbs bounding volumes from geometry]'\n );\n console.log('--validate [Enable validation]');\n process.exit(0); // eslint-disable-line\n}\n\n/**\n * Run conversion process\n * @param options validated tile-converter options\n */\nasync function convert(options: ValidatedTileConversionOptions) {\n console.log(`------------------------------------------------`); // eslint-disable-line\n console.log(`Starting conversion of ${options.inputType}`); // eslint-disable-line\n console.log(`------------------------------------------------`); // eslint-disable-line\n const inputType = options.inputType.toUpperCase();\n switch (inputType) {\n case TILESET_TYPE.I3S:\n const tiles3DConverter = new Tiles3DConverter();\n tiles3DConverter.convert({\n inputUrl: options.tileset,\n outputPath: options.output,\n tilesetName: options.name,\n maxDepth: options.maxDepth,\n egmFilePath: options.egm\n });\n break;\n case TILESET_TYPE._3DTILES:\n const converter = new I3SConverter();\n await converter.convert({\n inputUrl: options.tileset,\n outputPath: options.output,\n tilesetName: options.name,\n maxDepth: options.maxDepth,\n slpk: options.slpk,\n sevenZipExe: options.sevenZipExe,\n egmFilePath: options.egm,\n token: options.token,\n draco: options.draco,\n generateTextures: options.generateTextures,\n generateBoundingVolumes: options.generateBoundingVolumes,\n validate: options.validate\n });\n break;\n default:\n printHelp();\n }\n}\n\n// OPTIONS\n/**\n * Validate input options of the CLI command\n * @param options - input options of the CLI command\n * @returns validated options\n */\nfunction validateOptions(options: TileConversionOptions): ValidatedTileConversionOptions {\n const mandatoryOptionsWithExceptions: {\n [key: string]: () => void;\n } = {\n name: () => console.log('Missed: --name [Tileset name]'),\n output: () => console.log('Missed: --output [Output path name]'),\n sevenZipExe: () => console.log('Missed: --7zExe [7z archiver executable path]'),\n egm: () => console.log('Missed: --egm [*.pgm earth gravity model file path]'),\n tileset: () => console.log('Missed: --tileset [tileset.json file]'),\n inputType: () =>\n console.log('Missed/Incorrect: --input-type [tileset input type: I3S or 3DTILES]')\n };\n const exceptions: (() => void)[] = [];\n for (const mandatoryOption in mandatoryOptionsWithExceptions) {\n const optionValue = options[mandatoryOption];\n const isWrongInputType =\n Boolean(optionValue) &&\n mandatoryOption === 'inputType' &&\n !Object.values(TILESET_TYPE).includes(optionValue.toUpperCase());\n\n if (!optionValue || isWrongInputType) {\n exceptions.push(mandatoryOptionsWithExceptions[mandatoryOption]);\n }\n }\n if (exceptions.length) {\n exceptions.forEach((exeption) => exeption());\n process.exit(0); // eslint-disable-line\n }\n return <ValidatedTileConversionOptions>options;\n}\n\n/**\n * Parse option from the cli arguments array\n * @param args\n * @returns\n */\nfunction parseOptions(args: string[]): TileConversionOptions {\n const opts: TileConversionOptions = {\n output: 'data',\n sevenZipExe: 'C:\\\\Program Files\\\\7-Zip\\\\7z.exe',\n egm: join(process.cwd(), 'deps', 'egm2008-5.pgm'),\n draco: true,\n installDependencies: false,\n generateTextures: false,\n generateBoundingVolumes: false,\n validate: false,\n slpk: false\n };\n\n // eslint-disable-next-line complexity\n args.forEach((arg, index) => {\n if (arg.indexOf('--') === 0) {\n switch (arg) {\n case '--input-type':\n opts.inputType = getStringValue(index, args);\n break;\n case '--tileset':\n opts.tileset = getStringValue(index, args);\n break;\n case '--name':\n opts.name = getStringValue(index, args);\n break;\n case '--output':\n opts.output = getStringValue(index, args);\n break;\n case '--max-depth':\n opts.maxDepth = getIntegerValue(index, args);\n break;\n case '--slpk':\n opts.slpk = true;\n break;\n case '--7zExe':\n opts.sevenZipExe = getStringValue(index, args);\n break;\n case '--egm':\n opts.egm = getStringValue(index, args);\n break;\n case '--token':\n opts.token = getStringValue(index, args);\n break;\n case '--no-draco':\n opts.draco = false;\n break;\n case '--validate':\n opts.validate = true;\n break;\n case '--install-dependencies':\n opts.installDependencies = true;\n break;\n case '--generate-textures':\n opts.generateTextures = true;\n break;\n case '--generate-bounding-volumes':\n opts.generateBoundingVolumes = true;\n break;\n case '--help':\n printHelp();\n break;\n default:\n console.warn(`Unknown option ${arg}`);\n process.exit(0); // eslint-disable-line\n }\n }\n });\n return opts;\n}\n\n/**\n * Get string option value from cli arguments\n * @param index - option's name index in the argument's array.\n * The value of the option should be next to name of the option.\n * @param args - cli arguments array\n * @returns - string value of the option\n */\nfunction getStringValue(index: number, args: string[]): string {\n if (index + 1 >= args.length) {\n return '';\n }\n const value = args[index + 1];\n if (value.indexOf('--') === 0) {\n return '';\n }\n return value;\n}\n\n/**\n * Get integer option value from cli arguments\n * @param index - option's name index in the argument's array\n * The value of the option should be next to name of the option.\n * @param args - cli arguments array\n * @returns - number value of the option\n */\nfunction getIntegerValue(index: number, args: string[]): number {\n const stringValue: string = getStringValue(index, args);\n const result: number = Number.parseInt(stringValue);\n if (isFinite(result)) {\n return result;\n }\n return NaN;\n}\n"],"file":"converter-cli.js"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/deps-installer/deps-installer.js"],"names":["load","ZipLoader","writeFile","join","PGM_LINK","DepsInstaller","install","path","console","log","fileMap","depsPath","process","cwd","Uint8Array"],"mappings":"AAAA,SAAQA,IAAR,QAAmB,kBAAnB;AACA,SAAQC,SAAR,QAAwB,iBAAxB;AACA,SAAQC,SAAR,QAAwB,yBAAxB;AACA,SAAQC,IAAR,QAAmB,MAAnB;AAEA,MAAMC,QAAQ,GAAG,+EAAjB;AAEA,OAAO,MAAMC,aAAN,CAAoB;AACZ,QAAPC,OAAO,CAACC,IAAI,GAAG,EAAR,EAAY;AACvBC,IAAAA,OAAO,CAACC,GAAR,CAAY,iCAAZ;AACA,UAAMC,OAAO,GAAG,MAAMV,IAAI,CAACI,QAAD,EAAWH,SAAX,EAAsB,EAAtB,CAA1B;AAEA,QAAIU,QAAQ,GAAGC,OAAO,CAACC,GAAR,EAAf;;AACA,QAAIN,IAAJ,EAAU;AACRI,MAAAA,QAAQ,GAAGR,IAAI,CAACQ,QAAD,EAAWJ,IAAX,CAAf;AACD;;AAED,UAAML,SAAS,CAACS,QAAD,EAAW,IAAIG,UAAJ,CAAeJ,OAAO,CAAC,sBAAD,CAAtB,CAAX,EAA4D,eAA5D,CAAf;AAEAF,IAAAA,OAAO,CAACC,GAAR,CAAY,8CAAZ;AACD;;AAbwB","sourcesContent":["import {load} from '@loaders.gl/core';\nimport {ZipLoader} from '@loaders.gl/zip';\nimport {writeFile} from '../lib/utils/file-utils';\nimport {join} from 'path';\n\nconst PGM_LINK = 'https://raw.githubusercontent.com/visgl/deck.gl-data/master/egm/egm2008-5.zip';\n\nexport class DepsInstaller {\n async install(path = '') {\n console.log('Installing \"EGM2008-5\" model...'); // eslint-disable-line no-console\n const fileMap = await load(PGM_LINK, ZipLoader, {});\n\n let depsPath = process.cwd();\n if (path) {\n depsPath = join(depsPath, path);\n }\n\n await writeFile(depsPath, new Uint8Array(fileMap['geoids/egm2008-5.pgm']), 'egm2008-5.pgm');\n\n console.log('All dependencies were installed succesfully.'); // eslint-disable-line no-console\n }\n}\n"],"file":"deps-installer.js"}
1
+ {"version":3,"sources":["../../../src/deps-installer/deps-installer.ts"],"names":["load","ZipLoader","writeFile","join","PGM_LINK","DepsInstaller","install","path","console","log","fileMap","depsPath","process","cwd","Uint8Array"],"mappings":"AAAA,SAAQA,IAAR,QAAmB,kBAAnB;AACA,SAAQC,SAAR,QAAwB,iBAAxB;AACA,SAAQC,SAAR,QAAwB,yBAAxB;AACA,SAAQC,IAAR,QAAmB,MAAnB;AAEA,MAAMC,QAAQ,GAAG,+EAAjB;AAQA,OAAO,MAAMC,aAAN,CAAoB;AAKZ,QAAPC,OAAO,CAACC,IAAY,GAAG,EAAhB,EAAmC;AAC9CC,IAAAA,OAAO,CAACC,GAAR,CAAY,iCAAZ;AACA,UAAMC,OAAO,GAAG,MAAMV,IAAI,CAACI,QAAD,EAAWH,SAAX,EAAsB,EAAtB,CAA1B;AAEA,QAAIU,QAAQ,GAAGC,OAAO,CAACC,GAAR,EAAf;;AACA,QAAIN,IAAJ,EAAU;AACRI,MAAAA,QAAQ,GAAGR,IAAI,CAACQ,QAAD,EAAWJ,IAAX,CAAf;AACD;;AAED,UAAML,SAAS,CAACS,QAAD,EAAW,IAAIG,UAAJ,CAAeJ,OAAO,CAAC,sBAAD,CAAtB,CAAX,EAA4D,eAA5D,CAAf;AAEAF,IAAAA,OAAO,CAACC,GAAR,CAAY,8CAAZ;AACD;;AAjBwB","sourcesContent":["import {load} from '@loaders.gl/core';\nimport {ZipLoader} from '@loaders.gl/zip';\nimport {writeFile} from '../lib/utils/file-utils';\nimport {join} from 'path';\n\nconst PGM_LINK = 'https://raw.githubusercontent.com/visgl/deck.gl-data/master/egm/egm2008-5.zip';\n\n/**\n * Install external dependencies for converter:\n * * PGM file (implemented);\n * * Draco library (not implemented);\n * * 7z archiver (not implemented);\n */\nexport class DepsInstaller {\n /**\n * Run instalation\n * @param path destination folder\n */\n async install(path: string = ''): Promise<void> {\n console.log('Installing \"EGM2008-5\" model...'); // eslint-disable-line no-console\n const fileMap = await load(PGM_LINK, ZipLoader, {});\n\n let depsPath = process.cwd();\n if (path) {\n depsPath = join(depsPath, path);\n }\n\n await writeFile(depsPath, new Uint8Array(fileMap['geoids/egm2008-5.pgm']), 'egm2008-5.pgm');\n\n console.log('All dependencies were installed succesfully.'); // eslint-disable-line no-console\n }\n}\n"],"file":"deps-installer.js"}
@@ -0,0 +1,16 @@
1
+ import { processOnWorker } from '@loaders.gl/worker-utils';
2
+ const VERSION = typeof "3.2.0-alpha.3" !== 'undefined' ? "3.2.0-alpha.3" : 'latest';
3
+ export const I3SAttributesWorker = {
4
+ id: 'i3s-attributes',
5
+ name: 'I3S Attributes Worker',
6
+ module: 'tile-converter',
7
+ version: VERSION,
8
+ options: {
9
+ useCartesianPositions: false
10
+ }
11
+ };
12
+ export function transformI3SAttributesOnWorker(attributesData, options) {
13
+ return processOnWorker(I3SAttributesWorker, attributesData, options);
14
+ }
15
+ export const _typecheckI3SAttributesWorker = I3SAttributesWorker;
16
+ //# sourceMappingURL=i3s-attributes-worker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/i3s-attributes-worker.ts"],"names":["processOnWorker","VERSION","I3SAttributesWorker","id","name","module","version","options","useCartesianPositions","transformI3SAttributesOnWorker","attributesData","_typecheckI3SAttributesWorker"],"mappings":"AAIA,SAAQA,eAAR,QAA8B,0BAA9B;AAIA,MAAMC,OAAO,GAAG,2BAAuB,WAAvB,qBAAmD,QAAnE;AAiBA,OAAO,MAAMC,mBAAmB,GAAG;AACjCC,EAAAA,EAAE,EAAE,gBAD6B;AAEjCC,EAAAA,IAAI,EAAE,uBAF2B;AAGjCC,EAAAA,MAAM,EAAE,gBAHyB;AAIjCC,EAAAA,OAAO,EAAEL,OAJwB;AAKjCM,EAAAA,OAAO,EAAE;AACPC,IAAAA,qBAAqB,EAAE;AADhB;AALwB,CAA5B;AAaP,OAAO,SAASC,8BAAT,CACLC,cADK,EAELH,OAFK,EAGsC;AAC3C,SAAOP,eAAe,CAACE,mBAAD,EAAsBQ,cAAtB,EAAsCH,OAAtC,CAAtB;AACD;AAED,OAAO,MAAMI,6BAA2C,GAAGT,mBAApD","sourcesContent":["import type {WorkerObject} from '@loaders.gl/worker-utils';\nimport type {ConvertedAttributes} from './i3s-converter/types';\nimport type {Matrix4, Vector3} from '@math.gl/core';\n\nimport {processOnWorker} from '@loaders.gl/worker-utils';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\nexport type I3SAttributesWorkerOptions = {\n useCartesianPositions: boolean;\n source: string;\n};\n\nexport type B3DMAttributesData = {\n gltfMaterials?: {id: string}[];\n nodes: any;\n cartographicOrigin: Vector3;\n cartesianModelMatrix: Matrix4;\n};\n\n/**\n * I3S Attributes Worker to handle B3DM object\n */\nexport const I3SAttributesWorker = {\n id: 'i3s-attributes',\n name: 'I3S Attributes Worker',\n module: 'tile-converter',\n version: VERSION,\n options: {\n useCartesianPositions: false\n }\n};\n\n/**\n * Performs I3S attributes transformation\n */\nexport function transformI3SAttributesOnWorker(\n attributesData: B3DMAttributesData,\n options: I3SAttributesWorkerOptions\n): Promise<Map<string, ConvertedAttributes>> {\n return processOnWorker(I3SAttributesWorker, attributesData, options);\n}\n\nexport const _typecheckI3SAttributesWorker: WorkerObject = I3SAttributesWorker;\n"],"file":"i3s-attributes-worker.js"}
@@ -1,6 +1,6 @@
1
1
  import { Matrix3, Quaternion, Vector3 } from '@math.gl/core';
2
2
  import { Ellipsoid } from '@math.gl/geospatial';
3
- import { OrientedBoundingBox, makeOrientedBoundingBoxFromPoints, makeBoundingSphereFromPoints } from '@math.gl/culling';
3
+ import { OrientedBoundingBox, makeOrientedBoundingBoxFromPoints, makeBoundingSphereFromPoints, BoundingSphere } from '@math.gl/culling';
4
4
  export function createBoundingVolumes(tile, geoidHeightModel) {
5
5
  let radius;
6
6
  let halfSize;
@@ -55,19 +55,27 @@ export function convertPositionsToVectors(positions) {
55
55
 
56
56
  return result;
57
57
  }
58
- export function convertCommonToI3SExtentCoordinate(tileset) {
59
- const cartesianCenter = tileset === null || tileset === void 0 ? void 0 : tileset.cartesianCenter;
58
+ export function convertBoundingVolumeToI3SFullExtent(boundingVolume) {
59
+ let sphere;
60
60
 
61
- if (!cartesianCenter) {
62
- return null;
61
+ if (boundingVolume instanceof BoundingSphere) {
62
+ sphere = boundingVolume;
63
+ } else {
64
+ sphere = boundingVolume.getBoundingSphere();
63
65
  }
64
66
 
65
- const radius = tileset === null || tileset === void 0 ? void 0 : tileset.lodMetricValue;
66
- const rightTop = Ellipsoid.WGS84.cartesianToCartographic(new Vector3(cartesianCenter[0] + radius, cartesianCenter[1] + radius, cartesianCenter[2]), new Vector3());
67
- const leftBottom = Ellipsoid.WGS84.cartesianToCartographic(new Vector3(cartesianCenter[0] - radius, cartesianCenter[1] - radius, cartesianCenter[2]), new Vector3());
68
- const isFirstRight = rightTop[0] < leftBottom[0];
69
- const isFirstTop = rightTop[1] < leftBottom[1];
70
- return [isFirstRight ? rightTop[0] : leftBottom[0], isFirstTop ? rightTop[1] : leftBottom[1], isFirstRight ? leftBottom[0] : rightTop[0], isFirstTop ? leftBottom[1] : rightTop[1]];
67
+ const center = sphere.center;
68
+ const radius = sphere.radius;
69
+ const vertexMax = Ellipsoid.WGS84.cartesianToCartographic(new Vector3(center[0] + radius, center[1] + radius, center[2] + radius), new Vector3());
70
+ const vertexMin = Ellipsoid.WGS84.cartesianToCartographic(new Vector3(center[0] - radius, center[1] - radius, center[2] - radius), new Vector3());
71
+ return {
72
+ xmin: vertexMin[0],
73
+ xmax: vertexMax[0],
74
+ ymin: vertexMin[1],
75
+ ymax: vertexMax[1],
76
+ zmin: vertexMin[2],
77
+ zmax: vertexMax[2]
78
+ };
71
79
  }
72
80
  export function createObbFromMbs(mbs) {
73
81
  const radius = mbs[3];
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/i3s-converter/helpers/coordinate-converter.ts"],"names":["Matrix3","Quaternion","Vector3","Ellipsoid","OrientedBoundingBox","makeOrientedBoundingBoxFromPoints","makeBoundingSphereFromPoints","createBoundingVolumes","tile","geoidHeightModel","radius","halfSize","quaternion","boundingVolume","cartographicCenter","WGS84","cartesianToCartographic","center","getHeight","len","fromMatrix3","normalize","mbs","obb","createBoundingVolumesFromGeometry","cartesianPositions","positionVectors","convertPositionsToVectors","geometryObb","geometryMbs","mbsCenter","obbCenter","positions","result","i","length","positionVector","push","convertCommonToI3SExtentCoordinate","tileset","cartesianCenter","lodMetricValue","rightTop","leftBottom","isFirstRight","isFirstTop","createObbFromMbs","halfAxex"],"mappings":"AAEA,SAAQA,OAAR,EAAiBC,UAAjB,EAA6BC,OAA7B,QAA2C,eAA3C;AACA,SAAQC,SAAR,QAAwB,qBAAxB;AACA,SACEC,mBADF,EAEEC,iCAFF,EAGEC,4BAHF,QAIO,kBAJP;AAeA,OAAO,SAASC,qBAAT,CAA+BC,IAA/B,EAAiDC,gBAAjD,EAA2F;AAChG,MAAIC,MAAJ;AACA,MAAIC,QAAJ;AACA,MAAIC,UAAJ;AAEA,QAAMC,cAAc,GAAGL,IAAI,CAACK,cAA5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/core';\nimport {Ellipsoid} from '@math.gl/geospatial';\nimport {\n OrientedBoundingBox,\n makeOrientedBoundingBoxFromPoints,\n makeBoundingSphereFromPoints\n} from '@math.gl/culling';\nimport TileHeader from '@loaders.gl/tiles/src/tileset/tile-3d';\nimport {Geoid} from '@math.gl/geoid';\nimport {Tileset3D} from '@loaders.gl/tiles';\n\n/**\n * Create bounding volumes object from tile and geoid height model.\n * @param tile\n * @param geoidHeightModel\n * @returns - Bounding volumes object\n */\nexport function createBoundingVolumes(tile: TileHeader, geoidHeightModel: Geoid): BoundingVolumes {\n let radius;\n let halfSize;\n let quaternion;\n\n const boundingVolume = tile.boundingVolume;\n const cartographicCenter = Ellipsoid.WGS84.cartesianToCartographic(\n boundingVolume.center,\n new Vector3()\n );\n cartographicCenter[2] =\n cartographicCenter[2] -\n geoidHeightModel.getHeight(cartographicCenter[1], cartographicCenter[0]);\n if (boundingVolume instanceof OrientedBoundingBox) {\n halfSize = boundingVolume.halfSize;\n radius = new Vector3(halfSize[0], halfSize[1], halfSize[2]).len();\n quaternion = boundingVolume.quaternion;\n } else {\n radius = tile.boundingVolume.radius;\n halfSize = [radius, radius, radius];\n quaternion = new Quaternion()\n .fromMatrix3(new Matrix3([halfSize[0], 0, 0, 0, halfSize[1], 0, 0, 0, halfSize[2]]))\n .normalize();\n }\n\n return {\n mbs: [cartographicCenter[0], cartographicCenter[1], cartographicCenter[2], radius],\n obb: {\n center: [cartographicCenter[0], cartographicCenter[1], cartographicCenter[2]],\n halfSize,\n quaternion\n }\n };\n}\n\n/**\n * Generates bounding volumes from geometry positions\n * @param cartesianPositions\n * @param geoidHeightModel\n */\nexport function createBoundingVolumesFromGeometry(\n cartesianPositions: Float32Array,\n geoidHeightModel: Geoid\n): {mbs: Mbs; obb: Obb} {\n const positionVectors = convertPositionsToVectors(cartesianPositions);\n\n const geometryObb = makeOrientedBoundingBoxFromPoints(positionVectors);\n const geometryMbs = makeBoundingSphereFromPoints(positionVectors);\n\n let mbsCenter = Ellipsoid.WGS84.cartesianToCartographic(geometryMbs.center, new Vector3());\n let obbCenter = Ellipsoid.WGS84.cartesianToCartographic(geometryObb.center, new Vector3());\n\n mbsCenter[2] = mbsCenter[2] - geoidHeightModel.getHeight(mbsCenter[1], mbsCenter[0]);\n obbCenter[2] = obbCenter[2] - geoidHeightModel.getHeight(obbCenter[1], obbCenter[0]);\n\n return {\n mbs: [mbsCenter[0], mbsCenter[1], mbsCenter[2], geometryMbs.radius],\n obb: {\n center: obbCenter,\n halfSize: geometryObb.halfSize,\n quaternion: geometryObb.quaternion\n }\n };\n}\n\n/**\n * Create array of posisitons where each vertex is vector\n * @param {array} positions\n * @returns {Vector3[]}\n */\nexport function convertPositionsToVectors(positions: Float32Array): Vector3[] {\n const result: Vector3[] = [];\n\n for (let i = 0; i < positions.length; i += 3) {\n // TODO: (perf) new Vector3 is not optimal but required in `makeOrientedBoundingBoxFromPoints`.\n // modify `makeOrientedBoundingBoxFromPoints` to use scratch vectors\n const positionVector = new Vector3([positions[i], positions[i + 1], positions[i + 2]]);\n result.push(positionVector);\n }\n\n return result;\n}\n\n/**\n * Convert common coordinate to extent coordinate\n * @param tileset\n * @returns - Extent\n * @todo why lodMetricValue is radius? need to check this function\n */\nexport function convertCommonToI3SExtentCoordinate(tileset: Tileset3D | null): Extent | null {\n const cartesianCenter = tileset?.cartesianCenter;\n if (!cartesianCenter) {\n return null;\n }\n const radius = tileset?.lodMetricValue;\n const rightTop = Ellipsoid.WGS84.cartesianToCartographic(\n new Vector3(cartesianCenter[0] + radius, cartesianCenter[1] + radius, cartesianCenter[2]),\n new Vector3()\n );\n const leftBottom = Ellipsoid.WGS84.cartesianToCartographic(\n new Vector3(cartesianCenter[0] - radius, cartesianCenter[1] - radius, cartesianCenter[2]),\n new Vector3()\n );\n const isFirstRight = rightTop[0] < leftBottom[0];\n const isFirstTop = rightTop[1] < leftBottom[1];\n\n return [\n isFirstRight ? rightTop[0] : leftBottom[0],\n isFirstTop ? rightTop[1] : leftBottom[1],\n isFirstRight ? leftBottom[0] : rightTop[0],\n isFirstTop ? leftBottom[1] : rightTop[1]\n ];\n}\n\n/**\n * Creates oriented boundinb box from mbs.\n * @param mbs - Minimum Bounding Sphere\n * @returns - Oriented BOunding Box\n */\nexport function createObbFromMbs(mbs: Mbs): Obb {\n const radius = mbs[3];\n const center = new Vector3(mbs[0], mbs[1], mbs[2]);\n const halfAxex = new Matrix3([radius, 0, 0, 0, radius, 0, 0, 0, radius]);\n return new OrientedBoundingBox(center, halfAxex);\n}\n"],"file":"coordinate-converter.js"}
1
+ {"version":3,"sources":["../../../../src/i3s-converter/helpers/coordinate-converter.ts"],"names":["Matrix3","Quaternion","Vector3","Ellipsoid","OrientedBoundingBox","makeOrientedBoundingBoxFromPoints","makeBoundingSphereFromPoints","BoundingSphere","createBoundingVolumes","tile","geoidHeightModel","radius","halfSize","quaternion","boundingVolume","cartographicCenter","WGS84","cartesianToCartographic","center","getHeight","len","fromMatrix3","normalize","mbs","obb","createBoundingVolumesFromGeometry","cartesianPositions","positionVectors","convertPositionsToVectors","geometryObb","geometryMbs","mbsCenter","obbCenter","positions","result","i","length","positionVector","push","convertBoundingVolumeToI3SFullExtent","sphere","getBoundingSphere","vertexMax","vertexMin","xmin","xmax","ymin","ymax","zmin","zmax","createObbFromMbs","halfAxex"],"mappings":"AAEA,SAAQA,OAAR,EAAiBC,UAAjB,EAA6BC,OAA7B,QAA2C,eAA3C;AACA,SAAQC,SAAR,QAAwB,qBAAxB;AACA,SACEC,mBADF,EAEEC,iCAFF,EAGEC,4BAHF,EAIEC,cAJF,QAKO,kBALP;AAeA,OAAO,SAASC,qBAAT,CAA+BC,IAA/B,EAAiDC,gBAAjD,EAA2F;AAChG,MAAIC,MAAJ;AACA,MAAIC,QAAJ;AACA,MAAIC,UAAJ;AAEA,QAAMC,cAAc,GAAGL,IAAI,CAACK,cAA5B;AACA,QAAMC,kBAAkB,GAAGZ,SAAS,CAACa,KAAV,CAAgBC,uBAAhB,CACzBH,cAAc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P,MAAxB,EAAgCO,MAAM,CAAC,CAAD,CAAN,GAAYP,MAA5C,EAAoDO,MAAM,CAAC,CAAD,CAAN,GAAYP,MAAhE,CADgB,EAEhB,IAAIT,OAAJ,EAFgB,CAAlB;AAKA,SAAO;AACL0C,IAAAA,IAAI,EAAED,SAAS,CAAC,CAAD,CADV;AAELE,IAAAA,IAAI,EAAEH,SAAS,CAAC,CAAD,CAFV;AAGLI,IAAAA,IAAI,EAAEH,SAAS,CAAC,CAAD,CAHV;AAILI,IAAAA,IAAI,EAAEL,SAAS,CAAC,CAAD,CAJV;AAKLM,IAAAA,IAAI,EAAEL,SAAS,CAAC,CAAD,CALV;AAMLM,IAAAA,IAAI,EAAEP,SAAS,CAAC,CAAD;AANV,GAAP;AAQD;AAOD,OAAO,SAASQ,gBAAT,CAA0B3B,GAA1B,EAAyC;AAC9C,QAAMZ,MAAM,GAAGY,GAAG,CAAC,CAAD,CAAlB;AACA,QAAML,MAAM,GAAG,IAAIhB,OAAJ,CAAYqB,GAAG,CAAC,CAAD,CAAf,EAAoBA,GAAG,CAAC,CAAD,CAAvB,EAA4BA,GAAG,CAAC,CAAD,CAA/B,CAAf;AACA,QAAM4B,QAAQ,GAAG,IAAInD,OAAJ,CAAY,CAACW,MAAD,EAAS,CAAT,EAAY,CAAZ,EAAe,CAAf,EAAkBA,MAAlB,EAA0B,CAA1B,EAA6B,CAA7B,EAAgC,CAAhC,EAAmCA,MAAnC,CAAZ,CAAjB;AACA,SAAO,IAAIP,mBAAJ,CAAwBc,MAAxB,EAAgCiC,QAAhC,CAAP;AACD","sourcesContent":["import type {BoundingVolumes, FullExtent, Mbs, Obb} from '@loaders.gl/i3s';\n\nimport {Matrix3, Quaternion, Vector3} from '@math.gl/core';\nimport {Ellipsoid} from '@math.gl/geospatial';\nimport {\n OrientedBoundingBox,\n makeOrientedBoundingBoxFromPoints,\n makeBoundingSphereFromPoints,\n BoundingSphere\n} from '@math.gl/culling';\nimport TileHeader from '@loaders.gl/tiles/src/tileset/tile-3d';\nimport {Geoid} from '@math.gl/geoid';\n\n/**\n * Create bounding volumes object from tile and geoid height model.\n * @param tile\n * @param geoidHeightModel\n * @returns - Bounding volumes object\n */\nexport function createBoundingVolumes(tile: TileHeader, geoidHeightModel: Geoid): BoundingVolumes {\n let radius;\n let halfSize;\n let quaternion;\n\n const boundingVolume = tile.boundingVolume;\n const cartographicCenter = Ellipsoid.WGS84.cartesianToCartographic(\n boundingVolume.center,\n new Vector3()\n );\n cartographicCenter[2] =\n cartographicCenter[2] -\n geoidHeightModel.getHeight(cartographicCenter[1], cartographicCenter[0]);\n if (boundingVolume instanceof OrientedBoundingBox) {\n halfSize = boundingVolume.halfSize;\n radius = new Vector3(halfSize[0], halfSize[1], halfSize[2]).len();\n quaternion = boundingVolume.quaternion;\n } else {\n radius = tile.boundingVolume.radius;\n halfSize = [radius, radius, radius];\n quaternion = new Quaternion()\n .fromMatrix3(new Matrix3([halfSize[0], 0, 0, 0, halfSize[1], 0, 0, 0, halfSize[2]]))\n .normalize();\n }\n\n return {\n mbs: [cartographicCenter[0], cartographicCenter[1], cartographicCenter[2], radius],\n obb: {\n center: [cartographicCenter[0], cartographicCenter[1], cartographicCenter[2]],\n halfSize,\n quaternion\n }\n };\n}\n\n/**\n * Generates bounding volumes from geometry positions\n * @param cartesianPositions\n * @param geoidHeightModel\n */\nexport function createBoundingVolumesFromGeometry(\n cartesianPositions: Float32Array,\n geoidHeightModel: Geoid\n): {mbs: Mbs; obb: Obb} {\n const positionVectors = convertPositionsToVectors(cartesianPositions);\n\n const geometryObb = makeOrientedBoundingBoxFromPoints(positionVectors);\n const geometryMbs = makeBoundingSphereFromPoints(positionVectors);\n\n let mbsCenter = Ellipsoid.WGS84.cartesianToCartographic(geometryMbs.center, new Vector3());\n let obbCenter = Ellipsoid.WGS84.cartesianToCartographic(geometryObb.center, new Vector3());\n\n mbsCenter[2] = mbsCenter[2] - geoidHeightModel.getHeight(mbsCenter[1], mbsCenter[0]);\n obbCenter[2] = obbCenter[2] - geoidHeightModel.getHeight(obbCenter[1], obbCenter[0]);\n\n return {\n mbs: [mbsCenter[0], mbsCenter[1], mbsCenter[2], geometryMbs.radius],\n obb: {\n center: obbCenter,\n halfSize: geometryObb.halfSize,\n quaternion: geometryObb.quaternion\n }\n };\n}\n\n/**\n * Create array of posisitons where each vertex is vector\n * @param {array} positions\n * @returns {Vector3[]}\n */\nexport function convertPositionsToVectors(positions: Float32Array): Vector3[] {\n const result: Vector3[] = [];\n\n for (let i = 0; i < positions.length; i += 3) {\n // TODO: (perf) new Vector3 is not optimal but required in `makeOrientedBoundingBoxFromPoints`.\n // modify `makeOrientedBoundingBoxFromPoints` to use scratch vectors\n const positionVector = new Vector3([positions[i], positions[i + 1], positions[i + 2]]);\n result.push(positionVector);\n }\n\n return result;\n}\n\n/**\n * Convert common coordinate to fullExtent https://github.com/Esri/i3s-spec/blob/master/docs/1.8/fullExtent.cmn.md\n * @param\n * @param boundingVolume\n * @returns - fullExtent object\n */\nexport function convertBoundingVolumeToI3SFullExtent(\n boundingVolume: OrientedBoundingBox | BoundingSphere\n): FullExtent {\n let sphere: BoundingSphere;\n if (boundingVolume instanceof BoundingSphere) {\n sphere = boundingVolume;\n } else {\n sphere = boundingVolume.getBoundingSphere();\n }\n const center: Vector3 = sphere.center;\n const radius: number = sphere.radius;\n const vertexMax = Ellipsoid.WGS84.cartesianToCartographic(\n new Vector3(center[0] + radius, center[1] + radius, center[2] + radius),\n new Vector3()\n );\n const vertexMin = Ellipsoid.WGS84.cartesianToCartographic(\n new Vector3(center[0] - radius, center[1] - radius, center[2] - radius),\n new Vector3()\n );\n\n return {\n xmin: vertexMin[0],\n xmax: vertexMax[0],\n ymin: vertexMin[1],\n ymax: vertexMax[1],\n zmin: vertexMin[2],\n zmax: vertexMax[2]\n };\n}\n\n/**\n * Creates oriented boundinb box from mbs.\n * @param mbs - Minimum Bounding Sphere\n * @returns - Oriented BOunding Box\n */\nexport function createObbFromMbs(mbs: Mbs): Obb {\n const radius = mbs[3];\n const center = new Vector3(mbs[0], mbs[1], mbs[2]);\n const halfAxex = new Matrix3([radius, 0, 0, 0, radius, 0, 0, 0, radius]);\n return new OrientedBoundingBox(center, halfAxex);\n}\n"],"file":"coordinate-converter.js"}
@@ -7,9 +7,9 @@ export function generateAttributes(attributes) {
7
7
  normals,
8
8
  texCoords,
9
9
  colors,
10
- featureIndices,
11
- triangleCount
10
+ featureIndices
12
11
  } = attributes;
12
+ const triangleCount = positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE;
13
13
 
14
14
  if (!featureIndices.length) {
15
15
  return {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/i3s-converter/helpers/geometry-attributes.ts"],"names":["concatenateTypedArrays","VALUES_PER_VERTEX","POSITIONS_AND_NORMALS_PER_TRIANGLE","generateAttributes","attributes","positions","normals","texCoords","colors","featureIndices","triangleCount","length","faceRange","Uint32Array","featureIds","featureCount","data","calculateFaceRangesAndFeaturesCount","attributeObjects","makeAttributeObjects","unifiedAttributeObjectsByFeatureIds","unifyObjectsByFeatureId","groupedAttributes","groupAttributesAndRangesByFeatureId","rangeIndex","featureIndex","currentFeatureId","faceRangeList","uniqueFeatureIds","index","includes","push","groupedData","positionsList","Float32Array","normalsList","colorsList","Uint8Array","texCoordsList","faceRangeIndex","startIndex","endIndex","positionsCount","getSliceAttributeCount","normalsCount","colorsCount","texCoordsCount","featureId","slice","sort","first","second","attributeName","colorsPerVertex","texCoordsPerVertex","trianglesCount","vertexCount","sortedData","uniqueObjects","currentObject","existedObject","find","obj","unifiedObjects","firstAttributeObject","range","objIndex","sum","currentAttributesObject","groupedObject"],"mappings":"AACA,SAAQA,sBAAR,QAAqC,0BAArC;AAEA,MAAMC,iBAAiB,GAAG,CAA1B;AACA,MAAMC,kCAAkC,GAAG,CAA3C;AAOA,OAAO,SAASC,kBAAT,CAA4BC,UAA5B,EAA4E;AACjF,QAAM;AAACC,IAAAA,SAAD;AAAYC,IAAAA,OAAZ;AAAqBC,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AxB;AAAmCC,IAAAA,OAAnC;AAA4CE,IAAAA,MAA5C;AAAoDD,IAAAA,SAApD;AAA+DQ,IAAAA;AAA/D,GAAP;AACD","sourcesContent":["import type {GeometryAttributes, AttributesData, GroupedByFeatureIdAttributes} from '../types';\nimport {concatenateTypedArrays} from '@loaders.gl/loader-utils';\n\nconst VALUES_PER_VERTEX = 3;\nconst POSITIONS_AND_NORMALS_PER_TRIANGLE = 9;\n\n/**\n * Generate geometry attributes with faceRange and featureCount\n * @param attributes\n * @returns attirbutes with featureCount, featureIds and changed faceRange.\n */\nexport function generateAttributes(attributes: AttributesData): GeometryAttributes {\n const {positions, normals, texCoords, colors, featureIndices, triangleCount} = attributes;\n\n if (!featureIndices.length) {\n return {\n faceRange: new Uint32Array([0, triangleCount - 1]),\n featureIds: [0],\n featureCount: 1,\n positions,\n normals,\n texCoords,\n colors\n };\n }\n\n const data = calculateFaceRangesAndFeaturesCount(featureIndices);\n const attributeObjects = makeAttributeObjects({...data, ...attributes});\n const unifiedAttributeObjectsByFeatureIds = unifyObjectsByFeatureId(attributeObjects);\n const groupedAttributes = groupAttributesAndRangesByFeatureId(\n unifiedAttributeObjectsByFeatureIds,\n data.featureCount\n );\n return groupedAttributes;\n}\n\n/**\n * Calculates face Ranges and feature count based on featureIndices.\n * @param featureIndices\n * @returns Object with featureCount, reordered attributes and changed faceRange.\n */\nfunction calculateFaceRangesAndFeaturesCount(featureIndices: number[]): {\n faceRange: Uint32Array;\n featureCount: number;\n featureIds: number[];\n} {\n let rangeIndex = 1;\n let featureIndex = 1;\n let currentFeatureId = featureIndices[0];\n const faceRangeList: any[] = [];\n const featureIds: any[] = [];\n const uniqueFeatureIds = [currentFeatureId];\n\n faceRangeList[0] = 0;\n featureIds[0] = currentFeatureId;\n\n for (let index = 1; index < featureIndices.length; index++) {\n if (currentFeatureId !== featureIndices[index]) {\n faceRangeList[rangeIndex] = index / VALUES_PER_VERTEX - 1;\n faceRangeList[rangeIndex + 1] = index / VALUES_PER_VERTEX;\n featureIds[featureIndex] = featureIndices[index];\n\n if (!uniqueFeatureIds.includes(featureIndices[index])) {\n uniqueFeatureIds.push(featureIndices[index]);\n }\n\n rangeIndex += 2;\n featureIndex += 1;\n }\n currentFeatureId = featureIndices[index];\n }\n\n faceRangeList[rangeIndex] = featureIndices.length / VALUES_PER_VERTEX - 1;\n\n const faceRange = new Uint32Array(faceRangeList);\n const featureCount = uniqueFeatureIds.length;\n\n return {faceRange, featureCount, featureIds};\n}\n\n/**\n * Generate list of attribute object grouped by feature ids.\n * @param attributes\n * @returns sorted list of attribute objects.\n */\nfunction makeAttributeObjects(attributes: GeometryAttributes): GroupedByFeatureIdAttributes[] {\n const {\n featureIds,\n positions,\n normals,\n colors,\n texCoords,\n faceRange = new Uint32Array(0)\n } = attributes;\n const groupedData: GroupedByFeatureIdAttributes[] = [];\n\n let positionsList = new Float32Array(positions);\n let normalsList = new Float32Array(normals);\n let colorsList = new Uint8Array(colors);\n let texCoordsList = new Float32Array(texCoords);\n\n let faceRangeIndex = 0;\n\n for (let index = 0; index < featureIds.length; index++) {\n const startIndex = faceRange[index + faceRangeIndex];\n const endIndex = faceRange[index + faceRangeIndex + 1];\n\n const positionsCount = getSliceAttributeCount('positions', startIndex, endIndex);\n const normalsCount = getSliceAttributeCount('normals', startIndex, endIndex);\n const colorsCount = getSliceAttributeCount('colors', startIndex, endIndex);\n const texCoordsCount = getSliceAttributeCount('texCoords', startIndex, endIndex);\n\n groupedData.push({\n featureId: featureIds[index],\n positions: positionsList.slice(0, positionsCount),\n normals: normalsList.slice(0, normalsCount),\n colors: colorsList.slice(0, colorsCount),\n texCoords: texCoordsList.slice(0, texCoordsCount)\n });\n\n positionsList = positionsList.slice(positionsCount);\n normalsList = normalsList.slice(normalsCount);\n colorsList = colorsList.slice(colorsCount);\n texCoordsList = texCoordsList.slice(texCoordsCount);\n\n faceRangeIndex += 1;\n }\n\n return groupedData.sort((first, second) => first.featureId - second.featureId);\n}\n\n/**\n * Generate sliced count for generating attribute objects depends on attribute name and range.\n * @param attributeName\n * @param startIndex\n * @param endIndex\n * @returns sliced count\n */\nfunction getSliceAttributeCount(\n attributeName: string,\n startIndex: number,\n endIndex: number\n): number {\n const colorsPerVertex = 4;\n const texCoordsPerVertex = 2;\n\n const trianglesCount = endIndex - startIndex + 1;\n const vertexCount = trianglesCount * 3;\n\n switch (attributeName) {\n case 'positions':\n case 'normals':\n return trianglesCount * POSITIONS_AND_NORMALS_PER_TRIANGLE;\n case 'colors':\n return vertexCount * colorsPerVertex;\n case 'texCoords':\n return vertexCount * texCoordsPerVertex;\n default:\n return 0;\n }\n}\n\n/**\n * Generates unique object list depends on feature ids and concantenate their attributes.\n * @param sortedData\n * @returns unique list of objects\n */\nfunction unifyObjectsByFeatureId(\n sortedData: GroupedByFeatureIdAttributes[]\n): GroupedByFeatureIdAttributes[] {\n const uniqueObjects: GroupedByFeatureIdAttributes[] = [];\n\n for (let index = 0; index < sortedData.length; index++) {\n const currentObject = sortedData[index];\n const existedObject = uniqueObjects.find((obj) => obj.featureId === currentObject.featureId);\n\n if (existedObject) {\n existedObject.positions = concatenateTypedArrays(\n existedObject.positions,\n currentObject.positions\n );\n existedObject.normals = concatenateTypedArrays(existedObject.normals, currentObject.normals);\n existedObject.colors = concatenateTypedArrays(existedObject.colors, currentObject.colors);\n existedObject.texCoords = concatenateTypedArrays(\n existedObject.texCoords,\n currentObject.texCoords\n );\n } else {\n uniqueObjects.push(currentObject);\n }\n }\n\n return uniqueObjects;\n}\n\n/**\n * Generates attribute objects with new faceRange and reordered attributes.\n * @param unifiedObjects\n * @returns generated attributes with new faceRange.\n */\nfunction groupAttributesAndRangesByFeatureId(\n unifiedObjects: GroupedByFeatureIdAttributes[],\n featureCount: number\n): GeometryAttributes {\n const firstAttributeObject = unifiedObjects[0];\n const featureIds = [firstAttributeObject.featureId || 0];\n\n let positions = new Float32Array(firstAttributeObject.positions);\n let normals = new Float32Array(firstAttributeObject.normals);\n let colors = new Uint8Array(firstAttributeObject.colors);\n let texCoords = new Float32Array(firstAttributeObject.texCoords);\n const range = [0];\n\n let objIndex = 0;\n let sum = 0;\n\n for (let index = 1; index < unifiedObjects.length; index++) {\n const currentAttributesObject = unifiedObjects[index];\n featureIds.push(currentAttributesObject.featureId || 0);\n\n positions = concatenateTypedArrays(positions, currentAttributesObject.positions);\n normals = concatenateTypedArrays(normals, currentAttributesObject.normals);\n colors = concatenateTypedArrays(colors, currentAttributesObject.colors);\n texCoords = concatenateTypedArrays(texCoords, currentAttributesObject.texCoords);\n\n const groupedObject = unifiedObjects[objIndex];\n range.push(groupedObject.positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE - 1 + sum);\n range.push(groupedObject.positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE + sum);\n\n sum += groupedObject.positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE;\n objIndex += 1;\n }\n\n range.push(positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE - 1);\n\n const faceRange = new Uint32Array(range);\n return {faceRange, featureIds, positions, normals, colors, texCoords, featureCount};\n}\n"],"file":"geometry-attributes.js"}
1
+ {"version":3,"sources":["../../../../src/i3s-converter/helpers/geometry-attributes.ts"],"names":["concatenateTypedArrays","VALUES_PER_VERTEX","POSITIONS_AND_NORMALS_PER_TRIANGLE","generateAttributes","attributes","positions","normals","texCoords","colors","featureIndices","triangleCount","length","faceRange","Uint32Array","featureIds","featureCount","data","calculateFaceRangesAndFeaturesCount","attributeObjects","makeAttributeObjects","unifiedAttributeObjectsByFeatureIds","unifyObjectsByFeatureId","groupedAttributes","groupAttributesAndRangesByFeatureId","rangeIndex","featureIndex","currentFeatureId","faceRangeList","uniqueFeatureIds","index","includes","push","groupedData","positionsList","Float32Array","normalsList","colorsList","Uint8Array","texCoordsList","faceRangeIndex","startIndex","endIndex","positionsCount","getSliceAttributeCount","normalsCount","colorsCount","texCoordsCount","featureId","slice","sort","first","second","attributeName","colorsPerVertex","texCoordsPerVertex","trianglesCount","vertexCount","sortedData","uniqueObjects","currentObject","existedObject","find","obj","unifiedObjects","firstAttributeObject","range","objIndex","sum","currentAttributesObject","groupedObject"],"mappings":"AACA,SAAQA,sBAAR,QAAqC,0BAArC;AAEA,MAAMC,iBAAiB,GAAG,CAA1B;AACA,MAAMC,kCAAkC,GAAG,CAA3C;AAOA,OAAO,SAASC,kBAAT,CAA4BC,UAA5B,EAAiF;AACtF,QAAM;AAACC,IAAAA,SAAD;AAAYC,IAAAA,OAAZ;AAAqBC,IAAAA,SAArB;AAAgCC,IAAAA,MAAhC;AAAwCC,IAAAA;AAAxC,MAA0DL,UAAhE;AACA,QAAMM,aAAa,GAAGL,SAAS,CAACM,MAAV,GAAmBT,kCAAzC;;AAEA,MAAI,CAACO,cAAc,CAACE,MAApB,EAA4B;AAC1B,WAAO;AACLC,MAAAA,SAAS,EAAE,IAAIC,WAAJ,CAAgB,CAAC,CAAD,EAAIH,aAAa,GAAG,CAApB,CAAhB,CADN;AAELI,MAAAA,UAAU,EAAE,CAAC,CAAD,CAFP;AAGLC,MAAAA,YAAY,EAAE,CAHT;AAILV,MAAAA,SAJK;AAKLC,MAAAA,OALK;AAMLC,MAAAA,SANK;AAOLC,MAAAA;AAPK,KAAP;AASD;;AAED,QAAMQ,IAAI,GAAGC,mCAAmC,CAACR,cAAD,CAAhD;AACA,QAAMS,gBAAgB,GAAGC,oBAAoB,CAAC,EAAC,GAAGH,IAAJ;AAAU,OAAGZ;AAAb,GAAD,CAA7C;AACA,QAAMgB,mCAAmC,GAAGC,uBAAuB,CAACH,gBAAD,CAAnE;AACA,QAAMI,iBAAiB,GAAGC,mCAAmC,CAC3DH,mCAD2D,EAE3DJ,IAAI,CAACD,YAFsD,CAA7D;AAIA,SAAOO,iBAAP;AACD;;AAOD,SAASL,mCAAT,CAA6CR,cAA7C,EAIE;AACA,MAAIe,UAAU,GAAG,CAAjB;AACA,MAAIC,YAAY,GAAG,CAAnB;AACA,MAAIC,gBAAgB,GAAGjB,cAAc,CAAC,CAAD,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,IAAAA,GAAG,IAAIE,aAAa,CAAChE,SAAd,CAAwBM,MAAxB,GAAiCT,kCAAxC;AACAgE,IAAAA,QAAQ,IAAI,CAAZ;AACD;;AAEDD,EAAAA,KAAK,CAAClC,IAAN,CAAW1B,SAAS,CAACM,MAAV,GAAmBT,kCAAnB,GAAwD,CAAnE;AAEA,QAAMU,SAAS,GAAG,IAAIC,WAAJ,CAAgBoD,KAAhB,CAAlB;AACA,SAAO;AAACrD,IAAAA,SAAD;AAAYE,IAAAA,UAAZ;AAAwBT,IAAAA,SAAxB;AAAmCC,IAAAA,OAAnC;AAA4CE,IAAAA,MAA5C;AAAoDD,IAAAA,SAApD;AAA+DQ,IAAAA;AAA/D,GAAP;AACD","sourcesContent":["import type {GeometryAttributes, ConvertedAttributes, GroupedByFeatureIdAttributes} from '../types';\nimport {concatenateTypedArrays} from '@loaders.gl/loader-utils';\n\nconst VALUES_PER_VERTEX = 3;\nconst POSITIONS_AND_NORMALS_PER_TRIANGLE = 9;\n\n/**\n * Generate geometry attributes with faceRange and featureCount\n * @param attributes\n * @returns attirbutes with featureCount, featureIds and changed faceRange.\n */\nexport function generateAttributes(attributes: ConvertedAttributes): GeometryAttributes {\n const {positions, normals, texCoords, colors, featureIndices} = attributes;\n const triangleCount = positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE;\n\n if (!featureIndices.length) {\n return {\n faceRange: new Uint32Array([0, triangleCount - 1]),\n featureIds: [0],\n featureCount: 1,\n positions,\n normals,\n texCoords,\n colors\n };\n }\n\n const data = calculateFaceRangesAndFeaturesCount(featureIndices);\n const attributeObjects = makeAttributeObjects({...data, ...attributes});\n const unifiedAttributeObjectsByFeatureIds = unifyObjectsByFeatureId(attributeObjects);\n const groupedAttributes = groupAttributesAndRangesByFeatureId(\n unifiedAttributeObjectsByFeatureIds,\n data.featureCount\n );\n return groupedAttributes;\n}\n\n/**\n * Calculates face Ranges and feature count based on featureIndices.\n * @param featureIndices\n * @returns Object with featureCount, reordered attributes and changed faceRange.\n */\nfunction calculateFaceRangesAndFeaturesCount(featureIndices: number[]): {\n faceRange: Uint32Array;\n featureCount: number;\n featureIds: number[];\n} {\n let rangeIndex = 1;\n let featureIndex = 1;\n let currentFeatureId = featureIndices[0];\n const faceRangeList: any[] = [];\n const featureIds: any[] = [];\n const uniqueFeatureIds = [currentFeatureId];\n\n faceRangeList[0] = 0;\n featureIds[0] = currentFeatureId;\n\n for (let index = 1; index < featureIndices.length; index++) {\n if (currentFeatureId !== featureIndices[index]) {\n faceRangeList[rangeIndex] = index / VALUES_PER_VERTEX - 1;\n faceRangeList[rangeIndex + 1] = index / VALUES_PER_VERTEX;\n featureIds[featureIndex] = featureIndices[index];\n\n if (!uniqueFeatureIds.includes(featureIndices[index])) {\n uniqueFeatureIds.push(featureIndices[index]);\n }\n\n rangeIndex += 2;\n featureIndex += 1;\n }\n currentFeatureId = featureIndices[index];\n }\n\n faceRangeList[rangeIndex] = featureIndices.length / VALUES_PER_VERTEX - 1;\n\n const faceRange = new Uint32Array(faceRangeList);\n const featureCount = uniqueFeatureIds.length;\n\n return {faceRange, featureCount, featureIds};\n}\n\n/**\n * Generate list of attribute object grouped by feature ids.\n * @param attributes\n * @returns sorted list of attribute objects.\n */\nfunction makeAttributeObjects(attributes: GeometryAttributes): GroupedByFeatureIdAttributes[] {\n const {\n featureIds,\n positions,\n normals,\n colors,\n texCoords,\n faceRange = new Uint32Array(0)\n } = attributes;\n const groupedData: GroupedByFeatureIdAttributes[] = [];\n\n let positionsList = new Float32Array(positions);\n let normalsList = new Float32Array(normals);\n let colorsList = new Uint8Array(colors);\n let texCoordsList = new Float32Array(texCoords);\n\n let faceRangeIndex = 0;\n\n for (let index = 0; index < featureIds.length; index++) {\n const startIndex = faceRange[index + faceRangeIndex];\n const endIndex = faceRange[index + faceRangeIndex + 1];\n\n const positionsCount = getSliceAttributeCount('positions', startIndex, endIndex);\n const normalsCount = getSliceAttributeCount('normals', startIndex, endIndex);\n const colorsCount = getSliceAttributeCount('colors', startIndex, endIndex);\n const texCoordsCount = getSliceAttributeCount('texCoords', startIndex, endIndex);\n\n groupedData.push({\n featureId: featureIds[index],\n positions: positionsList.slice(0, positionsCount),\n normals: normalsList.slice(0, normalsCount),\n colors: colorsList.slice(0, colorsCount),\n texCoords: texCoordsList.slice(0, texCoordsCount)\n });\n\n positionsList = positionsList.slice(positionsCount);\n normalsList = normalsList.slice(normalsCount);\n colorsList = colorsList.slice(colorsCount);\n texCoordsList = texCoordsList.slice(texCoordsCount);\n\n faceRangeIndex += 1;\n }\n\n return groupedData.sort((first, second) => first.featureId - second.featureId);\n}\n\n/**\n * Generate sliced count for generating attribute objects depends on attribute name and range.\n * @param attributeName\n * @param startIndex\n * @param endIndex\n * @returns sliced count\n */\nfunction getSliceAttributeCount(\n attributeName: string,\n startIndex: number,\n endIndex: number\n): number {\n const colorsPerVertex = 4;\n const texCoordsPerVertex = 2;\n\n const trianglesCount = endIndex - startIndex + 1;\n const vertexCount = trianglesCount * 3;\n\n switch (attributeName) {\n case 'positions':\n case 'normals':\n return trianglesCount * POSITIONS_AND_NORMALS_PER_TRIANGLE;\n case 'colors':\n return vertexCount * colorsPerVertex;\n case 'texCoords':\n return vertexCount * texCoordsPerVertex;\n default:\n return 0;\n }\n}\n\n/**\n * Generates unique object list depends on feature ids and concantenate their attributes.\n * @param sortedData\n * @returns unique list of objects\n */\nfunction unifyObjectsByFeatureId(\n sortedData: GroupedByFeatureIdAttributes[]\n): GroupedByFeatureIdAttributes[] {\n const uniqueObjects: GroupedByFeatureIdAttributes[] = [];\n\n for (let index = 0; index < sortedData.length; index++) {\n const currentObject = sortedData[index];\n const existedObject = uniqueObjects.find((obj) => obj.featureId === currentObject.featureId);\n\n if (existedObject) {\n existedObject.positions = concatenateTypedArrays(\n existedObject.positions,\n currentObject.positions\n );\n existedObject.normals = concatenateTypedArrays(existedObject.normals, currentObject.normals);\n existedObject.colors = concatenateTypedArrays(existedObject.colors, currentObject.colors);\n existedObject.texCoords = concatenateTypedArrays(\n existedObject.texCoords,\n currentObject.texCoords\n );\n } else {\n uniqueObjects.push(currentObject);\n }\n }\n\n return uniqueObjects;\n}\n\n/**\n * Generates attribute objects with new faceRange and reordered attributes.\n * @param unifiedObjects\n * @returns generated attributes with new faceRange.\n */\nfunction groupAttributesAndRangesByFeatureId(\n unifiedObjects: GroupedByFeatureIdAttributes[],\n featureCount: number\n): GeometryAttributes {\n const firstAttributeObject = unifiedObjects[0];\n const featureIds = [firstAttributeObject.featureId || 0];\n\n let positions = new Float32Array(firstAttributeObject.positions);\n let normals = new Float32Array(firstAttributeObject.normals);\n let colors = new Uint8Array(firstAttributeObject.colors);\n let texCoords = new Float32Array(firstAttributeObject.texCoords);\n const range = [0];\n\n let objIndex = 0;\n let sum = 0;\n\n for (let index = 1; index < unifiedObjects.length; index++) {\n const currentAttributesObject = unifiedObjects[index];\n featureIds.push(currentAttributesObject.featureId || 0);\n\n positions = concatenateTypedArrays(positions, currentAttributesObject.positions);\n normals = concatenateTypedArrays(normals, currentAttributesObject.normals);\n colors = concatenateTypedArrays(colors, currentAttributesObject.colors);\n texCoords = concatenateTypedArrays(texCoords, currentAttributesObject.texCoords);\n\n const groupedObject = unifiedObjects[objIndex];\n range.push(groupedObject.positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE - 1 + sum);\n range.push(groupedObject.positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE + sum);\n\n sum += groupedObject.positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE;\n objIndex += 1;\n }\n\n range.push(positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE - 1);\n\n const faceRange = new Uint32Array(range);\n return {faceRange, featureIds, positions, normals, colors, texCoords, featureCount};\n}\n"],"file":"geometry-attributes.js"}