[Bf-blender-cvs] [cfafdde9277] functions: use function to generate a list of floats
Jacques Lucke
noreply at git.blender.org
Sun Mar 10 18:32:44 CET 2019
Commit: cfafdde927788607057acfec8d2ebe5e29a68575
Author: Jacques Lucke
Date: Sun Mar 10 18:10:53 2019 +0100
Branches: functions
https://developer.blender.org/rBcfafdde927788607057acfec8d2ebe5e29a68575
use function to generate a list of floats
===================================================================
M source/blender/blenlib/BLI_shared.hpp
M source/blender/functions/FN-C.h
M source/blender/functions/c_wrapper.cpp
M source/blender/functions/frontends/data_flow_nodes/function_generation.cpp
M source/blender/functions/types/lists.hpp
M source/blender/modifiers/intern/MOD_displace.c
M source/blender/modifiers/intern/MOD_functiondeform.c
M source/blender/modifiers/intern/MOD_functionpoints.c
===================================================================
diff --git a/source/blender/blenlib/BLI_shared.hpp b/source/blender/blenlib/BLI_shared.hpp
index 029494aa385..8317536a3ba 100644
--- a/source/blender/blenlib/BLI_shared.hpp
+++ b/source/blender/blenlib/BLI_shared.hpp
@@ -129,6 +129,13 @@ namespace BLI {
return m_object;
}
+ T *move_ptr()
+ {
+ T *value = m_object;
+ m_object = nullptr;
+ return value;
+ }
+
T *operator->() const
{
return this->ptr();
diff --git a/source/blender/functions/FN-C.h b/source/blender/functions/FN-C.h
index 2eb950eec03..c8d7a3a2805 100644
--- a/source/blender/functions/FN-C.h
+++ b/source/blender/functions/FN-C.h
@@ -11,12 +11,10 @@ extern "C" {
void FN_initialize(void);
+/************** Core *************/
+
typedef struct OpaqueFnFunction *FnFunction;
typedef struct OpaqueFnType *FnType;
-typedef struct OpaqueFnTuple *FnTuple;
-typedef struct OpaqueFnTupleCallBody *FnTupleCallBody;
-
-/************** Core *************/
void FN_function_free(FnFunction fn);
@@ -31,6 +29,8 @@ void FN_function_print(FnFunction fn);
/************** Types *************/
+typedef struct OpaqueFnFloatList *FnFloatList;
+
const char *FN_type_name(FnType type);
void FN_type_free(FnType type);
@@ -44,9 +44,16 @@ FnType FN_type_borrow_int32(void);
FnType FN_type_borrow_fvec3(void);
FnType FN_type_borrow_float_list(void);
+uint FN_list_size_float(FnFloatList list);
+float *FN_list_data_float(FnFloatList list);
+void FN_list_free_float(FnFloatList list);
+
/*************** Tuple Call ****************/
+typedef struct OpaqueFnTuple *FnTuple;
+typedef struct OpaqueFnTupleCallBody *FnTupleCallBody;
+
FnTupleCallBody FN_tuple_call_get(FnFunction fn);
void FN_tuple_call_invoke(FnTupleCallBody body, FnTuple fn_in, FnTuple fn_out);
FnTuple FN_tuple_for_input(FnTupleCallBody body);
@@ -56,10 +63,11 @@ void FN_tuple_free(FnTuple tuple);
void FN_tuple_set_float(FnTuple tuple, uint index, float value);
void FN_tuple_set_int32(FnTuple tuple, uint index, int32_t value);
-void FN_tuple_set_float_vector_3(FnTuple tuple, uint index, float vector[3]);
+void FN_tuple_set_fvec3(FnTuple tuple, uint index, float vector[3]);
float FN_tuple_get_float(FnTuple tuple, uint index);
int32_t FN_tuple_get_int32(FnTuple tuple, uint index);
-void FN_tuple_get_float_vector_3(FnTuple tuple, uint index, float dst[3]);
+void FN_tuple_get_fvec3(FnTuple tuple, uint index, float dst[3]);
+FnFloatList FN_tuple_relocate_out_float_list(FnTuple tuple, uint index);
uint fn_tuple_stack_prepare_size(FnTupleCallBody body);
void fn_tuple_prepare_stack(
@@ -87,6 +95,7 @@ void fn_tuple_destruct(FnTuple tuple);
FN_tuple_free(fn_in); \
FN_tuple_free(fn_out);
+
/*************** Dependencies ****************/
struct DepsNodeHandle;
diff --git a/source/blender/functions/c_wrapper.cpp b/source/blender/functions/c_wrapper.cpp
index ba37dfd9481..1e2cf523c32 100644
--- a/source/blender/functions/c_wrapper.cpp
+++ b/source/blender/functions/c_wrapper.cpp
@@ -20,6 +20,7 @@ WRAPPERS(Function *, FnFunction);
WRAPPERS(Type *, FnType);
WRAPPERS(Tuple *, FnTuple);
WRAPPERS(TupleCallBody *, FnTupleCallBody);
+WRAPPERS(List<float> *, FnFloatList);
static void playground()
{
@@ -196,16 +197,22 @@ int32_t FN_tuple_get_int32(FnTuple tuple, uint index)
using Types::Vector;
-void FN_tuple_set_float_vector_3(FnTuple tuple, uint index, float value[3])
+void FN_tuple_set_fvec3(FnTuple tuple, uint index, float value[3])
{
unwrap(tuple)->set<Vector>(index, *(Vector *)value);
}
-void FN_tuple_get_float_vector_3(FnTuple tuple, uint index, float dst[3])
+void FN_tuple_get_fvec3(FnTuple tuple, uint index, float dst[3])
{
*(Vector *)dst = unwrap(tuple)->get<Vector>(index);
}
+FnFloatList FN_tuple_relocate_out_float_list(FnTuple tuple, uint index)
+{
+ auto list = unwrap(tuple)->relocate_out<SharedFloatList>(index);
+ return wrap(list.move_ptr());
+}
+
const char *FN_type_name(FnType type)
{
return unwrap(type)->name().c_str();
@@ -234,6 +241,23 @@ SIMPLE_TYPE_GETTER(int32);
SIMPLE_TYPE_GETTER(fvec3);
SIMPLE_TYPE_GETTER(float_list);
+
+uint FN_list_size_float(FnFloatList list)
+{
+ return unwrap(list)->size();
+}
+
+float *FN_list_data_float(FnFloatList list)
+{
+ return unwrap(list)->data_ptr();
+}
+
+void FN_list_free_float(FnFloatList list)
+{
+ unwrap(list)->remove_user();
+}
+
+
FnFunction FN_tree_to_function(bNodeTree *btree)
{
TIMEIT("Tree to function");
diff --git a/source/blender/functions/frontends/data_flow_nodes/function_generation.cpp b/source/blender/functions/frontends/data_flow_nodes/function_generation.cpp
index 45f289ae3a7..3937312261e 100644
--- a/source/blender/functions/frontends/data_flow_nodes/function_generation.cpp
+++ b/source/blender/functions/frontends/data_flow_nodes/function_generation.cpp
@@ -16,6 +16,7 @@ namespace FN { namespace DataFlowNodes {
}
FunctionGraph fgraph = fgraph_.value();
+ // fgraph.graph()->to_dot__clipboard();
auto fn = SharedFunction::New(btree->id.name, fgraph.signature());
fgraph_add_DependenciesBody(fn, fgraph);
diff --git a/source/blender/functions/types/lists.hpp b/source/blender/functions/types/lists.hpp
index dee4610ab01..ab419a2f21b 100644
--- a/source/blender/functions/types/lists.hpp
+++ b/source/blender/functions/types/lists.hpp
@@ -15,11 +15,23 @@ namespace FN { namespace Types {
private:
SmallVector<T> m_data;
- ~List() {}
+ static constexpr bool DEBUG_ALLOCATIONS = true;
+
+ ~List()
+ {
+ if (DEBUG_ALLOCATIONS) {
+ std::cout << "List Freed" << std::endl;
+ }
+ }
public:
List()
- : BLI::SharedImmutable() {}
+ : BLI::SharedImmutable()
+ {
+ if (DEBUG_ALLOCATIONS) {
+ std::cout << "List Allocated" << std::endl;
+ }
+ }
void append(T value)
{
@@ -37,6 +49,11 @@ namespace FN { namespace Types {
return new_list;
}
+ T *data_ptr() const
+ {
+ return m_data.begin();
+ }
+
uint size() const
{
return m_data.size();
diff --git a/source/blender/modifiers/intern/MOD_displace.c b/source/blender/modifiers/intern/MOD_displace.c
index f472f5c8d85..8be69fe787d 100644
--- a/source/blender/modifiers/intern/MOD_displace.c
+++ b/source/blender/modifiers/intern/MOD_displace.c
@@ -227,7 +227,7 @@ static void displaceModifier_do_task(
FN_TUPLE_CALL_PREPARE_STACK(body, fn_in, fn_out);
- FN_tuple_set_float_vector_3(fn_in, 0, vertexCos[iter]);
+ FN_tuple_set_fvec3(fn_in, 0, vertexCos[iter]);
FN_tuple_set_int32(fn_in, 1, iter);
FN_tuple_call_invoke(body, fn_in, fn_out);
diff --git a/source/blender/modifiers/intern/MOD_functiondeform.c b/source/blender/modifiers/intern/MOD_functiondeform.c
index db43d712408..550e3602b2e 100644
--- a/source/blender/modifiers/intern/MOD_functiondeform.c
+++ b/source/blender/modifiers/intern/MOD_functiondeform.c
@@ -87,13 +87,13 @@ static void do_deformation(
int seed = fdmd->control2 * 234132;
for (int i = 0; i < numVerts; i++) {
- FN_tuple_set_float_vector_3(fn_in, 0, vertexCos[i]);
+ FN_tuple_set_fvec3(fn_in, 0, vertexCos[i]);
FN_tuple_set_int32(fn_in, 1, seed + i);
FN_tuple_set_float(fn_in, 2, fdmd->control1);
FN_tuple_call_invoke(body, fn_in, fn_out);
- FN_tuple_get_float_vector_3(fn_out, 0, vertexCos[i]);
+ FN_tuple_get_fvec3(fn_out, 0, vertexCos[i]);
}
clock_t end = clock();
diff --git a/source/blender/modifiers/intern/MOD_functionpoints.c b/source/blender/modifiers/intern/MOD_functionpoints.c
index b049c06ad53..0c3db37d1c7 100644
--- a/source/blender/modifiers/intern/MOD_functionpoints.c
+++ b/source/blender/modifiers/intern/MOD_functionpoints.c
@@ -58,11 +58,9 @@ static FnFunction get_current_function(FunctionPointsModifierData *fpmd)
FnType float_ty = FN_type_borrow_float();
FnType int32_ty = FN_type_borrow_int32();
- FnType fvec3_ty = FN_type_borrow_fvec3();
-
FnType float_list_ty = FN_type_borrow_float_list();
- FnType inputs[] = { int32_ty, NULL };
+ FnType inputs[] = { float_ty, int32_ty, NULL };
FnType outputs[] = { float_list_ty, NULL };
return FN_function_get_with_signature(tree, inputs, outputs);
@@ -70,18 +68,43 @@ static FnFunction get_current_function(FunctionPointsModifierData *fpmd)
static Mesh *build_point_mesh(FunctionPointsModifierData *fpmd)
{
- Mesh *mesh = BKE_mesh_new_nomain(2, 0, 0, 0, 0);
- float vec1[] = {4, 6, 3};
- float vec2[] = {1, 2, 3};
- copy_v3_v3(mesh->mvert + 0, vec1);
- copy_v3_v3(mesh->mvert + 1, vec2);
+ FnFunction fn = get_current_function(fpmd);
+ if (fn == NULL) {
+ modifier_setError(&fpmd->modifier, "Invalid function");
+ return BKE_mesh_new_nomain(0, 0, 0, 0, 0);
+ }
+
+ FnTupleCallBody body = FN_tuple_call_get(fn);
+
+ FN_TUPLE_CALL_PREPARE_STACK(body, fn_in, fn_out);
+
+ FN_tuple_set_float(fn_in, 0, fpmd->control1);
+ FN_tuple_set_int32(fn_in, 1, fpmd->control2);
+ FN_tuple_call_invoke(body, fn_in, fn_out);
+ FnFloatList list = FN_tuple_relocate_out_float_list(fn_out, 0);
+
+ FN_TUPLE_CALL_DESTRUCT_STACK(body, fn_in, fn_out);
+
+
+ FN_function_free(fn);
+
+ uint amount = FN_list_size_float(list);
+ float *ptr = FN_list_data_float(list);
+
+ Mesh *mesh = BKE_mesh_new_nomain(amount, 0, 0, 0, 0);
+ for (uint i = 0; i < amount; i++) {
+ float vec[3] = {0, 0, ptr[i]};
+ copy_v3_v3(mesh->mvert[i].co, vec);
+ }
+ FN_list_free_float(list);
+
return mesh;
}
static Mesh *applyModifier(
ModifierData *md,
- const struct ModifierEvalContext *ctx,
- struct Mesh *mesh)
+ const struct ModifierEvalContext *UNUSED(ctx),
+ struct Mesh *UNUSED(mesh))
{
return build_point_mesh((FunctionPointsModifierData *)md);
}
More information about the Bf-blender-cvs
mailing list