Coverage Report

Created: 2026-01-17 06:50

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ogre/OgreMain/include/OgreMeshSerializer.h
Line
Count
Source
1
/*
2
-----------------------------------------------------------------------------
3
This source file is part of OGRE
4
    (Object-oriented Graphics Rendering Engine)
5
For the latest info, see http://www.ogre3d.org/
6
7
Copyright (c) 2000-2014 Torus Knot Software Ltd
8
9
Permission is hereby granted, free of charge, to any person obtaining a copy
10
of this software and associated documentation files (the "Software"), to deal
11
in the Software without restriction, including without limitation the rights
12
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
copies of the Software, and to permit persons to whom the Software is
14
furnished to do so, subject to the following conditions:
15
16
The above copyright notice and this permission notice shall be included in
17
all copies or substantial portions of the Software.
18
19
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
THE SOFTWARE.
26
-----------------------------------------------------------------------------
27
*/
28
29
#ifndef __MeshSerializer_H__
30
#define __MeshSerializer_H__
31
32
#include "OgrePrerequisites.h"
33
#include "OgreSerializer.h"
34
#include "OgreHeaderPrefix.h"
35
36
namespace Ogre {
37
    
38
    class MeshSerializerListener;
39
    class MeshVersionData;
40
    
41
    /// Mesh compatibility versions
42
    enum MeshVersion 
43
    {
44
        /// Latest version available
45
        MESH_VERSION_LATEST,
46
        
47
        /// OGRE version v1.10+
48
        MESH_VERSION_1_10,
49
        /// OGRE version v1.8+
50
        MESH_VERSION_1_8,
51
        /// OGRE version v1.7+
52
        MESH_VERSION_1_7,
53
        /// OGRE version v1.4+
54
        MESH_VERSION_1_4,
55
        /// OGRE version v1.0+
56
        MESH_VERSION_1_0,
57
        
58
        /// Legacy versions, DO NOT USE for writing
59
        MESH_VERSION_LEGACY
60
    };
61
62
    /** \addtogroup Core
63
    *  @{
64
    */
65
    /** \addtogroup Resources
66
    *  @{
67
    */
68
    /** Class for serialising mesh data to/from an OGRE .mesh file.
69
70
        This class allows exporters to write OGRE .mesh files easily, and allows the
71
        OGRE engine to import .mesh files into instantiated OGRE Meshes.
72
        Note that a .mesh file can include not only the Mesh, but also definitions of
73
        any Materials it uses (although this is optional, the .mesh can rely on the
74
        Material being loaded from another source, especially useful if you want to
75
        take advantage of OGRE's advanced Material properties which may not be available
76
        in your modeller).
77
    @par
78
        To export a Mesh:<OL>
79
        <LI>Use the MaterialManager methods to create any dependent Material objects, if you want
80
            to export them with the Mesh.</LI>
81
        <LI>Create a Mesh object and populate it using it's methods.</LI>
82
        <LI>Call the exportMesh method</LI>
83
        </OL>
84
    @par
85
        It's important to realise that this exporter uses OGRE terminology. In this context,
86
        'Mesh' means a top-level mesh structure which can actually contain many SubMeshes, each
87
        of which has only one Material. Modelling packages may refer to these differently, for
88
        example in Milkshape, it says 'Model' instead of 'Mesh' and 'Mesh' instead of 'SubMesh', 
89
        but the theory is the same.
90
    */
91
    class _OgreExport MeshSerializer : public Serializer
92
    {
93
    public:
94
        MeshSerializer();
95
        virtual ~MeshSerializer();
96
97
        /** Exports a mesh to the file specified, in a specific version format. 
98
99
         This method takes an externally created Mesh object, and exports it
100
         to a .mesh file in the specified format version. Note that picking a
101
         format version other that the latest will cause some information to be
102
         lost.
103
         @param pMesh Pointer to the Mesh to export
104
         @param filename The destination filename
105
         @param version Mesh version to write
106
         @param endianMode The endian mode of the written file
107
         */
108
        void exportMesh(const Mesh* pMesh, const String& filename, MeshVersion version,
109
                        Endian endianMode = ENDIAN_NATIVE);
110
111
        /// @overload
112
        void exportMesh(const Mesh* pMesh, const String& filename, Endian endianMode = ENDIAN_NATIVE)
113
0
        {
114
0
            exportMesh(pMesh, filename, MESH_VERSION_LATEST, endianMode);
115
0
        }
116
117
        /// @overload
118
        void exportMesh(const MeshPtr& pMesh, const String& filename, Endian endianMode = ENDIAN_NATIVE)
119
0
        {
120
0
            exportMesh(pMesh.get(), filename, MESH_VERSION_LATEST, endianMode);
121
0
        }
122
123
        /// @overload
124
        void exportMesh(const Mesh* pMesh, const DataStreamPtr& stream, Endian endianMode = ENDIAN_NATIVE)
125
0
        {
126
0
            exportMesh(pMesh, stream, MESH_VERSION_LATEST, endianMode);
127
0
        }
128
129
        /// @overload
130
        void exportMesh(const Mesh* pMesh, DataStreamPtr stream, MeshVersion version,
131
                        Endian endianMode = ENDIAN_NATIVE);
132
133
        /** Imports Mesh and (optionally) Material data from a .mesh file DataStream.
134
135
            This method imports data from a DataStream opened from a .mesh file and places it's
136
            contents into the Mesh object which is passed in. 
137
        @param stream The DataStream holding the .mesh data. Must be initialised (pos at the start of the buffer).
138
        @param pDest Pointer to the Mesh object which will receive the data. Should be blank already.
139
        */
140
        void importMesh(const DataStreamPtr& stream, Mesh* pDest);
141
142
        /// Sets the listener for this serializer
143
        void setListener(MeshSerializerListener *listener);
144
        /// Returns the current listener
145
        MeshSerializerListener *getListener();
146
        
147
    private:
148
        typedef std::vector<MeshVersionData*> MeshVersionDataList;
149
        MeshVersionDataList mVersionData;
150
151
        MeshSerializerListener *mListener;
152
153
    };
154
155
    /** 
156
157
        This class allows users to hook into the mesh loading process and
158
        modify references within the mesh as they are loading. Material and
159
        skeletal references can be processed using this interface which allows
160
        finer control over resources.
161
    */
162
    class MeshSerializerListener
163
    {
164
    public:
165
0
        virtual ~MeshSerializerListener() {}
166
        /// Called to override the loading of the given named material
167
        virtual void processMaterialName(Mesh *mesh, String *name) = 0;
168
        /// Called to override the reference to a skeleton
169
        virtual void processSkeletonName(Mesh *mesh, String *name) = 0;
170
        /// Allows to do changes on mesh after it's completely loaded. For example you can generate LOD levels here.
171
        virtual void processMeshCompleted(Mesh *mesh) = 0;
172
    };
173
    /** @} */
174
    /** @} */
175
}
176
177
#include "OgreHeaderSuffix.h"
178
179
#endif