Example #1
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);
        }
Example #2
0
        private static GameObject CreateMeshColliderRuntime(Link.Geometry.Mesh mesh)
        {
            string     meshFilePath = UrdfAssetPathHandler.GetRelativeAssetPathFromUrdfPath(mesh.filename, false);
            GameObject meshObject   = null;

            if (meshFilePath.ToLower().EndsWith(".stl"))
            {
                meshObject = StlAssetPostProcessor.CreateStlGameObjectRuntime(meshFilePath);
            }
            else
            {
                Debug.LogError("Unable to create mesh collider for the mesh: " + mesh.filename);
            }

            if (meshObject != null)
            {
                ConvertMeshToColliders(meshObject);
            }
            return(meshObject);
        }
Example #3
0
        private static GameObject CreateMeshVisualRuntime(Link.Geometry.Mesh mesh)
        {
            GameObject meshObject = null;

            if (!string.IsNullOrEmpty(mesh.filename))
            {
                try
                {
                    string meshFilePath = UrdfAssetPathHandler.GetRelativeAssetPathFromUrdfPath(mesh.filename, false);
                    if (meshFilePath.ToLower().EndsWith(".stl"))
                    {
                        meshObject = StlAssetPostProcessor.CreateStlGameObjectRuntime(meshFilePath);
                    }
                    else if (meshFilePath.ToLower().EndsWith(".dae"))
                    {
                        float globalScale = ColladaAssetPostProcessor.ReadGlobalScale(meshFilePath);
                        meshObject = MeshImporter.Load(meshFilePath, globalScale, globalScale, globalScale);
                        if (meshObject != null)
                        {
                            ColladaAssetPostProcessor.ApplyColladaOrientation(meshObject, meshFilePath);
                        }
                    }
                    else if (meshFilePath.ToLower().EndsWith(".obj"))
                    {
                        meshObject = MeshImporter.Load(meshFilePath);
                    }
                }
                catch (Exception ex)
                {
                    Debug.LogAssertion(ex);
                }

                if (meshObject == null)
                {
                    Debug.LogError("Unable to load visual mesh: " + mesh.filename);
                }
            }
            return(meshObject);
        }