Skip to content

Commit

Permalink
support blender 4.1 smooth shading breaking change
Browse files Browse the repository at this point in the history
  • Loading branch information
skyslide22 committed Apr 30, 2024
1 parent 0c44696 commit 8d814fd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "NICE"]
path = NICE
url = https://github.com/schadocalex/gbx-py
url = https://github.com/schadocalex/gbx-py
14 changes: 8 additions & 6 deletions panels/PT_Items_Manipulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,14 @@ def draw(self, context):
editmode = obj.mode == "EDIT"
row.operator("object.shade_smooth" if not editmode else "mesh.faces_shade_smooth", icon=ICON_SMOOTH)
row.operator("object.shade_flat" if not editmode else "mesh.faces_shade_flat", icon=ICON_FLAT)
row= col.row(align=True)
innercol = row.column(align=True)
innercol.scale_x = 1.2
innercol.prop(obj.data, "use_auto_smooth", toggle=True, icon=ICON_FLAT_SMOOTH)
innercol = row.column(align=True)
innercol.prop(obj.data, "auto_smooth_angle", text="")

if bpy.app.version < (4, 1, 0): # 4.1 changed auto smooth to geo nodes AHHHH
row= col.row(align=True)
innercol = row.column(align=True)
innercol.scale_x = 1.2
innercol.prop(obj.data, "use_auto_smooth", toggle=True, icon=ICON_FLAT_SMOOTH)
innercol = row.column(align=True)
innercol.prop(obj.data, "auto_smooth_angle", text="")



Expand Down
21 changes: 17 additions & 4 deletions utils/ItemsImport.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,23 @@ def _clean_up_imported_item_gbx(objs: list[bpy.types.Object], item_name: str, de
slot.material = mat

# auto smooth
obj.data.polygons.foreach_set('use_smooth', [True] * len(obj.data.polygons))
obj.data.use_auto_smooth = 1
obj.data.auto_smooth_angle = math.pi/6 # 45 degrees

use_old_smoothing = bpy.app.version < (4, 1, 0)

if use_old_smoothing:
obj.data.polygons.foreach_set('use_smooth', [True] * len(obj.data.polygons))
obj.data.use_auto_smooth = 1
obj.data.auto_smooth_angle = math.pi/6 # 45 degrees

else:
# ugly access, maybe there is a better way to get the "nodes?" by name...
bpy.context.view_layer.objects.active = obj
bpy.ops.object.modifier_add_node_group(
asset_library_type='ESSENTIALS',
asset_library_identifier="",
relative_asset_identifier="geometry_nodes\\smooth_by_angle.blend\\NodeTree\\Smooth by Angle")
mod = obj.modifiers[-1]
mod["Input_1"] = math.pi/2 # float "Angle"
mod["Socket_1"] = True # bool "Ignore Sharpness"

obj.name = f"{item_name} {obj.name}"

Expand Down

0 comments on commit 8d814fd

Please sign in to comment.