Git Product home page Git Product logo

pcx's Introduction

Pcx - Point Cloud Importer/Renderer for Unity

GIF GIF

Pcx is a custom importer and renderer that allows for handling point cloud data in Unity.

System Requirements

  • Unity 2019.4

Supported Formats

Currently Pcx only supports PLY binary little-endian format.

How To Install

The Pcx package uses the scoped registry feature to import dependent packages. Please add the following sections to the package manifest file (Packages/manifest.json).

To the scopedRegistries section:

{
  "name": "Keijiro",
  "url": "https://registry.npmjs.com",
  "scopes": [ "jp.keijiro" ]
}

To the dependencies section:

"jp.keijiro.pcx": "1.0.1"

After changes, the manifest file should look like below:

{
  "scopedRegistries": [
    {
      "name": "Keijiro",
      "url": "https://registry.npmjs.com",
      "scopes": [ "jp.keijiro" ]
    }
  ],
  "dependencies": {
    "jp.keijiro.pcx": "1.0.1",
    ...

Container Types

Inspector

There are three types of container for point clouds.

Mesh

Points are to be contained in a Mesh object. They can be rendered with the standard MeshRenderer component. It's recommended to use the custom shaders included in Pcx (Point Cloud/Point and Point Cloud/Disk).

ComputeBuffer

Points are to be contained in a PointCloudData object, which uses ComputeBuffer to store point data. It can be rendered with using the PointCloudRenderer component.

Texture

Points are baked into Texture2D objects that can be used as attribute maps in Visual Effect Graph.

Rendering Methods

There are two types of rendering methods in Pcx.

Point (point primitives)

Points are rendered as point primitives when using the Point Cloud/Point shader.

Points Points

The size of points can be adjusted by changing the material properties.

Inspector

These size properties are only supported on some platforms; It may work with OpenGLCore and Metal, but never work with D3D11/12.

This method is also used when the point size is set to zero in PointCloudRenderer.

Disk (geometry shader)

Points are rendered as small disks when using the Point Cloud/Disk shader or PointCloudRenderer.

Disks

This method requires geometry shader support.

Acknowledgements

The point cloud files used in the examples of Pcx are created by authors listed below. These files are licensed under the Creative Commons Attribution license (CC BY 4.0). Please see the following original pages for further details.

pcx's People

Contributors

keijiro avatar thriftysnail avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pcx's Issues

ply using float double value

Thanks for this add ones, it's running perfectly but
There are any chance that ply importer can read ply with float double value ?
thanks
francois

Ply not showing in scene

Hi Keijiro,

While I have no issues importing my Ply file, when I drag it into the scene it simply does not show up. All of the components are there and editable, but I cannot see anything. The imported Ply file still has a thumbnail that is visible and shows my pointcloud

I downloaded the richmond-azaelias.ply file, and that works perfectly fine. However, both files are imported and visualised with no issues in Cloud Compare. I've included a screenshot of how it looks like after I drag in my Ply file (richmond-azaelias.ply in there for reference as working).

Test

As such it looks like it must be something to do with my Ply file; would you have any suggestions of what or how I may investigate further?

Any help would be very much appreciated.

(I am very very new to Unity, so my apologies if this question is very simple).

Getting build error

After downloading repository and opening in various Unity versions, I still get errors:

Assets/Pcx/Editor/PlyImporter.cs(67,29): error CS1061: Type UnityEditor.Experimental.AssetImporters.AssetImportContext' does not contain a definition for AddObjectToAsset' and no extension method AddObjectToAsset' of type UnityEditor.Experimental.AssetImporters.AssetImportContext' could be found. Are you missing an assembly reference?

Can you please help me understand why is that?
The projects looks very cool
Thanks!

Disk Shader Color Issue on Android

swirl-example
I tried exporting the sample project on Android OpenGL / Vulkan ( w/ unity 2019.3). The performance/animation is great but the colors seem scrambled (in a consistent way). Works perfect in editor too. Any idea of what's going wrong?

Strange color range on Android

Hi Keijiro,

I tried out the 'Plant' scene on Android 9 and got some strange results. The MeshRenderer version looks correct, but the Compute version seems to display with incorrect/greatly reduced color range. I tried changing the colorspace to Linear in the player settings but no luck.

Screenshot

Using:
Unity 2019.2.9f1
Android 9 on Pixel 3 XL

Modifyng Geometry Shader

Hi, i have a limited shader/coding knowledge and couldn't find which values should be edited to assign a different base shape to the Disk geometry shader? Like a triangle shape or other primitives?
Thanks!

Repo Setup

Hi Keijiro,

I'm curious about the layout of your repo and workflow when you use it in other projects. I see that you have a branch called upm and master. Why doesn't the upm branch include all of the files in the master branch? Notably I see the 'Asset' folder missing from the upm branch.

Could you point me to a project that uses this package with unity package manager?

Point Size broken with Point Shader on "Mesh" Pointcloud

In the Point Shader with a "Mesh" Pointcloud the Attribute Point Size doesn't get used.
The Pointcloud stays always the same.

Warning appears underneath:
"Only some plattform support these point size properties".

Unity Version: 2019.2.8f1 (Built-in Renderer)
Pcx Version: Release Version v1.2

iOS problem with AR Foundation

Hello Keijiro,

I want to congratulate you on the work of this Unity project it looks really cool.

I was currently working with Unity 2019.1.21f and AR Foundation 3.1.0, I had problems with the Pcx/Assets/Pcx/Runtime/Shaders/Point.shader shader since the graphics API used by the AR Foundation is OpenGLES3 (and not used OpenGLE2 because AR Foundation not supported but only shader when not used AR Foundation worked well) and in compilations in iOS it gave me this result:

New Project (1)

In the end, in the Point.shader file, change all the half to float, since you got the half non-recognition error when loading the point cloud. And I made it look good:

New Project

Any ideas why this happens?
(I am loading .ply files at runtime after download with external cloud, now works in Android and iOS with AR Foundation)

Thanks

How to load a PLY via script?

I have PLY files in the correct format that work in the editor, but how can I load them via script during runtime?

I searched the available issues here, but didn't find a solution yet.

X axis - Mirroring

I am so appreciative of the work that you have done here. Pcx is going to be very valuable to my work. I have however noticed that my imported ply is mirrored about the X axis. I was able to confirm this by setting my x scale value to the inverse.
Not a major problem and probably irrelevant for many applications. However, I would be interested to hear if anyone else had noticed this or if I am doing something wrong (I am relatively new to point clouds and to unity).
Thanks so much

Can i use this shader for point cloud in runtime?

Hi @keijiro ,

i am newbee to shader, i am doing the projeck with rendering the point cloud in runtime, my first idea was using triangles and mesh to make visualization, but it seems using shader is a better solution if we consider the performance, so is that possible to realize it with shader?

best regards

Wei

Visual effect graph managing total point count

Is there a way with the visual effect graph to have the total points only counting what the camera can see. From what I can tell from looking if I set a point count then this also counts to the points behind the camera/would not be visible and as such takes detail away from where the focus could be. Any idea what would be used to change this?
Thanks

real-time pointcloud update

Hi @keijiro
Thank you for sharing the awesome code.
Im trying to use pcx for real-time visualisation of our continously updated pointcloud.
we update sourceBuffer when we get and updated pointcloud, but the unity doesn't seem to update the poincloud.

do we need to clean the cloud before updating the new one? if yes, how do we do it?

Many thank you in advance.

Chang

LWRP: ComputeBuffer doesn't render in camera

With the New LWRP.
The Pointcloud in ComputeBuffer Mode doesn't render in the Camera. Only in Editor the Pointcloud gets correctly drawn.
If i switch back to builtin Renderpipeline everything works fine.

Mesh Rendering in LWRP works. But doesn't apply an Point Size.

Unity Version: 2019.2.8f1
Pcx Version: Release Version v1.2

additionally i get the following warning

GarbageCollector disposing of ComputeBuffer allocated in M:\Repo\GitRepos\SFMVisualizer_dev\SFMVisualizer_Unity\Assets\Pcx\Runtime\PointCloudData.cs at line 27. Please use ComputeBuffer.Release() or .Dispose() to manually release the buffer.
UnityEngine.ComputeBuffer:Finalize() (at C:/buildslave/unity/build/Runtime/Export/Shaders/ComputeShader.bindings.cs:28)

How can I make ply file to import?

I make ply file base on RealSense.

However, I can't Import this and I don't know how to debug this file.

ply file what I make has ascii type header and binary_little_endian type body.

[Source code]

public void SaveToPLY(string fileName)
        {
            Thread thread = new Thread(() =>
            {

                using (StreamWriter sw = new StreamWriter(@".\" + fileName, false, Encoding.ASCII))
                {
                    sw.Write("ply\n" +
                             "format binary_little_endian 1.0\n" +
                             "comment author: Jaeu Jeong\n" +
                             "comment object: Point Cloud\n" +
                             "element vertex " + vertices.Length.ToString() + "\n" + 
                             "property float x\n" +
                             "property float y\n" +
                             "property float z\n" +
                             "property uchar red\n" +
                             "property uchar green\n" +
                             "property uchar blue\n" +
                             "element face 0\n" +
                             "property list uchar int vertex_indices\n" +
                             "end_header\n");
                }
                
                FileStream fs = File.Open(@".\" + fileName, FileMode.Append);

                using (BinaryWriter wr = new BinaryWriter(fs))
                {
                    
                    foreach (var element in vertices)    // vertices is Vector3[] type
                    {
                        wr.Write(element.x);
                        //wr.Write(" ");
                        wr.Write(element.y);
                        //wr.Write(" ");
                        wr.Write(element.z);
                        //wr.Write(" ");
                    }

                    for (int i = 0; i < vertices.Length; i++)    // Texture is byte[] type
                    {
                        wr.Write(texture[i * 3]);
                        //wr.Write(" ");
                        wr.Write(texture[i * 3 + 1]);
                        //wr.Write(" ");
                        wr.Write(texture[i * 3 + 2]);
                        //wr.Write("\n");
                    }
                }
                
                Debug.Log("File save finished");
            });
            
            thread.Start();
        }

[Error Message]

Mesh 'test': abnormal mesh bounds - most likely it has some invalid vertices (+/-inifinity or NANs) due to errors exporting.
Mesh bounds min=(-inf, -inf, -inf), max=(inf, inf, inf). Please make sure the mesh is exported without any errors.
UnityEngine.Mesh:UploadMeshData(Boolean)
Pcx.PlyImporter:ImportAsMesh(String) (at Assets/Pcx/Editor/PlyImporter.cs:181)
Pcx.PlyImporter:OnImportAsset(AssetImportContext) (at Assets/Pcx/Editor/PlyImporter.cs:32)
UnityEditor.Experimental.AssetImporters.ScriptedImporter:GenerateAssetData(AssetImportContext)
UnityEditorInternal.InternalEditorUtility:ProjectWindowDrag(HierarchyProperty, Boolean)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

Upm branch

Hello,
Sorry for the disturbance, but I was wondering how do you create your upm branch ? It seems to be a symbolic link to the Assets/pcx folder and I think this git feature should be really useful (this is a nice example) , I have never seen this before !

But maybe you just created another normal branch and put everything into it. ๐Ÿ˜„

Thank you in advance for the information !

Rending just on one HoloLens Display

While using this Lib in a HoloLens-project, built with Unity, I can see the rendering of the point-cloud just on the left display. On the right eye there is no rending. We are using HoloLens Generation 1 here. We tested with multiple devices - same behaviour.

Add this info:
I'm using the Point Cloud Renderer with Container-Type "ComputeBuffer"

Continuous update a point cloud map from a flying drone

Hi

My question in #50 is well solved. Thanks for your advice.

I realized the package currently draws a static point cloud map for one time. But in my case, I need to draw a point cloud map continuously. The point clouds are updating in real-time. Does this package has the function?

Besides, I noticed the package used Graphics.DrawProcedural to draw each geometry. I'm not sure is it gonna affect the rendering performances if I draw up to 50,000 point clouds at 1Hz.

The device I'm using is HoloLens1.

Thanks
Glen

Mesh not readable

Hi Keijiro,

I've used this asset extensively using the texture baked import settings. For my current application I need to use a mesh. I use the "mesh" container type in the import settings. However, when I try to access the mesh data (vertices and colors) via a script, Unity complains it is not readable, which I cant set in the inspector. Any clues?

Best,

Sergio

Coordinate system options

Since the original question has been closed, I thought I would post a fix here for anyone else having similar problems. As mentioned in the original question, this issue occurs due to Unity using a left handed coordinate system whereas a lot of 3D modelling software and point cloud scanners use a right handed z-up coordinate system (Also sometimes called a real world coordinate system).

To resolve this, open Assets/Pcx/Editor/PlyImporter.cs and search for vertices.Add(new Vector3(x, y, z)); (It should be on/around line 150).
If your point cloud model is mirrored AND rotated on the X axis like it was for me then change it to vertices.Add(new Vector3(x, z, y));
If it is simply mirrored on the x axis and not rotated at all then change it to vertices.Add(new Vector3(-x, y, z));. If for some reason the point cloud is mirrored on a different axis then simply make that axis negative instead.

Afterwards, reimport your point clouds and they should show correctly

example of pcx and vfx

Hi Keijiro! and all,
Unable to combine vfx and pcx in Unity. Is there an example project rendering pointcloud with vfx in unity?
Thanks for the amazing work!
Eytan

Save the Color map

Hello,
Is there a way to save and edit manually the color map texture generated for the vfx graph ?
I don't find any good way to edit colors properly inside the vfx graph
Thanks

Ply norm consideration

I noticed that while parsing the PLY meta data, the norm is not taken into consideration explicitly (only through a generic Data32 type).
Later, after parsing the data, only the vertices and colors (rgba) are moved on to the shader.

I have a PLY with norm i need to take into consideration.
How do i implement using it in the shader? (point/disk)

Thanks

More efficient dynamic pointcloud

We have gotten the pointcloud working by rerender it completely every loop. It works fine. #29

Now the performance is not fast enough. We want to be able to use Initialise() to update a fixed size pointcloud.

Could you give us some suggestions on how we can modify the library? Or what is stopping h us from doing so?

Best Regards,
Chang

Shadow-Cast Support

All in the name. Any potential for feature to enable shadow casting or interaction with unity lighting at all?

Texture2D

This work is really incredible.

However, I would like to use Texture3D instead of Texture2D to use a plont cloud in the VFXgraph because with a Texture2D, all the points with a Z axis are baked in lines and not randomly as in a PLY file.

Do you know if it's possible to obtain a Texture3D from a point cloud in Unity ?

Thanks a lot.

LWRP

Hi, I tried to use the shader point cloud with LWRP, and works, but not the color. how can I fix this?

regards

Metal support

Metal doesn't have geometry shader. It has to be emulated by using compute + procedural indirect draw.

Cannot import my ply file

Here's my ply file header

ply
format ascii 1.0
comment VCGLIB generated
element vertex 5841
property float x
property float y
property float z
property float nx
property float ny
property float nz
property uchar red
property uchar green
property uchar blue
property uchar alpha
element face 11678
property list uchar int vertex_indices
end_header

Why doesn't my ply file get imported as a mesh?

Hi Kejiro,
Thanks for making this useful component. But, I am kinda unsure as to how it works when I add a new .ply file to my project. Does it automatically convert the file into a mesh? This new file is in little_big_endian format, I checked the header, so I think it should work, as you acknowledged in one of the other issues.
Thanks for your help,
Subhajit.
Screen Shot 2019-06-21 at 1 24 20 AM

LOD support

Awesome work!
Do you have any idea about how to enable Level of Detail control of point cloud rendering using your shaders?
One way I can think of is to discard some vertices in geometry shader, simply based on their vertexID.
You are very knowledgeable with Unity rendering, what would be your suggestion to integrate the LOD of this shader with Unity?

Newbie question: how to integrate Pcx with unity

Hello @keijiro ,

thanks for sharing this awesome library. Do you have any ressource explaining how to integrate Pcx with Unity to display pointcloud points generated from ros ? Any advice would be welcome as well.

I already imported the project into unity as specified in the installation guidelines.

Thanks again.

How to load my points

Hello,
I want to use this library but i dont want to load points from .ply file
I've got them stored in array, could you describe the steps to do to make it work and load my own point data?
I don't see any examples for this case.
Thanks

Google Draco Support

Hey!

I want to say thanks so much for this repo. Actually all of your work has been an inspiration to me for the last year, I stumble onto your github a lot. I've been working to add Google Draco support to Pcx and I'm almost done! Also I am adding support to flipbook style keyframe through point clouds. It's really fast and rad.

https://github.com/millerhooks/draco/tree/unity_point_cloud_plugin/unity/PointCloudLoader

I am no where near as tidy or competent as you however. I haven't written any C++ in 15 years and never ever done it well. I wanted to check to see if you had any pull request requirements I should know about.

After I get done with this first phase, I want to put the frames into an HDF5 and eliminate redundancy and/or potentially compress the whole animation, plus add the ability to transition to other cloud animations. I've got it pretty well mapped out how to get it done, probably in the lamest way possible. I would really like to work in your DX11 geometry shaders (and if you figure out an apple solution, oh boy!) to work as transitions / effects. Syncing cloud tornados to the beat or whatever.

If you have any thoughts on where I'm trying to go with this, I'd love to hear them.

Thanks again.

PS! 4Gb animated point cloud compresses down to roughly 800mb and is streamable. Roughly 1000 frames at 24Fps. That is with almost completely redundant clouds in each frame. Decoding sits currently around 10ms, but I don't even totally understand how the quantization and compression levels work. I think it can get smaller and faster.

Point and Disk shader render always on top

Hi!
Thank you for sharing the project, it is awesome!
I just had a quick question. Is there anyway to make the point cloud take into consideration the depth of transparent and similar shader? Right now the depth only seems to work with opaque materials. When using transparent or particle systems (for example) on other objects in the scene, the point cloud renders on top of everything.

Disk shader does not work in HDRP (2019.1.0f2)

Hi Keijiro,

I tried the disk shader on HDRP in Unity 2019.1.0f2, I get the magenta shader of death (with no errors). Any idea why?
I have a volumetric capture of an actor as a sequence of vertex and colors lists (each frame has a list of vertices and a list of colors). Do you have a suggestion on how to render them apart from a geometry shader?

Metal: Error creating pipeline state (Hidden/InternalErrorShader): Vertex attribute POSITION0(0) is missing from the vertex descriptor (null) on Animation Scene [OSX]

Love the project. Trying to get it working with Google Draco this week and shoot you a pull request!

I'm having some issues with this Vertex POSITION attribute on the hidden shader. I've looked at the targeting and potentially how float4's are handled on Metal with the disk shader, but I fear I'm out of my depth in this side of shader land.

Unity 2017.3.0b6

EDIT: Doops, I haven't upgraded this computer to High Sierra yet to get Metal2.
https://forum.unity.com/threads/compute-shaders-and-geometry-shaders-at-the-same-time-on-mac-osx.494021/

Updated to High Sierra, looks like Metal2 still isn't supported in Beta. If anyone has any hacky ideas I'd take them! Cheers!

How do I create Position map and Color map for the vfxgraph?

First I want to say thanks for your contribution to the community, love

I used Metashape to create a model I want to use. Importing it in Unity with Pcx works fine, but I'm not getting any color map and position map like the model you showed in the vfxgraph example. Can you please elaborate how can we create such so we can use the model in VFX?

License

How is this project licensed?

Add point cloud data failed due to MonoBehaviour

Hi

I import the Pcd package and tried to render point cloud in following steps,

  • Import Pcx packages.
  • Create PcxRender Gameobjects.
  • Drag script /Assets/Pcd/Runtime/PointCloudData.cs into object PcxRender

It showed errors as below,
ssss

Can you give advice with that?

Thanks

invalid type used for 'SV_VertexID' input semantics, must be integral at line 53

This is an error I have been receiving when trying to build my project.
"Shader error in 'Point Cloud/Point': invalid type used for 'SV_VertexID' input semantics, must be integral at line 53 (on d3d11_9x)"
It is odd because I had no problem with the shader before and it runs perfectly in the editor.
I have even built to the same device using the point shader before without issues.

*This error only arises when using the compute buffer rather than mesh import setting

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

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;
}

No color for points

In 2019.3.0f1, the color info is not loaded correctly by the shader. Perhaps related, it issues the following warning:

Drawing with MeshTopology.Points, yet the vertex program 'Hidden/SceneViewSelected' does not have PSIZE output.

Forming polygons from points?

Curious if any work had been done on forming polygons from points to make a true 3D object? Also, on a (possibly) related note, how does one use Texture2D? Fairly new to unity and this is fantastic work, so I appreciate the help very much.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.