[Bf-blender-cvs] [ceb9eba] object_nodes: Foundations for a mesh data type in bvm
Lukas Tönne
noreply at git.blender.org
Tue Nov 24 09:44:27 CET 2015
Commit: ceb9eba6bdae3f696e67d68a11e4ecf18b63d7db
Author: Lukas Tönne
Date: Thu Nov 19 15:50:36 2015 +0100
Branches: object_nodes
https://developer.blender.org/rBceb9eba6bdae3f696e67d68a11e4ecf18b63d7db
Foundations for a mesh data type in bvm
===================================================================
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.h
M source/blender/blenvm/bvm/bvm_eval_common.h
M source/blender/blenvm/bvm/bvm_opcode.h
M source/blender/blenvm/compile/bvm_codegen.cc
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/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c
index af54e22..ad9975b 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -1706,15 +1706,15 @@ static void dm_ensure_display_normals(DerivedMesh *dm)
static DerivedMesh *mesh_calc_modifier_nodes(Scene *scene, Object *ob, bNodeTree *ntree)
{
Mesh *me = ob->data;
- DerivedMesh *dm = CDDM_from_mesh(me);
+ DerivedMesh *dm;
struct BVMEvalGlobals *globals = BVM_globals_create();
- struct BVMSchedule *sched = BVM_gen_modifier_function(globals, ob, ntree, NULL);
+ struct BVMFunction *fn = BVM_gen_modifier_function(globals, ob, ntree, NULL);
{
struct BVMEvalContext *context = BVM_context_create();
- BVM_eval_modifier(context, sched);
+ dm = BVM_eval_modifier(context, fn, me);
BVM_context_free(context);
}
diff --git a/source/blender/blenvm/BVM_api.h b/source/blender/blenvm/BVM_api.h
index c0e285b..d8d8d69 100644
--- a/source/blender/blenvm/BVM_api.h
+++ b/source/blender/blenvm/BVM_api.h
@@ -121,11 +121,14 @@ void BVM_texture_cache_clear(void);
/* ------------------------------------------------------------------------- */
+struct DerivedMesh;
+struct Mesh;
+
struct BVMFunction *BVM_gen_modifier_function(const struct BVMEvalGlobals *globals,
struct Object *ob, struct bNodeTree *btree,
FILE *debug_file);
-void BVM_eval_modifier(struct BVMEvalContext *context, struct BVMFunction *fn);
+struct DerivedMesh *BVM_eval_modifier(struct BVMEvalContext *context, struct BVMFunction *fn, struct Mesh *base_mesh);
/* ------------------------------------------------------------------------- */
diff --git a/source/blender/blenvm/bvm/bvm_eval.cc b/source/blender/blenvm/bvm/bvm_eval.cc
index deadd44..a44b702 100644
--- a/source/blender/blenvm/bvm/bvm_eval.cc
+++ b/source/blender/blenvm/bvm/bvm_eval.cc
@@ -37,6 +37,7 @@ extern "C" {
#include "DNA_object_types.h"
#include "BKE_bvhutils.h"
+#include "BKE_cdderivedmesh.h"
#include "BKE_DerivedMesh.h"
#include "BKE_material.h"
}
@@ -89,6 +90,14 @@ static void eval_op_value_pointer(float *stack, PointerRNA value, StackIndex off
stack_store_pointer(stack, offset, value);
}
+/* Note: mesh data is not explicitly stored on the stack,
+ * this function always creates simply an empty mesh.
+ */
+static void eval_op_value_mesh(float *stack, StackIndex offset)
+{
+ stack_store_mesh(stack, offset, __empty_mesh__);
+}
+
static void eval_op_float_to_int(float *stack, StackIndex offset_from, StackIndex offset_to)
{
float f = stack_load_float(stack, offset_from);
@@ -451,6 +460,12 @@ static void eval_op_effector_closest_point(float *stack, StackIndex offset_objec
}
}
+static void eval_op_mesh_load(const EvalData *data, float *stack, StackIndex offset)
+{
+ DerivedMesh *dm = CDDM_from_mesh(data->modifier.base_mesh);
+ stack_store_mesh(stack, offset, mesh_ptr(dm));
+}
+
void EvalContext::eval_instructions(const EvalGlobals *globals, const EvalData *data, const Function *fn, float *stack) const
{
int instr = 0;
@@ -497,6 +512,11 @@ void EvalContext::eval_instructions(const EvalGlobals *globals, const EvalData *
eval_op_value_pointer(stack, value, offset);
break;
}
+ case OP_VALUE_MESH: {
+ StackIndex offset = fn->read_stack_index(&instr);
+ eval_op_value_mesh(stack, offset);
+ break;
+ }
case OP_FLOAT_TO_INT: {
StackIndex offset_from = fn->read_stack_index(&instr);
StackIndex offset_to = fn->read_stack_index(&instr);
@@ -861,6 +881,11 @@ void EvalContext::eval_instructions(const EvalGlobals *globals, const EvalData *
offset_position, offset_normal, offset_tangent);
break;
}
+ case OP_MESH_LOAD: {
+ StackIndex offset_mesh = fn->read_stack_index(&instr);
+ eval_op_mesh_load(data, stack, offset_mesh);
+ break;
+ }
case OP_END:
return;
default:
diff --git a/source/blender/blenvm/bvm/bvm_eval.h b/source/blender/blenvm/bvm/bvm_eval.h
index 979c395..791cd12 100644
--- a/source/blender/blenvm/bvm/bvm_eval.h
+++ b/source/blender/blenvm/bvm/bvm_eval.h
@@ -93,12 +93,17 @@ struct TextureEvalData {
int osatex;
};
+struct ModifierEvalData {
+ struct Mesh *base_mesh;
+};
+
struct EvalData {
EvalData()
{}
EffectorEvalData effector;
TextureEvalData texture;
+ ModifierEvalData modifier;
};
struct EvalContext {
diff --git a/source/blender/blenvm/bvm/bvm_eval_common.h b/source/blender/blenvm/bvm/bvm_eval_common.h
index e3c8d2d..f7507a0 100644
--- a/source/blender/blenvm/bvm/bvm_eval_common.h
+++ b/source/blender/blenvm/bvm/bvm_eval_common.h
@@ -67,6 +67,11 @@ inline static PointerRNA stack_load_pointer(float *stack, StackIndex offset)
return *(PointerRNA *)(&stack[offset]);
}
+inline static mesh_ptr stack_load_mesh(float *stack, StackIndex offset)
+{
+ return *(mesh_ptr *)(&stack[offset]);
+}
+
inline static void stack_store_float(float *stack, StackIndex offset, float f)
{
*(float *)(&stack[offset]) = f;
@@ -97,6 +102,11 @@ inline static void stack_store_pointer(float *stack, StackIndex offset, PointerR
*(PointerRNA *)(&stack[offset]) = p;
}
+inline static void stack_store_mesh(float *stack, StackIndex offset, mesh_ptr p)
+{
+ *(mesh_ptr *)(&stack[offset]) = p;
+}
+
} /* namespace bvm */
#endif /* __BVM_EVAL_COMMON_H__ */
diff --git a/source/blender/blenvm/bvm/bvm_opcode.h b/source/blender/blenvm/bvm/bvm_opcode.h
index eab0287..7d65040 100644
--- a/source/blender/blenvm/bvm/bvm_opcode.h
+++ b/source/blender/blenvm/bvm/bvm_opcode.h
@@ -42,6 +42,7 @@ enum OpCode {
OP_VALUE_INT,
OP_VALUE_MATRIX44,
OP_VALUE_POINTER,
+ OP_VALUE_MESH,
OP_FLOAT_TO_INT,
OP_INT_TO_FLOAT,
OP_PASS_FLOAT,
@@ -108,8 +109,10 @@ enum OpCode {
OP_EFFECTOR_TRANSFORM,
OP_EFFECTOR_CLOSEST_POINT,
+ OP_MESH_LOAD,
+
OP_END,
-
+
// OP_JUMP,
// OP_JUMP_IF_ZERO,
// OP_JUMP_IF_ONE,
diff --git a/source/blender/blenvm/compile/bvm_codegen.cc b/source/blender/blenvm/compile/bvm_codegen.cc
index bdf5cf2..c807a16 100644
--- a/source/blender/blenvm/compile/bvm_codegen.cc
+++ b/source/blender/blenvm/compile/bvm_codegen.cc
@@ -209,6 +209,8 @@ StackIndex BVMCompiler::codegen_value(const Value *value)
}
case BVM_MESH:
+ push_opcode(OP_VALUE_MESH);
+ push_stack_index(offset);
break;
}
diff --git a/source/blender/blenvm/compile/bvm_nodegraph.cc b/source/blender/blenvm/compile/bvm_nodegraph.cc
index df10472..9920371 100644
--- a/source/blender/blenvm/compile/bvm_nodegraph.cc
+++ b/source/blender/blenvm/compile/bvm_nodegraph.cc
@@ -795,6 +795,8 @@ OpCode get_opcode_from_node_type(const string &node)
NODETYPE(EFFECTOR_TRANSFORM);
NODETYPE(EFFECTOR_CLOSEST_POINT);
+ NODETYPE(MESH_LOAD);
+
#undef NODETYPE
assert(!"Invalid node type");
@@ -1001,6 +1003,9 @@ void register_opcode_node_types()
nt->add_output("position", BVM_FLOAT3, float3(0.0f, 0.0f, 0.0f));
nt->add_output("normal", BVM_FLOAT3, float3(0.0f, 0.0f, 0.0f));
nt->add_output("tangent", BVM_FLOAT3, float3(0.0f, 0.0f, 0.0f));
+
+ nt = NodeGraph::add_node_type("MESH_LOAD");
+ nt->add_output("mesh", BVM_MESH, __empty_mesh__);
}
} /* namespace bvm */
diff --git a/source/blender/blenvm/intern/bvm_api.cc b/source/blender/blenvm/intern/bvm_api.cc
index cae9973..70c8cd5 100644
--- a/source/blender/blenvm/intern/bvm_api.cc
+++ b/source/blender/blenvm/intern/bvm_api.cc
@@ -849,8 +849,10 @@ struct BVMFunction *BVM_gen_modifier_function(const struct BVMEvalGlobals *globa
using namespace bvm;
NodeGraph graph;
+ graph.add_output("mesh", BVM_MESH, __empty_mesh__);
+
CompileContext comp(_GLOBALS(globals));
-// parse_modifier_nodes(&comp, btree, &graph);
+ parse_py_nodes(&comp, btree, &graph);
if (debug_file) {
graph.dump_graphviz(debug_file, "Modifier Schedule Graph");
@@ -862,7 +864,20 @@ struct BVMFunction *BVM_gen_modifier_function(const struct BVMEvalGlobals *globa
return (BVMFunction *)fn;
}
-void BVM_eval_modifier(struct BVMEvalContext *context, struct BVMFunction *fn)
+struct DerivedMesh *BVM_eval_modifier(struct BVMEvalContext *ctx, struct BVMFunction *fn, struct Mesh *base_mesh)
{
+ using namespace bvm;
+
+ EvalGlobals globals;
+
+ EvalData data;
+ ModifierEvalData &moddata = data.modifier;
+ moddata.base_mesh = base_mesh;
+
+ mesh_ptr result;
+ void *results[] = { &result };
+
+ _CTX(ctx)->eval_expression(&globals, &data, _FUNC(fn), results);
+ return result.get();
}
diff --git a/source/blender/blenvm/util/bvm_util_typedesc.h b/source/blender/blenvm/util/bvm_util_typedesc.h
index aada4f0..0a985b6b 100644
--- a/source/blender/blenvm/util/bvm_util_typedesc.h
+++ b/source/blender/blenvm/util/bvm_util_typedesc.h
@@ -36,6 +36,7 @@
extern "C" {
#include "BKE_DerivedMesh.h"
+#include "BKE_cdderivedmesh.h"
#include "RNA_access.h"
}
@@ -296,6 +297,19 @@ struct DerivedMeshDestructor {
typedef node_data_ptr<DerivedMesh, DerivedMeshDestructor> mesh_ptr;
+namespace detail {
+
+static mesh_ptr create_empty_mesh()
+{
+ DerivedMesh *dm = CDDM_new(0, 0, 0, 0, 0);
+ dm->needsFree = 0;
+ return mesh_ptr(dm);
+}
+
+}
+
+static const mesh_ptr __empty_mesh__ = detail::create_empty_mesh();
+
template <BVMType type>
struct BaseTypeTraits;
More information about the Bf-blender-cvs
mailing list