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