Skip to content

Commit fce5346

Browse files
committed
Fix formatting
1 parent e9067de commit fce5346

28 files changed

+186
-164
lines changed

unity/Editor/Components/MjFlexDeformableEditor.cs

+53-53
Original file line numberDiff line numberDiff line change
@@ -2,66 +2,66 @@
22
using UnityEditor;
33

44
namespace Mujoco {
5-
[CustomEditor(typeof(MjFlexDeformable))]
6-
public class MjFlexDeformableEditor : Editor {
7-
public override void OnInspectorGUI() {
8-
serializedObject.Update();
95

10-
// To have properly rendered, dynamic edge/elasticity/contact properties with dropdowns
11-
// without manually creating the dropdown, HideInInspector in the main class doesn't work,
12-
// would end up needing to manually create the dropdown views. That would let us simply call
13-
// the default inspector for the other fields, but instead let's just add the boilerplate
14-
// for them.
15-
16-
EditorGUILayout.PropertyField(serializedObject.FindProperty("FlexName"), true);
17-
EditorGUILayout.PropertyField(serializedObject.FindProperty("Dim"), true);
18-
EditorGUILayout.PropertyField(serializedObject.FindProperty("Radius"), true);
19-
EditorGUILayout.PropertyField(serializedObject.FindProperty("Body"), true);
20-
EditorGUILayout.PropertyField(serializedObject.FindProperty("Vertex"), true);
21-
EditorGUILayout.PropertyField(serializedObject.FindProperty("Texcoord"), true);
22-
EditorGUILayout.PropertyField(serializedObject.FindProperty("Element"), true);
23-
EditorGUILayout.PropertyField(serializedObject.FindProperty("Flatskin"), true);
24-
EditorGUILayout.PropertyField(serializedObject.FindProperty("Group"), true);
25-
var component = (MjFlexDeformable)target;
6+
[CustomEditor(typeof(MjFlexDeformable))]
7+
public class MjFlexDeformableEditor : Editor {
8+
public override void OnInspectorGUI() {
9+
serializedObject.Update();
2610

27-
EditorGUILayout.Space(10);
28-
EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);
11+
// To have properly rendered, dynamic edge/elasticity/contact properties with dropdowns
12+
// without manually creating the dropdown, HideInInspector in the main class doesn't work,
13+
// would end up needing to manually create the dropdown views. That would let us simply call
14+
// the default inspector for the other fields, but instead let's just add the boilerplate
15+
// for them.
2916

30-
// Draw our hidden configuration sections
31-
SerializedProperty configureEdge = serializedObject.FindProperty("ConfigureEdge");
32-
SerializedProperty configureContact = serializedObject.FindProperty("ConfigureContact");
33-
SerializedProperty configureElasticity = serializedObject.FindProperty("ConfigureElasticity");
17+
EditorGUILayout.PropertyField(serializedObject.FindProperty("FlexName"), true);
18+
EditorGUILayout.PropertyField(serializedObject.FindProperty("Dim"), true);
19+
EditorGUILayout.PropertyField(serializedObject.FindProperty("Radius"), true);
20+
EditorGUILayout.PropertyField(serializedObject.FindProperty("Body"), true);
21+
EditorGUILayout.PropertyField(serializedObject.FindProperty("Vertex"), true);
22+
EditorGUILayout.PropertyField(serializedObject.FindProperty("Texcoord"), true);
23+
EditorGUILayout.PropertyField(serializedObject.FindProperty("Element"), true);
24+
EditorGUILayout.PropertyField(serializedObject.FindProperty("Flatskin"), true);
25+
EditorGUILayout.PropertyField(serializedObject.FindProperty("Group"), true);
26+
var component = (MjFlexDeformable)target;
3427

35-
// Edge Configuration
36-
EditorGUILayout.PropertyField(configureEdge);
37-
if (configureEdge.boolValue) {
38-
EditorGUI.indentLevel++;
39-
var edge = serializedObject.FindProperty("Edge");
40-
EditorGUILayout.PropertyField(edge, true);
41-
EditorGUI.indentLevel--;
42-
EditorGUILayout.Space(5);
43-
}
28+
EditorGUILayout.Space(10);
29+
EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);
4430

45-
// Contact Configuration
46-
EditorGUILayout.PropertyField(configureContact);
47-
if (configureContact.boolValue) {
48-
EditorGUI.indentLevel++;
49-
var contact = serializedObject.FindProperty("Contact");
50-
EditorGUILayout.PropertyField(contact, true);
51-
EditorGUI.indentLevel--;
52-
EditorGUILayout.Space(5);
53-
}
31+
// Draw our hidden configuration sections
32+
SerializedProperty configureEdge = serializedObject.FindProperty("ConfigureEdge");
33+
SerializedProperty configureContact = serializedObject.FindProperty("ConfigureContact");
34+
SerializedProperty configureElasticity = serializedObject.FindProperty("ConfigureElasticity");
35+
36+
EditorGUILayout.PropertyField(configureEdge);
37+
if (configureEdge.boolValue) {
38+
EditorGUI.indentLevel++;
39+
var edge = serializedObject.FindProperty("Edge");
40+
EditorGUILayout.PropertyField(edge, true);
41+
EditorGUI.indentLevel--;
42+
EditorGUILayout.Space(5);
43+
}
44+
45+
EditorGUILayout.PropertyField(configureContact);
46+
if (configureContact.boolValue) {
47+
EditorGUI.indentLevel++;
48+
var contact = serializedObject.FindProperty("Contact");
49+
EditorGUILayout.PropertyField(contact, true);
50+
EditorGUI.indentLevel--;
51+
EditorGUILayout.Space(5);
52+
}
5453

55-
// Elasticity Configuration
56-
EditorGUILayout.PropertyField(configureElasticity);
57-
if (configureElasticity.boolValue) {
58-
EditorGUI.indentLevel++;
59-
var elasticity = serializedObject.FindProperty("Elasticity");
60-
EditorGUILayout.PropertyField(elasticity, true);
61-
EditorGUI.indentLevel--;
62-
}
6354

64-
serializedObject.ApplyModifiedProperties();
55+
EditorGUILayout.PropertyField(configureElasticity);
56+
if (configureElasticity.boolValue) {
57+
EditorGUI.indentLevel++;
58+
var elasticity = serializedObject.FindProperty("Elasticity");
59+
EditorGUILayout.PropertyField(elasticity, true);
60+
EditorGUI.indentLevel--;
6561
}
62+
63+
serializedObject.ApplyModifiedProperties();
6664
}
65+
66+
}
6767
}

