Support tessellated polygonal face set for much more efficient files (44kb vs 84kb Suzanne!)

This commit is contained in:
Dion Moult
2020-08-21 18:14:46 +10:00
parent 09dd778f97
commit ff5bc25228
3 changed files with 23 additions and 0 deletions
@@ -2723,6 +2723,25 @@ class IfcExporter():
mesh = representation['raw']
if not representation['is_parametric']:
mesh = representation['raw_object'].evaluated_get(bpy.context.evaluated_depsgraph_get()).to_mesh()
if self.schema == 'IFC2X3' or self.ifc_export_settings.should_force_faceted_brep:
return self.create_faceted_brep(representation, mesh)
return self.create_polygonal_face_set(representation, mesh)
def create_polygonal_face_set(self, representation, mesh):
n_slots = max(1, len(representation['raw_object'].material_slots))
ifc_raw_items = [None] * n_slots
for i, value in enumerate(ifc_raw_items):
ifc_raw_items[i] = []
for polygon in mesh.polygons:
ifc_raw_items[polygon.material_index % n_slots].append(self.file.createIfcIndexedPolygonalFace([v+1 for v in polygon.vertices]))
coordinates = self.file.createIfcCartesianPointList3D([self.convert_si_to_unit(v.co) for v in mesh.vertices])
items = [self.file.createIfcPolygonalFaceSet(coordinates, None, i) for i in ifc_raw_items if i]
return self.file.createIfcShapeRepresentation(
self.ifc_rep_context[representation['context']][representation['subcontext']][
representation['target_view']]['ifc'],
representation['subcontext'], 'Tessellation', items)
def create_faceted_brep(self, representation, mesh):
self.create_vertices(mesh.vertices)
n_slots = max(1, len(representation['raw_object'].material_slots))
ifc_raw_items = [None] * n_slots
@@ -2983,6 +3002,7 @@ class IfcExportSettings:
settings.schema = scene_bim.export_schema
settings.should_use_presentation_style_assignment = scene_bim.export_should_use_presentation_style_assignment
settings.should_guess_quantities = scene_bim.export_should_guess_quantities
settings.should_force_faceted_brep = scene_bim.export_should_force_faceted_brep
settings.context_tree = []
for ifc_context in ['model', 'plan']:
if getattr(scene_bim, 'has_{}_context'.format(ifc_context)):
@@ -1085,6 +1085,7 @@ class BIMProperties(PropertyGroup):
export_has_representations: BoolProperty(name="Export Representations", default=True)
export_should_guess_quantities: BoolProperty(name="Export with Guessed Quantities", default=False)
export_should_use_presentation_style_assignment: BoolProperty(name="Export with Presentation Style Assignment", default=False)
export_should_force_faceted_brep: BoolProperty(name="Export with Faceted Breps", default=False)
import_should_ignore_site_coordinates: BoolProperty(name="Import Ignoring Site Coordinates", default=False)
import_should_ignore_building_coordinates: BoolProperty(name="Import Ignoring Building Coordinates", default=False)
import_should_reset_absolute_coordinates: BoolProperty(name="Import Resetting Absolute Coordinates", default=False)
@@ -1664,6 +1664,8 @@ class BIM_PT_mvd(Panel):
row = layout.row()
row.prop(bim_properties, 'export_should_guess_quantities')
row = layout.row()
row.prop(bim_properties, 'export_should_force_faceted_brep')
row = layout.row()
row.prop(bim_properties, 'import_should_import_type_representations')
row = layout.row()
row.prop(bim_properties, 'import_should_import_curves')