tiny_obj 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/ext/tiny_obj/tiny_obj_loader.h +81 -78
- data/lib/tiny_obj/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 509d72ffa20f965c025d7c3a3526ebd37d70bd4c658287745e63524798dd6f57
|
4
|
+
data.tar.gz: 6de83d9a0b674e1adfe3eb14e7d8db3357a8adafa6c2385442c6e14c6adc53a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 488dd94ca30b252504eb4ea4897d7af26fec8c46990caae26ab183264cc7f938e512710437eba1b0ba38cf16acf6c1271fd292427da5f7d2ed990deac91f13db
|
7
|
+
data.tar.gz: '09008e7cae84b20138cb7304090f95b40ff131f63d0df73c0fe4ce731563ff835234ec543a6b02b55dc9378d81742ad9616b6664aa8b786ae79b074b9742fc51'
|
data/Gemfile.lock
CHANGED
@@ -23,6 +23,7 @@ THE SOFTWARE.
|
|
23
23
|
*/
|
24
24
|
|
25
25
|
//
|
26
|
+
// version 1.4.0 : Modifed ParseTextureNameAndOption API
|
26
27
|
// version 1.3.1 : Make ParseTextureNameAndOption API public
|
27
28
|
// version 1.3.0 : Separate warning and error message(breaking API of LoadObj)
|
28
29
|
// version 1.2.3 : Added color space extension('-colorspace') to tex opts.
|
@@ -158,8 +159,8 @@ typedef struct {
|
|
158
159
|
real_t bump_multiplier; // -bm (for bump maps only, default 1.0)
|
159
160
|
|
160
161
|
// extension
|
161
|
-
std::string colorspace; // Explicitly specify color space of stored
|
162
|
-
// Usually `sRGB` or `linear` (default empty).
|
162
|
+
std::string colorspace; // Explicitly specify color space of stored texel
|
163
|
+
// value. Usually `sRGB` or `linear` (default empty).
|
163
164
|
} texture_option_t;
|
164
165
|
|
165
166
|
typedef struct {
|
@@ -388,17 +389,15 @@ void LoadMtl(std::map<std::string, int> *material_map,
|
|
388
389
|
std::string *warning, std::string *err);
|
389
390
|
|
390
391
|
///
|
391
|
-
/// Parse texture name and texture option for custom texture parameter through
|
392
|
+
/// Parse texture name and texture option for custom texture parameter through
|
393
|
+
/// material::unknown_parameter
|
392
394
|
///
|
393
395
|
/// @param[out] texname Parsed texture name
|
394
396
|
/// @param[out] texopt Parsed texopt
|
395
397
|
/// @param[in] linebuf Input string
|
396
|
-
/// @param[in] is_bump Is this texture bump/normal?
|
397
398
|
///
|
398
|
-
bool ParseTextureNameAndOption(std::string *texname,
|
399
|
-
|
400
|
-
const char *linebuf,
|
401
|
-
const bool is_bump);
|
399
|
+
bool ParseTextureNameAndOption(std::string *texname, texture_option_t *texopt,
|
400
|
+
const char *linebuf);
|
402
401
|
} // namespace tinyobj
|
403
402
|
|
404
403
|
#endif // TINY_OBJ_LOADER_H_
|
@@ -904,37 +903,12 @@ static vertex_index_t parseRawTriple(const char **token) {
|
|
904
903
|
return vi;
|
905
904
|
}
|
906
905
|
|
907
|
-
bool ParseTextureNameAndOption(std::string *texname,
|
908
|
-
|
909
|
-
const char *linebuf, const bool is_bump) {
|
906
|
+
bool ParseTextureNameAndOption(std::string *texname, texture_option_t *texopt,
|
907
|
+
const char *linebuf) {
|
910
908
|
// @todo { write more robust lexer and parser. }
|
911
909
|
bool found_texname = false;
|
912
910
|
std::string texture_name;
|
913
911
|
|
914
|
-
// Fill with default value for texopt.
|
915
|
-
if (is_bump) {
|
916
|
-
texopt->imfchan = 'l';
|
917
|
-
} else {
|
918
|
-
texopt->imfchan = 'm';
|
919
|
-
}
|
920
|
-
texopt->bump_multiplier = static_cast<real_t>(1.0);
|
921
|
-
texopt->clamp = false;
|
922
|
-
texopt->blendu = true;
|
923
|
-
texopt->blendv = true;
|
924
|
-
texopt->sharpness = static_cast<real_t>(1.0);
|
925
|
-
texopt->brightness = static_cast<real_t>(0.0);
|
926
|
-
texopt->contrast = static_cast<real_t>(1.0);
|
927
|
-
texopt->origin_offset[0] = static_cast<real_t>(0.0);
|
928
|
-
texopt->origin_offset[1] = static_cast<real_t>(0.0);
|
929
|
-
texopt->origin_offset[2] = static_cast<real_t>(0.0);
|
930
|
-
texopt->scale[0] = static_cast<real_t>(1.0);
|
931
|
-
texopt->scale[1] = static_cast<real_t>(1.0);
|
932
|
-
texopt->scale[2] = static_cast<real_t>(1.0);
|
933
|
-
texopt->turbulence[0] = static_cast<real_t>(0.0);
|
934
|
-
texopt->turbulence[1] = static_cast<real_t>(0.0);
|
935
|
-
texopt->turbulence[2] = static_cast<real_t>(0.0);
|
936
|
-
texopt->type = TEXTURE_TYPE_NONE;
|
937
|
-
|
938
912
|
const char *token = linebuf; // Assume line ends with NULL
|
939
913
|
|
940
914
|
while (!IS_NEW_LINE((*token))) {
|
@@ -1011,7 +985,46 @@ bool ParseTextureNameAndOption(std::string *texname,
|
|
1011
985
|
}
|
1012
986
|
}
|
1013
987
|
|
988
|
+
static void InitTexOpt(texture_option_t *texopt, const bool is_bump) {
|
989
|
+
if (is_bump) {
|
990
|
+
texopt->imfchan = 'l';
|
991
|
+
} else {
|
992
|
+
texopt->imfchan = 'm';
|
993
|
+
}
|
994
|
+
texopt->bump_multiplier = static_cast<real_t>(1.0);
|
995
|
+
texopt->clamp = false;
|
996
|
+
texopt->blendu = true;
|
997
|
+
texopt->blendv = true;
|
998
|
+
texopt->sharpness = static_cast<real_t>(1.0);
|
999
|
+
texopt->brightness = static_cast<real_t>(0.0);
|
1000
|
+
texopt->contrast = static_cast<real_t>(1.0);
|
1001
|
+
texopt->origin_offset[0] = static_cast<real_t>(0.0);
|
1002
|
+
texopt->origin_offset[1] = static_cast<real_t>(0.0);
|
1003
|
+
texopt->origin_offset[2] = static_cast<real_t>(0.0);
|
1004
|
+
texopt->scale[0] = static_cast<real_t>(1.0);
|
1005
|
+
texopt->scale[1] = static_cast<real_t>(1.0);
|
1006
|
+
texopt->scale[2] = static_cast<real_t>(1.0);
|
1007
|
+
texopt->turbulence[0] = static_cast<real_t>(0.0);
|
1008
|
+
texopt->turbulence[1] = static_cast<real_t>(0.0);
|
1009
|
+
texopt->turbulence[2] = static_cast<real_t>(0.0);
|
1010
|
+
texopt->type = TEXTURE_TYPE_NONE;
|
1011
|
+
}
|
1012
|
+
|
1014
1013
|
static void InitMaterial(material_t *material) {
|
1014
|
+
InitTexOpt(&material->ambient_texopt, /* is_bump */ false);
|
1015
|
+
InitTexOpt(&material->diffuse_texopt, /* is_bump */ false);
|
1016
|
+
InitTexOpt(&material->specular_texopt, /* is_bump */ false);
|
1017
|
+
InitTexOpt(&material->specular_highlight_texopt, /* is_bump */ false);
|
1018
|
+
InitTexOpt(&material->bump_texopt, /* is_bump */ true);
|
1019
|
+
InitTexOpt(&material->displacement_texopt, /* is_bump */ false);
|
1020
|
+
InitTexOpt(&material->alpha_texopt, /* is_bump */ false);
|
1021
|
+
InitTexOpt(&material->reflection_texopt, /* is_bump */ false);
|
1022
|
+
InitTexOpt(&material->roughness_texopt, /* is_bump */ false);
|
1023
|
+
InitTexOpt(&material->metallic_texopt, /* is_bump */ false);
|
1024
|
+
InitTexOpt(&material->sheen_texopt, /* is_bump */ false);
|
1025
|
+
InitTexOpt(&material->emissive_texopt, /* is_bump */ false);
|
1026
|
+
InitTexOpt(&material->normal_texopt,
|
1027
|
+
/* is_bump */ false); // @fixme { is_bump will be true? }
|
1015
1028
|
material->name = "";
|
1016
1029
|
material->ambient_texname = "";
|
1017
1030
|
material->diffuse_texname = "";
|
@@ -1342,7 +1355,7 @@ void LoadMtl(std::map<std::string, int> *material_map,
|
|
1342
1355
|
std::string linebuf;
|
1343
1356
|
while (inStream->peek() != -1) {
|
1344
1357
|
safeGetline(*inStream, linebuf);
|
1345
|
-
|
1358
|
+
line_no++;
|
1346
1359
|
|
1347
1360
|
// Trim trailing whitespace.
|
1348
1361
|
if (linebuf.size() > 0) {
|
@@ -1482,9 +1495,9 @@ void LoadMtl(std::map<std::string, int> *material_map,
|
|
1482
1495
|
|
1483
1496
|
if (has_tr) {
|
1484
1497
|
warn_ss << "Both `d` and `Tr` parameters defined for \""
|
1485
|
-
<< material.name
|
1486
|
-
<<
|
1487
|
-
<< std::endl;
|
1498
|
+
<< material.name
|
1499
|
+
<< "\". Use the value of `d` for dissolve (line " << line_no
|
1500
|
+
<< " in .mtl.)" << std::endl;
|
1488
1501
|
}
|
1489
1502
|
has_d = true;
|
1490
1503
|
continue;
|
@@ -1494,9 +1507,9 @@ void LoadMtl(std::map<std::string, int> *material_map,
|
|
1494
1507
|
if (has_d) {
|
1495
1508
|
// `d` wins. Ignore `Tr` value.
|
1496
1509
|
warn_ss << "Both `d` and `Tr` parameters defined for \""
|
1497
|
-
<< material.name
|
1498
|
-
<<
|
1499
|
-
<< std::endl;
|
1510
|
+
<< material.name
|
1511
|
+
<< "\". Use the value of `d` for dissolve (line " << line_no
|
1512
|
+
<< " in .mtl.)" << std::endl;
|
1500
1513
|
} else {
|
1501
1514
|
// We invert value of Tr(assume Tr is in range [0, 1])
|
1502
1515
|
// NOTE: Interpretation of Tr is application(exporter) dependent. For
|
@@ -1560,8 +1573,7 @@ void LoadMtl(std::map<std::string, int> *material_map,
|
|
1560
1573
|
if ((0 == strncmp(token, "map_Ka", 6)) && IS_SPACE(token[6])) {
|
1561
1574
|
token += 7;
|
1562
1575
|
ParseTextureNameAndOption(&(material.ambient_texname),
|
1563
|
-
&(material.ambient_texopt), token
|
1564
|
-
/* is_bump */ false);
|
1576
|
+
&(material.ambient_texopt), token);
|
1565
1577
|
continue;
|
1566
1578
|
}
|
1567
1579
|
|
@@ -1569,8 +1581,7 @@ void LoadMtl(std::map<std::string, int> *material_map,
|
|
1569
1581
|
if ((0 == strncmp(token, "map_Kd", 6)) && IS_SPACE(token[6])) {
|
1570
1582
|
token += 7;
|
1571
1583
|
ParseTextureNameAndOption(&(material.diffuse_texname),
|
1572
|
-
&(material.diffuse_texopt), token
|
1573
|
-
/* is_bump */ false);
|
1584
|
+
&(material.diffuse_texopt), token);
|
1574
1585
|
continue;
|
1575
1586
|
}
|
1576
1587
|
|
@@ -1578,8 +1589,7 @@ void LoadMtl(std::map<std::string, int> *material_map,
|
|
1578
1589
|
if ((0 == strncmp(token, "map_Ks", 6)) && IS_SPACE(token[6])) {
|
1579
1590
|
token += 7;
|
1580
1591
|
ParseTextureNameAndOption(&(material.specular_texname),
|
1581
|
-
&(material.specular_texopt), token
|
1582
|
-
/* is_bump */ false);
|
1592
|
+
&(material.specular_texopt), token);
|
1583
1593
|
continue;
|
1584
1594
|
}
|
1585
1595
|
|
@@ -1587,8 +1597,7 @@ void LoadMtl(std::map<std::string, int> *material_map,
|
|
1587
1597
|
if ((0 == strncmp(token, "map_Ns", 6)) && IS_SPACE(token[6])) {
|
1588
1598
|
token += 7;
|
1589
1599
|
ParseTextureNameAndOption(&(material.specular_highlight_texname),
|
1590
|
-
&(material.specular_highlight_texopt), token
|
1591
|
-
/* is_bump */ false);
|
1600
|
+
&(material.specular_highlight_texopt), token);
|
1592
1601
|
continue;
|
1593
1602
|
}
|
1594
1603
|
|
@@ -1596,8 +1605,7 @@ void LoadMtl(std::map<std::string, int> *material_map,
|
|
1596
1605
|
if ((0 == strncmp(token, "map_bump", 8)) && IS_SPACE(token[8])) {
|
1597
1606
|
token += 9;
|
1598
1607
|
ParseTextureNameAndOption(&(material.bump_texname),
|
1599
|
-
&(material.bump_texopt), token
|
1600
|
-
/* is_bump */ true);
|
1608
|
+
&(material.bump_texopt), token);
|
1601
1609
|
continue;
|
1602
1610
|
}
|
1603
1611
|
|
@@ -1605,8 +1613,7 @@ void LoadMtl(std::map<std::string, int> *material_map,
|
|
1605
1613
|
if ((0 == strncmp(token, "map_Bump", 8)) && IS_SPACE(token[8])) {
|
1606
1614
|
token += 9;
|
1607
1615
|
ParseTextureNameAndOption(&(material.bump_texname),
|
1608
|
-
&(material.bump_texopt), token
|
1609
|
-
/* is_bump */ true);
|
1616
|
+
&(material.bump_texopt), token);
|
1610
1617
|
continue;
|
1611
1618
|
}
|
1612
1619
|
|
@@ -1614,8 +1621,7 @@ void LoadMtl(std::map<std::string, int> *material_map,
|
|
1614
1621
|
if ((0 == strncmp(token, "bump", 4)) && IS_SPACE(token[4])) {
|
1615
1622
|
token += 5;
|
1616
1623
|
ParseTextureNameAndOption(&(material.bump_texname),
|
1617
|
-
&(material.bump_texopt), token
|
1618
|
-
/* is_bump */ true);
|
1624
|
+
&(material.bump_texopt), token);
|
1619
1625
|
continue;
|
1620
1626
|
}
|
1621
1627
|
|
@@ -1624,8 +1630,7 @@ void LoadMtl(std::map<std::string, int> *material_map,
|
|
1624
1630
|
token += 6;
|
1625
1631
|
material.alpha_texname = token;
|
1626
1632
|
ParseTextureNameAndOption(&(material.alpha_texname),
|
1627
|
-
&(material.alpha_texopt), token
|
1628
|
-
/* is_bump */ false);
|
1633
|
+
&(material.alpha_texopt), token);
|
1629
1634
|
continue;
|
1630
1635
|
}
|
1631
1636
|
|
@@ -1633,8 +1638,7 @@ void LoadMtl(std::map<std::string, int> *material_map,
|
|
1633
1638
|
if ((0 == strncmp(token, "disp", 4)) && IS_SPACE(token[4])) {
|
1634
1639
|
token += 5;
|
1635
1640
|
ParseTextureNameAndOption(&(material.displacement_texname),
|
1636
|
-
&(material.displacement_texopt), token
|
1637
|
-
/* is_bump */ false);
|
1641
|
+
&(material.displacement_texopt), token);
|
1638
1642
|
continue;
|
1639
1643
|
}
|
1640
1644
|
|
@@ -1642,8 +1646,7 @@ void LoadMtl(std::map<std::string, int> *material_map,
|
|
1642
1646
|
if ((0 == strncmp(token, "refl", 4)) && IS_SPACE(token[4])) {
|
1643
1647
|
token += 5;
|
1644
1648
|
ParseTextureNameAndOption(&(material.reflection_texname),
|
1645
|
-
&(material.reflection_texopt), token
|
1646
|
-
/* is_bump */ false);
|
1649
|
+
&(material.reflection_texopt), token);
|
1647
1650
|
continue;
|
1648
1651
|
}
|
1649
1652
|
|
@@ -1651,8 +1654,7 @@ void LoadMtl(std::map<std::string, int> *material_map,
|
|
1651
1654
|
if ((0 == strncmp(token, "map_Pr", 6)) && IS_SPACE(token[6])) {
|
1652
1655
|
token += 7;
|
1653
1656
|
ParseTextureNameAndOption(&(material.roughness_texname),
|
1654
|
-
&(material.roughness_texopt), token
|
1655
|
-
/* is_bump */ false);
|
1657
|
+
&(material.roughness_texopt), token);
|
1656
1658
|
continue;
|
1657
1659
|
}
|
1658
1660
|
|
@@ -1660,8 +1662,7 @@ void LoadMtl(std::map<std::string, int> *material_map,
|
|
1660
1662
|
if ((0 == strncmp(token, "map_Pm", 6)) && IS_SPACE(token[6])) {
|
1661
1663
|
token += 7;
|
1662
1664
|
ParseTextureNameAndOption(&(material.metallic_texname),
|
1663
|
-
&(material.metallic_texopt), token
|
1664
|
-
/* is_bump */ false);
|
1665
|
+
&(material.metallic_texopt), token);
|
1665
1666
|
continue;
|
1666
1667
|
}
|
1667
1668
|
|
@@ -1669,8 +1670,7 @@ void LoadMtl(std::map<std::string, int> *material_map,
|
|
1669
1670
|
if ((0 == strncmp(token, "map_Ps", 6)) && IS_SPACE(token[6])) {
|
1670
1671
|
token += 7;
|
1671
1672
|
ParseTextureNameAndOption(&(material.sheen_texname),
|
1672
|
-
&(material.sheen_texopt), token
|
1673
|
-
/* is_bump */ false);
|
1673
|
+
&(material.sheen_texopt), token);
|
1674
1674
|
continue;
|
1675
1675
|
}
|
1676
1676
|
|
@@ -1678,17 +1678,15 @@ void LoadMtl(std::map<std::string, int> *material_map,
|
|
1678
1678
|
if ((0 == strncmp(token, "map_Ke", 6)) && IS_SPACE(token[6])) {
|
1679
1679
|
token += 7;
|
1680
1680
|
ParseTextureNameAndOption(&(material.emissive_texname),
|
1681
|
-
&(material.emissive_texopt), token
|
1682
|
-
/* is_bump */ false);
|
1681
|
+
&(material.emissive_texopt), token);
|
1683
1682
|
continue;
|
1684
1683
|
}
|
1685
1684
|
|
1686
1685
|
// PBR: normal map texture
|
1687
1686
|
if ((0 == strncmp(token, "norm", 4)) && IS_SPACE(token[4])) {
|
1688
1687
|
token += 5;
|
1689
|
-
ParseTextureNameAndOption(
|
1690
|
-
|
1691
|
-
/* is_bump */ false); // @fixme { is_bump will be true? }
|
1688
|
+
ParseTextureNameAndOption(&(material.normal_texname),
|
1689
|
+
&(material.normal_texopt), token);
|
1692
1690
|
continue;
|
1693
1691
|
}
|
1694
1692
|
|
@@ -1947,7 +1945,8 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
|
|
1947
1945
|
static_cast<int>(vt.size() / 2), &vi)) {
|
1948
1946
|
if (err) {
|
1949
1947
|
std::stringstream ss;
|
1950
|
-
ss <<
|
1948
|
+
ss << "Failed parse `f' line(e.g. zero value for face index. line "
|
1949
|
+
<< line_num << ".)\n";
|
1951
1950
|
(*err) += ss.str();
|
1952
1951
|
}
|
1953
1952
|
return false;
|
@@ -2009,7 +2008,8 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
|
|
2009
2008
|
if (warn) {
|
2010
2009
|
std::stringstream ss;
|
2011
2010
|
ss << "Looks like empty filename for mtllib. Use default "
|
2012
|
-
|
2011
|
+
"material (line "
|
2012
|
+
<< line_num << ".)\n";
|
2013
2013
|
|
2014
2014
|
(*warn) += ss.str();
|
2015
2015
|
}
|
@@ -2218,21 +2218,24 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
|
|
2218
2218
|
if (greatest_v_idx >= static_cast<int>(v.size() / 3)) {
|
2219
2219
|
if (warn) {
|
2220
2220
|
std::stringstream ss;
|
2221
|
-
ss << "Vertex indices out of bounds (line " << line_num << ".)\n"
|
2221
|
+
ss << "Vertex indices out of bounds (line " << line_num << ".)\n"
|
2222
|
+
<< std::endl;
|
2222
2223
|
(*warn) += ss.str();
|
2223
2224
|
}
|
2224
2225
|
}
|
2225
2226
|
if (greatest_vn_idx >= static_cast<int>(vn.size() / 3)) {
|
2226
2227
|
if (warn) {
|
2227
2228
|
std::stringstream ss;
|
2228
|
-
ss << "Vertex normal indices out of bounds (line " << line_num << ".)\n"
|
2229
|
+
ss << "Vertex normal indices out of bounds (line " << line_num << ".)\n"
|
2230
|
+
<< std::endl;
|
2229
2231
|
(*warn) += ss.str();
|
2230
2232
|
}
|
2231
2233
|
}
|
2232
2234
|
if (greatest_vt_idx >= static_cast<int>(vt.size() / 2)) {
|
2233
2235
|
if (warn) {
|
2234
2236
|
std::stringstream ss;
|
2235
|
-
ss << "Vertex texcoord indices out of bounds (line " << line_num << ".)\n"
|
2237
|
+
ss << "Vertex texcoord indices out of bounds (line " << line_num << ".)\n"
|
2238
|
+
<< std::endl;
|
2236
2239
|
(*warn) += ss.str();
|
2237
2240
|
}
|
2238
2241
|
}
|
data/lib/tiny_obj/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tiny_obj
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Colin MacKenzie IV
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|