[Bf-blender-cvs] [e431c5b] object_nodes: Added an "Iteration" node as a general-purpose input for expressions.
Lukas Tönne
noreply at git.blender.org
Tue Dec 1 09:53:38 CET 2015
Commit: e431c5bde6f5baba96bbf2f33f2f27dcfef7919e
Author: Lukas Tönne
Date: Tue Dec 1 09:52:07 2015 +0100
Branches: object_nodes
https://developer.blender.org/rBe431c5bde6f5baba96bbf2f33f2f27dcfef7919e
Added an "Iteration" node as a general-purpose input for expressions.
This is used by the Array modifier node to give a meaningful per-instance
input to calculate a transform from.
===================================================================
M release/scripts/startup/bl_operators/object_nodes.py
M source/blender/blenvm/bvm/bvm_eval.cc
M source/blender/blenvm/bvm/bvm_eval.h
M source/blender/blenvm/bvm/bvm_eval_mesh.h
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 58bc50d..3f39164 100644
--- a/release/scripts/startup/bl_operators/object_nodes.py
+++ b/release/scripts/startup/bl_operators/object_nodes.py
@@ -70,6 +70,7 @@ node_categories = [
]),
GeometryNodeCategory("GEO_INPUT", "Input", items=[
+ NodeItem("ObjectIterationNode"),
NodeItem("GeometryMeshLoadNode"),
]),
GeometryNodeCategory("GEO_OUTPUT", "Output", items=[
@@ -184,12 +185,24 @@ class NodeTreeBase():
###############################################################################
# Generic Nodes
-class MathNodeBase():
+class CommonNodeBase():
@classmethod
def poll(cls, ntree):
return isinstance(ntree, NodeTreeBase)
-class MathNode(MathNodeBase, ObjectNode):
+class IterationNode(CommonNodeBase, ObjectNode):
+ '''Iteration number'''
+ bl_idname = 'ObjectIterationNode'
+ bl_label = 'Iteration'
+
+ def init(self, context):
+ self.outputs.new('NodeSocketInt', "N")
+
+ def compile(self, compiler):
+ node = compiler.add_node("ITERATION", self.name)
+ compiler.map_output(0, node, "value")
+
+class MathNode(CommonNodeBase, ObjectNode):
'''Math '''
bl_idname = 'ObjectMathNode'
bl_label = 'Math'
@@ -252,7 +265,7 @@ class MathNode(MathNodeBase, ObjectNode):
compiler.map_output(0, node, "value")
-class VectorMathNode(MathNodeBase, ObjectNode):
+class VectorMathNode(CommonNodeBase, ObjectNode):
'''Vector Math '''
bl_idname = 'ObjectVectorMathNode'
bl_label = 'Vector Math'
@@ -310,7 +323,7 @@ class VectorMathNode(MathNodeBase, ObjectNode):
compiler.map_output(1, node, "value")
-class SeparateVectorNode(MathNodeBase, ObjectNode):
+class SeparateVectorNode(CommonNodeBase, ObjectNode):
'''Separate vector into elements'''
bl_idname = 'ObjectSeparateVectorNode'
bl_label = 'Separate Vector'
@@ -338,7 +351,7 @@ class SeparateVectorNode(MathNodeBase, ObjectNode):
compiler.map_output(2, node, "value")
-class CombineVectorNode(MathNodeBase, ObjectNode):
+class CombineVectorNode(CommonNodeBase, ObjectNode):
'''Combine vector from component values'''
bl_idname = 'ObjectCombineVectorNode'
bl_label = 'Combine Vector'
diff --git a/source/blender/blenvm/bvm/bvm_eval.cc b/source/blender/blenvm/bvm/bvm_eval.cc
index ac7aa5d..e8dbc48 100644
--- a/source/blender/blenvm/bvm/bvm_eval.cc
+++ b/source/blender/blenvm/bvm/bvm_eval.cc
@@ -406,6 +406,11 @@ static void eval_op_mix_rgb(float *stack, int mode, StackIndex offset_col_a, Sta
stack_store_float4(stack, offset_r, a);
}
+static void eval_op_iteration(const EvalData *data, float *stack, StackIndex offset)
+{
+ stack_store_int(stack, offset, data->iteration);
+}
+
static void eval_op_tex_coord(const EvalData *data, float *stack, StackIndex offset)
{
stack_store_float3(stack, offset, data->texture.co);
@@ -808,6 +813,12 @@ void EvalContext::eval_instructions(const EvalGlobals *globals, const EvalData *
eval_op_mix_rgb(stack, mode, offset_col_a, offset_col_b, offset_fac, offset_r);
break;
}
+
+ case OP_ITERATION: {
+ StackIndex offset = fn->read_stack_index(&instr);
+ eval_op_iteration(data, stack, offset);
+ break;
+ }
case OP_TEX_COORD: {
StackIndex offset = fn->read_stack_index(&instr);
diff --git a/source/blender/blenvm/bvm/bvm_eval.h b/source/blender/blenvm/bvm/bvm_eval.h
index 57423bd..0be8487 100644
--- a/source/blender/blenvm/bvm/bvm_eval.h
+++ b/source/blender/blenvm/bvm/bvm_eval.h
@@ -91,6 +91,13 @@ struct EffectorEvalData {
};
struct TextureEvalData {
+ TextureEvalData() :
+ co(float3(0.0f, 0.0f, 0.0f)),
+ dxt(float3(0.0f, 0.0f, 0.0f)),
+ dyt(float3(0.0f, 0.0f, 0.0f)),
+ cfra(0),
+ osatex(0)
+ {}
float3 co;
float3 dxt, dyt;
int cfra;
@@ -98,16 +105,21 @@ struct TextureEvalData {
};
struct ModifierEvalData {
+ ModifierEvalData() :
+ base_mesh(NULL)
+ {}
struct Mesh *base_mesh;
};
struct EvalData {
- EvalData()
+ EvalData() :
+ iteration(0)
{}
EffectorEvalData effector;
TextureEvalData texture;
ModifierEvalData modifier;
+ int iteration;
MEM_CXX_CLASS_ALLOC_FUNCS("BVM:EvalData")
};
diff --git a/source/blender/blenvm/bvm/bvm_eval_mesh.h b/source/blender/blenvm/bvm/bvm_eval_mesh.h
index 5bc8be7..d782d7e 100644
--- a/source/blender/blenvm/bvm/bvm_eval_mesh.h
+++ b/source/blender/blenvm/bvm/bvm_eval_mesh.h
@@ -50,6 +50,7 @@ static DerivedMesh *do_array(const EvalGlobals *globals, const EvalData *data, c
DerivedMesh *dm, int count, int fn_transform, StackIndex offset_transform)
{
const bool use_recalc_normals = (dm->dirty & DM_DIRTY_NORMALS);
+ EvalData iter_data = *data;
int chunk_nverts = dm->getNumVerts(dm);
int chunk_nedges = dm->getNumEdges(dm);
@@ -63,6 +64,7 @@ static DerivedMesh *do_array(const EvalGlobals *globals, const EvalData *data, c
int result_npolys = chunk_npolys * count;
/* Initialize a result dm */
+ MVert *orig_dm_verts = dm->getVertArray(dm);
DerivedMesh *result = CDDM_from_template(dm, result_nverts, result_nedges, 0, result_nloops, result_npolys);
MVert *result_dm_verts = CDDM_get_verts(result);
@@ -95,18 +97,18 @@ static DerivedMesh *do_array(const EvalGlobals *globals, const EvalData *data, c
DM_copy_loop_data(result, result, 0, c * chunk_nloops, chunk_nloops);
DM_copy_poly_data(result, result, 0, c * chunk_npolys, chunk_npolys);
- MVert *mv_prev = result_dm_verts;
- MVert *mv = mv_prev + c * chunk_nverts;
-
/* calculate transform for the copy */
- kernel_data->context->eval_expression(globals, data, kernel_data->function, fn_transform, stack);
+ iter_data.iteration = c;
+ kernel_data->context->eval_expression(globals, &iter_data, kernel_data->function, fn_transform, stack);
matrix44 tfm = stack_load_matrix44(stack, offset_transform);
float mat[4][4];
transpose_m4_m4(mat, (float (*)[4])tfm.data);
/* apply offset to all new verts */
- for (int i = 0; i < chunk_nverts; i++, mv++, mv_prev++) {
- mul_m4_v3(mat, mv->co);
+ MVert *mv_orig = orig_dm_verts;
+ MVert *mv = result_dm_verts + c * chunk_nverts;
+ for (int i = 0; i < chunk_nverts; i++, mv++, mv_orig++) {
+ mul_v3_m4v3(mv->co, mat, mv_orig->co);
/* We have to correct normals too, if we do not tag them as dirty! */
if (!use_recalc_normals) {
diff --git a/source/blender/blenvm/bvm/bvm_opcode.h b/source/blender/blenvm/bvm/bvm_opcode.h
index db61fd0..8fd8760 100644
--- a/source/blender/blenvm/bvm/bvm_opcode.h
+++ b/source/blender/blenvm/bvm/bvm_opcode.h
@@ -92,6 +92,8 @@ enum OpCode {
OP_MIX_RGB,
+ OP_ITERATION,
+
OP_TEX_COORD,
OP_TEX_PROC_VORONOI,
OP_TEX_PROC_BLEND,
diff --git a/source/blender/blenvm/compile/bvm_nodegraph.cc b/source/blender/blenvm/compile/bvm_nodegraph.cc
index dbad9b9..61a2574 100644
--- a/source/blender/blenvm/compile/bvm_nodegraph.cc
+++ b/source/blender/blenvm/compile/bvm_nodegraph.cc
@@ -662,9 +662,42 @@ SocketPair NodeGraph::add_float4_converter(const SocketPair &from, BVMType to_ty
return result;
}
-SocketPair NodeGraph::add_int_converter(const SocketPair &/*from*/, BVMType /*to_type*/)
+SocketPair NodeGraph::add_int_converter(const SocketPair &from, BVMType to_type)
{
SocketPair result(NULL, "");
+ switch (to_type) {
+ case BVM_FLOAT: {
+ NodeInstance *node = add_node("INT_TO_FLOAT");
+ add_link(from.node, from.socket, node, "value");
+ result = SocketPair(node, "value");
+ break;
+ }
+ case BVM_FLOAT3: {
+ NodeInstance *fnode = add_node("INT_TO_FLOAT");
+ add_link(from.node, from.socket, fnode, "value");
+
+ NodeInstance *node = add_node("SET_FLOAT3");
+ add_link(fnode, "value", node, "value_x");
+ add_link(fnode, "value", node, "value_y");
+ add_link(fnode, "value", node, "value_z");
+ result = SocketPair(node, "value");
+ break;
+ }
+ case BVM_FLOAT4: {
+ NodeInstance *fnode = add_node("INT_TO_FLOAT");
+ add_link(from.node, from.socket, fnode, "value");
+
+ NodeInstance *node = add_node("SET_FLOAT4");
+ add_link(fnode, "value", node, "value_x");
+ add_link(fnode, "value", node, "value_y");
+ add_link(fnode, "value", node, "value_z");
+ add_link(fnode, "value", node, "value_w");
+ result = SocketPair(node, "value");
+ break;
+ }
+ default:
+ break;
+ }
return result;
}
@@ -1197,6 +1230,8 @@ OpCode get_opcode_from_node_type(const string &node)
NODETYPE(MIX_RGB);
+ NODETYPE(ITERATION);
+
NODETYPE(TEX_COORD);
NODETYPE(TEX_PROC_VORONOI);
NODETYPE(TEX_PROC_CLOUDS);
@@ -1416,6 +1451,9 @@ static void register_opcode_node_types()
nt->add_input("color2", BVM_FLOAT4, float4(0.0f, 0.0f, 0.0f, 1.0f));
nt->add_output("color", BVM_FLOAT4, float4(0.0f, 0.0f, 0.0f, 1.0f));
+ nt = NodeGraph::add_function_node_type("ITERATION");
+ nt->add_output("value", BVM_INT, 0);
+
nt = NodeGraph::add_function_node_type("TEX_COORD");
nt->add_output("value", BVM_FLOAT3, float3(0.0f, 0.0f, 0.0f));
More information about the Bf-blender-cvs
mailing list