Nodes: use auto registration for nodes #110686

Merged
Jacques Lucke merged 29 commits from JacquesLucke/blender:auto-node-register into main 2023-08-09 22:01:10 +02:00
3 changed files with 13 additions and 8 deletions
Showing only changes of commit fc1f18d7f6 - Show all commits

View File

@ -6,7 +6,7 @@ set(DISCOVER_NODES_PATH ${CMAKE_CURRENT_SOURCE_DIR}/intern/discover_nodes.py)
function(add_node_discovery
lib_name
source_directory
sources
output_file
output_function
)
@ -17,12 +17,11 @@ function(add_node_discovery
COMMAND
${PYTHON_EXECUTABLE}
${DISCOVER_NODES_PATH}
${source_directory}
${CMAKE_CURRENT_SOURCE_DIR}
${output_file}
${output_function}
${sources}
DEPENDS
# TODO: pass this in as parameter and figure out how to pass these
# files to discover_nodes.py instead of the root directory
${SRC}
${DISCOVER_NODES_PATH}
)

View File

@ -260,7 +260,7 @@ endif()
add_node_discovery(
bf_nodes_geometry_generated
${CMAKE_CURRENT_SOURCE_DIR}/nodes
"${SRC}"
${CMAKE_CURRENT_BINARY_DIR}/register_geometry_nodes.cc
register_geometry_nodes
)

View File

@ -5,9 +5,10 @@
'''
Usage:
python discover_nodes.py
<path/to/sources>
<sources/root>
<path/to/output.cc>
<generated_function_name>
<source>...
The goal is to make it easy for nodes to register themselves without having to have
a central place that registers all nodes manually. A node can use this mechanism by
@ -20,11 +21,12 @@ import re
import sys
from pathlib import Path
source_files_dir = Path(sys.argv[1])
source_root = Path(sys.argv[1])
macro_name = "NOD_REGISTER_NODE"
discover_suffix = "_discover"
output_cc_file = Path(sys.argv[2])
function_to_generate = sys.argv[3]
relative_source_files = sys.argv[4:]
include_lines = []
decl_lines = []
@ -42,7 +44,11 @@ re_namespace_end = r"^\} // namespace ([\w:]+)"
re_macro = r"MACRO\((\w+)\)".replace("MACRO", macro_name)
re_all = f"({re_namespace_begin})|({re_namespace_end})|({re_macro})"
for path in source_files_dir.glob("*.cc"):
for relative_source_file in relative_source_files:
if not relative_source_file.endswith(".cc"):
continue
path = source_root / relative_source_file
# Read the source code.
with open(path) as f:
code = f.read()