-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPine3D-minified.lua
1 lines (1 loc) · 27.5 KB
/
Pine3D-minified.lua
1
local a=(...):match("(.-)[^%.]+$")local b=require(a.."betterblittle")local c={}for d=1,16 do c[2^(d-1)]=("0123456789abcdef"):sub(d,d)end;local e=math.pow(10,99)local function f(g,h,i,j)local k=i-g;if k==0 then return e,-e*g end;local l=(j-h)/k;return l,h-l*g end;local m=math.min;local n=math.max;local o=math.floor;local p=math.ceil;local function q(g,h,i,j)local r={x1=g,y1=h,x2=i,y2=j,width=i-g+1,height=j-h+1,screenBuffer={{}},blittleWindow=nil,blittleOn=false,backgroundColor=colors.lightBlue}function r:setBufferSize(g,h,i,j)self.x1=g;self.y1=h;self.x2=i;self.y2=j;self.width=i-g+1;self.height=j-h+1;if self.blittleWindow then self.blittleWindow=self.blittleWindow.reposition(self.x1,self.y1,self.x1+self.width-1,self.y1+self.height-1)end;self:clear()end;function r:clear()local s=self.screenBuffer;s.c2={}local t=s.c2;local u=self.width;local v=self.backgroundColor;if self.blittleOn then for w=1,self.height do t[w]={}local x=t[w]for y=1,u do x[y]=v end end else local z=c[v]s.c1={}local A=s.c1;s.chars={}local B=s.chars;for w=1,self.height do A[w]={}t[w]={}B[w]={}local C=A[w]local x=t[w]local D=B[w]for y=1,u do C[y]=z;x[y]=z;D[y]=" "end end end end;function r:fastClearNormal()local E=self.backgroundColor;local s=self.screenBuffer;local B=s.chars;local A=s.c1;local t=s.c2;local E=c[E]local u=self.width;for w=1,self.height do local D=B[w]local C=A[w]local x=t[w]for y=1,u do D[y]=" "C[y]=E;x[y]=E end end end;function r:fastClearBLittle()local E=self.backgroundColor;local t=self.screenBuffer.c2;local u=self.width;for w=1,self.height do local x=t[w]for y=1,u do x[y]=E end end end;function r:setPixel(y,w,A,t,F)local y=math.floor(y+0.5)local w=math.floor(w+0.5)if y>=1 and y<=self.width then if w>=1 and w<=self.height then local s=self.screenBuffer;if self.blittleOn then s.c2[w][y]=t or A else s.c1[w][y]=c[A]s.c2[w][y]=c[t or A]s.chars[w][y]=" "end end end end;function r:image(k,G,H)for w,I in pairs(H)do for y,J in pairs(I)do if J and J>0 then if self.blittleOn then self:setPixel(y+(k-1)*2,w+(G-1)*3,J,J," ")else self:setPixel(y+k-1,w+G-1,J,J," ")end end end end end;function r:loadLineNormal(g,h,i,j,E,F,K,l,L)local s=self.screenBuffer;local A=s.c1;local t=s.c2;local B=s.chars;local M=self.width;local N=self.height;if i>=g then for y=n(p(g),1),m(o(i),M)do local w=o(l*y+L+0.5)if w>0 and w<=N then A[w][y]=K;t[w][y]=E;B[w][y]=F end end else for y=n(p(i),1),m(o(g),M)do local w=o(l*y+L+0.5)if w>0 and w<=N then A[w][y]=K;t[w][y]=E;B[w][y]=F end end end;if j>=h then for w=n(p(h),1),m(o(j),N)do local y=o((w-L)/l+0.5)if y>0 and y<=M then A[w][y]=K;t[w][y]=E;B[w][y]=F end end else for w=n(p(j),1),m(o(h),N)do local y=o((w-L)/l+0.5)if y>0 and y<=M then A[w][y]=K;t[w][y]=E;B[w][y]=F end end end end;function r:loadLineBLittle(g,h,i,j,E,l,L)local s=self.screenBuffer;local t=s.c2;local M=self.width;local N=self.height;if i>=g then for y=n(p(g),1),m(o(i),M)do local w=o(l*y+L+0.5)if w>0 and w<=N then t[w][y]=E end end else for y=n(p(i),1),m(o(g),M)do local w=o(l*y+L+0.5)if w>0 and w<=N then t[w][y]=E end end end;if j>=h then for w=n(p(h),1),m(o(j),N)do local y=o((w-L)/l+0.5)if y>0 and y<=M then t[w][y]=E end end else for w=n(p(j),1),m(o(h),N)do local y=o((w-L)/l+0.5)if y>0 and y<=M then t[w][y]=E end end end end;function r:horLineNormal(O,P,Q,R,S,T,E,F,K)local s=self.screenBuffer;local A=s.c1;local t=s.c2;local B=s.chars;local M=self.width;local N=self.height;for w=n(m(p(S),N+1),1),m(o(T),N)do local g=(w-P)/O;local i=(w-R)/Q;local C=A[w]local x=t[w]local D=B[w]if g<i then for y=n(m(o(g+0.5),M+1),1),m(i,M)do C[y]=K;x[y]=E;D[y]=F end else for y=n(m(o(i+0.5),M+1),1),m(g,M)do C[y]=K;x[y]=E;D[y]=F end end end end;function r:horLineBLittle(O,P,Q,R,S,T,E)local s=self.screenBuffer;local t=s.c2;local M=self.width;local N=self.height;for w=n(m(p(S),N+1),1),m(o(T),N)do local g=(w-P)/O;local i=(w-R)/Q;local x=t[w]if g<i then for y=n(m(o(g+0.5),M+1),1),m(i,M)do x[y]=E end else for y=n(m(o(i+0.5),M+1),1),m(g,M)do x[y]=E end end end end;local U=colors.black;function r:drawTriangleNormal(g,h,i,j,V,W,E,F,K,X)if g<0 and i<0 and V<0 or h<0 and j<0 and W<0 then return end;local M=self.width;if g>M and i>M and V>M then return end;local N=self.height;if h>N and j>N and W>N then return end;F=F or" "K=K or E;local E=c[E]local K=c[K]local O,P=f(g,h,i,j)local Q,R=f(i,j,V,W)local Y,Z=f(g,h,V,W)local _=self.horLineNormal;if h<=j and h<=W then if j<=W then if O~=0 then _(self,O,P,Y,Z,h,j,E,F,K)end;if Q~=0 then _(self,Q,R,Y,Z,j,W,E,F,K)end else if Y~=0 then _(self,O,P,Y,Z,h,W,E,F,K)end;if Q~=0 then _(self,O,P,Q,R,W,j,E,F,K)end end elseif j<=h and j<=W then if h<=W then if O~=0 then _(self,O,P,Q,R,j,h,E,F,K)end;if Y~=0 then _(self,Q,R,Y,Z,h,W,E,F,K)end else if Q~=0 then _(self,O,P,Q,R,j,W,E,F,K)end;if Y~=0 then _(self,O,P,Y,Z,W,h,E,F,K)end end else if h<=j then if Y~=0 then _(self,Q,R,Y,Z,W,h,E,F,K)end;if O~=0 then _(self,O,P,Q,R,h,j,E,F,K)end else if Q~=0 then _(self,Q,R,Y,Z,W,j,E,F,K)end;if O~=0 then _(self,O,P,Y,Z,j,h,E,F,K)end end end;local X=X;if X or self.triangleEdges then local a0=self.loadLineNormal;local E=c[X or U]a0(self,g,h,i,j,E,F,K,O,P)a0(self,i,j,V,W,E,F,K,Q,R)a0(self,V,W,g,h,E,F,K,Y,Z)end end;function r:drawTriangleBLittle(g,h,i,j,V,W,E,F,K,X)if g<0 and i<0 and V<0 or h<0 and j<0 and W<0 then return end;local M=self.width;if g>M and i>M and V>M then return end;local N=self.height;if h>N and j>N and W>N then return end;local O,P=f(g,h,i,j)local Q,R=f(i,j,V,W)local Y,Z=f(g,h,V,W)local _=self.horLineBLittle;if h<=j and h<=W then if j<=W then if O~=0 then _(self,O,P,Y,Z,h,j,E)end;if Q~=0 then _(self,Q,R,Y,Z,j,W,E)end else if Y~=0 then _(self,O,P,Y,Z,h,W,E)end;if Q~=0 then _(self,O,P,Q,R,W,j,E)end end elseif j<=h and j<=W then if h<=W then if O~=0 then _(self,O,P,Q,R,j,h,E)end;if Y~=0 then _(self,Q,R,Y,Z,h,W,E)end else if Q~=0 then _(self,O,P,Q,R,j,W,E)end;if Y~=0 then _(self,O,P,Y,Z,W,h,E)end end else if h<=j then if Y~=0 then _(self,Q,R,Y,Z,W,h,E)end;if O~=0 then _(self,O,P,Q,R,h,j,E)end else if Q~=0 then _(self,Q,R,Y,Z,W,j,E)end;if O~=0 then _(self,O,P,Y,Z,j,h,E)end end end;local X=X;if X or self.triangleEdges then local a0=self.loadLineBLittle;local E=X or U;a0(self,g,h,i,j,E,O,P)a0(self,i,j,V,W,E,Q,R)a0(self,V,W,g,h,E,Y,Z)end end;function r:drawBufferNormal()local g=self.x1;local h=self.y1;local s=self.screenBuffer;local a1=term.setCursorPos;local a2=term.blit;local B=s.chars;local A=s.c1;local t=s.c2;local a3=table.concat;for w=1,self.height do a1(g,w+h-1)local B=a3(B[w])local A=a3(A[w])local t=a3(t[w])a2(B,A,t)end end;function r:drawBufferBLittle()local a4=self.blittleWindow;if not a4 then self.blittleWindow=window.create(term.current(),self.x1,self.y1,self.x1+self.width-1,self.y1+self.height-1,false)a4=self.blittleWindow end;b.drawBuffer(self.screenBuffer.c2,a4)a4.setVisible(true)a4.setVisible(false)end;function r:highResMode(a5)self.blittleOn=a5;self.drawTriangle=a5 and self.drawTriangleBLittle or self.drawTriangleNormal;self.fastClear=a5 and self.fastClearBLittle or self.fastClearNormal;self.drawBuffer=a5 and self.drawBufferBLittle or self.drawBufferNormal;self:clear()end;function r:useTriangleEdges(a5)self.triangleEdges=a5 end;r:highResMode(true)return r end;local a6=math.sqrt;local a7=table.sort;local function a8(a9)local aa=a9[1][16]for d=2,#a9 do local ab=a9[d][16]if ab>aa then return false end;aa=ab end;return true end;local function ac(a9,ad,ae,af,ag)local ah=ag[1]local ai=ag[2]local aj=ag[3]local ak=ad and ad-ah or 0;local al=ae and ae-ai or 0;local am=af and af-aj or 0;for d=1,#a9 do local an=a9[d]local ao=ak+(an[1]+an[4]+an[7])/3;local ap=al+(an[2]+an[5]+an[8])/3;local aq=am+(an[3]+an[6]+an[9])/3;an[16]=ao*ao+ap*ap+aq*aq end;if not a8(a9)then a7(a9,function(l,L)return l[16]>L[16]end)end end;local ar=math.rad;local as=math.sin;local at=math.cos;local au=math.atan2;local function av(y,w,aw,ax,ay)local az=ay*aw-ax*w;local w=ax*aw+ay*w;local aw=az;return y,w,aw end;local function aA(y,w,aw,ax,ay)local az=ay*aw-ax*y;local y=ax*aw+ay*y;local aw=az;return y,w,aw end;local function aB(y,w,aw,ax,ay)local j=ay*w-ax*y;local y=ax*w+ay*y;local w=j;return y,w end;local function aC(aD,aE,aF,aG)local aH,aI=0,1;local aJ,aK=0,1;local aL,aM=0,1;if aE==0 then aE=nil end;if aE then aH,aI=as(aE),at(aE)end;if aF==0 then aF=nil end;if aF then aJ,aK=as(aF),at(aF)end;if aG==0 then aG=nil end;if aG then aL,aM=as(aG),at(aG)end;local aN={}for aO,an in pairs(aD)do local g,h,aP=an[1],an[2],an[3]local i,j,az=an[4],an[5],an[6]local V,W,aQ=an[7],an[8],an[9]if aF then g,h,aP=aA(g,h,aP,aJ,aK)i,j,az=aA(i,j,az,aJ,aK)V,W,aQ=aA(V,W,aQ,aJ,aK)end;if aG then g,h=aB(g,h,aP,aL,aM)i,j=aB(i,j,az,aL,aM)V,W=aB(V,W,aQ,aL,aM)end;if aE then g,h,aP=av(g,h,aP,aH,aI)i,j,az=av(i,j,az,aH,aI)V,W,aQ=av(V,W,aQ,aH,aI)end;aN[#aN+1]={g,h,aP,i,j,az,V,W,aQ}aN[#aN][10]=an[10]aN[#aN][11]=an[11]aN[#aN][12]=an[12]aN[#aN][13]=an[13]aN[#aN][14]=an[14]aN[#aN][15]=an[15]end;return aN end;local function aR(aS,ag)local aT=ag[1]local aU=ag[2]local aV=ag[3]for d=1,#aS do local aW=aS[d]local aX=aW[1]local aY=aW[2]local aZ=aW[3]local a_=aX and aX-aT or 0;local b0=aY and aY-aU or 0;local b1=aZ and aZ-aV or 0;aW[9]=a_*a_+b0*b0+b1*b1 end;a7(aS,function(l,L)return l[9]>L[9]end)end;local function b2(b3)local b4=fs.open(b3,"r")if not b4 then error("Could not find model for an object at path: "..b3)end;local b5=b4.readAll()b4.close()return textutils.unserialise(b5)end;local b6=math.pi;local as=math.sin;local at=math.cos;local b7=math.tan;local a6=math.sqrt;local function b8(g,h,i,j)local u,b9=term.getSize()if g and i then u=i-g+1 end;if h and j then b9=j-h+1 end;local g=g or 1;local h=h or 1;local i=i or u-g+1;local j=j or b9-h+1;local ba={camera={0.000001,0.000001,0.000001,nil,0,0},buffer=q(g,h,i,j),x1=g,y1=h,x2=i,y2=j,width=u,height=b9,blittleOn=false,pixelratio=1.5}ba.FoV=90;ba.camera[7]=ar(ba.FoV)ba.t=b7(ar(ba.FoV/2))*2*0.0001;function ba:setBackgroundColor(E)local bb=self.buffer;bb.backgroundColor=E;bb:fastClear()end;function ba:setSize(g,h,i,j)self.x1=g;self.y1=h;self.x2=i;self.y2=j;if not self.blittleOn then self.buffer:setBufferSize(g,h,i,j)self.width=i-g+1;self.height=j-h+1;self.pixelratio=1.5 else self.width=(i-g+1)*2;self.height=(j-h+1)*3;self.pixelratio=1;self.buffer:setBufferSize(g,h,g+self.width-1,h+self.height-1)end;self:updateMappingConstants()end;function ba:highResMode(a5)self.blittleOn=a5;self.buffer:highResMode(a5)if a5 then self.width=(self.x2-self.x1+1)*2;self.height=(self.y2-self.y1+1)*3;self.buffer:setBufferSize(self.x1,self.y1,self.x1+self.width-1,self.y1+self.height-1)self.pixelratio=1 else self.buffer:setBufferSize(self.x1,self.y1,self.x2,self.y2)self.width=self.x2-self.x1+1;self.height=self.y2-self.y1+1;self.pixelratio=1.5 end;self:updateMappingConstants()end;function ba:loadModelRaw(aD)local bc={}local bd=0;for d=1,#aD do local an=aD[d]bc[#bc+1]={}bc[#bc][1]=an.x1;bc[#bc][2]=an.y1;bc[#bc][3]=an.z1;bc[#bc][4]=an.x2;bc[#bc][5]=an.y2;bc[#bc][6]=an.z2;bc[#bc][7]=an.x3;bc[#bc][8]=an.y3;bc[#bc][9]=an.z3;bc[#bc][10]=an.forceRender;bc[#bc][11]=an.c;bc[#bc][12]=an.char;bc[#bc][13]=an.charc;bc[#bc][14]=an.outlineColor;bc[#bc][15]=d;local be=a6(an.x1*an.x1+an.y1*an.y1+an.z1*an.z1)local bf=a6(an.x2*an.x2+an.y2*an.y2+an.z2*an.z2)local bg=a6(an.x3*an.x3+an.y3*an.y3+an.z3*an.z3)if be>bd then bd=be end;if bf>bd then bd=bf end;if bg>bd then bd=bg end end;return bc,bd end;function ba:updateMappingConstants()self.renderOffsetX=o(self.width*0.5)+1;self.renderOffsetY=o(self.height*0.5)self.sXFactor=0.0001*self.width/self.t;self.sYFactor=-0.0001*self.width/(self.t*self.height*self.pixelratio)*self.height end;function ba:map3dTo2d(y,w,aw)local ag=self.camera;local bh=as(ag[4]or 0)local bi=at(ag[4]or 0)local bj=as(-ag[5])local bk=at(-ag[5])local bl=as(ag[6])local bm=at(ag[6])local a_=y-ag[1]local b0=w-ag[2]local b1=aw-ag[3]local bn=bk*a_-bj*b1;b1=bj*a_+bk*b1;a_=bn;local bo=bm*b0-bl*a_;a_=bl*b0+bm*a_;b0=bo;if bh~=0 then local bp=bh*b1-bi*b0;b0=bi*b1+bh*b0;b1=bp end;local bq=b1/a_*self.sXFactor+self.renderOffsetX;local br=b0/a_*self.sYFactor+self.renderOffsetY;return bq,br,a_>=0.0001 end;function ba:drawObject(aW,ag,bs)local aX=aW[1]local aY=aW[2]local aZ=aW[3]local bh=bs[1]local bi=bs[2]local bj=bs[3]local bk=bs[4]local bl=bs[5]local bm=bs[6]local bt=aX and aX-ag[1]or 0;local bu=aY and aY-ag[2]or 0;local bv=aZ and aZ-ag[3]or 0;local aD=aW[7]if#aD<=0 then return end;local bw=aW[8]local a_=bt;local b0=bu;local b1=bv;local bn=bk*a_-bj*b1;local b1=bj*a_+bk*b1;local a_=bn;local a_=bl*b0+bm*a_;if a_<-bw then return end;local bx=0.5*ag[7]local by=as(bx)local bz=at(bx)if(a_+bw)*by+(b1+bw)*bz<0 then return end;if(a_+bw)*by-(b1-bw)*bz<0 then return end;local aE=aW[4]local aF=aW[5]local aG=aW[6]if aE and aE~=0 or aF and aF~=0 or aG and aG~=0 then aD=aC(aD,aE,aF,aG)end;ac(aD,aX,aY,aZ,ag)local bA=bt*bt+bu*bu+bv*bv<bw*bw*4;local bB=self.renderOffsetX;local bC=self.renderOffsetY;local bD=self.sXFactor;local bE=self.sYFactor;local bh=bh;local bi=bi;local bj=bj;local bk=bk;local bl=bl;local bm=bm;local bt=bt;local bu=bu;local bv=bv;local function bF(a_,b0,b1)local bn=bk*a_-bj*b1;b1=bj*a_+bk*b1;a_=bn;local bo=bm*b0-bl*a_;a_=bl*b0+bm*a_;b0=bo;local bq=b1/a_*bD+bB;local br=b0/a_*bE+bC;return bq,br,a_ end;if bh~=0 then function bF(a_,b0,b1)local bn=bk*a_-bj*b1;b1=bj*a_+bk*b1;a_=bn;local bo=bm*b0-bl*a_;a_=bl*b0+bm*a_;b0=bo;local bp=bh*b1-bi*b0;b0=bi*b1+bh*b0;b1=bp;local bq=b1/a_*bD+bB;local br=b0/a_*bE+bC;return bq,br,a_ end end;local bG=aD;local bb=self.buffer;for d=1,#bG do local an=bG[d]local g,h,bH=bF(an[1]+bt,an[2]+bu,an[3]+bv)if bH>0.00010000001 then local i,j,bn=bF(an[4]+bt,an[5]+bu,an[6]+bv)if bn>0.00010000001 then local V,W,bI=bF(an[7]+bt,an[8]+bu,an[9]+bv)if bI>0.00010000001 then if an[10]or(i-g)*(W-j)-(j-h)*(V-i)<0 then bb:drawTriangle(g,h,i,j,V,W,an[11],an[12],an[13],an[14])end elseif bA then local function bJ(y,w,aw)local a_=y+bt;local b0=w+bu;local b1=aw+bv;local bn=bk*a_-bj*b1;b1=bj*a_+bk*b1;a_=bn;local bo=bm*b0-bl*a_;a_=bl*b0+bm*a_;b0=bo;if bh~=0 then local bp=bh*b1-bi*b0;b0=bi*b1+bh*b0;b1=bp end;local bq=b1/a_*bD+bB;local br=b0/a_*bE+bC;return bq,br,a_,b0,b1 end;local g,h,bH,bK,bL=bJ(an[1],an[2],an[3])local i,j,bn,bo,bp=bJ(an[4],an[5],an[6])local V,W,bI,bM,bN=bJ(an[7],an[8],an[9])local bO=math.abs;local bP=bO(bI-0.0001)local bQ=bO(bH-0.0001)local bR=bQ+bP;local bS=(bN*bQ+bL*bP)/bR;local bT=(bM*bQ+bK*bP)/bR;local bB,bD,bC,bE=bB,bD,bC,bE;local bU=bS*10000*bD+bB;local bV=bT*10000*bE+bC;if an[10]or(i-g)*(bV-j)-(j-h)*(bU-i)<0 then bb:drawTriangle(g,h,i,j,bU,bV,an[11],an[12],an[13],an[14])local bW=bO(bn-0.0001)local bR=bW+bP;local bS=(bp*bP+bN*bW)/bR;local bT=(bo*bP+bM*bW)/bR;local bX=bS*10000*bD+bB;local bY=bT*10000*bE+bC;bb:drawTriangle(bX,bY,i,j,bU,bV,an[11],an[12],an[13],an[14])end end elseif bA then local function bJ(y,w,aw)local a_=y+bt;local b0=w+bu;local b1=aw+bv;local bn=bk*a_-bj*b1;b1=bj*a_+bk*b1;a_=bn;local bo=bm*b0-bl*a_;a_=bl*b0+bm*a_;b0=bo;if bh~=0 then local bp=bh*b1-bi*b0;b0=bi*b1+bh*b0;b1=bp end;local bq=b1/a_*bD+bB;local br=b0/a_*bE+bC;return bq,br,a_,b0,b1 end;local g,h,bH,bK,bL=bJ(an[1],an[2],an[3])local i,j,bn,bo,bp=bJ(an[4],an[5],an[6])local V,W,bI,bM,bN=bJ(an[7],an[8],an[9])local bO=math.abs;if bI>0.00010000001 then local bW=bO(bn-0.0001)local bQ=bO(bH-0.0001)local bR=bQ+bW;local bS=(bp*bQ+bL*bW)/bR;local bT=(bo*bQ+bK*bW)/bR;local bB,bD,bC,bE=bB,bD,bC,bE;local bU=bS*10000*bD+bB;local bV=bT*10000*bE+bC;if an[10]or(bU-g)*(W-bV)-(bV-h)*(V-bU)<0 then bb:drawTriangle(g,h,bU,bV,V,W,an[11],an[12],an[13],an[14])local bP=bO(bI-0.0001)local bR=bW+bP;local bS=(bp*bP+bN*bW)/bR;local bT=(bo*bP+bM*bW)/bR;local bX=bS*10000*bD+bB;local bY=bT*10000*bE+bC;bb:drawTriangle(bX,bY,bU,bV,V,W,an[11],an[12],an[13],an[14])end else local bQ=bO(bH-0.0001)local bW=bO(bn-0.0001)local bP=bO(bI-0.0001)local bZ=bQ+bW;local b_=bQ+bP;local bS=(bL*bW+bp*bQ)/bZ;local bT=(bK*bW+bo*bQ)/bZ;local bB,bD,bC,bE=bB,bD,bC,bE;local bU=bS*10000*bD+bB;local bV=bT*10000*bE+bC;local c0=(bL*bP+bN*bQ)/b_;local c1=(bK*bP+bM*bQ)/b_;local bX=c0*10000*bD+bB;local bY=c1*10000*bE+bC;if an[10]or(bU-g)*(bY-bV)-(bV-h)*(bX-bU)<0 then bb:drawTriangle(g,h,bU,bV,bX,bY,an[11],an[12],an[13],an[14])end end end elseif bA then local function bJ(y,w,aw)local a_=y+bt;local b0=w+bu;local b1=aw+bv;local bn=bk*a_-bj*b1;b1=bj*a_+bk*b1;a_=bn;local bo=bm*b0-bl*a_;a_=bl*b0+bm*a_;b0=bo;if bh~=0 then local bp=bh*b1-bi*b0;b0=bi*b1+bh*b0;b1=bp end;local bq=b1/a_*bD+bB;local br=b0/a_*bE+bC;return bq,br,a_,b0,b1 end;local g,h,bH,bK,bL=bJ(an[1],an[2],an[3])local i,j,bn,bo,bp=bJ(an[4],an[5],an[6])local V,W,bI,bM,bN=bJ(an[7],an[8],an[9])local bO=math.abs;if bn>0.00010000001 then if bI>0.00010000001 then local bQ=bO(bH-0.0001)local bW=bO(bn-0.0001)local bR=bQ+bW;local bS=(bL*bW+bp*bQ)/bR;local bT=(bK*bW+bo*bQ)/bR;local bB,bD,bC,bE=bB,bD,bC,bE;local bU=bS*10000*bD+bB;local bV=bT*10000*bE+bC;if an[10]or(i-bU)*(W-j)-(j-bV)*(V-i)<0 then bb:drawTriangle(bU,bV,i,j,V,W,an[11],an[12],an[13],an[14])local bP=bO(bI-0.0001)local bR=bQ+bP;local bS=(bL*bP+bN*bQ)/bR;local bT=(bK*bP+bM*bQ)/bR;local bX=bS*10000*bD+bB;local bY=bT*10000*bE+bC;bb:drawTriangle(bU,bV,bX,bY,V,W,an[11],an[12],an[13],an[14])end else local bQ=bO(bH-0.0001)local bW=bO(bn-0.0001)local bP=bO(bI-0.0001)local bZ=bW+bQ;local b_=bW+bP;local bS=(bL*bW+bp*bQ)/bZ;local bT=(bK*bW+bo*bQ)/bZ;local bB,bD,bC,bE=bB,bD,bC,bE;local bU=bS*10000*bD+bB;local bV=bT*10000*bE+bC;local c0=(bp*bP+bN*bW)/b_;local c1=(bo*bP+bM*bW)/b_;local bX=c0*10000*bD+bB;local bY=c1*10000*bE+bC;if an[10]or(i-bU)*(bY-j)-(j-bV)*(bX-i)<0 then bb:drawTriangle(bU,bV,i,j,bX,bY,an[11],an[12],an[13],an[14])end end else if bI>0.00010000001 then local bQ=bO(bH-0.0001)local bW=bO(bn-0.0001)local bP=bO(bI-0.0001)local bZ=bP+bQ;local b_=bP+bW;local bS=(bL*bP+bN*bQ)/bZ;local bT=(bK*bP+bM*bQ)/bZ;local bB,bD,bC,bE=bB,bD,bC,bE;local bU=bS*10000*bD+bB;local bV=bT*10000*bE+bC;local c0=(bp*bP+bN*bW)/b_;local c1=(bo*bP+bM*bW)/b_;local bX=c0*10000*bD+bB;local bY=c1*10000*bE+bC;if an[10]or(bX-bU)*(W-bY)-(bY-bV)*(V-bX)<0 then bb:drawTriangle(bU,bV,bX,bY,V,W,an[11],an[12],an[13],an[14])end end end end end end;function ba:drawObjects(aS)local ag=self.camera;local bs={as(ag[4]or 0),at(ag[4]or 0),as(-ag[5]),at(-ag[5]),as(ag[6]),at(ag[6])}aR(aS,ag)local aS=aS;for d=1,#aS do self:drawObject(aS[d],ag,bs)end end;function ba:drawBuffer()local bb=self.buffer;bb:drawBuffer()bb:fastClear()end;function ba:setCamera(c2,c3,c4,aE,aF,aG)local ar=math.rad;if type(c2)=="table"then local ag=c2;self.camera={ag.x or self.camera[1]or 0,ag.y or self.camera[2]or 0,ag.z or self.camera[3]or 0,ag.rotX and ar(ag.rotX+90)or self.camera[4]or 0,ag.rotY and ar(ag.rotY)or self.camera[5]or 0,ag.rotZ and ar(ag.rotZ)or self.camera[6]or 0,self.camera[7]}else self.camera={c2 or self.camera[1]or 0,c3 or self.camera[2]or 0,c4 or self.camera[3]or 0,aE and ar(aE+90)or self.camera[4]or 0,aF and ar(aF)or self.camera[5]or 0,aG and ar(aG)or self.camera[6]or 0,self.camera[7]}end;if self.camera[4]==math.pi*0.5 then self.camera[4]=nil end end;function ba:setFoV(bx)self.FoV=bx or 90;self.t=b7(ar(self.FoV/2))*2*0.0001;self:updateMappingConstants()self.camera[7]=ar(self.FoV)end;function ba:setWireFrame(a5)self.buffer:useTriangleEdges(a5)end;function ba:getObjectIndexTrace(aS,y,w)local function c5(c6,c7,c8)return(c6.x-c8.x)*(c7.y-c8.y)-(c7.x-c8.x)*(c6.y-c8.y)end;local function c9(ca,cb,g,h,i,j,V,W,cc,cd,ce,cf)local P=c5({x=ca,y=cb},{x=g,y=h},{x=i,y=j})<0;local R=c5({x=ca,y=cb},{x=i,y=j},{x=V,y=W})<0;local Z=c5({x=ca,y=cb},{x=V,y=W},{x=g,y=h})<0;return P==R and R==Z end;local w=w-1;local cg={}if self.blittleOn then y=y*2;w=w*3+1 end;local ag=self.camera;local bs={as(ag[4]or 0),at(ag[4]or 0),as(-ag[5]),at(-ag[5]),as(ag[6]),at(ag[6])}local bh=bs[1]local bi=bs[2]local bj=bs[3]local bk=bs[4]local bl=bs[5]local bm=bs[6]for d=1,#aS do local aW=aS[d]local aD=aW[7]local aE=aW[4]local aF=aW[5]local aG=aW[6]if aE and aE~=0 or aF and aF~=0 or aG and aG~=0 then aD=aC(aD,aE,aF,aG)end;local aX=aW[1]local aY=aW[2]local aZ=aW[3]local bB=self.renderOffsetX;local bC=self.renderOffsetY;local bD=self.sXFactor;local bE=self.sYFactor;local bh=bh;local bi=bi;local bj=bj;local bk=bk;local bl=bl;local bm=bm;local bt=aX-ag[1]local bu=aY-ag[2]local bv=aZ-ag[3]local function bF(y,w,aw)local a_=y+bt;local b0=w+bu;local b1=aw+bv;local bn=bk*a_-bj*b1;b1=bj*a_+bk*b1;a_=bn;local bo=bm*b0-bl*a_;a_=bl*b0+bm*a_;b0=bo;if bh~=0 then local bp=bh*b1-bi*b0;b0=bi*b1+bh*b0;b1=bp end;local bq=b1/a_*bD+bB;local br=b0/a_*bE+bC;return bq,br,a_>0 end;for ch=1,#aD do local an=aD[ch]local g,h,ci=bF(an[1],an[2],an[3])if ci then local i,j,cj=bF(an[4],an[5],an[6])if cj then local V,W,ck=bF(an[7],an[8],an[9])if ck then if an[10]or(i-g)*(W-j)-(j-h)*(V-i)<0 then if not self.blittleOn then if c9(y,w,g,h,i,j,V,W,self.x1,self.y1,self.x2,self.y2)then cg[#cg+1]={objectIndex=d,polygonIndex=an[15]}end else if c9(y,w,g,h,i,j,V,W,(self.x2-1)*2+1,(self.y1-1)*3+1,self.x2*2,(self.y2+1)*3)then cg[#cg+1]={objectIndex=d,polygonIndex=an[15]}end end end end end end end end;if#cg<=0 then return elseif#cg==1 then return cg[1].objectIndex,cg[1].polygonIndex end;local cl={}local cm=-1;local cn=math.huge;for d=1,#cg do local aW=aS[cg[d].objectIndex]local a_=ag[1]-aW[1]local b0=ag[2]-aW[2]local b1=ag[3]-aW[3]local co=a6(a_*a_+b0*b0+b1*b1)if co<cn then cn=co;cm=cg[d].objectIndex end end;for d=1,#cg do local aW=aS[cg[d].objectIndex]local a_=ag[1]-aW[1]local b0=ag[2]-aW[2]local b1=ag[3]-aW[3]local co=a6(a_*a_+b0*b0+b1*b1)if co==cn then cl[#cl+1]=cg[d].polygonIndex end end;local aW=aS[cm]local aD=aW[7]local cp=-1;local cq=math.huge;local ak=aW[1]-ag[1]local al=aW[2]-ag[2]local am=aW[3]-ag[3]for d=1,#cl do local cr=cl[d]local an=aD[cr]local ao=ak+(an[1]+an[4]+an[7])/3;local ap=al+(an[2]+an[5]+an[8])/3;local aq=am+(an[3]+an[6]+an[9])/3;local co=a6(ao*ao+ap*ap+aq*aq)if co<cq then cq=co;cp=cl[d]end end;return cm,cp end;function ba:newObject(cs,y,w,aw,aE,aF,aG)local aD=nil;local bw=nil;if type(cs)=="table"then aD,bw=self:loadModelRaw(cs)else local ct=b2(cs)aD,bw=self:loadModelRaw(ct)end;local aW={y,w,aw,aE,aF,aG,aD,bw}aW.frame=self;function aW:setPos(y,w,aw)self[1]=y or self[1]self[2]=w or self[2]self[3]=aw or self[3]end;function aW:setRot(aE,aF,aG)self[4]=aE or self[4]self[5]=aF or self[5]self[6]=aG or self[6]end;function aW:setModel(cs)if type(cs)=="table"then aD,bw=self.frame:loadModelRaw(cs)self[7]=aD;self[8]=bw else local ct=b2(cs)aD,bw=self.frame:loadModelRaw(ct)self[7]=aD;self[8]=bw end end;return aW end;ba:updateMappingConstants()ba:highResMode(true)return ba end;local cu={}local function cv(g,h,aP,i,j,az,V,W,aQ,E)return{x1=g,y1=h,z1=aP,x2=i,y2=j,z2=az,x3=V,y3=W,z3=aQ,c=E}end;function cu:cube(cw)cw.color=cw.color or colors.red;return{cv(-.5,-.5,-.5,.5,-.5,.5,-.5,-.5,.5,cw.bottom or cw.color),cv(-.5,-.5,-.5,.5,-.5,-.5,.5,-.5,.5,cw.bottom2 or cw.bottom or cw.color),cv(-.5,.5,-.5,-.5,.5,.5,.5,.5,.5,cw.top or cw.color),cv(-.5,.5,-.5,.5,.5,.5,.5,.5,-.5,cw.top or cw.color),cv(-.5,-.5,-.5,-.5,-.5,.5,-.5,.5,-.5,cw.side or cw.color),cv(-.5,-.5,.5,-.5,.5,.5,-.5,.5,-.5,cw.side2 or cw.side or cw.color),cv(.5,-.5,-.5,.5,.5,.5,.5,-.5,.5,cw.side or cw.color),cv(.5,-.5,-.5,.5,.5,-.5,.5,.5,.5,cw.side2 or cw.side or cw.color),cv(-.5,-.5,-.5,.5,.5,-.5,.5,-.5,-.5,cw.side or cw.color),cv(-.5,-.5,-.5,-.5,.5,-.5,.5,.5,-.5,cw.side2 or cw.side or cw.color),cv(-.5,-.5,.5,.5,-.5,.5,-.5,.5,.5,cw.side or cw.color),cv(.5,-.5,.5,.5,.5,.5,-.5,.5,.5,cw.side2 or cw.side or cw.color)}end;function cu:sphere(cw)cw.res=cw.res or 32;cw.color=cw.color or colors.red;local cx=1/cw.res;local aD={}local cy={}for d=0,cw.res do local w=0.5*at(d/cw.res*b6)local cz={}for ch=0,cw.res do local cA=0.5*a6(1-w*2*w*2)local y=at(ch/cw.res*b6*2)*cA;local aw=as(ch/cw.res*b6*2)*cA;local i=at((ch+1)/cw.res*b6*2)*cA;local az=as((ch+1)/cw.res*b6*2)*cA;if cy[ch]then aD[#aD+1]={x1=cy[(ch+1)%cw.res].x,y1=cy[(ch+1)%cw.res].y,z1=cy[(ch+1)%cw.res].z,x2=y,y2=w,z2=aw,x3=cy[ch].x,y3=cy[ch].y,z3=cy[ch].z,c=cw.color}aD[#aD+1]={x1=i,y1=w,z1=az,x2=y,y2=w,z2=aw,x3=cy[(ch+1)%cw.res].x,y3=cy[(ch+1)%cw.res].y,z3=cy[(ch+1)%cw.res].z,c=cw.color2 or cw.color}end;cz[ch]={x=y,y=w,z=aw}end;cy=cz end;if cw.colors or cw.top or cw.bottom then for d=1,#aD do local cB=aD[d]local ap=(cB.y1+cB.y2+cB.y3)/3;if cw.colors then local cC=o((-ap+0.5)*#cw.colors+1)cB.c=cw.colors[cC]or cB.c else if ap>=0 then cB.c=cw.top or cB.c else cB.c=cw.bottom or cB.c end end end end;return aD end;function cu:icosphere(cw)cw.res=cw.res or 1;local cD=(1+a6(5))/2;local cE={{cD,1,0},{cD,-1,0},{-cD,-1,0},{-cD,1,0},{1,0,cD},{-1,0,cD},{-1,0,-cD},{1,0,-cD},{0,cD,1},{0,cD,-1},{0,-cD,-1},{0,-cD,1}}local function cF(cG,cH,cI)return cv(cE[cG][1],cE[cG][2],cE[cG][3],cE[cH][1],cE[cH][2],cE[cH][3],cE[cI][1],cE[cI][2],cE[cI][3],cw.colors and 1 or cw.color)end;local aD={cF(11,2,12),cF(11,8,2),cF(11,7,8),cF(11,3,7),cF(11,12,3),cF(4,7,3),cF(4,10,7),cF(4,9,10),cF(4,6,9),cF(4,3,6),cF(5,6,12),cF(5,9,6),cF(5,1,9),cF(5,2,1),cF(5,12,2),cF(3,12,6),cF(1,8,10),cF(1,10,9),cF(1,2,8),cF(10,8,7)}local function cJ()local cK={}for d=1,#aD do local cB=aD[d]local cL={x=(cB.x1+cB.x2)/2,y=(cB.y1+cB.y2)/2,z=(cB.z1+cB.z2)/2}local cM={x=(cB.x1+cB.x3)/2,y=(cB.y1+cB.y3)/2,z=(cB.z1+cB.z3)/2}local cN={x=(cB.x2+cB.x3)/2,y=(cB.y2+cB.y3)/2,z=(cB.z2+cB.z3)/2}local cO=cB.c;if cw.colorsFractal then cO=cO%#cw.colors+1 end;cK[#cK+1]=cv(cL.x,cL.y,cL.z,cN.x,cN.y,cN.z,cM.x,cM.y,cM.z,cB.c)cK[#cK+1]=cv(cB.x1,cB.y1,cB.z1,cL.x,cL.y,cL.z,cM.x,cM.y,cM.z,cO)cK[#cK+1]=cv(cL.x,cL.y,cL.z,cB.x2,cB.y2,cB.z2,cN.x,cN.y,cN.z,cO)cK[#cK+1]=cv(cM.x,cM.y,cM.z,cN.x,cN.y,cN.z,cB.x3,cB.y3,cB.z3,cO)end;aD=cK end;for d=1,cw.res-1 do cJ()end;local function cP(y,w,aw)local cQ=math.sqrt(y*y+w*w+aw*aw)local cR=0.5/cQ;return y*cR,w*cR,aw*cR end;for d=1,#aD do local cB=aD[d]cB.x1,cB.y1,cB.z1=cP(cB.x1,cB.y1,cB.z1)cB.x2,cB.y2,cB.z2=cP(cB.x2,cB.y2,cB.z2)cB.x3,cB.y3,cB.z3=cP(cB.x3,cB.y3,cB.z3)if not cw.colorsFractal then local ap=(cB.y1+cB.y2+cB.y3)/3;if cw.colors then local cC=math.floor((-ap+0.5)*#cw.colors+1)cB.c=cw.colors[cC]or cB.c else if ap>=0 then cB.c=cw.top or cB.c else cB.c=cw.bottom or cB.c end end else cB.c=cw.colors[cB.c]end end;return aD end;function cu:plane(cw)cw.color=cw.color or colors.lime;cw.size=cw.size or 1;cw.y=cw.y or 0;return{cv(-1*cw.size,cw.y,1*cw.size,1*cw.size,cw.y,-1*cw.size,-1*cw.size,cw.y,-1*cw.size,cw.color),cv(-1*cw.size,cw.y,1*cw.size,1*cw.size,cw.y,1*cw.size,1*cw.size,cw.y,-1*cw.size,cw.color)}end;function cu:mountains(cw)cw.res=cw.res or 20;cw.randomOffset=cw.randomOffset or 0;cw.height=cw.height or 1;cw.randomHeight=cw.randomHeight or 0;cw.y=cw.y or 0;cw.scale=cw.scale or 100;cw.color=cw.color or colors.green;cw.snowColor=cw.snowColor or colors.white;local cS=3/cw.res*cw.height/(cw.randomHeight+1)local cT=3/cw.res*cw.height*(cw.randomHeight+1)local aD={}for d=0,cw.res do local cU=math.random(-cw.randomOffset*100,cw.randomOffset*100)/100;local cV=d+cU;local g=at((cV-1)/cw.res*b6*2)*cw.scale;local aP=as((cV-1)/cw.res*b6*2)*cw.scale;local i=at((cV-0.5)/cw.res*b6*2)*cw.scale;local az=as((cV-0.5)/cw.res*b6*2)*cw.scale;local V=at(cV/cw.res*b6*2)*cw.scale;local aQ=as(cV/cw.res*b6*2)*cw.scale;local cW=math.random(cS*100,cT*100)/100*cw.scale;local an={x1=g,y1=cw.y,z1=aP,x2=V,y2=cw.y,z2=aQ,x3=i,y3=cw.y+cW,z3=az,c=cw.color,forceRender=true}aD[#aD+1]=an;if cw.snow then local cX=0.93;local cY=cw.snowHeight or 0.5;local cZ=1-cY*cT/(cW/cw.scale)cZ=n(0,m(1,cZ))if cZ>0.2 then local c_={x1=(g*cZ+i*(1-cZ))*cX,y1=cw.y+cW*(1-cZ),z1=(aP*cZ+az*(1-cZ))*cX,x2=(V*cZ+i*(1-cZ))*cX,y2=cw.y+cW*(1-cZ),z2=(aQ*cZ+az*(1-cZ))*cX,x3=i*cX,y3=cw.y+cW,z3=az*cX,c=cw.snowColor,forceRender=true}aD[#aD+1]=c_ end end end;return aD end;local d0={}function d0:invertTriangles(aD)if not aD or type(aD)~="table"then error("transforms:invertTriangles expected arg#1 to be a table (model)")end;local cK={}for d=1,#aD do local d1=aD[d]local d2={x1=d1.x1,y1=d1.y1,z1=d1.z1,x2=d1.x3,y2=d1.y3,z2=d1.z3,x3=d1.x2,y3=d1.y2,z3=d1.z2,c=d1.c,char=d1.char,charc=d1.charc,forceRender=d1.forceRender,outlineColor=d1.outlineColor}cK[d]=d2 end;return cK end;function d0:setOutline(aD,cw)if not aD or type(aD)~="table"then error("transforms:invertTriangles expected arg#1 to be a table (model)")end;for d=1,#aD do local d1=aD[d]if type(cw)=="table"then d1.outlineColor=cw[d1.c]or d1.outlineColor else d1.outlineColor=cw end end;return aD end;return{newFrame=b8,loadModel=b2,newBuffer=q,linear=f,models=cu,transforms=d0}