diff --git a/simulate/simulate.cc b/simulate/simulate.cc index bf4b4a13..2f5ee146 100644 --- a/simulate/simulate.cc +++ b/simulate/simulate.cc @@ -1141,17 +1141,74 @@ void AlignAndScaleView(mj::Simulate* sim, const mjModel* m) { } -// copy qpos to clipboard as key -void CopyPose(mj::Simulate* sim, const mjModel* m, const mjData* d) { - char clipboard[5000] = ""); + + // qvel + mju::strcat_arr(clipboard, "\"\n qvel=\""); + for (int i = 0; i < m->nv; i++) { + mju::sprintf_arr(buf, format, d->qvel[i]); + if (i < m->nv-1) mju::strcat_arr(buf, " "); + mju::strcat_arr(clipboard, buf); + } + + // act + if (m->na > 0) { + mju::strcat_arr(clipboard, "\"\n act=\""); + for (int i = 0; i < m->na; i++) { + mju::sprintf_arr(buf, format, d->act[i]); + if (i < m->na-1) mju::strcat_arr(buf, " "); + mju::strcat_arr(clipboard, buf); + } + } + + // ctrl + if (m->nu > 0) { + mju::strcat_arr(clipboard, "\"\n ctrl=\""); + for (int i = 0; i < m->nu; i++) { + mju::sprintf_arr(buf, format, d->ctrl[i]); + if (i < m->nu-1) mju::strcat_arr(buf, " "); + mju::strcat_arr(clipboard, buf); + } + } + + if (m->nmocap > 0) { + // mocap_pos + mju::strcat_arr(clipboard, "\"\n mpos=\""); + for (int i = 0; i < 3*m->nmocap; i++) { + mju::sprintf_arr(buf, format, d->mocap_pos[i]); + if (i < 3*m->nmocap-1) mju::strcat_arr(buf, " "); + mju::strcat_arr(clipboard, buf); + } + + // mocap_quat + mju::strcat_arr(clipboard, "\"\n mquat=\""); + for (int i = 0; i < 4*m->nmocap; i++) { + mju::sprintf_arr(buf, format, d->mocap_quat[i]); + if (i < 4*m->nmocap-1) mju::strcat_arr(buf, " "); + mju::strcat_arr(clipboard, buf); + } + } + + mju::strcat_arr(clipboard, "\"\n/>"); // copy to clipboard sim->platform_ui->SetClipboardString(clipboard); @@ -1412,8 +1469,9 @@ void UiEvent(mjuiState* state) { sim->pending_.align = true; break; - case 4: // Copy pose - sim->pending_.copy_pose = true; + case 4: // Copy key + sim->pending_.copy_key = true; + sim->pending_.copy_key_full_precision = sim->platform_ui->IsShiftKeyPressed(); break; case 5: // Adjust key @@ -1967,9 +2025,10 @@ void Simulate::Sync() { pending_.align = false; } - if (pending_.copy_pose) { - CopyPose(this, m_, d_); - pending_.copy_pose = false; + if (pending_.copy_key) { + CopyKey(this, m_, d_, pending_.copy_key_full_precision); + pending_.copy_key = false; + pending_.copy_key_full_precision = false; } if (pending_.load_from_history) { diff --git a/simulate/simulate.h b/simulate/simulate.h index cd654192..23bdb604 100644 --- a/simulate/simulate.h +++ b/simulate/simulate.h @@ -144,7 +144,8 @@ class Simulate { std::optional print_data; bool reset; bool align; - bool copy_pose; + bool copy_key; + bool copy_key_full_precision; bool load_from_history; bool load_key; bool save_key; @@ -293,7 +294,7 @@ class Simulate { {mjITEM_BUTTON, "Reset", 2, nullptr, " #259"}, {mjITEM_BUTTON, "Reload", 5, nullptr, "CL"}, {mjITEM_BUTTON, "Align", 2, nullptr, "CA"}, - {mjITEM_BUTTON, "Copy pose", 2, nullptr, "CC"}, + {mjITEM_BUTTON, "Copy state", 2, nullptr, "CC"}, {mjITEM_SLIDERINT, "Key", 3, &this->key, "0 0"}, {mjITEM_BUTTON, "Load key", 3}, {mjITEM_BUTTON, "Save key", 3},