@loaders.gl/tile-converter 3.1.0-alpha.3 → 3.1.0-beta.2
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/bin/converter.js +1 -1
- package/dist/bundle.js +85947 -4
- package/dist/converter.min.js +292 -0
- package/dist/es5/3d-tiles-converter/3d-tiles-converter.js +267 -0
- package/dist/es5/3d-tiles-converter/3d-tiles-converter.js.map +1 -0
- package/dist/{3d-tiles-converter → es5/3d-tiles-converter}/helpers/b3dm-converter.d.ts +0 -0
- package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js +269 -0
- package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -0
- package/dist/{3d-tiles-converter → es5/3d-tiles-converter}/helpers/i3s-obb-to-3d-tiles-obb.d.ts +0 -0
- package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +22 -0
- package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +1 -0
- package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js +40 -0
- package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js.map +1 -0
- package/dist/es5/3d-tiles-converter/json-templates/tileset.js +48 -0
- package/dist/es5/3d-tiles-converter/json-templates/tileset.js.map +1 -0
- package/dist/es5/bundle.js +7 -0
- package/dist/es5/bundle.js.map +1 -0
- package/dist/{deps-installer → es5/deps-installer}/deps-installer.d.ts +0 -0
- package/dist/es5/deps-installer/deps-installer.js +39 -0
- package/dist/es5/deps-installer/deps-installer.js.map +1 -0
- package/dist/es5/i3s-converter/helpers/coordinate-converter.js +65 -0
- package/dist/es5/i3s-converter/helpers/coordinate-converter.js.map +1 -0
- package/dist/es5/i3s-converter/helpers/create-scene-server-path.js +30 -0
- package/dist/es5/i3s-converter/helpers/create-scene-server-path.js.map +1 -0
- package/dist/es5/i3s-converter/helpers/geometry-attributes.js +208 -0
- package/dist/es5/i3s-converter/helpers/geometry-attributes.js.map +1 -0
- package/dist/{i3s-converter → es5/i3s-converter}/helpers/geometry-converter.d.ts +0 -0
- package/dist/es5/i3s-converter/helpers/geometry-converter.js +700 -0
- package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -0
- package/dist/es5/i3s-converter/helpers/node-debug.js +103 -0
- package/dist/es5/i3s-converter/helpers/node-debug.js.map +1 -0
- package/dist/{i3s-converter → es5/i3s-converter}/helpers/node-pages.d.ts +0 -0
- package/dist/es5/i3s-converter/helpers/node-pages.js +150 -0
- package/dist/es5/i3s-converter/helpers/node-pages.js.map +1 -0
- package/dist/es5/i3s-converter/i3s-converter.js +915 -0
- package/dist/es5/i3s-converter/i3s-converter.js.map +1 -0
- package/dist/es5/i3s-converter/json-templates/layers.js +203 -0
- package/dist/es5/i3s-converter/json-templates/layers.js.map +1 -0
- package/dist/es5/i3s-converter/json-templates/metadata.js +29 -0
- package/dist/es5/i3s-converter/json-templates/metadata.js.map +1 -0
- package/dist/es5/i3s-converter/json-templates/node.js +91 -0
- package/dist/es5/i3s-converter/json-templates/node.js.map +1 -0
- package/dist/es5/i3s-converter/json-templates/scene-server.js +35 -0
- package/dist/es5/i3s-converter/json-templates/scene-server.js.map +1 -0
- package/dist/es5/i3s-converter/json-templates/shared-resources.js +141 -0
- package/dist/es5/i3s-converter/json-templates/shared-resources.js.map +1 -0
- package/dist/es5/i3s-converter/json-templates/store.js +105 -0
- package/dist/es5/i3s-converter/json-templates/store.js.map +1 -0
- package/dist/es5/i3s-server/app.js +23 -0
- package/dist/es5/i3s-server/app.js.map +1 -0
- package/dist/{i3s-server → es5/i3s-server}/bin/www +0 -0
- package/dist/{i3s-server → es5/i3s-server}/certs/cert.pem +0 -0
- package/dist/{i3s-server → es5/i3s-server}/certs/key.pem +0 -0
- package/dist/es5/i3s-server/controllers/index-controller.js +33 -0
- package/dist/es5/i3s-server/controllers/index-controller.js.map +1 -0
- package/dist/es5/i3s-server/routes/index.js +22 -0
- package/dist/es5/i3s-server/routes/index.js.map +1 -0
- package/dist/es5/index.js +40 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/{lib → es5/lib}/geoid-height-model.d.ts +0 -0
- package/dist/es5/lib/geoid-height-model.js +149 -0
- package/dist/es5/lib/geoid-height-model.js.map +1 -0
- package/dist/{lib → es5/lib}/pgm-parser.d.ts +0 -0
- package/dist/es5/lib/pgm-parser.js +192 -0
- package/dist/es5/lib/pgm-parser.js.map +1 -0
- package/dist/es5/lib/utils/compress-util.js +202 -0
- package/dist/es5/lib/utils/compress-util.js.map +1 -0
- package/dist/{lib → es5/lib}/utils/compress-utils.d.ts +0 -0
- package/dist/{lib → es5/lib}/utils/file-utils.d.ts +0 -0
- package/dist/es5/lib/utils/file-utils.js +59 -0
- package/dist/es5/lib/utils/file-utils.js.map +1 -0
- package/dist/{lib → es5/lib}/utils/lod-conversion-utils.d.ts +0 -0
- package/dist/es5/lib/utils/lod-conversion-utils.js +52 -0
- package/dist/es5/lib/utils/lod-conversion-utils.js.map +1 -0
- package/dist/{lib → es5/lib}/utils/statistic-utills.d.ts +0 -0
- package/dist/es5/lib/utils/statistic-utills.js +85 -0
- package/dist/es5/lib/utils/statistic-utills.js.map +1 -0
- package/dist/es5/pgm-loader.js +24 -0
- package/dist/es5/pgm-loader.js.map +1 -0
- package/dist/{3d-tiles-converter → esm/3d-tiles-converter}/3d-tiles-converter.js +19 -13
- package/dist/esm/3d-tiles-converter/3d-tiles-converter.js.map +1 -0
- package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.d.ts +23 -0
- package/dist/{3d-tiles-converter → esm/3d-tiles-converter}/helpers/b3dm-converter.js +19 -8
- package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -0
- package/dist/esm/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.d.ts +16 -0
- package/dist/{3d-tiles-converter → esm/3d-tiles-converter}/helpers/i3s-obb-to-3d-tiles-obb.js +0 -0
- package/dist/esm/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +1 -0
- package/dist/esm/3d-tiles-converter/helpers/texture-atlas.js +33 -0
- package/dist/esm/3d-tiles-converter/helpers/texture-atlas.js.map +1 -0
- package/dist/{3d-tiles-converter → esm/3d-tiles-converter}/json-templates/tileset.js +0 -0
- package/dist/esm/3d-tiles-converter/json-templates/tileset.js.map +1 -0
- package/dist/esm/bundle.js +5 -0
- package/dist/esm/bundle.js.map +1 -0
- package/dist/esm/deps-installer/deps-installer.d.ts +10 -0
- package/dist/{deps-installer → esm/deps-installer}/deps-installer.js +0 -0
- package/dist/esm/deps-installer/deps-installer.js.map +1 -0
- package/dist/{i3s-converter → esm/i3s-converter}/helpers/coordinate-converter.js +0 -0
- package/dist/esm/i3s-converter/helpers/coordinate-converter.js.map +1 -0
- package/dist/{i3s-converter → esm/i3s-converter}/helpers/create-scene-server-path.js +0 -0
- package/dist/esm/i3s-converter/helpers/create-scene-server-path.js.map +1 -0
- package/dist/{i3s-converter → esm/i3s-converter}/helpers/geometry-attributes.js +0 -0
- package/dist/esm/i3s-converter/helpers/geometry-attributes.js.map +1 -0
- package/dist/esm/i3s-converter/helpers/geometry-converter.d.ts +40 -0
- package/dist/{i3s-converter → esm/i3s-converter}/helpers/geometry-converter.js +29 -31
- package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -0
- package/dist/{i3s-converter → esm/i3s-converter}/helpers/node-debug.js +2 -2
- package/dist/esm/i3s-converter/helpers/node-debug.js.map +1 -0
- package/dist/esm/i3s-converter/helpers/node-pages.d.ts +144 -0
- package/dist/{i3s-converter → esm/i3s-converter}/helpers/node-pages.js +2 -2
- package/dist/esm/i3s-converter/helpers/node-pages.js.map +1 -0
- package/dist/{i3s-converter → esm/i3s-converter}/i3s-converter.js +50 -31
- package/dist/esm/i3s-converter/i3s-converter.js.map +1 -0
- package/dist/{i3s-converter → esm/i3s-converter}/json-templates/layers.js +0 -0
- package/dist/esm/i3s-converter/json-templates/layers.js.map +1 -0
- package/dist/{i3s-converter → esm/i3s-converter}/json-templates/metadata.js +1 -1
- package/dist/esm/i3s-converter/json-templates/metadata.js.map +1 -0
- package/dist/{i3s-converter → esm/i3s-converter}/json-templates/node.js +0 -0
- package/dist/esm/i3s-converter/json-templates/node.js.map +1 -0
- package/dist/{i3s-converter → esm/i3s-converter}/json-templates/scene-server.js +1 -1
- package/dist/esm/i3s-converter/json-templates/scene-server.js.map +1 -0
- package/dist/{i3s-converter → esm/i3s-converter}/json-templates/shared-resources.js +2 -2
- package/dist/esm/i3s-converter/json-templates/shared-resources.js.map +1 -0
- package/dist/{i3s-converter → esm/i3s-converter}/json-templates/store.js +2 -2
- package/dist/esm/i3s-converter/json-templates/store.js.map +1 -0
- package/dist/{i3s-server → esm/i3s-server}/app.js +0 -0
- package/dist/esm/i3s-server/app.js.map +1 -0
- package/dist/esm/i3s-server/bin/www +102 -0
- package/dist/esm/i3s-server/certs/cert.pem +19 -0
- package/dist/esm/i3s-server/certs/key.pem +27 -0
- package/dist/{i3s-server → esm/i3s-server}/controllers/index-controller.js +2 -2
- package/dist/esm/i3s-server/controllers/index-controller.js.map +1 -0
- package/dist/{i3s-server → esm/i3s-server}/routes/index.js +0 -0
- package/dist/esm/i3s-server/routes/index.js.map +1 -0
- package/dist/{index.js → esm/index.js} +0 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lib/geoid-height-model.d.ts +41 -0
- package/dist/{lib → esm/lib}/geoid-height-model.js +0 -0
- package/dist/esm/lib/geoid-height-model.js.map +1 -0
- package/dist/esm/lib/pgm-parser.d.ts +14 -0
- package/dist/{lib → esm/lib}/pgm-parser.js +0 -0
- package/dist/esm/lib/pgm-parser.js.map +1 -0
- package/dist/{lib → esm/lib}/utils/compress-util.js +13 -13
- package/dist/esm/lib/utils/compress-util.js.map +1 -0
- package/dist/esm/lib/utils/compress-utils.d.ts +53 -0
- package/dist/esm/lib/utils/file-utils.d.ts +43 -0
- package/dist/{lib → esm/lib}/utils/file-utils.js +1 -1
- package/dist/esm/lib/utils/file-utils.js.map +1 -0
- package/dist/esm/lib/utils/lod-conversion-utils.d.ts +32 -0
- package/dist/{lib → esm/lib}/utils/lod-conversion-utils.js +0 -0
- package/dist/esm/lib/utils/lod-conversion-utils.js.map +1 -0
- package/dist/esm/lib/utils/statistic-utills.d.ts +25 -0
- package/dist/{lib → esm/lib}/utils/statistic-utills.js +5 -5
- package/dist/esm/lib/utils/statistic-utills.js.map +1 -0
- package/dist/{pgm-loader.js → esm/pgm-loader.js} +1 -1
- package/dist/esm/pgm-loader.js.map +1 -0
- package/package.json +24 -21
- package/src/3d-tiles-converter/3d-tiles-converter.ts +4 -2
- package/src/3d-tiles-converter/helpers/b3dm-converter.js +35 -7
- package/src/3d-tiles-converter/helpers/texture-atlas.ts +55 -0
- package/src/i3s-converter/helpers/geometry-converter.js +21 -22
- package/src/i3s-converter/i3s-converter.ts +32 -7
- package/src/i3s-converter/json-templates/metadata.js +1 -1
- package/src/i3s-converter/json-templates/scene-server.js +1 -1
- package/src/i3s-converter/json-templates/store.js +2 -2
- package/src/i3s-server/controllers/index-controller.js +1 -1
- package/dist/3d-tiles-converter/3d-tiles-converter.js.map +0 -1
- package/dist/3d-tiles-converter/helpers/b3dm-converter.js.map +0 -1
- package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +0 -1
- package/dist/3d-tiles-converter/json-templates/tileset.js.map +0 -1
- package/dist/bundle.js.map +0 -1
- package/dist/deps-installer/deps-installer.js.map +0 -1
- package/dist/dist.min.js +0 -94
- package/dist/dist.min.js.map +0 -1
- package/dist/i3s-converter/helpers/coordinate-converter.js.map +0 -1
- package/dist/i3s-converter/helpers/create-scene-server-path.js.map +0 -1
- package/dist/i3s-converter/helpers/geometry-attributes.js.map +0 -1
- package/dist/i3s-converter/helpers/geometry-converter.js.map +0 -1
- package/dist/i3s-converter/helpers/node-debug.js.map +0 -1
- package/dist/i3s-converter/helpers/node-pages.js.map +0 -1
- package/dist/i3s-converter/i3s-converter.js.map +0 -1
- package/dist/i3s-converter/json-templates/layers.js.map +0 -1
- package/dist/i3s-converter/json-templates/metadata.js.map +0 -1
- package/dist/i3s-converter/json-templates/node.js.map +0 -1
- package/dist/i3s-converter/json-templates/scene-server.js.map +0 -1
- package/dist/i3s-converter/json-templates/shared-resources.js.map +0 -1
- package/dist/i3s-converter/json-templates/store.js.map +0 -1
- package/dist/i3s-server/app.js.map +0 -1
- package/dist/i3s-server/controllers/index-controller.js.map +0 -1
- package/dist/i3s-server/routes/index.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/geoid-height-model.js.map +0 -1
- package/dist/lib/pgm-parser.js.map +0 -1
- package/dist/lib/utils/compress-util.js.map +0 -1
- package/dist/lib/utils/file-utils.js.map +0 -1
- package/dist/lib/utils/lod-conversion-utils.js.map +0 -1
- package/dist/lib/utils/statistic-utills.js.map +0 -1
- package/dist/pgm-loader.js.map +0 -1
- package/dist/scripts/converter.js +0 -274
|
@@ -0,0 +1,700 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = convertB3dmToI3sGeometry;
|
|
9
|
+
|
|
10
|
+
var _core = require("@math.gl/core");
|
|
11
|
+
|
|
12
|
+
var _geospatial = require("@math.gl/geospatial");
|
|
13
|
+
|
|
14
|
+
var _draco = require("@loaders.gl/draco");
|
|
15
|
+
|
|
16
|
+
var _core2 = require("@loaders.gl/core");
|
|
17
|
+
|
|
18
|
+
var _loaderUtils = require("@loaders.gl/loader-utils");
|
|
19
|
+
|
|
20
|
+
var _md = _interopRequireDefault(require("md5"));
|
|
21
|
+
|
|
22
|
+
var _geometryAttributes = require("./geometry-attributes");
|
|
23
|
+
|
|
24
|
+
const VALUES_PER_VERTEX = 3;
|
|
25
|
+
const VALUES_PER_TEX_COORD = 2;
|
|
26
|
+
const VALUES_PER_COLOR_ELEMENT = 4;
|
|
27
|
+
const STRING_TYPE = 'string';
|
|
28
|
+
const SHORT_INT_TYPE = 'Int32';
|
|
29
|
+
const DOUBLE_TYPE = 'Float64';
|
|
30
|
+
const OBJECT_ID_TYPE = 'Oid32';
|
|
31
|
+
const BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES = ['CUSTOM_ATTRIBUTE_2', '_BATCHID', 'BATCHID'];
|
|
32
|
+
|
|
33
|
+
async function convertB3dmToI3sGeometry(tileContent, nodeId, featuresHashArray, attributeStorageInfo, draco) {
|
|
34
|
+
const materialAndTextureList = convertMaterials(tileContent);
|
|
35
|
+
const convertedAttributesMap = convertAttributes(tileContent);
|
|
36
|
+
|
|
37
|
+
if (convertedAttributesMap.has('default')) {
|
|
38
|
+
materialAndTextureList.push({
|
|
39
|
+
material: getDefaultMaterial()
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const result = [];
|
|
44
|
+
let nodesCounter = nodeId;
|
|
45
|
+
let {
|
|
46
|
+
materials = []
|
|
47
|
+
} = tileContent.gltf;
|
|
48
|
+
|
|
49
|
+
if (!materials.length === 0) {
|
|
50
|
+
materials.push({
|
|
51
|
+
id: 'default'
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
for (let i = 0; i < materials.length; i++) {
|
|
56
|
+
const sourceMaterial = materials[i];
|
|
57
|
+
|
|
58
|
+
if (!convertedAttributesMap.has(sourceMaterial.id)) {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const convertedAttributes = convertedAttributesMap.get(sourceMaterial.id);
|
|
63
|
+
const {
|
|
64
|
+
material,
|
|
65
|
+
texture
|
|
66
|
+
} = materialAndTextureList[i];
|
|
67
|
+
result.push(await _makeNodeResources({
|
|
68
|
+
convertedAttributes,
|
|
69
|
+
material,
|
|
70
|
+
texture,
|
|
71
|
+
tileContent,
|
|
72
|
+
nodeId: nodesCounter,
|
|
73
|
+
featuresHashArray,
|
|
74
|
+
attributeStorageInfo,
|
|
75
|
+
draco
|
|
76
|
+
}));
|
|
77
|
+
nodesCounter++;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (!result.length) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async function _makeNodeResources({
|
|
88
|
+
convertedAttributes,
|
|
89
|
+
material,
|
|
90
|
+
texture,
|
|
91
|
+
tileContent,
|
|
92
|
+
nodeId,
|
|
93
|
+
featuresHashArray,
|
|
94
|
+
attributeStorageInfo,
|
|
95
|
+
draco
|
|
96
|
+
}) {
|
|
97
|
+
const vertexCount = convertedAttributes.positions.length / VALUES_PER_VERTEX;
|
|
98
|
+
const triangleCount = vertexCount / 3;
|
|
99
|
+
const {
|
|
100
|
+
faceRange,
|
|
101
|
+
featureIds,
|
|
102
|
+
positions,
|
|
103
|
+
normals,
|
|
104
|
+
colors,
|
|
105
|
+
texCoords,
|
|
106
|
+
featureCount
|
|
107
|
+
} = (0, _geometryAttributes.generateAttributes)({
|
|
108
|
+
triangleCount,
|
|
109
|
+
...convertedAttributes
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
if (tileContent.batchTableJson) {
|
|
113
|
+
makeFeatureIdsUnique(featureIds, convertedAttributes.featureIndices, featuresHashArray, tileContent.batchTableJson);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const header = new Uint32Array(2);
|
|
117
|
+
const typedFeatureIds = generateBigUint64Array(featureIds);
|
|
118
|
+
header.set([vertexCount, featureCount], 0);
|
|
119
|
+
const fileBuffer = new Uint8Array((0, _loaderUtils.concatenateArrayBuffers)(header.buffer, positions.buffer, normals.buffer, texture ? texCoords.buffer : new ArrayBuffer(0), colors.buffer, typedFeatureIds.buffer, faceRange.buffer));
|
|
120
|
+
const compressedGeometry = draco ? await generateCompressedGeometry(vertexCount, convertedAttributes, {
|
|
121
|
+
positions,
|
|
122
|
+
normals,
|
|
123
|
+
texCoords: texture ? texCoords : new Float32Array(0),
|
|
124
|
+
colors,
|
|
125
|
+
featureIds,
|
|
126
|
+
faceRange
|
|
127
|
+
}) : null;
|
|
128
|
+
const attributes = convertBatchTableToAttributeBuffers(tileContent.batchTableJson, featureIds, attributeStorageInfo);
|
|
129
|
+
return {
|
|
130
|
+
geometry: fileBuffer,
|
|
131
|
+
compressedGeometry,
|
|
132
|
+
texture,
|
|
133
|
+
sharedResources: getSharedResources(tileContent, nodeId),
|
|
134
|
+
meshMaterial: material,
|
|
135
|
+
vertexCount,
|
|
136
|
+
attributes,
|
|
137
|
+
featureCount
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function convertAttributes(tileContent) {
|
|
142
|
+
var _tileContent$gltf$sce;
|
|
143
|
+
|
|
144
|
+
const attributesMap = new Map();
|
|
145
|
+
|
|
146
|
+
for (const material of tileContent.gltf.materials || [{
|
|
147
|
+
id: 'default'
|
|
148
|
+
}]) {
|
|
149
|
+
attributesMap.set(material.id, {
|
|
150
|
+
positions: new Float32Array(0),
|
|
151
|
+
normals: new Float32Array(0),
|
|
152
|
+
texCoords: new Float32Array(0),
|
|
153
|
+
colors: new Uint8Array(0),
|
|
154
|
+
featureIndices: []
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const nodes = (tileContent.gltf.scene || ((_tileContent$gltf$sce = tileContent.gltf.scenes) === null || _tileContent$gltf$sce === void 0 ? void 0 : _tileContent$gltf$sce[0]) || tileContent.gltf).nodes;
|
|
159
|
+
convertNodes(nodes, tileContent, attributesMap);
|
|
160
|
+
|
|
161
|
+
for (const attrKey of attributesMap.keys()) {
|
|
162
|
+
const attributes = attributesMap.get(attrKey);
|
|
163
|
+
|
|
164
|
+
if (attributes.positions.length === 0) {
|
|
165
|
+
attributesMap.delete(attrKey);
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
attributes.featureIndices = attributes.featureIndices.reduce((acc, value) => acc.concat(value));
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return attributesMap;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function convertNodes(nodes, tileContent, attributesMap, matrix = new _core.Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])) {
|
|
176
|
+
if (nodes) {
|
|
177
|
+
for (const node of nodes) {
|
|
178
|
+
convertNode(node, tileContent, attributesMap, matrix);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function convertNode(node, tileContent, attributesMap, matrix = new _core.Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])) {
|
|
184
|
+
const nodeMatrix = node.matrix;
|
|
185
|
+
const compositeMatrix = nodeMatrix ? matrix.multiplyRight(nodeMatrix) : matrix;
|
|
186
|
+
const mesh = node.mesh;
|
|
187
|
+
|
|
188
|
+
if (mesh) {
|
|
189
|
+
convertMesh(mesh, tileContent, attributesMap, compositeMatrix);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
convertNodes(node.children, tileContent, attributesMap, compositeMatrix);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function convertMesh(mesh, content, attributesMap, matrix = new _core.Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])) {
|
|
196
|
+
for (const primitive of mesh.primitives) {
|
|
197
|
+
let outputAttributes = null;
|
|
198
|
+
|
|
199
|
+
if (primitive.material) {
|
|
200
|
+
outputAttributes = attributesMap.get(primitive.material.id);
|
|
201
|
+
} else if (attributesMap.has('default')) {
|
|
202
|
+
outputAttributes = attributesMap.get('default');
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
(0, _core2.assert)(outputAttributes !== null, 'Primitive - material mapping failed');
|
|
206
|
+
const attributes = primitive.attributes;
|
|
207
|
+
outputAttributes.positions = (0, _loaderUtils.concatenateTypedArrays)(outputAttributes.positions, transformVertexArray({
|
|
208
|
+
vertices: attributes.POSITION.value,
|
|
209
|
+
cartographicOrigin: content.cartographicOrigin,
|
|
210
|
+
cartesianModelMatrix: content.cartesianModelMatrix,
|
|
211
|
+
nodeMatrix: matrix,
|
|
212
|
+
indices: primitive.indices.value,
|
|
213
|
+
attributeSpecificTransformation: transformVertexPositions
|
|
214
|
+
}));
|
|
215
|
+
outputAttributes.normals = (0, _loaderUtils.concatenateTypedArrays)(outputAttributes.normals, transformVertexArray({
|
|
216
|
+
vertices: attributes.NORMAL && attributes.NORMAL.value,
|
|
217
|
+
cartographicOrigin: content.cartographicOrigin,
|
|
218
|
+
cartesianModelMatrix: content.cartesianModelMatrix,
|
|
219
|
+
nodeMatrix: matrix,
|
|
220
|
+
indices: primitive.indices.value,
|
|
221
|
+
attributeSpecificTransformation: transformVertexNormals
|
|
222
|
+
}));
|
|
223
|
+
outputAttributes.texCoords = (0, _loaderUtils.concatenateTypedArrays)(outputAttributes.texCoords, flattenTexCoords(attributes.TEXCOORD_0 && attributes.TEXCOORD_0.value, primitive.indices.value));
|
|
224
|
+
outputAttributes.colors = (0, _loaderUtils.concatenateTypedArrays)(outputAttributes.colors, flattenColors(attributes.COLOR_0, primitive.indices.value));
|
|
225
|
+
outputAttributes.featureIndices.push(flattenBatchIds(getBatchIdsByAttributeName(attributes), primitive.indices.value));
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function transformVertexArray(args) {
|
|
230
|
+
const {
|
|
231
|
+
vertices,
|
|
232
|
+
indices,
|
|
233
|
+
attributeSpecificTransformation
|
|
234
|
+
} = args;
|
|
235
|
+
const newVertices = new Float32Array(indices.length * VALUES_PER_VERTEX);
|
|
236
|
+
|
|
237
|
+
if (!vertices) {
|
|
238
|
+
return newVertices;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
for (let i = 0; i < indices.length; i++) {
|
|
242
|
+
const coordIndex = indices[i] * VALUES_PER_VERTEX;
|
|
243
|
+
const vertex = vertices.subarray(coordIndex, coordIndex + VALUES_PER_VERTEX);
|
|
244
|
+
let vertexVector = new _core.Vector3(Array.from(vertex));
|
|
245
|
+
vertexVector = attributeSpecificTransformation(vertexVector, args);
|
|
246
|
+
newVertices[i * VALUES_PER_VERTEX] = vertexVector.x;
|
|
247
|
+
newVertices[i * VALUES_PER_VERTEX + 1] = vertexVector.y;
|
|
248
|
+
newVertices[i * VALUES_PER_VERTEX + 2] = vertexVector.z;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
return newVertices;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function transformVertexPositions(vertexVector, calleeArgs) {
|
|
255
|
+
const {
|
|
256
|
+
cartesianModelMatrix,
|
|
257
|
+
cartographicOrigin,
|
|
258
|
+
nodeMatrix
|
|
259
|
+
} = calleeArgs;
|
|
260
|
+
|
|
261
|
+
if (nodeMatrix) {
|
|
262
|
+
vertexVector = vertexVector.transform(nodeMatrix);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
vertexVector = vertexVector.transform(cartesianModelMatrix);
|
|
266
|
+
|
|
267
|
+
_geospatial.Ellipsoid.WGS84.cartesianToCartographic([vertexVector[0], vertexVector[1], vertexVector[2]], vertexVector);
|
|
268
|
+
|
|
269
|
+
vertexVector = vertexVector.subtract(cartographicOrigin);
|
|
270
|
+
return vertexVector;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function transformVertexNormals(vertexVector, calleeArgs) {
|
|
274
|
+
const {
|
|
275
|
+
cartesianModelMatrix,
|
|
276
|
+
nodeMatrix
|
|
277
|
+
} = calleeArgs;
|
|
278
|
+
|
|
279
|
+
if (nodeMatrix) {
|
|
280
|
+
vertexVector = vertexVector.transformAsVector(nodeMatrix);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
vertexVector = vertexVector.transformAsVector(cartesianModelMatrix);
|
|
284
|
+
return vertexVector;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function flattenTexCoords(texCoords, indices) {
|
|
288
|
+
const newTexCoords = new Float32Array(indices.length * VALUES_PER_TEX_COORD);
|
|
289
|
+
|
|
290
|
+
if (!texCoords) {
|
|
291
|
+
newTexCoords.fill(1);
|
|
292
|
+
return newTexCoords;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
for (let i = 0; i < indices.length; i++) {
|
|
296
|
+
const coordIndex = indices[i] * VALUES_PER_TEX_COORD;
|
|
297
|
+
const texCoord = texCoords.subarray(coordIndex, coordIndex + VALUES_PER_TEX_COORD);
|
|
298
|
+
newTexCoords[i * VALUES_PER_TEX_COORD] = texCoord[0];
|
|
299
|
+
newTexCoords[i * VALUES_PER_TEX_COORD + 1] = texCoord[1];
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
return newTexCoords;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function flattenColors(colorsAttribute, indices) {
|
|
306
|
+
const components = (colorsAttribute === null || colorsAttribute === void 0 ? void 0 : colorsAttribute.components) || VALUES_PER_COLOR_ELEMENT;
|
|
307
|
+
const newColors = new Uint8Array(indices.length * components);
|
|
308
|
+
|
|
309
|
+
if (!colorsAttribute) {
|
|
310
|
+
newColors.fill(255);
|
|
311
|
+
return newColors;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
const colors = colorsAttribute.value;
|
|
315
|
+
|
|
316
|
+
for (let i = 0; i < indices.length; i++) {
|
|
317
|
+
const colorIndex = indices[i] * components;
|
|
318
|
+
const color = colors.subarray(colorIndex, colorIndex + components);
|
|
319
|
+
const colorUint8 = new Uint8Array(components);
|
|
320
|
+
|
|
321
|
+
for (let j = 0; j < color.length; j++) {
|
|
322
|
+
colorUint8[j] = color[j] * 255;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
newColors.set(colorUint8, i * components);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
return newColors;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
function flattenBatchIds(batchedIds, indices) {
|
|
332
|
+
if (!batchedIds.length || !indices.length) {
|
|
333
|
+
return [];
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
const newBatchIds = [];
|
|
337
|
+
|
|
338
|
+
for (let i = 0; i < indices.length; i++) {
|
|
339
|
+
const coordIndex = indices[i];
|
|
340
|
+
newBatchIds.push(batchedIds[coordIndex]);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
return newBatchIds;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function getBatchIdsByAttributeName(attributes) {
|
|
347
|
+
let batchIds = [];
|
|
348
|
+
|
|
349
|
+
for (let index = 0; index < BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES.length; index++) {
|
|
350
|
+
const possibleBatchIdAttributeName = BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES[index];
|
|
351
|
+
|
|
352
|
+
if (attributes[possibleBatchIdAttributeName] && attributes[possibleBatchIdAttributeName].value) {
|
|
353
|
+
batchIds = attributes[possibleBatchIdAttributeName].value;
|
|
354
|
+
break;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
return batchIds;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
function convertMaterials(tileContent) {
|
|
362
|
+
const result = [];
|
|
363
|
+
const sourceMaterials = tileContent.gltf.materials || [];
|
|
364
|
+
|
|
365
|
+
for (const sourceMaterial of sourceMaterials) {
|
|
366
|
+
result.push(convertMaterial(sourceMaterial));
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
return result;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
function convertMaterial(sourceMaterial) {
|
|
373
|
+
const material = {
|
|
374
|
+
doubleSided: sourceMaterial.doubleSided,
|
|
375
|
+
emissiveFactor: sourceMaterial.emissiveFactor.map(c => Math.round(c * 255)),
|
|
376
|
+
alphaMode: (sourceMaterial.alphaMode || 'OPAQUE').toLowerCase(),
|
|
377
|
+
pbrMetallicRoughness: {
|
|
378
|
+
roughnessFactor: sourceMaterial.pbrMetallicRoughness.roughnessFactor,
|
|
379
|
+
metallicFactor: sourceMaterial.pbrMetallicRoughness.metallicFactor
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
let texture;
|
|
383
|
+
|
|
384
|
+
if (sourceMaterial.pbrMetallicRoughness.baseColorTexture) {
|
|
385
|
+
texture = sourceMaterial.pbrMetallicRoughness.baseColorTexture.texture.source;
|
|
386
|
+
material.pbrMetallicRoughness.baseColorTexture = {
|
|
387
|
+
textureSetDefinitionId: 0
|
|
388
|
+
};
|
|
389
|
+
} else if (sourceMaterial.emissiveTexture) {
|
|
390
|
+
texture = sourceMaterial.emissiveTexture.texture.source;
|
|
391
|
+
material.pbrMetallicRoughness.baseColorTexture = {
|
|
392
|
+
textureSetDefinitionId: 0
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
if (!texture) {
|
|
397
|
+
const baseColorFactor = sourceMaterial.pbrMetallicRoughness.baseColorFactor;
|
|
398
|
+
material.pbrMetallicRoughness.baseColorFactor = baseColorFactor && baseColorFactor.map(c => Math.round(c * 255)) || undefined;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
return {
|
|
402
|
+
material,
|
|
403
|
+
texture
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
function getDefaultMaterial() {
|
|
408
|
+
return {
|
|
409
|
+
alphaMode: 'opaque',
|
|
410
|
+
pbrMetallicRoughness: {}
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
function getSharedResources(tileContent, nodeId) {
|
|
415
|
+
const gltfMaterials = tileContent.gltf.materials;
|
|
416
|
+
const i3sResources = {};
|
|
417
|
+
|
|
418
|
+
if (!gltfMaterials || !gltfMaterials.length) {
|
|
419
|
+
return i3sResources;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
i3sResources.materialDefinitionInfos = [];
|
|
423
|
+
|
|
424
|
+
for (const gltfMaterial of gltfMaterials) {
|
|
425
|
+
const {
|
|
426
|
+
materialDefinitionInfo,
|
|
427
|
+
textureDefinitionInfo
|
|
428
|
+
} = convertGLTFMaterialToI3sSharedResources(gltfMaterial, nodeId);
|
|
429
|
+
i3sResources.materialDefinitionInfos.push(materialDefinitionInfo);
|
|
430
|
+
|
|
431
|
+
if (textureDefinitionInfo) {
|
|
432
|
+
i3sResources.textureDefinitionInfos = i3sResources.textureDefinitionInfos || [];
|
|
433
|
+
i3sResources.textureDefinitionInfos.push(textureDefinitionInfo);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
return i3sResources;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
function convertGLTFMaterialToI3sSharedResources(gltfMaterial, nodeId) {
|
|
441
|
+
const texture = gltfMaterial.pbrMetallicRoughness.baseColorTexture || gltfMaterial.emissiveTexture;
|
|
442
|
+
let textureDefinitionInfo = null;
|
|
443
|
+
|
|
444
|
+
if (texture) {
|
|
445
|
+
textureDefinitionInfo = extractSharedResourcesTextureInfo(texture.texture, nodeId);
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
const {
|
|
449
|
+
baseColorFactor,
|
|
450
|
+
metallicFactor
|
|
451
|
+
} = gltfMaterial.pbrMetallicRoughness;
|
|
452
|
+
let colorFactor = baseColorFactor;
|
|
453
|
+
|
|
454
|
+
if ((!baseColorFactor || baseColorFactor[3] === 0) && gltfMaterial.emissiveFactor) {
|
|
455
|
+
colorFactor = gltfMaterial.emissiveFactor;
|
|
456
|
+
colorFactor[3] = colorFactor[3] || 1;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
return {
|
|
460
|
+
materialDefinitionInfo: extractSharedResourcesMaterialInfo(colorFactor, metallicFactor),
|
|
461
|
+
textureDefinitionInfo
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
function extractSharedResourcesMaterialInfo(baseColorFactor, metallicFactor = 0) {
|
|
466
|
+
const matDielectricColorComponent = 0.04 / 255;
|
|
467
|
+
const black = new _core.Vector4(0, 0, 0, 1);
|
|
468
|
+
const unitVector = new _core.Vector4(1, 1, 1, 1);
|
|
469
|
+
const dielectricSpecular = new _core.Vector4(matDielectricColorComponent, matDielectricColorComponent, matDielectricColorComponent, 0);
|
|
470
|
+
const baseColorVector = new _core.Vector4(baseColorFactor);
|
|
471
|
+
const firstOperand = unitVector.subtract(dielectricSpecular).multiply(baseColorVector);
|
|
472
|
+
const diffuse = firstOperand.lerp(firstOperand, black, metallicFactor);
|
|
473
|
+
dielectricSpecular[3] = 1;
|
|
474
|
+
const specular = dielectricSpecular.lerp(dielectricSpecular, baseColorVector, metallicFactor);
|
|
475
|
+
return {
|
|
476
|
+
diffuse: diffuse.toArray(),
|
|
477
|
+
specular: specular.toArray()
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
function extractSharedResourcesTextureInfo(texture, nodeId) {
|
|
482
|
+
return {
|
|
483
|
+
encoding: [texture.source.mimeType],
|
|
484
|
+
images: [{
|
|
485
|
+
id: generateImageId(texture, nodeId),
|
|
486
|
+
size: texture.source.image.width,
|
|
487
|
+
length: [texture.source.image.data.length]
|
|
488
|
+
}]
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
function generateImageId(texture, nodeId) {
|
|
493
|
+
const {
|
|
494
|
+
width,
|
|
495
|
+
height
|
|
496
|
+
} = texture.source.image;
|
|
497
|
+
const levelCountOfTexture = 1;
|
|
498
|
+
const indexOfLevel = 0;
|
|
499
|
+
const indexOfTextureInStore = nodeId + 1;
|
|
500
|
+
const zerosCount = 32 - indexOfTextureInStore.toString(2).length;
|
|
501
|
+
const rightHalf = '0'.repeat(zerosCount).concat(indexOfTextureInStore.toString(2));
|
|
502
|
+
const shiftedLevelCountOfTexture = levelCountOfTexture << 28;
|
|
503
|
+
const shiftedIndexOfLevel = indexOfLevel << 24;
|
|
504
|
+
const shiftedWidth = width - 1 << 12;
|
|
505
|
+
const shiftedHeight = height - 1 << 0;
|
|
506
|
+
const leftHalf = shiftedLevelCountOfTexture + shiftedIndexOfLevel + shiftedWidth + shiftedHeight;
|
|
507
|
+
const imageId = BigInt("0b".concat(leftHalf.toString(2)).concat(rightHalf));
|
|
508
|
+
return imageId.toString();
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
function makeFeatureIdsUnique(featureIds, featureIndices, featuresHashArray, batchTable) {
|
|
512
|
+
const replaceMap = getFeaturesReplaceMap(featureIds, batchTable, featuresHashArray);
|
|
513
|
+
replaceIndicesByUnique(featureIndices, replaceMap);
|
|
514
|
+
replaceIndicesByUnique(featureIds, replaceMap);
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
function getFeaturesReplaceMap(featureIds, batchTable, featuresHashArray) {
|
|
518
|
+
const featureMap = {};
|
|
519
|
+
|
|
520
|
+
for (let index = 0; index < featureIds.length; index++) {
|
|
521
|
+
const oldFeatureId = featureIds[index];
|
|
522
|
+
const uniqueFeatureId = getOrCreateUniqueFeatureId(index, batchTable, featuresHashArray);
|
|
523
|
+
featureMap[oldFeatureId.toString()] = uniqueFeatureId;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
return featureMap;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
function generateStringFromBatchTableByIndex(batchTable, index) {
|
|
530
|
+
let str = '';
|
|
531
|
+
|
|
532
|
+
for (const key in batchTable) {
|
|
533
|
+
str += batchTable[key][index];
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
return str;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
function getOrCreateUniqueFeatureId(index, batchTable, featuresHashArray) {
|
|
540
|
+
const batchTableStr = generateStringFromBatchTableByIndex(batchTable, index);
|
|
541
|
+
const hash = (0, _md.default)(batchTableStr);
|
|
542
|
+
|
|
543
|
+
if (featuresHashArray.includes(hash)) {
|
|
544
|
+
return featuresHashArray.indexOf(hash);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
return featuresHashArray.push(hash) - 1;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
function replaceIndicesByUnique(indicesArray, featureMap) {
|
|
551
|
+
for (let index = 0; index < indicesArray.length; index++) {
|
|
552
|
+
indicesArray[index] = featureMap[indicesArray[index]];
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
function convertBatchTableToAttributeBuffers(batchTable, featureIds, attributeStorageInfo) {
|
|
557
|
+
const attributeBuffers = [];
|
|
558
|
+
|
|
559
|
+
if (batchTable) {
|
|
560
|
+
const batchTableWithFeatureIds = {
|
|
561
|
+
OBJECTID: featureIds,
|
|
562
|
+
...batchTable
|
|
563
|
+
};
|
|
564
|
+
|
|
565
|
+
for (const key in batchTableWithFeatureIds) {
|
|
566
|
+
const type = getAttributeType(key, attributeStorageInfo);
|
|
567
|
+
let attributeBuffer = null;
|
|
568
|
+
|
|
569
|
+
switch (type) {
|
|
570
|
+
case OBJECT_ID_TYPE:
|
|
571
|
+
case SHORT_INT_TYPE:
|
|
572
|
+
attributeBuffer = generateShortIntegerAttributeBuffer(batchTableWithFeatureIds[key]);
|
|
573
|
+
break;
|
|
574
|
+
|
|
575
|
+
case DOUBLE_TYPE:
|
|
576
|
+
attributeBuffer = generateDoubleAttributeBuffer(batchTableWithFeatureIds[key]);
|
|
577
|
+
break;
|
|
578
|
+
|
|
579
|
+
case STRING_TYPE:
|
|
580
|
+
attributeBuffer = generateStringAttributeBuffer(batchTableWithFeatureIds[key]);
|
|
581
|
+
break;
|
|
582
|
+
|
|
583
|
+
default:
|
|
584
|
+
attributeBuffer = generateStringAttributeBuffer(batchTableWithFeatureIds[key]);
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
attributeBuffers.push(attributeBuffer);
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
return attributeBuffers;
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
function getAttributeType(key, attributeStorageInfo) {
|
|
595
|
+
const attribute = attributeStorageInfo.find(attr => attr.name === key);
|
|
596
|
+
return attribute.attributeValues.valueType;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
function generateShortIntegerAttributeBuffer(featureIds) {
|
|
600
|
+
const count = new Uint32Array([featureIds.length]);
|
|
601
|
+
const valuesArray = new Uint32Array(featureIds);
|
|
602
|
+
return (0, _loaderUtils.concatenateArrayBuffers)(count.buffer, valuesArray.buffer);
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
function generateDoubleAttributeBuffer(featureIds) {
|
|
606
|
+
const count = new Uint32Array([featureIds.length]);
|
|
607
|
+
const padding = new Uint8Array(4);
|
|
608
|
+
const valuesArray = new Float64Array(featureIds);
|
|
609
|
+
return (0, _loaderUtils.concatenateArrayBuffers)(count.buffer, padding.buffer, valuesArray.buffer);
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
function generateStringAttributeBuffer(batchAttributes) {
|
|
613
|
+
const stringCountArray = new Uint32Array([batchAttributes.length]);
|
|
614
|
+
let totalNumberOfBytes = 0;
|
|
615
|
+
const stringSizesArray = new Uint32Array(batchAttributes.length);
|
|
616
|
+
const stringBufferArray = [];
|
|
617
|
+
|
|
618
|
+
for (let index = 0; index < batchAttributes.length; index++) {
|
|
619
|
+
const currentString = "".concat(String(batchAttributes[index]), "\0");
|
|
620
|
+
const currentStringBuffer = Buffer.from(currentString);
|
|
621
|
+
const currentStringSize = currentStringBuffer.length;
|
|
622
|
+
totalNumberOfBytes += currentStringSize;
|
|
623
|
+
stringSizesArray[index] = currentStringSize;
|
|
624
|
+
stringBufferArray.push(currentStringBuffer);
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
const totalBytes = new Uint32Array([totalNumberOfBytes]);
|
|
628
|
+
return (0, _loaderUtils.concatenateArrayBuffers)(stringCountArray.buffer, totalBytes.buffer, stringSizesArray.buffer, ...stringBufferArray);
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
function generateBigUint64Array(featureIds) {
|
|
632
|
+
const typedFeatureIds = new BigUint64Array(featureIds.length);
|
|
633
|
+
|
|
634
|
+
for (let index = 0; index < featureIds.length; index++) {
|
|
635
|
+
typedFeatureIds[index] = BigInt(featureIds[index]);
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
return typedFeatureIds;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
async function generateCompressedGeometry(vertexCount, convertedAttributes, attributes) {
|
|
642
|
+
const {
|
|
643
|
+
positions,
|
|
644
|
+
normals,
|
|
645
|
+
texCoords,
|
|
646
|
+
colors,
|
|
647
|
+
featureIds,
|
|
648
|
+
faceRange
|
|
649
|
+
} = attributes;
|
|
650
|
+
const indices = new Uint32Array(vertexCount);
|
|
651
|
+
|
|
652
|
+
for (let index = 0; index < indices.length; index++) {
|
|
653
|
+
indices.set([index], index);
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
const featureIndices = new Uint32Array(convertedAttributes.featureIndices.length ? convertedAttributes.featureIndices : vertexCount);
|
|
657
|
+
const featureIndex = generateFeatureIndexAttribute(featureIndices, faceRange);
|
|
658
|
+
const compressedAttributes = {
|
|
659
|
+
positions,
|
|
660
|
+
normals,
|
|
661
|
+
colors,
|
|
662
|
+
'feature-index': featureIndex
|
|
663
|
+
};
|
|
664
|
+
|
|
665
|
+
if (texCoords.length) {
|
|
666
|
+
compressedAttributes.texCoords = texCoords;
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
const attributesMetadata = {
|
|
670
|
+
'feature-index': {
|
|
671
|
+
'i3s-attribute-type': 'feature-index',
|
|
672
|
+
'i3s-feature-ids': new Int32Array(featureIds)
|
|
673
|
+
}
|
|
674
|
+
};
|
|
675
|
+
return new Uint8Array(await (0, _core2.encode)({
|
|
676
|
+
attributes: compressedAttributes,
|
|
677
|
+
indices
|
|
678
|
+
}, _draco.DracoWriter, {
|
|
679
|
+
draco: {
|
|
680
|
+
method: 'MESH_SEQUENTIAL_ENCODING',
|
|
681
|
+
attributesMetadata
|
|
682
|
+
}
|
|
683
|
+
}));
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
function generateFeatureIndexAttribute(featureIndex, faceRange) {
|
|
687
|
+
const orderedFeatureIndices = new Uint32Array(featureIndex.length);
|
|
688
|
+
let fillIndex = 0;
|
|
689
|
+
let startIndex = 0;
|
|
690
|
+
|
|
691
|
+
for (let index = 1; index < faceRange.length; index += 2) {
|
|
692
|
+
const endIndex = (faceRange[index] + 1) * VALUES_PER_VERTEX;
|
|
693
|
+
orderedFeatureIndices.fill(fillIndex, startIndex, endIndex);
|
|
694
|
+
fillIndex++;
|
|
695
|
+
startIndex = endIndex + 1;
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
return orderedFeatureIndices;
|
|
699
|
+
}
|
|
700
|
+
//# sourceMappingURL=geometry-converter.js.map
|