Hello,
Here is my problem: I have a point cloud (pcd format file) that I imported into three js. I moved my point cloud (rotation + position). I have the trajectory of a robot which moves in this point cloud but since I moved the point cloud, how can I apply the new position to my trajectory? Thanks for your help
For me it is quite unclear what you ask for.
Nevertheless, if you add the robot as a child object of the cloud, then the robot (and its trajectory) will move together with the cloud, independent on how you reposition and rotate the cloud.
Thanks for your help, but how do I set this up?
For now I have a cloud that I import into three js like this:
// instantiate a loader
const loaderPCD = new PCDLoader();
// load a resource
loaderPCD.load(
// resource URL
'static/models/2106.pcd',
// called when the resource is loaded
function ( points ) {
//points.geometry.center();
points.rotateY(4.8);
points.rotateX(3.1);
points.rotateZ(-0.1);
points.position.x = 1.3;
points.position.y = 6;
points.position.z = 6;
scene.add(points);
},
// called when loading is in progresses
function ( xhr ) {
console.log( ( xhr.loaderPCD / xhr.total * 100 ) + '% loaded' );
},
// called when loading has errors
function ( error ) {
console.log( 'An error happened' );
}
);
My robot is a ply file imported in the same way:
function loadRobot(){
loader.load(
'static/models/car.ply',
function (geometry) {
geometry.computeVertexNormals()
const material = new THREE.MeshPhysicalMaterial({
color: 0x049ef4,
metalness: 0.5,
roughness: 0.5,
// transparent: true,
transmission: 0.5,
side: THREE.DoubleSide,
// clearcoat: 1.0,
// clearcoatRoughness: 0.25,
})
meshRobot = new THREE.Mesh( geometry, material );
meshRobot.position.x = 0.5; //RED
meshRobot.position.y = - 0.9; //green
meshRobot.position.z = - 0.12; //BLUE - 0.12
meshRobot.scale.multiplyScalar( 0.001 );
meshRobot.rotateX(Math.PI / 180)
scene.add(meshRobot)
//moove the robot
//moove()
},
(xhr) => {
console.log((xhr.loaded / xhr.total) * 100 + '% loaded')
},
(error) => {
console.log(error)
}
)
}
Finally regarding the trajectory I proceed like this:
const points = [
new THREE.Vector3(0.000118954, 0.001054873, -0.000306402),
new THREE.Vector3(0.000777644, 0.001525318, -0.000664352),
new THREE.Vector3(0.000707381, 0.002000148, -0.000671897),
new THREE.Vector3( 0.000860078, 0.003138441, -0.000428472 ),
new THREE.Vector3(0.000831843, 0.004344346, 0.000032551),
new THREE.Vector3(0.002976510, 0.005033887, 0.001953103),
new THREE.Vector3(0.004688929, 0.005484502, 0.004914966),
new THREE.Vector3(0.005369600, 0.005044235, 0.008556681),
new THREE.Vector3(0.003458110, 0.015809765, 0.009683169),
new THREE.Vector3(0.001738887, 0.027185621, 0.011905815),
new THREE.Vector3(0.002296457, 0.041347280, 0.011081150),
];
const path = new THREE.CatmullRomCurve3(points);
const pathGeomtry = new THREE.BufferGeometry().setFromPoints(path.getPoint(50));
const pathMaterial = new THREE.LineBasicMaterial({color:0x00ff00});
const pathObject = new THREE.Line(pathGeomtry,pathMaterial);
scene.add(pathObject);
And in the animate function:
const time = Date.now();
const t =(time/2000 % 12)/12;
const position = path.getPointAt(t);
if(document.getElementById("robot").checked) var device = meshRobot;
else var device = cube;
device.position.copy(position);
const tangent = path.getTangentAt(t).normalize();
device.lookAt(position.clone().add(tangent));
Thanks for your help
Still not clear what you’re asking.
Throw that junk into a jsfiddle or a glitch and try to articulate the problem more clearly, and we can look into it further.
Here’s a glitch you can “remix” and put your code into script.js