Original Post
Below is a screen shot of my imported OBJ inside my editor. I've been looking at several tutorials and for now - I just want to get a simple OBJ cube loaded with a color shader file. I am think I'm confused on the whole Index section, because I think this is where it's going haywire. I'll try to chainge the topology to trianglelist because now I have it set to trianglestrip.
Inside the debug console it writes the OBJ structure. 8 vertices and 12 faces. the OBJ import reverse the Index backwards also. It has to be the part where it loads the vertex and the index. Whenever ever someone has time - could they at least if I'm doing something wrong in codewise.
this part gathers the stored index count and literates the the file again - grabbing vertex data and such.
then when it's drawn - it looks like what's below. Additional, here's a wireframe shot within the editor.
[attachment=10401:OBJGoneWrong.PNG]
[attachment=10402:BadOBJWireFrame.PNG]
Thanks for the help guys! Much appreciated!
Inside the debug console it writes the OBJ structure. 8 vertices and 12 faces. the OBJ import reverse the Index backwards also. It has to be the part where it loads the vertex and the index. Whenever ever someone has time - could they at least if I'm doing something wrong in codewise.
// Read in the vertices, texture coordinates, and normals into the data structures.
// Important: Also convert to left hand coordinate system since Maya uses right hand coordinate system.
fin.get(input);
while(!fin.eof())
{
if(input == 'v')
{
fin.get(input);
// Read in the vertices.
if(input == ' ')
{
fin >> vertices[vertexIndex].x >> vertices[vertexIndex].y >> vertices[vertexIndex].z;
// Invert the Z vertex to change to left hand system.
vertices[vertexIndex].z = vertices[vertexIndex].z * -1.0f;
vertexIndex++;
}
// Read in the texture uv coordinates.
if(input == 't')
{
fin >> texcoords[texcoordIndex].x >> texcoords[texcoordIndex].y;
// Invert the V texture coordinates to left hand system.
texcoords[texcoordIndex].y = 1.0f - texcoords[texcoordIndex].y;
texcoordIndex++;
}
// Read in the normals.
if(input == 'n')
{
fin >> normals[normalIndex].x >> normals[normalIndex].y >> normals[normalIndex].z;
// Invert the Z normal to change to left hand system.
normals[normalIndex].z = normals[normalIndex].z * -1.0f;
normalIndex++;
}
}
// Read in the faces.
if(input == 'f')
{
fin.get(input);
if(input == ' ')
{
// Read the face data in backwards to convert it to a left hand system from right hand system.
fin >> faces[faceIndex].vIndex3 >> input2 >> faces[faceIndex].tIndex3 >> input2 >> faces[faceIndex].nIndex3
>> faces[faceIndex].vIndex2 >> input2 >> faces[faceIndex].tIndex2 >> input2 >> faces[faceIndex].nIndex2
>> faces[faceIndex].vIndex1 >> input2 >> faces[faceIndex].tIndex1 >> input2 >> faces[faceIndex].nIndex1;
faceIndex++;
}
}
// Read in the remainder of the line.
while(input != '\n')
{
fin.get(input);
}
// Start reading the beginning of the next line.
fin.get(input);
}
// Close the file.
fin.close();
this part gathers the stored index count and literates the the file again - grabbing vertex data and such.
D3D11_BUFFER_DESC vertexBufferDesc;
ZeroMemory( &vertexBufferDesc, sizeof(vertexBufferDesc) );
vertexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
vertexBufferDesc.ByteWidth = sizeof(VertexType) * vCount;
vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
vertexBufferDesc.CPUAccessFlags = 0;
vertexBufferDesc.MiscFlags = 0;
///////////////**************new**************////////////////////
D3D11_SUBRESOURCE_DATA vertexBufferData;
ZeroMemory( &vertexBufferData, sizeof(vertexBufferData) );
vertexBufferData.pSysMem = &vertices[0];
HR( dev->CreateBuffer( &vertexBufferDesc, &vertexBufferData, &objVertexBuffer));
//Set the vertex buffer
UINT stride = sizeof(VertexType);
UINT offset = 0;
devcon->IASetVertexBuffers( 0, 1, &objVertexBuffer, &stride, &offset );
Debug::WriteLine("OBJ Vertex Data Loaded Successfully!");
D3D11_BUFFER_DESC indexBufferDesc;
ZeroMemory( &indexBufferDesc, sizeof(indexBufferDesc) );
indexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
indexBufferDesc.ByteWidth = sizeof(FaceType) * 3 * 12;
indexBufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
indexBufferDesc.CPUAccessFlags = 0;
indexBufferDesc.MiscFlags = 0;
D3D11_SUBRESOURCE_DATA iinitData;
iinitData.pSysMem = &faces[0];
HR(dev->CreateBuffer(&indexBufferDesc, &iinitData, &objIndexBuffer));
devcon->IASetIndexBuffer( objIndexBuffer, DXGI_FORMAT_R32_UINT, 0);
Debug::WriteLine("Index Buffer from OBJ loaded Successfully!");
then when it's drawn - it looks like what's below. Additional, here's a wireframe shot within the editor.
[attachment=10401:OBJGoneWrong.PNG]
[attachment=10402:BadOBJWireFrame.PNG]
Thanks for the help guys! Much appreciated!