@loaders.gl/tile-converter 4.2.0-alpha.3 → 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.
- package/dist/3d-tiles-converter/3d-tiles-converter.d.ts +3 -3
- package/dist/3d-tiles-converter/3d-tiles-converter.d.ts.map +1 -1
- package/dist/3d-tiles-converter/3d-tiles-converter.js +329 -293
- package/dist/3d-tiles-converter/helpers/b3dm-converter.js +257 -200
- package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +14 -5
- package/dist/3d-tiles-converter/helpers/load-i3s.js +106 -75
- package/dist/3d-tiles-converter/helpers/texture-atlas.js +44 -21
- package/dist/3d-tiles-converter/json-templates/tileset.js +32 -33
- package/dist/constants.js +0 -1
- package/dist/converter-cli.js +255 -234
- package/dist/converter.min.cjs +80 -90
- package/dist/deps-installer/deps-installer.js +73 -59
- package/dist/i3s-converter/helpers/attribute-metadata-info.js +207 -153
- package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts +1 -1
- package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/batch-ids-extensions.js +145 -103
- package/dist/i3s-converter/helpers/coordinate-converter.js +100 -65
- package/dist/i3s-converter/helpers/create-scene-server-path.js +14 -9
- package/dist/i3s-converter/helpers/feature-attributes.js +168 -105
- package/dist/i3s-converter/helpers/geometry-attributes.d.ts +1 -1
- package/dist/i3s-converter/helpers/geometry-attributes.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/geometry-attributes.js +204 -212
- package/dist/i3s-converter/helpers/geometry-converter.d.ts +2 -2
- package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/geometry-converter.js +1148 -829
- package/dist/i3s-converter/helpers/gltf-attributes.d.ts +1 -1
- package/dist/i3s-converter/helpers/gltf-attributes.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/gltf-attributes.js +111 -97
- package/dist/i3s-converter/helpers/load-3d-tiles.js +103 -66
- package/dist/i3s-converter/helpers/node-debug.js +98 -54
- package/dist/i3s-converter/helpers/node-index-document.d.ts +3 -3
- package/dist/i3s-converter/helpers/node-index-document.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/node-index-document.js +248 -177
- package/dist/i3s-converter/helpers/node-pages.d.ts +1 -1
- package/dist/i3s-converter/helpers/node-pages.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/node-pages.js +299 -194
- package/dist/i3s-converter/helpers/preprocess-3d-tiles.d.ts +1 -1
- package/dist/i3s-converter/helpers/preprocess-3d-tiles.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/preprocess-3d-tiles.js +92 -60
- package/dist/i3s-converter/helpers/progress.js +134 -83
- package/dist/i3s-converter/helpers/tileset-traversal.d.ts +1 -1
- package/dist/i3s-converter/helpers/tileset-traversal.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/tileset-traversal.js +24 -13
- package/dist/i3s-converter/i3s-converter.d.ts +7 -7
- package/dist/i3s-converter/i3s-converter.d.ts.map +1 -1
- package/dist/i3s-converter/i3s-converter.js +1044 -898
- package/dist/i3s-converter/json-templates/geometry-definitions.js +70 -79
- package/dist/i3s-converter/json-templates/layers.js +120 -121
- package/dist/i3s-converter/json-templates/metadata.js +19 -20
- package/dist/i3s-converter/json-templates/node.js +73 -71
- package/dist/i3s-converter/json-templates/scene-server.js +25 -26
- package/dist/i3s-converter/json-templates/shared-resources.js +107 -108
- package/dist/i3s-converter/json-templates/store.js +96 -94
- package/dist/i3s-converter/types.js +35 -23
- package/dist/i3s-server/app.js +15 -12
- package/dist/i3s-server/bin/www.js +14 -7
- package/dist/i3s-server/controllers/index-controller.js +18 -15
- package/dist/i3s-server/controllers/slpk-controller.js +22 -11
- package/dist/i3s-server/routes/index.js +9 -8
- package/dist/i3s-server/routes/slpk-router.js +18 -17
- package/dist/i3s-server/utils/create-scene-server.js +15 -10
- package/dist/i3s-server/utils/server-utils.js +49 -32
- package/dist/index.cjs +292 -851
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/lib/json-schemas/conversion-dump-json-schema.js +243 -421
- package/dist/lib/utils/cli-utils.js +63 -36
- package/dist/lib/utils/compress-util.js +20 -15
- package/dist/lib/utils/conversion-dump.d.ts +1 -1
- package/dist/lib/utils/conversion-dump.d.ts.map +1 -1
- package/dist/lib/utils/conversion-dump.js +209 -187
- package/dist/lib/utils/file-utils.js +122 -74
- package/dist/lib/utils/geometry-utils.js +13 -7
- package/dist/lib/utils/lod-conversion-utils.js +65 -33
- package/dist/lib/utils/queue.js +12 -13
- package/dist/lib/utils/statistic-utills.d.ts +6 -23
- package/dist/lib/utils/statistic-utills.js +64 -59
- package/dist/lib/utils/write-queue.d.ts +2 -2
- package/dist/lib/utils/write-queue.d.ts.map +1 -1
- package/dist/lib/utils/write-queue.js +68 -86
- package/dist/pgm-loader.js +17 -13
- package/dist/slpk-extractor/slpk-extractor.js +59 -50
- package/dist/slpk-extractor-cli.js +82 -59
- package/package.json +18 -18
- package/dist/3d-tiles-converter/3d-tiles-converter.js.map +0 -1
- package/dist/3d-tiles-converter/helpers/b3dm-converter.js.map +0 -1
- package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +0 -1
- package/dist/3d-tiles-converter/helpers/load-i3s.js.map +0 -1
- package/dist/3d-tiles-converter/helpers/texture-atlas.js.map +0 -1
- package/dist/3d-tiles-converter/json-templates/tileset.js.map +0 -1
- package/dist/constants.js.map +0 -1
- package/dist/converter-cli.js.map +0 -1
- package/dist/deps-installer/deps-installer.js.map +0 -1
- package/dist/i3s-converter/helpers/attribute-metadata-info.js.map +0 -1
- package/dist/i3s-converter/helpers/batch-ids-extensions.js.map +0 -1
- package/dist/i3s-converter/helpers/coordinate-converter.js.map +0 -1
- package/dist/i3s-converter/helpers/create-scene-server-path.js.map +0 -1
- package/dist/i3s-converter/helpers/feature-attributes.js.map +0 -1
- package/dist/i3s-converter/helpers/geometry-attributes.js.map +0 -1
- package/dist/i3s-converter/helpers/geometry-converter.js.map +0 -1
- package/dist/i3s-converter/helpers/gltf-attributes.js.map +0 -1
- package/dist/i3s-converter/helpers/load-3d-tiles.js.map +0 -1
- package/dist/i3s-converter/helpers/node-debug.js.map +0 -1
- package/dist/i3s-converter/helpers/node-index-document.js.map +0 -1
- package/dist/i3s-converter/helpers/node-pages.js.map +0 -1
- package/dist/i3s-converter/helpers/preprocess-3d-tiles.js.map +0 -1
- package/dist/i3s-converter/helpers/progress.js.map +0 -1
- package/dist/i3s-converter/helpers/tileset-traversal.js.map +0 -1
- package/dist/i3s-converter/i3s-converter.js.map +0 -1
- package/dist/i3s-converter/json-templates/geometry-definitions.js.map +0 -1
- package/dist/i3s-converter/json-templates/layers.js.map +0 -1
- package/dist/i3s-converter/json-templates/metadata.js.map +0 -1
- package/dist/i3s-converter/json-templates/node.js.map +0 -1
- package/dist/i3s-converter/json-templates/scene-server.js.map +0 -1
- package/dist/i3s-converter/json-templates/shared-resources.js.map +0 -1
- package/dist/i3s-converter/json-templates/store.js.map +0 -1
- package/dist/i3s-converter/types.js.map +0 -1
- package/dist/i3s-server/README.md +0 -63
- package/dist/i3s-server/app.js.map +0 -1
- package/dist/i3s-server/bin/www.js.map +0 -1
- package/dist/i3s-server/certs/cert.pem +0 -19
- package/dist/i3s-server/certs/key.pem +0 -27
- package/dist/i3s-server/controllers/index-controller.js.map +0 -1
- package/dist/i3s-server/controllers/slpk-controller.js.map +0 -1
- package/dist/i3s-server/routes/index.js.map +0 -1
- package/dist/i3s-server/routes/slpk-router.js.map +0 -1
- package/dist/i3s-server/utils/create-scene-server.js.map +0 -1
- package/dist/i3s-server/utils/server-utils.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/json-schemas/conversion-dump-json-schema.js.map +0 -1
- package/dist/lib/utils/cli-utils.js.map +0 -1
- package/dist/lib/utils/compress-util.js.map +0 -1
- package/dist/lib/utils/conversion-dump.js.map +0 -1
- package/dist/lib/utils/file-utils.js.map +0 -1
- package/dist/lib/utils/geometry-utils.js.map +0 -1
- package/dist/lib/utils/lod-conversion-utils.js.map +0 -1
- package/dist/lib/utils/queue.js.map +0 -1
- package/dist/lib/utils/statistic-utills.js.map +0 -1
- package/dist/lib/utils/write-queue.js.map +0 -1
- package/dist/pgm-loader.js.map +0 -1
- package/dist/slpk-extractor/slpk-extractor.js.map +0 -1
- 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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
19
|
-
|
|
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
|
-
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
-
|
|
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
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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
|
-
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|