Compare commits
5 Commits
devel
...
better-cxx
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1e2cd27c64 | ||
|
|
49726abcf1 | ||
|
|
b29d34f2e1 | ||
|
|
cb085d1fb6 | ||
|
|
b38e97b7ec |
33
README.md
33
README.md
@@ -26,20 +26,11 @@ 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!
|
||||
|
||||
### Older version
|
||||
### Old version
|
||||
|
||||
Older version is avaiable in `v0.9.x` branch.
|
||||
Previous old version is avaiable in `v0.9.x` branch.
|
||||
|
||||
## Example
|
||||
|
||||
@@ -58,11 +49,7 @@ http://casual-effects.com/data/index.html
|
||||
|
||||
TinyObjLoader is successfully used in ...
|
||||
|
||||
### New version(v2.x)
|
||||
|
||||
* Your project here! (Letting us know via github issue is welcome!)
|
||||
|
||||
### Old version(v1.x)
|
||||
### New version(v1.0.x)
|
||||
|
||||
* Double precision support through `TINYOBJLOADER_USE_DOUBLE` thanks to noma
|
||||
* Loading models in Vulkan Tutorial https://vulkan-tutorial.com/Loading_models
|
||||
@@ -73,7 +60,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!)
|
||||
|
||||
### Older version(v0.9.x)
|
||||
### Old version(v0.9.x)
|
||||
|
||||
* bullet3 https://github.com/erwincoumans/bullet3
|
||||
* pbrt-v2 https://github.com/mmp/pbrt-v2
|
||||
@@ -241,12 +228,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[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 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 tx = attrib.texcoords[2*idx.texcoord_index+0];
|
||||
tinyobj::real_t ty = attrib.texcoords[2*idx.texcoord_index+1];
|
||||
// Optional: vertex colors
|
||||
|
||||
@@ -1440,7 +1440,9 @@ bool parseObj(attrib_t *attrib, std::vector<shape_t> *shapes,
|
||||
// std::cout << "mtllib :" << material_filename << std::endl;
|
||||
|
||||
auto t1 = std::chrono::high_resolution_clock::now();
|
||||
|
||||
if (material_filename.back() == '\r') {
|
||||
material_filename.pop_back();
|
||||
}
|
||||
std::ifstream ifs(material_filename);
|
||||
if (ifs.good()) {
|
||||
LoadMtl(&material_map, materials, &ifs);
|
||||
@@ -1516,13 +1518,13 @@ bool parseObj(attrib_t *attrib, std::vector<shape_t> *shapes,
|
||||
StackVector<std::thread, 16> workers;
|
||||
|
||||
for (size_t t = 0; t < num_threads; t++) {
|
||||
int material_id = -1; // -1 = default unknown material.
|
||||
workers->push_back(std::thread([&, t]() {
|
||||
size_t v_count = v_offsets[t];
|
||||
size_t n_count = n_offsets[t];
|
||||
size_t t_count = t_offsets[t];
|
||||
size_t f_count = f_offsets[t];
|
||||
size_t face_count = face_offsets[t];
|
||||
int material_id = -1; // -1 = default unknown material.
|
||||
|
||||
for (size_t i = 0; i < commands[t].size(); i++) {
|
||||
if (commands[t][i].type == COMMAND_EMPTY) {
|
||||
@@ -1579,7 +1581,19 @@ bool parseObj(attrib_t *attrib, std::vector<shape_t> *shapes,
|
||||
for (size_t t = 0; t < workers->size(); t++) {
|
||||
workers[t].join();
|
||||
}
|
||||
|
||||
if(material_map.size()>1&& num_threads>1) {
|
||||
for (size_t t = 0; t < num_threads; t++) {
|
||||
size_t face_count = face_offsets[t];
|
||||
if (-1 == attrib->material_ids[face_count]) {
|
||||
int prev_material_id = attrib->material_ids[face_count - 1];
|
||||
size_t max_face_offset = (t == num_threads - 1) ? attrib->material_ids.size() : face_offsets[t + 1];
|
||||
for (int i = face_count; i<max_face_offset; ++i) {
|
||||
if (attrib->material_ids[i] != -1) break;
|
||||
attrib->material_ids[i] = prev_material_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
auto t_end = std::chrono::high_resolution_clock::now();
|
||||
ms_merge = t_end - t_start;
|
||||
}
|
||||
@@ -29,9 +29,10 @@ extern "C" {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef TINYOBJ_USE_CXX11
|
||||
#ifdef __clang__
|
||||
#if __has_warning("-Wzero-as-null-pointer-constant")
|
||||
#pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant"
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wc++98-compat"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -69,7 +70,7 @@ class timerutil {
|
||||
}
|
||||
time_t current() {
|
||||
struct timeval t;
|
||||
gettimeofday(&t, NULL);
|
||||
gettimeofday(&t, tobj_null);
|
||||
return static_cast<time_t>(t.tv_sec * 1000 + t.tv_usec);
|
||||
}
|
||||
|
||||
@@ -112,24 +113,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(); v++) {
|
||||
for (size_t v = 0; v < attrib.vertices.size() / 3; v++) {
|
||||
printf(" v[%ld] = (%f, %f, %f)\n", static_cast<long>(v),
|
||||
static_cast<const double>(attrib.vertices[v].x),
|
||||
static_cast<const double>(attrib.vertices[v].y),
|
||||
static_cast<const double>(attrib.vertices[v].z));
|
||||
static_cast<const double>(attrib.vertices[3 * v + 0]),
|
||||
static_cast<const double>(attrib.vertices[3 * v + 1]),
|
||||
static_cast<const double>(attrib.vertices[3 * v + 2]));
|
||||
}
|
||||
|
||||
for (size_t v = 0; v < attrib.normals.size(); v++) {
|
||||
for (size_t v = 0; v < attrib.normals.size() / 3; v++) {
|
||||
printf(" n[%ld] = (%f, %f, %f)\n", static_cast<long>(v),
|
||||
static_cast<const double>(attrib.normals[v].x),
|
||||
static_cast<const double>(attrib.normals[v].y),
|
||||
static_cast<const double>(attrib.normals[v].z));
|
||||
static_cast<const double>(attrib.normals[3 * v + 0]),
|
||||
static_cast<const double>(attrib.normals[3 * v + 1]),
|
||||
static_cast<const double>(attrib.normals[3 * v + 2]));
|
||||
}
|
||||
|
||||
for (size_t v = 0; v < attrib.texcoords.size(); v++) {
|
||||
for (size_t v = 0; v < attrib.texcoords.size() / 2; v++) {
|
||||
printf(" uv[%ld] = (%f, %f)\n", static_cast<long>(v),
|
||||
static_cast<const double>(attrib.texcoords[v].x),
|
||||
static_cast<const double>(attrib.texcoords[v].y));
|
||||
static_cast<const double>(attrib.texcoords[2 * v + 0]),
|
||||
static_cast<const double>(attrib.texcoords[2 * v + 1]));
|
||||
}
|
||||
|
||||
// For each shape
|
||||
@@ -267,7 +268,7 @@ static void PrintInfo(const tinyobj::attrib_t& attrib,
|
||||
}
|
||||
}
|
||||
|
||||
static bool TestLoadObj(const char* filename, const char* basepath = NULL,
|
||||
static bool TestLoadObj(const char* filename, const char* basepath = tobj_null,
|
||||
bool triangulate = true) {
|
||||
std::cout << "Loading " << filename << std::endl;
|
||||
|
||||
@@ -367,7 +368,7 @@ static bool TestStreamLoadObj() {
|
||||
virtual ~MaterialStringStreamReader() {}
|
||||
virtual bool operator()(const std::string& matId,
|
||||
std::vector<material_t>* materials,
|
||||
std::map<unsigned int, int>* matMap,
|
||||
std::map<std::string, int>* matMap,
|
||||
std::string* err) {
|
||||
(void)matId;
|
||||
std::string warning;
|
||||
|
||||
@@ -22,22 +22,22 @@ static void PrintInfo(const tinyobj::attrib_t &attrib, const std::vector<tinyobj
|
||||
|
||||
for (size_t v = 0; v < attrib.vertices.size() / 3; v++) {
|
||||
printf(" v[%ld] = (%f, %f, %f)\n", v,
|
||||
static_cast<const double>(attrib.vertices[v].x),
|
||||
static_cast<const double>(attrib.vertices[v].y),
|
||||
static_cast<const double>(attrib.vertices[v].z));
|
||||
static_cast<const double>(attrib.vertices[3*v+0]),
|
||||
static_cast<const double>(attrib.vertices[3*v+1]),
|
||||
static_cast<const double>(attrib.vertices[3*v+2]));
|
||||
}
|
||||
|
||||
for (size_t v = 0; v < attrib.normals.size() / 3; v++) {
|
||||
printf(" n[%ld] = (%f, %f, %f)\n", v,
|
||||
static_cast<const double>(attrib.normals[v].x),
|
||||
static_cast<const double>(attrib.normals[v].y),
|
||||
static_cast<const double>(attrib.normals[v].z));
|
||||
static_cast<const double>(attrib.normals[3*v+0]),
|
||||
static_cast<const double>(attrib.normals[3*v+1]),
|
||||
static_cast<const double>(attrib.normals[3*v+2]));
|
||||
}
|
||||
|
||||
for (size_t v = 0; v < attrib.texcoords.size() / 2; v++) {
|
||||
printf(" uv[%ld] = (%f, %f)\n", v,
|
||||
static_cast<const double>(attrib.texcoords[v].x),
|
||||
static_cast<const double>(attrib.texcoords[v].y));
|
||||
static_cast<const double>(attrib.texcoords[2*v+0]),
|
||||
static_cast<const double>(attrib.texcoords[2*v+1]));
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < shapes.size(); i++) {
|
||||
@@ -303,8 +303,7 @@ std::string matStream(
|
||||
virtual bool operator() (
|
||||
const std::string& matId,
|
||||
std::vector<material_t>* materials,
|
||||
//std::map<std::string, int>* matMap,
|
||||
std::map<uint32_t, int>* matMap,
|
||||
std::map<std::string, int>* matMap,
|
||||
std::string* err)
|
||||
{
|
||||
(void)matId;
|
||||
|
||||
1949
tiny_obj_loader.h
1949
tiny_obj_loader.h
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user