[SOLVED]Static Mesh

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Garold
Posts: 60
Joined: Fri Sep 23, 2011 5:17 pm
Location: Liverpool, England

[SOLVED]Static Mesh

Post by Garold »

I cannot get the static mesh to work reliably. I created a level in Sketchup and used an exporter to create a .x model. The character walks around fine. Occasionally he/she will get stuck in the wall. The major problem is the kapow sphere and the boxes. If I fire the sphere it will get stuck in the floor or wall now and again. If I explode the sphere near a group of boxes they get stuck in the floor or walls and wobble around. I also get NaN errors.

I did a straight swap of the the playground mesh for my mesh.

Will I have to build a physics level out of boxes and not use the static mesh?
Last edited by Garold on Sun Oct 16, 2011 8:18 pm, edited 1 time in total.
BEPUphysics rules my world
http://cloneofduty.com
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Static Mesh

Post by Norbo »

Will I have to build a physics level out of boxes and not use the static mesh?
Nope!

Some possibilities:
-Is this in v1.0.0? In older versions, degenerate triangles in a mesh could cause NaN exceptions.

-It sounds like it might be a scale problem. How big are the triangles in the mesh? The engine likes to deal with objects on the scale of around 0.5 to 10 units. Going larger than that is usually okay, but if the triangles are way above 100 units long, you will probably start to see some oddities under certain circumstances- especially at edge collisions.

-Additionally, if there are near-degenerate triangles (e.g. 1000x1 units or similarly extreme ratios), robustness will suffer as well.

-Are the walls and floor made of multiple layers of triangles such that an object could get stuck between them? If so, consider setting the mesh's sidedness to onesided (either clockwise or counterclockwise). That way, objects that get between the layers will easily escape from the wall. You could also set the entities' position update mode to continuous. This wouldn't explain the NaN's very well by itself.

There's nothing special about the default playground mesh. Any properly scaled mesh with decent topology should work fine. In the latest version, even degenerate geometry should 'work' (though it's better to ensure the mesh has no degenerate geometry to begin with), so it would be nice to figure out where those NaN's are coming from.
Garold
Posts: 60
Joined: Fri Sep 23, 2011 5:17 pm
Location: Liverpool, England

Re: Static Mesh

Post by Garold »

I am using the latest source code df0f6d42d78f.

I read in other threads that scale could be an issue. It's neither big nor small. The exporter from google makes the model a bit small. In the AffineTransform I scale the model by 0.025375f;

Code: Select all

Vector3[] staticTriangleVertices;
int[] staticTriangleIndices;
modelHospital = game.Content.Load<Model>("Models/Hospital");
TriangleMesh.GetVerticesAndIndicesFromModel(modelHospital, out staticTriangleVertices, out staticTriangleIndices);
var staticMeshHospital = new StaticMesh(staticTriangleVertices, staticTriangleIndices, new AffineTransform(new Vector3(G.INCH, G.INCH, G.INCH), Quaternion.Identity, new Vector3(0, 0, 0)));
staticMeshHospital.Sidedness = TriangleSidedness.Counterclockwise;
staticMeshHospital.ImproveBoundaryBehavior = true;
Space.Add(staticMeshHospital);
I worked out the scale by creating a box in Sketchup. I then kept adjusting the scale till it matched a unit in Bepu. This turned out to be 0.025375f;

I reduced the size of the kapow sphere

Code: Select all

//Create the tossable ball.
kapow = new Sphere(new Vector3(11000, 0, 0), .25f, 1f);
kapow.PositionUpdateMode = BEPUphysics.PositionUpdating.PositionUpdateMode.Continuous;
kapowMaker = new Explosion(Vector3.Zero, 50, 15, Space);

The cylinder code is

Code: Select all

var cylinder = new Cylinder(new Vector3(0, 1, 0), 6 * G.FOOT, 1.5f * G.FOOT, 1);
cylinder.PositionUpdateMode = BEPUphysics.PositionUpdating.PositionUpdateMode.Continuous;
Space.Add(cylinder);
G.FOOT is 12 * G.INCH

I don't think the triangles are too big?

Haven't had a NaN error in a while. It was in CylinderShape.cs GetLocalExtremePointWithoutMargin

I have uploaded a video to youtube so you can see it. http://www.youtube.com/watch?v=-ottyNm3UGU
BEPUphysics rules my world
http://cloneofduty.com
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Static Mesh

Post by Norbo »

That doesn't look much like a scale issue. It appears to latch onto the ceiling/floor without getting halfway through, implying it's not getting stuck between two walls. Turning on the contact viewer ('k' in the demos) might give some hints.

A NaN error in a GetExtremePoint method means that the position and orientation of the entity became NaN in the prior frame. Those shouldn't happen except in extreme cases of numerical difficulty or invalid settings.

Could you send over the relevant files so I could debug it? You can PM me it if you would prefer to keep it off the public forum.
Garold
Posts: 60
Joined: Fri Sep 23, 2011 5:17 pm
Location: Liverpool, England

Re: Static Mesh

Post by Garold »

I have attached the .x model and c# in a PM.

The model has an upstairs, so there is a gap between the ceiling and the floor above.

The c# is a stripped down version of the characterplayground demo.

I have previously done a straight swap of the model into the original characterplayground demo, changing the scale from 0.01f to 0.03f to allow the character the pass through doorways. There were problems with the boxes getting stuck in walls when I exploded the sphere near them.
BEPUphysics rules my world
http://cloneofduty.com
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Static Mesh

Post by Norbo »

There appear to be some issues with the mesh. The issues can be seen more clearly using the BEPUphysicsDrawer (game.ModelDrawer.Add(staticMeshHospital)). Running in release without the debugger results in blacked out triangles; this is usually associated with nearby degenerate triangles. Further, it appears that all or most triangles are duplicated given that switching graphical cullmode does not make any difference.

Duplication can also be seen by changing the collision sidedness of the mesh from Counterclockwise to Clockwise. The behavior does not change significantly. In a regular mesh, going from Counterclockwise with collision to Clockwise winding would result in the objects falling through the floor without any resistance since the collision direction was reversed.

The duplicated triangles seem to fight each other, resulting in the occasional wall-latching. You can force the system into agreement by setting the collision sidedness to DoubleSided. I don't notice any artifacts in this mode.

However, the degenerate triangles are still hiding in the mesh, masked by protections built into the collision detection system. Additionally, all collisions are twice as expensive as they need to be, since there seem to be two triangles everywhere. Fixing the mesh (or using a more reliable export process if that is the source of the issues) should resolve the issues and result in better performance.
Garold
Posts: 60
Joined: Fri Sep 23, 2011 5:17 pm
Location: Liverpool, England

Re: Static Mesh

Post by Garold »

You are absolutely correct. The exporter I use has an option to use textured faces only. The collisions now work fine. I have uploaded a video.

http://www.youtube.com/watch?v=3IVo6dj3ib4

I would like to thank you for the time and effort you have put into this question. You are a dedicated professional. 8)
BEPUphysics rules my world
http://cloneofduty.com
Post Reply