void StatefulMeshSerializer::determineFileFormat(DataStreamPtr stream)
    {
        determineEndianness(stream);

        // Read header and determine the version
        unsigned short headerID;
        
        // Read header ID
        readShorts(stream, &headerID, 1);
        
        if (headerID != HEADER_CHUNK_ID)
        {
            OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, "File header not found",
                "MeshSerializer::importMesh");
        }
        // Read version
        mMeshFileVersion = readString(stream);
        // Jump back to start
        stream->seek(0);

#if OGRE_ENDIAN == OGRE_ENDIAN_BIG
        mMeshFileEndian = mFlipEndian ? ENDIAN_LITTLE : ENDIAN_BIG;
#else
        mMeshFileEndian = mFlipEndian ? ENDIAN_BIG : ENDIAN_LITTLE;
#endif
    }
    //---------------------------------------------------------------------
    void SkeletonSerializer::importSkeleton(DataStreamPtr& stream, Skeleton* pSkel)
    {
		// Determine endianness (must be the first thing we do!)
		determineEndianness(stream);

		// Check header
        readFileHeader(stream);

        unsigned short streamID;
        while(!stream->eof())
        {
            streamID = readChunk(stream);
            switch (streamID)
            {
            case SKELETON_BONE:
                readBone(stream, pSkel);
                break;
            case SKELETON_BONE_PARENT:
                readBoneParent(stream, pSkel);
                break;
            case SKELETON_ANIMATION:
                readAnimation(stream, pSkel);
				break;
			case SKELETON_ANIMATION_LINK:
				readSkeletonAnimationLink(stream, pSkel);
				break;
            }
        }

        // Assume bones are stored in the binding pose
        pSkel->setBindingPose();


    }
	void LodConfigSerializer::importLodConfig(Ogre::LodConfig* config, DataStreamPtr& stream)
	{
		mStream = stream;
		mLodConfig = config;

		// Determine endianness (must be the first thing we do!)
		determineEndianness(mStream);

		// Check header
		readFileHeader(mStream);

		pushInnerChunk(mStream);
		while (!mStream->eof())
		{
			unsigned short streamID = readChunk(mStream);
			switch (streamID)
			{
			case LCCID_LOD_CONFIG:
				readLodConfig();
				break;
			default:
				backpedalChunkHeader(mStream);
				popInnerChunk(mStream);
				return;
			}
		}
		popInnerChunk(mStream);
	}
	void LodConfigSerializer::exportLodConfig(Ogre::LodConfig& config, Ogre::DataStreamPtr stream, Endian endianMode /*= ENDIAN_NATIVE*/ )
	{
		Ogre::LogManager::getSingleton().logMessage("MeshSerializer writing mesh data to stream " + stream->getName() + "...");

		// Decide on endian mode
		determineEndianness(endianMode);
		mLodConfig = &config;
		mStream = stream;
		if (!stream->isWriteable())
		{
			OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
				"Unable to use stream " + stream->getName() + " for writing",
				"LodConfigSerializer::export");
		}

		writeFileHeader();
		LogManager::getSingleton().logMessage("File header written.");


		LogManager::getSingleton().logMessage("Writing Lod Config...");
		pushInnerChunk(mStream);
		writeLodConfig();
		popInnerChunk(mStream);
		LogManager::getSingleton().logMessage("LodConfigSerializer export successful.");
	}
    void StatefulSkeletonSerializer::determineFileFormat(DataStreamPtr stream)
    {
        determineEndianness(stream);

#if OGRE_ENDIAN == OGRE_ENDIAN_BIG
        mSkeletonFileEndian = mFlipEndian ? ENDIAN_LITTLE : ENDIAN_BIG;
#else
        mSkeletonFileEndian = mFlipEndian ? ENDIAN_BIG : ENDIAN_LITTLE;
#endif
    }
    //---------------------------------------------------------------------
    void SkeletonSerializer::exportSkeleton(const Skeleton* pSkeleton, 
		const String& filename, Endian endianMode)
    {
		// Decide on endian mode
		determineEndianness(endianMode);

        String msg;
        mpfFile = fopen(filename.c_str(), "wb");
		if (!mpfFile)
		{
			OGRE_EXCEPT(Exception::ERR_CANNOT_WRITE_TO_FILE,
				"Unable to open file " + filename + " for writing",
				"SkeletonSerializer::exportSkeleton");
		}

        writeFileHeader();

        // Write main skeleton data
        LogManager::getSingleton().logMessage("Exporting bones..");
        writeSkeleton(pSkeleton);
        LogManager::getSingleton().logMessage("Bones exported.");

        // Write all animations
        unsigned short numAnims = pSkeleton->getNumAnimations();
        LogManager::getSingleton().stream()
			<< "Exporting animations, count=" << numAnims;
        for (unsigned short i = 0; i < numAnims; ++i)
        {
            Animation* pAnim = pSkeleton->getAnimation(i);
			LogManager::getSingleton().stream()
				<< "Exporting animation: " << pAnim->getName();
            writeAnimation(pSkeleton, pAnim);
            LogManager::getSingleton().logMessage("Animation exported.");

        }

		// Write links
		Skeleton::LinkedSkeletonAnimSourceIterator linkIt = 
			pSkeleton->getLinkedSkeletonAnimationSourceIterator();
		while(linkIt.hasMoreElements())
		{
			const LinkedSkeletonAnimationSource& link = linkIt.getNext();
			writeSkeletonAnimationLink(pSkeleton, link);
		}

        fclose(mpfFile);

    }
