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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@basementuniverse/camera-3d

v1.5.0

Published

A camera component for use in 3d browser games

Readme

Game Component: Camera 3d

A camera component for use in 3d browser games.

Installation

npm install @basementuniverse/camera-3d

How to use

Create a camera:

import Camera3d from '@basementuniverse/camera-3d';

const camera = new Camera3d(
  // Initial position
  { x: 0, y: 0, z: 0 },

  // Initial target position
  { x: 0, y: 0, z: 0 },

  // Options (all optional)
  {
    mode: 'perspective', // 'perspective' or 'orthographic'
    up: { x: 0, y: 1, z: 0 }, // Up vector
    fov: Math.PI / 4, // Field of view (radians)
    aspect: 1, // Aspect ratio
    near: 0.1, // Near clipping plane
    far: 1000, // Far clipping plane
  }
);

Now we can start projecting 3D points into 2D screen space:

const projectedPoint = camera.project(
  { x: 1, y: 1, z: 1 }, // Point in 3D space
  { x: window.innerWidth, y: window.innerHeight } // Screen size
);

We can also get the view matrix and perspective or orthographic projection matrix:

const viewMatrix = camera.getViewMatrix();
const perspectiveProjectionMatrix = camera.getPerspectiveProjectionMatrix();
const orthographicProjectionMatrix = camera.getOrthographicProjectionMatrix();

The camera uses mat, vec2 and vec3 types from @basementuniverse/vec.

Easing

For easing to work correctly, we need to update the camera every frame:

class Game {
  // ...

  update() {
    // Update the camera to apply easing
    camera.update();
  }

  // ...
}

Move the camera by setting camera.position.

Get the camera's current "real" position (after easing) by reading camera.actualPosition.

Snap the camera to a new position (without easing) by setting camera.positionImmediate.

Set the camera's target position by setting camera.target.

Get the camera's current "real" target position (after easing) by reading camera.actualTarget.

Snap the camera's target position (without easing) by setting camera.targetImmediate.

Screen to world and raycasting

To convert a screen position to a world position, we can use the screenToWorld method:

const worldPosition = camera.screenToWorld(
  { x: screenX, y: screenY }, // Screen position
  { x: window.innerWidth, y: window.innerHeight }, // Screen size
  depth // Depth in world space (measured in world units)
);

We can also calculate a ray from the camera through a screen position:

const ray = camera.raycast(
  { x: screenX, y: screenY }, // Screen position
  { x: window.innerWidth, y: window.innerHeight } // Screen size
);