[Bf-blender-cvs] [b2a10fa615e] master: Vertex Paint: projection options
Campbell Barton
noreply at git.blender.org
Mon Oct 2 12:55:05 CEST 2017
Commit: b2a10fa615efcf403a9ca23005d86ca149ebf56b
Author: Campbell Barton
Date: Mon Oct 2 21:07:25 2017 +1100
Branches: master
https://developer.blender.org/rBb2a10fa615efcf403a9ca23005d86ca149ebf56b
Vertex Paint: projection options
This makes vertex paint match image painting more closely.
- Add falloff shape option sphere/circle
where sphere uses a 3D radius around the cursor and
circle uses a 2D radius (projected), like previous releases.
- Add normal angle option so you can control the falloff.
- Add Cull option, to paint onto faces pointing away.
Disabling normals, culling and using circle falloff
allows you to paint through the mesh.
===================================================================
M release/scripts/startup/bl_ui/space_view3d_toolbar.py
M source/blender/blenkernel/BKE_brush.h
M source/blender/blenkernel/BKE_paint.h
M source/blender/blenkernel/intern/brush.c
M source/blender/blenloader/intern/versioning_270.c
M source/blender/editors/sculpt_paint/paint_vertex.c
M source/blender/editors/sculpt_paint/sculpt.c
M source/blender/editors/sculpt_paint/sculpt_intern.h
M source/blender/makesdna/DNA_scene_types.h
M source/blender/makesrna/intern/rna_sculpt_paint.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
index d260bfe3460..798b5e28d9c 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -1761,9 +1761,16 @@ class VIEW3D_PT_tools_weightpaint_options(Panel, View3DPaintPanel):
wpaint = tool_settings.weight_paint
col = layout.column()
+ col.label("Falloff:")
row = col.row()
-
- row.prop(wpaint, "use_normal")
+ row.prop(wpaint, "falloff_shape", expand=True)
+ row = col.row()
+ row.prop(wpaint, "use_backface_culling")
+ row = col.row()
+ row.prop(wpaint, "use_normal_falloff")
+ sub = row.row()
+ sub.active = (wpaint.use_normal_falloff)
+ sub.prop(wpaint, "normal_angle", text="")
col = layout.column()
row = col.row()
row.prop(wpaint, "use_spray")
@@ -1798,19 +1805,21 @@ class VIEW3D_PT_tools_vertexpaint(Panel, View3DPaintPanel):
vpaint = toolsettings.vertex_paint
col = layout.column()
+ col.label("Falloff:")
+ row = col.row()
+ row.prop(vpaint, "falloff_shape", expand=True)
row = col.row()
- # col.prop(vpaint, "mode", text="")
- row.prop(vpaint, "use_normal")
+ row.prop(vpaint, "use_backface_culling")
+ row = col.row()
+ row.prop(vpaint, "use_normal_falloff")
+ sub = row.row()
+ sub.active = (vpaint.use_normal_falloff)
+ sub.prop(vpaint, "normal_angle", text="")
+
col.prop(vpaint, "use_spray")
self.unified_paint_settings(col, context)
-# Commented out because the Apply button isn't an operator yet, making these settings useless
-#~ col.label(text="Gamma:")
-#~ col.prop(vpaint, "gamma", text="")
-#~ col.label(text="Multiply:")
-#~ col.prop(vpaint, "mul", text="")
-
class VIEW3D_PT_tools_vertexpaint_symmetry(Panel, View3DPaintPanel):
bl_category = "Tools"
diff --git a/source/blender/blenkernel/BKE_brush.h b/source/blender/blenkernel/BKE_brush.h
index dedb75a080a..c1e107e101a 100644
--- a/source/blender/blenkernel/BKE_brush.h
+++ b/source/blender/blenkernel/BKE_brush.h
@@ -70,7 +70,7 @@ void BKE_brush_randomize_texture_coords(struct UnifiedPaintSettings *ups, bool m
/* brush curve */
void BKE_brush_curve_preset(struct Brush *b, int preset);
float BKE_brush_curve_strength_clamped(struct Brush *br, float p, const float len);
-float BKE_brush_curve_strength(struct Brush *br, float p, const float len);
+float BKE_brush_curve_strength(const struct Brush *br, float p, const float len);
/* sampling */
float BKE_brush_sample_tex_3D(
diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h
index fe7461c810d..19f332f5f54 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -231,7 +231,7 @@ typedef struct SculptSession {
/* Keep track of how much each vertex has been painted (non-airbrush only). */
float *alpha_weight;
- /* Needed to continuously re-apply over the same weights (VP_SPRAY disabled).
+ /* Needed to continuously re-apply over the same weights (VP_FLAG_SPRAY disabled).
* Lazy initialize as needed (flag is set to 1 to tag it as uninitialized). */
struct MDeformVert *dvert_prev;
} wpaint;
diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c
index 03b0710c8fc..0300dfe5891 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -966,7 +966,7 @@ void BKE_brush_randomize_texture_coords(UnifiedPaintSettings *ups, bool mask)
}
/* Uses the brush curve control to find a strength value */
-float BKE_brush_curve_strength(Brush *br, float p, const float len)
+float BKE_brush_curve_strength(const Brush *br, float p, const float len)
{
float strength;
diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c
index 8459e080f99..b374e49fc83 100644
--- a/source/blender/blenloader/intern/versioning_270.c
+++ b/source/blender/blenloader/intern/versioning_270.c
@@ -1699,6 +1699,20 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
}
}
}
+
+ if (!DNA_struct_elem_find(fd->filesdna, "VPaint", "char", "falloff_shape")) {
+ for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
+ ToolSettings *ts = scene->toolsettings;
+ for (int i = 0; i < 2; i++) {
+ VPaint *vp = i ? ts->vpaint : ts->wpaint;
+ if (vp != NULL) {
+ /* remove all other flags */
+ vp->flag &= (VP_FLAG_SPRAY | VP_FLAG_VGROUP_RESTRICT);
+ vp->normal_angle = 80;
+ }
+ }
+ }
+ }
}
}
diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c
index 7b534e12f31..ea85ae70794 100644
--- a/source/blender/editors/sculpt_paint/paint_vertex.c
+++ b/source/blender/editors/sculpt_paint/paint_vertex.c
@@ -88,6 +88,66 @@ struct WPaintAverageAccum {
double value;
};
+struct NormalAnglePrecalc {
+ bool do_mask_normal;
+ /* what angle to mask at */
+ float angle;
+ /* cos(angle), faster to compare */
+ float angle__cos;
+ float angle_inner;
+ float angle_inner__cos;
+ /* difference between angle and angle_inner, for easy access */
+ float angle_range;
+};
+
+
+static void view_angle_limits_init(
+ struct NormalAnglePrecalc *a, float angle, bool do_mask_normal)
+{
+ a->do_mask_normal = do_mask_normal;
+ if (do_mask_normal) {
+ a->angle_inner = angle;
+ a->angle = (a->angle_inner + 90.0f) * 0.5f;
+ }
+ else {
+ a->angle_inner = a->angle = angle;
+ }
+
+ a->angle_inner *= (float)(M_PI_2 / 90);
+ a->angle *= (float)(M_PI_2 / 90);
+ a->angle_range = a->angle - a->angle_inner;
+
+ if (a->angle_range <= 0.0f) {
+ a->do_mask_normal = false; /* no need to do blending */
+ }
+
+ a->angle__cos = cosf(a->angle);
+ a->angle_inner__cos = cosf(a->angle_inner);
+}
+
+static float view_angle_limits_apply_falloff(
+ const struct NormalAnglePrecalc *a, float angle_cos, float *mask_p)
+{
+ if (angle_cos <= a->angle__cos) {
+ /* outsize the normal limit */
+ return false;
+ }
+ else if (angle_cos < a->angle_inner__cos) {
+ *mask_p *= (a->angle - acosf(angle_cos)) / a->angle_range;
+ return true;
+ }
+ else {
+ return true;
+ }
+}
+
+static bool vwpaint_use_normal(const VPaint *vp)
+{
+ return ((vp->flag & VP_FLAG_PROJECT_BACKFACE) == 0) ||
+ ((vp->flag & VP_FLAG_PROJECT_FLAT) == 0);
+}
+
+
static void defweight_prev_restore_or_init(MDeformVert *dvert_prev, MDeformVert *dvert_curr, int index)
{
MDeformVert *dv_curr = &dvert_curr[index];
@@ -185,7 +245,7 @@ static VPaint *new_vpaint(int wpaint)
{
VPaint *vp = MEM_callocN(sizeof(VPaint), "VPaint");
- vp->flag = (wpaint) ? 0 : VP_SPRAY;
+ vp->flag = (wpaint) ? 0 : VP_FLAG_SPRAY;
vp->paint.flags |= PAINT_SHOW_BRUSH;
return vp;
@@ -213,7 +273,7 @@ static uint vpaint_blend(
uint color_blend = ED_vpaint_blend_tool(tool, color_curr, color_paint, alpha_i);
/* if no spray, clip color adding with colorig & orig alpha */
- if ((vp->flag & VP_SPRAY) == 0) {
+ if ((vp->flag & VP_FLAG_SPRAY) == 0) {
uint color_test, a;
char *cp, *ct, *co;
@@ -299,7 +359,7 @@ static float calc_vp_alpha_col_dl(
if (strength > 0.0f) {
float alpha = brush_alpha_pressure * strength;
- if (vp->flag & VP_NORMALS) {
+ if ((vp->flag & VP_FLAG_PROJECT_FLAT) == 0) {
float dvec[3];
/* transpose ! */
@@ -670,7 +730,7 @@ static void do_weight_paint_vertex_single(
index_mirr = vgroup_mirr = -1;
}
- if ((wp->flag & VP_SPRAY) == 0) {
+ if ((wp->flag & VP_FLAG_SPRAY) == 0) {
struct MDeformVert *dvert_prev = ob->sculpt->mode.wpaint.dvert_prev;
defweight_prev_restore_or_init(dvert_prev, me->dvert, index);
if (index_mirr != -1) {
@@ -678,7 +738,7 @@ static void do_weight_paint_vertex_single(
}
}
- if (wp->flag & VP_ONLYVGROUP) {
+ if (wp->flag & VP_FLAG_VGROUP_RESTRICT) {
dw = defvert_find_index(dv, wpi->active.index);
}
else {
@@ -692,7 +752,7 @@ static void do_weight_paint_vertex_single(
/* get the mirror def vars */
if (index_mirr != -1) {
dv_mirr = &me->dvert[index_mirr];
- if (wp->flag & VP_ONLYVGROUP) {
+ if (wp->flag & VP_FLAG_VGROUP_RESTRICT) {
dw_mirr = defvert_find_index(dv_mirr, vgroup_mirr);
if (dw_mirr == NULL) {
@@ -814,7 +874,7 @@ static void do_weight_paint_vertex_multi(
}
}
- if ((wp->flag & VP_SPRAY) == 0) {
+ if ((wp->flag & VP_FLAG_SPRAY) == 0) {
struct MDeformVert *dvert_prev = ob->sculpt->mode.wpaint.dvert_prev;
defweight_prev_restore_or_init(dvert_prev, me->dvert, index);
if (index_mirr != -1) {
@@ -947,7 +1007,7 @@ static void vertex_paint_init_session_data(const ToolSettings *ts, Object *ob)
/* Create average brush arrays */
if (ob->mode == OB_MODE_VERTEX_PAINT) {
- if ((ts->vpaint->flag & VP_SPRAY) == 0) {
+ if ((ts->vpaint->flag & VP_FLAG_SPRAY) == 0) {
if (ob->sculpt->mode.vpaint.previous_color == NULL) {
ob->sculpt->mode.vpaint.previous_color =
MEM_callocN(me->totloop * sizeof(uint), __func__);
@@ -968,7 +1028,7 @@ static void vertex_paint_init_session_data(const ToolSettings *ts, Object *ob)
}
}
else if (ob->mode == OB_MODE_WEIGHT_PAINT) {
- if ((ts->wpaint->flag & VP_SPRAY) == 0) {
+ if ((ts->wpaint->flag & VP_FLAG_SPRAY) == 0) {
if (ob->sculpt->mode.wpaint.alpha_weight == NULL) {
ob->sculpt->mode.wpaint.alpha_weight =
MEM_callocN(me->totvert * sizeof(float), __func__);
@@ -1116,6 +1176,7 @@ void PAINT_OT_weight_paint_toggle(wmOperatorType *ot)
struct WPaintData {
ViewContext vc;
+ struct NormalAnglePrecalc normal_angle_precalc;
struct WeightPaintGroupData active, mirror;
@@ -1138,12 +1199,12 @@ struct WPaintData {
/* Initialize the stroke cache invariants from operator properties */
static void vwpaint_update_cache_invariants(
- bContext *C, VPaint *vd, SculptSession *ss, wmOperator *op, const float mouse[2])
+ bContext *C, VPaint *vp, SculptSession *ss, wmOperator *op, c
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list