Major update of 3D libraries available

by abenedik 21. October 2011 22:50

I am really happy to announce that a new major release of Ab3d.Reader3ds and Ab3d.PowerToys libraries has been released.

The key features of this release are:

  • Added transparency sorting that prevents problems with transparent 3D objects in WPF.
  • Improved reading of some 3ds files.
  • Simplified animating camera rotations.
  • Added support for OrthographicCamera.
  • Improved commercial licensing code.

 

Before describing some of the key features in more details let me first give you the full list of changes.

Ab3d.Reader3ds v8.0:

  • Added support for simple transparency sorting that can prevent most of the problems with transparent objects. If the new IsTransparencySortingEnabled property is true (by default) the transparent objects are moved after non-transparent objects. For complex models with many transparent objects use of advanced transparency sorting in Ab3d.PowerToys is needed. Also added TransparentObjectsCount property to Reader3ds (so user can decide if he need to enable transparency sorting or not - with Ab3d.PowerToys).
  • Added NameFormatString to BaseXamlWriterSettings - it can be used to customize how the object names are written to XAML (custom prefixes and suffixes can be added to names).
  • Added possibility to read tga into BitmapImage with static Read method in a new Ab3d.Common.TgaReader class. Note: The previous versions of Reader3ds already supported reading tga files. But it was not possible to read tga files in your applications. This is now possible and enabled you to convert tga images to common files (for example png) that can be used with xaml created from 3ds file). This feature is available only in pro version.
  • Fixed reading some of the objects with object matrix that has negative determinant.
  • Fixed using ForceTwoSidedMaterials property for models that does not have material defined and where the default material is used.
  • Fixed objects without material set (default material is used) and with object matrix that has negative determinant.
  • Fixed when object with negative determinant is broken into sub objects for different materials - the parent's negative determinant was not used before.
  • Fixed reading 3ds file where definition of two sided material is written outside material chunk.
  • Fixed reading some partially broken 3ds file (objects with invalid triangle indices are not shaded).
  • Skipped importing 3D objects that does not have triangle indices set (have only positions set).
  • Fixed security exception in partially trusted WPF Browser applications - before the multi-treading code was not able to get the number of processors on the system.
  • Improved commercial licensing code to prevent delay caused in RSACryptoServiceProvider under some circumstances.
  • Added Ab3d.Licensing.PowerToys.EmbeddedLicenseAssembly property to speed-up looking for embedded license key in commercial version.

Ab3d.PowerToys v3.0:

  • Added support for transparency sorting with new TransparencySorter and TransparencyHelper classes.
  • Simplified animating camera rotation with new StartRotation, StopRotation methods on SphericalCamera. There is also a new IsRotating properties. The MouseCameraController is also adjusted to suspend animated rotation while user rotates the camera with the mouse.
  • Added axes names to CameraAxisPanel. Also added IsAxisNameShown, XAxisColor, YAxisColor and ZAxisColor properties to CameraAxisPanel.
  • Added support for OrthographicCamera for all Ab3d.PowerToys Cameras. Added CameraType and CameraWidth properties to BaseCamera.
  • Greatly improved creating wireframe from existing 3D models - now it is much faster and uses much less memory.
  • Improved LinesUpdater - the lines that are removed from the visual tree are now free to be cleaned by garbage collection.
  • Added Reset and UnregisterLine methods to LinesUpdater to manually remove lines from LinesUpdater. This enables better manual control of the registered lines.
  • Improved measuring scene bounds in SceneCamera when transformations are used on Visual3D objects. Before the used transformations prevented the camera to correctly show the scene.
  • Fixed selecting cameras with mouse click on camera icon in Visual Studio 2010 designer.
  • Added GetCameraMatrixes to BaseCamera to get view and projection Matrix3D of the current camera.
  • Improved Ab3d.Utilities.Dumper class - Added GetTransformText and GetMatrix3DText methods and made GetMaterialText public. Also the GetModelInfoString method now also displays the Transformation details.
  • Improved commercial licensing code to prevent delay caused in RSACryptoServiceProvider under some circumstances.
  • Added Ab3d.Licensing.PowerToys.EmbeddedLicenseAssembly property to speed-up looking for embedded license key in commercial version.

 

