Add colorspace extension to texture options. Fixes #184
This commit is contained in:
9
models/colorspace-issue-184.mtl
Normal file
9
models/colorspace-issue-184.mtl
Normal file
@@ -0,0 +1,9 @@
|
||||
newmtl default
|
||||
Ka 0 0 0
|
||||
Kd 0 0 0
|
||||
Ks 0 0 0
|
||||
Kt 0.1 0.2 0.3
|
||||
map_Kd -colorspace sRGB -o 0.1 diffuse.jpg
|
||||
map_Ks -s 0.1 0.2 specular.jpg
|
||||
map_bump -colorspace linear -bm 3 bumpmap.jpg
|
||||
|
||||
7
models/colorspace-issue-184.obj
Normal file
7
models/colorspace-issue-184.obj
Normal file
@@ -0,0 +1,7 @@
|
||||
mtllib colorspace-issue-184.mtl
|
||||
o Test
|
||||
v 1.864151 -1.219172 -5.532511
|
||||
v 0.575869 -0.666304 5.896140
|
||||
v 0.940448 1.000000 -1.971128
|
||||
usemtl default
|
||||
f 1 2 3
|
||||
@@ -825,6 +825,25 @@ TEST_CASE("multiple-group-names", "[group]") {
|
||||
REQUIRE(0 == shapes[1].name.compare("back cube")); // multiple whitespaces are aggregated as single white space.
|
||||
}
|
||||
|
||||
TEST_CASE("colorspace", "[Issue184]") {
|
||||
tinyobj::attrib_t attrib;
|
||||
std::vector<tinyobj::shape_t> shapes;
|
||||
std::vector<tinyobj::material_t> materials;
|
||||
|
||||
std::string err;
|
||||
bool ret = tinyobj::LoadObj(&attrib, &shapes, &materials, &err, "../models/colorspace-issue-184.obj", gMtlBasePath);
|
||||
|
||||
if (!err.empty()) {
|
||||
std::cerr << err << std::endl;
|
||||
}
|
||||
REQUIRE(true == ret);
|
||||
REQUIRE(1 == shapes.size());
|
||||
REQUIRE(1 == materials.size());
|
||||
REQUIRE(0 == materials[0].diffuse_texopt.colorspace.compare("sRGB"));
|
||||
REQUIRE(0 == materials[0].specular_texopt.colorspace.size());
|
||||
REQUIRE(0 == materials[0].bump_texopt.colorspace.compare("linear"));
|
||||
}
|
||||
|
||||
// Fuzzer test.
|
||||
// Just check if it does not crash.
|
||||
// Disable by default since Windows filesystem can't create filename of afl testdata
|
||||
|
||||
@@ -23,6 +23,7 @@ THE SOFTWARE.
|
||||
*/
|
||||
|
||||
//
|
||||
// version 1.2.3 : Added color space extension('-colorspace') to tex opts.
|
||||
// version 1.2.2 : Parse multiple group names.
|
||||
// version 1.2.1 : Added initial support for line('l') primitive(PR #178)
|
||||
// version 1.2.0 : Hardened implementation(#175)
|
||||
@@ -113,6 +114,11 @@ namespace tinyobj {
|
||||
// cube_front | cube_back | # side of the cube is specified
|
||||
// separately
|
||||
// cube_left | cube_right
|
||||
//
|
||||
// TinyObjLoader extension.
|
||||
//
|
||||
// -colorspace SPACE # Color space of the texture. e.g. 'sRGB` or 'linear'
|
||||
//
|
||||
|
||||
#ifdef TINYOBJLOADER_USE_DOUBLE
|
||||
//#pragma message "using double"
|
||||
@@ -147,6 +153,9 @@ typedef struct {
|
||||
bool blendu; // -blendu (default on)
|
||||
bool blendv; // -blendv (default on)
|
||||
real_t bump_multiplier; // -bm (for bump maps only, default 1.0)
|
||||
|
||||
// extension
|
||||
std::string colorspace; // Explicitly specify color space of stored value. Usually `sRGB` or `linear` (default empty).
|
||||
} texture_option_t;
|
||||
|
||||
typedef struct {
|
||||
@@ -950,6 +959,9 @@ static bool ParseTextureNameAndOption(std::string *texname,
|
||||
} else if ((0 == strncmp(token, "-mm", 3)) && IS_SPACE((token[3]))) {
|
||||
token += 4;
|
||||
parseReal2(&(texopt->brightness), &(texopt->contrast), &token, 0.0, 1.0);
|
||||
} else if ((0 == strncmp(token, "-colorspace", 11)) && IS_SPACE((token[11]))) {
|
||||
token += 12;
|
||||
texopt->colorspace = parseString(&token);
|
||||
} else {
|
||||
// Assume texture filename
|
||||
#if 0
|
||||
|
||||
Reference in New Issue
Block a user