[Bf-blender-cvs] [e6a35db8150] soc-2016-pbvh-painting: Added support for multires for both vertex and weight paint. Fixed a masking bug.
Nathan Vollmer
noreply at git.blender.org
Wed Apr 12 12:00:30 CEST 2017
Commit: e6a35db8150ae7662558e37a9ff7109850b917dc
Author: Nathan Vollmer
Date: Wed Apr 12 03:57:10 2017 -0600
Branches: soc-2016-pbvh-painting
https://developer.blender.org/rBe6a35db8150ae7662558e37a9ff7109850b917dc
Added support for multires for both vertex and weight paint. Fixed a masking bug.
===================================================================
M release/datafiles/locale
M release/scripts/addons
M release/scripts/addons_contrib
M source/blender/blenkernel/BKE_pbvh.h
M source/blender/blenkernel/intern/CCGSubSurf.c
M source/blender/blenkernel/intern/pbvh.c
M source/blender/blenkernel/intern/pbvh_intern.h
M source/blender/blenkernel/intern/subsurf_ccg.c
M source/blender/editors/sculpt_paint/paint_vertex.c
M source/tools
===================================================================
diff --git a/release/datafiles/locale b/release/datafiles/locale
index c93ed11a47b..81e6949b1f1 160000
--- a/release/datafiles/locale
+++ b/release/datafiles/locale
@@ -1 +1 @@
-Subproject commit c93ed11a47b3016cf59711ec16de2e2e94c30e99
+Subproject commit 81e6949b1f1bf3da1b685610bf76efcc7adc30a4
diff --git a/release/scripts/addons b/release/scripts/addons
index 371960484a3..e7c7ef6be46 160000
--- a/release/scripts/addons
+++ b/release/scripts/addons
@@ -1 +1 @@
-Subproject commit 371960484a38fc64e0a2635170a41a0d8ab2f6bd
+Subproject commit e7c7ef6be466111196c283f48b51c372e4167a88
diff --git a/release/scripts/addons_contrib b/release/scripts/addons_contrib
index a8515cfdfe9..2f47d3d7cfe 160000
--- a/release/scripts/addons_contrib
+++ b/release/scripts/addons_contrib
@@ -1 +1 @@
-Subproject commit a8515cfdfe9a98127b592f36fcbe51b7e23b969a
+Subproject commit 2f47d3d7cfea05672f7bb706c6878b7d07d52a1b
diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h
index c8c32c582d3..18f72cea536 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -71,7 +71,7 @@ void BKE_pbvh_build_grids(PBVH *bvh, struct CCGElem **grid_elems,
struct CCGKey *key, void **gridfaces, struct DMFlagMat *flagmats,
unsigned int **grid_hidden);
void BKE_pbvh_build_bmesh(PBVH *bvh, struct BMesh *bm, bool smooth_shading, struct BMLog *log, const int cd_vert_node_offset, const int cd_face_node_offset);
-
+void BKE_pbvh_add_ccgdm(PBVH *bvh, struct CCGDerivedMesh *ccgdm);
void BKE_pbvh_free(PBVH *bvh);
void BKE_pbvh_free_layer_disp(PBVH *bvh);
@@ -142,6 +142,7 @@ int BKE_pbvh_count_grid_quads(BLI_bitmap **grid_hidden,
/* multires level, only valid for type == PBVH_GRIDS */
void BKE_pbvh_get_grid_key(const PBVH *pbvh, struct CCGKey *key);
+void BKE_pbvh_get_ccgdm(const PBVH *bvh, struct CCGDerivedMesh *ccgdm);
/* Only valid for type == PBVH_BMESH */
struct BMesh *BKE_pbvh_get_bmesh(PBVH *pbvh);
diff --git a/source/blender/blenkernel/intern/CCGSubSurf.c b/source/blender/blenkernel/intern/CCGSubSurf.c
index 792e9195f12..7b74bbcba04 100644
--- a/source/blender/blenkernel/intern/CCGSubSurf.c
+++ b/source/blender/blenkernel/intern/CCGSubSurf.c
@@ -1196,6 +1196,7 @@ int ccgSubSurf_getNumEdges(const CCGSubSurf *ss)
}
int ccgSubSurf_getNumFaces(const CCGSubSurf *ss)
{
+
return ss->fMap->numEntries;
}
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index 258322ea361..028bb6eae02 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -34,6 +34,7 @@
#include "BKE_pbvh.h"
#include "BKE_ccg.h"
+#include "BKE_subsurf.h"
#include "BKE_DerivedMesh.h"
#include "BKE_global.h"
#include "BKE_mesh.h" /* for BKE_mesh_calc_normals */
@@ -606,6 +607,10 @@ void BKE_pbvh_build_grids(PBVH *bvh, CCGElem **grids,
MEM_freeN(prim_bbc);
}
+void BKE_pbvh_add_ccgdm(PBVH *bvh, CCGDerivedMesh *ccgdm) {
+ bvh->ccgdm = ccgdm;
+}
+
PBVH *BKE_pbvh_new(void)
{
PBVH *bvh = MEM_callocN(sizeof(PBVH), "pbvh");
@@ -1327,6 +1332,11 @@ void BKE_pbvh_get_grid_key(const PBVH *bvh, CCGKey *key)
*key = bvh->gridkey;
}
+void BKE_pbvh_get_ccgdm(const PBVH *bvh, struct CCGDerivedMesh **ccgdm) {
+ *ccgdm = bvh->ccgdm;
+}
+
+
BMesh *BKE_pbvh_get_bmesh(PBVH *bvh)
{
BLI_assert(bvh->type == PBVH_BMESH);
diff --git a/source/blender/blenkernel/intern/pbvh_intern.h b/source/blender/blenkernel/intern/pbvh_intern.h
index 19d3b31bd31..01057318568 100644
--- a/source/blender/blenkernel/intern/pbvh_intern.h
+++ b/source/blender/blenkernel/intern/pbvh_intern.h
@@ -149,6 +149,8 @@ struct PBVH {
* objects in sculpt mode with different sizes at the same time, so now storing that common gpu buffer
* in an opaque pointer per pbvh. See T47637. */
struct GridCommonGPUBuffer *grid_common_gpu_buffer;
+ /* The ccgdm is required for CD_ORIGINDEX lookup in vertex paint + multires */
+ struct CCGDerivedMesh *ccgdm;
/* Only used during BVH build and update,
* don't need to remain valid after */
diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c
index 6927bdaa438..e6943f4ba2b 100644
--- a/source/blender/blenkernel/intern/subsurf_ccg.c
+++ b/source/blender/blenkernel/intern/subsurf_ccg.c
@@ -4420,7 +4420,7 @@ static struct PBVH *ccgDM_getPBVH(Object *ob, DerivedMesh *dm)
return NULL;
/* In vwpaint, we always use a grid_pbvh for multires/subsurf */
- grid_pbvh = (!(ob->mode & OB_MODE_SCULPT)) || ccgDM_use_grid_pbvh(ccgdm);
+ grid_pbvh = (!(ob->mode & OB_MODE_SCULPT) || ccgDM_use_grid_pbvh(ccgdm));
if (ob->sculpt->pbvh) {
if (grid_pbvh) {
@@ -4436,8 +4436,12 @@ static struct PBVH *ccgDM_getPBVH(Object *ob, DerivedMesh *dm)
ccgdm->pbvh = ob->sculpt->pbvh;
}
- if (ccgdm->pbvh)
+ if (ccgdm->pbvh) {
+ /* For vertex paint, keep track of ccgdm */
+ if (!(ob->mode & OB_MODE_SCULPT))
+ BKE_pbvh_add_ccgdm(ccgdm->pbvh, ccgdm);
return ccgdm->pbvh;
+ }
/* 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
@@ -4473,6 +4477,10 @@ static struct PBVH *ccgDM_getPBVH(Object *ob, DerivedMesh *dm)
if (ccgdm->pbvh)
pbvh_show_diffuse_color_set(ccgdm->pbvh, ob->sculpt->show_diffuse_color);
+ /* For vertex paint, keep track of ccgdm */
+ if (!(ob->mode & OB_MODE_SCULPT) && ccgdm->pbvh)
+ BKE_pbvh_add_ccgdm(ccgdm->pbvh, ccgdm);
+
return ccgdm->pbvh;
}
diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c
index c6e4d6805ad..21a6c007777 100644
--- a/source/blender/editors/sculpt_paint/paint_vertex.c
+++ b/source/blender/editors/sculpt_paint/paint_vertex.c
@@ -66,6 +66,7 @@
#include "BKE_paint.h"
#include "BKE_report.h"
#include "BKE_colortools.h"
+#include "BKE_subsurf.h"
#include "WM_api.h"
#include "WM_types.h"
@@ -2352,6 +2353,15 @@ static void calc_brushdata_symm(
}
}
+static void get_brush_alpha_data(Scene *scene, SculptSession *ss, Brush *brush,
+ float *brush_size_pressure, float *brush_alpha_value, float *brush_alpha_pressure) {
+ *brush_size_pressure =
+ BKE_brush_size_get(scene, brush) * (BKE_brush_use_size_pressure(scene, brush) ? ss->cache->pressure : 1.0f);
+ *brush_alpha_value = BKE_brush_alpha_get(scene, brush);
+ *brush_alpha_pressure =
+ *brush_alpha_value * (BKE_brush_use_alpha_pressure(scene, brush) ? ss->cache->pressure : 1.0f);
+}
+
static void do_wpaint_brush_blur_task_cb_ex(
void *userdata, void *UNUSED(userdata_chunk), const int n, const int UNUSED(thread_id))
{
@@ -2360,48 +2370,69 @@ static void do_wpaint_brush_blur_task_cb_ex(
Brush *brush = data->brush;
StrokeCache *cache = ss->cache;
- const float bstrength = cache->bstrength;
-
+ Scene *scene = CTX_data_scene(data->C);
+ const float brush_strength = cache->bstrength;
+ float brush_size_pressure, brush_alpha_value, brush_alpha_pressure;
+ get_brush_alpha_data(scene, ss, brush, &brush_size_pressure, &brush_alpha_value, &brush_alpha_pressure);
int total_hit_loops;
+ CCGDerivedMesh *ccgdm = NULL;
+ BKE_pbvh_get_ccgdm(ss->pbvh, &ccgdm);
+ const bool use_face_sel = (data->me->editflag & ME_EDIT_PAINT_FACE_SEL) != 0;
+ const bool use_vert_sel = (data->me->editflag & ME_EDIT_PAINT_VERT_SEL) != 0;
- /* for each vertex */
+ /* For each vertex */
PBVHVertexIter vd;
-
BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE)
{
+ /* Test to see if the vertex coordinates are within the spherical brush region. */
SculptBrushTest test;
sculpt_brush_test_init(ss, &test);
- /* Test to see if the vertex coordinates are within the spherical brush region. */
if (sculpt_brush_test_sq(&test, vd.co)) {
- const int v_index = vd.vert_indices[vd.i];
-
- /* Get the average poly color */
- total_hit_loops = 0;
- float weight_final = 0.0f;
-
- for (int j = 0; j < ss->modes.vwpaint.vert_to_poly[v_index].count; j++) {
- const int p_index = ss->modes.vwpaint.vert_to_poly[v_index].indices[j];
- const MPoly *mp = &data->me->mpoly[p_index];
-
- total_hit_loops += mp->totloop;
- for (int k = 0; k < mp->totloop; k++) {
- const int l_index = mp->loopstart + k;
- const MLoop *ml = &data->me->mloop[l_index];
- MDeformVert *dv = &data->me->dvert[ml->v];
- const MDeformWeight *dw = defvert_verify_index(dv, data->wpi->active.index);
- weight_final += dw->weight;
- }
+ /* For grid based pbvh, take the vert whose loop coopresponds to the current grid.
+ Otherwise, take the current vert. */
+ float grid_alpha = 1.0;
+ int v_index;
+ if (ccgdm) {
+ v_index = data->me->mloop[vd.grid_indices[vd.g]].v;
+ grid_alpha = 1.0 / vd.gridsize;
}
- if (total_hit_loops != 0) {
- const float fade = BKE_brush_curve_strength(brush, sqrtf(test.dist), cache->radius);
- const float view_dot = dot_vf3vs3(cache->sculpt_normal_symm, vd.no);
+ else
+ v_index = vd.vert_indices[vd.i];
+ const char v_flag = data->me->mvert[v_index].flag;
+ /* If the vertex is selected */
+ if (!(use_face_sel || use_vert_sel) || v_flag & SELECT) {
+ /* Get the average poly weight */
+ total_hit_loops = 0;
+ float weight_final = 0.0f;
+ for (int j = 0; j < ss->modes.vwpaint.vert_to_poly[v_index].count; j++) {
+ const int p_index = ss->modes.vwpaint.vert_to_poly[v_index].indices[j];
+ const MPoly *mp = &data->me->mpoly[p_index];
- weight_final /= total_hit_loops;
- if (view_dot > 0.0) {
- do_weight_paint_vertex(
- data->vp, data->ob, data->wpi,
- v_index, view_dot * fade * bstrength, weight_final);
+ total_hit_loops += mp->totloop;
+ for (int k = 0; k < mp->totloop; k++) {
+ const int l_index = mp->loopstart + k;
+ const MLoop *ml = &data->me->mloop[l_index];
+ MDeformVert *dv = &data->me->dvert[ml->v];
+ const MDeformWeight *dw = defvert_verify_index(dv, data->wpi->active.index);
+ weight_final += dw->weight;
+ }
+ }
+
+ /* Apply the weight to the vertex. */
+ if (total_hit_loops != 0) {
+ const float brush_fade = BKE_brush_cur
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list