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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts +3 -3
  2. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts.map +1 -1
  3. package/dist/3d-tiles-converter/3d-tiles-converter.js +329 -293
  4. package/dist/3d-tiles-converter/helpers/b3dm-converter.js +257 -200
  5. package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +14 -5
  6. package/dist/3d-tiles-converter/helpers/load-i3s.js +106 -75
  7. package/dist/3d-tiles-converter/helpers/texture-atlas.js +44 -21
  8. package/dist/3d-tiles-converter/json-templates/tileset.js +32 -33
  9. package/dist/constants.js +0 -1
  10. package/dist/converter-cli.js +255 -234
  11. package/dist/converter.min.cjs +80 -90
  12. package/dist/deps-installer/deps-installer.js +72 -58
  13. package/dist/i3s-converter/helpers/attribute-metadata-info.js +207 -153
  14. package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts +1 -1
  15. package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts.map +1 -1
  16. package/dist/i3s-converter/helpers/batch-ids-extensions.js +145 -103
  17. package/dist/i3s-converter/helpers/coordinate-converter.js +100 -65
  18. package/dist/i3s-converter/helpers/create-scene-server-path.js +14 -9
  19. package/dist/i3s-converter/helpers/feature-attributes.js +168 -105
  20. package/dist/i3s-converter/helpers/geometry-attributes.d.ts +1 -1
  21. package/dist/i3s-converter/helpers/geometry-attributes.d.ts.map +1 -1
  22. package/dist/i3s-converter/helpers/geometry-attributes.js +204 -212
  23. package/dist/i3s-converter/helpers/geometry-converter.d.ts +2 -2
  24. package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -1
  25. package/dist/i3s-converter/helpers/geometry-converter.js +1148 -829
  26. package/dist/i3s-converter/helpers/gltf-attributes.d.ts +1 -1
  27. package/dist/i3s-converter/helpers/gltf-attributes.d.ts.map +1 -1
  28. package/dist/i3s-converter/helpers/gltf-attributes.js +111 -97
  29. package/dist/i3s-converter/helpers/load-3d-tiles.js +103 -66
  30. package/dist/i3s-converter/helpers/node-debug.js +98 -54
  31. package/dist/i3s-converter/helpers/node-index-document.d.ts +3 -3
  32. package/dist/i3s-converter/helpers/node-index-document.d.ts.map +1 -1
  33. package/dist/i3s-converter/helpers/node-index-document.js +248 -177
  34. package/dist/i3s-converter/helpers/node-pages.d.ts +1 -1
  35. package/dist/i3s-converter/helpers/node-pages.d.ts.map +1 -1
  36. package/dist/i3s-converter/helpers/node-pages.js +299 -194
  37. package/dist/i3s-converter/helpers/preprocess-3d-tiles.d.ts +1 -1
  38. package/dist/i3s-converter/helpers/preprocess-3d-tiles.d.ts.map +1 -1
  39. package/dist/i3s-converter/helpers/preprocess-3d-tiles.js +92 -60
  40. package/dist/i3s-converter/helpers/progress.js +134 -83
  41. package/dist/i3s-converter/helpers/tileset-traversal.d.ts +1 -1
  42. package/dist/i3s-converter/helpers/tileset-traversal.d.ts.map +1 -1
  43. package/dist/i3s-converter/helpers/tileset-traversal.js +24 -13
  44. package/dist/i3s-converter/i3s-converter.d.ts +7 -7
  45. package/dist/i3s-converter/i3s-converter.d.ts.map +1 -1
  46. package/dist/i3s-converter/i3s-converter.js +1044 -898
  47. package/dist/i3s-converter/json-templates/geometry-definitions.js +70 -79
  48. package/dist/i3s-converter/json-templates/layers.js +120 -121
  49. package/dist/i3s-converter/json-templates/metadata.js +19 -20
  50. package/dist/i3s-converter/json-templates/node.js +73 -71
  51. package/dist/i3s-converter/json-templates/scene-server.js +25 -26
  52. package/dist/i3s-converter/json-templates/shared-resources.js +107 -108
  53. package/dist/i3s-converter/json-templates/store.js +96 -94
  54. package/dist/i3s-converter/types.js +35 -23
  55. package/dist/i3s-server/app.js +15 -12
  56. package/dist/i3s-server/bin/www.js +14 -7
  57. package/dist/i3s-server/controllers/index-controller.js +18 -15
  58. package/dist/i3s-server/controllers/slpk-controller.js +22 -11
  59. package/dist/i3s-server/routes/index.js +9 -8
  60. package/dist/i3s-server/routes/slpk-router.js +18 -17
  61. package/dist/i3s-server/utils/create-scene-server.js +15 -10
  62. package/dist/i3s-server/utils/server-utils.js +49 -32
  63. package/dist/index.cjs +292 -851
  64. package/dist/index.cjs.map +7 -0
  65. package/dist/index.d.ts +2 -2
  66. package/dist/index.d.ts.map +1 -1
  67. package/dist/index.js +0 -1
  68. package/dist/lib/json-schemas/conversion-dump-json-schema.js +243 -421
  69. package/dist/lib/utils/cli-utils.js +63 -36
  70. package/dist/lib/utils/compress-util.js +20 -15
  71. package/dist/lib/utils/conversion-dump.d.ts +1 -1
  72. package/dist/lib/utils/conversion-dump.d.ts.map +1 -1
  73. package/dist/lib/utils/conversion-dump.js +209 -187
  74. package/dist/lib/utils/file-utils.js +122 -74
  75. package/dist/lib/utils/geometry-utils.js +13 -7
  76. package/dist/lib/utils/lod-conversion-utils.js +65 -33
  77. package/dist/lib/utils/queue.js +12 -13
  78. package/dist/lib/utils/statistic-utills.d.ts +6 -23
  79. package/dist/lib/utils/statistic-utills.js +64 -59
  80. package/dist/lib/utils/write-queue.d.ts +2 -2
  81. package/dist/lib/utils/write-queue.d.ts.map +1 -1
  82. package/dist/lib/utils/write-queue.js +68 -86
  83. package/dist/pgm-loader.js +16 -12
  84. package/dist/slpk-extractor/slpk-extractor.js +59 -50
  85. package/dist/slpk-extractor-cli.js +82 -59
  86. package/package.json +18 -18
  87. package/dist/3d-tiles-converter/3d-tiles-converter.js.map +0 -1
  88. package/dist/3d-tiles-converter/helpers/b3dm-converter.js.map +0 -1
  89. package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +0 -1
  90. package/dist/3d-tiles-converter/helpers/load-i3s.js.map +0 -1
  91. package/dist/3d-tiles-converter/helpers/texture-atlas.js.map +0 -1
  92. package/dist/3d-tiles-converter/json-templates/tileset.js.map +0 -1
  93. package/dist/constants.js.map +0 -1
  94. package/dist/converter-cli.js.map +0 -1
  95. package/dist/deps-installer/deps-installer.js.map +0 -1
  96. package/dist/i3s-converter/helpers/attribute-metadata-info.js.map +0 -1
  97. package/dist/i3s-converter/helpers/batch-ids-extensions.js.map +0 -1
  98. package/dist/i3s-converter/helpers/coordinate-converter.js.map +0 -1
  99. package/dist/i3s-converter/helpers/create-scene-server-path.js.map +0 -1
  100. package/dist/i3s-converter/helpers/feature-attributes.js.map +0 -1
  101. package/dist/i3s-converter/helpers/geometry-attributes.js.map +0 -1
  102. package/dist/i3s-converter/helpers/geometry-converter.js.map +0 -1
  103. package/dist/i3s-converter/helpers/gltf-attributes.js.map +0 -1
  104. package/dist/i3s-converter/helpers/load-3d-tiles.js.map +0 -1
  105. package/dist/i3s-converter/helpers/node-debug.js.map +0 -1
  106. package/dist/i3s-converter/helpers/node-index-document.js.map +0 -1
  107. package/dist/i3s-converter/helpers/node-pages.js.map +0 -1
  108. package/dist/i3s-converter/helpers/preprocess-3d-tiles.js.map +0 -1
  109. package/dist/i3s-converter/helpers/progress.js.map +0 -1
  110. package/dist/i3s-converter/helpers/tileset-traversal.js.map +0 -1
  111. package/dist/i3s-converter/i3s-converter.js.map +0 -1
  112. package/dist/i3s-converter/json-templates/geometry-definitions.js.map +0 -1
  113. package/dist/i3s-converter/json-templates/layers.js.map +0 -1
  114. package/dist/i3s-converter/json-templates/metadata.js.map +0 -1
  115. package/dist/i3s-converter/json-templates/node.js.map +0 -1
  116. package/dist/i3s-converter/json-templates/scene-server.js.map +0 -1
  117. package/dist/i3s-converter/json-templates/shared-resources.js.map +0 -1
  118. package/dist/i3s-converter/json-templates/store.js.map +0 -1
  119. package/dist/i3s-converter/types.js.map +0 -1
  120. package/dist/i3s-server/README.md +0 -63
  121. package/dist/i3s-server/app.js.map +0 -1
  122. package/dist/i3s-server/bin/www.js.map +0 -1
  123. package/dist/i3s-server/certs/cert.pem +0 -19
  124. package/dist/i3s-server/certs/key.pem +0 -27
  125. package/dist/i3s-server/controllers/index-controller.js.map +0 -1
  126. package/dist/i3s-server/controllers/slpk-controller.js.map +0 -1
  127. package/dist/i3s-server/routes/index.js.map +0 -1
  128. package/dist/i3s-server/routes/slpk-router.js.map +0 -1
  129. package/dist/i3s-server/utils/create-scene-server.js.map +0 -1
  130. package/dist/i3s-server/utils/server-utils.js.map +0 -1
  131. package/dist/index.js.map +0 -1
  132. package/dist/lib/json-schemas/conversion-dump-json-schema.js.map +0 -1
  133. package/dist/lib/utils/cli-utils.js.map +0 -1
  134. package/dist/lib/utils/compress-util.js.map +0 -1
  135. package/dist/lib/utils/conversion-dump.js.map +0 -1
  136. package/dist/lib/utils/file-utils.js.map +0 -1
  137. package/dist/lib/utils/geometry-utils.js.map +0 -1
  138. package/dist/lib/utils/lod-conversion-utils.js.map +0 -1
  139. package/dist/lib/utils/queue.js.map +0 -1
  140. package/dist/lib/utils/statistic-utills.js.map +0 -1
  141. package/dist/lib/utils/write-queue.js.map +0 -1
  142. package/dist/pgm-loader.js.map +0 -1
  143. package/dist/slpk-extractor/slpk-extractor.js.map +0 -1
  144. package/dist/slpk-extractor-cli.js.map +0 -1