TRANSPARENCY SORTING

WPF 3D can show transparent 3D objects. But to show them correctly, the transparent objects need to be defined after all the objects that are visible through them.

The following image shows the transparency problem in a simple 3D scene. Because the red boxes are defined after the semi-transparent GlassPlane they are not visible through the GlassPlane (the order of objects is visible in the right):

WPF 3D transparency problem

To solve the problem, the GlassPlane needs to be moved after the non-transparent objects. The following image is showing the correctly rendered scene.

Solved WPF 3D transparency problem

For cases when the number of transparent objects is not big and if the transparent objects are not positioned in 3D space one after another, the simple transparency sorting is usually enough to produce correct rendering in WPF 3D.

But simply moving transparent objects after non-transparent objects is not always enough. For example if transparent object A is visible through transparent object B, than B must be defined after A. The problem in this case occurs when the camera is rotated so that B is visible through A. Now B must be defined before A. To solve this problem correctly, firstly the transparent objects must be moved after non-transparent objects and than transparent objects must be sorted by their distance to the camera. The sorting must be done after the camera is changed.

As seen from the new features lists above, both Ab3d.Reader3ds and Ab3d.PowerToys now support transparency sorting.

Ab3d.Reader3ds can perform a simple transparency sorting by moving transparent objects after non-transparent objects. Transparency sorting is performed if the IsTransparencySortingEnabled is set to true (by default). It is also possible to get the number of transparent objects by the TransparentObjectsCount property. Ab3d.Reader3ds does not do any sorting by camera distance. For this the Ab3d.PowerToys library is needed.

With Ab3d.PowerToys library it is possible to perform simple transparency sorting and sorting by camera distance. TransparencySorter class can be used to perform simple transparency sorting or ByCameraDistance transparency sorting where the transparent objects are sorted by their distance to the camera.

Simple transparency sorting (moving transparent objects after non-transparent objects) can be done with the following line:

Ab3d.Utilities.TransparencySorter.SimpleSort(myModelsGroup);

When sorting by camera distance is used, the TransparencySorter can also automatically re-sort the objects when the camera is changed. To optimize the sorting it is possible to specify an angle that will tell how much the camera's direction must be changed when a new sort is preformed.

To perform transparency sorting by camera distance the following lines of code can be used:

private TransparencySorter _transparencySorter;
 
private void StartTransparencySorting()
{
    _transparencySorter = new TransparencySorter(_rootModel3DGroup, Camera1);
     
    // Re-sort on every 10 degrees change
    _transparencySorter.CameraAngleChange = 10; 
 
    // Do an initial sorting
    _transparencySorter.Sort();
 
    _transparencySorter.StartSortingOnCameraChanged();
}
 
private void StopTransparencySorting()
{
    if (_transparencySorter != null)
        _transparencySorter.StopSortingOnCameraChanged();
}

For more code samples see the samples that come with Ab3d.PowerToys library.

The following images show rendering of the objects before (left image) and after (right image) transparency sorting:

WPF 3D transparency problem

WPF 3D transparency problem

IMPROVED READING OF 3DS FILES IN AB3D.READER3DS

Ab3d.Reader3ds went through a big test with our bigger customer. Many real world 3ds files were used to test the accuracy of the reader. Because many test files were not created with 3D Studio Max or similar product, many of them were not correctly formatted (it was not possible to open them with 3D Studio Max). After some changes in Ab3d.Reader3ds mst of those "broken" 3ds file can now be read correctly. This made the library even better and proved its status as the best library for importing 3ds files.

IMPROVED COMMERCIAL LICENSING CODE

