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;
69 for (
int i = 0; i < spline->tot_point - 1; i++) {
73 if (point_index == -1 || point_index >= spline->tot_point) {
75 if (point_index == -1) {
76 point_index = spline->tot_point - 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) {
101 if (spline->tot_point != 1) {
104 const int index =
int(new_point - spline->points);
106 prev_point = &spline->points[
mod_i(index - 1, spline->tot_point)];
107 next_point = &spline->points[
mod_i(index + 1, spline->tot_point)];
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;
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];
159 if (spline->tot_point != 1) {
196 for (
int i = 0; i < cur_spline->
tot_point; i++) {
200 if (!
ELEM(*spline,
nullptr, cur_spline)) {
209 *spline = cur_spline;
215 cur_spline = cur_spline->
next;
229 new_point_array = MEM_cnew_array<MaskSplinePoint>(spline->tot_point + 1,
"add mask vert points");
231 memcpy(new_point_array, spline->points,
sizeof(
MaskSplinePoint) * (point_index + 1));
232 memcpy(new_point_array + point_index + 2,
233 spline->points + point_index + 1,
237 spline->points = new_point_array;
246 const float threshold = 12;
265 const float ctime = scene->r.cfra;
268 int point_index = point - spline->points;
274 new_point = &spline->points[point_index + 1];
302 const float ctime = scene->r.cfra;
310 float tangent_point[2];
312 bool do_cyclic_correct =
false;
322 point_index = (point - spline->points);
327 (point_index > 0 && point_index != spline->tot_point - 1))
332 if (
dot_v2v2(tangent_point, tangent_co) < 0.0f) {
342 else if (((spline->flag &
MASK_SPLINE_CYCLIC) == 0) && (point_index == spline->tot_point - 1)) {
354 if (point_index < 0) {
355 point_index += spline->tot_point;
357 do_cyclic_correct =
true;
365 printf(
"%d\n", point_index);
370 if (do_cyclic_correct) {
371 ref_point = &spline->points[point_index + 1];
372 new_point = &spline->points[point_index];
373 *ref_point = *new_point;
374 memset(new_point, 0,
sizeof(*new_point));
377 ref_point = &spline->points[point_index];
378 new_point = &spline->points[point_index + 1];
386 point_index = ((
int(new_point - spline->points) + 0) % spline->tot_point);
402 const float ctime = scene->r.cfra;
410 mask->masklay_act = mask->masklay_tot - 1;
418 new_point = spline->points;
425 int point_index = ((
int(new_point - spline->points) + 0) % spline->tot_point);
441 const float point_normalized[2],
442 float point_pixel[2])
447 float scalex, scaley;
450 point_pixel[0] = point_normalized[0] * scalex;
451 point_pixel[1] = point_normalized[1] * scaley;
461 const float tolerance_in_pixels_squared = 4 * 4;
473 float point_pixel[2];
477 if (dist_squared > tolerance_in_pixels_squared) {
499 const bool is_first_point_active = (active_point == first_point);
500 const bool is_last_point_active = (active_point == last_point);
501 if (is_last_point_active) {
504 if (is_first_point_active) {
522 if (mask ==
nullptr) {
530 mask_layer =
nullptr;
544 return cyclic_result;
605 "Location of vertex in normalized space",
622 const float threshold = 12;
649 if (weight_scalar != 0.0f) {
650 w =
w / weight_scalar;
682 ot->
name =
"Add Feather Vertex";
684 ot->
idname =
"MASK_OT_add_feather_vertex";
702 "Location of vertex in normalized space",
714 const int num_points,
715 const char handle_type,
717 const float location[2])
719 BezTriple *bezier_points = MEM_cnew_array<BezTriple>(num_points, __func__);
720 for (
int i = 0; i < num_points; i++) {
721 copy_v2_v2(bezier_points[i].vec[1], points[i]);
722 mul_v2_fl(bezier_points[i].vec[1], scale);
723 add_v2_v2(bezier_points[i].vec[1], location);
725 bezier_points[i].
h1 = handle_type;
726 bezier_points[i].
h2 = handle_type;
729 for (
int i = 0; i < num_points; i++) {
731 &bezier_points[(i - 1 + num_points) % num_points],
732 &bezier_points[(i + 1) % num_points],
737 return bezier_points;
741 bContext *C,
wmOperator *op,
const float (*points)[2],
int num_points,
char handle_type)
755 frame_size[0] = width;
756 frame_size[1] = height;
759 location[0] /= width;
760 location[1] /= height;
764 location[0] -= 0.5f * scale;
765 location[1] -= 0.5f * scale;
767 bool added_mask =
false;
785 for (
int i = 0; i < num_points; i++) {
791 new_point->
bezt = bezier_points[i];
842 "Location of new circle",
855 const float points[4][2] = {{0.0f, 0.5f}, {0.5f, 1.0f}, {1.0f, 0.5f}, {0.5f, 0.0f}};
868 ot->
idname =
"MASK_OT_primitive_circle_add";
890 const float points[4][2] = {{0.0f, 0.0f}, {0.0f, 1.0f}, {1.0f, 1.0f}, {1.0f, 0.0f}};
903 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)
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 Gabor Generate Gabor noise Gradient Generate interpolated color and intensity values based on the input vector Magic Generate a psychedelic color texture 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
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
draw_view in_light_buf[] float
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
void MEM_freeN(void *vmemh)
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 int add_vertex_exec(bContext *C, wmOperator *op)
static int primitive_circle_add_exec(bContext *C, wmOperator *op)
static int primitive_square_add_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])
static int add_feather_vertex_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static int add_feather_vertex_exec(bContext *C, wmOperator *op)
void MASK_OT_primitive_circle_add(wmOperatorType *ot)
static void define_primitive_add_properties(wmOperatorType *ot)
static int add_vertex_handle_cyclic(bContext *C, Mask *mask, MaskSpline *spline, MaskSplinePoint *active_point, float co[2])
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 int add_vertex_handle_cyclic_at_point(bContext *C, Mask *mask, MaskSpline *spline, MaskSplinePoint *active_point, MaskSplinePoint *other_point, float co[2])
static bool add_vertex_subdivide(const bContext *C, Mask *mask, const float co[2])
void MASK_OT_add_vertex(wmOperatorType *ot)
static int primitive_add_invoke(bContext *C, wmOperator *op, const wmEvent *)
static int add_vertex_invoke(bContext *C, wmOperator *op, const wmEvent *event)
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)
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
bool(* poll)(bContext *C) ATTR_WARN_UNUSED_RESULT
int(* invoke)(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
int(* exec)(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
struct wmOperatorType * type
void WM_event_add_notifier(const bContext *C, uint type, void *reference)