Store a copy of the attached specs in the destination spec.
PiperOrigin-RevId: 689013340 Change-Id: I2cb7a1f3850f0e3592834b355d35dcc2cd8f150f
This commit is contained in:
committed by
Copybara-Service
parent
d17d9e835c
commit
ed7655cf97
@@ -845,6 +845,12 @@ mjCBody& mjCBody::operator+=(const mjCBody& other) {
|
|||||||
|
|
||||||
// attach frame to body
|
// attach frame to body
|
||||||
mjCBody& mjCBody::operator+=(const mjCFrame& other) {
|
mjCBody& mjCBody::operator+=(const mjCFrame& other) {
|
||||||
|
// append a copy of the attached spec
|
||||||
|
if (other.model != model && !model->FindSpec(mjs_getString(other.model->spec.modelname))) {
|
||||||
|
model->AppendSpec(mj_copySpec(&other.model->spec));
|
||||||
|
}
|
||||||
|
|
||||||
|
// create a copy of the subtree that contains the frame
|
||||||
mjCBody* subtree = other.body;
|
mjCBody* subtree = other.body;
|
||||||
other.model->prefix = other.prefix;
|
other.model->prefix = other.prefix;
|
||||||
other.model->suffix = other.suffix;
|
other.model->suffix = other.suffix;
|
||||||
@@ -1805,6 +1811,12 @@ mjCFrame& mjCFrame::operator=(const mjCFrame& other) {
|
|||||||
|
|
||||||
// attach body to frame
|
// attach body to frame
|
||||||
mjCFrame& mjCFrame::operator+=(const mjCBody& other) {
|
mjCFrame& mjCFrame::operator+=(const mjCBody& other) {
|
||||||
|
// append a copy of the attached spec
|
||||||
|
if (other.model != model && !model->FindSpec(mjs_getString(other.model->spec.modelname))) {
|
||||||
|
model->AppendSpec(mj_copySpec(&other.model->spec));
|
||||||
|
}
|
||||||
|
|
||||||
|
// apply namespace and store keyframes in the source model
|
||||||
other.model->prefix = other.prefix;
|
other.model->prefix = other.prefix;
|
||||||
other.model->suffix = other.suffix;
|
other.model->suffix = other.suffix;
|
||||||
other.model->StoreKeyframes(model);
|
other.model->StoreKeyframes(model);
|
||||||
|
|||||||
@@ -624,7 +624,7 @@ TEST_F(PluginTest, TextureFromBuffer) {
|
|||||||
// -------------------------------- test attach --------------------------------
|
// -------------------------------- test attach --------------------------------
|
||||||
|
|
||||||
static constexpr char xml_child[] = R"(
|
static constexpr char xml_child[] = R"(
|
||||||
<mujoco>
|
<mujoco model="child">
|
||||||
<default>
|
<default>
|
||||||
<default class="cylinder">
|
<default class="cylinder">
|
||||||
<geom type="cylinder" size=".1 1 0"/>
|
<geom type="cylinder" size=".1 1 0"/>
|
||||||
@@ -691,7 +691,7 @@ TEST_F(MujocoTest, AttachSame) {
|
|||||||
std::string field = "";
|
std::string field = "";
|
||||||
|
|
||||||
static constexpr char xml_result[] = R"(
|
static constexpr char xml_result[] = R"(
|
||||||
<mujoco>
|
<mujoco model="child">
|
||||||
<default>
|
<default>
|
||||||
<default class="cylinder">
|
<default class="cylinder">
|
||||||
<geom type="cylinder" size=".1 1 0"/>
|
<geom type="cylinder" size=".1 1 0"/>
|
||||||
@@ -781,6 +781,9 @@ TEST_F(MujocoTest, AttachSame) {
|
|||||||
mjsBody* attached = mjs_attachBody(frame, body, "attached-", "-1");
|
mjsBody* attached = mjs_attachBody(frame, body, "attached-", "-1");
|
||||||
EXPECT_THAT(attached, mjs_findBody(parent, "attached-body-1"));
|
EXPECT_THAT(attached, mjs_findBody(parent, "attached-body-1"));
|
||||||
|
|
||||||
|
// check that the spec was not copied
|
||||||
|
EXPECT_THAT(mjs_findSpec(parent, "child"), IsNull());
|
||||||
|
|
||||||
// compile new model
|
// compile new model
|
||||||
mjModel* m_attached = mj_compile(parent, 0);
|
mjModel* m_attached = mj_compile(parent, 0);
|
||||||
EXPECT_THAT(m_attached, NotNull());
|
EXPECT_THAT(m_attached, NotNull());
|
||||||
@@ -912,6 +915,9 @@ TEST_F(MujocoTest, AttachDifferent) {
|
|||||||
mjsBody* attached = mjs_attachBody(frame, body, "attached-", "-1");
|
mjsBody* attached = mjs_attachBody(frame, body, "attached-", "-1");
|
||||||
EXPECT_THAT(attached, mjs_findBody(parent, "attached-body-1"));
|
EXPECT_THAT(attached, mjs_findBody(parent, "attached-body-1"));
|
||||||
|
|
||||||
|
// check that the spec was copied
|
||||||
|
EXPECT_THAT(mjs_findSpec(parent, "child"), NotNull());
|
||||||
|
|
||||||
// compile new model
|
// compile new model
|
||||||
mjModel* m_attached = mj_compile(parent, 0);
|
mjModel* m_attached = mj_compile(parent, 0);
|
||||||
EXPECT_THAT(m_attached, NotNull());
|
EXPECT_THAT(m_attached, NotNull());
|
||||||
@@ -1043,6 +1049,9 @@ TEST_F(MujocoTest, AttachFrame) {
|
|||||||
mjsFrame* attached = mjs_attachFrame(body, frame, "attached-", "-1");
|
mjsFrame* attached = mjs_attachFrame(body, frame, "attached-", "-1");
|
||||||
EXPECT_THAT(attached, mjs_findFrame(parent, "attached-pframe-1"));
|
EXPECT_THAT(attached, mjs_findFrame(parent, "attached-pframe-1"));
|
||||||
|
|
||||||
|
// check that the spec was copied
|
||||||
|
EXPECT_THAT(mjs_findSpec(parent, "child"), NotNull());
|
||||||
|
|
||||||
// compile new model
|
// compile new model
|
||||||
mjModel* m_attached = mj_compile(parent, 0);
|
mjModel* m_attached = mj_compile(parent, 0);
|
||||||
EXPECT_THAT(m_attached, NotNull());
|
EXPECT_THAT(m_attached, NotNull());
|
||||||
@@ -1073,7 +1082,7 @@ void TestDetachBody(bool compile) {
|
|||||||
std::string field = "";
|
std::string field = "";
|
||||||
|
|
||||||
static constexpr char xml_result[] = R"(
|
static constexpr char xml_result[] = R"(
|
||||||
<mujoco>
|
<mujoco model="child">
|
||||||
<asset>
|
<asset>
|
||||||
<texture name="texture" type="2d" builtin="checker" width="32" height="32"/>
|
<texture name="texture" type="2d" builtin="checker" width="32" height="32"/>
|
||||||
<material name="material" texture="texture" texrepeat="1 1" texuniform="true"/>
|
<material name="material" texture="texture" texrepeat="1 1" texuniform="true"/>
|
||||||
|
|||||||
Reference in New Issue
Block a user