xeokit / xeokit-convert

Convert various AEC model formats for efficient viewing in the browser with xeokit.
https://xeokit.github.io/xeokit-convert/docs/
Other
49 stars 52 forks source link

[FIX] Make convert2xkt configs argument optional #154

Closed ctrlmaniac closed 4 months ago

ctrlmaniac commented 4 months ago

I'm trying to use convert2xkt with node.js but i'm facing some issues...

Firstly I had to import iyt in this way:

const {
  convert2xkt,
} = require("@xeokit/xeokit-convert/dist/convert2xkt.cjs.js");

otherwise I'm getting a convert2xkt is not a function.

secondly I'm getting this error: Conversion failed: TypeError: Cannot read properties of undefined (reading 'sourceConfigs')

this is my configuration:

  const media = process.env["CLUSTER_PATH"] + "/media";

  const source = path.join(media, "buildings", "ifc", ifcFilename);
  const dest = path.join(media, "/buildings", "xkt", ifcFilename + ".xkt");

  convert2xkt({
      source: source,
      output: (buffer) => {
        fs.writeFileSync(dest, buffer);
      },
      log: (msg) => {
        console.log(msg);
      },
    }).then(
      () => {
        console.log("Converted.");
      },
      (errMsg) => {
        console.error("Conversion failed: " + errMsg);
      },
    );

how to fix these issues?

xeolabs commented 4 months ago

You need to pass a configs into the convert2xkt call.

I just made convert2xkt treat the configs arg as optional, so you could either supply an empty map for that, or update to the latest release.

See here for how to use on node:

https://github.com/xeokit/xeokit-convert/blob/main/convert2xkt.js

ctrlmaniac commented 4 months ago

Where do I get these configs? I've copied the file you provided in the src folder but now it says that Cannot read properties of undefined (reading 'IfcAPI')

xeolabs commented 4 months ago

Where do I get these configs? I've copied the file you provided in the src folder but now it says that Cannot read properties of undefined (reading 'IfcAPI')

See here for where the configs are obtained for passing into convert2xkt: https://github.com/xeokit/xeokit-convert/blob/main/convert2xkt.js#L172

This is the nodejs script that invokes the convert2xktfunction and provides the configs argument, along with the WebIFC argument required for converting IFC.

We don't have checking for missing arguments in the convert2xkt function, but the nodejs script will provide a working model for yoy to use the convert2xkt function on node.

This is the best support I can provide at the moment for your use case of calling convert2xkt function from your own nodejs script. If your enterprise needs prioritised support, please get in touch here: https://creoox.com/en/contact/

ctrlmaniac commented 4 months ago

ok but I cannot spawn the commander convert2xkt command from a node.js script since it is not exported from the package.json as en entry file... so I do not know how to make the function works either!

xeolabs commented 4 months ago

Try cloning the repository and modifying the convert2xkt.js script