Blender V5.3
blenkernel/intern/mask.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2012 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cstddef>
10#include <cstring>
11#include <optional>
12
13#include "CLG_log.h"
14
15#include "MEM_guardedalloc.h"
16
17#include "BLI_ghash.hh"
18#include "BLI_listbase.hh"
19#include "BLI_map.hh"
20#include "BLI_math_geom_c.hh"
21#include "BLI_math_matrix_c.hh"
22#include "BLI_math_vector_c.hh"
23#include "BLI_string_utf8.hh"
24#include "BLI_string_utils.hh"
25#include "BLI_utildefines.hh"
26
27#include "BLT_translation.hh"
28
29#include "DNA_mask_types.h"
30#include "DNA_movieclip_types.h"
31#include "DNA_object_types.h"
32
33#include "RNA_path.hh"
34
35#include "BKE_animsys.hh"
36#include "BKE_curve.hh"
37#include "BKE_idtype.hh"
38
39#include "BKE_global.hh"
40#include "BKE_image.hh"
41#include "BKE_lib_id.hh"
42#include "BKE_lib_query.hh"
43#include "BKE_main.hh"
44#include "BKE_mask.hh"
45#include "BKE_movieclip.hh"
46#include "BKE_tracking.hh"
47
49
50#include "BLO_read_write.hh"
51
52namespace blender {
53
54static CLG_LogRef LOG = {"mask"};
55
58{
59 mask->runtime.last_update = 0;
60}
61
62static void mask_copy_data(Main * /*bmain*/,
63 std::optional<Library *> /*owner_library*/,
64 ID *id_dst,
65 const ID *id_src,
66 const int /*flag*/)
67{
68 Mask *mask_dst = id_cast<Mask *>(id_dst);
69 const Mask *mask_src = id_cast<const Mask *>(id_src);
70
71 mask_dst->masklayers.clear_no_delete();
72
73 /* TODO: add unused flag to those as well. */
74 BKE_mask_layer_copy_list(&mask_dst->masklayers, &mask_src->masklayers);
75
76 /* enable fake user by default */
77 id_fake_user_set(&mask_dst->id);
78}
79
80static void mask_free_data(ID *id)
81{
82 Mask *mask = id_cast<Mask *>(id);
83
84 /* free mask data */
85 BKE_mask_layer_free_list(&mask->masklayers);
86}
87
89{
90 Mask *mask = id_cast<Mask *>(id);
91
92 for (MaskLayer &mask_layer : mask->masklayers) {
93 for (MaskSpline &mask_spline : mask_layer.splines) {
95 for (int i = 0; i < mask_spline.tot_point; i++) {
96 MaskSplinePoint *point = &mask_spline.points[i];
98 }
99 }
100 }
101}
102
103static void mask_blend_write(BlendWriter *writer, ID *id, const void *id_address)
104{
105 Mask *mask = id_cast<Mask *>(id);
106
107 writer->write_id_struct(id_address, mask, [](BlendStructWriter<Mask> &struct_writer) {
108 struct_writer.shallow_data.runtime = {};
109 });
110 BKE_id_blend_write(writer, &mask->id);
111
112 for (MaskLayer &masklay : mask->masklayers) {
113 writer->write_struct(&masklay);
114
115 for (MaskSpline &spline : masklay.splines) {
116 int i;
117
118 writer->write_struct(&spline, [](BlendStructWriter<MaskSpline> &struct_writer) {
119 struct_writer.shallow_data.runtime = nullptr;
120 });
121 writer->write_struct_array(spline.tot_point, spline.points);
122
123 for (i = 0; i < spline.tot_point; i++) {
124 MaskSplinePoint *point = &spline.points[i];
125
126 if (point->tot_uw) {
127 writer->write_struct_array(point->tot_uw, point->uw);
128 }
129 }
130 }
131
132 for (MaskLayerShape &masklay_shape : masklay.splines_shapes) {
133 writer->write_struct(&masklay_shape);
134 writer->write_float_array(masklay_shape.tot_vert *
135 (sizeof(MaskLayerShapeElem) / sizeof(float)),
136 masklay_shape.data);
137 }
138 }
139}
140
141static void mask_blend_read_data(BlendDataReader *reader, ID *id)
142{
143 Mask *mask = id_cast<Mask *>(id);
144
145 BLO_read_struct_list(reader, MaskLayer, &mask->masklayers);
146
147 for (MaskLayer &masklay : mask->masklayers) {
148 /* Can't use #newdataadr since it's a pointer within an array. */
149 MaskSplinePoint *act_point_search = nullptr;
150
151 BLO_read_struct_list(reader, MaskSpline, &masklay.splines);
152
153 for (MaskSpline &spline : masklay.splines) {
154 MaskSplinePoint *points_old = spline.points;
155
156 spline.runtime = MEM_new<bke::MaskSplineRuntime>(__func__);
157
158 BLO_read_array_and_validate_size(reader, &spline.points, &spline.tot_point);
159
160 for (int i = 0; i < spline.tot_point; i++) {
161 MaskSplinePoint *point = &spline.points[i];
162
163 if (point->tot_uw) {
164 BLO_read_array_and_validate_size(reader, &point->uw, &point->tot_uw);
165 }
166 }
167
168 /* detect active point */
169 if ((act_point_search == nullptr) && (masklay.act_point >= points_old) &&
170 (masklay.act_point < points_old + spline.tot_point))
171 {
172 act_point_search = &spline.points[masklay.act_point - points_old];
173 }
174 }
175
177
178 for (MaskLayerShape &masklay_shape : masklay.splines_shapes) {
179 if (!BLO_read_array(reader,
180 &masklay_shape.data,
181 masklay_shape.tot_vert,
182 sizeof(MaskLayerShapeElem) / sizeof(float)))
183 {
184 masklay_shape.tot_vert = 0;
185 }
186 }
187
188 BLO_read_struct(reader, MaskSpline, &masklay.act_spline);
189 masklay.act_point = act_point_search;
190 }
191
193}
194
196 .id_code = Mask::id_type,
197 .id_filter = FILTER_ID_MSK,
198 .dependencies_id_types = FILTER_ID_MC, /* WARNING! mask->parent.id, not typed. */
199 .main_listbase_index = INDEX_ID_MSK,
200 .struct_size = sizeof(Mask),
201 .name = "Mask",
202 .name_plural = N_("masks"),
203 .translation_context = BLT_I18NCONTEXT_ID_MASK,
205 .asset_type_info = nullptr,
206
207 .init_data = nullptr,
208 .copy_data = mask_copy_data,
209 .free_data = mask_free_data,
210 .make_local = nullptr,
211 .foreach_id = mask_foreach_id,
212 .foreach_cache = nullptr,
213 .foreach_path = nullptr,
214 .foreach_working_space_color = nullptr,
215 .foreach_asset_weak_reference = nullptr,
216 .owner_pointer_get = nullptr,
217
218 .blend_write = mask_blend_write,
219 .blend_read_data = mask_blend_read_data,
220 .blend_read_after_liblink = nullptr,
221
222 .blend_read_undo_preserve = nullptr,
223
224 .lib_override_apply_post = nullptr,
225};
226
228 ListBaseT<MaskSpline> splines;
230};
231
233{
234 static MaskClipboard mask_clipboard;
235 return mask_clipboard;
236}
237
239 MaskSplinePoint *points_array,
240 MaskSplinePoint *point)
241{
242 if (point == &points_array[spline->tot_point - 1]) {
243 if (spline->flag & MASK_SPLINE_CYCLIC) {
244 return &points_array[0];
245 }
246
247 return nullptr;
248 }
249
250 return point + 1;
251}
252
254 MaskSplinePoint *points_array,
255 MaskSplinePoint *point)
256{
257 if (point == points_array) {
258 if (spline->flag & MASK_SPLINE_CYCLIC) {
259 return &points_array[spline->tot_point - 1];
260 }
261
262 return nullptr;
263 }
264
265 return point - 1;
266}
267
269 MaskSplinePoint *points_array,
270 MaskSplinePoint *point)
271{
272 if (point == &points_array[spline->tot_point - 1]) {
273 if (spline->flag & MASK_SPLINE_CYCLIC) {
274 return &(points_array[0].bezt);
275 }
276
277 return nullptr;
278 }
279
280 return &(point + 1)->bezt;
281}
282
284{
285 return spline->runtime->points_deform.is_empty() ? spline->points :
286 spline->runtime->points_deform.data();
287}
288
290 const MaskSplinePoint *point_ref)
291{
292 if ((point_ref >= spline->points) && (point_ref < &spline->points[spline->tot_point])) {
293 return spline->points;
294 }
295
296 MaskSplinePoint *points_deform = spline->runtime->points_deform.data();
297 if ((point_ref >= points_deform) &&
298 (point_ref < points_deform + spline->runtime->points_deform.size()))
299 {
300 return points_deform;
301 }
302
303 BLI_assert_msg(0, "wrong array");
304 return nullptr;
305}
306
307/* mask layers */
308
310{
311 MaskLayer *masklay = MEM_new<MaskLayer>(__func__);
312
313 STRNCPY_UTF8(masklay->name, name && name[0] ? name : DATA_("MaskLayer"));
314
315 BLI_addtail(&mask->masklayers, masklay);
316
318
319 mask->masklay_tot++;
320
321 masklay->blend = MASK_BLEND_MERGE_ADD;
322 masklay->alpha = 1.0f;
325
326 return masklay;
327}
328
330{
331 return static_cast<MaskLayer *>(BLI_findlink(&mask->masklayers, mask->masklay_act));
332}
333
334MaskLayer *BKE_mask_layer_by_name(Mask *mask, const char *layer_name)
335{
336 for (MaskLayer &mask_layer : mask->masklayers) {
337 if (STREQ(mask_layer.name, layer_name)) {
338 return &mask_layer;
339 }
340 }
341 return nullptr;
342}
343
345{
346 mask->masklay_act = BLI_findindex(&mask->masklayers, masklay);
347}
348
350{
351 BLI_remlink(&mask->masklayers, masklay);
352 BKE_mask_layer_free(masklay);
353
354 mask->masklay_tot--;
355
356 if (mask->masklay_act >= mask->masklay_tot) {
357 mask->masklay_act = mask->masklay_tot - 1;
358 }
359}
360
362{
363 BLI_uniquename(&mask->masklayers,
364 masklay,
365 DATA_("MaskLayer"),
366 '.',
367 offsetof(MaskLayer, name),
368 sizeof(masklay->name));
369}
370
372 Main &bmain, Mask *mask, MaskLayer *masklay, const char *oldname, const char *newname)
373{
374 STRNCPY_UTF8(masklay->name, newname);
375
377
378 /* now fix animation paths */
380 "layers",
381 RNA_path_name_to_infix(oldname),
383 /*verify_paths=*/true,
384 bmain);
385}
386
388{
389 MaskLayer *masklay_new = MEM_new<MaskLayer>("new mask layer");
390
391 STRNCPY_UTF8(masklay_new->name, masklay->name);
392
393 masklay_new->alpha = masklay->alpha;
394 masklay_new->blend = masklay->blend;
395 masklay_new->blend_flag = masklay->blend_flag;
396 masklay_new->flag = masklay->flag;
397 masklay_new->falloff = masklay->falloff;
398 masklay_new->fill_solver = masklay->fill_solver;
399 masklay_new->visibility_flag = masklay->visibility_flag;
400
401 for (MaskSpline &spline : masklay->splines) {
402 MaskSpline *spline_new = BKE_mask_spline_copy(&spline);
403
404 BLI_addtail(&masklay_new->splines, spline_new);
405
406 if (&spline == masklay->act_spline) {
407 masklay_new->act_spline = spline_new;
408 }
409
410 if (masklay->act_point >= spline.points &&
411 masklay->act_point < spline.points + spline.tot_point)
412 {
413 const size_t point_index = masklay->act_point - spline.points;
414 masklay_new->act_point = spline_new->points + point_index;
415 }
416 }
417
418 /* correct animation */
419 if (masklay->splines_shapes.first()) {
420 for (MaskLayerShape &masklay_shape : masklay->splines_shapes) {
421 MaskLayerShape *masklay_shape_new = MEM_new<MaskLayerShape>("new mask layer shape");
422
423 masklay_shape_new->data = MEM_dupalloc(masklay_shape.data);
424 masklay_shape_new->tot_vert = masklay_shape.tot_vert;
425 masklay_shape_new->flag = masklay_shape.flag;
426 masklay_shape_new->frame = masklay_shape.frame;
427
428 BLI_addtail(&masklay_new->splines_shapes, masklay_shape_new);
429 }
430 }
431
432 return masklay_new;
433}
434
435void BKE_mask_layer_copy_list(ListBaseT<MaskLayer> *masklayers_new,
436 const ListBaseT<MaskLayer> *masklayers)
437{
438 for (MaskLayer &layer : *masklayers) {
439 MaskLayer *layer_new = BKE_mask_layer_copy(&layer);
440
441 BLI_addtail(masklayers_new, layer_new);
442 }
443}
444
445/* splines */
446
448{
449 MaskSpline *spline = MEM_new<MaskSpline>("new mask spline");
450 spline->runtime = MEM_new<bke::MaskSplineRuntime>(__func__);
451
452 BLI_addtail(&masklay->splines, spline);
453
454 /* spline shall have one point at least */
455 spline->points = MEM_new_array<MaskSplinePoint>(1, "new mask spline point");
456 spline->tot_point = 1;
457
458 /* cyclic shapes are more usually used */
459 /* Disable because its not so nice for drawing. could be done differently. */
460#if 0
461 spline->flag |= MASK_SPLINE_CYCLIC;
462#endif
463
465
467
468 return spline;
469}
470
472 MaskLayer *src_mask_layer,
473 MaskLayer *dst_mask_layer)
474{
475 if (src_mask_layer != dst_mask_layer) {
476 BLI_remlink(&src_mask_layer->splines, spline);
477 BLI_addtail(&dst_mask_layer->splines, spline);
478 }
479}
480
482{
483 if (BLI_remlink_safe(&mask_layer->splines, spline) == false) {
484 return false;
485 }
486
487 BKE_mask_spline_free(spline);
488
489 return true;
490}
491
493{
494 const int tot_uw = point->tot_uw;
495 const int tot_uw_half = tot_uw / 2;
496
497 float co_tmp[2];
498
499 /* swap handles */
500 copy_v2_v2(co_tmp, point->bezt.vec[0]);
501 copy_v2_v2(point->bezt.vec[0], point->bezt.vec[2]);
502 copy_v2_v2(point->bezt.vec[2], co_tmp);
503 /* in this case the flags are unlikely to be different but swap anyway */
504 std::swap(point->bezt.f1, point->bezt.f3);
505 std::swap(point->bezt.h1, point->bezt.h2);
506
507 /* swap UW's */
508 if (tot_uw > 1) {
509 /* count */
510 for (int i = 0; i < tot_uw_half; i++) {
511 MaskSplinePointUW *uw_a = &point->uw[i];
512 MaskSplinePointUW *uw_b = &point->uw[tot_uw - (i + 1)];
513 std::swap(*uw_a, *uw_b);
514 }
515 }
516
517 for (int i = 0; i < tot_uw; i++) {
518 MaskSplinePointUW *uw = &point->uw[i];
519 uw->u = 1.0f - uw->u;
520 }
521}
522
524{
525 const int tot_point = spline->tot_point;
526 const int tot_point_half = tot_point / 2;
527 int i, i_prev;
528
529 if (tot_point < 2) {
530 return;
531 }
532
533 /* count */
534 for (i = 0; i < tot_point_half; i++) {
535 MaskSplinePoint *point_a = &spline->points[i];
536 MaskSplinePoint *point_b = &spline->points[tot_point - (i + 1)];
537 std::swap(*point_a, *point_b);
538 }
539
540 /* correct UW's */
541 i_prev = tot_point - 1;
542 for (i = 0; i < tot_point; i++) {
543
545
546 std::swap(spline->points[i].uw, spline->points[i_prev].uw);
547 std::swap(spline->points[i].tot_uw, spline->points[i_prev].tot_uw);
548
549 i_prev = i;
550 }
551
552 /* correct animation */
553 if (masklay->splines_shapes.first()) {
554 const int spline_index = BKE_mask_layer_shape_spline_to_index(masklay, spline);
555
556 for (MaskLayerShape &masklay_shape : masklay->splines_shapes) {
557 MaskLayerShapeElem *fp_arr = reinterpret_cast<MaskLayerShapeElem *>(masklay_shape.data);
558
559 for (i = 0; i < tot_point_half; i++) {
560 MaskLayerShapeElem *fp_a = &fp_arr[spline_index + (i)];
561 MaskLayerShapeElem *fp_b = &fp_arr[spline_index + (tot_point - (i + 1))];
562 std::swap(*fp_a, *fp_b);
563 }
564 }
565 }
566}
567
569 MaskSplinePoint *point,
570 float start_u,
571 const float co[2],
572 const eMaskSign sign)
573{
574 const float proj_eps = 1e-3;
575 const float proj_eps_sq = proj_eps * proj_eps;
576 const int N = 1000;
577 float u = -1.0f, du = 1.0f / N, u1 = start_u, u2 = start_u;
578 float ang = -1.0f;
579
580 BLI_assert(abs(sign) <= 1); /* (-1, 0, 1) */
581
582 while (u1 > 0.0f || u2 < 1.0f) {
583 float n1[2], n2[2], co1[2], co2[2];
584 float v1[2], v2[2];
585 float ang1, ang2;
586
587 if (u1 >= 0.0f) {
588 BKE_mask_point_segment_co(spline, point, u1, co1);
589 BKE_mask_point_normal(spline, point, u1, n1);
590 sub_v2_v2v2(v1, co, co1);
591
592 if ((sign == MASK_PROJ_ANY) || ((sign == MASK_PROJ_NEG) && (dot_v2v2(v1, n1) <= 0.0f)) ||
593 ((sign == MASK_PROJ_POS) && (dot_v2v2(v1, n1) >= 0.0f)))
594 {
595
596 if (len_squared_v2(v1) > proj_eps_sq) {
597 ang1 = angle_v2v2(v1, n1);
598 if (ang1 > float(M_PI_2)) {
599 ang1 = float(M_PI) - ang1;
600 }
601
602 if (ang < 0.0f || ang1 < ang) {
603 ang = ang1;
604 u = u1;
605 }
606 }
607 else {
608 u = u1;
609 break;
610 }
611 }
612 }
613
614 if (u2 <= 1.0f) {
615 BKE_mask_point_segment_co(spline, point, u2, co2);
616 BKE_mask_point_normal(spline, point, u2, n2);
617 sub_v2_v2v2(v2, co, co2);
618
619 if ((sign == MASK_PROJ_ANY) || ((sign == MASK_PROJ_NEG) && (dot_v2v2(v2, n2) <= 0.0f)) ||
620 ((sign == MASK_PROJ_POS) && (dot_v2v2(v2, n2) >= 0.0f)))
621 {
622
623 if (len_squared_v2(v2) > proj_eps_sq) {
624 ang2 = angle_v2v2(v2, n2);
625 if (ang2 > float(M_PI_2)) {
626 ang2 = float(M_PI) - ang2;
627 }
628
629 if (ang2 < ang) {
630 ang = ang2;
631 u = u2;
632 }
633 }
634 else {
635 u = u2;
636 break;
637 }
638 }
639 }
640
641 u1 -= du;
642 u2 += du;
643 }
644
645 return u;
646}
647
648/* point */
649
651{
652 const BezTriple *bezt = &point->bezt;
653
654 if (bezt->h1 == bezt->h2 && bezt->h1 == HD_ALIGN) {
656 }
657
659}
660
662 eMaskWhichHandle which_handle,
663 float r_handle[2])
664{
665 const BezTriple *bezt = &point->bezt;
666
667 if (which_handle == MASK_WHICH_HANDLE_STICK) {
668 float vec[2];
669
670 sub_v2_v2v2(vec, bezt->vec[0], bezt->vec[1]);
671
672 r_handle[0] = (bezt->vec[1][0] + vec[1]);
673 r_handle[1] = (bezt->vec[1][1] - vec[0]);
674 }
675 else if (which_handle == MASK_WHICH_HANDLE_LEFT) {
676 copy_v2_v2(r_handle, bezt->vec[0]);
677 }
678 else if (which_handle == MASK_WHICH_HANDLE_RIGHT) {
679 copy_v2_v2(r_handle, bezt->vec[2]);
680 }
681 else {
682 BLI_assert_msg(0, "Unknown handle passed to BKE_mask_point_handle");
683 }
684}
685
687 eMaskWhichHandle which_handle,
688 float loc[2],
689 bool keep_direction,
690 float orig_handle[2],
691 float orig_vec[3][3])
692{
693 BezTriple *bezt = &point->bezt;
694
695 if (which_handle == MASK_WHICH_HANDLE_STICK) {
696 float v1[2], v2[2], vec[2];
697 if (keep_direction) {
698 sub_v2_v2v2(v1, loc, orig_vec[1]);
699 sub_v2_v2v2(v2, orig_handle, orig_vec[1]);
700
701 project_v2_v2v2(vec, v1, v2);
702
703 if (dot_v2v2(v2, vec) > 0) {
704 float len = len_v2(vec);
705
706 sub_v2_v2v2(v1, orig_vec[0], orig_vec[1]);
707
708 mul_v2_fl(v1, len / len_v2(v1));
709
710 add_v2_v2v2(bezt->vec[0], bezt->vec[1], v1);
711 sub_v2_v2v2(bezt->vec[2], bezt->vec[1], v1);
712 }
713 else {
714 copy_v3_v3(bezt->vec[0], bezt->vec[1]);
715 copy_v3_v3(bezt->vec[2], bezt->vec[1]);
716 }
717 }
718 else {
719 sub_v2_v2v2(v1, loc, bezt->vec[1]);
720
721 v2[0] = -v1[1];
722 v2[1] = v1[0];
723
724 add_v2_v2v2(bezt->vec[0], bezt->vec[1], v2);
725 sub_v2_v2v2(bezt->vec[2], bezt->vec[1], v2);
726 }
727 }
728 else if (which_handle == MASK_WHICH_HANDLE_LEFT) {
729 copy_v2_v2(bezt->vec[0], loc);
730 }
731 else if (which_handle == MASK_WHICH_HANDLE_RIGHT) {
732 copy_v2_v2(bezt->vec[2], loc);
733 }
734 else {
735 BLI_assert_msg(0, "unknown handle passed to BKE_mask_point_set_handle");
736 }
737}
738
739void BKE_mask_point_segment_co(MaskSpline *spline, MaskSplinePoint *point, float u, float co[2])
740{
741 MaskSplinePoint *points_array = BKE_mask_spline_point_array_from_point(spline, point);
742
743 BezTriple *bezt = &point->bezt, *bezt_next;
744
745 bezt_next = BKE_mask_spline_point_next_bezt(spline, points_array, point);
746
747 if (!bezt_next) {
748 copy_v2_v2(co, bezt->vec[1]);
749 return;
750 }
751
753 co, bezt->vec[1], bezt->vec[2], bezt_next->vec[0], bezt_next->vec[1], u);
754}
755
756BLI_INLINE void orthogonal_direction_get(const float vec[2], float result[2])
757{
758 result[0] = -vec[1];
759 result[1] = vec[0];
761}
762
763void BKE_mask_point_normal(MaskSpline *spline, MaskSplinePoint *point, float u, float n[2])
764{
765 /* TODO(sergey): This function will re-calculate loads of stuff again and again
766 * when differentiating feather points. This might be easily cached
767 * in the callee function for this case. */
768
769 MaskSplinePoint *point_prev, *point_next;
770
771 /* TODO(sergey): This actually depends on a resolution. */
772 const float du = 0.05f;
773
774 BKE_mask_get_handle_point_adjacent(spline, point, &point_prev, &point_next);
775
776 if (u - du < 0.0f && point_prev == nullptr) {
777 float co[2], dir[2];
778 BKE_mask_point_segment_co(spline, point, u + du, co);
779 sub_v2_v2v2(dir, co, point->bezt.vec[1]);
781 }
782 else if (u + du > 1.0f && point_next == nullptr) {
783 float co[2], dir[2];
784 BKE_mask_point_segment_co(spline, point, u - du, co);
785 sub_v2_v2v2(dir, point->bezt.vec[1], co);
787 }
788 else {
789 float prev_co[2], next_co[2], co[2];
790 float dir1[2], dir2[2], dir[2];
791
792 if (u - du < 0.0f) {
793 BKE_mask_point_segment_co(spline, point_prev, 1.0f + (u - du), prev_co);
794 }
795 else {
796 BKE_mask_point_segment_co(spline, point, u - du, prev_co);
797 }
798
799 BKE_mask_point_segment_co(spline, point, u, co);
800
801 if (u + du > 1.0f) {
802 BKE_mask_point_segment_co(spline, point_next, u + du - 1.0f, next_co);
803 }
804 else {
805 BKE_mask_point_segment_co(spline, point, u + du, next_co);
806 }
807
808 sub_v2_v2v2(dir1, co, prev_co);
809 sub_v2_v2v2(dir2, next_co, co);
810
811 normalize_v2(dir1);
812 normalize_v2(dir2);
813 add_v2_v2v2(dir, dir1, dir2);
814
816 }
817}
818
819static float mask_point_interp_weight(BezTriple *bezt, BezTriple *bezt_next, const float u)
820{
821 return (bezt->weight * (1.0f - u)) + (bezt_next->weight * u);
822}
823
824float BKE_mask_point_weight_scalar(MaskSpline *spline, MaskSplinePoint *point, const float u)
825{
826 MaskSplinePoint *points_array = BKE_mask_spline_point_array_from_point(spline, point);
827 BezTriple *bezt = &point->bezt, *bezt_next;
828
829 bezt_next = BKE_mask_spline_point_next_bezt(spline, points_array, point);
830
831 if (!bezt_next) {
832 return bezt->weight;
833 }
834 if (u <= 0.0f) {
835 return bezt->weight;
836 }
837 if (u >= 1.0f) {
838 return bezt_next->weight;
839 }
840
841 return mask_point_interp_weight(bezt, bezt_next, u);
842}
843
844float BKE_mask_point_weight(MaskSpline *spline, MaskSplinePoint *point, const float u)
845{
846 MaskSplinePoint *points_array = BKE_mask_spline_point_array_from_point(spline, point);
847 BezTriple *bezt = &point->bezt, *bezt_next;
848
849 bezt_next = BKE_mask_spline_point_next_bezt(spline, points_array, point);
850
851 if (!bezt_next) {
852 return bezt->weight;
853 }
854 if (u <= 0.0f) {
855 return bezt->weight;
856 }
857 if (u >= 1.0f) {
858 return bezt_next->weight;
859 }
860
861 float cur_u = 0.0f, cur_w = 0.0f, next_u = 0.0f, next_w = 0.0f, fac; /* Quite warnings */
862
863 for (int i = 0; i <= point->tot_uw; i++) {
864 if (i == 0) {
865 cur_u = 0.0f;
866 cur_w = 1.0f; /* mask_point_interp_weight will scale it */
867 }
868 else {
869 cur_u = point->uw[i - 1].u;
870 cur_w = point->uw[i - 1].w;
871 }
872
873 if (i == point->tot_uw) {
874 next_u = 1.0f;
875 next_w = 1.0f; /* mask_point_interp_weight will scale it */
876 }
877 else {
878 next_u = point->uw[i].u;
879 next_w = point->uw[i].w;
880 }
881
882 if (u >= cur_u && u <= next_u) {
883 break;
884 }
885 }
886
887 fac = (u - cur_u) / (next_u - cur_u);
888
889 cur_w *= mask_point_interp_weight(bezt, bezt_next, cur_u);
890 next_w *= mask_point_interp_weight(bezt, bezt_next, next_u);
891
892 if (spline->weight_interp == MASK_SPLINE_INTERP_EASE) {
893 return cur_w + (next_w - cur_w) * (3.0f * fac * fac - 2.0f * fac * fac * fac);
894 }
895
896 return (1.0f - fac) * cur_w + fac * next_w;
897}
898
900{
901 if (point->tot_uw > 1) {
902 int idx = uw - point->uw;
903
904 if (idx > 0 && point->uw[idx - 1].u > uw->u) {
905 while (idx > 0 && point->uw[idx - 1].u > point->uw[idx].u) {
906 std::swap(point->uw[idx - 1], point->uw[idx]);
907 idx--;
908 }
909 }
910
911 if (idx < point->tot_uw - 1 && point->uw[idx + 1].u < uw->u) {
912 while (idx < point->tot_uw - 1 && point->uw[idx + 1].u < point->uw[idx].u) {
913 std::swap(point->uw[idx + 1], point->uw[idx]);
914 idx++;
915 }
916 }
917
918 return &point->uw[idx];
919 }
920
921 return uw;
922}
923
924void BKE_mask_point_add_uw(MaskSplinePoint *point, float u, float w)
925{
926 if (!point->uw) {
927 point->uw = MEM_new_array<MaskSplinePointUW>(point->tot_uw + 1, "mask point uw");
928 }
929 else {
930 point->uw = static_cast<MaskSplinePointUW *>(
931 MEM_realloc_uninitialized(point->uw, (point->tot_uw + 1) * sizeof(*point->uw)));
932 }
933
934 point->uw[point->tot_uw].u = u;
935 point->uw[point->tot_uw].w = w;
936 point->uw[point->tot_uw].flag = 0;
937
938 point->tot_uw++;
939
940 BKE_mask_point_sort_uw(point, &point->uw[point->tot_uw - 1]);
941}
942
943void BKE_mask_point_select_set(MaskSplinePoint *point, const bool do_select)
944{
945 if (do_select) {
947 }
948 else {
950 }
951
952 for (int i = 0; i < point->tot_uw; i++) {
953 if (do_select) {
954 point->uw[i].flag |= SELECT;
955 }
956 else {
957 point->uw[i].flag &= ~SELECT;
958 }
959 }
960}
961
963 const eMaskWhichHandle which_handle,
964 const bool do_select)
965{
966 if (do_select) {
968 point->bezt.f1 |= BEZT_FLAG_SELECT;
969 point->bezt.f3 |= BEZT_FLAG_SELECT;
970 }
971 else if (which_handle == MASK_WHICH_HANDLE_LEFT) {
972 point->bezt.f1 |= BEZT_FLAG_SELECT;
973 }
974 else if (which_handle == MASK_WHICH_HANDLE_RIGHT) {
975 point->bezt.f3 |= BEZT_FLAG_SELECT;
976 }
977 else {
978 BLI_assert_msg(0, "Wrong which_handle passed to BKE_mask_point_select_set_handle");
979 }
980 }
981 else {
983 point->bezt.f1 &= ~BEZT_FLAG_SELECT;
984 point->bezt.f3 &= ~BEZT_FLAG_SELECT;
985 }
986 else if (which_handle == MASK_WHICH_HANDLE_LEFT) {
987 point->bezt.f1 &= ~BEZT_FLAG_SELECT;
988 }
989 else if (which_handle == MASK_WHICH_HANDLE_RIGHT) {
990 point->bezt.f3 &= ~BEZT_FLAG_SELECT;
991 }
992 else {
993 BLI_assert_msg(0, "Wrong which_handle passed to BKE_mask_point_select_set_handle");
994 }
995 }
996}
997
998/* only mask block itself */
999static Mask *mask_alloc(Main *bmain, const char *name)
1000{
1001 Mask *mask = static_cast<Mask *>(BKE_libblock_alloc(bmain, ID_MSK, name, 0));
1002
1003 id_fake_user_set(&mask->id);
1004
1005 return mask;
1006}
1007
1008Mask *BKE_mask_new(Main *bmain, const char *name)
1009{
1010 Mask *mask;
1011 char mask_name[MAX_ID_NAME - 2];
1012
1013 STRNCPY_UTF8(mask_name, (name && name[0]) ? name : DATA_("Mask"));
1014
1015 mask = mask_alloc(bmain, mask_name);
1016
1017 /* arbitrary defaults */
1018 mask->sfra = 1;
1019 mask->efra = 100;
1020
1022
1023 return mask;
1024}
1025
1027{
1028 if (point->uw) {
1029 MEM_delete(point->uw);
1030 }
1031}
1032
1034{
1035 for (int i = 0; i < spline->tot_point; i++) {
1036 BKE_mask_point_free(&spline->points[i]);
1037 }
1038 for (MaskSplinePoint &point : spline->runtime->points_deform) {
1039 BKE_mask_point_free(&point);
1040 }
1041
1042 MEM_delete(spline->points);
1043
1044 MEM_delete(spline->runtime);
1045
1046 MEM_delete(spline);
1047}
1048
1049void BKE_mask_spline_free_list(ListBaseT<MaskSpline> *splines)
1050{
1051 MaskSpline *spline = splines->first();
1052 while (spline) {
1053 MaskSpline *next_spline = spline->next;
1054
1055 BLI_remlink(splines, spline);
1056 BKE_mask_spline_free(spline);
1057
1058 spline = next_spline;
1059 }
1060}
1061
1062static MaskSplinePoint *mask_spline_points_copy(const MaskSplinePoint *points, int tot_point)
1063{
1064 MaskSplinePoint *npoints = MEM_dupalloc(points);
1065
1066 for (int i = 0; i < tot_point; i++) {
1067 MaskSplinePoint *point = &npoints[i];
1068
1069 if (point->uw) {
1070 point->uw = MEM_dupalloc(point->uw);
1071 }
1072 }
1073
1074 return npoints;
1075}
1076
1078{
1079 MaskSpline *nspline = MEM_new<MaskSpline>("new spline");
1080
1081 *nspline = *spline;
1082
1083 nspline->runtime = MEM_new<bke::MaskSplineRuntime>(__func__);
1084 nspline->points = mask_spline_points_copy(spline->points, spline->tot_point);
1085
1086 if (!spline->runtime->points_deform.is_empty()) {
1087 nspline->runtime->points_deform = spline->runtime->points_deform;
1088 for (MaskSplinePoint &point : nspline->runtime->points_deform) {
1089 if (point.uw) {
1090 point.uw = MEM_dupalloc(point.uw);
1091 }
1092 }
1093 }
1094
1095 return nspline;
1096}
1097
1099{
1100 MaskLayerShape *masklay_shape;
1101 int tot_vert = BKE_mask_layer_shape_totvert(masklay);
1102
1103 masklay_shape = MEM_new<MaskLayerShape>(__func__);
1104 masklay_shape->frame = frame;
1105 masklay_shape->tot_vert = tot_vert;
1106 masklay_shape->data = reinterpret_cast<float *>(
1107 MEM_new_array_zeroed<MaskLayerShapeElem>(tot_vert, __func__));
1108
1109 return masklay_shape;
1110}
1111
1113{
1114 if (masklay_shape->data) {
1115 MEM_delete(masklay_shape->data);
1116 }
1117
1118 MEM_delete(masklay_shape);
1119}
1120
1122{
1123 MaskLayerShape *masklay_shape;
1124
1125 /* free animation data */
1126 masklay_shape = masklay->splines_shapes.first();
1127 while (masklay_shape) {
1128 MaskLayerShape *next_masklay_shape = masklay_shape->next;
1129
1130 BLI_remlink(&masklay->splines_shapes, masklay_shape);
1131 BKE_mask_layer_shape_free(masklay_shape);
1132
1133 masklay_shape = next_masklay_shape;
1134 }
1135}
1136
1138{
1139 /* free splines */
1141
1142 /* free animation data */
1144
1145 MEM_delete(masklay);
1146}
1147
1148void BKE_mask_layer_free_list(ListBaseT<MaskLayer> *masklayers)
1149{
1150 MaskLayer *masklay = masklayers->first();
1151
1152 while (masklay) {
1153 MaskLayer *masklay_next = masklay->next;
1154
1155 BLI_remlink(masklayers, masklay);
1156 BKE_mask_layer_free(masklay);
1157
1158 masklay = masklay_next;
1159 }
1160}
1161
1162void BKE_mask_coord_from_frame(float r_co[2], const float co[2], const float frame_size[2])
1163{
1164 if (frame_size[0] == frame_size[1]) {
1165 r_co[0] = co[0];
1166 r_co[1] = co[1];
1167 }
1168 else if (frame_size[0] < frame_size[1]) {
1169 r_co[0] = ((co[0] - 0.5f) * (frame_size[0] / frame_size[1])) + 0.5f;
1170 r_co[1] = co[1];
1171 }
1172 else { /* (frame_size[0] > frame_size[1]) */
1173 r_co[0] = co[0];
1174 r_co[1] = ((co[1] - 0.5f) * (frame_size[1] / frame_size[0])) + 0.5f;
1175 }
1176}
1177
1179 MovieClipUser *user,
1180 float r_co[2],
1181 const float co[2])
1182{
1183 float aspx, aspy;
1184 float frame_size[2];
1185
1186 /* scaling for the clip */
1187 BKE_movieclip_get_size_fl(clip, user, frame_size);
1188 BKE_movieclip_get_aspect(clip, &aspx, &aspy);
1189
1190 frame_size[1] *= (aspy / aspx);
1191
1192 BKE_mask_coord_from_frame(r_co, co, frame_size);
1193}
1194
1195void BKE_mask_coord_from_image(Image *image, ImageUser *iuser, float r_co[2], const float co[2])
1196{
1197 float aspx, aspy;
1198 float frame_size[2];
1199
1200 BKE_image_get_size_fl(image, iuser, frame_size);
1201 BKE_image_get_aspect(image, &aspx, &aspy);
1202
1203 frame_size[1] *= (aspy / aspx);
1204
1205 BKE_mask_coord_from_frame(r_co, co, frame_size);
1206}
1207
1208void BKE_mask_coord_to_frame(float r_co[2], const float co[2], const float frame_size[2])
1209{
1210 if (frame_size[0] == frame_size[1]) {
1211 r_co[0] = co[0];
1212 r_co[1] = co[1];
1213 }
1214 else if (frame_size[0] < frame_size[1]) {
1215 r_co[0] = ((co[0] - 0.5f) / (frame_size[0] / frame_size[1])) + 0.5f;
1216 r_co[1] = co[1];
1217 }
1218 else { /* (frame_size[0] > frame_size[1]) */
1219 r_co[0] = co[0];
1220 r_co[1] = ((co[1] - 0.5f) / (frame_size[1] / frame_size[0])) + 0.5f;
1221 }
1222}
1223
1225 MovieClipUser *user,
1226 float r_co[2],
1227 const float co[2])
1228{
1229 float aspx, aspy;
1230 float frame_size[2];
1231
1232 /* scaling for the clip */
1233 BKE_movieclip_get_size_fl(clip, user, frame_size);
1234 BKE_movieclip_get_aspect(clip, &aspx, &aspy);
1235
1236 frame_size[1] *= (aspy / aspx);
1237
1238 BKE_mask_coord_to_frame(r_co, co, frame_size);
1239}
1240
1241void BKE_mask_coord_to_image(Image *image, ImageUser *iuser, float r_co[2], const float co[2])
1242{
1243 float aspx, aspy;
1244 float frame_size[2];
1245
1246 /* scaling for the clip */
1247 BKE_image_get_size_fl(image, iuser, frame_size);
1248 BKE_image_get_aspect(image, &aspx, &aspy);
1249
1250 frame_size[1] *= (aspy / aspx);
1251
1252 BKE_mask_coord_to_frame(r_co, co, frame_size);
1253}
1254
1256 float ctime,
1257 float parent_matrix[3][3])
1258{
1259 MaskParent *parent = &point->parent;
1260
1261 unit_m3(parent_matrix);
1262
1263 if (!parent) {
1264 return;
1265 }
1266
1267 if (parent->id_type == ID_MC) {
1268 if (parent->id) {
1269 MovieClip *clip = id_cast<MovieClip *>(parent->id);
1270 MovieTracking *tracking = static_cast<MovieTracking *>(&clip->tracking);
1272
1273 if (ob) {
1274 MovieClipUser user = {};
1275 float clip_framenr = BKE_movieclip_remap_scene_to_clip_frame(clip, ctime);
1276 BKE_movieclip_user_set_frame(&user, ctime);
1277
1278 if (parent->type == MASK_PARENT_POINT_TRACK) {
1280 parent->sub_parent);
1281
1282 if (track) {
1283 float marker_position[2], parent_co[2];
1284 BKE_tracking_marker_get_subframe_position(track, clip_framenr, marker_position);
1285 BKE_mask_coord_from_movieclip(clip, &user, parent_co, marker_position);
1286 sub_v2_v2v2(parent_matrix[2], parent_co, parent->parent_orig);
1287 }
1288 }
1289 else /* if (parent->type == MASK_PARENT_PLANE_TRACK) */ {
1291 ob, parent->sub_parent);
1292
1293 if (plane_track) {
1294 float corners[4][2];
1295 float aspx, aspy;
1296 float frame_size[2], H[3][3], mask_from_clip_matrix[3][3], mask_to_clip_matrix[3][3];
1297
1298 BKE_tracking_plane_marker_get_subframe_corners(plane_track, ctime, corners);
1300
1301 unit_m3(mask_from_clip_matrix);
1302
1303 BKE_movieclip_get_size_fl(clip, &user, frame_size);
1304 BKE_movieclip_get_aspect(clip, &aspx, &aspy);
1305
1306 frame_size[1] *= (aspy / aspx);
1307 if (frame_size[0] == frame_size[1]) {
1308 /* pass */
1309 }
1310 else if (frame_size[0] < frame_size[1]) {
1311 mask_from_clip_matrix[0][0] = frame_size[1] / frame_size[0];
1312 mask_from_clip_matrix[2][0] = -0.5f * (frame_size[1] / frame_size[0]) + 0.5f;
1313 }
1314 else { /* (frame_size[0] > frame_size[1]) */
1315 mask_from_clip_matrix[1][1] = frame_size[1] / frame_size[0];
1316 mask_from_clip_matrix[2][1] = -0.5f * (frame_size[1] / frame_size[0]) + 0.5f;
1317 }
1318
1319 invert_m3_m3(mask_to_clip_matrix, mask_from_clip_matrix);
1320 mul_m3_series(parent_matrix, mask_from_clip_matrix, H, mask_to_clip_matrix);
1321 }
1322 }
1323 }
1324 }
1325 }
1326}
1327
1329 MaskSplinePoint *point_prev,
1330 MaskSplinePoint *point_next)
1331{
1332 BezTriple *bezt = &point->bezt;
1333 BezTriple *bezt_prev = nullptr, *bezt_next = nullptr;
1334 // int handle_type = bezt->h1;
1335
1336 if (point_prev) {
1337 bezt_prev = &point_prev->bezt;
1338 }
1339
1340 if (point_next) {
1341 bezt_next = &point_next->bezt;
1342 }
1343
1344#if 1
1345 if (bezt_prev || bezt_next) {
1346 BKE_nurb_handle_calc(bezt, bezt_prev, bezt_next, false, 0);
1347 }
1348#else
1349 if (handle_type == HD_VECT) {
1350 BKE_nurb_handle_calc(bezt, bezt_prev, bezt_next, 0, 0);
1351 }
1352 else if (handle_type == HD_AUTO) {
1353 BKE_nurb_handle_calc(bezt, bezt_prev, bezt_next, 0, 0);
1354 }
1355 else if (ELEM(handle_type, HD_ALIGN, HD_ALIGN_DOUBLESIDE)) {
1356 float v1[3], v2[3];
1357 float vec[3], h[3];
1358
1359 sub_v3_v3v3(v1, bezt->vec[0], bezt->vec[1]);
1360 sub_v3_v3v3(v2, bezt->vec[2], bezt->vec[1]);
1361 add_v3_v3v3(vec, v1, v2);
1362
1363 if (len_squared_v3(vec) > (1e-3f * 1e-3f)) {
1364 h[0] = vec[1];
1365 h[1] = -vec[0];
1366 h[2] = 0.0f;
1367 }
1368 else {
1369 copy_v3_v3(h, v1);
1370 }
1371
1372 add_v3_v3v3(bezt->vec[0], bezt->vec[1], h);
1373 sub_v3_v3v3(bezt->vec[2], bezt->vec[1], h);
1374 }
1375#endif
1376}
1377
1379 MaskSplinePoint *point,
1380 MaskSplinePoint **r_point_prev,
1381 MaskSplinePoint **r_point_next)
1382{
1383 /* TODO: could avoid calling this at such low level. */
1384 MaskSplinePoint *points_array = BKE_mask_spline_point_array_from_point(spline, point);
1385
1386 *r_point_prev = mask_spline_point_prev(spline, points_array, point);
1387 *r_point_next = mask_spline_point_next(spline, points_array, point);
1388}
1389
1391{
1392 float tvec_a[2], tvec_b[2];
1393
1394 MaskSplinePoint *point_prev, *point_next;
1395
1396 BKE_mask_get_handle_point_adjacent(spline, point, &point_prev, &point_next);
1397
1398 if (point_prev) {
1399 sub_v2_v2v2(tvec_a, point->bezt.vec[1], point_prev->bezt.vec[1]);
1400 normalize_v2(tvec_a);
1401 }
1402 else {
1403 zero_v2(tvec_a);
1404 }
1405
1406 if (point_next) {
1407 sub_v2_v2v2(tvec_b, point_next->bezt.vec[1], point->bezt.vec[1]);
1408 normalize_v2(tvec_b);
1409 }
1410 else {
1411 zero_v2(tvec_b);
1412 }
1413
1414 add_v2_v2v2(t, tvec_a, tvec_b);
1415 normalize_v2(t);
1416}
1417
1419{
1420 MaskSplinePoint *point_prev, *point_next;
1421
1422 BKE_mask_get_handle_point_adjacent(spline, point, &point_prev, &point_next);
1423
1424 mask_calc_point_handle(point, point_prev, point_next);
1425}
1426
1428 MaskSplinePoint *point,
1429 const float u)
1430{
1431 /* TODO: make this interpolate between siblings - not always midpoint! */
1432 int length_tot = 0;
1433 float length_average = 0.0f;
1434 float weight_average = 0.0f;
1435
1436 MaskSplinePoint *point_prev, *point_next;
1437
1438 BLI_assert(u >= 0.0f && u <= 1.0f);
1439
1440 BKE_mask_get_handle_point_adjacent(spline, point, &point_prev, &point_next);
1441
1442 if (point_prev && point_next) {
1443 length_average = ((len_v2v2(point_prev->bezt.vec[0], point_prev->bezt.vec[1]) * (1.0f - u)) +
1444 (len_v2v2(point_next->bezt.vec[2], point_next->bezt.vec[1]) * u));
1445
1446 weight_average = (point_prev->bezt.weight * (1.0f - u) + point_next->bezt.weight * u);
1447 length_tot = 1;
1448 }
1449 else {
1450 if (point_prev) {
1451 length_average += len_v2v2(point_prev->bezt.vec[0], point_prev->bezt.vec[1]);
1452 weight_average += point_prev->bezt.weight;
1453 length_tot++;
1454 }
1455
1456 if (point_next) {
1457 length_average += len_v2v2(point_next->bezt.vec[2], point_next->bezt.vec[1]);
1458 weight_average += point_next->bezt.weight;
1459 length_tot++;
1460 }
1461 }
1462
1463 if (length_tot) {
1464 length_average /= float(length_tot);
1465 weight_average /= float(length_tot);
1466
1467 dist_ensure_v2_v2fl(point->bezt.vec[0], point->bezt.vec[1], length_average);
1468 dist_ensure_v2_v2fl(point->bezt.vec[2], point->bezt.vec[1], length_average);
1469 point->bezt.weight = weight_average;
1470 }
1471}
1472
1474 MaskSplinePoint *point,
1475 const bool do_recalc_length)
1476{
1477 MaskSplinePoint *point_prev, *point_next;
1478 const eBezTriple_Handle h_back[2] = {point->bezt.h1, point->bezt.h2};
1479 const float length_average = (do_recalc_length) ?
1480 0.0f /* dummy value */ :
1481 (len_v3v3(point->bezt.vec[0], point->bezt.vec[1]) +
1482 len_v3v3(point->bezt.vec[1], point->bezt.vec[2])) /
1483 2.0f;
1484
1485 BKE_mask_get_handle_point_adjacent(spline, point, &point_prev, &point_next);
1486
1487 point->bezt.h1 = HD_AUTO;
1488 point->bezt.h2 = HD_AUTO;
1489 mask_calc_point_handle(point, point_prev, point_next);
1490
1491 point->bezt.h1 = h_back[0];
1492 point->bezt.h2 = h_back[1];
1493
1494 /* preserve length by applying it back */
1495 if (do_recalc_length == false) {
1496 dist_ensure_v2_v2fl(point->bezt.vec[0], point->bezt.vec[1], length_average);
1497 dist_ensure_v2_v2fl(point->bezt.vec[2], point->bezt.vec[1], length_average);
1498 }
1499}
1500
1502{
1503 for (MaskSpline &spline : masklay->splines) {
1504 for (int i = 0; i < spline.tot_point; i++) {
1505 BKE_mask_calc_handle_point(&spline, &spline.points[i]);
1506 }
1507 }
1508}
1509
1511{
1512 if (spline->runtime->points_deform.size() != spline->tot_point) {
1513 for (MaskSplinePoint &point : spline->runtime->points_deform) {
1514 BKE_mask_point_free(&point);
1515 }
1516
1517 spline->runtime->points_deform.reinitialize(spline->tot_point);
1518 }
1519}
1520
1521void BKE_mask_layer_evaluate(MaskLayer *masklay, const float ctime, const bool do_newframe)
1522{
1523 /* Animation if available. */
1524 if (do_newframe) {
1525 BKE_mask_layer_evaluate_animation(masklay, ctime);
1526 }
1527 /* Update deform. */
1528 BKE_mask_layer_evaluate_deform(masklay, ctime);
1529}
1530
1531void BKE_mask_evaluate(Mask *mask, const float ctime, const bool do_newframe)
1532{
1533 for (MaskLayer &masklay : mask->masklayers) {
1534 BKE_mask_layer_evaluate(&masklay, ctime, do_newframe);
1535 }
1536}
1537
1539{
1540 parent->id_type = ID_MC;
1541}
1542
1543/* *** animation/shape-key implementation ***
1544 * BKE_mask_layer_shape_XXX */
1545
1547{
1548 /* At least two spline shapes are needed for an animation. */
1549 return !mask_layer.splines_shapes.is_empty() && !mask_layer.splines_shapes.is_single();
1550}
1551
1553{
1554 for (MaskLayer &mask_layer : mask.masklayers) {
1555 if (BKE_mask_layer_is_animated(mask_layer)) {
1556 return true;
1557 }
1558 }
1559 return false;
1560}
1561
1563{
1564 int tot = 0;
1565
1566 for (MaskSpline &spline : masklay->splines) {
1567 tot += spline.tot_point;
1568 }
1569
1570 return tot;
1571}
1572
1574{
1575 copy_v2_v2(shape->point[0], bezt->vec[0]);
1576 copy_v2_v2(shape->point[1], bezt->vec[1]);
1577 copy_v2_v2(shape->point[2], bezt->vec[2]);
1578 shape->weight = bezt->weight;
1579 shape->radius = bezt->radius;
1580}
1581
1583{
1584 copy_v2_v2(bezt->vec[0], shape->point[0]);
1585 copy_v2_v2(bezt->vec[1], shape->point[1]);
1586 copy_v2_v2(bezt->vec[2], shape->point[2]);
1587 bezt->weight = shape->weight;
1588 bezt->radius = shape->radius;
1589}
1590
1592{
1593 int tot = BKE_mask_layer_shape_totvert(masklay);
1594
1595 if (masklay_shape->tot_vert == tot) {
1596 MaskLayerShapeElem *points = masklay_shape->vertices();
1597
1598 for (MaskSpline &spline : masklay->splines) {
1599 for (int i = 0; i < spline.tot_point; i++) {
1600 mask_layer_shape_from_mask_point(&spline.points[i].bezt, points);
1601 points++;
1602 }
1603 }
1604 }
1605 else {
1606 CLOG_ERROR(&LOG,
1607 "vert mismatch %d != %d (frame %d)",
1608 masklay_shape->tot_vert,
1609 tot,
1610 masklay_shape->frame);
1611 }
1612}
1613
1615{
1616 int tot = BKE_mask_layer_shape_totvert(masklay);
1617
1618 if (masklay_shape->tot_vert == tot) {
1619 const MaskLayerShapeElem *points = masklay_shape->vertices();
1620
1621 for (MaskSpline &spline : masklay->splines) {
1622 for (int i = 0; i < spline.tot_point; i++) {
1623 mask_layer_shape_to_mask_point(&spline.points[i].bezt, points);
1624 points++;
1625 }
1626 }
1627 }
1628 else {
1629 CLOG_ERROR(&LOG,
1630 "vert mismatch %d != %d (frame %d)",
1631 masklay_shape->tot_vert,
1632 tot,
1633 masklay_shape->frame);
1634 }
1635}
1636
1638 float target[2], const float a[2], const float b[2], const float t, const float s)
1639{
1640 target[0] = s * a[0] + t * b[0];
1641 target[1] = s * a[1] + t * b[1];
1642}
1643
1645 MaskLayerShape *masklay_shape_a,
1646 MaskLayerShape *masklay_shape_b,
1647 const float fac)
1648{
1649 int tot = BKE_mask_layer_shape_totvert(masklay);
1650 if (masklay_shape_a->tot_vert == tot && masklay_shape_b->tot_vert == tot) {
1651 const MaskLayerShapeElem *fp_a = masklay_shape_a->vertices();
1652 const MaskLayerShapeElem *fp_b = masklay_shape_b->vertices();
1653 const float ifac = 1.0f - fac;
1654
1655 for (MaskSpline &spline : masklay->splines) {
1656 for (int i = 0; i < spline.tot_point; i++) {
1657 BezTriple *bezt = &spline.points[i].bezt;
1658 interp_v2_v2v2_flfl(bezt->vec[0], fp_a->point[0], fp_b->point[0], fac, ifac);
1659 interp_v2_v2v2_flfl(bezt->vec[1], fp_a->point[1], fp_b->point[1], fac, ifac);
1660 interp_v2_v2v2_flfl(bezt->vec[2], fp_a->point[2], fp_b->point[2], fac, ifac);
1661 bezt->weight = (fp_a->weight * ifac) + (fp_b->weight * fac);
1662 bezt->radius = (fp_a->radius * ifac) + (fp_b->radius * fac);
1663 fp_a++;
1664 fp_b++;
1665 }
1666 }
1667 }
1668 else {
1669 CLOG_ERROR(&LOG,
1670 "vert mismatch %d != %d != %d (frame %d - %d)",
1671 masklay_shape_a->tot_vert,
1672 masklay_shape_b->tot_vert,
1673 tot,
1674 masklay_shape_a->frame,
1675 masklay_shape_b->frame);
1676 }
1677}
1678
1680{
1681 for (MaskLayerShape &masklay_shape : masklay->splines_shapes) {
1682 if (frame == masklay_shape.frame) {
1683 return &masklay_shape;
1684 }
1685 if (frame < masklay_shape.frame) {
1686 break;
1687 }
1688 }
1689
1690 return nullptr;
1691}
1692
1694 const float frame,
1695 MaskLayerShape **r_masklay_shape_a,
1696 MaskLayerShape **r_masklay_shape_b)
1697{
1698 MaskLayerShape *masklay_shape;
1699
1700 for (masklay_shape = masklay->splines_shapes.first(); masklay_shape;
1701 masklay_shape = masklay_shape->next)
1702 {
1703 if (frame == masklay_shape->frame) {
1704 *r_masklay_shape_a = masklay_shape;
1705 *r_masklay_shape_b = nullptr;
1706 return 1;
1707 }
1708 if (frame < masklay_shape->frame) {
1709 if (masklay_shape->prev) {
1710 *r_masklay_shape_a = masklay_shape->prev;
1711 *r_masklay_shape_b = masklay_shape;
1712 return 2;
1713 }
1714
1715 *r_masklay_shape_a = masklay_shape;
1716 *r_masklay_shape_b = nullptr;
1717 return 1;
1718 }
1719 }
1720
1721 masklay_shape = masklay->splines_shapes.last();
1722 if (masklay_shape) {
1723 *r_masklay_shape_a = masklay_shape;
1724 *r_masklay_shape_b = nullptr;
1725 return 1;
1726 }
1727
1728 *r_masklay_shape_a = nullptr;
1729 *r_masklay_shape_b = nullptr;
1730
1731 return 0;
1732}
1733
1735{
1736 MaskLayerShape *masklay_shape;
1737
1738 masklay_shape = BKE_mask_layer_shape_find_frame(masklay, frame);
1739
1740 if (masklay_shape == nullptr) {
1741 masklay_shape = BKE_mask_layer_shape_alloc(masklay, frame);
1742 BLI_addtail(&masklay->splines_shapes, masklay_shape);
1744 }
1745
1746 return masklay_shape;
1747}
1748
1750{
1751 MaskLayerShape *masklay_shape_copy = MEM_dupalloc(masklay_shape);
1752
1753 if (masklay_shape_copy->data) [[likely]] {
1754 masklay_shape_copy->data = MEM_dupalloc(masklay_shape_copy->data);
1755 }
1756
1757 return masklay_shape_copy;
1758}
1759
1761{
1762 BLI_remlink(&masklay->splines_shapes, masklay_shape);
1763
1764 BKE_mask_layer_shape_free(masklay_shape);
1765}
1766
1767static int mask_layer_shape_sort_cb(const void *masklay_shape_a_ptr,
1768 const void *masklay_shape_b_ptr)
1769{
1770 const MaskLayerShape *masklay_shape_a = static_cast<const MaskLayerShape *>(masklay_shape_a_ptr);
1771 const MaskLayerShape *masklay_shape_b = static_cast<const MaskLayerShape *>(masklay_shape_b_ptr);
1772
1773 if (masklay_shape_a->frame < masklay_shape_b->frame) {
1774 return -1;
1775 }
1776 if (masklay_shape_a->frame > masklay_shape_b->frame) {
1777 return 1;
1778 }
1779
1780 return 0;
1781}
1782
1787
1789 int index,
1790 MaskSpline **r_masklay_shape,
1791 int *r_index)
1792{
1793 for (MaskSpline &spline : masklay->splines) {
1794 if (index < spline.tot_point) {
1795 *r_masklay_shape = &spline;
1796 *r_index = index;
1797 return true;
1798 }
1799 index -= spline.tot_point;
1800 }
1801
1802 return false;
1803}
1804
1806{
1807 MaskSpline *spline_iter;
1808 int i_abs = 0;
1809 for (spline_iter = masklay->splines.first(); spline_iter && spline_iter != spline;
1810 i_abs += spline_iter->tot_point, spline_iter = spline_iter->next)
1811 {
1812 /* pass */
1813 }
1814
1815 return i_abs;
1816}
1817
1818/* basic 2D interpolation functions, could make more comprehensive later */
1819static void interp_weights_uv_v2_calc(float r_uv[2],
1820 const float pt[2],
1821 const float pt_a[2],
1822 const float pt_b[2])
1823{
1824 const float segment_len = len_v2v2(pt_a, pt_b);
1825 if (segment_len == 0.0f) {
1826 r_uv[0] = 1.0f;
1827 r_uv[1] = 0.0f;
1828 return;
1829 }
1830
1831 float pt_on_line[2];
1832 r_uv[0] = closest_to_line_v2(pt_on_line, pt, pt_a, pt_b);
1833
1834 r_uv[1] = (len_v2v2(pt_on_line, pt) / segment_len) *
1835 /* This line only sets the sign. */
1836 ((line_point_side_v2(pt_a, pt_b, pt) < 0.0f) ? -1.0f : 1.0f);
1837}
1838
1839static void interp_weights_uv_v2_apply(const float uv[2],
1840 float r_pt[2],
1841 const float pt_a[2],
1842 const float pt_b[2])
1843{
1844 const float dvec[2] = {pt_b[0] - pt_a[0], pt_b[1] - pt_a[1]};
1845
1846 /* u */
1847 madd_v2_v2v2fl(r_pt, pt_a, dvec, uv[0]);
1848
1849 /* v */
1850 r_pt[0] += -dvec[1] * uv[1];
1851 r_pt[1] += dvec[0] * uv[1];
1852}
1853
1855 int index,
1856 bool do_init,
1857 bool do_init_interpolate)
1858{
1859 /* spline index from masklay */
1860 MaskSpline *spline;
1861 int spline_point_index;
1862
1863 if (BKE_mask_layer_shape_spline_from_index(masklay, index, &spline, &spline_point_index)) {
1864 /* sanity check */
1865 /* The point has already been removed in this array
1866 * so subtract one when comparing with the shapes. */
1867 int tot = BKE_mask_layer_shape_totvert(masklay) - 1;
1868
1869 /* for interpolation */
1870 /* TODO: assumes closed curve for now. */
1871 float uv[3][2]; /* 3x 2D handles */
1872 const int pi_curr = spline_point_index;
1873 const int pi_prev = ((spline_point_index - 1) + spline->tot_point) % spline->tot_point;
1874 const int pi_next = (spline_point_index + 1) % spline->tot_point;
1875
1876 const int index_offset = index - spline_point_index;
1877 // const int pi_curr_abs = index;
1878 const int pi_prev_abs = pi_prev + index_offset;
1879 const int pi_next_abs = pi_next + index_offset;
1880
1881 if (do_init_interpolate) {
1882 for (int i = 0; i < 3; i++) {
1884 spline->points[pi_curr].bezt.vec[i],
1885 spline->points[pi_prev].bezt.vec[i],
1886 spline->points[pi_next].bezt.vec[i]);
1887 }
1888 }
1889
1890 for (MaskLayerShape &masklay_shape : masklay->splines_shapes) {
1891 if (tot == masklay_shape.tot_vert) {
1892 masklay_shape.tot_vert++;
1894 masklay_shape.tot_vert, __func__);
1895 const MaskLayerShapeElem *data_source = reinterpret_cast<const MaskLayerShapeElem *>(
1896 masklay_shape.data);
1897 if (index > 0) {
1898 std::copy_n(data_source, index, data_resized);
1899 }
1900 if (index != masklay_shape.tot_vert - 1) {
1901 std::copy_n(
1902 data_source + index, masklay_shape.tot_vert - (index + 1), data_resized + index + 1);
1903 }
1904
1905 if (do_init) {
1906 MaskLayerShapeElem *point = &data_resized[index];
1907
1908 mask_layer_shape_from_mask_point(&spline->points[spline_point_index].bezt, point);
1909
1910 if (do_init_interpolate && spline->tot_point > 2) {
1911 for (int i = 0; i < 3; i++) {
1913 point->point[i],
1914 data_resized[pi_prev_abs].point[i],
1915 data_resized[pi_next_abs].point[i]);
1916 }
1917 }
1918 }
1919 else {
1920 memset(&data_resized[index], 0, sizeof(MaskLayerShapeElem));
1921 }
1922
1923 MEM_delete(masklay_shape.data);
1924 masklay_shape.data = reinterpret_cast<float *>(data_resized);
1925 }
1926 else {
1927 CLOG_ERROR(&LOG,
1928 "vert mismatch %d != %d (frame %d)",
1929 masklay_shape.tot_vert,
1930 tot,
1931 masklay_shape.frame);
1932 }
1933 }
1934 }
1935}
1936
1938{
1939 /* the point has already been removed in this array so add one when comparing with the shapes */
1940 int tot = BKE_mask_layer_shape_totvert(masklay);
1941
1942 for (MaskLayerShape &masklay_shape : masklay->splines_shapes) {
1943 if (tot == masklay_shape.tot_vert - count) {
1944 masklay_shape.tot_vert -= count;
1946 masklay_shape.tot_vert, __func__);
1947 const MaskLayerShapeElem *data_source = reinterpret_cast<const MaskLayerShapeElem *>(
1948 masklay_shape.data);
1949 if (index > 0) {
1950 std::copy_n(data_source, index, data_resized);
1951 }
1952 if (index != masklay_shape.tot_vert) {
1953 std::copy_n(
1954 data_source + (index + count), masklay_shape.tot_vert - index, data_resized + index);
1955 }
1956 MEM_delete(masklay_shape.data);
1957 masklay_shape.data = reinterpret_cast<float *>(data_resized);
1958 }
1959 else {
1960 CLOG_ERROR(&LOG,
1961 "vert mismatch %d != %d (frame %d)",
1962 masklay_shape.tot_vert - count,
1963 tot,
1964 masklay_shape.frame);
1965 }
1966 }
1967}
1968
1970{
1971 return max_ii(1, mask->efra - mask->sfra);
1972}
1973
1974/*********************** clipboard *************************/
1975
1977{
1978 MaskClipboard &mask_clipboard = get_mask_clipboard();
1979 BKE_mask_spline_free_list(&mask_clipboard.splines);
1980 mask_clipboard.splines.clear_no_delete();
1981 mask_clipboard.id_hash.clear();
1982}
1983
1988
1990{
1991 /* Nothing to do if selection if disabled for the given layer. */
1992 if (mask_layer->visibility_flag & MASK_HIDE_SELECT) {
1993 return;
1994 }
1995
1997 MaskClipboard &mask_clipboard = get_mask_clipboard();
1998
1999 for (MaskSpline &spline : mask_layer->splines) {
2000 if (spline.flag & SELECT) {
2001 MaskSpline *spline_new = BKE_mask_spline_copy(&spline);
2002 for (int i = 0; i < spline_new->tot_point; i++) {
2003 MaskSplinePoint *point = &spline_new->points[i];
2004 if (point->parent.id) {
2005 mask_clipboard.id_hash.add(point->parent.id, point->parent.id->name);
2006 }
2007 }
2008
2009 BLI_addtail(&mask_clipboard.splines, spline_new);
2010 }
2011 }
2012}
2013
2018
2020{
2021 MaskClipboard &mask_clipboard = get_mask_clipboard();
2022 for (MaskSpline &spline : mask_clipboard.splines) {
2023 MaskSpline *spline_new = BKE_mask_spline_copy(&spline);
2024
2025 for (int i = 0; i < spline_new->tot_point; i++) {
2026 MaskSplinePoint *point = &spline_new->points[i];
2027 if (point->parent.id) {
2028 const StringRefNull id_name = mask_clipboard.id_hash.lookup(point->parent.id);
2029 ListBaseT<ID> *listbase = which_libbase(bmain, GS(id_name.c_str()));
2030 point->parent.id = static_cast<ID *>(
2031 BLI_findstring(listbase, id_name.c_str() + 2, offsetof(ID, name) + 2));
2032 }
2033 }
2034
2035 BLI_addtail(&mask_layer->splines, spline_new);
2036 }
2037}
2038
2039} // namespace blender
#define BKE_LIB_FOREACHID_PROCESS_ID(data_, id_, cb_flag_)
#define SELECT
Definition BKE_mask.hh:19
#define M_PI_2
#define M_PI
#define mul_m3_series(...)
#define STRNCPY_UTF8(dst, src)
#define BLO_read_struct_list(reader, struct_name, list)
#define BLO_read_struct(reader, struct_name, ptr_p)
#define DATA_(msgid)
#define BLT_I18NCONTEXT_ID_MASK
#define CLOG_ERROR(clg_ref,...)
Definition CLG_log.h:188
#define FILTER_ID_MC
Definition DNA_ID.h:1212
#define MAX_ID_NAME
Definition DNA_ID.h:367
#define FILTER_ID_MSK
Definition DNA_ID.h:1214
Object is a sort of wrapper for general info.
Read Blender memory allocation and freeing.
#define BLI_INLINE
#define ELEM(...)
#define BLI_assert_msg(a, msg)
#define STREQ(a, b)
#define MEM_realloc_uninitialized(vmemh, len)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
void clear()
Definition BLI_map.hh:1038
bool add(const Key &key, const Value &value)
Definition BLI_map.hh:295
const Value & lookup(const Key &key) const
Definition BLI_map.hh:545
constexpr const char * c_str() const
#define offsetof(t, d)
#define layer
constexpr T sign(T) RET
#define abs
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
Definition math_dual.h:263
#define N
#define H(x, y, z)
BMesh Iterators.
eMaskWhichHandle
Definition BKE_mask.hh:44
@ MASK_WHICH_HANDLE_BOTH
Definition BKE_mask.hh:49
@ MASK_WHICH_HANDLE_LEFT
Definition BKE_mask.hh:47
@ MASK_WHICH_HANDLE_RIGHT
Definition BKE_mask.hh:48
@ MASK_WHICH_HANDLE_STICK
Definition BKE_mask.hh:46
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
static MaskSplinePoint * mask_spline_points_copy(const MaskSplinePoint *points, int tot_point)
bool BKE_mask_clipboard_is_empty()
void BKE_mask_point_select_set_handle(MaskSplinePoint *point, eMaskWhichHandle which_handle, bool do_select)
void BKE_mask_spline_free(MaskSpline *spline)
static void mask_blend_write(BlendWriter *writer, ID *id, const void *id_address)
void BKE_tracking_marker_get_subframe_position(MovieTrackingTrack *track, float framenr, float pos[2])
Definition tracking.cc:1512
MINLINE void copy_v3_v3(float r[3], const float a[3])
void BKE_mask_layer_shape_changed_remove(MaskLayer *masklay, int index, int count)
MINLINE void add_v2_v2v2(float r[2], const float a[2], const float b[2])
void BKE_mask_layer_evaluate_deform(MaskLayer *masklay, float ctime)
MaskLayerShape * BKE_mask_layer_shape_duplicate(MaskLayerShape *masklay_shape)
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
void BKE_mask_point_handle(const MaskSplinePoint *point, eMaskWhichHandle which_handle, float r_handle[2])
void BKE_mask_clipboard_copy_from_layer(MaskLayer *mask_layer)
MINLINE void mul_v2_fl(float r[2], float f)
BLI_INLINE void orthogonal_direction_get(const float vec[2], float result[2])
Mask * BKE_mask_new(Main *bmain, const char *name)
bool invert_m3_m3(float inverse[3][3], const float mat[3][3])
MINLINE void copy_v2_v2(float r[2], const float a[2])
void BKE_mask_get_handle_point_adjacent(MaskSpline *spline, MaskSplinePoint *point, MaskSplinePoint **r_point_prev, MaskSplinePoint **r_point_next)
MaskLayer * BKE_mask_layer_new(Mask *mask, const char *name)
void BKE_mask_layer_unique_name(Mask *mask, MaskLayer *masklay)
@ MASK_PROJ_POS
Definition BKE_mask.hh:121
@ MASK_PROJ_NEG
Definition BKE_mask.hh:119
@ MASK_PROJ_ANY
Definition BKE_mask.hh:120
MaskLayerShape * BKE_mask_layer_shape_alloc(MaskLayer *masklay, int frame)
void BKE_mask_spline_free_list(ListBaseT< MaskSpline > *splines)
MaskSplinePoint * BKE_mask_spline_point_array_from_point(MaskSpline *spline, const MaskSplinePoint *point_ref)
MaskSpline * BKE_mask_spline_copy(const MaskSpline *spline)
std::string RNA_path_name_to_infix(const StringRefNull string)
Definition rna_path.cc:1419
static MaskSplinePoint * mask_spline_point_prev(MaskSpline *spline, MaskSplinePoint *points_array, MaskSplinePoint *point)
void * BLI_findstring(const ListBase *listbase, const char *id, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:615
MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2])
void BKE_mask_point_parent_matrix_get(MaskSplinePoint *point, float ctime, float parent_matrix[3][3])
MINLINE float normalize_v2(float n[2])
BLI_INLINE bool BLI_listbase_is_empty(const ListBase *lb)
MINLINE int max_ii(int a, int b)
bool BKE_mask_spline_remove(MaskLayer *mask_layer, MaskSpline *spline)
void BKE_mask_layer_shape_to_mask(MaskLayer *masklay, MaskLayerShape *masklay_shape)
static void interp_weights_uv_v2_calc(float r_uv[2], const float pt[2], const float pt_a[2], const float pt_b[2])
int BKE_mask_get_duration(Mask *mask)
void BKE_image_get_aspect(Image *image, float *r_aspx, float *r_aspy)
void BKE_mask_calc_handle_adjacent_interp(MaskSpline *spline, MaskSplinePoint *point, float u)
void id_fake_user_set(ID *id)
Definition lib_id.cc:471
void BKE_mask_evaluate(Mask *mask, float ctime, bool do_newframe)
void BKE_id_blend_write(BlendWriter *writer, ID *id)
Definition lib_id.cc:2890
static MaskClipboard & get_mask_clipboard()
static void mask_layer_shape_from_mask_point(const BezTriple *bezt, MaskLayerShapeElem *shape)
void BKE_nurb_handle_calc(BezTriple *bezt, BezTriple *prev, BezTriple *next, bool is_fcurve, char smoothing)
Definition curve.cc:3975
void BKE_movieclip_get_size_fl(MovieClip *clip, const MovieClipUser *user, float r_size[2])
static void mask_foreach_id(ID *id, LibraryForeachIDData *data)
static void interp_weights_uv_v2_apply(const float uv[2], float r_pt[2], const float pt_a[2], const float pt_b[2])
void BKE_animdata_fix_paths(ID &id, StringRef prefix, StringRef old_infix, StringRef new_infix, bool verify_paths, const DriverMap &driver_map)
void BKE_tracking_plane_marker_get_subframe_corners(MovieTrackingPlaneTrack *plane_track, float framenr, float corners[4][2])
Definition tracking.cc:1871
int BKE_mask_layer_shape_find_frame_range(MaskLayer *masklay, float frame, MaskLayerShape **r_masklay_shape_a, MaskLayerShape **r_masklay_shape_b)
void BKE_mask_layer_evaluate(MaskLayer *masklay, float ctime, bool do_newframe)
void BKE_mask_layer_active_set(Mask *mask, MaskLayer *masklay)
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:541
void BLI_uniquename(const ListBase *list, void *vlink, const char *defname, char delim, int name_offset, size_t name_maxncpy) ATTR_NONNULL(1
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:593
bool BKE_mask_layer_is_animated(MaskLayer &mask_layer)
static void mask_blend_read_data(BlendDataReader *reader, ID *id)
void BKE_movieclip_get_aspect(MovieClip *clip, float *aspx, float *aspy)
void BKE_mask_coord_to_movieclip(MovieClip *clip, MovieClipUser *user, float r_co[2], const float co[2])
static void mask_clipboard_clear()
static void mask_copy_data(Main *, std::optional< Library * >, ID *id_dst, const ID *id_src, const int)
void BKE_mask_coord_from_image(Image *image, ImageUser *iuser, float r_co[2], const float co[2])
MovieTrackingPlaneTrack * BKE_tracking_object_find_plane_track_with_name(MovieTrackingObject *tracking_object, const char *name)
Definition tracking.cc:2010
void BKE_mask_layer_shape_from_mask(MaskLayer *masklay, MaskLayerShape *masklay_shape)
void BKE_mask_layer_shape_unlink(MaskLayer *masklay, MaskLayerShape *masklay_shape)
static void mask_layer_shape_to_mask_point(BezTriple *bezt, const MaskLayerShapeElem *shape)
BezTriple * BKE_mask_spline_point_next_bezt(MaskSpline *spline, MaskSplinePoint *points_array, MaskSplinePoint *point)
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:138
float BKE_mask_point_weight_scalar(MaskSpline *spline, MaskSplinePoint *point, float u)
BMesh const char void * data
@ MASK_PARENT_POINT_TRACK
MovieTrackingTrack * BKE_tracking_object_find_track_with_name(MovieTrackingObject *tracking_object, const char *name)
Definition tracking.cc:1998
MaskSplinePointUW * BKE_mask_point_sort_uw(MaskSplinePoint *point, MaskSplinePointUW *uw)
void BKE_mask_coord_to_frame(float r_co[2], const float co[2], const float frame_size[2])
void BKE_mask_point_set_handle(MaskSplinePoint *point, eMaskWhichHandle which_handle, float loc[2], bool keep_direction, float orig_handle[2], float orig_vec[3][3])
MaskLayer * BKE_mask_layer_by_name(Mask *mask, const char *layer_name)
MaskSpline * BKE_mask_spline_add(MaskLayer *masklay)
void BKE_mask_coord_from_movieclip(MovieClip *clip, MovieClipUser *user, float r_co[2], const float co[2])
void BKE_mask_point_deselect_handles(MaskSplinePoint *p)
Definition BKE_mask.hh:180
void BKE_mask_coord_from_frame(float r_co[2], const float co[2], const float frame_size[2])
void BKE_mask_spline_ensure_deform(MaskSpline *spline)
@ MASK_BLEND_MERGE_ADD
MaskLayer * BKE_mask_layer_active(Mask *mask)
void BKE_mask_calc_tangent_polyline(MaskSpline *spline, MaskSplinePoint *point, float t[2])
void BKE_mask_layer_calc_handles(MaskLayer *masklay)
@ MASK_SPLINE_CYCLIC
void project_v2_v2v2(float out[2], const float p[2], const float v_proj[2])
void BKE_mask_point_select_set(MaskSplinePoint *point, bool do_select)
void BKE_mask_spline_move_to_layer(MaskSpline *spline, MaskLayer *src_mask_layer, MaskLayer *dst_mask_layer)
void BKE_mask_point_normal(MaskSpline *spline, MaskSplinePoint *point, float u, float n[2])
static MaskSplinePoint * mask_spline_point_next(MaskSpline *spline, MaskSplinePoint *points_array, MaskSplinePoint *point)
void BKE_mask_clipboard_paste_to_layer(Main *bmain, MaskLayer *mask_layer)
@ MASK_FILL_SOLVER_CDT
void BKE_tracking_homography_between_two_quads(float reference_corners[4][2], float corners[4][2], float H[3][3])
bool BKE_mask_is_animated(Mask &mask)
void BKE_mask_layer_free(MaskLayer *masklay)
static float mask_point_interp_weight(BezTriple *bezt, BezTriple *bezt_next, const float u)
void BKE_mask_layer_copy_list(ListBaseT< MaskLayer > *masklayers_new, const ListBaseT< MaskLayer > *masklayers)
void dist_ensure_v2_v2fl(float v1[2], const float v2[2], float dist)
static void mask_runtime_reset(Mask *mask)
MINLINE float dot_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT
void BKE_mask_layer_evaluate_animation(MaskLayer *masklay, float ctime)
int BKE_mask_layer_shape_totvert(MaskLayer *masklay)
bool BLO_read_array(BlendDataReader *reader, T **ptr_p, const SizeT array_size, const int elems=1)
void void BLI_listbase_sort(ListBase *listbase, int(*cmp)(const void *, const void *)) ATTR_NONNULL(1
Definition listbase.cc:319
void BKE_movieclip_user_set_frame(MovieClipUser *user, int framenr)
void BLO_read_array_and_validate_size(BlendDataReader *reader, T **ptr_p, SizeT *array_size, const int elems=1)
static void mask_calc_point_handle(MaskSplinePoint *point, MaskSplinePoint *point_prev, MaskSplinePoint *point_next)
float BKE_movieclip_remap_scene_to_clip_frame(const MovieClip *clip, float framenr)
float BKE_mask_point_weight(MaskSpline *spline, MaskSplinePoint *point, float u)
MINLINE float len_squared_v2(const float v[2]) ATTR_WARN_UNUSED_RESULT
static int mask_layer_shape_sort_cb(const void *masklay_shape_a_ptr, const void *masklay_shape_b_ptr)
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
void BKE_mask_calc_handle_point(MaskSpline *spline, MaskSplinePoint *point)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
int BKE_mask_layer_shape_spline_to_index(MaskLayer *masklay, MaskSpline *spline)
void unit_m3(float m[3][3])
MaskLayer * BKE_mask_layer_copy(const MaskLayer *masklay)
void BKE_mask_layer_free_list(ListBaseT< MaskLayer > *masklayers)
void BKE_mask_parent_init(MaskParent *parent)
ATTR_WARN_UNUSED_RESULT const BMVert * v2
@ INDEX_ID_MSK
Definition DNA_ID.h:1308
MINLINE float len_v2v2(const float v1[2], const float v2[2]) ATTR_WARN_UNUSED_RESULT
MaskLayerShape * BKE_mask_layer_shape_find_frame(MaskLayer *masklay, int frame)
void BKE_mask_point_free(MaskSplinePoint *point)
MaskLayerShape * BKE_mask_layer_shape_verify_frame(MaskLayer *masklay, int frame)
ID_Type GS(const char *name)
Definition DNA_ID.h:410
MINLINE float len_squared_v3(const float v[3]) ATTR_WARN_UNUSED_RESULT
float closest_to_line_v2(float r_close[2], const float p[2], const float l1[2], const float l2[2])
void interp_v2_v2v2v2v2_cubic(float p[2], const float v1[2], const float v2[2], const float v3[2], const float v4[2], float u)
@ MASK_LAYERFLAG_FILL_DISCRETE
@ MASK_LAYERFLAG_FILL_OVERLAP
float angle_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT
MINLINE float line_point_side_v2(const float l1[2], const float l2[2], const float pt[2]) ATTR_WARN_UNUSED_RESULT
static CLG_LogRef LOG
Definition logging.cpp:12
void DEG_relations_tag_update(Main *bmain)
void BKE_mask_layer_free_shapes(MaskLayer *masklay)
Free all animation keys for a mask layer.
bool BLI_remlink_safe(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:161
MovieTrackingObject * BKE_tracking_object_get_named(MovieTracking *tracking, const char *name)
Definition tracking.cc:1971
void BKE_mask_coord_to_image(Image *image, ImageUser *iuser, float r_co[2], const float co[2])
static void mask_free_data(ID *id)
MINLINE float len_v2(const float v[2]) ATTR_WARN_UNUSED_RESULT
BLI_INLINE void interp_v2_v2v2_flfl(float target[2], const float a[2], const float b[2], const float t, const float s)
void BKE_mask_point_add_uw(MaskSplinePoint *point, float u, float w)
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
@ MASK_SPLINE_INTERP_EASE
void BKE_image_get_size_fl(Image *image, ImageUser *iuser, float r_size[2])
void BKE_mask_layer_shape_free(MaskLayerShape *masklay_shape)
static Mask * mask_alloc(Main *bmain, const char *name)
MaskSplinePoint * BKE_mask_spline_point_array(MaskSpline *spline)
void BKE_mask_layer_shape_to_mask_interp(MaskLayer *masklay, MaskLayerShape *masklay_shape_a, MaskLayerShape *masklay_shape_b, float fac)
IDTypeInfo IDType_ID_MSK
void BKE_mask_point_direction_switch(MaskSplinePoint *point)
void BKE_mask_spline_direction_switch(MaskLayer *masklay, MaskSpline *spline)
eMaskhandleMode BKE_mask_point_handles_mode_get(const MaskSplinePoint *point)
MINLINE void zero_v2(float r[2])
void BKE_mask_layer_remove(Mask *mask, MaskLayer *masklay)
void * BKE_libblock_alloc(Main *bmain, short type, const char *name, int flag) ATTR_WARN_UNUSED_RESULT
Definition lib_id.cc:1545
void BKE_mask_point_segment_co(MaskSpline *spline, MaskSplinePoint *point, float u, float co[2])
void BKE_mask_layer_shape_changed_add(MaskLayer *masklay, int index, bool do_init, bool do_init_interpolate)
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
eMaskhandleMode
Definition BKE_mask.hh:52
@ MASK_HANDLE_MODE_INDIVIDUAL_HANDLES
Definition BKE_mask.hh:54
@ MASK_HANDLE_MODE_STICK
Definition BKE_mask.hh:53
void BKE_mask_point_select_handles(MaskSplinePoint *p)
Definition BKE_mask.hh:173
bool BKE_mask_layer_shape_spline_from_index(MaskLayer *masklay, int index, MaskSpline **r_masklay_shape, int *r_index)
float BKE_mask_spline_project_co(MaskSpline *spline, MaskSplinePoint *point, float start_u, const float co[2], eMaskSign sign)
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void BKE_mask_layer_shape_sort(MaskLayer *masklay)
void BKE_mask_layer_rename(Main &bmain, Mask *mask, MaskLayer *masklay, const char *oldname, const char *newname)
MINLINE void madd_v2_v2v2fl(float r[2], const float a[2], const float b[2], float f)
ListBaseT< ID > * which_libbase(Main *bmain, short type)
Definition main.cc:1073
void BKE_mask_calc_handle_point_auto(MaskSpline *spline, MaskSplinePoint *point, bool do_recalc_length)
Resets auto handles even for non-auto bezier points.
@ IDTYPE_FLAGS_APPEND_IS_REUSABLE
Definition BKE_idtype.hh:50
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
eBezTriple_Handle h2
eBezTriple_Flag f3
eBezTriple_Flag f1
eBezTriple_Handle h1
void write_float_array(int64_t num, const float *data)
void write_id_struct(const void *id_address, const T *id, BlendStructWriterTypedFn< T > fn=nullptr)
void write_struct(const T *data, BlendStructWriterTypedFn< T > fn=nullptr)
void write_struct_array(const int64_t array_size, const T *data, BlendStructWriterTypedFn< T > fn=nullptr)
char name[258]
Definition DNA_ID.h:433
ListBaseT< MaskSpline > splines
Map< ID *, std::string > id_hash
struct MaskLayerShape * prev
MaskLayerShapeFlag flag
struct MaskLayerShape * next
MaskLayerBlendFlag blend_flag
struct MaskSplinePoint * act_point
struct MaskSpline * act_spline
MaskLayerBlend blend
ListBaseT< MaskLayerShape > splines_shapes
MaskLayerVisibility visibility_flag
ListBaseT< MaskSpline > splines
struct MaskLayer * next
MaskLayerFillSolverType fill_solver
float parent_corners_orig[4][2]
MaskParentType type
MaskSplinePointUW * uw
MaskSplineInterp weight_interp
MaskSplinePoint * points
MaskSplineRuntime * runtime
struct MaskSpline * next
MaskSplineFlag flag
ListBaseT< struct MaskLayer > masklayers
struct MovieTracking tracking
Array< MaskSplinePoint > points_deform
Definition BKE_mask.hh:38
#define N_(msgid)