@loaders.gl/tile-converter 4.0.0-alpha.22 → 4.0.0-alpha.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/3d-tiles-converter/helpers/load-i3s.d.ts.map +1 -1
- package/dist/constants.d.ts +0 -2
- package/dist/constants.d.ts.map +1 -1
- package/dist/converter.min.js +106 -106
- package/dist/dist.min.js +1883 -1241
- package/dist/es5/3d-tiles-converter/helpers/load-i3s.js.map +1 -1
- package/dist/es5/constants.js +1 -5
- package/dist/es5/constants.js.map +1 -1
- package/dist/es5/deps-installer/deps-installer.js +1 -1
- package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js +26 -11
- package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/feature-attributes.js +7 -17
- package/dist/es5/i3s-converter/helpers/feature-attributes.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/geometry-attributes.js +83 -44
- package/dist/es5/i3s-converter/helpers/geometry-attributes.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/geometry-converter.js +70 -17
- package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/node-index-document.js +3 -2
- package/dist/es5/i3s-converter/helpers/node-index-document.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/preprocess-3d-tiles.js +1 -2
- package/dist/es5/i3s-converter/helpers/preprocess-3d-tiles.js.map +1 -1
- package/dist/es5/i3s-converter/i3s-converter.js +36 -26
- package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
- package/dist/es5/i3s-converter/types.js.map +1 -1
- package/dist/es5/i3s-server/controllers/slpk-controller.js +2 -2
- package/dist/es5/i3s-server/controllers/slpk-controller.js.map +1 -1
- package/dist/es5/pgm-loader.js +11 -3
- package/dist/es5/pgm-loader.js.map +1 -1
- package/dist/es5/slpk-extractor/slpk-extractor.js +1 -1
- package/dist/es5/slpk-extractor/slpk-extractor.js.map +1 -1
- package/dist/esm/3d-tiles-converter/helpers/load-i3s.js.map +1 -1
- package/dist/esm/constants.js +0 -2
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/deps-installer/deps-installer.js +1 -1
- package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js +21 -6
- package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/feature-attributes.js +9 -7
- package/dist/esm/i3s-converter/helpers/feature-attributes.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/geometry-attributes.js +76 -34
- package/dist/esm/i3s-converter/helpers/geometry-attributes.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/geometry-converter.js +66 -13
- package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/node-index-document.js +2 -1
- package/dist/esm/i3s-converter/helpers/node-index-document.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/preprocess-3d-tiles.js +1 -1
- package/dist/esm/i3s-converter/helpers/preprocess-3d-tiles.js.map +1 -1
- package/dist/esm/i3s-converter/i3s-converter.js +20 -17
- package/dist/esm/i3s-converter/i3s-converter.js.map +1 -1
- package/dist/esm/i3s-converter/types.js.map +1 -1
- package/dist/esm/i3s-server/bin/i3s-server.min.js +71 -71
- package/dist/esm/i3s-server/controllers/slpk-controller.js +1 -1
- package/dist/esm/i3s-server/controllers/slpk-controller.js.map +1 -1
- package/dist/esm/pgm-loader.js +7 -4
- package/dist/esm/pgm-loader.js.map +1 -1
- package/dist/esm/slpk-extractor/slpk-extractor.js +2 -1
- package/dist/esm/slpk-extractor/slpk-extractor.js.map +1 -1
- package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/feature-attributes.d.ts +6 -6
- package/dist/i3s-converter/helpers/feature-attributes.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/geometry-attributes.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/geometry-converter.d.ts +2 -2
- package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/node-index-document.d.ts.map +1 -1
- package/dist/i3s-converter/i3s-converter.d.ts +1 -1
- package/dist/i3s-converter/i3s-converter.d.ts.map +1 -1
- package/dist/i3s-converter/types.d.ts +7 -4
- package/dist/i3s-converter/types.d.ts.map +1 -1
- package/dist/pgm-loader.d.ts +9 -2
- package/dist/pgm-loader.d.ts.map +1 -1
- package/dist/slpk-extractor/slpk-extractor.d.ts.map +1 -1
- package/dist/slpk-extractor.min.js +38 -38
- package/package.json +14 -14
- package/src/3d-tiles-converter/helpers/load-i3s.ts +1 -0
- package/src/constants.ts +0 -3
- package/src/i3s-converter/helpers/batch-ids-extensions.ts +53 -14
- package/src/i3s-converter/helpers/feature-attributes.ts +20 -15
- package/src/i3s-converter/helpers/geometry-attributes.ts +80 -50
- package/src/i3s-converter/helpers/geometry-converter.ts +153 -21
- package/src/i3s-converter/helpers/node-index-document.ts +5 -1
- package/src/i3s-converter/helpers/preprocess-3d-tiles.ts +1 -1
- package/src/i3s-converter/i3s-converter.ts +42 -17
- package/src/i3s-converter/types.ts +8 -4
- package/src/i3s-server/controllers/slpk-controller.ts +1 -1
- package/src/pgm-loader.ts +15 -7
- package/src/slpk-extractor/slpk-extractor.ts +2 -1
- package/dist/3d-tiles-converter/3d-tiles-converter.js +0 -279
- package/dist/3d-tiles-converter/helpers/b3dm-converter.js +0 -271
- package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +0 -23
- package/dist/3d-tiles-converter/helpers/load-i3s.js +0 -42
- package/dist/3d-tiles-converter/helpers/texture-atlas.js +0 -54
- package/dist/3d-tiles-converter/json-templates/tileset.js +0 -43
- package/dist/bundle.js +0 -5
- package/dist/constants.js +0 -6
- package/dist/converter-cli.js +0 -222
- package/dist/deps-installer/deps-installer.js +0 -89
- package/dist/i3s-converter/helpers/batch-ids-extensions.js +0 -158
- package/dist/i3s-converter/helpers/coordinate-converter.js +0 -122
- package/dist/i3s-converter/helpers/create-scene-server-path.js +0 -28
- package/dist/i3s-converter/helpers/feature-attributes.js +0 -216
- package/dist/i3s-converter/helpers/geometry-attributes.js +0 -203
- package/dist/i3s-converter/helpers/geometry-converter.js +0 -1240
- package/dist/i3s-converter/helpers/gltf-attributes.js +0 -129
- package/dist/i3s-converter/helpers/load-3d-tiles.js +0 -99
- package/dist/i3s-converter/helpers/node-debug.js +0 -120
- package/dist/i3s-converter/helpers/node-index-document.js +0 -268
- package/dist/i3s-converter/helpers/node-pages.js +0 -316
- package/dist/i3s-converter/helpers/preprocess-3d-tiles.js +0 -100
- package/dist/i3s-converter/helpers/tileset-traversal.js +0 -29
- package/dist/i3s-converter/i3s-converter.js +0 -945
- package/dist/i3s-converter/json-templates/geometry-definitions.js +0 -87
- package/dist/i3s-converter/json-templates/layers.js +0 -139
- package/dist/i3s-converter/json-templates/metadata.js +0 -25
- package/dist/i3s-converter/json-templates/node.js +0 -89
- package/dist/i3s-converter/json-templates/scene-server.js +0 -31
- package/dist/i3s-converter/json-templates/shared-resources.js +0 -129
- package/dist/i3s-converter/json-templates/store.js +0 -103
- package/dist/i3s-converter/types.js +0 -17
- package/dist/i3s-server/app.js +0 -29
- package/dist/i3s-server/bin/www.js +0 -37
- package/dist/i3s-server/controllers/index-controller.js +0 -31
- package/dist/i3s-server/controllers/slpk-controller.js +0 -33
- package/dist/i3s-server/routes/index.js +0 -20
- package/dist/i3s-server/routes/slpk-router.js +0 -34
- package/dist/i3s-server/utils/create-scene-server.js +0 -22
- package/dist/i3s-server/utils/server-utils.js +0 -66
- package/dist/index.js +0 -10
- package/dist/lib/utils/cli-utils.js +0 -82
- package/dist/lib/utils/compress-util.js +0 -257
- package/dist/lib/utils/file-utils.js +0 -139
- package/dist/lib/utils/geometry-utils.js +0 -18
- package/dist/lib/utils/lod-conversion-utils.js +0 -76
- package/dist/lib/utils/queue.js +0 -18
- package/dist/lib/utils/statistic-utills.js +0 -64
- package/dist/lib/utils/write-queue.js +0 -80
- package/dist/pgm-loader.js +0 -24
- package/dist/slpk-extractor/slpk-extractor.js +0 -74
- package/dist/slpk-extractor-cli.js +0 -102
|
@@ -1,279 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const path_1 = require("path");
|
|
7
|
-
const process_1 = __importDefault(require("process"));
|
|
8
|
-
const json_map_transform_1 = __importDefault(require("json-map-transform"));
|
|
9
|
-
const core_1 = require("@loaders.gl/core");
|
|
10
|
-
const i3s_1 = require("@loaders.gl/i3s");
|
|
11
|
-
const pgm_loader_1 = require("../pgm-loader");
|
|
12
|
-
const i3s_obb_to_3d_tiles_obb_1 = require("./helpers/i3s-obb-to-3d-tiles-obb");
|
|
13
|
-
const lod_conversion_utils_1 = require("../lib/utils/lod-conversion-utils");
|
|
14
|
-
const file_utils_1 = require("../lib/utils/file-utils");
|
|
15
|
-
const statistic_utills_1 = require("../lib/utils/statistic-utills");
|
|
16
|
-
const tileset_1 = require("./json-templates/tileset");
|
|
17
|
-
const coordinate_converter_1 = require("../i3s-converter/helpers/coordinate-converter");
|
|
18
|
-
const worker_utils_1 = require("@loaders.gl/worker-utils");
|
|
19
|
-
const constants_1 = require("../constants");
|
|
20
|
-
const b3dm_converter_1 = __importDefault(require("./helpers/b3dm-converter"));
|
|
21
|
-
const load_i3s_1 = require("./helpers/load-i3s");
|
|
22
|
-
const I3S = 'I3S';
|
|
23
|
-
/**
|
|
24
|
-
* Converter from i3s to 3d-tiles
|
|
25
|
-
*/
|
|
26
|
-
class Tiles3DConverter {
|
|
27
|
-
constructor() {
|
|
28
|
-
this.workerSource = {};
|
|
29
|
-
this.loaderOptions = {
|
|
30
|
-
_nodeWorkers: true,
|
|
31
|
-
reuseWorkers: true,
|
|
32
|
-
i3s: { coordinateSystem: i3s_1.COORDINATE_SYSTEM.LNGLAT_OFFSETS, decodeTextures: false },
|
|
33
|
-
// We need to load local fs workers because nodejs can't load workers from the Internet
|
|
34
|
-
'i3s-content': {
|
|
35
|
-
workerUrl: './modules/i3s/dist/i3s-content-worker-node.js'
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
this.options = {};
|
|
39
|
-
this.tilesetPath = '';
|
|
40
|
-
this.vertexCounter = 0;
|
|
41
|
-
this.conversionStartTime = [0, 0];
|
|
42
|
-
this.geoidHeightModel = null;
|
|
43
|
-
this.sourceTileset = null;
|
|
44
|
-
this.attributeStorageInfo = null;
|
|
45
|
-
this.workerSource = {};
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Convert i3s format data to 3dTiles
|
|
49
|
-
* @param options
|
|
50
|
-
* @param options.inputUrl the url to read the tileset from
|
|
51
|
-
* @param options.outputPath the output filename
|
|
52
|
-
* @param options.tilesetName the output name of the tileset
|
|
53
|
-
* @param options.egmFilePath location of *.pgm file to convert heights from ellipsoidal to gravity-related format
|
|
54
|
-
* @param options.maxDepth The max tree depth of conversion
|
|
55
|
-
*/
|
|
56
|
-
async convert(options) {
|
|
57
|
-
if (core_1.isBrowser) {
|
|
58
|
-
console.log(constants_1.BROWSER_ERROR_MESSAGE);
|
|
59
|
-
return constants_1.BROWSER_ERROR_MESSAGE;
|
|
60
|
-
}
|
|
61
|
-
const { inputUrl, outputPath, tilesetName, maxDepth, egmFilePath } = options;
|
|
62
|
-
this.conversionStartTime = process_1.default.hrtime();
|
|
63
|
-
this.options = { maxDepth };
|
|
64
|
-
console.log('Loading egm file...'); // eslint-disable-line
|
|
65
|
-
this.geoidHeightModel = await (0, core_1.load)(egmFilePath, pgm_loader_1.PGMLoader);
|
|
66
|
-
console.log('Loading egm file completed!'); // eslint-disable-line
|
|
67
|
-
this.sourceTileset = await (0, core_1.load)(inputUrl, i3s_1.I3SLoader, this.loaderOptions);
|
|
68
|
-
if (!this.sourceTileset) {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
const rootNode = this.sourceTileset?.root;
|
|
72
|
-
if (!rootNode.obb) {
|
|
73
|
-
rootNode.obb = (0, coordinate_converter_1.createObbFromMbs)(rootNode.mbs);
|
|
74
|
-
}
|
|
75
|
-
this.tilesetPath = (0, path_1.join)(`${outputPath}`, `${tilesetName}`);
|
|
76
|
-
this.attributeStorageInfo = this.sourceTileset.attributeStorageInfo;
|
|
77
|
-
// Removing the tilesetPath needed to exclude erroneous files after conversion
|
|
78
|
-
try {
|
|
79
|
-
await (0, file_utils_1.removeDir)(this.tilesetPath);
|
|
80
|
-
}
|
|
81
|
-
catch (e) {
|
|
82
|
-
// do nothing
|
|
83
|
-
}
|
|
84
|
-
const rootTile = {
|
|
85
|
-
boundingVolume: {
|
|
86
|
-
box: (0, i3s_obb_to_3d_tiles_obb_1.i3sObbTo3dTilesObb)(rootNode.obb, this.geoidHeightModel)
|
|
87
|
-
},
|
|
88
|
-
geometricError: (0, lod_conversion_utils_1.convertScreenThresholdToGeometricError)(rootNode),
|
|
89
|
-
children: []
|
|
90
|
-
};
|
|
91
|
-
await this._addChildren(rootNode, rootTile, 1);
|
|
92
|
-
const tileset = (0, json_map_transform_1.default)({ root: rootTile }, (0, tileset_1.TILESET)());
|
|
93
|
-
await (0, file_utils_1.writeFile)(this.tilesetPath, JSON.stringify(tileset), 'tileset.json');
|
|
94
|
-
this._finishConversion({ slpk: false, outputPath, tilesetName });
|
|
95
|
-
// Clean up worker pools
|
|
96
|
-
const workerFarm = worker_utils_1.WorkerFarm.getWorkerFarm({});
|
|
97
|
-
workerFarm.destroy();
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Convert particular I3S Node
|
|
101
|
-
* @param parentSourceNode the parent node tile object (@loaders.gl/tiles/Tile3D)
|
|
102
|
-
* @param parentNode object in resulting tileset
|
|
103
|
-
* @param level a current level of a tree depth
|
|
104
|
-
* @param childNodeInfo child node to convert
|
|
105
|
-
*/
|
|
106
|
-
async convertChildNode(parentSourceNode, parentNode, level, childNodeInfo) {
|
|
107
|
-
const sourceChild = await this._loadChildNode(parentSourceNode, childNodeInfo);
|
|
108
|
-
if (sourceChild.contentUrl) {
|
|
109
|
-
const content = await (0, load_i3s_1.loadI3SContent)(this.sourceTileset, sourceChild, this.loaderOptions);
|
|
110
|
-
if (!content) {
|
|
111
|
-
await this._addChildren(sourceChild, parentNode, level + 1);
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
this.vertexCounter += content?.vertexCount || 0;
|
|
115
|
-
let featureAttributes = null;
|
|
116
|
-
if (this.attributeStorageInfo) {
|
|
117
|
-
featureAttributes = await this._loadChildAttributes(sourceChild, this.attributeStorageInfo);
|
|
118
|
-
}
|
|
119
|
-
if (!sourceChild.obb) {
|
|
120
|
-
sourceChild.obb = (0, coordinate_converter_1.createObbFromMbs)(sourceChild.mbs);
|
|
121
|
-
}
|
|
122
|
-
const boundingVolume = {
|
|
123
|
-
box: (0, i3s_obb_to_3d_tiles_obb_1.i3sObbTo3dTilesObb)(sourceChild.obb, this.geoidHeightModel)
|
|
124
|
-
};
|
|
125
|
-
const child = {
|
|
126
|
-
boundingVolume,
|
|
127
|
-
geometricError: (0, lod_conversion_utils_1.convertScreenThresholdToGeometricError)(sourceChild),
|
|
128
|
-
children: []
|
|
129
|
-
};
|
|
130
|
-
const i3sAttributesData = {
|
|
131
|
-
tileContent: content,
|
|
132
|
-
box: boundingVolume.box,
|
|
133
|
-
textureFormat: sourceChild.textureFormat
|
|
134
|
-
};
|
|
135
|
-
const b3dmConverter = new b3dm_converter_1.default();
|
|
136
|
-
const b3dm = await b3dmConverter.convert(i3sAttributesData, featureAttributes);
|
|
137
|
-
child.content = {
|
|
138
|
-
uri: `${sourceChild.id}.b3dm`,
|
|
139
|
-
boundingVolume
|
|
140
|
-
};
|
|
141
|
-
await (0, file_utils_1.writeFile)(this.tilesetPath, new Uint8Array(b3dm), `${sourceChild.id}.b3dm`);
|
|
142
|
-
parentNode.children.push(child);
|
|
143
|
-
await this._addChildren(sourceChild, child, level + 1);
|
|
144
|
-
}
|
|
145
|
-
else {
|
|
146
|
-
await this._addChildren(sourceChild, parentNode, level + 1);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* The recursive function of traversal of a nodes tree
|
|
151
|
-
* @param parentSourceNode the parent node tile object (@loaders.gl/tiles/Tile3D)
|
|
152
|
-
* @param parentNode object in resulting tileset
|
|
153
|
-
* @param level a current level of a tree depth
|
|
154
|
-
*/
|
|
155
|
-
async _addChildren(parentSourceNode, parentNode, level) {
|
|
156
|
-
if (this.options.maxDepth && level > this.options.maxDepth) {
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
const promises = [];
|
|
160
|
-
for (const childNodeInfo of parentSourceNode.children || []) {
|
|
161
|
-
promises.push(this.convertChildNode(parentSourceNode, parentNode, level, childNodeInfo));
|
|
162
|
-
}
|
|
163
|
-
await Promise.all(promises);
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Load a child node having information from the node header
|
|
167
|
-
* @param parentNode a parent node tile object (@loaders.gl/tiles/Tile3D)
|
|
168
|
-
* @param childNodeInfo child information from 3DNodeIndexDocument
|
|
169
|
-
* (https://github.com/Esri/i3s-spec/blob/master/docs/1.7/nodeReference.cmn.md)
|
|
170
|
-
*/
|
|
171
|
-
async _loadChildNode(parentNode, childNodeInfo) {
|
|
172
|
-
let header;
|
|
173
|
-
if (this.sourceTileset?.nodePagesTile) {
|
|
174
|
-
console.log(`Node conversion: ${childNodeInfo.id}`); // eslint-disable-line no-console,no-undef
|
|
175
|
-
header = await this.sourceTileset.nodePagesTile.formTileFromNodePages(parseInt(childNodeInfo.id));
|
|
176
|
-
}
|
|
177
|
-
else {
|
|
178
|
-
const nodeUrl = this._relativeUrlToFullUrl(parentNode.url, childNodeInfo.href);
|
|
179
|
-
// load metadata
|
|
180
|
-
const options = {
|
|
181
|
-
i3s: {
|
|
182
|
-
...this.loaderOptions,
|
|
183
|
-
isTileHeader: true,
|
|
184
|
-
loadContent: false
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
console.log(`Node conversion: ${nodeUrl}`); // eslint-disable-line no-console,no-undef
|
|
188
|
-
header = await (0, core_1.load)(nodeUrl, i3s_1.I3SLoader, options);
|
|
189
|
-
}
|
|
190
|
-
return header;
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* Make an url of a resource from its relative url having the base url
|
|
194
|
-
* @param baseUrl the base url. A resulting url will be related from this url
|
|
195
|
-
* @param relativeUrl a realtive url of a resource
|
|
196
|
-
*/
|
|
197
|
-
_relativeUrlToFullUrl(baseUrl = '', relativeUrl) {
|
|
198
|
-
let resultArray = baseUrl.split('/');
|
|
199
|
-
const relativeUrlArray = relativeUrl.split('/');
|
|
200
|
-
for (const folder of relativeUrlArray) {
|
|
201
|
-
switch (folder) {
|
|
202
|
-
case '.':
|
|
203
|
-
continue; // eslint-disable-line no-continue
|
|
204
|
-
case '..':
|
|
205
|
-
resultArray = resultArray.slice(0, -1);
|
|
206
|
-
break;
|
|
207
|
-
default:
|
|
208
|
-
resultArray.push(folder);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
return resultArray.join('/');
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Do loading all attributes related to particular node.
|
|
215
|
-
* @param sourceChild
|
|
216
|
-
* @param attributeStorageInfo
|
|
217
|
-
* @returns Promise of attributes object.
|
|
218
|
-
*/
|
|
219
|
-
async _loadChildAttributes(sourceChild, attributeStorageInfo) {
|
|
220
|
-
const promises = [];
|
|
221
|
-
const { attributeUrls = [] } = sourceChild;
|
|
222
|
-
for (let index = 0; index < attributeUrls.length; index++) {
|
|
223
|
-
const inputUrl = attributeUrls[index];
|
|
224
|
-
const attribute = attributeStorageInfo[index];
|
|
225
|
-
const options = {
|
|
226
|
-
attributeName: attribute.name,
|
|
227
|
-
attributeType: this._getAttributeType(attribute)
|
|
228
|
-
};
|
|
229
|
-
promises.push((0, core_1.load)(inputUrl, i3s_1.I3SAttributeLoader, options));
|
|
230
|
-
}
|
|
231
|
-
const attributesList = await Promise.all(promises);
|
|
232
|
-
this._replaceNestedArrays(attributesList);
|
|
233
|
-
return Object.assign({}, ...attributesList);
|
|
234
|
-
}
|
|
235
|
-
/**
|
|
236
|
-
* Returns attribute type for loading attributes
|
|
237
|
-
* @param attribute
|
|
238
|
-
* Workaround for I3S v1.6. There is no attribute.attributeValues.valueType field in attribute.
|
|
239
|
-
* There is an 'Oid32' type if attribute has objectIds property.
|
|
240
|
-
* Doc: https://github.com/Esri/i3s-spec/blob/master/docs/1.6/attributeStorageInfo.cmn.md
|
|
241
|
-
*/
|
|
242
|
-
_getAttributeType(attribute) {
|
|
243
|
-
if (attribute.attributeValues) {
|
|
244
|
-
return attribute.attributeValues.valueType;
|
|
245
|
-
}
|
|
246
|
-
else if (attribute.objectIds) {
|
|
247
|
-
return 'Oid32';
|
|
248
|
-
}
|
|
249
|
-
return '';
|
|
250
|
-
}
|
|
251
|
-
/**
|
|
252
|
-
* Make simple arrays from attribute typed arrays.
|
|
253
|
-
* @param attributesList
|
|
254
|
-
*/
|
|
255
|
-
_replaceNestedArrays(attributesList) {
|
|
256
|
-
for (let index = 0; index < attributesList.length; index++) {
|
|
257
|
-
const attributeObject = attributesList[index];
|
|
258
|
-
for (const key in attributeObject) {
|
|
259
|
-
attributeObject[key] = Array.from(attributeObject[key]);
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
/**
|
|
264
|
-
* Print statistics in the end of conversion
|
|
265
|
-
* @param params - output files data
|
|
266
|
-
*/
|
|
267
|
-
async _finishConversion(params) {
|
|
268
|
-
const filesSize = await (0, statistic_utills_1.calculateFilesSize)(params);
|
|
269
|
-
const diff = process_1.default.hrtime(this.conversionStartTime);
|
|
270
|
-
const conversionTime = (0, statistic_utills_1.timeConverter)(diff);
|
|
271
|
-
console.log(`------------------------------------------------`); // eslint-disable-line
|
|
272
|
-
console.log(`Finish conversion of ${I3S}`); // eslint-disable-line
|
|
273
|
-
console.log(`Total conversion time: ${conversionTime}`); // eslint-disable-line
|
|
274
|
-
console.log(`Vertex count: `, this.vertexCounter); // eslint-disable-line
|
|
275
|
-
console.log(`File(s) size: `, filesSize, ' bytes'); // eslint-disable-line
|
|
276
|
-
console.log(`------------------------------------------------`); // eslint-disable-line
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
exports.default = Tiles3DConverter;
|
|
@@ -1,271 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const core_1 = require("@loaders.gl/core");
|
|
4
|
-
const gltf_1 = require("@loaders.gl/gltf");
|
|
5
|
-
const _3d_tiles_1 = require("@loaders.gl/3d-tiles");
|
|
6
|
-
const core_2 = require("@math.gl/core");
|
|
7
|
-
const geospatial_1 = require("@math.gl/geospatial");
|
|
8
|
-
const texture_atlas_1 = require("./texture-atlas");
|
|
9
|
-
const geometry_utils_1 = require("../../lib/utils/geometry-utils");
|
|
10
|
-
const Z_UP_TO_Y_UP_MATRIX = new core_2.Matrix4([1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1]);
|
|
11
|
-
const scratchVector = new core_2.Vector3();
|
|
12
|
-
/**
|
|
13
|
-
* Converts content of an I3S node to *.b3dm's file content
|
|
14
|
-
*/
|
|
15
|
-
class B3dmConverter {
|
|
16
|
-
/**
|
|
17
|
-
* The starter of content conversion
|
|
18
|
-
* @param i3sTile - Tile3D instance for I3S node
|
|
19
|
-
* @returns - encoded content
|
|
20
|
-
*/
|
|
21
|
-
async convert(i3sAttributesData, featureAttributes = null) {
|
|
22
|
-
const gltf = await this.buildGltf(i3sAttributesData, featureAttributes);
|
|
23
|
-
const b3dm = (0, core_1.encodeSync)({
|
|
24
|
-
gltfEncoded: new Uint8Array(gltf),
|
|
25
|
-
type: 'b3dm',
|
|
26
|
-
featuresLength: this._getFeaturesLength(featureAttributes),
|
|
27
|
-
batchTable: featureAttributes
|
|
28
|
-
}, _3d_tiles_1.Tile3DWriter);
|
|
29
|
-
return b3dm;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Build and encode gltf
|
|
33
|
-
* @param i3sTile - Tile3D instance for I3S node
|
|
34
|
-
* @returns - encoded glb content
|
|
35
|
-
*/
|
|
36
|
-
async buildGltf(i3sAttributesData, featureAttributes) {
|
|
37
|
-
const { tileContent, textureFormat, box } = i3sAttributesData;
|
|
38
|
-
const { material, attributes, indices: originalIndices, modelMatrix } = tileContent;
|
|
39
|
-
const gltfBuilder = new gltf_1.GLTFScenegraph();
|
|
40
|
-
const textureIndex = await this._addI3sTextureToGltf(tileContent, textureFormat, gltfBuilder);
|
|
41
|
-
const pbrMaterialInfo = this._convertI3sMaterialToGltfMaterial(material, textureIndex);
|
|
42
|
-
const materialIndex = gltfBuilder.addMaterial(pbrMaterialInfo);
|
|
43
|
-
const positions = attributes.positions;
|
|
44
|
-
const positionsValue = positions.value;
|
|
45
|
-
if (attributes.uvRegions && attributes.texCoords) {
|
|
46
|
-
attributes.texCoords.value = (0, texture_atlas_1.convertTextureAtlas)(attributes.texCoords.value, attributes.uvRegions.value);
|
|
47
|
-
}
|
|
48
|
-
const cartesianOrigin = new core_2.Vector3(box);
|
|
49
|
-
const cartographicOrigin = geospatial_1.Ellipsoid.WGS84.cartesianToCartographic(cartesianOrigin, new core_2.Vector3());
|
|
50
|
-
attributes.positions.value = this._normalizePositions(positionsValue, cartesianOrigin, cartographicOrigin, modelMatrix);
|
|
51
|
-
this._createBatchIds(tileContent, featureAttributes);
|
|
52
|
-
if (attributes.normals && !this._checkNormals(attributes.normals.value)) {
|
|
53
|
-
delete attributes.normals;
|
|
54
|
-
}
|
|
55
|
-
const indices = originalIndices || (0, geometry_utils_1.generateSyntheticIndices)(positionsValue.length / positions.size);
|
|
56
|
-
const meshIndex = gltfBuilder.addMesh({
|
|
57
|
-
attributes,
|
|
58
|
-
indices,
|
|
59
|
-
material: materialIndex,
|
|
60
|
-
mode: 4
|
|
61
|
-
});
|
|
62
|
-
const transformMatrix = this._generateTransformMatrix(cartesianOrigin);
|
|
63
|
-
const nodeIndex = gltfBuilder.addNode({ meshIndex, matrix: transformMatrix });
|
|
64
|
-
const sceneIndex = gltfBuilder.addScene({ nodeIndices: [nodeIndex] });
|
|
65
|
-
gltfBuilder.setDefaultScene(sceneIndex);
|
|
66
|
-
gltfBuilder.createBinaryChunk();
|
|
67
|
-
const gltfBuffer = (0, core_1.encodeSync)(gltfBuilder.gltf, gltf_1.GLTFWriter);
|
|
68
|
-
return gltfBuffer;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Update gltfBuilder with texture from I3S tile
|
|
72
|
-
* @param {object} i3sTile - Tile3D object
|
|
73
|
-
* @param {GLTFScenegraph} gltfBuilder - gltfScenegraph instance to construct GLTF
|
|
74
|
-
* @returns {Promise<number | null>} - GLTF texture index
|
|
75
|
-
*/
|
|
76
|
-
async _addI3sTextureToGltf(tileContent, textureFormat, gltfBuilder) {
|
|
77
|
-
const { texture, material, attributes } = tileContent;
|
|
78
|
-
let textureIndex = null;
|
|
79
|
-
let selectedTexture = texture;
|
|
80
|
-
if (!texture && material) {
|
|
81
|
-
selectedTexture =
|
|
82
|
-
material.pbrMetallicRoughness &&
|
|
83
|
-
material.pbrMetallicRoughness.baseColorTexture &&
|
|
84
|
-
material.pbrMetallicRoughness.baseColorTexture.texture.source.image;
|
|
85
|
-
}
|
|
86
|
-
if (selectedTexture) {
|
|
87
|
-
const mimeType = this._deduceMimeTypeFromFormat(textureFormat);
|
|
88
|
-
const imageIndex = gltfBuilder.addImage(selectedTexture, mimeType);
|
|
89
|
-
textureIndex = gltfBuilder.addTexture({ imageIndex });
|
|
90
|
-
delete attributes.colors;
|
|
91
|
-
}
|
|
92
|
-
return textureIndex;
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Generate a positions array which is correct for 3DTiles/GLTF format
|
|
96
|
-
* @param {Float64Array} positionsValue - the input geometry positions array
|
|
97
|
-
* @param {number[]} cartesianOrigin - the tile center in the cartesian coordinate system
|
|
98
|
-
* @param {number[]} cartographicOrigin - the tile center in the cartographic coordinate system
|
|
99
|
-
* @param {number[]} modelMatrix - the model matrix of geometry
|
|
100
|
-
* @returns {Float32Array} - the output geometry positions array
|
|
101
|
-
*/
|
|
102
|
-
_normalizePositions(positionsValue, cartesianOrigin, cartographicOrigin, modelMatrix) {
|
|
103
|
-
const newPositionsValue = new Float32Array(positionsValue.length);
|
|
104
|
-
for (let index = 0; index < positionsValue.length; index += 3) {
|
|
105
|
-
const vertex = positionsValue.subarray(index, index + 3);
|
|
106
|
-
const cartesianOriginVector = new core_2.Vector3(cartesianOrigin);
|
|
107
|
-
let vertexVector = new core_2.Vector3(Array.from(vertex))
|
|
108
|
-
.transform(modelMatrix)
|
|
109
|
-
.add(cartographicOrigin);
|
|
110
|
-
geospatial_1.Ellipsoid.WGS84.cartographicToCartesian(vertexVector, scratchVector);
|
|
111
|
-
vertexVector = scratchVector.subtract(cartesianOriginVector);
|
|
112
|
-
newPositionsValue.set(vertexVector, index);
|
|
113
|
-
}
|
|
114
|
-
return newPositionsValue;
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Generate the transformation matrix for GLTF node:
|
|
118
|
-
* https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#reference-node
|
|
119
|
-
* 1. Create the translate transformation from cartesianOrigin (the positions array stores offsets from this cartesianOrigin)
|
|
120
|
-
* 2. Create the rotation transformation to rotate model from z-up coordinates (I3S specific) to y-up coordinates (GLTF specific)
|
|
121
|
-
* @param {number[]} cartesianOrigin - the tile center in the cartesian coordinate system
|
|
122
|
-
* @returns {Matrix4} - an array of 16 numbers (4x4 matrix)
|
|
123
|
-
*/
|
|
124
|
-
_generateTransformMatrix(cartesianOrigin) {
|
|
125
|
-
const translateOriginMatrix = new core_2.Matrix4().translate(cartesianOrigin);
|
|
126
|
-
const result = translateOriginMatrix.multiplyLeft(Z_UP_TO_Y_UP_MATRIX);
|
|
127
|
-
return result;
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Create _BATCHID attribute
|
|
131
|
-
* @param {Object} i3sContent - the source object
|
|
132
|
-
* @returns {void}
|
|
133
|
-
*/
|
|
134
|
-
_createBatchIds(i3sContent, featureAttributes) {
|
|
135
|
-
const { featureIds } = i3sContent;
|
|
136
|
-
const { OBJECTID: objectIds } = featureAttributes || {};
|
|
137
|
-
if (!featureIds || !objectIds) {
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
for (let i = 0; i < featureIds.length; i++) {
|
|
141
|
-
const featureId = featureIds[i];
|
|
142
|
-
const batchId = objectIds.indexOf(featureId);
|
|
143
|
-
featureIds[i] = batchId;
|
|
144
|
-
}
|
|
145
|
-
i3sContent.attributes._BATCHID = {
|
|
146
|
-
size: 1,
|
|
147
|
-
byteOffset: 0,
|
|
148
|
-
value: featureIds
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Deduce mime type by format from `textureSetDefinition.formats[0].format`
|
|
153
|
-
* https://github.com/Esri/i3s-spec/blob/master/docs/1.7/textureSetDefinitionFormat.cmn.md
|
|
154
|
-
* @param {string} format - format name
|
|
155
|
-
* @returns {string} mime type.
|
|
156
|
-
*/
|
|
157
|
-
_deduceMimeTypeFromFormat(format) {
|
|
158
|
-
switch (format) {
|
|
159
|
-
case 'jpg':
|
|
160
|
-
return 'image/jpeg';
|
|
161
|
-
case 'png':
|
|
162
|
-
return 'image/png';
|
|
163
|
-
case 'ktx2':
|
|
164
|
-
return 'image/ktx2';
|
|
165
|
-
default:
|
|
166
|
-
console.warn(`Unexpected texture format in I3S: ${format}`); // eslint-disable-line no-console, no-undef
|
|
167
|
-
return 'image/jpeg';
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Convert i3s material to GLTF compatible material
|
|
172
|
-
* @param {object} material - i3s material definition
|
|
173
|
-
* @param {number | null} textureIndex - texture index in GLTF
|
|
174
|
-
* @returns {object} GLTF material
|
|
175
|
-
*/
|
|
176
|
-
_convertI3sMaterialToGltfMaterial(material, textureIndex) {
|
|
177
|
-
const isTextureIndexExists = textureIndex !== null;
|
|
178
|
-
if (!material) {
|
|
179
|
-
material = {
|
|
180
|
-
alphaMode: 'OPAQUE',
|
|
181
|
-
doubleSided: false,
|
|
182
|
-
pbrMetallicRoughness: {
|
|
183
|
-
metallicFactor: 0,
|
|
184
|
-
roughnessFactor: 1
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
if (isTextureIndexExists) {
|
|
188
|
-
material.pbrMetallicRoughness.baseColorTexture = {
|
|
189
|
-
index: textureIndex,
|
|
190
|
-
texCoord: 0
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
else {
|
|
194
|
-
material.pbrMetallicRoughness.baseColorFactor = [1, 1, 1, 1];
|
|
195
|
-
}
|
|
196
|
-
return material;
|
|
197
|
-
}
|
|
198
|
-
if (textureIndex !== null) {
|
|
199
|
-
material = this._setGltfTexture(material, textureIndex);
|
|
200
|
-
}
|
|
201
|
-
return material;
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* Set texture properties in material with GLTF textureIndex
|
|
205
|
-
* @param {object} materialDefinition - i3s material definition
|
|
206
|
-
* @param {number} textureIndex - texture index in GLTF
|
|
207
|
-
* @returns {void}
|
|
208
|
-
*/
|
|
209
|
-
_setGltfTexture(materialDefinition, textureIndex) {
|
|
210
|
-
const material = {
|
|
211
|
-
...materialDefinition,
|
|
212
|
-
pbrMetallicRoughness: { ...materialDefinition.pbrMetallicRoughness }
|
|
213
|
-
};
|
|
214
|
-
// I3SLoader now support loading only one texture. This elseif sequence will assign this texture to one of
|
|
215
|
-
// properties defined in materialDefinition
|
|
216
|
-
if (materialDefinition.pbrMetallicRoughness &&
|
|
217
|
-
materialDefinition.pbrMetallicRoughness.baseColorTexture) {
|
|
218
|
-
material.pbrMetallicRoughness.baseColorTexture = {
|
|
219
|
-
index: textureIndex,
|
|
220
|
-
texCoord: 0
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
else if (materialDefinition.emissiveTexture) {
|
|
224
|
-
material.emissiveTexture = {
|
|
225
|
-
index: textureIndex,
|
|
226
|
-
texCoord: 0
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
else if (materialDefinition.pbrMetallicRoughness &&
|
|
230
|
-
materialDefinition.pbrMetallicRoughness.metallicRoughnessTexture) {
|
|
231
|
-
material.pbrMetallicRoughness.metallicRoughnessTexture = {
|
|
232
|
-
index: textureIndex,
|
|
233
|
-
texCoord: 0
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
else if (materialDefinition.normalTexture) {
|
|
237
|
-
material.normalTexture = {
|
|
238
|
-
index: textureIndex,
|
|
239
|
-
texCoord: 0
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
else if (materialDefinition.occlusionTexture) {
|
|
243
|
-
material.occlusionTexture = {
|
|
244
|
-
index: textureIndex,
|
|
245
|
-
texCoord: 0
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
|
-
return material;
|
|
249
|
-
}
|
|
250
|
-
/*
|
|
251
|
-
* Returns Features length based on attribute array in attribute object.
|
|
252
|
-
* @param {Object} attributes
|
|
253
|
-
* @returns {Number} Features length .
|
|
254
|
-
*/
|
|
255
|
-
_getFeaturesLength(attributes) {
|
|
256
|
-
if (!attributes) {
|
|
257
|
-
return 0;
|
|
258
|
-
}
|
|
259
|
-
const firstKey = Object.keys(attributes)[0];
|
|
260
|
-
return firstKey ? attributes[firstKey].length : 0;
|
|
261
|
-
}
|
|
262
|
-
/* Checks that normals buffer is correct
|
|
263
|
-
* @param {TypedArray} normals
|
|
264
|
-
* @returns {boolean} true - normals are correct; false - normals are incorrect
|
|
265
|
-
*/
|
|
266
|
-
_checkNormals(normals) {
|
|
267
|
-
// If all normals === 0, the resulting tileset is all in black colors on Cesium
|
|
268
|
-
return normals.find((value) => value);
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
exports.default = B3dmConverter;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.i3sObbTo3dTilesObb = void 0;
|
|
4
|
-
const core_1 = require("@math.gl/core");
|
|
5
|
-
const geospatial_1 = require("@math.gl/geospatial");
|
|
6
|
-
const culling_1 = require("@math.gl/culling");
|
|
7
|
-
/**
|
|
8
|
-
* Convert quaternion-based OBB to half-axes-based OBB
|
|
9
|
-
* @param i3SObb quaternion based OBB
|
|
10
|
-
* @param geoidHeightModel the Earth Gravity Model instance
|
|
11
|
-
* @returns number[12] 3DTiles OBB https://github.com/CesiumGS/3d-tiles/tree/master/specification#box
|
|
12
|
-
*/
|
|
13
|
-
function i3sObbTo3dTilesObb(i3SObb, geoidHeightModel) {
|
|
14
|
-
const tiles3DCenter = [
|
|
15
|
-
i3SObb.center[0],
|
|
16
|
-
i3SObb.center[1],
|
|
17
|
-
i3SObb.center[2] + geoidHeightModel.getHeight(i3SObb.center[1], i3SObb.center[0])
|
|
18
|
-
];
|
|
19
|
-
const cartesianCenter = geospatial_1.Ellipsoid.WGS84.cartographicToCartesian(tiles3DCenter, new core_1.Vector3());
|
|
20
|
-
const tiles3DObb = new culling_1.OrientedBoundingBox().fromCenterHalfSizeQuaternion(cartesianCenter, i3SObb.halfSize, i3SObb.quaternion);
|
|
21
|
-
return [...tiles3DObb.center, ...tiles3DObb.halfAxes.toArray()];
|
|
22
|
-
}
|
|
23
|
-
exports.i3sObbTo3dTilesObb = i3sObbTo3dTilesObb;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.loadI3SContent = void 0;
|
|
4
|
-
const core_1 = require("@loaders.gl/core");
|
|
5
|
-
const i3s_1 = require("@loaders.gl/i3s");
|
|
6
|
-
/**
|
|
7
|
-
* Load I3S node content
|
|
8
|
-
* @param sourceTileset - source layer JSON
|
|
9
|
-
* @param sourceTile - source I3S node metadata
|
|
10
|
-
* @param tilesetLoadOptions - load options for Tiles3DLoader
|
|
11
|
-
* @returns - 3DTiles tile content or null
|
|
12
|
-
*/
|
|
13
|
-
const loadI3SContent = async (sourceTileset, sourceTile, tilesetLoadOptions) => {
|
|
14
|
-
if (!sourceTileset || !sourceTile.contentUrl) {
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
const loadOptions = {
|
|
18
|
-
...tilesetLoadOptions,
|
|
19
|
-
i3s: {
|
|
20
|
-
...tilesetLoadOptions.i3s,
|
|
21
|
-
isTileset: false,
|
|
22
|
-
isTileHeader: false,
|
|
23
|
-
_tileOptions: {
|
|
24
|
-
attributeUrls: sourceTile.attributeUrls,
|
|
25
|
-
textureUrl: sourceTile.textureUrl,
|
|
26
|
-
textureFormat: sourceTile.textureFormat,
|
|
27
|
-
textureLoaderOptions: sourceTile.textureLoaderOptions,
|
|
28
|
-
materialDefinition: sourceTile.materialDefinition,
|
|
29
|
-
isDracoGeometry: sourceTile.isDracoGeometry,
|
|
30
|
-
mbs: sourceTile.mbs
|
|
31
|
-
},
|
|
32
|
-
_tilesetOptions: {
|
|
33
|
-
store: sourceTileset.store,
|
|
34
|
-
attributeStorageInfo: sourceTileset.attributeStorageInfo,
|
|
35
|
-
fields: sourceTileset.fields
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
const tileContent = await (0, core_1.load)(sourceTile.contentUrl, i3s_1.I3SLoader, loadOptions);
|
|
40
|
-
return tileContent;
|
|
41
|
-
};
|
|
42
|
-
exports.loadI3SContent = loadI3SContent;
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.convertTextureAtlas = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Apply uvRegions to texture coordinates.
|
|
6
|
-
* Spec - https://github.com/Esri/i3s-spec/blob/master/docs/1.7/geometryUVRegion.cmn.md
|
|
7
|
-
* Shader formula vec2 uv = fract(texCoords) * (uvRegions.zw - uvRegions.xy) + uvRegions.xy;
|
|
8
|
-
* @param texCoords
|
|
9
|
-
* @param uvRegions
|
|
10
|
-
*/
|
|
11
|
-
function convertTextureAtlas(texCoords, uvRegions) {
|
|
12
|
-
const convertedTexCoords = new Float32Array(texCoords.length);
|
|
13
|
-
const normalisedRegions = normalizeRegions(uvRegions);
|
|
14
|
-
for (let index = 0; index < texCoords.length; index += 2) {
|
|
15
|
-
const uv = texCoords.subarray(index, index + 2);
|
|
16
|
-
const regions = normalisedRegions.slice(index * 2, index * 2 + 4);
|
|
17
|
-
// fract(texCoords)
|
|
18
|
-
const fractatedUV = fract([uv[0], uv[1]]);
|
|
19
|
-
// (uvRegions.zw - uvRegions.xy)
|
|
20
|
-
const subtracted = [regions[2] - regions[0], regions[3] - regions[1]];
|
|
21
|
-
// fract(texCoords) * (uvRegions.zw - uvRegions.xy)
|
|
22
|
-
const multiplicationResult = [fractatedUV[0] * subtracted[0], fractatedUV[1] * subtracted[1]];
|
|
23
|
-
// fract(texCoords) * (uvRegions.zw - uvRegions.xy) + uvRegions.xy;
|
|
24
|
-
const convertedUV = [
|
|
25
|
-
multiplicationResult[0] + regions[0],
|
|
26
|
-
multiplicationResult[1] + regions[1]
|
|
27
|
-
];
|
|
28
|
-
convertedTexCoords[index] = convertedUV[0];
|
|
29
|
-
convertedTexCoords[index + 1] = convertedUV[1];
|
|
30
|
-
}
|
|
31
|
-
return convertedTexCoords;
|
|
32
|
-
}
|
|
33
|
-
exports.convertTextureAtlas = convertTextureAtlas;
|
|
34
|
-
/**
|
|
35
|
-
* Do fractation of UV array.
|
|
36
|
-
* @param uv
|
|
37
|
-
*/
|
|
38
|
-
function fract(uv) {
|
|
39
|
-
return [uv[0] - Math.floor(uv[0]), uv[1] - Math.floor(uv[1])];
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Normalize uvRegions by dividing by the maximum Uint16 value
|
|
43
|
-
* @param regions
|
|
44
|
-
*/
|
|
45
|
-
function normalizeRegions(regions) {
|
|
46
|
-
// The code is for Uint16Array because it is the spec requirement
|
|
47
|
-
// https://github.com/Esri/i3s-spec/blob/master/docs/1.8/geometryUVRegion.cmn.md
|
|
48
|
-
const MAX_UINT_16_VALUE = 65535;
|
|
49
|
-
const normalizedRegions = [];
|
|
50
|
-
for (let index = 0; index < regions.length; index++) {
|
|
51
|
-
normalizedRegions[index] = regions[index] / MAX_UINT_16_VALUE;
|
|
52
|
-
}
|
|
53
|
-
return normalizedRegions;
|
|
54
|
-
}
|