Page MenuHome

2.8 Weight Painting Bug
Closed, ResolvedPublic

Description

System Information
Operating system: Windows 10
Graphics card: GTX 970

**2.8 Beta, baf599610a4*

The Bug: When weight painting an object that is currently rigged to an armature, the brushes affect the vertexes that would be under the brush if there were no armature instead of the vertexes that are actually there.

For example: Say you have a character model that was modeled in a T-Pose. The model is currently rigged to an armature that has the character holding his arms in front of his chest. If you were to enter weight painting with the character in pose, and you were to try to paint on the characters arms, Blender would instead paint on the characters chest, because the weight painting is affecting the vertexes that would be under the brush if the character had no armature modifier. To weight paint the character's arms, you would have to paint the empty area where the arms were before the pose.

Steps to recreate the bug:

Step 1) Open Blender 2.8. Add the subdivision surface modifier to the default cube, add several subdivision levels and then apply. (Just so you have enough detail to test armatures and weight painting with.)

Step 2) Add an armature to the scene. Enter Pose Mode and move the single bone a small distance away from the cube. Switch back to Object Mode.

Step 3) Reselect the cube and add an armature modifier. Set the cube's "object" setting to the armature.

Step 4) Enter Weight Paint mode on the cube. Paint a little bit and the section you're painting should snap to the bone.

Step 5) Turn your view so that the painted vertexes are not in front of the rest of the cube. Try to paint the vertex group back down to zero, and it won't work, because you're painting an area that only has vertexes when an armature is attached. Blender thinks you're painting onto nothing.

Step 6) Now try erasing the area where the vertexes originally were. This will work, the vertexes will snap back to their original position, even though you were drawing onto where they were, rather than where they are.

Step 7) Repaint those vertexes, and then position your view so that a non-painted area is behind the painted area. Try painting the painted area, and you'll find that the non-painted area is what's affected, instead of the painted area. This happens because Blender is painting what used to be there (the non-painted area) rather than what is actually there (the painted area).

Event Timeline

Jacques Lucke (JacquesLucke) triaged this task as Incomplete priority.Wed, Dec 5, 12:08 PM

Could you provide a .blend file please. That would make it easier and less time consuming for us to reproduce the bug. Thank you :)

Jacques Lucke (JacquesLucke) raised the priority of this task from Incomplete to Confirmed.EditedWed, Dec 5, 12:59 PM

What's interesting is that it works when instead of the Armature modifier, a Displace modifier is used to deform the geometry.

Doesn't seem to be related on bbones, but more like on what object to use to calculate matricies. Think this is to be calculated for an evaluated object, which has all animation and drivers evaluated, together with all other runtime data which is needed for modifiers.

Wouldn't mind having a second thought here, @Brecht Van Lommel (brecht)? :)

