title: WPF 3D performance
body: <p>I want to draw a cloud of point, searching the internet showing that there isn't point in 3D and I need to draw cubes.</p>
  
  <p>So I tried to add to a viewPort3D 50,000 cubes and it just taking a lot of time (~ 5 minutes) </p>
  
  <p>Is there any trick I can do on this code to get better performance ?</p>
  
  <p>this is my code : </p>
  
  <pre><code> public partial class MainWindow : Window
  {
      private Int32Collection _indices;
      DiffuseMaterial _diffuseMaterial = new DiffuseMaterial(Brushes.Gray);
  
      public MainWindow()
      {
          Int32CollectionConverter icc = new Int32CollectionConverter();
          _indices = (Int32Collection)icc.ConvertFromString(@"
                                    3,2,4 2,7,4 
                                    2,1,7 7,1,6
                                    4,7,5 5,7,6
                                    0,3,4 0,4,5
                                    1,0,5 1,5,6
                                    1,2,3 1,3,0      
                                   ");
  
  
          InitializeComponent();
  
          Stopwatch stopwatch = new Stopwatch();
          stopwatch.Start();
  
          for (int i = 0; i &lt; 50000; i++)
          {
              AddFeature(1, i, 1);
          }
  
          stopwatch.Stop();
          Console.WriteLine(stopwatch.Elapsed.TotalSeconds + "sec");
      }
  
      private void AddFeature(double x, double y, double z, double size = 1)
      {
          GeometryModel3D geometryModel3D = new GeometryModel3D();
          MeshGeometry3D model = new MeshGeometry3D();
  
          model.Positions.Add(new Point3D(-size + x, -size + y, -size + z));
          model.Positions.Add(new Point3D(size + x, -size + y, -size + z));
          model.Positions.Add(new Point3D(size + x, -size + y, size + z));
          model.Positions.Add(new Point3D(-size + x, -size + y, size + z));
          model.Positions.Add(new Point3D(-size + x, size + y, size + z));
          model.Positions.Add(new Point3D(-size + x, size + y, -size + z));
          model.Positions.Add(new Point3D(size + x, size + y, -size + z));
          model.Positions.Add(new Point3D(size + x, size + y, size + z));
  
          model.TriangleIndices = _indices;
          geometryModel3D.Material = _diffuseMaterial;
          geometryModel3D.Geometry = model;
          model3DGroup.Children.Add(geometryModel3D);
      }
  
  }
  </code></pre>
  
  <p>XAML:</p>
  
  <pre><code>&lt;Window x:Class="WpfApplication4.MainWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Title="MainWindow" Height="350" Width="525"&gt;
  &lt;Grid&gt;
      &lt;Viewport3D x:Name="Viewport3D" Margin="4,4,4,4" Grid.Row="0" Grid.Column="0" ClipToBounds="False" IsHitTestVisible="False"&gt;
          &lt;ModelVisual3D&gt;
              &lt;ModelVisual3D.Content&gt;
                  &lt;Model3DGroup x:Name="model3DGroup"&gt;
                      &lt;!-- Lights --&gt;
                      &lt;AmbientLight Color="Gray"/&gt;
                      &lt;DirectionalLight Color="Gray" Direction="1,-2,-3" /&gt;
                      &lt;DirectionalLight Color="Gray" Direction="-1,2,3" /&gt;
                  &lt;/Model3DGroup&gt;
              &lt;/ModelVisual3D.Content&gt;
          &lt;/ModelVisual3D&gt;
  
          &lt;Viewport3D.Camera&gt;
              &lt;PerspectiveCamera 
                Position = "2, 4, 6"
                LookDirection = "-1, -2, -3"
                UpDirection = "0, 1, 0"
                FieldOfView = "60"&gt;
                  &lt;PerspectiveCamera.Transform&gt;
                      &lt;Transform3DGroup&gt;
                          &lt;ScaleTransform3D x:Name="scaleTransform3D" CenterX="0" CenterY="0" CenterZ="0" /&gt;
                          &lt;RotateTransform3D&gt;
                              &lt;RotateTransform3D.Rotation&gt;
                                  &lt;AxisAngleRotation3D x:Name="axisAngleRotate1"
                                    Axis="0 1 0" 
                                     /&gt;
                              &lt;/RotateTransform3D.Rotation&gt;
                          &lt;/RotateTransform3D&gt;
                          &lt;RotateTransform3D&gt;
                              &lt;RotateTransform3D.Rotation&gt;
                                  &lt;AxisAngleRotation3D x:Name="axisAngleRotate2"
                                    Axis="1 0 0" 
                                     /&gt;
                              &lt;/RotateTransform3D.Rotation&gt;
                          &lt;/RotateTransform3D&gt;
                      &lt;/Transform3DGroup&gt;
                  &lt;/PerspectiveCamera.Transform&gt;
              &lt;/PerspectiveCamera&gt;
          &lt;/Viewport3D.Camera&gt;
      &lt;/Viewport3D&gt;
  
  
  &lt;/Grid&gt;
  </code></pre>
  
  <p></p>