[Bf-blender-cvs] [5385455e6a1] temp_bmesh_multires: Fixed undo bugs caused by SculptVertRef refactor. I need to figure out the right way to make assigning a pointer to a SculptVertRef to an int* spit out a compiler error.
Joseph Eagar
noreply at git.blender.org
Wed Dec 23 07:48:33 CET 2020
Commit: 5385455e6a17b17f4fb31bb412eccc96a9ecad8f
Author: Joseph Eagar
Date: Tue Dec 22 22:47:50 2020 -0800
Branches: temp_bmesh_multires
https://developer.blender.org/rB5385455e6a17b17f4fb31bb412eccc96a9ecad8f
Fixed undo bugs caused by SculptVertRef refactor. I need to figure out
the right way to make assigning a pointer to a SculptVertRef to an int*
spit out a compiler error.
===================================================================
M source/blender/editors/sculpt_paint/sculpt.c
M source/blender/editors/sculpt_paint/sculpt_automasking.c
M source/blender/editors/sculpt_paint/sculpt_intern.h
M source/blender/editors/sculpt_paint/sculpt_paint_color.c
M source/blender/editors/sculpt_paint/sculpt_undo.c
===================================================================
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index bf55d6a323e..de0ad706801 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -6203,9 +6203,8 @@ static void sculpt_topology_update(Sculpt *sd,
}
}
-static void do_brush_action_task_cb(void *__restrict userdata,
- const int n,
- const TaskParallelTLS *__restrict UNUSED(tls))
+__attribute__((optnone)) static void do_brush_action_task_cb(
+ void *__restrict userdata, const int n, const TaskParallelTLS *__restrict UNUSED(tls))
{
SculptThreadedTaskData *data = userdata;
SculptSession *ss = data->ob->sculpt;
diff --git a/source/blender/editors/sculpt_paint/sculpt_automasking.c b/source/blender/editors/sculpt_paint/sculpt_automasking.c
index 2c4ddba089c..e3bfdff90d1 100644
--- a/source/blender/editors/sculpt_paint/sculpt_automasking.c
+++ b/source/blender/editors/sculpt_paint/sculpt_automasking.c
@@ -164,7 +164,7 @@ float SCULPT_automasking_factor_get(AutomaskingCache *automasking,
mask = 1.0 - mask;
}
- mask = pow(mask*1.5f, (1.0f + automasking->settings.concave_factor) * 8.0);
+ mask = pow(mask*1.5f, (0.5f + automasking->settings.concave_factor) * 8.0);
CLAMP(mask, 0.0f, 1.0f);
}
diff --git a/source/blender/editors/sculpt_paint/sculpt_intern.h b/source/blender/editors/sculpt_paint/sculpt_intern.h
index b6cae9f8a9a..4955724512c 100644
--- a/source/blender/editors/sculpt_paint/sculpt_intern.h
+++ b/source/blender/editors/sculpt_paint/sculpt_intern.h
@@ -676,6 +676,7 @@ typedef struct SculptUndoNode {
int nodemap_size;
size_t undo_size;
+ //int gen, lasthash;
} SculptUndoNode;
/* Factor of brush to have rake point following behind
diff --git a/source/blender/editors/sculpt_paint/sculpt_paint_color.c b/source/blender/editors/sculpt_paint/sculpt_paint_color.c
index 9d5624196ea..bb8acd92b11 100644
--- a/source/blender/editors/sculpt_paint/sculpt_paint_color.c
+++ b/source/blender/editors/sculpt_paint/sculpt_paint_color.c
@@ -122,7 +122,6 @@ static void do_paint_brush_task_cb_ex(void *__restrict userdata,
PBVHVertexIter vd;
PBVHColorBufferNode *color_buffer;
-
SculptOrigVertData orig_data;
SCULPT_orig_vert_data_init(&orig_data, data->ob, data->nodes[n], SCULPT_UNDO_COLOR);
orig_data.datatype = SCULPT_UNDO_COLOR;
diff --git a/source/blender/editors/sculpt_paint/sculpt_undo.c b/source/blender/editors/sculpt_paint/sculpt_undo.c
index 4b29b95763f..cd2e82dc722 100644
--- a/source/blender/editors/sculpt_paint/sculpt_undo.c
+++ b/source/blender/editors/sculpt_paint/sculpt_undo.c
@@ -183,7 +183,9 @@ static bool sculpt_undo_restore_deformed(
return false;
}
-__attribute__((optnone)) static bool sculpt_undo_restore_coords(bContext *C, Depsgraph *depsgraph, SculptUndoNode *unode)
+__attribute__((optnone)) static bool sculpt_undo_restore_coords(bContext *C,
+ Depsgraph *depsgraph,
+ SculptUndoNode *unode)
{
ViewLayer *view_layer = CTX_data_view_layer(C);
Object *ob = OBACT(view_layer);
@@ -325,7 +327,7 @@ static bool sculpt_undo_restore_hidden(bContext *C, SculptUndoNode *unode)
return true;
}
-static bool sculpt_undo_restore_color(bContext *C, SculptUndoNode *unode)
+__attribute__((optnone)) static bool sculpt_undo_restore_color(bContext *C, SculptUndoNode *unode)
{
ViewLayer *view_layer = CTX_data_view_layer(C);
Object *ob = OBACT(view_layer);
@@ -333,13 +335,13 @@ static bool sculpt_undo_restore_color(bContext *C, SculptUndoNode *unode)
if (unode->maxvert) {
/* regular mesh restore */
- int *index = unode->index;
+ SculptVertRef *index = unode->index;
MVert *mvert = ss->mvert;
MPropCol *vcol = ss->vcol;
for (int i = 0; i < unode->totvert; i++) {
- swap_v4_v4(vcol[index[i]].color, unode->col[i]);
- mvert[index[i]].flag |= ME_VERT_PBVH_UPDATE;
+ swap_v4_v4(vcol[index[i].i].color, unode->col[i]);
+ mvert[index[i].i].flag |= ME_VERT_PBVH_UPDATE;
}
}
return true;
@@ -353,7 +355,7 @@ static bool sculpt_undo_restore_mask(bContext *C, SculptUndoNode *unode)
SubdivCCG *subdiv_ccg = ss->subdiv_ccg;
MVert *mvert;
float *vmask;
- int *index;
+ SculptVertRef *index;
if (unode->maxvert) {
/* Regular mesh restore. */
@@ -363,9 +365,9 @@ static bool sculpt_undo_restore_mask(bContext *C, SculptUndoNode *unode)
vmask = ss->vmask;
for (int i = 0; i < unode->totvert; i++) {
- if (vmask[index[i]] != unode->mask[i]) {
- SWAP(float, vmask[index[i]], unode->mask[i]);
- mvert[index[i]].flag |= ME_VERT_PBVH_UPDATE;
+ if (vmask[index[i].i] != unode->mask[i]) {
+ SWAP(float, vmask[index[i].i], unode->mask[i]);
+ mvert[index[i].i].flag |= ME_VERT_PBVH_UPDATE;
}
}
}
@@ -624,9 +626,7 @@ static int sculpt_undo_bmesh_restore(bContext *C,
return false;
}
-static void sculpt_undo_restore_list(bContext *C,
- Depsgraph *depsgraph,
- ListBase *lb)
+static void sculpt_undo_restore_list(bContext *C, Depsgraph *depsgraph, ListBase *lb)
{
Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
@@ -921,6 +921,27 @@ static bool sculpt_undo_cleanup(bContext *C, ListBase *lb)
}
#endif
+static int hash_sculpt_colors(SculptUndoNode *node)
+{
+ if (!node->col) {
+ return -1;
+ }
+
+ int i = 0;
+ int hash = 0;
+
+ for (i = 0; i < node->totvert; i++) {
+ float *col = node->col[i];
+
+ for (int j = 0; j < 4; j++) {
+ hash = hash ^ (int)(col[j] * 2048.0f * 2048.0f);
+ hash += (1 << 23) - 1;
+ }
+ }
+
+ return hash;
+}
+
SculptUndoNode *SCULPT_undo_get_node(PBVHNode *node, SculptUndoType type)
{
UndoSculpt *usculpt = sculpt_undo_get_nodes();
@@ -1044,13 +1065,13 @@ static SculptUndoNode *sculpt_undo_alloc_node(Object *ob, PBVHNode *node, Sculpt
case SCULPT_UNDO_MASK:
unode->mask = MEM_callocN(sizeof(float) * allvert, "SculptUndoNode.mask");
- usculpt->undo_size += (sizeof(float) * sizeof(int)) * allvert;
+ usculpt->undo_size += (sizeof(float) + sizeof(int)) * allvert;
break;
case SCULPT_UNDO_COLOR:
unode->col = MEM_callocN(sizeof(MPropCol) * allvert, "SculptUndoNode.col");
- usculpt->undo_size += (sizeof(MPropCol) * sizeof(int)) * allvert;
+ usculpt->undo_size += (sizeof(MPropCol) + sizeof(int)) * allvert;
break;
case SCULPT_UNDO_DYNTOPO_BEGIN:
@@ -1149,6 +1170,8 @@ static void sculpt_undo_store_color(Object *ob, SculptUndoNode *unode)
SculptSession *ss = ob->sculpt;
PBVHVertexIter vd;
+ //unode->gen++;
+
BKE_pbvh_vertex_iter_begin(ss->pbvh, unode->node, vd, PBVH_ITER_ALL)
{
copy_v4_v4(unode->col[vd.i], vd.col);
@@ -1369,7 +1392,9 @@ bool SCULPT_ensure_dyntopo_node_undo(Object *ob,
return true;
}
-SculptUndoNode *SCULPT_undo_push_node(Object *ob, PBVHNode *node, SculptUndoType type)
+__attribute__((optnone)) SculptUndoNode *SCULPT_undo_push_node(Object *ob,
+ PBVHNode *node,
+ SculptUndoType type)
{
SculptSession *ss = ob->sculpt;
SculptUndoNode *unode;
@@ -1383,20 +1408,24 @@ SculptUndoNode *SCULPT_undo_push_node(Object *ob, PBVHNode *node, SculptUndoType
/* Dynamic topology stores only one undo node per stroke,
* regardless of the number of PBVH nodes modified. */
unode = sculpt_undo_bmesh_push(ob, node, type);
+ sculpt_undo_print_nodes(NULL);
BLI_thread_unlock(LOCK_CUSTOM1);
return unode;
}
if (type == SCULPT_UNDO_GEOMETRY) {
unode = sculpt_undo_geometry_push(ob, type);
+ sculpt_undo_print_nodes(NULL);
BLI_thread_unlock(LOCK_CUSTOM1);
return unode;
}
if (type == SCULPT_UNDO_FACE_SETS) {
unode = sculpt_undo_face_sets_push(ob, type);
+ sculpt_undo_print_nodes(NULL);
BLI_thread_unlock(LOCK_CUSTOM1);
return unode;
}
if ((unode = SCULPT_undo_get_node(node, type))) {
+ sculpt_undo_print_nodes(NULL);
BLI_thread_unlock(LOCK_CUSTOM1);
return unode;
}
@@ -1419,10 +1448,10 @@ SculptUndoNode *SCULPT_undo_push_node(Object *ob, PBVHNode *node, SculptUndoType
BKE_pbvh_node_num_verts(ss->pbvh, node, NULL, &allvert);
BKE_pbvh_node_get_verts(ss->pbvh, node, &vert_indices, NULL);
- for (int i=0; i<unode->totvert; i++) {
+ for (int i = 0; i < unode->totvert; i++) {
unode->index[i].i = vert_indices[i];
}
- //memcpy(unode->index, vert_indices, sizeof(int) * unode->totvert);
+ // memcpy(unode->index, vert_indices, sizeof(int) * unode->totvert);
}
switch (type) {
@@ -1833,6 +1862,49 @@ static char *undo_type_to_str(int type)
static int nodeidgen = 1;
+static void print_sculpt_node(SculptUndoNode *node)
+{
+ int hash = hash_sculpt_colors(node);
+
+ //if (node->lasthash == 0) {
+ // node->lasthash = hash;
+ // }
+
+ printf(" %s:%s {applied=%d gen=%d hash=%d}\n",
+ undo_type_to_str(node->type),
+ node->idname,
+ node->applied,
+ 0, //node->gen,
+ hash /*- node->lasthash*/);
+}
+
+static void print_sculpt_undo_step(UndoStep *us, UndoStep *active, int i)
+{
+ SculptUndoNode *node;
+
+ if (us->type != BKE_UNDOSYS_TYPE_SCULPT) {
+ return;
+ }
+
+ int id = -1;
+
+ SculptUndoStep *su = (SculptUndoStep *)us;
+ if (!su->id) {
+ su->id = nodeidgen++;
+ }
+
+ id = su->id;
+
+ printf("id=%d %s %d %s\n", id, us == active ? "->" : " ", i, us->name);
+
+ if (us->type == BKE_UNDOSYS_TYPE_SCULPT) {
+ UndoSculpt *usculpt = sculpt_undosys_step_get_nodes(us);
+
+ for (node = usculpt->nodes.first; node; node = node->next) {
+ print_sculpt_node(node);
+ }
+ }
+}
void sculpt_undo_print_nodes(void *active)
{
#if 0
@@ -1849,33 +1921,20 @@ void sculpt_undo_print_nodes(void *active)
}
printf("\n");
+ if
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list