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 stulleman · Mar 13, 2015 at 01:48 PM · texturebuguv

Unity 5 uv bug?

EDIT: Don't blame me for the bad coding, it's just for testing purposes :P

So I've tried to solve this on my own but I've had no luck so far.
And since no one else seems to have this issue, I doubt it's a bug.

What I'm simply doing is build a mesh from script and apply a texture to it. I've done that many times before.

The problem now is that I have always 6 triangles in my mesh that are completely black. And they are always at world position 0,0,0.

Even if I move my mesh, the black triangles stay at 0,0,0.

The meshes origin is always at 0,0,0. I just change the the vertices position to move the mesh.

I've tried a custom and the standard shader. Same effect on both.

If someone wants to see the script. The relevant code should be in BuildMesh().

 using UnityEngine;
 using System.Collections.Generic;
 
 public class TerrainLayer : MonoBehaviour {
 
     public static int TERRAIN_WIDTH = 16;
     public static int TERRAIN_HEIGHT = 9;
 
     public Vector3 position;
 
     private byte[] terrainData;
     private Mesh mesh;
 
     public bool rebuildMesh;
 
     private float textureUnit = 0.0625f;
     private float textureMargin = 0.0001f;
     private List<Vector3> vertices;
     private List<int> triangles;
     private List<Vector2> uvs;
 
     // public
 
     void Awake() {
 
         terrainData = new byte[TERRAIN_WIDTH * TERRAIN_HEIGHT];
         vertices = new List<Vector3>();
         triangles = new List<int>();
         uvs = new List<Vector2>();
 
     }
 
     void Start() {
 
         mesh = GetComponent<MeshFilter>().mesh;
     }
 
     void Update() {
 
         if(rebuildMesh) {
 
             BuildMesh();
 
             rebuildMesh = false;
         }
 
     }
 
     #region Getter and Setter
 
     public void setRebuildFlag() {
         rebuildMesh = true;
     }
 
     public void setTerrainData(int x, int y, byte id) {
 
     }
 
     public byte getTerrainData(int x, int y) {
 
 
         return 0;
     }
 
     #endregion
 
     // private
 
     private void BuildMesh() {
 
         vertices.Clear();
         triangles.Clear();
         uvs.Clear();
 
         int quadCount = 0;
 
         Vector2 texture = new Vector2(0, 30);
 
         for(int x = (int)position.x - (TERRAIN_WIDTH / 2); x < position.x + (TERRAIN_WIDTH / 2); x++) {
             for(int y = (int)position.y - (TERRAIN_HEIGHT / 2); y < position.y + (TERRAIN_HEIGHT / 2); y++) {
 
                 vertices.Add(new Vector3(x, y + 1));
                 vertices.Add(new Vector3(x + 1, y + 1));
                 vertices.Add(new Vector3(x + 1, y));
                 vertices.Add(new Vector3(x, y));
 
                 triangles.Add(quadCount * 4);
                 triangles.Add((quadCount * 4) + 1);
                 triangles.Add((quadCount * 4) + 3);
                 triangles.Add((quadCount * 4) + 1);
                 triangles.Add((quadCount * 4) + 2);
                 triangles.Add((quadCount * 4) + 3);
 
                 uvs.Add(new Vector2(textureUnit * texture.x + textureMargin, textureUnit * texture.y + textureUnit - textureMargin));
                 uvs.Add(new Vector2(textureUnit * texture.x + textureUnit - textureMargin, textureUnit * texture.y + textureUnit - textureMargin));
                 uvs.Add(new Vector2(textureUnit * texture.x + textureUnit - textureMargin, textureUnit * texture.y + textureMargin));
                 uvs.Add(new Vector2(textureUnit * texture.x + textureMargin, textureUnit * texture.y + textureMargin));
 
                 quadCount++;
             }
         }
 
         mesh.vertices = vertices.ToArray();
         mesh.triangles = triangles.ToArray();
         mesh.uv = uvs.ToArray();
     }
 }
 

500.png (228.5 kB)
000.png (252.5 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 stulleman · Mar 13, 2015 at 02:10 PM

I kind of feel stupid now. I forgot to recalculate the normals of the mesh.

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

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

Assigning UV Map to model at runtime 0 Answers

Get a UV texture of a models surface 2 Answers

UV's are shrinking when zoomed out? 1 Answer

3D Text Mesh : Font Texture change to a Blank (Black) On Project Save 1 Answer

UV Problems When Model Imported Into Unity 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