1 Commits

Author SHA1 Message Date
Syoyo Fujita
b2ad2cd11e Remove invalid file.
Fix compilation.
2017-12-10 00:35:02 +09:00
2 changed files with 244 additions and 262 deletions

View File

@@ -303,8 +303,7 @@ std::string matStream(
virtual bool operator() ( virtual bool operator() (
const std::string& matId, const std::string& matId,
std::vector<material_t>* materials, std::vector<material_t>* materials,
//std::map<std::string, int>* matMap, std::map<unsigned int, int>* matMap,
std::map<uint32_t, int>* matMap,
std::string* err) std::string* err)
{ {
(void)matId; (void)matId;

View File

@@ -290,8 +290,7 @@ class MaterialFileReader : public MaterialReader {
virtual bool operator()(const std::string &matId, virtual bool operator()(const std::string &matId,
std::vector<material_t> *materials, std::vector<material_t> *materials,
// std::map<std::string, int> *matMap, // std::map<std::string, int> *matMap,
std::map<unsigned int, int> *matMap, std::map<unsigned int, int> *matMap, std::string *err);
std::string *err);
private: private:
std::string m_mtlBaseDir; std::string m_mtlBaseDir;
@@ -305,8 +304,7 @@ class MaterialStreamReader : public MaterialReader {
virtual bool operator()(const std::string &matId, virtual bool operator()(const std::string &matId,
std::vector<material_t> *materials, std::vector<material_t> *materials,
// std::map<std::string, int> *matMap, // std::map<std::string, int> *matMap,
std::map<unsigned int, int> *matMap, std::map<unsigned int, int> *matMap, std::string *err);
std::string *err);
private: private:
std::istream &m_inStream; std::istream &m_inStream;
@@ -350,9 +348,8 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
/// Loads materials into std::map /// Loads materials into std::map
void LoadMtl( void LoadMtl(
// std::map<std::string, int> *material_map, // std::map<std::string, int> *material_map,
std::map<unsigned int, int> *material_map, std::map<unsigned int, int> *material_map, std::vector<material_t> *materials,
std::vector<material_t> *materials, std::istream *inStream, std::istream *inStream, std::string *warning);
std::string *warning);
} // namespace tinyobj } // namespace tinyobj
@@ -373,6 +370,7 @@ void LoadMtl(
// #define TINYOBJLOADER_IMPLEMENTATION_BUFREAD // #define TINYOBJLOADER_IMPLEMENTATION_BUFREAD
#ifdef TINYOBJLOADER_IMPLEMENTATION_BUFREAD #ifdef TINYOBJLOADER_IMPLEMENTATION_BUFREAD
// TODO(syoyo): Support non-win32 system
#include <fcntl.h> #include <fcntl.h>
#include <io.h> #include <io.h>
#include <sys/stat.h> #include <sys/stat.h>
@@ -444,14 +442,11 @@ class ImportInBuf : public std::streambuf {
char *buffer_; char *buffer_;
int fd_; int fd_;
uint64_t fsize_, pos_; unsigned long long fsize_, pos_;
size_t buf_sz; size_t buf_sz;
}; };
#endif #endif
//***************************************************
//*************** tigro keywords hash functions begin
// tigra: x31 hash function // tigra: x31 hash function
typedef unsigned int khint_t; typedef unsigned int khint_t;
@@ -466,8 +461,7 @@ inline unsigned int X31_hash_stringSZ(const char *s, int sz) {
int i; int i;
khint_t h = static_cast<khint_t>(*s); khint_t h = static_cast<khint_t>(*s);
for (++s, i = sz - 1; i && *s; ++s, i--) for (++s, i = sz - 1; i && *s; ++s, i--) h = (h << 5) - h + static_cast<khint_t>(*s);
h = (h << 5) - h + static_cast<khint_t>(*s);
return h; return h;
} }
@@ -585,12 +579,10 @@ enum tokens_enum {
TOK_norm TOK_norm
}; };
// TODO(syoyo): Do not define in global scope.
#ifdef __clang__ #ifdef __clang__
#pragma clang diagnostic push #pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wglobal-constructors"
#pragma clang diagnostic ignored "-Wexit-time-destructors" #pragma clang diagnostic ignored "-Wexit-time-destructors"
#pragma clang diagnostic ignored "-Wglobal-constructors"
#endif #endif
static std::map<unsigned int, int> hashed_toks; static std::map<unsigned int, int> hashed_toks;
@@ -599,7 +591,7 @@ static std::map<unsigned int, int> hashed_toks;
#pragma clang diagnostic pop #pragma clang diagnostic pop
#endif #endif
// functions!
static void initHashedTokensMap() { static void initHashedTokensMap() {
// init hashed tokens map // init hashed tokens map
@@ -615,22 +607,19 @@ static void initHashedTokensMap() {
// init hashed tokens map END // init hashed tokens map END
} }
// search token in keywords hash map
static int token2tok(const char *token) { static int token2tok(const char *token) {
unsigned int token_sz, a_hash; unsigned int token_sz, a_hash;
int a_tok; int a_tok;
token_sz = static_cast<unsigned int>(strpbrk(token, " \t\r") - token_sz = static_cast<unsigned int>(strpbrk(token, " \t\r") - token); // token length
token); // token length
if (token_sz < 1) // delimiter not found, token_sz = strlen(token) if (token_sz < 1) // delimiter not found, token_sz = strlen(token)
{ {
// token_sz=strlen(token); // token_sz=strlen(token);
a_hash = X31_hash_string(token); a_hash = X31_hash_string(token);
} else { } else
a_hash = X31_hash_stringSZ(token, static_cast<int>(token_sz)); a_hash = X31_hash_stringSZ(token, static_cast<int>(token_sz));
}
a_tok = -1; a_tok = -1;
if (hashed_toks.find(a_hash) != hashed_toks.end()) if (hashed_toks.find(a_hash) != hashed_toks.end())
@@ -639,9 +628,6 @@ static int token2tok(const char *token) {
return a_tok; return a_tok;
} }
//*************** tigro keywords hash functions END
//*************************************************
MaterialReader::~MaterialReader() {} MaterialReader::~MaterialReader() {}
struct vertex_index { struct vertex_index {
@@ -1242,7 +1228,6 @@ static bool ParseTextureNameAndOption(std::string *texname,
parseReal2(&(texopt->brightness), &(texopt->contrast), &token, 0.0, parseReal2(&(texopt->brightness), &(texopt->contrast), &token, 0.0,
1.0); 1.0);
} }
} else { } else {
// Assume texture filename // Assume texture filename
#if 0 #if 0
@@ -1385,9 +1370,8 @@ static void SplitString(const std::string &s, char delim,
void LoadMtl( void LoadMtl(
// std::map<std::string, int> *material_map, // std::map<std::string, int> *material_map,
std::map<unsigned int, int> *material_map, std::map<unsigned int, int> *material_map, std::vector<material_t> *materials,
std::vector<material_t> *materials, std::istream *inStream, std::istream *inStream, std::string *warning) {
std::string *warning) {
// Create a default material anyway. // Create a default material anyway.
material_t material; material_t material;
InitMaterial(&material); InitMaterial(&material);
@@ -1440,8 +1424,11 @@ void LoadMtl(
if (IS_SPACE((token[2]))) { if (IS_SPACE((token[2]))) {
// group K // group K
if (token[0] == 'K') { if (token[0] == 'K') {
switch (token[1]) {
case 'a':
// ambient // ambient
if (token[1] == 'a') { // if (token[1] == 'a')
{
token += 2; token += 2;
real_t r, g, b; real_t r, g, b;
parseReal3(&r, &g, &b, &token); parseReal3(&r, &g, &b, &token);
@@ -1452,7 +1439,9 @@ void LoadMtl(
} }
// diffuse // diffuse
if (token[1] == 'd') { case 'd':
// if (token[1] == 'd')
{
token += 2; token += 2;
real_t r, g, b; real_t r, g, b;
parseReal3(&r, &g, &b, &token); parseReal3(&r, &g, &b, &token);
@@ -1463,7 +1452,9 @@ void LoadMtl(
} }
// specular // specular
if (token[1] == 's') { case 's':
// if (token[1] == 's')
{
token += 2; token += 2;
real_t r, g, b; real_t r, g, b;
parseReal3(&r, &g, &b, &token); parseReal3(&r, &g, &b, &token);
@@ -1474,7 +1465,9 @@ void LoadMtl(
} }
// transmittance // transmittance
if (token[1] == 't') { case 't':
// if (token[1] == 't')
{
token += 2; token += 2;
real_t r, g, b; real_t r, g, b;
parseReal3(&r, &g, &b, &token); parseReal3(&r, &g, &b, &token);
@@ -1485,7 +1478,9 @@ void LoadMtl(
} }
// emission // emission
if (token[1] == 'e') { case 'e':
// if (token[1] == 'e')
{
token += 2; token += 2;
real_t r, g, b; real_t r, g, b;
parseReal3(&r, &g, &b, &token); parseReal3(&r, &g, &b, &token);
@@ -1495,6 +1490,7 @@ void LoadMtl(
continue; continue;
} }
} }
}
// transmittance // transmittance
if ( //(token[0] == 'K' && token[1] == 't') || if ( //(token[0] == 'K' && token[1] == 't') ||
@@ -1521,8 +1517,22 @@ void LoadMtl(
material.shininess = parseReal(&token); material.shininess = parseReal(&token);
continue; continue;
} }
}
if (token[0] == 'T' && token[1] == 'r') { // dissolve
if ((token[0] == 'd' && IS_SPACE(token[1]))) {
token += 1;
material.dissolve = parseReal(&token);
if (has_tr) {
ss << "WARN: Both `d` and `Tr` parameters defined for \""
<< material.name << "\". Use the value of `d` for dissolve."
<< std::endl;
}
has_d = true;
continue;
}
if (token[0] == 'T' && token[1] == 'r' && IS_SPACE(token[2])) {
token += 2; token += 2;
if (has_d) { if (has_d) {
// `d` wins. Ignore `Tr` value. // `d` wins. Ignore `Tr` value.
@@ -1540,46 +1550,24 @@ void LoadMtl(
} }
// tigra: refactoring for new speedup release // tigra: refactoring for new speedup release
if (token[0] == 'P') { if (token[0] == 'P' && IS_SPACE(token[2])) {
token += 2;
// PBR: roughness // PBR: roughness
if (token[1] == 'r') { if (token[1] == 'r')
token += 2;
material.roughness = parseReal(&token); material.roughness = parseReal(&token);
continue; else
} else
// PBR: metallic // PBR: metallic
if (token[1] == 'm') { if (token[1] == 'm')
token += 2;
material.metallic = parseReal(&token); material.metallic = parseReal(&token);
continue; else
} else
// PBR: sheen // PBR: sheen
if (token[1] == 's') { if (token[1] == 's')
token += 2;
material.sheen = parseReal(&token); material.sheen = parseReal(&token);
continue; else
} else
// PBR: clearcoat thickness // PBR: clearcoat thickness
if (token[1] == 'c') { if (token[1] == 'c')
token += 2;
material.clearcoat_thickness = parseReal(&token); material.clearcoat_thickness = parseReal(&token);
continue;
}
}
}
// dissolve
if ((token[0] == 'd' && IS_SPACE(token[1]))) {
token += 1;
material.dissolve = parseReal(&token);
if (has_tr) {
ss << "WARN: Both `d` and `Tr` parameters defined for \""
<< material.name << "\". Use the value of `d` for dissolve."
<< std::endl;
}
has_d = true;
continue;
} }
a_tok = token2tok(token); a_tok = token2tok(token);
@@ -2003,9 +1991,8 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
if (token[0] == '#') continue; // comment line if (token[0] == '#') continue; // comment line
if (IS_SPACE((token[1]))) {
// vertex // vertex
if (token[0] == 'v') { if (token[0] == 'v' && IS_SPACE((token[1]))) {
token += 2; token += 2;
real_t x, y, z; real_t x, y, z;
real_t r, g, b; real_t r, g, b;
@@ -2020,8 +2007,29 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
continue; continue;
} }
// normal
if (token[0] == 'v' && token[1] == 'n' && IS_SPACE((token[2]))) {
token += 3;
real_t x, y, z;
parseReal3(&x, &y, &z, &token);
vn.push_back(x);
vn.push_back(y);
vn.push_back(z);
continue;
}
// texcoord
if (token[0] == 'v' && token[1] == 't' && IS_SPACE((token[2]))) {
token += 3;
real_t x, y;
parseReal2(&x, &y, &token);
vt.push_back(x);
vt.push_back(y);
continue;
}
// face // face
if (token[0] == 'f') { if (token[0] == 'f' && IS_SPACE((token[1]))) {
token += 2; token += 2;
token += strspn(token, " \t"); token += strspn(token, " \t");
@@ -2034,8 +2042,7 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
static_cast<int>(vn.size() / 3), static_cast<int>(vn.size() / 3),
static_cast<int>(vt.size() / 2), &vi)) { static_cast<int>(vt.size() / 2), &vi)) {
if (err) { if (err) {
(*err) = (*err) = "Failed parse `f' line(e.g. zero value for face index).\n";
"Failed parse `f' line(e.g. zero value for face index).\n";
} }
return false; return false;
} }
@@ -2053,10 +2060,10 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
} }
// group name // group name
if (token[0] == 'g') { if (token[0] == 'g' && IS_SPACE((token[1]))) {
// flush previous face group. // flush previous face group.
bool ret = exportFaceGroupToShape(&shape, faceGroup, tags, material, bool ret = exportFaceGroupToShape(&shape, faceGroup, tags, material, name,
name, triangulate); triangulate);
(void)ret; // return value not used. (void)ret; // return value not used.
if (shape.mesh.indices.size() > 0) { if (shape.mesh.indices.size() > 0) {
@@ -2090,10 +2097,10 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
} }
// object name // object name
if (token[0] == 'o') { if (token[0] == 'o' && IS_SPACE((token[1]))) {
// flush previous face group. // flush previous face group.
bool ret = exportFaceGroupToShape(&shape, faceGroup, tags, material, bool ret = exportFaceGroupToShape(&shape, faceGroup, tags, material, name,
name, triangulate); triangulate);
if (ret) { if (ret) {
shapes->push_back(shape); shapes->push_back(shape);
} }
@@ -2116,7 +2123,7 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
continue; continue;
} }
if (token[0] == 't') { if (token[0] == 't' && IS_SPACE(token[1])) {
tag_t tag; tag_t tag;
token += 2; token += 2;
@@ -2143,30 +2150,6 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
tags.push_back(tag); tags.push_back(tag);
} }
}
if (token[0] == 'v' && IS_SPACE((token[2]))) {
// normal
if (token[1] == 'n') {
token += 3;
real_t x, y, z;
parseReal3(&x, &y, &z, &token);
vn.push_back(x);
vn.push_back(y);
vn.push_back(z);
continue;
}
// texcoord
if (token[1] == 't') {
token += 3;
real_t x, y;
parseReal2(&x, &y, &token);
vt.push_back(x);
vt.push_back(y);
continue;
}
}
// tigra: refactoring for new speedup release // tigra: refactoring for new speedup release
// tigra: compares one more start // tigra: compares one more start