Add anchor support for connect constraint components.

Fixes #647

PiperOrigin-RevId: 495587232
Change-Id: I528a69dabbc1ac9a12f9ab7c16716e3d69c635e2
This commit is contained in:
Tom Erez
2022-12-15 07:25:16 -08:00
committed by Copybara-Service
parent bc02c2455e
commit e95b0c0eaf
@@ -22,14 +22,17 @@ namespace Mujoco {
public class MjConnect : MjBaseConstraint {
public MjBaseBody Body1;
public MjBaseBody Body2;
public Transform Anchor;
protected override string _constraintName => "connect";
protected override void FromMjcf(XmlElement mjcf) {
Body1 = mjcf.GetObjectReferenceAttribute<MjBaseBody>("body1");
Body2 = mjcf.GetObjectReferenceAttribute<MjBaseBody>("body2");
if (mjcf.GetStringAttribute("anchor") != null) {
Debug.Log($"anchor in connect {name} ignored. Set Transforms in the editor.");
}
var anchorPos = MjEngineTool.UnityVector3(
mjcf.GetVector3Attribute("anchor", defaultValue: Vector3.zero));
Anchor = new GameObject("connect_anchor").transform;
Anchor.parent = Body1.transform;
Anchor.localPosition = anchorPos;
}
// Generate implementation specific XML element.
@@ -39,6 +42,8 @@ namespace Mujoco {
}
mjcf.SetAttribute("body1", Body1.MujocoName);
mjcf.SetAttribute("body2", Body2.MujocoName);
mjcf.SetAttribute("anchor",
MjEngineTool.Vector3ToMjcf(MjEngineTool.MjVector3(Anchor.localPosition)));
}
public void OnValidate() {