engine_components icon indicating copy to clipboard operation
engine_components copied to clipboard

Colorizing objects with IfcGUID

Open lanjoni opened this issue 1 year ago • 3 comments

How can I set a color inside components based on IfcGUID of an element? The purpose is to correct colors inside the project or set a new color to a specific object. Is there any way to do that?

Thanks in advance for the help!

lanjoni avatar Feb 16 '24 21:02 lanjoni

I have the same problem, can anyone help us?

Ujs74wiop6 avatar Feb 16 '24 21:02 Ujs74wiop6

I might need this feature too. Keep you posted if I come up with something

MiguelG97 avatar Feb 24 '24 04:02 MiguelG97

@lanjoni would you mind posting this thread in stackoverflow? I would be more than happy to provide an answer there!

MiguelG97 avatar Mar 20 '24 16:03 MiguelG97

This is a duplicate of #262. The latest version of the API allows to work with IFC GlobalIds and to colorize fragments easily. For instance, to colorize a specific item given its GlobalID, I can modify the load function from the IFCLoader tutorial 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 globalID = "2idC0G3ezCdhA9WVjWe$4F";
  const expressID = model.globalToExpressIDs.get(globalID);
  const red = new THREE.Color(1, 0, 0);
  if (expressID !== undefined) {
    const map = model.getFragmentMap([expressID]);
    for (const fragID in map) {
      const fragment = fragments.list.get(fragID);
      if (!fragment) continue;
      const ids = map[fragID];
      fragment.setColor(red, ids);
    }
  }
}

And I get this result:

https://github.com/ThatOpen/engine_components/assets/56475338/086cd145-d8f2-4ab0-9bc0-70479347cdd9

agviegas avatar Jul 04 '24 08:07 agviegas