xeokit / xeokit-xkt-utils

Deprecated JavaScript tools to generate .XKT files; replaced by https://github.com/xeokit/xeokit-convert
Other
10 stars 9 forks source link

Cannot convert GLTF to XKT model #16

Open nmthastings opened 3 years ago

nmthastings commented 3 years ago

I'm slapping together a quick tech demo and am trying to follow along with the basic programmatic implementation of this util found in the xeokit-gltf-to-xkt Readme as part of the process to convert IFC to XKT. I'm running in to the following error when trying to use the parseGLTFIntoXKTModel parser.

TypeError: Cannot read property '0' of undefined at parseDefaultScene (C:\Users\hastings\Documents\Development\glowing-xenon\node_modules\@xeokit\xeokit-xkt-utils\dist\xeokit-xkt-utils.cjs.js:1:98098) at parseGLTFIntoXKTModel (C:\Users\hastings\Documents\Development\glowing-xenon\node_modules\@xeokit\xeokit-xkt-utils\dist\xeokit-xkt-utils.cjs.js:1:96060) at async convertIFCtoXKT (C:\Users\hastings\Documents\Development\glowing-xenon\src\main.js:51:5)

Below is a copy of the JS function that I am trying to use. I have confirmed that the model is getting converted properly up until the parsing function, and the gltf is being properly turned in to a Buffer Object. I omitted the callback for the parser in this snippet (my demo model has no external relations), but I have also tried including a callback and experienced no change.

(I've tried formatting it better, but GFM's parser is fighting it)

`/*Takes IFC filepath as a string, and converts that file to an XKTModel / async function convertIFCtoXKT(filePath) { const { XKTModel, parseGLTFIntoXKTModel, writeXKTModelToArrayBuffer } = require("@xeokit/xeokit-xkt-utils/dist/xeokit-xkt-utils.cjs.js");

//simple string conversions
const daeFile = filePath.replace('.ifc', '.dae');
const gltfFile = filePath.replace('.ifc', '.gltf');
const xktFile = filePath.replace('.ifc', '.xkt');
const jsonFile = filePath.replace('.ifc', '.json');

//Synchronously convert IFC to .dae, .dae to .dltf, and extract JSON metadata from IFC
child_process.execSync(`start lib/ifcConvert/ifcConvert.exe -y --use-element-guids "${filePath}" "${daeFile}"`);
child_process.execSync(`start lib/collada2gltf-v2.1.5/COLLADA2GLTF-bin.exe --materialsCommon -i "${daeFile}" -o "${gltfFile}"`);
child_process.execSync(`start lib/xeokit-metadata/xeokit-metadata.exe "${filePath}" "${jsonFile}"`);

//convert .gltf to .xkt
const xktModel = new XKTModel();
const gltfContent = fs.readFileSync(gltfFile);
await parseGLTFIntoXKTModel(gltfContent, xktModel);
xktModel.finalize();
const xktArrayBuffer = writeXKTModelToArrayBuffer(xktModel);
await fs.writeFileSync(xktFile, xktArrayBuffer);
return 0;

};`