[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [14350] trunk/blender/source/blender/ python/api2_2x: added an optional arg for object.getBoundBox(worldspace) - so you can get localspace boundboxes, this is useful when getting a dipli' s boundbox where the objects worldspace matrix has no useful meaning.
Campbell Barton
ideasman42 at gmail.com
Mon Apr 7 15:16:58 CEST 2008
Revision: 14350
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=14350
Author: campbellbarton
Date: 2008-04-07 15:16:56 +0200 (Mon, 07 Apr 2008)
Log Message:
-----------
added an optional arg for object.getBoundBox(worldspace) - so you can get localspace boundboxes, this is useful when getting a dipli's boundbox where the objects worldspace matrix has no useful meaning.
Modified Paths:
--------------
trunk/blender/source/blender/python/api2_2x/Object.c
trunk/blender/source/blender/python/api2_2x/doc/Object.py
Modified: trunk/blender/source/blender/python/api2_2x/Object.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Object.c 2008-04-07 10:12:21 UTC (rev 14349)
+++ trunk/blender/source/blender/python/api2_2x/Object.c 2008-04-07 13:16:56 UTC (rev 14350)
@@ -360,7 +360,8 @@
static PyObject *Object_getTimeOffset( BPy_Object * self );
static PyObject *Object_getTracked( BPy_Object * self );
static PyObject *Object_getType( BPy_Object * self );
-static PyObject *Object_getBoundBox( BPy_Object * self );
+static PyObject *Object_getBoundBox( BPy_Object * self, PyObject *args );
+static PyObject *Object_getBoundBox_noargs( BPy_Object * self );
static PyObject *Object_getAction( BPy_Object * self );
static PyObject *Object_getPose( BPy_Object * self );
static PyObject *Object_evaluatePose( BPy_Object * self, PyObject *args );
@@ -633,7 +634,7 @@
"Returns SB StiffQuads"},
{"setSBStiffQuads", ( PyCFunction ) Object_SetSBStiffQuads, METH_VARARGS,
"Sets SB StiffQuads"},
- {"getBoundBox", ( PyCFunction ) Object_getBoundBox, METH_NOARGS,
+ {"getBoundBox", ( PyCFunction ) Object_getBoundBox, METH_VARARGS,
"Returns the object's bounding box"},
{"makeDisplayList", ( PyCFunction ) Object_makeDisplayList, METH_NOARGS,
"Update this object's Display List. Some changes like turning\n\
@@ -1471,10 +1472,15 @@
return PyString_FromString( str );
}
-static PyObject *Object_getBoundBox( BPy_Object * self )
+static PyObject *Object_getBoundBox( BPy_Object * self, PyObject *args )
{
float *vec = NULL;
PyObject *vector, *bbox;
+ int worldspace = 1;
+
+ if( !PyArg_ParseTuple( args, "|i", &worldspace ) )
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "expected an int or nothing" );
if( !self->object->data )
return EXPP_ReturnPyObjError( PyExc_AttributeError,
@@ -1524,24 +1530,26 @@
for( i = 0, from = vec; i < 8; i++, from += 3 ) {
memcpy( tmpvec, from, 3 * sizeof( float ) );
tmpvec[3] = 1.0f; /* set w coord */
- Mat4MulVec4fl( self->object->obmat, tmpvec );
- /* divide x,y,z by w */
- tmpvec[0] /= tmpvec[3];
- tmpvec[1] /= tmpvec[3];
- tmpvec[2] /= tmpvec[3];
+
+ if (worldspace) {
+ Mat4MulVec4fl( self->object->obmat, tmpvec );
+ /* divide x,y,z by w */
+ tmpvec[0] /= tmpvec[3];
+ tmpvec[1] /= tmpvec[3];
+ tmpvec[2] /= tmpvec[3];
#if 0
- { /* debug print stuff */
- int i;
-
- printf( "\nobj bbox transformed\n" );
- for( i = 0; i < 4; ++i )
- printf( "%f ", tmpvec[i] );
-
- printf( "\n" );
+ { /* debug print stuff */
+ int i;
+
+ printf( "\nobj bbox transformed\n" );
+ for( i = 0; i < 4; ++i )
+ printf( "%f ", tmpvec[i] );
+
+ printf( "\n" );
+ }
+#endif
}
-#endif
-
/* because our bounding box is calculated and
does not have its own memory,
we must create vectors that allocate space */
@@ -1556,6 +1564,11 @@
return bbox;
}
+static PyObject *Object_getBoundBox_noargs( BPy_Object * self )
+{
+ return Object_getBoundBox(self, PyTuple_New(0));
+}
+
static PyObject *Object_makeDisplayList( BPy_Object * self )
{
Object *ob = self->object;
@@ -4818,7 +4831,7 @@
"The object's type",
NULL},
{"boundingBox",
- (getter)Object_getBoundBox, (setter)NULL,
+ (getter)Object_getBoundBox_noargs, (setter)NULL,
"The bounding box of this object",
NULL},
{"action",
Modified: trunk/blender/source/blender/python/api2_2x/doc/Object.py
===================================================================
--- trunk/blender/source/blender/python/api2_2x/doc/Object.py 2008-04-07 10:12:21 UTC (rev 14349)
+++ trunk/blender/source/blender/python/api2_2x/doc/Object.py 2008-04-07 13:16:56 UTC (rev 14350)
@@ -1178,10 +1178,12 @@
- 1 - selected
"""
- def getBoundBox():
+ def getBoundBox(worldspace=1):
"""
Returns the worldspace bounding box of this object. This works for meshes (out of
edit mode) and curves.
+ @type worldspace: int
+ @param worldspace: An optional argument. When zero, the bounding values will be localspace.
@rtype: list of 8 (x,y,z) float coordinate vectors (WRAPPED DATA)
@return: The coordinates of the 8 corners of the bounding box. Data is wrapped when
bounding box is present.
More information about the Bf-blender-cvs
mailing list