Проблемы при загрузке файлов .dae, индексы и вершины загружаются правильно

Итак, после прочтения этот Я подумал, что будет лучше изменить формат, в который я загружаю свои файлы, и решил использовать файлы .dae. После написания этого очень простого xml-загрузчика:

void Model::loadModelFromDae(std::string source)
{
using namespace std;
string name = source.substr(0,source.find("."));
cout<<"+++LOADING::"<<name<<"+++"<<endl;

ifstream file;
file.open(source);
string line;
size =0;
indexSize=0;

while(getline(file,line))
{
/*possible float_array's: vertices and normal*/
if(std::string::npos != line.find("<float_array"))
{
if(std::string::npos != line.find("positions"))
{
//get the size of the vertices float_array
int loc_count = line.find("count");
// to explain the hardcoded values: count=" is 7 char's
string cout_substr = line.substr(line.find("count"),line.find(">"));
cout_substr = cout_substr.substr(7,cout_substr.find("\""));
size = atoi(cout_substr.c_str());
cout<<"\tSIZE:"<<size<<endl;
vertices = new float[size];
memset(vertices,0.0f,sizeof(float)*size);

string values = line.substr(line.find("count")+11,line.size());
values = values.substr(0,values.size()-14);
std::stringstream converter(values);
vector<float> temp;
// Iterate over the istream, using >> to grab floats
// and push_back to store them in the vector
std::copy(std::istream_iterator<float>(converter),
std::istream_iterator<float>(),
std::back_inserter(temp));
for(int i=0;i<temp.size();i++) vertices[i] = temp.at(i);
}
//TODO: handle normal array
}
/*Handling indices*/
if(std::string::npos != line.find("<p>"))
{
string values = line.substr(line.find(">")+1,line.length());
values = values.substr(0,values.length()-4);
std::stringstream converter(values);
vector<short> temp;
// Iterate over the istream, using >> to grab shorts
// and push_back to store them in the vector
std::copy(std::istream_iterator<short>(converter),
std::istream_iterator<short>(),
std::back_inserter(temp));
indices = new short[temp.size()];
indexSize = temp.size();
cout<<"\tINDEXSIZE:"<<indexSize<<endl;
for(int i=0;i<temp.size();i++) indices[i] = temp.at(i);
}
}

cout<<"+++ENDED LOADING +DAE+ FILE:"<<name<<"+++"<<endl;
}

У меня все еще есть несколько проблем: я пытаюсь загрузить куб и проверил каждую вершину / индекс, и они точно соответствуют XML-файлу, но результат совсем не тот, который я ожидаю: куб отображает треугольники, но не в порядок они должны быть. Итак, я получил несколько вопросов:

  • Сохраняет ли .dae свои индексы в другом формате, чем OpenGL
    Это?
  • (Необязательно, потому что это требует много отладки.) Можете ли вы заметить мою ошибку, моя первоначальная мысль заключалась в том, что поверхность вершин
    неправильно но ставлю glFrontFace(GL_CCW); или же glFrontFace(GL_CW);
    ничего не меняет

0

Решение

Поработав с индексами, я пришел к такому выводу: индексы — это не только индексы вершин, но также нормалей и UV. Таким образом, при загрузке индексов вы должны быть осторожны, какой индекс принадлежит какому элементу.

2

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector