forked from bartvdbraak/blender
Fix T41463: Mirror Modifier breaks Automatic-Weights in weight-paint mode
The problem was it used copied verts on the opposite side.
This commit is contained in:
parent
94f35ecf1b
commit
5e3b63a22b
@ -651,6 +651,7 @@ void vDM_ColorBand_store(const struct ColorBand *coba, const char alert_color[4]
|
||||
* In use now by vertex/weight paint and particles */
|
||||
DMCoNo *mesh_get_mapped_verts_nors(struct Scene *scene, struct Object *ob);
|
||||
#endif
|
||||
void mesh_get_mapped_verts_coords(DerivedMesh *dm, float (*r_cos)[3], const int totcos);
|
||||
|
||||
/* */
|
||||
DerivedMesh *mesh_get_derived_final(struct Scene *scene, struct Object *ob,
|
||||
|
@ -44,6 +44,7 @@
|
||||
#include "DNA_scene_types.h"
|
||||
|
||||
#include "BLI_blenlib.h"
|
||||
#include "BLI_bitmap.h"
|
||||
#include "BLI_math.h"
|
||||
#include "BLI_utildefines.h"
|
||||
#include "BLI_linklist.h"
|
||||
@ -2580,6 +2581,46 @@ DMCoNo *mesh_get_mapped_verts_nors(Scene *scene, Object *ob)
|
||||
|
||||
#endif
|
||||
|
||||
/* same as above but for vert coords */
|
||||
typedef struct {
|
||||
float (*vertexcos)[3];
|
||||
BLI_bitmap *vertex_visit;
|
||||
} MappedUserData;
|
||||
|
||||
static void make_vertexcos__mapFunc(void *userData, int index, const float co[3],
|
||||
const float UNUSED(no_f[3]), const short UNUSED(no_s[3]))
|
||||
{
|
||||
MappedUserData *mappedData = (MappedUserData *)userData;
|
||||
|
||||
if (BLI_BITMAP_TEST(mappedData->vertex_visit, index) == 0) {
|
||||
/* we need coord from prototype vertex, not from copies,
|
||||
* assume they stored in the beginning of vertex array stored in DM
|
||||
* (mirror modifier for eg does this) */
|
||||
copy_v3_v3(mappedData->vertexcos[index], co);
|
||||
BLI_BITMAP_ENABLE(mappedData->vertex_visit, index);
|
||||
}
|
||||
}
|
||||
|
||||
void mesh_get_mapped_verts_coords(DerivedMesh *dm, float (*r_cos)[3], const int totcos)
|
||||
{
|
||||
float (*vertexcos)[3];
|
||||
|
||||
if (dm->foreachMappedVert) {
|
||||
MappedUserData userData;
|
||||
memset(r_cos, 0, sizeof(r_cos) * totcos);
|
||||
userData.vertexcos = r_cos;
|
||||
userData.vertex_visit = BLI_BITMAP_NEW(totcos, "vertexcos flags");
|
||||
dm->foreachMappedVert(dm, make_vertexcos__mapFunc, &userData, DM_FOREACH_NOP);
|
||||
MEM_freeN(userData.vertex_visit);
|
||||
}
|
||||
else {
|
||||
int i;
|
||||
for (i = 0; i < totcos; i++) {
|
||||
dm->getVertCo(dm, i, vertexcos[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ******************* GLSL ******************** */
|
||||
|
||||
typedef struct {
|
||||
|
@ -40,7 +40,6 @@
|
||||
|
||||
#include "BLI_utildefines.h"
|
||||
#include "BLI_math.h"
|
||||
#include "BLI_bitmap.h"
|
||||
|
||||
#include "BKE_crazyspace.h"
|
||||
#include "BKE_DerivedMesh.h"
|
||||
@ -49,11 +48,6 @@
|
||||
#include "BKE_mesh.h"
|
||||
#include "BKE_editmesh.h"
|
||||
|
||||
typedef struct {
|
||||
float (*vertexcos)[3];
|
||||
BLI_bitmap *vertex_visit;
|
||||
} MappedUserData;
|
||||
|
||||
BLI_INLINE void tan_calc_quat_v3(
|
||||
float r_quat[4],
|
||||
const float co_1[3], const float co_2[3], const float co_3[3])
|
||||
@ -88,20 +82,6 @@ static void set_crazy_vertex_quat(
|
||||
sub_qt_qtqt(r_quat, q2, q1);
|
||||
}
|
||||
|
||||
static void make_vertexcos__mapFunc(void *userData, int index, const float co[3],
|
||||
const float UNUSED(no_f[3]), const short UNUSED(no_s[3]))
|
||||
{
|
||||
MappedUserData *mappedData = (MappedUserData *)userData;
|
||||
|
||||
if (BLI_BITMAP_TEST(mappedData->vertex_visit, index) == 0) {
|
||||
/* we need coord from prototype vertex, not from copies,
|
||||
* assume they stored in the beginning of vertex array stored in DM
|
||||
* (mirror modifier for eg does this) */
|
||||
copy_v3_v3(mappedData->vertexcos[index], co);
|
||||
BLI_BITMAP_ENABLE(mappedData->vertex_visit, index);
|
||||
}
|
||||
}
|
||||
|
||||
static int modifiers_disable_subsurf_temporary(Object *ob)
|
||||
{
|
||||
ModifierData *md;
|
||||
@ -124,8 +104,6 @@ float (*BKE_crazyspace_get_mapped_editverts(Scene *scene, Object *obedit))[3]
|
||||
DerivedMesh *dm;
|
||||
float (*vertexcos)[3];
|
||||
int nverts = me->edit_btmesh->bm->totvert;
|
||||
BLI_bitmap *vertex_visit;
|
||||
MappedUserData userData;
|
||||
|
||||
/* disable subsurf temporal, get mapped cos, and enable it */
|
||||
if (modifiers_disable_subsurf_temporary(obedit)) {
|
||||
@ -134,22 +112,17 @@ float (*BKE_crazyspace_get_mapped_editverts(Scene *scene, Object *obedit))[3]
|
||||
}
|
||||
|
||||
/* now get the cage */
|
||||
vertexcos = MEM_mallocN(sizeof(*vertexcos) * nverts, "vertexcos map");
|
||||
|
||||
dm = editbmesh_get_derived_cage(scene, obedit, me->edit_btmesh, CD_MASK_BAREMESH);
|
||||
|
||||
vertexcos = MEM_callocN(sizeof(*vertexcos) * nverts, "vertexcos map");
|
||||
vertex_visit = BLI_BITMAP_NEW(nverts, "vertexcos flags");
|
||||
|
||||
userData.vertexcos = vertexcos;
|
||||
userData.vertex_visit = vertex_visit;
|
||||
dm->foreachMappedVert(dm, make_vertexcos__mapFunc, &userData, DM_FOREACH_NOP);
|
||||
mesh_get_mapped_verts_coords(dm, vertexcos, nverts);
|
||||
|
||||
dm->release(dm);
|
||||
|
||||
/* set back the flag, no new cage needs to be built, transform does it */
|
||||
modifiers_disable_subsurf_temporary(obedit);
|
||||
|
||||
MEM_freeN(vertex_visit);
|
||||
|
||||
return vertexcos;
|
||||
}
|
||||
|
||||
|
@ -180,15 +180,6 @@ static int dgroup_skinnable_cb(Object *ob, Bone *bone, void *datap)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void add_vgroups__mapFunc(void *userData, int index, const float co[3],
|
||||
const float UNUSED(no_f[3]), const short UNUSED(no_s[3]))
|
||||
{
|
||||
/* DerivedMesh mapFunc for getting final coords in weight paint mode */
|
||||
|
||||
float (*verts)[3] = userData;
|
||||
copy_v3_v3(verts[index], co);
|
||||
}
|
||||
|
||||
static void envelope_bone_weighting(Object *ob, Mesh *mesh, float (*verts)[3], int numbones, Bone **bonelist,
|
||||
bDeformGroup **dgrouplist, bDeformGroup **dgroupflip,
|
||||
float (*root)[3], float (*tip)[3], const int *selected, float scale)
|
||||
@ -374,7 +365,7 @@ static void add_verts_to_dgroups(ReportList *reports, Scene *scene, Object *ob,
|
||||
DerivedMesh *dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH);
|
||||
|
||||
if (dm->foreachMappedVert) {
|
||||
dm->foreachMappedVert(dm, add_vgroups__mapFunc, (void *)verts, DM_FOREACH_NOP);
|
||||
mesh_get_mapped_verts_coords(dm, verts, mesh->totvert);
|
||||
vertsfilled = 1;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user