[Bf-blender-cvs] [99e9984] object_nodes: New node "Curve Path" for reading interpolated curve data.

Lukas Tönne noreply at git.blender.org
Thu Dec 10 20:47:13 CET 2015


Commit: 99e998483b71408c3ed2e47f5be078881309029c
Author: Lukas Tönne
Date:   Thu Dec 10 20:26:56 2015 +0100
Branches: object_nodes
https://developer.blender.org/rB99e998483b71408c3ed2e47f5be078881309029c

New node "Curve Path" for reading interpolated curve data.

This introduces an improved way of handling ID relations inside the
node tree. Instead of storing simple indices to an object array,
the nodes now generate a 'key' (currently just ID name + lib name).
At eval time this key is then looked up from a hash table in globals,
to produce the actual pointer to the object.

Currently the node will not work, because the curve is not yet registered
in the globals map. This should happen in conjunction with depsgraph
updates.

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

M	release/scripts/nodes/geometry_nodes.py
M	release/scripts/nodes/node_compiler.py
M	source/blender/blenvm/BVM_api.h
M	source/blender/blenvm/bvm/CMakeLists.txt
M	source/blender/blenvm/bvm/bvm_eval.cc
M	source/blender/blenvm/bvm/bvm_eval.h
A	source/blender/blenvm/bvm/bvm_eval_curve.h
M	source/blender/blenvm/bvm/bvm_opcode.h
M	source/blender/blenvm/compile/bvm_nodegraph.cc
M	source/blender/blenvm/intern/bvm_api.cc
M	source/blender/makesrna/intern/rna_blenvm.c
M	source/blender/makesrna/intern/rna_nodetree.c
M	source/blender/makesrna/intern/rna_object.c

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

diff --git a/release/scripts/nodes/geometry_nodes.py b/release/scripts/nodes/geometry_nodes.py
index f5df771..958c0c5 100644
--- a/release/scripts/nodes/geometry_nodes.py
+++ b/release/scripts/nodes/geometry_nodes.py
@@ -218,6 +218,52 @@ class GeometryMeshDisplaceNode(GeometryNodeBase, ObjectNode):
 
 ###############################################################################
 
+class CurveNodeBase(NodeBase):
+    @classmethod
+    def poll(cls, ntree):
+        return isinstance(ntree, NodeTreeBase)
+
+class CurvePathNode(CurveNodeBase, ObjectNode):
+    '''Get curve geometry values'''
+    bl_idname = 'CurvePathNode'
+    bl_label = 'Curve Path'
+
+    bl_id_property_type = 'OBJECT'
+    def bl_id_property_poll(self, ob):
+        return ob.type == 'CURVE'
+
+    def draw_buttons(self, context, layout):
+        layout.template_ID(self, "id")
+
+    def init(self, context):
+        self.inputs.new('NodeSocketFloat', "Parameter")
+        self.outputs.new('NodeSocketVector', "Location")
+        self.outputs.new('NodeSocketVector', "Direction")
+        self.outputs.new('NodeSocketVector', "Normal")
+        self.outputs.new('TransformSocket', "Rotation")
+        self.outputs.new('NodeSocketFloat', "Radius")
+        self.outputs.new('NodeSocketFloat', "Weight")
+
+    def compile(self, compiler):
+        if self.id is None:
+            return
+        obkey = compiler.get_id_key(self.id)
+        obnode = compiler.add_node("OBJECT_LOOKUP")
+        node = compiler.add_node("CURVE_PATH")
+
+        obnode.inputs[0].set_value(obkey)
+        compiler.link(obnode.outputs[0], node.inputs[0])
+        compiler.map_input(0, node.inputs[1])
+        
+        compiler.map_output(0, node.outputs[0])
+        compiler.map_output(1, node.outputs[1])
+        compiler.map_output(2, node.outputs[2])
+        compiler.map_output(3, node.outputs[3])
+        compiler.map_output(4, node.outputs[4])
+        compiler.map_output(5, node.outputs[5])
+
+###############################################################################
+
 class GeometryNodesNew(Operator):
     """Create new geometry node tree"""
     bl_idname = "object_nodes.geometry_nodes_new"
@@ -278,6 +324,9 @@ def register():
             NodeItem("ObjectTextureCloudsNode"),
             NodeItem("ObjectTextureVoronoiNode"),
             ]),
+        GeometryNodeCategory("GEO_CURVE", "Curve", items=[
+            NodeItem("CurvePathNode"),
+            ]),
         GeometryNodeCategory("GEO_GROUP", "Group", items=[
             NodeItem(gnode.bl_idname),
             ]),
