Read 3D models from obj files with new version of Ab3d.PowerToys

by abenedik 29. November 2013 13:40

Ab3d.PowerToys library continues to get great new features. The new version gets ability to read 3D models from obj files. This adds a great new value to the Ab3d.PowerToys library because now it is possible to import 3D objects directly with the library.
Obj file format is very common file format to store 3D models. The model data is written in simple text format.

The following screenshot shows a 3D ship model that was read with the new Ab3d.ReaderObj library:
ReaderObj screenshot

Because now it is possible to import 3D models only with Ab3d.PowerToys library, the question arises if we still need Ab3d.Reader3ds library to read 3ds files. The following are the main differences between obj and 3ds file format:
obj is a text file; 3ds is a binary file,

  • 3ds file can define hierarchy of 3D objects with object transformations; obj file does not support hierarchies and transformation,
  • obj file does not support animations,
  • 3ds file is not capable of storing texture file names that exceed the 8.3 format; file names in obj file can be in any length.



The main difference is that animations and object’s hierarchies are supported only by 3ds files. For example if you need to create 3D objects similar to that used in Robotarm sample where rotating one part of the robot also rotates all child objects, you will need to use 3ds files to store the hierarchies.
Anyway obj files are still very common to store simple 3D models.

I would also like to mention that the code that is used to read obj files is highly optimized to parse the values from text files very fast. Also when common methods like Split and Regex are used to parse large text files in .Net with the memory usage can be very high – many string instances can be created. The code in ReaderObj class has been optimized also in regard to memory usage to minimize the creation of many string instances.

The version also has the following new features and bug fixes:

  • Fixed performance of LinesUpdater when the camera or other property is not changed (before lines were recreated every time, now only when they need to),
  • Added additional override of Dumper.Dump with Model3D as paramter to write Model3D info to Visual Studio output or immediate window.


The new version also comes with a new very interesting arrows sample that animate the arrows in a very nice way. The following screenshot show the sample:
Arrows sample screenshot

You can also see the new sample in a new video that also shows some other samples.

Tags:

Ab3d.PowerToys

New major release of Ab3d.PowerToys library available

by abenedik 22. October 2013 21:04

I am really happy to announce that the v4.0 of Ab3d.PowerToys is now available. It brings tons of new features and updates. The most important new features are:
-    Added polygon triangulation, creating extruded and lathe 3D objects,
-    Improved EventManager3D for even simpler usage of mouse events on 3D objects,
-    Added support for upcoming Ab3d.DXEngine library that will be able to render WPF 3D graphics with full DirectX 11 hardware acceleration.
-    Many new very interesting samples that show how easy is to create amazing 3D applications.

Polygon triangulation is a technique that converts a 2D polygon into triangles that can be used to define a 3D object. This makes it easy to create extruded objects – object that are created with extruding a 2D shape into a 3D world. The following image shows a screenshot from a sample that demonstrates those two techniques. The 2D shape is defined on the left side. It is the base for the 3D object that is shown on the right.

Ab3d.PowerToys Extrude

Lathe 3D objects are objects that are created be rotating the shape around an axis. The following image screenshot is taken from the sample that demonstrates how to create lathe objects. On the rights side the shape is defined by drawing the red lines. It is then rotated around up axis and the 3D object shown on the left is created. As seen on the 3D object it is also possible to define which edges are hard and which are soft.

Ab3d.PowerToys Lathe creator

Because we can now easily create lathe objects, we can also easily create 3D arrows. They can be created with the new ArrowMesh3D, ArrowVisual3D or ArrowUIElement3D objects. The following image shows many 3D arrows with different colors (screenshot from the new sample - still under development).

Ab3d.PowerToys Arrows sample

As mentioned before, another big improvement in this library was made with EventManager3D. EventManager3D can be used to simply subscribe to 3D objects just as they were normal FrameworkElements. For example the following code subscribes to some mouse events:

var eventSource3D = new Ab3d.Utilities.VisualEventSource3D(MyBoxVisual3D);
eventSource3D.MouseEnter += OnBoxMouseEnter;
eventSource3D.MouseLeave += OnBoxMouseLeave;
eventSource3D.MouseClick += OnBoxMouseClick;

