I wrote this function I plan on using to load in .obj files from Blender into a DirectX application. The problem I'm having is that when when the model is loaded, it appears that every other triangle face is missing in a pattern, for every quad, only 1 traingle is visible. I've been trying to debug it for a while and still can't find the issue. According to the debugger it's loading the exact amount of vertecies & faces as Blender says are in the model.
I was having this issue before when using a triangle face method to load in a quad model, I fixed that issue by simply adding a Trianglulate Modifier, but at that time I was importing the model into Visual Studio and then exporting to make it readable for another function I wrote previously. Because the extra import/export step was getting annoying I wrote the function again to load in the .obj models directly from blender and I'm sure the models are triaglulated.
I can't seem to find what's causing the problem again. The faces seem to there but are not drawn or just overlapping
struct faceindexgroup { int v_index, tx_index, nrm_index;};
bool Model3D::successfullyLoadedDataFromBLENDER_OBJ(const QString &blenderfilename)
{
QStringList filespacecuts = fileReadToLine(blenderfilename, " ").split(" ");
QList <QVector3D> vertecies, normals;
QList <QPointF> texcoords;
QList <faceindexgroup> ifaces;
const QString *cline = &filespacecuts.at(0); //isolated by spaces or a new line
for(int c = 0, sz = filespacecuts.size(); c<sz; cline = &filespacecuts.at(c < sz ? c++ : 0)) {
bool is_v = false, is_vt = false, is_vn = false;
if((is_v = (*cline) == "v") or (is_vt = (*cline) == "vt") or (is_vn = (*cline) == "vn")) {
float cx = filespacecuts.at(c++).toFloat();
float cy = filespacecuts.at(c++).toFloat();
float cz = !is_vt ? filespacecuts.at(c++).toFloat() : 0;
if(is_v)
vertecies.append(QVector3D (cx, cy, cz));
else if(is_vt)
texcoords.append(QPointF(cx, cy));
else if(is_vn)
normals.append(QVector3D (cx, cy, cz));
}
else if((*cline) == "f") {
IntList v1 = stringListToInts(filespacecuts.at(c++).split('/'));
IntList v2 = stringListToInts(filespacecuts.at(c++).split('/'));
IntList v3 = stringListToInts(filespacecuts.at(c++).split('/'));
faceindexgroup f;
f.v_index = v1.at(0);
f.tx_index = v1.at(1);
f.nrm_index = v1.at(2);
ifaces.append(f);
f.v_index = v2.at(0);
f.tx_index = v2.at(1);
f.nrm_index = v2.at(2);
ifaces.append(f);
f.v_index = v3.at(0);
f.tx_index = v3.at(1);
f.nrm_index = v3.at(2);
ifaces.append(f);
}
}
if(texcoords.isEmpty())
resizeList(texcoords, vertecies.size());
for(int c = 0, sz = ifaces.size(); c<sz; c++) {
const faceindexgroup *cf = &ifaces.at(c);
const QVector3D
*cv = &vertecies.at(cf->v_index - 1),
*cn = &normals.at(cf->nrm_index - 1);
const QPointF *ct = &texcoords.at(cf->tx_index - 1);
//contains the vertex, texure uv coord, and a noraml | 3 per face
ModelVertexProperty mv;
mv.x = cv->x();
mv.y = cv->y();
mv.z = cv->z();
mv.tu = ct->x();
mv.tv = ct->y();
mv.nx = cn->x();
mv.ny = cn->y();
mv.nz = cn->z();
d.vertexproperties.append(mv);
}
d.vertexcount = vertecies.size();
d.indexcount = d.vertexcount;
return true;
}
I'm using a few convieniece functions which I use a lot on difference occasions and after checking even them too, I'm sure they aren't causing the problem