[Bf-blender-cvs] [ba98e61] master: API calls for converting weights to float array
Campbell Barton
noreply at git.blender.org
Thu Jun 25 08:24:48 CEST 2015
Commit: ba98e6148b7f8ca1b9040c5555b7dfa011c13b90
Author: Campbell Barton
Date: Thu Jun 25 15:59:48 2015 +1000
Branches: master
https://developer.blender.org/rBba98e6148b7f8ca1b9040c5555b7dfa011c13b90
API calls for converting weights to float array
===================================================================
M source/blender/editors/include/ED_mesh.h
M source/blender/editors/object/object_vgroup.c
===================================================================
diff --git a/source/blender/editors/include/ED_mesh.h b/source/blender/editors/include/ED_mesh.h
index 9534da6..8e19ec8 100644
--- a/source/blender/editors/include/ED_mesh.h
+++ b/source/blender/editors/include/ED_mesh.h
@@ -243,6 +243,11 @@ void ED_vgroup_parray_mirror_assign(struct Object *ob,
void ED_vgroup_parray_remove_zero(struct MDeformVert **dvert_array, const int dvert_tot,
const bool *vgroup_validmap, const int vgroup_tot,
const float epsilon, const bool keep_single);
+void ED_vgroup_parray_to_weight_array(const struct MDeformVert **dvert_array, const int dvert_tot,
+ float *dvert_weights, const int def_nr);
+void ED_vgroup_parray_from_weight_array(struct MDeformVert **dvert_array, const int dvert_tot,
+ const float *dvert_weights, const int def_nr,
+ const bool remove_zero);
void ED_vgroup_mirror(struct Object *ob,
const bool mirror_weights, const bool flip_vgroups,
const bool all_vgroups, const bool use_topology,
diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c
index c8aa4a1..d586e35 100644
--- a/source/blender/editors/object/object_vgroup.c
+++ b/source/blender/editors/object/object_vgroup.c
@@ -427,6 +427,48 @@ bool ED_vgroup_array_copy(Object *ob, Object *ob_from)
return true;
}
+void ED_vgroup_parray_to_weight_array(
+ const MDeformVert **dvert_array, const int dvert_tot,
+ float *dvert_weights, const int def_nr)
+{
+ int i;
+
+ for (i = 0; i < dvert_tot; i++) {
+ const MDeformVert *dv = dvert_array[i];
+ dvert_weights[i] = dv ? defvert_find_weight(dv, def_nr) : 0.0f;
+ }
+}
+
+void ED_vgroup_parray_from_weight_array(
+ MDeformVert **dvert_array, const int dvert_tot,
+ const float *dvert_weights, const int def_nr, const bool remove_zero)
+{
+ int i;
+
+ for (i = 0; i < dvert_tot; i++) {
+ MDeformVert *dv = dvert_array[i];
+ if (dv) {
+ if (dvert_weights[i] > 0.0f) {
+ MDeformWeight *dw = defvert_verify_index(dv, def_nr);
+ BLI_assert(IN_RANGE_INCL(dvert_weights[i], 0.0f, 1.0f));
+ dw->weight = dvert_weights[i];
+ }
+ else {
+ MDeformWeight *dw = defvert_find_index(dv, def_nr);
+ if (dw) {
+ if (remove_zero) {
+ defvert_remove_group(dv, dw);
+ }
+ else {
+ dw->weight = 0.0f;
+ }
+ }
+ }
+ }
+ }
+}
+
+
/* TODO, cache flip data to speedup calls within a loop. */
static void mesh_defvert_mirror_update_internal(Object *ob,
MDeformVert *dvert_dst, MDeformVert *dvert_src,
More information about the Bf-blender-cvs
mailing list