Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntony Riakiotakis <kalast@gmail.com>2014-04-17 20:02:55 +0400
committerAntony Riakiotakis <kalast@gmail.com>2014-04-17 20:03:08 +0400
commit38eef8deee4261f0139d29eb81584131a862bf59 (patch)
treeeabdfc91ed986342d938c1fbcda945e768c5b660 /source/blender/editors/sculpt_paint
parent0ba3f7647071a7bd7fdf48e0d48a9e7e1ee79a7b (diff)
Refactor to Dyntopo node customdata commit.
Don't use a dedicated node layer but use temporary int layer instead. Works like a charm as long as we are careful resetting the layer when needed (after pbvh clearing and always after bmesh has been filled in undo) Tip by Campbell, thanks!
Diffstat (limited to 'source/blender/editors/sculpt_paint')
-rw-r--r--source/blender/editors/sculpt_paint/sculpt.c44
-rw-r--r--source/blender/editors/sculpt_paint/sculpt_intern.h5
-rw-r--r--source/blender/editors/sculpt_paint/sculpt_undo.c11
3 files changed, 47 insertions, 13 deletions
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index 4873587e9f5..dbf99e96053 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -4793,15 +4793,14 @@ void sculpt_pbvh_clear(Object *ob)
BKE_object_free_derived_caches(ob);
}
-void sculpt_dyntopo_node_layers_reset(BMesh *bm)
+void sculpt_dyntopo_node_layers_reset(SculptSession *ss)
{
- /* 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);
+ BMesh *bm = ss->bm;
+ int cd_vert_node_offset = ss->cd_vert_node_offset;
+ int cd_face_node_offset = ss->cd_face_node_offset;
/* clear the elements of the node information */
BM_ITER_MESH(v, &iter, bm, BM_VERTS_OF_MESH) {
@@ -4813,6 +4812,34 @@ void sculpt_dyntopo_node_layers_reset(BMesh *bm)
}
}
+void sculpt_dyntopo_node_layers_add(SculptSession *ss)
+{
+ int cd_node_layer_index;
+
+ char layer_id[] = "_dyntopo_node_id";
+
+ cd_node_layer_index = CustomData_get_named_layer_index(&ss->bm->vdata, CD_PROP_INT, layer_id);
+ if (cd_node_layer_index == -1) {
+ BM_data_layer_add_named(ss->bm, &ss->bm->vdata, CD_PROP_INT, layer_id);
+ cd_node_layer_index = CustomData_get_named_layer_index(&ss->bm->vdata, CD_PROP_INT, layer_id);
+ }
+
+ ss->cd_vert_node_offset = CustomData_get_n_offset(&ss->bm->vdata, CD_PROP_INT, cd_node_layer_index);
+
+ ss->bm->vdata.layers[cd_node_layer_index].flag |= CD_FLAG_TEMPORARY;
+
+ cd_node_layer_index = CustomData_get_named_layer_index(&ss->bm->pdata, CD_PROP_INT, layer_id);
+ if (cd_node_layer_index == -1) {
+ BM_data_layer_add_named(ss->bm, &ss->bm->pdata, CD_PROP_INT, layer_id);
+ cd_node_layer_index = CustomData_get_named_layer_index(&ss->bm->pdata, CD_PROP_INT, layer_id);
+ }
+
+ ss->cd_face_node_offset = CustomData_get_n_offset(&ss->bm->pdata, CD_PROP_INT, cd_node_layer_index);
+
+ ss->bm->pdata.layers[cd_node_layer_index].flag |= CD_FLAG_TEMPORARY;
+}
+
+
void sculpt_update_after_dynamic_topology_toggle(bContext *C)
{
Scene *scene = CTX_data_scene(C);
@@ -4845,8 +4872,9 @@ 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);
+ sculpt_dyntopo_node_layers_add(ss);
+ /* make sure the data for existing faces are initialized */
+ sculpt_dyntopo_node_layers_reset(ss);
BM_mesh_normals_update(ss->bm);
/* Enable dynamic topology */
@@ -5303,7 +5331,7 @@ static int sculpt_detail_flood_fill_exec(bContext *C, wmOperator *UNUSED(op))
/* force rebuild of pbvh for better BB placement */
sculpt_pbvh_clear(ob);
- sculpt_dyntopo_node_layers_reset(ss->bm);
+ sculpt_dyntopo_node_layers_reset(ss);
/* Redraw */
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
diff --git a/source/blender/editors/sculpt_paint/sculpt_intern.h b/source/blender/editors/sculpt_paint/sculpt_intern.h
index 79fd388e332..8cf5bf88bcc 100644
--- a/source/blender/editors/sculpt_paint/sculpt_intern.h
+++ b/source/blender/editors/sculpt_paint/sculpt_intern.h
@@ -42,13 +42,13 @@
struct bContext;
struct Brush;
-struct BMesh;
struct KeyBlock;
struct Mesh;
struct MultiresModifierData;
struct Object;
struct Scene;
struct Sculpt;
+struct SculptSession;
struct SculptStroke;
struct SculptUndoNode;
@@ -68,7 +68,8 @@ 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_dyntopo_node_layers_reset(struct SculptSession *ss);
+void sculpt_dyntopo_node_layers_add(struct SculptSession *ss);
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 b0fd7faa70d..39df15bd985 100644
--- a/source/blender/editors/sculpt_paint/sculpt_undo.c
+++ b/source/blender/editors/sculpt_paint/sculpt_undo.c
@@ -301,7 +301,7 @@ static void sculpt_undo_bmesh_restore_generic(bContext *C,
MEM_freeN(nodes);
}
else {
- sculpt_dyntopo_node_layers_reset(ss->bm);
+ sculpt_dyntopo_node_layers_reset(ss);
sculpt_pbvh_clear(ob);
}
}
@@ -318,8 +318,7 @@ 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);
+ sculpt_dyntopo_node_layers_add(ss);
me->flag |= ME_SCULPT_DYNAMIC_TOPOLOGY;
/* Restore the BMLog using saved entries */
@@ -342,6 +341,9 @@ static void sculpt_undo_bmesh_restore_begin(bContext *C,
/* Restore the mesh from the first log entry */
BM_log_redo(ss->bm, ss->bm_log);
+ /* reset layers for all bmesh data */
+ sculpt_dyntopo_node_layers_reset(ss);
+
unode->applied = true;
}
}
@@ -357,6 +359,9 @@ static void sculpt_undo_bmesh_restore_end(bContext *C,
/* Restore the mesh from the last log entry */
BM_log_undo(ss->bm, ss->bm_log);
+ /* reset layers for all bmesh data */
+ sculpt_dyntopo_node_layers_reset(ss);
+
unode->applied = false;
}
else {