ssaket

How to recalculate mesh triangulation

Recommended Posts

Hello, I have a use case where I would want to -

  • create a mesh (for example- Cube)
  • remove a vertex on some event (say mouse click)
  • reconstruct the mesh

I am able to remove the vertex from the mesh's verdata but when I use Delaunay triangulation to find the new Indices, the mesh geometry gets distorted. Not sure what to do here?

Any help is much appreciated.

Share this post


Link to post
Share on other sites

Here's the awesome playground - http://playground.babylonjs.com/#5WUV7S - click on any vertex to see how it works :)

TL;DR

okay, here's what I am currently doing- 

First, I try to find the facets from pickInfo, after that, I try to find the nearest vertex from the pickPoint -> then the corresponding triangles, which contains that vertex -> and delete them from the mesh indices.

I am not able to use the earcut's triangulation function, I don't know why but I thick it's because of the duplicated vertices.

 Also, I don't remove the vertex from the verdata: "BABYLON.VertexBuffer.PositionKind"- 

 

I can think of an another long approach- find all the coplaner faces-> apply 2d triangulation -> push them into vertexbuffer. But I don't  wanna use this ! Any inputs on how to use the earcut's triangulation function or any other idea? 

 

Share this post


Link to post
Share on other sites

Hi @ssaket and a warm welcome from me. I have taken a different approach, why re-triangulate when you can just re-position the vertex to delete, http://playground.babylonjs.com/#5WUV7S#3

Perhaps the PG does not do exactly what you want but perhaps you can gain something from it. My style of coding is a little different to yours but you can soon change anything to the way you want it done.

First step is to make the mesh updatable, this means the vertexData can be overwritten ( but quantities cannot be altered), then minimize the number of vertices by removing duplicates (this has issues) so that any vertex position has only one index. Next using the faceId check which vertex of that faceId is the one to be 'deleted'. Find all faces that have this vertex and store all vertices joining to this one. For all such connecting vertices average out their x, y and z positions and set the position of the vertex to be deleted to this average, effectively deleting it but keeping the same triangulation.

EDIT Opps 🙁. Not working correctly. There is a problem where a vertex is joined to a diagonally opposite one and not just along an edge. Need more time to sort this out.

Share this post


Link to post
Share on other sites

Having given it even more thought the PG above does work correctly in that it does what it says on the tin and re-positions the vertex with respect to the average of the connecting vertices. What I have not thought through is how I want the cube to appear when I 'delete' a vertex. Here is a new PG  http://playground.babylonjs.com/#5WUV7S#4 that works on the same basis but minimizes vertices after the click and reverts to a flat shaded one after 'deleting' the vertex. On running the PG and clicking on the top left of the face towards you I got what I expected, clicking on the top right of the face towards you gets the result that surprised me. (same result in #3) So I had an expectation that did not follow through but even worse I have no idea of your expectations. So a question I should have asked first

Given a cube from which you delete one corner (corner might have one or more vertices) what do you expect your mesh to look like?

Share this post


Link to post
Share on other sites

Hello @JohnK

Thank you so much for such a fast response. This community is really great !

Your coding style is definitely better than mine :P 

I liked your approach of projecting the vertex on to the plane and then updating the same. Though, I wanted the previous approach because, I may in future want to add an extra vertex also. 

 Have a look at this play ground - http://playground.babylonjs.com/#5WUV7S#5

you see those newly created spheres(which are just for reference) after you select a vertex, I would wanna connect them(basically the verdata-> like 123, 235 in mesh.indices; hope you getting my point). It work perfectly for the vertex which is shared by 3 facets(triangles). But when we have a vertex which is being shared by 6 facets (triangles) it fails. That's why I am curious to know how babylonjs connects

the vertices. 

Share this post


Link to post
Share on other sites

Whichever way you do it, true delete or simulated delete you still need to come up with a way to determine which of the vertices that connect to the 'to be deleted vertex' are the significant ones in terms of re-triangulation.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.