From fd3b4febd690de7d90888a08b4f8510e57584eef Mon Sep 17 00:00:00 2001 From: FredericNk Date: Fri, 3 Apr 2020 10:28:02 +0200 Subject: [PATCH 1/7] Fixed typo in icp_align polling function --- operators/icp_align.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/operators/icp_align.py b/operators/icp_align.py index dd2952c..39cc178 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() From e22f1c5514b320341d1b43b17133ff28c4519181 Mon Sep 17 00:00:00 2001 From: FredericNk Date: Fri, 3 Apr 2020 11:26:40 +0200 Subject: [PATCH 2/7] Apply transformation to multiple objects If the checkbox "Take m_ Objects with" in the toolbox menu is toggled all existing objects are searched and the finals transformationmatrix is applied to all that start with "m_" --- lib/preferences.py | 5 +++++ operators/align_pick_points.py | 13 +++++++++++++ operators/icp_align.py | 13 +++++++++++++ operators/icp_align_feedback.py | 2 ++ ui/__init__.py | 5 +++++ 5 files changed, 38 insertions(+) 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..a446d88 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) @@ -438,5 +439,17 @@ def align_obj(self,context): #it's this easy to update the obj... self.obj_align.matrix_world = self.obj_align.matrix_world @ new_mat + print(f"Checking take with, current val {take_m_with}") + if take_m_with == True: + print(f"Take_m_with is True") + for obj in bpy.context.scene.objects: + if obj.name[:2] == "m_": + print(f"Moving object: {obj.name}") + print(f"Matrix to world before: {obj.matrix_world}") + obj.matrix_world = obj.matrix_world @ new_mat + print(f"Matrix to world after: {obj.matrix_world}") + 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 39cc178..45d4df1 100644 --- a/operators/icp_align.py +++ b/operators/icp_align.py @@ -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,18 @@ def execute(self, context): new_mat[y][z] = M[y][z] align_obj.matrix_world = align_obj.matrix_world @ new_mat + + print(f"Checking take with, current val {take_m_with}") + if take_m_with == True: + print(f"Take_m_with is True") + for obj in bpy.context.scene.objects: + if obj.name[:2] == "m_": + print(f"Moving object: {obj.name}") + print(f"Matrix to world before: {obj.matrix_world}") + obj.matrix_world = obj.matrix_world @ new_mat + print(f"Matrix to world after: {obj.matrix_world}") + 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..94c0fb1 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 @@ -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 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() From 9116ed206d26ecbaf7ea23b130ed4ad9e15a58a9 Mon Sep 17 00:00:00 2001 From: FredericNk Date: Fri, 3 Apr 2020 11:51:19 +0200 Subject: [PATCH 3/7] Added take with to icp align feedback --- operators/icp_align_feedback.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/operators/icp_align_feedback.py b/operators/icp_align_feedback.py index 94c0fb1..7d433ee 100644 --- a/operators/icp_align_feedback.py +++ b/operators/icp_align_feedback.py @@ -193,6 +193,18 @@ def execute(self, context): new_mat[y][z] = M[y][z] align_obj.matrix_world = align_obj.matrix_world @ new_mat + + print(f"Checking take with, current val {take_m_with}") + if take_m_with == True: + print(f"Take_m_with is True") + for obj in bpy.context.scene.objects: + if obj.name[:2] == "m_": + print(f"Moving object: {obj.name}") + print(f"Matrix to world before: {obj.matrix_world}") + obj.matrix_world = obj.matrix_world @ new_mat + print(f"Matrix to world after: {obj.matrix_world}") + obj.update_tag() + trans = new_mat.to_translation() quat = new_mat.to_quaternion() From e21ac71c70d92991622ac103dd165f161ded77bd Mon Sep 17 00:00:00 2001 From: FredericNk Date: Fri, 3 Apr 2020 11:54:06 +0200 Subject: [PATCH 4/7] Added typo in poll function --- operators/icp_align_feedback.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/operators/icp_align_feedback.py b/operators/icp_align_feedback.py index 7d433ee..22a25c4 100644 --- a/operators/icp_align_feedback.py +++ b/operators/icp_align_feedback.py @@ -124,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() From 1ac81e25b0369f3e73ca575916af5e02a8b25708 Mon Sep 17 00:00:00 2001 From: FredericNk Date: Fri, 3 Apr 2020 11:55:07 +0200 Subject: [PATCH 5/7] Removed extensive logging --- operators/align_pick_points.py | 5 ----- operators/icp_align.py | 5 ----- operators/icp_align_feedback.py | 6 ------ 3 files changed, 16 deletions(-) diff --git a/operators/align_pick_points.py b/operators/align_pick_points.py index a446d88..9f18e73 100644 --- a/operators/align_pick_points.py +++ b/operators/align_pick_points.py @@ -439,15 +439,10 @@ def align_obj(self,context): #it's this easy to update the obj... self.obj_align.matrix_world = self.obj_align.matrix_world @ new_mat - print(f"Checking take with, current val {take_m_with}") if take_m_with == True: - print(f"Take_m_with is True") for obj in bpy.context.scene.objects: if obj.name[:2] == "m_": - print(f"Moving object: {obj.name}") - print(f"Matrix to world before: {obj.matrix_world}") obj.matrix_world = obj.matrix_world @ new_mat - print(f"Matrix to world after: {obj.matrix_world}") obj.update_tag() diff --git a/operators/icp_align.py b/operators/icp_align.py index 45d4df1..a836e1d 100644 --- a/operators/icp_align.py +++ b/operators/icp_align.py @@ -111,15 +111,10 @@ def execute(self, context): align_obj.matrix_world = align_obj.matrix_world @ new_mat - print(f"Checking take with, current val {take_m_with}") if take_m_with == True: - print(f"Take_m_with is True") for obj in bpy.context.scene.objects: if obj.name[:2] == "m_": - print(f"Moving object: {obj.name}") - print(f"Matrix to world before: {obj.matrix_world}") obj.matrix_world = obj.matrix_world @ new_mat - print(f"Matrix to world after: {obj.matrix_world}") obj.update_tag() trans = new_mat.to_translation() diff --git a/operators/icp_align_feedback.py b/operators/icp_align_feedback.py index 22a25c4..2f9d8bb 100644 --- a/operators/icp_align_feedback.py +++ b/operators/icp_align_feedback.py @@ -193,16 +193,10 @@ def execute(self, context): new_mat[y][z] = M[y][z] align_obj.matrix_world = align_obj.matrix_world @ new_mat - - print(f"Checking take with, current val {take_m_with}") if take_m_with == True: - print(f"Take_m_with is True") for obj in bpy.context.scene.objects: if obj.name[:2] == "m_": - print(f"Moving object: {obj.name}") - print(f"Matrix to world before: {obj.matrix_world}") obj.matrix_world = obj.matrix_world @ new_mat - print(f"Matrix to world after: {obj.matrix_world}") obj.update_tag() trans = new_mat.to_translation() From c81960d9d049b08b45467f3534037dfe81dda61c Mon Sep 17 00:00:00 2001 From: FredericNk Date: Fri, 3 Apr 2020 11:56:16 +0200 Subject: [PATCH 6/7] Added printing of transformation matrix --- operators/align_pick_points.py | 2 +- operators/icp_align.py | 2 +- operators/icp_align_feedback.py | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/operators/align_pick_points.py b/operators/align_pick_points.py index 9f18e73..3d4491d 100644 --- a/operators/align_pick_points.py +++ b/operators/align_pick_points.py @@ -438,7 +438,7 @@ 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_": diff --git a/operators/icp_align.py b/operators/icp_align.py index a836e1d..693b474 100644 --- a/operators/icp_align.py +++ b/operators/icp_align.py @@ -110,7 +110,7 @@ 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_": diff --git a/operators/icp_align_feedback.py b/operators/icp_align_feedback.py index 2f9d8bb..e2f9af8 100644 --- a/operators/icp_align_feedback.py +++ b/operators/icp_align_feedback.py @@ -193,6 +193,7 @@ 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_": From 827bd31d0a975b52f7a914a9dee62f41c7194f38 Mon Sep 17 00:00:00 2001 From: FredericNk Date: Fri, 3 Apr 2020 12:21:27 +0200 Subject: [PATCH 7/7] Added take with to iterate function --- operators/icp_align_feedback.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/operators/icp_align_feedback.py b/operators/icp_align_feedback.py index e2f9af8..8e111cb 100644 --- a/operators/icp_align_feedback.py +++ b/operators/icp_align_feedback.py @@ -263,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()