コード例 #1
0
        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);
            }
        }
コード例 #2
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 > 0)?((float)inertial.mass):minMass;
                if (inertial.origin != null)
                {
                    robotLink.centerOfMass = UrdfOrigin.GetPositionFromUrdf(inertial.origin);
                }
                else
                {
                    robotLink.centerOfMass = Vector3.zero;
                }
                urdfInertial.ImportInertiaData(inertial);

                urdfInertial.useUrdfData = true;
            }

            urdfInertial.displayInertiaGizmo = false;
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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>();

            UrdfVisualsExtensions.Create(linkObject.transform, link?.visuals);
            UrdfCollisionsExtensions.Create(linkObject.transform, link?.collisions);

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

            return(linkObject);
        }