//--------------------------------------------------------------------- void MeshSerializer::exportMesh(const Mesh* pMesh, DataStreamPtr stream, MeshVersion version, Endian endianMode) { MeshSerializerImpl* impl = 0; if (version == MESH_VERSION_LATEST) impl = mVersionData[0]->impl; else { for (MeshVersionDataList::iterator i = mVersionData.begin(); i != mVersionData.end(); ++i) { if (version == (*i)->version) { impl = (*i)->impl; break; } } } if (!impl) { OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, "Cannot find serializer implementation for " "specified version", "MeshSerializer::exportMesh"); } impl->exportMesh(pMesh, stream, endianMode); }
//--------------------------------------------------------------------- void MeshSerializer::exportMesh(const Mesh* pMesh, DataStreamPtr stream, MeshVersion version, Endian endianMode) { if (version == MESH_VERSION_LEGACY) OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "You may not supply a legacy version number (pre v1.0) for writing meshes.", "MeshSerializer::exportMesh"); MeshSerializerImpl* impl = 0; if (version == MESH_VERSION_LATEST) impl = mVersionData[0]->impl; else { for (MeshVersionDataList::iterator i = mVersionData.begin(); i != mVersionData.end(); ++i) { if (version == (*i)->version) { impl = (*i)->impl; break; } } } if (!impl) OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, "Cannot find serializer implementation for " "specified version", "MeshSerializer::exportMesh"); impl->exportMesh(pMesh, stream, endianMode); }
//--------------------------------------------------------------------- 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); }