/// <summary> /// Generate unity cubemap at specific location and save into JPG/PNG /// </summary> /// <description> /// Default save folder: your app's persistentDataPath /// Default file name: using current time OVR_hh_mm_ss.png /// Note1: this will take a few seconds to finish /// Note2: if you only want to specify path not filename, please end [pathName] with "/" /// </description> public static void TriggerCubemapCapture(Vector3 capturePos, CubemapSize cubemapSize = CubemapSize.Size_2048x2048, string pathName = null) { GameObject ownerObj = new GameObject("CubemapCamera", typeof(Camera)); ownerObj.hideFlags = HideFlags.HideAndDontSave; ownerObj.transform.position = capturePos; ownerObj.transform.rotation = Quaternion.identity; Camera camComponent = ownerObj.GetComponent <Camera>(); camComponent.farClipPlane = 10000.0f; camComponent.enabled = false; Cubemap cubemap = new Cubemap((int)cubemapSize, TextureFormat.RGB24, false); camComponent.RenderToCubemap(cubemap, 63); SaveCubemapCapture(cubemap, pathName); DestroyImmediate(cubemap); DestroyImmediate(ownerObj); }
/// <summary> /// Generate unity cubemap at specific location and save into JPG/PNG /// </summary> /// <description> /// Default save folder: your app's persistentDataPath /// Default file name: using current time OVR_hh_mm_ss.png /// Note1: this will take a few seconds to finish /// Note2: if you only want to specify path not filename, please end [pathName] with "/" /// </description> public static void TriggerCubemapCapture(Vector3 capturePos, CubemapSize cubemapSize = CubemapSize.Size_2048x2048, string pathName = null) { GameObject ownerObj = new GameObject("CubemapCamera", typeof(Camera)); ownerObj.hideFlags = HideFlags.HideAndDontSave; ownerObj.transform.position = capturePos; ownerObj.transform.rotation = Quaternion.identity; Camera camComponent = ownerObj.GetComponent<Camera>(); camComponent.farClipPlane = 10000.0f; camComponent.enabled = false; Cubemap cubemap = new Cubemap((int)cubemapSize, TextureFormat.RGB24, false); camComponent.RenderToCubemap(cubemap, 63); SaveCubemapCapture(cubemap, pathName); DestroyImmediate(cubemap); DestroyImmediate(ownerObj); }