Initial release of the Unity plugin.

PiperOrigin-RevId: 425947505
This commit is contained in:
Tom Erez
2022-02-02 20:17:13 +00:00
committed by Saran Tunyasuvunakool
parent 8ec3dd97a4
commit 6de9eafa13
298 changed files with 20617 additions and 2 deletions
@@ -0,0 +1,80 @@
// Copyright 2019 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.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Xml;
using NUnit.Framework;
using UnityEngine;
namespace Mujoco {
[TestFixture]
public class MjConnectTests {
private MjBody _body1;
private MjBody _body2;
private MjConnect _constraint;
private XmlDocument _doc;
[SetUp]
public void SetUp() {
_body1 = new GameObject("body1").AddComponent<MjBody>();
_body2 = new GameObject("body2").AddComponent<MjBody>();
_constraint = new GameObject("connect").AddComponent<MjConnect>();
_doc = new XmlDocument();
}
[TearDown]
public void TearDown() {
UnityEngine.Object.DestroyImmediate(_constraint.gameObject);
UnityEngine.Object.DestroyImmediate(_body1.gameObject);
UnityEngine.Object.DestroyImmediate(_body2.gameObject);
}
[Test]
public void ErrorThrownWhenBody1Empty() {
// This is an illegal MJCF, but the purpose of this test is to verify that if
// the user didn't assign the body in the editor, an error will be thrown when play is hit.
_doc.LoadXml("<body/>");
_constraint.ParseMjcf(_doc.GetElementsByTagName("body")[0] as XmlElement);
Assert.That(() => { _constraint.GenerateMjcf("name", _doc); }, Throws.Exception);
}
// In this constraint both elements are required.
[Test]
public void ErrorThrownWhenBody2Empty() {
_doc.LoadXml("<body body1='body1'/>");
_constraint.ParseMjcf(_doc.GetElementsByTagName("body")[0] as XmlElement);
Assert.That(() => { _constraint.GenerateMjcf("name", _doc); }, Throws.Exception);
}
[Test]
public void ParseXML() {
_doc.LoadXml("<connect body1='body1' body2='body2'/>");
_constraint.ParseMjcf(_doc.GetElementsByTagName("connect")[0] as XmlElement);
Assert.That(_constraint.Body1, Is.EqualTo(_body1));
Assert.That(_constraint.Body2, Is.EqualTo(_body2));
}
[Test]
public void GenerateXML() {
_constraint.Body1 = _body1;
_constraint.Body2 = _body2;
var mjcf = _constraint.GenerateMjcf("name", _doc);
Assert.That(mjcf.OuterXml, Does.Contain("<connect"));
Assert.That(mjcf.OuterXml, Does.Contain("body1=\""));
Assert.That(mjcf.OuterXml, Does.Contain("body2=\""));
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 9953e9b7dff0c4779b541fb6f198daf1
timeCreated: 1554295202
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,74 @@
// Copyright 2019 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.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Xml;
using NUnit.Framework;
using UnityEngine;
namespace Mujoco {
[TestFixture]
public class MjDistanceTests {
private MjGeom _geom1;
private MjGeom _geom2;
private MjDistance _distance;
private XmlDocument _doc;
[SetUp]
public void SetUp() {
_geom1 = new GameObject("geom1").AddComponent<MjGeom>();
_geom2 = new GameObject("geom2").AddComponent<MjGeom>();
_distance = new GameObject("distance").AddComponent<MjDistance>();
_doc = new XmlDocument();
}
[TearDown]
public void TearDown() {
UnityEngine.Object.DestroyImmediate(_distance.gameObject);
UnityEngine.Object.DestroyImmediate(_geom1.gameObject);
UnityEngine.Object.DestroyImmediate(_geom2.gameObject);
}
[Test]
public void ErrorThrownWhenGeom1Empty() {
// This is an illegal MJCF, but the purpose of this test is to verify that if
// the user didn't assign the geom in the editor, an error will be thrown when play is hit.
_doc.LoadXml("<geom/>");
_distance.ParseMjcf(_doc.GetElementsByTagName("geom")[0] as XmlElement);
Assert.That(() => { _distance.GenerateMjcf("name", _doc); }, Throws.Exception);
}
// In this constraint both elements are required.
[Test]
public void ErrorThrownWhenGeom2Empty() {
_doc.LoadXml("<geom geom1='geom1'/>");
_distance.ParseMjcf(_doc.GetElementsByTagName("geom")[0] as XmlElement);
Assert.That(() => { _distance.GenerateMjcf("name", _doc); }, Throws.Exception);
}
[Test]
public void ParseAndGenerate() {
_doc.LoadXml("<distance geom1='geom1' geom2='geom2'/>");
_distance.ParseMjcf(_doc.GetElementsByTagName("distance")[0] as XmlElement);
Assert.That(_distance.Geom1, Is.EqualTo(_geom1));
Assert.That(_distance.Geom2, Is.EqualTo(_geom2));
var mjcf = _distance.GenerateMjcf("name", _doc);
Assert.That(mjcf.OuterXml, Does.Contain("<distance"));
Assert.That(mjcf.OuterXml, Does.Contain("geom1=\""));
Assert.That(mjcf.OuterXml, Does.Contain("geom2=\""));
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 528955688a5574fa5ba1433088808a1b
timeCreated: 1552313909
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,69 @@
// Copyright 2019 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.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Xml;
using NUnit.Framework;
using UnityEngine;
namespace Mujoco {
[TestFixture]
public class MjJointConstraintTests {
private MjHingeJoint _joint1;
private MjHingeJoint _joint2;
private MjJointConstraint _constraint;
private XmlDocument _doc;
[SetUp]
public void SetUp() {
_joint1 = new GameObject("joint1").AddComponent<MjHingeJoint>();
_joint2 = new GameObject("joint2").AddComponent<MjHingeJoint>();
_constraint = new GameObject("joint").AddComponent<MjJointConstraint>();
_doc = new XmlDocument();
}
[TearDown]
public void TearDown() {
UnityEngine.Object.DestroyImmediate(_constraint.gameObject);
UnityEngine.Object.DestroyImmediate(_joint1.gameObject);
UnityEngine.Object.DestroyImmediate(_joint2.gameObject);
}
[Test]
public void ErrorThrownWhenJoint1Empty() {
// This is an illegal MJCF, but the purpose of this test is to verify that if
// the user didn't assign the joint in the editor, an error will be thrown when play is hit.
_doc.LoadXml("<joint/>");
_constraint.ParseMjcf(_doc.GetElementsByTagName("joint")[0] as XmlElement);
Assert.That(() => { _constraint.GenerateMjcf("name", _doc); }, Throws.Exception);
}
[Test]
public void Joint2Empty() {
_doc.LoadXml("<joint joint1='joint1'/>");
_constraint.ParseMjcf(_doc.GetElementsByTagName("joint")[0] as XmlElement);
_constraint.GenerateMjcf("name", _doc);
}
[Test]
public void ParseAllSettings() {
_doc.LoadXml("<joint joint1='joint1' joint2='joint2'/>");
_constraint.ParseMjcf(_doc.GetElementsByTagName("joint")[0] as XmlElement);
Assert.That(_constraint.Joint1, Is.EqualTo(_joint1));
Assert.That(_constraint.Joint2, Is.EqualTo(_joint2));
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: f27eef27742fe44898f332fc7bff870e
timeCreated: 1552309373
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,69 @@
// Copyright 2019 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.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Xml;
using NUnit.Framework;
using UnityEngine;
namespace Mujoco {
[TestFixture]
public class MjTendonConstraintTests {
private MjFixedTendon _tendon1;
private MjFixedTendon _tendon2;
private MjTendonConstraint _constraint;
private XmlDocument _doc;
[SetUp]
public void SetUp() {
_tendon1 = new GameObject("tendon1").AddComponent<MjFixedTendon>();
_tendon2 = new GameObject("tendon2").AddComponent<MjFixedTendon>();
_constraint = new GameObject("tendon").AddComponent<MjTendonConstraint>();
_doc = new XmlDocument();
}
[TearDown]
public void TearDown() {
UnityEngine.Object.DestroyImmediate(_constraint.gameObject);
UnityEngine.Object.DestroyImmediate(_tendon1.gameObject);
UnityEngine.Object.DestroyImmediate(_tendon2.gameObject);
}
[Test]
public void ErrorThrownWhenTendon1Empty() {
// This is an illegal MJCF, but the purpose of this test is to verify that if
// the user didn't assign the tendon in the editor, an error will be thrown when play is hit.
_doc.LoadXml("<tendon/>");
_constraint.ParseMjcf(_doc.GetElementsByTagName("tendon")[0] as XmlElement);
Assert.That(() => { _constraint.GenerateMjcf("name", _doc); }, Throws.Exception);
}
[Test]
public void Tendon2Empty() {
_doc.LoadXml("<tendon tendon1='tendon1'/>");
_constraint.ParseMjcf(_doc.GetElementsByTagName("tendon")[0] as XmlElement);
_constraint.GenerateMjcf("name", _doc);
}
[Test]
public void ParseAllSettings() {
_doc.LoadXml("<tendon tendon1='tendon1' tendon2='tendon2'/>");
_constraint.ParseMjcf(_doc.GetElementsByTagName("tendon")[0] as XmlElement);
Assert.That(_constraint.Tendon1, Is.EqualTo(_tendon1));
Assert.That(_constraint.Tendon2, Is.EqualTo(_tendon2));
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: dc3cafd0739674e46a797243aab71e50
timeCreated: 1552310856
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,80 @@
// Copyright 2019 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.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Xml;
using NUnit.Framework;
using UnityEngine;
namespace Mujoco {
[TestFixture]
public class MjWeldTests {
private MjBody _body1;
private MjBody _body2;
private MjWeld _constraint;
private XmlDocument _doc;
[SetUp]
public void SetUp() {
_body1 = new GameObject("body1").AddComponent<MjBody>();
_body2 = new GameObject("body2").AddComponent<MjBody>();
_constraint = new GameObject("weld").AddComponent<MjWeld>();
_doc = new XmlDocument();
}
[TearDown]
public void TearDown() {
UnityEngine.Object.DestroyImmediate(_constraint.gameObject);
UnityEngine.Object.DestroyImmediate(_body1.gameObject);
UnityEngine.Object.DestroyImmediate(_body2.gameObject);
}
[Test]
public void ParseXML() {
_doc.LoadXml("<weld body1='body1' body2='body2'/>");
_constraint.ParseMjcf(_doc.GetElementsByTagName("weld")[0] as XmlElement);
Assert.That(_constraint.Body1, Is.EqualTo(_body1));
Assert.That(_constraint.Body2, Is.EqualTo(_body2));
}
[Test]
public void GenerateXML() {
_constraint.Body1 = _body1;
_constraint.Body2 = _body2;
var mjcf = _constraint.GenerateMjcf("name", _doc);
Assert.That(mjcf.OuterXml, Does.Contain("<weld"));
Assert.That(mjcf.OuterXml, Does.Contain("body1=\""));
Assert.That(mjcf.OuterXml, Does.Contain("body2=\""));
}
[Test]
public void ErrorThrownWhenBody1Empty() {
// This is an illegal MJCF, but the purpose of this test is to verify that if
// the user didn't assign the body in the editor, an error will be thrown when play is hit.
_doc.LoadXml("<weld/>");
_constraint.ParseMjcf(_doc.GetElementsByTagName("weld")[0] as XmlElement);
Assert.That(() => { _constraint.GenerateMjcf("name", _doc); }, Throws.Exception);
}
// In this constraint both elements are required.
[Test]
public void ErrorThrownWhenBody2Empty() {
_doc.LoadXml("<weld body1='body1'/>");
_constraint.ParseMjcf(_doc.GetElementsByTagName("weld")[0] as XmlElement);
Assert.That(() => { _constraint.GenerateMjcf("name", _doc); }, Throws.Exception);
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 1482bf1eedf014e1bb156598b3e32f8e
timeCreated: 1550663177
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: