Skip to content

Commit 08ad26c

Browse files
jchaudhary21jasmeet0915
authored andcommitted
Converted sun_sphere model.sdf file into raw string in DayLightManager.cc file (space-ros#46)
1 parent 25423c0 commit 08ad26c

File tree

1 file changed

+57
-15
lines changed

1 file changed

+57
-15
lines changed

custom_gz_plugins/src/DayLightManager/DayLightManager.cc

Lines changed: 57 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,14 @@ namespace gz::sim::plugins
110110

111111
float *EARTHSKYCOLOR[3] = {&EARTHNIGHT[0], &EARTHDUSKDAWN[0], &EARTHNOON[0]};
112112

113-
float MARSNIGHT[4] = {0.02, 0.02, 0.05, 1.0};
114-
float MARSNOON[4] = {1, 0.412 ,0.05, 1.0};
115-
float MARSDUSKDAWN[4] = {0.85, 0.45, 0.30, 1.0};
113+
float MARSNIGHT[4] = {0.02, 0.02, 0.05, 1.0};
114+
float MARSNOON[4] = {1, 0.412, 0.05, 1.0};
115+
float MARSDUSKDAWN[4] = {0.85, 0.45, 0.30, 1.0};
116116

117-
float *MARSSKYCOLOR[3] = {&MARSNIGHT[0], &MARSDUSKDAWN[0], &MARSNOON[0]};
117+
float *MARSSKYCOLOR[3] = {&MARSNIGHT[0], &MARSDUSKDAWN[0], &MARSNOON[0]};
118118

119-
float NIGHTTHRES = -0.3;
120-
float DUSKDAWNTHRES = 0.15; // after this point there will be a major transition in sky color ; Dusk -> Noon && Noon -< Dawn
121-
119+
float NIGHTTHRES = -0.3;
120+
float DUSKDAWNTHRES = 0.15; // after this point there will be a major transition in sky color ; Dusk -> Noon && Noon -< Dawn
122121
};
123122
}
124123

@@ -213,11 +212,54 @@ void gz::sim::plugins::DayLightManager::Setup(gz::sim::EntityComponentManager &_
213212
std::string sunRemoveService = "/world/" + this->_dataPtr->_worldName + "/remove";
214213
this->_dataPtr->_node.Request(sunRemoveService, sunRemoveEntity, this->_dataPtr->_gzMsgsTimeout, sunRemoveRes, sunRemoveResult);
215214

215+
// sun sphere sdf file
216+
sdf::SDF sunSDF;
217+
sunSDF.SetFromString(
218+
R"(
219+
<?xml version='1.0'?>
220+
<sdf version="1.5">
221+
<model name="sun">
222+
<static>true</static>
223+
<pose>0 0 0 0 0 0</pose>
224+
<link name="link">
225+
<visual name="visual">
226+
<cast_shadows>false</cast_shadows>
227+
<geometry>
228+
<sphere>
229+
<radius>2.0</radius>
230+
</sphere>
231+
</geometry>
232+
<material>
233+
<lighting>1</lighting>
234+
<ambient>1 1 0.7 1</ambient>
235+
<diffuse>1 1 0.7 1</diffuse>
236+
<specular>1 1 1 1</specular>
237+
<emissive>1 1 0.5 1</emissive>
238+
</material>
239+
</visual>
240+
<light type="directional" name="directional_light">
241+
<cast_shadows>true</cast_shadows>
242+
<pose>0 0 10 0 0 0</pose>
243+
<diffuse>1 1 1 1</diffuse>
244+
<specular>1 1 1 1</specular>
245+
<attenuation>
246+
<range>100</range>
247+
<constant>0.9</constant>
248+
<linear>0.01</linear>
249+
<quadratic>0.001</quadratic>
250+
</attenuation>
251+
<direction>0 0 -1</direction>
252+
</light>
253+
</link>
254+
</model>
255+
</sdf>
256+
)");
257+
216258
// Insert sun_sphere model
217259
gz::msgs::EntityFactory sunSphereSpawnEntity;
218260
gz::msgs::Boolean sunSphereSpawnRes;
219261
bool sunSpawnResult;
220-
sunSphereSpawnEntity.set_sdf_filename("models/sun_sphere/model.sdf");
262+
sunSphereSpawnEntity.set_sdf(sunSDF.ToString());
221263
sunSphereSpawnEntity.set_name(this->_dataPtr->_sunModelName);
222264
std::string sunSphereSpawnService = "/world/" + this->_dataPtr->_worldName + "/create";
223265
this->_dataPtr->_node.Request(sunSphereSpawnService, sunSphereSpawnEntity, this->_dataPtr->_gzMsgsTimeout, sunSphereSpawnRes, sunSpawnResult);
@@ -449,7 +491,7 @@ void gz::sim::plugins::DayLightManager::SetY(int _y_bias)
449491
this->_y_bias = _y_bias;
450492
}
451493

452-
void gz::sim::plugins::DayLightManager::BgColor(bool _checked )
494+
void gz::sim::plugins::DayLightManager::BgColor(bool _checked)
453495
{
454496
this->_bgSet = _checked;
455497
}
@@ -507,15 +549,15 @@ void gz::sim::plugins::DayLightManager::PerformRenderingOperations()
507549
if (nullptr == this->scene)
508550
return;
509551

510-
if (_bgSet){
511-
this->scene->SetBackgroundColor({ this->R_next,
512-
this->G_next,
513-
this->B_next,
514-
1.0});
552+
if (_bgSet)
553+
{
554+
this->scene->SetBackgroundColor({this->R_next,
555+
this->G_next,
556+
this->B_next,
557+
1.0});
515558

516559
this->_dataPtr->_updateSky = false;
517560
}
518-
519561
}
520562

521563
/////////////////////////////////////////////////

0 commit comments

Comments
 (0)