|
Ab3d.PowerToys is the ultimate helper library for work with WPF 3D.
The main parts of the library are:
- Cameras (SceneCamera, FirstPersonCamera, ThirdPersonCamera, etc.)
- Camera Controllers (MouseCameraController, CameraControlPanel)
- 3D Models and Visuals (Sphere, Box, Cylinder, etc.)
- 3D Lines
- Event Manager 3D (simplified event handling on 3D objects)
Cameras, 3D Models and Lines can be defined in XAML. The results are immediately shown in Visual Studio Designer.
With Ab3d.PowerToys programming with 3D cannot be easier!

Cameras and Camera Controllers
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>
EventManager3D
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 and MouseDoubleClick. This way you do not need to do the
complicated 3D hit testing any more. The EventManager3D is also better than WPF's
ModelUIElement3D because it supports more mouse events (including mouse drag in
3D), provides better event data and preserves the structure of the 3D models. This
way your code is much simpler and better organized.
The following code shows a sample used of EventManager3D:
ModelEventSource3D eventSource;
EventManager3D eventManager;
eventManager = new ModelEventSource3D(MainViewport);
eventSource = new EventSource3D();
eventSource.TargetModel3D = myButton3D;
eventSource.MouseClick += new MouseButton3DEventHandler(myButton3D_MouseClick);
eventManager.RegisterEventSource3D(eventSource);
eventSource = new ModelEventSource3D();
eventSource.TargetModel3D = myMovableObject3D;
eventSource.BeginMouseDrag += new Mouse3DEventHandler(myMovableObject3D_BeginMouseDrag);
eventSource.MouseDrag += new MouseDrag3DEventHandler(myMovableObject3D_MouseDrag);
eventSource.EndMouseDrag += new Mouse3DEventHandler(myMovableObject3D_EndMouseDrag);
eventManager.RegisterEventSource3D(eventSource);
3D Models
The Ab3d.PowerToys library also contains classes to create basic 3D models in code
or XAML. It is possible to create Plane, Circle, Box, Pyramid, Sphere, Cone
and Cylinder 3D models.
The following XAML creates some of the 3D objects: WireGrid, 3D Sphere, 3D Box and 3D Cone. Note that the Sphere also has a ToolTip defined. Another interesting thing that is that the Materials are defined only by providing the name of the Color.
<Page x:Class="Ab3d.PowerToys.Samples.Objects3D.UIElementsToolTipSample"
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:visuals="clr-namespace:Ab3d.Visuals;assembly=Ab3d.PowerToys"
xmlns:uiElements="clr-namespace:Ab3d.UIElements;assembly=Ab3d.PowerToys">
<Grid>
<Viewport3D Name="MainViewport">
<visuals:WireGridVisual3D CenterPosition="0 0 0" Size="70 30"
WidthCellsCount="7" HeightCellsCount="3"
LineColor="Gray" LineThickness="2"/>
<uiElements:SphereUIElement3D CenterPosition="-20 5 0"
Radius="5"
Material="Green"
ToolTip="This is a simple tooltip"/>
<uiElements:BoxUIElement3D CenterPosition="20 5 0"
Size="10 10 10"
Material="Red"/>
<visuals:ConeVisual3D BottomCenterPosition="0 0 0"
BottomRadius="5" TopRadius="2"
Height="10" Segments="6"
IsSmooth="False" Material="Blue"/>
</Viewport3D>
<cameras:SceneCamera Heading="30" Attitude="-20" Bank="0"
Distance="100" ShowCameraLight="Always"/>
</Grid>
</Page>
The following image shows almost all the 3D objects that can be created with Ab3d.PowerToys. The image shows that the 3D objects are already visible at Design Time in Visual Studio.
There are also some Ab3d.PowerToys item in Toolbox (unfortunatlly it is not possible to show 3D objects in Toolbox). The Property Editor shows the properties for the currently selected ConeVisual3D.

The following image is taken from Sphere sample and shows the 3D sphere with drawn triangles and normals. The settings for the sphere are shown on the lower right part of the image.

3D Lines
There is also support for 3D Lines with optimized update mechanism
that make the 3D lines implementation the most advanced and with the best performance
for WPF.

History
To see the development history of Ab3d.PowerToys, check out the
related blog posts.
Important:
The Ab3d.PowerToys library is available as stand alone library.
It is also available for free with Ab3d.Reader3ds Pro license. This way you get a complete set of tools for WPF 3D.
Information about changes:
Subscribe to RSS feed to all Blog posts.
Follow me on twitter.
Subscribe to newsletter - enter your email into Newsletter box on my Blog.
|