[Bf-blender-cvs] [031c14e] object_nodes: New dupli mode for use of BVM node trees to generate duplis.

Lukas Tönne noreply at git.blender.org
Mon Dec 21 12:10:33 CET 2015


Commit: 031c14e1234d4a30eeb6e8e690e8c6b6457fbd0e
Author: Lukas Tönne
Date:   Sun Dec 20 10:07:48 2015 +0100
Branches: object_nodes
https://developer.blender.org/rB031c14e1234d4a30eeb6e8e690e8c6b6457fbd0e

New dupli mode for use of BVM node trees to generate duplis.

Not yet functional, as it doesn't have opcodes yet.

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

A	release/scripts/nodes/instancing_nodes.py
M	release/scripts/nodes/object_nodes.py
M	source/blender/blenkernel/BKE_anim.h
M	source/blender/blenkernel/intern/object_dupli.c
M	source/blender/blenvm/BVM_api.h
M	source/blender/blenvm/intern/bvm_api.cc
M	source/blender/makesdna/DNA_object_types.h
M	source/blender/makesrna/RNA_access.h
M	source/blender/makesrna/intern/CMakeLists.txt
M	source/blender/makesrna/intern/makesrna.c
M	source/blender/makesrna/intern/rna_internal.h
M	source/blender/makesrna/intern/rna_object.c
A	source/blender/makesrna/intern/rna_object_dupli.c

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

