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:
-rw-r--r--source/blender/blenlib/BLI_math_geom.h2
-rw-r--r--source/blender/blenlib/intern/math_geom.c49
-rw-r--r--source/blender/blenlib/intern/pbvh.c5
-rw-r--r--source/blender/editors/sculpt_paint/sculpt.c8
-rw-r--r--source/blender/editors/space_view3d/view3d_view.c6
5 files changed, 67 insertions, 3 deletions
diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h
index 0bbe8fac976..f650a55d8ad 100644
--- a/source/blender/blenlib/BLI_math_geom.h
+++ b/source/blender/blenlib/BLI_math_geom.h
@@ -111,6 +111,8 @@ int isect_axial_line_tri_v3(int axis, float co1[3], float co2[3],
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]);
+
/****************************** 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 2b94227099c..a80f999cdbb 100644
--- a/source/blender/blenlib/intern/math_geom.c
+++ b/source/blender/blenlib/intern/math_geom.c
@@ -1246,6 +1246,55 @@ int isect_point_tri_prism_v3(float p[3], float v1[3], float v2[3], float v3[3])
return 1;
}
+int clip_line_plane(float p1[3], float p2[3], float plane[4])
+{
+ float dp[3], n[3], div, t, pc[3];
+
+ copy_v3_v3(n, plane);
+ sub_v3_v3v3(dp, p2, p1);
+ div= dot_v3v3(dp, n);
+
+ if(div == 0.0f) /* parallel */
+ return 1;
+
+ t= -(dot_v3v3(p1, n) + plane[3])/div;
+
+ if(div > 0.0f) {
+ /* behind plane, completely clipped */
+ if(t >= 1.0f) {
+ zero_v3(p1);
+ zero_v3(p2);
+ return 0;
+ }
+
+ /* intersect plane */
+ if(t > 0.0f) {
+ madd_v3_v3v3fl(pc, p1, dp, t);
+ copy_v3_v3(p1, pc);
+ return 1;
+ }
+
+ return 1;
+ }
+ else {
+ /* behind plane, completely clipped */
+ if(t <= 0.0f) {
+ zero_v3(p1);
+ zero_v3(p2);
+ return 0;
+ }
+
+ /* intersect plane */
+ if(t < 1.0f) {
+ madd_v3_v3v3fl(pc, p1, dp, t);
+ copy_v3_v3(p2, pc);
+ return 1;
+ }
+
+ return 1;
+ }
+}
+
/****************************** Interpolation ********************************/
static float tri_signed_area(float *v1, float *v2, float *v3, int i, int j)
diff --git a/source/blender/blenlib/intern/pbvh.c b/source/blender/blenlib/intern/pbvh.c
index 6f33fab2571..c1bdbf32fac 100644
--- a/source/blender/blenlib/intern/pbvh.c
+++ b/source/blender/blenlib/intern/pbvh.c
@@ -694,6 +694,11 @@ void BLI_pbvh_search_gather(PBVH *bvh,
pbvh_iter_end(&iter);
+ if(tot == 0 && array) {
+ MEM_freeN(array);
+ array= NULL;
+ }
+
*r_array= array;
*r_tot= tot;
}
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index cfcd0d90e2c..11ce41c5ff8 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -1841,7 +1841,7 @@ int sculpt_stroke_get_location(bContext *C, struct PaintStroke *stroke, float ou
ViewContext *vc = paint_stroke_view_context(stroke);
SculptSession *ss= vc->obact->sculpt;
StrokeCache *cache= ss->cache;
- float ray_start[3], ray_normal[3];
+ float ray_start[3], ray_end[3], ray_normal[3], dist;
float obimat[4][4];
float mval[2] = {mouse[0] - vc->ar->winrct.xmin,
mouse[1] - vc->ar->winrct.ymin};
@@ -1849,7 +1849,9 @@ int sculpt_stroke_get_location(bContext *C, struct PaintStroke *stroke, float ou
sculpt_stroke_modifiers_check(C, ss);
- viewray(vc->ar, vc->v3d, mval, ray_start, ray_normal);
+ viewline(vc->ar, vc->v3d, mval, ray_start, ray_end);
+ sub_v3_v3v3(ray_normal, ray_end, ray_start);
+ dist= normalize_v3(ray_normal);
invert_m4_m4(obimat, ss->ob->obmat);
mul_m4_v3(obimat, ray_start);
@@ -1859,7 +1861,7 @@ int sculpt_stroke_get_location(bContext *C, struct PaintStroke *stroke, float ou
srd.ss = vc->obact->sculpt;
srd.ray_start = ray_start;
srd.ray_normal = ray_normal;
- srd.dist = FLT_MAX;
+ srd.dist = dist;
srd.hit = 0;
srd.original = (cache)? cache->original: 0;
BLI_pbvh_raycast(ss->tree, sculpt_raycast_cb, &srd,
diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c
index 48f3c77091f..c7b62dd7ef4 100644
--- a/source/blender/editors/space_view3d/view3d_view.c
+++ b/source/blender/editors/space_view3d/view3d_view.c
@@ -536,6 +536,7 @@ void viewline(ARegion *ar, View3D *v3d, float mval[2], float ray_start[3], float
{
RegionView3D *rv3d= ar->regiondata;
float vec[4];
+ int a;
if(rv3d->persp != RV3D_ORTHO){
vec[0]= 2.0f * mval[0] / ar->winx - 1;
@@ -564,6 +565,11 @@ void viewline(ARegion *ar, View3D *v3d, float mval[2], float ray_start[3], float
VECADDFAC(ray_start, vec, rv3d->viewinv[2], 1000.0f);
VECADDFAC(ray_end, vec, rv3d->viewinv[2], -1000.0f);
}
+
+ /* clipping */
+ if(rv3d->rflag & RV3D_CLIPPING)
+ for(a=0; a<4; a++)
+ clip_line_plane(ray_start, ray_end, rv3d->clip[a]);
}
/* create intersection ray in view Z direction at mouse coordinates */