more preparation for physics recording to ipo keyframes

This commit is contained in:
Erwin Coumans
2005-08-22 18:31:19 +00:00
parent 3b8e94ac6b
commit 43b59afebb
6 changed files with 107 additions and 48 deletions

View File

@@ -39,6 +39,10 @@
#include "KX_IpoConvert.h" #include "KX_IpoConvert.h"
#include "RAS_MeshObject.h" #include "RAS_MeshObject.h"
#include "KX_PhysicsEngineEnums.h" #include "KX_PhysicsEngineEnums.h"
#include "PHY_IPhysicsEnvironment.h"
#include "KX_KetsjiEngine.h"
#include "Object.h"
#include "KX_IPhysicsController.h"
#include "DummyPhysicsEnvironment.h" #include "DummyPhysicsEnvironment.h"
@@ -73,6 +77,10 @@
#include "DNA_world_types.h" #include "DNA_world_types.h"
#include "BKE_main.h" #include "BKE_main.h"
#include "DNA_object_types.h"
#include "DNA_ipo_types.h"
#include "DNA_curve_types.h"
KX_BlenderSceneConverter::KX_BlenderSceneConverter( KX_BlenderSceneConverter::KX_BlenderSceneConverter(
struct Main* maggie, struct Main* maggie,
@@ -321,7 +329,9 @@ void KX_BlenderSceneConverter::ConvertScene(const STR_String& scenename,
m_map_blender_to_gameobject.clear(); m_map_blender_to_gameobject.clear();
m_map_mesh_to_gamemesh.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() void KX_BlenderSceneConverter::ResetPhysicsObjectsAnimationIpo()
{ {
//todo,before 2.38/2.40 release, Erwin //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 ///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 ); 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 ) static PyObject *Ipo_getNBezPoints( BPy_Ipo * self, PyObject * args )
{ {
int num = 0, i = 0; int num = 0, i = 0;

View File

@@ -305,7 +305,7 @@ static void BL_RegisterSumoObject(
// need easy access, not via 'node' etc. // need easy access, not via 'node' etc.
KX_SumoPhysicsController* physicscontroller = new KX_SumoPhysicsController(sumoScene,sumoObj,motionstate,isDynamic); KX_SumoPhysicsController* physicscontroller = new KX_SumoPhysicsController(sumoScene,sumoObj,motionstate,isDynamic);
gameobj->SetPhysicsController(physicscontroller); gameobj->SetPhysicsController(physicscontroller,isDynamic);
if (!gameobj->getClientInfo()) if (!gameobj->getClientInfo())
@@ -1012,7 +1012,7 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj,
env->addCcdPhysicsController( physicscontroller); env->addCcdPhysicsController( physicscontroller);
gameobj->SetPhysicsController(physicscontroller); gameobj->SetPhysicsController(physicscontroller,dyna);
physicscontroller->setNewClientInfo(gameobj->getClientInfo()); physicscontroller->setNewClientInfo(gameobj->getClientInfo());
bool isActor = objprop->m_isactor; bool isActor = objprop->m_isactor;
gameobj->getClientInfo()->m_type = (isActor ? KX_ClientObjectInfo::ACTOR : KX_ClientObjectInfo::STATIC); gameobj->getClientInfo()->m_type = (isActor ? KX_ClientObjectInfo::ACTOR : KX_ClientObjectInfo::STATIC);

View File

@@ -265,38 +265,26 @@ public:
* @return a pointer to the physics controller owned by this class. * @return a pointer to the physics controller owned by this class.
*/ */
KX_IPhysicsController* KX_IPhysicsController* GetPhysicsController() ;
GetPhysicsController(
) ;
void SetPhysicsController void SetPhysicsController(KX_IPhysicsController* physicscontroller,bool isDynamic)
(KX_IPhysicsController* physicscontroller) {
{ m_pPhysicsController1 = physicscontroller;}; m_bDyna = isDynamic;
m_pPhysicsController1 = physicscontroller;
}
/** /**
* @section Coordinate system manipulation functions * @section Coordinate system manipulation functions
*/ */
void void NodeSetLocalPosition(const MT_Point3& trans );
NodeSetLocalPosition(
const MT_Point3& trans
);
void void NodeSetLocalOrientation(const MT_Matrix3x3& rot );
NodeSetLocalOrientation(
const MT_Matrix3x3& rot
);
void void NodeSetLocalScale( const MT_Vector3& scale );
NodeSetLocalScale(
const MT_Vector3& scale
);
void void NodeSetRelativeScale( const MT_Vector3& scale );
NodeSetRelativeScale(
const MT_Vector3& scale
);
void void
NodeUpdateGS( NodeUpdateGS(
@@ -324,16 +312,13 @@ public:
* @section scene graph node accessor functions. * @section scene graph node accessor functions.
*/ */
SG_Node* SG_Node* GetSGNode( )
GetSGNode( {
) {
return m_pSGNode; return m_pSGNode;
} }
const const SG_Node* GetSGNode( ) const
SG_Node* {
GetSGNode(
) const {
return m_pSGNode; return m_pSGNode;
} }
@@ -345,19 +330,14 @@ public:
* old node. This class takes ownership of the new * old node. This class takes ownership of the new
* node. * node.
*/ */
void void SetSGNode(SG_Node* node )
SetSGNode( {
SG_Node* node m_pSGNode = node;
){ }
m_pSGNode = node;
}
/** //Is it a dynamic/physics object ?
* Deprecated & broken bool IsDynamic() const
*/ {
bool
IsDynamic(
) const {
return m_bDyna; return m_bDyna;
} }

View File

@@ -258,6 +258,10 @@ void KX_KetsjiEngine::StartEngine()
m_firstframe = true; m_firstframe = true;
m_bInitialized = true; m_bInitialized = true;
m_ticrate = DEFAULT_LOGIC_TIC_RATE; m_ticrate = DEFAULT_LOGIC_TIC_RATE;
m_currentFrame = 0;
m_sceneconverter->ResetPhysicsObjectsAnimationIpo();
} }
bool KX_KetsjiEngine::BeginFrame() bool KX_KetsjiEngine::BeginFrame()
@@ -305,6 +309,8 @@ void KX_KetsjiEngine::EndFrame()
m_rendertools->EndFrame(m_rasterizer); m_rendertools->EndFrame(m_rasterizer);
m_canvas->EndDraw(); m_canvas->EndDraw();
} }
@@ -390,6 +396,9 @@ void KX_KetsjiEngine::NextFrame()
m_logger->StartLog(tc_physics, m_kxsystem->GetTimeInSeconds(), true); m_logger->StartLog(tc_physics, m_kxsystem->GetTimeInSeconds(), true);
scene->GetPhysicsEnvironment()->proceedDeltaTime(localtime,realDeltaTime); scene->GetPhysicsEnvironment()->proceedDeltaTime(localtime,realDeltaTime);
m_previoustime = curtime; m_previoustime = curtime;
m_sceneconverter->WritePhysicsObjectToAnimationIpo(m_currentFrame++);
} // suspended } // suspended
DoSound(scene); DoSound(scene);

View File

@@ -97,7 +97,8 @@ private:
bool m_bFixedTime; bool m_bFixedTime;
bool m_firstframe; bool m_firstframe;
int m_currentFrame;
double m_previoustime; double m_previoustime;
double m_deltatime; double m_deltatime;
static double m_ticrate; static double m_ticrate;

View File

@@ -157,9 +157,11 @@ void KX_SumoPhysicsController::SetObject (SG_IObject* object)
SG_Controller::SetObject(object); SG_Controller::SetObject(object);
// cheating here... // cheating here...
KX_GameObject* gameobj = (KX_GameObject*) object->GetSGClientObject(); //should not be necessary, is it for duplicates ?
gameobj->SetPhysicsController(this);
GetSumoObject()->setClientObject(gameobj->getClientInfo()); KX_GameObject* gameobj = (KX_GameObject*) object->GetSGClientObject();
gameobj->SetPhysicsController(this,gameobj->IsDynamic());
GetSumoObject()->setClientObject(gameobj->getClientInfo());
} }