[Bf-blender-cvs] [d3faf09082d] sculpt-dev: Merge branch 'master' into sculpt-dev
Pablo Dobarro
noreply at git.blender.org
Fri Aug 6 17:33:46 CEST 2021
Commit: d3faf09082d7d763b3b9259428f35e0d127cc339
Author: Pablo Dobarro
Date: Sat Jul 31 17:16:02 2021 +0200
Branches: sculpt-dev
https://developer.blender.org/rBd3faf09082d7d763b3b9259428f35e0d127cc339
Merge branch 'master' into sculpt-dev
===================================================================
===================================================================
diff --cc source/blender/blenkernel/BKE_mesh_remesh_voxel.h
index b7feb402c73,5887db59ff2..a12c37ad46e
--- a/source/blender/blenkernel/BKE_mesh_remesh_voxel.h
+++ b/source/blender/blenkernel/BKE_mesh_remesh_voxel.h
@@@ -59,10 -49,8 +49,10 @@@ struct Mesh *BKE_mesh_remesh_quadriflow
/* Data reprojection functions */
void BKE_mesh_remesh_reproject_paint_mask(struct Mesh *target, struct Mesh *source);
- void BKE_remesh_reproject_vertex_paint(struct Mesh *target, 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_materials(struct Mesh *target, struct Mesh *source);
+void BKE_mesh_remesh_sculpt_array_update(struct Object *ob, struct Mesh *target, struct Mesh *source);
#ifdef __cplusplus
}
diff --cc source/blender/blenkernel/intern/mesh_remesh_voxel.cc
index a713c47aa25,1ac6ec1b9c1..db455aa07f0
--- a/source/blender/blenkernel/intern/mesh_remesh_voxel.cc
+++ b/source/blender/blenkernel/intern/mesh_remesh_voxel.cc
@@@ -30,13 -30,12 +30,13 @@@
#include "MEM_guardedalloc.h"
- #include "BLI_blenlib.h"
- #include "BLI_math.h"
- #include "BLI_utildefines.h"
+ #include "BLI_array.hh"
+ #include "BLI_float3.hh"
+ #include "BLI_index_range.hh"
++#include "DNA_object_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
- #include "DNA_object_types.h"
#include "BKE_bvhutils.h"
#include "BKE_customdata.h"
@@@ -353,88 -340,13 +342,86 @@@ void BKE_mesh_remesh_reproject_paint_ma
free_bvhtree_from_mesh(&bvhtree);
}
+void BKE_mesh_remesh_sculpt_array_update(Object *ob, Mesh *target, Mesh *source)
+{
+
+ SculptSession *ss = ob->sculpt;
+
+ if (!ss) {
+ return;
+ }
+
+ SculptArray *array = ss->array;
+ if (!array) {
+ return;
+ }
+
+ BVHTreeFromMesh bvhtree = {
+ .nearest_callback = NULL,
+ };
+ BKE_bvhtree_from_mesh_get(&bvhtree, source, BVHTREE_FROM_VERTS, 2);
- MVert *target_verts = CustomData_get_layer(&target->vdata, CD_MVERT);
++ MVert *target_verts = (MVert *)CustomData_get_layer(&target->vdata, CD_MVERT);
+
+ const int target_totvert = target->totvert;
+
- int *target_copy_index = MEM_malloc_arrayN(sizeof(int), target_totvert, "target_copy_index");
- int *target_symmertry = MEM_malloc_arrayN(sizeof(int), target_totvert, "target_copy_index");
- float (*target_orco)[3] = MEM_malloc_arrayN(target->totvert, sizeof(float) * 3, "array orco");
++ int *target_copy_index = (int *)MEM_malloc_arrayN(sizeof(int), target_totvert, "target_copy_index");
++ int *target_symmertry = (int *)MEM_malloc_arrayN(sizeof(int), target_totvert, "target_copy_index");
++ float (*target_orco)[3] = (float (*)[3])MEM_malloc_arrayN(target->totvert, sizeof(float) * 3, "array orco");
+
+ for (int i = 0; i < target_totvert; i++) {
+ target_copy_index[i] = -1;
+ target_symmertry[i] = 0;
- copy_v3_v3(target_orco, target->mvert[i].co);
++ copy_v3_v3(target_orco[i], target->mvert[i].co);
+ }
+
+ for (int i = 0; i < target->totvert; i++) {
+ float from_co[3];
+ BVHTreeNearest nearest;
+ nearest.index = -1;
+ nearest.dist_sq = FLT_MAX;
+ copy_v3_v3(from_co, target_verts[i].co);
+ BLI_bvhtree_find_nearest(bvhtree.tree, from_co, &nearest, bvhtree.nearest_callback, &bvhtree);
+ if (nearest.index != -1) {
+ target_copy_index[i] = array->copy_index[nearest.index];
+ target_symmertry[i] = array->symmetry_pass[nearest.index];
+ }
+ }
+ free_bvhtree_from_mesh(&bvhtree);
+
+ MEM_freeN(array->copy_index);
+ MEM_freeN(array->symmetry_pass);
+ MEM_freeN(array->orco);
+
+ array->copy_index = target_copy_index;
+ array->symmetry_pass = target_symmertry;
+ array->orco = target_orco;
+
+ for (int i = 0; i < target->totvert; i++) {
+ int array_index = target_copy_index[i];
+ int array_symm_pass = target_symmertry[i];
+ if (array_index == -1) {
+ continue;
+ }
+ SculptArrayCopy *copy = &array->copies[array_symm_pass][array_index];
+ float co[3];
+ float source_origin_symm[3];
+ copy_v3_v3(co, target->mvert[i].co);
+ /* TODO: MAke symmetry work here. */
+ //flip_v3_v3(source_origin_symm, array->source_origin, array_symm_pass);
+ mul_v3_m4v3(co, array->source_imat, co);
+ mul_v3_m4v3(co, copy->imat, co);
+ sub_v3_v3v3(co, co, source_origin_symm);
+ copy_v3_v3(array->orco[i], co);
+ }
+}
+
void BKE_remesh_reproject_sculpt_face_sets(Mesh *target, Mesh *source)
{
- BVHTreeFromMesh bvhtree = {
- .nearest_callback = NULL,
- };
+ BVHTreeFromMesh bvhtree = {{nullptr}};
- const MPoly *target_polys = CustomData_get_layer(&target->pdata, CD_MPOLY);
- const MVert *target_verts = CustomData_get_layer(&target->vdata, CD_MVERT);
- const MLoop *target_loops = CustomData_get_layer(&target->ldata, CD_MLOOP);
+ 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);
int *target_face_sets;
if (CustomData_has_layer(&target->pdata, CD_SCULPT_FACE_SETS)) {
@@@ -475,39 -387,9 +462,37 @@@
free_bvhtree_from_mesh(&bvhtree);
}
+void BKE_remesh_reproject_materials(Mesh *target, Mesh *source)
+{
+ BVHTreeFromMesh bvhtree = {
+ .nearest_callback = NULL,
+ };
+
- const MPoly *target_polys = CustomData_get_layer(&target->pdata, CD_MPOLY);
- const MVert *target_verts = CustomData_get_layer(&target->vdata, CD_MVERT);
- const MLoop *target_loops = CustomData_get_layer(&target->ldata, CD_MLOOP);
++ const MPoly *target_polys = (MPoly *)CustomData_get_layer(&target->pdata, CD_MPOLY);
++ const MVert *target_verts = (MVert *)CustomData_get_layer(&target->vdata, CD_MVERT);
++ const MLoop *target_loops = (MLoop *)CustomData_get_layer(&target->ldata, CD_MLOOP);
+
+ const MLoopTri *looptri = BKE_mesh_runtime_looptri_ensure(source);
+ BKE_bvhtree_from_mesh_get(&bvhtree, source, BVHTREE_FROM_LOOPTRI, 2);
+
+ for (int i = 0; i < target->totpoly; i++) {
+ float from_co[3];
+ BVHTreeNearest nearest;
+ nearest.index = -1;
+ nearest.dist_sq = FLT_MAX;
+ const MPoly *mpoly = &target_polys[i];
+ BKE_mesh_calc_poly_center(mpoly, &target_loops[mpoly->loopstart], target_verts, from_co);
+ BLI_bvhtree_find_nearest(bvhtree.tree, from_co, &nearest, bvhtree.nearest_callback, &bvhtree);
+ if (nearest.index != -1) {
+ target->mpoly[i].mat_nr = source->mpoly[looptri[nearest.index].poly].mat_nr;
+ }
+ }
+ free_bvhtree_from_mesh(&bvhtree);
+}
+
- void BKE_remesh_reproject_vertex_paint(Mesh *target, Mesh *source)
+ void BKE_remesh_reproject_vertex_paint(Mesh *target, const Mesh *source)
{
- BVHTreeFromMesh bvhtree = {
- .nearest_callback = NULL,
- };
+ BVHTreeFromMesh bvhtree = {{nullptr}};
BKE_bvhtree_from_mesh_get(&bvhtree, source, BVHTREE_FROM_VERTS, 2);
int tot_color_layer = CustomData_number_of_layers(&source->vdata, CD_PROP_COLOR);
More information about the Bf-blender-cvs
mailing list