Skip to content

Commit 44bff46

Browse files
committed
Initial support of reflection map(refl).
1 parent 47989b5 commit 44bff46

4 files changed

Lines changed: 90 additions & 0 deletions

File tree

‎models/refl.mtl‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
newmtl white
2+
Ka 0 0 0
3+
Kd 1 1 1
4+
Ks 0 0 0
5+
refl reflection.tga
6+
7+
newmtl red
8+
Ka 0 0 0
9+
Kd 1 0 0
10+
Ks 0 0 0
11+
12+
newmtl green
13+
Ka 0 0 0
14+
Kd 0 1 0
15+
Ks 0 0 0
16+
17+
newmtl blue
18+
Ka 0 0 0
19+
Kd 0 0 1
20+
Ks 0 0 0
21+
22+
newmtl light
23+
Ka 20 20 20
24+
Kd 1 1 1
25+
Ks 0 0 0

‎models/refl.obj‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Test for `refl` material parameter
2+
mtllib refl.mtl
3+
4+
v 0.000000 2.000000 2.000000
5+
v 0.000000 0.000000 2.000000
6+
v 2.000000 0.000000 2.000000
7+
v 2.000000 2.000000 2.000000
8+
v 0.000000 2.000000 0.000000
9+
v 0.000000 0.000000 0.000000
10+
v 2.000000 0.000000 0.000000
11+
v 2.000000 2.000000 0.000000
12+
# 8 vertices
13+
14+
g front cube
15+
usemtl white
16+
f 1 2 3 4
17+
g back cube
18+
# expects white material
19+
f 8 7 6 5
20+
g right cube
21+
usemtl red
22+
f 4 3 7 8
23+
g top cube
24+
usemtl white
25+
f 5 1 4 8
26+
g left cube
27+
usemtl green
28+
f 5 6 2 1
29+
g bottom cube
30+
usemtl white
31+
f 2 6 7 3
32+
# 6 elements

‎tests/tester.cc‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ static void PrintInfo(const tinyobj::attrib_t &attrib, const std::vector<tinyobj
145145
printf(" material.map_bump = %s\n", materials[i].bump_texname.c_str());
146146
printf(" material.map_d = %s\n", materials[i].alpha_texname.c_str());
147147
printf(" material.disp = %s\n", materials[i].displacement_texname.c_str());
148+
printf(" material.refl = %s\n", materials[i].reflection_texname.c_str());
148149
std::map<std::string, std::string>::const_iterator it(materials[i].unknown_parameter.begin());
149150
std::map<std::string, std::string>::const_iterator itEnd(materials[i].unknown_parameter.end());
150151

@@ -564,6 +565,26 @@ TEST_CASE("tr_and_d", "[Issue43]") {
564565
REQUIRE(0.75 == Approx(materials[1].dissolve));
565566
}
566567

568+
TEST_CASE("refl", "[refl]") {
569+
tinyobj::attrib_t attrib;
570+
std::vector<tinyobj::shape_t> shapes;
571+
std::vector<tinyobj::material_t> materials;
572+
573+
std::string err;
574+
bool ret = tinyobj::LoadObj(&attrib, &shapes, &materials, &err, "../models/refl.obj", gMtlBasePath);
575+
576+
if (!err.empty()) {
577+
std::cerr << err << std::endl;
578+
}
579+
580+
PrintInfo(attrib, shapes, materials);
581+
582+
REQUIRE(true == ret);
583+
REQUIRE(5 == materials.size());
584+
585+
REQUIRE(materials[0].reflection_texname.compare("reflection.tga") == 0);
586+
}
587+
567588
#if 0
568589
int
569590
main(

‎tiny_obj_loader.h‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ typedef struct {
156156
std::string bump_texname; // map_bump, bump
157157
std::string displacement_texname; // disp
158158
std::string alpha_texname; // map_d
159+
std::string reflection_texname; // refl
159160

160161
texture_option_t ambient_texopt;
161162
texture_option_t diffuse_texopt;
@@ -164,6 +165,7 @@ typedef struct {
164165
texture_option_t bump_texopt;
165166
texture_option_t displacement_texopt;
166167
texture_option_t alpha_texopt;
168+
texture_option_t reflection_texopt;
167169

168170
// PBR extension
169171
// http://exocortex.com/blog/extending_wavefront_mtl_to_support_pbr
@@ -859,6 +861,7 @@ static void InitMaterial(material_t *material) {
859861
material->specular_highlight_texname = "";
860862
material->bump_texname = "";
861863
material->displacement_texname = "";
864+
material->reflection_texname = "";
862865
material->alpha_texname = "";
863866
for (int i = 0; i < 3; i++) {
864867
material->ambient[i] = 0.f;
@@ -1265,6 +1268,15 @@ void LoadMtl(std::map<std::string, int> *material_map,
12651268
continue;
12661269
}
12671270

1271+
// reflection map
1272+
if ((0 == strncmp(token, "refl", 4)) && IS_SPACE(token[4])) {
1273+
token += 5;
1274+
ParseTextureNameAndOption(&(material.reflection_texname),
1275+
&(material.reflection_texopt), token,
1276+
/* is_bump */ false);
1277+
continue;
1278+
}
1279+
12681280
// PBR: roughness texture
12691281
if ((0 == strncmp(token, "map_Pr", 6)) && IS_SPACE(token[6])) {
12701282
token += 7;

0 commit comments

Comments
 (0)