• Home
  • Products
    • Game Engine
      • Base
      • Mathematics
      • Geometry
      • Physics
      • Particles
      • Animation
      • Graphics
      • Game
      • Game UI
    • Windows Forms
      • Docking Windows
      • Text Editor Control
  • Downloads
  • Buy
    • Overview
    • Professional
    • Indie
    • Non-Commercial
  • Support
    • Overview
    • Blog
    • Forum
    • License FAQ
    • Documentation
  • About
    • About Us
      • Services
    • Contact Us
    • Press
    • Legal Terms
      • Imprint (English)
      • Imprint (German)
Select the search type
 
  • Site
  • Web
Search
DigitalRune.com
Login |Register
NEWS News RSS Feed BLOG Blog RSS Feed FORUM News RSS Feed DOCUMENTATION DigitalRune Software on YouTube DigitalRune Software on Twitter
You are here: SupportForum

If you want to contribute to the forum discussions, please Register or Login.

SearchHome
  • 1
  • 2
  • 3
  • 4
  • 5
HomeHomeDigitalRune Sof...DigitalRune Sof...Game EngineGame EngineSmooth Movement along TriangleMeshSmooth Movement along TriangleMesh
Previous
 
Next
New Post
7/6/2011 10:55 PM
 
madbarron
No Ranking

Joined: 7/6/2011
Posts: 4
Smooth Movement along TriangleMesh 
In my game I am rolling a small ball down a large, curved ramp which is a TriangleMesh imported from a FBX file.  Consider a ping-pong ball rolling down a half-pipe. The problem is that although the ramp has ~ 100 faces on the curve, the ball will often bounce off the surface unnaturally.

Is there anything I can do to make the ball "transfer" between the faces more easily? I've tried setting the restitution for both objects to zero, but that doesn't help much.

Thanks!
 
New Post
7/7/2011 9:22 AM
 
MartinG
7th Level Poster

www.digitalrune.com
Joined: 10/15/2006
Posts: 448
Re: Smooth Movement along TriangleMesh 
This is a typical problem when triangle meshes are used for physics.
However, we often test SphereShapes vs. TriangleMeshShapes and usually don't see any problems.

Make sure that the ball itself is a SphereShape and not a TriangleMeshShape.
Try to enable "contact welding" (TriangleMeshShape.EnableContactWelding) for the mesh shape. This should mitigate the problem.

Example:
triangleShapeMesh.EnableContactWelding = true;

If this does not solve the problem, please post a screenshot (wireframe if possible) of your level. 
(You can send the screenshot directly per email or you can post it here in the forum).
 
New Post
7/8/2011 12:47 AM
 
madbarron
No Ranking

Joined: 7/6/2011
Posts: 4
Re: Smooth Movement along TriangleMesh 
Thanks for the response, Martin. Unfortunately, EnableContactWelding didn't seem to help.

Attached is a screenshot of the scale I was hoping for and a wireframe of the ramp. I guess the problem is a result of the difference in size between the ball and the ramp, and the fact that the ball is going so fast compared to the curve. The problem begins to be reduced if I make the ball 5-10 times larger.

Any other suggestions that would help me keep this scale?
 
 wire.PNG
 ss.png
New Post
7/8/2011 4:14 PM
 
HelmutG
6th Level Poster

www.digitalrune.com
Joined: 10/15/2006
Posts: 565
Re: Smooth Movement along TriangleMesh 
Thanks for the screenshots.

I have made a few tests with a similar scene.
Unnatural bounces at triangle edges can have several causes and here are a few things you can try:


Contact Welding

Bounces can be caused by bad normal vectors at triangle edges.
Enable contact welding for the mesh:

  triangleShapeMesh.EnableContactWelding = true;

and make the welding more aggressive by setting the welding limit to 1. This is a static property of the TriangleMeshAlgorithm class:

  TriangleMeshAlgorithm.WeldingLimit = 1f;

Contact welding improves the contact normal vectors at triangle edges. 


Perfect sphere contacts

Normally, when a sphere touches another object, the contact normal vector points in the direction from the sphere center to the contact. When contact welding is used, the contact positions can be a bit off. - But small errors can cause visible bounces.
We can correct this with a custom contact filter:

public class MyContactFilter : IContactFilter
{
  private ContactReducer _defaultContactFilter = new ContactReducer();
  
