[Bf-blender-cvs] [4b308888d8a] temp_bmesh_multires: Add support for sculpt colors to the data transfer modifier
Joseph Eagar
noreply at git.blender.org
Sun Apr 4 04:23:32 CEST 2021
Commit: 4b308888d8a14f94f8bb1709867ce4352083c723
Author: Joseph Eagar
Date: Sat Apr 3 19:23:15 2021 -0700
Branches: temp_bmesh_multires
https://developer.blender.org/rB4b308888d8a14f94f8bb1709867ce4352083c723
Add support for sculpt colors to the data transfer modifier
===================================================================
M source/blender/blenkernel/BKE_data_transfer.h
M source/blender/blenkernel/BKE_pbvh.h
M source/blender/blenkernel/intern/data_transfer.c
M source/blender/blenkernel/intern/pbvh.c
M source/blender/blenkernel/intern/pbvh_intern.h
M source/blender/editors/sculpt_paint/sculpt.c
M source/blender/editors/sculpt_paint/sculpt_undo.c
M source/blender/makesrna/intern/rna_modifier.c
M source/blender/modifiers/intern/MOD_datatransfer.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_data_transfer.h b/source/blender/blenkernel/BKE_data_transfer.h
index d861baba14d..f8133b4da87 100644
--- a/source/blender/blenkernel/BKE_data_transfer.h
+++ b/source/blender/blenkernel/BKE_data_transfer.h
@@ -54,9 +54,11 @@ enum {
DT_TYPE_UV = 1 << 24,
DT_TYPE_SHARP_FACE = 1 << 25,
DT_TYPE_FREESTYLE_FACE = 1 << 26,
-#define DT_TYPE_MAX 27
+ DT_TYPE_PROPCOL = 1 << 27,
+#define DT_TYPE_MAX 28
- DT_TYPE_VERT_ALL = DT_TYPE_MDEFORMVERT | DT_TYPE_SHAPEKEY | DT_TYPE_SKIN | DT_TYPE_BWEIGHT_VERT,
+ DT_TYPE_VERT_ALL = DT_TYPE_MDEFORMVERT | DT_TYPE_SHAPEKEY | DT_TYPE_SKIN | DT_TYPE_BWEIGHT_VERT |
+ DT_TYPE_PROPCOL,
DT_TYPE_EDGE_ALL = DT_TYPE_SHARP_EDGE | DT_TYPE_SEAM | DT_TYPE_CREASE | DT_TYPE_BWEIGHT_EDGE |
DT_TYPE_FREESTYLE_EDGE,
DT_TYPE_LOOP_ALL = DT_TYPE_VCOL | DT_TYPE_LNOR | DT_TYPE_UV,
@@ -74,7 +76,7 @@ int BKE_object_data_transfer_dttype_to_cdtype(const int dtdata_type);
int BKE_object_data_transfer_dttype_to_srcdst_index(const int dtdata_type);
#define DT_DATATYPE_IS_VERT(_dt) \
- ELEM(_dt, DT_TYPE_MDEFORMVERT, DT_TYPE_SHAPEKEY, DT_TYPE_SKIN, DT_TYPE_BWEIGHT_VERT)
+ ELEM(_dt, DT_TYPE_MDEFORMVERT, DT_TYPE_SHAPEKEY, DT_TYPE_SKIN, DT_TYPE_BWEIGHT_VERT, DT_TYPE_PROPCOL)
#define DT_DATATYPE_IS_EDGE(_dt) \
ELEM(_dt, \
DT_TYPE_CREASE, \
@@ -94,7 +96,8 @@ enum {
DT_MULTILAYER_INDEX_SHAPEKEY = 1,
DT_MULTILAYER_INDEX_VCOL = 2,
DT_MULTILAYER_INDEX_UV = 3,
- DT_MULTILAYER_INDEX_MAX = 4,
+ DT_MULTILAYER_INDEX_PROPCOL = 4,
+ DT_MULTILAYER_INDEX_MAX = 5,
};
/* Below we keep positive values for real layers idx (generated dynamically). */
diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h
index b5a7965161a..efb417f806f 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -175,7 +175,7 @@ typedef enum {
PBVH_UpdateTopology = 1 << 13,
PBVH_UpdateColor = 1 << 14,
PBVH_Delete = 1 << 15,
- PBVH_UpdateCurvatureDir = 1<<16
+ PBVH_UpdateCurvatureDir = 1 << 16
} PBVHNodeFlags;
typedef struct PBVHFrustumPlanes {
@@ -648,6 +648,7 @@ PBVHColorBufferNode *BKE_pbvh_node_color_buffer_get(PBVHNode *node);
void BKE_pbvh_node_color_buffer_free(PBVH *pbvh);
int BKE_pbvh_get_node_index(PBVH *pbvh, PBVHNode *node);
+int BKE_pbvh_get_node_id(PBVH *pbvh, PBVHNode *node);
void BKE_pbvh_set_flat_vcol_shading(PBVH *pbvh, bool value);
#define DYNTOPO_CD_INTERP
diff --git a/source/blender/blenkernel/intern/data_transfer.c b/source/blender/blenkernel/intern/data_transfer.c
index 2bf58d9e764..7bcb8607a4e 100644
--- a/source/blender/blenkernel/intern/data_transfer.c
+++ b/source/blender/blenkernel/intern/data_transfer.c
@@ -150,6 +150,7 @@ bool BKE_object_data_transfer_get_dttypes_capacity(const int dtdata_types,
case DT_TYPE_UV:
ret = true;
break;
+ case DT_TYPE_PROPCOL:
case DT_TYPE_VCOL:
*r_advanced_mixing = true;
*r_threshold = true;
@@ -230,12 +231,12 @@ int BKE_object_data_transfer_dttype_to_cdtype(const int dtdata_type)
return CD_FAKE_SHARP;
case DT_TYPE_FREESTYLE_FACE:
return CD_FREESTYLE_FACE;
-
case DT_TYPE_VCOL:
return CD_MLOOPCOL;
case DT_TYPE_LNOR:
return CD_FAKE_LNOR;
-
+ case DT_TYPE_PROPCOL:
+ return CD_PROP_COLOR;
default:
BLI_assert(0);
}
@@ -253,6 +254,8 @@ int BKE_object_data_transfer_dttype_to_srcdst_index(const int dtdata_type)
return DT_MULTILAYER_INDEX_UV;
case DT_TYPE_VCOL:
return DT_MULTILAYER_INDEX_VCOL;
+ case DT_TYPE_PROPCOL:
+ return DT_MULTILAYER_INDEX_PROPCOL;
default:
return DT_MULTILAYER_INDEX_INVALID;
}
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index acde53509ae..a890634e158 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -249,6 +249,14 @@ void pbvh_grow_nodes(PBVH *pbvh, int totnode)
}
pbvh->totnode = totnode;
+
+ for (int i=0; i<pbvh->totnode; i++) {
+ PBVHNode *node = pbvh->nodes + i;
+
+ if (!node->id) {
+ node->id = ++pbvh->idgen;
+ }
+ }
}
/* Add a vertex to the map, with a positive value for unique vertices and
@@ -1472,7 +1480,7 @@ void BKE_pbvh_update_origcolor_bmesh(PBVH *pbvh, PBVHNode *node)
return;
}
- BKE_pbvh_vertex_iter_begin (pbvh, node, vd, PBVH_ITER_ALL) {
+ BKE_pbvh_vertex_iter_begin (pbvh, node, vd, PBVH_ITER_UNIQUE) {
MDynTopoVert *mv = BKE_PBVH_DYNVERT(pbvh->cd_dyn_vert, vd.bm_vert);
float *c2 = BM_ELEM_CD_GET_VOID_P(vd.bm_vert, pbvh->cd_vcol_offset);
@@ -1489,7 +1497,7 @@ void BKE_pbvh_update_origco_bmesh(PBVH *pbvh, PBVHNode *node)
return;
}
- BKE_pbvh_vertex_iter_begin (pbvh, node, vd, PBVH_ITER_ALL) {
+ BKE_pbvh_vertex_iter_begin (pbvh, node, vd, PBVH_ITER_UNIQUE) {
MDynTopoVert *mv = BKE_PBVH_DYNVERT(pbvh->cd_dyn_vert, vd.bm_vert);
copy_v3_v3(mv->origco, vd.bm_vert->co);
@@ -2997,7 +3005,7 @@ void BKE_pbvh_node_free_proxies(PBVHNode *node)
node->proxies[p].co = NULL;
}
- MEM_freeN(node->proxies);
+ MEM_SAFE_FREE(node->proxies);
node->proxies = NULL;
node->proxy_count = 0;
@@ -3232,6 +3240,11 @@ int BKE_pbvh_get_node_index(PBVH *pbvh, PBVHNode *node)
return (int)(node - pbvh->nodes);
}
+int BKE_pbvh_get_node_id(PBVH *pbvh, PBVHNode *node)
+{
+ return node->id;
+}
+
void BKE_pbvh_get_nodes(PBVH *pbvh, int flag, PBVHNode ***r_array, int *r_totnode)
{
BKE_pbvh_search_gather(pbvh, update_search_cb, POINTER_FROM_INT(flag), r_array, r_totnode);
diff --git a/source/blender/blenkernel/intern/pbvh_intern.h b/source/blender/blenkernel/intern/pbvh_intern.h
index 3e0dbf0bce5..3a68520c9ba 100644
--- a/source/blender/blenkernel/intern/pbvh_intern.h
+++ b/source/blender/blenkernel/intern/pbvh_intern.h
@@ -38,6 +38,8 @@ struct PBVHNode {
/* Opaque handle for drawing code */
struct GPU_PBVH_Buffers *draw_buffers;
+ int id;
+
/* Voxel bounds */
BB vb;
BB orig_vb;
@@ -125,6 +127,8 @@ struct PBVH {
PBVHType type;
PBVHFlags flags;
+ int idgen;
+
PBVHNode *nodes;
int node_mem_count, totnode;
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index 3c1e75b4bb2..38ad6c7e48a 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -6409,9 +6409,25 @@ static void do_brush_action(Sculpt *sd, Object *ob, Brush *brush, UnifiedPaintSe
BKE_pbvh_node_mark_update(nodes[i]);
}
}
+ else if (brush->sculpt_tool == SCULPT_TOOL_ELASTIC_DEFORM) {
+ PBVHNode **nodes2;
+ int totnode2 = 0;
+
+ BKE_pbvh_get_nodes(ss->pbvh, PBVH_Leaf, &nodes2, &totnode2);
+
+ for (int i = 0; i < totnode2; i++) {
+ if (SCULPT_ensure_dyntopo_node_undo(ob, nodes2[i], SCULPT_UNDO_COORDS, -1)) {
+ BKE_pbvh_update_origco_bmesh(ss->pbvh, nodes2[i]);
+ BKE_pbvh_node_free_proxies(nodes2[i]);
+ }
+ BKE_pbvh_node_mark_update(nodes2[i]);
+ }
+ }
else {
for (int i = 0; i < totnode; i++) {
- SCULPT_ensure_dyntopo_node_undo(ob, nodes[i], SCULPT_UNDO_COORDS, -1);
+ if (SCULPT_ensure_dyntopo_node_undo(ob, nodes[i], SCULPT_UNDO_COORDS, -1)) {
+ // BKE_pbvh_update_origco_bmesh(ss->pbvh, nodes[i]);
+ }
BKE_pbvh_node_mark_update(nodes[i]);
}
}
diff --git a/source/blender/editors/sculpt_paint/sculpt_undo.c b/source/blender/editors/sculpt_paint/sculpt_undo.c
index 134766c84cd..cdff1610e2f 100644
--- a/source/blender/editors/sculpt_paint/sculpt_undo.c
+++ b/source/blender/editors/sculpt_paint/sculpt_undo.c
@@ -1327,7 +1327,7 @@ static SculptUndoNode *sculpt_undo_bmesh_push(Object *ob, PBVHNode *node, Sculpt
case SCULPT_UNDO_MASK:
/* Before any vertex values get modified, ensure their
* original positions are logged. */
- BKE_pbvh_vertex_iter_begin (ss->pbvh, node, vd, PBVH_ITER_ALL) {
+ BKE_pbvh_vertex_iter_begin (ss->pbvh, node, vd, PBVH_ITER_UNIQUE) {
float *dummy;
BKE_pbvh_bmesh_update_origvert(ss->pbvh, vd.bm_vert, &dummy, &dummy, &dummy);
// BM_log_vert_before_modified(ss->bm_log, vd.bm_vert, vd.cd_vert_mask_offset, false);
@@ -1339,7 +1339,7 @@ static SculptUndoNode *sculpt_undo_bmesh_push(Object *ob, PBVHNode *node, Sculpt
TableGSet *faces = BKE_pbvh_bmesh_node_faces(node);
BMFace *f;
- BKE_pbvh_vertex_iter_begin (ss->pbvh, node, vd, PBVH_ITER_ALL) {
+ BKE_pbvh_vertex_iter_begin (ss->pbvh, node, vd, PBVH_ITER_UNIQUE) {
BM_log_vert_before_modified(ss->bm_log, vd.bm_vert, vd.cd_vert_mask_offset, true);
// BKE_pbvh_bmesh_update_origvert(ss->pbvh, vd.bm_vert, &dummy, &dummy, &dummy);
}
@@ -1354,7 +1354,7 @@ static SculptUndoNode *sculpt_undo_bmesh_push(Object *ob, PBVHNode *node, Sculpt
case SCULPT_UNDO_COLOR: {
#if 1
- BKE_pbvh_vertex_iter_begin (ss->pbvh, node, vd, PBVH_ITER_ALL) {
+ BKE_pbvh_vertex_iter_begin (ss->pbvh, node, vd, PBVH_ITER_UNIQUE) {
float *dummy;
BKE_pbvh_bmesh_update_origvert(ss->pbvh, vd.bm_vert, NULL, NULL, &dummy);
}
@@ -1409,7 +1409,7 @@ bool SCULPT_ensure_dyntopo_node_undo(Object *ob,
return SCULPT_ensure_dyntopo_node_undo(ob, node, type, extraType);
}
- int n = BKE_pbvh_get_node_index(ss->pbvh, node);
+ int n = BKE_pbvh_get_node_id(ss->pbvh, node);
if (unode->nodemap_size <= n) {
int newsize = (n + 1) * 2;
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index c78babf2ba5..8af4581dfa2 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -6386,6 +6386,7 @@ static void rna_def_modifier_datatransfer(BlenderRNA *brna)
# if 0
{DT_TYPE_SKIN, "SKIN", 0, "Skin Weight", "Transfer skin weights"},
# endif
+ {DT_TYPE_PROPCOL, "PROPCOL", 0, "Sculpt Colors", "Transfer sculpt colors"},
{DT_TYPE_BWEIGHT_VERT, "BEVEL_WEIGHT_VERT", 0, "Bevel Weight", "Transfer
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list