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.89 kB
import{c as w,B as l,M as m,C as M,b as i,T as g,s as f,Q as G,V as r,E as B,S as E,a as v,d as F,e as C,r as I}from"./init-BHUQqx8w.js";import{g as O}from"./lil-gui.module.min-Vka56b52.js";w.position.set(0,100,200);const z=new l(200,5,200),T=new l(200,10,5),S=new m({color:new M("hsl(200, 100%, 80%)")}),x=new i(z,S),p=new i(T,S);x.receiveShadow=!0;p.castShadow=!0;p.receiveShadow=!0;const o=new g({scene:f});o.addBox({mesh:x,isStatic:!0});for(let e=0;e<4;e++){const t=Math.sin(Math.PI*e/2),n=Math.cos(Math.PI*e/2);o.addBox({mesh:p.clone(),position:new r(97.5*t,7.5,-97.5*n),rotation:new G().setFromEuler(new B(0,t*Math.PI/2,0)),isStatic:!0})}let V=100,$=100;for(let e=0;e<V;e++){const s=Math.random()*10+5,t=Math.random()*10+5,n=Math.random()*10+5,a=new l(s,t,n),P=new m({color:new M(`hsl(${Math.random()*360}, 100%, 80%)`)}),h=new i(a,P);h.castShadow=!0,h.receiveShadow=!0,o.addBox({mesh:h,position:new r(Math.random()+-20,50+t*e,Math.random())})}for(let e=0;e<$;e++){const s=Math.random()*5+3,t=new E(s),n=new m({map:v(8,8,`hsl(${Math.random()*360}, 100%, 80%)`,`hsl(${Math.random()*360}, 100%, 70%)`)}),a=new i(t,n);a.castShadow=!0,a.receiveShadow=!0,o.addSphere({mesh:a,position:new r(Math.random(),10+s*e,Math.random())})}const Q=()=>{o.objects.map(e=>{e.position.y<-100&&(e.setPosition(()=>new r(Math.random(),200,Math.random())),e.setVelocity(()=>new r(0,0,0)))})};o.init();const d=new F;d.dom.style.setProperty("position","absolute");d.dom.style.setProperty("top","0");const c={pauseOnCollision:!1,start:()=>o.resume(),pause:()=>o.pause()},b=e=>{e?(o.onCollision=()=>{o.pause()},o.pause()):(o.onCollision=()=>{o.resume()},o.resume())};b(c.pauseOnCollision);const u=new O;u.add(c,"pauseOnCollision").onChange(b);u.add(c,"start");u.add(c,"pause");document.body.appendChild(d.dom);C.update();const y=()=>{C.update(),d.update(),o.step(),Q(),I.render(f,w),requestAnimationFrame(y)};y();