svn merge https://svn.blender.org/svnroot/bf-blender/trunk/blender -r20937:21899
[blender.git] / source / gameengine / Converter / BL_ActionActuator.cpp
index 88d6d294dc08e126d70c24c4177bde724466197c..30055a717e3c17151c3af949655f8936f5af64fb 100644 (file)
@@ -43,6 +43,7 @@
 #include "BKE_action.h"
 #include "DNA_action_types.h"
 #include "DNA_armature_types.h"
 #include "BKE_action.h"
 #include "DNA_action_types.h"
 #include "DNA_armature_types.h"
+#include "DNA_scene_types.h"
 #include "MEM_guardedalloc.h"
 #include "BLI_blenlib.h"
 #include "BLI_arithb.h"
 #include "MEM_guardedalloc.h"
 #include "BLI_blenlib.h"
 #include "BLI_arithb.h"
 #include "FloatValue.h"
 #include "PyObjectPlus.h"
 #include "KX_PyMath.h"
 #include "FloatValue.h"
 #include "PyObjectPlus.h"
 #include "KX_PyMath.h"
-#include "blendef.h"
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
 
 
 #ifdef HAVE_CONFIG_H
 #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)
 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);
                        
                        /* Get the underlying pose from the armature */
                        obj->GetPose(&m_pose);
-                       
+
+// 2.4x function, 
                        /* Override the necessary channels with ones from the action */
                        /* Override the necessary channels with ones from the action */
-                       extract_pose_from_action(m_pose, m_action, m_localtime);
+                       // 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);
                        /* Perform the user override (if any) */
                        if (m_userpose){
                                extract_pose_from_pose(m_pose, m_userpose);
@@ -381,7 +409,7 @@ bool BL_ActionActuator::Update(double curtime, bool frame)
                                
                                /* Find percentages */
                                newweight = (m_blendframe/(float)m_blendin);
                                
                                /* Find percentages */
                                newweight = (m_blendframe/(float)m_blendin);
-                               blend_poses(m_pose, m_blendpose, 1.0 - newweight, ACTSTRIPMODE_BLEND);
+                               game_blend_poses(m_pose, m_blendpose, 1.0 - newweight);
 
                                /* Increment current blending percentage */
                                m_blendframe = (curtime - m_blendstart)*KX_KetsjiEngine::GetAnimFrameRate();
 
                                /* Increment current blending percentage */
                                m_blendframe = (curtime - m_blendstart)*KX_KetsjiEngine::GetAnimFrameRate();
@@ -418,7 +446,7 @@ PyObject* BL_ActionActuator::PyGetAction(PyObject* args,
        ShowDeprecationWarning("getAction()", "the action property");
 
        if (m_action){
        ShowDeprecationWarning("getAction()", "the action property");
 
        if (m_action){
-               return PyString_FromString(m_action->id.name+2);
+               return PyUnicode_FromString(m_action->id.name+2);
        }
        Py_RETURN_NONE;
 }
        }
        Py_RETURN_NONE;
 }
