diff --git a/unity/Runtime/Components/Bodies/MjMocapBody.cs b/unity/Runtime/Components/Bodies/MjMocapBody.cs index 09ac2966..e919ce60 100644 --- a/unity/Runtime/Components/Bodies/MjMocapBody.cs +++ b/unity/Runtime/Components/Bodies/MjMocapBody.cs @@ -19,7 +19,11 @@ using UnityEngine; namespace Mujoco { public class MjMocapBody : MjBaseBody { protected override void OnParseMjcf(XmlElement mjcf) { - throw new Exception("parsing mocap bodies isn't supported."); + // Transform + transform.localPosition = + MjEngineTool.UnityVector3(mjcf.GetVector3Attribute("pos", defaultValue: Vector3.zero)); + transform.localRotation = MjEngineTool.UnityQuaternion( + mjcf.GetQuaternionAttribute("quat", defaultValue: MjEngineTool.MjQuaternionIdentity)); } protected override unsafe void OnBindToRuntime(MujocoLib.mjModel_* model, MujocoLib.mjData_* data) { diff --git a/unity/Runtime/Components/Sensors/MjBodyQuaternionSensor.cs b/unity/Runtime/Components/Sensors/MjBodyQuaternionSensor.cs index 23b25889..aa543a0f 100644 --- a/unity/Runtime/Components/Sensors/MjBodyQuaternionSensor.cs +++ b/unity/Runtime/Components/Sensors/MjBodyQuaternionSensor.cs @@ -20,7 +20,7 @@ using UnityEngine; namespace Mujoco { public class MjBodyQuaternionSensor : MjBaseSensor { - public MjBody Body; + public MjBaseBody Body; [Tooltip("Should the Frame sensors use the inertial or the regular frame of reference.")] public bool UseInertialFrame; @@ -39,7 +39,7 @@ public class MjBodyQuaternionSensor : MjBaseSensor { protected override void FromMjcf(XmlElement mjcf) { UseInertialFrame = mjcf.HasAttribute("body"); - Body = mjcf.GetObjectReferenceAttribute("objname"); + Body = mjcf.GetObjectReferenceAttribute("objname"); if (Body == null) { throw new NullReferenceException("Missing a reference to a MjBody."); } diff --git a/unity/Runtime/Components/Sensors/MjBodyVectorSensor.cs b/unity/Runtime/Components/Sensors/MjBodyVectorSensor.cs index 7606a880..fb37a934 100644 --- a/unity/Runtime/Components/Sensors/MjBodyVectorSensor.cs +++ b/unity/Runtime/Components/Sensors/MjBodyVectorSensor.cs @@ -36,7 +36,7 @@ public class MjBodyVectorSensor : MjBaseSensor { FrameAngAcc, } public AvailableSensors SensorType; - public MjBody Body; + public MjBaseBody Body; [Tooltip("Should the Frame sensors use the inertial or the regular frame of reference.")] public bool UseInertialFrame; @@ -64,9 +64,9 @@ public class MjBodyVectorSensor : MjBaseSensor { } if (mjcf.Name.Contains("frame")) { UseInertialFrame = mjcf.HasAttribute("body"); // as opposed to xbody - Body = mjcf.GetObjectReferenceAttribute("objname"); + Body = mjcf.GetObjectReferenceAttribute("objname"); } else { - Body = mjcf.GetObjectReferenceAttribute("body"); + Body = mjcf.GetObjectReferenceAttribute("body"); } } diff --git a/unity/Runtime/Importer/MjcfImporter.cs b/unity/Runtime/Importer/MjcfImporter.cs index 6215e6e0..3442de0b 100644 --- a/unity/Runtime/Importer/MjcfImporter.cs +++ b/unity/Runtime/Importer/MjcfImporter.cs @@ -252,7 +252,18 @@ public class MjcfImporter { break; } case "body": { - var childObject = CreateGameObjectWithUniqueName(parentObject, child); + GameObject childObject = null; + const string mocapAttribute = "mocap"; + if (child.HasAttribute(mocapAttribute)) { + var mocapValueStr = child.GetAttribute(mocapAttribute); + var mocapValue = bool.Parse(mocapValueStr); + if (mocapValue) { + childObject = CreateGameObjectWithUniqueName(parentObject, child); + } + } + if (childObject == null) { + childObject = CreateGameObjectWithUniqueName(parentObject, child); + } ParseBodyChildren(childObject, child); break; }