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

Revision 692, 4.6 KB checked in by mattausch, 19 years ago (diff)

adding ogre 1.2 and dependencies

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 "OgreLogManager.h"
33#include "OgreSkeleton.h"
34
35namespace Ogre {
36
37    String MeshSerializer::msCurrentVersion = "[MeshSerializer_v1.30]";
38    const unsigned short HEADER_CHUNK_ID = 0x1000;
39    //---------------------------------------------------------------------
40    MeshSerializer::MeshSerializer()
41    {
42        // Set up map
43        mImplementations.insert(
44            MeshSerializerImplMap::value_type("[MeshSerializer_v1.10]",
45            new MeshSerializerImpl_v1_1() ) );
46
47        mImplementations.insert(
48            MeshSerializerImplMap::value_type("[MeshSerializer_v1.20]",
49            new MeshSerializerImpl_v1_2() ) );
50
51        mImplementations.insert(
52            MeshSerializerImplMap::value_type(msCurrentVersion,
53            new MeshSerializerImpl() ) );
54    }
55    //---------------------------------------------------------------------
56    MeshSerializer::~MeshSerializer()
57    {
58        // delete map
59        for (MeshSerializerImplMap::iterator i = mImplementations.begin();
60            i != mImplementations.end(); ++i)
61        {
62            delete i->second;
63        }
64        mImplementations.clear();
65
66    }
67    //---------------------------------------------------------------------
68    void MeshSerializer::exportMesh(const Mesh* pMesh, const String& filename,
69                Endian endianMode)
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, endianMode);
79    }
80    //---------------------------------------------------------------------
81    void MeshSerializer::importMesh(DataStreamPtr& stream, Mesh* pDest)
82    {
83        determineEndianness(stream);
84
85        // Read header and determine the version
86        unsigned short headerID;
87       
88        // Read header ID
89        readShorts(stream, &headerID, 1);
90       
91        if (headerID != HEADER_CHUNK_ID)
92        {
93            OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, "File header not found",
94                "MeshSerializer::importMesh");
95        }
96        // Read version
97        String ver = readString(stream);
98        // Jump back to start
99        stream->seek(0);
100
101        // Find the implementation to use
102        MeshSerializerImplMap::iterator impl = mImplementations.find(ver);
103        if (impl == mImplementations.end())
104        {
105            OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, "Cannot find serializer implementation for "
106                "current version " + ver, "MeshSerializer::importMesh");
107        }
108
109        // Call implementation
110        impl->second->importMesh(stream, pDest);
111        // Warn on old version of mesh
112        if (ver != msCurrentVersion)
113        {
114            LogManager::getSingleton().logMessage("WARNING: " + pDest->getName() +
115                " is an older format (" + ver + "); you should upgrade it as soon as possible" +
116                " using the OgreMeshUpgrade tool.");
117        }
118
119    }
120    //---------------------------------------------------------------------
121
122}
123
Note: See TracBrowser for help on using the repository browser.