Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by burnumd · Dec 18, 2009 at 08:08 PM · cameratexture

How can I extract the individual faces from a generated cubemap?

We've generated a cubemap using the editor script sample found in the Camera.RenderToCubemap documentation. We'd like to edit the faces by hand but can't find a way to access the individual face textures that make up the Cubemap texture. Is it possible to do so? If so, how?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

7 Replies

· Add your reply
  • Sort: 
avatar image
8
Best Answer

Answer by Nawash · Sep 21, 2010 at 04:50 AM

In case somebody needs this, here is how to extract all the faces in png format, in the asset folder. Copy this script in an "editor" folder in a project "asset" folder

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"); }

}

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image eVRydayVR · May 14, 2015 at 04:02 AM 2
Share

Simplified version of above code:

 var tex = new Texture2D (cubemap.width, cubemap.height, TextureFormat.RGB24, false);
 CubemapFace[] faces = new CubemapFace[] {
     CubemapFace.PositiveX, CubemapFace.NegativeX,
     CubemapFace.PositiveY, CubemapFace.NegativeY,
     CubemapFace.PositiveZ, CubemapFace.NegativeZ };
 foreach (CubemapFace face in faces) {
     tex.SetPixels(cubemap.GetPixels(face));        
     File.WriteAllBytes(Application.dataPath + "/" + cubemap.name + "_" + face.ToString() + ".png",
                        tex.EncodeToPNG());
 }   
avatar image
2
Best Answer

Answer by Ashkan_gc · Dec 18, 2009 at 08:20 PM

take a look at cubemap class and it's setpixels method here you can get pixels with these methods and set them on a Texture2D or do any other thing that you want with it.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by ameierinco · Oct 24, 2012 at 07:49 PM

Finally got this working. The above code didn't work for me. Appears the problem is with the first line "import http://System.IO;". I'm not much of a coder, but this had to be wrong since any "//" automatically comments out anything that follows it. Anyway, here's the full script that worked for me. Hope it helps someone.

 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");
 }
 }
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image OutCyder · Jun 02, 2013 at 12:57 PM 0
Share

I downloaded this script as well, thank you very much, man :)

avatar image
0

Answer by MS-3D · Dec 21, 2011 at 06:20 AM

Many thanks for the script !

But some noobs (including me) have problems with this "not so good" documentation. I try to complete the docu:

  1. Greate a Javascript with the name "SaveCubeMapToPngWizard" in a Editor folder in Assets (how described above).

  2. Copy the script, but including the first lines "import....", "class SaveCube..." and the brace at the end of the script (in the green area).

  3. The first line should be: "import System.IO;" and NOT "import http://System.IO;"

I hope it helps someone !

Regards - MS

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by JunkyardSam · May 11, 2012 at 08:13 PM

On #3, MS-3D meant to say: "import System.IO;" and NOT "import http://System.IO;"

To be clear, the first line should be: import System.IO

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
  • 1
  • 2
  • ›

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

I'm trying to get a picture in game and display it on a plane 2 Answers

How to make the Health bar on Enemys head not be in relation to Player(main) Camera? 2 Answers

Assigning UV Map to model at runtime 0 Answers

Free-look camera y-rotation shake 2 Answers

OpenGLES error 0x0502 when TextureFormat.BGRA32 is used 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges