heigvd-software-engineering / bim-examples

A proof of concept for generating and visualizing BIM structures
MIT License
2 stars 0 forks source link

Cannot use web-ifc #2

Closed Moufblu closed 2 years ago

Moufblu commented 2 years ago

Context

I'm trying to use the web-ifc library from IFCjs to write a simple IFC structure from scratch.

I can already import an IFC file into a 3D viewer that I set up with IFCjs web-ifc-three.

I added a button to my frontend interface to log a simple IFC structure in the console. The logged structure must be generated from scratch with web-ifc. button image

The IFC structure I want to log comes from an example from web-ifc. It's an IFC writer with a code editor. It does what I want to do which means logging an IFC structure generated from scratch: link to the example

Current behavior

Here's my current behavior: log-behavior

I get this behavior with these lines of codes (sample):

// Import of the web-ifc library in my Vue component
import * as WebIFC from 'web-ifc';

// Function called on button click
async onLogIFCClick() {
  const ifcApi = new WebIFC.IfcAPI();

  // initialize the library
  await ifcApi.Init();
  ifcWriter.writeIFC(ifcApi);
}

// ifcWriter writeIFC function
function writeIFC(ifcAPI) {
    console.log('begin');
    // const ifcAPI = new WebIFC.IfcAPI();
    console.log('init');
    // ifcAPI.Init();
    console.log('setwasmpath');
    // ifcAPI.SetWasmPath('./wasm');

    console.log("Creating model...");

    const model = ifcAPI.CreateModel({
        COORDINATE_TO_ORIGIN: true,
        USE_FAST_BOOLS: true,
    });

    console.log("Building model...");
    // From IFCjs writer example (mentioned above)
    BuildModel(model, ifcAPI);

    console.log(model)

    const ifcData = ifcAPI.ExportFileAsIFC(model);
    ifcAPI.CloseModel(model);
    const ifcDataString = new TextDecoder().decode(ifcData);

    console.log(ifcDataString);

    return ifcDataString;
}

Links to the related files: App.vue ifcWriter.js

 Expected behavior

A simple IFC structure generated from scratch with web-ifc is logged in the console image

Moufblu commented 2 years ago

@bchapuis You can have some context about my issue here.

Moufblu commented 2 years ago

The problem is solved thanks to the community of IFCjs 🎉

The problem was that I had to use the web-ifc api from web-ifc-three instead of web-ifc.

So to solve my problem I had to: