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 Glurth · Feb 13, 2015 at 03:13 PM · meshtrianglespolygon

Merge mesh triangles into polygons: need help with vertex ordering

I’ve got an algorithm that takes triangular based meshes and creates a polygon based “mesh” from it. It seems to be working well except for one point.

When I do merge triangles or polygons(previously merged triangles) together (they must lie on the same plane and share an edge to be merged) into a poly, the points are no longer in “counterclockwise” order.

What I have been doing is, given poly1 and poly2: Remove the shared vertices from poly2, and then append the remaining vertices to poly1.

While this does get all the points I need into the polygon, it also, sometimes, messes up the order of the points. (even for a simple cube!)

This method also does NOT get rid of all unneeded points: consider a pie-slice-like, pentagon of triangles. Once I add the last triangle of the pentagon, the center vertex should be eliminated. But I have no idea how to check for such a condition.

QUESTIONS: How can ensure my polygons vertex order is correct (ideally WHILE merging two polys)?
How can I detect if particular vertex points need to be eliminated (like the center of the pie-slices)?

Thoughts: I was considering the following solution, but it won’t work for concave polygons, nor will it help with that center vertex removal I exampled above: Randomly select an interior point. Compute the angle between that point and each vertex. Sort vertices based on that angle.

I’ve researched this a bit, and found some good stuff, but nothing that has really helped with this particular minutiae of the algorithm. My initial research also failed to find an open-source-library which does this algorithm already, which was surprising, until I remembered I’m totally awful at searches.

UPDATE: progress so far... we know merging polys shared at least 2 vertices(flush).. so:

Rather than APPEND the vertices from one poly to another when merging, we must INSERT the vertices from one poly BETWEEN the two shared vertices of the other.

Furthermore, if we are merging a triangle and a poly, if we have 3 shared vertices, we REMOVE the middle shared vertex from the poly. (to get rid of the vertex in the center of the pie)

Working better now, but sill having a few issues (though it may just be a bug in my implementation of the above).

Update2: I managed to get an implementation going that creates an EDGE rather than a polygon, on triangles that are FLUSH , but NOT parallel (edge is created between the two shared vertices-"flush"). this seems to work for closed surface meshes only.

Update3: OK, getting REALLY close now. The ONLY issue remaining is one I though I had solved, but haven't. When combining two polys that share THREE vertices, this means I am "CLOSING" the polygon. I will need to insert all the vertices (except those shared), from poly A, between two of the three shared vertices of poly B, and remove the last shared vertex (the interior point) from the final poly. I remain unable to figure out which two points to insert between, and which point to remove. My intuition tells me it has to do the the number of vertices listed BETWEEN the three vertices in question, but I don't see it yet.

Comment
Add comment · Show 3
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 Baste · Feb 16, 2015 at 10:58 PM 0
Share

Is this mesh going to be visible?

$$anonymous$$erging collision meshes is pretty trivial, as you won't care about UVs. If that's not the case, merging is a lot harder. Remember, the standard cube has 24 verts, not 8, as each corner needs different UVs.

avatar image Glurth · Feb 16, 2015 at 11:37 PM 0
Share

No, it will not be visible. UV, normal, and color information is all discarded. (Because of your point about the cube vertices: at the very beginning of the routine, I check each vertex's position and if any others have the same position, I merge them into a single vertex.)

Actually, I'm NOT trying to merge meshes, I'm triangle to merge the TRIANGLES that make up a mesh, into a polygon based mesh data structure(basically, a list of polygons, where Polygon is just a list of vertex indexes). One I have this data, I can then use this to draw objects between vertices for a wire-frame like effect, or animate transform between vertices to get a cool effect. (But that's only a couple of examples of what I would like to do with these polygon meshes.)

$$anonymous$$any thanks for the input!

avatar image Anish_gupta_90 · Feb 17, 2016 at 03:34 PM 0
Share

Dear Glurth, I am working on similar problem where I am trying to merge 3D polygon on same plane. I faced same issue where I messed up order of points. I would like to know 1) What is complexity of your algorithm ? 2) I haven't got enough documents on internet, if possible can you please share some links.

Thanks,

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Glurth · Mar 28, 2016 at 07:06 PM

I eventually found a solution, here is the psudo-code:

Merge poly A into B

  Find first TWO or THREE shared verticies
  If we find exactly 3 shared verticies:
        -We compute the different between every shared vertex-index in B with every other shared-vertex in B
        -The differences that has a value of "2" specifies which of the two indices have the third BETWEEN them.
        -This third, between point, is the one    we will want to discard.
  Once that point is discarded we insert all the verticies from the second poly (excluding any shared    points) in exactly the same order as the original.   NOTE: This last part ASSUMES the two polygons are facing the same direction, vertex order-wise, before merging.
     -If our two points straddle the end or the vertex list, we insert at the end of the vertex list.

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

22 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

Related Questions

shooting raycast from each triangle on mesh and change its texture 0 Answers

Null Reference Exception Assigning Vertices to Mesh 0 Answers

UNITY4 all i see is the triangle/verts of objects 1 Answer

Mesh.triangles specification 1 Answer

Best Way to Link Vertices into Mesh 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