var eventManager = new Ab3d.Utilities.EventManager3D(MyViewport3D);
eventManager.RegisterEventSource3D(eventSource3D);

The new version of Ab3d.PowerToys adds the following additional functionality to the EventManager3D:

 

  • Added RegisterExcludedVisual3D and RemoveExcludedVisual3D methods to EventManager3D – used to define Visual3D objects that are excluded from hit testing.
  • Added CustomEventsSourceElement property to EventManager3D - it can be set to any FrameworkElement that will be used as source of mouse events instead of TargetViewport3D.
  • Added MouseMove event to EventManager3D.
  • Added FinalPointHit to all EventArgs used in EventManager3D event handlers - it gets the transformed 3D point that was hit by the mouse (if Visual3D uses Transformation, than HitPoint will be wrong, but FinalHitPoint will be transformed).

Ab3d.PowerToys can help you in all stages of development – also during debugging. In the Ab3d.Utilities.Dumper there are many methods that can be used to get nicely formatted info about MeshGeometry3D, Model3D, Transform3D, Material or Matrix. With the new version it is now possible to specify the format string used to format the values (this allows control of the number of displayed decimals). The new version also adds two new methods to Dumper class: DumpMeshInitializationCode and GetMeshInitializationCode. They can be used to generate the complete c# source code that can be used to create the MeshGeometry3D with all the Position, TriangleIndices, etc.

This is not all. The following are the additional new features and fixes:

  • Added CreateMouseRay3D to BaseCamera - it can be use used to calculate the 3D ray that goes from the mouse position into the 3D scene.
  • Improved Refresh method in LinesUpdater - calling this method now forces to redraw all visible lines.
  • Added MaxLineArrowLength and LineArrowAngle to LinesUpdater to better control the size and shape of the arrows on 3D lines.
  • Fixed LineWithTextVisual3D when it was created in code behind and the properties were set without using BeginInit and EndInit methods.
  • Fixed recreating the content of 3D objects derived from Visual3D (if initially IsVisible was set to false and was then set to true the object was not shown under some circumstances).
  • Added many possibilities to change the CameraAxisPanel with overriding CreateAxisVisual, SetAxisLength, SetAxisColors or EnsureAxisTextBlocks (the later also existed before)
  • Improved performance of Box3D geometry mesh creation when X, Y and Z segments count is 1 (simple box with 2 triangles for one plane) - the mesh is now created 10 times faster.
  • Moved initialization of RotationCursor in MouseCameaController from constructor to OnLoad event handler - this prevented calling virtual method in constructor.

Besides new features in Ab3d.PowerToys there are also some new very interesting samples that demonstrate the use of the library. Extrude and Lathe samples were already mentioned. I would also like to show the screenshot of the new “Distance measurement” sample:

Ab3d.PowerToys 3D distance measurement sample

The sample uses HeightMap (also part of Ab3d.PowerToys), 3D lines and custom hit testing (uses CreateMouseRay3D method on camera) to show the distance between two points in 3D world.

Another interesting new sample is Objects inspector. It can display many information about the selected object – shows individual triangles with TriangleIndice index, normals, all positions, XAML text and other data. The following is the screenshot of the sample:

Ab3d.PowerToys Objects inspector

Lastly, the new version of Ab3d.PowerToys adds support for the upcoming Ab3d.DXEngine.

The Ab3d.DXEngine is a brand new 3D rendering engine that can render WPF 3D graphics in hardware accelerated DirectX 11. This means a huge performance boost and what is more it allows many customizations and tweaks of the displayed graphics. Do not get me wrong – I still think that WPF 3D is great for business applications that need 3D graphics. But it has its limits. When it comes to very complex 3D objects, the existing rendering engine based on DirectX 9 just cannot use the full power of the GPU. Another limitation is that the current WPF 3D engine is a closed box – you cannot extend it in any way. If you would like to use some other shading technique, this is not possible. Even simple task as showing 3D lines is kind of a hack in WPF 3D. What is more, the new engine can be used with just very minimal change in the code.

