Created
March 12, 2015 10:33
-
-
Save robinkruyt/55701f2129f203a473e3 to your computer and use it in GitHub Desktop.
Panorama tools.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class CreatePanorama : MonoBehaviour { | |
public string captureName; | |
private float stepSize = 20; | |
// Use this for initialization | |
IEnumerator Start () { | |
int counter = 0; | |
for (float y = -90; y <= 90; y+=stepSize) { | |
for (float x = 0; x <= 360; x+=stepSize) { | |
transform.localEulerAngles = new Vector3(y, x, 0.0f); | |
Application.CaptureScreenshot("screenshots/"+captureName + "/screenshot-" + counter++ + "-" + x + "-" + y + ".png", 1); | |
yield return new WaitForSeconds(0.05f); | |
} | |
} | |
} | |
// Update is called once per frame | |
void Update () { | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEditor; | |
using System.Collections; | |
public class RenderCubemapWizard : ScriptableWizard { | |
public Transform renderFromPosition; | |
public Cubemap cubemap; | |
void OnWizardUpdate () { | |
string helpString = "Select transform to render from and cubemap to render into"; | |
bool isValid = (renderFromPosition != null) && (cubemap != null); | |
} | |
void OnWizardCreate () { | |
// create temporary camera for rendering | |
GameObject go = new GameObject( "CubemapCamera"); | |
go.AddComponent<Camera>(); | |
// place it on the object | |
go.transform.position = renderFromPosition.position; | |
go.transform.rotation = Quaternion.identity; | |
// render into cubemap | |
go.GetComponent<Camera>().RenderToCubemap( cubemap ); | |
// destroy temporary camera | |
DestroyImmediate( go ); | |
} | |
[MenuItem("GameObject/Render into Cubemap")] | |
static void RenderCubemap () { | |
ScriptableWizard.DisplayWizard<RenderCubemapWizard>( | |
"Render cubemap", "Render!"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import System; | |
import System.IO; | |
class SaveCubemapToPngWizard extends ScriptableWizard { | |
var cubemap : Cubemap; | |
function OnWizardUpdate () { | |
helpString = "Select cubemap to save to individual png"; | |
isValid = (cubemap != null); | |
} | |
function OnWizardCreate () | |
{ | |
var width = cubemap.width; | |
var height = cubemap.height; | |
Debug.Log(Application.dataPath + "/" +cubemap.name +"_PositiveX.png"); | |
var tex = new Texture2D (width, height, TextureFormat.RGB24, false); | |
// Read screen contents into the texture | |
tex.SetPixels(cubemap.GetPixels(CubemapFace.PositiveX)); | |
// Encode texture into PNG | |
var bytes = tex.EncodeToPNG(); | |
File.WriteAllBytes(Application.dataPath + "/" + cubemap.name +"_PositiveX.png", bytes); | |
tex.SetPixels(cubemap.GetPixels(CubemapFace.NegativeX)); | |
bytes = tex.EncodeToPNG(); | |
File.WriteAllBytes(Application.dataPath + "/" + cubemap.name +"_NegativeX.png", bytes); | |
tex.SetPixels(cubemap.GetPixels(CubemapFace.PositiveY)); | |
bytes = tex.EncodeToPNG(); | |
File.WriteAllBytes(Application.dataPath + "/" + cubemap.name +"_PositiveY.png", bytes); | |
tex.SetPixels(cubemap.GetPixels(CubemapFace.NegativeY)); | |
bytes = tex.EncodeToPNG(); | |
File.WriteAllBytes(Application.dataPath + "/" + cubemap.name +"_NegativeY.png", bytes); | |
tex.SetPixels(cubemap.GetPixels(CubemapFace.PositiveZ)); | |
bytes = tex.EncodeToPNG(); | |
File.WriteAllBytes(Application.dataPath + "/" + cubemap.name +"_PositiveZ.png", bytes); | |
tex.SetPixels(cubemap.GetPixels(CubemapFace.NegativeZ)); | |
bytes = tex.EncodeToPNG(); | |
File.WriteAllBytes(Application.dataPath + "/" + cubemap.name +"_NegativeZ.png", bytes); | |
DestroyImmediate(tex); | |
} | |
@MenuItem("GameObject/Save CubeMap To Png ") | |
static function SaveCubemapToPng () | |
{ | |
ScriptableWizard.DisplayWizard( | |
"Save CubeMap To Png", SaveCubemapToPngWizard , "Save"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment