00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <3dsparse/Mesh.h>
00022 #include <3dsparse/ModelStore.h>
00023 #include <3dsparse/MeshLOD.h>
00024 #include <common/Defines.h>
00025
00026 Mesh::Mesh(const char *name) : name_(name),
00027 referencesBones_(false), sphereMap_(false)
00028 {
00029 }
00030
00031 Mesh::~Mesh()
00032 {
00033 while (!faces_.empty())
00034 {
00035 Face *face = faces_.back();
00036 faces_.pop_back();
00037 delete face;
00038 }
00039 while (!vertexes_.empty())
00040 {
00041 Vertex *vertex = vertexes_.back();
00042 vertexes_.pop_back();
00043 delete vertex;
00044 }
00045 }
00046
00047 void Mesh::insertVertex(Vertex &vertex)
00048 {
00049 if (vertexes_.empty())
00050 {
00051 max_ = vertex.position;
00052 min_ = vertex.position;
00053 }
00054 else
00055 {
00056 max_[0] = MAX(max_[0], vertex.position[0]);
00057 max_[1] = MAX(max_[1], vertex.position[1]);
00058 max_[2] = MAX(max_[2], vertex.position[2]);
00059
00060 min_[0] = MIN(min_[0], vertex.position[0]);
00061 min_[1] = MIN(min_[1], vertex.position[1]);
00062 min_[2] = MIN(min_[2], vertex.position[2]);
00063 }
00064
00065 vertexes_.push_back(new Vertex(vertex));
00066 }
00067
00068 void Mesh::move(Vector &movement)
00069 {
00070 std::vector<Vertex *>::iterator itor;
00071 for (itor = vertexes_.begin();
00072 itor != vertexes_.end();
00073 itor++)
00074 {
00075 (*itor)->position += movement;
00076 }
00077 max_ += movement;
00078 min_ += movement;
00079 }
00080
00081 void Mesh::setTextureName(const char *t)
00082 {
00083 if (0 != strcmp(t, "none"))
00084 {
00085 sphereMap_ = (strstr(t, "/sphere_") != 0);
00086 textureName_ = t;
00087 }
00088 }
00089
00090 void Mesh::setupCollapse()
00091 {
00092 MeshLOD::progressiveMesh(vertexes_, faces_, collapseMap_);
00093 }