The last relase of Ab2d.ReaderSvg, Ab2d.ReaderWmf and ZoomPanel library already got improved commercial licensing code. The change fixed a potential issue with using RSACryptoServiceProvider that can lead to very long delays when checking the license key. This issue has been now fixed for Ab3d.Reader3ds and Ab3d.PowerToys. Because of this issue it is highly recommended to upgrade to the new version.

Additionally as with the 2D libraries it is now possible to set the EmbeddedLicenseAssembly property to speed up finding the embedded license key in the application.

To see more details about this change please see the blog post for the 2D libraries or check the new help files.

OTHER IMPORTANT AB3D.POWERTOYS IMPROVEMENTS

A very useful new features of the Ab3d.PowerToys library simplifies creating animated camera rotations. Before animated camera rotations were created with binding a DoubleAnimation to Heading property of the camera. But using DoubleAnimation has its drawback because it the animation locks the value of the Heading and therefore makes rotating the camera with the mouse impossible.

The new version now include the StartRotation and StopRotation methods that can be used to simply start the camera animation. The StartRotation method takes two parameters: the first is heading change per second, the second is attitude change per second. The best thing about this is that while the camera is animated with StartRotation method, user can still use the mouse to rotate the camera (during mouse rotation the animation is suspended). This way it is very easy to create great presentations of 3D models where the model is rotated and the used can still manually change the rotation with the mouse.

One of the very requested feature was also a support for OrthographicCamera. It is mostly used in technical applications where the ratios and parallel lines of the 3D objects need to be preserved. The OrthographicCamera is now also supported.

A very nice new feature is also that axis names are shown on the CameraAxisPanel (it shows the orientation of axis of the current scene).

A lot of work was also done to improve 3D lines. Now wireframes from existing 3D objects are created much faster and also use much less memory. Also the memory management of the 3D lines is greatly improved and enables user to have more control of the registered 3D lines.

 

With new features the development of applications with 3D content has become even easier.

WPF 3D is very capable of displaying 3D content for most needs of business applications. It also has many advantages over other platforms (DirectX, XNA). With WPF 3D, Ab3d.PowerToys and Ab3d.Reader3ds programming with 3D was never easier.

I would like to conclude with saying that in my opinion desktop applications will not just sink into oblivion. They will still have their big share with complex business applications that need to be very user friendly, need advanced user interfaces to simplify complex user processes or require lots of resources. Despite many (usually not developers but marketing driven) considerations, I believe that WPF is still the very best technology for writing such applications.

Tags:

Ab3d.PowerToys | Reader3ds

Improved Ab2d.ReaderSvg, Ab2d.ReaderWmf and ZoomPanel available

by abenedik 10. October 2011 14:23

The major improvement in this release is made in the licensing code for commercial versions of the products.

The update contains also some minor improvements in the Ab2d.ReaderSvg and Ab2d.ReaderWmf libraries and a small improvement in ViewerSvg. But let me first tell you about the changes in the commercial licensing code.

Recently a customer reported very long delays (up to 10s) when creating an instance of ZoomPanel class. After some investigation I have discovered that the delay is related to a "bug" in Microsoft's RSACryptoServiceProvider class (see http://support.microsoft.com/kb/948080). The RSACryptoServiceProvider is used to validate the license and under some circumstances the VerifyData method on the class can cause a long delay. The licensing code has been changed to prevent the delay. The problem with this bug is that the licensing code can work very well on computers where you test your products, but on some client's computer the RSACryptoServiceProvider can cause your application or product to start with a long delay.

Therefore it is highly recommended to update the products to the latest version.

But this was not the only improvement in the licensing code. Now it is possible to set the new EmbeddedLicenseAssembly property to make the check of the embedded license even faster. To understand the purpose of the new property let me first shortly describe how the licensing code works.

The licensing code in our components uses the standard .Net licensing system. This means that at compile time the compiler calls the licensing code in our products. There the developer license key is read. It is converted into a runtime license key and saved by the compiler into assemblies embedded resource. When our component is used in your application, its licensing code first tries to find the embedded runtime license key. Because our component does not know which assembly contains the embedded license key, it is usually needed to check resources in multiple assemblies before the correct one is found. To make this check much faster, it is now possible to set the static EmbeddedLicenseAssembly property to the assembly that contains the embedded license. This way the licensing code can immediately find the license key and can therefore execute much faster.

