working towards better COLLADA 1.4i physics conformance for the DOM
This commit is contained in:
@@ -26,6 +26,7 @@ subject to the following restrictions:
|
|||||||
#include "CollisionShapes/TriangleMesh.h"
|
#include "CollisionShapes/TriangleMesh.h"
|
||||||
#include "CollisionShapes/ConvexTriangleMeshShape.h"
|
#include "CollisionShapes/ConvexTriangleMeshShape.h"
|
||||||
#include "CollisionShapes/TriangleMeshShape.h"
|
#include "CollisionShapes/TriangleMeshShape.h"
|
||||||
|
#include "CollisionShapes/TriangleIndexVertexArray.h"
|
||||||
|
|
||||||
|
|
||||||
extern SimdVector3 gCameraUp;
|
extern SimdVector3 gCameraUp;
|
||||||
@@ -71,9 +72,10 @@ extern int gForwardAxis;
|
|||||||
#include "FCDocument/FCDGeometryInstance.h"
|
#include "FCDocument/FCDGeometryInstance.h"
|
||||||
#include "FCDocument/FCDGeometrySource.h"
|
#include "FCDocument/FCDGeometrySource.h"
|
||||||
#include "FCDocument/FCDGeometryMesh.h"
|
#include "FCDocument/FCDGeometryMesh.h"
|
||||||
|
#include "FCDocument/FCDPhysicsParameter.h"
|
||||||
|
#include "FCDocument/FCDPhysicsShape.h"
|
||||||
#include "FCDocument/FCDGeometryPolygons.h"
|
#include "FCDocument/FCDGeometryPolygons.h"
|
||||||
|
#include "FUtils/FUDaeSyntax.h"
|
||||||
|
|
||||||
#include "FCDocument/FCDGeometry.h"
|
#include "FCDocument/FCDGeometry.h"
|
||||||
#include "FCDocument/FCDPhysicsAnalyticalGeometry.h"
|
#include "FCDocument/FCDPhysicsAnalyticalGeometry.h"
|
||||||
@@ -354,44 +356,44 @@ bool ConvertColladaPhysicsToBulletPhysics(const FCDPhysicsSceneNode* inputNode)
|
|||||||
|
|
||||||
//Then affect all of its geometry instances.
|
//Then affect all of its geometry instances.
|
||||||
//Collect all the entities inside the entity vector and inside the children nodes
|
//Collect all the entities inside the entity vector and inside the children nodes
|
||||||
/*
|
/*
|
||||||
FREntityList childEntities = n->GetEntities();
|
FREntityList childEntities = n->GetEntities();
|
||||||
FRSceneNodeList childrenToParse = n->GetChildren();
|
FRSceneNodeList childrenToParse = n->GetChildren();
|
||||||
|
|
||||||
while (!childrenToParse.empty())
|
while (!childrenToParse.empty())
|
||||||
{
|
{
|
||||||
FRSceneNode* child = *childrenToParse.begin();
|
FRSceneNode* child = *childrenToParse.begin();
|
||||||
const FREntityList& e = child->GetEntities();
|
const FREntityList& e = child->GetEntities();
|
||||||
//add the entities of that child
|
//add the entities of that child
|
||||||
childEntities.insert(childEntities.end(), e.begin(), e.end());
|
childEntities.insert(childEntities.end(), e.begin(), e.end());
|
||||||
//queue the grand-children nodes
|
//queue the grand-children nodes
|
||||||
childrenToParse.insert(childrenToParse.end(), child->GetChildren().begin(), child->GetChildren().end());
|
childrenToParse.insert(childrenToParse.end(), child->GetChildren().begin(), child->GetChildren().end());
|
||||||
childrenToParse.erase(childrenToParse.begin());
|
childrenToParse.erase(childrenToParse.begin());
|
||||||
|
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
//now check which ones are geometry mesh (right now an entity is only derived by mesh
|
//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)
|
//but do this to avoid problems in the future)
|
||||||
/*
|
/*
|
||||||
for (FREntityList::iterator itT = childEntities.begin(); itT != childEntities.end(); itT++)
|
for (FREntityList::iterator itT = childEntities.begin(); itT != childEntities.end(); itT++)
|
||||||
{
|
{
|
||||||
|
|
||||||
if ((*itT)->GetType() == FREntity::MESH || (*itT)->GetType() == FREntity::MESH_CONTROLLER)
|
if ((*itT)->GetType() == FREntity::MESH || (*itT)->GetType() == FREntity::MESH_CONTROLLER)
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
||||||
FRMesh* cMesh = (FRMesh*)*itT;
|
FRMesh* cMesh = (FRMesh*)*itT;
|
||||||
|
|
||||||
//while we're here, bake the scaling transforms into the meshes
|
//while we're here, bake the scaling transforms into the meshes
|
||||||
|
|
||||||
BakeScalingIntoMesh(cMesh, scaleTransforms);
|
BakeScalingIntoMesh(cMesh, scaleTransforms);
|
||||||
|
|
||||||
controller->AddBindMesh((FRMesh*)*itT);
|
controller->AddBindMesh((FRMesh*)*itT);
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////
|
||||||
@@ -509,65 +511,65 @@ bool ConvertColladaPhysicsToBulletPhysics(const FCDPhysicsSceneNode* inputNode)
|
|||||||
|
|
||||||
//float value = inputs->source->GetSourceData()[index];
|
//float value = inputs->source->GetSourceData()[index];
|
||||||
|
|
||||||
int offset = poly->GetFaceVertexOffset(p);
|
int offset = poly->GetFaceVertexOffset(p);
|
||||||
int index;
|
int index;
|
||||||
index = inputs->indices[offset];
|
index = inputs->indices[offset];
|
||||||
|
|
||||||
SimdVector3 vertex0(
|
SimdVector3 vertex0(
|
||||||
inputs->source->GetSourceData()[index*3],
|
inputs->GetSource()->GetSourceData()[index*3],
|
||||||
inputs->source->GetSourceData()[index*3+1],
|
inputs->GetSource()->GetSourceData()[index*3+1],
|
||||||
inputs->source->GetSourceData()[index*3+2]);
|
inputs->GetSource()->GetSourceData()[index*3+2]);
|
||||||
|
|
||||||
index = inputs->indices[offset+1];
|
index = inputs->indices[offset+1];
|
||||||
|
|
||||||
SimdVector3 vertex1(
|
SimdVector3 vertex1(
|
||||||
inputs->source->GetSourceData()[index*3],
|
inputs->GetSource()->GetSourceData()[index*3],
|
||||||
inputs->source->GetSourceData()[index*3+1],
|
inputs->GetSource()->GetSourceData()[index*3+1],
|
||||||
inputs->source->GetSourceData()[index*3+2]);
|
inputs->GetSource()->GetSourceData()[index*3+2]);
|
||||||
|
|
||||||
index = inputs->indices[offset+2];
|
index = inputs->indices[offset+2];
|
||||||
|
|
||||||
SimdVector3 vertex2(
|
SimdVector3 vertex2(
|
||||||
inputs->source->GetSourceData()[index*3],
|
inputs->GetSource()->GetSourceData()[index*3],
|
||||||
inputs->source->GetSourceData()[index*3+1],
|
inputs->GetSource()->GetSourceData()[index*3+1],
|
||||||
inputs->source->GetSourceData()[index*3+2]);
|
inputs->GetSource()->GetSourceData()[index*3+2]);
|
||||||
|
|
||||||
|
|
||||||
trimesh->AddTriangle(vertex0,vertex1,vertex2);
|
trimesh->AddTriangle(vertex0,vertex1,vertex2);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
{
|
{
|
||||||
int offset = poly->GetFaceVertexOffset(p);
|
int offset = poly->GetFaceVertexOffset(p);
|
||||||
int index;
|
int index;
|
||||||
index = inputs->indices[offset];
|
index = inputs->indices[offset];
|
||||||
|
|
||||||
SimdVector3 vertex0(
|
SimdVector3 vertex0(
|
||||||
inputs->source->GetSourceData()[index*3],
|
inputs->GetSource()->GetSourceData()[index*3],
|
||||||
inputs->source->GetSourceData()[index*3+1],
|
inputs->GetSource()->GetSourceData()[index*3+1],
|
||||||
inputs->source->GetSourceData()[index*3+2]);
|
inputs->GetSource()->GetSourceData()[index*3+2]);
|
||||||
|
|
||||||
index = inputs->indices[offset+1];
|
index = inputs->indices[offset+1];
|
||||||
|
|
||||||
SimdVector3 vertex1(
|
SimdVector3 vertex1(
|
||||||
inputs->source->GetSourceData()[index*3],
|
inputs->GetSource()->GetSourceData()[index*3],
|
||||||
inputs->source->GetSourceData()[index*3+1],
|
inputs->GetSource()->GetSourceData()[index*3+1],
|
||||||
inputs->source->GetSourceData()[index*3+2]);
|
inputs->GetSource()->GetSourceData()[index*3+2]);
|
||||||
|
|
||||||
index = inputs->indices[offset+2];
|
index = inputs->indices[offset+2];
|
||||||
|
|
||||||
SimdVector3 vertex2(
|
SimdVector3 vertex2(
|
||||||
inputs->source->GetSourceData()[index*3],
|
inputs->GetSource()->GetSourceData()[index*3],
|
||||||
inputs->source->GetSourceData()[index*3+1],
|
inputs->GetSource()->GetSourceData()[index*3+1],
|
||||||
inputs->source->GetSourceData()[index*3+2]);
|
inputs->GetSource()->GetSourceData()[index*3+2]);
|
||||||
|
|
||||||
index = inputs->indices[offset+3];
|
index = inputs->indices[offset+3];
|
||||||
|
|
||||||
SimdVector3 vertex3(
|
SimdVector3 vertex3(
|
||||||
inputs->source->GetSourceData()[index*3],
|
inputs->GetSource()->GetSourceData()[index*3],
|
||||||
inputs->source->GetSourceData()[index*3+1],
|
inputs->GetSource()->GetSourceData()[index*3+1],
|
||||||
inputs->source->GetSourceData()[index*3+2]);
|
inputs->GetSource()->GetSourceData()[index*3+2]);
|
||||||
|
|
||||||
trimesh->AddTriangle(vertex0,vertex1,vertex2);
|
trimesh->AddTriangle(vertex0,vertex1,vertex2);
|
||||||
trimesh->AddTriangle(vertex0,vertex2,vertex3);
|
trimesh->AddTriangle(vertex0,vertex2,vertex3);
|
||||||
@@ -575,13 +577,13 @@ bool ConvertColladaPhysicsToBulletPhysics(const FCDPhysicsSceneNode* inputNode)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (colladaMesh->m_convex || isDynamic)
|
if (colladaMesh->IsConvex() || isDynamic)
|
||||||
{
|
{
|
||||||
collisionShape = new ConvexTriangleMeshShape(trimesh);
|
collisionShape = new ConvexTriangleMeshShape(trimesh);
|
||||||
} else
|
} else
|
||||||
@@ -615,25 +617,25 @@ bool ConvertColladaPhysicsToBulletPhysics(const FCDPhysicsSceneNode* inputNode)
|
|||||||
|
|
||||||
{
|
{
|
||||||
|
|
||||||
SAFE_DELETE(NewShape);
|
SAFE_DELETE(NewShape);
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
}
|
}
|
||||||
if (mat)
|
if (mat)
|
||||||
{
|
{
|
||||||
NewShape->SetMaterial(mat->GetStaticFriction(), mat->GetDynamicFriction(), mat->GetRestitution());
|
NewShape->SetMaterial(mat->GetStaticFriction(), mat->GetDynamicFriction(), mat->GetRestitution());
|
||||||
//FIXME
|
//FIXME
|
||||||
//NewShape->material->setFrictionCombineMode();
|
//NewShape->material->setFrictionCombineMode();
|
||||||
//NewShape->material->setSpring();
|
//NewShape->material->setSpring();
|
||||||
}
|
}
|
||||||
|
|
||||||
controller->AddShape(NewShape);
|
controller->AddShape(NewShape);
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -915,25 +917,25 @@ int main(int argc,char** argv)
|
|||||||
domAsset::domUp_axis * up = dom->getAsset()->getUp_axis();
|
domAsset::domUp_axis * up = dom->getAsset()->getUp_axis();
|
||||||
switch( up->getValue() )
|
switch( up->getValue() )
|
||||||
{
|
{
|
||||||
case UPAXISTYPE_X_UP:
|
case UPAXISTYPE_X_UP:
|
||||||
printf(" X is Up Data and Hiearchies must be converted!\n" );
|
printf(" X is Up Data and Hiearchies must be converted!\n" );
|
||||||
printf(" Conversion to X axis Up isn't currently supported!\n" );
|
printf(" Conversion to X axis Up isn't currently supported!\n" );
|
||||||
printf(" COLLADA_RT defaulting to Y Up \n" );
|
printf(" COLLADA_RT defaulting to Y Up \n" );
|
||||||
physicsEnvironmentPtr->setGravity(-10,0,0);
|
physicsEnvironmentPtr->setGravity(-10,0,0);
|
||||||
break;
|
break;
|
||||||
case UPAXISTYPE_Y_UP:
|
case UPAXISTYPE_Y_UP:
|
||||||
printf(" Y Axis is Up for this file \n" );
|
printf(" Y Axis is Up for this file \n" );
|
||||||
printf(" COLLADA_RT set to Y Up \n" );
|
printf(" COLLADA_RT set to Y Up \n" );
|
||||||
physicsEnvironmentPtr->setGravity(0,-10,0);
|
physicsEnvironmentPtr->setGravity(0,-10,0);
|
||||||
break;
|
break;
|
||||||
case UPAXISTYPE_Z_UP:
|
case UPAXISTYPE_Z_UP:
|
||||||
printf(" Z Axis is Up for this file \n" );
|
printf(" Z Axis is Up for this file \n" );
|
||||||
printf(" All Geometry and Hiearchies must be converted!\n" );
|
printf(" All Geometry and Hiearchies must be converted!\n" );
|
||||||
physicsEnvironmentPtr->setGravity(0,0,-10);
|
physicsEnvironmentPtr->setGravity(0,0,-10);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1007,6 +1009,9 @@ int main(int argc,char** argv)
|
|||||||
|
|
||||||
}//for all geometry libraries
|
}//for all geometry libraries
|
||||||
|
|
||||||
|
|
||||||
|
//dom->getLibrary_physics_models_array()
|
||||||
|
|
||||||
for ( int i = 0; i < dom->getLibrary_physics_scenes_array().getCount(); i++)
|
for ( int i = 0; i < dom->getLibrary_physics_scenes_array().getCount(); i++)
|
||||||
{
|
{
|
||||||
domLibrary_physics_scenesRef physicsScenesRef = dom->getLibrary_physics_scenes_array()[i];
|
domLibrary_physics_scenesRef physicsScenesRef = dom->getLibrary_physics_scenes_array()[i];
|
||||||
@@ -1016,196 +1021,256 @@ int main(int argc,char** argv)
|
|||||||
|
|
||||||
for (int m=0;m<physicsSceneRef->getInstance_physics_model_array().getCount();m++)
|
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;
|
domPhysics_modelRef model = *(domPhysics_modelRef*)&ref;
|
||||||
|
|
||||||
|
|
||||||
|
for (int r=0;r<instance_physicsModelRef->getInstance_rigid_body_array().getCount();r++)
|
||||||
|
|
||||||
float mass = 1.f;
|
|
||||||
bool isDynamics = true;
|
|
||||||
CollisionShape* colShape = 0;
|
|
||||||
SimdTransform startTransform;
|
|
||||||
startTransform.setIdentity();
|
|
||||||
SimdVector3 startScale(1.f,1.f,1.f);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
for (int r=0;r<model->getRigid_body_array().getCount();r++)
|
|
||||||
|
domInstance_rigid_bodyRef rigidbodyRef = instance_physicsModelRef->getInstance_rigid_body_array()[r];
|
||||||
|
|
||||||
|
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
|
||||||
domRigid_bodyRef physicsModel = model->getRigid_body_array()[r];
|
for (int r=0;r<model->getRigid_body_array().getCount();r++)
|
||||||
|
|
||||||
const domRigid_body::domTechnique_commonRef techniqueRef = physicsModel->getTechnique_common();
|
|
||||||
if (techniqueRef)
|
|
||||||
{
|
{
|
||||||
|
domRigid_bodyRef rigidBodyRef = model->getRigid_body_array()[r];
|
||||||
mass = techniqueRef->getMass()->getValue();
|
if (!strcmp(rigidBodyRef->getName(),bodyName))
|
||||||
isDynamics = techniqueRef->getDynamic()->getValue();
|
|
||||||
|
|
||||||
//shapes
|
|
||||||
for (int s=0;s<techniqueRef->getShape_array().getCount();s++)
|
|
||||||
{
|
{
|
||||||
domRigid_body::domTechnique_common::domShapeRef shapeRef = techniqueRef->getShape_array()[s];
|
|
||||||
|
|
||||||
|
const domRigid_body::domTechnique_commonRef techniqueRef = rigidBodyRef->getTechnique_common();
|
||||||
if (shapeRef->getBox())
|
if (techniqueRef)
|
||||||
{
|
{
|
||||||
domBoxRef boxRef = shapeRef->getBox();
|
|
||||||
domBox::domHalf_extentsRef domHalfExtentsRef = boxRef->getHalf_extents();
|
|
||||||
domFloat3& halfExtents = domHalfExtentsRef->getValue();
|
|
||||||
float x = halfExtents.get(0);
|
|
||||||
float y = halfExtents.get(1);
|
|
||||||
float z = halfExtents.get(2);
|
|
||||||
colShape = new BoxShape(SimdVector3(x,y,z));
|
|
||||||
}
|
|
||||||
if (shapeRef->getSphere())
|
|
||||||
{
|
|
||||||
domSphereRef sphereRef = shapeRef->getSphere();
|
|
||||||
domSphere::domRadiusRef radiusRef = sphereRef->getRadius();
|
|
||||||
domFloat radius = radiusRef->getValue();
|
|
||||||
colShape = new SphereShape(radius);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (shapeRef->getCylinder())
|
if (techniqueRef->getMass())
|
||||||
{
|
|
||||||
domCylinderRef cylinderRef = shapeRef->getCylinder();
|
|
||||||
domFloat height = cylinderRef->getHeight()->getValue();
|
|
||||||
domFloat2 radius2 = cylinderRef->getRadius()->getValue();
|
|
||||||
domFloat radius0 = radius2.get(0);
|
|
||||||
|
|
||||||
//Cylinder around the local Y axis
|
|
||||||
colShape = new CylinderShape(SimdVector3(radius0,height,radius0));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (shapeRef->getInstance_geometry())
|
|
||||||
{
|
|
||||||
const domInstance_geometryRef geomInstRef = shapeRef->getInstance_geometry();
|
|
||||||
daeElement* geomElem = geomInstRef->getUrl().getElement();
|
|
||||||
//elemRef->getTypeName();
|
|
||||||
domGeometry* geom = (domGeometry*) geomElem;
|
|
||||||
if (geom->getMesh())
|
|
||||||
{
|
{
|
||||||
const domMeshRef meshRef = geom->getMesh();
|
mass = techniqueRef->getMass()->getValue();
|
||||||
|
}
|
||||||
printf("(concave) mesh not supported yet\n");
|
if (techniqueRef->getDynamic())
|
||||||
|
{
|
||||||
|
isDynamics = techniqueRef->getDynamic()->getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (geom->getConvex_mesh())
|
//shapes
|
||||||
|
for (int s=0;s<techniqueRef->getShape_array().getCount();s++)
|
||||||
{
|
{
|
||||||
|
domRigid_body::domTechnique_common::domShapeRef shapeRef = techniqueRef->getShape_array()[s];
|
||||||
|
|
||||||
|
|
||||||
|
if (shapeRef->getBox())
|
||||||
{
|
{
|
||||||
const domConvex_meshRef convexRef = geom->getConvex_mesh();
|
domBoxRef boxRef = shapeRef->getBox();
|
||||||
daeElementRef otherElemRef = convexRef->getConvex_hull_of().getElement();
|
domBox::domHalf_extentsRef domHalfExtentsRef = boxRef->getHalf_extents();
|
||||||
if ( otherElemRef != NULL )
|
domFloat3& halfExtents = domHalfExtentsRef->getValue();
|
||||||
{
|
float x = halfExtents.get(0);
|
||||||
domGeometryRef linkedGeom = *(domGeometryRef*)&otherElemRef;
|
float y = halfExtents.get(1);
|
||||||
printf( "otherLinked\n");
|
float z = halfExtents.get(2);
|
||||||
} else
|
colShape = new BoxShape(SimdVector3(x,y,z));
|
||||||
{
|
}
|
||||||
printf("convexMesh polyCount = %i\n",convexRef->getPolygons_array().getCount());
|
if (shapeRef->getSphere())
|
||||||
printf("convexMesh triCount = %i\n",convexRef->getTriangles_array().getCount());
|
{
|
||||||
|
domSphereRef sphereRef = shapeRef->getSphere();
|
||||||
}
|
domSphere::domRadiusRef radiusRef = sphereRef->getRadius();
|
||||||
|
domFloat radius = radiusRef->getValue();
|
||||||
|
colShape = new SphereShape(radius);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (shapeRef->getCylinder())
|
||||||
|
|
||||||
ConvexHullShape* convexHullShape = new ConvexHullShape(0,0);
|
|
||||||
|
|
||||||
//it is quite a trick to get to the vertices, using Collada.
|
|
||||||
//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();
|
|
||||||
|
|
||||||
// Load all the geometry libraries
|
|
||||||
for ( int i = 0; i < dom->getLibrary_geometries_array().getCount(); i++)
|
|
||||||
{
|
{
|
||||||
domLibrary_geometriesRef libgeom = dom->getLibrary_geometries_array()[i];
|
domCylinderRef cylinderRef = shapeRef->getCylinder();
|
||||||
//int index = libgeom->findLastIndexOf(urlref2);
|
domFloat height = cylinderRef->getHeight()->getValue();
|
||||||
//can't find it
|
domFloat2 radius2 = cylinderRef->getRadius()->getValue();
|
||||||
|
domFloat radius0 = radius2.get(0);
|
||||||
|
|
||||||
for ( int i = 0; i < libgeom->getGeometry_array().getCount(); i++)
|
//Cylinder around the local Y axis
|
||||||
|
colShape = new CylinderShape(SimdVector3(radius0,height,radius0));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shapeRef->getInstance_geometry())
|
||||||
|
{
|
||||||
|
const domInstance_geometryRef geomInstRef = shapeRef->getInstance_geometry();
|
||||||
|
daeElement* geomElem = geomInstRef->getUrl().getElement();
|
||||||
|
//elemRef->getTypeName();
|
||||||
|
domGeometry* geom = (domGeometry*) geomElem;
|
||||||
|
if (geom->getMesh())
|
||||||
{
|
{
|
||||||
//ReadGeometry( );
|
const domMeshRef meshRef = geom->getMesh();
|
||||||
domGeometryRef lib = libgeom->getGeometry_array()[i];
|
TriangleIndexVertexArray* tindexArray = new TriangleIndexVertexArray();
|
||||||
if (!strcmp(lib->getName(),urlref2))
|
|
||||||
|
for (int tg = 0;tg<meshRef->getTriangles_array().getCount();tg++)
|
||||||
{
|
{
|
||||||
//found convex_hull geometry
|
domTrianglesRef triRef = meshRef->getTriangles_array()[tg];
|
||||||
domMesh *meshElement = lib->getMesh();
|
const domPRef pRef = triRef->getP();
|
||||||
if (meshElement)
|
daeMemoryRef memRef = pRef->getValue().getRawData();
|
||||||
|
IndexedMesh meshPart;
|
||||||
|
meshPart.m_triangleIndexStride=0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
for (int w=0;w<triRef->getInput_array().getCount();w++)
|
||||||
{
|
{
|
||||||
const domVerticesRef vertsRef = meshElement->getVertices();
|
int offset = triRef->getInput_array()[w]->getOffset();
|
||||||
int numInputs = vertsRef->getInput_array().getCount();
|
if (offset > meshPart.m_triangleIndexStride)
|
||||||
for (int i=0;i<numInputs;i++)
|
|
||||||
{
|
{
|
||||||
domInputLocalRef localRef = vertsRef->getInput_array()[i];
|
meshPart.m_triangleIndexStride = offset;
|
||||||
daeString str = localRef->getSemantic();
|
|
||||||
if ( !strcmp(str,"POSITION"))
|
|
||||||
{
|
|
||||||
const domURIFragmentType& frag = localRef->getSource();
|
|
||||||
|
|
||||||
daeElementConstRef constElem = frag.getElement();
|
|
||||||
|
|
||||||
const domSourceRef node = *(const domSourceRef*)&constElem;
|
|
||||||
const domFloat_arrayRef flArray = node->getFloat_array();
|
|
||||||
if (flArray)
|
|
||||||
{
|
|
||||||
int numElem = flArray->getCount();
|
|
||||||
const domListOfFloats& listFloats = flArray->getValue();
|
|
||||||
|
|
||||||
for (int k=0;k+2<numElem;k+=3)
|
|
||||||
{
|
|
||||||
domFloat fl0 = listFloats.get(k);
|
|
||||||
domFloat fl1 = listFloats.get(k+1);
|
|
||||||
domFloat fl2 = listFloats.get(k+2);
|
|
||||||
//printf("float %f %f %f\n",fl0,fl1,fl2);
|
|
||||||
|
|
||||||
convexHullShape->AddPoint(SimdPoint3(fl0,fl1,fl2));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (geom->getConvex_mesh())
|
||||||
|
{
|
||||||
|
|
||||||
|
{
|
||||||
|
const domConvex_meshRef convexRef = geom->getConvex_mesh();
|
||||||
|
daeElementRef otherElemRef = convexRef->getConvex_hull_of().getElement();
|
||||||
|
if ( otherElemRef != NULL )
|
||||||
|
{
|
||||||
|
domGeometryRef linkedGeom = *(domGeometryRef*)&otherElemRef;
|
||||||
|
printf( "otherLinked\n");
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
printf("convexMesh polyCount = %i\n",convexRef->getPolygons_array().getCount());
|
||||||
|
printf("convexMesh triCount = %i\n",convexRef->getTriangles_array().getCount());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ConvexHullShape* convexHullShape = new ConvexHullShape(0,0);
|
||||||
|
|
||||||
|
//it is quite a trick to get to the vertices, using Collada.
|
||||||
|
//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();
|
||||||
|
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++)
|
||||||
|
{
|
||||||
|
domLibrary_geometriesRef libgeom = dom->getLibrary_geometries_array()[i];
|
||||||
|
//int index = libgeom->findLastIndexOf(urlref2);
|
||||||
|
//can't find it
|
||||||
|
|
||||||
|
for ( int i = 0; i < libgeom->getGeometry_array().getCount(); i++)
|
||||||
|
{
|
||||||
|
//ReadGeometry( );
|
||||||
|
domGeometryRef lib = libgeom->getGeometry_array()[i];
|
||||||
|
if (!strcmp(lib->getName(),urlref2))
|
||||||
|
{*/
|
||||||
|
//found convex_hull geometry
|
||||||
|
domMesh *meshElement = linkedGeom->getMesh();
|
||||||
|
if (meshElement)
|
||||||
|
{
|
||||||
|
const domVerticesRef vertsRef = meshElement->getVertices();
|
||||||
|
int numInputs = vertsRef->getInput_array().getCount();
|
||||||
|
for (int i=0;i<numInputs;i++)
|
||||||
|
{
|
||||||
|
domInputLocalRef localRef = vertsRef->getInput_array()[i];
|
||||||
|
daeString str = localRef->getSemantic();
|
||||||
|
if ( !strcmp(str,"POSITION"))
|
||||||
|
{
|
||||||
|
const domURIFragmentType& frag = localRef->getSource();
|
||||||
|
|
||||||
|
daeElementConstRef constElem = frag.getElement();
|
||||||
|
|
||||||
|
const domSourceRef node = *(const domSourceRef*)&constElem;
|
||||||
|
const domFloat_arrayRef flArray = node->getFloat_array();
|
||||||
|
if (flArray)
|
||||||
|
{
|
||||||
|
int numElem = flArray->getCount();
|
||||||
|
const domListOfFloats& listFloats = flArray->getValue();
|
||||||
|
|
||||||
|
for (int k=0;k+2<numElem;k+=3)
|
||||||
|
{
|
||||||
|
domFloat fl0 = listFloats.get(k);
|
||||||
|
domFloat fl1 = listFloats.get(k+1);
|
||||||
|
domFloat fl2 = listFloats.get(k+2);
|
||||||
|
//printf("float %f %f %f\n",fl0,fl1,fl2);
|
||||||
|
|
||||||
|
convexHullShape->AddPoint(SimdPoint3(fl0,fl1,fl2));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (convexHullShape->GetNumVertices())
|
||||||
|
{
|
||||||
|
colShape = convexHullShape;
|
||||||
|
printf("created convexHullShape with %i points\n",convexHullShape->GetNumVertices());
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
delete convexHullShape;
|
||||||
|
printf("failed to create convexHullShape\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//domGeometryRef linkedGeom = *(domGeometryRef*)&otherElemRef;
|
||||||
|
|
||||||
|
printf("convexmesh\n");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (convexHullShape->GetNumVertices())
|
|
||||||
{
|
|
||||||
colShape = convexHullShape;
|
|
||||||
printf("created convexHullShape with %i points\n",convexHullShape->GetNumVertices());
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
delete convexHullShape;
|
|
||||||
printf("failed to create convexHullShape\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//domGeometryRef linkedGeom = *(domGeometryRef*)&otherElemRef;
|
|
||||||
|
|
||||||
printf("convexmesh\n");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1215,21 +1280,13 @@ int main(int argc,char** argv)
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//////////////////////
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
for (int r=0;r<modelRef->getInstance_rigid_body_array().getCount();r++)
|
//The 'target' points to a graphics element/node, which contains the start (world) transform
|
||||||
{
|
|
||||||
|
|
||||||
domInstance_rigid_bodyRef rigidbodyRef = modelRef->getInstance_rigid_body_array()[r];
|
|
||||||
domInstance_rigid_body::domTechnique_commonRef techniqueRef = rigidbodyRef->getTechnique_common();
|
|
||||||
daeElementRef elem = rigidbodyRef->getTarget().getElement();
|
daeElementRef elem = rigidbodyRef->getTarget().getElement();
|
||||||
if (elem)
|
if (elem)
|
||||||
{
|
{
|
||||||
@@ -1263,38 +1320,39 @@ int main(int argc,char** argv)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
domInstance_rigid_body::domTechnique_commonRef techniqueRef = rigidbodyRef->getTechnique_common();
|
||||||
if (techniqueRef)
|
if (techniqueRef)
|
||||||
{
|
{
|
||||||
mass = techniqueRef->getMass()->getValue();
|
if (techniqueRef->getMass())
|
||||||
isDynamics = techniqueRef->getDynamic()->getValue();
|
{
|
||||||
|
mass = techniqueRef->getMass()->getValue();
|
||||||
|
}
|
||||||
|
if (techniqueRef->getDynamic())
|
||||||
|
{
|
||||||
|
isDynamics = techniqueRef->getDynamic()->getValue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
printf("mass = %f, isDynamics %i\n",mass,isDynamics);
|
||||||
|
if (colShape)
|
||||||
|
{
|
||||||
|
CreatePhysicsObject(isDynamics,mass,startTransform,colShape);
|
||||||
|
|
||||||
printf("mass = %f, isDynamics %i\n",mass,isDynamics);
|
}
|
||||||
if (colShape)
|
|
||||||
{
|
|
||||||
CreatePhysicsObject(isDynamics,mass,startTransform,colShape);
|
|
||||||
|
|
||||||
}
|
} //for each instance_rigid_body
|
||||||
|
|
||||||
|
|
||||||
//we don't handle constraints just yet
|
//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
|
#endif
|
||||||
@@ -1841,3 +1899,4 @@ void clientMotionFunc(int x,int y)
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user