diff options
-rw-r--r-- | source/blender/blenkernel/BKE_nla.h | 6 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/nla.c | 45 | ||||
-rw-r--r-- | source/blender/python/api2_2x/Blender.c | 39 | ||||
-rw-r--r-- | source/blender/python/api2_2x/Object.c | 28 | ||||
-rw-r--r-- | source/blender/src/editnla.c | 38 |
5 files changed, 116 insertions, 40 deletions
diff --git a/source/blender/blenkernel/BKE_nla.h b/source/blender/blenkernel/BKE_nla.h index 9ac6b6ff3af..560e5d5c33c 100644 --- a/source/blender/blenkernel/BKE_nla.h +++ b/source/blender/blenkernel/BKE_nla.h @@ -35,11 +35,13 @@ struct bActionStrip; struct ListBase; +struct Object; -void free_actionstrip(struct bActionStrip* strip); +void free_actionstrip (struct bActionStrip* strip); void free_nlastrips (struct ListBase *nlalist); void copy_nlastrips (struct ListBase *dst, struct ListBase *src); void copy_actionstrip (struct bActionStrip **dst, struct bActionStrip **src); - +void find_stridechannel(struct Object *ob, struct bActionStrip *strip); +struct bActionStrip *convert_action_to_strip (struct Object *ob); #endif diff --git a/source/blender/blenkernel/intern/nla.c b/source/blender/blenkernel/intern/nla.c index 5fefc41f77c..100f2bb5d72 100644 --- a/source/blender/blenkernel/intern/nla.c +++ b/source/blender/blenkernel/intern/nla.c @@ -40,7 +40,9 @@ #include "DNA_action_types.h" #include "DNA_ID.h" #include "DNA_ipo_types.h" +#include "DNA_object_types.h" #include "MEM_guardedalloc.h" +#include "BKE_object.h" /* for convert_action_to_strip(ob) */ #ifdef HAVE_CONFIG_H #include <config.h> @@ -88,6 +90,49 @@ void copy_nlastrips (ListBase *dst, ListBase *src) } } +/* from editnla, for convert_action_to_strip -- no UI code so should be ok here.. */ +void find_stridechannel(Object *ob, bActionStrip *strip) +{ + if(ob && ob->pose) { + bPoseChannel *pchan; + for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) + if(pchan->flag & POSE_STRIDE) + break; + if(pchan) + BLI_strncpy(strip->stridechannel, pchan->name, 32); + else + strip->stridechannel[0]= 0; + } +} + +//called by convert_nla / bpy api with an object with the action to be converted to a new strip +bActionStrip *convert_action_to_strip (Object *ob) +{ + bActionStrip *nstrip; + + /* Make new actionstrip */ + nstrip = MEM_callocN(sizeof(bActionStrip), "bActionStrip"); + + /* Link the action to the nstrip */ + nstrip->act = ob->action; + id_us_plus(&nstrip->act->id); + calc_action_range(nstrip->act, &nstrip->actstart, &nstrip->actend, 1); + nstrip->start = nstrip->actstart; + nstrip->end = nstrip->actend; + nstrip->flag = ACTSTRIP_SELECT|ACTSTRIP_LOCK_ACTION; + + find_stridechannel(ob, nstrip); + //set_active_strip(ob, nstrip); /* is in editnla as does UI calls */ + + nstrip->repeat = 1.0; + + BLI_addtail(&ob->nlastrips, nstrip); + return nstrip; /* is created, malloced etc. here so is safe to just return the pointer? + this is needed for setting this active in UI, and probably useful for API too */ + +} + + void free_actionstrip(bActionStrip* strip) { diff --git a/source/blender/python/api2_2x/Blender.c b/source/blender/python/api2_2x/Blender.c index 1bbb91fac7f..f91a6604683 100644 --- a/source/blender/python/api2_2x/Blender.c +++ b/source/blender/python/api2_2x/Blender.c @@ -85,7 +85,9 @@ struct ID; /*keep me up here */ #include "Window.h" #include "World.h" - +//for the removefakeuser hack +#include "NLA.h" /*This must come first*/ +#include "BKE_action.h" extern PyObject *bpy_registryDict; /* defined in ../BPY_interface.c */ @@ -100,6 +102,7 @@ static PyObject *Blender_Quit( PyObject * self ); static PyObject *Blender_Load( PyObject * self, PyObject * args ); static PyObject *Blender_Save( PyObject * self, PyObject * args ); static PyObject *Blender_Run( PyObject * self, PyObject * args ); +static PyObject *Blender_RemoveFakeuser(PyObject *self, PyObject *args); static PyObject *Blender_ShowHelp( PyObject * self, PyObject * args ); static PyObject *Blender_UpdateMenus( PyObject * self); @@ -162,6 +165,10 @@ static char Blender_Run_doc[] = "(script) - Run the given Python script.\n\ (script) - the path to a file or the name of an available Blender Text."; +static char Blender_RemoveFakeuser_doc[] = + "(datablock) - remove the fake user from a datablock. useful for deleting actions.\n\ +(datablock) - the datablock that has a fakeuser. currently only action object accepted."; + static char Blender_ShowHelp_doc[] = "(script) - Show help for the given Python script.\n\ This will try to open the 'Scripts Help Browser' script, so to have\n\ @@ -186,6 +193,7 @@ static struct PyMethodDef Blender_methods[] = { {"Load", Blender_Load, METH_VARARGS, Blender_Load_doc}, {"Save", Blender_Save, METH_VARARGS, Blender_Save_doc}, {"Run", Blender_Run, METH_VARARGS, Blender_Run_doc}, + {"RemoveFakeuser", Blender_RemoveFakeuser, METH_VARARGS, Blender_RemoveFakeuser_doc}, {"ShowHelp", Blender_ShowHelp, METH_VARARGS, Blender_ShowHelp_doc}, {"UpdateMenus", ( PyCFunction ) Blender_UpdateMenus, METH_NOARGS, Blender_UpdateMenus_doc}, @@ -764,6 +772,35 @@ static PyObject * Blender_UpdateMenus( PyObject * self ) return Py_None; } +static PyObject *Blender_RemoveFakeuser(PyObject *self, PyObject *args) +{ + ID *id; + BPy_Action *py_thing; //lousy coder antont did not know how to accept any bpy thing with ID.. + + if( !PyArg_ParseTuple( args, "O!", &Action_Type, &py_thing ) ) + return EXPP_ReturnPyObjError( PyExc_AttributeError, + "expected python action type" ); + + id= (ID *)py_thing->action; + + if(id) { + if( id->flag & LIB_FAKEUSER) { + id->flag -= LIB_FAKEUSER; + id->us--; + } + else + return EXPP_ReturnPyObjError( PyExc_AttributeError, + "given datablock has no fakeusers"); + } else + return EXPP_ReturnPyObjError( PyExc_AttributeError, + "given object does not have a Blender ID"); + + Py_INCREF( Py_None ); + return Py_None; +} + + + /*****************************************************************************/ /* Function: initBlender */ /*****************************************************************************/ diff --git a/source/blender/python/api2_2x/Object.c b/source/blender/python/api2_2x/Object.c index fc81bf36976..9c5dfe6fdb6 100644 --- a/source/blender/python/api2_2x/Object.c +++ b/source/blender/python/api2_2x/Object.c @@ -63,6 +63,7 @@ struct rctf; #include "BKE_global.h" #include "BKE_main.h" #include "BKE_scene.h" +#include "BKE_nla.h" #include "BSE_editipo.h" #include "BSE_edit.h" @@ -298,6 +299,9 @@ static PyObject *Object_setSBUseEdges( BPy_Object * self, PyObject * args ); static PyObject *Object_getSBStiffQuads( BPy_Object * self ); static PyObject *Object_setSBStiffQuads( BPy_Object * self, PyObject * args ); static PyObject *Object_insertShapeKey(BPy_Object * self); +static PyObject *Object_copyNLA( BPy_Object * self, PyObject * args ); +static PyObject *Object_convertActionToStrip( BPy_Object * self ); + /*****************************************************************************/ /* Python BPy_Object methods table: */ /*****************************************************************************/ @@ -565,8 +569,11 @@ works only if self and the object specified are of the same type."}, "( ) - creates a new action with the information from object animations"}, {"setConstraintInfluenceForBone", ( PyCFunction ) Object_setConstraintInfluenceForBone, METH_VARARGS, "( ) - sets a constraint influence for a certain bone in this (armature)object."}, - {"getAllProperties", ( PyCFunction ) Object_getAllProperties, - METH_NOARGS, + {"copyNLA", ( PyCFunction ) Object_copyNLA, METH_VARARGS, + "( ) - copies all NLA strips from another object to this object."}, + {"convertActionToStrip", ( PyCFunction ) Object_convertActionToStrip, METH_NOARGS, + "( ) - copies all NLA strips from another object to this object."}, + {"getAllProperties", ( PyCFunction ) Object_getAllProperties, METH_NOARGS, "() - Get all the properties from this object"}, {"addProperty", ( PyCFunction ) Object_addProperty, METH_VARARGS, "() - Add a property to this object"}, @@ -2531,6 +2538,23 @@ static PyObject *Object_setConstraintInfluenceForBone( BPy_Object * self, PyObje return ( Py_None ); } +static PyObject *Object_copyNLA( BPy_Object * self, PyObject * args ) { + BPy_Object *bpy_fromob; + + if( !PyArg_ParseTuple( args, "O", &bpy_fromob ) ) + return ( EXPP_ReturnPyObjError( PyExc_AttributeError, "requires a Blender Object to copy NLA strips from." ) ); + copy_nlastrips(&self->object->nlastrips, &bpy_fromob->object->nlastrips); + + Py_INCREF( Py_None ); + return ( Py_None ); +} + +static PyObject *Object_convertActionToStrip( BPy_Object * self ) { + //when BPY gets a Strip type, make this to return the created strip. + convert_action_to_strip(self->object); + return EXPP_incr_ret_True (); //figured that True is closer to a Strip than None.. +} + static PyObject *Object_setLocation( BPy_Object * self, PyObject * args ) { float loc1; diff --git a/source/blender/src/editnla.c b/source/blender/src/editnla.c index 3a2a1d0d21c..76c48657815 100644 --- a/source/blender/src/editnla.c +++ b/source/blender/src/editnla.c @@ -276,20 +276,6 @@ static void set_active_strip(Object *ob, bActionStrip *act) } } -static void find_stridechannel(Object *ob, bActionStrip *strip) -{ - if(ob && ob->pose) { - bPoseChannel *pchan; - for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) - if(pchan->flag & POSE_STRIDE) - break; - if(pchan) - BLI_strncpy(strip->stridechannel, pchan->name, 32); - else - strip->stridechannel[0]= 0; - } -} - static void convert_nla(short mval[2]) { bActionStrip *strip, *nstrip; @@ -343,32 +329,14 @@ static void convert_nla(short mval[2]) switch (event){ case 1: - if (base->object->action){ - /* Make new actionstrip */ - nstrip = MEM_callocN(sizeof(bActionStrip), "bActionStrip"); - + if (base->object->action) { deselect_nlachannel_keys(0); - - /* Link the action to the nstrip */ - nstrip->act = base->object->action; - id_us_plus(&nstrip->act->id); - calc_action_range(nstrip->act, &nstrip->actstart, &nstrip->actend, 1); - nstrip->start = nstrip->actstart; - nstrip->end = nstrip->actend; - nstrip->flag = ACTSTRIP_SELECT|ACTSTRIP_LOCK_ACTION; - - find_stridechannel(base->object, nstrip); + nstrip = convert_action_to_strip(base->object); //creates a new NLA strip from the action in given object set_active_strip(base->object, nstrip); - - nstrip->repeat = 1.0; - - BLI_addtail(&base->object->nlastrips, nstrip); - BIF_undo_push("Convert NLA"); allqueue (REDRAWNLA, 0); } - - + break; default: break; |