Sculpting:

* Cleanup for previous commit and reduce some local variable referencing
* Add support for brushes that operate on frontfaces only and do not
show the option for those brushes. Currently only clay strips is in the
list but this may change according to artist feedback. This should take
care of the "sticky" surface problem completely.
This commit is contained in:
Antony Riakiotakis 2013-09-13 23:58:00 +00:00
parent 8f3a40830d
commit b1179c4752
6 changed files with 42 additions and 32 deletions

View File

@ -642,9 +642,10 @@ class VIEW3D_PT_tools_brush(Panel, View3DPaintPanel):
row.prop(brush, "height", slider=True, text="Height")
# use_frontface
col.separator()
row = col.row()
row.prop(brush, "use_frontface", text="Front Faces Only")
if capabilities.has_frontface:
col.separator()
row = col.row()
row.prop(brush, "use_frontface", text="Front Faces Only")
# direction
col.separator()

View File

@ -111,5 +111,8 @@ void BKE_brush_scale_size(int *BKE_brush_size_get,
/* debugging only */
void BKE_brush_debug_print_state(struct Brush *br);
/* sculpt */
bool BKE_sculpt_brush_frontface_only(struct Brush *);
#endif

View File

@ -173,5 +173,4 @@ void free_sculptsession(struct Object *ob);
void free_sculptsession_deformMats(struct SculptSession *ss);
void sculptsession_bm_to_me(struct Object *ob, int reorder);
void sculptsession_bm_to_me_for_render(struct Object *object);
#endif

View File

@ -1048,3 +1048,8 @@ struct ImBuf *BKE_brush_gen_radial_control_imbuf(Brush *br, bool secondary)
return im;
}
bool BKE_sculpt_brush_frontface_only(struct Brush *br)
{
return br->sculpt_tool != SCULPT_TOOL_CLAY_STRIPS;
}

View File

