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:
erwin.coumans
2009-12-21 22:55:32 +00:00
parent d68521803f
commit 9fa2460933
2 changed files with 116 additions and 50 deletions

View File

@@ -169,7 +169,8 @@ m_dom(0),
m_filename(0),
m_unitMeterScaling(1.f),
m_use32bitIndices(true),
m_use4componentVertices(true)
m_use4componentVertices(true),
m_verbosity(LOUD)
{
}
@@ -331,22 +332,31 @@ bool ColladaConverter::convert()
switch( up->getValue() )
{
case UPAXISTYPE_X_UP:
if( getVerbosity() > SILENT )
{
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));
setCameraInfo(btVector3(1,0,0),1);
break;
case UPAXISTYPE_Y_UP:
if( getVerbosity() > SILENT )
{
printf(" Y Axis is Up for this file \n" );
printf(" COLLADA_RT set to Y Up \n" );
}
setGravity(btVector3(0,-10,0));
setCameraInfo(btVector3(0,1,0),0);
break;
case UPAXISTYPE_Z_UP:
if( getVerbosity() > SILENT )
{
printf(" Z Axis is Up for this file \n" );
printf(" All Geometry and Hiearchies must be converted!\n" );
}
setGravity(btVector3(0,0,-10));
break;
default:
@@ -382,6 +392,7 @@ bool ColladaConverter::convert()
{
domLibrary_geometriesRef libgeom = m_dom->getLibrary_geometries_array()[i];
if( getVerbosity() > SILENT )
printf(" CrtScene::Reading Geometry Library \n" );
for ( unsigned int i = 0; i < libgeom->getGeometry_array().getCount(); i++)
{
@@ -396,6 +407,8 @@ bool ColladaConverter::convert()
int numPolygonGroups = (int)meshElement->getPolygons_array().getCount();
int numPolyList = (int)meshElement->getPolylist_array().getCount();
int totalGroups = numTriangleGroups + numPolygonGroups + numPolyList;
if( getVerbosity() > NORMAL )
{
if (totalGroups == 0)
{
printf("No Triangles or Polygons found int Geometry %s \n", lib->getId() );
@@ -403,18 +416,22 @@ bool ColladaConverter::convert()
{
printf("Found mesh geometry (%s): numTriangleGroups:%i numPolygonGroups :%i numPolyList=%i\n",lib->getId(),numTriangleGroups,numPolygonGroups,numPolyList);
}
}
}
domConvex_mesh *convexMeshElement = lib->getConvex_mesh();
if (convexMeshElement)
{
if( getVerbosity() > NORMAL )
printf("found convexmesh element\n");
// Find out how many groups we need to allocate space for
int numTriangleGroups = (int)convexMeshElement->getTriangles_array().getCount();
int numPolygonGroups = (int)convexMeshElement->getPolygons_array().getCount();
int totalGroups = numTriangleGroups + numPolygonGroups;
if( getVerbosity() > NORMAL )
{
if (totalGroups == 0)
{
printf("No Triangles or Polygons found in ConvexMesh Geometry %s \n", lib->getId() );
@@ -422,6 +439,7 @@ bool ColladaConverter::convert()
{
printf("Found convexmesh geometry: numTriangleGroups:%i numPolygonGroups:%i\n",numTriangleGroups,numPolygonGroups);
}
}
}//fi
}//for each geometry
@@ -442,6 +460,7 @@ bool ColladaConverter::convert()
if (physicsSceneRef->getTechnique_common()->getGravity())
{
const domFloat3 grav = physicsSceneRef->getTechnique_common()->getGravity()->getValue();
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)));
@@ -510,6 +529,7 @@ bool ColladaConverter::convert()
}
}
if( getVerbosity() > SILENT )
printf("mass = %f, isDynamics %i\n",mass,isDynamics);
if (bodyName && model)
@@ -603,6 +623,7 @@ bool ColladaConverter::convert()
}
}
if( getVerbosity() > SILENT )
printf("mass = %f, isDynamics %i\n",mass,isDynamics);
domRigid_bodyRef savedRbRef = NULL;
@@ -628,6 +649,7 @@ bool ColladaConverter::convert()
savedRbRef = rigidBodyRef;
rbInput.m_instanceRigidBodyRef = instRigidbodyRef;
ConvertRigidBodyRef( rbInput , output );
if( getVerbosity() > SILENT )
printf("Found body converting %s\n", bodyName);
mass = output.m_mass;
@@ -1006,7 +1028,15 @@ void ColladaConverter::prepareConstraints(ConstraintInput& input)
{
btRigidBody* body = getRigidBody (i);
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();
if (name)
@@ -1265,6 +1295,7 @@ domLibrary_physics_materials* ColladaConverter::getDefaultMaterialsLib ()
}
}
}
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->setName("Bullet-PhysicsMaterials");
@@ -1293,6 +1324,7 @@ domPhysics_model* ColladaConverter::getDefaultPhysicsModel ()
}
}
} else {
if( getVerbosity() > SILENT )
printf("No library physics model. Creating one\n");
modelsLib = daeSafeCast<domLibrary_physics_models> (m_dom->createAndPlace (COLLADA_ELEMENT_LIBRARY_PHYSICS_MODELS ));
}
@@ -1300,6 +1332,7 @@ domPhysics_model* ColladaConverter::getDefaultPhysicsModel ()
/* Always create in first physics models library */
modelsLib = m_dom->getLibrary_physics_models_array()[0];
if( getVerbosity() > SILENT )
printf("Could not find physics model. Creating one\n");
domPhysics_model* physicsModel = daeSafeCast<domPhysics_model>(modelsLib->createAndPlace (COLLADA_ELEMENT_PHYSICS_MODEL));
@@ -1324,6 +1357,7 @@ domInstance_physics_model* ColladaConverter::getDefaultInstancePhysicsModel ()
return physicsModelInstance;
}
}
if( getVerbosity() > SILENT )
printf("Creating Bullet-PhysicsModel instance\n");
domInstance_physics_model* physicsModelInstance = daeSafeCast<domInstance_physics_model>(physicsScene->createAndPlace (COLLADA_ELEMENT_INSTANCE_PHYSICS_MODEL));
physicsModelInstance->setUrl ("#Bullet-PhysicsModel");
@@ -1604,6 +1638,7 @@ void ColladaConverter::addConcaveMeshInternal(btStridingMeshInterface* meshInter
geo->setId( nodeName );
geo->setName ( nodeName);
if( getVerbosity() > NORMAL )
printf("numSubParts = \n",meshInterface->getNumSubParts ());
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);
if( getVerbosity() > NORMAL )
{
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);
@@ -2521,6 +2558,7 @@ void ColladaConverter::syncOrAddRigidBody (btRigidBody* body)
domRigid_body* dRigidBody=NULL;
domInstance_rigid_body* dInstanceRigidBody=NULL;
if( getVerbosity() > SILENT )
printf("New body\n");
btCollisionShape* shape = body->getCollisionShape ();
@@ -2541,6 +2579,7 @@ void ColladaConverter::syncOrAddRigidBody (btRigidBody* body)
shapeName = &shapeNameGen[0];
}
if( getVerbosity() > SILENT )
printf("Adding %s to COLLADA DOM.\n", nodeName);
@@ -3199,11 +3238,13 @@ void ColladaConverter::ConvertRigidBodyRef( btRigidBodyInput& rbInput,btRigidBod
if (rbOutput.m_isDynamics)
{
if( getVerbosity() > NORMAL )
printf("moving concave <mesh> added\n");
//rbOutput.m_colShape = createConvexTriangleMeshShape(trimesh);
rbOutput.m_colShape = createGimpactShape(trimesh);
} else
{
if( getVerbosity() > NORMAL )
printf("static concave triangle <mesh> added\n");
rbOutput.m_colShape = createBvhTriangleMeshShape(trimesh);
@@ -3276,11 +3317,15 @@ void ColladaConverter::ConvertRigidBodyRef( btRigidBodyInput& rbInput,btRigidBod
if ( otherElemRef != NULL )
{
domGeometryRef linkedGeom = *(domGeometryRef*)&otherElemRef;
if( getVerbosity() > NORMAL )
printf( "otherLinked\n");
} else
{
if( getVerbosity() > NORMAL )
{
printf("convexMesh polyCount = %i\n",convexRef->getPolygons_array().getCount());
printf("convexMesh triCount = %i\n",convexRef->getTriangles_array().getCount());
}
}
}
@@ -3404,16 +3449,19 @@ void ColladaConverter::ConvertRigidBodyRef( btRigidBodyInput& rbInput,btRigidBod
{
rbOutput.m_colShape = convexHullShape;
//rbOutput.m_colShape->setTypedUserInfo (new btShapeColladaInfo (geom));
if( getVerbosity() > NORMAL )
printf("created convexHullShape with %i points\n",convexHullShape->getNumVertices());
} else
{
deleteShape( convexHullShape);
if( getVerbosity() > NORMAL )
printf("failed to create convexHullShape\n");
}
//domGeometryRef linkedGeom = *(domGeometryRef*)&otherElemRef;
if( getVerbosity() > NORMAL )
printf("convexmesh\n");
}

View File

@@ -78,6 +78,22 @@ public:
///ColladaConverter helps converting the physics assets from COLLADA DOM into physics objects
class ColladaConverter
{
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];
@@ -99,6 +115,8 @@ protected:
bool m_use32bitIndices;
bool m_use4componentVertices;
VerbosityLevel m_verbosity;
void PreparePhysicsObject(struct btRigidBodyInput& input, bool isDynamics, float mass,btCollisionShape* colShape, const btVector3& linearVelocity, const btVector3& angularVelocity);
void prepareConstraints(ConstraintInput& input);