How to increase WPF 3D Performance?

Dragon 81 Reputation points

I have a problem looking forward to your suggestions about WPF 3D performance. It runs quite well with a small width and length, but with a width and length of about 949x825 When measured by stopwatch, all of the implementation in c# code only takes about 0.6 seconds, but it takes about 6 seconds for it to display 3D images in screen and when using the mouse to zoom or rotate the 3D image it is very slow. Is there any way to increase performance?

Code in C#:

// **Test with width = 949 and length = 825. It's very slow**
        // Make a mesh to hold the surface.
        MeshGeometry3D mesh = new MeshGeometry3D();
        Int32Collection triangleIndices = new Int32Collection();
        Point3DCollection positions = new Point3DCollection();

        //defining point and triangles
        int ind1 = 0;
        int ind2 = 0;

        for (var z = 0; z < length; z++)
            for (var x = 0; x < width; x++)
                var point = new Point3D(x, map[z, x] * ImageConstants.YScale, z);

                if (z < length - 1 &&
                    x < width - 1)
                    ind1 = x + z * width;
                    ind2 = ind1 + width;

                    //first triangle
                    triangleIndices.Add(ind2 + 1);

                    //second triangle
                    triangleIndices.Add(ind2 + 1);
                    triangleIndices.Add(ind1 + 1);

        mesh.Positions = positions;
        mesh.TriangleIndices = triangleIndices;

In Xaml:

<Grid Name="mainGrid" Background="Black" MouseWheel="OnMouseWheel" MouseDown="OnMouseDown">
        <Viewport3D Name="MainViewport3D">
                <PerspectiveCamera x:Name="MainPerspectiveCamera" FieldOfView="35" />
                    <Model3DGroup x:Name="MainModel3DGroup">

Thank you.

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,196 questions
No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Alex Li-MSFT 1,081 Reputation points

    Welcome to our Microsoft Q&A platform!

    You can see the following link about Maximize WPF 3D Performance