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.09 kB
import{c as a,S as m,M as r,a as h,b as i,B as w,C as y,T as C,V as s,s as p,d as b,e as l,r as x}from"./init-BHUQqx8w.js";import{g as M}from"./lil-gui.module.min-Vka56b52.js";a.position.set(0,20,100);const g=new m(10),f=new r({map:h(8,5,"hsl(0, 50%, 60%)","hsl(0, 50%, 80%)"),transparent:!0,opacity:.5}),G=new i(g,f),S=new w(15,15,15),B=new r({color:new y("hsl(240, 50%, 80%)"),transparent:!0,opacity:.5}),F=new i(S,B),e=new C({scene:p,gravity:new s(0,0,0)});e.addSphere({mesh:G,position:new s(-15,0,0)});e.addBox({mesh:F,position:new s(15,10,5),velocity:new s(-5,0,0)});e.init();const o=new b;o.dom.style.setProperty("position","absolute");o.dom.style.setProperty("top","0");const t={pauseOnCollision:!1,start:()=>e.resume(),pause:()=>e.pause()},c=u=>{u?(e.onCollision=()=>{e.pause()},e.pause()):(e.onCollision=()=>{e.resume()},e.resume())};c(t.pauseOnCollision);const n=new M;n.add(t,"pauseOnCollision").onChange(c);n.add(t,"start");n.add(t,"pause");document.body.appendChild(o.dom);l.update();const d=()=>{l.update(),o.update(),e.step(),x.render(p,a),requestAnimationFrame(d)};d();