The following example sets the EmbeddedLicenseAssembly for the ZoomPanel control:

public class MyClass()
{
    public MyClass()
    {
        Ab2d.Licensing.ZoomPanel.LicenseHelper.EmbeddedLicenseAssembly
          = typeof(MyClass).Assembly;

        InitializeComponent();
    }
}

Samples for other products and some additional details about this process can be found in the new "Using commercial version" help file.

 

The improved licensing code is currently available for Ab2d.ReaderSvg, Ab2d.ReaderWmf and ZoomPanel. The fix for Ab3d.Reader3ds and Ab3d.PowerToys will be available in the following days (both libraries will have many new features that have to be finished before publishing).

 

As mentioned before, this update also brings some additional improvements to Ab2d.ReaderSvg and Ab2d.ReaderWmf.

ReaderSvg and ViewerSvg:

  • Added NameFormatString property to BaseXamlWriterSettings - it can be used to customize how the object names are written to xaml (custom prefixes and suffixes can be added to names). The export window in the ViewerSvg have two new TextBoxes that can be used to specify custom prefix and suffix that will be used to format the object names.
  • Improved reading svg image elements with added support for preserveAspectRatio property.

 

ReaderWmf:

  • Improved drawing Paths - in some cases only path stroke should be drawn without using any fill.
  • Added support for monochrome brushes.

Tags:

ReaderSvg | ReaderWmf | ZoomPanel

Update for Ab2d.ReaderSvg, Ab2d.ReaderWmf and ZoomPanel available

by abenedik 12. August 2011 20:37

I am happy to announce that all our 2D products have been updated.

The following screenshow is showing improved design time support for SvgViewbox and WmfViewbox:
SvgViewbox and WmfViewbox in Visual Studio

 

The following are the changed in Ab2d.ReadSvg:

  • Improved design time support for SvgDrawing control - now the svg file is shown in design time (before the image in design time was shown only in SvgViewbox).
  • Added SvgFileLoading and SvgFileLoaded events to SvgViewbox and SvgDrawing controls.
  • Prevented locking referenced image files.

 

The following are the changed in Ab2d.ReadWmf:

  • Added support for pattern brushes. Reading pattern brushes is turned on by default but can de disabled with setting ReadPatternBrushes to false.
  • Improved design time support for WmfViewbox and WmfDrawing controls - now the metafile is shown in design time.
  • Added MetafileLoading and MetafileLoaded events to WmfViewbox and WmfDrawing controls.
  • Fixed reading some embedded images that have their width or height negative.

Added support for pattern brushes need some additional comments because there are some differences between handling pattern brushes in GDI+ and WPF. Pattern brushes in GDI+ are not affected by the scale of the shown image. This means that if you zoom in or out of the metafile that is drawn by GDI+, the pattern brush is not scaled and is always drawn in a way that one pixel in the pattern bitmap is always rendered with one pixel.

In WPF the bitmap brushes are affected by the scale.

For example if you have a rectangle with 10 x 10 size and pattern brush from 10 x 10 bitmap and you scale the rectangle to be shown on the whole screen, the bitmap will be also scaled to the whole screen. In GDI+ the bitmap is not scaled so the pattern is still the same as when showing the rectangle without scale.

Because of this difference the imported pattern brushes can sometimes look strange. Therefore it is possible to disable reading pattern brushes with setting ReadPatternBrushes to false.

 

ZoomPanel has received the following updates:

  • Fixed problems with using None for Stretch value.
  • Improved using ViewboxLimits.

 

All the products also had a licensing issue that showed unlicensed dialog under some circumstances. This issue is now fixed.

 

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

Tags:

ReaderSvg | ReaderWmf | ZoomPanel

New version of Ab2d.ReaderSvg available

