[Bf-blender-cvs] [a0296bfe0ad] temp-angavrilov: Weight Paint: use coordinates from normal evaluated mesh if same topology.

Alexander Gavrilov noreply at git.blender.org
Sun Jul 17 09:29:35 CEST 2022


Commit: a0296bfe0ad56219a221a5375f99a5b53a57339a
Author: Alexander Gavrilov
Date:   Sun Jul 17 10:27:57 2022 +0300
Branches: temp-angavrilov
https://developer.blender.org/rBa0296bfe0ad56219a221a5375f99a5b53a57339a

Weight Paint: use coordinates from normal evaluated mesh if same topology.

Weight and Vertex paint don't change coordinates and thus don't need
crazyspace data, which allows using coordinates from normal evaluated
meshes.

Since painting uses original topology, the deform only mesh is used,
but if the fully evaluated mesh has the same topology, it is preferred.
This is useful because not only Geometry Nodes, but even simple weight
computation modifiers are excluded from the deform only mesh evaluation.

===================================================================

M	source/blender/blenkernel/intern/paint.c

===================================================================

diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index 9b0d15ac702..22da5b472e5 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -1616,6 +1616,7 @@ static bool sculpt_modifiers_active(Scene *scene, Sculpt *sd, Object *ob)
  */
 static void sculpt_update_object(Depsgraph *depsgraph,
                                  Object *ob,
+                                 Object *ob_eval,
                                  Mesh *me_eval,
                                  bool need_pmap,
                                  bool need_mask,
@@ -1733,7 +1734,26 @@ static void sculpt_update_object(Depsgraph *depsgraph,
   pbvh_show_face_sets_set(ss->pbvh, ss->show_face_sets);
 
   if (ss->deform_modifiers_active) {
-    if (!ss->orig_cos) {
+    /* Painting doesn't need crazyspace, use already evaluated mesh coordinates. */
+    if (ob->mode & (OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT)) {
+      Mesh *me_eval_deform = ob_eval->runtime.mesh_deform_eval;
+
+      /* If the fully evaluated mesh has the same topology as the deform-only version, use it.
+       * This matters because 'deform eval' is very restrictive and excludes even modifiers that
+       * simply recompute vertex weights. */
+      if (me_eval_deform->mpoly == me_eval->mpoly && me_eval_deform->mloop == me_eval->mloop &&
+          me_eval_deform->totvert == me_eval->totvert) {
+        me_eval_deform = me_eval;
+      }
+
+      BKE_sculptsession_free_deformMats(ss);
+
+      BLI_assert(me_eval_deform->totvert == me->totvert);
+
+      ss->deform_cos = BKE_mesh_vert_coords_alloc(me_eval_deform, NULL);
+      BKE_pbvh_vert_coords_apply(ss->pbvh, ss->deform_cos, me->totvert);
+    }
+    else if (!ss->orig_cos) {
       int a;
 
       BKE_sculptsession_free_deformMats(ss);
@@ -1874,7 +1894,7 @@ void BKE_sculpt_update_object_after_eval(Depsgraph *depsgraph, Object *ob_eval)
   Mesh *me_eval = BKE_object_get_evaluated_mesh(ob_eval);
 
   BLI_assert(me_eval != NULL);
-  sculpt_update_object(depsgraph, ob_orig, me_eval, false, false, false);
+  sculpt_update_object(depsgraph, ob_orig, ob_eval, me_eval, false, false, false);
 }
 
 void BKE_sculpt_color_layer_create_if_needed(struct Object *object)
@@ -1920,7 +1940,7 @@ void BKE_sculpt_update_object_for_edit(
   Mesh *me_eval = BKE_object_get_evaluated_mesh(ob_eval);
   BLI_assert(me_eval != NULL);
 
-  sculpt_update_object(depsgraph, ob_orig, me_eval, need_pmap, need_mask, is_paint_tool);
+  sculpt_update_object(depsgraph, ob_orig, ob_eval, me_eval, need_pmap, need_mask, is_paint_tool);
 }
 
 int BKE_sculpt_mask_layers_ensure(Object *ob, MultiresModifierData *mmd)



More information about the Bf-blender-cvs mailing list