fixed issue importing uv failing for some IfcPolygonalFaceSets

It was failing with IfcIndexedTriangleTextureMap + IfcPolygonalFaceSet
This commit is contained in:
Andrej730
2023-11-28 12:16:25 +05:00
parent c7f6a5e621
commit a5bb458d3d
+14 -9
View File
@@ -157,23 +157,28 @@ class MaterialCreator:
# remap the faceset CoordList index to the vertices in blender mesh # remap the faceset CoordList index to the vertices in blender mesh
coordinates_remap = [] coordinates_remap = []
si_conversion = ifcopenshell.util.unit.calculate_unit_scale(self.ifc_importer.file) si_conversion = ifcopenshell.util.unit.calculate_unit_scale(self.ifc_importer.file)
for co in coordinates.MappedTo.Coordinates.CoordList: faceset = coordinates.MappedTo
for co in faceset.Coordinates.CoordList:
co = mathutils.Vector(co) * si_conversion co = mathutils.Vector(co) * si_conversion
index = next(v.index for v in bm.verts if (v.co - co).length_squared < 1e-5) index = next(v.index for v in bm.verts if (v.co - co).length_squared < 1e-5)
coordinates_remap.append(index) coordinates_remap.append(index)
faces_remap = None # ifc indices start with 1
texture_map = None remap_verts_to_blender = lambda ifc_verts: [coordinates_remap[i - 1] for i in ifc_verts]
# faces_remap - ifc faces described using blender verts indices
# IFC4.3+
if coordinates.is_a("IfcIndexedPolygonalTextureMap"): if coordinates.is_a("IfcIndexedPolygonalTextureMap"):
faces_remap = [ faces_remap = [
[coordinates_remap[i - 1] for i in tex_coord_index.TexCoordsOf.CoordIndex] remap_verts_to_blender(tex_coord_index.TexCoordsOf.CoordIndex)
for tex_coord_index in coordinates.TexCoordIndices for tex_coord_index in coordinates.TexCoordIndices
] ]
texture_map = [tex_coord_index.TexCoordIndex for tex_coord_index in coordinates.TexCoordIndices] texture_map = [tex_coord_index.TexCoordIndex for tex_coord_index in coordinates.TexCoordIndices]
elif coordinates.is_a("IfcIndexedTriangleTextureMap"): else: # IfcIndexedTriangleTextureMap
faces_remap = [ if faceset.is_a("IfcTriangulatedFaceSet"):
[coordinates_remap[i - 1] for i in triangle_face] for triangle_face in coordinates.MappedTo.CoordIndex faces_remap = [remap_verts_to_blender(triangle_face) for triangle_face in faceset.CoordIndex]
] else: # IfcPolygonalFaceSet
faces_remap = [remap_verts_to_blender(triangle_face.CoordIndex) for triangle_face in faceset.Faces]
texture_map = coordinates.TexCoordIndex texture_map = coordinates.TexCoordIndex
# apply uv to each face # apply uv to each face
@@ -183,7 +188,7 @@ class MaterialCreator:
# remap TexCoordIndex as the loop start may different from blender face # remap TexCoordIndex as the loop start may different from blender face
texCoordIndex = next( texCoordIndex = next(
[tex_coord_index[face_remap.index(i)] for i in face] [tex_coord_index[face_remap.index(i)] for i in face]
for tex_coord_index, face_remap in zip(texture_map, faces_remap) for tex_coord_index, face_remap in zip(texture_map, faces_remap, strict=True)
if all(i in face_remap for i in face) if all(i in face_remap for i in face)
) )
# apply uv to each loop # apply uv to each loop