From 7a8606e7fbeceef101569ad2525fdce2d99913c1 Mon Sep 17 00:00:00 2001 From: Ray Molenkamp Date: Mon, 15 Jan 2024 10:21:50 -0700 Subject: [PATCH] Update for blender 4.0 --- __init__.py | 45 +++++++++++++++++++++++++++++----- bonus_hexagon_addin.py | 22 +++++++++++------ brick_rounded_corner_addin.py | 22 +++++++++++------ brick_square_corner_addin.py | 22 +++++++++++------ uv_map_brick_wall_addin.py | 22 +++++++++++------ uv_map_diamond_addin.py | 22 +++++++++++------ uv_map_rotate_addin.py | 22 +++++++++++------ uv_map_swirl_addin.py | 22 +++++++++++------ uv_map_tile_pattern_1_addin.py | 22 +++++++++++------ uv_map_tile_pattern_2_addin.py | 22 +++++++++++------ 10 files changed, 165 insertions(+), 78 deletions(-) diff --git a/__init__.py b/__init__.py index e6d8838..43b54a8 100644 --- a/__init__.py +++ b/__init__.py @@ -4,7 +4,7 @@ "LazyDodo, " "Secrop" ), - "version": (0, 0, 1,4), + "version": (0, 0, 1,5), "blender": (2, 80, 0), "location": "Nodes > Add nodes", "description": "Brick Tricks Cycles Nodes", @@ -24,13 +24,15 @@ import bpy,nodeitems_utils from nodeitems_utils import NodeCategory, NodeItem - +from bpy.types import Menu +from bl_ui import node_add_menu + class ExtraNodesCategory(NodeCategory): @classmethod def poll(cls, context): return (context.space_data.tree_type == 'ShaderNodeTree' and context.scene.render.engine in ['BLENDER_EEVEE', 'CYCLES']) - + node_categories = [ ExtraNodesCategory("SH_BRICK_TRIKS", "BrickTricks", items=[ NodeItem("ShaderNodeuv_map_tile_pattern_1"), @@ -44,8 +46,35 @@ def poll(cls, context): NodeItem("ShaderNodebonus_hexagon"), ]), ] - + +class NODE_MT_category_shader_bricktricks(Menu): + bl_idname = "NODE_MT_category_shader_bricktricks" + bl_label = "Brick Tricks" + + def draw(self, context): + layout = self.layout + + node_add_menu.add_node_type(layout, "ShaderNodeuv_map_tile_pattern_1") + node_add_menu.add_node_type(layout, "ShaderNodeuv_map_tile_pattern_2") + node_add_menu.add_node_type(layout, "ShaderNodeuv_map_diamond") + node_add_menu.add_node_type(layout, "ShaderNodeuv_map_brick_wall") + node_add_menu.add_node_type(layout, "ShaderNodeuv_map_swirl") + node_add_menu.add_node_type(layout, "ShaderNodebrick_rounded_corner") + node_add_menu.add_node_type(layout, "ShaderNodebrick_square_corner") + node_add_menu.add_node_type(layout, "ShaderNodeuv_map_rotate") + node_add_menu.add_node_type(layout, "ShaderNodebonus_hexagon") + node_add_menu.draw_assets_for_catalog(layout, self.bl_label) + +def bricktricks_draw(self, context): + layout = self.layout + layout.menu("NODE_MT_category_shader_bricktricks") + def register(): + if bpy.app.version >= (4, 0, 0): + bpy.utils.register_class(NODE_MT_category_shader_bricktricks) + bpy.types.NODE_MT_shader_node_add_all.append(bricktricks_draw) + else: + nodeitems_utils.register_node_categories("BRICK_TRICKS_NODES", node_categories) bpy.utils.register_class(ShaderNodebonus_hexagon) bpy.utils.register_class(ShaderNodebrick_rounded_corner) bpy.utils.register_class(ShaderNodebrick_square_corner) @@ -55,11 +84,9 @@ def register(): bpy.utils.register_class(ShaderNodeuv_map_tile_pattern_1) bpy.utils.register_class(ShaderNodeuv_map_tile_pattern_2) bpy.utils.register_class(ShaderNodeuv_map_diamond) - nodeitems_utils.register_node_categories("BRICK_TRICKS_NODES", node_categories) def unregister(): - nodeitems_utils.unregister_node_categories("BRICK_TRICKS_NODES") bpy.utils.unregister_class(ShaderNodebonus_hexagon) bpy.utils.unregister_class(ShaderNodebrick_rounded_corner) bpy.utils.unregister_class(ShaderNodebrick_square_corner) @@ -69,6 +96,12 @@ def unregister(): bpy.utils.unregister_class(ShaderNodeuv_map_tile_pattern_1) bpy.utils.unregister_class(ShaderNodeuv_map_tile_pattern_2) bpy.utils.unregister_class(ShaderNodeuv_map_diamond) + if bpy.app.version >= (4, 0, 0): + bpy.types.NODE_MT_shader_node_add_all.remove(bricktricks_draw) + bpy.utils.unregister_class(NODE_MT_category_shader_bricktricks) + else: + nodeitems_utils.unregister_node_categories("BRICK_TRICKS_NODES") + if __name__ == "__main__": register() diff --git a/bonus_hexagon_addin.py b/bonus_hexagon_addin.py index c146083..074a1f8 100644 --- a/bonus_hexagon_addin.py +++ b/bonus_hexagon_addin.py @@ -154,7 +154,7 @@ def createNodetree(self, name) : self.addNode('ShaderNodeMath', { 'name':'Node134' ,'operation':'DIVIDE','use_clamp':1 }) #Sockets self.addSocket(False, 'NodeSocketVector', 'Vector') - self.addSocket(False, 'NodeSocketFloatFactor', 'HAS_Vector') + self.addSocket(False, 'NodeSocketFloat', 'HAS_Vector') self.addSocket(False, 'NodeSocketFloat', 'scale') self.addSocket(False, 'NodeSocketFloat', 'feather') self.addSocket(True, 'NodeSocketFloat', 'Value') @@ -358,13 +358,19 @@ def getNodetree(self, name): self.node_tree=bpy.data.node_groups[name] def addSocket(self, is_output, sockettype, name): - #for now duplicated socket names are not allowed - if is_output==True: - if self.node_tree.nodes['GroupOutput'].inputs.find(name)==-1: - socket=self.node_tree.outputs.new(sockettype, name) - elif is_output==False: - if self.node_tree.nodes['GroupInput'].outputs.find(name)==-1: - socket=self.node_tree.inputs.new(sockettype, name) + if bpy.app.version >= (4, 0, 0): + if is_output==True: + socket = self.node_tree.interface.new_socket(name, in_out='OUTPUT', socket_type=sockettype) + else: + socket = self.node_tree.interface.new_socket(name, in_out='INPUT', socket_type=sockettype) + else: + #for now duplicated socket names are not allowed + if is_output==True: + if self.node_tree.nodes['GroupOutput'].inputs.find(name)==-1: + socket=self.node_tree.outputs.new(sockettype, name) + elif is_output==False: + if self.node_tree.nodes['GroupInput'].outputs.find(name)==-1: + socket=self.node_tree.inputs.new(sockettype, name) return socket def addNode(self, nodetype, attrs): diff --git a/brick_rounded_corner_addin.py b/brick_rounded_corner_addin.py index d8e5d6e..4748f09 100644 --- a/brick_rounded_corner_addin.py +++ b/brick_rounded_corner_addin.py @@ -84,7 +84,7 @@ def createNodetree(self, name) : self.addNode('ShaderNodeMath', { 'name':'Node48' ,'operation':'DIVIDE','use_clamp':1 }) #Sockets self.addSocket(False, 'NodeSocketVector', 'Vector') - self.addSocket(False, 'NodeSocketFloatFactor', 'HAS_Vector') + self.addSocket(False, 'NodeSocketFloat', 'HAS_Vector') self.addSocket(False, 'NodeSocketFloat', 'brick_width') self.addSocket(False, 'NodeSocketFloat', 'brick_height') self.addSocket(False, 'NodeSocketFloat', 'border') @@ -177,13 +177,19 @@ def getNodetree(self, name): self.node_tree=bpy.data.node_groups[name] def addSocket(self, is_output, sockettype, name): - #for now duplicated socket names are not allowed - if is_output==True: - if self.node_tree.nodes['GroupOutput'].inputs.find(name)==-1: - socket=self.node_tree.outputs.new(sockettype, name) - elif is_output==False: - if self.node_tree.nodes['GroupInput'].outputs.find(name)==-1: - socket=self.node_tree.inputs.new(sockettype, name) + if bpy.app.version >= (4, 0, 0): + if is_output==True: + socket = self.node_tree.interface.new_socket(name, in_out='OUTPUT', socket_type=sockettype) + else: + socket = self.node_tree.interface.new_socket(name, in_out='INPUT', socket_type=sockettype) + else: + #for now duplicated socket names are not allowed + if is_output==True: + if self.node_tree.nodes['GroupOutput'].inputs.find(name)==-1: + socket=self.node_tree.outputs.new(sockettype, name) + elif is_output==False: + if self.node_tree.nodes['GroupInput'].outputs.find(name)==-1: + socket=self.node_tree.inputs.new(sockettype, name) return socket def addNode(self, nodetype, attrs): diff --git a/brick_square_corner_addin.py b/brick_square_corner_addin.py index 61f107a..7456d39 100644 --- a/brick_square_corner_addin.py +++ b/brick_square_corner_addin.py @@ -65,7 +65,7 @@ def createNodetree(self, name) : self.addNode('ShaderNodeMath', { 'name':'Node31' ,'operation':'GREATER_THAN' }) #Sockets self.addSocket(False, 'NodeSocketVector', 'Vector') - self.addSocket(False, 'NodeSocketFloatFactor', 'HAS_Vector') + self.addSocket(False, 'NodeSocketFloat', 'HAS_Vector') self.addSocket(False, 'NodeSocketFloat', 'brick_width') self.addSocket(False, 'NodeSocketFloat', 'brick_height') self.addSocket(False, 'NodeSocketFloat', 'border') @@ -129,13 +129,19 @@ def getNodetree(self, name): self.node_tree=bpy.data.node_groups[name] def addSocket(self, is_output, sockettype, name): - #for now duplicated socket names are not allowed - if is_output==True: - if self.node_tree.nodes['GroupOutput'].inputs.find(name)==-1: - socket=self.node_tree.outputs.new(sockettype, name) - elif is_output==False: - if self.node_tree.nodes['GroupInput'].outputs.find(name)==-1: - socket=self.node_tree.inputs.new(sockettype, name) + if bpy.app.version >= (4, 0, 0): + if is_output==True: + socket = self.node_tree.interface.new_socket(name, in_out='OUTPUT', socket_type=sockettype) + else: + socket = self.node_tree.interface.new_socket(name, in_out='INPUT', socket_type=sockettype) + else: + #for now duplicated socket names are not allowed + if is_output==True: + if self.node_tree.nodes['GroupOutput'].inputs.find(name)==-1: + socket=self.node_tree.outputs.new(sockettype, name) + elif is_output==False: + if self.node_tree.nodes['GroupInput'].outputs.find(name)==-1: + socket=self.node_tree.inputs.new(sockettype, name) return socket def addNode(self, nodetype, attrs): diff --git a/uv_map_brick_wall_addin.py b/uv_map_brick_wall_addin.py index 3bcf587..77753f7 100644 --- a/uv_map_brick_wall_addin.py +++ b/uv_map_brick_wall_addin.py @@ -102,7 +102,7 @@ def createNodetree(self, name) : self.addNode('ShaderNodeCombineXYZ', { 'name':'Node67' }) #Sockets self.addSocket(False, 'NodeSocketVector', 'Vector') - self.addSocket(False, 'NodeSocketFloatFactor', 'HAS_Vector') + self.addSocket(False, 'NodeSocketFloat', 'HAS_Vector') self.addSocket(False, 'NodeSocketFloat', 'scale') self.addSocket(False, 'NodeSocketFloat', 'brick_width') self.addSocket(False, 'NodeSocketFloat', 'brick_height') @@ -233,13 +233,19 @@ def getNodetree(self, name): self.node_tree=bpy.data.node_groups[name] def addSocket(self, is_output, sockettype, name): - #for now duplicated socket names are not allowed - if is_output==True: - if self.node_tree.nodes['GroupOutput'].inputs.find(name)==-1: - socket=self.node_tree.outputs.new(sockettype, name) - elif is_output==False: - if self.node_tree.nodes['GroupInput'].outputs.find(name)==-1: - socket=self.node_tree.inputs.new(sockettype, name) + if bpy.app.version >= (4, 0, 0): + if is_output==True: + socket = self.node_tree.interface.new_socket(name, in_out='OUTPUT', socket_type=sockettype) + else: + socket = self.node_tree.interface.new_socket(name, in_out='INPUT', socket_type=sockettype) + else: + #for now duplicated socket names are not allowed + if is_output==True: + if self.node_tree.nodes['GroupOutput'].inputs.find(name)==-1: + socket=self.node_tree.outputs.new(sockettype, name) + elif is_output==False: + if self.node_tree.nodes['GroupInput'].outputs.find(name)==-1: + socket=self.node_tree.inputs.new(sockettype, name) return socket def addNode(self, nodetype, attrs): diff --git a/uv_map_diamond_addin.py b/uv_map_diamond_addin.py index 57e8be8..7a7223b 100644 --- a/uv_map_diamond_addin.py +++ b/uv_map_diamond_addin.py @@ -215,7 +215,7 @@ def createNodetree(self, name) : self.addNode('ShaderNodeMixRGB', { 'name':'Node182' }) #Sockets self.addSocket(False, 'NodeSocketVector', 'Vector') - self.addSocket(False, 'NodeSocketFloatFactor', 'HAS_Vector') + self.addSocket(False, 'NodeSocketFloat', 'HAS_Vector') self.addSocket(False, 'NodeSocketFloat', 'scale') self.addSocket(False, 'NodeSocketFloat', 'diamond_size') self.addSocket(False, 'NodeSocketFloat', 'brick_width') @@ -583,13 +583,19 @@ def getNodetree(self, name): self.node_tree=bpy.data.node_groups[name] def addSocket(self, is_output, sockettype, name): - #for now duplicated socket names are not allowed - if is_output==True: - if self.node_tree.nodes['GroupOutput'].inputs.find(name)==-1: - socket=self.node_tree.outputs.new(sockettype, name) - elif is_output==False: - if self.node_tree.nodes['GroupInput'].outputs.find(name)==-1: - socket=self.node_tree.inputs.new(sockettype, name) + if bpy.app.version >= (4, 0, 0): + if is_output==True: + socket = self.node_tree.interface.new_socket(name, in_out='OUTPUT', socket_type=sockettype) + else: + socket = self.node_tree.interface.new_socket(name, in_out='INPUT', socket_type=sockettype) + else: + #for now duplicated socket names are not allowed + if is_output==True: + if self.node_tree.nodes['GroupOutput'].inputs.find(name)==-1: + socket=self.node_tree.outputs.new(sockettype, name) + elif is_output==False: + if self.node_tree.nodes['GroupInput'].outputs.find(name)==-1: + socket=self.node_tree.inputs.new(sockettype, name) return socket def addNode(self, nodetype, attrs): diff --git a/uv_map_rotate_addin.py b/uv_map_rotate_addin.py index ad2ffab..b155fb1 100644 --- a/uv_map_rotate_addin.py +++ b/uv_map_rotate_addin.py @@ -74,7 +74,7 @@ def createNodetree(self, name) : self.addNode('ShaderNodeMixRGB', { 'name':'Node41' }) #Sockets self.addSocket(False, 'NodeSocketVector', 'Vector') - self.addSocket(False, 'NodeSocketFloatFactor', 'HAS_Vector') + self.addSocket(False, 'NodeSocketFloat', 'HAS_Vector') self.addSocket(False, 'NodeSocketFloat', 'brick_width') self.addSocket(False, 'NodeSocketFloat', 'brick_height') self.addSocket(False, 'NodeSocketFloat', 'Angle') @@ -151,13 +151,19 @@ def getNodetree(self, name): self.node_tree=bpy.data.node_groups[name] def addSocket(self, is_output, sockettype, name): - #for now duplicated socket names are not allowed - if is_output==True: - if self.node_tree.nodes['GroupOutput'].inputs.find(name)==-1: - socket=self.node_tree.outputs.new(sockettype, name) - elif is_output==False: - if self.node_tree.nodes['GroupInput'].outputs.find(name)==-1: - socket=self.node_tree.inputs.new(sockettype, name) + if bpy.app.version >= (4, 0, 0): + if is_output==True: + socket = self.node_tree.interface.new_socket(name, in_out='OUTPUT', socket_type=sockettype) + else: + socket = self.node_tree.interface.new_socket(name, in_out='INPUT', socket_type=sockettype) + else: + #for now duplicated socket names are not allowed + if is_output==True: + if self.node_tree.nodes['GroupOutput'].inputs.find(name)==-1: + socket=self.node_tree.outputs.new(sockettype, name) + elif is_output==False: + if self.node_tree.nodes['GroupInput'].outputs.find(name)==-1: + socket=self.node_tree.inputs.new(sockettype, name) return socket def addNode(self, nodetype, attrs): diff --git a/uv_map_swirl_addin.py b/uv_map_swirl_addin.py index 14ad335..f42b788 100644 --- a/uv_map_swirl_addin.py +++ b/uv_map_swirl_addin.py @@ -113,7 +113,7 @@ def createNodetree(self, name) : self.addNode('ShaderNodeCombineXYZ', { 'name':'Node84' }) #Sockets self.addSocket(False, 'NodeSocketVector', 'Point') - self.addSocket(False, 'NodeSocketFloatFactor', 'HAS_Point') + self.addSocket(False, 'NodeSocketFloat', 'HAS_Point') self.addSocket(False, 'NodeSocketFloat', 'Scale') self.addSocket(False, 'NodeSocketVector', 'Center') self.addSocket(False, 'NodeSocketFloat', 'brickwidth') @@ -255,13 +255,19 @@ def getNodetree(self, name): self.node_tree=bpy.data.node_groups[name] def addSocket(self, is_output, sockettype, name): - #for now duplicated socket names are not allowed - if is_output==True: - if self.node_tree.nodes['GroupOutput'].inputs.find(name)==-1: - socket=self.node_tree.outputs.new(sockettype, name) - elif is_output==False: - if self.node_tree.nodes['GroupInput'].outputs.find(name)==-1: - socket=self.node_tree.inputs.new(sockettype, name) + if bpy.app.version >= (4, 0, 0): + if is_output==True: + socket = self.node_tree.interface.new_socket(name, in_out='OUTPUT', socket_type=sockettype) + else: + socket = self.node_tree.interface.new_socket(name, in_out='INPUT', socket_type=sockettype) + else: + #for now duplicated socket names are not allowed + if is_output==True: + if self.node_tree.nodes['GroupOutput'].inputs.find(name)==-1: + socket=self.node_tree.outputs.new(sockettype, name) + elif is_output==False: + if self.node_tree.nodes['GroupInput'].outputs.find(name)==-1: + socket=self.node_tree.inputs.new(sockettype, name) return socket def addNode(self, nodetype, attrs): diff --git a/uv_map_tile_pattern_1_addin.py b/uv_map_tile_pattern_1_addin.py index f388891..819d891 100644 --- a/uv_map_tile_pattern_1_addin.py +++ b/uv_map_tile_pattern_1_addin.py @@ -86,7 +86,7 @@ def createNodetree(self, name) : self.addNode('ShaderNodeMixRGB', { 'name':'Node55' }) #Sockets self.addSocket(False, 'NodeSocketVector', 'Vector') - self.addSocket(False, 'NodeSocketFloatFactor', 'HAS_Vector') + self.addSocket(False, 'NodeSocketFloat', 'HAS_Vector') self.addSocket(False, 'NodeSocketFloat', 'scale') self.addSocket(True, 'NodeSocketVector', 'UV') self.addSocket(True, 'NodeSocketVector', 'cellID') @@ -182,13 +182,19 @@ def getNodetree(self, name): self.node_tree=bpy.data.node_groups[name] def addSocket(self, is_output, sockettype, name): - #for now duplicated socket names are not allowed - if is_output==True: - if self.node_tree.nodes['GroupOutput'].inputs.find(name)==-1: - socket=self.node_tree.outputs.new(sockettype, name) - elif is_output==False: - if self.node_tree.nodes['GroupInput'].outputs.find(name)==-1: - socket=self.node_tree.inputs.new(sockettype, name) + if bpy.app.version >= (4, 0, 0): + if is_output==True: + socket = self.node_tree.interface.new_socket(name, in_out='OUTPUT', socket_type=sockettype) + else: + socket = self.node_tree.interface.new_socket(name, in_out='INPUT', socket_type=sockettype) + else: + #for now duplicated socket names are not allowed + if is_output==True: + if self.node_tree.nodes['GroupOutput'].inputs.find(name)==-1: + socket=self.node_tree.outputs.new(sockettype, name) + elif is_output==False: + if self.node_tree.nodes['GroupInput'].outputs.find(name)==-1: + socket=self.node_tree.inputs.new(sockettype, name) return socket def addNode(self, nodetype, attrs): diff --git a/uv_map_tile_pattern_2_addin.py b/uv_map_tile_pattern_2_addin.py index 51f30b4..efb820b 100644 --- a/uv_map_tile_pattern_2_addin.py +++ b/uv_map_tile_pattern_2_addin.py @@ -149,7 +149,7 @@ def createNodetree(self, name) : self.addNode('ShaderNodeCombineXYZ', { 'name':'Node117' }) #Sockets self.addSocket(False, 'NodeSocketVector', 'Vector') - self.addSocket(False, 'NodeSocketFloatFactor', 'HAS_Vector') + self.addSocket(False, 'NodeSocketFloat', 'HAS_Vector') self.addSocket(False, 'NodeSocketFloat', 'scale') self.addSocket(True, 'NodeSocketVector', 'UV') self.addSocket(True, 'NodeSocketVector', 'cellID') @@ -335,13 +335,19 @@ def getNodetree(self, name): self.node_tree=bpy.data.node_groups[name] def addSocket(self, is_output, sockettype, name): - #for now duplicated socket names are not allowed - if is_output==True: - if self.node_tree.nodes['GroupOutput'].inputs.find(name)==-1: - socket=self.node_tree.outputs.new(sockettype, name) - elif is_output==False: - if self.node_tree.nodes['GroupInput'].outputs.find(name)==-1: - socket=self.node_tree.inputs.new(sockettype, name) + if bpy.app.version >= (4, 0, 0): + if is_output==True: + socket = self.node_tree.interface.new_socket(name, in_out='OUTPUT', socket_type=sockettype) + else: + socket = self.node_tree.interface.new_socket(name, in_out='INPUT', socket_type=sockettype) + else: + #for now duplicated socket names are not allowed + if is_output==True: + if self.node_tree.nodes['GroupOutput'].inputs.find(name)==-1: + socket=self.node_tree.outputs.new(sockettype, name) + elif is_output==False: + if self.node_tree.nodes['GroupInput'].outputs.find(name)==-1: + socket=self.node_tree.inputs.new(sockettype, name) return socket def addNode(self, nodetype, attrs):