@loaders.gl/tile-converter 3.2.12 → 3.3.0-alpha.10
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-attributes-worker.d.ts +3 -3
- package/dist/3d-tiles-attributes-worker.d.ts.map +1 -1
- package/dist/3d-tiles-attributes-worker.js +2 -3
- package/dist/3d-tiles-attributes-worker.js.map +3 -3
- package/dist/3d-tiles-converter/3d-tiles-converter.d.ts +8 -0
- package/dist/3d-tiles-converter/3d-tiles-converter.d.ts.map +1 -1
- package/dist/3d-tiles-converter/3d-tiles-converter.js +57 -43
- package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts +5 -5
- package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts.map +1 -1
- package/dist/3d-tiles-converter/helpers/b3dm-converter.js +21 -17
- package/dist/converter-cli.js +43 -8
- package/dist/converter.min.js +24 -21
- package/dist/deps-installer/deps-installer.d.ts +5 -1
- package/dist/deps-installer/deps-installer.d.ts.map +1 -1
- package/dist/deps-installer/deps-installer.js +29 -1
- package/dist/dist.min.js +58405 -61237
- package/dist/es5/3d-tiles-attributes-worker.js +4 -7
- package/dist/es5/3d-tiles-attributes-worker.js.map +1 -1
- package/dist/es5/3d-tiles-converter/3d-tiles-converter.js +125 -210
- package/dist/es5/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
- package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js +53 -85
- package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
- package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +0 -8
- package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +1 -1
- package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js +0 -5
- package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js.map +1 -1
- package/dist/es5/3d-tiles-converter/json-templates/tileset.js +0 -6
- package/dist/es5/3d-tiles-converter/json-templates/tileset.js.map +1 -1
- package/dist/es5/bundle.js +0 -1
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/constants.js.map +1 -1
- package/dist/es5/converter-cli.js +50 -60
- package/dist/es5/converter-cli.js.map +1 -1
- package/dist/es5/deps-installer/deps-installer.js +73 -28
- package/dist/es5/deps-installer/deps-installer.js.map +1 -1
- package/dist/es5/i3s-attributes-worker.js +3 -6
- package/dist/es5/i3s-attributes-worker.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js +124 -0
- package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js.map +1 -0
- package/dist/es5/i3s-converter/helpers/coordinate-converter.js +2 -19
- package/dist/es5/i3s-converter/helpers/coordinate-converter.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/create-scene-server-path.js +0 -11
- package/dist/es5/i3s-converter/helpers/create-scene-server-path.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/feature-attributes.js +184 -0
- package/dist/es5/i3s-converter/helpers/feature-attributes.js.map +1 -0
- package/dist/es5/i3s-converter/helpers/geometry-attributes.js +60 -51
- package/dist/es5/i3s-converter/helpers/geometry-attributes.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/geometry-converter.js +516 -356
- package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/gltf-attributes.js +57 -43
- package/dist/es5/i3s-converter/helpers/gltf-attributes.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/node-debug.js +4 -23
- package/dist/es5/i3s-converter/helpers/node-debug.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/node-index-document.js +507 -0
- package/dist/es5/i3s-converter/helpers/node-index-document.js.map +1 -0
- package/dist/es5/i3s-converter/helpers/node-pages.js +462 -208
- package/dist/es5/i3s-converter/helpers/node-pages.js.map +1 -1
- package/dist/es5/i3s-converter/i3s-converter.js +722 -1153
- package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/geometry-definitions.js +107 -0
- package/dist/es5/i3s-converter/json-templates/geometry-definitions.js.map +1 -0
- package/dist/es5/i3s-converter/json-templates/layers.js +2 -107
- package/dist/es5/i3s-converter/json-templates/layers.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/metadata.js +0 -2
- package/dist/es5/i3s-converter/json-templates/metadata.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/node.js +2 -12
- package/dist/es5/i3s-converter/json-templates/node.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/scene-server.js +0 -2
- package/dist/es5/i3s-converter/json-templates/scene-server.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/shared-resources.js +9 -32
- package/dist/es5/i3s-converter/json-templates/shared-resources.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/store.js.map +1 -1
- package/dist/es5/i3s-converter/types.js.map +1 -1
- package/dist/es5/i3s-server/app.js +0 -5
- package/dist/es5/i3s-server/app.js.map +1 -1
- package/dist/es5/i3s-server/controllers/index-controller.js +0 -16
- package/dist/es5/i3s-server/controllers/index-controller.js.map +1 -1
- package/dist/es5/i3s-server/routes/index.js +1 -10
- package/dist/es5/i3s-server/routes/index.js.map +1 -1
- package/dist/es5/index.js +0 -3
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/utils/compress-util.js +19 -74
- package/dist/es5/lib/utils/compress-util.js.map +1 -1
- package/dist/es5/lib/utils/file-utils.js +103 -47
- package/dist/es5/lib/utils/file-utils.js.map +1 -1
- package/dist/es5/lib/utils/lod-conversion-utils.js +0 -7
- package/dist/es5/lib/utils/lod-conversion-utils.js.map +1 -1
- package/dist/es5/lib/utils/queue.js +0 -14
- package/dist/es5/lib/utils/queue.js.map +1 -1
- package/dist/es5/lib/utils/statistic-utills.js +1 -46
- package/dist/es5/lib/utils/statistic-utills.js.map +1 -1
- package/dist/es5/lib/utils/write-queue.js +41 -82
- package/dist/es5/lib/utils/write-queue.js.map +1 -1
- package/dist/es5/pgm-loader.js +1 -8
- package/dist/es5/pgm-loader.js.map +1 -1
- package/dist/es5/workers/3d-tiles-attributes-worker.js +2 -9
- package/dist/es5/workers/3d-tiles-attributes-worker.js.map +1 -1
- package/dist/es5/workers/i3s-attributes-worker.js +2 -10
- package/dist/es5/workers/i3s-attributes-worker.js.map +1 -1
- package/dist/esm/3d-tiles-attributes-worker.js +4 -2
- package/dist/esm/3d-tiles-attributes-worker.js.map +1 -1
- package/dist/esm/3d-tiles-converter/3d-tiles-converter.js +60 -77
- package/dist/esm/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
- package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js +29 -50
- package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
- package/dist/esm/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +1 -0
- package/dist/esm/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +1 -1
- package/dist/esm/3d-tiles-converter/helpers/texture-atlas.js +1 -4
- package/dist/esm/3d-tiles-converter/helpers/texture-atlas.js.map +1 -1
- package/dist/esm/3d-tiles-converter/json-templates/tileset.js +0 -3
- package/dist/esm/3d-tiles-converter/json-templates/tileset.js.map +1 -1
- package/dist/esm/bundle.js +1 -1
- package/dist/esm/bundle.js.map +1 -1
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/converter-cli.js +46 -40
- package/dist/esm/converter-cli.js.map +1 -1
- package/dist/esm/deps-installer/deps-installer.js +30 -4
- package/dist/esm/deps-installer/deps-installer.js.map +1 -1
- package/dist/esm/i3s-attributes-worker.js +3 -1
- package/dist/esm/i3s-attributes-worker.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js +113 -0
- package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js.map +1 -0
- package/dist/esm/i3s-converter/helpers/coordinate-converter.js +5 -6
- package/dist/esm/i3s-converter/helpers/coordinate-converter.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/create-scene-server-path.js +1 -0
- package/dist/esm/i3s-converter/helpers/create-scene-server-path.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/feature-attributes.js +158 -0
- package/dist/esm/i3s-converter/helpers/feature-attributes.js.map +1 -0
- package/dist/esm/i3s-converter/helpers/geometry-attributes.js +39 -33
- package/dist/esm/i3s-converter/helpers/geometry-attributes.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/geometry-converter.js +295 -196
- package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/gltf-attributes.js +59 -34
- package/dist/esm/i3s-converter/helpers/gltf-attributes.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/node-debug.js +3 -13
- package/dist/esm/i3s-converter/helpers/node-debug.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/node-index-document.js +197 -0
- package/dist/esm/i3s-converter/helpers/node-index-document.js.map +1 -0
- package/dist/esm/i3s-converter/helpers/node-pages.js +161 -87
- package/dist/esm/i3s-converter/helpers/node-pages.js.map +1 -1
- package/dist/esm/i3s-converter/i3s-converter.js +216 -491
- package/dist/esm/i3s-converter/i3s-converter.js.map +1 -1
- package/dist/esm/i3s-converter/json-templates/geometry-definitions.js +89 -0
- package/dist/esm/i3s-converter/json-templates/geometry-definitions.js.map +1 -0
- package/dist/esm/i3s-converter/json-templates/layers.js +2 -95
- package/dist/esm/i3s-converter/json-templates/layers.js.map +1 -1
- package/dist/esm/i3s-converter/json-templates/metadata.js.map +1 -1
- package/dist/esm/i3s-converter/json-templates/node.js +0 -4
- package/dist/esm/i3s-converter/json-templates/node.js.map +1 -1
- package/dist/esm/i3s-converter/json-templates/scene-server.js.map +1 -1
- package/dist/esm/i3s-converter/json-templates/shared-resources.js +3 -15
- package/dist/esm/i3s-converter/json-templates/shared-resources.js.map +1 -1
- package/dist/esm/i3s-converter/json-templates/store.js.map +1 -1
- package/dist/esm/i3s-converter/types.js.map +1 -1
- package/dist/esm/i3s-server/app.js +0 -5
- package/dist/esm/i3s-server/app.js.map +1 -1
- package/dist/esm/i3s-server/controllers/index-controller.js +0 -5
- package/dist/esm/i3s-server/controllers/index-controller.js.map +1 -1
- package/dist/esm/i3s-server/routes/index.js +0 -3
- package/dist/esm/i3s-server/routes/index.js.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/utils/compress-util.js +19 -12
- package/dist/esm/lib/utils/compress-util.js.map +1 -1
- package/dist/esm/lib/utils/file-utils.js +54 -11
- package/dist/esm/lib/utils/file-utils.js.map +1 -1
- package/dist/esm/lib/utils/lod-conversion-utils.js +2 -6
- package/dist/esm/lib/utils/lod-conversion-utils.js.map +1 -1
- package/dist/esm/lib/utils/queue.js +0 -4
- package/dist/esm/lib/utils/queue.js.map +1 -1
- package/dist/esm/lib/utils/statistic-utills.js +0 -11
- package/dist/esm/lib/utils/statistic-utills.js.map +1 -1
- package/dist/esm/lib/utils/write-queue.js +27 -38
- package/dist/esm/lib/utils/write-queue.js.map +1 -1
- package/dist/esm/pgm-loader.js +3 -1
- package/dist/esm/pgm-loader.js.map +1 -1
- package/dist/esm/workers/3d-tiles-attributes-worker.js +4 -1
- package/dist/esm/workers/3d-tiles-attributes-worker.js.map +1 -1
- package/dist/esm/workers/i3s-attributes-worker.js +4 -1
- package/dist/esm/workers/i3s-attributes-worker.js.map +1 -1
- package/dist/i3s-attributes-worker.d.ts +7 -3
- package/dist/i3s-attributes-worker.d.ts.map +1 -1
- package/dist/i3s-attributes-worker.js +2 -3
- package/dist/i3s-attributes-worker.js.map +3 -3
- package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts +11 -0
- package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts.map +1 -0
- package/dist/i3s-converter/helpers/batch-ids-extensions.js +141 -0
- package/dist/i3s-converter/helpers/coordinate-converter.d.ts +2 -2
- package/dist/i3s-converter/helpers/coordinate-converter.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/feature-attributes.d.ts +56 -0
- package/dist/i3s-converter/helpers/feature-attributes.d.ts.map +1 -0
- package/dist/i3s-converter/helpers/feature-attributes.js +216 -0
- package/dist/i3s-converter/helpers/geometry-attributes.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/geometry-attributes.js +42 -17
- package/dist/i3s-converter/helpers/geometry-converter.d.ts +18 -6
- package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/geometry-converter.js +349 -99
- package/dist/i3s-converter/helpers/gltf-attributes.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/gltf-attributes.js +53 -21
- package/dist/i3s-converter/helpers/node-index-document.d.ts +91 -0
- package/dist/i3s-converter/helpers/node-index-document.d.ts.map +1 -0
- package/dist/i3s-converter/helpers/node-index-document.js +242 -0
- package/dist/i3s-converter/helpers/node-pages.d.ts +81 -42
- package/dist/i3s-converter/helpers/node-pages.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/node-pages.js +200 -92
- package/dist/i3s-converter/i3s-converter.d.ts +52 -108
- package/dist/i3s-converter/i3s-converter.d.ts.map +1 -1
- package/dist/i3s-converter/i3s-converter.js +218 -403
- package/dist/i3s-converter/json-templates/geometry-definitions.d.ts +7 -0
- package/dist/i3s-converter/json-templates/geometry-definitions.d.ts.map +1 -0
- package/dist/i3s-converter/json-templates/geometry-definitions.js +87 -0
- package/dist/i3s-converter/json-templates/layers.d.ts +1 -30
- package/dist/i3s-converter/json-templates/layers.d.ts.map +1 -1
- package/dist/i3s-converter/json-templates/layers.js +2 -86
- package/dist/i3s-converter/json-templates/shared-resources.js +3 -3
- package/dist/i3s-converter/types.d.ts +38 -8
- package/dist/i3s-converter/types.d.ts.map +1 -1
- package/dist/lib/utils/file-utils.d.ts +17 -1
- package/dist/lib/utils/file-utils.d.ts.map +1 -1
- package/dist/lib/utils/file-utils.js +64 -7
- package/dist/lib/utils/write-queue.d.ts +19 -3
- package/dist/lib/utils/write-queue.d.ts.map +1 -1
- package/dist/lib/utils/write-queue.js +21 -16
- package/dist/pgm-loader.d.ts.map +1 -1
- package/dist/pgm-loader.js +2 -1
- package/dist/workers/3d-tiles-attributes-worker.js +1 -1
- package/dist/workers/i3s-attributes-worker.js +1 -1
- package/package.json +18 -16
- package/src/3d-tiles-attributes-worker.ts +1 -1
- package/src/3d-tiles-converter/3d-tiles-converter.ts +71 -55
- package/src/3d-tiles-converter/helpers/b3dm-converter.ts +25 -18
- package/src/converter-cli.ts +54 -8
- package/src/deps-installer/deps-installer.ts +38 -2
- package/src/i3s-attributes-worker.ts +5 -1
- package/src/i3s-converter/helpers/batch-ids-extensions.ts +206 -0
- package/src/i3s-converter/helpers/coordinate-converter.ts +2 -2
- package/src/i3s-converter/helpers/feature-attributes.ts +247 -0
- package/src/i3s-converter/helpers/geometry-attributes.ts +46 -18
- package/src/i3s-converter/helpers/geometry-converter.ts +423 -111
- package/src/i3s-converter/helpers/gltf-attributes.ts +59 -24
- package/src/i3s-converter/helpers/node-index-document.ts +306 -0
- package/src/i3s-converter/helpers/node-pages.ts +222 -109
- package/src/i3s-converter/i3s-converter.ts +264 -487
- package/src/i3s-converter/json-templates/geometry-definitions.ts +83 -0
- package/src/i3s-converter/json-templates/layers.ts +2 -91
- package/src/i3s-converter/json-templates/shared-resources.ts +3 -3
- package/src/i3s-converter/types.ts +33 -2
- package/src/lib/utils/file-utils.ts +62 -7
- package/src/lib/utils/write-queue.ts +42 -19
- package/src/pgm-loader.ts +2 -2
- package/src/workers/3d-tiles-attributes-worker.ts +1 -1
- package/src/workers/i3s-attributes-worker.ts +2 -1
|
@@ -4,9 +4,13 @@ import { DracoWriterWorker } from '@loaders.gl/draco';
|
|
|
4
4
|
import { assert, encode } from '@loaders.gl/core';
|
|
5
5
|
import { concatenateArrayBuffers, concatenateTypedArrays } from '@loaders.gl/loader-utils';
|
|
6
6
|
import md5 from 'md5';
|
|
7
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
7
8
|
import { generateAttributes } from './geometry-attributes';
|
|
8
9
|
import { createBoundingVolumesFromGeometry } from './coordinate-converter';
|
|
9
10
|
import { prepareDataForAttributesConversion } from './gltf-attributes';
|
|
11
|
+
import { handleBatchIdsExtensions } from './batch-ids-extensions';
|
|
12
|
+
import { checkPropertiesLength, flattenPropertyTableByFeatureIds } from './feature-attributes';
|
|
13
|
+
|
|
10
14
|
const DEFAULT_ROUGHNESS_FACTOR = 1;
|
|
11
15
|
const DEFAULT_METALLIC_FACTOR = 1;
|
|
12
16
|
const VALUES_PER_VERTEX = 3;
|
|
@@ -17,74 +21,52 @@ const SHORT_INT_TYPE = 'Int32';
|
|
|
17
21
|
const DOUBLE_TYPE = 'Float64';
|
|
18
22
|
const OBJECT_ID_TYPE = 'Oid32';
|
|
19
23
|
const BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES = ['CUSTOM_ATTRIBUTE_2', '_BATCHID', 'BATCHID'];
|
|
24
|
+
const EXT_FEATURE_METADATA = 'EXT_feature_metadata';
|
|
25
|
+
const EXT_MESH_FEATURES = 'EXT_mesh_features';
|
|
20
26
|
let scratchVector = new Vector3();
|
|
21
|
-
export default async function convertB3dmToI3sGeometry(tileContent, nodeId, featuresHashArray, attributeStorageInfo, draco, generateBoundingVolumes, geoidHeightModel, workerSource) {
|
|
22
|
-
var _tileContent$gltf;
|
|
23
27
|
|
|
28
|
+
export default async function convertB3dmToI3sGeometry(tileContent, addNodeToNodePage, propertyTable, featuresHashArray, attributeStorageInfo, draco, generateBoundingVolumes, shouldMergeMaterials, geoidHeightModel, workerSource) {
|
|
29
|
+
var _tileContent$gltf;
|
|
24
30
|
const useCartesianPositions = generateBoundingVolumes;
|
|
25
|
-
const materialAndTextureList = convertMaterials((_tileContent$gltf = tileContent.gltf) === null || _tileContent$gltf === void 0 ? void 0 : _tileContent$gltf.materials);
|
|
31
|
+
const materialAndTextureList = await convertMaterials((_tileContent$gltf = tileContent.gltf) === null || _tileContent$gltf === void 0 ? void 0 : _tileContent$gltf.materials, shouldMergeMaterials);
|
|
26
32
|
const dataForAttributesConversion = prepareDataForAttributesConversion(tileContent);
|
|
27
|
-
const convertedAttributesMap = await convertAttributes(dataForAttributesConversion, useCartesianPositions);
|
|
33
|
+
const convertedAttributesMap = await convertAttributes(dataForAttributesConversion, materialAndTextureList, useCartesianPositions);
|
|
28
34
|
|
|
29
35
|
if (generateBoundingVolumes) {
|
|
30
36
|
_generateBoundingVolumesFromGeometry(convertedAttributesMap, geoidHeightModel);
|
|
31
37
|
}
|
|
32
|
-
|
|
33
|
-
if (convertedAttributesMap.has('default')) {
|
|
34
|
-
materialAndTextureList.push({
|
|
35
|
-
material: getDefaultMaterial()
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
|
|
39
38
|
const result = [];
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
} = tileContent.gltf || {
|
|
44
|
-
materials: []
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
if (!(materials !== null && materials !== void 0 && materials.length)) {
|
|
48
|
-
materials.push({
|
|
49
|
-
id: 'default'
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
for (let i = 0; i < materials.length; i++) {
|
|
54
|
-
const sourceMaterial = materials[i];
|
|
55
|
-
|
|
56
|
-
if (!convertedAttributesMap.has(sourceMaterial.id)) {
|
|
39
|
+
for (const materialAndTexture of materialAndTextureList) {
|
|
40
|
+
const originarMaterialId = materialAndTexture.mergedMaterials[0].originalMaterialId;
|
|
41
|
+
if (!convertedAttributesMap.has(originarMaterialId)) {
|
|
57
42
|
continue;
|
|
58
43
|
}
|
|
59
44
|
|
|
60
|
-
const convertedAttributes = convertedAttributesMap.get(
|
|
61
|
-
|
|
45
|
+
const convertedAttributes = convertedAttributesMap.get(originarMaterialId);
|
|
62
46
|
if (!convertedAttributes) {
|
|
63
47
|
continue;
|
|
64
48
|
}
|
|
65
|
-
|
|
66
49
|
const {
|
|
67
50
|
material,
|
|
68
51
|
texture
|
|
69
|
-
} =
|
|
52
|
+
} = materialAndTexture;
|
|
53
|
+
const nodeId = await addNodeToNodePage();
|
|
70
54
|
result.push(await _makeNodeResources({
|
|
71
55
|
convertedAttributes,
|
|
72
56
|
material,
|
|
73
57
|
texture,
|
|
74
58
|
tileContent,
|
|
75
|
-
nodeId
|
|
59
|
+
nodeId,
|
|
76
60
|
featuresHashArray,
|
|
61
|
+
propertyTable,
|
|
77
62
|
attributeStorageInfo,
|
|
78
63
|
draco,
|
|
79
64
|
workerSource
|
|
80
65
|
}));
|
|
81
|
-
nodesCounter++;
|
|
82
66
|
}
|
|
83
|
-
|
|
84
67
|
if (!result.length) {
|
|
85
68
|
return null;
|
|
86
69
|
}
|
|
87
|
-
|
|
88
70
|
return result;
|
|
89
71
|
}
|
|
90
72
|
|
|
@@ -93,7 +75,6 @@ function _generateBoundingVolumesFromGeometry(convertedAttributesMap, geoidHeigh
|
|
|
93
75
|
const boundingVolumes = createBoundingVolumesFromGeometry(attributes.positions, geoidHeightModel);
|
|
94
76
|
attributes.boundingVolumes = boundingVolumes;
|
|
95
77
|
const cartographicOrigin = boundingVolumes.obb.center;
|
|
96
|
-
|
|
97
78
|
for (let index = 0; index < attributes.positions.length; index += VALUES_PER_VERTEX) {
|
|
98
79
|
const vertex = attributes.positions.subarray(index, index + VALUES_PER_VERTEX);
|
|
99
80
|
Ellipsoid.WGS84.cartesianToCartographic(Array.from(vertex), scratchVector);
|
|
@@ -104,19 +85,20 @@ function _generateBoundingVolumesFromGeometry(convertedAttributesMap, geoidHeigh
|
|
|
104
85
|
}
|
|
105
86
|
}
|
|
106
87
|
|
|
107
|
-
async function _makeNodeResources({
|
|
108
|
-
convertedAttributes,
|
|
109
|
-
material,
|
|
110
|
-
texture,
|
|
111
|
-
tileContent,
|
|
112
|
-
nodeId,
|
|
113
|
-
featuresHashArray,
|
|
114
|
-
attributeStorageInfo,
|
|
115
|
-
draco,
|
|
116
|
-
workerSource
|
|
117
|
-
}) {
|
|
88
|
+
async function _makeNodeResources(_ref) {
|
|
118
89
|
var _tileContent$gltf2;
|
|
119
|
-
|
|
90
|
+
let {
|
|
91
|
+
convertedAttributes,
|
|
92
|
+
material,
|
|
93
|
+
texture,
|
|
94
|
+
tileContent,
|
|
95
|
+
nodeId,
|
|
96
|
+
featuresHashArray,
|
|
97
|
+
propertyTable,
|
|
98
|
+
attributeStorageInfo,
|
|
99
|
+
draco,
|
|
100
|
+
workerSource
|
|
101
|
+
} = _ref;
|
|
120
102
|
const boundingVolumes = convertedAttributes.boundingVolumes;
|
|
121
103
|
const vertexCount = convertedAttributes.positions.length / VALUES_PER_VERTEX;
|
|
122
104
|
const {
|
|
@@ -125,31 +107,36 @@ async function _makeNodeResources({
|
|
|
125
107
|
positions,
|
|
126
108
|
normals,
|
|
127
109
|
colors,
|
|
110
|
+
uvRegions,
|
|
128
111
|
texCoords,
|
|
129
112
|
featureCount
|
|
130
113
|
} = generateAttributes(convertedAttributes);
|
|
131
|
-
|
|
132
114
|
if (tileContent.batchTableJson) {
|
|
133
115
|
makeFeatureIdsUnique(featureIds, convertedAttributes.featureIndices, featuresHashArray, tileContent.batchTableJson);
|
|
134
116
|
}
|
|
135
|
-
|
|
136
117
|
const header = new Uint32Array(2);
|
|
137
118
|
const typedFeatureIds = generateBigUint64Array(featureIds);
|
|
138
119
|
header.set([vertexCount, featureCount], 0);
|
|
139
|
-
const fileBuffer = new Uint8Array(concatenateArrayBuffers(header.buffer, positions.buffer, normals.buffer, texture ? texCoords.buffer : new ArrayBuffer(0), colors.buffer, typedFeatureIds.buffer, faceRange.buffer));
|
|
120
|
+
const fileBuffer = new Uint8Array(concatenateArrayBuffers(header.buffer, positions.buffer, normals.buffer, texture ? texCoords.buffer : new ArrayBuffer(0), colors.buffer, uvRegions, typedFeatureIds.buffer, faceRange.buffer));
|
|
140
121
|
const compressedGeometry = draco ? generateCompressedGeometry(vertexCount, convertedAttributes, {
|
|
141
122
|
positions,
|
|
142
123
|
normals,
|
|
143
124
|
texCoords: texture ? texCoords : new Float32Array(0),
|
|
144
125
|
colors,
|
|
126
|
+
uvRegions,
|
|
145
127
|
featureIds,
|
|
146
128
|
faceRange
|
|
147
129
|
}, workerSource.draco) : null;
|
|
148
|
-
|
|
130
|
+
let attributes = [];
|
|
131
|
+
if (attributeStorageInfo && propertyTable) {
|
|
132
|
+
attributes = convertPropertyTableToAttributeBuffers(featureIds, propertyTable, attributeStorageInfo);
|
|
133
|
+
}
|
|
149
134
|
return {
|
|
135
|
+
nodeId,
|
|
150
136
|
geometry: fileBuffer,
|
|
151
137
|
compressedGeometry,
|
|
152
138
|
texture,
|
|
139
|
+
hasUvRegions: Boolean(uvRegions.length),
|
|
153
140
|
sharedResources: getSharedResources(((_tileContent$gltf2 = tileContent.gltf) === null || _tileContent$gltf2 === void 0 ? void 0 : _tileContent$gltf2.materials) || [], nodeId),
|
|
154
141
|
meshMaterial: material,
|
|
155
142
|
vertexCount,
|
|
@@ -159,38 +146,36 @@ async function _makeNodeResources({
|
|
|
159
146
|
};
|
|
160
147
|
}
|
|
161
148
|
|
|
162
|
-
export async function convertAttributes(attributesData, useCartesianPositions) {
|
|
149
|
+
export async function convertAttributes(attributesData, materialAndTextureList, useCartesianPositions) {
|
|
163
150
|
const {
|
|
164
|
-
gltfMaterials,
|
|
165
151
|
nodes,
|
|
152
|
+
images,
|
|
166
153
|
cartographicOrigin,
|
|
167
154
|
cartesianModelMatrix
|
|
168
155
|
} = attributesData;
|
|
169
156
|
const attributesMap = new Map();
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
id: 'default'
|
|
173
|
-
}]) {
|
|
174
|
-
attributesMap.set(material.id, {
|
|
157
|
+
for (const materialAndTexture of materialAndTextureList) {
|
|
158
|
+
const attributes = {
|
|
175
159
|
positions: new Float32Array(0),
|
|
176
160
|
normals: new Float32Array(0),
|
|
177
161
|
texCoords: new Float32Array(0),
|
|
178
162
|
colors: new Uint8Array(0),
|
|
163
|
+
uvRegions: new Uint16Array(0),
|
|
179
164
|
featureIndicesGroups: [],
|
|
180
165
|
featureIndices: [],
|
|
181
|
-
boundingVolumes: null
|
|
182
|
-
|
|
166
|
+
boundingVolumes: null,
|
|
167
|
+
mergedMaterials: materialAndTexture.mergedMaterials
|
|
168
|
+
};
|
|
169
|
+
for (const mergedMaterial of materialAndTexture.mergedMaterials) {
|
|
170
|
+
attributesMap.set(mergedMaterial.originalMaterialId, attributes);
|
|
171
|
+
}
|
|
183
172
|
}
|
|
184
|
-
|
|
185
|
-
convertNodes(nodes, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions);
|
|
186
|
-
|
|
173
|
+
convertNodes(nodes, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions);
|
|
187
174
|
for (const attrKey of attributesMap.keys()) {
|
|
188
175
|
const attributes = attributesMap.get(attrKey);
|
|
189
|
-
|
|
190
176
|
if (!attributes) {
|
|
191
177
|
continue;
|
|
192
178
|
}
|
|
193
|
-
|
|
194
179
|
if (attributes.positions.length === 0) {
|
|
195
180
|
attributesMap.delete(attrKey);
|
|
196
181
|
continue;
|
|
@@ -201,14 +186,14 @@ export async function convertAttributes(attributesData, useCartesianPositions) {
|
|
|
201
186
|
delete attributes.featureIndicesGroups;
|
|
202
187
|
}
|
|
203
188
|
}
|
|
204
|
-
|
|
205
189
|
return attributesMap;
|
|
206
190
|
}
|
|
207
191
|
|
|
208
|
-
function convertNodes(nodes, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions
|
|
192
|
+
function convertNodes(nodes, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions) {
|
|
193
|
+
let matrix = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
|
|
209
194
|
if (nodes) {
|
|
210
195
|
for (const node of nodes) {
|
|
211
|
-
convertNode(node, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, matrix);
|
|
196
|
+
convertNode(node, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, matrix);
|
|
212
197
|
}
|
|
213
198
|
}
|
|
214
199
|
}
|
|
@@ -221,56 +206,56 @@ function getCompositeTransformationMatrix(node, matrix) {
|
|
|
221
206
|
scale,
|
|
222
207
|
translation
|
|
223
208
|
} = node;
|
|
224
|
-
|
|
225
209
|
if (nodeMatrix) {
|
|
226
210
|
transformationMatrix = matrix.multiplyRight(nodeMatrix);
|
|
227
211
|
}
|
|
228
|
-
|
|
229
212
|
if (translation) {
|
|
230
213
|
transformationMatrix = transformationMatrix.translate(translation);
|
|
231
214
|
}
|
|
232
|
-
|
|
233
215
|
if (rotation) {
|
|
234
216
|
transformationMatrix = transformationMatrix.rotateXYZ(rotation);
|
|
235
217
|
}
|
|
236
|
-
|
|
237
218
|
if (scale) {
|
|
238
219
|
transformationMatrix = transformationMatrix.scale(scale);
|
|
239
220
|
}
|
|
240
|
-
|
|
241
221
|
return transformationMatrix;
|
|
242
222
|
}
|
|
243
223
|
|
|
244
|
-
function convertNode(node, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions
|
|
224
|
+
function convertNode(node, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions) {
|
|
225
|
+
let matrix = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
|
|
245
226
|
const transformationMatrix = getCompositeTransformationMatrix(node, matrix);
|
|
246
227
|
const mesh = node.mesh;
|
|
247
|
-
|
|
248
228
|
if (mesh) {
|
|
249
|
-
convertMesh(mesh, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, transformationMatrix);
|
|
229
|
+
convertMesh(mesh, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, transformationMatrix);
|
|
250
230
|
}
|
|
251
|
-
|
|
252
|
-
convertNodes(node.children || [], cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, transformationMatrix);
|
|
231
|
+
convertNodes(node.children || [], images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, transformationMatrix);
|
|
253
232
|
}
|
|
254
233
|
|
|
255
|
-
function convertMesh(mesh, cartographicOrigin, cartesianModelMatrix, attributesMap
|
|
234
|
+
function convertMesh(mesh, images, cartographicOrigin, cartesianModelMatrix, attributesMap) {
|
|
235
|
+
let useCartesianPositions = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
|
|
236
|
+
let matrix = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
|
|
256
237
|
for (const primitive of mesh.primitives) {
|
|
257
|
-
var _primitive$indices, _primitive$indices2, _primitive$indices3, _primitive$indices4, _primitive$
|
|
258
|
-
|
|
238
|
+
var _primitive$indices, _primitive$indices2, _primitive$indices3, _primitive$indices4, _primitive$indices6;
|
|
259
239
|
let outputAttributes = null;
|
|
260
|
-
|
|
240
|
+
let materialUvRegion;
|
|
261
241
|
if (primitive.material) {
|
|
262
|
-
|
|
242
|
+
var _outputAttributes, _outputAttributes$mer;
|
|
243
|
+
outputAttributes = attributesMap.get(primitive.material.uniqueId);
|
|
244
|
+
materialUvRegion = (_outputAttributes = outputAttributes) === null || _outputAttributes === void 0 ? void 0 : (_outputAttributes$mer = _outputAttributes.mergedMaterials.find(_ref2 => {
|
|
245
|
+
var _primitive$material;
|
|
246
|
+
let {
|
|
247
|
+
originalMaterialId
|
|
248
|
+
} = _ref2;
|
|
249
|
+
return originalMaterialId === ((_primitive$material = primitive.material) === null || _primitive$material === void 0 ? void 0 : _primitive$material.uniqueId);
|
|
250
|
+
})) === null || _outputAttributes$mer === void 0 ? void 0 : _outputAttributes$mer.uvRegion;
|
|
263
251
|
} else if (attributesMap.has('default')) {
|
|
264
252
|
outputAttributes = attributesMap.get('default');
|
|
265
253
|
}
|
|
266
|
-
|
|
267
254
|
assert(outputAttributes !== null, 'Primitive - material mapping failed');
|
|
268
255
|
const attributes = primitive.attributes;
|
|
269
|
-
|
|
270
256
|
if (!outputAttributes) {
|
|
271
257
|
continue;
|
|
272
258
|
}
|
|
273
|
-
|
|
274
259
|
outputAttributes.positions = concatenateTypedArrays(outputAttributes.positions, transformVertexArray({
|
|
275
260
|
vertices: attributes.POSITION.value,
|
|
276
261
|
cartographicOrigin,
|
|
@@ -291,8 +276,12 @@ function convertMesh(mesh, cartographicOrigin, cartesianModelMatrix, attributesM
|
|
|
291
276
|
}));
|
|
292
277
|
outputAttributes.texCoords = concatenateTypedArrays(outputAttributes.texCoords, flattenTexCoords(attributes.TEXCOORD_0 && attributes.TEXCOORD_0.value, (_primitive$indices3 = primitive.indices) === null || _primitive$indices3 === void 0 ? void 0 : _primitive$indices3.value));
|
|
293
278
|
outputAttributes.colors = concatenateTypedArrays(outputAttributes.colors, flattenColors(attributes.COLOR_0, (_primitive$indices4 = primitive.indices) === null || _primitive$indices4 === void 0 ? void 0 : _primitive$indices4.value));
|
|
279
|
+
if (materialUvRegion) {
|
|
280
|
+
var _primitive$indices5;
|
|
281
|
+
outputAttributes.uvRegions = concatenateTypedArrays(outputAttributes.uvRegions, createUvRegion(materialUvRegion, (_primitive$indices5 = primitive.indices) === null || _primitive$indices5 === void 0 ? void 0 : _primitive$indices5.value));
|
|
282
|
+
}
|
|
294
283
|
outputAttributes.featureIndicesGroups = outputAttributes.featureIndicesGroups || [];
|
|
295
|
-
outputAttributes.featureIndicesGroups.push(flattenBatchIds(
|
|
284
|
+
outputAttributes.featureIndicesGroups.push(flattenBatchIds(getBatchIds(attributes, primitive, images), (_primitive$indices6 = primitive.indices) === null || _primitive$indices6 === void 0 ? void 0 : _primitive$indices6.value));
|
|
296
285
|
}
|
|
297
286
|
}
|
|
298
287
|
|
|
@@ -303,11 +292,9 @@ function transformVertexArray(args) {
|
|
|
303
292
|
attributeSpecificTransformation
|
|
304
293
|
} = args;
|
|
305
294
|
const newVertices = new Float32Array(indices.length * VALUES_PER_VERTEX);
|
|
306
|
-
|
|
307
295
|
if (!vertices) {
|
|
308
296
|
return newVertices;
|
|
309
297
|
}
|
|
310
|
-
|
|
311
298
|
for (let i = 0; i < indices.length; i++) {
|
|
312
299
|
const coordIndex = indices[i] * VALUES_PER_VERTEX;
|
|
313
300
|
const vertex = vertices.subarray(coordIndex, coordIndex + VALUES_PER_VERTEX);
|
|
@@ -317,7 +304,6 @@ function transformVertexArray(args) {
|
|
|
317
304
|
newVertices[i * VALUES_PER_VERTEX + 1] = vertexVector.y;
|
|
318
305
|
newVertices[i * VALUES_PER_VERTEX + 2] = vertexVector.z;
|
|
319
306
|
}
|
|
320
|
-
|
|
321
307
|
return newVertices;
|
|
322
308
|
}
|
|
323
309
|
|
|
@@ -328,17 +314,13 @@ function transformVertexPositions(vertexVector, calleeArgs) {
|
|
|
328
314
|
nodeMatrix,
|
|
329
315
|
useCartesianPositions
|
|
330
316
|
} = calleeArgs;
|
|
331
|
-
|
|
332
317
|
if (nodeMatrix) {
|
|
333
318
|
vertexVector = vertexVector.transform(nodeMatrix);
|
|
334
319
|
}
|
|
335
|
-
|
|
336
320
|
vertexVector = vertexVector.transform(cartesianModelMatrix);
|
|
337
|
-
|
|
338
321
|
if (useCartesianPositions) {
|
|
339
322
|
return vertexVector;
|
|
340
323
|
}
|
|
341
|
-
|
|
342
324
|
Ellipsoid.WGS84.cartesianToCartographic([vertexVector[0], vertexVector[1], vertexVector[2]], vertexVector);
|
|
343
325
|
vertexVector = vertexVector.subtract(cartographicOrigin);
|
|
344
326
|
return vertexVector;
|
|
@@ -349,102 +331,168 @@ function transformVertexNormals(vertexVector, calleeArgs) {
|
|
|
349
331
|
cartesianModelMatrix,
|
|
350
332
|
nodeMatrix
|
|
351
333
|
} = calleeArgs;
|
|
352
|
-
|
|
353
334
|
if (nodeMatrix) {
|
|
354
335
|
vertexVector = vertexVector.transformAsVector(nodeMatrix);
|
|
355
336
|
}
|
|
356
|
-
|
|
357
337
|
vertexVector = vertexVector.transformAsVector(cartesianModelMatrix);
|
|
358
338
|
return vertexVector;
|
|
359
339
|
}
|
|
360
340
|
|
|
361
341
|
function flattenTexCoords(texCoords, indices) {
|
|
362
342
|
const newTexCoords = new Float32Array(indices.length * VALUES_PER_TEX_COORD);
|
|
363
|
-
|
|
364
343
|
if (!texCoords) {
|
|
365
344
|
newTexCoords.fill(1);
|
|
366
345
|
return newTexCoords;
|
|
367
346
|
}
|
|
368
|
-
|
|
369
347
|
for (let i = 0; i < indices.length; i++) {
|
|
370
348
|
const coordIndex = indices[i] * VALUES_PER_TEX_COORD;
|
|
371
349
|
const texCoord = texCoords.subarray(coordIndex, coordIndex + VALUES_PER_TEX_COORD);
|
|
372
350
|
newTexCoords[i * VALUES_PER_TEX_COORD] = texCoord[0];
|
|
373
351
|
newTexCoords[i * VALUES_PER_TEX_COORD + 1] = texCoord[1];
|
|
374
352
|
}
|
|
375
|
-
|
|
376
353
|
return newTexCoords;
|
|
377
354
|
}
|
|
378
355
|
|
|
379
356
|
function flattenColors(colorsAttribute, indices) {
|
|
380
357
|
const components = (colorsAttribute === null || colorsAttribute === void 0 ? void 0 : colorsAttribute.components) || VALUES_PER_COLOR_ELEMENT;
|
|
381
358
|
const newColors = new Uint8Array(indices.length * components);
|
|
382
|
-
|
|
383
359
|
if (!colorsAttribute) {
|
|
384
360
|
newColors.fill(255);
|
|
385
361
|
return newColors;
|
|
386
362
|
}
|
|
387
|
-
|
|
388
363
|
const colors = colorsAttribute.value;
|
|
389
|
-
|
|
390
364
|
for (let i = 0; i < indices.length; i++) {
|
|
391
365
|
const colorIndex = indices[i] * components;
|
|
392
366
|
const color = colors.subarray(colorIndex, colorIndex + components);
|
|
393
367
|
const colorUint8 = new Uint8Array(components);
|
|
394
|
-
|
|
395
368
|
for (let j = 0; j < color.length; j++) {
|
|
396
369
|
colorUint8[j] = color[j] * 255;
|
|
397
370
|
}
|
|
398
|
-
|
|
399
371
|
newColors.set(colorUint8, i * components);
|
|
400
372
|
}
|
|
401
|
-
|
|
402
373
|
return newColors;
|
|
403
374
|
}
|
|
404
375
|
|
|
376
|
+
function createUvRegion(materialUvRegion, indices) {
|
|
377
|
+
const result = new Uint16Array(indices.length * 4);
|
|
378
|
+
for (let i = 0; i < result.length; i += 4) {
|
|
379
|
+
result.set(materialUvRegion, i);
|
|
380
|
+
}
|
|
381
|
+
return result;
|
|
382
|
+
}
|
|
383
|
+
|
|
405
384
|
function flattenBatchIds(batchedIds, indices) {
|
|
406
385
|
if (!batchedIds.length || !indices.length) {
|
|
407
386
|
return [];
|
|
408
387
|
}
|
|
409
|
-
|
|
410
388
|
const newBatchIds = [];
|
|
411
|
-
|
|
412
389
|
for (let i = 0; i < indices.length; i++) {
|
|
413
390
|
const coordIndex = indices[i];
|
|
414
391
|
newBatchIds.push(batchedIds[coordIndex]);
|
|
415
392
|
}
|
|
416
|
-
|
|
417
393
|
return newBatchIds;
|
|
418
394
|
}
|
|
419
395
|
|
|
420
|
-
function
|
|
421
|
-
|
|
422
|
-
|
|
396
|
+
function getBatchIds(attributes, primitive, images) {
|
|
397
|
+
const batchIds = handleBatchIdsExtensions(attributes, primitive, images);
|
|
398
|
+
if (batchIds.length) {
|
|
399
|
+
return batchIds;
|
|
400
|
+
}
|
|
423
401
|
for (let index = 0; index < BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES.length; index++) {
|
|
424
402
|
const possibleBatchIdAttributeName = BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES[index];
|
|
425
|
-
|
|
426
403
|
if (attributes[possibleBatchIdAttributeName] && attributes[possibleBatchIdAttributeName].value) {
|
|
427
|
-
|
|
428
|
-
break;
|
|
404
|
+
return attributes[possibleBatchIdAttributeName].value;
|
|
429
405
|
}
|
|
430
406
|
}
|
|
431
|
-
|
|
432
|
-
return batchIds;
|
|
407
|
+
return [];
|
|
433
408
|
}
|
|
434
409
|
|
|
435
|
-
function convertMaterials(
|
|
436
|
-
|
|
437
|
-
|
|
410
|
+
async function convertMaterials() {
|
|
411
|
+
let sourceMaterials = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
412
|
+
let shouldMergeMaterials = arguments.length > 1 ? arguments[1] : undefined;
|
|
413
|
+
let materials = [];
|
|
438
414
|
for (const sourceMaterial of sourceMaterials) {
|
|
439
|
-
|
|
415
|
+
materials.push(convertMaterial(sourceMaterial));
|
|
440
416
|
}
|
|
417
|
+
if (shouldMergeMaterials) {
|
|
418
|
+
materials = await mergeAllMaterials(materials);
|
|
419
|
+
}
|
|
420
|
+
return materials;
|
|
421
|
+
}
|
|
441
422
|
|
|
423
|
+
async function mergeAllMaterials(materials) {
|
|
424
|
+
const result = [];
|
|
425
|
+
while (materials.length > 0) {
|
|
426
|
+
let newMaterial = materials.splice(0, 1)[0];
|
|
427
|
+
const mergedIndices = [];
|
|
428
|
+
for (let i = 0; i < materials.length; i++) {
|
|
429
|
+
const material = materials[i];
|
|
430
|
+
if (newMaterial.texture && material.texture || !newMaterial.texture && !material.texture) {
|
|
431
|
+
newMaterial = await mergeMaterials(newMaterial, material);
|
|
432
|
+
mergedIndices.push(i);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
if (newMaterial.texture && mergedIndices.length) {
|
|
436
|
+
var _newMaterial$mergedMa, _newMaterial$mergedMa2;
|
|
437
|
+
const newWidth = (_newMaterial$mergedMa = newMaterial.mergedMaterials) === null || _newMaterial$mergedMa === void 0 ? void 0 : _newMaterial$mergedMa.reduce((accum, _ref3) => {
|
|
438
|
+
let {
|
|
439
|
+
textureSize
|
|
440
|
+
} = _ref3;
|
|
441
|
+
return accum + ((textureSize === null || textureSize === void 0 ? void 0 : textureSize.width) || 0);
|
|
442
|
+
}, 0);
|
|
443
|
+
const newHeight = (_newMaterial$mergedMa2 = newMaterial.mergedMaterials) === null || _newMaterial$mergedMa2 === void 0 ? void 0 : _newMaterial$mergedMa2.reduce((accum, _ref4) => {
|
|
444
|
+
let {
|
|
445
|
+
textureSize
|
|
446
|
+
} = _ref4;
|
|
447
|
+
return Math.max(accum, (textureSize === null || textureSize === void 0 ? void 0 : textureSize.height) || 0);
|
|
448
|
+
}, 0);
|
|
449
|
+
let currentX = -1;
|
|
450
|
+
for (const aTextureMetadata of newMaterial.mergedMaterials) {
|
|
451
|
+
if (aTextureMetadata.textureSize) {
|
|
452
|
+
const newX = currentX + 1 + aTextureMetadata.textureSize.width / newWidth * 2 ** (Uint16Array.BYTES_PER_ELEMENT * 8) - 1;
|
|
453
|
+
aTextureMetadata.uvRegion = new Uint16Array([currentX + 1, 0, newX, aTextureMetadata.textureSize.height / newHeight * 2 ** (Uint16Array.BYTES_PER_ELEMENT * 8) - 1]);
|
|
454
|
+
currentX = newX;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
newMaterial.texture.image.width = newWidth;
|
|
458
|
+
newMaterial.texture.image.height = newHeight;
|
|
459
|
+
}
|
|
460
|
+
for (const index of mergedIndices.reverse()) {
|
|
461
|
+
materials.splice(index, 1);
|
|
462
|
+
}
|
|
463
|
+
result.push(newMaterial);
|
|
464
|
+
}
|
|
465
|
+
if (!result.length) {
|
|
466
|
+
result.push({
|
|
467
|
+
material: getDefaultMaterial(),
|
|
468
|
+
mergedMaterials: [{
|
|
469
|
+
originalMaterialId: 'default'
|
|
470
|
+
}]
|
|
471
|
+
});
|
|
472
|
+
}
|
|
442
473
|
return result;
|
|
443
474
|
}
|
|
444
475
|
|
|
476
|
+
async function mergeMaterials(material1, material2) {
|
|
477
|
+
var _material1$texture, _material2$texture;
|
|
478
|
+
if ((_material1$texture = material1.texture) !== null && _material1$texture !== void 0 && _material1$texture.bufferView && (_material2$texture = material2.texture) !== null && _material2$texture !== void 0 && _material2$texture.bufferView && material1.mergedMaterials && material2.mergedMaterials) {
|
|
479
|
+
const buffer1 = Buffer.from(material1.texture.bufferView.data);
|
|
480
|
+
const buffer2 = Buffer.from(material2.texture.bufferView.data);
|
|
481
|
+
const {
|
|
482
|
+
joinImages
|
|
483
|
+
} = await import('join-images');
|
|
484
|
+
const sharpData = await joinImages([buffer1, buffer2], {
|
|
485
|
+
direction: 'horizontal'
|
|
486
|
+
});
|
|
487
|
+
material1.texture.bufferView.data = await sharpData.toFormat(material1.texture.mimeType === 'image/png' ? 'png' : 'jpeg').toBuffer();
|
|
488
|
+
material1.material.pbrMetallicRoughness.baseColorTexture.textureSetDefinitionId = 1;
|
|
489
|
+
}
|
|
490
|
+
material1.mergedMaterials = material1.mergedMaterials.concat(material2.mergedMaterials);
|
|
491
|
+
return material1;
|
|
492
|
+
}
|
|
493
|
+
|
|
445
494
|
function convertMaterial(sourceMaterial) {
|
|
446
495
|
var _sourceMaterial$emiss, _sourceMaterial$pbrMe, _sourceMaterial$pbrMe2, _sourceMaterial$pbrMe3;
|
|
447
|
-
|
|
448
496
|
const material = {
|
|
449
497
|
doubleSided: sourceMaterial.doubleSided,
|
|
450
498
|
emissiveFactor: (_sourceMaterial$emiss = sourceMaterial.emissiveFactor) === null || _sourceMaterial$emiss === void 0 ? void 0 : _sourceMaterial$emiss.map(c => Math.round(c * 255)),
|
|
@@ -455,7 +503,6 @@ function convertMaterial(sourceMaterial) {
|
|
|
455
503
|
}
|
|
456
504
|
};
|
|
457
505
|
let texture;
|
|
458
|
-
|
|
459
506
|
if (sourceMaterial !== null && sourceMaterial !== void 0 && (_sourceMaterial$pbrMe3 = sourceMaterial.pbrMetallicRoughness) !== null && _sourceMaterial$pbrMe3 !== void 0 && _sourceMaterial$pbrMe3.baseColorTexture) {
|
|
460
507
|
texture = sourceMaterial.pbrMetallicRoughness.baseColorTexture.texture.source;
|
|
461
508
|
material.pbrMetallicRoughness.baseColorTexture = {
|
|
@@ -467,17 +514,25 @@ function convertMaterial(sourceMaterial) {
|
|
|
467
514
|
textureSetDefinitionId: 0
|
|
468
515
|
};
|
|
469
516
|
}
|
|
470
|
-
|
|
517
|
+
const uniqueId = uuidv4();
|
|
518
|
+
sourceMaterial.uniqueId = uniqueId;
|
|
519
|
+
let mergedMaterials = [{
|
|
520
|
+
originalMaterialId: uniqueId
|
|
521
|
+
}];
|
|
471
522
|
if (!texture) {
|
|
472
523
|
var _sourceMaterial$pbrMe4;
|
|
473
|
-
|
|
474
524
|
const baseColorFactor = sourceMaterial === null || sourceMaterial === void 0 ? void 0 : (_sourceMaterial$pbrMe4 = sourceMaterial.pbrMetallicRoughness) === null || _sourceMaterial$pbrMe4 === void 0 ? void 0 : _sourceMaterial$pbrMe4.baseColorFactor;
|
|
475
525
|
material.pbrMetallicRoughness.baseColorFactor = baseColorFactor && baseColorFactor.map(c => Math.round(c * 255)) || undefined;
|
|
526
|
+
} else {
|
|
527
|
+
mergedMaterials[0].textureSize = {
|
|
528
|
+
width: texture.image.width,
|
|
529
|
+
height: texture.image.height
|
|
530
|
+
};
|
|
476
531
|
}
|
|
477
|
-
|
|
478
532
|
return {
|
|
479
533
|
material,
|
|
480
|
-
texture
|
|
534
|
+
texture,
|
|
535
|
+
mergedMaterials
|
|
481
536
|
};
|
|
482
537
|
}
|
|
483
538
|
|
|
@@ -485,13 +540,10 @@ function convertAlphaMode(gltfAlphaMode) {
|
|
|
485
540
|
switch (gltfAlphaMode) {
|
|
486
541
|
case 'OPAQUE':
|
|
487
542
|
return 'opaque';
|
|
488
|
-
|
|
489
543
|
case 'MASK':
|
|
490
544
|
return 'mask';
|
|
491
|
-
|
|
492
545
|
case 'BLEND':
|
|
493
546
|
return 'blend';
|
|
494
|
-
|
|
495
547
|
default:
|
|
496
548
|
return 'opaque';
|
|
497
549
|
}
|
|
@@ -509,57 +561,48 @@ function getDefaultMaterial() {
|
|
|
509
561
|
|
|
510
562
|
function getSharedResources(gltfMaterials, nodeId) {
|
|
511
563
|
const i3sResources = {};
|
|
512
|
-
|
|
513
564
|
if (!gltfMaterials || !gltfMaterials.length) {
|
|
514
565
|
return i3sResources;
|
|
515
566
|
}
|
|
516
|
-
|
|
517
567
|
i3sResources.materialDefinitionInfos = [];
|
|
518
|
-
|
|
519
568
|
for (const gltfMaterial of gltfMaterials) {
|
|
520
569
|
const {
|
|
521
570
|
materialDefinitionInfo,
|
|
522
571
|
textureDefinitionInfo
|
|
523
572
|
} = convertGLTFMaterialToI3sSharedResources(gltfMaterial, nodeId);
|
|
524
573
|
i3sResources.materialDefinitionInfos.push(materialDefinitionInfo);
|
|
525
|
-
|
|
526
574
|
if (textureDefinitionInfo) {
|
|
527
575
|
i3sResources.textureDefinitionInfos = i3sResources.textureDefinitionInfos || [];
|
|
528
576
|
i3sResources.textureDefinitionInfos.push(textureDefinitionInfo);
|
|
529
577
|
}
|
|
530
578
|
}
|
|
531
|
-
|
|
532
579
|
return i3sResources;
|
|
533
580
|
}
|
|
534
581
|
|
|
535
582
|
function convertGLTFMaterialToI3sSharedResources(gltfMaterial, nodeId) {
|
|
536
583
|
var _gltfMaterial$pbrMeta;
|
|
537
|
-
|
|
538
584
|
const texture = (gltfMaterial === null || gltfMaterial === void 0 ? void 0 : (_gltfMaterial$pbrMeta = gltfMaterial.pbrMetallicRoughness) === null || _gltfMaterial$pbrMeta === void 0 ? void 0 : _gltfMaterial$pbrMeta.baseColorTexture) || gltfMaterial.emissiveTexture;
|
|
539
585
|
let textureDefinitionInfo = null;
|
|
540
|
-
|
|
541
586
|
if (texture) {
|
|
542
587
|
textureDefinitionInfo = extractSharedResourcesTextureInfo(texture.texture, nodeId);
|
|
543
588
|
}
|
|
544
|
-
|
|
545
589
|
const {
|
|
546
590
|
baseColorFactor,
|
|
547
591
|
metallicFactor
|
|
548
592
|
} = (gltfMaterial === null || gltfMaterial === void 0 ? void 0 : gltfMaterial.pbrMetallicRoughness) || {};
|
|
549
593
|
let colorFactor = baseColorFactor;
|
|
550
|
-
|
|
551
594
|
if ((!baseColorFactor || baseColorFactor[3] === 0) && gltfMaterial.emissiveFactor) {
|
|
552
595
|
colorFactor = gltfMaterial.emissiveFactor;
|
|
553
596
|
colorFactor[3] = colorFactor[3] || 1;
|
|
554
597
|
}
|
|
555
|
-
|
|
556
598
|
return {
|
|
557
599
|
materialDefinitionInfo: extractSharedResourcesMaterialInfo(colorFactor || [1, 1, 1, 1], metallicFactor),
|
|
558
600
|
textureDefinitionInfo
|
|
559
601
|
};
|
|
560
602
|
}
|
|
561
603
|
|
|
562
|
-
function extractSharedResourcesMaterialInfo(baseColorFactor
|
|
604
|
+
function extractSharedResourcesMaterialInfo(baseColorFactor) {
|
|
605
|
+
let metallicFactor = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
563
606
|
const matDielectricColorComponent = 0.04 / 255;
|
|
564
607
|
const black = new Vector4(0, 0, 0, 1);
|
|
565
608
|
const unitVector = new Vector4(1, 1, 1, 1);
|
|
@@ -580,7 +623,6 @@ function extractSharedResourcesMaterialInfo(baseColorFactor, metallicFactor = 1)
|
|
|
580
623
|
|
|
581
624
|
function extractSharedResourcesTextureInfo(texture, nodeId) {
|
|
582
625
|
var _texture$source, _texture$source2, _texture$source3;
|
|
583
|
-
|
|
584
626
|
return {
|
|
585
627
|
encoding: texture !== null && texture !== void 0 && (_texture$source = texture.source) !== null && _texture$source !== void 0 && _texture$source.mimeType ? [texture.source.mimeType] : undefined,
|
|
586
628
|
images: [{
|
|
@@ -593,7 +635,6 @@ function extractSharedResourcesTextureInfo(texture, nodeId) {
|
|
|
593
635
|
|
|
594
636
|
function generateImageId(texture, nodeId) {
|
|
595
637
|
var _texture$source4;
|
|
596
|
-
|
|
597
638
|
const {
|
|
598
639
|
width,
|
|
599
640
|
height
|
|
@@ -620,34 +661,28 @@ function makeFeatureIdsUnique(featureIds, featureIndices, featuresHashArray, bat
|
|
|
620
661
|
|
|
621
662
|
function getFeaturesReplaceMap(featureIds, batchTable, featuresHashArray) {
|
|
622
663
|
const featureMap = {};
|
|
623
|
-
|
|
624
664
|
for (let index = 0; index < featureIds.length; index++) {
|
|
625
665
|
const oldFeatureId = featureIds[index];
|
|
626
666
|
const uniqueFeatureId = getOrCreateUniqueFeatureId(index, batchTable, featuresHashArray);
|
|
627
667
|
featureMap[oldFeatureId.toString()] = uniqueFeatureId;
|
|
628
668
|
}
|
|
629
|
-
|
|
630
669
|
return featureMap;
|
|
631
670
|
}
|
|
632
671
|
|
|
633
672
|
function generateStringFromBatchTableByIndex(batchTable, index) {
|
|
634
673
|
let str = '';
|
|
635
|
-
|
|
636
674
|
for (const key in batchTable) {
|
|
637
675
|
str += batchTable[key][index];
|
|
638
676
|
}
|
|
639
|
-
|
|
640
677
|
return str;
|
|
641
678
|
}
|
|
642
679
|
|
|
643
680
|
function getOrCreateUniqueFeatureId(index, batchTable, featuresHashArray) {
|
|
644
681
|
const batchTableStr = generateStringFromBatchTableByIndex(batchTable, index);
|
|
645
682
|
const hash = md5(batchTableStr);
|
|
646
|
-
|
|
647
683
|
if (featuresHashArray.includes(hash)) {
|
|
648
684
|
return featuresHashArray.indexOf(hash);
|
|
649
685
|
}
|
|
650
|
-
|
|
651
686
|
return featuresHashArray.push(hash) - 1;
|
|
652
687
|
}
|
|
653
688
|
|
|
@@ -657,46 +692,42 @@ function replaceIndicesByUnique(indicesArray, featureMap) {
|
|
|
657
692
|
}
|
|
658
693
|
}
|
|
659
694
|
|
|
660
|
-
function
|
|
695
|
+
function convertPropertyTableToAttributeBuffers(featureIds, propertyTable, attributeStorageInfo) {
|
|
661
696
|
const attributeBuffers = [];
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
switch (type) {
|
|
674
|
-
case OBJECT_ID_TYPE:
|
|
675
|
-
case SHORT_INT_TYPE:
|
|
676
|
-
attributeBuffer = generateShortIntegerAttributeBuffer(batchTableWithFeatureIds[key]);
|
|
677
|
-
break;
|
|
678
|
-
|
|
679
|
-
case DOUBLE_TYPE:
|
|
680
|
-
attributeBuffer = generateDoubleAttributeBuffer(batchTableWithFeatureIds[key]);
|
|
681
|
-
break;
|
|
682
|
-
|
|
683
|
-
case STRING_TYPE:
|
|
684
|
-
attributeBuffer = generateStringAttributeBuffer(batchTableWithFeatureIds[key]);
|
|
685
|
-
break;
|
|
686
|
-
|
|
687
|
-
default:
|
|
688
|
-
attributeBuffer = generateStringAttributeBuffer(batchTableWithFeatureIds[key]);
|
|
689
|
-
}
|
|
690
|
-
|
|
691
|
-
if (attributeBuffer) {
|
|
692
|
-
attributeBuffers.push(attributeBuffer);
|
|
693
|
-
}
|
|
694
|
-
}
|
|
697
|
+
const needFlattenPropertyTable = checkPropertiesLength(featureIds, propertyTable);
|
|
698
|
+
const properties = needFlattenPropertyTable ? flattenPropertyTableByFeatureIds(featureIds, propertyTable) : propertyTable;
|
|
699
|
+
const propertyTableWithObjectIds = {
|
|
700
|
+
OBJECTID: featureIds,
|
|
701
|
+
...properties
|
|
702
|
+
};
|
|
703
|
+
for (const propertyName in propertyTableWithObjectIds) {
|
|
704
|
+
const type = getAttributeType(propertyName, attributeStorageInfo);
|
|
705
|
+
const value = propertyTableWithObjectIds[propertyName];
|
|
706
|
+
const attributeBuffer = generateAttributeBuffer(type, value);
|
|
707
|
+
attributeBuffers.push(attributeBuffer);
|
|
695
708
|
}
|
|
696
|
-
|
|
697
709
|
return attributeBuffers;
|
|
698
710
|
}
|
|
699
711
|
|
|
712
|
+
function generateAttributeBuffer(type, value) {
|
|
713
|
+
let attributeBuffer;
|
|
714
|
+
switch (type) {
|
|
715
|
+
case OBJECT_ID_TYPE:
|
|
716
|
+
case SHORT_INT_TYPE:
|
|
717
|
+
attributeBuffer = generateShortIntegerAttributeBuffer(value);
|
|
718
|
+
break;
|
|
719
|
+
case DOUBLE_TYPE:
|
|
720
|
+
attributeBuffer = generateDoubleAttributeBuffer(value);
|
|
721
|
+
break;
|
|
722
|
+
case STRING_TYPE:
|
|
723
|
+
attributeBuffer = generateStringAttributeBuffer(value);
|
|
724
|
+
break;
|
|
725
|
+
default:
|
|
726
|
+
attributeBuffer = generateStringAttributeBuffer(value);
|
|
727
|
+
}
|
|
728
|
+
return attributeBuffer;
|
|
729
|
+
}
|
|
730
|
+
|
|
700
731
|
function getAttributeType(key, attributeStorageInfo) {
|
|
701
732
|
const attribute = attributeStorageInfo.find(attr => attr.name === key);
|
|
702
733
|
return attribute.attributeValues.valueType;
|
|
@@ -720,7 +751,6 @@ function generateStringAttributeBuffer(batchAttributes) {
|
|
|
720
751
|
let totalNumberOfBytes = 0;
|
|
721
752
|
const stringSizesArray = new Uint32Array(batchAttributes.length);
|
|
722
753
|
const stringBufferArray = [];
|
|
723
|
-
|
|
724
754
|
for (let index = 0; index < batchAttributes.length; index++) {
|
|
725
755
|
const currentString = "".concat(String(batchAttributes[index]), "\0");
|
|
726
756
|
const currentStringBuffer = Buffer.from(currentString);
|
|
@@ -729,18 +759,15 @@ function generateStringAttributeBuffer(batchAttributes) {
|
|
|
729
759
|
stringSizesArray[index] = currentStringSize;
|
|
730
760
|
stringBufferArray.push(currentStringBuffer);
|
|
731
761
|
}
|
|
732
|
-
|
|
733
762
|
const totalBytes = new Uint32Array([totalNumberOfBytes]);
|
|
734
763
|
return concatenateArrayBuffers(stringCountArray.buffer, totalBytes.buffer, stringSizesArray.buffer, ...stringBufferArray);
|
|
735
764
|
}
|
|
736
765
|
|
|
737
766
|
function generateBigUint64Array(featureIds) {
|
|
738
767
|
const typedFeatureIds = new BigUint64Array(featureIds.length);
|
|
739
|
-
|
|
740
768
|
for (let index = 0; index < featureIds.length; index++) {
|
|
741
769
|
typedFeatureIds[index] = BigInt(featureIds[index]);
|
|
742
770
|
}
|
|
743
|
-
|
|
744
771
|
return typedFeatureIds;
|
|
745
772
|
}
|
|
746
773
|
|
|
@@ -750,15 +777,14 @@ async function generateCompressedGeometry(vertexCount, convertedAttributes, attr
|
|
|
750
777
|
normals,
|
|
751
778
|
texCoords,
|
|
752
779
|
colors,
|
|
780
|
+
uvRegions,
|
|
753
781
|
featureIds,
|
|
754
782
|
faceRange
|
|
755
783
|
} = attributes;
|
|
756
784
|
const indices = new Uint32Array(vertexCount);
|
|
757
|
-
|
|
758
785
|
for (let index = 0; index < indices.length; index++) {
|
|
759
786
|
indices.set([index], index);
|
|
760
787
|
}
|
|
761
|
-
|
|
762
788
|
const featureIndices = new Uint32Array(convertedAttributes.featureIndices.length ? convertedAttributes.featureIndices : vertexCount);
|
|
763
789
|
const featureIndex = generateFeatureIndexAttribute(featureIndices, faceRange);
|
|
764
790
|
const compressedAttributes = {
|
|
@@ -767,21 +793,26 @@ async function generateCompressedGeometry(vertexCount, convertedAttributes, attr
|
|
|
767
793
|
colors,
|
|
768
794
|
'feature-index': featureIndex
|
|
769
795
|
};
|
|
770
|
-
|
|
771
796
|
if (texCoords.length) {
|
|
772
797
|
compressedAttributes.texCoords = texCoords;
|
|
773
798
|
}
|
|
774
|
-
|
|
775
799
|
const attributesMetadata = {
|
|
776
800
|
'feature-index': {
|
|
777
801
|
'i3s-attribute-type': 'feature-index',
|
|
778
802
|
'i3s-feature-ids': new Int32Array(featureIds)
|
|
779
803
|
}
|
|
780
804
|
};
|
|
805
|
+
if (uvRegions.length) {
|
|
806
|
+
compressedAttributes['uv-region'] = uvRegions;
|
|
807
|
+
attributesMetadata['uv-region'] = {
|
|
808
|
+
'i3s-attribute-type': 'uv-region'
|
|
809
|
+
};
|
|
810
|
+
}
|
|
781
811
|
return encode({
|
|
782
812
|
attributes: compressedAttributes,
|
|
783
813
|
indices
|
|
784
|
-
}, DracoWriterWorker, {
|
|
814
|
+
}, DracoWriterWorker, {
|
|
815
|
+
...DracoWriterWorker.options,
|
|
785
816
|
source: dracoWorkerSoure,
|
|
786
817
|
reuseWorkers: true,
|
|
787
818
|
_nodeWorkers: true,
|
|
@@ -796,14 +827,82 @@ function generateFeatureIndexAttribute(featureIndex, faceRange) {
|
|
|
796
827
|
const orderedFeatureIndices = new Uint32Array(featureIndex.length);
|
|
797
828
|
let fillIndex = 0;
|
|
798
829
|
let startIndex = 0;
|
|
799
|
-
|
|
800
830
|
for (let index = 1; index < faceRange.length; index += 2) {
|
|
801
831
|
const endIndex = (faceRange[index] + 1) * VALUES_PER_VERTEX;
|
|
802
832
|
orderedFeatureIndices.fill(fillIndex, startIndex, endIndex);
|
|
803
833
|
fillIndex++;
|
|
804
834
|
startIndex = endIndex + 1;
|
|
805
835
|
}
|
|
806
|
-
|
|
807
836
|
return orderedFeatureIndices;
|
|
808
837
|
}
|
|
838
|
+
|
|
839
|
+
export function getPropertyTable(tileContent) {
|
|
840
|
+
const batchTableJson = tileContent === null || tileContent === void 0 ? void 0 : tileContent.batchTableJson;
|
|
841
|
+
if (batchTableJson) {
|
|
842
|
+
return batchTableJson;
|
|
843
|
+
}
|
|
844
|
+
const {
|
|
845
|
+
extensionName,
|
|
846
|
+
extension
|
|
847
|
+
} = getPropertyTableExtension(tileContent);
|
|
848
|
+
switch (extensionName) {
|
|
849
|
+
case EXT_MESH_FEATURES:
|
|
850
|
+
{
|
|
851
|
+
console.warn('The I3S converter does not yet support the EXT_mesh_features extension');
|
|
852
|
+
return null;
|
|
853
|
+
}
|
|
854
|
+
case EXT_FEATURE_METADATA:
|
|
855
|
+
{
|
|
856
|
+
return getPropertyTableFromExtFeatureMetadata(extension);
|
|
857
|
+
}
|
|
858
|
+
default:
|
|
859
|
+
return null;
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
function getPropertyTableExtension(tileContent) {
|
|
864
|
+
var _tileContent$gltf3, _tileContent$gltf5, _tileContent$gltf5$ex;
|
|
865
|
+
const extensionsWithPropertyTables = [EXT_FEATURE_METADATA, EXT_MESH_FEATURES];
|
|
866
|
+
const extensionsUsed = tileContent === null || tileContent === void 0 ? void 0 : (_tileContent$gltf3 = tileContent.gltf) === null || _tileContent$gltf3 === void 0 ? void 0 : _tileContent$gltf3.extensionsUsed;
|
|
867
|
+
if (!extensionsUsed) {
|
|
868
|
+
return {
|
|
869
|
+
extensionName: null,
|
|
870
|
+
extension: null
|
|
871
|
+
};
|
|
872
|
+
}
|
|
873
|
+
let extensionName = '';
|
|
874
|
+
for (const extensionItem of (tileContent === null || tileContent === void 0 ? void 0 : (_tileContent$gltf4 = tileContent.gltf) === null || _tileContent$gltf4 === void 0 ? void 0 : _tileContent$gltf4.extensionsUsed) || []) {
|
|
875
|
+
var _tileContent$gltf4;
|
|
876
|
+
if (extensionsWithPropertyTables.includes(extensionItem)) {
|
|
877
|
+
extensionName = extensionItem;
|
|
878
|
+
break;
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
const extension = tileContent === null || tileContent === void 0 ? void 0 : (_tileContent$gltf5 = tileContent.gltf) === null || _tileContent$gltf5 === void 0 ? void 0 : (_tileContent$gltf5$ex = _tileContent$gltf5.extensions) === null || _tileContent$gltf5$ex === void 0 ? void 0 : _tileContent$gltf5$ex[extensionName];
|
|
882
|
+
return {
|
|
883
|
+
extensionName,
|
|
884
|
+
extension
|
|
885
|
+
};
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
function getPropertyTableFromExtFeatureMetadata(extension) {
|
|
889
|
+
if (extension !== null && extension !== void 0 && extension.featureTextures) {
|
|
890
|
+
console.warn('The I3S converter does not yet support the EXT_feature_metadata feature textures');
|
|
891
|
+
return null;
|
|
892
|
+
}
|
|
893
|
+
if (extension !== null && extension !== void 0 && extension.featureTables) {
|
|
894
|
+
var _Object$keys;
|
|
895
|
+
const firstFeatureTableName = (_Object$keys = Object.keys(extension.featureTables)) === null || _Object$keys === void 0 ? void 0 : _Object$keys[0];
|
|
896
|
+
if (firstFeatureTableName) {
|
|
897
|
+
const featureTable = extension === null || extension === void 0 ? void 0 : extension.featureTables[firstFeatureTableName];
|
|
898
|
+
const propertyTable = {};
|
|
899
|
+
for (const propertyName in featureTable.properties) {
|
|
900
|
+
propertyTable[propertyName] = featureTable.properties[propertyName].data;
|
|
901
|
+
}
|
|
902
|
+
return propertyTable;
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
console.warn("The I3S converter couldn't handle EXT_feature_metadata extension");
|
|
906
|
+
return null;
|
|
907
|
+
}
|
|
809
908
|
//# sourceMappingURL=geometry-converter.js.map
|