[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [12664] trunk/blender/source/blender/ python/api2_2x: ==Python API==

Campbell Barton ideasman42 at gmail.com
Sat Nov 24 19:29:33 CET 2007


Revision: 12664
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=12664
Author:   campbellbarton
Date:     2007-11-24 19:29:33 +0100 (Sat, 24 Nov 2007)

Log Message:
-----------
==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.

Modified Paths:
--------------
    trunk/blender/source/blender/python/api2_2x/Mesh.c
    trunk/blender/source/blender/python/api2_2x/doc/Mesh.py

Modified: trunk/blender/source/blender/python/api2_2x/Mesh.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Mesh.c	2007-11-24 17:10:48 UTC (rev 12663)
+++ trunk/blender/source/blender/python/api2_2x/Mesh.c	2007-11-24 18:29:33 UTC (rev 12664)
@@ -7429,28 +7429,34 @@
 	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 @@
 		"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 */

Modified: trunk/blender/source/blender/python/api2_2x/doc/Mesh.py
===================================================================
--- trunk/blender/source/blender/python/api2_2x/doc/Mesh.py	2007-11-24 17:10:48 UTC (rev 12663)
+++ trunk/blender/source/blender/python/api2_2x/doc/Mesh.py	2007-11-24 18:29:33 UTC (rev 12664)
@@ -834,10 +834,15 @@
 		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 @@
 		@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





More information about the Bf-blender-cvs mailing list