source: OGRE/trunk/ogrenew/OgreMain/src/OgreMeshSerializer.cpp @ 690

Revision 690, 4.5 KB checked in by mattausch, 18 years ago (diff)

added ogre 1.07 main

Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2005 The OGRE Team
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23-----------------------------------------------------------------------------
24*/
25#include "OgreStableHeaders.h"
26
27#include "OgreMeshSerializer.h"
28#include "OgreMeshFileFormat.h"
29#include "OgreMesh.h"
30#include "OgreSubMesh.h"
31#include "OgreException.h"
32#include "OgreMaterialManager.h"
33#include "OgreLogManager.h"
34#include "OgreSkeleton.h"
35
36namespace Ogre {
37
38    String MeshSerializer::msCurrentVersion = "[MeshSerializer_v1.30]";
39    const unsigned short HEADER_CHUNK_ID = 0x1000;
40    //---------------------------------------------------------------------
41    MeshSerializer::MeshSerializer()
42    {
43        // Set up map
44        mImplementations.insert(
45            MeshSerializerImplMap::value_type("[MeshSerializer_v1.10]",
46            new MeshSerializerImpl_v1_1() ) );
47
48        mImplementations.insert(
49            MeshSerializerImplMap::value_type("[MeshSerializer_v1.20]",
50            new MeshSerializerImpl_v1_2() ) );
51
52        mImplementations.insert(
53            MeshSerializerImplMap::value_type(msCurrentVersion,
54            new MeshSerializerImpl() ) );
55    }
56    //---------------------------------------------------------------------
57    MeshSerializer::~MeshSerializer()
58    {
59        // delete map
60        for (MeshSerializerImplMap::iterator i = mImplementations.begin();
61            i != mImplementations.end(); ++i)
62        {
63            delete i->second;
64        }
65        mImplementations.clear();
66
67    }
68    //---------------------------------------------------------------------
69    void MeshSerializer::exportMesh(const Mesh* pMesh, const String& filename)
70    {
71        MeshSerializerImplMap::iterator impl = mImplementations.find(msCurrentVersion);
72        if (impl == mImplementations.end())
73        {
74            OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, "Cannot find serializer implementation for "
75                "current version " + msCurrentVersion, "MeshSerializer::exportMesh");
76        }
77
78        impl->second->exportMesh(pMesh, filename);
79    }
80    //---------------------------------------------------------------------
81    void MeshSerializer::importMesh(DataStreamPtr& stream, Mesh* pDest)
82    {
83        // Read header and determine the version
84        unsigned short headerID;
85       
86        // Read header ID
87        readShorts(stream, &headerID, 1);
88       
89        if (headerID != HEADER_CHUNK_ID)
90        {
91            OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, "File header not found",
92                "MeshSerializer::importMesh");
93        }
94        // Read version
95        String ver = readString(stream);
96        // Jump back to start
97        stream->seek(0);
98
99        // Find the implementation to use
100        MeshSerializerImplMap::iterator impl = mImplementations.find(ver);
101        if (impl == mImplementations.end())
102        {
103            OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, "Cannot find serializer implementation for "
104                "current version " + ver, "MeshSerializer::importMesh");
105        }
106
107        // Call implementation
108        impl->second->importMesh(stream, pDest);
109        // Warn on old version of mesh
110        if (ver != msCurrentVersion)
111        {
112            LogManager::getSingleton().logMessage("WARNING: " + pDest->getName() +
113                " is an older format (" + ver + "); you should upgrade it as soon as possible" +
114                " using the OgreMeshUpgrade tool.");
115        }
116
117    }
118    //---------------------------------------------------------------------
119
120}
121
Note: See TracBrowser for help on using the repository browser.