@loaders.gl/tile-converter 3.1.1 → 3.1.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/converter.min.js +1 -1
- package/dist/{bundle.js → dist.min.js} +88 -24
- package/dist/es5/i3s-converter/helpers/create-scene-server-path.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/geometry-attributes.js +11 -18
- package/dist/es5/i3s-converter/helpers/geometry-attributes.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/geometry-converter.js +29 -4
- package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/node-debug.js +9 -3
- package/dist/es5/i3s-converter/helpers/node-debug.js.map +1 -1
- package/dist/es5/i3s-converter/i3s-converter.js +12 -10
- package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
- package/dist/es5/pgm-loader.js +1 -1
- package/dist/esm/i3s-converter/helpers/create-scene-server-path.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/geometry-attributes.js +10 -18
- package/dist/esm/i3s-converter/helpers/geometry-attributes.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/geometry-converter.js +31 -4
- package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/node-debug.js +9 -3
- package/dist/esm/i3s-converter/helpers/node-debug.js.map +1 -1
- package/dist/esm/i3s-converter/i3s-converter.js +3 -3
- package/dist/esm/i3s-converter/i3s-converter.js.map +1 -1
- package/dist/esm/pgm-loader.js +1 -1
- package/package.json +15 -15
- package/src/i3s-converter/helpers/create-scene-server-path.ts +9 -5
- package/src/i3s-converter/helpers/geometry-attributes.ts +52 -30
- package/src/i3s-converter/helpers/geometry-converter.js +39 -4
- package/src/i3s-converter/helpers/node-debug.ts +58 -12
- package/src/i3s-converter/i3s-converter.ts +4 -4
- package/src/i3s-converter/types.ts +28 -0
|
@@ -78654,7 +78654,7 @@ var VERSION5 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
|
78654
78654
|
var VERSION6 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
78655
78655
|
|
|
78656
78656
|
// ../textures/src/lib/parsers/basis-module-loader.ts
|
|
78657
|
-
var VERSION7 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "
|
|
78657
|
+
var VERSION7 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
78658
78658
|
var BASIS_CDN_ENCODER_WASM = `https://unpkg.com/@loaders.gl/textures@${VERSION7}/dist/libs/basis_encoder.wasm`;
|
|
78659
78659
|
var BASIS_CDN_ENCODER_JS = `https://unpkg.com/@loaders.gl/textures@${VERSION7}/dist/libs/basis_encoder.js`;
|
|
78660
78660
|
var loadBasisTranscoderPromise;
|
|
@@ -82359,7 +82359,8 @@ async function parseImplicitTiles(subtree, options, parentData = {
|
|
|
82359
82359
|
const currentTile = await parseImplicitTiles(subtree, options, pData, index, childTileLevel, globalData);
|
|
82360
82360
|
if (currentTile.contentUrl || currentTile.children.length) {
|
|
82361
82361
|
const globalLevel = lev + 1;
|
|
82362
|
-
const
|
|
82362
|
+
const childCoordinates = { childTileX, childTileY, childTileZ };
|
|
82363
|
+
const formattedTile = formatTileData(currentTile, globalLevel, childCoordinates, options);
|
|
82363
82364
|
tile.children.push(formattedTile);
|
|
82364
82365
|
}
|
|
82365
82366
|
}
|
|
@@ -82374,10 +82375,19 @@ function getAvailabilityResult(availabilityData, index) {
|
|
|
82374
82375
|
}
|
|
82375
82376
|
return false;
|
|
82376
82377
|
}
|
|
82377
|
-
function formatTileData(tile, level, options) {
|
|
82378
|
-
const {
|
|
82378
|
+
function formatTileData(tile, level, childCoordinates, options) {
|
|
82379
|
+
const {
|
|
82380
|
+
basePath,
|
|
82381
|
+
refine,
|
|
82382
|
+
getRefine: getRefine2,
|
|
82383
|
+
lodMetricType,
|
|
82384
|
+
getTileType: getTileType2,
|
|
82385
|
+
rootLodMetricValue,
|
|
82386
|
+
rootBoundingVolume
|
|
82387
|
+
} = options;
|
|
82379
82388
|
const uri = tile.contentUrl && tile.contentUrl.replace(`${basePath}/`, "");
|
|
82380
82389
|
const lodMetricValue = rootLodMetricValue / 2 ** level;
|
|
82390
|
+
const boundingVolume = calculateBoundingVolumeForChildTile(level, rootBoundingVolume, childCoordinates);
|
|
82381
82391
|
return {
|
|
82382
82392
|
children: tile.children,
|
|
82383
82393
|
contentUrl: tile.contentUrl,
|
|
@@ -82386,9 +82396,31 @@ function formatTileData(tile, level, options) {
|
|
|
82386
82396
|
refine: getRefine2(refine),
|
|
82387
82397
|
type: getTileType2(tile),
|
|
82388
82398
|
lodMetricType,
|
|
82389
|
-
lodMetricValue
|
|
82399
|
+
lodMetricValue,
|
|
82400
|
+
boundingVolume
|
|
82390
82401
|
};
|
|
82391
82402
|
}
|
|
82403
|
+
function calculateBoundingVolumeForChildTile(level, rootBoundingVolume, childCoordinates) {
|
|
82404
|
+
if (rootBoundingVolume.region) {
|
|
82405
|
+
const { childTileX, childTileY, childTileZ } = childCoordinates;
|
|
82406
|
+
const [west, south, east, north, minimumHeight, maximumHeight] = rootBoundingVolume.region;
|
|
82407
|
+
const boundingVolumesCount = 2 ** level;
|
|
82408
|
+
const sizeX = (east - west) / boundingVolumesCount;
|
|
82409
|
+
const sizeY = (north - south) / boundingVolumesCount;
|
|
82410
|
+
const sizeZ = (maximumHeight - minimumHeight) / boundingVolumesCount;
|
|
82411
|
+
const [childWest, childEast] = [west + sizeX * childTileX, west + sizeX * (childTileX + 1)];
|
|
82412
|
+
const [childSouth, childNorth] = [south + sizeY * childTileY, south + sizeY * (childTileY + 1)];
|
|
82413
|
+
const [childMinimumHeight, childMaximumHeight] = [
|
|
82414
|
+
minimumHeight + sizeZ * childTileZ,
|
|
82415
|
+
minimumHeight + sizeZ * (childTileZ + 1)
|
|
82416
|
+
];
|
|
82417
|
+
return {
|
|
82418
|
+
region: [childWest, childSouth, childEast, childNorth, childMinimumHeight, childMaximumHeight]
|
|
82419
|
+
};
|
|
82420
|
+
}
|
|
82421
|
+
console.warn("Unsupported bounding volume type: ", rootBoundingVolume);
|
|
82422
|
+
return null;
|
|
82423
|
+
}
|
|
82392
82424
|
function concatBits(first, second) {
|
|
82393
82425
|
return parseInt(first.toString(2) + second.toString(2), 2);
|
|
82394
82426
|
}
|
|
@@ -82490,6 +82522,7 @@ async function normalizeImplicitTileHeaders(tileset) {
|
|
|
82490
82522
|
const contentUrlTemplate = `${basePath}/${tileset.root.content.uri}`;
|
|
82491
82523
|
const refine = tileset.root.refine;
|
|
82492
82524
|
const rootLodMetricValue = tileset.root.geometricError;
|
|
82525
|
+
const rootBoundingVolume = tileset.root.boundingVolume;
|
|
82493
82526
|
const options = {
|
|
82494
82527
|
contentUrlTemplate,
|
|
82495
82528
|
subtreesUriTemplate,
|
|
@@ -82500,6 +82533,7 @@ async function normalizeImplicitTileHeaders(tileset) {
|
|
|
82500
82533
|
basePath,
|
|
82501
82534
|
lodMetricType: LOD_METRIC_TYPE.GEOMETRIC_ERROR,
|
|
82502
82535
|
rootLodMetricValue,
|
|
82536
|
+
rootBoundingVolume,
|
|
82503
82537
|
getTileType,
|
|
82504
82538
|
getRefine
|
|
82505
82539
|
};
|
|
@@ -83162,11 +83196,11 @@ function generateAttributes(attributes) {
|
|
|
83162
83196
|
colors
|
|
83163
83197
|
};
|
|
83164
83198
|
}
|
|
83165
|
-
const
|
|
83166
|
-
const attributeObjects = makeAttributeObjects({
|
|
83199
|
+
const data = calculateFaceRangesAndFeaturesCount(featureIndices);
|
|
83200
|
+
const attributeObjects = makeAttributeObjects({ ...data, ...attributes });
|
|
83167
83201
|
const unifiedAttributeObjectsByFeatureIds = unifyObjectsByFeatureId(attributeObjects);
|
|
83168
|
-
const groupedAttributes = groupAttributesAndRangesByFeatureId(unifiedAttributeObjectsByFeatureIds);
|
|
83169
|
-
return
|
|
83202
|
+
const groupedAttributes = groupAttributesAndRangesByFeatureId(unifiedAttributeObjectsByFeatureIds, data.featureCount);
|
|
83203
|
+
return groupedAttributes;
|
|
83170
83204
|
}
|
|
83171
83205
|
function calculateFaceRangesAndFeaturesCount(featureIndices) {
|
|
83172
83206
|
let rangeIndex = 1;
|
|
@@ -83196,7 +83230,14 @@ function calculateFaceRangesAndFeaturesCount(featureIndices) {
|
|
|
83196
83230
|
return { faceRange, featureCount, featureIds };
|
|
83197
83231
|
}
|
|
83198
83232
|
function makeAttributeObjects(attributes) {
|
|
83199
|
-
const {
|
|
83233
|
+
const {
|
|
83234
|
+
featureIds,
|
|
83235
|
+
positions,
|
|
83236
|
+
normals,
|
|
83237
|
+
colors,
|
|
83238
|
+
texCoords,
|
|
83239
|
+
faceRange = new Uint32Array(0)
|
|
83240
|
+
} = attributes;
|
|
83200
83241
|
const groupedData = [];
|
|
83201
83242
|
let positionsList = new Float32Array(positions);
|
|
83202
83243
|
let normalsList = new Float32Array(normals);
|
|
@@ -83258,9 +83299,9 @@ function unifyObjectsByFeatureId(sortedData) {
|
|
|
83258
83299
|
}
|
|
83259
83300
|
return uniqueObjects;
|
|
83260
83301
|
}
|
|
83261
|
-
function groupAttributesAndRangesByFeatureId(unifiedObjects) {
|
|
83302
|
+
function groupAttributesAndRangesByFeatureId(unifiedObjects, featureCount) {
|
|
83262
83303
|
const firstAttributeObject = unifiedObjects[0];
|
|
83263
|
-
const featureIds = [firstAttributeObject.featureId];
|
|
83304
|
+
const featureIds = [firstAttributeObject.featureId || 0];
|
|
83264
83305
|
let positions = new Float32Array(firstAttributeObject.positions);
|
|
83265
83306
|
let normals = new Float32Array(firstAttributeObject.normals);
|
|
83266
83307
|
let colors = new Uint8Array(firstAttributeObject.colors);
|
|
@@ -83270,7 +83311,7 @@ function groupAttributesAndRangesByFeatureId(unifiedObjects) {
|
|
|
83270
83311
|
let sum = 0;
|
|
83271
83312
|
for (let index = 1; index < unifiedObjects.length; index++) {
|
|
83272
83313
|
const currentAttributesObject = unifiedObjects[index];
|
|
83273
|
-
featureIds.push(currentAttributesObject.featureId);
|
|
83314
|
+
featureIds.push(currentAttributesObject.featureId || 0);
|
|
83274
83315
|
positions = concatenateTypedArrays(positions, currentAttributesObject.positions);
|
|
83275
83316
|
normals = concatenateTypedArrays(normals, currentAttributesObject.normals);
|
|
83276
83317
|
colors = concatenateTypedArrays(colors, currentAttributesObject.colors);
|
|
@@ -83283,7 +83324,7 @@ function groupAttributesAndRangesByFeatureId(unifiedObjects) {
|
|
|
83283
83324
|
}
|
|
83284
83325
|
range.push(positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE - 1);
|
|
83285
83326
|
const faceRange = new Uint32Array(range);
|
|
83286
|
-
return { faceRange, featureIds, positions, normals, colors, texCoords };
|
|
83327
|
+
return { faceRange, featureIds, positions, normals, colors, texCoords, featureCount };
|
|
83287
83328
|
}
|
|
83288
83329
|
|
|
83289
83330
|
// src/i3s-converter/helpers/coordinate-converter.ts
|
|
@@ -83503,14 +83544,30 @@ function convertNodes(nodes, tileContent, attributesMap, useCartesianPositions,
|
|
|
83503
83544
|
}
|
|
83504
83545
|
}
|
|
83505
83546
|
}
|
|
83547
|
+
function getCompositeTransformationMatrix(node2, matrix) {
|
|
83548
|
+
let transformationMatrix = matrix;
|
|
83549
|
+
const { matrix: nodeMatrix, rotation, scale, translation } = node2;
|
|
83550
|
+
if (nodeMatrix) {
|
|
83551
|
+
transformationMatrix = matrix.multiplyRight(nodeMatrix);
|
|
83552
|
+
}
|
|
83553
|
+
if (rotation) {
|
|
83554
|
+
transformationMatrix = transformationMatrix.rotateXYZ(rotation);
|
|
83555
|
+
}
|
|
83556
|
+
if (scale) {
|
|
83557
|
+
transformationMatrix = transformationMatrix.scale(scale);
|
|
83558
|
+
}
|
|
83559
|
+
if (translation) {
|
|
83560
|
+
transformationMatrix = transformationMatrix.translate(translation);
|
|
83561
|
+
}
|
|
83562
|
+
return transformationMatrix;
|
|
83563
|
+
}
|
|
83506
83564
|
function convertNode(node2, tileContent, attributesMap, useCartesianPositions, matrix = new import_core21.Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])) {
|
|
83507
|
-
const
|
|
83508
|
-
const compositeMatrix = nodeMatrix ? matrix.multiplyRight(nodeMatrix) : matrix;
|
|
83565
|
+
const transformationMatrix = getCompositeTransformationMatrix(node2, matrix);
|
|
83509
83566
|
const mesh = node2.mesh;
|
|
83510
83567
|
if (mesh) {
|
|
83511
|
-
convertMesh(mesh, tileContent, attributesMap, useCartesianPositions,
|
|
83568
|
+
convertMesh(mesh, tileContent, attributesMap, useCartesianPositions, transformationMatrix);
|
|
83512
83569
|
}
|
|
83513
|
-
convertNodes(node2.children, tileContent, attributesMap, useCartesianPositions,
|
|
83570
|
+
convertNodes(node2.children, tileContent, attributesMap, useCartesianPositions, transformationMatrix);
|
|
83514
83571
|
}
|
|
83515
83572
|
function convertMesh(mesh, content, attributesMap, useCartesianPositions = false, matrix = new import_core21.Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])) {
|
|
83516
83573
|
for (const primitive of mesh.primitives) {
|
|
@@ -84506,7 +84563,7 @@ var import_engine = __toModule(require_es514());
|
|
|
84506
84563
|
var import_core23 = __toModule(require_es54());
|
|
84507
84564
|
var import_geospatial9 = __toModule(require_es55());
|
|
84508
84565
|
function validateNodeBoundingVolumes(node2) {
|
|
84509
|
-
if (!node2
|
|
84566
|
+
if (!node2?.parentNode?.obb || !node2?.parentNode?.mbs) {
|
|
84510
84567
|
return [];
|
|
84511
84568
|
}
|
|
84512
84569
|
const tileWarnings = [];
|
|
@@ -84521,7 +84578,7 @@ function validateObb(tileWarnings, node2) {
|
|
|
84521
84578
|
if (isTileObbInsideParentObb) {
|
|
84522
84579
|
return;
|
|
84523
84580
|
}
|
|
84524
|
-
const title = `OBB of Tile (${node2.id}) doesn't fit into Parent (${node2.parentNode
|
|
84581
|
+
const title = `OBB of Tile (${node2.id}) doesn't fit into Parent (${node2.parentNode?.id}) tile OBB`;
|
|
84525
84582
|
tileWarnings.push(title);
|
|
84526
84583
|
}
|
|
84527
84584
|
function validateMbs(tileWarnings, node2) {
|
|
@@ -84529,7 +84586,7 @@ function validateMbs(tileWarnings, node2) {
|
|
|
84529
84586
|
const parentMbs = createBoundingSphereFromTileMbs(node2.parentNode.mbs);
|
|
84530
84587
|
const distanceBetweenCenters = tileMbs.center.distanceTo(parentMbs.center);
|
|
84531
84588
|
if (distanceBetweenCenters + tileMbs.radius > parentMbs.radius) {
|
|
84532
|
-
const title = `MBS of Tile (${node2.id}) doesn't fit into Parent (${node2.parentNode
|
|
84589
|
+
const title = `MBS of Tile (${node2.id}) doesn't fit into Parent (${node2.parentNode?.id}) tile MBS`;
|
|
84533
84590
|
tileWarnings.push(title);
|
|
84534
84591
|
}
|
|
84535
84592
|
}
|
|
@@ -85042,12 +85099,13 @@ var I3SConverter = class {
|
|
|
85042
85099
|
}
|
|
85043
85100
|
}
|
|
85044
85101
|
async writeTextureFile(textureData, name8, format, childPath, slpkChildPath) {
|
|
85045
|
-
const texturePath = (0, import_path7.join)(childPath, `textures/${name8}/`);
|
|
85046
|
-
await writeFile3(texturePath, textureData, `index.${format}`);
|
|
85047
85102
|
if (this.options.slpk) {
|
|
85048
85103
|
const slpkTexturePath = (0, import_path7.join)(childPath, "textures");
|
|
85049
85104
|
const compress = false;
|
|
85050
85105
|
this.fileMap[`${slpkChildPath}/textures/${name8}.${format}`] = await writeFileForSlpk(slpkTexturePath, textureData, `${name8}.${format}`, compress);
|
|
85106
|
+
} else {
|
|
85107
|
+
const texturePath = (0, import_path7.join)(childPath, `textures/${name8}/`);
|
|
85108
|
+
await writeFile3(texturePath, textureData, `index.${format}`);
|
|
85051
85109
|
}
|
|
85052
85110
|
}
|
|
85053
85111
|
async _writeAttributes(attributes, childPath, slpkChildPath) {
|
|
@@ -86011,7 +86069,13 @@ async function normalizeTilesetData(tileset, options, context) {
|
|
|
86011
86069
|
} else {
|
|
86012
86070
|
const rootNodeUrl = getUrlWithToken(`${tileset.url}/nodes/root`, options.i3s?.token);
|
|
86013
86071
|
tileset.root = await load(rootNodeUrl, tileset.loader, {
|
|
86014
|
-
|
|
86072
|
+
...options,
|
|
86073
|
+
i3s: {
|
|
86074
|
+
...options.i3s,
|
|
86075
|
+
loadContent: false,
|
|
86076
|
+
isTileHeader: true,
|
|
86077
|
+
isTileset: false
|
|
86078
|
+
}
|
|
86015
86079
|
});
|
|
86016
86080
|
}
|
|
86017
86081
|
tileset.basePath = tileset.url;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/i3s-converter/helpers/create-scene-server-path.ts"],"names":["createSceneServerPath","layerName","layers0","rootPath","sceneServerData","serviceItemId","replace","sceneServer","nodePagePath","JSON","stringify"],"mappings":";;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"sources":["../../../../src/i3s-converter/helpers/create-scene-server-path.ts"],"names":["createSceneServerPath","layerName","layers0","rootPath","sceneServerData","serviceItemId","replace","sceneServer","nodePagePath","JSON","stringify"],"mappings":";;;;;;;;;;;;;AACA;;AACA;;AACA;;AAEA;;AACA;;SAQsBA,qB;;;;;qFAAf,iBACLC,SADK,EAELC,OAFK,EAGLC,QAHK;AAAA;AAAA;AAAA;AAAA;AAAA;AAKCC,YAAAA,eALD,GAKmB;AACtBC,cAAAA,aAAa,EAAE,gBAASC,OAAT,CAAiB,KAAjB,EAAwB,EAAxB,CADO;AAEtBL,cAAAA,SAAS,EAATA,SAFsB;AAGtBC,cAAAA,OAAO,EAAPA;AAHsB,aALnB;AAWCK,YAAAA,WAXD,GAWe,+BAAUH,eAAV,EAA2B,gCAA3B,CAXf;AAYCI,YAAAA,YAZD,GAYgB,gBAAKL,QAAL,EAAe,aAAf,CAZhB;AAAA;AAAA,mBAaC,0BAAUK,YAAV,EAAwBC,IAAI,CAACC,SAAL,CAAeH,WAAf,CAAxB,CAbD;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,G","sourcesContent":["import type {SceneLayer3D} from '@loaders.gl/i3s';\nimport {v4 as uuidv4} from 'uuid';\nimport transform from 'json-map-transform';\nimport {join} from 'path';\n\nimport {SCENE_SERVER as sceneServerTemplate} from '../json-templates/scene-server';\nimport {writeFile} from '../../lib/utils/file-utils';\n\n/**\n * Form and save sceneServer meta data into a file\n * @param layerName - layer name to display\n * @param layers0 - layer object embedded into sceneServer meta data\n * @param rootPath - root path of new converted tileset\n */\nexport async function createSceneServerPath(\n layerName: string,\n layers0: SceneLayer3D,\n rootPath: string\n): Promise<void> {\n const sceneServerData = {\n serviceItemId: uuidv4().replace(/-/gi, ''),\n layerName,\n layers0\n };\n\n const sceneServer = transform(sceneServerData, sceneServerTemplate());\n const nodePagePath = join(rootPath, 'SceneServer');\n await writeFile(nodePagePath, JSON.stringify(sceneServer));\n}\n"],"file":"create-scene-server-path.js"}
|
|
@@ -38,20 +38,11 @@ function generateAttributes(attributes) {
|
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
var
|
|
42
|
-
|
|
43
|
-
featureCount = _calculateFaceRangesA.featureCount,
|
|
44
|
-
featureIds = _calculateFaceRangesA.featureIds;
|
|
45
|
-
|
|
46
|
-
var attributeObjects = makeAttributeObjects(_objectSpread({
|
|
47
|
-
faceRange: faceRange,
|
|
48
|
-
featureIds: featureIds
|
|
49
|
-
}, attributes));
|
|
41
|
+
var data = calculateFaceRangesAndFeaturesCount(featureIndices);
|
|
42
|
+
var attributeObjects = makeAttributeObjects(_objectSpread(_objectSpread({}, data), attributes));
|
|
50
43
|
var unifiedAttributeObjectsByFeatureIds = unifyObjectsByFeatureId(attributeObjects);
|
|
51
|
-
var groupedAttributes = groupAttributesAndRangesByFeatureId(unifiedAttributeObjectsByFeatureIds);
|
|
52
|
-
return
|
|
53
|
-
featureCount: featureCount
|
|
54
|
-
}, groupedAttributes);
|
|
44
|
+
var groupedAttributes = groupAttributesAndRangesByFeatureId(unifiedAttributeObjectsByFeatureIds, data.featureCount);
|
|
45
|
+
return groupedAttributes;
|
|
55
46
|
}
|
|
56
47
|
|
|
57
48
|
function calculateFaceRangesAndFeaturesCount(featureIndices) {
|
|
@@ -97,7 +88,8 @@ function makeAttributeObjects(attributes) {
|
|
|
97
88
|
normals = attributes.normals,
|
|
98
89
|
colors = attributes.colors,
|
|
99
90
|
texCoords = attributes.texCoords,
|
|
100
|
-
faceRange = attributes.faceRange
|
|
91
|
+
_attributes$faceRange = attributes.faceRange,
|
|
92
|
+
faceRange = _attributes$faceRange === void 0 ? new Uint32Array(0) : _attributes$faceRange;
|
|
101
93
|
var groupedData = [];
|
|
102
94
|
var positionsList = new Float32Array(positions);
|
|
103
95
|
var normalsList = new Float32Array(normals);
|
|
@@ -179,9 +171,9 @@ function unifyObjectsByFeatureId(sortedData) {
|
|
|
179
171
|
return uniqueObjects;
|
|
180
172
|
}
|
|
181
173
|
|
|
182
|
-
function groupAttributesAndRangesByFeatureId(unifiedObjects) {
|
|
174
|
+
function groupAttributesAndRangesByFeatureId(unifiedObjects, featureCount) {
|
|
183
175
|
var firstAttributeObject = unifiedObjects[0];
|
|
184
|
-
var featureIds = [firstAttributeObject.featureId];
|
|
176
|
+
var featureIds = [firstAttributeObject.featureId || 0];
|
|
185
177
|
var positions = new Float32Array(firstAttributeObject.positions);
|
|
186
178
|
var normals = new Float32Array(firstAttributeObject.normals);
|
|
187
179
|
var colors = new Uint8Array(firstAttributeObject.colors);
|
|
@@ -192,7 +184,7 @@ function groupAttributesAndRangesByFeatureId(unifiedObjects) {
|
|
|
192
184
|
|
|
193
185
|
for (var index = 1; index < unifiedObjects.length; index++) {
|
|
194
186
|
var currentAttributesObject = unifiedObjects[index];
|
|
195
|
-
featureIds.push(currentAttributesObject.featureId);
|
|
187
|
+
featureIds.push(currentAttributesObject.featureId || 0);
|
|
196
188
|
positions = (0, _loaderUtils.concatenateTypedArrays)(positions, currentAttributesObject.positions);
|
|
197
189
|
normals = (0, _loaderUtils.concatenateTypedArrays)(normals, currentAttributesObject.normals);
|
|
198
190
|
colors = (0, _loaderUtils.concatenateTypedArrays)(colors, currentAttributesObject.colors);
|
|
@@ -212,7 +204,8 @@ function groupAttributesAndRangesByFeatureId(unifiedObjects) {
|
|
|
212
204
|
positions: positions,
|
|
213
205
|
normals: normals,
|
|
214
206
|
colors: colors,
|
|
215
|
-
texCoords: texCoords
|
|
207
|
+
texCoords: texCoords,
|
|
208
|
+
featureCount: featureCount
|
|
216
209
|
};
|
|
217
210
|
}
|
|
218
211
|
//# sourceMappingURL=geometry-attributes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/i3s-converter/helpers/geometry-attributes.ts"],"names":["VALUES_PER_VERTEX","POSITIONS_AND_NORMALS_PER_TRIANGLE","generateAttributes","attributes","positions","normals","texCoords","colors","featureIndices","triangleCount","length","faceRange","Uint32Array","featureIds","featureCount","calculateFaceRangesAndFeaturesCount","attributeObjects","makeAttributeObjects","unifiedAttributeObjectsByFeatureIds","unifyObjectsByFeatureId","groupedAttributes","groupAttributesAndRangesByFeatureId","rangeIndex","featureIndex","currentFeatureId","faceRangeList","uniqueFeatureIds","index","includes","push","groupedData","positionsList","Float32Array","normalsList","colorsList","Uint8Array","texCoordsList","faceRangeIndex","startIndex","endIndex","positionsCount","getSliceAttributeCount","normalsCount","colorsCount","texCoordsCount","featureId","slice","sort","first","second","attributeName","colorsPerVertex","texCoordsPerVertex","trianglesCount","vertexCount","sortedData","uniqueObjects","currentObject","existedObject","find","obj","unifiedObjects","firstAttributeObject","range","objIndex","sum","currentAttributesObject","groupedObject"],"mappings":";;;;;;;;;;;AAAA;;;;;;AAEA,IAAMA,iBAAiB,GAAG,CAA1B;AACA,IAAMC,kCAAkC,GAAG,CAA3C;;AAOO,SAASC,kBAAT,CAA4BC,UAA5B,EAAwC;AAC7C,MAAOC,SAAP,GAA+ED,UAA/E,CAAOC,SAAP;AAAA,MAAkBC,OAAlB,GAA+EF,UAA/E,CAAkBE,OAAlB;AAAA,MAA2BC,SAA3B,GAA+EH,UAA/E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AA0EgE,GAArF;AACAF,IAAAA,KAAK,CAAClC,IAAN,CAAWsC,aAAa,CAAC/D,SAAd,CAAwBM,MAAxB,GAAiCT,kCAAjC,GAAsEgE,GAAjF;AAEAA,IAAAA,GAAG,IAAIE,aAAa,CAAC/D,SAAd,CAAwBM,MAAxB,GAAiCT,kCAAxC;AACA+D,IAAAA,QAAQ,IAAI,CAAZ;AACD;;AAEDD,EAAAA,KAAK,CAAClC,IAAN,CAAWzB,SAAS,CAACM,MAAV,GAAmBT,kCAAnB,GAAwD,CAAnE;AAEA,MAAMU,SAAS,GAAG,IAAIC,WAAJ,CAAgBmD,KAAhB,CAAlB;AACA,SAAO;AAACpD,IAAAA,SAAS,EAATA,SAAD;AAAYE,IAAAA,UAAU,EAAVA,UAAZ;AAAwBT,IAAAA,SAAS,EAATA,SAAxB;AAAmCC,IAAAA,OAAO,EAAPA,OAAnC;AAA4CE,IAAAA,MAAM,EAANA,MAA5C;AAAoDD,IAAAA,SAAS,EAATA;AAApD,GAAP;AACD","sourcesContent":["import {concatenateTypedArrays} from '@loaders.gl/loader-utils';\n\nconst VALUES_PER_VERTEX = 3;\nconst POSITIONS_AND_NORMALS_PER_TRIANGLE = 9;\n\n/**\n * Generate geometry attributes with faceRange and featureCount\n * @param {Object} attributes\n * @returns {Object} Object with featureCount, reordered attributes and changed faceRange.\n */\nexport function generateAttributes(attributes) {\n const {positions, normals, texCoords, colors, featureIndices, triangleCount} = attributes;\n\n if (!featureIndices.length) {\n return {\n faceRange: new Uint32Array([0, triangleCount - 1]),\n featureIds: [0],\n featureCount: 1,\n positions,\n normals,\n texCoords,\n colors\n };\n }\n\n const {faceRange, featureCount, featureIds} = calculateFaceRangesAndFeaturesCount(featureIndices);\n const attributeObjects = makeAttributeObjects({faceRange, featureIds, ...attributes});\n const unifiedAttributeObjectsByFeatureIds = unifyObjectsByFeatureId(attributeObjects);\n const groupedAttributes = groupAttributesAndRangesByFeatureId(\n unifiedAttributeObjectsByFeatureIds\n );\n return {featureCount, ...groupedAttributes};\n}\n\n/**\n * Calculates face Ranges and feature count based on featureIndices.\n * @param {Object} featureIndices\n * @returns {Object} Object with featureCount, reordered attributes and changed faceRange.\n */\nfunction calculateFaceRangesAndFeaturesCount(featureIndices) {\n let rangeIndex = 1;\n let featureIndex = 1;\n let currentFeatureId = featureIndices[0];\n const faceRangeList: any[] = [];\n const featureIds: any[] = [];\n const uniqueFeatureIds = [currentFeatureId];\n\n faceRangeList[0] = 0;\n featureIds[0] = currentFeatureId;\n\n for (let index = 1; index < featureIndices.length; index++) {\n if (currentFeatureId !== featureIndices[index]) {\n faceRangeList[rangeIndex] = index / VALUES_PER_VERTEX - 1;\n faceRangeList[rangeIndex + 1] = index / VALUES_PER_VERTEX;\n featureIds[featureIndex] = featureIndices[index];\n\n if (!uniqueFeatureIds.includes(featureIndices[index])) {\n uniqueFeatureIds.push(featureIndices[index]);\n }\n\n rangeIndex += 2;\n featureIndex += 1;\n }\n currentFeatureId = featureIndices[index];\n }\n\n faceRangeList[rangeIndex] = featureIndices.length / VALUES_PER_VERTEX - 1;\n\n const faceRange = new Uint32Array(faceRangeList);\n const featureCount = uniqueFeatureIds.length;\n\n return {faceRange, featureCount, featureIds};\n}\n\n/**\n * Generate list of attribute object grouped by feature ids.\n * @param {Object} attributes\n * @returns {Array} sorted list of attribute objects.\n */\nfunction makeAttributeObjects(attributes) {\n const {featureIds, positions, normals, colors, texCoords, faceRange} = attributes;\n const groupedData: any[] = [];\n\n let positionsList = new Float32Array(positions);\n let normalsList = new Float32Array(normals);\n let colorsList = new Uint8Array(colors);\n let texCoordsList = new Float32Array(texCoords);\n\n let faceRangeIndex = 0;\n\n for (let index = 0; index < featureIds.length; index++) {\n const startIndex = faceRange[index + faceRangeIndex];\n const endIndex = faceRange[index + faceRangeIndex + 1];\n\n const positionsCount = getSliceAttributeCount('positions', startIndex, endIndex);\n const normalsCount = getSliceAttributeCount('normals', startIndex, endIndex);\n const colorsCount = getSliceAttributeCount('colors', startIndex, endIndex);\n const texCoordsCount = getSliceAttributeCount('texCoords', startIndex, endIndex);\n\n groupedData.push({\n featureId: featureIds[index],\n positions: positionsList.slice(0, positionsCount),\n normals: normalsList.slice(0, normalsCount),\n colors: colorsList.slice(0, colorsCount),\n texCoords: texCoordsList.slice(0, texCoordsCount)\n });\n\n positionsList = positionsList.slice(positionsCount);\n normalsList = normalsList.slice(normalsCount);\n colorsList = colorsList.slice(colorsCount);\n texCoordsList = texCoordsList.slice(texCoordsCount);\n\n faceRangeIndex += 1;\n }\n\n return groupedData.sort((first, second) => first.featureId - second.featureId);\n}\n\n/**\n * Generate sliced count for generating attribute objects depends on attribute name and range.\n * @param {String} attributeName\n * @param {Number} startIndex\n * @param {Number} endIndex\n * @returns {Number} - sliced count\n */\nfunction getSliceAttributeCount(attributeName, startIndex, endIndex) {\n const colorsPerVertex = 4;\n const texCoordsPerVertex = 2;\n\n const trianglesCount = endIndex - startIndex + 1;\n const vertexCount = trianglesCount * 3;\n\n switch (attributeName) {\n case 'positions':\n case 'normals':\n return trianglesCount * POSITIONS_AND_NORMALS_PER_TRIANGLE;\n case 'colors':\n return vertexCount * colorsPerVertex;\n case 'texCoords':\n return vertexCount * texCoordsPerVertex;\n default:\n return 0;\n }\n}\n\n/**\n * Generates unique object list depends on feature ids and concantenate their attributes.\n * @param {Array} sortedData\n * @returns {Array} - unique list of objects\n */\nfunction unifyObjectsByFeatureId(sortedData) {\n const uniqueObjects: any[] = [];\n\n for (let index = 0; index < sortedData.length; index++) {\n const currentObject = sortedData[index];\n const existedObject = uniqueObjects.find((obj) => obj.featureId === currentObject.featureId);\n\n if (existedObject) {\n existedObject.positions = concatenateTypedArrays(\n existedObject.positions,\n currentObject.positions\n );\n existedObject.normals = concatenateTypedArrays(existedObject.normals, currentObject.normals);\n existedObject.colors = concatenateTypedArrays(existedObject.colors, currentObject.colors);\n existedObject.texCoords = concatenateTypedArrays(\n existedObject.texCoords,\n currentObject.texCoords\n );\n } else {\n uniqueObjects.push(currentObject);\n }\n }\n\n return uniqueObjects;\n}\n\n/**\n * Generates attribute objects with new faceRange and reordered attributes.\n * @param {Array} unifiedObjects\n * @returns {Object} - ugenerated attributes with new faceRange.\n */\nfunction groupAttributesAndRangesByFeatureId(unifiedObjects) {\n const firstAttributeObject = unifiedObjects[0];\n const featureIds = [firstAttributeObject.featureId];\n\n let positions = new Float32Array(firstAttributeObject.positions);\n let normals = new Float32Array(firstAttributeObject.normals);\n let colors = new Uint8Array(firstAttributeObject.colors);\n let texCoords = new Float32Array(firstAttributeObject.texCoords);\n const range = [0];\n\n let objIndex = 0;\n let sum = 0;\n\n for (let index = 1; index < unifiedObjects.length; index++) {\n const currentAttributesObject = unifiedObjects[index];\n featureIds.push(currentAttributesObject.featureId);\n\n positions = concatenateTypedArrays(positions, currentAttributesObject.positions);\n normals = concatenateTypedArrays(normals, currentAttributesObject.normals);\n colors = concatenateTypedArrays(colors, currentAttributesObject.colors);\n texCoords = concatenateTypedArrays(texCoords, currentAttributesObject.texCoords);\n\n const groupedObject = unifiedObjects[objIndex];\n range.push(groupedObject.positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE - 1 + sum);\n range.push(groupedObject.positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE + sum);\n\n sum += groupedObject.positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE;\n objIndex += 1;\n }\n\n range.push(positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE - 1);\n\n const faceRange = new Uint32Array(range);\n return {faceRange, featureIds, positions, normals, colors, texCoords};\n}\n"],"file":"geometry-attributes.js"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/i3s-converter/helpers/geometry-attributes.ts"],"names":["VALUES_PER_VERTEX","POSITIONS_AND_NORMALS_PER_TRIANGLE","generateAttributes","attributes","positions","normals","texCoords","colors","featureIndices","triangleCount","length","faceRange","Uint32Array","featureIds","featureCount","data","calculateFaceRangesAndFeaturesCount","attributeObjects","makeAttributeObjects","unifiedAttributeObjectsByFeatureIds","unifyObjectsByFeatureId","groupedAttributes","groupAttributesAndRangesByFeatureId","rangeIndex","featureIndex","currentFeatureId","faceRangeList","uniqueFeatureIds","index","includes","push","groupedData","positionsList","Float32Array","normalsList","colorsList","Uint8Array","texCoordsList","faceRangeIndex","startIndex","endIndex","positionsCount","getSliceAttributeCount","normalsCount","colorsCount","texCoordsCount","featureId","slice","sort","first","second","attributeName","colorsPerVertex","texCoordsPerVertex","trianglesCount","vertexCount","sortedData","uniqueObjects","currentObject","existedObject","find","obj","unifiedObjects","firstAttributeObject","range","objIndex","sum","currentAttributesObject","groupedObject"],"mappings":";;;;;;;;;;;AACA;;;;;;AAEA,IAAMA,iBAAiB,GAAG,CAA1B;AACA,IAAMC,kCAAkC,GAAG,CAA3C;;AAOO,SAASC,kBAAT,CAA4BC,UAA5B,EAA4E;AACjF,MAAOC,SAAP,GAA+ED,UAA/E,CAAOC,SAAP;AAAA,MAAkBC,OAAlB,GAA+EF,UAA/E,CAAkBE,OAAlB;AAAA,MAA2BC,SAA3B,GAA+EH,UAA/E,CAA2BG,SAA3B;AAAA,MAAsCC,MAAtC,GAA+EJ,UAA/E,CAAsCI,MAAtC;AAAA,MAA8CC,cAA9C,GAA+EL,UAA/E,CAA8CK,cAA9C;AAAA,MAA8DC,aAA9D,GAA+EN,UAA/E,CAA8DM,aAA9D;;AAEA,MAAI,CAACD,cAAc,CAACE,MAApB,EAA4B;AAC1B,WAAO;AACLC,MAAAA,SAAS,EAAE,IAAIC,WAAJ,CAAgB,CAAC,CAAD,EAAIH,aAAa,GAAG,CAApB,CAAhB,CADN;AAELI,MAAAA,UAAU,EAAE,CAAC,CAAD,CAFP;AAGLC,MAAAA,YAAY,EAAE,CAHT;AAILV,MAAAA,SAAS,EAATA,SAJK;AAKLC,MAAAA,OAAO,EAAPA,OALK;AAMLC,MAAAA,SAAS,EAATA,SANK;AAOLC,MAAAA,MAAM,EAANA;AAPK,KAAP;AASD;;AAED,MAAMQ,IAAI,GAAGC,mCAAmC,CAACR,cA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ypedArrays} from '@loaders.gl/loader-utils';\n\nconst VALUES_PER_VERTEX = 3;\nconst POSITIONS_AND_NORMALS_PER_TRIANGLE = 9;\n\n/**\n * Generate geometry attributes with faceRange and featureCount\n * @param attributes\n * @returns attirbutes with featureCount, featureIds and changed faceRange.\n */\nexport function generateAttributes(attributes: AttributesData): GeometryAttributes {\n const {positions, normals, texCoords, colors, featureIndices, triangleCount} = attributes;\n\n if (!featureIndices.length) {\n return {\n faceRange: new Uint32Array([0, triangleCount - 1]),\n featureIds: [0],\n featureCount: 1,\n positions,\n normals,\n texCoords,\n colors\n };\n }\n\n const data = calculateFaceRangesAndFeaturesCount(featureIndices);\n const attributeObjects = makeAttributeObjects({...data, ...attributes});\n const unifiedAttributeObjectsByFeatureIds = unifyObjectsByFeatureId(attributeObjects);\n const groupedAttributes = groupAttributesAndRangesByFeatureId(\n unifiedAttributeObjectsByFeatureIds,\n data.featureCount\n );\n return groupedAttributes;\n}\n\n/**\n * Calculates face Ranges and feature count based on featureIndices.\n * @param featureIndices\n * @returns Object with featureCount, reordered attributes and changed faceRange.\n */\nfunction calculateFaceRangesAndFeaturesCount(featureIndices: number[]): {\n faceRange: Uint32Array;\n featureCount: number;\n featureIds: number[];\n} {\n let rangeIndex = 1;\n let featureIndex = 1;\n let currentFeatureId = featureIndices[0];\n const faceRangeList: any[] = [];\n const featureIds: any[] = [];\n const uniqueFeatureIds = [currentFeatureId];\n\n faceRangeList[0] = 0;\n featureIds[0] = currentFeatureId;\n\n for (let index = 1; index < featureIndices.length; index++) {\n if (currentFeatureId !== featureIndices[index]) {\n faceRangeList[rangeIndex] = index / VALUES_PER_VERTEX - 1;\n faceRangeList[rangeIndex + 1] = index / VALUES_PER_VERTEX;\n featureIds[featureIndex] = featureIndices[index];\n\n if (!uniqueFeatureIds.includes(featureIndices[index])) {\n uniqueFeatureIds.push(featureIndices[index]);\n }\n\n rangeIndex += 2;\n featureIndex += 1;\n }\n currentFeatureId = featureIndices[index];\n }\n\n faceRangeList[rangeIndex] = featureIndices.length / VALUES_PER_VERTEX - 1;\n\n const faceRange = new Uint32Array(faceRangeList);\n const featureCount = uniqueFeatureIds.length;\n\n return {faceRange, featureCount, featureIds};\n}\n\n/**\n * Generate list of attribute object grouped by feature ids.\n * @param attributes\n * @returns sorted list of attribute objects.\n */\nfunction makeAttributeObjects(attributes: GeometryAttributes): GroupedByFeatureIdAttributes[] {\n const {\n featureIds,\n positions,\n normals,\n colors,\n texCoords,\n faceRange = new Uint32Array(0)\n } = attributes;\n const groupedData: GroupedByFeatureIdAttributes[] = [];\n\n let positionsList = new Float32Array(positions);\n let normalsList = new Float32Array(normals);\n let colorsList = new Uint8Array(colors);\n let texCoordsList = new Float32Array(texCoords);\n\n let faceRangeIndex = 0;\n\n for (let index = 0; index < featureIds.length; index++) {\n const startIndex = faceRange[index + faceRangeIndex];\n const endIndex = faceRange[index + faceRangeIndex + 1];\n\n const positionsCount = getSliceAttributeCount('positions', startIndex, endIndex);\n const normalsCount = getSliceAttributeCount('normals', startIndex, endIndex);\n const colorsCount = getSliceAttributeCount('colors', startIndex, endIndex);\n const texCoordsCount = getSliceAttributeCount('texCoords', startIndex, endIndex);\n\n groupedData.push({\n featureId: featureIds[index],\n positions: positionsList.slice(0, positionsCount),\n normals: normalsList.slice(0, normalsCount),\n colors: colorsList.slice(0, colorsCount),\n texCoords: texCoordsList.slice(0, texCoordsCount)\n });\n\n positionsList = positionsList.slice(positionsCount);\n normalsList = normalsList.slice(normalsCount);\n colorsList = colorsList.slice(colorsCount);\n texCoordsList = texCoordsList.slice(texCoordsCount);\n\n faceRangeIndex += 1;\n }\n\n return groupedData.sort((first, second) => first.featureId - second.featureId);\n}\n\n/**\n * Generate sliced count for generating attribute objects depends on attribute name and range.\n * @param attributeName\n * @param startIndex\n * @param endIndex\n * @returns sliced count\n */\nfunction getSliceAttributeCount(\n attributeName: string,\n startIndex: number,\n endIndex: number\n): number {\n const colorsPerVertex = 4;\n const texCoordsPerVertex = 2;\n\n const trianglesCount = endIndex - startIndex + 1;\n const vertexCount = trianglesCount * 3;\n\n switch (attributeName) {\n case 'positions':\n case 'normals':\n return trianglesCount * POSITIONS_AND_NORMALS_PER_TRIANGLE;\n case 'colors':\n return vertexCount * colorsPerVertex;\n case 'texCoords':\n return vertexCount * texCoordsPerVertex;\n default:\n return 0;\n }\n}\n\n/**\n * Generates unique object list depends on feature ids and concantenate their attributes.\n * @param sortedData\n * @returns unique list of objects\n */\nfunction unifyObjectsByFeatureId(\n sortedData: GroupedByFeatureIdAttributes[]\n): GroupedByFeatureIdAttributes[] {\n const uniqueObjects: GroupedByFeatureIdAttributes[] = [];\n\n for (let index = 0; index < sortedData.length; index++) {\n const currentObject = sortedData[index];\n const existedObject = uniqueObjects.find((obj) => obj.featureId === currentObject.featureId);\n\n if (existedObject) {\n existedObject.positions = concatenateTypedArrays(\n existedObject.positions,\n currentObject.positions\n );\n existedObject.normals = concatenateTypedArrays(existedObject.normals, currentObject.normals);\n existedObject.colors = concatenateTypedArrays(existedObject.colors, currentObject.colors);\n existedObject.texCoords = concatenateTypedArrays(\n existedObject.texCoords,\n currentObject.texCoords\n );\n } else {\n uniqueObjects.push(currentObject);\n }\n }\n\n return uniqueObjects;\n}\n\n/**\n * Generates attribute objects with new faceRange and reordered attributes.\n * @param unifiedObjects\n * @returns generated attributes with new faceRange.\n */\nfunction groupAttributesAndRangesByFeatureId(\n unifiedObjects: GroupedByFeatureIdAttributes[],\n featureCount: number\n): GeometryAttributes {\n const firstAttributeObject = unifiedObjects[0];\n const featureIds = [firstAttributeObject.featureId || 0];\n\n let positions = new Float32Array(firstAttributeObject.positions);\n let normals = new Float32Array(firstAttributeObject.normals);\n let colors = new Uint8Array(firstAttributeObject.colors);\n let texCoords = new Float32Array(firstAttributeObject.texCoords);\n const range = [0];\n\n let objIndex = 0;\n let sum = 0;\n\n for (let index = 1; index < unifiedObjects.length; index++) {\n const currentAttributesObject = unifiedObjects[index];\n featureIds.push(currentAttributesObject.featureId || 0);\n\n positions = concatenateTypedArrays(positions, currentAttributesObject.positions);\n normals = concatenateTypedArrays(normals, currentAttributesObject.normals);\n colors = concatenateTypedArrays(colors, currentAttributesObject.colors);\n texCoords = concatenateTypedArrays(texCoords, currentAttributesObject.texCoords);\n\n const groupedObject = unifiedObjects[objIndex];\n range.push(groupedObject.positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE - 1 + sum);\n range.push(groupedObject.positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE + sum);\n\n sum += groupedObject.positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE;\n objIndex += 1;\n }\n\n range.push(positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE - 1);\n\n const faceRange = new Uint32Array(range);\n return {faceRange, featureIds, positions, normals, colors, texCoords, featureCount};\n}\n"],"file":"geometry-attributes.js"}
|
|
@@ -333,17 +333,42 @@ function convertNodes(nodes, tileContent, attributesMap, useCartesianPositions)
|
|
|
333
333
|
}
|
|
334
334
|
}
|
|
335
335
|
|
|
336
|
+
function getCompositeTransformationMatrix(node, matrix) {
|
|
337
|
+
var transformationMatrix = matrix;
|
|
338
|
+
var nodeMatrix = node.matrix,
|
|
339
|
+
rotation = node.rotation,
|
|
340
|
+
scale = node.scale,
|
|
341
|
+
translation = node.translation;
|
|
342
|
+
|
|
343
|
+
if (nodeMatrix) {
|
|
344
|
+
transformationMatrix = matrix.multiplyRight(nodeMatrix);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
if (rotation) {
|
|
348
|
+
transformationMatrix = transformationMatrix.rotateXYZ(rotation);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
if (scale) {
|
|
352
|
+
transformationMatrix = transformationMatrix.scale(scale);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
if (translation) {
|
|
356
|
+
transformationMatrix = transformationMatrix.translate(translation);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
return transformationMatrix;
|
|
360
|
+
}
|
|
361
|
+
|
|
336
362
|
function convertNode(node, tileContent, attributesMap, useCartesianPositions) {
|
|
337
363
|
var matrix = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : new _core.Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
|
|
338
|
-
var
|
|
339
|
-
var compositeMatrix = nodeMatrix ? matrix.multiplyRight(nodeMatrix) : matrix;
|
|
364
|
+
var transformationMatrix = getCompositeTransformationMatrix(node, matrix);
|
|
340
365
|
var mesh = node.mesh;
|
|
341
366
|
|
|
342
367
|
if (mesh) {
|
|
343
|
-
convertMesh(mesh, tileContent, attributesMap, useCartesianPositions,
|
|
368
|
+
convertMesh(mesh, tileContent, attributesMap, useCartesianPositions, transformationMatrix);
|
|
344
369
|
}
|
|
345
370
|
|
|
346
|
-
convertNodes(node.children, tileContent, attributesMap, useCartesianPositions,
|
|
371
|
+
convertNodes(node.children, tileContent, attributesMap, useCartesianPositions, transformationMatrix);
|
|
347
372
|
}
|
|
348
373
|
|
|
349
374
|
function convertMesh(mesh, content, attributesMap) {
|