diff --git a/.drone.yml b/.drone.yml index 1724277..7fe6321 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,6 +1,6 @@ image: bradrydzewski/base script: - - curl -L -O premake4 https://github.com/syoyo/orebuildenv/blob/master/build/linux/bin/premake4?raw=true + - curl -L -o premake4 https://github.com/syoyo/orebuildenv/blob/master/build/linux/bin/premake4?raw=true - chmod +x ./premake4 - ./premake4 gmake - make diff --git a/examples/obj_sticher/obj_sticher.cc b/examples/obj_sticher/obj_sticher.cc index 1833216..8ec7a28 100644 --- a/examples/obj_sticher/obj_sticher.cc +++ b/examples/obj_sticher/obj_sticher.cc @@ -81,6 +81,7 @@ main( std::vector shapes; std::vector materials; shapes.resize(num_objfiles); + materials.resize(num_objfiles); for (int i = 0; i < num_objfiles; i++) { std::cout << "Loading " << argv[i+1] << " ... " << std::flush; @@ -98,7 +99,8 @@ main( std::vector out_material; StichObjs(out_shape, out_material, shapes, materials); - bool ret = WriteObj(out_filename, out_shape, out_material); + bool coordTransform = true; + bool ret = WriteObj(out_filename, out_shape, out_material, coordTransform); assert(ret); return 0; diff --git a/examples/obj_sticher/obj_writer.cc b/examples/obj_sticher/obj_writer.cc index bb12457..2c8bd7b 100644 --- a/examples/obj_sticher/obj_writer.cc +++ b/examples/obj_sticher/obj_writer.cc @@ -38,7 +38,7 @@ bool WriteMat(const std::string& filename, const std::vector& shapes, const std::vector& materials) { +bool WriteObj(const std::string& filename, const std::vector& shapes, const std::vector& materials, bool coordTransform) { FILE* fp = fopen(filename.c_str(), "w"); if (!fp) { fprintf(stderr, "Failed to open file [ %s ] for write.\n", filename.c_str()); @@ -74,10 +74,17 @@ bool WriteObj(const std::string& filename, const std::vector& for (size_t k = 0; k < shapes[i].mesh.indices.size() / 3; k++) { for (int j = 0; j < 3; j++) { int idx = shapes[i].mesh.indices[3*k+j]; - fprintf(fp, "v %f %f %f\n", - shapes[i].mesh.positions[3*idx+0], - shapes[i].mesh.positions[3*idx+1], - shapes[i].mesh.positions[3*idx+2]); + if (coordTransform) { + fprintf(fp, "v %f %f %f\n", + shapes[i].mesh.positions[3*idx+0], + shapes[i].mesh.positions[3*idx+2], + -shapes[i].mesh.positions[3*idx+1]); + } else { + fprintf(fp, "v %f %f %f\n", + shapes[i].mesh.positions[3*idx+0], + shapes[i].mesh.positions[3*idx+1], + shapes[i].mesh.positions[3*idx+2]); + } } } @@ -86,10 +93,17 @@ bool WriteObj(const std::string& filename, const std::vector& for (size_t k = 0; k < shapes[i].mesh.indices.size() / 3; k++) { for (int j = 0; j < 3; j++) { int idx = shapes[i].mesh.indices[3*k+j]; - fprintf(fp, "vn %f %f %f\n", - shapes[i].mesh.normals[3*idx+0], - shapes[i].mesh.normals[3*idx+1], - shapes[i].mesh.normals[3*idx+2]); + if (coordTransform) { + fprintf(fp, "vn %f %f %f\n", + shapes[i].mesh.normals[3*idx+0], + shapes[i].mesh.normals[3*idx+2], + -shapes[i].mesh.normals[3*idx+1]); + } else { + fprintf(fp, "vn %f %f %f\n", + shapes[i].mesh.normals[3*idx+0], + shapes[i].mesh.normals[3*idx+1], + shapes[i].mesh.normals[3*idx+2]); + } } } } @@ -119,6 +133,10 @@ bool WriteObj(const std::string& filename, const std::vector& int v1 = (3*k + 1) + 1 + v_offset; int v2 = (3*k + 2) + 1 + v_offset; + int vt0 = (3*k + 0) + 1 + vt_offset; + int vt1 = (3*k + 1) + 1 + vt_offset; + int vt2 = (3*k + 2) + 1 + vt_offset; + int material_id = shapes[i].mesh.material_ids[k]; if (material_id != prev_material_id) { std::string material_name = materials[material_id].name; @@ -128,7 +146,7 @@ bool WriteObj(const std::string& filename, const std::vector& if (has_vn && has_vt) { fprintf(fp, "f %d/%d/%d %d/%d/%d %d/%d/%d\n", - v0, v0, v0, v1, v1, v1, v2, v2, v2); + v0, vt0, v0, v1, vt1, v1, v2, vt2, v2); } else if (has_vn && !has_vt) { fprintf(fp, "f %d//%d %d//%d %d//%d\n", v0, v0, v1, v1, v2, v2); } else if (!has_vn && has_vt) { @@ -141,7 +159,7 @@ bool WriteObj(const std::string& filename, const std::vector& v_offset += shapes[i].mesh.indices.size(); //vn_offset += shapes[i].mesh.normals.size() / 3; - //vt_offset += shapes[i].mesh.texcoords.size() / 2; + vt_offset += shapes[i].mesh.texcoords.size() / 2; } diff --git a/examples/obj_sticher/obj_writer.h b/examples/obj_sticher/obj_writer.h index 00cd792..bb367b6 100644 --- a/examples/obj_sticher/obj_writer.h +++ b/examples/obj_sticher/obj_writer.h @@ -3,7 +3,7 @@ #include "../../tiny_obj_loader.h" -extern bool WriteObj(const std::string& filename, const std::vector& shapes, const std::vector& materials); +extern bool WriteObj(const std::string& filename, const std::vector& shapes, const std::vector& materials, bool coordTransform = false); #endif // __OBJ_WRITER_H__