ssaket Posted September 27, 2018 Share Posted September 27, 2018 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. Quote Link to comment Share on other sites More sharing options...
Guest Posted September 27, 2018 Share Posted September 27, 2018 Hey! We will need a sample in the Playground to help here Quote Link to comment Share on other sites More sharing options...
ssaket Posted September 28, 2018 Author Share Posted September 28, 2018 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? Quote Link to comment Share on other sites More sharing options...
JohnK Posted September 28, 2018 Share Posted September 28, 2018 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. Quote Link to comment Share on other sites More sharing options...
JohnK Posted September 28, 2018 Share Posted September 28, 2018 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? ssaket 1 Quote Link to comment Share on other sites More sharing options...
ssaket Posted September 28, 2018 Author Share Posted September 28, 2018 Hello @JohnK Thank you so much for such a fast response. This community is really great ! Your coding style is definitely better than mine 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. Quote Link to comment Share on other sites More sharing options...
ssaket Posted September 28, 2018 Author Share Posted September 28, 2018 I tried reading about this on https://www.davrous.com/2013/06/14/tutorial-part-2-learning-how-to-write-a-3d-soft-engine-from-scratch-in-c-ts-or-js-drawing-lines-triangles/ but still I am not able to figure it out. Just started working on 3d Lot to learn Quote Link to comment Share on other sites More sharing options...
JohnK Posted September 28, 2018 Share Posted September 28, 2018 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. Quote Link to comment Share on other sites More sharing options...
JohnK Posted September 28, 2018 Share Posted September 28, 2018 I do not know enough about Delaunay triangulation in 2D or 3D to know if its use would produce the shapes you require. This may be of interest https://www.kiv.zcu.cz/site/documents/verejne/vyzkum/publikace/technicke-zpravy/2002/tr-2002-02.pdf ssaket 1 Quote Link to comment Share on other sites More sharing options...
ssaket Posted September 28, 2018 Author Share Posted September 28, 2018 Totally, that's why you see whose spheres in #5(http://playground.babylonjs.com/#5WUV7S#5) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.