Listing the "Blender Foundation" as copyright holder implied the Blender Foundation holds copyright to files which may include work from many developers. While keeping copyright on headers makes sense for isolated libraries, Blender's own code may be refactored or moved between files in a way that makes the per file copyright holders less meaningful. Copyright references to the "Blender Foundation" have been replaced with "Blender Authors", with the exception of `./extern/` since these this contains libraries which are more isolated, any changed to license headers there can be handled on a case-by-case basis. Some directories in `./intern/` have also been excluded: - `./intern/cycles/` it's own `AUTHORS` file is planned. - `./intern/opensubdiv/`. An "AUTHORS" file has been added, using the chromium projects authors file as a template. Design task: #110784 Ref !110783.
55 lines
1.6 KiB
Python
55 lines
1.6 KiB
Python
# SPDX-FileCopyrightText: 2009-2023 Blender Authors
|
|
#
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
__all__ = (
|
|
"find_node_input",
|
|
)
|
|
|
|
|
|
def connect_sockets(input, output):
|
|
"""
|
|
Connect sockets in a node tree.
|
|
|
|
This is useful because the links created through the normal Python API are
|
|
invalid when one of the sockets is a virtual socket (grayed out sockets in
|
|
Group Input and Group Output nodes).
|
|
|
|
It replaces node_tree.links.new(input, output)
|
|
"""
|
|
import bpy
|
|
|
|
# Swap sockets if they are not passed in the proper order
|
|
if input.is_output and not output.is_output:
|
|
input, output = output, input
|
|
|
|
input_node = output.node
|
|
output_node = input.node
|
|
|
|
if input_node.id_data is not output_node.id_data:
|
|
print("Sockets do not belong to the same node tree")
|
|
return
|
|
|
|
if type(input) == type(output) == bpy.types.NodeSocketVirtual:
|
|
print("Cannot connect two virtual sockets together")
|
|
return
|
|
|
|
if output_node.type == 'GROUP_OUTPUT' and type(input) == bpy.types.NodeSocketVirtual:
|
|
output_node.id_data.outputs.new(type(output).__name__, output.name)
|
|
input = output_node.inputs[-2]
|
|
|
|
if input_node.type == 'GROUP_INPUT' and type(output) == bpy.types.NodeSocketVirtual:
|
|
output_node.id_data.inputs.new(type(input).__name__, input.name)
|
|
output = input_node.outputs[-2]
|
|
|
|
return input_node.id_data.links.new(input, output)
|
|
|
|
|
|
# XXX Names are not unique. Returns the first match.
|
|
def find_node_input(node, name):
|
|
for input in node.inputs:
|
|
if input.name == name:
|
|
return input
|
|
|
|
return None
|