Ab3d.DXEngine maintenance update available

by abenedik 15. March 2016 10:51

I would like to inform you that a smaller maintenance update for Ab3d.DXEngine has been published.

The update does not add new functionality to the rendering engine. It improves the performance of the engine and fixes a few issues.

The following is a list of changes:

  • Greatly improved performance of WireframeVisual3D when the 3D objects showing with WireframeVisual3D are animated with changing transformations.
  • Prevented black edges that sometimes appeared when showing textures.
  • Fixed rendering transparent objects that were not visible sometimes because of incorrect object order.
  • Fixed rendering specular highlight for directional light shader.
  • Fixed getting camera's view and projection matrices for left handed coordinate system (when IsRightHandedCoordinateSystem is false).

Tags: , ,

DXEngine

Rendering reflections and many other great new features with new versions of Ab3d.DXEngine and Ab3d.PowerToys

by abenedik 11. February 2016 23:01

The new version of Ab3d.DXEngine brings three big new features:

  1. Added support for rendering reflections with environmental and reflection maps.
  2. Added support for rendering unlimited number of lights with using multi-pass rendering.
  3. Improved rendering instanced objects with adding support for rendering many instances of Model3DGroup objects. Simplified hit testing on instanced objects with a new GetHitInstanceIndex method.

Rendering DirectX reflection in .Net with Ab3d.DXEngine

 

The Ab3d.PowerToys library also got some great new features. Some of the main new features are:

  1. Added ModelRotatorVisual3D that allows users to rotate selected 3D model. Improved ModelMoverVisual3D so that it also works in Ab3d.DXEngine.
  2. Greatly reduced the initialization time when creating many instances of SphereVisual3D and BoxVisual3D objects.
  3. Simplified working with hierarchically organized 3D models with new model iterators.

Rotating 3D models with ModelRotatorVisual3D

Let’s see some more details about the new features.</p> <p>Showing reflections pushes the boundaries of what is possible to achieve with WPF 3D API even further. The above image with reflective teapot shows a fully reflective 3D model. The level of reflection can be adjusted and specified for the whole object. Or, it can be specified for each part of the model with using a reflection map. The following image shows that is action (the reflection map is shown on the right):

Using DirectX ReflectionMap to specify reflection for each part of the 3D model


The handle and top of the teapot are shown with green color (specified in the teapot’s texture on the bottom image) and do not reflect the environment – those parts are almost black on the reflection map (upper image). But the rest of the teapot is fully reflective – defined by white color on the reflection map (in the bottom 1/3 of the image and on the smaller white rectangle on the right side).

To support scenarios where additional DXEngine properties need to be added to the existing WPF objects, the new version of Ab3d.DXEngine introduces a new set of extensions methods that allow adding additional attributes to WPF objects. 

For example the following two lines set EnvironmantMap and ReflectionMap to an existing WPF material:

usedMaterial.SetDXAttribute(DXAttributeType.Material_EnvironmentMap, _dxCubeMap);
usedMaterial.SetDXAttribute(DXAttributeType.Material_ReflectionMap, bitmapImage);

The new version of Ab3d.DXEngine also adds support to render unlimited number of lights. Previous version supported rendering only 16 lights + ambient light. This limit is now lifted with using multi-pass rendering. This means that when there are more than 16 lights in the scene it is rendered multiple times – each time different 16 lights are used and then all the rendered scenes are combined into the final image. The following screenshot shows a sample that animates the intensity of 64 PointLights:

Rendering many lights with using multiple-pass rendering

Multi-pass rendering is great for such scenarios. But it also has some disadvantages. If you need to use many lights, please check the additional comments in the “Many lights” sample.

 

I would also like to write a few words about new object instancing capabilities.

Object instancing is the ultimate performance optimization – if you show really many 3D objects and you convert your code to use object instancing than you have almost reached the peak of the performance. Some additional performance gains are still possible with tweaking the shaders, but most of the work was already done.

The trick is that when object instancing is used, the applications sends one mesh geometry to the graphics card and then tells it to render it many times – for each instance of the mesh you can specify different color and different transformation. Because the data about all the instances is send in one draw call, this can be done very quickly on the CPU. So the usual performance problem where GPU waits for the CPU to send commands is completely eliminated. 

Because instancing is so great for improving performance, the new version also allows you to render many instances of Model3DGroup objects (and not only many instances of MeshGeometry3D). The following screenshot shows many instances of RobotArm model:

Rendering many instances of Model3DGroup

Another improvement with instancing is that a GetHitInstanceIndex method was added to the InstanceData class. That method can be used in hit testing to get the index of the hit instance. This way you can easily connect the hit object with the background data that are connected to the hit instance.

If you are rendering many 3D objects, I would really advice you to try to convert your code to use instancing. You will be amazed on how fast the graphics cards can become when they are not waiting for the CPU (a newer graphics card recommended).

 

There are still lots of other new features and fixes. Also Ab3d.PowerToys library has been greatly improved.

But I do not want to make this blog post too long. 

To check new features in action, please check the new samples that come with the libraries. And for the record here are the full list of changes:

 

