Skip to content
128 changes: 118 additions & 10 deletions NodeToPython/export/node_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ class NTPNodeSetting(NamedTuple):
name_: str
st_: ST
min_version_: tuple = (4, 2, 0)
max_version_: tuple = (5, 1, 0)
max_version_: tuple = (5, 2, 0)

class NodeInfo(NamedTuple):
attributes_: list[NTPNodeSetting]
min_version_: tuple = (4, 2, 0)
max_version_: tuple = (5, 1, 0)
max_version_: tuple = (5, 2, 0)

node_settings : dict[str, NodeInfo] = {
'CompositorNodeAlphaOver' : NodeInfo(
Expand Down Expand Up @@ -647,6 +647,11 @@ class NodeInfo(NamedTuple):
]
),

'CompositorNodeMaskToSDF' : NodeInfo(
[],
min_version_ = (5, 1, 0)
),

'CompositorNodeMath' : NodeInfo(
[
NTPNodeSetting("operation", ST.ENUM),
Expand Down Expand Up @@ -804,6 +809,11 @@ class NodeInfo(NamedTuple):
max_version_ = (5, 0, 0)
),

'CompositorNodeSequencerStripInfo' : NodeInfo(
[],
min_version_ = (5, 1, 0)
),

'CompositorNodeSetAlpha' : NodeInfo(
[
NTPNodeSetting("mode", ST.ENUM, max_version_=(5, 0, 0)),
Expand Down Expand Up @@ -1093,6 +1103,11 @@ class NodeInfo(NamedTuple):
[]
),

'FunctionNodeMatrixSVD' : NodeInfo(
[],
min_version_ = (5, 1, 0)
),

'FunctionNodeProjectPoint' : NodeInfo(
[]
),
Expand Down Expand Up @@ -1220,6 +1235,13 @@ class NodeInfo(NamedTuple):
]
),

'GeometryNodeBoneInfo' : NodeInfo(
[
NTPNodeSetting("transform_space", ST.ENUM),
],
min_version_ = (5, 1, 0)
),

'GeometryNodeBoundBox' : NodeInfo(
[]
),
Expand Down Expand Up @@ -1282,6 +1304,11 @@ class NodeInfo(NamedTuple):
[]
),

'GeometryNodeCubeGridTopology' : NodeInfo(
[],
min_version_ = (5, 1, 0)
),

