ThatOpen / engine_components

MIT License
321 stars 126 forks source link

Cannot clone a model #439

Closed ThisIsMonta closed 2 months ago

ThisIsMonta commented 3 months ago

Describe the bug 📝

Trying to clone a model but got an error :

@thatopen_components.js?v=6f57743e:92 Uncaught (in promise) 
TypeError: Cannot read properties of undefined (reading 'index')
    at new Js (@thatopen_components.js?v=6f57743e:92:62)
    at Js.clone (chunk-NSW2P6WQ.js?v=6f57743e:5400:12)
    at Gi.copy (chunk-NSW2P6WQ.js?v=6f57743e:5425:24)
    at Gi.clone (chunk-NSW2P6WQ.js?v=6f57743e:5400:35)
    at ifc_worker.js?worker…e&type=module:49:24
Screen Shot 2024-07-03 at 14 23 03

Reproduction ▶️

No response

Steps to reproduce 🔢

No response

System Info 💻

.

Used Package Manager 📦

npm

Error Trace/Logs 📃

No response

Validations ✅

agviegas commented 3 months ago

Related to #222. Probably both issues can be solved at the same time. Duplicate from https://github.com/ThatOpen/engine_fragment/issues/18.

agviegas commented 2 months ago

We've implemented fragment cloning (and it can also be used to create fragment subsets).

It's available from @thatopen/components@2.1.17 and @thatopen/fragments@2.1.6. By modifying the IFCLoader tutorial code like this:

async function loadIfc() {
  const file = await fetch(
    "https://thatopen.github.io/engine_components/resources/small.ifc",
  );
  const data = await file.arrayBuffer();
  const buffer = new Uint8Array(data);
  const model = await fragmentIfcLoader.load(buffer);
  model.name = "example";
  world.scene.three.add(model);

  const classifier = components.get(OBC.Classifier);
  classifier.byEntity(model);
  const found = classifier.find({
    entities: ["IFCWALLSTANDARDCASE", "IFCSLAB"],
  });

  const clone = fragments.clone(model, found);
  world.scene.three.add(clone);
  window.addEventListener("keydown", (e) => {
    clone.position.x += 1;
  });

  const map = clone.getFragmentMap([186]);
  const hider = components.get(OBC.Hider);
  hider.set(false, map);
}

I get this:

https://github.com/user-attachments/assets/8fc61ff2-d9b3-4c85-aaa7-eef65ffa3de7