Added BoundingBox to StdMesh

stable-5.2
Armin Burgmeier 2009-07-10 22:02:32 +02:00
parent 16bd81ffad
commit 8c15d08a18
2 changed files with 28 additions and 0 deletions

View File

@ -163,6 +163,12 @@ private:
std::vector<StdMeshTrack*> Tracks; // bone-indexed
};
struct StdMeshBox
{
float x1, y1, z1;
float x2, y2, z2;
};
class StdMesh
{
friend class StdMeshInstance;
@ -187,6 +193,8 @@ public:
const StdMeshAnimation* GetAnimationByName(const StdStrBuf& name) const;
const StdMeshMaterial& GetMaterial() const { return *Material; }
const StdMeshBox& GetBoundingBox() const { return BoundingBox; }
private:
void AddMasterBone(StdMeshBone* bone);
@ -206,6 +214,7 @@ private:
std::map<StdStrBuf, StdMeshAnimation> Animations;
StdMeshBox BoundingBox;
const StdMeshMaterial* Material;
};

View File

@ -318,6 +318,8 @@ StdMeshAnimation& StdMeshAnimation::operator=(const StdMeshAnimation& other)
StdMesh::StdMesh():
Material(NULL)
{
BoundingBox.x1 = BoundingBox.y1 = BoundingBox.z1 = 0.0f;
BoundingBox.x2 = BoundingBox.y2 = BoundingBox.z2 = 0.0f;
}
StdMesh::~StdMesh()
@ -356,6 +358,23 @@ void StdMesh::InitXML(const char* filename, const char* xml_data, StdMeshSkeleto
Vertices[i].nz = mesh.RequireFloatAttribute(normal_elem, "z");
Vertices[i].u = mesh.RequireFloatAttribute(texcoord_elem, "u");
Vertices[i].v = mesh.RequireFloatAttribute(texcoord_elem, "v");
// Construct BoundingBox
if(i == 0)
{
BoundingBox.x1 = BoundingBox.x2 = Vertices[i].x;
BoundingBox.y1 = BoundingBox.y2 = Vertices[i].y;
BoundingBox.z1 = BoundingBox.z2 = Vertices[i].z;
}
else
{
BoundingBox.x1 = Min(Vertices[i].x, BoundingBox.x1);
BoundingBox.x2 = Max(Vertices[i].x, BoundingBox.x2);
BoundingBox.y1 = Min(Vertices[i].y, BoundingBox.y1);
BoundingBox.y2 = Max(Vertices[i].y, BoundingBox.y2);
BoundingBox.z1 = Min(Vertices[i].z, BoundingBox.z1);
BoundingBox.z2 = Max(Vertices[i].z, BoundingBox.z2);
}
}
TiXmlElement* faces_elem = mesh.RequireFirstChild(submesh_elem, "faces");