Drag three.js objects (including Group) like THREE.DragControls, but without modifying the original position.
Live demo available at here.
npm install --save three-dragger
The CDN build is also available on unpkg:
- unpkg.com/three-dragger@1/dist/three-dragger.umd.js
- unpkg.com/three-dragger@1/dist/three-dragger.umd.min.js
import ThreeDragger from 'three-dragger';
const draggableObjects = [];
const mouseDragger = new ThreeDragger(draggableObjects, camera, renderer.domElement);
mouseDragger.on('dragstart', function (data) {
// Remember to disable other Controls, such as OrbitControls or TrackballControls
});
mouseDragger.on('drag', function (data) {
const { target, position } = data;
target.position.set(position.x, position.y, position.z);
});
mouseDragger.on('dragend', function (data) {
// Remember to enable other Controls, such as OrbitControls or TrackballControls
});
Enable or disable the dragger. The default is true
.
Handle with the drag events:
dragstart
drag
dragend
data.target
: The dragged object.data.mouse
: The normalized device coordinates of the mouse.data.position
: The latest world coordinates of the mouse.data.event
: The original DOM event.
See EventEmitter3.
Update the draggable objects.
Remove all events handlers.
MIT