1 ////////////////////////////////////////////////////////////////////////////////
2 //    Scorched3D (c) 2000-2011
3 //
4 //    This file is part of Scorched3D.
5 //
6 //    Scorched3D is free software; you can redistribute it and/or modify
7 //    it under the terms of the GNU General Public License as published by
8 //    the Free Software Foundation; either version 2 of the License, or
9 //    (at your option) any later version.
10 //
11 //    Scorched3D is distributed in the hope that it will be useful,
12 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //    GNU General Public License for more details.
15 //
16 //    You should have received a copy of the GNU General Public License along
17 //    with this program; if not, write to the Free Software Foundation, Inc.,
18 //    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 ////////////////////////////////////////////////////////////////////////////////
20 
21 #if !defined(__INCLUDE_Meshh_INCLUDE__)
22 #define __INCLUDE_Meshh_INCLUDE__
23 
24 #include <common/DefinesAssert.h>
25 #include <common/FixedVector4.h>
26 #include <3dsparse/Face.h>
27 #include <3dsparse/Vertex.h>
28 #include <vector>
29 #include <string>
30 
31 #ifndef S3D_SERVER
32 #include <GLEXT/GLTextureReference.h>
33 #endif
34 
35 class Mesh
36 {
37 public:
38 	Mesh(const char *name);
39 	virtual ~Mesh();
40 
41 	// Accessors
getName()42 	const char *getName() { return name_.c_str(); }
getSphereMap()43 	bool getSphereMap() { return sphereMap_; }
getMin()44 	FixedVector &getMin() { return min_; }
getMax()45 	FixedVector &getMax() { return max_; }
getAmbientColor()46 	FixedVector4 &getAmbientColor() { return ambientColor_; }
getDiffuseColor()47 	FixedVector4 &getDiffuseColor() { return diffuseColor_; }
getSpecularColor()48 	FixedVector4 &getSpecularColor() { return specularColor_; }
getEmissiveColor()49 	FixedVector4 &getEmissiveColor() { return emissiveColor_; }
getAmbientNoTexColor()50 	FixedVector4 &getAmbientNoTexColor() { return ambientNoTexColor_; }
getDiffuseNoTexColor()51 	FixedVector4 &getDiffuseNoTexColor() { return diffuseNoTexColor_; }
getSpecularNoTexColor()52 	FixedVector4 &getSpecularNoTexColor() { return specularNoTexColor_; }
getEmissiveNoTexColor()53 	FixedVector4 &getEmissiveNoTexColor() { return emissiveNoTexColor_; }
getShininessColor()54 	fixed &getShininessColor() { return shininessColor_; }
getTextureName()55 	const char *getTextureName()
56 		{ return textureName_.c_str(); }
getATextureName()57 	const char *getATextureName()
58 		{ return aTextureName_.c_str(); }
59 
60 #ifndef S3D_SERVER
getTextureSet()61 	bool getTextureSet() { return textureSet_; }
getTexture()62 	GLTextureReference &getTexture() { return texture_; }
63 #endif
64 
getFaces()65 	std::vector<Face *> &getFaces()
66 		{ return faces_; }
getFace(int faceIndex)67 	Face *getFace(int faceIndex)
68 		{ DIALOG_ASSERT(faceIndex < (int) faces_.size());
69 		return faces_[faceIndex]; }
getVertexes()70 	std::vector<Vertex *> &getVertexes()
71 		{ return vertexes_; }
getVertex(int vertexIndex)72 	Vertex *getVertex(int vertexIndex)
73 		{ DIALOG_ASSERT(vertexIndex < (int) vertexes_.size());
74 		return vertexes_[vertexIndex]; }
75 
76 	// Modification
77 	void move(FixedVector &movement);
78 
79 	// Creation
insertFace(Face & face)80 	void insertFace(Face &face)
81 		{ faces_.push_back(new Face(face)); }
82 	void insertVertex(Vertex &vertex);
83 	void setTextureName(const char *t);
84 	void setATextureName(const char *t);
setFaceNormal(FixedVector & normal,int faceIndex,int normalIndex)85 	void setFaceNormal(FixedVector &normal, int faceIndex, int normalIndex)
86 		{ DIALOG_ASSERT(faceIndex < (int) faces_.size());
87 		faces_[faceIndex]->normal[normalIndex] = normal; }
setFaceTCoord(FixedVector & coord,int faceIndex,int coordIndex)88 	void setFaceTCoord(FixedVector &coord, int faceIndex, int coordIndex)
89 		{ DIALOG_ASSERT(faceIndex < (int) faces_.size());
90 		faces_[faceIndex]->tcoord[coordIndex] = coord; }
91 
92 protected:
93 #ifndef S3D_SERVER
94 	bool textureSet_;
95 	GLTextureReference texture_;
96 #endif
97 	std::string name_;
98 	std::string textureName_, aTextureName_;
99 	std::vector<Face *> faces_;
100 	std::vector<Vertex *> vertexes_;
101 	bool sphereMap_;
102 	fixed shininessColor_;
103 	FixedVector4 diffuseColor_, specularColor_;
104 	FixedVector4 ambientColor_, emissiveColor_;
105 	FixedVector4 diffuseNoTexColor_, specularNoTexColor_;
106 	FixedVector4 ambientNoTexColor_, emissiveNoTexColor_;
107 	FixedVector min_, max_;
108 };
109 
110 #endif // __INCLUDE_Meshh_INCLUDE__
111