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

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

Business transfered to a new company - AB4D d.o.o.

by abenedik 6. December 2010 21:18

Today is a great day!

After almost a month of dealing with bureaucracy I am happy to announce that today I have made the final step in establishing a new company AB4D d.o.o.

Until today all the products from www.ab4d.com were developed and sold in behalf of Andrej Benedik s.p. – a legal form of a sole proprietor.

Because the business has grown, the limitations of sole proprietor legal form have become too tight. So it was time for a step forward – to establish a real company in a form of limited liability company (d.o.o.).

After registering the company, opening a new bank account, registering for Euro VAT ID, opening new accounts on PayPal and Gate2Shop, adjusting the invoices and other content on web site, today, as the final step, the production web site (www.ab4d.com) was updated. Today the company had made its first breath of air.

Thank you for all your great feedback and support. I will do my best that under the new company your satisfaction will be even bigger.

To begin with I am planning to release a new version of Reader3ds and Ab3d.PowerToys in the next week. The new libraries will make programming with 3D so easy that even your grandma could do it (without even knowing that there are heavy C++ and DirectX books).

 

PS:

Where did the name of the company came from?

The users of the libraries will quicky guess that it came from the names of the namespaces used in my libraries (Ab2d and Ab3d). But wait - in this case the name should be AB5D. Ah, screw math - AB4D sounds better :)

Tags:

Web Page

Improved verson of Ab2d.ReaderWmf is available

by abenedik 19. October 2010 14:03

The Ab2d.ReaderWmf library has recieved a minor updated.

This update improves and fixes the following issues:

  • Fixed reading some embedded images (before sometimes FileFormatException was thrown).
  • Improved positioning text and handling rotated texts.
  • Fixed reading arc and pie segments for some cases.
  • Improved GetXaml method - now the images are written to xaml without need to specify ResolveImagePath delegate. The uri format can be specified with the new DefaultImageUriFormatString property in XamlWritterSettings.
  • Added ImageFileExtention string to EmbeddedImageData.
  • Improved setting minimal line thickness. In metafile a line thickness can be specified to 1 pixel regardless of the zoom level - this is not possible in WPF and Silverlight. The algorithm that sets the line thickness has been improved to prevent getting too thick lines.

 

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

Tags: , ,

ReaderWmf

New version of Ab2d.ReaderSvg and ViewerSvg

by abenedik 20. August 2010 17:55

The best svg reader for WPF and svg to xaml converter for WPF and Silverlight is now even better.

This release focuses mostly on making work with Ab2d.ReaderSvg easier. Now it is possible to get progress report when reading svg files (there are also two interesting samples about this). It is now easier to use GetXaml method when the read svg file has embedded images. Also the ResourceDictionaryWriter class (helper class to create ResourceDictionaries from svg files) is now greatly improved. With new protected fields and protected virtual methods it is now very customizable.

The reading engine also has some improvements. It fixes some of the special issues that were reported by error reporting in ViewerSvg. The number or error reports is now very low and this tells that the reading engine is already very good and can handle really most of svg files.

The problems with showing the exported xaml in Visual Studio 2010 designer for Silverlight are now gone. With the new version the GetXaml method sets Width and Height to Path element when it is called to create xaml for Silverlight. This is a workaround for a bug in Visual Studio - please vote for the bug on Microsoft Connect so it will be fixed as soon as possible.

The samples have also been updated. There are now a few more samples and they are now available for both Visual Studio 2008 and 2010.

The following is a list of all changes in Ab2d.ReaderSvg:

  • Added ProgressChanged event to ReaderSvg to get report progress when reading file.
  • Improved GetXaml method for Silverlight: Added workaround for displaying Paths in Silverlight in Visual Studio 2010 designer - set Width and Height to Path element.
  • Improved GetXaml method - now the images are written to xaml without need to specify ResolveImagePath delegate. The uri format can be specified with the new DefaultImageUriFormatString property in XamlWritterSettings.
  • Improved reading linked images (not embedded into svg file). Before an exception was thrown when the image file could not be located - now the image object is created but its Source is not set.
  • Fixed reading some svg files with embedded image that reported "Invalid length for a Base-64 char array." error (used custom base64 reader instead of .Net method to read the string).
  • Fixed problems with reading svg files from Microsoft Visio that have more than one layer with the same name defined.
  • Improved ResourceDictionaryWriter class to make it much more customizable. The AddFile and AddStream methods now work correctly. The usedSvgReader, geometrySettings and xamlWritterSettings fields are now protected so they can be changed in derived class. Also the methods CreateReaderSvg, CreateXamlWriterSettings, ReadSvgFile, ReadSvgStream, GetXaml, GetRootResourceKey and ResolveResourceKeyCallback are now protected and virtual so they can be overriden in derived class.
  • Added AddHiddenElements property that specifies if hidden elements are read. If the value of AddHiddenElements is true, than hidden elements are read and have their Visibility property set to Hidden or Collapsed (depends on using display or visibility attribute in svg file).

 

 

As always the ViewerSvg application has also been improved.

As with Paste2Xaml the ViewerSvg can now also change the size of read elements to any custom size. This is not done with only adding a ScaleTransform to the root element (as in previous versions) but now the positions, sizes and other values are changed to fit into the new size.

The improvements in Ab2d.ReaderSvg are also reflected in ViewerSvg. There is now an option to read or skip reading hidden elements. The export dialog also has some new settings - see the following is a screenshot:

ViewerSvg export dialog

 

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