@loaders.gl/tile-converter 4.2.0-alpha.3 → 4.2.0-alpha.5
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/3d-tiles-converter.d.ts +3 -3
- package/dist/3d-tiles-converter/3d-tiles-converter.d.ts.map +1 -1
- package/dist/3d-tiles-converter/3d-tiles-converter.js +329 -293
- package/dist/3d-tiles-converter/helpers/b3dm-converter.js +257 -200
- package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +14 -5
- package/dist/3d-tiles-converter/helpers/load-i3s.js +106 -75
- package/dist/3d-tiles-converter/helpers/texture-atlas.js +44 -21
- package/dist/3d-tiles-converter/json-templates/tileset.js +32 -33
- package/dist/constants.js +0 -1
- package/dist/converter-cli.js +255 -234
- package/dist/converter.min.cjs +80 -90
- package/dist/deps-installer/deps-installer.js +73 -59
- package/dist/i3s-converter/helpers/attribute-metadata-info.js +207 -153
- package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts +1 -1
- package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/batch-ids-extensions.js +145 -103
- package/dist/i3s-converter/helpers/coordinate-converter.js +100 -65
- package/dist/i3s-converter/helpers/create-scene-server-path.js +14 -9
- package/dist/i3s-converter/helpers/feature-attributes.js +168 -105
- package/dist/i3s-converter/helpers/geometry-attributes.d.ts +1 -1
- package/dist/i3s-converter/helpers/geometry-attributes.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/geometry-attributes.js +204 -212
- 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/geometry-converter.js +1148 -829
- package/dist/i3s-converter/helpers/gltf-attributes.d.ts +1 -1
- package/dist/i3s-converter/helpers/gltf-attributes.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/gltf-attributes.js +111 -97
- package/dist/i3s-converter/helpers/load-3d-tiles.js +103 -66
- package/dist/i3s-converter/helpers/node-debug.js +98 -54
- package/dist/i3s-converter/helpers/node-index-document.d.ts +3 -3
- package/dist/i3s-converter/helpers/node-index-document.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/node-index-document.js +248 -177
- package/dist/i3s-converter/helpers/node-pages.d.ts +1 -1
- package/dist/i3s-converter/helpers/node-pages.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/node-pages.js +299 -194
- package/dist/i3s-converter/helpers/preprocess-3d-tiles.d.ts +1 -1
- package/dist/i3s-converter/helpers/preprocess-3d-tiles.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/preprocess-3d-tiles.js +92 -60
- package/dist/i3s-converter/helpers/progress.js +134 -83
- package/dist/i3s-converter/helpers/tileset-traversal.d.ts +1 -1
- package/dist/i3s-converter/helpers/tileset-traversal.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/tileset-traversal.js +24 -13
- package/dist/i3s-converter/i3s-converter.d.ts +7 -7
- package/dist/i3s-converter/i3s-converter.d.ts.map +1 -1
- package/dist/i3s-converter/i3s-converter.js +1044 -898
- package/dist/i3s-converter/json-templates/geometry-definitions.js +70 -79
- package/dist/i3s-converter/json-templates/layers.js +120 -121
- package/dist/i3s-converter/json-templates/metadata.js +19 -20
- package/dist/i3s-converter/json-templates/node.js +73 -71
- package/dist/i3s-converter/json-templates/scene-server.js +25 -26
- package/dist/i3s-converter/json-templates/shared-resources.js +107 -108
- package/dist/i3s-converter/json-templates/store.js +96 -94
- package/dist/i3s-converter/types.js +35 -23
- package/dist/i3s-server/app.js +15 -12
- package/dist/i3s-server/bin/www.js +14 -7
- package/dist/i3s-server/controllers/index-controller.js +18 -15
- package/dist/i3s-server/controllers/slpk-controller.js +22 -11
- package/dist/i3s-server/routes/index.js +9 -8
- package/dist/i3s-server/routes/slpk-router.js +18 -17
- package/dist/i3s-server/utils/create-scene-server.js +15 -10
- package/dist/i3s-server/utils/server-utils.js +49 -32
- package/dist/index.cjs +292 -851
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/lib/json-schemas/conversion-dump-json-schema.js +243 -421
- package/dist/lib/utils/cli-utils.js +63 -36
- package/dist/lib/utils/compress-util.js +20 -15
- package/dist/lib/utils/conversion-dump.d.ts +1 -1
- package/dist/lib/utils/conversion-dump.d.ts.map +1 -1
- package/dist/lib/utils/conversion-dump.js +209 -187
- package/dist/lib/utils/file-utils.js +122 -74
- package/dist/lib/utils/geometry-utils.js +13 -7
- package/dist/lib/utils/lod-conversion-utils.js +65 -33
- package/dist/lib/utils/queue.js +12 -13
- package/dist/lib/utils/statistic-utills.d.ts +6 -23
- package/dist/lib/utils/statistic-utills.js +64 -59
- package/dist/lib/utils/write-queue.d.ts +2 -2
- package/dist/lib/utils/write-queue.d.ts.map +1 -1
- package/dist/lib/utils/write-queue.js +68 -86
- package/dist/pgm-loader.js +17 -13
- package/dist/slpk-extractor/slpk-extractor.js +59 -50
- package/dist/slpk-extractor-cli.js +82 -59
- package/package.json +18 -18
- 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/helpers/load-i3s.js.map +0 -1
- package/dist/3d-tiles-converter/helpers/texture-atlas.js.map +0 -1
- package/dist/3d-tiles-converter/json-templates/tileset.js.map +0 -1
- package/dist/constants.js.map +0 -1
- package/dist/converter-cli.js.map +0 -1
- package/dist/deps-installer/deps-installer.js.map +0 -1
- package/dist/i3s-converter/helpers/attribute-metadata-info.js.map +0 -1
- package/dist/i3s-converter/helpers/batch-ids-extensions.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/feature-attributes.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/gltf-attributes.js.map +0 -1
- package/dist/i3s-converter/helpers/load-3d-tiles.js.map +0 -1
- package/dist/i3s-converter/helpers/node-debug.js.map +0 -1
- package/dist/i3s-converter/helpers/node-index-document.js.map +0 -1
- package/dist/i3s-converter/helpers/node-pages.js.map +0 -1
- package/dist/i3s-converter/helpers/preprocess-3d-tiles.js.map +0 -1
- package/dist/i3s-converter/helpers/progress.js.map +0 -1
- package/dist/i3s-converter/helpers/tileset-traversal.js.map +0 -1
- package/dist/i3s-converter/i3s-converter.js.map +0 -1
- package/dist/i3s-converter/json-templates/geometry-definitions.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-converter/types.js.map +0 -1
- package/dist/i3s-server/README.md +0 -63
- package/dist/i3s-server/app.js.map +0 -1
- package/dist/i3s-server/bin/www.js.map +0 -1
- package/dist/i3s-server/certs/cert.pem +0 -19
- package/dist/i3s-server/certs/key.pem +0 -27
- package/dist/i3s-server/controllers/index-controller.js.map +0 -1
- package/dist/i3s-server/controllers/slpk-controller.js.map +0 -1
- package/dist/i3s-server/routes/index.js.map +0 -1
- package/dist/i3s-server/routes/slpk-router.js.map +0 -1
- package/dist/i3s-server/utils/create-scene-server.js.map +0 -1
- package/dist/i3s-server/utils/server-utils.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/json-schemas/conversion-dump-json-schema.js.map +0 -1
- package/dist/lib/utils/cli-utils.js.map +0 -1
- package/dist/lib/utils/compress-util.js.map +0 -1
- package/dist/lib/utils/conversion-dump.js.map +0 -1
- package/dist/lib/utils/file-utils.js.map +0 -1
- package/dist/lib/utils/geometry-utils.js.map +0 -1
- package/dist/lib/utils/lod-conversion-utils.js.map +0 -1
- package/dist/lib/utils/queue.js.map +0 -1
- package/dist/lib/utils/statistic-utills.js.map +0 -1
- package/dist/lib/utils/write-queue.js.map +0 -1
- package/dist/pgm-loader.js.map +0 -1
- package/dist/slpk-extractor/slpk-extractor.js.map +0 -1
- package/dist/slpk-extractor-cli.js.map +0 -1
|
@@ -10,217 +10,274 @@ const scratchVector = new Vector3();
|
|
|
10
10
|
const KHR_MATERIALS_UNLIT = 'KHR_materials_unlit';
|
|
11
11
|
const METALLIC_FACTOR_DEFAULT = 1.0;
|
|
12
12
|
const ROUGHNESS_FACTOR_DEFAULT = 1.0;
|
|
13
|
+
/**
|
|
14
|
+
* Converts content of an I3S node to *.b3dm's file content
|
|
15
|
+
*/
|
|
13
16
|
export default class B3dmConverter {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
async buildGLTF(i3sAttributesData, featureAttributes) {
|
|
30
|
-
const {
|
|
31
|
-
tileContent,
|
|
32
|
-
textureFormat,
|
|
33
|
-
box
|
|
34
|
-
} = i3sAttributesData;
|
|
35
|
-
const {
|
|
36
|
-
material,
|
|
37
|
-
attributes,
|
|
38
|
-
indices: originalIndices,
|
|
39
|
-
modelMatrix
|
|
40
|
-
} = tileContent;
|
|
41
|
-
const gltfBuilder = new GLTFScenegraph();
|
|
42
|
-
const textureIndex = await this._addI3sTextureToGLTF(tileContent, textureFormat, gltfBuilder);
|
|
43
|
-
const pbrMetallicRoughness = material === null || material === void 0 ? void 0 : material.pbrMetallicRoughness;
|
|
44
|
-
if (pbrMetallicRoughness && (pbrMetallicRoughness.metallicFactor === undefined || pbrMetallicRoughness.metallicFactor === METALLIC_FACTOR_DEFAULT) && (pbrMetallicRoughness.roughnessFactor === undefined || pbrMetallicRoughness.roughnessFactor === ROUGHNESS_FACTOR_DEFAULT)) {
|
|
45
|
-
gltfBuilder.addObjectExtension(material, KHR_MATERIALS_UNLIT, {});
|
|
46
|
-
gltfBuilder.addExtension(KHR_MATERIALS_UNLIT);
|
|
17
|
+
/**
|
|
18
|
+
* The starter of content conversion
|
|
19
|
+
* @param i3sTile - Tile3D instance for I3S node
|
|
20
|
+
* @returns - encoded content
|
|
21
|
+
*/
|
|
22
|
+
async convert(i3sAttributesData, featureAttributes = null) {
|
|
23
|
+
const gltf = await this.buildGLTF(i3sAttributesData, featureAttributes);
|
|
24
|
+
const b3dm = encodeSync({
|
|
25
|
+
gltfEncoded: new Uint8Array(gltf),
|
|
26
|
+
type: 'b3dm',
|
|
27
|
+
featuresLength: this._getFeaturesLength(featureAttributes),
|
|
28
|
+
batchTable: featureAttributes
|
|
29
|
+
}, Tile3DWriter);
|
|
30
|
+
return b3dm;
|
|
47
31
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Build and encode gltf
|
|
34
|
+
* @param i3sTile - Tile3D instance for I3S node
|
|
35
|
+
* @returns - encoded glb content
|
|
36
|
+
*/
|
|
37
|
+
async buildGLTF(i3sAttributesData, featureAttributes) {
|
|
38
|
+
const { tileContent, textureFormat, box } = i3sAttributesData;
|
|
39
|
+
const { material, attributes, indices: originalIndices, modelMatrix } = tileContent;
|
|
40
|
+
const gltfBuilder = new GLTFScenegraph();
|
|
41
|
+
const textureIndex = await this._addI3sTextureToGLTF(tileContent, textureFormat, gltfBuilder);
|
|
42
|
+
// Add KHR_MATERIALS_UNLIT extension in the following cases:
|
|
43
|
+
// - metallicFactor or roughnessFactor are set to default values
|
|
44
|
+
// - metallicFactor or roughnessFactor are not set
|
|
45
|
+
const pbrMetallicRoughness = material?.pbrMetallicRoughness;
|
|
46
|
+
if (pbrMetallicRoughness &&
|
|
47
|
+
(pbrMetallicRoughness.metallicFactor === undefined ||
|
|
48
|
+
pbrMetallicRoughness.metallicFactor === METALLIC_FACTOR_DEFAULT) &&
|
|
49
|
+
(pbrMetallicRoughness.roughnessFactor === undefined ||
|
|
50
|
+
pbrMetallicRoughness.roughnessFactor === ROUGHNESS_FACTOR_DEFAULT)) {
|
|
51
|
+
gltfBuilder.addObjectExtension(material, KHR_MATERIALS_UNLIT, {});
|
|
52
|
+
gltfBuilder.addExtension(KHR_MATERIALS_UNLIT);
|
|
53
|
+
}
|
|
54
|
+
const pbrMaterialInfo = this._convertI3sMaterialToGLTFMaterial(material, textureIndex);
|
|
55
|
+
const materialIndex = gltfBuilder.addMaterial(pbrMaterialInfo);
|
|
56
|
+
const positions = attributes.positions;
|
|
57
|
+
const positionsValue = positions.value;
|
|
58
|
+
if (attributes.uvRegions && attributes.texCoords) {
|
|
59
|
+
attributes.texCoords.value = convertTextureAtlas(attributes.texCoords.value, attributes.uvRegions.value);
|
|
60
|
+
}
|
|
61
|
+
const cartesianOrigin = new Vector3(box);
|
|
62
|
+
const cartographicOrigin = Ellipsoid.WGS84.cartesianToCartographic(cartesianOrigin, new Vector3());
|
|
63
|
+
attributes.positions.value = this._normalizePositions(positionsValue, cartesianOrigin, cartographicOrigin, modelMatrix);
|
|
64
|
+
this._createBatchIds(tileContent, featureAttributes);
|
|
65
|
+
if (attributes.normals && !this._checkNormals(attributes.normals.value)) {
|
|
66
|
+
delete attributes.normals;
|
|
67
|
+
}
|
|
68
|
+
const indices = originalIndices || generateSyntheticIndices(positionsValue.length / positions.size);
|
|
69
|
+
const meshIndex = gltfBuilder.addMesh({
|
|
70
|
+
attributes,
|
|
71
|
+
indices,
|
|
72
|
+
material: materialIndex,
|
|
73
|
+
mode: 4
|
|
74
|
+
});
|
|
75
|
+
const transformMatrix = this._generateTransformMatrix(cartesianOrigin);
|
|
76
|
+
const nodeIndex = gltfBuilder.addNode({ meshIndex, matrix: transformMatrix });
|
|
77
|
+
const sceneIndex = gltfBuilder.addScene({ nodeIndices: [nodeIndex] });
|
|
78
|
+
gltfBuilder.setDefaultScene(sceneIndex);
|
|
79
|
+
gltfBuilder.createBinaryChunk();
|
|
80
|
+
const gltfBuffer = encodeSync(gltfBuilder.gltf, GLTFWriter);
|
|
81
|
+
return gltfBuffer;
|
|
61
82
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
material,
|
|
86
|
-
attributes
|
|
87
|
-
} = tileContent;
|
|
88
|
-
let textureIndex = null;
|
|
89
|
-
let selectedTexture = texture;
|
|
90
|
-
if (!texture && material) {
|
|
91
|
-
selectedTexture = material.pbrMetallicRoughness && material.pbrMetallicRoughness.baseColorTexture && material.pbrMetallicRoughness.baseColorTexture.texture.source.image;
|
|
83
|
+
/**
|
|
84
|
+
* Update gltfBuilder with texture from I3S tile
|
|
85
|
+
* @param {object} i3sTile - Tile3D object
|
|
86
|
+
* @param {GLTFScenegraph} gltfBuilder - gltfScenegraph instance to construct GLTF
|
|
87
|
+
* @returns {Promise<number | null>} - GLTF texture index
|
|
88
|
+
*/
|
|
89
|
+
async _addI3sTextureToGLTF(tileContent, textureFormat, gltfBuilder) {
|
|
90
|
+
const { texture, material, attributes } = tileContent;
|
|
91
|
+
let textureIndex = null;
|
|
92
|
+
let selectedTexture = texture;
|
|
93
|
+
if (!texture && material) {
|
|
94
|
+
selectedTexture =
|
|
95
|
+
material.pbrMetallicRoughness &&
|
|
96
|
+
material.pbrMetallicRoughness.baseColorTexture &&
|
|
97
|
+
material.pbrMetallicRoughness.baseColorTexture.texture.source.image;
|
|
98
|
+
}
|
|
99
|
+
if (selectedTexture) {
|
|
100
|
+
const mimeType = this._deduceMimeTypeFromFormat(textureFormat);
|
|
101
|
+
const imageIndex = gltfBuilder.addImage(selectedTexture, mimeType);
|
|
102
|
+
textureIndex = gltfBuilder.addTexture({ imageIndex });
|
|
103
|
+
delete attributes.colors;
|
|
104
|
+
}
|
|
105
|
+
return textureIndex;
|
|
92
106
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
107
|
+
/**
|
|
108
|
+
* Generate a positions array which is correct for 3DTiles/GLTF format
|
|
109
|
+
* @param {Float64Array} positionsValue - the input geometry positions array
|
|
110
|
+
* @param {number[]} cartesianOrigin - the tile center in the cartesian coordinate system
|
|
111
|
+
* @param {number[]} cartographicOrigin - the tile center in the cartographic coordinate system
|
|
112
|
+
* @param {number[]} modelMatrix - the model matrix of geometry
|
|
113
|
+
* @returns {Float32Array} - the output geometry positions array
|
|
114
|
+
*/
|
|
115
|
+
_normalizePositions(positionsValue, cartesianOrigin, cartographicOrigin, modelMatrix) {
|
|
116
|
+
const newPositionsValue = new Float32Array(positionsValue.length);
|
|
117
|
+
for (let index = 0; index < positionsValue.length; index += 3) {
|
|
118
|
+
const vertex = positionsValue.subarray(index, index + 3);
|
|
119
|
+
const cartesianOriginVector = new Vector3(cartesianOrigin);
|
|
120
|
+
let vertexVector = new Vector3(Array.from(vertex))
|
|
121
|
+
.transform(modelMatrix)
|
|
122
|
+
.add(cartographicOrigin);
|
|
123
|
+
Ellipsoid.WGS84.cartographicToCartesian(vertexVector, scratchVector);
|
|
124
|
+
vertexVector = scratchVector.subtract(cartesianOriginVector);
|
|
125
|
+
newPositionsValue.set(vertexVector, index);
|
|
126
|
+
}
|
|
127
|
+
return newPositionsValue;
|
|
100
128
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
129
|
+
/**
|
|
130
|
+
* Generate the transformation matrix for GLTF node:
|
|
131
|
+
* https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#reference-node
|
|
132
|
+
* 1. Create the translate transformation from cartesianOrigin (the positions array stores offsets from this cartesianOrigin)
|
|
133
|
+
* 2. Create the rotation transformation to rotate model from z-up coordinates (I3S specific) to y-up coordinates (GLTF specific)
|
|
134
|
+
* @param {number[]} cartesianOrigin - the tile center in the cartesian coordinate system
|
|
135
|
+
* @returns {Matrix4} - an array of 16 numbers (4x4 matrix)
|
|
136
|
+
*/
|
|
137
|
+
_generateTransformMatrix(cartesianOrigin) {
|
|
138
|
+
const translateOriginMatrix = new Matrix4().translate(cartesianOrigin);
|
|
139
|
+
const result = translateOriginMatrix.multiplyLeft(Z_UP_TO_Y_UP_MATRIX);
|
|
140
|
+
return result;
|
|
112
141
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
142
|
+
/**
|
|
143
|
+
* Create _BATCHID attribute
|
|
144
|
+
* @param {Object} i3sContent - the source object
|
|
145
|
+
* @returns {void}
|
|
146
|
+
*/
|
|
147
|
+
_createBatchIds(i3sContent, featureAttributes) {
|
|
148
|
+
const { featureIds } = i3sContent;
|
|
149
|
+
const { OBJECTID: objectIds } = featureAttributes || {};
|
|
150
|
+
if (!featureIds || !objectIds) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
for (let i = 0; i < featureIds.length; i++) {
|
|
154
|
+
const featureId = featureIds[i];
|
|
155
|
+
const batchId = objectIds.indexOf(featureId);
|
|
156
|
+
featureIds[i] = batchId;
|
|
157
|
+
}
|
|
158
|
+
i3sContent.attributes._BATCHID = {
|
|
159
|
+
size: 1,
|
|
160
|
+
byteOffset: 0,
|
|
161
|
+
value: featureIds
|
|
162
|
+
};
|
|
129
163
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
164
|
+
/**
|
|
165
|
+
* Deduce mime type by format from `textureSetDefinition.formats[0].format`
|
|
166
|
+
* https://github.com/Esri/i3s-spec/blob/master/docs/1.7/textureSetDefinitionFormat.cmn.md
|
|
167
|
+
* @param {string} format - format name
|
|
168
|
+
* @returns {string} mime type.
|
|
169
|
+
*/
|
|
170
|
+
_deduceMimeTypeFromFormat(format) {
|
|
171
|
+
switch (format) {
|
|
172
|
+
case 'jpg':
|
|
173
|
+
return 'image/jpeg';
|
|
174
|
+
case 'png':
|
|
175
|
+
return 'image/png';
|
|
176
|
+
case 'ktx2':
|
|
177
|
+
return 'image/ktx2';
|
|
178
|
+
default:
|
|
179
|
+
console.warn(`Unexpected texture format in I3S: ${format}`); // eslint-disable-line no-console, no-undef
|
|
180
|
+
return 'image/jpeg';
|
|
181
|
+
}
|
|
134
182
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
183
|
+
/**
|
|
184
|
+
* Convert i3s material to GLTF compatible material
|
|
185
|
+
* @param {object} material - i3s material definition
|
|
186
|
+
* @param {number | null} textureIndex - texture index in GLTF
|
|
187
|
+
* @returns {object} GLTF material
|
|
188
|
+
*/
|
|
189
|
+
_convertI3sMaterialToGLTFMaterial(material, textureIndex) {
|
|
190
|
+
const isTextureIndexExists = textureIndex !== null;
|
|
191
|
+
if (!material) {
|
|
192
|
+
material = {
|
|
193
|
+
alphaMode: 'OPAQUE',
|
|
194
|
+
doubleSided: false,
|
|
195
|
+
pbrMetallicRoughness: {
|
|
196
|
+
metallicFactor: 0,
|
|
197
|
+
roughnessFactor: 1
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
if (isTextureIndexExists) {
|
|
201
|
+
material.pbrMetallicRoughness.baseColorTexture = {
|
|
202
|
+
index: textureIndex,
|
|
203
|
+
texCoord: 0
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
material.pbrMetallicRoughness.baseColorFactor = [1, 1, 1, 1];
|
|
208
|
+
}
|
|
209
|
+
return material;
|
|
210
|
+
}
|
|
211
|
+
if (textureIndex !== null) {
|
|
212
|
+
material = this._setGLTFTexture(material, textureIndex);
|
|
213
|
+
}
|
|
214
|
+
return material;
|
|
152
215
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
if (isTextureIndexExists) {
|
|
166
|
-
material.pbrMetallicRoughness.baseColorTexture = {
|
|
167
|
-
index: textureIndex,
|
|
168
|
-
texCoord: 0
|
|
216
|
+
/**
|
|
217
|
+
* Set texture properties in material with GLTF textureIndex
|
|
218
|
+
* @param {object} materialDefinition - i3s material definition
|
|
219
|
+
* @param {number} textureIndex - texture index in GLTF
|
|
220
|
+
* @returns {void}
|
|
221
|
+
*/
|
|
222
|
+
_setGLTFTexture(materialDefinition, textureIndex) {
|
|
223
|
+
const material = {
|
|
224
|
+
...materialDefinition,
|
|
225
|
+
pbrMetallicRoughness: { ...materialDefinition.pbrMetallicRoughness }
|
|
169
226
|
};
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
227
|
+
// I3SLoader now support loading only one texture. This elseif sequence will assign this texture to one of
|
|
228
|
+
// properties defined in materialDefinition
|
|
229
|
+
if (materialDefinition.pbrMetallicRoughness &&
|
|
230
|
+
materialDefinition.pbrMetallicRoughness.baseColorTexture) {
|
|
231
|
+
material.pbrMetallicRoughness.baseColorTexture = {
|
|
232
|
+
index: textureIndex,
|
|
233
|
+
texCoord: 0
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
else if (materialDefinition.emissiveTexture) {
|
|
237
|
+
material.emissiveTexture = {
|
|
238
|
+
index: textureIndex,
|
|
239
|
+
texCoord: 0
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
else if (materialDefinition.pbrMetallicRoughness &&
|
|
243
|
+
materialDefinition.pbrMetallicRoughness.metallicRoughnessTexture) {
|
|
244
|
+
material.pbrMetallicRoughness.metallicRoughnessTexture = {
|
|
245
|
+
index: textureIndex,
|
|
246
|
+
texCoord: 0
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
else if (materialDefinition.normalTexture) {
|
|
250
|
+
material.normalTexture = {
|
|
251
|
+
index: textureIndex,
|
|
252
|
+
texCoord: 0
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
else if (materialDefinition.occlusionTexture) {
|
|
256
|
+
material.occlusionTexture = {
|
|
257
|
+
index: textureIndex,
|
|
258
|
+
texCoord: 0
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
return material;
|
|
177
262
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
index: textureIndex,
|
|
190
|
-
texCoord: 0
|
|
191
|
-
};
|
|
192
|
-
} else if (materialDefinition.emissiveTexture) {
|
|
193
|
-
material.emissiveTexture = {
|
|
194
|
-
index: textureIndex,
|
|
195
|
-
texCoord: 0
|
|
196
|
-
};
|
|
197
|
-
} else if (materialDefinition.pbrMetallicRoughness && materialDefinition.pbrMetallicRoughness.metallicRoughnessTexture) {
|
|
198
|
-
material.pbrMetallicRoughness.metallicRoughnessTexture = {
|
|
199
|
-
index: textureIndex,
|
|
200
|
-
texCoord: 0
|
|
201
|
-
};
|
|
202
|
-
} else if (materialDefinition.normalTexture) {
|
|
203
|
-
material.normalTexture = {
|
|
204
|
-
index: textureIndex,
|
|
205
|
-
texCoord: 0
|
|
206
|
-
};
|
|
207
|
-
} else if (materialDefinition.occlusionTexture) {
|
|
208
|
-
material.occlusionTexture = {
|
|
209
|
-
index: textureIndex,
|
|
210
|
-
texCoord: 0
|
|
211
|
-
};
|
|
263
|
+
/*
|
|
264
|
+
* Returns Features length based on attribute array in attribute object.
|
|
265
|
+
* @param {Object} attributes
|
|
266
|
+
* @returns {Number} Features length .
|
|
267
|
+
*/
|
|
268
|
+
_getFeaturesLength(attributes) {
|
|
269
|
+
if (!attributes) {
|
|
270
|
+
return 0;
|
|
271
|
+
}
|
|
272
|
+
const firstKey = Object.keys(attributes)[0];
|
|
273
|
+
return firstKey ? attributes[firstKey].length : 0;
|
|
212
274
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
275
|
+
/* Checks that normals buffer is correct
|
|
276
|
+
* @param {TypedArray} normals
|
|
277
|
+
* @returns {boolean} true - normals are correct; false - normals are incorrect
|
|
278
|
+
*/
|
|
279
|
+
_checkNormals(normals) {
|
|
280
|
+
// If all normals === 0, the resulting tileset is all in black colors on Cesium
|
|
281
|
+
return normals.find((value) => value);
|
|
218
282
|
}
|
|
219
|
-
const firstKey = Object.keys(attributes)[0];
|
|
220
|
-
return firstKey ? attributes[firstKey].length : 0;
|
|
221
|
-
}
|
|
222
|
-
_checkNormals(normals) {
|
|
223
|
-
return normals.find(value => value);
|
|
224
|
-
}
|
|
225
283
|
}
|
|
226
|
-
//# sourceMappingURL=b3dm-converter.js.map
|
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import { Vector3 } from '@math.gl/core';
|
|
2
2
|
import { Ellipsoid } from '@math.gl/geospatial';
|
|
3
3
|
import { OrientedBoundingBox } from '@math.gl/culling';
|
|
4
|
+
/**
|
|
5
|
+
* Convert quaternion-based OBB to half-axes-based OBB
|
|
6
|
+
* @param i3SObb quaternion based OBB
|
|
7
|
+
* @param geoidHeightModel the Earth Gravity Model instance
|
|
8
|
+
* @returns number[12] 3DTiles OBB https://github.com/CesiumGS/3d-tiles/tree/master/specification#box
|
|
9
|
+
*/
|
|
4
10
|
export function i3sObbTo3dTilesObb(i3SObb, geoidHeightModel) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
11
|
+
const tiles3DCenter = [
|
|
12
|
+
i3SObb.center[0],
|
|
13
|
+
i3SObb.center[1],
|
|
14
|
+
i3SObb.center[2] + geoidHeightModel.getHeight(i3SObb.center[1], i3SObb.center[0])
|
|
15
|
+
];
|
|
16
|
+
const cartesianCenter = Ellipsoid.WGS84.cartographicToCartesian(tiles3DCenter, new Vector3());
|
|
17
|
+
const tiles3DObb = new OrientedBoundingBox().fromCenterHalfSizeQuaternion(cartesianCenter, i3SObb.halfSize, i3SObb.quaternion);
|
|
18
|
+
return [...tiles3DObb.center, ...tiles3DObb.halfAxes.toArray()];
|
|
9
19
|
}
|
|
10
|
-
//# sourceMappingURL=i3s-obb-to-3d-tiles-obb.js.map
|