3D Lines of different colors
#1
I have an application which needs to draw hundreds of thousands of 3D lines. N.B. that these are just lines - they are not a wireframe of a 3D surface or anything like that. I wrote a simple test application based on the AB4D PolyLineVisual3D sample code that came with the AB4D libraries and it works well.

But what I REALLY need to do is render some lines in one color and some in a difference color. Specifically, I'll be drawing a bounding box on a transparent canvas overlaying the Viewport3D and, after transforming the coordinates of the bounding box to the viewport, redrawing the 3D lines in the Viewport3D that are inside the bounding box in a different color than the ones outside the bounding box. Since a PolyLineVisual3D is all the same color (is this right?) I assume I'd have to use a Line3DVisual to do this.

1. Is this correct - that a PolyLineVisual3D is all the same color?

2. If so, where can I see some sample Line3DVisual code to use when drawing lines? I did a search in the Ab3d.DXEngine MAIN SAMPLES solution and in the .chm (help) files and couldn't find anything.

Thanks in advance.
#2
Both PolyLineVisual3D and LineVisua3D objects are defined in Ab3d.PowerToys library. There are more samples about the 3D lines with the Ab3d.PowerToys sample project. Also you should check the "Ab3d.PowerToys.chm" help file instead of DXEngine's help file.

You will see that the LineVisua3D is very easy to use - you just set the StartPosition, EndPosition, LineColor and LineThickness and the 3D line will be drawn.

The DXEngine is only used here to hardware accelerate the 3D lines.

To get good performance I would advise you to try to use as little Visual3D objects as possible. Each Visual3D object that draw lines is rendered with one draw call. If you will have a few thousand draw calls this will hurt performance a lot. Therefore it is much better to group 3D lines with the same color and thickness into one PolyLineVisual3D, MultiPolyLineVisual3D (those two are for connected lines) or to use MultiLineVisual3D object. With using the later three objects, you will be able to render mullions of 3D lines very fast (with good GPU).

Therefore I would advice you to group the 3D lines with the same color into one MultiLineVisual3D (or PolyLineVisual3D or MultiPolyLineVisual3D) object. Because you probably do not have thousands different colors, you will be able to use only a few of those objects.

You should also try to minimize the number of changes of Positions collection (defines the line positions). You need to know that each time positions are changed, then need to be transformed into vertex buffer and send to GPU. So if you have one positions collection with 100.000 positions and you change that one each frame, this can hurt performance. In this case it is better to device the positions into multiple collections (for example with 5000 positions each) and then change only those that are changed (and not all).

Based on your use case you will need to find a good balance there.

If you need more help, I would ask you to prepare a simple sample of your application and send it to me as PM or by email (see help). This way I will try to optimize it.

PS: If you have many 3D lines it also helps performance to set PresentationType to DirectXOverlay - this allows GPU to render in the background, but prevent putting other WPF objects over 3D scene.
Andrej Benedik
  


Forum Jump:


Users browsing this thread:
1 Guest(s)