I am trying to load a sample pcd file from my server to load it in scene inside 3d canvas in threejs . I have a get request which reads the pcd file and sends it.
const express = require('express')
const fs = require('fs')
const router = new express.Router()
router.get('/api/pcd', async (req, res) => {
try {
try {
let _path = 'simple.pcd'
if (fs.existsSync(_path)) {
fs.readFile(_path, 'utf8', (err, data) => {
res.send(data)
})
}
} catch (e) {
console.log('error')
}
} catch (e) {
res.status(500).send(e)
}
})
module.exports = router
Inside the javascript code using pcd loader tried to load the point cloud inside the scene.
var loader = new THREE.PCDLoader()
// load a resource
loader.load(
'http://localhost:8081/api/pcd',
function(mesh) {
scene.add(mesh)
var center = mesh.geometry.boundingSphere.center
console.log(center)
controls.target.set(center.x, center.y, center.z)
controls.update()
},
function(xhr) {
console.log((xhr.loaded / xhr.total) * 100 + '% loaded')
},
function(error) {
console.log(error)
}
)
But this is the error which is coming up. please help.
TypeError: geometry.setAttribute is not a function
at THREE.PCDLoader.parse (PCDLoader.js:361)
at Object.onLoad (PCDLoader.js:32)
at XMLHttpRequest.<anonymous> (three.js:34275)
Can you please share the PCD file in this thread?
https://github.com/mrdoob/three.js/blob/dev/examples/models/pcd/ascii/simple.pcd
And i tried pcd inside same binary folder Zaghetto.pcd File. I Had same issue for that file too.
Both files work fine with PCDLoader so it's obviously not an issue of the loader.
If you need help to fix your node.js app (or the way how it serves files), please use the forum instead. GitHub is for bugs and feature requests only.
BTW: You can login at the forum with your GitHub account.
Most helpful comment
Can you please share the PCD file in this thread?