diff options
author | Antony Riakiotakis <kalast@gmail.com> | 2014-04-16 06:31:02 +0400 |
---|---|---|
committer | Antony Riakiotakis <kalast@gmail.com> | 2014-04-16 06:31:02 +0400 |
commit | 556590fa3a9757f5ee21d923ce38471c343495b7 (patch) | |
tree | 7f6904650d4414ef0deb478a41b309365890bc8b /source/blender/editors | |
parent | b179647d52ae17eb9af243f0307398146ac2744d (diff) |
Dyntopo:
Store PBVH node ID in CustomData. This avoids a number of hash deletions
and checks/insertions on big hashes.
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/sculpt_paint/sculpt.c | 22 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/sculpt_intern.h | 2 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/sculpt_undo.c | 5 |
3 files changed, 27 insertions, 2 deletions
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index 290acc49a8e..db500e00b75 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -4793,6 +4793,26 @@ void sculpt_pbvh_clear(Object *ob) BKE_object_free_derived_caches(ob); } +void sculpt_dyntopo_node_layers_reset(BMesh *bm) +{ + /* A bit lame, but for now just recreate the PBVH. The alternative + * is to store changes to the PBVH in the undo stack. */ + BMFace *f; + BMVert *v; + BMIter iter; + const int cd_vert_node_offset = CustomData_get_offset(&bm->vdata, CD_DYNTOPO_NODE); + const int cd_face_node_offset = CustomData_get_offset(&bm->pdata, CD_DYNTOPO_NODE); + + /* clear the elements of the node information */ + BM_ITER_MESH(v, &iter, bm, BM_VERTS_OF_MESH) { + BM_ELEM_CD_SET_INT(v, cd_vert_node_offset, DYNTOPO_NODE_NONE); + } + + BM_ITER_MESH(f, &iter, bm, BM_FACES_OF_MESH) { + BM_ELEM_CD_SET_INT(f, cd_face_node_offset, DYNTOPO_NODE_NONE); + } +} + void sculpt_update_after_dynamic_topology_toggle(bContext *C) { Scene *scene = CTX_data_scene(C); @@ -4825,6 +4845,8 @@ void sculpt_dynamic_topology_enable(bContext *C) BM_mesh_bm_from_me(ss->bm, me, true, true, ob->shapenr); sculpt_dynamic_topology_triangulate(ss->bm); BM_data_layer_add(ss->bm, &ss->bm->vdata, CD_PAINT_MASK); + BM_data_layer_add(ss->bm, &ss->bm->vdata, CD_DYNTOPO_NODE); + BM_data_layer_add(ss->bm, &ss->bm->pdata, CD_DYNTOPO_NODE); BM_mesh_normals_update(ss->bm); /* Enable dynamic topology */ diff --git a/source/blender/editors/sculpt_paint/sculpt_intern.h b/source/blender/editors/sculpt_paint/sculpt_intern.h index 9c0e937c35c..79fd388e332 100644 --- a/source/blender/editors/sculpt_paint/sculpt_intern.h +++ b/source/blender/editors/sculpt_paint/sculpt_intern.h @@ -42,6 +42,7 @@ struct bContext; struct Brush; +struct BMesh; struct KeyBlock; struct Mesh; struct MultiresModifierData; @@ -67,6 +68,7 @@ bool sculpt_stroke_get_location(bContext *C, float out[3], const float mouse[2]) /* Dynamic topology */ void sculpt_pbvh_clear(Object *ob); +void sculpt_dyntopo_node_layers_reset(struct BMesh *bm); void sculpt_update_after_dynamic_topology_toggle(bContext *C); void sculpt_dynamic_topology_enable(struct bContext *C); void sculpt_dynamic_topology_disable(struct bContext *C, diff --git a/source/blender/editors/sculpt_paint/sculpt_undo.c b/source/blender/editors/sculpt_paint/sculpt_undo.c index 724d093a48f..b0fd7faa70d 100644 --- a/source/blender/editors/sculpt_paint/sculpt_undo.c +++ b/source/blender/editors/sculpt_paint/sculpt_undo.c @@ -301,8 +301,7 @@ static void sculpt_undo_bmesh_restore_generic(bContext *C, MEM_freeN(nodes); } else { - /* A bit lame, but for now just recreate the PBVH. The alternative - * is to store changes to the PBVH in the undo stack. */ + sculpt_dyntopo_node_layers_reset(ss->bm); sculpt_pbvh_clear(ob); } } @@ -319,6 +318,8 @@ static void sculpt_undo_bmesh_enable(Object *ob, /* Create empty BMesh and enable logging */ ss->bm = BM_mesh_create(&bm_mesh_allocsize_default); BM_data_layer_add(ss->bm, &ss->bm->vdata, CD_PAINT_MASK); + BM_data_layer_add(ss->bm, &ss->bm->vdata, CD_DYNTOPO_NODE); + BM_data_layer_add(ss->bm, &ss->bm->pdata, CD_DYNTOPO_NODE); me->flag |= ME_SCULPT_DYNAMIC_TOPOLOGY; /* Restore the BMLog using saved entries */ |