Skip to content

Commit cd6c258

Browse files
committed
IFC Clash in the BlenderBIM Add-on now generates snapshots of clashes in BCF
1 parent 0799a78 commit cd6c258

6 files changed

Lines changed: 42 additions & 3 deletions

File tree

src/bcf/bcf/bcfxml.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ def add_viewpoint(self, topic, viewpoint=None):
476476
if viewpoint.snapshot:
477477
topic_filepath = os.path.join(self.filepath, topic.guid)
478478
filepath = os.path.join(topic_filepath, viewpoint.snapshot)
479-
if not os.path.exists(filepath):
479+
if not os.path.exists(filepath) or topic_filepath not in filepath:
480480
filename = viewpoint.guid + "." + viewpoint.snapshot[-3:]
481481
copyfile(viewpoint.snapshot, os.path.join(topic_filepath, filename))
482482
viewpoint.snapshot = filename

src/ifcblenderexport/blenderbim/bim/module/bcf/operator.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ class NewBcfProject(bpy.types.Operator):
1010
bl_label = "New BCF Project"
1111

1212
def execute(self, context):
13+
bpy.context.scene.BCFProperties.is_loaded = False
1314
bcfxml = bcfstore.BcfStore.get_bcfxml()
1415
bcfxml.new_project()
1516
bpy.ops.bim.load_bcf_project()
17+
bpy.context.scene.BCFProperties.is_loaded = True
1618
return {"FINISHED"}
1719

1820

@@ -22,6 +24,7 @@ class LoadBcfProject(bpy.types.Operator):
2224
filepath: bpy.props.StringProperty(subtype="FILE_PATH")
2325

2426
def execute(self, context):
27+
bpy.context.scene.BCFProperties.is_loaded = False
2528
bcfxml = bcfstore.BcfStore.get_bcfxml()
2629
if self.filepath:
2730
bcfxml.get_project(self.filepath)

src/ifcblenderexport/blenderbim/bim/operator.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,6 +1588,28 @@ def execute(self, context):
15881588
settings.logger = logging.getLogger("Clash")
15891589
settings.logger.setLevel(logging.DEBUG)
15901590
ifc_clasher = ifcclash.IfcClasher(settings)
1591+
1592+
if bpy.context.scene.BIMProperties.should_create_clash_snapshots:
1593+
def get_viewpoint_snapshot(self, viewpoint, mat):
1594+
camera = bpy.data.objects.get('IFC Clash Camera')
1595+
if not camera:
1596+
camera = bpy.data.objects.new("IFC Clash Camera", bpy.data.cameras.new("IFC Clash Camera"))
1597+
bpy.context.scene.collection.objects.link(camera)
1598+
camera.matrix_world = Matrix(mat)
1599+
bpy.context.scene.camera = camera
1600+
camera.data.angle = radians(60)
1601+
area = next(area for area in bpy.context.screen.areas if area.type == "VIEW_3D")
1602+
area.spaces[0].region_3d.view_perspective = "CAMERA"
1603+
area.spaces[0].shading.show_xray = True
1604+
bpy.context.scene.render.resolution_x = 480
1605+
bpy.context.scene.render.resolution_y = 270
1606+
bpy.context.scene.render.image_settings.file_format = "PNG"
1607+
bpy.context.scene.render.filepath = os.path.join(bpy.context.scene.BIMProperties.data_dir, "snapshot.png")
1608+
bpy.ops.render.opengl(write_still=True)
1609+
return bpy.context.scene.render.filepath
1610+
1611+
ifcclash.IfcClasher.get_viewpoint_snapshot = get_viewpoint_snapshot
1612+
15911613
ifc_clasher.clash_sets = []
15921614
for clash_set in bpy.context.scene.BIMProperties.clash_sets:
15931615
self.a = []

src/ifcblenderexport/blenderbim/bim/prop.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,6 +1358,7 @@ class BIMProperties(PropertyGroup):
13581358
blender_clash_set_a: CollectionProperty(name="Blender Clash Set A", type=StrProperty)
13591359
blender_clash_set_b: CollectionProperty(name="Blender Clash Set B", type=StrProperty)
13601360
clash_sets: CollectionProperty(name="Clash Sets", type=ClashSet)
1361+
should_create_clash_snapshots: BoolProperty(name="Create Snapshots", default=True)
13611362
clash_results_path: StringProperty(name="Clash Results Path")
13621363
smart_grouped_clashes_path: StringProperty(name="Smart Grouped Clashes Path")
13631364
active_clash_set_index: IntProperty(name="Active Clash Set Index")

src/ifcblenderexport/blenderbim/bim/ui.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2172,9 +2172,9 @@ def draw(self, context):
21722172
row.prop(source, "selector", text="")
21732173

21742174
row = layout.row()
2175+
row.prop(props, "should_create_clash_snapshots")
2176+
row = layout.row(align=True)
21752177
row.operator("bim.execute_ifc_clash")
2176-
2177-
row = layout.row()
21782178
row.operator("bim.select_ifc_clash_results")
21792179

21802180

src/ifcclash/ifcclash.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,25 @@ def export_bcfxml(self):
187187
viewpoint.perspective_camera.camera_up_vector.x = mat[0][1]
188188
viewpoint.perspective_camera.camera_up_vector.y = mat[1][1]
189189
viewpoint.perspective_camera.camera_up_vector.z = mat[2][1]
190+
viewpoint.components = bcf.data.Components()
191+
c1 = bcf.data.Component()
192+
c1.ifc_guid = clash["a_global_id"]
193+
c2 = bcf.data.Component()
194+
c2.ifc_guid = clash["b_global_id"]
195+
viewpoint.components.selection.append(c1)
196+
viewpoint.components.selection.append(c2)
197+
viewpoint.components.visibility = bcf.data.ComponentVisibility()
198+
viewpoint.components.visibility.default_visibility = True
199+
viewpoint.snapshot = self.get_viewpoint_snapshot(viewpoint, mat)
190200
bcfxml.add_viewpoint(topic, viewpoint)
191201
if i == 0:
192202
bcfxml.save_project(self.settings.output)
193203
else:
194204
bcfxml.save_project(self.settings.output + f".{i}")
195205

206+
def get_viewpoint_snapshot(self, viewpoint, mat):
207+
return None # Possible to overload this function in a GUI application if used as a library
208+
196209
# https://blender.stackexchange.com/questions/68834/recreate-to-track-quat-with-two-vectors-using-python/141706#141706
197210
def get_track_to_matrix(self, camera_position, target_position):
198211
camera_direction = camera_position - target_position

0 commit comments

Comments
 (0)