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.20]"; 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.00]", 00046 new MeshSerializerImpl_v1() ) ); 00047 00048 mImplementations.insert( 00049 MeshSerializerImplMap::value_type("[MeshSerializer_v1.10]", 00050 new MeshSerializerImpl_v1_1() ) ); 00051 00052 // Format has not changed, but we need to tag because 'v' texture coordinate 00053 // has been inverted 00054 mImplementations.insert( 00055 MeshSerializerImplMap::value_type(msCurrentVersion, 00056 new MeshSerializerImpl() ) ); 00057 } 00058 //--------------------------------------------------------------------- 00059 MeshSerializer::~MeshSerializer() 00060 { 00061 // delete map 00062 for (MeshSerializerImplMap::iterator i = mImplementations.begin(); 00063 i != mImplementations.end(); ++i) 00064 { 00065 delete i->second; 00066 } 00067 mImplementations.clear(); 00068 00069 } 00070 //--------------------------------------------------------------------- 00071 void MeshSerializer::exportMesh(const Mesh* pMesh, const String& filename) 00072 { 00073 MeshSerializerImplMap::iterator impl = mImplementations.find(msCurrentVersion); 00074 if (impl == mImplementations.end()) 00075 { 00076 Except(Exception::ERR_INTERNAL_ERROR, "Cannot find serializer implementation for " 00077 "current version " + msCurrentVersion, "MeshSerializer::exportMesh"); 00078 } 00079 00080 impl->second->exportMesh(pMesh, filename); 00081 } 00082 //--------------------------------------------------------------------- 00083 void MeshSerializer::importMesh(DataChunk& chunk, Mesh* pDest) 00084 { 00085 // Read header and determine the version 00086 unsigned short headerID; 00087 00088 // Read header ID 00089 readShorts(chunk, &headerID, 1); 00090 00091 if (headerID != HEADER_CHUNK_ID) 00092 { 00093 Except(Exception::ERR_INTERNAL_ERROR, "File header not found", 00094 "MeshSerializer::importMesh"); 00095 } 00096 // Read version 00097 String ver = readString(chunk); 00098 // Jump back to start 00099 chunk.seek(0); 00100 00101 // Find the implementation to use 00102 MeshSerializerImplMap::iterator impl = mImplementations.find(ver); 00103 if (impl == mImplementations.end()) 00104 { 00105 Except(Exception::ERR_INTERNAL_ERROR, "Cannot find serializer implementation for " 00106 "current version " + ver, "MeshSerializer::importMesh"); 00107 } 00108 00109 // Call implementation 00110 impl->second->importMesh(chunk, pDest); 00111 // Warn on old version of mesh 00112 if (ver != msCurrentVersion) 00113 { 00114 LogManager::getSingleton().logMessage("WARNING: " + pDest->getName() + 00115 " is an older format (" + ver + "); you should upgrade it as soon as possible" + 00116 " using the OgreMeshUpgrade tool."); 00117 } 00118 00119 } 00120 //--------------------------------------------------------------------- 00121 00122 } 00123
Copyright © 2002-2003 by The OGRE Team
Last modified Fri May 14 23:22:26 2004