@@ -768,7 +796,7 @@ PyObject* BL_ActionActuator::PySetFrameProperty(PyObject* args,
 }
 
 PyObject* BL_ActionActuator::PyGetChannel(PyObject* value) {
 }
 
 PyObject* BL_ActionActuator::PyGetChannel(PyObject* value) {
-       char *string= PyString_AsString(value);
+       char *string= _PyUnicode_AsString(value);
        
        if (!string) {
                PyErr_SetString(PyExc_TypeError, "expected a single string");
        
        if (!string) {
                PyErr_SetString(PyExc_TypeError, "expected a single string");
@@ -864,7 +892,7 @@ PyObject* BL_ActionActuator::PySetType(PyObject* args,
 PyObject* BL_ActionActuator::PyGetContinue() {
        ShowDeprecationWarning("getContinue()", "the continue property");
 
 PyObject* BL_ActionActuator::PyGetContinue() {
        ShowDeprecationWarning("getContinue()", "the continue property");
 
-    return PyInt_FromLong((long)(m_end_reset==0));
+    return PyLong_FromSsize_t((long)(m_end_reset==0));
 }
 
 PyObject* BL_ActionActuator::PySetContinue(PyObject* value) {
 }
 
 PyObject* BL_ActionActuator::PySetContinue(PyObject* value) {
@@ -930,10 +958,10 @@ KX_PYMETHODDEF_DOC(BL_ActionActuator, setChannel,
                                obj->GetPose(&m_pose); /* Get the underlying pose from the armature */
                        game_copy_pose(&m_userpose, m_pose);
                }
                                obj->GetPose(&m_pose); /* Get the underlying pose from the armature */
                        game_copy_pose(&m_userpose, m_pose);
                }
-               //pchan= verify_pose_channel(m_userpose, string); // adds the channel if its not there.
+               // pchan= verify_pose_channel(m_userpose, string); // adds the channel if its not there.
                pchan= get_pose_channel(m_userpose, string); // adds the channel if its not there.
                
                pchan= get_pose_channel(m_userpose, string); // adds the channel if its not there.
                
-               if (pchan) {
+               if(pchan) {
                        VECCOPY (pchan->loc, matrix[3]);
                        Mat4ToSize(matrix, pchan->size);
                        Mat4ToQuat(matrix, pchan->quat);
                        VECCOPY (pchan->loc, matrix[3]);
                        Mat4ToSize(matrix, pchan->size);
                        Mat4ToQuat(matrix, pchan->quat);
@@ -942,9 +970,9 @@ KX_PYMETHODDEF_DOC(BL_ActionActuator, setChannel,
        else {
                MT_Vector3 loc;
                MT_Vector3 size;
        else {
                MT_Vector3 loc;
                MT_Vector3 size;
-               MT_Vector4 quat;
+               MT_Quaternion quat;
                
                
-               if (!PyVecTo(pyloc, loc) || !PyVecTo(pysize, size) || !PyVecTo(pyquat, quat))
+               if (!PyVecTo(pyloc, loc) || !PyVecTo(pysize, size) || !PyQuatTo(pyquat, quat))
                        return NULL;
                
                // same as above
                        return NULL;
                
                // same as above
@@ -953,14 +981,14 @@ KX_PYMETHODDEF_DOC(BL_ActionActuator, setChannel,
                                obj->GetPose(&m_pose); /* Get the underlying pose from the armature */
                        game_copy_pose(&m_userpose, m_pose);
                }
                                obj->GetPose(&m_pose); /* Get the underlying pose from the armature */
                        game_copy_pose(&m_userpose, m_pose);
                }
-               //pchan= verify_pose_channel(m_userpose, string); // adds the channel if its not there.
-               pchan= get_pose_channel(m_userpose, string);
+               // pchan= verify_pose_channel(m_userpose, string);
+               pchan= get_pose_channel(m_userpose, string); // adds the channel if its not there.
                
                // for some reason loc.setValue(pchan->loc) fails
                if(pchan) {
                        pchan->loc[0]= loc[0]; pchan->loc[1]= loc[1]; pchan->loc[2]= loc[2];
                        pchan->size[0]= size[0]; pchan->size[1]= size[1]; pchan->size[2]= size[2];
                
                // for some reason loc.setValue(pchan->loc) fails
                if(pchan) {
                        pchan->loc[0]= loc[0]; pchan->loc[1]= loc[1]; pchan->loc[2]= loc[2];
                        pchan->size[0]= size[0]; pchan->size[1]= size[1]; pchan->size[2]= size[2];
-                       pchan->quat[0]= quat[0]; pchan->quat[1]= quat[1]; pchan->quat[2]= quat[2]; pchan->quat[3]= quat[3];
+                       pchan->quat[0]= quat[3]; pchan->quat[1]= quat[0]; pchan->quat[2]= quat[1]; pchan->quat[3]= quat[2]; /* notice xyzw -> wxyz is intentional */
                }
        }
        
                }
        }
        
@@ -994,19 +1022,15 @@ PyTypeObject BL_ActionActuator::Type = {
                0,
                0,
                py_base_repr,
                0,
                0,
                py_base_repr,
-               0,0,0,0,0,0,
-               py_base_getattro,
-               py_base_setattro,
                0,0,0,0,0,0,0,0,0,
                0,0,0,0,0,0,0,0,0,
-               Methods
-};
-
-PyParentObject BL_ActionActuator::Parents[] = {
-       &BL_ActionActuator::Type,
+               Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
+               0,0,0,0,0,0,0,
+               Methods,
+               0,
+               0,
                &SCA_IActuator::Type,
                &SCA_IActuator::Type,
-               &SCA_ILogicBrick::Type,
-               &CValue::Type,
-               NULL
+               0,0,0,0,0,0,
+               py_base_new
 };
 
 PyMethodDef BL_ActionActuator::Methods[] = {
 };
 
 PyMethodDef BL_ActionActuator::Methods[] = {
@@ -1055,37 +1079,24 @@ PyAttributeDef BL_ActionActuator::Attributes[] = {
        { NULL }        //Sentinel
 };
 
        { NULL }        //Sentinel
 };
 
-PyObject* BL_ActionActuator::py_getattro(PyObject *attr) {
-       py_getattro_up(SCA_IActuator);
-}
-
-PyObject* BL_ActionActuator::py_getattro_dict() {
-       py_getattro_dict_up(SCA_IActuator);
-}
-
-int BL_ActionActuator::py_setattro(PyObject *attr, PyObject* value) {
-       py_setattro_up(SCA_IActuator);
-}
-
-
 PyObject* BL_ActionActuator::pyattr_get_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
 {
        BL_ActionActuator* self= static_cast<BL_ActionActuator*>(self_v);
 PyObject* BL_ActionActuator::pyattr_get_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
 {
        BL_ActionActuator* self= static_cast<BL_ActionActuator*>(self_v);
-       return PyString_FromString(self->GetAction() ? self->GetAction()->id.name+2 : "");
+       return PyUnicode_FromString(self->GetAction() ? self->GetAction()->id.name+2 : "");
 }
 
 int BL_ActionActuator::pyattr_set_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
 {
        BL_ActionActuator* self= static_cast<BL_ActionActuator*>(self_v);
        
 }
 
 int BL_ActionActuator::pyattr_set_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
 {
        BL_ActionActuator* self= static_cast<BL_ActionActuator*>(self_v);
        
-       if (!PyString_Check(value))
+       if (!PyUnicode_Check(value))
        {
                PyErr_SetString(PyExc_ValueError, "actuator.action = val: Action Actuator, expected the string name of the action");
                return PY_SET_ATTR_FAIL;
        }
 
        bAction *action= NULL;
        {
                PyErr_SetString(PyExc_ValueError, "actuator.action = val: Action Actuator, expected the string name of the action");
                return PY_SET_ATTR_FAIL;
        }
 
        bAction *action= NULL;
-       STR_String val = PyString_AsString(value);
+       STR_String val = _PyUnicode_AsString(value);
        
        if (val != "")
        {
        
        if (val != "")
        {
@@ -1113,7 +1124,7 @@ PyObject* BL_ActionActuator::pyattr_get_channel_names(void *self_v, const KX_PYA
        if(pose) {
                bPoseChannel *pchan;
                for(pchan= (bPoseChannel *)pose->chanbase.first; pchan; pchan= (bPoseChannel *)pchan->next) {
        if(pose) {
                bPoseChannel *pchan;
                for(pchan= (bPoseChannel *)pose->chanbase.first; pchan; pchan= (bPoseChannel *)pchan->next) {
-                       item= PyString_FromString(pchan->name);
+                       item= PyUnicode_FromString(pchan->name);
                        PyList_Append(ret, item);
                        Py_DECREF(item);
                }
                        PyList_Append(ret, item);
                        Py_DECREF(item);
                }