예제 #1
0
        private static Robot ExportRobotData(this UrdfRobot urdfRobot)
        {
            Robot robot = new Robot();

            robot.ConstructFromFile(urdfRobot.FilePath, urdfRobot.gameObject.name);

            List <string> linkNames = new List <string>();

            foreach (UrdfLink urdfLink in urdfRobot.GetComponentsInChildren <UrdfLink>())
            {
                //Link export
                if (linkNames.Contains(urdfLink.name))
                {
                    EditorUtility.DisplayDialog("URDF Export Error",
                                                "URDF export failed. There are several links with the name " +
                                                urdfLink.name + ". Make sure all link names are unique before exporting this robot.",
                                                "Ok");
                    return(null);
                }
                robot.links.Add(urdfLink.ExportLinkData());
                linkNames.Add(urdfLink.name);

                //Joint export
                UrdfJoint urdfJoint = urdfLink.gameObject.GetComponent <UrdfJoint>();
                if (urdfJoint != null)
                {
                    robot.joints.Add(urdfJoint.ExportJointData());
                }
                else if (!urdfLink.IsBaseLink)
                {
                    //Make sure that links with no rigidbodies are still connected to the robot by a default joint
                    robot.joints.Add(UrdfJoint.ExportDefaultJoint(urdfLink.transform));
                }
            }

            robot.materials = UrdfMaterial.Materials.Values.ToList();
            robot.plugins   = urdfRobot.GetComponentInChildren <UrdfPlugins>().ExportPluginsData();

            return(robot);
        }