ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

model.h

Go to the documentation of this file.
00001 /* ResidualVM - A 3D game interpreter
00002  *
00003  * ResidualVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #ifndef GRIM_MODEL_H
00024 #define GRIM_MODEL_H
00025 
00026 #include "engines/grim/object.h"
00027 #include "math/matrix4.h"
00028 #include "math/quat.h"
00029 
00030 namespace Common {
00031 class SeekableReadStream;
00032 }
00033 
00034 namespace Grim {
00035 
00036 class TextSplitter;
00037 class Material;
00038 class Mesh;
00039 class ModelNode;
00040 class CMap;
00041 class Sprite;
00042 
00043 class Model : public Object {
00044 public:
00045     // Construct a 3D model from the given data.
00046     Model(const Common::String &filename, Common::SeekableReadStream *data, CMap *cmap, Model *parent = NULL);
00047 
00048     void reload(CMap *cmap);
00049     void draw() const;
00050     Material *findMaterial(const char *name, CMap *cmap) const;
00051 
00052     ~Model();
00053     const Common::String &getFilename() const { return _fname; }
00054     const ObjectPtr<CMap> &getCMap() const { return _cmap; }
00055 
00056     ModelNode *getHierarchy() const;
00057     int getNumNodes() const { return _numHierNodes; }
00058 
00059     struct Geoset {
00060         void loadBinary(Common::SeekableReadStream *data, Material *materials[]);
00061         void loadText(TextSplitter *ts, Material *materials[]);
00062         void changeMaterials(Material *materials[]);
00063         Geoset() : _numMeshes(0), _meshes(NULL) { }
00064         ~Geoset();
00065 
00066         int _numMeshes;
00067         Mesh *_meshes;
00068     };
00069 
00070 //private:
00071     void loadMaterial(int index, CMap *cmap);
00072     void loadBinary(Common::SeekableReadStream *data);
00073     void loadText(TextSplitter *ts);
00074 
00075     Common::String _fname;
00076     ObjectPtr<CMap> _cmap;
00077     Model *_parent;
00078     int _numMaterials;
00079     char (*_materialNames)[32];
00080     Material **_materials;
00081     bool *_materialsShared;
00082     Math::Vector3d _insertOffset;
00083     int _numGeosets;
00084     Geoset *_geosets;
00085     float _radius;
00086     int _numHierNodes;
00087     ModelNode *_rootHierNode;
00088     Math::Vector3d _bboxPos;
00089     Math::Vector3d _bboxSize;
00090 };
00091 
00092 class MeshFace {
00093 public:
00094     MeshFace();
00095     ~MeshFace();
00096     void stealData(MeshFace &other);
00097     int loadBinary(Common::SeekableReadStream *data, Material *materials[]);
00098     int loadText(TextSplitter *ts, Material *materials[], int offset);
00099     void draw(const Mesh *mesh) const;
00100     void changeMaterial(Material *material);
00101 
00102     bool hasTexture() const { return _texVertices != nullptr; }
00103 
00104     const Math::Vector3d &getNormal() const { return _normal; }
00105     void setNormal(const Math::Vector3d &normal) { _normal = normal; }
00106     const Material *getMaterial() const { return _material; }
00107     int getNumVertices() const { return _numVertices; }
00108     int getVertex(int i) const { return _vertices[i]; }
00109     int getTextureVertex(int i) const { return _texVertices[i]; }
00110     int getLight() const { return _light; }
00111 
00112 private:
00113     Material *_material;
00114     int _type, _geo, _light, _tex;
00115     float _extraLight;
00116     int _numVertices;
00117     int *_vertices, *_texVertices;
00118     Math::Vector3d _normal;
00119 
00120 public:
00121     void *_userData;
00122 };
00123 
00124 class Mesh {
00125 public:
00126     void loadBinary(Common::SeekableReadStream *data, Material *materials[]);
00127     void loadText(TextSplitter *ts, Material *materials[]);
00128     void changeMaterials(Material *materials[]);
00129     void draw() const;
00130     void getBoundingBox(int *x1, int *y1, int *x2, int *y2) const;
00131     void update();
00132     Mesh();
00133     ~Mesh();
00134 
00135     char _name[32];
00136     float _radius;
00137     int _shadow, _geometryMode, _lightingMode, _textureMode;
00138 
00139     int _numVertices;
00140     int *_materialid;
00141     float *_vertices;       // sets of 3
00142     float *_verticesI;
00143     float *_vertNormals;    // sets of 3
00144 
00145     int _numTextureVerts;
00146     float *_textureVerts;   // sets of 2
00147 
00148     int _numFaces;
00149     MeshFace *_faces;
00150     Math::Matrix4 _matrix;
00151 
00152     void *_userData;
00153 
00154 private:
00155     void sortFaces();
00156 };
00157 
00158 class ModelNode {
00159 public:
00160     ModelNode();
00161     ~ModelNode();
00162     void loadBinary(Common::SeekableReadStream *data, ModelNode *hierNodes, const Model::Geoset *g);
00163     void draw() const;
00164     void getBoundingBox(int *x1, int *y1, int *x2, int *y2) const;
00165     void addChild(ModelNode *child);
00166     void removeChild(ModelNode *child);
00167     void setMatrix(const Math::Matrix4 &matrix);
00168     void update();
00169     void addSprite(Sprite *sprite);
00170     void removeSprite(const Sprite *sprite);
00171     void translateViewpoint() const;
00172     void translateViewpointStart() const;
00173     void translateViewpointFinish() const;
00174 
00175     char _name[64];
00176     Mesh *_mesh;
00182     int _flags;
00188     int _type;
00189     int _depth, _numChildren;
00190     ModelNode *_parent, *_child, *_sibling;
00191     // Specifies the bind pose for this node. This data is read from the model file and never altered
00192     // (could be const).
00193     Math::Vector3d _pos, _pivot;
00194     Math::Quaternion _rot;
00195     // Specifies the animated pose for this node.
00196     Math::Vector3d _animPos;
00197     Math::Quaternion _animRot;
00198     bool _meshVisible, _hierVisible;
00199     bool _initialized;
00200     bool _needsUpdate;
00201     Math::Matrix4 _matrix;
00202     Math::Matrix4 _localMatrix;
00203     Math::Matrix4 _pivotMatrix;
00204     Sprite *_sprite;
00205 };
00206 
00207 } // end of namespace Grim
00208 
00209 #endif


Generated on Sat Aug 17 2019 05:00:38 for ResidualVM by doxygen 1.7.1
curved edge   curved edge