three-trackballcontrols
Version:
A module for using THREE.TrackballControls with nodejs
69 lines (46 loc) • 1.86 kB
Markdown
[](https://www.npmjs.com/package/three-trackballcontrols)

A module for using THREE.TrackballControls with nodejs
`npm install three-trackballcontrols` or `yarn add three-trackballcontrols`
Example was using `three.js` + `three-trackballcontrols` inside of a very simple React app.
```javascript
import * as THREE from 'three';
import TrackballControls from 'three-trackballcontrols';
// Assumes there is a `camera` and `renderer` initialized.
const controls = new TrackballControls(camera, renderer.domElement);
// Any manual camera changes should be done first, then update the controls.
camera.position.z = 5;
controls.update();
const animate = function () {
requestAnimationFrame(animate);
// Required for updating during animations.
controls.update();
renderer.render(scene, camera);
}
animate();
```
Example uses [JSDelivr](https://www.jsdelivr.com/package/npm/three-trackballcontrols) version, look up the latest URL for using with static hosting.
```html
<script type="module">
import TrackballControls from 'https://cdn.jsdelivr.net/npm/three-trackballcontrols@0.0.8/index.min.js';
// Assumes that a `camera` and `renderer` initialized.
const controls = new TrackballControls(camera, renderer.domElement);
// Any manual camera changes should be done first, then update the controls.
camera.position.z = 5;
controls.update();
const animate = function () {
requestAnimationFrame(animate);
// Required for updating during animations.
controls.update();
renderer.render(scene, camera);
}
</script>
```
* Testing