Commit: 562bcb4d36a77901f896a0a3c3e743e6f75cf5e5
Author: Lukas Tönne
Date:   Wed Dec 23 12:46:36 2015 +0100
Branches: object_nodes
https://developer.blender.org/rB562bcb4d36a77901f896a0a3c3e743e6f75cf5e5

Implementation of the "make dupli" node to generate a single dupli object.

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

M       release/scripts/nodes/instancing_nodes.py
M       release/scripts/nodes/node_compiler.py
M       source/blender/blenvm/bvm/bvm_eval.cc
M       source/blender/blenvm/bvm/bvm_opcode.h
M       source/blender/blenvm/compile/bvm_nodegraph.cc

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

diff --git a/release/scripts/nodes/instancing_nodes.py 
b/release/scripts/nodes/instancing_nodes.py
index 3bca7f7..1a6341a 100644
--- a/release/scripts/nodes/instancing_nodes.py
+++ b/release/scripts/nodes/instancing_nodes.py
@@ -98,12 +98,40 @@ class MakeDupliNode(InstancingNodeBase, ObjectNode):
     bl_idname = 'InstancingMakeDupliNode'
     bl_label = 'Make Dupli'
 
+    bl_id_property_type = 'OBJECT'
+    def bl_id_property_poll(self, ob):
+        return True
+
+    def draw_buttons(self, context, layout):
+        layout.template_ID(self, "id")
+
+    def eval_dependencies(self, depsnode):
+        dob = self.id
+        if dob:
+            # XXX not quite ideal: we need to define a "dependency"
+            # because this puts the dupli object into the globals dict,
+            # even though the duplis don't actually need to be re-evaluated
+            # when this object changes
+            depsnode.add_object_relation(dob, 'GEOMETRY')
+
     def init(self, context):
         self.inputs.new('TransformSocket', "Transform")
+        self.inputs.new('NodeSocketInt', "Index")
+        self.inputs.new('NodeSocketInt', "Hide")
+        socket = self.inputs.new('NodeSocketInt', "Recursive")
+        socket.default_value = 1
+        self.outputs.new('DupliSocket', "")
 
     def compile(self, compiler):
-        #compiler.map_input(0, compiler.graph_output("mesh"))
-        print("DDDD")
+        ob = compile_object(compiler, self.id)
+
+        node = compiler.add_node("MAKE_DUPLI")
+        compiler.link(ob, node.inputs["object"])
+        compiler.map_input(0, node.inputs["transform"])
+        compiler.map_input(1, node.inputs["index"])
+        compiler.map_input(2, node.inputs["hide"])
+        compiler.map_input(3, node.inputs["recursive"])
+        compiler.map_output(0, node.outputs[0])
 
 ###############################################################################
 
@@ -139,6 +167,9 @@ def register():
             NodeItem("InstancingOutputNode"),
             NodeItem(goutput.bl_idname),
             ]),
