public static void Create(string filename) { Robot robot = new Robot(); robot.ConstructFromFile(filename); if (!UrdfAssetPathHandler.IsValidAssetPath(robot.filename)) { Debug.LogError("URDF file and ressources must be placed in Assets Folder:\n" + Application.dataPath); return; } GameObject robotGameObject = new GameObject(robot.name); robotGameObject.AddComponent <UrdfRobot>(); UrdfAssetPathHandler.SetPackageRoot(Path.GetDirectoryName(robot.filename)); UrdfMaterial.InitializeRobotMaterials(robot); UrdfPlugins.Create(robotGameObject.transform, robot.plugins); UrdfLinkExtensions.Create(robotGameObject.transform, robot.root); GameObjectUtility.SetParentAndAlign(robotGameObject, Selection.activeObject as GameObject); Undo.RegisterCreatedObjectUndo(robotGameObject, "Create " + robotGameObject.name); Selection.activeObject = robotGameObject; }
public static IEnumerator Create(string filename, ImportSettings settings, bool loadStatus = false) { CreateTag(); importsettings = settings; Robot robot = new Robot(filename); settings.totalLinks = robot.links.Count; if (!UrdfAssetPathHandler.IsValidAssetPath(robot.filename)) { Debug.LogError("URDF file and ressources must be placed in Assets Folder:\n" + Application.dataPath); yield break; } GameObject robotGameObject = new GameObject(robot.name); robotGameObject.tag = tagName; robotGameObject.AddComponent <UrdfRobot>(); robotGameObject.AddComponent <RosSharp.Control.Controller>(); robotGameObject.GetComponent <UrdfRobot>().SetAxis(settings.choosenAxis); UrdfAssetPathHandler.SetPackageRoot(Path.GetDirectoryName(robot.filename)); UrdfMaterial.InitializeRobotMaterials(robot); UrdfPlugins.Create(robotGameObject.transform, robot.plugins); Stack <Tuple <Link, Transform, Joint> > importStack = new Stack <Tuple <Link, Transform, Joint> >(); importStack.Push(new Tuple <Link, Transform, Joint>(robot.root, robotGameObject.transform, null)); while (importStack.Count != 0) { Tuple <Link, Transform, Joint> currentLink = importStack.Pop(); GameObject importedLink = UrdfLinkExtensions.Create(currentLink.Item2, currentLink.Item1, currentLink.Item3); settings.linksLoaded++; foreach (Joint childJoint in currentLink.Item1.joints) { Link child = childJoint.ChildLink; importStack.Push(new Tuple <Link, Transform, Joint>(child, importedLink.transform, childJoint)); } if (loadStatus) { yield return(null); } } GameObjectUtility.SetParentAndAlign(robotGameObject, Selection.activeObject as GameObject); Undo.RegisterCreatedObjectUndo(robotGameObject, "Create " + robotGameObject.name); Selection.activeObject = robotGameObject; CorrectAxis(robotGameObject); CreateCollisionExceptions(robot, robotGameObject); }
public static void Create(Transform parent, Link.Visual visual) { GameObject visualObject = new GameObject(visual.name ?? "unnamed"); visualObject.transform.SetParentAndAlign(parent); UrdfVisual urdfVisual = visualObject.AddComponent <UrdfVisual>(); urdfVisual.GeometryType = UrdfGeometry.GetGeometryType(visual.geometry); UrdfGeometryVisual.Create(visualObject.transform, urdfVisual.GeometryType, visual.geometry); UrdfMaterial.SetUrdfMaterial(visualObject, visual.material); UrdfOrigin.ImportOriginData(visualObject.transform, visual.origin); }
public static Link.Visual ExportVisualData(this UrdfVisual urdfVisual) { UrdfGeometry.CheckForUrdfCompatibility(urdfVisual.transform, urdfVisual.geometryType); Link.Geometry geometry = UrdfGeometry.ExportGeometryData(urdfVisual.geometryType, urdfVisual.transform); Link.Visual.Material material = null; if ((geometry.mesh != null)) { material = UrdfMaterial.ExportMaterialData(urdfVisual.GetComponentInChildren <MeshRenderer>().sharedMaterial); } string visualName = urdfVisual.name == "unnamed" ? null : urdfVisual.name; return(new Link.Visual(geometry, visualName, UrdfOrigin.ExportOriginData(urdfVisual.transform), material)); }
public static Link.Visual ExportVisualData(this UrdfVisual urdfVisual) { UrdfGeometry.CheckForUrdfCompatibility(urdfVisual.transform, urdfVisual.GeometryType); Link.Geometry geometry = UrdfGeometry.ExportGeometryData(urdfVisual.GeometryType, urdfVisual.transform); Link.Visual.Material material = null; if (!(geometry.mesh != null && geometry.mesh.filename.ToLower().EndsWith(".dae"))) //Collada files contain their own materials { material = UrdfMaterial.ExportMaterialData(urdfVisual.GetComponentInChildren <MeshRenderer>().sharedMaterial); } string visualName = urdfVisual.name == "unnamed" ? null : urdfVisual.name; return(new Link.Visual(geometry, visualName, UrdfOrigin.ExportOriginData(urdfVisual.transform), material)); }
public static void Create(Transform parent, Link.Visual visual) { if (String.IsNullOrEmpty(visual.name)) { visual.name = visual.GenerateNonReferenceID(); } if (parent.FindChildOrCreateWithComponent <UrdfVisual>(visual.name, out GameObject visualObject, out UrdfVisual urdfVisual)) { //only create these visuals if the gameobject had to be created itself urdfVisual.GeometryType = UrdfGeometry.GetGeometryType(visual.geometry); UrdfGeometryVisual.Create(visualObject.transform, urdfVisual.GeometryType, visual.geometry); } //update these values every time UrdfMaterial.SetUrdfMaterial(visualObject, visual.material); UrdfOrigin.ImportOriginData(visualObject.transform, visual.origin); }
private static void Create(Robot robot) { GameObject robotGameObject = new GameObject(robot.name); robotGameObject.AddComponent <JointStatePublisher>(); robotGameObject.AddComponent <JointCommandsSubscription>(); robotGameObject.AddComponent <UnityInputTeleop>(); robotGameObject.AddComponent <TwistBaseController>(); robotGameObject.AddComponent <OdometryPublisher>(); robotGameObject.AddComponent <DiffDriveWheelSpinner>().enabled = false; UrdfMaterial.InitializeRobotMaterials(robot); UrdfSimulationLinkExtensions.Create(robotGameObject.transform, robot.root); GameObjectUtility.SetParentAndAlign(robotGameObject, Selection.activeObject as GameObject); Undo.RegisterCreatedObjectUndo(robotGameObject, "Create " + robotGameObject.name); Selection.activeObject = robotGameObject; }
private static void Create(Robot robot) { GameObject rosVisualizerGameObject = new GameObject("RosVisualizer"); rosVisualizerGameObject.AddComponent <TfSubscriber>(); GameObject mapFrame = new GameObject("map"); GameObjectUtility.SetParentAndAlign(mapFrame, rosVisualizerGameObject); mapFrame.AddComponent <TfFrame>(); GameObject odomFrame = new GameObject("odom"); GameObjectUtility.SetParentAndAlign(odomFrame, mapFrame); odomFrame.AddComponent <TfFrame>(); UrdfMaterial.InitializeRobotMaterials(robot); UrdfVisualizedLinkExtensions.Create(odomFrame.transform, robot.root); }
public static void Create(string filename, ImportSettings settings) { CreateTag(); importsettings = settings; Robot robot = new Robot(filename); if (!UrdfAssetPathHandler.IsValidAssetPath(robot.filename)) { Debug.LogError("URDF file and ressources must be placed in Assets Folder:\n" + Application.dataPath); return; } GameObject robotGameObject = new GameObject(robot.name); robotGameObject.tag = tagName; robotGameObject.AddComponent <UrdfRobot>(); robotGameObject.AddComponent <RosSharp.Control.Controller>(); robotGameObject.GetComponent <UrdfRobot>().SetAxis(settings.choosenAxis); UrdfAssetPathHandler.SetPackageRoot(Path.GetDirectoryName(robot.filename)); UrdfMaterial.InitializeRobotMaterials(robot); UrdfPlugins.Create(robotGameObject.transform, robot.plugins); UrdfLinkExtensions.Create(robotGameObject.transform, robot.root); GameObjectUtility.SetParentAndAlign(robotGameObject, Selection.activeObject as GameObject); Undo.RegisterCreatedObjectUndo(robotGameObject, "Create " + robotGameObject.name); Selection.activeObject = robotGameObject; CorrectAxis(robotGameObject); CreateCollisionExceptions(robot, robotGameObject); }