Using a Raycaster for Input
Mouse Action:
About this demo...
This demo uses an object of type THREE.Raycaster to get input from the user. A Raycaster can find intersections of a ray with objects in the scene. By using the camera and mouse to specify the ray, a Raycaster can tell you which object the user clicks. It also gives the coordinates of the point at which the ray intersects the clicked object.
The scene shows a square, green base, and some tapered, yellow cylinders standing on the base. Cylinders can intersect; no attempt is made to treat them like real solid objects. The user can interact with the scene using the mouse. Four radio buttons let the user select the action that they want to perform with the mouse.
When "Rotate" is selected, dragging the mouse will rotate the world about the y-axis. Only the horizontal motion of the mouse is taken into account.
When "Drag" is selected, the mouse can be used to drag the yellow cylinders. The cylinder is constrained to stay on the base. An interesting point is that as the cylinder is dragged, its new position is determined using the Raycaster.
When "Add" is selected, a mouse click at a point on the green base will add a new cylinder at that point. Clicking a cylinder will have no effect.
When "Delete" is selected, clicking on one of the yellow cylinders will remove it from the scene. Clicking the ground will have no effect.