2003-08-15 18:00:22 +00:00
|
|
|
// Residual - Virtual machine to run LucasArts' 3D adventure games
|
2006-02-15 19:43:48 +00:00
|
|
|
// Copyright (C) 2003-2006 The ScummVM-Residual Team (www.scummvm.org)
|
2003-08-15 18:00:22 +00:00
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2.1 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
2003-08-15 19:41:26 +00:00
|
|
|
#ifndef MODEL_H
|
|
|
|
#define MODEL_H
|
2003-08-15 18:00:22 +00:00
|
|
|
|
2003-08-15 19:41:26 +00:00
|
|
|
#include "vector3d.h"
|
2003-08-28 01:55:48 +00:00
|
|
|
#include "matrix4.h"
|
2003-08-15 19:41:26 +00:00
|
|
|
#include "resource.h"
|
2005-01-01 12:27:57 +00:00
|
|
|
|
2003-08-15 18:00:22 +00:00
|
|
|
#include <cstring>
|
|
|
|
|
2003-10-05 17:45:46 +00:00
|
|
|
class CMap;
|
2003-08-15 18:00:22 +00:00
|
|
|
class Material;
|
|
|
|
class TextSplitter;
|
|
|
|
|
|
|
|
class Model : public Resource {
|
|
|
|
public:
|
2004-02-24 22:43:32 +00:00
|
|
|
// Construct a 3D model from the given data.
|
|
|
|
Model(const char *filename, const char *data, int len, const CMap &cmap);
|
|
|
|
void loadBinary(const char *data, const CMap &cmap);
|
|
|
|
void loadText(TextSplitter &ts, const CMap &cmap);
|
2005-07-10 18:57:27 +00:00
|
|
|
void reload(const CMap &cmap);
|
2004-02-24 22:43:32 +00:00
|
|
|
void draw() const;
|
|
|
|
|
|
|
|
~Model();
|
|
|
|
|
|
|
|
struct Geoset;
|
|
|
|
struct Mesh;
|
|
|
|
struct HierNode {
|
2005-07-21 15:16:35 +00:00
|
|
|
HierNode() : _initialized(false) { }
|
2004-02-24 22:43:32 +00:00
|
|
|
void loadBinary(const char *&data, HierNode *hierNodes, const Geoset &g);
|
|
|
|
void draw() const;
|
|
|
|
void addChild(HierNode *child);
|
|
|
|
void removeChild(HierNode *child);
|
|
|
|
void setMatrix(Matrix4 matrix);
|
|
|
|
void update();
|
|
|
|
|
2004-12-09 23:55:43 +00:00
|
|
|
char _name[64];
|
|
|
|
Mesh *_mesh;
|
|
|
|
int _flags, _type;
|
|
|
|
int _depth, _numChildren;
|
|
|
|
HierNode *_parent, *_child, *_sibling;
|
|
|
|
Vector3d _pos, _pivot;
|
|
|
|
float _pitch, _yaw, _roll;
|
|
|
|
Vector3d _animPos;
|
|
|
|
float _animPitch, _animYaw, _animRoll;
|
|
|
|
bool _meshVisible, _hierVisible;
|
|
|
|
int _priority, _totalWeight;
|
2005-07-21 15:16:35 +00:00
|
|
|
bool _initialized;
|
2004-12-09 23:55:43 +00:00
|
|
|
Matrix4 _matrix;
|
|
|
|
Matrix4 _localMatrix;
|
|
|
|
Matrix4 _pivotMatrix;
|
2004-02-24 22:43:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
HierNode *copyHierarchy();
|
2004-12-09 23:55:43 +00:00
|
|
|
int numNodes() const { return _numHierNodes; }
|
2003-08-15 18:00:22 +00:00
|
|
|
|
2004-04-19 09:56:34 +00:00
|
|
|
//private:
|
2004-02-24 22:43:32 +00:00
|
|
|
struct Face {
|
2005-07-10 18:57:27 +00:00
|
|
|
int loadBinary(const char *&data, ResPtr<Material> *materials);
|
2004-02-24 22:43:32 +00:00
|
|
|
void draw(float *vertices, float *vertNormals, float *textureVerts) const;
|
2005-07-10 18:57:27 +00:00
|
|
|
void changeMaterial(ResPtr<Material> materials);
|
2004-02-24 22:43:32 +00:00
|
|
|
~Face();
|
|
|
|
|
2004-12-09 23:55:43 +00:00
|
|
|
Material *_material;
|
|
|
|
int _type, _geo, _light, _tex;
|
|
|
|
float _extraLight;
|
|
|
|
int _numVertices;
|
|
|
|
int *_vertices, *_texVertices;
|
|
|
|
Vector3d _normal;
|
2004-02-24 22:43:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Mesh {
|
|
|
|
void loadBinary(const char *&data, ResPtr<Material> *materials);
|
|
|
|
void loadText(TextSplitter &ts, ResPtr<Material> *materials);
|
2005-07-10 18:57:27 +00:00
|
|
|
void changeMaterials(ResPtr<Material> *materials);
|
2004-02-24 22:43:32 +00:00
|
|
|
void draw() const;
|
|
|
|
void update();
|
2005-07-10 18:57:27 +00:00
|
|
|
Mesh() : _numFaces(0) { }
|
2004-02-24 22:43:32 +00:00
|
|
|
~Mesh();
|
|
|
|
|
2004-12-09 23:55:43 +00:00
|
|
|
char _name[32];
|
|
|
|
float _radius;
|
|
|
|
int _shadow, _geometryMode, _lightingMode, _textureMode;
|
2004-02-24 22:43:32 +00:00
|
|
|
|
2004-12-09 23:55:43 +00:00
|
|
|
int _numVertices;
|
2005-07-10 18:57:27 +00:00
|
|
|
int *_materialid;
|
2004-12-09 23:55:43 +00:00
|
|
|
float *_vertices; // sets of 3
|
|
|
|
float *_verticesI;
|
|
|
|
float *_vertNormals; // sets of 3
|
2004-02-24 22:43:32 +00:00
|
|
|
|
2004-12-09 23:55:43 +00:00
|
|
|
int _numTextureVerts;
|
|
|
|
float *_textureVerts; // sets of 2
|
2004-02-24 22:43:32 +00:00
|
|
|
|
2004-12-09 23:55:43 +00:00
|
|
|
int _numFaces;
|
|
|
|
Face *_faces;
|
|
|
|
Matrix4 _matrix;
|
2004-02-24 22:43:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Geoset {
|
|
|
|
void loadBinary(const char *&data, ResPtr<Material> *materials);
|
|
|
|
void loadText(TextSplitter &ts, ResPtr<Material> *materials);
|
2005-07-10 18:57:27 +00:00
|
|
|
void changeMaterials(ResPtr<Material> *materials);
|
|
|
|
Geoset() : _numMeshes(0) { }
|
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
|
|
|
};
|
|
|
|
|
2004-12-09 23:55:43 +00:00
|
|
|
int _numMaterials;
|
2005-07-10 18:57:27 +00:00
|
|
|
char (*_materialNames)[32];
|
2004-12-09 23:55:43 +00:00
|
|
|
ResPtr<Material> *_materials;
|
|
|
|
Vector3d _insertOffset;
|
|
|
|
int _numGeosets;
|
|
|
|
Geoset *_geosets;
|
|
|
|
float _radius;
|
|
|
|
int _numHierNodes;
|
|
|
|
HierNode *_rootHierNode;
|
2003-08-15 18:00:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|