public static GameObject CreateCollider(this Link.Geometry.Mesh mesh, GameObject parent)
        {
            GameObject prefabObject = LocateAssetHandler.FindUrdfAsset <GameObject>(mesh.filename);

            if (prefabObject == null)
            {
                return(null);
            }

            GameObject meshObject = Object.Instantiate(prefabObject);

            MeshFilter[] meshFilters = meshObject.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(meshObject);
            meshObject.transform.SetParentAndAlign(parent.transform);
            return(meshObject);
        }
Esempio n. 2
0
        public static GameObject CreateVisual(this Link.Geometry.Mesh mesh, GameObject parent)
        {
            GameObject gameObject = Object.Instantiate(AssetDatabase.LoadAssetAtPath <GameObject>(UrdfAssetDatabase.GetAssetPathFromPackagePath(mesh.filename)));

            mesh.setScale(gameObject);
            gameObject.transform.SetParentAndAlign(parent.transform);
            return(gameObject);
        }
 private static void setScale(this Link.Geometry.Mesh mesh, GameObject gameObject)
 {
     if (mesh.scale != null)
     {
         Vector3 scale = new Vector3((float)mesh.scale[0], (float)mesh.scale[1], (float)mesh.scale[2]);
         gameObject.transform.localScale = Vector3.Scale(gameObject.transform.localScale, scale);
     }
 }
        public static GameObject CreateVisual(this Link.Geometry.Mesh mesh, GameObject parent)
        {
            GameObject meshObject = LocateAssetHandler.FindUrdfAsset <GameObject>(mesh.filename);

            if (meshObject != null)
            {
                GameObject gameObject = Object.Instantiate(meshObject);
                mesh.setScale(gameObject);
                gameObject.transform.SetParentAndAlign(parent.transform);
                return(gameObject);
            }
            return(null);
        }
Esempio n. 5
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);
        }
        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);
        }