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 vargaendre · May 07, 2012 at 02:19 PM · texturemeshmeshfilter

Blured texture of custom mesh

Hi all!

When I create a mesh with the MeshFilter, The triangles look fine, but the texture is blured, doesn't really look like it should. I inspected the created mesh, the correct material is assigned. I tried just to use the original prefab's texture, and even assign a new texture to the MeshRenderer (from code and from Editor in runtime as well), but the results are the same.

One weird thing is, when I debug the code and inspect the mesh object, its uv array is empty, even after I assigned a valid array to it.

 public void drawMesh(Vector3[] vertices
                     , int[] indices
                     , Vector2[] uvs
                     , Texture2D tex
                     , GameObject obj)
 {
     
     Mesh mesh = new Mesh();
     obj.GetComponent<MeshFilter>().mesh = mesh;
     
     mesh.Clear();
     obj.GetComponent<MeshRenderer>().material.mainTexture=tex;
     mesh.vertices = vertices;
     mesh.triangles = indices; 
     mesh.uv=uvs;
     
     mesh.RecalculateNormals();
     mesh.RecalculateBounds();
     mesh.Optimize();
 }



These are the indices and UVs:

 int[] indices = new int[]{
                   0, 1, 2
                 , 2, 1, 3};
     
     Vector2 uv0 = new Vector2(0,0);
     Vector2 uv1 = new Vector2(1,0);
     Vector2 uv2 = new Vector2(0,1);
     Vector2 uv3 = new Vector2(1,1);
         
     Vector2[] uvs = new Vector2[]{
           uv2, uv3, uv0
         , uv0, uv3, uv1
     };

A picture about this:

http://kepfeltoltes.hu/120507/asphalt_incorrect_texture_www.kepfeltoltes.hu_.png

Any help appreciated!

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 Bunny83 · May 07, 2012 at 02:22 PM 0
Share

You should assign the triangles after the uvs. First setup the vertex data, then the triangles. However without a screenshot or the actual vertex / uv data we can just guess what's wrong.

avatar image vargaendre · May 07, 2012 at 02:54 PM 0
Share

Thanks! Unfortunately, putting the trianlges after the uvs didn't solve the problem. I added a link to a picture.

avatar image Owen-Reynolds · May 07, 2012 at 03:49 PM 0
Share

An empty uv array would probably cause exactly what you're seeing. If likely guesses all the UV coords are (0,0), which duplicates the lower-left pixel on everything (I usually try a texture with many colors to see if that's the case.)

I'm guessing the UV array is bad somehow (wrong length?...) and ins$$anonymous$$d of an error, it just gets ignored.

avatar image vargaendre · May 07, 2012 at 03:56 PM 0
Share

I think you are right about the uvs being ignored, because after assigning my values, the uv of the mesh is still an empty array. I updated the question with the uvs. Actually, I don't know what's the problem with them. Thanks!

1 Reply

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

Answer by Owen-Reynolds · May 08, 2012 at 01:13 AM

It looks like you have 4 verts (you assign tris using verts 0-3,) but have 6 uv coordinates. Should only have 4 (one per vert.)

Comment
Add comment · Show 2 · 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 Bunny83 · May 08, 2012 at 01:44 AM 0
Share

Yep, i guess that's the problem. Texture coords are per vertex, not per triangle index. If you need splitted uvs or normals (which you don't need in this case) you would have to duplicate the shared vertices.

The vertex data consists of those arrays: vertices, normals, tangents, uv, uv2, colors and boneWeights. The element count of all those arrays (as long as they are used) have to match the element count of the vertices array which have to be assigned first.

The triangles array should be assigned last. It just builds up the actual faces / triangles out of the vertices.

If you want to change any of the above properties for a single face, you need to duplicate the whole vertex.

For example the default box mesh usually have 8 vertices (one at each corner). But since you need a different vertex normal for each face to get correct lighting they have to use 24 vertices (4 vertices for each face)

avatar image vargaendre · May 08, 2012 at 07:38 AM 0
Share

Hey! Thanks a lot! In the meamtime I figured it out that it is the problem, but thank you though!

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

6 People are following this question.

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

Related Questions

"Baking" to 2d UV Map? 1 Answer

running a texture across multiple objects/meshes? 1 Answer

Getting the world position of mesh vertices? 2 Answers

Animating a texture on an FBX import from Maya 0 Answers

Combine multiple mesh entities to be exported as obj 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