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) {
|
||||
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("body2", Body2.MujocoName);
|
||||
mjcf.SetAttribute("anchor",
|
||||
|
||||
@@ -149,8 +149,7 @@ public struct MjSizeStruct {
|
||||
};
|
||||
|
||||
public void ParseMjcf(XmlElement mjcf) {
|
||||
var localDefault = MjSizeStruct.Default;
|
||||
Memory = mjcf.GetAttribute("memory", localDefault.Memory);
|
||||
Memory = mjcf.GetAttribute("memory");
|
||||
}
|
||||
|
||||
public XmlElement ToMjcf(XmlElement mjcf) {
|
||||
|
||||
@@ -134,10 +134,13 @@ public class MjcfImporter {
|
||||
}
|
||||
|
||||
protected virtual void ParseRoot(GameObject rootObject, XmlElement mujocoNode) {
|
||||
|
||||
var globalsObject = CreateGameObjectInParent("Global Settings", rootObject);
|
||||
var settingsComponent = globalsObject.AddComponent<MjGlobalSettings>();
|
||||
settingsComponent.ParseGlobalMjcfSections(mujocoNode);
|
||||
if (mujocoNode.SelectSingleNode("option") != null
|
||||
|| mujocoNode.SelectSingleNode("size") != null
|
||||
|| mujocoNode.SelectSingleNode("custom") != null) {
|
||||
var globalsObject = CreateGameObjectInParent("Global Settings", rootObject);
|
||||
var settingsComponent = globalsObject.AddComponent<MjGlobalSettings>();
|
||||
settingsComponent.ParseGlobalMjcfSections(mujocoNode);
|
||||
}
|
||||
|
||||
// This makes references to assets.
|
||||
var worldBodyNode = mujocoNode.SelectSingleNode("worldbody") as XmlElement;
|
||||
|
||||
@@ -24,6 +24,7 @@ namespace Mujoco {
|
||||
public class MjConnectTests {
|
||||
private MjBody _body1;
|
||||
private MjBody _body2;
|
||||
private Transform _anchor;
|
||||
private MjConnect _constraint;
|
||||
private XmlDocument _doc;
|
||||
|
||||
@@ -31,6 +32,7 @@ namespace Mujoco {
|
||||
public void SetUp() {
|
||||
_body1 = new GameObject("body1").AddComponent<MjBody>();
|
||||
_body2 = new GameObject("body2").AddComponent<MjBody>();
|
||||
_anchor = _body1.transform;
|
||||
_constraint = new GameObject("connect").AddComponent<MjConnect>();
|
||||
_doc = new XmlDocument();
|
||||
}
|
||||
@@ -44,10 +46,7 @@ namespace Mujoco {
|
||||
|
||||
[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);
|
||||
_constraint.Body1 = null;
|
||||
Assert.That(() => { _constraint.GenerateMjcf("name", _doc); }, Throws.Exception);
|
||||
}
|
||||
|
||||
@@ -71,10 +70,12 @@ namespace Mujoco {
|
||||
public void GenerateXML() {
|
||||
_constraint.Body1 = _body1;
|
||||
_constraint.Body2 = _body2;
|
||||
_constraint.Anchor = _anchor;
|
||||
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=\""));
|
||||
Assert.That(mjcf.OuterXml, Does.Contain("anchor=\""));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public class MjGlobalSettingsGenerationTests {
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenerateOptionAndSize() {
|
||||
public void GenerateOptionSizeFlagCustomNumeric() {
|
||||
_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);
|
||||
@@ -80,7 +80,7 @@ public class MjGlobalSettingsGenerationTests {
|
||||
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"""));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"memory=""1M"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -134,7 +134,7 @@ public class MjGlobalSettingsParsingTests {
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParseSizeOptionAndFlag() {
|
||||
public void ParseSizeOptionFlagCustomNumeric() {
|
||||
_option.SetAttribute("impratio", "1.2");
|
||||
_option.SetAttribute("magnetic", "3.4 4.5 5.6");
|
||||
_option.SetAttribute("wind", "6.7 7.8 8.9");
|
||||
|
||||
@@ -55,7 +55,8 @@ namespace Mujoco {
|
||||
var filename = "filename";
|
||||
var contents = "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));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user