| 1 | # three-orbit-controls |
| 2 | |
| 3 | [](http://github.com/badges/stability-badges) |
| 4 | |
| 5 | ThreeJS OrbitControls as an npm module. See [test](#testing) for an example. |
| 6 | |
| 7 | ```js |
| 8 | var THREE = require('three') |
| 9 | var OrbitControls = require('three-orbit-controls')(THREE) |
| 10 | |
| 11 | function start(gl, width, height) { |
| 12 | renderer = new THREE.WebGLRenderer({ |
| 13 | canvas: gl.canvas |
| 14 | }) |
| 15 | renderer.setClearColor(0x000000, 1.0) |
| 16 | |
| 17 | scene = new THREE.Scene() |
| 18 | camera = new THREE.PerspectiveCamera(50, width/height, 1, 1000) |
| 19 | camera.position.set(0, 1, -3) |
| 20 | camera.lookAt(new THREE.Vector3()) |
| 21 | |
| 22 | controls = new OrbitControls(camera) |
| 23 | |
| 24 | var geo = new THREE.BoxGeometry(1,1,1) |
| 25 | var mat = new THREE.MeshBasicMaterial({ wireframe: true, color: 0xffffff }) |
| 26 | var box = new THREE.Mesh(geo, mat) |
| 27 | scene.add(box) |
| 28 | } |
| 29 | |
| 30 | function render(gl, width, height) { |
| 31 | renderer.render(scene, camera) |
| 32 | } |
| 33 | ``` |
| 34 | |
| 35 | ## Usage |
| 36 | |
| 37 | [](https://nodei.co/npm/three-orbit-controls/) |
| 38 | |
| 39 | #### `OrbitControls = require('three-orbit-controls')(THREE)` |
| 40 | |
| 41 | This module exports a function which accepts an instance of THREE, and returns an OrbitControls class. This allows you to use the module with CommonJS, globals, etc. |
| 42 | |
| 43 | The returned function has the following constructor pattern: |
| 44 | |
| 45 | ```js |
| 46 | controls = new OrbitControls(camera[, domElement]) |
| 47 | ``` |
| 48 | |
| 49 | #### Versioning |
| 50 | |
| 51 | This uses an unusual versioning system to better support ThreeJS's (lack of) versioning. The major version of this repo will line up with ThreeJS breaking releases (`69.0.0` => `r69`). Often the module will continue to work (i.e. `69.0.0` should work with r70). |
| 52 | |
| 53 | The minor will be reserved for any new features, and patch for bug fixes and documentation/readme updates. In some rare cases, a minor feature may introduce a breaking change; so it's generally safest to use tilde or `--save-exact` for this module. |
| 54 | |
| 55 | If you see any version issues, open a ticket! |
| 56 | |
| 57 | ## testing |
| 58 | |
| 59 | Git clone, `npm install` and then run `npm start` to spin up a development server. Open `localhost:9966` in your browser to see the `test.js` file in action. |