Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2011-02-02 06:32:58 +0300
committerCampbell Barton <ideasman42@gmail.com>2011-02-02 06:32:58 +0300
commit691f2abad1f2d22fd6dec7430d6266366ecc1b21 (patch)
tree58d821c8aad2d4463e9d2d8a2124b65f89522bb6
parentb04bccd44e45dcb759de55c08d2913400853ee82 (diff)
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.
-rw-r--r--source/blender/blenlib/BLI_math_geom.h2
-rw-r--r--source/blender/blenlib/intern/math_geom.c66
-rw-r--r--source/blender/editors/gpencil/gpencil_paint.c15
-rw-r--r--source/blender/editors/include/ED_view3d.h5
-rw-r--r--source/blender/editors/space_view3d/view3d_edit.c43
5 files changed, 122 insertions, 9 deletions
diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h
index 701786e4b72..8f939e5dc61 100644
--- a/source/blender/blenlib/BLI_math_geom.h
+++ b/source/blender/blenlib/BLI_math_geom.h
@@ -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 */
diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c
index 15f696e073c..d7a71f8567c 100644
--- a/source/blender/blenlib/intern/math_geom.c
+++ b/source/blender/blenlib/intern/math_geom.c
@@ -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;
}
-
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index baa6f7d6a25..0ebbe223c3f 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -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) {
diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h
index d6fc0797449..4afe2ff10a2 100644
--- a/source/blender/editors/include/ED_view3d.h
+++ b/source/blender/editors/include/ED_view3d.h
@@ -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
diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c
index bbb52826de6..6df0793f2fe 100644
--- a/source/blender/editors/space_view3d/view3d_edit.c
+++ b/source/blender/editors/space_view3d/view3d_edit.c
@@ -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 ************************ */