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
0
Question by Opak · Jun 21, 2013 at 09:07 PM · texturesplitsetpixelsgetpixelsloadimageintotexture

LoadImageIntoTexture + GetPixels + SetPixels

Hi,

I am trying to load an image into a texture, split it up in 3x 1/3 parts and assign these 1/3 parts to three different walls. The problem is that it doesn't assign the downloaded texture to the walls at all and I don't know what I did wrong.

Here's the code:

 var texture : Texture;
 var sourceRect : Rect;
 var url = "http://www10.pic-upload.de/28.05.13/d8f3w59xp643.jpg";
 var wallL : GameObject;
 var wallR : GameObject;
 var wallT : GameObject;
 var EnterName: String = "Enter A Name";
 var showBox : boolean = true;    
     
 function Start () {
     wallL = GameObject.Find("WallL");
       wallR = GameObject.Find("WallR");
      wallT = GameObject.Find("WallT");
 }
 
 function Update () {
  
 }
 
 function OnGUI () {
 if (showBox == true) {
     Submit = GUI.Button(Rect(Screen.width/2+5, Screen.height/2+25, 165, 25), "Finished");
     EnterName = GUI.TextField(Rect(Screen.width/2, Screen.height/2, 175, 60), EnterName);
     if (Submit){
         url = EnterName;
         textureLoad();
         }
     }
 }
 
 function textureLoad () {
         texture = new Texture2D(1024, 512, TextureFormat.DXT1, false);
         // Start a download of the given URL
         var www = new WWW(url);
         // wait until the download is done
         yield www;
         // assign the downloaded image to the main texture of the object
         www.LoadImageIntoTexture(texture);
 
         // The values in the Rect structure are floats, so round them
         // down to the nearest integer.
         var x = Mathf.FloorToInt(sourceRect.x);
         var y = Mathf.FloorToInt(sourceRect.y);
         var width = Mathf.FloorToInt(sourceRect.width);
         var height = Mathf.FloorToInt(sourceRect.height);
         
         // Get the pixel block and place it into a new texture.
         var pix = texture.GetPixels(x, y, width, height);
         var destTex = new Texture2D(width, height);
         destTex.SetPixels(pix);
         // Set the current object's texture to show the
         // extracted rectangle.
         renderer.material.mainTexture = destTex;
 }

When I do it seperatly, like the LoadImage part only, then this part works fine. It's the same case with the GetPixels and SetPixels. When I use a texture that is already included in Unity, then the split part works fine as well. But when I combine the LoadImage and Get/SetPixels then it just doesn't apply the texture.

PS: I have only a basic setup with three walls and I'm trying to do it with this texture. The points 'x', 'y', 'width' and 'height' are predefined for every wall (e.g. 0, 0, 1024, 170 and 0, 170, 1024, 170 ...).

Thanks in advance for every answer, Opak

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

14 People are following this question.

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

Related Questions

Reset a Texture After GetPixels/SetPixels 0 Answers

Setting pixels on a texture? 2 Answers

Draw one texture on to another? Get Set Pixels. 0 Answers

Merging Textures At Runtime - Not Correct? 1 Answer

How do I set pixels with WebCamTexture.GetPixels 1 Answer


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