<p>In the glTF format, &quot;primitives&quot; 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.</p>
<p>I think your best bet here may be to take each IFC &quot;mesh&quot; and make it an empty parent node in glTF, and then take each IFC &quot;primitive&quot; and make it into a glTF child node + mesh + primitive with its transforms applied to the node.</p>
<p>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.</p>
<p>If you have a substantial number of mesh instances, consider using <a href="https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Vendor/EXT_mesh_gpu_instancing" rel="nofollow noreferrer">EXT_mesh_gpu_instancing</a>.</p>

CC BY-SA 4.0
2022-11-29T21:40:10.390Z
2022-11-29T21:40:10.390Z
emackey
<p>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.</p>
<p>Below is the <strong>available</strong> structure of Geometry from IFC File:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th></th>
<th>IFC (Available)</th>
</tr>
</thead>
<tbody>
<tr>
<td>Mesh 1</td>
<td>primitive A -   TransformationA-1 <br> primitive B - TransformationB-1</td>
</tr>
<tr>
<td>Mesh 2</td>
<td>primitive A -   TransformationA-2 <br> primitive B - TransformationB-2</td>
</tr>
</tbody>
</table>
</div>
<p>Below is the <strong>expected</strong> structure of geometry:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th></th>
<th></th>
<th>Gltf/Glb (Expected)</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td>Mesh 1</td>
<td>Primitive A + Primitive B</td>
</tr>
<tr>
<td>Node 1</td>
<td>Mesh 1</td>
<td>TransformationA-1 + TransformationB-1</td>
</tr>
<tr>
<td>Node 2</td>
<td>Mesh 1</td>
<td>TransformationA-2 + TransformationB-2</td>
</tr>
</tbody>
</table>
</div><hr />
<p>What I have currently tried is to</p>
<ul>
<li>apply the transformations of each primitive on each of its respective Vertex &amp; Normal arrays to get a new set of arrays with the actual location after applying the transformation.</li>
<li>Then I add each primitive to a mesh and then add the mesh into a node</li>
</ul>
<p>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.</p>
<p>Can someone help me in understanding how to combine transformations of multiple primitives and apply it to a mesh?</p>

<transformations><computational-geometry><javascript><linear-algebra><gltf>
How to apply transformation matrices from multiple primitives on a mesh
Gangula
# How to apply transformation matrices from multiple primitives on a mesh

(Asked by: username_0 on 2022-11-28)

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?

**Tags:** transformations, computational-geometry, javascript, linear-algebra, gltf


---

## 1 answers

### Answer by username_1 on 2022-11-29. Score: 1

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](https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Vendor/EXT_mesh_gpu_instancing).


---

