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 Hellojeska · Nov 13, 2020 at 12:03 PM · verticesedgeouter

How to Find Edge Vertices of a 2D mesh,How to Find Edge Vertices of a 2D mesh

I want to only Red point please help me,alt text

question.png (15.9 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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Nov 14, 2020 at 12:11 PM

I've posted an answer to a similar question over here. Does that help? Keep in mind this approach does only work when you have shared vertices all across the mesh. So any UV seam is considered an outer edge as well.

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
avatar image
0

Answer by Llama_w_2Ls · Nov 14, 2020 at 12:54 PM

Ive done lots of 3D mesh problems like this in WPF so let me take a crack.

First, if you had an array of the points/vertices, alongside the triangle indicies, you can create a list of edges like this: (pseudocode warning..)

     public class MainClass
     {
         private void GetEdges()
         {
             Point[] points = mesh.Points; // The mesh's vertices
             int[] indicies = mesh.TriangleIndices; // The mesh's triangle indicies
 
             List<Edge> edges = new List<Edge>();
 
             // for every two triangle indicies
             for (int i = 0; i < indicies.Length; i++)
             {
                 // if point a != point b (meaning there is an edge)
                 if (points[indicies[i]] != points[indicies[i + 1]])
                 {
                     // Create a new edge with the corresponding points
                     // and add it to edge list
                     Edge edge = new Edge(points[indicies[i]], points[indicies[i + 1]]);
                     edges.Add(edge);
                 }
 
             }
         }
     }
 
     public class Edge
     {
         public Point A;
         public Point B;
 
         public Edge(Point a, Point b)
         {
             A = a;
             B = b;
         }
 
         // Creates an object that represents
         // a line from A to B (an edge)
     }

With the edges, knowing that you only want the edges which dont go diagonally into the mesh, you can do a basic check with the points of each edge to check that the x or y of both points in the edge are the same, meaning it isn't slanted, but rather straight, either on the x-axis or y-axis. For example:

         private void GetStraightEdges(List<Edge> edges)
         {
             List<Edge> straightEdges = new List<Edge>();
 
             foreach (Edge edge in edges)
             {
                 if (edge.A.X == edge.B.X ||
                     edge.A.Y == edge.B.Y)
                 {
                     // edge is straight and not diagonal
                     straightEdges.Add(edge);
                 }
                 else
                 {
                     // edge is diagonal and can be discarded
                 }
             }
         }

Finally, you wish to only find the red points on each straight edge, so you can simply create a new point array containing those points (as you already have the right edges for the job)

         private List<Point> GetPoints(List<Edge> straightEdges)
         {
             List<Point> Points = new List<Point>();
 
             foreach (Edge edge in straightEdges)
             {
                 Points.Add(edge.A);
                 Points.Add(edge.B);
             }
 
             return Points;
         }

And this method returns the list of red points in your diagram from that mesh. You can do whatever you want with that list of points, like circling them, or allowing them to be edited, im guessing. You do need the original collection of vertices and triangle indicies from the original mesh to do this though, which Unity provides for each mesh you create. Hopefully this helps @Hellojeska

Full Code:

     public class MainClass
     {
         private void GetEdges()
         {
             Point[] points = mesh.Points; // The mesh's vertices
             int[] indicies = mesh.TriangleIndices; // The mesh's triangle indicies
 
             List<Edge> edges = new List<Edge>();
 
             // for every two triangle indicies
             for (int i = 0; i < indicies.Length; i++)
             {
                 // if point a != point b (meaning there is an edge)
                 if (points[indicies[i]] != points[indicies[i + 1]])
                 {
                     // Create a new edge with the corresponding points
                     // and add it to edge list
                     Edge edge = new Edge(points[indicies[i]], points[indicies[i + 1]]);
                     edges.Add(edge);
                 }
             }
 
             GetStraightEdges(edges);
         }
 
         private void GetStraightEdges(List<Edge> edges)
         {
             List<Edge> straightEdges = new List<Edge>();
 
             foreach (Edge edge in edges)
             {
                 if (edge.A.X == edge.B.X ||
                     edge.A.Y == edge.B.Y)
                 {
                     // edge is straight and not diagonal
                     straightEdges.Add(edge);
                 }
                 else
                 {
                     // edge is diagonal and can be discarded
                 }
             }
 
             List<Point> redPoints = GetPoints(straightEdges);
         }
 
         private List<Point> GetPoints(List<Edge> straightEdges)
         {
             List<Point> Points = new List<Point>();
 
             foreach (Edge edge in straightEdges)
             {
                 Points.Add(edge.A);
                 Points.Add(edge.B);
             }
 
             return Points;
         }
     }
 
     public class Edge
     {
         public Point A;
         public Point B;
 
         public Edge(Point a, Point b)
         {
             A = a;
             B = b;
         }
 
         // Creates an object that represents
         // a line from A to B (an edge)
     }
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

137 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

Related Questions

Create edges for vertices(JS) 1 Answer

how to Find the vertices of each edge on mesh 4 Answers

Getting mesh length (x,z) 1 Answer

Making Different vertices,triangle,uv maps in the same mesh 1 Answer

Access a game's 3D data during runtime 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