Adding an option for action actuator - "Continue" this means animations always play from where they left off. Continue was the 2.46 operation too, so new functionality is the option to disable.

When using states, an action like kick or throw can often switch out before finishing playing the action, and there was no way to play from the start frame the second time round. (even setting the actions current frame through python doesn't work work)
This commit is contained in:
Campbell Barton 2008-07-10 14:23:19 +00:00
parent 99fdf27af9
commit 310a37c29c
6 changed files with 65 additions and 13 deletions

@ -51,8 +51,9 @@ typedef struct bActionActuator {
int sta, end; /* Start & End frames */
char name[32]; /* For property-driven playback */
char frameProp[32]; /* Set this property to the actions current frame */
int blendin; /* Number of frames of blending */
short priority; /* Execution priority */
short blendin; /* Number of frames of blending */
short priority; /* Execution priority */
short end_reset; /* Ending the actuator (negative pulse) wont reset the the action to its starting frame */
short strideaxis; /* Displacement axis */
float stridelength; /* Displacement incurred by cycle */
} bActionActuator;

@ -1769,23 +1769,27 @@ static short draw_actuatorbuttons(Object *ob, bActuator *act, uiBlock *block, sh
#else
str= "Action types %t|Play %x0|Flipper %x2|Loop Stop %x3|Loop End %x4|Property %x6";
#endif
uiDefButS(block, MENU, B_REDR, str, xco+30, yco-24, (width-60)/2, 19, &aa->type, 0.0, 0.0, 0.0, 0.0, "Action playback type");
uiDefIDPoinBut(block, test_actionpoin_but, ID_AC, 1, "AC: ", xco+30 + ((width-60)/2), yco-24, (width-60)/2, 19, &aa->act, "Action name");
uiDefButS(block, MENU, B_REDR, str, xco+10, yco-24, width/3, 19, &aa->type, 0.0, 0.0, 0.0, 0.0, "Action playback type");
uiDefIDPoinBut(block, test_actionpoin_but, ID_AC, 1, "AC: ", xco+10+ (width/3), yco-24, ((width/3)*2) - (20 + 60), 19, &aa->act, "Action name");
uiDefButBitS(block, TOGN, 1, 0, "Continue", xco+((width/3)*2)+20, yco-24, 60, 19,
&aa->end_reset, 0.0, 0.0, 0, 0, "Restore last frame when switching on/off, otherwise play from the start each time");
if(aa->type == ACT_ACTION_FROM_PROP)
{
uiDefBut(block, TEX, 0, "Prop: ",xco+30, yco-44, width-60, 19, aa->name, 0.0, 31.0, 0, 0, "Use this property to define the Action position");
uiDefBut(block, TEX, 0, "Prop: ",xco+10, yco-44, width-20, 19, aa->name, 0.0, 31.0, 0, 0, "Use this property to define the Action position");
}
else
{
uiDefButI(block, NUM, 0, "Sta: ",xco+30, yco-44, (width-60)/2, 19, &aa->sta, 0.0, MAXFRAMEF, 0, 0, "Start frame");
uiDefButI(block, NUM, 0, "End: ",xco+30+(width-60)/2, yco-44, (width-60)/2, 19, &aa->end, 0.0, MAXFRAMEF, 0, 0, "End frame");
uiDefButI(block, NUM, 0, "Sta: ",xco+10, yco-44, (width-20)/2, 19, &aa->sta, 0.0, MAXFRAMEF, 0, 0, "Start frame");
uiDefButI(block, NUM, 0, "End: ",xco+10+(width-20)/2, yco-44, (width-20)/2, 19, &aa->end, 0.0, MAXFRAMEF, 0, 0, "End frame");
}
uiDefButI(block, NUM, 0, "Blendin: ", xco+30, yco-64, (width-60)/2, 19, &aa->blendin, 0.0, MAXFRAMEF, 0.0, 0.0, "Number of frames of motion blending");
uiDefButS(block, NUM, 0, "Priority: ", xco+30+(width-60)/2, yco-64, (width-60)/2, 19, &aa->priority, 0.0, 100.0, 0.0, 0.0, "Execution priority - lower numbers will override actions with higher numbers, With 2 or more actions at once, the overriding channels must be lower in the stack");
uiDefButS(block, NUM, 0, "Blendin: ", xco+10, yco-64, (width-20)/2, 19, &aa->blendin, 0.0, 32767, 0.0, 0.0, "Number of frames of motion blending");
uiDefButS(block, NUM, 0, "Priority: ", xco+10+(width-20)/2, yco-64, (width-20)/2, 19, &aa->priority, 0.0, 100.0, 0.0, 0.0, "Execution priority - lower numbers will override actions with higher numbers, With 2 or more actions at once, the overriding channels must be lower in the stack");
uiDefBut(block, TEX, 0, "FrameProp: ",xco+30, yco-84, width-60, 19, aa->frameProp, 0.0, 31.0, 0, 0, "Assign this property this actions current frame number");
uiDefBut(block, TEX, 0, "FrameProp: ",xco+10, yco-84, width-20, 19, aa->frameProp, 0.0, 31.0, 0, 0, "Assign this property this actions current frame number");
#ifdef __NLA_ACTION_BY_MOTION_ACTUATOR

@ -184,6 +184,11 @@ bool BL_ActionActuator::Update(double curtime, bool frame)
if (bNegativeEvent)
{
// dont continue where we left off when restarting
if (m_end_reset) {
m_flag &= ~ACT_FLAG_LOCKINPUT;
}
if (!(m_flag & ACT_FLAG_ACTIVE))
return false;
m_flag &= ~ACT_FLAG_ACTIVE;
@ -472,8 +477,10 @@ PyMethodDef BL_ActionActuator::Methods[] = {
{"getFrameProperty", (PyCFunction) BL_ActionActuator::sPyGetFrameProperty, METH_VARARGS, GetFrameProperty_doc},
{"setChannel", (PyCFunction) BL_ActionActuator::sPySetChannel, METH_VARARGS, SetChannel_doc},
// {"getChannel", (PyCFunction) BL_ActionActuator::sPyGetChannel, METH_VARARGS},
{"getType", (PyCFunction) BL_ActionActuator::sPyGetType, METH_VARARGS, GetType_doc},
{"getType", (PyCFunction) BL_ActionActuator::sPyGetType, METH_VARARGS, GetType_doc},
{"setType", (PyCFunction) BL_ActionActuator::sPySetType, METH_VARARGS, SetType_doc},
{"getContinue", (PyCFunction) BL_ActionActuator::sPyGetContinue, METH_NOARGS, 0},
{"setContinue", (PyCFunction) BL_ActionActuator::sPySetContinue, METH_O, 0},
{NULL,NULL} //Sentinel
};
@ -978,7 +985,26 @@ PyObject* BL_ActionActuator::PySetType(PyObject* self,
default:
printf("Invalid type for action actuator: %d\n", typeArg); /* error */
}
Py_Return;
Py_RETURN_NONE;
}
PyObject* BL_ActionActuator::PyGetContinue(PyObject* self) {
return PyInt_FromLong((long)(m_end_reset==0));
}
PyObject* BL_ActionActuator::PySetContinue(PyObject* self, PyObject* value) {
int param = PyObject_IsTrue( value );
if( param == -1 ) {
PyErr_SetString( PyExc_TypeError, "expected True/False or 0/1" );
return NULL;
}
if (param) {
m_end_reset = 0;
} else {
m_end_reset = 1;
}
Py_RETURN_NONE;
}

@ -47,6 +47,7 @@ public:
short playtype,
short blendin,
short priority,
short end_reset,
float stride,
PyTypeObject* T=&Type)
: SCA_IActuator(gameobj,T),
@ -64,6 +65,7 @@ public:
m_stridelength(stride),
m_playtype(playtype),
m_priority(priority),
m_end_reset(end_reset),
m_pose(NULL),
m_blendpose(NULL),
m_userpose(NULL),
@ -101,6 +103,8 @@ public:
// KX_PYMETHOD(BL_ActionActuator,GetChannel);
KX_PYMETHOD_DOC(BL_ActionActuator,GetType);
KX_PYMETHOD_DOC(BL_ActionActuator,SetType);
KX_PYMETHOD_NOARGS(BL_ActionActuator,GetContinue);
KX_PYMETHOD_O(BL_ActionActuator,SetContinue);
virtual PyObject* _getattr(const STR_String& attr);
@ -137,6 +141,7 @@ protected:
float m_stridelength;
short m_playtype;
short m_priority;
short m_end_reset;
struct bPose* m_pose;
struct bPose* m_blendpose;
struct bPose* m_userpose;

@ -193,6 +193,7 @@ void BL_ConvertActuators(char* maggiename,
actact->type, // + 1, because Blender starts to count at zero,
actact->blendin,
actact->priority,
actact->end_reset,
actact->stridelength
// Ketsji at 1, because zero is reserved for "NoDef"
);

@ -86,6 +86,14 @@ class BL_ActionActuator(SCA_IActuator):
@param mode: KX_ACTIONACT_PLAY, KX_ACTIONACT_PROPERTY, KX_ACTIONACT_FLIPPER, KX_ACTIONACT_LOOPSTOP, KX_ACTIONACT_LOOPEND
@type mode: integer
"""
def setContinue(cont):
"""
Set the actions continue option True or False. see getContinue.
@param cont: The continue option.
@type cont: bool
"""
def getType():
"""
@ -94,6 +102,13 @@ class BL_ActionActuator(SCA_IActuator):
@rtype: integer
@return: KX_ACTIONACT_PLAY, KX_ACTIONACT_PROPERTY, KX_ACTIONACT_FLIPPER, KX_ACTIONACT_LOOPSTOP, KX_ACTIONACT_LOOPEND
"""
def getContinue():
"""
When True, the action will always play from where last left off, otherwise negative events to this actuator will reset it to its start frame.
@rtype: bool
"""
def getAction():
"""