UV coordinates for triangulated face sets are now saved in IFC.

This commit is contained in:
Dion Moult
2022-02-08 15:32:03 +11:00
parent 3e4b1d95cb
commit d03685abfa
7 changed files with 74 additions and 3 deletions
@@ -40,6 +40,7 @@ class Usecase:
"unit_scale": None, # A scale factor to apply for all vectors in case the unit is different
"should_force_faceted_brep": False, # If we should force faceted breps for meshes
"should_force_triangulation": False, # If we should force triangulation for meshes
"should_generate_uvs": False, # If UV coordinates should also be generated
# Possible IFC representation classes:
# IfcExtrudedAreaSolid/IfcRectangleProfileDef
# IfcExtrudedAreaSolid/IfcCircleProfileDef
@@ -505,16 +506,43 @@ class Usecase:
def create_triangulated_face_set(self):
ifc_raw_items = [None] * self.settings["total_items"]
if self.settings["should_generate_uvs"]:
ifc_raw_uv_items = [None] * self.settings["total_items"]
for i, value in enumerate(ifc_raw_items):
ifc_raw_items[i] = []
if self.settings["should_generate_uvs"]:
ifc_raw_uv_items[i] = []
for polygon in self.settings["geometry"].polygons:
ifc_raw_items[polygon.material_index % self.settings["total_items"]].append(
[v + 1 for v in polygon.vertices]
)
if self.settings["should_generate_uvs"]:
ifc_raw_uv_items[polygon.material_index % self.settings["total_items"]].append(
[uv + 1 for uv in polygon.loop_indices]
)
coordinates = self.file.createIfcCartesianPointList3D(
[self.convert_si_to_unit(v.co) for v in self.settings["geometry"].vertices]
)
items = [self.file.createIfcTriangulatedFaceSet(coordinates, None, None, i) for i in ifc_raw_items if i]
if self.settings["should_generate_uvs"]:
# Blender supports multiple UV layers. We don't. Too bad.
tex_coords = self.file.createIfcTextureVertexList(
[tuple(x.uv) for x in self.settings["geometry"].uv_layers[0].data]
)
items = []
for i, coord_index in enumerate(ifc_raw_items):
if not coord_index:
continue
tex_coords_index = ifc_raw_uv_items[i]
face_set = self.file.createIfcTriangulatedFaceSet(coordinates, None, None, coord_index)
texture_map = self.file.createIfcIndexedTriangleTextureMap(
MappedTo=face_set, TexCoords=tex_coords, TexCoordIndex=tex_coords_index
)
items.append(face_set)
else:
items = [self.file.createIfcTriangulatedFaceSet(coordinates, None, None, i) for i in ifc_raw_items if i]
return self.file.createIfcShapeRepresentation(
self.settings["context"],
self.settings["context"].ContextIdentifier,