Fix compilation for double precision mode(Fixes #167).
This commit is contained in:
@@ -6,11 +6,21 @@
|
|||||||
|
|
||||||
* C++-11 compiler
|
* C++-11 compiler
|
||||||
|
|
||||||
|
## How to build
|
||||||
|
|
||||||
|
```
|
||||||
|
$ premak5 gmake
|
||||||
|
```
|
||||||
|
|
||||||
## Compile options
|
## Compile options
|
||||||
|
|
||||||
* zstd compressed .obj support. `--with-zstd` premake option.
|
* zstd compressed .obj support. `--with-zstd` premake option.
|
||||||
* gzip compressed .obj support. `--with-zlib` premake option.
|
* gzip compressed .obj support. `--with-zlib` premake option.
|
||||||
|
|
||||||
|
## Notes on AMD GPU + Linux
|
||||||
|
|
||||||
|
You may need to link with libdrm(`-ldrm`).
|
||||||
|
|
||||||
## Licenses
|
## Licenses
|
||||||
|
|
||||||
* lfpAlloc : MIT license.
|
* lfpAlloc : MIT license.
|
||||||
|
|||||||
@@ -57,6 +57,9 @@ namespace tinyobj {
|
|||||||
#if __has_warning("-Wzero-as-null-pointer-constant")
|
#if __has_warning("-Wzero-as-null-pointer-constant")
|
||||||
#pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant"
|
#pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#pragma clang diagnostic ignored "-Wpadded"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// https://en.wikipedia.org/wiki/Wavefront_.obj_file says ...
|
// https://en.wikipedia.org/wiki/Wavefront_.obj_file says ...
|
||||||
@@ -369,6 +372,7 @@ void LoadMtl(std::map<std::string, int> *material_map,
|
|||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include <limits>
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
@@ -866,22 +870,22 @@ static bool ParseTextureNameAndOption(std::string *texname,
|
|||||||
} else {
|
} else {
|
||||||
texopt->imfchan = 'm';
|
texopt->imfchan = 'm';
|
||||||
}
|
}
|
||||||
texopt->bump_multiplier = 1.0f;
|
texopt->bump_multiplier = static_cast<real_t>(1.0);
|
||||||
texopt->clamp = false;
|
texopt->clamp = false;
|
||||||
texopt->blendu = true;
|
texopt->blendu = true;
|
||||||
texopt->blendv = true;
|
texopt->blendv = true;
|
||||||
texopt->sharpness = 1.0f;
|
texopt->sharpness = static_cast<real_t>(1.0);
|
||||||
texopt->brightness = 0.0f;
|
texopt->brightness = static_cast<real_t>(0.0);
|
||||||
texopt->contrast = 1.0f;
|
texopt->contrast = static_cast<real_t>(1.0);
|
||||||
texopt->origin_offset[0] = 0.0f;
|
texopt->origin_offset[0] = static_cast<real_t>(0.0);
|
||||||
texopt->origin_offset[1] = 0.0f;
|
texopt->origin_offset[1] = static_cast<real_t>(0.0);
|
||||||
texopt->origin_offset[2] = 0.0f;
|
texopt->origin_offset[2] = static_cast<real_t>(0.0);
|
||||||
texopt->scale[0] = 1.0f;
|
texopt->scale[0] = static_cast<real_t>(1.0);
|
||||||
texopt->scale[1] = 1.0f;
|
texopt->scale[1] = static_cast<real_t>(1.0);
|
||||||
texopt->scale[2] = 1.0f;
|
texopt->scale[2] = static_cast<real_t>(1.0);
|
||||||
texopt->turbulence[0] = 0.0f;
|
texopt->turbulence[0] = static_cast<real_t>(0.0);
|
||||||
texopt->turbulence[1] = 0.0f;
|
texopt->turbulence[1] = static_cast<real_t>(0.0);
|
||||||
texopt->turbulence[2] = 0.0f;
|
texopt->turbulence[2] = static_cast<real_t>(0.0);
|
||||||
texopt->type = TEXTURE_TYPE_NONE;
|
texopt->type = TEXTURE_TYPE_NONE;
|
||||||
|
|
||||||
const char *token = linebuf; // Assume line ends with NULL
|
const char *token = linebuf; // Assume line ends with NULL
|
||||||
@@ -967,24 +971,24 @@ static void InitMaterial(material_t *material) {
|
|||||||
material->reflection_texname = "";
|
material->reflection_texname = "";
|
||||||
material->alpha_texname = "";
|
material->alpha_texname = "";
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
material->ambient[i] = 0.f;
|
material->ambient[i] = static_cast<real_t>(0.0);
|
||||||
material->diffuse[i] = 0.f;
|
material->diffuse[i] = static_cast<real_t>(0.0);
|
||||||
material->specular[i] = 0.f;
|
material->specular[i] = static_cast<real_t>(0.0);
|
||||||
material->transmittance[i] = 0.f;
|
material->transmittance[i] = static_cast<real_t>(0.0);
|
||||||
material->emission[i] = 0.f;
|
material->emission[i] = static_cast<real_t>(0.0);
|
||||||
}
|
}
|
||||||
material->illum = 0;
|
material->illum = 0;
|
||||||
material->dissolve = 1.f;
|
material->dissolve = static_cast<real_t>(1.0);
|
||||||
material->shininess = 1.f;
|
material->shininess = static_cast<real_t>(1.0);
|
||||||
material->ior = 1.f;
|
material->ior = static_cast<real_t>(1.0);
|
||||||
|
|
||||||
material->roughness = 0.f;
|
material->roughness = static_cast<real_t>(0.0);
|
||||||
material->metallic = 0.f;
|
material->metallic = static_cast<real_t>(0.0);
|
||||||
material->sheen = 0.f;
|
material->sheen = static_cast<real_t>(0.0);
|
||||||
material->clearcoat_thickness = 0.f;
|
material->clearcoat_thickness = static_cast<real_t>(0.0);
|
||||||
material->clearcoat_roughness = 0.f;
|
material->clearcoat_roughness = static_cast<real_t>(0.0);
|
||||||
material->anisotropy_rotation = 0.f;
|
material->anisotropy_rotation = static_cast<real_t>(0.0);
|
||||||
material->anisotropy = 0.f;
|
material->anisotropy = static_cast<real_t>(0.0);
|
||||||
material->roughness_texname = "";
|
material->roughness_texname = "";
|
||||||
material->metallic_texname = "";
|
material->metallic_texname = "";
|
||||||
material->sheen_texname = "";
|
material->sheen_texname = "";
|
||||||
@@ -995,8 +999,9 @@ static void InitMaterial(material_t *material) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// code from https://wrf.ecse.rpi.edu//Research/Short_Notes/pnpoly.html
|
// code from https://wrf.ecse.rpi.edu//Research/Short_Notes/pnpoly.html
|
||||||
static int pnpoly(int nvert, float *vertx, float *verty, float testx,
|
template<typename T>
|
||||||
float testy) {
|
static int pnpoly(int nvert, T *vertx, T *verty, T testx,
|
||||||
|
T testy) {
|
||||||
int i, j, c = 0;
|
int i, j, c = 0;
|
||||||
for (i = 0, j = nvert - 1; i < nvert; j = i++) {
|
for (i = 0, j = nvert - 1; i < nvert; j = i++) {
|
||||||
if (((verty[i] > testy) != (verty[j] > testy)) &&
|
if (((verty[i] > testy) != (verty[j] > testy)) &&
|
||||||
@@ -1054,10 +1059,10 @@ static bool exportFaceGroupToShape(shape_t *shape,
|
|||||||
real_t e1x = v2x - v1x;
|
real_t e1x = v2x - v1x;
|
||||||
real_t e1y = v2y - v1y;
|
real_t e1y = v2y - v1y;
|
||||||
real_t e1z = v2z - v1z;
|
real_t e1z = v2z - v1z;
|
||||||
float cx = std::fabs(e0y * e1z - e0z * e1y);
|
real_t cx = std::fabs(e0y * e1z - e0z * e1y);
|
||||||
float cy = std::fabs(e0z * e1x - e0x * e1z);
|
real_t cy = std::fabs(e0z * e1x - e0x * e1z);
|
||||||
float cz = std::fabs(e0x * e1y - e0y * e1x);
|
real_t cz = std::fabs(e0x * e1y - e0y * e1x);
|
||||||
const float epsilon = 0.0001f;
|
const real_t epsilon = std::numeric_limits<real_t>::epsilon();
|
||||||
if (cx > epsilon || cy > epsilon || cz > epsilon) {
|
if (cx > epsilon || cy > epsilon || cz > epsilon) {
|
||||||
// found a corner
|
// found a corner
|
||||||
if (cx > cy && cx > cz) {
|
if (cx > cy && cx > cz) {
|
||||||
@@ -1079,7 +1084,7 @@ static bool exportFaceGroupToShape(shape_t *shape,
|
|||||||
real_t v0y = v[vi0 * 3 + axes[1]];
|
real_t v0y = v[vi0 * 3 + axes[1]];
|
||||||
real_t v1x = v[vi1 * 3 + axes[0]];
|
real_t v1x = v[vi1 * 3 + axes[0]];
|
||||||
real_t v1y = v[vi1 * 3 + axes[1]];
|
real_t v1y = v[vi1 * 3 + axes[1]];
|
||||||
area += (v0x * v1y - v0y * v1x) * 0.5f;
|
area += (v0x * v1y - v0y * v1x) * static_cast<real_t>(0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
int maxRounds =
|
int maxRounds =
|
||||||
@@ -1108,7 +1113,7 @@ static bool exportFaceGroupToShape(shape_t *shape,
|
|||||||
real_t e1y = vy[2] - vy[1];
|
real_t e1y = vy[2] - vy[1];
|
||||||
real_t cross = e0x * e1y - e0y * e1x;
|
real_t cross = e0x * e1y - e0y * e1x;
|
||||||
// if an internal angle
|
// if an internal angle
|
||||||
if (cross * area < 0.0f) {
|
if (cross * area < static_cast<real_t>(0.0)) {
|
||||||
guess_vert += 1;
|
guess_vert += 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -1396,7 +1401,7 @@ void LoadMtl(std::map<std::string, int> *material_map,
|
|||||||
// We invert value of Tr(assume Tr is in range [0, 1])
|
// We invert value of Tr(assume Tr is in range [0, 1])
|
||||||
// NOTE: Interpretation of Tr is application(exporter) dependent. For
|
// NOTE: Interpretation of Tr is application(exporter) dependent. For
|
||||||
// some application(e.g. 3ds max obj exporter), Tr = d(Issue 43)
|
// some application(e.g. 3ds max obj exporter), Tr = d(Issue 43)
|
||||||
material.dissolve = 1.0f - parseReal(&token);
|
material.dissolve = static_cast<real_t>(1.0) - parseReal(&token);
|
||||||
}
|
}
|
||||||
has_tr = true;
|
has_tr = true;
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
Reference in New Issue
Block a user