Dynamically Repositioning Models
In xeokit v2.4, we have added the ability to dynamically reposition a model within xeokit's double-precision coordinate system. This means that once a model is loaded, it can be moved to any location within the full extents of xeokit’s double-precision coordinate system. This feature allows us to load a BIM model from an XKT file and a point cloud from an LAZ file, and then reposition either model to align them with each other.
A model can be dynamically translated and rotated, but cannot be scaled. Disallowing scaling of models is necessary for this mechanism to work efficiently within xeokit’s double-precision coordinate system.
The example below demonstrates the usefulness of this feature. We are loading a BIM model of an apartment building and a point cloud that contains a LiDAR scan of the building. The BIM model is already positioned at its original site placement of [-1842009.4968455553, -9.685518291306686, 5173295.851503017]
, while the point cloud is positioned at [0,0,0]
. To align the two models, we therefore translate the point cloud by [-1842009.4968455553, -9.685518291306686, 5173295.851503017]
.
As demonstrated in this example, what distinguishes xeokit from other viewers is its capability to move models using large, double-precision offsets without encountering jittering caused by rounding errors during rendering.
The screenshot actually shows the point cloud offset slightly from the BIM model, by a few meters along the World X-axis. This offset allows us to differentiate the two models from each other within the screenshot, while the code aligns them directly on top of each other.
import {Viewer, XKTLoaderPlugin, NavCubePlugin} from "https://cdn.jsdelivr.net/npm/@xeokit/xeokit-sdk/dist/xeokit-sdk.es.min.js";
const viewer = new Viewer({
canvasId: "myCanvas"
});
viewer.scene.camera.eye = [-33.39, 19.86, 16.48];
viewer.scene.camera.look = [8.29, 8.28, 0.31];
viewer.scene.camera.up = [0.23, 0.96, -0.09];
const xktLoader = new XKTLoaderPlugin(viewer);
const bimSceneModel = xktLoader.load({ // IFC converted to XKT
id: "myModel",
src: "MAP.xkt"
});
const lasSceneModel = xktLoader.load({ // LAS converted to XKT
id: "myModel2",
src: "MAP-PointCloud.xkt"
});
bimSceneModel.on("loaded", () => {
bimSceneModel.position = [-1842009.4968455553, -9.685518291306686, 5173295.851503017]
});