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
diff options
context:
space:
mode:
authorJoseph Gilbert <ascotan@gmail.com>2005-07-14 07:34:56 +0400
committerJoseph Gilbert <ascotan@gmail.com>2005-07-14 07:34:56 +0400
commitb89035906daa352ac8eae4c157c3dd6f61b7ad62 (patch)
treed3e3312fb8e282c327b6cb4f7b1f780ce299afa2 /source/blender/python/api2_2x/Bone.c
parent1bfd0eae148af20ed97992d44a66f5a6ec34571c (diff)
Mathutils update
- also included is some fixes for preprocessor inclues and some clean up of the previous commit -rewrite and bugfixes ---------------------------------- Here's my changelog: -fixed Rand() so that it doesn't seed everytime and should generate better random numbers - changed a few error return types to something more appropriate - clean up of uninitialized variables & removal of unneccessary objects - NMesh returns wrapped vectors now - World returns wrapped matrices now - Object.getEuler() and Object.getBoundingBox() return Wrapped data when data is present - Object.getMatrix() returns wrapped data if it's worldspace, 'localspace' returns a new matrix - Vector, Euler, Mat, Quat, call all now internally wrap object without destroying internal datablocks - Removed memory allocation (unneeded) from all methods - Vector's resize methods are only applicable to new vectors not wrapped data. - Matrix(), Quat(), Euler(), Vector() now accepts ANY sequence list, including tuples, list, or a self object to copy - matrices accept multiple sequences - Fixed Slerp() so that it now works correctly values are clamped between 0 and 1 - Euler.rotate does internal rotation now - Slice assignment now works better for all types - Vector * Vector and Quat * Quat are defined and return the DOT product - Mat * Vec and Vec * Mat are defined now - Moved #includes to .c file from headers. Also fixed prototypes in mathutils - Added new helper functions for incref'ing to genutils - Major cleanup of header files includes - include Mathutils.h for access to math types - matrix.toQuat() and .toEuler() now fixed take appropriate matrix sizes - Matrix() with no parameters now returns an identity matrix by default not a zero matrix - printf() now prints with 6 digits instead of 4 - printf() now prints output with object descriptor - Matrices now support [x][y] assignment (e.g. matrix[x][y] = 5.4) - Matrix[index] = value now expectes a sequence not an integer. This will now set a ROW of the matrix through a sequence. index cannot go above the row size of the matrix. - slice operations on matrices work with sequences now (rows of the matrix) example: mymatrix[0:2] returns a list of 2 wrapped vectors with access to the matrix data. - slice assignment will no longer modify the data if the assignment operation fails - fixed error in matrix * scalar multiplication - euler.toMatrix(), toQuat() no longer causes "creep" from repeated use - Wrapped data will generate wrapped objects when toEuler(), toQuat(), toMatrix() is used - Quats can be created with angle/axis, axis/angle - 4x4 matrices can be multiplied by 3D vectors (by popular demand :)) - vec *quat / quat * vec is now defined - vec.magnitude alias for vec.length - all self, internal methods return a pointer to self now so you can do print vector.internalmethod() or vector.internalmethod().nextmethod() (no more print matrix.inverse() returning 'none') - these methods have been deprecated (still functioning but suggested to use the corrected functionality): * CopyVec() - replaced by Vector() functionality * CopyMat() - replaced by Matrix() functionality * CopyQuat() - replace by Quaternion() functionality * CopyEuler() - replaced by Euler() functionality * RotateEuler() - replaced by Euler.rotate() funtionality * MatMultVec() - replaced by matrix * vector * VecMultMat() - replaced by vector * matrix - New struct containers references to python object data or internally allocated blender data for wrapping * Explaination here: math structs now function as a 'simple wrapper' or a 'py_object' - data that is created on the fly will now be a 'py_object' with its memory managed by python * otherwise if the data is returned by blender's G.main then the math object is a 'simple wrapper' and data can be accessed directly from the struct just like other python objects.
Diffstat (limited to 'source/blender/python/api2_2x/Bone.c')
-rw-r--r--source/blender/python/api2_2x/Bone.c179
1 files changed, 60 insertions, 119 deletions
diff --git a/source/blender/python/api2_2x/Bone.c b/source/blender/python/api2_2x/Bone.c
index 7c96a02d595..87ae85db99f 100644
--- a/source/blender/python/api2_2x/Bone.c
+++ b/source/blender/python/api2_2x/Bone.c
@@ -32,26 +32,30 @@
#include "Bone.h"
-#include <BKE_main.h>
-#include <BKE_global.h>
-#include <BKE_object.h>
-#include <BKE_armature.h>
-#include <BKE_library.h>
-#include <BLI_blenlib.h>
-#include <DNA_action_types.h>
-#include <DNA_armature_types.h>
-#include <DNA_ipo_types.h>
-#include <BIF_poseobject.h>
-#include <BKE_action.h>
-#include <BSE_editaction.h>
-#include <BKE_constraint.h>
-#include <MEM_guardedalloc.h>
+#include "BKE_main.h"
+#include "BKE_global.h"
+#include "BKE_object.h"
+#include "BKE_armature.h"
+#include "BKE_library.h"
+#include "BLI_blenlib.h"
+#include "DNA_action_types.h"
+#include "DNA_armature_types.h"
+#include "DNA_ipo_types.h"
+#include "BIF_poseobject.h"
+#include "BKE_action.h"
+#include "BSE_editaction.h"
+#include "BKE_constraint.h"
+#include "MEM_guardedalloc.h"
+#include "BKE_utildefines.h"
+#include "BLI_arithb.h"
#include "constant.h"
#include "gen_utils.h"
#include "NLA.h"
#include "quat.h"
#include "matrix.h"
#include "vector.h"
+#include "Types.h"
+
//--------------------Python API function prototypes for the Bone module----
static PyObject *M_Bone_New( PyObject * self, PyObject * args );
@@ -237,7 +241,6 @@ PyObject *Bone_Init( void )
//--------------- updatePyBone------------------------------------
static int updatePyBone( BPy_Bone * self )
{
- int x, y;
char *parent_str = "";
if( !self->bone ) {
@@ -540,45 +543,19 @@ PyObject *Bone_CreatePyObject( struct Bone * bone )
//allocate space for python vars
blen_bone->name = PyMem_Malloc( 32 + 1 );
blen_bone->parent = PyMem_Malloc( 32 + 1 );
- blen_bone->head =
- ( VectorObject * )
- newVectorObject( PyMem_Malloc( 3 * sizeof( float ) ), 3 );
- blen_bone->tail =
- ( VectorObject * )
- newVectorObject( PyMem_Malloc( 3 * sizeof( float ) ), 3 );
- blen_bone->loc =
- ( VectorObject * )
- newVectorObject( PyMem_Malloc( 3 * sizeof( float ) ), 3 );
- blen_bone->dloc =
- ( VectorObject * )
- newVectorObject( PyMem_Malloc( 3 * sizeof( float ) ), 3 );
- blen_bone->size =
- ( VectorObject * )
- newVectorObject( PyMem_Malloc( 3 * sizeof( float ) ), 3 );
- blen_bone->dsize =
- ( VectorObject * )
- newVectorObject( PyMem_Malloc( 3 * sizeof( float ) ), 3 );
- blen_bone->quat =
- ( QuaternionObject * )
- newQuaternionObject( PyMem_Malloc( 4 * sizeof( float ) ) );
- blen_bone->dquat =
- ( QuaternionObject * )
- newQuaternionObject( PyMem_Malloc( 4 * sizeof( float ) ) );
- blen_bone->obmat =
- ( MatrixObject * )
- newMatrixObject( PyMem_Malloc( 16 * sizeof( float ) ), 4, 4 );
- blen_bone->parmat =
- ( MatrixObject * )
- newMatrixObject( PyMem_Malloc( 16 * sizeof( float ) ), 4, 4 );
- blen_bone->defmat =
- ( MatrixObject * )
- newMatrixObject( PyMem_Malloc( 16 * sizeof( float ) ), 4, 4 );
- blen_bone->irestmat =
- ( MatrixObject * )
- newMatrixObject( PyMem_Malloc( 16 * sizeof( float ) ), 4, 4 );
- blen_bone->posemat =
- ( MatrixObject * )
- newMatrixObject( PyMem_Malloc( 16 * sizeof( float ) ), 4, 4 );
+ blen_bone->head = ( VectorObject *)newVectorObject( NULL, 3, Py_NEW );
+ blen_bone->tail = ( VectorObject *)newVectorObject( NULL, 3, Py_NEW );
+ blen_bone->loc = ( VectorObject *)newVectorObject( NULL, 3, Py_NEW );
+ blen_bone->dloc = ( VectorObject *)newVectorObject( NULL, 3, Py_NEW );
+ blen_bone->size = ( VectorObject *)newVectorObject( NULL, 3, Py_NEW );
+ blen_bone->dsize = ( VectorObject *)newVectorObject( NULL, 3, Py_NEW );
+ blen_bone->quat = blen_bone->quat = ( QuaternionObject *)newQuaternionObject( NULL, Py_NEW );
+ blen_bone->dquat = blen_bone->quat = ( QuaternionObject *)newQuaternionObject( NULL, Py_NEW );
+ blen_bone->obmat = blen_bone->obmat = ( MatrixObject *)newMatrixObject( NULL, 4, 4 , Py_NEW);
+ blen_bone->parmat = blen_bone->obmat = ( MatrixObject *)newMatrixObject( NULL, 4, 4 , Py_NEW);
+ blen_bone->defmat = blen_bone->obmat = ( MatrixObject *)newMatrixObject( NULL, 4, 4 , Py_NEW);
+ blen_bone->irestmat = blen_bone->obmat = ( MatrixObject *)newMatrixObject( NULL, 4, 4 , Py_NEW);
+ blen_bone->posemat = blen_bone->obmat = ( MatrixObject *)newMatrixObject( NULL, 4, 4 , Py_NEW);
if( !updatePyBone( blen_bone ) )
return EXPP_ReturnPyObjError( PyExc_AttributeError,
@@ -627,45 +604,19 @@ static PyObject *M_Bone_New( PyObject * self, PyObject * args )
//allocate space for python vars
py_bone->name = PyMem_Malloc( 32 + 1 );
py_bone->parent = PyMem_Malloc( 32 + 1 );
- py_bone->head =
- ( VectorObject * )
- newVectorObject( PyMem_Malloc( 3 * sizeof( float ) ), 3 );
- py_bone->tail =
- ( VectorObject * )
- newVectorObject( PyMem_Malloc( 3 * sizeof( float ) ), 3 );
- py_bone->loc =
- ( VectorObject * )
- newVectorObject( PyMem_Malloc( 3 * sizeof( float ) ), 3 );
- py_bone->dloc =
- ( VectorObject * )
- newVectorObject( PyMem_Malloc( 3 * sizeof( float ) ), 3 );
- py_bone->size =
- ( VectorObject * )
- newVectorObject( PyMem_Malloc( 3 * sizeof( float ) ), 3 );
- py_bone->dsize =
- ( VectorObject * )
- newVectorObject( PyMem_Malloc( 3 * sizeof( float ) ), 3 );
- py_bone->quat =
- ( QuaternionObject * )
- newQuaternionObject( PyMem_Malloc( 4 * sizeof( float ) ) );
- py_bone->dquat =
- ( QuaternionObject * )
- newQuaternionObject( PyMem_Malloc( 4 * sizeof( float ) ) );
- py_bone->obmat =
- ( MatrixObject * )
- newMatrixObject( PyMem_Malloc( 16 * sizeof( float ) ), 4, 4 );
- py_bone->parmat =
- ( MatrixObject * )
- newMatrixObject( PyMem_Malloc( 16 * sizeof( float ) ), 4, 4 );
- py_bone->defmat =
- ( MatrixObject * )
- newMatrixObject( PyMem_Malloc( 16 * sizeof( float ) ), 4, 4 );
- py_bone->irestmat =
- ( MatrixObject * )
- newMatrixObject( PyMem_Malloc( 16 * sizeof( float ) ), 4, 4 );
- py_bone->posemat =
- ( MatrixObject * )
- newMatrixObject( PyMem_Malloc( 16 * sizeof( float ) ), 4, 4 );
+ py_bone->head = ( VectorObject *)newVectorObject( NULL, 3, Py_NEW );
+ py_bone->tail = ( VectorObject *)newVectorObject( NULL, 3, Py_NEW );
+ py_bone->loc = ( VectorObject *)newVectorObject( NULL, 3, Py_NEW );
+ py_bone->dloc = ( VectorObject *)newVectorObject( NULL, 3, Py_NEW );
+ py_bone->size = ( VectorObject *)newVectorObject( NULL, 3, Py_NEW );
+ py_bone->dsize = ( VectorObject *)newVectorObject( NULL, 3, Py_NEW );
+ py_bone->quat = ( QuaternionObject *)newQuaternionObject( NULL, Py_NEW );
+ py_bone->dquat = ( QuaternionObject *)newQuaternionObject( NULL, Py_NEW );
+ py_bone->obmat = ( MatrixObject *)newMatrixObject( NULL, 4, 4 , Py_NEW);
+ py_bone->parmat = ( MatrixObject *)newMatrixObject( NULL, 4, 4 , Py_NEW);
+ py_bone->defmat = ( MatrixObject *)newMatrixObject( NULL, 4, 4 , Py_NEW);
+ py_bone->irestmat = ( MatrixObject *)newMatrixObject( NULL, 4, 4 , Py_NEW);
+ py_bone->posemat = ( MatrixObject *)newMatrixObject( NULL, 4, 4 , Py_NEW);
//default py values
BLI_strncpy( py_bone->name, name_str, strlen( name_str ) + 1 );
@@ -762,19 +713,17 @@ static PyObject *Bone_getWeight( BPy_Bone * self )
static PyObject *Bone_getHead( BPy_Bone * self )
{
PyObject *attr = NULL;
- float *vec;
+ float vec[3];
int x;
if( !self->bone ) { //test to see if linked to armature
//use python vars
- vec = PyMem_Malloc( 3 * sizeof( float ) );
for( x = 0; x < 3; x++ )
vec[x] = self->head->vec[x];
- attr = ( PyObject * ) newVectorObject( vec, 3 );
+ attr = ( PyObject * ) newVectorObject( vec, 3, Py_NEW );
} else {
//use bone datastruct
- attr = newVectorObject( PyMem_Malloc( 3 * sizeof( float ) ),
- 3 );
+ attr = newVectorObject( NULL, 3, Py_NEW );
( ( VectorObject * ) attr )->vec[0] = self->bone->head[0];
( ( VectorObject * ) attr )->vec[1] = self->bone->head[1];
( ( VectorObject * ) attr )->vec[2] = self->bone->head[2];
@@ -790,19 +739,17 @@ static PyObject *Bone_getHead( BPy_Bone * self )
static PyObject *Bone_getTail( BPy_Bone * self )
{
PyObject *attr = NULL;
- float *vec;
+ float vec[3];
int x;
if( !self->bone ) { //test to see if linked to armature
//use python vars
- vec = PyMem_Malloc( 3 * sizeof( float ) );
for( x = 0; x < 3; x++ )
vec[x] = self->tail->vec[x];
- attr = ( PyObject * ) newVectorObject( vec, 3 );
+ attr = ( PyObject * ) newVectorObject( vec, 3, Py_NEW );
} else {
//use bone datastruct
- attr = newVectorObject( PyMem_Malloc( 3 * sizeof( float ) ),
- 3 );
+ attr = newVectorObject( NULL, 3, Py_NEW );
( ( VectorObject * ) attr )->vec[0] = self->bone->tail[0];
( ( VectorObject * ) attr )->vec[1] = self->bone->tail[1];
( ( VectorObject * ) attr )->vec[2] = self->bone->tail[2];
@@ -818,19 +765,17 @@ static PyObject *Bone_getTail( BPy_Bone * self )
static PyObject *Bone_getLoc( BPy_Bone * self )
{
PyObject *attr = NULL;
- float *vec;
+ float vec[3];
int x;
if( !self->bone ) { //test to see if linked to armature
//use python vars
- vec = PyMem_Malloc( 3 * sizeof( float ) );
for( x = 0; x < 3; x++ )
vec[x] = self->loc->vec[x];
- attr = ( PyObject * ) newVectorObject( vec, 3 );
+ attr = ( PyObject * ) newVectorObject( vec, 3, Py_NEW );
} else {
//use bone datastruct
- attr = newVectorObject( PyMem_Malloc( 3 * sizeof( float ) ),
- 3 );
+ attr = newVectorObject( NULL, 3, Py_NEW );
// ( ( VectorObject * ) attr )->vec[0] = self->bone->loc[0];
// ( ( VectorObject * ) attr )->vec[1] = self->bone->loc[1];
@@ -847,19 +792,17 @@ static PyObject *Bone_getLoc( BPy_Bone * self )
static PyObject *Bone_getSize( BPy_Bone * self )
{
PyObject *attr = NULL;
- float *vec;
+ float vec[3];
int x;
if( !self->bone ) { //test to see if linked to armature
//use python vars
- vec = PyMem_Malloc( 3 * sizeof( float ) );
for( x = 0; x < 3; x++ )
vec[x] = self->size->vec[x];
- attr = ( PyObject * ) newVectorObject( vec, 3 );
+ attr = ( PyObject * ) newVectorObject( vec, 3, Py_NEW );
} else {
//use bone datastruct
- attr = newVectorObject( PyMem_Malloc( 3 * sizeof( float ) ),
- 3 );
+ attr = newVectorObject( NULL, 3, Py_NEW );
// ( ( VectorObject * ) attr )->vec[0] = self->bone->size[0];
// ( ( VectorObject * ) attr )->vec[1] = self->bone->size[1];
// ( ( VectorObject * ) attr )->vec[2] = self->bone->size[2];
@@ -875,20 +818,18 @@ static PyObject *Bone_getSize( BPy_Bone * self )
static PyObject *Bone_getQuat( BPy_Bone * self )
{
PyObject *attr = NULL;
- float *quat;
+ float quat[4];
int x;
if( !self->bone ) { //test to see if linked to armature
//use python vars - p.s. - you must return a copy or else
//python will trash the internal var
- quat = PyMem_Malloc( 4 * sizeof( float ) );
for( x = 0; x < 4; x++ )
quat[x] = self->quat->quat[x];
- attr = ( PyObject * ) newQuaternionObject( quat );
+ attr = ( PyObject * ) newQuaternionObject( quat, Py_NEW );
} else {
//use bone datastruct
- attr = newQuaternionObject( PyMem_Malloc
- ( 4 * sizeof( float ) ) );
+ attr = newQuaternionObject( NULL, Py_NEW );
// ( ( QuaternionObject * ) attr )->quat[0] = self->bone->quat[0];
// ( ( QuaternionObject * ) attr )->quat[1] = self->bone->quat[1];
// ( ( QuaternionObject * ) attr )->quat[2] = self->bone->quat[2];
@@ -1697,7 +1638,7 @@ static PyObject *Bone_getRestMatrix( BPy_Bone * self, PyObject * args )
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
"expected 'bonespace' or 'worldspace'" ) );
- matrix = newMatrixObject( PyMem_Malloc( 16 * sizeof( float ) ), 4, 4 );
+ matrix = newMatrixObject( NULL, 4, 4 , Py_NEW);
if( !self->bone ) { //test to see if linked to armature
//use python vars