Changeset View
Changeset View
Standalone View
Standalone View
source/gameengine/GameLogic/SCA_ShapeActionActuator.cpp
- This file was moved from source/gameengine/Converter/BL_ShapeActionActuator.cpp.
| Show All 19 Lines | |||||
| * | * | ||||
| * The Original Code is: all of this file. | * The Original Code is: all of this file. | ||||
| * | * | ||||
| * Contributor(s): none yet. | * Contributor(s): none yet. | ||||
| * | * | ||||
| * ***** END GPL LICENSE BLOCK ***** | * ***** END GPL LICENSE BLOCK ***** | ||||
| */ | */ | ||||
| /** \file gameengine/Converter/BL_ShapeActionActuator.cpp | /** \file gameengine/GameLogic/SCA_ShapeActionActuator.cpp | ||||
| * \ingroup bgeconv | * \ingroup gamelogic | ||||
| */ | */ | ||||
| #include <cmath> | #include <cmath> | ||||
| #include "SCA_LogicManager.h" | #include "SCA_LogicManager.h" | ||||
| #include "BL_ShapeActionActuator.h" | #include "SCA_ShapeActionActuator.h" | ||||
| #include "BL_ShapeDeformer.h" | #include "BL_ShapeDeformer.h" | ||||
| #include "KX_GameObject.h" | #include "KX_GameObject.h" | ||||
| #include "STR_HashedString.h" | #include "STR_HashedString.h" | ||||
| #include "DNA_nla_types.h" | #include "DNA_nla_types.h" | ||||
| #include "DNA_action_types.h" | #include "DNA_action_types.h" | ||||
| #include "DNA_anim_types.h" | #include "DNA_anim_types.h" | ||||
| #include "DNA_scene_types.h" | #include "DNA_scene_types.h" | ||||
| #include "BKE_action.h" | #include "BKE_action.h" | ||||
| #include "DNA_armature_types.h" | #include "DNA_armature_types.h" | ||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #include "BLI_blenlib.h" | #include "BLI_blenlib.h" | ||||
| #include "BLI_math.h" | #include "BLI_math.h" | ||||
| #include "MT_Matrix4x4.h" | #include "MT_Matrix4x4.h" | ||||
| #include "FloatValue.h" | #include "FloatValue.h" | ||||
| #include "PyObjectPlus.h" | #include "PyObjectPlus.h" | ||||
| extern "C" { | extern "C" { | ||||
| #include "BKE_animsys.h" | #include "BKE_animsys.h" | ||||
| #include "BKE_key.h" | #include "BKE_key.h" | ||||
| #include "RNA_access.h" | #include "RNA_access.h" | ||||
| } | } | ||||
| BL_ShapeActionActuator::BL_ShapeActionActuator(SCA_IObject* gameobj, | SCA_ShapeActionActuator::SCA_ShapeActionActuator(SCA_IObject* gameobj, | ||||
| const STR_String& propname, | const STR_String& propname, | ||||
| const STR_String& framepropname, | const STR_String& framepropname, | ||||
| float starttime, | float starttime, | ||||
| float endtime, | float endtime, | ||||
| struct bAction *action, | struct bAction *action, | ||||
| short playtype, | short playtype, | ||||
| short blendin, | short blendin, | ||||
| short priority, | short priority, | ||||
| float stride) | float stride) | ||||
| : SCA_IActuator(gameobj, KX_ACT_SHAPEACTION), | : SCA_IActuator(gameobj, SCA_ACT_SHAPEACTION), | ||||
| m_lastpos(0, 0, 0), | m_lastpos(0, 0, 0), | ||||
| m_blendframe(0), | m_blendframe(0), | ||||
| m_flag(0), | m_flag(0), | ||||
| m_startframe (starttime), | m_startframe (starttime), | ||||
| m_endframe(endtime) , | m_endframe(endtime) , | ||||
| m_starttime(0), | m_starttime(0), | ||||
| m_localtime(starttime), | m_localtime(starttime), | ||||
| m_lastUpdate(-1), | m_lastUpdate(-1), | ||||
| m_blendin(blendin), | m_blendin(blendin), | ||||
| m_blendstart(0), | m_blendstart(0), | ||||
| m_stridelength(stride), | m_stridelength(stride), | ||||
| m_playtype(playtype), | m_playtype(playtype), | ||||
| m_priority(priority), | m_priority(priority), | ||||
| m_action(action), | m_action(action), | ||||
| m_framepropname(framepropname), | m_framepropname(framepropname), | ||||
| m_propname(propname) | m_propname(propname) | ||||
| { | { | ||||
| m_idptr = new PointerRNA(); | m_idptr = new PointerRNA(); | ||||
| BL_DeformableGameObject *obj = (BL_DeformableGameObject*)GetParent(); | BL_DeformableGameObject *obj = (BL_DeformableGameObject*)GetParent(); | ||||
| BL_ShapeDeformer *shape_deformer = dynamic_cast<BL_ShapeDeformer*>(obj->GetDeformer()); | BL_ShapeDeformer *shape_deformer = dynamic_cast<BL_ShapeDeformer*>(obj->GetDeformer()); | ||||
| RNA_id_pointer_create(&shape_deformer->GetKey()->id, m_idptr); | RNA_id_pointer_create(&shape_deformer->GetKey()->id, m_idptr); | ||||
| }; | }; | ||||
| BL_ShapeActionActuator::~BL_ShapeActionActuator() | SCA_ShapeActionActuator::~SCA_ShapeActionActuator() | ||||
| { | { | ||||
| if (m_idptr) | if (m_idptr) | ||||
| delete m_idptr; | delete m_idptr; | ||||
| } | } | ||||
| void BL_ShapeActionActuator::ProcessReplica() | void SCA_ShapeActionActuator::ProcessReplica() | ||||
| { | { | ||||
| SCA_IActuator::ProcessReplica(); | SCA_IActuator::ProcessReplica(); | ||||
| m_localtime=m_startframe; | m_localtime=m_startframe; | ||||
| m_lastUpdate=-1; | m_lastUpdate=-1; | ||||
| } | } | ||||
| void BL_ShapeActionActuator::SetBlendTime(float newtime) | void SCA_ShapeActionActuator::SetBlendTime(float newtime) | ||||
| { | { | ||||
| m_blendframe = newtime; | m_blendframe = newtime; | ||||
| } | } | ||||
| CValue* BL_ShapeActionActuator::GetReplica() | CValue* SCA_ShapeActionActuator::GetReplica() | ||||
| { | { | ||||
| BL_ShapeActionActuator* replica = new BL_ShapeActionActuator(*this);//m_float,GetName()); | SCA_ShapeActionActuator* replica = new SCA_ShapeActionActuator(*this);//m_float,GetName()); | ||||
| replica->ProcessReplica(); | replica->ProcessReplica(); | ||||
| return replica; | return replica; | ||||
| } | } | ||||
| bool BL_ShapeActionActuator::ClampLocalTime() | bool SCA_ShapeActionActuator::ClampLocalTime() | ||||
| { | { | ||||
| if (m_startframe < m_endframe) { | if (m_startframe < m_endframe) { | ||||
| if (m_localtime < m_startframe) | if (m_localtime < m_startframe) | ||||
| { | { | ||||
| m_localtime = m_startframe; | m_localtime = m_startframe; | ||||
| return true; | return true; | ||||
| } | } | ||||
| else if (m_localtime > m_endframe) | else if (m_localtime > m_endframe) | ||||
| Show All 11 Lines | if (m_startframe < m_endframe) { | ||||
| { | { | ||||
| m_localtime = m_endframe; | m_localtime = m_endframe; | ||||
| return true; | return true; | ||||
| } | } | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| void BL_ShapeActionActuator::SetStartTime(float curtime) | void SCA_ShapeActionActuator::SetStartTime(float curtime) | ||||
| { | { | ||||
| float direction = m_startframe < m_endframe ? 1.0 : -1.0; | float direction = m_startframe < m_endframe ? 1.0 : -1.0; | ||||
| if (!(m_flag & ACT_FLAG_REVERSE)) | if (!(m_flag & ACT_FLAG_REVERSE)) | ||||
| m_starttime = curtime - direction*(m_localtime - m_startframe)/KX_KetsjiEngine::GetAnimFrameRate(); | m_starttime = curtime - direction*(m_localtime - m_startframe)/KX_KetsjiEngine::GetAnimFrameRate(); | ||||
| else | else | ||||
| m_starttime = curtime - direction*(m_endframe - m_localtime)/KX_KetsjiEngine::GetAnimFrameRate(); | m_starttime = curtime - direction*(m_endframe - m_localtime)/KX_KetsjiEngine::GetAnimFrameRate(); | ||||
| } | } | ||||
| void BL_ShapeActionActuator::SetLocalTime(float curtime) | void SCA_ShapeActionActuator::SetLocalTime(float curtime) | ||||
| { | { | ||||
| float delta_time = (curtime - m_starttime)*KX_KetsjiEngine::GetAnimFrameRate(); | float delta_time = (curtime - m_starttime)*KX_KetsjiEngine::GetAnimFrameRate(); | ||||
| if (m_endframe < m_startframe) | if (m_endframe < m_startframe) | ||||
| delta_time = -delta_time; | delta_time = -delta_time; | ||||
| if (!(m_flag & ACT_FLAG_REVERSE)) | if (!(m_flag & ACT_FLAG_REVERSE)) | ||||
| m_localtime = m_startframe + delta_time; | m_localtime = m_startframe + delta_time; | ||||
| else | else | ||||
| m_localtime = m_endframe - delta_time; | m_localtime = m_endframe - delta_time; | ||||
| } | } | ||||
| void BL_ShapeActionActuator::BlendShape(Key* key, float srcweight) | void SCA_ShapeActionActuator::BlendShape(Key* key, float srcweight) | ||||
| { | { | ||||
| vector<float>::const_iterator it; | vector<float>::const_iterator it; | ||||
| float dstweight; | float dstweight; | ||||
| KeyBlock *kb; | KeyBlock *kb; | ||||
| dstweight = 1.0F - srcweight; | dstweight = 1.0F - srcweight; | ||||
| for (it=m_blendshape.begin(), kb = (KeyBlock *)key->block.first; | for (it=m_blendshape.begin(), kb = (KeyBlock *)key->block.first; | ||||
| kb && it != m_blendshape.end(); | kb && it != m_blendshape.end(); | ||||
| kb = (KeyBlock *)kb->next, it++) | kb = (KeyBlock *)kb->next, it++) | ||||
| { | { | ||||
| kb->curval = kb->curval * dstweight + (*it) * srcweight; | kb->curval = kb->curval * dstweight + (*it) * srcweight; | ||||
| } | } | ||||
| } | } | ||||
| bool BL_ShapeActionActuator::Update(double curtime, bool frame) | bool SCA_ShapeActionActuator::Update(double curtime, bool frame) | ||||
| { | { | ||||
| bool bNegativeEvent = false; | bool bNegativeEvent = false; | ||||
| bool bPositiveEvent = false; | bool bPositiveEvent = false; | ||||
| bool keepgoing = true; | bool keepgoing = true; | ||||
| bool wrap = false; | bool wrap = false; | ||||
| bool apply=true; | bool apply=true; | ||||
| int priority; | int priority; | ||||
| float newweight; | float newweight; | ||||
| ▲ Show 20 Lines • Show All 284 Lines • ▼ Show 20 Lines | |||||
| #ifdef WITH_PYTHON | #ifdef WITH_PYTHON | ||||
| /* ------------------------------------------------------------------------- */ | /* ------------------------------------------------------------------------- */ | ||||
| /* Python functions */ | /* Python functions */ | ||||
| /* ------------------------------------------------------------------------- */ | /* ------------------------------------------------------------------------- */ | ||||
| /* Integration hooks ------------------------------------------------------- */ | /* Integration hooks ------------------------------------------------------- */ | ||||
| PyTypeObject BL_ShapeActionActuator::Type = { | PyTypeObject SCA_ShapeActionActuator::Type = { | ||||
| PyVarObject_HEAD_INIT(NULL, 0) | PyVarObject_HEAD_INIT(NULL, 0) | ||||
| "BL_ShapeActionActuator", | "SCA_ShapeActionActuator", | ||||
| sizeof(PyObjectPlus_Proxy), | sizeof(PyObjectPlus_Proxy), | ||||
| 0, | 0, | ||||
| py_base_dealloc, | py_base_dealloc, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| py_base_repr, | py_base_repr, | ||||
| 0,0,0,0,0,0,0,0,0, | 0,0,0,0,0,0,0,0,0, | ||||
| Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, | ||||
| 0,0,0,0,0,0,0, | 0,0,0,0,0,0,0, | ||||
| Methods, | Methods, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| &SCA_IActuator::Type, | &SCA_IActuator::Type, | ||||
| 0,0,0,0,0,0, | 0,0,0,0,0,0, | ||||
| py_base_new | py_base_new | ||||
| }; | }; | ||||
| PyMethodDef BL_ShapeActionActuator::Methods[] = { | PyMethodDef SCA_ShapeActionActuator::Methods[] = { | ||||
| {NULL,NULL} //Sentinel | {NULL,NULL} //Sentinel | ||||
| }; | }; | ||||
| PyAttributeDef BL_ShapeActionActuator::Attributes[] = { | PyAttributeDef SCA_ShapeActionActuator::Attributes[] = { | ||||
| KX_PYATTRIBUTE_FLOAT_RW("frameStart", 0, MAXFRAMEF, BL_ShapeActionActuator, m_startframe), | KX_PYATTRIBUTE_FLOAT_RW("frameStart", 0, MAXFRAMEF, SCA_ShapeActionActuator, m_startframe), | ||||
| KX_PYATTRIBUTE_FLOAT_RW("frameEnd", 0, MAXFRAMEF, BL_ShapeActionActuator, m_endframe), | KX_PYATTRIBUTE_FLOAT_RW("frameEnd", 0, MAXFRAMEF, SCA_ShapeActionActuator, m_endframe), | ||||
| KX_PYATTRIBUTE_FLOAT_RW("blendIn", 0, MAXFRAMEF, BL_ShapeActionActuator, m_blendin), | KX_PYATTRIBUTE_FLOAT_RW("blendIn", 0, MAXFRAMEF, SCA_ShapeActionActuator, m_blendin), | ||||
| KX_PYATTRIBUTE_RW_FUNCTION("action", BL_ShapeActionActuator, pyattr_get_action, pyattr_set_action), | KX_PYATTRIBUTE_RW_FUNCTION("action", SCA_ShapeActionActuator, pyattr_get_action, pyattr_set_action), | ||||
| KX_PYATTRIBUTE_SHORT_RW("priority", 0, 100, false, BL_ShapeActionActuator, m_priority), | KX_PYATTRIBUTE_SHORT_RW("priority", 0, 100, false, SCA_ShapeActionActuator, m_priority), | ||||
| KX_PYATTRIBUTE_FLOAT_RW_CHECK("frame", 0, MAXFRAMEF, BL_ShapeActionActuator, m_localtime, CheckFrame), | KX_PYATTRIBUTE_FLOAT_RW_CHECK("frame", 0, MAXFRAMEF, SCA_ShapeActionActuator, m_localtime, CheckFrame), | ||||
| KX_PYATTRIBUTE_STRING_RW("propName", 0, MAX_PROP_NAME, false, BL_ShapeActionActuator, m_propname), | KX_PYATTRIBUTE_STRING_RW("propName", 0, MAX_PROP_NAME, false, SCA_ShapeActionActuator, m_propname), | ||||
| KX_PYATTRIBUTE_STRING_RW("framePropName", 0, MAX_PROP_NAME, false, BL_ShapeActionActuator, m_framepropname), | KX_PYATTRIBUTE_STRING_RW("framePropName", 0, MAX_PROP_NAME, false, SCA_ShapeActionActuator, m_framepropname), | ||||
| KX_PYATTRIBUTE_FLOAT_RW_CHECK("blendTime", 0, MAXFRAMEF, BL_ShapeActionActuator, m_blendframe, CheckBlendTime), | KX_PYATTRIBUTE_FLOAT_RW_CHECK("blendTime", 0, MAXFRAMEF, SCA_ShapeActionActuator, m_blendframe, CheckBlendTime), | ||||
| KX_PYATTRIBUTE_SHORT_RW_CHECK("mode",0,100,false,BL_ShapeActionActuator,m_playtype,CheckType), | KX_PYATTRIBUTE_SHORT_RW_CHECK("mode",0,100,false,SCA_ShapeActionActuator,m_playtype,CheckType), | ||||
| { NULL } //Sentinel | { NULL } //Sentinel | ||||
| }; | }; | ||||
| PyObject *BL_ShapeActionActuator::pyattr_get_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) | PyObject *SCA_ShapeActionActuator::pyattr_get_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) | ||||
| { | { | ||||
| BL_ShapeActionActuator* self = static_cast<BL_ShapeActionActuator*>(self_v); | SCA_ShapeActionActuator* self = static_cast<SCA_ShapeActionActuator*>(self_v); | ||||
| return PyUnicode_FromString(self->GetAction() ? self->GetAction()->id.name+2 : ""); | return PyUnicode_FromString(self->GetAction() ? self->GetAction()->id.name+2 : ""); | ||||
| } | } | ||||
| int BL_ShapeActionActuator::pyattr_set_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) | int SCA_ShapeActionActuator::pyattr_set_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) | ||||
| { | { | ||||
| BL_ShapeActionActuator* self = static_cast<BL_ShapeActionActuator*>(self_v); | SCA_ShapeActionActuator* self = static_cast<SCA_ShapeActionActuator*>(self_v); | ||||
| /* exact copy of BL_ActionActuator's function from here down */ | /* exact copy of SCA_ActionActuator's function from here down */ | ||||
| if (!PyUnicode_Check(value)) | if (!PyUnicode_Check(value)) | ||||
| { | { | ||||
| PyErr_SetString(PyExc_ValueError, "actuator.action = val: Shape Action Actuator, expected the string name of the action"); | PyErr_SetString(PyExc_ValueError, "actuator.action = val: Shape Action Actuator, expected the string name of the action"); | ||||
| return PY_SET_ATTR_FAIL; | return PY_SET_ATTR_FAIL; | ||||
| } | } | ||||
| bAction *action= NULL; | bAction *action= NULL; | ||||
| STR_String val = _PyUnicode_AsString(value); | STR_String val = _PyUnicode_AsString(value); | ||||
| Show All 17 Lines | |||||