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 Martix10 · Sep 10, 2014 at 03:49 AM · rotationmeshrenderinguvs

Problem when creating UVs coordinates

Hi everyone, I'm trying to learn how to create a mesh form scratch. I Created a C# script that render a block, but i got stuck in this part. When I hit play the mesh is rendered good, but the texture has a wrong rotationalt text

Here the code:

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class CubeRender : MonoBehaviour {
 
 
 
     protected List<Vector3> verts = new List<Vector3> ();
     protected List<int> triangulos = new List<int> ();
     protected List<Vector2> uvs = new List<Vector2> ();
 
     private Mesh cubo;
 
 
     private float uText = 0.25f;
 
     void Start () 
     {
         cubo = GetComponent<MeshFilter> ().mesh;
 
         float x = transform.position.x;
         float z = transform.position.z;
         float y = transform.position.y;
 
         //Baixo
         CriarFace (new Vector3(x, y, z), Vector3.forward, Vector3.right, true);
 
         //Cima
         CriarFace (new Vector3(x, y + 1, z), Vector3.forward, Vector3.right, false);
 
         //Frente
         CriarFace (new Vector3(x, y, z + 1), Vector3.up, Vector3.right, true);
 
         //Tras
         CriarFace (new Vector3(x, y, z), Vector3.up, Vector3.right, false);
 
         //Esquerda
         CriarFace (new Vector3(x, y, z), Vector3.up, Vector3.forward, true);
 
         //Direita
         CriarFace (new Vector3(x + 1, y, z ), Vector3.up, Vector3.forward, false);
 
         cubo.Clear ();
         cubo.vertices = verts.ToArray ();
         cubo.triangles = triangulos.ToArray ();
         cubo.uv = uvs.ToArray ();
         cubo.Optimize ();
         cubo.RecalculateNormals ();
 
 
     }
     void CriarFace(Vector3  origem, Vector3 direita, Vector3 cima, bool revertido)
     {
         int index = verts.Count;
 
         verts.Add (origem);
         verts.Add (origem + direita);
         verts.Add (origem + cima);
         verts.Add (origem + direita + cima);
         
         if (invertido == true) {
             triangulos.Add (index + 1);
             triangulos.Add (index + 0);
             triangulos.Add (index + 2);
             triangulos.Add (index + 1);
             triangulos.Add (index + 2);
             triangulos.Add (index + 3);
         }else{
             triangulos.Add (index + 0);
             triangulos.Add (index + 1);
             triangulos.Add (index + 2);
             triangulos.Add (index + 2);
             triangulos.Add (index + 1);
             triangulos.Add (index + 3);
         }
 
         uvs.Add(new Vector2 (0, 0));
         uvs.Add(new Vector2 (uText, 0));
         uvs.Add(new Vector2 (0, uText));
         uvs.Add(new Vector2 (uText, uText));
 
 
 
     }
 
     void Update () 
     {
     
     }
 }

The rotation of top and bottom textures doesn't matter, but the sides are wrong, the green part should be on the top.
Anyone has any idea of how I can solve this ?

Sorry about the awful explanation, and the horrible english :s

block.png (36.6 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
1

Answer by zharik86 · Sep 10, 2014 at 06:17 AM

Simple way, this rotation of a texture on 90 degrees counterclockwise in any graphics editor. For example, in Photoshop. But it is possible to leave and so. But then it will be necessary to change textural coordinates. I change part of your code:

  void CriarFace(Vector3  origem, Vector3 direita, Vector3 cima, bool revertido) {
   int index = verts.Count;
 
   verts.Add (origem);
   verts.Add (origem + direita);
   verts.Add (origem + cima);
   verts.Add (origem + direita + cima);
 
   if (invertido == true) {
    triangulos.Add (index + 1);
    triangulos.Add (index + 0);
    triangulos.Add (index + 2);
    triangulos.Add (index + 1);
    triangulos.Add (index + 2);
    triangulos.Add (index + 3);
   }else{
    triangulos.Add (index + 0);
    triangulos.Add (index + 1);
    triangulos.Add (index + 2);
    triangulos.Add (index + 2);
    triangulos.Add (index + 1);
    triangulos.Add (index + 3);
   }
 
   //little change
   uvs.Add(new Vector2 (0, uText));
   uvs.Add(new Vector2 (0, 0));
   uvs.Add(new Vector2 (uText, uText));
   uvs.Add(new Vector2 (uText, 0));
  }

Or to change sequence of triangles. I hope that it willhelp you.

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 Martix10 · Sep 10, 2014 at 02:07 PM 0
Share

Nice it worked!Thank you!

avatar image zharik86 · Sep 10, 2014 at 06:44 PM 0
Share

@$$anonymous$$artix10 If I helped you, you can mark my answer. Possibility of a mark of the answer to be is slightly below than vote marks. And on the future if somebody helped you and he/she gave the correct answer, it is possible to mark it. The person tried, spent time.

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

2 People are following this question.

avatar image avatar image

Related Questions

Synchronising the rotation around Y axis of two objects 1 Answer

Changing mesh.uv works in editor, but not on Android 1 Answer

Rotation speed,Rotate script slows down 1 Answer

Use Unity's transform API to manipulate points? 0 Answers

Vertex Colours flickering blue 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