  public void Filter(ContactSet contactSet)
  {
    // Call the default contact filter.
    _defaultContactFilter.Filter(contactSet);
  
    // Abort if there are no contacts in this contact set.
    if (contactSet.Count == 0)
      return;
  
    // If this is a sphere vs. * contact set, then we correct the position of the 
    // contact point to make sure that the contact position is in line with the sphere center.
  
    var sphere = contactSet.ObjectA.GeometricObject.Shape as SphereShape;
    if (sphere != null)
    {
      float radius = sphere.Radius;
  
      foreach(var contact in contactSet)
        contact.Position = contactSet.ObjectA.GeometricObject.Pose.Position + contact.Normal * (radius - contact.PenetrationDepth / 2);
            
      return;
    }
  
    sphere = contactSet.ObjectB.GeometricObject.Shape as SphereShape;
    if (sphere != null)
    {
      float radius = sphere.Radius;
      foreach (var contact in contactSet)
        contact.Position = contactSet.ObjectB.GeometricObject.Pose.Position - contact.Normal * (radius - contact.PenetrationDepth / 2);
    }
  }
}


Set this filter with:
    simulation.CollisionDomain.CollisionDetection.ContactFilter = new MyContactFilter();

When I use contact welding and this contact filter, I get a very smooth movement.
If this does not help, here are a few more things you can try:


Lower friction

Try to use a lower friction. If the friction is lower, the spheres can glide more smoothly over bumps.


Allowed Penetration Depth

Try to lower the allowed penetration depth. For example: 
    simulation.Settings.Constraints.AllowedPenetration = 0.001f;

If this parameter is high (which is not good in your case), then the sphere will sink more into the triangle surface. And when it rolls to a triangle edge, it will perceive the neighbor edge as a small upwards step.


Gravity

When the gravity is high, small bumps can have a higher impact. Try to use a lower gravity, for example:
simulation.ForceEffects.Add(new Gravity() { Acceleration = new Vector3F(0, -5, 0)});


Height field instead of triangle mesh

Try to use a height field instead of a triangle mesh - if your scenario allows to use a height field.


Distorted triangles

Your triangles are very distorted (one side is small relative to the other sides). Subdivide your mesh to create more regular triangles. Very long, distorted shapes will create high numerical errors in many collision detection and physics algorithms.


Hope this helps - if not, let us know.
 
New Post
7/8/2011 10:02 PM
 
madbarron
No Ranking

Joined: 7/6/2011
Posts: 4
Re: Smooth Movement along TriangleMesh 
HelmutG wrote:

and make the welding more aggressive by setting the welding limit to 1. This is a static property of the TriangleMeshAlgorithm class:

  TriangleMeshAlgorithm.WeldingLimit = 1f;

Contact welding improves the contact normal vectors at triangle edges.

 

Thanks, I'll get on these changes.

Who holds the TriangleMeshAlgorithm? In what object can I find or put this class?

Thanks!

 
New Post
7/9/2011 2:26 AM
 
HelmutG
6th Level Poster

www.digitalrune.com
Joined: 10/15/2006
Posts: 565
Re: Smooth Movement along TriangleMesh 
madbarron wrote:

Who holds the TriangleMeshAlgorithm? In what object can I find or put this class?

 
The TriangleMeshAlgorithm class is in the namespace DigitalRune.Geometry.Collisions.Algorithms. (In most cases you do not interact with this class directly.)
The WeldingLimit property is a static class property, so you can call:

    DigitalRune.Geometry.Collisions.Algorithms.TriangleMeshAlgorithm.WeldingLimit = 1.0f;

 
New Post
7/9/2011 10:52 PM
 
madbarron
No Ranking

Joined: 7/6/2011
Posts: 4
Re: Smooth Movement along TriangleMesh 
Victory!

With contact welding (limit 1.0) , perfect sphere contacts, and much less skewed triangles, my simulation is working wonderfully!  At first, the custom contact filter was slowing down the simulation, causing stutters, so I reduced the number of polys at the bottom of the ramp. Thanks to the contact welding, the reduced resolution didn't hurt.

Thank you so much!
 
 Page 1 of 1
Previous
 
Next
HomeHomeDigitalRune Sof...DigitalRune Sof...Game EngineGame EngineSmooth Movement along TriangleMeshSmooth Movement along TriangleMesh


DigitalRune is a trademark of Garstenauer Information Technology OG.

Garstenauer Information Technology OG
Weingartenstrasse 35, 4452 Ternberg
Austria (EUROPE)
office@digitalrune.com

Home Products Downloads Buy Support About Us
Game Engine Particles Windows Forms Professional Blog Services
Base Animation Docking Windows Indie Forum Contact Us
Mathematics Graphics Text Editor Control Non-Commercial License FAQ Press (News)
Geometry Game Documentation Legal Terms
Physics Game UI Imprint
Impressum
Copyright © 2006-2012 Garstenauer Information Technology OG Terms Of UsePrivacy Statement