Пример #1
0
        private void ImportLinkData(Link link, Joint joint)
        {
            if (link.inertial == null && joint == null)
            {
                isBaseLink = true;
            }

            gameObject.name = link.name;

            if (joint?.origin != null)
            {
                UrdfOrigin.ImportOriginData(transform, joint.origin);
            }

            if (link.inertial != null)
            {
                UrdfInertial.Create(gameObject, link.inertial);

                if (joint != null)
                {
                    UrdfJoint.Create(gameObject, UrdfJoint.GetJointType(joint.type), joint);
                }
            }
            else if (joint != null)
            {
                Debug.LogWarning("No Joint Component will be created in GameObject \"" + gameObject.name + "\" as it has no Rigidbody Component.\n"
                                 + "Please define an Inertial for Link \"" + link.name + "\" in the URDF file to create a Rigidbody Component.\n", gameObject);
            }

            foreach (Joint childJoint in link.joints)
            {
                Link child = childJoint.ChildLink;
                UrdfLink.Create(transform, child, childJoint);
            }
        }
Пример #2
0
        public static void Create(GameObject linkObject, Link.Inertial inertial = null)
        {
            UrdfInertial urdfInertial = linkObject.AddComponent <UrdfInertial>();
            Rigidbody    _rigidbody   = urdfInertial.GetComponent <Rigidbody>();

            if (inertial != null)
            {
                _rigidbody.mass = (float)inertial.mass;

                if (inertial.origin != null)
                {
                    _rigidbody.centerOfMass = UrdfOrigin.GetPositionFromUrdf(inertial.origin);
                }

                urdfInertial.ImportInertiaData(inertial.inertia);

                urdfInertial.UseUrdfData = true;
            }

            urdfInertial.DisplayInertiaGizmo = false;

            //Save original rigidbody data from URDF
            urdfInertial.CenterOfMass          = _rigidbody.centerOfMass;
            urdfInertial.InertiaTensor         = _rigidbody.inertiaTensor;
            urdfInertial.InertiaTensorRotation = _rigidbody.inertiaTensorRotation;
        }
Пример #3
0
        public static void Create(GameObject linkObject, Link.Inertial inertial = null)
        {
            UrdfInertial urdfInertial = linkObject.AddComponent <UrdfInertial>();

#if UNITY_2020_1_OR_NEWER
            ArticulationBody robotLink = urdfInertial.GetComponent <ArticulationBody>();
#else
            Rigidbody robotLink = urdfInertial.GetComponent <Rigidbody>();
#endif
            if (inertial != null)
            {
                robotLink.mass = (float)inertial.mass;
                if (inertial.origin != null)
                {
                    robotLink.centerOfMass = UrdfOrigin.GetPositionFromUrdf(inertial.origin);
                }
                else
                {
                    robotLink.centerOfMass = Vector3.zero;
                }
                urdfInertial.ImportInertiaData(inertial);

                urdfInertial.useUrdfData = true;
            }

            urdfInertial.displayInertiaGizmo = false;
        }
Пример #4
0
        public static void Create(GameObject linkObject, Link.Inertial inertial)
        {
            UrdfInertial urdfInertial = linkObject.AddComponent <UrdfInertial>();

            urdfInertial.UrdfMass = (float)inertial.mass;

            if (inertial.origin != null)
            {
                urdfInertial.UrdfCenterOfMass = UrdfOrigin.GetPositionFromUrdf(inertial.origin);
            }

            urdfInertial.ImportInertiaData(inertial.inertia);
            urdfInertial.Initialize();
            urdfInertial.isCreated = true;
        }
Пример #5
0
        public Link ExportLinkData()
        {
            if (transform.localScale != Vector3.one)
            {
                Debug.LogWarning("Only visuals should be scaled. Scale on link \"" + gameObject.name + "\" cannot be saved to the URDF file.", gameObject);
            }

            UrdfInertial urdfInertial = gameObject.GetComponent <UrdfInertial>();
            Link         link         = new Link(gameObject.name)
            {
                visuals    = gameObject.GetComponentInChildren <UrdfVisuals>().ExportVisualsData(),
                collisions = gameObject.GetComponentInChildren <UrdfCollisions>().ExportCollisionsData(),
                inertial   = urdfInertial == null ? null : urdfInertial.ExportInertialData()
            };

            return(link);
        }
Пример #6
0
        public static UrdfLink Create(Transform parent, Link link = null, Joint joint = null)
        {
            GameObject linkObject = new GameObject("link");

            linkObject.transform.SetParentAndAlign(parent);
            UrdfLink urdfLink = linkObject.AddComponent <UrdfLink>();

            UrdfVisuals.Create(linkObject.transform, link?.visuals);
            UrdfCollisions.Create(linkObject.transform, link?.collisions);

            if (link != null)
            {
                urdfLink.ImportLinkData(link, joint);
            }
            else
            {
                UrdfInertial.Create(linkObject);
                EditorGUIUtility.PingObject(linkObject);
            }

            return(urdfLink);
        }
Пример #7
0
        public override void OnInspectorGUI()
        {
            UrdfInertial urdfInertial = (UrdfInertial)target;

            GUILayout.Space(5);
            urdfInertial.DisplayInertiaGizmo =
                EditorGUILayout.ToggleLeft("Display Inertia Gizmo", urdfInertial.DisplayInertiaGizmo);
            GUILayout.Space(5);

            bool newValue = EditorGUILayout.BeginToggleGroup("Use URDF Data", urdfInertial.UseUrdfData);

            EditorGUILayout.Vector3Field("URDF Center of Mass", urdfInertial.CenterOfMass);
            EditorGUILayout.Vector3Field("URDF Inertia Tensor", urdfInertial.InertiaTensor);
            EditorGUILayout.Vector3Field("URDF Inertia Tensor Rotation",
                                         urdfInertial.InertiaTensorRotation.eulerAngles);
            EditorGUILayout.EndToggleGroup();

            if (newValue != urdfInertial.UseUrdfData)
            {
                urdfInertial.UseUrdfData = newValue;
                urdfInertial.UpdateRigidBodyData();
            }
        }