[Bf-blender-cvs] [e21c21bbf9e] sculpt-dev: Sculpt-dev: support area weighted smooth for PBVH_FACES
Joseph Eagar
noreply at git.blender.org
Sun Nov 28 10:26:23 CET 2021
Commit: e21c21bbf9e7d3f7a400e1fc5485005c251c8f62
Author: Joseph Eagar
Date: Sun Nov 28 01:19:23 2021 -0800
Branches: sculpt-dev
https://developer.blender.org/rBe21c21bbf9e7d3f7a400e1fc5485005c251c8f62
Sculpt-dev: support area weighted smooth for PBVH_FACES
* This was actually kind of annoying; the
vertex->face-area-list code is in pbvh and
relies on edge ordering
around verts, but that order is non-trivial for
PBVH_FACES (relying as it does on a vertex->poly
map). This ordering was calculated entirely in
editors/sculpt_paint/sculpt.c, not callable from
pbvh.
* The solution was to add a helper function to pbvh
for building vertex->edge lists from vertex->poly
maps. This is then used by both sculpt.c and the
vertex->face-area-list code.
* Also improved boundary bevel smooth a bit. I'm
thinking of extracting it from SCULPT_neighbor_coords_average_interior
into its own function and possibly its own brush.
===================================================================
M release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
M release/scripts/startup/bl_ui/space_view3d_toolbar.py
M source/blender/blenkernel/BKE_paint.h
M source/blender/blenkernel/BKE_pbvh.h
M source/blender/blenkernel/intern/paint.c
M source/blender/blenkernel/intern/pbvh.c
M source/blender/blenkernel/intern/pbvh_intern.h
M source/blender/bmesh/intern/bmesh_log.c
M source/blender/editors/sculpt_paint/sculpt.c
M source/blender/editors/sculpt_paint/sculpt_filter_mesh.c
M source/blender/editors/sculpt_paint/sculpt_intern.h
M source/blender/editors/sculpt_paint/sculpt_ops.c
M source/blender/editors/sculpt_paint/sculpt_smooth.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
index 9ed8b0d3e56..c32ee75adf0 100644
--- a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
@@ -1350,6 +1350,7 @@ class _defs_sculpt:
layout.prop(props, "hard_edge_mode")
layout.prop(props, "preserve_fset_boundaries")
layout.prop(props, "bound_smooth_radius")
+ layout.prop(props, "bevel_smooth_fac")
return dict(idname="builtin.mesh_filter",
label="Mesh Filter",
diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
index 44ba09f499f..d69d08aa4bb 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -493,6 +493,10 @@ class VIEW3D_PT_tools_brush_color(Panel, View3DPaintPanel):
def draw(self, context):
layout = self.layout
settings = self.paint_settings(context)
+
+ if not settings:
+ return
+
brush = settings.brush
draw_color_settings(context, layout, brush, color_type=not context.vertex_paint_object)
diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h
index 31f827744d7..de6acbae8fd 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -743,6 +743,7 @@ typedef struct SculptSession {
float (*orig_cos)[3]; /* Coords of un-deformed mesh. */
float (*deform_cos)[3]; /* Coords of deformed mesh but without stroke displacement. */
float (*deform_imats)[3][3]; /* Crazy-space deformation matrices. */
+ float *face_areas; /* cached face areas for PBVH_FACES and PBVH_GRIDS */
/* Used to cache the render of the active texture */
unsigned int texcache_side, *texcache, texcache_actual;
@@ -890,6 +891,7 @@ bool BKE_sculptsession_customlayer_get(struct Object *ob,
const char *name,
SculptCustomLayer *scl,
SculptLayerParams *params);
+bool BKE_sculptsession_customlayer_release(struct Object *ob, SculptCustomLayer *scl);
void BKE_sculptsession_bmesh_attr_update_internal(struct Object *ob);
void BKE_sculptsession_update_attr_refs(struct Object *ob);
int BKE_sculptsession_get_totvert(const SculptSession *ss);
diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h
index 6b221da3ad4..24de34d21f2 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -292,7 +292,9 @@ void BKE_pbvh_build_mesh(PBVH *pbvh,
struct CustomData *pdata,
const struct MLoopTri *looptri,
int looptri_num,
- bool fast_draw);
+ bool fast_draw,
+ float *face_areas,
+ struct MeshElemMap *pmap);
void BKE_pbvh_build_grids(PBVH *pbvh,
struct CCGElem **grids,
int totgrid,
@@ -300,7 +302,8 @@ void BKE_pbvh_build_grids(PBVH *pbvh,
void **gridfaces,
struct DMFlagMat *flagmats,
unsigned int **grid_hidden,
- bool fast_draw);
+ bool fast_draw,
+ float *face_areas);
void BKE_pbvh_build_bmesh(PBVH *pbvh,
struct Mesh *me,
struct BMesh *bm,
@@ -1070,3 +1073,21 @@ void BKE_dyntopo_remesh(DynTopoState *ds,
PBVHTopologyUpdateMode mode);
void BKE_pbvh_bmesh_get_vcol(
struct BMVert *v, float color[4], int vcol_type, AttributeDomain vcol_domain, int vcol_offset);
+/*
+
+use pmap to build an array of edge indices surrounding vertex
+r_edges, r_edges_size, heap_alloc define an existing array to put data in.
+
+final array is similarly put in these pointers. note that calling code
+may pass a stack allocated array (*heap_alloc should be false), and must
+check if heap_alloc is true afterwards and free *r_edges.
+
+r_polys is an array of integer pairs and must be same logical size as r_edges
+*/
+void BKE_pbvh_pmap_to_edges(PBVH *pbvh,
+ SculptVertRef vertex,
+ int **r_edges,
+ int *r_edges_size,
+ bool *heap_alloc,
+ int **r_polys);
+void BKE_pbvh_set_vemap(PBVH *pbvh, struct MeshElemMap *vemap);
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index ce879af228a..9b28a12c57a 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -90,6 +90,8 @@ void SCULPT_undo_ensure_bmlog(Object *ob);
static void init_mdyntopo_layer(SculptSession *ss, PBVH *pbvh, int totvert);
+const char *face_areas_layer_name = "_sculpt_face_areas";
+
static void palette_init_data(ID *id)
{
Palette *palette = (Palette *)id;
@@ -1455,6 +1457,8 @@ static void sculptsession_free_pbvh(Object *object)
ss->pbvh = NULL;
}
+ MEM_SAFE_FREE(ss->face_areas);
+
MEM_SAFE_FREE(ss->pmap);
MEM_SAFE_FREE(ss->pmap_mem);
@@ -2444,19 +2448,24 @@ static PBVH *build_pbvh_from_regular_mesh(Object *ob, Mesh *me_eval_deform, bool
BKE_sculptsession_check_mdyntopo(ob->sculpt, pbvh, me->totvert);
+ MEM_SAFE_FREE(ss->face_areas);
+ ss->face_areas = MEM_calloc_arrayN(me->totpoly, sizeof(float), "ss->face_areas");
+
BKE_pbvh_build_mesh(pbvh,
me,
me->mpoly,
me->mloop,
me->mvert,
- ob->sculpt->mdyntopo_verts,
+ ss->mdyntopo_verts,
me->totvert,
&me->vdata,
&me->ldata,
&me->pdata,
looptri,
looptris_num,
- ob->sculpt->fast_draw);
+ ss->fast_draw,
+ ss->face_areas,
+ ss->pmap);
pbvh_show_mask_set(pbvh, ob->sculpt->show_mask);
pbvh_show_face_sets_set(pbvh, ob->sculpt->show_face_sets);
@@ -2474,6 +2483,8 @@ static PBVH *build_pbvh_from_regular_mesh(Object *ob, Mesh *me_eval_deform, bool
static PBVH *build_pbvh_from_ccg(Object *ob, SubdivCCG *subdiv_ccg, bool respect_hide)
{
+ SculptSession *ss = ob->sculpt;
+
CCGKey key;
BKE_subdiv_ccg_key_top_level(&key, subdiv_ccg);
PBVH *pbvh = BKE_pbvh_new();
@@ -2482,6 +2493,11 @@ static PBVH *build_pbvh_from_ccg(Object *ob, SubdivCCG *subdiv_ccg, bool respect
Mesh *base_mesh = BKE_mesh_from_object(ob);
BKE_sculpt_sync_face_set_visibility(base_mesh, subdiv_ccg);
+ int totgridfaces = base_mesh->totpoly * (key.grid_size - 1) * (key.grid_size - 1);
+
+ MEM_SAFE_FREE(ss->face_areas);
+ ss->face_areas = MEM_calloc_arrayN(totgridfaces, sizeof(float), "ss->face_areas");
+
BKE_pbvh_build_grids(pbvh,
subdiv_ccg->grids,
subdiv_ccg->num_grids,
@@ -2489,7 +2505,8 @@ static PBVH *build_pbvh_from_ccg(Object *ob, SubdivCCG *subdiv_ccg, bool respect
(void **)subdiv_ccg->grid_faces,
subdiv_ccg->grid_flag_mats,
subdiv_ccg->grid_hidden,
- ob->sculpt->fast_draw);
+ ob->sculpt->fast_draw,
+ ss->face_areas);
BKE_sculptsession_check_mdyntopo(ob->sculpt, pbvh, BKE_pbvh_get_grid_num_vertices(pbvh));
@@ -3353,3 +3370,54 @@ bool BKE_paint_uses_channels(ePaintMode mode)
{
return mode == PAINT_MODE_SCULPT;
}
+
+bool BKE_sculptsession_customlayer_release(Object *ob, SculptCustomLayer *scl)
+{
+ SculptSession *ss = ob->sculpt;
+ AttributeDomain domain = scl->domain;
+
+ if (scl->released) {
+ return false;
+ }
+
+ // remove from layers_to_free list if necassary
+ for (int i = 0; scl->data && i < ss->tot_layers_to_free; i++) {
+ if (ss->layers_to_free[i] && ss->layers_to_free[i]->data == scl->data) {
+ MEM_freeN(ss->layers_to_free[i]);
+ ss->layers_to_free[i] = NULL;
+ }
+ }
+
+ scl->released = true;
+
+ if (!scl->from_bmesh) {
+ // for now, don't clean up bmesh temp layers
+ if (scl->is_cdlayer && BKE_pbvh_type(ss->pbvh) != PBVH_GRIDS) {
+ CustomData *cdata = NULL;
+ int totelem = 0;
+
+ switch (domain) {
+ case ATTR_DOMAIN_POINT:
+ cdata = ss->vdata;
+ totelem = ss->totvert;
+ break;
+ case ATTR_DOMAIN_FACE:
+ cdata = ss->pdata;
+ totelem = ss->totfaces;
+ break;
+ default:
+ printf("error, unknown domain in %s\n", __func__);
+ return false;
+ }
+
+ CustomData_free_layer(cdata, scl->layer->type, totelem, scl->layer - cdata->layers);
+ BKE_sculptsession_update_attr_refs(ob);
+ }
+ else {
+ MEM_SAFE_FREE(scl->data);
+ }
+
+ scl->data = NULL;
+ }
+ return true;
+}
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index 06569b596e4..83557ba41de 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -22,6 +22,7 @@
#include "BLI_utildefines.h"
+#include "BLI_alloca.h"
#include "BLI_bitmap.h"
#include "BLI_ghash.h"
#include "BLI_math.h"
@@ -421,6 +422,7 @@ static void build_mesh_leaf_node(PBVH *pbvh, PBVHNode *node)
BKE_pbvh_node_mark_rebuild_draw(node);
BKE_pbvh_node_fully_hidden_set(node, !has_visible);
+ BKE_pbvh_node_mark_update_tri_area(node);
BLI_ghash_free(map, NULL, NULL);
}
@@ -493,6 +495,7 @@ static void build_grid_leaf_node(PBVH *pbvh, PBVHNode *node)
pbvh->grid_hidden, node->prim_indices, node->totprim, pbvh->gridkey.grid_size);
BKE_pbvh_node_fully_hidden_set(node, (totquads ==
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list