Hello,
I need to select a Group Object and then drag it across the space while making sure that certain restrictions on the coordinates are followed i.e. my y-coordinate is not changed. At the same time, I want the group geometry to follow the mouse coordinates in the x-z plane. To achieve this, I am casting a ray to a plane which is restricting the y-coordinates of my geometry. I am setting the position of the object as the intersection point of the plane and the ray.
However, with every successive dragging, the process seems to become slow.
Dragcontrols function
dragcontrols.addEventListener('drag', function (event){
raycaster.ray.intersectPlane(plane, newint);
event.object.position.set(newint.x, newint.y, newint.z);
for (var i=0; i<meshobjects.length; i++){
if(Math.abs(newint.x + groupbox[dragobj].getSize().x - (meshbox[i].getCenter().x - meshbox[i].getSize().x/2)) < 100/nf){
groupobjects[dragobj].position.x = meshbox[i].getCenter().x - meshbox[i].getSize().x/2 - groupbox[dragobj].getSize().x;
}
if(Math.abs(newint.x - (meshbox[i].getCenter().x + meshbox[i].getSize().x/2)) < 100/nf){
groupobjects[dragobj].position.x = meshbox[i].getCenter().x + meshbox[i].getSize().x/2;
}
if(Math.abs(newint.z + groupbox[dragobj].getSize().z - (meshbox[i].getCenter().z - meshbox[i].getSize().z/2)) < 100/nf){
groupobjects[dragobj].position.z = meshbox[i].getCenter().z - meshbox[i].getSize().z/2;
}
if(Math.abs(newint.z - (meshbox[i].getCenter().z + meshbox[i].getSize().z/2)) < 100/nf){
groupobjects[dragobj].position.z = meshbox[i].getCenter().z + meshbox[i].getSize().z/2;
}
}
grouphelper[dragobj].update();
groupbox[dragobj].setFromObject(groupobjects[dragobj]);
});
dragcontrols.addEventListener('dragend', function (event){
console.log("Good");
});