From 57bc1cae5d930972104d39dac75ac04168de7e6c Mon Sep 17 00:00:00 2001 From: Pratik Borhade Date: Fri, 5 Jan 2024 16:08:41 +0530 Subject: [PATCH 1/2] 3D Pie menu: Support pivotbottom for selected objects Operator is currently changing origin to geometry center of selected objects but then only calculates bottom for active object. To make it consistent with other origin_set operators, edit pivot of selected objects for this operator as well. Fixes #105091 --- space_view3d_pie_menus/pie_origin.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/space_view3d_pie_menus/pie_origin.py b/space_view3d_pie_menus/pie_origin.py index 5c6070adf..02656c5fa 100644 --- a/space_view3d_pie_menus/pie_origin.py +++ b/space_view3d_pie_menus/pie_origin.py @@ -59,19 +59,20 @@ class PIE_OT_PivotBottom(Operator): def execute(self, context): bpy.ops.object.transform_apply(location=True, rotation=True, scale=True) bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY') - o = context.active_object + init = 0 - for x in o.data.vertices: - if init == 0: - a = x.co.z - init = 1 - elif x.co.z < a: - a = x.co.z + for ob in context.selected_objects: + for x in ob.data.vertices: + if init == 0: + a = x.co.z + init = 1 + elif x.co.z < a: + a = x.co.z - for x in o.data.vertices: - x.co.z -= a + for x in ob.data.vertices: + x.co.z -= a - o.location.z += a + ob.location.z += a return {'FINISHED'} -- 2.30.2 From ad518971627119f175fa46e944f43132280463e4 Mon Sep 17 00:00:00 2001 From: Pratik Borhade Date: Wed, 10 Jan 2024 16:16:50 +0530 Subject: [PATCH 2/2] Support pivotbottom edit and move origin calculation in new fn --- space_view3d_pie_menus/pie_origin.py | 42 +++++++++++++--------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/space_view3d_pie_menus/pie_origin.py b/space_view3d_pie_menus/pie_origin.py index 02656c5fa..1fde987df 100644 --- a/space_view3d_pie_menus/pie_origin.py +++ b/space_view3d_pie_menus/pie_origin.py @@ -43,6 +43,22 @@ class PIE_OT_PivotToSelection(Operator): # Pivot to Bottom +def origin_to_bottom(ob): + if ob.type != 'MESH': + return + + init = 0 + for x in ob.data.vertices: + if init == 0: + a = x.co.z + init = 1 + elif x.co.z < a: + a = x.co.z + + for x in ob.data.vertices: + x.co.z -= a + + ob.location.z += a class PIE_OT_PivotBottom(Operator): bl_idname = "object.pivotobottom" @@ -60,19 +76,8 @@ class PIE_OT_PivotBottom(Operator): bpy.ops.object.transform_apply(location=True, rotation=True, scale=True) bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY') - init = 0 for ob in context.selected_objects: - for x in ob.data.vertices: - if init == 0: - a = x.co.z - init = 1 - elif x.co.z < a: - a = x.co.z - - for x in ob.data.vertices: - x.co.z -= a - - ob.location.z += a + origin_to_bottom(ob) return {'FINISHED'} @@ -94,19 +99,10 @@ class PIE_OT_PivotBottom_edit(Operator): bpy.ops.object.mode_set(mode='OBJECT') bpy.ops.object.transform_apply(location=True, rotation=True, scale=True) bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY') - o = context.active_object - init = 0 - for x in o.data.vertices: - if init == 0: - a = x.co.z - init = 1 - elif x.co.z < a: - a = x.co.z - for x in o.data.vertices: - x.co.z -= a + for ob in context.selected_objects: + origin_to_bottom(ob) - o.location.z += a bpy.ops.object.mode_set(mode='EDIT') return {'FINISHED'} -- 2.30.2