Revision: 14304 http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=14304 Author: blendix Date: 2008-04-01 12:15:39 +0200 (Tue, 01 Apr 2008)
Log Message: ----------- Fix for bug #8629: python object.boundingBox was not in worldspace anymore for meshes due to a bugfix. The python code assumed ob->bb was in worldspace while it isn't, also meant metaball bounding boxes were wrong. Modified Paths: -------------- trunk/blender/source/blender/python/api2_2x/Object.c Modified: trunk/blender/source/blender/python/api2_2x/Object.c =================================================================== --- trunk/blender/source/blender/python/api2_2x/Object.c 2008-04-01 10:10:37 UTC (rev 14303) +++ trunk/blender/source/blender/python/api2_2x/Object.c 2008-04-01 10:15:39 UTC (rev 14304) @@ -1498,73 +1498,57 @@ default: Py_RETURN_NONE; } + } else { /* the ob bbox exists */ + vec = ( float * ) self->object->bb->vec; + } - { /* transform our obdata bbox by the obmat. - the obmat is 4x4 homogeneous coords matrix. - each bbox coord is xyz, so we make it homogenous - by padding it with w=1.0 and doing the matrix mult. - afterwards we divide by w to get back to xyz. - */ - /* printmatrix4( "obmat", self->object->obmat); */ - float tmpvec[4]; /* tmp vector for homogenous coords math */ - int i; - float *from; + { /* transform our obdata bbox by the obmat. + the obmat is 4x4 homogeneous coords matrix. + each bbox coord is xyz, so we make it homogenous + by padding it with w=1.0 and doing the matrix mult. + afterwards we divide by w to get back to xyz. + */ + /* printmatrix4( "obmat", self->object->obmat); */ - bbox = PyList_New( 8 ); - if( !bbox ) - return EXPP_ReturnPyObjError - ( PyExc_MemoryError, - "couldn't create pylist" ); - 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]; + float tmpvec[4]; /* tmp vector for homogenous coords math */ + int i; + float *from; + bbox = PyList_New( 8 ); + if( !bbox ) + return EXPP_ReturnPyObjError + ( PyExc_MemoryError, + "couldn't create pylist" ); + 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 0 - { /* debug print stuff */ - int i; + { /* debug print stuff */ + int i; - printf( "\nobj bbox transformed\n" ); - for( i = 0; i < 4; ++i ) - printf( "%f ", tmpvec[i] ); + printf( "\nobj bbox transformed\n" ); + for( i = 0; i < 4; ++i ) + printf( "%f ", tmpvec[i] ); - printf( "\n" ); - } + printf( "\n" ); + } #endif - /* because our bounding box is calculated and - does not have its own memory, - we must create vectors that allocate space */ + /* because our bounding box is calculated and + does not have its own memory, + we must create vectors that allocate space */ - vector = newVectorObject( NULL, 3, Py_NEW); - memcpy( ( ( VectorObject * ) vector )->vec, - tmpvec, 3 * sizeof( float ) ); - PyList_SET_ITEM( bbox, i, vector ); - } - } - } else { /* the ob bbox exists */ - vec = ( float * ) self->object->bb->vec; - - if( !vec ) - return EXPP_ReturnPyObjError( PyExc_RuntimeError, - "couldn't retrieve bounding box data" ); - - bbox = PyList_New( 8 ); - - if( !bbox ) - return EXPP_ReturnPyObjError( PyExc_MemoryError, - "couldn't create pylist" ); - - /* create vectors referencing object bounding box coords */ - for( i = 0; i < 8; i++ ) { - vector = newVectorObject( vec, 3, Py_WRAP ); + vector = newVectorObject( NULL, 3, Py_NEW); + memcpy( ( ( VectorObject * ) vector )->vec, + tmpvec, 3 * sizeof( float ) ); PyList_SET_ITEM( bbox, i, vector ); - vec += 3; } } _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org http://lists.blender.org/mailman/listinfo/bf-blender-cvs