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.
This commit is contained in:
parent
dc92c5766f
commit
71b660571a
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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++) {
|
||||
|
|
Loading…
Reference in New Issue