-
Notifications
You must be signed in to change notification settings - Fork 70
/
UrdfLinkExtensions.cs
81 lines (71 loc) · 3.11 KB
/
UrdfLinkExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
© Siemens AG, 2018
Author: Suzannah Smith (suzannah.smith@siemens.com)
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 UnityEngine;
namespace Unity.Robotics.UrdfImporter
{
public static class UrdfLinkExtensions
{
public static GameObject Create(Transform parent, Link link = null, Joint joint = null)
{
GameObject linkObject = new GameObject("link");
linkObject.transform.SetParentAndAlign(parent);
UrdfLink urdfLink = linkObject.AddComponent<UrdfLink>();
UrdfCollisionsExtensions.Create(linkObject.transform, link?.collisions);
UrdfVisualsExtensions.Create(linkObject.transform, link?.visuals);
if (link != null)
{
urdfLink.ImportLinkData(link, joint);
}
else
{
UrdfInertial.Create(linkObject);
#if UNITY_EDITOR
UnityEditor.EditorGUIUtility.PingObject(linkObject);
#endif
}
return linkObject;
}
private static void ImportLinkData(this UrdfLink urdfLink, Link link, Joint joint)
{
if (link.inertial == null && joint == null)
{
urdfLink.IsBaseLink = true;
}
urdfLink.gameObject.name = link.name;
if (joint?.origin != null)
UrdfOrigin.ImportOriginData(urdfLink.transform, joint.origin);
if (link.inertial != null)
{
UrdfInertial.Create(urdfLink.gameObject, link.inertial);
if (joint != null)
UrdfJoint.Create(urdfLink.gameObject, UrdfJoint.GetJointType(joint.type), joint);
}
else if (joint != null)
UrdfJoint.Create(urdfLink.gameObject, UrdfJoint.GetJointType(joint.type), joint);
}
public static Link ExportLinkData(this UrdfLink urdfLink)
{
if (urdfLink.transform.localScale != Vector3.one)
Debug.LogWarning("Only visuals should be scaled. Scale on link \"" + urdfLink.gameObject.name + "\" cannot be saved to the URDF file.", urdfLink.gameObject);
UrdfInertial urdfInertial = urdfLink.gameObject.GetComponent<UrdfInertial>();
Link link = new Link(urdfLink.gameObject.name)
{
visuals = urdfLink.GetComponentInChildren<UrdfVisuals>().ExportVisualsData(),
collisions = urdfLink.GetComponentInChildren<UrdfCollisions>().ExportCollisionsData(),
inertial = urdfInertial == null ? null : urdfInertial.ExportInertialData()
};
return link;
}
}
}