From 9971993cdb560b76f42807b161f6645c850e2a36 Mon Sep 17 00:00:00 2001 From: Benjamin Nauck Date: Sat, 11 Feb 2023 21:38:33 +0100 Subject: [PATCH 1/6] Add support for implicit integrator type The `implicit` option was added in the IntegratorType enum. Using `@` prefix to avoid collision with reserved keyword. --- unity/Runtime/Components/MjGlobalSettings.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/unity/Runtime/Components/MjGlobalSettings.cs b/unity/Runtime/Components/MjGlobalSettings.cs index ad8b7e0f..94675182 100644 --- a/unity/Runtime/Components/MjGlobalSettings.cs +++ b/unity/Runtime/Components/MjGlobalSettings.cs @@ -29,7 +29,8 @@ namespace Mujoco { // exactly what the documentation specifies: http://mujoco.org/book/XMLreference.html#option . public enum IntegratorType { Euler, - RK4 + RK4, + @implicit } public enum CollisionCheckType { From e7a9447c03aa2aaac7b6ab664a1a72623d12c89c Mon Sep 17 00:00:00 2001 From: Benjamin Nauck Date: Sun, 12 Feb 2023 21:59:31 +0100 Subject: [PATCH 2/6] Add gravcomp to body in unity plugin The unity plugin is missing gravcomp which makes it impossible for buoyancy --- unity/Runtime/Components/Bodies/MjBody.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/unity/Runtime/Components/Bodies/MjBody.cs b/unity/Runtime/Components/Bodies/MjBody.cs index 8d6a8cd3..e29de5c0 100644 --- a/unity/Runtime/Components/Bodies/MjBody.cs +++ b/unity/Runtime/Components/Bodies/MjBody.cs @@ -20,17 +20,23 @@ namespace Mujoco { // The component represents the apex of hierarchy that defines a single rigid body. public class MjBody : MjBaseBody { + + [Tooltip("Gravity compensation force, specified as fraction of body weight.")] + public float GravityCompensation; + protected override void OnParseMjcf(XmlElement mjcf) { // Transform transform.localPosition = MjEngineTool.UnityVector3(mjcf.GetVector3Attribute("pos", defaultValue: Vector3.zero)); transform.localRotation = MjEngineTool.UnityQuaternion( mjcf.GetQuaternionAttribute("quat", defaultValue: MjEngineTool.MjQuaternionIdentity)); + GravityCompensation = mjcf.GetFloatAttribute("gravcomp", defaultValue: 0.0f); } protected override XmlElement OnGenerateMjcf(XmlDocument doc) { var mjcf = (XmlElement)doc.CreateElement("body"); MjEngineTool.PositionRotationToMjcf(mjcf, this); + mjcf.SetAttribute("gravcomp", MjEngineTool.MakeLocaleInvariant($"{GravityCompensation}")); return mjcf; } From 5228ad1b2e52df20a16a77ee0acb6e22581d20d4 Mon Sep 17 00:00:00 2001 From: Benjamin Nauck Date: Sun, 12 Feb 2023 22:03:12 +0100 Subject: [PATCH 3/6] Change default wind to the value from the doc --- unity/Runtime/Components/MjGlobalSettings.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unity/Runtime/Components/MjGlobalSettings.cs b/unity/Runtime/Components/MjGlobalSettings.cs index 94675182..4510a140 100644 --- a/unity/Runtime/Components/MjGlobalSettings.cs +++ b/unity/Runtime/Components/MjGlobalSettings.cs @@ -209,7 +209,7 @@ public struct MjOptionStruct { public static MjOptionStruct Default = new MjOptionStruct() { ImpRatio = 1.0f, Magnetic = Vector3.zero, - Wind = new Vector3(0.0f, -0.5f, 0.0f), + Wind = new Vector3(0.0f, 0.0f, 0.0f), Density = 0.0f, Viscosity = 0.0f, OverrideMargin = 0.0f, From 7ed632cb9e9f1848c3dcd40e7628cb8267305eba Mon Sep 17 00:00:00 2001 From: Benjamin Nauck Date: Mon, 13 Feb 2023 12:02:10 +0100 Subject: [PATCH 4/6] Add support for arbitrary default node lookup name Makes it possible to apply modifiers to elements even if the name doesn't match. This is necessary to support default values for tendons. --- unity/Runtime/Importer/MjXmlModifiers.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/unity/Runtime/Importer/MjXmlModifiers.cs b/unity/Runtime/Importer/MjXmlModifiers.cs index 66460b59..d9d74040 100644 --- a/unity/Runtime/Importer/MjXmlModifiers.cs +++ b/unity/Runtime/Importer/MjXmlModifiers.cs @@ -28,12 +28,17 @@ namespace Mujoco { _root = root; } - public void ApplyModifiersToElement(XmlElement element) { + public void ApplyModifiersToElement(XmlElement element, string elementName=null) { + // Allow overriding the element name for defaults lookup, needed for tendon + if (elementName == null) { + elementName = element.Name; + } + // Combine all defaults into one. At this stage, we want to overwrite attributes defined by // the previous defaults. var aggregateDefaults = _root.CreateElement("aggregate"); // Root default leaf should be processed only once, and handled first (so it's overriden). - var rootDefaultLeaf = _root.SelectSingleNode($"/mujoco/default/{element.Name}") as XmlElement; + var rootDefaultLeaf = _root.SelectSingleNode($"/mujoco/default/{elementName}") as XmlElement; if (rootDefaultLeaf != null) { CopyAttributes(rootDefaultLeaf, aggregateDefaults); } @@ -43,7 +48,7 @@ namespace Mujoco { var defaultClassElement = _root.SelectSingleNode($"descendant::default[@class='{className}']") as XmlElement; // Ancestry iterates up in the tree, but we want to apply changes from remote to specific. - var ancestors = GetDefaultAncestry(defaultClassElement, element.Name).Reverse(); + var ancestors = GetDefaultAncestry(defaultClassElement, elementName).Reverse(); foreach (var defaultAncestor in ancestors) { CopyAttributesOverwriteExisting(defaultAncestor, aggregateDefaults); } From 8599d80b4dd2438d2d243d4cae0fd30a72360f51 Mon Sep 17 00:00:00 2001 From: Benjamin Nauck Date: Mon, 13 Feb 2023 12:02:29 +0100 Subject: [PATCH 5/6] Apply tendon defaults on fixed and spatial tendons --- unity/Runtime/Importer/MjcfImporter.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/unity/Runtime/Importer/MjcfImporter.cs b/unity/Runtime/Importer/MjcfImporter.cs index fe83df5f..b9738c07 100644 --- a/unity/Runtime/Importer/MjcfImporter.cs +++ b/unity/Runtime/Importer/MjcfImporter.cs @@ -167,6 +167,7 @@ public class MjcfImporter { if (tendonNode != null) { var tendonsParentObject = CreateGameObjectInParent("tendons", rootObject); foreach (var child in tendonNode.OfType()) { + _modifiers.ApplyModifiersToElement(child, elementName: "tendon"); if (child.Name == "fixed") { CreateGameObjectWithUniqueName(tendonsParentObject, child); } else if (child.Name == "spatial") { From 87bc8d0ed2a05e0dbaf6017cab251a85f1907fd9 Mon Sep 17 00:00:00 2001 From: Benjamin Nauck Date: Sun, 12 Feb 2023 22:05:25 +0100 Subject: [PATCH 6/6] Fix spelling in MjcfImporter --- unity/Runtime/Importer/MjcfImporter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unity/Runtime/Importer/MjcfImporter.cs b/unity/Runtime/Importer/MjcfImporter.cs index b9738c07..6215e6e0 100644 --- a/unity/Runtime/Importer/MjcfImporter.cs +++ b/unity/Runtime/Importer/MjcfImporter.cs @@ -239,7 +239,7 @@ public class MjcfImporter { } } - // Called by ParseBodyChildren for each XML node, overridable by inheriting claases. + // Called by ParseBodyChildren for each XML node, overridable by inheriting classes. private void ParseBodyChild(XmlElement child, GameObject parentObject) { switch (child.Name) { case "geom": {