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

hecs-plugin-physx

v0.17.0

Published

A plugin for hecs that provides physics features via PhysX

Downloads

10

Readme

| :warning: Important: This package is WIP and is not ready for use | | --- |

Hecs Plugin PhysX

A plugin for Hecs that adds functionality to simulate physx-js bodies.


Usage

Install via npm/yarn:

yarn add hecs hecs-plugin-physx physx-js

This plugin depends on physx-js and expects you to load the wasm module as a global variable PhysX before instantiating your World. (note: this isn't ideal and will be improved on)

import PHYSX from 'physx-js'
import { World } from 'hecs'
import PhysXPlugin from 'hecs-plugin-physx'

function createWorld() {
  const world = new World({
    plugins: [PhysXPlugin],
    systems: [/* your systems */],
    components: [/* your components */],
  })
}

window.PhysX = PHYSX({
  onRuntimeInitialized() {
    createWorld()
  }
})

A world instance with this plugin installed can now use all of the features below:


World.physics

This prop is available if you want to extends the plugin. It contains all the shared parts for simulation such as the scene, layers and cooking.

World.physics.layers

Use this to specify which layers collide with each other. Layers are set on each Collider component (see below). There are 7 layers available and they all collide with each other by default.

const { layers } = world.physics
const Layers = {
  DEFAULT: 0,
  GHOST: 1,
}
layers.setCollision(Layers.DEFAULT, Layers.GHOST, false)

World.physics.setPassive(Boolean)

In certain cases such as an editor, you may want to register the plugin and its components but not have the physics simulated. Setting passive to false will disable the systems that build rigid bodies, collider shapes, and simulate physics.

RigidBody (Component)

This component describes the rigidbody the entity should have.

Field|Type|Default|Description ---|---|---|--- kind|String|'STATIC'|The kind of rigidbody. Options are STATIC, KINEMATIC and DYNAMIC linearVelocity|Vector3|new Vector3()|The linear velocity of the body. Ignored unless kind is DYNAMIC. angularVelocity|Vector3|new Vector3()|The angular velocity of the body. Ignored unless kind is DYNAMIC. mass|Number|1|The mass of the body. Ignored unless kind is DYNAMIC.

import { Transform } from 'hecs-plugins-core'
import { RigidBody } from 'hecs-plugins-physx'

entity
  .add(Transform)
  .add(RigidBody, { kind: 'DYNAMIC' })

Notes: Internally the plugin looks for a RigidBody component and will build the actual rigid body and attach it as a RigidBodyRef component. You can use this if you need to access the actual rigid body.

Collider (Component)

Describes a collider shape that should be attached to a rigid body. The shape will be attached to the closest entity that has a RigidBody component, starting from the current entity and walking up its parents. You can create compound colliders by having one parent RigidBody entity and multiple child Collider entities.

Field|Type|Default|Description ---|---|---|--- shape|String|'BOX'|The shape of the collider. Options are BOX and SPHERE boxSize|Vector3|new Vector3(1, 1, 1)|The size of the box. Only used when shape is BOX. sphereRadius|Number|0.5|The radius of the sphere. Only used when shape is SPHERE. material|Vector3|new Vector3(0.6, 0.6, 0)|The material of the collider shape. X is static friction, Y is dynamic friction, Z is restitution layer|Number|0|The layer this shape lives on. By default all shapes collide with each other.

Notes: Internally this plugin looks for a Collider component, builds the shape and adds it as a ColliderRef component. It also attaches a ColliderBody component which contains the actual RigidBody is has been attached to.

import { Transform, Vector3 } from 'hecs-plugins-core'
import { Collider } from 'hecs-plugins-physx'

entity
  .add(Transform)
  .add(Collider, { 
    shape: 'BOX',
    boxSize: new Vector3(2, 4, 2),
  })

FixedJoint (Component)

Describes a fixed joint that should be attached to another entity.

Field|Type|Default|Description ---|---|---|--- entity|String|''|The entity to attach the fixed joint to. If unset, the joint is attached to world space. breakForce|Number|0|The force needed to break the joint. Zero is unbreakable. breakTorque|Number|0|The torque needed to break the joint. Zero is unbreakable.

Notes: Internally this plugin looks for a FixedJoint component, constructs the actual joint and adds it as a FixedJointRef component. When a fixed joint breaks, the FixedJoint and FixedJointRef components will be removed automatically. If you are adding your own functionality that depends on a fixed joint it is better to use the actual ref to determine it's existence.

import { Transform, Vector3 } from 'hecs-plugins-core'
import { RigidBody, Collider, FixedJoint } from 'hecs-plugins-physx'

entity
  .add(Transform)
  .add(RigidBody, { kind: 'DYNAMIC' })
  .add(Collider)
  .add(FixedJoint)