@@ -1,122 +1,164 @@
1
1
  import { emod } from '@loaders.gl/math';
2
2
  import { EXT_MESH_FEATURES, EXT_FEATURE_METADATA } from '@loaders.gl/gltf';
3
+ /**
4
+ * Get featureTexture by a metadata class.
5
+ * Metadata classes come from a structural metadata extesion (EXT_feature_metadata or EXT_structural_metadata).
6
+ * The glTF might contain multiple texel-level metadata textures related to different classes. Having only one metadata class
7
+ * selected to convert to I3S, we have to pick only one texture to convert to per-vertex property.
8
+ * @param tileContent - 3d tile content
9
+ * @param metadataClass - user selected feature metadata class name
10
+ * @returns featureTexture key
11
+ */
3
12
  export function getTextureByMetadataClass(tileContent, metadataClass) {
4
- var _tileContent$gltf, _tileContent$gltf$ext;
5
- const extFeatureMetadata = (_tileContent$gltf = tileContent.gltf) === null || _tileContent$gltf === void 0 ? void 0 : (_tileContent$gltf$ext = _tileContent$gltf.extensions) === null || _tileContent$gltf$ext === void 0 ? void 0 : _tileContent$gltf$ext[EXT_FEATURE_METADATA];
6
- if (!(extFeatureMetadata !== null && extFeatureMetadata !== void 0 && extFeatureMetadata.featureTextures)) {
7
- return null;
8
- }
9
- for (const textureKey in extFeatureMetadata.featureTextures) {
10
- const texture = extFeatureMetadata.featureTextures[textureKey];
11
- if (texture.class === metadataClass) {
12
- return textureKey;
13
+ const extFeatureMetadata = tileContent.gltf?.extensions?.[EXT_FEATURE_METADATA];
14
+ if (!extFeatureMetadata?.featureTextures) {
15
+ return null;
16
+ }
17
+ for (const textureKey in extFeatureMetadata.featureTextures) {
18
+ const texture = extFeatureMetadata.featureTextures[textureKey];
19
+ if (texture.class === metadataClass) {
20
+ return textureKey;
21
+ }
13
22
  }
14
- }
15
- return null;
23
+ return null;
16
24
  }
25
+ /**
26
+ * Getting batchIds from 3DTilesNext extensions.
27
+ * @param attributes - gltf accessors
28
+ * @param primitive - gltf primitive data
29
+ * @param images - gltf texture images
30
+ * @param featureTexture - feature texture key
31
+ * @return array of batch IDs
32
+ */
17
33
  export function handleBatchIdsExtensions(attributes, primitive, images, featureTexture) {
18
- const extensions = primitive === null || primitive === void 0 ? void 0 : primitive.extensions;
19
- if (!extensions) {
20
- return [];
21
- }
22
- for (const [extensionName, extensionData] of Object.entries(extensions || {})) {
23
- switch (extensionName) {
24
- case EXT_FEATURE_METADATA:
25
- return handleExtFeatureMetadataExtension(attributes, extensionData, images, featureTexture);
26
- case EXT_MESH_FEATURES:
27
- return handleExtMeshFeaturesExtension(attributes, extensionData);
28
- default:
34
+ const extensions = primitive?.extensions;
35
+ if (!extensions) {
29
36
  return [];
30
37
  }
31
- }
32
- return [];
38
+ for (const [extensionName, extensionData] of Object.entries(extensions || {})) {
39
+ switch (extensionName) {
40
+ case EXT_FEATURE_METADATA:
41
+ return handleExtFeatureMetadataExtension(attributes, extensionData, images, featureTexture);
42
+ case EXT_MESH_FEATURES:
43
+ return handleExtMeshFeaturesExtension(attributes, extensionData);
44
+ default:
45
+ return [];
46
+ }
47
+ }
48
+ return [];
33
49
  }
50
+ /**
51
+ * Getting batchIds from EXT_mesh_features extensions.
52
+ * @param attributes - gltf accessors
53
+ * @param extMeshFeatures - EXT_mesh_features extension
54
+ * @returns an array of attribute values
55
+ */
34
56
  function handleExtMeshFeaturesExtension(attributes, extMeshFeatures) {
35
- for (let ids of extMeshFeatures.featureIds) {
36
- if (typeof ids.propertyTable !== 'undefined') {
37
- return ids.data;
57
+ for (let ids of extMeshFeatures.featureIds) {
58
+ if (typeof ids.propertyTable !== 'undefined') {
59
+ // propertyTable is an index that can be 0
60
+ // return the first featureID set that corresponts to property table.
61
+ return ids.data;
62
+ }
38
63
  }
39
- }
40
- return [];
64
+ return [];
41
65
  }
66
+ /**
67
+ * Get batchIds from EXT_feature_metadata extension.
68
+ * @see - https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata
69
+ * @param attributes - glTF attributes
70
+ * @param extFeatureMetadata - primitive-level EXT_FEATURE_METADATA extension data
71
+ * @param textures - texture images
72
+ * @param featureTexture - feature texture key
73
+ */
42
74
  function handleExtFeatureMetadataExtension(attributes, extFeatureMetadata, images, featureTexture) {
43
- var _extFeatureMetadata$f, _featureIdAttribute$f, _featureIdAttribute$f2, _featureIdAttribute$f3;
44
- const featureIdAttribute = extFeatureMetadata === null || extFeatureMetadata === void 0 ? void 0 : (_extFeatureMetadata$f = extFeatureMetadata.featureIdAttributes) === null || _extFeatureMetadata$f === void 0 ? void 0 : _extFeatureMetadata$f[0];
45
- if (featureIdAttribute !== null && featureIdAttribute !== void 0 && (_featureIdAttribute$f = featureIdAttribute.featureIds) !== null && _featureIdAttribute$f !== void 0 && _featureIdAttribute$f.attribute) {
46
- const batchIdsAttribute = attributes[featureIdAttribute.featureIds.attribute];
47
- return batchIdsAttribute.value;
48
- }
49
- if (featureIdAttribute !== null && featureIdAttribute !== void 0 && (_featureIdAttribute$f2 = featureIdAttribute.featureIds) !== null && _featureIdAttribute$f2 !== void 0 && _featureIdAttribute$f2.hasOwnProperty('constant') && featureIdAttribute !== null && featureIdAttribute !== void 0 && (_featureIdAttribute$f3 = featureIdAttribute.featureIds) !== null && _featureIdAttribute$f3 !== void 0 && _featureIdAttribute$f3.hasOwnProperty('divisor')) {
50
- var _attributes$POSITIONS;
51
- const featuresCount = (attributes === null || attributes === void 0 ? void 0 : (_attributes$POSITIONS = attributes.POSITIONS) === null || _attributes$POSITIONS === void 0 ? void 0 : _attributes$POSITIONS.value.length) / 3 || 0;
52
- return generateImplicitFeatureIds(featuresCount, featureIdAttribute.featureIds.constant, featureIdAttribute.featureIds.divisor);
53
- }
54
- const featureIdTexture = (extFeatureMetadata === null || extFeatureMetadata === void 0 ? void 0 : extFeatureMetadata.featureIdTextures) && (extFeatureMetadata === null || extFeatureMetadata === void 0 ? void 0 : extFeatureMetadata.featureIdTextures[0]);
55
- if (featureIdTexture) {
56
- var _featureIdTexture$fea, _featureIdTexture$fea2;
57
- const textureAttributeIndex = (featureIdTexture === null || featureIdTexture === void 0 ? void 0 : (_featureIdTexture$fea = featureIdTexture.featureIds) === null || _featureIdTexture$fea === void 0 ? void 0 : (_featureIdTexture$fea2 = _featureIdTexture$fea.texture) === null || _featureIdTexture$fea2 === void 0 ? void 0 : _featureIdTexture$fea2.texCoord) || 0;
58
- const textCoordAttribute = `TEXCOORD_${textureAttributeIndex}`;
59
- const textureCoordinates = attributes[textCoordAttribute].value;
60
- return generateBatchIdsFromTexture(featureIdTexture, textureCoordinates, images);
61
- }
62
- if (featureTexture) {
63
- const batchIdsAttribute = attributes[featureTexture];
64
- return batchIdsAttribute.value;
65
- }
66
- return [];
75
+ // Take only first extension object to get batchIds attribute name.
76
+ const featureIdAttribute = extFeatureMetadata?.featureIdAttributes?.[0];
77
+ if (featureIdAttribute?.featureIds?.attribute) {
78
+ const batchIdsAttribute = attributes[featureIdAttribute.featureIds.attribute];
79
+ return batchIdsAttribute.value;
80
+ }
81
+ if (featureIdAttribute?.featureIds?.hasOwnProperty('constant') &&
82
+ featureIdAttribute?.featureIds?.hasOwnProperty('divisor')) {
83
+ const featuresCount = attributes?.POSITIONS?.value.length / 3 || 0;
84
+ return generateImplicitFeatureIds(featuresCount, featureIdAttribute.featureIds.constant, featureIdAttribute.featureIds.divisor);
85
+ }
86
+ // Take only first extension object to get batchIds attribute name.
87
+ const featureIdTexture = extFeatureMetadata?.featureIdTextures && extFeatureMetadata?.featureIdTextures[0];
88
+ if (featureIdTexture) {
89
+ const textureAttributeIndex = featureIdTexture?.featureIds?.texture?.texCoord || 0;
90
+ const textCoordAttribute = `TEXCOORD_${textureAttributeIndex}`;
91
+ const textureCoordinates = attributes[textCoordAttribute].value;
92
+ return generateBatchIdsFromTexture(featureIdTexture, textureCoordinates, images);
93
+ }
94
+ if (featureTexture) {
95
+ const batchIdsAttribute = attributes[featureTexture];
96
+ return batchIdsAttribute.value;
97
+ }
98
+ return [];
67
99
  }
68
- function generateImplicitFeatureIds(featuresCount) {
69
- let constant = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
70
- let divisor = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
71
- let featureIds = [];
72
- if (divisor > 0) {
73
- let currentValue = constant;
74
- let devisorCounter = divisor;
75
- for (let index = 0; index < featuresCount; index++) {
76
- featureIds.push(currentValue);
77
- devisorCounter -= 1;
78
- if (devisorCounter === 0) {
79
- currentValue++;
80
- devisorCounter = divisor;
81
- }
100
+ /**
101
+ * Generates implicit feature ids
102
+ * @see - https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata#implicit-feature-ids
103
+ * @param featuresCount
104
+ * @param constant
105
+ * @param devisor
106
+ */
107
+ function generateImplicitFeatureIds(featuresCount, constant = 0, divisor = 0) {
108
+ let featureIds = [];
109
+ if (divisor > 0) {
110
+ let currentValue = constant;
111
+ let devisorCounter = divisor;
112
+ for (let index = 0; index < featuresCount; index++) {
113
+ featureIds.push(currentValue);
114
+ devisorCounter -= 1;
115
+ if (devisorCounter === 0) {
116
+ currentValue++;
117
+ devisorCounter = divisor;
118
+ }
119
+ }
120
+ }
121
+ else {
122
+ featureIds = Array(featuresCount).fill(constant, 0, featuresCount);
82
123
  }
83
- } else {
84
- featureIds = Array(featuresCount).fill(constant, 0, featuresCount);
85
- }
86
- return featureIds;
124
+ return featureIds;
87
125
  }
126
+ /**
127
+ * Get batchIds from texture.
128
+ * @param primitive
129
+ * @param featureIdTextures
130
+ */
88
131
  function generateBatchIdsFromTexture(featureIdTexture, textureCoordinates, images) {
89
- var _featureIdTexture$fea3, _featureIdTexture$fea4, _featureIdTexture$fea5;
90
- if (!(images !== null && images !== void 0 && images.length)) {
91
- return [];
92
- }
93
- const CHANNELS_MAP = {
94
- r: 0,
95
- g: 1,
96
- b: 2,
97
- a: 3
98
- };
99
- const textureIndex = featureIdTexture === null || featureIdTexture === void 0 ? void 0 : (_featureIdTexture$fea3 = featureIdTexture.featureIds) === null || _featureIdTexture$fea3 === void 0 ? void 0 : (_featureIdTexture$fea4 = _featureIdTexture$fea3.texture) === null || _featureIdTexture$fea4 === void 0 ? void 0 : _featureIdTexture$fea4.index;
100
- const featureChannel = featureIdTexture === null || featureIdTexture === void 0 ? void 0 : (_featureIdTexture$fea5 = featureIdTexture.featureIds) === null || _featureIdTexture$fea5 === void 0 ? void 0 : _featureIdTexture$fea5.channels;
101
- if (!featureChannel || textureIndex === undefined) {
102
- return [];
103
- }
104
- const image = images[textureIndex];
105
- const batchIds = [];
106
- const channels = CHANNELS_MAP[featureChannel];
107
- if (image && image !== null && image !== void 0 && image.width && image !== null && image !== void 0 && image.height && image !== null && image !== void 0 && image.components) {
108
- for (let index = 0; index < textureCoordinates.length; index += 2) {
109
- const u = textureCoordinates[index];
110
- const v = textureCoordinates[index + 1];
111
- const tx = Math.min(emod(u) * image.width | 0, image.width - 1);
112
- const ty = Math.min(emod(v) * image.height | 0, image.height - 1);
113
- const offset = (ty * image.width + tx) * image.components + channels;
114
- const batchId = new Uint8Array(image.data)[offset];
115
- batchIds.push(batchId);
132
+ if (!images?.length) {
133
+ return [];
134
+ }
135
+ const CHANNELS_MAP = {
136
+ r: 0,
137
+ g: 1,
138
+ b: 2,
139
+ a: 3
140
+ };
141
+ const textureIndex = featureIdTexture?.featureIds?.texture?.index;
142
+ const featureChannel = featureIdTexture?.featureIds?.channels;
143
+ if (!featureChannel || textureIndex === undefined) {
144
+ return [];
145
+ }
146
+ const image = images[textureIndex];
147
+ const batchIds = [];
148
+ const channels = CHANNELS_MAP[featureChannel];
149
+ if (image && image?.width && image?.height && image?.components) {
150
+ for (let index = 0; index < textureCoordinates.length; index += 2) {
151
+ const u = textureCoordinates[index];
152
+ const v = textureCoordinates[index + 1];
153
+ const tx = Math.min((emod(u) * image.width) | 0, image.width - 1);
154
+ const ty = Math.min((emod(v) * image.height) | 0, image.height - 1);
155
+ const offset = (ty * image.width + tx) * image.components + channels;
156
+ const batchId = new Uint8Array(image.data)[offset];
157
+ batchIds.push(batchId);
158
+ }
159
+ }
160
+ else {
161
+ console.warn(`Can't get batch Ids from ${image?.mimeType || ''} compressed texture`);
116
162
  }
117
- } else {
118
- console.warn(`Can't get batch Ids from ${(image === null || image === void 0 ? void 0 : image.mimeType) || ''} compressed texture`);
119
- }
120
- return batchIds;
163
+ return batchIds;
121
164
  }
122
- //# sourceMappingURL=batch-ids-extensions.js.map
@@ -1,79 +1,114 @@
1
1
  import { Matrix3, Quaternion, Vector3 } from '@math.gl/core';
2
2
  import { Ellipsoid } from '@math.gl/geospatial';
3
3
  import { OrientedBoundingBox, makeOrientedBoundingBoxFromPoints, makeBoundingSphereFromPoints, BoundingSphere } from '@math.gl/culling';
4
+ /**
5
+ * Create bounding volumes object from tile and geoid height model.
6
+ * @param sourceBoundingVolume - initialized bounding volume of the source tile
7
+ * @param geoidHeightModel - instance of Geoid class that converts elevation from geoidal to ellipsoidal and back
8
+ * @returns - Bounding volumes object
9
+ */
4
10
  export function createBoundingVolumes(sourceBoundingVolume, geoidHeightModel) {
5
- let radius;
6
- let halfSize;
7
- let quaternion;
8
- const cartographicCenter = Ellipsoid.WGS84.cartesianToCartographic(sourceBoundingVolume.center, new Vector3());
9
- cartographicCenter[2] = cartographicCenter[2] - geoidHeightModel.getHeight(cartographicCenter[1], cartographicCenter[0]);
10
- if (sourceBoundingVolume instanceof OrientedBoundingBox) {
11
- halfSize = sourceBoundingVolume.halfSize;
12
- radius = new Vector3(halfSize[0], halfSize[1], halfSize[2]).len();
13
- quaternion = sourceBoundingVolume.quaternion;
14
- } else {
15
- radius = sourceBoundingVolume.radius;
16
- halfSize = [radius, radius, radius];
17
- quaternion = new Quaternion().fromMatrix3(new Matrix3([halfSize[0], 0, 0, 0, halfSize[1], 0, 0, 0, halfSize[2]])).normalize();
18
- }
19
- return {
20
- mbs: [cartographicCenter[0], cartographicCenter[1], cartographicCenter[2], radius],
21
- obb: {
22
- center: [cartographicCenter[0], cartographicCenter[1], cartographicCenter[2]],
23
- halfSize,
24
- quaternion
11
+ let radius;
12
+ let halfSize;
13
+ let quaternion;
14
+ const cartographicCenter = Ellipsoid.WGS84.cartesianToCartographic(sourceBoundingVolume.center, new Vector3());
15
+ cartographicCenter[2] =
16
+ cartographicCenter[2] -
17
+ geoidHeightModel.getHeight(cartographicCenter[1], cartographicCenter[0]);
18
+ if (sourceBoundingVolume instanceof OrientedBoundingBox) {
19
+ halfSize = sourceBoundingVolume.halfSize;
20
+ radius = new Vector3(halfSize[0], halfSize[1], halfSize[2]).len();
21
+ quaternion = sourceBoundingVolume.quaternion;
25
22
  }
26
- };
23
+ else {
24
+ radius = sourceBoundingVolume.radius;
25
+ halfSize = [radius, radius, radius];
26
+ quaternion = new Quaternion()
27
+ .fromMatrix3(new Matrix3([halfSize[0], 0, 0, 0, halfSize[1], 0, 0, 0, halfSize[2]]))
28
+ .normalize();
29
+ }
30
+ return {
31
+ mbs: [cartographicCenter[0], cartographicCenter[1], cartographicCenter[2], radius],
32
+ obb: {
33
+ center: [cartographicCenter[0], cartographicCenter[1], cartographicCenter[2]],
34
+ halfSize,
35
+ quaternion
36
+ }
37
+ };
27
38
  }
39
+ /**
40
+ * Generates bounding volumes from geometry positions
41
+ * @param cartesianPositions
42
+ * @param geoidHeightModel
43
+ */
28
44
  export function createBoundingVolumesFromGeometry(cartesianPositions, geoidHeightModel) {
29
- const positionVectors = convertPositionsToVectors(cartesianPositions);
30
- const geometryObb = makeOrientedBoundingBoxFromPoints(positionVectors);
31
- const geometryMbs = makeBoundingSphereFromPoints(positionVectors);
32
- let mbsCenter = Ellipsoid.WGS84.cartesianToCartographic(geometryMbs.center, new Vector3());
33
- let obbCenter = Ellipsoid.WGS84.cartesianToCartographic(geometryObb.center, new Vector3());
34
- mbsCenter[2] = mbsCenter[2] - geoidHeightModel.getHeight(mbsCenter[1], mbsCenter[0]);
35
- obbCenter[2] = obbCenter[2] - geoidHeightModel.getHeight(obbCenter[1], obbCenter[0]);
36
- return {
37
- mbs: [mbsCenter[0], mbsCenter[1], mbsCenter[2], geometryMbs.radius],
38
- obb: {
39
- center: obbCenter,
40
- halfSize: geometryObb.halfSize,
41
- quaternion: geometryObb.quaternion
42
- }
43
- };
45
+ const positionVectors = convertPositionsToVectors(cartesianPositions);
46
+ const geometryObb = makeOrientedBoundingBoxFromPoints(positionVectors);
47
+ const geometryMbs = makeBoundingSphereFromPoints(positionVectors);
48
+ let mbsCenter = Ellipsoid.WGS84.cartesianToCartographic(geometryMbs.center, new Vector3());
49
+ let obbCenter = Ellipsoid.WGS84.cartesianToCartographic(geometryObb.center, new Vector3());
50
+ mbsCenter[2] = mbsCenter[2] - geoidHeightModel.getHeight(mbsCenter[1], mbsCenter[0]);
51
+ obbCenter[2] = obbCenter[2] - geoidHeightModel.getHeight(obbCenter[1], obbCenter[0]);
52
+ return {
53
+ mbs: [mbsCenter[0], mbsCenter[1], mbsCenter[2], geometryMbs.radius],
54
+ obb: {
55
+ center: obbCenter,
56
+ halfSize: geometryObb.halfSize,
57
+ quaternion: geometryObb.quaternion
58
+ }
59
+ };
44
60
  }
61
+ /**
62
+ * Create array of posisitons where each vertex is vector
63
+ * @param {array} positions
64
+ * @returns {Vector3[]}
65
+ */
45
66
  export function convertPositionsToVectors(positions) {
46
- const result = [];
47
- for (let i = 0; i < positions.length; i += 3) {
48
- const positionVector = new Vector3([positions[i], positions[i + 1], positions[i + 2]]);
49
- result.push(positionVector);
50
- }
51
- return result;
67
+ const result = [];
68
+ for (let i = 0; i < positions.length; i += 3) {
69
+ // TODO: (perf) new Vector3 is not optimal but required in `makeOrientedBoundingBoxFromPoints`.
70
+ // modify `makeOrientedBoundingBoxFromPoints` to use scratch vectors
71
+ const positionVector = new Vector3([positions[i], positions[i + 1], positions[i + 2]]);
72
+ result.push(positionVector);
73
+ }
74
+ return result;
52
75
  }
76
+ /**
77
+ * Convert common coordinate to fullExtent https://github.com/Esri/i3s-spec/blob/master/docs/1.8/fullExtent.cmn.md
78
+ * @param boundingVolume
79
+ * @returns - fullExtent object
80
+ */
53
81
  export function convertBoundingVolumeToI3SFullExtent(boundingVolume) {
54
- let sphere;
55
- if (boundingVolume instanceof BoundingSphere) {
56
- sphere = boundingVolume;
57
- } else {
58
- sphere = boundingVolume.getBoundingSphere();
59
- }
60
- const center = sphere.center;
61
- const radius = sphere.radius;
62
- const vertexMax = Ellipsoid.WGS84.cartesianToCartographic(new Vector3(center[0] + radius, center[1] + radius, center[2] + radius), new Vector3());
63
- const vertexMin = Ellipsoid.WGS84.cartesianToCartographic(new Vector3(center[0] - radius, center[1] - radius, center[2] - radius), new Vector3());
64
- return {
65
- xmin: Math.min(vertexMin[0], vertexMax[0]),
66
- xmax: Math.max(vertexMin[0], vertexMax[0]),
67
- ymin: Math.min(vertexMin[1], vertexMax[1]),
68
- ymax: Math.max(vertexMin[1], vertexMax[1]),
69
- zmin: Math.min(vertexMin[2], vertexMax[2]),
70
- zmax: Math.max(vertexMin[2], vertexMax[2])
71
- };
82
+ let sphere;
83
+ if (boundingVolume instanceof BoundingSphere) {
84
+ sphere = boundingVolume;
85
+ }
86
+ else {
87
+ sphere = boundingVolume.getBoundingSphere();
88
+ }
89
+ const center = sphere.center;
90
+ const radius = sphere.radius;
91
+ const vertexMax = Ellipsoid.WGS84.cartesianToCartographic(new Vector3(center[0] + radius, center[1] + radius, center[2] + radius), new Vector3());
92
+ const vertexMin = Ellipsoid.WGS84.cartesianToCartographic(new Vector3(center[0] - radius, center[1] - radius, center[2] - radius), new Vector3());
93
+ // Converter sometimes returns min values that are bigger then max,
94
+ // so we should check and take bigger value from max and smaller for nim
95
+ return {
96
+ xmin: Math.min(vertexMin[0], vertexMax[0]),
97
+ xmax: Math.max(vertexMin[0], vertexMax[0]),
98
+ ymin: Math.min(vertexMin[1], vertexMax[1]),
99
+ ymax: Math.max(vertexMin[1], vertexMax[1]),
100
+ zmin: Math.min(vertexMin[2], vertexMax[2]),
101
+ zmax: Math.max(vertexMin[2], vertexMax[2])
102
+ };
72
103
  }
104
+ /**
105
+ * Creates oriented boundinb box from mbs.
106
+ * @param mbs - Minimum Bounding Sphere
107
+ * @returns - Oriented Bounding Box
108
+ */
73
109
  export function createObbFromMbs(mbs) {
74
- const radius = mbs[3];
75
- const center = new Vector3(mbs[0], mbs[1], mbs[2]);
76
- const halfAxex = new Matrix3([radius, 0, 0, 0, radius, 0, 0, 0, radius]);
77
- return new OrientedBoundingBox(center, halfAxex);
110
+ const radius = mbs[3];
111
+ const center = new Vector3(mbs[0], mbs[1], mbs[2]);
112
+ const halfAxex = new Matrix3([radius, 0, 0, 0, radius, 0, 0, 0, radius]);
113
+ return new OrientedBoundingBox(center, halfAxex);
78
114
  }
79
- //# sourceMappingURL=coordinate-converter.js.map
@@ -3,14 +3,19 @@ import transform from 'json-map-transform';
3
3
  import { join } from 'path';
4
4
  import { SCENE_SERVER as sceneServerTemplate } from "../json-templates/scene-server.js";
5
5
  import { writeFile } from "../../lib/utils/file-utils.js";
6
+ /**
7
+ * Form and save sceneServer meta data into a file
8
+ * @param layerName - layer name to display
9
+ * @param layers0 - layer object embedded into sceneServer meta data
10
+ * @param rootPath - root path of new converted tileset
11
+ */
6
12
  export async function createSceneServerPath(layerName, layers0, rootPath) {
7
- const sceneServerData = {
8
- serviceItemId: uuidv4().replace(/-/gi, ''),
9
- layerName,
10
- layers0
11
- };
12
- const sceneServer = transform(sceneServerData, sceneServerTemplate());
13
- const nodePagePath = join(rootPath, 'SceneServer');
14
- await writeFile(nodePagePath, JSON.stringify(sceneServer));
13
+ const sceneServerData = {
14
+ serviceItemId: uuidv4().replace(/-/gi, ''),
15
+ layerName,
16
+ layers0
17
+ };
18
+ const sceneServer = transform(sceneServerData, sceneServerTemplate());
19
+ const nodePagePath = join(rootPath, 'SceneServer');
20
+ await writeFile(nodePagePath, JSON.stringify(sceneServer));
15
21
  }
16
- //# sourceMappingURL=create-scene-server-path.js.map