[Bf-blender-cvs] [434123a] object_nodes: Use the relative transform of target objects and the modified object to adjust modifiers.

Lukas Tönne noreply at git.blender.org
Fri Dec 11 18:33:58 CET 2015


Commit: 434123a6ead74cc34bbd845ab1e7c47db9be3089
Author: Lukas Tönne
Date:   Fri Dec 11 18:30:25 2015 +0100
Branches: object_nodes
https://developer.blender.org/rB434123a6ead74cc34bbd845ab1e7c47db9be3089

Use the relative transform of target objects and the modified object to adjust modifiers.

This affects modifiers which use an external target object (currently
boolean and curve path). The modified object is a graph input argument,
which the target object is looked up via its key. The relative transform
means the values calculated from external geometry are always in the
modified object's local space.

Note that transform and its inverse are provided explicitly to nodes.
This will allow optimization for constants later on.

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

M	release/scripts/nodes/geometry_nodes.py
M	source/blender/blenkernel/intern/DerivedMesh.c
M	source/blender/blenvm/BVM_api.h
M	source/blender/blenvm/bvm/bvm_eval.cc
M	source/blender/blenvm/bvm/bvm_eval_curve.h
M	source/blender/blenvm/bvm/bvm_eval_mesh.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

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

diff --git a/release/scripts/nodes/geometry_nodes.py b/release/scripts/nodes/geometry_nodes.py
index ea7f8e0..5758c3b 100644
--- a/release/scripts/nodes/geometry_nodes.py
+++ b/release/scripts/nodes/geometry_nodes.py
@@ -58,6 +58,43 @@ class GeometryNodeBase(NodeBase):
         return ntree.bl_idname == 'GeometryNodeTree'
 
 
+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]
+
+# typical inputs of a modifier node:
+# (object, transform, inverse transform)
+def compile_modifier_inputs(compiler, obptr):
+    ptfm = compile_object_transform(compiler, compiler.graph_input("modifier.object"))
+    pitfm = compile_matrix_inverse(compiler, ptfm)
+
+    ob = compile_object(compiler, obptr)
+    obtfm = compile_object_transform(compiler, ob)
+
+    tfm = compile_matrix_multiply(compiler, pitfm, obtfm)
+    itfm = compile_matrix_inverse(compiler, tfm)
+
+    return ob, tfm, itfm
+
+
 class GeometryOutputNode(GeometryNodeBase, ObjectNode):
     '''Geometry output'''
     bl_idname = 'GeometryOutputNode'
@@ -263,19 +300,19 @@ class GeometryBooleanNode(GeometryNodeBase, ObjectNode):
     def compile(self, compiler):
         if self.id is None:
             return
-        
-        obkey = compiler.get_id_key(self.id)
-        obnode = compiler.add_node("OBJECT_LOOKUP")
-        obnode.inputs[0].set_value(obkey)
-        
+        ob, tfm, itfm = compile_modifier_inputs(compiler, self.id)
+
         node = compiler.add_node("MESH_BOOLEAN")
         compiler.map_input(0, node.inputs[0])
-        compiler.link(obnode.outputs[0], node.inputs[1])
-        node.inputs[2].set_value(self.operation_value)
-        node.inputs[3].set_value(self.use_separate)
-        node.inputs[4].set_value(self.use_dissolve)
-        node.inputs[5].set_value(self.use_connect_regions)
-        node.inputs[6].set_value(self.threshold)
+        compiler.link(ob, node.inputs[1])
+        compiler.link(tfm, node.inputs[2])
+        compiler.link(itfm, node.inputs[3])
+        node.inputs[4].set_value(self.operation_value)
+        node.inputs[5].set_value(self.use_separate)
+        node.inputs[6].set_value(self.use_dissolve)
+        node.inputs[7].set_value(self.use_connect_regions)
+        node.inputs[8].set_value(self.threshold)
+        
         compiler.map_output(0, node.outputs[0])
 
 ###############################################################################
@@ -315,13 +352,13 @@ class CurvePathNode(CurveNodeBase, ObjectNode):
     def compile(self, compiler):
         if self.id is None:
             return
-        obkey = compiler.get_id_key(self.id)
-        obnode = compiler.add_node("OBJECT_LOOKUP")
+        ob, tfm, itfm = compile_modifier_inputs(compiler, self.id)
+        
         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.link(ob, node.inputs[0])
