[Bf-blender-cvs] [d6d1ddbf0b8] sculpt-dev: Sculpt-dev: Roll brush tests.
Joseph Eagar
noreply at git.blender.org
Tue May 17 09:20:44 CEST 2022
Commit: d6d1ddbf0b837a02a2bfd901860e007e65914d2a
Author: Joseph Eagar
Date: Tue May 17 00:12:44 2022 -0700
Branches: sculpt-dev
https://developer.blender.org/rBd6d1ddbf0b837a02a2bfd901860e007e65914d2a
Sculpt-dev: Roll brush tests.
Wrote test code for a "roll" texture mapping
mode. This is purely a development test, there
is no user-visible functionality here.
===================================================================
M source/blender/blenkernel/intern/brush.c
M source/blender/editors/sculpt_paint/paint_intern.h
M source/blender/editors/sculpt_paint/paint_stroke.c
M source/blender/editors/sculpt_paint/sculpt.c
M source/blender/editors/sculpt_paint/sculpt_intern.h
M source/blender/makesdna/DNA_texture_types.h
M source/blender/makesrna/intern/rna_brush.c
===================================================================
diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c
index 43e5914f167..376e7d9b445 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -2307,6 +2307,13 @@ float BKE_brush_sample_tex_3d(const Scene *scene,
invradius = 1.0f / ups->pixel_radius;
}
+ else if (mtex->brush_map_mode == MTEX_MAP_MODE_ROLL) {
+ // XXX implement me
+ x = point_2d[0] - ups->tex_mouse[0];
+ y = point_2d[1] - ups->tex_mouse[1];
+
+ invradius = 1.0f / ups->pixel_radius;
+ }
x *= invradius;
y *= invradius;
diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h
index cf98922aa99..73a2bb0a1e6 100644
--- a/source/blender/editors/sculpt_paint/paint_intern.h
+++ b/source/blender/editors/sculpt_paint/paint_intern.h
@@ -9,9 +9,9 @@
#include "BKE_paint.h"
-#include "BLI_rect.h"
#include "BLI_compiler_compat.h"
#include "BLI_math.h"
+#include "BLI_rect.h"
#include "DNA_scene_types.h"
@@ -87,8 +87,16 @@ typedef struct PaintStroke {
float last_mouse_position[2];
float last_world_space_position[3];
+
+ float mouse_cubic[4][2];
+ float world_cubic[4][3];
+
+ bool has_cubic_stroke;
+
bool stroke_over_mesh;
+
/* space distance covered so far */
+ int stroke_sample_index;
float stroke_distance;
float stroke_distance_t; // divided by brush radius
@@ -109,6 +117,8 @@ typedef struct PaintStroke {
float cached_size_pressure;
/* last pressure will store last pressure value for use in interpolation for space strokes */
float last_pressure;
+ float last_pressure2;
+
int stroke_mode;
float last_tablet_event_pressure;
@@ -608,6 +618,8 @@ void paint_delete_blur_kernel(BlurKernel *);
/* paint curve defines */
#define PAINT_CURVE_NUM_SEGMENTS 40
+bool paint_stroke_has_cubic(const PaintStroke *stroke);
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c
index 43c3ede9aea..5687e104e4f 100644
--- a/source/blender/editors/sculpt_paint/paint_stroke.c
+++ b/source/blender/editors/sculpt_paint/paint_stroke.c
@@ -166,8 +166,9 @@ static bool paint_stroke_use_scene_spacing(ToolSettings *ts, Brush *brush, ePain
{
switch (mode) {
case PAINT_MODE_SCULPT:
- return BRUSHSET_GET_FINAL_BOOL(brush->channels, ts->sculpt->channels, use_scene_spacing, NULL);
- //return brush->flag & BRUSH_SCENE_SPACING;
+ return BRUSHSET_GET_FINAL_BOOL(
+ brush->channels, ts->sculpt->channels, use_scene_spacing, NULL);
+ // return brush->flag & BRUSH_SCENE_SPACING;
default:
break;
}
@@ -460,7 +461,7 @@ static bool paint_stroke_use_jitter(ePaintMode mode, Brush *brush, bool invert)
}
/* Put the location of the next stroke dot into the stroke RNA and apply it to the mesh */
-static void paint_brush_stroke_add_step(
+ATTR_NO_OPT static void paint_brush_stroke_add_step(
bContext *C, wmOperator *op, PaintStroke *stroke, const float mouse_in[2], float pressure)
{
Scene *scene = CTX_data_scene(C);
@@ -472,6 +473,8 @@ static void paint_brush_stroke_add_step(
PointerRNA itemptr;
float location[3];
+ stroke->stroke_sample_index++;
+
/* the following code is adapted from texture paint. It may not be needed but leaving here
* just in case for reference (code in texpaint removed as part of refactoring).
* It's strange that only texpaint had these guards. */
@@ -502,6 +505,7 @@ static void paint_brush_stroke_add_step(
/* copy last position -before- jittering, or space fill code
* will create too many dabs */
copy_v2_v2(stroke->last_mouse_position, mouse_in);
+ stroke->last_pressure2 = stroke->last_pressure;
stroke->last_pressure = pressure;
if (paint_stroke_use_scene_spacing(scene->toolsettings, brush, mode)) {
@@ -566,6 +570,10 @@ static void paint_brush_stroke_add_step(
RNA_float_set(&itemptr, "x_tilt", stroke->x_tilt);
RNA_float_set(&itemptr, "y_tilt", stroke->y_tilt);
+ if (stroke->has_cubic_stroke) {
+ RNA_float_set_array(&itemptr, "mouse_cubic", (float *)stroke->mouse_cubic);
+ }
+
stroke->update_step(C, op, stroke, &itemptr);
/* don't record this for now, it takes up a lot of memory when doing long
@@ -656,7 +664,7 @@ static float paint_space_stroke_spacing(bContext *C,
}
/* apply spacing pressure */
- //mapping.pressure = 1.5f - spacing_pressure;
+ // mapping.pressure = 1.5f - spacing_pressure;
mapping.pressure = spacing_pressure;
if (ss->cache && ss->cache->channels_final) {
@@ -830,11 +838,11 @@ static float paint_space_stroke_spacing_variable(bContext *C,
/* For brushes with stroke spacing enabled, moves mouse in steps
* towards the final mouse location. */
-static int paint_space_stroke(bContext *C,
- wmOperator *op,
- PaintStroke *stroke,
- const float final_mouse[2],
- float final_pressure)
+ATTR_NO_OPT static int paint_space_stroke(bContext *C,
+ wmOperator *op,
+ PaintStroke *stroke,
+ const float final_mouse[2],
+ float final_pressure)
{
const Scene *scene = CTX_data_scene(C);
ARegion *region = CTX_wm_region(C);
@@ -855,6 +863,11 @@ static int paint_space_stroke(bContext *C,
sub_v2_v2v2(dmouse, final_mouse, stroke->last_mouse_position);
float length = normalize_v2(dmouse);
+ /* normalize_v2 is giving inf on negative zero*/
+ if (isinf(length)) {
+ length = 0.0f;
+ }
+
if (use_scene_spacing) {
float world_space_position[3];
bool hit = SCULPT_stroke_get_location(C, world_space_position, final_mouse);
@@ -927,14 +940,14 @@ static int paint_space_stroke(bContext *C,
/**** Public API ****/
-PaintStroke *paint_stroke_new(bContext *C,
- wmOperator *op,
- StrokeGetLocation get_location,
- StrokeTestStart test_start,
- StrokeUpdateStep update_step,
- StrokeRedraw redraw,
- StrokeDone done,
- int event_type)
+ATTR_NO_OPT PaintStroke *paint_stroke_new(bContext *C,
+ wmOperator *op,
+ StrokeGetLocation get_location,
+ StrokeTestStart test_start,
+ StrokeUpdateStep update_step,
+ StrokeRedraw redraw,
+ StrokeDone done,
+ int event_type)
{
struct Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
PaintStroke *stroke = MEM_callocN(sizeof(PaintStroke), "PaintStroke");
@@ -959,6 +972,10 @@ PaintStroke *paint_stroke_new(bContext *C,
get_imapaint_zoom(C, &zoomx, &zoomy);
stroke->zoom_2d = max_ff(zoomx, zoomy);
+ stroke->has_cubic_stroke = ELEM(
+ MTEX_MAP_MODE_ROLL, br->mtex.brush_map_mode, br->mask_mtex.brush_map_mode);
+ stroke->stroke_sample_index = 0;
+
if (stroke->stroke_mode == BRUSH_STROKE_INVERT) {
if (br->flag & BRUSH_CURVE) {
RNA_enum_set(op->ptr, "mode", BRUSH_STROKE_NORMAL);
@@ -1184,12 +1201,21 @@ struct wmKeyMap *paint_stroke_modal_keymap(struct wmKeyConfig *keyconf)
return keymap;
}
+bool paint_stroke_has_cubic(const PaintStroke *stroke)
+{
+ return stroke->has_cubic_stroke;
+}
+
static void paint_stroke_add_sample(
const Paint *paint, PaintStroke *stroke, float x, float y, float pressure)
{
PaintSample *sample = &stroke->samples[stroke->cur_sample];
int max_samples = CLAMPIS(paint->num_input_samples, 1, PAINT_MAX_INPUT_SAMPLES);
+ if (stroke->has_cubic_stroke) {
+ max_samples = max_ii(max_samples, 5);
+ }
+
sample->mouse[0] = x;
sample->mouse[1] = y;
sample->pressure = pressure;
@@ -1238,7 +1264,8 @@ static void paint_line_strokes_spacing(bContext *C,
ePaintMode mode = BKE_paintmode_get_active_from_context(C);
ARegion *region = CTX_wm_region(C);
- const bool use_scene_spacing = paint_stroke_use_scene_spacing(CTX_data_scene(C)->toolsettings, brush, mode);
+ const bool use_scene_spacing = paint_stroke_use_scene_spacing(
+ CTX_data_scene(C)->toolsettings, brush, mode);
float mouse[2], dmouse[2];
float length;
@@ -1395,7 +1422,8 @@ static bool paint_stroke_curve_end(bContext *C, wmOperator *op, PaintStroke *str
stroke->last_pressure = 1.0;
copy_v2_v2(stroke->last_mouse_position, data + 2 * j);
- if (paint_stroke_use_scene_spacing(scene->toolsettings, br, BKE_paintmode_get_active_from_context(C))) {
+ if (paint_stroke_use_scene_spacing(
+ scene->toolsettings, br, BKE_paintmode_get_active_from_context(C))) {
stroke->stroke_over_mesh = SCULPT_stroke_get_location(
C, stroke->last_world_space_position, data + 2 * j);
mul_m4_v3(stroke->vc.obact->obmat, stroke->last_world_space_position);
@@ -1405,6 +1433,11 @@ static bool paint_stroke_curve_end(bContext *C, wmOperator *op, PaintStroke *str
if (stroke->stroke_started) {
paint_brush_stroke_add_step(C, op, stroke, data + 2 * j, 1.0);
+
+ if (stroke->has_cubic_stroke) {
+ paint_brush_stroke_add_step(C, op, stroke, data + 2 * j, 1.0);
+ }
+
paint_line_strokes_spacing(
C, op, stroke, spacing, &length_residue, data + 2 * j, data + 2 * (j + 1));
}
@@ -1457,7 +1490,10 @@ static void paint_stroke_line_constrain(PaintStroke *stroke, float mouse[2])
}
}
-int paint_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event, PaintStroke **stroke_p)
+ATTR_NO_OPT int paint_stroke_modal(bContext *C,
+ wmOperator *op,
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list