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 johannesneff · Jul 11, 2020 at 10:47 AM · meshscripting beginnerverticestrianglesuvs

Procedural Mesh : draw labels with triangles and uvs to display a image at specific vertices

Hi - c# beginner here - Im using a text file to generate the height in an array of vertices of an procedural mesh. Now I want to draw little labels at specific points (for example at each point which has a "T" Value) - these labels should be drawn with a new set of vertices (triangles) and uvs (for both sides) so you can see the picture on each side of the rect. How can I setup the new Vertice and triangle array + the uv mapping to achieve this? Little bit confusing right now

Heres my code so far:

using System.Collections; using System.Collections.Generic; using UnityEngine;

[RequireComponent(typeof(MeshFilter))] public class TMesh01 : MonoBehaviour {

 Mesh mesh;

 Vector3[] vertices;
 int[] triangles;

 public Material Tshader;
 public int xSize = 10;
 public int zSize = 10;
 
 TextAsset textFile;

 // public float scale = 20f;

 // Start is called before the first frame update

 

 public void start()
 {
    
     Debug.Log("Resources.Load: "); 
     Debug.Log(fileName);
     textFile = Resources.Load<TextAsset>("text"); 
     Debug.Log(textFile.text);
     mesh = new Mesh();

     GetComponent<MeshFilter>().mesh = mesh;
     CreateShape();
     UpdateMesh();

 }

 void CreateShape()

 {
     Mesh mesh = GetComponent<MeshFilter>().mesh;

     string basen = textFile.text;
  
     zSize = 32;
     xSize = Mathf.CeilToInt(basen.Length / 32f);
     vertices = new Vector3[(xSize + 2) * (zSize + 2)];


     
     int valueA = 1;
     int valueC = 1;
     int valueG = 1;
     int valueT = 1;

     var CubeColor = Color.gray;
     int lastCharValue = 0;

     for (int x = 0; x < xSize + 2; x++)
     {
         for (int z = 0; z < zSize + 2; z++)
         {
             float y = 0;
             int index = x * (zSize + 2) + z;
             int basenIndex = (x - 1) * zSize + (z - 1);

             if (x > 0 && x < xSize + 2 && z > 0 && z < zSize + 1 && basenIndex < basen.Length)
             {
                 
                 char c = basen[basenIndex];
                 char lastChar = 'A';

                 if (basenIndex > 0) { lastChar = basen[basenIndex - 1]; }

                 if (c == 'A' && lastChar == 'A')
                 {
                     lastCharValue += valueA;
                 }
                 else if (c == 'C' && lastChar == 'C')
                 {
                     lastCharValue += valueC;
                 }
                 else if (c == 'G' && lastChar == 'G')
                 {
                     lastCharValue += valueG;
                 }
                 else if (c == 'T' && lastChar == 'T')
                 {
                     lastCharValue += valueT;
                 }
                 else
                 {
                     lastCharValue = 0;
                 }    
                 y = lastCharValue;

                 }else{ //Debug.Log(x + " " + z);
             }   



              //int radius = zSize / 2;
              float winkel = ((x * 1.0f / xSize) * Mathf.PI * 2);
              float _z = Mathf.Cos((winkel)) * (z + 30);
              float _x = Mathf.Sin((winkel)) * (z + 30);
              vertices[index] = new Vector3(_x, y, _z);


             
              Vector3[] verticesT = new Vector3[];                 4 per label * 2 ?
              Vector2[] uvsT = new Vector2[verticesT.Length]; 
              triangles = new int[]; // 4 per label * 3 ?

               
                                   

              int index = (x * (zSize + 2) + z);

              verticesT[index]   = new Vector3(_x + 0.1f,   y,          _z);
              verticesT[index+1] = new Vector3(_x + 0.1f,   y + 0.2f,   _z);
              verticesT[index+2] = new Vector3(_x - 0.1f,   y + 0.2f,   _z);
              verticesT[index+3] = new Vector3(_x - 0.1f,   y,          _z);

              verticesT[index+4] = new Vector3(_x + 0.1f,   y,          _z);
              verticesT[index+5] = new Vector3(_x + 0.1f,   y + 0.2f,   _z);
              verticesT[index+6] = new Vector3(_x - 0.1f,   y + 0.2f,   _z);
              verticesT[index+7] = new Vector3(_x - 0.1f,   y,          _z);


              uvsT[index]   = new Vector2(1,0);
              uvsT[index+1] = new Vector2(1,1);
              uvsT[index+2] = new Vector2(0,1);
              uvsT[index+3] = new Vector2(0,0);

              uvsT[index+4] = new Vector2(1,0);
              uvsT[index+5] = new Vector2(1,1);
              uvsT[index+6] = new Vector2(0,1);
              uvsT[index+7] = new Vector2(0,0);

                                     
             //front
              triangles[index + 0] = 0;  //0
              triangles[index + 1] = 1;  //1
              triangles[index + 2] = 2;  //2

              triangles[index + 3] = 2;  //2
              triangles[index + 4] = 3;  //3
              triangles[index + 5] = 0;  //0

               // back
              triangles[index + 6] = 7;  //7
              triangles[index + 7] = 6;  //6
              triangles[index + 8] = 5;  //5

              triangles[index + 9]  = 5;  //5
              triangles[index + 10] = 4;  //4
              triangles[index + 11] = 7;  //7
                                     

         }

     }

 }

 void UpdateMesh()
 {

     mesh.Clear();
     mesh.vertices = vertices;
     mesh.triangles = triangles;
     mesh.RecalculateNormals();

 }

}

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

0 Replies

· Add your reply
  • Sort: 

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

154 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 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 make sure two meshes have the same vertex count 0 Answers

can 5 verts and 4 triangles be done on a square texture? 1 Answer

contains two different ids for the same vertex 0 Answers

Problem drawing a mesh with Graphics.DrawMeshNow 1 Answer

Highmap on a cube. 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