diff --git a/release/scripts/nodes/instancing_nodes.py b/release/scripts/nodes/instancing_nodes.py
new file mode 100644
index 0000000..32095ca
--- /dev/null
+++ b/release/scripts/nodes/instancing_nodes.py
@@ -0,0 +1,160 @@
+# ##### 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
+from bpy.props import *
+from nodeitems_utils import NodeCategory, NodeItem
+from mathutils import *
+from common_nodes import NodeTreeBase, NodeBase, enum_property_copy, enum_property_value_prop
+import group_nodes
+
+###############################################################################
+
+
+# our own base class with an appropriate poll function,
+# so the categories only show up in our own tree type
+class InstancingNodeCategory(NodeCategory):
+    @classmethod
+    def poll(cls, context):
+        tree = context.space_data.edit_tree
+        return tree and tree.bl_idname == 'InstancingNodeTree'
+
+###############################################################################
+
+class InstancingNodeTree(NodeTreeBase, NodeTree):
+    '''Instancing nodes'''
+    bl_idname = 'InstancingNodeTree'
+    bl_label = 'Instancing Nodes'
+    bl_icon = 'EMPTY_DATA'
+
+    # does not show up in the editor header
+    @classmethod
+    def poll(cls, context):
+        return False
+
+
+class InstancingNodeBase(NodeBase):
+    @classmethod
+    def poll(cls, ntree):
+        return ntree.bl_idname == 'InstancingNodeTree'
+
+
+def compile_object_transform(compiler, ob):
+    node = compiler.add_node("OBJECT_TRANSFORM")
+    compiler.link(ob, node.inputs[0])
+    return node.outputs[0]
+
+def compile_matrix_inverse(compiler, mat):
+    node = compiler.add_node("INVERT_MATRIX44")
+    compiler.link(mat, node.inputs[0])
+    return node.outputs[0]
+
+def compile_matrix_multiply(compiler, mat1, mat2):
+    node = compiler.add_node("MUL_MATRIX44")
+    compiler.link(mat1, node.inputs[0])
+    compiler.link(mat2, node.inputs[1])
+    return node.outputs[0]
+
+def compile_object(compiler, ptr):
+    key = compiler.get_id_key(ptr)
+    node = compiler.add_node("OBJECT_LOOKUP")
+    node.inputs[0].set_value(key)
+    return node.outputs[0]
+
+
+class MakeDupliNode(InstancingNodeBase, ObjectNode):
+    '''Make object instance'''
+    bl_idname = 'InstancingMakeDupliNode'
+    bl_label = 'Make Dupli'
+
+    def init(self, context):
+        self.inputs.new('TransformSocket', "Transform")
+
+    def compile(self, compiler):
+        #compiler.map_input(0, compiler.graph_output("mesh"))
+        print("DDDD")
+
+###############################################################################
+
+class InstancingNodesNew(Operator):
+    """Create new Instancing node tree"""
+    bl_idname = "object_nodes.instancing_nodes_new"
+    bl_label = "New"
+    bl_options = {'REGISTER', 'UNDO'}
+
+    name = StringProperty(
+            name="Name",
+            )
+
+    def execute(self, context):
+        return bpy.ops.node.new_node_tree(type='InstancingNodeTree', name="InstancingNodes")
+
+###############################################################################
+
+def register():
+    gnode, ginput, goutput = group_nodes.make_node_group_types("Instancing", InstancingNodeTree, InstancingNodeBase)
+    bpy.utils.register_module(__name__)
+
+    node_categories = [
+        InstancingNodeCategory("DUPLI_INPUT", "Input", items=[
+            NodeItem("ObjectIterationNode"),
+            NodeItem(ginput.bl_idname),
+            NodeItem("ObjectValueFloatNode"),
+            NodeItem("ObjectValueIntNode"),
+            NodeItem("ObjectValueVectorNode"),
+            NodeItem("ObjectValueColorNode"),
+            ]),
+        InstancingNodeCategory("INS_OUTPUT", "Output", items=[
+            NodeItem("InstancingMakeDupliNode"),
+            NodeItem(goutput.bl_idname),
+            ]),
+        InstancingNodeCategory("GEO_CONVERTER", "Converter", items=[
+            NodeItem("ObjectSeparateVectorNode"),
+            NodeItem("ObjectCombineVectorNode"),
+            ]),
+        InstancingNodeCategory("GEO_MATH", "Math", items=[
+            NodeItem("ObjectMathNode"),
+            NodeItem("ObjectVectorMathNode"),
+            NodeItem("ObjectTranslationTransformNode"),
+            NodeItem("ObjectEulerTransformNode"),
+            NodeItem("ObjectAxisAngleTransformNode"),
+            NodeItem("ObjectScaleTransformNode"),
+            NodeItem("ObjectGetTranslationNode"),
+            NodeItem("ObjectGetEulerNode"),
+            NodeItem("ObjectGetAxisAngleNode"),
+            NodeItem("ObjectGetScaleNode"),
+            NodeItem("ObjectRandomNode"),
+            ]),
+        InstancingNodeCategory("GEO_TEXTURE", "Texture", items=[
+            NodeItem("ObjectTextureCloudsNode"),
+            NodeItem("ObjectTextureVoronoiNode"),
+            ]),
+        InstancingNodeCategory("GEO_GROUP", "Group", items=[
+            NodeItem(gnode.bl_idname),
+            ]),
+        ]
+    nodeitems_utils.register_node_categories("INSTANCING_NODES", node_categories)
+
+def unregister():
+    nodeitems_utils.unregister_node_categories("INSTANCING_NODES")
+
+    bpy.utils.unregister_module(__name__)
diff --git a/release/scripts/nodes/object_nodes.py b/release/scripts/nodes/object_nodes.py
index f2464e2..791fddc 100644
--- a/release/scripts/nodes/object_nodes.py
+++ b/release/scripts/nodes/object_nodes.py
@@ -86,6 +86,33 @@ class GeometryNode(ObjectNodeBase, ObjectNode):
         pass
 
 
+class InstancingNode(ObjectNodeBase, ObjectNode):
+    '''Instancing'''
+    bl_idname = 'InstancingNode'
+    bl_label = 'Instancing'
+    bl_icon = 'EMPTY_DATA'
+
+    bl_id_property_type = 'NODETREE'
+    def bl_id_property_poll(self, ntree):
+        return ntree.bl_idname == 'InstancingNodeTree'
+
+    def compile_dependencies(self, depsnode):
+        ntree = self.id
+        if ntree:
+            ntree.bvm_compile_dependencies(depsnode)
+
+    def eval_dependencies(self, depsnode):
+        ntree = self.id
+        if ntree:
+            ntree.bvm_eval_dependencies(depsnode)
+
+    def draw_buttons(self, context, layout):
+        layout.template_ID(self, "id", new="object_nodes.instancing_nodes_new")
+
+    def compile(self, compiler):
+        pass
+
+
 class ForceFieldNode(ObjectNodeBase, ObjectNode):
     '''Force Field'''
     bl_idname = 'ForceFieldNode'
