Add metallic and roughness scalar attributes to materials.

Rename `light_radius` -> `light_bulbradius`, make the default value 0.02.

PiperOrigin-RevId: 627032170
Change-Id: I1e01e2eca028c0aefc2e7dc384e8b34abac184aa
This commit is contained in:
Yuval Tassa
2024-04-22 07:37:52 -07:00
committed by Copybara-Service
parent c2d0c5dd1b
commit caf215e342
18 changed files with 170 additions and 45 deletions
+23 -7
View File
@@ -1788,6 +1788,18 @@ properties are grouped together.
instead. Only the first reflective geom in the model is rendered as such. This adds one extra rendering pass through
all geoms, in addition to the extra rendering pass added by each shadow-casting light.
.. _asset-material-metallic:
:at:`metallic`: :at-val:`real, "0"`
This attribute corresponds to uniform metallicity coefficient applied to the entire material. This attribute has no
effect in MuJoCo's native renderer, but it can be useful when rendering scenes with an external renderer.
.. _asset-material-roughness:
:at:`roughness`: :at-val:`real, "1"`
This attribute corresponds to uniform roughness coefficient applied to the entire material. This attribute has no
effect in MuJoCo's native renderer, but it can be useful when rendering scenes with an external renderer.
.. _asset-material-rgba:
:at:`rgba`: :at-val:`real(4), "1 1 1 1"`
@@ -3165,6 +3177,12 @@ the direction specified by the dir attribute. It does not have a full spatial fr
these clipping planes bound the cone or box shadow volume in the light direction. As a result, some shadows
(especially those very close to the light) may be clipped.
.. _body-light-bulbradius:
:at:`radius`: :at-val:`real, "0.02"`
Radius of the light, affects shadow softness. This attribute has no effect in MuJoCo's native renderer, but it can be
useful when rendering scenes with an external renderer.
.. _body-light-active:
:at:`active`: :at-val:`[false, true], "true"`
@@ -3181,12 +3199,6 @@ the direction specified by the dir attribute. It does not have a full spatial fr
:at:`dir`: :at-val:`real(3), "0 0 -1"`
Direction of the light.
.. _body-light-radius:
:at:`radius`: :at-val:`real, "0"`
Radius of the light, affects shadow softness. This attribute has no effect in MuJoCo's native renderer, but it can be
useful when rendering scenes with an external renderer.
.. _body-light-attenuation:
:at:`attenuation`: :at-val:`real(3), "1 0 0"`
@@ -7372,6 +7384,10 @@ if omitted.
.. _default-material-reflectance:
.. _default-material-metallic:
.. _default-material-roughness:
.. _default-material-rgba:
.. _default-material-texrepeat:
@@ -7592,7 +7608,7 @@ if omitted.
.. _default-light-dir:
.. _default-light-radius:
.. _default-light-bulbradius:
.. _default-light-directional:
+6 -4
View File
@@ -213,7 +213,7 @@
| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ |
| | | | :ref:`texuniform<asset-material-texuniform>` | :ref:`emission<asset-material-emission>` | :ref:`specular<asset-material-specular>` | :ref:`shininess<asset-material-shininess>` | |
| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ |
| | | | :ref:`reflectance<asset-material-reflectance>` | :ref:`rgba<asset-material-rgba>` | | | |
| | | | :ref:`reflectance<asset-material-reflectance>` | :ref:`metallic<asset-material-metallic>` | :ref:`roughness<asset-material-roughness>` | :ref:`rgba<asset-material-rgba>` | |
| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ |
+------------------------------------+----+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| mujoco |br| |L| | | .. table:: |
@@ -369,7 +369,7 @@
| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ |
| | | | :ref:`name<body-light-name>` | :ref:`class<body-light-class>` | :ref:`directional<body-light-directional>` | :ref:`castshadow<body-light-castshadow>` | |
| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ |
| | | | :ref:`active<body-light-active>` | :ref:`pos<body-light-pos>` | :ref:`dir<body-light-dir>` | :ref:`radius<body-light-radius>` | |
| | | | :ref:`active<body-light-active>` | :ref:`pos<body-light-pos>` | :ref:`dir<body-light-dir>` | :ref:`bulbradius<body-light-bulbradius>` | |
| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ |
| | | | :ref:`attenuation<body-light-attenuation>` | :ref:`cutoff<body-light-cutoff>` | :ref:`exponent<body-light-exponent>` | :ref:`ambient<body-light-ambient>` | |
| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ |
@@ -1307,7 +1307,9 @@
| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ |
| | | | :ref:`texture<default-material-texture>` | :ref:`emission<default-material-emission>` | :ref:`specular<default-material-specular>` | :ref:`shininess<default-material-shininess>` | |
| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ |
| | | | :ref:`reflectance<default-material-reflectance>` | :ref:`rgba<default-material-rgba>` | :ref:`texrepeat<default-material-texrepeat>` | :ref:`texuniform<default-material-texuniform>` | |
| | | | :ref:`reflectance<default-material-reflectance>` | :ref:`metallic<default-material-metallic>` | :ref:`roughness<default-material-roughness>` | :ref:`rgba<default-material-rgba>` | |
| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ |
| | | | :ref:`texrepeat<default-material-texrepeat>` | :ref:`texuniform<default-material-texuniform>` | | | |
| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ |
+------------------------------------+----+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |_| default |br| |_| |L| | | .. table:: |
@@ -1378,7 +1380,7 @@
| :ref:`light | ? | :class: mjcf-attributes |
| <default-light>` | | |
| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ |
| | | | :ref:`pos<default-light-pos>` | :ref:`dir<default-light-dir>` | :ref:`radius<default-light-radius>` | :ref:`directional<default-light-directional>` | |
| | | | :ref:`pos<default-light-pos>` | :ref:`dir<default-light-dir>` | :ref:`bulbradius<default-light-bulbradius>` | :ref:`directional<default-light-directional>` | |
| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ |
| | | | :ref:`castshadow<default-light-castshadow>` | :ref:`active<default-light-active>` | :ref:`attenuation<default-light-attenuation>` | :ref:`cutoff<default-light-cutoff>` | |
| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ |
+7 -3
View File
@@ -9,8 +9,12 @@ General
^^^^^^^
1. Added ``mjModel.mesh_scale``: the scaling applied to asset vertices, as specified in the
:ref:`scale<asset-mesh-scale>` attribute.
2. Added the :ref:`light/radius<body-light-radius>` attribute and corresponding ``mjModel.light_radius`` field. This
value has no effect in MuJoCo's native renderer, but can be usful when rendering scenes with an external renderer.
2. Added visual properties which are ignored by the native renderer, but can be used by external renderers:
- :ref:`light/bulbradius<body-light-bulbradius>` attribute and corresponding ``mjModel.light_bulbradius`` field.
- :ref:`material/metallic<asset-material-metallic>` attribute and corresponding ``mjModel.material_metallic`` field.
- :ref:`material/roughness<asset-material-roughness>` attribute and corresponding ``mjModel.material_roughness``
field.
MJX
^^^
@@ -36,7 +40,7 @@ MJX
Bug fixes
^^^^^^^^^
12. Defaults of lights were not being saved, now fixed.
13. Prevent overwriting of frame names by body names when saving an XML. Introduced in 3.1.4.
13. Prevent overwriting of frame names by body names when saving an XML. Bug introduced in 3.1.4.
14. Fixed bug in Python binding of :ref:`mj_saveModel`: ``buffer`` argument was documented as optional but was actually
not optional.
+7 -1
View File
@@ -1079,10 +1079,10 @@ struct mjModel_ {
int* light_targetbodyid; // id of targeted body; -1: none (nlight x 1)
mjtByte* light_directional; // directional light (nlight x 1)
mjtByte* light_castshadow; // does light cast shadows (nlight x 1)
float* light_bulbradius; // light radius for soft shadows (nlight x 1)
mjtByte* light_active; // is light on (nlight x 1)
mjtNum* light_pos; // position rel. to body frame (nlight x 3)
mjtNum* light_dir; // direction rel. to body frame (nlight x 3)
mjtNum* light_radius; // radius of the light (nlight x 1)
mjtNum* light_poscom0; // global position rel. to sub-com in qpos0 (nlight x 3)
mjtNum* light_pos0; // global position rel. to body in qpos0 (nlight x 3)
mjtNum* light_dir0; // global direction in qpos0 (nlight x 3)
@@ -1219,6 +1219,8 @@ struct mjModel_ {
float* mat_specular; // specular (x white) (nmat x 1)
float* mat_shininess; // shininess coef (nmat x 1)
float* mat_reflectance; // reflectance (0: disable) (nmat x 1)
float* mat_metallic; // metallic coef (nmat x 1)
float* mat_roughness; // roughness coef (nmat x 1)
float* mat_rgba; // rgba (nmat x 4)
// predefined geom pairs for collision detection; has precedence over exclude
@@ -2022,6 +2024,7 @@ struct mjvLight_ { // OpenGL light
mjtByte headlight; // headlight
mjtByte directional; // directional light
mjtByte castshadow; // does light cast shadows
float bulbradius; // bulb radius for soft shadows
};
typedef struct mjvLight_ mjvLight;
struct mjvOption_ { // abstract visualization options
@@ -2236,6 +2239,7 @@ struct mjvSceneState_ {
mjtByte* light_directional;
mjtByte* light_castshadow;
float* light_bulbradius;
mjtByte* light_active;
float* light_attenuation;
float* light_cutoff;
@@ -2303,6 +2307,8 @@ struct mjvSceneState_ {
float* mat_specular;
float* mat_shininess;
float* mat_reflectance;
float* mat_metallic;
float* mat_roughness;
float* mat_rgba;
int* eq_type;
+3 -1
View File
@@ -794,10 +794,10 @@ struct mjModel_ {
int* light_targetbodyid; // id of targeted body; -1: none (nlight x 1)
mjtByte* light_directional; // directional light (nlight x 1)
mjtByte* light_castshadow; // does light cast shadows (nlight x 1)
float* light_bulbradius; // light radius for soft shadows (nlight x 1)
mjtByte* light_active; // is light on (nlight x 1)
mjtNum* light_pos; // position rel. to body frame (nlight x 3)
mjtNum* light_dir; // direction rel. to body frame (nlight x 3)
mjtNum* light_radius; // radius of the light (nlight x 1)
mjtNum* light_poscom0; // global position rel. to sub-com in qpos0 (nlight x 3)
mjtNum* light_pos0; // global position rel. to body in qpos0 (nlight x 3)
mjtNum* light_dir0; // global direction in qpos0 (nlight x 3)
@@ -934,6 +934,8 @@ struct mjModel_ {
float* mat_specular; // specular (x white) (nmat x 1)
float* mat_shininess; // shininess coef (nmat x 1)
float* mat_reflectance; // reflectance (0: disable) (nmat x 1)
float* mat_metallic; // metallic coef (nmat x 1)
float* mat_roughness; // roughness coef (nmat x 1)
float* mat_rgba; // rgba (nmat x 4)
// predefined geom pairs for collision detection; has precedence over exclude
+4
View File
@@ -263,6 +263,7 @@ struct mjvLight_ { // OpenGL light
mjtByte headlight; // headlight
mjtByte directional; // directional light
mjtByte castshadow; // does light cast shadows
float bulbradius; // bulb radius for soft shadows
};
typedef struct mjvLight_ mjvLight;
@@ -493,6 +494,7 @@ struct mjvSceneState_ {
mjtByte* light_directional;
mjtByte* light_castshadow;
float* light_bulbradius;
mjtByte* light_active;
float* light_attenuation;
float* light_cutoff;
@@ -560,6 +562,8 @@ struct mjvSceneState_ {
float* mat_specular;
float* mat_shininess;
float* mat_reflectance;
float* mat_metallic;
float* mat_roughness;
float* mat_rgba;
int* eq_type;
+3 -1
View File
@@ -292,10 +292,10 @@
X ( int, light_targetbodyid, nlight, 1 ) \
XMJV( mjtByte, light_directional, nlight, 1 ) \
XMJV( mjtByte, light_castshadow, nlight, 1 ) \
XMJV( float, light_bulbradius, nlight, 1 ) \
XMJV( mjtByte, light_active, nlight, 1 ) \
X ( mjtNum, light_pos, nlight, 3 ) \
X ( mjtNum, light_dir, nlight, 3 ) \
X ( mjtNum, light_radius, nlight, 1 ) \
X ( mjtNum, light_poscom0, nlight, 3 ) \
X ( mjtNum, light_pos0, nlight, 3 ) \
X ( mjtNum, light_dir0, nlight, 3 ) \
@@ -418,6 +418,8 @@
XMJV( float, mat_specular, nmat, 1 ) \
XMJV( float, mat_shininess, nmat, 1 ) \
XMJV( float, mat_reflectance, nmat, 1 ) \
XMJV( float, mat_metallic, nmat, 1 ) \
XMJV( float, mat_roughness, nmat, 1 ) \
XMJV( float, mat_rgba, nmat, 4 ) \
X ( int, pair_dim, npair, 1 ) \
X ( int, pair_geom1, npair, 1 ) \
+47 -7
View File
@@ -2095,6 +2095,13 @@ STRUCTS: Mapping[str, StructDecl] = dict([
),
doc='does light cast shadows (nlight x 1)',
),
StructFieldDecl(
name='light_bulbradius',
type=PointerType(
inner_type=ValueType(name='float'),
),
doc='light radius for soft shadows (nlight x 1)',
),
StructFieldDecl(
name='light_active',
type=PointerType(
@@ -2116,13 +2123,6 @@ STRUCTS: Mapping[str, StructDecl] = dict([
),
doc='direction rel. to body frame (nlight x 3)',
),
StructFieldDecl(
name='light_radius',
type=PointerType(
inner_type=ValueType(name='mjtNum'),
),
doc='radius of the light (nlight x 1)',
),
StructFieldDecl(
name='light_poscom0',
type=PointerType(
@@ -2977,6 +2977,20 @@ STRUCTS: Mapping[str, StructDecl] = dict([
),
doc='reflectance (0: disable) (nmat x 1)',
),
StructFieldDecl(
name='mat_metallic',
type=PointerType(
inner_type=ValueType(name='float'),
),
doc='metallic coef (nmat x 1)',
),
StructFieldDecl(
name='mat_roughness',
type=PointerType(
inner_type=ValueType(name='float'),
),
doc='roughness coef (nmat x 1)',
),
StructFieldDecl(
name='mat_rgba',
type=PointerType(
@@ -5624,6 +5638,11 @@ STRUCTS: Mapping[str, StructDecl] = dict([
type=ValueType(name='mjtByte'),
doc='does light cast shadows',
),
StructFieldDecl(
name='bulbradius',
type=ValueType(name='float'),
doc='bulb radius for soft shadows',
),
),
)),
('mjvOption',
@@ -6719,6 +6738,13 @@ STRUCTS: Mapping[str, StructDecl] = dict([
),
doc='',
),
StructFieldDecl(
name='light_bulbradius',
type=PointerType(
inner_type=ValueType(name='float'),
),
doc='',
),
StructFieldDecl(
name='light_active',
type=PointerType(
@@ -7146,6 +7172,20 @@ STRUCTS: Mapping[str, StructDecl] = dict([
),
doc='',
),
StructFieldDecl(
name='mat_metallic',
type=PointerType(
inner_type=ValueType(name='float'),
),
doc='',
),
StructFieldDecl(
name='mat_roughness',
type=PointerType(
inner_type=ValueType(name='float'),
),
doc='',
),
StructFieldDecl(
name='mat_rgba',
type=PointerType(
+1
View File
@@ -2226,6 +2226,7 @@ This is useful for example when the MJB is not available as a file on disk.)"));
X(headlight);
X(directional);
X(castshadow);
X(bulbradius);
#undef X
#define X(var) DefinePyArray(mjvLight, #var, &MjvLightWrapper::var)
+1
View File
@@ -2091,6 +2091,7 @@ void mjv_makeLights(const mjModel* m, mjData* d, mjvScene* scn) {
memset(thislight, 0, sizeof(mjvLight));
thislight->directional = m->light_directional[i];
thislight->castshadow = m->light_castshadow[i];
thislight->bulbradius = m->light_bulbradius[i];
if (!thislight->directional) {
f2f(thislight->attenuation, m->light_attenuation+3*i, 3);
thislight->exponent = m->light_exponent[i];
+3 -1
View File
@@ -347,7 +347,6 @@ typedef struct _mjsLight { // light specification
// frame
double pos[3]; // position
double dir[3]; // direction
double radius; // radius
mjtCamLight mode; // tracking mode
mjString targetbody; // target body for targeting
@@ -355,6 +354,7 @@ typedef struct _mjsLight { // light specification
mjtByte active; // is light active
mjtByte directional; // is light directional or spot
mjtByte castshadow; // does light cast shadows
double bulbradius; // bulb radius, for soft shadows
float attenuation[3]; // OpenGL attenuation (quadratic model)
float cutoff; // OpenGL cutoff
float exponent; // OpenGL exponent
@@ -515,6 +515,8 @@ typedef struct _mjsMaterial { // material specification
float specular; // specular
float shininess; // shininess
float reflectance; // reflectance
float metallic; // metallic
float roughness; // roughness
float rgba[4]; // rgba
mjString info; // message appended to compiler errors
} mjsMaterial;
+3
View File
@@ -218,6 +218,7 @@ void mjs_defaultLight(mjsLight& light) {
// intrinsics
light.castshadow = 1;
light.bulbradius = 0.02;
light.active = 1;
light.dir[2] = -1;
light.attenuation[0] = 1;
@@ -305,6 +306,8 @@ void mjs_defaultMaterial(mjsMaterial& material) {
material.specular = 0.5;
material.shininess = 0.5;
material.reflectance = 0;
material.metallic = 1.0;
material.roughness = 1.0;
material.rgba[0] = material.rgba[1] = material.rgba[2] = material.rgba[3] = 1;
}
+3 -1
View File
@@ -2070,7 +2070,7 @@ void mjCModel::CopyTree(mjModel* m) {
m->light_active[lid] = (mjtByte)pl->active;
copyvec(m->light_pos+3*lid, pl->pos, 3);
copyvec(m->light_dir+3*lid, pl->dir, 3);
m->light_radius[lid] = pl->radius;
m->light_bulbradius[lid] = pl->bulbradius;
copyvec(m->light_attenuation+3*lid, pl->attenuation, 3);
m->light_cutoff[lid] = pl->cutoff;
m->light_exponent[lid] = pl->exponent;
@@ -2487,6 +2487,8 @@ void mjCModel::CopyObjects(mjModel* m) {
m->mat_specular[i] = pmat->specular;
m->mat_shininess[i] = pmat->shininess;
m->mat_reflectance[i] = pmat->reflectance;
m->mat_metallic[i] = pmat->metallic;
m->mat_roughness[i] = pmat->roughness;
copyvec(m->mat_rgba+4*i, pmat->rgba, 4);
}
+9 -7
View File
@@ -136,8 +136,8 @@ const char* MJCF[nMJCF][mjXATTRNUM] = {
{"default", "R", "1", "class"},
{"<"},
{"mesh", "?", "1", "scale"},
{"material", "?", "8", "texture", "emission", "specular", "shininess",
"reflectance", "rgba", "texrepeat", "texuniform"},
{"material", "?", "10", "texture", "emission", "specular", "shininess",
"reflectance", "metallic", "roughness", "rgba", "texrepeat", "texuniform"},
{"joint", "?", "22", "type", "group", "pos", "axis", "springdamper",
"limited", "actuatorfrclimited", "solreflimit", "solimplimit",
"solreffriction", "solimpfriction", "stiffness", "range", "actuatorfrcrange",
@@ -153,7 +153,7 @@ const char* MJCF[nMJCF][mjXATTRNUM] = {
{"camera", "?", "16", "fovy", "ipd", "resolution", "pos", "quat", "axisangle", "xyaxes",
"zaxis", "euler", "mode", "focal", "focalpixel", "principal", "principalpixel",
"sensorsize", "user"},
{"light", "?", "13", "pos", "dir", "radius", "directional", "castshadow", "active",
{"light", "?", "13", "pos", "dir", "bulbradius", "directional", "castshadow", "active",
"attenuation", "cutoff", "exponent", "ambient", "diffuse", "specular", "mode"},
{"pair", "?", "7", "condim", "friction", "solref", "solreffriction", "solimp",
"gap", "margin"},
@@ -232,8 +232,8 @@ const char* MJCF[nMJCF][mjXATTRNUM] = {
"fileright", "fileleft", "fileup", "filedown", "filefront", "fileback",
"builtin", "rgb1", "rgb2", "mark", "markrgb", "random", "width", "height",
"hflip", "vflip"},
{"material", "*", "10", "name", "class", "texture", "texrepeat", "texuniform",
"emission", "specular", "shininess", "reflectance", "rgba"},
{"material", "*", "12", "name", "class", "texture", "texrepeat", "texuniform",
"emission", "specular", "shininess", "reflectance", "metallic", "roughness", "rgba"},
{">"},
{"body", "R", "11", "name", "childclass", "pos", "quat", "mocap",
@@ -264,7 +264,7 @@ const char* MJCF[nMJCF][mjXATTRNUM] = {
"axisangle", "xyaxes", "zaxis", "euler", "mode", "target", "focal", "focalpixel",
"principal", "principalpixel", "sensorsize", "user"},
{"light", "*", "16", "name", "class", "directional", "castshadow", "active",
"pos", "dir", "radius", "attenuation", "cutoff", "exponent", "ambient", "diffuse",
"pos", "dir", "bulbradius", "attenuation", "cutoff", "exponent", "ambient", "diffuse",
"specular", "mode", "target"},
{"plugin", "*", "2", "plugin", "instance"},
{"<"},
@@ -1530,6 +1530,8 @@ void mjXReader::OneMaterial(XMLElement* elem, mjsMaterial* pmat) {
ReadAttr(elem, "specular", 1, &pmat->specular, text);
ReadAttr(elem, "shininess", 1, &pmat->shininess, text);
ReadAttr(elem, "reflectance", 1, &pmat->reflectance, text);
ReadAttr(elem, "metallic", 1, &pmat->metallic, text);
ReadAttr(elem, "roughness", 1, &pmat->roughness, text);
ReadAttr(elem, "rgba", 4, pmat->rgba, text);
// write error info
@@ -1783,7 +1785,7 @@ void mjXReader::OneLight(XMLElement* elem, mjsLight* plight) {
}
ReadAttr(elem, "pos", 3, plight->pos, text);
ReadAttr(elem, "dir", 3, plight->dir, text);
ReadAttr(elem, "radius", 1, &plight->radius, text);
ReadAttr(elem, "bulbradius", 1, &plight->bulbradius, text);
ReadAttr(elem, "attenuation", 3, plight->attenuation, text);
ReadAttr(elem, "cutoff", 1, &plight->cutoff, text);
ReadAttr(elem, "exponent", 1, &plight->exponent, text);
+3 -1
View File
@@ -268,6 +268,8 @@ void mjXWriter::OneMaterial(XMLElement* elem, mjCMaterial* pmat, mjCDef* def) {
WriteAttr(elem, "specular", 1, &pmat->specular, &def->material.specular);
WriteAttr(elem, "shininess", 1, &pmat->shininess, &def->material.shininess);
WriteAttr(elem, "reflectance", 1, &pmat->reflectance, &def->material.reflectance);
WriteAttr(elem, "metallic", 1, &pmat->metallic, &def->material.metallic);
WriteAttr(elem, "roughness", 1, &pmat->roughness, &def->material.roughness);
WriteAttr(elem, "rgba", 4, pmat->rgba, def->material.rgba);
}
@@ -508,7 +510,7 @@ void mjXWriter::OneLight(XMLElement* elem, mjCLight* plight, mjCDef* def) {
}
// defaults and regular
WriteAttr(elem, "radius", 1, &plight->radius, &def->light.radius);
WriteAttr(elem, "bulbradius", 1, &plight->bulbradius, &def->light.bulbradius);
WriteAttrKey(elem, "directional", bool_map, 2, plight->directional, def->light.directional);
WriteAttrKey(elem, "castshadow", bool_map, 2, plight->castshadow, def->light.castshadow);
WriteAttrKey(elem, "active", bool_map, 2, plight->active, def->light.active);
+5 -5
View File
@@ -1873,22 +1873,22 @@ TEST_F(XMLReaderTest, LightRadius) {
<mujoco>
<default>
<default class="r1">
<light radius="1"/>
<light bulbradius="1"/>
</default>
</default>
<worldbody>
<light/>
<light class="r1"/>
<light class="r1" radius="2"/>
<light class="r1" bulbradius="2"/>
</worldbody>
</mujoco>
)";
std::array<char, 1024> error;
mjModel* model = LoadModelFromString(xml, error.data(), error.size());
ASSERT_THAT(model, NotNull()) << error.data();
EXPECT_EQ(model->light_radius[0], 0);
EXPECT_EQ(model->light_radius[1], 1);
EXPECT_EQ(model->light_radius[2], 2);
EXPECT_FLOAT_EQ(model->light_bulbradius[0], 0.02);
EXPECT_FLOAT_EQ(model->light_bulbradius[1], 1);
EXPECT_FLOAT_EQ(model->light_bulbradius[2], 2);
mj_deleteModel(model);
}
+35 -5
View File
@@ -943,13 +943,13 @@ TEST_F(XMLWriterTest, WritesLight) {
<mujoco>
<default>
<default class="r1">
<light radius="1"/>
<light bulbradius="1"/>
</default>
</default>
<worldbody>
<light/>
<light class="r1"/>
<light class="r1" radius="2"/>
<light class="r1" bulbradius="2"/>
</worldbody>
</mujoco>
)";
@@ -959,9 +959,39 @@ TEST_F(XMLWriterTest, WritesLight) {
// save and read, compare data
mjModel* mtemp = LoadModelFromString(SaveAndReadXml(model));
EXPECT_EQ(mtemp->nlight, 3);
EXPECT_EQ(mtemp->light_radius[0], 0);
EXPECT_EQ(mtemp->light_radius[1], 1);
EXPECT_EQ(mtemp->light_radius[2], 2);
EXPECT_FLOAT_EQ(mtemp->light_bulbradius[0], 0.02);
EXPECT_FLOAT_EQ(mtemp->light_bulbradius[1], 1);
EXPECT_FLOAT_EQ(mtemp->light_bulbradius[2], 2);
mj_deleteModel(mtemp);
mj_deleteModel(model);
}
TEST_F(XMLWriterTest, WritesMaterial) {
static constexpr char xml[] = R"(
<mujoco>
<default>
<default class="mat">
<material metallic="2" roughness="3"/>
</default>
</default>
<asset>
<material name="0" class="mat"/>
<material name="1" class="mat" metallic="4" roughness="5"/>
</asset>
</mujoco>
)";
std::array<char, 1000> error;
mjModel* model = LoadModelFromString(xml, error.data(), error.size());
ASSERT_THAT(model, NotNull()) << error.data();
// save and read, compare data
mjModel* mtemp = LoadModelFromString(SaveAndReadXml(model));
EXPECT_EQ(mtemp->nmat, 2);
EXPECT_EQ(mtemp->mat_metallic[0], 2);
EXPECT_EQ(mtemp->mat_metallic[1], 4);
EXPECT_EQ(mtemp->mat_roughness[0], 3);
EXPECT_EQ(mtemp->mat_roughness[1], 5);
mj_deleteModel(mtemp);
mj_deleteModel(model);
+7 -1
View File
@@ -5294,10 +5294,10 @@ public unsafe struct mjModel_ {
public int* light_targetbodyid;
public byte* light_directional;
public byte* light_castshadow;
public float* light_bulbradius;
public byte* light_active;
public double* light_pos;
public double* light_dir;
public double* light_radius;
public double* light_poscom0;
public double* light_pos0;
public double* light_dir0;
@@ -5420,6 +5420,8 @@ public unsafe struct mjModel_ {
public float* mat_specular;
public float* mat_shininess;
public float* mat_reflectance;
public float* mat_metallic;
public float* mat_roughness;
public float* mat_rgba;
public int* pair_dim;
public int* pair_geom1;
@@ -5872,6 +5874,7 @@ public unsafe struct mjvLight_ {
public byte headlight;
public byte directional;
public byte castshadow;
public float bulbradius;
}
[StructLayout(LayoutKind.Sequential)]
@@ -6149,6 +6152,7 @@ public unsafe struct model {
public float* cam_sensorsize;
public byte* light_directional;
public byte* light_castshadow;
public float* light_bulbradius;
public byte* light_active;
public float* light_attenuation;
public float* light_cutoff;
@@ -6210,6 +6214,8 @@ public unsafe struct model {
public float* mat_specular;
public float* mat_shininess;
public float* mat_reflectance;
public float* mat_metallic;
public float* mat_roughness;
public float* mat_rgba;
public int* eq_type;
public int* eq_obj1id;