by abenedik 1. August 2011 10:19

I am happy to announce that the new version of Ab2d.ReaderSvg library is available.

The version adds improved support for svg use and embedded svg elements. Those two svg elements are now correctly placed and have the correct size.

The new version also provides two new properties that can be used to fix problems that are caused by the differences between WPF and svg.

The first new property is SwitchElementProcessingType. It specifies which children of the svg switch element will be imported and shown. The switch element in svg file defines children that are shown based on the conditions defined in switch element. Because it is not possible to process svg conditions in WPF, it is possible to choose how the children will be imported and which children will be shown. The possible values for SwitchElementProcessingType are:

  • Disabled - svg switch element will not be imported.
  • ShowFirstDiscardOthers - only the first switch child will be imported. Other children will not be imported.
  • ShowFirstHideOthers - all switch children will be imported. Only the first element will be shown. Other children will have their Visibility set to Hidden.
  • ShowFirstCollapseOthers (default) - all switch children will be imported. Only the first element will be shown. Other children will have their Visibility set to Collapsed.
  • ShowAll - all switch children will be imported and shown.

 

The second new property is OverrideMiterLimit. The property has been added because WPF renders miter limit line cab differently as they are defined in svg specifications. The miter lime cabs show sharp line edges. But when the two lines meet at low angle, the sharp edge could extend very far away from the line junction. Therefore the miter limit can limit the sharp edges. In WPF the miter limit is used to specify how far away the sharp edge is allowed to go. In svg, the miter limit defined at which angle the miter limit is converted into beveled edge. This difference can lead to some anomalies when importing svg files. In this case the OverrideMiterLimit can be used to override the miter limit specified in the svg file and use value 1 or 2 instead.

For more information about the differences please see forum thread about this.

For backwards compatibility by default the miter limit defined in svg file is used (OverrideMiterLimit = 0).

 

Both new properties can be also set in the new ViewerSvg (here the default OverrideMiterLimit is set to 2 - miter limit of 2 is used by default).

Tags: , , ,

ReaderSvg

New version of ZoomPanel with tons of new features is available

by abenedik 26. June 2011 22:31

I am really happy to announce that the highly anticipated new version of ZoomPanel library is finally released.

ZoomPanel

The new version brings tons of great new features:

  • Added ZoomPanelNavigator, NavigationCircle and NavigationSlider controls. They can be used to move around zoom area and set zoom factor with slider (shown in the upper left corner in the image above).
  • Added ZoomPanelMiniMap, ViewboxExMiniMap and BaseMiniMap controls. The ZoomPanelMiniMap can be used to preview which part of the content is shown. It also enables moving the shown content and zooming in and out with mouse wheel (shown in the bottom right corner in the image above).
  • Added Stretch property to ZoomPanel - before only Uniform stretch was used. Now it is also possible to use other stretch values: None, Fill, Uniform or UniformToFill.
  • Added IsZoomPositionPreserved property to ZoomPanel - it controls if mouse wheel zooms at the mouse position or at the center of the ZoomPanel.
  • Added RotationAngle property to ZoomPanel.
  • Added ZoomFactor, CenterPosition and CenterPositionUnits properties to ZoomPanel. Before the area that is shown with ZoomPanel was controller by Viewbox property. The usage of this property was sometimes quite complex. Therefore ZoomFactor and CenterPosition were added. They are much simpler to understand and use.
  • Added support to save and navigate through the ZoomPanel history.
  • Added ActualViewbox to ZoomPanel - it describes the actually shown viewbox (the difference is created because of different aspect ratio).
  • Added SetZoom method to ZoomPanel with many overloads to simplify setting which part of the content is shown.
  • Added ZoomAtMousePosition and ZoomAtRelativeMousePosition methods to ZoomPanel.
  • Added IsAutoZoomPanelFindingEnabled property to ZoomController - now it is possible to disable automatically finding the ZoomPanel in case we need to set it manually.
  • Improved design time support when setting Viewbox value for ZoomPanel. Now it is allowed to temporary set the value of Width and Height to 0 (before when 1 was changed the 0.5 the designer throw an exception when 1 was replaced with 0).
  • Added MultiTouchZoomPanel control with full source code.
  • BREAKING CHANGE: When using custom content: Now ZoomFactor is used instead of zoomLevel (in CustomContentProvider callback).

