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 /
  • Help Room /
avatar image
0
Question by nyetram · Nov 24, 2016 at 09:20 PM · texturemesh

Material is not stretching on Meshes

I used this script to draw some polygons: http://wiki.unity3d.com/index.php?title=Triangulator

I changed this part, to set the base texture coordinates of the mesh:

 // Create the Vector3 vertices
 Vector3[] vertices = new Vector3[vertices2D.Length];
 Vector2[] uvs = new Vector2[vertices2D.Length];
 for (int i = 0; i < vertices.Length; i++)
 {
     vertices[i] = new Vector3(vertices2D[i].x, vertices2D[i].y, 0);
     uvs[i] = new Vector2(vertices2D[i].x, vertices2D[i].y);
 }
 msh.uv = uvs;

Now I set a material to the created GameObject, like this: polygonObject.GetComponent().material = blueMaterial;

The material of the GameObject has changed, but it now consists of thousands of small pictures of the desired one: alt text

The picture isn't a small one (1600x1200). The size of the picture in the background is like (2600x1600). So there is clearly something wrong. How can I get this fixed, so the material of the GameObject fits the picture?

wood.jpg (159.1 kB)
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

1 Reply

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

Answer by hexagonius · Nov 24, 2016 at 09:58 PM

Little rundown on UVs. for a mesh to know what to display it has normalized information about where to read pixels on a texture. since the size can be any size, some smart people thought that could be normalized. That means a value of 0,0 is the lower left of a texture and 1,1 is the upper right of a texture no matter the size.
what you need to do is apply values between 0 to 1. larger values just repeat the texture as you can see.

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 nyetram · Nov 25, 2016 at 09:32 AM 0
Share

Thanks! I have written this method and it works now:

 private Vector2[] sort(Vector2[] vertices2D)
         {
             float highestX = vertices2D[0].x;
             float highestY = vertices2D[0].y;
             float lowestX = vertices2D[0].x;
             float lowestY = vertices2D[0].y;
 
             for (int i = 0; i < vertices2D.Length; i++)
             {
 
                 float x = vertices2D[i].x;
                 float y = vertices2D[i].y;
 
                 if (x > highestX) {
                     highestX = x;
                 }
 
                 if (x < lowestX)
                 {
                     lowestX = x;
                 }
 
                 if (y > highestY)
                 {
                     highestY = y;
                 }
 
                 if (y < lowestY)
                 {
                     lowestY = y;
                 }
             }
 
             Vector2[] uvs = new Vector2[vertices2D.Length];
 
             float diffX = highestX - lowestX;
             float diffY = highestY - lowestY;
 
             for (int i = 0; i < uvs.Length; i++)
             {
                 uvs[i] = new Vector2(1/ diffX*(vertices2D[i].x-lowestX), 1 / diffY * (vertices2D[i].y-lowestY));
             }
 
             return uvs;
         }

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

94 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 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 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 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 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

How to add roughness to a mesh collider ? 0 Answers

How to partially change texture? 0 Answers

How to create a mesh for 2D maps with transparent parts, which is generated by software? 0 Answers

2 Models 1 Cracked How to make both look the same? (Material Problems) 1 Answer

Automatically assign hundred of textures to .obj file 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