==Python API==
authorCampbell Barton <ideasman42@gmail.com>
Sat, 24 Nov 2007 18:29:33 +0000 (18:29 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 24 Nov 2007 18:29:33 +0000 (18:29 +0000)
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.

source/blender/python/api2_2x/Mesh.c
source/blender/python/api2_2x/doc/Mesh.py

index 8a832d0deeb5fe6d63143ccd4307226516caa5f1..8248816bc3d46f178130d0a3c24db6ef0641def0 100644 (file)
@@ -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 */
index e572d6a91ae5ef2db1378fc2ed20b93c2089abfd..7e7514e8b3aa8f09c002d6b2e3617e0f6e792e46 100644 (file)
@@ -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