Drawing Static Triangle Groups / Mesh

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Arch3r
Posts: 4
Joined: Sun Jul 04, 2010 10:57 am

Drawing Static Triangle Groups / Mesh

Post by Arch3r »

Ive been using The demo's BEPUphysicsDrawer to draw the majority of my items in my current project most importantly my 3d model terrain

ive also been trying to figure out how the physicsDrawer works, but since it uses so many custom classes and jumps back and forth between InstancedModelDraw to ModelDisplayObjectBase and selfDrawingModel...so on and so forth

my question is What are the key needed components to draw a terrain using the Static Triangle Group Method?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Drawing Static Triangle Groups / Mesh

Post by Norbo »

The simplest way to do it is to load in a Model and draw it directly. You can see an example in the DisplayModel class.

Code: Select all

            myModel.CopyAbsoluteBoneTransformsTo(transforms);
            for (int i = 0; i < model.Meshes.Count; i++)
            {
                for (int j = 0; j < model.Meshes[i].Effects.Count; j++)
                {
                    BasicEffect effect = model.Meshes[i].Effects[j] as BasicEffect;
                    if (effect != null)
                    {
                        effect.World = transforms[model.Meshes[i].ParentBone.Index] * worldTransform;
                        effect.View = viewMatrix;
                        effect.Projection = projectionMatrix;
                    }
                }
                model.Meshes[i].Draw();
            }
It basically goes through each mesh in the model, sets up the mesh's BasicEffect, and then tells it to draw.

If you create a StaticTriangleGroup from a Model, the graphics and physics should be aligned as long as the worldTransform you use for each is consistent.

The above is not the fastest or cleanest way to draw things, but it's fairly simple. There's a variety of samples on the XNA site too.
Post Reply