For example the following code is all that is needed to add zooming and panning to the ZoomPanel's content (12345 text in this sample), buttons to control the ZoomMode (ZoomController), zoom panel navigation with buttons and slider to change zoom factor (ZoomNavigator) and mini map that shows which part of the content is shown:

<Window x:Class="Ab2d.ZoomControlSample.ZoomPanelSample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ab2d="clr-namespace:Ab2d.Controls;assembly=Ab2d.Controls.ZoomPanel">
  <Grid>
    <ab2d:ZoomPanel Name="myZoomPanel">
      <TextBlock>12345</TextBlock>
    </ab2d:ZoomPanel>
    <ab2d:ZoomController VerticalAlignment="Top"
                         HorizontalAlignment="Right"/>
    <ab2d:ZoomPanelNavigator VerticalAlignment="Top"
                             HorizontalAlignment="Left"/>
    <ab2d:ZoomPanelMiniMap VerticalAlignment="Bottom"
                           HorizontalAlignment="Right"/>
  </Grid>
</Window>

 

The new version comes with many new samples that demonstrate the new functionality. The following screenshot shows one of the samples (the list of all the samples is seen on the left side):

ZoomPanel

 

Even before version 3, the ZoomPanel was the most advanced zooming and panning control for WPF. With this release the control has become even better.

The current price for the Single developer license is only $69. Because so many new features were added to the library, the price will increase significantly on 11th July 2011 (more details are available on Purchase page). So now it is an ideal time to purchase the control, renew the updates subscription or purchase source code for the library.

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

Tags: ,

ZoomPanel

Multi-Touch 3D camera sample added to a new version of Ab3d.PowerToys

by abenedik 7. May 2011 23:20

A new version of Ab3d.PowerToys was just published.

The work on a new version was started as a response to the user post on the forum that asked how it would be possible to control a 3D camera from Ab3d.PowerToys library with his fingers on a multi-touch tablet pc. This looked as a simple an interested task but ended with discovering a probable bug in .Net 4.0 and creating a workaround for it. Also a discovered problems with WPF Browser applications were also fixed.

The following is a short list of new things in this release:

  • Added multi-touch camera controller sample (for .Net 4.0).
  • Fixed using MaterialTypeConverter in .Net 4.0 applications (for example using the following in XAML: Materila="Blue").
  • Fixed problems in WPF Browser applications (fixed showing licensing windows in partially trusted environment).
  • Added Ab3d.PowerToys WPF Browser applications sample.

 

The following screenshot shows the working multi-touch camera sample.

Because the support for multi-touch devices is available in .Net Framework 4.0 I did not want to put the new code into the library as it would raise the requirements from .Net 3.5 to .Net 4.0. So I have decided to create a sample .Net 4.0. project that would reference Ab3d.PowerToys library and use the multi-touch capabilities of the framework to adjust the camera.

Cameras and camera controllers in Ab3d.PoweToys library are very extendable, so it was really easy to create a multi-touch camera controller.

The following code shows the event handler that handles the touch data:

