2012-01-06 22:29:45 +00:00
|
|
|
/* ResidualVM - A 3D game interpreter
|
2008-06-13 14:57:47 +00:00
|
|
|
*
|
2012-01-06 22:29:45 +00:00
|
|
|
* ResidualVM is the legal property of its developers, whose names
|
2011-04-16 12:12:44 +00:00
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
2008-06-13 14:57:47 +00:00
|
|
|
* file distributed with this source distribution.
|
2006-04-02 14:20:45 +00:00
|
|
|
*
|
2012-12-19 22:15:43 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2014-04-05 16:18:42 +00:00
|
|
|
*
|
2012-12-19 22:15:43 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2006-04-02 14:20:45 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-12-19 22:15:43 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2014-04-05 16:18:42 +00:00
|
|
|
*
|
2012-12-19 22:15:43 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2006-04-02 14:20:45 +00:00
|
|
|
*
|
|
|
|
*/
|
2003-08-15 18:00:22 +00:00
|
|
|
|
2009-05-26 09:39:42 +00:00
|
|
|
#ifndef GRIM_MODEL_H
|
|
|
|
#define GRIM_MODEL_H
|
2003-08-15 18:00:22 +00:00
|
|
|
|
2011-03-20 21:16:27 +00:00
|
|
|
#include "engines/grim/object.h"
|
2011-09-10 15:46:07 +00:00
|
|
|
#include "math/matrix4.h"
|
2014-06-25 14:15:41 +00:00
|
|
|
#include "math/quat.h"
|
2005-01-01 12:27:57 +00:00
|
|
|
|
2011-12-19 17:26:48 +00:00
|
|
|
namespace Common {
|
|
|
|
class SeekableReadStream;
|
|
|
|
}
|
|
|
|
|
2009-05-25 06:49:57 +00:00
|
|
|
namespace Grim {
|
|
|
|
|
2003-08-15 18:00:22 +00:00
|
|
|
class TextSplitter;
|
2011-05-14 00:55:14 +00:00
|
|
|
class Material;
|
2011-07-22 20:09:49 +00:00
|
|
|
class Mesh;
|
|
|
|
class ModelNode;
|
2011-05-14 00:55:14 +00:00
|
|
|
class CMap;
|
2013-07-08 00:18:30 +00:00
|
|
|
class Sprite;
|
2011-05-15 13:47:09 +00:00
|
|
|
|
2011-03-20 21:16:27 +00:00
|
|
|
class Model : public Object {
|
2003-08-15 18:00:22 +00:00
|
|
|
public:
|
2004-02-24 22:43:32 +00:00
|
|
|
// Construct a 3D model from the given data.
|
2011-12-19 17:26:48 +00:00
|
|
|
Model(const Common::String &filename, Common::SeekableReadStream *data, CMap *cmap, Model *parent = NULL);
|
2012-04-25 00:21:18 +00:00
|
|
|
|
2011-03-20 21:16:27 +00:00
|
|
|
void reload(CMap *cmap);
|
2004-02-24 22:43:32 +00:00
|
|
|
void draw() const;
|
2011-07-27 16:07:35 +00:00
|
|
|
Material *findMaterial(const char *name, CMap *cmap) const;
|
2004-02-24 22:43:32 +00:00
|
|
|
|
|
|
|
~Model();
|
2012-04-25 00:21:18 +00:00
|
|
|
const Common::String &getFilename() const { return _fname; }
|
|
|
|
const ObjectPtr<CMap> &getCMap() const { return _cmap; }
|
2009-06-26 16:13:11 +00:00
|
|
|
|
2011-12-12 18:18:33 +00:00
|
|
|
ModelNode *getHierarchy() const;
|
2011-05-05 09:43:04 +00:00
|
|
|
int getNumNodes() const { return _numHierNodes; }
|
2003-08-15 18:00:22 +00:00
|
|
|
|
2004-02-24 22:43:32 +00:00
|
|
|
struct Geoset {
|
2011-12-19 17:26:48 +00:00
|
|
|
void loadBinary(Common::SeekableReadStream *data, Material *materials[]);
|
2009-08-27 19:01:09 +00:00
|
|
|
void loadText(TextSplitter *ts, Material *materials[]);
|
|
|
|
void changeMaterials(Material *materials[]);
|
2013-04-21 13:41:23 +00:00
|
|
|
Geoset() : _numMeshes(0), _meshes(NULL) { }
|
2004-02-24 22:43:32 +00:00
|
|
|
~Geoset();
|
|
|
|
|
2004-12-09 23:55:43 +00:00
|
|
|
int _numMeshes;
|
|
|
|
Mesh *_meshes;
|
2004-02-24 22:43:32 +00:00
|
|
|
};
|
|
|
|
|
2012-04-25 00:21:18 +00:00
|
|
|
//private:
|
2012-04-26 00:32:45 +00:00
|
|
|
void loadMaterial(int index, CMap *cmap);
|
2012-04-25 00:21:18 +00:00
|
|
|
void loadBinary(Common::SeekableReadStream *data);
|
|
|
|
void loadText(TextSplitter *ts);
|
2011-07-18 21:43:01 +00:00
|
|
|
|
2012-04-25 00:21:18 +00:00
|
|
|
Common::String _fname;
|
|
|
|
ObjectPtr<CMap> _cmap;
|
2011-07-18 21:43:01 +00:00
|
|
|
Model *_parent;
|
2004-12-09 23:55:43 +00:00
|
|
|
int _numMaterials;
|
2005-07-10 18:57:27 +00:00
|
|
|
char (*_materialNames)[32];
|
2011-07-18 20:16:40 +00:00
|
|
|
Material **_materials;
|
2011-07-18 21:43:01 +00:00
|
|
|
bool *_materialsShared;
|
2011-09-10 15:46:07 +00:00
|
|
|
Math::Vector3d _insertOffset;
|
2004-12-09 23:55:43 +00:00
|
|
|
int _numGeosets;
|
|
|
|
Geoset *_geosets;
|
|
|
|
float _radius;
|
|
|
|
int _numHierNodes;
|
2011-07-22 20:09:49 +00:00
|
|
|
ModelNode *_rootHierNode;
|
2011-09-10 15:46:07 +00:00
|
|
|
Math::Vector3d _bboxPos;
|
|
|
|
Math::Vector3d _bboxSize;
|
2011-07-22 20:09:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class MeshFace {
|
|
|
|
public:
|
2014-03-30 21:02:32 +00:00
|
|
|
MeshFace();
|
|
|
|
~MeshFace();
|
2014-03-30 22:33:24 +00:00
|
|
|
void stealData(MeshFace &other);
|
2011-12-19 17:26:48 +00:00
|
|
|
int loadBinary(Common::SeekableReadStream *data, Material *materials[]);
|
2014-03-30 21:02:32 +00:00
|
|
|
int loadText(TextSplitter *ts, Material *materials[], int offset);
|
2012-12-27 18:08:46 +00:00
|
|
|
void draw(const Mesh *mesh) const;
|
2011-07-22 20:09:49 +00:00
|
|
|
void changeMaterial(Material *material);
|
|
|
|
|
2014-03-30 21:38:52 +00:00
|
|
|
bool hasTexture() const { return _texVertices != nullptr; }
|
|
|
|
|
|
|
|
const Math::Vector3d &getNormal() const { return _normal; }
|
|
|
|
void setNormal(const Math::Vector3d &normal) { _normal = normal; }
|
|
|
|
const Material *getMaterial() const { return _material; }
|
|
|
|
int getNumVertices() const { return _numVertices; }
|
|
|
|
int getVertex(int i) const { return _vertices[i]; }
|
|
|
|
int getTextureVertex(int i) const { return _texVertices[i]; }
|
|
|
|
int getLight() const { return _light; }
|
|
|
|
|
|
|
|
private:
|
2011-07-22 20:09:49 +00:00
|
|
|
Material *_material;
|
|
|
|
int _type, _geo, _light, _tex;
|
|
|
|
float _extraLight;
|
|
|
|
int _numVertices;
|
|
|
|
int *_vertices, *_texVertices;
|
2011-09-10 15:46:07 +00:00
|
|
|
Math::Vector3d _normal;
|
2013-07-14 13:43:54 +00:00
|
|
|
|
2014-03-30 21:38:52 +00:00
|
|
|
public:
|
2013-07-14 13:43:54 +00:00
|
|
|
void *_userData;
|
2011-07-22 20:09:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class Mesh {
|
|
|
|
public:
|
2011-12-19 17:26:48 +00:00
|
|
|
void loadBinary(Common::SeekableReadStream *data, Material *materials[]);
|
2011-07-22 20:09:49 +00:00
|
|
|
void loadText(TextSplitter *ts, Material *materials[]);
|
|
|
|
void changeMaterials(Material *materials[]);
|
2011-12-12 17:57:17 +00:00
|
|
|
void draw() const;
|
|
|
|
void getBoundingBox(int *x1, int *y1, int *x2, int *y2) const;
|
2011-07-22 20:09:49 +00:00
|
|
|
void update();
|
2013-04-21 13:39:39 +00:00
|
|
|
Mesh();
|
2011-07-22 20:09:49 +00:00
|
|
|
~Mesh();
|
|
|
|
|
|
|
|
char _name[32];
|
|
|
|
float _radius;
|
|
|
|
int _shadow, _geometryMode, _lightingMode, _textureMode;
|
|
|
|
|
|
|
|
int _numVertices;
|
|
|
|
int *_materialid;
|
2013-07-09 19:12:55 +00:00
|
|
|
float *_vertices; // sets of 3
|
2011-07-22 20:09:49 +00:00
|
|
|
float *_verticesI;
|
2013-07-09 19:12:55 +00:00
|
|
|
float *_vertNormals; // sets of 3
|
2011-07-22 20:09:49 +00:00
|
|
|
|
|
|
|
int _numTextureVerts;
|
2013-07-09 19:12:55 +00:00
|
|
|
float *_textureVerts; // sets of 2
|
2011-07-22 20:09:49 +00:00
|
|
|
|
|
|
|
int _numFaces;
|
|
|
|
MeshFace *_faces;
|
2011-09-10 15:46:07 +00:00
|
|
|
Math::Matrix4 _matrix;
|
2013-02-20 23:50:13 +00:00
|
|
|
|
2013-07-14 13:43:54 +00:00
|
|
|
void *_userData;
|
|
|
|
|
2013-02-20 23:50:13 +00:00
|
|
|
private:
|
|
|
|
void sortFaces();
|
2011-07-22 20:09:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class ModelNode {
|
|
|
|
public:
|
2013-10-25 01:26:01 +00:00
|
|
|
ModelNode();
|
2011-07-22 20:09:49 +00:00
|
|
|
~ModelNode();
|
2011-12-19 17:26:48 +00:00
|
|
|
void loadBinary(Common::SeekableReadStream *data, ModelNode *hierNodes, const Model::Geoset *g);
|
2011-12-12 17:57:17 +00:00
|
|
|
void draw() const;
|
|
|
|
void getBoundingBox(int *x1, int *y1, int *x2, int *y2) const;
|
2011-07-22 20:09:49 +00:00
|
|
|
void addChild(ModelNode *child);
|
|
|
|
void removeChild(ModelNode *child);
|
2012-02-05 02:07:24 +00:00
|
|
|
void setMatrix(const Math::Matrix4 &matrix);
|
2011-07-22 20:09:49 +00:00
|
|
|
void update();
|
|
|
|
void addSprite(Sprite *sprite);
|
2013-10-25 14:40:30 +00:00
|
|
|
void removeSprite(const Sprite *sprite);
|
2011-12-12 17:57:17 +00:00
|
|
|
void translateViewpoint() const;
|
2017-11-28 00:39:55 +00:00
|
|
|
void translateViewpointStart() const;
|
|
|
|
void translateViewpointFinish() const;
|
2011-07-22 20:09:49 +00:00
|
|
|
|
|
|
|
char _name[64];
|
|
|
|
Mesh *_mesh;
|
2011-10-31 00:55:29 +00:00
|
|
|
/**
|
|
|
|
* A value of 0x100 (256) specifies that when animating this node, keyframes should not be
|
|
|
|
* interpolated (lerped), but instead the transition from source to target is to occur
|
|
|
|
* discretely.
|
|
|
|
*/
|
|
|
|
int _flags;
|
2012-02-05 02:07:24 +00:00
|
|
|
/**
|
2011-10-31 00:55:29 +00:00
|
|
|
* Each KeyFrameAnim has a type identifier. This type field is a bitmask which is ANDed againts
|
|
|
|
* the type in the KeyFrameAnim to control which KeyFrameAnims animate on which nodes of the character.
|
|
|
|
* This enables selectively controlling the animations to act only on certain bones.
|
|
|
|
*/
|
|
|
|
int _type;
|
2011-07-22 20:09:49 +00:00
|
|
|
int _depth, _numChildren;
|
|
|
|
ModelNode *_parent, *_child, *_sibling;
|
2014-12-26 22:21:56 +00:00
|
|
|
// Specifies the bind pose for this node. This data is read from the model file and never altered
|
|
|
|
// (could be const).
|
2011-09-10 15:46:07 +00:00
|
|
|
Math::Vector3d _pos, _pivot;
|
2014-06-25 14:15:41 +00:00
|
|
|
Math::Quaternion _rot;
|
2014-12-26 22:21:56 +00:00
|
|
|
// Specifies the animated pose for this node.
|
2011-09-10 15:46:07 +00:00
|
|
|
Math::Vector3d _animPos;
|
2014-06-25 14:15:41 +00:00
|
|
|
Math::Quaternion _animRot;
|
2011-07-22 20:09:49 +00:00
|
|
|
bool _meshVisible, _hierVisible;
|
|
|
|
bool _initialized;
|
2012-04-08 09:54:42 +00:00
|
|
|
bool _needsUpdate;
|
2011-09-10 15:46:07 +00:00
|
|
|
Math::Matrix4 _matrix;
|
|
|
|
Math::Matrix4 _localMatrix;
|
|
|
|
Math::Matrix4 _pivotMatrix;
|
2013-07-09 19:12:55 +00:00
|
|
|
Sprite *_sprite;
|
2003-08-15 18:00:22 +00:00
|
|
|
};
|
|
|
|
|
2009-05-25 06:49:57 +00:00
|
|
|
} // end of namespace Grim
|
|
|
|
|
2003-08-15 18:00:22 +00:00
|
|
|
#endif
|