Reference Source
public class | since 2.0.17 | source

LASLoaderPlugin

Extends:

Plugin → LASLoaderPlugin

Viewer plugin that loads lidar point cloud geometry from LAS files.

[Run this example]

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

center(value: Boolean)

Configures if LASLoaderPlugin immediately centers LAS positions.

public get

Gets whether LASLoaderPlugin assumes that LAS colors are encoded using 8 or 16 bits.

public set

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

fp64(value: Boolean)

Configures if LASLoaderPlugin assumes that LAS positions are stored in 64-bit floats instead of 32-bit.

public get

rotate: Number[] | null: *

Gets the current rotations to apply to LAS positions as they are loaded.

public set

rotate(rotate: Number[] | null)

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

skip: Number: *

When LASLoaderPlugin is configured to load every n points, returns the value of n.

public set

skip(value: Number)

Configures LASLoaderPlugin to load every n points.

public get

Gets the current transformation to apply to LAS positions as they are loaded.

public set

transform(transform: Number[] | null)

Sets the current transformation to apply to LAS positions as they are loaded.

Method Summary

Public Methods
public

load(params: *): Entity

Loads an LAS model into this LASLoaderPlugin's Viewer.

Inherited Summary

From class Plugin
public

ID for this Plugin, unique within its Viewer.

public

The Viewer that contains this Plugin.

public

Destroys this Plugin and removes it from its Viewer.

public

error(msg: String)

Logs an error message to the JavaScript developer console, prefixed with the ID of this Plugin.

public

fire(event: String, value: Object, forget: Boolean)

Fires an event on this Plugin.

public

Returns true if there are any subscribers to the given event on this Plugin.

public

log(msg: String)

Logs a message to the JavaScript developer console, prefixed with the ID of this Plugin.

public

off(subId: String)

Cancels an event subscription that was previously made with Plugin#on or Plugin#once.

public

on(event: String, callback: Function, scope: Object): String

Subscribes to an event on this Plugin.

public

once(event: String, callback: Function, scope: Object)

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

warn(msg: String)

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#constructor

Params:

NameTypeAttributeDescription
viewer Viewer

The Viewer.

cfg Object

Plugin configuration.

cfg.id String
  • optional
  • default: "lasLoader"

Optional ID for this plugin, so that we can find it within Viewer#plugins.

cfg.dataSource Object
  • optional

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
  • optional
  • default: 1

Configures LASLoaderPlugin to load every n points.

cfg.fp64 Number
  • optional
  • default: false

Configures if LASLoaderPlugin assumes that LAS positions are stored in 64-bit floats instead of 32-bit.

cfg.colorDepth Number
  • optional
  • default: 8

Configures whether LASLoaderPlugin assumes that LAS colors are encoded using 8 or 16 bits. Accepted values are 8, 16 an "auto".

cfg.center Boolean
  • optional
  • default: false

Whether to center the LAS points. Applied before "rotateX", "rotate" and "transform".

cfg.rotateX Boolean
  • optional
  • default: false

Whether to rotate the LAS point positions 90 degrees. Applied after "center".

cfg.rotate Number[]
  • optional
  • default: [0,0,0]

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[]
  • optional

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.

Return:

Boolean

True if LASLoaderPlugin immediately centers LAS positions.

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.

Return:

Number | String

Possible returned values are 8, 16 and "auto".

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.

Return:

Number[] | null

If defined, an array of three Euler angles in degrees, for each of the X, Y and Z axis. Null if undefined.

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.

Return:

Number

The nth point that LASLoaderPlugin will read.

public set skip(value: Number) source

Configures LASLoaderPlugin to load every n points.

Default value is 1.

public get transform: Number[] | null: * source

Gets the current transformation to apply to LAS positions as they are loaded.

If this is true, then LAS positions will be transformed after they are centered and rotated.

Default value is null.

Return:

Number[] | null

A 16-element array containing a 4x4 transformation matrix.

public set transform(transform: Number[] | null) source

Sets the current transformation to apply to LAS positions as they are loaded.

If this is true, then LAS positions will be transformed after they are centered and rotated.

Default value is null.

Public Methods

public load(params: *): Entity source

Loads an LAS model into this LASLoaderPlugin's Viewer.

Params:

NameTypeAttributeDescription
params *

Loading parameters.

params.id String
  • optional

ID to assign to the root Entity#id, unique among all components in the Viewer's Scene, generated automatically by default.

params.src String
  • optional

Path to a LAS file, as an alternative to the las parameter.

params.las ArrayBuffer
  • optional

The LAS file data, as an alternative to the src parameter.

params.loadMetadata Boolean
  • optional
  • default: true

Whether to load metadata for the LAS model.

params.origin Number[]
  • optional
  • default: [0,0,0]

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[]
  • optional
  • default: [0,0,0]

The model single-precision 3D position, relative to the origin parameter.

params.scale Number[]
  • optional
  • default: [1,1,1]

The model's scale.

params.rotation Number[]
  • optional
  • default: [0,0,0]

The model's orientation, given as Euler angles in degrees, for each of the X, Y and Z axis.

params.matrix Number[]
  • optional
  • default: [1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]

The model's world transform matrix. Overrides the position, scale and rotation parameters. Relative to origin.

params.stats Object
  • optional

Collects model statistics.

Return:

Entity

Entity representing the model, which will have Entity#isModel set true and will be registered by Entity#id in Scene#models.