ActionActuator in the game engine working again to display deformed meshes with the...
[blender-staging.git] / source / gameengine / Converter / BL_ArmatureObject.cpp
index bf774bf75683b286c5deb8e25ddb1a412ca803da..f8a9b1b637ffdae6ad4481ef37fb9b83be30b20b 100644 (file)
@@ -38,6 +38,7 @@
 #include "DNA_action_types.h"
 #include "DNA_armature_types.h"
 #include "DNA_object_types.h"
+#include "DNA_scene_types.h"
 
 #include "MT_Matrix4x4.h"
 
 #include <config.h>
 #endif
 
-
 BL_ArmatureObject::BL_ArmatureObject(
                                void* sgReplicationInfo, 
                                SG_Callbacks callbacks, 
-                               Object *armature )
+                               Object *armature,
+                               Scene *scene)
 
 :      KX_GameObject(sgReplicationInfo,callbacks),
        m_objArma(armature),
+       m_scene(scene), // maybe remove later. needed for where_is_pose
        m_framePose(NULL),
        m_lastframe(0.0),
        m_activeAct(NULL),
        m_activePriority(999),
        m_lastapplyframe(0.0)
 {
-       m_armature = get_armature(m_objArma);
+       m_armature = (bArmature *)armature->data;
 
        /* we make a copy of blender object's pose, and then always swap it with
         * the original pose before calling into blender functions, to deal with
         * replica's or other objects using the same blender object */
        m_pose = NULL;
-       copy_pose(&m_pose, m_objArma->pose, 1 /* copy_constraint_channels_hack */);
+       game_copy_pose(&m_pose, m_objArma->pose);
 }
 
 CValue* BL_ArmatureObject::GetReplica()
 {
        BL_ArmatureObject* replica = new BL_ArmatureObject(*this);
-       
-       // this will copy properties and so on...
-       CValue::AddDataToReplica(replica);
-
-       ProcessReplica(replica);
+       replica->ProcessReplica();
        return replica;
 }
 
-void BL_ArmatureObject::ProcessReplica(BL_ArmatureObject *replica)
+void BL_ArmatureObject::ProcessReplica()
 {
-       KX_GameObject::ProcessReplica(replica);
+       bPose *pose= m_pose;
+       KX_GameObject::ProcessReplica();
 
-       replica->m_pose = NULL;
-       copy_pose(&replica->m_pose, m_pose, 1 /* copy_constraint_channels_hack */);
+       m_pose = NULL;
+       game_copy_pose(&m_pose, pose);
 }
 
 BL_ArmatureObject::~BL_ArmatureObject()
 {
        if (m_pose)
-               free_pose(m_pose);
+               game_free_pose(m_pose);
 }
 
-bool BL_ArmatureObject::VerifyPose()
+void BL_ArmatureObject::ApplyPose()
 {
+       m_armpose = m_objArma->pose;
+       m_objArma->pose = m_pose;
+       //m_scene->r.cfra++;
        if(m_lastapplyframe != m_lastframe) {
-               extract_pose_from_pose(m_objArma->pose, m_pose);
-               where_is_pose(m_objArma);
+               where_is_pose(m_scene, m_objArma); // XXX
                m_lastapplyframe = m_lastframe;
-               extract_pose_from_pose(m_pose, m_objArma->pose);
-               return false;
        }
-       else
-               return true;
 }
 
-void BL_ArmatureObject::ApplyPose()
+void BL_ArmatureObject::RestorePose()
 {
-       if(VerifyPose())
-               extract_pose_from_pose(m_objArma->pose, m_pose);
+       m_objArma->pose = m_armpose;
+       m_armpose = NULL;
 }
 
 void BL_ArmatureObject::SetPose(bPose *pose)
@@ -164,8 +161,7 @@ void BL_ArmatureObject::GetPose(bPose **pose)
                        a crash and memory leakage when 
                        &BL_ActionActuator::m_pose is freed
                */
-               int copy_constraint_channels_hack = 1;
-               copy_pose(pose, m_pose, copy_constraint_channels_hack);
+               game_copy_pose(pose, m_pose);
        }
        else {
                if (*pose == m_pose)
@@ -181,17 +177,10 @@ void BL_ArmatureObject::GetMRDPose(bPose **pose)
        /* If the caller supplies a null pose, create a new one. */
        /* Otherwise, copy the armature's pose channels into the caller-supplied pose */
 
-       if (!*pose) {
-               // must duplicate the constraints too otherwise we have corruption in free_pose_channels()
-               // because it will free the blender constraints. 
-               // Ideally, blender should rememeber that the constraints were not copied so that
-               // free_pose_channels() would not free them.
-               copy_pose(pose, m_pose, 1);
-       }
-       else {
+       if (!*pose)
+               game_copy_pose(pose, m_pose);
+       else
                extract_pose_from_pose(*pose, m_pose);
-       }
-
 }
 
 short BL_ArmatureObject::GetActivePriority()
@@ -210,13 +199,11 @@ bool BL_ArmatureObject::GetBoneMatrix(Bone* bone, MT_Matrix4x4& matrix)
 
        ApplyPose();
        pchan = get_pose_channel(m_objArma->pose, bone->name);
-
-       if(pchan) {
+       if(pchan)
                matrix.setValue(&pchan->pose_mat[0][0]);
-               return true;
-       }
+       RestorePose();
 
-       return false;
+       return (pchan != NULL);
 }
 
 float BL_ArmatureObject::GetBoneLength(Bone* bone) const