In Three JS, is it possible to rotate the object with mouse instead of rotating the camera with OrbitControls.js (https://threejs.org/docs/#examples/controls/OrbitControls) Thanks.
-
Have a look at this SO answerprisoner849– prisoner8492018-07-03 10:00:54 +00:00Commented Jul 3, 2018 at 10:00
-
thanks @prisoner849Asela– Asela2018-07-05 09:25:30 +00:00Commented Jul 5, 2018 at 9:25
-
stackoverflow.com/questions/19588602/…Nguyen Tran– Nguyen Tran2019-01-03 07:15:04 +00:00Commented Jan 3, 2019 at 7:15
Add a comment
|
2 Answers
I solved this problem this way:
I created the 'ObjectControls' module for ThreeJS that allows you to rotate a single OBJECT (or a Group), and not the SCENE.
Include the libary:
Usage:
var controls = new ObjectControls(camera, renderer.domElement, yourMesh);
You can find here a live demo here: https://albertopiras.github.io/threeJS-object-controls/
Here is the repo: https://github.com/albertopiras/threeJS-object-controls.
1 Comment
AirOne01
Can it keep mouse momentum ?
You can listen to 'mousemove' event and apply an increment to the objects rotation.
This is a very easy working solution to start with:
var canvas = renderer.domElement;
canvas.addEventListener('mousemove', onMouseMove);
function onMouseMove(event) {
cube.rotation.y += event.movementX * 0.005;
}