@@ -17673,7 +17673,7 @@ function parseLASIntoXKTModel({
17673
17673
transform = null,
17674
17674
colorDepth = "auto",
17675
17675
fp64 = false,
17676
- skip = 10 ,
17676
+ skip = 1 ,
17677
17677
stats,
17678
17678
log = () => {
17679
17679
}
@@ -17708,8 +17708,7 @@ function parseLASIntoXKTModel({
17708
17708
parse$2(data, LASLoader, {
17709
17709
las: {
17710
17710
colorDepth,
17711
- fp64,
17712
- skip
17711
+ fp64
17713
17712
}
17714
17713
}).then((parsedData) => {
17715
17714
@@ -17723,46 +17722,43 @@ function parseLASIntoXKTModel({
17723
17722
return;
17724
17723
}
17725
17724
17726
- let positionsValue;
17727
- let colorsCompressed;
17725
+ let readAttributes = {};
17728
17726
17729
17727
switch (pointsFormatId) {
17730
17728
case 0:
17731
17729
if (!attributes.intensity) {
17732
17730
log("No intensities found in file (expected for LAS point format 0)");
17733
17731
return;
17734
17732
}
17735
- positionsValue = readPositions(attributes.POSITION);
17736
- colorsCompressed = readIntensities(attributes.intensity);
17733
+
17734
+ readAttributes = readIntensities(attributes.POSITION, attributes.intensity);
17737
17735
break;
17738
17736
case 1:
17739
17737
if (!attributes.intensity) {
17740
17738
log("No intensities found in file (expected for LAS point format 1)");
17741
17739
return;
17742
17740
}
17743
- positionsValue = readPositions(attributes.POSITION);
17744
- colorsCompressed = readIntensities(attributes.intensity);
17741
+ readAttributes = readIntensities(attributes.POSITION, attributes.intensity);
17745
17742
break;
17746
17743
case 2:
17747
17744
if (!attributes.intensity) {
17748
17745
log("No intensities found in file (expected for LAS point format 2)");
17749
17746
return;
17750
17747
}
17751
- positionsValue = readPositions(attributes.POSITION);
17752
- colorsCompressed = readColorsAndIntensities(attributes.COLOR_0, attributes.intensity);
17748
+
17749
+ readAttributes = readColorsAndIntensities(attributes.POSITION, attributes.COLOR_0, attributes.intensity);
17753
17750
break;
17754
17751
case 3:
17755
17752
if (!attributes.intensity) {
17756
17753
log("No intensities found in file (expected for LAS point format 3)");
17757
17754
return;
17758
17755
}
17759
- positionsValue = readPositions(attributes.POSITION);
17760
- colorsCompressed = readColorsAndIntensities(attributes.COLOR_0, attributes.intensity);
17756
+ readAttributes = readColorsAndIntensities(attributes.POSITION, attributes.COLOR_0, attributes.intensity);
17761
17757
break;
17762
17758
}
17763
17759
17764
- const pointsChunks = chunkArray(positionsValue , MAX_VERTICES * 3);
17765
- const colorsChunks = chunkArray(colorsCompressed , MAX_VERTICES * 4);
17760
+ const pointsChunks = chunkArray(readPositions(readAttributes.positions) , MAX_VERTICES * 3);
17761
+ const colorsChunks = chunkArray(readAttributes.colors , MAX_VERTICES * 4);
17766
17762
17767
17763
const meshIds = [];
17768
17764
@@ -17818,7 +17814,7 @@ function parseLASIntoXKTModel({
17818
17814
stats.numPropertySets = 0;
17819
17815
stats.numObjects = 1;
17820
17816
stats.numGeometries = 1;
17821
- stats.numVertices = positionsValue .length / 3;
17817
+ stats.numVertices = readAttributes.positions .length / 3;
17822
17818
}
17823
17819
17824
17820
resolve();
@@ -17828,11 +17824,9 @@ function parseLASIntoXKTModel({
17828
17824
});
17829
17825
});
17830
17826
17831
- function readPositions(attributesPosition) {
17832
- const positionsValue = attributesPosition.value;
17827
+ function readPositions(positionsValue) {
17833
17828
if (positionsValue) {
17834
17829
if (center) {
17835
-
17836
17830
const centerPos = math.vec3();
17837
17831
const numPoints = positionsValue.length;
17838
17832
for (let i = 0, len = positionsValue.length; i < len; i += 3) {
@@ -17866,32 +17860,60 @@ function parseLASIntoXKTModel({
17866
17860
return positionsValue;
17867
17861
}
17868
17862
17869
- function readColorsAndIntensities(attributesColor, attributesIntensity) {
17863
+ function readColorsAndIntensities(attributesPosition, attributesColor, attributesIntensity) {
17864
+ const positionsValue = attributesPosition.value;
17870
17865
const colors = attributesColor.value;
17871
17866
const colorSize = attributesColor.size;
17872
17867
const intensities = attributesIntensity.value;
17873
17868
const colorsCompressedSize = intensities.length * 4;
17874
- const colorsCompressed = new Uint8Array(colorsCompressedSize);
17875
- for (let i = 0, j = 0, k = 0, len = intensities.length; i < len; i++, k += colorSize, j += 4) {
17876
- colorsCompressed[j + 0] = colors[k + 0];
17877
- colorsCompressed[j + 1] = colors[k + 1];
17878
- colorsCompressed[j + 2] = colors[k + 2];
17879
- colorsCompressed[j + 3] = Math.round((intensities[i] / 65536) * 255);
17869
+ const positions = [];
17870
+ const colorsCompressed = new Uint8Array(colorsCompressedSize / skip);
17871
+ let count = skip;
17872
+ for (let i = 0, j = 0, k = 0, l = 0, m = 0, n=0,len = intensities.length; i < len; i++, k += colorSize, j += 4, l += 3) {
17873
+ if (count <= 0) {
17874
+ colorsCompressed[m++] = colors[k + 0];
17875
+ colorsCompressed[m++] = colors[k + 1];
17876
+ colorsCompressed[m++] = colors[k + 2];
17877
+ colorsCompressed[m++] = Math.round((intensities[i] / 65536) * 255);
17878
+ positions[n++] = positionsValue[l + 0];
17879
+ positions[n++] = positionsValue[l + 1];
17880
+ positions[n++] = positionsValue[l + 2];
17881
+ count = skip;
17882
+ } else {
17883
+ count--;
17884
+ }
17880
17885
}
17881
- return colorsCompressed;
17886
+ return {
17887
+ positions,
17888
+ colors: colorsCompressed
17889
+ };
17882
17890
}
17883
17891
17884
- function readIntensities(attributesIntensity) {
17892
+ function readIntensities(attributesPosition, attributesIntensity) {
17893
+ const positionsValue = attributesPosition.value;
17885
17894
const intensities = attributesIntensity.intensity;
17886
17895
const colorsCompressedSize = intensities.length * 4;
17887
- const colorsCompressed = new Uint8Array(colorsCompressedSize);
17888
- for (let i = 0, j = 0, k = 0, len = intensities.length; i < len; i++, k += 3, j += 4) {
17889
- colorsCompressed[j + 0] = 0;
17890
- colorsCompressed[j + 1] = 0;
17891
- colorsCompressed[j + 2] = 0;
17892
- colorsCompressed[j + 3] = Math.round((intensities[i] / 65536) * 255);
17896
+ const positions = [];
17897
+ const colorsCompressed = new Uint8Array(colorsCompressedSize / skip);
17898
+ let count = skip;
17899
+ for (let i = 0, j = 0, k = 0, l = 0, m = 0, n = 0, len = intensities.length; i < len; i++, k += 3, j += 4, l += 3) {
17900
+ if (count <= 0) {
17901
+ colorsCompressed[m++] = 0;
17902
+ colorsCompressed[m++] = 0;
17903
+ colorsCompressed[m++] = 0;
17904
+ colorsCompressed[m++] = Math.round((intensities[i] / 65536) * 255);
17905
+ positions[n++] = positionsValue[l + 0];
17906
+ positions[n++] = positionsValue[l + 1];
17907
+ positions[n++] = positionsValue[l + 2];
17908
+ count = skip;
17909
+ } else {
17910
+ count--;
17911
+ }
17893
17912
}
17894
- return colorsCompressed;
17913
+ return {
17914
+ positions,
17915
+ colors: colorsCompressed
17916
+ };
17895
17917
}
17896
17918
17897
17919
function chunkArray(array, chunkSize) {
@@ -26149,13 +26171,15 @@ const NUM_MATERIAL_ATTRIBUTES = 6;
26149
26171
* Writes an {@link XKTModel} to an {@link ArrayBuffer}.
26150
26172
*
26151
26173
* @param {XKTModel} xktModel The {@link XKTModel}.
26152
- * @param {String} metaModelJSON The metamodel JSON in an string.
26174
+ * @param {String} metaModelJSON The metamodel JSON in a string.
26153
26175
* @param {Object} [stats] Collects statistics.
26176
+ * @param {Object} options Options for how the XKT is written.
26177
+ * @param {Boolean} [options.zip=true] ZIP the contents?
26154
26178
* @returns {ArrayBuffer} The {@link ArrayBuffer}.
26155
26179
*/
26156
- function writeXKTModelToArrayBuffer(xktModel, metaModelJSON, stats = {} ) {
26180
+ function writeXKTModelToArrayBuffer(xktModel, metaModelJSON, stats, options ) {
26157
26181
const data = getModelData(xktModel, metaModelJSON, stats);
26158
- const deflatedData = deflateData(data, metaModelJSON);
26182
+ const deflatedData = deflateData(data, metaModelJSON, options );
26159
26183
stats.texturesSize += deflatedData.textureData.byteLength;
26160
26184
const arrayBuffer = createArrayBuffer(deflatedData);
26161
26185
return arrayBuffer;
@@ -26483,47 +26507,53 @@ function getModelData(xktModel, metaModelDataStr, stats) {
26483
26507
return data;
26484
26508
}
26485
26509
26486
- function deflateData(data, metaModelJSON) {
26510
+ function deflateData(data, metaModelJSON, options) {
26511
+
26512
+ function deflate(buffer) {
26513
+ return (options.zip !== false) ? deflate_1(buffer) : buffer;
26514
+ }
26515
+
26487
26516
let metaModelBytes;
26488
26517
if (metaModelJSON) {
26489
26518
const deflatedJSON = deflateJSON(metaModelJSON);
26490
- metaModelBytes = deflate_1 (deflatedJSON);
26519
+ metaModelBytes = deflate (deflatedJSON);
26491
26520
} else {
26492
26521
const deflatedJSON = deflateJSON(data.metadata);
26493
- metaModelBytes = deflate_1 (deflatedJSON);
26522
+ metaModelBytes = deflate (deflatedJSON);
26494
26523
}
26524
+
26495
26525
return {
26496
26526
metadata: metaModelBytes,
26497
- textureData: deflate_1 (data.textureData.buffer),
26498
- eachTextureDataPortion: deflate_1 (data.eachTextureDataPortion.buffer),
26499
- eachTextureAttributes: deflate_1 (data.eachTextureAttributes.buffer),
26500
- positions: deflate_1 (data.positions.buffer),
26501
- normals: deflate_1 (data.normals.buffer),
26502
- colors: deflate_1 (data.colors.buffer),
26503
- uvs: deflate_1 (data.uvs.buffer),
26504
- indices: deflate_1 (data.indices.buffer),
26505
- edgeIndices: deflate_1 (data.edgeIndices.buffer),
26506
- eachTextureSetTextures: deflate_1 (data.eachTextureSetTextures.buffer),
26507
- matrices: deflate_1 (data.matrices.buffer),
26508
- reusedGeometriesDecodeMatrix: deflate_1 (data.reusedGeometriesDecodeMatrix.buffer),
26509
- eachGeometryPrimitiveType: deflate_1 (data.eachGeometryPrimitiveType.buffer),
26510
- eachGeometryPositionsPortion: deflate_1 (data.eachGeometryPositionsPortion.buffer),
26511
- eachGeometryNormalsPortion: deflate_1 (data.eachGeometryNormalsPortion.buffer),
26512
- eachGeometryColorsPortion: deflate_1 (data.eachGeometryColorsPortion.buffer),
26513
- eachGeometryUVsPortion: deflate_1 (data.eachGeometryUVsPortion.buffer),
26514
- eachGeometryIndicesPortion: deflate_1 (data.eachGeometryIndicesPortion.buffer),
26515
- eachGeometryEdgeIndicesPortion: deflate_1 (data.eachGeometryEdgeIndicesPortion.buffer),
26516
- eachMeshGeometriesPortion: deflate_1 (data.eachMeshGeometriesPortion.buffer),
26517
- eachMeshMatricesPortion: deflate_1 (data.eachMeshMatricesPortion.buffer),
26518
- eachMeshTextureSet: deflate_1 (data.eachMeshTextureSet.buffer),
26519
- eachMeshMaterialAttributes: deflate_1 (data.eachMeshMaterialAttributes.buffer),
26520
- eachEntityId: deflate_1 (JSON.stringify(data.eachEntityId)
26527
+ textureData: deflate (data.textureData.buffer),
26528
+ eachTextureDataPortion: deflate (data.eachTextureDataPortion.buffer),
26529
+ eachTextureAttributes: deflate (data.eachTextureAttributes.buffer),
26530
+ positions: deflate (data.positions.buffer),
26531
+ normals: deflate (data.normals.buffer),
26532
+ colors: deflate (data.colors.buffer),
26533
+ uvs: deflate (data.uvs.buffer),
26534
+ indices: deflate (data.indices.buffer),
26535
+ edgeIndices: deflate (data.edgeIndices.buffer),
26536
+ eachTextureSetTextures: deflate (data.eachTextureSetTextures.buffer),
26537
+ matrices: deflate (data.matrices.buffer),
26538
+ reusedGeometriesDecodeMatrix: deflate (data.reusedGeometriesDecodeMatrix.buffer),
26539
+ eachGeometryPrimitiveType: deflate (data.eachGeometryPrimitiveType.buffer),
26540
+ eachGeometryPositionsPortion: deflate (data.eachGeometryPositionsPortion.buffer),
26541
+ eachGeometryNormalsPortion: deflate (data.eachGeometryNormalsPortion.buffer),
26542
+ eachGeometryColorsPortion: deflate (data.eachGeometryColorsPortion.buffer),
26543
+ eachGeometryUVsPortion: deflate (data.eachGeometryUVsPortion.buffer),
26544
+ eachGeometryIndicesPortion: deflate (data.eachGeometryIndicesPortion.buffer),
26545
+ eachGeometryEdgeIndicesPortion: deflate (data.eachGeometryEdgeIndicesPortion.buffer),
26546
+ eachMeshGeometriesPortion: deflate (data.eachMeshGeometriesPortion.buffer),
26547
+ eachMeshMatricesPortion: deflate (data.eachMeshMatricesPortion.buffer),
26548
+ eachMeshTextureSet: deflate (data.eachMeshTextureSet.buffer),
26549
+ eachMeshMaterialAttributes: deflate (data.eachMeshMaterialAttributes.buffer),
26550
+ eachEntityId: deflate (JSON.stringify(data.eachEntityId)
26521
26551
.replace(/[\u007F-\uFFFF]/g, function (chr) { // Produce only ASCII-chars, so that the data can be inflated later
26522
26552
return "\\u" + ("0000" + chr.charCodeAt(0).toString(16)).substr(-4)
26523
26553
})),
26524
- eachEntityMeshesPortion: deflate_1 (data.eachEntityMeshesPortion.buffer),
26525
- eachTileAABB: deflate_1 (data.eachTileAABB.buffer),
26526
- eachTileEntitiesPortion: deflate_1 (data.eachTileEntitiesPortion.buffer)
26554
+ eachEntityMeshesPortion: deflate (data.eachEntityMeshesPortion.buffer),
26555
+ eachTileAABB: deflate (data.eachTileAABB.buffer),
26556
+ eachTileEntitiesPortion: deflate (data.eachTileEntitiesPortion.buffer)
26527
26557
};
26528
26558
}
26529
26559
@@ -27592,7 +27622,7 @@ function convert2xkt({
27592
27622
27593
27623
log("XKT document built OK. Writing to XKT file...");
27594
27624
27595
- const xktArrayBuffer = writeXKTModelToArrayBuffer(xktModel, metaModelJSON, stats);
27625
+ const xktArrayBuffer = writeXKTModelToArrayBuffer(xktModel, metaModelJSON, stats, {zip: true} );
27596
27626
27597
27627
const xktContent = Buffer.from(xktArrayBuffer);
27598
27628
0 commit comments