4
$\begingroup$

I'm working on some code to convert a 3d geometry from IFC to gltf/glb. One of the challenges I'm facing with this is that - IFC provides transformations for each primitive separately i.e., if I have a mesh (MeshA) which has 4 primitives, i'm getting a transformation matrix for each of the primitive. And once I construct MeshA using all these primitives, I would like to re-use this mesh in all other nodes where this mesh is referenced and apply a new transformation which I can retrieve from the respective mesh in IFC file.

Below is the available structure of Geometry from IFC File:

IFC (Available)
Mesh 1 primitive A - TransformationA-1
primitive B - TransformationB-1
Mesh 2 primitive A - TransformationA-2
primitive B - TransformationB-2

Below is the expected structure of geometry:

Gltf/Glb (Expected)
Mesh 1 Primitive A + Primitive B
Node 1 Mesh 1 TransformationA-1 + TransformationB-1
Node 2 Mesh 1 TransformationA-2 + TransformationB-2

What I have currently tried is to

  • apply the transformations of each primitive on each of its respective Vertex & Normal arrays to get a new set of arrays with the actual location after applying the transformation.
  • Then I add each primitive to a mesh and then add the mesh into a node

But I'm having to do this to each mesh and create new mesh - instead of referencing the existing mesh (because I don't know the transformation of the entire mesh) - which is increasing the output size significantly.

Can someone help me in understanding how to combine transformations of multiple primitives and apply it to a mesh?

$\endgroup$

1 Answer 1

1
$\begingroup$

In the glTF format, "primitives" are just a way to specify separate draw calls (and hence, separate materials or shader programs) for a single mesh. There is no transform, as you've discovered, applied to a glTF primitive separately from its parent mesh.

I think your best bet here may be to take each IFC "mesh" and make it an empty parent node in glTF, and then take each IFC "primitive" and make it into a glTF child node + mesh + primitive with its transforms applied to the node.

This would mean that each time an IFC mesh is reused, you would possibly need to place multiple child nodes and meshes in glTF. But the raw vertex data wouldn't change per instance, so could be easily reused without duplication.

If you have a substantial number of mesh instances, consider using EXT_mesh_gpu_instancing.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.