1diff --git a/source/blender/blenkernel/intern/crazyspace.c b/source/blender/blenkernel/intern/crazyspace.c
2index 354cc4926f1..8062ac7a965 100644
3--- a/source/blender/blenkernel/intern/crazyspace.c
4+++ b/source/blender/blenkernel/intern/crazyspace.c
5@@ -50,6 +50,8 @@
6 #include "BKE_editmesh.h"
7 #include "BKE_library.h"
8
9+#include "DEG_depsgraph_query.h"
10+
11 BLI_INLINE void tan_calc_quat_v3(
12 float r_quat[4],
13 const float co_1[3], const float co_2[3], const float co_3[3])
14@@ -313,17 +315,18 @@ int BKE_crazyspace_get_first_deform_matrices_editbmesh(
15
16 int BKE_sculpt_get_first_deform_matrices(
17 struct Depsgraph *depsgraph, Scene *scene,
18- Object *ob, float (**deformmats)[3][3], float (**deformcos)[3])
19+ Object *object, float (**deformmats)[3][3], float (**deformcos)[3])
20 {
21 ModifierData *md;
22 Mesh *me_eval;
23 int a, numVerts = 0;
24 float (*defmats)[3][3] = NULL, (*deformedVerts)[3] = NULL;
25- MultiresModifierData *mmd = get_multires_modifier(scene, ob, 0);
26- const bool has_multires = mmd != NULL && mmd->sculptlvl > 0;
27 int numleft = 0;
28 VirtualModifierData virtualModifierData;
29- const ModifierEvalContext mectx = {depsgraph, ob, 0};
30+ Object *object_eval = DEG_get_evaluated_object(depsgraph, object);
31+ MultiresModifierData *mmd = get_multires_modifier(scene, object_eval, 0);
32+ const bool has_multires = mmd != NULL && mmd->sculptlvl > 0;
33+ const ModifierEvalContext mectx = {depsgraph, object_eval, 0};
34
35 if (has_multires) {
36 *deformmats = NULL;
37@@ -332,7 +335,7 @@ int BKE_sculpt_get_first_deform_matrices(
38 }
39
40 me_eval = NULL;
41- md = modifiers_getVirtualModifierList(ob, &virtualModifierData);
42+ md = modifiers_getVirtualModifierList(object_eval, &virtualModifierData);
43
44 for (; md; md = md->next) {
45 const ModifierTypeInfo *mti = modifierType_getInfo(md->type);
46@@ -341,7 +344,7 @@ int BKE_sculpt_get_first_deform_matrices(
47
48 if (mti->type == eModifierTypeType_OnlyDeform) {
49 if (!defmats) {
50- Mesh *me = ob->data;
51+ Mesh *me = object_eval->data;
52 me_eval = BKE_mesh_copy_for_eval(me, true);
53 deformedVerts = BKE_mesh_vertexCos_get(me, &numVerts);
54 defmats = MEM_callocN(sizeof(*defmats) * numVerts, "defmats");

This comment was removed by Sebastian Parborg (zeddb).

@Sergey Sharybin (sergey) that patch doesn't seem to solve the issue for me.

I still can't paint on the deformed verts.
I deleted my previous message too quickly. I did a quick and dirty fix by forcefully updating the bbone cache if it is missing


But this is not the way to go I suspect. It's better to figure out why the cache is missing in the first place I think.

However, if I debug the depsgraph, the cache should have been created as it reports that the armature object has run BKE_pose_eval_done. So I'm not sure why it is missing later...

Well, that's simple, one line changed :)

1diff --git a/source/blender/blenkernel/intern/crazyspace.c b/source/blender/blenkernel/intern/crazyspace.c
2index 354cc4926f1..a2c0d95e9b4 100644
3--- a/source/blender/blenkernel/intern/crazyspace.c
4+++ b/source/blender/blenkernel/intern/crazyspace.c
5@@ -50,6 +50,8 @@
6 #include "BKE_editmesh.h"
7 #include "BKE_library.h"
8
9+#include "DEG_depsgraph_query.h"
10+
11 BLI_INLINE void tan_calc_quat_v3(
12 float r_quat[4],
13 const float co_1[3], const float co_2[3], const float co_3[3])
14@@ -313,17 +315,18 @@ int BKE_crazyspace_get_first_deform_matrices_editbmesh(
15
16 int BKE_sculpt_get_first_deform_matrices(
17 struct Depsgraph *depsgraph, Scene *scene,
18- Object *ob, float (**deformmats)[3][3], float (**deformcos)[3])
19+ Object *object, float (**deformmats)[3][3], float (**deformcos)[3])
20 {
21 ModifierData *md;
22 Mesh *me_eval;
23 int a, numVerts = 0;
24 float (*defmats)[3][3] = NULL, (*deformedVerts)[3] = NULL;
25- MultiresModifierData *mmd = get_multires_modifier(scene, ob, 0);
26- const bool has_multires = mmd != NULL && mmd->sculptlvl > 0;
27 int numleft = 0;
28 VirtualModifierData virtualModifierData;
29- const ModifierEvalContext mectx = {depsgraph, ob, 0};
30+ Object *object_eval = DEG_get_evaluated_object(depsgraph, object);
31+ MultiresModifierData *mmd = get_multires_modifier(scene, object_eval, 0);
32+ const bool has_multires = mmd != NULL && mmd->sculptlvl > 0;
33+ const ModifierEvalContext mectx = {depsgraph, object_eval, 0};
34
35 if (has_multires) {
36 *deformmats = NULL;
37@@ -332,7 +335,7 @@ int BKE_sculpt_get_first_deform_matrices(
38 }
39
40 me_eval = NULL;
41- md = modifiers_getVirtualModifierList(ob, &virtualModifierData);
42+ md = modifiers_getVirtualModifierList(object_eval, &virtualModifierData);
43
44 for (; md; md = md->next) {
45 const ModifierTypeInfo *mti = modifierType_getInfo(md->type);
46@@ -341,7 +344,8 @@ int BKE_sculpt_get_first_deform_matrices(
47
48 if (mti->type == eModifierTypeType_OnlyDeform) {
49 if (!defmats) {
50- Mesh *me = ob->data;
51+ /* NOTE: Need to start with original undeformed mesh. */
52+ Mesh *me = object->data;
53 me_eval = BKE_mesh_copy_for_eval(me, true);
54 deformedVerts = BKE_mesh_vertexCos_get(me, &numVerts);
55 defmats = MEM_callocN(sizeof(*defmats) * numVerts, "defmats");

That solves the problem for me, thanks for the update.

It seems ok but incomplete, the code in BKE_crazyspace_build_sculpt() probably needs similar changes?

Just downloaded the newest patch and weight painting works again. Thank you all so much!