Пример #7
0
    //---------------------------------------------------------------------
    void MeshSerializer::importMesh(DataStreamPtr& stream, Mesh* pDest)
    {
        determineEndianness(stream);

        // Read header and determine the version
        unsigned short headerID;
        
        // Read header ID
        readShorts(stream, &headerID, 1);
        
        if (headerID != HEADER_CHUNK_ID)
        {
            OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, "File header not found",
                "MeshSerializer::importMesh");
        }
        // Read version
        String ver = readString(stream);
        // Jump back to start
        stream->seek(0);

        // Find the implementation to use
        MeshSerializerImpl* impl = 0;
        for (MeshVersionDataList::iterator i = mVersionData.begin(); 
             i != mVersionData.end(); ++i)
        {
            if ((*i)->versionString == ver)
            {
                impl = (*i)->impl;
                break;
            }
        }           
        if (!impl)
            OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, "Cannot find serializer implementation for "
                        "mesh version " + ver, "MeshSerializer::importMesh");
        
        // Call implementation
        impl->importMesh(stream, pDest, mListener);
        // Warn on old version of mesh
        if (ver != mVersionData[0]->versionString)
        {
            LogManager::getSingleton().logMessage("WARNING: " + pDest->getName() + 
                " is an older format (" + ver + "); you should upgrade it as soon as possible" +
                " using the OgreMeshTool tool.", LML_CRITICAL);
        }

        if(mListener)
            mListener->processMeshCompleted(pDest);
    }
    //---------------------------------------------------------------------
    void SkeletonSerializer::exportSkeleton(const Skeleton* pSkeleton, 
		DataStreamPtr stream, SkeletonVersion ver, Endian endianMode)
    {
		setWorkingVersion(ver);
		// Decide on endian mode
		determineEndianness(endianMode);

        String msg;
        mStream = stream; 
		if (!stream->isWriteable())
		{
			OGRE_EXCEPT(Exception::ERR_CANNOT_WRITE_TO_FILE,
				"Unable to write to stream " + stream->getName(),
				"SkeletonSerializer::exportSkeleton");
		}


        writeFileHeader();

        // Write main skeleton data
        LogManager::getSingleton().logMessage("Exporting bones..");
        writeSkeleton(pSkeleton, ver);
        LogManager::getSingleton().logMessage("Bones exported.");

        // Write all animations
        unsigned short numAnims = pSkeleton->getNumAnimations();
        LogManager::getSingleton().stream()
			<< "Exporting animations, count=" << numAnims;
        for (unsigned short i = 0; i < numAnims; ++i)
        {
            Animation* pAnim = pSkeleton->getAnimation(i);
			LogManager::getSingleton().stream()
				<< "Exporting animation: " << pAnim->getName();
            writeAnimation(pSkeleton, pAnim, ver);
            LogManager::getSingleton().logMessage("Animation exported.");

        }

		// Write links
		Skeleton::LinkedSkeletonAnimSourceIterator linkIt = 
			pSkeleton->getLinkedSkeletonAnimationSourceIterator();
		while(linkIt.hasMoreElements())
		{
			const LinkedSkeletonAnimationSource& link = linkIt.getNext();
			writeSkeletonAnimationLink(pSkeleton, link);
		}       

    }
Пример #9
0
	//---------------------------------------------------------------------
	void StreamSerialiser::writeHeader()
	{
		if (mEndian == ENDIAN_AUTO)
			determineEndianness();

		// Header chunk has zero data size
		writeChunkImpl(HEADER_ID, 1);

		// real format
		bool realIsDouble = (mRealFormat == REAL_DOUBLE);
		write(&realIsDouble);

		writeChunkEnd(HEADER_ID);

		mReadWriteHeader = false;
	}
Пример #10
0
    //---------------------------------------------------------------------
    void SkeletonSerializer::importSkeleton(DataStreamPtr& stream, Skeleton* pSkel)
    {
        // Determine endianness (must be the first thing we do!)
        determineEndianness(stream);

        // Check header
        readFileHeader(stream);
        pushInnerChunk(stream);
        unsigned short streamID = readChunk(stream);

        while(!stream->eof())
        {
            switch (streamID)
            {
            case SKELETON_BLENDMODE:
            {
                // Optional blend mode
                uint16 blendMode;
                readShorts(stream, &blendMode, 1);
                pSkel->setBlendMode(static_cast<SkeletonAnimationBlendMode>(blendMode));
                break;
            }
            case SKELETON_BONE:
                readBone(stream, pSkel);
                break;
            case SKELETON_BONE_PARENT:
                readBoneParent(stream, pSkel);
                break;
            case SKELETON_ANIMATION:
                readAnimation(stream, pSkel);
                break;
            case SKELETON_ANIMATION_LINK:
                readSkeletonAnimationLink(stream, pSkel);
                break;
            default:
                break;
            }

            streamID = readChunk(stream);
        }
        // Assume bones are stored in the binding pose
        pSkel->setBindingPose();
        popInnerChunk(stream);

    }
