Smoothing motion on banked track

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Smoothing motion on banked track

Postby Cannos » Wed Jul 19, 2017 9:04 pm

My game has a disc (chamfer cylinder) sliding directly on a race track mesh. This works fine on flat tracks, but tracks with banked turns are causing problems. The triangulation of the bank causes an uneven "saw" pattern, like this:
https://www.dropbox.com/s/e8orzose9lj267s/banktriangulation1.jpg?dl=0

You can see the disc moving up and down along triangle faces here, particularly at the end:
https://youtu.be/-0vb59lWb-M

This isn't unexpected, but I'm looking for tips on the best solutions. Here's what I'm considering:

  1. Subdivide the mesh laterally. This helps, but may not be enough to smooth out the motion without an extremely large amount of subdivision. See this:
    https://www.dropbox.com/s/mu89r24ca2wxzxr/banktriangulation2.jpg?dl=0
  2. Add suspension to disc. I've tried adding 4 springs on outside edges of disc pointing downward. This helps a little but I haven't really found a good tuning that makes a significant difference.
    • One issue with this is that I want the disc to appear in contact with the track. So I can't have very long springs under the disc.
    • Another issue is that I like the feel of the default Newton friction model and how it slows the disc sliding across the track mesh. If I do use a suspension and the disc no longer contacts the ground directly, I'll need to manually model the friction for deceleration. Any tips on doing this?
  3. Create a NURBS surface to represent the track collision surface. I'd need to replace the current mesh collision with a custom NURBS surface collision. Is it possible to integrate a user collision system that isn't mesh/triangle based into Newton?

(1) and (2) seem like the easiest things to do, just a matter of finding a good balance of triangulation and suspension tuning. Is (3) possible, and does it seem like a good idea, or overkill? Any other ideas for smoothing out these banks would be greatly appreciated!
Cannos
 
Posts: 129
Joined: Thu Mar 04, 2010 5:41 pm

Re: Smoothing motion on banked track

Postby Julio Jerez » Wed Jul 19, 2017 9:20 pm

the first thing we need to determine is if the mesh is smooth.
if it is not the we know the solution have to be a clever customization.

if the mesh is smooth then we need to determine If the edge are welded.
sometime they aren't specially when there are double faces or ill formed faces.
My guess is that the mesh is in fact not smooth because is curved.
has you tried Continue collision.

your option three is definillty possible and maybe the best solution because the surface will be smooth at all time if you have a way to make your mesh for Non Uniform splines.
if you do it is quite eassy to replace and integrate a user static collision.

you will have to calculate the the contact point and the normal for the bezier curves in order to be smooth triangulating the patch is the same as having a polygonal mesh, but it will still be a triangular mesh just of higher resolution. so that's it an improvement not really a solution.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Smoothing motion on banked track

Postby Julio Jerez » Wed Jul 19, 2017 9:36 pm

3 is probably the best idea, if you have a way to make bezier patches,

however let us not rush, when I see eh video, it seems like the disturbance are too large to be accredited to mesh irregularities.

can you serialize a test scene and play in the demos sanbox, lete us see how that works first.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Smoothing motion on banked track

Postby Sweenie » Thu Jul 20, 2017 3:30 am

How about smoothing the contact normals using barycentric coordinates? I used this to make a mesh terrain appear smooth in a raytracer once.(using Newton to cast rays).

[EDIT]
Hmm, realized this technique is for smooth rendering... i guess physics may not be fooled that easily... :lol:
But maybe the contact position could be interpolated as well, not just the normal.
Sweenie
 
Posts: 498
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: Smoothing motion on banked track

Postby Cannos » Thu Jul 20, 2017 4:04 am

The mesh is definitely not smooth, so this is expected. Due to the triangulation of the banked/curved section it will never be perfectly smooth, though it gets smoother with more dense triangulation. That's probably easier to see in the exaggerated example mesh images rather than in the video where everything is smoothly shaded.

I don't currently have a patch representation for the track, though it is made by extruding a simple mesh cross section along bezier splines. So I have part of the data for making patches. In this simple case any contact point would just be a lateral offset from the spline, and the normal would be the spline normal at the closest point on the spline.

I could try smoothing just the contact normals, though I expect I'd still see some roughness due to the contact points being based on rough triangles. But maybe that would be okay with some extra subdivision (1), and some contact point interpolation too? Perhaps I'll try this first.

For trying (3), what API do I use? I see the NewtonCreateUserMeshCollision API, but it appears that it requires triangulating a mesh which is the source of the problem. Is there another method for custom collision?
Cannos
 
Posts: 129
Joined: Thu Mar 04, 2010 5:41 pm

Re: Smoothing motion on banked track

Postby Julio Jerez » Thu Jul 20, 2017 6:49 am

Cannos wrote:The mesh is definitely not smooth, so this is expected. Due to the triangulation of the banked/curved section it will never be perfectly smooth, though it gets smoother with more dense triangulation. That's probably easier to see in the exaggerated example mesh images rather than in the video where everything is smoothly shaded.



that was what I thought, I have a very similar problem since newton 1.5 with a mesh of a race track that I got from some body, it look really nice but the moment I try to drive a vehicle over it at the curve the vehicle start bumping like crazy just the puck on the video. I ignored and simple did no show the mesh, the years later I try again with another vehicle, this when on version after version until one day to render the normal at the curves and what do yo know the where all bended, not smooth at all, the reason they look nice is because of the magic of normal interpolation for rendering.

one way to show that is not in fact smooth is to render the debug display which show the mesh flat shaded.

try soothing the normal is a good idea by the will required a change in the collision mesh because the engine is designed to have one normal per polygon, so in that regard the physics engine is like a flat shaded renderer.

