00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://www.ogre3d.org/ 00006 00007 Copyright © 2000-2002 The OGRE Team 00008 Also see acknowledgements in Readme.html 00009 00010 This program is free software; you can redistribute it and/or modify it under 00011 the terms of the GNU Lesser General Public License as published by the Free Software 00012 Foundation; either version 2 of the License, or (at your option) any later 00013 version. 00014 00015 This program is distributed in the hope that it will be useful, but WITHOUT 00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License along with 00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple 00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to 00022 http://www.gnu.org/copyleft/lesser.txt. 00023 ----------------------------------------------------------------------------- 00024 */ 00025 #include "OgreStableHeaders.h" 00026 00027 #include "OgreMeshSerializer.h" 00028 #include "OgreMeshFileFormat.h" 00029 #include "OgreMesh.h" 00030 #include "OgreSubMesh.h" 00031 #include "OgreException.h" 00032 #include "OgreMaterialManager.h" 00033 #include "OgreLogManager.h" 00034 #include "OgreSkeleton.h" 00035 00036 namespace Ogre { 00037 00038 String MeshSerializer::msCurrentVersion = "[MeshSerializer_v1.30]"; 00039 const unsigned short HEADER_CHUNK_ID = 0x1000; 00040 //--------------------------------------------------------------------- 00041 MeshSerializer::MeshSerializer() 00042 { 00043 // Set up map 00044 mImplementations.insert( 00045 MeshSerializerImplMap::value_type("[MeshSerializer_v1.10]", 00046 new MeshSerializerImpl_v1_1() ) ); 00047 00048 mImplementations.insert( 00049 MeshSerializerImplMap::value_type("[MeshSerializer_v1.20]", 00050 new MeshSerializerImpl_v1_2() ) ); 00051 00052 mImplementations.insert( 00053 MeshSerializerImplMap::value_type(msCurrentVersion, 00054 new MeshSerializerImpl() ) ); 00055 } 00056 //--------------------------------------------------------------------- 00057 MeshSerializer::~MeshSerializer() 00058 { 00059 // delete map 00060 for (MeshSerializerImplMap::iterator i = mImplementations.begin(); 00061 i != mImplementations.end(); ++i) 00062 { 00063 delete i->second; 00064 } 00065 mImplementations.clear(); 00066 00067 } 00068 //--------------------------------------------------------------------- 00069 void MeshSerializer::exportMesh(const Mesh* pMesh, const String& filename) 00070 { 00071 MeshSerializerImplMap::iterator impl = mImplementations.find(msCurrentVersion); 00072 if (impl == mImplementations.end()) 00073 { 00074 Except(Exception::ERR_INTERNAL_ERROR, "Cannot find serializer implementation for " 00075 "current version " + msCurrentVersion, "MeshSerializer::exportMesh"); 00076 } 00077 00078 impl->second->exportMesh(pMesh, filename); 00079 } 00080 //--------------------------------------------------------------------- 00081 void MeshSerializer::importMesh(DataChunk& chunk, Mesh* pDest) 00082 { 00083 // Read header and determine the version 00084 unsigned short headerID; 00085 00086 // Read header ID 00087 readShorts(chunk, &headerID, 1); 00088 00089 if (headerID != HEADER_CHUNK_ID) 00090 { 00091 Except(Exception::ERR_INTERNAL_ERROR, "File header not found", 00092 "MeshSerializer::importMesh"); 00093 } 00094 // Read version 00095 String ver = readString(chunk); 00096 // Jump back to start 00097 chunk.seek(0); 00098 00099 // Find the implementation to use 00100 MeshSerializerImplMap::iterator impl = mImplementations.find(ver); 00101 if (impl == mImplementations.end()) 00102 { 00103 Except(Exception::ERR_INTERNAL_ERROR, "Cannot find serializer implementation for " 00104 "current version " + ver, "MeshSerializer::importMesh"); 00105 } 00106 00107 // Call implementation 00108 impl->second->importMesh(chunk, pDest); 00109 // Warn on old version of mesh 00110 if (ver != msCurrentVersion) 00111 { 00112 LogManager::getSingleton().logMessage("WARNING: " + pDest->getName() + 00113 " is an older format (" + ver + "); you should upgrade it as soon as possible" + 00114 " using the OgreMeshUpgrade tool."); 00115 } 00116 00117 } 00118 //--------------------------------------------------------------------- 00119 00120 } 00121
Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:35 2004