Beispiel #1
0
        private static string LocateAssetFile(string invalidPath)
        {
            string fileExtension = Path.GetExtension(invalidPath)?.Replace(".", "");

            string newPath = RuntimeUrdf.EditorUtility_OpenFilePanel(
                "Couldn't find asset at " + invalidPath + ". Select correct file.",
                UrdfAssetPathHandler.GetPackageRoot(),
                fileExtension);

            return(UrdfAssetPathHandler.GetRelativeAssetPath(newPath));
        }
Beispiel #2
0
 private static void MoveMaterialsToNewLocation(string oldPackageRoot)
 {
     if (RuntimeUrdf.AssetDatabase_IsValidFolder(Path.Combine(oldPackageRoot, MaterialFolderName)))
     {
         RuntimeUrdf.AssetDatabase_MoveAsset(
             Path.Combine(oldPackageRoot, MaterialFolderName),
             Path.Combine(UrdfAssetPathHandler.GetPackageRoot(), MaterialFolderName));
     }
     else
     {
         RuntimeUrdf.AssetDatabase_CreateFolder(UrdfAssetPathHandler.GetPackageRoot(), MaterialFolderName);
     }
 }
Beispiel #3
0
        private static void ConvertCylinderToCollider(MeshFilter filter)
        {
            GameObject go       = filter.gameObject;
            var        collider = filter.sharedMesh;

            // Only create an asset if not runtime import
            if (!RuntimeUrdf.IsRuntimeMode())
            {
                var packageRoot = UrdfAssetPathHandler.GetPackageRoot();
                var filePath    = RuntimeUrdf.AssetDatabase_GUIDToAssetPath(RuntimeUrdf.AssetDatabase_CreateFolder($"{packageRoot}", "meshes"));
                var name        = $"{filePath}/Cylinder.asset";
                Debug.Log($"Creating new cylinder file: {name}");
                RuntimeUrdf.AssetDatabase_CreateAsset(collider, name, uniquePath: true);
                RuntimeUrdf.AssetDatabase_SaveAssets();
            }
            MeshCollider current = go.AddComponent <MeshCollider>();

            current.sharedMesh = collider;
            current.convex     = true;
            Object.DestroyImmediate(go.GetComponent <MeshRenderer>());
            Object.DestroyImmediate(filter);
        }
Beispiel #4
0
        public static T FindUrdfAsset <T>(string urdfFileName) where T : UnityEngine.Object
        {
            string fileAssetPath = UrdfAssetPathHandler.GetRelativeAssetPathFromUrdfPath(urdfFileName);

            // check if it is an asset tha requires post processing (AIRO-908)
            var originalUrdfPath = UrdfAssetPathHandler.GetRelativeAssetPathFromUrdfPath(urdfFileName, false);

            if (originalUrdfPath.ToLower().EndsWith(".stl"))
            {     // it is an asset that requires post processing
                if (UrdfRobotExtensions.importsettings.OverwriteExistingPrefabs || !RuntimeUrdf.AssetExists(fileAssetPath, true))
                { // post process again to (re)create prefabs
                    StlAssetPostProcessor.PostprocessStlFile(originalUrdfPath);
                }
            }

            T assetObject = RuntimeUrdf.AssetDatabase_LoadAssetAtPath <T>(fileAssetPath);

            if (assetObject)
            {
                return(assetObject);
            }

            //If asset was not found, let user choose whether to search for
            //or ignore the missing asset.
            string invalidPath = fileAssetPath ?? urdfFileName;
            int    option      = RuntimeUrdf.EditorUtility_DisplayDialogComplex("Urdf Importer: Asset Not Found",
                                                                                "Current root folder: " + UrdfAssetPathHandler.GetPackageRoot() +
                                                                                "\n\nExpected asset path: " + invalidPath,
                                                                                "Locate Asset",
                                                                                "Ignore Missing Asset",
                                                                                "Locate Root Folder");

            switch (option)
            {
            case 0:
                fileAssetPath = LocateAssetFile(invalidPath);
                break;

            case 1: break;

            case 2:
                fileAssetPath = LocateRootAssetFolder <T>(urdfFileName);
                break;
            }

            assetObject = (T)RuntimeUrdf.AssetDatabase_LoadAssetAtPath(fileAssetPath, typeof(T));
            if (assetObject != null)
            {
                return(assetObject);
            }

            ChooseFailureOption(urdfFileName);
            return(null);
        }