Search Unity

Render a pointcloud from a .xyz file with a colormap based on a property

Discussion in 'Visual Scripting' started by NassD13, Jan 7, 2021.

  1. NassD13

    NassD13

    Joined:
    Jan 7, 2021
    Posts:
    8
    Hi,

    I am a total newbie to Unity, basically I am trying to migrate a viewer from THREE.js to unity with webGl.
    One of the 3D type I need is a pointcloud colored with a colormap evaluated on each point with a value.
    I'm using .xyz files with x, y, z coordinates and a list of properties value for each point, so for example x, y, z, prop1. The colormap is based on this property and I need to be able to change dynamically this property via a GUI or something like that.

    So far I've seen few possibilities, one is the particle system but I'm struggling to use it and the second one is the PCX viewer (https://github.com/keijiro/Pcx) but it's using .ply files. I am currently trying to reuse that code to render point cloud from my .xyz files.

    Do you have suggestions or examples of how should render a simple point cloud like that (it needs to be useable in the browser)

    Thanks for your answers and sorry if it sounds dummy I'm still discovering 3D rendering with Unity
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,438
    is the prop basically 0-255 value, for example to pick color from gradient?

    if you use pcx, i think it supports converting to mesh, so that works in unity webgl viewer (might need to adjust shader for webgl, if it doesnt work as is)

    here is example (not from pcx, but same idea.. would need to add that color property into shader though)
    https://unitycoder.com/upload/demos/pointcloudwebgl/
     
  3. NassD13

    NassD13

    Joined:
    Jan 7, 2021
    Posts:
    8
    No the prop can be anything, in three.js, I was just creating ranges for the colormap: I get the max and min, I just divide the interval by the number of colors in the colormap

    How can I use Pcx with an .xyz file? from what I've seen it only supports .ply files
     
  4. NassD13

    NassD13

    Joined:
    Jan 7, 2021
    Posts:
    8
    Here is a screenshot of my viewer in three.js that's the kind of pointcloud I'd like to realize it's not scanner data, it's geological data
    upload_2021-1-7_15-27-3.png
     
  5. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,438
    convert .xyz to .ply, using MeshLab or CloudCompare or other external tools.
    (or add xyz parser for pcx, its simple ascii format so its easy to read)

    for prop, then need to make custom shader to do that, then you can adjust that value from script with
    https://docs.unity3d.com/ScriptReference/Material.SetFloat.html
     
    wuddadid likes this.
  6. NassD13

    NassD13

    Joined:
    Jan 7, 2021
    Posts:
    8
    Thanks for your answer, I should have said sooner that my .xyz file is streaming from an api, this is supposed to be part of the web app.

    So I can't do any modification to the file with external software.
    The point cloud is only one part of my viewer I need to be able to render surfaces, and trajectories. I don't know how easy it is to combine pcx with that, knowing that everything has coordinates (x, y, z) and should be at the same place.

    I know it's quite complex but I want to go step by step, first step is to assess that I can render a pointcloud from an .xyz file that is streamed from an api
     
  7. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,438
    ok, then you don't really need pcx for that (well can look for reference how to build point meshes and possibly shaders).

    possible ideas for it:
    - receive xyz data (by loading from your api, maybe webrequest https://docs.unity3d.com/ScriptReference/Networking.UnityWebRequest.html or javascript sockets https://docs.unity3d.com/Manual/webgl-networking.html or some other plugins https://forum.unity.com/threads/unity-netcode-io-secure-udp-communication-in-webgl.486917/ )
    - create meshes from that data https://docs.unity3d.com/ScriptReference/Mesh.html (for meshes, you can set vertex colors and other mesh properties, if you want to save extra data into them, like that prop)
    - add your custom shader to those meshes ( shader tuts http://www.alanzucconi.com/2015/06/10/a-gentle-introduction-to-shaders-in-unity3d/ )

    also i personally would use build in render pipeline, not URP or HDRP. (to make custom webgl/mobile shaders easier..)
     
  8. NassD13

    NassD13

    Joined:
    Jan 7, 2021
    Posts:
    8
    Thank you for your pointers

    When you say meshes, you mean creating one mesh for each point? I'm confused on how to get a pointcloud out of a mesh
     
  9. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,438
  10. NassD13

    NassD13

    Joined:
    Jan 7, 2021
    Posts:
    8
    Ok, got you

    Do you have pointers on the particles?
    I tried to use it, but I couldn't make it work
     
  11. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,438