diff --git a/include/mujoco/experimental/usd/layer_sink.h b/include/mujoco/experimental/usd/layer_sink.h new file mode 100644 index 00000000..34af9134 --- /dev/null +++ b/include/mujoco/experimental/usd/layer_sink.h @@ -0,0 +1,41 @@ +// Copyright 2025 DeepMind Technologies Limited +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef MUJOCO_SRC_EXPERIMENTAL_USD_LAYER_SINK_H_ +#define MUJOCO_SRC_EXPERIMENTAL_USD_LAYER_SINK_H_ + +#include + +#include +#include +#include + +namespace mujoco { +namespace usd { + +// A sink for writing pose data to an SDF layer. +// Opinions will be authored on the edit target layer for the +// passed stage argument. +class LayerSink { + public: + explicit LayerSink(pxr::UsdStageRefPtr stage); + void Update(const mjData* const data, std::vector body_paths_); + + private: + pxr::UsdStageRefPtr stage_; +}; +} // namespace usd +} // namespace mujoco + +#endif // MUJOCO_SRC_EXPERIMENTAL_USD_LAYER_SINK_H_ diff --git a/src/experimental/usd/mjcPhysics/actuatorAPI.h b/include/mujoco/experimental/usd/mjcPhysics/actuatorAPI.h similarity index 99% rename from src/experimental/usd/mjcPhysics/actuatorAPI.h rename to include/mujoco/experimental/usd/mjcPhysics/actuatorAPI.h index c914ef77..266ecd51 100644 --- a/src/experimental/usd/mjcPhysics/actuatorAPI.h +++ b/include/mujoco/experimental/usd/mjcPhysics/actuatorAPI.h @@ -17,8 +17,8 @@ /// \file mjcPhysics/actuatorAPI.h -#include "./api.h" -#include "./tokens.h" +#include +#include #include "pxr/base/gf/matrix4d.h" #include "pxr/base/gf/vec3d.h" #include "pxr/base/gf/vec3f.h" diff --git a/src/experimental/usd/mjcPhysics/api.h b/include/mujoco/experimental/usd/mjcPhysics/api.h similarity index 100% rename from src/experimental/usd/mjcPhysics/api.h rename to include/mujoco/experimental/usd/mjcPhysics/api.h diff --git a/src/experimental/usd/mjcPhysics/collisionAPI.h b/include/mujoco/experimental/usd/mjcPhysics/collisionAPI.h similarity index 98% rename from src/experimental/usd/mjcPhysics/collisionAPI.h rename to include/mujoco/experimental/usd/mjcPhysics/collisionAPI.h index e3681526..49dd9ce9 100644 --- a/src/experimental/usd/mjcPhysics/collisionAPI.h +++ b/include/mujoco/experimental/usd/mjcPhysics/collisionAPI.h @@ -17,8 +17,8 @@ /// \file mjcPhysics/collisionAPI.h -#include "./api.h" -#include "./tokens.h" +#include +#include #include "pxr/base/gf/matrix4d.h" #include "pxr/base/gf/vec3d.h" #include "pxr/base/gf/vec3f.h" diff --git a/src/experimental/usd/mjcPhysics/meshCollisionAPI.h b/include/mujoco/experimental/usd/mjcPhysics/meshCollisionAPI.h similarity index 98% rename from src/experimental/usd/mjcPhysics/meshCollisionAPI.h rename to include/mujoco/experimental/usd/mjcPhysics/meshCollisionAPI.h index 55c8c27e..4dd6cdec 100644 --- a/src/experimental/usd/mjcPhysics/meshCollisionAPI.h +++ b/include/mujoco/experimental/usd/mjcPhysics/meshCollisionAPI.h @@ -17,8 +17,8 @@ /// \file mjcPhysics/meshCollisionAPI.h -#include "./api.h" -#include "./tokens.h" +#include +#include #include "pxr/base/gf/matrix4d.h" #include "pxr/base/gf/vec3d.h" #include "pxr/base/gf/vec3f.h" diff --git a/src/experimental/usd/mjcPhysics/sceneAPI.h b/include/mujoco/experimental/usd/mjcPhysics/sceneAPI.h similarity index 99% rename from src/experimental/usd/mjcPhysics/sceneAPI.h rename to include/mujoco/experimental/usd/mjcPhysics/sceneAPI.h index 2ac745c7..22c5bce7 100644 --- a/src/experimental/usd/mjcPhysics/sceneAPI.h +++ b/include/mujoco/experimental/usd/mjcPhysics/sceneAPI.h @@ -17,8 +17,8 @@ /// \file mjcPhysics/sceneAPI.h -#include "./api.h" -#include "./tokens.h" +#include +#include #include "pxr/base/gf/matrix4d.h" #include "pxr/base/gf/vec3d.h" #include "pxr/base/gf/vec3f.h" diff --git a/src/experimental/usd/mjcPhysics/siteAPI.h b/include/mujoco/experimental/usd/mjcPhysics/siteAPI.h similarity index 99% rename from src/experimental/usd/mjcPhysics/siteAPI.h rename to include/mujoco/experimental/usd/mjcPhysics/siteAPI.h index 537345ce..2cb786d8 100644 --- a/src/experimental/usd/mjcPhysics/siteAPI.h +++ b/include/mujoco/experimental/usd/mjcPhysics/siteAPI.h @@ -17,7 +17,7 @@ /// \file mjcPhysics/siteAPI.h -#include "./api.h" +#include #include "pxr/base/gf/matrix4d.h" #include "pxr/base/gf/vec3d.h" #include "pxr/base/gf/vec3f.h" diff --git a/src/experimental/usd/mjcPhysics/tokens.h b/include/mujoco/experimental/usd/mjcPhysics/tokens.h similarity index 99% rename from src/experimental/usd/mjcPhysics/tokens.h rename to include/mujoco/experimental/usd/mjcPhysics/tokens.h index 999f6015..b19ada98 100644 --- a/src/experimental/usd/mjcPhysics/tokens.h +++ b/include/mujoco/experimental/usd/mjcPhysics/tokens.h @@ -26,7 +26,7 @@ #include -#include "./api.h" +#include #include "pxr/base/tf/staticData.h" #include "pxr/base/tf/token.h" #include "pxr/pxr.h" diff --git a/src/experimental/usd/utils.h b/include/mujoco/experimental/usd/utils.h similarity index 100% rename from src/experimental/usd/utils.h rename to include/mujoco/experimental/usd/utils.h diff --git a/include/mujoco/experimental/usd/writer.h b/include/mujoco/experimental/usd/writer.h new file mode 100644 index 00000000..f3d191d1 --- /dev/null +++ b/include/mujoco/experimental/usd/writer.h @@ -0,0 +1,52 @@ +// Copyright 2025 DeepMind Technologies Limited +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef MUJOCO_SRC_EXPERIMENTAL_USD_WRITER_H_ +#define MUJOCO_SRC_EXPERIMENTAL_USD_WRITER_H_ + +#include +#include + +#include +#include +#include + +namespace mujoco { +namespace usd { +using PoseSinkFn = + std::function)>; + +class Writer { + public: + Writer(pxr::UsdStageRefPtr stage, mjSpec* spec, mjModel_* model); + ~Writer(); + Writer(const Writer&) = delete; + Writer& operator=(const Writer&) = delete; + + void Update(const mjData* const data); + void AddSink(PoseSinkFn sink_fn); + + private: + void BuildMjUsdMapping(); + + pxr::UsdStageRefPtr stage_; + std::vector body_id_to_path_; + mjSpec* spec_ = nullptr; + mjModel_* model_ = nullptr; + std::vector pose_sinks_; +}; +} // namespace usd +} // namespace mujoco + +#endif // MUJOCO_SRC_EXPERIMENTAL_USD_WRITER_H_ diff --git a/src/experimental/usd/mjcPhysics/actuatorAPI.cpp b/src/experimental/usd/mjcPhysics/actuatorAPI.cpp index 1ba5dae1..13e25fc8 100644 --- a/src/experimental/usd/mjcPhysics/actuatorAPI.cpp +++ b/src/experimental/usd/mjcPhysics/actuatorAPI.cpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "./actuatorAPI.h" +#include #include "pxr/usd/sdf/assetPath.h" #include "pxr/usd/sdf/types.h" diff --git a/src/experimental/usd/mjcPhysics/collisionAPI.cpp b/src/experimental/usd/mjcPhysics/collisionAPI.cpp index ff113849..ba1e52e9 100644 --- a/src/experimental/usd/mjcPhysics/collisionAPI.cpp +++ b/src/experimental/usd/mjcPhysics/collisionAPI.cpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "./collisionAPI.h" +#include #include "pxr/usd/sdf/assetPath.h" #include "pxr/usd/sdf/types.h" diff --git a/src/experimental/usd/mjcPhysics/meshCollisionAPI.cpp b/src/experimental/usd/mjcPhysics/meshCollisionAPI.cpp index 50c579dd..17cda5ae 100644 --- a/src/experimental/usd/mjcPhysics/meshCollisionAPI.cpp +++ b/src/experimental/usd/mjcPhysics/meshCollisionAPI.cpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "./meshCollisionAPI.h" +#include #include "pxr/usd/sdf/assetPath.h" #include "pxr/usd/sdf/types.h" diff --git a/src/experimental/usd/mjcPhysics/sceneAPI.cpp b/src/experimental/usd/mjcPhysics/sceneAPI.cpp index 7bce5c2d..ba961a55 100644 --- a/src/experimental/usd/mjcPhysics/sceneAPI.cpp +++ b/src/experimental/usd/mjcPhysics/sceneAPI.cpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "./sceneAPI.h" +#include #include "pxr/usd/sdf/assetPath.h" #include "pxr/usd/sdf/types.h" diff --git a/src/experimental/usd/mjcPhysics/siteAPI.cpp b/src/experimental/usd/mjcPhysics/siteAPI.cpp index 1693dd16..88e47544 100644 --- a/src/experimental/usd/mjcPhysics/siteAPI.cpp +++ b/src/experimental/usd/mjcPhysics/siteAPI.cpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "./siteAPI.h" +#include #include "pxr/usd/sdf/assetPath.h" #include "pxr/usd/sdf/types.h" diff --git a/src/experimental/usd/mjcPhysics/tokens.cpp b/src/experimental/usd/mjcPhysics/tokens.cpp index dcbfc393..0fa5cef2 100644 --- a/src/experimental/usd/mjcPhysics/tokens.cpp +++ b/src/experimental/usd/mjcPhysics/tokens.cpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "./tokens.h" +#include PXR_NAMESPACE_OPEN_SCOPE diff --git a/src/experimental/usd/plugins/mjcf/mujoco_to_usd.cc b/src/experimental/usd/plugins/mjcf/mujoco_to_usd.cc index 6d559fa8..c91d91e2 100644 --- a/src/experimental/usd/plugins/mjcf/mujoco_to_usd.cc +++ b/src/experimental/usd/plugins/mjcf/mujoco_to_usd.cc @@ -23,7 +23,7 @@ #include #include -#include "third_party/mujoco/src/experimental/usd/mjcPhysics/tokens.h" +#include #include "mjcf/utils.h" #include #include diff --git a/src/experimental/usd/utils.cc b/src/experimental/usd/utils.cc index 220c4178..0dc66353 100644 --- a/src/experimental/usd/utils.cc +++ b/src/experimental/usd/utils.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "third_party/mujoco/src/experimental/usd/utils.h" +#include #include #include diff --git a/test/experimental/usd/mjcPhysics/mjc_physics_scene_test.cc b/test/experimental/usd/mjcPhysics/mjc_physics_scene_test.cc index 534dcffe..5748f5bb 100644 --- a/test/experimental/usd/mjcPhysics/mjc_physics_scene_test.cc +++ b/test/experimental/usd/mjcPhysics/mjc_physics_scene_test.cc @@ -14,8 +14,8 @@ #include #include +#include #include -#include "src/experimental/usd/mjcPhysics/sceneAPI.h" #include "test/fixture.h" #include #include diff --git a/test/experimental/usd/mjcPhysics/mjc_site_api_test.cc b/test/experimental/usd/mjcPhysics/mjc_site_api_test.cc index a193dbb1..360989f9 100644 --- a/test/experimental/usd/mjcPhysics/mjc_site_api_test.cc +++ b/test/experimental/usd/mjcPhysics/mjc_site_api_test.cc @@ -14,9 +14,9 @@ #include #include -#include +#include +#include #include -#include "src/experimental/usd/mjcPhysics/siteAPI.h" #include "test/fixture.h" #include #include diff --git a/test/experimental/usd/plugins/mjcf/mjcf_file_format_test.cc b/test/experimental/usd/plugins/mjcf/mjcf_file_format_test.cc index 41bd3ea3..a9e5d8c1 100644 --- a/test/experimental/usd/plugins/mjcf/mjcf_file_format_test.cc +++ b/test/experimental/usd/plugins/mjcf/mjcf_file_format_test.cc @@ -17,12 +17,12 @@ #include #include -#include "src/experimental/usd/mjcPhysics/actuatorAPI.h" -#include "src/experimental/usd/mjcPhysics/collisionAPI.h" -#include "src/experimental/usd/mjcPhysics/meshCollisionAPI.h" -#include "src/experimental/usd/mjcPhysics/sceneAPI.h" -#include "src/experimental/usd/mjcPhysics/siteAPI.h" -#include "src/experimental/usd/mjcPhysics/tokens.h" +#include +#include +#include +#include +#include +#include #include "test/experimental/usd/test_utils.h" #include "test/fixture.h" #include