Reputation: 1508
I am creating a WPF application with a Viewport3D and inside the viewport I have meshes with text on them. The text is different for each of the mesh. (This means that I can have a single reference for a material for the regular meshes, but for the text I need to create different materials every time.) I have also froze all the regular meshes since they are static.
However I can create any number of meshes, with a SolidColorBrush, that I want and the performance stays stable. (I have tried up to about 700 - 800 meshes)
However if I implement the text meshes the performance drops drastically. For example when I have around 200 regular Meshes and 200 text Meshes, the performance is very bad.
I have tried two different ways to render text; - I have tried rendering text as a Viewport2DVisual3D. (However I presume this is a terrible way, since it means in my prior example there are 200 viewports additional to the Viewport3D itself.) - I have tried rendering text as a GeometryModel3D, so the creation is the same as the regular brushes. However the material consists of a VisualBrush instead of a SolidColorBrush. (This does enhance the performance quite a bit, but still not perfect)
Does anyone have solutions to further enhance my performance with rendering text, so that I can render many more?
(I already followed most of the performance guidelines on the following site: https://msdn.microsoft.com/en-us/library/bb613553%28v=vs.110%29.aspx)
@edit: I have found that if I do the following with a visualbrush:
VisualBrush v = new VisualBrush(Text.createCubeStackText(text1));
RenderOptions.SetCachingHint(v, CachingHint.Cache);
viewport.Material = new DiffuseMaterial(v);
It improves the performance really much. I have tried, and can now render 700 regular meshes and 300 text meshes without any performance problems. Performance starts to drop with 550 text meshes and 550 regular meshes.
(I would still like any other suggestion though.)
Upvotes: 3
Views: 829
Reputation: 50672
Text in 3D can be very slow due to the tessellation that is needed to render the text. You might want to consider:
Remove the 3D rendering of text by overlaying the 3DViewport with a canvas and calculate the proper location of the text and render the text as a 2D overlay. You could even change the font size dependent on the Z value of the text's position
Render the text to a (transparent) bitmap and add the text as a texture to a billboard in the 3D scene
Use IsHitTestVisible=false
to click-through the overlay and project the 3D position of the text to the canvas by using this: Projecting a 3D point to a 2D screen coordinate
Upvotes: 1