void physx::PxFabricCookerImpl::save( PxOutputStream& stream, bool /*platformMismatch*/ ) const
{
	PxU32 version = PX_PHYSICS_VERSION;
	stream.write(&version, sizeof(PxU32));

	PxClothFabricDesc desc = getDescriptor();

	// write explicit sizes, others are implicit
	stream.write(&mNumParticles, sizeof(PxU32));
	stream.write(&desc.nbPhases, sizeof(PxU32));
	stream.write(&desc.nbSets, sizeof(PxU32));
	stream.write(&desc.nbTethers, sizeof(PxU32));

	PxU32 nbConstraints = desc.sets[desc.nbSets-1];

	// write actual data
	PX_COMPILE_TIME_ASSERT(sizeof(PxClothFabricPhaseType::Enum) == sizeof(PxU32));
	stream.write(desc.phases, desc.nbPhases*sizeof(PxClothFabricPhase));
	stream.write(desc.sets, desc.nbSets*sizeof(PxU32));

	stream.write(desc.restvalues, nbConstraints*sizeof(PxReal));
	stream.write(desc.indices, nbConstraints*2*sizeof(PxU32));

	stream.write(desc.tetherAnchors, desc.nbTethers*sizeof(PxU32));
	stream.write(desc.tetherLengths, desc.nbTethers*sizeof(PxReal));
}
Ejemplo n.º 2
0
void PxDumpMetaData(PxOutputStream& stream, const PxPhysics& sdk)
{
    class MetaDataStream : public PxOutputStream
    {
    public:
        virtual	PxU32 write(const void* src, PxU32 count)
        {
            PX_ASSERT(count==sizeof(Cm::MetaDataEntry));
            const Cm::MetaDataEntry* entry = (const Cm::MetaDataEntry*)src;
            metaData.pushBack(*entry);
            return count;
        }
        Array<Cm::MetaDataEntry> metaData;
    } s;

    PxGetSDKMetaData(sdk, s);

    Cm::OutputStreamWriter writer(s);
    Cm::LegacySerialStream legacyStream(writer);
    PxRegisterExtJointMetaData(legacyStream);

    physx::shdfnd::Array<char>	stringTable;

    PxU32 nb = s.metaData.size();
    Cm::MetaDataEntry* entries = s.metaData.begin();
    for(PxU32 i=0; i<nb; i++)
    {
        entries[i].mType = (const char*)size_t(Cm::addToStringTable(stringTable, entries[i].mType));
        entries[i].mName = (const char*)size_t(Cm::addToStringTable(stringTable, entries[i].mName));
    }

    PxU32 platformTag = 0;
#ifdef PX_X64
    platformTag = PX_MAKE_FOURCC('P','C','6','4');
    const PxU32 gaussMapLimit = PxGetGaussMapVertexLimitForPlatform(PxPlatform::ePC);
    const PxU32 tiledHeightFieldSamples = 0;
#endif
#if defined(PX_X86) || defined(__CYGWIN__)
    platformTag = PX_MAKE_FOURCC('P','C','3','2');
    const PxU32 gaussMapLimit = PxGetGaussMapVertexLimitForPlatform(PxPlatform::ePC);
    const PxU32 tiledHeightFieldSamples = 0;
#endif
#ifdef PX_X360
    platformTag = PX_MAKE_FOURCC('X','B','O','X');
    const PxU32 gaussMapLimit = PxGetGaussMapVertexLimitForPlatform(PxPlatform::eXENON);
    const PxU32 tiledHeightFieldSamples = 0;
#endif
#ifdef PX_PS3
    platformTag = PX_MAKE_FOURCC('P','S','_','3');
    const PxU32 gaussMapLimit = PxGetGaussMapVertexLimitForPlatform(PxPlatform::ePLAYSTATION3);
    const PxU32 tiledHeightFieldSamples = 1;
#endif
#ifdef PX_ARM
    platformTag = PX_MAKE_FOURCC('A','R','M',' ');
    const PxU32 gaussMapLimit = PxGetGaussMapVertexLimitForPlatform(PxPlatform::eARM);
    const PxU32 tiledHeightFieldSamples = 0;
#endif

    const PxU32 header = PX_MAKE_FOURCC('M','E','T','A');
    const PxU32 version = PX_PHYSICS_VERSION;
    const PxU32 ptrSize = sizeof(void*);
    stream.write(&header, 4);
    stream.write(&version, 4);
    stream.write(&ptrSize, 4);
    stream.write(&platformTag, 4);
    stream.write(&gaussMapLimit, 4);
    stream.write(&tiledHeightFieldSamples, 4);

    stream.write(&nb, 4);
    stream.write(entries, nb*sizeof(Cm::MetaDataEntry));

    PxU32 length = stringTable.size();
    const char* table = stringTable.begin();
    stream.write(&length, 4);
    stream.write(table, length);
}
Ejemplo n.º 3
0
void PxSerialization::dumpBinaryMetaData(PxOutputStream& outputStream, PxSerializationRegistry& sr)
{
	class MetaDataStream : public PxOutputStream
	{
	public:
		bool addNewType(const char* typeName)
		{			
			for(PxU32 i=0;i<types.size();i++)
			{			
				if(strcmp(types[i], typeName)==0)
					return false;
			}
			types.pushBack(typeName);
			return true;
		}
		virtual	PxU32 write(const void* src, PxU32 count)
		{
			PX_ASSERT(count==sizeof(PxMetaDataEntry));
			const PxMetaDataEntry* entry = (const PxMetaDataEntry*)src;
			if(( entry->flags & PxMetaDataFlag::eTYPEDEF) || ((entry->flags & PxMetaDataFlag::eCLASS) && (!entry->name)) )
                 newType = addNewType(entry->type);
			if(newType)
			   metaData.pushBack(*entry);
			return count;
		}		
		shdfnd::Array<PxMetaDataEntry> metaData;
		shdfnd::Array<const char*> types;
		bool newType;
	}s;

	SerializationRegistry& sn = static_cast<SerializationRegistry&>(sr);
	sn.getBinaryMetaData(s);

	shdfnd::Array<char>	stringTable;

	PxU32 nb = s.metaData.size();
	PxMetaDataEntry* entries = s.metaData.begin();
	for(PxU32 i=0;i<nb;i++)
	{
		entries[i].type = (const char*)size_t(addToStringTable(stringTable, entries[i].type));
		entries[i].name = (const char*)size_t(addToStringTable(stringTable, entries[i].name));
	}

	PxU32 platformTag = getBinaryPlatformTag();

#if defined(PX_X64)
	const PxU32 gaussMapLimit = PxGetGaussMapVertexLimitForPlatform(PxPlatform::ePC);
	const PxU32 tiledHeightFieldSamples = 0;
#endif
#if defined(PX_X86) || defined(__CYGWIN__)
	const PxU32 gaussMapLimit = PxGetGaussMapVertexLimitForPlatform(PxPlatform::ePC);
	const PxU32 tiledHeightFieldSamples = 0;
#endif
#ifdef PX_X360
	const PxU32 gaussMapLimit = PxGetGaussMapVertexLimitForPlatform(PxPlatform::eXENON);
	const PxU32 tiledHeightFieldSamples = 0;
#endif
#ifdef PX_PS3
	const PxU32 gaussMapLimit = PxGetGaussMapVertexLimitForPlatform(PxPlatform::ePLAYSTATION3);
	const PxU32 tiledHeightFieldSamples = 1;
#endif
#if defined(PX_ARM) || defined(PX_A64)
	const PxU32 gaussMapLimit = PxGetGaussMapVertexLimitForPlatform(PxPlatform::eARM);
	const PxU32 tiledHeightFieldSamples = 0;
#endif
#ifdef PX_WIIU
	const PxU32 gaussMapLimit = PxGetGaussMapVertexLimitForPlatform(PxPlatform::eWIIU);
	const PxU32 tiledHeightFieldSamples = 0;
#endif

	const PxU32 header = PX_MAKE_FOURCC('M','E','T','A');
	const PxU32 version = PX_PHYSICS_VERSION;
	const PxU32 binaryVersion = PX_BINARY_SERIAL_VERSION;
	const PxU32 ptrSize = sizeof(void*);
	PxU32 buildNumber = 0;
#if defined(PX_BUILD_NUMBER)
	buildNumber =  PX_BUILD_NUMBER;
#endif
	outputStream.write(&header, 4);
	outputStream.write(&version, 4);
	outputStream.write(&binaryVersion, 4);
	outputStream.write(&buildNumber, 4);
	outputStream.write(&ptrSize, 4);
	outputStream.write(&platformTag, 4);
	outputStream.write(&gaussMapLimit, 4);
	outputStream.write(&tiledHeightFieldSamples, 4);

	outputStream.write(&nb, 4);
	outputStream.write(entries, nb*sizeof(PxMetaDataEntry));
	
	//concreteTypes to name	
	PxU32 num = sn.getNbSerializers();
	outputStream.write(&num, 4);
	for(PxU32 i=0; i<num; i++)
	{
		PxU16 type = sn.getSerializerType(i);
		PxU32 nameOffset = addToStringTable(stringTable, sn.getSerializerName(i)); 
		outputStream.write(&type, 2);
		outputStream.write(&nameOffset, 4);
	}

	PxU32 length = stringTable.size();
	const char* table = stringTable.begin();
	outputStream.write(&length, 4);
	outputStream.write(table, length);
}