Clean-up test files.
Also, don't add a Global Settings component at import if the xml doesn't have any global settings (option/size/custom). PiperOrigin-RevId: 495950899 Change-Id: I6599e8ea3f3a82729fc5c974fd7ced8eb93b277e
This commit is contained in:
committed by
Copybara-Service
parent
69c74f850e
commit
6a58fd1522
@@ -40,6 +40,9 @@ namespace Mujoco {
|
|||||||
if (Body1 == null || Body2 == null) {
|
if (Body1 == null || Body2 == null) {
|
||||||
throw new NullReferenceException($"Both bodies in connect {name} are required.");
|
throw new NullReferenceException($"Both bodies in connect {name} are required.");
|
||||||
}
|
}
|
||||||
|
if (Anchor == null) {
|
||||||
|
throw new NullReferenceException($"Anchor in connect {name} is required.");
|
||||||
|
}
|
||||||
mjcf.SetAttribute("body1", Body1.MujocoName);
|
mjcf.SetAttribute("body1", Body1.MujocoName);
|
||||||
mjcf.SetAttribute("body2", Body2.MujocoName);
|
mjcf.SetAttribute("body2", Body2.MujocoName);
|
||||||
mjcf.SetAttribute("anchor",
|
mjcf.SetAttribute("anchor",
|
||||||
|
|||||||
@@ -149,8 +149,7 @@ public struct MjSizeStruct {
|
|||||||
};
|
};
|
||||||
|
|
||||||
public void ParseMjcf(XmlElement mjcf) {
|
public void ParseMjcf(XmlElement mjcf) {
|
||||||
var localDefault = MjSizeStruct.Default;
|
Memory = mjcf.GetAttribute("memory");
|
||||||
Memory = mjcf.GetAttribute("memory", localDefault.Memory);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public XmlElement ToMjcf(XmlElement mjcf) {
|
public XmlElement ToMjcf(XmlElement mjcf) {
|
||||||
|
|||||||
@@ -134,10 +134,13 @@ public class MjcfImporter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void ParseRoot(GameObject rootObject, XmlElement mujocoNode) {
|
protected virtual void ParseRoot(GameObject rootObject, XmlElement mujocoNode) {
|
||||||
|
if (mujocoNode.SelectSingleNode("option") != null
|
||||||
var globalsObject = CreateGameObjectInParent("Global Settings", rootObject);
|
|| mujocoNode.SelectSingleNode("size") != null
|
||||||
var settingsComponent = globalsObject.AddComponent<MjGlobalSettings>();
|
|| mujocoNode.SelectSingleNode("custom") != null) {
|
||||||
settingsComponent.ParseGlobalMjcfSections(mujocoNode);
|
var globalsObject = CreateGameObjectInParent("Global Settings", rootObject);
|
||||||
|
var settingsComponent = globalsObject.AddComponent<MjGlobalSettings>();
|
||||||
|
settingsComponent.ParseGlobalMjcfSections(mujocoNode);
|
||||||
|
}
|
||||||
|
|
||||||
// This makes references to assets.
|
// This makes references to assets.
|
||||||
var worldBodyNode = mujocoNode.SelectSingleNode("worldbody") as XmlElement;
|
var worldBodyNode = mujocoNode.SelectSingleNode("worldbody") as XmlElement;
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ namespace Mujoco {
|
|||||||
public class MjConnectTests {
|
public class MjConnectTests {
|
||||||
private MjBody _body1;
|
private MjBody _body1;
|
||||||
private MjBody _body2;
|
private MjBody _body2;
|
||||||
|
private Transform _anchor;
|
||||||
private MjConnect _constraint;
|
private MjConnect _constraint;
|
||||||
private XmlDocument _doc;
|
private XmlDocument _doc;
|
||||||
|
|
||||||
@@ -31,6 +32,7 @@ namespace Mujoco {
|
|||||||
public void SetUp() {
|
public void SetUp() {
|
||||||
_body1 = new GameObject("body1").AddComponent<MjBody>();
|
_body1 = new GameObject("body1").AddComponent<MjBody>();
|
||||||
_body2 = new GameObject("body2").AddComponent<MjBody>();
|
_body2 = new GameObject("body2").AddComponent<MjBody>();
|
||||||
|
_anchor = _body1.transform;
|
||||||
_constraint = new GameObject("connect").AddComponent<MjConnect>();
|
_constraint = new GameObject("connect").AddComponent<MjConnect>();
|
||||||
_doc = new XmlDocument();
|
_doc = new XmlDocument();
|
||||||
}
|
}
|
||||||
@@ -44,10 +46,7 @@ namespace Mujoco {
|
|||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void ErrorThrownWhenBody1Empty() {
|
public void ErrorThrownWhenBody1Empty() {
|
||||||
// This is an illegal MJCF, but the purpose of this test is to verify that if
|
_constraint.Body1 = null;
|
||||||
// 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);
|
Assert.That(() => { _constraint.GenerateMjcf("name", _doc); }, Throws.Exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,10 +70,12 @@ namespace Mujoco {
|
|||||||
public void GenerateXML() {
|
public void GenerateXML() {
|
||||||
_constraint.Body1 = _body1;
|
_constraint.Body1 = _body1;
|
||||||
_constraint.Body2 = _body2;
|
_constraint.Body2 = _body2;
|
||||||
|
_constraint.Anchor = _anchor;
|
||||||
var mjcf = _constraint.GenerateMjcf("name", _doc);
|
var mjcf = _constraint.GenerateMjcf("name", _doc);
|
||||||
Assert.That(mjcf.OuterXml, Does.Contain("<connect"));
|
Assert.That(mjcf.OuterXml, Does.Contain("<connect"));
|
||||||
Assert.That(mjcf.OuterXml, Does.Contain("body1=\""));
|
Assert.That(mjcf.OuterXml, Does.Contain("body1=\""));
|
||||||
Assert.That(mjcf.OuterXml, Does.Contain("body2=\""));
|
Assert.That(mjcf.OuterXml, Does.Contain("body2=\""));
|
||||||
|
Assert.That(mjcf.OuterXml, Does.Contain("anchor=\""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ public class MjGlobalSettingsGenerationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void GenerateOptionAndSize() {
|
public void GenerateOptionSizeFlagCustomNumeric() {
|
||||||
_settings.GlobalOptions.ImpRatio = 1.2f;
|
_settings.GlobalOptions.ImpRatio = 1.2f;
|
||||||
_settings.GlobalOptions.Magnetic = new Vector3(3.4f, 4.5f, 5.6f);
|
_settings.GlobalOptions.Magnetic = new Vector3(3.4f, 4.5f, 5.6f);
|
||||||
_settings.GlobalOptions.Wind = new Vector3(6.7f, 7.8f, 8.9f);
|
_settings.GlobalOptions.Wind = new Vector3(6.7f, 7.8f, 8.9f);
|
||||||
@@ -80,7 +80,7 @@ public class MjGlobalSettingsGenerationTests {
|
|||||||
Assert.That(_doc.OuterXml, Does.Contain(@"noslip_tolerance=""6.7"""));
|
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_iterations=""8"""));
|
||||||
Assert.That(_doc.OuterXml, Does.Contain(@"mpr_tolerance=""0.9"""));
|
Assert.That(_doc.OuterXml, Does.Contain(@"mpr_tolerance=""0.9"""));
|
||||||
Assert.That(_doc.OuterXml, Does.Contain(@"nconmax=""321"""));
|
Assert.That(_doc.OuterXml, Does.Contain(@"memory=""1M"""));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -134,7 +134,7 @@ public class MjGlobalSettingsParsingTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void ParseSizeOptionAndFlag() {
|
public void ParseSizeOptionFlagCustomNumeric() {
|
||||||
_option.SetAttribute("impratio", "1.2");
|
_option.SetAttribute("impratio", "1.2");
|
||||||
_option.SetAttribute("magnetic", "3.4 4.5 5.6");
|
_option.SetAttribute("magnetic", "3.4 4.5 5.6");
|
||||||
_option.SetAttribute("wind", "6.7 7.8 8.9");
|
_option.SetAttribute("wind", "6.7 7.8 8.9");
|
||||||
|
|||||||
@@ -55,7 +55,8 @@ namespace Mujoco {
|
|||||||
var filename = "filename";
|
var filename = "filename";
|
||||||
var contents = "contents";
|
var contents = "contents";
|
||||||
_vfs.AddFile(filename, contents);
|
_vfs.AddFile(filename, contents);
|
||||||
var filedata = Marshal.PtrToStringAnsi(_vfs.Data.filedata[0]);
|
var fileIndex = _vfs.FindFile(filename);
|
||||||
|
var filedata = Marshal.PtrToStringAnsi(_vfs.Data.filedata[fileIndex]);
|
||||||
Assert.That(filedata, Is.EqualTo(contents));
|
Assert.That(filedata, Is.EqualTo(contents));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user