private static void CopyDaeTextureToExportDestination(string prefabPath, string newFolderLocation)
        {
            //Get material from Collada prefab
            Material material = AssetDatabase.LoadAssetAtPath <Material>(prefabPath);

            if (material.mainTexture == null)
            {
                return;
            }

            //Get relative subfolder where texture is, compared to the DAE file.
            string commonFolder     = Path.GetDirectoryName(prefabPath).SetSeparatorChar();
            string texturePath      = AssetDatabase.GetAssetPath(material.mainTexture).SetSeparatorChar();
            string relativeLocation = "";

            if (texturePath.Contains(commonFolder))
            {
                relativeLocation = texturePath.Substring(commonFolder.Length + 1);
            }
            string newTexturePath = Path.Combine(newFolderLocation, relativeLocation);

            Directory.CreateDirectory(Path.GetDirectoryName(newTexturePath));

            CopyFileToNewLocation(UrdfAssetPathHandler.GetFullAssetPath(texturePath), newTexturePath);
        }
Beispiel #2
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 void CreateSimulatedUrdfObject()
        {
            string assetPath = AssetDatabase.GetAssetPath(Selection.activeObject);

            if (Path.GetExtension(assetPath)?.ToLower() == ".urdf")
            {
                UrdfSimulatedRobotExtensions.CreateFromFile(UrdfAssetPathHandler.GetFullAssetPath(assetPath));
            }
            else
            {
                EditorUtility.DisplayDialog("Urdf Import As Simulation",
                                            "The file you selected was not a URDF file. A robot can only be imported from a valid URDF file.", "Ok");
            }
        }
        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);
        }
Beispiel #5
0
        private static void CreateUrdfObject()
        {
            //Get path to asset, check if it's a urdf file
            string assetPath = AssetDatabase.GetAssetPath(Selection.activeObject);

            if (Path.GetExtension(assetPath)?.ToLower() == ".urdf")
            {
                UrdfRobotExtensions.Create(UrdfAssetPathHandler.GetFullAssetPath(assetPath));
            }
            else
            {
                EditorUtility.DisplayDialog("URDF Import",
                                            "The file you selected was not a URDF file. A robot can only be imported from a valid URDF file.", "Ok");
            }
        }
        private static void CreateUrdfObject()
        {
            //Get path to asset, check if it's a urdf file
            string assetPath = AssetDatabase.GetAssetPath(Selection.activeObject);

            if (Path.GetExtension(assetPath)?.ToLower() == ".urdf")
            {
                // Get existing open window or if none, make a new one:
                FileImportMenu window = (FileImportMenu)EditorWindow.GetWindow(typeof(FileImportMenu));
                window.urdfFile = UrdfAssetPathHandler.GetFullAssetPath(assetPath);
                window.minSize  = new Vector2(500, 200);
                window.Show();
            }
            else
            {
                EditorUtility.DisplayDialog("URDF Import",
                                            "The file you selected was not a URDF file. Please select a valid URDF file.", "Ok");
            }
        }