You've already forked stocker_helper
Fix: Issue with boundary alignment and size
This commit is contained in:
+26
-18
@@ -21,10 +21,18 @@ def resolve_to_mesh_objects(obj):
|
||||
return []
|
||||
|
||||
|
||||
def calculate_global_bounds(selected_objects):
|
||||
def calculate_global_bounds(selected_objects, parent=None):
|
||||
if not selected_objects:
|
||||
return None
|
||||
|
||||
# Determine target coordinate space. When parent is given, compute bounds
|
||||
# in the parent's local space so the boundary size matches the parent's
|
||||
# orientation (not world-space AABB which grows with rotation).
|
||||
if parent:
|
||||
target_matrix = parent.matrix_world.inverted_safe()
|
||||
else:
|
||||
target_matrix = mathutils.Matrix.Identity(4)
|
||||
|
||||
min_x, min_y, min_z = float('inf'), float('inf'), float('inf')
|
||||
max_x, max_y, max_z = float('-inf'), float('-inf'), float('-inf')
|
||||
|
||||
@@ -37,25 +45,22 @@ def calculate_global_bounds(selected_objects):
|
||||
for source_obj in mesh_objects:
|
||||
found_any_mesh = True
|
||||
|
||||
# Get world-space corners (use bound_box_world when available)
|
||||
if hasattr(source_obj, 'bound_box_world') and source_obj.bound_box_world:
|
||||
bbw = source_obj.bound_box_world
|
||||
for corner in bbw:
|
||||
min_x = min(min_x, corner.x)
|
||||
min_y = min(min_y, corner.y)
|
||||
min_z = min(min_z, corner.z)
|
||||
max_x = max(max_x, corner.x)
|
||||
max_y = max(max_y, corner.y)
|
||||
max_z = max(max_z, corner.z)
|
||||
world_corners = source_obj.bound_box_world
|
||||
else:
|
||||
matrix = source_obj.matrix_world
|
||||
for corner in source_obj.bound_box:
|
||||
world_corner = matrix @ mathutils.Vector(corner)
|
||||
min_x = min(min_x, world_corner.x)
|
||||
min_y = min(min_y, world_corner.y)
|
||||
min_z = min(min_z, world_corner.z)
|
||||
max_x = max(max_x, world_corner.x)
|
||||
max_y = max(max_y, world_corner.y)
|
||||
max_z = max(max_z, world_corner.z)
|
||||
world_corners = [matrix @ mathutils.Vector(corner) for corner in source_obj.bound_box]
|
||||
|
||||
# Transform to target coordinate space and update AABB
|
||||
for corner in world_corners:
|
||||
target_corner = target_matrix @ corner
|
||||
min_x = min(min_x, target_corner.x)
|
||||
min_y = min(min_y, target_corner.y)
|
||||
min_z = min(min_z, target_corner.z)
|
||||
max_x = max(max_x, target_corner.x)
|
||||
max_y = max(max_y, target_corner.y)
|
||||
max_z = max(max_z, target_corner.z)
|
||||
|
||||
if not found_any_mesh:
|
||||
return None
|
||||
@@ -116,7 +121,10 @@ def create_aligned_boundary_cube(bounds, parent=None, mode=None):
|
||||
mesh.from_pydata(verts, [], faces)
|
||||
mesh.update()
|
||||
|
||||
# Parent to selected object so boundary follows instances
|
||||
# Parent to selected object so boundary follows instances.
|
||||
# Bounds are already in parent-local space (computed by
|
||||
# calculate_global_bounds with parent matrix), so location values are
|
||||
# directly usable after parenting — no additional conversion needed.
|
||||
if parent:
|
||||
obj.parent = parent
|
||||
|
||||
|
||||
Reference in New Issue
Block a user