diff options
author | Campbell Barton <ideasman42@gmail.com> | 2007-11-13 18:32:27 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2007-11-13 18:32:27 +0300 |
commit | d376b0630bed0c7cb4c21910d95fac7a5532dae6 (patch) | |
tree | 2586dede740441649fb5d7f04e42e9ec34c46dae /source/blender/python/api2_2x | |
parent | 470a69388f5b34e16bd1fbcb4a9c93c0d3a6892f (diff) |
==Python API==
mesh.pointInside(vec) wasnt working in all cases. (own mistake)
Diffstat (limited to 'source/blender/python/api2_2x')
-rw-r--r-- | source/blender/python/api2_2x/Mesh.c | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/source/blender/python/api2_2x/Mesh.c b/source/blender/python/api2_2x/Mesh.c index 494a1250728..88fa09bd607 100644 --- a/source/blender/python/api2_2x/Mesh.c +++ b/source/blender/python/api2_2x/Mesh.c @@ -7379,28 +7379,34 @@ static PyObject *Mesh_fill( BPy_Mesh * self ) /* * "pointInside" function */ +/* Warning - this is ordered - need to test both orders to be sure */ #define SIDE_OF_LINE(pa,pb,pp) ((pa[0]-pp[0])*(pb[1]-pp[1]))-((pb[0]-pp[0])*(pa[1]-pp[1])) #define POINT_IN_TRI(p0,p1,p2,p3) ((SIDE_OF_LINE(p1,p2,p0)>=0) && (SIDE_OF_LINE(p2,p3,p0)>=0) && (SIDE_OF_LINE(p3,p1,p0)>=0)) static short pointInside_internal(float *vec, float *v1, float *v2, float *v3 ) { float z,w1,w2,w3,wtot; - if (!POINT_IN_TRI(vec, v1,v2,v3)) + + if (vec[2] > MAX3(v1[2], v2[2], v3[2])) return 0; - if (vec[2] < MAX3(v1[2], v2[2], v3[2])) { - w1= AreaF2Dfl(vec, v2, v3); - w2= AreaF2Dfl(v1, vec, v3); - w3= AreaF2Dfl(v1, v2, vec); - wtot = w1+w2+w3; - w1/=wtot; w2/=wtot; w3/=wtot; - z =((v1[2] * (w2+w3)) + - (v2[2] * (w1+w3)) + - (v3[2] * (w1+w2))) * 0.5; - /* only return true if the face is above vec*/ - if (vec[2] < z ) - return 1; - } + /* need to test both orders */ + if (!POINT_IN_TRI(vec, v1,v2,v3) && !POINT_IN_TRI(vec, v3,v2,v1)) + return 0; + + w1= AreaF2Dfl(vec, v2, v3); + w2= AreaF2Dfl(v1, vec, v3); + w3= AreaF2Dfl(v1, v2, vec); + wtot = w1+w2+w3; + w1/=wtot; w2/=wtot; w3/=wtot; + z =((v1[2] * w1) + + (v2[2] * w2) + + (v3[2] * w3)); + + /* only return true if the face is above vec*/ + if (vec[2] < z ) + return 1; + return 0; } @@ -7418,13 +7424,15 @@ static PyObject *Mesh_pointInside( BPy_Mesh * self, VectorObject * vec ) if(vec->size < 3) return EXPP_ReturnPyObjError(PyExc_AttributeError, - "Mesh.pointInside(vec) expects a 3D vector objects\n"); + "Mesh.pointInside(vec) expects a 3D vector object\n"); - for( i = 0; i < mesh->totface; ++mf, ++i ) { - if (pointInside_internal(vec->vec, mvert[mf->v1].co, mvert[mf->v2].co, mvert[mf->v3].co)) + for( i = 0; i < mesh->totface; mf++, i++ ) { + if (pointInside_internal(vec->vec, mvert[mf->v1].co, mvert[mf->v2].co, mvert[mf->v3].co)) { isect_count++; - else if (mf->v4 && pointInside_internal(vec->vec,mvert[mf->v1].co, mvert[mf->v3].co, mvert[mf->v4].co)) + } else if (mf->v4 && pointInside_internal(vec->vec,mvert[mf->v1].co, mvert[mf->v3].co, mvert[mf->v4].co)) { + isect_count++; + } } if (isect_count % 2) |