Ab3d.DXEngine v1.2:

  • Added support for rendering reflections with using EnvironmentalMaps
  • Added support for ReflectionMaps
  • Added support for rendering more than 16 lights (+ ambient light) with using multi-pass rendering.
  • Added support for Transform on InstancedMeshGeometryVisual3D
  • Added InstancedModelGroupVisual3D that can render many instances of all 3D models defined in the Model3DGroup.
  • Added GetHitInstanceIndex method to InstanceData to get an index of hit instance
  • Fixed showing transparent objects in some cases
  • Added TextureBlendState to IDiffuseTextureMaterial interface
  • Fixed rendering textures from files that use different DPI settings
  • Added extension methods that simplify adding additional DXEngine attributes to the existing WPF's objects (SetDXAttribute, GetDXAttributeCollection, GetDXAttribute, IsDXAttributeSet, ClearDXAttribute, GetDXAttributeOrDefault). This is currently used to specify the EnvironmentalMap and ReflectionMap.
  • Prevented memory leak when 3D model that was shown inside WireframeVisual3D was changed (further performance improvements in this case will follow).
  • Prevented rendering strange 3D lines that sometimes occur when the 3D lines were completely behind the camera
  • Fixed rendering transparent 3D lines
  • Fixed rendering transparent objects with emissive materials
  • Some other smaller bug fixes and improvements

BREAKING CHANGE:
The InstancedGeometryVisual3D was renamed into InstancedMeshGeometryVisual3D – the renaming was needed because a new InstancedModelGroupVisual3D was introduced and the previous name did not describe the class well enough.

 

Ab3d.PowerToys v7.4:

  • Added ModelRotatorVisual3D that allows user to rotate selected Model3D around any axes.
  • Added SubscribeWithEventManager3D method to ModelMoverVisual3D and ModelRotatorVisual3D to allow them to use EventManager3D for processing mouse events. This allows using the ModelMoverVisual3D and ModelRotatorVisual3D in Ab3d.DXEngine.
  • Greatly reduced the initialization time when creating many instances of SphereVisual3D or BoxVisual3D objects
  • Added ModelIterator class and two extension methods (ForEachVisual3D and ForEachGeometryModel3D) to simplify working with hierarchacly organized 3D models.
  • Added FitIntoView and GetFitIntoViewDistanceOrCameraWidth methods to TargetPositionCamera, SceneCamera, TargetRect3DCamera and ThirdPersonCamera. The method has greatly improved algorithm then it was available in the "Scene Editor" sample in the previous versions of Ab3d.PowerToys.
  • Fixed showing transparent 3D lines when LineColor's alpha value is less than 255.
  • Improved support for TextureCoordinates in ModelOptimizer
  • Added WidthDirection and HeightDirection to WireGridVisual3D that allows to set custom direction of the WireGrid (not only horizontal or horizontal in another coordinate system)
  • Added CreateWireGrid to Line3DFactory that allows creating WireGrid object with custom widthDirection and heightDirection vectors.
  • Added GetTargetViewport3DSceneBounds method to all Camera classes in Ab3d.PowerToys – the method calculates the scene bounding box
  • Change validation of Size property on BoxVisual3D, WireBoxVisual3D, MultiMaterialBoxVisual3D and PyramidVisual3D to allow having one component of size zero.
  • Fixed calculating scene size in SceneCamera when the scene hierarchy is complex
  • Added GetBounds and CombineTransform methods to Ab3d.Utilities.ModelUtils
  • Added CompositionRenderingHelper to help work with CompositionTarget.Rendering (allowing subscribed objects to be recycled by Garbage Collection and therefore preventing infinite rendering subscription in case when the Rendering is not unsubscribed)
  • Improved ModelMoverVisual3D so that it can also use EventManager3D for mouse event processing - this allows using ModelMoverVisual3D inside Ab3d.DXEngine.
  • Prevented throwing "Object reference" exception in ModelOptimiter that could occur sometimes when ImageBrush is used.
  • Added HeightDirection to TubeVisual3D and TubeMesh3D – this allows orienting the object in any direction and not only in up (0, 1, 0) direction.
  • Fixed throwing exception when Is3DAxesShown is initially set to false on CameraAxisPanel
  • Added "Custom Up Axis" sample that shows how to show data in another coordinate system - for example where Z is up.
  • Added "Perspective Transformation" sample that shows how to convert 3D positions to the 2D positions on the screen

BREAKING CHANGE:
Moved the ModelMovedEventArgs class from Ab3d.PowerToys.Common to Ab3d.Common namespace

Tags: , , , , ,

Ab3d.PowerToys | DXEngine

Greatly improved performance, new features and a new real-time HLSL shader editor come with new versions of Ab3d.DXEngine and Ab3d.PowerToys

by abenedik 3. December 2015 23:01

New versions of Ab3d.DXEngine and Ab3d.PowerToys libraries have been published.

The new versions bring improved performance, new features and many bug fixes. 

But let me talk about that later and start with a very interesting new sample that comes with Ab3d.DXEngine – a real-time HLSL shader editor. The following screenshot shows it in action:

Real-time shader editor in Ab3d.DXEngine

On the left side you can see the HLSL editor with full syntax highlighting. The editor is using great AvalonEdit component. The right side shows some options and a real-time preview of the 3D scene and used shader.

The real-time preview means that after each change of HLSL text, the HLSL text is compiled and the new shaders are used to render the preview image on the right.

The opened ComboBox shows that the editor comes with 6 shaders that can be used as a simple step by step HLSL tutorial. The first sample shows how to render all objects with a single color (you can experiment with changing the color components). The following effects add some interesting coloring. And the final shader shows how to create a shader with directional light lighting and with added fog.

So, if you have not tried to program in HLSL, this is your best and easiest chance to try it out.

And if you want to change the 3D scene, you can just open the XAML editor and change the 3D objects defined there.

 

And there are more great news. 

The new version of Ab3d.DXEngine has significantly better performance. In some cases (for example where many BoxVisual3D or similar objects are shown) the frame rate can be 3 times the previous frame rate. And already the previous version had some impressive performance. Also the time spend in the Update method is greatly reduced.

