[Bf-blender-cvs] [71402ca] object_nodes: Added a matrix compose/decompose node for loc/rot/scale.
Lukas Tönne
noreply at git.blender.org
Tue Nov 24 09:44:58 CET 2015
Commit: 71402ca5d956dc42b457d1fc59f248f6852ab992
Author: Lukas Tönne
Date: Mon Nov 23 11:07:07 2015 +0100
Branches: object_nodes
https://developer.blender.org/rB71402ca5d956dc42b457d1fc59f248f6852ab992
Added a matrix compose/decompose node for loc/rot/scale.
===================================================================
M release/scripts/startup/bl_operators/object_nodes.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/startup/bl_operators/object_nodes.py b/release/scripts/startup/bl_operators/object_nodes.py
index fd822fd..a106a7c 100644
--- a/release/scripts/startup/bl_operators/object_nodes.py
+++ b/release/scripts/startup/bl_operators/object_nodes.py
@@ -287,11 +287,15 @@ class GeometryMeshArrayNode(GeometryNodeBase, ObjectNode):
self.outputs.new('GeometrySocket', "")
def compile(self, compiler):
- node = compiler.add_node("MESH_ARRAY", self.name)
+ node_tfm = compiler.add_node("LOCROTSCALE_TO_MATRIX44", self.name+"TFM")
+ compiler.map_input(2, node_tfm, "loc")
+
+ node = compiler.add_node("MESH_ARRAY", self.name+"MOD")
compiler.map_input(0, node, "mesh_in")
compiler.map_input(1, node, "count")
- node.set_value_matrix44("transform", Matrix.Translation((0.6,0,0)))
compiler.map_output(0, node, "mesh_out")
+
+ compiler.add_link_internal(node_tfm, "matrix", node, "transform")
###############################################################################
diff --git a/source/blender/blenvm/bvm/bvm_eval.cc b/source/blender/blenvm/bvm/bvm_eval.cc
index a454a3b..c2ac111 100644
--- a/source/blender/blenvm/bvm/bvm_eval.cc
+++ b/source/blender/blenvm/bvm/bvm_eval.cc
@@ -143,6 +143,28 @@ static void eval_op_get_elem_float4(float *stack, int index, StackIndex offset_f
stack_store_float(stack, offset_to, f[index]);
}
+static void eval_op_matrix44_to_locrotscale(float *stack, StackIndex offset_from, StackIndex offset_loc,
+ StackIndex offset_rot, StackIndex offset_scale)
+{
+ matrix44 m = stack_load_matrix44(stack, offset_from);
+ float loc[3], rot[4], scale[3];
+ mat4_decompose(loc, rot, scale, m.data);
+ stack_store_float3(stack, offset_loc, float3::from_data(loc));
+ stack_store_float4(stack, offset_rot, float4::from_data(rot));
+ stack_store_float3(stack, offset_scale, float3::from_data(scale));
+}
+
+static void eval_op_locrotscale_to_matrix44(float *stack, StackIndex offset_loc, StackIndex offset_rot,
+ StackIndex offset_scale, StackIndex offset_to)
+{
+ float3 loc = stack_load_float3(stack, offset_loc);
+ float4 rot = stack_load_float4(stack, offset_rot);
+ float3 scale = stack_load_float3(stack, offset_scale);
+ float mat[4][4];
+ loc_quat_size_to_mat4(mat, loc.data(), rot.data(), scale.data());
+ stack_store_matrix44(stack, offset_to, matrix44::from_data(&mat[0][0]));
+}
+
static void eval_op_init_mesh_ptr(float *stack, StackIndex offset, int use_count)
{
mesh_ptr p(NULL);
@@ -533,6 +555,22 @@ void EvalContext::eval_instructions(const EvalGlobals *globals, const EvalData *
eval_op_get_elem_float4(stack, index, offset_from, offset_to);
break;
}
+ case OP_MATRIX44_TO_LOCROTSCALE: {
+ StackIndex offset_from = fn->read_stack_index(&instr);
+ StackIndex offset_loc = fn->read_stack_index(&instr);
+ StackIndex offset_rot = fn->read_stack_index(&instr);
+ StackIndex offset_scale = fn->read_stack_index(&instr);
+ eval_op_matrix44_to_locrotscale(stack, offset_from, offset_loc, offset_rot, offset_scale);
+ break;
+ }
+ case OP_LOCROTSCALE_TO_MATRIX44: {
+ StackIndex offset_loc = fn->read_stack_index(&instr);
+ StackIndex offset_rot = fn->read_stack_index(&instr);
+ StackIndex offset_scale = fn->read_stack_index(&instr);
+ StackIndex offset_to = fn->read_stack_index(&instr);
+ eval_op_locrotscale_to_matrix44(stack, offset_loc, offset_rot, offset_scale, offset_to);
+ break;
+ }
case OP_INIT_MESH_PTR: {
StackIndex offset = fn->read_stack_index(&instr);
int use_count = fn->read_int(&instr);
diff --git a/source/blender/blenvm/bvm/bvm_opcode.h b/source/blender/blenvm/bvm/bvm_opcode.h
index b1f3194..db61fd0 100644
--- a/source/blender/blenvm/bvm/bvm_opcode.h
+++ b/source/blender/blenvm/bvm/bvm_opcode.h
@@ -49,6 +49,8 @@ enum OpCode {
OP_GET_ELEM_FLOAT3,
OP_SET_FLOAT4,
OP_GET_ELEM_FLOAT4,
+ OP_MATRIX44_TO_LOCROTSCALE,
+ OP_LOCROTSCALE_TO_MATRIX44,
OP_INIT_MESH_PTR,
OP_RELEASE_MESH_PTR,
diff --git a/source/blender/blenvm/compile/bvm_nodegraph.cc b/source/blender/blenvm/compile/bvm_nodegraph.cc
index 6e35501..1bdd965 100644
--- a/source/blender/blenvm/compile/bvm_nodegraph.cc
+++ b/source/blender/blenvm/compile/bvm_nodegraph.cc
@@ -1016,6 +1016,8 @@ OpCode get_opcode_from_node_type(const string &node)
NODETYPE(GET_ELEM_FLOAT3);
NODETYPE(SET_FLOAT4);
NODETYPE(GET_ELEM_FLOAT4);
+ NODETYPE(MATRIX44_TO_LOCROTSCALE);
+ NODETYPE(LOCROTSCALE_TO_MATRIX44);
NODETYPE(POINT_POSITION);
NODETYPE(POINT_VELOCITY);
@@ -1140,6 +1142,18 @@ void register_opcode_node_types()
nt->add_input("value_w", BVM_FLOAT, 0.0f);
nt->add_output("value", BVM_FLOAT4, float4(0.0f, 0.0f, 0.0f, 0.0f));
+ nt = NodeGraph::add_node_type("MATRIX44_TO_LOCROTSCALE");
+ nt->add_input("matrix", BVM_MATRIX44, matrix44::identity());
+ nt->add_output("loc", BVM_FLOAT3, float3(0.0f, 0.0f, 0.0f));
+ nt->add_output("rot", BVM_FLOAT4, float4(1.0f, 0.0f, 0.0f, 0.0f));
+ nt->add_output("scale", BVM_FLOAT3, float3(1.0f, 1.0f, 1.0f));
+
+ nt = NodeGraph::add_node_type("LOCROTSCALE_TO_MATRIX44");
+ nt->add_input("loc", BVM_FLOAT3, float3(0.0f, 0.0f, 0.0f));
+ nt->add_input("rot", BVM_FLOAT4, float4(1.0f, 0.0f, 0.0f, 0.0f));
+ nt->add_input("scale", BVM_FLOAT3, float3(1.0f, 1.0f, 1.0f));
+ nt->add_output("matrix", BVM_MATRIX44, matrix44::identity());
+
nt = NodeGraph::add_node_type("POINT_POSITION");
nt->add_output("value", BVM_FLOAT3, float3(0.0f, 0.0f, 0.0f));
More information about the Bf-blender-cvs
mailing list