@loaders.gl/tile-converter 3.3.0-alpha.1 → 3.3.0-alpha.11
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 +42714 -45782
- 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 +517 -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 +770 -1131
- 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 +202 -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 +217 -509
- 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 +95 -0
- package/dist/i3s-converter/helpers/node-index-document.d.ts.map +1 -0
- package/dist/i3s-converter/helpers/node-index-document.js +250 -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 +201 -93
- 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 +223 -421
- 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 +315 -0
- package/src/i3s-converter/helpers/node-pages.ts +222 -109
- package/src/i3s-converter/i3s-converter.ts +269 -500
- 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
|
@@ -1,19 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
5
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.convertAttributes = void 0;
|
|
29
|
+
exports.getPropertyTable = exports.convertAttributes = void 0;
|
|
7
30
|
const core_1 = require("@math.gl/core");
|
|
8
31
|
const geospatial_1 = require("@math.gl/geospatial");
|
|
9
32
|
const draco_1 = require("@loaders.gl/draco");
|
|
10
33
|
const core_2 = require("@loaders.gl/core");
|
|
11
34
|
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
12
35
|
const md5_1 = __importDefault(require("md5"));
|
|
36
|
+
const uuid_1 = require("uuid");
|
|
13
37
|
const geometry_attributes_1 = require("./geometry-attributes");
|
|
14
38
|
const coordinate_converter_1 = require("./coordinate-converter");
|
|
15
39
|
const gltf_attributes_1 = require("./gltf-attributes");
|
|
16
40
|
const batch_ids_extensions_1 = require("./batch-ids-extensions");
|
|
41
|
+
const feature_attributes_1 = require("./feature-attributes");
|
|
17
42
|
// Spec - https://github.com/Esri/i3s-spec/blob/master/docs/1.7/pbrMetallicRoughness.cmn.md
|
|
18
43
|
const DEFAULT_ROUGHNESS_FACTOR = 1;
|
|
19
44
|
const DEFAULT_METALLIC_FACTOR = 1;
|
|
@@ -30,68 +55,64 @@ const OBJECT_ID_TYPE = 'Oid32';
|
|
|
30
55
|
* BATCHID - Legacy attribute name which includes batch info.
|
|
31
56
|
*/
|
|
32
57
|
const BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES = ['CUSTOM_ATTRIBUTE_2', '_BATCHID', 'BATCHID'];
|
|
58
|
+
const EXT_FEATURE_METADATA = 'EXT_feature_metadata';
|
|
59
|
+
const EXT_MESH_FEATURES = 'EXT_mesh_features';
|
|
33
60
|
let scratchVector = new core_1.Vector3();
|
|
34
61
|
/**
|
|
35
62
|
* Convert binary data from b3dm file to i3s resources
|
|
36
63
|
*
|
|
37
64
|
* @param tileContent - 3d tile content
|
|
38
|
-
* @param
|
|
65
|
+
* @param addNodeToNodePage - function to add new node to node pages
|
|
66
|
+
* @param propertyTable - batch table (corresponding to feature attributes data)
|
|
39
67
|
* @param featuresHashArray - hash array of features that is needed to not to mix up same features in parent and child nodes
|
|
40
68
|
* @param attributeStorageInfo - attributes metadata from 3DSceneLayer json
|
|
41
69
|
* @param draco - is converter should create draco compressed geometry
|
|
42
70
|
* @param generateBoundingVolumes - is converter should create accurate bounding voulmes from geometry attributes
|
|
71
|
+
* @param shouldMergeMaterials - Try to merge similar materials to be able to merge meshes into one node
|
|
43
72
|
* @param geoidHeightModel - model to convert elevation from elipsoidal to geoid
|
|
73
|
+
* @param workerSource - source code of used workers
|
|
44
74
|
* @returns Array of node resources to create one or more i3s nodes
|
|
45
75
|
*/
|
|
46
|
-
async function convertB3dmToI3sGeometry(tileContent,
|
|
76
|
+
async function convertB3dmToI3sGeometry(tileContent, addNodeToNodePage, propertyTable, featuresHashArray, attributeStorageInfo, draco, generateBoundingVolumes, shouldMergeMaterials, geoidHeightModel, workerSource) {
|
|
47
77
|
const useCartesianPositions = generateBoundingVolumes;
|
|
48
|
-
const materialAndTextureList = convertMaterials(tileContent.gltf?.materials);
|
|
78
|
+
const materialAndTextureList = await convertMaterials(tileContent.gltf?.materials, shouldMergeMaterials);
|
|
49
79
|
const dataForAttributesConversion = (0, gltf_attributes_1.prepareDataForAttributesConversion)(tileContent);
|
|
50
|
-
const convertedAttributesMap = await convertAttributes(dataForAttributesConversion, useCartesianPositions);
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
80
|
+
const convertedAttributesMap = await convertAttributes(dataForAttributesConversion, materialAndTextureList, useCartesianPositions);
|
|
81
|
+
/** Usage of worker here brings more overhead than advantage */
|
|
82
|
+
// const convertedAttributesMap: Map<string, ConvertedAttributes> =
|
|
83
|
+
// await transformI3SAttributesOnWorker(dataForAttributesConversion, {
|
|
84
|
+
// reuseWorkers: true,
|
|
85
|
+
// _nodeWorkers: true,
|
|
86
|
+
// useCartesianPositions,
|
|
87
|
+
// source: workerSource.I3SAttributes
|
|
88
|
+
// });
|
|
59
89
|
if (generateBoundingVolumes) {
|
|
60
90
|
_generateBoundingVolumesFromGeometry(convertedAttributesMap, geoidHeightModel);
|
|
61
91
|
}
|
|
62
|
-
if (convertedAttributesMap.has('default')) {
|
|
63
|
-
materialAndTextureList.push({
|
|
64
|
-
material: getDefaultMaterial()
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
92
|
const result = [];
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
materials.push({ id: 'default' });
|
|
72
|
-
}
|
|
73
|
-
for (let i = 0; i < materials.length; i++) {
|
|
74
|
-
const sourceMaterial = materials[i];
|
|
75
|
-
if (!convertedAttributesMap.has(sourceMaterial.id)) {
|
|
93
|
+
for (const materialAndTexture of materialAndTextureList) {
|
|
94
|
+
const originarMaterialId = materialAndTexture.mergedMaterials[0].originalMaterialId;
|
|
95
|
+
if (!convertedAttributesMap.has(originarMaterialId)) {
|
|
76
96
|
continue; // eslint-disable-line no-continue
|
|
77
97
|
}
|
|
78
|
-
const convertedAttributes = convertedAttributesMap.get(
|
|
98
|
+
const convertedAttributes = convertedAttributesMap.get(originarMaterialId);
|
|
79
99
|
if (!convertedAttributes) {
|
|
80
100
|
continue;
|
|
81
101
|
}
|
|
82
|
-
const { material, texture } =
|
|
102
|
+
const { material, texture } = materialAndTexture;
|
|
103
|
+
const nodeId = await addNodeToNodePage();
|
|
83
104
|
result.push(await _makeNodeResources({
|
|
84
105
|
convertedAttributes,
|
|
85
106
|
material,
|
|
86
107
|
texture,
|
|
87
108
|
tileContent,
|
|
88
|
-
nodeId
|
|
109
|
+
nodeId,
|
|
89
110
|
featuresHashArray,
|
|
111
|
+
propertyTable,
|
|
90
112
|
attributeStorageInfo,
|
|
91
113
|
draco,
|
|
92
114
|
workerSource
|
|
93
115
|
}));
|
|
94
|
-
nodesCounter++;
|
|
95
116
|
}
|
|
96
117
|
if (!result.length) {
|
|
97
118
|
return null;
|
|
@@ -128,36 +149,44 @@ function _generateBoundingVolumesFromGeometry(convertedAttributesMap, geoidHeigh
|
|
|
128
149
|
* @param params.tileContent - B3DM decoded content
|
|
129
150
|
* @param params.nodeId - new node ID
|
|
130
151
|
* @param params.featuresHashArray - hash array of features that is needed to not to mix up same features in parent and child nodes
|
|
131
|
-
* @param params.
|
|
152
|
+
* @param params.propertyTable - batch table (corresponding to feature attributes data)
|
|
153
|
+
* @param params.attributeStorageInfo - attributes metadata from 3DSceneLayer json
|
|
132
154
|
* @param params.draco - is converter should create draco compressed geometry
|
|
155
|
+
* @param params.workerSource - source code of used workers
|
|
133
156
|
* @returns Array of I3S node resources
|
|
134
157
|
*/
|
|
135
|
-
async function _makeNodeResources({ convertedAttributes, material, texture, tileContent, nodeId, featuresHashArray, attributeStorageInfo, draco, workerSource }) {
|
|
158
|
+
async function _makeNodeResources({ convertedAttributes, material, texture, tileContent, nodeId, featuresHashArray, propertyTable, attributeStorageInfo, draco, workerSource }) {
|
|
136
159
|
const boundingVolumes = convertedAttributes.boundingVolumes;
|
|
137
160
|
const vertexCount = convertedAttributes.positions.length / VALUES_PER_VERTEX;
|
|
138
|
-
const { faceRange, featureIds, positions, normals, colors, texCoords, featureCount } = (0, geometry_attributes_1.generateAttributes)(convertedAttributes);
|
|
161
|
+
const { faceRange, featureIds, positions, normals, colors, uvRegions, texCoords, featureCount } = (0, geometry_attributes_1.generateAttributes)(convertedAttributes);
|
|
139
162
|
if (tileContent.batchTableJson) {
|
|
140
163
|
makeFeatureIdsUnique(featureIds, convertedAttributes.featureIndices, featuresHashArray, tileContent.batchTableJson);
|
|
141
164
|
}
|
|
142
165
|
const header = new Uint32Array(2);
|
|
143
166
|
const typedFeatureIds = generateBigUint64Array(featureIds);
|
|
144
167
|
header.set([vertexCount, featureCount], 0);
|
|
145
|
-
const fileBuffer = new Uint8Array((0, loader_utils_1.concatenateArrayBuffers)(header.buffer, positions.buffer, normals.buffer, texture ? texCoords.buffer : new ArrayBuffer(0), colors.buffer, typedFeatureIds.buffer, faceRange.buffer));
|
|
168
|
+
const fileBuffer = new Uint8Array((0, loader_utils_1.concatenateArrayBuffers)(header.buffer, positions.buffer, normals.buffer, texture ? texCoords.buffer : new ArrayBuffer(0), colors.buffer, uvRegions, typedFeatureIds.buffer, faceRange.buffer));
|
|
146
169
|
const compressedGeometry = draco
|
|
147
170
|
? generateCompressedGeometry(vertexCount, convertedAttributes, {
|
|
148
171
|
positions,
|
|
149
172
|
normals,
|
|
150
173
|
texCoords: texture ? texCoords : new Float32Array(0),
|
|
151
174
|
colors,
|
|
175
|
+
uvRegions,
|
|
152
176
|
featureIds,
|
|
153
177
|
faceRange
|
|
154
178
|
}, workerSource.draco)
|
|
155
179
|
: null;
|
|
156
|
-
|
|
180
|
+
let attributes = [];
|
|
181
|
+
if (attributeStorageInfo && propertyTable) {
|
|
182
|
+
attributes = convertPropertyTableToAttributeBuffers(featureIds, propertyTable, attributeStorageInfo);
|
|
183
|
+
}
|
|
157
184
|
return {
|
|
185
|
+
nodeId,
|
|
158
186
|
geometry: fileBuffer,
|
|
159
187
|
compressedGeometry,
|
|
160
188
|
texture,
|
|
189
|
+
hasUvRegions: Boolean(uvRegions.length),
|
|
161
190
|
sharedResources: getSharedResources(tileContent.gltf?.materials || [], nodeId),
|
|
162
191
|
meshMaterial: material,
|
|
163
192
|
vertexCount,
|
|
@@ -168,26 +197,32 @@ async function _makeNodeResources({ convertedAttributes, material, texture, tile
|
|
|
168
197
|
}
|
|
169
198
|
/**
|
|
170
199
|
* Convert attributes from the gltf nodes tree to i3s plain geometry
|
|
171
|
-
* @param
|
|
200
|
+
* @param attributesData - geometry attributes from gltf
|
|
201
|
+
* @param materialAndTextureList - array of data about materials and textures of the content
|
|
172
202
|
* @param useCartesianPositions - convert positions to absolute cartesian coordinates instead of cartographic offsets.
|
|
173
203
|
* Cartesian coordinates will be required for creating bounding voulmest from geometry positions
|
|
174
204
|
* @returns map of converted geometry attributes
|
|
175
205
|
*/
|
|
176
|
-
async function convertAttributes(attributesData, useCartesianPositions) {
|
|
177
|
-
const {
|
|
206
|
+
async function convertAttributes(attributesData, materialAndTextureList, useCartesianPositions) {
|
|
207
|
+
const { nodes, images, cartographicOrigin, cartesianModelMatrix } = attributesData;
|
|
178
208
|
const attributesMap = new Map();
|
|
179
|
-
for (const
|
|
180
|
-
|
|
209
|
+
for (const materialAndTexture of materialAndTextureList) {
|
|
210
|
+
const attributes = {
|
|
181
211
|
positions: new Float32Array(0),
|
|
182
212
|
normals: new Float32Array(0),
|
|
183
213
|
texCoords: new Float32Array(0),
|
|
184
214
|
colors: new Uint8Array(0),
|
|
215
|
+
uvRegions: new Uint16Array(0),
|
|
185
216
|
featureIndicesGroups: [],
|
|
186
217
|
featureIndices: [],
|
|
187
|
-
boundingVolumes: null
|
|
188
|
-
|
|
218
|
+
boundingVolumes: null,
|
|
219
|
+
mergedMaterials: materialAndTexture.mergedMaterials
|
|
220
|
+
};
|
|
221
|
+
for (const mergedMaterial of materialAndTexture.mergedMaterials) {
|
|
222
|
+
attributesMap.set(mergedMaterial.originalMaterialId, attributes);
|
|
223
|
+
}
|
|
189
224
|
}
|
|
190
|
-
convertNodes(nodes, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions);
|
|
225
|
+
convertNodes(nodes, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions);
|
|
191
226
|
for (const attrKey of attributesMap.keys()) {
|
|
192
227
|
const attributes = attributesMap.get(attrKey);
|
|
193
228
|
if (!attributes) {
|
|
@@ -209,17 +244,19 @@ exports.convertAttributes = convertAttributes;
|
|
|
209
244
|
* Gltf has hierarchical structure of nodes. This function converts nodes starting from those which are in gltf scene object.
|
|
210
245
|
* The goal is applying tranformation matrix for all children. Functions "convertNodes" and "convertNode" work together recursively.
|
|
211
246
|
* @param nodes - gltf nodes array
|
|
212
|
-
* @param
|
|
247
|
+
* @param images - gltf images array
|
|
248
|
+
* @param cartographicOrigin - cartographic origin of bounding volume
|
|
249
|
+
* @param cartesianModelMatrix - cartesian model matrix to convert coordinates to cartographic
|
|
213
250
|
* @param attributesMap - for recursive concatenation of attributes
|
|
214
251
|
* @param useCartesianPositions - convert positions to absolute cartesian coordinates instead of cartographic offsets.
|
|
215
252
|
* Cartesian coordinates will be required for creating bounding voulmest from geometry positions
|
|
216
253
|
* @param matrix - transformation matrix - cumulative transformation matrix formed from all parent node matrices
|
|
217
254
|
* @returns {void}
|
|
218
255
|
*/
|
|
219
|
-
function convertNodes(nodes, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, matrix = new core_1.Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])) {
|
|
256
|
+
function convertNodes(nodes, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, matrix = new core_1.Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])) {
|
|
220
257
|
if (nodes) {
|
|
221
258
|
for (const node of nodes) {
|
|
222
|
-
convertNode(node, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, matrix);
|
|
259
|
+
convertNode(node, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, matrix);
|
|
223
260
|
}
|
|
224
261
|
}
|
|
225
262
|
}
|
|
@@ -249,26 +286,31 @@ function getCompositeTransformationMatrix(node, matrix) {
|
|
|
249
286
|
/**
|
|
250
287
|
* Convert all primitives of node and all children nodes
|
|
251
288
|
* @param node - gltf node
|
|
252
|
-
* @param
|
|
289
|
+
* @param images - gltf images array
|
|
290
|
+
* @param cartographicOrigin - cartographic origin of bounding volume
|
|
291
|
+
* @param cartesianModelMatrix - cartesian model matrix to convert coordinates to cartographic
|
|
253
292
|
* @param {Map} attributesMap Map<{positions: Float32Array, normals: Float32Array, texCoords: Float32Array, colors: Uint8Array, featureIndices: Array}> - for recursive concatenation of
|
|
254
293
|
* attributes
|
|
255
294
|
* @param useCartesianPositions - convert positions to absolute cartesian coordinates instead of cartographic offsets.
|
|
256
295
|
* Cartesian coordinates will be required for creating bounding voulmest from geometry positions
|
|
257
296
|
* @param {Matrix4} matrix - transformation matrix - cumulative transformation matrix formed from all parent node matrices
|
|
258
297
|
*/
|
|
259
|
-
function convertNode(node, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, matrix = new core_1.Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])) {
|
|
298
|
+
function convertNode(node, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, matrix = new core_1.Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])) {
|
|
260
299
|
const transformationMatrix = getCompositeTransformationMatrix(node, matrix);
|
|
261
300
|
const mesh = node.mesh;
|
|
262
|
-
const images = node.images;
|
|
263
301
|
if (mesh) {
|
|
264
302
|
convertMesh(mesh, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, transformationMatrix);
|
|
265
303
|
}
|
|
266
|
-
convertNodes(node.children || [], cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, transformationMatrix);
|
|
304
|
+
convertNodes(node.children || [], images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, transformationMatrix);
|
|
267
305
|
}
|
|
268
306
|
/**
|
|
269
|
-
* Convert all primitives of
|
|
270
|
-
* @param mesh - gltf
|
|
271
|
-
* @param
|
|
307
|
+
* Convert all primitives of the mesh
|
|
308
|
+
* @param mesh - gltf mesh data
|
|
309
|
+
* @param images - gltf images array
|
|
310
|
+
* @param cartographicOrigin - cartographic origin of bounding volume
|
|
311
|
+
* @param cartesianModelMatrix - cartesian model matrix to convert coordinates to cartographic
|
|
312
|
+
* @param attributesMap Map<{positions: Float32Array, normals: Float32Array, texCoords: Float32Array, colors: Uint8Array, featureIndices: Array}> - for recursive concatenation of
|
|
313
|
+
* attributes
|
|
272
314
|
* @param useCartesianPositions - convert positions to absolute cartesian coordinates instead of cartographic offsets.
|
|
273
315
|
* Cartesian coordinates will be required for creating bounding voulmest from geometry positions
|
|
274
316
|
* @param attributesMap Map<{positions: Float32Array, normals: Float32Array, texCoords: Float32Array, colors: Uint8Array, featureIndices: Array}> - for recursive concatenation of
|
|
@@ -279,8 +321,10 @@ function convertNode(node, cartographicOrigin, cartesianModelMatrix, attributesM
|
|
|
279
321
|
function convertMesh(mesh, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions = false, matrix = new core_1.Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])) {
|
|
280
322
|
for (const primitive of mesh.primitives) {
|
|
281
323
|
let outputAttributes = null;
|
|
324
|
+
let materialUvRegion;
|
|
282
325
|
if (primitive.material) {
|
|
283
|
-
outputAttributes = attributesMap.get(primitive.material.
|
|
326
|
+
outputAttributes = attributesMap.get(primitive.material.uniqueId);
|
|
327
|
+
materialUvRegion = outputAttributes?.mergedMaterials.find(({ originalMaterialId }) => originalMaterialId === primitive.material?.uniqueId)?.uvRegion;
|
|
284
328
|
}
|
|
285
329
|
else if (attributesMap.has('default')) {
|
|
286
330
|
outputAttributes = attributesMap.get('default');
|
|
@@ -310,6 +354,9 @@ function convertMesh(mesh, images, cartographicOrigin, cartesianModelMatrix, att
|
|
|
310
354
|
}));
|
|
311
355
|
outputAttributes.texCoords = (0, loader_utils_1.concatenateTypedArrays)(outputAttributes.texCoords, flattenTexCoords(attributes.TEXCOORD_0 && attributes.TEXCOORD_0.value, primitive.indices?.value));
|
|
312
356
|
outputAttributes.colors = (0, loader_utils_1.concatenateTypedArrays)(outputAttributes.colors, flattenColors(attributes.COLOR_0, primitive.indices?.value));
|
|
357
|
+
if (materialUvRegion) {
|
|
358
|
+
outputAttributes.uvRegions = (0, loader_utils_1.concatenateTypedArrays)(outputAttributes.uvRegions, createUvRegion(materialUvRegion, primitive.indices?.value));
|
|
359
|
+
}
|
|
313
360
|
outputAttributes.featureIndicesGroups = outputAttributes.featureIndicesGroups || [];
|
|
314
361
|
outputAttributes.featureIndicesGroups.push(flattenBatchIds(getBatchIds(attributes, primitive, images), primitive.indices?.value));
|
|
315
362
|
}
|
|
@@ -430,6 +477,19 @@ function flattenColors(colorsAttribute, indices) {
|
|
|
430
477
|
}
|
|
431
478
|
return newColors;
|
|
432
479
|
}
|
|
480
|
+
/**
|
|
481
|
+
* Create per-vertex uv-region array
|
|
482
|
+
* @param materialUvRegion - uv-region fragment for a single vertex
|
|
483
|
+
* @param indices - geometry indices data
|
|
484
|
+
* @returns - uv-region array
|
|
485
|
+
*/
|
|
486
|
+
function createUvRegion(materialUvRegion, indices) {
|
|
487
|
+
const result = new Uint16Array(indices.length * 4);
|
|
488
|
+
for (let i = 0; i < result.length; i += 4) {
|
|
489
|
+
result.set(materialUvRegion, i);
|
|
490
|
+
}
|
|
491
|
+
return result;
|
|
492
|
+
}
|
|
433
493
|
/**
|
|
434
494
|
* Flatten batchedIds list based on indices to right ordered array, compatible with i3s
|
|
435
495
|
* @param batchedIds - gltf primitive
|
|
@@ -449,9 +509,9 @@ function flattenBatchIds(batchedIds, indices) {
|
|
|
449
509
|
}
|
|
450
510
|
/**
|
|
451
511
|
* Get batchIds for featureIds creation
|
|
452
|
-
* @param attributes
|
|
453
|
-
* @param primitive
|
|
454
|
-
* @param
|
|
512
|
+
* @param attributes - gltf accessors
|
|
513
|
+
* @param primitive - gltf primitive data
|
|
514
|
+
* @param images - gltf texture images
|
|
455
515
|
*/
|
|
456
516
|
function getBatchIds(attributes, primitive, images) {
|
|
457
517
|
const batchIds = (0, batch_ids_extensions_1.handleBatchIdsExtensions)(attributes, primitive, images);
|
|
@@ -470,15 +530,101 @@ function getBatchIds(attributes, primitive, images) {
|
|
|
470
530
|
/**
|
|
471
531
|
* Convert GLTF material to I3S material definitions and textures
|
|
472
532
|
* @param sourceMaterials Source GLTF materials
|
|
533
|
+
* @param shouldMergeMaterials - if true - the converter will try to merge similar materials
|
|
534
|
+
* to be able to merge primitives having those materials
|
|
473
535
|
* @returns Array of Couples I3SMaterialDefinition + texture content
|
|
474
536
|
*/
|
|
475
|
-
function convertMaterials(sourceMaterials = []) {
|
|
476
|
-
|
|
537
|
+
async function convertMaterials(sourceMaterials = [], shouldMergeMaterials) {
|
|
538
|
+
let materials = [];
|
|
477
539
|
for (const sourceMaterial of sourceMaterials) {
|
|
478
|
-
|
|
540
|
+
materials.push(convertMaterial(sourceMaterial));
|
|
541
|
+
}
|
|
542
|
+
if (shouldMergeMaterials) {
|
|
543
|
+
materials = await mergeAllMaterials(materials);
|
|
544
|
+
}
|
|
545
|
+
return materials;
|
|
546
|
+
}
|
|
547
|
+
/**
|
|
548
|
+
* Merge materials when possible
|
|
549
|
+
* @param materials materials array
|
|
550
|
+
* @returns merged materials array
|
|
551
|
+
*/
|
|
552
|
+
async function mergeAllMaterials(materials) {
|
|
553
|
+
const result = [];
|
|
554
|
+
while (materials.length > 0) {
|
|
555
|
+
let newMaterial = materials.splice(0, 1)[0];
|
|
556
|
+
const mergedIndices = [];
|
|
557
|
+
for (let i = 0; i < materials.length; i++) {
|
|
558
|
+
const material = materials[i];
|
|
559
|
+
if ((newMaterial.texture && material.texture) ||
|
|
560
|
+
(!newMaterial.texture && !material.texture)) {
|
|
561
|
+
newMaterial = await mergeMaterials(newMaterial, material);
|
|
562
|
+
mergedIndices.push(i);
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
if (newMaterial.texture && mergedIndices.length) {
|
|
566
|
+
const newWidth = newMaterial.mergedMaterials?.reduce((accum, { textureSize }) => accum + (textureSize?.width || 0), 0);
|
|
567
|
+
const newHeight = newMaterial.mergedMaterials?.reduce((accum, { textureSize }) => Math.max(accum, textureSize?.height || 0), 0);
|
|
568
|
+
let currentX = -1;
|
|
569
|
+
for (const aTextureMetadata of newMaterial.mergedMaterials) {
|
|
570
|
+
if (aTextureMetadata.textureSize) {
|
|
571
|
+
const newX = currentX +
|
|
572
|
+
1 +
|
|
573
|
+
(aTextureMetadata.textureSize.width / newWidth) *
|
|
574
|
+
2 ** (Uint16Array.BYTES_PER_ELEMENT * 8) -
|
|
575
|
+
1;
|
|
576
|
+
aTextureMetadata.uvRegion = new Uint16Array([
|
|
577
|
+
currentX + 1,
|
|
578
|
+
0,
|
|
579
|
+
newX,
|
|
580
|
+
(aTextureMetadata.textureSize.height / newHeight) *
|
|
581
|
+
2 ** (Uint16Array.BYTES_PER_ELEMENT * 8) -
|
|
582
|
+
1
|
|
583
|
+
]);
|
|
584
|
+
currentX = newX;
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
newMaterial.texture.image.width = newWidth;
|
|
588
|
+
newMaterial.texture.image.height = newHeight;
|
|
589
|
+
}
|
|
590
|
+
for (const index of mergedIndices.reverse()) {
|
|
591
|
+
materials.splice(index, 1);
|
|
592
|
+
}
|
|
593
|
+
result.push(newMaterial);
|
|
594
|
+
}
|
|
595
|
+
if (!result.length) {
|
|
596
|
+
result.push({
|
|
597
|
+
material: getDefaultMaterial(),
|
|
598
|
+
mergedMaterials: [{ originalMaterialId: 'default' }]
|
|
599
|
+
});
|
|
479
600
|
}
|
|
480
601
|
return result;
|
|
481
602
|
}
|
|
603
|
+
/**
|
|
604
|
+
* Merge 2 materials including texture
|
|
605
|
+
* @param material1
|
|
606
|
+
* @param material2
|
|
607
|
+
* @returns
|
|
608
|
+
*/
|
|
609
|
+
async function mergeMaterials(material1, material2) {
|
|
610
|
+
if (material1.texture?.bufferView &&
|
|
611
|
+
material2.texture?.bufferView &&
|
|
612
|
+
material1.mergedMaterials &&
|
|
613
|
+
material2.mergedMaterials) {
|
|
614
|
+
const buffer1 = Buffer.from(material1.texture.bufferView.data);
|
|
615
|
+
const buffer2 = Buffer.from(material2.texture.bufferView.data);
|
|
616
|
+
// @ts-ignore
|
|
617
|
+
const { joinImages } = await Promise.resolve().then(() => __importStar(require('join-images')));
|
|
618
|
+
const sharpData = await joinImages([buffer1, buffer2], { direction: 'horizontal' });
|
|
619
|
+
material1.texture.bufferView.data = await sharpData
|
|
620
|
+
.toFormat(material1.texture.mimeType === 'image/png' ? 'png' : 'jpeg')
|
|
621
|
+
.toBuffer();
|
|
622
|
+
// @ts-ignore
|
|
623
|
+
material1.material.pbrMetallicRoughness.baseColorTexture.textureSetDefinitionId = 1;
|
|
624
|
+
}
|
|
625
|
+
material1.mergedMaterials = material1.mergedMaterials.concat(material2.mergedMaterials);
|
|
626
|
+
return material1;
|
|
627
|
+
}
|
|
482
628
|
/**
|
|
483
629
|
* Convert texture and material from gltf 2.0 material object
|
|
484
630
|
* @param sourceMaterial - material object
|
|
@@ -510,6 +656,9 @@ function convertMaterial(sourceMaterial) {
|
|
|
510
656
|
textureSetDefinitionId: 0
|
|
511
657
|
};
|
|
512
658
|
}
|
|
659
|
+
const uniqueId = (0, uuid_1.v4)();
|
|
660
|
+
sourceMaterial.uniqueId = uniqueId;
|
|
661
|
+
let mergedMaterials = [{ originalMaterialId: uniqueId }];
|
|
513
662
|
if (!texture) {
|
|
514
663
|
// Should use default baseColorFactor if it is not present in source material
|
|
515
664
|
// https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#reference-pbrmetallicroughness
|
|
@@ -517,7 +666,10 @@ function convertMaterial(sourceMaterial) {
|
|
|
517
666
|
material.pbrMetallicRoughness.baseColorFactor =
|
|
518
667
|
(baseColorFactor && baseColorFactor.map((c) => Math.round(c * 255))) || undefined;
|
|
519
668
|
}
|
|
520
|
-
|
|
669
|
+
else {
|
|
670
|
+
mergedMaterials[0].textureSize = { width: texture.image.width, height: texture.image.height };
|
|
671
|
+
}
|
|
672
|
+
return { material, texture, mergedMaterials };
|
|
521
673
|
}
|
|
522
674
|
/**
|
|
523
675
|
* Converts from `alphaMode` material property from GLTF to I3S format
|
|
@@ -626,7 +778,9 @@ function extractSharedResourcesMaterialInfo(baseColorFactor, metallicFactor = 1)
|
|
|
626
778
|
const specular = dielectricSpecular.lerp(dielectricSpecular, baseColorVector, metallicFactor);
|
|
627
779
|
return {
|
|
628
780
|
params: {
|
|
781
|
+
// @ts-expect-error NumericArray
|
|
629
782
|
diffuse: diffuse.toArray(),
|
|
783
|
+
// @ts-expect-error NumericArray
|
|
630
784
|
specular: specular.toArray(),
|
|
631
785
|
renderMode: 'solid'
|
|
632
786
|
}
|
|
@@ -653,7 +807,7 @@ function extractSharedResourcesTextureInfo(texture, nodeId) {
|
|
|
653
807
|
};
|
|
654
808
|
}
|
|
655
809
|
/**
|
|
656
|
-
* Formula for
|
|
810
|
+
* Formula for calculating imageId:
|
|
657
811
|
* https://github.com/Esri/i3s-spec/blob/0a6366a9249b831db8436c322f8d27521e86cf07/format/Indexed%203d%20Scene%20Layer%20Format%20Specification.md#generating-image-ids
|
|
658
812
|
* @param texture - texture image info
|
|
659
813
|
* @param nodeId - I3S node ID
|
|
@@ -743,43 +897,53 @@ function replaceIndicesByUnique(indicesArray, featureMap) {
|
|
|
743
897
|
}
|
|
744
898
|
}
|
|
745
899
|
/**
|
|
746
|
-
* Convert
|
|
747
|
-
* @param {Object} batchTable - table with metadata for particular feature.
|
|
900
|
+
* Convert property table data to attribute buffers.
|
|
748
901
|
* @param {Array} featureIds
|
|
902
|
+
* @param {Object} propertyTable - table with metadata for particular feature.
|
|
749
903
|
* @param {Array} attributeStorageInfo
|
|
750
904
|
* @returns {Array} - Array of file buffers.
|
|
751
905
|
*/
|
|
752
|
-
function
|
|
906
|
+
function convertPropertyTableToAttributeBuffers(featureIds, propertyTable, attributeStorageInfo) {
|
|
753
907
|
const attributeBuffers = [];
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
case DOUBLE_TYPE:
|
|
768
|
-
attributeBuffer = generateDoubleAttributeBuffer(batchTableWithFeatureIds[key]);
|
|
769
|
-
break;
|
|
770
|
-
case STRING_TYPE:
|
|
771
|
-
attributeBuffer = generateStringAttributeBuffer(batchTableWithFeatureIds[key]);
|
|
772
|
-
break;
|
|
773
|
-
default:
|
|
774
|
-
attributeBuffer = generateStringAttributeBuffer(batchTableWithFeatureIds[key]);
|
|
775
|
-
}
|
|
776
|
-
if (attributeBuffer) {
|
|
777
|
-
attributeBuffers.push(attributeBuffer);
|
|
778
|
-
}
|
|
779
|
-
}
|
|
908
|
+
const needFlattenPropertyTable = (0, feature_attributes_1.checkPropertiesLength)(featureIds, propertyTable);
|
|
909
|
+
const properties = needFlattenPropertyTable
|
|
910
|
+
? (0, feature_attributes_1.flattenPropertyTableByFeatureIds)(featureIds, propertyTable)
|
|
911
|
+
: propertyTable;
|
|
912
|
+
const propertyTableWithObjectIds = {
|
|
913
|
+
OBJECTID: featureIds,
|
|
914
|
+
...properties
|
|
915
|
+
};
|
|
916
|
+
for (const propertyName in propertyTableWithObjectIds) {
|
|
917
|
+
const type = getAttributeType(propertyName, attributeStorageInfo);
|
|
918
|
+
const value = propertyTableWithObjectIds[propertyName];
|
|
919
|
+
const attributeBuffer = generateAttributeBuffer(type, value);
|
|
920
|
+
attributeBuffers.push(attributeBuffer);
|
|
780
921
|
}
|
|
781
922
|
return attributeBuffers;
|
|
782
923
|
}
|
|
924
|
+
/**
|
|
925
|
+
* Generates attribute buffer based on attribute type
|
|
926
|
+
* @param type
|
|
927
|
+
* @param value
|
|
928
|
+
*/
|
|
929
|
+
function generateAttributeBuffer(type, value) {
|
|
930
|
+
let attributeBuffer;
|
|
931
|
+
switch (type) {
|
|
932
|
+
case OBJECT_ID_TYPE:
|
|
933
|
+
case SHORT_INT_TYPE:
|
|
934
|
+
attributeBuffer = generateShortIntegerAttributeBuffer(value);
|
|
935
|
+
break;
|
|
936
|
+
case DOUBLE_TYPE:
|
|
937
|
+
attributeBuffer = generateDoubleAttributeBuffer(value);
|
|
938
|
+
break;
|
|
939
|
+
case STRING_TYPE:
|
|
940
|
+
attributeBuffer = generateStringAttributeBuffer(value);
|
|
941
|
+
break;
|
|
942
|
+
default:
|
|
943
|
+
attributeBuffer = generateStringAttributeBuffer(value);
|
|
944
|
+
}
|
|
945
|
+
return attributeBuffer;
|
|
946
|
+
}
|
|
783
947
|
/**
|
|
784
948
|
* Return attribute type.
|
|
785
949
|
* @param {String} key
|
|
@@ -853,7 +1017,7 @@ function generateBigUint64Array(featureIds) {
|
|
|
853
1017
|
* @returns {Promise<object>} - COmpressed geometry.
|
|
854
1018
|
*/
|
|
855
1019
|
async function generateCompressedGeometry(vertexCount, convertedAttributes, attributes, dracoWorkerSoure) {
|
|
856
|
-
const { positions, normals, texCoords, colors, featureIds, faceRange } = attributes;
|
|
1020
|
+
const { positions, normals, texCoords, colors, uvRegions, featureIds, faceRange } = attributes;
|
|
857
1021
|
const indices = new Uint32Array(vertexCount);
|
|
858
1022
|
for (let index = 0; index < indices.length; index++) {
|
|
859
1023
|
indices.set([index], index);
|
|
@@ -875,6 +1039,12 @@ async function generateCompressedGeometry(vertexCount, convertedAttributes, attr
|
|
|
875
1039
|
'i3s-feature-ids': new Int32Array(featureIds)
|
|
876
1040
|
}
|
|
877
1041
|
};
|
|
1042
|
+
if (uvRegions.length) {
|
|
1043
|
+
compressedAttributes['uv-region'] = uvRegions;
|
|
1044
|
+
attributesMetadata['uv-region'] = {
|
|
1045
|
+
'i3s-attribute-type': 'uv-region'
|
|
1046
|
+
};
|
|
1047
|
+
}
|
|
878
1048
|
return (0, core_2.encode)({ attributes: compressedAttributes, indices }, draco_1.DracoWriterWorker, {
|
|
879
1049
|
...draco_1.DracoWriterWorker.options,
|
|
880
1050
|
source: dracoWorkerSoure,
|
|
@@ -904,3 +1074,78 @@ function generateFeatureIndexAttribute(featureIndex, faceRange) {
|
|
|
904
1074
|
}
|
|
905
1075
|
return orderedFeatureIndices;
|
|
906
1076
|
}
|
|
1077
|
+
/**
|
|
1078
|
+
* Find property table in tile
|
|
1079
|
+
* For example it can be batchTable for b3dm files or property table in gLTF extension.
|
|
1080
|
+
* @param sourceTile
|
|
1081
|
+
* @return batch table from b3dm / feature properties from EXT_FEATURE_METADATA
|
|
1082
|
+
*/
|
|
1083
|
+
function getPropertyTable(tileContent) {
|
|
1084
|
+
const batchTableJson = tileContent?.batchTableJson;
|
|
1085
|
+
if (batchTableJson) {
|
|
1086
|
+
return batchTableJson;
|
|
1087
|
+
}
|
|
1088
|
+
const { extensionName, extension } = getPropertyTableExtension(tileContent);
|
|
1089
|
+
switch (extensionName) {
|
|
1090
|
+
case EXT_MESH_FEATURES: {
|
|
1091
|
+
console.warn('The I3S converter does not yet support the EXT_mesh_features extension');
|
|
1092
|
+
return null;
|
|
1093
|
+
}
|
|
1094
|
+
case EXT_FEATURE_METADATA: {
|
|
1095
|
+
return getPropertyTableFromExtFeatureMetadata(extension);
|
|
1096
|
+
}
|
|
1097
|
+
default:
|
|
1098
|
+
return null;
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
exports.getPropertyTable = getPropertyTable;
|
|
1102
|
+
/**
|
|
1103
|
+
* Check extensions which can be with property table inside.
|
|
1104
|
+
* @param sourceTile
|
|
1105
|
+
*/
|
|
1106
|
+
function getPropertyTableExtension(tileContent) {
|
|
1107
|
+
const extensionsWithPropertyTables = [EXT_FEATURE_METADATA, EXT_MESH_FEATURES];
|
|
1108
|
+
const extensionsUsed = tileContent?.gltf?.extensionsUsed;
|
|
1109
|
+
if (!extensionsUsed) {
|
|
1110
|
+
return { extensionName: null, extension: null };
|
|
1111
|
+
}
|
|
1112
|
+
let extensionName = '';
|
|
1113
|
+
for (const extensionItem of tileContent?.gltf?.extensionsUsed || []) {
|
|
1114
|
+
if (extensionsWithPropertyTables.includes(extensionItem)) {
|
|
1115
|
+
extensionName = extensionItem;
|
|
1116
|
+
break;
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
const extension = tileContent?.gltf?.extensions?.[extensionName];
|
|
1120
|
+
return { extensionName, extension };
|
|
1121
|
+
}
|
|
1122
|
+
/**
|
|
1123
|
+
* Handle EXT_feature_metadata to get property table
|
|
1124
|
+
* @param extension
|
|
1125
|
+
* TODO add EXT_feature_metadata feature textures support.
|
|
1126
|
+
*/
|
|
1127
|
+
function getPropertyTableFromExtFeatureMetadata(extension) {
|
|
1128
|
+
if (extension?.featureTextures) {
|
|
1129
|
+
console.warn('The I3S converter does not yet support the EXT_feature_metadata feature textures');
|
|
1130
|
+
return null;
|
|
1131
|
+
}
|
|
1132
|
+
if (extension?.featureTables) {
|
|
1133
|
+
/**
|
|
1134
|
+
* Take only first feature table to generate attributes storage info object.
|
|
1135
|
+
* TODO: Think about getting data from all feature tables?
|
|
1136
|
+
* It can be tricky just because 3dTiles is able to have multiple featureId attributes and multiple feature tables.
|
|
1137
|
+
* In I3S we should decide which featureIds attribute will be passed to geometry data.
|
|
1138
|
+
*/
|
|
1139
|
+
const firstFeatureTableName = Object.keys(extension.featureTables)?.[0];
|
|
1140
|
+
if (firstFeatureTableName) {
|
|
1141
|
+
const featureTable = extension?.featureTables[firstFeatureTableName];
|
|
1142
|
+
const propertyTable = {};
|
|
1143
|
+
for (const propertyName in featureTable.properties) {
|
|
1144
|
+
propertyTable[propertyName] = featureTable.properties[propertyName].data;
|
|
1145
|
+
}
|
|
1146
|
+
return propertyTable;
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
console.warn("The I3S converter couldn't handle EXT_feature_metadata extension");
|
|
1150
|
+
return null;
|
|
1151
|
+
}
|