Also the problems with hardware accelerated 3D lines are now fixed. Because of some problems in the production version preparation, the previous version of Ab3d.DXEngine in many cases did not render the 3D lines with full hardware acceleration.

The biggest performance improvement in Ab3d.DXEngine can be achieved with using object instancing – rendering many instances of the same mesh. The performance is really amazing the following screenshot is showing 16.000 bunnies (each bummy model has 11.553 position) rendered at aroud 20 FPS (on i7 6700 and NVIDIA 970 GTX). Note that statistics in the lower right corner is showing that 184.848.000 positions are rendered:

Instancing in Ab3d.DXEngine

The problem with instancing in the previous version was that it did not support hit testing. This has been improved in the new version. Now you can set the IsWpfHitTestVisible property on InstancedGeometryVisual3D to true and hit testing (also the EventsManager3D from Ab3d.PowerToys) will begin to work. Though this will increase the initialization time because WPF objects need to be created before WPF hit testing can work. 

The new version also adds support for Binding on objects inside DXViewportView. For example, now you can bind IsVisible property on ModelVisual3D objects to CheckBox.IsChecked property.

The following is the full list of changes and improvements:

  • Fixed using Binding on objects inside DXViewportView.
  • Fixed rendering 3D lines with hardware accelerating geometry shader (instead of Ab3d.PowerToys's LinesUpdater).
  • Improved support for transformations on TileBrush (used on ImageBrush, VisualBrush and DrawingBrush).
  • Added IsWpfHitTestVisible to InstancedGeometryVisual3D - this allows WPF hit testing of instanced geometry (though this increased initialization time because WPF's GeometryModel3D objects needs to be created).
  • Improved InstancedGeometryVisual3D so that it is not needed any more to call Update method when the InstancesData is set for the first time. Also fixed problems when the objects were not shown if Update was called before the InstancedGeometryVisual3D was added to Visual tree.
  • Improved performance with moving some matrix calculations to vertex shader.
  • Added support for rendering WPF's UIElement3D objects. NOTE: WpfUIElement3DNode can only show 3D models but does not support the input events on the UIElement3D (MouseEnter, MouseMove, etc.). Those events cannot be supported because Viewport3D control is not visible and does not provide the events to the UIElement3D.
  • Greatly improved Update method call performance when many Visual3D objects from Ab3d.PowerToys are used (for example BoxVisual3D objects).
  • Added IsCheckingChildrenForChanges field to WpfModelVisual3DNode that can be used to skip checking ModelVisual3D's Childen collection and improve Update performance.
  • Added IsCheckingChildrenForChangesDefaultValue static field to WpfModelVisual3DNode - used to set the default value of the IsCheckingChildrenForChanges field.
  • Fixed problems where wrong image was shown when multiple DrawingImage brushes or VisualBrshes were used.
  • Prevented throwing exception when unsupported type of Visual3D (for example UIElement3D) or Model3D was used in the scene.
  • Added Refresh method to Ab3d.DirectX.Material and its derived classes. This allows user to manually update the materials properties and its resources (textures are regenerated).
  • Fixed hit testing on some Viewport3D objects (usually when the Viewport3D was removed from visual tree and then added to DXViewportView).
  • Fixed using IsAutomaticallyUpdatingDXScene when the DXScene was created after the IsAutomaticallyUpdatingDXScene property was set.

 

The Ab3d.PowerToys library also got some fixes. The following is a full list of changes:

  • Fixed showing 3D lines that were created with IsVisible property set to false. When later the IsVisible is set to true, sometimes the 3D lines were not shown.
  • Fixed rendering 3D lines with arrows that were not rendered correctly under some circumstances.
  • Fixed reporting MouseLeave event that was sometimes not triggered when CustomEventsSourceElement was used.
  • Fixed changing BoxVisual3D and SphereVisual3D objects after Position is changed under some circumstances.
  • Added GetCameraMatrixes to BaseCamera that can calculate view and projection camera even if TargetViewport3D is not assigned to the camera.
  • Prevented throwing null reference exception in Dumper.Dump method when TextureCoordinates or Normals collection was null.
  • Prevented throwing null reference exception that could sometimes occur in MouseCameraControllerInfo when in XAML designer.

 

The wrapper for assimp importer was also improved. The new library should read some models more correctly (especially models from fbx files). Also, the AssimpWpfImporter class now supports IDisposable interface. This means that it can be now easily disposed to release all managed and unmanaged resources. The following is list of all the changes in this library:

  • AssimpWpfImporter now implements IDisposable and have new Dispose method to easily dispose all managed and unmanaged resources.
  • Improved reading transformations - in case the transformation matrix is identity, the Transform property is set to null; in case the matrix is a simple translation, a TranslateTransform3D is created; in case of simple scale a ScaleTransform3D is created; otherwise a MatrixTransform3D is created.
  • Improved reading 3D models that are stored in left coordinate system.
  • Added ForceConvertToRightHandedCoordinateSystem property to AssimpWpfImporter and AssimpWpfConverter.

 

I hope that you share the excitement of the new versions with me. And I promise to bring you more great news in the future versions.

Tags: , , , ,

Ab3d.PowerToys | DXEngine

The best platform for business applications that require 3D graphics

by abenedik 11. September 2012 23:18

In the blog posts that were posted so far I was mostly describing new versions of the products. During recent vacation at seaside I have decided to change that and prepare blog posts that would present some of the features of Ab3d.PowerToys and Ab3d.Reader3ds libraries.

I would also like to persuade you that WPF 3D with Ab3d.PowerToys and Ab3d.Reader3ds libraries is the best platform for building business applications that require 3D graphics.


Ab3d.PowerToys library greatly simplifies work with WPF 3D and make WPF 3D the easiest platform for business applications that require 3D graphics.

In this blog post I will try to write about some of the basic new concepts that are introduced with the library.

Plot 3D sample

This post is divided into the following sections:

  1. Basic 3D scene setup
  2. Cameras
  3. 3D Objects
  4. Showing objects from 3ds files
  5. Conclusion

 

1) Basic 3D scene setup

This section shows how to prepare an XAML file to show 3D content.
First we need to add a reference to the Ab3d.PowerToys library. Then the following namespace declarations are usually added to the XAML file:

xmlns:cameras="clr-namespace:Ab3d.Cameras;assembly=Ab3d.PowerToys"
xmlns:controls="clr-namespace:Ab3d.Controls;assembly=Ab3d.PowerToys"  
xmlns:visuals="clr-namespace:Ab3d.Visuals;assembly=Ab3d.PowerToys"

cameras namespace defines the possible cameras (SceneCamera, FirstPersonCamera, ThirdPersonCamera, etc.)

controls namespace defines controls that will be used to control the camera (MouseCameraController, CameraControlPanel).

visuals namespace defines 3D objects that can be added to Viewport3D (BoxVisual3D, SphereVisual3D, ConeVisual3D, LineVisual3D, WireBoxVisual3D, HeightMapVisual3D and many more).


Now we can define our 3D scene with the following XAML:

<Border Name="ViewportBorder" Background="Transparent">
    <Viewport3D Name="MainViewport">
    </Viewport3D>
</Border>

<cameras:SceneCamera Name="Camera1" Heading="40" Attitude="-20" Bank="0" 
                     Distance="250" ShowCameraLight="Always"
                     TargetViewport3D="{Binding ElementName=MainViewport}"/>

<controls:CameraControlPanel VerticalAlignment="Bottom" HorizontalAlignment="Left" 
                             Margin="5" Width="225" Height="75" 
                             ShowMoveButtons="True"
                             TargetCamera="{Binding ElementName=Camera1}"/>

<controls:MouseCameraController UsedMouseButton="Left" 
                                TargetCamera="{Binding ElementName=Camera1}"
                                EventsSourceElement="{Binding ElementName=ViewportBorder}"/>

<controls:CameraAxisPanel HorizontalAlignment="Right" VerticalAlignment="Bottom" />

First we defined a Border that contains an empty Viewport3D control. Then we added SceneCamera, CameraControlPanel (shows buttons to control the camera), MouseCameraController (use mouse to control the camera) and CameraAxisPanel (shows the orientation of the coordinate axes).


An interesting difference from standard WPF’s way is that the camera is not defined inside Viewport3D but outside it as a standard control. The reason for that is that all WPF’s cameras are sealed or contain internal virtual methods that cannot be defined in derived class. Therefore it is not possible to derive custom cameras from any WPF’s camera.

Before describing the cameras let me first describe how the added controls are connected to each other.

First we need to connect our SceneCamera to the Viewport3D. The connected Viewport3D will be controlled by our SceneCamera. This can be done with setting the TargetViewport3D property on SceneCamera. Using that property and simple binding is the most efficient way to connect the camera to the Viewport3D. But it is not the only possible way to do it. Instead it would be also possible to set TargetViewport3DName property to “Camera1”. It would be even possible to skip both that properties. In that case the camera would check the WPF controls tree and connect to the first found Viewport3D. Because the code where the TargetViewport3D property is set with binding is executed slightly faster that other methods, it is recommended to use it. But when there are only a few controls defined in the parent Window or UserControl, it is also ok to skip the TargetViewport3D definition and let the camera to connect automatically. In case when you want to connect the camera to the Viewport3D later in code and do not define TargetViewport3D and TargetViewport3DName in XAML, you can set the IsAutoViewport3DFindingEnabled to false to prevent the automatic camera connection.

In a similar way the CameraControlPanel and the MouseCameraController are connected to the SceneCamera. As with the camera we could use TargetCameraName property or skip the TragetCamera property and leave the control to find the Camera automatically by searching the objects tree.

The MouseCameraController is also connected to the ViewportBorder element. The connection is created with the EventsSourceElement property. This property defines which element is used as the source of mouse events that are used to control the camera. Because this element has a transparent background, the mouse events are triggered on the whole area of the border element (if the background property would not be defined, than the mouse events would be triggered only on areas where some content is shown). This means that when a user would be over the ViewportBorder element the mouse event would be used to control the camera. It is very easy to define what keyboard and mouse button combinations rotate and which move the camera – by default right mouse button is used to rotate the camera and ALT + right mouse button is used to move the camera – see the help file or samples that come with Ab3d.PowerToys for more info. If EventsSourceElement property would not be defined, the source of mouse events would be the Viewport3D that is connected to the camera. But because Viewport3D does not have the Background property, it would be only possible to rotate the camera when the mouse would be over shown 3D objects – clicking on the area around the objects would not trigger any mouse events.

The MouseCameraController also shows a special cursor icon when the camera is rotating or when the user can rotate the camera with left mouse button. If you would like to use different cursor, you can set the RotationCursor property to some other value.

With the CameraControlPanel it is possible to control the camera with clicking on the shown buttons. By default the CameraControlPanel shows buttons to rotate the camera and to change the distance of the camera. With adding ShowMoveButtons property and setting it to true, additional buttons to move the camera would be also shown.

 

2) Cameras

