Compute nonzero default mass value only if geom is not in the default section.
Fixes #561. PiperOrigin-RevId: 486604407 Change-Id: Ie62578808f96f0de3a2353c6bc4cc8bd3ae3afbc
This commit is contained in:
committed by
Copybara-Service
parent
36b30e4500
commit
fc24097b92
@@ -252,6 +252,7 @@ void mjXWriter::OneJoint(XMLElement* elem, mjCJoint* pjoint, mjCDef* def) {
|
||||
// write geom
|
||||
void mjXWriter::OneGeom(XMLElement* elem, mjCGeom* pgeom, mjCDef* def) {
|
||||
double unitq[4] = {1, 0, 0, 0};
|
||||
double mass = 0;
|
||||
|
||||
// regular
|
||||
if (!writingdefaults) {
|
||||
@@ -260,6 +261,9 @@ void mjXWriter::OneGeom(XMLElement* elem, mjCGeom* pgeom, mjCDef* def) {
|
||||
if (mjGEOMINFO[pgeom->type]) {
|
||||
WriteAttr(elem, "size", mjGEOMINFO[pgeom->type], pgeom->size, def->geom.size);
|
||||
}
|
||||
if (mjuu_defined(pgeom->_mass)) {
|
||||
mass = pgeom->GetVolume() * def->geom.density;
|
||||
}
|
||||
|
||||
// mesh geom
|
||||
if (pgeom->type==mjGEOM_MESH) {
|
||||
@@ -308,7 +312,6 @@ void mjXWriter::OneGeom(XMLElement* elem, mjCGeom* pgeom, mjCDef* def) {
|
||||
WriteAttr(elem, "fluidcoef", 5, pgeom->fluid_coefs, def->geom.fluid_coefs);
|
||||
WriteAttrKey(elem, "shellinertia", meshtype_map, 2, pgeom->typeinertia, def->geom.typeinertia);
|
||||
if (mjuu_defined(pgeom->_mass)) {
|
||||
double mass = pgeom->GetVolume() * def->geom.density;
|
||||
WriteAttr(elem, "mass", 1, &pgeom->mass, &mass);
|
||||
} else {
|
||||
WriteAttr(elem, "density", 1, &pgeom->density, &def->geom.density);
|
||||
|
||||
@@ -684,6 +684,31 @@ TEST_F(XMLWriterTest, OverwritesDensity) {
|
||||
mj_deleteModel(model);
|
||||
}
|
||||
|
||||
TEST_F(XMLWriterTest, SaveDefaultMass) {
|
||||
static constexpr char xml[] = R"(
|
||||
<mujoco>
|
||||
<asset>
|
||||
<mesh name="example"
|
||||
vertex="0 0 0 1 0 0 0 1 0 0 0 1"
|
||||
face="2 0 3 0 1 3 1 2 3 0 2 1" />
|
||||
</asset>
|
||||
<default class="main">
|
||||
<geom type="mesh" mass="1"/>
|
||||
</default>
|
||||
<worldbody>
|
||||
<body>
|
||||
<geom mesh="example" size=".1 .2 .3"/>
|
||||
</body>
|
||||
</worldbody>
|
||||
</mujoco>
|
||||
)";
|
||||
mjModel* model = LoadModelFromString(xml);
|
||||
EXPECT_THAT(model, NotNull());
|
||||
std::string content = SaveAndReadXml(model);
|
||||
EXPECT_THAT(content, HasSubstr("mass=\"1\""));
|
||||
mj_deleteModel(model);
|
||||
}
|
||||
|
||||
TEST_F(XMLWriterTest, UsesTwoSpaces) {
|
||||
static constexpr char xml[] = R"(
|
||||
<mujoco>
|
||||
|
||||
Reference in New Issue
Block a user