forked from bartvdbraak/blender
My first DerivedMesh code! :)
Bugfix #3002: Using 'calc weights from envelope' WKey in weightpaint mode now uses the subsurfered vertex coordinates to calculate weights.
This commit is contained in:
parent
7939735887
commit
6cff3258d5
@ -49,6 +49,7 @@
|
|||||||
#include "BKE_constraint.h"
|
#include "BKE_constraint.h"
|
||||||
#include "BKE_deform.h"
|
#include "BKE_deform.h"
|
||||||
#include "BKE_depsgraph.h"
|
#include "BKE_depsgraph.h"
|
||||||
|
#include "BKE_DerivedMesh.h"
|
||||||
#include "BKE_displist.h"
|
#include "BKE_displist.h"
|
||||||
#include "BKE_global.h"
|
#include "BKE_global.h"
|
||||||
#include "BKE_object.h"
|
#include "BKE_object.h"
|
||||||
@ -576,19 +577,50 @@ void paste_posebuf (int flip)
|
|||||||
|
|
||||||
/* ********************************************** */
|
/* ********************************************** */
|
||||||
|
|
||||||
|
struct vgroup_map {
|
||||||
|
float head[3], tail[3];
|
||||||
|
Bone *bone;
|
||||||
|
bDeformGroup *dg;
|
||||||
|
Object *meshobj;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void pose_adds_vgroups__mapFunc(void *userData, int index, float *co, float *no_f, short *no_s)
|
||||||
|
{
|
||||||
|
struct vgroup_map *map= userData;
|
||||||
|
float vec[3], fac;
|
||||||
|
|
||||||
|
|
||||||
|
VECCOPY(vec, co);
|
||||||
|
Mat4MulVecfl(map->meshobj->obmat, vec);
|
||||||
|
|
||||||
|
/* get the distance-factor from the vertex to bone */
|
||||||
|
fac= distfactor_to_bone (vec, map->head, map->tail, map->bone->rad_head, map->bone->rad_tail, map->bone->dist);
|
||||||
|
|
||||||
|
/* add to vgroup. this call also makes me->dverts */
|
||||||
|
if(fac!=0.0f)
|
||||||
|
add_vert_to_defgroup (map->meshobj, map->dg, index, fac, WEIGHT_REPLACE);
|
||||||
|
else
|
||||||
|
remove_vert_defgroup (map->meshobj, map->dg, index);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void pose_adds_vgroups(Object *meshobj)
|
void pose_adds_vgroups(Object *meshobj)
|
||||||
{
|
{
|
||||||
|
struct vgroup_map map;
|
||||||
|
DerivedMesh *dm;
|
||||||
Object *poseobj= meshobj->parent;
|
Object *poseobj= meshobj->parent;
|
||||||
bPoseChannel *pchan;
|
bPoseChannel *pchan;
|
||||||
Bone *bone;
|
Bone *bone;
|
||||||
bDeformGroup *dg;
|
bDeformGroup *dg;
|
||||||
Mesh *me= meshobj->data;
|
int DMneedsFree;
|
||||||
MVert *mvert;
|
|
||||||
float head[3], tail[3], vec[3], fac;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if(poseobj==NULL || (poseobj->flag & OB_POSEMODE)==0) return;
|
if(poseobj==NULL || (poseobj->flag & OB_POSEMODE)==0) return;
|
||||||
|
|
||||||
|
dm = mesh_get_derived_final(meshobj, &DMneedsFree);
|
||||||
|
|
||||||
|
map.meshobj= meshobj;
|
||||||
|
|
||||||
for(pchan= poseobj->pose->chanbase.first; pchan; pchan= pchan->next) {
|
for(pchan= poseobj->pose->chanbase.first; pchan; pchan= pchan->next) {
|
||||||
bone= pchan->bone;
|
bone= pchan->bone;
|
||||||
if(bone->flag & (BONE_SELECTED)) {
|
if(bone->flag & (BONE_SELECTED)) {
|
||||||
@ -599,31 +631,30 @@ void pose_adds_vgroups(Object *meshobj)
|
|||||||
dg= add_defgroup_name(meshobj, bone->name);
|
dg= add_defgroup_name(meshobj, bone->name);
|
||||||
|
|
||||||
/* get the root of the bone in global coords */
|
/* get the root of the bone in global coords */
|
||||||
VECCOPY(head, bone->arm_head);
|
VECCOPY(map.head, bone->arm_head);
|
||||||
Mat4MulVecfl(poseobj->obmat, head);
|
Mat4MulVecfl(poseobj->obmat, map.head);
|
||||||
|
|
||||||
/* get the tip of the bone in global coords */
|
/* get the tip of the bone in global coords */
|
||||||
VECCOPY(tail, bone->arm_tail);
|
VECCOPY(map.tail, bone->arm_tail);
|
||||||
Mat4MulVecfl(poseobj->obmat, tail);
|
Mat4MulVecfl(poseobj->obmat, map.tail);
|
||||||
|
|
||||||
/* todo; get the optimal vertices instead of mverts */
|
/* use the optimal vertices instead of mverts */
|
||||||
mvert= me->mvert;
|
map.dg= dg;
|
||||||
for ( i=0 ; i < me->totvert ; i++ , mvert++) {
|
map.bone= bone;
|
||||||
VECCOPY(vec, mvert->co);
|
if(dm->foreachMappedVert)
|
||||||
Mat4MulVecfl(meshobj->obmat, vec);
|
dm->foreachMappedVert(dm, pose_adds_vgroups__mapFunc, (void*) &map);
|
||||||
|
else {
|
||||||
/* get the distance-factor from the vertex to bone */
|
Mesh *me= meshobj->data;
|
||||||
fac= distfactor_to_bone (vec, head, tail, bone->rad_head, bone->rad_tail, bone->dist);
|
int i;
|
||||||
|
for(i=0; i<me->totvert; i++)
|
||||||
/* add to vgroup. this call also makes me->dverts */
|
pose_adds_vgroups__mapFunc(&map, i, (me->mvert+i)->co, NULL, NULL);
|
||||||
if(fac!=0.0f)
|
|
||||||
add_vert_to_defgroup (meshobj, dg, i, fac, WEIGHT_REPLACE);
|
|
||||||
else
|
|
||||||
remove_vert_defgroup (meshobj, dg, i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (DMneedsFree) dm->release(dm);
|
||||||
|
|
||||||
allqueue(REDRAWVIEW3D, 0);
|
allqueue(REDRAWVIEW3D, 0);
|
||||||
allqueue(REDRAWBUTSEDIT, 0);
|
allqueue(REDRAWBUTSEDIT, 0);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user