46 const float point_co[2],
50 const bool reference_adjacent)
60 bezt = &new_point->
bezt;
64 if (reference_point) {
69 int point_index = reference_point - spline->
points;
70 int delta = new_point == spline->
points ? 1 : -1;
71 for (
int i = 0; i < spline->
tot_point - 1; i++) {
75 if (point_index == -1 || point_index >= spline->
tot_point) {
77 if (point_index == -1) {
80 else if (point_index >= spline->
tot_point) {
89 current_point = &spline->
points[point_index];
91 bezt->
h1 = bezt->
h2 = std::max(current_point->
bezt.
h2, current_point->
bezt.
h1);
97 bezt->
h1 = bezt->
h2 = std::max(reference_point->
bezt.
h2, reference_point->
bezt.
h1);
100 reference_parent_point = reference_point;
102 else if (reference_adjacent) {
116 if (prev_point && next_point) {
123 close_point = prev_point ? prev_point : next_point;
129 handle_type = prev_point->
bezt.
h2;
132 handle_type = std::max(next_point->
bezt.
h2, handle_type);
134 bezt->
h1 = bezt->
h2 = handle_type;
137 reference_parent_point = close_point;
147 if (reference_parent_point) {
151 float parent_matrix[3][3];
198 for (
int i = 0; i < cur_spline->
tot_point; i++) {
202 if (!
ELEM(*spline,
nullptr, cur_spline)) {
211 *spline = cur_spline;
217 cur_spline = cur_spline->
next;
231 new_point_array = MEM_new_array<MaskSplinePoint>(spline->
tot_point + 1,
"add mask vert points");
234 memcpy(new_point_array + point_index + 2,
235 spline->
points + point_index + 1,
238 MEM_delete(spline->
points);
239 spline->
points = new_point_array;
248 const float threshold = 12;
267 const float ctime = scene->
r.
cfra;
270 int point_index = point - spline->
points;
276 new_point = &spline->
points[point_index + 1];
304 const float ctime = scene->
r.
cfra;
312 float tangent_point[2];
314 bool do_cyclic_correct =
false;
324 point_index = (point - spline->
points);
329 (point_index > 0 && point_index != spline->
tot_point - 1))
334 if (
dot_v2v2(tangent_point, tangent_co) < 0.0f) {
356 if (point_index < 0) {
359 do_cyclic_correct =
true;
367 printf(
"%d\n", point_index);
372 if (do_cyclic_correct) {
373 ref_point = &spline->
points[point_index + 1];
374 new_point = &spline->
points[point_index];
375 *ref_point = *new_point;
379 ref_point = &spline->
points[point_index];
380 new_point = &spline->
points[point_index + 1];
388 point_index = ((int(new_point - spline->
points) + 0) % spline->
tot_point);
404 const float ctime = scene->
r.
cfra;
412 mask->masklay_act =
mask->masklay_tot - 1;
420 new_point = spline->
points;
427 int point_index = ((int(new_point - spline->
points) + 0) % spline->
tot_point);
443 const float point_normalized[2],
444 float point_pixel[2])
449 float scalex, scaley;
452 point_pixel[0] = point_normalized[0] * scalex;
453 point_pixel[1] = point_normalized[1] * scaley;
463 const float tolerance_in_pixels_squared = 4 * 4;
475 float point_pixel[2];
479 if (dist_squared > tolerance_in_pixels_squared) {
501 const bool is_first_point_active = (active_point == first_point);
502 const bool is_last_point_active = (active_point == last_point);
503 if (is_last_point_active) {
506 if (is_first_point_active) {
524 if (
mask ==
nullptr) {
532 mask_layer =
nullptr;
545 C,
mask, spline, active_point, co);
547 return cyclic_result;
588 ot->
name =
"Add Vertex";
590 ot->
idname =
"MASK_OT_add_vertex";
608 "Location of vertex in normalized space",
625 const float threshold = 12;
652 if (weight_scalar != 0.0f) {
653 w =
w / weight_scalar;
687 ot->
name =
"Add Feather Vertex";
689 ot->
idname =
"MASK_OT_add_feather_vertex";
707 "Location of vertex in normalized space",
719 const int num_points,
722 const float location[2])
725 for (
int i = 0; i < num_points; i++) {
726 copy_v2_v2(bezier_points[i].vec[1], points[i]);
728 add_v2_v2(bezier_points[i].vec[1], location);
730 bezier_points[i].
h1 = handle_type;
731 bezier_points[i].
h2 = handle_type;
734 for (
int i = 0; i < num_points; i++) {
736 &bezier_points[(i - 1 + num_points) % num_points],
737 &bezier_points[(i + 1) % num_points],
742 return bezier_points;
747 const float (*points)[2],
763 frame_size[0] = width;
764 frame_size[1] = height;
767 location[0] /= width;
768 location[1] /= height;
772 location[0] -= 0.5f *
scale;
773 location[1] -= 0.5f *
scale;
775 bool added_mask =
false;
793 for (
int i = 0; i < num_points; i++) {
799 new_point->
bezt = bezier_points[i];
808 MEM_delete(bezier_points);
849 "Size of new primitive",
859 "Location of new primitive",
872 const float points[4][2] = {{0.0f, 0.5f}, {0.5f, 1.0f}, {1.0f, 0.5f}, {0.5f, 0.0f}};
883 ot->
name =
"Add Circle";
885 ot->
idname =
"MASK_OT_primitive_circle_add";
907 const float points[4][2] = {{0.0f, 0.0f}, {0.0f, 1.0f}, {1.0f, 1.0f}, {1.0f, 0.0f}};
918 ot->
name =
"Add Square";
920 ot->
idname =
"MASK_OT_primitive_square_add";
Read Blender memory allocation and freeing.
#define MEM_realloc_zeroed(vmemh, len)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
float3x3 scale(float3x3 mat, float2 scale)
void MASK_OT_primitive_square_add(wmOperatorType *ot)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void RNA_float_set_array(PointerRNA *ptr, const char *name, const float *values)
static wmOperatorStatus add_vertex_exec(bContext *C, wmOperator *op)
MINLINE int mod_i(int i, int n)
ScrArea * CTX_wm_area(const bContext *C)
static wmOperatorStatus add_vertex_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static wmOperatorStatus primitive_square_add_exec(bContext *C, wmOperator *op)
static wmOperatorStatus add_vertex_handle_cyclic(bContext *C, Mask *mask, MaskSpline *spline, MaskSplinePoint *active_point, float co[2])
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE void mul_v2_fl(float r[2], float f)
MINLINE void copy_v2_v2(float r[2], const float a[2])
void ED_mask_select_toggle_all(Mask *mask, int action)
void ED_mask_view_lock_state_store(const bContext *C, MaskViewLockState *state)
MaskLayer * BKE_mask_layer_new(Mask *mask, const char *name)
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)
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)
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 int max_ii(int a, int b)
void mul_m3_v2(const float m[3][3], float r[2])
void BKE_mask_calc_handle_adjacent_interp(MaskSpline *spline, MaskSplinePoint *point, float u)
void ED_mask_cursor_location_get(ScrArea *area, float cursor[2])
void BKE_nurb_handle_calc(BezTriple *bezt, BezTriple *prev, BezTriple *next, bool is_fcurve, char smoothing)
static bool add_vertex_extrude(const bContext *C, Mask *mask, MaskLayer *mask_layer, const float co[2])
MaskLayer * ED_mask_layer_ensure(bContext *C, bool *r_added_mask)
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)
static wmOperatorStatus add_vertex_handle_cyclic_at_point(bContext *C, Mask *mask, MaskSpline *spline, MaskSplinePoint *active_point, MaskSplinePoint *other_point, float co[2])
void ED_mask_pixelspace_factor(ScrArea *area, ARegion *region, float *r_scalex, float *r_scaley)
static wmOperatorStatus add_feather_vertex_exec(bContext *C, wmOperator *op)
MINLINE void add_v2_v2(float r[2], const float a[2])
static void mask_spline_add_point_at_index(MaskSpline *spline, int point_index)
bool BKE_mask_point_selected(const MaskSplinePoint *p)
void DEG_id_tag_update(ID *id, unsigned int flags)
float BKE_mask_point_weight_scalar(MaskSpline *spline, MaskSplinePoint *point, float u)
static wmOperatorStatus primitive_add_invoke(bContext *C, wmOperator *op, const wmEvent *)
MaskSpline * BKE_mask_spline_add(MaskLayer *masklay)
void BKE_mask_point_deselect_handles(MaskSplinePoint *p)
void BKE_mask_coord_from_frame(float r_co[2], const float co[2], const float frame_size[2])
MaskLayer * BKE_mask_layer_active(Mask *mask)
void BKE_mask_calc_tangent_polyline(MaskSpline *spline, MaskSplinePoint *point, float t[2])
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
void BKE_mask_point_select_set(MaskSplinePoint *point, bool do_select)
void ED_mask_get_size(ScrArea *area, int *r_width, int *r_height)
Mask * CTX_data_edit_mask(const bContext *C)
void ED_mask_select_flush_all(Mask *mask)
void ED_mask_view_lock_state_restore_no_jump(const bContext *C, const MaskViewLockState *state)
MINLINE float dot_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT
bool ED_maskedit_mask_poll(bContext *C)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void print_v2(const char *str, const float v[2])
static bool add_vertex_subdivide(const bContext *C, Mask *mask, const float co[2])
bool invert_m3(float mat[3][3])
float BKE_mask_point_weight(MaskSpline *spline, MaskSplinePoint *point, float u)
static wmOperatorStatus primitive_circle_add_exec(bContext *C, wmOperator *op)
int BKE_mask_layer_shape_spline_to_index(MaskLayer *masklay, MaskSpline *spline)
static void mask_point_make_pixel_space(bContext *C, const float point_normalized[2], float point_pixel[2])
void BKE_mask_parent_init(MaskParent *parent)
bool ED_maskedit_visible_splines_poll(bContext *C)
static void define_primitive_add_properties(wmOperatorType *ot)
static wmOperatorStatus add_feather_vertex_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static void finSelectedSplinePoint(MaskLayer *mask_layer, MaskSpline **spline, MaskSplinePoint **point, bool check_active)
Scene * CTX_data_scene(const bContext *C)
void MASK_OT_add_vertex(wmOperatorType *ot)
void BKE_mask_point_add_uw(MaskSplinePoint *point, float u, float w)
void MASK_OT_add_feather_vertex(wmOperatorType *ot)
void MASK_OT_primitive_circle_add(wmOperatorType *ot)
MINLINE float len_squared_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT
static int create_primitive_from_points(bContext *C, wmOperator *op, const float(*points)[2], int num_points, eBezTriple_Handle handle_type)
void ED_mask_mouse_pos(ScrArea *area, ARegion *region, const int mval[2], float r_co[2])
static BezTriple * points_to_bezier(const float(*points)[2], const int num_points, const eBezTriple_Handle handle_type, const float scale, const float location[2])
Mask * ED_mask_new(bContext *C, const char *name)
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)
ARegion * CTX_wm_region(const bContext *C)
float RNA_float_get(PointerRNA *ptr, const char *name)
void BKE_mask_layer_shape_changed_add(MaskLayer *masklay, int index, bool do_init, bool do_init_interpolate)
void BKE_mask_point_select_handles(MaskSplinePoint *p)
void RNA_float_get_array(PointerRNA *ptr, const char *name, float *values)
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_calc_handle_point_auto(MaskSpline *spline, MaskSplinePoint *point, bool do_recalc_length)
Resets auto handles even for non-auto bezier points.
static bool add_vertex_new(const bContext *C, Mask *mask, MaskLayer *mask_layer, const float co[2])
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)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
struct MaskSplinePoint * act_point
struct MaskSpline * act_spline
ListBaseT< MaskLayerShape > splines_shapes
MaskLayerVisibility visibility_flag
ListBaseT< MaskSpline > splines
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
struct wmOperatorType * type