javascripttypescriptbim

Open-bim-components - Global ID/Express ID from Selection


I'm currently working on selecting individual elements within the IFC model. I'm essentially using a ray-caster (SimpleRayCaster) to cast a ray onto the object, which is functioning well. I'm receiving a FragmentMesh as the identified object. How can I retrieve the expressId or global id for this entity that I've intersected, so that I can highlight it individually? Currently, I'm receiving an array of ids that appear to be all the entities of this type. I kindly inquire whether it's possible to achieve this without using the highlighter.

So far I've made a ray-cast and receiving a fragment-mesh (holds a fragment), but without any individual ID.


Solution

  • If you wish to get the ExpressId or GlobalID/Guid you can do the following. Having in mind that the raycast intersection returns this output: enter image description here

    i) You can start by picking the FragmentMesh.uuid prop so you get GUID

    const guid = raycast.object.uuid
    

    Which looks something like this: "ebe4a0e0-e815-4978-8e4b-601fcb711b82"

    ii) for the express Id, there might be different way of getting it. One option is by using the FragmentsGroup which represents your model. Basically, you iterate through its items and find the one which id prop match with the guid from the raycast.

    const fragment = model.items.find(x=>x.id===guid );
    

    Now the ids from the fragment packs your expressIds. The list can be longer than 1 item if it's an instancedMesh object. To get the desired instance you can make use of the raycast output:

    const index = raycast.instanceId;
    const expressId = fragment.ids[index];
    

    Not sure how do you pretend to highlight the mesh by using the expressId or GUID. But you can give it a shot by just setting the fragmentMesh.material.color prop:

    const mat = mesh.material[0] as THREE.MeshLambertMaterial;
    mat.color = new THREE.Color("red");
    

    and when moving on to another selection, you can restore the material like this:

    const mat = mesh.material[0] as THREE.MeshLambertMaterial;
    mat.color = new THREE.Color(1, 1, 1);