diff options
Diffstat (limited to 'source/blender/editors/sculpt_paint/sculpt.c')
-rw-r--r-- | source/blender/editors/sculpt_paint/sculpt.c | 89 |
1 files changed, 59 insertions, 30 deletions
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index 0b009dba651..c26a4d52a9e 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -208,7 +208,8 @@ typedef struct StrokeCache { int first_time; /* Beginning of stroke may do some things special */ - bglMats *mats; + /* from ED_view3d_ob_project_mat_get() */ + float projection_mat[4][4]; /* Clean this up! */ ViewContext *vc; @@ -405,7 +406,8 @@ static int sculpt_brush_test_cube(SculptBrushTest *test, float co[3], float loca } } -static float frontface(Brush *brush, float sculpt_normal[3], short no[3], float fno[3]) +static float frontface(Brush *brush, const float sculpt_normal[3], + const short no[3], const float fno[3]) { if (brush->flag & BRUSH_FRONTFACE) { float dot; @@ -655,7 +657,11 @@ static float brush_strength(Sculpt *sd, StrokeCache *cache, float feather) } /* Return a multiplier for brush strength on a particular vertex. */ -static float tex_strength(SculptSession *ss, Brush *br, float *point, const float len) +static float tex_strength(SculptSession *ss, Brush *br, float point[3], + const float len, + const float sculpt_normal[3], + const short vno[3], + const float fno[3]) { MTex *mtex = &br->mtex; float avg= 1; @@ -673,7 +679,8 @@ static float tex_strength(SculptSession *ss, Brush *br, float *point, const floa } else if(ss->texcache) { float rotation = -mtex->rot; - float x, y, point_2d[3]; + float symm_point[3], point_2d[2]; + float x, y; float radius; /* if the active area is being applied for symmetry, flip it @@ -681,12 +688,13 @@ static float tex_strength(SculptSession *ss, Brush *br, float *point, const floa position in order to project it. This insures that the brush texture will be oriented correctly. */ - flip_coord(point_2d, point, ss->cache->mirror_symmetry_pass); + flip_coord(symm_point, point, ss->cache->mirror_symmetry_pass); if (ss->cache->radial_symmetry_pass) - mul_m4_v3(ss->cache->symm_rot_mat_inv, point_2d); + mul_m4_v3(ss->cache->symm_rot_mat_inv, symm_point); - projectf(ss->cache->mats, point_2d, point_2d); + ED_view3d_project_float(ss->cache->vc->ar, symm_point, point_2d, + ss->cache->projection_mat); /* if fixed mode, keep coordinates relative to mouse */ if(mtex->brush_map_mode == MTEX_MAP_MODE_FIXED) { @@ -742,7 +750,10 @@ static float tex_strength(SculptSession *ss, Brush *br, float *point, const floa avg += br->texture_sample_bias; - avg *= brush_curve_strength(br, len, ss->cache->radius); /* Falloff curve */ + /* Falloff curve */ + avg *= brush_curve_strength(br, len, ss->cache->radius); + + avg *= frontface(br, sculpt_normal, vno, fno); return avg; } @@ -980,7 +991,8 @@ static void do_mesh_smooth_brush(Sculpt *sd, SculptSession *ss, PBVHNode *node, BLI_pbvh_vertex_iter_begin(ss->pbvh, node, vd, PBVH_ITER_UNIQUE) { if(sculpt_brush_test(&test, vd.co)) { - const float fade = bstrength*tex_strength(ss, brush, vd.co, test.dist)*frontface(brush, ss->cache->view_normal, vd.no, vd.fno); + const float fade = bstrength*tex_strength(ss, brush, vd.co, test.dist, + ss->cache->view_normal, vd.no, vd.fno); float avg[3], val[3]; neighbor_average(ss, avg, vd.vert_indices[vd.i]); @@ -1073,7 +1085,8 @@ static void do_multires_smooth_brush(Sculpt *sd, SculptSession *ss, PBVHNode *no fno= data[index].no; if(sculpt_brush_test(&test, co)) { - const float fade = bstrength*tex_strength(ss, brush, co, test.dist)*frontface(brush, ss->cache->view_normal, NULL, fno); + const float fade = bstrength*tex_strength(ss, brush, co, test.dist, + ss->cache->view_normal, NULL, fno); float *avg, val[3]; float n; @@ -1169,9 +1182,9 @@ static void do_draw_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNIQUE) { if (sculpt_brush_test(&test, vd.co)) { - //if(sculpt_brush_test_cyl(&test, vd.co, ss->cache->location, area_normal)) { /* offset vertex */ - float fade = tex_strength(ss, brush, vd.co, test.dist)*frontface(brush, area_normal, vd.no, vd.fno); + float fade = tex_strength(ss, brush, vd.co, test.dist, + area_normal, vd.no, vd.fno); mul_v3_v3fl(proxy[vd.i], offset, fade); @@ -1225,7 +1238,8 @@ static void do_crease_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnod BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNIQUE) { if(sculpt_brush_test(&test, vd.co)) { /* offset vertex */ - const float fade = tex_strength(ss, brush, vd.co, test.dist)*frontface(brush, area_normal, vd.no, vd.fno); + const float fade = tex_strength(ss, brush, vd.co, test.dist, + area_normal, vd.no, vd.fno); float val1[3]; float val2[3]; @@ -1266,7 +1280,8 @@ static void do_pinch_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNIQUE) { if(sculpt_brush_test(&test, vd.co)) { - float fade = bstrength*tex_strength(ss, brush, vd.co, test.dist)*frontface(brush, ss->cache->view_normal, vd.no, vd.fno); + float fade = bstrength*tex_strength(ss, brush, vd.co, test.dist, + ss->cache->view_normal, vd.no, vd.fno); float val[3]; sub_v3_v3v3(val, test.location, vd.co); @@ -1326,7 +1341,8 @@ static void do_grab_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNIQUE) { if(sculpt_brush_test(&test, origco[vd.i])) { - const float fade = bstrength*tex_strength(ss, brush, origco[vd.i], test.dist)*frontface(brush, an, origno[vd.i], NULL); + const float fade = bstrength*tex_strength(ss, brush, origco[vd.i], test.dist, + an, origno[vd.i], NULL); mul_v3_v3fl(proxy[vd.i], grab_delta, fade); @@ -1367,7 +1383,8 @@ static void do_nudge_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNIQUE) { if(sculpt_brush_test(&test, vd.co)) { - const float fade = bstrength*tex_strength(ss, brush, vd.co, test.dist)*frontface(brush, an, vd.no, vd.fno); + const float fade = bstrength*tex_strength(ss, brush, vd.co, test.dist, + an, vd.no, vd.fno); mul_v3_v3fl(proxy[vd.i], cono, fade); @@ -1416,7 +1433,8 @@ static void do_snake_hook_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int to BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNIQUE) { if(sculpt_brush_test(&test, vd.co)) { - const float fade = bstrength*tex_strength(ss, brush, vd.co, test.dist)*frontface(brush, an, vd.no, vd.fno); + const float fade = bstrength*tex_strength(ss, brush, vd.co, test.dist, + an, vd.no, vd.fno); mul_v3_v3fl(proxy[vd.i], grab_delta, fade); @@ -1464,7 +1482,8 @@ static void do_thumb_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNIQUE) { if(sculpt_brush_test(&test, origco[vd.i])) { - const float fade = bstrength*tex_strength(ss, brush, origco[vd.i], test.dist)*frontface(brush, an, origno[vd.i], NULL); + const float fade = bstrength*tex_strength(ss, brush, origco[vd.i], test.dist, + an, origno[vd.i], NULL); mul_v3_v3fl(proxy[vd.i], cono, fade); @@ -1510,7 +1529,8 @@ static void do_rotate_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnod BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNIQUE) { if(sculpt_brush_test(&test, origco[vd.i])) { - const float fade = bstrength*tex_strength(ss, brush, origco[vd.i], test.dist)*frontface(brush, an, origno[vd.i], NULL); + const float fade = bstrength*tex_strength(ss, brush, origco[vd.i], test.dist, + an, origno[vd.i], NULL); mul_v3_m3v3(proxy[vd.i], m, origco[vd.i]); sub_v3_v3(proxy[vd.i], origco[vd.i]); @@ -1564,7 +1584,8 @@ static void do_layer_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNIQUE) { if(sculpt_brush_test(&test, origco[vd.i])) { - const float fade = bstrength*tex_strength(ss, brush, vd.co, test.dist)*frontface(brush, area_normal, vd.no, vd.fno); + const float fade = bstrength*tex_strength(ss, brush, vd.co, test.dist, + area_normal, vd.no, vd.fno); float *disp= &layer_disp[vd.i]; float val[3]; @@ -1615,7 +1636,8 @@ static void do_inflate_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totno BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNIQUE) { if(sculpt_brush_test(&test, vd.co)) { - const float fade = bstrength*tex_strength(ss, brush, vd.co, test.dist)*frontface(brush, ss->cache->view_normal, vd.no, vd.fno); + const float fade = bstrength*tex_strength(ss, brush, vd.co, test.dist, + ss->cache->view_normal, vd.no, vd.fno); float val[3]; if(vd.fno) copy_v3_v3(val, vd.fno); @@ -1947,7 +1969,8 @@ static void do_flatten_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totno sub_v3_v3v3(val, intr, vd.co); if (plane_trim(ss->cache, brush, val)) { - const float fade = bstrength*tex_strength(ss, brush, vd.co, sqrt(test.dist))*frontface(brush, an, vd.no, vd.fno); + const float fade = bstrength*tex_strength(ss, brush, vd.co, sqrt(test.dist), + an, vd.no, vd.fno); mul_v3_v3fl(proxy[vd.i], val, fade); @@ -2020,7 +2043,9 @@ static void do_clay_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) sub_v3_v3v3(val, intr, vd.co); if (plane_trim(ss->cache, brush, val)) { - const float fade = bstrength*tex_strength(ss, brush, vd.co, sqrt(test.dist))*frontface(brush, an, vd.no, vd.fno); + const float fade = bstrength*tex_strength(ss, brush, vd.co, + sqrt(test.dist), + an, vd.no, vd.fno); mul_v3_v3fl(proxy[vd.i], val, fade); @@ -2111,7 +2136,9 @@ static void do_clay_tubes_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int to sub_v3_v3v3(val, intr, vd.co); if (plane_trim(ss->cache, brush, val)) { - const float fade = bstrength*tex_strength(ss, brush, vd.co, ss->cache->radius*test.dist)*frontface(brush, an, vd.no, vd.fno); + const float fade = bstrength*tex_strength(ss, brush, vd.co, + ss->cache->radius*test.dist, + an, vd.no, vd.fno); mul_v3_v3fl(proxy[vd.i], val, fade); @@ -2172,7 +2199,9 @@ static void do_fill_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) sub_v3_v3v3(val, intr, vd.co); if (plane_trim(ss->cache, brush, val)) { - const float fade = bstrength*tex_strength(ss, brush, vd.co, sqrt(test.dist))*frontface(brush, an, vd.no, vd.fno); + const float fade = bstrength*tex_strength(ss, brush, vd.co, + sqrt(test.dist), + an, vd.no, vd.fno); mul_v3_v3fl(proxy[vd.i], val, fade); @@ -2233,7 +2262,9 @@ static void do_scrape_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnod sub_v3_v3v3(val, intr, vd.co); if (plane_trim(ss->cache, brush, val)) { - const float fade = bstrength*tex_strength(ss, brush, vd.co, sqrt(test.dist))*frontface(brush, an, vd.no, vd.fno); + const float fade = bstrength*tex_strength(ss, brush, vd.co, + sqrt(test.dist), + an, vd.no, vd.fno); mul_v3_v3fl(proxy[vd.i], val, fade); @@ -2782,8 +2813,6 @@ static void sculpt_cache_free(StrokeCache *cache) { if(cache->face_norms) MEM_freeN(cache->face_norms); - if(cache->mats) - MEM_freeN(cache->mats); MEM_freeN(cache); } @@ -2882,8 +2911,8 @@ static void sculpt_update_cache_invariants(bContext* C, Sculpt *sd, SculptSessio cache->brush = brush; - cache->mats = MEM_callocN(sizeof(bglMats), "sculpt bglMats"); - view3d_get_transformation(vc->ar, vc->rv3d, vc->obact, cache->mats); + /* cache projection matrix */ + ED_view3d_ob_project_mat_get(cache->vc->rv3d, ob, cache->projection_mat); ED_view3d_global_to_vector(cache->vc->rv3d, cache->vc->rv3d->twmat[3], cache->true_view_normal); /* Initialize layer brush displacements and persistent coords */ |