[Bf-blender-cvs] [6c9c7f14ec8] temp-trimesh-sculpt: * Migrated optimizations from trimesh to bmesh dyntopo: - Original coordinate/normals are now stored in customdata layers, instead of being looked up in the BMLog - Vertex "indices" are now actually pointers to BMVerts. - Dyntopo split/collapse is now time-limited - Increased pbvh->leaf_limit to 2000 - Nodes are split after topolgy updates, not just after the user lets up the mouse.
Joseph Eagar
noreply at git.blender.org
Sat Oct 24 02:24:18 CEST 2020
Commit: 6c9c7f14ec87c62ff5eca5e200640b4bd6ccdedf
Author: Joseph Eagar
Date: Fri Oct 23 17:19:47 2020 -0700
Branches: temp-trimesh-sculpt
https://developer.blender.org/rB6c9c7f14ec87c62ff5eca5e200640b4bd6ccdedf
* Migrated optimizations from trimesh to bmesh dyntopo:
- Original coordinate/normals are now stored in customdata layers,
instead of being looked up in the BMLog
- Vertex "indices" are now actually pointers to BMVerts.
- Dyntopo split/collapse is now time-limited
- Increased pbvh->leaf_limit to 2000
- Nodes are split after topolgy updates, not just after the user lets up
the mouse.
* Also, renamed TMElemSet to TableGSet
TODO:
- Migrate PBVHNode->bm_[unique_verts/other_verts/faces] to TableGSet.
Currently GHash is completely inlined in this branch which does almost
the same thing performance-size; inlining GHash seems beyond the scope of this
project however.
===================================================================
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/editors/sculpt_paint/sculpt.c
M source/blender/editors/sculpt_paint/sculpt_detail.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_smooth.c
M source/blender/editors/sculpt_paint/sculpt_undo.c
M source/blender/editors/space_info/info_stats.c
M source/blender/makesrna/intern/rna_object.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h
index a35dc63d9bd..46e2e56a552 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -478,6 +478,8 @@ typedef struct SculptSession {
struct BMesh *bm;
int cd_vert_node_offset;
int cd_face_node_offset;
+ int cd_origco_offset;
+ int cd_origno_offset;
bool bm_smooth_shading;
/* Undo/redo log for dynamic topology sculpting */
struct BMLog *bm_log;
diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h
index 721763178fe..4ea9a1cf6a0 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -232,7 +232,9 @@ void BKE_pbvh_build_bmesh(PBVH *pbvh,
bool smooth_shading,
struct BMLog *log,
const int cd_vert_node_offset,
- const int cd_face_node_offset);
+ const int cd_face_node_offset,
+ const int cd_origco_offset,
+ const int cd_origno_offset);
void BKE_pbvh_build_trimesh(PBVH *bvh,
struct TM_TriMesh *bm,
bool smooth_shading,
@@ -240,6 +242,9 @@ void BKE_pbvh_build_trimesh(PBVH *bvh,
const int cd_vert_node_offset,
const int cd_face_node_offset);
+struct BMVert;
+void BKE_pbvh_bmesh_update_origvert(PBVH *bvh, struct BMVert *v);
+
void BKE_pbvh_free(PBVH *bvh);
// void BKE_pbvh_free_layer_disp(PBVH *bvh);
@@ -368,7 +373,8 @@ bool BKE_pbvh_bmesh_update_topology(PBVH *pbvh,
const float view_normal[3],
float radius,
const bool use_frontface,
- const bool use_projected);
+ const bool use_projected,
+ int sym_axis);
bool BKE_pbvh_trimesh_update_topology(PBVH *bvh,
PBVHTopologyUpdateMode mode,
@@ -507,6 +513,8 @@ typedef struct PBVHVertexIter {
struct CustomData *tm_vdata;
int cd_vert_mask_offset;
+ int cd_origco_offset;
+ int cd_origno_offset;
/* result: these are all computed in the macro, but we assume
* that compiler optimization's will skip the ones we don't use */
@@ -705,7 +713,7 @@ void pbvh_vertex_iter_init(PBVH *pbvh, PBVHNode *node, PBVHVertexIter *vi, int m
} \
vi.co = vi.bm_vert->co; \
vi.fno = vi.bm_vert->no; \
- vi.index = BM_elem_index_get(vi.bm_vert); \
+ vi.index = (SculptIdx)vi.bm_vert; \
vi.mask = BM_ELEM_CD_GET_VOID_P(vi.bm_vert, vi.cd_vert_mask_offset); \
}
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index 074fc4ecff5..f2e6c52a61a 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -1467,7 +1467,7 @@ void BKE_sculptsession_free(Object *ob)
if (ob && ob->sculpt) {
SculptSession *ss = ob->sculpt;
- if (ss->tm) {
+ if (ss->tm || ss->bm) {
#ifdef WITH_TRIMESH
BKE_sculptsession_tm_to_me(ob, true);
TMesh_free(ss->tm);
@@ -2065,7 +2065,9 @@ static PBVH *build_pbvh_for_dynamic_topology(Object *ob)
ob->sculpt->bm_smooth_shading,
ob->sculpt->bm_log,
ob->sculpt->cd_vert_node_offset,
- ob->sculpt->cd_face_node_offset);
+ ob->sculpt->cd_face_node_offset,
+ ob->sculpt->cd_origco_offset,
+ ob->sculpt->cd_origno_offset);
#endif
pbvh_show_mask_set(pbvh, ob->sculpt->show_mask);
pbvh_show_face_sets_set(pbvh, false);
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index d042ac359c0..3140837ebac 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -2441,7 +2441,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,
@@ -3111,6 +3111,8 @@ void pbvh_vertex_iter_init(PBVH *pbvh, PBVHNode *node, PBVHVertexIter *vi, int m
BLI_gsetIterator_init(&vi->bm_unique_verts, node->bm_unique_verts);
BLI_gsetIterator_init(&vi->bm_other_verts, node->bm_other_verts);
vi->bm_vdata = &pbvh->bm->vdata;
+ vi->cd_origco_offset = pbvh->cd_origco_offset;
+ vi->cd_origno_offset = pbvh->cd_origno_offset;
vi->cd_vert_mask_offset = CustomData_get_offset(vi->bm_vdata, CD_PAINT_MASK);
}
diff --git a/source/blender/blenkernel/intern/pbvh_bmesh.c b/source/blender/blenkernel/intern/pbvh_bmesh.c
index 7c3b9edcc70..0d31494daa8 100644
--- a/source/blender/blenkernel/intern/pbvh_bmesh.c
+++ b/source/blender/blenkernel/intern/pbvh_bmesh.c
@@ -26,6 +26,7 @@
#include "BLI_math.h"
#include "BLI_memarena.h"
#include "BLI_utildefines.h"
+#include "PIL_time.h"
#include "BKE_DerivedMesh.h"
#include "BKE_ccg.h"
@@ -36,6 +37,9 @@
#include "bmesh.h"
#include "pbvh_intern.h"
+#define DYNTOPO_TIME_LIMIT 0.015
+#define DYNTOPO_RUN_INTERVAL 0.01
+
/* Avoid skinny faces */
#define USE_EDGEQUEUE_EVEN_SUBDIV
#ifdef USE_EDGEQUEUE_EVEN_SUBDIV
@@ -1236,8 +1240,13 @@ static bool pbvh_bmesh_subdivide_long_edges(EdgeQueueContext *eq_ctx,
BLI_Buffer *edge_loops)
{
bool any_subdivided = false;
+ double time = PIL_check_seconds_timer();
while (!BLI_heapsimple_is_empty(eq_ctx->q->heap)) {
+ if (PIL_check_seconds_timer() - time > DYNTOPO_TIME_LIMIT) {
+ break;
+ }
+
BMVert **pair = BLI_heapsimple_pop_min(eq_ctx->q->heap);
BMVert *v1 = pair[0], *v2 = pair[1];
BMEdge *e;
@@ -1451,6 +1460,17 @@ 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)
+{
+ BM_log_vert_before_modified(pbvh->bm_log, v, pbvh->cd_vert_mask_offset);
+
+ 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);
+
+ copy_v3_v3(co, v->co);
+ copy_v3_v3(no, v->no);
+}
+
static bool pbvh_bmesh_collapse_short_edges(EdgeQueueContext *eq_ctx,
PBVH *pbvh,
BLI_Buffer *deleted_faces)
@@ -1460,7 +1480,13 @@ static bool pbvh_bmesh_collapse_short_edges(EdgeQueueContext *eq_ctx,
/* deleted verts point to vertices they were merged into, or NULL when removed. */
GHash *deleted_verts = BLI_ghash_ptr_new("deleted_verts");
+ double time = PIL_check_seconds_timer();
+
while (!BLI_heapsimple_is_empty(eq_ctx->q->heap)) {
+ if (PIL_check_seconds_timer() - time > DYNTOPO_TIME_LIMIT) {
+ break;
+ }
+
BMVert **pair = BLI_heapsimple_pop_min(eq_ctx->q->heap);
BMVert *v1 = pair[0], *v2 = pair[1];
BLI_mempool_free(eq_ctx->pool, pair);
@@ -1556,7 +1582,7 @@ bool pbvh_bmesh_node_raycast(PBVHNode *node,
if (len_squared_v3v3(location, v_tri[j]->co) <
len_squared_v3v3(location, nearest_vertex_co)) {
copy_v3_v3(nearest_vertex_co, v_tri[j]->co);
- *r_active_vertex_index = BM_elem_index_get(v_tri[j]);
+ *r_active_vertex_index = (SculptIdx)v_tri[j]; // BM_elem_index_get(v_tri[j]);
}
}
}
@@ -1880,10 +1906,16 @@ void BKE_pbvh_build_bmesh(PBVH *pbvh,
bool smooth_shading,
BMLog *log,
const int cd_vert_node_offset,
- const int cd_face_node_offset)
+ const int cd_face_node_offset,
+ const int cd_origco_offset,
+ const int cd_origno_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->bm = bm;
BKE_pbvh_bmesh_detail_size_set(pbvh, 0.75);
@@ -1892,7 +1924,7 @@ void BKE_pbvh_build_bmesh(PBVH *pbvh,
pbvh->bm_log = log;
/* TODO: choose leaf limit better */
- pbvh->leaf_limit = 100;
+ pbvh->leaf_limit = 2000;
if (smooth_shading) {
pbvh->flags |= PBVH_DYNTOPO_SMOOTH_SHADING;
@@ -1952,6 +1984,10 @@ void BKE_pbvh_build_bmesh(PBVH *pbvh,
MEM_freeN(nodeinfo);
}
+static double last_update_time[128] = {
+ 0,
+};
+
/* Collapse short edges, subdivide long edges */
bool BKE_pbvh_bmesh_update_topology(PBVH *pbvh,
PBVHTopologyUpdateMode mode,
@@ -1959,8 +1995,19 @@ bool BKE_pbvh_bmesh_update_topology(PBVH *pbvh,
const float view_normal[3],
float radius,
const bool use_frontface,
- const bool use_projected)
+ const bool use_projected,
+ int sym_axis)
{
+ if (sym_axis >= 0 &&
+ PIL_check_seconds_timer() - last_update_time[sym_axis] < DYNTOPO_RUN_INTERVAL) {
+ return false;
+ // return false;
+ }
+
+ if (sym_axis >= 0) {
+ last_update_time[sym_axis] = PIL_check_seconds_timer();
+ }
+
/* 2 is enough for edge faces - manifold edge */
BLI_buffer_declare_static(BMLoop *, edge_loops, BLI_BUFFER_NOP, 2);
BLI_buffer_declare_static(BMFace *, deleted_faces, BLI_BUFFER_NOP, 32);
@@ -2012,14 +2059,32 @@ bool BKE_pbvh_bmesh_update_topology(PBVH *pbvh,
BLI_mempool_destr
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list