Jump to content

Intersecting Concave Meshes and Their Physics


Recommended Posts

The title might look impressive but there is a long way to go yet. I am playing around with the idea of colliding meshes that have concave parts to them and then reacting based on some physics that will use BabylonJS rather than a Physics Engine. "Why?" you may say - because it gives me something to do that I am interested in.

So how far have I got? Not very far but have two things that appear to be working. I say appear as my testing is limited to two shapes which I have intersected in a couple of positions and it looks like it works. Be concerned be very concerned. The code makes extensive use of  Jerome's work on facetData.

1. Finding the approximate points of impact of two meshes.


2. Finding the center of mass of a mesh. (EDIT - Scroll down topic for playground version, following Jerome's advice)

Demo http://grideasy.github.io/Babylon/com.html    Code https://github.com/grideasy/grideasy.github.io/tree/master/Babylon

Finding the approximate points of impact of two meshes.

The basis to this is

  1. Find the overlap of the two meshes, one being the hitter and the other the hittee
  2. Split the overlap into 8 octants and recursively check each octant recursively as below until the octant is too small.
  3. Check if the hitter has any has any facets inside the current octant using the mid point of the overlap area to find the closest facet to it. If there is such a one project this onto the hittee (if such a projection exists).
  4. See if the two facets are close enough for impact, if so return the facet position from the hitter and the projected point from the hittee.
  5. If no two points are close enough split the current octant into 8 more octants and recursively repeat 2, 3, 4 and 5. If octants get too small and no hitter and hittee facets close enough return null.

Finding the center of mass of a mesh.

At some stage if the collision idea develops for more complex shapes the center of mass of the shape will be needed.

In order to complete the code I had to add to Jerome's code within BJS version 2.6 itself and hence the code is in github not in the playground. As well as being able to get facetPositions and facetNormals I have added the capability to get facetAreas. To see these additions search for JK or facetAreas within the Babylon26JK.js code from the link given above.

Warning Notes for Both Projects

For speed the first two facets close enough are taken so may not actually be the best two facets to use.

In calculating the center of mass for a mesh the mesh is assumed to be hollow and is based on the area of each facet, the density of each facet is assumed to be the same for all facets. I have not yet though about how to do it for a solid mesh (not that meshes are ever solid but perhaps calculations could be done as if they were solid).

My coding is not particularly efficient and there are probably much better ways of achieving what I have done so far in terms of structure and use of existing BJS code but I am enjoying myself and if other want to join in make improvements then the more the merrier.


Link to comment
Share on other sites

This is excellent !

I like your idea about finding the impact point, what is the real challenge in your goal.

Btw, I didn't implement the pre-computed facet area storage, what could be done easily in the same loop in ComputeNormals(), just because I thought it would take extra-memory for probably no use then and because it could be done per call really easily, knowing the facet index, from the mesh arrays indices and positions.

Really impressive work anyway :):)

Link to comment
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.

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.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...