some work on fcollada import

This commit is contained in:
ejcoumans
2006-05-27 01:24:08 +00:00
parent 718faabe59
commit 7392431860
7 changed files with 22 additions and 411 deletions

View File

@@ -37,36 +37,6 @@ subject to the following restrictions:
#include "GLDebugDrawer.h" #include "GLDebugDrawer.h"
//#define COLLADA_PHYSICS_TEST 1
#ifdef COLLADA_PHYSICS_TEST
//Collada Physics test
//#define NO_LIBXML //need LIBXML, because FCDocument/FCDPhysicsRigidBody.h needs FUDaeWriter, through FCDPhysicsParameter.hpp
#include "FUtils/FUtils.h"
#include "FCDocument/FCDocument.h"
#include "FCDocument/FCDSceneNode.h"
#include "FUtils/FUFileManager.h"
#include "FUtils/FULogFile.h"
#include "FCDocument/FCDPhysicsSceneNode.h"
#include "FCDocument/FCDPhysicsModelInstance.h"
#include "FCDocument/FCDPhysicsRigidBodyInstance.h"
#include "FCDocument/FCDPhysicsRigidBody.h"
#include "FCDocument/FCDGeometryInstance.h"
#include "FCDocument/FCDGeometryMesh.h"
#include "FCDocument/FCDGeometry.h"
#include "FCDocument/FCDPhysicsAnalyticalGeometry.h"
//aaa
#endif //COLLADA_PHYSICS_TEST
@@ -143,349 +113,8 @@ CollisionShape* shapePtr[numShapes] =
//////////////////////////////////// ////////////////////////////////////
#ifdef COLLADA_PHYSICS_TEST
bool ConvertColladaPhysicsToBulletPhysics(const FCDPhysicsSceneNode* inputNode)
{
assert(inputNode);
/// FRSceneNodeList nodesToDelete;
// FRMeshPhysicsController::StartCooking();
FCDPhysicsModelInstanceList models = inputNode->GetInstances();
//Go through all of the physics models
for (FCDPhysicsModelInstanceList::iterator itM=models.begin(); itM != models.end(); itM++)
{
FCDEntityInstanceList& instanceList = (*itM)->GetInstances();
//create one node per physics model. This node is pretty much only a middle man,
//but better describes the structure we get from the input file
//FRSceneNode* modelNode = new FRSceneNode();
//modelNode->SetParent(outputNode);
//outputNode->AddChild(modelNode);
//Go through all of the rigid bodies and rigid constraints in that model
for (FCDEntityInstanceList::iterator itE=instanceList.begin(); itE!=instanceList.end(); itE++)
{
if ((*itE)->GetType() == FCDEntityInstance::PHYSICS_RIGID_CONSTRAINT)
{
//not yet, could add point to point / hinge support easily
}
else
if ((*itE)->GetType() == FCDEntityInstance::PHYSICS_RIGID_BODY)
{
printf("PHYSICS_RIGID_BODY\n");
//Create a controller per rigid-body
//FRMeshPhysicsController* controller = new FRMeshPhysicsController(inputNode->GetGravity(), inputNode->GetTimestep());
FCDPhysicsRigidBodyInstance* rbInstance = (FCDPhysicsRigidBodyInstance*)(*itE);
FCDSceneNode* targetNode = rbInstance->GetTargetNode();
if (!targetNode)
{
//DebugOut("FCTranslator: No target node defined in rigid body instance");
//SAFE_DELETE(controller);
continue;
}
//Transfer all the transforms in n into cNode, and bake
//at the same time the scalings. It is necessary to re-translate the
//transforms as they will get deleted when we delete the old node.
//A better way to do this would be to steal the transforms from the old
//nodes, and make sure they're not deleted later, but this is impractical
//right now as we would also have to migrate all the animation curves.
//FRTScaleList scaleTransforms;
uint32 numTransforms = targetNode->GetTransformCount();
for (uint32 i=0; i<numTransforms; i++)
{
//targetNode->GetTransforms()[i]);
}
//Then affect all of its geometry instances.
//Collect all the entities inside the entity vector and inside the children nodes
/*
FREntityList childEntities = n->GetEntities();
FRSceneNodeList childrenToParse = n->GetChildren();
while (!childrenToParse.empty())
{
FRSceneNode* child = *childrenToParse.begin();
const FREntityList& e = child->GetEntities();
//add the entities of that child
childEntities.insert(childEntities.end(), e.begin(), e.end());
//queue the grand-children nodes
childrenToParse.insert(childrenToParse.end(), child->GetChildren().begin(), child->GetChildren().end());
childrenToParse.erase(childrenToParse.begin());
}
*/
//now check which ones are geometry mesh (right now an entity is only derived by mesh
//but do this to avoid problems in the future)
/*
for (FREntityList::iterator itT = childEntities.begin(); itT != childEntities.end(); itT++)
{
if ((*itT)->GetType() == FREntity::MESH || (*itT)->GetType() == FREntity::MESH_CONTROLLER)
{
FRMesh* cMesh = (FRMesh*)*itT;
//while we're here, bake the scaling transforms into the meshes
BakeScalingIntoMesh(cMesh, scaleTransforms);
controller->AddBindMesh((FRMesh*)*itT);
}
}
*/
/////////////////////////////////////////////////////////////////////
//We're done with the targets. Now take care of the physics shapes.
FCDPhysicsRigidBody* rigidBody = rbInstance->FlattenRigidBody();
FCDPhysicsMaterial* mat = rigidBody->GetPhysicsMaterial();
FCDPhysicsShapeList shapes = rigidBody->GetPhysicsShapeList();
for (uint32 i=0; i<shapes.size(); i++)
{
FCDPhysicsShape* OldShape = shapes[i];
OldShape->GetType();//
//controller->SetDensity(OldShape->GetDensity());
if (OldShape->GetGeometryInstance())
{
FCDGeometry* geoTemp = (FCDGeometry*)(OldShape->GetGeometryInstance()->GetEntity());
const FCDGeometryMesh* colladaMesh = geoTemp->GetMesh();
//FRMesh* cMesh = ToFREntityGeometry(geoTemp);
//BakeScalingIntoMesh(cMesh, scaleTransforms);
for (uint32 j=0; j<colladaMesh->GetPolygonsCount(); j++)
{
/*
FRMeshPhysicsShape* NewShape = new FRMeshPhysicsShape(controller);
if (!NewShape->CreateTriangleMesh(cMesh, j, true))
{
SAFE_DELETE(NewShape);
continue;
}
if (mat)
{
NewShape->SetMaterial(mat->GetStaticFriction(), mat->GetDynamicFriction(), mat->GetRestitution());
//FIXME
//NewShape->material->setFrictionCombineMode();
//NewShape->material->setSpring();
}
controller->AddShape(NewShape);
*/
}
}
else
{
//FRMeshPhysicsShape* NewShape = new FRMeshPhysicsShape(controller);
FCDPhysicsAnalyticalGeometry* analGeom = OldShape->GetAnalyticalGeometry();
//increse the following value for nicer shapes with more vertices
uint16 superEllipsoidSubdivisionLevel = 2;
if (!analGeom)
continue;
switch (analGeom->GetGeomType())
{
case FCDPhysicsAnalyticalGeometry::BOX:
{
FCDPASBox* box = (FCDPASBox*)analGeom;
break;
}
case FCDPhysicsAnalyticalGeometry::PLANE:
{
FCDPASPlane* plane = (FCDPASPlane*)analGeom;
break;
}
case FCDPhysicsAnalyticalGeometry::SPHERE:
{
FCDPASSphere* sphere = (FCDPASSphere*)analGeom;
break;
}
case FCDPhysicsAnalyticalGeometry::CYLINDER:
{
//FIXME: only using the first radius of the cylinder
FCDPASCylinder* cylinder = (FCDPASCylinder*)analGeom;
break;
}
case FCDPhysicsAnalyticalGeometry::CAPSULE:
{
//FIXME: only using the first radius of the capsule
FCDPASCapsule* capsule = (FCDPASCapsule*)analGeom;
break;
}
case FCDPhysicsAnalyticalGeometry::TAPERED_CAPSULE:
{
//FIXME: only using the first radius of the capsule
FCDPASTaperedCapsule* tcapsule = (FCDPASTaperedCapsule*)analGeom;
break;
}
case FCDPhysicsAnalyticalGeometry::TAPERED_CYLINDER:
{
//FIXME: only using the first radius of the cylinder
FCDPASTaperedCylinder* tcylinder = (FCDPASTaperedCylinder*)analGeom;
break;
}
default:
{
break;
}
}
//controller->AddShape(NewShape);
}
}
FCDPhysicsParameter<bool>* dyn = (FCDPhysicsParameter<bool>*)rigidBody->FindParameterByReference(DAE_DYNAMIC_ELEMENT);
if (dyn)
{
//dyn->GetValue();
}
FCDPhysicsParameter<float>* mass = (FCDPhysicsParameter<float>*)rigidBody->FindParameterByReference(DAE_MASS_ELEMENT);
if (mass)
{
mass->GetValue();
}
FCDPhysicsParameter<FMVector3>* inertia = (FCDPhysicsParameter<FMVector3>*)rigidBody->FindParameterByReference(DAE_INERTIA_ELEMENT);
if (inertia)
{
inertia->GetValue();
}
FCDPhysicsParameter<FMVector3>* velocity = (FCDPhysicsParameter<FMVector3>*)rigidBody->FindParameterByReference(DAE_VELOCITY_ELEMENT);
if (velocity)
{
velocity->GetValue();
}
FCDPhysicsParameter<FMVector3>* angularVelocity = (FCDPhysicsParameter<FMVector3>*)rigidBody->FindParameterByReference(DAE_ANGULAR_VELOCITY_ELEMENT);
if (angularVelocity)
{
angularVelocity->GetValue();
}
//controller->SetGlobalPose(n->CalculateWorldTransformation());//??
//SAFE_DELETE(rigidBody);
}
}
}
return true;
}
#endif //COLLADA_PHYSICS_TEST
////////////////////////////////////
@@ -494,27 +123,6 @@ GLDebugDrawer debugDrawer;
int main(int argc,char** argv) int main(int argc,char** argv)
{ {
#ifdef COLLADA_PHYSICS_TEST
char* filename = "ColladaPhysics.dae";
FCDocument* document = new FCDocument();
FUStatus status = document->LoadFromFile(filename);
bool success = status.IsSuccessful();
printf ("Collada import %i\n",success);
if (success)
{
const FCDPhysicsSceneNode* physicsSceneRoot = document->GetPhysicsSceneRoot();
if (ConvertColladaPhysicsToBulletPhysics( physicsSceneRoot ))
{
printf("ConvertColladaPhysicsToBulletPhysics successfull\n");
} else
{
printf("ConvertColladaPhysicsToBulletPhysics failed\n");
}
}
#endif //COLLADA_PHYSICS_TEST
CollisionDispatcher* dispatcher = new CollisionDispatcher(); CollisionDispatcher* dispatcher = new CollisionDispatcher();

View File

@@ -37,7 +37,7 @@ subject to the following restrictions:
#include "GLDebugDrawer.h" #include "GLDebugDrawer.h"
//#define COLLADA_PHYSICS_TEST 1 #define COLLADA_PHYSICS_TEST 1
#ifdef COLLADA_PHYSICS_TEST #ifdef COLLADA_PHYSICS_TEST
//Collada Physics test //Collada Physics test
@@ -57,8 +57,6 @@ subject to the following restrictions:
#include "FCDocument/FCDPhysicsAnalyticalGeometry.h" #include "FCDocument/FCDPhysicsAnalyticalGeometry.h"
//aaa //aaa
@@ -274,7 +272,6 @@ bool ConvertColladaPhysicsToBulletPhysics(const FCDPhysicsSceneNode* inputNode)
if (OldShape->GetGeometryInstance()) if (OldShape->GetGeometryInstance())
{ {
FCDGeometry* geoTemp = (FCDGeometry*)(OldShape->GetGeometryInstance()->GetEntity()); FCDGeometry* geoTemp = (FCDGeometry*)(OldShape->GetGeometryInstance()->GetEntity());
@@ -288,6 +285,7 @@ bool ConvertColladaPhysicsToBulletPhysics(const FCDPhysicsSceneNode* inputNode)
for (uint32 j=0; j<colladaMesh->GetPolygonsCount(); j++) for (uint32 j=0; j<colladaMesh->GetPolygonsCount(); j++)
{ {
/* /*
FRMeshPhysicsShape* NewShape = new FRMeshPhysicsShape(controller); FRMeshPhysicsShape* NewShape = new FRMeshPhysicsShape(controller);
@@ -436,14 +434,16 @@ bool ConvertColladaPhysicsToBulletPhysics(const FCDPhysicsSceneNode* inputNode)
if (dyn) if (dyn)
{ {
//dyn->GetValue(); bool* mydyn = dyn->GetValue();
printf("mydyn %i\n",*mydyn);
} }
FCDPhysicsParameter<float>* mass = (FCDPhysicsParameter<float>*)rigidBody->FindParameterByReference(DAE_MASS_ELEMENT); FCDPhysicsParameter<float>* mass = (FCDPhysicsParameter<float>*)rigidBody->FindParameterByReference(DAE_MASS_ELEMENT);
if (mass) if (mass)
{ {
mass->GetValue(); float* mymass = mass->GetValue();
printf("RB mass:%f\n",*mymass);
} }
FCDPhysicsParameter<FMVector3>* inertia = (FCDPhysicsParameter<FMVector3>*)rigidBody->FindParameterByReference(DAE_INERTIA_ELEMENT); FCDPhysicsParameter<FMVector3>* inertia = (FCDPhysicsParameter<FMVector3>*)rigidBody->FindParameterByReference(DAE_INERTIA_ELEMENT);
@@ -495,7 +495,7 @@ int main(int argc,char** argv)
{ {
#ifdef COLLADA_PHYSICS_TEST #ifdef COLLADA_PHYSICS_TEST
char* filename = "ColladaPhysics.dae"; char* filename = "analyticalGeomPhysicsTest.dae";//ColladaPhysics.dae";
FCDocument* document = new FCDocument(); FCDocument* document = new FCDocument();
FUStatus status = document->LoadFromFile(filename); FUStatus status = document->LoadFromFile(filename);
bool success = status.IsSuccessful(); bool success = status.IsSuccessful();

View File

@@ -290,7 +290,7 @@ unsigned int ConvexBuilder::process(const DecompDesc &desc)
hdesc.mVertexStride = sizeof(float)*3; hdesc.mVertexStride = sizeof(float)*3;
hdesc.mMaxVertices = desc.mMaxVertices; // maximum number of vertices allowed in the output hdesc.mMaxVertices = desc.mMaxVertices; // maximum number of vertices allowed in the output
if ( desc.mSkinWidth > 0 ) if ( desc.mSkinWidth )
{ {
hdesc.mSkinWidth = desc.mSkinWidth; hdesc.mSkinWidth = desc.mSkinWidth;
hdesc.SetHullFlag(QF_SKIN_WIDTH); // do skin width computation. hdesc.SetHullFlag(QF_SKIN_WIDTH); // do skin width computation.

View File

@@ -167,6 +167,8 @@ FUStatus FCDPhysicsShape::LoadFromXML(xmlNode* physicsShapeNode)
else else
{ {
FCDTransform* transform = FCDTFactory::CreateTransform(GetDocument(), NULL, child); FCDTransform* transform = FCDTFactory::CreateTransform(GetDocument(), NULL, child);
if (transform)
{
if (transform != NULL && (transform->GetType() != FCDTransform::TRANSLATION if (transform != NULL && (transform->GetType() != FCDTransform::TRANSLATION
|| transform->GetType() != FCDTransform::ROTATION || transform->GetType() != FCDTransform::SCALE)) || transform->GetType() != FCDTransform::ROTATION || transform->GetType() != FCDTransform::SCALE))
{ {
@@ -179,6 +181,7 @@ FUStatus FCDPhysicsShape::LoadFromXML(xmlNode* physicsShapeNode)
} }
} }
} }
}
return status; return status;
} }

View File

@@ -36,7 +36,7 @@ public:
/** Copy constructor. /** Copy constructor.
@param copy The dynamically-sized array to copy the values from. */ @param copy The dynamically-sized array to copy the values from. */
vector(const std::vector& copy) : std::vector<T>(copy) {} vector(const std::vector<T>& copy) : std::vector<T>(copy) {}
/** Constructor: Builds a dynamically-sized array from a constant-sized array. /** Constructor: Builds a dynamically-sized array from a constant-sized array.
@param values A constant-sized array of floating-point values. @param values A constant-sized array of floating-point values.

View File

@@ -237,7 +237,7 @@ fstring FUFileManager::MakeFilePathAbsolute(const fstring& _filePath)
if (filePath.size() < 2 || (filePath[1] != ':' && filePath[1] != '|')) if (filePath.size() < 2 || (filePath[1] != ':' && filePath[1] != '|'))
{ {
filePath.insert(0, '/'); filePath.insert(0, "/");//'/');
} }
} }

View File

@@ -50,7 +50,7 @@ void FUUniqueStringMapT<Builder>::AddUniqueString(typename Builder::String& want
{ {
// Attempt to generate a new string by appending an increasing counter. // Attempt to generate a new string by appending an increasing counter.
uint32 counter = 2; uint32 counter = 2;
static const maxCounter = 256; static const int maxCounter = 256;
Builder buffer; Builder buffer;
buffer.reserve(wantedStr.length() + 5); buffer.reserve(wantedStr.length() + 5);
do do