xoreos  0.0.5
model_nwn.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_NWN_H
26 #define GRAPHICS_AURORA_MODEL_NWN_H
27 
30 
31 namespace Common {
32  class SeekableReadStream;
33  class StreamTokenizer;
34 }
35 
36 namespace Graphics {
37 
38 namespace Aurora {
39 
40 class ModelNode_NWN_Binary;
41 class ModelNode_NWN_ASCII;
42 
44 class Model_NWN : public Model {
45 public:
47  const Common::UString &texture = "", ModelCache *modelCache = 0);
48  ~Model_NWN();
49 
50 private:
51  struct ParserContext {
53 
55 
56  State *state;
57 
58  bool isASCII;
59 
60  std::list<ModelNode *> nodes;
61 
63 
66 
69 
71  std::vector<uint32> anims;
72 
73  ParserContext(const Common::UString &name, const Common::UString &t);
75 
76  bool findNode(const Common::UString &name, ModelNode *&node) const;
77 
78  void clear();
79  };
80 
81 
82  void newState(ParserContext &ctx);
83  void addState(ParserContext &ctx);
84 
85  void loadBinary(ParserContext &ctx);
86  void readAnimBinary(ParserContext &ctx, uint32 offset);
87 
88  void loadASCII(ParserContext &ctx);
89  void readAnimASCII(ParserContext &ctx);
90  void skipAnimASCII(ParserContext &ctx);
91 
92  void loadSuperModel(ModelCache *modelCache);
93 
95 
96  friend class ModelNode_NWN_Binary;
97  friend class ModelNode_NWN_ASCII;
98 };
99 
101 public:
102  ModelNode_NWN_Binary(Model &model);
104 
105  void load(Model_NWN::ParserContext &ctx);
106 
108 
109 private:
111 
114 
116  uint32 count, std::vector<float> &data);
117 };
118 
120 public:
121  ModelNode_NWN_ASCII(Model &model);
123 
124  void load(Model_NWN::ParserContext &ctx,
125  const Common::UString &type, const Common::UString &name);
126 
127 private:
128  struct Mesh {
132 
133  std::vector<Common::UString> textures;
134 
135  std::vector<float> vX, vY, vZ;
136  std::vector<float> tX, tY;
137 
138  std::vector<uint32> vIA, vIB, vIC;
139  std::vector<uint32> tIA, tIB, tIC;
140 
141  std::vector<uint32> smooth, mat;
142 
143  Mesh();
144  };
145 
148 
149  void readFloats(const std::vector<Common::UString> &strings,
150  float *floats, uint32 n, uint32 start);
151 
152  void readVCoords(Model_NWN::ParserContext &ctx, Mesh &mesh);
153  void readTCoords(Model_NWN::ParserContext &ctx, Mesh &mesh);
154 
155  void readFaces(Model_NWN::ParserContext &ctx, Mesh &mesh);
156 
158 };
159 
160 } // End of namespace Aurora
161 
162 } // End of namespace Graphics
163 
164 #endif // GRAPHICS_AURORA_MODEL_NWN_BINARY_H
Model_NWN(const Common::UString &name, ModelType type=kModelTypeObject, const Common::UString &texture="", ModelCache *modelCache=0)
Definition: model_nwn.cpp:184
void loadSuperModel(ModelCache *modelCache)
Definition: model_nwn.cpp:480
void loadBinary(ParserContext &ctx)
Definition: model_nwn.cpp:214
Definition: 2dafile.h:39
A class holding an UTF-8 string.
Definition: ustring.h:48
void readFaces(Model_NWN::ParserContext &ctx, Mesh &mesh)
Definition: model_nwn.cpp:1313
std::vector< Common::UString > textures
Definition: model_nwn.h:133
A 3D model in the NWN MDL format.
Definition: model_nwn.h:44
A real object in the game world.
Definition: types.h:52
Tokenizes a stream.
void readWeights(Model_NWN::ParserContext &ctx, uint32 n)
Definition: model_nwn.cpp:1241
void readConstraints(Model_NWN::ParserContext &ctx, uint32 n)
Definition: model_nwn.cpp:1225
void readAnimBinary(ParserContext &ctx, uint32 offset)
Definition: model_nwn.cpp:423
void processMesh(ModelNode_NWN_ASCII::Mesh &mesh)
Definition: model_nwn.cpp:1374
void readNodeControllers(Model_NWN::ParserContext &ctx, uint32 offset, uint32 count, std::vector< float > &data)
Definition: model_nwn.cpp:991
void load(Model_NWN::ParserContext &ctx, const Common::UString &type, const Common::UString &name)
Definition: model_nwn.cpp:1088
void readTCoords(Model_NWN::ParserContext &ctx, Mesh &mesh)
Definition: model_nwn.cpp:1291
void addState(ParserContext &ctx)
Definition: model_nwn.cpp:396
ModelType
The display type of a model.
Definition: types.h:51
void newState(ParserContext &ctx)
Definition: model_nwn.cpp:352
void readAnim(Model_NWN::ParserContext &ctx)
Definition: model_nwn.cpp:972
A node within a 3D model.
void load(Model_NWN::ParserContext &ctx)
Definition: model_nwn.cpp:547
A 3D model of an object.
void checkDuplicateNode(Model_NWN::ParserContext &ctx, ModelNode_NWN_Binary *newNode)
Definition: model_nwn.cpp:655
static Common::UString loadName(Model_NWN::ParserContext &ctx)
Definition: model_nwn.cpp:535
std::list< ModelNode * > nodes
Definition: model_nwn.h:60
Common::StreamTokenizer * tokenize
Definition: model_nwn.h:70
ParserContext(const Common::UString &name, const Common::UString &t)
Definition: model_nwn.cpp:126
void readMesh(Model_NWN::ParserContext &ctx)
Definition: model_nwn.cpp:703
void readVCoords(Model_NWN::ParserContext &ctx, Mesh &mesh)
Definition: model_nwn.cpp:1267
bool findNode(const Common::UString &name, ModelNode *&node) const
Definition: model_nwn.cpp:163
void skipAnimASCII(ParserContext &ctx)
Definition: model_nwn.cpp:360
void loadASCII(ParserContext &ctx)
Definition: model_nwn.cpp:287
uint32_t uint32
Definition: types.h:204
void readFloats(const std::vector< Common::UString > &strings, float *floats, uint32 n, uint32 start)
Definition: model_nwn.cpp:1257
void readAnimASCII(ParserContext &ctx)
Definition: model_nwn.cpp:386
Interface for a seekable & readable data stream.
Definition: readstream.h:265
Common::SeekableReadStream * mdl
Definition: model_nwn.h:52