Ab4d.SharpEngine beta 2 comes with many new samples

by abenedik 18. April 2023 09:30

The second official beta version of the new cross-platform 3D rendering engine has been published. You can get the new samples from: https://github.com/ab4d/Ab4d.SharpEngine.Samples (on GitHub also click on the Watch button to be informed of future changes).

The new version comes with many new samples that demonstrate a lot of functionality of the new engine. There are samples that demonstate cameras, mouse camera controller, materials, lights, different 3D objects and lines, model importers and animation. The following screenshot shows the samples running in a WinUI 3.0 application:

Ab4d.SharpEngine Vulkan samples in WinUI 3.0 application

You can see that the samples are organized in a similar way as the samples for Ab3d.PowerToys and Ab3d.DXEngine.

Because the engine can run on multiple platforms and UI frameworks, most samples are now defined in a common samples project (Ab4d.SharpEngine.Samples.Common). That project uses a generic UI provider that can create UI elements like Labels, CheckBoxes, ComboBoxes, Sliders, Buttons and other elements that are required for the sample. Then the project for the specific platform references that common project and provides rendering of the UI. This way the same sample code can be used for WPF, WinUI and Avalonia. The Avalonia sample works on Windows and without any change in code the same sample also runs on Linux and macOS (see screenshot with Rider IDE in the back):

Ab4d.SharpEngine Vulkan samples in Avalonia application running on Linux

Ab4d.SharpEngine Vulkan samples in Avalonia application running on macOS

There are also two special samples for Android. They show only a single 3D scene. Their purpose is to demonstrate two different ways on how to initialize the engine in Android. From there on, the code to create and manipulate the 3D scene is the same as for desktop operating systems. The following screenshot shows the engine running in Android:

Ab4d.SharpEngine sample in Android application

The current version does not support iOS yet. The problem there is that AOT (ahead-of-time) compilation that is required for iOS does not support function pointers (https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-9.0/function-pointers) that are used by the engine to communicate with Vulkan. It is interesting that for Android or desktop it is possible to use AOT compilation and there function pointers work without problems. If you have any recommendations on how to use function pointers on iOS, I would be glad to hear that. Otherwise, it seems that a special build of SharpEngine will be required for iOS. That build would use a different and less efficient way to call Vulkan functions (using standard delegates and UnmanagedFunctionPointer attribute). This needs some additional research so the support for iOS has been moved to the next version.

The major goal of this beta version was to provide new samples that demonstrate how to use the engine. But there were also many improvements behind the scene.

