UNPKG

threefiz

Version:

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

2 lines (1 loc) 1.23 kB
import{c as i,B as l,M as c,C as u,b as d,T as C,s as p,V as o,Q as b,E as x,d as M,e as m,r as S}from"./init-BHUQqx8w.js";import{g as F}from"./lil-gui.module.min-Vka56b52.js";i.position.set(0,100,200);const g=new l(10,10,10),B=new c({color:new u("hsl(200, 100%, 80%)")}),r=new d(g,B),P=new l(200,10,200),V=new c({color:new u("hsl(0, 100%, 80%)")}),w=new d(P,V);r.castShadow=!0;r.receiveShadow=!0;w.receiveShadow=!0;const e=new C({scene:p});for(let t=0;t<10;t++){const n=new o().random().multiplyScalar(50),f=new o().random();e.addBox({mesh:r.clone(),position:new o(n.x,10+n.y,n.z),velocity:new o(0,0,0),angularVelocity:new o(0,0,0),rotation:new b().setFromEuler(new x().setFromVector3(f)),restitution:.5})}e.addBox({mesh:w,restitution:.5,isStatic:!0});e.init();const s=new M;s.dom.style.setProperty("position","absolute");s.dom.style.setProperty("top","0");const a={pauseOnCollision:!1,start:()=>{e.resume()},pause:()=>e.pause()},v=t=>{t?(e.onCollision=()=>{e.pause()},e.pause()):(e.onCollision=()=>{e.resume()},e.resume())};v(a.pauseOnCollision);const h=new F;h.add(a,"start");h.add(a,"pause");document.body.appendChild(s.dom);m.update();const y=()=>{m.update(),s.update(),e.step(),S.render(p,i),requestAnimationFrame(y)};y();