Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/ogre/OgreMain/src/OgreMeshSerializer.cpp @ 45

Last change on this file since 45 was 5, checked in by anonymous, 17 years ago

=hoffentlich gehts jetzt

File size: 4.8 KB
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-2006 Torus Knot Software Ltd
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
24You may alternatively use this source under the terms of a specific version of
25the OGRE Unrestricted License provided you have obtained such a license from
26Torus Knot Software Ltd.
27-----------------------------------------------------------------------------
28*/
29#include "OgreStableHeaders.h"
30
31#include "OgreMeshSerializer.h"
32#include "OgreMeshFileFormat.h"
33#include "OgreMesh.h"
34#include "OgreSubMesh.h"
35#include "OgreException.h"
36#include "OgreLogManager.h"
37#include "OgreSkeleton.h"
38
39namespace Ogre {
40
41    String MeshSerializer::msCurrentVersion = "[MeshSerializer_v1.40]";
42    const unsigned short HEADER_CHUNK_ID = 0x1000;
43    //---------------------------------------------------------------------
44    MeshSerializer::MeshSerializer()
45    {
46        // Set up map
47        mImplementations.insert(
48            MeshSerializerImplMap::value_type("[MeshSerializer_v1.10]", 
49            new MeshSerializerImpl_v1_1() ) );
50
51        mImplementations.insert(
52            MeshSerializerImplMap::value_type("[MeshSerializer_v1.20]", 
53            new MeshSerializerImpl_v1_2() ) );
54
55        mImplementations.insert(
56            MeshSerializerImplMap::value_type("[MeshSerializer_v1.30]", 
57            new MeshSerializerImpl_v1_3() ) );
58
59        mImplementations.insert(
60            MeshSerializerImplMap::value_type(msCurrentVersion, 
61            new MeshSerializerImpl() ) );
62    }
63    //---------------------------------------------------------------------
64    MeshSerializer::~MeshSerializer()
65    {
66        // delete map
67        for (MeshSerializerImplMap::iterator i = mImplementations.begin();
68            i != mImplementations.end(); ++i)
69        {
70            delete i->second;
71        }
72        mImplementations.clear();
73
74    }
75    //---------------------------------------------------------------------
76    void MeshSerializer::exportMesh(const Mesh* pMesh, const String& filename,
77                Endian endianMode)
78    {
79        MeshSerializerImplMap::iterator impl = mImplementations.find(msCurrentVersion);
80        if (impl == mImplementations.end())
81        {
82            OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, "Cannot find serializer implementation for "
83                "current version " + msCurrentVersion, "MeshSerializer::exportMesh");
84        }
85
86        impl->second->exportMesh(pMesh, filename, endianMode);
87    }
88    //---------------------------------------------------------------------
89    void MeshSerializer::importMesh(DataStreamPtr& stream, Mesh* pDest)
90    {
91        determineEndianness(stream);
92
93        // Read header and determine the version
94        unsigned short headerID;
95       
96        // Read header ID
97        readShorts(stream, &headerID, 1);
98       
99        if (headerID != HEADER_CHUNK_ID)
100        {
101            OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, "File header not found",
102                "MeshSerializer::importMesh");
103        }
104        // Read version
105        String ver = readString(stream);
106        // Jump back to start
107        stream->seek(0);
108
109        // Find the implementation to use
110        MeshSerializerImplMap::iterator impl = mImplementations.find(ver);
111        if (impl == mImplementations.end())
112        {
113            OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, "Cannot find serializer implementation for "
114                "current version " + ver, "MeshSerializer::importMesh");
115        }
116
117        // Call implementation
118        impl->second->importMesh(stream, pDest);
119        // Warn on old version of mesh
120        if (ver != msCurrentVersion)
121        {
122            LogManager::getSingleton().logMessage("WARNING: " + pDest->getName() + 
123                " is an older format (" + ver + "); you should upgrade it as soon as possible" +
124                " using the OgreMeshUpgrade tool.");
125        }
126
127    }
128    //---------------------------------------------------------------------
129
130}
131
Note: See TracBrowser for help on using the repository browser.