Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2008-04-07 17:16:56 +0400
committerCampbell Barton <ideasman42@gmail.com>2008-04-07 17:16:56 +0400
commit7c15baff16a0250e7a5966688cde16110cac960c (patch)
treee55fe75cb6d9c02b0092517c99f4e8237e6d364f /source
parent66e74e6057ff4266fb3a6b19268b4c114c7cfe89 (diff)
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.
Diffstat (limited to 'source')
-rw-r--r--source/blender/python/api2_2x/Object.c51
-rw-r--r--source/blender/python/api2_2x/doc/Object.py4
2 files changed, 35 insertions, 20 deletions
diff --git a/source/blender/python/api2_2x/Object.c b/source/blender/python/api2_2x/Object.c
index 02403c71a36..7b1ccb93d68 100644
--- a/source/blender/python/api2_2x/Object.c
+++ b/source/blender/python/api2_2x/Object.c
@@ -360,7 +360,8 @@ static PyObject *Object_getSize( BPy_Object * self, PyObject * args );
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 @@ automatic when the script finishes."},
"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 @@ static PyObject *Object_getType( BPy_Object * self )
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 @@ static PyObject *Object_getBoundBox( BPy_Object * self )
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
-
+ }
/* because our bounding box is calculated and
does not have its own memory,
we must create vectors that allocate space */
@@ -1556,6 +1564,11 @@ static PyObject *Object_getBoundBox( BPy_Object * self )
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 @@ static PyGetSetDef BPy_Object_getseters[] = {
"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",
diff --git a/source/blender/python/api2_2x/doc/Object.py b/source/blender/python/api2_2x/doc/Object.py
index 4228f6de1a8..8157045550d 100644
--- a/source/blender/python/api2_2x/doc/Object.py
+++ b/source/blender/python/api2_2x/doc/Object.py
@@ -1178,10 +1178,12 @@ class Object:
- 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.