Skip to content

Commit b85f6d5

Browse files
committed
create a default ZeroSim robot
1 parent 447ee4d commit b85f6d5

File tree

5 files changed

+238
-1556
lines changed

5 files changed

+238
-1556
lines changed

Editor/CustomEditors/ZODocumentRootEditor.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ public override void OnInspectorGUI() {
5353

5454

5555
}
56-
57-
5856
}
57+
5958
}
6059
}

Editor/ZOZeroSimMenu.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using UnityEngine;
2+
using UnityEditor;
3+
using ZO.Document;
4+
5+
namespace ZO.Editor {
6+
public static class ZOZeroSimMenu {
7+
[MenuItem("GameObject/ZeroSim/New Robot", false, 0)]
8+
static void CreateZeroSimRobot(MenuCommand menuCommand) {
9+
GameObject documentRoot = new GameObject("MyRobot");
10+
ZOSimDocumentRoot docRoot = documentRoot.AddComponent<ZOSimDocumentRoot>();
11+
12+
GameObject baseOccurrence = new GameObject("base");
13+
baseOccurrence.transform.SetParent(documentRoot.transform);
14+
ZOSimOccurrence occurrence = baseOccurrence.AddComponent<ZOSimOccurrence>();
15+
occurrence.DocumentRoot = docRoot;
16+
17+
18+
GameObject visuals = new GameObject("visuals");
19+
visuals.transform.SetParent(occurrence.transform);
20+
21+
GameObject collisions = new GameObject("collisions");
22+
collisions.transform.SetParent(occurrence.transform);
23+
24+
// create default cube visual
25+
GameObject cubeVisual = GameObject.CreatePrimitive(PrimitiveType.Cube);
26+
cubeVisual.name = "MyExampleVisualCube";
27+
cubeVisual.transform.SetParent(visuals.transform);
28+
BoxCollider boxCollider = cubeVisual.GetComponent<BoxCollider>();
29+
GameObject.DestroyImmediate(boxCollider);
30+
31+
// create default collision cube
32+
GameObject cubeCollision = new GameObject("MyExampleCollisionCube");
33+
cubeCollision.AddComponent<BoxCollider>();
34+
cubeCollision.transform.SetParent(collisions.transform);
35+
36+
37+
38+
Undo.RegisterCreatedObjectUndo(documentRoot, "Create ZeroSim Robot " + documentRoot.name);
39+
Selection.activeGameObject = documentRoot;
40+
}
41+
}
42+
}

Editor/ZOZeroSimMenu.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime/Scripts/Document/ZOSimOccurrence.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,15 +1194,15 @@ public static void BuildURDF(XElement robot, ZOSimOccurrence simOccurrence, Matr
11941194
// build links
11951195
HashSet<ZOSimOccurrence> links = new HashSet<ZOSimOccurrence>();
11961196
foreach(URDFJoint joint in joints) {
1197-
if (links.Contains<ZOSimOccurrence>(joint.Parent) == false) {
1197+
if (links.Contains<ZOSimOccurrence>(joint.Parent) == false) { // build parent link if not exist
11981198
Vector3 offset = -1.0f * joint.ConnectedAnchor;
11991199
if (joints[0] == joint) { // if base joint do not apply any offset to parent link
12001200
offset = Vector3.zero;
12011201
}
12021202
joint.Parent.BuildURDFLink(robot, offset);
12031203
links.Add(joint.Parent);
12041204
}
1205-
if (links.Contains<ZOSimOccurrence>(joint.Child) == false) {
1205+
if (links.Contains<ZOSimOccurrence>(joint.Child) == false) { // build child link if not exist
12061206
Vector3 offset = -1.0f * joint.ConnectedAnchor;
12071207
joint.Child.BuildURDFLink(robot, offset);
12081208
links.Add(joint.Child);

0 commit comments

Comments
 (0)