[Bf-blender-cvs] [f9f2acf] object_nodes: Complementary separate/combine nodes for vectors.
Lukas Tönne
noreply at git.blender.org
Tue Nov 24 09:43:15 CET 2015
Commit: f9f2acfce18589b11ef1d80cd471f835f589287e
Author: Lukas Tönne
Date: Wed Oct 21 10:33:42 2015 +0200
Branches: object_nodes
https://developer.blender.org/rBf9f2acfce18589b11ef1d80cd471f835f589287e
Complementary separate/combine nodes for vectors.
===================================================================
M release/scripts/startup/bl_operators/object_nodes.py
M source/blender/blenvm/bvm/bvm_eval.cc
M source/blender/blenvm/bvm/bvm_expression.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/blenvm/util/bvm_util_typedesc.h
===================================================================
diff --git a/release/scripts/startup/bl_operators/object_nodes.py b/release/scripts/startup/bl_operators/object_nodes.py
index e393b03..22fae25 100644
--- a/release/scripts/startup/bl_operators/object_nodes.py
+++ b/release/scripts/startup/bl_operators/object_nodes.py
@@ -45,6 +45,10 @@ node_categories = [
ForceFieldNodeCategory("FORCE_OUTPUT", "Output", items=[
NodeItem("ForceOutputNode"),
]),
+ ForceFieldNodeCategory("CONVERTER", "Converter", items=[
+ NodeItem("ObjectSeparateVectorNode"),
+ NodeItem("ObjectCombineVectorNode"),
+ ]),
ForceFieldNodeCategory("MATH", "Math", items=[
NodeItem("ObjectMathNode"),
NodeItem("ObjectVectorMathNode"),
@@ -119,6 +123,30 @@ class ForceOutputNode(ForceNodeBase, ObjectNode):
self.inputs.new('NodeSocketVector', "Impulse")
+class SeparateVectorNode(ForceNodeBase, ObjectNode):
+ '''Separate vector into elements'''
+ bl_idname = 'ObjectSeparateVectorNode'
+ bl_label = 'Separate Vector'
+
+ def init(self, context):
+ self.inputs.new('NodeSocketVector', "Vector")
+ self.outputs.new('NodeSocketFloat', "X")
+ self.outputs.new('NodeSocketFloat', "Y")
+ self.outputs.new('NodeSocketFloat', "Z")
+
+
+class CombineVectorNode(ForceNodeBase, ObjectNode):
+ '''Combine vector from component values'''
+ bl_idname = 'ObjectCombineVectorNode'
+ bl_label = 'Combine Vector'
+
+ def init(self, context):
+ self.inputs.new('NodeSocketFloat', "X")
+ self.inputs.new('NodeSocketFloat', "Y")
+ self.inputs.new('NodeSocketFloat', "Z")
+ self.outputs.new('NodeSocketVector', "Vector")
+
+
class MathNode(ForceNodeBase, ObjectNode):
'''Math '''
bl_idname = 'ObjectMathNode'
diff --git a/source/blender/blenvm/bvm/bvm_eval.cc b/source/blender/blenvm/bvm/bvm_eval.cc
index 15cc603..c513495 100644
--- a/source/blender/blenvm/bvm/bvm_eval.cc
+++ b/source/blender/blenvm/bvm/bvm_eval.cc
@@ -68,6 +68,8 @@ inline static void stack_store_float3(float *stack, StackIndex offset, float3 f)
*(float3 *)(&stack[offset]) = f;
}
+/* ------------------------------------------------------------------------- */
+
static void eval_op_value_float(float *stack, float value, StackIndex offset)
{
stack_store_float(stack, offset, value);
@@ -90,6 +92,21 @@ static void eval_op_pass_float3(float *stack, StackIndex offset_from, StackIndex
stack_store_float3(stack, offset_to, f);
}
+static void eval_op_set_float3(float *stack, StackIndex offset_x, StackIndex offset_y, StackIndex offset_z, StackIndex offset_to)
+{
+ float x = stack_load_float(stack, offset_x);
+ float y = stack_load_float(stack, offset_y);
+ float z = stack_load_float(stack, offset_z);
+ stack_store_float3(stack, offset_to, float3(x, y, z));
+}
+
+static void eval_op_get_elem_float3(float *stack, int index, StackIndex offset_from, StackIndex offset_to)
+{
+ assert(index >= 0 && index < 3);
+ float3 f = stack_load_float3(stack, offset_from);
+ stack_store_float(stack, offset_to, f[index]);
+}
+
static void eval_op_add_float(float *stack, StackIndex offset_a, StackIndex offset_b, StackIndex offset_r)
{
float a = stack_load_float(stack, offset_a);
@@ -269,6 +286,32 @@ void EvalContext::eval_instructions(const Expression &expr, float *stack) const
eval_op_pass_float3(stack, offset_from, offset_to);
break;
}
+ case OP_SET_FLOAT3: {
+ StackIndex offset_x = expr.read_stack_index(&instr);
+ StackIndex offset_y = expr.read_stack_index(&instr);
+ StackIndex offset_z = expr.read_stack_index(&instr);
+ StackIndex offset_to = expr.read_stack_index(&instr);
+ eval_op_set_float3(stack, offset_x, offset_y, offset_z, offset_to);
+ break;
+ }
+ case OP_GET_ELEM0_FLOAT3: {
+ StackIndex offset_from = expr.read_stack_index(&instr);
+ StackIndex offset_to = expr.read_stack_index(&instr);
+ eval_op_get_elem_float3(stack, 0, offset_from, offset_to);
+ break;
+ }
+ case OP_GET_ELEM1_FLOAT3: {
+ StackIndex offset_from = expr.read_stack_index(&instr);
+ StackIndex offset_to = expr.read_stack_index(&instr);
+ eval_op_get_elem_float3(stack, 1, offset_from, offset_to);
+ break;
+ }
+ case OP_GET_ELEM2_FLOAT3: {
+ StackIndex offset_from = expr.read_stack_index(&instr);
+ StackIndex offset_to = expr.read_stack_index(&instr);
+ eval_op_get_elem_float3(stack, 2, offset_from, offset_to);
+ break;
+ }
case OP_ADD_FLOAT: {
StackIndex offset_a = expr.read_stack_index(&instr);
StackIndex offset_b = expr.read_stack_index(&instr);
diff --git a/source/blender/blenvm/bvm/bvm_expression.h b/source/blender/blenvm/bvm/bvm_expression.h
index ac92f54..a71ac62 100644
--- a/source/blender/blenvm/bvm/bvm_expression.h
+++ b/source/blender/blenvm/bvm/bvm_expression.h
@@ -52,6 +52,13 @@ static inline Instruction float_to_instruction(float f)
return u.i;
}
+static inline Instruction int_to_instruction(int v)
+{
+ union { uint32_t i; int v; } u;
+ u.v = v;
+ return u.i;
+}
+
static inline float instruction_to_float(Instruction i)
{
union { uint32_t i; float f; } u;
@@ -59,6 +66,13 @@ static inline float instruction_to_float(Instruction i)
return u.f;
}
+static inline int instruction_to_int(Instruction i)
+{
+ union { uint32_t i; int v; } u;
+ u.i = i;
+ return u.v;
+}
+
struct ReturnValue {
ReturnValue(const TypeDesc &typedesc, const string &name) :
typedesc(typedesc),
@@ -84,18 +98,21 @@ struct Expression {
++(*instr);
return op;
}
+
StackIndex read_stack_index(int *instr) const
{
StackIndex index = instructions[*instr];
++(*instr);
return index;
}
+
float read_float(int *instr) const
{
float f = instruction_to_float(instructions[*instr]);
++(*instr);
return f;
}
+
float3 read_float3(int *instr) const
{
float3 f;
@@ -106,6 +123,13 @@ struct Expression {
return f;
}
+ int read_int(int *instr) const
+ {
+ int i = instruction_to_int(instructions[*instr]);
+ ++(*instr);
+ return i;
+ }
+
void add_instruction(Instruction v);
ReturnValue &add_return_value(const TypeDesc &typedesc, const string &name = "");
diff --git a/source/blender/blenvm/bvm/bvm_opcode.h b/source/blender/blenvm/bvm/bvm_opcode.h
index f04568b..79c00a5 100644
--- a/source/blender/blenvm/bvm/bvm_opcode.h
+++ b/source/blender/blenvm/bvm/bvm_opcode.h
@@ -40,6 +40,10 @@ enum OpCode {
OP_VALUE_FLOAT3,
OP_PASS_FLOAT,
OP_PASS_FLOAT3,
+ OP_SET_FLOAT3,
+ OP_GET_ELEM0_FLOAT3,
+ OP_GET_ELEM1_FLOAT3,
+ OP_GET_ELEM2_FLOAT3,
OP_ADD_FLOAT,
OP_SUB_FLOAT,
diff --git a/source/blender/blenvm/compile/bvm_nodegraph.cc b/source/blender/blenvm/compile/bvm_nodegraph.cc
index e13c09e..4b60e60 100644
--- a/source/blender/blenvm/compile/bvm_nodegraph.cc
+++ b/source/blender/blenvm/compile/bvm_nodegraph.cc
@@ -543,6 +543,10 @@ OpCode get_opcode_from_node_type(const string &node)
NODETYPE(PASS_FLOAT);
NODETYPE(PASS_FLOAT3);
+ NODETYPE(SET_FLOAT3);
+ NODETYPE(GET_ELEM0_FLOAT3);
+ NODETYPE(GET_ELEM1_FLOAT3);
+ NODETYPE(GET_ELEM2_FLOAT3);
NODETYPE(ADD_FLOAT);
NODETYPE(SUB_FLOAT);
@@ -586,6 +590,24 @@ void register_opcode_node_types()
nt->add_input("value", BVM_FLOAT3, float3(0.0f, 0.0f, 0.0f));
nt->add_output("value", BVM_FLOAT3, float3(0.0f, 0.0f, 0.0f));
+ nt = NodeGraph::add_node_type("GET_ELEM0_FLOAT3");
+ nt->add_input("value", BVM_FLOAT3, float3(0.0f, 0.0f, 0.0f));
+ nt->add_output("value", BVM_FLOAT, 0.0f);
+
+ nt = NodeGraph::add_node_type("GET_ELEM1_FLOAT3");
+ nt->add_input("value", BVM_FLOAT3, float3(0.0f, 0.0f, 0.0f));
+ nt->add_output("value", BVM_FLOAT, 0.0f);
+
+ nt = NodeGraph::add_node_type("GET_ELEM2_FLOAT3");
+ nt->add_input("value", BVM_FLOAT3, float3(0.0f, 0.0f, 0.0f));
+ nt->add_output("value", BVM_FLOAT, 0.0f);
+
+ nt = NodeGraph::add_node_type("SET_FLOAT3");
+ nt->add_input("value_x", BVM_FLOAT, 0.0f);
+ nt->add_input("value_y", BVM_FLOAT, 0.0f);
+ nt->add_input("value_z", BVM_FLOAT, 0.0f);
+ nt->add_output("value", BVM_FLOAT3, float3(0.0f, 0.0f, 0.0f));
+
#define BINARY_MATH_NODE(name) \
nt = NodeGraph::add_node_type(STRINGIFY(name)); \
nt->add_input("value_a", BVM_FLOAT, 0.0f); \
diff --git a/source/blender/blenvm/intern/bvm_api.cc b/source/blender/blenvm/intern/bvm_api.cc
index 43da7c3..5b7efd9 100644
--- a/source/blender/blenvm/intern/bvm_api.cc
+++ b/source/blender/blenvm/intern/bvm_api.cc
@@ -222,6 +222,30 @@ static void gen_forcefield_nodegraph(bNodeTree *btree, bvm::NodeGraph &graph)
graph.set_output_link("impulse", node, "value");
}
}
+ else if (bvm::string(type) == "ObjectSeparateVectorNode") {
+ {
+ bvm::NodeInstance *node = graph.add_node("GET_ELEM0_FLOAT3", "GET_ELEM0_" + bvm::string(bnode->name));
+ map_input_socket(socket_map, bnode, 0, node, "value");
+ map_output_socket(socket_map, bnode, 0, node, "value");
+ }
+ {
+ bvm::NodeInstance *node = graph.add_node("GET_ELEM1_FLOAT3", "GET_ELEM1_" + bvm::string(bnode->name));
+ map_input_socket(socket_map, bnode, 0, node, "value");
+ map_output_socket(socket_map, bnode, 1, node, "value");
+ }
+ {
+ bvm::NodeInstance *node = graph.add_node("GET_ELEM2_FLOAT3", "GET_ELEM2_" + bvm::string(bnode->name));
+ map_input_socket(socket_map, bnode, 0, node, "value");
+ map_output_socket(socket_map, bnode, 2, node, "value");
+ }
+ }
+ else if (bvm::string(type) == "ObjectCombineVectorNode") {
+ bvm::NodeInstance *node = graph.add_node("SET_FLOAT3", bvm::string(bnode->name));
+ map_input_socket(socket_map, bnode, 0, node, "value_x");
+ map_input_socket(socket_map, bnode, 1, node, "value_y");
+ map_input_socket(socket_map, bnode, 2, node, "value_z");
+ map_output_socket(socket_map, bnode, 0, node, "value");
+ }
else if (bvm::string(type) == "ObjectMathNode") {
int mode = RNA_enum_get(&ptr, "mode");
switch (mode) {
diff --git a/source/blender/blenvm/util/bvm_util_typedesc.h b/source/blender/blenvm/util/bvm_util_typedesc.h
index 922a168..d076c63 100644
--- a/source/blender/blenvm/util/bvm_util_typedesc.h
+++ b/source/blender/blenvm/util/bvm_util_typedesc.h
@@ -49,6 +49,15 @@ struct float3 {
x(x), y(y), z(z)
{}
+ float& operator[] (int index)
+ {
+ return ((float*)
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list