fix [#25684] Grease pencil strokes with "Surface" option attach erratically to curves.

added new functions
- view_autodist_depth_segment()
- plot_line_v2v2i(), which takes a callback and plots x/y points.
This commit is contained in:
2011-02-02 03:32:58 +00:00
parent b04bccd44e
commit 691f2abad1
5 changed files with 122 additions and 9 deletions

View File

@@ -120,6 +120,8 @@ int isect_aabb_aabb_v3(float min1[3], float max1[3], float min2[3], float max2[3
int clip_line_plane(float clipco[3], float plane[4], float co[3]);
void plot_line_v2v2i(int p1[2], int p2[2], int (*callback)(int, int, void *), void *userData);
/****************************** Interpolation ********************************/
/* tri or quad, d can be NULL */

View File

@@ -1358,6 +1358,71 @@ int clip_line_plane(float p1[3], float p2[3], float plane[4])
}
}
void plot_line_v2v2i(int p1[2], int p2[2], int (*callback)(int, int, void *), void *userData)
{
int x1= p1[0];
int y1= p1[1];
int x2= p2[0];
int y2= p2[1];
signed char ix;
signed char iy;
// if x1 == x2 or y1 == y2, then it does not matter what we set here
int delta_x = (x2 > x1?(ix = 1, x2 - x1):(ix = -1, x1 - x2)) << 1;
int delta_y = (y2 > y1?(iy = 1, y2 - y1):(iy = -1, y1 - y2)) << 1;
if(callback(x1, y1, userData) == 0) {
return;
}
if (delta_x >= delta_y) {
// error may go below zero
int error = delta_y - (delta_x >> 1);
while (x1 != x2) {
if (error >= 0) {
if (error || (ix > 0)) {
y1 += iy;
error -= delta_x;
}
// else do nothing
}
// else do nothing
x1 += ix;
error += delta_y;
if(callback(x1, y1, userData) == 0) {
return ;
}
}
}
else {
// error may go below zero
int error = delta_x - (delta_y >> 1);
while (y1 != y2) {
if (error >= 0) {
if (error || (iy > 0)) {
x1 += ix;
error -= delta_y;
}
// else do nothing
}
// else do nothing
y1 += iy;
error += delta_x;
if(callback(x1, y1, userData) == 0) {
return;
}
}
}
}
/****************************** Interpolation ********************************/
static float tri_signed_area(float *v1, float *v2, float *v3, int i, int j)
@@ -2566,4 +2631,3 @@ float form_factor_hemi_poly(float p[3], float n[3], float v1[3], float v2[3], fl
return contrib;
}

View File

@@ -547,18 +547,25 @@ static void gp_stroke_newfrombuffer (tGPsdata *p)
/* get an array of depths, far depths are blended */
if (gpencil_project_check(p)) {
short mval[2];
short mval[2], mval_prev[2]= {0};
int interp_depth = 0;
int found_depth = 0;
depth_arr= MEM_mallocN(sizeof(float) * gpd->sbuffer_size, "depth_points");
for (i=0, ptc=gpd->sbuffer; i < gpd->sbuffer_size; i++, ptc++, pt++) {
mval[0]= ptc->x; mval[1]= ptc->y;
if (view_autodist_depth(p->ar, mval, depth_margin, depth_arr+i) == 0)
if ((view_autodist_depth(p->ar, mval, depth_margin, depth_arr+i) == 0) &&
(i && (view_autodist_depth_segment(p->ar, mval, mval_prev, depth_margin + 1, depth_arr+i) == 0))
) {
interp_depth= TRUE;
else
}
else {
found_depth= TRUE;
}
VECCOPY2D(mval_prev, mval);
}
if (found_depth == FALSE) {

View File

@@ -136,8 +136,9 @@ int view_autodist(struct Scene *scene, struct ARegion *ar, struct View3D *v3d, s
/* only draw so view_autodist_simple can be called many times after */
int view_autodist_init(struct Scene *scene, struct ARegion *ar, struct View3D *v3d, int mode);
int view_autodist_simple(struct ARegion *ar, short *mval, float mouse_worldloc[3], int margin, float *force_depth);
int view_autodist_depth(struct ARegion *ar, short *mval, int margin, float *depth);
int view_autodist_simple(struct ARegion *ar, short mval[2], float mouse_worldloc[3], int margin, float *force_depth);
int view_autodist_depth(struct ARegion *ar, short mval[2], int margin, float *depth);
int view_autodist_depth_segment(struct ARegion *ar, short mval_sta[2], short mval_end[2], int margin, float *depth);
/* select */
#define MAXPICKBUF 10000

View File

@@ -2622,7 +2622,7 @@ void VIEW3D_OT_enable_manipulator(wmOperatorType *ot)
/* ************************* below the line! *********************** */
static float view_autodist_depth_margin(ARegion *ar, short *mval, int margin)
static float view_autodist_depth_margin(ARegion *ar, short mval[2], int margin)
{
ViewDepths depth_temp= {0};
rcti rect;
@@ -2721,12 +2721,51 @@ int view_autodist_simple(ARegion *ar, short *mval, float mouse_worldloc[3], int
return 1;
}
int view_autodist_depth(struct ARegion *ar, short *mval, int margin, float *depth)
int view_autodist_depth(struct ARegion *ar, short mval[2], int margin, float *depth)
{
*depth= view_autodist_depth_margin(ar, mval, margin);
return (*depth==FLT_MAX) ? 0:1;
}
static int depth_segment_cb(int x, int y, void *userData)
{
struct { struct ARegion *ar; int margin; float depth; } *data = userData;
short mval[2];
float depth;
mval[0]= (short)x;
mval[1]= (short)y;
depth= view_autodist_depth_margin(data->ar, mval, data->margin);
if(depth != FLT_MAX) {
data->depth= depth;
return 0;
}
else {
return 1;
}
}
int view_autodist_depth_segment(struct ARegion *ar, short mval_sta[2], short mval_end[2], int margin, float *depth)
{
struct { struct ARegion *ar; int margin; float depth; } data = {0};
int p1[2];
int p2[2];
data.ar= ar;
data.margin= margin;
data.depth= FLT_MAX;
VECCOPY2D(p1, mval_sta);
VECCOPY2D(p2, mval_end);
plot_line_v2v2i(p1, p2, depth_segment_cb, &data);
*depth= data.depth;
return (*depth==FLT_MAX) ? 0:1;
}
/* ********************* NDOF ************************ */