forked from bartvdbraak/blender
Curve Draw: option to apply absolute offset
Offset used curve radius, which isn't useful drawing without any bevel radius.
This commit is contained in:
parent
568514c875
commit
6f2797b50b
@ -597,7 +597,8 @@ class VIEW3D_PT_tools_curveedit_options_stroke(View3DPanel, Panel):
|
|||||||
|
|
||||||
col = layout.column()
|
col = layout.column()
|
||||||
if cps.depth_mode == 'SURFACE':
|
if cps.depth_mode == 'SURFACE':
|
||||||
col.prop(cps, "radius_offset")
|
col.prop(cps, "surface_offset")
|
||||||
|
col.prop(cps, "use_offset_absolute")
|
||||||
col.prop(cps, "use_stroke_endpoints")
|
col.prop(cps, "use_stroke_endpoints")
|
||||||
if cps.use_stroke_endpoints:
|
if cps.use_stroke_endpoints:
|
||||||
colsub = layout.column(align=True)
|
colsub = layout.column(align=True)
|
||||||
|
@ -194,6 +194,8 @@ struct CurveDrawData {
|
|||||||
/* offset projection by this value */
|
/* offset projection by this value */
|
||||||
bool use_offset;
|
bool use_offset;
|
||||||
float offset[3]; /* worldspace */
|
float offset[3]; /* worldspace */
|
||||||
|
float surface_offset;
|
||||||
|
bool use_surface_offset_absolute;
|
||||||
} project;
|
} project;
|
||||||
|
|
||||||
/* cursor sampling */
|
/* cursor sampling */
|
||||||
@ -204,7 +206,6 @@ struct CurveDrawData {
|
|||||||
|
|
||||||
struct {
|
struct {
|
||||||
float min, max, range;
|
float min, max, range;
|
||||||
float offset;
|
|
||||||
} radius;
|
} radius;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
@ -243,7 +244,10 @@ static float stroke_elem_radius(const struct CurveDrawData *cdd, const struct St
|
|||||||
|
|
||||||
static void stroke_elem_pressure_set(const struct CurveDrawData *cdd, struct StrokeElem *selem, float pressure)
|
static void stroke_elem_pressure_set(const struct CurveDrawData *cdd, struct StrokeElem *selem, float pressure)
|
||||||
{
|
{
|
||||||
if ((cdd->radius.offset != 0.0f) && !is_zero_v3(selem->normal_local)) {
|
if ((cdd->project.surface_offset != 0.0f) &&
|
||||||
|
!cdd->project.use_surface_offset_absolute &&
|
||||||
|
!is_zero_v3(selem->normal_local))
|
||||||
|
{
|
||||||
const float adjust = stroke_elem_radius_from_pressure(cdd, pressure) -
|
const float adjust = stroke_elem_radius_from_pressure(cdd, pressure) -
|
||||||
stroke_elem_radius_from_pressure(cdd, selem->pressure);
|
stroke_elem_radius_from_pressure(cdd, selem->pressure);
|
||||||
madd_v3_v3fl(selem->location_local, selem->normal_local, adjust);
|
madd_v3_v3fl(selem->location_local, selem->normal_local, adjust);
|
||||||
@ -269,7 +273,7 @@ static void stroke_elem_interp(
|
|||||||
static bool stroke_elem_project(
|
static bool stroke_elem_project(
|
||||||
const struct CurveDrawData *cdd,
|
const struct CurveDrawData *cdd,
|
||||||
const int mval_i[2], const float mval_fl[2],
|
const int mval_i[2], const float mval_fl[2],
|
||||||
const float radius_offset, const float radius,
|
float surface_offset, const float radius,
|
||||||
float r_location_world[3], float r_normal_world[3])
|
float r_location_world[3], float r_normal_world[3])
|
||||||
{
|
{
|
||||||
View3D *v3d = cdd->vc.v3d;
|
View3D *v3d = cdd->vc.v3d;
|
||||||
@ -307,10 +311,11 @@ static bool stroke_elem_project(
|
|||||||
zero_v3(r_normal_world);
|
zero_v3(r_normal_world);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (radius_offset != 0.0f) {
|
if (surface_offset != 0.0f) {
|
||||||
|
const float offset = cdd->project.use_surface_offset_absolute ? 1.0f : radius;
|
||||||
float normal[3];
|
float normal[3];
|
||||||
if (depth_read_normal(&cdd->vc, &cdd->mats, mval_i, normal)) {
|
if (depth_read_normal(&cdd->vc, &cdd->mats, mval_i, normal)) {
|
||||||
madd_v3_v3fl(r_location_world, normal, radius_offset * radius);
|
madd_v3_v3fl(r_location_world, normal, offset * surface_offset);
|
||||||
if (r_normal_world) {
|
if (r_normal_world) {
|
||||||
copy_v3_v3(r_normal_world, normal);
|
copy_v3_v3(r_normal_world, normal);
|
||||||
}
|
}
|
||||||
@ -333,14 +338,14 @@ static bool stroke_elem_project(
|
|||||||
static bool stroke_elem_project_fallback(
|
static bool stroke_elem_project_fallback(
|
||||||
const struct CurveDrawData *cdd,
|
const struct CurveDrawData *cdd,
|
||||||
const int mval_i[2], const float mval_fl[2],
|
const int mval_i[2], const float mval_fl[2],
|
||||||
const float radius_offset, const float radius,
|
const float surface_offset, const float radius,
|
||||||
const float location_fallback_depth[3],
|
const float location_fallback_depth[3],
|
||||||
float r_location_world[3], float r_location_local[3],
|
float r_location_world[3], float r_location_local[3],
|
||||||
float r_normal_world[3], float r_normal_local[3])
|
float r_normal_world[3], float r_normal_local[3])
|
||||||
{
|
{
|
||||||
bool is_depth_found = stroke_elem_project(
|
bool is_depth_found = stroke_elem_project(
|
||||||
cdd, mval_i, mval_fl,
|
cdd, mval_i, mval_fl,
|
||||||
radius_offset, radius,
|
surface_offset, radius,
|
||||||
r_location_world, r_normal_world);
|
r_location_world, r_normal_world);
|
||||||
if (is_depth_found == false) {
|
if (is_depth_found == false) {
|
||||||
ED_view3d_win_to_3d(cdd->vc.ar, location_fallback_depth, mval_fl, r_location_world);
|
ED_view3d_win_to_3d(cdd->vc.ar, location_fallback_depth, mval_fl, r_location_world);
|
||||||
@ -372,7 +377,7 @@ static bool stroke_elem_project_fallback_elem(
|
|||||||
const float radius = stroke_elem_radius(cdd, selem);
|
const float radius = stroke_elem_radius(cdd, selem);
|
||||||
return stroke_elem_project_fallback(
|
return stroke_elem_project_fallback(
|
||||||
cdd, mval_i, selem->mval,
|
cdd, mval_i, selem->mval,
|
||||||
cdd->radius.offset, radius,
|
cdd->project.surface_offset, radius,
|
||||||
location_fallback_depth,
|
location_fallback_depth,
|
||||||
selem->location_world, selem->location_local,
|
selem->location_world, selem->location_local,
|
||||||
selem->normal_world, selem->normal_local);
|
selem->normal_world, selem->normal_local);
|
||||||
@ -637,7 +642,7 @@ static void curve_draw_event_add_first(wmOperator *op, const wmEvent *event)
|
|||||||
|
|
||||||
/* Special case for when we only have offset applied on the first-hit,
|
/* Special case for when we only have offset applied on the first-hit,
|
||||||
* the remaining stroke must be offset too. */
|
* the remaining stroke must be offset too. */
|
||||||
if (cdd->radius.offset != 0.0f) {
|
if (cdd->project.surface_offset != 0.0f) {
|
||||||
const float mval_fl[2] = {UNPACK2(event->mval)};
|
const float mval_fl[2] = {UNPACK2(event->mval)};
|
||||||
|
|
||||||
float location_no_offset[3];
|
float location_no_offset[3];
|
||||||
@ -688,7 +693,8 @@ static bool curve_draw_init(bContext *C, wmOperator *op, bool is_invoke)
|
|||||||
cdd->radius.min = cps->radius_min;
|
cdd->radius.min = cps->radius_min;
|
||||||
cdd->radius.max = cps->radius_max;
|
cdd->radius.max = cps->radius_max;
|
||||||
cdd->radius.range = cps->radius_max - cps->radius_min;
|
cdd->radius.range = cps->radius_max - cps->radius_min;
|
||||||
cdd->radius.offset = cps->radius_offset;
|
cdd->project.surface_offset = cps->surface_offset;
|
||||||
|
cdd->project.use_surface_offset_absolute = (cps->flag & CURVE_PAINT_FLAG_DEPTH_STROKE_OFFSET_ABS) != 0;
|
||||||
|
|
||||||
cdd->stroke_elem_pool = BLI_mempool_create(
|
cdd->stroke_elem_pool = BLI_mempool_create(
|
||||||
sizeof(struct StrokeElem), 0, 512, BLI_MEMPOOL_ALLOW_ITER);
|
sizeof(struct StrokeElem), 0, 512, BLI_MEMPOOL_ALLOW_ITER);
|
||||||
|
@ -1275,7 +1275,7 @@ typedef struct CurvePaintSettings {
|
|||||||
int error_threshold;
|
int error_threshold;
|
||||||
float radius_min, radius_max;
|
float radius_min, radius_max;
|
||||||
float radius_taper_start, radius_taper_end;
|
float radius_taper_start, radius_taper_end;
|
||||||
float radius_offset;
|
float surface_offset;
|
||||||
float corner_angle;
|
float corner_angle;
|
||||||
} CurvePaintSettings;
|
} CurvePaintSettings;
|
||||||
|
|
||||||
@ -1284,6 +1284,7 @@ enum {
|
|||||||
CURVE_PAINT_FLAG_CORNERS_DETECT = (1 << 0),
|
CURVE_PAINT_FLAG_CORNERS_DETECT = (1 << 0),
|
||||||
CURVE_PAINT_FLAG_PRESSURE_RADIUS = (1 << 1),
|
CURVE_PAINT_FLAG_PRESSURE_RADIUS = (1 << 1),
|
||||||
CURVE_PAINT_FLAG_DEPTH_STROKE_ENDPOINTS = (1 << 2),
|
CURVE_PAINT_FLAG_DEPTH_STROKE_ENDPOINTS = (1 << 2),
|
||||||
|
CURVE_PAINT_FLAG_DEPTH_STROKE_OFFSET_ABS = (1 << 3),
|
||||||
};
|
};
|
||||||
|
|
||||||
/* CurvePaintSettings.depth_mode */
|
/* CurvePaintSettings.depth_mode */
|
||||||
|
@ -2639,6 +2639,10 @@ static void rna_def_curve_paint_settings(BlenderRNA *brna)
|
|||||||
RNA_def_property_boolean_sdna(prop, NULL, "flag", CURVE_PAINT_FLAG_DEPTH_STROKE_ENDPOINTS);
|
RNA_def_property_boolean_sdna(prop, NULL, "flag", CURVE_PAINT_FLAG_DEPTH_STROKE_ENDPOINTS);
|
||||||
RNA_def_property_ui_text(prop, "Only First", "Use the start of the stroke for the depth");
|
RNA_def_property_ui_text(prop, "Only First", "Use the start of the stroke for the depth");
|
||||||
|
|
||||||
|
prop = RNA_def_property(srna, "use_offset_absolute", PROP_BOOLEAN, PROP_NONE);
|
||||||
|
RNA_def_property_boolean_sdna(prop, NULL, "flag", CURVE_PAINT_FLAG_DEPTH_STROKE_OFFSET_ABS);
|
||||||
|
RNA_def_property_ui_text(prop, "Absolute Offset", "Apply a fixed offset (don't scale by the radius)");
|
||||||
|
|
||||||
prop = RNA_def_property(srna, "error_threshold", PROP_INT, PROP_PIXEL);
|
prop = RNA_def_property(srna, "error_threshold", PROP_INT, PROP_PIXEL);
|
||||||
RNA_def_property_range(prop, 1, 100);
|
RNA_def_property_range(prop, 1, 100);
|
||||||
RNA_def_property_ui_text(prop, "Tolerance", "Allow deviation for a smoother, less precise line");
|
RNA_def_property_ui_text(prop, "Tolerance", "Allow deviation for a smoother, less precise line");
|
||||||
@ -2669,7 +2673,7 @@ static void rna_def_curve_paint_settings(BlenderRNA *brna)
|
|||||||
RNA_def_property_ui_range(prop, 0.0f, 1.0, 1, 2);
|
RNA_def_property_ui_range(prop, 0.0f, 1.0, 1, 2);
|
||||||
RNA_def_property_ui_text(prop, "Radius Max", "Taper factor for the radius of each point along the curve");
|
RNA_def_property_ui_text(prop, "Radius Max", "Taper factor for the radius of each point along the curve");
|
||||||
|
|
||||||
prop = RNA_def_property(srna, "radius_offset", PROP_FLOAT, PROP_NONE);
|
prop = RNA_def_property(srna, "surface_offset", PROP_FLOAT, PROP_NONE);
|
||||||
RNA_def_property_range(prop, -10.0, 10.0);
|
RNA_def_property_range(prop, -10.0, 10.0);
|
||||||
RNA_def_property_ui_range(prop, -1.0f, 1.0, 1, 2);
|
RNA_def_property_ui_range(prop, -1.0f, 1.0, 1, 2);
|
||||||
RNA_def_property_ui_text(prop, "Offset", "Offset the stroke from the surface");
|
RNA_def_property_ui_text(prop, "Offset", "Offset the stroke from the surface");
|
||||||
|
Loading…
Reference in New Issue
Block a user