void ViewportBorder_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
{
    ManipulationDelta delta = e.DeltaManipulation;

    if (delta.Scale.X != 1 || delta.Scale.Y != 1)
    {
        // Scale with adjusting camera distance
        Camera1.Distance *= 1 / ((delta.Scale.X + delta.Scale.Y) / 2);
                
        e.Handled = true;
    }

    if (delta.Translation.X != 0 || delta.Translation.Y != 0)
    {
        // Rotate and move with calling RotateCamera or MoveCamera methods on MouseCameraController1.
        // Both methods take mouse dx and dy as parameters.
        // The amount of rotation is controller by EventsSourceElementRotationChange property on MouseCameraController1: Gets or sets the double value that specifies for how many degrees the camera is rotates when the mouse moves from one side of the EventsSourceElement to another size. The default value is 270.
        // The amount of movement is calculated by MouseCameraController1 that tries to make the movements in 3D just as big to follow the mouse / hand movements
        if (RotateRadioButton.IsChecked ?? false)
            MouseCameraController1.RotateCamera(-delta.Translation.X, -delta.Translation.Y);
        else
            MouseCameraController1.MoveCamera(-delta.Translation.X, -delta.Translation.Y);

        e.Handled = true;
    }
}

As the code shows the pinch zooming is represented as Scale in the DeltaManipulation. The scale is simply used to adjust the camera's distance.

Handling of the translation depends on the state of the RadioButtons that specify if we are rotating or moving the camera. In case of rotating, the RotateCamera method on camera controller is called. It takes the mouse difference as input parameter. In case a camera movement mode is selected, MoveCamera method is called - again it accepts mouse changes.

When I wanted to test the fist version of the code that would rotate a simple box, I got a runtime error that the value "#247589" cannot be assigned to Material. The error pointed to the following line of xaml:

<visuals:BoxVisual3D CenterPosition="0 20 0" Size="40 40 40" Material="#247589"/>

The xaml was copied from other samples for Ab3d.PowerToys library. When the project with other samples was started, there was no runtime exception. But in the new multi-touch sample the same line suddenly produces an exception. This is very strange.

