diff options
author | Benoit Bolsee <benoit.bolsee@online.be> | 2011-09-07 19:34:04 +0400 |
---|---|---|
committer | Benoit Bolsee <benoit.bolsee@online.be> | 2011-09-07 19:34:04 +0400 |
commit | dbd6658d737b1592a633ddf6397be14e50e434d9 (patch) | |
tree | 57081721d70622a3c3141909b258f9bce8a5b1e3 /source/gameengine/Converter | |
parent | b5bd86e5907c3fa98546dabeda9703dfb15862f4 (diff) | |
parent | 884fc84793be1c5fdd6643ad267331381f8e1c6b (diff) |
svn merge -r 37306:39975 https://svn.blender.org/svnroot/bf-blender/trunk/blender
Diffstat (limited to 'source/gameengine/Converter')
26 files changed, 896 insertions, 778 deletions
diff --git a/source/gameengine/Converter/BL_ActionActuator.cpp b/source/gameengine/Converter/BL_ActionActuator.cpp index c00e7ec7e29..895def17e8e 100644 --- a/source/gameengine/Converter/BL_ActionActuator.cpp +++ b/source/gameengine/Converter/BL_ActionActuator.cpp @@ -36,6 +36,7 @@ #include "BL_ActionActuator.h" #include "BL_ArmatureObject.h" #include "BL_SkinDeformer.h" +#include "BL_Action.h" #include "KX_GameObject.h" #include "STR_HashedString.h" #include "MEM_guardedalloc.h" @@ -60,6 +61,49 @@ extern "C" { #include "RNA_define.h" } +BL_ActionActuator::BL_ActionActuator(SCA_IObject* gameobj, + const STR_String& propname, + const STR_String& framepropname, + float starttime, + float endtime, + struct bAction *action, + short playtype, + short blendin, + short priority, + short layer, + float layer_weight, + short ipo_flags, + short end_reset, + float stride) + : SCA_IActuator(gameobj, KX_ACT_ACTION), + + m_lastpos(0, 0, 0), + m_blendframe(0), + m_flag(0), + m_startframe (starttime), + m_endframe(endtime) , + m_starttime(0), + m_localtime(starttime), + m_lastUpdate(-1), + m_blendin(blendin), + m_blendstart(0), + m_stridelength(stride), + m_layer_weight(layer_weight), + m_playtype(playtype), + m_priority(priority), + m_layer(layer), + m_ipo_flags(ipo_flags), + m_pose(NULL), + m_blendpose(NULL), + m_userpose(NULL), + m_action(action), + m_propname(propname), + m_framepropname(framepropname) +{ + if (!end_reset) + m_flag |= ACT_FLAG_CONTINUE; +}; + BL_ActionActuator::~BL_ActionActuator() { if (m_pose) @@ -85,370 +129,220 @@ 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; -} - -bool BL_ActionActuator::ClampLocalTime() +void BL_ActionActuator::SetLocalTime(float curtime) { - if (m_startframe < m_endframe) + float dt = (curtime-m_starttime)*KX_KetsjiEngine::GetAnimFrameRate(); + + if (m_endframe < m_startframe) + dt = -dt; + + m_localtime = m_startframe + dt; + + // Handle wrap around + if (m_localtime < min(m_startframe, m_endframe) || m_localtime > max(m_startframe, m_endframe)) { - if (m_localtime < m_startframe) - { - m_localtime = m_startframe; - return true; - } - else if (m_localtime > m_endframe) + switch(m_playtype) { + case ACT_ACTION_PLAY: + // Clamp m_localtime = m_endframe; - return true; - } - } else { - if (m_localtime > m_startframe) - { + break; + case ACT_ACTION_LOOP_END: + // Put the time back to the beginning m_localtime = m_startframe; - return true; - } - else if (m_localtime < m_endframe) - { - m_localtime = m_endframe; - return true; + m_starttime = curtime; + break; + case ACT_ACTION_PINGPONG: + // Swap the start and end frames + float temp = m_startframe; + m_startframe = m_endframe; + m_endframe = temp; + + m_starttime = curtime; + + break; } } - return false; } -void BL_ActionActuator::SetStartTime(float curtime) +void BL_ActionActuator::ResetStartTime(float curtime) { - float direction = m_startframe < m_endframe ? 1.0 : -1.0; - - if (!(m_flag & ACT_FLAG_REVERSE)) - m_starttime = curtime - direction*(m_localtime - m_startframe)/KX_KetsjiEngine::GetAnimFrameRate(); - else - m_starttime = curtime - direction*(m_endframe - m_localtime)/KX_KetsjiEngine::GetAnimFrameRate(); -} + float dt = m_localtime - m_startframe; -void BL_ActionActuator::SetLocalTime(float curtime) -{ - float delta_time = (curtime - m_starttime)*KX_KetsjiEngine::GetAnimFrameRate(); - - 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; + m_starttime = curtime - dt / (KX_KetsjiEngine::GetAnimFrameRate()); + //SetLocalTime(curtime); } +CValue* BL_ActionActuator::GetReplica() { + BL_ActionActuator* replica = new BL_ActionActuator(*this);//m_float,GetName()); + replica->ProcessReplica(); + return replica; +} bool BL_ActionActuator::Update(double curtime, bool frame) { bool bNegativeEvent = false; bool bPositiveEvent = false; - bool keepgoing = true; - bool wrap = false; - bool apply=true; - int priority; - float newweight; + bool bUseContinue = false; + KX_GameObject *obj = (KX_GameObject*)GetParent(); + short playtype = BL_Action::ACT_MODE_PLAY; + float start = m_startframe; + float end = m_endframe; + + // If we don't have an action, we can't do anything + if (!m_action) + return false; + + // Convert our playtype to one that BL_Action likes + switch(m_playtype) + { + case ACT_ACTION_LOOP_END: + case ACT_ACTION_LOOP_STOP: + playtype = BL_Action::ACT_MODE_LOOP; + break; + + case ACT_ACTION_PINGPONG: + // We handle ping pong ourselves to increase compabitility + // with files made prior to animation changes from GSoC 2011. + playtype = BL_Action::ACT_MODE_PLAY; + + if (m_flag & ACT_FLAG_REVERSE) + { + m_localtime = start; + start = end; + end = m_localtime; + } + + break; + case ACT_ACTION_FROM_PROP: + CValue* prop = GetParent()->GetProperty(m_propname); + + // If we don't have a property, we can't do anything, so just bail + if (!prop) return false; - curtime -= KX_KetsjiEngine::GetSuspendedDelta(); + playtype = BL_Action::ACT_MODE_PLAY; + start = end = prop->GetNumber(); + + break; + } + + // Continue only really makes sense for play stop and flipper. All other modes go until they are complete. + if (m_flag & ACT_FLAG_CONTINUE && + (m_playtype == ACT_ACTION_LOOP_STOP || + m_playtype == ACT_ACTION_FLIPPER)) + bUseContinue = true; - // result = true if animation has to be continued, false if animation stops - // maybe there are events for us in the queue ! + + // Handle events if (frame) { bNegativeEvent = m_negevent; bPositiveEvent = m_posevent; RemoveAllEvents(); - - if (bPositiveEvent) - m_flag |= ACT_FLAG_ACTIVE; - - 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; - } } - - /* 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(); - float length = m_endframe - m_startframe; - - 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; - m_localtime = m_startframe; - m_starttime = curtime; - } - } - 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; - m_flag &= ~ACT_FLAG_KEYUP; - m_flag |= ACT_FLAG_LOCKINPUT; - SetStartTime(curtime); - } - } - if (bNegativeEvent){ - m_flag |= ACT_FLAG_KEYUP; - m_flag &= ~ACT_FLAG_LOCKINPUT; - keepgoing=false; - apply=false; - } - break; - case ACT_ACTION_PINGPONG: - if (bPositiveEvent){ - if (!(m_flag & ACT_FLAG_LOCKINPUT)){ - m_flag &= ~ACT_FLAG_KEYUP; - m_localtime = m_starttime; - m_starttime = curtime; - m_flag |= ACT_FLAG_LOCKINPUT; - } - } - break; - case ACT_ACTION_FLIPPER: - if (bPositiveEvent){ - if (!(m_flag & ACT_FLAG_LOCKINPUT)){ - m_flag &= ~ACT_FLAG_REVERSE; - m_flag |= ACT_FLAG_LOCKINPUT; - SetStartTime(curtime); - } - } - else if (bNegativeEvent){ - m_flag |= ACT_FLAG_REVERSE; - m_flag &= ~ACT_FLAG_LOCKINPUT; - SetStartTime(curtime); - } - break; - case ACT_ACTION_PLAY: - if (bPositiveEvent){ - if (!(m_flag & ACT_FLAG_LOCKINPUT)){ - m_flag &= ~ACT_FLAG_REVERSE; - m_localtime = m_starttime; - m_starttime = curtime; - m_flag |= ACT_FLAG_LOCKINPUT; - } - } - break; - default: - break; + + if (m_flag & ACT_FLAG_ATTEMPT_PLAY) + SetLocalTime(curtime); + + if (bUseContinue && (m_flag & ACT_FLAG_ACTIVE)) + { + m_localtime = obj->GetActionFrame(m_layer); + ResetStartTime(curtime); } - - /* 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{ - SetLocalTime(curtime); - } + + // Handle a frame property if it's defined + if ((m_flag & ACT_FLAG_ACTIVE) && m_framepropname[0] != 0) + { + CValue* oldprop = obj->GetProperty(m_framepropname); + CValue* newval = new CFloatValue(obj->GetActionFrame(m_layer)); + if (oldprop) + oldprop->SetValue(newval); + else + obj->SetProperty(m_framepropname, newval); + + newval->Release(); } - - /* Check if a wrapping response is needed */ - if (length){ - if (m_localtime < m_startframe || m_localtime > m_endframe) - { - m_localtime = m_startframe + fmod(m_localtime, length); - wrap = true; - } + + // Handle a finished animation + if ((m_flag & ACT_FLAG_PLAY_END) && obj->IsActionDone(m_layer)) + { + m_flag &= ~ACT_FLAG_ACTIVE; + m_flag &= ~ACT_FLAG_ATTEMPT_PLAY; + obj->StopAction(m_layer); + return false; } - else - m_localtime = m_startframe; - /* Perform post-increment tasks */ - switch (m_playtype){ - case ACT_ACTION_FROM_PROP: + // If a different action is playing, we've been overruled and are no longer active + if (obj->GetCurrentAction(m_layer) != m_action) + m_flag &= ~ACT_FLAG_ACTIVE; + + if (bPositiveEvent || (m_flag & ACT_FLAG_ATTEMPT_PLAY && !(m_flag & ACT_FLAG_ACTIVE))) + { + if (bPositiveEvent) + ResetStartTime(curtime); + + if (obj->PlayAction(m_action->id.name+2, start, end, m_layer, m_priority, m_blendin, playtype, m_layer_weight, m_ipo_flags)) { - CValue* propval = GetParent()->GetProperty(m_propname); - if (propval) - m_localtime = propval->GetNumber(); - - if (bNegativeEvent){ - keepgoing=false; - } - } - break; - case ACT_ACTION_MOTION: - break; - case ACT_ACTION_LOOP_STOP: - break; - case ACT_ACTION_PINGPONG: - if (wrap){ - if (!(m_flag & ACT_FLAG_REVERSE)) - m_localtime = m_endframe; - else - m_localtime = m_startframe; - - m_flag &= ~ACT_FLAG_LOCKINPUT; - m_flag ^= ACT_FLAG_REVERSE; //flip direction - keepgoing = false; - } - break; - case ACT_ACTION_FLIPPER: - if (wrap){ - if (!(m_flag & ACT_FLAG_REVERSE)){ - m_localtime=m_endframe; - //keepgoing = false; - } - else { - m_localtime=m_startframe; - keepgoing = false; - } - } - break; - case ACT_ACTION_LOOP_END: - if (wrap){ - if (m_flag & ACT_FLAG_KEYUP){ - keepgoing = false; - m_localtime = m_endframe; - m_flag &= ~ACT_FLAG_LOCKINPUT; - } - SetStartTime(curtime); - } - break; - case ACT_ACTION_PLAY: - if (wrap){ - m_localtime = m_endframe; - keepgoing = false; - m_flag &= ~ACT_FLAG_LOCKINPUT; + m_flag |= ACT_FLAG_ACTIVE; + if (bUseContinue) + obj->SetActionFrame(m_layer, m_localtime); + + if (m_playtype == ACT_ACTION_PLAY) + m_flag |= ACT_FLAG_PLAY_END; + else + m_flag &= ~ACT_FLAG_PLAY_END; } - break; - default: - keepgoing = false; - break; + m_flag |= ACT_FLAG_ATTEMPT_PLAY; } - - /* Set the property if its defined */ - if (m_framepropname[0] != '\0') { - 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); + else if ((m_flag & ACT_FLAG_ACTIVE) && bNegativeEvent) + { + m_flag &= ~ACT_FLAG_ATTEMPT_PLAY; + bAction *curr_action = obj->GetCurrentAction(m_layer); + if (curr_action && curr_action != m_action) + { + // Someone changed the action on us, so we wont mess with it + // Hopefully there wont be too many problems with two actuators using + // the same action... + m_flag &= ~ACT_FLAG_ACTIVE; + return false; } - newval->Release(); - } - - if (bNegativeEvent) - 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); - -// 2.4x function, - /* Override the necessary channels with ones from the action */ - // XXX extract_pose_from_action(m_pose, m_action, m_localtime); - - -// 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); - } - // done getting the pose from the action - - /* Perform the user override (if any) */ - if (m_userpose){ - extract_pose_from_pose(m_pose, m_userpose); - game_free_pose(m_userpose); //cant use MEM_freeN(m_userpose) because the channels need freeing too. - 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); - m_blendstart = curtime; - } - - /* Find percentages */ - newweight = (m_blendframe/(float)m_blendin); - game_blend_poses(m_pose, m_blendpose, 1.0 - newweight); - - /* Increment current blending percentage */ - m_blendframe = (curtime - m_blendstart)*KX_KetsjiEngine::GetAnimFrameRate(); - if (m_blendframe>m_blendin) - m_blendframe = m_blendin; - - } -#endif - m_lastUpdate = m_localtime; - obj->SetPose (m_pose); - } - else{ - m_blendframe = 0.0; + + m_localtime = obj->GetActionFrame(m_layer); + if (m_localtime < min(m_startframe, m_endframe) || m_localtime > max(m_startframe, m_endframe)) + m_localtime = m_startframe; + + switch(m_playtype) + { + case ACT_ACTION_LOOP_STOP: + obj->StopAction(m_layer); // Stop the action after getting the frame + + // We're done + m_flag &= ~ACT_FLAG_ACTIVE; + return false; + case ACT_ACTION_PINGPONG: + m_flag ^= ACT_FLAG_REVERSE; + // Now fallthrough to LOOP_END code + case ACT_ACTION_LOOP_END: + // Convert into a play and let it finish + obj->SetPlayMode(m_layer, BL_Action::ACT_MODE_PLAY); + + m_flag |= ACT_FLAG_PLAY_END; + break; + + case ACT_ACTION_FLIPPER: + // Convert into a play action and play back to the beginning + end = start; + start = obj->GetActionFrame(m_layer); + obj->PlayAction(m_action->id.name+2, start, end, m_layer, m_priority, 0, BL_Action::ACT_MODE_PLAY, m_layer_weight, m_ipo_flags); + + m_flag |= ACT_FLAG_PLAY_END; + break; } } - - if (!keepgoing){ - m_blendframe = 0.0; - } - return keepgoing; -}; + + return true; +} #ifdef WITH_PYTHON @@ -633,10 +527,10 @@ PyAttributeDef BL_ActionActuator::Attributes[] = { KX_PYATTRIBUTE_RW_FUNCTION("action", BL_ActionActuator, pyattr_get_action, pyattr_set_action), KX_PYATTRIBUTE_RO_FUNCTION("channelNames", BL_ActionActuator, pyattr_get_channel_names), 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), + KX_PYATTRIBUTE_RW_FUNCTION("frame", BL_ActionActuator, pyattr_get_frame, pyattr_set_frame), 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), + KX_PYATTRIBUTE_RW_FUNCTION("useContinue", BL_ActionActuator, pyattr_get_use_continue, pyattr_set_use_continue), KX_PYATTRIBUTE_FLOAT_RW_CHECK("blendTime", 0, MAXFRAMEF, BL_ActionActuator, m_blendframe, CheckBlendTime), KX_PYATTRIBUTE_SHORT_RW_CHECK("mode",0,100,false,BL_ActionActuator,m_playtype,CheckType), { NULL } //Sentinel @@ -696,4 +590,37 @@ PyObject* BL_ActionActuator::pyattr_get_channel_names(void *self_v, const KX_PYA return ret; } +PyObject* BL_ActionActuator::pyattr_get_use_continue(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + BL_ActionActuator* self= static_cast<BL_ActionActuator*>(self_v); + return PyBool_FromLong(self->m_flag & ACT_FLAG_CONTINUE); +} + +int BL_ActionActuator::pyattr_set_use_continue(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + BL_ActionActuator* self= static_cast<BL_ActionActuator*>(self_v); + + if (PyObject_IsTrue(value)) + self->m_flag |= ACT_FLAG_CONTINUE; + else + self->m_flag &= ~ACT_FLAG_CONTINUE; + + return PY_SET_ATTR_SUCCESS; +} + +PyObject* BL_ActionActuator::pyattr_get_frame(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + BL_ActionActuator* self= static_cast<BL_ActionActuator*>(self_v); + return PyFloat_FromDouble(((KX_GameObject*)self->m_gameobj)->GetActionFrame(self->m_layer)); +} + +int BL_ActionActuator::pyattr_set_frame(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + BL_ActionActuator* self= static_cast<BL_ActionActuator*>(self_v); + + ((KX_GameObject*)self->m_gameobj)->SetActionFrame(self->m_layer, PyFloat_AsDouble(value)); + + return PY_SET_ATTR_SUCCESS; +} + #endif // WITH_PYTHON diff --git a/source/gameengine/Converter/BL_ActionActuator.h b/source/gameengine/Converter/BL_ActionActuator.h index ff4ca785a96..357c2b4a05e 100644 --- a/source/gameengine/Converter/BL_ActionActuator.h +++ b/source/gameengine/Converter/BL_ActionActuator.h @@ -52,38 +52,20 @@ public: short playtype, short blendin, short priority, + short layer, + float layer_weight, + short ipo_flags, short end_reset, - float stride) - : SCA_IActuator(gameobj, KX_ACT_ACTION), - - m_lastpos(0, 0, 0), - m_blendframe(0), - m_flag(0), - m_startframe (starttime), - m_endframe(endtime) , - m_starttime(0), - m_localtime(starttime), - m_lastUpdate(-1), - m_blendin(blendin), - m_blendstart(0), - m_stridelength(stride), - m_playtype(playtype), - m_priority(priority), - m_end_reset(end_reset), - m_pose(NULL), - m_blendpose(NULL), - m_userpose(NULL), - m_action(action), - m_propname(propname), - m_framepropname(framepropname) - { - }; + float stride); + virtual ~BL_ActionActuator(); virtual bool Update(double curtime, bool frame); virtual CValue* GetReplica(); virtual void ProcessReplica(); void SetBlendTime (float newtime); + void SetLocalTime (float curtime); + void ResetStartTime (float curtime); bAction* GetAction() { return m_action; } void SetAction(bAction* act) { m_action= act; } @@ -96,18 +78,10 @@ public: static PyObject* pyattr_get_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); static int pyattr_set_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); static PyObject* pyattr_get_channel_names(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); - /* attribute check */ - static int CheckFrame(void *self, const PyAttributeDef*) - { - BL_ActionActuator* act = reinterpret_cast<BL_ActionActuator*>(self); - - if (act->m_localtime < act->m_startframe) - act->m_localtime = act->m_startframe; - else if (act->m_localtime > act->m_endframe) - act->m_localtime = act->m_endframe; - - return 0; - } + static PyObject* pyattr_get_use_continue(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_set_use_continue(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static PyObject* pyattr_get_frame(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_set_frame(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); static int CheckBlendTime(void *self, const PyAttributeDef*) { @@ -139,11 +113,6 @@ public: #endif // WITH_PYTHON protected: - - void SetStartTime(float curtime); - void SetLocalTime(float curtime); - bool ClampLocalTime(); - MT_Point3 m_lastpos; float m_blendframe; int m_flag; @@ -160,9 +129,11 @@ protected: float m_blendin; float m_blendstart; float m_stridelength; + float m_layer_weight; short m_playtype; short m_priority; - bool m_end_reset; + short m_layer; + short m_ipo_flags; struct bPose* m_pose; struct bPose* m_blendpose; struct bPose* m_userpose; @@ -171,11 +142,17 @@ protected: STR_String m_framepropname; }; +// Not all of these values are used in BL_ActionActuator anymore, +// but BL_ShapeActionActuator still uses them, so we keep them around +// for now. enum { - ACT_FLAG_REVERSE = 0x00000001, - ACT_FLAG_LOCKINPUT = 0x00000002, - ACT_FLAG_KEYUP = 0x00000004, - ACT_FLAG_ACTIVE = 0x00000008 + ACT_FLAG_REVERSE = 1<<0, + ACT_FLAG_LOCKINPUT = 1<<1, + ACT_FLAG_KEYUP = 1<<2, + ACT_FLAG_ACTIVE = 1<<3, + ACT_FLAG_CONTINUE = 1<<4, + ACT_FLAG_PLAY_END = 1<<5, + ACT_FLAG_ATTEMPT_PLAY = 1<<6, }; #endif diff --git a/source/gameengine/Converter/BL_ArmatureObject.cpp b/source/gameengine/Converter/BL_ArmatureObject.cpp index c6c20a96482..684bd3f341e 100644 --- a/source/gameengine/Converter/BL_ArmatureObject.cpp +++ b/source/gameengine/Converter/BL_ArmatureObject.cpp @@ -218,7 +218,8 @@ BL_ArmatureObject::BL_ArmatureObject( void* sgReplicationInfo, SG_Callbacks callbacks, Object *armature, - Scene *scene) + Scene *scene, + int vert_deform_type) : KX_GameObject(sgReplicationInfo,callbacks), m_controlledConstraints(), @@ -230,6 +231,7 @@ BL_ArmatureObject::BL_ArmatureObject( m_timestep(0.040), m_activeAct(NULL), m_activePriority(999), + m_vert_deform_type(vert_deform_type), m_constraintNumber(0), m_channelNumber(0), m_lastapplyframe(0.0) @@ -298,6 +300,7 @@ void BL_ArmatureObject::LoadConstraints(KX_BlenderSceneConverter* converter) case CONSTRAINT_TYPE_CLAMPTO: case CONSTRAINT_TYPE_TRANSFORM: case CONSTRAINT_TYPE_DISTLIMIT: + case CONSTRAINT_TYPE_TRANSLIKE: cti = constraint_get_typeinfo(pcon); gametarget = gamesubtarget = NULL; if (cti && cti->get_constraint_targets) { diff --git a/source/gameengine/Converter/BL_ArmatureObject.h b/source/gameengine/Converter/BL_ArmatureObject.h index 2c3ca7404b3..1467f05c1bd 100644 --- a/source/gameengine/Converter/BL_ArmatureObject.h +++ b/source/gameengine/Converter/BL_ArmatureObject.h @@ -69,7 +69,8 @@ public: void* sgReplicationInfo, SG_Callbacks callbacks, Object *armature, - Scene *scene + Scene *scene, + int vert_deform_type ); virtual ~BL_ArmatureObject(); @@ -90,6 +91,8 @@ public: Object* GetArmatureObject() {return m_objArma;} + int GetVertDeformType() {return m_vert_deform_type;} + // for constraint python API void LoadConstraints(KX_BlenderSceneConverter* converter); size_t GetConstraintNumber() const { return m_constraintNumber; } @@ -136,6 +139,7 @@ protected: double m_timestep; // delta since last pose evaluation. class BL_ActionActuator *m_activeAct; short m_activePriority; + int m_vert_deform_type; size_t m_constraintNumber; size_t m_channelNumber; // store the original armature object matrix diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp index 4b475a4b5e7..d4b43cd7ac1 100644 --- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp +++ b/source/gameengine/Converter/BL_BlenderDataConversion.cpp @@ -353,6 +353,8 @@ bool ConvertMaterial( // use lighting? material->ras_mode |= ( mat->mode & MA_SHLESS )?0:USE_LIGHT; + // cast shadows? + material->ras_mode |= ( mat->mode & MA_SHADBUF )?CAST_SHADOW:0; MTex *mttmp = 0; numchan = getNumTexChannels(mat); int valid_index = 0; @@ -1484,7 +1486,7 @@ void BL_CreatePhysicsObjectNew(KX_GameObject* gameobj, { objprop.m_gamesoftFlag = OB_BSB_BENDING_CONSTRAINTS | OB_BSB_SHAPE_MATCHING | OB_BSB_AERO_VPOINT; - objprop.m_soft_linStiff = 0.5;; + objprop.m_soft_linStiff = 0.5; objprop.m_soft_angStiff = 1.f; /* angular stiffness 0..1 */ objprop.m_soft_volume= 1.f; /* volume preservation 0..1 */ @@ -1685,8 +1687,6 @@ static KX_LightObject *gamelight_from_blamp(Object *ob, Lamp *la, unsigned int l gamelight = new KX_LightObject(kxscene, KX_Scene::m_callbacks, rendertools, lightobj, glslmat); - - BL_ConvertLampIpos(la, gamelight, converter); return gamelight; } @@ -1699,8 +1699,6 @@ static KX_Camera *gamecamera_from_bcamera(Object *ob, KX_Scene *kxscene, KX_Blen gamecamera= new KX_Camera(kxscene, KX_Scene::m_callbacks, camdata); gamecamera->SetName(ca->id.name + 2); - BL_ConvertCameraIpos(ca, gamecamera, converter); - return gamecamera; } @@ -1817,11 +1815,13 @@ static KX_GameObject *gameobject_from_blenderobject( case OB_ARMATURE: { + bArmature *arm = (bArmature*)ob->data; gameobj = new BL_ArmatureObject( kxscene, KX_Scene::m_callbacks, ob, - kxscene->GetBlenderScene() // handle + kxscene->GetBlenderScene(), // handle + arm->gevertdeformer ); /* Get the current pose from the armature object and apply it as the rest pose */ break; @@ -1850,7 +1850,6 @@ static KX_GameObject *gameobject_from_blenderobject( { gameobj->SetLayer(ob->lay); gameobj->SetBlenderObject(ob); - gameobj->SetObjectColor(ob->col); /* set the visibility state based on the objects render option in the outliner */ if(ob->restrictflag & OB_RESTRICT_RENDER) gameobj->SetVisible(0, 0); } @@ -1922,11 +1921,11 @@ void RBJconstraints(Object *ob)//not used KX_IPhysicsController* getPhId(CListValue* sumolist,STR_String busc){//not used - for (int j=0;j<sumolist->GetCount();j++) + for (int j=0;j<sumolist->GetCount();j++) { - KX_GameObject* gameobje = (KX_GameObject*) sumolist->GetValue(j); - if (gameobje->GetName()==busc) - return gameobje->GetPhysicsController(); + KX_GameObject* gameobje = (KX_GameObject*) sumolist->GetValue(j); + if (gameobje->GetName()==busc) + return gameobje->GetPhysicsController(); } return 0; @@ -1935,11 +1934,11 @@ KX_IPhysicsController* getPhId(CListValue* sumolist,STR_String busc){//not used KX_GameObject* getGameOb(STR_String busc,CListValue* sumolist){ - for (int j=0;j<sumolist->GetCount();j++) + for (int j=0;j<sumolist->GetCount();j++) { - KX_GameObject* gameobje = (KX_GameObject*) sumolist->GetValue(j); - if (gameobje->GetName()==busc) - return gameobje; + KX_GameObject* gameobje = (KX_GameObject*) sumolist->GetValue(j); + if (gameobje->GetName()==busc) + return gameobje; } return 0; @@ -1987,8 +1986,8 @@ void BL_ConvertBlenderObjects(struct Main* maggie, frame_type = RAS_FrameSettings::e_frame_scale; } - aspect_width = blenderscene->gm.xsch; - aspect_height = blenderscene->gm.ysch; + aspect_width = blenderscene->r.xsch*blenderscene->r.xasp; + aspect_height = blenderscene->r.ysch*blenderscene->r.yasp; } RAS_FrameSettings frame_settings( @@ -2101,8 +2100,7 @@ void BL_ConvertBlenderObjects(struct Main* maggie, gameobj->NodeSetLocalOrientation(MT_Matrix3x3(eulxyz)); gameobj->NodeSetLocalScale(scale); gameobj->NodeUpdateGS(0); - - BL_ConvertIpos(blenderobject,gameobj,converter); + BL_ConvertMaterialIpos(blenderobject, gameobj, converter); sumolist->Add(gameobj->AddRef()); @@ -2291,8 +2289,7 @@ void BL_ConvertBlenderObjects(struct Main* maggie, gameobj->NodeSetLocalOrientation(MT_Matrix3x3(eulxyz)); gameobj->NodeSetLocalScale(scale); gameobj->NodeUpdateGS(0); - - BL_ConvertIpos(blenderobject,gameobj,converter); + BL_ConvertMaterialIpos(blenderobject,gameobj, converter); sumolist->Add(gameobj->AddRef()); @@ -2642,7 +2639,7 @@ void BL_ConvertBlenderObjects(struct Main* maggie, { PHY_IPhysicsController* physctrl = (PHY_IPhysicsController*) gameobj->GetPhysicsController()->GetUserData(); //we need to pass a full constraint frame, not just axis - + //localConstraintFrameBasis MT_Matrix3x3 localCFrame(MT_Vector3(dat->axX,dat->axY,dat->axZ)); MT_Vector3 axis0 = localCFrame.getColumn(0); diff --git a/source/gameengine/Converter/BL_DeformableGameObject.cpp b/source/gameengine/Converter/BL_DeformableGameObject.cpp index bfba054d0d4..48392ee8dda 100644 --- a/source/gameengine/Converter/BL_DeformableGameObject.cpp +++ b/source/gameengine/Converter/BL_DeformableGameObject.cpp @@ -87,15 +87,16 @@ bool BL_DeformableGameObject::SetActiveAction(BL_ShapeActionActuator *act, short bool BL_DeformableGameObject::GetShape(vector<float> &shape) { shape.clear(); - if (m_pDeformer) + BL_ShapeDeformer* shape_deformer = dynamic_cast<BL_ShapeDeformer*>(m_pDeformer); + if (shape_deformer) { - Mesh* mesh = ((BL_MeshDeformer*)m_pDeformer)->GetMesh(); // this check is normally superfluous: a shape deformer can only be created if the mesh // has relative keys - if (mesh && mesh->key && mesh->key->type==KEY_RELATIVE) + Key* key = shape_deformer->GetKey(); + if (key && key->type==KEY_RELATIVE) { KeyBlock *kb; - for (kb = (KeyBlock*)mesh->key->block.first; kb; kb = (KeyBlock*)kb->next) + for (kb = (KeyBlock*)key->block.first; kb; kb = (KeyBlock*)kb->next) { shape.push_back(kb->curval); } diff --git a/source/gameengine/Converter/BL_DeformableGameObject.h b/source/gameengine/Converter/BL_DeformableGameObject.h index 615bb84ac2b..3ba55664007 100644 --- a/source/gameengine/Converter/BL_DeformableGameObject.h +++ b/source/gameengine/Converter/BL_DeformableGameObject.h @@ -82,23 +82,6 @@ public: bool SetActiveAction(class BL_ShapeActionActuator *act, short priority, double curtime); bool GetShape(vector<float> &shape); - Key* GetKey() - { - if(m_pDeformer) { - BL_MeshDeformer *deformer= dynamic_cast<BL_MeshDeformer *>(m_pDeformer); // incase its not a MeshDeformer - if(deformer) { - return deformer->GetMesh()->key; - } - -#if 0 // TODO. shape keys for softbody, currently they dont store a mesh. - KX_SoftBodyDeformer *deformer_soft= dynamic_cast<KX_SoftBodyDeformer *>(m_pDeformer); - if(deformer) { - return deformer->GetMesh()->key; - } -#endif - } - return NULL; - } virtual void SetDeformer(class RAS_Deformer* deformer); virtual class RAS_Deformer* GetDeformer() diff --git a/source/gameengine/Converter/BL_MeshDeformer.h b/source/gameengine/Converter/BL_MeshDeformer.h index 90466e930fb..0968478ce7e 100644 --- a/source/gameengine/Converter/BL_MeshDeformer.h +++ b/source/gameengine/Converter/BL_MeshDeformer.h @@ -88,7 +88,7 @@ protected: // -- int m_tvtot; BL_DeformableGameObject* m_gameobj; - double m_lastDeformUpdate; + double m_lastDeformUpdate; #ifdef WITH_CXX_GUARDEDALLOC diff --git a/source/gameengine/Converter/BL_ShapeActionActuator.cpp b/source/gameengine/Converter/BL_ShapeActionActuator.cpp index bb53c2d6fe6..ac377cdb7ca 100644 --- a/source/gameengine/Converter/BL_ShapeActionActuator.cpp +++ b/source/gameengine/Converter/BL_ShapeActionActuator.cpp @@ -59,10 +59,49 @@ extern "C" { #include "BKE_animsys.h" + #include "BKE_key.h" + #include "RNA_access.h" } +BL_ShapeActionActuator::BL_ShapeActionActuator(SCA_IObject* gameobj, + const STR_String& propname, + const STR_String& framepropname, + float starttime, + float endtime, + struct bAction *action, + short playtype, + short blendin, + short priority, + float stride) + : SCA_IActuator(gameobj, KX_ACT_SHAPEACTION), + + m_lastpos(0, 0, 0), + m_blendframe(0), + m_flag(0), + m_startframe (starttime), + m_endframe(endtime) , + m_starttime(0), + m_localtime(starttime), + m_lastUpdate(-1), + m_blendin(blendin), + m_blendstart(0), + m_stridelength(stride), + m_playtype(playtype), + m_priority(priority), + m_action(action), + m_framepropname(framepropname), + m_propname(propname) +{ + m_idptr = new PointerRNA(); + BL_DeformableGameObject *obj = (BL_DeformableGameObject*)GetParent(); + BL_ShapeDeformer *shape_deformer = dynamic_cast<BL_ShapeDeformer*>(obj->GetDeformer()); + RNA_id_pointer_create(&shape_deformer->GetKey()->id, m_idptr); +}; + BL_ShapeActionActuator::~BL_ShapeActionActuator() { + if (m_idptr) + delete m_idptr; } void BL_ShapeActionActuator::ProcessReplica() @@ -382,7 +421,11 @@ bool BL_ShapeActionActuator::Update(double curtime, bool frame) /* Priority test */ if (obj->SetActiveAction(this, priority, curtime)){ - Key *key = obj->GetKey(); + BL_ShapeDeformer *shape_deformer = dynamic_cast<BL_ShapeDeformer*>(obj->GetDeformer()); + Key *key = NULL; + + if (shape_deformer) + key = shape_deformer->GetKey(); if (!key) { // this could happen if the mesh was changed in the middle of an action @@ -397,10 +440,14 @@ bool BL_ShapeActionActuator::Update(double curtime, bool frame) obj->GetShape(m_blendshape); m_blendstart = curtime; } - // only interested in shape channel - // in 2.4x was // extract_ipochannels_from_action(&tchanbase, &key->id, m_action, "Shape", m_localtime); - BKE_animsys_evaluate_animdata(&key->id, key->adt, m_localtime, ADT_RECALC_ANIM); + KeyBlock *kb; + // We go through and clear out the keyblocks so there isn't any interference + // from other shape actions + for (kb=(KeyBlock*)key->block.first; kb; kb=(KeyBlock*)kb->next) + kb->curval = 0.f; + + animsys_evaluate_action(m_idptr, m_action, NULL, m_localtime); // XXX - in 2.5 theres no way to do this. possibly not that important to support - Campbell if (0) { // XXX !execute_ipochannels(&tchanbase)) { diff --git a/source/gameengine/Converter/BL_ShapeActionActuator.h b/source/gameengine/Converter/BL_ShapeActionActuator.h index 7a4523d4554..efd24fc305f 100644 --- a/source/gameengine/Converter/BL_ShapeActionActuator.h +++ b/source/gameengine/Converter/BL_ShapeActionActuator.h @@ -54,27 +54,7 @@ public: short playtype, short blendin, short priority, - float stride) - : SCA_IActuator(gameobj, KX_ACT_SHAPEACTION), - - m_lastpos(0, 0, 0), - m_blendframe(0), - m_flag(0), - m_startframe (starttime), - m_endframe(endtime) , - m_starttime(0), - m_localtime(starttime), - m_lastUpdate(-1), - m_blendin(blendin), - m_blendstart(0), - m_stridelength(stride), - m_playtype(playtype), - m_priority(priority), - m_action(action), - m_framepropname(framepropname), - m_propname(propname) - { - }; + float stride); virtual ~BL_ShapeActionActuator(); virtual bool Update(double curtime, bool frame); virtual CValue* GetReplica(); @@ -160,6 +140,7 @@ protected: STR_String m_framepropname; STR_String m_propname; vector<float> m_blendshape; + struct PointerRNA *m_idptr; }; #endif diff --git a/source/gameengine/Converter/BL_ShapeDeformer.cpp b/source/gameengine/Converter/BL_ShapeDeformer.cpp index 8d8f149bb6c..f4c683f60ba 100644 --- a/source/gameengine/Converter/BL_ShapeDeformer.cpp +++ b/source/gameengine/Converter/BL_ShapeDeformer.cpp @@ -44,13 +44,12 @@ #include "RAS_MeshObject.h" //#include "BL_ArmatureController.h" +#include "DNA_anim_types.h" #include "DNA_armature_types.h" #include "DNA_action_types.h" #include "DNA_key_types.h" #include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" -#include "DNA_ipo_types.h" -#include "DNA_curve_types.h" #include "BKE_armature.h" #include "BKE_action.h" #include "BKE_key.h" @@ -59,6 +58,7 @@ extern "C"{ #include "BKE_lattice.h" + #include "BKE_animsys.h" } @@ -68,9 +68,42 @@ extern "C"{ #define __NLA_DEFNORMALS //#undef __NLA_DEFNORMALS +BL_ShapeDeformer::BL_ShapeDeformer(BL_DeformableGameObject *gameobj, + Object *bmeshobj, + RAS_MeshObject *mesh) + : + BL_SkinDeformer(gameobj,bmeshobj, mesh), + m_useShapeDrivers(false), + m_lastShapeUpdate(-1) +{ + m_key = m_bmesh->key; + m_bmesh->key = copy_key(m_key); +}; + +/* this second constructor is needed for making a mesh deformable on the fly. */ +BL_ShapeDeformer::BL_ShapeDeformer(BL_DeformableGameObject *gameobj, + Object *bmeshobj_old, + Object *bmeshobj_new, + RAS_MeshObject *mesh, + bool release_object, + bool recalc_normal, + BL_ArmatureObject* arma) + : + BL_SkinDeformer(gameobj, bmeshobj_old, bmeshobj_new, mesh, release_object, recalc_normal, arma), + m_useShapeDrivers(false), + m_lastShapeUpdate(-1) +{ + m_key = m_bmesh->key; + m_bmesh->key = copy_key(m_key); +}; BL_ShapeDeformer::~BL_ShapeDeformer() { + if (m_key && m_bmesh->key) + { + free_key(m_bmesh->key); + m_bmesh->key = m_key; + } }; RAS_Deformer *BL_ShapeDeformer::GetReplica() @@ -90,45 +123,23 @@ void BL_ShapeDeformer::ProcessReplica() bool BL_ShapeDeformer::LoadShapeDrivers(Object* arma) { - IpoCurve *icu; - - m_shapeDrivers.clear(); - // check if this mesh has armature driven shape keys - if (m_bmesh->key && m_bmesh->key->ipo) { - for(icu= (IpoCurve*)m_bmesh->key->ipo->curve.first; icu; icu= (IpoCurve*)icu->next) { - if(icu->driver && - (icu->flag & IPO_MUTE) == 0 && - icu->driver->type == IPO_DRIVER_TYPE_NORMAL && - icu->driver->ob == arma && - icu->driver->blocktype == ID_AR) { - // this shape key ipo curve has a driver on the parent armature - // record this curve in the shape deformer so that the corresponding - m_shapeDrivers.push_back(icu); - } - } - } - return !m_shapeDrivers.empty(); + // This used to check if we had drivers from this armature, + // now we just assume we want to use shape drivers + // and let the animsys handle things. + m_useShapeDrivers = true; + + return true; } bool BL_ShapeDeformer::ExecuteShapeDrivers(void) { - if (!m_shapeDrivers.empty() && PoseUpdated()) { - vector<IpoCurve*>::iterator it; -// void *poin; -// int type; - + if (m_useShapeDrivers && PoseUpdated()) { // the shape drivers use the bone matrix as input. Must // update the matrix now m_armobj->ApplyPose(); - for (it=m_shapeDrivers.begin(); it!=m_shapeDrivers.end(); it++) { - // no need to set a specific time: this curve has a driver - // XXX IpoCurve *icu = *it; - //calc_icu(icu, 1.0f); - //poin = get_ipo_poin((ID*)m_bmesh->key, icu, &type); - //if (poin) - // write_ipo_poin(poin, type, icu->curval); - } + // We don't need an actual time, just use 0 + BKE_animsys_evaluate_animdata(NULL, &GetKey()->id, GetKey()->adt, 0.f, ADT_RECALC_DRIVERS); ForceUpdate(); m_armobj->RestorePose(); @@ -190,3 +201,13 @@ bool BL_ShapeDeformer::Update(void) } return bSkinUpdate; } + +Key *BL_ShapeDeformer::GetKey() +{ + return m_bmesh->key; +} + +void BL_ShapeDeformer::SetKey(Key *key) +{ + m_bmesh->key = key; +} diff --git a/source/gameengine/Converter/BL_ShapeDeformer.h b/source/gameengine/Converter/BL_ShapeDeformer.h index 8115af59d27..609603ae52b 100644 --- a/source/gameengine/Converter/BL_ShapeDeformer.h +++ b/source/gameengine/Converter/BL_ShapeDeformer.h @@ -42,19 +42,12 @@ #include "BL_DeformableGameObject.h" #include <vector> -struct IpoCurve; - class BL_ShapeDeformer : public BL_SkinDeformer { public: BL_ShapeDeformer(BL_DeformableGameObject *gameobj, - Object *bmeshobj, - RAS_MeshObject *mesh) - : - BL_SkinDeformer(gameobj,bmeshobj, mesh), - m_lastShapeUpdate(-1) - { - }; + Object *bmeshobj, + RAS_MeshObject *mesh); /* this second constructor is needed for making a mesh deformable on the fly. */ BL_ShapeDeformer(BL_DeformableGameObject *gameobj, @@ -63,12 +56,7 @@ public: class RAS_MeshObject *mesh, bool release_object, bool recalc_normal, - BL_ArmatureObject* arma = NULL) - : - BL_SkinDeformer(gameobj, bmeshobj_old, bmeshobj_new, mesh, release_object, recalc_normal, arma), - m_lastShapeUpdate(-1) - { - }; + BL_ArmatureObject* arma = NULL); virtual RAS_Deformer *GetReplica(); virtual void ProcessReplica(); @@ -78,14 +66,18 @@ public: bool LoadShapeDrivers(Object* arma); bool ExecuteShapeDrivers(void); + struct Key *GetKey(); + void SetKey(struct Key *key); + void ForceUpdate() { m_lastShapeUpdate = -1.0; }; protected: - vector<IpoCurve*> m_shapeDrivers; - double m_lastShapeUpdate; + bool m_useShapeDrivers; + double m_lastShapeUpdate; + struct Key* m_key; #ifdef WITH_CXX_GUARDEDALLOC diff --git a/source/gameengine/Converter/BL_SkinDeformer.cpp b/source/gameengine/Converter/BL_SkinDeformer.cpp index 34f9cb56c27..98afcf877a1 100644 --- a/source/gameengine/Converter/BL_SkinDeformer.cpp +++ b/source/gameengine/Converter/BL_SkinDeformer.cpp @@ -36,6 +36,10 @@ #pragma warning (disable : 4786) #endif //WIN32 +// Eigen2 stuff used for BGEDeformVerts +#include <Eigen/Core> +#include <Eigen/LU> + #include "BL_SkinDeformer.h" #include "CTR_Map.h" #include "STR_HashedString.h" @@ -54,6 +58,7 @@ extern "C"{ #include "BKE_lattice.h" + #include "BKE_deform.h" } @@ -74,7 +79,9 @@ BL_SkinDeformer::BL_SkinDeformer(BL_DeformableGameObject *gameobj, //m_defbase(&bmeshobj->defbase), m_releaseobject(false), m_poseApplied(false), - m_recalcNormal(true) + m_recalcNormal(true), + m_copyNormals(false), + m_dfnrToPC(NULL) { copy_m4_m4(m_obmat, bmeshobj->obmat); }; @@ -92,7 +99,9 @@ BL_SkinDeformer::BL_SkinDeformer( m_lastArmaUpdate(-1), //m_defbase(&bmeshobj_old->defbase), m_releaseobject(release_object), - m_recalcNormal(recalc_normal) + m_recalcNormal(recalc_normal), + m_copyNormals(false), + m_dfnrToPC(NULL) { // this is needed to ensure correct deformation of mesh: // the deformation is done with Blender's armature_deform_verts() function @@ -106,6 +115,8 @@ BL_SkinDeformer::~BL_SkinDeformer() { if(m_releaseobject && m_armobj) m_armobj->Release(); + if(m_dfnrToPC) + delete [] m_dfnrToPC; } void BL_SkinDeformer::Relink(CTR_Map<class CTR_HashedPtr, void*>*map) @@ -152,9 +163,14 @@ bool BL_SkinDeformer::Apply(RAS_IPolyMaterial *mat) for(i=it.startvertex; i<it.endvertex; i++) { RAS_TexVert& v = it.vertex[i]; v.SetXYZ(m_transverts[v.getOrigIndex()]); + if (m_copyNormals) + v.SetNormal(m_transnors[v.getOrigIndex()]); } } } + + if (m_copyNormals) + m_copyNormals = false; } return true; } @@ -174,19 +190,124 @@ void BL_SkinDeformer::ProcessReplica() BL_MeshDeformer::ProcessReplica(); m_lastArmaUpdate = -1; m_releaseobject = false; + m_dfnrToPC = NULL; +} + +void BL_SkinDeformer::BlenderDeformVerts() +{ + float obmat[4][4]; // the original object matrix + Object* par_arma = m_armobj->GetArmatureObject(); + + // save matrix first + copy_m4_m4(obmat, m_objMesh->obmat); + // set reference matrix + copy_m4_m4(m_objMesh->obmat, m_obmat); + + armature_deform_verts( par_arma, m_objMesh, NULL, m_transverts, NULL, m_bmesh->totvert, ARM_DEF_VGROUP, NULL, NULL ); + + // restore matrix + copy_m4_m4(m_objMesh->obmat, obmat); + +#ifdef __NLA_DEFNORMALS + if (m_recalcNormal) + RecalcNormals(); +#endif +} + +void BL_SkinDeformer::BGEDeformVerts() +{ + Object *par_arma = m_armobj->GetArmatureObject(); + MDeformVert *dverts = m_bmesh->dvert; + bDeformGroup *dg; + int numGroups = BLI_countlist(&m_objMesh->defbase); + + if (!dverts) + return; + + if (m_dfnrToPC == NULL) + { + m_dfnrToPC = new bPoseChannel*[numGroups]; + int i; + for (i=0, dg=(bDeformGroup*)m_objMesh->defbase.first; + dg; + ++i, dg=(bDeformGroup*)dg->next) + { + m_dfnrToPC[i] = get_pose_channel(par_arma->pose, dg->name); + + if (m_dfnrToPC[i] && m_dfnrToPC[i]->bone->flag & BONE_NO_DEFORM) + m_dfnrToPC[i] = NULL; + } + } + + + for (int i=0; i<m_bmesh->totvert; ++i) + { + float contrib = 0.f, weight, max_weight=0.f; + bPoseChannel *pchan=NULL; + MDeformVert *dvert; + Eigen::Map<Eigen::Vector3f> norm(m_transnors[i]); + Eigen::Vector4f vec(0, 0, 0, 1); + Eigen::Matrix4f norm_chan_mat; + Eigen::Vector4f co(m_transverts[i][0], + m_transverts[i][1], + m_transverts[i][2], + 1.f); + + dvert = dverts+i; + + if (!dvert->totweight) + continue; + + for (int j=0; j<dvert->totweight; ++j) + { + int index = dvert->dw[j].def_nr; + + if (index < numGroups && (pchan=m_dfnrToPC[index])) + { + weight = dvert->dw[j].weight; + + if (weight) + { + Eigen::Vector4f cop(co); + Eigen::Matrix4f chan_mat = Eigen::Matrix4f::Map((float*)pchan->chan_mat); + + // Update Vertex Position + cop = chan_mat*cop; + vec += (cop - co)*weight; + + // Save the most influential channel so we can use it to update the vertex normal + if (weight > max_weight) + { + max_weight = weight; + norm_chan_mat = chan_mat; + } + + contrib += weight; + } + } + } + + + // Update Vertex Normal + norm = norm_chan_mat.corner<3, 3>(Eigen::TopLeft)*norm; + + if (contrib > 0.0001f) + { + vec *= 1.f/contrib; + co += vec; + } + + m_transverts[i][0] = co[0]; + m_transverts[i][1] = co[1]; + m_transverts[i][2] = co[2]; + } + m_copyNormals = true; } -//void where_is_pose (Object *ob); -//void armature_deform_verts(Object *armOb, Object *target, float (*vertexCos)[3], int numVerts, int deformflag); bool BL_SkinDeformer::UpdateInternal(bool shape_applied) { /* See if the armature has been updated for this frame */ if (PoseUpdated()){ - float obmat[4][4]; // the original object matrice - - /* XXX note: where_is_pose() (from BKE_armature.h) calculates all matrices needed to start deforming */ - /* but it requires the blender object pointer... */ - Object* par_arma = m_armobj->GetArmatureObject(); if(!shape_applied) { /* store verts locally */ @@ -194,25 +315,23 @@ bool BL_SkinDeformer::UpdateInternal(bool shape_applied) /* duplicate */ for (int v =0; v<m_bmesh->totvert; v++) + { VECCOPY(m_transverts[v], m_bmesh->mvert[v].co); + VECCOPY(m_transnors[v], m_bmesh->mvert[v].no); + } } m_armobj->ApplyPose(); - // save matrix first - copy_m4_m4(obmat, m_objMesh->obmat); - // set reference matrix - copy_m4_m4(m_objMesh->obmat, m_obmat); - - armature_deform_verts( par_arma, m_objMesh, NULL, m_transverts, NULL, m_bmesh->totvert, ARM_DEF_VGROUP, NULL, NULL ); - - // restore matrix - copy_m4_m4(m_objMesh->obmat, obmat); - -#ifdef __NLA_DEFNORMALS - if (m_recalcNormal) - RecalcNormals(); -#endif + switch (m_armobj->GetVertDeformType()) + { + case ARM_VDEF_BGE_CPU: + BGEDeformVerts(); + break; + case ARM_VDEF_BLENDER: + default: + BlenderDeformVerts(); + } /* Update the current frame */ m_lastArmaUpdate=m_armobj->GetLastFrame(); diff --git a/source/gameengine/Converter/BL_SkinDeformer.h b/source/gameengine/Converter/BL_SkinDeformer.h index e53e21e946f..be974619281 100644 --- a/source/gameengine/Converter/BL_SkinDeformer.h +++ b/source/gameengine/Converter/BL_SkinDeformer.h @@ -109,6 +109,11 @@ protected: bool m_releaseobject; bool m_poseApplied; bool m_recalcNormal; + bool m_copyNormals; // dirty flag so we know if Apply() needs to copy normal information (used for BGEDeformVerts()) + struct bPoseChannel** m_dfnrToPC; + + void BlenderDeformVerts(); + void BGEDeformVerts(); #ifdef WITH_CXX_GUARDEDALLOC diff --git a/source/gameengine/Converter/BlenderWorldInfo.cpp b/source/gameengine/Converter/BlenderWorldInfo.cpp index 8fc01032de7..f003a0049e5 100644 --- a/source/gameengine/Converter/BlenderWorldInfo.cpp +++ b/source/gameengine/Converter/BlenderWorldInfo.cpp @@ -170,10 +170,10 @@ float BlenderWorldInfo::getMistStart() float BlenderWorldInfo::getMistDistance() { return m_mistdistance; -} - +} + + - float BlenderWorldInfo::getMistColorRed() { return m_mistcolor[0]; diff --git a/source/gameengine/Converter/CMakeLists.txt b/source/gameengine/Converter/CMakeLists.txt index fcb608a5830..039f454e870 100644 --- a/source/gameengine/Converter/CMakeLists.txt +++ b/source/gameengine/Converter/CMakeLists.txt @@ -26,37 +26,36 @@ set(INC . - ../../../intern/string - ../../../intern/guardedalloc + ../BlenderRoutines + ../Expressions + ../GameLogic + ../Ketsji + ../Ketsji/KXNetwork + ../Network + ../Network/LoopBackNetwork + ../Physics/Bullet + ../Physics/Dummy + ../Physics/common + ../Rasterizer + ../Rasterizer/RAS_OpenGLRasterizer + ../Rasterizer/RAS_OpenGLRasterizer + ../SceneGraph + ../../blender + ../../blender/blenkernel + ../../blender/blenlib + ../../blender/blenloader + ../../blender/gpu + ../../blender/ikplugin + ../../blender/imbuf + ../../blender/makesdna + ../../blender/makesrna + ../../blender/windowmanager + ../../../extern/bullet2/src + ../../../extern/Eigen2 ../../../intern/container - ../../../source/gameengine/Rasterizer/RAS_OpenGLRasterizer - ../../../intern/audaspace/intern - ../../../source/gameengine/Converter - ../../../source/gameengine/BlenderRoutines - ../../../source/blender/imbuf + ../../../intern/guardedalloc ../../../intern/moto/include - ../../../source/gameengine/Ketsji - ../../../source/gameengine/Ketsji/KXNetwork - ../../../source/blender/blenlib - ../../../source/blender/blenkernel - ../../../source/blender/windowmanager - ../../../source/blender - ../../../source/blender/makesdna - ../../../source/blender/makesrna - ../../../source/gameengine/Rasterizer - ../../../source/gameengine/Rasterizer/RAS_OpenGLRasterizer - ../../../source/gameengine/GameLogic - ../../../source/gameengine/Expressions - ../../../source/gameengine/Network - ../../../source/gameengine/SceneGraph - ../../../source/gameengine/Physics/common - ../../../source/gameengine/Physics/Bullet - ../../../source/gameengine/Physics/Dummy - ../../../source/gameengine/Network/LoopBackNetwork - ../../../source/blender/blenloader - ../../../source/blender/gpu - ../../../source/blender/ikplugin - ../../../extern/bullet2/src + ../../../intern/string ../../../extern/recastnavigation/Detour/Include ) @@ -114,4 +113,11 @@ if(WITH_BULLET) add_definitions(-DUSE_BULLET) endif() +if(WITH_AUDASPACE) + list(APPEND INC + ../../../intern/audaspace/intern + ) + add_definitions(-DWITH_AUDASPACE) +endif() + blender_add_lib(ge_converter "${SRC}" "${INC}" "${INC_SYS}") diff --git a/source/gameengine/Converter/KX_BlenderScalarInterpolator.cpp b/source/gameengine/Converter/KX_BlenderScalarInterpolator.cpp index a9a3e66f996..75c0e012226 100644 --- a/source/gameengine/Converter/KX_BlenderScalarInterpolator.cpp +++ b/source/gameengine/Converter/KX_BlenderScalarInterpolator.cpp @@ -47,11 +47,11 @@ float BL_ScalarInterpolator::GetValue(float currentTime) const { return evaluate_fcurve(m_fcu, currentTime); } -BL_InterpolatorList::BL_InterpolatorList(struct AnimData *adt) { - if(adt->action==NULL) +BL_InterpolatorList::BL_InterpolatorList(bAction *action) { + if(action==NULL) return; - for(FCurve *fcu= (FCurve *)adt->action->curves.first; fcu; fcu= (FCurve *)fcu->next) { + for(FCurve *fcu= (FCurve *)action->curves.first; fcu; fcu= (FCurve *)fcu->next) { if(fcu->rna_path) { BL_ScalarInterpolator *new_ipo = new BL_ScalarInterpolator(fcu); //assert(new_ipo); diff --git a/source/gameengine/Converter/KX_BlenderScalarInterpolator.h b/source/gameengine/Converter/KX_BlenderScalarInterpolator.h index bd786bae969..cca66b3771c 100644 --- a/source/gameengine/Converter/KX_BlenderScalarInterpolator.h +++ b/source/gameengine/Converter/KX_BlenderScalarInterpolator.h @@ -66,7 +66,7 @@ public: class BL_InterpolatorList : public std::vector<KX_IScalarInterpolator *> { public: - BL_InterpolatorList(struct AnimData *adt); + BL_InterpolatorList(struct bAction *action); ~BL_InterpolatorList(); KX_IScalarInterpolator *GetScalarInterpolator(const char *rna_path, int array_index); diff --git a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp index 58089cc4b2d..656dcfa3220 100644 --- a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp +++ b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp @@ -385,6 +385,12 @@ void KX_BlenderSceneConverter::ConvertScene(class KX_Scene* destinationscene, //This cache mecanism is buggy so I leave it disable and the memory leak //that would result from this is fixed in RemoveScene() m_map_mesh_to_gamemesh.clear(); + +#ifndef USE_BULLET + /* quiet compiler warning */ + (void)useDbvtCulling; +#endif + } // This function removes all entities stored in the converter for that scene @@ -566,18 +572,18 @@ void KX_BlenderSceneConverter::RegisterPolyMaterial(RAS_IPolyMaterial *polymat) void KX_BlenderSceneConverter::RegisterInterpolatorList( - BL_InterpolatorList *adtList, - struct AnimData *for_adt) + BL_InterpolatorList *actList, + struct bAction *for_act) { - m_map_blender_to_gameAdtList.insert(CHashedPtr(for_adt), adtList); + m_map_blender_to_gameAdtList.insert(CHashedPtr(for_act), actList); } BL_InterpolatorList *KX_BlenderSceneConverter::FindInterpolatorList( - struct AnimData *for_adt) + struct bAction *for_act) { - BL_InterpolatorList **listp = m_map_blender_to_gameAdtList[CHashedPtr(for_adt)]; + BL_InterpolatorList **listp = m_map_blender_to_gameAdtList[CHashedPtr(for_act)]; return listp?*listp:NULL; } @@ -679,7 +685,7 @@ void KX_BlenderSceneConverter::ResetPhysicsObjectsAnimationIpo(bool clearIpo) MEM_freeN( tmpicu ); localDel_ipoCurve( tmpicu ); } - } + } } else { ipo = NULL; // XXX add_ipo(blenderObject->id.name+2, ID_OB); blenderObject->ipo = ipo; @@ -950,7 +956,6 @@ bool KX_BlenderSceneConverter::LinkBlendFilePath(const char *path, char *group, bool KX_BlenderSceneConverter::LinkBlendFile(BlendHandle *bpy_openlib, const char *path, char *group, KX_Scene *scene_merge, char **err_str, short options) { - bContext *C; Main *main_newlib; /* stored as a dynamic 'main' until we free it */ Main *main_tmp= NULL; /* created only for linking, then freed */ LinkNode *names = NULL; @@ -981,12 +986,10 @@ bool KX_BlenderSceneConverter::LinkBlendFile(BlendHandle *bpy_openlib, const cha } main_newlib= (Main *)MEM_callocN( sizeof(Main), "BgeMain"); - C= CTX_create(); - CTX_data_main_set(C, main_newlib); BKE_reports_init(&reports, RPT_STORE); /* here appending/linking starts */ - main_tmp = BLO_library_append_begin(C, &bpy_openlib, (char *)path); + main_tmp = BLO_library_append_begin(main_newlib, &bpy_openlib, (char *)path); int totnames_dummy; names = BLO_blendhandle_get_datablock_names( bpy_openlib, idcode, &totnames_dummy); @@ -1000,11 +1003,11 @@ bool KX_BlenderSceneConverter::LinkBlendFile(BlendHandle *bpy_openlib, const cha } BLI_linklist_free(names, free); /* free linklist *and* each node's data */ - BLO_library_append_end(C, main_tmp, &bpy_openlib, idcode, flag); + BLO_library_append_end(NULL, main_tmp, &bpy_openlib, idcode, flag); /* now do another round of linking for Scenes so all actions are properly loaded */ if (idcode==ID_SCE && options & LIB_LOAD_LOAD_ACTIONS) { - main_tmp = BLO_library_append_begin(C, &bpy_openlib, (char *)path); + main_tmp = BLO_library_append_begin(main_newlib, &bpy_openlib, (char *)path); int totnames_dummy; names = BLO_blendhandle_get_datablock_names( bpy_openlib, ID_AC, &totnames_dummy); @@ -1018,12 +1021,11 @@ bool KX_BlenderSceneConverter::LinkBlendFile(BlendHandle *bpy_openlib, const cha } BLI_linklist_free(names, free); /* free linklist *and* each node's data */ - BLO_library_append_end(C, main_tmp, &bpy_openlib, ID_AC, flag); + BLO_library_append_end(NULL, main_tmp, &bpy_openlib, ID_AC, flag); } BLO_blendhandle_close(bpy_openlib); - - CTX_free(C); + BKE_reports_clear(&reports); /* done linking */ @@ -1087,7 +1089,7 @@ bool KX_BlenderSceneConverter::LinkBlendFile(BlendHandle *bpy_openlib, const cha * most are temp and NewRemoveObject frees m_map_gameobject_to_blender */ bool KX_BlenderSceneConverter::FreeBlendFile(struct Main *maggie) { - int maggie_index; + int maggie_index= -1; int i=0; if(maggie==NULL) @@ -1105,6 +1107,10 @@ bool KX_BlenderSceneConverter::FreeBlendFile(struct Main *maggie) i++; } + /* should never happen but just to be safe */ + if(maggie_index == -1) + return false; + m_DynamicMaggie.erase(m_DynamicMaggie.begin() + maggie_index); tag_main(maggie, 1); diff --git a/source/gameengine/Converter/KX_BlenderSceneConverter.h b/source/gameengine/Converter/KX_BlenderSceneConverter.h index 2340e44d288..ba919eb9592 100644 --- a/source/gameengine/Converter/KX_BlenderSceneConverter.h +++ b/source/gameengine/Converter/KX_BlenderSceneConverter.h @@ -113,8 +113,8 @@ public: void RegisterBlenderMaterial(BL_Material *mat); - void RegisterInterpolatorList(BL_InterpolatorList *adtList, struct AnimData *for_adt); - BL_InterpolatorList *FindInterpolatorList(struct AnimData *for_adt); + void RegisterInterpolatorList(BL_InterpolatorList *actList, struct bAction *for_act); + BL_InterpolatorList *FindInterpolatorList(struct bAction *for_act); void RegisterGameActuator(SCA_IActuator *act, struct bActuator *for_actuator); SCA_IActuator *FindGameActuator(struct bActuator *for_actuator); diff --git a/source/gameengine/Converter/KX_ConvertActuators.cpp b/source/gameengine/Converter/KX_ConvertActuators.cpp index a8d5ab0b2ff..c73ffc2b932 100644 --- a/source/gameengine/Converter/KX_ConvertActuators.cpp +++ b/source/gameengine/Converter/KX_ConvertActuators.cpp @@ -43,7 +43,12 @@ #include "KX_BlenderSceneConverter.h" #include "KX_ConvertActuators.h" -#include "AUD_C-API.h" + +#ifdef WITH_AUDASPACE +# include "AUD_C-API.h" +# include "AUD_ChannelMapperFactory.h" +#endif + // Actuators //SCA logiclibrary native logicbricks #include "SCA_PropertyActuator.h" @@ -78,6 +83,7 @@ /* This little block needed for linking to Blender... */ #include "BKE_text.h" #include "BLI_blenlib.h" +#include "BLI_math_base.h" #define FILE_MAX 240 // repeated here to avoid dependency from BKE_utildefines.h @@ -96,6 +102,7 @@ #include "BL_ShapeActionActuator.h" #include "BL_ArmatureActuator.h" #include "RNA_access.h" +#include "BL_Action.h" /* end of blender include block */ #include "BL_BlenderDataConversion.h" @@ -193,30 +200,37 @@ void BL_ConvertActuators(char* maggiename, } case ACT_ACTION: { - if (blenderobject->type==OB_ARMATURE){ - bActionActuator* actact = (bActionActuator*) bact->data; - STR_String propname = (actact->name ? actact->name : ""); - STR_String propframe = (actact->frameProp ? actact->frameProp : ""); + bActionActuator* actact = (bActionActuator*) bact->data; + STR_String propname = (actact->name ? actact->name : ""); + STR_String propframe = (actact->frameProp ? actact->frameProp : ""); + + short ipo_flags = 0; + + // Convert flags + if (actact->flag & ACT_IPOFORCE) ipo_flags |= BL_Action::ACT_IPOFLAG_FORCE; + if (actact->flag & ACT_IPOLOCAL) ipo_flags |= BL_Action::ACT_IPOFLAG_LOCAL; + if (actact->flag & ACT_IPOADD) ipo_flags |= BL_Action::ACT_IPOFLAG_ADD; + if (actact->flag & ACT_IPOCHILD) ipo_flags |= BL_Action::ACT_IPOFLAG_CHILD; - BL_ActionActuator* tmpbaseact = new BL_ActionActuator( - gameobj, - propname, - propframe, - actact->sta, - actact->end, - actact->act, - 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" - ); - baseact= tmpbaseact; - break; - } - else - printf ("Discarded action actuator from non-armature object [%s]\n", blenderobject->id.name+2); + BL_ActionActuator* tmpbaseact = new BL_ActionActuator( + gameobj, + propname, + propframe, + actact->sta, + actact->end, + actact->act, + actact->type, // + 1, because Blender starts to count at zero, + actact->blendin, + actact->priority, + actact->layer, + actact->layer_weight, + ipo_flags, + actact->end_reset, + actact->stridelength + // Ketsji at 1, because zero is reserved for "NoDef" + ); + baseact= tmpbaseact; + break; } case ACT_SHAPEACTION: { @@ -288,7 +302,8 @@ void BL_ConvertActuators(char* maggiename, camact->height, camact->min, camact->max, - camact->axis=='x'); + camact->axis=='x', + camact->damping); baseact = tmpcamact; } break; @@ -376,7 +391,7 @@ void BL_ConvertActuators(char* maggiename, { bSound* sound = soundact->sound; bool is3d = soundact->flag & ACT_SND_3D_SOUND ? true : false; - AUD_Sound* snd_sound = NULL; + AUD_Reference<AUD_IFactory> snd_sound; KX_3DSoundSettings settings; settings.cone_inner_angle = soundact->sound3D.cone_inner_angle; settings.cone_outer_angle = soundact->sound3D.cone_outer_angle; @@ -394,12 +409,28 @@ void BL_ConvertActuators(char* maggiename, "\" has no sound datablock." << std::endl; } else - snd_sound = sound->playback_handle; + { + snd_sound = *reinterpret_cast<AUD_Reference<AUD_IFactory>*>(sound->playback_handle); + + // if sound shall be 3D but isn't mono, we have to make it mono! + if(is3d) + { + AUD_Reference<AUD_IReader> reader = snd_sound->createReader(); + if(reader->getSpecs().channels != AUD_CHANNELS_MONO) + { + AUD_DeviceSpecs specs; + specs.channels = AUD_CHANNELS_MONO; + specs.rate = AUD_RATE_INVALID; + specs.format = AUD_FORMAT_INVALID; + snd_sound = new AUD_ChannelMapperFactory(snd_sound, specs); + } + } + } KX_SoundActuator* tmpsoundact = new KX_SoundActuator(gameobj, snd_sound, soundact->volume, - (float)(exp((soundact->pitch / 12.0) * log(2.0))), + (float)(exp((soundact->pitch / 12.0) * M_LN2)), is3d, settings, soundActuatorType); @@ -913,7 +944,7 @@ void BL_ConvertActuators(char* maggiename, case ACT_2DFILTER: { bTwoDFilterActuator *_2dfilter = (bTwoDFilterActuator*) bact->data; - SCA_2DFilterActuator *tmp = NULL; + SCA_2DFilterActuator *tmp = NULL; RAS_2DFilterManager::RAS_2DFILTER_MODE filtermode; switch(_2dfilter->type) @@ -967,7 +998,7 @@ void BL_ConvertActuators(char* maggiename, filtermode = RAS_2DFilterManager::RAS_2DFILTER_NOFILTER; break; } - + tmp = new SCA_2DFilterActuator(gameobj, filtermode, _2dfilter->flag, _2dfilter->float_arg,_2dfilter->int_arg,ketsjiEngine->GetRasterizer(),scene); @@ -983,8 +1014,8 @@ void BL_ConvertActuators(char* maggiename, } } - baseact = tmp; - + baseact = tmp; + } break; case ACT_PARENT: diff --git a/source/gameengine/Converter/KX_ConvertControllers.cpp b/source/gameengine/Converter/KX_ConvertControllers.cpp index 98afc3a690a..fafaaf5cef6 100644 --- a/source/gameengine/Converter/KX_ConvertControllers.cpp +++ b/source/gameengine/Converter/KX_ConvertControllers.cpp @@ -210,7 +210,11 @@ void BL_ConvertControllers( CIntValue* uniqueval = new CIntValue(uniqueint); uniquename += uniqueval->GetText(); uniqueval->Release(); - gamecontroller->SetName(uniquename); + //unique name was never implemented for sensors and actuators, only for controllers + //and it's producing difference in the keys for the lists: obj.controllers/sensors/actuators + //at some point it should either be implemented globally (and saved as a separate var) or removed. + //gamecontroller->SetName(uniquename); + gamecontroller->SetName(bcontr->name); gameobj->AddController(gamecontroller); converter->RegisterGameController(gamecontroller, bcontr); diff --git a/source/gameengine/Converter/KX_ConvertSensors.cpp b/source/gameengine/Converter/KX_ConvertSensors.cpp index ad6941dcdc7..a250bc6064b 100644 --- a/source/gameengine/Converter/KX_ConvertSensors.cpp +++ b/source/gameengine/Converter/KX_ConvertSensors.cpp @@ -276,7 +276,7 @@ void BL_ConvertSensors(struct Object* blenderobject, gReverseKeyTranslateTable[ENDKEY ] = SCA_IInputDevice::KX_ENDKEY; } - int executePriority = 0; + int executePriority = 0; int uniqueint = 0; int count = 0; bSensor* sens = (bSensor*)blenderobject->sensors.first; diff --git a/source/gameengine/Converter/KX_IpoConvert.cpp b/source/gameengine/Converter/KX_IpoConvert.cpp index 2ad56717e26..b13dbe324f5 100644 --- a/source/gameengine/Converter/KX_IpoConvert.cpp +++ b/source/gameengine/Converter/KX_IpoConvert.cpp @@ -54,6 +54,7 @@ #include "DNA_object_types.h" #include "DNA_action_types.h" +#include "DNA_anim_types.h" #include "DNA_ipo_types.h" #include "DNA_lamp_types.h" #include "DNA_world_types.h" @@ -72,226 +73,226 @@ #include "STR_HashedString.h" -static BL_InterpolatorList *GetAdtList(struct AnimData *for_adt, KX_BlenderSceneConverter *converter) { - BL_InterpolatorList *adtList= converter->FindInterpolatorList(for_adt); +static BL_InterpolatorList *GetAdtList(struct bAction *for_act, KX_BlenderSceneConverter *converter) { + BL_InterpolatorList *adtList= converter->FindInterpolatorList(for_act); if (!adtList) { - adtList = new BL_InterpolatorList(for_adt); - converter->RegisterInterpolatorList(adtList, for_adt); + adtList = new BL_InterpolatorList(for_act); + converter->RegisterInterpolatorList(adtList, for_act); } return adtList; } -void BL_ConvertIpos(struct Object* blenderobject,KX_GameObject* gameobj,KX_BlenderSceneConverter *converter) +SG_Controller *BL_CreateIPO(struct bAction *action, KX_GameObject* gameobj, KX_BlenderSceneConverter *converter) { - if (blenderobject->adt) { - - KX_IpoSGController* ipocontr = new KX_IpoSGController(); - gameobj->GetSGNode()->AddSGController(ipocontr); - ipocontr->SetObject(gameobj->GetSGNode()); - - // For ipo_as_force, we need to know which SM object and Scene the - // object associated with this ipo is in. Is this already known here? - // I think not.... then it must be done later :( -// ipocontr->SetSumoReference(gameobj->GetSumoScene(), -// gameobj->GetSumoObject()); - - ipocontr->SetGameObject(gameobj); - - ipocontr->GetIPOTransform().SetPosition( - MT_Point3( - blenderobject->loc[0]/*+blenderobject->dloc[0]*/, - blenderobject->loc[1]/*+blenderobject->dloc[1]*/, - blenderobject->loc[2]/*+blenderobject->dloc[2]*/ - ) - ); - ipocontr->GetIPOTransform().SetEulerAngles( - MT_Vector3( - blenderobject->rot[0], - blenderobject->rot[1], - blenderobject->rot[2] - ) - ); - ipocontr->GetIPOTransform().SetScaling( - MT_Vector3( - blenderobject->size[0], - blenderobject->size[1], - blenderobject->size[2] - ) - ); - - const char *rotmode, *drotmode; - - switch(blenderobject->rotmode) - { - case ROT_MODE_AXISANGLE: - rotmode = "rotation_axis_angle"; - drotmode = "delta_rotation_axis_angle"; - case ROT_MODE_QUAT: - rotmode = "rotation_quaternion"; - drotmode = "delta_rotation_quaternion"; - default: - rotmode = "rotation_euler"; - drotmode = "delta_rotation_euler"; - } + KX_IpoSGController* ipocontr = new KX_IpoSGController(); + ipocontr->SetGameObject(gameobj); + + Object* blenderobject = gameobj->GetBlenderObject(); + + ipocontr->GetIPOTransform().SetPosition(MT_Point3(blenderobject->loc)); + ipocontr->GetIPOTransform().SetEulerAngles(MT_Vector3(blenderobject->rot)); + ipocontr->GetIPOTransform().SetScaling(MT_Vector3(blenderobject->size)); + + const char *rotmode, *drotmode; + + switch(blenderobject->rotmode) { + case ROT_MODE_AXISANGLE: + rotmode = "rotation_axis_angle"; + drotmode = "delta_rotation_axis_angle"; + break; + case ROT_MODE_QUAT: + rotmode = "rotation_quaternion"; + drotmode = "delta_rotation_quaternion"; + break; + default: + rotmode = "rotation_euler"; + drotmode = "delta_rotation_euler"; + break; + } - BL_InterpolatorList *adtList= GetAdtList(blenderobject->adt, converter); + BL_InterpolatorList *adtList= GetAdtList(action, converter); - // For each active channel in the adtList add an - // interpolator to the game object. + // For each active channel in the adtList add an + // interpolator to the game object. - KX_IInterpolator *interpolator; - KX_IScalarInterpolator *interp; + KX_IInterpolator *interpolator; + KX_IScalarInterpolator *interp; - for(int i=0; i<3; i++) { - if ((interp = adtList->GetScalarInterpolator("location", i))) { - interpolator= new KX_ScalarInterpolator(&(ipocontr->GetIPOTransform().GetPosition()[i]), interp); - ipocontr->AddInterpolator(interpolator); - ipocontr->SetIPOChannelActive(OB_LOC_X+i, true); - } + for(int i=0; i<3; i++) { + if ((interp = adtList->GetScalarInterpolator("location", i))) { + interpolator= new KX_ScalarInterpolator(&(ipocontr->GetIPOTransform().GetPosition()[i]), interp); + ipocontr->AddInterpolator(interpolator); + ipocontr->SetIPOChannelActive(OB_LOC_X+i, true); } - for(int i=0; i<3; i++) { - if ((interp = adtList->GetScalarInterpolator("delta_location", i))) { - interpolator= new KX_ScalarInterpolator(&(ipocontr->GetIPOTransform().GetDeltaPosition()[i]), interp); - ipocontr->AddInterpolator(interpolator); - ipocontr->SetIPOChannelActive(OB_DLOC_X+i, true); - } + } + for(int i=0; i<3; i++) { + if ((interp = adtList->GetScalarInterpolator("delta_location", i))) { + interpolator= new KX_ScalarInterpolator(&(ipocontr->GetIPOTransform().GetDeltaPosition()[i]), interp); + ipocontr->AddInterpolator(interpolator); + ipocontr->SetIPOChannelActive(OB_DLOC_X+i, true); } - for(int i=0; i<3; i++) { - if ((interp = adtList->GetScalarInterpolator(rotmode, i))) { - interpolator= new KX_ScalarInterpolator(&(ipocontr->GetIPOTransform().GetEulerAngles()[i]), interp); - ipocontr->AddInterpolator(interpolator); - ipocontr->SetIPOChannelActive(OB_ROT_X+i, true); - } + } + for(int i=0; i<3; i++) { + if ((interp = adtList->GetScalarInterpolator(rotmode, i))) { + interpolator= new KX_ScalarInterpolator(&(ipocontr->GetIPOTransform().GetEulerAngles()[i]), interp); + ipocontr->AddInterpolator(interpolator); + ipocontr->SetIPOChannelActive(OB_ROT_X+i, true); } - for(int i=0; i<3; i++) { - if ((interp = adtList->GetScalarInterpolator(drotmode, i))) { - interpolator= new KX_ScalarInterpolator(&(ipocontr->GetIPOTransform().GetDeltaEulerAngles()[i]), interp); - ipocontr->AddInterpolator(interpolator); - ipocontr->SetIPOChannelActive(OB_DROT_X+i, true); - } + } + for(int i=0; i<3; i++) { + if ((interp = adtList->GetScalarInterpolator(drotmode, i))) { + interpolator= new KX_ScalarInterpolator(&(ipocontr->GetIPOTransform().GetDeltaEulerAngles()[i]), interp); + ipocontr->AddInterpolator(interpolator); + ipocontr->SetIPOChannelActive(OB_DROT_X+i, true); } - for(int i=0; i<3; i++) { - if ((interp = adtList->GetScalarInterpolator("scale", i))) { - interpolator= new KX_ScalarInterpolator(&(ipocontr->GetIPOTransform().GetScaling()[i]), interp); - ipocontr->AddInterpolator(interpolator); - ipocontr->SetIPOChannelActive(OB_SIZE_X+i, true); - } + } + for(int i=0; i<3; i++) { + if ((interp = adtList->GetScalarInterpolator("scale", i))) { + interpolator= new KX_ScalarInterpolator(&(ipocontr->GetIPOTransform().GetScaling()[i]), interp); + ipocontr->AddInterpolator(interpolator); + ipocontr->SetIPOChannelActive(OB_SIZE_X+i, true); } - for(int i=0; i<3; i++) { - if ((interp = adtList->GetScalarInterpolator("delta_scale", i))) { - interpolator= new KX_ScalarInterpolator(&(ipocontr->GetIPOTransform().GetDeltaScaling()[i]), interp); - ipocontr->AddInterpolator(interpolator); - ipocontr->SetIPOChannelActive(OB_DSIZE_X+i, true); - } + } + for(int i=0; i<3; i++) { + if ((interp = adtList->GetScalarInterpolator("delta_scale", i))) { + interpolator= new KX_ScalarInterpolator(&(ipocontr->GetIPOTransform().GetDeltaScaling()[i]), interp); + ipocontr->AddInterpolator(interpolator); + ipocontr->SetIPOChannelActive(OB_DSIZE_X+i, true); } + } - { - KX_ObColorIpoSGController* ipocontr_obcol=NULL; + { + KX_ObColorIpoSGController* ipocontr_obcol=NULL; - for(int i=0; i<4; i++) { - if ((interp = adtList->GetScalarInterpolator("color", i))) { - if (!ipocontr_obcol) { - ipocontr_obcol = new KX_ObColorIpoSGController(); - gameobj->GetSGNode()->AddSGController(ipocontr_obcol); - ipocontr_obcol->SetObject(gameobj->GetSGNode()); - } - interpolator= new KX_ScalarInterpolator(&ipocontr_obcol->m_rgba[i], interp); - ipocontr_obcol->AddInterpolator(interpolator); + for(int i=0; i<4; i++) { + if ((interp = adtList->GetScalarInterpolator("color", i))) { + if (!ipocontr_obcol) { + ipocontr_obcol = new KX_ObColorIpoSGController(); + gameobj->GetSGNode()->AddSGController(ipocontr_obcol); + ipocontr_obcol->SetObject(gameobj->GetSGNode()); } + interpolator= new KX_ScalarInterpolator(&ipocontr_obcol->m_rgba[i], interp); + ipocontr_obcol->AddInterpolator(interpolator); } } } + + return ipocontr; } -void BL_ConvertLampIpos(struct Lamp* blenderlamp, KX_GameObject *lightobj,KX_BlenderSceneConverter *converter) +void BL_ConvertIpos(struct Object* blenderobject,KX_GameObject* gameobj,KX_BlenderSceneConverter *converter) { + if (blenderobject->adt) { + SG_Controller *ipocontr = BL_CreateIPO(blenderobject->adt->action, gameobj, converter); + gameobj->GetSGNode()->AddSGController(ipocontr); + ipocontr->SetObject(gameobj->GetSGNode()); + } +} - if (blenderlamp->adt) { +SG_Controller *BL_CreateLampIPO(struct bAction *action, KX_GameObject* lightobj, KX_BlenderSceneConverter *converter) +{ + KX_LightIpoSGController* ipocontr = new KX_LightIpoSGController(); - KX_LightIpoSGController* ipocontr = new KX_LightIpoSGController(); - lightobj->GetSGNode()->AddSGController(ipocontr); - ipocontr->SetObject(lightobj->GetSGNode()); - - ipocontr->m_energy = blenderlamp->energy; - ipocontr->m_col_rgb[0] = blenderlamp->r; - ipocontr->m_col_rgb[1] = blenderlamp->g; - ipocontr->m_col_rgb[2] = blenderlamp->b; - ipocontr->m_dist = blenderlamp->dist; + Lamp *blenderlamp = (Lamp*)lightobj->GetBlenderObject()->data; - BL_InterpolatorList *adtList= GetAdtList(blenderlamp->adt, converter); + ipocontr->m_energy = blenderlamp->energy; + ipocontr->m_col_rgb[0] = blenderlamp->r; + ipocontr->m_col_rgb[1] = blenderlamp->g; + ipocontr->m_col_rgb[2] = blenderlamp->b; + ipocontr->m_dist = blenderlamp->dist; - // For each active channel in the adtList add an - // interpolator to the game object. + BL_InterpolatorList *adtList= GetAdtList(action, converter); + + // For each active channel in the adtList add an + // interpolator to the game object. - KX_IInterpolator *interpolator; - KX_IScalarInterpolator *interp; + KX_IInterpolator *interpolator; + KX_IScalarInterpolator *interp; - if ((interp= adtList->GetScalarInterpolator("energy", 0))) { - interpolator= new KX_ScalarInterpolator(&ipocontr->m_energy, interp); - ipocontr->AddInterpolator(interpolator); - ipocontr->SetModifyEnergy(true); - } + if ((interp= adtList->GetScalarInterpolator("energy", 0))) { + interpolator= new KX_ScalarInterpolator(&ipocontr->m_energy, interp); + ipocontr->AddInterpolator(interpolator); + ipocontr->SetModifyEnergy(true); + } - if ((interp = adtList->GetScalarInterpolator("distance", 0))) { - interpolator= new KX_ScalarInterpolator(&ipocontr->m_dist, interp); - ipocontr->AddInterpolator(interpolator); - ipocontr->SetModifyDist(true); - } + if ((interp = adtList->GetScalarInterpolator("distance", 0))) { + interpolator= new KX_ScalarInterpolator(&ipocontr->m_dist, interp); + ipocontr->AddInterpolator(interpolator); + ipocontr->SetModifyDist(true); + } - for(int i=0; i<3; i++) { - if ((interp = adtList->GetScalarInterpolator("color", i))) { - interpolator= new KX_ScalarInterpolator(&ipocontr->m_col_rgb[i], interp); - ipocontr->AddInterpolator(interpolator); - ipocontr->SetModifyColor(true); - } + for(int i=0; i<3; i++) { + if ((interp = adtList->GetScalarInterpolator("color", i))) { + interpolator= new KX_ScalarInterpolator(&ipocontr->m_col_rgb[i], interp); + ipocontr->AddInterpolator(interpolator); + ipocontr->SetModifyColor(true); } } + + return ipocontr; } +void BL_ConvertLampIpos(struct Lamp* blenderlamp, KX_GameObject *lightobj,KX_BlenderSceneConverter *converter) +{ + if (blenderlamp->adt) { + SG_Controller* ipocontr = BL_CreateLampIPO(blenderlamp->adt->action, lightobj, converter); + lightobj->GetSGNode()->AddSGController(ipocontr); + ipocontr->SetObject(lightobj->GetSGNode()); + + + } +} -void BL_ConvertCameraIpos(struct Camera* blendercamera, KX_GameObject *cameraobj,KX_BlenderSceneConverter *converter) +SG_Controller *BL_CreateCameraIPO(struct bAction *action, KX_GameObject* cameraobj, KX_BlenderSceneConverter *converter) { + KX_CameraIpoSGController* ipocontr = new KX_CameraIpoSGController(); - if (blendercamera->adt) { + Camera *blendercamera = (Camera*)cameraobj->GetBlenderObject()->data; - KX_CameraIpoSGController* ipocontr = new KX_CameraIpoSGController(); - cameraobj->GetSGNode()->AddSGController(ipocontr); - ipocontr->SetObject(cameraobj->GetSGNode()); - - ipocontr->m_lens = blendercamera->lens; - ipocontr->m_clipstart = blendercamera->clipsta; - ipocontr->m_clipend = blendercamera->clipend; + ipocontr->m_lens = blendercamera->lens; + ipocontr->m_clipstart = blendercamera->clipsta; + ipocontr->m_clipend = blendercamera->clipend; - BL_InterpolatorList *adtList= GetAdtList(blendercamera->adt, converter); + BL_InterpolatorList *adtList= GetAdtList(action, converter); - // For each active channel in the adtList add an - // interpolator to the game object. + // For each active channel in the adtList add an + // interpolator to the game object. - KX_IInterpolator *interpolator; - KX_IScalarInterpolator *interp; + KX_IInterpolator *interpolator; + KX_IScalarInterpolator *interp; - if ((interp = adtList->GetScalarInterpolator("lens", 0))) { - interpolator= new KX_ScalarInterpolator(&ipocontr->m_lens, interp); - ipocontr->AddInterpolator(interpolator); - ipocontr->SetModifyLens(true); - } + if ((interp = adtList->GetScalarInterpolator("lens", 0))) { + interpolator= new KX_ScalarInterpolator(&ipocontr->m_lens, interp); + ipocontr->AddInterpolator(interpolator); + ipocontr->SetModifyLens(true); + } - if ((interp = adtList->GetScalarInterpolator("clip_start", 0))) { - interpolator= new KX_ScalarInterpolator(&ipocontr->m_clipstart, interp); - ipocontr->AddInterpolator(interpolator); - ipocontr->SetModifyClipStart(true); - } + if ((interp = adtList->GetScalarInterpolator("clip_start", 0))) { + interpolator= new KX_ScalarInterpolator(&ipocontr->m_clipstart, interp); + ipocontr->AddInterpolator(interpolator); + ipocontr->SetModifyClipStart(true); + } - if ((interp = adtList->GetScalarInterpolator("clip_end", 0))) { - interpolator= new KX_ScalarInterpolator(&ipocontr->m_clipend, interp); - ipocontr->AddInterpolator(interpolator); - ipocontr->SetModifyClipEnd(true); - } + if ((interp = adtList->GetScalarInterpolator("clip_end", 0))) { + interpolator= new KX_ScalarInterpolator(&ipocontr->m_clipend, interp); + ipocontr->AddInterpolator(interpolator); + ipocontr->SetModifyClipEnd(true); + } + + return ipocontr; +} +void BL_ConvertCameraIpos(struct Camera* blendercamera, KX_GameObject *cameraobj,KX_BlenderSceneConverter *converter) +{ + + if (blendercamera->adt) { + SG_Controller* ipocontr = BL_CreateCameraIPO(blendercamera->adt->action, cameraobj, converter); + cameraobj->GetSGNode()->AddSGController(ipocontr); + ipocontr->SetObject(cameraobj->GetSGNode()); } } @@ -314,7 +315,7 @@ void BL_ConvertWorldIpos(struct World* blenderworld,KX_BlenderSceneConverter *co ipocontr->m_mist_rgb[1] = blenderworld->horg; ipocontr->m_mist_rgb[2] = blenderworld->horb; - BL_InterpolatorList *adtList= GetAdtList(blenderworld->adt, converter); + BL_InterpolatorList *adtList= GetAdtList(blenderworld->adt->action, converter); // For each active channel in the adtList add an // interpolator to the game object. @@ -356,7 +357,7 @@ static void ConvertMaterialIpos( gameobj->GetSGNode()->AddSGController(ipocontr); ipocontr->SetObject(gameobj->GetSGNode()); - BL_InterpolatorList *adtList= GetAdtList(blendermaterial->adt, converter); + BL_InterpolatorList *adtList= GetAdtList(blendermaterial->adt->action, converter); ipocontr->m_rgba[0] = blendermaterial->r; diff --git a/source/gameengine/Converter/KX_IpoConvert.h b/source/gameengine/Converter/KX_IpoConvert.h index d77a72a82e2..60e695c68a7 100644 --- a/source/gameengine/Converter/KX_IpoConvert.h +++ b/source/gameengine/Converter/KX_IpoConvert.h @@ -36,10 +36,18 @@ struct Object; +class SG_Controller *BL_CreateIPO(struct bAction *action, + class KX_GameObject* gameobj, + class KX_BlenderSceneConverter *converter); + void BL_ConvertIpos(struct Object* blenderobject, class KX_GameObject* gameobj, class KX_BlenderSceneConverter *converter); +class SG_Controller *BL_CreateLampIPO(struct bAction *action, + class KX_GameObject* lightobj, + class KX_BlenderSceneConverter *converter); + void BL_ConvertLampIpos(struct Lamp* blenderlight, class KX_GameObject* lightobj, class KX_BlenderSceneConverter *converter); @@ -47,6 +55,10 @@ void BL_ConvertLampIpos(struct Lamp* blenderlight, void BL_ConvertWorldIpos(struct World* blenderworld, class KX_BlenderSceneConverter *converter); +class SG_Controller *BL_CreateCameraIPO(struct bAction *action, + class KX_GameObject* cameraobj, + class KX_BlenderSceneConverter *converter); + void BL_ConvertCameraIpos(struct Camera* blendercamera, class KX_GameObject* cameraobj, class KX_BlenderSceneConverter *converter); diff --git a/source/gameengine/Converter/SConscript b/source/gameengine/Converter/SConscript index edcd40e23ff..e155677e522 100644 --- a/source/gameengine/Converter/SConscript +++ b/source/gameengine/Converter/SConscript @@ -21,6 +21,7 @@ incs += ' #source/blender/windowmanager' incs += ' #source/blender/makesrna' incs += ' #source/blender/ikplugin' incs += ' #extern/recastnavigation/Detour/Include' +incs += ' #extern/Eigen2' incs += ' ' + env['BF_BULLET_INC'] |