コード例 #1
0
	/// <summary>
	/// Generates a NPOT 6x1 cubemap in the following format PX NX PY NY PZ NZ
	/// </summary>
	void GenerateTexture(Cubemap cubemap, string pathName)
	{
		// Encode the texture and save it to disk
		pathName = pathName.Replace(".cubemap", (textureFormat == TexFormat.PNG) ? ".png" : ".jpg" ).ToLower():
		pathName = pathName.Replace( cubeMapFolder.ToLower(), "" ):
		string format = textureFormat.ToString():
		string fullPath = EditorUtility.SaveFilePanel( string.Format( "Save Cubemap Screenshot as {0}", format ), "", pathName, format.ToLower() ):
		if ( !string.IsNullOrEmpty( fullPath ) )
        {
			Debug.Log( "Saving: " + fullPath ):
			OVRCubemapCapture.SaveCubemapCapture(cubemap, fullPath):
		}
	}
コード例 #2
0
 private void Update()
 {
     if (this.autoTriggerAfterLaunch)
     {
         this.autoTriggerElapse += Time.deltaTime;
         if (this.autoTriggerElapse >= this.autoTriggerDelay)
         {
             this.autoTriggerAfterLaunch = false;
             OVRCubemapCapture.TriggerCubemapCapture(base.transform.position, this.cubemapSize, this.pathName);
         }
     }
     if (Input.GetKeyDown(this.triggeredByKey))
     {
         OVRCubemapCapture.TriggerCubemapCapture(base.transform.position, this.cubemapSize, this.pathName);
     }
 }
コード例 #3
0
    public static void TriggerCubemapCapture(Vector3 capturePos, int cubemapSize = 2048, string pathName = null)
    {
        GameObject gameObject = new GameObject("CubemapCamera", new Type[]
        {
            typeof(Camera)
        });

        gameObject.hideFlags          = HideFlags.HideAndDontSave;
        gameObject.transform.position = capturePos;
        gameObject.transform.rotation = Quaternion.identity;
        Camera component = gameObject.GetComponent <Camera>();

        component.farClipPlane = 10000f;
        component.enabled      = false;
        Cubemap cubemap = new Cubemap(cubemapSize, TextureFormat.RGB24, false);

        OVRCubemapCapture.RenderIntoCubemap(component, cubemap);
        OVRCubemapCapture.SaveCubemapCapture(cubemap, pathName);
        UnityEngine.Object.DestroyImmediate(cubemap);
        UnityEngine.Object.DestroyImmediate(gameObject);
    }
コード例 #4
0
    /// <summary>
    /// Renders the cubemap
    /// </summary>
    void OnWizardCreate()
    {
        if (!AssetDatabase.IsValidFolder(cubeMapFolder))
        {
            if (!CreateAssetPath(cubeMapFolder))
            {
                Debug.LogError("Created path failed: " + cubeMapFolder);
                return;
            }
        }

        bool   existingCamera          = true;
        bool   existingCameraStateSave = true;
        Camera camera = renderFrom.GetComponent <Camera>();

        if (camera == null)
        {
            camera = renderFrom.AddComponent <Camera>();
            camera.farClipPlane = 10000f;
            existingCamera      = false;
        }
        else
        {
            existingCameraStateSave = camera.enabled;
            camera.enabled          = true;
        }
        // find the last screenshot saved
        if (cubeMapFolder[cubeMapFolder.Length - 1] != '/')
        {
            cubeMapFolder += "/";
        }
        int idx = 0;

        string[] fileNames = Directory.GetFiles(cubeMapFolder);
        foreach (string fileName in fileNames)
        {
            if (!fileName.ToLower().EndsWith(".cubemap"))
            {
                continue;
            }
            string temp = fileName.Replace(cubeMapFolder + "vr_screenshot_", string.Empty);
            temp = temp.Replace(".cubemap", string.Empty);
            int tempIdx = 0;
            if (int.TryParse(temp, out tempIdx))
            {
                if (tempIdx > idx)
                {
                    idx = tempIdx;
                }
            }
        }
        string  pathName = string.Format("{0}vr_screenshot_{1}.cubemap", cubeMapFolder, (++idx).ToString("d2"));
        Cubemap cubemap  = new Cubemap(size, TextureFormat.RGB24, false);

        // render into cubemap
        if ((camera != null) && (cubemap != null))
        {
            // set up cubemap defaults
            OVRCubemapCapture.RenderIntoCubemap(camera, cubemap);
            if (existingCamera)
            {
                camera.enabled = existingCameraStateSave;
            }
            else
            {
                DestroyImmediate(camera);
            }
            // generate a regular texture as well?
            if ((saveMode == SaveMode.SaveCubemapScreenshot) || (saveMode == SaveMode.SaveBoth))
            {
                GenerateTexture(cubemap, pathName);
            }

            if ((saveMode == SaveMode.SaveUnityCubemap) || (saveMode == SaveMode.SaveBoth))
            {
                Debug.Log("Saving: " + pathName);
                // by default the unity cubemap isn't saved
                AssetDatabase.CreateAsset(cubemap, pathName);
                // reimport as necessary
                AssetDatabase.SaveAssets();
                // select it in the project tree so developers can find it
                EditorGUIUtility.PingObject(cubemap);
                Selection.activeObject = cubemap;
            }
            AssetDatabase.Refresh();
        }
    }