code cleanup: move functions for getting defgroup arrays from objects out of editors into blenkernel, since they are generally useful.

This commit is contained in:
Campbell Barton
2012-09-05 02:51:55 +00:00
parent a4b71f4e01
commit 84dc5c2992
4 changed files with 165 additions and 86 deletions

View File

@@ -0,0 +1,37 @@
/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributor(s): Campbell Barton
*
* ***** END GPL LICENSE BLOCK *****
*/
#ifndef __BKE_OBJECT_DEFORM_H__
#define __BKE_OBJECT_DEFORM_H__
/** \file BKE_object_vgroup.h
* \ingroup bke
* \brief Functions for dealing with objects and deform verts,
* used by painting and tools.
*/
struct Object;
char *BKE_objdef_lock_flags_get(struct Object *ob, const int defbase_tot);
char *BKE_objdef_validmap_get(struct Object *ob, const int defbase_tot);
#endif /* __BKE_OBJECT_DEFORM_H__ */

View File

@@ -115,6 +115,7 @@ set(SRC
intern/nla.c
intern/node.c
intern/object.c
intern/object_deform.c
intern/ocean.c
intern/packedFile.c
intern/paint.c
@@ -203,6 +204,7 @@ set(SRC
BKE_nla.h
BKE_node.h
BKE_object.h
BKE_object_deform.h
BKE_ocean.h
BKE_packedFile.h
BKE_paint.h

View File

@@ -0,0 +1,123 @@
/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file blender/blenkernel/intern/object_deform.c
* \ingroup bke
*/
#include <stdlib.h>
#include "MEM_guardedalloc.h"
#include "BLI_utildefines.h"
#include "BLI_ghash.h"
#include "BKE_object_deform.h" /* own include */
#include "BKE_modifier.h"
#include "DNA_armature_types.h"
#include "DNA_modifier_types.h"
#include "DNA_object_types.h"
/* --- functions for getting vgroup aligned maps --- */
/**
* gets the status of "flag" for each bDeformGroup
* in ob->defbase and returns an array containing them
*/
char *BKE_objdef_lock_flags_get(Object *ob, const int defbase_tot)
{
char is_locked = FALSE;
int i;
//int defbase_tot = BLI_countlist(&ob->defbase);
char *lock_flags = MEM_mallocN(defbase_tot * sizeof(char), "defflags");
bDeformGroup *defgroup;
for (i = 0, defgroup = ob->defbase.first; i < defbase_tot && defgroup; defgroup = defgroup->next, i++) {
lock_flags[i] = ((defgroup->flag & DG_LOCK_WEIGHT) != 0);
is_locked |= lock_flags[i];
}
if (is_locked) {
return lock_flags;
}
MEM_freeN(lock_flags);
return NULL;
}
char *BKE_objdef_validmap_get(Object *ob, const int defbase_tot)
{
bDeformGroup *dg;
ModifierData *md;
char *vgroup_validmap;
GHash *gh;
int i, step1 = 1;
//int defbase_tot = BLI_countlist(&ob->defbase);
if (ob->defbase.first == NULL) {
return NULL;
}
gh = BLI_ghash_str_new("BKE_objdef_validmap_get gh");
/* add all names to a hash table */
for (dg = ob->defbase.first; dg; dg = dg->next) {
BLI_ghash_insert(gh, dg->name, NULL);
}
BLI_assert(BLI_ghash_size(gh) == defbase_tot);
/* now loop through the armature modifiers and identify deform bones */
for (md = ob->modifiers.first; md; md = !md->next && step1 ? (step1 = 0), modifiers_getVirtualModifierList(ob) : md->next) {
if (!(md->mode & (eModifierMode_Realtime | eModifierMode_Virtual)))
continue;
if (md->type == eModifierType_Armature) {
ArmatureModifierData *amd = (ArmatureModifierData *) md;
if (amd->object && amd->object->pose) {
bPose *pose = amd->object->pose;
bPoseChannel *chan;
for (chan = pose->chanbase.first; chan; chan = chan->next) {
if (chan->bone->flag & BONE_NO_DEFORM)
continue;
if (BLI_ghash_remove(gh, chan->name, NULL, NULL)) {
BLI_ghash_insert(gh, chan->name, SET_INT_IN_POINTER(1));
}
}
}
}
}
vgroup_validmap = MEM_mallocN(defbase_tot, "wpaint valid map");
/* add all names to a hash table */
for (dg = ob->defbase.first, i = 0; dg; dg = dg->next, i++) {
vgroup_validmap[i] = (BLI_ghash_lookup(gh, dg->name) != NULL);
}
BLI_assert(i == BLI_ghash_size(gh));
BLI_ghash_free(gh, NULL, NULL);
return vgroup_validmap;
}

View File

@@ -72,6 +72,7 @@
#include "BKE_mesh.h"
#include "BKE_modifier.h"
#include "BKE_object.h"
#include "BKE_object_deform.h"
#include "BKE_paint.h"
#include "BKE_report.h"
@@ -1308,29 +1309,6 @@ static char has_locked_group(MDeformVert *dvert, const int defbase_tot,
}
return FALSE;
}
/*
* gen_lck_flags gets the status of "flag" for each bDeformGroup
* in ob->defbase and returns an array containing them
*/
static char *gen_lock_flags(Object *ob, int defbase_tot)
{
char is_locked = FALSE;
int i;
//int defbase_tot = BLI_countlist(&ob->defbase);
char *lock_flags = MEM_mallocN(defbase_tot * sizeof(char), "defflags");
bDeformGroup *defgroup;
for (i = 0, defgroup = ob->defbase.first; i < defbase_tot && defgroup; defgroup = defgroup->next, i++) {
lock_flags[i] = ((defgroup->flag & DG_LOCK_WEIGHT) != 0);
is_locked |= lock_flags[i];
}
if (is_locked) {
return lock_flags;
}
MEM_freeN(lock_flags);
return NULL;
}
static int has_locked_group_selected(int defbase_tot, const char *defbase_sel, const char *lock_flags)
{
@@ -1722,10 +1700,6 @@ static int get_first_selected_nonzero_weight(MDeformVert *dvert, const int defba
return -1;
}
static char *wpaint_make_validmap(Object *ob);
static void do_weight_paint_vertex(
/* vars which remain the same for every vert */
VPaint *wp, Object *ob, const WeightPaintInfo *wpi,
@@ -2067,63 +2041,6 @@ struct WPaintData {
int defbase_tot;
};
static char *wpaint_make_validmap(Object *ob)
{
bDeformGroup *dg;
ModifierData *md;
char *vgroup_validmap;
GHash *gh;
int i, step1 = 1;
if (ob->defbase.first == NULL) {
return NULL;
}
gh = BLI_ghash_str_new("wpaint_make_validmap gh");
/* add all names to a hash table */
for (dg = ob->defbase.first; dg; dg = dg->next) {
BLI_ghash_insert(gh, dg->name, NULL);
}
/* now loop through the armature modifiers and identify deform bones */
for (md = ob->modifiers.first; md; md = !md->next && step1 ? (step1 = 0), modifiers_getVirtualModifierList(ob) : md->next) {
if (!(md->mode & (eModifierMode_Realtime | eModifierMode_Virtual)))
continue;
if (md->type == eModifierType_Armature) {
ArmatureModifierData *amd = (ArmatureModifierData *) md;
if (amd->object && amd->object->pose) {
bPose *pose = amd->object->pose;
bPoseChannel *chan;
for (chan = pose->chanbase.first; chan; chan = chan->next) {
if (chan->bone->flag & BONE_NO_DEFORM)
continue;
if (BLI_ghash_remove(gh, chan->name, NULL, NULL)) {
BLI_ghash_insert(gh, chan->name, SET_INT_IN_POINTER(1));
}
}
}
}
}
vgroup_validmap = MEM_mallocN(BLI_ghash_size(gh), "wpaint valid map");
/* add all names to a hash table */
for (dg = ob->defbase.first, i = 0; dg; dg = dg->next, i++) {
vgroup_validmap[i] = (BLI_ghash_lookup(gh, dg->name) != NULL);
}
BLI_assert(i == BLI_ghash_size(gh));
BLI_ghash_free(gh, NULL, NULL);
return vgroup_validmap;
}
static int wpaint_stroke_test_start(bContext *C, wmOperator *op, const float UNUSED(mouse[2]))
{
Scene *scene = CTX_data_scene(C);
@@ -2202,9 +2119,9 @@ static int wpaint_stroke_test_start(bContext *C, wmOperator *op, const float UNU
/* set up auto-normalize, and generate map for detecting which
* vgroups affect deform bones */
wpd->defbase_tot = BLI_countlist(&ob->defbase);
wpd->lock_flags = gen_lock_flags(ob, wpd->defbase_tot);
wpd->lock_flags = BKE_objdef_lock_flags_get(ob, wpd->defbase_tot);
if (ts->auto_normalize || ts->multipaint || wpd->lock_flags) {
wpd->vgroup_validmap = wpaint_make_validmap(ob);
wpd->vgroup_validmap = BKE_objdef_validmap_get(ob, wpd->defbase_tot);
}
/* painting on subsurfs should give correct points too, this returns me->totvert amount */