Skip to content

Instantly share code, notes, and snippets.

@robinkruyt
Created March 12, 2015 10:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save robinkruyt/55701f2129f203a473e3 to your computer and use it in GitHub Desktop.
Save robinkruyt/55701f2129f203a473e3 to your computer and use it in GitHub Desktop.
Panorama tools.
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 () {
}
}
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!");
}
}
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