xoreos  0.0.5
model_dragonage.h
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #ifndef GRAPHICS_AURORA_MODEL_DRAGONAGE_H
26 #define GRAPHICS_AURORA_MODEL_DRAGONAGE_H
27 
28 #include "glm/vec4.hpp"
29 
30 #include "src/aurora/types.h"
31 
34 
35 namespace Common {
36  class SeekableReadStream;
37 }
38 
39 namespace Graphics {
40 
41 namespace Aurora {
42 
43 class ModelNode_DragonAge;
44 
54 class Model_DragonAge : public Model {
55 public:
58 
59 private:
60  struct ParserContext {
63 
66 
69 
70  const ::Aurora::GFF4Struct *mmhTop;
71  const ::Aurora::GFF4Struct *mshTop;
72 
73  State *state;
74 
75  std::list<ModelNode_DragonAge *> nodes;
76 
77  ParserContext(const Common::UString &name);
79 
80  void open(const Common::UString &name);
81  void clear();
82  };
83 
84 
85  void newState(ParserContext &ctx);
86  void addState(ParserContext &ctx);
87 
88  void load(ParserContext &ctx);
89 
90  friend class ModelNode_DragonAge;
91 };
92 
94 public:
95  ModelNode_DragonAge(Model &model);
97 
98  void load(Model_DragonAge::ParserContext &ctx, const ::Aurora::GFF4Struct &nodeGFF);
99 
100 private:
102  enum MeshDeclUse {
117 
118  kMeshDeclUseUnused = 0xFFFFFFFF
119  };
120 
140 
141  kMeshDeclTypeUnused = 0xFFFFFFFF
142  };
143 
147  const ::Aurora::GFF4Struct *gff;
148 
151 
152  MeshDeclaration(MeshDeclUse u = kMeshDeclUseUnused, const ::Aurora::GFF4Struct *g = 0,
153  int32 o = -1, MeshDeclType t = kMeshDeclTypeUnused) :
154  use(u), gff(g), offset(o), type(t) {
155  }
156  };
157  typedef std::list<MeshDeclaration> MeshDeclarations;
158 
160  struct MaterialObject {
163 
164  std::map<Common::UString, float> floats;
165  std::map<Common::UString, glm::vec4> vectors;
166  std::map<Common::UString, Common::UString> textures;
167  };
168 
169  void readTransformation(const ::Aurora::GFF4Struct &nodeGFF);
170  void readChildren(Model_DragonAge::ParserContext &ctx, const ::Aurora::GFF4Struct &nodeGFF);
171 
172  void readMesh(Model_DragonAge::ParserContext &ctx, const ::Aurora::GFF4Struct &meshGFF);
173 
174  void sanityCheckMeshChunk(const ::Aurora::GFF4Struct &meshChunk);
175  void readMeshDecl(const ::Aurora::GFF4Struct &meshChunk, MeshDeclarations &meshDecl);
176 
177  void createIndexBuffer (const ::Aurora::GFF4Struct &meshChunk, Common::SeekableReadStream &indexData);
178  void createVertexBuffer(const ::Aurora::GFF4Struct &meshChunk, Common::SeekableReadStream &vertexData,
179  const MeshDeclarations &meshDecl);
180 
181  void readMAO(const Common::UString &materialName, MaterialObject &material);
182  void readMAOGFF(Common::SeekableReadStream *maoStream, MaterialObject &material);
183  void readMAOXML(Common::SeekableReadStream *maoStream, MaterialObject &material,
184  const Common::UString &fileName);
185 
186  void loadTextures(const std::vector<Common::UString> &textures, const MaterialObject &material);
187 
188  void fixTexturesAlpha(const std::vector<Common::UString> &textures);
189  void fixTexturesHair (const std::vector<Common::UString> &textures);
190 
191  static void read2Float32(Common::ReadStream &stream, MeshDeclType type, float *&f);
192  static void read3Float32(Common::ReadStream &stream, MeshDeclType type, float *&f);
193  static void read4Float32(Common::ReadStream &stream, MeshDeclType type, float *&f);
194 };
195 
196 } // End of namespace Aurora
197 
198 } // End of namespace Graphics
199 
200 #endif // GRAPHICS_AURORA_MODEL_DRAGONAGE_H
void addState(ParserContext &ctx)
std::list< MeshDeclaration > MeshDeclarations
void readMAO(const Common::UString &materialName, MaterialObject &material)
Read a material object MAO, which can be encoded in either XML or GFF.
static void read2Float32(Common::ReadStream &stream, MeshDeclType type, float *&f)
Generic interface for a readable data stream.
Definition: readstream.h:64
Definition: 2dafile.h:39
A class holding an UTF-8 string.
Definition: ustring.h:48
std::map< Common::UString, glm::vec4 > vectors
void readMAOGFF(Common::SeekableReadStream *maoStream, MaterialObject &material)
Read a MAO encoded in a GFF file.
Model_DragonAge(const Common::UString &name, ModelType type=kModelTypeObject)
A real object in the game world.
Definition: types.h:52
4 unsigned integers of 10-bit, 10-bit, 10-bit, 2-bit.
A 3D model in the Dragon Age MMH+MSH format.
A GFF (generic file format) V4.0/V4.1 file, found in Dragon Age: Origins, Dragon Age 2 and Sonic Chro...
Definition: gff4file.h:93
void readTransformation(const ::Aurora::GFF4Struct &nodeGFF)
static void read4Float32(Common::ReadStream &stream, MeshDeclType type, float *&f)
ModelType
The display type of a model.
Definition: types.h:51
MeshDeclaration(MeshDeclUse u=kMeshDeclUseUnused, const ::Aurora::GFF4Struct *g=0, int32 o=-1, MeshDeclType t=kMeshDeclTypeUnused)
void loadTextures(const std::vector< Common::UString > &textures, const MaterialObject &material)
std::map< Common::UString, Common::UString > textures
void sanityCheckMeshChunk(const ::Aurora::GFF4Struct &meshChunk)
static void read3Float32(Common::ReadStream &stream, MeshDeclType type, float *&f)
A node within a 3D model.
A 3D model of an object.
MeshDeclUse
Usage information for a mesh declaration part.
void readMeshDecl(const ::Aurora::GFF4Struct &meshChunk, MeshDeclarations &meshDecl)
MeshDeclType
Type information for a mesh declaration part.
Basic type definitions to handle files used in BioWare&#39;s Aurora engine.
void newState(ParserContext &ctx)
void fixTexturesAlpha(const std::vector< Common::UString > &textures)
void readChildren(Model_DragonAge::ParserContext &ctx, const ::Aurora::GFF4Struct &nodeGFF)
void createVertexBuffer(const ::Aurora::GFF4Struct &meshChunk, Common::SeekableReadStream &vertexData, const MeshDeclarations &meshDecl)
void fixTexturesHair(const std::vector< Common::UString > &textures)
void createIndexBuffer(const ::Aurora::GFF4Struct &meshChunk, Common::SeekableReadStream &indexData)
void readMesh(Model_DragonAge::ParserContext &ctx, const ::Aurora::GFF4Struct &meshGFF)
void readMAOXML(Common::SeekableReadStream *maoStream, MaterialObject &material, const Common::UString &fileName)
Read a MAO encoded in an XML file.
std::list< ModelNode_DragonAge * > nodes
Interface for a seekable & readable data stream.
Definition: readstream.h:265
4 normalized unsigned integers of 10-bit, 10-bit, 10-bit, 2-bit.
void load(Model_DragonAge::ParserContext &ctx, const ::Aurora::GFF4Struct &nodeGFF)
int32_t int32
Definition: types.h:203