Now let me describe the cameras in Ab3d.PowerToys in more details.

In the XAML above we are using SceneCamera. This is just one of the cameras that come with Ab3d.PowerToys library. It is the most advanced and the most easy to use. The camera automatically measures the 3D scene (3D objects inside Viewport3D) and shows them from the specified angle (Heading="40" Attitude="-20" Bank="0") and distance (Distance="250"). Those four properties are common to all the cameras in Ab3d.PowerToys. They represent the main advantage over the WPF’s cameras because it is much easier to define the camera with angles than with 3D directional vectors. The following image (taken from Ab3d.PowerToys Samples) is showing how different angles are rotating the camera:

Camera Heading, Attitude, Bank

As sad before SceneCamera measures the objects in 3D scene and calculates the center position of the scene’s bounding box. The value that is specified with the Distance property is the distance of the camera from the center position of the scene.

Because measuring the scene also gives us the size of the shown 3D objects, it is also possible to use the IsDistancePercent property. If that property would be set to true then the Distance value would mean the percentage of the size of shown objects. For example if Distance would be set to 2, this would mean that the camera’s actual distance from the center of the scene would be 2 times the size of the object’s bounding box (length of diagonal). This makes the camera usage really simple because you do not need to worry about the size of the shown 3D objects. But note that if you change the content of the Viewport3D you need to call Refresh method on the SceneCamera so the scene is measured again. You can also set the IsDynamicTarget property to true and the camera will check the size and center position of the scene on every rendering event (on more complex scenes this can take some time, so it is recommended to manually call Refresh method).

