ThatOpen/web-ifc-three

"geo.attributes.position is undefined" when selecting in multiple objects

iserranoe opened this issue · 6 comments

I'm representing multiple objects in the same ifc loader in React. As I have the models in different urls the code for loading them is something like this:

ifcModels=[]
layers.forEach((layer)=>{
        const url = layer.url_ifc
        let center = {}
        loader.load(
          url,
          (object) => {
            scene.add(object);
            ifcModels.push(object)
            const box = new Box3().setFromObject(object);
            center = box.getCenter(new Vector3());
            const size = box.getSize(new Vector3()).length();
            const r = size//Math.sqrt(3)*size/2;
  
            const theta = 0;
            const phi = 0;
            const camara_x = r * Math.cos(phi) * Math.sin(theta)+center.x;
            const camara_y = r * Math.sin(phi) * Math.sin(theta)+center.y;
            const camara_z = r * Math.cos(theta)+center.z;
            camera.position.x = camara_x;
            camera.position.y = camara_y;
            camera.position.z = camara_z;
  
            scene.add(object);  
          }
        );
      })

This is working fine; however, I also want to highlight the subsets following the tutorial here: https://ifcjs.github.io/info/docs/Guide/web-ifc-three/Tutorials/Highlighting. With just one model it's working fine, but with two I can only select subsets from one model, when I try to select the second one I have the warning in ifc.createSubset. Even if I select this latter model first I get the same error.

Unhandled Rejection (TypeError): geo.attributes.position is undefined

Unhandled Rejection (TypeError): geo.attributes.position is undefined
highlight
src/components/modelos/Detalles_ifc.js:343

  340 | const id = await ifc.getExpressId(geometry, index);
  341 | 
  342 | // Creates subset
> 343 | ifc.createSubset({
      | ^  344 |     modelID: object.id,
  345 |     ids: [id],
  346 |     material: material,

I tried with useRef as sugested here: #87 but I get the same error.

UPDATE!!

I looked around ICFLoader.js and I saw this.state.models only contains the last model loaded, therefore, I guess when it tries to find the position of the subset in the second model it's undefined.

I'm having this problem even with 2 models, using 2 separate IFC loaders. I'll put together a codesandbox with the issue and hopefully could get some advice/resolution!

Hi! Probably this is due to the way you initialize IFC.js inside React. Did you check this react example? It doesn't happen there!

@agviegas that example uses web-ifc-viewer not web-ifc-three and looks like it's just loading 1 model at a time

Not sure about OP but I'm not having any problem getting the highlighting example working with a React setup with just 1 model, the problem arises when trying to work with multiple models (perhaps especially when trying to create many instances of a single model)

I raised a separate issue #126 with a more specific question, it'd be really useful if there was a simple working example of working with subsets across several models including duplicates of particular models

Web-ifc-viewer is just a wrapper around web-ifc-three 🤔 In the example I mentioned I'm able to load multiple IFC files and highlight them all without seeing any error. Maybe you can put together a minimal example I can reproduce?

Web-ifc-viewer is just a wrapper around web-ifc-three thinking In the example I mentioned I'm able to load multiple IFC files and highlight them all without seeing any error. Maybe you can put together a minimal example I can reproduce?

Ah, you're right, you can load multiple IFC's in that example. I assumed it was just replacing the IFC every time you select a new one. Okay cool it seems to work, I'll check it out and try to adapt my code this way, cheers!

I've been able to work around the issues I was having as suggested in #83 (see also #126)