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 ?
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.
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).
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.
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.
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);