The new engine will be soon ready for the first alpha version. But before going public with the new engine, I would like to test it with some of our partners. I already have a few interested Ab3d.PowerToys customers that would like to try the new engine. If you are interested in that, please contact me to our email or with using Feedback page.

Tags:

Ab3d.PowerToys

New maintenance release for almost all products published

by abenedik 15. October 2013 23:02

After quite a long time I am happy to announce that a maintenance release for the following products has been released:

  • Ab2d.ReaderSvg with ViewerSvg,
  • Ab2d.ReaderWmf with Paste2Xaml,
  • Ab2d.ZoomPanel,
  • Ab3d.Reader3ds with Viewer3ds.

 

New version mainily include some bug fixes and improvements that were created based on users feedback.

The following is the what's new list:

 

Ab2d.ReaderSvg

  • Fixed reading text with gradient fill or stroke brush.
  • Prevent throwing exception when incorrect number text was used for numbers.
  • Invisible objects (Visibility != Visible) are not exported to geometry any more.
  • Shapes with Opacity set (Opacity < 1.0) are now correctly exported as geometries.

 

Ab2d.ReaderWmf

  • Added reading images from EMR_ALPHABLEND records. Note that usually those images are not rendered correctly because the blend dwRop operations are not supported by WPF, but at least user can get the image and convert it manually to a transparent image that could be used to achieve correct results.
  • Added ResolveBitmapOperation that is called in processing EMR_ALPHABLEND record - here the user can change the bitmap to get correct results - for example convert black to transparent.
  • Invisible objects (Visibility != Visible) are not exported to geometry any more.
  • Shapes with Opacity set (Opacity < 1.0) are now correctly exported as geometries.

 

Ab2d.ZoomPanel

  • Fixed using ZoomPanel under some circumstances when viewbox limits is set.

 

Ab3d.Reader3ds

  • Small fix for a problem that can occure when one object has multiple materials assigned.
  • Improved reading broken files - no exception is thrown when the animation data for camera is broken.

 

You could say that this is not much for quite a long time since last update. And you would be right.

The reason for that is that I am preparing a new major release of Ab3d.PowerToys which will be hopefully ready until beginning of the next week. It will have much much more to show.

And that is not all. With the release of the new version of Ab3d.PowerToys I will also announce a brand new project that I have been working on for almost a year. I am very excited about that project and I am sure you will also like it.

Tags: , , ,

Reader3ds | ReaderSvg | ReaderWmf | ZoomPanel

TrueTransform added to ReaderSvg and ReaderWmf

by abenedik 21. June 2013 10:16

For quite some time it was possible to transform the read objects in ViewerSvg and Paste2Xaml. I am not talking about simply adding a transformation to read objects but to actually change all coordinates, sizes and other values with the specified transformation.

For example after reading a svg file we get the following xaml (some common properties were removed to simplify the xaml):

<Canvas Width="422.425" Height="208.895">
    <TextBlock Text="text1" FontSize="10" Canvas.Left="68.571" Canvas.Top="103.145"/>
    <Path Stroke="Black" StrokeThickness="3" StrokeMiterLimit="2" 
          Data="M366.43,67.029C358.951,54.888 368.807,24.872 384.677,34.264 394.346,39.986 389.365,72.847 384.677,80.68 384.384,71.342 374.133,66.51 366.43,67.029z"/>

In Export dialog in ViewerSvg it was possible to transform this with specifying custom width (instead of 422.425) we could set the width to 100. After transformation the xaml is:

<Canvas Width="100" Height="49.5">
    <TextBlock Text="text1" FontSize="2.368" Canvas.Left="16.233" Canvas.Top="24.441"/>
    <Path Stroke="Black" StrokeThickness="0.711" StrokeMiterLimit="2" 
          Data="M86.744,15.883C84.974,13.006 87.307,5.894 91.064,8.119 93.353,9.475 92.174,17.262 91.064,19.118 90.995,16.905 88.568,15.76 86.744,15.883z"/>

 
As seen from xaml, the transformation changed the FontSize, position in canvas, StrokeThickness and also path data. ViewerSvg and Paste2Xaml used an internal TrueTransform class that performed the transformation.

