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,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.
|
||||
|
||||
#if UNITY_EDITOR
|
||||
|
||||
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 MjJointStateTests {
|
||||
private MjBody _body;
|
||||
private MjHingeJoint _joint;
|
||||
private MjInertial _inertial;
|
||||
private MjScene _scene;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_scene = MjScene.Instance;
|
||||
_body = new GameObject("body").AddComponent<MjBody>();
|
||||
_joint = new GameObject("joint").AddComponent<MjHingeJoint>();
|
||||
_joint.transform.parent = _body.transform;
|
||||
_inertial = new GameObject("inertial").AddComponent<MjInertial>();
|
||||
_inertial.transform.parent = _body.transform;
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
GameObject.DestroyImmediate(_joint.gameObject);
|
||||
GameObject.DestroyImmediate(_inertial.gameObject);
|
||||
GameObject.DestroyImmediate(_body.gameObject);
|
||||
GameObject.DestroyImmediate(MjScene.Instance);
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator JointVelocityChangesTheConfiguration() {
|
||||
_joint.Velocity = 10;
|
||||
_scene.CreateScene();
|
||||
yield return new WaitForFixedUpdate();
|
||||
Assert.That(_joint.Configuration, Is.Not.EqualTo(0));
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator JointConfigurationIsUsed() {
|
||||
_joint.Configuration = 10;
|
||||
_scene.CreateScene();
|
||||
yield return new WaitForFixedUpdate();
|
||||
Assert.That(_joint.Configuration, Is.Not.EqualTo(0));
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator JointConfigurationIsReadOnly() {
|
||||
_scene.CreateScene();
|
||||
_joint.Configuration = 10;
|
||||
yield return new WaitForFixedUpdate();
|
||||
Assert.That(_joint.Configuration, Is.EqualTo(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: acc8876e5b07dea7d825d8056331b4fa
|
||||
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.Linq;
|
||||
using System.Xml;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
namespace Mujoco {
|
||||
|
||||
[TestFixture]
|
||||
public class MjMeshFilterTests {
|
||||
|
||||
private MjGeom _geom;
|
||||
private MeshFilter _meshFilter;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
var gameObject = new GameObject(
|
||||
"object", typeof(MjGeom), typeof(MeshFilter), typeof(MjMeshFilter));
|
||||
_geom = gameObject.GetComponent<MjGeom>();
|
||||
_meshFilter = gameObject.GetComponent<MeshFilter>();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
UnityEngine.Object.DestroyImmediate(_geom.gameObject);
|
||||
GameObject.DestroyImmediate(MjScene.Instance);
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator NotMakingUnnecesaryMeshChanges() {
|
||||
yield return null;
|
||||
var firstMesh = _meshFilter.mesh;
|
||||
yield return null;
|
||||
var secondMesh = _meshFilter.mesh;
|
||||
Assert.That(firstMesh, Is.EqualTo(secondMesh));
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator DetectingChangesOfGeomShape() {
|
||||
yield return null;
|
||||
var firstMesh = _meshFilter.mesh;
|
||||
_geom.ShapeType = MjShapeComponent.ShapeTypes.Box;
|
||||
yield return null;
|
||||
var secondMesh = _meshFilter.mesh;
|
||||
Assert.That(firstMesh, Is.Not.EqualTo(secondMesh));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9ca786de0abc745edaa19ef76be40ffd
|
||||
timeCreated: 1539770521
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,106 @@
|
||||
// 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.
|
||||
|
||||
#if UNITY_EDITOR
|
||||
|
||||
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 MjScenePlayTests {
|
||||
private MjScene _scene;
|
||||
private MjBody _body;
|
||||
private MjInertial _inertia;
|
||||
private MjHingeJoint _joint;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_scene = MjScene.Instance;
|
||||
_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;
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
GameObject.DestroyImmediate(_joint.gameObject);
|
||||
GameObject.DestroyImmediate(_inertia.gameObject);
|
||||
GameObject.DestroyImmediate(_body.gameObject);
|
||||
GameObject.DestroyImmediate(_scene.gameObject);
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator RecreatedScenePreservesPosition() {
|
||||
_joint.Velocity = .1f;
|
||||
_scene.CreateScene();
|
||||
yield return null; // qpos moves, xpos stays at zero
|
||||
yield return null; // now xpos changed
|
||||
var tickedRotation = _body.transform.rotation;
|
||||
_scene.RecreateScene();
|
||||
// xpos is one step behind qpos, so it's not a perfect no-op, hence the high tolerance
|
||||
Assert.That(tickedRotation.x, Is.EqualTo(_body.transform.rotation.x).Within(1e-3f));
|
||||
Assert.That(tickedRotation.y, Is.EqualTo(_body.transform.rotation.y).Within(1e-3f));
|
||||
Assert.That(tickedRotation.z, Is.EqualTo(_body.transform.rotation.z).Within(1e-3f));
|
||||
Assert.That(tickedRotation.w, Is.EqualTo(_body.transform.rotation.w).Within(1e-3f));
|
||||
// Assert.That(tickedRotation, Is.EqualTo(_body.transform.rotation).Using(_quaternionComparer));
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator SceneRecreatedWithAddition() {
|
||||
_joint.Velocity = 1;
|
||||
_scene.CreateScene();
|
||||
Assert.That(_scene.SceneRecreationAtLateUpdateRequested, Is.False);
|
||||
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;
|
||||
yield return null; // call "start"
|
||||
Assert.That(_scene.SceneRecreationAtLateUpdateRequested, Is.True);
|
||||
yield return null; // call "lateUpdate"
|
||||
Assert.That(_scene.SceneRecreationAtLateUpdateRequested, Is.False);
|
||||
UnityEngine.Object.DestroyImmediate(inertia.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(joint.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(body.gameObject);
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator 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;
|
||||
yield return null;
|
||||
yield return null;
|
||||
Assert.That(_scene.SceneRecreationAtLateUpdateRequested, Is.False);
|
||||
UnityEngine.Object.DestroyImmediate(inertia.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(joint.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(body.gameObject);
|
||||
Assert.That(_scene.SceneRecreationAtLateUpdateRequested, Is.True);
|
||||
yield return null; // should result in a new scene
|
||||
Assert.That(_scene.SceneRecreationAtLateUpdateRequested, Is.False);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5235f153ea7908fad80b5c28b3978ac4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,67 @@
|
||||
// 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.
|
||||
|
||||
#if UNITY_EDITOR
|
||||
|
||||
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 MjSiteStateSyncTests {
|
||||
private MjBody _body;
|
||||
private MjSite _site;
|
||||
private MjScene _scene;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_scene = MjScene.Instance;
|
||||
_body = new GameObject("body").AddComponent<MjBody>();
|
||||
_site = new GameObject("site").AddComponent<MjSite>();
|
||||
_site.transform.parent = _body.transform;
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
GameObject.DestroyImmediate(_site.gameObject);
|
||||
GameObject.DestroyImmediate(_body.gameObject);
|
||||
GameObject.DestroyImmediate(_scene.gameObject);
|
||||
GameObject.DestroyImmediate(MjScene.Instance);
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator InitialTransform() {
|
||||
_site.transform.position = new Vector3(1, 2, 3);
|
||||
_scene.CreateScene(); // compilation happens here
|
||||
yield return new WaitForFixedUpdate(); // updating the transform
|
||||
Assert.That(_site.transform.position, Is.EqualTo(new Vector3(1, 2, 3)));
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator ChangedTransformIsOverwrittenByItsMjCounterpart() {
|
||||
_scene.CreateScene(); // compilation happens here
|
||||
_site.transform.position = new Vector3(1, 2, 3);
|
||||
yield return new WaitForFixedUpdate(); // updating the transform
|
||||
Assert.That(_site.transform.position, Is.EqualTo(Vector3.zero));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: add332d9433794539b0daf49d5d388bd
|
||||
timeCreated: 1547485698
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "Tests.Runtime",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"UnityEngine.TestRunner",
|
||||
"Mujoco"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": true,
|
||||
"overrideReferences": true,
|
||||
"precompiledReferences": [
|
||||
"nunit.framework.dll"
|
||||
],
|
||||
"autoReferenced": false,
|
||||
"defineConstraints": [
|
||||
"UNITY_INCLUDE_TESTS"
|
||||
],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 20c866b9eb6a4306297cce0c740191d2
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user