@@ -110,15 +110,14 @@ namespace gz::sim::plugins
110
110
111
111
float *EARTHSKYCOLOR[3 ] = {&EARTHNIGHT[0 ], &EARTHDUSKDAWN[0 ], &EARTHNOON[0 ]};
112
112
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 };
116
116
117
- float *MARSSKYCOLOR[3 ] = {&MARSNIGHT[0 ], &MARSDUSKDAWN[0 ], &MARSNOON[0 ]};
117
+ float *MARSSKYCOLOR[3 ] = {&MARSNIGHT[0 ], &MARSDUSKDAWN[0 ], &MARSNOON[0 ]};
118
118
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
122
121
};
123
122
}
124
123
@@ -213,11 +212,54 @@ void gz::sim::plugins::DayLightManager::Setup(gz::sim::EntityComponentManager &_
213
212
std::string sunRemoveService = " /world/" + this ->_dataPtr ->_worldName + " /remove" ;
214
213
this ->_dataPtr ->_node .Request (sunRemoveService, sunRemoveEntity, this ->_dataPtr ->_gzMsgsTimeout , sunRemoveRes, sunRemoveResult);
215
214
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
+
216
258
// Insert sun_sphere model
217
259
gz::msgs::EntityFactory sunSphereSpawnEntity;
218
260
gz::msgs::Boolean sunSphereSpawnRes;
219
261
bool sunSpawnResult;
220
- sunSphereSpawnEntity.set_sdf_filename ( " models/sun_sphere/model.sdf " );
262
+ sunSphereSpawnEntity.set_sdf (sunSDF. ToString () );
221
263
sunSphereSpawnEntity.set_name (this ->_dataPtr ->_sunModelName );
222
264
std::string sunSphereSpawnService = " /world/" + this ->_dataPtr ->_worldName + " /create" ;
223
265
this ->_dataPtr ->_node .Request (sunSphereSpawnService, sunSphereSpawnEntity, this ->_dataPtr ->_gzMsgsTimeout , sunSphereSpawnRes, sunSpawnResult);
@@ -449,7 +491,7 @@ void gz::sim::plugins::DayLightManager::SetY(int _y_bias)
449
491
this ->_y_bias = _y_bias;
450
492
}
451
493
452
- void gz::sim::plugins::DayLightManager::BgColor (bool _checked )
494
+ void gz::sim::plugins::DayLightManager::BgColor (bool _checked)
453
495
{
454
496
this ->_bgSet = _checked;
455
497
}
@@ -507,15 +549,15 @@ void gz::sim::plugins::DayLightManager::PerformRenderingOperations()
507
549
if (nullptr == this ->scene )
508
550
return ;
509
551
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 });
515
558
516
559
this ->_dataPtr ->_updateSky = false ;
517
560
}
518
-
519
561
}
520
562
521
563
// ///////////////////////////////////////////////
0 commit comments