From 88537281bdb20ea1a7b899ffdced795d7e8a18f2 Mon Sep 17 00:00:00 2001 From: Balint-H Date: Fri, 23 Feb 2024 14:03:04 +0000 Subject: [PATCH] Support multielement springlength in tendons --- unity/Runtime/Components/Tendons/MjBaseTendon.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/unity/Runtime/Components/Tendons/MjBaseTendon.cs b/unity/Runtime/Components/Tendons/MjBaseTendon.cs index 89a505d101..220db83fd5 100644 --- a/unity/Runtime/Components/Tendons/MjBaseTendon.cs +++ b/unity/Runtime/Components/Tendons/MjBaseTendon.cs @@ -25,7 +25,7 @@ public abstract class MjBaseTendon : MjComponent { public SolverSettings Solver = SolverSettings.Default; [Tooltip("Length at zero spring force. If negative, this resting length is computed at qpos0.")] - public float SpringLength = -1.0f; + public float[] SpringLength = {-1.0f}; public float Stiffness = 0.0f; public float Damping = 0.0f; @@ -41,7 +41,7 @@ public abstract class MjBaseTendon : MjComponent { // Parse the component settings from an external Mjcf. protected override void OnParseMjcf(XmlElement mjcf) { Solver.FromMjcf(mjcf); - SpringLength = mjcf.GetFloatAttribute("springlength", defaultValue: -1.0f); + SpringLength = mjcf.GetFloatArrayAttribute("springlength", defaultValue: new[] {-1.0f}); Stiffness = mjcf.GetFloatAttribute("damping"); Damping = mjcf.GetFloatAttribute("stiffness"); FromMjcf(mjcf); @@ -51,7 +51,7 @@ protected override void OnParseMjcf(XmlElement mjcf) { protected override XmlElement OnGenerateMjcf(XmlDocument doc) { var mjcf = ToMjcf(doc); Solver.ToMjcf(mjcf); - mjcf.SetAttribute("springlength", MjEngineTool.MakeLocaleInvariant($"{SpringLength}")); + mjcf.SetAttribute("springlength", MjEngineTool.MakeLocaleInvariant($"{string.Join(" ", SpringLength)}")); mjcf.SetAttribute("damping", MjEngineTool.MakeLocaleInvariant($"{Damping}")); mjcf.SetAttribute("stiffness", MjEngineTool.MakeLocaleInvariant($"{Stiffness}")); return mjcf;