Add realtime parameter to visual global.

PiperOrigin-RevId: 478775714
Change-Id: Ic2d178a5c57d298d005215219ce8470392c4651b
This commit is contained in:
Alessio Quaglino
2022-10-04 07:08:21 -07:00
committed by Copybara-Service
parent f85cfb8ed2
commit bc1490b7a8
10 changed files with 29 additions and 3 deletions
+1
View File
@@ -1237,6 +1237,7 @@ mjVisual
float ipd; // inter-pupilary distance for free camera
float linewidth; // line width for wireframe and ray rendering
float glow; // glow coefficient for selected body
float realtime; // initial real-time factor (1: real time)
int offwidth; // width of offscreen buffer
int offheight; // height of offscreen buffer
} global;
+3
View File
@@ -592,6 +592,9 @@ is effectively a miscellaneous subsection.
:at:`glow`: :at-val:`real, "0.3"`
The value of this attribute is added to the emission coefficient of all geoms attached to the selected body. As a
result, the selected body appears to glow.
:at:`realtime`: :at-val:`real, "1"`
This value sets the initial real-time factor of the model, when loaded in `simulate`. 1: real time. Less than 1:
slower than real time. Must be greater than 0.
:at:`offwidth`: :at-val:`int, "640"`
This and the next attribute specify the size in pixels of the off-screen OpenGL rendering buffer. This attribute
specifies the width of the buffer. The size of this buffer can also be adjusted at runtime, but it is usually more
+2
View File
@@ -50,6 +50,8 @@ General
- Added :at:`assetdir` compiler option, which sets the values of both :at:`meshdir` and :at:`texturedir`. Values in
the latter attributes take precedence over :at:`assetdir`.
- Added :at:`realtime` option to :ref:`visual` for starting a simulation at a slower speed.
Python bindings
^^^^^^^^^^^^^^^
+1
View File
@@ -429,6 +429,7 @@ struct mjVisual_ { // visualization options
float elevation; // initial elevation of free camera (degrees)
float linewidth; // line width for wireframe and ray rendering
float glow; // glow coefficient for selected body
float realtime; // initial real-time factor (1: real time)
int offwidth; // width of offscreen buffer
int offheight; // height of offscreen buffer
} global;
+12
View File
@@ -1648,6 +1648,18 @@ void Simulate::loadmodel() {
// clear request
this->loadrequest = 0;
cond_loadrequest.notify_all();
// set real time index
int numclicks = sizeof(this->percentRealTime) / sizeof(this->percentRealTime[0]);
float min_error = 1e6;
float desired = mju_log(100*this->m->vis.global.realtime);
for (int click=0; click<numclicks; click++) {
float error = mju_abs(mju_log(this->percentRealTime[click]) - desired);
if (error < min_error) {
min_error = error;
this->realTimeIndex = click;
}
}
}
+1 -1
View File
@@ -125,7 +125,7 @@ class MJSIMULATEAPI Simulate {
char previous_filename[kMaxFilenameLength] = "";
// time synchronization
int realTimeIndex = 0;
int realTimeIndex;
bool speedChanged = true;
float measuredSlowdown = 1.0;
// logarithmically spaced realtime slow-down coefficients (percent)
+1
View File
@@ -160,6 +160,7 @@ void mj_defaultVisual(mjVisual* vis) {
vis->global.glow = 0.3;
vis->global.offwidth = 640;
vis->global.offheight = 480;
vis->global.realtime = 1.0;
// rendering quality
vis->quality.shadowsize = 4096;
+6 -2
View File
@@ -109,8 +109,8 @@ static const char* MJCF[nMJCF][mjXATTRNUM] = {
{"visual", "*", "0"},
{"<"},
{"global", "?", "8", "fovy", "ipd", "azimuth", "elevation", "linewidth", "glow", "offwidth",
"offheight"},
{"global", "?", "9", "fovy", "ipd", "azimuth", "elevation", "linewidth", "glow", "offwidth",
"offheight", "realtime"},
{"quality", "?", "5", "shadowsize", "offsamples", "numslices", "numstacks",
"numquads"},
{"headlight", "?", "4", "ambient", "diffuse", "specular", "active"},
@@ -2172,6 +2172,10 @@ void mjXReader::Visual(XMLElement* section) {
ReadAttr(elem, "glow", 1, &vis->global.glow, text);
ReadAttrInt(elem, "offwidth", &vis->global.offwidth);
ReadAttrInt(elem, "offheight", &vis->global.offheight);
if (ReadAttr(elem, "realtime", 1, &vis->global.realtime, text))
if (vis->global.realtime<=0) {
throw mjXError(elem, "realtime must be greater than 0");
}
}
// quality sub-element
+1
View File
@@ -868,6 +868,7 @@ void mjXWriter::Visual(XMLElement* root) {
WriteAttr(elem, "elevation", 1, &vis->global.elevation, &visdef.global.elevation);
WriteAttr(elem, "linewidth", 1, &vis->global.linewidth, &visdef.global.linewidth);
WriteAttr(elem, "glow", 1, &vis->global.glow, &visdef.global.glow);
WriteAttr(elem, "realtime", 1, &vis->global.realtime, &visdef.global.realtime);
WriteAttrInt(elem, "offwidth", vis->global.offwidth, visdef.global.offwidth);
WriteAttrInt(elem, "offheight", vis->global.offheight, visdef.global.offheight);
if (!elem->FirstAttribute()) {
+1
View File
@@ -1749,6 +1749,7 @@ public unsafe struct global {
public float elevation;
public float linewidth;
public float glow;
public float realtime;
public int offwidth;
public int offheight;
}