-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -5,7 +5,7 @@ | |||
#include <vector> | ||||
#include "model.h" | ||||
|
||||
Model::Model(const char *filename) : verts_(), faces_() { | ||||
Model::Model(const char *filename) : verts_(), faces_(), norms_(), uv_() { | ||||
std::ifstream in; | ||||
in.open (filename, std::ifstream::in); | ||||
if (in.fail()) return; | ||||
|
@@ -19,18 +19,29 @@ Model::Model(const char *filename) : verts_(), faces_() { | |||
Vec3f v; | ||||
for (int i=0;i<3;i++) iss >> v[i]; | ||||
verts_.push_back(v); | ||||
} else if (!line.compare(0, 2, "f ")) { | ||||
std::vector<int> f; | ||||
int itrash, idx; | ||||
} else if (!line.compare(0, 3, "vn ")) { | ||||
iss >> trash >> trash; | ||||
Vec3f n; | ||||
for (int i=0;i<3;i++) iss >> n[i]; | ||||
norms_.push_back(n); | ||||
} else if (!line.compare(0, 3, "vt ")) { | ||||
iss >> trash >> trash; | ||||
Vec2f uv; | ||||
for (int i=0;i<2;i++) iss >> uv[i]; | ||||
uv_.push_back(uv); | ||||
} else if (!line.compare(0, 2, "f ")) { | ||||
std::vector<Vec3i> f; | ||||
Vec3i tmp; | ||||
iss >> trash; | ||||
while (iss >> idx >> trash >> itrash >> trash >> itrash) { | ||||
idx--; // in wavefront obj all indices start at 1, not zero | ||||
f.push_back(idx); | ||||
while (iss >> tmp[0] >> trash >> tmp[1] >> trash >> tmp[2]) { | ||||
for (int i=0; i<3; i++) tmp[i]--; // in wavefront obj all indices start at 1, not zero | ||||
f.push_back(tmp); | ||||
} | ||||
faces_.push_back(f); | ||||
} | ||||
} | ||||
std::cerr << "# v# " << verts_.size() << " f# " << faces_.size() << std::endl; | ||||
std::cerr << "# v# " << verts_.size() << " f# " << faces_.size() << " vt# " << uv_.size() << " vn# " << norms_.size() << std::endl; | ||||
load_texture(filename, "_diffuse.tga", diffusemap_); | ||||
} | ||||
|
||||
Model::~Model() { | ||||
|
@@ -45,10 +56,32 @@ int Model::nfaces() { | |||
} | ||||
|
||||
std::vector<int> Model::face(int idx) { | ||||
return faces_[idx]; | ||||
std::vector<int> face; | ||||
for (int i=0; i<(int)faces_[idx].size(); i++) face.push_back(faces_[idx][i][0]); | ||||
return face; | ||||
} | ||||
|
||||
Vec3f Model::vert(int i) { | ||||
return verts_[i]; | ||||
} | ||||
|
||||
void Model::load_texture(std::string filename, const char *suffix, TGAImage &img) { | ||||
std::string texfile(filename); | ||||
size_t dot = texfile.find_last_of("."); | ||||
if (dot!=std::string::npos) { | ||||
texfile = texfile.substr(0,dot) + std::string(suffix); | ||||
std::cerr << "texture file " << texfile << " loading " << (img.read_tga_file(texfile.c_str()) ? "ok" : "failed") << std::endl; | ||||
img.flip_vertically(); | ||||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
ssloy
via email
Author
Owner
|
image.flip_vertically(); // i want to have the origin at the left bottom corner of the image |
image.flip_vertically(); // i want to have the origin at the left bottom corner of the image
Не совсем понял ошибка ли это, или я что-то делаю не правильно просто.
This comment has been minimized.
This comment has been minimized.
Sorry, something went wrong.
Почему изображение переворачивается дважды? По стандарту вроде немного другая логика здесь.