Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Eagar <joeedh@gmail.com>2022-06-29 08:30:28 +0300
committerThomas Dinges <blender@dingto.org>2022-06-29 10:15:44 +0300
commite4df7fcf76307537a14706fac7efadc2f9a14347 (patch)
treefd1d34a24004979aa00abce48a1075c7d33f8511
parent0ff60d75cf05baa583035122890f9486f2917071 (diff)
Fix T99209: Remesh modifier frees sculpt masking attributes.
-rw-r--r--source/blender/blenkernel/BKE_paint.h2
-rw-r--r--source/blender/blenkernel/intern/DerivedMesh.cc2
-rw-r--r--source/blender/blenkernel/intern/paint.c37
3 files changed, 34 insertions, 7 deletions
diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h
index 0e976f04dd1..0f96c5d1ab8 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -676,7 +676,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 a31c1362935..e4a20582621 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.cc
+++ b/source/blender/blenkernel/intern/DerivedMesh.cc
@@ -1786,7 +1786,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 0f523d87d9b..322e7deb86a 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -1795,22 +1795,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;
@@ -1825,6 +1842,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)