Tree to PLY
It can be useful to use cloudpoints in Grasshopper and therefore having a way import PLY files.
The Binari format is fully readable, meaning that it’s possible to read, filter, and extract any useful information. Let’s dive.
We will start from the photogrammetry from a tree. To test we will use a light version of the cloud point.
Exporting PLY from Meshlab / CloudCompare
First the more important is to understand the PLY’s file header. It can be slightly different depending which software writes it.
We can here remember that the Header takes 17 lines and points coordinates are lines 5 to 6 and colour + alpha are lines 11 to 14.
After the header we have the points coordinates
In CloudCompare it is possible to filter the needed information when importing
The Alpha Channel is not always set. I can be done by hand.
The export gives
We see here that elements are not sorted in the same order. Lines 6 to 8 are for the coordinates and colours are 9 to 11 and there is no Alpha.
We will take that into account in Grasshopper.
Let’s start by creating a File Path and a Read File
Adding a Panel I can see how my file is structured
Then I will separate the Header from the points coordinates
I use a Split List. Here it has to be cut line 15.
Now I need to break the lines of coordinates to have Points Coordinates, Normals, and Colors into lists.
I use a Text Split
Now I’ve a got my list of points and as sub lists, all the coordinates.
I’ll isolate the point coordinates, the colours and Normals
We add the Index and the Construct Point
For the Colours I kept the Alpha just in case, even if I don’t have it here.
We can see that the cloudpoint is visible in Rhino (I used a very light cloudpoint)
We can create boxes from the points to visualise the colours.
And add colours
Result with 10 000 points. But very fast Rhino and Grasshopper will be overflowed.