Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef STARK_MODEL_MODEL_H
00024 #define STARK_MODEL_MODEL_H
00025
00026 #include "common/array.h"
00027 #include "common/str.h"
00028
00029 #include "math/ray.h"
00030 #include "math/vector3d.h"
00031
00032 namespace Stark {
00033
00034 namespace Gfx {
00035 class TextureSet;
00036 }
00037
00038 class ArchiveReadStream;
00039
00040 class VertNode {
00041 public:
00042 Math::Vector3d _pos1, _pos2;
00043 Math::Vector3d _normal;
00044 float _texS, _texT;
00045 uint32 _bone1, _bone2;
00046 float _boneWeight;
00047 };
00048
00049 struct Face {
00050 uint32 materialId;
00051 Common::Array<uint32> vertexIndices;
00052
00053 Face() : materialId(0) {}
00054 };
00055
00056 struct Material {
00057 Common::String name;
00058 Common::String texture;
00059 float r, g, b;
00060 bool doubleSided;
00061
00062 Material() : r(0), g(0), b(0), doubleSided(false) {};
00063 };
00064
00065 class BoneNode {
00066 public:
00067 BoneNode() : _parent(-1), _idx(0), _u1(0) {}
00068 ~BoneNode() { }
00069
00071 bool intersectRay(const Math::Ray &ray) const;
00072
00074 void expandModelSpaceBB(Math::AABB &aabb) const;
00075
00076 Common::String _name;
00077 float _u1;
00078 Common::Array<uint32> _children;
00079 int _parent;
00080 uint32 _idx;
00081
00082 Math::Vector3d _animPos;
00083 Math::Quaternion _animRot;
00084
00086 Math::AABB _boundingBox;
00087 };
00088
00092 class Model {
00093 public:
00094 Model();
00095 ~Model();
00096
00100 void readFromStream(ArchiveReadStream *stream);
00101
00102 const Common::Array<VertNode *> &getVertices() const { return _vertices; }
00103 const Common::Array<Face *> &getFaces() const { return _faces; }
00104 const Common::Array<Material *> &getMaterials() const { return _materials; }
00105 const Common::Array<BoneNode *> &getBones() const { return _bones; };
00106
00108 bool intersectRay(const Math::Ray &ray) const;
00109
00111 void updateBoundingBox();
00112
00114 Math::AABB getBoundingBox() const;
00115
00116 private:
00117 void buildBonesBoundingBoxes();
00118 void buildBoneBoundingBox(BoneNode *bone) const;
00119 void readBones(ArchiveReadStream *stream);
00120
00121 Common::String _name;
00122 uint32 _u1;
00123 float _u2;
00124
00125 Common::Array<VertNode *> _vertices;
00126 Common::Array<Material *> _materials;
00127 Common::Array<Face *> _faces;
00128 Common::Array<BoneNode *> _bones;
00129 Math::AABB _boundingBox;
00130 };
00131
00132 }
00133
00134 #endif // STARK_MODEL_MODEL_H