Ab3d.PowerToys beta 1 introduced

by abenedik 13. October 2009 23:13

The Ab3d.PowerToys library is a collection of classes and utilities that simplify programming with 3D in WPF. With Ab3d.PowerToys programming with 3D was never easier!

The following are the main parts of the library:

  • Cameras
  • Camera Controllers
  • Mouse Event Manager 3D

Ab3d.PowerToys Samples - Wind Generator sample

The library defines a few new Cameras that can be used instead of the current WPF's cameras. The main difference between Ab3d Cameras and WPF cameras is that Ab3d Cameras does not use Vectors to define the LookDirection, but instead use angles in degrees to define it. This is much more natural. For example if you want to look at the scene a little bit from the right and from above, you just define the Heading to be 30 and Attitude to be -45. You can also define the Distance from the scene. The most important Ab3d Cameras are: SceneCamera, FirstPersonCamera and ThirdPersonCamera. All the Ab3d Cameras with their properties can be seen on the class diagram.

Camera Controllers are used to control the camera. The MouseCameraController can be used to change the angle and distance of the camera with the mouse. This way it is very simple to rotate the camera around. The CameraControlPanel shows nice buttons to rotate the camera and move the camera closer or farther away. There is also a CameraPreviewPanel that graphically shows at which angle the camera is looking at the object or scene.

The following code demonstarates that with only a few lines of xaml a WPF application can use a camera that is showing the whole scene (SceneCamera) and can be rotated by the mouse (MouseCameraController) or by nice buttons (CameraControlPanel). There is also a preview of the camera that is showing from which angle the camera is looking at the scene. Also if the WindGeneratorModel model does not contain a light, a camera light is automatically added to the scene and it is iluminating the scene from the camera's position (ShowCameraLight="Auto").

<Window x:Class="Ab3d.PowerToys.Samples.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cameras="clr-namespace:Ab3d.Cameras;assembly=Ab3d.PowerToys"
xmlns:ab3d="clr-namespace:Ab3d.Controls;assembly=Ab3d.PowerToys">
  <Grid>
     <Viewport3D Name="MainViewport3D">
         <ModelVisual3D Content="{StaticResource WindGeneratorModel}"/>
     </Viewport3D>
     
     <cameras:SceneCamera Name="SceneCamera1"
                             Heading="30" 
                             Attitude="-30" 
                             Distance="3" IsDistancePercent="True"
                             IsDynamicTarget="True"
                             ShowCameraLight="Auto"/>
                          
     <ab3d:MouseCameraController TargetCameraName="SceneCamera1" 
                                    IsMouseWheelZoomEnabled="True"/>
                               
     <ab3d:CameraControlPanel TargetCameraName="SceneCamera1"
                                 VerticalAlignment="Bottom" 
                                 HorizontalAlignment="Left"/>
                              
     <ab3d:CameraPreviewPanel TargetCameraName="SceneCamera1" 
                                 Width="100" Height="100" 
                                 VerticalAlignment="Bottom" 
                                 HorizontalAlignment="Right"/>
  </Grid>
</Window>

 

The EventManager3D class is a helper class that enables user to simply subscribe to mouse events on 3D objects. The following mouse events are supported: MouseEnter, MouseLeave, MouseDown, MouseUp, MouseClick, BeginMouseDrag, MouseDrag, EndMouseDrag (MouseDoubleClick is not in available in beta). This way you do not need to do the complicated 3D hit testing any more. You can simply subscribe to mouse events. This way you the code is much simpler and better organized.

The following code shows a sample used of EventManager3D:

                    
EventSource3D eventSource;
EventManager3D eventManager;

eventManager = new EventManager3D(MainViewport);                                 


eventSource = new EventSource3D();
eventSource.TargetObject = myButton3D;
eventSource.MouseClick += new MouseButton3DEventHandler(myButton3D_MouseClick);

eventManager.RegisterEventSource3D(eventSource);                                 


eventSource = new EventSource3D();
eventSource.TargetObject = myMovableObject3D;
eventSource.BeginMouseDrag += new Mouse3DEventHandler(myMovableObject3D_BeginMouseDrag);
eventSource.MouseDrag += new MouseDrag3DEventHandler(myMovableObject3D_MouseDrag);
eventSource.EndMouseDrag += new Mouse3DEventHandler(myMovableObject3D_EndMouseDrag);

eventManager.RegisterEventSource3D(eventSource);                    

 

Beta notice:

The current version of Ab3d.PowerToys is in beta. That means that it is not yet features complete and not fully tested.

Roadmap:

  • Beta 1 - 13th October 2009
  • Beta 2 - end of October 2009
  • Release Candidate - middle of November 2009
  • Release - start of December 2009


The Ab3d.PowerToys beta 1 and the samples can be downloaded from my Downloads page.

Tags: , , , ,

Ab3d.PowerToys