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

rb-phys2d

v0.1.0

Published

2D rigid body physics for JavaScript and Typescript

Downloads

6

Readme

CI npm version

RbPhys2D

JavaScript and Typescript rigid body 2d physics engine primarily devised to create complex scenes involved various types of joints and shapes.

Examples

Features

  • Circle, Box, Ellipse, Capsule, Polygon
  • Continuous Collision Detection (only between convex shapes yet)
  • Concave Mesh Shape
  • Lifecycle Events
  • Distance, Prismatic, Revolute, Weld, Wheel, Spring, Mouse, Motor Joints
  • Physical Material Features: Restitution, Friction, Damping
  • Bodies Sleeping
  • World Islands
  • Force-Based Constraint Solver

Installation

Using npm package manager:

npm install rb-phys2d

Getting started

ESM

  1. Install additional npm package for drawing world onto canvas element:
npm install rb-phys2d-renderer
  1. Create world:
// gl-matrix is nessesary for vector/matrix operations
import { vec2 } from 'gl-matrix';
// include Box shape and world factory
import { Box, createWorld } from "rb-phys2d";
// stuff for rendering and interacting with world through canvas
import { createViewport, createWorldRenderer } from "rb-phys2d-renderer";

// world is main entry point for almost all api
const world = createWorld({ ... })
  1. Fill world with bodies:
// create static floor
const floor = world.createBody({
  position: vec2.fromValues(0, -5),
  mass: Number.POSITIVE_INFINITY,
  inertia: Number.POSITIVE_INFINITY,
});
world.addCollider({ shape: new Box(10, 2), body: floor });

// create dynamic box
const box = world.createBody({ mass: 1 });
world.addCollider({ shape: new Box(1, 1), body: box });
  1. Create viewport and promote world through main loop:
const canvas = document.getElementById('canvas');

const viewport = createViewport(canvas)
  .addMousePickingControl(world)
  .addViewportAdjustingControl();

const renderer = createWorldRenderer(viewport, world);

// it is frame duration in seconds
const dt = 0.0167;

const step = () => {
  // world simulation starts here
  world.step(dt);

  // here all rendering happen
  renderer.clear();
  renderer.render();

  requestAnimationFrame(step);
};

requestAnimationFrame(step);

See full source code and life demo here.

Browser

  1. Include necessary bundles into html page
<script src="./node_modules/gl-matrix/gl-matrix.js"></script>
<script src="./node_modules/rb-phys2d/dist/bundle/rb-phys2d.js"></script>
<script src="./node_modules/rb-phys2d-renderer/dist/bundle/rb-phys2d-renderer.js"></script>
  1. Use the global accessible objects rbPhys2d and rbPhys2dRenderer to get access to api.

Extensions And Plugins

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT