Skip to content

Commit d719838

Browse files
iche033Nate Koenig
and
Nate Koenig
authored
Add lightmap demo (#471)
Signed-off-by: Ian Chen <[email protected]> Signed-off-by: Nate Koenig <[email protected]> Co-authored-by: Nate Koenig <[email protected]>
1 parent 55ddac7 commit d719838

File tree

4 files changed

+122
-0
lines changed

4 files changed

+122
-0
lines changed

examples/worlds/lightmap.sdf

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?xml version="1.0" ?>
2+
<!--
3+
4+
A world demonstrating an indoor environment model that uses a lightmap.
5+
There are no dynamic lights or shadows in the scene.
6+
7+
-->
8+
9+
<sdf version="1.7">
10+
<world name="lightmap">
11+
<physics name="1ms" type="ignored">
12+
<max_step_size>0.001</max_step_size>
13+
<real_time_factor>1.0</real_time_factor>
14+
</physics>
15+
<scene>
16+
<ambient>1.0 1.0 1.0</ambient>
17+
<background>0.8 0.8 0.8</background>
18+
<grid>false</grid>
19+
</scene>
20+
21+
<gui fullscreen="0">
22+
23+
<!-- 3D scene -->
24+
<plugin filename="GzScene3D" name="3D View">
25+
<ignition-gui>
26+
<title>3D View</title>
27+
<property type="bool" key="showTitleBar">false</property>
28+
<property type="string" key="state">docked</property>
29+
</ignition-gui>
30+
31+
<engine>ogre2</engine>
32+
<scene>scene</scene>
33+
<ambient_light>1.0 1.0 1.0</ambient_light>
34+
<background_color>0.8 0.8 0.8</background_color>
35+
<camera_pose>-5.5 -2 0.5 0 0.0 0</camera_pose>
36+
</plugin>
37+
38+
<!-- World control -->
39+
<plugin filename="WorldControl" name="World control">
40+
<ignition-gui>
41+
<title>World control</title>
42+
<property type="bool" key="showTitleBar">false</property>
43+
<property type="bool" key="resizable">false</property>
44+
<property type="double" key="height">72</property>
45+
<property type="double" key="width">121</property>
46+
<property type="double" key="z">1</property>
47+
48+
<property type="string" key="state">floating</property>
49+
<anchors target="3D View">
50+
<line own="left" target="left"/>
51+
<line own="bottom" target="bottom"/>
52+
</anchors>
53+
</ignition-gui>
54+
55+
<play_pause>true</play_pause>
56+
<step>true</step>
57+
<start_paused>true</start_paused>
58+
59+
</plugin>
60+
61+
<!-- World statistics -->
62+
<plugin filename="WorldStats" name="World stats">
63+
<ignition-gui>
64+
<title>World stats</title>
65+
<property type="bool" key="showTitleBar">false</property>
66+
<property type="bool" key="resizable">false</property>
67+
<property type="double" key="height">110</property>
68+
<property type="double" key="width">290</property>
69+
<property type="double" key="z">1</property>
70+
71+
<property type="string" key="state">floating</property>
72+
<anchors target="3D View">
73+
<line own="right" target="right"/>
74+
<line own="bottom" target="bottom"/>
75+
</anchors>
76+
</ignition-gui>
77+
78+
<sim_time>true</sim_time>
79+
<real_time>true</real_time>
80+
<real_time_factor>true</real_time_factor>
81+
<iterations>true</iterations>
82+
83+
</plugin>
84+
</gui>
85+
86+
<include>
87+
<static>true</static>
88+
<name>Indoor Lightmap</name>
89+
<pose>0 0 0 0 0 0</pose>
90+
<uri>https://fuel.ignitionrobotics.org/1.0/OpenRobotics/models/Indoor Lightmap</uri>
91+
</include>
92+
93+
</world>
94+
</sdf>

src/Conversions.cc

+5
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,9 @@ msgs::Material ignition::gazebo::convert(const sdf::Material &_in)
316316
asFullPath(workflow->EnvironmentMap(), _in.FilePath()));
317317
pbrMsg->set_emissive_map(workflow->EmissiveMap().empty() ? "" :
318318
asFullPath(workflow->EmissiveMap(), _in.FilePath()));
319+
pbrMsg->set_light_map(workflow->LightMap().empty() ? "" :
320+
asFullPath(workflow->LightMap(), _in.FilePath()));
321+
pbrMsg->set_light_map_texcoord_set(workflow->LightMapTexCoordSet());
319322
}
320323
}
321324
return out;
@@ -363,6 +366,8 @@ sdf::Material ignition::gazebo::convert(const msgs::Material &_in)
363366
workflow.SetEnvironmentMap(pbrMsg.environment_map());
364367
workflow.SetAmbientOcclusionMap(pbrMsg.ambient_occlusion_map());
365368
workflow.SetEmissiveMap(pbrMsg.emissive_map());
369+
workflow.SetLightMap(pbrMsg.light_map(), pbrMsg.light_map_texcoord_set());
370+
366371
pbr.SetWorkflow(workflow.Type(), workflow);
367372
out.SetPbrMaterial(pbr);
368373
}

src/Conversions_TEST.cc

+6
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ TEST(Conversions, Material)
222222
workflow.SetEmissiveMap("emissive_map.png");
223223
workflow.SetGlossinessMap("dummy_glossiness_map.png");
224224
workflow.SetSpecularMap("dummy_specular_map.png");
225+
workflow.SetLightMap("light_map.png", 1u);
225226
workflow.SetMetalness(0.3);
226227
workflow.SetRoughness(0.9);
227228
workflow.SetGlossiness(0.1);
@@ -257,6 +258,9 @@ TEST(Conversions, Material)
257258
EXPECT_EQ("ambient_occlusion_map.png", pbrMsg.ambient_occlusion_map());
258259
EXPECT_EQ("dummy_glossiness_map.png", pbrMsg.glossiness_map());
259260
EXPECT_EQ("dummy_specular_map.png", pbrMsg.specular_map());
261+
EXPECT_EQ("light_map.png", pbrMsg.light_map());
262+
EXPECT_EQ(1u, pbrMsg.light_map_texcoord_set());
263+
260264
EXPECT_DOUBLE_EQ(0.3, pbrMsg.metalness());
261265
EXPECT_DOUBLE_EQ(0.9, pbrMsg.roughness());
262266
EXPECT_DOUBLE_EQ(0.1, pbrMsg.glossiness());
@@ -284,6 +288,8 @@ TEST(Conversions, Material)
284288
EXPECT_EQ("ambient_occlusion_map.png", newWorkflow->AmbientOcclusionMap());
285289
EXPECT_EQ("dummy_glossiness_map.png", newWorkflow->GlossinessMap());
286290
EXPECT_EQ("dummy_specular_map.png", newWorkflow->SpecularMap());
291+
EXPECT_EQ("light_map.png", newWorkflow->LightMap());
292+
EXPECT_EQ(1u, newWorkflow->LightMapTexCoordSet());
287293
EXPECT_DOUBLE_EQ(0.3, newWorkflow->Metalness());
288294
EXPECT_DOUBLE_EQ(0.9, newWorkflow->Roughness());
289295
EXPECT_DOUBLE_EQ(0.1, newWorkflow->Glossiness());

src/rendering/SceneManager.cc

+17
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,23 @@ rendering::MaterialPtr SceneManager::LoadMaterial(
538538
else
539539
ignerr << "Unable to find file [" << emissiveMap << "]\n";
540540
}
541+
542+
// light map
543+
std::string lightMap = workflow->LightMap();
544+
if (!lightMap.empty())
545+
{
546+
std::string fullPath = common::findFile(
547+
asFullPath(lightMap, _material.FilePath()));
548+
if (!fullPath.empty())
549+
{
550+
unsigned int uvSet = workflow->LightMapTexCoordSet();
551+
material->SetLightMap(fullPath, uvSet);
552+
}
553+
else
554+
{
555+
ignerr << "Unable to find file [" << lightMap << "]\n";
556+
}
557+
}
541558
}
542559
return material;
543560
}

0 commit comments

Comments
 (0)