I have a very simple 3D scene and want to rotate it with the mouse wheel. When using no cache mode at all, everything works fine. But my real application is showing more than just a single triangle so I was happy when I heard the about cache mode. It really speeds up the UI drastically but if I set the mode on the Viewport3D, the whole UI freezes for seconds (up to a minute) when the rotation reaches a certain value! Here's my code:
<Window x:Class="BitmapCacheProblem.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="850" Width="825"><Border x:Name="border"><Viewport3D x:Name="viewport"><Viewport3D.Camera><PerspectiveCamera Position="0,-9,3" LookDirection="0,9,-3" UpDirection="0,0,1"/></Viewport3D.Camera><ModelVisual3D x:Name="world"><ModelVisual3D.Content><Model3DGroup><GeometryModel3D><GeometryModel3D.Geometry><MeshGeometry3D Positions="0 0 0, 10 0 0, 0 10 0" TriangleIndices="0 1 2"/></GeometryModel3D.Geometry><GeometryModel3D.Material><DiffuseMaterial Brush="Green"/></GeometryModel3D.Material></GeometryModel3D><AmbientLight Color="Gray"/><DirectionalLight Color="White" Direction="0,1,-1" /></Model3DGroup></ModelVisual3D.Content></ModelVisual3D></Viewport3D></Border></Window>
public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); viewport.CacheMode = new BitmapCache(); } protected override void OnMouseWheel(MouseWheelEventArgs e) { double angle = e.Delta < 0 ? -10 : 10; Vector3D axis = new Vector3D(0, 0, 1); Point3D center = new Point3D(0, 0, 0); Matrix3D m = world.Transform.Value; m.RotateAt(new Quaternion(axis, angle), center); world.Transform = new MatrixTransform3D(m); } }
Setting the cache mode on the border instead does not freeze the UI. So is this a bug or just a lack of information?
Cheers,
Forester