10#include <fmt/format.h>
197 if (
math::mod(point, num_shared_points) == 0) {
221 colors.
fill(color_gizmo_primary);
222 sizes.
fill(size_primary);
227 colors.
fill(color_gizmo_primary);
228 sizes.
fill(size_primary);
235 colors.
fill(color_gizmo_secondary);
236 sizes.
fill(size_secondary);
242 colors[
i] = color_gizmo_b;
243 sizes[
i] = size_tertiary;
247 colors.
last() = color_gizmo_primary;
248 sizes.
last() = size_tertiary;
251 colors.
last(1) = color_gizmo_secondary;
252 sizes.
last(1) = size_primary;
257 if (active_index != -1) {
258 sizes[active_index] *= 1.5;
259 colors[active_index] =
math::interpolate(colors[active_index], color_gizmo_a, 0.5f);
282 const float size = sizes[point];
319 const int new_points_num = new_positions.
size();
322 new_positions.
fill(control_points.
last());
330 const float t =
math::mod(
i /
float(subdivision + 1), 1.0f);
331 const int point = int(
i / (subdivision + 1));
332 const int point_next = point + 1;
333 new_positions[
i] =
math::interpolate(control_points[point], control_points[point_next], t);
335 new_positions.
last() = control_points.
last();
340 const int num_segments = ptd.
segments;
341 for (
const int segment_i :
IndexRange(num_segments)) {
342 const float2 A = control_points[num_shared_points * segment_i + 0];
343 const float2 B = control_points[num_shared_points * segment_i + 1];
344 const float2 C = control_points[num_shared_points * segment_i + 2];
346 const float t =
i / float(subdivision + 1);
352 new_positions.
last() = control_points.
last();
357 const int num_segments = ptd.
segments;
359 for (
const int segment_i :
IndexRange(num_segments)) {
360 const float2 A = control_points[num_shared_points * segment_i + 0];
361 const float2 B = control_points[num_shared_points * segment_i + 1];
362 const float2 C = control_points[num_shared_points * segment_i + 2];
363 const float2 D = control_points[num_shared_points * segment_i + 3];
365 const float t =
i / float(subdivision + 1);
374 new_positions.
last() = control_points.
last();
381 const float t =
i / float(new_points_num);
409 const float t =
math::mod(
i /
float(subdivision + 1), 1.0f);
410 const int point = int(
i / (subdivision + 1));
411 const int point_next =
math::mod(point + 1, 4);
446 const int join_points = ptd.
segments + 1;
447 return join_points + subdivision * ptd.
segments;
451 return 4 + subdivision * 4;
462 const bool on_back = ptd.
on_back;
467 const int target_curve_index = on_back ? 0 :
curves.curves_range().last();
470 const IndexRange curve_points =
curves.points_by_curve()[target_curve_index];
487 rotations =
curves.attributes_for_write().lookup_or_add_for_write_span<
float>(
489 new_rotations = rotations.
span.slice(curve_points);
498 for (
const int point : curve_points.
index_range()) {
499 float pressure = 1.0f;
502 const float t = point / float(new_points_num - 1);
517 lengths[point] = 0.0f;
520 const float distance_2d =
math::distance(positions_2d[point - 1], positions_2d[point]);
521 lengths[point] = lengths[point - 1] + distance_2d;
529 std::optional<BrushColorJitterSettings> jitter_settings =
547 point_attributes_to_skip.
add_multiple({
"position",
"radius",
"opacity"});
549 point_attributes_to_skip.
add(
"vertex_color");
552 point_attributes_to_skip.
add(
"rotation");
573 const bool on_back = ptd.
on_back;
576 const int target_curve_index = on_back ? 0 : (
curves.curves_num() - 1);
585 curve_attributes_to_skip.
add(
"material_index");
592 curve_attributes_to_skip.
add(
"cyclic");
597 softness.span[target_curve_index] = ptd.
softness;
599 curve_attributes_to_skip.
add(
"softness");
609 curve_attributes_to_skip.
add(
"start_cap");
619 curve_attributes_to_skip.
add(
"end_cap");
630 fill_opacities.span[target_curve_index] = ptd.
fill_opacity;
631 fill_opacities.finish();
632 curve_attributes_to_skip.
add(
"fill_opacity");
638 curve_attributes_to_skip.
add(
"fill_color");
644 u_scale.span[target_curve_index] = 1.0f;
646 curve_attributes_to_skip.
add(
"u_scale");
650 curves.update_curve_types();
651 curve_attributes_to_skip.
add(
"curve_type");
657 on_back ?
curves.curves_range().take_front(1) :
658 curves.curves_range().take_back(1));
665 const int target_curve_index = ptd.
on_back ? 0 : (
curves.curves_num() - 1);
679 status.
item(
IFACE_(
"Align"), ICON_EVENT_SHIFT);
685 status.
item(
IFACE_(
"Center"), ICON_EVENT_ALT);
808 if (use_vertex_color) {
813 std::make_optional(color_base) :
816 std::make_optional(color_base) :
841 BLI_assert(grease_pencil->has_active_layer());
842 ptd.
local_transform = grease_pencil->get_active_layer()->local_transform();
843 ptd.
drawing = grease_pencil->get_editable_drawing_at(*grease_pencil->get_active_layer(),
871 if (do_automerge_endpoints && !cancelled) {
876 constexpr float merge_distance = 30.0f;
885 *
CTX_wm_region(
C), src_curves, layer_to_world, merge_distance, selection, {});
901 MEM_delete<PrimitiveToolOperation>(ptd);
908 using namespace math;
915 using namespace math;
922 using namespace math;
924 const float sin225 = 0.3826834323650897717284599840304f;
931 using namespace math;
935 const float2 dif = end - start;
951 float2 center = start + offset;
962 for (
const int i :
IndexRange(number_control_points + 1)) {
964 end_pos, start_pos, (
i /
float(number_control_points)));
973 const float2 dif = end - start;
1009 (other_point_2d +
float2(event->
mval)) / 2.0f);
1017 const float2 dif = end - start;
1037 return center_of_mass;
1048 const float2 end_ = end - center_of_mass;
1049 const float2 start_ = start - center_of_mass;
1055 const float2 dif = start_pos2 - center_of_mass;
1059 const float2 pos2 =
rot * dif + center_of_mass;
1078 const float2 pos2 = (start_pos2 - center_of_mass) * scale + center_of_mass;
1087 const int value =
RNA_int_get(&brush_ptr,
"size");
1124 const int new_value = std::max(
int(delta.x), 1);
1138 mouse_co.x - display_size);
1140 const float new_value = delta.x / display_size;
1148 float closest_distance_squared = std::numeric_limits<float>::max();
1149 int closest_point = -1;
1157 if (distance_squared <= radius_sq) {
1164 if (distance_squared < closest_distance_squared &&
1168 closest_point = point;
1169 closest_distance_squared = distance_squared;
1173 if (closest_point != -1) {
1174 return closest_point;
1211 switch (event->
val) {
1490 switch (event->
type) {
1547 const int default_subdiv,
1557 {0,
nullptr, 0,
nullptr,
nullptr},
1568 "Number of subdivisions per segment",
1574 ot->srna,
"type", grease_pencil_primitive_type,
int(default_type),
"Type",
"Type of shape");
1580 ot->name =
"Grease Pencil Line Shape";
1581 ot->idname =
"GREASE_PENCIL_OT_primitive_line";
1582 ot->description =
"Create predefined Grease Pencil stroke lines";
1599 ot->name =
"Grease Pencil Polyline Shape";
1600 ot->idname =
"GREASE_PENCIL_OT_primitive_polyline";
1601 ot->description =
"Create predefined Grease Pencil stroke polylines";
1618 ot->name =
"Grease Pencil Arc Shape";
1619 ot->idname =
"GREASE_PENCIL_OT_primitive_arc";
1620 ot->description =
"Create predefined Grease Pencil stroke arcs";
1637 ot->name =
"Grease Pencil Curve Shape";
1638 ot->idname =
"GREASE_PENCIL_OT_primitive_curve";
1639 ot->description =
"Create predefined Grease Pencil stroke curve shapes";
1656 ot->name =
"Grease Pencil Box Shape";
1657 ot->idname =
"GREASE_PENCIL_OT_primitive_box";
1658 ot->description =
"Create predefined Grease Pencil stroke boxes";
1675 ot->name =
"Grease Pencil Circle Shape";
1676 ot->idname =
"GREASE_PENCIL_OT_primitive_circle";
1677 ot->description =
"Create predefined Grease Pencil stroke circles";
1716 "INCREASE_SUBDIVISION",
1718 "Increase Subdivision",
1721 "DECREASE_SUBDIVISION",
1723 "Decrease Subdivision",
1727 {0,
nullptr, 0,
nullptr,
nullptr},
const std::optional< BrushColorJitterSettings > BKE_brush_color_jitter_get_settings(const Scene *scene, const Paint *paint, const Brush *brush)
void BKE_brush_init_gpencil_settings(Brush *brush)
wmWindow * CTX_wm_window(const bContext *C)
Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
Scene * CTX_data_scene(const bContext *C)
Main * CTX_data_main(const bContext *C)
ARegion * CTX_wm_region(const bContext *C)
View3D * CTX_wm_view3d(const bContext *C)
Low-level operations for curves.
Low-level operations for grease pencil.
Material * BKE_grease_pencil_object_material_ensure_from_brush(Main *bmain, Object *ob, Brush *brush)
General operations, lookup, etc. for materials.
int BKE_object_material_index_get(Object *ob, const Material *ma)
Brush * BKE_paint_brush(Paint *paint)
#define BLI_assert_unreachable()
void srgb_to_linearrgb_v3_v3(float linear[3], const float srgb[3])
void DEG_id_tag_update(ID *id, unsigned int flags)
@ GP_STROKE_CAP_TYPE_ROUND
@ GP_SCULPT_SETT_FLAG_PRIMITIVE_CURVE
@ GPPAINT_FLAG_USE_VERTEXCOLOR
@ GP_TOOL_FLAG_PAINT_ONBACK
@ GP_TOOL_FLAG_AUTOMERGE_STROKE
@ OP_IS_MODAL_CURSOR_REGION
void ED_workspace_status_text(bContext *C, const char *str)
void ED_region_tag_redraw(ARegion *region)
void * ED_region_draw_cb_activate(ARegionType *art, void(*draw)(const bContext *, ARegion *, void *), void *customdata, int type)
#define REGION_DRAW_POST_VIEW
bool ED_region_draw_cb_exit(ARegionType *art, void *handle)
blender::float2 ED_view3d_project_float_v2_m4(const ARegion *region, const float co[3], const blender::float4x4 &mat)
ViewContext ED_view3d_viewcontext_init(bContext *C, Depsgraph *depsgraph)
void ED_view3d_navigation_free(bContext *C, ViewOpsData *vod)
blender::float4x4 ED_view3d_ob_project_mat_get(const RegionView3D *rv3d, const Object *ob)
bool ED_view3d_navigation_do(bContext *C, ViewOpsData *vod, const wmEvent *event, const float depth_loc_override[3])
ViewOpsData * ED_view3d_navigation_init(bContext *C, const wmKeyMapItem *kmi_merge)
@ GPU_SHADER_3D_POINT_VARYING_SIZE_VARYING_COLOR
void GPU_program_point_size(bool enable)
void UI_GetThemeColor4fv(int colorid, float col[4])
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
SIMD_FORCE_INLINE btScalar length() const
Return the length of the vector.
constexpr MutableSpan slice(const int64_t start, const int64_t size) const
void item(std::string text, int icon1, int icon2=0)
void opmodal(std::string text, const wmOperatorType *ot, int propvalue, bool inverted=false)
constexpr int64_t first() const
constexpr IndexRange drop_back(int64_t n) const
constexpr int64_t last(const int64_t n=0) const
static constexpr IndexRange from_single(const int64_t index)
constexpr IndexRange index_range() const
constexpr int64_t size() const
constexpr void fill(const T &value) const
constexpr IndexRange index_range() const
constexpr T & last(const int64_t n=0) const
static RandomNumberGenerator from_random_seed()
void add_multiple(Span< Key > keys)
constexpr const T & last(const int64_t n=0) const
static VArray ForSingle(T value, const int64_t size)
bool contains(StringRef attribute_id) const
IndexRange curves_range() const
GSpanAttributeWriter lookup_or_add_for_write_span(StringRef attribute_id, AttrDomain domain, eCustomDataType data_type, const AttributeInit &initializer=AttributeInitDefaultValue())
MutableSpan< float > opacities_for_write()
MutableSpan< float > radii_for_write()
bke::CurvesGeometry & strokes_for_write()
const bke::CurvesGeometry & strokes() const
void tag_topology_changed()
MutableSpan< ColorGeometry4f > fill_colors_for_write()
MutableSpan< ColorGeometry4f > vertex_colors_for_write()
void set_texture_matrices(Span< float4x2 > matrices, const IndexMask &selection)
float4x4 to_world_space(const Object &object) const
bool use_project_to_surface() const
void cache_viewport_depths(Depsgraph *depsgraph, ARegion *region, View3D *view3d)
bool use_project_to_stroke() const
float4x4 to_world_space() const
float3 project(float2 co, bool &clipped) const
static bool is_cyclic(const Nurb *nu)
VecBase< float, D > normalize(VecOp< float, D >) RET
void ED_primitivetool_modal_keymap(wmKeyConfig *keyconf)
void ED_operatortypes_grease_pencil_primitives()
void copy(const GVArray &src, GMutableSpan dst, int64_t grain_size=4096)
auto attribute_filter_from_skip_ref(const Span< StringRef > skip)
void fill_attribute_range_default(MutableAttributeAccessor dst_attributes, AttrDomain domain, const AttributeFilter &attribute_filter, IndexRange range)
static void grease_pencil_primitive_init_opacity(PrimitiveToolOperation &ptd)
static constexpr int control_point_center
static void grease_pencil_primitive_change_opacity(PrimitiveToolOperation &ptd, const wmEvent *event)
static int control_points_per_segment(const PrimitiveToolOperation &ptd)
static void grease_pencil_primitive_cancel_opacity(PrimitiveToolOperation &ptd)
float randomize_rotation(const BrushGpencilSettings &settings, const float stroke_factor, const float distance, const float pressure)
static constexpr float ui_tertiary_point_draw_size_px
void resize_single_curve(bke::CurvesGeometry &curves, const bool at_end, const int new_points_num)
static void grease_pencil_primitive_cancel(bContext *C, wmOperator *op)
static void grease_pencil_primitive_grab_update(PrimitiveToolOperation &ptd, const wmEvent *event)
static void grease_pencil_primitive_operator_update(PrimitiveToolOperation &ptd, const wmEvent *event)
static void grease_pencil_primitive_cancel_radius(PrimitiveToolOperation &ptd)
float randomize_opacity(const BrushGpencilSettings &settings, const float stroke_factor, const float distance, const float opacity, const float pressure)
static void GREASE_PENCIL_OT_primitive_circle(wmOperatorType *ot)
static float2 snap_diagonals_box(float2 p)
static constexpr int control_point_first
static float2 snap_8_angles(float2 p)
float opacity_from_input_sample(const float pressure, const Brush *brush, const BrushGpencilSettings *settings)
ColorGeometry4f randomize_color(const BrushGpencilSettings &settings, const std::optional< BrushColorJitterSettings > &jitter, const float stroke_hue_factor, const float stroke_saturation_factor, const float stroke_value_factor, const float distance, const ColorGeometry4f color, const float pressure)
static wmOperatorStatus grease_pencil_primitive_event_modal_map(bContext *C, wmOperator *op, PrimitiveToolOperation &ptd, const wmEvent *event)
void add_single_curve(bke::CurvesGeometry &curves, const bool at_end)
static void grease_pencil_primitive_change_radius(PrimitiveToolOperation &ptd, const wmEvent *event)
float randomize_radius(const BrushGpencilSettings &settings, const float stroke_factor, const float distance, const float radius, const float pressure)
static void grease_pencil_primitive_drag_update(PrimitiveToolOperation &ptd, const wmEvent *event)
float radius_from_input_sample(const RegionView3D *rv3d, const ARegion *region, const Brush *brush, const float pressure, const float3 location, const float4x4 to_world, const BrushGpencilSettings *settings)
static void grease_pencil_primitive_init_radius(PrimitiveToolOperation &ptd)
static void primitive_calulate_curve_positions(PrimitiveToolOperation &ptd, Span< float2 > control_points, MutableSpan< float2 > new_positions)
static void control_point_colors_and_sizes(const PrimitiveToolOperation &ptd, MutableSpan< ColorGeometry4f > colors, MutableSpan< float > sizes)
static void grease_pencil_primitive_extruding_update(PrimitiveToolOperation &ptd, const wmEvent *event)
static int grease_pencil_primitive_curve_points_number(PrimitiveToolOperation &ptd)
static void grease_pencil_primitive_update_view(bContext *C, PrimitiveToolOperation &ptd)
static void grease_pencil_primitive_draw(const bContext *, ARegion *, void *arg)
static void draw_control_points(PrimitiveToolOperation &ptd)
static void grease_pencil_primitive_update_curves(PrimitiveToolOperation &ptd)
static float2 primitive_center_of_mass(const PrimitiveToolOperation &ptd)
static void grease_pencil_primitive_drag_all_update(PrimitiveToolOperation &ptd, const wmEvent *event)
static constexpr float ui_secondary_point_draw_size_px
bke::CurvesGeometry curves_merge_endpoints_by_distance(const ARegion ®ion, const bke::CurvesGeometry &src_curves, const float4x4 &layer_to_world, const float merge_distance, const IndexMask &selection, const bke::AttributeFilter &attribute_filter)
static constexpr float ui_point_hit_size_px
static constexpr int control_point_last
static constexpr float ui_point_max_hit_size_px
static void grease_pencil_primitive_init_curves(PrimitiveToolOperation &ptd)
static void grease_pencil_primitive_undo_curves(PrimitiveToolOperation &ptd)
static wmOperatorStatus grease_pencil_primitive_modal(bContext *C, wmOperator *op, const wmEvent *event)
static void GREASE_PENCIL_OT_primitive_line(wmOperatorType *ot)
static void grease_pencil_primitive_scale_all_update(PrimitiveToolOperation &ptd, const wmEvent *event)
static void primitive_calulate_curve_positions_2d(PrimitiveToolOperation &ptd, MutableSpan< float2 > new_positions)
static ControlPointType get_control_point_type(const PrimitiveToolOperation &ptd, const int point)
wmOperatorStatus grease_pencil_draw_operator_invoke(bContext *C, wmOperator *op, const bool use_duplicate_previous_key)
static constexpr float ui_primary_point_draw_size_px
static void grease_pencil_primitive_common_props(wmOperatorType *ot, const int default_subdiv, const PrimitiveType default_type)
static void grease_pencil_primitive_rotate_all_update(PrimitiveToolOperation &ptd, const wmEvent *event)
float4x2 calculate_texture_space(const Scene *scene, const ARegion *region, const float2 &mouse, const DrawingPlacement &placement)
static void grease_pencil_primitive_exit(bContext *C, wmOperator *op, const bool cancelled)
static void grease_pencil_primitive_cursor_update(bContext *C, PrimitiveToolOperation &ptd, const wmEvent *event)
static void grease_pencil_primitive_load(PrimitiveToolOperation &ptd)
static void grease_pencil_primitive_status_indicators(bContext *C, wmOperator *op, PrimitiveToolOperation &ptd)
static void GREASE_PENCIL_OT_primitive_polyline(wmOperatorType *ot)
static void GREASE_PENCIL_OT_primitive_curve(wmOperatorType *ot)
static float2 primitive_local_to_screen(const PrimitiveToolOperation &ptd, const float3 &point)
static void grease_pencil_primitive_save(PrimitiveToolOperation &ptd)
static float2 snap_diagonals(float2 p)
static void GREASE_PENCIL_OT_primitive_box(wmOperatorType *ot)
static wmOperatorStatus grease_pencil_primitive_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static wmOperatorStatus grease_pencil_primitive_mouse_event(PrimitiveToolOperation &ptd, const wmEvent *event)
static void GREASE_PENCIL_OT_primitive_arc(wmOperatorType *ot)
static int primitive_check_ui_hover(const PrimitiveToolOperation &ptd, const wmEvent *event)
T cos(const AngleRadianBase< T > &a)
T distance(const T &a, const T &b)
T length(const VecBase< T, Size > &a)
T interpolate(const T &a, const T &b, const FactorT &t)
T atan2(const T &y, const T &x)
T distance_squared(const VecBase< T, Size > &a, const VecBase< T, Size > &b)
T sin(const AngleRadianBase< T > &a)
T mod(const T &a, const T &b)
VecBase< T, 3 > transform_point(const CartesianBasis &basis, const VecBase< T, 3 > &v)
MatBase< float, 2, 2 > float2x2
MatBase< float, 4, 4 > float4x4
VecBase< float, 2 > float2
MatBase< float, 4, 2 > float4x2
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
VecBase< float, 3 > float3
void RNA_int_set(PointerRNA *ptr, const char *name, int value)
int RNA_int_get(PointerRNA *ptr, const char *name)
float RNA_float_get(PointerRNA *ptr, const char *name)
void RNA_float_set(PointerRNA *ptr, const char *name, float value)
int RNA_enum_get(PointerRNA *ptr, const char *name)
PointerRNA RNA_id_pointer_create(ID *id)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
ARegionRuntimeHandle * runtime
struct CurveMapping * curve_sensitivity
struct CurveMapping * curve_strength
struct CurveMapping * curve_jitter
struct CurveMapping * curve_rand_pressure
struct CurveMapping * curve_rand_strength
struct CurveMapping * curve_rand_uv
struct CurveMapping * curve_rand_saturation
struct CurveMapping * curve_rand_hue
struct CurveMapping * curve_rand_value
struct BrushGpencilSettings * gpencil_settings
struct CurveMapping * cur_primitive
struct MaterialGPencilStyle * gp_style
struct ToolSettings * toolsettings
MutableVArraySpan< T > span
wmEventModifierFlag modifier
struct wmOperatorType * type
void WM_cursor_modal_set(wmWindow *win, int val)
void WM_cursor_modal_restore(wmWindow *win)
wmEventHandler_Op * WM_event_add_modal_handler(bContext *C, wmOperator *op)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
wmKeyMap * WM_modalkeymap_ensure(wmKeyConfig *keyconf, const char *idname, const EnumPropertyItem *items)
void WM_modalkeymap_assign(wmKeyMap *km, const char *opname)
wmKeyMap * WM_modalkeymap_find(wmKeyConfig *keyconf, const char *idname)
void WM_operatortype_append(void(*opfunc)(wmOperatorType *))