diff options
author | Toni Alatalo <antont@kyperjokki.fi> | 2006-02-08 19:58:12 +0300 |
---|---|---|
committer | Toni Alatalo <antont@kyperjokki.fi> | 2006-02-08 19:58:12 +0300 |
commit | a3d0d456ac84279beffb08da2056a718448639a2 (patch) | |
tree | 407f32cfdca184c9ec3e47f9fed9de00d6315e51 | |
parent | 839b338be35dd11d30231d1dee1a3454b952ab55 (diff) |
More things for easying the job of replacing proxy/working armatures in the scenes of Elephants Dream with the final ones: 1) adds removing Fakeusers from Actions to PyAPI, now with a hackish call in the Blender module. Possibility of better ways should be discussed on bf-python. 2) adds BPY Object.copyNLA(otherob) - that was simple 'cause the copy_nla function was nicely in kernel nla.c. 3) Object.convertActionToStrip(), here it gets tricky: the function to convert the active action of an object to a NLA strip was buried inside the respective function in the GUI editnla.c which had also code for reading mouse coordinates and whatnot. So I took the actual copying out of it and moved it to the kernel nla.c as a new function, bActionStrip *convert_action_to_strip (Object *ob). that code used other functions, of which find_stridechannel() was also in editnla.c but free of UI code so i moved it to kernel too. kept things with UI code in editnla.c. tried to be careful with keeping mallocs and the pointer business intact, and tested that this works and after usage Blender gives no memory warnings or anything, so seems ok - but certainly is best reviewed by ppl more active with c coding than me. hopefully this little refactor makes it possible to add this function to the menus too, which was not straightforward earlier when Matt took a look at it.
-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; |