OBJNode.hh
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 #ifndef ACG_OBJ_NODE_HH
00053 #define ACG_OBJ_NODE_HH
00054
00055
00056
00057
00058 #include "BaseNode.hh"
00059 #include "DrawModes.hh"
00060 #include "../Math/VectorT.hh"
00061 #include <string>
00062 #include <vector>
00063
00064
00065
00066
00067
00068
00069
00070
00071 namespace ACG {
00072 namespace SceneGraph {
00073
00074
00075
00076
00077
00078 class ACGDLLEXPORT OBJNode : public BaseNode
00079 {
00080
00081 public:
00082
00084 OBJNode( BaseNode* _parent=0,
00085 std::string _name="<OBJNode>" )
00086 : BaseNode(_parent, _name)
00087 {}
00088
00089
00091 virtual ~OBJNode() {}
00092
00093
00094 ACG_CLASSNAME(OBJNode);
00095
00096
00098 unsigned int availableDrawModes() const;
00099
00101 void boundingBox(Vec3f& _bbMin, Vec3f& _bbMax);
00102
00104 void draw(GLState& _state, unsigned int _drawMode);
00105
00107 void pick(GLState& _state, PickTarget _target);
00108
00109
00110 struct Face
00111 {
00112 Face(int _i0=-1, int _i1=-1, int _i2=-1,
00113 int _t0=-1, int _t1=-1, int _t2=-1)
00114 : i0(_i0), i1(_i1), i2(_i2),
00115 t0(_t0), t1(_t1), t2(_t2) {}
00116 int i0, i1, i2, t0, t1, t2;
00117 };
00118
00119
00121 unsigned int n_vertices() const { return vertices_.size(); }
00123 unsigned int n_faces() const { return faces_.size(); }
00125 unsigned int n_normals() const { return normals_.size(); }
00127 unsigned int n_texcoords() const { return texCoords_.size(); }
00128
00129
00131 void clear()
00132 {
00133 vertices_.clear();
00134 faces_.clear();
00135 normals_.clear();
00136 texCoords_.clear();
00137 }
00138
00139
00141 unsigned int add_vertex(const Vec3f& _v)
00142 {
00143 vertices_.push_back(_v);
00144 return vertices_.size()-1;
00145 }
00146
00147
00149 unsigned int add_face(const Face& _f)
00150 {
00151 faces_.push_back(_f);
00152 return faces_.size()-1;
00153 }
00154
00156 unsigned int add_face(unsigned int _i0,
00157 unsigned int _i1,
00158 unsigned int _i2)
00159 {
00160 faces_.push_back(Face(_i0, _i1, _i2));
00161 return faces_.size()-1;
00162 }
00163
00164
00166 Vec3f& vertex(unsigned int _i)
00167 {
00168 assert(_i < n_vertices());
00169 return vertices_[_i];
00170 }
00172 const Vec3f& vertex(unsigned int _i) const
00173 {
00174 assert(_i < n_vertices());
00175 return vertices_[_i];
00176 }
00177
00178
00180 const Face& face(unsigned int _i) const
00181 {
00182 assert(_i < n_faces());
00183 return faces_[_i];
00184 }
00186 Face& face(unsigned int _i)
00187 {
00188 assert(_i < n_faces());
00189 return faces_[_i];
00190 }
00191
00192
00194 const Vec3f& normal(unsigned int _i) const
00195 {
00196 assert(_i < n_normals());
00197 return normals_[_i];
00198 }
00200 Vec3f& normal(unsigned int _i)
00201 {
00202 assert(_i < n_normals());
00203 return normals_[_i];
00204 }
00205
00206
00208 bool read(const std::string& _filename);
00209
00210
00212 void update_face_normals();
00213
00214
00215 private:
00216
00217 void draw_obj() const;
00218 void draw_obj_tex() const;
00219
00220 std::vector<Vec3f> vertices_;
00221 std::vector<Vec3f> normals_;
00222 std::vector<Vec2f> texCoords_;
00223 std::vector<Face> faces_;
00224 };
00225
00226
00227
00228 }
00229 }
00230
00231 #endif // ACG_OBJ_NODE_HH
00232