P
P
Pychev Anatoly2020-08-19 12:26:51
Unity
Pychev Anatoly, 2020-08-19 12:26:51

How to properly fill texture using UnityWebRequest?

Hello.
There is a VR project with a "sphere" object. The camera is inside the sphere. The texture on the sphere is loaded programmatically via http.
In the previous version of the project, the WWW tool was used to load the texture, but it has recently been deprecated. An attempt was made to replace it with a new UnityWebRequest. As a result, artifacts appeared on the image.
5f3cef51d5c04588641221.jpeg
5f3cef5b21bef167100168.jpeg

Download Code via WWW
[SerializeField] private MeshRenderer SphereMesh;
 
    private Texture2D texture;
 
    void Start()
    {
        texture = new Texture2D(8192, 4096);
        SphereMesh.material.mainTexture = texture;
        StartCoroutine(InitializeVR("http://server/im1.jpg"));
       
    }
 
    IEnumerator InitializeVR(string url)
    {
        WWW www = new WWW(url);
        yield return www;
        www.LoadImageIntoTexture(texture);
        Screen.orientation = ScreenOrientation.LandscapeLeft;
        www.Dispose();
    }

Loading code via UnityWebRequest
void Start()
    {
        StartCoroutine(setHDR("server/im1.jpg"));
 
    }
 
    IEnumerator setHDR(string url)
    {
        using (UnityWebRequest uwr = UnityWebRequestTexture.GetTexture(url))
        {
            yield return uwr.SendWebRequest();
 
            if (uwr.isNetworkError || uwr.isHttpError)
            {
                Debug.Log(uwr.error);
            }
            else
            {
                SphereMesh.material.mainTexture = DownloadHandlerTexture.GetContent(uwr);
                Screen.orientation = ScreenOrientation.LandscapeLeft;
 
                Debug.Log("complete");
            }
        }
    }

Sphere settings screen
5f3cf03c958a2663479932.png


Please tell me where to fix or what to pay attention to.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2020-08-19
@pton

https://forum.unity.com/threads/generate-mipmaps-a...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question