bool IsInVertProp = false;
int VertPropCount = 0;
- for(;;)
+ for (;;)
{
- if(!GetNextLine(ist, s))
+ if (!GetNextLine(ist, s))
return false;
- if(CheckHeader(s, "end_header"))
+ if (CheckHeader(s, "end_header"))
return true;
- if(IsInVertProp)
+ if (IsInVertProp)
{
- if(CheckHeader(s, "property "))
+ if (CheckHeader(s, "property "))
{
std::string type = s.substr(s.find_last_of(" ") + 1);
- if(type == "x")
+ if (type == "x")
m_Header.m_VPI.vX = VertPropCount;
- else if(type == "y")
+ else if (type == "y")
m_Header.m_VPI.vY = VertPropCount;
- else if(type == "z")
+ else if (type == "z")
m_Header.m_VPI.vZ = VertPropCount;
- else if(type == "nx")
+ else if (type == "nx")
m_Header.m_VPI.nX = VertPropCount;
- else if(type == "ny")
+ else if (type == "ny")
m_Header.m_VPI.nY = VertPropCount;
- else if(type == "nz")
+ else if (type == "nz")
m_Header.m_VPI.nZ = VertPropCount;
- else if(type == "red")
+ else if (type == "red")
m_Header.m_VPI.cR = VertPropCount;
- else if(type == "green")
+ else if (type == "green")
m_Header.m_VPI.cG = VertPropCount;
- else if(type == "blue")
+ else if (type == "blue")
m_Header.m_VPI.cB = VertPropCount;
+ else if (type == "alpha")
+ m_Header.m_VPI.cA = VertPropCount;
VertPropCount++;
continue;
m_Header.m_NumFaces = ToInt(s.substr(strlen("element face ")));
}
}
-
- return false;
}
bool PlyMesh::CheckHeader(const std::string& line, const char* header) const
{
- if(line == header)
+ if (line == header)
return true;
- for(size_t i = 0; i < line.length(); ++i)
+ for (size_t i = 0; i < line.length(); ++i)
{
- if(header[i] == '\0')
+ if (header[i] == '\0')
return true;
- if(line[i] != header[i])
+ if (line[i] != header[i])
return false;
}
for (size_t i = 0; i < m_Header.m_NumVerts; ++i)
{
ist.read((char*)m_Verts[i].v(), sizeof(float) * 3);
-
+ if (!is_little_endian)
+ ToBigEndian(m_Verts[i]);
+
if (hasNorm)
+ {
ist.read((char*)m_Normals[i].v(), sizeof(float) * 3);
- if (hasCol)
- ist.read((char*)m_Col[i].v(), sizeof(char) * 3);
+ if (!is_little_endian)
+ ToBigEndian(m_Normals[i]);
+ }
- if (!is_little_endian)
- ToBigEndian(m_Verts[i]);
+ if (hasCol)
+ {
+ int nc = m_Header.NumColorElems();
+ ist.read((char*)m_Col[i].v(), sizeof(char) * nc);
+ }
}
m_Faces.resize(m_Header.m_NumFaces);
m_Col[i].y = ReadColorElem(is);
else if (j == m_Header.m_VPI.cB)
m_Col[i].z = ReadColorElem(is);
+ else if (j == m_Header.m_VPI.cA)
+ m_Col[i].w = ReadColorElem(is);
}
}
m_Faces.resize(m_Header.m_NumFaces);
- for(size_t i = 0; i < m_Header.m_NumFaces; ++i)
+ for (size_t i = 0; i < m_Header.m_NumFaces; ++i)
{
int num_v;
ist >> num_v;
m_Faces[i].m_Vid.resize(num_v);
- for(int j = 0; j < num_v; ++j)
+ for (int j = 0; j < num_v; ++j)
{
ist >> m_Faces[i].m_Vid[j];
}
bool PlyMesh::GetNextLine(std::istream& ist, std::string& s) const
{
- while(!ist.eof())
+ while (!ist.eof())
{
std::getline(ist, s);
- if(!s.empty())
+ if (!s.empty())
return true;
}
bool PlyMesh::Save( const std::string& i_Filename ) const
{
- std::ofstream ofs( i_Filename.c_str() , std::ios::binary );
- if( !ofs.is_open() )
+ std::ofstream ofs(i_Filename.c_str(), std::ios::binary);
+ if (!ofs.is_open())
return false;
- return Save( ofs );
+ return Save(ofs);
}
bool PlyMesh::ConvertToBaseMesh( BaseMesh& o_mesh ) const