[Bf-blender-cvs] [031bc7ca2d6] functions: Use Vector List in Function Points modifier

Jacques Lucke noreply at git.blender.org
Wed Mar 27 12:19:09 CET 2019


Commit: 031bc7ca2d61b060d8fb4f5f467b978382d7c058
Author: Jacques Lucke
Date:   Wed Mar 27 12:18:25 2019 +0100
Branches: functions
https://developer.blender.org/rB031bc7ca2d61b060d8fb4f5f467b978382d7c058

Use Vector List in Function Points modifier

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

M	source/blender/functions/FN-C.h
M	source/blender/functions/c_wrapper.cpp
M	source/blender/modifiers/intern/MOD_functionpoints.c

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

diff --git a/source/blender/functions/FN-C.h b/source/blender/functions/FN-C.h
index e3d2b2d6c41..92df8b8673c 100644
--- a/source/blender/functions/FN-C.h
+++ b/source/blender/functions/FN-C.h
@@ -33,24 +33,30 @@ void FN_function_print(FnFunction fn);
 /************** Types *************/
 
 typedef struct OpaqueFnFloatList *FnFloatList;
+typedef struct OpaqueFnFVec3List *FnFVec3List;
 
 const char *FN_type_name(FnType type);
 void FN_type_free(FnType type);
 
-FnType FN_type_get_float(void);
-FnType FN_type_get_int32(void);
-FnType FN_type_get_fvec3(void);
-FnType FN_type_get_float_list(void);
+#define TYPE_GET_AND_BORROW(name) \
+	FnType FN_type_get_##name(void); \
+	FnType FN_type_borrow_##name(void);
 
-FnType FN_type_borrow_float(void);
-FnType FN_type_borrow_int32(void);
-FnType FN_type_borrow_fvec3(void);
-FnType FN_type_borrow_float_list(void);
+TYPE_GET_AND_BORROW(float);
+TYPE_GET_AND_BORROW(int32);
+TYPE_GET_AND_BORROW(fvec3);
+TYPE_GET_AND_BORROW(float_list);
+TYPE_GET_AND_BORROW(fvec3_list);
+#undef TYPE_GET_AND_BORROW
 
-uint FN_list_size_float(FnFloatList list);
-float *FN_list_data_float(FnFloatList list);
-void FN_list_free_float(FnFloatList list);
+#define LIST_TYPE(name, ptr_type, list_type) \
+	uint FN_list_size_##name(list_type list); \
+	ptr_type FN_list_data_##name(list_type list); \
+	void FN_list_free_##name(list_type list);
 
+LIST_TYPE(float, float *, FnFloatList);
+LIST_TYPE(fvec3, float *, FnFVec3List);
+#undef LIST_TYPE
 
 /*************** Tuple Call ****************/
 
@@ -71,6 +77,7 @@ float FN_tuple_get_float(FnTuple tuple, uint index);
 int32_t FN_tuple_get_int32(FnTuple tuple, uint index);
 void FN_tuple_get_fvec3(FnTuple tuple, uint index, float dst[3]);
 FnFloatList FN_tuple_relocate_out_float_list(FnTuple tuple, uint index);
+FnFVec3List FN_tuple_relocate_out_fvec3_list(FnTuple tuple, uint index);
 
 uint fn_tuple_stack_prepare_size(FnTupleCallBody body);
 void fn_tuple_prepare_stack(
diff --git a/source/blender/functions/c_wrapper.cpp b/source/blender/functions/c_wrapper.cpp
index e0324605424..a051babe9b8 100644
--- a/source/blender/functions/c_wrapper.cpp
+++ b/source/blender/functions/c_wrapper.cpp
@@ -90,6 +90,7 @@ void FN_function_print(FnFunction fn)
 /**************** Types ******************/
 
 WRAPPERS(List<float> *, FnFloatList);
+WRAPPERS(List<Vector> *, FnFVec3List);
 
 const char *FN_type_name(FnType type)
 {
@@ -118,21 +119,18 @@ SIMPLE_TYPE_GETTER(float);
 SIMPLE_TYPE_GETTER(int32);
 SIMPLE_TYPE_GETTER(fvec3);
 SIMPLE_TYPE_GETTER(float_list);
+SIMPLE_TYPE_GETTER(fvec3_list);
 
-uint FN_list_size_float(FnFloatList list)
-{
-	return unwrap(list)->size();
-}
-
-float *FN_list_data_float(FnFloatList list)
-{
-	return unwrap(list)->data_ptr();
-}
+#define LIST_WRAPPER(name, ptr_type, list_type) \
+	uint FN_list_size_##name(list_type list) \
+	{ return unwrap(list)->size(); } \
+	ptr_type FN_list_data_##name(list_type list) \
+	{ return (ptr_type)unwrap(list)->data_ptr(); } \
+	void FN_list_free_##name(list_type list) \
+	{ unwrap(list)->remove_user(); }
 
-void FN_list_free_float(FnFloatList list)
-{
-	unwrap(list)->remove_user();
-}
+LIST_WRAPPER(float, float *, FnFloatList);
+LIST_WRAPPER(fvec3, float *, FnFVec3List);
 
 
 
@@ -241,6 +239,11 @@ FnFloatList FN_tuple_relocate_out_float_list(FnTuple tuple, uint index)
 	return wrap(list.extract_ptr());
 }
 
+FnFVec3List FN_tuple_relocate_out_fvec3_list(FnTuple tuple, uint index)
+{
+	auto list = unwrap(tuple)->relocate_out<SharedFVec3List>(index);
+	return wrap(list.extract_ptr());
+}
 
 
 /**************** Dependencies *******************/
diff --git a/source/blender/modifiers/intern/MOD_functionpoints.c b/source/blender/modifiers/intern/MOD_functionpoints.c
index 3dc85be1c3e..d923f3a04c5 100644
--- a/source/blender/modifiers/intern/MOD_functionpoints.c
+++ b/source/blender/modifiers/intern/MOD_functionpoints.c
@@ -58,10 +58,10 @@ static FnFunction get_current_function(FunctionPointsModifierData *fpmd)
 
 	FnType float_ty = FN_type_borrow_float();
 	FnType int32_ty = FN_type_borrow_int32();
-	FnType float_list_ty = FN_type_borrow_float_list();
+	FnType fvec3_list_ty = FN_type_borrow_fvec3_list();
 
 	FnType inputs[] = { float_ty, int32_ty, NULL };
-	FnType outputs[] = { float_list_ty, NULL };
+	FnType outputs[] = { fvec3_list_ty, NULL };
 
 	return FN_function_get_with_signature(tree, inputs, outputs);
 }
@@ -75,28 +75,25 @@ static Mesh *build_point_mesh(FunctionPointsModifierData *fpmd)
 	}
 
 	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);
+	FnFVec3List list = FN_tuple_relocate_out_fvec3_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);
+
+	uint amount = FN_list_size_fvec3(list);
+	float *ptr = FN_list_data_fvec3(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);
+		copy_v3_v3(mesh->mvert[i].co, ptr + (3 * i));
 	}
-	FN_list_free_float(list);
+	FN_list_free_fvec3(list);
 
 	return mesh;
 }



More information about the Bf-blender-cvs mailing list