Walls and slabs (or any vertical or horziontal layer) now auto recalculate origins after editing

This commit is contained in:
Dion Moult
2021-08-15 11:05:47 +10:00
parent 184081ebaf
commit 1515ef98b7
2 changed files with 48 additions and 32 deletions
@@ -20,10 +20,9 @@ def element_listener(element, obj):
def mode_callback(obj, data): def mode_callback(obj, data):
for obj in bpy.context.selected_objects + [bpy.context.active_object]: for obj in set(bpy.context.selected_objects + [bpy.context.active_object]):
if ( if (
obj.mode != "EDIT" not obj.data
or not obj.data
or not isinstance(obj.data, (bpy.types.Mesh, bpy.types.Curve, bpy.types.TextCurve)) or not isinstance(obj.data, (bpy.types.Mesh, bpy.types.Curve, bpy.types.TextCurve))
or not obj.BIMObjectProperties.ifc_definition_id or not obj.BIMObjectProperties.ifc_definition_id
or not bpy.context.scene.BIMProjectProperties.is_authoring or not bpy.context.scene.BIMProjectProperties.is_authoring
@@ -33,27 +32,36 @@ def mode_callback(obj, data):
parametric = ifcopenshell.util.element.get_psets(product).get("EPset_Parametric") parametric = ifcopenshell.util.element.get_psets(product).get("EPset_Parametric")
if not parametric or parametric["Engine"] != "BlenderBIM.DumbLayer3": if not parametric or parametric["Engine"] != "BlenderBIM.DumbLayer3":
return return
IfcStore.edited_objs.add(obj) if obj.mode == "EDIT":
modifier = [m for m in obj.modifiers if m.type == "SOLIDIFY"] IfcStore.edited_objs.add(obj)
if modifier: modifier = [m for m in obj.modifiers if m.type == "SOLIDIFY"]
return if modifier:
depth = obj.dimensions.z return
bm = bmesh.from_edit_mesh(obj.data) depth = obj.dimensions.z
bmesh.ops.dissolve_limit(bm, angle_limit=pi / 180 * 1, verts=bm.verts, edges=bm.edges) bm = bmesh.from_edit_mesh(obj.data)
bm.faces.ensure_lookup_table() bmesh.ops.dissolve_limit(bm, angle_limit=pi / 180 * 1, verts=bm.verts, edges=bm.edges)
non_bottom_faces = [] bm.faces.ensure_lookup_table()
for face in bm.faces: non_bottom_faces = []
if face.normal.z > -0.9: for face in bm.faces:
non_bottom_faces.append(face) if face.normal.z > -0.9:
else: non_bottom_faces.append(face)
face.normal_flip() else:
bmesh.ops.delete(bm, geom=non_bottom_faces, context="FACES") face.normal_flip()
bmesh.update_edit_mesh(obj.data) bmesh.ops.delete(bm, geom=non_bottom_faces, context="FACES")
bm.free() bmesh.update_edit_mesh(obj.data)
modifier = obj.modifiers.new("Slab Depth", "SOLIDIFY") bm.free()
modifier.use_even_offset = True modifier = obj.modifiers.new("Slab Depth", "SOLIDIFY")
modifier.offset = 1 modifier.use_even_offset = True
modifier.thickness = depth modifier.offset = 1
modifier.thickness = depth
else:
new_origin = obj.matrix_world @ Vector(obj.bound_box[0])
obj.data.transform(
Matrix.Translation(
(obj.matrix_world.inverted().to_quaternion() @ (obj.matrix_world.translation - new_origin))
)
)
obj.matrix_world.translation = new_origin
def ensure_solid(usecase_path, ifc_file, settings): def ensure_solid(usecase_path, ifc_file, settings):
@@ -22,8 +22,7 @@ def element_listener(element, obj):
def mode_callback(obj, data): def mode_callback(obj, data):
for obj in set(bpy.context.selected_objects + [bpy.context.active_object]): for obj in set(bpy.context.selected_objects + [bpy.context.active_object]):
if ( if (
obj.mode != "EDIT" not obj.data
or not obj.data
or not isinstance(obj.data, (bpy.types.Mesh, bpy.types.Curve, bpy.types.TextCurve)) or not isinstance(obj.data, (bpy.types.Mesh, bpy.types.Curve, bpy.types.TextCurve))
or not obj.BIMObjectProperties.ifc_definition_id or not obj.BIMObjectProperties.ifc_definition_id
or not bpy.context.scene.BIMProjectProperties.is_authoring or not bpy.context.scene.BIMProjectProperties.is_authoring
@@ -33,12 +32,21 @@ def mode_callback(obj, data):
parametric = ifcopenshell.util.element.get_psets(product).get("EPset_Parametric") parametric = ifcopenshell.util.element.get_psets(product).get("EPset_Parametric")
if not parametric or parametric["Engine"] != "BlenderBIM.DumbLayer2": if not parametric or parametric["Engine"] != "BlenderBIM.DumbLayer2":
return return
bpy.ops.bim.dynamically_void_product(obj=obj.name) if obj.mode == "EDIT":
IfcStore.edited_objs.add(obj) bpy.ops.bim.dynamically_void_product(obj=obj.name)
bm = bmesh.from_edit_mesh(obj.data) IfcStore.edited_objs.add(obj)
bmesh.ops.dissolve_limit(bm, angle_limit=pi / 180 * 1, verts=bm.verts, edges=bm.edges) bm = bmesh.from_edit_mesh(obj.data)
bmesh.update_edit_mesh(obj.data) bmesh.ops.dissolve_limit(bm, angle_limit=pi / 180 * 1, verts=bm.verts, edges=bm.edges)
bm.free() bmesh.update_edit_mesh(obj.data)
bm.free()
else:
new_origin = obj.matrix_world @ Vector(obj.bound_box[0])
obj.data.transform(
Matrix.Translation(
(obj.matrix_world.inverted().to_quaternion() @ (obj.matrix_world.translation - new_origin))
)
)
obj.matrix_world.translation = new_origin
class JoinWall(bpy.types.Operator): class JoinWall(bpy.types.Operator):