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