Blender V5.0
ED_curves.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11#include "BKE_crazyspace.hh"
12#include "BKE_curves.hh"
13
14#include "BLI_index_mask_fwd.hh"
15#include "BLI_vector.hh"
16#include "BLI_vector_set.hh"
17
18#include "DNA_view3d_types.h"
20
21#include "ED_select_utils.hh"
22#include "ED_view3d.hh"
23
24struct bContext;
25struct Curves;
26struct UndoType;
27struct rcti;
28struct TransVertStore;
29struct wmKeyConfig;
30struct wmOperator;
31struct wmKeyMap;
32struct EnumPropertyItem;
33namespace blender::bke {
34enum class AttrDomain : int8_t;
36} // namespace blender::bke
37
38namespace blender::ed::curves {
39
42void undosys_type_register(UndoType *ut);
43void keymap_curves(wmKeyConfig *keyconf);
44
47
48namespace pen_tool {
49
50enum class ElementMode : int8_t {
51 None = 0,
52 Point = 1,
53 Edge = 2,
56};
57
59 float distance_squared = std::numeric_limits<float>::max();
61 int point_index = -1;
62 int curve_index = -1;
63 float edge_t = -1.0f;
64 int drawing_index = -1;
65
66 bool is_closer(const float new_distance_squared,
67 const ElementMode new_element_mode,
68 const float threshold_distance) const;
69};
70
72 public:
74
77
86 float radius;
87
91
94 /* Used to go back to `aligned` after `move_handle` becomes `false` */
96
103
104 std::optional<int> active_drawing_index;
106 /* Only used for Grease Pencil. */
108
109 virtual ~PenToolOperation() = default;
110
111 virtual float3 project(const float2 &screen_co) const = 0;
112 virtual IndexMask all_selected_points(int curves_index, IndexMaskMemory &memory) const = 0;
113 virtual IndexMask visible_bezier_handle_points(int curves_index,
114 IndexMaskMemory &memory) const = 0;
115 virtual IndexMask editable_curves(int curves_index, IndexMaskMemory &memory) const = 0;
116 virtual void tag_curve_changed(int curves_index) const = 0;
117 virtual bke::CurvesGeometry &get_curves(int curves_index) const = 0;
118 virtual IndexRange curves_range() const = 0;
119 virtual void single_point_attributes(bke::CurvesGeometry &curves, int curves_index) const = 0;
123 virtual bool can_create_new_curve(wmOperator *op) const = 0;
124 virtual void update_view(bContext *C) const = 0;
125 virtual std::optional<wmOperatorStatus> initialize(bContext *C,
126 wmOperator *op,
127 const wmEvent *event) = 0;
128
129 float2 layer_to_screen(const float4x4 &layer_to_object, const float3 &point) const;
130
131 float3 screen_to_layer(const float4x4 &layer_to_world,
132 const float2 &screen_co,
133 const float3 &depth_point_layer) const;
134
135 wmOperatorStatus invoke(bContext *C, wmOperator *op, const wmEvent *event);
136 wmOperatorStatus modal(bContext *C, wmOperator *op, const wmEvent *event);
137};
138
141
142} // namespace pen_tool
143
149float (*point_normals_array_create(const Curves *curves_id))[3];
150
158
163
168
169/* Get all possible curve selection attribute names. */
171
177
184 Span<StringRef> selection_attribute_names = get_curves_all_selection_attribute_names());
185
189std::optional<Span<float3>> get_selection_attribute_positions(
191 const bke::crazyspace::GeometryDeformation &deformation,
192 StringRef attribute_name);
193
195 IndexRange range, Span<float3> positions, StringRef selection_attribute_name)>;
205 const bke::crazyspace::GeometryDeformation &deformation,
206 eHandleDisplay handle_display,
207 SelectionRangeFn range_consumer);
208
215 const bke::crazyspace::GeometryDeformation &deformation,
216 eHandleDisplay handle_display,
217 SelectionRangeFn range_consumer);
218
219bool object_has_editable_curves(const Main &bmain, const Object &object);
220bke::CurvesGeometry primitive_random_sphere(int curves_size, int points_per_curve);
223
230 TransVertStore *tvs,
231 const bool skip_handles);
232
233/* -------------------------------------------------------------------- */
236
241bool curves_poll(bContext *C);
242
244
245/* -------------------------------------------------------------------- */
248
254
256
257/* -------------------------------------------------------------------- */
260
265 const IndexMask &point_mask,
266 const GrainSize grain_size,
267 IndexMaskMemory &memory);
268
277 int amount_start,
278 int amount_end,
279 bool inverted,
280 IndexMaskMemory &memory);
282 const IndexMask &curves_mask,
283 int amount_start,
284 int amount_end,
285 bool inverted,
286 IndexMaskMemory &memory);
287
289
290/* -------------------------------------------------------------------- */
302
303void fill_selection_false(GMutableSpan selection);
304void fill_selection_true(GMutableSpan selection);
305void fill_selection(GMutableSpan selection, bool value);
306void fill_selection_false(GMutableSpan selection, const IndexMask &mask);
307void fill_selection_true(GMutableSpan selection, const IndexMask &mask);
308
315 bke::AttrDomain selection_domain,
316 const IndexMask &mask);
317
321bool has_anything_selected(GSpan selection);
322bool has_anything_selected(const VArray<bool> &varray, IndexRange range_to_check);
323bool has_anything_selected(const VArray<bool> &varray, const IndexMask &indices_to_check);
324
331
344 StringRef attribute_name,
345 const IndexMask &bezier_points,
346 IndexMaskMemory &memory);
347
353 int handle_display,
354 IndexMaskMemory &memory);
355
360 bke::AttrDomain selection_domain,
361 bke::AttrType create_type,
362 StringRef attribute_name = ".selection");
363
366 bke::AttrDomain selection_domain,
367 FunctionRef<void(bke::GSpanAttributeWriter &selection)> fn);
368
370void apply_selection_operation_at_index(GMutableSpan selection, int index, eSelectOp sel_op);
371
380void select_all(bke::CurvesGeometry &curves, bke::AttrDomain selection_domain, int action);
382 const IndexMask &mask,
383 bke::AttrDomain selection_domain,
384 int action);
385
392void select_linked(bke::CurvesGeometry &curves, const IndexMask &curves_mask);
393
399void select_alternate(bke::CurvesGeometry &curves, const bool deselect_ends);
401 const IndexMask &curves_mask,
402 const bool deselect_ends);
403
409void select_adjacent(bke::CurvesGeometry &curves, bool deselect);
410void select_adjacent(bke::CurvesGeometry &curves, const IndexMask &curves_mask, bool deselect);
411
416 int index = -1;
418};
419
425std::optional<FindClosestData> closest_elem_find_screen_space(const ViewContext &vc,
426 OffsetIndices<int> points_by_curve,
427 Span<float3> deformed_positions,
428 const VArray<bool> &cyclic,
429 const float4x4 &projection,
430 const IndexMask &mask,
431 bke::AttrDomain domain,
432 int2 coord,
433 const FindClosestData &initial);
434
438bool select_box(const ViewContext &vc,
440 const bke::crazyspace::GeometryDeformation &deformation,
441 const float4x4 &projection,
442 const IndexMask &selection_mask,
443 const IndexMask &bezier_mask,
444 bke::AttrDomain selection_domain,
445 const rcti &rect,
446 eSelectOp sel_op);
447
451bool select_lasso(const ViewContext &vc,
453 const bke::crazyspace::GeometryDeformation &deformation,
454 const float4x4 &projection,
455 const IndexMask &selection_mask,
456 const IndexMask &bezier_mask,
457 bke::AttrDomain selection_domain,
458 Span<int2> lasso_coords,
459 eSelectOp sel_op);
460
464bool select_circle(const ViewContext &vc,
466 const bke::crazyspace::GeometryDeformation &deformation,
467 const float4x4 &projection,
468 const IndexMask &selection_mask,
469 const IndexMask &bezier_mask,
470 bke::AttrDomain selection_domain,
471 int2 coord,
472 float radius,
473 eSelectOp sel_op);
474
479 StringRef attribute_name,
480 bool deselect,
481 IndexMaskMemory &memory);
483 const IndexMask &curves_mask,
484 StringRef attribute_name,
485 bool deselect,
486 IndexMaskMemory &memory);
487
493 const bke::crazyspace::GeometryDeformation &deformation,
494 const float4x4 &projection,
495 const IndexMask &selection_mask,
496 const IndexMask &bezier_mask,
497 bke::AttrDomain selection_domain,
498 StringRef attribute_name,
499 const rcti &rect,
500 IndexMaskMemory &memory);
501
507 const bke::crazyspace::GeometryDeformation &deformation,
508 const float4x4 &projection,
509 const IndexMask &selection_mask,
510 const IndexMask &bezier_mask,
511 bke::AttrDomain selection_domain,
512 StringRef attribute_name,
513 Span<int2> lasso_coords,
514 IndexMaskMemory &memory);
515
521 const bke::crazyspace::GeometryDeformation &deformation,
522 const float4x4 &projection,
523 const IndexMask &selection_mask,
524 const IndexMask &bezier_mask,
525 bke::AttrDomain selection_domain,
526 StringRef attribute_name,
527 int2 coord,
528 float radius,
529 IndexMaskMemory &memory);
531
532/* -------------------------------------------------------------------- */
535
541
544
546 const IndexMask &points_to_separate,
547 bke::CurvesGeometry &separated,
548 bke::CurvesGeometry &retained);
549
551 const IndexMask &points_to_split);
552
558
567 const IndexMask &curves_to_resize,
568 Span<int> new_sizes);
574void reorder_curves(bke::CurvesGeometry &curves, Span<int> old_by_new_indices_map);
575
577
578enum class SetHandleType : uint8_t {
579 Free = 0,
580 Auto = 1,
582 Align = 3,
584};
585
587
589
590} // namespace blender::ed::curves
Low-level operations for curves.
eHandleDisplay
struct wmKeyConfig wmKeyConfig
eSelectOp
#define C
Definition RandGen.cpp:29
virtual bool can_create_new_curve(wmOperator *op) const =0
virtual void tag_curve_changed(int curves_index) const =0
virtual IndexRange curves_range() const =0
virtual IndexMask editable_curves(int curves_index, IndexMaskMemory &memory) const =0
wmOperatorStatus invoke(bContext *C, wmOperator *op, const wmEvent *event)
virtual IndexMask visible_bezier_handle_points(int curves_index, IndexMaskMemory &memory) const =0
virtual IndexMask all_selected_points(int curves_index, IndexMaskMemory &memory) const =0
virtual bke::CurvesGeometry & get_curves(int curves_index) const =0
virtual float3 project(const float2 &screen_co) const =0
virtual void update_view(bContext *C) const =0
float2 layer_to_screen(const float4x4 &layer_to_object, const float3 &point) const
float3 screen_to_layer(const float4x4 &layer_to_world, const float2 &screen_co, const float3 &depth_point_layer) const
wmOperatorStatus modal(bContext *C, wmOperator *op, const wmEvent *event)
virtual void single_point_attributes(bke::CurvesGeometry &curves, int curves_index) const =0
virtual std::optional< wmOperatorStatus > initialize(bContext *C, wmOperator *op, const wmEvent *event)=0
nullptr float
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
void pen_tool_common_props(wmOperatorType *ot)
wmKeyMap * ensure_keymap(wmKeyConfig *keyconf)
void select_linked(bke::CurvesGeometry &curves, const IndexMask &curves_mask)
const EnumPropertyItem rna_enum_set_handle_type_items[]
void transverts_from_curves_positions_create(bke::CurvesGeometry &curves, TransVertStore *tvs, const bool skip_handles)
void apply_selection_operation_at_index(GMutableSpan selection, const int index, const eSelectOp sel_op)
void foreach_selectable_point_range(const bke::CurvesGeometry &curves, const bke::crazyspace::GeometryDeformation &deformation, eHandleDisplay handle_display, SelectionRangeFn range_consumer)
IndexMask select_circle_mask(const ViewContext &vc, const bke::CurvesGeometry &curves, const bke::crazyspace::GeometryDeformation &deformation, const float4x4 &projection, const IndexMask &selection_mask, const IndexMask &bezier_mask, const bke::AttrDomain selection_domain, const StringRef attribute_name, const int2 coord, const float radius, IndexMaskMemory &memory)
bool remove_selection(bke::CurvesGeometry &curves, const bke::AttrDomain selection_domain)
void keymap_curves(wmKeyConfig *keyconf)
void CURVES_OT_draw(wmOperatorType *ot)
static bool has_anything_selected(const Span< Curves * > curves_ids)
IndexMask retrieve_all_selected_points(const bke::CurvesGeometry &curves, const int handle_display, IndexMaskMemory &memory)
void resize_curves(bke::CurvesGeometry &curves, const IndexMask &curves_to_resize, const Span< int > new_sizes)
IndexMask retrieve_selected_curves(const bke::CurvesGeometry &curves, IndexMaskMemory &memory)
void remove_selection_attributes(bke::MutableAttributeAccessor &attributes, Span< StringRef > selection_attribute_names)
void select_all(bke::CurvesGeometry &curves, const IndexMask &mask, const bke::AttrDomain selection_domain, int action)
void duplicate_curves(bke::CurvesGeometry &curves, const IndexMask &mask)
Vector< Span< float3 > > get_curves_positions(const bke::CurvesGeometry &curves)
float(* point_normals_array_create(const Curves *curves_id))[3]
void select_alternate(bke::CurvesGeometry &curves, const IndexMask &curves_mask, const bool deselect_ends)
void duplicate_points(bke::CurvesGeometry &curves, const IndexMask &mask)
void foreach_selectable_curve_range(const bke::CurvesGeometry &curves, const bke::crazyspace::GeometryDeformation &deformation, eHandleDisplay handle_display, SelectionRangeFn range_consumer)
VectorSet< Curves * > get_unique_editable_curves(const bContext &C)
Definition curves_ops.cc:91
bool editable_curves_poll(bContext *C)
void select_adjacent(bke::CurvesGeometry &curves, const IndexMask &curves_mask, const bool deselect)
void foreach_selection_attribute_writer(bke::CurvesGeometry &curves, bke::AttrDomain selection_domain, blender::FunctionRef< void(bke::GSpanAttributeWriter &selection)> fn)
IndexMask curve_mask_from_points(const bke::CurvesGeometry &curves, const IndexMask &point_mask, const GrainSize grain_size, IndexMaskMemory &memory)
void separate_points(const bke::CurvesGeometry &curves, const IndexMask &points_to_separate, bke::CurvesGeometry &separated, bke::CurvesGeometry &retained)
Span< StringRef > get_curves_bezier_selection_attribute_names(const bke::CurvesGeometry &curves)
bke::CurvesGeometry split_points(const bke::CurvesGeometry &curves, const IndexMask &points_to_split)
void fill_selection_false(GMutableSpan selection)
bool object_has_editable_curves(const Main &bmain, const Object &object)
Definition curves_ops.cc:77
void add_curves(bke::CurvesGeometry &curves, const Span< int > new_sizes)
IndexMask select_lasso_mask(const ViewContext &vc, const bke::CurvesGeometry &curves, const bke::crazyspace::GeometryDeformation &deformation, const float4x4 &projection, const IndexMask &selection_mask, const IndexMask &bezier_mask, const bke::AttrDomain selection_domain, const StringRef attribute_name, const Span< int2 > lasso_coords, IndexMaskMemory &memory)
void ED_curves_pentool_modal_keymap(wmKeyConfig *keyconf)
bool editable_curves_in_edit_mode_poll(bContext *C)
bool select_circle(const ViewContext &vc, bke::CurvesGeometry &curves, const bke::crazyspace::GeometryDeformation &deformation, const float4x4 &projection, const IndexMask &selection_mask, const IndexMask &bezier_mask, const bke::AttrDomain selection_domain, const int2 coord, const float radius, const eSelectOp sel_op)
IndexMask select_adjacent_mask(const bke::CurvesGeometry &curves, const IndexMask &curves_mask, const StringRef attribute_name, const bool deselect, IndexMaskMemory &memory)
void fill_selection_true(GMutableSpan selection)
Vector< MutableSpan< float3 > > get_curves_positions_for_write(bke::CurvesGeometry &curves)
bke::CurvesGeometry primitive_random_sphere(const int curves_size, const int points_per_curve)
Span< StringRef > get_curves_selection_attribute_names(const bke::CurvesGeometry &curves)
void fill_selection(GMutableSpan selection, bool value)
std::optional< FindClosestData > closest_elem_find_screen_space(const ViewContext &vc, const OffsetIndices< int > points_by_curve, const Span< float3 > positions, const VArray< bool > &cyclic, const float4x4 &projection, const IndexMask &mask, const bke::AttrDomain domain, const int2 coord, const FindClosestData &initial_closest)
void undosys_type_register(UndoType *ut)
void ED_operatortypes_curves_pen()
void ensure_surface_deformation_node_exists(bContext &C, Object &curves_ob)
Definition curves_add.cc:64
Span< StringRef > get_curves_all_selection_attribute_names()
IndexMask end_points(const bke::CurvesGeometry &curves, const IndexMask &curves_mask, const int amount_start, const int amount_end, const bool inverted, IndexMaskMemory &memory)
bool curves_with_surface_poll(bContext *C)
IndexMask select_box_mask(const ViewContext &vc, const bke::CurvesGeometry &curves, const bke::crazyspace::GeometryDeformation &deformation, const float4x4 &projection, const IndexMask &selection_mask, const IndexMask &bezier_mask, const bke::AttrDomain selection_domain, const StringRef attribute_name, const rcti &rect, IndexMaskMemory &memory)
void CURVES_OT_separate(wmOperatorType *ot)
bool select_lasso(const ViewContext &vc, bke::CurvesGeometry &curves, const bke::crazyspace::GeometryDeformation &deformation, const float4x4 &projection, const IndexMask &selection_mask, const IndexMask &bezier_mask, const bke::AttrDomain selection_domain, const Span< int2 > lasso_coords, const eSelectOp sel_op)
void CURVES_OT_attribute_set(wmOperatorType *ot)
bool curves_poll(bContext *C)
std::optional< Span< float3 > > get_selection_attribute_positions(const bke::CurvesGeometry &curves, const bke::crazyspace::GeometryDeformation &deformation, const StringRef attribute_name)
bke::GSpanAttributeWriter ensure_selection_attribute(bke::CurvesGeometry &curves, bke::AttrDomain selection_domain, bke::AttrType create_type, StringRef attribute_name)
IndexMask retrieve_selected_points(const bke::CurvesGeometry &curves, IndexMaskMemory &memory)
wmOperatorStatus join_objects_exec(bContext *C, wmOperator *op)
void CURVES_OT_extrude(wmOperatorType *ot)
void CURVES_OT_select_linked_pick(wmOperatorType *ot)
FunctionRef< void( IndexRange range, Span< float3 > positions, StringRef selection_attribute_name)> SelectionRangeFn
Definition ED_curves.hh:194
void reorder_curves(bke::CurvesGeometry &curves, const Span< int > old_by_new_indices_map)
bool editable_curves_with_surface_poll(bContext *C)
bool select_box(const ViewContext &vc, bke::CurvesGeometry &curves, const bke::crazyspace::GeometryDeformation &deformation, const float4x4 &projection, const IndexMask &selection_mask, const IndexMask &bezier_mask, const bke::AttrDomain selection_domain, const rcti &rect, const eSelectOp sel_op)
MatBase< float, 4, 4 > float4x4
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
VecBase< float, 3 > float3
#define FLT_MAX
Definition stdcycles.h:14
bool is_closer(const float new_distance_squared, const ElementMode new_element_mode, const float threshold_distance) const
Definition curves_pen.cc:79
wmOperatorType * ot
Definition wm_files.cc:4237