[Bf-extensions-cvs] [b0502cd8] master: Preserve smoothing options when changing a bolt

Robert Meerman noreply at git.blender.org
Sat Feb 12 23:03:27 CET 2022


Commit: b0502cd83ca389c8deb3f7458fcd13efa080982f
Author: Robert Meerman
Date:   Sun Feb 13 11:02:07 2022 +1300
Branches: master
https://developer.blender.org/rBAb0502cd83ca389c8deb3f7458fcd13efa080982f

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)

===================================================================

M	add_mesh_BoltFactory/Boltfactory.py

===================================================================

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:



More information about the Bf-extensions-cvs mailing list