[Bf-blender-cvs] [38b50452056] soc-2016-pbvh-painting: fixed masking bug, & pbvh freeing bug. Still trying to figure out grids...
Nathan Vollmer
noreply at git.blender.org
Wed Apr 5 12:11:48 CEST 2017
Commit: 38b5045205656dffa01b01f225434814bcb06f51
Author: Nathan Vollmer
Date: Tue Apr 4 23:00:02 2017 -0600
Branches: soc-2016-pbvh-painting
https://developer.blender.org/rB38b5045205656dffa01b01f225434814bcb06f51
fixed masking bug, & pbvh freeing bug. Still trying to figure out grids...
===================================================================
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/subsurf_ccg.c
M source/blender/editors/sculpt_paint/paint_vertex.c
M source/blender/editors/sculpt_paint/sculpt.c
M source/blender/editors/sculpt_paint/sculpt_intern.h
===================================================================
diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h
index 3a46e8281a1..d8ef476988c 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -214,6 +214,7 @@ typedef struct SculptSession {
unsigned int *tot_loops_hit;
float *max_weight;
unsigned int *previous_color;
+ 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 ebe809143c2..1554ff3d75f 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -2740,7 +2740,7 @@ void BKE_object_sculpt_modifiers_changed(Object *ob)
{
SculptSession *ss = ob->sculpt;
- if (ss) {
+ 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 b1006f3807c..07fe63929cd 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -875,6 +875,9 @@ 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->building_vp_handle = false;
+
if (need_mask) {
if (mmd == NULL) {
if (!CustomData_has_layer(&me->vdata, CD_PAINT_MASK)) {
diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c
index 53dae7a141b..6927bdaa438 100644
--- a/source/blender/blenkernel/intern/subsurf_ccg.c
+++ b/source/blender/blenkernel/intern/subsurf_ccg.c
@@ -4419,7 +4419,8 @@ static struct PBVH *ccgDM_getPBVH(Object *ob, DerivedMesh *dm)
if (!ob->sculpt)
return NULL;
- grid_pbvh = ccgDM_use_grid_pbvh(ccgdm);
+ /* In vwpaint, we always use a grid_pbvh for multires/subsurf */
+ grid_pbvh = (!(ob->mode & OB_MODE_SCULPT)) || ccgDM_use_grid_pbvh(ccgdm);
if (ob->sculpt->pbvh) {
if (grid_pbvh) {
@@ -4441,8 +4442,8 @@ static struct PBVH *ccgDM_getPBVH(Object *ob, DerivedMesh *dm)
/* no pbvh exists yet, we need to create one. only in case of multires
* we build a pbvh over the modified mesh, in other cases the base mesh
* is being sculpted, so we build a pbvh from that. */
- /* Note: VWPaint do not support PBVH_GRIDS at the moment. */
- if (grid_pbvh && ob->mode & OB_MODE_SCULPT) {
+ /* Note: vwpaint always builds a pbvh over the modified mesh. */
+ if (grid_pbvh) {
ccgdm_create_grids(dm);
numGrids = ccgDM_getNumGrids(dm);
diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c
index f0e275a00d1..5ee2ae12b18 100644
--- a/source/blender/editors/sculpt_paint/paint_vertex.c
+++ b/source/blender/editors/sculpt_paint/paint_vertex.c
@@ -81,6 +81,8 @@
#include "bmesh.h"
#include "bmesh_tools.h"
+#include "BKE_subsurf.h"
+#include "BKE_ccg.h"
/* small structure to defer applying weight-paint results */
struct WPaintDefer {
@@ -1656,9 +1658,10 @@ static void do_weight_paint_vertex(
/ copied from sculpt.c ****/
static void vertex_paint_init_session(Scene *scene, Object *ob)
{
- if (!ob->sculpt)
- ob->sculpt = MEM_callocN(sizeof(SculptSession), "sculpt session");
- BKE_sculpt_update_mesh_elements(scene, scene->toolsettings->sculpt, ob, 0, false);
+ if (!ob->sculpt) {
+ ob->sculpt = MEM_callocN(sizeof(SculptSession), "sculpt session");
+ BKE_sculpt_update_mesh_elements(scene, scene->toolsettings->sculpt, ob, 0, false);
+ }
}
static void vertex_paint_init_session_maps(Object *ob) {
@@ -2112,7 +2115,9 @@ static bool wpaint_stroke_test_start(bContext *C, wmOperator *op, const float mo
}
/* painting on subsurfs should give correct points too, this returns me->totvert amount */
+ ob->sculpt->building_vp_handle = true;
wpd->vp_handle = ED_vpaint_proj_handle_create(scene, ob, &wpd->vertexcosnos);
+ ob->sculpt->building_vp_handle = false;
/* imat for normals */
mul_m4_m4m4(mat, wpd->vc.rv3d->viewmat, ob->obmat);
@@ -2271,7 +2276,7 @@ static void calc_brushdata_symm(VPaint *vd, StrokeCache *cache, const char symm,
}
static void do_wpaint_brush_blur_task_cb_ex(
- void *userdata, void *UNUSED(userdata_chunk), const int n, const int UNUSED(thread_id))
+ void *userdata, void *UNUSED(userdata_chunk), const int n, const int UNUSED(thread_id))
{
SculptThreadedTaskData *data = userdata;
SculptSession *ss = data->ob->sculpt;
@@ -2292,7 +2297,7 @@ static void do_wpaint_brush_blur_task_cb_ex(
sculpt_brush_test_init(ss, &test);
/* Test to see if the vertex coordinates are within the spherical brush region. */
- if (sculpt_brush_test(&test, vd.co)) {
+ if (sculpt_brush_test_sq(&test, vd.co)) {
const int vertexIndex = vd.vert_indices[vd.i];
/* Get the average poly color */
@@ -2301,11 +2306,11 @@ static void do_wpaint_brush_blur_task_cb_ex(
for (int j = 0; j < ss->vert_to_poly[vertexIndex].count; j++) {
int polyIndex = ss->vert_to_poly[vertexIndex].indices[j];
- MPoly poly = data->me->mpoly[polyIndex];
+ MPoly *poly = &data->me->mpoly[polyIndex];
- total_hit_loops += poly.totloop;
- for (int k = 0; k < poly.totloop; ++k) {
- int loopIndex = poly.loopstart + k;
+ total_hit_loops += poly->totloop;
+ for (int k = 0; k < poly->totloop; ++k) {
+ int loopIndex = poly->loopstart + k;
MLoop loop = data->me->mloop[loopIndex];
MDeformVert *dv = &data->me->dvert[loop.v];
MDeformWeight *dw = defvert_verify_index(dv, data->wpi->active.index);
@@ -2313,7 +2318,7 @@ static void do_wpaint_brush_blur_task_cb_ex(
}
}
if (total_hit_loops != 0) {
- const float fade = BKE_brush_curve_strength(brush, test.dist, cache->radius);
+ const float fade = BKE_brush_curve_strength(brush, sqrtf(test.dist), cache->radius);
const float dot = dot_vf3vs3(cache->sculpt_normal_symm, vd.no);
finalColor /= total_hit_loops;
@@ -2327,7 +2332,7 @@ static void do_wpaint_brush_blur_task_cb_ex(
}
static void do_wpaint_brush_smudge_task_cb_ex(
- void *userdata, void *UNUSED(userdata_chunk), const int n, const int UNUSED(thread_id))
+ void *userdata, void *UNUSED(userdata_chunk), const int n, const int UNUSED(thread_id))
{
SculptThreadedTaskData *data = userdata;
SculptSession *ss = data->ob->sculpt;
@@ -2350,7 +2355,7 @@ static void do_wpaint_brush_smudge_task_cb_ex(
sculpt_brush_test_init(ss, &test);
/* Test to see if the vertex coordinates are within the spherical brush region. */
- if (sculpt_brush_test(&test, vd.co)) {
+ if (sculpt_brush_test_fast(&test, vd.co)) {
const float dot = dot_vf3vs3(cache->sculpt_normal_symm, vd.no);
const int vertexIndex = vd.vert_indices[vd.i];
MVert *currentVert = &data->me->mvert[vertexIndex];
@@ -2397,7 +2402,7 @@ static void do_wpaint_brush_smudge_task_cb_ex(
static void do_wpaint_brush_draw_task_cb_ex(
- void *userdata, void *UNUSED(userdata_chunk), const int n, const int UNUSED(thread_id))
+ void *userdata, void *UNUSED(userdata_chunk), const int n, const int UNUSED(thread_id))
{
SculptThreadedTaskData *data = userdata;
SculptSession *ss = data->ob->sculpt;
@@ -2407,58 +2412,60 @@ static void do_wpaint_brush_draw_task_cb_ex(
StrokeCache *cache = ss->cache;
const float bstrength = cache->bstrength;
float paintweight = BKE_brush_weight_get(scene, brush);
+ const float brush_alpha_value = BKE_brush_alpha_get(scene, brush);
+ const float brush_alpha_pressure =
+ brush_alpha_value * (BKE_brush_use_alpha_pressure(scene, brush) ? ss->cache->pressure : 1.0f);
+ int face_mask_on = data->me->editflag & ME_EDIT_PAINT_FACE_SEL;
+ int vert_mask_on = data->me->editflag & ME_EDIT_PAINT_VERT_SEL;
PBVHVertexIter vd;
BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE)
{
SculptBrushTest test;
sculpt_brush_test_init(ss, &test);
- if (sculpt_brush_test(&test, vd.co)) {
+ if (sculpt_brush_test_sq(&test, vd.co)) {
const int vertexIndex = vd.vert_indices[vd.i];
- MVert v = data->me->mvert[vertexIndex];
- /* If the vertex is selected */
- if (v.flag & 1) {
- const float dot = dot_vf3vs3(cache->sculpt_normal_symm, vd.no);
- const float fade = BKE_brush_curve_strength(brush, test.dist, cache->radius);
- const float brush_alpha_value = BKE_brush_alpha_get(scene, brush);
- const float brush_alpha_pressure =
- brush_alpha_value * (BKE_brush_use_alpha_pressure(scene, brush) ? ss->cache->pressure : 1.0f);
- float actualStrength = bstrength * fade * dot * brush_alpha_pressure;
- float currentWeight;
-
- /* Spray logic */
- if (!(data->vp->flag & VP_SPRAY)) {
- MDeformVert *dv = &data->me->dvert[vertexIndex];
- MDeformWeight *dw;
- dw = (data->vp->flag & VP_ONLYVGROUP) ? defvert_find_index(dv, data->wpi->active.index) :
- defvert_verify_index(dv, data->wpi->active.index);
- currentWeight = dw->weight;
- if (ss->max_weight[vertexIndex] < 0) {
- ss->max_weight[vertexIndex] = min_ff(bstrength + dw->weight, 1.0f);
- }
- CLAMP(actualStrength, 0.0, ss->max_weight[vertexIndex] - dw->weight);
- }
-
- /* Splash Prevention */
- if (dot > 0.0){
- switch (data->vp->flag) {
- case VP_SPRAY:
- if (currentWeight < ss->max_weight[vertexIndex])
- do_weight_paint_vertex(data->vp, data->ob, data->wpi, vertexIndex, actualStrength, paintweight);
- break;
- default:
- do_weight_paint_vertex(data->vp, data->ob, data->wpi, vertexIndex, actualStrength, paintweight);
- break;
- }
- }
- }
+ char v_flag = data->me->mvert[vertexIndex].flag;
+ /* If the vertex is selected */
+ if (!(face_mask_on || vert_mask_on) || v_flag & SELECT) {
+ const float dot = dot_vf
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list