working towards better COLLADA 1.4i physics conformance for the DOM

This commit is contained in:
ejcoumans
2006-07-16 22:26:11 +00:00
parent 4d596a6e7e
commit 9f9f35f847

View File

@@ -26,6 +26,7 @@ subject to the following restrictions:
#include "CollisionShapes/TriangleMesh.h"
#include "CollisionShapes/ConvexTriangleMeshShape.h"
#include "CollisionShapes/TriangleMeshShape.h"
#include "CollisionShapes/TriangleIndexVertexArray.h"
extern SimdVector3 gCameraUp;
@@ -71,9 +72,10 @@ extern int gForwardAxis;
#include "FCDocument/FCDGeometryInstance.h"
#include "FCDocument/FCDGeometrySource.h"
#include "FCDocument/FCDGeometryMesh.h"
#include "FCDocument/FCDPhysicsParameter.h"
#include "FCDocument/FCDPhysicsShape.h"
#include "FCDocument/FCDGeometryPolygons.h"
#include "FUtils/FUDaeSyntax.h"
#include "FCDocument/FCDGeometry.h"
#include "FCDocument/FCDPhysicsAnalyticalGeometry.h"
@@ -354,7 +356,7 @@ bool ConvertColladaPhysicsToBulletPhysics(const FCDPhysicsSceneNode* inputNode)
//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();
@@ -369,10 +371,10 @@ bool ConvertColladaPhysicsToBulletPhysics(const FCDPhysicsSceneNode* inputNode)
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++)
{
@@ -391,7 +393,7 @@ bool ConvertColladaPhysicsToBulletPhysics(const FCDPhysicsSceneNode* inputNode)
}
}
*/
*/
/////////////////////////////////////////////////////////////////////
@@ -514,23 +516,23 @@ bool ConvertColladaPhysicsToBulletPhysics(const FCDPhysicsSceneNode* inputNode)
index = inputs->indices[offset];
SimdVector3 vertex0(
inputs->source->GetSourceData()[index*3],
inputs->source->GetSourceData()[index*3+1],
inputs->source->GetSourceData()[index*3+2]);
inputs->GetSource()->GetSourceData()[index*3],
inputs->GetSource()->GetSourceData()[index*3+1],
inputs->GetSource()->GetSourceData()[index*3+2]);
index = inputs->indices[offset+1];
SimdVector3 vertex1(
inputs->source->GetSourceData()[index*3],
inputs->source->GetSourceData()[index*3+1],
inputs->source->GetSourceData()[index*3+2]);
inputs->GetSource()->GetSourceData()[index*3],
inputs->GetSource()->GetSourceData()[index*3+1],
inputs->GetSource()->GetSourceData()[index*3+2]);
index = inputs->indices[offset+2];
SimdVector3 vertex2(
inputs->source->GetSourceData()[index*3],
inputs->source->GetSourceData()[index*3+1],
inputs->source->GetSourceData()[index*3+2]);
inputs->GetSource()->GetSourceData()[index*3],
inputs->GetSource()->GetSourceData()[index*3+1],
inputs->GetSource()->GetSourceData()[index*3+2]);
trimesh->AddTriangle(vertex0,vertex1,vertex2);
@@ -544,30 +546,30 @@ bool ConvertColladaPhysicsToBulletPhysics(const FCDPhysicsSceneNode* inputNode)
index = inputs->indices[offset];
SimdVector3 vertex0(
inputs->source->GetSourceData()[index*3],
inputs->source->GetSourceData()[index*3+1],
inputs->source->GetSourceData()[index*3+2]);
inputs->GetSource()->GetSourceData()[index*3],
inputs->GetSource()->GetSourceData()[index*3+1],
inputs->GetSource()->GetSourceData()[index*3+2]);
index = inputs->indices[offset+1];
SimdVector3 vertex1(
inputs->source->GetSourceData()[index*3],
inputs->source->GetSourceData()[index*3+1],
inputs->source->GetSourceData()[index*3+2]);
inputs->GetSource()->GetSourceData()[index*3],
inputs->GetSource()->GetSourceData()[index*3+1],
inputs->GetSource()->GetSourceData()[index*3+2]);
index = inputs->indices[offset+2];
SimdVector3 vertex2(
inputs->source->GetSourceData()[index*3],
inputs->source->GetSourceData()[index*3+1],
inputs->source->GetSourceData()[index*3+2]);
inputs->GetSource()->GetSourceData()[index*3],
inputs->GetSource()->GetSourceData()[index*3+1],
inputs->GetSource()->GetSourceData()[index*3+2]);
index = inputs->indices[offset+3];
SimdVector3 vertex3(
inputs->source->GetSourceData()[index*3],
inputs->source->GetSourceData()[index*3+1],
inputs->source->GetSourceData()[index*3+2]);
inputs->GetSource()->GetSourceData()[index*3],
inputs->GetSource()->GetSourceData()[index*3+1],
inputs->GetSource()->GetSourceData()[index*3+2]);
trimesh->AddTriangle(vertex0,vertex1,vertex2);
trimesh->AddTriangle(vertex0,vertex2,vertex3);
@@ -581,7 +583,7 @@ bool ConvertColladaPhysicsToBulletPhysics(const FCDPhysicsSceneNode* inputNode)
}
}
if (colladaMesh->m_convex || isDynamic)
if (colladaMesh->IsConvex() || isDynamic)
{
collisionShape = new ConvexTriangleMeshShape(trimesh);
} else
@@ -1007,6 +1009,9 @@ int main(int argc,char** argv)
}//for all geometry libraries
//dom->getLibrary_physics_models_array()
for ( int i = 0; i < dom->getLibrary_physics_scenes_array().getCount(); i++)
{
domLibrary_physics_scenesRef physicsScenesRef = dom->getLibrary_physics_scenes_array()[i];
@@ -1016,39 +1021,49 @@ int main(int argc,char** argv)
for (int m=0;m<physicsSceneRef->getInstance_physics_model_array().getCount();m++)
{
domInstance_physics_modelRef modelRef = physicsSceneRef->getInstance_physics_model_array()[m];
domInstance_physics_modelRef instance_physicsModelRef = physicsSceneRef->getInstance_physics_model_array()[m];
daeElementRef ref = instance_physicsModelRef->getUrl().getElement();
//domPhysics_modelRef mr =;
daeElementRef ref = modelRef->getUrl().getElement();
domPhysics_modelRef model = *(domPhysics_modelRef*)&ref;
for (int r=0;r<instance_physicsModelRef->getInstance_rigid_body_array().getCount();r++)
{
domInstance_rigid_bodyRef rigidbodyRef = instance_physicsModelRef->getInstance_rigid_body_array()[r];
float mass = 1.f;
bool isDynamics = true;
CollisionShape* colShape = 0;
SimdTransform startTransform;
startTransform.setIdentity();
SimdVector3 startScale(1.f,1.f,1.f);
float mass = 1.f;
bool isDynamics = true;
CollisionShape* colShape = 0;
xsNCName bodyName = rigidbodyRef->getBody();
if (bodyName)
{
//try to find the rigid body
for (int r=0;r<model->getRigid_body_array().getCount();r++)
{
domRigid_bodyRef rigidBodyRef = model->getRigid_body_array()[r];
if (!strcmp(rigidBodyRef->getName(),bodyName))
{
domRigid_bodyRef physicsModel = model->getRigid_body_array()[r];
const domRigid_body::domTechnique_commonRef techniqueRef = physicsModel->getTechnique_common();
const domRigid_body::domTechnique_commonRef techniqueRef = rigidBodyRef->getTechnique_common();
if (techniqueRef)
{
if (techniqueRef->getMass())
{
mass = techniqueRef->getMass()->getValue();
}
if (techniqueRef->getDynamic())
{
isDynamics = techniqueRef->getDynamic()->getValue();
}
//shapes
for (int s=0;s<techniqueRef->getShape_array().getCount();s++)
@@ -1095,6 +1110,48 @@ int main(int argc,char** argv)
if (geom->getMesh())
{
const domMeshRef meshRef = geom->getMesh();
TriangleIndexVertexArray* tindexArray = new TriangleIndexVertexArray();
for (int tg = 0;tg<meshRef->getTriangles_array().getCount();tg++)
{
domTrianglesRef triRef = meshRef->getTriangles_array()[tg];
const domPRef pRef = triRef->getP();
daeMemoryRef memRef = pRef->getValue().getRawData();
IndexedMesh meshPart;
meshPart.m_triangleIndexStride=0;
for (int w=0;w<triRef->getInput_array().getCount();w++)
{
int offset = triRef->getInput_array()[w]->getOffset();
if (offset > meshPart.m_triangleIndexStride)
{
meshPart.m_triangleIndexStride = offset;
}
}
meshPart.m_triangleIndexStride++;
//int* m_triangleIndexBase;
meshPart.m_numTriangles = triRef->getCount();
//int m_triangleIndexStride;//calculate max offset
//int m_numVertices;
//float* m_vertexBase;//getRawData on floatArray
//int m_vertexStride;//use the accessor for this
//};
tindexArray->AddIndexedMesh(meshPart);
}
printf("(concave) mesh not supported yet\n");
}
@@ -1125,11 +1182,15 @@ int main(int argc,char** argv)
//we are not there yet...
const domConvex_meshRef convexRef = geom->getConvex_mesh();
daeString urlref = convexRef->getConvex_hull_of().getURI();
daeString urlref2 = convexRef->getConvex_hull_of().getOriginalURI();
//daeString urlref = convexRef->getConvex_hull_of().getURI();
//daeString urlref2 = convexRef->getConvex_hull_of().getOriginalURI();
daeElementRef otherElemRef = convexRef->getConvex_hull_of().getElement();
if ( otherElemRef != NULL )
{
domGeometryRef linkedGeom = *(domGeometryRef*)&otherElemRef;
// Load all the geometry libraries
for ( int i = 0; i < dom->getLibrary_geometries_array().getCount(); i++)
/*for ( int i = 0; i < dom->getLibrary_geometries_array().getCount(); i++)
{
domLibrary_geometriesRef libgeom = dom->getLibrary_geometries_array()[i];
//int index = libgeom->findLastIndexOf(urlref2);
@@ -1140,9 +1201,9 @@ int main(int argc,char** argv)
//ReadGeometry( );
domGeometryRef lib = libgeom->getGeometry_array()[i];
if (!strcmp(lib->getName(),urlref2))
{
{*/
//found convex_hull geometry
domMesh *meshElement = lib->getMesh();
domMesh *meshElement = linkedGeom->getMesh();
if (meshElement)
{
const domVerticesRef vertsRef = meshElement->getVertices();
@@ -1182,8 +1243,8 @@ int main(int argc,char** argv)
}
}
}
}
@@ -1207,13 +1268,9 @@ int main(int argc,char** argv)
printf("convexmesh\n");
}
}
}
@@ -1221,15 +1278,15 @@ int main(int argc,char** argv)
}
}
}
//////////////////////
}
for (int r=0;r<modelRef->getInstance_rigid_body_array().getCount();r++)
{
domInstance_rigid_bodyRef rigidbodyRef = modelRef->getInstance_rigid_body_array()[r];
domInstance_rigid_body::domTechnique_commonRef techniqueRef = rigidbodyRef->getTechnique_common();
//The 'target' points to a graphics element/node, which contains the start (world) transform
daeElementRef elem = rigidbodyRef->getTarget().getElement();
if (elem)
{
@@ -1263,13 +1320,17 @@ int main(int argc,char** argv)
}
domInstance_rigid_body::domTechnique_commonRef techniqueRef = rigidbodyRef->getTechnique_common();
if (techniqueRef)
{
if (techniqueRef->getMass())
{
mass = techniqueRef->getMass()->getValue();
}
if (techniqueRef->getDynamic())
{
isDynamics = techniqueRef->getDynamic()->getValue();
}
}
printf("mass = %f, isDynamics %i\n",mass,isDynamics);
@@ -1279,22 +1340,19 @@ int main(int argc,char** argv)
}
} //for each instance_rigid_body
//we don't handle constraints just yet
for (int c=0;c<modelRef->getInstance_rigid_constraint_array().getCount();i++)
for (int c=0;c<instance_physicsModelRef->getInstance_rigid_constraint_array().getCount();i++)
{
}
}
}
}
}
}
#endif
@@ -1841,3 +1899,4 @@ void clientMotionFunc(int x,int y)
}
}