Page 1 of 1

Loading FBX Models to Entity

Posted: Sun Feb 20, 2011 5:22 pm
by Becki
Hey there!

I'm fairly new to physics engines, especially BEPU. It's a great engine, but I'm having some problems. I can't get my head around converting a StaticTriangleGroup/TriangleMesh into a ConvexHull/* Entity. I've looked all over and found no answers that helped. If possible, could somebody submit some code for it? This is all for learning purposes.

Current code:

Code: Select all

                var barrelAndPlatform = Content.Load<Model>("models/basketball");
                StaticTriangleGroup.StaticTriangleGroupVertex[] staticTriangleVertices;
                int[] staticTriangleIndices;
                StaticTriangleGroup.GetVerticesAndIndicesFromModel(barrelAndPlatform, out staticTriangleVertices, out staticTriangleIndices);

                //Note that the final 'margin' parameter is optional, but can be used to specify a collision margin on triangles in the static triangle group.
                var mesh = new TriangleMesh(staticTriangleVertices, staticTriangleIndices, 0);
                var fishDepositoryGroup = new StaticTriangleGroup(mesh);
                space.Add(fishDepositoryGroup);
                ModelDrawer.Add(mesh);

                //Here I want to convert it into a non-static entity for physics handling
Yes, it was taken from an example ;)

Thanks.

Re: Loading FBX Models to Entity

Posted: Sun Feb 20, 2011 10:53 pm
by Norbo
ConvexHulls are pointsets, so you can take some loaded vertices and construct a ConvexHull directly from it. You don't have to create any TriangleMeshes or StaticTriangleGroups.

To get the list of Vector3's, you can use a build-time content processor to extract the vertices, or just use the TriangleMesh.GetVerticesandIndicesFromModel convenience method, or anything else that can get the list of vertices.

Once you have a List<Vector3>, just make a new entity:

Code: Select all

ConvexHull entity = new ConvexHull(points, mass);
It's a good idea to keep the complexity of ConvexHulls to a minimum for performance and stability. While the graphical model may have thousands of triangles, it can usually be approximated by only a couple dozen points for collision. This simplification process can be done by creating a separate model at build time. There are also algorithmic approaches to simplification, but none are currently included in the engine.