[Bf-blender-cvs] [eaec01cad57] master: Sculpt: Fix backwards normals in PBVH_GRIDS raycasting

Joseph Eagar noreply at git.blender.org
Wed Jun 29 07:30:43 CEST 2022


Commit: eaec01cad573a240fe1dc99bbe4463c46e311508
Author: Joseph Eagar
Date:   Tue Jun 28 22:30:28 2022 -0700
Branches: master
https://developer.blender.org/rBeaec01cad573a240fe1dc99bbe4463c46e311508

Sculpt: Fix backwards normals in PBVH_GRIDS raycasting

Winding order of grid quads was backwards.

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

M	source/blender/blenkernel/BKE_paint.h
M	source/blender/blenkernel/intern/DerivedMesh.cc
M	source/blender/blenkernel/intern/paint.c

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

diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h
index 93a5e0a4072..a2d93f5ede2 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -680,7 +680,7 @@ void BKE_sculpt_update_object_for_edit(struct Depsgraph *depsgraph,
                                        bool need_pmap,
                                        bool need_mask,
                                        bool need_colors);
-void BKE_sculpt_update_object_before_eval(struct Object *ob_eval);
+void BKE_sculpt_update_object_before_eval(const struct Scene *scene, struct Object *ob_eval);
 void BKE_sculpt_update_object_after_eval(struct Depsgraph *depsgraph, struct Object *ob_eval);
 
 /**
diff --git a/source/blender/blenkernel/intern/DerivedMesh.cc b/source/blender/blenkernel/intern/DerivedMesh.cc
index b3a9d894944..ffac89c15e6 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.cc
+++ b/source/blender/blenkernel/intern/DerivedMesh.cc
@@ -1771,7 +1771,7 @@ void makeDerivedMesh(struct Depsgraph *depsgraph,
 
   BKE_object_free_derived_caches(ob);
   if (DEG_is_active(depsgraph)) {
-    BKE_sculpt_update_object_before_eval(ob);
+    BKE_sculpt_update_object_before_eval(scene, ob);
   }
 
   /* NOTE: Access the `edit_mesh` after freeing the derived caches, so that `ob->data` is restored
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index 8c91ea2b369..9b72b939f77 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -1798,22 +1798,39 @@ static void sculpt_update_object(Depsgraph *depsgraph,
   }
 }
 
-void BKE_sculpt_update_object_before_eval(Object *ob)
+static void sculpt_face_sets_ensure(Mesh *mesh)
+{
+  if (CustomData_has_layer(&mesh->pdata, CD_SCULPT_FACE_SETS)) {
+    return;
+  }
+
+  int *new_face_sets = CustomData_add_layer(
+      &mesh->pdata, CD_SCULPT_FACE_SETS, CD_CALLOC, NULL, mesh->totpoly);
+
+  /* Initialize the new Face Set data-layer with a default valid visible ID and set the default
+   * color to render it white. */
+  for (int i = 0; i < mesh->totpoly; i++) {
+    new_face_sets[i] = 1;
+  }
+  mesh->face_sets_color_default = 1;
+}
+
+void BKE_sculpt_update_object_before_eval(const Scene *scene, Object *ob_eval)
 {
   /* Update before mesh evaluation in the dependency graph. */
-  SculptSession *ss = ob->sculpt;
+  SculptSession *ss = ob_eval->sculpt;
 
   if (ss && ss->building_vp_handle == false) {
     if (!ss->cache && !ss->filter_cache && !ss->expand_cache) {
       /* We free pbvh on changes, except in the middle of drawing a stroke
        * since it can't deal with changing PVBH node organization, we hope
        * topology does not change in the meantime .. weak. */
-      sculptsession_free_pbvh(ob);
+      sculptsession_free_pbvh(ob_eval);
 
-      BKE_sculptsession_free_deformMats(ob->sculpt);
+      BKE_sculptsession_free_deformMats(ob_eval->sculpt);
 
       /* In vertex/weight paint, force maps to be rebuilt. */
-      BKE_sculptsession_free_vwpaint_data(ob->sculpt);
+      BKE_sculptsession_free_vwpaint_data(ob_eval->sculpt);
     }
     else {
       PBVHNode **nodes;
@@ -1828,6 +1845,16 @@ void BKE_sculpt_update_object_before_eval(Object *ob)
       MEM_freeN(nodes);
     }
   }
+
+  if (ss) {
+    Object *ob_orig = DEG_get_original_object(ob_eval);
+    Mesh *mesh = BKE_object_get_original_mesh(ob_orig);
+    MultiresModifierData *mmd = BKE_sculpt_multires_active(scene, ob_orig);
+
+    /* Ensure attribute layout is still correct. */
+    sculpt_face_sets_ensure(mesh);
+    BKE_sculpt_mask_layers_ensure(ob_orig, mmd);
+  }
 }
 
 void BKE_sculpt_update_object_after_eval(Depsgraph *depsgraph, Object *ob_eval)



More information about the Bf-blender-cvs mailing list