From b0502cd83ca389c8deb3f7458fcd13efa080982f Mon Sep 17 00:00:00 2001 From: Robert Meerman Date: Sun, 13 Feb 2022 11:02:07 +1300 Subject: Preserve smoothing options when changing a bolt Patch D10037 Prior to this patch the effect of applying the "Shade Smooth" object operator and the value of "Vertex > Auto Smooth" were lost when changing an existing bolt (via context-menu's "Change Bolt"). This patch preserves both. A simple heuristic is used to detect if "Shade Smooth" has been used: the value of use_smooth of the first polygon in the mesh (prior to activating "Change Bolt"). Experiment has shown that "Shade Smooth" / "Shade Flat" are equivalent to setting use_smooth to True/False (respectively) on every polygon in the mesh. (No heuristic is needed for Auto Smooth, as it is a top-level property of mesh data blocks) --- add_mesh_BoltFactory/Boltfactory.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/add_mesh_BoltFactory/Boltfactory.py b/add_mesh_BoltFactory/Boltfactory.py index eb673ee4..501043d1 100644 --- a/add_mesh_BoltFactory/Boltfactory.py +++ b/add_mesh_BoltFactory/Boltfactory.py @@ -416,6 +416,9 @@ class add_mesh_bolt(Operator, AddObjectHelper): (context.active_object.data is not None) and ('Bolt' in context.active_object.data.keys()) and \ (self.change == True): obj = context.active_object + use_auto_smooth = bool(obj.data.use_auto_smooth) # Copy value, do not take a reference + use_smooth = bool(obj.data.polygons[0].use_smooth) # Copy value, do not take a reference + mesh = createMesh.Create_New_Mesh(self, context) # Modify existing mesh data object by replacing geometry (but leaving materials etc) @@ -424,6 +427,11 @@ class add_mesh_bolt(Operator, AddObjectHelper): bm.to_mesh(obj.data) bm.free() + # Preserve flat/smooth choice. New mesh is flat by default + obj.data.use_auto_smooth = use_auto_smooth + if use_smooth: + bpy.ops.object.shade_smooth() + bpy.data.meshes.remove(mesh) try: -- cgit v1.2.3