Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System.IO;
- using System.Collections.Generic;
- public class LoadImages : MonoBehaviour {
- public string baseDir = @"C:\panoramic";
- public List<KeyValuePair<int, Texture2D>> images = new List<KeyValuePair<int, Texture2D>>();
- private string[,] filepaths;
- private int contadorDir = 0;
- private GameObject cilindro;
- private GameObject[] cilindroChildren = new GameObject[4];
- private Renderer renderer;
- private string[] dirs;
- private GameObject loading;
- private TextMesh loadingtext;
- private int contadorLoaded = 0;
- private WWW load;
- Texture2D tempTexture;
- // Use this for initialization
- public IEnumerator Start()
- {
- cilindro = GameObject.Find("cilindro");
- loading = GameObject.Find("loading");
- loadingtext = loading.GetComponent<TextMesh>();
- loadingtext.text = "Loading (0%)";
- loading.SetActive(true);
- cilindro.SetActive(false);
- //UnityEngine.VR.InputTracking.Recenter();
- OVRManager.display.timeWarp = true;
- OVRManager.display.RecenterPose();
- dirs = Directory.GetDirectories(baseDir);
- filepaths = new string[dirs.Length, 4]; //Cada diretório / panorama contém 4 imagens
- for (int i = 0; i < dirs.Length; i++)
- {
- filepaths[i, 0] = dirs[i] + "\\1.png";
- filepaths[i, 1] = dirs[i] + "\\2.png";
- filepaths[i, 2] = dirs[i] + "\\3.png";
- filepaths[i, 3] = dirs[i] + "\\4.png";
- }
- yield return StartCoroutine("LoadAll", filepaths);
- //Setar as primeiras texturas
- setTextures();
- loading.SetActive(false);
- cilindro.SetActive(true);
- }
- private void setTextures()
- {
- loading.SetActive(true);
- cilindro.SetActive(false);
- //UnityEngine.VR.InputTracking.Recenter();
- OVRManager.display.RecenterPose();
- for (int i = 0; i < cilindro.transform.childCount; i++)
- {
- cilindroChildren[i] = cilindro.transform.GetChild(i).gameObject;
- renderer = cilindroChildren[i].GetComponent<Renderer>();
- renderer.material.mainTexture = images[(contadorDir * 4) + i].Value;
- Debug.Log("Image " + (i + 1) + " set");
- }
- Debug.Log("Textures set");
- loading.SetActive(false);
- cilindro.SetActive(true);
- }
- public IEnumerator LoadAll(string[,] filePaths)
- {
- Debug.Log("Load started..");
- //Carregar as 4 texturas deste panorama
- for (int i = 0; i < dirs.Length; i++)
- {
- for (int j = 0; j < 4; j++)
- {
- Debug.Log("Loading image " + (i+1) + ": " + (j + 1));
- loadingtext.text = "Loading.. (" + contadorLoaded * 100 / (dirs.Length * 4) + "%)";
- contadorLoaded++;
- load = new WWW("file:///" + filepaths[i, j]);
- yield return load;
- if (!string.IsNullOrEmpty(load.error))
- {
- Debug.LogWarning(filepaths[i, j] + " error");
- }
- else
- {
- tempTexture = new Texture2D(2048, 2048, TextureFormat.DXT1, true);
- load.LoadImageIntoTexture((Texture2D)tempTexture);
- tempTexture.filterMode = FilterMode.Bilinear;
- tempTexture.anisoLevel = 1;
- images.Add(new KeyValuePair<int, Texture2D>(i, tempTexture));
- }
- Debug.Log("Image " + (i+1) + ": "+ (j + 1) + " loaded");
- }
- }
- Debug.Log("Load finished!");
- }
- // Update is called once per frame
- void Update()
- {
- if (Input.GetKeyUp(KeyCode.Return))
- {
- if (contadorDir < dirs.Length - 1)
- {
- contadorDir++;
- }else{
- contadorDir = 0;
- }
- setTextures();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement