Initial release of the Unity plugin.
PiperOrigin-RevId: 425947505
This commit is contained in:
committed by
Saran Tunyasuvunakool
parent
8ec3dd97a4
commit
6de9eafa13
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e45a6008183fa3804aa9daf9b921c48d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,88 @@
|
||||
// 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;
|
||||
using UnityEngine.TestTools.Utils;
|
||||
|
||||
namespace Mujoco {
|
||||
|
||||
[TestFixture]
|
||||
public class MjBodyTransformTests {
|
||||
|
||||
private GameObject _parent;
|
||||
private MjBody _body;
|
||||
private XmlDocument _doc;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_parent = new GameObject("parent");
|
||||
_body = new GameObject("body", typeof(MjBody)).GetComponent<MjBody>();
|
||||
_body.transform.parent = _parent.transform;
|
||||
_doc = new XmlDocument();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
GameObject.DestroyImmediate(_body.gameObject);
|
||||
GameObject.DestroyImmediate(_parent);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RelativePositionUsedInMjcf() {
|
||||
_parent.transform.position = new Vector3(1, 2, 3);
|
||||
_parent.transform.rotation = Quaternion.AngleAxis(45.0f, (new Vector3(1, 2, 3)).normalized);
|
||||
var element = _doc.AppendChild(_body.GenerateMjcf("name", _doc)) as XmlElement;
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"pos=""1 3 2"""));
|
||||
Assert.That(
|
||||
element.GetQuaternionAttribute("quat", Quaternion.identity),
|
||||
Is.EqualTo(new Quaternion(w:-0.9238795f, x:0.1022765f, y:0.3068294f, z:0.2045529f))
|
||||
.Using(new Vector4EqualityComparer(1e-4f)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LocalPositionParsing() {
|
||||
var bodyElement = (XmlElement)_doc.AppendChild(_doc.CreateElement("body"));
|
||||
bodyElement.SetAttribute("pos", "1 2 3");
|
||||
_body.ParseMjcf(bodyElement);
|
||||
Assert.That(_body.transform.localPosition, Is.EqualTo(new Vector3(1, 3, 2)));
|
||||
}
|
||||
|
||||
[TestCase(0.866f, 0.5f, 0, 0, 0.5f, 0, 0, -0.866f)]
|
||||
[TestCase(0.866f, 0, 0.5f, 0, 0, 0, 0.5f, -0.866f)]
|
||||
[TestCase(0.866f, 0, 0, 0.5f, 0, 0.5f, 0, -0.866f)]
|
||||
[TestCase(0, 0.866f, 0.5f, 0, 0.866f, 0, 0.5f, 0)]
|
||||
[TestCase(0, 0.866f, 0, 0.5f, 0.866f, 0.5f, 0, 0)]
|
||||
[TestCase(0, 0, 0.866f, 0.5f, 0, 0.5f, 0.866f, 0)]
|
||||
public void BodyLocalRotationParsing(
|
||||
float ix, float iy, float iz, float iw, float ex, float ey, float ez, float ew) {
|
||||
var bodyElement = (XmlElement)_doc.AppendChild(_doc.CreateElement("body"));
|
||||
bodyElement.SetAttribute("quat", $"{ix} {iy} {iz} {iw}");
|
||||
_body.ParseMjcf(bodyElement);
|
||||
var angle = Quaternion.Angle(_body.transform.localRotation, new Quaternion(ex, ey, ez, ew));
|
||||
Assert.That(angle, Is.EqualTo(0).Within(3));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParsingDefaultRotation() {
|
||||
var bodyElement = (XmlElement)_doc.AppendChild(_doc.CreateElement("body"));
|
||||
_body.ParseMjcf(bodyElement);
|
||||
Assert.That(_body.transform.localRotation, Is.EqualTo(Quaternion.identity));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d682a3aa23e0740fe8fc6e00ba1b0e53
|
||||
timeCreated: 1537462858
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3483f37c29faced05bc1ddd810a7911d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
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 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:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 14dbadfe71f022782b39f72eec43ca8f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
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 MjBallJointTests {
|
||||
|
||||
private GameObject _parent;
|
||||
private MjBallJoint _joint;
|
||||
private XmlDocument _doc;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_parent = new GameObject("parent");
|
||||
_joint = new GameObject("joint").AddComponent<MjBallJoint>();
|
||||
_joint.transform.parent = _parent.transform;
|
||||
_doc = new XmlDocument();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
GameObject.DestroyImmediate(_parent);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ComponentWorldPositionConvertedToMjCoordinates() {
|
||||
_joint.transform.position = new Vector3(1, 2, 3);
|
||||
_doc.AppendChild(_joint.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"pos=""1 3 2"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenerateLimits() {
|
||||
_joint.RangeUpper = 10;
|
||||
_doc.AppendChild(_joint.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"range=""0 10"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParsingPosition() {
|
||||
var jointElement = (XmlElement)_doc.AppendChild(_doc.CreateElement("joint"));
|
||||
jointElement.SetAttribute("pos", "1 2 3");
|
||||
_joint.ParseMjcf(jointElement);
|
||||
Assert.That(_joint.transform.localPosition, Is.EqualTo(new Vector3(1, 3, 2)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParsingJointLimitRangeSettings() {
|
||||
var jointElement = (XmlElement)_doc.AppendChild(_doc.CreateElement("joint"));
|
||||
jointElement.SetAttribute("range", "0 10");
|
||||
_joint.ParseMjcf(jointElement);
|
||||
Assert.That(_joint.RangeUpper, Is.EqualTo(10));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 76c34ae488142477588dcd6231bb0386
|
||||
timeCreated: 1552057103
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,77 @@
|
||||
// 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;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
namespace Mujoco {
|
||||
|
||||
[TestFixture]
|
||||
public class MjBaseJointTests {
|
||||
|
||||
public class FakeJoint : MjBaseJoint {
|
||||
protected override void OnParseMjcf(XmlElement mjcf) {}
|
||||
|
||||
protected override XmlElement OnGenerateMjcf(XmlDocument doc) {
|
||||
return (XmlElement)doc.CreateElement("joint");
|
||||
}
|
||||
}
|
||||
|
||||
private FakeJoint _joint;
|
||||
private MjBaseBody _parent;
|
||||
private MjBaseBody _grandParent;
|
||||
|
||||
[Test]
|
||||
public void RetrievingBodiesConnectedByTheJoint() {
|
||||
_joint = new GameObject("joint").AddComponent<FakeJoint>();
|
||||
_parent = new GameObject("parent").AddComponent<MjBody>();
|
||||
_grandParent = new GameObject("grandParent").AddComponent<MjBody>();
|
||||
|
||||
_joint.transform.parent = _parent.transform;
|
||||
_parent.transform.parent = _grandParent.transform;
|
||||
|
||||
MjBaseBody grandParent, parent;
|
||||
_joint.GetConnectedBodies(out grandParent, out parent);
|
||||
Assert.That(grandParent, Is.EqualTo(_grandParent));
|
||||
Assert.That(parent, Is.EqualTo(_parent));
|
||||
|
||||
GameObject.DestroyImmediate(_joint.gameObject);
|
||||
GameObject.DestroyImmediate(_parent.gameObject);
|
||||
GameObject.DestroyImmediate(_grandParent.gameObject);
|
||||
GameObject.DestroyImmediate(MjScene.Instance);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RetrievingBodiesConnectedToTheWorld() {
|
||||
_joint = new GameObject("joint").AddComponent<FakeJoint>();
|
||||
_parent = new GameObject("parent").AddComponent<MjBody>();
|
||||
|
||||
_joint.transform.parent = _parent.transform;
|
||||
|
||||
MjBaseBody grandParent, parent;
|
||||
_joint.GetConnectedBodies(out grandParent, out parent);
|
||||
Assert.That(grandParent, Is.Null);
|
||||
Assert.That(parent, Is.EqualTo(_parent));
|
||||
|
||||
GameObject.DestroyImmediate(_joint.gameObject);
|
||||
GameObject.DestroyImmediate(_parent.gameObject);
|
||||
GameObject.DestroyImmediate(MjScene.Instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 61b458a2c0d3a4c54a2ead000ba4b32e
|
||||
timeCreated: 1538412731
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,102 @@
|
||||
// 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;
|
||||
using UnityEngine.TestTools.Utils;
|
||||
|
||||
namespace Mujoco {
|
||||
|
||||
[TestFixture]
|
||||
public class MjHingeJointTests {
|
||||
|
||||
private GameObject _parent;
|
||||
private MjHingeJoint _joint;
|
||||
private XmlDocument _doc;
|
||||
private Vector3EqualityComparer _comparer;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_parent = new GameObject("parent");
|
||||
_joint = new GameObject("joint", typeof(MjHingeJoint)).GetComponent<MjHingeJoint>();
|
||||
_joint.transform.parent = _parent.transform;
|
||||
_doc = new XmlDocument();
|
||||
_comparer = new Vector3EqualityComparer(1e-3f);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
GameObject.DestroyImmediate(_parent);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ComponentWorldPositionConvertedToMjCoordinates() {
|
||||
_joint.transform.position = new Vector3(1, 2, 3);
|
||||
_doc.AppendChild(_joint.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"pos=""1 3 2"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestingAnOffsetAxis() {
|
||||
_joint.transform.rotation =
|
||||
Quaternion.AngleAxis(45.0f, Vector3.up);
|
||||
var element = _joint.GenerateMjcf("name", _doc);
|
||||
Assert.That(element.GetVector3Attribute("axis", Vector3.zero),
|
||||
Is.EqualTo(new Vector3(0.7071068f, -0.7071069f, 0)).Using(_comparer));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenerateLimits() {
|
||||
_joint.RangeLower = -20;
|
||||
_joint.RangeUpper = 10;
|
||||
_doc.AppendChild(_joint.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"range=""-20 10"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParsingPosition() {
|
||||
var jointElement = (XmlElement)_doc.AppendChild(_doc.CreateElement("joint"));
|
||||
jointElement.SetAttribute("pos", "1 2 3");
|
||||
_joint.ParseMjcf(jointElement);
|
||||
Assert.That(_joint.transform.localPosition, Is.EqualTo(new Vector3(1, 3, 2)));
|
||||
}
|
||||
|
||||
[TestCase("1 0 0", 1, 0, 0)]
|
||||
[TestCase("0 1 0", 0, 0, 1)]
|
||||
[TestCase("0 0 1", 0, 1, 0)]
|
||||
public void ParsingTranslatesRotationAxisIntoJointRotation(
|
||||
string setting, float rx, float ry, float rz) {
|
||||
var jointElement = (XmlElement)_doc.AppendChild(_doc.CreateElement("joint"));
|
||||
jointElement.SetAttribute("axis", setting);
|
||||
_joint.ParseMjcf(jointElement);
|
||||
Assert.That(_joint.RotationAxis, Is.EqualTo(new Vector3(rx, ry, rz)).Using(_comparer));
|
||||
}
|
||||
|
||||
[TestCase("0 10", 0, 10)]
|
||||
[TestCase("-10 0", -10, 0)]
|
||||
[TestCase("-10 10", -10, 10)]
|
||||
public void ParsingJointLimitRangeSettings(
|
||||
string setting, float expectedLow, float expectedHigh) {
|
||||
var jointElement = (XmlElement)_doc.AppendChild(_doc.CreateElement("joint"));
|
||||
jointElement.SetAttribute("range", setting);
|
||||
_joint.ParseMjcf(jointElement);
|
||||
Assert.That(_joint.RangeLower, Is.EqualTo(expectedLow));
|
||||
Assert.That(_joint.RangeUpper, Is.EqualTo(expectedHigh));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 61d44d0160a1c43e38cb0f9eaebbfa92
|
||||
timeCreated: 1537527115
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,223 @@
|
||||
// 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 MjJointSettingsGenerationTests {
|
||||
|
||||
private MjJointSettings _settings;
|
||||
private XmlDocument _doc;
|
||||
private XmlElement _mjcf;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_settings = new MjJointSettings();
|
||||
_doc = new XmlDocument();
|
||||
_mjcf = (XmlElement)_doc.AppendChild(_doc.CreateElement("joint"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DampingMjcf() {
|
||||
_settings.Spring.Damping = 5;
|
||||
_settings.Spring.ToMjcf(_mjcf);
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"damping=""5"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FrictionLossMjcf() {
|
||||
_settings.Solver.FrictionLoss = 5;
|
||||
_settings.Solver.ToMjcf(_mjcf);
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"frictionloss=""5"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void StiffnessMjcf() {
|
||||
_settings.Spring.Stiffness = 5;
|
||||
_settings.Spring.ToMjcf(_mjcf);
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"stiffness=""5"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SpringDamperSettingsMjcf() {
|
||||
_settings.Spring.TimeConstant = 5;
|
||||
_settings.Spring.DampingRatio = 6;
|
||||
_settings.ToMjcf(_mjcf);
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"springdamper=""5 6"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SpringEquilibriumPoseMjcf() {
|
||||
_settings.Spring.EquilibriumPose = 5;
|
||||
_settings.Spring.ToMjcf(_mjcf);
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"springref=""5"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ArmatureMjcf() {
|
||||
_settings.Armature = 3;
|
||||
_settings.ToMjcf(_mjcf);
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"armature=""3"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SolverRefLimitMjcf() {
|
||||
_settings.Solver.RefLimit = new SolverReference() { TimeConst = 5, DampRatio = 6 };
|
||||
_settings.ToMjcf(_mjcf);
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"solreflimit=""5 6"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SolverImpLimitMjcf() {
|
||||
_settings.Solver.ImpLimit = new SolverImpedance() {
|
||||
DMin = 5, DMax = 6, Width = 7, Midpoint = 8, Power = 9 };
|
||||
_settings.ToMjcf(_mjcf);
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"solimplimit=""5 6 7 8 9"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SolverRefFrictionMjcf() {
|
||||
_settings.Solver.RefFriction = new SolverReference() { TimeConst = 5, DampRatio = 6 };
|
||||
_settings.ToMjcf(_mjcf);
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"solreffriction=""5 6"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SolverImpFrictionMjcf() {
|
||||
_settings.Solver.ImpFriction = new SolverImpedance() {
|
||||
DMin = 5, DMax = 6, Width = 7, Midpoint = 8, Power = 9 };
|
||||
_settings.ToMjcf(_mjcf);
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"solimpfriction=""5 6 7 8 9"""));
|
||||
}
|
||||
}
|
||||
|
||||
[TestFixture]
|
||||
public class MjJointSettingsParsingTests {
|
||||
|
||||
private MjJointSettings _settings;
|
||||
private XmlDocument _doc;
|
||||
private XmlElement _mjcf;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_doc = new XmlDocument();
|
||||
_mjcf = (XmlElement)_doc.AppendChild(_doc.CreateElement("joint"));
|
||||
_settings = new MjJointSettings();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DampingMjcf() {
|
||||
_mjcf.SetAttribute("damping", "5");
|
||||
_settings.FromMjcf(_mjcf);
|
||||
Assert.That(_settings.Spring.Damping, Is.EqualTo(5));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ArmatureMjcf() {
|
||||
_mjcf.SetAttribute("armature", "3");
|
||||
_settings.FromMjcf(_mjcf);
|
||||
Assert.That(_settings.Armature, Is.EqualTo(3));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FrictionLossMjcf() {
|
||||
_mjcf.SetAttribute("frictionloss", "5");
|
||||
_settings.FromMjcf(_mjcf);
|
||||
Assert.That(_settings.Solver.FrictionLoss, Is.EqualTo(5));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void StiffnessMjcf() {
|
||||
_mjcf.SetAttribute("stiffness", "5");
|
||||
_settings.FromMjcf(_mjcf);
|
||||
Assert.That(_settings.Spring.Stiffness, Is.EqualTo(5));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SpringDamperSettingsMjcf() {
|
||||
_mjcf.SetAttribute("springdamper", "5 6");
|
||||
_settings.FromMjcf(_mjcf);
|
||||
Assert.That(_settings.Spring.TimeConstant, Is.EqualTo(5));
|
||||
Assert.That(_settings.Spring.DampingRatio, Is.EqualTo(6));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SpringEquilibriumPoseMjcf() {
|
||||
_mjcf.SetAttribute("springref", "5");
|
||||
_settings.FromMjcf(_mjcf);
|
||||
Assert.That(_settings.Spring.EquilibriumPose, Is.EqualTo(5));
|
||||
}
|
||||
|
||||
[TestCase("true", true)]
|
||||
[TestCase("false", false)]
|
||||
public void ParsingJointLimitSettings(string setting, bool expected) {
|
||||
_mjcf.SetAttribute("limited", setting);
|
||||
_settings.FromMjcf(_mjcf);
|
||||
Assert.That(_settings.Solver.Limited, Is.EqualTo(expected));
|
||||
}
|
||||
|
||||
[TestCase("1", 1)]
|
||||
[TestCase("-5", -5)]
|
||||
public void ParsingJointLimitMarginSettings(string setting, float expected) {
|
||||
_mjcf.SetAttribute("margin", setting);
|
||||
_settings.FromMjcf(_mjcf);
|
||||
Assert.That(_settings.Solver.Margin, Is.EqualTo(expected));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SolverRefLimitMjcf() {
|
||||
_mjcf.SetAttribute("solreflimit", "5 6");
|
||||
_settings.FromMjcf(_mjcf);
|
||||
Assert.That(_settings.Solver.RefLimit.TimeConst, Is.EqualTo(5));
|
||||
Assert.That(_settings.Solver.RefLimit.DampRatio, Is.EqualTo(6));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SolverImpLimitMjcf() {
|
||||
_mjcf.SetAttribute("solimplimit", "5 6 7 8 9");
|
||||
_settings.FromMjcf(_mjcf);
|
||||
Assert.That(_settings.Solver.ImpLimit.DMin, Is.EqualTo(5));
|
||||
Assert.That(_settings.Solver.ImpLimit.DMax, Is.EqualTo(6));
|
||||
Assert.That(_settings.Solver.ImpLimit.Width, Is.EqualTo(7));
|
||||
Assert.That(_settings.Solver.ImpLimit.Midpoint, Is.EqualTo(8));
|
||||
Assert.That(_settings.Solver.ImpLimit.Power, Is.EqualTo(9));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SolverRefFrictionMjcf() {
|
||||
_mjcf.SetAttribute("solreffriction", "5 6");
|
||||
_settings.FromMjcf(_mjcf);
|
||||
Assert.That(_settings.Solver.RefFriction.TimeConst, Is.EqualTo(5));
|
||||
Assert.That(_settings.Solver.RefFriction.DampRatio, Is.EqualTo(6));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SolverImpFrictionMjcf() {
|
||||
_mjcf.SetAttribute("solimpfriction", "5 6 7 8 9");
|
||||
_settings.FromMjcf(_mjcf);
|
||||
Assert.That(_settings.Solver.ImpFriction.DMin, Is.EqualTo(5));
|
||||
Assert.That(_settings.Solver.ImpFriction.DMax, Is.EqualTo(6));
|
||||
Assert.That(_settings.Solver.ImpFriction.Width, Is.EqualTo(7));
|
||||
Assert.That(_settings.Solver.ImpFriction.Midpoint, Is.EqualTo(8));
|
||||
Assert.That(_settings.Solver.ImpFriction.Power, Is.EqualTo(9));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 05670ca69732c47f58a7a6f61510efad
|
||||
timeCreated: 1539945962
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,102 @@
|
||||
// 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;
|
||||
using UnityEngine.TestTools.Utils;
|
||||
|
||||
namespace Mujoco {
|
||||
|
||||
[TestFixture]
|
||||
public class MjSlideJointTests {
|
||||
|
||||
private GameObject _parent;
|
||||
private MjSlideJoint _joint;
|
||||
private XmlDocument _doc;
|
||||
private Vector3EqualityComparer _comparer;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_parent = new GameObject("parent");
|
||||
_joint = new GameObject("joint", typeof(MjSlideJoint)).GetComponent<MjSlideJoint>();
|
||||
_joint.transform.parent = _parent.transform;
|
||||
_doc = new XmlDocument();
|
||||
_comparer = new Vector3EqualityComparer(1e-3f);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
GameObject.DestroyImmediate(_parent);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ComponentWorldPositionConvertedToMjCoordinates() {
|
||||
_joint.transform.position = new Vector3(1, 2, 3);
|
||||
_doc.AppendChild(_joint.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"pos=""1 3 2"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenerateLimits() {
|
||||
_joint.RangeLower = -20;
|
||||
_joint.RangeUpper = 10;
|
||||
_doc.AppendChild(_joint.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"range=""-20 10"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestingAnOffsetAxis() {
|
||||
_joint.transform.rotation =
|
||||
Quaternion.AngleAxis(45.0f, Vector3.up);
|
||||
var element = _joint.GenerateMjcf("name", _doc);
|
||||
Assert.That(element.GetVector3Attribute("axis", Vector3.zero),
|
||||
Is.EqualTo(new Vector3(0.7071068f, -0.7071069f, 0)).Using(_comparer));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParsingPosition() {
|
||||
var jointElement = (XmlElement)_doc.AppendChild(_doc.CreateElement("joint"));
|
||||
jointElement.SetAttribute("pos", "1 2 3");
|
||||
_joint.ParseMjcf(jointElement);
|
||||
Assert.That(_joint.transform.localPosition, Is.EqualTo(new Vector3(1, 3, 2)));
|
||||
}
|
||||
|
||||
[TestCase("1 0 0", 1, 0, 0)]
|
||||
[TestCase("0 1 0", 0, 0, 1)]
|
||||
[TestCase("0 0 1", 0, 1, 0)]
|
||||
public void ParsingTranslatesSlidexisIntoJointRotation(
|
||||
string setting, float rx, float ry, float rz) {
|
||||
var jointElement = (XmlElement)_doc.AppendChild(_doc.CreateElement("joint"));
|
||||
jointElement.SetAttribute("axis", setting);
|
||||
_joint.ParseMjcf(jointElement);
|
||||
Assert.That(_joint.SlideAxis, Is.EqualTo(new Vector3(rx, ry, rz)).Using(_comparer));
|
||||
}
|
||||
|
||||
[TestCase("0 10", 0, 10)]
|
||||
[TestCase("-10 0", -10, 0)]
|
||||
[TestCase("-10 10", -10, 10)]
|
||||
public void ParsingJointLimitRangeSettings(
|
||||
string setting, float expectedLow, float expectedHigh) {
|
||||
var jointElement = (XmlElement)_doc.AppendChild(_doc.CreateElement("joint"));
|
||||
jointElement.SetAttribute("range", setting);
|
||||
_joint.ParseMjcf(jointElement);
|
||||
Assert.That(_joint.RangeLower, Is.EqualTo(expectedLow));
|
||||
Assert.That(_joint.RangeUpper, Is.EqualTo(expectedHigh));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dffb7c2e3d1504bfd8830b6c511732ef
|
||||
timeCreated: 1537806570
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,559 @@
|
||||
// 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 MjActuatorTests {
|
||||
private MjHingeJoint _joint;
|
||||
private MjActuator _actuator;
|
||||
private XmlDocument _doc;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_joint = new GameObject("joint").AddComponent<MjHingeJoint>();
|
||||
_joint.name = "my_joint";
|
||||
_actuator = new GameObject("actuator").AddComponent<MjActuator>();
|
||||
_actuator.Joint = _joint;
|
||||
_doc = new XmlDocument();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
UnityEngine.Object.DestroyImmediate(_actuator.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(_joint.gameObject);
|
||||
}
|
||||
|
||||
[TestCase(true, "true")]
|
||||
[TestCase(false, "false")]
|
||||
public void ControlLimitedFlagMjcf(bool value, string expected) {
|
||||
_actuator.CommonParams.CtrlLimited = value;
|
||||
_doc.AppendChild(_actuator.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"ctrllimited=\"{expected}\""));
|
||||
}
|
||||
|
||||
[TestCase(true, "true")]
|
||||
[TestCase(false, "false")]
|
||||
public void ForceLimitedFlagMjcf(bool value, string expected) {
|
||||
_actuator.CommonParams.ForceLimited = value;
|
||||
_doc.AppendChild(_actuator.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"forcelimited=\"{expected}\""));
|
||||
}
|
||||
|
||||
[TestCase(0, 1, "0 1")]
|
||||
[TestCase(1, 0, "0 1")]
|
||||
public void ControlRangeSortingForMjcf(float min, float max, string expected) {
|
||||
_actuator.CommonParams.CtrlRange = new Vector2(min, max);
|
||||
_doc.AppendChild(_actuator.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"ctrlrange=\"{expected}\""));
|
||||
}
|
||||
|
||||
[TestCase(0, 1, "0 1")]
|
||||
[TestCase(1, 0, "0 1")]
|
||||
public void ForceRangeSortingForMjcf(float min, float max, string expected) {
|
||||
_actuator.CommonParams.ForceRange = new Vector2(min, max);
|
||||
_doc.AppendChild(_actuator.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"forcerange=\"{expected}\""));
|
||||
}
|
||||
|
||||
[TestCase(0, 1, "0 1")]
|
||||
[TestCase(1, 0, "0 1")]
|
||||
public void LengthRangeSortingForMjcf(float min, float max, string expected) {
|
||||
_actuator.CommonParams.LengthRange = new Vector2(min, max);
|
||||
_doc.AppendChild(_actuator.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"lengthrange=\"{expected}\""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GearMjcf() {
|
||||
_actuator.CommonParams.Gear = new List<float>() { 1, 2, 3, 4, 5, 6 };
|
||||
_doc.AppendChild(_actuator.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"gear=\"1 2 3 4 5 6\""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void JointNameMjcf() {
|
||||
_joint.GenerateMjcf("joint_name", _doc);
|
||||
_doc.AppendChild(_actuator.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"joint=\"joint_name\""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParseAllSettings() {
|
||||
_doc.LoadXml(
|
||||
"<general joint=\"my_joint\" ctrllimited=\"true\" forcelimited=\"true\" ctrlrange=\"2 3\" "
|
||||
+ "forcerange=\"4 5\" lengthrange=\"6 7\" gear=\"8 9\"/>");
|
||||
_actuator.ParseMjcf(_doc.GetElementsByTagName("general")[0] as XmlElement);
|
||||
Assert.That(_actuator.CommonParams.CtrlLimited, Is.True);
|
||||
Assert.That(_actuator.CommonParams.ForceLimited, Is.True);
|
||||
Assert.That(_actuator.CommonParams.CtrlRange, Is.EqualTo(new Vector2(2, 3)));
|
||||
Assert.That(_actuator.CommonParams.ForceRange, Is.EqualTo(new Vector2(4, 5)));
|
||||
Assert.That(_actuator.CommonParams.LengthRange, Is.EqualTo(new Vector2(6, 7)));
|
||||
Assert.That(_actuator.CommonParams.Gear, Has.Count.EqualTo(2));
|
||||
Assert.That(_actuator.CommonParams.Gear[0], Is.EqualTo(8));
|
||||
Assert.That(_actuator.CommonParams.Gear[1], Is.EqualTo(9));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParseDefaultSettings() {
|
||||
_doc.LoadXml("<general joint=\"my_joint\"/>");
|
||||
_actuator.ParseMjcf(_doc.GetElementsByTagName("general")[0] as XmlElement);
|
||||
Assert.That(_actuator.CommonParams.CtrlLimited, Is.False);
|
||||
Assert.That(_actuator.CommonParams.ForceLimited, Is.False);
|
||||
Assert.That(_actuator.CommonParams.CtrlRange, Is.EqualTo(Vector2.zero));
|
||||
Assert.That(_actuator.CommonParams.ForceRange, Is.EqualTo(Vector2.zero));
|
||||
Assert.That(_actuator.CommonParams.LengthRange, Is.EqualTo(Vector2.zero));
|
||||
Assert.That(_actuator.CommonParams.Gear, Has.Count.EqualTo(1));
|
||||
Assert.That(_actuator.CommonParams.Gear[0], Is.EqualTo(1));
|
||||
}
|
||||
}
|
||||
|
||||
[TestFixture]
|
||||
public class MjGeneralActuatorTests {
|
||||
private MjHingeJoint _joint;
|
||||
private MjActuator _actuator;
|
||||
private XmlDocument _doc;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_joint = new GameObject("joint").AddComponent<MjHingeJoint>();
|
||||
_joint.name = "my_joint";
|
||||
_actuator = new GameObject("actuator").AddComponent<MjActuator>();
|
||||
_actuator.Type = MjActuator.ActuatorType.General;
|
||||
_actuator.Joint = _joint;
|
||||
_doc = new XmlDocument();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
UnityEngine.Object.DestroyImmediate(_actuator.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(_joint.gameObject);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProperTagNameUsed() {
|
||||
_doc.AppendChild(_actuator.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"<general"));
|
||||
}
|
||||
|
||||
[TestCase(MujocoLib.mjtDyn.mjDYN_NONE, "none")]
|
||||
[TestCase(MujocoLib.mjtDyn.mjDYN_INTEGRATOR, "integrator")]
|
||||
[TestCase(MujocoLib.mjtDyn.mjDYN_FILTER, "filter")]
|
||||
[TestCase(MujocoLib.mjtDyn.mjDYN_MUSCLE, "muscle")]
|
||||
[TestCase(MujocoLib.mjtDyn.mjDYN_USER, "user")]
|
||||
public void DynamicsTypeMjcf(MujocoLib.mjtDyn value, string expected) {
|
||||
_actuator.CustomParams.DynType = value;
|
||||
_doc.AppendChild(_actuator.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"dyntype=\"{expected}\""));
|
||||
}
|
||||
|
||||
[TestCase(MujocoLib.mjtGain.mjGAIN_FIXED, "fixed")]
|
||||
[TestCase(MujocoLib.mjtGain.mjGAIN_MUSCLE, "muscle")]
|
||||
[TestCase(MujocoLib.mjtGain.mjGAIN_USER, "user")]
|
||||
public void GainTypeMjcf(MujocoLib.mjtGain value, string expected) {
|
||||
_actuator.CustomParams.GainType = value;
|
||||
_doc.AppendChild(_actuator.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"gaintype=\"{expected}\""));
|
||||
}
|
||||
|
||||
[TestCase(MujocoLib.mjtBias.mjBIAS_NONE, "none")]
|
||||
[TestCase(MujocoLib.mjtBias.mjBIAS_AFFINE, "affine")]
|
||||
[TestCase(MujocoLib.mjtBias.mjBIAS_MUSCLE, "muscle")]
|
||||
[TestCase(MujocoLib.mjtBias.mjBIAS_USER, "user")]
|
||||
public void BiasTypeMjcf(MujocoLib.mjtBias value, string expected) {
|
||||
_actuator.CustomParams.BiasType = value;
|
||||
_doc.AppendChild(_actuator.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"biastype=\"{expected}\""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DynamicsParamsMjcf() {
|
||||
_actuator.CustomParams.DynPrm = new List<float>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
|
||||
_doc.AppendChild(_actuator.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"dynprm=\"1 2 3 4 5 6 7 8 9 10\""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GainParamsMjcf() {
|
||||
_actuator.CustomParams.GainPrm = new List<float>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
|
||||
_doc.AppendChild(_actuator.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"gainprm=\"1 2 3 4 5 6 7 8 9 10\""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BiasParamsMjcf() {
|
||||
_actuator.CustomParams.BiasPrm = new List<float>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
|
||||
_doc.AppendChild(_actuator.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"biasprm=\"1 2 3 4 5 6 7 8 9 10\""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParseAllSettings() {
|
||||
_doc.LoadXml(
|
||||
"<general joint=\"my_joint\" dyntype=\"integrator\" gaintype=\"muscle\" "
|
||||
+ "biastype=\"affine\" dynprm=\"6\" gainprm=\"7 8\" biasprm=\"9 10 11 12\"/>");
|
||||
_actuator.ParseMjcf(_doc.GetElementsByTagName("general")[0] as XmlElement);
|
||||
Assert.That(_actuator.CustomParams.DynType, Is.EqualTo(MujocoLib.mjtDyn.mjDYN_INTEGRATOR));
|
||||
Assert.That(_actuator.CustomParams.GainType, Is.EqualTo(MujocoLib.mjtGain.mjGAIN_MUSCLE));
|
||||
Assert.That(_actuator.CustomParams.BiasType, Is.EqualTo(MujocoLib.mjtBias.mjBIAS_AFFINE));
|
||||
Assert.That(_actuator.CustomParams.DynPrm, Has.Count.EqualTo(3));
|
||||
Assert.That(_actuator.CustomParams.GainPrm, Has.Count.EqualTo(3));
|
||||
Assert.That(_actuator.CustomParams.BiasPrm, Has.Count.EqualTo(4));
|
||||
Assert.That(_actuator.CustomParams.DynPrm[0], Is.EqualTo(6));
|
||||
Assert.That(_actuator.CustomParams.DynPrm[1], Is.EqualTo(0));
|
||||
Assert.That(_actuator.CustomParams.DynPrm[2], Is.EqualTo(0));
|
||||
Assert.That(_actuator.CustomParams.GainPrm[0], Is.EqualTo(7));
|
||||
Assert.That(_actuator.CustomParams.GainPrm[1], Is.EqualTo(8));
|
||||
Assert.That(_actuator.CustomParams.GainPrm[2], Is.EqualTo(0));
|
||||
Assert.That(_actuator.CustomParams.BiasPrm[0], Is.EqualTo(9));
|
||||
Assert.That(_actuator.CustomParams.BiasPrm[1], Is.EqualTo(10));
|
||||
Assert.That(_actuator.CustomParams.BiasPrm[2], Is.EqualTo(11));
|
||||
Assert.That(_actuator.CustomParams.BiasPrm[3], Is.EqualTo(12));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParseDefaultSettings() {
|
||||
_doc.LoadXml("<general joint=\"my_joint\"/>");
|
||||
_actuator.ParseMjcf(_doc.GetElementsByTagName("general")[0] as XmlElement);
|
||||
Assert.That(_actuator.CustomParams.DynType, Is.EqualTo(MujocoLib.mjtDyn.mjDYN_NONE));
|
||||
Assert.That(_actuator.CustomParams.GainType, Is.EqualTo(MujocoLib.mjtGain.mjGAIN_FIXED));
|
||||
Assert.That(_actuator.CustomParams.BiasType, Is.EqualTo(MujocoLib.mjtBias.mjBIAS_NONE));
|
||||
Assert.That(_actuator.CustomParams.DynPrm, Has.Count.EqualTo(3));
|
||||
Assert.That(_actuator.CustomParams.GainPrm, Has.Count.EqualTo(3));
|
||||
Assert.That(_actuator.CustomParams.BiasPrm, Has.Count.EqualTo(3));
|
||||
Assert.That(_actuator.CustomParams.DynPrm[0], Is.EqualTo(1));
|
||||
Assert.That(_actuator.CustomParams.DynPrm[1], Is.EqualTo(0));
|
||||
Assert.That(_actuator.CustomParams.DynPrm[2], Is.EqualTo(0));
|
||||
Assert.That(_actuator.CustomParams.GainPrm[0], Is.EqualTo(1));
|
||||
Assert.That(_actuator.CustomParams.GainPrm[1], Is.EqualTo(0));
|
||||
Assert.That(_actuator.CustomParams.GainPrm[2], Is.EqualTo(0));
|
||||
Assert.That(_actuator.CustomParams.BiasPrm[0], Is.EqualTo(0));
|
||||
Assert.That(_actuator.CustomParams.BiasPrm[1], Is.EqualTo(0));
|
||||
Assert.That(_actuator.CustomParams.BiasPrm[2], Is.EqualTo(0));
|
||||
}
|
||||
}
|
||||
|
||||
[TestFixture]
|
||||
public class MjPositionActuatorTests {
|
||||
private MjHingeJoint _joint;
|
||||
private MjActuator _actuator;
|
||||
private XmlDocument _doc;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_joint = new GameObject("joint").AddComponent<MjHingeJoint>();
|
||||
_joint.name = "my_joint";
|
||||
_actuator = new GameObject("actuator").AddComponent<MjActuator>();
|
||||
_actuator.Type = MjActuator.ActuatorType.Position;
|
||||
_actuator.Joint = _joint;
|
||||
_doc = new XmlDocument();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
UnityEngine.Object.DestroyImmediate(_actuator.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(_joint.gameObject);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProperTagNameUsed() {
|
||||
_doc.AppendChild(_actuator.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"<position"));
|
||||
}
|
||||
|
||||
[TestCase(3, "3")]
|
||||
[TestCase(-2, "2")]
|
||||
public void BiasParamsMjcf(float value, string expected) {
|
||||
_actuator.CustomParams.Kp = value;
|
||||
_doc.AppendChild(_actuator.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"kp=\"{expected}\""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParseAllSettings() {
|
||||
_doc.LoadXml("<position joint=\"my_joint\" kp=\"2\"/>");
|
||||
_actuator.ParseMjcf(_doc.GetElementsByTagName("position")[0] as XmlElement);
|
||||
Assert.That(_actuator.CustomParams.Kp, Is.EqualTo(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParseDefaultSettings() {
|
||||
_doc.LoadXml("<position joint=\"my_joint\"/>");
|
||||
_actuator.ParseMjcf(_doc.GetElementsByTagName("position")[0] as XmlElement);
|
||||
Assert.That(_actuator.CustomParams.Kp, Is.EqualTo(1));
|
||||
}
|
||||
}
|
||||
|
||||
[TestFixture]
|
||||
public class MjVelocityActuatorTests {
|
||||
private MjHingeJoint _joint;
|
||||
private MjActuator _actuator;
|
||||
private XmlDocument _doc;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_joint = new GameObject("joint").AddComponent<MjHingeJoint>();
|
||||
_joint.name = "my_joint";
|
||||
_actuator = new GameObject("actuator").AddComponent<MjActuator>();
|
||||
_actuator.Type = MjActuator.ActuatorType.Velocity;
|
||||
_actuator.Joint = _joint;
|
||||
_doc = new XmlDocument();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
UnityEngine.Object.DestroyImmediate(_actuator.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(_joint.gameObject);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProperTagNameUsed() {
|
||||
_doc.AppendChild(_actuator.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"<velocity"));
|
||||
}
|
||||
|
||||
[TestCase(3, "3")]
|
||||
[TestCase(-2, "2")]
|
||||
public void BiasParamsMjcf(float value, string expected) {
|
||||
_actuator.CustomParams.Kv = value;
|
||||
_doc.AppendChild(_actuator.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"kv=\"{expected}\""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParseAllSettings() {
|
||||
_doc.LoadXml("<velocity joint=\"my_joint\" kv=\"2\"/>");
|
||||
_actuator.ParseMjcf(_doc.GetElementsByTagName("velocity")[0] as XmlElement);
|
||||
Assert.That(_actuator.CustomParams.Kv, Is.EqualTo(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParseDefaultSettings() {
|
||||
_doc.LoadXml("<velocity joint=\"my_joint\"/>");
|
||||
_actuator.ParseMjcf(_doc.GetElementsByTagName("velocity")[0] as XmlElement);
|
||||
Assert.That(_actuator.CustomParams.Kv, Is.EqualTo(1));
|
||||
}
|
||||
}
|
||||
|
||||
[TestFixture]
|
||||
public class MjCylinderActuatorTests {
|
||||
private MjHingeJoint _joint;
|
||||
private MjActuator _actuator;
|
||||
private XmlDocument _doc;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_joint = new GameObject("joint").AddComponent<MjHingeJoint>();
|
||||
_joint.name = "my_joint";
|
||||
_actuator = new GameObject("actuator").AddComponent<MjActuator>();
|
||||
_actuator.Type = MjActuator.ActuatorType.Cylinder;
|
||||
_actuator.Joint = _joint;
|
||||
_doc = new XmlDocument();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
UnityEngine.Object.DestroyImmediate(_actuator.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(_joint.gameObject);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProperTagNameUsed() {
|
||||
_doc.AppendChild(_actuator.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"<cylinder"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TimeConstantMjcf() {
|
||||
_actuator.CustomParams.CylinderTimeConst = 2.0f;
|
||||
_doc.AppendChild(_actuator.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"timeconst=\"2\""));
|
||||
}
|
||||
|
||||
[TestCase(3, "3")]
|
||||
[TestCase(-2, "2")]
|
||||
public void AreaMjcf(float value, string expected) {
|
||||
_actuator.CustomParams.Area = value;
|
||||
_doc.AppendChild(_actuator.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"area=\"{expected}\""));
|
||||
}
|
||||
|
||||
[TestCase(3, "3")]
|
||||
[TestCase(-2, "2")]
|
||||
public void DiameterMjcf(float value, string expected) {
|
||||
_actuator.CustomParams.Diameter = value;
|
||||
_doc.AppendChild(_actuator.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"diameter=\"{expected}\""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BiasMjcf() {
|
||||
_actuator.CustomParams.Bias = new float[] { 1, 2, 3 };
|
||||
_doc.AppendChild(_actuator.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"bias=\"1 2 3\""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParseAllSettings() {
|
||||
_doc.LoadXml("<cylinder joint=\"my_joint\" timeconst=\"1\" area =\"2\" diameter=\"3\" "
|
||||
+ "bias=\"4 5\"/>");
|
||||
_actuator.ParseMjcf(_doc.GetElementsByTagName("cylinder")[0] as XmlElement);
|
||||
Assert.That(_actuator.CustomParams.CylinderTimeConst, Is.EqualTo(1));
|
||||
Assert.That(_actuator.CustomParams.Area, Is.EqualTo(2));
|
||||
Assert.That(_actuator.CustomParams.Diameter, Is.EqualTo(3));
|
||||
Assert.That(_actuator.CustomParams.Bias, Has.Length.EqualTo(3));
|
||||
Assert.That(_actuator.CustomParams.Bias[0], Is.EqualTo(4));
|
||||
Assert.That(_actuator.CustomParams.Bias[1], Is.EqualTo(5));
|
||||
Assert.That(_actuator.CustomParams.Bias[2], Is.EqualTo(0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParseDefaultSettings() {
|
||||
_doc.LoadXml("<cylinder joint=\"my_joint\"/>");
|
||||
_actuator.ParseMjcf(_doc.GetElementsByTagName("cylinder")[0] as XmlElement);
|
||||
Assert.That(_actuator.CustomParams.CylinderTimeConst, Is.EqualTo(1));
|
||||
Assert.That(_actuator.CustomParams.Area, Is.EqualTo(1));
|
||||
Assert.That(_actuator.CustomParams.Diameter, Is.EqualTo(0));
|
||||
Assert.That(_actuator.CustomParams.Bias, Has.Length.EqualTo(3));
|
||||
Assert.That(_actuator.CustomParams.Bias[0], Is.EqualTo(0));
|
||||
Assert.That(_actuator.CustomParams.Bias[1], Is.EqualTo(0));
|
||||
Assert.That(_actuator.CustomParams.Bias[2], Is.EqualTo(0));
|
||||
}
|
||||
}
|
||||
|
||||
[TestFixture]
|
||||
public class MjMuscleActuatorTests {
|
||||
private MjHingeJoint _joint;
|
||||
private MjActuator _actuator;
|
||||
private XmlDocument _doc;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_joint = new GameObject("joint").AddComponent<MjHingeJoint>();
|
||||
_joint.name = "my_joint";
|
||||
_actuator = new GameObject("actuator").AddComponent<MjActuator>();
|
||||
_actuator.Type = MjActuator.ActuatorType.Muscle;
|
||||
_actuator.Joint = _joint;
|
||||
_doc = new XmlDocument();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
UnityEngine.Object.DestroyImmediate(_actuator.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(_joint.gameObject);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProperTagNameUsed() {
|
||||
_doc.AppendChild(_actuator.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"<muscle"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TimeConstantMjcf() {
|
||||
_actuator.CustomParams.MuscleTimeConst = new Vector2(1, 2);
|
||||
_doc.AppendChild(_actuator.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"timeconst=\"1 2\""));
|
||||
}
|
||||
|
||||
[TestCase(1, 2, "1 2")]
|
||||
[TestCase(2, 1, "1 2")]
|
||||
public void RangeMjcf(float x, float y, string expected) {
|
||||
_actuator.CustomParams.Range = new Vector2(x, y);
|
||||
_doc.AppendChild(_actuator.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"range=\"{expected}\""));
|
||||
}
|
||||
|
||||
[TestCase(-2, "-2")]
|
||||
[TestCase(2, "2")]
|
||||
public void ForceMjcf(float value, string expected) {
|
||||
_actuator.CustomParams.Force = value;
|
||||
_doc.AppendChild(_actuator.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"force=\"{expected}\""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LMinMjcf() {
|
||||
_actuator.CustomParams.LMin = 2.0f;
|
||||
_doc.AppendChild(_actuator.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"lmin=\"2\""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LMaxMjcf() {
|
||||
_actuator.CustomParams.LMin = 3.0f;
|
||||
_doc.AppendChild(_actuator.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"lmin=\"3\""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void VMaxMjcf() {
|
||||
_actuator.CustomParams.VMax = 4.0f;
|
||||
_doc.AppendChild(_actuator.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"vmax=\"4\""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FpMaxMjcf() {
|
||||
_actuator.CustomParams.FpMax = 5.0f;
|
||||
_doc.AppendChild(_actuator.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"fpmax=\"5\""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FvMaxMjcf() {
|
||||
_actuator.CustomParams.FvMax = 6.0f;
|
||||
_doc.AppendChild(_actuator.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"fvmax=\"6\""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParseAllSettings() {
|
||||
_doc.LoadXml(
|
||||
"<muscle joint=\"my_joint\" timeconst=\"1 2\" range =\"3 4\" force=\"5\" scale=\"6\" "
|
||||
+ "lmin=\"7\" lmax=\"8\" vmax=\"9\" fpmax=\"10\" fvmax=\"11\"/>");
|
||||
_actuator.ParseMjcf(_doc.GetElementsByTagName("muscle")[0] as XmlElement);
|
||||
Assert.That(_actuator.CustomParams.MuscleTimeConst, Is.EqualTo(new Vector2(1, 2)));
|
||||
Assert.That(_actuator.CustomParams.Range, Is.EqualTo(new Vector2(3, 4)));
|
||||
Assert.That(_actuator.CustomParams.Force, Is.EqualTo(5));
|
||||
Assert.That(_actuator.CustomParams.Scale, Is.EqualTo(6));
|
||||
Assert.That(_actuator.CustomParams.LMin, Is.EqualTo(7));
|
||||
Assert.That(_actuator.CustomParams.LMax, Is.EqualTo(8));
|
||||
Assert.That(_actuator.CustomParams.VMax, Is.EqualTo(9));
|
||||
Assert.That(_actuator.CustomParams.FpMax, Is.EqualTo(10));
|
||||
Assert.That(_actuator.CustomParams.FvMax, Is.EqualTo(11));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParseDefaultSettings() {
|
||||
_doc.LoadXml("<muscle joint=\"my_joint\"/>");
|
||||
_actuator.ParseMjcf(_doc.GetElementsByTagName("muscle")[0] as XmlElement);
|
||||
Assert.That(_actuator.CustomParams.MuscleTimeConst, Is.EqualTo(new Vector2(0.01f, 0.04f)));
|
||||
Assert.That(_actuator.CustomParams.Range, Is.EqualTo(new Vector2(0.75f, 1.05f)));
|
||||
Assert.That(_actuator.CustomParams.Force, Is.EqualTo(-1));
|
||||
Assert.That(_actuator.CustomParams.Scale, Is.EqualTo(200));
|
||||
Assert.That(_actuator.CustomParams.LMin, Is.EqualTo(0.5f));
|
||||
Assert.That(_actuator.CustomParams.LMax, Is.EqualTo(1.6f));
|
||||
Assert.That(_actuator.CustomParams.VMax, Is.EqualTo(1.5f));
|
||||
Assert.That(_actuator.CustomParams.FpMax, Is.EqualTo(1.3f));
|
||||
Assert.That(_actuator.CustomParams.FvMax, Is.EqualTo(1.2f));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f9f410f3cddf84133a9db8a7226af54f
|
||||
timeCreated: 1547033205
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,54 @@
|
||||
// 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 MjExcludeTests {
|
||||
private MjBody _body1;
|
||||
private MjBody _body2;
|
||||
private MjExclude _exclude;
|
||||
private XmlDocument _doc;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_body1 = new GameObject("body1").AddComponent<MjBody>();
|
||||
_body2 = new GameObject("body2").AddComponent<MjBody>();
|
||||
_exclude = new GameObject("exclude").AddComponent<MjExclude>();
|
||||
_doc = new XmlDocument();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
UnityEngine.Object.DestroyImmediate(_exclude.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(_body1.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(_body2.gameObject);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParseAllSettings() {
|
||||
_doc.LoadXml(
|
||||
"<exclude body1='body1' body2='body2'/>");
|
||||
_exclude.ParseMjcf(_doc.GetElementsByTagName("exclude")[0] as XmlElement);
|
||||
Assert.That(_exclude.Body1, Is.EqualTo(_body1));
|
||||
Assert.That(_exclude.Body2, Is.EqualTo(_body2));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0b6ccb511e4d84261942206958dd2c73
|
||||
timeCreated: 1550588347
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,203 @@
|
||||
// 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 MjGeomSettingsGenerationTests {
|
||||
|
||||
private MjGeomSettings _settings;
|
||||
private XmlDocument _doc;
|
||||
private XmlElement _mjcf;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_settings = new MjGeomSettings();
|
||||
_doc = new XmlDocument();
|
||||
_mjcf = (XmlElement)_doc.AppendChild(_doc.CreateElement("geom"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ContactFilteringTypeMjcf() {
|
||||
_settings.Filtering.Contype = 5;
|
||||
_settings.ToMjcf(_mjcf);
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"contype=""5"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ContactFilteringAffinityMjcf() {
|
||||
_settings.Filtering.Conaffinity = 5;
|
||||
_settings.ToMjcf(_mjcf);
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"conaffinity=""5"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ContactFilteringGroupMjcf() {
|
||||
_settings.Filtering.Group = 5;
|
||||
_settings.ToMjcf(_mjcf);
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"group=""5"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SolverContactDimensionalityMjcf() {
|
||||
_settings.Solver.ConDim = 5;
|
||||
_settings.ToMjcf(_mjcf);
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"condim=""5"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SolverMixMjcf() {
|
||||
_settings.Solver.SolMix = 5;
|
||||
_settings.ToMjcf(_mjcf);
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"solmix=""5"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SolverReferenceMjcf() {
|
||||
_settings.Solver.SolRef.TimeConst = 5;
|
||||
_settings.Solver.SolRef.DampRatio = 6;
|
||||
_settings.ToMjcf(_mjcf);
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"solref=""5 6"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SolverImpendanceMjcf() {
|
||||
_settings.Solver.SolImp.DMin = 5;
|
||||
_settings.Solver.SolImp.DMax = 6;
|
||||
_settings.Solver.SolImp.Width = 7;
|
||||
_settings.ToMjcf(_mjcf);
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"solimp=""5 6 7"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SolverMarginMjcf() {
|
||||
_settings.Solver.Margin = 5;
|
||||
_settings.ToMjcf(_mjcf);
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"margin=""5"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SolverGapMjcf() {
|
||||
_settings.Solver.Gap = 5;
|
||||
_settings.ToMjcf(_mjcf);
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"gap=""5"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MaterialFrictionMjcf() {
|
||||
_settings.Friction.Sliding = 5;
|
||||
_settings.Friction.Torsional = 6;
|
||||
_settings.Friction.Rolling = 7;
|
||||
_settings.ToMjcf(_mjcf);
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"friction=""5 6 7"""));
|
||||
}
|
||||
}
|
||||
|
||||
[TestFixture]
|
||||
public class MjGeomSettingsParsingTests {
|
||||
|
||||
private MjGeomSettings _settings;
|
||||
private XmlDocument _doc;
|
||||
private XmlElement _mjcf;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_doc = new XmlDocument();
|
||||
_mjcf = (XmlElement)_doc.AppendChild(_doc.CreateElement("geom"));
|
||||
_settings = new MjGeomSettings();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ContactFilteringTypeMjcf() {
|
||||
_mjcf.SetAttribute("contype", "5");
|
||||
_settings.FromMjcf(_mjcf);
|
||||
Assert.That(_settings.Filtering.Contype, Is.EqualTo(5));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ContactFilteringAffinityMjcf() {
|
||||
_mjcf.SetAttribute("conaffinity", "5");
|
||||
_settings.FromMjcf(_mjcf);
|
||||
Assert.That(_settings.Filtering.Conaffinity, Is.EqualTo(5));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ContactFilteringGroupMjcf() {
|
||||
_mjcf.SetAttribute("group", "5");
|
||||
_settings.FromMjcf(_mjcf);
|
||||
Assert.That(_settings.Filtering.Group, Is.EqualTo(5));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SolverContactDimensionalityMjcf() {
|
||||
_mjcf.SetAttribute("condim", "5");
|
||||
_settings.FromMjcf(_mjcf);
|
||||
Assert.That(_settings.Solver.ConDim, Is.EqualTo(5));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SolverMixMjcf() {
|
||||
_mjcf.SetAttribute("solmix", "5");
|
||||
_settings.FromMjcf(_mjcf);
|
||||
Assert.That(_settings.Solver.SolMix, Is.EqualTo(5));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SolverReferenceMjcf() {
|
||||
_mjcf.SetAttribute("solref", "5 6");
|
||||
_settings.FromMjcf(_mjcf);
|
||||
Assert.That(_settings.Solver.SolRef.TimeConst, Is.EqualTo(5));
|
||||
Assert.That(_settings.Solver.SolRef.DampRatio, Is.EqualTo(6));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SolverImpendanceMjcf() {
|
||||
_mjcf.SetAttribute("solimp", "5 6 7");
|
||||
_settings.FromMjcf(_mjcf);
|
||||
Assert.That(_settings.Solver.SolImp.DMin, Is.EqualTo(5));
|
||||
Assert.That(_settings.Solver.SolImp.DMax, Is.EqualTo(6));
|
||||
Assert.That(_settings.Solver.SolImp.Width, Is.EqualTo(7));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SolverMarginMjcf() {
|
||||
_mjcf.SetAttribute("margin", "5");
|
||||
_settings.FromMjcf(_mjcf);
|
||||
Assert.That(_settings.Solver.Margin, Is.EqualTo(5));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SolverGapMjcf() {
|
||||
_mjcf.SetAttribute("gap", "5");
|
||||
_settings.FromMjcf(_mjcf);
|
||||
Assert.That(_settings.Solver.Gap, Is.EqualTo(5));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MaterialFrictionMjcf() {
|
||||
_mjcf.SetAttribute("friction", "5 6 7");
|
||||
_settings.FromMjcf(_mjcf);
|
||||
Assert.That(_settings.Friction.Sliding, Is.EqualTo(5));
|
||||
Assert.That(_settings.Friction.Torsional, Is.EqualTo(6));
|
||||
Assert.That(_settings.Friction.Rolling, Is.EqualTo(7));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 83a2b8f3a6ff24e15ac22ec387fe57fc
|
||||
timeCreated: 1539945962
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,207 @@
|
||||
// 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 MjGeomTransformTests {
|
||||
|
||||
private GameObject _parent;
|
||||
private MjGeom _geom;
|
||||
private XmlDocument _doc;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_parent = new GameObject("parent");
|
||||
_geom = new GameObject("geom", typeof(MjGeom)).GetComponent<MjGeom>();
|
||||
_geom.transform.parent = _parent.transform;
|
||||
_doc = new XmlDocument();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
UnityEngine.Object.DestroyImmediate(_geom.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(_parent);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WorldPositionToMjCoordinates() {
|
||||
_geom.transform.position = new Vector3(1, 2, 3);
|
||||
_doc.AppendChild(_geom.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"pos=""1 3 2"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WorldRotationToMjCoordinates() {
|
||||
_geom.transform.rotation = Quaternion.AngleAxis(45.0f, Vector3.up);
|
||||
_doc.AppendChild(_geom.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"quat=""-0.9238795 0 0 0.3826835"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BodyRelativePositionUsedInMjcf() {
|
||||
_parent.transform.position = new Vector3(1, 2, 3);
|
||||
_parent.transform.rotation = Quaternion.AngleAxis(45.0f, (new Vector3(1, 2, 3)).normalized);
|
||||
_doc.AppendChild(_geom.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"pos=""1 3 2"""));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"quat=""-0.9238795 0.1022765 0.3068294 0.2045529"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LocalPositionParsing() {
|
||||
var geomElement = (XmlElement)_doc.AppendChild(_doc.CreateElement("geom"));
|
||||
geomElement.SetAttribute("pos", "1 2 3");
|
||||
_geom.ParseMjcf(geomElement);
|
||||
Assert.That(_geom.transform.localPosition, Is.EqualTo(new Vector3(1, 3, 2)));
|
||||
}
|
||||
|
||||
[TestCase(0.866f, 0.5f, 0, 0, 0.5f, 0, 0, -0.866f)]
|
||||
[TestCase(0.866f, 0, 0.5f, 0, 0, 0, 0.5f, -0.866f)]
|
||||
[TestCase(0.866f, 0, 0, 0.5f, 0, 0.5f, 0, -0.866f)]
|
||||
[TestCase(0, 0.866f, 0.5f, 0, 0.866f, 0, 0.5f, 0)]
|
||||
[TestCase(0, 0.866f, 0, 0.5f, 0.866f, 0.5f, 0, 0)]
|
||||
[TestCase(0, 0, 0.866f, 0.5f, 0, 0.5f, 0.866f, 0)]
|
||||
public void BodyLocalRotationParsing(
|
||||
float ix, float iy, float iz, float iw, float ex, float ey, float ez, float ew) {
|
||||
var geomElement = (XmlElement)_doc.AppendChild(_doc.CreateElement("geom"));
|
||||
geomElement.SetAttribute("quat", $"{ix} {iy} {iz} {iw}");
|
||||
_geom.ParseMjcf(geomElement);
|
||||
var angle = Quaternion.Angle(_geom.transform.localRotation, new Quaternion(ex, ey, ez, ew));
|
||||
Assert.That(angle, Is.EqualTo(0).Within(3));
|
||||
}
|
||||
|
||||
[TestCase("0 0 0 0 0 1", 0, 0, 0, 1)]
|
||||
[TestCase("0 0 0 0 1 0", 0.707f, 0, 0, 0.707f)]
|
||||
[TestCase("0 0 0 1 0 0", 0, 0, -0.707f, 0.707f)]
|
||||
[TestCase("1 0 0 0 0 0", 0, 0, 0.707f, 0.707f)]
|
||||
[TestCase("0 1 0 0 0 0", -0.707f, 0, 0, 0.707f)]
|
||||
[TestCase("0 0 1 0 0 0", 1, 0, 0, 0)]
|
||||
[TestCase("1 0 0 0 0 1", 0, 0, 0.382f, 0.924f)]
|
||||
[TestCase("1 0 0 0 1 0", 0.5f, 0, 0.5f, 0.707f)]
|
||||
public void OrientationSpecifiedUsingFromToParameterIsTheDirectionOfFromToVector(
|
||||
string input, float ex, float ey, float ez, float ew) {
|
||||
var geomElement = (XmlElement)_doc.AppendChild(_doc.CreateElement("geom"));
|
||||
geomElement.SetAttribute("type", "box");
|
||||
geomElement.SetAttribute("fromto", input);
|
||||
_geom.ParseMjcf(geomElement);
|
||||
var angle = Quaternion.Angle(_geom.transform.localRotation, new Quaternion(ex, ey, ez, ew));
|
||||
Assert.That(angle, Is.EqualTo(0).Within(3));
|
||||
}
|
||||
|
||||
[TestCase("0 0 0 0 0 1", 0)]
|
||||
[TestCase("0 0 0 0 0.01 1", 0.573f)]
|
||||
[TestCase("0 0 0 0 -0.01 1", 0.573f)]
|
||||
[TestCase("0 0 0 0 0 -1", 180)]
|
||||
[TestCase("0 0 0 0 0.01 -1", 179.427f)]
|
||||
[TestCase("0 0 0 0 -0.01 -1", 179.427f)]
|
||||
public void TestingFromToRotationsAroundThePoles(string input, float expectedAngle) {
|
||||
var geomElement = (XmlElement)_doc.AppendChild(_doc.CreateElement("geom"));
|
||||
geomElement.SetAttribute("type", "box");
|
||||
geomElement.SetAttribute("fromto", input);
|
||||
_geom.ParseMjcf(geomElement);
|
||||
var transformedForward = _geom.transform.localRotation * Vector3.forward;
|
||||
var angle = Vector3.Angle(transformedForward, Vector3.forward);
|
||||
Assert.That(angle, Is.EqualTo(expectedAngle).Within(1e-3f));
|
||||
}
|
||||
|
||||
[TestCase("0 0 0 0 0 1", 0, 0.5f, 0)]
|
||||
[TestCase("0 0 0 0 1 0", 0, 0, 0.5f)]
|
||||
[TestCase("0 0 0 1 0 0", 0.5f, 0, 0)]
|
||||
[TestCase("1 0 0 0 0 1", 0.5f, 0.5f, 0)]
|
||||
[TestCase("0 1 0 0 0 1", 0, 0.5f, 0.5f)]
|
||||
[TestCase("0 1 0 0 0 1", 0, 0.5f, 0.5f)]
|
||||
public void PositionSpecifiedUsingFromToParameterIsMiddleOfFromToSegment(
|
||||
string input, float x, float y, float z) {
|
||||
var geomElement = (XmlElement)_doc.AppendChild(_doc.CreateElement("geom"));
|
||||
geomElement.SetAttribute("type", "box");
|
||||
geomElement.SetAttribute("fromto", input);
|
||||
_geom.ParseMjcf(geomElement);
|
||||
Assert.That(_geom.transform.localPosition, Is.EqualTo(new Vector3(x, y, z)));
|
||||
}
|
||||
|
||||
[TestCase("0 0 1", 0, 0, 0, 1)]
|
||||
[TestCase("0 1 0", 0.707f, 0, 0, 0.707f)]
|
||||
[TestCase("1 0 0", 0, 0, -0.707f, 0.707f)]
|
||||
public void ZAxisParameterSpecifiesForwardVectorOfGeom(
|
||||
string input, float ex, float ey, float ez, float ew) {
|
||||
var geomElement = (XmlElement)_doc.AppendChild(_doc.CreateElement("geom"));
|
||||
geomElement.SetAttribute("zaxis", input);
|
||||
_geom.ParseMjcf(geomElement);
|
||||
var angle = Quaternion.Angle(_geom.transform.localRotation, new Quaternion(ex, ey, ez, ew));
|
||||
Assert.That(angle, Is.EqualTo(0).Within(3));
|
||||
}
|
||||
|
||||
[TestCase("0 0 90", 0, 0.707f, 0, 0.707f)]
|
||||
[TestCase("0 90 0", 0, 0, -0.707f, 0.707f)]
|
||||
[TestCase("90 0 0", 0.707f, 0, 0, 0.707f)]
|
||||
[TestCase("0 0 45", 0, 0.382f, 0, 0.924f)]
|
||||
[TestCase("0 45 0", 0, 0, -0.382f, 0.924f)]
|
||||
[TestCase("45 0 0", 0.382f, 0, 0, 0.924f)]
|
||||
public void UsingEulerAnglesToSpecifyRotation(
|
||||
string input, float ex, float ey, float ez, float ew) {
|
||||
var geomElement = (XmlElement)_doc.AppendChild(_doc.CreateElement("geom"));
|
||||
geomElement.SetAttribute("euler", input);
|
||||
_geom.ParseMjcf(geomElement);
|
||||
var angle = Quaternion.Angle(_geom.transform.localRotation, new Quaternion(ex, ey, ez, ew));
|
||||
Assert.That(angle, Is.EqualTo(0).Within(3));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NoRotationSpecificationSetsIdentityRotation() {
|
||||
var geomElement = (XmlElement)_doc.AppendChild(_doc.CreateElement("geom"));
|
||||
_geom.ParseMjcf(geomElement);
|
||||
Assert.That(_geom.transform.localRotation, Is.EqualTo(Quaternion.identity));
|
||||
}
|
||||
}
|
||||
|
||||
[TestFixture]
|
||||
public class MjGeomPropertiesSerializingTests {
|
||||
|
||||
private MjGeom _geom;
|
||||
private XmlDocument _doc;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_geom = new GameObject("geom", typeof(MjGeom)).GetComponent<MjGeom>();
|
||||
_doc = new XmlDocument();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
UnityEngine.Object.DestroyImmediate(_geom.gameObject);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MaterialDensityMjcf() {
|
||||
_geom.Density = 5;
|
||||
_doc.AppendChild(_geom.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"density=""5"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MaterialDensityParsing() {
|
||||
var geomElement = (XmlElement)_doc.AppendChild(_doc.CreateElement("geom"));
|
||||
geomElement.SetAttribute("density", "5.2");
|
||||
_geom.ParseMjcf(geomElement);
|
||||
Assert.That(_geom.Density, Is.EqualTo(5.2f));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 626fcf7698e8e484eb8c1f0c2399947d
|
||||
timeCreated: 1537258560
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,197 @@
|
||||
// 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 MjGlobalSettingsGenerationTests {
|
||||
|
||||
private MjGlobalSettings _settings;
|
||||
private XmlDocument _doc;
|
||||
private XmlElement _option;
|
||||
private XmlElement _size;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_settings = new GameObject("settings").AddComponent<MjGlobalSettings>();
|
||||
_doc = new XmlDocument();
|
||||
var root = (XmlElement)_doc.AppendChild(_doc.CreateElement("root"));
|
||||
_option = (XmlElement)root.AppendChild(_doc.CreateElement("option"));
|
||||
_size = (XmlElement)root.AppendChild(_doc.CreateElement("size"));
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
UnityEngine.Object.DestroyImmediate(_settings.gameObject);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenerateOptionAndSize() {
|
||||
_settings.GlobalOptions.ImpRatio = 1.2f;
|
||||
_settings.GlobalOptions.Magnetic = new Vector3(3.4f, 4.5f, 5.6f);
|
||||
_settings.GlobalOptions.Wind = new Vector3(6.7f, 7.8f, 8.9f);
|
||||
_settings.GlobalOptions.Density = 0.1f;
|
||||
_settings.GlobalOptions.Viscosity = 2.3f;
|
||||
_settings.GlobalOptions.OverrideMargin = 4.5f;
|
||||
_settings.GlobalOptions.Integrator = IntegratorType.RK4;
|
||||
_settings.GlobalOptions.Cone = FrictionConeType.elliptic;
|
||||
_settings.GlobalOptions.Jacobian = JacobianType.dense;
|
||||
_settings.GlobalOptions.Solver = ConstraintSolverType.PGS;
|
||||
_settings.GlobalOptions.Iterations = 12;
|
||||
_settings.GlobalOptions.Tolerance = 3.4f;
|
||||
_settings.GlobalOptions.NoSlipIterations = 5;
|
||||
_settings.GlobalOptions.NoSlipTolerance = 6.7f;
|
||||
_settings.GlobalOptions.MprIterations = 8;
|
||||
_settings.GlobalOptions.MprTolerance = 0.9f;
|
||||
_settings.GlobalSizes.Nconmax = 321;
|
||||
|
||||
_settings.OptionSizeToMjcf(_option, _size);
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"impratio=""1.2"""));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"magnetic=""3.4 4.5 5.6"""));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"wind=""6.7 7.8 8.9"""));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"density=""0.1"""));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"viscosity=""2.3"""));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"o_margin=""4.5"""));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"integrator=""RK4"""));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"cone=""elliptic"""));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"collision=""all""")); // the default value.
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"jacobian=""dense"""));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"o_solref="));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"o_solimp="));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"solver=""PGS"""));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"iterations=""12"""));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"tolerance=""3.4"""));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"noslip_iterations=""5"""));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"noslip_tolerance=""6.7"""));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"mpr_iterations=""8"""));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"mpr_tolerance=""0.9"""));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"nconmax=""321"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenerateFlag() {
|
||||
_settings.GlobalOptions.Flag.Gravity = EnableDisableFlag.disable;
|
||||
_settings.OptionSizeToMjcf(_option, _size);
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"gravity=""disable"""));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"constraint="));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"equality="));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"frictionloss="));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"limit="));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"contact="));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"passive="));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"clampctrl="));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"warmstart="));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"filterparent="));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"actuation="));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"refsafe="));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"override="));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"energy="));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"fwdinv="));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"sensornoise="));
|
||||
}
|
||||
}
|
||||
|
||||
[TestFixture]
|
||||
public class MjGlobalSettingsParsingTests {
|
||||
|
||||
private MjGlobalSettings _settings;
|
||||
private XmlElement _option;
|
||||
private XmlElement _size;
|
||||
private XmlElement _flag;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_settings = new GameObject("settings").AddComponent<MjGlobalSettings>();
|
||||
var doc = new XmlDocument();
|
||||
var root = (XmlElement)doc.AppendChild(doc.CreateElement("root"));
|
||||
_option = (XmlElement)root.AppendChild(doc.CreateElement("option"));
|
||||
_size = (XmlElement)root.AppendChild(doc.CreateElement("size"));
|
||||
_flag = (XmlElement)_option.AppendChild(doc.CreateElement("flag"));
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
UnityEngine.Object.DestroyImmediate(_settings.gameObject);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParseSizeOptionAndFlag() {
|
||||
_option.SetAttribute("impratio", "1.2");
|
||||
_option.SetAttribute("magnetic", "3.4 4.5 5.6");
|
||||
_option.SetAttribute("wind", "6.7 7.8 8.9");
|
||||
_option.SetAttribute("density", "0.1");
|
||||
_option.SetAttribute("viscosity", "2.3");
|
||||
_option.SetAttribute("o_margin", "4.5");
|
||||
_option.SetAttribute("integrator", "RK4");
|
||||
_option.SetAttribute("cone", "elliptic");
|
||||
_option.SetAttribute("collisionchecktype", "all");
|
||||
_option.SetAttribute("jacobian", "dense");
|
||||
_option.SetAttribute("solver", "PGS");
|
||||
_option.SetAttribute("iterations", "12");
|
||||
_option.SetAttribute("tolerance", "3.4");
|
||||
_option.SetAttribute("noslip_iterations", "5");
|
||||
_option.SetAttribute("noslip_tolerance", "6.7");
|
||||
_option.SetAttribute("mpr_iterations", "8");
|
||||
_option.SetAttribute("mpr_tolerance", "0.9");
|
||||
|
||||
_flag.SetAttribute("gravity", "disable");
|
||||
|
||||
_size.SetAttribute("nconmax", "432");
|
||||
|
||||
_settings.ParseOptionSizeMjcf(_option, _size);
|
||||
Assert.That(_settings.GlobalOptions.ImpRatio, Is.EqualTo(1.2f));
|
||||
Assert.That(_settings.GlobalOptions.Magnetic, Is.EqualTo(new Vector3(3.4f, 4.5f, 5.6f)));
|
||||
Assert.That(_settings.GlobalOptions.Wind, Is.EqualTo(new Vector3(6.7f, 7.8f, 8.9f)));
|
||||
Assert.That(_settings.GlobalOptions.Density, Is.EqualTo(0.1f));
|
||||
Assert.That(_settings.GlobalOptions.Viscosity, Is.EqualTo(2.3f));
|
||||
Assert.That(_settings.GlobalOptions.OverrideMargin, Is.EqualTo(4.5f));
|
||||
Assert.That(_settings.GlobalOptions.Integrator, Is.EqualTo(IntegratorType.RK4));
|
||||
Assert.That(_settings.GlobalOptions.Cone, Is.EqualTo(FrictionConeType.elliptic));
|
||||
Assert.That(_settings.GlobalOptions.Jacobian, Is.EqualTo(JacobianType.dense));
|
||||
Assert.That(_settings.GlobalOptions.Solver, Is.EqualTo(ConstraintSolverType.PGS));
|
||||
Assert.That(_settings.GlobalOptions.Iterations, Is.EqualTo(12));
|
||||
Assert.That(_settings.GlobalOptions.Tolerance, Is.EqualTo(3.4f));
|
||||
Assert.That(_settings.GlobalOptions.NoSlipIterations, Is.EqualTo(5));
|
||||
Assert.That(_settings.GlobalOptions.NoSlipTolerance, Is.EqualTo(6.7f));
|
||||
Assert.That(_settings.GlobalOptions.MprIterations, Is.EqualTo(8));
|
||||
Assert.That(_settings.GlobalOptions.MprTolerance, Is.EqualTo(0.9f));
|
||||
|
||||
Assert.That(_settings.GlobalOptions.Flag.Gravity, Is.EqualTo(EnableDisableFlag.disable));
|
||||
|
||||
Assert.That(_settings.GlobalSizes.Nconmax, Is.EqualTo(432));
|
||||
// these statements shouldn't fail:
|
||||
_settings.ParseOptionSizeMjcf(_option, null);
|
||||
_settings.ParseOptionSizeMjcf(null, _size);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AvoidMultipleFlagClauses() {
|
||||
var doubleFlagXML = @"<option>
|
||||
<flag/> <flag/>
|
||||
</option>";
|
||||
var doc = new XmlDocument();
|
||||
doc.LoadXml(doubleFlagXML);
|
||||
Assert.That(
|
||||
() => { _settings.ParseOptionSizeMjcf(doc.DocumentElement, null); },
|
||||
Throws.ArgumentException);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 57b08bea18fda4c70a99bc636a13c1f2
|
||||
timeCreated: 1548950233
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,57 @@
|
||||
// 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 MjInertialTests {
|
||||
private MjInertial _inertial;
|
||||
private XmlDocument _doc;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_inertial = new GameObject("inertial").AddComponent<MjInertial>();
|
||||
_doc = new XmlDocument();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
UnityEngine.Object.DestroyImmediate(_inertial.gameObject);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParseAllSettings() {
|
||||
_doc.LoadXml("<inertial mass='5' diaginertia='1 2 3'/>");
|
||||
_inertial.ParseMjcf(_doc.GetElementsByTagName("inertial")[0] as XmlElement);
|
||||
Assert.That(_inertial.Mass, Is.EqualTo(5.0f));
|
||||
Assert.That(_inertial.DiagInertia, Is.EqualTo(new Vector3(1, 3, 2)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenerateMjcf() {
|
||||
_inertial.Mass = 6.0f;
|
||||
_inertial.DiagInertia = new Vector3(7, 8, 9);
|
||||
var mjcf = _inertial.GenerateMjcf("inertial", _doc);
|
||||
Assert.That(mjcf.OuterXml, Does.Contain("mass=\"6\""));
|
||||
Assert.That(mjcf.OuterXml, Does.Contain("diaginertia=\"7 9 8\""));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 49a2df64f659c498aa573ad717200548
|
||||
timeCreated: 1551130256
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,215 @@
|
||||
// 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;
|
||||
using UnityEngine.TestTools.Utils;
|
||||
|
||||
namespace Mujoco {
|
||||
|
||||
[TestFixture]
|
||||
public class MjSceneGenerationTests {
|
||||
|
||||
[Test]
|
||||
public void AssigningComponentsUniqueName() {
|
||||
_fakeBodyA.enabled = true;
|
||||
_fakeBodyB.enabled = true;
|
||||
_scene.CreateScene(skipCompile:true);
|
||||
Assert.That(_fakeBodyA.MujocoName, Is.Not.EqualTo(_fakeBodyB.MujocoName));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AttachingComponentsToMjNodesThroughId() {
|
||||
_fakeBodyA.enabled = true;
|
||||
_fakeBodyB.enabled = true;
|
||||
_scene.CreateScene();
|
||||
Assert.That(_fakeBodyA.MujocoId, Is.GreaterThanOrEqualTo(0));
|
||||
Assert.That(_fakeBodyB.MujocoId, Is.GreaterThanOrEqualTo(0));
|
||||
Assert.That(_fakeBodyA.MujocoId, Is.Not.EqualTo(_fakeBodyB.MujocoId));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public unsafe void ModelStructureIsInitialized() {
|
||||
_fakeBodyA.enabled = true;
|
||||
_fakeBodyB.enabled = true;
|
||||
_scene.CreateScene();
|
||||
Assert.That(_scene.Model->nbody, Is.GreaterThanOrEqualTo(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SyncingComponentStateOnFixedUpdate() {
|
||||
_fakeBodyA.enabled = true;
|
||||
_fakeBodyB.enabled = true;
|
||||
_scene.CreateScene();
|
||||
Assert.That(_fakeBodyA.StateSynced, Is.False);
|
||||
Assert.That(_fakeBodyB.StateSynced, Is.False);
|
||||
_scene.StepScene();
|
||||
Assert.That(_fakeBodyA.StateSynced, Is.True);
|
||||
Assert.That(_fakeBodyB.StateSynced, Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public unsafe void PhysicsRuntimeError() {
|
||||
_scene.CreateScene();
|
||||
_scene.Data->qpos[0] = float.PositiveInfinity;
|
||||
Assert.That(
|
||||
() => { _scene.StepScene(); },
|
||||
Throws.TypeOf<PhysicsRuntimeException>()
|
||||
.With.Message.EqualTo("BADQPOS: NaN/inf in qpos."));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MjcfHierarchyMirrorsTheHierarchyOfUnityObjects() {
|
||||
_fakeBodyA.transform.parent = _fakeBodyB.transform;
|
||||
_fakeBodyA.enabled = true;
|
||||
_fakeBodyB.enabled = true;
|
||||
var mjcf = _scene.CreateScene(skipCompile:true);
|
||||
// Three components are already in this scene: body, joint and inertia (see SetUp function below)
|
||||
var mjcfFakeBodyB = mjcf.SelectNodes("/mujoco/worldbody/body")[1] as XmlElement;
|
||||
var mjcfFakeBodyA = mjcf.SelectNodes("/mujoco/worldbody/body/body")[0] as XmlElement;
|
||||
Assert.That(mjcfFakeBodyA, Is.Not.Null);
|
||||
Assert.That(mjcfFakeBodyB, Is.Not.Null);
|
||||
// B is the parent, so it appears first in the XML
|
||||
Assert.That(mjcfFakeBodyB.GetAttribute("name"), Is.EqualTo("component_3"));
|
||||
Assert.That(mjcfFakeBodyA.GetAttribute("name"), Is.EqualTo("component_4"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ActuatorsAreAddedToDedicatedTag() {
|
||||
_actuator.enabled = true;
|
||||
var mjcf = _scene.CreateScene(skipCompile:true);
|
||||
var mjcfForActuator = mjcf.SelectNodes("/mujoco/actuator/general")[0] as XmlElement;
|
||||
Assert.That(mjcfForActuator, Is.Not.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SensorsAreAddedToDedicatedTag() {
|
||||
_sensor.enabled = true;
|
||||
var mjcf = _scene.CreateScene(skipCompile:true);
|
||||
var mjcfForSensor = mjcf.SelectNodes("/mujoco/sensor/jointpos")[0] as XmlElement;
|
||||
Assert.That(mjcfForSensor, Is.Not.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public unsafe void SceneRecreatedWithAddition() {
|
||||
_scene.CreateScene();
|
||||
_scene.Data->qvel[0] = 1;
|
||||
var nq = _scene.Model->nq;
|
||||
var tickedRotation = _body.transform.rotation;
|
||||
var body = new GameObject("body").AddComponent<MjBody>();
|
||||
var inertia = new GameObject("inertia").AddComponent<MjInertial>();
|
||||
inertia.transform.parent = body.transform;
|
||||
var joint = new GameObject("joint").AddComponent<MjHingeJoint>();
|
||||
joint.transform.parent = body.transform;
|
||||
_scene.RecreateScene();
|
||||
Assert.That(_scene.Model->nq, Is.EqualTo(nq+1));
|
||||
Assert.That(_scene.Data->qvel[joint.DofAddress], Is.EqualTo(0));
|
||||
Assert.That(_scene.Data->qvel[_joint.DofAddress], Is.EqualTo(1));
|
||||
UnityEngine.Object.DestroyImmediate(inertia.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(joint.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(body.gameObject);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public unsafe void SceneRecreatedAfterDeletion() {
|
||||
var body = new GameObject("body").AddComponent<MjBody>();
|
||||
var inertia = new GameObject("inertia").AddComponent<MjInertial>();
|
||||
inertia.transform.parent = body.transform;
|
||||
var joint = new GameObject("joint").AddComponent<MjHingeJoint>();
|
||||
joint.transform.parent = body.transform;
|
||||
_scene.CreateScene();
|
||||
_scene.Data->qvel[0] = 1;
|
||||
_scene.Data->qvel[1] = 2;
|
||||
var nq = _scene.Model->nq;
|
||||
UnityEngine.Object.DestroyImmediate(inertia.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(joint.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(body.gameObject);
|
||||
_scene.RecreateScene();
|
||||
Assert.That(_scene.Model->nq, Is.EqualTo(nq-1));
|
||||
Assert.That(_scene.Data->qvel[0], Is.EqualTo(2));
|
||||
}
|
||||
|
||||
#region Test setup.
|
||||
|
||||
public class FakeMjBody : MjBaseBody {
|
||||
public bool StateSynced = false;
|
||||
|
||||
public override MujocoLib.mjtObj ObjectType => MujocoLib.mjtObj.mjOBJ_BODY;
|
||||
|
||||
protected override void OnParseMjcf(XmlElement mjcf) {}
|
||||
|
||||
protected override XmlElement OnGenerateMjcf(XmlDocument doc) {
|
||||
// We'll create an actual element because the code will then pass it on to Mujoco scene
|
||||
// compiler, and we care that the compiler doesn't fail.
|
||||
var mjcf = doc.CreateElement("body");
|
||||
return mjcf;
|
||||
}
|
||||
|
||||
public override unsafe void OnSyncState(MujocoLib.mjData_* data) {
|
||||
StateSynced = true;
|
||||
}
|
||||
}
|
||||
|
||||
private MjScene _scene;
|
||||
private FakeMjBody _fakeBodyA;
|
||||
private FakeMjBody _fakeBodyB;
|
||||
private MjJointScalarSensor _sensor;
|
||||
private MjBody _body;
|
||||
private MjInertial _inertia;
|
||||
private MjHingeJoint _joint;
|
||||
private MjActuator _actuator;
|
||||
private Vector4EqualityComparer _quaternionComparer;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_quaternionComparer = new Vector4EqualityComparer(1e-5f);
|
||||
_scene = MjScene.Instance;
|
||||
_fakeBodyA = new GameObject("component").AddComponent<FakeMjBody>();
|
||||
_fakeBodyB = new GameObject("component").AddComponent<FakeMjBody>();
|
||||
_sensor = new GameObject("sensor").AddComponent<MjJointScalarSensor>();
|
||||
_actuator = new GameObject("actuator").AddComponent<MjActuator>();
|
||||
// body, joint and inertia are always present so that the actuator and sensor are valid
|
||||
_body = new GameObject("body").AddComponent<MjBody>();
|
||||
_inertia = new GameObject("inertia").AddComponent<MjInertial>();
|
||||
_inertia.transform.parent = _body.transform;
|
||||
_joint = new GameObject("joint").AddComponent<MjHingeJoint>();
|
||||
_joint.transform.parent = _body.transform;
|
||||
_sensor.Joint = _joint;
|
||||
_sensor.SensorType = MjJointScalarSensor.AvailableSensors.JointPos;
|
||||
_actuator.Joint = _joint;
|
||||
_fakeBodyA.enabled = false;
|
||||
_fakeBodyB.enabled = false;
|
||||
_sensor.enabled = false;
|
||||
_actuator.enabled = false;
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
UnityEngine.Object.DestroyImmediate(_fakeBodyA.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(_fakeBodyB.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(_sensor.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(_actuator.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(_joint.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(_inertia.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(_body.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(_scene.gameObject);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d5db1f5b04f4c4ab3b6081481fa45cab
|
||||
timeCreated: 1536939770
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,65 @@
|
||||
// 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 MjSiteEditorTests {
|
||||
|
||||
private MjSite _site;
|
||||
private XmlDocument _doc;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_site = new GameObject("site", typeof(MjSite)).GetComponent<MjSite>();
|
||||
_doc = new XmlDocument();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
GameObject.DestroyImmediate(_site.gameObject);
|
||||
}
|
||||
|
||||
private XmlElement Parse(string mjcfString, string tag) {
|
||||
_doc.LoadXml(mjcfString);
|
||||
var elementList = _doc.GetElementsByTagName(tag);
|
||||
return elementList[0] as XmlElement;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GeneratingShapePropertiesMjcf() {
|
||||
_site.ShapeType = MjShapeComponent.ShapeTypes.Box;
|
||||
_site.Box.Extents = new Vector3(1, 2, 3);
|
||||
_doc.AppendChild(_site.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain("type=\"box\""));
|
||||
Assert.That(_doc.OuterXml, Does.Contain("size=\"1 3 2\""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParsingShapePropertiesMjcf() {
|
||||
var mjcfString = "<site type=\"box\" size=\"1 3 2\"/>";
|
||||
var mjcfElement = Parse(mjcfString, "site");
|
||||
_site.ParseMjcf(mjcfElement);
|
||||
Assert.That(_site.ShapeType, Is.EqualTo(MjShapeComponent.ShapeTypes.Box));
|
||||
Assert.That(_site.Box.Extents, Is.EqualTo(new Vector3(1, 2, 3)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c0e1212bb116746d990a603c60820a7f
|
||||
timeCreated: 1547480369
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,144 @@
|
||||
// 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 MjcfGenerationContextTests {
|
||||
|
||||
[Test]
|
||||
public void ComponentAssignedMujocoName() {
|
||||
var mjcf = _scene.CreateScene(skipCompile:true);
|
||||
Assert.That(mjcf.OuterXml, Does.Contain(
|
||||
@"name=""component_0"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TwoComponentsWithSameNameReceiveDistinctMujocoNames() {
|
||||
var mjcf = _scene.CreateScene(skipCompile:true);
|
||||
Assert.That(mjcf.OuterXml, Does.Contain(
|
||||
@"name=""component_0"""));
|
||||
Assert.That(mjcf.OuterXml, Does.Contain(
|
||||
@"name=""component_1"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GravityVectorIsConvertedToMjWorldReferenceFrame() {
|
||||
Physics.gravity = new Vector3(1, 2, 3);
|
||||
var mjcf = _scene.CreateScene(skipCompile:true);
|
||||
Assert.That(mjcf.OuterXml, Does.Contain("gravity=\"1 3 2\""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConfigurationMjcfSpecifiesTimeout() {
|
||||
var mjcf = _scene.CreateScene(skipCompile:true);
|
||||
Assert.That(mjcf.OuterXml, Does.Contain($"timestep=\"{Time.fixedDeltaTime}\""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConfigurationMjcfSpecifiesCoordinateSystemAsLocal() {
|
||||
var mjcf = _scene.CreateScene(skipCompile:true);
|
||||
Assert.That(mjcf.OuterXml, Does.Contain("coordinate=\"local\""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConfigurationMjcIncludesOptions() {
|
||||
var mjcf = _scene.CreateScene(skipCompile:true);
|
||||
Assert.That(mjcf.OuterXml, Does.Contain("impratio"));
|
||||
Assert.That(mjcf.OuterXml, Does.Contain("magnetic"));
|
||||
Assert.That(mjcf.OuterXml, Does.Contain("wind"));
|
||||
Assert.That(mjcf.OuterXml, Does.Contain("density"));
|
||||
Assert.That(mjcf.OuterXml, Does.Contain("viscosity"));
|
||||
Assert.That(mjcf.OuterXml, Does.Contain("o_margin"));
|
||||
Assert.That(mjcf.OuterXml, Does.Contain("o_solref"));
|
||||
Assert.That(mjcf.OuterXml, Does.Contain("o_solimp"));
|
||||
Assert.That(mjcf.OuterXml, Does.Contain("iterations"));
|
||||
Assert.That(mjcf.OuterXml, Does.Contain("tolerance"));
|
||||
Assert.That(mjcf.OuterXml, Does.Contain("noslip_iterations"));
|
||||
Assert.That(mjcf.OuterXml, Does.Contain("noslip_tolerance"));
|
||||
Assert.That(mjcf.OuterXml, Does.Contain("mpr_iterations"));
|
||||
Assert.That(mjcf.OuterXml, Does.Contain("mpr_tolerance"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AssigningGeneratedMeshAssetsUniqueNames() {
|
||||
var context = new MjcfGenerationContext();
|
||||
var uniqueAssetName = context.AddMeshAsset(mesh: new Mesh());
|
||||
var element = new XmlDocument().CreateElement("test");
|
||||
context.GenerateMjcf(element);
|
||||
var assetNodes = element.SelectNodes($"asset/mesh[@name='{uniqueAssetName}']");
|
||||
Assert.That(assetNodes, Has.Count.EqualTo(1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MeshMjcfIgnoresTriangleConnectivityAndStoredOnlyTheVertexCloud() {
|
||||
var mesh = new Mesh();
|
||||
mesh.vertices = new Vector3[] {
|
||||
new Vector3(1, 0, 0), new Vector3(0, 1, 0), new Vector3(0, 0, 1) };
|
||||
mesh.triangles = new int[] { 0, 1, 2, 2, 1, 0, 1, 0, 2 };
|
||||
var context = new MjcfGenerationContext();
|
||||
context.AddMeshAsset(mesh);
|
||||
var element = new XmlDocument().CreateElement("test");
|
||||
context.GenerateMjcf(element);
|
||||
Assert.That(element.OuterXml, Does.Contain("vertex=\"1 0 0 0 0 1 0 1 0 \""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SettingNUserSensorValuesKeepsTheHigherValue() {
|
||||
var context = new MjcfGenerationContext();
|
||||
context.NUserSensor = 5;
|
||||
context.NUserSensor = 6;
|
||||
context.NUserSensor = 1;
|
||||
Assert.That(context.NUserSensor, Is.EqualTo(6));
|
||||
var element = new XmlDocument().CreateElement("test");
|
||||
context.GenerateMjcf(element);
|
||||
Assert.That(element.OuterXml, Does.Contain("nuser_sensor=\"6\""));
|
||||
}
|
||||
|
||||
#region Test setup.
|
||||
|
||||
private MjBody _componentA;
|
||||
private MjBody _componentB;
|
||||
private Vector3 _originalGravity;
|
||||
private MjScene _scene;
|
||||
private MjGlobalSettings _settings;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_componentA = new GameObject("component").AddComponent<MjBody>();
|
||||
_componentB = new GameObject("component").AddComponent<MjBody>();
|
||||
_scene = MjScene.Instance;
|
||||
_originalGravity = Physics.gravity;
|
||||
_settings = new GameObject("settings").AddComponent<MjGlobalSettings>();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
Physics.gravity = _originalGravity;
|
||||
UnityEngine.Object.DestroyImmediate(_componentA.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(_componentB.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(_settings.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(_scene.gameObject);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: de5be923668a9430596708fea97eb93c
|
||||
timeCreated: 1537461794
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f2ea6a2cbdb5b655782b59b4f75f602d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,108 @@
|
||||
// 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 MjActuatorScalarSensorTests {
|
||||
|
||||
private MjActuatorScalarSensor _sensor;
|
||||
private MjActuator _actuator;
|
||||
private MjHingeJoint _joint;
|
||||
private XmlDocument _doc;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_sensor = new GameObject("sensor", typeof(MjActuatorScalarSensor))
|
||||
.GetComponent<MjActuatorScalarSensor>();
|
||||
_joint = new GameObject("joint", typeof(MjHingeJoint)).GetComponent<MjHingeJoint>();
|
||||
_actuator = new GameObject("actuator", typeof(MjActuator)).GetComponent<MjActuator>();
|
||||
_actuator.Joint = _joint;
|
||||
_sensor.Actuator = _actuator;
|
||||
|
||||
_doc = new XmlDocument();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
UnityEngine.Object.DestroyImmediate(_sensor.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(_joint.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(_actuator.gameObject);
|
||||
}
|
||||
|
||||
private XmlElement Parse(string mjcfString, string tag) {
|
||||
_doc.LoadXml(mjcfString);
|
||||
var elementList = _doc.GetElementsByTagName(tag);
|
||||
return elementList[0] as XmlElement;
|
||||
}
|
||||
|
||||
[TestCase(MjActuatorScalarSensor.AvailableSensors.ActuatorPos, "actuatorpos")]
|
||||
[TestCase(MjActuatorScalarSensor.AvailableSensors.ActuatorVel, "actuatorvel")]
|
||||
[TestCase(MjActuatorScalarSensor.AvailableSensors.ActuatorFrc, "actuatorfrc")]
|
||||
public void GenerateSensorName(
|
||||
MjActuatorScalarSensor.AvailableSensors type, string expectedTag) {
|
||||
_sensor.SensorType = type;
|
||||
_doc.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"<{expectedTag}"));
|
||||
}
|
||||
|
||||
[TestCase(MjActuatorScalarSensor.AvailableSensors.ActuatorPos)]
|
||||
[TestCase(MjActuatorScalarSensor.AvailableSensors.ActuatorVel)]
|
||||
[TestCase(MjActuatorScalarSensor.AvailableSensors.ActuatorFrc)]
|
||||
public void GenerateJointReference(MjActuatorScalarSensor.AvailableSensors type) {
|
||||
var parentNode = _doc.CreateElement("parent");
|
||||
_doc.AppendChild(parentNode);
|
||||
_sensor.SensorType = type;
|
||||
parentNode.AppendChild(_actuator.GenerateMjcf("test_actuator", _doc));
|
||||
parentNode.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain("actuator=\"test_actuator\""));
|
||||
}
|
||||
|
||||
[TestCase("actuatorpos", MjActuatorScalarSensor.AvailableSensors.ActuatorPos)]
|
||||
[TestCase("actuatorvel", MjActuatorScalarSensor.AvailableSensors.ActuatorVel)]
|
||||
[TestCase("actuatorfrc", MjActuatorScalarSensor.AvailableSensors.ActuatorFrc)]
|
||||
public void ParsingSensorType(
|
||||
string tag, MjActuatorScalarSensor.AvailableSensors expectedType) {
|
||||
var mjcfString = $"<sensors><{tag} actuator=\"actuator\"/></sensors>";
|
||||
var mjcfElement = Parse(mjcfString, tag);
|
||||
_sensor.ParseMjcf(mjcfElement);
|
||||
Assert.That(_sensor.SensorType, Is.EqualTo(expectedType));
|
||||
}
|
||||
|
||||
[TestCase("actuatorpos")]
|
||||
[TestCase("actuatorvel")]
|
||||
[TestCase("actuatorfrc")]
|
||||
public void ParsingReferenceToExistingActuator(string tag) {
|
||||
var mjcfString = $"<sensors><{tag} actuator=\"actuator\"/></sensors>";
|
||||
var mjcfElement = Parse(mjcfString, tag);
|
||||
_sensor.ParseMjcf(mjcfElement);
|
||||
Assert.That(_sensor.Actuator, Is.EqualTo(_actuator));
|
||||
}
|
||||
|
||||
[TestCase("actuatorpos")]
|
||||
[TestCase("actuatorvel")]
|
||||
[TestCase("actuatorfrc")]
|
||||
public void ParsingReferenceToMissingAcgtuatorThrowsException(string tag) {
|
||||
var mjcfString = $"<sensors><{tag} actuator=\"missing_actuator\"/></sensors>";
|
||||
var mjcfElement = Parse(mjcfString, tag);
|
||||
Assert.That(() => { _sensor.ParseMjcf(mjcfElement); }, Throws.TypeOf<ArgumentException>());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 287455e1e42ce4ac1817b65258ddd17f
|
||||
timeCreated: 1548111403
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,72 @@
|
||||
// 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 MjBaseSensorTests {
|
||||
|
||||
public class MjMockSensor : MjBaseSensor {
|
||||
protected override XmlElement ToMjcf(XmlDocument doc) {
|
||||
return doc.CreateElement("sensor");
|
||||
}
|
||||
protected override void FromMjcf(XmlElement mjcf) {}
|
||||
}
|
||||
|
||||
private MjMockSensor _sensor;
|
||||
private XmlDocument _doc;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_sensor = new GameObject("sensor", typeof(MjMockSensor)).GetComponent<MjMockSensor>();
|
||||
_doc = new XmlDocument();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
UnityEngine.Object.DestroyImmediate(_sensor.gameObject);
|
||||
}
|
||||
|
||||
private XmlElement Parse(string mjcfString, string tag) {
|
||||
_doc.LoadXml(mjcfString);
|
||||
var elementList = _doc.GetElementsByTagName(tag);
|
||||
return elementList[0] as XmlElement;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GeneratingNoiseAndCutoffMjcf() {
|
||||
_sensor.Noise = 2.0f;
|
||||
_sensor.Cutoff = 3.0f;
|
||||
_doc.AppendChild(_sensor.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain("noise=\"2\""));
|
||||
Assert.That(_doc.OuterXml, Does.Contain("cutoff=\"3\""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParsingShapePropertiesMjcf() {
|
||||
var mjcfString = "<sensor noise=\"3\" cutoff=\"4\" actuator=\"actuator\"/>";
|
||||
var mjcfElement = Parse(mjcfString, "sensor");
|
||||
_sensor.ParseMjcf(mjcfElement);
|
||||
Assert.That(_sensor.Noise, Is.EqualTo(3.0f));
|
||||
Assert.That(_sensor.Cutoff, Is.EqualTo(4.0f));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8bfd8b530bc0546a69960cffd3c1cb35
|
||||
timeCreated: 1548085697
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,91 @@
|
||||
// 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 MjBodyQuaternionSensorTests {
|
||||
|
||||
private MjBodyQuaternionSensor _sensor;
|
||||
private MjBody _body;
|
||||
private XmlDocument _doc;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_sensor = new GameObject("sensor", typeof(MjBodyQuaternionSensor))
|
||||
.GetComponent<MjBodyQuaternionSensor>();
|
||||
_body = new GameObject("body", typeof(MjBody)).GetComponent<MjBody>();
|
||||
_sensor.Body = _body;
|
||||
|
||||
_doc = new XmlDocument();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
UnityEngine.Object.DestroyImmediate(_sensor.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(_body.gameObject);
|
||||
}
|
||||
|
||||
private XmlElement Parse(string mjcfString, string tag) {
|
||||
_doc.LoadXml(mjcfString);
|
||||
var elementList = _doc.GetElementsByTagName(tag);
|
||||
return elementList[0] as XmlElement;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenerateSensorName() {
|
||||
_doc.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"<framequat"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenerateBodyReference() {
|
||||
var parentNode = (XmlElement)_doc.CreateElement("parent");
|
||||
_doc.AppendChild(parentNode);
|
||||
parentNode.AppendChild(_body.GenerateMjcf("test_body", _doc));
|
||||
parentNode.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"objname=\"test_body\""));
|
||||
}
|
||||
|
||||
[TestCase(true, "xbody")]
|
||||
[TestCase(false, "body")]
|
||||
public void FrameTypeSpecification(bool useInertial, string expectedValue) {
|
||||
_sensor.UseInertialFrame = useInertial;
|
||||
_doc.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Not.Contain($"objname=\"{expectedValue}\""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParsingFrameBodyName() {
|
||||
var mjcfString = $"<sensors><framequat objname=\"body\"/></sensors>";
|
||||
var mjcfElement = Parse(mjcfString, $"framequat");
|
||||
_sensor.ParseMjcf(mjcfElement);
|
||||
Assert.That(_sensor.Body, Is.EqualTo(_body));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ExceptionThrownWhenReferencedBodyNotFoundInScene() {
|
||||
var mjcfString = $"<sensors><framequat objname=\"missing_body\"/></sensors>";
|
||||
var mjcfElement = Parse(mjcfString, $"framequat");
|
||||
Assert.That(() => { _sensor.ParseMjcf(mjcfElement); }, Throws.TypeOf<ArgumentException>());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f205441f0cfbb407abd911ffd114bef9
|
||||
timeCreated: 1548171405
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,176 @@
|
||||
// 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 MjBodyVectorSensorTests {
|
||||
|
||||
private MjBodyVectorSensor _sensor;
|
||||
private MjBody _body;
|
||||
private XmlDocument _doc;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_sensor = new GameObject("sensor", typeof(MjBodyVectorSensor))
|
||||
.GetComponent<MjBodyVectorSensor>();
|
||||
_body = new GameObject("body", typeof(MjBody)).GetComponent<MjBody>();
|
||||
_sensor.Body = _body;
|
||||
|
||||
_doc = new XmlDocument();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
UnityEngine.Object.DestroyImmediate(_sensor.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(_body.gameObject);
|
||||
}
|
||||
|
||||
private XmlElement Parse(string mjcfString, string tag) {
|
||||
_doc.LoadXml(mjcfString);
|
||||
var elementList = _doc.GetElementsByTagName(tag);
|
||||
return elementList[0] as XmlElement;
|
||||
}
|
||||
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.SubtreeCom, "subtreecom")]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.SubtreeLinVel, "subtreelinvel")]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.SubtreeAngMom, "subtreeangmom")]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FramePos, "framepos")]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameXAxis, "framexaxis")]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameYAxis, "frameyaxis")]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameZAxis, "framezaxis")]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameLinVel, "framelinvel")]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameAngVel, "frameangvel")]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameLinAcc, "framelinacc")]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameAngAcc, "frameangacc")]
|
||||
public void GenerateSensorName(
|
||||
MjBodyVectorSensor.AvailableSensors type, string expectedTag) {
|
||||
_sensor.SensorType = type;
|
||||
_doc.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"<{expectedTag}"));
|
||||
}
|
||||
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.SubtreeCom, "body")]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.SubtreeLinVel, "body")]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.SubtreeAngMom, "body")]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FramePos, "objname")]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameXAxis, "objname")]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameYAxis, "objname")]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameZAxis, "objname")]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameLinVel, "objname")]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameAngVel, "objname")]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameLinAcc, "objname")]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameAngAcc, "objname")]
|
||||
public void GenerateBodyReference(
|
||||
MjBodyVectorSensor.AvailableSensors type, string expectedAttribute) {
|
||||
var parentNode = (XmlElement)_doc.CreateElement("parent");
|
||||
_doc.AppendChild(parentNode);
|
||||
_sensor.SensorType = type;
|
||||
parentNode.AppendChild(_body.GenerateMjcf("test_body", _doc));
|
||||
parentNode.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"{expectedAttribute}=\"test_body\""));
|
||||
}
|
||||
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.SubtreeCom)]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.SubtreeLinVel)]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.SubtreeAngMom)]
|
||||
public void SensorsWithoutExplicitBindingTypeSpecification(
|
||||
MjBodyVectorSensor.AvailableSensors type) {
|
||||
_sensor.SensorType = type;
|
||||
_doc.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Not.Contain($"objname"));
|
||||
}
|
||||
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FramePos)]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameXAxis)]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameYAxis)]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameZAxis)]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameLinVel)]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameAngVel)]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameLinAcc)]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameAngAcc)]
|
||||
public void InertialFrameSpecification(MjBodyVectorSensor.AvailableSensors type) {
|
||||
_sensor.SensorType = type;
|
||||
_sensor.UseInertialFrame = true;
|
||||
_doc.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Not.Contain($"objname=\"xbody\""));
|
||||
}
|
||||
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FramePos)]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameXAxis)]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameYAxis)]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameZAxis)]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameLinVel)]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameAngVel)]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameLinAcc)]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameAngAcc)]
|
||||
public void RegularFrameSpecification(MjBodyVectorSensor.AvailableSensors type) {
|
||||
_sensor.SensorType = type;
|
||||
_sensor.UseInertialFrame = false;
|
||||
_doc.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Not.Contain($"objname=\"body\""));
|
||||
}
|
||||
|
||||
[TestCase("subtreecom", MjBodyVectorSensor.AvailableSensors.SubtreeCom)]
|
||||
[TestCase("subtreelinvel", MjBodyVectorSensor.AvailableSensors.SubtreeLinVel)]
|
||||
[TestCase("subtreeangmom", MjBodyVectorSensor.AvailableSensors.SubtreeAngMom)]
|
||||
[TestCase("framepos", MjBodyVectorSensor.AvailableSensors.FramePos)]
|
||||
[TestCase("framexaxis", MjBodyVectorSensor.AvailableSensors.FrameXAxis)]
|
||||
[TestCase("frameyaxis", MjBodyVectorSensor.AvailableSensors.FrameYAxis)]
|
||||
[TestCase("framezaxis", MjBodyVectorSensor.AvailableSensors.FrameZAxis)]
|
||||
[TestCase("framelinvel", MjBodyVectorSensor.AvailableSensors.FrameLinVel)]
|
||||
[TestCase("frameangvel", MjBodyVectorSensor.AvailableSensors.FrameAngVel)]
|
||||
[TestCase("framelinacc", MjBodyVectorSensor.AvailableSensors.FrameLinAcc)]
|
||||
[TestCase("frameangacc", MjBodyVectorSensor.AvailableSensors.FrameAngAcc)]
|
||||
public void ParsingSensorType(
|
||||
string tag, MjBodyVectorSensor.AvailableSensors expectedType) {
|
||||
var mjcfString = $"<sensors><{tag} body=\"body\" objname=\"body\"/></sensors>";
|
||||
var mjcfElement = Parse(mjcfString, $"{tag}");
|
||||
_sensor.ParseMjcf(mjcfElement);
|
||||
Assert.That(_sensor.SensorType, Is.EqualTo(expectedType));
|
||||
}
|
||||
|
||||
[TestCase("subtreecom", "body")]
|
||||
[TestCase("subtreelinvel", "body")]
|
||||
[TestCase("subtreeangmom", "body")]
|
||||
public void ParsingSubtreeBodyName(string tag, string bodyAttribute) {
|
||||
var mjcfString = $"<sensors><{tag} {bodyAttribute}=\"body\"/></sensors>";
|
||||
var mjcfElement = Parse(mjcfString, $"{tag}");
|
||||
_sensor.ParseMjcf(mjcfElement);
|
||||
Assert.That(_sensor.Body, Is.EqualTo(_body));
|
||||
}
|
||||
|
||||
[TestCase("framepos", "objname")]
|
||||
[TestCase("framexaxis", "objname")]
|
||||
[TestCase("frameyaxis", "objname")]
|
||||
[TestCase("framezaxis", "objname")]
|
||||
[TestCase("framelinvel", "objname")]
|
||||
[TestCase("frameangvel", "objname")]
|
||||
[TestCase("framelinacc", "objname")]
|
||||
[TestCase("frameangacc", "objname")]
|
||||
public void ParsingFrameBodyName(string tag, string bodyAttribute) {
|
||||
var mjcfString = $"<sensors><{tag} {bodyAttribute}=\"body\"/></sensors>";
|
||||
var mjcfElement = Parse(mjcfString, $"{tag}");
|
||||
_sensor.ParseMjcf(mjcfElement);
|
||||
Assert.That(_sensor.Body, Is.EqualTo(_body));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f526488db0d874499bc9af392d6dedd1
|
||||
timeCreated: 1548105164
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,88 @@
|
||||
// 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 MjGeomQuaternionSensorTests {
|
||||
|
||||
private MjGeomQuaternionSensor _sensor;
|
||||
private MjGeom _geom;
|
||||
private XmlDocument _doc;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_sensor = new GameObject("MjGeomQuaternionSensorTests_sensor")
|
||||
.AddComponent<MjGeomQuaternionSensor>();
|
||||
_geom = new GameObject("MjGeomQuaternionSensorTests_geom").AddComponent<MjGeom>();
|
||||
_sensor.Geom = _geom;
|
||||
|
||||
_doc = new XmlDocument();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
UnityEngine.Object.DestroyImmediate(_sensor.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(_geom.gameObject);
|
||||
}
|
||||
|
||||
private XmlElement Parse(string mjcfString, string tag) {
|
||||
_doc.LoadXml(mjcfString);
|
||||
var elementList = _doc.GetElementsByTagName(tag);
|
||||
return elementList[0] as XmlElement;
|
||||
}
|
||||
|
||||
public void GenerateSensorName() {
|
||||
_doc.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain("<framequat"));
|
||||
}
|
||||
|
||||
public void GenerateGeomReference() {
|
||||
var parentNode = (XmlElement)_doc.CreateElement("parent");
|
||||
_doc.AppendChild(parentNode);
|
||||
parentNode.AppendChild(_geom.GenerateMjcf("test_geom", _doc));
|
||||
parentNode.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain("objname=\"test_geom\""));
|
||||
}
|
||||
|
||||
public void FrameTypeSpecification() {
|
||||
_doc.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(
|
||||
_doc.OuterXml, Does.Not.Contain("objname=\"MjGeomQuaternionSensorTests_geom\""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FindTheReferencedGeom() {
|
||||
var mjcfString =
|
||||
"<sensors><framequat objname=\"MjGeomQuaternionSensorTests_geom\"/></sensors>";
|
||||
var mjcfElement = Parse(mjcfString, "framequat");
|
||||
_sensor.Geom = null;
|
||||
_sensor.ParseMjcf(mjcfElement);
|
||||
Assert.That(_sensor.Geom, Is.EqualTo(_geom));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ExceptionThrownWhenReferencedBodyNotFoundInScene() {
|
||||
var mjcfString = "<sensors><framequat objname=\"missing_geom\"/></sensors>";
|
||||
var mjcfElement = Parse(mjcfString, "framequat");
|
||||
Assert.That(() => { _sensor.ParseMjcf(mjcfElement); }, Throws.TypeOf<ArgumentException>());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ca32673e22b8f42f58cb7fb324980224
|
||||
timeCreated: 1548171623
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,134 @@
|
||||
// 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 MjGeomVectorSensorTests {
|
||||
|
||||
private MjGeomVectorSensor _sensor;
|
||||
private MjGeom _geom;
|
||||
private XmlDocument _doc;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_sensor = new GameObject("MjGeomVectorSensorTests_sensor")
|
||||
.AddComponent<MjGeomVectorSensor>();
|
||||
_geom = new GameObject("MjGeomVectorSensorTests_geom").AddComponent<MjGeom>();
|
||||
_sensor.Geom = _geom;
|
||||
|
||||
_doc = new XmlDocument();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
UnityEngine.Object.DestroyImmediate(_sensor.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(_geom.gameObject);
|
||||
}
|
||||
|
||||
private XmlElement Parse(string mjcfString, string tag) {
|
||||
_doc.LoadXml(mjcfString);
|
||||
var elementList = _doc.GetElementsByTagName(tag);
|
||||
return elementList[0] as XmlElement;
|
||||
}
|
||||
|
||||
[TestCase(MjGeomVectorSensor.AvailableSensors.FramePos, "framepos")]
|
||||
[TestCase(MjGeomVectorSensor.AvailableSensors.FrameXAxis, "framexaxis")]
|
||||
[TestCase(MjGeomVectorSensor.AvailableSensors.FrameYAxis, "frameyaxis")]
|
||||
[TestCase(MjGeomVectorSensor.AvailableSensors.FrameZAxis, "framezaxis")]
|
||||
[TestCase(MjGeomVectorSensor.AvailableSensors.FrameLinVel, "framelinvel")]
|
||||
[TestCase(MjGeomVectorSensor.AvailableSensors.FrameAngVel, "frameangvel")]
|
||||
[TestCase(MjGeomVectorSensor.AvailableSensors.FrameLinAcc, "framelinacc")]
|
||||
[TestCase(MjGeomVectorSensor.AvailableSensors.FrameAngAcc, "frameangacc")]
|
||||
public void GenerateSensorName(
|
||||
MjGeomVectorSensor.AvailableSensors type, string expectedTag) {
|
||||
_sensor.SensorType = type;
|
||||
_doc.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"<{expectedTag}"));
|
||||
}
|
||||
|
||||
[TestCase(MjGeomVectorSensor.AvailableSensors.FramePos, "objname")]
|
||||
[TestCase(MjGeomVectorSensor.AvailableSensors.FrameXAxis, "objname")]
|
||||
[TestCase(MjGeomVectorSensor.AvailableSensors.FrameYAxis, "objname")]
|
||||
[TestCase(MjGeomVectorSensor.AvailableSensors.FrameZAxis, "objname")]
|
||||
[TestCase(MjGeomVectorSensor.AvailableSensors.FrameLinVel, "objname")]
|
||||
[TestCase(MjGeomVectorSensor.AvailableSensors.FrameAngVel, "objname")]
|
||||
[TestCase(MjGeomVectorSensor.AvailableSensors.FrameLinAcc, "objname")]
|
||||
[TestCase(MjGeomVectorSensor.AvailableSensors.FrameAngAcc, "objname")]
|
||||
public void GenerateGeomReference(
|
||||
MjGeomVectorSensor.AvailableSensors type, string expectedAttribute) {
|
||||
var parentNode = (XmlElement)_doc.CreateElement("parent");
|
||||
_doc.AppendChild(parentNode);
|
||||
_sensor.SensorType = type;
|
||||
parentNode.AppendChild(_geom.GenerateMjcf("test_geom", _doc));
|
||||
parentNode.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"{expectedAttribute}=\"test_geom\""));
|
||||
}
|
||||
|
||||
[TestCase(MjGeomVectorSensor.AvailableSensors.FramePos)]
|
||||
[TestCase(MjGeomVectorSensor.AvailableSensors.FrameXAxis)]
|
||||
[TestCase(MjGeomVectorSensor.AvailableSensors.FrameYAxis)]
|
||||
[TestCase(MjGeomVectorSensor.AvailableSensors.FrameZAxis)]
|
||||
[TestCase(MjGeomVectorSensor.AvailableSensors.FrameLinVel)]
|
||||
[TestCase(MjGeomVectorSensor.AvailableSensors.FrameAngVel)]
|
||||
[TestCase(MjGeomVectorSensor.AvailableSensors.FrameLinAcc)]
|
||||
[TestCase(MjGeomVectorSensor.AvailableSensors.FrameAngAcc)]
|
||||
public void FrameTypeSpecification(MjGeomVectorSensor.AvailableSensors type) {
|
||||
_sensor.SensorType = type;
|
||||
_doc.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Not.Contain($"objname=\"MjGeomVectorSensorTests_geom\""));
|
||||
}
|
||||
|
||||
[TestCase("framepos", MjGeomVectorSensor.AvailableSensors.FramePos)]
|
||||
[TestCase("framexaxis", MjGeomVectorSensor.AvailableSensors.FrameXAxis)]
|
||||
[TestCase("frameyaxis", MjGeomVectorSensor.AvailableSensors.FrameYAxis)]
|
||||
[TestCase("framezaxis", MjGeomVectorSensor.AvailableSensors.FrameZAxis)]
|
||||
[TestCase("framelinvel", MjGeomVectorSensor.AvailableSensors.FrameLinVel)]
|
||||
[TestCase("frameangvel", MjGeomVectorSensor.AvailableSensors.FrameAngVel)]
|
||||
[TestCase("framelinacc", MjGeomVectorSensor.AvailableSensors.FrameLinAcc)]
|
||||
[TestCase("frameangacc", MjGeomVectorSensor.AvailableSensors.FrameAngAcc)]
|
||||
public void ParsingSensorType(
|
||||
string tag, MjGeomVectorSensor.AvailableSensors expectedType) {
|
||||
var mjcfString =
|
||||
$"<sensors><{tag} geom=\"MjGeomVectorSensorTests_geom\" " +
|
||||
"objname=\"MjGeomVectorSensorTests_geom\"/></sensors>";
|
||||
var mjcfElement = Parse(mjcfString, $"{tag}");
|
||||
_sensor.ParseMjcf(mjcfElement);
|
||||
Assert.That(_sensor.SensorType, Is.EqualTo(expectedType));
|
||||
}
|
||||
|
||||
[TestCase("framepos", "objname")]
|
||||
[TestCase("framexaxis", "objname")]
|
||||
[TestCase("frameyaxis", "objname")]
|
||||
[TestCase("framezaxis", "objname")]
|
||||
[TestCase("framelinvel", "objname")]
|
||||
[TestCase("frameangvel", "objname")]
|
||||
[TestCase("framelinacc", "objname")]
|
||||
[TestCase("frameangacc", "objname")]
|
||||
public void ParsingFrameGeomName(string tag, string siteAttribute) {
|
||||
var mjcfString =
|
||||
$"<sensors><{tag} {siteAttribute}=\"MjGeomVectorSensorTests_geom\"/></sensors>";
|
||||
var mjcfElement = Parse(mjcfString, $"{tag}");
|
||||
_sensor.ParseMjcf(mjcfElement);
|
||||
Assert.That(_sensor.Geom, Is.EqualTo(_geom));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2692b29d3e9a341338aeeedf820a6ee6
|
||||
timeCreated: 1548110539
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,113 @@
|
||||
// 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 MjJointScalarSensorTests {
|
||||
|
||||
private MjJointScalarSensor _sensor;
|
||||
private MjHingeJoint _joint;
|
||||
private XmlDocument _doc;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_sensor = new GameObject("sensor").AddComponent<MjJointScalarSensor>();
|
||||
_joint = new GameObject("joint").AddComponent<MjHingeJoint>();
|
||||
_sensor.Joint = _joint;
|
||||
|
||||
_doc = new XmlDocument();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
UnityEngine.Object.DestroyImmediate(_sensor.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(_joint.gameObject);
|
||||
}
|
||||
|
||||
private XmlElement Parse(string mjcfString, string tag) {
|
||||
_doc.LoadXml(mjcfString);
|
||||
var elementList = _doc.GetElementsByTagName(tag);
|
||||
return elementList[0] as XmlElement;
|
||||
}
|
||||
|
||||
[TestCase(MjJointScalarSensor.AvailableSensors.JointPos, "jointpos")]
|
||||
[TestCase(MjJointScalarSensor.AvailableSensors.JointVel, "jointvel")]
|
||||
[TestCase(MjJointScalarSensor.AvailableSensors.JointLimitPos, "jointlimitpos")]
|
||||
[TestCase(MjJointScalarSensor.AvailableSensors.JointLimitVel, "jointlimitvel")]
|
||||
[TestCase(MjJointScalarSensor.AvailableSensors.JointLimitFrc, "jointlimitfrc")]
|
||||
public void GenerateSensorName(
|
||||
MjJointScalarSensor.AvailableSensors type, string expectedTag) {
|
||||
_sensor.SensorType = type;
|
||||
_doc.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"<{expectedTag}"));
|
||||
}
|
||||
|
||||
[TestCase(MjJointScalarSensor.AvailableSensors.JointPos)]
|
||||
[TestCase(MjJointScalarSensor.AvailableSensors.JointVel)]
|
||||
[TestCase(MjJointScalarSensor.AvailableSensors.JointLimitPos)]
|
||||
[TestCase(MjJointScalarSensor.AvailableSensors.JointLimitVel)]
|
||||
[TestCase(MjJointScalarSensor.AvailableSensors.JointLimitFrc)]
|
||||
public void GenerateJointReference(MjJointScalarSensor.AvailableSensors type) {
|
||||
var parentNode = _doc.CreateElement("parent");
|
||||
_doc.AppendChild(parentNode);
|
||||
_sensor.SensorType = type;
|
||||
parentNode.AppendChild(_joint.GenerateMjcf("test_joint", _doc));
|
||||
parentNode.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain("joint=\"test_joint\""));
|
||||
}
|
||||
|
||||
[TestCase("jointpos", MjJointScalarSensor.AvailableSensors.JointPos)]
|
||||
[TestCase("jointvel", MjJointScalarSensor.AvailableSensors.JointVel)]
|
||||
[TestCase("jointlimitpos", MjJointScalarSensor.AvailableSensors.JointLimitPos)]
|
||||
[TestCase("jointlimitvel", MjJointScalarSensor.AvailableSensors.JointLimitVel)]
|
||||
[TestCase("jointlimitfrc", MjJointScalarSensor.AvailableSensors.JointLimitFrc)]
|
||||
public void ParsingSensorType(
|
||||
string tag, MjJointScalarSensor.AvailableSensors expectedType) {
|
||||
var mjcfString = $"<sensors><{tag} joint=\"joint\"/></sensors>";
|
||||
var mjcfElement = Parse(mjcfString, $"{tag}");
|
||||
_sensor.ParseMjcf(mjcfElement);
|
||||
Assert.That(_sensor.SensorType, Is.EqualTo(expectedType));
|
||||
}
|
||||
|
||||
[TestCase("jointpos")]
|
||||
[TestCase("jointvel")]
|
||||
[TestCase("jointlimitpos")]
|
||||
[TestCase("jointlimitvel")]
|
||||
[TestCase("jointlimitfrc")]
|
||||
public void ParsingReferenceToExistingJoint(string tag) {
|
||||
var mjcfString = $"<sensors><{tag} joint=\"joint\"/></sensors>";
|
||||
var mjcfElement = Parse(mjcfString, $"{tag}");
|
||||
_sensor.ParseMjcf(mjcfElement);
|
||||
Assert.That(_sensor.Joint, Is.EqualTo(_joint));
|
||||
}
|
||||
|
||||
[TestCase("jointpos")]
|
||||
[TestCase("jointvel")]
|
||||
[TestCase("jointlimitpos")]
|
||||
[TestCase("jointlimitvel")]
|
||||
[TestCase("jointlimitfrc")]
|
||||
public void ParsingReferenceToMissingJointThrowsException(string tag) {
|
||||
var mjcfString = $"<sensors><{tag} joint=\"missing_joint\"/></sensors>";
|
||||
var mjcfElement = Parse(mjcfString, $"{tag}");
|
||||
Assert.That(() => { _sensor.ParseMjcf(mjcfElement); }, Throws.TypeOf<ArgumentException>());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 723fee04a97c5487486652cd5167bd06
|
||||
timeCreated: 1548111043
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,84 @@
|
||||
// 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 MjSiteQuaternionSensorTests {
|
||||
|
||||
private MjSiteQuaternionSensor _sensor;
|
||||
private MjSite _site;
|
||||
private XmlDocument _doc;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_sensor = new GameObject("sensor", typeof(MjSiteQuaternionSensor))
|
||||
.GetComponent<MjSiteQuaternionSensor>();
|
||||
_site = new GameObject("site", typeof(MjSite)).GetComponent<MjSite>();
|
||||
_sensor.Site = _site;
|
||||
|
||||
_doc = new XmlDocument();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
UnityEngine.Object.DestroyImmediate(_sensor.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(_site.gameObject);
|
||||
}
|
||||
|
||||
private XmlElement Parse(string mjcfString, string tag) {
|
||||
_doc.LoadXml(mjcfString);
|
||||
var elementList = _doc.GetElementsByTagName(tag);
|
||||
return elementList[0] as XmlElement;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenerateSensorName() {
|
||||
_doc.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain("<framequat"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenerateSiteReference() {
|
||||
var parentNode = _doc.CreateElement("parent");
|
||||
_doc.AppendChild(parentNode);
|
||||
parentNode.AppendChild(_site.GenerateMjcf("test_site", _doc));
|
||||
parentNode.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain("objname=\"test_site\""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FindingRenferencedSite() {
|
||||
var mjcfString = "<sensors><framequat objname=\"site\"/></sensors>";
|
||||
var mjcfElement = Parse(mjcfString, "framequat");
|
||||
_sensor.Site = null;
|
||||
_sensor.ParseMjcf(mjcfElement);
|
||||
Assert.That(_sensor.Site, Is.EqualTo(_site));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ExceptionThrownWhenReferencedBodyNotFoundInScene() {
|
||||
var mjcfString = "<sensors><framequat objname=\"missing_site\"/></sensors>";
|
||||
var mjcfElement = Parse(mjcfString, "framequat");
|
||||
Assert.That(() => { _sensor.ParseMjcf(mjcfElement); }, Throws.TypeOf<ArgumentException>());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 733b3b2c8a1ea44ddab4da302810cc4d
|
||||
timeCreated: 1548171912
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,101 @@
|
||||
// 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 MjSiteScalarSensorTests {
|
||||
|
||||
private MjSiteScalarSensor _sensor;
|
||||
private MjSite _site;
|
||||
private XmlDocument _doc;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_sensor = new GameObject("sensor", typeof(MjSiteScalarSensor))
|
||||
.GetComponent<MjSiteScalarSensor>();
|
||||
_site = new GameObject("site", typeof(MjSite)).GetComponent<MjSite>();
|
||||
_sensor.Site = _site;
|
||||
|
||||
_doc = new XmlDocument();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
UnityEngine.Object.DestroyImmediate(_sensor.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(_site.gameObject);
|
||||
}
|
||||
|
||||
private XmlElement Parse(string mjcfString, string tag) {
|
||||
_doc.LoadXml(mjcfString);
|
||||
var elementList = _doc.GetElementsByTagName(tag);
|
||||
return elementList[0] as XmlElement;
|
||||
}
|
||||
|
||||
[TestCase(MjSiteScalarSensor.AvailableSensors.Touch, "touch")]
|
||||
[TestCase(MjSiteScalarSensor.AvailableSensors.RangeFinder, "rangefinder")]
|
||||
public void GenerateSensorName(
|
||||
MjSiteScalarSensor.AvailableSensors type, string expectedTag) {
|
||||
_sensor.SensorType = type;
|
||||
_doc.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"<{expectedTag}"));
|
||||
}
|
||||
|
||||
[TestCase(MjSiteScalarSensor.AvailableSensors.Touch)]
|
||||
[TestCase(MjSiteScalarSensor.AvailableSensors.RangeFinder)]
|
||||
public void GenerateSiteReference(MjSiteScalarSensor.AvailableSensors type) {
|
||||
var parentNode = (XmlElement)_doc.CreateElement("parent");
|
||||
_doc.AppendChild(parentNode);
|
||||
_sensor.SensorType = type;
|
||||
parentNode.AppendChild(_site.GenerateMjcf("test_site", _doc));
|
||||
parentNode.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"site=\"test_site\""));
|
||||
}
|
||||
|
||||
[TestCase(MjSiteScalarSensor.AvailableSensors.Touch)]
|
||||
[TestCase(MjSiteScalarSensor.AvailableSensors.RangeFinder)]
|
||||
public void SensorsWithoutExplicitBindingTypeSpecification(
|
||||
MjSiteScalarSensor.AvailableSensors type) {
|
||||
_sensor.SensorType = type;
|
||||
_doc.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Not.Contain($"objname"));
|
||||
}
|
||||
|
||||
[TestCase("touch", MjSiteScalarSensor.AvailableSensors.Touch)]
|
||||
[TestCase("rangefinder", MjSiteScalarSensor.AvailableSensors.RangeFinder)]
|
||||
public void ParsingSensorType(
|
||||
string tag, MjSiteScalarSensor.AvailableSensors expectedType) {
|
||||
var mjcfString = $"<sensors><{tag} site=\"site\"/></sensors>";
|
||||
var mjcfElement = Parse(mjcfString, $"{tag}");
|
||||
_sensor.ParseMjcf(mjcfElement);
|
||||
Assert.That(_sensor.SensorType, Is.EqualTo(expectedType));
|
||||
}
|
||||
|
||||
[TestCase("touch", "site")]
|
||||
[TestCase("rangefinder", "site")]
|
||||
public void ParsingSubtreeSiteName(string tag, string siteAttribute) {
|
||||
var mjcfString = $"<sensors><{tag} {siteAttribute}=\"site\"/></sensors>";
|
||||
var mjcfElement = Parse(mjcfString, $"{tag}");
|
||||
_sensor.ParseMjcf(mjcfElement);
|
||||
Assert.That(_sensor.Site, Is.EqualTo(_site));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3a827466bc75c47b6afc4bc474a2a066
|
||||
timeCreated: 1548110161
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,173 @@
|
||||
// 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 MjSiteVectorSensorTests {
|
||||
|
||||
private MjSiteVectorSensor _sensor;
|
||||
private MjSite _site;
|
||||
private XmlDocument _doc;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_sensor = new GameObject("sensor").AddComponent<MjSiteVectorSensor>();
|
||||
_site = new GameObject("site").AddComponent<MjSite>();
|
||||
_sensor.Site = _site;
|
||||
|
||||
_doc = new XmlDocument();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
UnityEngine.Object.DestroyImmediate(_sensor.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(_site.gameObject);
|
||||
}
|
||||
|
||||
private XmlElement Parse(string mjcfString, string tag) {
|
||||
_doc.LoadXml(mjcfString);
|
||||
var elementList = _doc.GetElementsByTagName(tag);
|
||||
return elementList[0] as XmlElement;
|
||||
}
|
||||
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.Accelerometer, "accelerometer")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.Velocimeter, "velocimeter")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.Gyro, "gyro")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.Force, "force")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.Torque, "torque")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.Magnetometer, "magnetometer")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.FramePos, "framepos")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.FrameXAxis, "framexaxis")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.FrameYAxis, "frameyaxis")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.FrameZAxis, "framezaxis")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.FrameLinVel, "framelinvel")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.FrameAngVel, "frameangvel")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.FrameLinAcc, "framelinacc")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.FrameAngAcc, "frameangacc")]
|
||||
public void GenerateSensorName(
|
||||
MjSiteVectorSensor.AvailableSensors type, string expectedTag) {
|
||||
_sensor.SensorType = type;
|
||||
_doc.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"<{expectedTag}"));
|
||||
}
|
||||
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.Accelerometer, "site")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.Velocimeter, "site")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.Gyro, "site")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.Force, "site")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.Torque, "site")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.Magnetometer, "site")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.FramePos, "objname")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.FrameXAxis, "objname")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.FrameYAxis, "objname")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.FrameZAxis, "objname")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.FrameLinVel, "objname")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.FrameAngVel, "objname")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.FrameLinAcc, "objname")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.FrameAngAcc, "objname")]
|
||||
public void GenerateSiteReference(
|
||||
MjSiteVectorSensor.AvailableSensors type, string expectedAttribute) {
|
||||
var parentNode = (XmlElement)_doc.CreateElement("parent");
|
||||
_doc.AppendChild(parentNode);
|
||||
_sensor.SensorType = type;
|
||||
parentNode.AppendChild(_site.GenerateMjcf("test_site", _doc));
|
||||
parentNode.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"{expectedAttribute}=\"test_site\""));
|
||||
}
|
||||
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.Accelerometer)]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.Velocimeter)]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.Gyro)]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.Force)]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.Torque)]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.Magnetometer)]
|
||||
public void SensorsWithoutExplicitBindingTypeSpecification(
|
||||
MjSiteVectorSensor.AvailableSensors type) {
|
||||
_sensor.SensorType = type;
|
||||
_doc.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Not.Contain("objname"));
|
||||
}
|
||||
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.FramePos)]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.FrameXAxis)]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.FrameYAxis)]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.FrameZAxis)]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.FrameLinVel)]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.FrameAngVel)]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.FrameLinAcc)]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.FrameAngAcc)]
|
||||
public void FrameTypeSpecification(MjSiteVectorSensor.AvailableSensors type) {
|
||||
_sensor.SensorType = type;
|
||||
_doc.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Not.Contain("objname=\"site\""));
|
||||
}
|
||||
|
||||
[TestCase("accelerometer", MjSiteVectorSensor.AvailableSensors.Accelerometer)]
|
||||
[TestCase("velocimeter", MjSiteVectorSensor.AvailableSensors.Velocimeter)]
|
||||
[TestCase("gyro", MjSiteVectorSensor.AvailableSensors.Gyro)]
|
||||
[TestCase("force", MjSiteVectorSensor.AvailableSensors.Force)]
|
||||
[TestCase("torque", MjSiteVectorSensor.AvailableSensors.Torque)]
|
||||
[TestCase("magnetometer", MjSiteVectorSensor.AvailableSensors.Magnetometer)]
|
||||
[TestCase("framepos", MjSiteVectorSensor.AvailableSensors.FramePos)]
|
||||
[TestCase("framexaxis", MjSiteVectorSensor.AvailableSensors.FrameXAxis)]
|
||||
[TestCase("frameyaxis", MjSiteVectorSensor.AvailableSensors.FrameYAxis)]
|
||||
[TestCase("framezaxis", MjSiteVectorSensor.AvailableSensors.FrameZAxis)]
|
||||
[TestCase("framelinvel", MjSiteVectorSensor.AvailableSensors.FrameLinVel)]
|
||||
[TestCase("frameangvel", MjSiteVectorSensor.AvailableSensors.FrameAngVel)]
|
||||
[TestCase("framelinacc", MjSiteVectorSensor.AvailableSensors.FrameLinAcc)]
|
||||
[TestCase("frameangacc", MjSiteVectorSensor.AvailableSensors.FrameAngAcc)]
|
||||
public void ParsingSensorType(
|
||||
string tag, MjSiteVectorSensor.AvailableSensors expectedType) {
|
||||
var mjcfString = $"<sensors><{tag} site=\"site\" objname=\"site\"/></sensors>";
|
||||
var mjcfElement = Parse(mjcfString, tag);
|
||||
_sensor.ParseMjcf(mjcfElement);
|
||||
Assert.That(_sensor.SensorType, Is.EqualTo(expectedType));
|
||||
}
|
||||
|
||||
[TestCase("accelerometer", "site")]
|
||||
[TestCase("velocimeter", "site")]
|
||||
[TestCase("gyro", "site")]
|
||||
[TestCase("force", "site")]
|
||||
[TestCase("torque", "site")]
|
||||
[TestCase("magnetometer", "site")]
|
||||
public void ParsingSubtreeSiteName(string tag, string siteAttribute) {
|
||||
var mjcfString = $"<sensors><{tag} {siteAttribute}=\"site\"/></sensors>";
|
||||
var mjcfElement = Parse(mjcfString, tag);
|
||||
_sensor.ParseMjcf(mjcfElement);
|
||||
Assert.That(_sensor.Site, Is.EqualTo(_site));
|
||||
}
|
||||
|
||||
[TestCase("framepos", "objname")]
|
||||
[TestCase("framexaxis", "objname")]
|
||||
[TestCase("frameyaxis", "objname")]
|
||||
[TestCase("framezaxis", "objname")]
|
||||
[TestCase("framelinvel", "objname")]
|
||||
[TestCase("frameangvel", "objname")]
|
||||
[TestCase("framelinacc", "objname")]
|
||||
[TestCase("frameangacc", "objname")]
|
||||
public void ParsingFrameSiteName(string tag, string siteAttribute) {
|
||||
var mjcfString = $"<sensors><{tag} {siteAttribute}=\"site\"/></sensors>";
|
||||
var mjcfElement = Parse(mjcfString, tag);
|
||||
_sensor.ParseMjcf(mjcfElement);
|
||||
Assert.That(_sensor.Site, Is.EqualTo(_site));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8f9f930ccc5684f279f5e2ca0ec29cc8
|
||||
timeCreated: 1548171912
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6cee6252a3cdc9a24a25b7cc99be3392
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,174 @@
|
||||
// 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.Linq;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools.Utils;
|
||||
|
||||
namespace Mujoco {
|
||||
|
||||
[TestFixture]
|
||||
public class MeshGeneratorsEditorTests {
|
||||
[Test]
|
||||
public void FirstAndLastVerticalSlicesContainVerticesLocatedInTheSamePlace() {
|
||||
var meshData = MeshGenerators.BuildSphere(scale: Vector3.one, numVerticalSlices: 4,
|
||||
numHorizontalSlices: 3);
|
||||
var vertices = meshData.Item1;
|
||||
Assert.That(vertices[0], Is.EqualTo(vertices[1]));
|
||||
Assert.That(vertices[1], Is.EqualTo(vertices[2]));
|
||||
Assert.That(vertices[2], Is.EqualTo(vertices[3]));
|
||||
Assert.That(vertices[8], Is.EqualTo(vertices[9]));
|
||||
Assert.That(vertices[9], Is.EqualTo(vertices[10]));
|
||||
Assert.That(vertices[10], Is.EqualTo(vertices[11]));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GeneratedSphereWithProperScaling() {
|
||||
var scale = new Vector3(0.5f, 2, 3);
|
||||
var meshData =
|
||||
MeshGenerators.BuildSphere(scale: scale, numVerticalSlices: 4, numHorizontalSlices: 3);
|
||||
var vertices = meshData.Item1;
|
||||
// One of the vertices of the bottom cap.
|
||||
Assert.That(vertices[0], Is.EqualTo(Vector3.down * scale.y).Using(Vector3ComparerWithEqualsOperator.Instance));
|
||||
// One of the vertices of the top cap.
|
||||
Assert.That(vertices[8], Is.EqualTo(Vector3.up * scale.y).Using(Vector3ComparerWithEqualsOperator.Instance));
|
||||
// The sides.
|
||||
Assert.That(vertices[4], Is.EqualTo(Vector3.right * scale.x).Using(Vector3ComparerWithEqualsOperator.Instance));
|
||||
Assert.That(vertices[5], Is.EqualTo(Vector3.back * scale.z).Using(Vector3ComparerWithEqualsOperator.Instance));
|
||||
Assert.That(vertices[6], Is.EqualTo(Vector3.left * scale.x).Using(Vector3ComparerWithEqualsOperator.Instance));
|
||||
Assert.That(vertices[7],
|
||||
Is.EqualTo(Vector3.forward * scale.z).Using(Vector3ComparerWithEqualsOperator.Instance));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GeneratedCylinderHasCorrectHeight() {
|
||||
var meshData = MeshGenerators.BuildCylinder(radius: 1.0f, height: 5.0f, numVerticalSlices: 4);
|
||||
var bottomVertex =
|
||||
meshData.Item1.Aggregate((result, item) => result.y < item.y ? result : item);
|
||||
var topVertex = meshData.Item1.Aggregate((result, item) => result.y > item.y ? result : item);
|
||||
Assert.That(topVertex.y - bottomVertex.y, Is.EqualTo(5.0f).Within(1e-3f));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GeneratedCylinderHasCorrectRadius() {
|
||||
var meshData = MeshGenerators.BuildCylinder(radius: 2.0f, height: 1.0f, numVerticalSlices: 4);
|
||||
var averageRadius =
|
||||
meshData.Item1.Select(v => new Vector3(v.x, 0, v.z).magnitude).Average(radius => radius);
|
||||
Assert.That(averageRadius, Is.EqualTo(2.0f).Within(1e-3f));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GeneratedCapsuleHasCorrectHeight() {
|
||||
var meshData = MeshGenerators.BuildCapsule(radius: 1.0f, height: 5.0f, numVerticalSlices: 4,
|
||||
numHorizontalSlices: 3);
|
||||
var bottomVertex =
|
||||
meshData.Item1.Aggregate((result, item) => result.y < item.y ? result : item);
|
||||
var topVertex = meshData.Item1.Aggregate((result, item) => result.y > item.y ? result : item);
|
||||
// The height of the capsule is the height of the body plus the diameter of the sphere that
|
||||
// forms the bases.
|
||||
Assert.That(topVertex.y - bottomVertex.y, Is.EqualTo(5.0f).Within(1e-3f));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GeneratedCapsuleHasCorrectRadius() {
|
||||
var meshData = MeshGenerators.BuildCapsule(radius: 2.0f, height: 3.0f, numVerticalSlices: 4,
|
||||
numHorizontalSlices: 3);
|
||||
var averageRadius = meshData.Item1.Where(v => Math.Abs(v.y) <= 0.5f)
|
||||
.Select(v => new Vector3(v.x, 0, v.z).magnitude)
|
||||
.Average(radius => radius);
|
||||
Assert.That(averageRadius, Is.EqualTo(2.0f).Within(1e-3f));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GeneratedBoxHasCorrectExtents() {
|
||||
var extents = new Vector3(0.5f, 2, 3);
|
||||
var meshData = MeshGenerators.BuildBox(extents: extents);
|
||||
var minVertex = meshData.Item1.Aggregate(
|
||||
(result, item) =>
|
||||
(result.x + result.y + result.z) < (item.x + item.y + item.z) ? result : item);
|
||||
var maxVertex = meshData.Item1.Aggregate(
|
||||
(result, item) =>
|
||||
(result.x + result.y + result.z) > (item.x + item.y + item.z) ? result : item);
|
||||
Assert.That(minVertex, Is.EqualTo(extents * -1.0f).Using(Vector3ComparerWithEqualsOperator.Instance));
|
||||
Assert.That(maxVertex, Is.EqualTo(extents).Using(Vector3ComparerWithEqualsOperator.Instance));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GeneratedBoxTriangleMapIsAListOfConsecutiveIntegers() {
|
||||
var meshData = MeshGenerators.BuildBox(extents: Vector3.one);
|
||||
Assert.That(meshData.Item2, Has.Length.EqualTo(36));
|
||||
for (var i = 0; i < 36; ++i) {
|
||||
Assert.That(meshData.Item2[i], Is.EqualTo(i));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GeneratedPlaneHasCorrectExtents() {
|
||||
var meshData = MeshGenerators.BuildPlane(width: 2, height: 3);
|
||||
var minVertex = meshData.Item1.Aggregate(
|
||||
(result, item) => (result.x + result.z) < (item.x + item.z) ? result : item);
|
||||
var maxVertex = meshData.Item1.Aggregate(
|
||||
(result, item) => (result.x + result.z) > (item.x + item.z) ? result : item);
|
||||
Assert.That(minVertex, Is.EqualTo(new Vector3(-1, 0, -1.5f)).Using(Vector3ComparerWithEqualsOperator.Instance));
|
||||
Assert.That(maxVertex, Is.EqualTo(new Vector3(1, 0, 1.5f)).Using(Vector3ComparerWithEqualsOperator.Instance));
|
||||
}
|
||||
}
|
||||
|
||||
[TestFixture]
|
||||
public class MeshMergerEditorTests {
|
||||
private MeshMerger _meshMerger;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_meshMerger = new MeshMerger();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AddingMeshVerticesAggregatesThem() {
|
||||
_meshMerger.Add(vertices: new Vector3[] { Vector3.one }, triangles: new int[] {});
|
||||
Assert.That(_meshMerger.Vertices, Has.Length.EqualTo(1));
|
||||
_meshMerger.Add(vertices: new Vector3[] { Vector3.forward }, triangles: new int[] {});
|
||||
Assert.That(_meshMerger.Vertices, Has.Length.EqualTo(2));
|
||||
Assert.That(_meshMerger.Vertices[0], Is.EqualTo(Vector3.one));
|
||||
Assert.That(_meshMerger.Vertices[1], Is.EqualTo(Vector3.forward));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TriangleIndicesAreOffsetToPointAtTheCorrespondingMeshes() {
|
||||
_meshMerger.Add(vertices: new Vector3[] { Vector3.right, Vector3.up },
|
||||
triangles: new int[] { 0, 1 });
|
||||
_meshMerger.Add(vertices: new Vector3[] { Vector3.forward, Vector3.zero },
|
||||
triangles: new int[] { 0, 1 });
|
||||
Assert.That(_meshMerger.Triangles, Has.Length.EqualTo(4));
|
||||
Assert.That(_meshMerger.Vertices[_meshMerger.Triangles[0]], Is.EqualTo(Vector3.right));
|
||||
Assert.That(_meshMerger.Vertices[_meshMerger.Triangles[1]], Is.EqualTo(Vector3.up));
|
||||
Assert.That(_meshMerger.Vertices[_meshMerger.Triangles[2]], Is.EqualTo(Vector3.forward));
|
||||
Assert.That(_meshMerger.Vertices[_meshMerger.Triangles[3]], Is.EqualTo(Vector3.zero));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TranslatingAddedVertices() {
|
||||
_meshMerger.AddAndTranslate(vertices: new Vector3[] { Vector3.zero }, triangles: new int[] {},
|
||||
translation: Vector3.right);
|
||||
_meshMerger.AddAndTranslate(vertices: new Vector3[] { Vector3.zero }, triangles: new int[] {},
|
||||
translation: Vector3.up);
|
||||
Assert.That(_meshMerger.Vertices[0], Is.EqualTo(Vector3.right));
|
||||
Assert.That(_meshMerger.Vertices[1], Is.EqualTo(Vector3.up));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d757196bb4bbd7d0d8eddc399cfeddef
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,104 @@
|
||||
// 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 MjBoxShapeTests {
|
||||
private GameObject _owner;
|
||||
private MjShapeComponent _shape;
|
||||
private XmlDocument _doc;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_owner = new GameObject("owner");
|
||||
_shape = _owner.AddComponent<MjSite>();
|
||||
_shape.ShapeType = MjShapeComponent.ShapeTypes.Box;
|
||||
_shape.Box.Extents = Vector3.one;
|
||||
_doc = new XmlDocument();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
UnityEngine.Object.DestroyImmediate(_owner);
|
||||
}
|
||||
|
||||
[TestCase(1, 2, 3, "1 3 2")]
|
||||
public void BoxSize(float x, float y, float z, string expectedResult) {
|
||||
var mjcf = (XmlElement)_doc.AppendChild(_doc.CreateElement("test"));
|
||||
_shape.Box.Extents = new Vector3(x, y, z);
|
||||
_shape.ShapeToMjcf(mjcf, _owner.transform);
|
||||
Assert.That(_doc.OuterXml, Does.Contain("size=\"" + expectedResult + "\""));
|
||||
}
|
||||
|
||||
[TestCase(0.5f, "0.5 0.5 0.5")]
|
||||
[TestCase(2.0f, "2 2 2")]
|
||||
public void EffectOfUniformScaling(float uniformScale, string expectedResult) {
|
||||
var mjcf = (XmlElement)_doc.AppendChild(_doc.CreateElement("test"));
|
||||
_owner.transform.localScale = Vector3.one * uniformScale;
|
||||
_shape.ShapeToMjcf(mjcf, _owner.transform);
|
||||
Assert.That(_doc.OuterXml, Does.Contain("size=\"" + expectedResult + "\""));
|
||||
}
|
||||
|
||||
[TestCase(2, 3, 4, "2 4 3")]
|
||||
public void EffectOfNonUniformScaling(float x, float y, float z, string expectedResult) {
|
||||
var mjcf = (XmlElement)_doc.AppendChild(_doc.CreateElement("test"));
|
||||
_owner.transform.localScale = new Vector3(x, y, z);
|
||||
_shape.ShapeToMjcf(mjcf, _owner.transform);
|
||||
Assert.That(_doc.OuterXml, Does.Contain("size=\"" + expectedResult + "\""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParsingSettings() {
|
||||
var mjcf = (XmlElement)_doc.AppendChild(_doc.CreateElement("test"));
|
||||
mjcf.SetAttribute("type", "box");
|
||||
mjcf.SetAttribute("size", "0.1 0.2 0.3");
|
||||
_shape.ShapeFromMjcf(mjcf);
|
||||
Assert.That(_shape.ShapeType, Is.EqualTo(MjShapeComponent.ShapeTypes.Box));
|
||||
Assert.That(_shape.Box.Extents, Is.EqualTo(new Vector3(0.1f, 0.3f, 0.2f)));
|
||||
}
|
||||
|
||||
[TestCase("0 0 0 0 0 1", 0.5f, 0.5f, 0.5f)]
|
||||
[TestCase("0 0 0 0 1 0", 0.5f, 0.5f, 0.5f)]
|
||||
[TestCase("0 0 0 1 0 0", 0.5f, 0.5f, 0.5f)]
|
||||
[TestCase("0 0 -1 0 0 1", 1, 1, 1)]
|
||||
[TestCase("0 -1 0 0 1 0", 1, 1, 1)]
|
||||
[TestCase("-1 0 0 1 0 0", 1, 1, 1)]
|
||||
public void FromToSizeSpecificationIsOrientationAgnostic(string fromToStr, float x, float y,
|
||||
float z) {
|
||||
var mjcf = (XmlElement)_doc.AppendChild(_doc.CreateElement("test"));
|
||||
mjcf.SetAttribute("type", "box");
|
||||
mjcf.SetAttribute("fromto", fromToStr);
|
||||
_shape.ShapeFromMjcf(mjcf);
|
||||
Assert.That(_shape.Box.Extents, Is.EqualTo(new Vector3(x, y, z)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FromToSizeSpecificationUsesMagnitudeOfVectorAsSizeBase() {
|
||||
var mjcf = (XmlElement)_doc.AppendChild(_doc.CreateElement("test"));
|
||||
mjcf.SetAttribute("type", "box");
|
||||
mjcf.SetAttribute("fromto", "-1 0 0 0 0 1");
|
||||
_shape.ShapeFromMjcf(mjcf);
|
||||
Assert.That((_shape.Box.Extents - new Vector3(0.707f, 0.707f, 0.707f)).magnitude,
|
||||
Is.EqualTo(0).Within(1e-3f));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aec19e8fe359a4415a24f826721d003c
|
||||
timeCreated: 1547644312
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,96 @@
|
||||
// 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 MjCapsuleShapeTests {
|
||||
private GameObject _owner;
|
||||
private MjShapeComponent _shape;
|
||||
private XmlDocument _doc;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_owner = new GameObject("owner");
|
||||
_shape = _owner.AddComponent<MjSite>();
|
||||
_shape.ShapeType = MjShapeComponent.ShapeTypes.Capsule;
|
||||
_doc = new XmlDocument();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
UnityEngine.Object.DestroyImmediate(_owner);
|
||||
}
|
||||
|
||||
[TestCase(0.5f, 0.5f, "0.5 0.5")]
|
||||
[TestCase(1.5f, 1.5f, "1.5 1.5")]
|
||||
public void CapsuleSize(float radius, float halfHeight, string expectedResult) {
|
||||
var mjcf = (XmlElement)_doc.AppendChild(_doc.CreateElement("test"));
|
||||
_shape.Capsule.Radius = radius;
|
||||
_shape.Capsule.HalfHeight = halfHeight;
|
||||
_shape.ShapeToMjcf(mjcf, _owner.transform);
|
||||
Assert.That(_doc.OuterXml, Does.Contain("size=\"" + expectedResult + "\""));
|
||||
}
|
||||
|
||||
[TestCase(0.5f, "0.5 1")]
|
||||
[TestCase(2.0f, "2 4")]
|
||||
public void EffectOfUniformScaling(float uniformScale, string expectedResult) {
|
||||
var mjcf = (XmlElement)_doc.AppendChild(_doc.CreateElement("test"));
|
||||
_shape.Capsule.Radius = 1.0f;
|
||||
_shape.Capsule.HalfHeight = 2.0f;
|
||||
_owner.transform.localScale = Vector3.one * uniformScale;
|
||||
_shape.ShapeToMjcf(mjcf, _owner.transform);
|
||||
Assert.That(_doc.OuterXml, Does.Contain("size=\"" + expectedResult + "\""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParsingSettings() {
|
||||
var mjcf = (XmlElement)_doc.AppendChild(_doc.CreateElement("test"));
|
||||
mjcf.SetAttribute("type", "capsule");
|
||||
mjcf.SetAttribute("size", "1.5 2.4");
|
||||
_shape.ShapeFromMjcf(mjcf);
|
||||
Assert.That(_shape.ShapeType, Is.EqualTo(MjShapeComponent.ShapeTypes.Capsule));
|
||||
Assert.That(_shape.Capsule.Radius, Is.EqualTo(1.5f));
|
||||
Assert.That(_shape.Capsule.HalfHeight, Is.EqualTo(2.4f));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FromToSizeSpecificationOverridesHeightOnly() {
|
||||
var mjcf = (XmlElement)_doc.AppendChild(_doc.CreateElement("test"));
|
||||
mjcf.SetAttribute("type", "capsule");
|
||||
mjcf.SetAttribute("size", "5 1");
|
||||
mjcf.SetAttribute("fromto", "0 0 0 0 0 3");
|
||||
_shape.ShapeFromMjcf(mjcf);
|
||||
Assert.That(_shape.Capsule.Radius, Is.EqualTo(5));
|
||||
Assert.That(_shape.Capsule.HalfHeight, Is.EqualTo(1.5f));
|
||||
}
|
||||
|
||||
[TestCase("0 0 -1 0 0 2", 1.5f)]
|
||||
[TestCase("1 0 0 3 0 0", 1)]
|
||||
public void FromToHeightMeasuredAsSegmentLength(string fromToStr, float expectedHeight) {
|
||||
var mjcf = (XmlElement)_doc.AppendChild(_doc.CreateElement("test"));
|
||||
mjcf.SetAttribute("type", "capsule");
|
||||
mjcf.SetAttribute("fromto", fromToStr);
|
||||
_shape.ShapeFromMjcf(mjcf);
|
||||
Assert.That(_shape.Capsule.HalfHeight, Is.EqualTo(expectedHeight));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9871b9790c4594f638a5bd00d660e897
|
||||
timeCreated: 1547635214
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,96 @@
|
||||
// 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 MjCylinderShapeTests {
|
||||
private GameObject _owner;
|
||||
private MjShapeComponent _shape;
|
||||
private XmlDocument _doc;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_owner = new GameObject("owner");
|
||||
_shape = _owner.AddComponent<MjSite>();
|
||||
_shape.ShapeType = MjShapeComponent.ShapeTypes.Cylinder;
|
||||
_doc = new XmlDocument();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
UnityEngine.Object.DestroyImmediate(_owner);
|
||||
}
|
||||
|
||||
[TestCase(0.5f, 0.5f, "0.5 0.5")]
|
||||
[TestCase(1.5f, 1.5f, "1.5 1.5")]
|
||||
public void CylinderSize(float radius, float height, string expectedResult) {
|
||||
var mjcf = (XmlElement)_doc.AppendChild(_doc.CreateElement("test"));
|
||||
_shape.Cylinder.Radius = radius;
|
||||
_shape.Cylinder.HalfHeight = height;
|
||||
_shape.ShapeToMjcf(mjcf, _owner.transform);
|
||||
Assert.That(_doc.OuterXml, Does.Contain("size=\"" + expectedResult + "\""));
|
||||
}
|
||||
|
||||
[TestCase(0.5f, "0.5 1")]
|
||||
[TestCase(2.0f, "2 4")]
|
||||
public void EffectOfUniformScaling(float uniformScale, string expectedResult) {
|
||||
var mjcf = (XmlElement)_doc.AppendChild(_doc.CreateElement("test"));
|
||||
_shape.Cylinder.Radius = 1.0f;
|
||||
_shape.Cylinder.HalfHeight = 2.0f;
|
||||
_owner.transform.localScale = Vector3.one * uniformScale;
|
||||
_shape.ShapeToMjcf(mjcf, _owner.transform);
|
||||
Assert.That(_doc.OuterXml, Does.Contain("size=\"" + expectedResult + "\""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParsingSettings() {
|
||||
var mjcf = (XmlElement)_doc.AppendChild(_doc.CreateElement("test"));
|
||||
mjcf.SetAttribute("type", "cylinder");
|
||||
mjcf.SetAttribute("size", "1.5 2.4");
|
||||
_shape.ShapeFromMjcf(mjcf);
|
||||
Assert.That(_shape.ShapeType, Is.EqualTo(MjShapeComponent.ShapeTypes.Cylinder));
|
||||
Assert.That(_shape.Cylinder.Radius, Is.EqualTo(1.5f));
|
||||
Assert.That(_shape.Cylinder.HalfHeight, Is.EqualTo(2.4f));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FromToSizeSpecificationOverridesHeightOnly() {
|
||||
var mjcf = (XmlElement)_doc.AppendChild(_doc.CreateElement("test"));
|
||||
mjcf.SetAttribute("type", "cylinder");
|
||||
mjcf.SetAttribute("size", "5 1");
|
||||
mjcf.SetAttribute("fromto", "0 0 0 0 0 3");
|
||||
_shape.ShapeFromMjcf(mjcf);
|
||||
Assert.That(_shape.Cylinder.Radius, Is.EqualTo(5));
|
||||
Assert.That(_shape.Cylinder.HalfHeight, Is.EqualTo(1.5f));
|
||||
}
|
||||
|
||||
[TestCase("0 0 -1 0 0 2", 1.5f)]
|
||||
[TestCase("1 0 0 3 0 0", 1)]
|
||||
public void FromToHeightMeasuredAsSegmentLength(string fromToStr, float expectedHeight) {
|
||||
var mjcf = (XmlElement)_doc.AppendChild(_doc.CreateElement("test"));
|
||||
mjcf.SetAttribute("type", "cylinder");
|
||||
mjcf.SetAttribute("fromto", fromToStr);
|
||||
_shape.ShapeFromMjcf(mjcf);
|
||||
Assert.That(_shape.Cylinder.HalfHeight, Is.EqualTo(expectedHeight));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cb7edb2ed8966435991a52ed46024185
|
||||
timeCreated: 1547729698
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,104 @@
|
||||
// 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 MjEllipsoidShapeTests {
|
||||
private GameObject _owner;
|
||||
private MjShapeComponent _shape;
|
||||
private XmlDocument _doc;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_owner = new GameObject("owner");
|
||||
_shape = _owner.AddComponent<MjSite>();
|
||||
_shape.ShapeType = MjShapeComponent.ShapeTypes.Ellipsoid;
|
||||
_shape.Ellipsoid.Radiuses = Vector3.one;
|
||||
_doc = new XmlDocument();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
UnityEngine.Object.DestroyImmediate(_owner);
|
||||
}
|
||||
|
||||
[TestCase(1, 2, 3, "1 3 2")]
|
||||
public void EllipsoidSize(float x, float y, float z, string expectedResult) {
|
||||
var mjcf = (XmlElement)_doc.AppendChild(_doc.CreateElement("test"));
|
||||
_shape.Ellipsoid.Radiuses = new Vector3(x, y, z);
|
||||
_shape.ShapeToMjcf(mjcf, _owner.transform);
|
||||
Assert.That(_doc.OuterXml, Does.Contain("size=\"" + expectedResult + "\""));
|
||||
}
|
||||
|
||||
[TestCase(0.5f, "0.5 0.5 0.5")]
|
||||
[TestCase(2.0f, "2 2 2")]
|
||||
public void EffectOfUniformScaling(float uniformScale, string expectedResult) {
|
||||
var mjcf = (XmlElement)_doc.AppendChild(_doc.CreateElement("test"));
|
||||
_owner.transform.localScale = Vector3.one * uniformScale;
|
||||
_shape.ShapeToMjcf(mjcf, _owner.transform);
|
||||
Assert.That(_doc.OuterXml, Does.Contain("size=\"" + expectedResult + "\""));
|
||||
}
|
||||
|
||||
[TestCase(2, 3, 4, "2 4 3")]
|
||||
public void EffectOfNonUniformScaling(float x, float y, float z, string expectedResult) {
|
||||
var mjcf = (XmlElement)_doc.AppendChild(_doc.CreateElement("test"));
|
||||
_owner.transform.localScale = new Vector3(x, y, z);
|
||||
_shape.ShapeToMjcf(mjcf, _owner.transform);
|
||||
Assert.That(_doc.OuterXml, Does.Contain("size=\"" + expectedResult + "\""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParsingSettings() {
|
||||
var mjcf = (XmlElement)_doc.AppendChild(_doc.CreateElement("test"));
|
||||
mjcf.SetAttribute("type", "ellipsoid");
|
||||
mjcf.SetAttribute("size", "0.1 0.2 0.3");
|
||||
_shape.ShapeFromMjcf(mjcf);
|
||||
Assert.That(_shape.ShapeType, Is.EqualTo(MjShapeComponent.ShapeTypes.Ellipsoid));
|
||||
Assert.That(_shape.Ellipsoid.Radiuses, Is.EqualTo(new Vector3(0.1f, 0.3f, 0.2f)));
|
||||
}
|
||||
|
||||
[TestCase("0 0 0 0 0 1", 0.5f, 0.5f, 0.5f)]
|
||||
[TestCase("0 0 0 0 1 0", 0.5f, 0.5f, 0.5f)]
|
||||
[TestCase("0 0 0 1 0 0", 0.5f, 0.5f, 0.5f)]
|
||||
[TestCase("0 0 -1 0 0 1", 1, 1, 1)]
|
||||
[TestCase("0 -1 0 0 1 0", 1, 1, 1)]
|
||||
[TestCase("-1 0 0 1 0 0", 1, 1, 1)]
|
||||
public void FromToSizeSpecificationIsOrientationAgnostic(string fromToStr, float x, float y,
|
||||
float z) {
|
||||
var mjcf = (XmlElement)_doc.AppendChild(_doc.CreateElement("test"));
|
||||
mjcf.SetAttribute("type", "ellipsoid");
|
||||
mjcf.SetAttribute("fromto", fromToStr);
|
||||
_shape.ShapeFromMjcf(mjcf);
|
||||
Assert.That(_shape.Ellipsoid.Radiuses, Is.EqualTo(new Vector3(x, y, z)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FromToSizeSpecificationUsesMagnitudeOfVectorAsSizeBase() {
|
||||
var mjcf = (XmlElement)_doc.AppendChild(_doc.CreateElement("test"));
|
||||
mjcf.SetAttribute("type", "ellipsoid");
|
||||
mjcf.SetAttribute("fromto", "-1 0 0 0 0 1");
|
||||
_shape.ShapeFromMjcf(mjcf);
|
||||
Assert.That((_shape.Ellipsoid.Radiuses - new Vector3(0.707f, 0.707f, 0.707f)).magnitude,
|
||||
Is.EqualTo(0).Within(1e-3f));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8fe14b804de054f709bd186df6160648
|
||||
timeCreated: 1547644312
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,270 @@
|
||||
// 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 NUnit.Framework;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Mujoco {
|
||||
|
||||
[TestFixture]
|
||||
public class MjGizmosDrawArcTests {
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
MjGizmos.DrawLine = MockDrawLine;
|
||||
MjGizmos.NumCircleSegments = 4;
|
||||
_lineFrom = new List<Vector3>();
|
||||
_lineTo = new List<Vector3>();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
MjGizmos.DrawLine = Gizmos.DrawLine;
|
||||
MjGizmos.NumCircleSegments = 32;
|
||||
}
|
||||
|
||||
private List<Vector3> _lineFrom;
|
||||
private List<Vector3> _lineTo;
|
||||
|
||||
private void MockDrawLine(Vector3 from, Vector3 to) {
|
||||
_lineFrom.Add(from);
|
||||
_lineTo.Add(to);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LineCountOfDrawnCircle() {
|
||||
MjGizmos.DrawArc(Vector3.zero, 1.0f, Vector3.up, 1.0f, 0.0f);
|
||||
Assert.That(_lineFrom, Has.Count.EqualTo(MjGizmos.NumCircleSegments));
|
||||
Assert.That(_lineTo, Has.Count.EqualTo(MjGizmos.NumCircleSegments));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LineAdjacencyOfDrawnCircle() {
|
||||
MjGizmos.DrawArc(Vector3.zero, 1.0f, Vector3.up, 1.0f, 0.0f);
|
||||
Assert.That((_lineFrom[0] - _lineTo[3]).magnitude, Is.LessThan(1e-3f));
|
||||
Assert.That((_lineFrom[1] - _lineTo[0]).magnitude, Is.LessThan(1e-3f));
|
||||
Assert.That((_lineFrom[2] - _lineTo[1]).magnitude, Is.LessThan(1e-3f));
|
||||
Assert.That((_lineFrom[3] - _lineTo[2]).magnitude, Is.LessThan(1e-3f));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CircleVertexPositions() {
|
||||
MjGizmos.DrawArc(Vector3.zero, 1.0f, Vector3.up, 1.0f, 0.0f);
|
||||
Assert.That((_lineFrom[0] - new Vector3(0, 0, -1)).magnitude, Is.LessThan(1e-3f));
|
||||
Assert.That((_lineFrom[1] - new Vector3(-1, 0, 0)).magnitude, Is.LessThan(1e-3f));
|
||||
Assert.That((_lineFrom[2] - new Vector3(0, 0, 1)).magnitude, Is.LessThan(1e-3f));
|
||||
Assert.That((_lineFrom[3] - new Vector3(1, 0, 0)).magnitude, Is.LessThan(1e-3f));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void VerticesOfOffsetCircle() {
|
||||
MjGizmos.DrawArc(Vector3.one, 1.0f, Vector3.up, 1.0f, 0.0f);
|
||||
Assert.That((_lineFrom[0] - new Vector3(1, 1, 0)).magnitude, Is.LessThan(1e-3f));
|
||||
Assert.That((_lineFrom[1] - new Vector3(0, 1, 1)).magnitude, Is.LessThan(1e-3f));
|
||||
Assert.That((_lineFrom[2] - new Vector3(1, 1, 2)).magnitude, Is.LessThan(1e-3f));
|
||||
Assert.That((_lineFrom[3] - new Vector3(2, 1, 1)).magnitude, Is.LessThan(1e-3f));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DrawingRotatedCircle() {
|
||||
MjGizmos.DrawArc(Vector3.zero, 1.0f, Vector3.right, 1.0f, 0.0f);
|
||||
Assert.That((_lineFrom[0] - new Vector3(0, 0, 1)).magnitude, Is.LessThan(1e-3f));
|
||||
Assert.That((_lineFrom[1] - new Vector3(0, -1, 0)).magnitude, Is.LessThan(1e-3f));
|
||||
Assert.That((_lineFrom[2] - new Vector3(0, 0, -1)).magnitude, Is.LessThan(1e-3f));
|
||||
Assert.That((_lineFrom[3] - new Vector3(0, 1, 0)).magnitude, Is.LessThan(1e-3f));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DrawingHalfCircle() {
|
||||
MjGizmos.DrawArc(Vector3.zero, 1.0f, Vector3.up, 0.25f, 0.0f);
|
||||
Assert.That(_lineFrom, Has.Count.EqualTo(1));
|
||||
Assert.That(_lineTo, Has.Count.EqualTo(1));
|
||||
Assert.That((_lineFrom[0] - new Vector3(0, 0, -1)).magnitude, Is.LessThan(1e-3f));
|
||||
Assert.That((_lineTo[0] - new Vector3(-1, 0, 0)).magnitude, Is.LessThan(1e-3f));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DrawingHalfCircleWithOffsetCircumference() {
|
||||
MjGizmos.DrawArc(Vector3.zero, 1.0f, Vector3.up, 0.25f, 90);
|
||||
Assert.That((_lineFrom[0] - new Vector3(-1, 0, 0)).magnitude, Is.LessThan(1e-3f));
|
||||
Assert.That((_lineTo[0] - new Vector3(0, 0, 1)).magnitude, Is.LessThan(1e-3f));
|
||||
}
|
||||
}
|
||||
|
||||
[TestFixture]
|
||||
public class MjGizmosCapsuleTests {
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
MjGizmos.DrawLine = MockDrawLine;
|
||||
MjGizmos.DrawArc = MockDrawArc;
|
||||
MjGizmos.NumCircleSegments = 4;
|
||||
_arc = new List<Tuple<Vector3, float, Vector3, float, float>>();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
MjGizmos.DrawLine = Gizmos.DrawLine;
|
||||
MjGizmos.DrawArc = MjGizmos.DrawArcInternal;
|
||||
MjGizmos.NumCircleSegments = 32;
|
||||
}
|
||||
|
||||
private List<Tuple<Vector3, float, Vector3, float, float>> _arc;
|
||||
|
||||
private void MockDrawLine(Vector3 from, Vector3 to) {}
|
||||
|
||||
private void MockDrawArc(Vector3 position, float radius, Vector3 axis, float length,
|
||||
float startAngle) {
|
||||
_arc.Add(Tuple.Create(position, radius, axis, length, startAngle));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NumberOfArcsUsedToDrawCapsule() {
|
||||
MjGizmos.DrawWireCapsule(Vector3.zero, 0.5f, 1.0f);
|
||||
Assert.That(_arc, Has.Count.EqualTo(6));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CapsuleBaseCirclesOrigins() {
|
||||
MjGizmos.DrawWireCapsule(Vector3.zero, 0.5f, 1.0f);
|
||||
Assert.That((_arc[0].Item1 - new Vector3(0, 0.5f, 0)).magnitude, Is.LessThan(1e-3f));
|
||||
Assert.That((_arc[1].Item1 - new Vector3(0, -0.5f, 0)).magnitude, Is.LessThan(1e-3f));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CapsuleBaseCirclesRadiuses() {
|
||||
MjGizmos.DrawWireCapsule(Vector3.zero, 0.5f, 1.0f);
|
||||
Assert.That(_arc[0].Item2, Is.EqualTo(0.5f));
|
||||
Assert.That(_arc[1].Item2, Is.EqualTo(0.5f));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CapsuleBaseArcsOrigins() {
|
||||
MjGizmos.DrawWireCapsule(Vector3.zero, 0.5f, 1.0f);
|
||||
Assert.That((_arc[2].Item1 - new Vector3(0, -0.5f, 0)).magnitude, Is.LessThan(1e-3f));
|
||||
Assert.That((_arc[3].Item1 - new Vector3(0, 0.5f, 0)).magnitude, Is.LessThan(1e-3f));
|
||||
Assert.That((_arc[4].Item1 - new Vector3(0, 0.5f, 0)).magnitude, Is.LessThan(1e-3f));
|
||||
Assert.That((_arc[5].Item1 - new Vector3(0, -0.5f, 0)).magnitude, Is.LessThan(1e-3f));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CapsuleBaseArcsRadiuses() {
|
||||
MjGizmos.DrawWireCapsule(Vector3.zero, 0.5f, 1.0f);
|
||||
Assert.That(_arc[2].Item2, Is.EqualTo(0.5f));
|
||||
Assert.That(_arc[3].Item2, Is.EqualTo(0.5f));
|
||||
Assert.That(_arc[4].Item2, Is.EqualTo(0.5f));
|
||||
Assert.That(_arc[5].Item2, Is.EqualTo(0.5f));
|
||||
}
|
||||
}
|
||||
|
||||
[TestFixture]
|
||||
public class MjGizmosCylinderTests {
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
MjGizmos.DrawLine = MockDrawLine;
|
||||
MjGizmos.DrawArc = MockDrawArc;
|
||||
MjGizmos.NumCircleSegments = 4;
|
||||
_arc = new List<Tuple<Vector3, float, Vector3, float, float>>();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
MjGizmos.DrawLine = Gizmos.DrawLine;
|
||||
MjGizmos.DrawArc = MjGizmos.DrawArcInternal;
|
||||
MjGizmos.NumCircleSegments = 32;
|
||||
}
|
||||
|
||||
private List<Tuple<Vector3, float, Vector3, float, float>> _arc;
|
||||
|
||||
private void MockDrawLine(Vector3 from, Vector3 to) {}
|
||||
|
||||
private void MockDrawArc(Vector3 position, float radius, Vector3 axis, float length,
|
||||
float startAngle) {
|
||||
_arc.Add(Tuple.Create(position, radius, axis, length, startAngle));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NumberOfArcsUsedToDrawCylinder() {
|
||||
MjGizmos.DrawWireCylinder(Vector3.zero, 0.5f, 1.0f);
|
||||
Assert.That(_arc, Has.Count.EqualTo(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CylinderBaseCirclesOrigins() {
|
||||
MjGizmos.DrawWireCylinder(Vector3.zero, 0.5f, 1.0f);
|
||||
Assert.That((_arc[0].Item1 - new Vector3(0, 0.5f, 0)).magnitude, Is.LessThan(1e-3f));
|
||||
Assert.That((_arc[1].Item1 - new Vector3(0, -0.5f, 0)).magnitude, Is.LessThan(1e-3f));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CylinderBaseCirclesRadiuses() {
|
||||
MjGizmos.DrawWireCylinder(Vector3.zero, 0.5f, 1.0f);
|
||||
Assert.That(_arc[0].Item2, Is.EqualTo(0.5f));
|
||||
Assert.That(_arc[1].Item2, Is.EqualTo(0.5f));
|
||||
}
|
||||
}
|
||||
|
||||
[TestFixture]
|
||||
public class MjGizmosPlaneTests {
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
MjGizmos.DrawLine = MockDrawLine;
|
||||
_lines = new List<Tuple<Vector3, Vector3>>();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
MjGizmos.DrawLine = Gizmos.DrawLine;
|
||||
_lines.Clear();
|
||||
}
|
||||
|
||||
private List<Tuple<Vector3, Vector3>> _lines;
|
||||
|
||||
private void MockDrawLine(Vector3 start, Vector3 end) {
|
||||
_lines.Add(Tuple.Create(start, end));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DrawingPlaneAroundArbitraryCenter() {
|
||||
MjGizmos.DrawWirePlane(new Vector3(1, 2, 3), 1, 1);
|
||||
Assert.That(_lines, Has.Count.EqualTo(5));
|
||||
Assert.That(_lines[0].Item1, Is.EqualTo(new Vector3(0.5f, 2, 2.5f)));
|
||||
Assert.That(_lines[0].Item2, Is.EqualTo(new Vector3(1.5f, 2, 2.5f)));
|
||||
Assert.That(_lines[1].Item1, Is.EqualTo(new Vector3(1.5f, 2, 2.5f)));
|
||||
Assert.That(_lines[1].Item2, Is.EqualTo(new Vector3(1.5f, 2, 3.5f)));
|
||||
Assert.That(_lines[2].Item1, Is.EqualTo(new Vector3(1.5f, 2, 3.5f)));
|
||||
Assert.That(_lines[2].Item2, Is.EqualTo(new Vector3(0.5f, 2, 3.5f)));
|
||||
Assert.That(_lines[3].Item1, Is.EqualTo(new Vector3(0.5f, 2, 3.5f)));
|
||||
Assert.That(_lines[3].Item2, Is.EqualTo(new Vector3(0.5f, 2, 2.5f)));
|
||||
Assert.That(_lines[4].Item1, Is.EqualTo(new Vector3(0.5f, 2, 2.5f)));
|
||||
Assert.That(_lines[4].Item2, Is.EqualTo(new Vector3(1.5f, 2, 3.5f)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DrawingPlaneWithCorrectDimensions() {
|
||||
MjGizmos.DrawWirePlane(Vector3.zero, width: 2, height: 4);
|
||||
Assert.That(_lines[0].Item1, Is.EqualTo(new Vector3(-1, 0, -2)));
|
||||
Assert.That(_lines[0].Item2, Is.EqualTo(new Vector3(1, 0, -2)));
|
||||
Assert.That(_lines[1].Item1, Is.EqualTo(new Vector3(1, 0, -2)));
|
||||
Assert.That(_lines[1].Item2, Is.EqualTo(new Vector3(1, 0, 2)));
|
||||
Assert.That(_lines[2].Item1, Is.EqualTo(new Vector3(1, 0, 2)));
|
||||
Assert.That(_lines[2].Item2, Is.EqualTo(new Vector3(-1, 0, 2)));
|
||||
Assert.That(_lines[3].Item1, Is.EqualTo(new Vector3(-1, 0, 2)));
|
||||
Assert.That(_lines[3].Item2, Is.EqualTo(new Vector3(-1, 0, -2)));
|
||||
Assert.That(_lines[4].Item1, Is.EqualTo(new Vector3(-1, 0, -2)));
|
||||
Assert.That(_lines[4].Item2, Is.EqualTo(new Vector3(1, 0, 2)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a8a01c1e2d4304ce78d8efc6150f2f87
|
||||
timeCreated: 1536937372
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,78 @@
|
||||
// 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 MjPlaneShapeTests {
|
||||
private GameObject _owner;
|
||||
private MjShapeComponent _shape;
|
||||
private XmlDocument _doc;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_owner = new GameObject("owner");
|
||||
_shape = _owner.AddComponent<MjSite>();
|
||||
_shape.ShapeType = MjShapeComponent.ShapeTypes.Plane;
|
||||
_doc = new XmlDocument();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
UnityEngine.Object.DestroyImmediate(_owner);
|
||||
}
|
||||
|
||||
[TestCase(1, 2, "1 2 1")]
|
||||
public void PlaneSize(float x, float y, string expectedResult) {
|
||||
var mjcf = (XmlElement)_doc.AppendChild(_doc.CreateElement("test"));
|
||||
_shape.Plane.Extents = new Vector2(x, y);
|
||||
_shape.ShapeToMjcf(mjcf, _owner.transform);
|
||||
Assert.That(_doc.OuterXml, Does.Contain("size=\"" + expectedResult + "\""));
|
||||
}
|
||||
|
||||
[TestCase(0.5f, "0.5 0.5 0.5")]
|
||||
[TestCase(2.0f, "2 2 2")]
|
||||
public void EffectOfUniformScaling(float uniformScale, string expectedResult) {
|
||||
var mjcf = (XmlElement)_doc.AppendChild(_doc.CreateElement("test"));
|
||||
_owner.transform.localScale = Vector3.one * uniformScale;
|
||||
_shape.ShapeToMjcf(mjcf, _owner.transform);
|
||||
Assert.That(_doc.OuterXml, Does.Contain("size=\"" + expectedResult + "\""));
|
||||
}
|
||||
|
||||
[TestCase(2, 3, 4, "2 3 4")]
|
||||
public void EffectOfNonUniformScaling(float x, float y, float z, string expectedResult) {
|
||||
var mjcf = (XmlElement)_doc.AppendChild(_doc.CreateElement("test"));
|
||||
_owner.transform.localScale = new Vector3(x, y, z);
|
||||
_shape.ShapeToMjcf(mjcf, _owner.transform);
|
||||
Assert.That(_doc.OuterXml, Does.Contain("size=\"" + expectedResult + "\""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParsingSettings() {
|
||||
var mjcf = (XmlElement)_doc.AppendChild(_doc.CreateElement("test"));
|
||||
mjcf.SetAttribute("type", "plane");
|
||||
mjcf.SetAttribute("size", "0.1 0.2 0.3");
|
||||
_shape.ShapeFromMjcf(mjcf);
|
||||
Assert.That(_shape.ShapeType, Is.EqualTo(MjShapeComponent.ShapeTypes.Plane));
|
||||
Assert.That(_shape.Plane.Extents, Is.EqualTo(new Vector2(0.1f, 0.2f)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b37384fec57304bfbb4edd50d7f2f80a
|
||||
timeCreated: 1547644312
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,72 @@
|
||||
// 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 MjSphereShapeTests {
|
||||
private GameObject _owner;
|
||||
private MjShapeComponent _shape;
|
||||
private XmlDocument _doc;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_owner = new GameObject("owner");
|
||||
_shape = _owner.AddComponent<MjSite>();
|
||||
_shape.ShapeType = MjShapeComponent.ShapeTypes.Sphere;
|
||||
_shape.Sphere.Radius = 1.0f;
|
||||
_doc = new XmlDocument();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
UnityEngine.Object.DestroyImmediate(_owner);
|
||||
}
|
||||
|
||||
[TestCase(2.0f, "2")]
|
||||
[TestCase(1.5f, "1.5")]
|
||||
public void XmlSizeForUnscaledSphere(float radius, string expectedResult) {
|
||||
var mjcf = (XmlElement)_doc.AppendChild(_doc.CreateElement("test"));
|
||||
_shape.Sphere.Radius = radius;
|
||||
_shape.ShapeToMjcf(mjcf, _owner.transform);
|
||||
Assert.That(_doc.OuterXml, Does.Contain("size=\"" + expectedResult + "\""));
|
||||
}
|
||||
|
||||
[TestCase(0.5f, "0.5")]
|
||||
[TestCase(2.0f, "2")]
|
||||
public void EffectOfUniformScaling(float uniformScale, string expectedResult) {
|
||||
var mjcf = (XmlElement)_doc.AppendChild(_doc.CreateElement("test"));
|
||||
_owner.transform.localScale = Vector3.one * uniformScale;
|
||||
_shape.ShapeToMjcf(mjcf, _owner.transform);
|
||||
Assert.That(_doc.OuterXml, Does.Contain("size=\"" + expectedResult + "\""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParsingSettings() {
|
||||
var mjcf = (XmlElement)_doc.AppendChild(_doc.CreateElement("test"));
|
||||
mjcf.SetAttribute("type", "sphere");
|
||||
mjcf.SetAttribute("size", "0.75");
|
||||
_shape.ShapeFromMjcf(mjcf);
|
||||
Assert.That(_shape.ShapeType, Is.EqualTo(MjShapeComponent.ShapeTypes.Sphere));
|
||||
Assert.That(_shape.Sphere.Radius, Is.EqualTo(0.75f));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 11e6a66435b9b4c79b38438dfe92b14d
|
||||
timeCreated: 1547635214
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7a0617b3ff610c7f1929e31ec82c7e75
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,60 @@
|
||||
// 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 MjFixedTendonTests {
|
||||
private MjHingeJoint _joint1;
|
||||
private MjHingeJoint _joint2;
|
||||
private MjFixedTendon _tendon;
|
||||
private XmlDocument _doc;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_joint1 = new GameObject("joint1").AddComponent<MjHingeJoint>();
|
||||
_joint2 = new GameObject("joint2").AddComponent<MjHingeJoint>();
|
||||
_tendon = new GameObject("tendon").AddComponent<MjFixedTendon>();
|
||||
_doc = new XmlDocument();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
UnityEngine.Object.DestroyImmediate(_tendon.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(_joint1.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(_joint2.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(MjScene.Instance);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParseAllSettings() {
|
||||
_doc.LoadXml("<fixed range='3 4'>" + "<joint joint='joint1' coef='1'/>" +
|
||||
"<joint joint='joint2' coef='2'/>" + "</fixed>");
|
||||
_tendon.ParseMjcf(_doc.GetElementsByTagName("fixed")[0] as XmlElement);
|
||||
Assert.That(_tendon.RangeLower, Is.EqualTo(3));
|
||||
Assert.That(_tendon.RangeUpper, Is.EqualTo(4));
|
||||
Assert.That(_tendon.JointList.Count, Is.EqualTo(2));
|
||||
Assert.That(_tendon.JointList[0].Joint, Is.EqualTo(_joint1));
|
||||
Assert.That(_tendon.JointList[0].Coefficient, Is.EqualTo(1.0f));
|
||||
Assert.That(_tendon.JointList[1].Joint, Is.EqualTo(_joint2));
|
||||
Assert.That(_tendon.JointList[1].Coefficient, Is.EqualTo(2.0f));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 839d86acac1494dba9a7617f96ba27df
|
||||
timeCreated: 1550658312
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,56 @@
|
||||
// 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 MjSpatialTendonTests {
|
||||
private MjSite _site1;
|
||||
private MjSite _site2;
|
||||
private MjSpatialTendon _tendon;
|
||||
private XmlDocument _doc;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_site1 = new GameObject("site1").AddComponent<MjSite>();
|
||||
_site2 = new GameObject("site2").AddComponent<MjSite>();
|
||||
_tendon = new GameObject("tendon").AddComponent<MjSpatialTendon>();
|
||||
_doc = new XmlDocument();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
UnityEngine.Object.DestroyImmediate(_tendon.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(_site1.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(_site2.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(MjScene.Instance);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParseAllSettings() {
|
||||
_doc.LoadXml("<spatial>" + "<site site='site1'/>" +
|
||||
"<site site='site2'/>" + "</spatial>");
|
||||
_tendon.ParseMjcf(_doc.GetElementsByTagName("spatial")[0] as XmlElement);
|
||||
Assert.That(_tendon.ViapointsList.Count, Is.EqualTo(2));
|
||||
Assert.That(_tendon.ViapointsList[0].Site, Is.EqualTo(_site1));
|
||||
Assert.That(_tendon.ViapointsList[1].Site, Is.EqualTo(_site2));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e8324e6aceb78a067801d2bc304e4a27
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user