keijiro / Pcx

Point cloud importer & renderer for Unity
The Unlicense
1.36k stars 197 forks source link

Separate the conversion positions/colors -> Point[] from the _pointData assignment in Initialize(List<Vector3>, List<Color32>) #49

Closed masmil1988 closed 4 years ago

masmil1988 commented 4 years ago

I have a lot of point clouds with a lot of points to render at runtime. In order to avoid to overload the main thread I perform the most of my calculations in a secondary thread; when points are ready to be rendered I call PointCloudData.Initialize by passing the points positions and colors.

This method needs to be called on the main thread. If I have a lot of points this method locks the main thread until all points have been put into a Point[] array. This conversion can still be done in a secondary thread, so that when the PointCloudData has to be initialized this operation can be done by passing already prepared data.

I modified your library by adding a method PreparePoints(List positions, List) which returns a Point[].

public static Point[] PreparePoints(List<Vector3> positions, List<Color32> colors)
{
    PointCloudData.Point[] points = new Point[positions.Count];
    for (int i = 0; i < positions.Count; i++)
    {
        points[i] = new Point
        {
            position = positions[i],
            color = EncodeColor(colors[i])
        };
    }

    return points;
}

public void Initialize(Point[] points)
{
    _pointData = points;
}
keijiro commented 4 years ago

I think that's a good solution for your problem. By the way, what's the point of this issue? I think this is not a bug report nor a technical question.

keijiro commented 4 years ago

I'm closing this issue now. Please feel free to reopen it for further problems.