title: WPF 3D triangle overlap problem
body: <p>I'm rendering a scene with WPF 3D by making a MeshGeometry3D and adding vertices and normals to it.  Everything looks good in the rendered scene (lights are there, material looks fine), but where mesh triangles overlap, the triangle closer to the camera is not necessarily rendered on top.  It looks like they're being drawn in a random order.  Is there any way I can  ensure that the mesh triangles are rendered in the "correct" order?</p>
  
  <p>Just in case it helps, here's my XAML:</p>
  
  <pre><code>&lt;Viewport3D&gt;
      &lt;ModelVisual3D&gt;
          &lt;ModelVisual3D.Content&gt;
              &lt;Model3DGroup&gt;
                  &lt;AmbientLight Color="#FF5A5A5A" /&gt;
                  &lt;GeometryModel3D x:Name="geometryModel"&gt;
                      &lt;GeometryModel3D.Material&gt;
                           &lt;DiffuseMaterial Brush="DarkRed"/&gt;
                      &lt;/GeometryModel3D.Material&gt;
                  &lt;/GeometryModel3D&gt;
               &lt;/Model3DGroup&gt;
           &lt;/ModelVisual3D.Content&gt;
       &lt;/ModelVisual3D&gt;
   &lt;/Viewport3D&gt;
  </code></pre>
  
  <p>and in code, I'm generating the mesh something like this:</p>
  
  <pre><code>var mesh = new MeshGeometry3D();
  
  foreach (var item in objectsToTriangulate) {
      var triangles = item.Triangulate();
      foreach (var triangle in triangles) {
          mesh.Positions.Add(triangle.Vertices[0]);
          mesh.Positions.Add(triangle.Vertices[1]);
          mesh.Positions.Add(triangle.Vertices[2]);
          mesh.Normals.Add(triangle.Normal);
          mesh.Normals.Add(triangle.Normal);
          mesh.Normals.Add(triangle.Normal);
      }
  }
  
  geometryModel.Geometry = mesh;
  </code></pre>
  
  <p>EDIT: None of the triangles intersect (except at the edges), and sometimes the triangle that appears on top is actually WAY behind the other one, so I don't think it's an ambiguity with the 3D sorting of the triangles, as Ray Burns has suggested.</p>
  
  <p>The other behavior that I've noticed is that the order the triangles are rendered does not seem to change as I move around the scene.  I.e. if I view a problem area from the other side, the triangles are rendered in the same, now "correct", order.</p>