[Bf-blender-cvs] [71b660571a1] master: Sculpt: Avoid creating mask and face set when remeshing

Hans Goudey noreply at git.blender.org
Tue Aug 30 00:00:53 CEST 2022


Commit: 71b660571a1fe832a81eae71ed571083c3110de3
Author: Hans Goudey
Date:   Mon Aug 29 16:55:26 2022 -0500
Branches: master
https://developer.blender.org/rB71b660571a1fe832a81eae71ed571083c3110de3

Sculpt: Avoid creating mask and face set when remeshing

If these layers didn't exist on the original mesh, they would be created
from scratch and transferred anyway. That is inefficient because all the
work is pointless, and because creating these layers could slow down
subsequent sculpt operations.

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

M	source/blender/blenkernel/BKE_mesh_remesh_voxel.h
M	source/blender/blenkernel/intern/mesh_remesh_voxel.cc

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

diff --git a/source/blender/blenkernel/BKE_mesh_remesh_voxel.h b/source/blender/blenkernel/BKE_mesh_remesh_voxel.h
index dff17bd6575..d9f5a75ca61 100644
--- a/source/blender/blenkernel/BKE_mesh_remesh_voxel.h
+++ b/source/blender/blenkernel/BKE_mesh_remesh_voxel.h
@@ -28,9 +28,9 @@ struct Mesh *BKE_mesh_remesh_quadriflow(const struct Mesh *mesh,
                                         void *update_cb_data);
 
 /* Data reprojection functions */
-void BKE_mesh_remesh_reproject_paint_mask(struct Mesh *target, struct Mesh *source);
+void BKE_mesh_remesh_reproject_paint_mask(struct Mesh *target, const struct Mesh *source);
 void BKE_remesh_reproject_vertex_paint(struct Mesh *target, const struct Mesh *source);
-void BKE_remesh_reproject_sculpt_face_sets(struct Mesh *target, struct Mesh *source);
+void BKE_remesh_reproject_sculpt_face_sets(struct Mesh *target, const struct Mesh *source);
 
 #ifdef __cplusplus
 }
diff --git a/source/blender/blenkernel/intern/mesh_remesh_voxel.cc b/source/blender/blenkernel/intern/mesh_remesh_voxel.cc
index 85aed01ce52..423f76407a0 100644
--- a/source/blender/blenkernel/intern/mesh_remesh_voxel.cc
+++ b/source/blender/blenkernel/intern/mesh_remesh_voxel.cc
@@ -275,11 +275,15 @@ Mesh *BKE_mesh_remesh_voxel(const Mesh *mesh,
 #endif
 }
 
-void BKE_mesh_remesh_reproject_paint_mask(Mesh *target, Mesh *source)
+void BKE_mesh_remesh_reproject_paint_mask(Mesh *target, const Mesh *source)
 {
   BVHTreeFromMesh bvhtree = {nullptr};
   BKE_bvhtree_from_mesh_get(&bvhtree, source, BVHTREE_FROM_VERTS, 2);
-  MVert *target_verts = (MVert *)CustomData_get_layer(&target->vdata, CD_MVERT);
+  const MVert *target_verts = (const MVert *)CustomData_get_layer(&target->vdata, CD_MVERT);
+  const float *source_mask = (const float *)CustomData_get_layer(&source->vdata, CD_PAINT_MASK);
+  if (source_mask == nullptr) {
+    return;
+  }
 
   float *target_mask;
   if (CustomData_has_layer(&target->vdata, CD_PAINT_MASK)) {
@@ -290,15 +294,6 @@ void BKE_mesh_remesh_reproject_paint_mask(Mesh *target, Mesh *source)
         &target->vdata, CD_PAINT_MASK, CD_CALLOC, nullptr, target->totvert);
   }
 
-  const float *source_mask;
-  if (CustomData_has_layer(&source->vdata, CD_PAINT_MASK)) {
-    source_mask = (float *)CustomData_get_layer(&source->vdata, CD_PAINT_MASK);
-  }
-  else {
-    source_mask = (float *)CustomData_add_layer(
-        &source->vdata, CD_PAINT_MASK, CD_CALLOC, nullptr, source->totvert);
-  }
-
   for (int i = 0; i < target->totvert; i++) {
     float from_co[3];
     BVHTreeNearest nearest;
@@ -313,13 +308,16 @@ void BKE_mesh_remesh_reproject_paint_mask(Mesh *target, Mesh *source)
   free_bvhtree_from_mesh(&bvhtree);
 }
 
-void BKE_remesh_reproject_sculpt_face_sets(Mesh *target, Mesh *source)
+void BKE_remesh_reproject_sculpt_face_sets(Mesh *target, const Mesh *source)
 {
-  BVHTreeFromMesh bvhtree = {nullptr};
-
   const MPoly *target_polys = (const MPoly *)CustomData_get_layer(&target->pdata, CD_MPOLY);
   const MVert *target_verts = (const MVert *)CustomData_get_layer(&target->vdata, CD_MVERT);
   const MLoop *target_loops = (const MLoop *)CustomData_get_layer(&target->ldata, CD_MLOOP);
+  const int *source_face_sets = (const int *)CustomData_get_layer(&source->pdata,
+                                                                  CD_SCULPT_FACE_SETS);
+  if (source_face_sets == nullptr) {
+    return;
+  }
 
   int *target_face_sets;
   if (CustomData_has_layer(&target->pdata, CD_SCULPT_FACE_SETS)) {
@@ -330,16 +328,8 @@ void BKE_remesh_reproject_sculpt_face_sets(Mesh *target, Mesh *source)
         &target->pdata, CD_SCULPT_FACE_SETS, CD_CALLOC, nullptr, target->totpoly);
   }
 
-  const int *source_face_sets;
-  if (CustomData_has_layer(&source->pdata, CD_SCULPT_FACE_SETS)) {
-    source_face_sets = (const int *)CustomData_get_layer(&source->pdata, CD_SCULPT_FACE_SETS);
-  }
-  else {
-    source_face_sets = (const int *)CustomData_add_layer(
-        &source->pdata, CD_SCULPT_FACE_SETS, CD_CALLOC, nullptr, source->totpoly);
-  }
-
   const MLoopTri *looptri = BKE_mesh_runtime_looptri_ensure(source);
+  BVHTreeFromMesh bvhtree = {nullptr};
   BKE_bvhtree_from_mesh_get(&bvhtree, source, BVHTREE_FROM_LOOPTRI, 2);
 
   for (int i = 0; i < target->totpoly; i++) {



More information about the Bf-blender-cvs mailing list