Format code.

This commit is contained in:
Syoyo Fujita
2017-12-12 17:31:22 +09:00
parent 583590767e
commit 160d6be10f

View File

@@ -370,37 +370,28 @@ std::map<unsigned int, int> *material_map,
#include <fstream>
#include <sstream>
//#define TINYOBJLOADER_IMPLEMENTATION_BUFREAD
#ifdef TINYOBJLOADER_IMPLEMENTATION_BUFREAD
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <io.h>
#include <sys/stat.h>
#include <sys/types.h>
#define O_LARGEFILE 0100000
#endif
namespace tinyobj {
#ifdef TINYOBJLOADER_IMPLEMENTATION_BUFREAD
// tigra: ImportInBuf - buffered input file
class ImportInBuf: public std::streambuf
{
class ImportInBuf : public std::streambuf {
public:
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);
if(fd_<0)
{
if (fd_ < 0) {
fprintf(stderr, "can't open file %s\n", filename);
exit(1);
}
@@ -420,8 +411,7 @@ fsize_=st.st_size;
}
// 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);
pos_ = pos;
setg(buffer_, buffer_, buffer_);
@@ -430,20 +420,20 @@ setg(buffer_,buffer_,buffer_);
uint64_t tellg() const { return pos_; }
uint64_t size() const { return fsize_; }
~ImportInBuf(){ close(fd_); free(buffer_); }
~ImportInBuf() {
close(fd_);
free(buffer_);
}
private:
ImportInBuf(const ImportInBuf &);
ImportInBuf &operator=(const ImportInBuf &);
virtual int underflow()
{
if(gptr()<egptr())
{
virtual int underflow() {
if (gptr() < egptr()) {
return *gptr();
}
int size = read(fd_, buffer_, buf_sz);
if(size)
{
if (size) {
pos_ += size;
setg(buffer_, buffer_, buffer_ + size);
return *gptr();
@@ -459,8 +449,6 @@ size_t buf_sz;
};
#endif
//***************************************************
//*************** tigro keywords hash functions begin
@@ -468,33 +456,33 @@ size_t buf_sz;
typedef unsigned int khint_t;
inline unsigned int X31_hash_string(const char *s)
{
inline unsigned int X31_hash_string(const char *s) {
khint_t h = static_cast<khint_t>(*s);
for (++s; *s; ++s) h = (h << 5) - h + static_cast<khint_t>(*s);
return h;
}
inline unsigned int X31_hash_stringSZ(const char *s, int sz)
{
inline unsigned int X31_hash_stringSZ(const char *s, int sz) {
int i;
khint_t h = static_cast<khint_t>(*s);
for (++s, i = sz-1 ; i && *s; ++s, i--) h = (h << 5) - h + static_cast<khint_t>(*s);
for (++s, i = sz - 1; i && *s; ++s, i--)
h = (h << 5) - h + static_cast<khint_t>(*s);
return h;
}
// tigra: refactoring2 - add list of keywords
static const char *keywords[] = {
// on off
"on", "off",
// 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
"-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",
@@ -524,28 +512,55 @@ static const char * keywords[] = {
"map_Ke",
// PBR: normal map texture
"norm"
};
"norm"};
// tigra: enum of tokens
enum tokens_enum {
// on off
TOK_on, TOK_off,
TOK_on,
TOK_off,
// 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
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
TOK_newmtl, TOK_illum, TOK_mtllib, TOK_usemtl,
TOK_newmtl,
TOK_illum,
TOK_mtllib,
TOK_usemtl,
// PBR params
TOK_Pcr, TOK_aniso, TOK_anisor,
TOK_Pcr,
TOK_aniso,
TOK_anisor,
// 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
TOK_map_d,
@@ -557,7 +572,8 @@ enum tokens_enum {
TOK_refl,
// PBR: roughness texture, metallic texture
TOK_map_Pr, TOK_map_Pm,
TOK_map_Pr,
TOK_map_Pm,
// PBR: sheen texture
TOK_map_Ps,
@@ -569,7 +585,6 @@ enum tokens_enum {
TOK_norm
};
// TODO(syoyo): Do not define in global scope.
#ifdef __clang__
@@ -584,19 +599,15 @@ static std::map <unsigned int,int> hashed_toks;
#pragma clang diagnostic pop
#endif
// functions!
static void initHashedTokensMap()
{
static void initHashedTokensMap() {
// init hashed tokens map
unsigned int hhh;
int iii;
if(hashed_toks.empty())
{
for(iii=sizeof(keywords)/sizeof(char*);iii;iii--)
{
if (hashed_toks.empty()) {
for (iii = sizeof(keywords) / sizeof(char *); iii; iii--) {
hhh = X31_hash_string(keywords[iii - 1]);
hashed_toks[hhh] = iii - 1;
}
@@ -604,28 +615,23 @@ static void initHashedTokensMap()
// 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;
int a_tok;
token_sz = static_cast<unsigned int>(strpbrk(token, " \t\r") - token); // token length
token_sz = static_cast<unsigned int>(strpbrk(token, " \t\r") -
token); // token length
if (token_sz < 1) // delimiter not found, token_sz = strlen(token)
{
// token_sz=strlen(token);
a_hash = X31_hash_string(token);
}
else {
} else {
a_hash = X31_hash_stringSZ(token, static_cast<int>(token_sz));
}
a_tok = -1;
if (hashed_toks.find(a_hash) != hashed_toks.end())
a_tok = hashed_toks[a_hash];
@@ -636,8 +642,6 @@ static int token2tok(const char* token)
//*************** tigro keywords hash functions END
//*************************************************
MaterialReader::~MaterialReader() {}
struct vertex_index {
@@ -935,9 +939,10 @@ static inline void parseV(real_t *x, real_t *y, real_t *z, real_t *w,
}
// Extension: parse vertex with colors(6 items)
static inline bool parseVertexWithColor(real_t *x, real_t *y, real_t *z, real_t *r,
real_t *g, real_t *b,
const char **token, const double default_x = 0.0,
static inline bool parseVertexWithColor(real_t *x, real_t *y, real_t *z,
real_t *r, real_t *g, real_t *b,
const char **token,
const double default_x = 0.0,
const double default_y = 0.0,
const double default_z = 0.0) {
(*x) = parseReal(token, default_x);
@@ -973,8 +978,6 @@ static inline texture_type_t parseTextureType(
texture_type_t ty = default_value;
int a_tok;
// init hashed tokens map
@@ -983,45 +986,35 @@ static inline texture_type_t parseTextureType(
a_tok = token2tok(*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 (a_tok == TOK_cube_top)
{
if (a_tok == TOK_cube_top) {
ty = TEXTURE_TYPE_CUBE_TOP;
} else
// 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;
} else
// 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;
} else
// 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;
} else
// 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;
} else
// 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;
} else
// if ((0 == strncmp((*token), "sphere", strlen("sphere"))))
if (a_tok == TOK_sphere)
{
if (a_tok == TOK_sphere) {
ty = TEXTURE_TYPE_SPHERE;
}
}
(*token) = end;
@@ -1173,83 +1166,68 @@ static bool ParseTextureNameAndOption(std::string *texname,
const char *token = linebuf; // Assume line ends with NULL
int a_tok;
// init hashed tokens map
initHashedTokensMap();
while (!IS_NEW_LINE((*token))) {
token += strspn(token, " \t"); // skip space
a_tok = token2tok(token);
// 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 (a_tok == TOK_blendu)
{
if (a_tok == TOK_blendu) {
token += 8;
texopt->blendu = parseOnOff(&token, /* default */ true);
} else
// if ((0 == strncmp(token, "-blendv", 7)) && IS_SPACE((token[7])))
if (a_tok == TOK_blendv)
{
if (a_tok == TOK_blendv) {
token += 8;
texopt->blendv = parseOnOff(&token, /* default */ true);
} else
// if ((0 == strncmp(token, "-clamp", 6)) && IS_SPACE((token[6])))
if (a_tok == TOK_clamp)
{
if (a_tok == TOK_clamp) {
token += 7;
texopt->clamp = parseOnOff(&token, /* default */ true);
} else
// if ((0 == strncmp(token, "-boost", 6)) && IS_SPACE((token[6])))
if (a_tok == TOK_boost)
{
if (a_tok == TOK_boost) {
token += 7;
texopt->sharpness = parseReal(&token, 1.0);
} else
// if ((0 == strncmp(token, "-bm", 3)) && IS_SPACE((token[3])))
if (a_tok == TOK_bm)
{
if (a_tok == TOK_bm) {
token += 4;
texopt->bump_multiplier = parseReal(&token, 1.0);
} else
// if ((0 == strncmp(token, "-o", 2)) && IS_SPACE((token[2])))
if (a_tok == TOK_o)
{
if (a_tok == TOK_o) {
token += 3;
parseReal3(&(texopt->origin_offset[0]), &(texopt->origin_offset[1]),
&(texopt->origin_offset[2]), &token);
} else
// if ((0 == strncmp(token, "-s", 2)) && IS_SPACE((token[2])))
if (a_tok == TOK_s)
{
if (a_tok == TOK_s) {
token += 3;
parseReal3(&(texopt->scale[0]), &(texopt->scale[1]), &(texopt->scale[2]),
&token, 1.0, 1.0, 1.0);
parseReal3(&(texopt->scale[0]), &(texopt->scale[1]),
&(texopt->scale[2]), &token, 1.0, 1.0, 1.0);
} else
// if ((0 == strncmp(token, "-t", 2)) && IS_SPACE((token[2])))
if (a_tok == TOK_t)
{
if (a_tok == TOK_t) {
token += 3;
parseReal3(&(texopt->turbulence[0]), &(texopt->turbulence[1]),
&(texopt->turbulence[2]), &token);
} else
// if ((0 == strncmp(token, "-type", 5)) && IS_SPACE((token[5])))
if (a_tok == TOK_type)
{
if (a_tok == TOK_type) {
token += 5;
texopt->type = parseTextureType((&token), TEXTURE_TYPE_NONE);
} else
// if ((0 == strncmp(token, "-imfchan", 8)) && IS_SPACE((token[8])))
if (a_tok == TOK_imfchan)
{
if (a_tok == TOK_imfchan) {
token += 9;
token += strspn(token, " \t");
const char *end = token + strcspn(token, " \t\r");
@@ -1259,14 +1237,13 @@ static bool ParseTextureNameAndOption(std::string *texname,
token = end;
} else
// if ((0 == strncmp(token, "-mm", 3)) && IS_SPACE((token[3])))
if (a_tok == TOK_mm)
{
if (a_tok == TOK_mm) {
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
#if 0
size_t len = strcspn(token, " \t\r"); // untile next space
@@ -1424,8 +1401,6 @@ std::map<unsigned int, int> *material_map,
// init hashed tokens map
initHashedTokensMap();
std::stringstream ss;
std::string linebuf;
@@ -1462,14 +1437,11 @@ std::map<unsigned int, int> *material_map,
if (token[0] == '#') continue; // comment line
// group size==2
if(IS_SPACE((token[2])))
{
if (IS_SPACE((token[2]))) {
// group K
if (token[0] == 'K')
{
if (token[0] == 'K') {
// ambient
if (token[1] == 'a')
{
if (token[1] == 'a') {
token += 2;
real_t r, g, b;
parseReal3(&r, &g, &b, &token);
@@ -1480,8 +1452,7 @@ std::map<unsigned int, int> *material_map,
}
// diffuse
if (token[1] == 'd')
{
if (token[1] == 'd') {
token += 2;
real_t r, g, b;
parseReal3(&r, &g, &b, &token);
@@ -1492,8 +1463,7 @@ std::map<unsigned int, int> *material_map,
}
// specular
if (token[1] == 's')
{
if (token[1] == 's') {
token += 2;
real_t r, g, b;
parseReal3(&r, &g, &b, &token);
@@ -1504,8 +1474,7 @@ std::map<unsigned int, int> *material_map,
}
// transmittance
if (token[1] == 't')
{
if (token[1] == 't') {
token += 2;
real_t r, g, b;
parseReal3(&r, &g, &b, &token);
@@ -1516,8 +1485,7 @@ std::map<unsigned int, int> *material_map,
}
// emission
if (token[1] == 'e')
{
if (token[1] == 'e') {
token += 2;
real_t r, g, b;
parseReal3(&r, &g, &b, &token);
@@ -1554,7 +1522,6 @@ std::map<unsigned int, int> *material_map,
continue;
}
if (token[0] == 'T' && token[1] == 'r') {
token += 2;
if (has_d) {
@@ -1574,34 +1541,26 @@ std::map<unsigned int, int> *material_map,
// tigra: refactoring for new speedup release
if (token[0] == 'P') {
// PBR: roughness
if(token[1] == 'r')
{
if (token[1] == 'r') {
token += 2;
material.roughness = parseReal(&token);
continue;
}
else
} else
// PBR: metallic
if(token[1] == 'm')
{
if (token[1] == 'm') {
token += 2;
material.metallic = parseReal(&token);
continue;
}
else
} else
// PBR: sheen
if(token[1] == 's')
{
if (token[1] == 's') {
token += 2;
material.sheen = parseReal(&token);
continue;
}
else
} else
// PBR: clearcoat thickness
if(token[1] == 'c')
{
if (token[1] == 'c') {
token += 2;
material.clearcoat_thickness = parseReal(&token);
continue;
@@ -1623,18 +1582,14 @@ std::map<unsigned int, int> *material_map,
continue;
}
a_tok = token2tok(token);
// 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
// new mtl
// if ((0 == strncmp(token, "newmtl", 6)) && IS_SPACE((token[6])))
if (a_tok == TOK_newmtl)
{
if (a_tok == TOK_newmtl) {
// flush previous material.
if (!material.name.empty()) {
/*
@@ -1643,12 +1598,10 @@ std::map<unsigned int, int> *material_map,
);
*/
unsigned int hsh1 = X31_hash_string(material.name.c_str());
material_map->insert(std::pair<unsigned int, int>(
hsh1, static_cast<int>(materials->size()))
);
hsh1, static_cast<int>(materials->size())));
materials->push_back(material);
}
@@ -1674,19 +1627,15 @@ std::map<unsigned int, int> *material_map,
// illum model
// if (0 == strncmp(token, "illum", 5) && IS_SPACE(token[5]))
if (a_tok == TOK_illum)
{
if (a_tok == TOK_illum) {
token += 6;
material.illum = parseInt(&token);
continue;
}
// PBR: clearcoat roughness
// if ((0 == strncmp(token, "Pcr", 3)) && IS_SPACE(token[3]))
if (a_tok == TOK_Pcr)
{
if (a_tok == TOK_Pcr) {
token += 4;
material.clearcoat_roughness = parseReal(&token);
continue;
@@ -1694,8 +1643,7 @@ std::map<unsigned int, int> *material_map,
// PBR: anisotropy
// if ((0 == strncmp(token, "aniso", 5)) && IS_SPACE(token[5]))
if (a_tok == TOK_aniso)
{
if (a_tok == TOK_aniso) {
token += 6;
material.anisotropy = parseReal(&token);
continue;
@@ -1703,8 +1651,7 @@ std::map<unsigned int, int> *material_map,
// PBR: anisotropy rotation
// if ((0 == strncmp(token, "anisor", 6)) && IS_SPACE(token[6]))
if (a_tok == TOK_anisor)
{
if (a_tok == TOK_anisor) {
token += 7;
material.anisotropy_rotation = parseReal(&token);
continue;
@@ -1712,8 +1659,7 @@ std::map<unsigned int, int> *material_map,
// ambient texture
// 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;
ParseTextureNameAndOption(&(material.ambient_texname),
&(material.ambient_texopt), token,
@@ -1723,8 +1669,7 @@ std::map<unsigned int, int> *material_map,
// diffuse texture
// 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;
ParseTextureNameAndOption(&(material.diffuse_texname),
&(material.diffuse_texopt), token,
@@ -1734,8 +1679,7 @@ std::map<unsigned int, int> *material_map,
// specular texture
// 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;
ParseTextureNameAndOption(&(material.specular_texname),
&(material.specular_texopt), token,
@@ -1745,8 +1689,7 @@ std::map<unsigned int, int> *material_map,
// specular highlight texture
// 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;
ParseTextureNameAndOption(&(material.specular_highlight_texname),
&(material.specular_highlight_texopt), token,
@@ -1756,8 +1699,7 @@ std::map<unsigned int, int> *material_map,
// bump texture
// 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;
ParseTextureNameAndOption(&(material.bump_texname),
&(material.bump_texopt), token,
@@ -1767,8 +1709,7 @@ std::map<unsigned int, int> *material_map,
// bump texture
// 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;
ParseTextureNameAndOption(&(material.bump_texname),
&(material.bump_texopt), token,
@@ -1778,8 +1719,7 @@ std::map<unsigned int, int> *material_map,
// bump texture
// if ((0 == strncmp(token, "bump", 4)) && IS_SPACE(token[4]))
if (a_tok == TOK_bump)
{
if (a_tok == TOK_bump) {
token += 5;
ParseTextureNameAndOption(&(material.bump_texname),
&(material.bump_texopt), token,
@@ -1789,8 +1729,7 @@ std::map<unsigned int, int> *material_map,
// alpha texture
// 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;
material.alpha_texname = token;
ParseTextureNameAndOption(&(material.alpha_texname),
@@ -1801,8 +1740,7 @@ std::map<unsigned int, int> *material_map,
// displacement texture
// if ((0 == strncmp(token, "disp", 4)) && IS_SPACE(token[4]))
if (a_tok == TOK_disp)
{
if (a_tok == TOK_disp) {
token += 5;
ParseTextureNameAndOption(&(material.displacement_texname),
&(material.displacement_texopt), token,
@@ -1812,8 +1750,7 @@ std::map<unsigned int, int> *material_map,
// reflection map
// if ((0 == strncmp(token, "refl", 4)) && IS_SPACE(token[4]))
if (a_tok == TOK_refl)
{
if (a_tok == TOK_refl) {
token += 5;
ParseTextureNameAndOption(&(material.reflection_texname),
&(material.reflection_texopt), token,
@@ -1823,8 +1760,7 @@ std::map<unsigned int, int> *material_map,
// PBR: roughness texture
// 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;
ParseTextureNameAndOption(&(material.roughness_texname),
&(material.roughness_texopt), token,
@@ -1834,8 +1770,7 @@ std::map<unsigned int, int> *material_map,
// PBR: metallic texture
// 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;
ParseTextureNameAndOption(&(material.metallic_texname),
&(material.metallic_texopt), token,
@@ -1845,8 +1780,7 @@ std::map<unsigned int, int> *material_map,
// PBR: sheen texture
// 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;
ParseTextureNameAndOption(&(material.sheen_texname),
&(material.sheen_texopt), token,
@@ -1856,8 +1790,7 @@ std::map<unsigned int, int> *material_map,
// PBR: emissive texture
// 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;
ParseTextureNameAndOption(&(material.emissive_texname),
&(material.emissive_texopt), token,
@@ -1867,8 +1800,7 @@ std::map<unsigned int, int> *material_map,
// PBR: normal map texture
// if ((0 == strncmp(token, "norm", 4)) && IS_SPACE(token[4]))
if (a_tok == TOK_norm)
{
if (a_tok == TOK_norm) {
token += 5;
ParseTextureNameAndOption(
&(material.normal_texname), &(material.normal_texopt), token,
@@ -1899,8 +1831,8 @@ std::map<unsigned int, int> *material_map,
material.name, static_cast<int>(materials->size())));
*/
material_map->insert(std::pair<unsigned int, int>(
hsh1, static_cast<int>(materials->size())));
material_map->insert(
std::pair<unsigned int, int>(hsh1, static_cast<int>(materials->size())));
materials->push_back(material);
if (warning) {
@@ -2028,7 +1960,6 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
std::vector<std::vector<vertex_index> > faceGroup;
std::string name;
int a_tok;
// init hashed tokens map
@@ -2103,7 +2034,8 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
static_cast<int>(vn.size() / 3),
static_cast<int>(vt.size() / 2), &vi)) {
if (err) {
(*err) = "Failed parse `f' line(e.g. zero value for face index).\n";
(*err) =
"Failed parse `f' line(e.g. zero value for face index).\n";
}
return false;
}
@@ -2123,8 +2055,8 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
// group name
if (token[0] == 'g') {
// flush previous face group.
bool ret = exportFaceGroupToShape(&shape, faceGroup, tags, material, name,
triangulate);
bool ret = exportFaceGroupToShape(&shape, faceGroup, tags, material,
name, triangulate);
(void)ret; // return value not used.
if (shape.mesh.indices.size() > 0) {
@@ -2160,8 +2092,8 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
// object name
if (token[0] == 'o') {
// flush previous face group.
bool ret = exportFaceGroupToShape(&shape, faceGroup, tags, material, name,
triangulate);
bool ret = exportFaceGroupToShape(&shape, faceGroup, tags, material,
name, triangulate);
if (ret) {
shapes->push_back(shape);
}
@@ -2213,8 +2145,6 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
}
}
if (token[0] == 'v' && IS_SPACE((token[2]))) {
// normal
if (token[1] == 'n') {
@@ -2241,14 +2171,11 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
// tigra: refactoring for new speedup release
// tigra: compares one more start
a_tok = token2tok(token);
// use mtl
// if ((0 == strncmp(token, "usemtl", 6)) && IS_SPACE((token[6])))
if (a_tok==TOK_usemtl)
{
if (a_tok == TOK_usemtl) {
token += 7;
/*
std::stringstream ss;
@@ -2267,8 +2194,6 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
}
*/
unsigned int hsh = X31_hash_string(token);
int newMaterialId = -1;
@@ -2293,8 +2218,7 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
// load mtl
// if ((0 == strncmp(token, "mtllib", 6)) && IS_SPACE((token[6])))
if (a_tok==TOK_mtllib)
{
if (a_tok == TOK_mtllib) {
if (readMatFn) {
token += 7;
@@ -2370,14 +2294,11 @@ bool LoadObjWithCallback(std::istream &inStream, const callback_t &callback,
std::string *err /*= NULL*/) {
std::stringstream errss;
int a_tok;
// init hashed tokens map
initHashedTokensMap();
// material
// std::map<std::string, int> material_map;
std::map<unsigned int, int> material_map;
@@ -2586,19 +2507,14 @@ bool LoadObjWithCallback(std::istream &inStream, const callback_t &callback,
}
#endif
// tigra: refactoring for new speedup release
// tigra: compares start
a_tok = token2tok(token);
// use mtl
// if ((0 == strncmp(token, "usemtl", 6)) && IS_SPACE((token[6])))
if (a_tok==TOK_usemtl)
{
if (a_tok == TOK_usemtl) {
token += 7;
/*
std::stringstream ss;
@@ -2641,8 +2557,7 @@ bool LoadObjWithCallback(std::istream &inStream, const callback_t &callback,
// load mtl
// if ((0 == strncmp(token, "mtllib", 6)) && IS_SPACE((token[6])))
if (a_tok == TOK_mtllib)
{
if (a_tok == TOK_mtllib) {
if (readMatFn) {
token += 7;