[Bf-blender-cvs] [a2ca81bf6e9] functions: initial version of less automatic inferencer
Jacques Lucke
noreply at git.blender.org
Wed Mar 20 13:04:16 CET 2019
Commit: a2ca81bf6e9f4520c45aefe079e73fd89c4a78aa
Author: Jacques Lucke
Date: Wed Mar 20 12:46:30 2019 +0100
Branches: functions
https://developer.blender.org/rBa2ca81bf6e9f4520c45aefe079e73fd89c4a78aa
initial version of less automatic inferencer
===================================================================
M release/scripts/startup/function_nodes/base.py
M release/scripts/startup/function_nodes/nodes/append_to_list.py
M release/scripts/startup/function_nodes/nodes/combine_lists.py
M release/scripts/startup/function_nodes/nodes/create_list.py
M release/scripts/startup/function_nodes/nodes/get_list_element.py
M release/scripts/startup/function_nodes/socket_decl.py
M release/scripts/startup/function_nodes/update_sockets.py
===================================================================
diff --git a/release/scripts/startup/function_nodes/base.py b/release/scripts/startup/function_nodes/base.py
index cbd4c87dadc..8fc36353c53 100644
--- a/release/scripts/startup/function_nodes/base.py
+++ b/release/scripts/startup/function_nodes/base.py
@@ -120,8 +120,9 @@ class BaseNode:
props.settings_repr = repr(settings)
def draw_socket(self, socket, layout):
- decl = self.storage.decl_per_socket[socket]
- index = self.storage.decl_index_per_socket[socket]
+ storage = self.storage
+ decl = storage.decl_per_socket[socket]
+ index = storage.decl_index_per_socket[socket]
decl.draw_socket(layout, self, socket, index)
@classmethod
@@ -184,6 +185,9 @@ class BaseSocket:
def to_id(self, node):
return (node, self.is_output, self.identifier)
+ def get_decl(self, node):
+ return node.storage.decl_per_socket[self]
+
class FunctionNode(BaseNode):
pass
diff --git a/release/scripts/startup/function_nodes/nodes/append_to_list.py b/release/scripts/startup/function_nodes/nodes/append_to_list.py
index c52d679faef..b321bd5d3f5 100644
--- a/release/scripts/startup/function_nodes/nodes/append_to_list.py
+++ b/release/scripts/startup/function_nodes/nodes/append_to_list.py
@@ -1,17 +1,17 @@
import bpy
from .. base import FunctionNode
-from .. socket_decl import BaseSocketDecl, ListSocketDecl
+from .. socket_decl import ListSocketDecl
class AppendToListNode(bpy.types.Node, FunctionNode):
bl_idname = "fn_AppendToListNode"
bl_label = "Append to List"
- active_type: BaseSocketDecl.Property()
+ active_type: ListSocketDecl.Property()
def get_sockets(self):
return [
- ListSocketDecl("list", "List", "active_type"),
- BaseSocketDecl("value", "Value", "active_type"),
+ ListSocketDecl("list", "List", "active_type", "LIST"),
+ ListSocketDecl("value", "Value", "active_type", "BASE"),
], [
- ListSocketDecl("list", "List", "active_type"),
+ ListSocketDecl("list", "List", "active_type", "LIST"),
]
\ No newline at end of file
diff --git a/release/scripts/startup/function_nodes/nodes/combine_lists.py b/release/scripts/startup/function_nodes/nodes/combine_lists.py
index 343d633e5e2..1aa3519440c 100644
--- a/release/scripts/startup/function_nodes/nodes/combine_lists.py
+++ b/release/scripts/startup/function_nodes/nodes/combine_lists.py
@@ -10,8 +10,8 @@ class CombineListsNode(bpy.types.Node, FunctionNode):
def get_sockets(self):
return [
- ListSocketDecl("list1", "List 1", "active_type"),
- ListSocketDecl("list2", "List 2", "active_type"),
+ ListSocketDecl("list1", "List 1", "active_type", "LIST"),
+ ListSocketDecl("list2", "List 2", "active_type", "LIST"),
], [
- ListSocketDecl("list", "List", "active_type"),
+ ListSocketDecl("list", "List", "active_type", "LIST"),
]
\ No newline at end of file
diff --git a/release/scripts/startup/function_nodes/nodes/create_list.py b/release/scripts/startup/function_nodes/nodes/create_list.py
index 0216f36f3ea..fb3b7289fb2 100644
--- a/release/scripts/startup/function_nodes/nodes/create_list.py
+++ b/release/scripts/startup/function_nodes/nodes/create_list.py
@@ -1,7 +1,7 @@
import bpy
from bpy.props import *
from .. base import FunctionNode
-from .. socket_decl import VariadicListDecl, FixedSocketDecl
+from .. socket_decl import PackListDecl, FixedSocketDecl
from .. sockets import type_infos
class CreateListNode(bpy.types.Node, FunctionNode):
@@ -9,11 +9,11 @@ class CreateListNode(bpy.types.Node, FunctionNode):
bl_label = "Create List"
active_type: StringProperty(default="Float")
- variadic: VariadicListDecl.Property()
+ variadic: PackListDecl.Property()
def get_sockets(self):
return [
- VariadicListDecl("inputs", "variadic", self.active_type),
+ PackListDecl("inputs", "variadic", self.active_type),
], [
FixedSocketDecl("output", "List", type_infos.to_list(self.active_type)),
]
\ No newline at end of file
diff --git a/release/scripts/startup/function_nodes/nodes/get_list_element.py b/release/scripts/startup/function_nodes/nodes/get_list_element.py
index 75e7620b7d2..066e23d4e6f 100644
--- a/release/scripts/startup/function_nodes/nodes/get_list_element.py
+++ b/release/scripts/startup/function_nodes/nodes/get_list_element.py
@@ -1,18 +1,18 @@
import bpy
from .. base import FunctionNode
-from .. socket_decl import FixedSocketDecl, BaseSocketDecl, ListSocketDecl
+from .. socket_decl import FixedSocketDecl, ListSocketDecl
class GetListElementNode(bpy.types.Node, FunctionNode):
bl_idname = "fn_GetListElementNode"
bl_label = "Get List Element"
- active_type: BaseSocketDecl.Property()
+ active_type: ListSocketDecl.Property()
def get_sockets(self):
return [
- ListSocketDecl("list", "List", "active_type"),
+ ListSocketDecl("list", "List", "active_type", "LIST"),
FixedSocketDecl("index", "Index", "Integer"),
- BaseSocketDecl("fallback", "Fallback", "active_type"),
+ ListSocketDecl("fallback", "Fallback", "active_type", "BASE"),
], [
- BaseSocketDecl("value", "Value", "active_type"),
+ ListSocketDecl("value", "Value", "active_type", "BASE"),
]
\ No newline at end of file
diff --git a/release/scripts/startup/function_nodes/socket_decl.py b/release/scripts/startup/function_nodes/socket_decl.py
index a89e18f301b..0e7f61bdd72 100644
--- a/release/scripts/startup/function_nodes/socket_decl.py
+++ b/release/scripts/startup/function_nodes/socket_decl.py
@@ -35,41 +35,29 @@ class FixedSocketDecl(SocketDeclBase):
return 1
class ListSocketDecl(SocketDeclBase):
- def __init__(self, identifier: str, display_name: str, type_property: str):
+ def __init__(self, identifier: str, display_name: str, prop_name: str, list_or_base: str):
self.identifier = identifier
self.display_name = display_name
- self.type_property = type_property
-
- def build(self, node, node_sockets):
- base_type = getattr(node, self.type_property)
- list_type = type_infos.to_list(base_type)
- return [type_infos.build(
- list_type,
- node_sockets,
- self.display_name,
- self.identifier)]
-
- def amount(self, node):
- return 1
-
- @classmethod
- def Property(cls):
- return StringProperty(default="Float")
-
-class BaseSocketDecl(SocketDeclBase):
- def __init__(self, identifier: str, display_name: str, type_property: str):
- self.identifier = identifier
- self.display_name = display_name
- self.type_property = type_property
+ self.prop_name = prop_name
+ self.list_or_base = list_or_base
def build(self, node, node_sockets):
- data_type = getattr(node, self.type_property)
+ data_type = self.get_data_type(node)
return [type_infos.build(
data_type,
node_sockets,
self.display_name,
self.identifier)]
+ def get_data_type(self, node):
+ base_type = getattr(node, self.prop_name)
+ if self.list_or_base == "BASE":
+ return base_type
+ elif self.list_or_base == "LIST":
+ return type_infos.to_list(base_type)
+ else:
+ assert False
+
def amount(self, node):
return 1
@@ -77,33 +65,7 @@ class BaseSocketDecl(SocketDeclBase):
def Property(cls):
return StringProperty(default="Float")
-class AnyOfDecl(SocketDeclBase):
- def __init__(self,
- identifier: str,
- display_name: str,
- prop_name: str,
- allowed_types: str):
- self.identifier = identifier
- self.display_name = display_name
- self.prop_name = prop_name
- self.allowed_types = allowed_types
-
- def build(self, node, node_sockets):
- data_type = getattr(node, self.prop_name)
- return [type_infos.build(
- data_type,
- node_sockets,
- self.display_name,
- self.identifier)]
-
- def amount(self, node):
- return 1
-
- @classmethod
- def Property(cls, default_type):
- return StringProperty(default=default_type)
-
-class VariadicListDecl(SocketDeclBase):
+class PackListDecl(SocketDeclBase):
def __init__(self, identifier: str, prop_name: str, base_type: str):
self.identifier_suffix = identifier
self.prop_name = prop_name
@@ -166,10 +128,10 @@ class VariadicListDecl(SocketDeclBase):
@classmethod
def Property(cls):
- return CollectionProperty(type=VariadicListPropertyGroup)
+ return CollectionProperty(type=PackListPropertyGroup)
-class VariadicListPropertyGroup(bpy.types.PropertyGroup):
- bl_idname = "fn_VariadicListPropertyGroup"
+class PackListPropertyGroup(bpy.types.PropertyGroup):
+ bl_idname = "fn_PackListPropertyGroup"
state: StringProperty(default="BASE")
identifier_prefix: StringProperty()
diff --git a/release/scripts/startup/function_nodes/update_sockets.py b/release/scripts/startup/function_nodes/update_sockets.py
index 56008d9431d..a941133bcd5 100644
--- a/release/scripts/startup/function_nodes/update_sockets.py
+++ b/release/scripts/startup/function_nodes/update_sockets.py
@@ -3,15 +3,13 @@ from . base import FunctionNode, DataSocket
from . inferencer import Inferencer
from collections import defaultdict
from . sockets import type_infos, OperatorSocket, DataSocket
-from dataclasses import dataclass
+from pprint import pprint
from . socket_decl import (
FixedSocketDecl,
ListSocketDecl,
- BaseSocketDecl,
- VariadicListDecl,
+ PackListDecl,
AnyVariadicDecl,
- AnyOfDecl,
)
class UpdateFunctionTreeOperator(bpy.types.Operator):
@@ -22,7 +20,8 @@ class UpdateFunctionTreeOperator(bpy.types.Operator):
def execute(self, context):
tree = context.space_data.node_tree
run_socket_operators(tree)
- run_sock
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list