Blender  V3.3
mask_relationships.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2012 Blender Foundation. All rights reserved. */
3 
8 #include "BLI_listbase.h"
9 #include "BLI_math.h"
10 #include "BLI_string.h"
11 
12 #include "BKE_context.h"
13 #include "BKE_mask.h"
14 #include "BKE_tracking.h"
15 
16 #include "DEG_depsgraph.h"
17 
18 #include "DNA_mask_types.h"
19 
20 #include "WM_api.h"
21 #include "WM_types.h"
22 
23 #include "ED_clip.h" /* frame remapping functions */
24 #include "ED_mask.h"
25 #include "ED_screen.h"
26 
27 #include "mask_intern.h" /* own include */
28 
30 {
32 
33  LISTBASE_FOREACH (MaskLayer *, mask_layer, &mask->masklayers) {
34  if (mask_layer->visibility_flag & (MASK_HIDE_VIEW | MASK_HIDE_SELECT)) {
35  continue;
36  }
37 
38  LISTBASE_FOREACH (MaskSpline *, spline, &mask_layer->splines) {
39  for (int i = 0; i < spline->tot_point; i++) {
40  MaskSplinePoint *point = &spline->points[i];
41 
43  point->parent.id = NULL;
44  }
45  }
46  }
47  }
48 
50  DEG_id_tag_update(&mask->id, 0);
51 
52  return OPERATOR_FINISHED;
53 }
54 
56 {
57  /* identifiers */
58  ot->name = "Clear Parent";
59  ot->description = "Clear the mask's parenting";
60  ot->idname = "MASK_OT_parent_clear";
61 
62  /* api callbacks */
64 
66 
67  /* flags */
69 }
70 
72 {
74 
75  /* parent info */
78  MovieTracking *tracking;
79  MovieTrackingTrack *track;
80  MovieTrackingPlaneTrack *plane_track;
81  MovieTrackingObject *tracking_object;
82  /* done */
83 
84  int framenr, parent_type;
85  float parmask_pos[2], orig_corners[4][2];
86  const char *sub_parent_name;
87 
88  if (ELEM(NULL, sc, clip)) {
89  return OPERATOR_CANCELLED;
90  }
91 
93 
94  tracking = &clip->tracking;
95  tracking_object = BKE_tracking_object_get_active(&clip->tracking);
96 
97  if (tracking_object == NULL) {
98  return OPERATOR_CANCELLED;
99  }
100 
101  if ((track = BKE_tracking_track_get_active(tracking)) != NULL) {
102  MovieTrackingMarker *marker = BKE_tracking_marker_get(track, framenr);
103  float marker_pos_ofs[2];
104 
105  add_v2_v2v2(marker_pos_ofs, marker->pos, track->offset);
106 
107  BKE_mask_coord_from_movieclip(clip, &sc->user, parmask_pos, marker_pos_ofs);
108 
109  sub_parent_name = track->name;
110  parent_type = MASK_PARENT_POINT_TRACK;
111  memset(orig_corners, 0, sizeof(orig_corners));
112  }
113  else if ((plane_track = BKE_tracking_plane_track_get_active(tracking)) != NULL) {
114  MovieTrackingPlaneMarker *plane_marker = BKE_tracking_plane_marker_get(plane_track, framenr);
115 
116  zero_v2(parmask_pos);
117  sub_parent_name = plane_track->name;
118  parent_type = MASK_PARENT_PLANE_TRACK;
119  memcpy(orig_corners, plane_marker->corners, sizeof(orig_corners));
120  }
121  else {
122  return OPERATOR_CANCELLED;
123  }
124 
125  LISTBASE_FOREACH (MaskLayer *, mask_layer, &mask->masklayers) {
126  if (mask_layer->visibility_flag & (MASK_HIDE_VIEW | MASK_HIDE_SELECT)) {
127  continue;
128  }
129 
130  LISTBASE_FOREACH (MaskSpline *, spline, &mask_layer->splines) {
131  for (int i = 0; i < spline->tot_point; i++) {
132  MaskSplinePoint *point = &spline->points[i];
133 
134  if (MASKPOINT_ISSEL_ANY(point)) {
135  point->parent.id_type = ID_MC;
136  point->parent.id = &clip->id;
137  point->parent.type = parent_type;
138  BLI_strncpy(point->parent.parent, tracking_object->name, sizeof(point->parent.parent));
139  BLI_strncpy(point->parent.sub_parent, sub_parent_name, sizeof(point->parent.sub_parent));
140 
141  copy_v2_v2(point->parent.parent_orig, parmask_pos);
142  memcpy(point->parent.parent_corners_orig,
143  orig_corners,
144  sizeof(point->parent.parent_corners_orig));
145  }
146  }
147  }
148  }
149 
151  DEG_id_tag_update(&mask->id, 0);
152 
153  return OPERATOR_FINISHED;
154 }
155 
157 {
158  /* identifiers */
159  ot->name = "Make Parent";
160  ot->description = "Set the mask's parenting";
161  ot->idname = "MASK_OT_parent_set";
162 
163  /* api callbacks */
164  // ot->invoke = mask_parent_set_invoke;
166 
168 
169  /* flags */
171 }
struct SpaceClip * CTX_wm_space_clip(const bContext *C)
Definition: context.c:923
struct Mask * CTX_data_edit_mask(const bContext *C)
Definition: context.c:1390
#define MASKPOINT_ISSEL_ANY(p)
Definition: BKE_mask.h:296
void BKE_mask_coord_from_movieclip(struct MovieClip *clip, struct MovieClipUser *user, float r_co[2], const float co[2])
Definition: mask.c:1200
struct MovieTrackingPlaneTrack * BKE_tracking_plane_track_get_active(struct MovieTracking *tracking)
Definition: tracking.c:1718
struct MovieTrackingPlaneMarker * BKE_tracking_plane_marker_get(struct MovieTrackingPlaneTrack *plane_track, int framenr)
Definition: tracking.c:1890
struct MovieTrackingTrack * BKE_tracking_track_get_active(struct MovieTracking *tracking)
Definition: tracking.c:1089
struct MovieTrackingMarker * BKE_tracking_marker_get(struct MovieTrackingTrack *track, int framenr)
Definition: tracking.c:1424
struct MovieTrackingObject * BKE_tracking_object_get_active(struct MovieTracking *tracking)
Definition: tracking.c:2092
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:336
MINLINE void copy_v2_v2(float r[2], const float a[2])
MINLINE void add_v2_v2v2(float r[2], const float a[2], const float b[2])
MINLINE void zero_v2(float r[2])
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONNULL()
Definition: string.c:64
#define UNUSED(x)
#define ELEM(...)
void DEG_id_tag_update(struct ID *id, int flag)
@ ID_MC
Definition: DNA_ID_enums.h:73
#define MASK_HIDE_SELECT
#define MASK_HIDE_VIEW
@ MASK_PARENT_PLANE_TRACK
@ MASK_PARENT_POINT_TRACK
@ OPERATOR_CANCELLED
@ OPERATOR_FINISHED
int ED_space_clip_get_clip_frame_number(struct SpaceClip *sc)
Definition: clip_editor.c:231
bool ED_space_clip_maskedit_mask_poll(struct bContext *C)
Definition: clip_editor.c:115
struct MovieClip * ED_space_clip_get_clip(struct SpaceClip *sc)
Definition: clip_editor.c:570
bool ED_maskedit_mask_visible_splines_poll(struct bContext *C)
Definition: mask_edit.c:77
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Sky Generate a procedural sky texture Noise Generate fractal Perlin noise Wave Generate procedural bands or rings with noise Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a point
#define C
Definition: RandGen.cpp:25
@ OPTYPE_UNDO
Definition: WM_types.h:148
@ OPTYPE_REGISTER
Definition: WM_types.h:146
#define ND_DATA
Definition: WM_types.h:456
#define NC_MASK
Definition: WM_types.h:348
static int mask_parent_set_exec(bContext *C, wmOperator *UNUSED(op))
void MASK_OT_parent_clear(wmOperatorType *ot)
void MASK_OT_parent_set(wmOperatorType *ot)
static int mask_parent_clear_exec(bContext *C, wmOperator *UNUSED(op))
ccl_device_inline float4 mask(const int4 &mask, const float4 &a)
Definition: math_float4.h:513
struct MovieTracking tracking
struct MovieClipUser user
const char * name
Definition: WM_types.h:888
const char * idname
Definition: WM_types.h:890
bool(* poll)(struct bContext *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:943
const char * description
Definition: WM_types.h:893
int(* exec)(struct bContext *, struct wmOperator *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:903
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
wmOperatorType * ot
Definition: wm_files.c:3479