mrdoob/three.js — Issue #876: Is there any way to create a dragging but in 3D?
Author: BorisDutkin
Created: 2011-12-08 16:26:18+00:00
State: open

I've built a scene in witch you can drag objects...
There is another feature in that project...witch is the whole scene rotation (360 deg)...

The dragging part is pretty famous one :

function onDocumentMouseMove( event ) {

event.preventDefault();

mouse.x = (event.clientX / window.innerWidth) * 2 - 1; // update mouse.x position
mouse.y = -(event.clientY / window.innerHeight) * 2 + 1; // update mouse.y position
var vector = new THREE.Vector3(mouse.x, mouse.y, 0.5); // calculating the position in 3D
projector.unprojectVector(vector, camera);

var ray = new THREE.Ray(camera.position, vector.subSelf(camera.position).normalize());

if (SELECTED) {
var intersects = ray.intersectObject(plane);
SELECTED.position.copy(intersects[0].point.subSelf(offset));

//fixing the (Z) axis jumping when switching flower
objects[thisObject].position.z = PosZ;

var PosX = SELECTED.position.x; // PosX holds the SELECTED object (X) position
var PosY = SELECTED.position.y; // PosY holds the SELECTED object (Y) position
// rotate (Y) axis of flower
flowerRotationAngleZ = -(PosX * 0.040);
stemTopY = PosY;
stemTopX = PosX;

return;
}

var intersects = ray.intersectObjects(objects);

if (intersects.length > 0) {

if (INTERSECTED != intersects[0].object) {

if (INTERSECTED)
INTERSECTED.material.color.setHex(INTERSECTED.currentHex);

INTERSECTED = intersects[0].object;
INTERSECTED.currentHex = INTERSECTED.material.color.getHex();

plane.position.copy(INTERSECTED.position);

}

container.style.cursor = 'pointer';

}
else {

if (INTERSECTED)
INTERSECTED.material.color.setHex(INTERSECTED.currentHex);

INTERSECTED = null;

container.style.cursor = 'auto';

}
}

Now my question is how can I make this code work for 3D dragging....
After rotating the scene for example