import {LASLoaderPlugin} from '@xeokit/xeokit-sdk/src/plugins/LASLoaderPlugin/LASLoaderPlugin.js'
LASLoaderPlugin
Extends:
Viewer plugin that loads lidar point cloud geometry from LAS files.
Summary
- Loads LAS Formats up to v1.3 from both .las and .laz files. It does not support LAS v1.4.
- Loads lidar point cloud positions, colors and intensities.
- Supports 32 and 64-bit positions.
- Supports 8 and 16-bit color depths.
- Option to load every n points.
- Does not (yet) load point classifications.
Performance
If you need faster loading, consider pre-converting your LAS files to XKT format using xeokit-convert, then loading them with XKTLoaderPlugin.
Scene and metadata representation
When LASLoaderPlugin loads a LAS file, it creates two Entitys, a MetaModel and a MetaObject.
The first Entity represents the file as a model within the Viewer's Scene. To indicate that it represents a model,
this Entity will have Entity#isModel set true
and will be registered by Entity#id in Scene#models.
The second Entity represents the the point cloud itself, as an object within the Scene. To indicate that it
represents an object, this Entity will have Entity#isObject set true
and will be registered
by Entity#id in Scene#objects.
The MetaModel registers the LAS file as a model within the Viewer's MetaScene. The MetaModel will be registered by MetaModel#id in MetaScene#metaModels .
Finally, the MetaObject registers the point cloud as an object within the MetaScene. The MetaObject will be registered by MetaObject#id in MetaScene#metaObjects.
Usage
In the example below we'll load the Autzen model from a LAS file. Once the model has loaded, we'll then find its MetaModel, and the MetaObject and Entity that represent its point cloud.
import {Viewer, LASLoaderPlugin} from "xeokit-sdk.es.js";
const viewer = new Viewer({
canvasId: "myCanvas",
transparent: true
});
viewer.camera.eye = [-2.56, 8.38, 8.27];
viewer.camera.look = [13.44, 3.31, -14.83];
viewer.camera.up = [0.10, 0.98, -0.14];
const lasLoader = new LASLoaderPlugin(viewer, {
colorDepth: 8, // Default
fp64: false, // Default
skip: 1 // Default
});
const modelEntity = lasLoader.load({
id: "myModel",
src: "../assets/models/las/autzen.laz"
});
modelEntity.on("loaded", () => {
const metaModel = viewer.metaScene.metaModels[modelEntity.id];
const pointCloudMetaObject = metaModel.rootMetaObject;
const pointCloudEntity = viewer.scene.objects[pointCloudMetaObject.id];
//...
});
Transforming
We have the option to rotate, scale and translate each LAS model as we load it.
In the example below, we'll scale our model to half its size, rotate it 90 degrees about its local X-axis, then position it at [1842022, 10, -5173301] within xeokit's world coordinate system.
const modelEntity = lasLoader.load({
id: "myModel",
src: "../assets/models/las/autzen.laz"
rotation: [90,0,0],
scale: [0.5, 0.5, 0.5],
origin: [1842022, 10, -5173301]
});
Configuring a custom data source
By default, LASLoaderPlugin will load LAS files over HTTP.
In the example below, we'll customize the way LASLoaderPlugin loads the files by configuring it with our own data source object. For simplicity, our custom data source example also uses HTTP, using a couple of xeokit utility functions.
import {utils} from "xeokit-sdk.es.js";
class MyDataSource {
constructor() {
}
// Gets the contents of the given LAS file in an arraybuffer
getLAS(src, ok, error) {
utils.loadArraybuffer(src,
(arraybuffer) => {
ok(arraybuffer);
},
(errMsg) => {
error(errMsg);
});
}
}
const lasLoader = new LASLoaderPlugin(viewer, {
dataSource: new MyDataSource()
});
const modelEntity = lasLoader.load({
id: "myModel",
src: "../assets/models/las/autzen.laz"
});
Showing a LAS/LAZ model in TreeViewPlugin
We can use the load()
method's elementId
parameter
to make LASLoaderPlugin load the entire model into a single Entity that gets this ID.
In conjunction with that parameter, we can then use the load()
method's metaModelJSON
parameter to create a MetaModel that
contains a MetaObject that corresponds to that Entity.
When we've done that, then xeokit's TreeViewPlugin is able to have a node that represents the model and controls the visibility of that Entity (ie. to control the visibility of the entire model).
The snippet below shows how this is done.
import {Viewer, LASLoaderPlugin, NavCubePlugin, TreeViewPlugin} from "../../dist/xeokit-sdk.es.js";
const viewer = new Viewer({
canvasId: "myCanvas",
transparent: true
});
new TreeViewPlugin(viewer, {
containerElement: document.getElementById("treeViewContainer"),
hierarchy: "containment"
});
const lasLoader = new LASLoaderPlugin(viewer);
const sceneModel = lasLoader.load({ // Creates a SceneModel with ID "myScanModel"
id: "myScanModel",
src: "../../assets/models/las/Nalls_Pumpkin_Hill.laz",
rotation: [-90, 0, 0],
entityId: "3toKckUfH2jBmd$7uhJHa4", // Creates an Entity with this ID
metaModelJSON: { // Creates a MetaModel with ID "myScanModel"
"metaObjects": [
{
"id": "3toKckUfH2jBmd$7uhJHa6", // Creates this MetaObject with this ID
"name": "My Project",
"type": "Default",
"parent": null
},
{
"id": "3toKckUfH2jBmd$7uhJHa4", // Creates this MetaObject with this ID
"name": "My Scan",
"type": "Default",
"parent": "3toKckUfH2jBmd$7uhJHa6"
}
]
}
});
Constructor Summary
Public Constructor | ||
public |
constructor(viewer: Viewer, cfg: Object) |
Member Summary
Public Members | ||
public get |
Gets if LASLoaderPlugin immediately centers LAS positions. |
|
public set |
Configures if LASLoaderPlugin immediately centers LAS positions. |
|
public get |
colorDepth: Number | String: * Gets whether LASLoaderPlugin assumes that LAS colors are encoded using 8 or 16 bits. |
|
public set |
colorDepth(value: Number | String) Configures whether LASLoaderPlugin assumes that LAS colors are encoded using 8 or 16 bits. |
|
public get |
Gets the custom data source through which the LASLoaderPlugin can load LAS files. |
|
public set |
Sets a custom data source through which the LASLoaderPlugin can load LAS files. |
|
public get |
Gets if LASLoaderPlugin assumes that LAS positions are stored in 64-bit floats instead of 32-bit. |
|
public set |
Configures if LASLoaderPlugin assumes that LAS positions are stored in 64-bit floats instead of 32-bit. |
|
public get |
Gets the current rotations to apply to LAS positions as they are loaded. |
|
public set |
Sets the current rotations to apply to LAS positions as they are loaded. |
|
public get |
rotateX: *: * Gets if LAS positions are rotated 90 degrees about X as they are loaded. |
|
public set |
rotateX(rotateX: *) Sets if LAS positions are rotated 90 degrees about X as they are loaded. |
|
public get |
When LASLoaderPlugin is configured to load every n points, returns the value of n. |
|
public set |
Configures LASLoaderPlugin to load every n points. |
|
public get |
Gets the current transformation to apply to LAS positions as they are loaded. |
|
public set |
Sets the current transformation to apply to LAS positions as they are loaded. |
Method Summary
Public Methods | ||
public |
Loads an |
Inherited Summary
From class Plugin | ||
public |
ID for this Plugin, unique within its Viewer. |
|
public |
The Viewer that contains this Plugin. |
|
public |
destroy() Destroys this Plugin and removes it from its Viewer. |
|
public |
Logs an error message to the JavaScript developer console, prefixed with the ID of this Plugin. |
|
public |
Fires an event on this Plugin. |
|
public |
Returns true if there are any subscribers to the given event on this Plugin. |
|
public |
Logs a message to the JavaScript developer console, prefixed with the ID of this Plugin. |
|
public |
Cancels an event subscription that was previously made with Plugin#on or Plugin#once. |
|
public |
Subscribes to an event on this Plugin. |
|
public |
Subscribes to the next occurrence of the given event, then un-subscribes as soon as the event is subIdd. |
|
public |
scheduleTask(task: *) Schedule a task to perform on the next browser interval |
|
public |
Logs a warning message to the JavaScript developer console, prefixed with the ID of this Plugin. |
Public Constructors
public constructor(viewer: Viewer, cfg: Object) source
Creates this Plugin and installs it into the given Viewer.
Override:
Plugin#constructorParams:
Name | Type | Attribute | Description |
viewer | Viewer | The Viewer. |
|
cfg | Object | Plugin configuration. |
|
cfg.id | String |
|
Optional ID for this plugin, so that we can find it within Viewer#plugins. |
cfg.dataSource | Object |
|
A custom data source through which the LASLoaderPlugin can load model and metadata files. Defaults to an instance of LASDefaultDataSource, which loads over HTTP. |
cfg.skip | Number |
|
Configures LASLoaderPlugin to load every n points. |
cfg.fp64 | Number |
|
Configures if LASLoaderPlugin assumes that LAS positions are stored in 64-bit floats instead of 32-bit. |
cfg.colorDepth | Number |
|
Configures whether LASLoaderPlugin assumes that LAS colors are encoded using 8 or 16 bits. Accepted values are 8, 16 an "auto". |
cfg.center | Boolean |
|
Whether to center the LAS points. Applied before "rotateX", "rotate" and "transform". |
cfg.rotateX | Boolean |
|
Whether to rotate the LAS point positions 90 degrees. Applied after "center". |
cfg.rotate | Number[] |
|
Rotations to immediately apply to the LAS points, given as Euler angles in degrees, for each of the X, Y and Z axis. Rotation is applied after "center" and "rotateX". |
cfg.transform | Number[] |
|
4x4 transform matrix to immediately apply to the LAS points. This is applied after "center", "rotateX" and "rotate". Typically used instead of "rotateX" and "rotate". |
Public Members
public get center: Boolean: * source
Gets if LASLoaderPlugin immediately centers LAS positions.
If this is true
then centering is the first thing that happens to LAS positions as they are loaded.
Default value is false
.
public set center(value: Boolean) source
Configures if LASLoaderPlugin immediately centers LAS positions.
If this is true
then centering is the first thing that happens to LAS positions as they are loaded.
Default value is false
.
public get colorDepth: Number | String: * source
Gets whether LASLoaderPlugin assumes that LAS colors are encoded using 8 or 16 bits.
Default value is 8
.
Note: LAS specification recommends 16 bits.
public set colorDepth(value: Number | String) source
Configures whether LASLoaderPlugin assumes that LAS colors are encoded using 8 or 16 bits.
Default value is 8
.
Note: LAS specification recommends 16 bits.
public get dataSource: Object source
Gets the custom data source through which the LASLoaderPlugin can load LAS files.
Default value is LASDefaultDataSource, which loads via HTTP.
public set dataSource: Object source
Sets a custom data source through which the LASLoaderPlugin can load LAS files.
Default value is LASDefaultDataSource, which loads via HTTP.
public get fp64: Boolean: * source
Gets if LASLoaderPlugin assumes that LAS positions are stored in 64-bit floats instead of 32-bit.
Default value is false
.
Return:
Boolean | True if LASLoaderPlugin assumes that positions are stored in 64-bit floats instead of 32-bit. |
public set fp64(value: Boolean) source
Configures if LASLoaderPlugin assumes that LAS positions are stored in 64-bit floats instead of 32-bit.
Default value is false
.
public get rotate: Number[] | null: * source
Gets the current rotations to apply to LAS positions as they are loaded.
Rotations are an array of three Euler angles in degrees, for each of the X, Y and Z axis, applied in that order.
Default value is null.
public set rotate(rotate: Number[] | null) source
Sets the current rotations to apply to LAS positions as they are loaded.
Rotations are an array of three Euler angles in degrees, for each of the X, Y and Z axis, applied in that order.
Default value is null.
public get rotateX: *: * source
Gets if LAS positions are rotated 90 degrees about X as they are loaded.
Default value is false
.
Return:
* |
public set rotateX(rotateX: *) source
Sets if LAS positions are rotated 90 degrees about X as they are loaded.
Default value is false
.
public get skip: Number: * source
When LASLoaderPlugin is configured to load every n points, returns the value of n.
Default value is 1
.
public set skip(value: Number) source
Configures LASLoaderPlugin to load every n points.
Default value is 1
.
Public Methods
public load(params: *): Entity source
Loads an LAS
model into this LASLoaderPlugin's Viewer.
Params:
Name | Type | Attribute | Description |
params | * | Loading parameters. |
|
params.id | String |
|
ID to assign to the root Entity#id, unique among all components in the Viewer's Scene, generated automatically by default. |
params.src | String |
|
Path to a LAS file, as an alternative to the |
params.las | ArrayBuffer |
|
The LAS file data, as an alternative to the |
params.loadMetadata | Boolean |
|
Whether to load metadata for the LAS model. |
params.origin | Number[] |
|
The model's World-space double-precision 3D origin. Use this to position the model within xeokit's World coordinate system, using double-precision coordinates. |
params.position | Number[] |
|
The model single-precision 3D position, relative to the |
params.scale | Number[] |
|
The model's scale. |
params.rotation | Number[] |
|
The model's orientation, given as Euler angles in degrees, for each of the X, Y and Z axis. |
params.matrix | Number[] |
|
The model's world transform matrix. Overrides the position, scale and rotation parameters. Relative to |
params.stats | Object |
|
Collects model statistics. |
Return:
Entity | Entity representing the model, which will have Entity#isModel set |