Ejemplo n.º 1
0
    private IEnumerator LoadCamFromFile(string camJSONPath)
    {
        SerializableCAVECam camFile;

        if (File.Exists(camJSONPath))
        {
            string camJson = File.ReadAllText(camJSONPath);

            camFile = JsonUtility.FromJson <SerializableCAVECam>(camJson);

            Debug.Log("Found Cam. Loading");

            yield return(null);
        }

        else
        {
            if (File.Exists(defaultCamPath))
            {
                Debug.LogWarning("No CAVECam JSON found at " + camJSONPath + ". Attempting to use default path: " + defaultCamPath);

                string objJSON = File.ReadAllText(defaultCamPath);

                camFile = JsonUtility.FromJson <SerializableCAVECam>(objJSON);

                yield return(null);
            }
            else
            {
                if (!File.Exists(defaultLeftEyePath) || !File.Exists(defaultRightEyePath))
                {
                    Debug.LogErrorFormat("Cannot load CAVECam, and no defaults set. Please create defaults to prevent this error");
                    yield break;
                }

                camFile = new SerializableCAVECam(defaultLeftEyePath, defaultRightEyePath, "Default Text");

                File.WriteAllText(defaultCamPath, JsonUtility.ToJson(camFile));

                Debug.LogWarningFormat("No CAVECam JSON found at {0}, and no default JSON at {1}. Creating a blank cam with left eye {2} and right eye {3}.", camJSONPath, defaultCamPath, defaultLeftEyePath, defaultRightEyePath);

                yield return(null);
            }
        }

        siteData = camFile;
        Load();
    }
Ejemplo n.º 2
0
    private IEnumerator LoadCamFromFile(string camJSONPath)
    {
        SerializableCAVECam camFile;

        if (File.Exists(camJSONPath))
        {
            string camJson = File.ReadAllText(camJSONPath);

            camFile = JsonUtility.FromJson <SerializableCAVECam>(camJson);

            Debug.Log("Found Cam. Loading");

            yield return(null);
        }

        else
        {
            if (File.Exists(defaultCamPath))
            {
                camFile = JsonUtility.FromJson <SerializableCAVECam>(defaultCamPath);

                Debug.LogWarning("No CAVECam JSON found at " + camJSONPath + ". Attempting to use default path: " + defaultCamPath);

                yield return(null);
            }
            else
            {
                if (!File.Exists(defaultLeftEyePath) || !File.Exists(defaultRightEyePath))
                {
                    Debug.LogErrorFormat("Cannot load CAVECam, and no defaults set. Please create defaults to prevent this error");
                    yield break;
                }

                camFile = new SerializableCAVECam(defaultLeftEyePath, defaultRightEyePath, "Default Text");

                File.WriteAllText(defaultCamPath, camFile.GetJSON());

                Debug.LogWarningFormat("No CAVECam JSON found at {0}, and no default JSON at {1}. Creating a blank cam with left eye {2} and right eye {3}.", camJSONPath, defaultCamPath, defaultLeftEyePath, defaultRightEyePath);

                yield return(null);
            }
        }


        leftEyePath  = camFile.leftEye.filePath;
        rightEyePath = camFile.rightEye.filePath;

        List <Texture2D> leftTextures  = new List <Texture2D>();
        List <Texture2D> rightTextures = new List <Texture2D>();

        if (Directory.Exists(GetCacheDirectory(leftEyePath)))
        {
            yield return(StartCoroutine(GetTexturesFromCache(leftEyePath, leftTextures)));
        }
        else
        {
            yield return(StartCoroutine(GetTexturesFromTif(leftEyePath, leftTextures)));
        }

        if (Directory.Exists(GetCacheDirectory(rightEyePath)))
        {
            yield return(StartCoroutine(GetTexturesFromCache(rightEyePath, rightTextures)));
        }
        else
        {
            yield return(StartCoroutine(GetTexturesFromTif(rightEyePath, rightTextures)));
        }

        int leftTexSize  = leftTextures[0].width;
        int rightTexSize = rightTextures[0].width;

        TextureFormat format = leftTextures[0].format;

        Cubemap leftCubemap  = new Cubemap(leftTexSize, format, false);
        Cubemap rightCubemap = new Cubemap(rightTexSize, format, false);

        Debug.LogFormat("Left Tex Size: {0}", leftTexSize);
        Debug.LogFormat("Right Tex Size: {0}", rightTexSize);

        yield return(StartCoroutine(CreateCubemapFromTextures(leftTextures, leftCubemap)));

        yield return(StartCoroutine(CreateCubemapFromTextures(rightTextures, rightCubemap)));

        leftCubemap.Apply();
        rightCubemap.Apply();

        Debug.Log("Created Cubemaps");

        Debug.LogFormat("LEFT CUBEMAP: {0}", leftCubemap);

        yield return(null);

        leftEye  = new Material(Shader.Find("Skybox/Cubemap"));
        rightEye = new Material(Shader.Find("Skybox/Cubemap"));

        leftEye.SetTexture(Shader.PropertyToID("_Tex"), leftCubemap);
        rightEye.SetTexture(Shader.PropertyToID("_Tex"), rightCubemap);


        yield return(null);
    }