This is fact a big job that required an entire new collision shape, that passes each triangle with three tringle faces. and the collision resolution does the varicentry normal interpolation. That way the collision will look like a goraud shaded mesh.

has you try rendering the mesh flat shaded to see if this is correct.

if so one quick solution that I can add is an option to the collision tree that smooth edge normal. or maybe smooth vertex normal.

option 3 will only be as good as a high texelated mesh, because you will still have to triangulate the mesh and pass back a normal per triangle.

you can find the inerface you user static collision is this file
../demosSandbox\sdkDemos\demos\UserStaticCollision.cpp

there is a demo for a single infinite plane and one for a height field, to try this

we can do this, see if you can implement the user mesh collision, the try making a height texlaled mesh to see if the problem tend to disappears, if this si the case.

the I can add and a new collision mesh called implicit surface, here the callback report each face with a normal per vertex. and the engine does the interpolation, for collision.

at the moment the triangle have 11 parameters. we can add 3 more for the implicit shape
her is the data structure for the shape.

Code: Select all
   typedef struct NewtonUserMeshCollisionCollideDesc
   {
      dFloat m_boxP0[4];                     // lower bounding box of intersection query in local space
      dFloat m_boxP1[4];                     // upper bounding box of intersection query in local space
      dFloat m_boxDistanceTravel[4];            // max distance that box bpxP0 and boxP1 can travel on this timestep, used this for continue collision mode.
      int m_threadNumber;                     // current thread executing this query
      int   m_faceCount;                           // the application should set here how many polygons intersect the query box
      int m_vertexStrideInBytes;                 // the application should set here the size of each vertex
      dFloat m_skinThickness;                     // this is the minimum skin separation specified by the material between these two colliding shapes
      void* m_userData;                          // user data passed to the collision geometry at creation time

      NewtonBody* m_objBody;                     // pointer to the colliding body
      NewtonBody* m_polySoupBody;                // pointer to the rigid body owner of this collision tree
      NewtonCollision* m_objCollision;         // collision shape of the colliding body, (no necessarily the collision of m_objBody)
      NewtonCollision* m_polySoupCollision;      // collision shape of the collision tree, (no necessarily the collision of m_polySoupBody)

      dFloat* m_vertex;                          // the application should set here the pointer to the global vertex of the mesh.
      int* m_faceIndexCount;                     // the application should set here the pointer to the vertex count of each face.
      int* m_faceVertexIndex;                    // the application should set here the pointer index array for each vertex on a face.
                                       // the format of a face is I0, I1, I2, I3, ..., M, N, E0, E1, E2, ..., A
                                                   // I0, I1, I2, .. are the indices to the vertex, relative to m_vertex pointer
                                                 // M is the index to the material sub shape id
                                       // N in the index to the vertex normal relative to m_vertex pointer
                                       // E0, E1, E2, ... are the indices of the the face normal that is shared to that face edge, when the edge does not share a face normal then the edge index is set to index N, which the index to the face normal   
                                       // A is and estimate of the largest diagonal of the face, this used internally as a hint to improve floating point accuracy and algorithm performance.


how is that?
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Smoothing motion on banked track

Postby Julio Jerez » Thu Jul 20, 2017 7:08 am

Sweenie wrote:How about smoothing the contact normals using barycentric coordinates? I used this to make a mesh terrain appear smooth in a raytracer once.(using Newton to cast rays).

[EDIT]
Hmm, realized this technique is for smooth rendering... i guess physics may not be fooled that easily... :lol:
But maybe the contact position could be interpolated as well, not just the normal.



yes you are correct Sweeney, but this is how technogies make progress, we now identified one real problem, we can solve it, by adding the implicitly surface option to the collision shape.
here this will be the equivalent of a smooth shaded collision shape, that should provide a better that linear improvement to eh collision quality, the same way smooth shading improve visual quality over flat shaded rendering.

the first test if to try a texelated mesh and see if this is in fact the problem, then we move on to the solution.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Smoothing motion on banked track

Postby Cannos » Thu Jul 20, 2017 7:21 pm

Here is a video of a more tessellated mesh, basically approach (1):
https://youtu.be/H-3R0agmcFk

It's definitely smoother. Not perfect but better. I suppose I could tessellate even a bit more and that might be enough, and the easiest solution as it requires no code changes.

For reference, here's a look comparing the 2 different tessellations on that track as flat shaded polys:
https://www.dropbox.com/s/bancj2yfdysk2rh/banktriangulation3.jpg
Cannos
 
Posts: 129
Joined: Thu Mar 04, 2010 5:41 pm

Re: Smoothing motion on banked track

Postby Julio Jerez » Fri Jul 21, 2017 7:24 am

ha that's better, maybe trying and even lower texlation, and it should be fine as long as you do no use large bank angles.

and yes the image in he left clearly shows the surface is not smooth, is the one on eh right the higher texelated?
I guess you have under control?
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Smoothing motion on banked track

Postby Cannos » Fri Jul 21, 2017 5:53 pm

Yeah, I'll continue with this approach (1) and see how it goes. Thanks for the information on the custom static collision, knowing that it requires triangles is helpful for future uses.

I may still investigate adding a suspension to the disc (2) for other reasons, though the limitations I described earlier may make that difficult.
Cannos
 
Posts: 129
Joined: Thu Mar 04, 2010 5:41 pm

Re: Smoothing motion on banked track

Postby Julio Jerez » Fri Jul 21, 2017 6:46 pm

regarding suspension, we you are ready to do that, you may want to pin me again.

suspension can be easily emulated by setting the contacts to be soft contacts.
there is not current support for that yet, but I will be adding it the next few days for another feature that I am working on.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 10 guests