KhronosGroup / COLLADA2GLTF

COLLADA to glTF converter
Other
536 stars 157 forks source link

I/O warning : failed to load external entity #279

Closed assaad97 closed 3 years ago

assaad97 commented 3 years ago

what im trying to do, is convert ifc files to gltf files, the process is the following :

1) convert if to dae using IfcConvert from this link : http://ifcopenshell.org/ifcconvert 2) convert dae to gltf using COLLADA2GLTF

i needed to automate this process in js using exec from the module child_process, here is the js code

`const { exec } = require("child_process");

function IfcConvertor(file) {

//filename in different extensions naming
const FileName = file.split('.');

console.log(FileName);

const ifcFile = FileName[0]+'.ifc';
const daeFile = FileName[0]+'.dae';
const gltfFile = FileName[0]+'.gltf';
const xktFile = FileName[0]+'.xkt';
const jsonFile = FileName[0]+'.json';

console.log(ifcFile+' '+daeFile+' '+gltfFile+' '+xktFile+' '+jsonFile+' ')

let convertCmds = [
    `IfcConvert --use-element-guids ${ifcFile} ${daeFile} --exclude=entities IfcOpeningElement`,
    `COLLADA2GLTF-bin -i ${daeFile} -o ${gltfFile}`,
];

for (const indexCmd in convertCmds) {
    console.log(convertCmds[indexCmd]);
    exec(convertCmds[indexCmd], (error, stdout, stderr) => {
        if (error) {
            console.log(`error: ${error.message}`);
            return;
        }
        if (stderr) {
            console.log(`stderr: ${stderr}`);
            return;
        }
        console.log(`stdout: ${stdout}`);
    });
    setTimeout(() => {}, 1000);
}

} `

the problem that happens is when i run the script this error is raised : `error: Command failed: COLLADA2GLTF-bin -i sample.dae -o sample.gltf I/O warning : failed to load external entity "sample.dae"

stdout: IfcOpenShell IfcConvert 0.6.0b0 (OCC 7.3.0) Scanning file... Done scanning file Parsing input file took 0 seconds Creating geometry... Done creating geometry (9 objects)

Conversion took 0 seconds`

i cant figure out why it is happening, so i tried to do it manually in the CLI, and it worked

lasalvavida commented 3 years ago

Exec is asynchronous, so I'm guessing COLLADA2GLTF is being run before IfcConvert is finished writing the file and the XML parser quits because the input is not valid.

Try execSync.

https://nodejs.org/api/child_process.html#child_process_child_process_execsync_command_options

assaad97 commented 3 years ago

@lasalvavida thanks for your help, it worked, you actually saved me the weekend xD, thanks again for your help