[Bf-blender-cvs] [2218d7bf9ef] functions: check function signature in modifier
Jacques Lucke
noreply at git.blender.org
Wed Feb 20 17:21:32 CET 2019
Commit: 2218d7bf9efae155a4e5e3a535904c58ac5ab160
Author: Jacques Lucke
Date: Wed Feb 20 16:06:09 2019 +0100
Branches: functions
https://developer.blender.org/rB2218d7bf9efae155a4e5e3a535904c58ac5ab160
check function signature in modifier
===================================================================
M source/blender/functions/FN_functions.h
M source/blender/functions/c_wrapper.cpp
M source/blender/modifiers/intern/MOD_functiondeform.c
===================================================================
diff --git a/source/blender/functions/FN_functions.h b/source/blender/functions/FN_functions.h
index e677ad9ac50..843c9649a33 100644
--- a/source/blender/functions/FN_functions.h
+++ b/source/blender/functions/FN_functions.h
@@ -19,9 +19,9 @@ FnCallable FN_function_get_callable(FnFunction fn);
void FN_function_call(FnCallable call, FnTuple fn_in, FnTuple fn_out);
void FN_function_free(FnFunction fn);
+bool FN_function_has_signature(FnFunction, FnType *inputs, FnType *outputs);
uint FN_input_amount(FnFunction fn);
uint FN_output_amount(FnFunction fn);
-
bool FN_input_has_type(FnFunction fn, uint index, FnType type);
bool FN_output_has_type(FnFunction fn, uint index, FnType type);
diff --git a/source/blender/functions/c_wrapper.cpp b/source/blender/functions/c_wrapper.cpp
index 91ce024f3b7..8803b14a223 100644
--- a/source/blender/functions/c_wrapper.cpp
+++ b/source/blender/functions/c_wrapper.cpp
@@ -39,6 +39,26 @@ void FN_function_free(FnFunction fn)
unwrap(fn)->decref();
}
+
+bool FN_function_has_signature(FnFunction fn, FnType *inputs, FnType *outputs)
+{
+ uint input_amount;
+ uint output_amount;
+ for (input_amount = 0; inputs[input_amount]; input_amount++) {}
+ for (output_amount = 0; outputs[output_amount]; output_amount++) {}
+
+ if (FN_input_amount(fn) != input_amount) return false;
+ if (FN_output_amount(fn) != output_amount) return false;
+
+ for (uint i = 0; i < input_amount; i++) {
+ if (!FN_input_has_type(fn, i, inputs[i])) return false;
+ }
+ for (uint i = 0; i < output_amount; i++) {
+ if (!FN_output_has_type(fn, i, outputs[i])) return false;
+ }
+ return true;
+}
+
uint FN_input_amount(FnFunction fn)
{
return unwrap(fn)->ptr()->signature().inputs().size();
diff --git a/source/blender/modifiers/intern/MOD_functiondeform.c b/source/blender/modifiers/intern/MOD_functiondeform.c
index 1dad929de08..ef38cefd22d 100644
--- a/source/blender/modifiers/intern/MOD_functiondeform.c
+++ b/source/blender/modifiers/intern/MOD_functiondeform.c
@@ -59,6 +59,22 @@ static FnFunction get_current_function(FunctionDeformModifierData *fdmd)
return FN_tree_to_function(tree);
}
+static bool is_deform_function(FnFunction fn)
+{
+ FnType float_ty = FN_type_get_float();
+ FnType fvec3_ty = FN_type_get_fvec3();
+
+ FnType inputs[] = { fvec3_ty, float_ty, NULL };
+ FnType outputs[] = { float_ty, NULL };
+
+ bool match = FN_function_has_signature(fn, inputs, outputs);
+
+ FN_type_free(float_ty);
+ FN_type_free(fvec3_ty);
+
+ return match;
+}
+
static void do_deformation(
FunctionDeformModifierData *fdmd,
float (*vertexCos)[3],
@@ -68,6 +84,9 @@ static void do_deformation(
if (fn == NULL) {
return;
}
+ if (!is_deform_function(fn)) {
+ return;
+ }
FnCallable fn_call = FN_function_get_callable(fn);
BLI_assert(fn_call);
More information about the Bf-blender-cvs
mailing list