+        InstancingNodeCategory("INS_DUPLIS", "Duplis", items=[
+            NodeItem("InstancingMakeDupliNode"),
+            ]),
         InstancingNodeCategory("INS_CONVERTER", "Converter", items=[
             NodeItem("ObjectSeparateVectorNode"),
             NodeItem("ObjectCombineVectorNode"),
diff --git a/release/scripts/nodes/node_compiler.py 
b/release/scripts/nodes/node_compiler.py
index 153b5e3..655986c 100644
--- a/release/scripts/nodes/node_compiler.py
+++ b/release/scripts/nodes/node_compiler.py
@@ -159,7 +159,7 @@ class NodeCompiler:
 
     @staticmethod
     def get_id_key(id_data):
-        return BVMEvalGlobals.get_id_key(id_data)
+        return BVMEvalGlobals.get_id_key(id_data) if id_data else 0
 
 ###############################################################################
 
diff --git a/source/blender/blenvm/bvm/bvm_eval.cc 
b/source/blender/blenvm/bvm/bvm_eval.cc
index 1a231f8..7db1e6c 100644
--- a/source/blender/blenvm/bvm/bvm_eval.cc
+++ b/source/blender/blenvm/bvm/bvm_eval.cc
@@ -304,6 +304,24 @@ static void eval_op_effector_closest_point(float *stack, 
StackIndex offset_objec
        }
 }
 
+static void eval_op_make_dupli(float *stack, StackIndex offset_object, 
StackIndex offset_transform, StackIndex offset_index,
+                               StackIndex offset_hide, StackIndex 
offset_recursive, StackIndex offset_dupli)
+{
+       PointerRNA object = stack_load_pointer(stack, offset_object);
+       if (!object.data || !RNA_struct_is_a(&RNA_Object, object.type))
+               return;
+       
+       DupliList *list = new DupliList(1);
+       Dupli &dupli = list->back();
+       dupli.object = (Object *)object.data;
+       dupli.transform = stack_load_matrix44(stack, offset_transform);
+       dupli.index = stack_load_int(stack, offset_index);
+       dupli.hide = stack_load_int(stack, offset_hide);
+       dupli.recursive = stack_load_int(stack, offset_recursive);
+       
+       stack_store_duplis(stack, offset_dupli, list);
+}
+
 void EvalContext::eval_instructions(const EvalGlobals *globals, const Function 
*fn, int entry_point, float *stack) const
 {
        EvalKernelData kd;
@@ -949,6 +967,18 @@ void EvalContext::eval_instructions(const EvalGlobals 
*globals, const Function *
                                break;
                        }
                        
+                       case OP_MAKE_DUPLI: {
+                               StackIndex offset_object = 
fn->read_stack_index(&instr);
+                               StackIndex offset_transform = 
fn->read_stack_index(&instr);
+                               StackIndex offset_index = 
fn->read_stack_index(&instr);
+                               StackIndex offset_hide = 
fn->read_stack_index(&instr);
+                               StackIndex offset_recursive = 
fn->read_stack_index(&instr);
+                               StackIndex offset_dupli = 
fn->read_stack_index(&instr);
+                               eval_op_make_dupli(stack, offset_object, 
offset_transform, offset_index,
+                                                  offset_hide, 
offset_recursive, offset_dupli);
+                               break;
+                       }
+                       
                        case OP_END:
                                return;
                }
diff --git a/source/blender/blenvm/bvm/bvm_opcode.h 
b/source/blender/blenvm/bvm/bvm_opcode.h
index fc65540..2838f40 100644
--- a/source/blender/blenvm/bvm/bvm_opcode.h
+++ b/source/blender/blenvm/bvm/bvm_opcode.h
@@ -143,6 +143,8 @@ enum OpCode {
        
        OP_CURVE_PATH,
        
+       OP_MAKE_DUPLI,
+       
        OP_END,
        
 //     OP_JUMP,
diff --git a/source/blender/blenvm/compile/bvm_nodegraph.cc 
b/source/blender/blenvm/compile/bvm_nodegraph.cc
index f2cb4be..339b671 100644
--- a/source/blender/blenvm/compile/bvm_nodegraph.cc
+++ b/source/blender/blenvm/compile/bvm_nodegraph.cc
@@ -884,6 +884,8 @@ OpCode get_opcode_from_node_type(const string &node)
        
        NODETYPE(CURVE_PATH);
        
+       NODETYPE(MAKE_DUPLI);
+       
        #undef NODETYPE
        
        return OP_NOOP;
@@ -1260,6 +1262,14 @@ static void register_opcode_node_types()
        nt->add_output("weight", TYPE_FLOAT);
        nt->add_output("tilt", TYPE_FLOAT);
        
+       nt = NodeGraph::add_function_node_type("MAKE_DUPLI");
+       nt->add_input("object", TYPE_POINTER, PointerRNA_NULL);
+       nt->add_input("transform", TYPE_MATRIX44, matrix44::identity());
+       nt->add_input("index", TYPE_INT, 0);
+       nt->add_input("hide", TYPE_INT, 0);
+       nt->add_input("recursive", TYPE_INT, 1);
+       nt->add_output("dupli", TYPE_DUPLIS);
+       
        nt = NodeGraph::add_function_node_type("ADD_MATRIX44");
        nt->add_input("value_a", TYPE_MATRIX44, matrix44::identity());
        nt->add_input("value_b", TYPE_MATRIX44, matrix44::identity());

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to