If you check the above XAML more carefully you will see that the camera also sets the ShowCameraLight property to Always. This is another great feature of the cameras and simplifies defining the lights. It adds a DirectionalLight to Viewport3D that is illuminating the scene in the same direction as the camera is facing. This is almost the same as a light would be mounted to a real camera because when the camera rotates the light direction will be also changed accordingly. The value “Always” means that the DirectionalLight is always added. We could also set the value of ShowCameraLight to “Auto” – this would mean that the camera would check the scene and if it would not find any light, it would add the DirectionalLight. This is also the default value of the ShowCameraLight property. But if you know that you will define your own lights and want to skip the check for the lights, you can set the ShowCameraLight to “Never”.

SceneCamera is just one of many cameras in Ab3d.PowerToys library. The following is a list of the most useful camera types:

  • SceneCamera
  • ThirdPersonCamera
  • TargetPositionCamera
  • FirstPersonCamea

ThirdPersonCamera is very similar to SceneCamera. But instead of looking at the whole scene it only looks at a specified object (set to CenterObject property). The angles define from which direction the camera looks at the object. The distance in that case defines the distance from the object’s center position. With ThirdPersonCamera it is also possible to use IsDistancePercent property.

TargetPositionCamera is similar to SceneCamera and ThirdPersonCamera but does not have any automatic measurement. Instead there you have full control of the position where the camera is looking at (set with TargetPosition property). If you know the position and size of your 3D objects you can use that camera instead of SceneCamera. TragetPositionCamera is also used when you want full control of the position where the camera is looking at. This camera does not have IsDistancePercent property.

FirstPersonCamera is a camera that does not look at the scene, target position or specified object as previous cameras. Instead it looks at the world from the specified position (set with Position property) – the position of the camera. The angles define the orientation of the camera. This camera does not have the Distance property.

The following pdf file shows samples of using the described cameras:
Cameras cheat sheet

The following image shows the class diagram of the cameras (click on the image to see it in full resolution):

 

Cameras class diagram

This was just a really brief description of the cameras. To learn more about them please see the help file and check the samples that come with the library.

 

3) 3D Objects

After so many words we still do not have anything to show. So it is really time to add some 3D objects.

Ab3d.PowerToys library comes with many 3D objects. The following are available in version 3.4:

  • Axis
  • Box
  • CenteredLineText
  • Circle
  • ColoredAxis
  • Cone
  • Cylinder
  • HeightMap
  • HorizontalPlane
  • LineArc
  • Line
  • LineWithText
  • MultiLine
  • MultiMaterialBox
  • Plane
  • PolyLine
  • Pyramid
  • Rectangle
  • Sphere
  • Text
  • Tube
  • VerticalPlane
  • WireBox
  • WireCross
  • WireGrid

If you define 3D objects in XAML you have two possible choices: you can create 3D object that are derived from Visual3D or from UIElement3D. For example to define a 3D box you can create a BoxVisual3D or BoxUIElement3D. The later add some additional features like focus, mouse events, tool tip, etc. But if you do not need that features you can use Visual3D objects.

When defining 3D objects in code, you can still create instances of Visual3D or UIElement3D objects. But you can also get a more low level objects (GeometryModel3D) with Model3DFactory, Line3DFactory, WireframeFactory or Text3DFactory classes.

As seen from the list above, the library also supports 3D lines. Here and additional note is needed. Because 3D lines are not supported in WPF 3D, they are not rendered in hardware. Therefore 3D lines are created with triangles that are than send to WPF 3D to render them in hardware.

For example if we need to create a 10 pixels wide 3D line, we are need to calculate the positions that will form two triangles that are oriented in such a way that they are facing the camera. This means that when the camera is changed, we need to recalculate the positions of the triangles so they are still facing the new camera. When we are showing only a few lines this is not a problem. But if we are showing many lines, for example a wireframe from a model with 20.000 vertices, then line recalculation can bring the CPU down and make the application response very bad. There are some tricks that can be used to improve the performance of 3D lines. They are described in the “Lines Stress Test” sample that came with the library (see the comments in the source code of that sample). Here I would just like to notify you that 3D lines in WPF 3D are much slower than solid models and should be used in greater quantities with care. However smaller number of lines are surely not a problem.


