How to use three-to-cannon - 2 common examples

To help you get started, we’ve selected a few three-to-cannon examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github donmccurdy / aframe-extras / src / physics / body.js View on Github external
initBody: function () {
    var shape,
        el = this.el,
        data = this.data,
        pos = el.getComputedAttribute('position'),
        options = data.shape === 'auto' ? undefined : AFRAME.utils.extend({}, this.data, {
          type: mesh2shape.Type[data.shape.toUpperCase()]
        });

    // Matrix World must be updated at root level, if scale is to be applied – updateMatrixWorld()
    // only checks an object's parent, not the rest of the ancestors. Hence, a wrapping entity with
    // scale="0.5 0.5 0.5" will be ignored.
    // Reference: https://github.com/mrdoob/three.js/blob/master/src/core/Object3D.js#L511-L541
    // Potential fix: https://github.com/mrdoob/three.js/pull/7019
    this.el.object3D.updateMatrixWorld(true);
    shape = mesh2shape(this.el.object3D, options);

    if (!shape) {
      this.el.addEventListener('model-loaded', this.initBody.bind(this));
      return;
    }

    this.body = new CANNON.Body({
github donmccurdy / aframe-physics-system / src / components / body / body.js View on Github external
quaternion: new CANNON.Quaternion(quat.x, quat.y, quat.z, quat.w),
      linearDamping: data.linearDamping,
      angularDamping: data.angularDamping,
      type: data.type === 'dynamic' ? CANNON.Body.DYNAMIC : CANNON.Body.STATIC,
    });

    // Matrix World must be updated at root level, if scale is to be applied – updateMatrixWorld()
    // only checks an object's parent, not the rest of the ancestors. Hence, a wrapping entity with
    // scale="0.5 0.5 0.5" will be ignored.
    // Reference: https://github.com/mrdoob/three.js/blob/master/src/core/Object3D.js#L511-L541
    // Potential fix: https://github.com/mrdoob/three.js/pull/7019
    this.el.object3D.updateMatrixWorld(true);

    if(data.shape !== 'none') {
      var options = data.shape === 'auto' ? undefined : AFRAME.utils.extend({}, this.data, {
        type: mesh2shape.Type[data.shape.toUpperCase()]
      });

      var shape = mesh2shape(this.el.object3D, options);

      if (!shape) {
        el.addEventListener('object3dset', this.initBody.bind(this));
        return;
      }
      this.body.addShape(shape, shape.offset, shape.orientation);

      // Show wireframe
      if (this.system.debug) {
        this.shouldUpdateWireframe = true;
      }

      this.isLoaded = true;

three-to-cannon

Convert a THREE.Mesh to a CANNON.Shape.

MIT
Latest version published 3 months ago

Package Health Score

69 / 100
Full package analysis

Popular three-to-cannon functions