add readFaces() and readVertexRef()
This commit is contained in:
parent
476f4cde66
commit
dffa5a98a5
35
WFObj.cc
35
WFObj.cc
@ -196,6 +196,9 @@ void WFObj::processInputLine(const std::string & input)
|
|||||||
m_vertices[VERTEX_NORMAL].push_back(readVertex(tokens));
|
m_vertices[VERTEX_NORMAL].push_back(readVertex(tokens));
|
||||||
else if (type == "f")
|
else if (type == "f")
|
||||||
{
|
{
|
||||||
|
if (m_faces.find(m_current_material_name) == m_faces.end())
|
||||||
|
m_faces[m_current_material_name] = vector<Face>();
|
||||||
|
m_faces[m_current_material_name].push_back(readFace(tokens));
|
||||||
}
|
}
|
||||||
else if (type == "usemtl")
|
else if (type == "usemtl")
|
||||||
{
|
{
|
||||||
@ -242,6 +245,38 @@ WFObj::Vertex WFObj::readVertex(const vector<string> & parts)
|
|||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vector<WFObj::Face> WFObj::readFaces(const std::vector<std::string> & parts)
|
||||||
|
{
|
||||||
|
vector<Face> faces;
|
||||||
|
VertexRef refs[4];
|
||||||
|
for (int i = 1, len = parts.size(); i < len && i <= 4; i++)
|
||||||
|
{
|
||||||
|
refs[i - 1] = readVertexRef(parts[i]);
|
||||||
|
}
|
||||||
|
return faces;
|
||||||
|
}
|
||||||
|
|
||||||
|
WFObj::VertexRef WFObj::readVertexRef(const std::string ref)
|
||||||
|
{
|
||||||
|
vector<string> parts = splitString(ref, '/');
|
||||||
|
VertexRef fr;
|
||||||
|
for (int i = 0, sz = parts.size(); i < sz; i++)
|
||||||
|
{
|
||||||
|
string idx_str = trimString(parts[i]);
|
||||||
|
if (idx_str.size() > 0)
|
||||||
|
{
|
||||||
|
int idx = atoi(idx_str.c_str());
|
||||||
|
switch (i)
|
||||||
|
{
|
||||||
|
case 0: fr.vertex = idx; break;
|
||||||
|
case 1: fr.texture = idx; break;
|
||||||
|
case 2: fr.normal = idx; break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
2
WFObj.h
2
WFObj.h
@ -90,6 +90,8 @@ protected:
|
|||||||
void clear();
|
void clear();
|
||||||
void processInputLine(const std::string & input);
|
void processInputLine(const std::string & input);
|
||||||
Vertex readVertex(const std::vector<std::string> & parts);
|
Vertex readVertex(const std::vector<std::string> & parts);
|
||||||
|
std::vector<Face> readFaces(const std::vector<std::string> & parts);
|
||||||
|
VertexRef readVertexRef(const std::string ref);
|
||||||
void updateAABB(const float * const vertex);
|
void updateAABB(const float * const vertex);
|
||||||
static Buffer loadfile(const char *path);
|
static Buffer loadfile(const char *path);
|
||||||
std::string getLine(const Buff & buff, size_t idx, size_t *update_idx);
|
std::string getLine(const Buff & buff, size_t idx, size_t *update_idx);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user