diff --git a/release/scripts/nodes/node_compiler.py b/release/scripts/nodes/node_compiler.py
index e084f31..927a70b 100644
--- a/release/scripts/nodes/node_compiler.py
+++ b/release/scripts/nodes/node_compiler.py
@@ -156,6 +156,9 @@ class NodeCompiler:
             raise KeyError("Output %r not found in node %r" % (key, bnode))
         self.link(socket, bnode_outputs[key].inputs[0])
 
+    def get_id_key(self, id_data):
+        return self.graph.get_id_key(id_data)
+
 ###############################################################################
 
 def register():
diff --git a/source/blender/blenvm/BVM_api.h b/source/blender/blenvm/BVM_api.h
index e9e1b0b..58a3d08 100644
--- a/source/blender/blenvm/BVM_api.h
+++ b/source/blender/blenvm/BVM_api.h
@@ -100,6 +100,8 @@ void BVM_globals_free(struct BVMEvalGlobals *globals);
 
 void BVM_globals_add_object(struct BVMEvalGlobals *globals, struct Object *ob);
 
+int BVM_get_id_key(struct ID *id);
+
 struct BVMEvalContext *BVM_context_create(void);
 void BVM_context_free(struct BVMEvalContext *context);
 
diff --git a/source/blender/blenvm/bvm/CMakeLists.txt b/source/blender/blenvm/bvm/CMakeLists.txt
index 0a5e848..97b0de2 100644
--- a/source/blender/blenvm/bvm/CMakeLists.txt
+++ b/source/blender/blenvm/bvm/CMakeLists.txt
@@ -41,6 +41,7 @@ set(SRC
 	bvm_eval.cc
 	bvm_eval.h
 	bvm_eval_common.h
+	bvm_eval_curve.h
 	bvm_eval_math.h
 	bvm_eval_mesh.h
 	bvm_eval_texture.h
diff --git a/source/blender/blenvm/bvm/bvm_eval.cc b/source/blender/blenvm/bvm/bvm_eval.cc
index e444e1c..6eb34df 100644
--- a/source/blender/blenvm/bvm/bvm_eval.cc
+++ b/source/blender/blenvm/bvm/bvm_eval.cc
@@ -33,7 +33,9 @@
 
 extern "C" {
 #include "BLI_math.h"
+#include "BLI_ghash.h"
 
+#include "DNA_ID.h"
 #include "DNA_object_types.h"
 
 #include "BKE_bvhutils.h"
@@ -44,12 +46,45 @@ extern "C" {
 
 #include "bvm_eval.h"
 #include "bvm_eval_common.h"
+#include "bvm_eval_curve.h"
 #include "bvm_eval_math.h"
 #include "bvm_eval_mesh.h"
 #include "bvm_eval_texture.h"
 
+#include "bvm_util_hash.h"
+
 namespace bvm {
 
+int EvalGlobals::get_id_key(ID *id)
+{
+	int hash = BLI_ghashutil_strhash(id->name);
+	if (id->lib) {
+		hash = hash_combine(hash, BLI_ghashutil_strhash(id->lib->name));
+	}
+	return hash;
+}
+
+void EvalGlobals::add_object(Object *ob)
+{
+	int key = get_id_key((ID *)ob);
+	m_objects[key] = ob;
+}
+
+PointerRNA EvalGlobals::lookup_object(int key) const
+{
+	ObjectMap::const_iterator it = m_objects.find(key);
+	if (it != m_objects.end()) {
+		PointerRNA ptr;
+		RNA_id_pointer_create((ID *)it->second, &ptr);
+		return ptr;
+	}
+	else {
+		return PointerRNA_NULL;
+	}
+}
+
+/* ------------------------------------------------------------------------- */
+
 EvalContext::EvalContext()
 {
 }
@@ -170,11 +205,22 @@ static void eval_op_mix_rgb(float *stack, int mode, StackIndex offset_col_a, Sta
 	stack_store_float4(stack, offset_r, a);
 }
 
+static void eval_op_object_lookup(const EvalGlobals *globals, float *stack, int key, StackIndex offset_object)
+{
+	PointerRNA ptr = globals->lookup_object(key);
+	stack_store_pointer(stack, offset_object, ptr);
+}
+
 static void eval_op_effector_transform(const EvalGlobals *globals, float *stack, int object_index, StackIndex offset_tfm)
 {
-	Object *ob = globals->objects[object_index];
-	matrix44 m = matrix44::from_data(&ob->obmat[0][0], matrix44::COL_MAJOR);
-	stack_store_matrix44(stack, offset_tfm, m);
+	// TODO the way objects are stored in globals has changed a lot, this needs updating
+	(void)globals;
+	(void)stack;
+	(void)object_index;
+	(void)offset_tfm;
+//	Object *ob = globals->objects[object_index];
+//	matrix44 m = matrix44::from_data(&ob->obmat[0][0], matrix44::COL_MAJOR);
+//	stack_store_matrix44(stack, offset_tfm, m);
 }
 
 static void eval_op_effector_closest_point(float *stack, StackIndex offset_object, StackIndex offset_vector,
@@ -721,6 +767,13 @@ void EvalContext::eval_instructions(const EvalGlobals *globals, const Function *
 				break;
 			}
 			
+			case OB_OBJECT_LOOKUP: {
+				int key = fn->read_int(&instr);
+				StackIndex offset_object = fn->read_stack_index(&instr);
+				eval_op_object_lookup(globals, stack, key, offset_object);
+				break;
+			}
+			
 			case OP_EFFECTOR_TRANSFORM: {
 				int object_index = fn->read_int(&instr);
 				StackIndex offset_tfm = fn->read_stack_index(&instr);
@@ -774,6 +827,22 @@ void EvalContext::eval_instructions(const EvalGlobals *globals, const Function *
 				                      offset_elem_index, offset_elem_loc);
 				break;
 			}
+			
+			case OP_CURVE_PATH: {
+				StackIndex offset_object = fn->read_stack_index(&instr);
+				StackIndex offset_param = fn->read_stack_index(&instr);
+				StackIndex offset_loc = fn->read_stack_index(&instr);
+				StackIndex offset_dir = fn->read_stack_index(&instr);
+				StackIndex offset_nor = fn->read_stack_index(&instr);
+				StackIndex offset_rot = fn->read_stack_index(&instr);
+				StackIndex offset_radius = fn->read_stack_index(&instr);
+				StackIndex offset_weight = fn->read_stack_index(&instr);
+				eval_op_curve_path(stack, offset_object, offset_param,
+				                   offset_loc, offset_dir, offset_nor,
+				                   offset_rot, offset_radius, offset_weight);
+				break;
+			}
+			
 			case OP_END:
 				return;
 			default:
diff --git a/source/blender/blenvm/bvm/bvm_eval.h b/source/blender/blenvm/bvm/bvm_eval.h
index 2480da6..ce3f217 100644
--- a/source/blender/blenvm/bvm/bvm_eval.h
+++ b/source/blender/blenvm/bvm/bvm_eval.h
@@ -40,6 +40,7 @@
 #include "bvm_util_string.h"
 #include "bvm_util_typedesc.h"
 
+struct ID;
 struct Object;
 
 namespace bvm {
@@ -49,9 +50,15 @@ struct Function;
 #define BVM_STACK_SIZE 4095
 
 struct EvalGlobals {
-	typedef std::vector<Object *> ObjectList;
+	typedef unordered_map<int, Object *> ObjectMap;
 	
-	ObjectList objects;
+	static int get_id_key(ID *id);
+	
+	void add_object(Object *ob);
+	PointerRNA lookup_object(int key) const;
+	
+private:
+	ObjectMap m_objects;
 
 	MEM_CXX_CLASS_ALLOC_FUNCS("BVM:EvalGlobals")
 };
diff --git a/source/blender/blenvm/bvm/bvm_eval_curve.h b/source/blender/blenvm/bvm/bvm_eval_curve.h
new file mode 100644
index 0000000..6c74ec1
--- /dev/null
+++ b/source/blender/blenvm/bvm/bvm_eval_curve.h
@@ -0,0 +1,77 @@
+/*
+ * ***** 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.
+ *
+ * The Original Code is Copyright (C) Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Lukas Toenne
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef __BVM_EVAL_CURVE_H__
+#define __BVM_EVAL_CURVE_H__
+
+/** \file bvm_eval_curve.h
+ *  \ingroup bvm
+ */
+
+extern "C" {
+#include "BLI_math.h"
+
+#include "BKE_anim.h"
+}
+
+#include "bvm_eval_common.h"
+
+#include "bvm_util_math.h"
+
+namespace bvm {
+
+static void eval_op_curve_path(float *stack, StackIndex offset_object, StackIndex offset_param,
+                               StackI

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list