ActionActuator in the game engine working again to display deformed meshes with the...
authorCampbell Barton <ideasman42@gmail.com>
Tue, 16 Jun 2009 20:38:18 +0000 (20:38 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 16 Jun 2009 20:38:18 +0000 (20:38 +0000)
Note that the animation conversion from existing 2.4x blend files doesnt yet set the Action pointer in the actuator so the only way to test is to use the python api to set the new converted action active on the actuator because there is no user interface.

source/gameengine/Converter/BL_ActionActuator.cpp
source/gameengine/Converter/BL_ArmatureObject.cpp
source/gameengine/Converter/BL_ArmatureObject.h
source/gameengine/Converter/BL_BlenderDataConversion.cpp
source/gameengine/Converter/KX_BlenderScalarInterpolator.cpp

index 0c7b99df3879cf21914e2126f119f9f716ce1718..131d48aed4f3ba8781eb0a2b3b9c19bd2af63e25 100644 (file)
 #include <config.h>
 #endif
 
+extern "C" {
+#include "BKE_animsys.h"
+#include "BKE_action.h"
+#include "RNA_access.h"
+#include "RNA_define.h"
+}
+
 BL_ActionActuator::~BL_ActionActuator()
 {
        if (m_pose)
@@ -360,10 +367,31 @@ bool BL_ActionActuator::Update(double curtime, bool frame)
                        
                        /* 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);
index 6fc5c40d57089a8b3c811d551751f499caefff7c..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"
 
 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),
@@ -93,9 +96,9 @@ void BL_ArmatureObject::ApplyPose()
 {
        m_armpose = m_objArma->pose;
        m_objArma->pose = m_pose;
-
+       //m_scene->r.cfra++;
        if(m_lastapplyframe != m_lastframe) {
-               where_is_pose(NULL, m_objArma); // XXX
+               where_is_pose(m_scene, m_objArma); // XXX
                m_lastapplyframe = m_lastframe;
        }
 }
index d5402cfd12671f7b25e965a35215e69ff4c186fd..e1e176840a600ae69af9fa63a28f6e1400d823d3 100644 (file)
@@ -51,7 +51,8 @@ public:
        BL_ArmatureObject(
                void* sgReplicationInfo,
                SG_Callbacks callbacks,
-               Object *armature
+               Object *armature,
+               Scene *scene
        );
        virtual ~BL_ArmatureObject();
 
@@ -67,6 +68,7 @@ public:
        
        struct bArmature * GetArmature() { return m_armature; }
        const struct bArmature * GetArmature() const { return m_armature; }
+       const struct Scene * GetScene() const { return m_scene; }
        
        Object* GetArmatureObject() {return m_objArma;}
 
@@ -84,6 +86,7 @@ protected:
        struct bPose            *m_pose;
        struct bPose            *m_armpose;
        struct bPose            *m_framePose;
+       struct Scene            *m_scene; // need for where_is_pose 
        double  m_lastframe;
        class BL_ActionActuator *m_activeAct;
        short   m_activePriority;
index c25bdbe71f7ee4a90427d2daf9737dddac32413e..b907e300879799538bdef1ddbf3b7919451fa2bc 100644 (file)
@@ -1795,7 +1795,8 @@ static KX_GameObject *gameobject_from_blenderobject(
                gameobj = new BL_ArmatureObject(
                        kxscene,
                        KX_Scene::m_callbacks,
-                       ob // handle
+                       ob,
+                       blenderscene // handle
                );
                /* Get the current pose from the armature object and apply it as the rest pose */
                break;
index 1ae963501976e1a5feb09604c965df0f38b21a72..20829524558ec8e180b594d186b243b66fbea22e 100644 (file)
@@ -27,7 +27,7 @@
  */
 
 #include "KX_BlenderScalarInterpolator.h"
-#include "stdio.h"
+
 #include <cstring>
 
 extern "C" {