Now let’s add some 3D objects.

Insert the following into the Viewport3D:

<visuals:BoxVisual3D CenterPosition="0 5 0" Size="20 10 40" Material="Blue"/>

This will add a blue box to the 3D scene. The box is added to the specified location, with specified size and material. But wait! The Material definition looks very simple. If you are familiar with standard WPF 3D programming than you are more familiar with the following Material definition:

<visuals:BoxVisual3D CenterPosition="0 5 0" Size="20 10 40">
    <visuals:BoxVisual3D.Material>
        <DiffuseMaterial>
            <DiffuseMaterial.Brush>
                <SolidColorBrush Color="Blue"/>
            </DiffuseMaterial.Brush>
        </DiffuseMaterial>
    </visuals:BoxVisual3D.Material>
</visuals:BoxVisual3D>

This is the standard WPF’s way to assign a Blue material. Luckily all the 3D objects in Ab3d.PowerToys library have custom MaterialTypeConverter that enables you to use only one simple word to define the material. The used MaterialTypeConverter is very powerful – with simple strings you can define many possible materials.

For example the same blue material could be specified with Material="#0000FF".

In similar fashion it is also possible to set an image file as a texture. To do that just set the Material to the image file name – for example Material="Images/MyTexture.png".

It is also possible to define a SpecularMaterial. Let’s add a 3D sphere to show you how:

<visuals:SphereVisual3D CenterPosition="30 10 0" Radius="10" Material="S:64;Silver"/>

This creates a MaterialGroup with two children: SpecularMaterial (SpeculaPower = 64, Brush = White) and DiffuseMaterial (Brush = Silver). The SpeculaPower is defined by “S:64;” text. This short material definition always set the SpecularMaterial’s Brush to White (the most common setting). The following string sets a texture image instead of Silver brush: Material="S:64;Images/MyTexture.png".

It is also possible to use EmissiveMaterial. The following will create a sphere that is always Yellow regarding of the lights:

<visuals:SphereVisual3D CenterPosition="30 10 0" Radius="10" Material="E:Yellow"/>

Emissive material is created with a MaterialGroup with black DiffuseMaterial and EmissiveMaterial with brush defined with used string.

 

The following XAML defines some other 3D objects:

<visuals:BoxVisual3D CenterPosition="0 5 0" Size="20 10 40" Material="Blue"/>

<visuals:SphereVisual3D CenterPosition="30 10 0" Radius="10" Material="s:64;Silver"/>

<visuals:SphereVisual3D CenterPosition="-40 20 40" Radius="3" Material="e:Yellow"/>

<visuals:WireCrossVisual3D Position="-40 20 10" LinesLength="15" 
                            LineColor="Red" LineThickness="3"/>

<visuals:LineVisual3D StartPosition="10 10 -20" EndPosition="20 20 -20"
                        LineColor="Blue" LineThickness="2" StartLineCap="ArrowAnchor" />
                
<visuals:LineWithTextVisual3D StartPosition="20 20 -20" EndPosition="60 20 -20" 
                                LineColor="Blue" LineThickness="2"
                                Text="3D TEXT"/>

<visuals:WireGridVisual3D x:Name="BottomWireGrid" LineColor="#777" LineThickness="1" 
                        WidthCellsCount="10" HeightCellsCount="10" Size="100 100" />

And here is a screenshot from Visual Studio with the 3D scene defined above:

3D Objects in Visual Studio 2010

All the defined 3D objects are seen in the preview window.

In the lower left corner are buttons for the CameraControlPanel. In the lower right corner there is an icon which represents the SceneCamera. This icon is visible only in design time and is there so you can easily select the camera in XAML with simply clicking on the icon (note: if you do not want to see the icon in design time you can set the IsDesignTimeInfoIconShown property to false).

Now you can try out one of the nicest features of the library – the preview of the changes. Everything you change in the XAML, the change will be immediately shown in the preview. This means that you can simple change the heading or attitude of the camera and you will see your objects from another direction. You can also change the position or size of the objects. This way it is very easy to compose your 3D scene. Note: sometimes it can happen that the scene and XAML are not in sync any more – in that case the best solution is to rebuild your project and the preview should be showing the correct image again.

If you run that sample now you will see the 3D objects and will be able to rotate the camera around the objects with left mouse button and move the camera with holding ALT key and left mouse button. You could also rotate the camera with CameraControlPanel buttons. Not bad for just a few lines of XAML.
As shows in the list before the Ab3d.PowerToys define many other 3D objects. The following pdf file shows many of them:
Objects cheat sheet

 

4) Showing objects from 3ds files

Usually you will want to show more complex 3D models that are defined in some 3D modeling application. This can be done with Ab3d.Reader3ds library.

The Ab3d.Reader3ds library contains classes that can read 3D objects with all of their properties, lights, cameras and animations from 3ds files. The 3ds file format is one of the most commonly used file format for storing 3D models. Therefore almost all 3D modeling applications support exporting into it.

The following schema shows the process of showing 3D objects in WPF application:

Reader3ds Schema

Here let me present just the simplest usage of the Ab3d.Reader3ds.

I will show you how to add 3D objects from 3ds file to your scene defined in XAML file. First you need to add reference to the Ab3d.Reader3ds library and add the following namespace declaration:

xmlns:visual3ds="clr-namespace:Ab3d.Visuals;assembly=Ab3d.Reader3ds"

Than you can use the following XAML to read 3D objects:

<visual3ds:Model3ds Source="Resources/MyObject.3ds" 
                    Position="0 0 0" PositionType="BottomCenter" />

