44 const float point_co[2],
48 const bool reference_adjacent)
58 bezt = &new_point->
bezt;
62 if (reference_point) {
67 int point_index = reference_point - spline->
points;
68 int delta = new_point == spline->
points ? 1 : -1;
73 if (point_index == -1 || point_index >= spline->
tot_point) {
75 if (point_index == -1) {
78 else if (point_index >= spline->
tot_point) {
87 current_point = &spline->
points[point_index];
89 bezt->
h1 = bezt->
h2 = std::max(current_point->
bezt.
h2, current_point->
bezt.
h1);
95 bezt->
h1 = bezt->
h2 = std::max(reference_point->
bezt.
h2, reference_point->
bezt.
h1);
98 reference_parent_point = reference_point;
100 else if (reference_adjacent) {
104 const int index = int(new_point - spline->
points);
110 prev_point = (index != 0) ? &spline->
points[index - 1] :
nullptr;
111 next_point = (index != spline->
tot_point - 1) ? &spline->
points[index + 1] :
nullptr;
114 if (prev_point && next_point) {
121 close_point = prev_point ? prev_point : next_point;
125 uint8_t handle_type = 0;
127 handle_type = prev_point->
bezt.
h2;
130 handle_type = std::max(next_point->
bezt.
h2, handle_type);
132 bezt->
h1 = bezt->
h2 = handle_type;
135 reference_parent_point = close_point;
145 if (reference_parent_point) {
149 float parent_matrix[3][3];
200 if (!
ELEM(*spline,
nullptr, cur_spline)) {
209 *spline = cur_spline;
215 cur_spline = cur_spline->
next;
230 "add mask vert points");
233 memcpy(new_point_array + point_index + 2,
234 spline->
points + point_index + 1,
238 spline->
points = new_point_array;
247 const float threshold = 12;
266 const float ctime = scene->
r.
cfra;
269 int point_index = point - spline->
points;
275 new_point = &spline->
points[point_index + 1];
303 const float ctime = scene->
r.
cfra;
311 float tangent_point[2];
313 bool do_cyclic_correct =
false;
323 point_index = (point - spline->
points);
328 (point_index > 0 && point_index != spline->
tot_point - 1))
333 if (
dot_v2v2(tangent_point, tangent_co) < 0.0f) {
355 if (point_index < 0) {
358 do_cyclic_correct =
true;
366 printf(
"%d\n", point_index);
371 if (do_cyclic_correct) {
372 ref_point = &spline->
points[point_index + 1];
373 new_point = &spline->
points[point_index];
374 *ref_point = *new_point;
378 ref_point = &spline->
points[point_index];
379 new_point = &spline->
points[point_index + 1];
387 point_index = ((int(new_point - spline->
points) + 0) % spline->
tot_point);
403 const float ctime = scene->
r.
cfra;
411 mask->masklay_act =
mask->masklay_tot - 1;
419 new_point = spline->
points;
426 int point_index = ((int(new_point - spline->
points) + 0) % spline->
tot_point);
442 const float point_normalized[2],
443 float point_pixel[2])
448 float scalex, scaley;
451 point_pixel[0] = point_normalized[0] * scalex;
452 point_pixel[1] = point_normalized[1] * scaley;
462 const float tolerance_in_pixels_squared = 4 * 4;
474 float point_pixel[2];
478 if (dist_squared > tolerance_in_pixels_squared) {
500 const bool is_first_point_active = (active_point == first_point);
501 const bool is_last_point_active = (active_point == last_point);
502 if (is_last_point_active) {
505 if (is_first_point_active) {
523 if (
mask ==
nullptr) {
531 mask_layer =
nullptr;
544 C,
mask, spline, active_point, co);
546 return cyclic_result;
587 ot->name =
"Add Vertex";
588 ot->description =
"Add vertex to active spline";
589 ot->idname =
"MASK_OT_add_vertex";
607 "Location of vertex in normalized space",
624 const float threshold = 12;
651 if (weight_scalar != 0.0f) {
652 w =
w / weight_scalar;
686 ot->name =
"Add Feather Vertex";
687 ot->description =
"Add vertex to feather";
688 ot->idname =
"MASK_OT_add_feather_vertex";
706 "Location of vertex in normalized space",
718 const int num_points,
719 const char handle_type,
721 const float location[2])
724 for (
int i = 0;
i < num_points;
i++) {
729 bezier_points[
i].
h1 = handle_type;
730 bezier_points[
i].
h2 = handle_type;
733 for (
int i = 0;
i < num_points;
i++) {
735 &bezier_points[(
i - 1 + num_points) % num_points],
736 &bezier_points[(
i + 1) % num_points],
741 return bezier_points;
759 frame_size[0] = width;
760 frame_size[1] = height;
763 location[0] /= width;
764 location[1] /= height;
768 location[0] -= 0.5f * scale;
769 location[1] -= 0.5f * scale;
771 bool added_mask =
false;
789 for (
int i = 0;
i < num_points;
i++) {
795 new_point->
bezt = bezier_points[
i];
848 "Location of new circle",
861 const float points[4][2] = {{0.0f, 0.5f}, {0.5f, 1.0f}, {1.0f, 0.5f}, {0.5f, 0.0f}};
872 ot->name =
"Add Circle";
873 ot->description =
"Add new circle-shaped spline";
874 ot->idname =
"MASK_OT_primitive_circle_add";
896 const float points[4][2] = {{0.0f, 0.0f}, {0.0f, 1.0f}, {1.0f, 1.0f}, {1.0f, 0.0f}};
907 ot->name =
"Add Square";
908 ot->description =
"Add new square-shaped spline";
909 ot->idname =
"MASK_OT_primitive_square_add";
Mask * CTX_data_edit_mask(const bContext *C)
ScrArea * CTX_wm_area(const bContext *C)
Scene * CTX_data_scene(const bContext *C)
ARegion * CTX_wm_region(const bContext *C)
void BKE_nurb_handle_calc(BezTriple *bezt, BezTriple *prev, BezTriple *next, bool is_fcurve, char smoothing)
#define MASKPOINT_ISSEL_ANY(p)
void BKE_mask_layer_shape_changed_add(struct MaskLayer *masklay, int index, bool do_init, bool do_init_interpolate)
void BKE_mask_calc_tangent_polyline(struct MaskSpline *spline, struct MaskSplinePoint *point, float t[2])
void BKE_mask_point_select_set(struct MaskSplinePoint *point, bool do_select)
void BKE_mask_calc_handle_point_auto(struct MaskSpline *spline, struct MaskSplinePoint *point, bool do_recalc_length)
Resets auto handles even for non-auto bezier points.
struct MaskSpline * BKE_mask_spline_add(struct MaskLayer *masklay)
#define MASKPOINT_SEL_ALL(p)
float BKE_mask_point_weight(struct MaskSpline *spline, struct MaskSplinePoint *point, float u)
struct MaskLayer * BKE_mask_layer_new(struct Mask *mask, const char *name)
float BKE_mask_point_weight_scalar(struct MaskSpline *spline, struct MaskSplinePoint *point, float u)
void BKE_mask_calc_handle_adjacent_interp(struct MaskSpline *spline, struct MaskSplinePoint *point, float u)
void BKE_mask_point_parent_matrix_get(struct MaskSplinePoint *point, float ctime, float parent_matrix[3][3])
void BKE_mask_point_add_uw(struct MaskSplinePoint *point, float u, float w)
int BKE_mask_layer_shape_spline_to_index(struct MaskLayer *masklay, struct MaskSpline *spline)
void BKE_mask_parent_init(struct MaskParent *parent)
#define MASKPOINT_DESEL_ALL(p)
struct MaskLayer * BKE_mask_layer_active(struct Mask *mask)
void BKE_mask_coord_from_frame(float r_co[2], const float co[2], const float frame_size[2])
MINLINE int max_ii(int a, int b)
MINLINE int mod_i(int i, int n)
void mul_m3_v2(const float m[3][3], float r[2])
bool invert_m3(float mat[3][3])
MINLINE float len_squared_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT
MINLINE void mul_v2_fl(float r[2], float f)
MINLINE void copy_v2_v2(float r[2], const float a[2])
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE void add_v2_v2(float r[2], const float a[2])
void print_v2(const char *str, const float v[2])
MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2])
MINLINE float dot_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT
void DEG_id_tag_update(ID *id, unsigned int flags)
void ED_mask_mouse_pos(ScrArea *area, ARegion *region, const int mval[2], float r_co[2])
void ED_mask_get_size(ScrArea *area, int *r_width, int *r_height)
void ED_mask_cursor_location_get(ScrArea *area, float cursor[2])
bool ED_maskedit_visible_splines_poll(bContext *C)
void ED_mask_pixelspace_factor(ScrArea *area, ARegion *region, float *r_scalex, float *r_scaley)
bool ED_maskedit_mask_poll(bContext *C)
Read Guarded memory(de)allocation.
#define MEM_recallocN(vmemh, len)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
static wmOperatorStatus add_vertex_exec(bContext *C, wmOperator *op)
static wmOperatorStatus add_vertex_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void * MEM_calloc_arrayN(size_t len, size_t size, const char *str)
void MEM_freeN(void *vmemh)
static wmOperatorStatus add_feather_vertex_exec(bContext *C, wmOperator *op)
void MASK_OT_add_feather_vertex(wmOperatorType *ot)
static int create_primitive_from_points(bContext *C, wmOperator *op, const float(*points)[2], int num_points, char handle_type)
static wmOperatorStatus add_vertex_handle_cyclic(bContext *C, Mask *mask, MaskSpline *spline, MaskSplinePoint *active_point, float co[2])
static wmOperatorStatus primitive_add_invoke(bContext *C, wmOperator *op, const wmEvent *)
static wmOperatorStatus add_vertex_exec(bContext *C, wmOperator *op)
static bool add_vertex_extrude(const bContext *C, Mask *mask, MaskLayer *mask_layer, const float co[2])
static void setup_vertex_point(Mask *mask, MaskSpline *spline, MaskSplinePoint *new_point, const float point_co[2], const float u, const float ctime, const MaskSplinePoint *reference_point, const bool reference_adjacent)
void MASK_OT_primitive_square_add(wmOperatorType *ot)
static BezTriple * points_to_bezier(const float(*points)[2], const int num_points, const char handle_type, const float scale, const float location[2])
void MASK_OT_primitive_circle_add(wmOperatorType *ot)
static void define_primitive_add_properties(wmOperatorType *ot)
static wmOperatorStatus add_vertex_handle_cyclic_at_point(bContext *C, Mask *mask, MaskSpline *spline, MaskSplinePoint *active_point, MaskSplinePoint *other_point, float co[2])
static wmOperatorStatus primitive_square_add_exec(bContext *C, wmOperator *op)
static wmOperatorStatus add_vertex_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static wmOperatorStatus primitive_circle_add_exec(bContext *C, wmOperator *op)
static void mask_point_make_pixel_space(bContext *C, const float point_normalized[2], float point_pixel[2])
static bool add_vertex_new(const bContext *C, Mask *mask, MaskLayer *mask_layer, const float co[2])
static wmOperatorStatus add_feather_vertex_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static bool add_vertex_subdivide(const bContext *C, Mask *mask, const float co[2])
void MASK_OT_add_vertex(wmOperatorType *ot)
static void finSelectedSplinePoint(MaskLayer *mask_layer, MaskSpline **spline, MaskSplinePoint **point, bool check_active)
static void mask_spline_add_point_at_index(MaskSpline *spline, int point_index)
void ED_mask_view_lock_state_restore_no_jump(const bContext *C, const MaskViewLockState *state)
void ED_mask_view_lock_state_store(const bContext *C, MaskViewLockState *state)
MaskSplinePoint * ED_mask_point_find_nearest(const bContext *C, Mask *mask_orig, const float normal_co[2], float threshold, MaskLayer **r_mask_layer, MaskSpline **r_spline, eMaskWhichHandle *r_which_handle, float *r_score)
MaskLayer * ED_mask_layer_ensure(bContext *C, bool *r_added_mask)
Mask * ED_mask_new(bContext *C, const char *name)
void ED_mask_select_flush_all(Mask *mask)
void ED_mask_select_toggle_all(Mask *mask, int action)
bool ED_mask_find_nearest_diff_point(const bContext *C, Mask *mask_orig, const float normal_co[2], int threshold, bool feather, float tangent[2], bool use_deform, bool use_project, MaskLayer **r_mask_layer, MaskSpline **r_spline, MaskSplinePoint **r_point, float *r_u, float *r_score)
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
void RNA_float_get_array(PointerRNA *ptr, const char *name, float *values)
float RNA_float_get(PointerRNA *ptr, const char *name)
void RNA_float_set_array(PointerRNA *ptr, const char *name, const float *values)
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)
PropertyRNA * RNA_def_float_vector(StructOrFunctionRNA *cont_, const char *identifier, const int len, const float *default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
struct MaskSplinePoint * act_point
struct MaskSpline * act_spline
wmOperatorStatus(* exec)(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
struct wmOperatorType * type
void WM_event_add_notifier(const bContext *C, uint type, void *reference)