[Bf-blender-cvs] [62f4467a492] functions: simple operators to create new function trees from modifier

Jacques Lucke noreply at git.blender.org
Mon Apr 1 10:33:15 CEST 2019


Commit: 62f4467a492e36d22720bb20497a222a6a986465
Author: Jacques Lucke
Date:   Mon Apr 1 10:11:56 2019 +0200
Branches: functions
https://developer.blender.org/rB62f4467a492e36d22720bb20497a222a6a986465

simple operators to create new function trees from modifier

===================================================================

M	release/scripts/startup/bl_operators/__init__.py
A	release/scripts/startup/bl_operators/modifiers.py
M	release/scripts/startup/bl_ui/properties_data_modifier.py
M	release/scripts/startup/function_nodes/node_operators.py

===================================================================

diff --git a/release/scripts/startup/bl_operators/__init__.py b/release/scripts/startup/bl_operators/__init__.py
index bb92e070d00..8a9c5f01e5f 100644
--- a/release/scripts/startup/bl_operators/__init__.py
+++ b/release/scripts/startup/bl_operators/__init__.py
@@ -34,6 +34,7 @@ _modules = [
     "image",
     "mask",
     "mesh",
+    "modifiers",
     "node",
     "object",
     "object_align",
diff --git a/release/scripts/startup/bl_operators/modifiers.py b/release/scripts/startup/bl_operators/modifiers.py
new file mode 100644
index 00000000000..c6009cde396
--- /dev/null
+++ b/release/scripts/startup/bl_operators/modifiers.py
@@ -0,0 +1,64 @@
+import bpy
+from bpy.props import (
+    StringProperty,
+)
+
+class ModifierOperator:
+    object_name: StringProperty()
+    modifier_name: StringProperty()
+
+    def get_modifier(self):
+        ob = bpy.data.objects.get(self.object_name)
+        if ob is None:
+            return None
+        return ob.modifiers.get(self.modifier_name)
+
+class NewDeformationFunction(bpy.types.Operator, ModifierOperator):
+    bl_idname = "fn.new_deformation_function"
+    bl_label = "New Deformation Function"
+
+    def execute(self, context):
+        mod = self.get_modifier()
+        if mod is None:
+            return {'CANCELLED'}
+
+        from function_nodes.node_operators import new_function_tree
+        tree = new_function_tree("Deformation Function", [
+            ("Vector", "Old Position"),
+            ("Integer", "Vertex Seed"),
+            ("Float", "Control")
+        ], [
+            ("Vector", "New Position"),
+        ])
+
+        input_node = tree.get_input_node()
+        output_node = tree.get_output_node()
+        tree.new_link(input_node.outputs[0], output_node.inputs[0])
+
+        mod.function_tree = tree
+        return {'FINISHED'}
+
+class NewPointGeneratorFunction(bpy.types.Operator, ModifierOperator):
+    bl_idname = "fn.new_point_generator_function"
+    bl_label = "New Point Generator Function"
+
+    def execute(self, context):
+        mod = self.get_modifier()
+        if mod is None:
+            return {'CANCELLED'}
+
+        from function_nodes.node_operators import new_function_tree
+        tree = new_function_tree("Point Generator", [
+            ("Float", "Control 1"),
+            ("Integer", "Control 2"),
+        ], [
+            ("Vector List", "Points"),
+        ])
+
+        mod.function_tree = tree
+        return {'FINISHED'}
+
+classes = (
+    NewDeformationFunction,
+    NewPointGeneratorFunction,
+)
\ No newline at end of file
diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index 8f4eb58adda..e3a81d94f73 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1639,12 +1639,22 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
     def FUNCTION_DEFORM(self, layout, ob, md):
         layout.prop(md, "control1")
         layout.prop(md, "control2")
-        layout.prop(md, "function_tree")
+
+        row = layout.row(align=True)
+        row.prop(md, "function_tree")
+        props = row.operator("fn.new_deformation_function", text="", icon="ADD")
+        props.object_name = ob.name
+        props.modifier_name = md.name
 
     def FUNCTION_POINTS(self, layout, ob, md):
         layout.prop(md, "control1")
         layout.prop(md, "control2")
-        layout.prop(md, "function_tree")
+
+        row = layout.row(align=True)
+        row.prop(md, "function_tree")
+        props = row.operator("fn.new_point_generator_function", text="", icon="ADD")
+        props.object_name = ob.name
+        props.modifier_name = md.name
 
 
 class DATA_PT_gpencil_modifiers(ModifierButtonsPanel, Panel):
diff --git a/release/scripts/startup/function_nodes/node_operators.py b/release/scripts/startup/function_nodes/node_operators.py
index c7539f45bd5..8e8401c3e65 100644
--- a/release/scripts/startup/function_nodes/node_operators.py
+++ b/release/scripts/startup/function_nodes/node_operators.py
@@ -85,34 +85,26 @@ class MoveViewToNode(bpy.types.Operator):
         bpy.ops.node.view_selected('INVOKE_DEFAULT')
         return {'FINISHED'}
 
-class NewFunctionTree(bpy.types.Operator):
-    bl_idname = "fn.new_function_tree"
-    bl_label = "New Function Tree"
-
-    name: StringProperty()
-    inputs: StringProperty()
-    outputs: StringProperty()
-
-    def execute(self, context):
-        tree = bpy.data.node_groups.new(self.name, "FunctionTree")
-        input_node = self.create_input(tree)
-        output_node = self.create_output(tree)
-        input_node.location.x = -200 - input_node.width
-        output_node.location.x = 200
-        return {'FINISHED'}
-
-    def create_input(self, tree):
+def new_function_tree(name, inputs, outputs):
+    def create_input(tree):
         input_node = tree.nodes.new("fn_FunctionInputNode")
         variadic = input_node.outputs[0].get_decl(input_node)
-        for data_type, name in eval(self.inputs):
+        for data_type, name in inputs:
             variadic.add_item(data_type, name)
         input_node.refresh()
         return input_node
 
-    def create_output(self, tree):
+    def create_output(tree):
         output_node = tree.nodes.new("fn_FunctionOutputNode")
         variadic = output_node.inputs[0].get_decl(output_node)
-        for data_type, name in eval(self.outputs):
+        for data_type, name in outputs:
             variadic.add_item(data_type, name)
         output_node.refresh()
-        return output_node
\ No newline at end of file
+        return output_node
+
+    tree = bpy.data.node_groups.new(name, "FunctionTree")
+    input_node = create_input(tree)
+    output_node = create_output(tree)
+    input_node.location.x = -200 - input_node.width
+    output_node.location.x = 200
+    return tree



More information about the Bf-blender-cvs mailing list