+        compiler.link(tfm, node.inputs[1])
+        compiler.link(itfm, node.inputs[2])
+        compiler.map_input(0, node.inputs[3])
         
         compiler.map_output(0, node.outputs[0])
         compiler.map_output(1, node.outputs[1])
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c
index fef13c1..9e52332 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -1715,7 +1715,7 @@ static DerivedMesh *mesh_calc_modifier_nodes(Scene *UNUSED(scene), Object *ob, b
 		BVM_globals_add_nodetree_relations(globals, ntree);
 		
 		struct BVMEvalContext *context = BVM_context_create();
-		dm = BVM_eval_modifier(globals, context, fn, me);
+		dm = BVM_eval_modifier(globals, context, fn, ob, me);
 		BVM_context_free(context);
 		
 		BVM_globals_free(globals);
diff --git a/source/blender/blenvm/BVM_api.h b/source/blender/blenvm/BVM_api.h
index 1c63819..1910286 100644
--- a/source/blender/blenvm/BVM_api.h
+++ b/source/blender/blenvm/BVM_api.h
@@ -142,7 +142,11 @@ struct Mesh;
 
 struct BVMFunction *BVM_gen_modifier_function(struct Object *ob, struct bNodeTree *btree, FILE *debug_file);
 
-struct DerivedMesh *BVM_eval_modifier(struct BVMEvalGlobals *globals, struct BVMEvalContext *context, struct BVMFunction *fn, struct Mesh *base_mesh);
+struct DerivedMesh *BVM_eval_modifier(struct BVMEvalGlobals *globals,
+                                      struct BVMEvalContext *context,
+                                      struct BVMFunction *fn,
+                                      struct Object *ob,
+                                      struct Mesh *base_mesh);
 
 /* ------------------------------------------------------------------------- */
 
diff --git a/source/blender/blenvm/bvm/bvm_eval.cc b/source/blender/blenvm/bvm/bvm_eval.cc
index 7756bae..7ce9477 100644
--- a/source/blender/blenvm/bvm/bvm_eval.cc
+++ b/source/blender/blenvm/bvm/bvm_eval.cc
@@ -210,6 +210,20 @@ static void eval_op_object_lookup(const EvalGlobals *globals, float *stack, int
 	stack_store_pointer(stack, offset_object, ptr);
 }
 
+static void eval_op_object_transform(float *stack, StackIndex offset_object, StackIndex offset_transform)
+{
+	PointerRNA ptr = stack_load_pointer(stack, offset_object);
+	matrix44 obmat;
+	if (ptr.data && RNA_struct_is_a(&RNA_Object, ptr.type)) {
+		Object *ob = (Object *)ptr.data;
+		copy_m4_m4(obmat.data, ob->obmat);
+	}
+	else
+		obmat = matrix44::identity();
+	
+	stack_store_matrix44(stack, offset_transform, obmat);
+}
+
 static void eval_op_effector_transform(const EvalGlobals *globals, float *stack, int object_index, StackIndex offset_tfm)
 {
 	// TODO the way objects are stored in globals has changed a lot, this needs updating
@@ -772,6 +786,12 @@ void EvalContext::eval_instructions(const EvalGlobals *globals, const Function *
 				eval_op_object_lookup(globals, stack, key, offset_object);
 				break;
 			}
+			case OP_OBJECT_TRANSFORM: {
+				StackIndex offset_object = fn->read_stack_index(&instr);
+				StackIndex offset_transform = fn->read_stack_index(&instr);
+				eval_op_object_transform(stack, offset_object, offset_transform);
+				break;
+			}
 			
 			case OP_EFFECTOR_TRANSFORM: {
 				int object_index = fn->read_int(&instr);
@@ -829,6 +849,8 @@ void EvalContext::eval_instructions(const EvalGlobals *globals, const Function *
 			case OP_MESH_BOOLEAN: {
 				StackIndex offset_mesh_in = fn->read_stack_index(&instr);
 				StackIndex offset_object = fn->read_stack_index(&instr);
+				StackIndex offset_transform = fn->read_stack_index(&instr);
+				StackIndex offset_invtransform = fn->read_stack_index(&instr);
 				StackIndex offset_operation = fn->read_stack_index(&instr);
 				StackIndex offset_separate = fn->read_stack_index(&instr);
 				StackIndex offset_dissolve = fn->read_stack_index(&instr);
@@ -836,7 +858,7 @@ void EvalContext::eval_instructions(const EvalGlobals *globals, const Function *
 				StackIndex offset_threshold = fn->read_stack_index(&instr);
 				StackIndex offset_mesh_out = fn->read_stack_index(&instr);
 				eval_op_mesh_boolean(globals, &kd, stack, offset_mesh_in,
-				                     offset_object, offset_operation,
+				                     offset_object, offset_transform, offset_invtransform, offset_operation,
 				                     offset_separate, offset_dissolve, offset_connect_regions,
 				                     offset_threshold, offset_mesh_out);
 				break;
@@ -844,6 +866,8 @@ void EvalContext::eval_instructions(const EvalGlobals *globals, const Function *
 			
 			case OP_CURVE_PATH: {
 				StackIndex offset_object = fn->read_stack_index(&instr);
+				StackIndex offset_transform = fn->read_stack_index(&instr);
+				StackIndex offset_invtransform = 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);
@@ -852,8 +876,8 @@ void EvalContext::eval_instructions(const EvalGlobals *globals, const Function *
 				StackIndex offset_radius = fn->read_stack_index(&instr);
 				StackIndex offset_weight = fn->read_stack_index(&instr);
 				StackIndex offset_tilt = fn->read_stack_index(&instr);
-				eval_op_curve_path(stack, offset_object, offset_param,
-				                   offset_loc, offset_dir, offset_nor,
+				eval_op_curve_path(stack, offset_object, offset_transform, offset_invtransform,
+				                   offset_param, offset_loc, offset_dir, offset_nor,
 				                   offset_rot, offset_radius, offset_weight,
 				                   offset_tilt);
 				break;
diff --git a/source/blender/blenvm/bvm/bvm_eval_curve.h b/source/blender/blenvm/bvm/bvm_eval_curve.h
index 5d24cf3..09131b9 100644
--- a/source/blender/blenvm/bvm/bvm_eval_curve.h
+++ b/source/blender/blenvm/bvm/bvm_eval_curve.h
@@ -44,9 +44,17 @@ extern "C" {
 
 namespace bvm {
 
-static void eval_op_curve_path(float *stack, StackIndex offset_object, StackIndex offset_param,
-                               StackIndex offset_loc, StackIndex offset_dir, StackIndex offset_nor,
-                               StackIndex offset_rot, StackIndex offset_radius, StackIndex offset_weight,
+static void eval_op_curve_path(float *stack,
+                               StackIndex offset_object,
+                               StackIndex offset_transform,
+                               StackIndex offset_invtransform,
+                               StackIndex offset_param,
+                               StackIndex offset_loc,
+                

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list