11 Commits

Author SHA1 Message Date
Syoyo Fujita
f37fed32f3 Merge pull request #196 from jasjuang/master
Use CMake built-in variable BUILD_SHARED_LIBS instead of custom TINYOBJLOADER_COMPILATION_SHARED
2019-01-05 15:52:55 +09:00
jasjuang
85d92bb5cb use cmake default variable BUILD_SHARED_LIBS instead of custom TINYOBJLOADER_COMPILATION_SHARED 2019-01-04 11:06:27 -08:00
Syoyo Fujita
40d00fd935 Merge pull request #195 from Neptilo/master
Fix crash when reading mtllib command
2019-01-04 22:13:05 +09:00
Neptilo
7712f1bebd Fix crash when reading mtllib command
The code was assuming the mtllib command to be near the beginning of the file, and therefore to always be read by the first thread.
2019-01-04 13:57:34 +01:00
Syoyo Fujita
e96e994355 Merge pull request #194 from jasjuang/master
namespace for cmake export
2019-01-04 12:33:19 +09:00
jasjuang
8f16866c37 namespace for cmake export 2019-01-03 19:26:00 -08:00
Syoyo Fujita
5e668b398a Merge pull request #193 from scpeters/patch-1
tiny_obj_loader.h: initialize pad_ in constructor
2018-12-15 01:30:19 +09:00
Steven Peters
df3bb6f8e8 tiny_obj_loader.h: fix order of variables 2018-12-13 10:49:18 -08:00
Steven Peters
546aa09d8d tiny_obj_loader.h: initialize pad_ in constructor 2018-12-11 15:09:56 -08:00
Syoyo Fujita
aa90b5466f Merge pull request #192 from basicNew/ChangeLoopTerminationConstraint
Change triangulation loop termination constraint
2018-12-08 17:57:06 +09:00
Andres Fortier
b404f3af67 Change loop termination constraint 2018-12-07 17:06:38 -03:00
3 changed files with 26 additions and 11 deletions

View File

@@ -46,15 +46,13 @@ set(TINYOBJLOADER_PKGCONFIG_DIR ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
set(TINYOBJLOADER_RUNTIME_DIR ${CMAKE_INSTALL_BINDIR}) set(TINYOBJLOADER_RUNTIME_DIR ${CMAKE_INSTALL_BINDIR})
option(TINYOBJLOADER_BUILD_TEST_LOADER "Build Example Loader Application" OFF) option(TINYOBJLOADER_BUILD_TEST_LOADER "Build Example Loader Application" OFF)
option(TINYOBJLOADER_COMPILATION_SHARED "Build as shared library" OFF)
if(TINYOBJLOADER_COMPILATION_SHARED) add_library(${LIBRARY_NAME} ${tinyobjloader-Source})
add_library(${LIBRARY_NAME} SHARED ${tinyobjloader-Source})
if(BUILD_SHARED_LIBS)
set_target_properties(${LIBRARY_NAME} PROPERTIES set_target_properties(${LIBRARY_NAME} PROPERTIES
SOVERSION ${TINYOBJLOADER_SOVERSION} SOVERSION ${TINYOBJLOADER_SOVERSION}
) )
else()
add_library(${LIBRARY_NAME} STATIC ${tinyobjloader-Source})
endif() endif()
set_target_properties(${LIBRARY_NAME} PROPERTIES VERSION ${TINYOBJLOADER_VERSION}) set_target_properties(${LIBRARY_NAME} PROPERTIES VERSION ${TINYOBJLOADER_VERSION})
@@ -120,6 +118,8 @@ install(TARGETS
) )
install(EXPORT install(EXPORT
${PROJECT_NAME}-targets ${PROJECT_NAME}-targets
NAMESPACE
tinyobjloader::
DESTINATION DESTINATION
${TINYOBJLOADER_CMAKE_DIR} ${TINYOBJLOADER_CMAKE_DIR}
) )

View File

@@ -1414,8 +1414,9 @@ bool parseObj(attrib_t *attrib, std::vector<shape_t> *shapes,
} }
if (command.type == COMMAND_MTLLIB) { if (command.type == COMMAND_MTLLIB) {
// Save the indices of the `mtllib` command in `commands` to easily find it later
mtllib_t_index = t; mtllib_t_index = t;
mtllib_i_index = commands->size(); mtllib_i_index = commands[t].size();
} }
commands[t].emplace_back(std::move(command)); commands[t].emplace_back(std::move(command));

View File

@@ -435,7 +435,7 @@ struct face_t {
int pad_; int pad_;
std::vector<vertex_index_t> vertex_indices; // face vertex indices. std::vector<vertex_index_t> vertex_indices; // face vertex indices.
face_t() : smoothing_group_id(0) {} face_t() : smoothing_group_id(0), pad_(0) {}
}; };
struct line_t { struct line_t {
@@ -1171,20 +1171,34 @@ static bool exportGroupsToShape(shape_t *shape,
area += (v0x * v1y - v0y * v1x) * static_cast<real_t>(0.5); area += (v0x * v1y - v0y * v1x) * static_cast<real_t>(0.5);
} }
int maxRounds = 10; // arbitrary max loop count to protect against
// unexpected errors
face_t remainingFace = face; // copy face_t remainingFace = face; // copy
size_t guess_vert = 0; size_t guess_vert = 0;
vertex_index_t ind[3]; vertex_index_t ind[3];
real_t vx[3]; real_t vx[3];
real_t vy[3]; real_t vy[3];
while (remainingFace.vertex_indices.size() > 3 && maxRounds > 0) {
// How many iterations can we do without decreasing the remaining
// vertices.
size_t remainingIterations = face.vertex_indices.size();
size_t previousRemainingVertices = remainingFace.vertex_indices.size();
while (remainingFace.vertex_indices.size() > 3 && remainingIterations > 0){
npolys = remainingFace.vertex_indices.size(); npolys = remainingFace.vertex_indices.size();
if (guess_vert >= npolys) { if (guess_vert >= npolys) {
maxRounds -= 1;
guess_vert -= npolys; guess_vert -= npolys;
} }
if (previousRemainingVertices != npolys) {
// The number of remaining vertices decreased. Reset counters.
previousRemainingVertices = npolys;
remainingIterations = npolys;
} else {
// We didn't consume a vertex on previous iteration, reduce the
// available iterations.
remainingIterations--;
}
for (size_t k = 0; k < 3; k++) { for (size_t k = 0; k < 3; k++) {
ind[k] = remainingFace.vertex_indices[(guess_vert + k) % npolys]; ind[k] = remainingFace.vertex_indices[(guess_vert + k) % npolys];
size_t vi = size_t(ind[k].v_idx); size_t vi = size_t(ind[k].v_idx);