@xeokit/xeokit-sdk 2.0.17 → 2.0.18

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.
@@ -78940,8 +78940,7 @@ class ModelTreeView {
78940
78940
  * hierarchy of the IFC elements in each model we load.
78941
78941
  *
78942
78942
  * Then we'll use an {@link XKTLoaderPlugin} to load the Schependomlaan model from an
78943
- * [.xkt file](https://github.com/xeokit/xeokit-sdk/tree/master/examples/models/xkt/schependomlaan), along
78944
- * with an accompanying JSON [IFC metadata file](https://github.com/xeokit/xeokit-sdk/tree/master/examples/metaModels/schependomlaan).
78943
+ * [.xkt file](https://github.com/xeokit/xeokit-sdk/tree/master/examples/models/xkt/schependomlaan).
78945
78944
  *
78946
78945
  * [[Run this example](https://xeokit.github.io/xeokit-sdk/examples/#BIMOffline_XKT_Schependomlaan)]
78947
78946
  *
@@ -145473,9 +145472,9 @@ const LASLoader = {
145473
145472
  /**
145474
145473
  * {@link Viewer} plugin that loads lidar point cloud geometry from LAS files.
145475
145474
  *
145476
- * <a href="/examples/#loading_LASLoaderPlugin_Autzen"><img src="/assets/images/autzen.png"></a>
145475
+ * <a href="https://xeokit.github.io/xeokit-sdk/examples/#loading_LASLoaderPlugin_Autzen"><img src="https://xeokit.github.io/xeokit-sdk/assets/images/autzen.png"></a>
145477
145476
  *
145478
- * [[Run this example](/examples/#loading_LASLoaderPlugin_Autzen)]
145477
+ * [[Run this example](https://xeokit.github.io/xeokit-sdk/examples/#loading_LASLoaderPlugin_Autzen)]
145479
145478
  *
145480
145479
  * ## Summary
145481
145480
  *
@@ -145511,10 +145510,10 @@ const LASLoader = {
145511
145510
  * ## Usage
145512
145511
  *
145513
145512
  * In the example below we'll load the Autzen model from
145514
- * a [LAS file](https://github.com/xeokit/xeokit-sdk/tree/master/examples/models/las/Duplex.las). Once the model has
145513
+ * a [LAS file](/assets/models/las/). Once the model has
145515
145514
  * loaded, we'll then find its {@link MetaModel}, and the {@link MetaObject} and {@link Entity} that represent its point cloud.
145516
145515
  *
145517
- * * [[Run this example](/examples/#loading_LASLoaderPlugin_Autzen)]
145516
+ * * [[Run this example](https://xeokit.github.io/xeokit-sdk/examples/#loading_LASLoaderPlugin_Autzen)]
145518
145517
  *
145519
145518
  * ````javascript
145520
145519
  * import {Viewer, LASLoaderPlugin} from "xeokit-sdk.es.js";
@@ -145555,7 +145554,7 @@ const LASLoader = {
145555
145554
  * We have the option to rotate, scale and translate each LAS model as we load it.
145556
145555
  *
145557
145556
  * In the example below, we'll scale our model to half its size, rotate it 90 degrees about its local X-axis, then
145558
- * translate it 100 units along its X axis.
145557
+ * position it at [1842022, 10, -5173301] within xeokit's world coordinate system.
145559
145558
  *
145560
145559
  * ````javascript
145561
145560
  * const modelEntity = lasLoader.load({
@@ -145563,7 +145562,7 @@ const LASLoader = {
145563
145562
  * src: "../assets/models/las/autzen.laz"
145564
145563
  * rotation: [90,0,0],
145565
145564
  * scale: [0.5, 0.5, 0.5],
145566
- * origin: [100, 0, 0]
145565
+ * origin: [1842022, 10, -5173301]
145567
145566
  * });
145568
145567
  * ````
145569
145568
  *
@@ -145605,7 +145604,7 @@ const LASLoader = {
145605
145604
  * ````
145606
145605
  *
145607
145606
  * @class LASLoaderPlugin
145608
- * @since 2.0.13
145607
+ * @since 2.0.17
145609
145608
  */
145610
145609
  class LASLoaderPlugin extends Plugin {
145611
145610
 
@@ -145797,6 +145796,48 @@ class LASLoaderPlugin extends Plugin {
145797
145796
 
145798
145797
  _parseModel(arrayBuffer, params, options, performanceModel) {
145799
145798
 
145799
+ function readPositions(attributesPosition) {
145800
+ const positionsValue = attributesPosition.value;
145801
+ if (params.rotateX) {
145802
+ if (positionsValue) {
145803
+ for (let i = 0, len = positionsValue.length; i < len; i += 3) {
145804
+ const temp = positionsValue[i + 1];
145805
+ positionsValue[i + 1] = positionsValue[i + 2];
145806
+ positionsValue[i + 2] = temp;
145807
+ }
145808
+ }
145809
+ }
145810
+ return positionsValue;
145811
+ }
145812
+
145813
+ function readColorsAndIntensities(attributesColor, attributesIntensity) {
145814
+ const colors = attributesColor.value;
145815
+ const colorSize = attributesColor.size;
145816
+ const intensities = attributesIntensity.value;
145817
+ const colorsCompressedSize = intensities.length * 4;
145818
+ const colorsCompressed = new Uint8Array(colorsCompressedSize);
145819
+ for (let i = 0, j = 0, k = 0, len = intensities.length; i < len; i++, k += colorSize, j += 4) {
145820
+ colorsCompressed[j + 0] = colors[k + 0];
145821
+ colorsCompressed[j + 1] = colors[k + 1];
145822
+ colorsCompressed[j + 2] = colors[k + 2];
145823
+ colorsCompressed[j + 3] = Math.round((intensities[i] / 65536) * 255);
145824
+ }
145825
+ return colorsCompressed;
145826
+ }
145827
+
145828
+ function readIntensities(attributesIntensity) {
145829
+ const intensities = attributesIntensity.intensity;
145830
+ const colorsCompressedSize = intensities.length * 4;
145831
+ const colorsCompressed = new Uint8Array(colorsCompressedSize);
145832
+ for (let i = 0, j = 0, len = intensities.length; i < len; i++, j += 4) {
145833
+ colorsCompressed[j + 0] = 0;
145834
+ colorsCompressed[j + 1] = 0;
145835
+ colorsCompressed[j + 2] = 0;
145836
+ colorsCompressed[j + 3] = Math.round((intensities[i] / 65536) * 255);
145837
+ }
145838
+ return colorsCompressed;
145839
+ }
145840
+
145800
145841
  return new Promise((resolve, reject) => {
145801
145842
 
145802
145843
  if (performanceModel.destroyed) {
@@ -145820,78 +145861,60 @@ class LASLoaderPlugin extends Plugin {
145820
145861
  try {
145821
145862
  parse(arrayBuffer, LASLoader, options).then((parsedData) => {
145822
145863
 
145864
+ const loaderData = parsedData.loaderData;
145865
+ const loaderDataHeader = loaderData.header;
145866
+ const pointsFormatId = loaderDataHeader.pointsFormatId;
145867
+
145823
145868
  const attributes = parsedData.attributes;
145824
- const attributesPosition = attributes.POSITION;
145825
- const attributesColor = attributes.COLOR_0;
145826
- // const attributesColor_0 = attributes.COLOR_0;
145827
- const attributesIntensity = attributes.intensity;
145828
- const attributesClassification = attributes.classification;
145829
145869
 
145830
- if (!attributesPosition) {
145870
+ if (!attributes.POSITION) {
145831
145871
  performanceModel.finalize();
145832
145872
  reject("No positions found in file");
145833
145873
  return;
145834
145874
  }
145835
-
145836
- const positionsValue = attributesPosition.value;
145837
-
145838
- if (params.rotateX) {
145839
- if (positionsValue) {
145840
- for (let i = 0, len = positionsValue.length; i < len; i += 3) {
145841
- const temp = positionsValue[i + 1];
145842
- positionsValue[i + 1] = positionsValue[i + 2];
145843
- positionsValue[i + 2] = temp;
145875
+
145876
+ let positionsValue;
145877
+ let colorsCompressed;
145878
+
145879
+ switch (pointsFormatId) {
145880
+ case 0:
145881
+ positionsValue = readPositions(attributes.POSITION);
145882
+ colorsCompressed = readIntensities(attributes.intensity);
145883
+ break;
145884
+ case 1:
145885
+ if (!attributes.intensity) {
145886
+ performanceModel.finalize();
145887
+ reject("No positions found in file");
145888
+ return;
145844
145889
  }
145845
- }
145846
- }
145847
-
145848
- let colorsCompressed = null;
145849
-
145850
- if (attributesColor) {
145851
- colorsCompressed = attributesColor.value;
145852
- } else {
145853
-
145854
- }
145855
-
145856
- if (attributesIntensity) {
145857
- const intensities = attributesIntensity.value;
145858
- colorsCompressed = new Uint8Array(intensities.length * 4);
145859
-
145860
- if (attributesColor) { // Intensities with colors
145861
- const colors = attributesColor.value;
145862
- const colorsSize = attributesColor.size;
145863
- for (let i = 0, j = 0, len = intensities.length; i < len; i++, j += 4) {
145864
- const intensity = Math.round((intensities[i] / 65536) * 255); // FIXME: Precision loss converting intensity from 16 to 8 bits
145865
- colorsCompressed[j + 0] = colors[i * colorsSize];
145866
- colorsCompressed[j + 1] = colors[i * colorsSize + 1];
145867
- colorsCompressed[j + 2] = colors[i * colorsSize + 2];
145868
- colorsCompressed[j + 3] = intensity;
145890
+ positionsValue = readPositions(attributes.POSITION);
145891
+ colorsCompressed = readIntensities(attributes.intensity);
145892
+ break;
145893
+ case 2:
145894
+ if (!attributes.intensity) {
145895
+ performanceModel.finalize();
145896
+ reject("No positions found in file");
145897
+ return;
145869
145898
  }
145870
- } else { // Intensities without colors
145871
- for (let i = 0, j = 0, len = intensities.length; i < len; i++, j += 4) {
145872
- const intensity = Math.round((intensities[i] / 65536) * 255);
145873
- colorsCompressed[j + 0] = 125; // Gray
145874
- colorsCompressed[j + 1] = 125;
145875
- colorsCompressed[j + 2] = 125;
145876
- colorsCompressed[j + 3] = intensity;
145899
+ positionsValue = readPositions(attributes.POSITION);
145900
+ colorsCompressed = readColorsAndIntensities(attributes.COLOR_0, attributes.intensity);
145901
+ break;
145902
+ case 3:
145903
+ if (!attributes.intensity) {
145904
+ performanceModel.finalize();
145905
+ reject("No positions found in file");
145906
+ return;
145877
145907
  }
145878
- }
145879
- } else if (attributesColor) { // Colors without intensities
145880
- const colors = attributesColor.value;
145881
- const colorsSize = attributesColor.size;
145882
- for (let i = 0, j = 0, len = colors.length / colorsSize; i < len; i++, j += 4) {
145883
- colorsCompressed[j + 0] = colors[i * colorsSize];
145884
- colorsCompressed[j + 1] = colors[i * colorsSize + 1];
145885
- colorsCompressed[j + 2] = colors[i * colorsSize + 2];
145886
- colorsCompressed[j + 3] = (colorsSize === 4) ? colors[i * colorsSize + 3] : 255;
145887
- }
145908
+ positionsValue = readPositions(attributes.POSITION);
145909
+ colorsCompressed = readColorsAndIntensities(attributes.COLOR_0, attributes.intensity);
145910
+ break;
145888
145911
  }
145889
145912
 
145890
145913
  performanceModel.createMesh({
145891
145914
  id: "pointsMesh",
145892
145915
  primitive: "points",
145893
145916
  positions: positionsValue,
145894
- colorsCompressed
145917
+ colorsCompressed: colorsCompressed
145895
145918
  });
145896
145919
 
145897
145920
  performanceModel.createEntity({
@@ -145904,7 +145927,6 @@ class LASLoaderPlugin extends Plugin {
145904
145927
 
145905
145928
  // TODO: Create metamodel
145906
145929
 
145907
-
145908
145930
  performanceModel.scene.once("tick", () => {
145909
145931
  if (performanceModel.destroyed) {
145910
145932
  return;