Store the mjsCompiler -> appended mjSpec map when appending an mjSpec.
Previously, we stored the source `mjSpec` during a copy as a hack for having access to the compiler options, but this is not robust since we cannot guarantee that 1) the source `mjSpec` is not destroyed before we need to look up the compiler options nor 2) that the `mjSpec` was appended without a copy. While 2) could be solved by simply handling an additional case in `mjCModel::FindSpec`, using a map also solves 1) and it is easier to understand. PiperOrigin-RevId: 741504264 Change-Id: Iab1bfd9e61299a94fa8caf3a244c067b09d54384
This commit is contained in:
committed by
Copybara-Service
parent
6e19035aab
commit
01d4c46753
@@ -2514,6 +2514,54 @@ TEST_F(MujocoTest, DifferentUnitsAllowed) {
|
||||
mj_deleteModel(copied_model);
|
||||
}
|
||||
|
||||
TEST_F(MujocoTest, DifferentOptionsInAttachedFrame) {
|
||||
static constexpr char xml_parent[] = R"(
|
||||
<mujoco>
|
||||
<worldbody/>
|
||||
</mujoco>
|
||||
)";
|
||||
|
||||
static constexpr char xml_child[] = R"(
|
||||
<mujoco>
|
||||
<compiler eulerseq="zyx"/>
|
||||
<worldbody>
|
||||
<frame name="child" >
|
||||
<site euler="0 90 180"/>
|
||||
</frame>
|
||||
</worldbody>
|
||||
</mujoco>
|
||||
)";
|
||||
|
||||
// load specs and compile child
|
||||
mjSpec* parent = mj_parseXMLString(xml_parent, 0, nullptr, 0);
|
||||
EXPECT_THAT(parent, NotNull());
|
||||
mjSpec* child = mj_parseXMLString(xml_child, 0, nullptr, 0);
|
||||
EXPECT_THAT(child, NotNull());
|
||||
mjModel* m_child = mj_compile(child, 0);
|
||||
EXPECT_THAT(m_child, NotNull());
|
||||
|
||||
// attach child frame to parent worldbody
|
||||
mjsBody* world = mjs_findBody(parent, "world");
|
||||
EXPECT_THAT(world, NotNull());
|
||||
mjsFrame* child_frame = mjs_findFrame(child, "child");
|
||||
EXPECT_THAT(child_frame, NotNull());
|
||||
mjsFrame* attached_frame = mjs_attachFrame(world, child_frame, "child-", "");
|
||||
EXPECT_THAT(attached_frame, NotNull());
|
||||
|
||||
// wrap the child frame in the parent frame and compile
|
||||
mjModel* m_attached = mj_compile(parent, 0);
|
||||
EXPECT_THAT(m_attached, NotNull());
|
||||
EXPECT_NEAR(m_attached->site_quat[0], m_child->site_quat[0], 1e-6);
|
||||
EXPECT_NEAR(m_attached->site_quat[1], m_child->site_quat[1], 1e-6);
|
||||
EXPECT_NEAR(m_attached->site_quat[2], m_child->site_quat[2], 1e-6);
|
||||
EXPECT_NEAR(m_attached->site_quat[3], m_child->site_quat[3], 1e-6);
|
||||
|
||||
mj_deleteSpec(parent);
|
||||
mj_deleteSpec(child);
|
||||
mj_deleteModel(m_child);
|
||||
mj_deleteModel(m_attached);
|
||||
}
|
||||
|
||||
TEST_F(MujocoTest, CopyAttachedSpec) {
|
||||
static constexpr char xml_parent[] = R"(
|
||||
<mujoco>
|
||||
|
||||
Reference in New Issue
Block a user