Blender V5.3
interpolate.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "BKE_colortools.hh"
6#include "BKE_context.hh"
7#include "BKE_curves.hh"
8#include "BKE_deform.hh"
10#include "BKE_paint.hh"
11
12#include "BLI_array_utils.hh"
13#include "BLI_easing.hh"
14#include "BLI_index_mask.hh"
16#include "BLI_math_geom_c.hh"
17#include "BLI_math_rotation.hh"
19#include "BLI_math_vector.hh"
20#include "BLI_offset_indices.hh"
21#include "BLI_task.hh"
22
23#include "BLT_translation.hh"
24
25#include "DEG_depsgraph.hh"
26
28
29#include "ED_curves.hh"
30#include "ED_grease_pencil.hh"
31#include "ED_numinput.hh"
32#include "ED_screen.hh"
33
35#include "GEO_smooth_curves.hh"
36
37#include "MEM_guardedalloc.h"
38
39#include "RNA_access.hh"
40#include "RNA_define.hh"
41#include "RNA_enum_types.hh"
42#include "RNA_prototypes.hh"
43
44#include "UI_interface.hh"
46#include "UI_resources.hh"
47
48#include <climits>
49
50namespace blender {
51
53
56
57/* -------------------------------------------------------------------- */
60
61/* Modes for the interpolation tool. */
79
85 /* Interpolation. */
87 N_("Standard transitions between keyframes")),
89 "LINEAR",
90 ICON_IPO_LINEAR,
91 "Linear",
92 "Straight-line interpolation between A and B (i.e. no ease in/out)"},
94 "CUSTOM",
95 ICON_IPO_BEZIER,
96 "Custom",
97 "Custom interpolation defined using a curve map"},
98
99 /* Easing. */
101 N_("Predefined inertial transitions, useful for motion graphics "
102 "(from least to most \"dramatic\")")),
104 "SINE",
105 ICON_IPO_SINE,
106 "Sinusoidal",
107 "Sinusoidal easing (weakest, almost linear but with a slight curvature)"},
108 {int(InterpolationType::Quadratic), "QUAD", ICON_IPO_QUAD, "Quadratic", "Quadratic easing"},
109 {int(InterpolationType::Cubic), "CUBIC", ICON_IPO_CUBIC, "Cubic", "Cubic easing"},
110 {int(InterpolationType::Quartic), "QUART", ICON_IPO_QUART, "Quartic", "Quartic easing"},
111 {int(InterpolationType::Quintic), "QUINT", ICON_IPO_QUINT, "Quintic", "Quintic easing"},
113 "EXPO",
114 ICON_IPO_EXPO,
115 "Exponential",
116 "Exponential easing (dramatic)"},
118 "CIRC",
119 ICON_IPO_CIRC,
120 "Circular",
121 "Circular easing (strongest and most dynamic)"},
122
124 N_("Simple physics-inspired easing effects")),
126 "BACK",
127 ICON_IPO_BACK,
128 "Back",
129 "Cubic easing with overshoot and settle"},
131 "BOUNCE",
132 ICON_IPO_BOUNCE,
133 "Bounce",
134 "Exponentially decaying parabolic bounce, like when objects collide"},
136 "ELASTIC",
137 ICON_IPO_ELASTIC,
138 "Elastic",
139 "Exponentially decaying sine wave, like an elastic band"},
140
141 {0, nullptr, 0, nullptr, nullptr},
142};
143
145 {int(InterpolateFlipMode::None), "NONE", 0, "No Flip", ""},
146 {int(InterpolateFlipMode::Flip), "FLIP", 0, "Flip", ""},
147 {int(InterpolateFlipMode::FlipAuto), "AUTO", 0, "Automatic", ""},
148 {0, nullptr, 0, nullptr, nullptr},
149};
150
152 {int(InterpolateLayerMode::Active), "ACTIVE", 0, "Active", ""},
153 {int(InterpolateLayerMode::All), "ALL", 0, "All Layers", ""},
154 {0, nullptr, 0, nullptr, nullptr},
155};
156
157constexpr float interpolate_factor_min = -1.0f;
158constexpr float interpolate_factor_max = 2.0f;
159
160/* Pair of curves in a layer that get interpolated. */
167
169 struct LayerData {
170 /* Curve pairs to interpolate from this layer. */
172
173 /* Geometry of the target frame before interpolation for restoring on cancel. */
174 std::optional<bke::CurvesGeometry> orig_curves;
175 };
176
177 /* Layers to include. */
180 /* Exclude breakdown keyframes when finding intervals. */
182
183 /* Interpolation factor bias controlled by the user. */
184 float shift;
185 /* Interpolation base factor for the active layer. */
190
194
195 static InterpolateOpData *from_operator(const bContext &C, const wmOperator &op);
196};
197
198using FramesMapKeyIntervalT = std::pair<int, int>;
199
200static std::optional<FramesMapKeyIntervalT> find_frames_interval(
201 const bke::greasepencil::Layer &layer, const int frame_number, const bool exclude_breakdowns)
202{
205 using SortedKeysIterator = Layer::SortedKeysIterator;
206
207 const Span<FramesMapKeyT> sorted_keys = layer.sorted_keys();
208 SortedKeysIterator prev_key_it = layer.sorted_keys_iterator_at(frame_number);
209 if (!prev_key_it) {
210 return std::nullopt;
211 }
212 SortedKeysIterator next_key_it = std::next(prev_key_it);
213
214 /* Skip over invalid keyframes on either side. */
215 auto is_valid_keyframe = [&](const FramesMapKeyT key) {
216 const GreasePencilFrame *frame = layer.frame_at(key);
217 if (!frame || frame->is_end()) {
218 return false;
219 }
220 if (exclude_breakdowns && frame->type == BEZT_KEYTYPE_BREAKDOWN) {
221 return false;
222 }
223 return true;
224 };
225
226 for (; next_key_it != sorted_keys.end(); ++next_key_it) {
227 if (is_valid_keyframe(*next_key_it)) {
228 break;
229 }
230 }
231 for (; prev_key_it != sorted_keys.begin(); --prev_key_it) {
232 if (is_valid_keyframe(*prev_key_it)) {
233 break;
234 }
235 }
236 if (next_key_it == sorted_keys.end() || !is_valid_keyframe(*prev_key_it)) {
237 return std::nullopt;
238 }
239
240 return std::make_pair(*prev_key_it, *next_key_it);
241}
242
243/* Build index lists for curve interpolation using index. */
246 const int current_frame,
247 const bool exclude_breakdowns,
248 const bool only_selected,
249 InterpolationPairs &pairs)
250{
252
253 const std::optional<FramesMapKeyIntervalT> interval = find_frames_interval(
254 layer, current_frame, exclude_breakdowns);
255 if (!interval) {
256 return false;
257 }
258
259 BLI_assert(layer.has_drawing_at(interval->first));
260 BLI_assert(layer.has_drawing_at(interval->second));
261 const Drawing &from_drawing = *grease_pencil.get_drawing_at(layer, interval->first);
262 const Drawing &to_drawing = *grease_pencil.get_drawing_at(layer, interval->second);
263 /* In addition to interpolated pairs, the unselected original strokes are also included, making
264 * the total pair count the same as the "from" curve count. */
265 const int pairs_num = from_drawing.strokes().curves_num();
266
267 const int old_pairs_num = pairs.from_frames.size();
268 pairs.from_frames.append_n_times(interval->first, pairs_num);
269 pairs.to_frames.append_n_times(interval->second, pairs_num);
270 pairs.from_curves.resize(old_pairs_num + pairs_num);
271 pairs.to_curves.resize(old_pairs_num + pairs_num);
272 MutableSpan<int> from_curves = pairs.from_curves.as_mutable_span().slice(old_pairs_num,
273 pairs_num);
274 MutableSpan<int> to_curves = pairs.to_curves.as_mutable_span().slice(old_pairs_num, pairs_num);
275
276 /* Write source indices into the pair data. If one drawing has more selected curves than the
277 * other the remainder is ignored. */
278
279 IndexMaskMemory memory;
280 IndexMask from_selection, to_selection;
281 if (only_selected && ed::curves::has_anything_selected(from_drawing.strokes()) &&
283 {
284 from_selection = ed::curves::retrieve_selected_curves(from_drawing.strokes(), memory);
285 to_selection = ed::curves::retrieve_selected_curves(to_drawing.strokes(), memory);
286 }
287 else {
288 from_selection = from_drawing.strokes().curves_range();
289 to_selection = to_drawing.strokes().curves_range();
290 }
291 /* Discard additional elements of the larger selection. */
292 if (from_selection.size() > to_selection.size()) {
293 from_selection = from_selection.slice(0, to_selection.size());
294 }
295 else if (to_selection.size() > from_selection.size()) {
296 to_selection = to_selection.slice(0, from_selection.size());
297 }
298
299 /* By default: copy the "from" curve and ignore the "to" curve. */
301 to_curves.fill(-1);
302 /* Selected curves are interpolated. */
303 IndexMask::foreach_segment_zipped({from_selection, to_selection},
304 [&](Span<IndexMaskSegment> segments) {
305 const IndexMaskSegment &from_segment = segments[0];
306 const IndexMaskSegment &to_segment = segments[1];
307 BLI_assert(from_segment.size() == to_segment.size());
308 for (const int i : from_segment.index_range()) {
309 to_curves[from_segment[i]] = to_segment[i];
310 }
311 return true;
312 });
313
314 return true;
315}
316
318{
321
322 const Scene &scene = *CTX_data_scene(&C);
323 const int current_frame = scene.r.cfra;
324 const Object &object = *CTX_data_active_object(&C);
325 const GreasePencil &grease_pencil = *id_cast<GreasePencil *>(object.data);
326
327 if (!grease_pencil.has_active_layer()) {
328 return nullptr;
329 }
330
331 const Layer &active_layer = *grease_pencil.get_active_layer();
332
333 InterpolateOpData *data = MEM_new<InterpolateOpData>(__func__);
334
335 if (RNA_struct_find_property(op.ptr, "shift") != nullptr) {
336 data->shift = RNA_float_get(op.ptr, "shift");
337 }
338 data->exclude_breakdowns = RNA_boolean_get(op.ptr, "exclude_breakdowns");
339 data->flipmode = InterpolateFlipMode(RNA_enum_get(op.ptr, "flip"));
340 data->smooth_factor = RNA_float_get(op.ptr, "smooth_factor");
341 data->smooth_steps = RNA_int_get(op.ptr, "smooth_steps");
342 data->active_layer_index = *grease_pencil.get_layer_index(active_layer);
343 const bool use_selection = RNA_boolean_get(op.ptr, "use_selection");
344
345 const auto layer_mode = InterpolateLayerMode(RNA_enum_get(op.ptr, "layers"));
346 switch (layer_mode) {
347 case InterpolateLayerMode::Active:
348 data->layer_mask = IndexRange::from_single(data->active_layer_index);
349 break;
350 case InterpolateLayerMode::All:
351 data->layer_mask = IndexMask::from_predicate(
352 grease_pencil.layers().index_range(),
353 data->layer_mask_memory,
354 [&](const int layer_index) { return grease_pencil.layer(layer_index).is_editable(); });
355 break;
356 }
357
358 bool found_mapping = false;
359 data->layer_data.reinitialize(grease_pencil.layers().size());
360 data->layer_mask.foreach_index([&](const int layer_index) {
361 const Layer &layer = grease_pencil.layer(layer_index);
362 InterpolateOpData::LayerData &layer_data = data->layer_data[layer_index];
363
364 /* Pair from/to curves by index. */
365 const bool has_curve_mapping = find_curve_mapping_from_index(grease_pencil,
366 layer,
367 current_frame,
368 data->exclude_breakdowns,
369 use_selection,
371 found_mapping = found_mapping || has_curve_mapping;
372 });
373
374 /* No mapping between frames was found. */
375 if (!found_mapping) {
376 MEM_delete(data);
377 return nullptr;
378 }
379
380 const std::optional<FramesMapKeyIntervalT> active_layer_interval = find_frames_interval(
381 active_layer, current_frame, data->exclude_breakdowns);
382 data->init_factor = active_layer_interval ?
383 float(current_frame - active_layer_interval->first) /
384 (active_layer_interval->second - active_layer_interval->first + 1) :
385 0.5f;
386
387 return data;
388}
389
390/* Find ranges of sorted pairs with the same from/to frame intervals. */
392 const Span<int> order)
393{
394 Vector<int> pair_offsets;
395
396 int prev_from_frame = INT_MIN;
397 int prev_to_frame = INT_MIN;
398 int current_count = 0;
399 for (const int pair_index : order) {
400 const int from_frame = curve_pairs.from_frames[pair_index];
401 const int to_frame = curve_pairs.to_frames[pair_index];
402 if (from_frame != prev_from_frame || to_frame != prev_to_frame) {
403 /* New pair. */
404 if (current_count > 0) {
405 pair_offsets.append(current_count);
406 }
407 current_count = 0;
408 }
409 ++current_count;
410 }
411 if (current_count > 0) {
412 pair_offsets.append(current_count);
413 }
414
415 /* Last entry for overall size. */
416 if (pair_offsets.is_empty()) {
417 return {};
418 }
419
420 /* Extra element for the total size needed for OffsetIndices. */
421 pair_offsets.append(0);
423
424 return pair_offsets;
425}
426
427static bool compute_auto_flip(const Span<float3> from_positions, const Span<float3> to_positions)
428{
429 if (from_positions.size() < 2 || to_positions.size() < 2) {
430 return false;
431 }
432
433 constexpr float min_angle = DEG2RADF(15);
434
435 const float3 &from_first = from_positions.first();
436 const float3 &from_last = from_positions.last();
437 const float3 &to_first = to_positions.first();
438 const float3 &to_last = to_positions.last();
439
440 /* If lines intersect at a sharp angle check distances. */
441 if (isect_seg_seg_v2(from_first, to_first, from_last, to_last) == ISECT_LINE_LINE_CROSS) {
442 if (math::angle_between(math::normalize(to_first - from_first),
443 math::normalize(to_last - from_last))
444 .radian() < min_angle)
445 {
446 if (math::distance_squared(from_first, to_first) >=
447 math::distance_squared(from_last, to_first))
448 {
449 return math::distance_squared(from_last, to_first) >=
450 math::distance_squared(from_last, to_last);
451 }
452
453 return math::distance_squared(from_first, to_first) <
454 math::distance_squared(from_first, to_last);
455 }
456
457 return true;
458 }
459
460 return math::dot(from_last - from_first, to_last - to_first) < 0.0f;
461}
462
465 const InterpolationPairs &curve_pairs,
466 const float mix_factor,
467 const InterpolateFlipMode flip_mode)
468{
470
471 const int dst_curve_num = curve_pairs.from_curves.size();
472 BLI_assert(curve_pairs.to_curves.size() == dst_curve_num);
473 BLI_assert(curve_pairs.from_frames.size() == dst_curve_num);
474 BLI_assert(curve_pairs.to_frames.size() == dst_curve_num);
475
476 /* Sort pairs by unique to/from frame combinations.
477 * Curves for each frame pair are then interpolated together.
478 * Map entries are indices into the original curve_pairs array,
479 * so the order of strokes can be maintained. */
480 Array<int> sorted_pairs(dst_curve_num);
482 std::ranges::sort(sorted_pairs, [&](const int a, const int b) {
483 const int from_frame_a = curve_pairs.from_frames[a];
484 const int to_frame_a = curve_pairs.to_frames[a];
485 const int from_frame_b = curve_pairs.from_frames[b];
486 const int to_frame_b = curve_pairs.to_frames[b];
487 return from_frame_a < from_frame_b ||
488 (from_frame_a == from_frame_b && to_frame_a < to_frame_b);
489 });
490
491 /* Find ranges of sorted pairs with the same from/to frame intervals. */
492 Vector<int> pair_offsets = find_curve_pair_offsets(curve_pairs, sorted_pairs);
493 const OffsetIndices<int> curves_by_pair(pair_offsets);
494
495 /* Compute curve length and flip mode for each pair. */
496 Array<int> dst_curve_offsets(curves_by_pair.size() + 1, 0);
497 Array<bool> dst_curve_flip(curves_by_pair.size(), false);
498 const OffsetIndices<int> dst_points_by_curve = [&]() {
499 /* Last entry for overall size. */
500 if (curves_by_pair.is_empty()) {
501 return OffsetIndices<int>{};
502 }
503
504 for (const int pair_range_i : curves_by_pair.index_range()) {
505 const IndexRange pair_range = curves_by_pair[pair_range_i];
506 BLI_assert(!pair_range.is_empty());
507
508 const int first_pair_index = sorted_pairs[pair_range.first()];
509 const int from_frame = curve_pairs.from_frames[first_pair_index];
510 const int to_frame = curve_pairs.to_frames[first_pair_index];
511 const Drawing *from_drawing = grease_pencil.get_drawing_at(layer, from_frame);
512 const Drawing *to_drawing = grease_pencil.get_drawing_at(layer, to_frame);
513 if (!from_drawing || !to_drawing) {
514 continue;
515 }
516 const OffsetIndices from_points_by_curve = from_drawing->strokes().points_by_curve();
517 const OffsetIndices to_points_by_curve = to_drawing->strokes().points_by_curve();
518 const Span<float3> from_positions = from_drawing->strokes().positions();
519 const Span<float3> to_positions = to_drawing->strokes().positions();
520
521 for (const int sorted_index : pair_range) {
522 const int pair_index = sorted_pairs[sorted_index];
523 const int from_curve = curve_pairs.from_curves[pair_index];
524 const int to_curve = curve_pairs.to_curves[pair_index];
525
526 int curve_size = 0;
527 bool curve_flip = false;
528 if (from_curve < 0 && to_curve < 0) {
529 /* No output curve. */
530 }
531 else if (from_curve < 0) {
532 const IndexRange to_points = to_points_by_curve[to_curve];
533 curve_size = to_points.size();
534 curve_flip = false;
535 }
536 else if (to_curve < 0) {
537 const IndexRange from_points = from_points_by_curve[from_curve];
538 curve_size = from_points.size();
539 curve_flip = false;
540 }
541 else {
542 const IndexRange from_points = from_points_by_curve[from_curve];
543 const IndexRange to_points = to_points_by_curve[to_curve];
544
545 curve_size = std::max(from_points.size(), to_points.size());
546 switch (flip_mode) {
547 case InterpolateFlipMode::None:
548 curve_flip = false;
549 break;
550 case InterpolateFlipMode::Flip:
551 curve_flip = true;
552 break;
553 case InterpolateFlipMode::FlipAuto: {
554 curve_flip = compute_auto_flip(from_positions.slice(from_points),
555 to_positions.slice(to_points));
556 break;
557 }
558 }
559 }
560
561 dst_curve_offsets[pair_index] = curve_size;
562 dst_curve_flip[pair_index] = curve_flip;
563 }
564 }
565 return offset_indices::accumulate_counts_to_offsets(dst_curve_offsets);
566 }();
567 const int dst_point_num = dst_points_by_curve.total_size();
568
569 bke::CurvesGeometry dst_curves(dst_point_num, dst_curve_num);
570 /* Offsets are empty when there are no curves. */
571 if (dst_curve_num > 0) {
572 dst_curves.offsets_for_write().copy_from(dst_curve_offsets);
573 }
574
575 /* Copy vertex group names since we still have other parts of the code depends on vertex group
576 * names to be available. */
577 BKE_defgroup_copy_list(&dst_curves.vertex_group_names, &grease_pencil.vertex_group_names);
578
579 /* Sorted map arrays that can be passed to the interpolation function directly.
580 * These index maps have the same order as the sorted indices, so slices of indices can be used
581 * for interpolating all curves of a frame pair at once. */
582 Array<int> from_curve_buffer(dst_curve_num);
583 Array<int> to_curve_buffer(dst_curve_num);
584 Array<int> from_sample_indices(dst_point_num);
585 Array<int> to_sample_indices(dst_point_num);
586 Array<float> from_sample_factors(dst_point_num);
587 Array<float> to_sample_factors(dst_point_num);
588 IndexMaskMemory memory;
589
590 for (const int pair_range_i : curves_by_pair.index_range()) {
591 const IndexRange pair_range = curves_by_pair[pair_range_i];
592 /* Subset of target curves that are filled by this frame pair. Selection is built from pair
593 * indices, which correspond to dst curve indices. */
594 const IndexMask dst_curve_mask = IndexMask::from_indices(
595 sorted_pairs.as_span().slice(pair_range), memory);
596 MutableSpan<int> from_indices = from_curve_buffer.as_mutable_span().slice(pair_range);
597 MutableSpan<int> to_indices = to_curve_buffer.as_mutable_span().slice(pair_range);
598
599 const int first_pair_index = sorted_pairs[pair_range.first()];
600 const int from_frame = curve_pairs.from_frames[first_pair_index];
601 const int to_frame = curve_pairs.to_frames[first_pair_index];
602 const Drawing *from_drawing = grease_pencil.get_drawing_at(layer, from_frame);
603 const Drawing *to_drawing = grease_pencil.get_drawing_at(layer, to_frame);
604 if (!from_drawing || !to_drawing) {
605 continue;
606 }
607 const OffsetIndices from_points_by_curve = from_drawing->strokes().points_by_curve();
608 const OffsetIndices to_points_by_curve = to_drawing->strokes().points_by_curve();
609 const VArray<bool> from_curves_cyclic = from_drawing->strokes().cyclic();
610 const VArray<bool> to_curves_cyclic = to_drawing->strokes().cyclic();
611
612 for (const int i : pair_range.index_range()) {
613 const int pair_index = sorted_pairs[pair_range[i]];
614 const IndexRange dst_points = dst_points_by_curve[pair_index];
615 from_indices[i] = curve_pairs.from_curves[pair_index];
616 to_indices[i] = curve_pairs.to_curves[pair_index];
617
618 const int from_curve = curve_pairs.from_curves[pair_index];
619 const int to_curve = curve_pairs.to_curves[pair_index];
620
621 BLI_assert(from_curve >= 0 || to_curve >= 0);
622 if (to_curve < 0) {
623 /* Copy "from" curve. */
624 array_utils::fill_index_range(from_sample_indices.as_mutable_span().slice(dst_points));
625 from_sample_factors.fill(0.0f);
626 continue;
627 }
628 if (from_curve < 0) {
629 /* Copy "to" curve. */
630 array_utils::fill_index_range(to_sample_indices.as_mutable_span().slice(dst_points));
631 to_sample_factors.fill(0.0f);
632 continue;
633 }
634
635 const IndexRange from_points = from_points_by_curve[from_curve];
636 const IndexRange to_points = to_points_by_curve[to_curve];
637 if (from_points.size() >= to_points.size()) {
638 /* Target curve samples match 'from' points. */
639 BLI_assert(from_points.size() == dst_points.size());
640 array_utils::fill_index_range(from_sample_indices.as_mutable_span().slice(dst_points));
641 from_sample_factors.as_mutable_span().slice(dst_points).fill(0.0f);
643 to_curve,
644 to_curves_cyclic[to_curve],
645 dst_curve_flip[pair_index],
646 to_sample_indices.as_mutable_span().slice(dst_points),
647 to_sample_factors.as_mutable_span().slice(dst_points));
648 }
649 else {
650 /* Target curve samples match 'to' points. */
651 BLI_assert(to_points.size() == dst_points.size());
653 from_curve,
654 from_curves_cyclic[from_curve],
655 dst_curve_flip[pair_index],
656 from_sample_indices.as_mutable_span().slice(dst_points),
657 from_sample_factors.as_mutable_span().slice(dst_points));
658 array_utils::fill_index_range(to_sample_indices.as_mutable_span().slice(dst_points));
659 to_sample_factors.fill(0.0f);
660 }
661 }
662
664 to_drawing->strokes(),
665 from_indices,
666 to_indices,
667 from_sample_indices,
668 to_sample_indices,
669 from_sample_factors,
670 to_sample_factors,
671 dst_curve_mask,
672 mix_factor,
673 dst_curves,
674 memory);
675 }
676
677 return dst_curves;
678}
679
681
682/* -------------------------------------------------------------------- */
685
687 const InterpolateOpData &opdata)
688{
689 Scene &scene = *CTX_data_scene(&C);
690 ScrArea &area = *CTX_wm_area(&C);
691
692 const StringRef msg = IFACE_("GPencil Interpolation: ");
693
694 std::string status;
695 if (hasNumInput(&opdata.numeric_input)) {
696 char str_ofs[NUM_STR_REP_LEN];
697 outputNumInput(&const_cast<NumInput &>(opdata.numeric_input), str_ofs, scene.unit);
698 status = msg + std::string(str_ofs);
699 }
700 else {
701 status = msg + std::to_string(int((opdata.init_factor + opdata.shift) * 100.0f)) + " %";
702 }
703
704 ED_area_status_text(&area, status.c_str());
706 &C, IFACE_("ESC/RMB to cancel, Enter/LMB to confirm, WHEEL/MOVE to adjust factor"));
707}
708
709/* Utility function to get a drawing at the exact frame number. */
712 const int frame_number)
713{
715
716 const std::optional<int> start_frame = layer.start_frame_at(frame_number);
717 if (start_frame && *start_frame == frame_number) {
718 return grease_pencil.get_editable_drawing_at(layer, frame_number);
719 }
720 return nullptr;
721}
722
727 const int frame_number)
728{
730
731 static constexpr eBezTriple_KeyframeType keyframe_type = BEZT_KEYTYPE_BREAKDOWN;
732
733 if (Drawing *drawing = get_drawing_at_exact_frame(grease_pencil, layer, frame_number)) {
734 layer_data.orig_curves = drawing->strokes();
735 return drawing;
736 }
737 return grease_pencil.insert_frame(layer, frame_number, 0, keyframe_type);
738}
739
741{
744
745 const auto &opdata = *static_cast<InterpolateOpData *>(op.customdata);
746 const Scene &scene = *CTX_data_scene(&C);
747 const int current_frame = scene.r.cfra;
748 Object &object = *CTX_data_active_object(&C);
749 GreasePencil &grease_pencil = *id_cast<GreasePencil *>(object.data);
750 const auto flip_mode = InterpolateFlipMode(RNA_enum_get(op.ptr, "flip"));
751
752 opdata.layer_mask.foreach_index([&](const int layer_index) {
753 Layer &layer = grease_pencil.layer(layer_index);
754 const InterpolateOpData::LayerData &layer_data = opdata.layer_data[layer_index];
755
756 /* Drawings must be created on operator invoke. */
757 Drawing *dst_drawing = get_drawing_at_exact_frame(grease_pencil, layer, current_frame);
758 if (dst_drawing == nullptr) {
759 return;
760 }
761
762 const float mix_factor = opdata.init_factor + opdata.shift;
764 grease_pencil, layer, layer_data.curve_pairs, mix_factor, flip_mode);
765
766 if (opdata.smooth_factor > 0.0f && opdata.smooth_steps > 0) {
767 MutableSpan<float3> positions = interpolated_curves.positions_for_write();
769 interpolated_curves.curves_range(),
770 interpolated_curves.points_by_curve(),
771 VArray<bool>::from_single(true, interpolated_curves.points_num()),
772 interpolated_curves.cyclic(),
773 opdata.smooth_steps,
774 opdata.smooth_factor,
775 false,
776 true,
777 positions);
778 interpolated_curves.tag_positions_changed();
779 }
780
781 dst_drawing->strokes_for_write() = std::move(interpolated_curves);
782 dst_drawing->tag_topology_changed();
783 });
784
786
789}
790
791/* Restore timeline changes when canceled. */
793{
796
797 if (op.customdata == nullptr) {
798 return;
799 }
800
801 const auto &opdata = *static_cast<InterpolateOpData *>(op.customdata);
802 const Scene &scene = *CTX_data_scene(&C);
803 const int current_frame = scene.r.cfra;
804 Object &object = *CTX_data_active_object(&C);
805 GreasePencil &grease_pencil = *id_cast<GreasePencil *>(object.data);
806
807 opdata.layer_mask.foreach_index([&](const int layer_index) {
808 Layer &layer = grease_pencil.layer(layer_index);
809 const InterpolateOpData::LayerData &layer_data = opdata.layer_data[layer_index];
810
811 if (layer_data.orig_curves) {
812 /* Keyframe existed before the operator, restore geometry. */
813 Drawing *drawing = grease_pencil.get_editable_drawing_at(layer, current_frame);
814 if (drawing) {
815 drawing->strokes_for_write() = *layer_data.orig_curves;
816 drawing->tag_topology_changed();
819 }
820 }
821 else {
822 /* Frame was empty, remove the added drawing. */
823 grease_pencil.remove_frames(layer, {current_frame});
826 }
827 });
828}
829
831{
833
835 if (op.customdata == nullptr) {
836 return false;
837 }
838 InterpolateOpData &data = *static_cast<InterpolateOpData *>(op.customdata);
839
840 const Scene &scene = *CTX_data_scene(&C);
841 const int current_frame = scene.r.cfra;
842 Object &object = *CTX_data_active_object(&C);
843 GreasePencil &grease_pencil = *id_cast<GreasePencil *>(object.data);
844
845 /* Create target frames. */
846 data.layer_mask.foreach_index([&](const int layer_index) {
847 Layer &layer = grease_pencil.layer(layer_index);
848 InterpolateOpData::LayerData &layer_data = data.layer_data[layer_index];
849
850 ensure_drawing_at_exact_frame(grease_pencil, layer, layer_data, current_frame);
851 });
852
853 return true;
854}
855
856/* Exit and free memory. */
858{
859 ScrArea &area = *CTX_wm_area(&C);
860
861 if (op.customdata == nullptr) {
862 return;
863 }
864
865 ED_area_status_text(&area, nullptr);
866 ED_workspace_status_text(&C, nullptr);
867
868 MEM_delete(static_cast<InterpolateOpData *>(op.customdata));
869 op.customdata = nullptr;
870}
871
873{
875 return false;
876 }
878 if (!ts || !ts->gp_paint) {
879 return false;
880 }
881 /* Only 3D view */
882 ScrArea *area = CTX_wm_area(C);
883 if (area && area->spacetype != SPACE_VIEW3D) {
884 return false;
885 }
886
887 return true;
888}
889
890/* Invoke handler: Initialize the operator */
892 wmOperator *op,
893 const wmEvent * /*event*/)
894{
895 wmWindow &win = *CTX_wm_window(C);
896
897 if (!grease_pencil_interpolate_init(*C, *op)) {
899 return OPERATOR_CANCELLED;
900 }
901 InterpolateOpData &opdata = *static_cast<InterpolateOpData *>(op->customdata);
902
903 /* Set cursor to indicate modal operator. */
905
907
909
911
913}
914
916 Cancel = 1,
917 Confirm,
920};
921
922/* Modal handler: Events handling during interactive part */
924 wmOperator *op,
925 const wmEvent *event)
926{
927 wmWindow &win = *CTX_wm_window(C);
928 const ARegion &region = *CTX_wm_region(C);
929 ScrArea &area = *CTX_wm_area(C);
930 InterpolateOpData &opdata = *static_cast<InterpolateOpData *>(op->customdata);
931 const bool has_numinput = hasNumInput(&opdata.numeric_input);
932
933 switch (event->type) {
934 case EVT_MODAL_MAP: {
935 switch (InterpolateToolModalEvent(event->val)) {
937 ED_area_status_text(&area, nullptr);
938 ED_workspace_status_text(C, nullptr);
940
943 return OPERATOR_CANCELLED;
945 ED_area_status_text(&area, nullptr);
946 ED_workspace_status_text(C, nullptr);
948
949 /* Write current factor to properties for the next execution. */
950 RNA_float_set(op->ptr, "shift", opdata.shift);
951
953 return OPERATOR_FINISHED;
955 opdata.shift = std::clamp(opdata.init_factor + opdata.shift + 0.01f,
958 opdata.init_factor;
960 break;
962 opdata.shift = std::clamp(opdata.init_factor + opdata.shift - 0.01f,
965 opdata.init_factor;
967 break;
968 }
969 break;
970 }
971 case MOUSEMOVE:
972 /* Only handle mouse-move if not doing numeric-input. */
973 if (!has_numinput) {
974 const float mouse_pos = event->mval[0];
975 const float factor = std::clamp(
977 opdata.shift = factor - opdata.init_factor;
978
980 }
981 break;
982 default: {
983 if ((event->val == KM_PRESS) && handleNumInput(C, &opdata.numeric_input, event)) {
984 float value = (opdata.init_factor + opdata.shift) * 100.0f;
985 applyNumInput(&opdata.numeric_input, &value);
986 opdata.shift = std::clamp(value * 0.01f, interpolate_factor_min, interpolate_factor_max) -
987 opdata.init_factor;
988
990 break;
991 }
992 /* Unhandled event, allow to pass through. */
994 }
995 }
996
998}
999
1005
1007{
1008 ot->name = "Grease Pencil Interpolation";
1009 ot->idname = "GREASE_PENCIL_OT_interpolate";
1010 ot->description = "Interpolate Grease Pencil strokes between frames";
1011
1016
1018
1020 ot->srna,
1021 "shift",
1022 0.0f,
1023 -1.0f,
1024 1.0f,
1025 "Shift",
1026 "Bias factor for which frame has more influence on the interpolated strokes",
1027 -0.9f,
1028 0.9f);
1029
1030 RNA_def_enum(ot->srna,
1031 "layers",
1033 0,
1034 "Layer",
1035 "Layers included in the interpolation");
1036
1038 "exclude_breakdowns",
1039 false,
1040 "Exclude Breakdowns",
1041 "Exclude existing Breakdowns keyframes as interpolation extremes");
1042
1044 "use_selection",
1045 false,
1046 "Use Selection",
1047 "Use only selected strokes for interpolating");
1048
1049 RNA_def_enum(ot->srna,
1050 "flip",
1052 int(InterpolateFlipMode::FlipAuto),
1053 "Flip Mode",
1054 "Invert destination stroke to match start and end with source stroke");
1055
1056 RNA_def_int(ot->srna,
1057 "smooth_steps",
1058 1,
1059 1,
1060 3,
1061 "Iterations",
1062 "Number of times to smooth newly created strokes",
1063 1,
1064 3);
1065
1066 RNA_def_float(ot->srna,
1067 "smooth_factor",
1068 0.0f,
1069 0.0f,
1070 2.0f,
1071 "Smooth",
1072 "Amount of smoothing to apply to interpolated strokes, to reduce jitter/noise",
1073 0.0f,
1074 2.0f);
1075}
1076
1078
1079/* -------------------------------------------------------------------- */
1082
1083/* Helper: Perform easing equation calculations for GP interpolation operator. */
1085 const InterpolationType type,
1086 const float back_easing,
1087 const float amplitude,
1088 const float period,
1089 const CurveMapping &custom_ipo,
1090 const float time)
1091{
1092 constexpr float begin = 0.0f;
1093 constexpr float change = 1.0f;
1094 constexpr float duration = 1.0f;
1095
1096 switch (type) {
1098 return time;
1099
1101 return BKE_curvemapping_evaluateF(&custom_ipo, 0, time);
1102
1104 switch (easing) {
1105 case BEZT_IPO_EASE_IN:
1106 return BLI_easing_back_ease_in(time, begin, change, duration, back_easing);
1107 case BEZT_IPO_EASE_OUT:
1108 return BLI_easing_back_ease_out(time, begin, change, duration, back_easing);
1110 return BLI_easing_back_ease_in_out(time, begin, change, duration, back_easing);
1111
1112 default:
1113 return BLI_easing_back_ease_out(time, begin, change, duration, back_easing);
1114 }
1115 break;
1116
1118 switch (easing) {
1119 case BEZT_IPO_EASE_IN:
1120 return BLI_easing_bounce_ease_in(time, begin, change, duration);
1121 case BEZT_IPO_EASE_OUT:
1122 return BLI_easing_bounce_ease_out(time, begin, change, duration);
1124 return BLI_easing_bounce_ease_in_out(time, begin, change, duration);
1125
1126 default:
1127 return BLI_easing_bounce_ease_out(time, begin, change, duration);
1128 }
1129 break;
1130
1132 switch (easing) {
1133 case BEZT_IPO_EASE_IN:
1134 return BLI_easing_circ_ease_in(time, begin, change, duration);
1135 case BEZT_IPO_EASE_OUT:
1136 return BLI_easing_circ_ease_out(time, begin, change, duration);
1138 return BLI_easing_circ_ease_in_out(time, begin, change, duration);
1139
1140 default:
1141 return BLI_easing_circ_ease_in(time, begin, change, duration);
1142 }
1143 break;
1144
1146 switch (easing) {
1147 case BEZT_IPO_EASE_IN:
1148 return BLI_easing_cubic_ease_in(time, begin, change, duration);
1149 case BEZT_IPO_EASE_OUT:
1150 return BLI_easing_cubic_ease_out(time, begin, change, duration);
1152 return BLI_easing_cubic_ease_in_out(time, begin, change, duration);
1153
1154 default:
1155 return BLI_easing_cubic_ease_in(time, begin, change, duration);
1156 }
1157 break;
1158
1160 switch (easing) {
1161 case BEZT_IPO_EASE_IN:
1162 return BLI_easing_elastic_ease_in(time, begin, change, duration, amplitude, period);
1163 case BEZT_IPO_EASE_OUT:
1164 return BLI_easing_elastic_ease_out(time, begin, change, duration, amplitude, period);
1166 return BLI_easing_elastic_ease_in_out(time, begin, change, duration, amplitude, period);
1167
1168 default:
1169 return BLI_easing_elastic_ease_out(time, begin, change, duration, amplitude, period);
1170 }
1171 break;
1172
1174 switch (easing) {
1175 case BEZT_IPO_EASE_IN:
1176 return BLI_easing_expo_ease_in(time, begin, change, duration);
1177 case BEZT_IPO_EASE_OUT:
1178 return BLI_easing_expo_ease_out(time, begin, change, duration);
1180 return BLI_easing_expo_ease_in_out(time, begin, change, duration);
1181
1182 default:
1183 return BLI_easing_expo_ease_in(time, begin, change, duration);
1184 }
1185 break;
1186
1188 switch (easing) {
1189 case BEZT_IPO_EASE_IN:
1190 return BLI_easing_quad_ease_in(time, begin, change, duration);
1191 case BEZT_IPO_EASE_OUT:
1192 return BLI_easing_quad_ease_out(time, begin, change, duration);
1194 return BLI_easing_quad_ease_in_out(time, begin, change, duration);
1195
1196 default:
1197 return BLI_easing_quad_ease_in(time, begin, change, duration);
1198 }
1199 break;
1200
1202 switch (easing) {
1203 case BEZT_IPO_EASE_IN:
1204 return BLI_easing_quart_ease_in(time, begin, change, duration);
1205 case BEZT_IPO_EASE_OUT:
1206 return BLI_easing_quart_ease_out(time, begin, change, duration);
1208 return BLI_easing_quart_ease_in_out(time, begin, change, duration);
1209
1210 default:
1211 return BLI_easing_quart_ease_in(time, begin, change, duration);
1212 }
1213 break;
1214
1216 switch (easing) {
1217 case BEZT_IPO_EASE_IN:
1218 return BLI_easing_quint_ease_in(time, begin, change, duration);
1219 case BEZT_IPO_EASE_OUT:
1220 return BLI_easing_quint_ease_out(time, begin, change, duration);
1222 return BLI_easing_quint_ease_in_out(time, begin, change, duration);
1223
1224 default:
1225 return BLI_easing_quint_ease_in(time, begin, change, duration);
1226 }
1227 break;
1228
1230 switch (easing) {
1231 case BEZT_IPO_EASE_IN:
1232 return BLI_easing_sine_ease_in(time, begin, change, duration);
1233 case BEZT_IPO_EASE_OUT:
1234 return BLI_easing_sine_ease_out(time, begin, change, duration);
1236 return BLI_easing_sine_ease_in_out(time, begin, change, duration);
1237
1238 default:
1239 return BLI_easing_sine_ease_in(time, begin, change, duration);
1240 }
1241 break;
1242
1243 default:
1245 break;
1246 }
1247
1248 return time;
1249}
1250
1252{
1255
1257 if (op->customdata == nullptr) {
1258 return OPERATOR_FINISHED;
1259 }
1260 InterpolateOpData &opdata = *static_cast<InterpolateOpData *>(op->customdata);
1261
1262 const Scene &scene = *CTX_data_scene(C);
1263 const int current_frame = scene.r.cfra;
1264 Object &object = *CTX_data_active_object(C);
1265 GreasePencil &grease_pencil = *id_cast<GreasePencil *>(object.data);
1267 const InterpolationType type = InterpolationType(RNA_enum_get(op->ptr, "type"));
1268 const eBezTriple_Easing easing = eBezTriple_Easing(RNA_enum_get(op->ptr, "easing"));
1269 const float back_easing = RNA_float_get(op->ptr, "back");
1270 const float amplitude = RNA_float_get(op->ptr, "amplitude");
1271 const float period = RNA_float_get(op->ptr, "period");
1272 const int step = RNA_int_get(op->ptr, "step");
1273
1274 GP_Interpolate_Settings &ipo_settings = ts.gp_interpolate;
1275 if (ipo_settings.custom_ipo == nullptr) {
1276 ipo_settings.custom_ipo = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
1277 }
1278 BKE_curvemapping_init(ipo_settings.custom_ipo);
1279
1280 opdata.layer_mask.foreach_index([&](const int layer_index) {
1281 Layer &layer = grease_pencil.layer(layer_index);
1282 InterpolateOpData::LayerData &layer_data = opdata.layer_data[layer_index];
1283
1284 std::optional<FramesMapKeyIntervalT> interval = find_frames_interval(
1285 layer, current_frame, opdata.exclude_breakdowns);
1286 if (!interval) {
1287 return;
1288 }
1289
1290 const int frame_range_size = interval->second - interval->first + 1;
1291
1292 /* First and last frame are ignored. */
1293 for (int cframe = interval->first + step; cframe < interval->second; cframe += step) {
1295 Drawing *dst_drawing = get_drawing_at_exact_frame(grease_pencil, layer, cframe);
1296 if (dst_drawing == nullptr) {
1297 return;
1298 }
1299
1300 const float base_factor = float(cframe - interval->first) /
1301 std::max(frame_range_size - 1, 1);
1302 const float mix_factor = grease_pencil_interpolate_sequence_easing_calc(
1303 easing, type, back_easing, amplitude, period, *ipo_settings.custom_ipo, base_factor);
1304
1305 bke::CurvesGeometry interpolated_curves = interpolate_between_curves(
1306 grease_pencil, layer, layer_data.curve_pairs, mix_factor, opdata.flipmode);
1307
1308 if (opdata.smooth_factor > 0.0f && opdata.smooth_steps > 0) {
1309 MutableSpan<float3> positions = interpolated_curves.positions_for_write();
1311 interpolated_curves.curves_range(),
1312 interpolated_curves.points_by_curve(),
1313 VArray<bool>::from_single(true, interpolated_curves.points_num()),
1314 interpolated_curves.cyclic(),
1315 opdata.smooth_steps,
1316 opdata.smooth_factor,
1317 false,
1318 true,
1319 positions);
1320 interpolated_curves.tag_positions_changed();
1321 }
1322
1323 dst_drawing->strokes_for_write() = std::move(interpolated_curves);
1324 dst_drawing->tag_topology_changed();
1325 }
1326 });
1327
1328 /* Notifiers */
1331
1332 MEM_delete(static_cast<InterpolateOpData *>(op->customdata));
1333 op->customdata = nullptr;
1334
1335 return OPERATOR_FINISHED;
1336}
1337
1339{
1340 ui::Layout &layout = *op->layout;
1341
1342 const InterpolationType type = InterpolationType(RNA_enum_get(op->ptr, "type"));
1343
1344 layout.use_property_split_set(true);
1345 layout.use_property_decorate_set(false);
1346 ui::Layout *row = &layout.row(true);
1347 row->prop(op->ptr, "step", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1348
1349 row = &layout.row(true);
1350 row->prop(op->ptr, "layers", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1351
1353 row = &layout.row(true);
1354 row->prop(op->ptr, "interpolate_selected_only", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1355 }
1356
1357 row = &layout.row(true);
1358 row->prop(op->ptr, "exclude_breakdowns", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1359
1360 row = &layout.row(true);
1361 row->prop(op->ptr, "use_selection", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1362
1363 row = &layout.row(true);
1364 row->prop(op->ptr, "flip", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1365
1366 ui::Layout &col = layout.column(true);
1367 col.prop(op->ptr, "smooth_factor", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1368 col.prop(op->ptr, "smooth_steps", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1369
1370 row = &layout.row(true);
1371 row->prop(op->ptr, "type", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1372
1373 if (type == InterpolationType::CurveMap) {
1374 /* Get an RNA pointer to ToolSettings to give to the custom curve. */
1375 Scene *scene = CTX_data_scene(C);
1376 ToolSettings *ts = scene->toolsettings;
1377 PointerRNA gpsettings_ptr = RNA_pointer_create_discrete(
1378 &scene->id, RNA_GPencilInterpolateSettings, &ts->gp_interpolate);
1379 template_curve_mapping(
1380 &layout, &gpsettings_ptr, "interpolation_curve", 0, false, true, true, false, false);
1381 }
1382 else if (type != InterpolationType::Linear) {
1383 row = &layout.row(false);
1384 row->prop(op->ptr, "easing", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1385 if (type == InterpolationType::Back) {
1386 row = &layout.row(false);
1387 row->prop(op->ptr, "back", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1388 }
1389 else if (type == InterpolationType::Elastic) {
1390 row = &layout.row(false);
1391 row->prop(op->ptr, "amplitude", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1392 row = &layout.row(false);
1393 row->prop(op->ptr, "period", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1394 }
1395 }
1396}
1397
1399{
1400 PropertyRNA *prop;
1401
1402 ot->name = "Interpolate Sequence";
1403 ot->idname = "GREASE_PENCIL_OT_interpolate_sequence";
1405 ot->description = "Generate 'in-betweens' to smoothly interpolate between Grease Pencil frames";
1406
1410
1411 RNA_def_int(ot->srna,
1412 "step",
1413 1,
1414 1,
1415 MAXFRAME,
1416 "Step",
1417 "Number of frames between generated interpolated frames",
1418 1,
1419 MAXFRAME);
1420
1421 RNA_def_enum(ot->srna,
1422 "layers",
1424 0,
1425 "Layer",
1426 "Layers included in the interpolation");
1427
1429 "exclude_breakdowns",
1430 false,
1431 "Exclude Breakdowns",
1432 "Exclude existing Breakdowns keyframes as interpolation extremes");
1433
1435 "use_selection",
1436 false,
1437 "Use Selection",
1438 "Use only selected strokes for interpolating");
1439
1440 RNA_def_enum(ot->srna,
1441 "flip",
1443 int(InterpolateFlipMode::FlipAuto),
1444 "Flip Mode",
1445 "Invert destination stroke to match start and end with source stroke");
1446
1447 RNA_def_int(ot->srna,
1448 "smooth_steps",
1449 1,
1450 1,
1451 3,
1452 "Iterations",
1453 "Number of times to smooth newly created strokes",
1454 1,
1455 3);
1456
1457 RNA_def_float(ot->srna,
1458 "smooth_factor",
1459 0.0f,
1460 0.0f,
1461 2.0f,
1462 "Smooth",
1463 "Amount of smoothing to apply to interpolated strokes, to reduce jitter/noise",
1464 0.0f,
1465 2.0f);
1466
1467 prop = RNA_def_enum(ot->srna,
1468 "type",
1470 0,
1471 "Type",
1472 "Interpolation method to use the next time 'Interpolate Sequence' is run");
1474
1475 prop = RNA_def_enum(
1476 ot->srna,
1477 "easing",
1480 "Easing",
1481 "Which ends of the segment between the preceding and following Grease Pencil frames "
1482 "easing interpolation is applied to");
1484
1485 prop = RNA_def_float(ot->srna,
1486 "back",
1487 1.702f,
1488 0.0f,
1489 FLT_MAX,
1490 "Back",
1491 "Amount of overshoot for 'back' easing",
1492 0.0f,
1493 FLT_MAX);
1495
1496 RNA_def_float(ot->srna,
1497 "amplitude",
1498 0.15f,
1499 0.0f,
1500 FLT_MAX,
1501 "Amplitude",
1502 "Amount to boost elastic bounces for 'elastic' easing",
1503 0.0f,
1504 FLT_MAX);
1505
1506 RNA_def_float(ot->srna,
1507 "period",
1508 0.15f,
1509 -FLT_MAX,
1510 FLT_MAX,
1511 "Period",
1512 "Time between bounces for elastic easing",
1513 -FLT_MAX,
1514 FLT_MAX);
1515
1517}
1518
1520
1521} // namespace ed::sculpt_paint::greasepencil
1522
1523/* -------------------------------------------------------------------- */
1526
1533
1535{
1537 static const EnumPropertyItem modal_items[] = {
1538 {int(InterpolateToolModalEvent::Cancel), "CANCEL", 0, "Cancel", ""},
1539 {int(InterpolateToolModalEvent::Confirm), "CONFIRM", 0, "Confirm", ""},
1540 {int(InterpolateToolModalEvent::Increase), "INCREASE", 0, "Increase", ""},
1541 {int(InterpolateToolModalEvent::Decrease), "DECREASE", 0, "Decrease", ""},
1542 {0, nullptr, 0, nullptr, nullptr},
1543 };
1544
1545 wmKeyMap *keymap = WM_modalkeymap_find(keyconf, "Interpolate Tool Modal Map");
1546
1547 /* This function is called for each space-type, only needs to add map once. */
1548 if (keymap && keymap->modal_items) {
1549 return;
1550 }
1551
1552 keymap = WM_modalkeymap_ensure(keyconf, "Interpolate Tool Modal Map", modal_items);
1553
1554 WM_modalkeymap_assign(keymap, "GREASE_PENCIL_OT_interpolate");
1555}
1556
1558
1559} // namespace blender
Low-level operations for curves.
support for deformation groups and hooks.
Low-level operations for grease pencil.
#define DEG2RADF(_deg)
#define ISECT_LINE_LINE_CROSS
#define CTX_N_(context, msgid)
#define BLT_I18NCONTEXT_ID_GPENCIL
#define IFACE_(msgid)
#define MAXFRAME
#define NUM_STR_REP_LEN
Read Blender memory allocation and freeing.
#define RNA_ENUM_ITEM_HEADING(name, description)
Definition RNA_types.hh:759
#define C
Definition RandGen.cpp:29
#define UI_ITEM_NONE
#define ND_DATA
Definition WM_types.hh:552
#define NA_EDITED
Definition WM_types.hh:634
#define NC_GPENCIL
Definition WM_types.hh:412
#define BLI_assert_unreachable()
Span< T > as_span() const
Definition BLI_array.hh:254
MutableSpan< T > as_mutable_span()
Definition BLI_array.hh:259
void fill(const T &value) const
Definition BLI_array.hh:283
static IndexMask from_predicate(const IndexMask &universe, LinearAllocator<> &memory, Fn &&predicate, exec_mode::Mode mode=exec_mode::parallel)
static IndexMask from_indices(Span< T > indices, LinearAllocator<> &memory)
static void foreach_segment_zipped(Span< IndexMask > masks, FunctionRef< bool(Span< IndexMaskSegment > segments)> fn)
constexpr int64_t first() const
constexpr int64_t size() const
constexpr bool is_empty() const
static constexpr IndexRange from_single(const int64_t index)
constexpr IndexRange index_range() const
const int * SortedKeysIterator
constexpr void fill(const T &value) const
Definition BLI_span.hh:523
int64_t size() const
IndexRange index_range() const
constexpr Span slice(int64_t start, int64_t size) const
Definition BLI_span.hh:141
constexpr const T & first() const
Definition BLI_span.hh:319
constexpr int64_t size() const
Definition BLI_span.hh:256
constexpr const T & last(const int64_t n=0) const
Definition BLI_span.hh:329
constexpr const T * end() const
Definition BLI_span.hh:228
constexpr const T * begin() const
Definition BLI_span.hh:224
static VArray from_single(T value, const int64_t size)
int64_t size() const
void append(const T &value)
bool is_empty() const
void resize(const int64_t new_size)
MutableSpan< T > as_mutable_span()
void append_n_times(const T &value, const int64_t n)
MutableSpan< float3 > positions_for_write()
VArray< bool > cyclic() const
Span< float3 > positions() const
IndexRange curves_range() const
MutableSpan< int > offsets_for_write()
OffsetIndices< int > points_by_curve() const
bke::CurvesGeometry & strokes_for_write()
const bke::CurvesGeometry & strokes() const
IndexMask slice(IndexRange range) const
void foreach_index(Fn &&fn, Mode mode=exec_mode::serial) const
#define FLT_MAX
#define layer
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
void fill_index_range(MutableSpan< T > span, const T start=0)
bool has_anything_selected(const VArray< bool > &varray, const IndexRange range_to_check)
IndexMask retrieve_selected_curves(const bke::CurvesGeometry &curves, LinearAllocator<> &memory)
bool active_grease_pencil_poll(bContext *C)
static float grease_pencil_interpolate_sequence_easing_calc(const eBezTriple_Easing easing, const InterpolationType type, const float back_easing, const float amplitude, const float period, const CurveMapping &custom_ipo, const float time)
static void grease_pencil_interpolate_exit(bContext &C, wmOperator &op)
static bool find_curve_mapping_from_index(const GreasePencil &grease_pencil, const bke::greasepencil::Layer &layer, const int current_frame, const bool exclude_breakdowns, const bool only_selected, InterpolationPairs &pairs)
static bke::CurvesGeometry interpolate_between_curves(const GreasePencil &grease_pencil, const bke::greasepencil::Layer &layer, const InterpolationPairs &curve_pairs, const float mix_factor, const InterpolateFlipMode flip_mode)
static void grease_pencil_interpolate_cancel(bContext *C, wmOperator *op)
static wmOperatorStatus grease_pencil_interpolate_invoke(bContext *C, wmOperator *op, const wmEvent *)
static void grease_pencil_interpolate_status_indicators(bContext &C, const InterpolateOpData &opdata)
static wmOperatorStatus grease_pencil_interpolate_sequence_exec(bContext *C, wmOperator *op)
static const EnumPropertyItem grease_pencil_interpolate_layer_items[]
static bool grease_pencil_interpolate_init(const bContext &C, wmOperator &op)
static const EnumPropertyItem grease_pencil_interpolate_flip_mode_items[]
static bool compute_auto_flip(const Span< float3 > from_positions, const Span< float3 > to_positions)
static const EnumPropertyItem grease_pencil_interpolation_type_items[]
static void grease_pencil_interpolate_sequence_ui(bContext *C, wmOperator *op)
static wmOperatorStatus grease_pencil_interpolate_modal(bContext *C, wmOperator *op, const wmEvent *event)
static bke::greasepencil::Drawing * get_drawing_at_exact_frame(GreasePencil &grease_pencil, bke::greasepencil::Layer &layer, const int frame_number)
static bool grease_pencil_interpolate_poll(bContext *C)
static void grease_pencil_interpolate_update(bContext &C, const wmOperator &op)
static void GREASE_PENCIL_OT_interpolate_sequence(wmOperatorType *ot)
static std::optional< FramesMapKeyIntervalT > find_frames_interval(const bke::greasepencil::Layer &layer, const int frame_number, const bool exclude_breakdowns)
static void grease_pencil_interpolate_restore(bContext &C, wmOperator &op)
static void GREASE_PENCIL_OT_interpolate(wmOperatorType *ot)
std::pair< int, int > FramesMapKeyIntervalT
static Vector< int > find_curve_pair_offsets(const InterpolationPairs &curve_pairs, const Span< int > order)
static bke::greasepencil::Drawing * ensure_drawing_at_exact_frame(GreasePencil &grease_pencil, bke::greasepencil::Layer &layer, InterpolateOpData::LayerData &layer_data, const int frame_number)
void interpolate_curves_with_samples(const bke::CurvesGeometry &from_curves, const bke::CurvesGeometry &to_curves, Span< int > from_curve_indices, Span< int > to_curve_indices, Span< int > from_sample_indices, Span< int > to_sample_indices, Span< float > from_sample_factors, Span< float > to_sample_factors, const IndexMask &dst_curve_mask, float mix_factor, bke::CurvesGeometry &dst_curves, IndexMaskMemory &memory)
void sample_curve_padded(const Span< float3 > positions, bool cyclic, MutableSpan< int > r_indices, MutableSpan< float > r_factors)
void smooth_curve_attribute(const IndexMask &curves_to_smooth, const OffsetIndices< int > points_by_curve, const VArray< bool > &point_selection, const VArray< bool > &cyclic, int iterations, float influence, bool smooth_ends, bool keep_shape, GMutableSpan attribute_data)
AngleRadianBase< T > angle_between(const QuaternionBase< T > &a, const QuaternionBase< T > &b)
T dot(const QuaternionBase< T > &a, const QuaternionBase< T > &b)
MatBase< T, NumCol, NumRow > normalize(const MatBase< T, NumCol, NumRow > &a)
T distance_squared(const VecBase< T, Size > &a, const VecBase< T, Size > &b)
OffsetIndices< int > accumulate_counts_to_offsets(MutableSpan< int > counts_to_offsets, int start_offset=0)
BMesh Iterators.
CurveMapping * BKE_curvemapping_add(int tot, float minx, float miny, float maxx, float maxy)
Definition colortools.cc:99
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
@ BEZT_KEYTYPE_BREAKDOWN
float BLI_easing_elastic_ease_in(float time, float begin, float change, float duration, float amplitude, float period)
Definition easing.cc:148
void WM_operatortype_append(void(*opfunc)(wmOperatorType *))
float BLI_easing_quint_ease_out(float time, float begin, float change, float duration)
Definition easing.cc:336
ScrArea * CTX_wm_area(const bContext *C)
int RNA_enum_get(PointerRNA *ptr, const char *name)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
wmKeyMap * WM_modalkeymap_find(wmKeyConfig *keyconf, const char *idname)
Definition wm_keymap.cc:999
float BLI_easing_sine_ease_in(float time, float begin, float change, float duration)
Definition easing.cc:350
float BLI_easing_back_ease_in_out(float time, float begin, float change, float duration, float overshoot)
Definition easing.cc:34
float BLI_easing_expo_ease_in_out(float time, float begin, float change, float duration)
Definition easing.cc:273
bool handleNumInput(bContext *C, NumInput *n, const wmEvent *event)
Definition numinput.cc:344
float BLI_easing_quad_ease_out(float time, float begin, float change, float duration)
Definition easing.cc:295
void WM_cursor_modal_set(wmWindow *win, int val)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
float BLI_easing_cubic_ease_in_out(float time, float begin, float change, float duration)
Definition easing.cc:110
int RNA_int_get(PointerRNA *ptr, const char *name)
bool hasNumInput(const NumInput *n)
Definition numinput.cc:188
wmWindow * CTX_wm_window(const bContext *C)
enum eContextObjectMode CTX_data_mode_enum(const bContext *C)
int isect_seg_seg_v2(const float v1[2], const float v2[2], const float v3[2], const float v4[2])
float BLI_easing_quart_ease_out(float time, float begin, float change, float duration)
Definition easing.cc:316
float BLI_easing_cubic_ease_out(float time, float begin, float change, float duration)
Definition easing.cc:104
float BLI_easing_sine_ease_out(float time, float begin, float change, float duration)
Definition easing.cc:355
float BLI_easing_back_ease_out(float time, float begin, float change, float duration, float overshoot)
Definition easing.cc:27
float BLI_easing_expo_ease_in(float time, float begin, float change, float duration)
Definition easing.cc:257
@ CTX_MODE_EDIT_GPENCIL_LEGACY
float BLI_easing_bounce_ease_out(float time, float begin, float change, float duration)
Definition easing.cc:45
void ED_operatortypes_grease_pencil_interpolate()
void ED_interpolatetool_modal_keymap(wmKeyConfig *keyconf)
float BLI_easing_circ_ease_out(float time, float begin, float change, float duration)
Definition easing.cc:83
float BLI_easing_circ_ease_in_out(float time, float begin, float change, float duration)
Definition easing.cc:89
PropertyRNA * RNA_def_float_factor(StructOrFunctionRNA *cont_, const char *identifier, const float default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
float BLI_easing_quint_ease_in(float time, float begin, float change, float duration)
Definition easing.cc:331
void BKE_curvemapping_init(CurveMapping *cumap)
void DEG_id_tag_update(ID *id, unsigned int flags)
BMesh const char void * data
float BLI_easing_quad_ease_in_out(float time, float begin, float change, float duration)
Definition easing.cc:301
const EnumPropertyItem rna_enum_beztriple_interpolation_easing_items[]
void WM_cursor_modal_restore(wmWindow *win)
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
float BLI_easing_back_ease_in(float time, float begin, float change, float duration, float overshoot)
Definition easing.cc:20
void ED_area_status_text(ScrArea *area, const char *str)
Definition area.cc:975
ToolSettings * CTX_data_tool_settings(const bContext *C)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void RNA_float_set(PointerRNA *ptr, const char *name, float value)
float BLI_easing_quart_ease_in_out(float time, float begin, float change, float duration)
Definition easing.cc:322
bool applyNumInput(NumInput *n, float *vec)
Definition numinput.cc:207
float BLI_easing_bounce_ease_in(float time, float begin, float change, float duration)
Definition easing.cc:63
void RNA_def_property_translation_context(PropertyRNA *prop, const char *context)
float BLI_easing_expo_ease_out(float time, float begin, float change, float duration)
Definition easing.cc:265
wmEventHandler_Op * WM_event_add_modal_handler(bContext *C, wmOperator *op)
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)
@ WM_CURSOR_EW_SCROLL
Definition wm_cursors.hh:56
float BLI_easing_bounce_ease_in_out(float time, float begin, float change, float duration)
Definition easing.cc:68
float BLI_easing_quint_ease_in_out(float time, float begin, float change, float duration)
Definition easing.cc:341
iter begin(iter)
void outputNumInput(NumInput *n, char *str, const UnitSettings &unit_settings)
Definition numinput.cc:104
float BLI_easing_circ_ease_in(float time, float begin, float change, float duration)
Definition easing.cc:77
@ ID_RECALC_TRANSFORM
Definition DNA_ID.h:1054
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1074
void BKE_defgroup_copy_list(ListBaseT< bDeformGroup > *outbase, const ListBaseT< bDeformGroup > *inbase)
Definition deform.cc:75
void WM_modalkeymap_assign(wmKeyMap *km, const char *opname)
float BLI_easing_elastic_ease_in_out(float time, float begin, float change, float duration, float amplitude, float period)
Definition easing.cc:213
Scene * CTX_data_scene(const bContext *C)
wmKeyMap * WM_modalkeymap_ensure(wmKeyConfig *keyconf, const char *idname, const EnumPropertyItem *items)
Definition wm_keymap.cc:972
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
@ OPTYPE_BLOCKING
Definition WM_types.hh:192
float BLI_easing_quad_ease_in(float time, float begin, float change, float duration)
Definition easing.cc:289
VecBase< float, 3 > float3
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
float BLI_easing_quart_ease_in(float time, float begin, float change, float duration)
Definition easing.cc:310
PropertyRNA * RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, const float default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
Object * CTX_data_active_object(const bContext *C)
ARegion * CTX_wm_region(const bContext *C)
void ED_workspace_status_text(bContext *C, const char *str)
Definition area.cc:1153
float BKE_curvemapping_evaluateF(const CurveMapping *cumap, int cur, float value)
float BLI_easing_sine_ease_in_out(float time, float begin, float change, float duration)
Definition easing.cc:360
float RNA_float_get(PointerRNA *ptr, const char *name)
float BLI_easing_cubic_ease_in(float time, float begin, float change, float duration)
Definition easing.cc:98
signed char int8_t
Definition BKE_text.h:76
float BLI_easing_elastic_ease_out(float time, float begin, float change, float duration, float amplitude, float period)
Definition easing.cc:181
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
ListBaseT< struct bDeformGroup > vertex_group_names
struct UnitSettings unit
struct RenderData r
struct ToolSettings * toolsettings
struct GP_Interpolate_Settings gp_interpolate
static InterpolateOpData * from_operator(const bContext &C, const wmOperator &op)
void use_property_decorate_set(bool is_decorate)
void use_property_split_set(bool is_sep)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)
Layout & column(bool align)
Layout & row(bool align)
wmEventType type
Definition WM_types.hh:817
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
const char * description
Definition WM_types.hh:1115
void(*) cancel(bContext *C, wmOperator *op)
Definition WM_types.hh:1149
const char * translation_context
Definition WM_types.hh:1113
void(*) ui(bContext *C, wmOperator *op)
Definition WM_types.hh:1176
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1141
wmOperatorStatus(*) modal(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1157
#define N_(msgid)