Hide menu
Loading a 3D file into memory

Once the input 3D file has been prepared in the form of CDXFB files, their contents can be loaded into the application as follows:

// Create model
const aModel = new cadex.ModelData_Model();
// Model loads external data asynchronously on demand, so requires data provider for it.
const dataLoader = async (theModelPath, theObjId) => {
const aRes = await fetch(theModelPath + '/' + theObjId);
if (aRes.status === 200) {
return aRes.arrayBuffer();
}
throw new Error(aRes.statusText);
};
// Load model by URL.
const aLoadResult = await aModel.loadFile(theModelPath, dataLoader, false /*append roots*/);

where:

  • theModelPath is a url to the top CDXFB directory (e.g. output/conrod.cdxfb),
  • theObjId is a file in the CDXFB directory (e.g. scenegraph.cdxfb)

cadex.ModelData_Model is essentially an object which encapsulates 3D model in memory. This class corresponds to a C++ counterpart cadex::ModelData_Model class described in details in the CAD Exchanger SDK User’s Guide. So you might want to read that guide if you have not done so yet.