The most important is updated code for sharing the rendered 3D scene with WinUI and Avalonia. In this case the 3D scene that is rendered by Vulkan stays in the GPU memory and is shared by the WinUI or Avalonia. The code for WinUI now uses SwapChainPanel instead of SurfaceImageSource. This is faster and better supported - SurfaceImageSource had problems on older computers or computers with integrated Intel GPU. In Avalonia the previous code for sharing texture created OpenGL vertex and pixel shaders and rendered the shared Vulkan texture to an OpenGL context. This was very complex and did not work well on all platforms. The developers of the Avalonia UI were also aware that this was not done well, so we worked together to define a new interface that can be used for sharing an external texture with Avalonia (after some private discussions with the developers the following was issued: External GPU memory interop (OpenGL, Vulkan, DirectX). The new version of the engine uses that new interface. This works very well so that shared texture can be used on computers where the previous approach did not work. What is more, Avalonia currently uses OpenGL to render its user interface, but there already exists a build of Avalonia that uses Vulkan to render the interface. This will be publicly available in one of the future versions. This means that it will be even easier and faster to share the 3D scene created with Ab4d.SharpEngine because whole application could use the same Vulkan device.

If you have not tested the beta 1 version, I would like to encourage you to try the new beta version. If you know how to create a 3D scene by using Ab3d.PowerToys, then it should be easy to work with the new library because the general concepts are the same. There are some differences in object names, but when working with the new engine, you will quickly see that the new API is much more polished than when using the Ab3d.PowerToys and Ab3d.DXEngine. The problem with those two libraries was that they were based on WPF 3D object model. That object model was extended by Ab3d.PowerToys and later by Ab3d.DXEngine objects. Because of this in those two libraries there exists multiple ways to define 3D objects: based on GeometryModel3D, Visual3D and on SceneNodes from DXEngine. Now, the 3D objects are all derived from SceneNode. All object grouping is done by GroupNode (instead of Model3DGroup, ModelVisual3D, ContentVisual3D, SceneNode). Also, when using Ab4d.DXEngine you need to use some tricks (using SetDXAttribute method) to define advanced properties on WPF materials. Now all material properties are directly accessible.

As promised before, the work on Ab3d.PowerToys and Ab3d.DXEngine will not stop. There are already many improvements and fixes in the current development version. Now I will focus on providing some additional new features and then prepare a new release. So if you have any recommendations, it is now a great time to provide that.

Tags: , ,

SharpEngine

The first beta version of a new cross-platform rendering engine has been published

by abenedik 15. December 2022 14:03

I am really glad to inform you that the first beta version of the Ab4d.SharpEngine has been published. 

Ab4d.SharpEngine logo

Ab4d.SharpEngine is a cross-platform 3D rendering engine for desktop and mobile .Net applications.

The existing rendering engine, Ab3d.DXEngine, uses DirectX 11. Because of that, it can only be used on Windows. The new engine uses Vulkan API.  And because it is built using .NET 6, the new engine is truly cross-platform and can be used on Windows, Linux (including Raspberry PI 4), macOS, Android and iOS. 

I know that now you would want to ask me: what about web? I am monitoring the status of Blazor with WebAssembly. I think that things are developing in the right direction but currently this technology is not yet capable enough for a more complex application with 3D graphics. The main problem is that WebAssembly does not have direct access to the Canvas, so each call needs to go through java script. Because 3D rendering engine needs to execute a lot of WebGL (or WebGPU) calls, this would be very slow. Also, in my opinion web will always be slow for high end and demanding 3D graphics. Anyway, the long time plan is to also provide support for web so that the same c# code could also run in a browser.

Vulkan is also an API with very little overhead, which makes it much faster than DirectX 11. What is more, Vulkan supports all new features that are added to new graphics cards, including ray tracing. This does not mean that Ab3d.DXEngine already supports ray tracing, but it is possible to add that and other new features in the future.

Because the new rendering engine was built from the ground up, it was possible to use all the know-how and experience from Ab3d.PowerToys and Ab3d.DXEngine to make its programming API clean and very easier to use. I admit that when using Ab3d.DXEngine and Ab3d.PowerToys, the API is not very nice in all cases. The Ab3d.PowerToy was built on top of WPF 3D objects that are not very extendable, so some compromises were needed (for example, cameras are derived from FrameworkElement and not from Camera). Also, Ab3d.DXEngine converts all WPF 3D and Ab3d.PowerToys objects into its own objects. This means that the application has two versions of each object. In other cases, some tricks must be used to provide Ab3d.DXEngine features to Ab3d.PowerToys and WPF 3D objects (for example using SetDXAttribute). Therefore, having an easy-to-use API was one of the primary goals of the new engine. Please contact me if you have any recommendations or find something that bothers you. 

 

I hope that you are already excited about the new rendering engine.
In that case, just jump into the samples page on GitHub: Ab4d.SharpEngine.Samples

There you will find solutions that show how to use the Ab4d.SharpEngine with WPF, AvaloniaUI, WinUI 3, SDL, Glfw. Some samples will run only on Windows; some will also run on Linux and macOS. Some will run on Android. iOS samples are coming in the near future. I also plan to add support for WinForms and MAUI. If you know of any other well know UI framework, please let me know and I will try to provide support for that too.

Check also the readme on GitHub as it provides a lot of other information.

 

Because you are an existing user of Ab3d.PowerToys and Ab3d.DXEngine, you are probably very interested in comparing the new engine with the current libraries.

Let's start with advantages of Ab3d.DXEngine and Ab3d.PowerToys:

  • Ab3d.DXEngine and Ab3d.PowerToys are very mature products that are tested and proven in the "field" by many customers.
  • Those two libraries currently provide more features and come with more samples that can be used as code templates for your needs.
  • Ab3d.DXEngine supports multi-threading and currently provides faster 3D rendering in many use cases.
  • Ab3d.DXEngine can use software rendering when there is no graphics card present (for example in virtual machines or on a server).
  • Ab3d.DXEngine and Ab3d.PowerToys can run on older .Net versions, including .Net Framework 4.5+.

Advantages of Ab4d.SharpEngine:

  • Ab4d.SharpEngine can run on multiple platforms. You can start writing code for Windows and later simply add support for Linux, macOS, Android and iOS. Or port just a smaller part of the application to other platforms.
  • Ab4d.SharpEngine uses Vulkan API that is the most advanced graphics API. It is actively developed and gets new features as new versions of graphics cards are released. This provides options to support all current and future graphics features (for example Ray tracing - not possible with DirectX 11).
  • As mentioned before, Ab4d.SharpEngine has a very clean and easy to use programming API. 
  • Working with WPF objects is very slow (accessing DependencyProperties has a lot of overhead). Also, Ab3d.DXEngine needs to convert all WPF objects into its own objects. Working with objects in Ab4d.SharpEngine is much faster.
  • Vulkan is a significantly faster graphics API than DirectX 11. Though the Ab4d.SharpEngine does not use all the fastest algorithms yet (no multi-threading), in the future the engine will be significantly faster than Ab3d.DXEngine.
  • Ab4d.SharpEngine is built on top of .NET 6 and that provides many performance benefits because of using System.Numerics, Span and other improved .NET features.
  • In the future Ab4d.SharpEngine will provide more functionality than Ab3d.DXEngine with Ab3d.PowerToys.

 

So, if you have a big and complex application that uses Ab3d.PowerToys and Ab3d.DXEngine, I would not recommend you to try to port it to the new engine. You could not just copy and paste the code to the new engine. Though the ideas and principles of both engines are still the same, for example there are TargetPositionCamera and MouseCameraController - both with almost the same properties and methods. But there are many smaller differences, for example BoxVisual3D is now BoxModelNode. Anyway, if you know how to use the existing engine, you will feel very familiar with the new engine also.

But if you are starting to build a new application with 3D graphics or would like to port some smaller part of your big application (for example a viewer with a few additional functionalities) to a more mobile format, then the new engine is a perfect choice for that. Also, if you are curious about how to program in .NET for other platforms or will have a little bit more time in December, I would be really glad if you could try the new engine and provide some feedback (you can also use Discussions or Issues on GitHub, or simply use email, forum or feedback form).

But please don't be too demanding. This is the first open beta and some things may not work as expected. In those cases, please see the Troubleshooting section on GitHub for more info.

 

Let me also share the planned road map for the new engine.

In the following weeks and months I will try to release new beta versions with fixes and improvements. After a few months, probably in Q2 or maybe in Q3 2023, the first production-ready versions should be released. Maybe some parts of the engine will remain in beta, for example AvaloniaUI, MAUI, macOS and iOS support. The plan is to have the main and most common parts ready for production: Windows (WPF, WinForms, SDL, Glfw), major Linux distributions (SDL, Glfw) and Android. 

 

And finally, I would like to assure you that Ab3d.PowerToys and Ab3d.DXEngine will still be actively developed, will get new releases and features and will have full support in the future!

 

I hope that the new engine will allow developers to use the beautiful c# language to create amazing apps with 3D graphics that could run on all possible platforms. If you have the right tools, then even 3D graphics is not hard!

And of course: Merry Christmas and happy new year!

Tags: , ,

Ab3d.PowerToys | DXEngine | SharpEngine

New Ab3d.PowerToys and Ab3d.DXEngine with .Net 7 build

by abenedik 10. November 2022 19:58

New versions of Ab3d.PowerToys and Ab3d.DXEngine have just been released. The new versions bring many great new features and because they were released just after the .Net 7 release, the new versions also come with a new .Net 7 build.

Because this release is also linked to a new .Net version release, this blog post also shows some performance numbers related to running Ab3d.DXEngine by using different .Net versions. See the end of this blog post for more information.

 

Now back to new features. In the past there were many requests to improve the triangulator that was part of the Ab3d.PowerToys library. If we want to show a filled 2D shape, for example an ellipse, as a 3D object, we need to first convert 2D points to 3D points and then define the triangles that will connect the positions. This can be done by using a triangulator. The old version of Ab3d.PowerToys already has a triangulator, but it could process only simple polygons. This was improved in the new version so that the new triangulator can now process multiple polygons and also supports polygons with holes.

Triangulated 3D text

As seen from the image above, this allows generating a 3D mesh from any text (text is represented by a series of 2D shapes). The sample also shows how to generate a 3D mesh from multiple 2D shapes (ellipses, rectangles, paths with bezier curves, etc.). The lower part of the sample shows individual triangles that were generated. There is also a Slider control that can be used to show how the triangles are laid out from the first to the last.

In some cases the new triangulator can also be used instead of Boolean operations. This requires that the main 3D object has a constant height (for example represents a sheet of metal or wood). In case when user wants to subtract a cylinder or some other object that can be extruded from a 2D shape, then using the triangulator instead of a Boolean subtract operation will be much faster and will provide better results (fewer triangles will be created).

Another highly requested feature is better support for collision detection. By using bounding boxes it was already possible to do some collision detection. However, because the bounding box is only an approximation of the space occupied by the object, this was not very precise. The new version of Ab3d.DXEngine brings a new MeshCollider object that can be used to check if one 3D position is inside another 3D mesh. By checking all the positions of one mesh, it is possible to check if one mesh collides with another mesh. The new sample demonstrates that (when checking the sample use arrows, PgUp and PgDown keys):

MeshCollider

An interesting new material type that will greatly simplify work for some users is the new FaceColorMaterial. It supports defining different colors for each of the triangles in the mesh. Before it was already possible to achieve that by using a VertexColorMaterial. But this required that the positions of the mesh were duplicated so that each triangle used its own unique set of positions. Now this is greatly simplified because the original mesh can be used. What is more, by setting the alpha color to zero, the individual triangles can be discarded from rendering. The new sample nicely demonstrates that:

Face color material

Improving the performance of the Ab3d.DXEngine is a never-ending job. This version brings two new performance improvements. The first one is for those that use DXEngine's SceneNode objects and meshes. The new version significantly improves performance of hit testing because it can use OctTree objects on DXEngine's meshes. Before OctTree objects were created only from WPF's MeshGeometry3D objects. 

OctTree object organizes the triangles in a mesh in hierarchically organized 3D space regions so that when triangles are checked if they are intersected by a 3D ray, the number of checked triangles is much much lower. This makes hit testing almost instant even on huge meshes.

Now the DXScene.DXHitTestOptions.MeshPositionsCountForOctTreeGeneration property is also used when doing hit tests on DXEngine's meshes. Its default value is 512. This means that an OctTree will be automatically generated when the mesh has more than 512 positions. You can also manually generate the OctTree by calling the CreateOctTree method.

The second performance improvement will be great news for those who are rendering many polylines (lines where line segments are connected to each other). Multiple polylines are usually defined by a single MultiPolyLineVisual3D object. But though one object is used to define multiple lines, each line was still rendered by its own DirectX draw call. And if there were thousands of lines to render, it took quite some time to issue draw calls for each line. The good news is that with the new version, all the polylines can be rendered with only one draw call. This means that there will be almost no CPU cost for rendering any number of polylines.

As always, there are also many other improvements and fixes. See the change logs for more details here: Ab3d.PowerToys changelog and Ab3d.DXEngine changelog. Also get the latest samples (Ab3d.PowerToys.Wpf.Samples and Ab3d.DXEngine.Wpf.Samples) and check for UP and NEW icons to see new or updated samples.

 

And as promised before, let me show you some additional performance numbers. Each .Net version brings many performance improvements. There are new classes that can be used to write faster code. But also existing .Net code can run faster because each version improves the JIT compiler so it produces faster assembler code. The following graph shows how performance of the Ab3d.DXEngine can be improved when the application is run in a newer .Net version (running in .Net 4.8 is shown with a blue rectangle that represents 100% of the time; running in .Net 6.0 and .Net 7.0 executed the code faster and therefore the rectangles are shorter):

Ab3d.DXEngine performance in .Net versions

(1) "Multi-threading and caching" sample was run with showing 20000 boxes, using no background threads and disabled DirectX caching. The DrawRenderTime performance parameter measures the time that Ab3d.DXEngine needs to issue all DirectX draw calls. This requires going through all objects, checking their state, setting the DirectX state and calling DirectX Draw method. In this sample most of the time is spent in native DirectX code so the performance gains cannot be huge. But still, there is almost 10% better rendering performance just by using a newer .Net version.

(2) "Instanced animated arrows" sample was run with showing 1 million arrows. The graph shows values for the time that is required to calculate 1 million transformation matrices - each matrix is defined so that an arrow mesh will point toward the animated sphere. The values are based on highly optimized code (manually inlined and optimized math operations) that run on multiple threads (using Parallel.For).

(3) "Instanced animated arrows" sample showing 1 million arrows but this time the source code without any manual optimization is executed. The graph shows that the new JIT compiler can greatly optimize the generated assembler and in this case can provide a 25% performance boost.

(4) "Transparency sorting performance" sample shows the performance of different sorting algorithms that sort 3D objects to prevent transparency artifacts (the sample was updated to show 7200 instead of 720 boxes). The values under (4) show the difference of sorting that sort WPF 3D objects and is implemented by TransparencySorter from Ab3d.PowerToy library. Working with WPF objects is not very fast and there will be no changes in the WPF to make this faster. So it is great news that only using a new version of .Net can significantly improve the performance.

(5) The values here are again from the "Transparency sorting performance" sample, but this time showing the performance improvements of the transparency sorting from Ab3d.DXEngine. The source code for this sorting algorithm is already highly optimized, but still newer versions of .Net can squeeze some more juice from that.

So, Microsoft, keep up the great work!

 

And finally, the first open beta version of the new Vulkan based cross-platform rendering engine will be available before the end of this year! Let's conclude with the new logo for the engine:

Ab3d.SharpEngine logo

Tags: , , , , , ,

Ab3d.PowerToys | DXEngine

New versions of 3D libraries released

by abenedik 28. April 2022 19:57

I am happy to inform you that new versions of Ab3d.PowerToys and Ab3d.DXEngine libraries have been published.

This is a maintenance release with many improvements, fixes, and some new features.

The most interesting new feature in the Ab3d.DXEngine is added support for XRayEffect. The XRayEffect can render objects that look as they would be photographed by an x-ray. This can be useful when you work on a complex model with many parts and want to select one part while the other parts are just barely visible. In that case it is possible to make other parts semi-transparent. Another option that is available with the new version is to use the new XRayEffect or XRayMaterial. This works especially well when showing models with many triangles and with curved shapes. See example (this is a screenshot from slightly modified XRayEffect sample):

X-Ray effect on Ab3d.DXEngine

The new XRayEffect can be also used in the updated "Model Viewer" sample in the Ab3d.DXEngine samples (to use it check the new "Use X-Ray material" CheckBox in the second tab).

Another new feature can be used by those who use object instancing to render thousands of objects and want to do fast hit testing on the instanced objects. In this case, the new version allows rendering instance id bitmap from instanced objects. This generates a bitmap where colors represent the ids of the instances. By checking the color at a specific pixel, you can get the instance id that was rendered at that screen coordinates. This can also be used to do a rectangular selection or selection of the instance around the mouse cursor.

Also, the standard RenderToBitmap method got an improvement. With the new version it is possible to get direct access to the memory of the rendered bitmap. This way you can reuse the WritableBitmap or use any other method of using the rendered image. This is very useful when you are calling RenderToBitmap method very often because you can optimize and reuse the used objects (before a new WritableBitmap object was created on each call of RenderToBitmap method and this could generate many objects on the large memory heap).

The new version also improves stability in case of disconnecting an external monitor. Stability is also improved in some cases when rendering through a remote desktop.

The previous version introduced two-sided material that doubles the performance of rendering models that had the same front and back side materials. But this did not work in all the cases. This version fixes this issue.

There are also some other fixes and improvements. See the full list here: https://www.ab4d.com/DXEngine-history.aspx

 

The Ab3d.PowerToys library also got a few new features and improvements.

One interesting new feature is an improved algorithm for extruding a shape along a path. Now you can use two new options. One is to preserve the size of the shape at junctions and the other is to preserve the orientation of the shape's Y direction. See screenshot (the right side shows the extruded model using the new option):

Extrude a shape along a path

The new version of the library also comes with an updated Assimp importer and exporter. It now supports reading embedded textures and saving textures into fbx and glft files. There is also a new native Assimp library v5.2.3 that should improve the accuracy of importing and exporting files (https://github.com/assimp/assimp/releases/tag/v5.2.3)

To see the full list of changes see the change log here: https://www.ab4d.com/PowerToys-history.aspx

 

You can get the new version by updating the NuGet packages or by downloading the new evaluation or commercial version from your User Account web page. Note if you are using libraries from NuGet and you have recently renewed the updated subscription, then you will probably need to generate a new license activation code for the new version to work (this code can be generated from your User Account web page).

 

The list of new features is not as long as with some previous versions. The reason for this is that a lot of development effort is now spent on the new Vulkan based rendering engine (Ab3d.SharpEngine). This new engine is progressing very well. This engine will be fully cross-platform so the same code should be able to run on many different hardware devices. Recently we were able to run the code that works on Windows and desktop Linux on Raspberry Pi with a small touch screen attached - see photo:

SharpEngine on Resberry Pi with touch screen (pre-alpha)

Such a setup makes the engine great for controlling some industry machines or equipment.

The engine can also work on Android:

SharpEngine on Android phone (pre-alpha)

Many features from Ab3d.PowerToys and Ab3d.DXEngine were already ported to the new engine. But before releasing an alpha version, the core of the engine still needs some polishing and testing. I expect that the first alpha can be released in a month or two. The plan is to release a closed alpha version and later an open beta version. If you are interested in trying the new engine, please write me an email or feedback and you will be informed when the alpha version is available. This will allow you to test the engine on your hardware and on your devices. It will aso give you some influence on which features will make it to the first official and production-ready version.

Tags: , , , , , ,

Ab3d.PowerToys | DXEngine | SharpEngine

Last major version of Ab2d.ReaderSvg and ZoomPanel published

by abenedik 17. December 2021 11:01

I would like to inform you that the last major version of Ab2d.ReaderSvg and ZoomPanel libraries have been published.

With this release both libraries have got special builds for .Net 5.0 and .Net 6.0. Also, both libraries are available as NuGet packages. Note that the version that is distributed through NuGet uses a different licensing mechanism than the version that is installed by the evaluation or commercial version installer. The same assembly from NuGet can be used for evaluation and commercial usage. The commercial usage can be activated by calling the SetLicense method. The code for that method can be obtained from the User Account web page.

With the support for the latest .Net versions and NuGet both libraries are updated to the latest standards. 

The Ab2d.ReaderSvg library also got some additional new features that improve reading some more complex svg files that use "use" or "marker" elements. See the changelog for more info.

Both libraries are used by many customers in many commercial products. In the last years, they have received many new features and fixes. This makes then are very mature.

The development at AB4D company is focused on 3D products. Therefore, the 2D products (including Ab2d.ReaderSvg and ZoomPanel) will get only limited support. Also, there are no major new versions planned. The future development will cover only simpler or critical issues or be based on custom development.

Tags:

ReaderSvg | ZoomPanel

New major versions for 3D libraries released

by abenedik 26. November 2021 10:08

I am happy to inform you that new major versions for Ab3dPowerToys and Ab3d.DXEngine libraries have been released. 

The Ab3d.DXDXEngine has reached version 5.0. This is the 21st release of the library. The Ab3d.PowerToys library has climbed even higher and has reached version 10.0, having the 34th release of the library. The high number of releases is even more impressive when checking the actual change logs (see https://www.ab4d.com/PowerToys-history.aspx and https://www.ab4d.com/DXEngine-history.aspx). The long list of new features and changes that were often requested by the users shows that the libraries have become very mature and that they can be used for many different types of business, technical and scientific applications with 3D graphics. To make the numbers even more interesting, the build number of the new version is set to 8000. Because the build number is calculated as the number of days since 1st January 2000, this means that this release has happened on the 8000th day of the new Millenium (on 26th November 2021).

The highlights of the new versions are:

  • New Model viewer sample.
  • Rendering two-sided materials in one render pass.
  • Triangles sorting for transparent meshes.
  • Updated assimp importer that can read 3D models from almost any file format.
  • Added FitIntoView method for FreeCamera.

 

The first great new added value of the new version is a new Model viewer sample:

DXEngine Model Viewer

This sample does not provide any new feature but demonstrates many features of the Ab3d.PowerToys and Ab3d.DXEngine libraries. And because almost any application with 3D graphics requires object loading, mouse selection, wireframe and solid object rendering and showing object hierarchy, the sample is an excellent source of code snippets that you can use in your applications.

You can also use the sample to inspect the 3D models that are loaded from many file formats with Assimp importer. As shown in the following screenshot, it is possible to show mesh normals, position indexes and triangle orientations for the selected model:

DXEngine Model Viewer

Additional information can be obtained when an object without children (a GeometryModel3D) is selected. Then clicking on the "Show info" button will show the details about the mesh with a generate c# code that defines the mesh (creating arrays for all positions, normals, texture coordinates and triangle indices).

I am sure that you will find the new Model viewer interesting. Now let me provide some information about new features. Let me start with some background knowledge.

In 3D graphics the most fundamental building block of a 3D object is a triangle. And each triangle has its front and its backside. By default the front side of the triangle is the side where the vertices are defined in counter-clockwise order. The backside is the other side where the vertices are defined in clockwise order (see more here https://www.khronos.org/opengl/wiki/Face_Culling). In 3D graphics you can assign one material to the front side of the triangles and another material to the back side of the triangles. When using a GeometryModel3D object, the front material is assigned to the Material property, and the backface material is set to the BackMaterial property.

Many times the 3D models are solid and closed so we cannot see inside the 3D model. In those cases we can render only the front sides of the triangles and skip rendering the backsides. This reduces the number of rendered pixels by half. For example, 3D box and 3D sphere are solid and closed models and therefore the graphics card does not need to render the inner sides of the triangles. But when rendering a 3D plane, opened cylinder or any other model with holes, the graphics card needs to render both front and back triangles (both Material and BackMaterial properties need to be set). This is needed because the user can rotate the camera to see the other side of the plane or inside the model. The other case when we need to render both sides is when the object uses semi-transparent material. There the user can see the inner side of the 3D model. The models that use the same material for both the front and back sides are described as using a two-sided material. Two-sided materials are used many times for all the objects in technical 3D graphics.

Usually, the rendering of two-sided materials is done in two passes. First, the backside of the material is rendered, then the front side is rendered. When rendering the backside, the DirectX rasterizer state needs to be changed to prevent culling (skipping) the backside. Also, the code in the shader needs to invert the normal vector so that the lighting calculations are correct. This means that rendering models with two-sided material requires two DirectX draw calls and therefore takes twice as much time as rendering models with single-sided materials (actually, there is also an additional performance penalty because of rasterizer state changes).

The new version of Ab3d.DXEngine can use the DirectX SV_IsFrontFace semantics (https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-semantics) that is used in the shader to check if the front side or the backside of the triangle is being rendered. This information is needed to invert the normal in the case of backside rendering. Also, the backside culling needs to be disabled in the DirectX rasterizer state. This allows the new version of Ab3d.DXEngine to render two-sided materials in one rendering pass. This means that 3D scenes where all 3D models have two-sided materials will be rendered twice as fast as before.

When using DXEngine's materials (supported by StandardMaterial, VertexColorMaterial, PhysicallyBasedMaterial and WpfMaterial), the two-sided rendering can be enabled by setting the IsTwoSided property to true. When using WPF 3D objects, then two-sided rendering will be used when the Material and BackMaterial on the GeometryModel3D are set to the same material instance. This will set the IsTwoSided property to true in the DXEngine's WpfMaterial that is created from the WPF's material. 

It is possible to prevent this new functionality by changing the static DXViewportView.UseTwoSidedMaterialsForSolidObjects and DXViewportView.UseTwoSidedMaterialsForTransparentObjects fields. As seen from the field names, there are different settings for solid and for transparent objects. By default, solid two-sided objects are rendered in one rendering pass (UseTwoSidedMaterialsForSolidObjects is true). But by default, transparent objects are still rendered in two passes (UseTwoSidedMaterialsForTransparentObjects is false) - first rendering the back material and then the front material. This is needed to preserve the rendered result as it was before. It is possible to set the UseTwoSidedMaterialsForTransparentObjects to true, but then it is recommended to set the new DefaultTransparentDepthStencilState field to DepthRead (from DepthReadWrite). This will render transparent objects in one render pass and correctly render the inner side of the objects. See the new "TwoSided materials" sample for more info.

DXEngine Model Viewer

 

The next new feature of the engine is the support for sorting individual triangles in a mesh. This may be required when showing semi-transparent meshes that have complicated geometry, as for example the following torus knot:

DXEngine Model Viewer

On the left the screenshot shows the object without sorted triangles. Red arrows mark the parts that are not correctly visible through the mesh. Green arrows indicate the correctly rendered pars of the object. Note, if the object would be rotated to the other side, then the correctly visible parts would change.

The new version of Ab3d.DXEngine has a highly optimized triangle sorting code that works on low-level triangles and positions data (WPF's MeshGeometry3D objects are not used because they are very slow). The code changes the data in the index buffer. After sorting is done on the CPU, then the changed index buffer needs to be sent to get GPU. Those two processes can take some time, so you should consider using triangle sorting only when really needed. 

Ab3d.DXEngine has got some other great new features and bug fixes. And there are also two new additional samples that are designed to improve understanding of GraphicsProfiles and different options to render wireframe lines. See screenshots:

DXEngine Model Viewer

DXEngine Model Viewer

 

The Ab3d.PowerToys library also got some great new features. In my opinion the most important new feature is an updated Assimp importer. The Assimp importer is a third-party native library that can import 3D models from more than 40 file formats. The previous version 5.0.1 of Assimp was released a long time ago, in January 2020. After that release, the library got many improvements and also some breaking changes that crashed the .Net wrapper. But because there was no increase in the library's version number, it was not possible to update the wrapper to work with the newer build of the library. Finally, on 20th November (last week) a new official version 5.1.1 of Assimp library was released. This meant that it was possible to update the AssimpNet (.Net wrapper for the native library) and the Ab3d.PowerToys.Assimp library (helper library that converts the read 3D models into WPF 3D objects). The new libraries improve support for many file formats and add some new file formats to the supported list.

Those two libraries and the compiled native Assimp library are available with the new Ab3d.PowerToys sample on GitHub (https://github.com/ab4d/Ab3d.PowerToys.Wpf.Samples/tree/master/lib). Those libraries are also installed by the evaluation installer of the AB4D products (https://www.ab4d.com/Downloads.aspx) and the commercial installer for the Ab3d.PowerToys library (available from User Account web page).

The new version of Ab3d.PowerToy also comes support for calling the FitIntoView method when using FreeCamera (a highly requested feature). This provides the same functionality to FreeCamera as available by the TargetPositionCamera.

 

As always, please update to the new versions and check the new samples projects (https://github.com/ab4d/Ab3d.DXEngine.Wpf.Samples, https://github.com/ab4d/Ab3d.PowerToys.Wpf.Samples). In the new samples check the samples that are marked with NEW and UP icons. The icons mark new samples and the samples that were updated in the last version (hovering the mouse over the UP icon will show you more information about the change).

Tags: , , , ,

Ab3d.PowerToys | DXEngine

New Assimp importer for Ab3d.DXEngine published

by abenedik 30. July 2021 14:22

In this short blog post I would like to inform you that a new Ab3d.DXEngine.Assimp library has been published. It can be used to import 3D objects from many file formats into Ab3d.DXEngine objects.


The library is available with full source code on GitHub: https://github.com/ab4d/Ab3d.DXEngine.Assimp.

 

It is also available as a NuGet packge: https://www.nuget.org/packages/Ab3d.DXEngine.Assimp

 

Before this new library was published, it was also possible to import 3D objects into Ab3d.DXEngine objects, but this required using Ab3d.PowerToys.Assimp library. That library first converted native assimp objects into managed objects in Assimp.Net library, then converted those objects into WPF 3D objects and finally converted that into Ab3d.DXEngine objects. This took much longer and required more memory.

 


Now with the Ab3d.DXEngine.Assimp library it is possible to convert the native assimp objects directly into the Ab3d.DXEngine objects. The library creates the following objects:

  • MeshObjectNode for objects with meshes
  • SceneNode objects for groups of objects
  • SimpleMesh<PositionNormalTexture> for meshes
  • StandardMaterial for materials


The new library is using a Silk.NET.Assimp library as a wrapper library (instead of an old Assimp.Net library that Ab3d.PowerToys.Assimp uses).

 

Because of Silk.NET.Assimp the new library can currently work only in x64 processes (I have added an issue to the Silk.NET.Assimp GitHub repository about the problem in x86 process so hopefully, this will be solved soon).

 

Though the Ab3d.DXEngine.Assimp is much faster then Ab3d.PowerToys. Assimp, it also have the following limitations compared to Ab3d.PowerToys.Assimp:

  • cannot read animation data (Ab3d.PowerToys.Assimp can read animations and even play skinned animations by using Ab3d.PowerToys)
  • cannot read polygon data (polygon indices are read by Ab3d.PowerToys.Assimp into MeshGeometry3D).
  • cannot export 3D scene into file by using assimp as an exporter.

 

Anyway, if you only need to import 3D objects and you are using Ab3d.DXEngine that in it worth checking the new importer. Some missing features will be added in the future versions.



 

As a sidenote, I would also like to inform you that at the beginning of this week, a new hotfix version of Ab3d.DXEngine was published. It fixes a few issues mainly related to using multiple DXViewportView objects. The change log can be read here: https://www.ab4d.com/DXEngine-history.aspx


If you are using multiple DXViewportView objects, then it is highly recommended to upgrade to that version.

Tags:

DXEngine