question

Dragon-2509 avatar image
0 Votes"
Dragon-2509 asked ·

How to increase WPF 3D Performance?

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);
                 positions.Add(point);
    
                 if (z < length - 1 &&
                     x < width - 1)
                 {
                     ind1 = x + z * width;
                     ind2 = ind1 + width;
    
                     //first triangle
                     triangleIndices.Add(ind1);
                     triangleIndices.Add(ind2);
                     triangleIndices.Add(ind2 + 1);
    
                     //second triangle
                     triangleIndices.Add(ind1);
                     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">
             <Viewport3D.Camera>
                 <PerspectiveCamera x:Name="MainPerspectiveCamera" FieldOfView="35" />
             </Viewport3D.Camera>
             <ModelVisual3D>
                 <ModelVisual3D.Content>
                     <Model3DGroup x:Name="MainModel3DGroup">
                     </Model3DGroup>
                 </ModelVisual3D.Content>
             </ModelVisual3D>
         </Viewport3D>
     </Grid>


Thank you.



windows-wpf
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

AlexLi-MSFT avatar image
0 Votes"
AlexLi-MSFT answered ·

Welcome to our Microsoft Q&A platform!

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


Thanks.

· 1 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Dear @AlexLi-MSFT

I have read the link you provided before. But I think my problem is that it has too many triangles, I think it's about 1.5 million triangles. I see people suggesting mesh reduction. But I do not know how in WPF yet? Can you help me?

Thank you so much.

0 Votes 0 ·