Enabled dyntopo for sharp brush. Also fixed paint brush strength being

too strong with dyntopo enabled.
This commit is contained in:
Joseph Eagar 2020-11-03 00:47:19 -08:00
parent 7834b59598
commit e07bb3955e
8 changed files with 61 additions and 35 deletions

View File

@ -401,7 +401,7 @@ bool BKE_pbvh_node_frustum_exclude_AABB(PBVHNode *node, void *frustum);
struct TableGSet *BKE_pbvh_bmesh_node_unique_verts(PBVHNode *node);
struct TableGSet *BKE_pbvh_bmesh_node_other_verts(PBVHNode *node);
struct TableGSet *BKE_pbvh_bmesh_node_faces(PBVHNode *node);
void BKE_pbvh_bmesh_node_save_orig(struct BMesh *bm, PBVHNode *node);
void BKE_pbvh_bmesh_node_save_ortri(struct BMesh *bm, PBVHNode *node);
void BKE_pbvh_bmesh_after_stroke(PBVH *pbvh);
/* Update Bounding Box/Redraw and clear flags */

View File

@ -290,7 +290,7 @@ static void pbvh_bmesh_node_finalize(PBVH *pbvh,
n->flag |= PBVH_UpdateNormals | PBVH_UpdateTopology;
if (add_orco) {
BKE_pbvh_bmesh_node_save_orig(pbvh->bm, n);
BKE_pbvh_bmesh_node_save_ortri(pbvh->bm, n);
}
}
@ -441,6 +441,13 @@ static void pbvh_bmesh_node_split(
n->orig_vb = n->vb;
}
static void pbvh_bmesh_copy_facedata(BMesh *bm, BMFace *dest, BMFace *src)
{
dest->head.hflag = src->head.hflag;
dest->mat_nr = src->mat_nr;
CustomData_bmesh_copy_data(&bm->pdata, &bm->pdata, src->head.data, &dest->head.data);
}
/* Recursively split the node if it exceeds the leaf_limit */
static bool pbvh_bmesh_node_limit_ensure(PBVH *pbvh, int node_index)
{
@ -1534,6 +1541,8 @@ static void pbvh_bmesh_split_edge(EdgeQueueContext *eq_ctx,
BMEdge *e,
BLI_Buffer *edge_loops)
{
BMesh *bm = pbvh->bm;
float co_mid[3], no_mid[3];
/* Get all faces adjacent to the edge */
@ -1622,6 +1631,8 @@ static void pbvh_bmesh_split_edge(EdgeQueueContext *eq_ctx,
f_new = pbvh_bmesh_face_create(pbvh, ni, v_tri, e_tri, f_adj);
long_edge_queue_face_add(eq_ctx, f_new);
pbvh_bmesh_copy_facedata(bm, f_new, f_adj);
#ifdef DYNTOPO_CD_INTERP
BMLoop *lfirst = f_adj->l_first;
while (lfirst->v != v1) {
@ -1664,6 +1675,8 @@ static void pbvh_bmesh_split_edge(EdgeQueueContext *eq_ctx,
f_new = pbvh_bmesh_face_create(pbvh, ni, v_tri, e_tri, f_adj);
long_edge_queue_face_add(eq_ctx, f_new);
pbvh_bmesh_copy_facedata(bm, f_new, f_adj);
#ifdef DYNTOPO_CD_INTERP
lsrcs[0] = lfirst->head.data;
lsrcs[1] = lfirst->next->head.data;
@ -1980,7 +1993,8 @@ static void pbvh_bmesh_collapse_edge(PBVH *pbvh,
#ifdef DYNTOPO_CD_INTERP
BMLoop *l2 = f2->l_first;
CustomData_bmesh_copy_data(&pbvh->bm->pdata, &pbvh->bm->pdata, f->head.data, &f2->head.data);
pbvh_bmesh_copy_facedata(pbvh->bm, f2, f);
CustomData_bmesh_copy_data(&pbvh->bm->ldata, &pbvh->bm->ldata, l->head.data, &l2->head.data);
CustomData_bmesh_copy_data(
&pbvh->bm->ldata, &pbvh->bm->ldata, l->next->head.data, &l2->next->head.data);
@ -2047,10 +2061,10 @@ static void pbvh_bmesh_collapse_edge(PBVH *pbvh,
/* Move v_conn to the midpoint of v_conn and v_del (if v_conn still exists, it
* may have been deleted above) */
if (v_conn != NULL) {
// BM_log_vert_before_modified(pbvh->bm, pbvh->bm_log, v_conn, eq_ctx->cd_vert_mask_offset,
// false);
void *dummy;
BKE_pbvh_bmesh_update_origvert(pbvh, v_conn, &dummy, &dummy, &dummy);
//log vert in bmlog, but don't update original customata layers, we want them to be interpolated
BM_log_vert_before_modified(pbvh->bm_log, v_conn, eq_ctx->cd_vert_mask_offset, true);
//void *dummy;
//BKE_pbvh_bmesh_update_origvert(pbvh, v_conn, &dummy, &dummy, &dummy);
mid_v3_v3v3(v_conn->co, v_conn->co, v_del->co);
add_v3_v3(v_conn->no, v_del->no);
@ -2287,7 +2301,7 @@ bool pbvh_bmesh_node_raycast(PBVHNode *node,
for (int j = 0; j < 3; j++) {
if (!hit || len_squared_v3v3(location, v_tri[j]->co) <
len_squared_v3v3(location, nearest_vertex_co)) {
len_squared_v3v3(location, nearest_vertex_co)) {
copy_v3_v3(nearest_vertex_co, v_tri[j]->co);
SculptVertRef vref = {(intptr_t)v_tri[j]}; // BM_elem_index_get(v_tri[j]);
*r_active_vertex_index = vref;
@ -2854,7 +2868,7 @@ bool BKE_pbvh_bmesh_update_topology(PBVH *pbvh,
* (currently just raycast), store the node's triangles and vertices.
*
* Skips triangles that are hidden. */
void BKE_pbvh_bmesh_node_save_orig(BMesh *bm, PBVHNode *node)
void BKE_pbvh_bmesh_node_save_ortri(BMesh *bm, PBVHNode *node)
{
/* Skip if original coords/triangles are already saved */
if (node->bm_orco) {

View File

@ -264,6 +264,10 @@ static void bm_log_vert_customdata(BMesh *bm, BMLog *log, BMVert *v, BMLogVert *
//}
BMLogEntry *entry = log->current_entry;
if (!entry) {
return;
}
if (lv->customdata) {
BLI_mempool_free(entry->vdata.pool, lv->customdata);
lv->customdata = NULL;

View File

@ -1356,6 +1356,7 @@ void SCULPT_orig_vert_data_init(SculptOrigVertData *data, Object *ob, PBVHNode *
SculptUndoNode *unode = NULL;
data->ss = ob->sculpt;
/*do not allocate an undo node for bmesh pbvh*/
if (!ob->sculpt->bm) {
unode = SCULPT_undo_push_node(ob, node, SCULPT_UNDO_COORDS);
}
@ -1378,11 +1379,6 @@ void SCULPT_orig_vert_data_update(SculptOrigVertData *orig_data, PBVHVertexIter
orig_data->no = orig_data->_no;
orig_data->col = BM_ELEM_CD_GET_VOID_P(iter->bm_vert, orig_data->ss->cd_origvcol_offset);
// BKE_pbvh_bmesh_update_origvert(
// orig_data->pbvh, iter->bm_vert, &orig_data->co, &orig_data->no, &orig_data->col);
// BM_log_original_vert_data(orig_data->bm_log, iter->bm_vert, &orig_data->co,
// &orig_data->no);
}
else {
orig_data->co = orig_data->coords[iter->i];
@ -1392,9 +1388,6 @@ void SCULPT_orig_vert_data_update(SculptOrigVertData *orig_data, PBVHVertexIter
else if (orig_data->datatype == SCULPT_UNDO_COLOR) {
if (orig_data->bm_log) {
orig_data->col = BM_ELEM_CD_GET_VOID_P(iter->bm_vert, orig_data->ss->cd_origvcol_offset);
// BKE_pbvh_bmesh_update_origvert(orig_data->pbvh, iter->bm_vert, NULL, NULL,
// &orig_data->col);
}
else {
orig_data->col = orig_data->colors[iter->i];
@ -5719,16 +5712,22 @@ static void sculpt_topology_update(Sculpt *sd,
}
}
bool undo_push = !use_original ||
SCULPT_stroke_is_first_brush_step_of_symmetry_pass(ss->cache);
for (n = 0; n < totnode; n++) {
SCULPT_undo_push_node(ob,
nodes[n],
brush->sculpt_tool == SCULPT_TOOL_MASK ? SCULPT_UNDO_MASK :
SCULPT_UNDO_COORDS);
if (undo_push) {
SCULPT_undo_push_node(ob,
nodes[n],
brush->sculpt_tool == SCULPT_TOOL_MASK ? SCULPT_UNDO_MASK :
SCULPT_UNDO_COORDS);
}
BKE_pbvh_node_mark_update(nodes[n]);
if (BKE_pbvh_type(ss->pbvh) == PBVH_BMESH) {
BKE_pbvh_node_mark_topology_update(nodes[n]);
BKE_pbvh_bmesh_node_save_orig(ss->bm, nodes[n]);
BKE_pbvh_bmesh_node_save_ortri(ss->bm, nodes[n]);
}
}
@ -5784,7 +5783,9 @@ static void do_brush_action_task_cb(void *__restrict userdata,
BKE_pbvh_node_mark_update_color(data->nodes[n]);
}
else {
SCULPT_undo_push_node(data->ob, data->nodes[n], SCULPT_UNDO_COORDS);
if (!ss->bm) {
SCULPT_undo_push_node(data->ob, data->nodes[n], SCULPT_UNDO_COORDS);
}
BKE_pbvh_node_mark_update(data->nodes[n]);
}
}
@ -5892,11 +5893,17 @@ static void do_brush_action(Sculpt *sd, Object *ob, Brush *brush, UnifiedPaintSe
};
// dyntopo can't push undo nodes inside a thread
if (ss->bm) {
if (ss->bm && ELEM(brush->sculpt_tool, SCULPT_TOOL_PAINT, SCULPT_TOOL_SMEAR)) {
for (int i = 0; i < totnode; i++) {
//SCULPT_ensure_dyntopo_node_undo(ob, nodes[i], SCULPT_UNDO_COLOR);
SCULPT_undo_push_node(ob, nodes[i], SCULPT_UNDO_COLOR);
BKE_pbvh_update_origcolor_bmesh(ss->pbvh, nodes[i]);
if (SCULPT_ensure_dyntopo_node_undo(ob, nodes[i], SCULPT_UNDO_COLOR)) {
BKE_pbvh_update_origcolor_bmesh(ss->pbvh, nodes[i]);
}
// SCULPT_undo_push_node(ob, nodes[i], SCULPT_UNDO_COLOR);
}
}
else if (ss->bm) {
for (int i = 0; i < totnode; i++) {
SCULPT_ensure_dyntopo_node_undo(ob, nodes[i], SCULPT_UNDO_COORDS);
}
}
@ -9593,14 +9600,14 @@ static void dyntopo_detail_size_sample_from_surface(Object *ob,
DyntopoDetailSizeEditCustomData *cd)
{
SculptSession *ss = ob->sculpt;
const int active_vertex = SCULPT_active_vertex_get(ss);
const SculptVertRef active_vertex = SCULPT_active_vertex_get(ss);
float len_accum = 0;
int num_neighbors = 0;
SculptVertexNeighborIter ni;
SCULPT_VERTEX_NEIGHBORS_ITER_BEGIN (ss, active_vertex, ni) {
len_accum += len_v3v3(SCULPT_vertex_co_get(ss, active_vertex),
SCULPT_vertex_co_get(ss, ni.index));
SCULPT_vertex_co_get(ss, ni.vertex));
num_neighbors++;
}
SCULPT_VERTEX_NEIGHBORS_ITER_END(ni);

View File

@ -220,7 +220,7 @@ static void cloth_brush_add_length_constraint(SculptSession *ss,
cloth_brush_reallocate_constraints(cloth_sim);
/* Add the constraint to the #GSet to avoid creating it again. */
BLI_edgeset_add(cloth_sim->created_length_constraints, v1, v2);
BLI_edgeset_add(cloth_sim->created_length_constraints, v1i, v2i);
}
static void cloth_brush_add_softbody_constraint(SculptClothSimulation *cloth_sim,

View File

@ -335,7 +335,8 @@ static int sculpt_face_set_create_exec(bContext *C, wmOperator *op)
for (int i = 0; i < tot_vert; i++) {
SculptVertRef vertex = BKE_pbvh_table_index_to_vertex(ss->pbvh, i);
if (SCULPT_vertex_mask_get(ss, vertex) >= threshold && SCULPT_vertex_visible_get(ss, vertex)) {
if (SCULPT_vertex_mask_get(ss, vertex) >= threshold &&
SCULPT_vertex_visible_get(ss, vertex)) {
SCULPT_vertex_face_set_set(ss, vertex, next_face_set);
}
}
@ -1159,7 +1160,8 @@ static void sculpt_face_set_delete_geometry(Object *ob,
.use_toolflags = true,
}));
BM_mesh_bm_from_me(bm,
BM_mesh_bm_from_me(ob,
bm,
mesh,
(&(struct BMeshFromMeshParams){
.calc_face_normal = true,
@ -1180,6 +1182,7 @@ static void sculpt_face_set_delete_geometry(Object *ob,
BM_mesh_elem_hflag_disable_all(bm, BM_VERT | BM_EDGE | BM_FACE, BM_ELEM_TAG, false);
BM_mesh_bm_to_me(NULL,
ob,
bm,
ob->data,
(&(struct BMeshToMeshParams){

View File

@ -868,7 +868,6 @@ typedef enum eBrushUVSculptTool {
SCULPT_TOOL_THUMB, \
SCULPT_TOOL_LAYER, \
SCULPT_TOOL_DISPLACEMENT_ERASER, \
SCULPT_TOOL_DRAW_SHARP, \
SCULPT_TOOL_SLIDE_RELAX, \
SCULPT_TOOL_ELASTIC_DEFORM, \
SCULPT_TOOL_POSE, \
@ -886,7 +885,6 @@ typedef enum eBrushUVSculptTool {
SCULPT_TOOL_GRAB, \
SCULPT_TOOL_ROTATE, \
SCULPT_TOOL_THUMB, \
SCULPT_TOOL_DRAW_SHARP, \
SCULPT_TOOL_DISPLACEMENT_ERASER, \
SCULPT_TOOL_SLIDE_RELAX, \
SCULPT_TOOL_MASK) == 0)

View File

@ -1,4 +1,4 @@
f /*
/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2