Skip to content

Commit

Permalink
Refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
xeolabs committed Nov 7, 2024
1 parent cc2d44b commit dbd997a
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 7 deletions.
14 changes: 7 additions & 7 deletions packages/las2dtx/src/index.ts → packages/las2xgf/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/**
* [![npm version](https://badge.fury.io/js/%40xeokit%2Fifcviewer.svg)](https://badge.fury.io/js/%40xeokit%2Fifcviewer)
* [![](https://data.jsdelivr.com/v1/package/npm/@xeokit/las2dtx/badge)](https://www.jsdelivr.com/package/npm/@xeokit/ifcviewer)
* [![](https://data.jsdelivr.com/v1/package/npm/@xeokit/las2xgf/badge)](https://www.jsdelivr.com/package/npm/@xeokit/ifcviewer)
*
* <img style="padding:0px; padding-top:30px; padding-bottom:30px;" src="media://images/tree_view_icon.png"/>
*
* <br>
*
* ## las2dtx
* ## las2xgf
*
* Node CLI tool to convert LAS files into [DTX](https://xeokit.github.io/sdk/docs/pages/GLOSSARY.html#dtx) files.
* Node CLI tool to convert LAS files into [XGF](https://xeokit.github.io/sdk/docs/pages/GLOSSARY.html#xgf) files.
*
* ## Features
*
Expand All @@ -17,17 +17,17 @@
* ## Installation
*
* ````bash
* npm install @xeokit/las2dtx
* npm install @xeokit/las2xgf
* ````
*
* ## Usage
*
* TODO
*
* ````bash
* las2dtx -i model.json -o model.dtx
* las2xgf -i model.json -o model.xgf
* ````
*
* @module @xeokit/las2dtx
* @module @xeokit/las2xgf
*/
export * from "./las2dtx"
export * from "./las2xgf"
116 changes: 116 additions & 0 deletions packages/las2xgf/src/las2xgf.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#!/usr/bin/env node

import '@loaders.gl/polyfills';
import {Data, DataModel} from "@xeokit/data";
import {Scene, SceneModel} from "@xeokit/scene";
import {SDKError} from "@xeokit/core";
import {loadLAS} from "@xeokit/las";
import {saveXGF, SAVED_XGF_VERSIONS, DEFAULT_SAVED_XGF_VERSION} from "@xeokit/xgf";

/**
* @private
*/
function las2xgf(params: {
fileData: ArrayBuffer,
xgfVersion?: number,
createDataModel?: boolean
}): Promise<{
xgfArrayBuffer: ArrayBuffer,
sceneModel: SceneModel,
dataModel?: DataModel,
dataModelJSON: any
}> {
const {fileData, xgfVersion, createDataModel} = params;
return new Promise(function (resolve, reject) {
const scene = new Scene();
const sceneModel = scene.createModel({
id: "foo"
});
if (sceneModel instanceof SDKError) {
return reject(sceneModel.message);
} else {
if (createDataModel) { // Create default DataModel from glTF
const data = new Data();
const dataModel = data.createModel({
id: "foo"
});
if (dataModel instanceof SDKError) {
return reject(dataModel.message);
} else {
loadLAS({
fileData,
dataModel,
sceneModel
}).then(() => {
sceneModel.build().then(() => {
dataModel.build().then(() => {
const xgfArrayBuffer = saveXGF({
sceneModel,
xgfVersion
});
if (xgfArrayBuffer instanceof SDKError) {
return reject(xgfArrayBuffer.message);
} else {
const dataModelJSON = dataModel.getJSON();
return resolve({
xgfArrayBuffer,
sceneModel,
dataModel,
dataModelJSON
});
}
}).catch(reason => {
return reject(reason);
});
}).catch((reason) => {
return reject(reason);
});
}).catch((reason) => {
return reject(reason);
});
}
} else { // Don't create DataModel
loadLAS({
fileData,
sceneModel
}).then(() => {
sceneModel.build().then(() => {
const xgfArrayBuffer = saveXGF({
sceneModel,
xgfVersion
});
if (xgfArrayBuffer instanceof SDKError) {
return reject(xgfArrayBuffer.message);
} else {
return resolve({
xgfArrayBuffer,
sceneModel,
dataModel: null,
dataModelJSON: null
});
}
}).catch(err => {
return reject(err);
});
}).catch(err => {
return reject(err);
});
}
}
});
}

/**
* @private
*/
export {las2xgf};

/**
* @private
*/
export const _SAVED_XGF_VERSIONS = SAVED_XGF_VERSIONS; // Make these private for our CLI tool's use only

/**
* @private
*/
export const _DEFAULT_SAVED_XGF_VERSION = DEFAULT_SAVED_XGF_VERSION;

0 comments on commit dbd997a

Please sign in to comment.