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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Silver7 · May 23, 2014 at 11:41 AM · texturetilingresizingadjust

Change material tiling according to loaded texture size in CS

Hi, I have a project in unity4, where U can browse your computer and upload an image from it into a model in runtime. I´m using UniFileBrowser in cs. The problem is when the uploaded image does not match 1x1 aspect ratio it gets distorted because of tiling. I can let the user change it manually with sliders or input fields but since they use it mostly on fair presentations - it shold be less fuss / more action. It seems so basic - but i just can´t get my head around it. Thanks in advance. void OpenFile (string pathToFile) { var Tagged_1 = GameObject.FindWithTag("kuubik");

         var fileIndex = pathToFile.LastIndexOf (pathChar);
         message = "You selected file: " + pathToFile.Substring (fileIndex+1, pathToFile.Length-fileIndex-1);
         Fade();
         string[] filePaths = Directory.GetFiles(@"" + pathToFile);
         WWW www = new WWW("file://" + filePaths[0]);
         Texture2D new_texture = new Texture2D(512,512);            
         www.LoadImageIntoTexture(new_texture);                         
         Tagged_1.renderer.material.mainTexture = new_texture;
 
     }
Comment
Add comment · Show 2
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 robertbu · May 26, 2014 at 02:46 PM 0
Share

Why are you using a new_texture rather than just use www.texture?

As for material tiling, you can set the material scale according to the aspect ratio of the texture;

 Textur2D tex = www.texture;
 Tagged_1.renderer.material.mainTexture = tex;
 Tagged_1.renderer.material.mainTextureScale = new Vector2(1, tex.height / tex.width);
avatar image Silver7 · May 27, 2014 at 08:48 AM 0
Share

Hi, thanks for Your reply. For whatever reason - when i use www.texture, the material seems faded but using new_texture gives more precise result of the texture used (picture attached right sided used www.texture). Another thing is - (1, tex.height / tex.width) gives "1,0" as a result. But when i use (tex.height, tex.width) the numbers are accurate (image height pixels, image witdth pixels).

test.jpg (25.9 kB)

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

20 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Same material, different meshes, different tiling 2 Answers

Effects Of Tiling Textures 1 Answer

Texture Tiling Stopped Working in Unity 4? 2 Answers

How would you texture a road 2 Answers

Question about draw distance and texture tiling 2 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