Mustard2 / MustardUI

Custom UI for Blender human models. It features automatic outfits switch, custom properties support, armature panel creation, and much more.
https://mustard3d.eu
MIT License
293 stars 29 forks source link

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

Closed cl3m3c7 closed 3 months ago

cl3m3c7 commented 5 months ago

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 commented 5 months ago

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
Mustard2 commented 4 months ago

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

cl3m3c7 commented 4 months ago

done!

Mustard2 commented 4 months ago

Perfect, thank you! Let me review it

Mustard2 commented 4 months ago

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

cl3m3c7 commented 4 months ago

@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

Mustard2 commented 4 months ago

@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.

cl3m3c7 commented 4 months ago

@Mustard2 fair enough!