mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-14 19:34:34 +00:00
IFC Clash in the BlenderBIM Add-on now generates snapshots of clashes in BCF
This commit is contained in:
@@ -476,7 +476,7 @@ class BcfXml:
|
||||
if viewpoint.snapshot:
|
||||
topic_filepath = os.path.join(self.filepath, topic.guid)
|
||||
filepath = os.path.join(topic_filepath, viewpoint.snapshot)
|
||||
if not os.path.exists(filepath):
|
||||
if not os.path.exists(filepath) or topic_filepath not in filepath:
|
||||
filename = viewpoint.guid + "." + viewpoint.snapshot[-3:]
|
||||
copyfile(viewpoint.snapshot, os.path.join(topic_filepath, filename))
|
||||
viewpoint.snapshot = filename
|
||||
|
||||
@@ -10,9 +10,11 @@ class NewBcfProject(bpy.types.Operator):
|
||||
bl_label = "New BCF Project"
|
||||
|
||||
def execute(self, context):
|
||||
bpy.context.scene.BCFProperties.is_loaded = False
|
||||
bcfxml = bcfstore.BcfStore.get_bcfxml()
|
||||
bcfxml.new_project()
|
||||
bpy.ops.bim.load_bcf_project()
|
||||
bpy.context.scene.BCFProperties.is_loaded = True
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
@@ -22,6 +24,7 @@ class LoadBcfProject(bpy.types.Operator):
|
||||
filepath: bpy.props.StringProperty(subtype="FILE_PATH")
|
||||
|
||||
def execute(self, context):
|
||||
bpy.context.scene.BCFProperties.is_loaded = False
|
||||
bcfxml = bcfstore.BcfStore.get_bcfxml()
|
||||
if self.filepath:
|
||||
bcfxml.get_project(self.filepath)
|
||||
|
||||
@@ -1588,6 +1588,28 @@ class ExecuteIfcClash(bpy.types.Operator):
|
||||
settings.logger = logging.getLogger("Clash")
|
||||
settings.logger.setLevel(logging.DEBUG)
|
||||
ifc_clasher = ifcclash.IfcClasher(settings)
|
||||
|
||||
if bpy.context.scene.BIMProperties.should_create_clash_snapshots:
|
||||
def get_viewpoint_snapshot(self, viewpoint, mat):
|
||||
camera = bpy.data.objects.get('IFC Clash Camera')
|
||||
if not camera:
|
||||
camera = bpy.data.objects.new("IFC Clash Camera", bpy.data.cameras.new("IFC Clash Camera"))
|
||||
bpy.context.scene.collection.objects.link(camera)
|
||||
camera.matrix_world = Matrix(mat)
|
||||
bpy.context.scene.camera = camera
|
||||
camera.data.angle = radians(60)
|
||||
area = next(area for area in bpy.context.screen.areas if area.type == "VIEW_3D")
|
||||
area.spaces[0].region_3d.view_perspective = "CAMERA"
|
||||
area.spaces[0].shading.show_xray = True
|
||||
bpy.context.scene.render.resolution_x = 480
|
||||
bpy.context.scene.render.resolution_y = 270
|
||||
bpy.context.scene.render.image_settings.file_format = "PNG"
|
||||
bpy.context.scene.render.filepath = os.path.join(bpy.context.scene.BIMProperties.data_dir, "snapshot.png")
|
||||
bpy.ops.render.opengl(write_still=True)
|
||||
return bpy.context.scene.render.filepath
|
||||
|
||||
ifcclash.IfcClasher.get_viewpoint_snapshot = get_viewpoint_snapshot
|
||||
|
||||
ifc_clasher.clash_sets = []
|
||||
for clash_set in bpy.context.scene.BIMProperties.clash_sets:
|
||||
self.a = []
|
||||
|
||||
@@ -1358,6 +1358,7 @@ class BIMProperties(PropertyGroup):
|
||||
blender_clash_set_a: CollectionProperty(name="Blender Clash Set A", type=StrProperty)
|
||||
blender_clash_set_b: CollectionProperty(name="Blender Clash Set B", type=StrProperty)
|
||||
clash_sets: CollectionProperty(name="Clash Sets", type=ClashSet)
|
||||
should_create_clash_snapshots: BoolProperty(name="Create Snapshots", default=True)
|
||||
clash_results_path: StringProperty(name="Clash Results Path")
|
||||
smart_grouped_clashes_path: StringProperty(name="Smart Grouped Clashes Path")
|
||||
active_clash_set_index: IntProperty(name="Active Clash Set Index")
|
||||
|
||||
@@ -2172,9 +2172,9 @@ class BIM_PT_ifcclash(Panel):
|
||||
row.prop(source, "selector", text="")
|
||||
|
||||
row = layout.row()
|
||||
row.prop(props, "should_create_clash_snapshots")
|
||||
row = layout.row(align=True)
|
||||
row.operator("bim.execute_ifc_clash")
|
||||
|
||||
row = layout.row()
|
||||
row.operator("bim.select_ifc_clash_results")
|
||||
|
||||
|
||||
|
||||
@@ -187,12 +187,25 @@ class IfcClasher:
|
||||
viewpoint.perspective_camera.camera_up_vector.x = mat[0][1]
|
||||
viewpoint.perspective_camera.camera_up_vector.y = mat[1][1]
|
||||
viewpoint.perspective_camera.camera_up_vector.z = mat[2][1]
|
||||
viewpoint.components = bcf.data.Components()
|
||||
c1 = bcf.data.Component()
|
||||
c1.ifc_guid = clash["a_global_id"]
|
||||
c2 = bcf.data.Component()
|
||||
c2.ifc_guid = clash["b_global_id"]
|
||||
viewpoint.components.selection.append(c1)
|
||||
viewpoint.components.selection.append(c2)
|
||||
viewpoint.components.visibility = bcf.data.ComponentVisibility()
|
||||
viewpoint.components.visibility.default_visibility = True
|
||||
viewpoint.snapshot = self.get_viewpoint_snapshot(viewpoint, mat)
|
||||
bcfxml.add_viewpoint(topic, viewpoint)
|
||||
if i == 0:
|
||||
bcfxml.save_project(self.settings.output)
|
||||
else:
|
||||
bcfxml.save_project(self.settings.output + f".{i}")
|
||||
|
||||
def get_viewpoint_snapshot(self, viewpoint, mat):
|
||||
return None # Possible to overload this function in a GUI application if used as a library
|
||||
|
||||
# https://blender.stackexchange.com/questions/68834/recreate-to-track-quat-with-two-vectors-using-python/141706#141706
|
||||
def get_track_to_matrix(self, camera_position, target_position):
|
||||
camera_direction = camera_position - target_position
|
||||
|
||||
Reference in New Issue
Block a user