The line defines a 3D box with specified center position, its size and material color. The material color is set by a help of the MaterialTypeConverter that comes with Ab3d.PowerToys library and enables setting the material by simply writing the name of the color (Blue), its hex number (#247589) or specifying image file name that should be used as texture. Without the MaterialTypeConverter the previous line should be written:

<visuals:BoxVisual3D CenterPosition="0 20 0" Size="40 40 40">
    <visuals:BoxVisual3D.Material>
        <DiffuseMaterial>
            <DiffuseMaterial.Brush>
                <SolidColorBrush Color="#247589"/>
            </DiffuseMaterial.Brush>
        </DiffuseMaterial>
    </visuals:BoxVisual3D.Material>
</visuals:BoxVisual3D>

I have removed the Material="#247589" and use the standard WPF was to set the material (as written above). This time the sample worked without errors.

The difference between the working and not working project was the target framework version. The not working was using 4.0.

It looked like that the baml parser (parser that reads the compiled xaml) in .Net 4.0 works does not want to use the custom type converter (MaterialTypeConverter). It was time to search the web. There were many problems with custom type converters, but none was similar to mine. The web did not have a clue about my problems. To make things easier, I created two new project were I wanted to reproduce the problem with as less code as possible. The first attemp showed that type converters on properties and dependancy properties work correctly in .Net 4.0. After some additional checking I have discovered that the Material property in Ab3d.PowerToys library was not created from stretch with Register method, but was created with AddOwner method - I wanted to reuse the already defined property on my own class. That was a breakthrough. When I changed the Register method with the AddOwner on a simplified project, the same error occurred.

After that discovery the workaround was simple - define the Material property from stretch.

This showed a case where assemblies that are created for .Net 3.5 does not work the same when they run with .Net 4.0. I think this should not happen. I am going to report this as a bug to Microsoft Connect.

So a rather simple task lead to interesting discoveries.

 

 

The multi-touch sample is available with the new version of Ab3d.PowerToys library. If you already have the library and do not want to upgrade to latest version just to see the sample, you can also download just the sample from the following link: Ab3d.PowerToys.Multitouch.zip (remember to uncomment the old style 3d box definition in xaml).

EDIT:

From Ab3d.PowerToys version 5.2 on, the multi-touch support is already build into the core Ab3d.PowerToys library into its .Net 4.0 version. This means that you do not need to use special MultiTouchMouseCameraController class for that. All you need to do is to make sure that you are referencing the .Net 4 version of the library from the ".NET 4" subfolder (the .Net 3.5 version does not support multi-touch).

Tags:

Ab3d.PowerToys

New maintenance release with many improvements for metafile reader

by abenedik 20. April 2011 23:42

This release brings many improvements to almost all our products.

The metafile reader (Ab2d.ReaderWmf) library got most of the changes. The svg reader (Ab2d.ReaderSvg) also got a few new features. There were also some improvements that affected all the products except ZoomPanel. ZoomPanel control was left out of this release because the library is waiting for a major upgrade. Now when this release is out I will finally start working on it (many things are already prepared - like mini map, rotate the content, zoom slider, etc. - they just need to be polished and tested).

Let me first describe the changes that affected all the products (except ZoomPanel):

  • The licensing dialogs are now created in WPF and not in Windows Forms as before (this skips loading Windows Forms and other related assemblies and therefore speeds up the application start - especially in evaluation version).
  • Improved commercial license code that tries to find embedded resources - this code is now much faster.
  • Added splash screens to all of the converter applications.

Besides the changes above the Ab3d.Reader3ds and Ab3d.PowerToys libraries did not get any new features.

 

But as mentioned before the Ab2d.ReaderWmf library was improved quite significantly. The code that transformed positions data from metafile into WPF was rewritten from ground up. The new version now enables to specify in which units the read positions will be - they can be in Pixels, Millimeters, Inches or GdiCompatable units. This can be useful when the drawing for example in Microsoft Visio is created in millimeters, the WPF elements that are created with pasting the drawing into Paste2Xaml can be also defined in millimeters. When the default Pixel units are used, the size of the read metafile is now the same as the size that is shown when the metafile is opened by Windows.

This is the list of changes in Ab2d.ReaderWmf library:

  • Added MetafileUnits property. It specifies the units in which the metafile is read. By default its value is set to Pixel. It can be also set to Millimeter, Inch or GdiCompatable. This can be useful to preserve the positions and other properties when the drawing is created in millimeter or inch units.
  • Added AutoSize property - defines if size of the root canvas is get from metafiles bounds or its frame. When bounds is used, the root canvas size is just as big as its containing objects.
  • Added GetSize(units) method that can be used to get the size of the read metafile in the specified units.
  • The size of the read metafile is now by default (if MetafileUnits is Pixel) the same as the size shown when metafile is opened by Window.
  • Improved reading metafiles that use MM_LOMETRIC, MM_HIMETRIC, MM_LOENGLISH, MM_HIENGLISH or MM_TWIPS mapping mode.
  • When reading polyline from a metafile and it has only 2 points a Line is used instead of a Polyline.
  • Added UsedMinLineWidthFactor to get the used minimal line width.
  • Improved Ab2d.Utility.ReaderWmf.ResourceDictionaryWriter - now the process of creating ResourceDictionary from metafiles can be better customized by creating a derived class.
  • Removed obsolete Ab2d.WmfViewbox control - the control has been obsolete for a few versions - Ab2d.Controls.WmfViewbox should be used instead. This also removes the need for Designer assemblies to remove the obsolete control from Designer ToolBox.

The Paste2Xaml application that can be used to simply copy objects from drawing application and paste them into XAML was also improved - support for the new features of the Ab2d.ReaderWmd library was added.

 

Some of the changes were also made in Ab2d.ReaderSvg library:

  • Markers (arrows and other line endings) are now correctly show on line and polyline elements (before they worked only on path elements).
  • markerWidth and markerHeight attributes are now correctly handled.
  • Removed obsolete Ab2d.SvgViewbox control - the control has been obsolete for a few versions - Ab2d.Controls.SvgViewbox should be used instead. This also removes the need for Designer assemblies to remove the obsolete control from Designer ToolBox.

 

Now I have to put together the new version of ZoomPanel.

Than a new exciting area awaits - Silverlght 5 with its 3D.

Tags: , , ,

Ab3d.PowerToys | Reader3ds | ReaderSvg | ReaderWmf