AB4D Forum

Full Version: Text in DXScene using WpfModelVisual3DNode and TextVisual3D
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm trying to get text working in my DXScene. I'm rendering directly to a winforms control by calling Render on my DXScene object. This seems to be working fine. I'm successfully rendering mesh data.

But I'm unable to get text working. This is what I'm trying:

Code:
var txt = new TextVisual3D
{
  Text = "this is some text yo!",
  LineThickness = 3,
  Position = new Point3D(0, 0, 0),
  TextDirection = new Vector3D(1, 0, 0),
  UpDirection = new Vector3D(0, 1, 0),
  TextColor = System.Windows.Media.Colors.HotPink,
};
obj.AddChild(new WpfModelVisual3DNode(txt));
_dxScene.RootNode.AddChild(obj);

Should this work? If not, what should I do instead? Do I need to render to a viewport3d instead? It isn't clear to me how to use all the functionality given some seems to be designed for using the wpf viewport3d control, but it is unclear whether I should be able to use this functionality in the DXScene or not, and if so how that works.

I've not been able to find any documentation that describes this dichotomy in your framework - am I missing something?

Thanks!
When you do not use DXViewportView and use only DXScene, some functionality that is defined by Ab3d.PowerToys library does not work.

By default, 3D lines do not work in this way.

But in the DXEngine v2.3 it is possible to enable rendering 3D lines with a little trick.
You need to create an instance of DXViewportView. This will enable preparing line data for DXEngine in the Ab3d.PowerToys library. You do not need to use the created DXViewportView - just the code in its constructor needs to be executed.

I have improved that and in the next version of Ab3d.PowerToys (v8.2) this will not be needed anymore.


After the DXViewportView constructor is called, you can create 3D lines and also TextVisual3D (uses 3D lines internally) and then you can add it to DXScene with creating WpfModelVisual3DNode (as you do in your scene).

Note that you will not be able to render lines with arrows because arrows are not fully hardware accelerated - their geometry is prepared in code in Ab3d.PowerToys library. But you can use ArrowVisual3D instead.
Fantastic, that works, thanks.

Do you have any idea about the performance of your text visual as compared to adding lines of similar complexity?

Put another way, if I created a ScreenSpaceLineNode with a ScreenSpaceLineMesh using the exact same geometry as the text visual, would one perform better than the other?

Thanks!
TextVisual3D object is converted into ScreenSpaceLineNode by DXEngine so the performance is the same - only there is a very small initialization overhead but this is not noticeable and you get an easier to use API with TextVisual3D. 

But if you would change the text data very frequently and have many (thousands) TextVisual3D objects, then it would be better to use lower level API that is provided by ScreenSpaceLineNode.


You can get a dump of created SceneNodes with calling DXScene.DumpSceneNodes() method (for example in Visual Studio's Immediate Window).

An even easier way to see that is to start DXEngineSnoop tool (installed into Tools folder), connect to your application with 3D scene and then in the DXEngineSnoop menu select option to show scene nodes. It is greatly recommended to use this tool especially when customizing the DXEngine (note: the full source code of the Diagnostics window can be seen in the Ab3d.DirectX.Client.Diagnostics project).
Fantastic, thanks so much for the info. In my situation I have potentially thousands of individual text scene nodes and it seems quite slow. I think it is the text that is slowing it down although I'm not 100% sure about that yet, I'm focussing elsewhere.

The text for each node is quite small (maybe 2-4 lines each with up to 4 numeric characters) but there may be up to 5000 of them.

Anyway, I'll take a look at the lower level API and see how I go.
The best way to see why the performance is not good is to use DXEngineSnoop tool (see also https://www.ab4d.com/DirectX/3D/Diagnostics.aspx) - if the DrawRenderTime is big, then the time to execute all draw calls is long - in this case, it is recommended to try to reduce the number of objects. Maybe you can combine some texts into one object.