workaround [#30480] Knife tool flicker

the problem was numeric precision when in ortho mode the start/end points for the view vector would be 2000 apart which caused trouble for the intersection test.
This commit is contained in:
Campbell Barton 2012-03-13 01:11:08 +00:00
parent b457c7fdbd
commit 8646bb4464
5 changed files with 33 additions and 4 deletions

View File

@ -73,6 +73,7 @@ void closest_to_plane_v3(float r[3], const float plane_co[3], const float plane
float line_point_factor_v3(const float p[3], const float l1[3], const float l2[3]);
float line_point_factor_v2(const float p[2], const float l1[2], const float l2[2]);
void limit_dist_v3(float v1[3], float v2[3], const float dist);
/******************************* Intersection ********************************/

View File

@ -1320,6 +1320,25 @@ float line_point_factor_v2(const float p[2], const float l1[2], const float l2[2
return(dot_v2v2(u, h)/dot_v2v2(u, u));
}
/* ensyre the distance between these points is no greater then 'dist'
* if it is, scale then both into the center */
void limit_dist_v3(float v1[3], float v2[3], const float dist)
{
const float dist_old = len_v3v3(v1, v2);
if (dist_old > dist) {
float v1_old[3];
float v2_old[3];
float fac = (dist / dist_old) * 0.5f;
copy_v3_v3(v1_old, v1);
copy_v3_v3(v2_old, v2);
interp_v3_v3v3(v1, v1_old, v2_old, 0.5f - fac);
interp_v3_v3v3(v2, v1_old, v2_old, 0.5f + fac);
}
}
/* Similar to LineIntersectsTriangleUV, except it operates on a quad and in 2d, assumes point is in quad */
void isect_point_quad_uv_v2(const float v0[2], const float v1[2], const float v2[2], const float v3[2], const float pt[2], float r_uv[2])
{

View File

@ -4447,7 +4447,7 @@ static int mesh_bevel_exec(bContext *C, wmOperator *op)
BMIter iter;
BMEdge *eed;
BMOperator bmop;
float factor = RNA_float_get(op->ptr, "percent"), fac = factor /*, dfac */ /* UNUSED */, df, s;
float factor = RNA_float_get(op->ptr, "percent"), /*, dfac */ /* UNUSED */, df, s;
int i, recursion = RNA_int_get(op->ptr, "recursion");
const int use_even = RNA_boolean_get(op->ptr, "use_even");
const int use_dist = RNA_boolean_get(op->ptr, "use_dist");
@ -4484,9 +4484,8 @@ static int mesh_bevel_exec(bContext *C, wmOperator *op)
mul_vn_fl(w, recursion, 1.0f / (float)ftot);
fac = factor;
for (i = 0; i < recursion; i++) {
fac = w[recursion - i - 1] * factor;
float fac = w[recursion - i - 1] * factor;
if (!EDBM_InitOpf(em, &bmop, op,
"bevel geom=%hev percent=%f lengthlayer=%i use_lengths=%b use_even=%b use_dist=%b",

View File

@ -1178,6 +1178,16 @@ static void knife_find_line_hits(knifetool_opdata *kcd)
mul_m4_v3(kcd->ob->imat, v3);
mul_m4_v3(kcd->ob->imat, v4);
/* numeric error, 'v1' -> 'v2', 'v2' -> 'v4' can end up being ~2000 units apart in otho mode
* (from ED_view3d_win_to_segment_clip() above)
* this gives precision error in 'knife_edge_tri_isect', rather then solving properly
* (which may involve using doubles everywhere!),
* limit the distance between these points */
if (kcd->is_ortho) {
limit_dist_v3(v1, v3, 200.0f);
limit_dist_v3(v2, v4, 200.0f);
}
BLI_smallhash_init(ehash);
/* test two triangles of sceen line's plane */

View File

@ -1101,7 +1101,7 @@ static PyObject *quat__apply_to_copy(PyNoArgsFunction quat_func, QuaternionObjec
}
}
/* axis vector suffers from precission errors, use this function to ensure */
/* axis vector suffers from precision errors, use this function to ensure */
static void quat__axis_angle_sanitize(float axis[3], float *angle)
{
if (axis) {