34 float max_segment = 0.01f;
37 if (width != 0 && height != 0) {
41 for (i = 0; i < spline->tot_point; i++) {
47 bezt_curr = &point->bezt;
50 if (bezt_next ==
nullptr) {
59 cur_resol =
len / max_segment;
61 resol = std::max(resol, cur_resol);
73 const float max_segment = 0.005;
75 float max_jump = 0.0f;
82 for (
int i = 0; i < spline->tot_point; i++) {
88 for (
int j = 0; j < point->tot_uw; j++) {
89 const float w_diff = (point->uw[j].w - prev_w);
90 const float u_diff = (point->uw[j].u - prev_u);
94 if (u_diff > FLT_EPSILON) {
100 prev_u = point->uw[j].u;
101 prev_w = point->uw[j].w;
105 resol += max_jump / max_segment;
113 return spline->tot_point * resol;
116 return ((spline->tot_point - 1) * resol) + 1;
121 uint *r_tot_diff_point))[2]
126 float(*diff_points)[2], (*fp)[2];
130 if (spline->tot_point <= 1) {
132 *r_tot_diff_point = 0;
137 *r_tot_diff_point = tot;
138 diff_points = fp = MEM_cnew_array<float[2]>(tot + 1,
"mask spline vets");
140 a = spline->tot_point - 1;
145 point_prev = points_array;
146 point_curr = point_prev + 1;
154 point_curr = points_array;
157 bezt_prev = &point_prev->
bezt;
158 bezt_curr = &point_curr->
bezt;
160 for (j = 0; j < 2; j++) {
162 bezt_prev->
vec[2][j],
163 bezt_curr->
vec[0][j],
164 bezt_curr->
vec[1][j],
176 point_prev = point_curr;
184 MaskSpline *spline,
int width,
int height,
uint *r_tot_diff_point))[2]
201 const int alloc_delta = 256;
205 bucket->
segments = MEM_cnew_array<int[2]>(alloc_delta,
"feather bucket segments");
222 int tot_feather_point,
227 const float *v1 = (
float *)feather_points[cur_a];
228 const float *
v2 = (
float *)feather_points[cur_b];
231 int check_a = bucket->
segments[i][0];
232 int check_b = bucket->
segments[i][1];
234 const float *v3 = (
float *)feather_points[check_a];
235 const float *v4 = (
float *)feather_points[check_b];
237 if (check_a >= cur_a - 1 || cur_b == check_a) {
244 float min_a[2], max_a[2];
245 float min_b[2], max_b[2];
253 for (k = 0; k < tot_feather_point; k++) {
254 if (k >= check_b && k <= cur_a) {
262 if (max_a[0] - min_a[0] < max_b[0] - min_b[0] || max_a[1] - min_a[1] < max_b[1] - min_b[1]) {
263 for (k = check_b; k <= cur_a; k++) {
268 for (k = 0; k <= check_a; k++) {
273 for (k = cur_b; k < tot_feather_point; k++) {
284 const float bucket_scale[2],
285 const int buckets_per_side)
287 int x =
int((co[0] -
min[0]) * bucket_scale[0]);
288 int y =
int((co[1] -
min[1]) * bucket_scale[1]);
290 if (x == buckets_per_side) {
294 if (y == buckets_per_side) {
298 return y * buckets_per_side +
x;
302 int start_bucket_index,
303 int end_bucket_index,
304 int buckets_per_side,
308 int start_bucket_x = start_bucket_index % buckets_per_side;
309 int start_bucket_y = start_bucket_index / buckets_per_side;
311 int end_bucket_x = end_bucket_index % buckets_per_side;
312 int end_bucket_y = end_bucket_index / buckets_per_side;
314 int diagonal_bucket_a_index = start_bucket_y * buckets_per_side + end_bucket_x;
315 int diagonal_bucket_b_index = end_bucket_y * buckets_per_side + start_bucket_x;
317 *r_diagonal_bucket_a = &buckets[diagonal_bucket_a_index];
318 *r_diagonal_bucket_b = &buckets[diagonal_bucket_b_index];
322 float (*feather_points)[2],
323 const uint tot_feather_point)
325#define BUCKET_INDEX(co) feather_bucket_index_from_coord(co, min, bucket_scale, buckets_per_side)
327 int buckets_per_side, tot_bucket;
328 float bucket_size, bucket_scale[2];
332 float min[2], max[2];
333 float max_delta_x = -1.0f, max_delta_y = -1.0f, max_delta;
335 if (tot_feather_point < 4) {
346 for (
uint i = 0; i < tot_feather_point; i++) {
352 if (
next == tot_feather_point) {
361 delta =
fabsf(feather_points[i][0] - feather_points[
next][0]);
362 if (delta > max_delta_x) {
366 delta =
fabsf(feather_points[i][1] - feather_points[
next][1]);
367 if (delta > max_delta_y) {
373 if (max[0] -
min[0] < FLT_EPSILON) {
378 if (max[1] -
min[1] < FLT_EPSILON) {
388 max_delta_x /= max[0] -
min[0];
389 max_delta_y /= max[1] -
min[1];
391 max_delta = std::max(max_delta_x, max_delta_y);
393 buckets_per_side =
min_ii(512, 0.9f / max_delta);
395 if (buckets_per_side == 0) {
398 buckets_per_side = 1;
401 tot_bucket = buckets_per_side * buckets_per_side;
402 bucket_size = 1.0f / buckets_per_side;
405 bucket_scale[0] = 1.0f / ((max[0] -
min[0]) * bucket_size);
406 bucket_scale[1] = 1.0f / ((max[1] -
min[1]) * bucket_size);
409 buckets = MEM_cnew_array<FeatherEdgesBucket>(tot_bucket,
"feather buckets");
411 for (
int i = 0; i < tot_feather_point; i++) {
412 int start = i, end = i + 1;
413 int start_bucket_index, end_bucket_index;
415 if (end == tot_feather_point) {
424 start_bucket_index =
BUCKET_INDEX(feather_points[start]);
429 if (start_bucket_index != end_bucket_index) {
447 for (
int i = 0; i < tot_feather_point; i++) {
448 int cur_a = i, cur_b = i + 1;
449 int start_bucket_index, end_bucket_index;
453 if (cur_b == tot_feather_point) {
457 start_bucket_index =
BUCKET_INDEX(feather_points[cur_a]);
460 start_bucket = &buckets[start_bucket_index];
464 if (start_bucket_index != end_bucket_index) {
477 feather_points, tot_feather_point, diagonal_bucket_a, cur_a, cur_b);
479 feather_points, tot_feather_point, diagonal_bucket_b, cur_a, cur_b);
484 for (
int i = 0; i < tot_bucket; i++) {
485 if (buckets[i].segments) {
499 const bool do_feather_isect,
500 uint *r_tot_feather_point))[2]
504 float(*feather)[2], (*fp)[2];
510 feather = fp = MEM_cnew_array<float[2]>(tot + 1,
"mask spline feather diff points");
512 a = spline->tot_point - 1;
517 point_prev = points_array;
518 point_curr = point_prev + 1;
526 point_curr = points_array;
532 for (j = 0; j < resol; j++, fp++) {
533 float u =
float(j) / resol, weight;
546 float u = 1.0f, weight;
556 point_prev = point_curr;
560 *r_tot_feather_point = tot;
573 const bool do_feather_isect,
574 uint *r_tot_feather_point))[2]
579 float(*feather)[2], (*fp)[2];
583 if (spline->tot_point <= 1) {
585 *r_tot_feather_point = 0;
590 *r_tot_feather_point = tot;
591 feather = fp = MEM_cnew_array<float[2]>(tot + 1,
"mask spline vets");
593 a = spline->tot_point - 1;
598 point_prev = points_array;
599 point_curr = point_prev + 1;
604 float point_prev_n[2], point_curr_n[2], tvec[2];
605 float weight_prev, weight_curr;
606 float len_base, len_feather, len_scalar;
613 point_curr = points_array;
616 bezt_prev = &point_prev->
bezt;
617 bezt_curr = &point_curr->
bezt;
620 local_prevbezt = *bezt_prev;
621 local_bezt = *bezt_curr;
623 bezt_prev = &local_prevbezt;
624 bezt_curr = &local_bezt;
629 point_prev_n[0] = -tvec[1];
630 point_prev_n[1] = tvec[0];
634 point_curr_n[0] = -tvec[1];
635 point_curr_n[1] = tvec[0];
637 weight_prev = bezt_prev->
weight;
638 weight_curr = bezt_curr->
weight;
657 len_scalar = len_feather / len_base;
665 for (j = 0; j < 2; j++) {
667 bezt_prev->
vec[2][j],
668 bezt_curr->
vec[0][j],
669 bezt_curr->
vec[1][j],
677 for (j = 0; j < resol; j++, fp++) {
678 float u =
float(j) / resol;
679 float weight_uw, weight_scalar;
700 point_prev = point_curr;
714 const bool do_feather_isect,
715 uint *r_tot_feather_point))[2]
717 switch (spline->offset_mode) {
720 spline, resol, do_feather_isect, r_tot_feather_point);
724 spline, resol, do_feather_isect, r_tot_feather_point);
733 float(*feather)[2], (*fp)[2];
736 for (i = 0; i < spline->tot_point; i++) {
743 feather = fp = MEM_cnew_array<float[2]>(tot,
"mask spline feather points");
745 for (i = 0; i < spline->tot_point; i++) {
757 for (j = 0; j < point->tot_uw; j++) {
758 float u = point->uw[j].u;
770 *r_tot_feather_point = tot;
781 feather = fp = MEM_cnew_array<float>(2 * resol,
"mask point spline feather diff points");
783 for (
uint i = 0; i < resol; i++, fp += 2) {
784 float u =
float(i % resol) / resol, weight;
791 fp[0] = co[0] + n[0] * weight;
792 fp[1] = co[1] + n[1] * weight;
795 *r_tot_feather_point = resol;
806 float *diff_points, *fp;
817 *r_tot_diff_point = resol + 1;
818 diff_points = fp = MEM_cnew_array<float>(2 * (resol + 1),
"mask segment vets");
820 for (j = 0; j < 2; j++) {
823 bezt_next->
vec[0][j],
824 bezt_next->
vec[1][j],
837 float parent_matrix[3][3];
839 mul_m3_v2(parent_matrix, point->bezt.vec[0]);
840 mul_m3_v2(parent_matrix, point->bezt.vec[1]);
841 mul_m3_v2(parent_matrix, point->bezt.vec[2]);
851 masklay, ctime, &masklay_shape_a, &masklay_shape_b)))
855 printf(
"%s: exact %d %d (%d)\n",
859 masklay_shape_a->
frame);
863 else if (found == 2) {
864 float w = masklay_shape_b->
frame - masklay_shape_a->
frame;
866 printf(
"%s: tween %d %d (%d %d)\n",
870 masklay_shape_a->
frame,
871 masklay_shape_b->
frame);
874 masklay, masklay_shape_a, masklay_shape_b, (ctime - masklay_shape_a->
frame) /
w);
887 bool need_handle_recalc =
false;
889 for (
int i = 0; i < spline->tot_point; i++) {
893 *point_deform = *
point;
898 need_handle_recalc =
true;
904 if (need_handle_recalc) {
905 for (
int i = 0; i < spline->tot_point; i++) {
934 if (is_depsgraph_active) {
937 *masklay_eval =
static_cast<MaskLayer *
>(mask->masklayers.first);
938 masklay_orig !=
nullptr;
939 masklay_orig = masklay_orig->
next, masklay_eval = masklay_eval->
next)
942 *spline_eval =
static_cast<MaskSpline *
>(masklay_eval->splines.first);
943 spline_orig !=
nullptr;
944 spline_orig = spline_orig->
next, spline_eval = spline_eval->
next)
946 for (
int i = 0; i < spline_eval->tot_point; i++) {
949 point_orig->
bezt = point_eval->
bezt;
void BKE_curve_forward_diff_bezier(float q0, float q1, float q2, float q3, float *p, int it, int stride)
void BKE_mask_layer_shape_to_mask(struct MaskLayer *masklay, struct MaskLayerShape *masklay_shape)
struct MaskSplinePoint * BKE_mask_spline_point_array_from_point(struct MaskSpline *spline, const struct MaskSplinePoint *point_ref)
void BKE_mask_layer_shape_to_mask_interp(struct MaskLayer *masklay, struct MaskLayerShape *masklay_shape_a, struct MaskLayerShape *masklay_shape_b, float fac)
void BKE_mask_calc_handle_point(struct MaskSpline *spline, struct MaskSplinePoint *point)
void BKE_mask_point_free(struct MaskSplinePoint *point)
int BKE_mask_layer_shape_find_frame_range(struct MaskLayer *masklay, float frame, struct MaskLayerShape **r_masklay_shape_a, struct MaskLayerShape **r_masklay_shape_b)
struct BezTriple * BKE_mask_spline_point_next_bezt(struct MaskSpline *spline, struct MaskSplinePoint *points_array, struct MaskSplinePoint *point)
void BKE_mask_spline_ensure_deform(struct MaskSpline *spline)
float BKE_mask_point_weight(struct MaskSpline *spline, struct MaskSplinePoint *point, float u)
float BKE_mask_point_weight_scalar(struct MaskSpline *spline, struct MaskSplinePoint *point, float u)
void BKE_mask_layer_calc_handles(struct MaskLayer *masklay)
void BKE_mask_point_parent_matrix_get(struct MaskSplinePoint *point, float ctime, float parent_matrix[3][3])
void BKE_mask_point_normal(struct MaskSpline *spline, struct MaskSplinePoint *point, float u, float n[2])
void BKE_mask_point_segment_co(struct MaskSpline *spline, struct MaskSplinePoint *point, float u, float co[2])
struct MaskSplinePoint * BKE_mask_spline_point_array(struct MaskSpline *spline)
#define LISTBASE_FOREACH(type, var, list)
int BLI_listbase_count(const struct ListBase *listbase) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
MINLINE float max_ff(float a, float b)
MINLINE int min_ii(int a, int b)
MINLINE int max_ii(int a, int b)
bool isect_seg_seg_v2_simple(const float v1[2], const float v2[2], const float v3[2], const float v4[2])
int isect_seg_seg_v2_point(const float v0[2], const float v1[2], const float v2[2], const float v3[2], float r_vi[2])
void mul_m3_v2(const float m[3][3], float r[2])
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void madd_v2_v2v2fl(float r[2], const float a[2], const float b[2], float f)
MINLINE float len_v2v2(const float v1[2], const float v2[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])
void dist_ensure_v2_v2fl(float v1[2], const float v2[2], float dist)
void minmax_v2v2_v2(float min[2], float max[2], const float vec[2])
MINLINE void add_v2_v2(float r[2], const float a[2])
MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2])
MINLINE float normalize_v2(float n[2])
#define INIT_MINMAX2(min, max)
bool DEG_is_active(const Depsgraph *depsgraph)
void DEG_debug_print_eval(Depsgraph *depsgraph, const char *function_name, const char *object_name, const void *object_address)
float DEG_get_ctime(const Depsgraph *graph)
ID * DEG_get_original_id(ID *id)
@ MASK_SPLINE_OFFSET_SMOOTH
@ MASK_SPLINE_OFFSET_EVEN
@ MASK_SPLINE_NOINTERSECT
Object is a sort of wrapper for general info.
Read Guarded memory(de)allocation.
#define MEM_reallocN(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
ATTR_WARN_UNUSED_RESULT const BMVert * v2
void jump(const btVector3 &v=btVector3(0, 0, 0))
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
local_group_size(16, 16) .push_constant(Type b
const Depsgraph * depsgraph
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 *(* MEM_dupallocN)(const void *vmemh)
static void feather_bucket_get_diagonal(FeatherEdgesBucket *buckets, int start_bucket_index, int end_bucket_index, int buckets_per_side, FeatherEdgesBucket **r_diagonal_bucket_a, FeatherEdgesBucket **r_diagonal_bucket_b)
float(* BKE_mask_spline_feather_points(MaskSpline *spline, int *r_tot_feather_point))[2]
int BKE_mask_spline_resolution(MaskSpline *spline, int width, int height)
void BKE_mask_layer_evaluate_animation(MaskLayer *masklay, const float ctime)
static float(* mask_spline_feather_differentiated_points_with_resolution__even(MaskSpline *spline, const uint resol, const bool do_feather_isect, uint *r_tot_feather_point))[2]
static void mask_evaluate_apply_point_parent(MaskSplinePoint *point, float ctime)
int BKE_mask_spline_differentiate_calc_total(const MaskSpline *spline, const uint resol)
void BKE_mask_spline_feather_collapse_inner_loops(MaskSpline *spline, float(*feather_points)[2], const uint tot_feather_point)
void BKE_mask_eval_animation(Depsgraph *depsgraph, Mask *mask)
float(* BKE_mask_spline_feather_differentiated_points_with_resolution(MaskSpline *spline, const uint resol, const bool do_feather_isect, uint *r_tot_feather_point))[2]
float(* BKE_mask_spline_differentiate(MaskSpline *spline, int width, int height, uint *r_tot_diff_point))[2]
static void feather_bucket_check_intersect(float(*feather_points)[2], int tot_feather_point, FeatherEdgesBucket *bucket, int cur_a, int cur_b)
void BKE_mask_layer_evaluate_deform(MaskLayer *masklay, const float ctime)
float(* BKE_mask_spline_differentiate_with_resolution(MaskSpline *spline, const uint resol, uint *r_tot_diff_point))[2]
static float(* mask_spline_feather_differentiated_points_with_resolution__double(MaskSpline *spline, const uint resol, const bool do_feather_isect, uint *r_tot_feather_point))[2]
uint BKE_mask_spline_feather_resolution(MaskSpline *spline, int width, int height)
void BKE_mask_eval_update(Depsgraph *depsgraph, Mask *mask)
static void feather_bucket_add_edge(FeatherEdgesBucket *bucket, int start, int end)
static int feather_bucket_index_from_coord(const float co[2], const float min[2], const float bucket_scale[2], const int buckets_per_side)
float * BKE_mask_point_segment_diff(MaskSpline *spline, MaskSplinePoint *point, int width, int height, uint *r_tot_diff_point)
float * BKE_mask_point_segment_feather_diff(MaskSpline *spline, MaskSplinePoint *point, int width, int height, uint *r_tot_feather_point)