44 const int layer_index,
63 for (const int src_curve : src_curves) {
64 const float3 &normal = normals[src_curve];
65 const IndexRange points = src_points_by_curve[src_curve];
66 const float3 &point = deformation.positions[points.first()];
67 curve_planes[src_curve] = float4(normal, -math::dot(point, normal));
72 input_curves.
resize(src.points_num() + mcoords.size(), src.curves_num() + 1);
112 const OffsetIndices<int> points_by_curve = input_curves.
points_by_curve();
113 Array<float2> src_positions_2d(input_curves.
points_num());
114 const Span<float3> positions = input_curves.
positions();
116 src_positions_2d[i] = project_fn(positions[i]);
119 Array<Bounds<float2>> screen_space_bbox(input_curves.
curves_num());
121 for (const int curve_i : curves_i) {
122 const IndexRange points_i = points_by_curve[curve_i];
123 screen_space_bbox[curve_i] = *bounds::min_max(src_positions_2d.as_span().slice(points_i));
127 const VArray<int8_t> curve_types = input_curves.
curve_types();
129 const Bounds<float2> bbox_j = screen_space_bbox.
last();
131 IndexMaskMemory memory;
134 const Bounds<float2> bbox_i = screen_space_bbox[curve_i];
137 if (curve_types[curve_i] == CURVE_TYPE_POLY) {
149 if (!curves_to_convert.is_empty()) {
155 boolean::CurveBooleanOpParameters op_params;
156 op_params.boolean_mode = boolean::Operation::Difference;
157 op_params.keep_caps = keep_caps;
158 op_params.skip_clipping_attributes =
true;
159 op_params.separate_islands =
true;
161 const GroupedSpan<int> shapes = shapes_data.
shapes();
162 const IndexRange clipping_shapes = IndexRange::from_single(shapes.size() - 1);
164 IndexMaskMemory memory;
165 const IndexMask editable_strokes = ed::greasepencil::retrieve_editable_strokes(
166 obact, drawing, layer_index, memory);
167 const IndexMask editable_shapes = bke::greasepencil::curves_mask_to_shapes(
168 editable_strokes, shapes, memory);
170 bke::CurvesGeometry carved_strokes = boolean::curve_boolean_with_planes(op_params,
181 drawing.strokes_for_write() = std::move(carved_strokes);
182 drawing.tag_topology_changed();
210 for (const int i : i_range) {
211 coords[i] = float2(mcoords[i]);
216 const int smooth_iterations = 4;
217 const float smooth_factor = 0.8f;
224 lasso_pos.as_mutable_span());
228 if (
brush->gpencil_settings ==
nullptr) {
233 std::atomic<bool> changed =
false;
234 std::atomic<bool> converted =
false;
236 bool inserted_keyframe =
false;
237 if (active_layer_only) {
243 if (!
layer.is_editable()) {
244 return OPERATOR_CANCELLED;
248 const float4x4 layer_to_world =
layer.to_world_space(*ob_eval);
250 const Vector<ed::greasepencil::MutableDrawingInfo> drawings =
251 ed::greasepencil::retrieve_editable_drawings_from_layer(*scene,
grease_pencil,
layer);
254 DrawingPlacement placement = ed::greasepencil::DrawingPlacement(
255 *scene, *region, *view3d, *ob_eval, &
layer);
257 threading::parallel_for_each(drawings, [&](
const ed::greasepencil::MutableDrawingInfo &info) {
258 bool r_converted =
false;
281 if (
layer->is_editable()) {
282 ed::greasepencil::ensure_active_keyframe(
288 const Vector<ed::greasepencil::MutableDrawingInfo> drawings =
289 ed::greasepencil::retrieve_editable_drawings(*scene,
grease_pencil);
290 threading::parallel_for_each(drawings, [&](
const ed::greasepencil::MutableDrawingInfo &info) {
292 const float4x4 layer_to_world =
layer.to_world_space(*ob_eval);
296 DrawingPlacement placement = ed::greasepencil::DrawingPlacement(
297 *scene, *region, *view3d, *ob_eval, &
layer);
299 bool r_converted =
false;
322 BKE_report(op->reports, RPT_WARNING,
"Some curves were converted to Poly");
328 if (inserted_keyframe) {
342 ot->
name =
"Grease Pencil Carver";
343 ot->
idname =
"GREASE_PENCIL_OT_stroke_carver";
344 ot->
description =
"Cuts stroke point in the intersect lasso";
348 ot->
exec = grease_pencil_stroke_carver_exec;
349 ot->
poll = grease_pencil_painting_poll;
General operations, lookup, etc. for materials.
IndexRange index_range() const
static IndexMask from_predicate(const IndexMask &universe, LinearAllocator<> &memory, Fn &&predicate, exec_mode::Mode mode=exec_mode::parallel)
static constexpr IndexRange from_begin_size(const int64_t begin, const int64_t size)
static constexpr IndexRange from_single(const int64_t index)
T last(const int64_t n=0) const
static VArray from_single(T value, const int64_t size)
VArray< int8_t > curve_types() const
MutableSpan< float3 > positions_for_write()
void resize(int points_num, int curves_num)
Span< float3 > positions() const
bool is_single_type(CurveType type) const
IndexRange curves_range() const
MutableSpan< int > offsets_for_write()
IndexRange points_range() const
void fill_curve_types(CurveType type)
MutableSpan< bool > cyclic_for_write()
OffsetIndices< int > points_by_curve() const
MutableAttributeAccessor attributes_for_write()
GSpanAttributeWriter lookup_or_add_for_write_span(StringRef name, AttrDomain domain, AttrType data_type, const AttributeInit &initializer=AttributeInitDefaultValue())
Span< float3 > curve_plane_normals() const
const bke::CurvesGeometry & strokes() const
GeometryDeformation get_evaluated_grease_pencil_drawing_deformation(const Object *ob_eval, const Object &ob_orig, const bke::greasepencil::Drawing &drawing_orig)
IndexMask selected_mask_to_fills(const IndexMask &selected_mask, const CurvesGeometry &curves, AttrDomain selection_domain, IndexMaskMemory &memory)
int get_next_available_fill_id(Span< int > fill_ids)
ShapeData shapes_from_fill_ids(const VArray< int > &fill_ids, int curves_num)
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)
std::optional< Bounds< T > > intersect(const Bounds< T > &a, const Bounds< T > &b)
bool ensure_active_keyframe(const Scene &scene, GreasePencil &grease_pencil, bke::greasepencil::Layer &layer, const bool duplicate_previous_key, bool &r_inserted_keyframe)
static wmOperatorStatus grease_pencil_stroke_carver_exec(bContext *C, wmOperator *op)
static bool execute_carver_on_drawing(const Object &ob_eval, Object &obact, const ARegion ®ion, const float4x4 &projection, const int layer_index, const float4x4 &layer_to_world, const DrawingPlacement &placement, const Span< float2 > mcoords, const bool keep_caps, bke::greasepencil::Drawing &drawing, bool *r_converted)
CurvesGeometry resample_to_evaluated(const CurvesGeometry &src_curves, const IndexMask &selection, const ResampleCurvesOutputAttributeIDs &output_ids={})
void gaussian_blur_1D(const GSpan src, int iterations, const VArray< float > &influence_by_point, const bool smooth_ends, const bool keep_shape, const bool is_cyclic, GMutableSpan dst)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
void GREASE_PENCIL_OT_stroke_carver(wmOperatorType *ot)
Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
void WM_gesture_lasso_cancel(bContext *C, wmOperator *op)
float2 ED_view3d_project_float_v2_m4(const ARegion *region, const float co[3], const float4x4 &mat)
void BKE_brush_init_gpencil_settings(Brush *brush)
wmOperatorStatus WM_gesture_lasso_modal(bContext *C, wmOperator *op, const wmEvent *event)
MatBase< float, 4, 4 > float4x4
void DEG_id_tag_update(ID *id, unsigned int flags)
void BKE_report(ReportList *reports, eReportType type, const char *message)
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
RegionView3D * CTX_wm_region_view3d(const bContext *C)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
wmOperatorStatus WM_gesture_lasso_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Paint * BKE_paint_get_active_from_context(const bContext *C)
Array< int2 > WM_gesture_lasso_path_to_array(bContext *, wmOperator *op)
float4x4 ED_view3d_ob_project_mat_get_from_obmat(const RegionView3D *rv3d, const float4x4 &obmat)
Brush * BKE_paint_brush(Paint *paint)
Scene * CTX_data_scene(const bContext *C)
@ GP_BRUSH_ERASER_KEEP_CAPS
@ GP_BRUSH_ACTIVE_LAYER_ONLY
Object * CTX_data_active_object(const bContext *C)
ARegion * CTX_wm_region(const bContext *C)
View3D * CTX_wm_view3d(const bContext *C)
void WM_operator_properties_gesture_lasso(wmOperatorType *ot)
MutableVArraySpan< T > span
const GroupedSpan< int > shapes() const
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
void(*) cancel(bContext *C, wmOperator *op)
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
wmOperatorStatus(*) modal(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT