Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Meerman <meermanr>2022-02-13 01:02:07 +0300
committerAaron Keith <aaroninusa@gmail.com>2022-02-13 01:02:07 +0300
commitb0502cd83ca389c8deb3f7458fcd13efa080982f (patch)
tree39ba6e13bae071f005c0af85dc231054d637ced9
parent2fab0283474d136201bf2b8f947e8f96fa71b838 (diff)
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)
-rw-r--r--add_mesh_BoltFactory/Boltfactory.py8
1 files changed, 8 insertions, 0 deletions
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: