Search code examples
unity-game-enginegraphics3dpoint-clouds

Quickly reading XYZ point cloud and rendering animated points into Unity


I have an application in Unity that currently reads tens of thousands of points from a text file containing x,y and z coordinates for a point cloud. As one can imagine, this take a large amount of time.

I am unfamiliar with particle systems in Unity and am looking for suggestions on how to speed this process up. I have tried to use the ParticleSystem object but it seems I cannot tie it with reading a text file of xyz coordinates. I have also attempted to convert the text file to .obj and importing that as a model into Unity. Although the .obj model appears in Blender and Meshlab, it does not appear in Unity as I believe it lacks a "mesh".

Furthermore, the points must be "animated". Meaning that I have a text file of xyz coordinates which is rendered. This text file is then replaced with different xyz coordinates, and then rendered again thus "animating" the point cloud. This makes rendering speed an essential requirement. My solution to this was originally to use a .obj model that updates, however as mentioned above, this did not work.

Any help is appreciated. Thanks.


Solution

  • I would recommend converting xyz file to binary. It will read it a lot faster. For some reason Unity is really slow in terms of reading text files. Therefore, i would recommend creating a C# or C++ console application for this task.

    Then you can import this binary to Unity and create meshes in Unity without triangulating them like done here or you can use particle system as you said.

    I have done a similar task but i modified Free Point Cloud viewer tool because it allows you to create meshes with 65535 limit and i had a point cloud with around 1 million point. I converted it to binary and it takes 3 4 secs to import it to Unity with creating meshes and everything. Tens of thousands of points wont be a problem at all.

    After you imported the point cloud you can just translate points to new imported positions and RecalculateBoundsof your mesh. Then you have your animation.

    Note that: When reading from text in Unity try to avoid string.split. As far as i observed that is the bottleneck. I would recommend creating files which would not require any split operation.