[Bf-blender-cvs] [8331fce] object_nodes: New vector math mode for vector length, patch by Philipp Oeser (lichtwerk).
Lukas Tönne
noreply at git.blender.org
Fri Jan 1 13:43:35 CET 2016
Commit: 8331fceec622a5e7133d513e2d951b5ef3193275
Author: Lukas Tönne
Date: Fri Jan 1 13:42:13 2016 +0100
Branches: object_nodes
https://developer.blender.org/rB8331fceec622a5e7133d513e2d951b5ef3193275
New vector math mode for vector length, patch by Philipp Oeser (lichtwerk).
===================================================================
M release/scripts/nodes/common_nodes.py
M source/blender/blenvm/bvm/bvm_eval.cc
M source/blender/blenvm/bvm/bvm_eval_math.h
M source/blender/blenvm/bvm/bvm_opcode.h
M source/blender/blenvm/compile/bvm_nodegraph.cc
===================================================================
diff --git a/release/scripts/nodes/common_nodes.py b/release/scripts/nodes/common_nodes.py
index 3dc5b5e..1a9f3cf 100644
--- a/release/scripts/nodes/common_nodes.py
+++ b/release/scripts/nodes/common_nodes.py
@@ -342,6 +342,7 @@ class VectorMathNode(CommonNodeBase, ObjectNode):
('DOT_FLOAT3', 'Dot Product', '', 'NONE', 5),
('CROSS_FLOAT3', 'Cross Product', '', 'NONE', 6),
('NORMALIZE_FLOAT3', 'Normalize', '', 'NONE', 7),
+ ('LENGTH_FLOAT3', 'Vector Length', '', 'NONE', 8),
]
mode = EnumProperty(name="Mode",
items=_mode_items)
@@ -362,7 +363,7 @@ class VectorMathNode(CommonNodeBase, ObjectNode):
'AVERAGE_FLOAT3', 'DOT_FLOAT3', 'CROSS_FLOAT3'}
has_vector_out = self.mode in {'ADD_FLOAT3', 'SUB_FLOAT3', 'MUL_FLOAT3', 'DIV_FLOAT3',
'AVERAGE_FLOAT3', 'CROSS_FLOAT3', 'NORMALIZE_FLOAT3'}
- has_value_out = self.mode in {'DOT_FLOAT3', 'NORMALIZE_FLOAT3'}
+ has_value_out = self.mode in {'DOT_FLOAT3', 'NORMALIZE_FLOAT3', 'LENGTH_FLOAT3'}
if is_binary:
# binary node
@@ -434,7 +435,6 @@ class CombineVectorNode(CommonNodeBase, ObjectNode):
compiler.map_input(2, node.inputs[2])
compiler.map_output(0, node.outputs[0])
-
class TranslationTransformNode(CommonNodeBase, ObjectNode):
'''Create translation from a vector'''
bl_idname = 'ObjectTranslationTransformNode'
diff --git a/source/blender/blenvm/bvm/bvm_eval.cc b/source/blender/blenvm/bvm/bvm_eval.cc
index b56c756..5227279 100644
--- a/source/blender/blenvm/bvm/bvm_eval.cc
+++ b/source/blender/blenvm/bvm/bvm_eval.cc
@@ -671,6 +671,12 @@ void EvalContext::eval_instructions(const EvalGlobals *globals, const Function *
eval_op_normalize_float3(stack, offset, offset_vec, offset_val);
break;
}
+ case OP_LENGTH_FLOAT3: {
+ StackIndex offset = fn->read_stack_index(&instr);
+ StackIndex offset_len = fn->read_stack_index(&instr);
+ eval_op_length_float3(stack, offset, offset_len);
+ break;
+ }
case OP_ADD_MATRIX44: {
StackIndex offset_a = fn->read_stack_index(&instr);
StackIndex offset_b = fn->read_stack_index(&instr);
diff --git a/source/blender/blenvm/bvm/bvm_eval_math.h b/source/blender/blenvm/bvm/bvm_eval_math.h
index 5454fdc..df22ed9 100644
--- a/source/blender/blenvm/bvm/bvm_eval_math.h
+++ b/source/blender/blenvm/bvm/bvm_eval_math.h
@@ -321,6 +321,13 @@ static void eval_op_normalize_float3(float *stack, StackIndex offset, StackIndex
stack_store_float(stack, offset_val, l);
}
+static void eval_op_length_float3(float *stack, StackIndex offset, StackIndex offset_len)
+{
+ float3 v = stack_load_float3(stack, offset);
+ float l = sqrtf(v.x*v.x + v.y*v.y + v.z*v.z);
+ stack_store_float(stack, offset_len, l);
+}
+
static void eval_op_add_matrix44(float *stack, StackIndex offset_a, StackIndex offset_b, StackIndex offset_r)
{
matrix44 a = stack_load_matrix44(stack, offset_a);
diff --git a/source/blender/blenvm/bvm/bvm_opcode.h b/source/blender/blenvm/bvm/bvm_opcode.h
index 8471174..93fc287 100644
--- a/source/blender/blenvm/bvm/bvm_opcode.h
+++ b/source/blender/blenvm/bvm/bvm_opcode.h
@@ -98,6 +98,7 @@ enum OpCode {
OP_DOT_FLOAT3,
OP_CROSS_FLOAT3,
OP_NORMALIZE_FLOAT3,
+ OP_LENGTH_FLOAT3,
OP_ADD_MATRIX44,
OP_SUB_MATRIX44,
diff --git a/source/blender/blenvm/compile/bvm_nodegraph.cc b/source/blender/blenvm/compile/bvm_nodegraph.cc
index d8ec060..d7cebd2 100644
--- a/source/blender/blenvm/compile/bvm_nodegraph.cc
+++ b/source/blender/blenvm/compile/bvm_nodegraph.cc
@@ -821,6 +821,7 @@ OpCode get_opcode_from_node_type(const string &node)
NODETYPE(DOT_FLOAT3);
NODETYPE(CROSS_FLOAT3);
NODETYPE(NORMALIZE_FLOAT3);
+ NODETYPE(LENGTH_FLOAT3);
NODETYPE(ADD_MATRIX44);
NODETYPE(SUB_MATRIX44);
@@ -1126,6 +1127,10 @@ static void register_opcode_node_types()
nt->add_output("vector", TYPE_FLOAT3);
nt->add_output("value", TYPE_FLOAT);
+ nt = NodeGraph::add_function_node_type("LENGTH_FLOAT3");
+ nt->add_input("value", TYPE_FLOAT3, float3(0.0f, 0.0f, 0.0f));
+ nt->add_output("length", TYPE_FLOAT);
+
nt = NodeGraph::add_function_node_type("MIX_RGB");
nt->add_input("mode", TYPE_INT, 0, INPUT_CONSTANT);
nt->add_input("factor", TYPE_FLOAT, 0.0f);
More information about the Bf-blender-cvs
mailing list