[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [12399] trunk/blender/source/blender/ python/api2_2x: ==Python API==
Campbell Barton
cbarton at metavr.com
Fri Oct 26 10:19:41 CEST 2007
Revision: 12399
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=12399
Author: campbellbarton
Date: 2007-10-26 10:19:40 +0200 (Fri, 26 Oct 2007)
Log Message:
-----------
==Python API==
layerMask access for bone and armatures
Window.PoseMode() similar to Window.EditMode()
Modified Paths:
--------------
trunk/blender/source/blender/python/api2_2x/Armature.c
trunk/blender/source/blender/python/api2_2x/Bone.c
trunk/blender/source/blender/python/api2_2x/Bone.h
trunk/blender/source/blender/python/api2_2x/Window.c
trunk/blender/source/blender/python/api2_2x/doc/Armature.py
trunk/blender/source/blender/python/api2_2x/doc/Window.py
Modified: trunk/blender/source/blender/python/api2_2x/Armature.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Armature.c 2007-10-25 23:10:42 UTC (rev 12398)
+++ trunk/blender/source/blender/python/api2_2x/Armature.c 2007-10-26 08:19:40 UTC (rev 12399)
@@ -297,10 +297,8 @@
editbone->zwidth = ((BPy_EditBone*)value)->zwidth;
VECCOPY(editbone->head, ((BPy_EditBone*)value)->head);
VECCOPY(editbone->tail, ((BPy_EditBone*)value)->tail);
+ editbone->layer= ((BPy_EditBone*)value)->layer;
- // FIXME, should be exposed via python. this avoids creating bones with no layers.
- editbone->layer= 1;
-
//set object pointer
((BPy_EditBone*)value)->editbone = editbone;
@@ -927,6 +925,36 @@
return EXPP_intError(PyExc_AttributeError, "%s%s",
sArmatureError, "You are not allowed to change the .Bones attribute");
}
+
+//------------------------Bone.layerMask (get)
+static PyObject *Armature_getLayerMask(BPy_Armature *self)
+{
+ /* do this extra stuff because the short's bits can be negative values */
+ unsigned short laymask = 0;
+ laymask |= self->armature->layer;
+ return PyInt_FromLong((int)laymask);
+}
+//------------------------Bone.layerMask (set)
+static int Armature_setLayerMask(BPy_Armature *self, PyObject *value)
+{
+ int laymask;
+ if (!PyInt_Check(value)) {
+ return EXPP_ReturnIntError( PyExc_AttributeError,
+ "expected an integer (bitmask) as argument" );
+ }
+
+ laymask = PyInt_AsLong(value);
+
+ if (laymask <= 0 || laymask > (1<<16) - 1)
+ return EXPP_ReturnIntError( PyExc_AttributeError,
+ "bitmask must have from 1 up to 16 bits set");
+
+ self->armature->layer = 0;
+ self->armature->layer |= laymask;
+
+ return 0;
+}
+
//------------------TYPE_OBECT IMPLEMENTATION--------------------------
//------------------------tp_doc
//The __doc__ string for this object
@@ -974,6 +1002,8 @@
"Adds temporal IK chains while grabbing bones", NULL},
{"layers", (getter)Armature_getLayers, (setter)Armature_setLayers,
"List of layers for the armature", NULL},
+ {"layerMask", (getter)Armature_getLayerMask, (setter)Armature_setLayerMask,
+ "Layer bitmask", NULL },
{NULL, NULL, NULL, NULL, NULL}
};
//------------------------tp_new
Modified: trunk/blender/source/blender/python/api2_2x/Bone.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Bone.c 2007-10-25 23:10:42 UTC (rev 12398)
+++ trunk/blender/source/blender/python/api2_2x/Bone.c 2007-10-26 08:19:40 UTC (rev 12399)
@@ -709,7 +709,41 @@
sEditBoneError, ".tailRadius: ", "expects a float");
}
+//------------------------Bone.layerMask (get)
+static PyObject *EditBone_getLayerMask(BPy_EditBone *self)
+{
+ /* do this extra stuff because the short's bits can be negative values */
+ unsigned short laymask = 0;
+ if (self->editbone) laymask |= self->editbone->layer;
+ else laymask |= self->layer;
+ return PyInt_FromLong((int)laymask);
+}
+//------------------------Bone.layerMask (set)
+static int EditBone_setLayerMask(BPy_EditBone *self, PyObject *value)
+{
+ int laymask;
+ if (!PyInt_Check(value)) {
+ return EXPP_ReturnIntError( PyExc_AttributeError,
+ "expected an integer (bitmask) as argument" );
+ }
+
+ laymask = PyInt_AsLong(value);
+ if (laymask <= 0 || laymask > (1<<16) - 1)
+ return EXPP_ReturnIntError( PyExc_AttributeError,
+ "bitmask must have from 1 up to 16 bits set");
+
+ if (self->editbone) {
+ self->editbone->layer = 0;
+ self->editbone->layer |= laymask;
+ } else {
+ self->layer = 0;
+ self->layer |= laymask;
+ }
+
+ return 0;
+}
+
//------------------TYPE_OBECT IMPLEMENTATION--------------------------
//------------------------tp_methods
//This contains a list of all methods the object contains
@@ -749,6 +783,8 @@
"Set the radius of this bones tip", NULL},
{"headRadius", (getter)EditBone_getHeadRadius, (setter)EditBone_setHeadRadius,
"Set the radius of this bones head", NULL},
+ {"layerMask", (getter)EditBone_getLayerMask, (setter)EditBone_setLayerMask,
+ "Layer bitmask", NULL },
{NULL, NULL, NULL, NULL,NULL}
};
@@ -803,6 +839,7 @@
py_editBone->rad_head= 0.10f;
py_editBone->rad_tail= 0.05f;
py_editBone->segments= 1;
+ py_editBone->layer= 1;
py_editBone->flag = 0;
py_editBone->roll = 0.0f;
@@ -1203,6 +1240,35 @@
sEditBoneError, ".headRadius: ", "expects a float");
}
+//------------------------Bone.layerMask (get)
+static PyObject *Bone_getLayerMask(BPy_Bone *self)
+{
+ /* do this extra stuff because the short's bits can be negative values */
+ unsigned short laymask = 0;
+ laymask |= self->bone->layer;
+ return PyInt_FromLong((int)laymask);
+}
+//------------------------Bone.layerMask (set)
+static int Bone_setLayerMask(BPy_Bone *self, PyObject *value)
+{
+ int laymask;
+ if (!PyInt_Check(value)) {
+ return EXPP_ReturnIntError( PyExc_AttributeError,
+ "expected an integer (bitmask) as argument" );
+ }
+
+ laymask = PyInt_AsLong(value);
+
+ if (laymask <= 0 || laymask > (1<<16) - 1)
+ return EXPP_ReturnIntError( PyExc_AttributeError,
+ "bitmask must have from 1 up to 16 bits set");
+
+ self->bone->layer = 0;
+ self->bone->layer |= laymask;
+
+ return 0;
+}
+
//------------------TYPE_OBECT IMPLEMENTATION--------------------------
//------------------------tp_methods
//This contains a list of all methods the object contains
@@ -1246,6 +1312,8 @@
"Set the radius of this bones tip", NULL},
{"headRadius", (getter)Bone_getHeadRadius, (setter)Bone_setHeadRadius,
"Set the radius of this bones head", NULL},
+ {"layerMask", (getter)Bone_getLayerMask, (setter)Bone_setLayerMask,
+ "Layer bitmask", NULL },
{NULL, NULL, NULL, NULL,NULL}
};
//------------------------tp_repr
Modified: trunk/blender/source/blender/python/api2_2x/Bone.h
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Bone.h 2007-10-25 23:10:42 UTC (rev 12398)
+++ trunk/blender/source/blender/python/api2_2x/Bone.h 2007-10-26 08:19:40 UTC (rev 12399)
@@ -65,6 +65,7 @@
float rad_head;
float rad_tail;
short segments;
+ short layer;
} BPy_EditBone;
/*-------------------VISIBLE PROTOTYPES-------------------------*/
PyObject *PyBone_FromBone(struct Bone *bone);
Modified: trunk/blender/source/blender/python/api2_2x/Window.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Window.c 2007-10-25 23:10:42 UTC (rev 12398)
+++ trunk/blender/source/blender/python/api2_2x/Window.c 2007-10-26 08:19:40 UTC (rev 12399)
@@ -86,6 +86,7 @@
static PyObject *M_Window_FileSelector( PyObject * self, PyObject * args );
static PyObject *M_Window_ImageSelector( PyObject * self, PyObject * args );
static PyObject *M_Window_EditMode( PyObject * self, PyObject * args );
+static PyObject *M_Window_PoseMode( PyObject * self, PyObject * args );
static PyObject *M_Window_ViewLayers( PyObject * self, PyObject * args );
static PyObject *M_Window_CameraView( PyObject * self, PyObject * args );
static PyObject *M_Window_QTest( PyObject * self );
@@ -180,6 +181,9 @@
edit mode before applying changes to a mesh (otherwise the changes will\n\
be lost) and then returning to it upon leaving.";
+static char M_Window_PoseMode_doc[] =
+ "() - Get the current status -- 0: not in pose mode; 1: in edit mode";
+
static char M_Window_ViewLayers_doc[] =
"(layers = [], winid = None) - Get/set active layers in all 3d View windows.\n\
() - Make no changes, only return currently visible layers.\n\
@@ -325,6 +329,8 @@
M_Window_GetPerspMatrix_doc},
{"EditMode", ( PyCFunction ) M_Window_EditMode, METH_VARARGS,
M_Window_EditMode_doc},
+ {"PoseMode", ( PyCFunction ) M_Window_PoseMode, METH_VARARGS,
+ M_Window_PoseMode_doc},
{"ViewLayers", ( PyCFunction ) M_Window_ViewLayers, METH_VARARGS,
M_Window_ViewLayers_doc},
/* typo, deprecate someday: */
@@ -949,6 +955,32 @@
return Py_BuildValue( "h", G.obedit ? 1 : 0 );
}
+static PyObject *M_Window_PoseMode( PyObject * self, PyObject * args )
+{
+ short status = -1;
+ short is_posemode = 0;
+ Base *base;
+
+ if( !PyArg_ParseTuple( args, "|h", &status ) )
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "expected optional int (bool) as argument" );
+
+ if( status >= 0 ) {
+ if( status ) {
+ enter_posemode();
+ } else if( G.obedit ) {
+ exit_posemode();
+ }
+ }
+
+ base= BASACT;
+ if (base && base->object->flag & OB_POSEMODE) {
+ is_posemode = 1;
+ }
+
+ return Py_BuildValue( "h", is_posemode );
+}
+
static PyObject *M_Window_ViewLayers( PyObject * self, PyObject * args )
{
PyObject *item = NULL;
Modified: trunk/blender/source/blender/python/api2_2x/doc/Armature.py
===================================================================
--- trunk/blender/source/blender/python/api2_2x/doc/Armature.py 2007-10-25 23:10:42 UTC (rev 12398)
+++ trunk/blender/source/blender/python/api2_2x/doc/Armature.py 2007-10-26 08:19:40 UTC (rev 12399)
@@ -156,6 +156,11 @@
@type mirrorEdit: Bool
@ivar autoIK: Adds temporary IK chains while grabbing bones
@type autoIK: Bool
+ @ivar layerMask: Layer bitmask
+ Example::
+ # set armature to layers 14 and 16
+ armature.layerMask = (1<<13) + (1<<15)
+ @type layerMask: Int
"""
def __init__(name = 'myArmature'):
@@ -282,6 +287,11 @@
@type headRadius: Float
@ivar tailRadius: The radius of this bones head (used for envalope bones)
@type tailRadius: Float
+ @ivar layerMask: Layer bitmask
+ Example::
+ # set bone to layers 14 and 16
+ bone.layerMask = (1<<13) + (1<<15)
+ @type layerMask: Int
"""
def hasParent():
Modified: trunk/blender/source/blender/python/api2_2x/doc/Window.py
===================================================================
--- trunk/blender/source/blender/python/api2_2x/doc/Window.py 2007-10-25 23:10:42 UTC (rev 12398)
+++ trunk/blender/source/blender/python/api2_2x/doc/Window.py 2007-10-26 08:19:40 UTC (rev 12399)
@@ -284,6 +284,20 @@
because the normal mesh will be rebuilt based on its unchanged edit mesh.
"""
+def PoseMode(enable = -1):
+ """
+ Get and optionally set the current pose mode status: in or out.
+ @type enable: int
+ @param enable: get/set current status:
+ - -1: just return current status (default);
+ - 0: leave edit mode;
+ - 1: enter edit mode.
+
+ @return: 0 if Blender is not in edit mode right now, 1 otherwise.
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list