diff --git a/lib/preferences.py b/lib/preferences.py index 33a2f2d..da31bfe 100644 --- a/lib/preferences.py +++ b/lib/preferences.py @@ -61,6 +61,10 @@ class ObjectAlignmentPreferences(AddonPreferences): name="Use Target", description="Calc alignment stats at each iteration to assess convergence. SLower per step, may result in less steps", default=True) + take_m_with = BoolProperty( + name="Take m_ Objects with", + description="Applies the same Transformation Matrix to all Objects which start with 'm_'", + default=False) align_methods =['RIGID','ROT_LOC_SCALE']#,'AFFINE'] align_items = [] for index, item in enumerate(align_methods): @@ -104,6 +108,7 @@ def draw(self, context): layout.prop(self, "use_target") layout.prop(self, "target_d") layout.prop(self, "align_meth") + layout.prop(self, "take_m_with") # updater draw function addon_updater_ops.update_settings_ui(self,context) diff --git a/operators/align_pick_points.py b/operators/align_pick_points.py index 8f52e07..3d4491d 100644 --- a/operators/align_pick_points.py +++ b/operators/align_pick_points.py @@ -420,6 +420,7 @@ def align_obj(self,context): #test new method settings = get_addon_preferences() align_meth = settings.align_meth + take_m_with = settings.take_m_with if align_meth == '0': #rigid transform M = affine_matrix_from_points(A, B, shear=False, scale=False, usesvd=True) @@ -437,6 +438,13 @@ def align_obj(self,context): #because we calced transform in local space #it's this easy to update the obj... self.obj_align.matrix_world = self.obj_align.matrix_world @ new_mat + print(f"Final Transformation Matrix is: {new_mat}") + if take_m_with == True: + for obj in bpy.context.scene.objects: + if obj.name[:2] == "m_": + obj.matrix_world = obj.matrix_world @ new_mat + obj.update_tag() + self.obj_align.update_tag() context.view_layer.update() diff --git a/operators/icp_align.py b/operators/icp_align.py index dd2952c..693b474 100644 --- a/operators/icp_align.py +++ b/operators/icp_align.py @@ -41,8 +41,8 @@ class OBJECT_OT_icp_align(Operator): @classmethod def poll(cls, context): condition_1 = len(context.selected_objects) == 2 - conidion_2 = context.object.type == 'MESH' - return condition_1 and condition_1 + condition_2 = context.object.type == 'MESH' + return condition_1 and condition_2 def execute(self, context): settings = get_addon_preferences() @@ -85,6 +85,7 @@ def execute(self, context): iters = settings.icp_iterations target_d = settings.target_d use_target = settings.use_target + take_m_with = settings.take_m_with factor = round(1/sample) n = 0 @@ -109,6 +110,13 @@ def execute(self, context): new_mat[y][z] = M[y][z] align_obj.matrix_world = align_obj.matrix_world @ new_mat + print(f"Final Transformation Matrix is: {new_mat}") + if take_m_with == True: + for obj in bpy.context.scene.objects: + if obj.name[:2] == "m_": + obj.matrix_world = obj.matrix_world @ new_mat + obj.update_tag() + trans = new_mat.to_translation() quat = new_mat.to_quaternion() diff --git a/operators/icp_align_feedback.py b/operators/icp_align_feedback.py index 8615c3c..8e111cb 100644 --- a/operators/icp_align_feedback.py +++ b/operators/icp_align_feedback.py @@ -90,6 +90,7 @@ def invoke(self,context, event): self.iters = settings.icp_iterations self.target_d = settings.target_d self.use_target = settings.use_target + self.take_m_with = settings.take_m_with self.sample_factor = round(1/self.sample_fraction) self.redraw_frequency = settings.redraw_frequency @@ -123,8 +124,8 @@ def modal(self, context, event): @classmethod def poll(cls, context): condition_1 = len(context.selected_objects) == 2 - conidion_2 = context.object.type == 'MESH' - return condition_1 and condition_1 + condition_2 = context.object.type == 'MESH' + return condition_1 and condition_2 def execute(self, context): settings = get_addon_preferences() @@ -167,6 +168,7 @@ def execute(self, context): iters = settings.icp_iterations target_d = settings.target_d use_target = settings.use_target + take_m_with = settings.take_m_with factor = round(1/sample) n = 0 @@ -191,6 +193,13 @@ def execute(self, context): new_mat[y][z] = M[y][z] align_obj.matrix_world = align_obj.matrix_world @ new_mat + print(f"Final Transformation Matrix is: {new_mat}") + if take_m_with == True: + for obj in bpy.context.scene.objects: + if obj.name[:2] == "m_": + obj.matrix_world = obj.matrix_world @ new_mat + obj.update_tag() + trans = new_mat.to_translation() quat = new_mat.to_quaternion() @@ -254,6 +263,12 @@ def iterate(self,context): new_mat[y][z] = M[y][z] self.align_obj.matrix_world = self.align_obj.matrix_world @ new_mat + + if take_m_with == True: + for obj in bpy.context.scene.objects: + if obj.name[:2] == "m_": + obj.matrix_world = obj.matrix_world @ new_mat + obj.update_tag() trans = new_mat.to_translation() quat = new_mat.to_quaternion() diff --git a/ui/__init__.py b/ui/__init__.py index dc0635b..1eb919f 100644 --- a/ui/__init__.py +++ b/ui/__init__.py @@ -75,6 +75,11 @@ def draw(self, context): row.operator("object.align_exclude") row.operator("object.align_exclude_clear", icon="X", text="") + row = layout.row() + row.label(text="General Alignment") + row = layout.row() + row.prop(settings, "take_m_with") + row = layout.row() row.label(text="Initial Alignment") row = layout.row()