Sign in to follow this  

Mesh drawing problem

This topic is 3840 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all!, I've some problems for drawing textured mesh with DirectX / C#, here is a shot: Free Image Hosting at www.ImageShack.us And the drawing code:
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{

      device.Clear(ClearFlags.Target, Color.DarkSlateBlue , 1.0f, 0);

      device.Transform.World =  Matrix.Translation(new Vector3(5,5,-65) * Matrix.Scaling(2,2,2);
    device.RenderState.Lighting = false;

      device.BeginScene();

      this.DrawMesh(spacemesh, spacemeshmaterials, spacemeshtextures);
          
      device.EndScene();
 
      device.Present();
  
      this.Invalidate();
}
the mesh load/draw code:
private void LoadMesh(string filename, ref Microsoft.DirectX.Direct3D.Mesh mesh, ref Material[] meshmaterials, ref Texture[] meshtextures, ref float meshradius)
     {
             ExtendedMaterial[] materialarray;
             mesh = Mesh.FromFile(filename, MeshFlags.Managed, device, out materialarray);
 
             if ((materialarray != null) && (materialarray.Length > 0))
             {
                 meshmaterials = new Material[materialarray.Length];
                 meshtextures = new Texture[materialarray.Length];
 
                 for (int i = 0; i < materialarray.Length; i++)
                 {
                     meshmaterials[i] = materialarray[i].Material3D;
                     meshmaterials[i].Ambient = meshmaterials[i].Diffuse;
 
                     if ((materialarray[i].TextureFilename != null) && (materialarray[i].TextureFilename != string.Empty))
                     {
                     
                     	meshtextures[i] = TextureLoader.FromFile(device, materialarray[i].TextureFilename.Replace(".GIF",".jpg"));
                     }
                 }                
             }
 
             mesh = mesh.Clone(mesh.Options.Value, CustomVertex.PositionNormalTextured.Format, device);
             mesh.ComputeNormals();
 
             VertexBuffer vertices = mesh.VertexBuffer;
             GraphicsStream stream = vertices.Lock(0, 0, LockFlags.None);
             Vector3 meshcenter;
             meshradius = Geometry.ComputeBoundingSphere(stream, mesh.NumberVertices, mesh.VertexFormat, out meshcenter) * scaling;
             vertices.Unlock();
         }
 
         private void LoadMeshes()
         {        
             LoadMesh("racer.x", ref spacemesh, ref spacemeshmaterials, ref spacemeshtextures, ref spacemeshradius);
         }
         
         private void DrawMesh(Mesh mesh, Material[] meshmaterials, Texture[] meshtextures)
         {
             for (int i = 0; i < meshmaterials.Length; i++)
             {
                 device.Material = meshmaterials[i];
                 device.SetTexture(0, meshtextures[i]);
                 mesh.DrawSubset(i);
             }
         }
and the car should be like this: I need your help :)! Thanks EDIT: Please remember to use 'source' tags in future... [Edited by - jollyjeffers on June 9, 2007 4:42:41 PM]

Share this post


Link to post
Share on other sites
device.Clear(ClearFlags.Target, Color.DarkSlateBlue , 1.0f, 0);

This line does not clear the depth buffer, is this intentional? Have you configured one? Your screenshot looks like the results of no/incorrect depth buffering. Simply set it up (or reinstate the clear operation) and you should be sorted [smile]


hth
Jack

Share this post


Link to post
Share on other sites

This topic is 3840 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this