Answer the question
In order to leave comments, you need to log in
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.
[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();
}
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");
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question