Page 1 of 1

major jitter problems with static and moveable mesh

Posted: Thu Apr 19, 2012 7:28 pm
by martin
I have a problem with mesh objects jittering around and generally not colliding correctly in my game. I *think* this problem appeared after I changed the way in which meshes are generated, so I think this is caused by handing in mesh data the engine doesn't like.

I've made a simple test setup like this:

Image

If the floor and the box are both simple primitive shapes it works just fine. If I change just the floor to be a StaticMesh or just the box to be a MobileMesh things still work fine. However, if I change both the floor and the box into mesh shapes then everything goes wrong - the box jitters around more and more and eventually jumps right through the floor!

The box is created like this:

Code: Select all

return new MorphableEntity(new MobileMeshShape(vertices, indices, AffineTransform.Identity, MobileMeshSolidity.Solid));
and the floor is created like this:

Code: Select all

return new StaticMesh(vertices, indices);
Like I said, I suspect this is a case of bad mesh data. However, I've tried swapping around the winding to no effect.

The mobile cube is created from this data, note that there are a lot of duplicated vertices in there, is that likely to be a problem?

Code: Select all

Vertices
0:{X:0.5 Y:0.5 Z:0.5}
1:{X:0.5 Y:0.5 Z:-0.5}
2:{X:-0.5000001 Y:0.5 Z:-0.4999999}
3:{X:-0.4999998 Y:0.5 Z:0.5000002}
4:{X:-0.4999998 Y:-0.5 Z:0.5000002}
5:{X:-0.5000001 Y:-0.5 Z:-0.4999999}
6:{X:0.5 Y:-0.5 Z:-0.5}
7:{X:0.5 Y:-0.5 Z:0.5}
8:{X:0.5 Y:0.5 Z:0.5}
9:{X:0.5 Y:-0.5 Z:0.5}
10:{X:0.5 Y:-0.5 Z:-0.5}
11:{X:0.5 Y:0.5 Z:-0.5}
12:{X:0.5 Y:0.5 Z:-0.5}
13:{X:0.5 Y:-0.5 Z:-0.5}
14:{X:-0.5000001 Y:-0.5 Z:-0.4999999}
15:{X:-0.5000001 Y:0.5 Z:-0.4999999}
16:{X:-0.5000001 Y:0.5 Z:-0.4999999}
17:{X:-0.5000001 Y:-0.5 Z:-0.4999999}
18:{X:-0.4999998 Y:-0.5 Z:0.5000002}
19:{X:-0.4999998 Y:0.5 Z:0.5000002}
20:{X:-0.4999998 Y:0.5 Z:0.5000002}
21:{X:-0.4999998 Y:-0.5 Z:0.5000002}
22:{X:0.5 Y:-0.5 Z:0.5} 23:{X:0.5 Y:0.5 Z:0.5}

Indices:
2 1 0
3 2 0
6 5 4
7 6 4
10 9 8
11 10 8
14 13 12
15 14 12
18 17 16
19 18 16
22 21 20
23 22 20
Thanks, Martin

Re: major jitter problems with static and moveable mesh

Posted: Thu Apr 19, 2012 10:22 pm
by Norbo
The mobile cube is created from this data, note that there are a lot of duplicated vertices in there, is that likely to be a problem?
It shouldn't be an issue, as long as triangles aren't degenerate or something.

It sounds like the mobile mesh solidity system is picking the wrong winding. It will choose a sidedness independently from the mesh data's winding and certain meshes can confuse it.

Does it still happen when using Counterclockwise or Clockwise instead of Solid?

I'll take a closer look with the mesh data later when I have some more time; such a simple dataset should provide an easy look at how the solidity sidedness computation is failing (if it is at fault).

Re: major jitter problems with static and moveable mesh

Posted: Fri Apr 20, 2012 1:09 am
by martin
Aha! Using Counterclockwise winding fixes it, as you said MobileMeshShape (ComputeSolidSidedness(), line 326) is picking the wrong sidedness when using Solid.

Re: major jitter problems with static and moveable mesh

Posted: Fri Apr 20, 2012 5:01 am
by Norbo
The new development version should fix this problem.

If performance is a concern and the mesh works well enough without solidity, though, keeping it off might be a good idea. Solidity has some hefty overhead. (And of course, if performance is really really important, using approximations instead of a full-fledged mobile mesh is even faster :))

Re: major jitter problems with static and moveable mesh

Posted: Fri Apr 20, 2012 2:24 pm
by martin
Thanks Norbo!