Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by alexandermenakhin · Aug 23, 2016 at 05:53 AM · wwwskyboxcubemaphttpwebrequestsetpixels

Download 6 textures from the web, create a cubemap and set it as skybox in runtime

In my app I need teh user to be able to download already prepared 360 photos, cut into 6 pieces. After that, the cubemap must be made, and loaded as a skybox, so that the user could explore 360 degrees photos on his mobile device.

I've been stuck here for almost a week, but nothing worked for different reasons, finally I've ended up with something that doesn't throw exceptions, but still it sets an emty gray skybox in the end.

Option 1: HttpWebRespone

     public Material second;
 private Cubemap c; 
     public void SetSkybox()
         {
     c = new Cubemap (1024, TextureFormat.RGB24, false);
     PhotoRequest("front", CubemapFace.PositiveZ);
     PhotoRequest ("back", CubemapFace.NegativeZ);
     PhotoRequest ("top", CubemapFace.PositiveY);
     PhotoRequest ("bottom", CubemapFace.NegativeY);
     PhotoRequest ("right", CubemapFace.PositiveX);
     PhotoRequest ("left", CubemapFace.NegativeX);

     c.Apply ();
     Material mat = new Material (second);
     mat.SetTexture ("_Cube", c);
     RenderSettings.skybox = mat;
 }

     private void PhotoRequest(string filename, CubemapFace cmf)
 {
     ServicePointManager.ServerCertificateValidationCallback = SkyboxAuthentication.Validator; // I know, it's bad
     string url = {path to the webfolder with the photos};
     string completeURL = url + filename;
     var request = (HttpWebRequest)WebRequest.Create (completeURL);
     var response = (HttpWebResponse)request.GetResponse ();
     Stream dataStream = response.GetResponseStream ();
     BinaryReader reader = new BinaryReader (dataStream);
     byte[] responseFromServer = ReadAllBytes(reader);
     Texture2D tex = new Texture2D (1920, 1920);
     tex.LoadImage (responseFromServer);
     Color[] colors = tex.GetPixels ();
     c.SetPixels (colors, cmf);
     reader.Close ();
     response.Close ();
 }

 byte[] ReadAllBytes(BinaryReader rdr)
 {
     const int bufferSize = 1024;
     using (var ms = new MemoryStream()) {
         byte[] buffer = new byte[bufferSize];
         int count;
         while ((count = rdr.Read (buffer, 0, buffer.Length)) != 0) {
             ms.Write (buffer, 0, count);
         }
         return ms.ToArray ();
     }
 }

Option 2: WWW

     bool front = false;
     bool back = false;
     bool top = false;
     bool bottom = false;
     bool right = false;
     bool left = false;
 public void SecondSkybox()
     {
         c = new Cubemap (1024, TextureFormat.RGB24, false);
         StartCoroutine(PhotoRequest ("front", CubemapFace.PositiveZ));
         StartCoroutine(PhotoRequest ("back", CubemapFace.NegativeZ));
         StartCoroutine(PhotoRequest ("top", CubemapFace.PositiveY));
         StartCoroutine(PhotoRequest ("bottom", CubemapFace.NegativeY));
         StartCoroutine(PhotoRequest ("right", CubemapFace.PositiveX));
         StartCoroutine(PhotoRequest ("left", CubemapFace.NegativeX));
         StartCoroutine (DoLast ());
 
         c.Apply ();
         Material mat = new Material (second);
         mat.SetTexture ("_Cube", c);
         RenderSettings.skybox = mat;
     }

 private IEnumerator PhotoRequest(string filename, CubemapFace cmf)
     {
         switch (filename) {
         case "front":
             front = true;
             break;
         case "back":
             back = true;
             break;
         case "top":
             top = true;
             break;
         case "bottom":
             bottom = true;
             break;
         case "right":
             right = true;
             break;
         case "left":
             left = true;
             break;
         }
 
         string url = {path to the webfolder with the photos};
         WWW www = new WWW (url + filename);
         yield return www;
         Debug.Log (www.responseHeaders["STATUS"].ToString());
         Color[] colors = www.texture.GetPixels();
         c.SetPixels (colors, cmf);
 
         switch (filename) {
         case "front":
             front = false;
             break;
         case "back":
             back = false;
             break;
         case "top":
             top = false;
             break;
         case "bottom":
             bottom = false;
             break;
         case "right":
             right = false;
             break;
         case "left":
             left = false;
             break;
         }
     }
 
     private IEnumerator DoLast()
     {
         while (front || back || top || bottom || right || left) {
             yield return new WaitForSeconds (0.1f);
         }
     }



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

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

HttpWebRequest No longer working? 0 Answers

360 Photo as Skybox: Sprite 2D VS Cubemap? in Oculus Go 0 Answers

Cubemap Projection Shader 0 Answers

Exporting Cubemap in different mapping layouts? 0 Answers

how to make Panorama hotspot creation between 2 panorama? 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