I am working on animating a linear gripping motion for picking and placing objects. Here is a codesandbox link where you can see the issue I am facing:
https://i.sstatic.net/dUdPv.png
- The gripper is created, moves down to reach the LEGO brick, and then stops.
const grip_pos = new Vector3(
pick_pos.x,
pick_pos.y,
pick_pos.z + 5
);
createGripper(grip_pos, this.scene);
console.log(this.scene.getObjectByName("gripper", true));
const gripper = this.scene.getObjectByName("gripper", true);
// Down
while (gripper.position.y > (pick_pos.z / 0.48)) {
gripper.position.y -= 0.1;
};
- The gripper grabs the Lego, lifts it up, and moves it to the designated position to place it.
gripper.add(lego);
// if Down then Up
if (!gripper.position.y > pick_pos.z / 0.48) {
while (gripper.position.y < grip_pos) {
gripper.position.y += step;
}
if (pick_rot) {
gripper.rotateY(Math.PI / 2);
}
}
// Move to Place Position
while (gripper.position.x > place_pos.y / 0.8 + 9.2) {
gripper.position.x -= step;
}
while (gripper.position.x < place_pos.y / 0.8 + 9.2) {
gripper.position.x += step;
}
while (gripper.position.z > place_pos.x / 0.8 + 2.8) {
gripper.position.z -= step;
}
while (gripper.position.z < place_pos.x / 0.8 + 2.8) {
gripper.position.z += step;
}
- The gripper descends to the place position, releases the Lego, moves up, and disappears.
// Place Down
if (
gripper.position.x === place_pos.y &&
gripper.position.z === place_pos.x
) {
while (gripper.position.y > pick_pos.z / 0.48) {
gripper.position.y -= step;
}
}
if (place_rot) {
gripper.rotateY(Math.PI / 2);
}
this.scene.add(lego);
this.scene.remove(gripper);
this.renderer.render(this.scene, this.camera);
cancelAnimationFrame(id);
I have already created the gripper and tried to execute the movement as described. However, I am not seeing any motion and my browser freezes without any error messages. Can you provide guidance on achieving the desired linear motion? Thank you in advance.
Please note that I am using two different coordinate frames,
xyz
andzyx
, with translations and scaling. This may be affecting the positioning of the objects. Check this conversion in the code for more details.