2002-10-12 11:37:38 +00:00
|
|
|
/**
|
|
|
|
* $Id$
|
|
|
|
*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
2008-04-16 22:40:48 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
|
|
|
* Contributor(s): none yet.
|
|
|
|
*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
|
|
|
|
2004-11-23 23:04:30 +00:00
|
|
|
#if defined (__sgi)
|
|
|
|
#include <math.h>
|
|
|
|
#else
|
2004-10-16 11:41:50 +00:00
|
|
|
#include <cmath>
|
2004-11-23 23:04:30 +00:00
|
|
|
#endif
|
2004-10-16 11:41:50 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "SCA_LogicManager.h"
|
|
|
|
#include "BL_ActionActuator.h"
|
|
|
|
#include "BL_ArmatureObject.h"
|
|
|
|
#include "BL_SkinDeformer.h"
|
|
|
|
#include "KX_GameObject.h"
|
|
|
|
#include "STR_HashedString.h"
|
2007-07-19 14:28:57 +00:00
|
|
|
#include "DNA_nla_types.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "BKE_action.h"
|
2009-01-26 08:34:40 +00:00
|
|
|
#include "DNA_action_types.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "DNA_armature_types.h"
|
2009-01-26 08:34:40 +00:00
|
|
|
#include "DNA_scene_types.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
#include "BLI_blenlib.h"
|
2009-11-10 20:43:45 +00:00
|
|
|
#include "BLI_math.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "MT_Matrix4x4.h"
|
|
|
|
#include "BKE_utildefines.h"
|
2008-06-23 15:32:44 +00:00
|
|
|
#include "FloatValue.h"
|
2008-09-06 14:13:31 +00:00
|
|
|
#include "PyObjectPlus.h"
|
2009-06-16 18:25:48 +00:00
|
|
|
#include "KX_PyMath.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2009-06-16 20:38:18 +00:00
|
|
|
extern "C" {
|
|
|
|
#include "BKE_animsys.h"
|
|
|
|
#include "BKE_action.h"
|
|
|
|
#include "RNA_access.h"
|
|
|
|
#include "RNA_define.h"
|
|
|
|
}
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
BL_ActionActuator::~BL_ActionActuator()
|
|
|
|
{
|
2008-07-30 16:15:15 +00:00
|
|
|
if (m_pose)
|
2008-09-17 01:29:54 +00:00
|
|
|
game_free_pose(m_pose);
|
2008-07-30 16:15:15 +00:00
|
|
|
if (m_userpose)
|
2008-09-17 01:29:54 +00:00
|
|
|
game_free_pose(m_userpose);
|
2008-07-30 16:15:15 +00:00
|
|
|
if (m_blendpose)
|
2008-09-17 01:29:54 +00:00
|
|
|
game_free_pose(m_blendpose);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2009-06-08 20:08:19 +00:00
|
|
|
void BL_ActionActuator::ProcessReplica()
|
|
|
|
{
|
|
|
|
SCA_IActuator::ProcessReplica();
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
m_pose = NULL;
|
|
|
|
m_blendpose = NULL;
|
2004-11-06 04:53:41 +00:00
|
|
|
m_localtime=m_startframe;
|
2002-10-12 11:37:38 +00:00
|
|
|
m_lastUpdate=-1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void BL_ActionActuator::SetBlendTime (float newtime){
|
|
|
|
m_blendframe = newtime;
|
|
|
|
}
|
|
|
|
|
|
|
|
CValue* BL_ActionActuator::GetReplica() {
|
|
|
|
BL_ActionActuator* replica = new BL_ActionActuator(*this);//m_float,GetName());
|
|
|
|
replica->ProcessReplica();
|
|
|
|
return replica;
|
2004-11-06 04:53:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool BL_ActionActuator::ClampLocalTime()
|
|
|
|
{
|
|
|
|
if (m_startframe < m_endframe)
|
|
|
|
{
|
|
|
|
if (m_localtime < m_startframe)
|
|
|
|
{
|
|
|
|
m_localtime = m_startframe;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (m_localtime > m_endframe)
|
|
|
|
{
|
|
|
|
m_localtime = m_endframe;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (m_localtime > m_startframe)
|
|
|
|
{
|
|
|
|
m_localtime = m_startframe;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (m_localtime < m_endframe)
|
|
|
|
{
|
|
|
|
m_localtime = m_endframe;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BL_ActionActuator::SetStartTime(float curtime)
|
|
|
|
{
|
|
|
|
float direction = m_startframe < m_endframe ? 1.0 : -1.0;
|
|
|
|
|
|
|
|
if (!(m_flag & ACT_FLAG_REVERSE))
|
2008-06-17 10:06:38 +00:00
|
|
|
m_starttime = curtime - direction*(m_localtime - m_startframe)/KX_KetsjiEngine::GetAnimFrameRate();
|
2004-11-06 04:53:41 +00:00
|
|
|
else
|
2008-06-17 10:06:38 +00:00
|
|
|
m_starttime = curtime - direction*(m_endframe - m_localtime)/KX_KetsjiEngine::GetAnimFrameRate();
|
2004-11-06 04:53:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BL_ActionActuator::SetLocalTime(float curtime)
|
|
|
|
{
|
2008-06-17 10:06:38 +00:00
|
|
|
float delta_time = (curtime - m_starttime)*KX_KetsjiEngine::GetAnimFrameRate();
|
2004-11-06 04:53:41 +00:00
|
|
|
|
|
|
|
if (m_endframe < m_startframe)
|
|
|
|
delta_time = -delta_time;
|
|
|
|
|
|
|
|
if (!(m_flag & ACT_FLAG_REVERSE))
|
|
|
|
m_localtime = m_startframe + delta_time;
|
|
|
|
else
|
|
|
|
m_localtime = m_endframe - delta_time;
|
|
|
|
}
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2004-10-16 11:41:50 +00:00
|
|
|
bool BL_ActionActuator::Update(double curtime, bool frame)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
bool bNegativeEvent = false;
|
|
|
|
bool bPositiveEvent = false;
|
|
|
|
bool keepgoing = true;
|
|
|
|
bool wrap = false;
|
|
|
|
bool apply=true;
|
|
|
|
int priority;
|
|
|
|
float newweight;
|
2008-09-16 21:11:38 +00:00
|
|
|
|
|
|
|
curtime -= KX_KetsjiEngine::GetSuspendedDelta();
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
// result = true if animation has to be continued, false if animation stops
|
|
|
|
// maybe there are events for us in the queue !
|
2004-12-05 02:50:57 +00:00
|
|
|
if (frame)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2009-06-08 20:08:19 +00:00
|
|
|
bNegativeEvent = m_negevent;
|
|
|
|
bPositiveEvent = m_posevent;
|
|
|
|
RemoveAllEvents();
|
2004-12-05 02:50:57 +00:00
|
|
|
|
|
|
|
if (bPositiveEvent)
|
|
|
|
m_flag |= ACT_FLAG_ACTIVE;
|
|
|
|
|
|
|
|
if (bNegativeEvent)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2008-07-10 14:23:19 +00:00
|
|
|
// dont continue where we left off when restarting
|
|
|
|
if (m_end_reset) {
|
|
|
|
m_flag &= ~ACT_FLAG_LOCKINPUT;
|
|
|
|
}
|
|
|
|
|
2004-12-05 02:50:57 +00:00
|
|
|
if (!(m_flag & ACT_FLAG_ACTIVE))
|
|
|
|
return false;
|
|
|
|
m_flag &= ~ACT_FLAG_ACTIVE;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We know that action actuators have been discarded from all non armature objects:
|
|
|
|
if we're being called, we're attached to a BL_ArmatureObject */
|
|
|
|
BL_ArmatureObject *obj = (BL_ArmatureObject*)GetParent();
|
2004-11-06 04:53:41 +00:00
|
|
|
float length = m_endframe - m_startframe;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
priority = m_priority;
|
|
|
|
|
|
|
|
/* Determine pre-incrementation behaviour and set appropriate flags */
|
|
|
|
switch (m_playtype){
|
|
|
|
case ACT_ACTION_MOTION:
|
|
|
|
if (bNegativeEvent){
|
|
|
|
keepgoing=false;
|
|
|
|
apply=false;
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
case ACT_ACTION_FROM_PROP:
|
|
|
|
if (bNegativeEvent){
|
|
|
|
apply=false;
|
|
|
|
keepgoing=false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ACT_ACTION_LOOP_END:
|
|
|
|
if (bPositiveEvent){
|
|
|
|
if (!(m_flag & ACT_FLAG_LOCKINPUT)){
|
|
|
|
m_flag &= ~ACT_FLAG_KEYUP;
|
|
|
|
m_flag &= ~ACT_FLAG_REVERSE;
|
|
|
|
m_flag |= ACT_FLAG_LOCKINPUT;
|
2004-11-06 04:53:41 +00:00
|
|
|
m_localtime = m_startframe;
|
|
|
|
m_starttime = curtime;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bNegativeEvent){
|
|
|
|
m_flag |= ACT_FLAG_KEYUP;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ACT_ACTION_LOOP_STOP:
|
|
|
|
if (bPositiveEvent){
|
|
|
|
if (!(m_flag & ACT_FLAG_LOCKINPUT)){
|
|
|
|
m_flag &= ~ACT_FLAG_REVERSE;
|
2004-11-06 04:53:41 +00:00
|
|
|
m_flag &= ~ACT_FLAG_KEYUP;
|
|
|
|
m_flag |= ACT_FLAG_LOCKINPUT;
|
|
|
|
SetStartTime(curtime);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bNegativeEvent){
|
2004-11-06 04:53:41 +00:00
|
|
|
m_flag |= ACT_FLAG_KEYUP;
|
|
|
|
m_flag &= ~ACT_FLAG_LOCKINPUT;
|
2002-10-12 11:37:38 +00:00
|
|
|
keepgoing=false;
|
|
|
|
apply=false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ACT_ACTION_FLIPPER:
|
|
|
|
if (bPositiveEvent){
|
|
|
|
if (!(m_flag & ACT_FLAG_LOCKINPUT)){
|
|
|
|
m_flag &= ~ACT_FLAG_REVERSE;
|
2004-11-06 04:53:41 +00:00
|
|
|
m_flag |= ACT_FLAG_LOCKINPUT;
|
2004-12-05 02:50:57 +00:00
|
|
|
SetStartTime(curtime);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (bNegativeEvent){
|
|
|
|
m_flag |= ACT_FLAG_REVERSE;
|
2004-11-06 04:53:41 +00:00
|
|
|
m_flag &= ~ACT_FLAG_LOCKINPUT;
|
|
|
|
SetStartTime(curtime);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ACT_ACTION_PLAY:
|
|
|
|
if (bPositiveEvent){
|
|
|
|
if (!(m_flag & ACT_FLAG_LOCKINPUT)){
|
|
|
|
m_flag &= ~ACT_FLAG_REVERSE;
|
|
|
|
m_localtime = m_starttime;
|
2004-11-06 04:53:41 +00:00
|
|
|
m_starttime = curtime;
|
2002-10-12 11:37:38 +00:00
|
|
|
m_flag |= ACT_FLAG_LOCKINPUT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Perform increment */
|
|
|
|
if (keepgoing){
|
|
|
|
if (m_playtype == ACT_ACTION_MOTION){
|
|
|
|
MT_Point3 newpos;
|
|
|
|
MT_Point3 deltapos;
|
|
|
|
|
|
|
|
newpos = obj->NodeGetWorldPosition();
|
|
|
|
|
|
|
|
/* Find displacement */
|
|
|
|
deltapos = newpos-m_lastpos;
|
|
|
|
m_localtime += (length/m_stridelength) * deltapos.length();
|
|
|
|
m_lastpos = newpos;
|
|
|
|
}
|
|
|
|
else{
|
2004-11-06 04:53:41 +00:00
|
|
|
SetLocalTime(curtime);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if a wrapping response is needed */
|
|
|
|
if (length){
|
2004-11-06 04:53:41 +00:00
|
|
|
if (m_localtime < m_startframe || m_localtime > m_endframe)
|
2004-10-16 11:41:50 +00:00
|
|
|
{
|
2004-11-06 04:53:41 +00:00
|
|
|
m_localtime = m_startframe + fmod(m_localtime, length);
|
2004-10-16 11:41:50 +00:00
|
|
|
wrap = true;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2004-11-06 04:53:41 +00:00
|
|
|
m_localtime = m_startframe;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
/* Perform post-increment tasks */
|
|
|
|
switch (m_playtype){
|
|
|
|
case ACT_ACTION_FROM_PROP:
|
|
|
|
{
|
|
|
|
CValue* propval = GetParent()->GetProperty(m_propname);
|
2004-10-16 11:41:50 +00:00
|
|
|
if (propval)
|
2002-10-12 11:37:38 +00:00
|
|
|
m_localtime = propval->GetNumber();
|
|
|
|
|
|
|
|
if (bNegativeEvent){
|
|
|
|
keepgoing=false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ACT_ACTION_MOTION:
|
|
|
|
break;
|
|
|
|
case ACT_ACTION_LOOP_STOP:
|
|
|
|
break;
|
|
|
|
case ACT_ACTION_FLIPPER:
|
|
|
|
if (wrap){
|
|
|
|
if (!(m_flag & ACT_FLAG_REVERSE)){
|
2004-11-06 04:53:41 +00:00
|
|
|
m_localtime=m_endframe;
|
|
|
|
//keepgoing = false;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
else {
|
2004-11-06 04:53:41 +00:00
|
|
|
m_localtime=m_startframe;
|
2002-10-12 11:37:38 +00:00
|
|
|
keepgoing = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ACT_ACTION_LOOP_END:
|
|
|
|
if (wrap){
|
|
|
|
if (m_flag & ACT_FLAG_KEYUP){
|
|
|
|
keepgoing = false;
|
2004-11-06 04:53:41 +00:00
|
|
|
m_localtime = m_endframe;
|
2002-10-12 11:37:38 +00:00
|
|
|
m_flag &= ~ACT_FLAG_LOCKINPUT;
|
|
|
|
}
|
2004-12-05 02:50:57 +00:00
|
|
|
SetStartTime(curtime);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ACT_ACTION_PLAY:
|
|
|
|
if (wrap){
|
2004-11-06 04:53:41 +00:00
|
|
|
m_localtime = m_endframe;
|
2002-10-12 11:37:38 +00:00
|
|
|
keepgoing = false;
|
|
|
|
m_flag &= ~ACT_FLAG_LOCKINPUT;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
keepgoing = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-06-23 15:32:44 +00:00
|
|
|
/* Set the property if its defined */
|
2008-06-26 12:39:06 +00:00
|
|
|
if (m_framepropname[0] != '\0') {
|
2008-06-23 15:32:44 +00:00
|
|
|
CValue* propowner = GetParent();
|
|
|
|
CValue* oldprop = propowner->GetProperty(m_framepropname);
|
|
|
|
CValue* newval = new CFloatValue(m_localtime);
|
|
|
|
if (oldprop) {
|
|
|
|
oldprop->SetValue(newval);
|
|
|
|
} else {
|
|
|
|
propowner->SetProperty(m_framepropname, newval);
|
|
|
|
}
|
|
|
|
newval->Release();
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2004-10-16 11:41:50 +00:00
|
|
|
if (bNegativeEvent)
|
2002-10-12 11:37:38 +00:00
|
|
|
m_blendframe=0.0;
|
|
|
|
|
|
|
|
/* Apply the pose if necessary*/
|
|
|
|
if (apply){
|
|
|
|
|
|
|
|
/* Priority test */
|
|
|
|
if (obj->SetActiveAction(this, priority, curtime)){
|
|
|
|
|
|
|
|
/* Get the underlying pose from the armature */
|
|
|
|
obj->GetPose(&m_pose);
|
2009-06-16 20:38:18 +00:00
|
|
|
|
|
|
|
// 2.4x function,
|
2002-10-12 11:37:38 +00:00
|
|
|
/* Override the necessary channels with ones from the action */
|
2009-02-10 18:06:26 +00:00
|
|
|
// XXX extract_pose_from_action(m_pose, m_action, m_localtime);
|
2009-06-16 20:38:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
// 2.5x - replacement for extract_pose_from_action(...) above.
|
|
|
|
{
|
|
|
|
struct PointerRNA id_ptr;
|
|
|
|
Object *arm= obj->GetArmatureObject();
|
|
|
|
bPose *pose_back= arm->pose;
|
|
|
|
|
|
|
|
arm->pose= m_pose;
|
|
|
|
RNA_id_pointer_create((ID *)arm, &id_ptr);
|
|
|
|
animsys_evaluate_action(&id_ptr, m_action, NULL, m_localtime);
|
|
|
|
|
|
|
|
arm->pose= pose_back;
|
|
|
|
|
|
|
|
// 2.5x - could also do this but looks too high level, constraints use this, it works ok.
|
|
|
|
// Object workob; /* evaluate using workob */
|
|
|
|
// what_does_obaction((Scene *)obj->GetScene(), obj->GetArmatureObject(), &workob, m_pose, m_action, NULL, m_localtime);
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2009-06-16 20:38:18 +00:00
|
|
|
// done getting the pose from the action
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
/* Perform the user override (if any) */
|
|
|
|
if (m_userpose){
|
Result of 2 weeks of quiet coding work in Greece :)
Aim was to get a total refresh of the animation system. This
is needed because;
- we need to upgrade it with 21st century features
- current code is spaghetti/hack combo, and hides good design
- it should become lag-free with using dependency graphs
A full log, with complete code API/structure/design explanation
will follow, that's a load of work... so here below the list with
hot changes;
- The entire object update system (matrices, geometry) is now
centralized. Calls to where_is_object and makeDispList are
forbidden, instead we tag objects 'changed' and let the
depgraph code sort it out
- Removed all old "Ika" code
- Depgraph is aware of all relationships, including meta balls,
constraints, bevelcurve, and so on.
- Made depgraph aware of relation types and layers, to do smart
flushing of 'changed' events. Nothing gets calculated too often!
- Transform uses depgraph to detect changes
- On frame-advance, depgraph flushes animated changes
Armatures;
Almost all armature related code has been fully built from scratch.
It now reveils the original design much better, with a very clean
implementation, lag free without even calculating each Bone more than
once. Result is quite a speedup yes!
Important to note is;
1) Armature is data containing the 'rest position'
2) Pose is the changes of rest position, and always on object level.
That way more Objects can use same Pose. Also constraints are in Pose
3) Actions only contain the Ipos to change values in Poses.
- Bones draw unrotated now
- Drawing bones speedup enormously (10-20 times)
- Bone selecting in EditMode, selection state is saved for PoseMode,
and vice-versa
- Undo in editmode
- Bone renaming does vertexgroups, constraints, posechannels, actions,
for all users of Armature in entire file
- Added Bone renaming in NKey panel
- Nkey PoseMode shows eulers now
- EditMode and PoseMode now have 'active' bone too (last clicked)
- Parenting in EditMode' CTRL+P, ALT+P, with nice options!
- Pose is added in Outliner now, with showing that constraints are in
the Pose, not Armature
- Disconnected IK solving from constraints. It's a separate phase now,
on top of the full Pose calculations
- Pose itself has a dependency graph too, so evaluation order is lag free.
TODO NOW;
- Rotating in Posemode has incorrect inverse transform (Martin will fix)
- Python Bone/Armature/Pose API disabled... needs full recode too
(wait for my doc!)
- Game engine will need upgrade too
- Depgraph code needs revision, cleanup, can be much faster!
(But, compliments for Jean-Luc, it works like a charm!)
- IK changed, it now doesnt use previous position to advance to next
position anymore. That system looks nice (no flips) but is not well
suited for NLA and background render.
TODO LATER;
We now can do loadsa new nifty features as well; like:
- Kill PoseMode (can be option for armatures itself)
- Make B-Bones (Bezier, Bspline, like for spines)
- Move all silly button level edit to 3d window (like CTRL+I = add
IK)
- Much better & informative drawing
- Fix action/nla editors
- Put all ipos in Actions (object, mesh key, lamp color)
- Add hooks
- Null bones
- Much more advanced constraints...
Bugfixes;
- OGL render (view3d header) had wrong first frame on anim render
- Ipo 'recording' mode had wrong playback speed
- Vertex-key mode now sticks to show 'active key', until frame change
-Ton-
2005-07-03 17:35:38 +00:00
|
|
|
extract_pose_from_pose(m_pose, m_userpose);
|
2009-06-16 18:25:48 +00:00
|
|
|
game_free_pose(m_userpose); //cant use MEM_freeN(m_userpose) because the channels need freeing too.
|
2002-10-12 11:37:38 +00:00
|
|
|
m_userpose = NULL;
|
|
|
|
}
|
|
|
|
#if 1
|
|
|
|
/* Handle blending */
|
|
|
|
if (m_blendin && (m_blendframe<m_blendin)){
|
|
|
|
/* If this is the start of a blending sequence... */
|
|
|
|
if ((m_blendframe==0.0) || (!m_blendpose)){
|
|
|
|
obj->GetMRDPose(&m_blendpose);
|
2004-10-16 11:41:50 +00:00
|
|
|
m_blendstart = curtime;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Find percentages */
|
|
|
|
newweight = (m_blendframe/(float)m_blendin);
|
2009-06-19 16:27:01 +00:00
|
|
|
game_blend_poses(m_pose, m_blendpose, 1.0 - newweight);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
/* Increment current blending percentage */
|
2008-06-17 10:06:38 +00:00
|
|
|
m_blendframe = (curtime - m_blendstart)*KX_KetsjiEngine::GetAnimFrameRate();
|
2002-10-12 11:37:38 +00:00
|
|
|
if (m_blendframe>m_blendin)
|
|
|
|
m_blendframe = m_blendin;
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
m_lastUpdate = m_localtime;
|
|
|
|
obj->SetPose (m_pose);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
m_blendframe = 0.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!keepgoing){
|
|
|
|
m_blendframe = 0.0;
|
|
|
|
}
|
|
|
|
return keepgoing;
|
|
|
|
};
|
|
|
|
|
2010-10-31 04:11:39 +00:00
|
|
|
#ifdef WITH_PYTHON
|
2009-09-29 21:42:40 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
/* Python functions */
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
|
2009-06-16 18:25:48 +00:00
|
|
|
PyObject* BL_ActionActuator::PyGetChannel(PyObject* value) {
|
2009-06-29 02:25:54 +00:00
|
|
|
char *string= _PyUnicode_AsString(value);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2009-06-16 18:25:48 +00:00
|
|
|
if (!string) {
|
|
|
|
PyErr_SetString(PyExc_TypeError, "expected a single string");
|
|
|
|
return NULL;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2009-06-16 18:25:48 +00:00
|
|
|
|
|
|
|
bPoseChannel *pchan;
|
|
|
|
|
2009-06-17 09:42:04 +00:00
|
|
|
if(m_userpose==NULL && m_pose==NULL) {
|
|
|
|
BL_ArmatureObject *obj = (BL_ArmatureObject*)GetParent();
|
|
|
|
obj->GetPose(&m_pose); /* Get the underlying pose from the armature */
|
|
|
|
}
|
2009-06-16 18:25:48 +00:00
|
|
|
|
|
|
|
// get_pose_channel accounts for NULL pose, run on both incase one exists but
|
|
|
|
// the channel doesnt
|
|
|
|
if( !(pchan=get_pose_channel(m_userpose, string)) &&
|
|
|
|
!(pchan=get_pose_channel(m_pose, string)) )
|
|
|
|
{
|
|
|
|
PyErr_SetString(PyExc_ValueError, "channel doesnt exist");
|
2008-07-01 13:21:37 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2009-06-16 18:25:48 +00:00
|
|
|
|
|
|
|
PyObject *ret = PyTuple_New(3);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2009-06-16 18:25:48 +00:00
|
|
|
PyObject *list = PyList_New(3);
|
|
|
|
PyList_SET_ITEM(list, 0, PyFloat_FromDouble(pchan->loc[0]));
|
|
|
|
PyList_SET_ITEM(list, 1, PyFloat_FromDouble(pchan->loc[1]));
|
|
|
|
PyList_SET_ITEM(list, 2, PyFloat_FromDouble(pchan->loc[2]));
|
|
|
|
PyTuple_SET_ITEM(ret, 0, list);
|
|
|
|
|
|
|
|
list = PyList_New(3);
|
|
|
|
PyList_SET_ITEM(list, 0, PyFloat_FromDouble(pchan->size[0]));
|
|
|
|
PyList_SET_ITEM(list, 1, PyFloat_FromDouble(pchan->size[1]));
|
|
|
|
PyList_SET_ITEM(list, 2, PyFloat_FromDouble(pchan->size[2]));
|
|
|
|
PyTuple_SET_ITEM(ret, 1, list);
|
|
|
|
|
|
|
|
list = PyList_New(4);
|
|
|
|
PyList_SET_ITEM(list, 0, PyFloat_FromDouble(pchan->quat[0]));
|
|
|
|
PyList_SET_ITEM(list, 1, PyFloat_FromDouble(pchan->quat[1]));
|
|
|
|
PyList_SET_ITEM(list, 2, PyFloat_FromDouble(pchan->quat[2]));
|
|
|
|
PyList_SET_ITEM(list, 3, PyFloat_FromDouble(pchan->quat[3]));
|
|
|
|
PyTuple_SET_ITEM(ret, 2, list);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
/*
|
|
|
|
return Py_BuildValue("([fff][fff][ffff])",
|
|
|
|
pchan->loc[0], pchan->loc[1], pchan->loc[2],
|
|
|
|
pchan->size[0], pchan->size[1], pchan->size[2],
|
|
|
|
pchan->quat[0], pchan->quat[1], pchan->quat[2], pchan->quat[3] );
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
2009-06-16 18:25:48 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2009-01-26 08:34:40 +00:00
|
|
|
/* setChannel */
|
|
|
|
KX_PYMETHODDEF_DOC(BL_ActionActuator, setChannel,
|
2002-10-12 11:37:38 +00:00
|
|
|
"setChannel(channel, matrix)\n"
|
|
|
|
"\t - channel : A string specifying the name of the bone channel.\n"
|
|
|
|
"\t - matrix : A 4x4 matrix specifying the overriding transformation\n"
|
2009-01-26 08:34:40 +00:00
|
|
|
"\t as an offset from the bone's rest position.\n")
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2009-06-16 18:25:48 +00:00
|
|
|
BL_ArmatureObject *obj = (BL_ArmatureObject*)GetParent();
|
2002-10-12 11:37:38 +00:00
|
|
|
char *string;
|
2009-06-16 18:25:48 +00:00
|
|
|
PyObject *pymat= NULL;
|
|
|
|
PyObject *pyloc= NULL, *pysize= NULL, *pyquat= NULL;
|
|
|
|
bPoseChannel *pchan;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2009-06-16 18:25:48 +00:00
|
|
|
if(PyTuple_Size(args)==2) {
|
|
|
|
if (!PyArg_ParseTuple(args,"sO:setChannel", &string, &pymat)) // matrix
|
|
|
|
return NULL;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2009-06-16 18:25:48 +00:00
|
|
|
else if(PyTuple_Size(args)==4) {
|
|
|
|
if (!PyArg_ParseTuple(args,"sOOO:setChannel", &string, &pyloc, &pysize, &pyquat)) // loc/size/quat
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
PyErr_SetString(PyExc_ValueError, "Expected a string and a 4x4 matrix (2 args) or a string and loc/size/quat sequences (4 args)");
|
|
|
|
return NULL;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2009-06-16 18:25:48 +00:00
|
|
|
if(pymat) {
|
|
|
|
float matrix[4][4];
|
|
|
|
MT_Matrix4x4 mat;
|
|
|
|
|
|
|
|
if(!PyMatTo(pymat, mat))
|
|
|
|
return NULL;
|
|
|
|
|
2009-12-22 23:38:09 +00:00
|
|
|
mat.getValue((float*)matrix);
|
2009-06-16 18:25:48 +00:00
|
|
|
|
|
|
|
BL_ArmatureObject *obj = (BL_ArmatureObject*)GetParent();
|
|
|
|
|
|
|
|
if (!m_userpose) {
|
2009-06-17 09:42:04 +00:00
|
|
|
if(!m_pose)
|
|
|
|
obj->GetPose(&m_pose); /* Get the underlying pose from the armature */
|
2009-09-24 21:22:24 +00:00
|
|
|
game_copy_pose(&m_userpose, m_pose, 0);
|
2009-06-16 18:25:48 +00:00
|
|
|
}
|
2009-07-25 20:59:09 +00:00
|
|
|
// pchan= verify_pose_channel(m_userpose, string); // adds the channel if its not there.
|
2009-06-17 09:42:04 +00:00
|
|
|
pchan= get_pose_channel(m_userpose, string); // adds the channel if its not there.
|
2009-06-16 18:25:48 +00:00
|
|
|
|
2009-07-25 20:59:09 +00:00
|
|
|
if(pchan) {
|
2009-06-17 09:42:04 +00:00
|
|
|
VECCOPY (pchan->loc, matrix[3]);
|
2009-11-10 20:43:45 +00:00
|
|
|
mat4_to_size( pchan->size,matrix);
|
|
|
|
mat4_to_quat( pchan->quat,matrix);
|
2009-06-17 09:42:04 +00:00
|
|
|
}
|
2009-06-16 18:25:48 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
MT_Vector3 loc;
|
|
|
|
MT_Vector3 size;
|
2009-06-25 20:47:41 +00:00
|
|
|
MT_Quaternion quat;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2009-06-25 20:47:41 +00:00
|
|
|
if (!PyVecTo(pyloc, loc) || !PyVecTo(pysize, size) || !PyQuatTo(pyquat, quat))
|
2009-06-16 18:25:48 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
// same as above
|
|
|
|
if (!m_userpose) {
|
2009-06-17 09:42:04 +00:00
|
|
|
if(!m_pose)
|
|
|
|
obj->GetPose(&m_pose); /* Get the underlying pose from the armature */
|
2009-09-24 21:22:24 +00:00
|
|
|
game_copy_pose(&m_userpose, m_pose, 0);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2009-07-25 20:59:09 +00:00
|
|
|
// pchan= verify_pose_channel(m_userpose, string);
|
|
|
|
pchan= get_pose_channel(m_userpose, string); // adds the channel if its not there.
|
2009-06-16 18:25:48 +00:00
|
|
|
|
|
|
|
// for some reason loc.setValue(pchan->loc) fails
|
2009-06-17 09:42:04 +00:00
|
|
|
if(pchan) {
|
|
|
|
pchan->loc[0]= loc[0]; pchan->loc[1]= loc[1]; pchan->loc[2]= loc[2];
|
|
|
|
pchan->size[0]= size[0]; pchan->size[1]= size[1]; pchan->size[2]= size[2];
|
2009-07-25 20:59:09 +00:00
|
|
|
pchan->quat[0]= quat[3]; pchan->quat[1]= quat[0]; pchan->quat[2]= quat[1]; pchan->quat[3]= quat[2]; /* notice xyzw -> wxyz is intentional */
|
2009-06-17 09:42:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(pchan==NULL) {
|
|
|
|
PyErr_SetString(PyExc_ValueError, "Channel could not be found, use the 'channelNames' attribute to get a list of valid channels");
|
|
|
|
return NULL;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2008-08-14 03:23:36 +00:00
|
|
|
Py_RETURN_NONE;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2009-01-26 08:34:40 +00:00
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
/* Python Integration Hooks */
|
|
|
|
/* ------------------------------------------------------------------------- */
|
2004-07-17 05:28:23 +00:00
|
|
|
|
2009-01-26 08:34:40 +00:00
|
|
|
PyTypeObject BL_ActionActuator::Type = {
|
2009-06-08 20:08:19 +00:00
|
|
|
PyVarObject_HEAD_INIT(NULL, 0)
|
2009-08-10 00:07:34 +00:00
|
|
|
"BL_ActionActuator",
|
|
|
|
sizeof(PyObjectPlus_Proxy),
|
|
|
|
0,
|
|
|
|
py_base_dealloc,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
py_base_repr,
|
|
|
|
0,0,0,0,0,0,0,0,0,
|
|
|
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
|
|
|
|
0,0,0,0,0,0,0,
|
|
|
|
Methods,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
&SCA_IActuator::Type,
|
|
|
|
0,0,0,0,0,0,
|
|
|
|
py_base_new
|
2009-01-26 08:34:40 +00:00
|
|
|
};
|
2004-07-17 05:28:23 +00:00
|
|
|
|
2009-01-26 08:34:40 +00:00
|
|
|
PyMethodDef BL_ActionActuator::Methods[] = {
|
2009-06-16 18:25:48 +00:00
|
|
|
{"getChannel", (PyCFunction) BL_ActionActuator::sPyGetChannel, METH_O},
|
2009-01-26 08:34:40 +00:00
|
|
|
KX_PYMETHODTABLE(BL_ActionActuator, setChannel),
|
|
|
|
{NULL,NULL} //Sentinel
|
|
|
|
};
|
|
|
|
|
|
|
|
PyAttributeDef BL_ActionActuator::Attributes[] = {
|
2009-06-08 20:08:19 +00:00
|
|
|
KX_PYATTRIBUTE_FLOAT_RW("frameStart", 0, MAXFRAMEF, BL_ActionActuator, m_startframe),
|
|
|
|
KX_PYATTRIBUTE_FLOAT_RW("frameEnd", 0, MAXFRAMEF, BL_ActionActuator, m_endframe),
|
|
|
|
KX_PYATTRIBUTE_FLOAT_RW("blendIn", 0, MAXFRAMEF, BL_ActionActuator, m_blendin),
|
2009-04-20 15:06:46 +00:00
|
|
|
KX_PYATTRIBUTE_RW_FUNCTION("action", BL_ActionActuator, pyattr_get_action, pyattr_set_action),
|
2009-06-17 09:42:04 +00:00
|
|
|
KX_PYATTRIBUTE_RO_FUNCTION("channelNames", BL_ActionActuator, pyattr_get_channel_names),
|
2009-01-26 08:34:40 +00:00
|
|
|
KX_PYATTRIBUTE_SHORT_RW("priority", 0, 100, false, BL_ActionActuator, m_priority),
|
|
|
|
KX_PYATTRIBUTE_FLOAT_RW_CHECK("frame", 0, MAXFRAMEF, BL_ActionActuator, m_localtime, CheckFrame),
|
2009-06-08 20:08:19 +00:00
|
|
|
KX_PYATTRIBUTE_STRING_RW("propName", 0, 31, false, BL_ActionActuator, m_propname),
|
|
|
|
KX_PYATTRIBUTE_STRING_RW("framePropName", 0, 31, false, BL_ActionActuator, m_framepropname),
|
|
|
|
KX_PYATTRIBUTE_BOOL_RW("useContinue", BL_ActionActuator, m_end_reset),
|
2009-01-26 08:34:40 +00:00
|
|
|
KX_PYATTRIBUTE_FLOAT_RW_CHECK("blendTime", 0, MAXFRAMEF, BL_ActionActuator, m_blendframe, CheckBlendTime),
|
2009-06-08 20:08:19 +00:00
|
|
|
KX_PYATTRIBUTE_SHORT_RW_CHECK("mode",0,100,false,BL_ActionActuator,m_playtype,CheckType),
|
2009-01-26 08:34:40 +00:00
|
|
|
{ NULL } //Sentinel
|
|
|
|
};
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
PyObject* BL_ActionActuator::pyattr_get_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
|
|
|
{
|
|
|
|
BL_ActionActuator* self= static_cast<BL_ActionActuator*>(self_v);
|
2009-06-29 02:25:54 +00:00
|
|
|
return PyUnicode_FromString(self->GetAction() ? self->GetAction()->id.name+2 : "");
|
2009-04-20 15:06:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int BL_ActionActuator::pyattr_set_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
|
|
|
|
{
|
|
|
|
BL_ActionActuator* self= static_cast<BL_ActionActuator*>(self_v);
|
|
|
|
|
2009-06-29 02:25:54 +00:00
|
|
|
if (!PyUnicode_Check(value))
|
2009-04-20 15:06:46 +00:00
|
|
|
{
|
|
|
|
PyErr_SetString(PyExc_ValueError, "actuator.action = val: Action Actuator, expected the string name of the action");
|
2009-06-08 20:08:19 +00:00
|
|
|
return PY_SET_ATTR_FAIL;
|
2009-04-20 15:06:46 +00:00
|
|
|
}
|
2009-01-26 08:34:40 +00:00
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
bAction *action= NULL;
|
2009-06-29 02:25:54 +00:00
|
|
|
STR_String val = _PyUnicode_AsString(value);
|
2009-04-20 15:06:46 +00:00
|
|
|
|
|
|
|
if (val != "")
|
|
|
|
{
|
|
|
|
action= (bAction*)SCA_ILogicBrick::m_sCurrentLogicManager->GetActionByName(val);
|
2009-01-26 08:34:40 +00:00
|
|
|
if (!action)
|
|
|
|
{
|
2009-04-20 15:06:46 +00:00
|
|
|
PyErr_SetString(PyExc_ValueError, "actuator.action = val: Action Actuator, action not found!");
|
2009-06-08 20:08:19 +00:00
|
|
|
return PY_SET_ATTR_FAIL;
|
2009-01-26 08:34:40 +00:00
|
|
|
}
|
2008-07-10 14:23:19 +00:00
|
|
|
}
|
2009-04-20 15:06:46 +00:00
|
|
|
|
|
|
|
self->SetAction(action);
|
2009-06-08 20:08:19 +00:00
|
|
|
return PY_SET_ATTR_SUCCESS;
|
2009-04-20 15:06:46 +00:00
|
|
|
|
2004-07-17 05:28:23 +00:00
|
|
|
}
|
2009-06-17 09:42:04 +00:00
|
|
|
|
|
|
|
PyObject* BL_ActionActuator::pyattr_get_channel_names(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
|
|
|
{
|
|
|
|
BL_ActionActuator* self= static_cast<BL_ActionActuator*>(self_v);
|
|
|
|
PyObject *ret= PyList_New(0);
|
2009-07-25 20:51:45 +00:00
|
|
|
PyObject *item;
|
2009-06-17 09:42:04 +00:00
|
|
|
|
|
|
|
bPose *pose= ((BL_ArmatureObject*)self->GetParent())->GetOrigPose();
|
|
|
|
|
|
|
|
if(pose) {
|
|
|
|
bPoseChannel *pchan;
|
|
|
|
for(pchan= (bPoseChannel *)pose->chanbase.first; pchan; pchan= (bPoseChannel *)pchan->next) {
|
2009-07-25 20:59:09 +00:00
|
|
|
item= PyUnicode_FromString(pchan->name);
|
2009-07-25 20:51:45 +00:00
|
|
|
PyList_Append(ret, item);
|
|
|
|
Py_DECREF(item);
|
2009-06-17 09:42:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2009-09-29 21:42:40 +00:00
|
|
|
|
2010-10-31 04:11:39 +00:00
|
|
|
#endif // WITH_PYTHON
|