[Bf-blender-cvs] [a9f4708] object_nodes: First input node: getting basic properties of the "effected" point.
Lukas Tönne
noreply at git.blender.org
Tue Nov 24 09:43:16 CET 2015
Commit: a9f47080d82d426bff0eda3be6ba9b66c9aa0b17
Author: Lukas Tönne
Date: Wed Oct 21 11:47:26 2015 +0200
Branches: object_nodes
https://developer.blender.org/rBa9f47080d82d426bff0eda3be6ba9b66c9aa0b17
First input node: getting basic properties of the "effected" point.
===================================================================
M release/scripts/startup/bl_operators/object_nodes.py
M source/blender/blenkernel/intern/effect.c
M source/blender/blenvm/BVM_api.h
M source/blender/blenvm/bvm/bvm_eval.cc
M source/blender/blenvm/bvm/bvm_eval.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/startup/bl_operators/object_nodes.py b/release/scripts/startup/bl_operators/object_nodes.py
index 22fae25..3470920 100644
--- a/release/scripts/startup/bl_operators/object_nodes.py
+++ b/release/scripts/startup/bl_operators/object_nodes.py
@@ -42,6 +42,9 @@ node_categories = [
ObjectNodeCategory("COMPONENTS", "Components", items=[
NodeItem("ForceFieldNode"),
]),
+ ForceFieldNodeCategory("INPUT", "Input", items=[
+ NodeItem("ForceEffectorDataNode"),
+ ]),
ForceFieldNodeCategory("FORCE_OUTPUT", "Output", items=[
NodeItem("ForceOutputNode"),
]),
@@ -147,6 +150,16 @@ class CombineVectorNode(ForceNodeBase, ObjectNode):
self.outputs.new('NodeSocketVector', "Vector")
+class EffectorDataNode(ForceNodeBase, ObjectNode):
+ '''Input data of physical points'''
+ bl_idname = 'ForceEffectorDataNode'
+ bl_label = 'Effector Data'
+
+ def init(self, context):
+ self.outputs.new('NodeSocketVector', "Position")
+ self.outputs.new('NodeSocketVector', "Velocity")
+
+
class MathNode(ForceNodeBase, ObjectNode):
'''Math '''
bl_idname = 'ObjectMathNode'
diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c
index 2f08f8e..0b2bea7 100644
--- a/source/blender/blenkernel/intern/effect.c
+++ b/source/blender/blenkernel/intern/effect.c
@@ -1020,7 +1020,7 @@ void pdDoEffectors(struct EffectorContext *effctx, ListBase *colliders, Effector
for (; p<tot; p+=step) {
if (eff->expression) {
- BVM_eval_forcefield(effctx->eval_context, eff->expression, force, impulse);
+ BVM_eval_forcefield(effctx->eval_context, eff->expression, point, force, impulse);
}
else if (get_effector_data(eff, &efd, point, 0)) {
efd.falloff= effector_falloff(eff, &efd, point, weights);
diff --git a/source/blender/blenvm/BVM_api.h b/source/blender/blenvm/BVM_api.h
index 3fd7d6e..b44137d 100644
--- a/source/blender/blenvm/BVM_api.h
+++ b/source/blender/blenvm/BVM_api.h
@@ -70,11 +70,13 @@ struct BVMNodeInstance *BVM_nodegraph_add_node(struct BVMNodeGraph *graph, const
/* ------------------------------------------------------------------------- */
struct BVMEvalContext;
+struct EffectedPoint;
struct BVMEvalContext *BVM_context_create(void);
void BVM_context_free(struct BVMEvalContext *result);
-void BVM_eval_forcefield(struct BVMEvalContext *context, struct BVMExpression *expr, float force[3], float impulse[3]);
+void BVM_eval_forcefield(struct BVMEvalContext *context, struct BVMExpression *expr,
+ const struct EffectedPoint *point, float force[3], float impulse[3]);
/* ------------------------------------------------------------------------- */
diff --git a/source/blender/blenvm/bvm/bvm_eval.cc b/source/blender/blenvm/bvm/bvm_eval.cc
index c513495..e6e879a 100644
--- a/source/blender/blenvm/bvm/bvm_eval.cc
+++ b/source/blender/blenvm/bvm/bvm_eval.cc
@@ -107,6 +107,16 @@ static void eval_op_get_elem_float3(float *stack, int index, StackIndex offset_f
stack_store_float(stack, offset_to, f[index]);
}
+static void eval_op_effector_position(const EvalData *data, float *stack, StackIndex offset)
+{
+ stack_store_float3(stack, offset, data->effector.position);
+}
+
+static void eval_op_effector_velocity(const EvalData *data, float *stack, StackIndex offset)
+{
+ stack_store_float3(stack, offset, data->effector.velocity);
+}
+
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);
@@ -252,7 +262,7 @@ static void eval_op_sub_float3(float *stack, StackIndex offset_a, StackIndex off
stack_store_float3(stack, offset_r, float3(a.x - b.x, a.y - b.y, a.z - b.z));
}
-void EvalContext::eval_instructions(const Expression &expr, float *stack) const
+void EvalContext::eval_instructions(const EvalData *data, const Expression &expr, float *stack) const
{
int instr = 0;
@@ -312,6 +322,16 @@ void EvalContext::eval_instructions(const Expression &expr, float *stack) const
eval_op_get_elem_float3(stack, 2, offset_from, offset_to);
break;
}
+ case OP_EFFECTOR_POSITION: {
+ StackIndex offset = expr.read_stack_index(&instr);
+ eval_op_effector_position(data, stack, offset);
+ break;
+ }
+ case OP_EFFECTOR_VELOCITY: {
+ StackIndex offset = expr.read_stack_index(&instr);
+ eval_op_effector_velocity(data, stack, offset);
+ break;
+ }
case OP_ADD_FLOAT: {
StackIndex offset_a = expr.read_stack_index(&instr);
StackIndex offset_b = expr.read_stack_index(&instr);
@@ -466,11 +486,11 @@ void EvalContext::eval_instructions(const Expression &expr, float *stack) const
}
}
-void EvalContext::eval_expression(const Expression &expr, void **results) const
+void EvalContext::eval_expression(const EvalData *data, const Expression &expr, void **results) const
{
float stack[BVM_STACK_SIZE];
- eval_instructions(expr, stack);
+ eval_instructions(data, expr, stack);
for (int i = 0; i < expr.return_values_size(); ++i) {
const ReturnValue &rval = expr.return_value(i);
diff --git a/source/blender/blenvm/bvm/bvm_eval.h b/source/blender/blenvm/bvm/bvm_eval.h
index 6acf203..7e52d6d 100644
--- a/source/blender/blenvm/bvm/bvm_eval.h
+++ b/source/blender/blenvm/bvm/bvm_eval.h
@@ -64,14 +64,31 @@ private:
};
#endif
+struct EffectorEvalData {
+ EffectorEvalData() :
+ position(0.0f, 0.0f, 0.0f),
+ velocity(0.0f, 0.0f, 0.0f)
+ {}
+
+ float3 position;
+ float3 velocity;
+};
+
+struct EvalData {
+ EvalData()
+ {}
+
+ EffectorEvalData effector;
+};
+
struct EvalContext {
EvalContext();
~EvalContext();
- void eval_expression(const Expression &expr, void **results) const;
+ void eval_expression(const EvalData *data, const Expression &expr, void **results) const;
protected:
- void eval_instructions(const Expression &expr, float *stack) const;
+ void eval_instructions(const EvalData *data, const Expression &expr, float *stack) const;
};
} /* namespace bvm */
diff --git a/source/blender/blenvm/bvm/bvm_opcode.h b/source/blender/blenvm/bvm/bvm_opcode.h
index 79c00a5..459d512 100644
--- a/source/blender/blenvm/bvm/bvm_opcode.h
+++ b/source/blender/blenvm/bvm/bvm_opcode.h
@@ -45,6 +45,9 @@ enum OpCode {
OP_GET_ELEM1_FLOAT3,
OP_GET_ELEM2_FLOAT3,
+ OP_EFFECTOR_POSITION,
+ OP_EFFECTOR_VELOCITY,
+
OP_ADD_FLOAT,
OP_SUB_FLOAT,
OP_MUL_FLOAT,
diff --git a/source/blender/blenvm/compile/bvm_nodegraph.cc b/source/blender/blenvm/compile/bvm_nodegraph.cc
index 4b60e60..546201b 100644
--- a/source/blender/blenvm/compile/bvm_nodegraph.cc
+++ b/source/blender/blenvm/compile/bvm_nodegraph.cc
@@ -548,6 +548,9 @@ OpCode get_opcode_from_node_type(const string &node)
NODETYPE(GET_ELEM1_FLOAT3);
NODETYPE(GET_ELEM2_FLOAT3);
+ NODETYPE(EFFECTOR_POSITION);
+ NODETYPE(EFFECTOR_VELOCITY);
+
NODETYPE(ADD_FLOAT);
NODETYPE(SUB_FLOAT);
NODETYPE(MUL_FLOAT);
@@ -608,6 +611,12 @@ void register_opcode_node_types()
nt->add_input("value_z", BVM_FLOAT, 0.0f);
nt->add_output("value", BVM_FLOAT3, float3(0.0f, 0.0f, 0.0f));
+ nt = NodeGraph::add_node_type("EFFECTOR_POSITION");
+ nt->add_output("value", BVM_FLOAT3, float3(0.0f, 0.0f, 0.0f));
+
+ nt = NodeGraph::add_node_type("EFFECTOR_VELOCITY");
+ 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 5b7efd9..c3c359a 100644
--- a/source/blender/blenvm/intern/bvm_api.cc
+++ b/source/blender/blenvm/intern/bvm_api.cc
@@ -37,6 +37,7 @@ extern "C" {
#include "DNA_node_types.h"
+#include "BKE_effect.h"
#include "BKE_node.h"
#include "BVM_api.h"
@@ -106,10 +107,15 @@ struct BVMEvalContext *BVM_context_create(void)
void BVM_context_free(struct BVMEvalContext *ctx)
{ delete _CTX(ctx); }
-void BVM_eval_forcefield(struct BVMEvalContext *ctx, struct BVMExpression *expr, float force[3], float impulse[3])
+void BVM_eval_forcefield(struct BVMEvalContext *ctx, struct BVMExpression *expr,
+ const EffectedPoint *point, float force[3], float impulse[3])
{
+ bvm::EvalData data;
+ data.effector.position = bvm::float3(point->loc[0], point->loc[1], point->loc[2]);
+ data.effector.velocity = bvm::float3(point->vel[0], point->vel[1], point->vel[2]);
void *results[] = { force, impulse };
- _CTX(ctx)->eval_expression(*_EXPR(expr), results);
+
+ _CTX(ctx)->eval_expression(&data, *_EXPR(expr), results);
}
/* ------------------------------------------------------------------------- */
@@ -246,6 +252,16 @@ static void gen_forcefield_nodegraph(bNodeTree *btree, bvm::NodeGraph &graph)
map_input_socket(socket_map, bnode, 2, node, "value_z");
map_output_socket(socket_map, bnode, 0, node, "value");
}
+ else if (bvm::string(type) == "ForceEffectorDataNode") {
+ {
+ bvm::NodeInstance *node = graph.add_node("EFFECTOR_POSITION", "EFFECTOR_POS" + bvm::string(bnode->name));
+ map_output_socket(socket_map, bnode, 0, node, "value");
+ }
+ {
+ bvm::NodeInstance *node = graph.add_node("EFFECTOR_VELOCITY", "EFFECTOR_VEL" + bvm::string(bnode->name));
+ map_output_socket(socket_map, bnode, 1, node, "value");
+ }
+ }
else if (bvm::string(type) == "ObjectMathNode") {
int mode = RNA_enum_get(&ptr, "mode");
switch (mode) {
More information about the Bf-blender-cvs
mailing list