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/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,44 +356,44 @@ 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();
|
||||
|
||||
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());
|
||||
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)
|
||||
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];
|
||||
|
||||
int offset = poly->GetFaceVertexOffset(p);
|
||||
int index;
|
||||
index = inputs->indices[offset];
|
||||
int offset = poly->GetFaceVertexOffset(p);
|
||||
int index;
|
||||
index = inputs->indices[offset];
|
||||
|
||||
SimdVector3 vertex0(
|
||||
inputs->source->GetSourceData()[index*3],
|
||||
inputs->source->GetSourceData()[index*3+1],
|
||||
inputs->source->GetSourceData()[index*3+2]);
|
||||
SimdVector3 vertex0(
|
||||
inputs->GetSource()->GetSourceData()[index*3],
|
||||
inputs->GetSource()->GetSourceData()[index*3+1],
|
||||
inputs->GetSource()->GetSourceData()[index*3+2]);
|
||||
|
||||
index = inputs->indices[offset+1];
|
||||
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];
|
||||
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);
|
||||
break;
|
||||
break;
|
||||
}
|
||||
|
||||
case 4:
|
||||
{
|
||||
int offset = poly->GetFaceVertexOffset(p);
|
||||
int index;
|
||||
index = inputs->indices[offset];
|
||||
int offset = poly->GetFaceVertexOffset(p);
|
||||
int index;
|
||||
index = inputs->indices[offset];
|
||||
|
||||
SimdVector3 vertex0(
|
||||
inputs->source->GetSourceData()[index*3],
|
||||
inputs->source->GetSourceData()[index*3+1],
|
||||
inputs->source->GetSourceData()[index*3+2]);
|
||||
SimdVector3 vertex0(
|
||||
inputs->GetSource()->GetSourceData()[index*3],
|
||||
inputs->GetSource()->GetSourceData()[index*3+1],
|
||||
inputs->GetSource()->GetSourceData()[index*3+2]);
|
||||
|
||||
index = inputs->indices[offset+1];
|
||||
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];
|
||||
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);
|
||||
@@ -575,13 +577,13 @@ bool ConvertColladaPhysicsToBulletPhysics(const FCDPhysicsSceneNode* inputNode)
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
}
|
||||
default:
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (colladaMesh->m_convex || isDynamic)
|
||||
if (colladaMesh->IsConvex() || isDynamic)
|
||||
{
|
||||
collisionShape = new ConvexTriangleMeshShape(trimesh);
|
||||
} else
|
||||
@@ -615,25 +617,25 @@ bool ConvertColladaPhysicsToBulletPhysics(const FCDPhysicsSceneNode* inputNode)
|
||||
|
||||
{
|
||||
|
||||
SAFE_DELETE(NewShape);
|
||||
SAFE_DELETE(NewShape);
|
||||
|
||||
continue;
|
||||
continue;
|
||||
|
||||
}
|
||||
if (mat)
|
||||
{
|
||||
NewShape->SetMaterial(mat->GetStaticFriction(), mat->GetDynamicFriction(), mat->GetRestitution());
|
||||
//FIXME
|
||||
//NewShape->material->setFrictionCombineMode();
|
||||
//NewShape->material->setSpring();
|
||||
NewShape->SetMaterial(mat->GetStaticFriction(), mat->GetDynamicFriction(), mat->GetRestitution());
|
||||
//FIXME
|
||||
//NewShape->material->setFrictionCombineMode();
|
||||
//NewShape->material->setSpring();
|
||||
}
|
||||
|
||||
controller->AddShape(NewShape);
|
||||
|
||||
*/
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -915,25 +917,25 @@ int main(int argc,char** argv)
|
||||
domAsset::domUp_axis * up = dom->getAsset()->getUp_axis();
|
||||
switch( up->getValue() )
|
||||
{
|
||||
case UPAXISTYPE_X_UP:
|
||||
printf(" X is Up Data and Hiearchies must be converted!\n" );
|
||||
printf(" Conversion to X axis Up isn't currently supported!\n" );
|
||||
printf(" COLLADA_RT defaulting to Y Up \n" );
|
||||
physicsEnvironmentPtr->setGravity(-10,0,0);
|
||||
break;
|
||||
case UPAXISTYPE_Y_UP:
|
||||
printf(" Y Axis is Up for this file \n" );
|
||||
printf(" COLLADA_RT set to Y Up \n" );
|
||||
physicsEnvironmentPtr->setGravity(0,-10,0);
|
||||
break;
|
||||
case UPAXISTYPE_Z_UP:
|
||||
printf(" Z Axis is Up for this file \n" );
|
||||
printf(" All Geometry and Hiearchies must be converted!\n" );
|
||||
physicsEnvironmentPtr->setGravity(0,0,-10);
|
||||
break;
|
||||
default:
|
||||
case UPAXISTYPE_X_UP:
|
||||
printf(" X is Up Data and Hiearchies must be converted!\n" );
|
||||
printf(" Conversion to X axis Up isn't currently supported!\n" );
|
||||
printf(" COLLADA_RT defaulting to Y Up \n" );
|
||||
physicsEnvironmentPtr->setGravity(-10,0,0);
|
||||
break;
|
||||
case UPAXISTYPE_Y_UP:
|
||||
printf(" Y Axis is Up for this file \n" );
|
||||
printf(" COLLADA_RT set to Y Up \n" );
|
||||
physicsEnvironmentPtr->setGravity(0,-10,0);
|
||||
break;
|
||||
case UPAXISTYPE_Z_UP:
|
||||
printf(" Z Axis is Up for this file \n" );
|
||||
printf(" All Geometry and Hiearchies must be converted!\n" );
|
||||
physicsEnvironmentPtr->setGravity(0,0,-10);
|
||||
break;
|
||||
default:
|
||||
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,196 +1021,256 @@ 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;
|
||||
|
||||
|
||||
|
||||
|
||||
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<instance_physicsModelRef->getInstance_rigid_body_array().getCount();r++)
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
||||
domRigid_bodyRef physicsModel = model->getRigid_body_array()[r];
|
||||
|
||||
const domRigid_body::domTechnique_commonRef techniqueRef = physicsModel->getTechnique_common();
|
||||
if (techniqueRef)
|
||||
//try to find the rigid body
|
||||
for (int r=0;r<model->getRigid_body_array().getCount();r++)
|
||||
{
|
||||
|
||||
mass = techniqueRef->getMass()->getValue();
|
||||
isDynamics = techniqueRef->getDynamic()->getValue();
|
||||
|
||||
//shapes
|
||||
for (int s=0;s<techniqueRef->getShape_array().getCount();s++)
|
||||
domRigid_bodyRef rigidBodyRef = model->getRigid_body_array()[r];
|
||||
if (!strcmp(rigidBodyRef->getName(),bodyName))
|
||||
{
|
||||
domRigid_body::domTechnique_common::domShapeRef shapeRef = techniqueRef->getShape_array()[s];
|
||||
|
||||
|
||||
if (shapeRef->getBox())
|
||||
const domRigid_body::domTechnique_commonRef techniqueRef = rigidBodyRef->getTechnique_common();
|
||||
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())
|
||||
{
|
||||
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())
|
||||
if (techniqueRef->getMass())
|
||||
{
|
||||
const domMeshRef meshRef = geom->getMesh();
|
||||
|
||||
printf("(concave) mesh not supported yet\n");
|
||||
mass = techniqueRef->getMass()->getValue();
|
||||
}
|
||||
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();
|
||||
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());
|
||||
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
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++)
|
||||
if (shapeRef->getCylinder())
|
||||
{
|
||||
domLibrary_geometriesRef libgeom = dom->getLibrary_geometries_array()[i];
|
||||
//int index = libgeom->findLastIndexOf(urlref2);
|
||||
//can't find it
|
||||
domCylinderRef cylinderRef = shapeRef->getCylinder();
|
||||
domFloat height = cylinderRef->getHeight()->getValue();
|
||||
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( );
|
||||
domGeometryRef lib = libgeom->getGeometry_array()[i];
|
||||
if (!strcmp(lib->getName(),urlref2))
|
||||
const domMeshRef meshRef = geom->getMesh();
|
||||
TriangleIndexVertexArray* tindexArray = new TriangleIndexVertexArray();
|
||||
|
||||
for (int tg = 0;tg<meshRef->getTriangles_array().getCount();tg++)
|
||||
{
|
||||
//found convex_hull geometry
|
||||
domMesh *meshElement = lib->getMesh();
|
||||
if (meshElement)
|
||||
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++)
|
||||
{
|
||||
const domVerticesRef vertsRef = meshElement->getVertices();
|
||||
int numInputs = vertsRef->getInput_array().getCount();
|
||||
for (int i=0;i<numInputs;i++)
|
||||
int offset = triRef->getInput_array()[w]->getOffset();
|
||||
if (offset > meshPart.m_triangleIndexStride)
|
||||
{
|
||||
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));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
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++)
|
||||
{
|
||||
|
||||
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,38 +1320,39 @@ int main(int argc,char** argv)
|
||||
|
||||
}
|
||||
|
||||
|
||||
domInstance_rigid_body::domTechnique_commonRef techniqueRef = rigidbodyRef->getTechnique_common();
|
||||
if (techniqueRef)
|
||||
{
|
||||
mass = techniqueRef->getMass()->getValue();
|
||||
isDynamics = techniqueRef->getDynamic()->getValue();
|
||||
if (techniqueRef->getMass())
|
||||
{
|
||||
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
|
||||
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)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user