Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/sculpt_paint/paint_stroke.c
| Show First 20 Lines • Show All 1,178 Lines • ▼ Show 20 Lines | static void paint_line_strokes_spacing(bContext *C, | ||||
| wmOperator *op, | wmOperator *op, | ||||
| PaintStroke *stroke, | PaintStroke *stroke, | ||||
| float spacing, | float spacing, | ||||
| float *length_residue, | float *length_residue, | ||||
| const float old_pos[2], | const float old_pos[2], | ||||
| const float new_pos[2]) | const float new_pos[2]) | ||||
| { | { | ||||
| UnifiedPaintSettings *ups = stroke->ups; | UnifiedPaintSettings *ups = stroke->ups; | ||||
| Paint *paint = BKE_paint_get_active_from_context(C); | |||||
| Brush *brush = BKE_paint_brush(paint); | |||||
| 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(brush, mode); | |||||
| float mouse[2], dmouse[2]; | float mouse[2], dmouse[2]; | ||||
| float length; | float length; | ||||
| float d_world_space_position[3] = {0.0f}; | |||||
| float world_space_position_old[3], world_space_position_new[3]; | |||||
| sub_v2_v2v2(dmouse, new_pos, old_pos); | |||||
| copy_v2_v2(stroke->last_mouse_position, old_pos); | copy_v2_v2(stroke->last_mouse_position, old_pos); | ||||
| if (use_scene_spacing) { | |||||
| bool hit_old = SCULPT_stroke_get_location(C, world_space_position_old, old_pos); | |||||
| bool hit_new = SCULPT_stroke_get_location(C, world_space_position_new, new_pos); | |||||
| mul_m4_v3(stroke->vc.obact->obmat, world_space_position_old); | |||||
| mul_m4_v3(stroke->vc.obact->obmat, world_space_position_new); | |||||
| if (hit_old && hit_new && stroke->stroke_over_mesh) { | |||||
| sub_v3_v3v3(d_world_space_position, world_space_position_new, world_space_position_old); | |||||
| length = len_v3(d_world_space_position); | |||||
| stroke->stroke_over_mesh = true; | |||||
| } | |||||
| else { | |||||
| length = 0.0f; | |||||
| zero_v3(d_world_space_position); | |||||
| stroke->stroke_over_mesh = hit_new; | |||||
| if (stroke->stroke_over_mesh) { | |||||
| copy_v3_v3(stroke->last_world_space_position, world_space_position_old); | |||||
| } | |||||
| } | |||||
| } | |||||
| else { | |||||
| sub_v2_v2v2(dmouse, new_pos, old_pos); | |||||
| length = normalize_v2(dmouse); | length = normalize_v2(dmouse); | ||||
| } | |||||
| BLI_assert(length >= 0.0f); | BLI_assert(length >= 0.0f); | ||||
| if (length == 0.0f) { | if (length == 0.0f) { | ||||
| return; | return; | ||||
| } | } | ||||
| while (length > 0.0f) { | while (length > 0.0f) { | ||||
| float spacing_final = spacing - *length_residue; | float spacing_final = spacing - *length_residue; | ||||
| length += *length_residue; | length += *length_residue; | ||||
| *length_residue = 0.0; | *length_residue = 0.0; | ||||
| if (length >= spacing) { | if (length >= spacing) { | ||||
| if (use_scene_spacing) { | |||||
| float final_world_space_position[3]; | |||||
| normalize_v3(d_world_space_position); | |||||
| mul_v3_v3fl(final_world_space_position, d_world_space_position, spacing_final); | |||||
| add_v3_v3v3( | |||||
| final_world_space_position, world_space_position_old, final_world_space_position); | |||||
| ED_view3d_project(region, final_world_space_position, mouse); | |||||
| } | |||||
| else { | |||||
| mouse[0] = stroke->last_mouse_position[0] + dmouse[0] * spacing_final; | mouse[0] = stroke->last_mouse_position[0] + dmouse[0] * spacing_final; | ||||
| mouse[1] = stroke->last_mouse_position[1] + dmouse[1] * spacing_final; | mouse[1] = stroke->last_mouse_position[1] + dmouse[1] * spacing_final; | ||||
| } | |||||
| ups->overlap_factor = paint_stroke_integrate_overlap(stroke->brush, 1.0); | ups->overlap_factor = paint_stroke_integrate_overlap(stroke->brush, 1.0); | ||||
| stroke->stroke_distance += spacing / stroke->zoom_2d; | stroke->stroke_distance += spacing / stroke->zoom_2d; | ||||
| paint_brush_stroke_add_step(C, op, mouse, 1.0); | paint_brush_stroke_add_step(C, op, mouse, 1.0); | ||||
| length -= spacing; | length -= spacing; | ||||
| spacing_final = spacing; | spacing_final = spacing; | ||||
| ▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | for (i = 0; i < pc->tot_points - 1; i++, pcp++) { | ||||
| if (do_rake) { | if (do_rake) { | ||||
| float rotation = atan2f(tangents[2 * j], tangents[2 * j + 1]); | float rotation = atan2f(tangents[2 * j], tangents[2 * j + 1]); | ||||
| paint_update_brush_rake_rotation(ups, br, rotation); | paint_update_brush_rake_rotation(ups, br, rotation); | ||||
| } | } | ||||
| if (!stroke->stroke_started) { | if (!stroke->stroke_started) { | ||||
| stroke->last_pressure = 1.0; | stroke->last_pressure = 1.0; | ||||
| copy_v2_v2(stroke->last_mouse_position, data + 2 * j); | copy_v2_v2(stroke->last_mouse_position, data + 2 * j); | ||||
| if (paint_stroke_use_scene_spacing(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); | |||||
| } | |||||
| stroke->stroke_started = stroke->test_start(C, op, stroke->last_mouse_position); | stroke->stroke_started = stroke->test_start(C, op, stroke->last_mouse_position); | ||||
| if (stroke->stroke_started) { | if (stroke->stroke_started) { | ||||
| paint_brush_stroke_add_step(C, op, data + 2 * j, 1.0); | paint_brush_stroke_add_step(C, op, data + 2 * j, 1.0); | ||||
| paint_line_strokes_spacing( | paint_line_strokes_spacing( | ||||
| C, op, stroke, spacing, &length_residue, data + 2 * j, data + 2 * (j + 1)); | C, op, stroke, spacing, &length_residue, data + 2 * j, data + 2 * (j + 1)); | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 321 Lines • Show Last 20 Lines | |||||