Blender V5.3
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
24namespace blender {
25
26struct bContext;
27struct Curves;
28struct UndoType;
29struct rcti;
30struct TransVertStore;
31struct wmKeyConfig;
32struct wmOperator;
33struct wmKeyMap;
34struct EnumPropertyItem;
35namespace bke {
36enum class AttrDomain : int8_t;
38} // namespace bke
39
40namespace ed::curves {
41
44void undosys_type_register(UndoType *ut);
45void keymap_curves(wmKeyConfig *keyconf);
46
48void ED_curves_pentool_modal_keymap(wmKeyConfig *keyconf);
49
50namespace pen_tool {
51
52enum class ElementMode : int8_t {
53 None = 0,
54 Point = 1,
55 Edge = 2,
58};
59
61 float distance_squared = std::numeric_limits<float>::max();
63 int point_index = -1;
64 int curve_index = -1;
65 float edge_t = -1.0f;
66 int drawing_index = -1;
67
68 bool is_closer(const float new_distance_squared,
69 const ElementMode new_element_mode,
70 const float threshold_distance) const;
71};
72
74 public:
76
79
88 float radius;
89
93
96 /* Used to go back to `aligned` after `move_handle` becomes `false` */
98
105
106 std::optional<int> active_drawing_index;
108 /* Only used for Grease Pencil. */
110
111 virtual ~PenToolOperation() = default;
112
113 virtual float3 project(const float2 &screen_co) const = 0;
114 virtual IndexMask all_selected_points(int curves_index, IndexMaskMemory &memory) const = 0;
115 virtual IndexMask visible_bezier_handle_points(int curves_index,
116 IndexMaskMemory &memory) const = 0;
117 virtual IndexMask editable_curves(int curves_index, IndexMaskMemory &memory) const = 0;
118 virtual void tag_curve_changed(int curves_index) const = 0;
119 virtual bke::CurvesGeometry &get_curves(int curves_index) const = 0;
120 virtual IndexRange curves_range() const = 0;
121 virtual void single_point_attributes(bke::CurvesGeometry &curves, int curves_index) const = 0;
125 virtual bool can_create_new_curve(wmOperator *op) const = 0;
126 virtual void update_view(bContext *C) const = 0;
127 virtual std::optional<wmOperatorStatus> initialize(bContext *C,
128 wmOperator *op,
129 const wmEvent *event) = 0;
130
131 float2 layer_to_screen(const float4x4 &layer_to_object, const float3 &point) const;
132
133 float3 screen_to_layer(const float4x4 &layer_to_world,
134 const float2 &screen_co,
135 const float3 &depth_point_layer) const;
136
137 wmOperatorStatus invoke(bContext *C, wmOperator *op, const wmEvent *event);
138 wmOperatorStatus modal(bContext *C, wmOperator *op, const wmEvent *event);
139};
140
143
144} // namespace pen_tool
145
151float (*point_normals_array_create(const Curves *curves_id))[3];
152
160
165
170
171/* Get all possible curve selection attribute names. */
173
179
186 Span<StringRef> selection_attribute_names = get_curves_all_selection_attribute_names());
187
191std::optional<Span<float3>> get_selection_attribute_positions(
193 const bke::crazyspace::GeometryDeformation &deformation,
194 StringRef attribute_name);
195
197 IndexRange range, Span<float3> positions, StringRef selection_attribute_name)>;
207 const bke::crazyspace::GeometryDeformation &deformation,
208 eHandleDisplay handle_display,
209 SelectionRangeFn range_consumer);
210
217 const bke::crazyspace::GeometryDeformation &deformation,
218 eHandleDisplay handle_display,
219 SelectionRangeFn range_consumer);
220
221bool object_has_editable_curves(const Main &bmain, const Object &object);
222bke::CurvesGeometry primitive_random_sphere(int curves_size, int points_per_curve);
225
232 TransVertStore *tvs,
233 const bool skip_handles);
234
239 const TransVertStore *tvs,
240 bool skip_handles);
241
242/* -------------------------------------------------------------------- */
245
250bool curves_poll(bContext *C);
251
253
254/* -------------------------------------------------------------------- */
257
263
265
266/* -------------------------------------------------------------------- */
269
278 int amount_start,
279 int amount_end,
280 bool inverted,
281 IndexMaskMemory &memory);
283 const IndexMask &curves_mask,
284 int amount_start,
285 int amount_end,
286 bool inverted,
287 IndexMaskMemory &memory);
288
290
291/* -------------------------------------------------------------------- */
303
304void fill_selection_false(GMutableSpan selection);
305void fill_selection_true(GMutableSpan selection);
306void fill_selection(GMutableSpan selection, bool value);
307void fill_selection_false(GMutableSpan selection, const IndexMask &mask);
308void fill_selection_true(GMutableSpan selection, const IndexMask &mask);
309
316 bke::AttrDomain selection_domain,
317 const IndexMask &mask);
318
322bool has_anything_selected(GSpan selection);
323bool has_anything_selected(const VArray<bool> &varray, IndexRange range_to_check);
324bool has_anything_selected(const VArray<bool> &varray, const IndexMask &indices_to_check);
325
332
345 StringRef attribute_name,
346 const IndexMask &bezier_points,
347 LinearAllocator<> &memory);
348
354 int handle_display,
355 LinearAllocator<> &memory);
356
361 bke::AttrDomain selection_domain,
362 bke::AttrType create_type,
363 StringRef attribute_name = ".selection");
364
367 bke::AttrDomain selection_domain,
368 FunctionRef<void(bke::GSpanAttributeWriter &selection)> fn);
369
372
381void select_all(bke::CurvesGeometry &curves, bke::AttrDomain selection_domain, int action);
383 const IndexMask &mask,
384 bke::AttrDomain selection_domain,
385 int action);
386
392void select_linked(bke::CurvesGeometry &curves, const bool unselect = false);
394 const IndexMask &curves_mask,
395 const bool unselect = false);
396
402void select_alternate(bke::CurvesGeometry &curves, const bool deselect_ends);
404 const IndexMask &curves_mask,
405 const bool deselect_ends);
406
412void select_adjacent(bke::CurvesGeometry &curves, bool deselect);
413void select_adjacent(bke::CurvesGeometry &curves, const IndexMask &curves_mask, bool deselect);
414
419 int index = -1;
421};
422
428std::optional<FindClosestData> closest_elem_find_screen_space(const ViewContext &vc,
429 OffsetIndices<int> points_by_curve,
430 Span<float3> deformed_positions,
431 const VArray<bool> &cyclic,
432 const float4x4 &projection,
433 const IndexMask &mask,
434 bke::AttrDomain domain,
435 int2 coord,
436 const FindClosestData &initial);
437
441bool select_box(const ViewContext &vc,
443 const bke::crazyspace::GeometryDeformation &deformation,
444 const float4x4 &projection,
445 const IndexMask &selection_mask,
446 const IndexMask &bezier_mask,
447 bke::AttrDomain selection_domain,
448 const rcti &rect,
449 eSelectOp sel_op);
450
454bool select_lasso(const ViewContext &vc,
456 const bke::crazyspace::GeometryDeformation &deformation,
457 const float4x4 &projection,
458 const IndexMask &selection_mask,
459 const IndexMask &bezier_mask,
460 bke::AttrDomain selection_domain,
461 Span<int2> lasso_coords,
462 eSelectOp sel_op);
463
467bool select_circle(const ViewContext &vc,
469 const bke::crazyspace::GeometryDeformation &deformation,
470 const float4x4 &projection,
471 const IndexMask &selection_mask,
472 const IndexMask &bezier_mask,
473 bke::AttrDomain selection_domain,
474 int2 coord,
475 float radius,
476 eSelectOp sel_op);
477
482 StringRef attribute_name,
483 bool deselect,
484 IndexMaskMemory &memory);
486 const IndexMask &curves_mask,
487 StringRef attribute_name,
488 bool deselect,
489 IndexMaskMemory &memory);
490
496 const bke::crazyspace::GeometryDeformation &deformation,
497 const float4x4 &projection,
498 const IndexMask &selection_mask,
499 const IndexMask &bezier_mask,
500 bke::AttrDomain selection_domain,
501 StringRef attribute_name,
502 const rcti &rect,
503 IndexMaskMemory &memory);
504
510 const bke::crazyspace::GeometryDeformation &deformation,
511 const float4x4 &projection,
512 const IndexMask &selection_mask,
513 const IndexMask &bezier_mask,
514 bke::AttrDomain selection_domain,
515 StringRef attribute_name,
516 Span<int2> lasso_coords,
517 IndexMaskMemory &memory);
518
524 const bke::crazyspace::GeometryDeformation &deformation,
525 const float4x4 &projection,
526 const IndexMask &selection_mask,
527 const IndexMask &bezier_mask,
528 bke::AttrDomain selection_domain,
529 StringRef attribute_name,
530 int2 coord,
531 float radius,
532 IndexMaskMemory &memory);
534
535/* -------------------------------------------------------------------- */
538
544
547
549 const IndexMask &points_to_separate,
550 bke::CurvesGeometry &separated,
551 bke::CurvesGeometry &retained);
552
554 const IndexMask &points_to_split);
555
561
570 const IndexMask &curves_to_resize,
571 Span<int> new_sizes);
577void reorder_curves(bke::CurvesGeometry &curves, Span<int> old_by_new_indices_map);
578
580
581enum class SetHandleType : uint8_t {
582 Free = 0,
583 Auto = 1,
585 Align = 3,
587};
588
590
592
593} // namespace ed::curves
594} // namespace blender
Low-level operations for curves.
#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
#define FLT_MAX
ccl_device_inline float3x3 inverted(const float3x3 m)
void pen_tool_common_props(wmOperatorType *ot)
wmKeyMap * ensure_keymap(wmKeyConfig *keyconf)
bool has_anything_selected(const VArray< bool > &varray, const IndexRange range_to_check)
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)
void resize_curves(bke::CurvesGeometry &curves, const IndexMask &curves_to_resize, const Span< int > new_sizes)
void remove_selection_attributes(bke::MutableAttributeAccessor &attributes, Span< StringRef > selection_attribute_names)
void select_linked(bke::CurvesGeometry &curves, const IndexMask &curves_mask, const bool unselect)
void select_all(bke::CurvesGeometry &curves, const IndexMask &mask, const bke::AttrDomain selection_domain, int action)
IndexMask retrieve_selected_points(const bke::CurvesGeometry &curves, LinearAllocator<> &memory)
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)
void foreach_selection_attribute_writer(bke::CurvesGeometry &curves, bke::AttrDomain selection_domain, FunctionRef< void(bke::GSpanAttributeWriter &selection)> fn)
bool editable_curves_poll(bContext *C)
void select_adjacent(bke::CurvesGeometry &curves, const IndexMask &curves_mask, const bool deselect)
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:87
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)
IndexMask retrieve_selected_curves(const bke::CurvesGeometry &curves, LinearAllocator<> &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 transverts_update_curves(bke::CurvesGeometry &curves, const TransVertStore *tvs, const bool skip_handles)
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)
IndexMask retrieve_all_selected_points(const bke::CurvesGeometry &curves, const int handle_display, LinearAllocator<> &memory)
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)
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:196
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)
BMesh Iterators.
MatBase< float, 4, 4 > float4x4
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
unsigned char uint8_t
Definition BKE_text.h:79
VecBase< float, 3 > float3
signed char int8_t
Definition BKE_text.h:76
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
bool is_closer(const float new_distance_squared, const ElementMode new_element_mode, const float threshold_distance) const
Definition curves_pen.cc:78