matrix.org/static/~matthew/dots-3d/assets/index.273f8abd.js

2 lines
8.2 KiB
JavaScript

var ne=Object.defineProperty;var se=(s,e,o)=>e in s?ne(s,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):s[e]=o;var b=(s,e,o)=>(se(s,typeof e!="symbol"?e+"":e,o),o);import{G as D,M as T,C as Q,a as x,Q as ie,V as w,S as X,T as c,b as re,P as ae,W as le,O as ce,F as pe,L as he,B as A,c as k,d as ue,R as de,e as me,f as fe,g as ge}from"./vendor.c4322398.js";const we=function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const t of document.querySelectorAll('link[rel="modulepreload"]'))n(t);new MutationObserver(t=>{for(const i of t)if(i.type==="childList")for(const r of i.addedNodes)r.tagName==="LINK"&&r.rel==="modulepreload"&&n(r)}).observe(document,{childList:!0,subtree:!0});function o(t){const i={};return t.integrity&&(i.integrity=t.integrity),t.referrerpolicy&&(i.referrerPolicy=t.referrerpolicy),t.crossorigin==="use-credentials"?i.credentials="include":t.crossorigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function n(t){if(t.ep)return;t.ep=!0;const i=o(t);fetch(t.href,i)}};we();class ye{constructor(e){b(this,"group");b(this,"points");b(this,"segments");b(this,"previewSegment");b(this,"color");b(this,"material");this.group=new D,this.points=[],this.segments=[],this.color=e,this.material=new T({color:this.color});const o=new Q(.0286,.0286,1);this.previewSegment=new x(o,this.material)}getObject(){return this.group}positionSegment(e,o,n){const t=n.clone().sub(o),i=t.length(),r=new ie().setFromUnitVectors(new w(0,1,0),t.normalize());e.scale.set(1,i,1),e.setRotationFromQuaternion(r),e.position.copy(o.clone().lerp(n,.5))}pushPoint(e){if(console.log("pushPoint()",e,JSON.stringify(this.points)),this.points.length==0&&(this.group.add(this.previewSegment),this.positionSegment(this.previewSegment,e,e)),this.points.push(e),this.points.length>1){const r=new Q(.0286,.0286,1),a=new T({color:this.color}),u=new x(r,a);this.positionSegment(u,this.points[this.points.length-2],this.points[this.points.length-1]),this.group.add(u),this.segments.push(u)}const o=new X(.15),n=this.material.clone();n.transparent=!0,n.opacity=.5,n.depthWrite=!1;const t=new x(o,n);t.position.copy(e),this.group.add(t);const i=1;new c.Tween(t.material).delay(150*i).to({opacity:0},450*i).easing(c.Easing.Cubic.Out).start(),new c.Tween(t.scale).to({x:2,y:2,z:2},600*i).easing(c.Easing.Cubic.Out).start().onComplete(()=>{this.group.remove(t)})}popPoint(){console.log("popPoint()",JSON.stringify(this.points)),this.points.pop();const e=this.segments.pop();this.group.remove(e)}clear(){console.log("clear()",JSON.stringify(this.points));for(const e of this.segments)this.group.remove(e);this.group.remove(this.previewSegment),this.segments=[],this.points=[]}previewPoint(e){!this.points.length||(e?this.positionSegment(this.previewSegment,this.points[this.points.length-1],e):(e=this.points[this.points.length-1],this.positionSegment(this.previewSegment,e,e)))}}const F=new re,O=new ae(75,window.innerWidth/window.innerHeight,.1,1e3),g=new le({antialias:!0});g.setSize(window.innerWidth,window.innerHeight);g.setClearColor(16777215,0);document.body.appendChild(g.domElement);const S=new ce(O,g.domElement);S.enableDamping=!0;S.enablePan=!1;O.position.set(0,0,5);S.update();const G=new X(.15),E=3,y=3,M=3,v=1,W=[14313039,9461936,14932816,9747193,10544793],I=[];for(const s of W)I.push(new T({color:s}));F.fog=new pe(16777215,4,9);const f=new D;F.add(f);const be=new T({transparent:!0,opacity:0,depthTest:!1});let P=[];const Y=[],h=new Array(E);for(let s=0;s<E;s++){h[s]=new Array(y);for(let e=0;e<y;e++){h[s][e]=new Array(M);for(let o=0;o<M;o++){const n=Math.floor(W.length*Math.random()),t=new x(G,I[n]);t.position.x=s,t.position.y=e,t.position.z=o,f.add(t),P.push(t),h[s][e][o]=t;const i=new x(G,be);i.scale.x=2,i.scale.y=2,i.scale.z=2,i.position.x=s,i.position.y=e,i.position.z=o,Y.push(i),f.add(i)}}}const z=new D;z.renderOrder=1e4;f.add(z);const L=new he({color:14540253,transparent:!0,opacity:0});for(let s=0;s<E;s++){for(let e=0;e<y;e++){const o=[];o.push(new w(s,e,0)),o.push(new w(s,e,M-1));const n=new A().setFromPoints(o),t=new k(n,L);z.add(t)}for(let e=0;e<M;e++){const o=[];o.push(new w(s,0,e)),o.push(new w(s,y-1,e));const n=new A().setFromPoints(o),t=new k(n,L);z.add(t)}}for(let s=0;s<y;s++)for(let e=0;e<M;e++){const o=[];o.push(new w(0,s,e)),o.push(new w(E-1,s,e));const n=new A().setFromPoints(o),t=new k(n,L);z.add(t)}te();f.translateX(-(E-1)/2);f.translateY(-(y-1)/2);f.translateZ(-(M-1)/2);const $=new ue,C=new de,B=new ge,K=new w,j=new w,R=new w,U=new me;let V=null,p=null,N=!1,l=[],d=null,J=0;g.domElement.addEventListener("pointerdown",Pe);g.domElement.addEventListener("pointermove",Me);g.domElement.addEventListener("pointerup",ee);g.domElement.addEventListener("pointerleave",ee);g.domElement.style.touchAction="none";const Z=fe();document.body.appendChild(Z.dom);function ve(s){const e=g.domElement.getBoundingClientRect();B.x=(s.clientX-e.left)/e.width*2-1,B.y=-(s.clientY-e.top)/e.height*2+1}function _(s,e){ve(s);const o=[];C.setFromCamera(B,O);let n=!0;if(C.intersectObjects(P,!0,o),o.length||(n=!1,C.intersectObjects(Y,!0,o)),o.length)if(S.enabled=!1,V=p,n)p=o[0].object;else{const t=o[0].object;p=h[t.position.x][t.position.y][t.position.z]}else p=null,N=!1;if(p){let t;if(e)d&&f.remove(d.getObject()),t=p,l=[t],d=new ye(p.material.color),f.add(d.getObject()),d.pushPoint(p.position),$.setFromNormalAndCoplanarPoint(O.getWorldDirection($.normal),R.setFromMatrixPosition(o[0].object.matrixWorld)),C.ray.intersectPlane($,j)&&(U.copy(o[0].object.parent.matrixWorld).invert(),K.copy(j).sub(R.setFromMatrixPosition(o[0].object.matrixWorld)));else{if(t=l[l.length-1],p.position.distanceTo(t.position)>1.1||!p.material.color.equals(t.material.color)||p===l[l.length-2])return;!V&&p==t&&Date.now()-J>500?l.length>1&&(d.popPoint(),l.pop(),N=!0):p!=t&&!N&&(d.pushPoint(p.position),l.push(p),J=Date.now())}}}function Pe(s){new c.Tween(L).to({opacity:1},250*v).easing(c.Easing.Cubic.In).start(),_(s,!0)}function Me(s){l.length>0&&(_(s,!1),C.ray.intersectPlane($,j)&&d.previewPoint(j.sub(K).applyMatrix4(U)))}function H(s,e,o){const n=[0,.2,0,.05,0];let t,i;e=o+1;let r=e;for(const a of n){const u=a*e+(1-a)*o,m=Math.sqrt(Math.abs(u-r)*75e3*v),q=new c.Tween(s.position).to({y:u},m).easing(u<r?c.Easing.Quadratic.In:c.Easing.Quadratic.Out);i?(i.chain(q),i=q):t=i=q,r=u}t.start()}function ee(){if(new c.Tween(L).to({opacity:0},250*v).easing(c.Easing.Cubic.In).start(),d){if(l.length>1){if(new Set(l).size!==l.length){const n=l[0].material.color;l=[];for(const t of P)t.material.color.equals(n)&&l.push(t)}const e={};for(const n of l){const t=new c.Tween(n.scale).to({x:1.3,y:1.3,z:1.3},50*v).easing(c.Easing.Cubic.In),i=new c.Tween(n.scale).to({x:0,y:0,z:0},150*v).easing(c.Easing.Cubic.Out);t.chain(i),t.start().onComplete(()=>{F.remove(n)});let r=Math.round(n.position.x),a=Math.round(n.position.z);e[`${r},${a}`]?n.position.y<e[`${r},${a}`].position.y&&(e[`${r},${a}`]=n):e[`${r},${a}`]=n}P=P.filter(n=>!l.includes(n));const o={};for(const n of Object.values(e)){let t=Math.round(n.position.x),i=Math.round(n.position.z),r=Math.round(n.position.y);o[`${t},${i}`]=1;for(let a=r+1;a<y;a++){if(l.includes(h[t][a][i])){o[`${t},${i}`]++;continue}console.log(`dropping ${t},${a},${i} to ${r}`),H(h[t][a][i],a,r),h[t][r][i]=h[t][a][i],r++}}for(const n of Object.keys(o)){let t,i;[t,i]=n.split(","),t=parseInt(t),i=parseInt(i);for(let r=1;r<=o[n];r++){const a=Math.floor(W.length*Math.random()),u=y-r,m=new x(G,I[a].clone());m.position.x=t,m.position.y=u+o[n],m.position.z=i,m.material.transparent=!0,m.material.opacity=0,f.add(m),P.push(m),h[t][u][i]=m,H(m,u+o[n],u),new c.Tween(m.material).to({opacity:1},150*v).easing(c.Easing.Cubic.In).start()}}te()}const s=d.getObject();d.clear(),setTimeout(()=>{f.remove(s)},600*v),d.previewPoint(null),d=null,l=[]}S.enabled=!0}function te(){let s=!1;for(;!s;){for(let e=0;e<E-1&&!s;e++)for(let o=0;o<y-1&&!s;o++)for(let n=0;n<M-1&&!s;n++)(h[e][o][n].material.color.equals(h[e+1][o][n].material.color)||h[e][o][n].material.color.equals(h[e][o+1][n].material.color)||h[e][o][n].material.color.equals(h[e][o][n+1].material.color))&&(s=!0);if(!s){console.log("Stalemate detected; resetting");for(let e of P){const o=Math.floor(W.length*Math.random());e.material=I[o].clone()}}}}function oe(){requestAnimationFrame(oe),S.update(),c.update(),g.render(F,O),Z.update()}oe();