[Bf-blender-cvs] [f9859a3b2af] temp_bmesh_multires: Got sculpt colors to work, needs more testing
Joseph Eagar
noreply at git.blender.org
Mon Oct 26 06:35:17 CET 2020
Commit: f9859a3b2afbcd82957450aa1b009b8d34a53d60
Author: Joseph Eagar
Date: Sun Oct 25 22:35:02 2020 -0700
Branches: temp_bmesh_multires
https://developer.blender.org/rBf9859a3b2afbcd82957450aa1b009b8d34a53d60
Got sculpt colors to work, needs more testing
===================================================================
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_bmesh.c
M source/blender/blenkernel/intern/pbvh_intern.h
M source/blender/blenlib/intern/BLI_mempool.c
M source/blender/bmesh/intern/bmesh_log.c
M source/blender/editors/sculpt_paint/sculpt.c
M source/blender/editors/sculpt_paint/sculpt_boundary.c
M source/blender/editors/sculpt_paint/sculpt_dyntopo.c
M source/blender/editors/sculpt_paint/sculpt_intern.h
M source/blender/editors/sculpt_paint/sculpt_undo.c
M source/blender/gpu/intern/gpu_buffers.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h
index fe3235bfe5d..74e167019a5 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -525,6 +525,7 @@ typedef struct SculptSession {
struct RegionView3D *rv3d;
struct View3D *v3d;
struct Scene *scene;
+ int cd_origvcol_offset;
int cd_origco_offset;
int cd_origno_offset;
diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h
index fd68a63f5b5..60f0b420864 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -45,6 +45,7 @@ BLI_INLINE SculptVertRef BKE_pbvh_make_vref(intptr_t i)
struct BMLog;
struct BMesh;
+struct BMVert;
struct CCGElem;
struct CCGKey;
struct CustomData;
@@ -212,23 +213,29 @@ void BKE_pbvh_build_bmesh(PBVH *pbvh,
const int cd_vert_node_offset,
const int cd_face_node_offset,
const int cd_origco_offset,
- const int cd_origno_offset);
+ const int cd_origno_offset,
+ const int cd_origvcol_offset);
void BKE_pbvh_update_offsets(PBVH *pbvh,
const int cd_vert_node_offset,
const int cd_face_node_offset,
const int cd_origco_offset,
- const int cd_origno_offset);
+ const int cd_origno_offset,
+ const int cd_origvcol_offset);
void BKE_pbvh_free(PBVH *pbvh);
-/* Hierarchical Search in the BVH, two methods:
- * - for each hit calling a callback
- * - gather nodes in an array (easy to multithread) */
+/** update original data, only data whose r_** parameters are passed in will be updated*/
+void BKE_pbvh_bmesh_update_origvert(
+ PBVH *pbvh, struct BMVert *v, float **r_co, float **r_no, float **r_color);
-void BKE_pbvh_search_callback(PBVH *pbvh,
- BKE_pbvh_SearchCallback scb,
- void *search_data,
- BKE_pbvh_HitCallback hcb,
- void *hit_data);
+ /* Hierarchical Search in the BVH, two methods:
+ * - for each hit calling a callback
+ * - gather nodes in an array (easy to multithread) */
+
+ void BKE_pbvh_search_callback(PBVH *pbvh,
+ BKE_pbvh_SearchCallback scb,
+ void *search_data,
+ BKE_pbvh_HitCallback hcb,
+ void *hit_data);
void BKE_pbvh_search_gather(
PBVH *pbvh, BKE_pbvh_SearchCallback scb, void *search_data, PBVHNode ***array, int *tot);
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index 33a49bb159f..07ac4601bb5 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -1977,7 +1977,8 @@ static PBVH *build_pbvh_for_dynamic_topology(Object *ob)
ob->sculpt->cd_vert_node_offset,
ob->sculpt->cd_face_node_offset,
ob->sculpt->cd_origco_offset,
- ob->sculpt->cd_origno_offset);
+ ob->sculpt->cd_origno_offset,
+ ob->sculpt->cd_origvcol_offset);
pbvh_show_mask_set(pbvh, ob->sculpt->show_mask);
pbvh_show_face_sets_set(pbvh, false);
return pbvh;
@@ -2068,7 +2069,8 @@ PBVH *BKE_sculpt_object_pbvh_ensure(Depsgraph *depsgraph, Object *ob)
if (subdiv_ccg != NULL) {
BKE_sculpt_bvh_update_from_ccg(pbvh, subdiv_ccg);
}
- } else if (BKE_pbvh_type(pbvh) == PBVH_BMESH) {
+ }
+ else if (BKE_pbvh_type(pbvh) == PBVH_BMESH) {
SCULPT_dynamic_topology_sync_layers(ob);
}
return pbvh;
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index 0124564173a..b643564f6b4 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -2259,7 +2259,8 @@ static bool pbvh_grids_node_raycast(PBVH *pbvh,
copy_v3_v3(nearest_vertex_co, co[j]);
*r_active_vertex_index = BKE_pbvh_make_vref(gridkey->grid_area * grid_index +
- (y + y_it[j]) * gridkey->grid_size + (x + x_it[j]));
+ (y + y_it[j]) * gridkey->grid_size +
+ (x + x_it[j]));
}
}
}
@@ -2322,7 +2323,7 @@ bool BKE_pbvh_node_raycast(PBVH *pbvh,
face_normal);
break;
case PBVH_BMESH:
- //BM_mesh_elem_index_ensure(pbvh->bm, BM_VERT);
+ // BM_mesh_elem_index_ensure(pbvh->bm, BM_VERT);
hit = pbvh_bmesh_node_raycast(node,
ray_start,
ray_normal,
@@ -2911,9 +2912,17 @@ void BKE_pbvh_gather_proxies(PBVH *pbvh, PBVHNode ***r_array, int *r_tot)
PBVHColorBufferNode *BKE_pbvh_node_color_buffer_get(PBVHNode *node)
{
+ unsigned int totvert;
+
+ if (node->bm_unique_verts) {
+ totvert = BLI_table_gset_len(node->bm_unique_verts);
+ }
+ else {
+ totvert = node->uniq_verts;
+ }
if (!node->color_buffer.color) {
- node->color_buffer.color = MEM_callocN(sizeof(float[4]) * node->uniq_verts, "Color buffer");
+ node->color_buffer.color = MEM_callocN(sizeof(float[4]) * totvert, "Color buffer");
}
return &node->color_buffer;
}
@@ -2977,7 +2986,9 @@ void pbvh_vertex_iter_init(PBVH *pbvh, PBVHNode *node, PBVHVertexIter *vi, int m
vi->bm_other_verts = node->bm_other_verts;
vi->bm_vdata = &pbvh->bm->vdata;
vi->bm_vert = NULL;
- vi->cd_vcol_offset = CustomData_get_offset(vi->bm_vdata, CD_PROP_COLOR);
+
+ // we ensure pbvh->cd_vcol_offset is up to date here too
+ vi->cd_vcol_offset = pbvh->cd_vcol_offset = CustomData_get_offset(vi->bm_vdata, CD_PROP_COLOR);
vi->cd_vert_mask_offset = CustomData_get_offset(vi->bm_vdata, CD_PAINT_MASK);
}
@@ -3007,7 +3018,8 @@ bool pbvh_has_mask(PBVH *pbvh)
return false;
}
-SculptVertRef BKE_pbvh_table_index_to_vertex(PBVH *pbvh, int idx) {
+SculptVertRef BKE_pbvh_table_index_to_vertex(PBVH *pbvh, int idx)
+{
if (pbvh->type == PBVH_BMESH) {
SculptVertRef ref = {(intptr_t)pbvh->bm->vtable[idx]};
return ref;
diff --git a/source/blender/blenkernel/intern/pbvh_bmesh.c b/source/blender/blenkernel/intern/pbvh_bmesh.c
index 7cc9246cb9a..f45eb2e0a53 100644
--- a/source/blender/blenkernel/intern/pbvh_bmesh.c
+++ b/source/blender/blenkernel/intern/pbvh_bmesh.c
@@ -1784,15 +1784,42 @@ static void pbvh_bmesh_collapse_edge(PBVH *pbvh,
BM_vert_kill(pbvh->bm, v_del);
}
-void BKE_pbvh_bmesh_update_origvert(PBVH *pbvh, BMVert *v)
+void BKE_pbvh_bmesh_update_origvert(
+ PBVH *pbvh, BMVert *v, float **r_co, float **r_no, float **r_color)
{
- BM_log_vert_before_modified(pbvh->bm_log, v, pbvh->cd_vert_mask_offset);
+ float *co = NULL, *no = NULL;
- float *co = BM_ELEM_CD_GET_VOID_P(v, pbvh->cd_origco_offset);
- float *no = BM_ELEM_CD_GET_VOID_P(v, pbvh->cd_origno_offset);
+ if (r_co || r_no) {
+ BM_log_vert_before_modified(pbvh->bm_log, v, pbvh->cd_vert_mask_offset);
- copy_v3_v3(co, v->co);
- copy_v3_v3(no, v->no);
+ co = BM_ELEM_CD_GET_VOID_P(v, pbvh->cd_origco_offset);
+ no = BM_ELEM_CD_GET_VOID_P(v, pbvh->cd_origno_offset);
+
+ copy_v3_v3(co, v->co);
+ copy_v3_v3(no, v->no);
+
+ if (r_co) {
+ *r_co = co;
+ }
+
+ if (r_no) {
+ *r_no = no;
+ }
+ }
+
+ if (r_color && pbvh->cd_vcol_offset >= 0 && pbvh->cd_origvcol_offset >= 0) {
+ MPropCol *ml1 = BM_ELEM_CD_GET_VOID_P(v, pbvh->cd_vcol_offset);
+ MPropCol *ml2 = BM_ELEM_CD_GET_VOID_P(v, pbvh->cd_origvcol_offset);
+
+ copy_v4_v4(ml2->color, ml1->color);
+
+ if (r_color) {
+ *r_color = ml2->color;
+ }
+ }
+ else if (r_color) {
+ *r_color = NULL;
+ }
}
static bool pbvh_bmesh_collapse_short_edges(EdgeQueueContext *eq_ctx,
@@ -2268,13 +2295,15 @@ void BKE_pbvh_build_bmesh(PBVH *pbvh,
const int cd_vert_node_offset,
const int cd_face_node_offset,
const int cd_origco_offset,
- const int cd_origno_offset)
+ const int cd_origno_offset,
+ const int cd_origvcol_offset)
{
pbvh->cd_vert_node_offset = cd_vert_node_offset;
pbvh->cd_face_node_offset = cd_face_node_offset;
pbvh->cd_origco_offset = cd_origco_offset;
pbvh->cd_origno_offset = cd_origno_offset;
pbvh->cd_vert_mask_offset = CustomData_get_offset(&bm->vdata, CD_PAINT_MASK);
+ pbvh->cd_origvcol_offset = cd_origvcol_offset;
pbvh->bm = bm;
@@ -2282,6 +2311,7 @@ void BKE_pbvh_build_bmesh(PBVH *pbvh,
pbvh->type = PBVH_BMESH;
pbvh->bm_log = log;
+ pbvh->cd_vcol_offset = CustomData_get_offset(&bm->vdata, CD_PROP_COLOR);
/* TODO: choose leaf limit better */
pbvh->leaf_limit = 3000;
@@ -3141,11 +3171,13 @@ void BKE_pbvh_update_offsets(PBVH *pbvh,
const int cd_vert_node_offset,
const int cd_face_node_offset,
const int cd_origco_offset,
- const int cd_origno_offset)
+ const int cd_origno_offset,
+ const int cd_origvcol_offset)
{
pbvh->cd_face_node_offset = cd_face_node_offset;
pbvh->cd_vert_node_offset = cd_vert_node_offset;
pbvh->cd_vert_mask_offset = CustomData_get_offset(&pbvh->bm->vdata, CD_PAINT_MASK);
pbvh->cd_origco_offset = cd_origco_offset;
pbvh->cd_origno_offset = cd_origno_offset;
+ pbvh->cd_origvcol_offset = cd_origvcol_offset;
}
diff --git a/source/blender/blenkernel/intern/pbvh_intern.h b/source/blender/blenkernel/intern/pbvh_intern.h
index 284d2571669..797ae7d8f0f 100644
--- a/source/blender/blenkernel/intern/pbvh_intern.h
+++ b/source/blend
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list