diff --git a/README.md b/README.md index 47477f8..93ae79a 100644 --- a/README.md +++ b/README.md @@ -26,11 +26,20 @@ Old version is available `v0.9.x` branch https://github.com/syoyo/tinyobjloader/ ## What's new +### Version 2.x + +* Refactor API +* Support triangulation for concave polygons(#151) + +### Version 1.x + +Avaiable in `v1.x.y` branch. + * 20 Aug, 2016 : Bump version v1.0.0. New data structure and API! -### Old version +### Older version -Previous old version is avaiable in `v0.9.x` branch. +Older version is avaiable in `v0.9.x` branch. ## Example @@ -49,7 +58,11 @@ http://casual-effects.com/data/index.html TinyObjLoader is successfully used in ... -### New version(v1.0.x) +### New version(v2.x) + +* Your project here! (Letting us know via github issue is welcome!) + +### Old version(v1.x) * Double precision support through `TINYOBJLOADER_USE_DOUBLE` thanks to noma * Loading models in Vulkan Tutorial https://vulkan-tutorial.com/Loading_models @@ -60,7 +73,7 @@ TinyObjLoader is successfully used in ... * VFPR - a Vulkan Forward Plus Renderer : https://github.com/WindyDarian/Vulkan-Forward-Plus-Renderer * Your project here! (Letting us know via github issue is welcome!) -### Old version(v0.9.x) +### Older version(v0.9.x) * bullet3 https://github.com/erwincoumans/bullet3 * pbrt-v2 https://github.com/mmp/pbrt-v2 @@ -228,12 +241,12 @@ for (size_t s = 0; s < shapes.size(); s++) { for (size_t v = 0; v < fv; v++) { // access to vertex tinyobj::index_t idx = shapes[s].mesh.indices[index_offset + v]; - tinyobj::real_t vx = attrib.vertices[3*idx.vertex_index+0]; - tinyobj::real_t vy = attrib.vertices[3*idx.vertex_index+1]; - tinyobj::real_t vz = attrib.vertices[3*idx.vertex_index+2]; - tinyobj::real_t nx = attrib.normals[3*idx.normal_index+0]; - tinyobj::real_t ny = attrib.normals[3*idx.normal_index+1]; - tinyobj::real_t nz = attrib.normals[3*idx.normal_index+2]; + tinyobj::real_t vx = attrib.vertices[idx.vertex_index].x; + tinyobj::real_t vy = attrib.vertices[idx.vertex_index].y; + tinyobj::real_t vz = attrib.vertices[idx.vertex_index].z; + tinyobj::real_t nx = attrib.normals[idx.normal_index].x; + tinyobj::real_t ny = attrib.normals[idx.normal_index].y; + tinyobj::real_t nz = attrib.normals[idx.normal_index].z; tinyobj::real_t tx = attrib.texcoords[2*idx.texcoord_index+0]; tinyobj::real_t ty = attrib.texcoords[2*idx.texcoord_index+1]; // Optional: vertex colors diff --git a/experimental/README.md b/experimental/multithreaded/README.md similarity index 100% rename from experimental/README.md rename to experimental/multithreaded/README.md diff --git a/experimental/lfpAlloc/Allocator.hpp b/experimental/multithreaded/lfpAlloc/Allocator.hpp similarity index 100% rename from experimental/lfpAlloc/Allocator.hpp rename to experimental/multithreaded/lfpAlloc/Allocator.hpp diff --git a/experimental/lfpAlloc/ChunkList.hpp b/experimental/multithreaded/lfpAlloc/ChunkList.hpp similarity index 100% rename from experimental/lfpAlloc/ChunkList.hpp rename to experimental/multithreaded/lfpAlloc/ChunkList.hpp diff --git a/experimental/lfpAlloc/LICENSE b/experimental/multithreaded/lfpAlloc/LICENSE similarity index 100% rename from experimental/lfpAlloc/LICENSE rename to experimental/multithreaded/lfpAlloc/LICENSE diff --git a/experimental/lfpAlloc/Pool.hpp b/experimental/multithreaded/lfpAlloc/Pool.hpp similarity index 100% rename from experimental/lfpAlloc/Pool.hpp rename to experimental/multithreaded/lfpAlloc/Pool.hpp diff --git a/experimental/lfpAlloc/PoolDispatcher.hpp b/experimental/multithreaded/lfpAlloc/PoolDispatcher.hpp similarity index 100% rename from experimental/lfpAlloc/PoolDispatcher.hpp rename to experimental/multithreaded/lfpAlloc/PoolDispatcher.hpp diff --git a/experimental/lfpAlloc/Utils.hpp b/experimental/multithreaded/lfpAlloc/Utils.hpp similarity index 100% rename from experimental/lfpAlloc/Utils.hpp rename to experimental/multithreaded/lfpAlloc/Utils.hpp diff --git a/experimental/premake5.lua b/experimental/multithreaded/premake5.lua similarity index 100% rename from experimental/premake5.lua rename to experimental/multithreaded/premake5.lua diff --git a/experimental/tinyobj_loader_opt.h b/experimental/multithreaded/tinyobj_loader_opt.h similarity index 100% rename from experimental/tinyobj_loader_opt.h rename to experimental/multithreaded/tinyobj_loader_opt.h diff --git a/experimental/trackball.cc b/experimental/multithreaded/trackball.cc similarity index 100% rename from experimental/trackball.cc rename to experimental/multithreaded/trackball.cc diff --git a/experimental/trackball.h b/experimental/multithreaded/trackball.h similarity index 100% rename from experimental/trackball.h rename to experimental/multithreaded/trackball.h diff --git a/experimental/viewer.cc b/experimental/multithreaded/viewer.cc similarity index 100% rename from experimental/viewer.cc rename to experimental/multithreaded/viewer.cc diff --git a/loader_example.cc b/loader_example.cc index 203fbf8..72fbfd5 100644 --- a/loader_example.cc +++ b/loader_example.cc @@ -106,24 +106,24 @@ static void PrintInfo(const tinyobj::attrib_t& attrib, std::cout << "# of shapes : " << shapes.size() << std::endl; std::cout << "# of materials : " << materials.size() << std::endl; - for (size_t v = 0; v < attrib.vertices.size() / 3; v++) { + for (size_t v = 0; v < attrib.vertices.size(); v++) { printf(" v[%ld] = (%f, %f, %f)\n", static_cast(v), - static_cast(attrib.vertices[3 * v + 0]), - static_cast(attrib.vertices[3 * v + 1]), - static_cast(attrib.vertices[3 * v + 2])); + static_cast(attrib.vertices[v].x), + static_cast(attrib.vertices[v].y), + static_cast(attrib.vertices[v].z)); } - for (size_t v = 0; v < attrib.normals.size() / 3; v++) { + for (size_t v = 0; v < attrib.normals.size(); v++) { printf(" n[%ld] = (%f, %f, %f)\n", static_cast(v), - static_cast(attrib.normals[3 * v + 0]), - static_cast(attrib.normals[3 * v + 1]), - static_cast(attrib.normals[3 * v + 2])); + static_cast(attrib.normals[v].x), + static_cast(attrib.normals[v].y), + static_cast(attrib.normals[v].z)); } - for (size_t v = 0; v < attrib.texcoords.size() / 2; v++) { + for (size_t v = 0; v < attrib.texcoords.size(); v++) { printf(" uv[%ld] = (%f, %f)\n", static_cast(v), - static_cast(attrib.texcoords[2 * v + 0]), - static_cast(attrib.texcoords[2 * v + 1])); + static_cast(attrib.texcoords[v].x), + static_cast(attrib.texcoords[v].y)); } // For each shape diff --git a/tiny_obj_loader.h b/tiny_obj_loader.h index 71488e0..f519d00 100644 --- a/tiny_obj_loader.h +++ b/tiny_obj_loader.h @@ -23,6 +23,7 @@ THE SOFTWARE. */ // +// version 2.0.0 : New API! And support triangulation of concave polygon(#151). // version 1.1.0 : Support parsing vertex color(#144) // version 1.0.8 : Fix parsing `g` tag just after `usemtl`(#138) // version 1.0.7 : Support multiple tex options(#126) @@ -108,13 +109,13 @@ typedef double real_t; typedef float real_t; #endif -struct V3 { real_t x,y,z; }; -inline V3 operator+(const V3 &l,const V3 &r){V3 o;o.x=l.x+r.x;o.y=l.y+r.y;o.z=l.z+r.z;return o;} -inline V3 operator-(const V3 &l,const V3 &r){V3 o;o.x=l.x-r.x;o.y=l.y-r.y;o.z=l.z-r.z;return o;} -inline V3 operator*(const V3 &l,real_t r){V3 o;o.x=l.x*r;o.y=l.y*r;o.z=l.z*r;return o;} -inline V3 cross(const V3 &l,const V3 &r){V3 o;o.x=l.y*r.z-r.y*l.z;o.y=l.z*r.x-r.z*l.x;o.z=l.x*r.y-r.x*l.y;return o;} -inline real_t dot(const V3 &l,const V3 &r){return l.x*r.x+l.y*r.y+l.z*r.z;} -struct V2 { real_t x,y; }; +struct vec3_t { real_t x,y,z; }; +inline vec3_t operator+(const vec3_t &l,const vec3_t &r){vec3_t o;o.x=l.x+r.x;o.y=l.y+r.y;o.z=l.z+r.z;return o;} +inline vec3_t operator-(const vec3_t &l,const vec3_t &r){vec3_t o;o.x=l.x-r.x;o.y=l.y-r.y;o.z=l.z-r.z;return o;} +inline vec3_t operator*(const vec3_t &l,real_t r){vec3_t o;o.x=l.x*r;o.y=l.y*r;o.z=l.z*r;return o;} +inline vec3_t cross(const vec3_t &l,const vec3_t &r){vec3_t o;o.x=l.y*r.z-r.y*l.z;o.y=l.z*r.x-r.z*l.x;o.z=l.x*r.y-r.x*l.y;return o;} +inline real_t dot(const vec3_t &l,const vec3_t &r){return l.x*r.x+l.y*r.y+l.z*r.z;} +struct vec2_t { real_t x,y; }; typedef enum { TEXTURE_TYPE_NONE, // default @@ -236,9 +237,9 @@ typedef struct { // Vertex attributes typedef struct { - std::vector vertices; // 'v' - std::vector normals; // 'vn' - std::vector texcoords; // 'vt' + std::vector vertices; // 'v' + std::vector normals; // 'vn' + std::vector texcoords; // 'vt' std::vector colors; // extension: vertex colors } attrib_t; @@ -982,7 +983,7 @@ static void InitMaterial(material_t *material) { static bool exportFaceGroupToShape( shape_t *shape, const std::vector > &faceGroup, const std::vector &tags, const int material_id, - const std::string &name, bool triangulate, const std::vector &v ) { + const std::string &name, bool triangulate, const std::vector &v ) { if (faceGroup.empty()) { return false; } @@ -998,18 +999,18 @@ static bool exportFaceGroupToShape( size_t npolys = face.size(); if (triangulate) { - V3 face_normal = {0,0,0}; + vec3_t face_normal = {0,0,0}; for(size_t k = 0; k < npolys; ++k) { int vi0 = face[(k+0)%npolys].v_idx; int vi1 = face[(k+1)%npolys].v_idx; int vi2 = face[(k+2)%npolys].v_idx; - const V3 &v0 = v[vi0]; - const V3 &v1 = v[vi1]; - const V3 &v2 = v[vi2]; - const V3 e0 = v1 - v0; - const V3 e1 = v2 - v1; - const V3 n = cross( e0, e1 ); + const vec3_t &v0 = v[vi0]; + const vec3_t &v1 = v[vi1]; + const vec3_t &v2 = v[vi2]; + const vec3_t e0 = v1 - v0; + const vec3_t e1 = v2 - v1; + const vec3_t n = cross( e0, e1 ); face_normal = face_normal + n; } @@ -1035,12 +1036,12 @@ static bool exportFaceGroupToShape( int vi0 = i0.v_idx; int vi1 = i1.v_idx; int vi2 = i2.v_idx; - const V3 &v0 = v[vi0]; - const V3 &v1 = v[vi1]; - const V3 &v2 = v[vi2]; - const V3 e0 = v1 - v0; - const V3 e1 = v2 - v1; - const V3 n = cross( e0, e1 ); + const vec3_t &v0 = v[vi0]; + const vec3_t &v1 = v[vi1]; + const vec3_t &v2 = v[vi2]; + const vec3_t e0 = v1 - v0; + const vec3_t e1 = v2 - v1; + const vec3_t n = cross( e0, e1 ); bool internal = dot( n, face_normal ) < 0.0f; if( internal ) { guess_vert += 1; continue; } @@ -1048,7 +1049,7 @@ static bool exportFaceGroupToShape( bool overlap = false; for( size_t otherVert = 3; otherVert < npolys; ++otherVert ) { int ovi = remainingFace[(guess_vert+otherVert)%npolys].v_idx; - const V3 &ov = v[ovi]; + const vec3_t &ov = v[ovi]; if( dot( face_normal, cross( e0, ov-v0 ) ) < 0 ) continue; if( dot( face_normal, cross( e1, ov-v1 ) ) < 0 ) @@ -1631,9 +1632,9 @@ bool LoadObj(attrib_t *attrib, std::vector *shapes, bool triangulate) { std::stringstream errss; - std::vector v; - std::vector vn; - std::vector vt; + std::vector v; + std::vector vn; + std::vector vt; std::vector vc; std::vector tags; std::vector > faceGroup; @@ -1676,7 +1677,7 @@ bool LoadObj(attrib_t *attrib, std::vector *shapes, // vertex if (token[0] == 'v' && IS_SPACE((token[1]))) { token += 2; - V3 v3; + vec3_t v3; real_t r, g, b; parseVertexWithColor(&v3.x, &v3.y, &v3.z, &r, &g, &b, &token); v.push_back(v3); @@ -1690,7 +1691,7 @@ bool LoadObj(attrib_t *attrib, std::vector *shapes, // normal if (token[0] == 'v' && token[1] == 'n' && IS_SPACE((token[2]))) { token += 3; - V3 v3; + vec3_t v3; parseReal3(&v3.x, &v3.y, &v3.z, &token); vn.push_back(v3); continue; @@ -1699,7 +1700,7 @@ bool LoadObj(attrib_t *attrib, std::vector *shapes, // texcoord if (token[0] == 'v' && token[1] == 't' && IS_SPACE((token[2]))) { token += 3; - V2 v2; + vec2_t v2; parseReal2(&v2.x, &v2.y, &token); vt.push_back(v2); continue;