Alter the OBJ loader to allow for texturing

This commit is contained in:
2023-12-22 09:44:03 -05:00
parent 4b0a4dbd43
commit 4b16aefac7
2 changed files with 45 additions and 25 deletions

View File

@@ -1,24 +1,38 @@
# Blender v3.6.4 OBJ File: ''
# www.blender.org
o Cube
v 0.900000 0.900000 -0.900000
v 0.900000 -0.900000 -0.900000
v 0.900000 0.900000 0.900000
v 0.900000 -0.900000 0.900000
v -0.900000 0.900000 -0.900000
v -0.900000 -0.900000 -0.900000
v -0.900000 0.900000 0.900000
v -0.900000 -0.900000 0.900000
v 1.000000 1.000000 -1.000000
v 1.000000 -1.000000 -1.000000
v 1.000000 1.000000 1.000000
v 1.000000 -1.000000 1.000000
v -1.000000 1.000000 -1.000000
v -1.000000 -1.000000 -1.000000
v -1.000000 1.000000 1.000000
v -1.000000 -1.000000 1.000000
vt 0.875000 0.500000
vt 0.625000 0.750000
vt 0.625000 0.500000
vt 0.375000 1.000000
vt 0.375000 0.750000
vt 0.625000 0.000000
vt 0.375000 0.250000
vt 0.375000 0.000000
vt 0.375000 0.500000
vt 0.125000 0.750000
vt 0.125000 0.500000
vt 0.625000 0.250000
vt 0.875000 0.750000
vt 0.625000 1.000000
s off
f 5 3 1
f 3 8 4
f 7 6 8
f 2 8 6
f 1 4 2
f 5 2 6
f 5 7 3
f 3 7 8
f 7 5 6
f 2 4 8
f 1 3 4
f 5 1 2
f 5/1 3/2 1/3
f 3/2 8/4 4/5
f 7/6 6/7 8/8
f 2/9 8/10 6/11
f 1/3 4/5 2/9
f 5/12 2/9 6/7
f 5/1 7/13 3/2
f 3/2 7/14 8/4
f 7/6 5/12 6/7
f 2/9 4/5 8/10
f 1/3 3/2 4/5
f 5/12 1/3 2/9

View File

@@ -11,6 +11,7 @@
struct Vertex {
GLfloat x, y, z;
GLfloat u, v;
};
class VertexArray {
@@ -43,12 +44,17 @@ public:
float x, y, z;
stream >> x >> y >> z;
vertices.push_back({x, y, z});
} else if (prefix == "vt") {
float u, v;
stream >> u >> v;
vertices.back().u = u;
vertices.back().v = v;
} else if (prefix == "f") {
unsigned int v1, v2, v3;
stream >> v1 >> v2 >> v3;
indices.push_back(v1 - 1);
indices.push_back(v2 - 1);
indices.push_back(v3 - 1);
unsigned int index, texCoordIndex;
char slash;
while (stream >> index >> slash >> texCoordIndex) {
indices.push_back(index - 1);
}
}
}
file.close();