本文整理汇总了C++中TokenStream::ResetStream方法的典型用法代码示例。如果您正苦于以下问题:C++ TokenStream::ResetStream方法的具体用法?C++ TokenStream::ResetStream怎么用?C++ TokenStream::ResetStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TokenStream
的用法示例。
在下文中一共展示了TokenStream::ResetStream方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadOBJ
bool ObjModel::LoadOBJ(const wchar_t* fileName)
{
wprintf_s(L"Loading Obj from: %s\n", fileName);
std::ifstream fileStream;
int fileSize = 0;
fileStream.open(fileName, std::ifstream::in);
wprintf_s(L"fileStream.open()\n");
if (fileStream.is_open() == false)
return false;
wprintf_s(L"fileStream.is_open()\n");
fileStream.seekg(0, std::ios::end);
fileSize = (int)fileStream.tellg();
fileStream.seekg(0, std::ios::beg);
if (fileSize <= 0)
return false;
char* buffer = new char[fileSize];
if (buffer == 0)
return false;
memset(buffer, '\0', fileSize);
TokenStream tokenStream;
TokenStream lineStream;
TokenStream faceStream;
std::string tempLine;
std::string token;
fileStream.read(buffer, fileSize);
tokenStream.SetTokenStream(buffer);
delete[] buffer;
tokenStream.ResetStream();
std::vector<float> verts, norms, texC;
std::vector<int> faces;
char lineDelimiters[2] = { '\n', ' ' };
while (tokenStream.MoveToNextLine(&tempLine))
{
lineStream.SetTokenStream((char*)tempLine.c_str());
tokenStream.GetNextToken(0, 0, 0);
if (!lineStream.GetNextToken(&token, lineDelimiters, 2))
continue;
if (strcmp(token.c_str(), "v") == 0)
{
lineStream.GetNextToken(&token, lineDelimiters, 2);
verts.push_back((float)atof(token.c_str()));
lineStream.GetNextToken(&token, lineDelimiters, 2);
verts.push_back((float)atof(token.c_str()));
lineStream.GetNextToken(&token, lineDelimiters, 2);
verts.push_back((float)atof(token.c_str()));
}
else if (strcmp(token.c_str(), "vn") == 0)
{
lineStream.GetNextToken(&token, lineDelimiters, 2);
norms.push_back((float)atof(token.c_str()));
lineStream.GetNextToken(&token, lineDelimiters, 2);
norms.push_back((float)atof(token.c_str()));
lineStream.GetNextToken(&token, lineDelimiters, 2);
norms.push_back((float)atof(token.c_str()));
}
else if (strcmp(token.c_str(), "vt") == 0)
{
lineStream.GetNextToken(&token, lineDelimiters, 2);
texC.push_back((float)atof(token.c_str()));
lineStream.GetNextToken(&token, lineDelimiters, 2);
texC.push_back((float)atof(token.c_str()));
}
else if (strcmp(token.c_str(), "f") == 0)
{
char faceTokens[3] = { '\n', ' ', '/' };
std::string faceIndex;
faceStream.SetTokenStream((char*)tempLine.c_str());
faceStream.GetNextToken(0, 0, 0);
for (int i = 0; i < 3; i++)
{
faceStream.GetNextToken(&faceIndex, faceTokens, 3);
faces.push_back((int)atoi(faceIndex.c_str()));
//.........这里部分代码省略.........