Provide verbosity control in BulletColladaConverter, see Issue 228
Thanks SkewMatrix for the patch Fix a crash in BulletColladaConverter, when bodies were created outside of the Collada converter, Thanks Jan Ciger for the patch, see Issue 306
This commit is contained in:
@@ -169,7 +169,8 @@ m_dom(0),
|
|||||||
m_filename(0),
|
m_filename(0),
|
||||||
m_unitMeterScaling(1.f),
|
m_unitMeterScaling(1.f),
|
||||||
m_use32bitIndices(true),
|
m_use32bitIndices(true),
|
||||||
m_use4componentVertices(true)
|
m_use4componentVertices(true),
|
||||||
|
m_verbosity(LOUD)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -331,22 +332,31 @@ bool ColladaConverter::convert()
|
|||||||
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" );
|
if( getVerbosity() > SILENT )
|
||||||
printf(" Conversion to X axis Up isn't currently supported!\n" );
|
{
|
||||||
printf(" COLLADA_RT defaulting to Y Up \n" );
|
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" );
|
||||||
|
}
|
||||||
setGravity(btVector3(-10,0,0));
|
setGravity(btVector3(-10,0,0));
|
||||||
setCameraInfo(btVector3(1,0,0),1);
|
setCameraInfo(btVector3(1,0,0),1);
|
||||||
break;
|
break;
|
||||||
case UPAXISTYPE_Y_UP:
|
case UPAXISTYPE_Y_UP:
|
||||||
printf(" Y Axis is Up for this file \n" );
|
if( getVerbosity() > SILENT )
|
||||||
printf(" COLLADA_RT set to Y Up \n" );
|
{
|
||||||
|
printf(" Y Axis is Up for this file \n" );
|
||||||
|
printf(" COLLADA_RT set to Y Up \n" );
|
||||||
|
}
|
||||||
setGravity(btVector3(0,-10,0));
|
setGravity(btVector3(0,-10,0));
|
||||||
setCameraInfo(btVector3(0,1,0),0);
|
setCameraInfo(btVector3(0,1,0),0);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case UPAXISTYPE_Z_UP:
|
case UPAXISTYPE_Z_UP:
|
||||||
printf(" Z Axis is Up for this file \n" );
|
if( getVerbosity() > SILENT )
|
||||||
printf(" All Geometry and Hiearchies must be converted!\n" );
|
{
|
||||||
|
printf(" Z Axis is Up for this file \n" );
|
||||||
|
printf(" All Geometry and Hiearchies must be converted!\n" );
|
||||||
|
}
|
||||||
setGravity(btVector3(0,0,-10));
|
setGravity(btVector3(0,0,-10));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -382,7 +392,8 @@ bool ColladaConverter::convert()
|
|||||||
{
|
{
|
||||||
domLibrary_geometriesRef libgeom = m_dom->getLibrary_geometries_array()[i];
|
domLibrary_geometriesRef libgeom = m_dom->getLibrary_geometries_array()[i];
|
||||||
|
|
||||||
printf(" CrtScene::Reading Geometry Library \n" );
|
if( getVerbosity() > SILENT )
|
||||||
|
printf(" CrtScene::Reading Geometry Library \n" );
|
||||||
for ( unsigned int i = 0; i < libgeom->getGeometry_array().getCount(); i++)
|
for ( unsigned int i = 0; i < libgeom->getGeometry_array().getCount(); i++)
|
||||||
{
|
{
|
||||||
//ReadGeometry( );
|
//ReadGeometry( );
|
||||||
@@ -396,32 +407,39 @@ bool ColladaConverter::convert()
|
|||||||
int numPolygonGroups = (int)meshElement->getPolygons_array().getCount();
|
int numPolygonGroups = (int)meshElement->getPolygons_array().getCount();
|
||||||
int numPolyList = (int)meshElement->getPolylist_array().getCount();
|
int numPolyList = (int)meshElement->getPolylist_array().getCount();
|
||||||
int totalGroups = numTriangleGroups + numPolygonGroups + numPolyList;
|
int totalGroups = numTriangleGroups + numPolygonGroups + numPolyList;
|
||||||
if (totalGroups == 0)
|
if( getVerbosity() > NORMAL )
|
||||||
{
|
{
|
||||||
printf("No Triangles or Polygons found int Geometry %s \n", lib->getId() );
|
if (totalGroups == 0)
|
||||||
} else
|
{
|
||||||
{
|
printf("No Triangles or Polygons found int Geometry %s \n", lib->getId() );
|
||||||
printf("Found mesh geometry (%s): numTriangleGroups:%i numPolygonGroups :%i numPolyList=%i\n",lib->getId(),numTriangleGroups,numPolygonGroups,numPolyList);
|
} else
|
||||||
}
|
{
|
||||||
|
printf("Found mesh geometry (%s): numTriangleGroups:%i numPolygonGroups :%i numPolyList=%i\n",lib->getId(),numTriangleGroups,numPolygonGroups,numPolyList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
domConvex_mesh *convexMeshElement = lib->getConvex_mesh();
|
domConvex_mesh *convexMeshElement = lib->getConvex_mesh();
|
||||||
if (convexMeshElement)
|
if (convexMeshElement)
|
||||||
{
|
{
|
||||||
printf("found convexmesh element\n");
|
if( getVerbosity() > NORMAL )
|
||||||
|
printf("found convexmesh element\n");
|
||||||
// Find out how many groups we need to allocate space for
|
// Find out how many groups we need to allocate space for
|
||||||
int numTriangleGroups = (int)convexMeshElement->getTriangles_array().getCount();
|
int numTriangleGroups = (int)convexMeshElement->getTriangles_array().getCount();
|
||||||
int numPolygonGroups = (int)convexMeshElement->getPolygons_array().getCount();
|
int numPolygonGroups = (int)convexMeshElement->getPolygons_array().getCount();
|
||||||
|
|
||||||
int totalGroups = numTriangleGroups + numPolygonGroups;
|
int totalGroups = numTriangleGroups + numPolygonGroups;
|
||||||
if (totalGroups == 0)
|
if( getVerbosity() > NORMAL )
|
||||||
{
|
{
|
||||||
printf("No Triangles or Polygons found in ConvexMesh Geometry %s \n", lib->getId() );
|
if (totalGroups == 0)
|
||||||
}else
|
{
|
||||||
{
|
printf("No Triangles or Polygons found in ConvexMesh Geometry %s \n", lib->getId() );
|
||||||
printf("Found convexmesh geometry: numTriangleGroups:%i numPolygonGroups:%i\n",numTriangleGroups,numPolygonGroups);
|
}else
|
||||||
}
|
{
|
||||||
|
printf("Found convexmesh geometry: numTriangleGroups:%i numPolygonGroups:%i\n",numTriangleGroups,numPolygonGroups);
|
||||||
|
}
|
||||||
|
}
|
||||||
}//fi
|
}//fi
|
||||||
}//for each geometry
|
}//for each geometry
|
||||||
|
|
||||||
@@ -442,7 +460,8 @@ bool ColladaConverter::convert()
|
|||||||
if (physicsSceneRef->getTechnique_common()->getGravity())
|
if (physicsSceneRef->getTechnique_common()->getGravity())
|
||||||
{
|
{
|
||||||
const domFloat3 grav = physicsSceneRef->getTechnique_common()->getGravity()->getValue();
|
const domFloat3 grav = physicsSceneRef->getTechnique_common()->getGravity()->getValue();
|
||||||
printf("gravity set to %f,%f,%f\n",grav.get(0),grav.get(1),grav.get(2));
|
if( getVerbosity() > SILENT )
|
||||||
|
printf("gravity set to %f,%f,%f\n",grav.get(0),grav.get(1),grav.get(2));
|
||||||
|
|
||||||
setGravity(btVector3(grav.get(0),grav.get(1),grav.get(2)));
|
setGravity(btVector3(grav.get(0),grav.get(1),grav.get(2)));
|
||||||
}
|
}
|
||||||
@@ -510,7 +529,8 @@ bool ColladaConverter::convert()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("mass = %f, isDynamics %i\n",mass,isDynamics);
|
if( getVerbosity() > SILENT )
|
||||||
|
printf("mass = %f, isDynamics %i\n",mass,isDynamics);
|
||||||
|
|
||||||
if (bodyName && model)
|
if (bodyName && model)
|
||||||
{
|
{
|
||||||
@@ -603,7 +623,8 @@ bool ColladaConverter::convert()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("mass = %f, isDynamics %i\n",mass,isDynamics);
|
if( getVerbosity() > SILENT )
|
||||||
|
printf("mass = %f, isDynamics %i\n",mass,isDynamics);
|
||||||
|
|
||||||
domRigid_bodyRef savedRbRef = NULL;
|
domRigid_bodyRef savedRbRef = NULL;
|
||||||
if (bodyName && model)
|
if (bodyName && model)
|
||||||
@@ -628,7 +649,8 @@ bool ColladaConverter::convert()
|
|||||||
savedRbRef = rigidBodyRef;
|
savedRbRef = rigidBodyRef;
|
||||||
rbInput.m_instanceRigidBodyRef = instRigidbodyRef;
|
rbInput.m_instanceRigidBodyRef = instRigidbodyRef;
|
||||||
ConvertRigidBodyRef( rbInput , output );
|
ConvertRigidBodyRef( rbInput , output );
|
||||||
printf("Found body converting %s\n", bodyName);
|
if( getVerbosity() > SILENT )
|
||||||
|
printf("Found body converting %s\n", bodyName);
|
||||||
|
|
||||||
mass = output.m_mass;
|
mass = output.m_mass;
|
||||||
isDynamics = output.m_isDynamics;
|
isDynamics = output.m_isDynamics;
|
||||||
@@ -1006,7 +1028,15 @@ void ColladaConverter::prepareConstraints(ConstraintInput& input)
|
|||||||
{
|
{
|
||||||
btRigidBody* body = getRigidBody (i);
|
btRigidBody* body = getRigidBody (i);
|
||||||
domRigid_body* domRigidBody = findRigid_body(body);
|
domRigid_body* domRigidBody = findRigid_body(body);
|
||||||
btAssert(domRigidBody);
|
|
||||||
|
/*
|
||||||
|
* JC patch. Skip the rigid body if it doesn't have any DOM
|
||||||
|
* node associated - e.g. because it was created directly, without
|
||||||
|
* the COLLADA file.
|
||||||
|
*/
|
||||||
|
if(!domRigidBody)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
|
||||||
const char* name = domRigidBody->getSid();
|
const char* name = domRigidBody->getSid();
|
||||||
if (name)
|
if (name)
|
||||||
@@ -1265,7 +1295,8 @@ domLibrary_physics_materials* ColladaConverter::getDefaultMaterialsLib ()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf("No library physics materials. Creating one\n");
|
if( getVerbosity() > SILENT )
|
||||||
|
printf("No library physics materials. Creating one\n");
|
||||||
materialsLib = daeSafeCast<domLibrary_physics_materials> (m_dom->createAndPlace (COLLADA_ELEMENT_LIBRARY_PHYSICS_MATERIALS));
|
materialsLib = daeSafeCast<domLibrary_physics_materials> (m_dom->createAndPlace (COLLADA_ELEMENT_LIBRARY_PHYSICS_MATERIALS));
|
||||||
materialsLib->setName("Bullet-PhysicsMaterials");
|
materialsLib->setName("Bullet-PhysicsMaterials");
|
||||||
return materialsLib;
|
return materialsLib;
|
||||||
@@ -1293,14 +1324,16 @@ domPhysics_model* ColladaConverter::getDefaultPhysicsModel ()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
printf("No library physics model. Creating one\n");
|
if( getVerbosity() > SILENT )
|
||||||
|
printf("No library physics model. Creating one\n");
|
||||||
modelsLib = daeSafeCast<domLibrary_physics_models> (m_dom->createAndPlace (COLLADA_ELEMENT_LIBRARY_PHYSICS_MODELS ));
|
modelsLib = daeSafeCast<domLibrary_physics_models> (m_dom->createAndPlace (COLLADA_ELEMENT_LIBRARY_PHYSICS_MODELS ));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Always create in first physics models library */
|
/* Always create in first physics models library */
|
||||||
modelsLib = m_dom->getLibrary_physics_models_array()[0];
|
modelsLib = m_dom->getLibrary_physics_models_array()[0];
|
||||||
|
|
||||||
printf("Could not find physics model. Creating one\n");
|
if( getVerbosity() > SILENT )
|
||||||
|
printf("Could not find physics model. Creating one\n");
|
||||||
|
|
||||||
domPhysics_model* physicsModel = daeSafeCast<domPhysics_model>(modelsLib->createAndPlace (COLLADA_ELEMENT_PHYSICS_MODEL));
|
domPhysics_model* physicsModel = daeSafeCast<domPhysics_model>(modelsLib->createAndPlace (COLLADA_ELEMENT_PHYSICS_MODEL));
|
||||||
|
|
||||||
@@ -1324,7 +1357,8 @@ domInstance_physics_model* ColladaConverter::getDefaultInstancePhysicsModel ()
|
|||||||
return physicsModelInstance;
|
return physicsModelInstance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf("Creating Bullet-PhysicsModel instance\n");
|
if( getVerbosity() > SILENT )
|
||||||
|
printf("Creating Bullet-PhysicsModel instance\n");
|
||||||
domInstance_physics_model* physicsModelInstance = daeSafeCast<domInstance_physics_model>(physicsScene->createAndPlace (COLLADA_ELEMENT_INSTANCE_PHYSICS_MODEL));
|
domInstance_physics_model* physicsModelInstance = daeSafeCast<domInstance_physics_model>(physicsScene->createAndPlace (COLLADA_ELEMENT_INSTANCE_PHYSICS_MODEL));
|
||||||
physicsModelInstance->setUrl ("#Bullet-PhysicsModel");
|
physicsModelInstance->setUrl ("#Bullet-PhysicsModel");
|
||||||
return physicsModelInstance;
|
return physicsModelInstance;
|
||||||
@@ -1604,7 +1638,8 @@ void ColladaConverter::addConcaveMeshInternal(btStridingMeshInterface* meshInter
|
|||||||
geo->setId( nodeName );
|
geo->setId( nodeName );
|
||||||
geo->setName ( nodeName);
|
geo->setName ( nodeName);
|
||||||
|
|
||||||
printf("numSubParts = \n",meshInterface->getNumSubParts ());
|
if( getVerbosity() > NORMAL )
|
||||||
|
printf("numSubParts = \n",meshInterface->getNumSubParts ());
|
||||||
|
|
||||||
for (int i = 0; i < meshInterface->getNumSubParts (); i++)
|
for (int i = 0; i < meshInterface->getNumSubParts (); i++)
|
||||||
{
|
{
|
||||||
@@ -1628,10 +1663,12 @@ void ColladaConverter::addConcaveMeshInternal(btStridingMeshInterface* meshInter
|
|||||||
|
|
||||||
meshInterface->getLockedReadOnlyVertexIndexBase (&vertexBase, numVerts, vertexType, vertexStride, &indexBase, indexStride, numFaces, indexType, i);
|
meshInterface->getLockedReadOnlyVertexIndexBase (&vertexBase, numVerts, vertexType, vertexStride, &indexBase, indexStride, numFaces, indexType, i);
|
||||||
|
|
||||||
printf("meshInterface subpart[%d].numVerts = %d\n",i,numVerts);
|
if( getVerbosity() > NORMAL )
|
||||||
printf("meshInterface subpart[%d].numFaces = %d\n",i,numFaces);
|
{
|
||||||
printf("meshInterface subpart[%d].indexType= %d\n",i,indexType);
|
printf("meshInterface subpart[%d].numVerts = %d\n",i,numVerts);
|
||||||
|
printf("meshInterface subpart[%d].numFaces = %d\n",i,numFaces);
|
||||||
|
printf("meshInterface subpart[%d].indexType= %d\n",i,indexType);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
btAssert (vertexBase);
|
btAssert (vertexBase);
|
||||||
@@ -2521,7 +2558,8 @@ void ColladaConverter::syncOrAddRigidBody (btRigidBody* body)
|
|||||||
domRigid_body* dRigidBody=NULL;
|
domRigid_body* dRigidBody=NULL;
|
||||||
domInstance_rigid_body* dInstanceRigidBody=NULL;
|
domInstance_rigid_body* dInstanceRigidBody=NULL;
|
||||||
|
|
||||||
printf("New body\n");
|
if( getVerbosity() > SILENT )
|
||||||
|
printf("New body\n");
|
||||||
btCollisionShape* shape = body->getCollisionShape ();
|
btCollisionShape* shape = body->getCollisionShape ();
|
||||||
|
|
||||||
if (!nodeName)
|
if (!nodeName)
|
||||||
@@ -2541,7 +2579,8 @@ void ColladaConverter::syncOrAddRigidBody (btRigidBody* body)
|
|||||||
shapeName = &shapeNameGen[0];
|
shapeName = &shapeNameGen[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Adding %s to COLLADA DOM.\n", nodeName);
|
if( getVerbosity() > SILENT )
|
||||||
|
printf("Adding %s to COLLADA DOM.\n", nodeName);
|
||||||
|
|
||||||
|
|
||||||
switch (shape->getShapeType())
|
switch (shape->getShapeType())
|
||||||
@@ -3199,12 +3238,14 @@ void ColladaConverter::ConvertRigidBodyRef( btRigidBodyInput& rbInput,btRigidBod
|
|||||||
|
|
||||||
if (rbOutput.m_isDynamics)
|
if (rbOutput.m_isDynamics)
|
||||||
{
|
{
|
||||||
printf("moving concave <mesh> added\n");
|
if( getVerbosity() > NORMAL )
|
||||||
|
printf("moving concave <mesh> added\n");
|
||||||
//rbOutput.m_colShape = createConvexTriangleMeshShape(trimesh);
|
//rbOutput.m_colShape = createConvexTriangleMeshShape(trimesh);
|
||||||
rbOutput.m_colShape = createGimpactShape(trimesh);
|
rbOutput.m_colShape = createGimpactShape(trimesh);
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
printf("static concave triangle <mesh> added\n");
|
if( getVerbosity() > NORMAL )
|
||||||
|
printf("static concave triangle <mesh> added\n");
|
||||||
|
|
||||||
rbOutput.m_colShape = createBvhTriangleMeshShape(trimesh);
|
rbOutput.m_colShape = createBvhTriangleMeshShape(trimesh);
|
||||||
|
|
||||||
@@ -3276,11 +3317,15 @@ void ColladaConverter::ConvertRigidBodyRef( btRigidBodyInput& rbInput,btRigidBod
|
|||||||
if ( otherElemRef != NULL )
|
if ( otherElemRef != NULL )
|
||||||
{
|
{
|
||||||
domGeometryRef linkedGeom = *(domGeometryRef*)&otherElemRef;
|
domGeometryRef linkedGeom = *(domGeometryRef*)&otherElemRef;
|
||||||
printf( "otherLinked\n");
|
if( getVerbosity() > NORMAL )
|
||||||
|
printf( "otherLinked\n");
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
printf("convexMesh polyCount = %i\n",convexRef->getPolygons_array().getCount());
|
if( getVerbosity() > NORMAL )
|
||||||
printf("convexMesh triCount = %i\n",convexRef->getTriangles_array().getCount());
|
{
|
||||||
|
printf("convexMesh polyCount = %i\n",convexRef->getPolygons_array().getCount());
|
||||||
|
printf("convexMesh triCount = %i\n",convexRef->getTriangles_array().getCount());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3404,17 +3449,20 @@ void ColladaConverter::ConvertRigidBodyRef( btRigidBodyInput& rbInput,btRigidBod
|
|||||||
{
|
{
|
||||||
rbOutput.m_colShape = convexHullShape;
|
rbOutput.m_colShape = convexHullShape;
|
||||||
//rbOutput.m_colShape->setTypedUserInfo (new btShapeColladaInfo (geom));
|
//rbOutput.m_colShape->setTypedUserInfo (new btShapeColladaInfo (geom));
|
||||||
printf("created convexHullShape with %i points\n",convexHullShape->getNumVertices());
|
if( getVerbosity() > NORMAL )
|
||||||
|
printf("created convexHullShape with %i points\n",convexHullShape->getNumVertices());
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
deleteShape( convexHullShape);
|
deleteShape( convexHullShape);
|
||||||
printf("failed to create convexHullShape\n");
|
if( getVerbosity() > NORMAL )
|
||||||
|
printf("failed to create convexHullShape\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//domGeometryRef linkedGeom = *(domGeometryRef*)&otherElemRef;
|
//domGeometryRef linkedGeom = *(domGeometryRef*)&otherElemRef;
|
||||||
|
|
||||||
printf("convexmesh\n");
|
if( getVerbosity() > NORMAL )
|
||||||
|
printf("convexmesh\n");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,7 +78,23 @@ public:
|
|||||||
///ColladaConverter helps converting the physics assets from COLLADA DOM into physics objects
|
///ColladaConverter helps converting the physics assets from COLLADA DOM into physics objects
|
||||||
class ColladaConverter
|
class ColladaConverter
|
||||||
{
|
{
|
||||||
char m_cleaned_filename[513];
|
public:
|
||||||
|
typedef enum {
|
||||||
|
SILENT,
|
||||||
|
NORMAL,
|
||||||
|
LOUD
|
||||||
|
} VerbosityLevel;
|
||||||
|
void setVerbosity( VerbosityLevel verbosity )
|
||||||
|
{
|
||||||
|
m_verbosity = verbosity;
|
||||||
|
}
|
||||||
|
VerbosityLevel getVerbosity() const
|
||||||
|
{
|
||||||
|
return( m_verbosity );
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
char m_cleaned_filename[513];
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -99,7 +115,9 @@ protected:
|
|||||||
bool m_use32bitIndices;
|
bool m_use32bitIndices;
|
||||||
bool m_use4componentVertices;
|
bool m_use4componentVertices;
|
||||||
|
|
||||||
void PreparePhysicsObject(struct btRigidBodyInput& input, bool isDynamics, float mass,btCollisionShape* colShape, const btVector3& linearVelocity, const btVector3& angularVelocity);
|
VerbosityLevel m_verbosity;
|
||||||
|
|
||||||
|
void PreparePhysicsObject(struct btRigidBodyInput& input, bool isDynamics, float mass,btCollisionShape* colShape, const btVector3& linearVelocity, const btVector3& angularVelocity);
|
||||||
|
|
||||||
void prepareConstraints(ConstraintInput& input);
|
void prepareConstraints(ConstraintInput& input);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user