EntityShape and Entity (compound bodies creation)

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
JusTiCe8
Posts: 52
Joined: Mon Jun 01, 2015 9:02 am

EntityShape and Entity (compound bodies creation)

Post by JusTiCe8 »

Hi,

maybe you remember my rotating planes issue :), going back to it, in order to make an actual working maze, I haven't figured out how to do it.

There are only simple examples of CompoundShape in demos using EntityShape objects, some using convexHull shape, but nothing else in EntityConstructionDemo and CompoundBodiesDemo. In the first one, there is a lot of comments but they're not very helpful (to me).

I guess I can create a maze using something like this one (from EntityConstructionDemo):

Code: Select all

CompoundBody body = new CompoundBody(new List<CompoundShapeEntry>
            {
                new CompoundShapeEntry(new BoxShape(1, 1, 1), new Vector3(-7, 3, 8), 1),
                new CompoundShapeEntry(new BoxShape(1, 3, 1), new Vector3(-8, 2, 8), 5),
                new CompoundShapeEntry(new BoxShape(1, 1, 1), new Vector3(-9, 1, 8), 1)
            }, 10);
(which will need some maths + a proper data structure, which is what I would like to ultimately achieve in order to build random mazes).

Could you provide one/some example(s) of a concave shape made with the helpful ModelDataExtractor (this one could really be included as a utility method in BEPUutilities library) please ?
I admit I'm lack some C# knowledge to handle classes, abstract classes and inheritance for now.

ex: MobileMeshShape is an EntityShape but CompoundShapeEntry constructor doesn't allow it:

Code: Select all

Error	2	Argument 1: cannot convert from 'BEPUphysics.Entities.Prefabs.MobileMesh' to 'BEPUphysics.CollisionShapes.EntityShape'
with this code:

Code: Select all

BEPUutilities.Vector3[] staticTriangleVertices;
int[] staticTriangleIndices;
ModelDataExtractor.GetVerticesAndIndicesFromModel(HandMadeMaze, out staticTriangleVertices, out staticTriangleIndices);

var staticMaze = new MobileMesh(staticTriangleVertices, staticTriangleIndices, new AffineTransform(Matrix3x3.CreateFromAxisAngle(BEPUutilities.Vector3.Up, BEPUutilities.MathHelper.Pi), new BEPUutilities.Vector3(0, -10, 0)), MobileMeshSolidity.Solid);
            
var compoundShape = new CompoundShape(new List<CompoundShapeEntry>
            {
               new CompoundShapeEntry(staticMaze, new BEPUutilities.Vector3(0, 6, 0), 1)
            });
Thanks.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: EntityShape and Entity (compound bodies creation)

Post by Norbo »

Could you provide one/some example(s) of a concave shape made with the helpful ModelDataExtractor ... MobileMeshShape is an EntityShape but CompoundShapeEntry constructor doesn't allow it:
A MobileMesh is not a MobileMeshShape. A MobileMesh is an Entity with collision defined by a MobileMeshShape. (The existence of the prefab entity types like MobileMesh is one of those examples of 'fake' simplicity that's going away in v2.)

So, all you need to do is to change "var staticMaze = new MobileMesh(..." to "var staticMaze = new MobileMeshShape(...".
ModelDataExtractor (this one could really be included as a utility method in BEPUutilities library)
Unfortunately, ModelDataExtractor is XNA specific, so the libraries cannot rely on it.

A few other notes:
1) Avoid MobileMeshShapes when possible. They're often way more expensive than using simpler primitives to express the same rough shape.
2) If MobileMeshShapes are used, make sure the geometry is built to be kind to the physics. Avoid crazy long triangles, avoid degenerate triangles, avoid unnecessary density.
3) If MobileMeshShapes are used, avoid MobileMeshSolidity.Solid if possible. It's significantly more expensive than than the other options. Usually, using one of the one sided options is best.
JusTiCe8
Posts: 52
Joined: Mon Jun 01, 2015 9:02 am

Re: EntityShape and Entity (compound bodies creation)

Post by JusTiCe8 »

Norbo wrote:A MobileMesh is not a MobileMeshShape. A MobileMesh is an Entity with collision defined by a MobileMeshShape. (The existence of the prefab entity types like MobileMesh is one of those examples of 'fake' simplicity that's going away in v2.)

So, all you need to do is to change "var staticMaze = new MobileMesh(..." to "var staticMaze = new MobileMeshShape(...".
Thanks, as always.
Norbo wrote: Unfortunately, ModelDataExtractor is XNA specific, so the libraries cannot rely on it.
mmm... I'll never get used to that ! :)
Norbo wrote: A few other notes:
1) Avoid MobileMeshShapes when possible. They're often way more expensive than using simpler primitives to express the same rough shape.
2) If MobileMeshShapes are used, make sure the geometry is built to be kind to the physics. Avoid crazy long triangles, avoid degenerate triangles, avoid unnecessary density.
3) If MobileMeshShapes are used, avoid MobileMeshSolidity.Solid if possible. It's significantly more expensive than than the other options. Usually, using one of the one sided options is best.
The point 2 seems a bit contradictory to itself as it could be better (from a texturing point of view) to split a long rectangle into smaller ones, so moving from two long triangles into a bunch of smaller ones, increasing density (of vertices and triangles). Even knowing it is not good from modelling point of view (as these extra faces doesn't change the overall shape).

For the point 1 it would be a lot more easier if we have some tool to (as much as possible) build automatically the physical mesh from the visual object, in the best possible way from the BEPU point of view, like the tool unity editor have (creating convex, or not, collider(s) from mesh(es)). Without any visual, it's just maths :)

If some readers would like to do it, it may be possible to write some unity script to convert colliders into BEPU basic shapes. So we could use unity editor with a given object to create a physical representation of it for use into BEPU.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: EntityShape and Entity (compound bodies creation)

Post by Norbo »

The point 2 seems a bit contradictory to itself as it could be better (from a texturing point of view) to split a long rectangle into smaller ones, so moving from two long triangles into a bunch of smaller ones, increasing density (of vertices and triangles). Even knowing it is not good from modelling point of view (as these extra faces doesn't change the overall shape).
A couple of notes:
1) The physics representation should almost never be the same geometry as the graphical mesh, unless the graphical mesh is extremely simple and well-behaved. The requirements for the two representations are just too different to combine well in most cases.
2) Strictly from a physics perspective, if you have to choose, avoiding really long triangles (and especially near-degenerate triangles) is more important than avoiding a few extra triangles. Super long and near-degenerate triangles will tend to force a greater number of difficult collision tests compared to a few more regular triangles.
For the point 1 it would be a lot more easier if we have some tool to (as much as possible) build automatically the physical mesh from the visual object, in the best possible way from the BEPU point of view, like the tool unity editor have (creating convex, or not, collider(s) from mesh(es)). Without any visual, it's just maths
There are some tools that do this sort of thing. The best I've seen for convex decomposition in particular is VHACD. These sorts of tools could export data which could be consumed by BEPUphysics, though BEPUphysics doesn't offer anything special to help.

Unfortunately, this is a hard problem to solve automatically. In many cases, a human can still do better by making use of assumptions and shortcuts that the automatic tool doesn't know about.
Post Reply