[Bf-blender-cvs] [f57cfa8] object_nodes: Reorganize python scripts for object nodes into their own script directory.
Lukas Tönne
noreply at git.blender.org
Fri Dec 4 18:08:53 CET 2015
Commit: f57cfa892fcba112603b0090c00267b092378f34
Author: Lukas Tönne
Date: Fri Dec 4 18:08:11 2015 +0100
Branches: object_nodes
https://developer.blender.org/rBf57cfa892fcba112603b0090c00267b092378f34
Reorganize python scripts for object nodes into their own script directory.
===================================================================
M release/scripts/modules/bpy/utils/__init__.py
A release/scripts/nodes/__init__.py
A release/scripts/nodes/common_nodes.py
A release/scripts/nodes/forcefield_nodes.py
A release/scripts/nodes/geometry_nodes.py
A release/scripts/nodes/node_compiler.py
A release/scripts/nodes/object_nodes.py
M release/scripts/startup/bl_operators/__init__.py
D release/scripts/startup/bl_operators/object_nodes.py
===================================================================
diff --git a/release/scripts/modules/bpy/utils/__init__.py b/release/scripts/modules/bpy/utils/__init__.py
index 986d8b9..e2785d5 100644
--- a/release/scripts/modules/bpy/utils/__init__.py
+++ b/release/scripts/modules/bpy/utils/__init__.py
@@ -69,7 +69,7 @@ import sys as _sys
import addon_utils as _addon_utils
_user_preferences = _bpy.context.user_preferences
-_script_module_dirs = "startup", "modules"
+_script_module_dirs = "startup", "modules", "nodes"
def _test_import(module_name, loaded_modules):
diff --git a/release/scripts/startup/bl_operators/__init__.py b/release/scripts/nodes/__init__.py
similarity index 72%
copy from release/scripts/startup/bl_operators/__init__.py
copy to release/scripts/nodes/__init__.py
index 9051d6f..c492b06 100644
--- a/release/scripts/startup/bl_operators/__init__.py
+++ b/release/scripts/nodes/__init__.py
@@ -24,36 +24,14 @@ if "bpy" in locals():
reload(val)
del reload
_modules = [
- "add_mesh_torus",
- "anim",
- "clip",
- "console",
- "file",
- "image",
- "mask",
- "mesh",
- "node",
- "object_align",
- "object",
+ "common_nodes",
+ "forcefield_nodes",
+ "geometry_nodes",
"object_nodes",
- "object_randomize_transform",
- "object_quick_effects",
- "presets",
- "rigidbody",
- "screen_play_rendered_anim",
- "sequencer",
- "uvcalc_follow_active",
- "uvcalc_lightmap",
- "uvcalc_smart_project",
- "vertexpaint_dirt",
- "view3d",
- "wm",
]
import bpy
-if bpy.app.build_options.freestyle:
- _modules.append("freestyle")
__import__(name=__name__, fromlist=_modules)
_namespace = globals()
_modules_loaded = {name: _namespace[name] for name in _modules if name != "bpy"}
@@ -61,6 +39,7 @@ del _namespace
def register():
+ print("REGISTER!")
bpy.utils.register_module(__name__)
diff --git a/release/scripts/nodes/common_nodes.py b/release/scripts/nodes/common_nodes.py
new file mode 100644
index 0000000..126562e
--- /dev/null
+++ b/release/scripts/nodes/common_nodes.py
@@ -0,0 +1,282 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+# <pep8-80 compliant>
+
+import bpy
+import nodeitems_utils
+from bpy.types import Operator, ObjectNode, NodeTree, Node, NodeSocket
+from bpy.props import *
+from node_compiler import NodeCompiler, NodeWrapper, InputWrapper, OutputWrapper, StringDict
+
+class NodeTreeBase():
+ def bvm_compile(self, context, graph):
+ def socket_type_to_bvm(socket):
+ if isinstance(socket, bpy.types.NodeSocketFloat):
+ return 'FLOAT'
+ elif isinstance(socket, bpy.types.NodeSocketVector):
+ return 'FLOAT3'
+ elif isinstance(socket, bpy.types.NodeSocketColor):
+ return 'FLOAT4'
+ elif isinstance(socket, bpy.types.NodeSocketInt):
+ return 'INT'
+ elif isinstance(socket, bpy.types.GeometrySocket):
+ return 'MESH'
+
+ comp = NodeCompiler(context, graph)
+
+ input_map = dict()
+ output_map = dict()
+
+ for bnode in self.nodes:
+ if not bnode.is_registered_node_type():
+ continue
+ if not hasattr(bnode, "compile"):
+ continue
+
+ # proxies for inputs/outputs
+ bnode_inputs = StringDict()
+ for binput in bnode.inputs:
+ itype = socket_type_to_bvm(binput)
+
+ proxy = comp.add_node("PASS_%s" % itype)
+ bnode_inputs[binput.identifier] = proxy.outputs[0]
+ input_map[(bnode, binput)] = proxy.inputs[0]
+
+ if hasattr(binput, "default_value"):
+ proxy.inputs[0].set_value(binput.default_value)
+
+ bnode_outputs = StringDict()
+ for boutput in bnode.outputs:
+ otype = socket_type_to_bvm(boutput)
+
+ proxy = comp.add_node("PASS_%s" % otype)
+ bnode_outputs[boutput.identifier] = proxy.inputs[0]
+ output_map[(bnode, boutput)] = proxy.outputs[0]
+
+ comp.bnode = bnode
+ comp.bnode_inputs = bnode_inputs
+ comp.bnode_outputs = bnode_outputs
+ bnode.compile(comp)
+
+ comp.bnode = None
+ comp.bnode_inputs = None
+ comp.bnode_outputs = None
+
+ for blink in self.links:
+ if not blink.is_valid:
+ continue
+
+ src = (blink.from_node, blink.from_socket)
+ dst = (blink.to_node, blink.to_socket)
+ comp.link(output_map[src], input_map[dst])
+
+###############################################################################
+# Generic Nodes
+
+class CommonNodeBase():
+ @classmethod
+ def poll(cls, ntree):
+ return isinstance(ntree, NodeTreeBase)
+
+class IterationNode(CommonNodeBase, ObjectNode):
+ '''Iteration number'''
+ bl_idname = 'ObjectIterationNode'
+ bl_label = 'Iteration'
+
+ def init(self, context):
+ self.outputs.new('NodeSocketInt', "N")
+
+ def compile(self, compiler):
+ node = compiler.add_node("ITERATION", self.name)
+ compiler.map_output(0, node.outputs[0])
+
+class MathNode(CommonNodeBase, ObjectNode):
+ '''Math '''
+ bl_idname = 'ObjectMathNode'
+ bl_label = 'Math'
+
+ _mode_items = [
+ ('ADD_FLOAT', 'Add', '', 'NONE', 0),
+ ('SUB_FLOAT', 'Subtract', '', 'NONE', 1),
+ ('MUL_FLOAT', 'Multiply', '', 'NONE', 2),
+ ('DIV_FLOAT', 'Divide', '', 'NONE', 3),
+ ('SINE', 'Sine', '', 'NONE', 4),
+ ('COSINE', 'Cosine', '', 'NONE', 5),
+ ('TANGENT', 'Tangent', '', 'NONE', 6),
+ ('ARCSINE', 'Arcsine', '', 'NONE', 7),
+ ('ARCCOSINE', 'Arccosine', '', 'NONE', 8),
+ ('ARCTANGENT', 'Arctangent', '', 'NONE', 9),
+ ('POWER', 'Power', '', 'NONE', 10),
+ ('LOGARITHM', 'Logarithm', '', 'NONE', 11),
+ ('MINIMUM', 'Minimum', '', 'NONE', 12),
+ ('MAXIMUM', 'Maximum', '', 'NONE', 13),
+ ('ROUND', 'Round', '', 'NONE', 14),
+ ('LESS_THAN', 'Less Than', '', 'NONE', 15),
+ ('GREATER_THAN', 'Greater Than', '', 'NONE', 16),
+ ('MODULO', 'Modulo', '', 'NONE', 17),
+ ('ABSOLUTE', 'Absolute', '', 'NONE', 18),
+ ('CLAMP', 'Clamp', '', 'NONE', 19),
+ ]
+ mode = EnumProperty(name="Mode",
+ items=_mode_items)
+
+ def draw_buttons(self, context, layout):
+ layout.prop(self, "mode")
+
+ def init(self, context):
+ self.inputs.new('NodeSocketFloat', "Value")
+ self.inputs.new('NodeSocketFloat', "Value")
+ self.outputs.new('NodeSocketFloat', "Value")
+
+ def compile(self, compiler):
+ node = compiler.add_node(self.mode, self.name+"N")
+
+ is_binary = self.mode in {'ADD_FLOAT', 'SUB_FLOAT', 'MUL_FLOAT', 'DIV_FLOAT',
+ 'POWER', 'LOGARITHM', 'MINIMUM', 'MAXIMUM',
+ 'LESS_THAN', 'GREATER_THAN', 'MODULO'}
+
+ if is_binary:
+ # binary mode
+ compiler.map_input(0, node.inputs[0])
+ compiler.map_input(1, node.inputs[1])
+ else:
+ # unary mode
+ socket_a = self.inputs[0]
+ socket_b = self.inputs[1]
+ linked_a = (not socket_a.hide) and socket_a.is_linked
+ linked_b = (not socket_a.hide) and socket_a.is_linked
+ if linked_a or (not linked_b):
+ compiler.map_input(0, node.inputs[0])
+ else:
+ compiler.map_input(1, node.inputs[0])
+
+ compiler.map_output(0, node.outputs[0])
+
+
+class VectorMathNode(CommonNodeBase, ObjectNode):
+ '''Vector Math '''
+ bl_idname = 'ObjectVectorMathNode'
+ bl_label = 'Vector Math'
+
+ _mode_items = [
+ ('ADD_FLOAT3', 'Add', '', 'NONE', 0),
+ ('SUB_FLOAT3', 'Subtract', '', 'NONE', 1),
+ ('AVERAGE_FLOAT3', 'Average', '', 'NONE', 2),
+ ('DOT_FLOAT3', 'Dot Product', '', 'NONE', 3),
+ ('CROSS_FLOAT3', 'Cross Product', '', 'NONE', 4),
+ ('NORMALIZE_FLOAT3', 'Normalize', '', 'NONE', 5),
+ ]
+ mode = EnumProperty(name="Mode",
+ items=_mode_items)
+
+ def draw_buttons(self, context, layout):
+ layout.prop(self, "mode")
+
+ def init(self, context):
+ self.inputs.new('NodeSocketVector', "Vector")
+ self.inputs.new('NodeSocketVector', "Vector")
+ self.outputs.new('NodeSocketVector', "Vector")
+ self.outputs.new('NodeSocketFloat', "Value")
+
+ def compile(self, compiler):
+ node = compiler.add_node(self.mode, self.name+"N")
+
+ is_binary = self.mode in {'ADD_FLOAT3', 'SUB_FLOAT3', 'AVERAGE_FLOAT3',
+ 'DOT_FLOAT3', 'CROSS_FLOAT3'}
+ has_vector_out = self.mode in {'ADD_FLOAT3', 'SUB_FLOAT3', 'AVERAGE_FLOAT3',
+ 'CROSS_FLOAT3', 'NORMALIZE_FLOAT3'}
+ has_value_out = self.mode in {'DOT_FLOAT3', 'NORMALIZE_FLOAT3'}
+
+ if is_binary:
+ # binary node
+ compiler.map_input(0, node.inputs[0])
+ compiler.map_input(1, node.inputs[1])
+ else:
+ # unary node
+ socket_a = self.inputs[0]
+ socket_b = self.inputs[1]
+ linked_a = (not socket_a.hide) and socket_a.is_linked
+ linked_b = (not socke
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list