Page 1 of 1

MobileMesh Model anomaly

Posted: Sun Nov 03, 2013 10:14 pm
by Jack Burton
Hi I have a problem with a model I have been using as it seems to be missing some of the mesh when I draw it to the game window. The model on the right is drawn as you would normally, while the model on the left that is missing part of the mesh is drawn using Bepu's MobileMesh.

Has anyone seen this before? or can anyone suggest a way to resolve it.

Image Image

Code to draw Ship missing mesh parts

Code: Select all

//==============================Player Ship=============================================
            Vector3[] ShipVertices;
            int[] ShipIndices;
            //Create a big hollow sphere (squished into an ellipsoid).
            TriangleMesh.GetVerticesAndIndicesFromModel(Content.Load<Model>("Models/Ship"), out ShipVertices, out ShipIndices);
            var transform = new AffineTransform(new Vector3(.0005f, .0005f, .0005f), Quaternion.Identity, new Vector3(0, 0, 0));

            //Note that meshes can also be made solid (MobileMeshSolidity.Solid).  This gives meshes a solid collidable volume, instead of just
            //being thin shells.  However, enabling solidity is more expensive.
            shipMesh = new MobileMesh(ShipVertices, ShipIndices, transform, MobileMeshSolidity.Counterclockwise);
            shipMesh.Position = new Vector3(1, 0, 0);            
            space.Add(shipMesh);
            //ModelDrawer.Add(shipMesh);           
            //========================================================================================            
Draw Method

Code: Select all

protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            //RasterizerState rasterizerState = new RasterizerState();
            //rasterizerState.FillMode = FillMode.WireFrame;
            //GraphicsDevice.RasterizerState = rasterizerState;

            // TODO: Add your drawing code here
            DrawModels(shipModel, Matrix.CreateScale(0.0005f));

            DrawMobileModels(shipModel, shipMesh);

            //ModelDrawer.Draw(Camera.ViewMatrix, Camera.ProjectionMatrix);

            
            base.Draw(gameTime);
        }
Method to draw mesh plus graphic

Code: Select all

void DrawMobileModels(Model M, MobileMesh MM)
        {
            Matrix a = M.Bones[0].Transform;//note that model contents a single mesh
            a *= Matrix.CreateFromQuaternion(MM.Orientation) * Matrix.CreateScale(0.0005f);
            a.Translation = MM.Position;
            BasicEffect B = M.Meshes[0].Effects[0] as BasicEffect;
            B.Projection = Camera.ProjectionMatrix;
            B.View = Camera.ViewMatrix;
            B.World = a;
            M.Meshes[0].Draw();
        }


Re: MobileMesh Model anomaly

Posted: Mon Nov 04, 2013 12:52 am
by Norbo
The physics simulation is completely separate from, and blind to, graphics. The fact that a MobileMesh is being used should have no bearing on whether or not bits of a graphical model are visible.

My guess is that the model actually has multiple meshes in it. The draw method only draws one.

By the way, it's a good idea to use simple shapes to represent your objects. A simple convex primitive (box, sphere...), a simplified convex hull, or maybe a few such shapes put together into a compound shape would tend to be much more efficient than a MobileMesh.

Re: MobileMesh Model anomaly

Posted: Tue Nov 05, 2013 1:39 am
by Jack Burton
Thanks Norbo

I cleaned up the code a little and the problem fixed itself I have no Idea what was causing it to display incorrectly so cannot offer a solution.
I did however take you advice and change form a MobileMesh to a box primitive for collision

thanks