1 Commits

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

View File

@@ -1,3 +0,0 @@
git add *
git commit -m %1
git push origin master

View File

@@ -361,7 +361,7 @@ static bool TestStreamLoadObj() {
virtual ~MaterialStringStreamReader() {} virtual ~MaterialStringStreamReader() {}
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<unsigned int, int>* matMap,
std::string* err) { std::string* err) {
(void)matId; (void)matId;
std::string warning; std::string warning;

View File

@@ -303,7 +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::string* err) std::string* err)
{ {
(void)matId; (void)matId;

View File

@@ -278,7 +278,7 @@ class 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<uint32_t, int> *matMap, std::map<unsigned int, int> *matMap,
std::string *err) = 0; std::string *err) = 0;
}; };
@@ -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<uint32_t, 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<uint32_t, 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<uint32_t, 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
@@ -370,37 +367,29 @@ std::map<uint32_t, int> *material_map,
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
// #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 <sys/types.h>
#include <sys/stat.h>
#include <io.h> #include <io.h>
#include <sys/stat.h>
#include <sys/types.h>
#define O_LARGEFILE 0100000 #define O_LARGEFILE 0100000
#endif #endif
namespace tinyobj { namespace tinyobj {
#ifdef TINYOBJLOADER_IMPLEMENTATION_BUFREAD #ifdef TINYOBJLOADER_IMPLEMENTATION_BUFREAD
// tigra: ImportInBuf - buffered input file // tigra: ImportInBuf - buffered input file
class ImportInBuf: public std::streambuf class ImportInBuf : public std::streambuf {
{
public: public:
ImportInBuf(const char *filename, size_t buf_sz_ = 64 * 1024) ImportInBuf(const char *filename, size_t buf_sz_ = 64 * 1024)
:fd_(open(filename,O_RDONLY | O_LARGEFILE)) : fd_(open(filename, O_RDONLY | O_LARGEFILE)) {
{
// fprintf(stderr, "ImportInBuf(%s\n", filename); // fprintf(stderr, "ImportInBuf(%s\n", filename);
if(fd_<0) if (fd_ < 0) {
{
fprintf(stderr, "can't open file %s\n", filename); fprintf(stderr, "can't open file %s\n", filename);
exit(1); exit(1);
} }
@@ -420,8 +409,7 @@ fsize_=st.st_size;
} }
// you don't have to do it like this if your streams are 64 bit // you don't have to do it like this if your streams are 64 bit
void seekg(uint64_t pos) void seekg(uint64_t pos) {
{
lseek(fd_, pos, SEEK_SET); lseek(fd_, pos, SEEK_SET);
pos_ = pos; pos_ = pos;
setg(buffer_, buffer_, buffer_); setg(buffer_, buffer_, buffer_);
@@ -430,20 +418,20 @@ setg(buffer_,buffer_,buffer_);
uint64_t tellg() const { return pos_; } uint64_t tellg() const { return pos_; }
uint64_t size() const { return fsize_; } uint64_t size() const { return fsize_; }
~ImportInBuf(){ close(fd_); free(buffer_); } ~ImportInBuf() {
close(fd_);
free(buffer_);
}
private: private:
ImportInBuf(const ImportInBuf &); ImportInBuf(const ImportInBuf &);
ImportInBuf &operator=(const ImportInBuf &); ImportInBuf &operator=(const ImportInBuf &);
virtual int underflow() virtual int underflow() {
{ if (gptr() < egptr()) {
if(gptr()<egptr())
{
return *gptr(); return *gptr();
} }
int size = read(fd_, buffer_, buf_sz); int size = read(fd_, buffer_, buf_sz);
if(size) if (size) {
{
pos_ += size; pos_ += size;
setg(buffer_, buffer_, buffer_ + size); setg(buffer_, buffer_, buffer_ + size);
return *gptr(); return *gptr();
@@ -454,43 +442,41 @@ return EOF;
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
// tigra: x31 hash function // tigra: x31 hash function
typedef uint32_t khint_t; typedef unsigned int khint_t;
inline uint32_t X31_hash_string(const char *s) inline unsigned int X31_hash_string(const char *s) {
{ khint_t h = static_cast<khint_t>(*s);
khint_t h = *s; for (++s; *s; ++s) h = (h << 5) - h + static_cast<khint_t>(*s);
for (++s ; *s; ++s) h = (h << 5) - h + *s;
return h; return h;
} }
inline uint32_t X31_hash_stringSZ(const char *s, int sz) inline unsigned int X31_hash_stringSZ(const char *s, int sz) {
{
int i; int i;
khint_t h = *s; khint_t h = static_cast<khint_t>(*s);
for (++s, i = sz-1 ; i && *s; ++s, i--) h = (h << 5) - h + *s; for (++s, i = sz - 1; i && *s; ++s, i--) h = (h << 5) - h + static_cast<khint_t>(*s);
return h; return h;
} }
// tigra: refactoring2 - add list of keywords // tigra: refactoring2 - add list of keywords
static char * keywords[] = { static const char *keywords[] = {
// on off // on off
"on", "off", "on", "off",
// TextureType // TextureType
"cube_top", "cube_bottom", "cube_left", "cube_right", "cube_front", "cube_back", "sphere", "cube_top", "cube_bottom", "cube_left", "cube_right", "cube_front",
"cube_back", "sphere",
// TextureNameAndOption // TextureNameAndOption
"-blendu", "-blendv", "-clamp", "-boost", "-bm", "-o", "-s", "-t", "-type", "-imfchan", "-mm", "-blendu", "-blendv", "-clamp", "-boost", "-bm", "-o", "-s", "-t", "-type",
"-imfchan", "-mm",
// newmtl, illum, mtllib, usemtl // newmtl, illum, mtllib, usemtl
"newmtl", "illum", "mtllib", "usemtl", "newmtl", "illum", "mtllib", "usemtl",
@@ -520,28 +506,55 @@ static char * keywords[] = {
"map_Ke", "map_Ke",
// PBR: normal map texture // PBR: normal map texture
"norm" "norm"};
};
// tigra: enum of tokens // tigra: enum of tokens
enum tokens_enum { enum tokens_enum {
// on off // on off
TOK_on, TOK_off, TOK_on,
TOK_off,
// TextureType // TextureType
TOK_cube_top, TOK_cube_bottom, TOK_cube_left, TOK_cube_right, TOK_cube_front, TOK_cube_back, TOK_sphere, TOK_cube_top,
TOK_cube_bottom,
TOK_cube_left,
TOK_cube_right,
TOK_cube_front,
TOK_cube_back,
TOK_sphere,
// TextureNameAndOption // TextureNameAndOption
TOK_blendu, TOK_blendv, TOK_clamp, TOK_boost, TOK_bm, TOK_o, TOK_s, TOK_t, TOK_type, TOK_imfchan, TOK_mm, TOK_blendu,
TOK_blendv,
TOK_clamp,
TOK_boost,
TOK_bm,
TOK_o,
TOK_s,
TOK_t,
TOK_type,
TOK_imfchan,
TOK_mm,
// newmtl, illum, mtllib, usemtl // newmtl, illum, mtllib, usemtl
TOK_newmtl, TOK_illum, TOK_mtllib, TOK_usemtl, TOK_newmtl,
TOK_illum,
TOK_mtllib,
TOK_usemtl,
// PBR params // PBR params
TOK_Pcr, TOK_aniso, TOK_anisor, TOK_Pcr,
TOK_aniso,
TOK_anisor,
// maps // maps
TOK_map_Ka, TOK_map_Kd, TOK_map_Ks, TOK_map_Ns, TOK_map_bump, TOK_map_Bump, TOK_bump, TOK_map_Ka,
TOK_map_Kd,
TOK_map_Ks,
TOK_map_Ns,
TOK_map_bump,
TOK_map_Bump,
TOK_bump,
// alpha texture // alpha texture
TOK_map_d, TOK_map_d,
@@ -553,7 +566,8 @@ enum tokens_enum {
TOK_refl, TOK_refl,
// PBR: roughness texture, metallic texture // PBR: roughness texture, metallic texture
TOK_map_Pr, TOK_map_Pm, TOK_map_Pr,
TOK_map_Pm,
// PBR: sheen texture // PBR: sheen texture
TOK_map_Ps, TOK_map_Ps,
@@ -565,23 +579,27 @@ enum tokens_enum {
TOK_norm TOK_norm
}; };
std::map <uint32_t,int> hashed_toks; #ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wexit-time-destructors"
#pragma clang diagnostic ignored "-Wglobal-constructors"
#endif
static std::map<unsigned int, int> hashed_toks;
#ifdef __clang__
#pragma clang diagnostic pop
#endif
static void initHashedTokensMap() {
void initHashedTokensMap()
{
// init hashed tokens map // init hashed tokens map
uint32_t hhh; unsigned int hhh;
int iii; int iii;
if(hashed_toks.empty()) if (hashed_toks.empty()) {
{ for (iii = sizeof(keywords) / sizeof(char *); iii; iii--) {
for(iii=sizeof(keywords)/sizeof(char*);iii;iii--)
{
hhh = X31_hash_string(keywords[iii - 1]); hhh = X31_hash_string(keywords[iii - 1]);
hashed_toks[hhh] = iii - 1; hashed_toks[hhh] = iii - 1;
} }
@@ -589,25 +607,19 @@ void initHashedTokensMap()
// init hashed tokens map END // init hashed tokens map END
} }
static int token2tok(const char *token) {
int token2tok(const char* token) unsigned int token_sz, a_hash;
{
uint32_t token_sz, a_hash;
int a_tok; int a_tok;
token_sz = static_cast<unsigned int>(strpbrk(token, " \t\r") - token); // token length
token_sz = strpbrk(token, " \t\r") - 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, 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())
@@ -616,8 +628,6 @@ int token2tok(const char* token)
return a_tok; return a_tok;
} }
MaterialReader::~MaterialReader() {} MaterialReader::~MaterialReader() {}
struct vertex_index { struct vertex_index {
@@ -915,9 +925,10 @@ static inline void parseV(real_t *x, real_t *y, real_t *z, real_t *w,
} }
// Extension: parse vertex with colors(6 items) // Extension: parse vertex with colors(6 items)
static inline bool parseVertexWithColor(real_t *x, real_t *y, real_t *z, real_t *r, static inline bool parseVertexWithColor(real_t *x, real_t *y, real_t *z,
real_t *g, real_t *b, real_t *r, real_t *g, real_t *b,
const char **token, const double default_x = 0.0, const char **token,
const double default_x = 0.0,
const double default_y = 0.0, const double default_y = 0.0,
const double default_z = 0.0) { const double default_z = 0.0) {
(*x) = parseReal(token, default_x); (*x) = parseReal(token, default_x);
@@ -953,8 +964,6 @@ static inline texture_type_t parseTextureType(
texture_type_t ty = default_value; texture_type_t ty = default_value;
int a_tok; int a_tok;
// init hashed tokens map // init hashed tokens map
@@ -963,45 +972,35 @@ static inline texture_type_t parseTextureType(
a_tok = token2tok(*token); a_tok = token2tok(*token);
// tigra: dont check if wrong token // tigra: dont check if wrong token
if(a_tok>=TOK_cube_top && a_tok<=TOK_sphere) if (a_tok >= TOK_cube_top && a_tok <= TOK_sphere) {
{
// if ((0 == strncmp((*token), "cube_top", strlen("cube_top")))) // if ((0 == strncmp((*token), "cube_top", strlen("cube_top"))))
if (a_tok == TOK_cube_top) if (a_tok == TOK_cube_top) {
{
ty = TEXTURE_TYPE_CUBE_TOP; ty = TEXTURE_TYPE_CUBE_TOP;
} else } else
// if ((0 == strncmp((*token), "cube_bottom", strlen("cube_bottom")))) // if ((0 == strncmp((*token), "cube_bottom", strlen("cube_bottom"))))
if (a_tok == TOK_cube_bottom) if (a_tok == TOK_cube_bottom) {
{
ty = TEXTURE_TYPE_CUBE_BOTTOM; ty = TEXTURE_TYPE_CUBE_BOTTOM;
} else } else
// if ((0 == strncmp((*token), "cube_left", strlen("cube_left")))) // if ((0 == strncmp((*token), "cube_left", strlen("cube_left"))))
if (a_tok == TOK_cube_left) if (a_tok == TOK_cube_left) {
{
ty = TEXTURE_TYPE_CUBE_LEFT; ty = TEXTURE_TYPE_CUBE_LEFT;
} else } else
// if ((0 == strncmp((*token), "cube_right", strlen("cube_right")))) // if ((0 == strncmp((*token), "cube_right", strlen("cube_right"))))
if (a_tok == TOK_cube_right) if (a_tok == TOK_cube_right) {
{
ty = TEXTURE_TYPE_CUBE_RIGHT; ty = TEXTURE_TYPE_CUBE_RIGHT;
} else } else
// if ((0 == strncmp((*token), "cube_front", strlen("cube_front")))) // if ((0 == strncmp((*token), "cube_front", strlen("cube_front"))))
if (a_tok == TOK_cube_front) if (a_tok == TOK_cube_front) {
{
ty = TEXTURE_TYPE_CUBE_FRONT; ty = TEXTURE_TYPE_CUBE_FRONT;
} else } else
// if ((0 == strncmp((*token), "cube_back", strlen("cube_back")))) // if ((0 == strncmp((*token), "cube_back", strlen("cube_back"))))
if (a_tok == TOK_cube_back) if (a_tok == TOK_cube_back) {
{
ty = TEXTURE_TYPE_CUBE_BACK; ty = TEXTURE_TYPE_CUBE_BACK;
} else } else
// if ((0 == strncmp((*token), "sphere", strlen("sphere")))) // if ((0 == strncmp((*token), "sphere", strlen("sphere"))))
if (a_tok == TOK_sphere) if (a_tok == TOK_sphere) {
{
ty = TEXTURE_TYPE_SPHERE; ty = TEXTURE_TYPE_SPHERE;
} }
} }
(*token) = end; (*token) = end;
@@ -1153,82 +1152,68 @@ static bool ParseTextureNameAndOption(std::string *texname,
const char *token = linebuf; // Assume line ends with NULL const char *token = linebuf; // Assume line ends with NULL
int a_tok; int a_tok;
// init hashed tokens map // init hashed tokens map
initHashedTokensMap(); initHashedTokensMap();
while (!IS_NEW_LINE((*token))) { while (!IS_NEW_LINE((*token))) {
token += strspn(token, " \t"); // skip space token += strspn(token, " \t"); // skip space
a_tok = token2tok(token); a_tok = token2tok(token);
// tigra: minimize checks // tigra: minimize checks
if(a_tok>=TOK_blendu && a_tok<=TOK_mm) if (a_tok >= TOK_blendu && a_tok <= TOK_mm) {
{
// if ((0 == strncmp(token, "-blendu", 7)) && IS_SPACE((token[7]))) // if ((0 == strncmp(token, "-blendu", 7)) && IS_SPACE((token[7])))
if (a_tok == TOK_blendu) if (a_tok == TOK_blendu) {
{
token += 8; token += 8;
texopt->blendu = parseOnOff(&token, /* default */ true); texopt->blendu = parseOnOff(&token, /* default */ true);
} else } else
// if ((0 == strncmp(token, "-blendv", 7)) && IS_SPACE((token[7]))) // if ((0 == strncmp(token, "-blendv", 7)) && IS_SPACE((token[7])))
if (a_tok == TOK_blendv) if (a_tok == TOK_blendv) {
{
token += 8; token += 8;
texopt->blendv = parseOnOff(&token, /* default */ true); texopt->blendv = parseOnOff(&token, /* default */ true);
} else } else
// if ((0 == strncmp(token, "-clamp", 6)) && IS_SPACE((token[6]))) // if ((0 == strncmp(token, "-clamp", 6)) && IS_SPACE((token[6])))
if (a_tok == TOK_clamp) if (a_tok == TOK_clamp) {
{
token += 7; token += 7;
texopt->clamp = parseOnOff(&token, /* default */ true); texopt->clamp = parseOnOff(&token, /* default */ true);
} else } else
// if ((0 == strncmp(token, "-boost", 6)) && IS_SPACE((token[6]))) // if ((0 == strncmp(token, "-boost", 6)) && IS_SPACE((token[6])))
if (a_tok == TOK_boost) if (a_tok == TOK_boost) {
{
token += 7; token += 7;
texopt->sharpness = parseReal(&token, 1.0); texopt->sharpness = parseReal(&token, 1.0);
} else } else
// if ((0 == strncmp(token, "-bm", 3)) && IS_SPACE((token[3]))) // if ((0 == strncmp(token, "-bm", 3)) && IS_SPACE((token[3])))
if (a_tok == TOK_bm) if (a_tok == TOK_bm) {
{
token += 4; token += 4;
texopt->bump_multiplier = parseReal(&token, 1.0); texopt->bump_multiplier = parseReal(&token, 1.0);
} else } else
// if ((0 == strncmp(token, "-o", 2)) && IS_SPACE((token[2]))) // if ((0 == strncmp(token, "-o", 2)) && IS_SPACE((token[2])))
if (a_tok == TOK_o) if (a_tok == TOK_o) {
{
token += 3; token += 3;
parseReal3(&(texopt->origin_offset[0]), &(texopt->origin_offset[1]), parseReal3(&(texopt->origin_offset[0]), &(texopt->origin_offset[1]),
&(texopt->origin_offset[2]), &token); &(texopt->origin_offset[2]), &token);
} else } else
// if ((0 == strncmp(token, "-s", 2)) && IS_SPACE((token[2]))) // if ((0 == strncmp(token, "-s", 2)) && IS_SPACE((token[2])))
if (a_tok == TOK_s) if (a_tok == TOK_s) {
{
token += 3; token += 3;
parseReal3(&(texopt->scale[0]), &(texopt->scale[1]), &(texopt->scale[2]), parseReal3(&(texopt->scale[0]), &(texopt->scale[1]),
&token, 1.0, 1.0, 1.0); &(texopt->scale[2]), &token, 1.0, 1.0, 1.0);
} else } else
// if ((0 == strncmp(token, "-t", 2)) && IS_SPACE((token[2]))) // if ((0 == strncmp(token, "-t", 2)) && IS_SPACE((token[2])))
if (a_tok == TOK_t) if (a_tok == TOK_t) {
{
token += 3; token += 3;
parseReal3(&(texopt->turbulence[0]), &(texopt->turbulence[1]), parseReal3(&(texopt->turbulence[0]), &(texopt->turbulence[1]),
&(texopt->turbulence[2]), &token); &(texopt->turbulence[2]), &token);
} else } else
// if ((0 == strncmp(token, "-type", 5)) && IS_SPACE((token[5]))) // if ((0 == strncmp(token, "-type", 5)) && IS_SPACE((token[5])))
if (a_tok == TOK_type) if (a_tok == TOK_type) {
{
token += 5; token += 5;
texopt->type = parseTextureType((&token), TEXTURE_TYPE_NONE); texopt->type = parseTextureType((&token), TEXTURE_TYPE_NONE);
} else } else
// if ((0 == strncmp(token, "-imfchan", 8)) && IS_SPACE((token[8]))) // if ((0 == strncmp(token, "-imfchan", 8)) && IS_SPACE((token[8])))
if (a_tok == TOK_imfchan) if (a_tok == TOK_imfchan) {
{
token += 9; token += 9;
token += strspn(token, " \t"); token += strspn(token, " \t");
const char *end = token + strcspn(token, " \t\r"); const char *end = token + strcspn(token, " \t\r");
@@ -1238,13 +1223,12 @@ static bool ParseTextureNameAndOption(std::string *texname,
token = end; token = end;
} else } else
// if ((0 == strncmp(token, "-mm", 3)) && IS_SPACE((token[3]))) // if ((0 == strncmp(token, "-mm", 3)) && IS_SPACE((token[3])))
if (a_tok == TOK_mm) if (a_tok == TOK_mm) {
{
token += 4; token += 4;
parseReal2(&(texopt->brightness), &(texopt->contrast), &token, 0.0, 1.0); parseReal2(&(texopt->brightness), &(texopt->contrast), &token, 0.0,
1.0);
} }
} } else {
else {
// Assume texture filename // Assume texture filename
#if 0 #if 0
size_t len = strcspn(token, " \t\r"); // untile next space size_t len = strcspn(token, " \t\r"); // untile next space
@@ -1386,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<uint32_t, 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);
@@ -1402,8 +1385,6 @@ std::map<uint32_t, int> *material_map,
// init hashed tokens map // init hashed tokens map
initHashedTokensMap(); initHashedTokensMap();
std::stringstream ss; std::stringstream ss;
std::string linebuf; std::string linebuf;
@@ -1440,13 +1421,10 @@ std::map<uint32_t, int> *material_map,
if (token[0] == '#') continue; // comment line if (token[0] == '#') continue; // comment line
// group size==2 // group size==2
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]) {
switch(token[1])
{
case 'a': case 'a':
// ambient // ambient
// if (token[1] == 'a') // if (token[1] == 'a')
@@ -1512,7 +1490,6 @@ std::map<uint32_t, int> *material_map,
continue; continue;
} }
} }
} }
// transmittance // transmittance
@@ -1540,7 +1517,6 @@ std::map<uint32_t, int> *material_map,
material.shininess = parseReal(&token); material.shininess = parseReal(&token);
continue; continue;
} }
} }
// dissolve // dissolve
@@ -1594,18 +1570,14 @@ std::map<uint32_t, int> *material_map,
material.clearcoat_thickness = parseReal(&token); material.clearcoat_thickness = parseReal(&token);
} }
a_tok = token2tok(token); a_tok = token2tok(token);
// tigra: minimize checks // tigra: minimize checks
if(a_tok>=TOK_newmtl && a_tok<=TOK_norm) if (a_tok >= TOK_newmtl && a_tok <= TOK_norm) {
{
// tigra: refactoring for new speedup release // tigra: refactoring for new speedup release
// new mtl // new mtl
// if ((0 == strncmp(token, "newmtl", 6)) && IS_SPACE((token[6]))) // if ((0 == strncmp(token, "newmtl", 6)) && IS_SPACE((token[6])))
if (a_tok == TOK_newmtl) if (a_tok == TOK_newmtl) {
{
// flush previous material. // flush previous material.
if (!material.name.empty()) { if (!material.name.empty()) {
/* /*
@@ -1614,12 +1586,10 @@ std::map<uint32_t, int> *material_map,
); );
*/ */
unsigned int hsh1 = X31_hash_string(material.name.c_str());
uint32_t hsh1 = X31_hash_string(material.name.c_str()); material_map->insert(std::pair<unsigned int, int>(
hsh1, static_cast<int>(materials->size())));
material_map->insert(std::pair<uint32_t, int>(
hsh1, static_cast<int>(materials->size()))
);
materials->push_back(material); materials->push_back(material);
} }
@@ -1645,19 +1615,15 @@ std::map<uint32_t, int> *material_map,
// illum model // illum model
// if (0 == strncmp(token, "illum", 5) && IS_SPACE(token[5])) // if (0 == strncmp(token, "illum", 5) && IS_SPACE(token[5]))
if (a_tok == TOK_illum) if (a_tok == TOK_illum) {
{
token += 6; token += 6;
material.illum = parseInt(&token); material.illum = parseInt(&token);
continue; continue;
} }
// PBR: clearcoat roughness // PBR: clearcoat roughness
// if ((0 == strncmp(token, "Pcr", 3)) && IS_SPACE(token[3])) // if ((0 == strncmp(token, "Pcr", 3)) && IS_SPACE(token[3]))
if (a_tok == TOK_Pcr) if (a_tok == TOK_Pcr) {
{
token += 4; token += 4;
material.clearcoat_roughness = parseReal(&token); material.clearcoat_roughness = parseReal(&token);
continue; continue;
@@ -1665,8 +1631,7 @@ std::map<uint32_t, int> *material_map,
// PBR: anisotropy // PBR: anisotropy
// if ((0 == strncmp(token, "aniso", 5)) && IS_SPACE(token[5])) // if ((0 == strncmp(token, "aniso", 5)) && IS_SPACE(token[5]))
if (a_tok == TOK_aniso) if (a_tok == TOK_aniso) {
{
token += 6; token += 6;
material.anisotropy = parseReal(&token); material.anisotropy = parseReal(&token);
continue; continue;
@@ -1674,8 +1639,7 @@ std::map<uint32_t, int> *material_map,
// PBR: anisotropy rotation // PBR: anisotropy rotation
// if ((0 == strncmp(token, "anisor", 6)) && IS_SPACE(token[6])) // if ((0 == strncmp(token, "anisor", 6)) && IS_SPACE(token[6]))
if (a_tok == TOK_anisor) if (a_tok == TOK_anisor) {
{
token += 7; token += 7;
material.anisotropy_rotation = parseReal(&token); material.anisotropy_rotation = parseReal(&token);
continue; continue;
@@ -1683,8 +1647,7 @@ std::map<uint32_t, int> *material_map,
// ambient texture // ambient texture
// if ((0 == strncmp(token, "map_Ka", 6)) && IS_SPACE(token[6])) // if ((0 == strncmp(token, "map_Ka", 6)) && IS_SPACE(token[6]))
if (a_tok == TOK_map_Ka) if (a_tok == TOK_map_Ka) {
{
token += 7; token += 7;
ParseTextureNameAndOption(&(material.ambient_texname), ParseTextureNameAndOption(&(material.ambient_texname),
&(material.ambient_texopt), token, &(material.ambient_texopt), token,
@@ -1694,8 +1657,7 @@ std::map<uint32_t, int> *material_map,
// diffuse texture // diffuse texture
// if ((0 == strncmp(token, "map_Kd", 6)) && IS_SPACE(token[6])) // if ((0 == strncmp(token, "map_Kd", 6)) && IS_SPACE(token[6]))
if (a_tok == TOK_map_Kd) if (a_tok == TOK_map_Kd) {
{
token += 7; token += 7;
ParseTextureNameAndOption(&(material.diffuse_texname), ParseTextureNameAndOption(&(material.diffuse_texname),
&(material.diffuse_texopt), token, &(material.diffuse_texopt), token,
@@ -1705,8 +1667,7 @@ std::map<uint32_t, int> *material_map,
// specular texture // specular texture
// if ((0 == strncmp(token, "map_Ks", 6)) && IS_SPACE(token[6])) // if ((0 == strncmp(token, "map_Ks", 6)) && IS_SPACE(token[6]))
if (a_tok == TOK_map_Ks) if (a_tok == TOK_map_Ks) {
{
token += 7; token += 7;
ParseTextureNameAndOption(&(material.specular_texname), ParseTextureNameAndOption(&(material.specular_texname),
&(material.specular_texopt), token, &(material.specular_texopt), token,
@@ -1716,8 +1677,7 @@ std::map<uint32_t, int> *material_map,
// specular highlight texture // specular highlight texture
// if ((0 == strncmp(token, "map_Ns", 6)) && IS_SPACE(token[6])) // if ((0 == strncmp(token, "map_Ns", 6)) && IS_SPACE(token[6]))
if (a_tok == TOK_map_Ns) if (a_tok == TOK_map_Ns) {
{
token += 7; token += 7;
ParseTextureNameAndOption(&(material.specular_highlight_texname), ParseTextureNameAndOption(&(material.specular_highlight_texname),
&(material.specular_highlight_texopt), token, &(material.specular_highlight_texopt), token,
@@ -1727,8 +1687,7 @@ std::map<uint32_t, int> *material_map,
// bump texture // bump texture
// if ((0 == strncmp(token, "map_bump", 8)) && IS_SPACE(token[8])) // if ((0 == strncmp(token, "map_bump", 8)) && IS_SPACE(token[8]))
if (a_tok == TOK_map_bump) if (a_tok == TOK_map_bump) {
{
token += 9; token += 9;
ParseTextureNameAndOption(&(material.bump_texname), ParseTextureNameAndOption(&(material.bump_texname),
&(material.bump_texopt), token, &(material.bump_texopt), token,
@@ -1738,8 +1697,7 @@ std::map<uint32_t, int> *material_map,
// bump texture // bump texture
// if ((0 == strncmp(token, "map_Bump", 8)) && IS_SPACE(token[8])) // if ((0 == strncmp(token, "map_Bump", 8)) && IS_SPACE(token[8]))
if (a_tok == TOK_map_Bump) if (a_tok == TOK_map_Bump) {
{
token += 9; token += 9;
ParseTextureNameAndOption(&(material.bump_texname), ParseTextureNameAndOption(&(material.bump_texname),
&(material.bump_texopt), token, &(material.bump_texopt), token,
@@ -1749,8 +1707,7 @@ std::map<uint32_t, int> *material_map,
// bump texture // bump texture
// if ((0 == strncmp(token, "bump", 4)) && IS_SPACE(token[4])) // if ((0 == strncmp(token, "bump", 4)) && IS_SPACE(token[4]))
if (a_tok == TOK_bump) if (a_tok == TOK_bump) {
{
token += 5; token += 5;
ParseTextureNameAndOption(&(material.bump_texname), ParseTextureNameAndOption(&(material.bump_texname),
&(material.bump_texopt), token, &(material.bump_texopt), token,
@@ -1760,8 +1717,7 @@ std::map<uint32_t, int> *material_map,
// alpha texture // alpha texture
// if ((0 == strncmp(token, "map_d", 5)) && IS_SPACE(token[5])) // if ((0 == strncmp(token, "map_d", 5)) && IS_SPACE(token[5]))
if (a_tok == TOK_map_d) if (a_tok == TOK_map_d) {
{
token += 6; token += 6;
material.alpha_texname = token; material.alpha_texname = token;
ParseTextureNameAndOption(&(material.alpha_texname), ParseTextureNameAndOption(&(material.alpha_texname),
@@ -1772,8 +1728,7 @@ std::map<uint32_t, int> *material_map,
// displacement texture // displacement texture
// if ((0 == strncmp(token, "disp", 4)) && IS_SPACE(token[4])) // if ((0 == strncmp(token, "disp", 4)) && IS_SPACE(token[4]))
if (a_tok == TOK_disp) if (a_tok == TOK_disp) {
{
token += 5; token += 5;
ParseTextureNameAndOption(&(material.displacement_texname), ParseTextureNameAndOption(&(material.displacement_texname),
&(material.displacement_texopt), token, &(material.displacement_texopt), token,
@@ -1783,8 +1738,7 @@ std::map<uint32_t, int> *material_map,
// reflection map // reflection map
// if ((0 == strncmp(token, "refl", 4)) && IS_SPACE(token[4])) // if ((0 == strncmp(token, "refl", 4)) && IS_SPACE(token[4]))
if (a_tok == TOK_refl) if (a_tok == TOK_refl) {
{
token += 5; token += 5;
ParseTextureNameAndOption(&(material.reflection_texname), ParseTextureNameAndOption(&(material.reflection_texname),
&(material.reflection_texopt), token, &(material.reflection_texopt), token,
@@ -1794,8 +1748,7 @@ std::map<uint32_t, int> *material_map,
// PBR: roughness texture // PBR: roughness texture
// if ((0 == strncmp(token, "map_Pr", 6)) && IS_SPACE(token[6])) // if ((0 == strncmp(token, "map_Pr", 6)) && IS_SPACE(token[6]))
if (a_tok == TOK_map_Pr) if (a_tok == TOK_map_Pr) {
{
token += 7; token += 7;
ParseTextureNameAndOption(&(material.roughness_texname), ParseTextureNameAndOption(&(material.roughness_texname),
&(material.roughness_texopt), token, &(material.roughness_texopt), token,
@@ -1805,8 +1758,7 @@ std::map<uint32_t, int> *material_map,
// PBR: metallic texture // PBR: metallic texture
// if ((0 == strncmp(token, "map_Pm", 6)) && IS_SPACE(token[6])) // if ((0 == strncmp(token, "map_Pm", 6)) && IS_SPACE(token[6]))
if (a_tok == TOK_map_Pm) if (a_tok == TOK_map_Pm) {
{
token += 7; token += 7;
ParseTextureNameAndOption(&(material.metallic_texname), ParseTextureNameAndOption(&(material.metallic_texname),
&(material.metallic_texopt), token, &(material.metallic_texopt), token,
@@ -1816,8 +1768,7 @@ std::map<uint32_t, int> *material_map,
// PBR: sheen texture // PBR: sheen texture
// if ((0 == strncmp(token, "map_Ps", 6)) && IS_SPACE(token[6])) // if ((0 == strncmp(token, "map_Ps", 6)) && IS_SPACE(token[6]))
if (a_tok == TOK_map_Ps) if (a_tok == TOK_map_Ps) {
{
token += 7; token += 7;
ParseTextureNameAndOption(&(material.sheen_texname), ParseTextureNameAndOption(&(material.sheen_texname),
&(material.sheen_texopt), token, &(material.sheen_texopt), token,
@@ -1827,8 +1778,7 @@ std::map<uint32_t, int> *material_map,
// PBR: emissive texture // PBR: emissive texture
// if ((0 == strncmp(token, "map_Ke", 6)) && IS_SPACE(token[6])) // if ((0 == strncmp(token, "map_Ke", 6)) && IS_SPACE(token[6]))
if (a_tok == TOK_map_Ke) if (a_tok == TOK_map_Ke) {
{
token += 7; token += 7;
ParseTextureNameAndOption(&(material.emissive_texname), ParseTextureNameAndOption(&(material.emissive_texname),
&(material.emissive_texopt), token, &(material.emissive_texopt), token,
@@ -1838,8 +1788,7 @@ std::map<uint32_t, int> *material_map,
// PBR: normal map texture // PBR: normal map texture
// if ((0 == strncmp(token, "norm", 4)) && IS_SPACE(token[4])) // if ((0 == strncmp(token, "norm", 4)) && IS_SPACE(token[4]))
if (a_tok == TOK_norm) if (a_tok == TOK_norm) {
{
token += 5; token += 5;
ParseTextureNameAndOption( ParseTextureNameAndOption(
&(material.normal_texname), &(material.normal_texopt), token, &(material.normal_texname), &(material.normal_texopt), token,
@@ -1862,7 +1811,7 @@ std::map<uint32_t, int> *material_map,
} }
} }
uint32_t hsh1 = X31_hash_string(material.name.c_str()); unsigned int hsh1 = X31_hash_string(material.name.c_str());
// flush last material. // flush last material.
/* /*
@@ -1870,8 +1819,8 @@ std::map<uint32_t, int> *material_map,
material.name, static_cast<int>(materials->size()))); material.name, static_cast<int>(materials->size())));
*/ */
material_map->insert(std::pair<uint32_t, int>( material_map->insert(
hsh1, static_cast<int>(materials->size()))); std::pair<unsigned int, int>(hsh1, static_cast<int>(materials->size())));
materials->push_back(material); materials->push_back(material);
if (warning) { if (warning) {
@@ -1882,7 +1831,7 @@ std::map<uint32_t, int> *material_map,
bool MaterialFileReader::operator()(const std::string &matId, bool MaterialFileReader::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<uint32_t, int> *matMap, std::map<unsigned int, int> *matMap,
std::string *err) { std::string *err) {
std::string filepath; std::string filepath;
@@ -1924,7 +1873,7 @@ bool MaterialFileReader::operator()(const std::string &matId,
bool MaterialStreamReader::operator()(const std::string &matId, bool MaterialStreamReader::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<uint32_t, int> *matMap, std::map<unsigned int, int> *matMap,
std::string *err) { std::string *err) {
(void)matId; (void)matId;
if (!m_inStream) { if (!m_inStream) {
@@ -1999,7 +1948,6 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
std::vector<std::vector<vertex_index> > faceGroup; std::vector<std::vector<vertex_index> > faceGroup;
std::string name; std::string name;
int a_tok; int a_tok;
// init hashed tokens map // init hashed tokens map
@@ -2008,9 +1956,9 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
// material // material
// std::map<std::string, int> material_map; // std::map<std::string, int> material_map;
//tigra: key of material_map is uint32_t now // tigra: key of material_map is unsigned int now
// because std::map is an red-black trees it is better to store key as int // because std::map is an red-black trees it is better to store key as int
std::map<uint32_t, int> material_map; std::map<unsigned int, int> material_map;
int material = -1; int material = -1;
shape_t shape; shape_t shape;
@@ -2203,18 +2151,14 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
tags.push_back(tag); tags.push_back(tag);
} }
// tigra: refactoring for new speedup release // tigra: refactoring for new speedup release
// tigra: compares one more start // tigra: compares one more start
a_tok = token2tok(token); a_tok = token2tok(token);
// use mtl // use mtl
// if ((0 == strncmp(token, "usemtl", 6)) && IS_SPACE((token[6]))) // if ((0 == strncmp(token, "usemtl", 6)) && IS_SPACE((token[6])))
if (a_tok==TOK_usemtl) if (a_tok == TOK_usemtl) {
{
token += 7; token += 7;
/* /*
std::stringstream ss; std::stringstream ss;
@@ -2233,9 +2177,7 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
} }
*/ */
unsigned int hsh = X31_hash_string(token);
uint32_t hsh = X31_hash_string(token);
int newMaterialId = -1; int newMaterialId = -1;
if (material_map.find(hsh) != material_map.end()) { if (material_map.find(hsh) != material_map.end()) {
@@ -2259,8 +2201,7 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
// load mtl // load mtl
// if ((0 == strncmp(token, "mtllib", 6)) && IS_SPACE((token[6]))) // if ((0 == strncmp(token, "mtllib", 6)) && IS_SPACE((token[6])))
if (a_tok==TOK_mtllib) if (a_tok == TOK_mtllib) {
{
if (readMatFn) { if (readMatFn) {
token += 7; token += 7;
@@ -2336,17 +2277,14 @@ bool LoadObjWithCallback(std::istream &inStream, const callback_t &callback,
std::string *err /*= NULL*/) { std::string *err /*= NULL*/) {
std::stringstream errss; std::stringstream errss;
int a_tok; int a_tok;
// init hashed tokens map // init hashed tokens map
initHashedTokensMap(); initHashedTokensMap();
// material // material
// std::map<std::string, int> material_map; // std::map<std::string, int> material_map;
std::map<uint32_t, int> material_map; std::map<unsigned int, int> material_map;
int material_id = -1; // -1 = invalid int material_id = -1; // -1 = invalid
std::vector<index_t> indices; std::vector<index_t> indices;
@@ -2552,19 +2490,14 @@ bool LoadObjWithCallback(std::istream &inStream, const callback_t &callback,
} }
#endif #endif
// tigra: refactoring for new speedup release // tigra: refactoring for new speedup release
// tigra: compares start // tigra: compares start
a_tok = token2tok(token); a_tok = token2tok(token);
// use mtl // use mtl
// if ((0 == strncmp(token, "usemtl", 6)) && IS_SPACE((token[6]))) // if ((0 == strncmp(token, "usemtl", 6)) && IS_SPACE((token[6])))
if (a_tok==TOK_usemtl) if (a_tok == TOK_usemtl) {
{
token += 7; token += 7;
/* /*
std::stringstream ss; std::stringstream ss;
@@ -2584,7 +2517,7 @@ bool LoadObjWithCallback(std::istream &inStream, const callback_t &callback,
*/ */
// make a hash from token // make a hash from token
uint32_t hsh = X31_hash_string(token); unsigned int hsh = X31_hash_string(token);
int newMaterialId = -1; int newMaterialId = -1;
if (material_map.find(hsh) != material_map.end()) { if (material_map.find(hsh) != material_map.end()) {
@@ -2607,8 +2540,7 @@ bool LoadObjWithCallback(std::istream &inStream, const callback_t &callback,
// load mtl // load mtl
// if ((0 == strncmp(token, "mtllib", 6)) && IS_SPACE((token[6]))) // if ((0 == strncmp(token, "mtllib", 6)) && IS_SPACE((token[6])))
if (a_tok == TOK_mtllib) if (a_tok == TOK_mtllib) {
{
if (readMatFn) { if (readMatFn) {
token += 7; token += 7;