2

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.

3

2 Answers 2

11

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Can it keep mouse momentum ?
6

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;
}

http://jsfiddle.net/go2fhr3v/14/

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.