Commit: ebc898756a93ef1c4a768d9feb4b0f8cf9b8a4f6
Author: Jacques Lucke
Date:   Wed Jan 23 16:24:15 2019 +0100
Branches: functions
https://developer.blender.org/rBebc898756a93ef1c4a768d9feb4b0f8cf9b8a4f6

deform function test

===================================================================

M       source/blender/editors/object/object_edit.c
M       source/blender/functions/FN_functions.h
M       source/blender/functions/intern/c_wrapper.cpp

===================================================================

diff --git a/source/blender/editors/object/object_edit.c 
b/source/blender/editors/object/object_edit.c
index ce47ebea011..5ac3c25517e 100644
--- a/source/blender/editors/object/object_edit.c
+++ b/source/blender/editors/object/object_edit.c
@@ -1748,16 +1748,21 @@ void OBJECT_OT_link_to_collection(wmOperatorType *ot)
 
 static int test_functions_exec(bContext *UNUSED(C), wmOperator *UNUSED(op))
 {
-       FunctionRef fn = FN_get_add_const_function(100);
+       FunctionRef fn = FN_get_deform_function();
        FnInputsRef fn_in = FN_inputs_new(fn);
        FnOutputsRef fn_out = FN_outputs_new(fn);
 
-       int value = 42;
-       FN_inputs_set_index(fn_in, 0, &value);
+       float input[3] = {1, 2, 3};
+       float control = 10;
+       FN_inputs_set_index(fn_in, 0, input);
+       FN_inputs_set_index(fn_in, 1, &control);
+
        FN_function_call(fn, fn_in, fn_out);
-       int result;
-       FN_outputs_get_index(fn_out, 0, &result);
-       printf("Result: %d\n", result);
+
+       float result[3];
+       FN_outputs_get_index(fn_out, 0, result);
+
+       printf("Result: %f %f %f\n", result[0], result[1], result[2]);
 
        printf("Finished\n");
        return OPERATOR_FINISHED;
diff --git a/source/blender/functions/FN_functions.h 
b/source/blender/functions/FN_functions.h
index 01f0974ac68..1a6b708e90d 100644
--- a/source/blender/functions/FN_functions.h
+++ b/source/blender/functions/FN_functions.h
@@ -63,6 +63,7 @@ FnTypeRef FN_type_get_int32(void);
 FnTypeRef FN_type_get_float_vector_3d(void);
 
 FunctionRef FN_get_add_const_function(int value);
+FunctionRef FN_get_deform_function();
 
 #ifdef __cplusplus
 }
diff --git a/source/blender/functions/intern/c_wrapper.cpp 
b/source/blender/functions/intern/c_wrapper.cpp
index bc0f669747b..5d11316e1bf 100644
--- a/source/blender/functions/intern/c_wrapper.cpp
+++ b/source/blender/functions/intern/c_wrapper.cpp
@@ -72,3 +72,41 @@ FunctionRef FN_get_add_const_function(int value)
 {
        return (FunctionRef)AddConstFunction::Create(value);
 }
+
+#include <cmath>
+
+class DeformFunction : public FN::Function {
+private:
+       DeformFunction(FN::Signature sig)
+               : Function(sig) {}
+
+public:
+       static DeformFunction *Create()
+       {
+               FN::Signature sig({FN::Types::floatvec3d_ty, 
FN::Types::float_ty}, {FN::Types::floatvec3d_ty});
+               return new DeformFunction(sig);
+       }
+
+       bool call(const FN::Inputs &fn_in, FN::Outputs &fn_out) override
+       {
+               float vec[3];
+               float control;
+               fn_in.get(0, vec);
+               fn_in.get(1, &control);
+
+               float result[3];
+
+               result[0] = vec[0] * control;
+               result[1] = vec[1] + std::sin(control);
+               result[2] = vec[2];
+
+               fn_out.set(0, result);
+
+               return true;
+       }
+};
+
+FunctionRef FN_get_deform_function()
+{
+       return (FunctionRef)DeformFunction::Create();
+}
\ No newline at end of file

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to