Example #1
0
        public static GameObject Create(this Link.Visual visual, GameObject parent)
        {
            GameObject gameObject = new GameObject((visual.name == null) ? "unnamed" : visual.name);

            gameObject.transform.SetParentAndAlign(parent.transform);

            if (visual.origin != null)
            {
                visual.origin.SetTransform(gameObject);
            }

            visual.geometry.CreateVisual(gameObject);


            if (visual.material != null)
            {
                UrdfAssetDatabase.SetMaterial(gameObject, visual.material.name);
            }

            if (gameObject.GetComponentInChildren <Renderer>().sharedMaterial == null)
            {
                UrdfAssetDatabase.SetDefaultMaterial(gameObject);
            }

            return(gameObject);
        }
        public static GameObject CreateVisual(this Link.Geometry.Mesh mesh, GameObject parent)
        {
            string     assetPath  = UrdfAssetDatabase.GetAssetPathFromPackagePath(mesh.filename);
            GameObject gameObject = Object.Instantiate(AssetDatabase.LoadAssetAtPath <GameObject>(assetPath));

            gameObject.transform.SetParentAndAlign(parent.transform);
            mesh.setScale(gameObject);
            return(gameObject);
        }
        private static T LocateAssetFile <T>() where T : UnityEngine.Object
        {
            T      assetObject;
            string newAssetFilePath = EditorUtility.OpenFilePanel(
                "Couldn't find asset at " + fileAssetPath + ". Select correct file.",
                Path.Combine(Path.GetDirectoryName(Application.dataPath), "Assets"),
                "");

            fileAssetPath = UrdfAssetDatabase.GetAssetPathFromAbsolutePath(newAssetFilePath);
            assetObject   = (T)AssetDatabase.LoadAssetAtPath(fileAssetPath, typeof(T));
            return(assetObject);
        }
        private static T LocateRootAssetFolder <T>(string assetFileName) where T : UnityEngine.Object
        {
            T      assetObject;
            string newAssetPath = EditorUtility.OpenFolderPanel(
                "Locate package root folder",
                Path.Combine(Path.GetDirectoryName(Application.dataPath), "Assets"),
                "");

            UrdfAssetDatabase.UpdateAssetPath(UrdfAssetDatabase.GetAssetPathFromAbsolutePath(newAssetPath));
            fileAssetPath = UrdfAssetDatabase.GetAssetPathFromPackagePath(assetFileName);
            assetObject   = (T)AssetDatabase.LoadAssetAtPath(fileAssetPath, typeof(T));
            return(assetObject);
        }
        public static GameObject CreateCollider(this Link.Geometry.Mesh mesh, GameObject parent)
        {
            GameObject gameObject = new GameObject(mesh.filename + "(MeshCollider)");
            GameObject reference  = AssetDatabase.LoadAssetAtPath <GameObject>(UrdfAssetDatabase.GetAssetPathFromPackagePath(mesh.filename));

            gameObject.transform.position   = reference.transform.position;
            gameObject.transform.rotation   = reference.transform.rotation;
            gameObject.transform.localScale = reference.transform.localScale;

            MeshFilter[] meshFilters = reference.GetComponentsInChildren <MeshFilter>();
            foreach (MeshFilter meshFilter in meshFilters)
            {
                MeshCollider meshCollider = gameObject.AddComponent <MeshCollider>();
                meshCollider.sharedMesh = meshFilter.sharedMesh;
            }
            gameObject.transform.SetParentAndAlign(parent.transform);
            mesh.setScale(gameObject);

            return(gameObject);
        }
        public static T FindUrdfAsset <T>(string assetFileName) where T : UnityEngine.Object
        {
            fileAssetPath = UrdfAssetDatabase.GetAssetPathFromPackagePath(assetFileName);
            T assetObject = AssetDatabase.LoadAssetAtPath <T>(fileAssetPath);

            if (assetObject != null)
            {
                return(assetObject);
            }

            int option = EditorUtility.DisplayDialogComplex("Urdf Importer: Asset Not Found",
                                                            "Current root folder: " + UrdfAssetDatabase.GetAssetRootFolder() +
                                                            "\n\nExpected asset path: " + fileAssetPath,
                                                            "Locate Asset",
                                                            "Ignore Missing Asset",
                                                            "Locate Root Folder");

            switch (option)
            {
            case 0:
                assetObject = LocateAssetFile <T>();
                break;

            case 1: break;

            case 2:
                assetObject = LocateRootAssetFolder <T>(assetFileName);
                break;

            default: break;
            }

            if (assetObject != null)
            {
                return(assetObject);
            }

            ChooseFailureOption(fileAssetPath);
            return(null);
        }
Example #7
0
        public static GameObject Create(this Robot robot)
        {
            if (UrdfAssetDatabase.GetAssetParentDirectoryPath(robot.filename) == null)
            {
                Debug.LogError("URDF file and ressources must be placed in Assets Folder:\n" + Application.dataPath);
                return(null);
            }

            UrdfAssetDatabase.Initialize(robot);

            GameObject gameObject = new GameObject(robot.name);

            robot.root.Create(gameObject);

            GameObjectUtility.SetParentAndAlign(gameObject, Selection.activeObject as GameObject);
            Undo.RegisterCreatedObjectUndo(gameObject, "Create " + gameObject.name);
            Selection.activeObject = gameObject;

            setKinematic(gameObject, true);

            return(gameObject);
        }
Example #8
0
        public static GameObject CreateCollider(this Link.Geometry.Mesh mesh, GameObject parent)
        {
            GameObject gameObject = Object.Instantiate(AssetDatabase.LoadAssetAtPath <GameObject>(UrdfAssetDatabase.GetAssetPathFromPackagePath(mesh.filename)));

            MeshFilter[] meshFilters = gameObject.GetComponentsInChildren <MeshFilter>();
            foreach (MeshFilter meshFilter in meshFilters)
            {
                GameObject   child        = meshFilter.gameObject;
                MeshCollider meshCollider = child.AddComponent <MeshCollider>();
                meshCollider.sharedMesh = meshFilter.sharedMesh;
                Object.DestroyImmediate(child.GetComponent <MeshRenderer>());
                Object.DestroyImmediate(meshFilter);
            }
            mesh.setScale(gameObject);
            gameObject.transform.SetParentAndAlign(parent.transform);
            return(gameObject);
        }