unity/Editor/Components/MjFlexDeformableEditor.cs.meta

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unity/Runtime/Components/Custom.meta

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unity/Runtime/Components/Custom/MjCustom.cs

+9-2
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ public XmlElement ToMjcf(XmlDocument doc) {
117117
}
118118

119119
protected abstract XmlElement ToMjcfInner(XmlDocument doc);
120+
120121
}
121122

122123
[Serializable]
@@ -150,7 +151,10 @@ private class MjNumeric : MjCustomElement {
150151
public float[] data;
151152

152153
protected override void ParseInner(XmlElement mjcf) {
153-
if (int.TryParse(mjcf.GetStringAttribute("size", "-1"), out var size)) {
154+
bool hasParsed = int.TryParse(
155+
mjcf.GetStringAttribute("size", "-1"),
156+
out var size);
157+
if (hasParsed) {
154158
this.size = size;
155159
}
156160
var data = mjcf.GetFloatArrayAttribute("data", new float[] {});
@@ -165,7 +169,10 @@ protected override void ParseInner(XmlElement mjcf) {
165169
protected override XmlElement ToMjcfInner(XmlDocument doc) {
166170
var mjcf = (XmlElement)doc.CreateElement("numeric");
167171
if (size >= 0) {
168-
mjcf.SetAttribute("size", MjEngineTool.MakeLocaleInvariant($"{size}"));
172+
mjcf.SetAttribute(
173+
"size",
174+
MjEngineTool.MakeLocaleInvariant($"{size}")
175+
);
169176
}
170177

171178
mjcf.SetAttribute("data", MjEngineTool.ArrayToMjcf(data));

unity/Runtime/Components/Custom/MjCustom.cs.meta

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unity/Runtime/Components/Deformable.meta

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unity/Runtime/Components/Deformable/MjFlexDeformable.cs

+5-3
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class MjFlexDeformable : MjComponent {
4949

5050
// Due to their low complexity, no further hierarchy and uniqueness I opted not to have
5151
// separate Unity MonoBehaviours and GameObjects in Unity for the child elements of flex.
52-
// H
52+
5353
public bool ConfigureEdge;
5454

5555
[SerializeField]
@@ -74,7 +74,8 @@ protected override void OnParseMjcf(XmlElement mjcf) {
7474
FlexName = mjcf.GetStringAttribute("name", "");
7575
Dim = mjcf.GetIntAttribute("dim", 2);
7676
Radius = mjcf.GetFloatAttribute("radius", 0.005f);
77-
Body = mjcf.GetStringAttribute("body").Split(" ", StringSplitOptions.RemoveEmptyEntries)
77+
Body = mjcf.GetStringAttribute("body")
78+
.Split(" ", StringSplitOptions.RemoveEmptyEntries)
7879
.Select(MjHierarchyTool.FindComponentOfTypeAndName<MjBaseBody>).ToArray();
7980
Vertex = mjcf.GetFloatArrayAttribute("vertex", Array.Empty<float>());
8081
Texcoord = mjcf.GetFloatArrayAttribute("texcoord", Array.Empty<float>());
@@ -118,7 +119,8 @@ protected override XmlElement OnGenerateMjcf(XmlDocument doc) {
118119
mjcf.SetAttribute("dim", MjEngineTool.MakeLocaleInvariant($"{Dim}"));
119120
mjcf.SetAttribute("radius", MjEngineTool.MakeLocaleInvariant($"{Radius}"));
120121
if (Body.Length > 0)
121-
mjcf.SetAttribute("body", MjEngineTool.ArrayToMjcf(Body.Select(b => b.MujocoName).ToArray()));
122+
mjcf.SetAttribute("body",
123+
MjEngineTool.ArrayToMjcf(Body.Select(b => b.MujocoName).ToArray()));
122124
if (Vertex.Length > 0)
123125
mjcf.SetAttribute("vertex", MjEngineTool.ArrayToMjcf(Vertex));
124126
if (Texcoord.Length > 0)

unity/Runtime/Components/Deformable/MjFlexDeformable.cs.meta

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unity/Runtime/Components/Deformable/MjFlexMeshBuilder.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,11 @@ public void GenerateSkinnedMesh() {
6767
// Assuming horizontal layout
6868
uv[i] = new Vector2(
6969
Mathf.InverseLerp(vertices.Min(u => Vector3.Dot(u, uvProjectionU)),
70-
vertices.Max(u => Vector3.Dot(u, uvProjectionU)), Vector3.Dot(vertices[i], uvProjectionU)),
70+
vertices.Max(u => Vector3.Dot(u, uvProjectionU)),
71+
Vector3.Dot(vertices[i], uvProjectionU)),
7172
Mathf.InverseLerp(vertices.Min(u => Vector3.Dot(u, uvProjectionV)),
72-
vertices.Max(u => Vector3.Dot(u, uvProjectionV)), Vector3.Dot(vertices[i], uvProjectionV))
73+
vertices.Max(u => Vector3.Dot(u, uvProjectionV)),
74+
Vector3.Dot(vertices[i], uvProjectionV))
7375
);
7476
}
7577
mesh.uv = uv;

unity/Runtime/Components/Deformable/MjFlexMeshBuilder.cs.meta

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unity/Runtime/Components/Equality/MjConnect.cs

+45-40
Original file line numberDiff line numberDiff line change
@@ -19,50 +19,55 @@
1919

2020
namespace Mujoco {
2121

22-
public class MjConnect : MjBaseConstraint {
23-
public MjBaseBody Body1;
24-
public MjBaseBody Body2;
25-
public MjSite Site1;
26-
public MjSite Site2;
27-
public Transform Anchor;
28-
protected override string _constraintName => "connect";
22+
public class MjConnect : MjBaseConstraint {
23+
public MjBaseBody Body1;
24+
public MjBaseBody Body2;
25+
public MjSite Site1;
26+
public MjSite Site2;
27+
public Transform Anchor;
28+
protected override string _constraintName => "connect";
2929

30-
protected override void FromMjcf(XmlElement mjcf) {
31-
Body1 = mjcf.GetObjectReferenceAttribute<MjBaseBody>("body1");
32-
Body2 = mjcf.GetObjectReferenceAttribute<MjBaseBody>("body2");
33-
Site1 = mjcf.GetObjectReferenceAttribute<MjSite>("site1");
34-
Site2 = mjcf.GetObjectReferenceAttribute<MjSite>("site2");
35-
var anchorPos = MjEngineTool.UnityVector3(
36-
mjcf.GetVector3Attribute("anchor", defaultValue: Vector3.zero));
37-
Anchor = new GameObject("connect_anchor").transform;
38-
Anchor.parent = Body1.transform;
39-
Anchor.localPosition = anchorPos;
40-
}
41-
42-
// Generate implementation specific XML element.
43-
protected override void ToMjcf(XmlElement mjcf) {
44-
if (!(Body1 && Anchor) && !(Site1 && Site2)) {
45-
throw new NullReferenceException($"Either body1 and anchor is required or both sites have to be defined in {name}.");
46-
}
47-
if (Body1)
48-
mjcf.SetAttribute("body1", Body1.MujocoName);
49-
if (Body2)
50-
mjcf.SetAttribute("body2", Body2.MujocoName);
51-
if (Anchor)
52-
mjcf.SetAttribute("anchor",
53-
MjEngineTool.Vector3ToMjcf(MjEngineTool.MjVector3(Anchor.localPosition)));
54-
if (Site1)
55-
mjcf.SetAttribute("site1", Site1.MujocoName);
56-
if (Site2)
57-
mjcf.SetAttribute("site2", Site2.MujocoName);
30+
protected override void FromMjcf(XmlElement mjcf) {
31+
Body1 = mjcf.GetObjectReferenceAttribute<MjBaseBody>("body1");
32+
Body2 = mjcf.GetObjectReferenceAttribute<MjBaseBody>("body2");
33+
Site1 = mjcf.GetObjectReferenceAttribute<MjSite>("site1");
34+
Site2 = mjcf.GetObjectReferenceAttribute<MjSite>("site2");
35+
var anchorPos = MjEngineTool.UnityVector3(
36+
mjcf.GetVector3Attribute("anchor", defaultValue: Vector3.zero));
37+
Anchor = new GameObject("connect_anchor").transform;
38+
Anchor.parent = Body1.transform;
39+
Anchor.localPosition = anchorPos;
40+
}
5841

42+
// Generate implementation specific XML element.
43+
protected override void ToMjcf(XmlElement mjcf) {
44+
if (!(Body1 && Anchor) && !(Site1 && Site2)) {
45+
throw new NullReferenceException($"Either body1 and anchor is required or both sites have to be defined in {name}.");
46+
}
47+
if (Body1) {
48+
mjcf.SetAttribute("body1", Body1.MujocoName);
49+
}
50+
if (Body2) {
51+
mjcf.SetAttribute("body2", Body2.MujocoName);
5952
}
53+
if (Anchor) {
54+
mjcf.SetAttribute(
55+
"anchor",
56+
MjEngineTool.Vector3ToMjcf(MjEngineTool.MjVector3(Anchor.localPosition)));
57+
}
58+
if (Site1) {
59+
mjcf.SetAttribute("site1", Site1.MujocoName);
60+
}
61+
if (Site2) {
62+
mjcf.SetAttribute("site2", Site2.MujocoName);
63+
}
64+
}
6065

61-
public void OnValidate() {
62-
if (Body1 != null && Body1 == Body2) {
63-
Debug.LogError("Body1 and Body2 can't be the same - resetting Body2.", this);
64-
Body2 = null;
65-
}
66+
public void OnValidate() {
67+
if (Body1 != null && Body1 == Body2) {
68+
Debug.LogError("Body1 and Body2 can't be the same - resetting Body2.", this);
69+
Body2 = null;
6670
}
6771
}
6872
}
73+
}

unity/Runtime/Components/Equality/MjFlexConstraint.cs

+10-10
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@
1919

2020
namespace Mujoco {
2121

22-
public class MjFlexConstraint : MjBaseConstraint {
23-
public string Flex;
24-
protected override string _constraintName => "flex";
22+
public class MjFlexConstraint : MjBaseConstraint {
23+
public string Flex;
24+
protected override string _constraintName => "flex";
2525

26-
protected override void FromMjcf(XmlElement mjcf) {
27-
Flex = mjcf.GetStringAttribute("flex");
28-
}
29-
30-
protected override void ToMjcf(XmlElement mjcf) {
31-
mjcf.SetAttribute("flex", Flex);
32-
}
26+
protected override void FromMjcf(XmlElement mjcf) {
27+
Flex = mjcf.GetStringAttribute("flex");
28+
}
3329

30+
protected override void ToMjcf(XmlElement mjcf) {
31+
mjcf.SetAttribute("flex", Flex);
3432
}
33+
34+
}
3535
}

unity/Runtime/Components/Equality/MjFlexConstraint.cs.meta

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unity/Runtime/Components/Plugins.meta

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)