Esempio n. 1
0
        private static Link.Geometry ExportGeometryMeshData(GameObject geometryObject, double[] urdfSize, bool isCollisionGeometry)
        {
            string newFilePath = UrdfMeshExportHandler.CopyOrCreateMesh(geometryObject, isCollisionGeometry);
            string packagePath = UrdfExportPathHandler.GetPackagePathForMesh(newFilePath);

            return(new Link.Geometry(null, null, null, new Link.Geometry.Mesh(packagePath, urdfSize)));
        }
Esempio n. 2
0
        public void ExportGeometryData_MeshUnityDecomposer_DefaultGeometry()
        {
            // Force runtime mode to set testing package root
            RuntimeUrdf.runtimeModeEnabled = true;
            UrdfAssetPathHandler.SetPackageRoot("Packages/com.unity.robotics.urdf-importer/Tests/Runtime/Assets/URDF/cube/");
            RuntimeUrdf.runtimeModeEnabled     = false;
            UrdfRobotExtensions.importsettings = ImportSettings.DefaultSettings();
            UrdfRobotExtensions.importsettings.convexMethod = ImportSettings.convexDecomposer.unity;

            var    parent       = new GameObject("Parent").transform;
            string path         = "package://meshes/cube.stl";
            var    meshGeometry = new Geometry(mesh: new Mesh(path, new double[] { 1, 1, 1 }));

            UrdfCollisionExtensions.Create(parent, new Collision(meshGeometry));

            UrdfExportPathHandler.SetExportPath("Assets");
            var t      = parent.GetComponentInChildren <UrdfCollision>().transform.GetChild(0);
            var export = UrdfGeometry.ExportGeometryData(GeometryTypes.Mesh, t);

            Assert.IsNotNull(export);

            Object.DestroyImmediate(parent.gameObject);
            List <string> outFailedPaths = new List <string>();

            AssetDatabase.DeleteAssets(new string[] { "Assets/meshes" }, outFailedPaths);
        }
Esempio n. 3
0
        private static Link.Visual.Material.Texture ExportTextureData(Texture texture)
        {
            string oldTexturePath = UrdfAssetPathHandler.GetFullAssetPath(AssetDatabase.GetAssetPath(texture));
            string newTexturePath = UrdfExportPathHandler.GetNewResourcePath(Path.GetFileName(oldTexturePath));

            if (oldTexturePath != newTexturePath)
            {
                File.Copy(oldTexturePath, newTexturePath, true);
            }

            string packagePath = UrdfExportPathHandler.GetPackagePathForResource(newTexturePath);

            return(new Link.Visual.Material.Texture(packagePath));
        }
        private static string CopyMeshToExportDestination(string prefabPath)
        {
            string newPrefabPath = UrdfExportPathHandler.GetNewMeshPath(Path.GetFileName(prefabPath));

            if (Path.GetExtension(prefabPath)?.ToLower() == ".dae")
            {
                CopyDaeTextureToExportDestination(prefabPath, Path.GetDirectoryName(newPrefabPath));
            }

            prefabPath = UrdfAssetPathHandler.GetFullAssetPath(prefabPath);

            CopyFileToNewLocation(prefabPath, newPrefabPath);

            return(newPrefabPath);
        }
        private static string CreateNewStlFile(GameObject geometryObject, bool isCollisionGeometry)
        {
            Debug.Log("Did not find an existing STL or DAE file for Geometry Mesh "
                      + geometryObject.name + ". Exporting a new STL file.", geometryObject);

            string newMeshPath = UrdfExportPathHandler.GetNewMeshPath(geometryObject.name + ".stl");

            StlExporter stlExporter = new StlExporter(newMeshPath, geometryObject, isCollisionGeometry);

            if (!stlExporter.Export())
            {
                Debug.LogWarning("Mesh export for geometry " + geometryObject.name + " failed.", geometryObject);
            }

            return(newMeshPath);
        }
        public static void ExportRobotToUrdf(this UrdfRobot urdfRobot, string exportRootFolder, string exportDestination)
        {
            UrdfExportPathHandler.SetExportPath(exportRootFolder, exportDestination);

            urdfRobot.FilePath = Path.Combine(UrdfExportPathHandler.GetExportDestination(), urdfRobot.name + ".urdf");

            Robot robot = urdfRobot.ExportRobotData();

            if (robot == null)
            {
                return;
            }

            robot.WriteToUrdf();

            UnityEngine.Debug.Log(robot.name + " was exported to " + UrdfExportPathHandler.GetExportDestination());

            UrdfMaterial.Materials.Clear();
            UrdfExportPathHandler.Clear();
            AssetDatabase.Refresh();
        }