This can be very useful in many cases:

  • When creating graphics for WPF, Silverlight or WinRT the graphics elements can be created in a drawing application and can have any possible dimension. But if your application needs graphics element that would have size 100 x 100, it is very convenient to transform the graphics into the required dimensions.
  • Some drawing applications (for example Inkscape) allow users to draw in real units (in mm), but when the drawing is saved into svg file, all the units are converted to pixels. With using TrueTransform it is possible to convert the coordinates and other data back to mm units.


Now this functionally is available in Ab2d.ReaderSvg and Ab2d.ReaderWmf libraries also. This means that you can now also use TrueTransform in your applications.

The simplest way to use TrueTransform is to use Transform or TransformFromPixelsToMM methods on ReaderSvg or ReaderWmf class. The Transform needs two parameters: the first one is a Transform object (can be ScaleTransform, TranslateTransform, TransformGroup, or any other Transform); the second is a Boolean that specifies if the LastReadViewbox (property of ReaderSvg and ReaderWmf) is also changed – if true this means that GetXaml method will return the xaml of the transformed objects. The TransformFromPixelsToMM method can be used to transform from pixel to real units.

It is not only possible to transform the objects that are read from svg or metafiles but also almost any other objects – this can be done with Ab2d.Common.ReaderSvg.TrueTransform (or Ab2d.Common.ReaderWmf.TrueTransform) class.
 

ReaderSvg also got a new property – SvgCreator. It is an enum that is set after reading svg file and specifies the application that was used to create svg file. Currently the following applications are recognized: Microsoft Visio, CorelDraw, Adobe Illustrator and Inkscape.

 

There is also a new sample that come with ReaderSvg that demonstrates the new transformations.


As always if you are new to our tools, you are most welcome to download a 60-day trial from the Download page. Existing customers can get the updated versions from their User Account page.

Tags: ,

ReaderSvg | ReaderWmf

Maintenance releases for Ab2d.ReaderSvg and Ab2d.ReaderWmf are now available

by abenedik 15. May 2013 21:05

I am happy to inform you that a new version of Ab2d.ReaderSvg (svg reader for WPF) and Ab2d.ReaderWmf (metafile reader for WPF) have been published.

Ab2d.ReaderSvg got the following improvements:

  • Fixed reading numbers defined with em unit (for example: "123.45em")
  • Fixed writing Image.Stretch into XAML
  • Added writing HorizontalAlignment and VerticalAlignment into XAML when exporting Image (when using preserveAspectRatio svg element)

Ab2d.ReaderWmf got the following improvement:

  • Improved positioning some elements (in case ViewPortExtentX or ViewPortExtentY is set)

 

All those fixes are based on the user's feedback. The small number of reported issues and fixes shows that both products are very mature and work very well for the customers.

Tags: ,

ReaderSvg | ReaderWmf

Improved version of ZoomPanel available

by abenedik 20. March 2013 22:13

I am happy to say that a new version of ZoomPanel control is available.

After some straggling to fix some problems with using ViewboxLimits, FitToHeight and FitToWidth I have decided to rewrite part of the code again. Hopefully this time the ZoomPanel should work regardless of the ViewboxLimits, content size and available ZoomPanel size.

There are no new features in this version. I think that ZoomPanel already has many great features and is a complete solution for any possible scenario that needs zooming and panning.

As always the existing customers can download the new version from their User Account page. Others can try the new version with downloaded the new evaluation version.

Tags:

ZoomPanel

Minor improvements for Ab3d.Reader3ds, Ab2d.ReaderWmf and Ab2d.ReaderSvg published

by abenedik 15. January 2013 13:54

I would like to inform you that new versions for Ab3d.Reader3ds, Ab2d.ReaderWmf and Ab2d.ReaderSvg has been published.

The new version contains a fix for generating object names for exported XAML. A bug in one of the previous version prevented the exporter code to check and fix the object's name.

There is also an additional minor improvement in Ab2d.ReaderWmf library that now correctly position text is some of the rare cases.

Tags: , ,

Reader3ds | ReaderSvg | ReaderWmf