Load PCD from .xyz file

Hi People !

I’m new to three.js but i need some help with the loader for Point Cloud file. I need to load a “.xyz” file but i read the only way for do it is load is PCDLoader with the file format of “.pcd”.
Is possible to load in that format(XYZ) and integreted with .obj file ?

Thanks.

There is currently no loader for the XYZ file format. The problem is that XYZ specifies molecule geometry but without defining connectivity data. Meaning you have to generate these data on the fly which makes a proper implementation more hard.

I’m not sure why you’ve mentioned PCD since XYZ is not a pure point cloud file format.

Can you share your XYZ in this thread? It should not be hard to just parse the data and return an instance of BufferGeometry (meaning without connectivity information).

2 Likes

Thanks for the reply @Mugen87.

I mentioned PCD because i try to see how three.js load point cloud data and after see the doc i think they can be link to my case but you confirm my fear of impossibility to load an .xyz file format.

This is a snipped of my file beacuse the origial file is < 200mb.

“-5.263289 -2.018107 -6.778724 15 10 7
-5.265210 -2.018104 -6.761683 15 10 7
-5.287247 -2.031802 -6.761683 15 10 7
-5.264249 -2.018106 -6.770204 15 10 7
-5.276228 -2.024953 -6.761683 15 10 7
-5.275268 -2.024955 -6.770204 15 10 7
-5.263289 -2.021674 -6.785642 15 10 7
-5.275268 -2.026738 -6.773663 15 10 7
-5.263289 -2.019891 -6.782183 15 10 7
-5.287247 -2.024631 -6.737726 15 10 7
-5.287247 -2.028217 -6.749704 15 10 7
-5.276228 -2.021368 -6.749704 15 10 7
-5.266147 -2.018107 -6.737726 15 10 7
-5.276697 -2.021369 -6.737726 15 10 7
-5.265678 -2.018106 -6.749704 15 10 7
-5.263289 -2.010802 -6.761683 2 2 2
-5.263289 -2.014455 -6.770204 2 2 2
-5.264249 -2.014453 -6.761683 2 2 2
-5.263289 -2.011748 -6.737726 1 0 5
-5.264249 -2.014926 -6.749704 1 0 5
…”

thanks for your help.

Just curious: what is what in those lines of data?

x y z r g b

Um, it seems this format is something different than what I have talked about, see XYZ file format.

1 Like

Quite dark :slight_smile: Would be interesting to see the result :slight_smile:

Yeah @prisoner849 ! :slight_smile: after a lot i just find a loader online lidarview.com for point cloud.
The problem is the output format for the final file…

Yes i forgot to mention the R,G,B column in the file… @Mugen87

Hi there, I want to do the same thing as Spressox. I had a look at the file formats and the situation and decided to write a loader for the .xyz file format, as it doesn’t seem that different from the .pcd format. I have forked three.js and written a new loader based on the PCDLoader but I’ve never made a PR to any open source project and would appreciate if someone could give me some instruction as to what to do. Also I haven’t tested it out yet either, but I think it should work as the main diference is just the headers of the file and the format of the rgb values.

Looking forward to adding this functionality to the project.

Best,

Erica.

It always important to test what you are developing. Especially since you should submit a new example when providing a new loader.

use this node on yout xyz file to have a pcd

var fs = require('fs');
var xyzrgb = fs.readFileSync('input.xyz').toString();
var lines = xyzrgb.split('\n').filter(v=>v!=="");

var out = `VERSION .7
FIELDS x y z rgb
SIZE 4 4 4 4
TYPE F F F F
COUNT 1 1 1 1
WIDTH ${lines.length}
HEIGHT 1
VIEWPOINT 0 0 0 1 0 0 0
POINTS ${lines.length}
DATA ascii
`;

for (var i = 0; i < lines.length ; i++) {
    var data = lines[i].match(/[+-]?\d+(\.\d+)?/g).map(function(v) { return parseFloat(v); });
    var r = data[3];
    var g = data[4];
    var b = data[5];
    var color = (r<<16) + (g<<8) + b;
    out += `${data[0]} ${data[1]} ${data[2]} ${color.toExponential()}\n`
}

fs.writeFileSync('output.pcd',out);

Starting with r123, there will be an official XYZLoader :tada:.

It supports XYZ and XYZRGB data sets.

3 Likes