Search Unity

Import point cloud to unity

Discussion in 'General Discussion' started by ciacadline, Mar 19, 2019.

  1. ciacadline

    ciacadline

    Joined:
    Mar 19, 2019
    Posts:
    2
    Hi,
    I am new to unity and I am wondering how to bring a point cloud into unity.
    I have an RCP and E57.
    Please help!
     
  2. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,501
    Hi @ciacadline I'm a user like you.
    Unity is not a design tool. So there are no points like in a 3D software tool.
    There are game objects that contain a transform component where you can add the position.
    So I presume you want to convert a file.txt ore else into a bunch of game object with different positions
    or an array of Vector 3. For this, you need to know C# programming.
    Here there is a tutorial about array in C#
    https://unity3d.com/learn/tutorials/topics/scripting/arrays?playlist=17117

    You need to make a curve or place content in the scene?
    Also, you need to bring a point cloud into Unity in the game or just in the editor one time only?
    Are you loading this file using windows or for/in any platform?

    I also look for tutorials into youtube: link example
    Follow the tutorials and try to be more specific on the question.
    You are welcome to this Unity forum!
     
  3. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
  4. ciacadline

    ciacadline

    Joined:
    Mar 19, 2019
    Posts:
    2
    thanks for your help, I am just trying it out at the minute :)
     
  5. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,983
    Just use a particle system and set all the particles to be the positions of the points, thats the most performant way instead of using gameobjects or paying for pixyz
     
    SparrowGS likes this.
  6. Rickmc3280

    Rickmc3280

    Joined:
    Jun 28, 2014
    Posts:
    189
    I purchased mgears Point cloud viewer and it works pretty well and has a lot of good features. I am curious of this particle system for point clouds concept too. We are trying to find every way possible to squeeze performance for so anyone can view the point clouds. Is there any documentation for it?

    Also, I would look into file converting for your e57 file and send it into pts or laz. Mgear has a converter that converts it to a binary file which is akin to las/laz files in that the files are significantly reduced and easier to load into memory.
     
    Last edited: Apr 24, 2019
  7. irhamillahkhamsim

    irhamillahkhamsim

    Joined:
    Jun 16, 2019
    Posts:
    6
    I couldnt see the you tube link that you post in here.
     
  8. irhamillahkhamsim

    irhamillahkhamsim

    Joined:
    Jun 16, 2019
    Posts:
    6
  9. irhamillahkhamsim

    irhamillahkhamsim

    Joined:
    Jun 16, 2019
    Posts:
    6
    I have experience working with point cloud. but I dont know how to load the point cloud to unity. I already install the free package of point cloud viewer. but I dont have any idea how to start with. is there any link or tutorial for dummies just to view point cloud in unity. thanks
     
    nicktruchman likes this.
  10. irhamillahkhamsim

    irhamillahkhamsim

    Joined:
    Jun 16, 2019
    Posts:
    6
    thanks. but I am beginner of unity so I am a bit scare if I buy it and it dont have any manual guide. if there's include the manual guide too I will buy this plug in. my point cloud data is around 30 millions after i merge all the scans.
     
  11. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
  12. irhamillahkhamsim

    irhamillahkhamsim

    Joined:
    Jun 16, 2019
    Posts:
    6
    i use the unity 2018.3.7 .is that support this plug in? because when i click window i couldnt find the point cloud tool.
     
  13. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
    should work, have you imported it from asset store? any errors in console?
     
  14. irhamillahkhamsim

    irhamillahkhamsim

    Joined:
    Jun 16, 2019
    Posts:
    6
    ok. it show this view. but how can i want to change the data to my own data.
    upload_2019-6-18_18-20-17.png

    is there any video that you record about this. thanks
     
  15. Rickmc3280

    Rickmc3280

    Joined:
    Jun 28, 2014
    Posts:
    189
    In the right side of the picture, where it says data path, change it to your files location.
     
  16. sharimken

    sharimken

    Joined:
    Jul 30, 2015
    Posts:
    14
    Point cloud is getting more popular recently, but there are still very few point cloud tools in Unity3D.
    Let me share this interesting demo here. They runs smoothly on mobile.


     
    Last edited: Mar 10, 2020
  17. V-J

    V-J

    Joined:
    Apr 1, 2015
    Posts:
    73
    @GameDevCouple_I could you please explain it futher?
    I have also a E57 file that i like to import.
     
  18. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,300
    The ParticleSystem is a good way to show a large number of points, it does have its limits which will largely be dependent on the hardware it's running(use the profiler).

    Here is a simple script to show how you would convert a list of vector3 into a particle system

    Code (csharp):
    1.  
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Rendering;
    5.  
    6. public class ShowPoints : MonoBehaviour
    7. {
    8.     public Color color;
    9.     public float particleSize = 5;
    10.  
    11.     public void ApplyToParticleSystem(List<Vector3> positions)
    12.     {
    13.         var ps = GetComponent<ParticleSystem>();
    14.         if (ps == null)
    15.             return;
    16.  
    17.         var particles = new ParticleSystem.Particle[positions.Count];
    18.  
    19.         for (int i = 0; i < particles.Length; ++i)
    20.         {
    21.             particles[i].position = positions[i];
    22.             particles[i].startSize = particleSize;
    23.             particles[i].startColor = color;
    24.         }
    25.         ps.SetParticles(particles);
    26.         ps.Pause();
    27.     }
    28. }
    One thing you could do to try and squeeze additional performance would be to use BakeMesh after the particle system has been populated although this would depend on how the system is being visualized(any animation, billboarding etc would not function the same after baking).
     
  19. V-J

    V-J

    Joined:
    Apr 1, 2015
    Posts:
    73

    Thx! but i need a little more help please, can you tell me how to set this up in Unity?, I have a gameobject with a Particle sys and added the script to it. also I converted the e57 in a xyz and xyb format.

    Do i need to use this?
    https://docs.unity3d.com/ScriptReference/ParticleSystem.SetCustomParticleData.html
     
  20. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,573
    He sorta provided complete solution to you already. At this point you need to give it a try and read the docs.
     
    MadeFromPolygons and karl_jones like this.
  21. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,300
    My example should give you everything you need. You just need to call ApplyToParticleSystem with the list of points.
     
    MadeFromPolygons likes this.
  22. Rickmc3280

    Rickmc3280

    Joined:
    Jun 28, 2014
    Posts:
    189
    Karl_Jones
    Unity should buy Point Cloud Tools and develop it with DOTS :) I think it would be better and has tons more implications for the future of graphics rendering :) I know yall know better than I do, but I've used over 10 pieces of software for point cloud, and this toolset performs the best yet. Havent tried converting it to dots because I cant wrap my head around it with the tuts but... Should give it a try.
     
  23. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,300
    I did convert a small point cloud microstructure scan to dots last year, the conversation and processing was very fast! Dots is well suited to working with point clouds :)
    It's not as scary as it sounds, take a look at some of the samples. I started just writing c# jobs first, they are very fast and can work with normal code.
     
    alpha_rat and Rickmc3280 like this.
  24. V-J

    V-J

    Joined:
    Apr 1, 2015
    Posts:
    73
    Well ok, but do i need to convert the xyz positions in the e57 first into a list?
     
    Last edited: Mar 15, 2020
  25. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,573
    YOu need to grab his example and modify it to your needs after experimenting with it. It wont' take a lot of time to figure out what you need to modify.
     
  26. V-J

    V-J

    Joined:
    Apr 1, 2015
    Posts:
    73
    easier said than done if your a programmer. :)

    Something like this?

    Code (CSharp):
    1. public List<string> nameList;
    2.  
    3.     private void Start()
    4.     {
    5.         nameList = new List<string>(System.IO.File.ReadAllLines("Hous_partpoints onecell.txt"));
    6.     }
     
  27. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
    yes, need to load the file,
    then parse those values manually, into Vector3 array, (search for float.Parse examples)
    then assign each particle position from that Vector3 array.
    (and usually need to swap Y and Z values, if the point cloud appears sideways)
     
    MadeFromPolygons and karl_jones like this.
  28. omar575

    omar575

    Joined:
    Apr 8, 2021
    Posts:
    2
    I have a question.I did visualized my data using the particle systems but the problem is that the particles are far away from my move tool.I dont know what is exactly the problem here.
     
  29. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
    usually point cloud coordinates can be really huge values,
    you can solve it by offsetting their values with certain value.

    for example if points are around x:35467 y:123 z:-4333,
    subtract that amount from all points, so your points get near 0,0,0
     
    omar575 likes this.
  30. omar575

    omar575

    Joined:
    Apr 8, 2021
    Posts:
    2
    Thank you so much I get it now :):)
     
  31. Songbin333

    Songbin333

    Joined:
    Dec 20, 2021
    Posts:
    7
    Hi,
    i'm new to Unity and try to bring a point cloud in format of into Unity. Now i have trouble importing data. The file is more then 100GB and i use the FileStream to read it. But every time after decoding, there will be garbled. I have tried much decode formats, but all of these didn't work.
    The following is my code,could you take a look and give some advice? Thanks a lot!

    Code (CSharp):
    1. string path1 = @"D:\Data.e57";
    2.             FileStream fsRead;
    3.             fsRead = new FileStream(path1,FileMode.Open);
    4.             long leftLength = fsRead.Length;        //Length of file content not yet read
    5.             byte[] buffer = new byte[1024];          //Create a byte array that receives the contents of the file
    6.             int maxLength = buffer.Length;          //Maximum number of bytes per read
    7.             int num = 0;                                       //The number of bytes actually returned each time
    8.             int fileStart = 0;                               //The position where the file starts to be read
    9.             while (leftLength > 0)
    10.             {
    11.                 fsRead.Position = fileStart;        //Set the read position of the file stream
    12.                 if (leftLength < maxLength)
    13.                 {
    14.                     num = fsRead.Read(buffer, 0, Convert.ToInt32(leftLength));
    15.                 }
    16.                 else
    17.                 {
    18.                     num = fsRead.Read(buffer,0,maxLength);
    19.                 }
    20.                 if (num == 0)
    21.                 {
    22.                     break;
    23.                 }
    24.                 fileStart += num;
    25.                 leftLength -= num;
    26.                 Console.WriteLine(Encoding.Default.GetString(buffer));
    27.             }
    28.             fsRead.Close();
    29.             Console.ReadKey();
     
  32. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,573
    Normally reading a file is done in this way.
    Code (csharp):
    1.  
    2.         var bufferSize = 1024*1024;
    3.         var buffer = new byte[bufferSize];
    4.         var path = "/1.tmp";
    5.         using(var fs = File.Create(path)){
    6.             while(true){
    7.                 var numRead = fs.Read(buffer, 0, bufferSize);
    8.                 if (numRead <= 0)
    9.                     break;
    10.             }
    11.         }
    12.  
    Meaning you don't need to maintain so many variables and if/else conditions, plus the compiler can close it for you.

    However, if your binary file is 100+ gigabytes, then resulting data simply might not fit into system memory.
     
    alpha_rat likes this.
  33. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
    .e57 is completely different format from pure .csv or .pts or other raw ascii formats (those you could read easily line by line and use float.parse)

    look for e57 file format structure, there's info available. (but can be quite a lot of work to create parser from scratch).
    also note the c# maximum array size, if you are going to read all into single points array.
     
  34. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,780
    @Songbin333 does it need to be that big? Can you use some software, which reduces point cloud size and actually generates a mesh? There are few software, which can generate meshes. Once you got mesh you can import to Unity as object. Much more friendly to work with in Unity.
     
  35. Songbin333

    Songbin333

    Joined:
    Dec 20, 2021
    Posts:
    7
    Thank you for your advice.
    I tried to use some software like cloudcompare to thin the point cloud. But cloudcompare cloudn't even read this whole data, because it's too big and there is not big enough memory. Do you have any recommended software for processing .e57 file?
     
  36. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,780
    If I remember correctly, unfortunately I don't have experience with this format.
    libE57 (http://www.libe57.org/index.html) is best starting point, which I am sure you are already aware of.

    I used in the past both cloudcompare and meshlab. They were used in conjunction, to automate solution two problems of same pointcloud. But I don't know, if meshlab will be any of use for you. You need check it out.

    My best bet would be to try matlab and some packages for pointcloud.
    Alternatively, try to look int python solutions?
    I am a bit rusty otherwise.
     
  37. Mike_Chatz

    Mike_Chatz

    Joined:
    Jan 18, 2019
    Posts:
    8
    Thanks for this!

    Could you help me with something please? This works great for me in Standalone Build and in the Editor, but when I try to run it on android, the Particle System doesn't show up at all. I have been trying to figure out what goes wrong 3 days now. If you could help me somehow I would greatly appreciate it!
     
  38. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,300
    I dont know why it would not work in Android.
    Do you get any error messages?
    How many points are in the system?
    Is it being culled by the camera?
     
  39. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
    karl_jones likes this.
  40. Mike_Chatz

    Mike_Chatz

    Joined:
    Jan 18, 2019
    Posts:
    8
    Thanks for the fast reply!

    I don't get any errors. I have tried 10k, 50k, 100k and 200k pts. It is in front of the camera, in editor it is displayed perfectly.
     
  41. Mike_Chatz

    Mike_Chatz

    Joined:
    Jan 18, 2019
    Posts:
    8
  42. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,300
    Sounds like you need to do some debugging. Check that the file is actually being read, check the point values match the ones you have in Editor. Maybe debug log some values and see if they are the same.
     
  43. Mike_Chatz

    Mike_Chatz

    Joined:
    Jan 18, 2019
    Posts:
    8
    I have done debugging but no different values. I think it is the device I am using for some reason. Probably it is old for my Unity project.
     
  44. Mike_Chatz

    Mike_Chatz

    Joined:
    Jan 18, 2019
    Posts:
    8
    Once again, thank you for this.
    Could I ask you a question?

    I have modified the function so that it receives colors apart from positions as well. I am using 8 colors, but one of them (a light green) appears as white. Do you got an idea why is this happening? The other colors are displayed fine.
     
  45. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,300
    No sorry. Maybe its the shader/material you are using or the color is not being converted correctly?
     
  46. Mike_Chatz

    Mike_Chatz

    Joined:
    Jan 18, 2019
    Posts:
    8
    I have tried 4-5 shaders, but none of them is working :/
     
  47. GerenMeric

    GerenMeric

    Joined:
    May 15, 2023
    Posts:
    47
    Hi, i am trying to import ROS point cloud messages into and display them iside Unity, using particle system. I have written a code to import, parse and then display the point cloud comprising of particles. But, when i try to display particles, i can't see any particles (or we can say point cloud) in the screen. When, i debug i see correct values for colors and number of points (and particles). Can you help me display particles in Unity please?

    Here is the code i wrote:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Rendering;
    5. using Unity.Robotics.ROSTCPConnector;
    6. using PointCloud = RosMessageTypes.Sensor.PointCloud2Msg;
    7.  
    8. public class PointCloudScriptWithParticles : MonoBehaviour{
    9.  
    10.     public string topic = "/voxel_grid/output";
    11.     public ParticleSystem pointCloudParticleSystem;
    12.  
    13.     /*
    14.  
    15.     ParticleSystem.Particle[] particles;
    16.     Vector3[] points;
    17.     Color32[] colors;
    18.  
    19.     */
    20.  
    21.     byte r, g, b;
    22.     byte rgb_max = 255;
    23.  
    24.     // Imports, parses and then displays the point cloud.
    25.  
    26.     void GetParseDisplayPointCloud(PointCloud message)
    27.     {
    28.  
    29.         int numberOfPoints = (int)(message.width * message.height);
    30.  
    31.         Vector3[] points = new Vector3[numberOfPoints];
    32.         Color32[] colors = new Color32[numberOfPoints];
    33.  
    34.         Debug.Log("Number of points: " + numberOfPoints);
    35.         Debug.Log("Message Height: " + message.height);
    36.         Debug.Log("Message Width: " + message.width);
    37.  
    38.         ParticleSystem.Particle[] particles = new ParticleSystem.Particle[numberOfPoints];
    39.  
    40.         int axisIndex = 0, colorIndex = 16;
    41.  
    42.         for (int i = 0; i < numberOfPoints; i++)
    43.         {
    44.  
    45.             points[i] = new Vector3(System.BitConverter.ToSingle(message.data, axisIndex), System.BitConverter.ToSingle(message.data, axisIndex + 4), System.BitConverter.ToSingle(message.data, axisIndex + 8));
    46.  
    47.             b = message.data[colorIndex];
    48.             g = message.data[colorIndex + 1];
    49.             r = message.data[colorIndex + 2];
    50.  
    51.             colors[i] = new Color32(r, g, b, rgb_max);
    52.  
    53.             particles[i].position = points[i];
    54.             particles[i].startSize = 10;
    55.             particles[i].startColor = colors[i];
    56.  
    57.             axisIndex += (int)message.point_step;
    58.             colorIndex += (int)message.point_step;
    59.  
    60.         }
    61.  
    62.         Debug.Log("Number of colors: " + colors.Length);
    63.         Debug.Log("Number of positions: " + points.Length);
    64.  
    65.         Debug.Log("RGB at Color array: (" + colors[0] + ")");
    66.         Debug.Log("R Value at the end: " + colors[0].r);
    67.         Debug.Log("G Value at the end: " + colors[0].g);
    68.         Debug.Log("B Value at the end: " + colors[0].b);
    69.         Debug.Log("Alpha Value at the end: " + colors[0].a);
    70.  
    71.         pointCloudParticleSystem.SetParticles(particles, particles.Length);
    72.         pointCloudParticleSystem.Pause();
    73.  
    74.     }
    75.  
    76.     void Start(){
    77.      
    78.         pointCloudParticleSystem = GetComponent<ParticleSystem>();
    79.      
    80.         if (pointCloudParticleSystem == null){
    81.  
    82.             pointCloudParticleSystem = gameObject.AddComponent<ParticleSystem>();
    83.      
    84.         }
    85.      
    86.         // Just imports the point cloud and specifies to which function it will be imported
    87.  
    88.         ROSConnection.GetOrCreateInstance().Subscribe<PointCloud>(topic, GetParseDisplayPointCloud);
    89.  
    90.     }
    91.  
    92. }
    93.  
    94.  
     
    Last edited: Jun 20, 2023
  48. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,300
    Are the particles very close together or far apart? Try adjusting the particle size, and camera near and far clipping values to see if they are preventing the particles from being seen.
    Do you see the game view triangles (tris) increase in the statistics panel when you add the point cloud?
     
  49. GerenMeric

    GerenMeric

    Joined:
    May 15, 2023
    Posts:
    47
    Sorry for my belated response. I have tried particle sizes of 10, 1 and 0.5 . But, it didn't change the result. I have also tried different camera near and far clipping values between 0.01 and 300 for near, 0.02 and 1000 for far clipping values. But, still i couldn't see any particles. I see game view triangles increase in size from 3.5k before adding the point cloud to something between 80k and 120k after adding the point cloud.

    Thank you for all the help you offer.
     
  50. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,300
    It sounds like the particles are being generated then, you just can't see them.
    That could be for a number of reasons:

    • Too big or small. Try adjusting the particle systems transform scale, increase and decrease it gradually and see if anything appears. Also try adjusting the Renderer Min/Max particle size.
    • Shader/Material issues. If you are using a custom material/shader it may have issues, try switching the view to wireframe or changing to a different material, the Sprite one is a good one to start with. Check that the particles dont have the color alpha set to or near 0 or they will be invisible
    • Module/Animation issues. It could be animating the color/size. Try disabling all but the essential modules.
    • float imprecision issues - Is the particle systems position very high (+/- 10,000~)? Try moving it to the origin of the world (0,0,0).