-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
123 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |