[Bf-blender-cvs] [1a37890] object_nodes: Return duplis from a bvm node evaluation, just like DerivedMesh.

Lukas Tönne noreply at git.blender.org
Wed Dec 23 12:47:39 CET 2015


Commit: 1a37890ac07e97b983cd5aad72f0e0403164d583
Author: Lukas Tönne
Date:   Tue Dec 22 14:30:09 2015 +0100
Branches: object_nodes
https://developer.blender.org/rB1a37890ac07e97b983cd5aad72f0e0403164d583

Return duplis from a bvm node evaluation, just like DerivedMesh.

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

M	release/scripts/nodes/instancing_nodes.py
M	release/scripts/nodes/socket_types.py
M	source/blender/blenvm/compile/bvm_nodegraph.cc
M	source/blender/blenvm/intern/bvm_api.cc

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

diff --git a/release/scripts/nodes/instancing_nodes.py b/release/scripts/nodes/instancing_nodes.py
index 32095ca..3bca7f7 100644
--- a/release/scripts/nodes/instancing_nodes.py
+++ b/release/scripts/nodes/instancing_nodes.py
@@ -81,6 +81,18 @@ def compile_object(compiler, ptr):
     return node.outputs[0]
 
 
+class OutputNode(InstancingNodeBase, ObjectNode):
+    '''Dupli output'''
+    bl_idname = 'InstancingOutputNode'
+    bl_label = 'Output'
+
+    def init(self, context):
+        self.inputs.new('DupliSocket', "")
+
+    def compile(self, compiler):
+        compiler.map_input(0, compiler.graph_output("dupli.result"))
+
+
 class MakeDupliNode(InstancingNodeBase, ObjectNode):
     '''Make object instance'''
     bl_idname = 'InstancingMakeDupliNode'