Пример #11
0
	    //---------------------------------------------------------------------
	    void ParseOgre::importMesh(DataStreamPtr&	stream, OgreMesh* pDest)
	    {
	        determineEndianness(stream);
	
	        // Read header and determine the version
	        unsigned short headerID;//	=	*(U16*)p;
	        
	        // Read header ID
			//stream.g
	        readShorts(stream, &headerID, 1);
			//Read(&headerID,sizeof(headerID),1,pData,uiPos);
	        
	        if (headerID != HEADER_CHUNK_ID)
	        {
	//             OGRE_EXCEPT(0, "File header not found",
	//                 "ParseOgre::importMesh");
	        }
	        // Read version
	        AString ver = readString(stream);
	// 		AChar	version[MAX_NAME];
	// 		ReadStr(pData,version,uiPos);
	// 		ver	=	version;
	        // Jump back to start
	        stream->seek(0);
	
	        // Find the implementation to use
	        ParseOgreImplMap::iterator impl = mImplementations.find(ver);
	        if (impl == mImplementations.end())
	        {
	//             OGRE_EXCEPT(0, "Cannot find serializer implementation for "
	//                 "current version " + ver, "ParseOgre::importMesh");
	        }
	
	        // Call implementation
	        impl->second->importMesh(stream, pDest, mListener);
	        // Warn on old version of mesh
	        if (ver != msCurrentVersion)
	        {
	//             LogManager("WARNING: " + pDest->getName() + 
	//                 " is an older format (" + ver + "); you should upgrade it as soon as possible" +
	//                 " using the OgreMeshUpgrade tool.");
	        }
	
	    }
Пример #12
0
    //---------------------------------------------------------------------
    void MeshSerializer::importMesh(DataStreamPtr& stream, Mesh* pDest)
    {
        determineEndianness(stream);

        // Read header and determine the version
        unsigned short headerID;
        
        // Read header ID
        readShorts(stream, &headerID, 1);
        
        if (headerID != HEADER_CHUNK_ID)
        {
            OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, "File header not found",
                "MeshSerializer::importMesh");
        }
        // Read version
        String ver = readString(stream);
        // Jump back to start
        stream->seek(0);

        // Find the implementation to use
        MeshSerializerImplMap::iterator impl = mImplementations.find(ver);
        if (impl == mImplementations.end())
        {
            OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, "Cannot find serializer implementation for "
                "current version " + ver, "MeshSerializer::importMesh");
        }

        // Call implementation
        impl->second->importMesh(stream, pDest, mListener);
        // Warn on old version of mesh
        if (ver != msCurrentVersion)
        {
            LogManager::getSingleton().logMessage("WARNING: " + pDest->getName() + 
                " is an older format (" + ver + "); you should upgrade it as soon as possible" +
                " using the OgreMeshUpgrade tool.");
        }

    }
Пример #13
0
	//---------------------------------------------------------------------
	void StreamSerialiser::readHeader()
	{
		uint32 headerid;
		size_t actually_read = mStream->read(&headerid, sizeof(uint32));
		// skip back
		mStream->skip(0 - (long)actually_read);
		// validate that this is a header chunk
		if (headerid == REVERSE_HEADER_ID)
		{
			mFlipEndian = true;
		}
		else if (headerid == HEADER_ID)
		{
			mFlipEndian = false;
		}
		else
		{
			// no good
			OGRE_EXCEPT(Exception::ERR_INVALID_STATE, 
				"Cannot determine endian mode because header is missing", 
				"StreamSerialiser::readHeader");
		}
		determineEndianness();

		mReadWriteHeader = false;

		const Chunk* c = readChunkBegin();
		// endian should be flipped now
		assert(c->id == HEADER_ID);
        (void)c; // Silence warning

		// read real storage format
		bool realIsDouble;
		read(&realIsDouble);
		mRealFormat = realIsDouble? REAL_DOUBLE : REAL_FLOAT;

		readChunkEnd(HEADER_ID);

	}
Пример #14
0
void OgreMeshDeserializer::deserialize()
{

    // Determine endianness (must be the first thing we do!)
    determineEndianness(m_stream);

    // Check header
    readFileHeader(m_stream);

    unsigned short streamID = readChunk(m_stream);

    while (!m_stream.eof()) {
        switch (streamID) {
            case M_MESH:
                readMesh();
                break;
            default:
                skipChunk(m_stream);
        }

        streamID = readChunk(m_stream);
    }

}