JSPM

threefiz

0.5.001
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q43428F
  • License MIT

Implementation of a physics engine based on the [Three.js](https://github.com/mrdoob/three.js) library.

Package Exports

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (threefiz) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    ThreeFiz

    Implementation of a physics engine based on the Three.js library.

    Demo

    Installation

    npm i threefiz

    Features

    • Rigid body dynamics
    • Collision detecion of OBB's objects
    • Library presents 3 collision relations for now
      • sphere - sphere
      • OBB - OBB
      • OBB - sphere

    Example

    This example creates a three.js environment and then adds a perpendicular and a sphere

    import * as THREE from "three";
    import ThreeFiz from "threefiz";
    
    const scene = new THREE.Scene();
    const camera = new THREE.PerspectiveCamera(
      45,
      window.innerWidth / window.innerHeight,
      1,
      10000
    );
    
    const renderer = new THREE.WebGLRenderer();
    renderer.setSize(window.innerWidth, window.innerHeight);
    document.body.appendChild(renderer.domElement);
    
    const light = new THREE.DirectionalLight(0xffffff, 3);
    
    const geometry = new THREE.SphereGeometry(1);
    const material = new THREE.MeshPhongMaterial({ color: 0x0000ff });
    const sphere = new THREE.Mesh(geometry, material);
    
    const floorGeometry = new THREE.BoxGeometry(10, 1, 10);
    const floorMaterial = new THREE.MeshPhongMaterial({ color: 0xff0000 });
    const floor = new THREE.Mesh(floorGeometry, floorMaterial);
    const physic = new ThreeFiz({ scene });
    physic.addSphere({
      mesh: sphere,
      mass: 10,
      restitution: 0.2,
      isStatic: false,
      position: new THREE.Vector3(0, 20, 0),
    });
    
    physic.addBox({
      mesh: floor,
      mass: 10,
      restitution: 0.2,
      isStatic: true,
    });
    
    physic.init();
    
    scene.add(light);
    
    camera.position.set(0, 10, 50);
    light.position.set(500, 500, 500);
    
    let animate = () => {
      physic.step();
      renderer.render(scene, camera);
      requestAnimationFrame(animate);
    };
    
    animate();