Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 iko79 · Mar 22, 2019 at 11:28 AM · meshlinerendererline drawing

How to create a Mesh made up of lines, not triangles

Is there any way to draw a Mesh without having triangles but lines (or points) instead? Do I really need to take the detour of a geometry shader? I am trying to draw a complex, constantly updating graph and I'm trying this the way I would if I had to solve this in OpenGL: by drawing a horizontal straight line with the number of vertices I need and then doing the vertical displacement in the vertex shader by looking up the y-axis from a 1D texture.

I already tried using a LineRenderer, but the result looks awful, as the thickness varies, depending on the steepness of the graph segment.

I tried creating a Mesh object in code, but realized they only expose methods/properties related to triangles.

As a workaround I'm currently drawing the line in OnRenderObject with GL.Vertex using a GL.LINE_STRIP (with seems a quite bad idea to me, but at least it does he job for the time being). Only issue is that now this graph for some reason now shows up in every camera, regardless of the culling mask I use.

So now I'm back to square one, seems to be a big deal in Unity. Is there a way of creating a Mesh object just made of lines? This would save me from quite some headache. Much appreciated!

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Bunny83 · Mar 22, 2019 at 11:50 AM

Unity does support other mesh topologies for quite some time now. Just use Mesh.SetIndices instead of SetTriangles or triangles. See MeshTopology for more details.

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 iko79 · Mar 22, 2019 at 12:32 PM 0
Share

Exactly what I was looking for, totally missed that, thanks!

avatar image
0

Answer by juelzsantana123 · Apr 29, 2021 at 01:17 PM

 using UnityEngine;
 using System.Collections.Generic;
 
 [RequireComponent(typeof(MeshRenderer))]
 [RequireComponent(typeof(MeshFilter))]
 public class GridMesh : MonoBehaviour
 {
     public int xSize = 4;
     public int ySize = 3;
 
     [ColorUsage(true, true)]
     public Color color = Color.red;
     public Material material;
     private void CreateGrid()
     {
         xSize = Mathf.Abs(xSize);
         ySize = Mathf.Abs(ySize);
         MeshFilter filter = gameObject.GetComponent<MeshFilter>();
         var mesh = new Mesh();
         var verticies = new List<Vector3>();
 
         var indicies = new List<int>();
         int indc = 0;
         for (int i = 0; i <= xSize; i++)
         {
             verticies.Add(new Vector3(i, 0, 0));
             verticies.Add(new Vector3(i, 0, ySize));
             indicies.Add(indc++);
             indicies.Add(indc++);
         }
         for (int j = 0; j <= ySize; j++)
         {
             verticies.Add(new Vector3(0, 0, j));
             verticies.Add(new Vector3(xSize, 0, j));
             indicies.Add(indc++);
             indicies.Add(indc++);
         }
 
         mesh.vertices = verticies.ToArray();
         mesh.SetIndices(indicies.ToArray(), MeshTopology.Lines, 0);
         filter.mesh = mesh;
 
         MeshRenderer meshRenderer = gameObject.GetComponent<MeshRenderer>();
         meshRenderer.sharedMaterial = material;
         meshRenderer.sharedMaterial.color = color;
     }
 
     private void OnValidate()
     {
         Mesh mesh = gameObject.GetComponent<MeshFilter>().sharedMesh;
         if(mesh != null)
             DestroyImmediate(mesh);
         CreateGrid();
     }
 }
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

115 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

Related Questions

Creating a mesh out of a linerenderer - how do you convert revolved vertices set to triangles and uv's 1 Answer

LineRenderer with nontrivial radius? 1 Answer

SetTriangleStrip to SetTriangles 1 Answer

Recalculate linerenderer when moving gameobjects 1 Answer

How to make dotted line for Bubble game? 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