@@ -115,7 +127,7 @@ def register():
     bpy.utils.register_module(__name__)
 
     node_categories = [
-        InstancingNodeCategory("DUPLI_INPUT", "Input", items=[
+        InstancingNodeCategory("INS_INPUT", "Input", items=[
             NodeItem("ObjectIterationNode"),
             NodeItem(ginput.bl_idname),
             NodeItem("ObjectValueFloatNode"),
@@ -124,14 +136,14 @@ def register():
             NodeItem("ObjectValueColorNode"),
             ]),
         InstancingNodeCategory("INS_OUTPUT", "Output", items=[
-            NodeItem("InstancingMakeDupliNode"),
+            NodeItem("InstancingOutputNode"),
             NodeItem(goutput.bl_idname),
             ]),
-        InstancingNodeCategory("GEO_CONVERTER", "Converter", items=[
+        InstancingNodeCategory("INS_CONVERTER", "Converter", items=[
             NodeItem("ObjectSeparateVectorNode"),
             NodeItem("ObjectCombineVectorNode"),
             ]),
-        InstancingNodeCategory("GEO_MATH", "Math", items=[
+        InstancingNodeCategory("INS_MATH", "Math", items=[
             NodeItem("ObjectMathNode"),
             NodeItem("ObjectVectorMathNode"),
             NodeItem("ObjectTranslationTransformNode"),
@@ -144,11 +156,11 @@ def register():
             NodeItem("ObjectGetScaleNode"),
             NodeItem("ObjectRandomNode"),
             ]),
-        InstancingNodeCategory("GEO_TEXTURE", "Texture", items=[
+        InstancingNodeCategory("INS_TEXTURE", "Texture", items=[
             NodeItem("ObjectTextureCloudsNode"),
             NodeItem("ObjectTextureVoronoiNode"),
             ]),
-        InstancingNodeCategory("GEO_GROUP", "Group", items=[
+        InstancingNodeCategory("INS_GROUP", "Group", items=[
             NodeItem(gnode.bl_idname),
             ]),
         ]
diff --git a/release/scripts/nodes/socket_types.py b/release/scripts/nodes/socket_types.py
index f703266..03ba66c 100644
--- a/release/scripts/nodes/socket_types.py
+++ b/release/scripts/nodes/socket_types.py
@@ -51,6 +51,21 @@ class GeometrySocket(NodeSocket):
         alpha = 0.4 if self.is_placeholder else 1.0
         return (1.0, 0.4, 0.216, alpha)
 
+class DupliSocket(NodeSocket):
+    '''Dupli instances socket'''
+    bl_idname = 'DupliSocket'
+    bl_label = 'Duplis'
+
+    is_placeholder = BoolProperty(name="Is Placeholder",
+                                  default=False)
+
+    def draw(self, context, layout, node, text):
+        layout.label(text)
+
+    def draw_color(self, context, node):
+        alpha = 0.4 if self.is_placeholder else 1.0
+        return (1.0, 0.4, 0.216, alpha)
+
 ###############################################################################
 
 socket_type_items = [
@@ -59,6 +74,7 @@ socket_type_items = [
     ("VECTOR", "Vector", "3D vector", 0, 2),
     ("COLOR", "Color", "RGBA color", 0, 3),
     ("MESH", "Mesh", "Mesh data", 0, 4),
+    ("DUPLIS", "Duplis", "Dupli instances", 0, 4),
     ("TRANSFORM", "Transform", "Affine transformation", 0, 5),
     ]
 
@@ -69,6 +85,7 @@ def socket_type_to_rna(base_type):
         "VECTOR" : bpy.types.NodeSocketVector,
         "COLOR" : bpy.types.NodeSocketColor,
         "MESH" : bpy.types.GeometrySocket,
+        "DUPLIS" : bpy.types.DupliSocket,
         "TRANSFORM" : bpy.types.TransformSocket,
         }
     return types.get(base_type, None)
@@ -82,10 +99,12 @@ def rna_to_bvm_type(cls):
         return 'FLOAT4'
     elif issubclass(cls, bpy.types.NodeSocketInt):
         return 'INT'
-    elif issubclass(cls, bpy.types.GeometrySocket):
-        return 'MESH'
     elif issubclass(cls, bpy.types.TransformSocket):
         return 'MATRIX44'
+    elif issubclass(cls, bpy.types.GeometrySocket):
+        return 'MESH'
+    elif issubclass(cls, bpy.types.DupliSocket):
+        return 'DUPLIS'
 
 def socket_type_to_bvm_type(base_type):
     return rna_to_bvm_type(socket_type_to_rna(base_type))
diff --git a/source/blender/blenvm/compile/bvm_nodegraph.cc b/source/blender/blenvm/compile/bvm_nodegraph.cc
index 3df64f2..7727a8d 100644
--- a/source/blender/blenvm/compile/bvm_nodegraph.cc
+++ b/source/blender/blenvm/compile/bvm_nodegraph.cc
@@ -938,8 +938,8 @@ static void register_opcode_node_types()
 	nt->add_output("value", TYPE_MESH);
 	
 	nt = NodeGraph::add_pass_node_type("PASS_DUPLIS");
-	nt->add_input("value", TYPE_MESH, __empty_duplis__);
-	nt->add_output("value", TYPE_MESH);
+	nt->add_input("value", TYPE_DUPLIS, __empty_duplis__);
+	nt->add_output("value", TYPE_DUPLIS);
 	
 	nt = NodeGraph::add_pass_node_type("PASS_FLOAT_ARRAY");
 	nt->add_input("value", TYPE_FLOAT_ARRAY, array<BVM_FLOAT>());
diff --git a/source/blender/blenvm/intern/bvm_api.cc b/source/blender/blenvm/intern/bvm_api.cc
index 5354e59..5da2581 100644
--- a/source/blender/blenvm/intern/bvm_api.cc
+++ b/source/blender/blenvm/intern/bvm_api.cc
@@ -65,6 +65,8 @@ extern "C" {
 
 namespace bvm {
 static mesh_ptr __empty_mesh__;
+static ListBase __empty_listbase__ = {0};
+static duplis_ptr __empty_duplis__ = duplis_ptr(&__empty_listbase__);
 }
 
 void BVM_init(void)
@@ -1064,7 +1066,7 @@ struct BVMFunction *BVM_gen_dupli_function(struct bNodeTree *btree, FILE *debug_
 	
 	NodeGraph graph;
 	graph.add_input("dupli.object", TYPE_POINTER);
-	graph.add_input("dupli.container", TYPE_POINTER);
+	graph.add_output("dupli.result", TYPE_DUPLIS, __empty_duplis__);
 	
 	parse_py_nodes(btree, &graph);
 	graph.finalize();
@@ -1088,11 +1090,21 @@ void BVM_eval_dupli(struct BVMEvalGlobals *globals,
 {
 	using namespace bvm;
 
-	PointerRNA object_ptr, duplicont_ptr;
+	PointerRNA object_ptr;
 	RNA_id_pointer_create((ID *)object, &object_ptr);
-	RNA_pointer_create((ID *)object, &RNA_DupliContainer, duplicont, &duplicont_ptr);
-	const void *args[] = { &object_ptr, &duplicont_ptr };
-	void *results[] = {};
+	const void *args[] = { &object_ptr };
+	
+	duplis_ptr duplis;
+	void *results[] = { &duplis };
 	
 	_CTX(ctx)->eval_function(_GLOBALS(globals), _FUNC(fn), args, results);
+	
+	ListBase *lb = duplis.get();
+	if (lb) {
+		for (DupliObject *dob = (DupliObject *)lb->first; dob; dob = dob->next) {
+			BKE_dupli_add_instance(duplicont, dob->ob, dob->mat, dob->persistent_id[0],
+			        dob->animated, dob->no_draw, false);
+		}
+		BLI_freelistN(lb);
+	}
 }




More information about the Bf-blender-cvs mailing list