'GeometryNodeCurveArc' : NodeInfo(
[
NTPNodeSetting("mode", ST.ENUM),
Expand Down Expand Up @@ -1495,6 +1522,13 @@ class NodeInfo(NamedTuple):
min_version_ = (5, 0, 0)
),

'GeometryNodeFieldToList' : NodeInfo(
[
NTPNodeSetting("active_index", ST.INT),
],
min_version_ = (5, 1, 0)
),

'GeometryNodeFieldVariance' : NodeInfo(
[
NTPNodeSetting("data_type", ST.ENUM),
Expand Down Expand Up @@ -1542,6 +1576,11 @@ class NodeInfo(NamedTuple):
[]
),

'GeometryNodeGetGeometryBundle' : NodeInfo(
[],
min_version_ = (5, 1, 0)
),

'GeometryNodeGetNamedGrid' : NodeInfo(
[
NTPNodeSetting("data_type", ST.ENUM),
Expand Down Expand Up @@ -1590,11 +1629,25 @@ class NodeInfo(NamedTuple):
min_version_ = (5, 0, 0)
),

'GeometryNodeGridClip' : NodeInfo(
[
NTPNodeSetting("data_type", ST.ENUM),
],
min_version_ = (5, 1, 0)
),

'GeometryNodeGridCurl' : NodeInfo(
[],
min_version_ = (5, 0, 0)
),

'GeometryNodeGridDilateAndErode' : NodeInfo(
[
NTPNodeSetting("data_type", ST.ENUM),
],
min_version_ = (5, 1, 0)
),

'GeometryNodeGridDivergence' : NodeInfo(
[],
min_version_ = (5, 0, 0)
Expand All @@ -1617,6 +1670,20 @@ class NodeInfo(NamedTuple):
min_version_ = (5, 0, 0)
),

'GeometryNodeGridMean' : NodeInfo(
[
NTPNodeSetting("data_type", ST.ENUM),
],
min_version_ = (5, 1, 0)
),

'GeometryNodeGridMedian' : NodeInfo(
[
NTPNodeSetting("data_type", ST.ENUM),
],
min_version_ = (5, 1, 0)
),

'GeometryNodeGridPrune' : NodeInfo(
[
NTPNodeSetting("data_type", ST.ENUM),
Expand All @@ -1628,6 +1695,13 @@ class NodeInfo(NamedTuple):
[]
),

'GeometryNodeGridToPoints' : NodeInfo(
[
NTPNodeSetting("data_type", ST.ENUM),
],
min_version_ = (5, 1, 0)
),

'GeometryNodeGridVoxelize' : NodeInfo(
[
NTPNodeSetting("data_type", ST.ENUM),
Expand Down Expand Up @@ -1873,12 +1947,15 @@ class NodeInfo(NamedTuple):
[
NTPNodeSetting("data_type", ST.ENUM),
],
min_version_ = (5, 0, 0)
min_version_ = (5, 0, 0),
max_version_ = (5, 1, 0)
),

'GeometryNodeListGetItem' : NodeInfo(
[
NTPNodeSetting("data_type", ST.ENUM),
NTPNodeSetting("data_type", ST.ENUM, max_version_=(5, 1, 0)),
NTPNodeSetting("socket_type", ST.ENUM, min_version_=(5, 1, 0)),
NTPNodeSetting("structure_type", ST.ENUM, min_version_=(5, 1, 0)),
],
min_version_ = (5, 0, 0)
),
Expand Down Expand Up @@ -2048,7 +2125,9 @@ class NodeInfo(NamedTuple):
),

'GeometryNodeRealizeInstances' : NodeInfo(
[]
[
NTPNodeSetting("realize_to_point_domain", ST.BOOL, min_version_=(5, 1, 0)),
]
),

'GeometryNodeRemoveAttribute' : NodeInfo(
Expand Down Expand Up @@ -2224,6 +2303,11 @@ class NodeInfo(NamedTuple):
[]
),

'GeometryNodeSetGeometryBundle' : NodeInfo(
[],
min_version_ = (5, 1, 0)
),

'GeometryNodeSetGeometryName' : NodeInfo(
[],
min_version_ = (4, 3, 0)
Expand Down Expand Up @@ -2362,11 +2446,11 @@ class NodeInfo(NamedTuple):

'GeometryNodeStringToCurves' : NodeInfo(
[
NTPNodeSetting("align_x", ST.ENUM),
NTPNodeSetting("align_y", ST.ENUM),
NTPNodeSetting("font", ST.FONT),
NTPNodeSetting("overflow", ST.ENUM),
NTPNodeSetting("pivot_mode", ST.ENUM),
NTPNodeSetting("align_x", ST.ENUM, max_version_=(5, 1, 0)),
NTPNodeSetting("align_y", ST.ENUM, max_version_=(5, 1, 0)),
NTPNodeSetting("font", ST.FONT, max_version_=(5, 1, 0)),
NTPNodeSetting("overflow", ST.ENUM, max_version_=(5, 1, 0)),
NTPNodeSetting("pivot_mode", ST.ENUM, max_version_=(5, 1, 0)),
]
),

Expand Down Expand Up @@ -2548,6 +2632,14 @@ class NodeInfo(NamedTuple):
]
),

'NodeGetBundleItem' : NodeInfo(
[
NTPNodeSetting("socket_type", ST.ENUM),
NTPNodeSetting("structure_type", ST.ENUM),
],
min_version_ = (5, 1, 0)
),

'NodeGroup' : NodeInfo(
[
NTPNodeSetting("node_tree", ST.NODE_TREE),
Expand Down Expand Up @@ -2584,6 +2676,14 @@ class NodeInfo(NamedTuple):
min_version_ = (5, 0, 0)
),

'NodeStoreBundleItem' : NodeInfo(
[
NTPNodeSetting("socket_type", ST.ENUM),
NTPNodeSetting("structure_type", ST.ENUM),
],
min_version_ = (5, 1, 0)
),

'ShaderNodeAddShader' : NodeInfo(
[]
),
Expand Down Expand Up @@ -2852,6 +2952,7 @@ class NodeInfo(NamedTuple):

'ShaderNodeNormalMap' : NodeInfo(
[
NTPNodeSetting("convention", ST.ENUM, min_version_=(5, 1, 0)),
NTPNodeSetting("space", ST.ENUM),
NTPNodeSetting("uv_map", ST.STRING),
]
Expand Down Expand Up @@ -2927,6 +3028,13 @@ class NodeInfo(NamedTuple):
min_version_ = (5, 0, 0)
),

'ShaderNodeRaycast' : NodeInfo(
[
NTPNodeSetting("only_local", ST.BOOL),
],
min_version_ = (5, 1, 0)
),

'ShaderNodeScript' : NodeInfo(
[
NTPNodeSetting("bytecode", ST.STRING),
Expand Down
49 changes: 40 additions & 9 deletions NodeToPython/export/node_tree_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,16 @@
bpy.types.NodeTreeInterfaceSocketMatrix,
bpy.types.NodeTreeInterfaceSocketObject,
bpy.types.NodeTreeInterfaceSocketShader,
bpy.types.NodeTreeInterfaceSocketTexture
bpy.types.NodeTreeInterfaceSocketTexture,
}

if bpy.app.version >= (5, 0, 0):
NO_DEFAULT_SOCKETS.add(bpy.types.NodeTreeInterfaceSocketBundle)
NO_DEFAULT_SOCKETS.add(bpy.types.NodeTreeInterfaceSocketClosure)

if bpy.app.version >= (5, 1, 0):
NO_DEFAULT_SOCKETS.add(bpy.types.NodeTreeInterfaceSocketFont)

#node input sockets that are messy to set default values for
DONT_SET_DEFAULTS = {
'NodeSocketGeometry',
Expand Down Expand Up @@ -573,24 +576,48 @@ def _set_tree_socket_defaults(
elif type(dv) == mathutils.Euler:
dv = vec3_to_py_str(dv)
elif type(dv) == bpy_prop_array:
dv = array_to_py_str(dv)
if hasattr(socket_interface, "dimensions"):
dimensions = getattr(socket_interface, "dimensions")
if dimensions != len(dv):
self._operator.report(
{'WARNING'},
f"Mismatched dimensions ({dimensions}) and "
f"default value ({len(dv)}) for socket {socket_var}"
)
if dimensions <= len(dv):
dv = vec_to_py_str(dv, dimensions)
else:
return
else:
dv = array_to_py_str(dv)
elif type(dv) == str:
dv = str_to_py_str(dv)
elif type(dv) == mathutils.Vector:
if len(dv) == 2:
dv = vec2_to_py_str(dv)
elif len(dv) == 3:
dv = vec3_to_py_str(dv)
elif len(dv) == 4:
dv = vec4_to_py_str(dv)
dimensions = getattr(socket_interface, "dimensions")
if dimensions != len(dv):
self._operator.report(
{'WARNING'},
f"Mismatched dimensions ({dimensions}) and "
f"default value ({len(dv)}) for socket {socket_var}"
)
return
if dimensions in {2, 3, 4}:
dv = vec_to_py_str(dv, dimensions)
else:
self._operator.report(
{'WARNING'},
f"Incorrect number of dimensions {dimensions} "
f"found for socket {socket_var}"
)
return
self._write(f"{socket_var}.default_value = {dv}")

# min value
if hasattr(socket_interface, "min_value"):
min_val = getattr(socket_interface, "min_value")
self._write(f"{socket_var}.min_value = {min_val}")
# max value
if hasattr(socket_interface, "min_value"):
if hasattr(socket_interface, "max_value"):
max_val = getattr(socket_interface, "max_value")
self._write(f"{socket_var}.max_value = {max_val}")

Expand Down Expand Up @@ -1509,6 +1536,10 @@ def _set_input_defaults(self, node: bpy.types.Node) -> None:
self._in_file_inputs(input, socket_var, "textures")
default_val = None

elif input.bl_idname == 'NodeSocketFont':
self._in_file_inputs(input, socket_var, "fonts")
default_val = None

else:
default_val = getattr(input, "default_value")

Expand Down
19 changes: 17 additions & 2 deletions NodeToPython/export/ntp_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
}

MIN_BLENDER_VERSION = (4, 2, 0)
MAX_BLENDER_VERSION = (5, 1, 0)
MAX_BLENDER_VERSION = (5, 2, 0)

class NodeTreeInfo():
def __init__(self):
Expand Down Expand Up @@ -414,7 +414,22 @@ def dfs(nt: bpy.types.NodeTree) -> None:
node_info._lib_dependencies[relative_path].append(nt)
return
else:
print(f"Library {lib_path} didn't seem essential, copying node groups")
# Try to link to current Blender version
# TODO: this fails when the tree interface changes
#for parent in lib_path.parents:
# if parent.name == "datafiles":
# relative_path = lib_path.relative_to(parent)
# if relative_path not in node_info._lib_dependencies:
# node_info._lib_dependencies[relative_path] = []
# node_info._lib_dependencies[relative_path].append(nt)
# return
self.report(
{'WARNING'},
f"Performing deep copy of node group \"{nt.name}\". "
f"Library {lib_path} was not included with current "
f"Blender version. If this node group came with Blender, "
f"please upgrade your node group to the current version"
)

if nt not in self._visited:
self._visited.add(nt)
Expand Down
Loading