diff options
author | Campbell Barton <ideasman42@gmail.com> | 2007-11-24 21:29:33 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2007-11-24 21:29:33 +0300 |
commit | 13e73af13e4d61206459ee61585c09e967b557f8 (patch) | |
tree | ed28dc0b949d8787cb3f5565c2e1a4a75274458a /source/blender/python/api2_2x | |
parent | 7dc125086526d40e8b753f655c44bcb06e44c2d9 (diff) |
==Python API==
Added a keyword argument for mesh.pointInside(point, selected_only=True)
This means only selected faces are tested when doing the inside/outside test, disabled by default.
Diffstat (limited to 'source/blender/python/api2_2x')
-rw-r--r-- | source/blender/python/api2_2x/Mesh.c | 26 | ||||
-rw-r--r-- | source/blender/python/api2_2x/doc/Mesh.py | 9 |
2 files changed, 23 insertions, 12 deletions
diff --git a/source/blender/python/api2_2x/Mesh.c b/source/blender/python/api2_2x/Mesh.c index 8a832d0deeb..8248816bc3d 100644 --- a/source/blender/python/api2_2x/Mesh.c +++ b/source/blender/python/api2_2x/Mesh.c @@ -7429,28 +7429,34 @@ static short pointInside_internal(float *vec, float *v1, float *v2, float *v3 ) return 0; } -static PyObject *Mesh_pointInside( BPy_Mesh * self, VectorObject * vec ) +static PyObject *Mesh_pointInside( BPy_Mesh * self, PyObject * args, PyObject *kwd ) { Mesh *mesh = self->mesh; MFace *mf = mesh->mface; MVert *mvert = mesh->mvert; int i; int isect_count=0; + int selected_only = 0; + VectorObject *vec; + static char *kwlist[] = {"point", "selected_only", NULL}; - if(!VectorObject_Check(vec)) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected one vector type" ); + if( !PyArg_ParseTupleAndKeywords(args, kwd, "|O!i", kwlist, + &vector_Type, &vec, &selected_only) ) { + return EXPP_ReturnPyObjError( PyExc_TypeError, "expected a vector and an optional bool argument"); + } if(vec->size < 3) return EXPP_ReturnPyObjError(PyExc_AttributeError, "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)) { - isect_count++; - } else if (mf->v4 && pointInside_internal(vec->vec,mvert[mf->v1].co, mvert[mf->v3].co, mvert[mf->v4].co)) { - - isect_count++; + if (!selected_only || mf->flag & ME_FACE_SEL) { + 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)) { + + isect_count++; + } } } @@ -7536,7 +7542,7 @@ static struct PyMethodDef BPy_Mesh_methods[] = { "Removes duplicates from selected vertices (experimental)"}, {"recalcNormals", (PyCFunction)Mesh_recalcNormals, METH_VARARGS, "Recalculates inside or outside normals (experimental)"}, - {"pointInside", (PyCFunction)Mesh_pointInside, METH_O, + {"pointInside", (PyCFunction)Mesh_pointInside, METH_VARARGS|METH_KEYWORDS, "Recalculates inside or outside normals (experimental)"}, /* mesh custom data layers */ diff --git a/source/blender/python/api2_2x/doc/Mesh.py b/source/blender/python/api2_2x/doc/Mesh.py index e572d6a91ae..7e7514e8b3a 100644 --- a/source/blender/python/api2_2x/doc/Mesh.py +++ b/source/blender/python/api2_2x/doc/Mesh.py @@ -834,10 +834,15 @@ class Mesh: Recalculates the vertex normals using face data. """ - def pointInside(vector): + def pointInside(point, selected_only=False): """ + @type point: vector + @param point: Test if this point is inside the mesh + @type selected_only: bool + @param selected_only: if True or 1, only the selected faces are taken into account. Returns true if vector is inside the mesh. @note: Only returns a valid result for mesh data that has no holes. + @note: Bubbles in the mesh work as expect. """ def transform(matrix, recalc_normals = False, selected_only=False): @@ -869,7 +874,7 @@ class Mesh: @param matrix: 4x4 Matrix which can contain location, scale and rotation. @type recalc_normals: int @param recalc_normals: if True or 1, also transform vertex normals. - @type selected_only: int + @type selected_only: bool @param selected_only: if True or 1, only the selected verts will be transformed. @warn: unlike L{NMesh.transform()<NMesh.NMesh.transform>}, this method I{will immediately modify the mesh data} when it is used. If you |