In PhysX 3.3.4, convexmesh\trianglemesh\heightfield should be cooked before use, and they could be cooked offline or at runtime.
According to http://docs.nvidia.com/gameworks/content/gameworkslibrary/physx/guide/Manual/Geometry.html, we can cook a geometry in two manners:
offline manner by streaming
PxDefaultMemoryOutputStream writeBuffer; cooking.cookTriangleMesh(someDescription, writeBuffer); PxDefaultMemoryInputData readBuffer(writeBuffer.getData(), writeBuffer.getSize()); PxTriangleMesh* aTriangleMesh = physics.createTriangleMesh(readBuffer);
runtime manner by cook api
PxTriangleMesh* aTriangleMesh = theCooking->createTriangleMesh(meshDesc, thePhysics->getPhysicsInsertionCallback());
According to this page, if I want the best performance at runtime, I should use the offline manner. I read the source code of PhysX and found them identical, except for an extra stream in offline manner containing data generated at cook time. So to speed up performance, should I save the stream to disk and recovery the cooked data at runtime to make cook actually “offline”?
Note: cooking also generates a binary output stream. The primary purpose of cooking, however, is to translate from a user format to a format suitable for the SDK runtime, and so it is not considered a serialization mechanism. Loading a cooked mesh from a stream involves allocation and endian conversion. As a consequence, it is much less efficient than PhysX’ binary serialization mechanism. See http://docs.nvidia.com/gameworks/content/gameworkslibrary/physx/guide/Manual/RigidBodyCollision.html#rigidbodycollisionshapes for more details about cooking.
So the stream generated in the offline cook manner should not be stored at disk. If that is the case, what does the redundancy stream for?
If I use the PhysX binary serialization mechanism, how to make the cook procedure offline and achieve the best performance?