class to work with physics

https://didisoftwares.ddns.net/20/index.html

class:
https://didisoftwares.ddns.net/20/js/physics.js

usage:

import IPHYSICS from "https://didisoftwares.ddns.net/20/js/physics.js"

const physics = new IPHYSICS();

await physics.create().then(() => {
 //YOUR CODE
});

//on update function
function onUpdate(){
  var delta=clock.getDelta();
  physics.update(delta);
}

example of create physic object

//create rigid body
const mass=2;
physics.createObj(mesh, 'geometry', 'obj', null, mass);

//create soft body
physics.createObj(mesh2, 'geometry', 'obj', null, mass, null, { soft: true, pressure:1 });

createobject variables

createObj(
        obj,
        type, // box - cylinder - sphere - cone - capsule // hull - shape - triangle - geometry
        model, // obj - tile - wall
        tam, // vector3 size or null
        mass, // 0=no moveable
        contactS, // extra contact size {x,y,z} or null
        extra //{ soft:false, pressure:1.0, margin:0.5, ignoreCentroid:false, } or undefined
    ) 

Just don’t forget to create the ground first with zero mass, so the objects fall on top, or you won’t see them in the scene where they will fall

1 Like