(Solved) Problem with PCD Loader to parse binary file

I wrote a very simple server to send both ASCII and binary format of PCD file to three.js front-end.
Three.js can show ASCII format correctly.
However, the loader cannot load the binary file with the correct encoding.

When I inspect the content of PCDLoader.js Line:72
/mrdoob/three.js/blob/dev/examples/jsm/loaders/PCDLoader.js#L72 in chrome debugger. The data will be converted to utf-8 encoding (one-byte content will be expended to 2 bytes).

How can I solve this issue?

I made a sample project to reproduce this result.
GitHub: HTLife/pcdutf8
How to use it:

  1. Run server

    cd server
    node main.js

  2. Start front-end

    npm install
    npm run dev

  3. You should see the front-end load the ascii file and show with no problem

  4. Please modify the code under https://github.com/HTLife/pcdutf8/blob/020ca3fae6aaf8b247bf1d7455ed6be96ce9d965/src/components/pcdviewer.vue#L82
    comment out Line: 82 and uncommnet line:83
    to test the binary format file.

I don’t understand this. The onLoad() callback gets an array buffer as result (data). Since the header of a PCD file is always in ASCII text, a respective decode is performed. Can you please explain in more detail what you mean?

The parsed position attribute of your file contains some NaN values which is suspicious.

BTW: You have set the wrong path in https://github.com/HTLife/pcdutf8/blob/020ca3fae6aaf8b247bf1d7455ed6be96ce9d965/src/components/pcdviewer.vue#L82

It should be this.showPCD('http://localhost:3010/api/binary').

I’ve made another test with your binary PCD file. I’ve just copied it over to the three.js repository and load it from our dev server (http-server). Everything works fine:

So there might be an issue with your web server configuration.

Thanks for your kindly help.
I search for the Node.js+Express server configuration.
It turns out that I met a pitfall in the Express server.

The following code could solve the utf-8 conversion problem:

res.setHeader('Content-Transfer-Encoding', 'binary')
res.setHeader('Content-Type', 'application/octet-stream')
res.send(new Buffer(obj, 'binary'))
1 Like