[Bf-blender-cvs] [5b6ab0769d1] soc-2016-pbvh-painting: Cleanup: split vert/weight paint into separate members
Campbell Barton
noreply at git.blender.org
Wed Sep 27 06:37:31 CEST 2017
Commit: 5b6ab0769d1a30eaee7500165ffb90e03eb2c3e6
Author: Campbell Barton
Date: Wed Sep 27 14:40:33 2017 +1000
Branches: soc-2016-pbvh-painting
https://developer.blender.org/rB5b6ab0769d1a30eaee7500165ffb90e03eb2c3e6
Cleanup: split vert/weight paint into separate members
- Remove unused previous wpaint/vpaint struct members.
- Avoid allocating arrays when they aren't used.
===================================================================
M source/blender/blenkernel/BKE_paint.h
M source/blender/blenkernel/intern/object.c
M source/blender/blenkernel/intern/paint.c
M source/blender/blenkernel/intern/scene.c
M source/blender/blenloader/intern/readfile.c
M source/blender/editors/sculpt_paint/paint_intern.h
M source/blender/editors/sculpt_paint/paint_vertex.c
M source/blender/editors/sculpt_paint/sculpt_intern.h
M source/blender/makesdna/DNA_scene_types.h
===================================================================
diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h
index 782f45e6cb9..bb2916bcff9 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -160,6 +160,17 @@ void paint_update_brush_rake_rotation(struct UnifiedPaintSettings *ups, struct B
void BKE_paint_stroke_get_average(struct Scene *scene, struct Object *ob, float stroke[3]);
+/* Used for both vertex color and weight paint */
+struct SculptVertexPaintGeomMap {
+ int *vert_map_mem;
+ struct MeshElemMap *vert_to_loop;
+ int *poly_map_mem;
+ struct MeshElemMap *vert_to_poly;
+
+ /* Runtime. */
+ unsigned int *tot_loops_hit;
+};
+
/* Session data (mode-specific) */
typedef struct SculptSession {
@@ -208,23 +219,36 @@ typedef struct SculptSession {
union {
struct {
- int *vert_map_mem;
- struct MeshElemMap *vert_to_loop;
- int *poly_map_mem;
- struct MeshElemMap *vert_to_poly;
-
- unsigned int (*total_color)[3];
- double *total_weight;
- unsigned int *tot_loops_hit;
- float *alpha_weight;
- float *previous_weight;
+ struct SculptVertexPaintGeomMap gmap;
+
+ /* For non-airbrush painting to re-apply from the original (MLoop aligned). */
unsigned int *previous_color;
- bool building_vp_handle;
- } vwpaint;
+
+ /* For blur only (PBVH Node aligned). */
+ unsigned int (*average_color)[3];
+ } vpaint;
+
+ struct {
+ struct SculptVertexPaintGeomMap gmap;
+
+ /* Vertex aligned arrays of weights. */
+ /* For non-airbrush painting to re-apply from the original. */
+ float *previous_weight;
+ /* Keep track of how much each vertex has been painted (non-airbrush only). */
+ float *alpha_weight;
+
+ /* For blur only (PBVH Node aligned). */
+ double *average_weight;
+ } wpaint;
+
//struct {
//ToDo: identify sculpt-only fields
//} sculpt;
- } modes;
+ } mode;
+ int mode_type;
+
+ /* This flag prevents PBVH from being freed when creating the vp_handle for texture paint. */
+ bool building_vp_handle;
} SculptSession;
void BKE_sculptsession_free(struct Object *ob);
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index a89b1a2d60e..44058c989ff 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -2682,7 +2682,7 @@ void BKE_object_sculpt_modifiers_changed(Object *ob)
{
SculptSession *ss = ob->sculpt;
- if (ss && ss->modes.vwpaint.building_vp_handle == false) {
+ if (ss && ss->building_vp_handle == false) {
if (!ss->cache) {
/* we free pbvh on changes, except during sculpt since it can't deal with
* changing PVBH node organization, we hope topology does not change in
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index a96e6158584..d1820479ed0 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -676,18 +676,32 @@ void BKE_sculptsession_free_deformMats(SculptSession *ss)
void BKE_sculptsession_free_vwpaint_data(struct SculptSession *ss)
{
/* Free maps */
- MEM_SAFE_FREE(ss->modes.vwpaint.vert_to_loop);
- MEM_SAFE_FREE(ss->modes.vwpaint.vert_map_mem);
- MEM_SAFE_FREE(ss->modes.vwpaint.vert_to_poly);
- MEM_SAFE_FREE(ss->modes.vwpaint.poly_map_mem);
-
- /* Free average, blur, and spray brush arrays */
- MEM_SAFE_FREE(ss->modes.vwpaint.tot_loops_hit);
- MEM_SAFE_FREE(ss->modes.vwpaint.total_color);
- MEM_SAFE_FREE(ss->modes.vwpaint.total_weight);
- MEM_SAFE_FREE(ss->modes.vwpaint.alpha_weight);
- MEM_SAFE_FREE(ss->modes.vwpaint.previous_weight);
- MEM_SAFE_FREE(ss->modes.vwpaint.previous_color);
+ /* Create maps */
+ struct SculptVertexPaintGeomMap *gmap = NULL;
+ if (ss->mode_type == OB_MODE_VERTEX_PAINT) {
+ gmap = &ss->mode.vpaint.gmap;
+
+ /* Free average, blur, and spray brush arrays */
+ MEM_SAFE_FREE(ss->mode.vpaint.average_color);
+ MEM_SAFE_FREE(ss->mode.vpaint.previous_color);
+ }
+ else if (ss->mode_type == OB_MODE_WEIGHT_PAINT) {
+ gmap = &ss->mode.wpaint.gmap;
+
+ /* Free average, blur, and spray brush arrays */
+ MEM_SAFE_FREE(ss->mode.wpaint.average_weight);
+ MEM_SAFE_FREE(ss->mode.wpaint.alpha_weight);
+ MEM_SAFE_FREE(ss->mode.wpaint.previous_weight);
+ }
+ else {
+ return;
+ }
+ MEM_SAFE_FREE(gmap->vert_to_loop);
+ MEM_SAFE_FREE(gmap->vert_map_mem);
+ MEM_SAFE_FREE(gmap->vert_to_poly);
+ MEM_SAFE_FREE(gmap->poly_map_mem);
+
+ MEM_SAFE_FREE(gmap->tot_loops_hit);
}
/* Write out the sculpt dynamic-topology BMesh to the Mesh */
@@ -864,8 +878,7 @@ void BKE_sculpt_update_mesh_elements(Scene *scene, Sculpt *sd, Object *ob,
ss->modifiers_active = sculpt_modifiers_active(scene, sd, ob);
ss->show_diffuse_color = (sd->flags & SCULPT_SHOW_DIFFUSE) != 0;
- /* This flag prevents PBVH from being freed when creating the vp_handle for texture paint */
- ss->modes.vwpaint.building_vp_handle = false;
+ ss->building_vp_handle = false;
if (need_mask) {
if (mmd == NULL) {
diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c
index 5b809386267..c0dcac33656 100644
--- a/source/blender/blenkernel/intern/scene.c
+++ b/source/blender/blenkernel/intern/scene.c
@@ -217,16 +217,10 @@ void BKE_scene_copy_data(Main *bmain, Scene *sce_dst, const Scene *sce_src, cons
ToolSettings *ts = sce_dst->toolsettings = MEM_dupallocN(sce_dst->toolsettings);
if (ts->vpaint) {
ts->vpaint = MEM_dupallocN(ts->vpaint);
- ts->vpaint->paintcursor = NULL;
- ts->vpaint->vpaint_prev = NULL;
- ts->vpaint->wpaint_prev = NULL;
BKE_paint_copy(&ts->vpaint->paint, &ts->vpaint->paint, flag_subdata);
}
if (ts->wpaint) {
ts->wpaint = MEM_dupallocN(ts->wpaint);
- ts->wpaint->paintcursor = NULL;
- ts->wpaint->vpaint_prev = NULL;
- ts->wpaint->wpaint_prev = NULL;
BKE_paint_copy(&ts->wpaint->paint, &ts->wpaint->paint, flag_subdata);
}
if (ts->sculpt) {
@@ -335,16 +329,10 @@ Scene *BKE_scene_copy(Main *bmain, Scene *sce, int type)
if (ts) {
if (ts->vpaint) {
ts->vpaint = MEM_dupallocN(ts->vpaint);
- ts->vpaint->paintcursor = NULL;
- ts->vpaint->vpaint_prev = NULL;
- ts->vpaint->wpaint_prev = NULL;
BKE_paint_copy(&ts->vpaint->paint, &ts->vpaint->paint, 0);
}
if (ts->wpaint) {
ts->wpaint = MEM_dupallocN(ts->wpaint);
- ts->wpaint->paintcursor = NULL;
- ts->wpaint->vpaint_prev = NULL;
- ts->wpaint->wpaint_prev = NULL;
BKE_paint_copy(&ts->wpaint->paint, &ts->wpaint->paint, 0);
}
if (ts->sculpt) {
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index f2d958adb95..3b7662be2b2 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -6003,16 +6003,6 @@ static void direct_link_scene(FileData *fd, Scene *sce)
sce->toolsettings->particle.scene = NULL;
sce->toolsettings->particle.object = NULL;
sce->toolsettings->gp_sculpt.paintcursor = NULL;
-
- /* in rare cases this is needed, see [#33806] */
- if (sce->toolsettings->vpaint) {
- sce->toolsettings->vpaint->vpaint_prev = NULL;
- sce->toolsettings->vpaint->tot = 0;
- }
- if (sce->toolsettings->wpaint) {
- sce->toolsettings->wpaint->wpaint_prev = NULL;
- sce->toolsettings->wpaint->tot = 0;
- }
/* relink grease pencil drawing brushes */
link_list(fd, &sce->toolsettings->gp_brushes);
diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h
index f91a6baf6a9..b7706db3e37 100644
--- a/source/blender/editors/sculpt_paint/paint_intern.h
+++ b/source/blender/editors/sculpt_paint/paint_intern.h
@@ -98,7 +98,7 @@ int vertex_paint_poll(struct bContext *C);
int vertex_paint_mode_poll(struct bContext *C);
bool ED_vpaint_fill(struct Object *ob, unsigned int paintcol);
-bool ED_wpaint_fill(struct VPaint *wp, struct Object *ob, float paintweight);
+bool ED_wpaint_fill(struct Object *ob, float paintweight);
bool ED_vpaint_smooth(struct Object *ob);
diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c
index 901086fa44f..5265032ed58 100644
--- a/source/blender/editors/sculpt_paint/paint_vertex.c
+++ b/source/blender/editors/sculpt_paint/paint_vertex.c
@@ -293,27 +293,37 @@ static int wpaint_mirror_vgroup_ensure(Object *ob, const int vgroup_active)
return -1;
}
-static void free_wpaint_prev(VPaint *vp)
+struct WPaintPrev {
+ struct MDeformVert *wpaint_prev; /* previous vertex weights */
+ int tot; /* allocation size of prev buffers */
+};
+
+static void wpaint_prev_init(struct WPaintPrev *wpp)
{
- if (vp->wpaint_prev) {
- BKE_defvert_array_free(vp->wpaint_prev, vp->tot);
- vp->wpaint_prev = NULL;
- vp->tot = 0;
- }
+ wpp->wpaint_prev = NULL;
+ wpp->tot = 0;
}
-static void copy_wpaint_prev(VPaint *wp, MDeformVert *dverts, int dcount)
+static void wpaint_prev_create(struct WPaintPrev *wpp, MDeformVert *dverts, int dcount)
{
- free_wpaint_prev(wp);
-
+ wpaint_prev_init(wpp);
+
if (dverts && dcount) {
-
- wp->wpaint_prev = MEM_mallocN(sizeof(MDeformVert) * dcount, "wpaint prev");
- wp->tot = dcount;
- BKE_defvert_array_copy(wp->wpaint_prev, dverts, dcount);
+ wpp->wpaint_prev = MEM_mallocN(sizeof(MDeformVert) * dcount, "wpaint prev");
+ wpp->tot = dcount;
+ BKE_defvert_array_copy(wpp->wpaint_prev, dverts, dcount);
}
}
+static void wpaint_prev_destroy(struct WPaintPrev *wpp)
+{
+ if (wpp->wpaint_prev) {
+ BKE_defvert_array_free(wpp->wpaint_prev, wpp->tot);
+ }
+ wpp->wpaint_prev = NULL;
+ wpp->tot = 0;
+}
+
bool ED_vpaint_fill(Object *ob, uint paintcol)
{
Mesh *me;
@@ -350,7 +360,7 @@ bool ED_vpaint_fill(Object *ob, uint paintcol)
/* fills in the selected faces with the current weight and vertex group */
-bool ED_wpaint_fill(VPaint *wp, Object *ob, float paintweight)
+bool ED_wpaint_fill(Object *ob, float paintweight)
{
Mesh *me = ob->data;
const MPoly *mp;
@@ -373,7 +383,8 @@ bool ED_wpaint_fill(VPaint *wp, Object *ob, float paintweight)
vgroup_mirror = wpaint_mirror_vgroup_ensure(ob, vgroup_active);
}
- copy_wpaint_prev(wp, me->dvert, me->totvert);
+ struct WPaintPrev wpp;
+ wpai
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list