Bowl simulation?

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Senlaar
Posts: 12
Joined: Mon Jun 22, 2020 6:11 am

Bowl simulation?

Post by Senlaar »

Hello!

I'm interested in simulating spheres rolling inside a bowl-like curved surface. Any chance you have advice on the bowl? The inside of a hemi-sphere would probably be the simplest implementation to start, but I'd be really interested in simulating a more "shallow" bowl as well, i.e. radius of the top circle of the bowl stays the same while the bowl becomes less deep. Any thoughts would be super appreciated, thanks!

-Senlaar
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Bowl simulation?

Post by Norbo »

If the bowl is static or kinematic, a mesh could be used to approximate the shape.

If it's dynamic, using a mesh would be iffy since if there are any other meshes it might collide with, you'd run into the usual 'triangles are infinitely thin, and two infinitely thin things don't tend to rest on each other' related problems.

Approximating the concave shape with multiple convexes in a compound (or BigCompound, depending on the number of children) would also work across the board.
Senlaar
Posts: 12
Joined: Mon Jun 22, 2020 6:11 am

Re: Bowl simulation?

Post by Senlaar »

Excellent point - fortunately it does not need to be dynamic.

Just a few more questions:

1. Not super familiar with Mesh creation yet. Does this entail specifying the individual triangles (as 3 Vector3's each maybe) that would create the bowl? And is just the full set of triangles enough, or is there any further logic to "stitch" adjacent triangles together?

2. I can scale Meshes after creation, correct? i.e. to create the "shallower" bowl I mentioned, I'm guessing the math is easier to create a hemisphere and then scale down on the axis of depth?

3. Can you point me at a good introduction(s) to Mesh creation in Demo project code?

Thanks so much again! Super helpful as always.

-Senlaar
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Bowl simulation?

Post by Norbo »

1. Not super familiar with Mesh creation yet. Does this entail specifying the individual triangles (as 3 Vector3's each maybe) that would create the bowl? And is just the full set of triangles enough, or is there any further logic to "stitch" adjacent triangles together?
Just a list of Triangle structs, each of which being 3 Vector3s, yup. Everything else is automatic.
2. I can scale Meshes after creation, correct? i.e. to create the "shallower" bowl I mentioned, I'm guessing the math is easier to create a hemisphere and then scale down on the axis of depth?
Yes, each mesh shape can have a different scale. Note that it has to be a different shape, but you don't have to duplicate the acceleration structure and stuff- simply doing a shallow copy and adjusting the scale will work:

Code: Select all

var mesh1 = new Mesh(triangles, scaling, pool);
var mesh2 = mesh1;
mesh2.Scale = someOtherScaling;
var shapeHandle1 = Simulation.Shapes.Add(mesh1);
var shapeHandle2 = Simulation.Shapes.Add(mesh2);
3. Can you point me at a good introduction(s) to Mesh creation in Demo project code?
The DemoMeshHelper has a few examples, and is used in a number of demos: https://github.com/bepu/bepuphysics2/bl ... hHelper.cs
Senlaar
Posts: 12
Joined: Mon Jun 22, 2020 6:11 am

Re: Bowl simulation?

Post by Senlaar »

Awesome - making the mesh worked great.

My new problem seems to be collisions with it. The mesh is a static hemisphere, with the opening up like a bowl. I can drop a dynamic sphere down one side of the bowl, and it correctly falls down the side and rolls towards the bottom. Then, if I apply linear impulse to the sphere in the plane of the ground beneath the bowl, it correctly starts rolling up a side of the bowl. However, at some point (I'm guessing when the impulse becomes sufficiently perpendicular to the bowl side that's becoming more and more vertical as the sphere rolls up) the sphere just pushes through the mesh bowl and falls out the other side.

Can I do something so the sphere will not break through the mesh, even when impulse on the sphere is directly against the mesh side? In case it's relevant: I'm using a PositionLastTimestepper, because of a similar feeling situation where a sphere lying against a static wall could be slowly pushed into the wall by applying impulse.

Thanks again!

-Senlaar
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Bowl simulation?

Post by Norbo »

This shouldn't be related to the use of a Mesh. While using PositionLastTimestepper, I'd only expect things to push through a collision if 1) the impulse is extremely high, and/or 2) collision stiffness is low, and/or 3) the object has a speculative margin that is too small relative to its velocity to catch collisions early enough.

For #2, all contacts are actually springs with a stiffness/damping defined through an oscillation frequency and damping ratio provided in the INarrowPhaseCallbacks.ConfigureContactManifold.

If the impulse is not very high and it's still being pushed through, something wonky is afoot. If none of the above point to an obvious cause, I'd recommend trying to reproduce the behavior in the demos so I can look at it directly.
Senlaar
Posts: 12
Joined: Mon Jun 22, 2020 6:11 am

Re: Bowl simulation?

Post by Senlaar »

I had a bug in my triangle creation code for the hemisphere =(. (of course somehow perfectly placed to be hard to spot in the simulation.)

Working great now. Thanks so much.

-Senlaar
Post Reply