npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

orbit-controls

v1.2.4

Published

generic controls for orbiting a target in 3D

Downloads

1,466

Readme

orbit-controls

experimental

(demo)(source)

Generic controls for orbiting a target in 3D. Can be used to control a camera, a 3D ray, or anything with { position, direction }.

Features:

  • zooms on mouse wheel
  • values are smoothed with damping
  • intuitive orbiting; roll is locked
  • modular and un-opinionated; can be used in any render engine
  • zooming with two-touch pinch

Roadmap:

  • panning with two fingers / right mouse button

Can be used with any camera abstraction that uses position and direction to form the view matrix, including ThreeJS, Babylon, stackgl, etc.

Well-suited alongside perspective-camera.

Note: This module is still in development.

Example

var controls = require('orbit-controls')()

function tick () {
  controls.update()
  controls.copyInto(camera.position, camera.direction, camera.up)
}

Demos

Usage

NPM

controls = createControls([opts])

  • position the initial position of the camera, default [0, 0, 1]
  • up the initial direction of the camera, default [0, 1, 0]
  • target the center of the orbit, default [0, 0, 0]
  • phi the initial rotation in radians, phi in spherical coordinates, default Math.PI/2
  • theta the initial rotation in radians, theta in spherical coordinates, default 0
  • distance the distance from the target, default 1
  • damping how fast the controls slow down, between 0 and 1, default 0.25
  • rotateSpeed the speed of the rotation, default 0.28
  • zoomSpeed the speed of the zoom, default 0.0075
  • pinchSpeed (coming soon) the speed of the pinch, default 0.0075
  • pinch (coming soon) enable pinching, default true
  • zoom enable zooming, default true
  • rotate enable rotating, default true
  • phiBounds the bounds of the phi rotation, default [0, Math.PI]
  • thetaBounds the bounds of the theta rotation, default [-Infinity, Infinity]
  • distanceBounds the bounds of the distance, default [0, Infinity]
  • parent the parent element, default window
  • element the element, default window

methods

controls.update()

Update the internal position, direction, and up vectors that represent the camera.

controls.copyInto(position, direction, up)

Apply the control's current state to a target camera.

This is purely for convenience; you can also copy the controls.position and other members manually.

controls.enable()

Enables the DOM events and input, attaching new mouse and touch events. If already enabled, this function does nothing.

controls.disable()

Disables the DOM events and input, detaching all events. If already disabled, this function does nothing.

properties

position, direction, up

Vector arrays [x, y, z] that represent the camera controls. These are typically copied into your camera interface with:

var camera = new MyPerspectiveCamera()
controls.copyInto(camera.position, camera.direction, camera.up)

target

The vec3 center of the orbit

phi, theta

The initial rotation in radians, in spherical coordinates. Changing either will re-calculate the direction.

distance

The distance from the target, default 1

damping

How fast the controls slow down, between 0 and 1, default 0.25

rotateSpeed, zoomSpeed, pinchSpeed

The speed of the controls.

pinch, zoom, rotate

Enable pinch, zoom, and rotate

phiBounds, thetaBounds, distanceBounds

The bounds of the controls

dragging (read-only)

Returns true if the user is currently dragging the controls.

pinching (read-only)

Returns true if the user is currently pinching (zooming on mobile) the controls.

License

MIT, see LICENSE.md for details.