@ -318,6 +318,8 @@ typedef struct StrokeCache {
float plane_trim_squared;
rcti previous_r; /* previous redraw rectangle */
bool frontface; /* use front face */
} StrokeCache;
/************** Access to original unmodified vertex data *************/
@ -669,10 +671,10 @@ static int sculpt_brush_test_cube(SculptBrushTest *test, float co[3], float loca
}
}
static float frontface(Brush *brush, const float sculpt_normal[3],
static float frontface(bool ff, const float sculpt_normal[3],
const short no[3], const float fno[3])
{
if (brush->flag & BRUSH_FRONTFACE) {
if (ff) {
float dot;
if (no) {
@ -949,7 +951,8 @@ static float tex_strength(SculptSession *ss, Brush *br,
const float fno[3],
const float mask)
{
const Scene *scene = ss->cache->vc->scene;
const StrokeCache *cache = ss->cache;
const Scene *scene = cache->vc->scene;
MTex *mtex = &br->mtex;
float avg = 1;
float rgba[4];
@ -971,12 +974,12 @@ static float tex_strength(SculptSession *ss, Brush *br,
* position in order to project it. This insures that the
* brush texture will be oriented correctly. */
flip_v3_v3(symm_point, point, ss->cache->mirror_symmetry_pass);
flip_v3_v3(symm_point, point, cache->mirror_symmetry_pass);
if (ss->cache->radial_symmetry_pass)
mul_m4_v3(ss->cache->symm_rot_mat_inv, symm_point);
if (cache->radial_symmetry_pass)
mul_m4_v3(cache->symm_rot_mat_inv, symm_point);
ED_view3d_project_float_v2_m4(ss->cache->vc->ar, symm_point, point_2d, ss->cache->projection_mat);
ED_view3d_project_float_v2_m4(cache->vc->ar, symm_point, point_2d, cache->projection_mat);
/* still no symmetry supported for other paint modes.
* Sculpt does it DIY */
@ -984,7 +987,7 @@ static float tex_strength(SculptSession *ss, Brush *br,
/* Similar to fixed mode, but projects from brush angle
* rather than view direction */
mul_m4_v3(ss->cache->brush_local_mat, symm_point);
mul_m4_v3(cache->brush_local_mat, symm_point);
x = symm_point[0];
y = symm_point[1];
@ -1006,9 +1009,9 @@ static float tex_strength(SculptSession *ss, Brush *br,
}
/* Falloff curve */
avg *= BKE_brush_curve_strength(br, len, ss->cache->radius);
avg *= BKE_brush_curve_strength(br, len, cache->radius);
avg *= frontface(br, sculpt_normal, vno, fno);
avg *= frontface(cache->frontface, sculpt_normal, vno, fno);
/* Paint mask */
avg *= 1.0f - mask;
@ -2307,11 +2310,9 @@ static void calc_flatten_center(Sculpt *sd, Object *ob, PBVHNode **nodes, int to
{
if (sculpt_brush_test_fast(&test, unode->co[vd.i])) {
float fno[3];
float dot_result;
normal_short_to_float_v3(fno, unode->no[vd.i]);
dot_result = dot_v3v3(ss->cache->view_normal, fno);
if (dot_result > 0) {
if (dot_v3v3(ss->cache->view_normal, fno) > 0) {
add_v3_v3(private_fc, unode->co[vd.i]);
private_count++;
}
@ -2327,16 +2328,13 @@ static void calc_flatten_center(Sculpt *sd, Object *ob, PBVHNode **nodes, int to
BKE_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNIQUE)
{
if (sculpt_brush_test_fast(&test, vd.co)) {
float dot_result;
/* for area normal */
if (vd.no) {
float fno[3];
normal_short_to_float_v3(fno, vd.no);
dot_result = dot_v3v3(ss->cache->view_normal, fno);
if (dot_result > 0) {
if (dot_v3v3(ss->cache->view_normal, fno) > 0) {
add_v3_v3(private_fc, vd.co);
private_count++;
}
@ -2346,8 +2344,7 @@ static void calc_flatten_center(Sculpt *sd, Object *ob, PBVHNode **nodes, int to
}
}
else {
dot_result = dot_v3v3(ss->cache->view_normal, vd.fno);
if (dot_result > 0) {
if (dot_v3v3(ss->cache->view_normal, vd.fno) > 0) {
add_v3_v3(private_fc, vd.co);
private_count++;
}
@ -2423,11 +2420,10 @@ static void calc_area_normal_and_flatten_center(Sculpt *sd, Object *ob,
if (sculpt_brush_test_fast(&test, unode->co[vd.i])) {
/* for area normal */
float fno[3];
float dot_result;
normal_short_to_float_v3(fno, unode->no[vd.i]);
dot_result = dot_v3v3(ss->cache->view_normal, fno);
if (dot_result > 0) {
if (dot_v3v3(ss->cache->view_normal, fno) > 0) {
add_v3_v3(private_an, fno);
add_v3_v3(private_fc, unode->co[vd.i]);
private_count++;
@ -2445,16 +2441,13 @@ static void calc_area_normal_and_flatten_center(Sculpt *sd, Object *ob,
BKE_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNIQUE)
{
if (sculpt_brush_test_fast(&test, vd.co)) {
float dot_result;
/* for area normal */
if (vd.no) {
float fno[3];
normal_short_to_float_v3(fno, vd.no);
dot_result = dot_v3v3(ss->cache->view_normal, fno);
if (dot_result > 0) {
if (dot_v3v3(ss->cache->view_normal, fno) > 0) {
add_v3_v3(private_an, fno);
add_v3_v3(private_fc, vd.co);
private_count++;
@ -2466,8 +2459,7 @@ static void calc_area_normal_and_flatten_center(Sculpt *sd, Object *ob,
}
}
else {
dot_result = dot_v3v3(ss->cache->view_normal, vd.fno);
if (dot_result > 0) {
if (dot_v3v3(ss->cache->view_normal, vd.fno) > 0) {
add_v3_v3(private_an, vd.fno);
add_v3_v3(private_fc, vd.co);
private_count++;
@ -3930,6 +3922,9 @@ static void sculpt_update_cache_invariants(bContext *C, Sculpt *sd, SculptSessio
cache->previous_vertex_rotation = 0;
cache->init_dir_set = false;
cache->frontface = ((brush->flag & BRUSH_FRONTFACE) != 0) ||
BKE_sculpt_brush_frontface_only(brush);
sculpt_omp_start(sd, ss);
}

View File

@ -237,6 +237,12 @@ static int rna_SculptToolCapabilities_has_strength_get(PointerRNA *ptr)
return !ELEM(br->sculpt_tool, SCULPT_TOOL_GRAB, SCULPT_TOOL_SNAKE_HOOK);
}
static int rna_SculptToolCapabilities_has_frontface_get(PointerRNA *ptr)
{
Brush *br = (Brush *)ptr->data;
return BKE_sculpt_brush_frontface_only(br);
}
static int rna_BrushCapabilities_has_texture_angle_get(PointerRNA *ptr)
{
Brush *br = (Brush *)ptr->data;
@ -556,6 +562,7 @@ static void rna_def_sculpt_capabilities(BlenderRNA *brna)
SCULPT_TOOL_CAPABILITY(has_smooth_stroke, "Has Smooth Stroke");
SCULPT_TOOL_CAPABILITY(has_space_attenuation, "Has Space Attenuation");
SCULPT_TOOL_CAPABILITY(has_strength, "Has Strength");
SCULPT_TOOL_CAPABILITY(has_frontface, "Has Strength");
#undef SCULPT_CAPABILITY
}