MustardUI icon indicating copy to clipboard operation
MustardUI copied to clipboard

Normal auto smooth still uses old auto smooth for blender 4.1+

Open cl3m3c7 opened this issue 1 year ago • 8 comments

Hey, the normal auto smooth option for the outfits and hair still uses data.use_auto_smooth prop. I think it would be good to unify the code for all of them (body, hair and outfits).

https://github.com/Mustard2/MustardUI/blob/a9bfd0ca0f04e5cb225566bb171c26185b701ff0/settings/rig.py#L422

https://github.com/Mustard2/MustardUI/blob/a9bfd0ca0f04e5cb225566bb171c26185b701ff0/settings/rig.py#L657

cl3m3c7 avatar Apr 16 '24 01:04 cl3m3c7

something like this maybe?

diff --git a/settings/rig.py b/settings/rig.py
index dd2570d..3dfb6f8 100644
--- a/settings/rig.py
+++ b/settings/rig.py
@@ -64,18 +64,7 @@ class MustardUI_RigSettings(bpy.types.PropertyGroup):
 
     # Update function for Auto-smooth function
     def update_norm_autosmooth(self, context):
-
-        if bpy.app.version < (4, 1, 0):
-            self.model_body.data.use_auto_smooth = self.body_norm_autosmooth
-            return
-
-        for modifier in [x for x in self.model_body.modifiers if x.type == "NODES"]:
-            if modifier.node_group is None:
-                continue
-            if modifier.node_group.name != "Smooth by Angle":
-                continue
-            modifier.show_viewport = self.body_norm_autosmooth
-            modifier.show_render = self.body_norm_autosmooth
+        MustardUI_RigSettings._set_normal_autosmooth(self.model_body, self.body_norm_autosmooth)
 
     # Update function for Smooth Correction modifiers
     def update_solidify(self, context):
@@ -417,9 +406,9 @@ class MustardUI_RigSettings(bpy.types.PropertyGroup):
         for collection in collections:
             items = collection.all_objects if self.outfit_config_subcollections else collection.objects
             for obj in items:
-
-                if obj.type == "MESH" and self.outfits_enable_global_normalautosmooth:
-                    obj.data.use_auto_smooth = self.outfits_global_normalautosmooth
+                MustardUI_RigSettings._set_normal_autosmooth(obj,
+                                      self.outfits_global_normalautosmooth,
+                                      self.outfits_enable_global_normalautosmooth)
 
                 for modifier in obj.modifiers:
                     if modifier.type == "CORRECTIVE_SMOOTH" and self.outfits_enable_global_smoothcorrection:
@@ -653,8 +642,10 @@ class MustardUI_RigSettings(bpy.types.PropertyGroup):
 
         if self.hair_collection is not None:
             for obj in self.hair_collection.objects:
-                if obj.type == "MESH" and self.hair_enable_global_normalautosmooth:
-                    obj.data.use_auto_smooth = self.hair_global_normalautosmooth
+                MustardUI_RigSettings._set_normal_autosmooth(obj,
+                                                             self.hair_global_normalautosmooth,
+                                                             self.hair_enable_global_normalautosmooth)
+
                 for modifier in obj.modifiers:
                     if modifier.type == "CORRECTIVE_SMOOTH" and self.hair_enable_global_smoothcorrection:
                         modifier.show_viewport = self.hair_global_smoothcorrection
@@ -1081,6 +1072,23 @@ class MustardUI_RigSettings(bpy.types.PropertyGroup):
     # Property for collapsing debug properties section
     debug_config_collapse: bpy.props.BoolProperty(default=True,
                                                   name="")
+    @staticmethod
+    def _set_normal_autosmooth(target_object, autosmooth_value, autosmooth_enabled=True):
+
+        if target_object.type == "MESH" and autosmooth_enabled:
+            if bpy.app.version < (4, 1, 0):
+                target_object.data.use_auto_smooth = autosmooth_value
+
+            else:
+                for modifier in [x for x in target_object.modifiers if x.type == "NODES"]:
+                    if modifier.node_group is None:
+                        continue
+
+                    if modifier.node_group.name != "Smooth by Angle":
+                        continue
+
+                    modifier.show_viewport = autosmooth_value
+                    modifier.show_render = autosmooth_value
 
     # END OF MustardUI_RigSettings class
 

cl3m3c7 avatar Apr 16 '24 01:04 cl3m3c7

@cl3m3c7 seems a good addition, do you want to create a pull request yourself?

Mustard2 avatar Apr 22 '24 11:04 Mustard2

done!

cl3m3c7 avatar Apr 23 '24 18:04 cl3m3c7

Perfect, thank you! Let me review it

Mustard2 avatar Apr 28 '24 20:04 Mustard2

Ok merged into the new version merge request #168 . Thank you very much!

Mustard2 avatar Apr 28 '24 20:04 Mustard2

@Mustard2 one question though, is it really necessary to include code for older versions (4.0!) when the addon requires the blender version to be an exact one (or higher) as per release notes?

ie: if the latest version of the plugin does require blender version to be 4.1+, the I think testing and adding compatible code for lower versions is kind of unnecessary?

https://github.com/search?q=repo%3AMustard2%2FMustardUI+app.version+%3E%3D++OR+%3C+&type=code

cl3m3c7 avatar Apr 29 '24 10:04 cl3m3c7

@cl3m3c7 Yeah, I feel the same, but I want to give a sort of "grace period" before completely deprecating some stuffs. Not everyone updates Blender as soon as the version goes out. After a couple of major Blender version I will just delete the old parts.

Mustard2 avatar Apr 30 '24 18:04 Mustard2

@Mustard2 fair enough!

cl3m3c7 avatar May 06 '24 03:05 cl3m3c7