changed: gcc8 base update
[opensg.git] / Source / System / FileIO / Ogre / OSGOgreMeshReader.h
blobc3f04b64f6981ce2d23d1d98b577a24303bff8ad
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2010 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
18 * *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
23 * *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
27 * *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 #ifndef _OSGOGREMESHREADER_H_
40 #define _OSGOGREMESHREADER_H_
41 #ifdef __sgi
42 #pragma once
43 #endif
45 /*! \file OSGOgreMeshReader.h
46 \ingroup GrpLoader
49 #include "OSGConfig.h"
50 #include "OSGFileIODef.h"
51 #include "OSGOgreChunkReader.h"
52 #include "OSGOgreOptions.h"
53 #include "OSGGeometry.h"
54 #include "OSGGeoIntegralProperty.h"
55 #include "OSGGeoVectorProperty.h"
56 #include "OSGSkeleton.h"
58 OSG_BEGIN_NAMESPACE
60 class OSG_FILEIO_DLLMAPPING OgreMeshReader : public OgreChunkReader
62 /*========================== PUBLIC =================================*/
63 public:
64 /*---------------------------------------------------------------------*/
65 /*! \name Types */
66 /*! \{ */
68 typedef OgreChunkReader Inherited;
70 /*! \} */
71 /*---------------------------------------------------------------------*/
72 /*! \name Constructors/Destructor */
73 /*! \{ */
75 explicit OgreMeshReader( std::istream &is,
76 const OgreOptions &options);
77 virtual ~OgreMeshReader(void );
79 /*! \} */
80 /*---------------------------------------------------------------------*/
81 /*! \name Read */
82 /*! \{ */
84 Node* getRoot(void);
86 void read(void);
88 /*! \} */
89 /*========================= PROTECTED ===============================*/
90 protected:
91 enum ChunkIds
93 CHUNK_HEADER = 0x1000,
94 CHUNK_MESH = 0x3000,
96 CHUNK_SUBMESH = 0x4000,
97 CHUNK_SUBMESH_OPERATION = 0x4010,
98 CHUNK_SUBMESH_BONE_ASSIGNMENT = 0x4100,
99 CHUNK_SUBMESH_TEXTURE_ALIAS = 0x4200,
101 CHUNK_GEOMETRY = 0x5000,
102 CHUNK_GEOMETRY_VERTEX_DECLARATION = 0x5100,
103 CHUNK_GEOMETRY_VERTEX_ELEMENT = 0x5110,
104 CHUNK_GEOMETRY_VERTEX_BUFFER = 0x5200,
105 CHUNK_GEOMETRY_VERTEX_BUFFER_DATA = 0x5210,
107 CHUNK_MESH_SKELETON_LINK = 0x6000,
108 CHUNK_MESH_BONE_ASSIGNMENT = 0x7000,
109 CHUNK_MESH_LOD = 0x8000,
110 CHUNK_MESH_LOD_USAGE = 0x8100,
111 CHUNK_MESH_LOD_MANUAL = 0x8110,
112 CHUNK_MESH_LOD_GENERATED = 0x8120,
113 CHUNK_MESH_BOUNDS = 0x9000,
115 CHUNK_SUBMESH_NAME_TABLE = 0xA000,
116 CHUNK_SUBMESH_NAME_TABLE_ELEMENT = 0xA100,
118 CHUNK_EDGE_LISTS = 0xB000,
119 CHUNK_EDGE_LIST_LOD = 0xB100,
120 CHUNK_EDGE_GROUP = 0xB110,
122 CHUNK_POSES = 0xC000,
123 CHUNK_POSE = 0xC100,
124 CHUNK_POSE_VERTEX = 0xC111,
126 CHUNK_ANIMATIONS = 0xD000,
127 CHUNK_ANIMATION = 0xD100,
128 CHUNK_ANIMATION_TRACK = 0xD110,
129 CHUNK_ANIMATION_MORPH_KEYFRAME = 0xD111,
130 CHUNK_ANIMATION_POSE_KEYFRAME = 0xD112,
131 CHUNK_ANIMAITON_POSE_REF = 0xD113,
133 CHUNK_TABLE_EXTREMES = 0xE000,
136 enum VertexElementType
138 VET_FLOAT1 = 0,
139 VET_FLOAT2 = 1,
140 VET_FLOAT3 = 2,
141 VET_FLOAT4 = 3,
142 VET_COLOUR = 4,
143 VET_SHORT1 = 5,
144 VET_SHORT2 = 6,
145 VET_SHORT3 = 7,
146 VET_SHORT4 = 8,
147 VET_UBYTE4 = 9,
148 VET_COLOUR_ARGB = 10,
149 VET_COLOUR_ABGR = 11
152 enum VertexElementSemantic
154 VES_POSITION = 1,
155 VES_BLEND_WEIGHTS = 2,
156 VES_BLEND_INDICES = 3,
157 VES_NORMAL = 4,
158 VES_DIFFUSE = 5,
159 VES_SPECULAR = 6,
160 VES_TEXTURE_COORDINATES = 7,
161 VES_BINORMAL = 8,
162 VES_TANGENT = 9
165 enum SubMeshOperation
167 SMO_POINT_LIST = 1,
168 SMO_LINE_LIST = 2,
169 SMO_LINE_STRIP = 3,
170 SMO_TRIANGLE_LIST = 4,
171 SMO_TRIANGLE_STRIP = 5,
172 SMO_TRIANGLE_FAN = 6
175 struct VertexElement
177 UInt16 bufferIdx;
178 VertexElementType type;
179 VertexElementSemantic semantic;
180 UInt16 offset;
181 UInt16 index;
183 GeoVectorPropertyUnrecPtr prop;
185 VertexElement(void) :
186 bufferIdx(0 ),
187 type (VET_FLOAT3 ),
188 semantic (VES_POSITION),
189 offset (0 ),
190 index (0 ),
192 prop (NULL ) {}
196 typedef std::vector<VertexElement > VertexElementStore;
197 typedef std::vector<std::vector<UInt32> > BufferVertexMap;
199 struct SubMeshInfo
201 bool sharedVertex;
202 bool skelAnim;
203 VertexElementStore vertexElements;
204 SubMeshOperation meshOp;
205 std::string name;
206 std::string matName;
208 GeoIntegralPropertyUnrecPtr propIdx;
210 GeometryUnrecPtr mesh;
211 NodeUnrecPtr meshN;
213 SubMeshInfo(void) :
214 sharedVertex (false ),
215 skelAnim (false ),
216 vertexElements( ),
217 meshOp (SMO_TRIANGLE_LIST),
218 name ( ),
219 matName ( ),
221 propIdx (NULL ),
223 mesh (NULL ),
224 meshN (NULL ) {}
228 typedef std::vector<SubMeshInfo> SubMeshStore;
230 typedef std::map<std::string, MaterialUnrecPtr> MaterialMap;
232 std::string getVertexElementTypeString (VertexElementType veType );
233 std::string getVertexElementSemanticString(VertexElementSemantic veSemantic);
234 std::string getSubMeshOperationString (SubMeshOperation meshOp );
237 void readMesh (void);
238 void readSubMesh (SubMeshStore &subMeshInfo,
239 VertexElementStore &sharedVertexElements,
240 bool skelAnim );
242 void readSubMeshOperation (SubMeshInfo &smInfo );
243 void readSubMeshBoneAssignment (SubMeshInfo &smInfo,
244 Int16 &boneIdxVE,
245 Int16 &boneWeightVE );
246 void readSubMeshTextureAlias (void);
247 void readGeometry (VertexElementStore &vertexElements );
248 void readGeometryVertexDeclaration(VertexElementStore &vertexElements,
249 BufferVertexMap &bufferMap );
250 void readGeometryVertexElement (VertexElementStore &vertexElements,
251 BufferVertexMap &bufferMap );
252 void readGeometryVertexBuffer (UInt32 vertCount,
253 VertexElementStore &vertexElements,
254 BufferVertexMap &bufferMap );
255 void readGeometryVertexBufferData (UInt32 vertCount,
256 UInt16 bindIdx,
257 VertexElementStore &vertexElements,
258 BufferVertexMap &bufferMap );
260 void readMeshSkeletonLink (SubMeshStore &subMeshInfo );
261 void readMeshBoneAssignment (VertexElementStore &vertexElements,
262 Int16 &boneIdxVE,
263 Int16 &boneWeightVE );
264 void readMeshLOD (void);
265 void readMeshLODUsage (void);
266 void readMeshLODManual (void);
267 void readMeshLODGenerated (void);
268 void readMeshBounds (void);
269 void readSubMeshNameTable (SubMeshStore &subMeshInfo );
270 void readSubMeshNameTableElement (SubMeshStore &subMeshInfo );
271 void readEdgeLists (void);
272 void readPoses (void);
273 void readAnimations (void);
274 void readTableExtremes (void);
276 void readBoneAssignment (VertexElementStore &vertexElements,
277 Int16 &boneIdxVE,
278 Int16 &boneWeightVE );
279 void verifyBoneAssignment (VertexElementStore &vertexElements,
280 Int16 &boneIdxVE,
281 Int16 &boneWeightVE );
283 void constructSubMesh (SubMeshInfo &smInfo,
284 VertexElementStore &vertexElements );
285 void constructMaterial (SubMeshInfo &smInfo );
287 static const std::string _versionString;
289 const OgreOptions &_options;
291 MaterialMap _matMap;
293 NodeUnrecPtr _rootN;
294 SkeletonUnrecPtr _skel;
297 OSG_END_NAMESPACE
299 #endif // _OSGOGREMESHREADER_H_