more preparation for physics recording to ipo keyframes
authorErwin Coumans <blender@erwincoumans.com>
Mon, 22 Aug 2005 18:31:19 +0000 (18:31 +0000)
committerErwin Coumans <blender@erwincoumans.com>
Mon, 22 Aug 2005 18:31:19 +0000 (18:31 +0000)
source/gameengine/Converter/KX_BlenderSceneConverter.cpp
source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
source/gameengine/Ketsji/KX_GameObject.h
source/gameengine/Ketsji/KX_KetsjiEngine.cpp
source/gameengine/Ketsji/KX_KetsjiEngine.h
source/gameengine/Ketsji/KX_SumoPhysicsController.cpp

index fa71698..b7942fd 100644 (file)
 #include "KX_IpoConvert.h"
 #include "RAS_MeshObject.h"
 #include "KX_PhysicsEngineEnums.h"
+#include "PHY_IPhysicsEnvironment.h"
+#include "KX_KetsjiEngine.h"
+#include "Object.h"
+#include "KX_IPhysicsController.h"
 
 #include "DummyPhysicsEnvironment.h"
 
 #include "DNA_world_types.h"
 #include "BKE_main.h"
 
+#include "DNA_object_types.h"
+#include "DNA_ipo_types.h"
+#include "DNA_curve_types.h"
+
 
 KX_BlenderSceneConverter::KX_BlenderSceneConverter(
                                                        struct Main* maggie,
@@ -321,7 +329,9 @@ void KX_BlenderSceneConverter::ConvertScene(const STR_String& scenename,
        
        m_map_blender_to_gameobject.clear();
        m_map_mesh_to_gamemesh.clear();
-       m_map_gameobject_to_blender.clear();
+
+       //don't clear it yet, it is needed for the baking physics into ipo animation
+       //m_map_gameobject_to_blender.clear();
 }
 
 
@@ -466,6 +476,50 @@ void KX_BlenderSceneConverter::RegisterWorldInfo(
 void   KX_BlenderSceneConverter::ResetPhysicsObjectsAnimationIpo()
 {
        //todo,before 2.38/2.40 release, Erwin
+
+       KX_SceneList* scenes = m_ketsjiEngine->CurrentScenes();
+       int numScenes = scenes->size();
+       int i;
+       for (i=0;i<numScenes;i++)
+       {
+               KX_Scene* scene = scenes->at(i);
+               //PHY_IPhysicsEnvironment* physEnv = scene->GetPhysicsEnvironment();
+               CListValue* parentList = scene->GetRootParentList();
+               int numObjects = parentList->GetCount();
+               int g;
+               for (g=0;g<numObjects;g++)
+               {
+                       KX_GameObject* gameObj = (KX_GameObject*)parentList->GetValue(g);
+                       if (gameObj->IsDynamic())
+                       {
+                               //KX_IPhysicsController* physCtrl = gameObj->GetPhysicsController();
+                               
+                               Object* blenderObject = FindBlenderObject(gameObj);
+                               if (blenderObject)
+                               {
+                                       //erase existing ipo's
+                                       Ipo* ipo = blenderObject->ipo;
+                                       if (ipo)
+                                       {
+
+                                               IpoCurve *icu;
+                                               int numCurves = 0;
+                                               for( icu = (IpoCurve*)ipo->curve.first; icu; icu = icu->next ) {
+                                                       numCurves++;
+                                                       
+                                               }
+
+                                       }
+                               }
+                       }
+
+               }
+               
+       
+       }
+
+
+
 }
 
        ///this generates ipo curves for position, rotation, allowing to use game physics in animation
@@ -596,6 +650,19 @@ void       KX_BlenderSceneConverter::WritePhysicsObjectToAnimationIpo(int frameNumber)
                                                        return IpoCurve_CreatePyObject( icu );
                                                }
 
+                                               static PyObject *Ipo_getNcurves( BPy_Ipo * self )
+                                               {
+                                                       int i = 0;
+
+                                                       IpoCurve *icu;
+                                                       for( icu = self->ipo->curve.first; icu; icu = icu->next ) {
+                                                               i++;
+                                                       }
+
+                                                       return ( PyInt_FromLong( i ) );
+                                               }
+
+
                                                static PyObject *Ipo_getNBezPoints( BPy_Ipo * self, PyObject * args )
                                                {
                                                        int num = 0, i = 0;
index cedd689..b5aea65 100644 (file)
@@ -305,7 +305,7 @@ static void BL_RegisterSumoObject(
 
                // need easy access, not via 'node' etc.
                KX_SumoPhysicsController* physicscontroller = new KX_SumoPhysicsController(sumoScene,sumoObj,motionstate,isDynamic);
-               gameobj->SetPhysicsController(physicscontroller);
+               gameobj->SetPhysicsController(physicscontroller,isDynamic);
 
                
                if (!gameobj->getClientInfo())
@@ -1012,7 +1012,7 @@ void      KX_ConvertBulletObject( class   KX_GameObject* gameobj,
        env->addCcdPhysicsController( physicscontroller);
 
        
-       gameobj->SetPhysicsController(physicscontroller);
+       gameobj->SetPhysicsController(physicscontroller,dyna);
        physicscontroller->setNewClientInfo(gameobj->getClientInfo());          
        bool isActor = objprop->m_isactor;
        gameobj->getClientInfo()->m_type = (isActor ? KX_ClientObjectInfo::ACTOR : KX_ClientObjectInfo::STATIC);
index fa11679..3462889 100644 (file)
@@ -265,38 +265,26 @@ public:
         * @return a pointer to the physics controller owned by this class.
         */
 
-               KX_IPhysicsController* 
-       GetPhysicsController(
-       ) ;
+       KX_IPhysicsController* GetPhysicsController() ;
 
-       void    SetPhysicsController
-               (KX_IPhysicsController* physicscontroller) 
-       { m_pPhysicsController1 = physicscontroller;};
+       void    SetPhysicsController(KX_IPhysicsController*     physicscontroller,bool isDynamic) 
+       { 
+               m_bDyna = isDynamic;
+               m_pPhysicsController1 = physicscontroller;
+       }
 
 
        /**
         * @section Coordinate system manipulation functions
         */
 
-               void                                            
-       NodeSetLocalPosition(
-               const MT_Point3& trans
-       );
+       void    NodeSetLocalPosition(const MT_Point3& trans     );
 
-               void                                            
-       NodeSetLocalOrientation(
-               const MT_Matrix3x3& rot
-       );
+       void    NodeSetLocalOrientation(const MT_Matrix3x3& rot );
 
-               void                                            
-       NodeSetLocalScale(
-               const MT_Vector3& scale
-       );
+       void    NodeSetLocalScale(      const MT_Vector3& scale );
 
-               void                                            
-       NodeSetRelativeScale(
-               const MT_Vector3& scale
-       );
+       void    NodeSetRelativeScale(   const MT_Vector3& scale );
 
                void                                            
        NodeUpdateGS(
@@ -324,16 +312,13 @@ public:
         * @section scene graph node accessor functions.
         */
 
-               SG_Node*                                        
-       GetSGNode(
-       ) { 
+       SG_Node*        GetSGNode(      ) 
+       { 
                return m_pSGNode;
        }
 
-       const 
-               SG_Node*                                
-       GetSGNode(
-       ) const { 
+       const   SG_Node* GetSGNode(     ) const 
+       { 
                return m_pSGNode;
        }
 
@@ -345,19 +330,14 @@ public:
         * old node. This class takes ownership of the new
         * node.
         */
-               void                                            
-       SetSGNode(
-               SG_Node* node
-       ){ 
-               m_pSGNode = node; 
-       }
+               void    SetSGNode(SG_Node* node )
+               { 
+                       m_pSGNode = node; 
+               }
        
-       /**
-        * Deprecated & broken
-        */
-               bool                                            
-       IsDynamic(
-       ) const { 
+       //Is it a dynamic/physics object ?
+       bool    IsDynamic() const 
+       { 
                return m_bDyna; 
        }
        
index 10bf708..24c3497 100644 (file)
@@ -258,6 +258,10 @@ void KX_KetsjiEngine::StartEngine()
        m_firstframe = true;
        m_bInitialized = true;
        m_ticrate = DEFAULT_LOGIC_TIC_RATE;
+       m_currentFrame = 0;
+
+       m_sceneconverter->ResetPhysicsObjectsAnimationIpo();
+
 }
 
 bool KX_KetsjiEngine::BeginFrame()
@@ -305,6 +309,8 @@ void KX_KetsjiEngine::EndFrame()
        m_rendertools->EndFrame(m_rasterizer);
        
        m_canvas->EndDraw();
+       
+
 }
 
 
@@ -390,6 +396,9 @@ void KX_KetsjiEngine::NextFrame()
                                m_logger->StartLog(tc_physics, m_kxsystem->GetTimeInSeconds(), true);
                                scene->GetPhysicsEnvironment()->proceedDeltaTime(localtime,realDeltaTime);
                                m_previoustime = curtime;
+
+                               m_sceneconverter->WritePhysicsObjectToAnimationIpo(m_currentFrame++);
+
                        } // suspended
        
                        DoSound(scene);
index 8ea6112..5af694f 100644 (file)
@@ -97,7 +97,8 @@ private:
        bool                            m_bFixedTime;
        
        bool                            m_firstframe;
-       
+       int                                     m_currentFrame;
+
        double                          m_previoustime;
        double                          m_deltatime;
        static double                   m_ticrate;
index a062a34..11a09a1 100644 (file)
@@ -157,9 +157,11 @@ void       KX_SumoPhysicsController::SetObject (SG_IObject* object)
        SG_Controller::SetObject(object);
 
        // cheating here...
-       KX_GameObject* gameobj = (KX_GameObject*)       object->GetSGClientObject();
-       gameobj->SetPhysicsController(this);
-       GetSumoObject()->setClientObject(gameobj->getClientInfo());
+//should not be necessary, is it for duplicates ?
+
+KX_GameObject* gameobj = (KX_GameObject*)      object->GetSGClientObject();
+gameobj->SetPhysicsController(this,gameobj->IsDynamic());
+GetSumoObject()->setClientObject(gameobj->getClientInfo());
 }