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

regl-camera

v2.1.1

Published

Camera for regl

Downloads

204

Readme

regl-camera

A basic reusable "turntable" camera component for regl. (Secretly just spherical coordinates.)

Example

const regl = require('regl')()
const camera = require('regl-camera')(regl, {
  center: [0, 2.5, 0]
})

const bunny = require('bunny')
const normals = require('angle-normals')

const drawBunny = regl({
  frag: `
    precision mediump float;
    varying vec3 vnormal;
    void main () {
      gl_FragColor = vec4(abs(vnormal), 1.0);
    }`,
  vert: `
    precision mediump float;
    uniform mat4 projection, view;
    attribute vec3 position, normal;
    varying vec3 vnormal;
    void main () {
      vnormal = normal;
      gl_Position = projection * view * vec4(position, 1.0);
    }`,
  attributes: {
    position: bunny.positions,
    normal: normals(bunny.cells, bunny.positions)
  },
  elements: bunny.cells
})

regl.frame(() => {
  camera((state) => {
    if (!state.dirty) return;
    regl.clear({color: [0, 0, 0, 1]})
    drawBunny()
  })
})

Install

npm i regl-camera

API

Constructor

var camera = require('regl-camera')(regl[, options])

module.exports of regl-camera is a constructor for the camera. It takes the following arguments:

  • regl is a handle to the regl instance
  • options is an object with the following optional properties:
    • center which is the center of the camera
    • theta the theta angle for the camera
    • phi the phi angle for the camera
    • distance the distance from the camera eye to the center
    • up is the up vector for the camera
    • fovy is the field of view angle in y direction (defaults to Math.PI / 4)
    • near is the near clipping plane in z (defaults to 0.01)
    • far is the far clipping plane in z (defaults to 1000.0)
    • mouse set to false to turn off mouse events
    • damping multiplier for inertial damping (default 0.9). Set to 0 to disable inertia.
    • noScroll boolean flag to prevent mouse wheel from scrolling the whole window. Default is false.
    • element is an optional DOM element for mouse events (defaults to regl canvas element)
    • rotationSpeed the rotation interactions (default: 1)
    • zoomSpeed the zoom interactions (default: 1)
    • renderOnDirty boolean flag to control whether scene is only rendered when the camera state has changed. If true, render can be triggerd at any time by setting camer.dirty = true. If false, dirty state can still be detected and used through context.dirty.

Command usage

camera(block)

regl-camera sets up an environment with the following variables in both the context and uniform blocks:

| Variable | Type | Description | |----------|------|-------------| | view | mat4 | The view matrix for the camera | | projection | mat4 | The projection matrix for the camera | | center | vec3 | The center of the camera | | eye | vec3 | The eye coordinates of the camera | | up | vec3 | The up vector for the camera matrix | | theta | float | Latitude angle parameter in radians | | phi | float | Longitude angle parameter in radians | | distance | float | Distance from camera to center of objective | | dirty | boolean | Flag set to true when camera state has changed |

Note These properties can also be accessed and modified directly by accessing the object, though at the moment you will need to manually set camera.dirty = true if relying upon renderOnDirty

License

(c) 2016 Mikola Lysenko. MIT License