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

mesh-collision

v1.0.0

Published

return the contact set between two 3d meshes in motion

Downloads

7

Readme

mesh-collision

return the contact set between two 3d meshes in motion

example

var collide = require('mesh-collision');
var mat4 = require('gl-mat4');
var transformMat4 = require('gl-vec3/transformMat4');

var loop = require('frame-loop');
var lerp = require('mat4-interpolate');
var teapot = require('teapot');
var bunny = require('bunny');

var bodies = [
    {
        prev: mat4.create(),
        next: translate(mat4.create(), [-15,0,5]),
        cells: bunny.cells,
        positions: bunny.positions,
        velocity: translate(mat4.create(), [5,0,0])
    },
    {
        prev: mat4.create(),
        next: translate(mat4.create(), [0,0,10]),
        cells: teapot.cells,
        positions: teapot.positions,
        velocity: translate(mat4.create(), [0,0,-1.6])
    }
];
var tmpm = mat4.create();
var origin = [0,0,0];

var engine = loop({ fps: 10 }, function (dt) {
    for (var i = 0; i < bodies.length; i++) {
        var b = bodies[i];
        mat4.copy(b.prev, b.next);
        
        var endm = mat4.multiply(tmpm, b.next, b.velocity);
        lerp(b.next, b.next, endm, dt / 1000);
    }
    
    for (var i = 0; i < bodies.length - 1; i++) {
        for (var j = i + 1; j < bodies.length; j++) {
            var c = collide(bodies[i], bodies[j]);
            if (c) {
                console.log(c);
                engine.pause();
            }
        }
    }
});
engine.run();

function translate (out, xyz) { return mat4.translate(out, out, xyz) }

output:

{ mix: 0.7277780106077933,
  point: [ -1.070312, 0.234375, 0.0786932272210148 ],
  normal: [ -0.5790840193768065, -0.8026245943343034, 0.14302258238508114 ] }

method

var collision = require('mesh-collision')

var contact = collision(a, b)

Raycast from each point in a onto b.

a and b both must have these properties:

  • next - a mat4 of the next position and rotation
  • prev - a mat4 of the previous position and rotation
  • positions - an array of [x,y,z] coordinate arrays
  • cells - an array of arrays of indexes

The positions and cells array structures are compatible with simplicial-complex.

If there was not a collision, return null.

Otherwise return contact, an object with these properties:

  • point - contact point as an [x,y,z]
  • normal - contact normal as an [x,y,z]
  • mix - the amount of linear interpolation (0 to 1) between prev and next where the collision occured.

The contact object is modeled after the contact set mentioned in the SPOOK paper but using mix instead of a penetration depth.

install

With npm do:

npm install mesh-collision

license

MIT