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 self = this
var loader = new THREE.PCDLoader()
// load a resource
loader.load(
'http://localhost:8081/api/pcd',
function(mesh) {
self.scene.add(mesh)
var center = mesh.geometry.boundingSphere.center
console.log(center)
self.controls.target.set(center.x, center.y, center.z)
self.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)
This the code used as reference https://github.com/mrdoob/three.js/blob/79edf22a345079dc6cf5d8c6ad38ee22e9edab3c/examples/webgl_loader_pcd.html
This is the pcd file https://github.com/mrdoob/three.js/blob/79edf22a345079dc6cf5d8c6ad38ee22e9edab3c/examples/models/pcd/ascii/simple.pcd
I tried this with simple.pcd inside the public folder, and this program is inside public/umd folder, still am getting the same error. geometry.setAttribute
var loader = new THREE.PCDLoader()
// load a resource
loader.load(
'simple.pcd',
function(mesh) {
self.scene.add(mesh)
var center = mesh.geometry.boundingSphere.center
console.log(center)
self.controls.target.set(center.x, center.y, center.z)
self.controls.update()
},
function(xhr) {
console.log((xhr.loaded / xhr.total) * 100 + '% loaded')
},
function(error) {
console.log(error)
}
)