These docs are for v1.2. Click to read the latest docs for v2-beta.x.

🚧

WHS.PhysicsComponent depends on WHS.MeshComponent (It should be set first).

PhysicsComponent overwrites some data to make it possible to use this object as physics object. It wraps 3D transforms to make object relocation while physics is simulating possible.

It also adds all Physijs.mesh methods (like .setLinearVelocity()) to the component.

Making a Physics mesh Component

// ...
import MeshComponent from 'whs/lib/core/MeshComponent';
import PhysicsComponent from 'whs/lib/core/PhysicsComponent';
// ...

@PhysicsComponent
@MeshComponent
class BasicSphere extends Component {
  // ...

  build(params = {}) {
    // Load THREE.Material from properties.
    const material = loadMaterial(params.material);

    let Mesh;

    if (this.physics) Mesh = SphereMesh;
    else Mesh = THREE.Mesh;

    return new Promise((resolve) => {
      this.native = new Mesh(
        new THREE.SphereGeometry(params.myParameter, 16, 16),

        material,
        this.params
      );

      resolve();
    });
  }
}

Added methods list

  • setAngularVelocity()
  • setLinearVelocity()
  • applyCentralImpulse()
  • applyImpulse()
  • applyTorque()
  • applyCentralForce()
  • applyForce()
  • getAngularVelocity()
  • getLinearVelocity()
  • setAngularFactor()
  • setLinearFactor()
  • setDamping()
  • setCcdMotionThreshold()
  • setCcdSweptSphereRadius()
  • appendAnchor(world, object, node, influence, collisionBetweenLinkedBodies = true)

See their explanation at Physijs wiki