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 htsoft · Nov 18, 2012 at 11:19 AM · texturewwwmaterials

How to stretch a texture applied to a material

Hi,

I'm working on a simple viewer with WebPlayer that displays a texture, contained into a URL, on an specific material of a displayed object.

Actually the texture is loaded and displayed on the object into the correct material, but the texture is not resized properly and a small part of it is displayed, this is the code that I'm using:

 function loadTexture (url : String) {
     // Start a download of the given URL
     var www : WWW = new WWW (url);

     // Wait for download to complete
     yield www;

     // assign texture
     var texture : Texture2D = www.texture;
     texture.Compress(true);
     renderer.materials[0].mainTexture = texture; 
     renderer.materials[0].mainTextureScale = Vector2(1,1);
 }

The object has already a texture on the same material that is displayed properly.

Thanks in advance for your help.

Comment
Add comment · Show 4
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 Seth-Bergman · Nov 18, 2012 at 12:15 PM 0
Share

what kind of object?

avatar image htsoft · Nov 18, 2012 at 12:20 PM 0
Share

It's a mesh, originally an FBX object

avatar image Seth-Bergman · Nov 18, 2012 at 12:25 PM 0
Share

Right.. a mesh, as in something 3d, not just a simple plane, correct?

And the texture was not created for the object, correct?

avatar image htsoft · Nov 18, 2012 at 12:28 PM 0
Share

It's correct.

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Seth-Bergman · Nov 18, 2012 at 12:43 PM

Sounds like a mapping issue..

3D objects use a 3D coordinate system, we refer to as UVW. In order to add textures to them, we do something called UNWRAP it... Basically, we peel off pieces, flatten them, and arrange them into a square "tile", we call this a UV tile. The position of each vertex in the tile determines where the texture will map to..

In other words, you can't just add any texture to a 3d model, it actually would need to correspond to the model..

To give you an idea, here is a UV tile I have for a character in one of my projects:

alt text

EDIT: To stretch the texture, just say

renderer.material.mainTextureScale = Vector2(scaleX,scaleY);

http://docs.unity3d.com/Documentation/ScriptReference/Material-mainTextureScale.html

in your example, you are using (1,1) as the scale, which is where it starts at.. just lower the numbers, such as (.5,.5), to increase the size.. or raise them to decrease the size..


sweet_blue.png (95.2 kB)
Comment
Add comment · Show 5 · 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 htsoft · Nov 18, 2012 at 02:14 PM 0
Share

I know how UV coordinates works. But in this case the material is assegned to a simple rect. The texture must be simply stretched. There is a way to stretch it?

avatar image Seth-Bergman · Nov 18, 2012 at 02:40 PM 0
Share

see edit above

avatar image htsoft · Nov 18, 2012 at 02:44 PM 0
Share

Thank you Seth. But if you take some moment to see the code i've already posted, there's already the row that you've edited. It simply doesn't works. I will try some other way.

avatar image Seth-Bergman · Nov 18, 2012 at 02:48 PM 0
Share

YOUR LINE sets the scale to (1,1)

this is where it starts already

you need to use something else, such as (2,2)

avatar image htsoft · Nov 18, 2012 at 02:52 PM 0
Share

Uhm... I need to do a proportion before establish the scale, but it could works. I will try and let you know.

avatar image
0

Answer by htsoft · Nov 27, 2012 at 09:20 AM

I've found this solution:

1 - In Maya i've duplicated the polygon which will receive the texture and made an UV on it
2 - I've assigned a material to this polygon
3 - I've removed the original polygon and saved the mesh
4 - In Unity i've simply assigned a texture to the material and Unity made the correct work.

I've tried with a complex structure and it worked fine.

Thank you.

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 Maulik2208 · Nov 27, 2012 at 12:45 PM

 YOURGAMEOBJECTNAME.renderer.material.SetTextureOffset("_MainTex",offset);    
             YOURGAMEOBJECTNAME.renderer.material.SetTextureScale("_MainTex", _size);

HOPE THIS WILL WORK FOR YOU.......(<")

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

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

11 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

Related Questions

where to call wwwLoadImageIntoTexture 1 Answer

Error display when loading a 6000 x 3000 jpg by using WWW 0 Answers

Where is downloaded things from editor script being saved? 0 Answers

Textures are not tiling properly on my wall model! 3 Answers

Converting downloaded texture into PVRTC on iPhone 3 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