Beispiel #1
0
bool PhysXWorld::ExportWholeScene(const char *filename) const
{
	using namespace physx::repx;
	if (!PhysXSDK || !PhysXScene)
		return false;

	PxCollection *cl = PhysXSDK->createCollection();
	if (!cl)
		return false;

	PhysxUserFileWriteStream fs(filename);

	RepXCollection* theCollection = createCollection(PhysXSDK->getTolerancesScale(), PhysXFoundation->getAllocatorCallback());
	RepXIdToRepXObjectMap* theIdMap =  RepXIdToRepXObjectMap::create(PxGetFoundation().getAllocatorCallback());
	addSDKItemsToRepX ( *PhysXSDK, *theIdMap, *theCollection); //add physcis object
	addSceneItemsToRepX ( *PhysXScene, *theIdMap, *theCollection); //add physcis object
//	physx::repx::addObjectsToScene(theCollection, physics, cooking, scene, mStringTable );
	theCollection->save(fs);
	theCollection->destroy();
	theIdMap->destroy();
	return true;


//	PxCollectForExportSDK(*PhysXSDK, *cl);
//	PxCollectForExportScene(*PhysXScene, *cl);
	ObjectIterator iter = GameWorld().GetFirstOfAllObjects();

	while( iter.current )
	{
		GameObject* o = iter.current;

		if (o->PhysicsObject)
		{
			PxActor *a = o->PhysicsObject->getPhysicsActor();
			PxSerialFlags f = a->getSerialFlags();
			a->collectForExport(*cl);
			break;
		}

		iter = GameWorld().GetNextOfAllObjects( iter );
	}
	PxU32 numObjs = cl->getNbObjects();
	numObjs;

	cl->serialize(fs);

	PhysXSDK->releaseCollection(*cl);
	fclose(fs.fpw);

	FILE* fp=NULL;

	if( (fp = fopen(filename, "rb")) )
	{
		fseek(fp, 0, SEEK_END);
		PxU32 fileSize = ftell(fp);
		fseek(fp, 0, SEEK_SET);

		PX_ASSERT(fileSize!=0);
		void* mem = malloc(fileSize+PX_SERIAL_FILE_ALIGN);

		void* mem16 = (void*)((size_t(mem) + PX_SERIAL_FILE_ALIGN)&~(PX_SERIAL_FILE_ALIGN-1));
		fread(mem16, 1, fileSize, fp);
		fclose(fp);

		PxUserReferences* convexRefs = PhysXSDK->createUserReferences();
		PxCollection* collection = PhysXSDK->createCollection();
		collection->deserialize(mem16, convexRefs, NULL);

		PxU32 numObjs = collection->getNbObjects();
		for (PxU32 i = 0; i < numObjs; ++i)
		{
			PxSerializable *o = collection->getObject(i);
			const char * name = o->getConcreteTypeName();
			PX_ASSERT(name);
		}
	}


	return true;
}