From 159a89ef1e0357e517f41661e9716a2885932742 Mon Sep 17 00:00:00 2001 From: ocupe Date: Sat, 2 Mar 2024 14:48:46 +0100 Subject: [PATCH 1/5] Make addon work with Blender 4.0 --- __init__.py | 2 +- projector.py | 29 ++++++++++++++++++----------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/__init__.py b/__init__.py index 61e3e13..dffc486 100644 --- a/__init__.py +++ b/__init__.py @@ -7,7 +7,7 @@ "author": "Jonas Schell", "description": "Easy Projector creation and modification.", "blender": (2, 81, 0), - "version": (2023, 2, 0), + "version": (2024, 1, 0), "location": "3D Viewport > Add > Light > Projector", "category": "Lighting", "wiki_url": "https://github.com/Ocupe/Projectors/wiki", diff --git a/projector.py b/projector.py index 501cf8c..129938a 100644 --- a/projector.py +++ b/projector.py @@ -96,9 +96,8 @@ def add_projector_node_tree_to_spot(spot): node_group = bpy.data.node_groups.new('_Projector', 'ShaderNodeTree') # Create output sockets for the node group. - output = node_group.outputs - output.new('NodeSocketVector', 'texture vector') - output.new('NodeSocketColor', 'color') + node_group.interface.new_socket('TextureVector', in_out="OUTPUT", socket_type='NodeSocketVector') + node_group.interface.new_socket('Color', in_out="OUTPUT", socket_type='NodeSocketColor') # # Inside Group Node # # ##################### @@ -116,6 +115,12 @@ def add_projector_node_tree_to_spot(spot): tex = nodes.new('ShaderNodeTexCoord') tex.location = auto_pos(200) + geo = nodes.new('ShaderNodeNewGeometry') + geo.location = auto_pos(0, -300) + vec_transform = nodes.new('ShaderNodeVectorTransform') + vec_transform.location = auto_pos(200) + vec_transform.vector_type = 'NORMAL' + map_1 = nodes.new('ShaderNodeMapping') map_1.vector_type = 'TEXTURE' # Flip the image horizontally and vertically to display it the intended way. @@ -194,7 +199,11 @@ def add_projector_node_tree_to_spot(spot): # ############## # Link inside group node - tree.links.new(tex.outputs['Normal'], map_1.inputs['Vector']) + if(bpy.app.version >= (4, 0)): + tree.links.new(geo.outputs['Incoming'], vec_transform.inputs['Vector']) + tree.links.new(vec_transform.outputs['Vector'], map_1.inputs['Vector']) + else: + tree.links.new(tex.outputs['Normal'], map_1.inputs['Vector']) tree.links.new(map_1.outputs['Vector'], sep.inputs['Vector']) tree.links.new(sep.outputs[0], div_1.inputs[0]) # X -> value0 @@ -218,8 +227,8 @@ def add_projector_node_tree_to_spot(spot): tree.links.new(checker_tex.outputs['Color'], mix_rgb.inputs[2]) # Link in root - root_tree.links.new(group.outputs[0], user_texture.inputs['Vector']) - root_tree.links.new(group.outputs[1], emission.inputs['Color']) + root_tree.links.new(group.outputs['TextureVector'], user_texture.inputs['Vector']) + root_tree.links.new(group.outputs['Color'], emission.inputs['Color']) root_tree.links.new(emission.outputs['Emission'], output.inputs['Surface']) # Pixel Grid Setup @@ -362,12 +371,10 @@ def create_pixel_grid_node_group(): '_Projectors-Addon_PixelGrid', 'ShaderNodeTree') # Create input/output sockets for the node group. - inputs = node_group.inputs - inputs.new('NodeSocketShader', 'Shader') - inputs.new('NodeSocketVector', 'Vector') + node_group.interface.new_socket('PixelGridOutput_Shader', socket_type='NodeSocketShader') + node_group.interface.new_socket('PixelGridOutput_Vector', socket_type='NodeSocketVector') - outputs = node_group.outputs - outputs.new('NodeSocketShader', 'Shader') + node_group.interface.new_socket('PixelGridOutput_Shader', in_out='OUTPUT', socket_type='NodeSocketShader') nodes = node_group.nodes From 9ea74f81834bdab6b9ff12a4f477c7fda6d6126f Mon Sep 17 00:00:00 2001 From: ocupe Date: Sat, 2 Mar 2024 15:02:44 +0100 Subject: [PATCH 2/5] update version nr --- __init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/__init__.py b/__init__.py index dffc486..0288f93 100644 --- a/__init__.py +++ b/__init__.py @@ -3,11 +3,11 @@ from . import operators bl_info = { - "name": "Projector", + "name": "Projector RC1", "author": "Jonas Schell", "description": "Easy Projector creation and modification.", "blender": (2, 81, 0), - "version": (2024, 1, 0), + "version": (2024, 0, 0), "location": "3D Viewport > Add > Light > Projector", "category": "Lighting", "wiki_url": "https://github.com/Ocupe/Projectors/wiki", From 3dc128f60c001261e14a68db78775942227c5a45 Mon Sep 17 00:00:00 2001 From: ocupe Date: Sun, 10 Mar 2024 19:13:26 +0100 Subject: [PATCH 3/5] set shadow soft size to 0 to get better results --- projector.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projector.py b/projector.py index 129938a..927ab40 100644 --- a/projector.py +++ b/projector.py @@ -485,7 +485,7 @@ def create_projector(context): spot.scale = (.01, .01, .01) spot.data.spot_size = math.pi spot.data.spot_blend = 0 - spot.data.shadow_soft_size = 0.00000001 + spot.data.shadow_soft_size = 0.0 spot.hide_select = True spot[ADDON_ID.format('spot')] = True spot.data.cycles.use_multiple_importance_sampling = False From 32956b958325cae2b0083e5fea0bfa1da60b3cf0 Mon Sep 17 00:00:00 2001 From: ocupe Date: Sun, 10 Mar 2024 19:27:58 +0100 Subject: [PATCH 4/5] handle blender 3 and 4 --- projector.py | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/projector.py b/projector.py index 927ab40..df267ab 100644 --- a/projector.py +++ b/projector.py @@ -96,8 +96,13 @@ def add_projector_node_tree_to_spot(spot): node_group = bpy.data.node_groups.new('_Projector', 'ShaderNodeTree') # Create output sockets for the node group. - node_group.interface.new_socket('TextureVector', in_out="OUTPUT", socket_type='NodeSocketVector') - node_group.interface.new_socket('Color', in_out="OUTPUT", socket_type='NodeSocketColor') + if(bpy.app.version >= (4, 0)): + node_group.interface.new_socket('texture vector', in_out="OUTPUT", socket_type='NodeSocketVector') + node_group.interface.new_socket('color', in_out="OUTPUT", socket_type='NodeSocketColor') + else: + output = node_group.outputs + output.new('NodeSocketVector', 'texture vector') + output.new('NodeSocketColor', 'color') # # Inside Group Node # # ##################### @@ -227,8 +232,8 @@ def add_projector_node_tree_to_spot(spot): tree.links.new(checker_tex.outputs['Color'], mix_rgb.inputs[2]) # Link in root - root_tree.links.new(group.outputs['TextureVector'], user_texture.inputs['Vector']) - root_tree.links.new(group.outputs['Color'], emission.inputs['Color']) + root_tree.links.new(group.outputs['texture vector'], user_texture.inputs['Vector']) + root_tree.links.new(group.outputs['color'], emission.inputs['Color']) root_tree.links.new(emission.outputs['Emission'], output.inputs['Surface']) # Pixel Grid Setup @@ -371,10 +376,18 @@ def create_pixel_grid_node_group(): '_Projectors-Addon_PixelGrid', 'ShaderNodeTree') # Create input/output sockets for the node group. - node_group.interface.new_socket('PixelGridOutput_Shader', socket_type='NodeSocketShader') - node_group.interface.new_socket('PixelGridOutput_Vector', socket_type='NodeSocketVector') + if(bpy.app.version >= (4, 0)): + node_group.interface.new_socket('Shader', socket_type='NodeSocketShader') + node_group.interface.new_socket('Vector', socket_type='NodeSocketVector') + + node_group.interface.new_socket('Shader', in_out='OUTPUT', socket_type='NodeSocketShader') + else: + inputs = node_group.inputs + inputs.new('NodeSocketShader', 'Shader') + inputs.new('NodeSocketVector', 'Vector') - node_group.interface.new_socket('PixelGridOutput_Shader', in_out='OUTPUT', socket_type='NodeSocketShader') + outputs = node_group.outputs + outputs.new('NodeSocketShader', 'Shader') nodes = node_group.nodes From 2f46883605f45560e2964b97d546828126d2cb87 Mon Sep 17 00:00:00 2001 From: ocupe Date: Sun, 10 Mar 2024 19:29:09 +0100 Subject: [PATCH 5/5] Update Projector version in __init__.py --- __init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/__init__.py b/__init__.py index 0288f93..dffc486 100644 --- a/__init__.py +++ b/__init__.py @@ -3,11 +3,11 @@ from . import operators bl_info = { - "name": "Projector RC1", + "name": "Projector", "author": "Jonas Schell", "description": "Easy Projector creation and modification.", "blender": (2, 81, 0), - "version": (2024, 0, 0), + "version": (2024, 1, 0), "location": "3D Viewport > Add > Light > Projector", "category": "Lighting", "wiki_url": "https://github.com/Ocupe/Projectors/wiki",