<visual3ds:Model3ds Source="Resources/OtherObjects.3ds" ObjectName="Car01" 
    Position="100 0 0" PositionType="BottomCenter" SizeX="100"/>

The first line reads 3D models from MyObject.3ds file. The model is positioned so that its bottom center position is at (0, 0, 0) coordinates.

The second line reads the OtherObjects.3ds file. It does not show all the objects from that file (as in the first line) but only the object with the “Car01” name. The Car01 object is scaled so its x size is 100 and positioned so that its bottom center is at (100, 0, 0).

Note that when using more than one Model3D with the same 3ds file, the 3ds file is read only once.
Ab3d.Reader3ds also provides many other ways to read 3ds file. To see more please check the samples and help file that come with the library.

 

5) Conclusion

There are still many features that were not described in this blog post. For example in Ab3d.PowerToys library there is an EventManager3D class that simplifies using mouse events on 3D objects – you can use MouseClick, MouseOver, MouseDrag and other mouse events on specific 3D objects. The library also solves problem with semi-transparent 3D objects with TransparencySorter.

I hope I have persuaded you that the Ab3d.PowerToys and Ab3d.Reader3ds libraries are really easy to use and provide many features to create great WPF 3D applications.

To read more about other advantaged of using WPF 3D and our libraries you are also invited to read the 3D Overview page.

Tags: , ,

Ab3d.PowerToys | Reader3ds

New maintenance release for Ab2d.Reader3ds and Ab3d.PowerToys

by abenedik 3. March 2011 21:37

A minor update for Ab2d.Reader3ds and Ab3d.PowerToys libraries is available.

The update fixes licensing code for WPF Browser applications (partially trusted) - before it was not possible to use both Ab3d.Reader3ds and Ab3d.PowerToys the same WPF Browser application.

The update also fixes problems with reading some tga files with Ab3d.Reader3ds. Because some older 3ds files use tga files for textures quite often, the internal tga file reader was added to version 7.0. This version had problems with some tga files. This problems are now fixed.


Some of you have already noticed that the evaluation version has a brand new installer that enables installing any product from only one installer (before each product has to be installed separately). With the new versions the new installers are now available also for commercial products.

Because of the new installers there are also new commercial versions of Ab2d.ReaderSvg and Ab2d.ReaderWmf libraries available to commercial users. Those versions contain just small changes made for the new installation process and do not bring any new functionality.

Tags: , ,

Ab3d.PowerToys | Reader3ds

New versions of 3D libraries bring WPF 3D to a completely new level

by abenedik 16. December 2010 18:19

With the release of Ab3d.Reader3ds v7.0 and Ab3d.PowerToys v2.0 a new milestone in 3D programming was reached.

The first version of WPF brought us simplified programming with 3D. With WPF there is no need any more to deal with C++, DirectX and graphics drivers. Now programmers can use xaml and managed code to define the 3D scene. Besides this WPF can use high end graphic cards when they are available and can fallback to software rendering when the computer does not have an accelerated graphics.

Of course WPF does not provide all the features of DirectX, so it is not capable of running high end 3D games. But my customers have already proven that it is very capable of showing very complex 3D scenes with models with several hundred thousands triangles.

But WPF still lacks many features to make programming with 3D easy.

Now with Ab3d.Reader3ds and Ab3d.PowerToys users have the ultimate framework to work with WPF 3D.

The Ab3d.PowerToys includes advanced cameras, camera controllers (rotate and move the camera with the mouse, etc.), 3D objects (Box, Sphere, Cone, etc.), 3D lines, 3D text and classes to simplify using mouse events on 3D objects.

With Ab3d.Reader3ds and Viewer3ds it is possible to define 3D models in almost any 3D modeling application (3D Studio Max, Maya, AutoCad, etc.), save the objects into 3ds file and use the 3D models in your WPF application.

The libraries gives you a complete solution for:

  • creating monitoring systems with 3D models,
  • displaying 3D simulations and mathematical models,
  • displaying 3D models of your products or prototypes,
  • creating designing and configuration applications in reality-like 3D scenes,
  • creating interesting 3D effects,
  • etc.

 

That was a short overview. Now to the details about the libraries and more information about new features.

Viewer3ds

The new version of Viewer3ds application (3ds to xaml converter) that comes with Ab3d.Reader3ds library brings many new improvements.

The application is now using the Ab3d.PowerToys library. Therefore it was really easy to add camera rotation and movement. Among other changes I would also like to mention the new possibility to get detailed information about selected objects (sizes, materials, detailed mesh information, etc.).

 

The Ab3d.Reader3ds library also got many improvements.

The biggest enhancement is great performance improvement - because of optimized algorithm and multi-threaded processing some 3ds files are read 80% faster. But reading some very large 3ds files can still take a few seconds. To improve user experiance it is now possible to get progress reports while reading the file. The samples that came with the library demonstrate how to show progress window on another thread or read the 3ds file on another thread and show the progress on the main thread.

Let me also mention some other important changes:

  • Improved handling of texture files with simplified notifications about missing texture files.
  • Added GetXaml method to Reader3ds class to get formatted xaml text of the read 3ds file.
  • Improved reading FiledOfView and SpecularMaterials.
  • Improved support for running in partially trusted environment.
  • Added Lights collection.

Complete list of changes can be seen here.

 

Viewer3ds

I am really proud of the features and capabilities the Ab3d.PowerToys library. They really bring WPF 3D to a completely new level.

The library makes Visual Studio a simple 3D modeling application as all the 3D objects and cameras that are defined in xaml are immediately seen in designer window. This way it is very easy to arrange the objects, set camera or otherwise define the scene.

