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

physics-module-ammonext

v0.1.2-fix.1

Published

physics module for Whitestorm.js

Downloads

11

Readme

physics-module-ammonext NPM Version

Physics module for Whitestorm.js [Beta]

Go to WhitestormJS/whitestorm.js

physics module

Modules list

new PHYSICS.WorldModule()

const app = new WHS.App([
  // ...
  new PHYSICS.WorldModule({
    gravity: new THREE.Vector3(0, -10, 0),
    ammo: 'path/to/ammo.js'
  })
]);

app.start();

new PHYSICS.BoxModule()

const box = new WHS.Box({
  geometry: {
    width: 2,
    height: 2,
    depth: 4
  },
  
  modules: [
    new PHYSICS.BoxModule({
      mass: 10
    })
  ],
  
  material: new THREE.MeshBasicMaterial({color: 0xff0000})
});

box.addTo(app);

new PHYSICS.SphereModule()

const sphere = new WHS.Box({
  geometry: {
    radius: 3
  },
  
  modules: [
    new PHYSICS.SphereModule({
      mass: 10
    })
  ],
  
  material: new THREE.MeshBasicMaterial({color: 0xff0000})
});

sphere.addTo(app);

new PHYSICS.PlaneModule()

const plane = new WHS.Plane({
  geometry: {
    width: 100,
    height: 100
  },
  
  modules: [
    new PHYSICS.PlaneModule({
      mass: 5
    })
  ],
  
  material: new THREE.MeshBasicMaterial({color: 0xff0000})
});

plane.addTo(app);

new PHYSICS.CapsuleModule()

No example yet.

new PHYSICS.ConeModule()

const sphere = new WHS.Cylinder({
  geometry: {
    radiusTop: 0,
    radiusBottom: 3,
    height: 4
  },
  
  modules: [
    new PHYSICS.ConeModule({
      mass: 2
    })
  ],
  
  material: new THREE.MeshBasicMaterial({color: 0xff0000})
});

box.addTo(app);

new PHYSICS.ConvexModule()

const teapot = new WHS.Model({
  geometry: {
    path: 'path/to/teapot.json'
  },
  
  modules: [
    new PHYSICS.ConvexModule({
      mass: 2,
      path: 'path/to/simplified/teapot.json'
    })
  ],
  
  material: new THREE.MeshBasicMaterial({color: 0xff0000})
});

teapot.addTo(app);

new PHYSICS.CylinderModule()

const sphere = new WHS.Cylinder({
  geometry: {
    radiusTop: 3,
    radiusBottom: 3,
    height: 4
  },
  
  modules: [
    new PHYSICS.CylinderModule({
      mass: 2
    })
  ],
  
  material: new THREE.MeshBasicMaterial({color: 0xff0000})
});

box.addTo(app);

new PHYSICS.HeightfieldModule()

const terrain = new WHS.Parametric({
  geometry: {
    func: myFunction
  },
  
  modules: [
    new PHYSICS.HeightfieldModule({
      mass: 5,
      size: new THREE.Vector2(100, 100),
      autoAlign: true // center physics object automatically.
    })
  ],
  
  material: new THREE.MeshBasicMaterial({color: 0xff0000})
});

terrain.addTo(app);

new PHYSICS.CompoundModule()

This module should be used only if you want to create a copmound physics object without shape and then add needed objects. CompoundModule is selected by default if you add object to another object.

new PHYSICS.ConcaveModule()

const teapot = new WHS.Model({
  geometry: {
    path: 'path/to/teapot.json'
  },
  
  modules: [
    new PHYSICS.ConcaveModule({
      mass: 2,
      path: 'path/to/simplified/teapot.json'
    })
  ],
  
  material: new THREE.MeshBasicMaterial({color: 0xff0000})
});

teapot.addTo(app);

new PHYSICS.SoftbodyModule()

const sphere = new WHS.Icosahedron({
  geometry: {
    radius: 3,
    detial: 2
  },
  
  modules: [
    new PHYSICS.SoftbodyModule({
      mass: 5,
      pressure: 500
    })
  ],
  
  material: new THREE.MeshBasicMaterial({color: 0xff0000})
});

sphere.addTo(app);

new PHYSICS.ClothModule()

Used only with WHS.Plane

const cloth = new WHS.Plane({
  geometry: {
    width: 100,
    height: 50
  },
  
  modules: [
    new PHYSICS.ClothModule({
      mass: 5
    })
  ],
  
  material: new THREE.MeshBasicMaterial({color: 0xff0000})
});

cloth.addTo(app);

new PHYSICS.RopeModule()

const rope = new WHS.Line({
  geometry: {
    curve: new THREE.LineCurve3(new THREE.Vector3(0, 10, 0), new THREE.Vector3(0, 20, 0))
  },
  
  modules: [
    new PHYSICS.RopeModule({
      mass: 5
    })
  ],
  
  material: new THREE.MeshBasicMaterial({color: 0xff0000})
});

rope.addTo(app);

Additional available physics parameters

RigidBody

{
  restitution: 0.3,
  friction: 0.8,
  damping: 0,
  margin: 0
}

SodtBody (SoftModule, ClothModule, RopeModule)

{
  friction: 0.8,
  damping: 0,
  margin: 0,
  klst: 0.9,
  kvst: 0.9,
  kast: 0.9,
  piterations: 1,
  viterations: 0,
  diterations: 0,
  citerations: 4,
  anchorHardness: 0.7,
  rigidHardness: 1
}

Events

collision

Example

player.on('collision', (otherObject, v, r, contactNormal) => {
  if (contactNormal.y < 0.5) // Use a "good" threshold value between 0 and 1 here!
    canJump = true;
});

FAQ

Q: My ClothModule doesn't work properly, what to do?

A: In 90% cases it is because you have set pressure parameter. You shouldn't set it for ClothModule.