Ejemplo n.º 3
0
    protected override IEnumerator LoadCoroutine()
    {
        if (this.idleAnimation == null)
        {
            this.idleAnimation = new SpinningIdle(0.05f);
        }

        SerializableCAVECam camData = siteData as SerializableCAVECam;

        Debug.Log("Loading " + camData.name);

        if (camData.cube4096 == null || string.IsNullOrEmpty(camData.cube4096.left) || string.IsNullOrEmpty(camData.cube4096.right))
        {
            leftEyePath  = GetAbsolutePath(camData.cube1024.left);
            rightEyePath = GetAbsolutePath(camData.cube1024.right);
        }
        else
        {
            leftEyePath  = GetAbsolutePath(camData.cube4096.left);
            rightEyePath = GetAbsolutePath(camData.cube4096.right);
        }


        if (!File.Exists(leftEyePath) || !File.Exists(rightEyePath))
        {
            StatusText.SetText("Failed to load files");
            Debug.LogErrorFormat("Could not load pano: Failed to find left pano {0} or right pano {1}", leftEyePath, rightEyePath);
        }

        else
        {
            yield return(StartCoroutine(LoadAndSaveCubemapMaterials(rightEyePath, true)));

            if (CAVECameraRig.isCAVE)
            {
                yield return(StartCoroutine(LoadAndSaveCubemapMaterials(leftEyePath, false)));
            }
            else
            {
                leftEye = rightEye;
            }

            loaded = true;

            yield return(null);
        }

        //Janky memory fix, remove and watch your ram skyrocket
        var    wait = new WaitForSeconds(0.01f);
        string name = SceneManager.GetActiveScene().name;

        yield return(SceneManager.LoadSceneAsync(name));

        yield return(wait);

        yield return(SceneManager.LoadSceneAsync(name));

        yield return(wait);

        yield return(SceneManager.LoadSceneAsync(name));

        yield return(wait);

        yield return(SceneManager.LoadSceneAsync(name));

        yield return(wait);

        yield return(SceneManager.LoadSceneAsync(name));

        yield return(wait);

        yield return(SceneManager.LoadSceneAsync(name));

        yield return(wait);

        yield return(SceneManager.LoadSceneAsync(name));

        yield return(wait);

        yield return(SceneManager.LoadSceneAsync(name));

        yield return(wait);

        yield return(SceneManager.LoadSceneAsync(name));

        yield return(wait);

        yield return(SceneManager.LoadSceneAsync(name));

        yield return(wait);

        yield return(SceneManager.LoadSceneAsync(name));

        yield return(wait);

        yield return(SceneManager.LoadSceneAsync(name));

        yield return(wait);
    }