Import point cloud to unity

Thanks for the reply!
I use a plugin called SimpleFileBrowser from which I get the path to the file that I wanna read. The file is in my DCIM.

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.

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.

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.

No sorry. Maybe its the shader/material you are using or the color is not being converted correctly?

I have tried 4-5 shaders, but none of them is working :confused:

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:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
using Unity.Robotics.ROSTCPConnector;
using PointCloud = RosMessageTypes.Sensor.PointCloud2Msg;

public class PointCloudScriptWithParticles : MonoBehaviour{
 
    public string topic = "/voxel_grid/output";
    public ParticleSystem pointCloudParticleSystem;
 
    /*

    ParticleSystem.Particle[] particles;
    Vector3[] points;
    Color32[] colors;
 
    */

    byte r, g, b;
    byte rgb_max = 255;

    // Imports, parses and then displays the point cloud.

    void GetParseDisplayPointCloud(PointCloud message)
    {

        int numberOfPoints = (int)(message.width * message.height);

        Vector3[] points = new Vector3[numberOfPoints];
        Color32[] colors = new Color32[numberOfPoints];

        Debug.Log("Number of points: " + numberOfPoints);
        Debug.Log("Message Height: " + message.height);
        Debug.Log("Message Width: " + message.width);

        ParticleSystem.Particle[] particles = new ParticleSystem.Particle[numberOfPoints];

        int axisIndex = 0, colorIndex = 16;

        for (int i = 0; i < numberOfPoints; i++)
        {

            points[i] = new Vector3(System.BitConverter.ToSingle(message.data, axisIndex), System.BitConverter.ToSingle(message.data, axisIndex + 4), System.BitConverter.ToSingle(message.data, axisIndex + 8));

            b = message.data[colorIndex];
            g = message.data[colorIndex + 1];
            r = message.data[colorIndex + 2];

            colors[i] = new Color32(r, g, b, rgb_max);

            particles[i].position = points[i];
            particles[i].startSize = 10;
            particles[i].startColor = colors[i];

            axisIndex += (int)message.point_step;
            colorIndex += (int)message.point_step;

        }

        Debug.Log("Number of colors: " + colors.Length);
        Debug.Log("Number of positions: " + points.Length);

        Debug.Log("RGB at Color array: (" + colors[0] + ")");
        Debug.Log("R Value at the end: " + colors[0].r);
        Debug.Log("G Value at the end: " + colors[0].g);
        Debug.Log("B Value at the end: " + colors[0].b);
        Debug.Log("Alpha Value at the end: " + colors[0].a);

        pointCloudParticleSystem.SetParticles(particles, particles.Length);
        pointCloudParticleSystem.Pause();

    }

    void Start(){
     
        pointCloudParticleSystem = GetComponent<ParticleSystem>();
     
        if (pointCloudParticleSystem == null){

            pointCloudParticleSystem = gameObject.AddComponent<ParticleSystem>();
     
        }
     
        // Just imports the point cloud and specifies to which function it will be imported 

        ROSConnection.GetOrCreateInstance().Subscribe<PointCloud>(topic, GetParseDisplayPointCloud);
 
    }

}

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?

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.

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).
  • Just tried scales of 1, 10 and 100. It didn’t make a difference.
  • I didn’t use a shader/material here. Are you suggesting using ParticleSystemRenderer here? (I am new to Unity)

Alpha values are set in my code to 1f for each point or particle.

Actually, just tried changing material to Sprites-Default and set MaxParticleSize to 10. Now, i see squares on top of each other with differing colors and opacities instead of point cloud:

  • Only have Render, emission and shape modules enabled.
  • GameObject is at the origin (0 ,0 ,0)

@karl_jones
What file formats could be read by the particle system with your script to generate a cloud?
Specifically is HDF5 possible?

I’m not familiar with HDF5. If you have a way to convert the file into vector points, then it will work.

@ngclcs
Would you like to checkout FM Points, which is compatible for “ply” format.
Probably you may try converting your data to ply via CloudCompare as well.