Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Old version is available as `v0.9.x` branch https://github.com/syoyo/tinyobjload

## What's new

* 29 Jul, 2021 : Added Mapbox's earcut for robust triangulation. Also fixes triangulation bug.
* 19 Feb, 2020 : The repository has been moved to https://github.com/tinyobjloader/tinyobjloader !
* 18 May, 2019 : Python binding!(See `python` folder. Also see https://pypi.org/project/tinyobjloader/)
* 14 Apr, 2019 : Bump version v2.0.0 rc0. New C++ API and python bindings!(1.x API still exists for backward compatibility)
Expand Down Expand Up @@ -139,6 +140,7 @@ TinyObjLoader is licensed under MIT license.
### Third party licenses.

* pybind11 : BSD-style license.
* mapbox earcut.hpp: ISC License.

## Usage

Expand Down Expand Up @@ -241,10 +243,22 @@ TinyObjLoader now use `real_t` for floating point data type.
Default is `float(32bit)`.
You can enable `double(64bit)` precision by using `TINYOBJLOADER_USE_DOUBLE` define.

### Robust triangulation

When you enable `triangulation`(default is enabled),
TinyObjLoader triangulate polygons(faces with 4 or more vertices).

Built-in trinagulation code may not work well in some polygon shape.

You can define `TINYOBJLOADER_USE_MAPBOX_EARCUT` for robust triangulation using `mapbox/earcut.hpp`.
This requires C++11 compiler though.

#### Example code (Deprecated API)

```c++
#define TINYOBJLOADER_IMPLEMENTATION // define this in only *one* .cc
// Optional. define TINYOBJLOADER_USE_MAPBOX_EARCUT gives robust trinagulation. Requires C++11
//#define TINYOBJLOADER_USE_MAPBOX_EARCUT
#include "tiny_obj_loader.h"

std::string inputfile = "cornell_box.obj";
Expand Down Expand Up @@ -315,6 +329,8 @@ for (size_t s = 0; s < shapes.size(); s++) {

```c++
#define TINYOBJLOADER_IMPLEMENTATION // define this in only *one* .cc
// Optional. define TINYOBJLOADER_USE_MAPBOX_EARCUT gives robust trinagulation. Requires C++11
//#define TINYOBJLOADER_USE_MAPBOX_EARCUT
#include "tiny_obj_loader.h"


Expand Down Expand Up @@ -353,7 +369,7 @@ for (size_t s = 0; s < shapes.size(); s++) {
tinyobj::real_t vx = attrib.vertices[3*size_t(idx.vertex_index)+0];
tinyobj::real_t vy = attrib.vertices[3*size_t(idx.vertex_index)+1];
tinyobj::real_t vz = attrib.vertices[3*size_t(idx.vertex_index)+2];

// Check if `normal_index` is zero or positive. negative = no normal data
if (idx.normal_index >= 0) {
tinyobj::real_t nx = attrib.normals[3*size_t(idx.normal_index)+0];
Expand Down
11 changes: 11 additions & 0 deletions examples/viewer/viewer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,24 @@
#include <GLFW/glfw3.h>

#define TINYOBJLOADER_IMPLEMENTATION
// TINYOBJLOADER_USE_MAPBOX_EARCUT: Enable better triangulation. Requires C++11
//#define TINYOBJLOADER_USE_MAPBOX_EARCUT
#include "../../tiny_obj_loader.h"

#include "trackball.h"

#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Weverything"
#endif

#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"

#ifdef __clang__
#pragma clang diagnostic pop
#endif

#ifdef _WIN32
#ifdef __cplusplus
extern "C" {
Expand Down
3 changes: 3 additions & 0 deletions python/tiny_obj_loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
// Need also define this in `binding.cc`(and all compilation units)
#define TINYOBJLOADER_USE_DOUBLE

// Use robust triangulation by using Mapbox earcut.
#define TINYOBJLOADER_USE_MAPBOX_EARCUT

#define TINYOBJLOADER_IMPLEMENTATION
#include "tiny_obj_loader.h"
Loading