Skip to content

Commit

Permalink
Merge pull request #37 from Ocupe/fix/blender-4
Browse files Browse the repository at this point in the history
Make addon work with Blender 4.0
  • Loading branch information
Ocupe authored Mar 10, 2024
2 parents bad17c7 + 2f46883 commit b66587f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
2 changes: 1 addition & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
44 changes: 32 additions & 12 deletions projector.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +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.
output = node_group.outputs
output.new('NodeSocketVector', 'texture vector')
output.new('NodeSocketColor', 'color')
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 #
# #####################
Expand All @@ -116,6 +120,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.
Expand Down Expand Up @@ -194,7 +204,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
Expand All @@ -218,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[0], user_texture.inputs['Vector'])
root_tree.links.new(group.outputs[1], 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
Expand Down Expand Up @@ -362,12 +376,18 @@ 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')
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')

outputs = node_group.outputs
outputs.new('NodeSocketShader', 'Shader')
outputs = node_group.outputs
outputs.new('NodeSocketShader', 'Shader')

nodes = node_group.nodes

Expand Down Expand Up @@ -478,7 +498,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
Expand Down

0 comments on commit b66587f

Please sign in to comment.