mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-20 15:08:51 +00:00
Refactor enable_constraints for performance reasons.
`context.view_layer.update()` was being called for every object in the loop. Now it is just called after all the constraints are enabled.
This commit is contained in:
committed by
Bruno Perdigão
parent
5ebaaa6c8c
commit
f6c34ac196
@@ -123,25 +123,27 @@ class Aggregate(bonsai.core.tool.Aggregate):
|
|||||||
bpy.ops.constraint.apply(constraint=constraint.name)
|
bpy.ops.constraint.apply(constraint=constraint.name)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def disable_constraints(cls, part: bpy.types.Object):
|
def disable_constraints(cls, objs: list[bpy.types.Object]):
|
||||||
# Disable constraints while keeping parts in the same location
|
# Disable constraints while keeping parts in the same location
|
||||||
matrix = part.matrix_world.copy()
|
for obj in objs:
|
||||||
constraint = next((c for c in part.constraints if c.type == "CHILD_OF"), None)
|
matrix = obj.matrix_world.copy()
|
||||||
if constraint:
|
constraint = next((c for c in obj.constraints if c.type == "CHILD_OF"), None)
|
||||||
constraint.enabled = False
|
if constraint:
|
||||||
part.matrix_world = matrix
|
constraint.enabled = False
|
||||||
|
obj.matrix_world = matrix
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def enable_constraints(cls, part: bpy.types.Object):
|
def enable_constraints(cls, objs: list[bpy.types.Object]):
|
||||||
# Enable constraints while keeping parts in the same location
|
# Enable constraints while keeping parts in the same location
|
||||||
constraint = next((c for c in part.constraints if c.type == "CHILD_OF"), None)
|
for obj in objs:
|
||||||
if constraint:
|
constraint = next((c for c in obj.constraints if c.type == "CHILD_OF"), None)
|
||||||
constraint.enabled = True
|
if constraint:
|
||||||
|
constraint.enabled = True
|
||||||
bpy.context.view_layer.update()
|
bpy.context.view_layer.update()
|
||||||
diff = part.matrix_world.translation - part.location
|
for obj in objs:
|
||||||
part.location -= diff
|
diff = obj.matrix_world.translation - obj.location
|
||||||
|
obj.location -= diff
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_aggregate_mode(cls):
|
def get_aggregate_mode(cls):
|
||||||
return bpy.context.scene.BIMAggregateProperties.in_aggregate_mode
|
return bpy.context.scene.BIMAggregateProperties.in_aggregate_mode
|
||||||
@@ -178,7 +180,8 @@ class Aggregate(bonsai.core.tool.Aggregate):
|
|||||||
else:
|
else:
|
||||||
editing_obj = props.editing_objects.add()
|
editing_obj = props.editing_objects.add()
|
||||||
editing_obj.obj = obj.original
|
editing_obj.obj = obj.original
|
||||||
tool.Aggregate.disable_constraints(obj.original)
|
|
||||||
|
tool.Aggregate.disable_constraints([o.obj for o in props.editing_objects])
|
||||||
|
|
||||||
props.in_aggregate_mode = True
|
props.in_aggregate_mode = True
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
@@ -196,9 +199,7 @@ class Aggregate(bonsai.core.tool.Aggregate):
|
|||||||
|
|
||||||
parts = ifcopenshell.util.element.get_parts(tool.Ifc.get_entity(props.editing_aggregate))
|
parts = ifcopenshell.util.element.get_parts(tool.Ifc.get_entity(props.editing_aggregate))
|
||||||
objs = [tool.Ifc.get_object(part) for part in parts]
|
objs = [tool.Ifc.get_object(part) for part in parts]
|
||||||
for obj in objs:
|
tool.Aggregate.enable_constraints(objs)
|
||||||
tool.Aggregate.enable_constraints(obj)
|
|
||||||
|
|
||||||
if context.space_data.local_view:
|
if context.space_data.local_view:
|
||||||
bpy.ops.view3d.localview()
|
bpy.ops.view3d.localview()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user