Git Product home page Git Product logo

three-orbit-controls's Introduction

three-orbit-controls

stable

ThreeJS OrbitControls as an npm module. See test for an example.

var THREE = require('three')
var OrbitControls = require('three-orbit-controls')(THREE)

function start(gl, width, height) {
    renderer = new THREE.WebGLRenderer({
        canvas: gl.canvas
    })
    renderer.setClearColor(0x000000, 1.0)

    scene = new THREE.Scene()
    camera = new THREE.PerspectiveCamera(50, width/height, 1, 1000)
    camera.position.set(0, 1, -3)
    camera.lookAt(new THREE.Vector3())

    controls = new OrbitControls(camera)

    var geo = new THREE.BoxGeometry(1,1,1)
    var mat = new THREE.MeshBasicMaterial({ wireframe: true, color: 0xffffff })
    var box = new THREE.Mesh(geo, mat)
    scene.add(box)
}

function render(gl, width, height) {
    renderer.render(scene, camera)
}

Usage

NPM

OrbitControls = require('three-orbit-controls')(THREE)

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.

The returned function has the following constructor pattern:

controls = new OrbitControls(camera[, domElement])

Versioning

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).

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.

If you see any version issues, open a ticket!

testing

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.

three-orbit-controls's People

Contributors

bsergean avatar madwed avatar mattdesl avatar wolfd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

three-orbit-controls's Issues

add zoom for orthographic camera

Works great so far. Only I'm missing proper support for cameras other than PerspectiveCamera.
E.g. zoom does not work with an OthographicCamera.

instanceof fails for camera.

Because you have bundled a copy of Three.js library in your project, instanceof fails when I pass a camera I made from another copy of Three.js (that I installed using npm and loaded with typings). Please consider requiring the installation of three.js separately from your orbital-controls package, and then using that one instead.

Or, a quick and non-breaking option would be to change the lines similar to the following:
if (this.object instanceof THREE.PerspectiveCamera) { ...
to
if (this.object.type === "PerspectiveCamera") { ...

'Orbiting' works without the fix, but zoom and pan are both broken with the following message (I'm just showing the zoom one here):
WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.

In case there is confusion, here is a tree of what is happening:

  • node_modules
    • @types
      • three (definition file. points to the following three library)
    • three
      • three (standard npm library, the one that I use throughout my project)
    • three-orbitcontrols-ts (your library)
      • three (the same three library, but you have bundled ANOTHER copy just for your module)
      • dist (your orbiting controls code)

Angular 4 - Cannot read property 'prototype' of undefined

I'm trying to use this within my Angular 4 app, but I'm getting

Error: Uncaught (in promise): TypeError: Cannot read property 'prototype' of undefined
TypeError: Cannot read property 'prototype' of undefined

Errors on this line
OrbitControls.prototype = Object.create( THREE.EventDispatcher.prototype );
OrbitControls.prototype.constructor = OrbitControls;

about maintenance and peerDependencies

Hi,

I had the same idea about packaging OrbitControls, and I created https://github.com/fibo/three-orbitcontrols, then I discovered this package (I could not find it on npm at a first search).

I have just copyed the original module, imported three.js, and exported it using commonjs. Since I have done only the minimum required to make it importable, I think it will be easier to update it, in fact three.js is now at r78 and, in particular, OrbitControl.js was updated 2 weeks ago mrdoob/three.js@e51d15c

I used peerDependencies, instead of passing three.js in the exported method, cause I think it will be easier to keep the package updated.

Do you think it is a good approach? If yes, I could do a pull request here, so we could keep only one package, instead of publish mine on npm.

Tell me what do you think, if you consider I can collaborate.

saveState

v94 (maybe it arrived earlier) has something called saveState, which something else I am using depended on.

Bower package

Thanks for this repo. Any chance we can get a bower package for this?

Update: seems that the existing bower package of THREE.js comes with OrbitControls but is not referenced directly.

incompatible with Three 0.85.2

It looks like with the latest version of THREE, the change event is never dispatched. I went back to 0.82.1 and it seems to work now.

I tested with 0.85.0 and it still works, so it could be either one of the latest two versions that might have introduced some bugs or breaking changes.

combination select + three-orbit-controls

Seems like I can't use a simple HTML select element anymore when I use three-orbit-controls on a project where my whole viewport is a canvas element.

Any ideas how I could fix this?

Orbit Controls does not use camera.lookAt value

Reproduce:

  1. Create a camera and set its lookAt value.
  2. Create orbit controls.

Issue:
After adding orbit controls, the camera is "looking at" the origin, not the camera's lookAt value.

How do you get the camera to lookAt a specific point when adding orbit controls?

Some example code:

  camera = new THREE.OrthographicCamera(
    globals.cameraDimensions.left,
    globals.cameraDimensions.right,
    globals.cameraDimensions.top,
    globals.cameraDimensions.bottom,
    1,
    2000
  );

  // Sets the position to a Vector3 angle, then sets the length.
  camera.position.set(0, 50, 100);
  camera.up = new THREE.Vector3(0, 1, 0);
  camera.lookAt(new THREE.Vector3(0, 50, 0));

  renderer = new THREE.WebGLRenderer({ alpha: true, antialias: true });
  renderer.setSize(window.innerWidth, window.innerHeight);
  document.body.appendChild(renderer.domElement);

  controls = new THREE.OrbitControls(camera, renderer.domElement);

camera up vector not respected when switching cameras

In an application that support multiple view / camera, switching camera can be done by setting the .object member variable.

this.controls.object = otherCamera

The problem is that if this camera has an up vector different from the default value, that up vector won't be respected. However, OrbitControls has support for non standard (0, 1, 0) up vectors since some code respect it to compute its internal quaternion. (cf those 2 lines of code in the "constructor").

var quat = new THREE.Quaternion().setFromUnitVectors( object.up, new THREE.Vector3( 0, 1, 0 ) );
var quatInverse = quat.clone().inverse();

A patch request follows, which make quat and quatInverse member variables and turn the previous block of code into a method that is called on update.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.