36#include "curve_fit_nd.h"
41#define COORD_FITTING_INFLUENCE 20.0f
52 gpc_pt->
flag &= ~GP_CURVE_POINT_SELECT;
55 gpc->
flag &= ~GP_CURVE_SELECT;
65 const float stroke_radius)
76 float offset = (pt->
pressure * stroke_radius) * 2.0f;
79 for (
int j = 0; j < 3; j++) {
82 tmp_vec[0] +=
float(j - 1) * offset;
103 float length =
len_v3v3(&first_pt->
x, &last_pt->
x);
104 float offset = length / 3;
108 for (
int i = 0; i < 2; i++) {
114 for (
int j = 0; j < 3; j++) {
138 const float error_threshold,
139 const float corner_angle,
140 const float stroke_radius)
147 float *points =
static_cast<float *
>(
152 for (
int i = 0; i < gps->
totpoints; i++) {
159 points[row + 3] = pt->
pressure / diag_length;
162 points[row + 4] = pt->
strength / diag_length;
166 uint calc_flag = CURVE_FIT_CALC_HIGH_QUALIY;
168 calc_flag |= CURVE_FIT_CALC_CYCLIC;
171 float *r_cubic_array =
nullptr;
172 uint r_cubic_array_len = 0;
173 uint *r_cubic_orig_index =
nullptr;
174 uint *r_corners_index_array =
nullptr;
175 uint r_corners_index_len = 0;
176 int r = curve_fit_cubic_to_points_refit_fl(points,
187 &r_corners_index_array,
188 &r_corners_index_len);
190 if (r != 0 || r_cubic_array_len < 1) {
198 for (
int i = 0; i < r_cubic_array_len; i++) {
201 float *curve_point = &r_cubic_array[i * curve_point_size];
203 for (
int j = 0; j < 3; j++) {
204 float *bez = &curve_point[j *
POINT_DIM];
208 float *ctrl_point = &curve_point[1 *
POINT_DIM];
209 cpt->
pressure = ctrl_point[3] * diag_length;
210 cpt->
strength = ctrl_point[4] * diag_length;
220 if (r_corners_index_len > 0 && r_corners_index_array !=
nullptr) {
221 int start = 0, end = r_corners_index_len;
222 if ((r_corners_index_len > 1) && (calc_flag & CURVE_FIT_CALC_CYCLIC) == 0) {
224 end = r_corners_index_len - 1;
226 for (
int i = start; i < end; i++) {
238 if (r_corners_index_array) {
239 free(r_corners_index_array);
241 if (r_cubic_orig_index) {
242 free(r_cubic_orig_index);
264 gpc_pt->
flag &= ~GP_CURVE_POINT_SELECT;
270 gpc->
flag &= ~GP_CURVE_SELECT;
277 if (gps ==
nullptr || gps->
editcurve ==
nullptr) {
281 bool changed =
false;
376 for (
int axis = 0; axis < 3; axis++) {
377 float p0, p1, p2, p3, m0, m1, q0,
q1,
b;
378 p0 = bezt_start->
vec[1][axis];
379 p1 = bezt_start->
vec[2][axis];
380 p2 = bezt_end->
vec[0][axis];
381 p3 = bezt_end->
vec[1][axis];
384 q0 = (p0 + 2 * p1 + p2) / 4;
385 b = (p0 + 3 * p1 + 3 * p2 + p3) / 8;
386 q1 = (p1 + 2 * p2 + p3) / 4;
389 bezt_new->
vec[0][axis] = q0;
390 bezt_new->
vec[2][axis] =
q1;
391 bezt_new->
vec[1][axis] =
b;
393 bezt_start->
vec[2][axis] = m0;
394 bezt_end->
vec[0][axis] = m1;
411 for (
int s = 0; s < cuts; s++) {
414 if (new_num_curve_points == 0) {
417 int new_tot_curve_points = old_tot_curve_points + new_num_curve_points;
422 bool prev_subdivided =
false;
424 for (
int i = 0; i < old_tot_curve_points - 1; i++, j++) {
440 prev_subdivided =
true;
443 else if (!prev_subdivided) {
445 prev_subdivided =
false;
448 prev_subdivided =
false;
468 else if (!prev_subdivided) {
void BKE_nurb_handle_calc(BezTriple *bezt, BezTriple *prev, BezTriple *next, bool is_fcurve, char smoothing)
struct bGPDcurve * BKE_gpencil_stroke_editcurve_new(int tot_curve_points)
General operations, lookup, etc. for materials.
void BLI_kdtree_nd_ free(KDTree *tree)
MINLINE float interpf(float target, float origin, float t)
MINLINE void copy_v4_v4(float r[4], const float a[4])
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void mul_v4_v4fl(float r[4], const float a[4], float f)
MINLINE void copy_v3_v3(float r[3], const float a[3])
void interp_v4_v4v4(float r[4], const float a[4], const float b[4], float t)
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void madd_v3_v3v3fl(float r[3], const float a[3], const float b[3], float f)
MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f)
MINLINE float normalize_v3_length(float n[3], float unit_length)
Object groups, one object can be in many groups at once.
#define BEZT_SEL_ALL(bezt)
#define BEZT_DESEL_ALL(bezt)
@ GP_STROKE_NEEDS_CURVE_UPDATE
Read Guarded memory(de)allocation.
local_group_size(16, 16) .push_constant(Type b
static bool is_cyclic(const Nurb *nu)
draw_view in_light_buf[] float
void BKE_gpencil_editcurve_stroke_sync_selection(bGPdata *, bGPDstroke *gps, bGPDcurve *gpc)
void BKE_gpencil_editcurve_subdivide(bGPDstroke *gps, const int cuts)
static void gpencil_editcurve_subdivide_curve_segment(bGPDcurve_point *cpt_start, bGPDcurve_point *cpt_end, bGPDcurve_point *cpt_new)
static bGPDcurve * gpencil_stroke_editcurve_generate_edgecases(bGPDstroke *gps, const float stroke_radius)
#define COORD_FITTING_INFLUENCE
static void gpencil_editstroke_deselect_all(bGPDcurve *gpc)
bGPDcurve * BKE_gpencil_stroke_editcurve_generate(bGPDstroke *gps, const float error_threshold, const float corner_angle, const float stroke_radius)
void BKE_gpencil_editcurve_recalculate_handles(bGPDstroke *gps)
static int gpencil_editcurve_subdivide_count(bGPDcurve *gpc, bool is_cyclic)
void MEM_freeN(void *vmemh)
void *(* MEM_callocN)(size_t len, const char *str)
bGPDcurve_point * curve_points
struct bGPDcurve * editcurve