Friday 25 August 2017

Convert .obj to .xyz manually without using any third-party software

             The reason I am stressing about .xyz format is that PFTrack supports .xyz, .pts, .txt, .xyb file formats to import lidar data in the survey solver node. 3DEqualizer can import .obj, .xyz, .pts, .ptx file formats. Here, PFTrack is lagging in importing .obj file format which is supported by most of the 3D applications. So, here comes a situation where you have an .obj file and want to use it for survey in PFTrack, the easiest solution for this is to download MeshLab or some other 3D processing software to convert an .obj file to .xyz file format. Solved it, but what if we come across an even worse situation where you don't have access to internet connection(which is kind of rare situation) to download MeshLab, the solution here is we could manually convert it. 
             There is a closer relation in syntax of both .obj and .xyz file formats. The .obj file contains vertex, vertex normals and faces data stored in it with respect to the world space. Coming to .xyz file format, it stores vertex or point position. Following image depicts the difference in syntax between the two formats.

       Now we got the solution, open the .obj file in a notepad, delete all the lines leaving back the lines with vertex position and we are done. No, no, no....this is not yet over, we have to remove the letter 'v' in front of the position or vertex values, and yes we could manually remove those line by line but it would eat a lot of time when it comes to large data(this time you could better opt for an internet connection).
     Now the actual solution for this is to edit the file using wordpad because notepad doesn't take the indentation of the line into account. Get rid of the unwanted vn, f and # lines. Replace the letter 'v' with nothing, using the find and replace option in wordpad. But this even doesn't work because we can find that there is a space between letter 'v' and the position value, so, when we replace the letter 'v' with null value, each line will start with a space. So, we need to make sure that we are replacing that space too. 
Now, replace the letter and space 'v ' with nothing or null. In this way, we could get a clean file with only position values. Save the file with .xyz extension and import in PFTrack for testing. In PFTrack, make sure you switch the static render proxy and dynamic render proxy to None or 1/2 for point visibility when there are only few points and also choose the correct coordinate system.