Already the previous version of the library had advanced cameras (SceneCamera, FirstPersonCamera, ThirdPersonCamera) that enable setting the camera with simply setting heading, attitude and bank angles and defining some other properties like distance. The cameras can be simply rotated with the mouse or camera control panel. The new version goes further with enabling moving the camera. Now any camera can be rotated and moved around. And it is possible to assign rotation and movement of the camera to any mouse button and to any keyboard modifiers. For example the following two lines of xaml add a SceneCamera to the scene and enable rotationg the camera with right mouse button and moving the camera with right mouse button and alt key pressed:

<cameras:SceneCamera Heading="30" Attitude="-20" Distance="200"/>
<ab3dControls:MouseCameraController RotateCameraConditions="RightMouseButtonPressed"
                                    MoveCameraConditions="RightMouseButtonPressed, AltKey"/>

The previous version of Ab3d.PowerToys already included many basic 3D objects (Box, Sphere, Cone, etc), 3D Lines and simplified mouse event handling on 3D objects.

Besides improved cameras the following are the main improvements of the new version:

  • Added support for 3D text.
  • Improved PolyLines - they are now correctly connected to each other.
  • Added MultiMaterialBox where each side of the box can have its own material.
  • Added CreateFrom method to all Ab3d.Cameras - it can be used to create any Ab3d.Camera from existing WPF's Camera (or camera read from 3ds file with Ab3d.Reader3ds).
  • Added CameraAxisPanel - a predefined panel that shows the axis orientation for the target camera.
  • Added RectangleVisual3D, WireBoxVisual3, WireCrossVisual3D, VerticalPlaneVisual3D and LineArcVisual3D.
  • Added IsVisible property to all 3D models derived from Visual3D.
  • Added CreateWireframe method that takes Model3D to create wireframe from Model3DGroup or GeometryModel3D.
  • Fixed for using in partially trusted environment - before creating custom cursor was not allowed - now a Hand cursor is used instead.
  • BREAKING CHANGE: Fixed Bank - now the positive bank values rotate the camera in the clockwise direction (before the direction was counter-clockwise). For example bank angle 30 means that the Camera is rotated as a head would be bended to the right.

The complete list of changes is really long - it can be seen on Abd3.PowerToys web page.

 

A quick preview of cameras and 3D objects can be seen from two cheat sheets (prepared with WPF; full source code is included with the samples that come with the library):
Cameras cheat sheet
Cameras cheat sheet


Objects cheat sheet
3D Objects cheat sheet

 

The following are a few screenshots (click on xaml link to see the xaml source code):

[xaml] [xaml] [xaml]
 
 
[xaml] [xaml]  

 

To see more screenshots and details about the library see Abd3.PowerToys web page.

 

Ab3d.Reader3ds and Ab3d.PowerToys are separate products, but when the Ab3d.Reader3ds pro library license is purchased, the price for Ab3d.PowerToys library is ONLY 1 USD.

 

I am already planning to add a few new exciting features to the library. If you have any recommendation and other comments you are most welcome to post them to the library’s forum.

 

As usual the new version can be downloaded from User Account page (for commercial users) or from my Downloads page (for evaluation version).

 

PS: For the customers of Ab3d.Reader3ds with expired updates subscription I am preparing a very special offer to renew the subscription – detailed information will be sent to your email in the following days.

Tags: , , , ,

Ab3d.PowerToys | Reader3ds

Ab3d.PowerToys V1.0 released

by abenedik 21. December 2009 09:17

I am happy to announce that the final version of Ab3d.PowerToys has been released.

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).

The created 3D objects and used 3D cameras are fully visible in Visual Studio Designer.
This means that the 3D scene can be very easily designed in Visual Studio.

With Ab3d.PowerToys programming with 3D cannot be easier!

Ab3d.PowerToys - All 3D models in Visual Studio Designer

 

The following is the list of improvements from the Release Candidate version:

  • Added public Model property as Model3D to all 3D UIElements,
  • CenterObject on ThirdPersonCamera now accepts object type instead of Model3D - so it is now possible to assign Visual3D and UIElement3D as center object,
  • Transformed the CurrentSurfaceHitPoint on MouseDrag3DEventArgs when used on Visual3D objects - now the real hit Point3D is get,
  • Fixed EventManager3D when there were no drag surface registered but there were some event sources subscribed to drag event,
  • Added HitObjectName and HitObject to BaseMouse3DEventArgs,
  • Added additional comments and code samples to help file.

 

There are also a few new samples.

Two new samples show the power of EventManager3D. One show how easy is to create a 3D object that is moved around with the mouse. The other sample shows how to use EventManager3D with Ab3d.Reader3ds library. The sample is similar to Robot Arm sample in Reader3ds samples. But instead of using sliders to move the robot, this sample utilizes the powerful EventManger3D so the robot can be moved around simply by dragging the mouse. Also the light can be switched on and off by clicking on it.

The most interesting new sample is the 3D Cannon simulation. It shows a 3D simulation of a cannon where user can set many parameters like Gravity, Drag factor, ball mass, etc. It is also possible to switch between many possible cameras. The following image shows the sample in action:

Ab3d.PowerToys - Cannon simulation

 

The 60-days evaluation of Ab3d.PowerToys can be downloaded from Downloads page.

The price for Ab3d.PowerToys license starts from $179.00 (very low price for the amount of work-hours saved). It is also possible to buy full source code for the library.

And that is not all. When a Ab3d.Reader3ds Pro license is bought, the Ab3d.PowerToys license is get for free!

And that is still not all - see the next blog post that is coming very soon Smile

Tags: , ,

Ab3d.PowerToys