diff --git a/enginecustom/applicationclass.cpp b/enginecustom/applicationclass.cpp
index ff5e4d2..75b676a 100644
--- a/enginecustom/applicationclass.cpp
+++ b/enginecustom/applicationclass.cpp
@@ -55,7 +55,7 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
m_Camera->SetRotation(0.0f, 0.0f, 10.0f);
// Set the file name of the model.
- strcpy_s(modelFilename, "cube.obj");
+ strcpy_s(modelFilename, "cylinder.obj");
strcpy_s(outputModelFilename, "output.txt");
diff --git a/enginecustom/enginecustom.vcxproj b/enginecustom/enginecustom.vcxproj
index 369e28f..df8c573 100644
--- a/enginecustom/enginecustom.vcxproj
+++ b/enginecustom/enginecustom.vcxproj
@@ -84,6 +84,11 @@
Document
+
+
+ Document
+
+
17.0
Win32Proj
diff --git a/enginecustom/modelclass.cpp b/enginecustom/modelclass.cpp
index 3debce5..0cc0aeb 100644
--- a/enginecustom/modelclass.cpp
+++ b/enginecustom/modelclass.cpp
@@ -344,24 +344,37 @@ void ModelClass::ConvertObjToTxt(const std::string& inputFilename, const std::st
normals.push_back(normal);
}
else if (prefix == "f") {
- ModelType v;
+ std::vector posIndices, texIndices, normIndices;
char slash; // To skip slashes
int posIndex, texIndex, normIndex;
- for (int i = 0; i < 3; ++i) { // For each vertex of the face
- if (!(iss >> posIndex >> slash >> texIndex >> slash >> normIndex)) { break; }
+ // Read all indices of the face
+ while (iss >> posIndex >> slash >> texIndex >> slash >> normIndex) {
+ posIndices.push_back(posIndex);
+ texIndices.push_back(texIndex);
+ normIndices.push_back(normIndex);
+ }
- // .obj indices start at 1, so subtract 1 to get 0-based indices
- v.x = positions[posIndex - 1].x;
- v.y = positions[posIndex - 1].y;
- v.z = positions[posIndex - 1].z;
- v.tu = texCoords[texIndex - 1].x;
- v.tv = texCoords[texIndex - 1].y;
- v.nx = normals[normIndex - 1].x;
- v.ny = normals[normIndex - 1].y;
- v.nz = normals[normIndex - 1].z;
+ // For each triangle in the face
+ for (size_t i = 1; i < posIndices.size() - 1; ++i) {
+ ModelType v[3]; // Vertices of the triangle
- vertices.push_back(v);
+ // Indices of the vertices of the triangle
+ int indices[3] = { 0, i, i + 1 };
+
+ for (int j = 0; j < 3; ++j) {
+ // .obj indices start at 1, so subtract 1 to get 0-based indices
+ v[j].x = positions[posIndices[indices[j]] - 1].x;
+ v[j].y = positions[posIndices[indices[j]] - 1].y;
+ v[j].z = positions[posIndices[indices[j]] - 1].z;
+ v[j].tu = texCoords[texIndices[indices[j]] - 1].x;
+ v[j].tv = texCoords[texIndices[indices[j]] - 1].y;
+ v[j].nx = normals[normIndices[indices[j]] - 1].x;
+ v[j].ny = normals[normIndices[indices[j]] - 1].y;
+ v[j].nz = normals[normIndices[indices[j]] - 1].z;
+
+ vertices.push_back(v[j]);
+ }
}
}
}
diff --git a/enginecustom/objects/New Bitmap Image.mtl b/enginecustom/objects/New Bitmap Image.mtl
deleted file mode 100644
index e69de29..0000000
diff --git a/enginecustom/output.txt b/enginecustom/output.txt
index a0908a9..ddf4730 100644
--- a/enginecustom/output.txt
+++ b/enginecustom/output.txt
@@ -1,262 +1,4 @@
-Vertex Count: 258
+Vertex Count: 0
Data:
-1 1 -1 0.625 0.5 0 1 0
--1 1 -1 0.875 0.5 0 1 0
--1 1 1 0.875 0.75 0 1 0
-1 -1 1 0.375 0.75 0 0 1
-1 -0.777778 1 0.402778 0.75 0 0 1
-1 -0.555556 1 0.430556 0.75 0 0 1
--1 -1 1 0.375 0 -1 0 0
--1 1 1 0.625 0 -1 0 0
--1 1 -1 0.625 0.25 -1 0 0
--1 -1 -1 0.125 0.5 0 -1 0
-1 -1 -1 0.375 0.5 0 -1 0
-1 -1 -0.777778 0.375 0.527778 0 -1 0
-1 0.777778 0.777778 0.597222 0.722222 1 0 0
-1 1 0.777778 0.625 0.722222 1 0 0
-1 1 1 0.625 0.75 1 0 0
--1 -1 -1 0.375 0.25 0 0 -1
--1 1 -1 0.625 0.25 0 0 -1
-1 1 -1 0.625 0.5 0 0 -1
-1 -1 0.777778 0.375 0.722222 1 0 0
-1 -0.777778 0.777778 0.402778 0.722222 1 0 0
-1 -0.777778 1 0.402778 0.75 1 0 0
-1 -0.777778 0.777778 0.402778 0.722222 1 0 0
-1 -0.555556 0.777778 0.430556 0.722222 1 0 0
-1 -0.555556 1 0.430556 0.75 1 0 0
-1 -0.555556 0.777778 0.430556 0.722222 1 0 0
-1 -0.333333 0.777778 0.458333 0.722222 1 0 0
-1 -0.333333 1 0.458333 0.75 1 0 0
-1 -0.333333 0.777778 0.458333 0.722222 1 0 0
-1 -0.111111 0.777778 0.486111 0.722222 1 0 0
-1 -0.111111 1 0.486111 0.75 1 0 0
-1 -0.111111 0.777778 0.486111 0.722222 1 0 0
-1 0.111111 0.777778 0.513889 0.722222 1 0 0
-1 0.111111 1 0.513889 0.75 1 0 0
-1 0.111111 0.777778 0.513889 0.722222 1 0 0
-1 0.333333 0.777778 0.541667 0.722222 1 0 0
-1 0.333333 1 0.541667 0.75 1 0 0
-1 0.333333 0.777778 0.541667 0.722222 1 0 0
-1 0.555556 0.777778 0.569445 0.722222 1 0 0
-1 0.555556 1 0.569444 0.75 1 0 0
-1 0.555556 0.777778 0.569445 0.722222 1 0 0
-1 0.777778 0.777778 0.597222 0.722222 1 0 0
-1 0.777778 1 0.597222 0.75 1 0 0
-1 -1 -1 0.375 0.5 1 0 0
-1 -0.777778 -1 0.402778 0.5 1 0 0
-1 -0.777778 -0.777778 0.402778 0.527778 1 0 0
-1 -1 -0.777778 0.375 0.527778 1 0 0
-1 -0.777778 -0.777778 0.402778 0.527778 1 0 0
-1 -0.777778 -0.555556 0.402778 0.555556 1 0 0
-1 -1 -0.555556 0.375 0.555556 1 0 0
-1 -0.777778 -0.555556 0.402778 0.555556 1 0 0
-1 -0.777778 -0.333333 0.402778 0.583333 1 0 0
-1 -1 -0.333333 0.375 0.583333 1 0 0
-1 -0.777778 -0.333333 0.402778 0.583333 1 0 0
-1 -0.777778 -0.111111 0.402778 0.611111 1 0 0
-1 -1 -0.111111 0.375 0.611111 1 0 0
-1 -0.777778 -0.111111 0.402778 0.611111 1 0 0
-1 -0.777778 0.111111 0.402778 0.638889 1 0 0
-1 -1 0.111111 0.375 0.638889 1 0 0
-1 -0.777778 0.111111 0.402778 0.638889 1 0 0
-1 -0.777778 0.333333 0.402778 0.666667 1 0 0
-1 -1 0.333333 0.375 0.666667 1 0 0
-1 -0.777778 0.333333 0.402778 0.666667 1 0 0
-1 -0.777778 0.555556 0.402778 0.694444 1 0 0
-1 -1 0.555556 0.375 0.694444 1 0 0
-1 -0.777778 0.555556 0.402778 0.694444 1 0 0
-1 -0.777778 0.777778 0.402778 0.722222 1 0 0
-1 -0.777778 -1 0.402778 0.5 1 0 0
-1 -0.555556 -1 0.430556 0.5 1 0 0
-1 -0.555556 -0.777778 0.430556 0.527778 1 0 0
-1 -0.777778 -0.777778 0.402778 0.527778 1 0 0
-1 -0.555556 -0.777778 0.430556 0.527778 1 0 0
-1 -0.555556 -0.555556 0.430556 0.555556 1 0 0
-1 -0.777778 -0.333333 0.402778 0.583333 1 0 0
-1 -0.555556 -0.333333 0.430556 0.583333 1 0 0
-1 -0.555556 -0.111111 0.430556 0.611111 1 0 0
-1 -0.777778 -0.111111 0.402778 0.611111 1 0 0
-1 -0.555556 -0.111111 0.430556 0.611111 1 0 0
-1 -0.555556 0.111111 0.430556 0.638889 1 0 0
-1 -0.777778 0.333333 0.402778 0.666667 1 0 0
-1 -0.555556 0.333333 0.430556 0.666667 1 0 0
-1 -0.555556 0.555556 0.430556 0.694444 1 0 0
-1 -0.555556 -1 0.430556 0.5 1 0 0
-1 -0.333333 -1 0.458333 0.5 1 0 0
-1 -0.333333 -0.777778 0.458333 0.527778 1 0 0
-1 -0.555556 -0.777778 0.430556 0.527778 1 0 0
-1 -0.333333 -0.777778 0.458333 0.527778 1 0 0
-1 -0.333333 -0.555556 0.458333 0.555556 1 0 0
-1 -0.555556 -0.333333 0.430556 0.583333 1 0 0
-1 -0.333333 -0.333333 0.458333 0.583333 1 0 0
-1 -0.333333 -0.111111 0.458333 0.611111 1 0 0
-1 -0.555556 -0.111111 0.430556 0.611111 1 0 0
-1 -0.333333 -0.111111 0.458333 0.611111 1 0 0
-1 -0.333333 0.111111 0.458333 0.638889 1 0 0
-1 -0.555556 0.333333 0.430556 0.666667 1 0 0
-1 -0.333333 0.333333 0.458333 0.666667 1 0 0
-1 -0.333333 0.555556 0.458333 0.694444 1 0 0
-1 -0.333333 -1 0.458333 0.5 1 0 0
-1 -0.111111 -1 0.486111 0.5 1 0 0
-1 -0.111111 -0.777778 0.486111 0.527778 1 0 0
-1 -0.333333 -0.777778 0.458333 0.527778 1 0 0
-1 -0.111111 -0.777778 0.486111 0.527778 1 0 0
-1 -0.111111 -0.555556 0.486111 0.555556 1 0 0
-1 -0.333333 -0.333333 0.458333 0.583333 1 0 0
-1 -0.111111 -0.333333 0.486111 0.583333 1 0 0
-1 -0.111111 -0.111111 0.486111 0.611111 1 0 0
-1 -0.333333 -0.111111 0.458333 0.611111 1 0 0
-1 -0.111111 -0.111111 0.486111 0.611111 1 0 0
-1 -0.111111 0.111111 0.486111 0.638889 1 0 0
-1 -0.333333 0.333333 0.458333 0.666667 1 0 0
-1 -0.111111 0.333333 0.486111 0.666667 1 0 0
-1 -0.111111 0.555556 0.486111 0.694444 1 0 0
-1 -0.111111 -1 0.486111 0.5 1 0 0
-1 0.111111 -1 0.513889 0.5 1 0 0
-1 0.111111 -0.777778 0.513889 0.527778 1 0 0
-1 -0.111111 -0.777778 0.486111 0.527778 1 0 0
-1 0.111111 -0.777778 0.513889 0.527778 1 0 0
-1 0.111111 -0.555556 0.513889 0.555556 1 0 0
-1 -0.111111 -0.333333 0.486111 0.583333 1 0 0
-1 0.111111 -0.333333 0.513889 0.583333 1 0 0
-1 0.111111 -0.111111 0.513889 0.611111 1 0 0
-1 -0.111111 -0.111111 0.486111 0.611111 1 0 0
-1 0.111111 -0.111111 0.513889 0.611111 1 0 0
-1 0.111111 0.111111 0.513889 0.638889 1 0 0
-1 0.111111 -1 0.513889 0.5 1 0 0
-1 0.333333 -1 0.541667 0.5 1 0 0
-1 0.333333 -0.777778 0.541667 0.527778 1 0 0
-1 0.111111 -0.777778 0.513889 0.527778 1 0 0
-1 0.333333 -0.777778 0.541667 0.527778 1 0 0
-1 0.333333 -0.555556 0.541667 0.555556 1 0 0
-1 0.111111 -0.333333 0.513889 0.583333 1 0 0
-1 0.333333 -0.333333 0.541667 0.583333 1 0 0
-1 0.333333 -0.111111 0.541667 0.611111 1 0 0
-1 0.111111 -0.111111 0.513889 0.611111 1 0 0
-1 0.333333 -0.111111 0.541667 0.611111 1 0 0
-1 0.333333 0.111111 0.541667 0.638889 1 0 0
-1 0.111111 0.333333 0.513889 0.666667 1 0 0
-1 0.333333 0.333333 0.541667 0.666667 1 0 0
-1 0.333333 0.555556 0.541667 0.694444 1 0 0
-1 0.333333 -1 0.541667 0.5 1 0 0
-1 0.555556 -1 0.569444 0.5 1 0 0
-1 0.555556 -0.777778 0.569445 0.527778 1 0 0
-1 0.333333 -0.777778 0.541667 0.527778 1 0 0
-1 0.555556 -0.777778 0.569445 0.527778 1 0 0
-1 0.555556 -0.555556 0.569445 0.555556 1 0 0
-1 0.333333 -0.555556 0.541667 0.555556 1 0 0
-1 0.555556 -0.555556 0.569445 0.555556 1 0 0
-1 0.555556 -0.333333 0.569445 0.583333 1 0 0
-1 0.333333 -0.333333 0.541667 0.583333 1 0 0
-1 0.555556 -0.333333 0.569445 0.583333 1 0 0
-1 0.555556 -0.111111 0.569445 0.611111 1 0 0
-1 0.333333 -0.111111 0.541667 0.611111 1 0 0
-1 0.555556 -0.111111 0.569445 0.611111 1 0 0
-1 0.555556 0.111111 0.569445 0.638889 1 0 0
-1 0.333333 0.333333 0.541667 0.666667 1 0 0
-1 0.555556 0.333333 0.569445 0.666667 1 0 0
-1 0.555556 0.555556 0.569445 0.694444 1 0 0
-1 0.555556 -1 0.569444 0.5 1 0 0
-1 0.777778 -1 0.597222 0.5 1 0 0
-1 0.777778 -0.777778 0.597222 0.527778 1 0 0
-1 0.555556 -0.777778 0.569445 0.527778 1 0 0
-1 0.777778 -0.777778 0.597222 0.527778 1 0 0
-1 0.777778 -0.555556 0.597222 0.555556 1 0 0
-1 0.555556 -0.333333 0.569445 0.583333 1 0 0
-1 0.777778 -0.333333 0.597222 0.583333 1 0 0
-1 0.777778 -0.111111 0.597222 0.611111 1 0 0
-1 0.555556 -0.111111 0.569445 0.611111 1 0 0
-1 0.777778 -0.111111 0.597222 0.611111 1 0 0
-1 0.777778 0.111111 0.597222 0.638889 1 0 0
-1 0.555556 0.333333 0.569445 0.666667 1 0 0
-1 0.777778 0.333333 0.597222 0.666667 1 0 0
-1 0.777778 0.555556 0.597222 0.694444 1 0 0
-1 0.777778 -1 0.597222 0.5 1 0 0
-1 1 -1 0.625 0.5 1 0 0
-1 1 -0.777778 0.625 0.527778 1 0 0
-1 0.777778 -0.777778 0.597222 0.527778 1 0 0
-1 1 -0.777778 0.625 0.527778 1 0 0
-1 1 -0.555556 0.625 0.555556 1 0 0
-1 0.777778 -0.555556 0.597222 0.555556 1 0 0
-1 1 -0.555556 0.625 0.555556 1 0 0
-1 1 -0.333333 0.625 0.583333 1 0 0
-1 0.777778 -0.333333 0.597222 0.583333 1 0 0
-1 1 -0.333333 0.625 0.583333 1 0 0
-1 1 -0.111111 0.625 0.611111 1 0 0
-1 0.777778 -0.111111 0.597222 0.611111 1 0 0
-1 1 -0.111111 0.625 0.611111 1 0 0
-1 1 0.111111 0.625 0.638889 1 0 0
-1 0.777778 0.111111 0.597222 0.638889 1 0 0
-1 1 0.111111 0.625 0.638889 1 0 0
-1 1 0.333333 0.625 0.666667 1 0 0
-1 0.777778 0.333333 0.597222 0.666667 1 0 0
-1 1 0.333333 0.625 0.666667 1 0 0
-1 1 0.555556 0.625 0.694444 1 0 0
-1 0.777778 0.555556 0.597222 0.694444 1 0 0
-1 1 0.555556 0.625 0.694444 1 0 0
-1 1 0.777778 0.625 0.722222 1 0 0
-1 -0.777778 -0.555556 0.402778 0.555556 1 0 0
-1 -0.555556 -0.555556 0.430556 0.555556 1 0 0
-1 -0.555556 -0.333333 0.430556 0.583333 1 0 0
-1 -0.777778 0.111111 0.402778 0.638889 1 0 0
-1 -0.555556 0.111111 0.430556 0.638889 1 0 0
-1 -0.555556 0.333333 0.430556 0.666667 1 0 0
-1 -0.777778 0.555556 0.402778 0.694444 1 0 0
-1 -0.555556 0.555556 0.430556 0.694444 1 0 0
-1 -0.555556 0.777778 0.430556 0.722222 1 0 0
-1 -0.555556 -0.555556 0.430556 0.555556 1 0 0
-1 -0.333333 -0.555556 0.458333 0.555556 1 0 0
-1 -0.333333 -0.333333 0.458333 0.583333 1 0 0
-1 -0.555556 0.111111 0.430556 0.638889 1 0 0
-1 -0.333333 0.111111 0.458333 0.638889 1 0 0
-1 -0.333333 0.333333 0.458333 0.666667 1 0 0
-1 -0.555556 0.555556 0.430556 0.694444 1 0 0
-1 -0.333333 0.555556 0.458333 0.694444 1 0 0
-1 -0.333333 0.777778 0.458333 0.722222 1 0 0
-1 -0.333333 -0.555556 0.458333 0.555556 1 0 0
-1 -0.111111 -0.555556 0.486111 0.555556 1 0 0
-1 -0.111111 -0.333333 0.486111 0.583333 1 0 0
-1 -0.333333 0.111111 0.458333 0.638889 1 0 0
-1 -0.111111 0.111111 0.486111 0.638889 1 0 0
-1 -0.111111 0.333333 0.486111 0.666667 1 0 0
-1 -0.333333 0.555556 0.458333 0.694444 1 0 0
-1 -0.111111 0.555556 0.486111 0.694444 1 0 0
-1 -0.111111 0.777778 0.486111 0.722222 1 0 0
-1 -0.111111 -0.555556 0.486111 0.555556 1 0 0
-1 0.111111 -0.555556 0.513889 0.555556 1 0 0
-1 0.111111 -0.333333 0.513889 0.583333 1 0 0
-1 -0.111111 0.111111 0.486111 0.638889 1 0 0
-1 0.111111 0.111111 0.513889 0.638889 1 0 0
-1 0.111111 0.333333 0.513889 0.666667 1 0 0
-1 -0.111111 0.333333 0.486111 0.666667 1 0 0
-1 0.111111 0.333333 0.513889 0.666667 1 0 0
-1 0.111111 0.555556 0.513889 0.694444 1 0 0
-1 -0.111111 0.555556 0.486111 0.694444 1 0 0
-1 0.111111 0.555556 0.513889 0.694444 1 0 0
-1 0.111111 0.777778 0.513889 0.722222 1 0 0
-1 0.111111 -0.555556 0.513889 0.555556 1 0 0
-1 0.333333 -0.555556 0.541667 0.555556 1 0 0
-1 0.333333 -0.333333 0.541667 0.583333 1 0 0
-1 0.111111 0.111111 0.513889 0.638889 1 0 0
-1 0.333333 0.111111 0.541667 0.638889 1 0 0
-1 0.333333 0.333333 0.541667 0.666667 1 0 0
-1 0.111111 0.555556 0.513889 0.694444 1 0 0
-1 0.333333 0.555556 0.541667 0.694444 1 0 0
-1 0.333333 0.777778 0.541667 0.722222 1 0 0
-1 0.333333 0.111111 0.541667 0.638889 1 0 0
-1 0.555556 0.111111 0.569445 0.638889 1 0 0
-1 0.555556 0.333333 0.569445 0.666667 1 0 0
-1 0.333333 0.555556 0.541667 0.694444 1 0 0
-1 0.555556 0.555556 0.569445 0.694444 1 0 0
-1 0.555556 0.777778 0.569445 0.722222 1 0 0
-1 0.555556 -0.555556 0.569445 0.555556 1 0 0
-1 0.777778 -0.555556 0.597222 0.555556 1 0 0
-1 0.777778 -0.333333 0.597222 0.583333 1 0 0
-1 0.555556 0.111111 0.569445 0.638889 1 0 0
-1 0.777778 0.111111 0.597222 0.638889 1 0 0
-1 0.777778 0.333333 0.597222 0.666667 1 0 0
-1 0.555556 0.555556 0.569445 0.694444 1 0 0
-1 0.777778 0.555556 0.597222 0.694444 1 0 0
-1 0.777778 0.777778 0.597222 0.722222 1 0 0