CreateLine3D: visualisation very slow
#1
I tried to create ~50.000 lines with different colors. Worked, but it's very slow (displaying, rotating, zooming)
with Polyline it works fine.
Where I'm going wrong? 

// with individual color of each line -> slow

            Model3DGroup model = new Model3DGroup();
            var lineStartPos = _displayData[0];
            for (int i = 1; i < _displayData.Count; i++)
            {
                var lineEndPos = _displayData[i];
                var line = Line3DFactory.CreateLine3D(new Point3D(lineStartPos.XPos, lineStartPos.YPos, lineStartPos.ZPos),
                    new Point3D(lineEndPos.XPos, lineEndPos.YPos, lineEndPos.ZPos), 2, lineEndPos.Color,
                    LineCap.Flat, LineCap.Flat, MainViewport);
                model.Children.Add(line);
                lineStartPos = lineEndPos;
            }
            CurveModelVisual.Content = model;

// with same color for each line -> fast
            //List<Point3D> allPositions = new List<Point3D>();
            //foreach (var positionData in _allSpheresData)
            //{
            //    allPositions.Add(positionData.Position);
            //}
            //BezierCurve bezierCurve = BezierCurve.CreateFromCurvePositions(allPositions);
            //Point3DCollection curvePoints = bezierCurve.CreateBezierCurve(positionsPerSegment: 1); 
            //Model3D curveModel = Line3DFactory.CreatePolyLine3D(curvePoints, thickness: 2, color: Colors.Blue, isClosed: false, startLineCap: LineCap.Flat, endLineCap: LineCap.Flat, parentViewport3D: MainViewport);
            //CurveModelVisual.Content = curveModel;
#2
Found it! By using of the DirectX add on it works fine (https://www.ab4d.com/DirectX/3D/QuickStart.aspx)
@Moderator: there is a '/' missing in the documentaion:
<dxControls:DXViewportView Name="MainDXViewportView">
    <Viewport3D Name="MainViewport"> 
        <!-- existing WPF Viewport3D content -->
    </Viewport3D> 
</dxControls:DXViewportView>
#3
Rendering many 3D lines with Ab3d.PowerToys and WPF 3D is slow (this is also written a few times in the Ab3d.PowerToys samples project). 

The problem is that 3D rendering engine that comes with WPF does not support hardware rendering of 3D lines. So to render the 3D lines, the lines need to be defined as 3D rectangles that have the required size and are always oriented towards the camera. This means that the geometry for each line needs to be generated on the CPU. What is more, on each camera change, the line's geometry needs to be recreated. This works well for a few 3D lines, but when you have a lot of them, then this is very slow.

To solve this problem, please use the Ab3d.DXEngine library. This is a super fast DirectX 11 rendering engine that supports hardware rendering of 3D lines and can render millions of 3D lines on a modern graphics card. The following screenshot shows rendering 80 million 3D lines:

[Image: https://www.ab4d.com/images/DXEngineGall...-lines.png]


But if you will use Ab3d.DXEngine and try to render 50.000 individual 3D lines the performance will still not be great (even though Ab3d.DXEngine uses multi-threading and DirectX commands caching). The problem is that this would still execute 50.000 individual DirectX draw call commands. And this can take some time to process by the DirectX and the driver.

This can be solved by using MultiLineVisual3D that can render many 3D lines with one draw call (when using Ab3d.DXEngine). Also PolyLineVisual3D can render the whole poly-line with one draw call. But those two objects can render many lines with only one color. 

If you only need to use a few different colors for all the lines, then create MultiLineVisual3D for each of the color. But if you need to show many different colors, then you will need to use DXEngine's ScreenSpaceLineNode and PositionColoredLineMaterial objects. This will allow you to specify different colors for each line's start and end position. This way you will be able to render all the lines with one draw call and maximize the graphics card utilization with almost no CPU overhead. See "Improved Visuals / Colored lines" sample in the Ab3d.DXEngine samples project for more info.

Ab3d.DXEngine samples project can be downloaded from: https://github.com/ab4d/Ab3d.DXEngine.Wpf.Samples
Andrej Benedik
  


Forum Jump:


Users browsing this thread:
1 Guest(s)