I want to print out the earth obj, but it keeps printing strangely like a picture.
The vertexes are printed in an empty form in the middle.
_mesh = new Mesh("obj\\13902_Earth_v1_l3.obj", "obj\\Earth_diff.jpg");
First, enter the file name like this. Over there, _mesh is the object of the Mesh class that I created.
Mesh(char* obj, char* texture) {
open(obj);
loadTexture(texture, _textureIndex);
}
This is the constructor of the Mesh class. The Opne function outputs obj, and loadTexture reads the texture. just look at the Open function.
void Mesh::open(char* file)
{
FILE* fp;
char buffer[100] = { 0 };
Vec3<double> pos;
int index[3], tex[3], empty[3];
int id = 0;
_minBound.Set(1000000.0);
_maxBound.Set(-1000000.0);
fopen_s(&fp, file, "r");
while (fscanf(fp, "%s %lf %lf %lf", buffer, &pos[0], &pos[1], &pos[2]) != EOF)
{
// v 0.2 0.3 0.1
// vt
if (buffer[0] == 'v' && buffer[1] == NULL) {
for (int i = 0; i < 3; i++) {
if (_minBound[i] > pos[i]) _minBound[i] = pos[i];
if (_maxBound[i] < pos[i]) _maxBound[i] = pos[i];
}
_vertices.push_back(new Vertex(id, pos));
}
}
// read texture coordinate of vertics
id = 0;
fseek(fp, 0, SEEK_SET);
while (fscanf(fp, "%s %lf %lf", &buffer, &pos[0], &pos[1]) != EOF) {
if (!strcmp(buffer, "vt")) {
_textureCoords.push_back(new Texture(pos[0], 1.0 - pos[1], 0.0));
}
}
// read faces
id = 0;
fseek(fp, 0, SEEK_SET);
while (fscanf(fp, "%s %d/%d/%d %d/%d/%d %d/%d/%d", &buffer, &index[0], &tex[0], &empty[0], &index[1], &tex[1], &empty[1], &index[2], &tex[2], &empty[2]) != EOF) {
if (buffer[0] == 'f' && buffer[1] == NULL) {
auto v0 = _vertices[index[0] - 1];
auto v1 = _vertices[index[1] - 1];
auto v2 = _vertices[index[2] - 1];
_faces.push_back(new Face(id++, v0, v1, v2, tex[0] - 1, tex[1] - 1, tex[2] - 1));
//_faces.push_back(new Face(index++, _vertices[v_index[0] - 1], _vertices[v_index[1] - 1], _vertices[v_index[2] - 1]));
}
}
fclose(fp);
moveToCenter(10.0);
makeList();
computeNormal();
}
In the code, _vertices and _faces are class vectors that I've created. It's simply a text file in this format that's made vector computation.
And I didn't read the value of vn there, and I didn't read the third value of f. Then at least the vertex value would have been entered well, but why does it print out like that?
This is what it looks like when I don't put on textures.
All other sphere objects are printed in that form. How do we solve this?