[Bf-blender-cvs] [73da0bdf64c] sculpt-mode-features: Voxel remesher: Reproject mask option
Pablo Dobarro
noreply at git.blender.org
Fri Apr 12 16:50:07 CEST 2019
Commit: 73da0bdf64ca94355d425fadd873aeec087160d9
Author: Pablo Dobarro
Date: Fri Apr 12 16:49:51 2019 +0200
Branches: sculpt-mode-features
https://developer.blender.org/rB73da0bdf64ca94355d425fadd873aeec087160d9
Voxel remesher: Reproject mask option
===================================================================
M release/scripts/startup/bl_ui/properties_data_mesh.py
M source/blender/blenkernel/BKE_remesh.h
M source/blender/blenkernel/intern/remesh_voxel.c
M source/blender/editors/object/object_edit.c
M source/blender/makesdna/DNA_mesh_types.h
M source/blender/makesrna/intern/rna_mesh.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/properties_data_mesh.py b/release/scripts/startup/bl_ui/properties_data_mesh.py
index bf2a1d00d20..8c9e46e7b7f 100644
--- a/release/scripts/startup/bl_ui/properties_data_mesh.py
+++ b/release/scripts/startup/bl_ui/properties_data_mesh.py
@@ -472,6 +472,7 @@ class DATA_PT_remesh(MeshButtonsPanel, Panel):
col.prop(mesh, "voxel_size")
col.prop(mesh, "smooth_normals")
col.prop(mesh, "reproject_vertex_paint")
+ col.prop(mesh, "reproject_paint_mask")
col.operator("object.remesh", text="Remesh")
diff --git a/source/blender/blenkernel/BKE_remesh.h b/source/blender/blenkernel/BKE_remesh.h
index d3ea0a1c928..a58e7baae9a 100644
--- a/source/blender/blenkernel/BKE_remesh.h
+++ b/source/blender/blenkernel/BKE_remesh.h
@@ -34,7 +34,9 @@ Mesh *BKE_remesh_voxel_ovdb_volume_to_mesh_nomain(struct OpenVDBLevelSet *level_
/* MVertCol based Reprojection for remesh operator */
void BKE_remesh_voxel_init_empty_vertex_color_layer(Mesh *mesh);
+void BKE_remesh_voxel_reproject(Mesh *target, Mesh *source, const int flag);
void BKE_remesh_voxel_reproject_vertex_paint(Mesh *target, Mesh *source);
+void BKE_remesh_voxel_reproject_paint_mask(Mesh *target, Mesh *source);
/* MLoopCol remapping based Reprojection for remesh modifier */
MLoopCol* BKE_remesh_remap_loop_vertex_color_layer(Mesh *mesh);
diff --git a/source/blender/blenkernel/intern/remesh_voxel.c b/source/blender/blenkernel/intern/remesh_voxel.c
index f79bb783238..479a6891a88 100644
--- a/source/blender/blenkernel/intern/remesh_voxel.c
+++ b/source/blender/blenkernel/intern/remesh_voxel.c
@@ -163,6 +163,89 @@ void BKE_remesh_voxel_reproject_vertex_paint(Mesh *target, Mesh *source)
free_bvhtree_from_mesh(&bvhtree);
}
+void BKE_remesh_voxel_reproject_paint_mask(Mesh *target, Mesh *source)
+{
+ BVHTreeFromMesh bvhtree = {NULL};
+ BKE_bvhtree_from_mesh_get(&bvhtree, source, BVHTREE_FROM_VERTS, 2);
+ MVert *target_verts = CustomData_get_layer(&target->vdata, CD_MVERT);
+
+ float *target_mask;
+ if (CustomData_has_layer(&target->vdata, CD_PAINT_MASK)) {
+ target_mask = CustomData_get_layer(&target->vdata, CD_PAINT_MASK);
+ }
+ else {
+ target_mask = CustomData_add_layer(&target->vdata, CD_PAINT_MASK, CD_CALLOC, NULL, target->totvert);
+ }
+
+ float *source_mask;
+ if (CustomData_has_layer(&source->vdata, CD_PAINT_MASK)) {
+ source_mask = CustomData_get_layer(&source->vdata, CD_PAINT_MASK);
+ }
+ else {
+ source_mask = CustomData_add_layer(&source->vdata, CD_PAINT_MASK, CD_CALLOC, NULL, source->totvert);
+ }
+
+ 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_mask[i] = source_mask[nearest.index];
+ }
+ }
+ free_bvhtree_from_mesh(&bvhtree);
+}
+
+void BKE_remesh_voxel_reproject(Mesh *target, Mesh *source, const int flag)
+{
+ BVHTreeFromMesh bvhtree = {NULL};
+ BKE_bvhtree_from_mesh_get(&bvhtree, source, BVHTREE_FROM_VERTS, 2);
+ MVert *target_verts = CustomData_get_layer(&target->vdata, CD_MVERT);
+
+ MVertCol *target_color = CustomData_get_layer(&target->vdata, CD_MVERTCOL);
+ MVertCol *source_color = CustomData_get_layer(&source->vdata, CD_MVERTCOL);
+
+ float *target_mask;
+ if (CustomData_has_layer(&target->vdata, CD_PAINT_MASK)) {
+ target_mask = CustomData_get_layer(&target->vdata, CD_PAINT_MASK);
+ }
+ else {
+ target_mask = CustomData_add_layer(&target->vdata, CD_PAINT_MASK, CD_CALLOC, NULL, target->totvert);
+ }
+
+ float *source_mask;
+ if (CustomData_has_layer(&source->vdata, CD_PAINT_MASK)) {
+ source_mask = CustomData_get_layer(&source->vdata, CD_PAINT_MASK);
+ }
+ else {
+ source_mask = CustomData_add_layer(&source->vdata, CD_PAINT_MASK, CD_CALLOC, NULL, source->totvert);
+ }
+
+ 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) {
+ if (flag & ME_REMESH_REPROJECT_VERTEX_PAINT) {
+ target_color[i].r = source_color[nearest.index].r;
+ target_color[i].g = source_color[nearest.index].g;
+ target_color[i].b = source_color[nearest.index].b;
+ target_color[i].a = source_color[nearest.index].a;
+ }
+ if (flag & ME_REMESH_REPROJECT_PAINT_MASK) {
+ target_mask[i] = source_mask[nearest.index];
+ }
+ }
+ }
+ free_bvhtree_from_mesh(&bvhtree);
+}
+
/*caller needs to free returned data */
MLoopCol* BKE_remesh_remap_loop_vertex_color_layer(Mesh *mesh)
{
diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c
index d87327f0277..ccc088713af 100644
--- a/source/blender/editors/object/object_edit.c
+++ b/source/blender/editors/object/object_edit.c
@@ -1797,7 +1797,8 @@ static int remesh_exec(bContext *C, wmOperator *op)
OpenVDBTransform_free(xform);
Mesh *objMesh_copy;
- if (mesh->flag & ME_REMESH_REPROJECT_VERTEX_PAINT) {
+ if (mesh->flag & ME_REMESH_REPROJECT_VERTEX_PAINT ||
+ mesh->flag & ME_REMESH_REPROJECT_PAINT_MASK) {
objMesh_copy = BKE_mesh_new_nomain_from_template(mesh, mesh->totvert, 0, 0, 0, 0);
CustomData_copy(&mesh->vdata, &objMesh_copy->vdata, CD_MASK_MESH.vmask, CD_DUPLICATE, mesh->totvert);
for(int i = 0; i < mesh->totvert; i++) {
@@ -1809,8 +1810,9 @@ static int remesh_exec(bContext *C, wmOperator *op)
BKE_remesh_voxel_init_empty_vertex_color_layer(mesh);
- if (mesh->flag & ME_REMESH_REPROJECT_VERTEX_PAINT) {
- BKE_remesh_voxel_reproject_vertex_paint(mesh, objMesh_copy);
+ if (mesh->flag & ME_REMESH_REPROJECT_VERTEX_PAINT ||
+ mesh->flag & ME_REMESH_REPROJECT_PAINT_MASK) {
+ BKE_remesh_voxel_reproject(mesh, objMesh_copy, mesh->flag);
BKE_mesh_free(objMesh_copy);
}
diff --git a/source/blender/makesdna/DNA_mesh_types.h b/source/blender/makesdna/DNA_mesh_types.h
index b8096358a24..843dbb48dd6 100644
--- a/source/blender/makesdna/DNA_mesh_types.h
+++ b/source/blender/makesdna/DNA_mesh_types.h
@@ -248,6 +248,7 @@ enum {
ME_SCULPT_DYNAMIC_TOPOLOGY = 1 << 10,
ME_REMESH_SMOOTH_NORMALS = 1 << 11,
ME_REMESH_REPROJECT_VERTEX_PAINT = 1 << 12,
+ ME_REMESH_REPROJECT_PAINT_MASK = 1 << 13,
};
/* me->cd_flag */
diff --git a/source/blender/makesrna/intern/rna_mesh.c b/source/blender/makesrna/intern/rna_mesh.c
index 22456c583a6..24e412a789e 100644
--- a/source/blender/makesrna/intern/rna_mesh.c
+++ b/source/blender/makesrna/intern/rna_mesh.c
@@ -2754,6 +2754,13 @@ static void rna_def_mesh(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Reproject Vertex Paint",
"Keep the current vertex paint on the new mesh");
RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
+
+ prop = RNA_def_property(srna, "reproject_paint_mask", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "flag", ME_REMESH_REPROJECT_PAINT_MASK);
+ RNA_def_property_boolean_default(prop, false);
+ RNA_def_property_ui_text(prop, "Reproject Mask",
+ "Keep the current mask on the new mesh");
+ RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
/* End remesher */
prop = RNA_def_property(srna, "use_auto_smooth", PROP_BOOLEAN, PROP_NONE);
More information about the Bf-blender-cvs
mailing list