@@ -177,6 +204,7 @@ def register():
         ObjectNodeCategory("COMPONENTS", "Components", items=[
             NodeItem("GeometryNode"),
             NodeItem("ForceFieldNode"),
+            NodeItem("InstancingNode"),
             ]),
         ]
     nodeitems_utils.register_node_categories("OBJECT_NODES", node_categories)
diff --git a/source/blender/blenkernel/BKE_anim.h b/source/blender/blenkernel/BKE_anim.h
index 584f0da..a754874 100644
--- a/source/blender/blenkernel/BKE_anim.h
+++ b/source/blender/blenkernel/BKE_anim.h
@@ -65,6 +65,14 @@ int where_on_path(struct Object *ob, float ctime, float vec[4], float dir[3], fl
 /* ---------------------------------------------------- */
 /* Dupli-Geometry */
 
+/* opaque API for storing dupli instances */
+struct DupliContainer;
+
+/* API wrapper for make_dupli using the DupliContainer type */
+void BKE_dupli_add_instance(struct DupliContainer *cont,
+                            struct Object *ob, float mat[4][4], int index,
+                            bool animated, bool hide, bool recursive);
+
 struct ListBase *object_duplilist_ex(struct EvaluationContext *eval_ctx, struct Scene *sce, struct Object *ob, bool update);
 struct ListBase *object_duplilist(struct EvaluationContext *eval_ctx, struct Scene *sce, struct Object *ob);
 void free_object_duplilist(struct ListBase *lb);
diff --git a/source/blender/blenkernel/intern/object_dupli.c b/source/blender/blenkernel/intern/object_dupli.c
index 8abe4bd..bf9f440 100644
--- a/source/blender/blenkernel/intern/object_dupli.c
+++ b/source/blender/blenkernel/intern/object_dupli.c
@@ -44,6 +44,7 @@
 #include "DNA_anim_types.h"
 #include "DNA_group_types.h"
 #include "DNA_mesh_types.h"
+#include "DNA_node_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_vfont_types.h"
 
@@ -62,6 +63,8 @@
 #include "BKE_editmesh.h"
 #include "BKE_anim.h"
 
+#include "BVM_api.h"
+
 
 #include "BLI_strict_flags.h"
 
@@ -88,8 +91,14 @@ typedef struct DupliContext {
 	ListBase *duplilist; /* legacy doubly-linked list */
 } DupliContext;
 
+static struct DupliContainer *get_dupli_container(const DupliContext *ctx)
+{
+	/* note: DupliContainer is a dummy type, used only to clarify the API */
+	return (struct DupliContainer *)ctx;
+}
+
 typedef struct DupliGenerator {
-	short type;				/* dupli type */
+	int type;				/* dupli type */
 	void (*make_duplis)(const DupliContext *ctx);
 } DupliGenerator;
 
@@ -1137,6 +1146,57 @@ const DupliGenerator gen_dupli_particles = {
     make_duplis_particles           /* make_duplis */
 };
 
+
+/* OB_DUPLINODES */
+
+static void make_duplis_nodetree(struct bNodeTree *ntree, const DupliContext *dupctx)
+{
+	struct BVMFunction *fn = BVM_function_cache_acquire(ntree);
+	if (!fn) {
+		fn = BVM_gen_dupli_function(ntree, NULL);
+		BVM_function_cache_set(ntree, fn);
+	}
+	
+	{
+		struct BVMEvalGlobals *globals = BVM_globals_create();
+		BVM_globals_add_nodetree_relations(globals, ntree);
+		
+		struct BVMEvalContext *context = BVM_context_create();
+		BVM_eval_dupli(globals, context, fn, dupctx

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list