Skip to content

GLTFImage.cs ToTexture2D() ERROR: Cannot connect to destination host When Importing #239

Open

Description

@BatuhanCandr

IEnumerator DownloadAvatar()
{
Debug.LogError("Test 1 ");
string[] avatarUrls = new string[]
{
//URLs
};
Debug.LogError("Test 2 ");
for (int i = 0; i < avatarUrls.Length; i++)
{
Debug.LogError("Test 3 ");
using (UnityWebRequest www = UnityWebRequest.Get(avatarUrls[i]))
{
yield return www.SendWebRequest();

            if (www.result == UnityWebRequest.Result.Success)
            {
                string filePath = Application.persistentDataPath + "/" + Path.GetFileName(avatarUrls[i]);

                Debug.LogError("Test 7 ");
                File.WriteAllBytes(filePath, www.downloadHandler.data);
                Debug.LogError("Test 8");

                string extension = Path.GetExtension(filePath).ToLower();
                if (extension == ".bin")
                {
                    // do something with binary data
                    Debug.LogError("Test 11 ");
                }
                Debug.LogError("Test 9 ");
                if (extension == ".jpg")
                {
                    Debug.Log("jpg before");
                    _avatarTex = new Texture2D(2, 2);
                    defaultMat.mainTexture = _avatarTex;
                    _avatarTex.LoadImage(www.downloadHandler.data);
                    Debug.LogError("Test 10 ");
                }

               

                if (extension == ".gltf")
                {
                    GameObject result = Importer.LoadFromFile(filePath);
                    result.transform.GetChild(0).GetComponent<SkinnedMeshRenderer>().material = defaultMat;
                    result.transform.position = Vector3.zero;
                    Debug.LogError("Test 12 ");
                }
            }
            else
            {
                Debug.LogError("Error downloading file: " + www.error);
                Debug.LogError("Test 6 ");
            }
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions