btHeightfieldTerrainShape does not seem to serialize, after loading back in, seems to be null values.
Some questions:
1)Does serializeSingleShape work for btHeightfieldTerrainShape?
2)How to convert from btHeightfieldTerrainShape to btBvhTriangleMeshShape?
NOTES:
I am having trouble getting btHeightfieldTerrainShape to serialize, I have successfully serialized many other shapes including btBvhTriangleMeshShape. So if I could convert from btHeightfieldTerrainShape to btBvhTriangleMeshShape, or some other object that I can convert to , serialize out, load, then convert back.
regards,
Mark.
Can you SerializeSingleShape with btHeightfieldTerrainShape?
-
- Posts: 4
- Joined: Thu Dec 30, 2010 1:03 pm
-
- Posts: 4
- Joined: Thu Dec 30, 2010 1:03 pm
Re: Can you SerializeSingleShape with btHeightfieldTerrainSh
Ok I have been working the problem...
Using the code from ConcavePhysicsDemo.cpp, I am back using btBvhTriangleMeshShape but still encountering problems...
Here is the Code I use to create the Shape, it shows correctly if I make it now:
I then serialize it as so:
And then try to load it back in like this:
But it crashes:[ :
> TerrainTest.exe!`btBvhTriangleMeshShape::processAllTriangles'::`2'::MyNodeOverlapCallback::processNode(int nodeSubPart=0, int nodeTriangleIndex=576) Line 299 + 0xb bytes C++
TerrainTest.exe!btQuantizedBvh::walkStacklessQuantizedTree(btNodeOverlapCallback * nodeCallback=0x001dee20, unsigned short * quantizedQueryAabbMin=0x001dede0, unsigned short * quantizedQueryAabbMax=0x001dedd0, int startNodeIndex=0, int endNodeIndex=3843) Line 712 + 0x21 bytes C++
TerrainTest.exe!btQuantizedBvh::reportAabbOverlappingNodex(btNodeOverlapCallback * nodeCallback=0x001dee20, const btVector3 & aabbMin={...}, const btVector3 & aabbMax={...}) Line 329 C++
TerrainTest.exe!btBvhTriangleMeshShape::processAllTriangles(btTriangleCallback * callback=0x07952010, const btVector3 & aabbMin={...}, const btVector3 & aabbMax={...}) Line 329 C++
TerrainTest.exe!btConvexConcaveCollisionAlgorithm::processCollision(btCollisionObject * body0=0x07c1bb00, btCollisionObject * body1=0x197664b0, const btDispatcherInfo & dispatchInfo={...}, btManifoldResult * resultOut=0x001deef0) Line 197 + 0x2e bytes C++
TerrainTest.exe!btCollisionDispatcher::defaultNearCallback(btBroadphasePair & collisionPair={...}, btCollisionDispatcher & dispatcher={...}, const btDispatcherInfo & dispatchInfo={...}) Line 268 + 0x28 bytes C++
TerrainTest.exe!btCollisionPairCallback::processOverlap(btBroadphasePair & pair={...}) Line 224 + 0x21 bytes C++
TerrainTest.exe!btHashedOverlappingPairCache::processAllOverlappingPairs(btOverlapCallback * callback=0x001df01c, btDispatcher * dispatcher=0x05ea88e8) Line 387 + 0x13 bytes C++
TerrainTest.exe!btCollisionDispatcher::dispatchAllCollisionPairs(btOverlappingPairCache * pairCache=0x07908db0, const btDispatcherInfo & dispatchInfo={...}, btDispatcher * dispatcher=0x05ea88e8) Line 238 + 0x17 bytes C++
TerrainTest.exe!btCollisionWorld::performDiscreteCollisionDetection() Line 214 + 0x37 bytes C++
TerrainTest.exe!btDiscreteDynamicsWorld::internalSingleStepSimulation(float timeStep=0.016666668) Line 318 + 0xf bytes C++
TerrainTest.exe!btDiscreteDynamicsWorld::stepSimulation(float timeStep=3.9730000, int maxSubSteps=10, float fixedTimeStep=0.016666668) Line 281 + 0x19 bytes C++
at this line
graphicsbase is null, so I am assuming that it is missing some vertex data etc... but why does it not crash if I run it before serializing, but crashes after serializing?
I am assuming that I have missed something? Any Ideas anybody?
regards,
Rip.
Using the code from ConcavePhysicsDemo.cpp, I am back using btBvhTriangleMeshShape but still encountering problems...
Here is the Code I use to create the Shape, it shows correctly if I make it now:
Code: Select all
btTriangleMesh *trimesh = new btTriangleMesh();
int vCount=0;
btVector3 vertex0(0,0,0);
btVector3 vertex1(0,0,0);
btVector3 vertex2(0,0,0);
for(std::map<unsigned short, Ogre::Vector3>::iterator i = vOgrePointList.begin(); i != vOgrePointList.end(); i++)
{
if((*i).second.y>vMax.y) vMax.y=(*i).second.y;
if((*i).second.y<vMin.y) vMin.y=(*i).second.y;
if(vCount==0)
{
vertex0 = btVector3((*i).second.x,(*i).second.y,(*i).second.z);
}else if(vCount==1)
{
vertex1 = btVector3((*i).second.x,(*i).second.y,(*i).second.z);
}else if(vCount==2)
{
vertex2 = btVector3((*i).second.x,(*i).second.y,(*i).second.z);
trimesh->addTriangle(vertex0, vertex1, vertex2);
vCount=-1;
}
vCount++;
}
btVector3 vPMin(vMin.x,vMin.y,vMin.z);
btVector3 vPMax(vMax.x,vMax.y,vMax.z);
const bool useQuantizedAABB = true;
btBvhTriangleMeshShape *vShape = new btBvhTriangleMeshShape(trimesh, useQuantizedAABB,vPMin,vPMax);
vShape->buildOptimizedBvh();
vShape->recalcLocalAabb();
Code: Select all
btDefaultSerializer* vSerializer;
vSerializer = new btDefaultSerializer(maxSerializeBufferSize);
vSerializer->startSerialization();
vSerializer->registerNameForPointer(vShape,getData().mName);
vShape->serializeSingleShape(vSerializer);
// vShape->serializeSingleBvh(vSerializer);
// vShape->serializeSingleTriangleInfoMap(vSerializer);
vSerializer->finishSerialization();
Ogre::String vName = "ROS-Landscape"+Ogre::StringConverter().toString(getData().mID)+".bullet";
std::cout << "LandscapeP:Saving Shape(" << getData().mName << ")Size(" << maxSerializeBufferSize << ")."<< std::endl;
FILE* file = fopen(vName.c_str(),"wb");
fwrite(vSerializer->getBufferPointer(),vSerializer->getCurrentBufferSize(),1, file);
fclose(file);
Code: Select all
btBulletWorldImporter vFileLoader(0);//mWorld);
Ogre::String vName = "ROS-Landscape"+Ogre::StringConverter().toString(getData().mID)+".bullet";
if(vFileLoader.loadFile(vName.c_str()))
{
//***TERRAIN SURFACE - Ok now lets load up the surface for the map
//Lets load the ground shape.
int numShapes = vFileLoader.getNumCollisionShapes();
if (numShapes)
{
mLandscapeShape = (btBvhTriangleMeshShape*)vFileLoader.getCollisionShapeByName(getData().mName);
}
mLandscapeState = new btDefaultMotionState();
//Create the Body.
mLandscapeBody = new btRigidBody(0, mLandscapeState, mLandscapeShape);
mLandscapeBody->getWorldTransform().setOrigin(mPosition);
mLandscapeBody->getWorldTransform().setRotation(btQuaternion(Ogre::Quaternion::IDENTITY.x,Ogre::Quaternion::IDENTITY.y,Ogre::Quaternion::IDENTITY.z, Ogre::Quaternion::IDENTITY.w));
mLandscapeBody->setCollisionFlags(mLandscapeBody->getCollisionFlags() | btCollisionObject::CF_STATIC_OBJECT);
mWorld->addRigidBody(mLandscapeBody);
> TerrainTest.exe!`btBvhTriangleMeshShape::processAllTriangles'::`2'::MyNodeOverlapCallback::processNode(int nodeSubPart=0, int nodeTriangleIndex=576) Line 299 + 0xb bytes C++
TerrainTest.exe!btQuantizedBvh::walkStacklessQuantizedTree(btNodeOverlapCallback * nodeCallback=0x001dee20, unsigned short * quantizedQueryAabbMin=0x001dede0, unsigned short * quantizedQueryAabbMax=0x001dedd0, int startNodeIndex=0, int endNodeIndex=3843) Line 712 + 0x21 bytes C++
TerrainTest.exe!btQuantizedBvh::reportAabbOverlappingNodex(btNodeOverlapCallback * nodeCallback=0x001dee20, const btVector3 & aabbMin={...}, const btVector3 & aabbMax={...}) Line 329 C++
TerrainTest.exe!btBvhTriangleMeshShape::processAllTriangles(btTriangleCallback * callback=0x07952010, const btVector3 & aabbMin={...}, const btVector3 & aabbMax={...}) Line 329 C++
TerrainTest.exe!btConvexConcaveCollisionAlgorithm::processCollision(btCollisionObject * body0=0x07c1bb00, btCollisionObject * body1=0x197664b0, const btDispatcherInfo & dispatchInfo={...}, btManifoldResult * resultOut=0x001deef0) Line 197 + 0x2e bytes C++
TerrainTest.exe!btCollisionDispatcher::defaultNearCallback(btBroadphasePair & collisionPair={...}, btCollisionDispatcher & dispatcher={...}, const btDispatcherInfo & dispatchInfo={...}) Line 268 + 0x28 bytes C++
TerrainTest.exe!btCollisionPairCallback::processOverlap(btBroadphasePair & pair={...}) Line 224 + 0x21 bytes C++
TerrainTest.exe!btHashedOverlappingPairCache::processAllOverlappingPairs(btOverlapCallback * callback=0x001df01c, btDispatcher * dispatcher=0x05ea88e8) Line 387 + 0x13 bytes C++
TerrainTest.exe!btCollisionDispatcher::dispatchAllCollisionPairs(btOverlappingPairCache * pairCache=0x07908db0, const btDispatcherInfo & dispatchInfo={...}, btDispatcher * dispatcher=0x05ea88e8) Line 238 + 0x17 bytes C++
TerrainTest.exe!btCollisionWorld::performDiscreteCollisionDetection() Line 214 + 0x37 bytes C++
TerrainTest.exe!btDiscreteDynamicsWorld::internalSingleStepSimulation(float timeStep=0.016666668) Line 318 + 0xf bytes C++
TerrainTest.exe!btDiscreteDynamicsWorld::stepSimulation(float timeStep=3.9730000, int maxSubSteps=10, float fixedTimeStep=0.016666668) Line 281 + 0x19 bytes C++
at this line
Code: Select all
float* graphicsbase = (float*)(vertexbase+graphicsindex*stride);
m_triangle[j] = btVector3(
graphicsbase[0]*meshScaling.getX(),
graphicsbase[1]*meshScaling.getY(),
graphicsbase[2]*meshScaling.getZ());
I am assuming that I have missed something? Any Ideas anybody?
regards,
Rip.
