*armature api for python

- don't get too excited
- allows you to get armatures from a scene
- makeEditable()/saveChanges() puts the armature into out of editmode (pythonically)
- Armature.bones is a dictionary that contains all the bones in the armature and can be iterated
- getters are available for:
name,
roll (dictionary) keys are BONESPACE, ARMATURESPACE
head (dictionary) keys are BONESPACE, ARMATURESPACE
tail (dictionary) keys are BONESPACE, ARMATURESPACE
matrix (dictionary) keys are BONESPACE, ARMATURESPACE
weight
deform_dist
subdivisions
options (list of constants)
parent
children

Setter work only in editmode. Some are not fully implemented.
Type class is embedded in the module. This means the construct is called as follows:
Blender.Armature.ArmatureType()

import Blender.Armature as Armature
arm = Armature.Get('myarm')
for name, bone in arm.bones.items():
...print name, bone, bone.matrix['ARMATURESPACE']

more documentation is forth coming. This is an alpha for this api.
This commit is contained in:
2005-11-07 20:03:32 +00:00
parent a39559ea11
commit f09a3611be
5 changed files with 1705 additions and 2177 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -23,9 +23,7 @@
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* This is a new part of Blender.
*
* Contributor(s): Jordi Rovira i Bonet, Joseph gilbert
* Contributor(s): Joseph gilbert
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
@@ -36,18 +34,31 @@
#include <Python.h>
#include "DNA_armature_types.h"
//---------------------Python BPy_Armature structure definition-------
//-------------------TYPE CHECKS---------------------------------
#define ArmatureObject_Check(v) ((v)->ob_type == &Armature_Type)
#define BonesDictObject_Check(v) ((v)->ob_type == &BonesDict_Type)
//-------------------MODULE INIT---------------------------------
PyObject *Armature_Init( void );
//-------------------TYPEOBJECT----------------------------------
PyTypeObject Armature_Type;
PyTypeObject BonesDict_Type;
//-------------------STRUCT DEFINITION---------------------------
typedef struct {
PyObject_HEAD
bArmature * armature;
PyObject *dict;
PyObject *editBoneDict;
short editmode_flag; //1 = in , 0 = not in
} BPy_BonesDict;
typedef struct {
PyObject_HEAD
struct bArmature * armature;
PyObject *Bones;
} BPy_Armature;
//--------------------visible prototypes------------------------------
//-------------------VISIBLE PROTOTYPES-------------------------
PyObject *PyArmature_FromArmature(struct bArmature *armature);
struct bArmature *PyArmature_AsArmature(BPy_Armature *py_armature);
PyObject *Armature_Init( void );
PyObject *Armature_CreatePyObject( bArmature * armature );
bArmature *Armature_FromPyObject( PyObject * py_obj );
int Armature_CheckPyObject( PyObject * py_obj );
#endif /* EXPP_ARMATURE_H */
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -23,9 +23,7 @@
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* This is a new part of Blender.
*
* Contributor(s): Jordi Rovira i Bonet, Joseph Gilbert
* Contributor(s): Joseph Gilbert
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
@@ -33,6 +31,75 @@
#ifndef EXPP_BONE_H
#define EXPP_BONE_H
#include <Python.h>
#include "DNA_armature_types.h"
//-------------------TYPE CHECKS---------------------------------
#define BoneObject_Check(v) ((v)->ob_type == &Bone_Type)
#define EditBoneObject_Check(v) ((v)->ob_type == &EditBone_Type)
//-------------------TYPEOBJECT----------------------------------
PyTypeObject EditBone_Type;
PyTypeObject Bone_Type;
//-------------------STRUCT DEFINITION----------------------------
typedef struct {
PyObject_HEAD
Bone * bone;
} BPy_Bone;
typedef struct {
PyObject_HEAD
struct Bone *temp; //temp tracking
char parent[32];
char name[32];
float roll;
float head[3];
float tail[3];
int flag;
float length;
float dist;
float weight;
float xwidth;
float zwidth;
float ease1;
float ease2;
float rad_head;
float rad_tail;
short segments;
} BPy_EditBone;
//-------------------VISIBLE PROTOTYPES-------------------------
PyObject *PyBone_FromBone(struct Bone *bone);
struct Bone *PyBone_AsBone(BPy_Bone *py_Bone);
#endif
/*
#ifndef EXPP_BONE_H
#define EXPP_BONE_H
#include <Python.h>
#include "DNA_armature_types.h"
#include "Mathutils.h"
@@ -73,3 +140,5 @@ PyObject *Bone_Init( void );
int updateBoneData( BPy_Bone * self, Bone * parent );
#endif
*/

View File

@@ -638,7 +638,6 @@ PyObject *M_Object_New( PyObject * self, PyObject * args )
}
object = alloc_libblock( &( G.main->object ), ID_OB, name );
object->id.us = 0;
object->flag = 0;
object->type = (short)type;
@@ -724,6 +723,7 @@ PyObject *M_Object_Get( PyObject * self, PyObject * args )
( BPy_Object * ) PyObject_NEW( BPy_Object,
&Object_Type );
blen_object->object = object;
object->id.us++;
return ( ( PyObject * ) blen_object );
} else {
@@ -747,6 +747,7 @@ PyObject *M_Object_Get( PyObject * self, PyObject * args )
( BPy_Object * ) PyObject_NEW( BPy_Object,
&Object_Type );
blen_object->object = object;
object->id.us++;
PyList_SetItem( obj_list, index,
( PyObject * ) blen_object );
@@ -1022,7 +1023,7 @@ static PyObject *Object_getData( BPy_Object *self, PyObject *args, PyObject *kwd
switch ( object->type ) {
case OB_ARMATURE:
data_object = Armature_CreatePyObject( object->data );
data_object = PyArmature_FromArmature( object->data );
break;
case OB_CAMERA:
data_object = Camera_CreatePyObject( object->data );
@@ -1479,10 +1480,9 @@ static PyObject *Object_link( BPy_Object * self, PyObject * args )
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
"expected an object as argument" ) );
}
if( Armature_CheckPyObject( py_data ) )
data = ( void * ) Armature_FromPyObject( py_data );
else if( Camera_CheckPyObject( py_data ) )
if( ArmatureObject_Check( py_data ) )
data = ( void * ) PyArmature_AsArmature((BPy_Armature*)py_data);
if( Camera_CheckPyObject( py_data ) )
data = ( void * ) Camera_FromPyObject( py_data );
else if( Lamp_CheckPyObject( py_data ) )
data = ( void * ) Lamp_FromPyObject( py_data );
@@ -2594,6 +2594,7 @@ PyObject *Object_CreatePyObject( struct Object * obj )
return ( NULL );
}
blen_object->object = obj;
obj->id.us++;
return ( ( PyObject * ) blen_object );
}
@@ -2651,6 +2652,7 @@ Object *GetObjectByName( char *name )
/*****************************************************************************/
static void Object_dealloc( BPy_Object * obj )
{
obj->object->id.us--;
PyObject_DEL( obj );
}