summaryrefslogtreecommitdiff
path: root/Build/source/utils/asymptote/base
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/utils/asymptote/base')
-rw-r--r--Build/source/utils/asymptote/base/asy-kate.sh4
-rw-r--r--Build/source/utils/asymptote/base/geometry.asy93
-rw-r--r--Build/source/utils/asymptote/base/graph.asy54
-rw-r--r--Build/source/utils/asymptote/base/graph3.asy22
-rw-r--r--Build/source/utils/asymptote/base/plain.asy32
-rw-r--r--Build/source/utils/asymptote/base/plain_arrows.asy158
-rw-r--r--Build/source/utils/asymptote/base/plain_pens.asy4
-rw-r--r--Build/source/utils/asymptote/base/rationalSimplex.asy74
-rw-r--r--Build/source/utils/asymptote/base/shaders/blend.glsl145
-rw-r--r--Build/source/utils/asymptote/base/shaders/compress.glsl23
-rw-r--r--Build/source/utils/asymptote/base/shaders/count.glsl15
-rw-r--r--Build/source/utils/asymptote/base/shaders/fragment.glsl67
-rw-r--r--Build/source/utils/asymptote/base/shaders/sum1.glsl50
-rw-r--r--Build/source/utils/asymptote/base/shaders/sum2.glsl45
-rw-r--r--Build/source/utils/asymptote/base/shaders/sum2fast.glsl59
-rw-r--r--Build/source/utils/asymptote/base/shaders/sum3.glsl80
-rw-r--r--Build/source/utils/asymptote/base/shaders/zero.glsl4
-rw-r--r--Build/source/utils/asymptote/base/simplex.asy47
-rw-r--r--Build/source/utils/asymptote/base/slopefield.asy10
-rw-r--r--Build/source/utils/asymptote/base/stats.asy27
-rw-r--r--Build/source/utils/asymptote/base/three.asy5
-rw-r--r--Build/source/utils/asymptote/base/three_surface.asy39
-rw-r--r--Build/source/utils/asymptote/base/v3dheadertypes.asy2
-rw-r--r--Build/source/utils/asymptote/base/v3dtypes.asy2
-rw-r--r--Build/source/utils/asymptote/base/webgl/asygl.js2
25 files changed, 692 insertions, 371 deletions
diff --git a/Build/source/utils/asymptote/base/asy-kate.sh b/Build/source/utils/asymptote/base/asy-kate.sh
index 5f482b376d9..4212b1cb85a 100644
--- a/Build/source/utils/asymptote/base/asy-kate.sh
+++ b/Build/source/utils/asymptote/base/asy-kate.sh
@@ -2,7 +2,7 @@
echo '<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE language SYSTEM "language.dtd">
<!-- based on asy-keywords.el and Highlighting file asymptote.xml by Christoph Hormann-->
-<language version="1.0" kateversion="3.2.2" name="asymptote" section="Sources" extensions="*.asy" mimetype="text/x-asymptote" licence="LGPL" author="Carsten Brenner">
+<language version="1.0" kateversion="3.2.2" name="Asymptote" section="Sources" extensions="*.asy" mimetype="text/x-asymptote" licence="LGPL" author="Carsten Brenner">
<highlighting>
' > asymptote.xml
@@ -122,7 +122,7 @@ echo '
<itemData name="Decimal" defStyleNum="dsDecVal"/>
<itemData name="Extensions" defStyleNum="dsKeyword" color="#0095ff" selColor="#ffffff" bold="1" italic="0"/>
<itemData name="Float" defStyleNum="dsFloat"/>
- <itemData name="Function" defStyleNum="dsFunction" />
+ <itemData name="Function" defStyleNum="dsFunction" />
<itemData name="Hex" defStyleNum="dsBaseN"/>
<itemData name="Keyword" defStyleNum="dsKeyword"/>
<itemData name="Normal Text" defStyleNum="dsNormal"/>
diff --git a/Build/source/utils/asymptote/base/geometry.asy b/Build/source/utils/asymptote/base/geometry.asy
index 9f4be8d15ca..37d085cb1c4 100644
--- a/Build/source/utils/asymptote/base/geometry.asy
+++ b/Build/source/utils/asymptote/base/geometry.asy
@@ -1556,6 +1556,11 @@ segment operator cast(line l)
return segment(l.A, l.B);
}
+path operator ecast(segment s)
+{
+ return s.A -- s.B;
+}
+
/*<asyxml><operator type = "line" signature="*(transform,line)"><code></asyxml>*/
line operator *(transform t, line l)
{/*<asyxml></code><documentation>Provide transform * line</documentation></operator></asyxml>*/
@@ -3738,6 +3743,17 @@ void draw(picture pic = currentpicture, Label L = "", circle c,
else draw(pic, L, (path)c, align, p, arrow, bar, margin, legend, marker);
}
+void fill(picture pic = currentpicture, circle c, pen p = currentpen)
+{
+ if (!degenerate(c)) fill(pic, (path)c, p);
+}
+
+void filldraw(picture pic = currentpicture, circle c, pen fillpen = currentpen, pen drawpen = currentpen)
+{
+ fill(pic, c, fillpen);
+ draw(pic, c, drawpen);
+}
+
/*<asyxml><function type="void" signature="draw(picture,Label,ellipse,align,pen,arrowbar,arrowbar,margin,Label,marker)"><code></asyxml>*/
void draw(picture pic = currentpicture, Label L = "", ellipse el,
align align = NoAlign, pen p = currentpen,
@@ -3748,6 +3764,17 @@ void draw(picture pic = currentpicture, Label L = "", ellipse el,
else draw(pic, L, (path)el, align, p, arrow, bar, margin, legend, marker);
}
+void fill(picture pic = currentpicture, ellipse el, pen p = currentpen)
+{
+ if (!degenerate(el)) fill(pic, (path)el, p);
+}
+
+void filldraw(picture pic = currentpicture, ellipse el, pen fillpen = currentpen, pen drawpen = currentpen)
+{
+ fill(pic, el, fillpen);
+ draw(pic, el, drawpen);
+}
+
/*<asyxml><function type="void" signature="draw(picture,Label,parabola,align,pen,arrowbar,arrowbar,margin,Label,marker)"><code></asyxml>*/
void draw(picture pic = currentpicture, Label L = "", parabola parabola,
align align = NoAlign, pen p = currentpen,
@@ -5383,8 +5410,8 @@ void dot(picture pic = currentpicture, Label L, explicit mass M, align align = N
// *=======================================================*
// *.......................TRIANGLES.......................*
-/*<asyxml><function type="point" signature="orthocentercenter(point,point,point)"><code></asyxml>*/
-point orthocentercenter(point A, point B, point C)
+/*<asyxml><function type="point" signature="orthocenter(point,point,point)"><code></asyxml>*/
+point orthocenter(point A, point B, point C)
{/*<asyxml></code><documentation>Return the orthocenter of the triangle ABC.</documentation></function></asyxml>*/
point[] P = standardizecoordsys(A, B, C);
coordsys R = P[0].coordsys;
@@ -5539,9 +5566,9 @@ struct triangle {/*<asyxml></code><documentation></documentation></asyxml>*/
real gamma() {return degrees(acos((a()^2 + b()^2 - c()^2)/(2a() * b())));}
/*<asyxml><method type = "path" signature="Path()"><code></asyxml>*/
- path Path()
+ path Path() // retained for backward compatibility
{/*<asyxml></code><documentation>The path of the triangle.</documentation></method></asyxml>*/
- return A--C--B--cycle;
+ return A--B--C--cycle;
}
/*<asyxml><struct signature="side"><code></asyxml>*/
@@ -5584,6 +5611,8 @@ struct triangle {/*<asyxml></code><documentation></documentation></asyxml>*/
}/*<asyxml></struct></asyxml>*/
+path operator cast(triangle t) { return t.A -- t.B -- t.C -- cycle; }
+
from triangle unravel side; // The structure 'side' is now available outside the triangle structure.
from triangle unravel vertex; // The structure 'vertex' is now available outside the triangle structure.
@@ -5715,10 +5744,10 @@ line altitude(side side)
return altitude(opposite(side));
}
-/*<asyxml><function type="point" signature="orthocentercenter(triangle)"><code></asyxml>*/
-point orthocentercenter(triangle t)
+/*<asyxml><function type="point" signature="orthocenter(triangle)"><code></asyxml>*/
+point orthocenter(triangle t)
{/*<asyxml></code><documentation>Return the orthocenter of the triangle t.</documentation></function></asyxml>*/
- return orthocentercenter(t.A, t.B, t.C);
+ return orthocenter(t.A, t.B, t.C);
}
/*<asyxml><function type="point" signature="centroid(triangle)"><code></asyxml>*/
@@ -6276,13 +6305,34 @@ void show(picture pic = currentpicture,
/*<asyxml><function type="void" signature="draw(picture,triangle,pen,marker)"><code></asyxml>*/
void draw(picture pic = currentpicture, triangle t, pen p = currentpen, marker marker = nomarker)
{/*<asyxml></code><documentation>Draw sides of the triangle 't' on picture 'pic' using pen 'p'.</documentation></function></asyxml>*/
- draw(pic, t.Path(), p, marker);
+ draw(pic, (path)t, p, marker);
+}
+
+void fill(picture pic = currentpicture, triangle t, pen p = currentpen)
+{
+ fill(pic, (path)t, p);
+}
+
+void filldraw(picture pic = currentpicture, triangle t, pen fillpen = currentpen, pen drawpen = currentpen)
+{
+ fill(pic, t, fillpen);
+ draw(pic, t, drawpen);
}
/*<asyxml><function type="void" signature="draw(picture,triangle[],pen,marker)"><code></asyxml>*/
-void draw(picture pic = currentpicture, triangle[] t, pen p = currentpen, marker marker = nomarker)
+void draw(picture pic = currentpicture, triangle[] ts, pen p = currentpen, marker marker = nomarker)
{/*<asyxml></code><documentation>Draw sides of the triangles 't' on picture 'pic' using pen 'p'.</documentation></function></asyxml>*/
- for(int i = 0; i < t.length; ++i) draw(pic, t[i], p, marker);
+ for(triangle t: ts) draw(pic, t, p, marker);
+}
+
+void fill(picture pic = currentpicture, triangle[] ts, pen p = currentpen)
+{
+ for(triangle t: ts) fill(pic, t, p);
+}
+
+void filldraw(picture pic = currentpicture, triangle[] ts, pen fillpen = currentpen, pen drawpen = currentpen)
+{
+ for(triangle t: ts) filldraw(pic, t, fillpen, drawpen);
}
/*<asyxml><function type="void" signature="drawline(picture,triangle,pen)"><code></asyxml>*/
@@ -6368,13 +6418,13 @@ inversion inversion(circle c1, circle c2, real sgn = 1)
point O = radicalcenter(c1, c2);
return inversion(O^c1, O);
}
- real a = abs(c1.r/c2.r);
- if(sgn > 0) {
- point O = c1.C + a/abs(1 - a) * (c2.C - c1.C);
- return inversion(a * abs(abs(O - c2.C)^2 - c2.r^2), O);
+ else {
+ point C1 = c1.C, C2 = c2.C;
+ real r1 = c1.r, r2 = sgn(sgn) * c2.r;
+ return inversion(
+ r1 * r2 * (1 - (length(C2 - C1) / (r1 + r2))^2),
+ (r2 * C1 + r1 * C2) / (r1 + r2));
}
- point O = c1.C + a/abs(1 + a) * (c2.C - c1.C);
- return inversion(-a * abs(abs(O - c2.C)^2 - c2.r^2), O);
}
/*<asyxml><function type="inversion" signature="inversion(circle,circle,circle)"><code></asyxml>*/
@@ -7192,9 +7242,18 @@ path arc(explicit pair B, explicit pair A, explicit pair C, real r)
return arc(A, abs(r), BA, CA, (r < 0) ^ ((BA-CA) % 360 < 180) ? CW : CCW);
}
+point orthocentercenter(point A, point B, point C)
+{
+ return orthocenter(A, B, C);
+}
+
+point orthocentercenter(triangle t)
+{
+ return orthocenter(t.A, t.B, t.C);
+}
+
// *.......End of compatibility routines........*
// *=======================================================*
// *........................FOOTER.........................*
// *=======================================================*
-
diff --git a/Build/source/utils/asymptote/base/graph.asy b/Build/source/utils/asymptote/base/graph.asy
index 1d4dfc1bfd3..433aa2fc20f 100644
--- a/Build/source/utils/asymptote/base/graph.asy
+++ b/Build/source/utils/asymptote/base/graph.asy
@@ -2186,45 +2186,49 @@ picture vectorfield(path vector(real), path g, int n, bool truesize=false,
return pic;
}
-real maxlength(pair a, pair b, int nx, int ny)
-{
- return min((b.x-a.x)/nx,(b.y-a.y)/ny);
-}
-
// return a vector field over box(a,b).
picture vectorfield(path vector(pair), pair a, pair b,
int nx=nmesh, int ny=nx, bool truesize=false,
- real maxlength=truesize ? 0 : maxlength(a,b,nx,ny),
bool cond(pair z)=null, pen p=currentpen,
arrowbar arrow=Arrow, margin margin=PenMargin)
{
picture pic;
- real dx=1/nx;
- real dy=1/ny;
+ real dx=(b.x-a.x)/(nx-1);
+ real dy=(b.y-a.y)/(ny-1);
bool all=cond == null;
real scale;
- if(maxlength > 0) {
- real size(pair z) {
- path g=vector(z);
- return abs(point(g,size(g)-1)-point(g,0));
- }
- real max=size(a);
- for(int i=0; i <= nx; ++i) {
- real x=interp(a.x,b.x,i*dx);
- for(int j=0; j <= ny; ++j)
- max=max(max,size((x,interp(a.y,b.y,j*dy))));
+ transform t=scale(dx,dy);
+ pair size(pair z) {
+ path g=t*vector(z);
+ int n=size(g);
+ pair w=n == 1 ? point(g,0) : point(g,n-1)-point(g,0);
+ return (abs(w.x),abs(w.y));
+ }
+ pair max=size(a);
+ for(int i=0; i < nx; ++i) {
+ real x=a.x+i*dx;
+ for(int j=0; j < ny; ++j) {
+ real y=a.y+j*dy;
+ max=maxbound(max,size((x,y)));
}
- scale=max > 0 ? maxlength/max : 1;
- } else scale=1;
+ }
+
+ if(max.x == 0)
+ scale=max.y == 0 ? 1.0 : dy/max.y;
+ else if(max.y == 0)
+ scale=dx/max.x;
+ else
+ scale=min(dx/max.x,dy/max.y);
- for(int i=0; i <= nx; ++i) {
- real x=interp(a.x,b.x,i*dx);
- for(int j=0; j <= ny; ++j) {
- real y=interp(a.y,b.y,j*dy);
+ for(int i=0; i < nx; ++i) {
+ real x=a.x+i*dx;
+ for(int j=0; j < ny; ++j) {
+ real y=a.y+j*dy;
pair z=(x,y);
if(all || cond(z)) {
- path g=scale(scale)*vector(z);
+ path v=scale(scale)*t*vector(z);
+ path g=size(v) == 1 ? (0,0)--v : v;
if(truesize)
draw(z,pic,g,p,arrow);
else
diff --git a/Build/source/utils/asymptote/base/graph3.asy b/Build/source/utils/asymptote/base/graph3.asy
index f690c6a3c10..f17b4e97074 100644
--- a/Build/source/utils/asymptote/base/graph3.asy
+++ b/Build/source/utils/asymptote/base/graph3.asy
@@ -2201,21 +2201,24 @@ picture vectorfield(path3 vector(pair v), triple f(pair z), pair a, pair b,
string name="", render render=defaultrender)
{
picture pic;
- real du=1/nu;
- real dv=1/nv;
+ real du=(b.x-a.x)/(nu-1);
+ real dv=(b.y-a.y)/(nv-1);
bool all=cond == null;
real scale;
if(maxlength > 0) {
real size(pair z) {
path3 g=vector(z);
- return abs(point(g,size(g)-1)-point(g,0));
+ triple w=point(g,size(g)-1)-point(g,0);
+ return max(w.x,w.y,w.z);
}
- real max=size((0,0));
+ real max=size(a);
for(int i=0; i <= nu; ++i) {
- real x=interp(a.x,b.x,i*du);
- for(int j=0; j <= nv; ++j)
- max=max(max,size((x,interp(a.y,b.y,j*dv))));
+ real u=a.x+i*du;
+ for(int j=0; j < nv; ++j) {
+ real v=a.y+j*dv;
+ max=max(max,size((u,v)));
+ }
}
scale=max > 0 ? maxlength/max : 1;
} else scale=1;
@@ -2224,9 +2227,10 @@ picture vectorfield(path3 vector(pair v), triple f(pair z), pair a, pair b,
if(group)
begingroup3(pic,name == "" ? "vectorfield" : name,render);
for(int i=0; i <= nu; ++i) {
- real x=interp(a.x,b.x,i*du);
+ real u=a.x+i*du;
for(int j=0; j <= nv; ++j) {
- pair z=(x,interp(a.y,b.y,j*dv));
+ real v=a.y+j*dv;
+ pair z=(u,v);
if(all || cond(z)) {
path3 g=scale3(scale)*vector(z);
string name="vector";
diff --git a/Build/source/utils/asymptote/base/plain.asy b/Build/source/utils/asymptote/base/plain.asy
index cac6aa07222..084fedd7581 100644
--- a/Build/source/utils/asymptote/base/plain.asy
+++ b/Build/source/utils/asymptote/base/plain.asy
@@ -171,7 +171,7 @@ string[] reverse(string[] a) {return a[reverse(a.length)];}
real[] uniform(real a, real b, int n)
{
if(n <= 0) return new real[];
- return a+(b-a)/n*sequence(n+1);
+ return a+sequence(n+1)/n*(b-a);
}
void eval(string s, bool embedded=false)
@@ -264,7 +264,7 @@ struct cputime {
cputime cputime()
{
static processtime last;
- real [] a=_cputime();
+ real[] a=_cputime();
cputime cputime;
real clock=a[4];
cputime.parent.user=a[0];
@@ -302,6 +302,34 @@ void write(string s="", cputime c, string format=cputimeformat,
write(stdout,s,c,format,suffix);
}
+struct realschur {
+ real[][] U;
+ real[][] T;
+}
+
+realschur schur(real[][] a)
+{
+ real[][][] S=_schur(a);
+ realschur schur;
+ schur.U=S[0];
+ schur.T=S[1];
+ return schur;
+}
+
+struct schur {
+ pair[][] U;
+ pair[][] T;
+}
+
+schur schur(pair[][] a)
+{
+ pair[][][] S=_schur(a);
+ schur schur;
+ schur.U=S[0];
+ schur.T=S[1];
+ return schur;
+}
+
if(settings.autoimport != "") {
string s=settings.autoimport;
settings.autoimport="";
diff --git a/Build/source/utils/asymptote/base/plain_arrows.asy b/Build/source/utils/asymptote/base/plain_arrows.asy
index 79ee403af3d..d9c08636fc9 100644
--- a/Build/source/utils/asymptote/base/plain_arrows.asy
+++ b/Build/source/utils/asymptote/base/plain_arrows.asy
@@ -53,39 +53,39 @@ path arrowbase(path r, pair y, real t, real size)
arrowhead DefaultHead;
DefaultHead.head=new path(path g, position position=EndPoint, pen p=currentpen,
real size=0, real angle=arrowangle) {
- if(size == 0) size=DefaultHead.size(p);
- bool relative=position.relative;
- real position=position.position.x;
- if(relative) position=reltime(g,position);
- path r=subpath(g,position,0);
- pair x=point(r,0);
- real t=arctime(r,size);
- pair y=point(r,t);
- path base=arrowbase(r,y,t,size);
- path left=rotate(-angle,x)*r;
- path right=rotate(angle,x)*r;
- real[] T=arrowbasepoints(base,left,right);
- pair denom=point(right,T[1])-y;
- real factor=denom != 0 ? length((point(left,T[0])-y)/denom) : 1;
- path left=rotate(-angle*factor,x)*r;
- path right=rotate(angle*factor,x)*r;
- real[] T=arrowbasepoints(base,left,right);
- return subpath(left,0,T[0])--subpath(right,T[1],0)&cycle;
+ if(size == 0) size=DefaultHead.size(p);
+ bool relative=position.relative;
+ real position=position.position.x;
+ if(relative) position=reltime(g,position);
+ path r=subpath(g,position,0);
+ pair x=point(r,0);
+ real t=arctime(r,size);
+ pair y=point(r,t);
+ path base=arrowbase(r,y,t,size);
+ path left=rotate(-angle,x)*r;
+ path right=rotate(angle,x)*r;
+ real[] T=arrowbasepoints(base,left,right);
+ pair denom=point(right,T[1])-y;
+ real factor=denom != 0 ? length((point(left,T[0])-y)/denom) : 1;
+ path left=rotate(-angle*factor,x)*r;
+ path right=rotate(angle*factor,x)*r;
+ real[] T=arrowbasepoints(base,left,right);
+ return subpath(left,0,T[0])--subpath(right,T[1],0)&cycle;
};
arrowhead SimpleHead;
SimpleHead.head=new path(path g, position position=EndPoint, pen p=currentpen,
real size=0, real angle=arrowangle) {
- if(size == 0) size=SimpleHead.size(p);
- bool relative=position.relative;
- real position=position.position.x;
- if(relative) position=reltime(g,position);
- path r=subpath(g,position,0);
- pair x=point(r,0);
- real t=arctime(r,size);
- path left=rotate(-angle,x)*r;
- path right=rotate(angle,x)*r;
- return subpath(left,t,0)--subpath(right,0,t);
+ if(size == 0) size=SimpleHead.size(p);
+ bool relative=position.relative;
+ real position=position.position.x;
+ if(relative) position=reltime(g,position);
+ path r=subpath(g,position,0);
+ pair x=point(r,0);
+ real t=arctime(r,size);
+ path left=rotate(-angle,x)*r;
+ path right=rotate(angle,x)*r;
+ return subpath(left,t,0)--subpath(right,0,t);
};
arrowhead HookHead(real dir=arrowdir, real barb=arrowbarb)
@@ -94,34 +94,34 @@ arrowhead HookHead(real dir=arrowdir, real barb=arrowbarb)
a.head=new path(path g, position position=EndPoint, pen p=currentpen,
real size=0, real angle=arrowangle)
{
- if(size == 0) size=a.size(p);
- angle=min(angle*arrowhookfactor,45);
- bool relative=position.relative;
- real position=position.position.x;
- if(relative) position=reltime(g,position);
- path r=subpath(g,position,0);
- pair x=point(r,0);
- real t=arctime(r,size);
- pair y=point(r,t);
- path base=arrowbase(r,y,t,size);
- path left=rotate(-angle,x)*r;
- path right=rotate(angle,x)*r;
- real[] T=arrowbasepoints(base,left,right,1);
- pair denom=point(right,T[1])-y;
- real factor=denom != 0 ? length((point(left,T[0])-y)/denom) : 1;
- path left=rotate(-angle*factor,x)*r;
- path right=rotate(angle*factor,x)*r;
- real[] T=arrowbasepoints(base,left,right,1);
- left=subpath(left,0,T[0]);
- right=subpath(right,T[1],0);
- pair pl0=point(left,0), pl1=relpoint(left,1);
- pair pr0=relpoint(right,0), pr1=relpoint(right,1);
- pair M=(pl1+pr0)/2;
- pair v=barb*unit(M-pl0);
- pl1=pl1+v; pr0=pr0+v;
- left=pl0{dir(-dir+degrees(M-pl0,false))}..pl1--M;
- right=M--pr0..pr1{dir(dir+degrees(pr1-M,false))};
- return left--right&cycle;
+ if(size == 0) size=a.size(p);
+ angle=min(angle*arrowhookfactor,45);
+ bool relative=position.relative;
+ real position=position.position.x;
+ if(relative) position=reltime(g,position);
+ path r=subpath(g,position,0);
+ pair x=point(r,0);
+ real t=arctime(r,size);
+ pair y=point(r,t);
+ path base=arrowbase(r,y,t,size);
+ path left=rotate(-angle,x)*r;
+ path right=rotate(angle,x)*r;
+ real[] T=arrowbasepoints(base,left,right,1);
+ pair denom=point(right,T[1])-y;
+ real factor=denom != 0 ? length((point(left,T[0])-y)/denom) : 1;
+ path left=rotate(-angle*factor,x)*r;
+ path right=rotate(angle*factor,x)*r;
+ real[] T=arrowbasepoints(base,left,right,1);
+ left=subpath(left,0,T[0]);
+ right=subpath(right,T[1],0);
+ pair pl0=point(left,0), pl1=relpoint(left,1);
+ pair pr0=relpoint(right,0), pr1=relpoint(right,1);
+ pair M=(pl1+pr0)/2;
+ pair v=barb*unit(M-pl0);
+ pl1=pl1+v; pr0=pr0+v;
+ left=pl0{dir(-dir+degrees(M-pl0,false))}..pl1--M;
+ right=M--pr0..pr1{dir(dir+degrees(pr1-M,false))};
+ return left--right&cycle;
};
return a;
}
@@ -130,34 +130,34 @@ arrowhead HookHead=HookHead();
arrowhead TeXHead;
TeXHead.size=new real(pen p)
{
- static real hcoef=2.1; // 84/40=abs(base-hint)/base_height
- return hcoef*arrowtexfactor*linewidth(p);
+ static real hcoef=2.1; // 84/40=abs(base-hint)/base_height
+ return hcoef*arrowtexfactor*linewidth(p);
};
TeXHead.arcsize=TeXHead.size;
TeXHead.head=new path(path g, position position=EndPoint, pen p=currentpen,
real size=0, real angle=arrowangle) {
- static real wcoef=1/84; // 1/abs(base-hint)
- static path texhead=scale(wcoef)*
- ((0,20) .. controls (-75,75) and (-108,158) ..
- (-108,166) .. controls (-108,175) and (-100,178) ..
- (-93,178) .. controls (-82,178) and (-80,173) ..
- (-77,168) .. controls (-62,134) and (-30,61) ..
- (70,14) .. controls (82,8) and (84,7) ..
- (84,0) .. controls (84,-7) and (82,-8) ..
- (70,-14) .. controls (-30,-61) and (-62,-134) ..
- (-77,-168) .. controls (-80,-173) and (-82,-178) ..
- (-93,-178) .. controls (-100,-178) and (-108,-175)..
- (-108,-166).. controls (-108,-158) and (-75,-75) ..
- (0,-20)--cycle);
- if(size == 0) size=TeXHead.size(p);
- path gp=scale(size)*texhead;
- bool relative=position.relative;
- real position=position.position.x;
- if(relative) position=reltime(g,position);
- path r=subpath(g,position,0);
- pair y=point(r,arctime(r,size));
- return shift(y)*rotate(degrees(-dir(r,arctime(r,0.5*size))))*gp;
+ static real wcoef=1/84; // 1/abs(base-hint)
+ static path texhead=scale(wcoef)*
+ ((0,20) .. controls (-75,75) and (-108,158) ..
+ (-108,166) .. controls (-108,175) and (-100,178) ..
+ (-93,178) .. controls (-82,178) and (-80,173) ..
+ (-77,168) .. controls (-62,134) and (-30,61) ..
+ (70,14) .. controls (82,8) and (84,7) ..
+ (84,0) .. controls (84,-7) and (82,-8) ..
+ (70,-14) .. controls (-30,-61) and (-62,-134) ..
+ (-77,-168) .. controls (-80,-173) and (-82,-178) ..
+ (-93,-178) .. controls (-100,-178) and (-108,-175)..
+ (-108,-166).. controls (-108,-158) and (-75,-75) ..
+ (0,-20)--cycle);
+ if(size == 0) size=TeXHead.size(p);
+ path gp=scale(size)*texhead;
+ bool relative=position.relative;
+ real position=position.position.x;
+ if(relative) position=reltime(g,position);
+ path r=subpath(g,position,0);
+ pair y=point(r,arctime(r,size));
+ return shift(y)*rotate(degrees(-dir(r,arctime(r,0.5*size)),false))*gp;
};
TeXHead.defaultfilltype=new filltype(pen p) {return Fill(p);};
diff --git a/Build/source/utils/asymptote/base/plain_pens.asy b/Build/source/utils/asymptote/base/plain_pens.asy
index 2e3a4449a38..2f47855a9f4 100644
--- a/Build/source/utils/asymptote/base/plain_pens.asy
+++ b/Build/source/utils/asymptote/base/plain_pens.asy
@@ -1,4 +1,4 @@
-real labelmargin=0.3;
+real labelmargin=0.28;
real dotfactor=6;
pen solid=linetype(new real[]);
@@ -173,7 +173,7 @@ pen fontsize(real size)
real labelmargin(pen p=currentpen)
{
- return labelmargin*fontsize(p);
+ return labelmargin*fontsize(p)+0.5*linewidth(p);
}
void write(file file=stdout, string s="", pen[] p)
diff --git a/Build/source/utils/asymptote/base/rationalSimplex.asy b/Build/source/utils/asymptote/base/rationalSimplex.asy
index 3a376ba2ddb..b6ce98c4ae9 100644
--- a/Build/source/utils/asymptote/base/rationalSimplex.asy
+++ b/Build/source/utils/asymptote/base/rationalSimplex.asy
@@ -1,9 +1,14 @@
// Rational simplex solver written by John C. Bowman and Pouria Ramazi, 2018.
import rational;
+bool optimizeTableau=true;
+
+int[] artificialColumn;
+
void simplexInit(rational[] c, rational[][] A, int[] s=new int[],
rational[] b, int count) {}
-void simplexTableau(rational[][] E, int[] Bindices, int I=-1, int J=-1) {}
+void simplexTableau(rational[][] E, int[] Bindices, int I=-1, int J=-1,
+ int n=E[0].length-1) {}
void simplexPhase1(rational[] c, rational[][] A, rational[] b,
int[] Bindices) {}
void simplexPhase2() {}
@@ -71,7 +76,7 @@ struct simplex {
}
}
- int iterate(rational[][] E, int N, int[] Bindices) {
+ int iterate(rational[][] E, int N, int[] Bindices, bool phase1=false) {
while(true) {
// Bland's rule: first negative entry in reduced cost (bottom) row enters
rational[] Em=E[m];
@@ -108,11 +113,13 @@ struct simplex {
// Generate new tableau
Bindices[I]=J;
rowreduce(E,N,I,J);
+
+ if(phase1 && Em[0] == 0) break;
}
return OPTIMAL;
}
- int iterateDual(rational[][] E, int N, int[] Bindices) {
+ int iterateDual(rational[][] E, int N, int[] Bindices, bool phase1=false) {
while(true) {
// Bland's rule: negative variable with smallest subscript exits
int I;
@@ -211,30 +218,31 @@ struct simplex {
if(phase1) {
Bindices=new int[m];
- int p=0;
+ int k=0;
+ artificialColumn.delete();
// Check for redundant basis vectors.
- bool checkBasis(int j) {
- for(int i=0; i < m; ++i) {
- rational[] Ei=E[i];
- if(i != p ? Ei[j] != 0 : Ei[j] <= 0) return false;
+ for(int p=0; p < m; ++p) {
+ bool checkBasis(int j) {
+ for(int i=0; i < m; ++i) {
+ rational[] Ei=E[i];
+ if(i != p ? Ei[j] != 0 : Ei[j] <= 0)
+ return false;
+ }
+ return true;
}
- return true;
- }
- int checkTableau() {
- for(int j=1; j <= n; ++j)
- if(checkBasis(j)) return j;
- return 0;
- }
+ int checkTableau() {
+ if(optimizeTableau)
+ for(int j=1; j <= n; ++j)
+ if(checkBasis(j)) return j;
+ return 0;
+ }
- int k=0;
- while(p < m) {
int j=checkTableau();
- if(j > 0)
- Bindices[p]=j;
- else { // Add an artificial variable
- Bindices[p]=n+1+k;
+ Bindices[p]=n+1+p;
+ if(j == 0) { // Add an artificial variable
+ artificialColumn.push(p+1);
for(int i=0; i < p; ++i)
E[i].push(0);
E[p].push(1);
@@ -243,14 +251,13 @@ struct simplex {
E[m].push(0);
++k;
}
- ++p;
}
basicValues();
simplexPhase1(c,A,b,Bindices);
- iterate(E,n+k,Bindices);
+ iterate(E,n+k,Bindices,true);
if(Em[0] != 0) {
simplexTableau(E,Bindices);
@@ -265,23 +272,22 @@ struct simplex {
rational[] cB=phase1 ? new rational[m] : c[n-m:n];
rational[][] D=phase1 ? new rational[m+1][n+1] : E;
if(phase1) {
- bool output=true;
+ write("n=",n);
+ write(Bindices);
// Drive artificial variables out of basis.
for(int i=0; i < m; ++i) {
- int k=Bindices[i];
- if(k > n) {
+ if(Bindices[i] > n) {
rational[] Ei=E[i];
int j;
for(j=1; j <= n; ++j)
if(Ei[j] != 0) break;
if(j > n) continue;
- output=false;
- simplexTableau(E,Bindices,i,j);
+ simplexTableau(E,Bindices,i,j,n);
Bindices[i]=j;
rowreduce(E,n,i,j);
}
}
- if(output) simplexTableau(E,Bindices);
+ simplexTableau(E,Bindices,-1,-1,n);
int ip=0; // reduced i
for(int i=0; i < m; ++i) {
int k=Bindices[i];
@@ -307,7 +313,6 @@ struct simplex {
D.delete(ip,m-1);
m=ip;
}
- if(!output) simplexTableau(D,Bindices);
}
rational[] Dm=D[m];
@@ -335,6 +340,8 @@ struct simplex {
for(int k=0; k < m; ++k)
x[Bindices[k]-1]=D[k][0];
+
+ xStandard=copy(x);
}
if(case == UNBOUNDED) {
@@ -414,10 +421,7 @@ struct simplex {
simplexInit(C,a,b,count);
operator init(C,a,b,phase1);
- if(case != INFEASIBLE) {
- xStandard=copy(x);
- if(count > 0)
- x.delete(n,n+count-1);
- }
+ if(case != INFEASIBLE && count > 0)
+ x.delete(n,n+count-1);
}
}
diff --git a/Build/source/utils/asymptote/base/shaders/blend.glsl b/Build/source/utils/asymptote/base/shaders/blend.glsl
index 76dfe94ad30..2db4f30abee 100644
--- a/Build/source/utils/asymptote/base/shaders/blend.glsl
+++ b/Build/source/utils/asymptote/base/shaders/blend.glsl
@@ -1,34 +1,22 @@
-layout(binding=0, std430) buffer offsetBuffer {
+layout(binding=0, std430) buffer offsetBuffer
+{
+ uint maxDepth;
uint offset[];
};
-layout(binding=1, std430) buffer maxBuffer {
+layout(binding=2, std430) buffer countBuffer
+{
uint maxSize;
-};
-
-#ifdef GPUINDEXING
-uniform uint offset2;
-uniform uint m1;
-uniform uint r;
-
-layout(binding=2, std430) buffer localSumBuffer {
- uint localSum[];
-};
-
-layout(binding=3, std430) buffer globalSumBuffer {
- uint globalSum[];
-};
-#else
-layout(binding=2, std430) buffer countBuffer {
uint count[];
};
-#endif
-layout(binding=4, std430) buffer fragmentBuffer {
+layout(binding=4, std430) buffer fragmentBuffer
+{
vec4 fragment[];
};
-layout(binding=5, std430) buffer depthBuffer {
+layout(binding=5, std430) buffer depthBuffer
+{
float depth[];
};
@@ -40,10 +28,21 @@ layout(binding=7, std430) buffer opaqueDepthBuffer {
float opaqueDepth[];
};
+#ifdef GPUCOMPRESS
+layout(binding=1, std430) buffer indexBuffer
+{
+ uint index[];
+};
+#define INDEX(pixel) index[pixel]
+#define COUNT(pixel) index[pixel]
+#else
+#define INDEX(pixel) pixel
+#define COUNT(pixel) count[pixel]
+#endif
+
out vec4 outColor;
uniform uint width;
-uniform uint pixels;
uniform vec4 background;
vec4 blend(vec4 outColor, vec4 color)
@@ -53,29 +52,37 @@ vec4 blend(vec4 outColor, vec4 color)
void main()
{
- uint headIndex=uint(gl_FragCoord.y)*width+uint(gl_FragCoord.x);
+ uint pixel=uint(gl_FragCoord.y)*width+uint(gl_FragCoord.x);
+ float OpaqueDepth=opaqueDepth[pixel];
+ uint element=INDEX(pixel);
+
+#ifdef GPUCOMPRESS
+ if(element == 0u) {
+ if(OpaqueDepth != 0.0)
+ opaqueDepth[pixel]=0.0;
+ discard;
+ }
+#endif
+
#ifdef GPUINDEXING
- uint size=offset[headIndex];
+ uint listIndex=offset[element];
+ uint size=offset[element+1u]-listIndex;
#else
- uint size=count[headIndex];
+ uint size=count[element];
#endif
- float OpaqueDepth=opaqueDepth[headIndex];
+
+#ifndef GPUCOMPRESS
if(size == 0u) {
-#ifdef GPUINDEXING
- offset[pixels+headIndex]=0u;
-#endif
- opaqueDepth[headIndex]=0.0;
+ if(OpaqueDepth != 0.0)
+ opaqueDepth[pixel]=0.0;
discard;
}
+#endif
- outColor=OpaqueDepth != 0.0 ? opaqueColor[headIndex] : background;
+ outColor=OpaqueDepth != 0.0 ? opaqueColor[pixel] : background;
-#ifdef GPUINDEXING
- uint p=headIndex < r*(m1+1u) ? headIndex/(m1+1u) : (headIndex-r)/m1;
- uint listIndex=localSum[p]+localSum[offset2+p/m2]+globalSum[p/(m2*m2)]+
- offset[pixels+headIndex];
-#else
- uint listIndex=offset[headIndex]-size;
+#ifndef GPUINDEXING
+ uint listIndex=offset[element]-size;
#endif
uint k=0u;
@@ -83,36 +90,49 @@ void main()
while(k < size && depth[listIndex+k] >= OpaqueDepth)
++k;
+ uint n=size-k;
+
// Sort the fragments with respect to descending depth
- if(size-k <= ARRAYSIZE) {
- if(k < size) {
- uint Index[ARRAYSIZE];
- float Depth[ARRAYSIZE];
- Index[0]=k;
- Depth[0]=depth[listIndex+k];
- ++k;
+ if(n <= ARRAYSIZE) {
+ if(n == 1)
+ outColor=blend(outColor,fragment[listIndex+k]);
+ else if(n > 0) {
+ struct element {
+ uint index;
+ float depth;
+ };
+
+ element E[ARRAYSIZE];
+ E[0]=element(k,depth[listIndex+k]);
uint i=1u;
- while(true) {
- if(OpaqueDepth != 0.0)
- while(k < size && depth[listIndex+k] >= OpaqueDepth)
- ++k;
- if(k == size) break;
+ while(++k < size) {
float d=depth[listIndex+k];
+ if(OpaqueDepth != 0.0) {
+ while(k < size && d >= OpaqueDepth) {
+ ++k;
+ d=depth[listIndex+k];
+ }
+ if(k == size) break;
+ }
uint j=i;
- while(j > 0u && d > Depth[j-1u]) {
- Index[j]=Index[j-1u];
- Depth[j]=Depth[j-1u];
+ while(j > 0u && d > E[j-1u].depth) {
+ E[j]=E[j-1u];
--j;
}
- Index[j]=k++;
- Depth[j]=d;
+ E[j]=element(k,d);
++i;
}
for(uint j=0u; j < i; ++j)
- outColor=blend(outColor,fragment[listIndex+Index[j]]);
+ outColor=blend(outColor,fragment[listIndex+E[j].index]);
}
+
+ if(OpaqueDepth != 0.0)
+ opaqueDepth[pixel]=0.0;
} else {
- atomicMax(maxSize,size);
+ atomicMax(maxDepth,size);
+#ifndef GPUINDEXING
+ maxSize=maxDepth;
+#endif
for(uint i=k+1u; i < size; i++) {
vec4 temp=fragment[listIndex+i];
float d=depth[listIndex+i];
@@ -130,19 +150,14 @@ void main()
if(OpaqueDepth == 0.0)
for(uint i=listIndex+k; i < stop; i++)
outColor=blend(outColor,fragment[i]);
- else
+ else {
for(uint i=listIndex+k; i < stop; i++) {
if(depth[i] < OpaqueDepth)
outColor=blend(outColor,fragment[i]);
}
+ opaqueDepth[pixel]=0.0;
+ }
}
-
- opaqueDepth[headIndex]=0.0;
-#ifdef GPUINDEXING
- offset[headIndex]=0u;
- offset[pixels+headIndex]=0u;
-#else
- count[headIndex]=0u;
-#endif
+ COUNT(pixel)=0u;
}
diff --git a/Build/source/utils/asymptote/base/shaders/compress.glsl b/Build/source/utils/asymptote/base/shaders/compress.glsl
new file mode 100644
index 00000000000..26b4e1041e9
--- /dev/null
+++ b/Build/source/utils/asymptote/base/shaders/compress.glsl
@@ -0,0 +1,23 @@
+layout(binding=0) uniform atomic_uint elements;
+
+layout(binding=1, std430) buffer indexBuffer
+{
+ uint index[];
+};
+
+layout(binding=2, std430) buffer countBuffer
+{
+ uint maxSize;
+ uint count[];
+};
+
+uniform uint width;
+
+void main()
+{
+ uint pixel=uint(gl_FragCoord.y)*width+uint(gl_FragCoord.x);
+ uint Count=index[pixel];
+ if(Count > 0u)
+ count[(index[pixel]=atomicCounterIncrement(elements))]=Count;
+ discard;
+}
diff --git a/Build/source/utils/asymptote/base/shaders/count.glsl b/Build/source/utils/asymptote/base/shaders/count.glsl
index c9427714980..f64b25ed44a 100644
--- a/Build/source/utils/asymptote/base/shaders/count.glsl
+++ b/Build/source/utils/asymptote/base/shaders/count.glsl
@@ -1,10 +1,13 @@
-#ifdef GPUINDEXING
-layout(binding=0, std430) buffer offsetBuffer {
- uint count[];
+#ifdef GPUCOMPRESS
+layout(binding=1, std430) buffer indexBuffer
+{
+ uint index[];
};
#else
-layout(binding=2, std430) buffer countBuffer {
- uint count[];
+layout(binding=2, std430) buffer countBuffer
+{
+ uint maxSize;
+ uint index[];
};
#endif
@@ -12,6 +15,6 @@ uniform uint width;
void main()
{
- atomicAdd(count[uint(gl_FragCoord.y)*width+uint(gl_FragCoord.x)],1u);
+ atomicAdd(index[uint(gl_FragCoord.y)*width+uint(gl_FragCoord.x)],1u);
discard;
}
diff --git a/Build/source/utils/asymptote/base/shaders/fragment.glsl b/Build/source/utils/asymptote/base/shaders/fragment.glsl
index e8d4be86cf2..6f42f7d4919 100644
--- a/Build/source/utils/asymptote/base/shaders/fragment.glsl
+++ b/Build/source/utils/asymptote/base/shaders/fragment.glsl
@@ -30,49 +30,51 @@ float Roughness;
#ifdef HAVE_SSBO
-layout(binding=0, std430) buffer offsetBuffer {
+layout(binding=0, std430) buffer offsetBuffer
+{
+ uint maxDepth;
uint offset[];
};
-#ifdef GPUINDEXING
-
-#if defined(TRANSPARENT) || (!defined(HAVE_INTERLOCK) && !defined(OPAQUE))
-uniform uint offset2;
-uniform uint m1;
-uniform uint r;
-#endif
-
-layout(binding=2, std430) buffer localSumBuffer {
- uint localSum[];
-};
-
-layout(binding=3, std430) buffer globalSumBuffer {
- uint globalSum[];
-};
-#else
-layout(binding=2, std430) buffer countBuffer {
+#ifndef GPUINDEXING
+layout(binding=2, std430) buffer countBuffer
+{
+ uint maxSize;
uint count[];
};
#endif
-layout(binding=4, std430) buffer fragmentBuffer {
+layout(binding=4, std430) buffer fragmentBuffer
+{
vec4 fragment[];
};
-layout(binding=5, std430) buffer depthBuffer {
+layout(binding=5, std430) buffer depthBuffer
+{
float depth[];
};
-layout(binding=6, std430) buffer opaqueBuffer {
+layout(binding=6, std430) buffer opaqueBuffer
+{
vec4 opaqueColor[];
};
-layout(binding=7, std430) buffer opaqueDepthBuffer {
+layout(binding=7, std430) buffer opaqueDepthBuffer
+{
float opaqueDepth[];
};
+#ifdef GPUCOMPRESS
+layout(binding=1, std430) buffer indexBuffer
+{
+ uint index[];
+};
+#define INDEX(pixel) index[pixel]
+#else
+#define INDEX(pixel) pixel
+#endif
+
uniform uint width;
-uniform uint pixels;
#endif
@@ -272,14 +274,13 @@ void main()
#ifndef WIDTH
#ifdef HAVE_SSBO
- uint headIndex=uint(gl_FragCoord.y)*width+uint(gl_FragCoord.x);
+ uint pixel=uint(gl_FragCoord.y)*width+uint(gl_FragCoord.x);
#if defined(TRANSPARENT) || (!defined(HAVE_INTERLOCK) && !defined(OPAQUE))
+ uint element=INDEX(pixel);
#ifdef GPUINDEXING
- uint p=headIndex < r*(m1+1u) ? headIndex/(m1+1u) : (headIndex-r)/m1;
- uint listIndex=localSum[p]+localSum[offset2+p/m2]+globalSum[p/(m2*m2)]+
- atomicAdd(offset[pixels+headIndex],-1u)-1u;
+ uint listIndex=atomicAdd(offset[element],-1u)-1u;
#else
- uint listIndex=offset[headIndex]-atomicAdd(count[headIndex],1u)-1u;
+ uint listIndex=offset[element]-atomicAdd(count[element],1u)-1u;
#endif
fragment[listIndex]=outColor;
depth[listIndex]=gl_FragCoord.z;
@@ -287,18 +288,16 @@ void main()
discard;
#endif
#else
-#ifndef OPAQUE
-#ifdef HAVE_INTERLOCK
+#if defined(HAVE_INTERLOCK) && !defined(OPAQUE)
beginInvocationInterlockARB();
- if(opaqueDepth[headIndex] == 0.0 || gl_FragCoord.z < opaqueDepth[headIndex])
+ if(opaqueDepth[pixel] == 0.0 || gl_FragCoord.z < opaqueDepth[pixel])
{
- opaqueDepth[headIndex]=gl_FragCoord.z;
- opaqueColor[headIndex]=outColor;
+ opaqueDepth[pixel]=gl_FragCoord.z;
+ opaqueColor[pixel]=outColor;
}
endInvocationInterlockARB();
#endif
#endif
#endif
#endif
-#endif
}
diff --git a/Build/source/utils/asymptote/base/shaders/sum1.glsl b/Build/source/utils/asymptote/base/shaders/sum1.glsl
index 2cb9ed23aac..e54744a1d46 100644
--- a/Build/source/utils/asymptote/base/shaders/sum1.glsl
+++ b/Build/source/utils/asymptote/base/shaders/sum1.glsl
@@ -1,38 +1,40 @@
-layout(local_size_x=LOCAL_SIZE_X) in;
+layout(local_size_x=LOCALSIZE) in;
+
+const uint groupSize=LOCALSIZE*BLOCKSIZE;
uniform uint elements;
-layout(binding=0, std430) buffer offsetBuffer
+layout(binding=2, std430) buffer countBuffer
{
- uint offset[];
+ uint maxSize;
+ uint count[];
};
-layout(binding=2, std430) buffer localSumBuffer
+layout(binding=3, std430) buffer globalSumBuffer
{
- uint localSum[];
+ uint globalSum[];
};
-void main(void)
+shared uint groupSum[LOCALSIZE];
+
+void main()
{
- uint id=gl_GlobalInvocationID.x;
-
- uint m=elements/(gl_WorkGroupSize.x*gl_NumWorkGroups.x);
- uint r=elements-m*gl_WorkGroupSize.x*gl_NumWorkGroups.x;
- uint row,stop;
- if(id < r) {
- row=m*id+id;
- stop=row+m+1u;
- } else {
- row=m*id+r;
- stop=row+m;
- }
+ uint id=gl_LocalInvocationID.x;
+ uint dataOffset=gl_WorkGroupID.x*groupSize+id;
+ uint stop=dataOffset+groupSize;
+ uint sum=0u;
+ for(uint i=dataOffset; i < stop; i += LOCALSIZE)
+ sum += count[i];
+
+ groupSum[id]=sum;
+ barrier();
- uint Sum=offset[row];
- offset[elements+row]=Sum;
- for(uint i=row+1u; i < stop; ++i) {
- Sum += offset[i];
- offset[elements+i]=Sum;
+ for(uint s=LOCALSIZE/2; s > 0u; s >>= 1u) {
+ if(id < s)
+ groupSum[id] += groupSum[id+s];
+ barrier();
}
- localSum[id+1u]=Sum;
+ if(id == 0u)
+ globalSum[gl_WorkGroupID.x]=groupSum[0u];
}
diff --git a/Build/source/utils/asymptote/base/shaders/sum2.glsl b/Build/source/utils/asymptote/base/shaders/sum2.glsl
index 1ab03513ebd..17b5efeaeeb 100644
--- a/Build/source/utils/asymptote/base/shaders/sum2.glsl
+++ b/Build/source/utils/asymptote/base/shaders/sum2.glsl
@@ -1,24 +1,43 @@
-layout(local_size_x=LOCAL_SIZE_X) in;
+layout(local_size_x=LOCALSIZE) in;
-uniform uint offset2;
+const uint groupSize=LOCALSIZE*BLOCKSIZE;
-layout(binding=2, std430) buffer localSumBuffer
+uniform uint blockSize;
+
+layout(binding=3, std430) buffer globalSumBuffer
{
- uint localSum[];
+ uint globalSum[];
};
-void main(void)
+shared uint groupSum[LOCALSIZE];
+
+void main()
{
- uint id=gl_GlobalInvocationID.x;
+ uint localSum[groupSize];
+ uint id=gl_LocalInvocationID.x;
+
+ uint dataOffset=blockSize*id;
+ uint sum=0u;
+ for(uint i=0; i < blockSize; ++i) {
+ localSum[i]=sum;
+ sum += globalSum[dataOffset+i];
+ }
- uint row=LOCAL_SIZE_X*id;
- uint stop=row+LOCAL_SIZE_X;
+ groupSum[id]=sum;
+ barrier();
- uint Sum=localSum[row];
- for(uint i=row+1u; i < stop; ++i) {
- Sum += localSum[i];
- localSum[i]=Sum;
+ for(uint shift=1u; shift < LOCALSIZE; shift *= 2u) {
+ uint read;
+ if(shift <= id)
+ read=groupSum[id]+groupSum[id-shift];
+ barrier();
+ if(shift <= id)
+ groupSum[id]=read;
+ barrier();
}
- localSum[offset2+id+1u]=Sum;
+ // shift local sums and store
+ uint shift=id > 0u ? groupSum[id-1u] : 0u;
+ for(uint i=0u; i < blockSize; ++i)
+ globalSum[dataOffset+i]=localSum[i]+shift;
}
diff --git a/Build/source/utils/asymptote/base/shaders/sum2fast.glsl b/Build/source/utils/asymptote/base/shaders/sum2fast.glsl
new file mode 100644
index 00000000000..d0c93c09575
--- /dev/null
+++ b/Build/source/utils/asymptote/base/shaders/sum2fast.glsl
@@ -0,0 +1,59 @@
+layout(local_size_x=LOCALSIZE) in;
+
+const uint groupSize=LOCALSIZE*BLOCKSIZE;
+
+layout(binding=3, std430) buffer globalSumBuffer
+{
+ uint globalSum[];
+};
+
+layout(binding=8, std430) buffer feedbackBuffer
+{
+ uint maxSize;
+ uint fragments;
+};
+
+shared uint shuffle[groupSize+LOCALSIZE-1u];
+shared uint groupSum[LOCALSIZE+1u];
+
+void main()
+{
+ uint id=gl_LocalInvocationID.x;
+
+// avoid bank conflicts and coalesce global memory accesses
+ uint shuffleOffset=id/BLOCKSIZE+id;
+ const uint stride=LOCALSIZE/BLOCKSIZE+LOCALSIZE;
+ for(uint i=0u; i < BLOCKSIZE; i++)
+ shuffle[shuffleOffset+i*stride]=globalSum[id+i*LOCALSIZE];
+
+ barrier();
+
+ uint Offset=id*BLOCKSIZE+id;
+ uint stop=Offset+BLOCKSIZE;
+ uint sum=0u;
+ for(uint i=Offset; i < stop; ++i) {
+ uint value=shuffle[i];
+ shuffle[i]=sum;
+ sum += value;
+ }
+
+ if(id == 0u)
+ groupSum[0u]=0u;
+ groupSum[id+1u]=sum;
+ barrier();
+
+ // Apply Hillis-Steele algorithm over all sums in workgroup
+ for(uint shift=1u; shift < LOCALSIZE; shift *= 2u) {
+ uint read;
+ if(shift <= id)
+ read=groupSum[id]+groupSum[id-shift];
+ barrier();
+ if(shift <= id)
+ groupSum[id]=read;
+ barrier();
+ }
+
+ for(uint i=0u; i < BLOCKSIZE; i++)
+ globalSum[id+i*LOCALSIZE]=
+ shuffle[shuffleOffset+i*stride]+groupSum[(i*LOCALSIZE+id)/BLOCKSIZE];
+}
diff --git a/Build/source/utils/asymptote/base/shaders/sum3.glsl b/Build/source/utils/asymptote/base/shaders/sum3.glsl
index 85f55ff2a6c..4ee5203060b 100644
--- a/Build/source/utils/asymptote/base/shaders/sum3.glsl
+++ b/Build/source/utils/asymptote/base/shaders/sum3.glsl
@@ -1,28 +1,80 @@
-layout(local_size_x=LOCAL_SIZE_X) in;
+layout(local_size_x=LOCALSIZE) in;
-uniform uint offset2;
+const uint groupSize=LOCALSIZE*BLOCKSIZE;
-layout(binding=2, std430) buffer localSumBuffer
+uniform uint final;
+
+layout(binding=0, std430) buffer offsetBuffer
+{
+ uint maxDepth;
+ uint offset[];
+};
+
+layout(binding=2, std430) buffer countBuffer
{
- uint localSum[];
+ uint maxSize;
+ uint count[];
};
-layout(binding=3, std430) buffer globalSumBuffer {
+layout(binding=3, std430) buffer globalSumBuffer
+{
uint globalSum[];
};
-void main(void)
+layout(binding=8, std430) buffer feedbackBuffer
{
- uint id=gl_GlobalInvocationID.x;
+ uint size;
+ uint fragments;
+};
- uint row=offset2+LOCAL_SIZE_X*id;
- uint stop=row+LOCAL_SIZE_X;
+shared uint shuffle[groupSize+LOCALSIZE-1u];
+shared uint groupSum[LOCALSIZE+1u];
+
+void main()
+{
+ uint id=gl_LocalInvocationID.x;
- uint Sum=localSum[row];
- for(uint i=row+1u; i < stop; ++i) {
- Sum += localSum[i];
- localSum[i]=Sum;
+// avoid bank conflicts and coalesce global memory accesses
+ uint dataOffset=gl_WorkGroupID.x*groupSize+id;
+ uint shuffleOffset=id/BLOCKSIZE+id;
+ const uint stride=LOCALSIZE/BLOCKSIZE+LOCALSIZE;
+ for(uint i=0u; i < BLOCKSIZE; i++)
+ shuffle[shuffleOffset+i*stride]=count[dataOffset+i*LOCALSIZE];
+
+ barrier();
+
+ uint Offset=id*BLOCKSIZE+id;
+ uint stop=Offset+BLOCKSIZE;
+
+ uint sum=0u;
+ for(uint i=Offset; i < stop; ++i)
+ shuffle[i]=sum += shuffle[i];
+
+ if(id == 0u)
+ groupSum[0u]=0u;
+ groupSum[id+1u]=sum;
+ barrier();
+
+ // Apply Hillis-Steele algorithm over all sums in workgroup
+ for(uint shift=1u; shift < LOCALSIZE; shift *= 2u) {
+ uint read;
+ if(shift <= id)
+ read=groupSum[id]+groupSum[id-shift];
+ barrier();
+ if(shift <= id)
+ groupSum[id]=read;
+ barrier();
}
- globalSum[id+1u]=Sum;
+ uint groupOffset=globalSum[gl_WorkGroupID.x];
+ for(uint i=0u; i < BLOCKSIZE; ++i)
+ offset[dataOffset+i*LOCALSIZE]=shuffle[shuffleOffset+i*stride]+
+ groupSum[(i*LOCALSIZE+id)/BLOCKSIZE]+groupOffset;
+
+ uint diff=final-dataOffset;
+ if(diff < groupSize && diff % LOCALSIZE == 0) {
+ size=maxDepth;
+ maxDepth=0u;
+ fragments=offset[final+1u]=offset[final];
+ }
}
diff --git a/Build/source/utils/asymptote/base/shaders/zero.glsl b/Build/source/utils/asymptote/base/shaders/zero.glsl
index 9bcb6d222e5..06a5359e6d9 100644
--- a/Build/source/utils/asymptote/base/shaders/zero.glsl
+++ b/Build/source/utils/asymptote/base/shaders/zero.glsl
@@ -1,4 +1,6 @@
-layout(binding=2, std430) buffer countBuffer {
+layout(binding=2, std430) buffer countBuffer
+{
+ uint maxSize;
uint count[];
};
diff --git a/Build/source/utils/asymptote/base/simplex.asy b/Build/source/utils/asymptote/base/simplex.asy
index 3bc74635dbb..8b53ede6eb6 100644
--- a/Build/source/utils/asymptote/base/simplex.asy
+++ b/Build/source/utils/asymptote/base/simplex.asy
@@ -42,7 +42,7 @@ struct simplex {
}
}
- int iterate(real[][] E, int N, int[] Bindices) {
+ int iterate(real[][] E, int N, int[] Bindices, bool phase1=false) {
while(true) {
// Bland's rule: first negative entry in reduced cost (bottom) row enters
real[] Em=E[m];
@@ -77,11 +77,13 @@ struct simplex {
// Generate new tableau
Bindices[I]=J;
rowreduce(E,N,I,J);
+
+ if(phase1 && abs(Em[0]) <= EpsilonA) break;
}
return OPTIMAL;
}
- int iterateDual(real[][] E, int N, int[] Bindices) {
+ int iterateDual(real[][] E, int N, int[] Bindices, bool phase1=false) {
while(true) {
// Bland's rule: negative variable with smallest subscript exits
int I;
@@ -182,30 +184,28 @@ struct simplex {
if(phase1) {
Bindices=new int[m];
- int p=0;
+ int k=0;
// Check for redundant basis vectors.
- bool checkBasis(int j) {
- for(int i=0; i < m; ++i) {
- real[] Ei=E[i];
- if(i != p ? abs(Ei[j]) >= epsilonA : Ei[j] <= epsilonA) return false;
+ for(int p=0; p < m; ++p) {
+ bool checkBasis(int j) {
+ for(int i=0; i < m; ++i) {
+ real[] Ei=E[i];
+ if(i != p ? abs(Ei[j]) >= epsilonA : Ei[j] <= epsilonA)
+ return false;
+ }
+ return true;
}
- return true;
- }
- int checkTableau() {
- for(int j=1; j <= n; ++j)
- if(checkBasis(j)) return j;
- return 0;
- }
+ int checkTableau() {
+ for(int j=1; j <= n; ++j)
+ if(checkBasis(j)) return j;
+ return 0;
+ }
- int k=0;
- while(p < m) {
int j=checkTableau();
- if(j > 0)
- Bindices[p]=j;
- else { // Add an artificial variable
- Bindices[p]=n+1+k;
+ Bindices[p]=n+1+p;
+ if(j == 0) { // Add an artificial variable
for(int i=0; i < p; ++i)
E[i].push(0.0);
E[p].push(1.0);
@@ -214,11 +214,11 @@ struct simplex {
E[m].push(0.0);
++k;
}
- ++p;
}
basicValues();
- iterate(E,n+k,Bindices);
+
+ iterate(E,n+k,Bindices,true);
if(abs(Em[0]) > EpsilonA) {
case=INFEASIBLE;
@@ -234,8 +234,7 @@ struct simplex {
if(phase1) {
// Drive artificial variables out of basis.
for(int i=0; i < m; ++i) {
- int k=Bindices[i];
- if(k > n) {
+ if(Bindices[i] > n) {
real[] Ei=E[i];
int j;
for(j=1; j <= n; ++j)
diff --git a/Build/source/utils/asymptote/base/slopefield.asy b/Build/source/utils/asymptote/base/slopefield.asy
index c36ee4d9d01..c295fd61b63 100644
--- a/Build/source/utils/asymptote/base/slopefield.asy
+++ b/Build/source/utils/asymptote/base/slopefield.asy
@@ -3,7 +3,7 @@ real stepfraction=0.05;
picture slopefield(real f(real,real), pair a, pair b,
int nx=nmesh, int ny=nx,
- real tickfactor=0.5, pen p=currentpen, arrowbar arrow=None)
+ real tickfactor=0.5, pen p=currentpen)
{
picture pic;
real dx=(b.x-a.x)/nx;
@@ -16,17 +16,16 @@ picture slopefield(real f(real,real), pair a, pair b,
pair cp=(x,a.y+j*dy);
real slope=f(cp.x,cp.y);
real mp=step/sqrt(1+slope^2);
- draw(pic,(cp.x-mp,cp.y-mp*slope)--(cp.x+mp,cp.y+mp*slope),p,arrow);
+ draw(pic,(cp.x-mp,cp.y-mp*slope)--(cp.x+mp,cp.y+mp*slope),p);
}
}
return pic;
}
picture slopefield(real f(real), pair a, pair b,
- int nx=nmesh, int ny=nx, pen p=currentpen,
- arrowbar arrow=None)
+ int nx=nmesh, int ny=nx, pen p=currentpen)
{
- return slopefield(new real(real x, real y) {return f(x);},a,b,nx,ny,p,arrow);
+ return slopefield(new real(real x, real y) {return f(x);},a,b,nx,ny,p);
}
path curve(pair c, real f(real,real), pair a, pair b)
@@ -83,4 +82,3 @@ path curve(pair c, real f(real), pair a, pair b)
{
return curve(c,new real(real x, real y){return f(x);},a,b);
}
-
diff --git a/Build/source/utils/asymptote/base/stats.asy b/Build/source/utils/asymptote/base/stats.asy
index 6183fc18df2..3143a390035 100644
--- a/Build/source/utils/asymptote/base/stats.asy
+++ b/Build/source/utils/asymptote/base/stats.asy
@@ -290,3 +290,30 @@ linefit leastsquares(real[] x, real[] y)
}
return L;
}
+
+// Do a least-squares fit of data in real arrays x and y weighted by w
+// to the line y=m*x+b, by minimizing sum(w*(y-m*x-b)^2).
+linefit leastsquares(real[] x, real[] y, real[] w)
+{
+ linefit L;
+ int n=x.length;
+ if(n == 1) abort("Least squares fit requires at least 2 data points");
+ real sx=sum(w*x);
+ real sy=sum(w*y);
+ real W=sum(w);
+ real sxx=W*sum(w*x^2)-sx^2;
+ real sxy=W*sum(w*x*y)-sx*sy;
+ L.m=sxy/sxx;
+ L.b=(sy-L.m*sx)/W;
+ if(n > 2) {
+ real syy=W*sum(w*y^2)-sy^2;
+ if(sxx == 0 || syy == 0) return L;
+ L.r=sxy/sqrt(sxx*syy);
+ real arg=syy-sxy^2/sxx;
+ if(arg <= 0) return L;
+ real s=sqrt(arg/(n-2));
+ L.dm=s*sqrt(1/sxx);
+ L.db=s*sqrt(1+sx^2/sxx)/W;
+ }
+ return L;
+}
diff --git a/Build/source/utils/asymptote/base/three.asy b/Build/source/utils/asymptote/base/three.asy
index c208f59df84..9dfad6ce798 100644
--- a/Build/source/utils/asymptote/base/three.asy
+++ b/Build/source/utils/asymptote/base/three.asy
@@ -2907,11 +2907,6 @@ object embed(string prefix=outprefix(), string label=prefix,
if((preview || (prc && settings.render == 0)) && settings.embed) {
image=prefix;
if(settings.inlinetex) image += "_0";
- if(!preview && !S.pic2.empty2()) {
- transform T=S.pic2.scaling(S.width,S.height);
- _shipout(image,S.pic2.fit(T),newframe,nativeformat(),false,false);
- }
-
image += "."+nativeformat();
if(!settings.inlinetex) file3.push(image);
image=graphic(image,"hiresbb");
diff --git a/Build/source/utils/asymptote/base/three_surface.asy b/Build/source/utils/asymptote/base/three_surface.asy
index 95f41a61817..16613f3e33e 100644
--- a/Build/source/utils/asymptote/base/three_surface.asy
+++ b/Build/source/utils/asymptote/base/three_surface.asy
@@ -20,7 +20,7 @@ triple coons3(path3 external) {
struct patch {
triple[][] P;
- pen[] colors; // Optionally specify 4 corner colors.
+ pen[] colors; // Optionally specify corner colors.
bool straight; // Patch is based on a piecewise straight external path.
bool3 planar; // Patch is planar.
bool triangular; // Patch is a Bezier triangle.
@@ -1384,7 +1384,8 @@ void draw3D(frame f, patch s, material m,
if(prc() && light.on())
straight=false; // PRC vertex colors (for quads only) ignore lighting
m=material(m);
- m.diffuse(mean(s.colors));
+ if(prc())
+ m.diffuse(mean(s.colors));
}
m=material(m,light,s.colors.length > 0);
@@ -1423,7 +1424,7 @@ void draw(frame f, triple[] v, int[][] vi,
triple[] n={}, int[][] ni={}, material m=currentpen, pen[] p={},
int[][] pi={}, light light=currentlight, render render=defaultrender)
{
- bool normals=n.length > 0;
+ bool normals=ni.length > 0;
if(!normals) {
ni=new int[vi.length][3];
normals=computeNormals(v,vi,n,ni) > 0;
@@ -1431,6 +1432,35 @@ void draw(frame f, triple[] v, int[][] vi,
if(p.length > 0)
m=mean(p);
m=material(m,light);
+
+ if(prc()) {
+ int[] vertexNormal=new int[ni.length];
+ int[] vertexPen=new int[pi.length];
+
+ bool pens=pi.length > 0;
+
+ for(int i=0; i < vi.length; ++i) {
+ int[] vii=vi[i];
+ int[] nii=ni[i];
+ for(int j=0; j < 3; ++j) {
+ int V=vii[j];
+ vertexNormal[V]=nii[j];
+ if(pens)
+ vertexPen[V]=pi[i][j];
+ }
+ }
+
+ for(int i=0; i < vi.length; ++i) {
+ int[] vii=vi[i];
+ for(int j=0; j < 3; ++j) {
+ int V=vii[j];
+ ni[i][j]=vertexNormal[V];
+ if(pens)
+ pi[i][j]=vertexPen[V];
+ }
+ }
+ }
+
draw(f,v,vi,render.interaction.center,n,ni,
m.p,m.opacity,m.shininess,m.metallic,m.fresnel0,p,pi,
render.interaction.type);
@@ -1441,8 +1471,7 @@ void draw(picture pic=currentpicture, triple[] v, int[][] vi,
triple[] n={}, int[][] ni={}, material m=currentpen, pen[] p={},
int[][] pi={}, light light=currentlight, render render=defaultrender)
{
- bool prc=prc();
- bool normals=n.length > 0;
+ bool normals=ni.length > 0;
if(!normals) {
ni=new int[vi.length][3];
normals=computeNormals(v,vi,n,ni) > 0;
diff --git a/Build/source/utils/asymptote/base/v3dheadertypes.asy b/Build/source/utils/asymptote/base/v3dheadertypes.asy
index dba3c18d0b3..653a8ba2d98 100644
--- a/Build/source/utils/asymptote/base/v3dheadertypes.asy
+++ b/Build/source/utils/asymptote/base/v3dheadertypes.asy
@@ -1,6 +1,6 @@
// Enum class for v3dheadertypes
// AUTO-GENERATED from v3dheadertypes.csv
-// Generated at 2022-03-07 12:05:14.285216
+// Generated at 2023-01-23 00:17:44
struct v3dheadertypes
{
diff --git a/Build/source/utils/asymptote/base/v3dtypes.asy b/Build/source/utils/asymptote/base/v3dtypes.asy
index 6de6b31c5c2..c1014888275 100644
--- a/Build/source/utils/asymptote/base/v3dtypes.asy
+++ b/Build/source/utils/asymptote/base/v3dtypes.asy
@@ -1,6 +1,6 @@
// Enum class for v3dtypes
// AUTO-GENERATED from v3dtypes.csv
-// Generated at 2022-03-07 12:05:14.274334
+// Generated at 2023-01-23 00:17:44
struct v3dtypes
{
diff --git a/Build/source/utils/asymptote/base/webgl/asygl.js b/Build/source/utils/asymptote/base/webgl/asygl.js
index f33ee3ef54f..b5f77299a6e 100644
--- a/Build/source/utils/asymptote/base/webgl/asygl.js
+++ b/Build/source/utils/asymptote/base/webgl/asygl.js
@@ -36,4 +36,4 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.*/
-let vertex="\n#ifdef WEBGL2\n#define IN in\n#define OUT out\n#else\n#define IN attribute\n#define OUT varying\n#endif\n\nIN vec3 position;\n#ifdef WIDTH\nIN float width;\n#endif\n#ifdef NORMAL\nIN vec3 normal;\n#endif\n\nIN float materialIndex;\n\n#ifdef WEBGL2\nflat out int MaterialIndex;\n#ifdef COLOR\nOUT vec4 Color;\n#endif\n\n#else\nOUT vec4 diffuse;\nOUT vec3 specular;\nOUT float roughness,metallic,fresnel0;\nOUT vec4 emissive;\n\nstruct Material {\n vec4 diffuse,emissive,specular;\n vec4 parameters;\n};\n\nuniform Material Materials[Nmaterials];\n#endif\n\n#ifdef COLOR\nIN vec4 color;\n#endif\n\nuniform mat3 normMat;\nuniform mat4 viewMat;\nuniform mat4 projViewMat;\n\n#ifdef NORMAL\n#ifndef ORTHOGRAPHIC\nOUT vec3 ViewPosition;\n#endif\nOUT vec3 Normal;\n#endif\n\nvoid main(void)\n{\n vec4 v=vec4(position,1.0);\n gl_Position=projViewMat*v;\n\n#ifdef NORMAL\n#ifndef ORTHOGRAPHIC\n ViewPosition=(viewMat*v).xyz;\n#endif\n Normal=normalize(normal*normMat);\n#endif\n\n#ifdef WEBGL2\n MaterialIndex=int(materialIndex);\n#ifdef COLOR\n Color=color;\n#endif\n#else\n#ifdef NORMAL\n Material m;\n#ifdef TRANSPARENT\n m=Materials[int(abs(materialIndex))-1];\n emissive=m.emissive;\n if(materialIndex >= 0.0)\n diffuse=m.diffuse;\n else {\n diffuse=color;\n#if nlights == 0\n emissive += color;\n#endif\n }\n#else\n m=Materials[int(materialIndex)];\n emissive=m.emissive;\n#ifdef COLOR\n diffuse=color;\n#if nlights == 0\n emissive += color;\n#endif\n#else\n diffuse=m.diffuse;\n#endif // COLOR\n#endif // TRANSPARENT\n specular=m.specular.rgb;\n vec4 parameters=m.parameters;\n roughness=1.0-parameters[0];\n metallic=parameters[1];\n fresnel0=parameters[2];\n#else\n emissive=Materials[int(materialIndex)].emissive;\n#endif // NORMAL\n#endif // WEBGL2\n\n#ifdef WIDTH\n gl_PointSize=width;\n#endif\n}\n",fragment="\n#ifdef WEBGL2\n#define IN in\nout vec4 outValue;\n#define OUTVALUE outValue\n#else\n#define IN varying\n#define OUTVALUE gl_FragColor\n#endif\n\n#ifdef WEBGL2\nflat in int MaterialIndex;\n\nstruct Material {\n vec4 diffuse,emissive,specular;\n vec4 parameters;\n};\n\nuniform Material Materials[Nmaterials];\n\nvec4 diffuse;\nvec3 specular;\nfloat roughness,metallic,fresnel0;\nvec4 emissive;\n\n#ifdef COLOR\nin vec4 Color;\n#endif\n\n#else\nIN vec4 diffuse;\nIN vec3 specular;\nIN float roughness,metallic,fresnel0;\nIN vec4 emissive;\n#endif\n\n#ifdef NORMAL\n\n#ifndef ORTHOGRAPHIC\nIN vec3 ViewPosition;\n#endif\nIN vec3 Normal;\n\nvec3 normal;\n\nstruct Light {\n vec3 direction;\n vec3 color;\n};\n\nuniform Light Lights[Nlights];\n\n#ifdef USE_IBL\nuniform sampler2D reflBRDFSampler;\nuniform sampler2D diffuseSampler;\nuniform sampler2D reflImgSampler;\n\nconst float pi=acos(-1.0);\nconst float piInv=1.0/pi;\nconst float twopi=2.0*pi;\nconst float twopiInv=1.0/twopi;\n\n// (x,y,z) -> (r,theta,phi);\n// theta -> [0,pi]: colatitude\n// phi -> [-pi,pi]: longitude\nvec3 cart2sphere(vec3 cart)\n{\n float x=cart.x;\n float y=cart.z;\n float z=cart.y;\n\n float r=length(cart);\n float theta=r > 0.0 ? acos(z/r) : 0.0;\n float phi=atan(y,x);\n\n return vec3(r,theta,phi);\n}\n\nvec2 normalizedAngle(vec3 cartVec)\n{\n vec3 sphericalVec=cart2sphere(cartVec);\n sphericalVec.y=sphericalVec.y*piInv;\n sphericalVec.z=0.75-sphericalVec.z*twopiInv;\n return sphericalVec.zy;\n}\n\nvec3 IBLColor(vec3 viewDir)\n{\n vec3 IBLDiffuse=diffuse.rgb*texture(diffuseSampler,normalizedAngle(normal)).rgb;\n vec3 reflectVec=normalize(reflect(-viewDir,normal));\n vec2 reflCoord=normalizedAngle(reflectVec);\n vec3 IBLRefl=textureLod(reflImgSampler,reflCoord,roughness*ROUGHNESS_STEP_COUNT).rgb;\n vec2 IBLbrdf=texture(reflBRDFSampler,vec2(dot(normal,viewDir),roughness)).rg;\n float specularMultiplier=fresnel0*IBLbrdf.x+IBLbrdf.y;\n vec3 dielectric=IBLDiffuse+specularMultiplier*IBLRefl;\n vec3 metal=diffuse.rgb*IBLRefl;\n return mix(dielectric,metal,metallic);\n}\n#else\nfloat Roughness2;\nfloat NDF_TRG(vec3 h)\n{\n float ndoth=max(dot(normal,h),0.0);\n float alpha2=Roughness2*Roughness2;\n float denom=ndoth*ndoth*(alpha2-1.0)+1.0;\n return denom != 0.0 ? alpha2/(denom*denom) : 0.0;\n}\n\nfloat GGX_Geom(vec3 v)\n{\n float ndotv=max(dot(v,normal),0.0);\n float ap=1.0+Roughness2;\n float k=0.125*ap*ap;\n return ndotv/((ndotv*(1.0-k))+k);\n}\n\nfloat Geom(vec3 v, vec3 l)\n{\n return GGX_Geom(v)*GGX_Geom(l);\n}\n\nfloat Fresnel(vec3 h, vec3 v, float fresnel0)\n{\n float a=1.0-max(dot(h,v),0.0);\n float b=a*a;\n return fresnel0+(1.0-fresnel0)*b*b*a;\n}\n\n// physical based shading using UE4 model.\nvec3 BRDF(vec3 viewDirection, vec3 lightDirection)\n{\n vec3 lambertian=diffuse.rgb;\n vec3 h=normalize(lightDirection+viewDirection);\n\n float omegain=max(dot(viewDirection,normal),0.0);\n float omegaln=max(dot(lightDirection,normal),0.0);\n\n float D=NDF_TRG(h);\n float G=Geom(viewDirection,lightDirection);\n float F=Fresnel(h,viewDirection,fresnel0);\n\n float denom=4.0*omegain*omegaln;\n float rawReflectance=denom > 0.0 ? (D*G)/denom : 0.0;\n\n vec3 dielectric=mix(lambertian,rawReflectance*specular,F);\n vec3 metal=rawReflectance*diffuse.rgb;\n\n return mix(dielectric,metal,metallic);\n}\n#endif\n\n#endif\n\nvoid main(void)\n{\n#ifdef WEBGL2\n#ifdef NORMAL\n Material m;\n#ifdef TRANSPARENT\n m=Materials[abs(MaterialIndex)-1];\n emissive=m.emissive;\n if(MaterialIndex >= 0)\n diffuse=m.diffuse;\n else {\n diffuse=Color;\n#if nlights == 0\n emissive += Color;\n#endif\n }\n#else\n m=Materials[MaterialIndex];\n emissive=m.emissive;\n#ifdef COLOR\n diffuse=Color;\n#if nlights == 0\n emissive += Color;\n#endif\n#else\n diffuse=m.diffuse;\n#endif // COLOR\n#endif // TRANSPARENT\n specular=m.specular.rgb;\n vec4 parameters=m.parameters;\n roughness=1.0-parameters[0];\n metallic=parameters[1];\n fresnel0=parameters[2];\n#else\n emissive=Materials[MaterialIndex].emissive;\n#endif // NORMAL\n#endif // WEBGL2\n\n#if defined(NORMAL) && nlights > 0\n normal=normalize(Normal);\n normal=gl_FrontFacing ? normal : -normal;\n#ifdef ORTHOGRAPHIC\n vec3 viewDir=vec3(0.0,0.0,1.0);\n#else\n vec3 viewDir=-normalize(ViewPosition);\n#endif\n\nvec3 color;\n#ifdef USE_IBL\n color=IBLColor(viewDir);\n#else\n Roughness2=roughness*roughness;\n color=emissive.rgb;\n for(int i=0; i < nlights; ++i) {\n Light Li=Lights[i];\n vec3 L=Li.direction;\n float cosTheta=max(dot(normal,L),0.0);\n vec3 radiance=cosTheta*Li.color;\n color += BRDF(viewDir,L)*radiance;\n }\n#endif\n OUTVALUE=vec4(color,diffuse.a);\n#else\n OUTVALUE=emissive;\n#endif\n}\n";!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var i=t();for(var a in i)("object"==typeof exports?exports:e)[a]=i[a]}}("undefined"!=typeof self?self:this,(function(){return function(e){var t={};function i(a){if(t[a])return t[a].exports;var n=t[a]={i:a,l:!1,exports:{}};return e[a].call(n.exports,n,n.exports,i),n.l=!0,n.exports}return i.m=e,i.c=t,i.d=function(e,t,a){i.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:a})},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="",i(i.s=1)}([function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.setMatrixArrayType=function(e){t.ARRAY_TYPE=e},t.toRadian=function(e){return e*n},t.equals=function(e,t){return Math.abs(e-t)<=a*Math.max(1,Math.abs(e),Math.abs(t))};var a=t.EPSILON=1e-6;t.ARRAY_TYPE="undefined"!=typeof Float32Array?Float32Array:Array,t.RANDOM=Math.random;var n=Math.PI/180},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.mat4=t.mat3=void 0;var a=r(i(2)),n=r(i(3));function r(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t.default=e,t}t.mat3=a,t.mat4=n},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.create=function(){var e=new a.ARRAY_TYPE(9);return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=1,e[5]=0,e[6]=0,e[7]=0,e[8]=1,e},t.fromMat4=function(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[4],e[4]=t[5],e[5]=t[6],e[6]=t[8],e[7]=t[9],e[8]=t[10],e},t.invert=function(e,t){var i=t[0],a=t[1],n=t[2],r=t[3],s=t[4],o=t[5],l=t[6],h=t[7],c=t[8],d=c*s-o*h,m=-c*r+o*l,f=h*r-s*l,u=i*d+a*m+n*f;if(!u)return null;return u=1/u,e[0]=d*u,e[1]=(-c*a+n*h)*u,e[2]=(o*a-n*s)*u,e[3]=m*u,e[4]=(c*i-n*l)*u,e[5]=(-o*i+n*r)*u,e[6]=f*u,e[7]=(-h*i+a*l)*u,e[8]=(s*i-a*r)*u,e};var a=function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t.default=e,t}(i(0))},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.create=function(){var e=new a.ARRAY_TYPE(16);return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e},t.identity=function(e){return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e},t.invert=function(e,t){var i=t[0],a=t[1],n=t[2],r=t[3],s=t[4],o=t[5],l=t[6],h=t[7],c=t[8],d=t[9],m=t[10],f=t[11],u=t[12],p=t[13],g=t[14],v=t[15],x=i*o-a*s,w=i*l-n*s,M=i*h-r*s,b=a*l-n*o,T=a*h-r*o,S=n*h-r*l,R=c*p-d*u,A=c*g-m*u,I=c*v-f*u,P=d*g-m*p,E=d*v-f*p,y=m*v-f*g,L=x*y-w*E+M*P+b*I-T*A+S*R;if(!L)return null;return L=1/L,e[0]=(o*y-l*E+h*P)*L,e[1]=(n*E-a*y-r*P)*L,e[2]=(p*S-g*T+v*b)*L,e[3]=(m*T-d*S-f*b)*L,e[4]=(l*I-s*y-h*A)*L,e[5]=(i*y-n*I+r*A)*L,e[6]=(g*M-u*S-v*w)*L,e[7]=(c*S-m*M+f*w)*L,e[8]=(s*E-o*I+h*R)*L,e[9]=(a*I-i*E-r*R)*L,e[10]=(u*T-p*M+v*x)*L,e[11]=(d*M-c*T-f*x)*L,e[12]=(o*A-s*P-l*R)*L,e[13]=(i*P-a*A+n*R)*L,e[14]=(p*w-u*b-g*x)*L,e[15]=(c*b-d*w+m*x)*L,e},t.multiply=n,t.translate=function(e,t,i){var a=i[0],n=i[1],r=i[2],s=void 0,o=void 0,l=void 0,h=void 0,c=void 0,d=void 0,m=void 0,f=void 0,u=void 0,p=void 0,g=void 0,v=void 0;t===e?(e[12]=t[0]*a+t[4]*n+t[8]*r+t[12],e[13]=t[1]*a+t[5]*n+t[9]*r+t[13],e[14]=t[2]*a+t[6]*n+t[10]*r+t[14],e[15]=t[3]*a+t[7]*n+t[11]*r+t[15]):(s=t[0],o=t[1],l=t[2],h=t[3],c=t[4],d=t[5],m=t[6],f=t[7],u=t[8],p=t[9],g=t[10],v=t[11],e[0]=s,e[1]=o,e[2]=l,e[3]=h,e[4]=c,e[5]=d,e[6]=m,e[7]=f,e[8]=u,e[9]=p,e[10]=g,e[11]=v,e[12]=s*a+c*n+u*r+t[12],e[13]=o*a+d*n+p*r+t[13],e[14]=l*a+m*n+g*r+t[14],e[15]=h*a+f*n+v*r+t[15]);return e},t.rotate=function(e,t,i,n){var r,s,o,l,h,c,d,m,f,u,p,g,v,x,w,M,b,T,S,R,A,I,P,E,y=n[0],L=n[1],D=n[2],O=Math.sqrt(y*y+L*L+D*D);if(Math.abs(O)<a.EPSILON)return null;y*=O=1/O,L*=O,D*=O,r=Math.sin(i),s=Math.cos(i),o=1-s,l=t[0],h=t[1],c=t[2],d=t[3],m=t[4],f=t[5],u=t[6],p=t[7],g=t[8],v=t[9],x=t[10],w=t[11],M=y*y*o+s,b=L*y*o+D*r,T=D*y*o-L*r,S=y*L*o-D*r,R=L*L*o+s,A=D*L*o+y*r,I=y*D*o+L*r,P=L*D*o-y*r,E=D*D*o+s,e[0]=l*M+m*b+g*T,e[1]=h*M+f*b+v*T,e[2]=c*M+u*b+x*T,e[3]=d*M+p*b+w*T,e[4]=l*S+m*R+g*A,e[5]=h*S+f*R+v*A,e[6]=c*S+u*R+x*A,e[7]=d*S+p*R+w*A,e[8]=l*I+m*P+g*E,e[9]=h*I+f*P+v*E,e[10]=c*I+u*P+x*E,e[11]=d*I+p*P+w*E,t!==e&&(e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]);return e},t.fromTranslation=function(e,t){return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=t[0],e[13]=t[1],e[14]=t[2],e[15]=1,e},t.fromRotation=function(e,t,i){var n,r,s,o=i[0],l=i[1],h=i[2],c=Math.sqrt(o*o+l*l+h*h);if(Math.abs(c)<a.EPSILON)return null;return o*=c=1/c,l*=c,h*=c,n=Math.sin(t),r=Math.cos(t),s=1-r,e[0]=o*o*s+r,e[1]=l*o*s+h*n,e[2]=h*o*s-l*n,e[3]=0,e[4]=o*l*s-h*n,e[5]=l*l*s+r,e[6]=h*l*s+o*n,e[7]=0,e[8]=o*h*s+l*n,e[9]=l*h*s-o*n,e[10]=h*h*s+r,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e},t.frustum=function(e,t,i,a,n,r,s){var o=1/(i-t),l=1/(n-a),h=1/(r-s);return e[0]=2*r*o,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=2*r*l,e[6]=0,e[7]=0,e[8]=(i+t)*o,e[9]=(n+a)*l,e[10]=(s+r)*h,e[11]=-1,e[12]=0,e[13]=0,e[14]=s*r*2*h,e[15]=0,e},t.ortho=function(e,t,i,a,n,r,s){var o=1/(t-i),l=1/(a-n),h=1/(r-s);return e[0]=-2*o,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=-2*l,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=2*h,e[11]=0,e[12]=(t+i)*o,e[13]=(n+a)*l,e[14]=(s+r)*h,e[15]=1,e};var a=function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t.default=e,t}(i(0));function n(e,t,i){var a=t[0],n=t[1],r=t[2],s=t[3],o=t[4],l=t[5],h=t[6],c=t[7],d=t[8],m=t[9],f=t[10],u=t[11],p=t[12],g=t[13],v=t[14],x=t[15],w=i[0],M=i[1],b=i[2],T=i[3];return e[0]=w*a+M*o+b*d+T*p,e[1]=w*n+M*l+b*m+T*g,e[2]=w*r+M*h+b*f+T*v,e[3]=w*s+M*c+b*u+T*x,w=i[4],M=i[5],b=i[6],T=i[7],e[4]=w*a+M*o+b*d+T*p,e[5]=w*n+M*l+b*m+T*g,e[6]=w*r+M*h+b*f+T*v,e[7]=w*s+M*c+b*u+T*x,w=i[8],M=i[9],b=i[10],T=i[11],e[8]=w*a+M*o+b*d+T*p,e[9]=w*n+M*l+b*m+T*g,e[10]=w*r+M*h+b*f+T*v,e[11]=w*s+M*c+b*u+T*x,w=i[12],M=i[13],b=i[14],T=i[15],e[12]=w*a+M*o+b*d+T*p,e[13]=w*n+M*l+b*m+T*g,e[14]=w*r+M*h+b*f+T*v,e[15]=w*s+M*c+b*u+T*x,e}}])}));let Transform,canvasWidth,canvasHeight,imageURL,image,minBound,maxBound,orthographic,angleOfView,initialZoom,viewportMargin,zoomFactor,zoomPinchFactor,zoomPinchCap,zoomStep,shiftHoldDistance,shiftWaitTime,vibrateTime,canvasWidth0,canvasHeight0,zoom0,embedded,canvas,gl,alpha,offscreen,context,maxMaterials,halfCanvasWidth,halfCanvasHeight,P=[],Materials=[],Lights=[],Centers=[],Background=[1,1,1,1],absolute=!1,ibl=!1,viewportShift=[0,0],webgl2=!1,nlights=0,Nmaterials=2,materials=[];const pixelResolution=.75,zoomRemeshFactor=1.5,FillFactor=.1,windowTrim=10,third=1/3,pi=Math.acos(-1),radians=pi/180;let Zoom,lastZoom,xshift,yshift,maxViewportWidth,maxViewportHeight,H,zmin,zmax,size2,ArcballFactor,rotMat=mat4.create(),projMat=mat4.create(),viewMat=mat4.create(),projViewMat=mat4.create(),normMat=mat3.create(),viewMat3=mat3.create(),cjMatInv=mat4.create(),Temp=mat4.create(),center={x:0,y:0,z:0},shift={x:0,y:0},viewParam={xmin:0,xmax:0,ymin:0,ymax:0,zmin:0,zmax:0},remesh=!0,wireframe=0,mouseDownOrTouchActive=!1,lastMouseX=null,lastMouseY=null,touchID=null,Positions=[],Normals=[],Colors=[],Indices=[],IBLReflMap=null,IBLDiffuseMap=null,IBLbdrfMap=null;function IBLReady(){return null!==IBLReflMap&&null!==IBLDiffuseMap&&null!==IBLbdrfMap}function SetIBL(){embedded||deleteShaders(),initShaders(ibl)}let roughnessStepCount=8;class Material{constructor(e,t,i,a,n,r){this.diffuse=e,this.emissive=t,this.specular=i,this.shininess=a,this.metallic=n,this.fresnel0=r}setUniform(e,t){let i=i=>gl.getUniformLocation(e,"Materials["+t+"]."+i);gl.uniform4fv(i("diffuse"),new Float32Array(this.diffuse)),gl.uniform4fv(i("emissive"),new Float32Array(this.emissive)),gl.uniform4fv(i("specular"),new Float32Array(this.specular)),gl.uniform4f(i("parameters"),this.shininess,this.metallic,this.fresnel0,0)}}let indexExt,TRIANGLES,material0Data,material1Data,materialData,colorData,transparentData,triangleData,materialIndex,enumPointLight=1,enumDirectionalLight=2;class Light{constructor(e,t){this.direction=e,this.color=t}setUniform(e,t){let i=i=>gl.getUniformLocation(e,"Lights["+t+"]."+i);gl.uniform3fv(i("direction"),new Float32Array(this.direction)),gl.uniform3fv(i("color"),new Float32Array(this.color))}}function initShaders(e=!1){let t=gl.getParameter(gl.MAX_VERTEX_UNIFORM_VECTORS);maxMaterials=Math.floor((t-14)/4),Nmaterials=Math.min(Math.max(Nmaterials,Materials.length),maxMaterials),pixelOpt=["WIDTH"],materialOpt=["NORMAL"],colorOpt=["NORMAL","COLOR"],transparentOpt=["NORMAL","COLOR","TRANSPARENT"],e&&(materialOpt.push("USE_IBL"),transparentOpt.push("USE_IBL")),pixelShader=initShader(pixelOpt),materialShader=initShader(materialOpt),colorShader=initShader(colorOpt),transparentShader=initShader(transparentOpt)}function deleteShaders(){gl.deleteProgram(transparentShader),gl.deleteProgram(colorShader),gl.deleteProgram(materialShader),gl.deleteProgram(pixelShader)}function saveAttributes(){let e=webgl2?window.top.document.asygl2[alpha]:window.top.document.asygl[alpha];e.gl=gl,e.nlights=Lights.length,e.Nmaterials=Nmaterials,e.maxMaterials=maxMaterials,e.pixelShader=pixelShader,e.materialShader=materialShader,e.colorShader=colorShader,e.transparentShader=transparentShader}function restoreAttributes(){let e=webgl2?window.top.document.asygl2[alpha]:window.top.document.asygl[alpha];gl=e.gl,nlights=e.nlights,Nmaterials=e.Nmaterials,maxMaterials=e.maxMaterials,pixelShader=e.pixelShader,materialShader=e.materialShader,colorShader=e.colorShader,transparentShader=e.transparentShader}function webGL(e,t){let i;return webgl2&&(i=e.getContext("webgl2",{alpha:t}),embedded&&!i)?(webgl2=!1,ibl=!1,initGL(!1),null):(i||(webgl2=!1,ibl=!1,i=e.getContext("webgl",{alpha:t})),i||alert("Could not initialize WebGL"),i)}function initGL(e=!0){if(ibl&&(webgl2=!0),alpha=Background[3]<1,embedded){let t=window.top.document;if(e&&(context=canvas.getContext("2d")),offscreen=webgl2?t.offscreen2:t.offscreen,offscreen||(offscreen=t.createElement("canvas"),webgl2?t.offscreen2=offscreen:t.offscreen=offscreen),webgl2?t.asygl2||(t.asygl2=Array(2)):t.asygl||(t.asygl=Array(2)),asygl=webgl2?t.asygl2:t.asygl,asygl[alpha]&&asygl[alpha].gl)restoreAttributes(),(Lights.length!=nlights||Math.min(Materials.length,maxMaterials)>Nmaterials)&&(initShaders(),saveAttributes());else{if(rc=webGL(offscreen,alpha),!rc)return;gl=rc,initShaders(),webgl2?t.asygl2[alpha]={}:t.asygl[alpha]={},saveAttributes()}}else gl=webGL(canvas,alpha),initShaders();indexExt=gl.getExtension("OES_element_index_uint"),TRIANGLES=gl.TRIANGLES,material0Data=new vertexBuffer(gl.POINTS),material1Data=new vertexBuffer(gl.LINES),materialData=new vertexBuffer,colorData=new vertexBuffer,transparentData=new vertexBuffer,triangleData=new vertexBuffer}function getShader(e,t,i,a=[]){let n=webgl2?"300 es":"100",r=Array(...a),s=[["nlights",0==wireframe?Lights.length:0],["Nmaterials",Nmaterials]],o=[["int","Nlights",Math.max(Lights.length,1)]];webgl2&&r.push("WEBGL2"),ibl&&s.push(["ROUGHNESS_STEP_COUNT",roughnessStepCount.toFixed(2)]),orthographic&&r.push("ORTHOGRAPHIC"),macros_str=s.map(e=>`#define ${e[0]} ${e[1]}`).join("\n"),define_str=r.map(e=>"#define "+e).join("\n"),const_str=o.map(e=>`const ${e[0]} ${e[1]}=${e[2]};`).join("\n"),ext_str=[].map(e=>`#extension ${e}: enable`).join("\n"),shaderSrc=`#version ${n}\n${ext_str}\n${define_str}\n${const_str}\n${macros_str}\n\n\n#ifdef GL_FRAGMENT_PRECISION_HIGH\nprecision highp float;\n#else\nprecision mediump float;\n#endif\n \n${t}\n `;let l=e.createShader(i);return e.shaderSource(l,shaderSrc),e.compileShader(l),e.getShaderParameter(l,e.COMPILE_STATUS)?l:(alert(e.getShaderInfoLog(l)),null)}function registerBuffer(e,t,i,a=gl.ARRAY_BUFFER){return e.length>0&&(0==t&&(t=gl.createBuffer(),i=!0),gl.bindBuffer(a,t),i&&gl.bufferData(a,e,gl.STATIC_DRAW)),t}function drawBuffer(e,t,i=e.indices){if(0==e.indices.length)return;let a=t!=pixelShader;setUniforms(e,t),null!=IBLDiffuseMap&&(gl.activeTexture(gl.TEXTURE0),gl.bindTexture(gl.TEXTURE_2D,IBLbdrfMap),gl.uniform1i(gl.getUniformLocation(t,"reflBRDFSampler"),0),gl.activeTexture(gl.TEXTURE1),gl.bindTexture(gl.TEXTURE_2D,IBLDiffuseMap),gl.uniform1i(gl.getUniformLocation(t,"diffuseSampler"),1),gl.activeTexture(gl.TEXTURE2),gl.bindTexture(gl.TEXTURE_2D,IBLReflMap),gl.uniform1i(gl.getUniformLocation(t,"reflImgSampler"),2));let n=remesh||e.partial||!e.rendered;e.verticesBuffer=registerBuffer(new Float32Array(e.vertices),e.verticesBuffer,n),gl.vertexAttribPointer(positionAttribute,3,gl.FLOAT,!1,a?24:16,0),a?Lights.length>0&&gl.vertexAttribPointer(normalAttribute,3,gl.FLOAT,!1,24,12):gl.vertexAttribPointer(widthAttribute,1,gl.FLOAT,!1,16,12),e.materialsBuffer=registerBuffer(new Int16Array(e.materialIndices),e.materialsBuffer,n),gl.vertexAttribPointer(materialAttribute,1,gl.SHORT,!1,2,0),t!=colorShader&&t!=transparentShader||(e.colorsBuffer=registerBuffer(new Uint8Array(e.colors),e.colorsBuffer,n),gl.vertexAttribPointer(colorAttribute,4,gl.UNSIGNED_BYTE,!0,0,0)),e.indicesBuffer=registerBuffer(indexExt?new Uint32Array(i):new Uint16Array(i),e.indicesBuffer,n,gl.ELEMENT_ARRAY_BUFFER),e.rendered=!0,gl.drawElements(a?wireframe?gl.LINES:e.type:gl.POINTS,i.length,indexExt?gl.UNSIGNED_INT:gl.UNSIGNED_SHORT,0)}class vertexBuffer{constructor(e){this.type=e||TRIANGLES,this.verticesBuffer=0,this.materialsBuffer=0,this.colorsBuffer=0,this.indicesBuffer=0,this.rendered=!1,this.partial=!1,this.clear()}clear(){this.vertices=[],this.materialIndices=[],this.colors=[],this.indices=[],this.nvertices=0,this.materials=[],this.materialTable=[]}vertex(e,t){return this.vertices.push(e[0]),this.vertices.push(e[1]),this.vertices.push(e[2]),this.vertices.push(t[0]),this.vertices.push(t[1]),this.vertices.push(t[2]),this.materialIndices.push(materialIndex),this.nvertices++}Vertex(e,t,i=[0,0,0,0]){return this.vertices.push(e[0]),this.vertices.push(e[1]),this.vertices.push(e[2]),this.vertices.push(t[0]),this.vertices.push(t[1]),this.vertices.push(t[2]),this.materialIndices.push(materialIndex),this.colors.push(i[0]),this.colors.push(i[1]),this.colors.push(i[2]),this.colors.push(i[3]),this.nvertices++}vertex0(e,t){return this.vertices.push(e[0]),this.vertices.push(e[1]),this.vertices.push(e[2]),this.vertices.push(t),this.materialIndices.push(materialIndex),this.nvertices++}iVertex(e,t,i,a=[0,0,0,0]){let n=6*e;this.vertices[n]=t[0],this.vertices[n+1]=t[1],this.vertices[n+2]=t[2],this.vertices[n+3]=i[0],this.vertices[n+4]=i[1],this.vertices[n+5]=i[2],this.materialIndices[e]=materialIndex;let r=4*e;this.colors[r]=a[0],this.colors[r+1]=a[1],this.colors[r+2]=a[2],this.colors[r+3]=a[3],this.indices.push(e)}append(e){append(this.vertices,e.vertices),append(this.materialIndices,e.materialIndices),append(this.colors,e.colors),appendOffset(this.indices,e.indices,this.nvertices),this.nvertices+=e.nvertices}}function append(e,t){let i=e.length,a=t.length;e.length+=a;for(let n=0;n<a;++n)e[i+n]=t[n]}function appendOffset(e,t,i){let a=e.length,n=t.length;e.length+=t.length;for(let r=0;r<n;++r)e[a+r]=t[r]+i}class Geometry{constructor(){this.data=new vertexBuffer,this.Onscreen=!1,this.m=[]}offscreen(e){let t=projViewMat,i=e[0],a=i[0],n=i[1],r=i[2],s=1/(t[3]*a+t[7]*n+t[11]*r+t[15]);this.x=this.X=(t[0]*a+t[4]*n+t[8]*r+t[12])*s,this.y=this.Y=(t[1]*a+t[5]*n+t[9]*r+t[13])*s;for(let i=1,a=e.length;i<a;++i){let a=e[i],n=a[0],r=a[1],s=a[2],o=1/(t[3]*n+t[7]*r+t[11]*s+t[15]),l=(t[0]*n+t[4]*r+t[8]*s+t[12])*o,h=(t[1]*n+t[5]*r+t[9]*s+t[13])*o;l<this.x?this.x=l:l>this.X&&(this.X=l),h<this.y?this.y=h:h>this.Y&&(this.Y=h)}return(this.X<-1.01||this.x>1.01||this.Y<-1.01||this.y>1.01)&&(this.Onscreen=!1,!0)}T(e){let t=this.c[0],i=this.c[1],a=this.c[2],n=e[0]-t,r=e[1]-i,s=e[2]-a;return[n*normMat[0]+r*normMat[3]+s*normMat[6]+t,n*normMat[1]+r*normMat[4]+s*normMat[7]+i,n*normMat[2]+r*normMat[5]+s*normMat[8]+a]}Tcorners(e,t){return[this.T(e),this.T([e[0],e[1],t[2]]),this.T([e[0],t[1],e[2]]),this.T([e[0],t[1],t[2]]),this.T([t[0],e[1],e[2]]),this.T([t[0],e[1],t[2]]),this.T([t[0],t[1],e[2]]),this.T(t)]}setMaterial(e,t){null==e.materialTable[this.MaterialIndex]&&(e.materials.length>=Nmaterials&&(e.partial=!0,t()),e.materialTable[this.MaterialIndex]=e.materials.length,e.materials.push(Materials[this.MaterialIndex])),materialIndex=e.materialTable[this.MaterialIndex]}render(){let e;if(this.setMaterialIndex(),0==this.CenterIndex?e=corners(this.Min,this.Max):(this.c=Centers[this.CenterIndex-1],e=this.Tcorners(this.Min,this.Max)),this.offscreen(e))return this.data.clear(),void this.notRendered();let t,i=this.controlpoints;if(0==this.CenterIndex){if(!remesh&&this.Onscreen)return void this.append();t=i}else{let e=i.length;t=Array(e);for(let a=0;a<e;++a)t[a]=this.T(i[a])}let a=orthographic?1:this.Min[2]/maxBound[2],n=.75*Math.hypot(a*(viewParam.xmax-viewParam.xmin),a*(viewParam.ymax-viewParam.ymin))/size2;this.res2=n*n,this.Epsilon=.1*n,this.data.clear(),this.notRendered(),this.Onscreen=!0,this.process(t)}}class BezierPatch extends Geometry{constructor(e,t,i,a,n,r){super(),this.controlpoints=e,this.CenterIndex=t,this.MaterialIndex=i,this.Min=a,this.Max=n,this.color=r;let s=e.length;if(r){let e=r[0][3]+r[1][3]+r[2][3];this.transparent=16==s||4==s?e+r[3][3]<1020:e<765}else this.transparent=Materials[i].diffuse[3]<1;this.vertex=this.transparent?this.data.Vertex.bind(this.data):this.data.vertex.bind(this.data),this.L2norm(this.controlpoints)}setMaterialIndex(){this.transparent?this.setMaterial(transparentData,drawTransparent):this.color?this.setMaterial(colorData,drawColor):this.setMaterial(materialData,drawMaterial)}L2norm(e){let t=e[0];this.epsilon=0;let i=e.length;for(let a=1;a<i;++a)this.epsilon=Math.max(this.epsilon,abs2([e[a][0]-t[0],e[a][1]-t[1],e[a][2]-t[2]]));this.epsilon*=Number.EPSILON}processTriangle(e){let t=e[0],i=e[1],a=e[2],n=unit(cross([i[0]-t[0],i[1]-t[1],i[2]-t[2]],[a[0]-t[0],a[1]-t[1],a[2]-t[2]]));if(!this.offscreen([t,i,a])){let e,r,s;this.color?(e=this.data.Vertex(t,n,this.color[0]),r=this.data.Vertex(i,n,this.color[1]),s=this.data.Vertex(a,n,this.color[2])):(e=this.vertex(t,n),r=this.vertex(i,n),s=this.vertex(a,n)),0==wireframe?(this.data.indices.push(e),this.data.indices.push(r),this.data.indices.push(s)):(this.data.indices.push(e),this.data.indices.push(r),this.data.indices.push(r),this.data.indices.push(s),this.data.indices.push(s),this.data.indices.push(e)),this.append()}}processQuad(e){let t=e[0],i=e[1],a=e[2],n=e[3],r=cross([i[0]-t[0],i[1]-t[1],i[2]-t[2]],[a[0]-i[0],a[1]-i[1],a[2]-i[2]]),s=cross([a[0]-n[0],a[1]-n[1],a[2]-n[2]],[n[0]-t[0],n[1]-t[1],n[2]-t[2]]),o=unit([r[0]+s[0],r[1]+s[1],r[2]+s[2]]);if(!this.offscreen([t,i,a,n])){let e,r,s,l;this.color?(e=this.data.Vertex(t,o,this.color[0]),r=this.data.Vertex(i,o,this.color[1]),s=this.data.Vertex(a,o,this.color[2]),l=this.data.Vertex(n,o,this.color[3])):(e=this.vertex(t,o),r=this.vertex(i,o),s=this.vertex(a,o),l=this.vertex(n,o)),0==wireframe?(this.data.indices.push(e),this.data.indices.push(r),this.data.indices.push(s),this.data.indices.push(e),this.data.indices.push(s),this.data.indices.push(l)):(this.data.indices.push(e),this.data.indices.push(r),this.data.indices.push(r),this.data.indices.push(s),this.data.indices.push(s),this.data.indices.push(l),this.data.indices.push(l),this.data.indices.push(e)),this.append()}}curve(e,t,i,a,n){new BezierCurve([e[t],e[i],e[a],e[n]],0,materialIndex,this.Min,this.Max).render()}process(e){if(this.transparent&&1!=wireframe&&(materialIndex=this.color?-1-materialIndex:1+materialIndex),10==e.length)return this.process3(e);if(3==e.length)return this.processTriangle(e);if(4==e.length)return this.processQuad(e);if(1==wireframe)return this.curve(e,0,4,8,12),this.curve(e,12,13,14,15),this.curve(e,15,11,7,3),void this.curve(e,3,2,1,0);let t=e[0],i=e[3],a=e[12],n=e[15],r=this.normal(i,e[2],e[1],t,e[4],e[8],a);abs2(r)<this.epsilon&&(r=this.normal(i,e[2],e[1],t,e[13],e[14],n),abs2(r)<this.epsilon&&(r=this.normal(n,e[11],e[7],i,e[4],e[8],a)));let s=this.normal(t,e[4],e[8],a,e[13],e[14],n);abs2(s)<this.epsilon&&(s=this.normal(t,e[4],e[8],a,e[11],e[7],i),abs2(s)<this.epsilon&&(s=this.normal(i,e[2],e[1],t,e[13],e[14],n)));let o=this.normal(a,e[13],e[14],n,e[11],e[7],i);abs2(o)<this.epsilon&&(o=this.normal(a,e[13],e[14],n,e[2],e[1],t),abs2(o)<this.epsilon&&(o=this.normal(t,e[4],e[8],a,e[11],e[7],i)));let l=this.normal(n,e[11],e[7],i,e[2],e[1],t);if(abs2(l)<this.epsilon&&(l=this.normal(n,e[11],e[7],i,e[4],e[8],a),abs2(l)<this.epsilon&&(l=this.normal(a,e[13],e[14],n,e[2],e[1],t))),this.color){let h=this.color[0],c=this.color[1],d=this.color[2],m=this.color[3],f=this.data.Vertex(t,r,h),u=this.data.Vertex(a,s,c),p=this.data.Vertex(n,o,d),g=this.data.Vertex(i,l,m);this.Render(e,f,u,p,g,t,a,n,i,!1,!1,!1,!1,h,c,d,m)}else{let h=this.vertex(t,r),c=this.vertex(a,s),d=this.vertex(n,o),m=this.vertex(i,l);this.Render(e,h,c,d,m,t,a,n,i,!1,!1,!1,!1)}this.data.indices.length>0&&this.append()}append(){this.transparent?transparentData.append(this.data):this.color?colorData.append(this.data):materialData.append(this.data)}notRendered(){this.transparent?transparentData.rendered=!1:this.color?colorData.rendered=!1:materialData.rendered=!1}Render(e,t,i,a,n,r,s,o,l,h,c,d,m,f,u,p,g){let v=this.Distance(e);if(v[0]<this.res2&&v[1]<this.res2)this.offscreen([r,s,o])||(0==wireframe?(this.data.indices.push(t),this.data.indices.push(i),this.data.indices.push(a)):(this.data.indices.push(t),this.data.indices.push(i),this.data.indices.push(i),this.data.indices.push(a))),this.offscreen([r,o,l])||(0==wireframe?(this.data.indices.push(t),this.data.indices.push(a),this.data.indices.push(n)):(this.data.indices.push(a),this.data.indices.push(n),this.data.indices.push(n),this.data.indices.push(t)));else{if(this.offscreen(e))return;let x=e[0],w=e[3],M=e[12],b=e[15];if(v[0]<this.res2){let v=new Split3(x,e[1],e[2],w),T=new Split3(e[4],e[5],e[6],e[7]),S=new Split3(e[8],e[9],e[10],e[11]),R=new Split3(M,e[13],e[14],b),A=[x,v.m0,v.m3,v.m5,e[4],T.m0,T.m3,T.m5,e[8],S.m0,S.m3,S.m5,M,R.m0,R.m3,R.m5],I=[v.m5,v.m4,v.m2,w,T.m5,T.m4,T.m2,e[7],S.m5,S.m4,S.m2,e[11],R.m5,R.m4,R.m2,b],P=this.normal(A[12],A[13],A[14],A[15],A[11],A[7],A[3]);abs2(P)<=this.epsilon&&(P=this.normal(A[12],A[13],A[14],A[15],A[2],A[1],A[0]),abs2(P)<=this.epsilon&&(P=this.normal(A[0],A[4],A[8],A[12],A[11],A[7],A[3])));let E=this.normal(I[3],I[2],I[1],I[0],I[4],I[8],I[12]);abs2(E)<=this.epsilon&&(E=this.normal(I[3],I[2],I[1],I[0],I[13],I[14],I[15]),abs2(E)<=this.epsilon&&(E=this.normal(I[15],I[11],I[7],I[3],I[4],I[8],I[12])));let y=this.Epsilon,L=[.5*(s[0]+o[0]),.5*(s[1]+o[1]),.5*(s[2]+o[2])];if(!c)if(c=Straightness(M,e[13],e[14],b)<this.res2){let e=unit(this.differential(I[12],I[8],I[4],I[0]));L=[L[0]-y*e[0],L[1]-y*e[1],L[2]-y*e[2]]}else L=A[15];let D=[.5*(l[0]+r[0]),.5*(l[1]+r[1]),.5*(l[2]+r[2])];if(!m)if(m=Straightness(x,e[1],e[2],w)<this.res2){let e=unit(this.differential(A[3],A[7],A[11],A[15]));D=[D[0]-y*e[0],D[1]-y*e[1],D[2]-y*e[2]]}else D=I[0];if(f){let e=Array(4),v=Array(4);for(let t=0;t<4;++t)e[t]=.5*(u[t]+p[t]),v[t]=.5*(g[t]+f[t]);let x=this.data.Vertex(L,P,e),w=this.data.Vertex(D,E,v);this.Render(A,t,i,x,w,r,s,L,D,h,c,!1,m,f,u,e,v),this.Render(I,w,x,a,n,D,L,o,l,!1,c,d,m,v,e,p,g)}else{let e=this.vertex(L,P),f=this.vertex(D,E);this.Render(A,t,i,e,f,r,s,L,D,h,c,!1,m),this.Render(I,f,e,a,n,D,L,o,l,!1,c,d,m)}return}if(v[1]<this.res2){let v=new Split3(x,e[4],e[8],M),T=new Split3(e[1],e[5],e[9],e[13]),S=new Split3(e[2],e[6],e[10],e[14]),R=new Split3(w,e[7],e[11],b),A=[x,e[1],e[2],w,v.m0,T.m0,S.m0,R.m0,v.m3,T.m3,S.m3,R.m3,v.m5,T.m5,S.m5,R.m5],I=[v.m5,T.m5,S.m5,R.m5,v.m4,T.m4,S.m4,R.m4,v.m2,T.m2,S.m2,R.m2,M,e[13],e[14],b],P=this.normal(A[0],A[4],A[8],A[12],A[13],A[14],A[15]);abs2(P)<=this.epsilon&&(P=this.normal(A[0],A[4],A[8],A[12],A[11],A[7],A[3]),abs2(P)<=this.epsilon&&(P=this.normal(A[3],A[2],A[1],A[0],A[13],A[14],A[15])));let E=this.normal(I[15],I[11],I[7],I[3],I[2],I[1],I[0]);abs2(E)<=this.epsilon&&(E=this.normal(I[15],I[11],I[7],I[3],I[4],I[8],I[12]),abs2(E)<=this.epsilon&&(E=this.normal(I[12],I[13],I[14],I[15],I[2],I[1],I[0])));let y=this.Epsilon,L=[.5*(r[0]+s[0]),.5*(r[1]+s[1]),.5*(r[2]+s[2])];if(!h)if(h=Straightness(x,e[4],e[8],M)<this.res2){let e=unit(this.differential(I[0],I[1],I[2],I[3]));L=[L[0]-y*e[0],L[1]-y*e[1],L[2]-y*e[2]]}else L=A[12];let D=[.5*(o[0]+l[0]),.5*(o[1]+l[1]),.5*(o[2]+l[2])];if(!d)if(d=Straightness(b,e[11],e[7],w)<this.res2){let e=unit(this.differential(A[15],A[14],A[13],A[12]));D=[D[0]-y*e[0],D[1]-y*e[1],D[2]-y*e[2]]}else D=I[3];if(f){let e=Array(4),v=Array(4);for(let t=0;t<4;++t)e[t]=.5*(f[t]+u[t]),v[t]=.5*(p[t]+g[t]);let x=this.data.Vertex(L,P,e),w=this.data.Vertex(D,E,v);this.Render(A,t,x,w,n,r,L,D,l,h,!1,d,m,f,e,v,g),this.Render(I,x,i,a,w,L,s,o,D,h,c,d,!1,e,u,p,v)}else{let e=this.vertex(L,P),f=this.vertex(D,E);this.Render(A,t,e,f,n,r,L,D,l,h,!1,d,m),this.Render(I,e,i,a,f,L,s,o,D,h,c,d,!1)}return}let T=new Split3(x,e[1],e[2],w),S=new Split3(e[4],e[5],e[6],e[7]),R=new Split3(e[8],e[9],e[10],e[11]),A=new Split3(M,e[13],e[14],b),I=new Split3(x,e[4],e[8],M),P=new Split3(T.m0,S.m0,R.m0,A.m0),E=new Split3(T.m3,S.m3,R.m3,A.m3),y=new Split3(T.m5,S.m5,R.m5,A.m5),L=new Split3(T.m4,S.m4,R.m4,A.m4),D=new Split3(T.m2,S.m2,R.m2,A.m2),O=new Split3(w,e[7],e[11],b),B=[x,T.m0,T.m3,T.m5,I.m0,P.m0,E.m0,y.m0,I.m3,P.m3,E.m3,y.m3,I.m5,P.m5,E.m5,y.m5],N=[I.m5,P.m5,E.m5,y.m5,I.m4,P.m4,E.m4,y.m4,I.m2,P.m2,E.m2,y.m2,M,A.m0,A.m3,A.m5],z=[y.m5,L.m5,D.m5,O.m5,y.m4,L.m4,D.m4,O.m4,y.m2,L.m2,D.m2,O.m2,A.m5,A.m4,A.m2,b],_=[T.m5,T.m4,T.m2,w,y.m0,L.m0,D.m0,O.m0,y.m3,L.m3,D.m3,O.m3,y.m5,L.m5,D.m5,O.m5],C=B[15],V=this.normal(B[0],B[4],B[8],B[12],B[13],B[14],B[15]);abs2(V)<this.epsilon&&(V=this.normal(B[0],B[4],B[8],B[12],B[11],B[7],B[3]),abs2(V)<this.epsilon&&(V=this.normal(B[3],B[2],B[1],B[0],B[13],B[14],B[15])));let U=this.normal(N[12],N[13],N[14],N[15],N[11],N[7],N[3]);abs2(U)<this.epsilon&&(U=this.normal(N[12],N[13],N[14],N[15],N[2],N[1],N[0]),abs2(U)<this.epsilon&&(U=this.normal(N[0],N[4],N[8],N[12],N[11],N[7],N[3])));let H=this.normal(z[15],z[11],z[7],z[3],z[2],z[1],z[0]);abs2(H)<this.epsilon&&(H=this.normal(z[15],z[11],z[7],z[3],z[4],z[8],z[12]),abs2(H)<this.epsilon&&(H=this.normal(z[12],z[13],z[14],z[15],z[2],z[1],z[0])));let G=this.normal(_[3],_[2],_[1],_[0],_[4],_[8],_[12]);abs2(G)<this.epsilon&&(G=this.normal(_[3],_[2],_[1],_[0],_[13],_[14],_[15]),abs2(G)<this.epsilon&&(G=this.normal(_[15],_[11],_[7],_[3],_[4],_[8],_[12])));let F=this.normal(z[3],z[2],z[1],C,z[4],z[8],z[12]),W=this.Epsilon,X=[.5*(r[0]+s[0]),.5*(r[1]+s[1]),.5*(r[2]+s[2])];if(!h)if(h=Straightness(x,e[4],e[8],M)<this.res2){let e=unit(this.differential(N[0],N[1],N[2],N[3]));X=[X[0]-W*e[0],X[1]-W*e[1],X[2]-W*e[2]]}else X=B[12];let j=[.5*(s[0]+o[0]),.5*(s[1]+o[1]),.5*(s[2]+o[2])];if(!c)if(c=Straightness(M,e[13],e[14],b)<this.res2){let e=unit(this.differential(z[12],z[8],z[4],z[0]));j=[j[0]-W*e[0],j[1]-W*e[1],j[2]-W*e[2]]}else j=N[15];let Z=[.5*(o[0]+l[0]),.5*(o[1]+l[1]),.5*(o[2]+l[2])];if(!d)if(d=Straightness(b,e[11],e[7],w)<this.res2){let e=unit(this.differential(_[15],_[14],_[13],_[12]));Z=[Z[0]-W*e[0],Z[1]-W*e[1],Z[2]-W*e[2]]}else Z=z[3];let k=[.5*(l[0]+r[0]),.5*(l[1]+r[1]),.5*(l[2]+r[2])];if(!m)if(m=Straightness(x,e[1],e[2],w)<this.res2){let e=unit(this.differential(B[3],B[7],B[11],B[15]));k=[k[0]-W*e[0],k[1]-W*e[1],k[2]-W*e[2]]}else k=_[0];if(f){let e=Array(4),v=Array(4),x=Array(4),w=Array(4),M=Array(4);for(let t=0;t<4;++t)e[t]=.5*(f[t]+u[t]),v[t]=.5*(u[t]+p[t]),x[t]=.5*(p[t]+g[t]),w[t]=.5*(g[t]+f[t]),M[t]=.5*(e[t]+x[t]);let b=this.data.Vertex(X,V,e),T=this.data.Vertex(j,U,v),S=this.data.Vertex(Z,H,x),R=this.data.Vertex(k,G,w),A=this.data.Vertex(C,F,M);this.Render(B,t,b,A,R,r,X,C,k,h,!1,!1,m,f,e,M,w),this.Render(N,b,i,T,A,X,s,j,C,h,c,!1,!1,e,u,v,M),this.Render(z,A,T,a,S,C,j,o,Z,!1,c,d,!1,M,v,p,x),this.Render(_,R,A,S,n,k,C,Z,l,!1,!1,d,m,w,M,x,g)}else{let e=this.vertex(X,V),f=this.vertex(j,U),u=this.vertex(Z,H),p=this.vertex(k,G),g=this.vertex(C,F);this.Render(B,t,e,g,p,r,X,C,k,h,!1,!1,m),this.Render(N,e,i,f,g,X,s,j,C,h,c,!1,!1),this.Render(z,g,f,a,u,C,j,o,Z,!1,c,d,!1),this.Render(_,p,g,u,n,k,C,Z,l,!1,!1,d,m)}}}process3(e){if(1==wireframe)return this.curve(e,0,1,3,6),this.curve(e,6,7,8,9),void this.curve(e,9,5,2,0);let t=e[0],i=e[6],a=e[9],n=this.normal(a,e[5],e[2],t,e[1],e[3],i),r=this.normal(t,e[1],e[3],i,e[7],e[8],a),s=this.normal(i,e[7],e[8],a,e[5],e[2],t);if(this.color){let o=this.color[0],l=this.color[1],h=this.color[2],c=this.data.Vertex(t,n,o),d=this.data.Vertex(i,r,l),m=this.data.Vertex(a,s,h);this.Render3(e,c,d,m,t,i,a,!1,!1,!1,o,l,h)}else{let o=this.vertex(t,n),l=this.vertex(i,r),h=this.vertex(a,s);this.Render3(e,o,l,h,t,i,a,!1,!1,!1)}this.data.indices.length>0&&this.append()}Render3(e,t,i,a,n,r,s,o,l,h,c,d,m){if(this.Distance3(e)<this.res2)this.offscreen([n,r,s])||(0==wireframe?(this.data.indices.push(t),this.data.indices.push(i),this.data.indices.push(a)):(this.data.indices.push(t),this.data.indices.push(i),this.data.indices.push(i),this.data.indices.push(a),this.data.indices.push(a),this.data.indices.push(t)));else{if(this.offscreen(e))return;let f=e[0],u=e[1],p=e[2],g=e[3],v=e[4],x=e[5],w=e[6],M=e[7],b=e[8],T=e[9],S=[.5*(T[0]+x[0]),.5*(T[1]+x[1]),.5*(T[2]+x[2])],R=[.5*(T[0]+b[0]),.5*(T[1]+b[1]),.5*(T[2]+b[2])],A=[.5*(x[0]+p[0]),.5*(x[1]+p[1]),.5*(x[2]+p[2])],I=[.5*(b[0]+v[0]),.5*(b[1]+v[1]),.5*(b[2]+v[2])],P=[.5*(b[0]+M[0]),.5*(b[1]+M[1]),.5*(b[2]+M[2])],E=[.5*(p[0]+v[0]),.5*(p[1]+v[1]),.5*(p[2]+v[2])],y=[.5*(p[0]+f[0]),.5*(p[1]+f[1]),.5*(p[2]+f[2])],L=[.5*(v[0]+g[0]),.5*(v[1]+g[1]),.5*(v[2]+g[2])],D=[.5*(M[0]+w[0]),.5*(M[1]+w[1]),.5*(M[2]+w[2])],O=[.5*(f[0]+u[0]),.5*(f[1]+u[1]),.5*(f[2]+u[2])],B=[.5*(u[0]+g[0]),.5*(u[1]+g[1]),.5*(u[2]+g[2])],N=[.5*(g[0]+w[0]),.5*(g[1]+w[1]),.5*(g[2]+w[2])],z=[.5*(S[0]+A[0]),.5*(S[1]+A[1]),.5*(S[2]+A[2])],_=[.5*(R[0]+P[0]),.5*(R[1]+P[1]),.5*(R[2]+P[2])],C=[.5*(A[0]+y[0]),.5*(A[1]+y[1]),.5*(A[2]+y[2])],V=[.5*I[0]+.25*(v[0]+u[0]),.5*I[1]+.25*(v[1]+u[1]),.5*I[2]+.25*(v[2]+u[2])],U=[.5*(P[0]+D[0]),.5*(P[1]+D[1]),.5*(P[2]+D[2])],H=[.5*E[0]+.25*(v[0]+M[0]),.5*E[1]+.25*(v[1]+M[1]),.5*E[2]+.25*(v[2]+M[2])],G=[.25*(x[0]+v[0])+.5*L[0],.25*(x[1]+v[1])+.5*L[1],.25*(x[2]+v[2])+.5*L[2]],F=[.5*(O[0]+B[0]),.5*(O[1]+B[1]),.5*(O[2]+B[2])],W=[.5*(B[0]+N[0]),.5*(B[1]+N[1]),.5*(B[2]+N[2])],X=[.5*(H[0]+F[0]),.5*(H[1]+F[1]),.5*(H[2]+F[2])],j=[.5*(H[0]+W[0]),.5*(H[1]+W[1]),.5*(H[2]+W[2])],Z=[.5*(F[0]+W[0]),.5*(F[1]+W[1]),.5*(F[2]+W[2])],k=[.5*(G[0]+U[0]),.5*(G[1]+U[1]),.5*(G[2]+U[2])],Y=[.5*(_[0]+G[0]),.5*(_[1]+G[1]),.5*(_[2]+G[2])],q=[.5*(_[0]+U[0]),.5*(_[1]+U[1]),.5*(_[2]+U[2])],$=[.5*(z[0]+V[0]),.5*(z[1]+V[1]),.5*(z[2]+V[2])],K=[.5*(C[0]+V[0]),.5*(C[1]+V[1]),.5*(C[2]+V[2])],Q=[.5*(z[0]+C[0]),.5*(z[1]+C[1]),.5*(z[2]+C[2])],J=[f,O,y,F,[.5*(E[0]+O[0]),.5*(E[1]+O[1]),.5*(E[2]+O[2])],C,Z,X,K,Q],ee=[Z,W,j,N,[.5*(L[0]+D[0]),.5*(L[1]+D[1]),.5*(L[2]+D[2])],k,w,D,U,q],te=[Q,$,z,Y,[.5*(S[0]+I[0]),.5*(S[1]+I[1]),.5*(S[2]+I[2])],S,q,_,R,T],ie=[q,Y,k,$,[.25*(A[0]+P[0]+B[0]+v[0]),.25*(A[1]+P[1]+B[1]+v[1]),.25*(A[2]+P[2]+B[2]+v[2])],j,Q,K,X,Z],ae=this.normal(Z,j,k,q,Y,$,Q),ne=this.normal(q,Y,$,Q,K,X,Z),re=this.normal(Q,K,X,Z,j,k,q),se=this.Epsilon,oe=[.5*(r[0]+s[0]),.5*(r[1]+s[1]),.5*(r[2]+s[2])];if(!o)if(o=Straightness(w,M,b,T)<this.res2){let e=unit(this.sumdifferential(ie[0],ie[2],ie[5],ie[9],ie[1],ie[3],ie[6]));oe=[oe[0]-se*e[0],oe[1]-se*e[1],oe[2]-se*e[2]]}else oe=q;let le=[.5*(s[0]+n[0]),.5*(s[1]+n[1]),.5*(s[2]+n[2])];if(!l)if(l=Straightness(f,p,x,T)<this.res2){let e=unit(this.sumdifferential(ie[6],ie[3],ie[1],ie[0],ie[7],ie[8],ie[9]));le=[le[0]-se*e[0],le[1]-se*e[1],le[2]-se*e[2]]}else le=Q;let he=[.5*(n[0]+r[0]),.5*(n[1]+r[1]),.5*(n[2]+r[2])];if(!h)if(h=Straightness(f,u,g,w)<this.res2){let e=unit(this.sumdifferential(ie[9],ie[8],ie[7],ie[6],ie[5],ie[2],ie[0]));he=[he[0]-se*e[0],he[1]-se*e[1],he[2]-se*e[2]]}else he=Z;if(c){let e=Array(4),f=Array(4),u=Array(4);for(let t=0;t<4;++t)e[t]=.5*(d[t]+m[t]),f[t]=.5*(m[t]+c[t]),u[t]=.5*(c[t]+d[t]);let p=this.data.Vertex(oe,ae,e),g=this.data.Vertex(le,ne,f),v=this.data.Vertex(he,re,u);this.Render3(J,t,v,g,n,he,le,!1,l,h,c,u,f),this.Render3(ee,v,i,p,he,r,oe,o,!1,h,u,d,e),this.Render3(te,g,p,a,le,oe,s,o,l,!1,f,e,m),this.Render3(ie,p,g,v,oe,le,he,!1,!1,!1,e,f,u)}else{let e=this.vertex(oe,ae),c=this.vertex(le,ne),d=this.vertex(he,re);this.Render3(J,t,d,c,n,he,le,!1,l,h),this.Render3(ee,d,i,e,he,r,oe,o,!1,h),this.Render3(te,c,e,a,le,oe,s,o,l,!1),this.Render3(ie,e,c,d,oe,le,he,!1,!1,!1)}}}Distance(e){let t=e[0],i=e[3],a=e[12],n=e[15],r=Flatness(t,a,i,n);r=Math.max(Straightness(t,e[4],e[8],a)),r=Math.max(r,Straightness(e[1],e[5],e[9],e[13])),r=Math.max(r,Straightness(i,e[7],e[11],n)),r=Math.max(r,Straightness(e[2],e[6],e[10],e[14]));let s=Flatness(t,i,a,n);return s=Math.max(s,Straightness(t,e[1],e[2],i)),s=Math.max(s,Straightness(e[4],e[5],e[6],e[7])),s=Math.max(s,Straightness(e[8],e[9],e[10],e[11])),s=Math.max(s,Straightness(a,e[13],e[14],n)),[r,s]}Distance3(e){let t=e[0],i=e[4],a=e[6],n=e[9],r=abs2([(t[0]+a[0]+n[0])*(1/3)-i[0],(t[1]+a[1]+n[1])*(1/3)-i[1],(t[2]+a[2]+n[2])*(1/3)-i[2]]);return r=Math.max(r,Straightness(t,e[1],e[3],a)),r=Math.max(r,Straightness(t,e[2],e[5],n)),Math.max(r,Straightness(a,e[7],e[8],n))}differential(e,t,i,a){let n=[3*(t[0]-e[0]),3*(t[1]-e[1]),3*(t[2]-e[2])];return abs2(n)>this.epsilon?n:(n=bezierPP(e,t,i),abs2(n)>this.epsilon?n:bezierPPP(e,t,i,a))}sumdifferential(e,t,i,a,n,r,s){let o=this.differential(e,t,i,a),l=this.differential(e,n,r,s);return[o[0]+l[0],o[1]+l[1],o[2]+l[2]]}normal(e,t,i,a,n,r,s){let o=3*(n[0]-a[0]),l=3*(n[1]-a[1]),h=3*(n[2]-a[2]),c=3*(i[0]-a[0]),d=3*(i[1]-a[1]),m=3*(i[2]-a[2]),f=[l*m-h*d,h*c-o*m,o*d-l*c];if(abs2(f)>this.epsilon)return f;let u=[c,d,m],p=[o,l,h],g=bezierPP(a,i,t),v=bezierPP(a,n,r),x=cross(v,u),w=cross(p,g);if(f=[x[0]+w[0],x[1]+w[1],x[2]+w[2]],abs2(f)>this.epsilon)return f;let M=bezierPPP(a,i,t,e),b=bezierPPP(a,n,r,s);x=cross(p,M),w=cross(b,u);let T=cross(v,g);return f=[x[0]+w[0]+T[0],x[1]+w[1]+T[1],x[2]+w[2]+T[2]],abs2(f)>this.epsilon?f:(x=cross(b,g),w=cross(v,M),f=[x[0]+w[0],x[1]+w[1],x[2]+w[2]],abs2(f)>this.epsilon?f:cross(b,M))}}class BezierCurve extends Geometry{constructor(e,t,i,a,n){super(),this.controlpoints=e,this.CenterIndex=t,this.MaterialIndex=i,this.Min=a,this.Max=n}setMaterialIndex(){this.setMaterial(material1Data,drawMaterial1)}processLine(e){let t=e[0],i=e[1];if(!this.offscreen([t,i])){let e=[0,0,1];this.data.indices.push(this.data.vertex(t,e)),this.data.indices.push(this.data.vertex(i,e)),this.append()}}process(e){if(2==e.length)return this.processLine(e);let t=e[0],i=e[1],a=e[2],n=e[3],r=this.normal(bezierP(t,i),bezierPP(t,i,a)),s=this.normal(bezierP(a,n),bezierPP(n,a,i)),o=this.data.vertex(t,r),l=this.data.vertex(n,s);this.Render(e,o,l),this.data.indices.length>0&&this.append()}append(){material1Data.append(this.data)}notRendered(){material1Data.rendered=!1}Render(e,t,i){let a=e[0],n=e[1],r=e[2],s=e[3];if(Straightness(a,n,r,s)<this.res2)this.offscreen([a,s])||(this.data.indices.push(t),this.data.indices.push(i));else{if(this.offscreen(e))return;let o=[.5*(a[0]+n[0]),.5*(a[1]+n[1]),.5*(a[2]+n[2])],l=[.5*(n[0]+r[0]),.5*(n[1]+r[1]),.5*(n[2]+r[2])],h=[.5*(r[0]+s[0]),.5*(r[1]+s[1]),.5*(r[2]+s[2])],c=[.5*(o[0]+l[0]),.5*(o[1]+l[1]),.5*(o[2]+l[2])],d=[.5*(l[0]+h[0]),.5*(l[1]+h[1]),.5*(l[2]+h[2])],m=[.5*(c[0]+d[0]),.5*(c[1]+d[1]),.5*(c[2]+d[2])],f=[a,o,c,m],u=[m,d,h,s],p=this.normal(bezierPh(a,n,r,s),bezierPPh(a,n,r,s)),g=this.data.vertex(m,p);this.Render(f,t,g),this.Render(u,g,i)}}normal(e,t){let i=dot(e,e),a=dot(e,t);return[i*t[0]-a*e[0],i*t[1]-a*e[1],i*t[2]-a*e[2]]}}class Pixel extends Geometry{constructor(e,t,i,a,n){super(),this.controlpoint=e,this.width=t,this.CenterIndex=0,this.MaterialIndex=i,this.Min=a,this.Max=n}setMaterialIndex(){this.setMaterial(material0Data,drawMaterial0)}process(e){this.data.indices.push(this.data.vertex0(this.controlpoint,this.width)),this.append()}append(){material0Data.append(this.data)}notRendered(){material0Data.rendered=!1}}class Triangles extends Geometry{constructor(e,t,i,a){super(),this.CenterIndex=e,this.MaterialIndex=t,this.Min=i,this.Max=a,this.controlpoints=Positions,this.Normals=Normals,this.Colors=Colors,this.Indices=Indices,Positions=[],Normals=[],Colors=[],Indices=[],this.transparent=Materials[this.MaterialIndex].diffuse[3]<1}setMaterialIndex(){this.transparent?this.setMaterial(transparentData,drawTransparent):this.setMaterial(triangleData,drawTriangle)}process(e){this.data.vertices=new Array(6*e.length),materialIndex=this.Colors.length>0?-1-materialIndex:1+materialIndex;for(let t=0,i=this.Indices.length;t<i;++t){let i=this.Indices[t],a=i[0],n=e[a[0]],r=e[a[1]],s=e[a[2]];if(!this.offscreen([n,r,s])){let e=i.length>1?i[1]:a;if(e&&0!=e.length||(e=a),this.Colors.length>0){let t=i.length>2?i[2]:a;t&&0!=t.length||(t=a);let o=this.Colors[t[0]],l=this.Colors[t[1]],h=this.Colors[t[2]];this.transparent|=o[3]+l[3]+h[3]<765,0==wireframe?(this.data.iVertex(a[0],n,this.Normals[e[0]],o),this.data.iVertex(a[1],r,this.Normals[e[1]],l),this.data.iVertex(a[2],s,this.Normals[e[2]],h)):(this.data.iVertex(a[0],n,this.Normals[e[0]],o),this.data.iVertex(a[1],r,this.Normals[e[1]],l),this.data.iVertex(a[1],r,this.Normals[e[1]],l),this.data.iVertex(a[2],s,this.Normals[e[2]],h),this.data.iVertex(a[2],s,this.Normals[e[2]],h),this.data.iVertex(a[0],n,this.Normals[e[0]],o))}else 0==wireframe?(this.data.iVertex(a[0],n,this.Normals[e[0]]),this.data.iVertex(a[1],r,this.Normals[e[1]]),this.data.iVertex(a[2],s,this.Normals[e[2]])):(this.data.iVertex(a[0],n,this.Normals[e[0]]),this.data.iVertex(a[1],r,this.Normals[e[1]]),this.data.iVertex(a[1],r,this.Normals[e[1]]),this.data.iVertex(a[2],s,this.Normals[e[2]]),this.data.iVertex(a[2],s,this.Normals[e[2]]),this.data.iVertex(a[0],n,this.Normals[e[0]]))}}this.data.nvertices=e.length,this.data.indices.length>0&&this.append()}append(){this.transparent?transparentData.append(this.data):triangleData.append(this.data)}notRendered(){this.transparent?transparentData.rendered=!1:triangleData.rendered=!1}}function redrawScene(){initProjection(),setProjection(),remesh=!0,drawScene()}function home(){mat4.identity(rotMat),redrawScene(),window.top.asyWebApplication&&window.top.asyWebApplication.setProjection(""),window.parent.asyProjection=!1}let positionAttribute=0,normalAttribute=1,materialAttribute=2,colorAttribute=3,widthAttribute=4;function initShader(e=[]){let t=getShader(gl,vertex,gl.VERTEX_SHADER,e),i=getShader(gl,fragment,gl.FRAGMENT_SHADER,e),a=gl.createProgram();return gl.attachShader(a,t),gl.attachShader(a,i),gl.bindAttribLocation(a,positionAttribute,"position"),gl.bindAttribLocation(a,normalAttribute,"normal"),gl.bindAttribLocation(a,materialAttribute,"materialIndex"),gl.bindAttribLocation(a,colorAttribute,"color"),gl.bindAttribLocation(a,widthAttribute,"width"),gl.linkProgram(a),gl.getProgramParameter(a,gl.LINK_STATUS)||alert("Could not initialize shaders"),a}class Split3{constructor(e,t,i,a){this.m0=[.5*(e[0]+t[0]),.5*(e[1]+t[1]),.5*(e[2]+t[2])];let n=.5*(t[0]+i[0]),r=.5*(t[1]+i[1]),s=.5*(t[2]+i[2]);this.m2=[.5*(i[0]+a[0]),.5*(i[1]+a[1]),.5*(i[2]+a[2])],this.m3=[.5*(this.m0[0]+n),.5*(this.m0[1]+r),.5*(this.m0[2]+s)],this.m4=[.5*(n+this.m2[0]),.5*(r+this.m2[1]),.5*(s+this.m2[2])],this.m5=[.5*(this.m3[0]+this.m4[0]),.5*(this.m3[1]+this.m4[1]),.5*(this.m3[2]+this.m4[2])]}}function unit(e){let t=1/(Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2])||1);return[e[0]*t,e[1]*t,e[2]*t]}function abs2(e){return e[0]*e[0]+e[1]*e[1]+e[2]*e[2]}function dot(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function cross(e,t){return[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]]}function bezierP(e,t){return[t[0]-e[0],t[1]-e[1],t[2]-e[2]]}function bezierPP(e,t,i){return[3*(e[0]+i[0])-6*t[0],3*(e[1]+i[1])-6*t[1],3*(e[2]+i[2])-6*t[2]]}function bezierPPP(e,t,i,a){return[a[0]-e[0]+3*(t[0]-i[0]),a[1]-e[1]+3*(t[1]-i[1]),a[2]-e[2]+3*(t[2]-i[2])]}function bezierPh(e,t,i,a){return[i[0]+a[0]-e[0]-t[0],i[1]+a[1]-e[1]-t[1],i[2]+a[2]-e[2]-t[2]]}function bezierPPh(e,t,i,a){return[3*e[0]-5*t[0]+i[0]+a[0],3*e[1]-5*t[1]+i[1]+a[1],3*e[2]-5*t[2]+i[2]+a[2]]}function Straightness(e,t,i,a){let n=[1/3*(a[0]-e[0]),1/3*(a[1]-e[1]),1/3*(a[2]-e[2])];return Math.max(abs2([t[0]-n[0]-e[0],t[1]-n[1]-e[1],t[2]-n[2]-e[2]]),abs2([a[0]-n[0]-i[0],a[1]-n[1]-i[1],a[2]-n[2]-i[2]]))}function Flatness(e,t,i,a){let n=[t[0]-e[0],t[1]-e[1],t[2]-e[2]],r=[a[0]-i[0],a[1]-i[1],a[2]-i[2]];return Math.max(abs2(cross(n,unit(r))),abs2(cross(r,unit(n))))/9}function corners(e,t){return[e,[e[0],e[1],t[2]],[e[0],t[1],e[2]],[e[0],t[1],t[2]],[t[0],e[1],e[2]],[t[0],e[1],t[2]],[t[0],t[1],e[2]],t]}function minbound(e){return[Math.min(e[0][0],e[1][0],e[2][0],e[3][0],e[4][0],e[5][0],e[6][0],e[7][0]),Math.min(e[0][1],e[1][1],e[2][1],e[3][1],e[4][1],e[5][1],e[6][1],e[7][1]),Math.min(e[0][2],e[1][2],e[2][2],e[3][2],e[4][2],e[5][2],e[6][2],e[7][2])]}function maxbound(e){return[Math.max(e[0][0],e[1][0],e[2][0],e[3][0],e[4][0],e[5][0],e[6][0],e[7][0]),Math.max(e[0][1],e[1][1],e[2][1],e[3][1],e[4][1],e[5][1],e[6][1],e[7][1]),Math.max(e[0][2],e[1][2],e[2][2],e[3][2],e[4][2],e[5][2],e[6][2],e[7][2])]}function COBTarget(e,t){mat4.fromTranslation(Temp,[center.x,center.y,center.z]),mat4.invert(cjMatInv,Temp),mat4.multiply(e,t,cjMatInv),mat4.multiply(e,Temp,e)}function setUniforms(e,t){let i=t==pixelShader;gl.useProgram(t),gl.enableVertexAttribArray(positionAttribute),i&&gl.enableVertexAttribArray(widthAttribute);let a=!i&&Lights.length>0;if(a&&gl.enableVertexAttribArray(normalAttribute),gl.enableVertexAttribArray(materialAttribute),t.projViewMatUniform=gl.getUniformLocation(t,"projViewMat"),t.viewMatUniform=gl.getUniformLocation(t,"viewMat"),t.normMatUniform=gl.getUniformLocation(t,"normMat"),t!=colorShader&&t!=transparentShader||gl.enableVertexAttribArray(colorAttribute),a)for(let e=0;e<Lights.length;++e)Lights[e].setUniform(t,e);for(let i=0;i<e.materials.length;++i)e.materials[i].setUniform(t,i);gl.uniformMatrix4fv(t.projViewMatUniform,!1,projViewMat),gl.uniformMatrix4fv(t.viewMatUniform,!1,viewMat),gl.uniformMatrix3fv(t.normMatUniform,!1,normMat)}function handleMouseDown(e){zoomEnabled||enableZoom(),mouseDownOrTouchActive=!0,lastMouseX=e.clientX,lastMouseY=e.clientY}let pinchStart,touchStartTime,pinch=!1;function pinchDistance(e){return Math.hypot(e[0].pageX-e[1].pageX,e[0].pageY-e[1].pageY)}function handleTouchStart(e){e.preventDefault(),zoomEnabled||enableZoom();let t=e.targetTouches;swipe=rotate=pinch=!1,zooming||(1!=t.length||mouseDownOrTouchActive||(touchStartTime=(new Date).getTime(),touchId=t[0].identifier,lastMouseX=t[0].pageX,lastMouseY=t[0].pageY),2!=t.length||mouseDownOrTouchActive||(touchId=t[0].identifier,pinchStart=pinchDistance(t),pinch=!0))}function handleMouseUpOrTouchEnd(e){mouseDownOrTouchActive=!1}function rotateScene(e,t,i,a,n){if(e==i&&t==a)return;let[r,s]=arcball([e,-t],[i,-a]);mat4.fromRotation(Temp,2*n*ArcballFactor*r/Zoom,s),mat4.multiply(rotMat,Temp,rotMat)}function shiftScene(e,t,i,a){let n=1/Zoom;shift.x+=(i-e)*n*halfCanvasWidth,shift.y-=(a-t)*n*halfCanvasHeight}function panScene(e,t,i,a){orthographic?shiftScene(e,t,i,a):(center.x+=(i-e)*(viewParam.xmax-viewParam.xmin),center.y-=(a-t)*(viewParam.ymax-viewParam.ymin))}function updateViewMatrix(){COBTarget(viewMat,rotMat),mat4.translate(viewMat,viewMat,[center.x,center.y,0]),mat3.fromMat4(viewMat3,viewMat),mat3.invert(normMat,viewMat3),mat4.multiply(projViewMat,projMat,viewMat)}function capzoom(){let e=Math.sqrt(Number.MAX_VALUE),t=1/e;Zoom<=t&&(Zoom=t),Zoom>=e&&(Zoom=e),(1.5*Zoom<lastZoom||Zoom>1.5*lastZoom)&&(remesh=!0,lastZoom=Zoom)}function zoomImage(e){let t=zoomStep*halfCanvasHeight*e;const i=Math.log(.1*Number.MAX_VALUE)/Math.log(zoomFactor);Math.abs(t)<i&&(Zoom*=zoomFactor**t,capzoom())}function normMouse(e){let t=e[0],i=e[1],a=Math.hypot(t,i);return a>1&&(denom=1/a,t*=denom,i*=denom),[t,i,Math.sqrt(Math.max(1-i*i-t*t,0))]}function arcball(e,t){let i=normMouse(e),a=normMouse(t),n=dot(i,a);return[n>1?0:n<-1?pi:Math.acos(n),unit(cross(i,a))]}function zoomScene(e,t,i,a){zoomImage(t-a)}const DRAGMODE_ROTATE=1,DRAGMODE_SHIFT=2,DRAGMODE_ZOOM=3,DRAGMODE_PAN=4;function processDrag(e,t,i,a=1){let n;switch(i){case 1:n=rotateScene;break;case 2:n=shiftScene;break;case 3:n=zoomScene;break;case 4:n=panScene;break;default:n=(e,t,i,a)=>{}}n((lastMouseX-halfCanvasWidth)/halfCanvasWidth,(lastMouseY-halfCanvasHeight)/halfCanvasHeight,(e-halfCanvasWidth)/halfCanvasWidth,(t-halfCanvasHeight)/halfCanvasHeight,a),lastMouseX=e,lastMouseY=t,setProjection(),drawScene()}let zoomEnabled=0;function enableZoom(){zoomEnabled=1,canvas.addEventListener("wheel",handleMouseWheel,!1)}function disableZoom(){zoomEnabled=0,canvas.removeEventListener("wheel",handleMouseWheel,!1)}function Camera(){let e=Array(3),t=Array(3),i=Array(3),a=center.x,n=center.y,r=.5*(viewParam.zmin+viewParam.zmax);for(let s=0;s<3;++s){let o=0,l=0,h=0,c=4*s;for(let e=0;e<4;++e){let t=4*e,i=rotMat[t],s=rotMat[t+1],d=rotMat[t+2],m=rotMat[t+3],f=Transform[c+e];o+=f*(m-a*i-n*s-r*d),h+=f*s,l+=f*(m-a*i-n*s)}e[s]=o,t[s]=h,i[s]=l}return[e,t,i]}function projection(){if(null==Transform)return"";let e,t,i;[e,t,i]=Camera();let a=orthographic?" orthographic(":" perspective(",n="".padStart(a.length),r="currentprojection=\n"+a+"camera=("+e+"),\n"+n+"up=("+t+"),\n"+n+"target=("+i+"),\n"+n+"zoom="+Zoom*initialZoom/zoom0;return orthographic||(r+=",\n"+n+"angle="+2*Math.atan(Math.tan(.5*angleOfView)/Zoom)/radians),0==xshift&&0==yshift||(r+=",\n"+n+"viewportshift=("+xshift+","+yshift+")"),orthographic||(r+=",\n"+n+"autoadjust=false"),r+=");\n",window.parent.asyProjection=!0,r}function handleKey(e){if(zoomEnabled||enableZoom(),embedded&&zoomEnabled&&27==e.keyCode)return void disableZoom();let t=[];switch(e.key){case"x":t=[1,0,0];break;case"y":t=[0,1,0];break;case"z":t=[0,0,1];break;case"h":home();break;case"m":++wireframe,3==wireframe&&(wireframe=0),2!=wireframe&&(embedded||deleteShaders(),initShaders(ibl)),remesh=!0,drawScene();break;case"+":case"=":case">":expand();break;case"-":case"_":case"<":shrink();break;case"c":showCamera()}t.length>0&&(mat4.rotate(rotMat,rotMat,.1,t),updateViewMatrix(),drawScene())}function setZoom(){capzoom(),setProjection(),drawScene()}function handleMouseWheel(e){e.preventDefault(),e.deltaY<0?Zoom*=zoomFactor:Zoom/=zoomFactor,setZoom()}function handleMouseMove(e){if(!mouseDownOrTouchActive)return;let t,i=e.clientX,a=e.clientY;t=e.getModifierState("Control")?2:e.getModifierState("Shift")?3:e.getModifierState("Alt")?4:1,processDrag(i,a,t)}let zooming=!1,swipe=!1,rotate=!1;function handleTouchMove(e){if(e.preventDefault(),zooming)return;let t=e.targetTouches;if(!pinch&&1==t.length&&touchId==t[0].identifier){let e=t[0].pageX,i=t[0].pageY,a=e-lastMouseX,n=i-lastMouseY,r=a*a+n*n<=shiftHoldDistance*shiftHoldDistance;if(r&&!swipe&&!rotate&&(new Date).getTime()-touchStartTime>shiftWaitTime&&(navigator.vibrate&&window.navigator.vibrate(vibrateTime),swipe=!0),swipe)processDrag(e,i,2);else if(!r){rotate=!0,processDrag(t[0].pageX,t[0].pageY,1,.5)}}if(pinch&&!swipe&&2==t.length&&touchId==t[0].identifier){let e=pinchDistance(t),i=e-pinchStart;zooming=!0,i*=zoomPinchFactor,i>zoomPinchCap&&(i=zoomPinchCap),i<-zoomPinchCap&&(i=-zoomPinchCap),zoomImage(i/size2),pinchStart=e,swipe=rotate=zooming=!1,setProjection(),drawScene()}}let pixelShader,materialShader,colorShader,transparentShader,zbuffer=[];function transformVertices(e){let t=viewMat[2],i=viewMat[6],a=viewMat[10];zbuffer.length=e.length;for(let n=0;n<e.length;++n){let r=6*n;zbuffer[n]=t*e[r]+i*e[r+1]+a*e[r+2]}}function drawMaterial0(){drawBuffer(material0Data,pixelShader),material0Data.clear()}function drawMaterial1(){drawBuffer(material1Data,materialShader),material1Data.clear()}function drawMaterial(){drawBuffer(materialData,materialShader),materialData.clear()}function drawColor(){drawBuffer(colorData,colorShader),colorData.clear()}function drawTriangle(){drawBuffer(triangleData,transparentShader),triangleData.rendered=!1,triangleData.clear()}function drawTransparent(){let e=transparentData.indices;if(wireframe>0)return drawBuffer(transparentData,transparentShader,e),void transparentData.clear();if(e.length>0){transformVertices(transparentData.vertices);let t=e.length/3,i=Array(t).fill().map((e,t)=>t);i.sort((function(t,i){let a=3*t;Ia=e[a],Ib=e[a+1],Ic=e[a+2];let n=3*i;return IA=e[n],IB=e[n+1],IC=e[n+2],zbuffer[Ia]+zbuffer[Ib]+zbuffer[Ic]<zbuffer[IA]+zbuffer[IB]+zbuffer[IC]?-1:1}));let a=Array(e.length);for(let n=0;n<t;++n){let t=3*i[n];a[3*n]=e[t],a[3*n+1]=e[t+1],a[3*n+2]=e[t+2]}gl.depthMask(!1),drawBuffer(transparentData,transparentShader,a),transparentData.rendered=!1,gl.depthMask(!0)}transparentData.clear()}function drawBuffers(){drawMaterial0(),drawMaterial1(),drawMaterial(),drawColor(),drawTriangle(),drawTransparent(),requestAnimationFrame(drawBuffers)}function drawScene(){embedded&&(offscreen.width=canvasWidth,offscreen.height=canvasHeight,setViewport()),gl.clearColor(Background[0],Background[1],Background[2],Background[3]),gl.clear(gl.COLOR_BUFFER_BIT|gl.DEPTH_BUFFER_BIT);for(let e=0;e<P.length;++e)P[e].render();drawBuffers(),embedded&&(context.clearRect(0,0,canvasWidth,canvasHeight),context.drawImage(offscreen,0,0)),0==wireframe&&(remesh=!1)}function setDimensions(e,t,i,a){let n=e/t;xshift=(i/e+viewportShift[0])*Zoom,yshift=(a/t+viewportShift[1])*Zoom;let r=1/Zoom;if(orthographic){let e=maxBound[0]-minBound[0],t=maxBound[1]-minBound[1];if(e<t*n){let e=.5*t*n*r,i=2*e*xshift,a=t*r*yshift;viewParam.xmin=-e-i,viewParam.xmax=e-i,viewParam.ymin=minBound[1]*r-a,viewParam.ymax=maxBound[1]*r-a}else{let t=.5*e*r/n,i=e*r*xshift,a=2*t*yshift;viewParam.xmin=minBound[0]*r-i,viewParam.xmax=maxBound[0]*r-i,viewParam.ymin=-t-a,viewParam.ymax=t-a}}else{let e=H*r,t=e*n,i=2*t*xshift,a=2*e*yshift;viewParam.xmin=-t-i,viewParam.xmax=t-i,viewParam.ymin=-e-a,viewParam.ymax=e-a}}function setProjection(){setDimensions(canvasWidth,canvasHeight,shift.x,shift.y),(orthographic?mat4.ortho:mat4.frustum)(projMat,viewParam.xmin,viewParam.xmax,viewParam.ymin,viewParam.ymax,-viewParam.zmax,-viewParam.zmin),updateViewMatrix(),window.top.asyWebApplication&&window.top.asyWebApplication.setProjection(projection())}function showCamera(){window.top.asyWebApplication||prompt("Ctrl+c Enter to copy currentprojection to clipboard; then append to asy file:",projection())}function initProjection(){H=-Math.tan(.5*angleOfView)*maxBound[2],center.x=center.y=0,center.z=.5*(minBound[2]+maxBound[2]),lastZoom=Zoom=zoom0,viewParam.zmin=minBound[2],viewParam.zmax=maxBound[2],shift.x=shift.y=0}function setViewport(){gl.viewportWidth=canvasWidth,gl.viewportHeight=canvasHeight,gl.viewport(.5*(canvas.width-canvasWidth),.5*(canvas.height-canvasHeight),canvasWidth,canvasHeight),gl.scissor(0,0,canvas.width,canvas.height)}function setCanvas(){embedded&&(canvas.width=offscreen.width=canvasWidth,canvas.height=offscreen.height=canvasHeight),size2=Math.hypot(canvasWidth,canvasHeight),halfCanvasWidth=.5*canvas.width,halfCanvasHeight=.5*canvas.height,ArcballFactor=1+8*Math.hypot(viewportMargin[0],viewportMargin[1])/size2}function setsize(e,t){e>maxViewportWidth&&(e=maxViewportWidth),t>maxViewportHeight&&(t=maxViewportHeight),shift.x*=e/canvasWidth,shift.y*=t/canvasHeight,canvasWidth=e,canvasHeight=t,setCanvas(),setViewport(),setProjection(),remesh=!0}function resize(){if(zoom0=initialZoom,window.top.asyWebApplication&&""==window.top.asyWebApplication.getProjection()&&(window.parent.asyProjection=!1),absolute&&!embedded)canvasWidth=canvasWidth0*window.devicePixelRatio,canvasHeight=canvasHeight0*window.devicePixelRatio;else{let e=canvasWidth0/canvasHeight0;canvasWidth=Math.max(window.innerWidth-10,10),canvasHeight=Math.max(window.innerHeight-10,10),!orthographic&&!window.parent.asyProjection&&canvasWidth<canvasHeight*e&&(zoom0*=canvasWidth/(canvasHeight*e))}canvas.width=canvasWidth,canvas.height=canvasHeight;window.innerWidth,window.innerHeight;let e=1/zoom0;viewportShift[0]*=e,viewportShift[1]*=e,setsize(canvasWidth,canvasHeight),redrawScene()}function expand(){Zoom*=zoomFactor,setZoom()}function shrink(){Zoom/=zoomFactor,setZoom()}class Align{constructor(e,t){if(this.center=e,t){let e=t[0],i=t[1];this.ct=Math.cos(e),this.st=Math.sin(e),this.cp=Math.cos(i),this.sp=Math.sin(i)}}T0(e){return[e[0]+this.center[0],e[1]+this.center[1],e[2]+this.center[2]]}T(e){let t=e[0],i=e[1],a=e[2],n=t*this.ct+a*this.st;return[n*this.cp-i*this.sp+this.center[0],n*this.sp+i*this.cp+this.center[1],-t*this.st+a*this.ct+this.center[2]]}}function Tcorners(e,t,i){let a=[e(t),e([t[0],t[1],i[2]]),e([t[0],i[1],t[2]]),e([t[0],i[1],i[2]]),e([i[0],t[1],t[2]]),e([i[0],t[1],i[2]]),e([i[0],i[1],t[2]]),e(i)];return[minbound(a),maxbound(a)]}function material(e,t,i,a,n,r){Materials.push(new Material(e,t,i,a,n,r))}function patch(e,t,i,a,n,r){P.push(new BezierPatch(e,t,i,a,n,r))}function curve(e,t,i,a,n){P.push(new BezierCurve(e,t,i,a,n))}function pixel(e,t,i,a,n){P.push(new Pixel(e,t,i,a,n))}function triangles(e,t,i,a){P.push(new Triangles(e,t,i,a))}function sphere(e,t,i,n,r){let s,o,l,h,c,d,m=.524670512339254,f=.595936986722291,u=.954967051233925,p=.0820155480083437,g=.996685028842544,v=.0549670512339254,x=.998880711874577,w=.0405017186586849,M=[[[1,0,0],[1,0,m],[f,0,u],[p,0,g],[1,a,0],[1,a,m],[f,a*f,u],[p,a*p,g],[a,1,0],[a,1,m],[a*f,f,u],[a*p,p,g],[0,1,0],[0,1,m],[0,f,u],[0,p,g]],[[p,0,g],[p,a*p,g],[v,0,x],[a*p,p,g],[w,w,1],[.05*a,0,1],[0,p,g],[0,v,x],[0,.05*a,1],[0,0,1]]],b=new Align(e,r);function T(e){let t=Array(e.length);for(let i=0;i<e.length;++i){let a=e[i];t[i]=c([s*a[0],o*a[1],l*a[2]])}return t}r?(h=1,d=0,c=b.T.bind(b)):(h=-1,d=-t,c=b.T0.bind(b));let S=Tcorners(c,[-t,-t,d],[t,t,t]),R=S[0],A=S[1];for(let e=-1;e<=1;e+=2){s=e*t;for(let e=-1;e<=1;e+=2){o=e*t;for(let e=h;e<=1;e+=2){l=e*t;for(let e=0;e<2;++e)P.push(new BezierPatch(T(M[e]),i,n,R,A))}}}}let a=4/3*(Math.sqrt(2)-1);function disk(e,t,i,n,r){let s=1-2*a/3,o=[[1,0,0],[1,-a,0],[a,-1,0],[0,-1,0],[1,a,0],[s,0,0],[0,-s,0],[-a,-1,0],[a,1,0],[0,s,0],[-s,0,0],[-1,-a,0],[0,1,0],[-a,1,0],[-1,a,0],[-1,0,0]],l=new Align(e,r);let h=Tcorners(l.T.bind(l),[-t,-t,0],[t,t,0]);P.push(new BezierPatch(function(e){let i=Array(e.length);for(let a=0;a<e.length;++a){let n=e[a];i[a]=l.T([t*n[0],t*n[1],0])}return i}(o),i,n,h[0],h[1]))}function cylinder(e,t,i,n,r,s,o){let l,h,c=[[1,0,0],[1,0,1/3],[1,0,2/3],[1,0,1],[1,a,0],[1,a,1/3],[1,a,2/3],[1,a,1],[a,1,0],[a,1,1/3],[a,1,2/3],[a,1,1],[0,1,0],[0,1,1/3],[0,1,2/3],[0,1,1]],d=new Align(e,s);function m(e){let t=Array(e.length);for(let a=0;a<e.length;++a){let n=e[a];t[a]=d.T([l*n[0],h*n[1],i*n[2]])}return t}let f=Tcorners(d.T.bind(d),[-t,-t,0],[t,t,i]),u=f[0],p=f[1];for(let e=-1;e<=1;e+=2){l=e*t;for(let e=-1;e<=1;e+=2)h=e*t,P.push(new BezierPatch(m(c),n,r,u,p))}if(o){let t=d.T([0,0,i]);P.push(new BezierCurve([e,t],n,r,e,t))}}function rmf(e,t,i,a,n){class r{constructor(e,t,i){this.p=e,this.r=t,this.t=i,this.s=cross(i,t)}}let s=Number.EPSILON*Math.max(abs2(e),abs2(t),abs2(i),abs2(a));function o(n){if(1==n){let n=[a[0]-i[0],a[1]-i[1],a[2]-i[2]];return abs2(n)>s?unit(n):(n=[2*i[0]-t[0]-a[0],2*i[1]-t[1]-a[1],2*i[2]-t[2]-a[2]],abs2(n)>s?unit(n):[a[0]-e[0]+3*(t[0]-i[0]),a[1]-e[1]+3*(t[1]-i[1]),a[2]-e[2]+3*(t[2]-i[2])])}let r=[a[0]-e[0]+3*(t[0]-i[0]),a[1]-e[1]+3*(t[1]-i[1]),a[2]-e[2]+3*(t[2]-i[2])],o=[2*(e[0]+i[0])-4*t[0],2*(e[1]+i[1])-4*t[1],2*(e[2]+i[2])-4*t[2]],l=[t[0]-e[0],t[1]-e[1],t[2]-e[2]],h=n*n,c=[r[0]*h+o[0]*n+l[0],r[1]*h+o[1]*n+l[1],r[2]*h+o[2]*n+l[2]];return abs2(c)>s?unit(c):(h=2*n,c=[r[0]*h+o[0],r[1]*h+o[1],r[2]*h+o[2]],abs2(c)>s?unit(c):unit(r))}let l=Array(n.length),h=[t[0]-e[0],t[1]-e[1],t[2]-e[2]];abs2(h)<s&&(h=[e[0]-2*t[0]+i[0],e[1]-2*t[1]+i[1],e[2]-2*t[2]+i[2]],abs2(h)<s&&(h=[a[0]-e[0]+3*(t[0]-i[0]),a[1]-e[1]+3*(t[1]-i[1]),a[2]-e[2]+3*(t[2]-i[2])])),h=unit(h);let c=function(e){let t=cross(e,[0,1,0]),i=Number.EPSILON*abs2(e);return abs2(t)>i?unit(t):(t=cross(e,[0,0,1]),abs2(t)>i?unit(t):[1,0,0])}(h);l[0]=new r(e,c,h);for(let s=1;s<n.length;++s){let h=l[s-1],c=n[s],d=1-c,m=d*d,f=m*d,u=3*c;m*=u,d*=u*c;let p=c*c*c,g=[f*e[0]+m*t[0]+d*i[0]+p*a[0],f*e[1]+m*t[1]+d*i[1]+p*a[1],f*e[2]+m*t[2]+d*i[2]+p*a[2]],v=[g[0]-h.p[0],g[1]-h.p[1],g[2]-h.p[2]];if(0!=v[0]||0!=v[1]||0!=v[2]){let e=h.r,t=unit(v),i=h.t,a=dot(t,i),n=[i[0]-2*a*t[0],i[1]-2*a*t[1],i[2]-2*a*t[2]];i=o(c);let d=2*dot(t,e),m=[e[0]-d*t[0],e[1]-d*t[1],e[2]-d*t[2]],f=unit([i[0]-n[0],i[1]-n[1],i[2]-n[2]]),u=2*dot(f,m);m=[m[0]-u*f[0],m[1]-u*f[1],m[2]-u*f[2]],l[s]=new r(g,unit(m),unit(i))}else l[s]=l[s-1]}return l}function tube(e,t,i,n,r,s,o){let l=rmf(e[0],e[1],e[2],e[3],[0,1/3,2/3,1]),h=a*t,c=[[t,0],[t,h],[h,t],[0,t]];function d(t,a,o,h){let d=Array(16);for(let i=0;i<4;++i){let n=l[i],r=n.r[0],s=n.s[0],m=r*t+s*a,f=r*o+s*h;r=n.r[1],s=n.s[1];let u=r*t+s*a,p=r*o+s*h;r=n.r[2],s=n.s[2];let g=r*t+s*a,v=r*o+s*h,x=e[i],w=x[0];w1=x[1],w2=x[2];for(let e=0;e<4;++e){let t=c[e],a=t[0],n=t[1];d[4*i+e]=[m*a+f*n+w,u*a+p*n+w1,g*a+v*n+w2]}}P.push(new BezierPatch(d,i,n,r,s))}d(1,0,0,1),d(0,-1,1,0),d(-1,0,0,-1),d(0,1,-1,0),o&&P.push(new BezierCurve(e,i,n,r,s))}async function getReq(e){return(await fetch(e)).arrayBuffer()}function rgb(e){return e.getBytes().filter((e,t)=>t%4!=3)}function createTexture(e,t,i=gl.RGB16F){let a=e.width(),n=e.height(),r=gl.createTexture();return gl.activeTexture(gl.TEXTURE0+t),gl.bindTexture(gl.TEXTURE_2D,r),gl.pixelStorei(gl.UNPACK_ALIGNMENT,1),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,gl.LINEAR),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,gl.LINEAR),gl.texImage2D(gl.TEXTURE_2D,0,i,a,n,0,gl.RGB,gl.FLOAT,rgb(e)),r}async function initIBL(){let e=imageURL+image+"/";function t(e){return new Promise(t=>setTimeout(t,e))}for(;!Module.EXRLoader;)await t(0);promises=[getReq(imageURL+"refl.exr").then(e=>{let t=new Module.EXRLoader(e);IBLbdrfMap=createTexture(t,0)}),getReq(e+"diffuse.exr").then(e=>{let t=new Module.EXRLoader(e);IBLDiffuseMap=createTexture(t,1)})],refl_promise=[],refl_promise.push(getReq(e+"refl0.exr"));for(let t=1;t<=roughnessStepCount;++t)refl_promise.push(getReq(e+"refl"+t+"w.exr"));finished_promise=Promise.all(refl_promise).then(e=>{let t=gl.createTexture();gl.activeTexture(gl.TEXTURE0+2),gl.pixelStorei(gl.UNPACK_ALIGNMENT,1),gl.bindTexture(gl.TEXTURE_2D,t),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAX_LEVEL,e.length-1),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,gl.LINEAR_MIPMAP_LINEAR),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,gl.LINEAR),gl.texParameterf(gl.TEXTURE_2D,gl.TEXTURE_MIN_LOD,0),gl.texParameterf(gl.TEXTURE_2D,gl.TEXTURE_MAX_LOD,roughnessStepCount);for(let t=0;t<e.length;++t){let i=new Module.EXRLoader(e[t]);gl.texImage2D(gl.TEXTURE_2D,t,gl.RGB16F,i.width(),i.height(),0,gl.RGB,gl.FLOAT,rgb(i))}IBLReflMap=t}),promises.push(finished_promise),await Promise.all(promises)}function webGLStart(){canvas=document.getElementById("Asymptote"),embedded=window.top.document!=document,initGL(),gl.enable(gl.BLEND),gl.blendFunc(gl.SRC_ALPHA,gl.ONE_MINUS_SRC_ALPHA),gl.enable(gl.DEPTH_TEST),gl.enable(gl.SCISSOR_TEST),canvas.onmousedown=handleMouseDown,document.onmouseup=handleMouseUpOrTouchEnd,document.onmousemove=handleMouseMove,canvas.onkeydown=handleKey,embedded||enableZoom(),canvas.addEventListener("touchstart",handleTouchStart,!1),canvas.addEventListener("touchend",handleMouseUpOrTouchEnd,!1),canvas.addEventListener("touchcancel",handleMouseUpOrTouchEnd,!1),canvas.addEventListener("touchleave",handleMouseUpOrTouchEnd,!1),canvas.addEventListener("touchmove",handleTouchMove,!1),document.addEventListener("keydown",handleKey,!1),canvasWidth0=canvasWidth,canvasHeight0=canvasHeight,mat4.identity(rotMat),0!=window.innerWidth&&0!=window.innerHeight&&resize(),window.addEventListener("resize",resize,!1),ibl&&initIBL().then(SetIBL).then(redrawScene)}
+let vertex="\n#ifdef WEBGL2\n#define IN in\n#define OUT out\n#else\n#define IN attribute\n#define OUT varying\n#endif\n\nIN vec3 position;\n#ifdef WIDTH\nIN float width;\n#endif\n#ifdef NORMAL\nIN vec3 normal;\n#endif\n\nIN float materialIndex;\n\n#ifdef WEBGL2\nflat out int MaterialIndex;\n#ifdef COLOR\nOUT vec4 Color;\n#endif\n\n#else\nOUT vec4 diffuse;\nOUT vec3 specular;\nOUT float roughness,metallic,fresnel0;\nOUT vec4 emissive;\n\nstruct Material {\n vec4 diffuse,emissive,specular;\n vec4 parameters;\n};\n\nuniform Material Materials[Nmaterials];\n#endif\n\n#ifdef COLOR\nIN vec4 color;\n#endif\n\nuniform mat3 normMat;\nuniform mat4 viewMat;\nuniform mat4 projViewMat;\n\n#ifdef NORMAL\n#ifndef ORTHOGRAPHIC\nOUT vec3 ViewPosition;\n#endif\nOUT vec3 Normal;\n#endif\n\nvoid main(void)\n{\n vec4 v=vec4(position,1.0);\n gl_Position=projViewMat*v;\n\n#ifdef NORMAL\n#ifndef ORTHOGRAPHIC\n ViewPosition=(viewMat*v).xyz;\n#endif\n Normal=normalize(normal*normMat);\n#endif\n\n#ifdef WEBGL2\n MaterialIndex=int(materialIndex);\n#ifdef COLOR\n Color=color;\n#endif\n#else\n#ifdef NORMAL\n Material m;\n#ifdef TRANSPARENT\n m=Materials[int(abs(materialIndex))-1];\n emissive=m.emissive;\n if(materialIndex >= 0.0)\n diffuse=m.diffuse;\n else {\n diffuse=color;\n#if nlights == 0\n emissive += color;\n#endif\n }\n#else\n m=Materials[int(materialIndex)];\n emissive=m.emissive;\n#ifdef COLOR\n diffuse=color;\n#if nlights == 0\n emissive += color;\n#endif\n#else\n diffuse=m.diffuse;\n#endif // COLOR\n#endif // TRANSPARENT\n specular=m.specular.rgb;\n vec4 parameters=m.parameters;\n roughness=1.0-parameters[0];\n metallic=parameters[1];\n fresnel0=parameters[2];\n#else\n emissive=Materials[int(materialIndex)].emissive;\n#endif // NORMAL\n#endif // WEBGL2\n\n#ifdef WIDTH\n gl_PointSize=width;\n#endif\n}\n",fragment="\n#ifdef WEBGL2\n#define IN in\nout vec4 outValue;\n#define OUTVALUE outValue\n#else\n#define IN varying\n#define OUTVALUE gl_FragColor\n#endif\n\n#ifdef WEBGL2\nflat in int MaterialIndex;\n\nstruct Material {\n vec4 diffuse,emissive,specular;\n vec4 parameters;\n};\n\nuniform Material Materials[Nmaterials];\n\nvec4 diffuse;\nvec3 specular;\nfloat roughness,metallic,fresnel0;\nvec4 emissive;\n\n#ifdef COLOR\nin vec4 Color;\n#endif\n\n#else\nIN vec4 diffuse;\nIN vec3 specular;\nIN float roughness,metallic,fresnel0;\nIN vec4 emissive;\n#endif\n\n#ifdef NORMAL\n\n#ifndef ORTHOGRAPHIC\nIN vec3 ViewPosition;\n#endif\nIN vec3 Normal;\n\nvec3 normal;\n\nstruct Light {\n vec3 direction;\n vec3 color;\n};\n\nuniform Light Lights[Nlights];\n\n#ifdef USE_IBL\nuniform sampler2D reflBRDFSampler;\nuniform sampler2D diffuseSampler;\nuniform sampler2D reflImgSampler;\n\nconst float pi=acos(-1.0);\nconst float piInv=1.0/pi;\nconst float twopi=2.0*pi;\nconst float twopiInv=1.0/twopi;\n\n// (x,y,z) -> (r,theta,phi);\n// theta -> [0,pi]: colatitude\n// phi -> [-pi,pi]: longitude\nvec3 cart2sphere(vec3 cart)\n{\n float x=cart.x;\n float y=cart.z;\n float z=cart.y;\n\n float r=length(cart);\n float theta=r > 0.0 ? acos(z/r) : 0.0;\n float phi=atan(y,x);\n\n return vec3(r,theta,phi);\n}\n\nvec2 normalizedAngle(vec3 cartVec)\n{\n vec3 sphericalVec=cart2sphere(cartVec);\n sphericalVec.y=sphericalVec.y*piInv;\n sphericalVec.z=0.75-sphericalVec.z*twopiInv;\n return sphericalVec.zy;\n}\n\nvec3 IBLColor(vec3 viewDir)\n{\n vec3 IBLDiffuse=diffuse.rgb*texture(diffuseSampler,normalizedAngle(normal)).rgb;\n vec3 reflectVec=normalize(reflect(-viewDir,normal));\n vec2 reflCoord=normalizedAngle(reflectVec);\n vec3 IBLRefl=textureLod(reflImgSampler,reflCoord,roughness*ROUGHNESS_STEP_COUNT).rgb;\n vec2 IBLbrdf=texture(reflBRDFSampler,vec2(dot(normal,viewDir),roughness)).rg;\n float specularMultiplier=fresnel0*IBLbrdf.x+IBLbrdf.y;\n vec3 dielectric=IBLDiffuse+specularMultiplier*IBLRefl;\n vec3 metal=diffuse.rgb*IBLRefl;\n return mix(dielectric,metal,metallic);\n}\n#else\nfloat Roughness2;\nfloat NDF_TRG(vec3 h)\n{\n float ndoth=max(dot(normal,h),0.0);\n float alpha2=Roughness2*Roughness2;\n float denom=ndoth*ndoth*(alpha2-1.0)+1.0;\n return denom != 0.0 ? alpha2/(denom*denom) : 0.0;\n}\n\nfloat GGX_Geom(vec3 v)\n{\n float ndotv=max(dot(v,normal),0.0);\n float ap=1.0+Roughness2;\n float k=0.125*ap*ap;\n return ndotv/((ndotv*(1.0-k))+k);\n}\n\nfloat Geom(vec3 v, vec3 l)\n{\n return GGX_Geom(v)*GGX_Geom(l);\n}\n\nfloat Fresnel(vec3 h, vec3 v, float fresnel0)\n{\n float a=1.0-max(dot(h,v),0.0);\n float b=a*a;\n return fresnel0+(1.0-fresnel0)*b*b*a;\n}\n\n// physical based shading using UE4 model.\nvec3 BRDF(vec3 viewDirection, vec3 lightDirection)\n{\n vec3 lambertian=diffuse.rgb;\n vec3 h=normalize(lightDirection+viewDirection);\n\n float omegain=max(dot(viewDirection,normal),0.0);\n float omegaln=max(dot(lightDirection,normal),0.0);\n\n float D=NDF_TRG(h);\n float G=Geom(viewDirection,lightDirection);\n float F=Fresnel(h,viewDirection,fresnel0);\n\n float denom=4.0*omegain*omegaln;\n float rawReflectance=denom > 0.0 ? (D*G)/denom : 0.0;\n\n vec3 dielectric=mix(lambertian,rawReflectance*specular,F);\n vec3 metal=rawReflectance*diffuse.rgb;\n\n return mix(dielectric,metal,metallic);\n}\n#endif\n\n#endif\n\nvoid main(void)\n{\n#ifdef WEBGL2\n#ifdef NORMAL\n Material m;\n#ifdef TRANSPARENT\n m=Materials[abs(MaterialIndex)-1];\n emissive=m.emissive;\n if(MaterialIndex >= 0)\n diffuse=m.diffuse;\n else {\n diffuse=Color;\n#if nlights == 0\n emissive += Color;\n#endif\n }\n#else\n m=Materials[MaterialIndex];\n emissive=m.emissive;\n#ifdef COLOR\n diffuse=Color;\n#if nlights == 0\n emissive += Color;\n#endif\n#else\n diffuse=m.diffuse;\n#endif // COLOR\n#endif // TRANSPARENT\n specular=m.specular.rgb;\n vec4 parameters=m.parameters;\n roughness=1.0-parameters[0];\n metallic=parameters[1];\n fresnel0=parameters[2];\n#else\n emissive=Materials[MaterialIndex].emissive;\n#endif // NORMAL\n#endif // WEBGL2\n\n#if defined(NORMAL) && nlights > 0\n normal=normalize(Normal);\n normal=gl_FrontFacing ? normal : -normal;\n#ifdef ORTHOGRAPHIC\n vec3 viewDir=vec3(0.0,0.0,1.0);\n#else\n vec3 viewDir=-normalize(ViewPosition);\n#endif\n\nvec3 color;\n#ifdef USE_IBL\n color=IBLColor(viewDir);\n#else\n Roughness2=roughness*roughness;\n color=emissive.rgb;\n for(int i=0; i < nlights; ++i) {\n Light Li=Lights[i];\n vec3 L=Li.direction;\n float cosTheta=max(dot(normal,L),0.0);\n vec3 radiance=cosTheta*Li.color;\n color += BRDF(viewDir,L)*radiance;\n }\n#endif\n OUTVALUE=vec4(color,diffuse.a);\n#else\n OUTVALUE=emissive;\n#endif\n}\n";!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var i=e();for(var n in i)("object"==typeof exports?exports:t)[n]=i[n]}}("undefined"!=typeof self?self:this,(function(){return function(t){var e={};function i(n){if(e[n])return e[n].exports;var r=e[n]={i:n,l:!1,exports:{}};return t[n].call(r.exports,r,r.exports,i),r.l=!0,r.exports}return i.m=t,i.c=e,i.d=function(t,e,n){i.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:n})},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="",i(i.s=1)}([function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.setMatrixArrayType=function(t){e.ARRAY_TYPE=t},e.toRadian=function(t){return t*r},e.equals=function(t,e){return Math.abs(t-e)<=n*Math.max(1,Math.abs(t),Math.abs(e))};var n=e.EPSILON=1e-6;e.ARRAY_TYPE="undefined"!=typeof Float32Array?Float32Array:Array,e.RANDOM=Math.random;var r=Math.PI/180},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.mat4=e.mat3=void 0;var n=s(i(2)),r=s(i(3));function s(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e.default=t,e}e.mat3=n,e.mat4=r},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.create=function(){var t=new n.ARRAY_TYPE(9);return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=1,t[5]=0,t[6]=0,t[7]=0,t[8]=1,t},e.fromMat4=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[4],t[4]=e[5],t[5]=e[6],t[6]=e[8],t[7]=e[9],t[8]=e[10],t},e.invert=function(t,e){var i=e[0],n=e[1],r=e[2],s=e[3],a=e[4],o=e[5],h=e[6],l=e[7],c=e[8],d=c*a-o*l,m=-c*s+o*h,f=l*s-a*h,u=i*d+n*m+r*f;if(!u)return null;return u=1/u,t[0]=d*u,t[1]=(-c*n+r*l)*u,t[2]=(o*n-r*a)*u,t[3]=m*u,t[4]=(c*i-r*h)*u,t[5]=(-o*i+r*s)*u,t[6]=f*u,t[7]=(-l*i+n*h)*u,t[8]=(a*i-n*s)*u,t};var n=function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e.default=t,e}(i(0))},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.create=function(){var t=new n.ARRAY_TYPE(16);return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},e.identity=function(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},e.invert=function(t,e){var i=e[0],n=e[1],r=e[2],s=e[3],a=e[4],o=e[5],h=e[6],l=e[7],c=e[8],d=e[9],m=e[10],f=e[11],u=e[12],p=e[13],v=e[14],x=e[15],g=i*o-n*a,w=i*h-r*a,M=i*l-s*a,b=n*h-r*o,R=n*l-s*o,T=r*l-s*h,y=c*p-d*u,A=c*v-m*u,E=c*x-f*u,I=d*v-m*p,L=d*x-f*p,N=m*x-f*v,O=g*N-w*L+M*I+b*E-R*A+T*y;if(!O)return null;return O=1/O,t[0]=(o*N-h*L+l*I)*O,t[1]=(r*L-n*N-s*I)*O,t[2]=(p*T-v*R+x*b)*O,t[3]=(m*R-d*T-f*b)*O,t[4]=(h*E-a*N-l*A)*O,t[5]=(i*N-r*E+s*A)*O,t[6]=(v*M-u*T-x*w)*O,t[7]=(c*T-m*M+f*w)*O,t[8]=(a*L-o*E+l*y)*O,t[9]=(n*E-i*L-s*y)*O,t[10]=(u*R-p*M+x*g)*O,t[11]=(d*M-c*R-f*g)*O,t[12]=(o*A-a*I-h*y)*O,t[13]=(i*I-n*A+r*y)*O,t[14]=(p*w-u*b-v*g)*O,t[15]=(c*b-d*w+m*g)*O,t},e.multiply=r,e.translate=function(t,e,i){var n=i[0],r=i[1],s=i[2],a=void 0,o=void 0,h=void 0,l=void 0,c=void 0,d=void 0,m=void 0,f=void 0,u=void 0,p=void 0,v=void 0,x=void 0;e===t?(t[12]=e[0]*n+e[4]*r+e[8]*s+e[12],t[13]=e[1]*n+e[5]*r+e[9]*s+e[13],t[14]=e[2]*n+e[6]*r+e[10]*s+e[14],t[15]=e[3]*n+e[7]*r+e[11]*s+e[15]):(a=e[0],o=e[1],h=e[2],l=e[3],c=e[4],d=e[5],m=e[6],f=e[7],u=e[8],p=e[9],v=e[10],x=e[11],t[0]=a,t[1]=o,t[2]=h,t[3]=l,t[4]=c,t[5]=d,t[6]=m,t[7]=f,t[8]=u,t[9]=p,t[10]=v,t[11]=x,t[12]=a*n+c*r+u*s+e[12],t[13]=o*n+d*r+p*s+e[13],t[14]=h*n+m*r+v*s+e[14],t[15]=l*n+f*r+x*s+e[15]);return t},e.rotate=function(t,e,i,r){var s,a,o,h,l,c,d,m,f,u,p,v,x,g,w,M,b,R,T,y,A,E,I,L,N=r[0],O=r[1],_=r[2],P=Math.sqrt(N*N+O*O+_*_);if(Math.abs(P)<n.EPSILON)return null;N*=P=1/P,O*=P,_*=P,s=Math.sin(i),a=Math.cos(i),o=1-a,h=e[0],l=e[1],c=e[2],d=e[3],m=e[4],f=e[5],u=e[6],p=e[7],v=e[8],x=e[9],g=e[10],w=e[11],M=N*N*o+a,b=O*N*o+_*s,R=_*N*o-O*s,T=N*O*o-_*s,y=O*O*o+a,A=_*O*o+N*s,E=N*_*o+O*s,I=O*_*o-N*s,L=_*_*o+a,t[0]=h*M+m*b+v*R,t[1]=l*M+f*b+x*R,t[2]=c*M+u*b+g*R,t[3]=d*M+p*b+w*R,t[4]=h*T+m*y+v*A,t[5]=l*T+f*y+x*A,t[6]=c*T+u*y+g*A,t[7]=d*T+p*y+w*A,t[8]=h*E+m*I+v*L,t[9]=l*E+f*I+x*L,t[10]=c*E+u*I+g*L,t[11]=d*E+p*I+w*L,e!==t&&(t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]);return t},e.fromTranslation=function(t,e){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=e[0],t[13]=e[1],t[14]=e[2],t[15]=1,t},e.fromRotation=function(t,e,i){var r,s,a,o=i[0],h=i[1],l=i[2],c=Math.sqrt(o*o+h*h+l*l);if(Math.abs(c)<n.EPSILON)return null;return o*=c=1/c,h*=c,l*=c,r=Math.sin(e),s=Math.cos(e),a=1-s,t[0]=o*o*a+s,t[1]=h*o*a+l*r,t[2]=l*o*a-h*r,t[3]=0,t[4]=o*h*a-l*r,t[5]=h*h*a+s,t[6]=l*h*a+o*r,t[7]=0,t[8]=o*l*a+h*r,t[9]=h*l*a-o*r,t[10]=l*l*a+s,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},e.frustum=function(t,e,i,n,r,s,a){var o=1/(i-e),h=1/(r-n),l=1/(s-a);return t[0]=2*s*o,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=2*s*h,t[6]=0,t[7]=0,t[8]=(i+e)*o,t[9]=(r+n)*h,t[10]=(a+s)*l,t[11]=-1,t[12]=0,t[13]=0,t[14]=a*s*2*l,t[15]=0,t},e.ortho=function(t,e,i,n,r,s,a){var o=1/(e-i),h=1/(n-r),l=1/(s-a);return t[0]=-2*o,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=-2*h,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=2*l,t[11]=0,t[12]=(e+i)*o,t[13]=(r+n)*h,t[14]=(a+s)*l,t[15]=1,t};var n=function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e.default=t,e}(i(0));function r(t,e,i){var n=e[0],r=e[1],s=e[2],a=e[3],o=e[4],h=e[5],l=e[6],c=e[7],d=e[8],m=e[9],f=e[10],u=e[11],p=e[12],v=e[13],x=e[14],g=e[15],w=i[0],M=i[1],b=i[2],R=i[3];return t[0]=w*n+M*o+b*d+R*p,t[1]=w*r+M*h+b*m+R*v,t[2]=w*s+M*l+b*f+R*x,t[3]=w*a+M*c+b*u+R*g,w=i[4],M=i[5],b=i[6],R=i[7],t[4]=w*n+M*o+b*d+R*p,t[5]=w*r+M*h+b*m+R*v,t[6]=w*s+M*l+b*f+R*x,t[7]=w*a+M*c+b*u+R*g,w=i[8],M=i[9],b=i[10],R=i[11],t[8]=w*n+M*o+b*d+R*p,t[9]=w*r+M*h+b*m+R*v,t[10]=w*s+M*l+b*f+R*x,t[11]=w*a+M*c+b*u+R*g,w=i[12],M=i[13],b=i[14],R=i[15],t[12]=w*n+M*o+b*d+R*p,t[13]=w*r+M*h+b*m+R*v,t[14]=w*s+M*l+b*f+R*x,t[15]=w*a+M*c+b*u+R*g,t}}])})),function(){document.asy={canvasWidth:0,canvasHeight:0,absolute:!1,minBound:[0,0,0],maxBound:[0,0,0],orthographic:!1,angleOfView:0,initialZoom:0,viewportShift:[0,0],viewportMargin:[0,0],background:[],zoomFactor:0,zoomPinchFactor:0,zoomPinchCap:0,zoomStep:0,shiftHoldDistance:0,shiftWaitTime:0,vibrateTime:0,ibl:!1,webgl2:!1,imageURL:"",image:"",Transform:[],Centers:[]};let t,e,i,n,r,s,a,o=document.asy,h=[],l=[],c=[],d=0,m=2;const f=Math.acos(-1),u=f/180,p=Math.ceil(1-Math.log2(Number.EPSILON));let v,x,g,w,M,b,R,T=mat4.create(),y=mat4.create(),A=mat4.create(),E=mat4.create(),I=mat3.create(),L=mat3.create(),N=mat4.create(),O=mat4.create(),_={x:0,y:0,z:0},P={x:0,y:0},S={xmin:0,xmax:0,ymin:0,ymax:0,zmin:0,zmax:0},U=!0,V=0,B=!1,D=null,C=null,F=[],z=[],H=[],X=[],G=null,W=null,j=null;function k(){o.embedded||st(),rt(o.ibl)}class Y{constructor(t,e,i,n,r,s){this.diffuse=t,this.emissive=e,this.specular=i,this.shininess=n,this.metallic=r,this.fresnel0=s}setUniform(e,i){let n=n=>t.getUniformLocation(e,"Materials["+i+"]."+n);t.uniform4fv(n("diffuse"),new Float32Array(this.diffuse)),t.uniform4fv(n("emissive"),new Float32Array(this.emissive)),t.uniform4fv(n("specular"),new Float32Array(this.specular)),t.uniform4f(n("parameters"),this.shininess,this.metallic,this.fresnel0,0)}}let $,q,K,Z,Q,J,tt,et,it;class nt{constructor(t,e){this.direction=t,this.color=e}setUniform(e,i){let n=n=>t.getUniformLocation(e,"Lights["+i+"]."+n);t.uniform3fv(n("direction"),new Float32Array(this.direction)),t.uniform3fv(n("color"),new Float32Array(this.color))}}function rt(e=!1){let i=t.getParameter(t.MAX_VERTEX_UNIFORM_VECTORS);r=Math.floor((i-14)/4),m=Math.min(Math.max(m,c.length),r),pixelOpt=["WIDTH"],materialOpt=["NORMAL"],colorOpt=["NORMAL","COLOR"],transparentOpt=["NORMAL","COLOR","TRANSPARENT"],e&&(materialOpt.push("USE_IBL"),transparentOpt.push("USE_IBL")),xe=Lt(pixelOpt),ge=Lt(materialOpt),we=Lt(colorOpt),Me=Lt(transparentOpt)}function st(){t.deleteProgram(Me),t.deleteProgram(we),t.deleteProgram(ge),t.deleteProgram(xe)}function at(){let i=o.webgl2?window.top.document.asygl2[e]:window.top.document.asygl[e];i.gl=t,i.nlights=l.length,i.Nmaterials=m,i.maxMaterials=r,i.pixelShader=xe,i.materialShader=ge,i.colorShader=we,i.transparentShader=Me}function ot(t,e){let i;return o.webgl2&&(i=t.getContext("webgl2",{alpha:e}),o.embedded&&!i)?(o.webgl2=!1,o.ibl=!1,ht(!1),null):(i||(o.webgl2=!1,o.ibl=!1,i=t.getContext("webgl",{alpha:e})),i||alert("Could not initialize WebGL"),i)}function ht(s=!0){if(o.ibl&&(o.webgl2=!0),e=o.background[3]<1,o.embedded){let a=window.top.document;if(s&&(n=o.canvas.getContext("2d")),i=o.webgl2?a.offscreen2:a.offscreen,i||(i=a.createElement("canvas"),o.webgl2?a.offscreen2=i:a.offscreen=i),o.webgl2?a.asygl2||(a.asygl2=Array(2)):a.asygl||(a.asygl=Array(2)),asygl=o.webgl2?a.asygl2:a.asygl,asygl[e]&&asygl[e].gl)!function(){let i=o.webgl2?window.top.document.asygl2[e]:window.top.document.asygl[e];t=i.gl,d=i.nlights,m=i.Nmaterials,r=i.maxMaterials,xe=i.pixelShader,ge=i.materialShader,we=i.colorShader,Me=i.transparentShader}(),(l.length!=d||Math.min(c.length,r)>m)&&(rt(),at());else{if(rc=ot(i,e),!rc)return;t=rc,rt(),o.webgl2?a.asygl2[e]={}:a.asygl[e]={},at()}}else t=ot(o.canvas,e),rt();$=t.getExtension("OES_element_index_uint"),q=t.TRIANGLES,K=new mt(t.POINTS),Z=new mt(t.LINES),Q=new mt,J=new mt,tt=new mt,et=new mt}function lt(t,e,i,n=[]){let r=o.webgl2?"300 es":"100",s=Array(...n),a=[["nlights",0==V?l.length:0],["Nmaterials",m]],h=[["int","Nlights",Math.max(l.length,1)]];o.webgl2&&s.push("WEBGL2"),o.ibl&&a.push(["ROUGHNESS_STEP_COUNT",8..toFixed(2)]),o.orthographic&&s.push("ORTHOGRAPHIC"),macros_str=a.map(t=>`#define ${t[0]} ${t[1]}`).join("\n"),define_str=s.map(t=>"#define "+t).join("\n"),const_str=h.map(t=>`const ${t[0]} ${t[1]}=${t[2]};`).join("\n"),ext_str=[].map(t=>`#extension ${t}: enable`).join("\n"),shaderSrc=`#version ${r}\n${ext_str}\n${define_str}\n${const_str}\n${macros_str}\n\n\n#ifdef GL_FRAGMENT_PRECISION_HIGH\nprecision highp float;\n#else\nprecision mediump float;\n#endif\n \n${e}\n `;let c=t.createShader(i);return t.shaderSource(c,shaderSrc),t.compileShader(c),t.getShaderParameter(c,t.COMPILE_STATUS)?c:(alert(t.getShaderInfoLog(c)),null)}function ct(e,i,n,r=t.ARRAY_BUFFER){return e.length>0&&(0==i&&(i=t.createBuffer(),n=!0),t.bindBuffer(r,i),n&&t.bufferData(r,e,t.STATIC_DRAW)),i}function dt(e,i,n=e.indices){if(0==e.indices.length)return;let r=i!=xe;!function(e,i){let n=i==xe;t.useProgram(i),t.enableVertexAttribArray(Tt),n&&t.enableVertexAttribArray(It);let r=!n&&l.length>0;r&&t.enableVertexAttribArray(yt);t.enableVertexAttribArray(At),i.projViewMatUniform=t.getUniformLocation(i,"projViewMat"),i.viewMatUniform=t.getUniformLocation(i,"viewMat"),i.normMatUniform=t.getUniformLocation(i,"normMat"),(i==we||i==Me)&&t.enableVertexAttribArray(Et);if(r)for(let t=0;t<l.length;++t)l[t].setUniform(i,t);for(let t=0;t<e.materials.length;++t)e.materials[t].setUniform(i,t);t.uniformMatrix4fv(i.projViewMatUniform,!1,E),t.uniformMatrix4fv(i.viewMatUniform,!1,A),t.uniformMatrix3fv(i.normMatUniform,!1,I)}(e,i),null!=W&&(t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,j),t.uniform1i(t.getUniformLocation(i,"reflBRDFSampler"),0),t.activeTexture(t.TEXTURE1),t.bindTexture(t.TEXTURE_2D,W),t.uniform1i(t.getUniformLocation(i,"diffuseSampler"),1),t.activeTexture(t.TEXTURE2),t.bindTexture(t.TEXTURE_2D,G),t.uniform1i(t.getUniformLocation(i,"reflImgSampler"),2));let s=U||e.partial||!e.rendered;e.verticesBuffer=ct(new Float32Array(e.vertices),e.verticesBuffer,s),t.vertexAttribPointer(Tt,3,t.FLOAT,!1,r?24:16,0),r?l.length>0&&t.vertexAttribPointer(yt,3,t.FLOAT,!1,24,12):t.vertexAttribPointer(It,1,t.FLOAT,!1,16,12),e.materialsBuffer=ct(new Int16Array(e.materialIndices),e.materialsBuffer,s),t.vertexAttribPointer(At,1,t.SHORT,!1,2,0),i!=we&&i!=Me||(e.colorsBuffer=ct(new Float32Array(e.colors),e.colorsBuffer,s),t.vertexAttribPointer(Et,4,t.FLOAT,!0,0,0)),e.indicesBuffer=ct($?new Uint32Array(n):new Uint16Array(n),e.indicesBuffer,s,t.ELEMENT_ARRAY_BUFFER),e.rendered=!0,t.drawElements(r?V?t.LINES:e.type:t.POINTS,n.length,$?t.UNSIGNED_INT:t.UNSIGNED_SHORT,0)}class mt{constructor(t){this.type=t||q,this.verticesBuffer=0,this.materialsBuffer=0,this.colorsBuffer=0,this.indicesBuffer=0,this.rendered=!1,this.partial=!1,this.clear()}clear(){this.vertices=[],this.materialIndices=[],this.colors=[],this.indices=[],this.nvertices=0,this.materials=[],this.materialTable=[]}vertex(t,e){return this.vertices.push(t[0]),this.vertices.push(t[1]),this.vertices.push(t[2]),this.vertices.push(e[0]),this.vertices.push(e[1]),this.vertices.push(e[2]),this.materialIndices.push(it),this.nvertices++}Vertex(t,e,i=[0,0,0,0]){return this.vertices.push(t[0]),this.vertices.push(t[1]),this.vertices.push(t[2]),this.vertices.push(e[0]),this.vertices.push(e[1]),this.vertices.push(e[2]),this.materialIndices.push(it),this.colors.push(i[0]),this.colors.push(i[1]),this.colors.push(i[2]),this.colors.push(i[3]),this.nvertices++}vertex0(t,e){return this.vertices.push(t[0]),this.vertices.push(t[1]),this.vertices.push(t[2]),this.vertices.push(e),this.materialIndices.push(it),this.nvertices++}iVertex(t,e,i,n=[0,0,0,0]){let r=6*t;this.vertices[r]=e[0],this.vertices[r+1]=e[1],this.vertices[r+2]=e[2],this.vertices[r+3]=i[0],this.vertices[r+4]=i[1],this.vertices[r+5]=i[2],this.materialIndices[t]=it;let s=4*t;this.colors[s]=n[0],this.colors[s+1]=n[1],this.colors[s+2]=n[2],this.colors[s+3]=n[3],this.indices.push(t)}append(t){ft(this.vertices,t.vertices),ft(this.materialIndices,t.materialIndices),ft(this.colors,t.colors),function(t,e,i){let n=t.length,r=e.length;t.length+=e.length;for(let s=0;s<r;++s)t[n+s]=e[s]+i}(this.indices,t.indices,this.nvertices),this.nvertices+=t.nvertices}}function ft(t,e){let i=t.length,n=e.length;t.length+=n;for(let r=0;r<n;++r)t[i+r]=e[r]}class ut{constructor(){this.data=new mt,this.Onscreen=!1,this.m=[]}offscreen(t){let e=E,i=t[0],n=i[0],r=i[1],s=i[2],a=1/(e[3]*n+e[7]*r+e[11]*s+e[15]);this.x=this.X=(e[0]*n+e[4]*r+e[8]*s+e[12])*a,this.y=this.Y=(e[1]*n+e[5]*r+e[9]*s+e[13])*a;for(let i=1,n=t.length;i<n;++i){let n=t[i],r=n[0],s=n[1],a=n[2],o=1/(e[3]*r+e[7]*s+e[11]*a+e[15]),h=(e[0]*r+e[4]*s+e[8]*a+e[12])*o,l=(e[1]*r+e[5]*s+e[9]*a+e[13])*o;h<this.x?this.x=h:h>this.X&&(this.X=h),l<this.y?this.y=l:l>this.Y&&(this.Y=l)}return(this.X<-1.01||this.x>1.01||this.Y<-1.01||this.y>1.01)&&(this.Onscreen=!1,!0)}T(t){let e=this.c[0],i=this.c[1],n=this.c[2],r=t[0]-e,s=t[1]-i,a=t[2]-n;return[r*I[0]+s*I[3]+a*I[6]+e,r*I[1]+s*I[4]+a*I[7]+i,r*I[2]+s*I[5]+a*I[8]+n]}Tcorners(t,e){return[this.T(t),this.T([t[0],t[1],e[2]]),this.T([t[0],e[1],t[2]]),this.T([t[0],e[1],e[2]]),this.T([e[0],t[1],t[2]]),this.T([e[0],t[1],e[2]]),this.T([e[0],e[1],t[2]]),this.T(e)]}setMaterial(t,e){null==t.materialTable[this.MaterialIndex]&&(t.materials.length>=m&&(t.partial=!0,e()),t.materialTable[this.MaterialIndex]=t.materials.length,t.materials.push(c[this.MaterialIndex])),it=t.materialTable[this.MaterialIndex]}render(){let t;var e,i;if(this.setMaterialIndex(),0==this.CenterIndex?(e=this.Min,i=this.Max,t=[e,[e[0],e[1],i[2]],[e[0],i[1],e[2]],[e[0],i[1],i[2]],[i[0],e[1],e[2]],[i[0],e[1],i[2]],[i[0],i[1],e[2]],i]):(this.c=o.Centers[this.CenterIndex-1],t=this.Tcorners(this.Min,this.Max)),this.offscreen(t))return this.data.clear(),void this.notRendered();let n,r=this.controlpoints;if(0==this.CenterIndex){if(!U&&this.Onscreen)return void this.append();n=r}else{let t=r.length;n=Array(t);for(let e=0;e<t;++e)n[e]=this.T(r[e])}let s=o.orthographic?1:this.Min[2]/o.maxBound[2],a=.75*Math.hypot(s*(S.xmax-S.xmin),s*(S.ymax-S.ymin))/b;this.res2=a*a,this.Epsilon=.1*a,this.data.clear(),this.notRendered(),this.Onscreen=!0,this.process(n)}}function pt(t,e){let i=t[0],n=t.length;for(let r=1;r<n;++r)i=e(i,t[r]);return i}class vt extends ut{constructor(t,e,i,n,r,s){super(),this.controlpoints=t,this.CenterIndex=e,this.MaterialIndex=i,this.color=n;let a=t.length;if(n){let t=n[0][3]+n[1][3]+n[2][3];this.transparent=16==a||4==a?t+n[3][3]<1020:t<765}else this.transparent=c[i].diffuse[3]<1;this.vertex=this.transparent?this.data.Vertex.bind(this.data):this.data.vertex.bind(this.data);let o=this.L2norm2(this.controlpoints),h=Math.sqrt(1e3*Number.EPSILON*o);this.epsilon=o*Number.EPSILON,this.Min=r||this.Bounds(this.controlpoints,Math.min,h),this.Max=s||this.Bounds(this.controlpoints,Math.max,h)}setMaterialIndex(){this.transparent?this.setMaterial(tt,Ie):this.color?this.setMaterial(J,Ae):this.setMaterial(Q,ye)}cornerbound(t,e){let i=e(t[0],t[3]);return i=e(i,t[12]),e(i,t[15])}controlbound(t,e){let i=e(t[1],t[2]);return i=e(i,t[4]),i=e(i,t[5]),i=e(i,t[6]),i=e(i,t[7]),i=e(i,t[8]),i=e(i,t[9]),i=e(i,t[10]),i=e(i,t[11]),i=e(i,t[13]),e(i,t[14])}bound(t,e,i,n,r){if(i=e(i,this.cornerbound(t,e)),e(-1,1)*(i-this.controlbound(t,e))>=-n||0==r)return i;--r,n*=2;let s=new Nt(t[0],t[1],t[2],t[3]),a=new Nt(t[4],t[5],t[6],t[7]),o=new Nt(t[8],t[9],t[10],t[11]),h=new Nt(t[12],t[13],t[14],t[15]),l=new Nt(t[0],t[4],t[8],t[12]),c=new Nt(s.m0,a.m0,o.m0,h.m0),d=new Nt(s.m3,a.m3,o.m3,h.m3),m=new Nt(s.m5,a.m5,o.m5,h.m5),f=new Nt(s.m4,a.m4,o.m4,h.m4),u=new Nt(s.m2,a.m2,o.m2,h.m2),p=new Nt(t[3],t[7],t[11],t[15]),v=[t[0],s.m0,s.m3,s.m5,l.m0,c.m0,d.m0,m.m0,l.m3,c.m3,d.m3,m.m3,l.m5,c.m5,d.m5,m.m5];i=this.bound(v,e,i,n,r);let x=[l.m5,c.m5,d.m5,m.m5,l.m4,c.m4,d.m4,m.m4,l.m2,c.m2,d.m2,m.m2,t[12],h.m0,h.m3,h.m5];i=this.bound(x,e,i,n,r);let g=[m.m5,f.m5,u.m5,p.m5,m.m4,f.m4,u.m4,p.m4,m.m2,f.m2,u.m2,p.m2,h.m5,h.m4,h.m2,t[15]];i=this.bound(g,e,i,n,r);let w=[s.m5,s.m4,s.m2,t[3],m.m0,f.m0,u.m0,p.m0,m.m3,f.m3,u.m3,p.m3,m.m5,f.m5,u.m5,p.m5];return this.bound(w,e,i,n,r)}cornerboundtri(t,e){let i=e(t[0],t[6]);return e(i,t[9])}controlboundtri(t,e){let i=e(t[1],t[2]);return i=e(i,t[3]),i=e(i,t[4]),i=e(i,t[5]),i=e(i,t[7]),e(i,t[8])}boundtri(t,e,i,n,r){if(i=e(i,this.cornerboundtri(t,e)),e(-1,1)*(i-this.controlboundtri(t,e))>=-n||0==r)return i;--r,n*=2;let s=new _t(t),a=[s.l003,s.l102,s.l012,s.l201,s.l111,s.l021,s.l300,s.l210,s.l120,s.l030];i=this.boundtri(a,e,i,n,r);let o=[s.l300,s.r102,s.r012,s.r201,s.r111,s.r021,s.r300,s.r210,s.r120,s.r030];i=this.boundtri(o,e,i,n,r);let h=[s.l030,s.u102,s.u012,s.u201,s.u111,s.u021,s.r030,s.u210,s.u120,s.u030];i=this.boundtri(h,e,i,n,r);let l=[s.r030,s.u201,s.r021,s.u102,s.c111,s.r012,s.l030,s.l120,s.l210,s.l300];return this.boundtri(l,e,i,n,r)}Bounds(t,e,i){let n=Array(3),r=t.length,s=Array(r);for(let a=0;a<3;++a){for(let e=0;e<r;++e)s[e]=t[e][a];n[a]=16==r?this.bound(s,e,s[0],i,p):10==r?this.boundtri(s,e,s[0],i,p):pt(s,e)}return[n[0],n[1],n[2]]}L2norm2(t){let e=t[0],i=0,n=t.length;for(let r=1;r<n;++r)i=Math.max(i,St([t[r][0]-e[0],t[r][1]-e[1],t[r][2]-e[2]]));return i}processTriangle(t){let e=t[0],i=t[1],n=t[2],r=Pt(Vt([i[0]-e[0],i[1]-e[1],i[2]-e[2]],[n[0]-e[0],n[1]-e[1],n[2]-e[2]]));if(!this.offscreen([e,i,n])){let t,s,a;this.color?(t=this.data.Vertex(e,r,this.color[0]),s=this.data.Vertex(i,r,this.color[1]),a=this.data.Vertex(n,r,this.color[2])):(t=this.vertex(e,r),s=this.vertex(i,r),a=this.vertex(n,r)),0==V?(this.data.indices.push(t),this.data.indices.push(s),this.data.indices.push(a)):(this.data.indices.push(t),this.data.indices.push(s),this.data.indices.push(s),this.data.indices.push(a),this.data.indices.push(a),this.data.indices.push(t)),this.append()}}processQuad(t){let e=t[0],i=t[1],n=t[2],r=t[3],s=Vt([i[0]-e[0],i[1]-e[1],i[2]-e[2]],[n[0]-i[0],n[1]-i[1],n[2]-i[2]]),a=Vt([n[0]-r[0],n[1]-r[1],n[2]-r[2]],[r[0]-e[0],r[1]-e[1],r[2]-e[2]]),o=Pt([s[0]+a[0],s[1]+a[1],s[2]+a[2]]);if(!this.offscreen([e,i,n,r])){let t,s,a,h;this.color?(t=this.data.Vertex(e,o,this.color[0]),s=this.data.Vertex(i,o,this.color[1]),a=this.data.Vertex(n,o,this.color[2]),h=this.data.Vertex(r,o,this.color[3])):(t=this.vertex(e,o),s=this.vertex(i,o),a=this.vertex(n,o),h=this.vertex(r,o)),0==V?(this.data.indices.push(t),this.data.indices.push(s),this.data.indices.push(a),this.data.indices.push(t),this.data.indices.push(a),this.data.indices.push(h)):(this.data.indices.push(t),this.data.indices.push(s),this.data.indices.push(s),this.data.indices.push(a),this.data.indices.push(a),this.data.indices.push(h),this.data.indices.push(h),this.data.indices.push(t)),this.append()}}curve(t,e,i,n,r){new wt([t[e],t[i],t[n],t[r]],0,it,this.Min,this.Max).render()}process(t){if(this.transparent&&1!=V&&(it=this.color?-1-it:1+it),10==t.length)return this.process3(t);if(3==t.length)return this.processTriangle(t);if(4==t.length)return this.processQuad(t);if(1==V)return this.curve(t,0,4,8,12),this.curve(t,12,13,14,15),this.curve(t,15,11,7,3),void this.curve(t,3,2,1,0);let e=t[0],i=t[3],n=t[12],r=t[15],s=this.normal(i,t[2],t[1],e,t[4],t[8],n);St(s)<this.epsilon&&(s=this.normal(i,t[2],t[1],e,t[13],t[14],r),St(s)<this.epsilon&&(s=this.normal(r,t[11],t[7],i,t[4],t[8],n)));let a=this.normal(e,t[4],t[8],n,t[13],t[14],r);St(a)<this.epsilon&&(a=this.normal(e,t[4],t[8],n,t[11],t[7],i),St(a)<this.epsilon&&(a=this.normal(i,t[2],t[1],e,t[13],t[14],r)));let o=this.normal(n,t[13],t[14],r,t[11],t[7],i);St(o)<this.epsilon&&(o=this.normal(n,t[13],t[14],r,t[2],t[1],e),St(o)<this.epsilon&&(o=this.normal(e,t[4],t[8],n,t[11],t[7],i)));let h=this.normal(r,t[11],t[7],i,t[2],t[1],e);if(St(h)<this.epsilon&&(h=this.normal(r,t[11],t[7],i,t[4],t[8],n),St(h)<this.epsilon&&(h=this.normal(n,t[13],t[14],r,t[2],t[1],e))),this.color){let l=this.color[0],c=this.color[1],d=this.color[2],m=this.color[3],f=this.data.Vertex(e,s,l),u=this.data.Vertex(n,a,c),p=this.data.Vertex(r,o,d),v=this.data.Vertex(i,h,m);this.Render(t,f,u,p,v,e,n,r,i,!1,!1,!1,!1,l,c,d,m)}else{let l=this.vertex(e,s),c=this.vertex(n,a),d=this.vertex(r,o),m=this.vertex(i,h);this.Render(t,l,c,d,m,e,n,r,i,!1,!1,!1,!1)}this.data.indices.length>0&&this.append()}append(){this.transparent?tt.append(this.data):this.color?J.append(this.data):Q.append(this.data)}notRendered(){this.transparent?tt.rendered=!1:this.color?J.rendered=!1:Q.rendered=!1}Render(t,e,i,n,r,s,a,o,h,l,c,d,m,f,u,p,v){let x=this.Distance(t);if(x[0]<this.res2&&x[1]<this.res2)this.offscreen([s,a,o])||(0==V?(this.data.indices.push(e),this.data.indices.push(i),this.data.indices.push(n)):(this.data.indices.push(e),this.data.indices.push(i),this.data.indices.push(i),this.data.indices.push(n))),this.offscreen([s,o,h])||(0==V?(this.data.indices.push(e),this.data.indices.push(n),this.data.indices.push(r)):(this.data.indices.push(n),this.data.indices.push(r),this.data.indices.push(r),this.data.indices.push(e)));else{if(this.offscreen(t))return;let g=t[0],w=t[3],M=t[12],b=t[15];if(x[0]<this.res2){let x=new Ot(g,t[1],t[2],w),R=new Ot(t[4],t[5],t[6],t[7]),T=new Ot(t[8],t[9],t[10],t[11]),y=new Ot(M,t[13],t[14],b),A=[g,x.m0,x.m3,x.m5,t[4],R.m0,R.m3,R.m5,t[8],T.m0,T.m3,T.m5,M,y.m0,y.m3,y.m5],E=[x.m5,x.m4,x.m2,w,R.m5,R.m4,R.m2,t[7],T.m5,T.m4,T.m2,t[11],y.m5,y.m4,y.m2,b],I=this.normal(A[12],A[13],A[14],A[15],A[11],A[7],A[3]);St(I)<=this.epsilon&&(I=this.normal(A[12],A[13],A[14],A[15],A[2],A[1],A[0]),St(I)<=this.epsilon&&(I=this.normal(A[0],A[4],A[8],A[12],A[11],A[7],A[3])));let L=this.normal(E[3],E[2],E[1],E[0],E[4],E[8],E[12]);St(L)<=this.epsilon&&(L=this.normal(E[3],E[2],E[1],E[0],E[13],E[14],E[15]),St(L)<=this.epsilon&&(L=this.normal(E[15],E[11],E[7],E[3],E[4],E[8],E[12])));let N=this.Epsilon,O=[.5*(a[0]+o[0]),.5*(a[1]+o[1]),.5*(a[2]+o[2])];if(!c)if(c=zt(M,t[13],t[14],b)<this.res2){let t=Pt(this.differential(E[12],E[8],E[4],E[0]));O=[O[0]-N*t[0],O[1]-N*t[1],O[2]-N*t[2]]}else O=A[15];let _=[.5*(h[0]+s[0]),.5*(h[1]+s[1]),.5*(h[2]+s[2])];if(!m)if(m=zt(g,t[1],t[2],w)<this.res2){let t=Pt(this.differential(A[3],A[7],A[11],A[15]));_=[_[0]-N*t[0],_[1]-N*t[1],_[2]-N*t[2]]}else _=E[0];if(f){let t=Array(4),x=Array(4);for(let e=0;e<4;++e)t[e]=.5*(u[e]+p[e]),x[e]=.5*(v[e]+f[e]);let g=this.data.Vertex(O,I,t),w=this.data.Vertex(_,L,x);this.Render(A,e,i,g,w,s,a,O,_,l,c,!1,m,f,u,t,x),this.Render(E,w,g,n,r,_,O,o,h,!1,c,d,m,x,t,p,v)}else{let t=this.vertex(O,I),f=this.vertex(_,L);this.Render(A,e,i,t,f,s,a,O,_,l,c,!1,m),this.Render(E,f,t,n,r,_,O,o,h,!1,c,d,m)}return}if(x[1]<this.res2){let x=new Ot(g,t[4],t[8],M),R=new Ot(t[1],t[5],t[9],t[13]),T=new Ot(t[2],t[6],t[10],t[14]),y=new Ot(w,t[7],t[11],b),A=[g,t[1],t[2],w,x.m0,R.m0,T.m0,y.m0,x.m3,R.m3,T.m3,y.m3,x.m5,R.m5,T.m5,y.m5],E=[x.m5,R.m5,T.m5,y.m5,x.m4,R.m4,T.m4,y.m4,x.m2,R.m2,T.m2,y.m2,M,t[13],t[14],b],I=this.normal(A[0],A[4],A[8],A[12],A[13],A[14],A[15]);St(I)<=this.epsilon&&(I=this.normal(A[0],A[4],A[8],A[12],A[11],A[7],A[3]),St(I)<=this.epsilon&&(I=this.normal(A[3],A[2],A[1],A[0],A[13],A[14],A[15])));let L=this.normal(E[15],E[11],E[7],E[3],E[2],E[1],E[0]);St(L)<=this.epsilon&&(L=this.normal(E[15],E[11],E[7],E[3],E[4],E[8],E[12]),St(L)<=this.epsilon&&(L=this.normal(E[12],E[13],E[14],E[15],E[2],E[1],E[0])));let N=this.Epsilon,O=[.5*(s[0]+a[0]),.5*(s[1]+a[1]),.5*(s[2]+a[2])];if(!l)if(l=zt(g,t[4],t[8],M)<this.res2){let t=Pt(this.differential(E[0],E[1],E[2],E[3]));O=[O[0]-N*t[0],O[1]-N*t[1],O[2]-N*t[2]]}else O=A[12];let _=[.5*(o[0]+h[0]),.5*(o[1]+h[1]),.5*(o[2]+h[2])];if(!d)if(d=zt(b,t[11],t[7],w)<this.res2){let t=Pt(this.differential(A[15],A[14],A[13],A[12]));_=[_[0]-N*t[0],_[1]-N*t[1],_[2]-N*t[2]]}else _=E[3];if(f){let t=Array(4),x=Array(4);for(let e=0;e<4;++e)t[e]=.5*(f[e]+u[e]),x[e]=.5*(p[e]+v[e]);let g=this.data.Vertex(O,I,t),w=this.data.Vertex(_,L,x);this.Render(A,e,g,w,r,s,O,_,h,l,!1,d,m,f,t,x,v),this.Render(E,g,i,n,w,O,a,o,_,l,c,d,!1,t,u,p,x)}else{let t=this.vertex(O,I),f=this.vertex(_,L);this.Render(A,e,t,f,r,s,O,_,h,l,!1,d,m),this.Render(E,t,i,n,f,O,a,o,_,l,c,d,!1)}return}let R=new Ot(g,t[1],t[2],w),T=new Ot(t[4],t[5],t[6],t[7]),y=new Ot(t[8],t[9],t[10],t[11]),A=new Ot(M,t[13],t[14],b),E=new Ot(g,t[4],t[8],M),I=new Ot(R.m0,T.m0,y.m0,A.m0),L=new Ot(R.m3,T.m3,y.m3,A.m3),N=new Ot(R.m5,T.m5,y.m5,A.m5),O=new Ot(R.m4,T.m4,y.m4,A.m4),_=new Ot(R.m2,T.m2,y.m2,A.m2),P=new Ot(w,t[7],t[11],b),S=[g,R.m0,R.m3,R.m5,E.m0,I.m0,L.m0,N.m0,E.m3,I.m3,L.m3,N.m3,E.m5,I.m5,L.m5,N.m5],U=[E.m5,I.m5,L.m5,N.m5,E.m4,I.m4,L.m4,N.m4,E.m2,I.m2,L.m2,N.m2,M,A.m0,A.m3,A.m5],V=[N.m5,O.m5,_.m5,P.m5,N.m4,O.m4,_.m4,P.m4,N.m2,O.m2,_.m2,P.m2,A.m5,A.m4,A.m2,b],B=[R.m5,R.m4,R.m2,w,N.m0,O.m0,_.m0,P.m0,N.m3,O.m3,_.m3,P.m3,N.m5,O.m5,_.m5,P.m5],D=S[15],C=this.normal(S[0],S[4],S[8],S[12],S[13],S[14],S[15]);St(C)<this.epsilon&&(C=this.normal(S[0],S[4],S[8],S[12],S[11],S[7],S[3]),St(C)<this.epsilon&&(C=this.normal(S[3],S[2],S[1],S[0],S[13],S[14],S[15])));let F=this.normal(U[12],U[13],U[14],U[15],U[11],U[7],U[3]);St(F)<this.epsilon&&(F=this.normal(U[12],U[13],U[14],U[15],U[2],U[1],U[0]),St(F)<this.epsilon&&(F=this.normal(U[0],U[4],U[8],U[12],U[11],U[7],U[3])));let z=this.normal(V[15],V[11],V[7],V[3],V[2],V[1],V[0]);St(z)<this.epsilon&&(z=this.normal(V[15],V[11],V[7],V[3],V[4],V[8],V[12]),St(z)<this.epsilon&&(z=this.normal(V[12],V[13],V[14],V[15],V[2],V[1],V[0])));let H=this.normal(B[3],B[2],B[1],B[0],B[4],B[8],B[12]);St(H)<this.epsilon&&(H=this.normal(B[3],B[2],B[1],B[0],B[13],B[14],B[15]),St(H)<this.epsilon&&(H=this.normal(B[15],B[11],B[7],B[3],B[4],B[8],B[12])));let X=this.normal(V[3],V[2],V[1],D,V[4],V[8],V[12]),G=this.Epsilon,W=[.5*(s[0]+a[0]),.5*(s[1]+a[1]),.5*(s[2]+a[2])];if(!l)if(l=zt(g,t[4],t[8],M)<this.res2){let t=Pt(this.differential(U[0],U[1],U[2],U[3]));W=[W[0]-G*t[0],W[1]-G*t[1],W[2]-G*t[2]]}else W=S[12];let j=[.5*(a[0]+o[0]),.5*(a[1]+o[1]),.5*(a[2]+o[2])];if(!c)if(c=zt(M,t[13],t[14],b)<this.res2){let t=Pt(this.differential(V[12],V[8],V[4],V[0]));j=[j[0]-G*t[0],j[1]-G*t[1],j[2]-G*t[2]]}else j=U[15];let k=[.5*(o[0]+h[0]),.5*(o[1]+h[1]),.5*(o[2]+h[2])];if(!d)if(d=zt(b,t[11],t[7],w)<this.res2){let t=Pt(this.differential(B[15],B[14],B[13],B[12]));k=[k[0]-G*t[0],k[1]-G*t[1],k[2]-G*t[2]]}else k=V[3];let Y=[.5*(h[0]+s[0]),.5*(h[1]+s[1]),.5*(h[2]+s[2])];if(!m)if(m=zt(g,t[1],t[2],w)<this.res2){let t=Pt(this.differential(S[3],S[7],S[11],S[15]));Y=[Y[0]-G*t[0],Y[1]-G*t[1],Y[2]-G*t[2]]}else Y=B[0];if(f){let t=Array(4),x=Array(4),g=Array(4),w=Array(4),M=Array(4);for(let e=0;e<4;++e)t[e]=.5*(f[e]+u[e]),x[e]=.5*(u[e]+p[e]),g[e]=.5*(p[e]+v[e]),w[e]=.5*(v[e]+f[e]),M[e]=.5*(t[e]+g[e]);let b=this.data.Vertex(W,C,t),R=this.data.Vertex(j,F,x),T=this.data.Vertex(k,z,g),y=this.data.Vertex(Y,H,w),A=this.data.Vertex(D,X,M);this.Render(S,e,b,A,y,s,W,D,Y,l,!1,!1,m,f,t,M,w),this.Render(U,b,i,R,A,W,a,j,D,l,c,!1,!1,t,u,x,M),this.Render(V,A,R,n,T,D,j,o,k,!1,c,d,!1,M,x,p,g),this.Render(B,y,A,T,r,Y,D,k,h,!1,!1,d,m,w,M,g,v)}else{let t=this.vertex(W,C),f=this.vertex(j,F),u=this.vertex(k,z),p=this.vertex(Y,H),v=this.vertex(D,X);this.Render(S,e,t,v,p,s,W,D,Y,l,!1,!1,m),this.Render(U,t,i,f,v,W,a,j,D,l,c,!1,!1),this.Render(V,v,f,n,u,D,j,o,k,!1,c,d,!1),this.Render(B,p,v,u,r,Y,D,k,h,!1,!1,d,m)}}}process3(t){if(1==V)return this.curve(t,0,1,3,6),this.curve(t,6,7,8,9),void this.curve(t,9,5,2,0);let e=t[0],i=t[6],n=t[9],r=this.normal(n,t[5],t[2],e,t[1],t[3],i),s=this.normal(e,t[1],t[3],i,t[7],t[8],n),a=this.normal(i,t[7],t[8],n,t[5],t[2],e);if(this.color){let o=this.color[0],h=this.color[1],l=this.color[2],c=this.data.Vertex(e,r,o),d=this.data.Vertex(i,s,h),m=this.data.Vertex(n,a,l);this.Render3(t,c,d,m,e,i,n,!1,!1,!1,o,h,l)}else{let o=this.vertex(e,r),h=this.vertex(i,s),l=this.vertex(n,a);this.Render3(t,o,h,l,e,i,n,!1,!1,!1)}this.data.indices.length>0&&this.append()}Render3(t,e,i,n,r,s,a,o,h,l,c,d,m){if(this.Distance3(t)<this.res2)this.offscreen([r,s,a])||(0==V?(this.data.indices.push(e),this.data.indices.push(i),this.data.indices.push(n)):(this.data.indices.push(e),this.data.indices.push(i),this.data.indices.push(i),this.data.indices.push(n),this.data.indices.push(n),this.data.indices.push(e)));else{if(this.offscreen(t))return;let f=t[0],u=t[1],p=t[2],v=t[3],x=t[4],g=t[5],w=t[6],M=t[7],b=t[8],R=t[9],T=[.5*(R[0]+g[0]),.5*(R[1]+g[1]),.5*(R[2]+g[2])],y=[.5*(R[0]+b[0]),.5*(R[1]+b[1]),.5*(R[2]+b[2])],A=[.5*(g[0]+p[0]),.5*(g[1]+p[1]),.5*(g[2]+p[2])],E=[.5*(b[0]+x[0]),.5*(b[1]+x[1]),.5*(b[2]+x[2])],I=[.5*(b[0]+M[0]),.5*(b[1]+M[1]),.5*(b[2]+M[2])],L=[.5*(p[0]+x[0]),.5*(p[1]+x[1]),.5*(p[2]+x[2])],N=[.5*(p[0]+f[0]),.5*(p[1]+f[1]),.5*(p[2]+f[2])],O=[.5*(x[0]+v[0]),.5*(x[1]+v[1]),.5*(x[2]+v[2])],_=[.5*(M[0]+w[0]),.5*(M[1]+w[1]),.5*(M[2]+w[2])],P=[.5*(f[0]+u[0]),.5*(f[1]+u[1]),.5*(f[2]+u[2])],S=[.5*(u[0]+v[0]),.5*(u[1]+v[1]),.5*(u[2]+v[2])],U=[.5*(v[0]+w[0]),.5*(v[1]+w[1]),.5*(v[2]+w[2])],V=[.5*(T[0]+A[0]),.5*(T[1]+A[1]),.5*(T[2]+A[2])],B=[.5*(y[0]+I[0]),.5*(y[1]+I[1]),.5*(y[2]+I[2])],D=[.5*(A[0]+N[0]),.5*(A[1]+N[1]),.5*(A[2]+N[2])],C=[.5*E[0]+.25*(x[0]+u[0]),.5*E[1]+.25*(x[1]+u[1]),.5*E[2]+.25*(x[2]+u[2])],F=[.5*(I[0]+_[0]),.5*(I[1]+_[1]),.5*(I[2]+_[2])],z=[.5*L[0]+.25*(x[0]+M[0]),.5*L[1]+.25*(x[1]+M[1]),.5*L[2]+.25*(x[2]+M[2])],H=[.25*(g[0]+x[0])+.5*O[0],.25*(g[1]+x[1])+.5*O[1],.25*(g[2]+x[2])+.5*O[2]],X=[.5*(P[0]+S[0]),.5*(P[1]+S[1]),.5*(P[2]+S[2])],G=[.5*(S[0]+U[0]),.5*(S[1]+U[1]),.5*(S[2]+U[2])],W=[.5*(z[0]+X[0]),.5*(z[1]+X[1]),.5*(z[2]+X[2])],j=[.5*(z[0]+G[0]),.5*(z[1]+G[1]),.5*(z[2]+G[2])],k=[.5*(X[0]+G[0]),.5*(X[1]+G[1]),.5*(X[2]+G[2])],Y=[.5*(H[0]+F[0]),.5*(H[1]+F[1]),.5*(H[2]+F[2])],$=[.5*(B[0]+H[0]),.5*(B[1]+H[1]),.5*(B[2]+H[2])],q=[.5*(B[0]+F[0]),.5*(B[1]+F[1]),.5*(B[2]+F[2])],K=[.5*(V[0]+C[0]),.5*(V[1]+C[1]),.5*(V[2]+C[2])],Z=[.5*(D[0]+C[0]),.5*(D[1]+C[1]),.5*(D[2]+C[2])],Q=[.5*(V[0]+D[0]),.5*(V[1]+D[1]),.5*(V[2]+D[2])],J=[f,P,N,X,[.5*(L[0]+P[0]),.5*(L[1]+P[1]),.5*(L[2]+P[2])],D,k,W,Z,Q],tt=[k,G,j,U,[.5*(O[0]+_[0]),.5*(O[1]+_[1]),.5*(O[2]+_[2])],Y,w,_,F,q],et=[Q,K,V,$,[.5*(T[0]+E[0]),.5*(T[1]+E[1]),.5*(T[2]+E[2])],T,q,B,y,R],it=[q,$,Y,K,[.25*(A[0]+I[0]+S[0]+x[0]),.25*(A[1]+I[1]+S[1]+x[1]),.25*(A[2]+I[2]+S[2]+x[2])],j,Q,Z,W,k],nt=this.normal(k,j,Y,q,$,K,Q),rt=this.normal(q,$,K,Q,Z,W,k),st=this.normal(Q,Z,W,k,j,Y,q),at=this.Epsilon,ot=[.5*(s[0]+a[0]),.5*(s[1]+a[1]),.5*(s[2]+a[2])];if(!o)if(o=zt(w,M,b,R)<this.res2){let t=Pt(this.sumdifferential(it[0],it[2],it[5],it[9],it[1],it[3],it[6]));ot=[ot[0]-at*t[0],ot[1]-at*t[1],ot[2]-at*t[2]]}else ot=q;let ht=[.5*(a[0]+r[0]),.5*(a[1]+r[1]),.5*(a[2]+r[2])];if(!h)if(h=zt(f,p,g,R)<this.res2){let t=Pt(this.sumdifferential(it[6],it[3],it[1],it[0],it[7],it[8],it[9]));ht=[ht[0]-at*t[0],ht[1]-at*t[1],ht[2]-at*t[2]]}else ht=Q;let lt=[.5*(r[0]+s[0]),.5*(r[1]+s[1]),.5*(r[2]+s[2])];if(!l)if(l=zt(f,u,v,w)<this.res2){let t=Pt(this.sumdifferential(it[9],it[8],it[7],it[6],it[5],it[2],it[0]));lt=[lt[0]-at*t[0],lt[1]-at*t[1],lt[2]-at*t[2]]}else lt=k;if(c){let t=Array(4),f=Array(4),u=Array(4);for(let e=0;e<4;++e)t[e]=.5*(d[e]+m[e]),f[e]=.5*(m[e]+c[e]),u[e]=.5*(c[e]+d[e]);let p=this.data.Vertex(ot,nt,t),v=this.data.Vertex(ht,rt,f),x=this.data.Vertex(lt,st,u);this.Render3(J,e,x,v,r,lt,ht,!1,h,l,c,u,f),this.Render3(tt,x,i,p,lt,s,ot,o,!1,l,u,d,t),this.Render3(et,v,p,n,ht,ot,a,o,h,!1,f,t,m),this.Render3(it,p,v,x,ot,ht,lt,!1,!1,!1,t,f,u)}else{let t=this.vertex(ot,nt),c=this.vertex(ht,rt),d=this.vertex(lt,st);this.Render3(J,e,d,c,r,lt,ht,!1,h,l),this.Render3(tt,d,i,t,lt,s,ot,o,!1,l),this.Render3(et,c,t,n,ht,ot,a,o,h,!1),this.Render3(it,t,c,d,ot,ht,lt,!1,!1,!1)}}}Distance(t){let e=t[0],i=t[3],n=t[12],r=t[15],s=Ht(e,n,i,r);s=Math.max(zt(e,t[4],t[8],n)),s=Math.max(s,zt(t[1],t[5],t[9],t[13])),s=Math.max(s,zt(i,t[7],t[11],r)),s=Math.max(s,zt(t[2],t[6],t[10],t[14]));let a=Ht(e,i,n,r);return a=Math.max(a,zt(e,t[1],t[2],i)),a=Math.max(a,zt(t[4],t[5],t[6],t[7])),a=Math.max(a,zt(t[8],t[9],t[10],t[11])),a=Math.max(a,zt(n,t[13],t[14],r)),[s,a]}Distance3(t){let e=t[0],i=t[4],n=t[6],r=t[9],s=St([(e[0]+n[0]+r[0])*(1/3)-i[0],(e[1]+n[1]+r[1])*(1/3)-i[1],(e[2]+n[2]+r[2])*(1/3)-i[2]]);return s=Math.max(s,zt(e,t[1],t[3],n)),s=Math.max(s,zt(e,t[2],t[5],r)),Math.max(s,zt(n,t[7],t[8],r))}differential(t,e,i,n){let r=[3*(e[0]-t[0]),3*(e[1]-t[1]),3*(e[2]-t[2])];return St(r)>this.epsilon?r:(r=Ct(t,e,i),St(r)>this.epsilon?r:Ft(t,e,i,n))}sumdifferential(t,e,i,n,r,s,a){let o=this.differential(t,e,i,n),h=this.differential(t,r,s,a);return[o[0]+h[0],o[1]+h[1],o[2]+h[2]]}normal(t,e,i,n,r,s,a){let o=3*(r[0]-n[0]),h=3*(r[1]-n[1]),l=3*(r[2]-n[2]),c=3*(i[0]-n[0]),d=3*(i[1]-n[1]),m=3*(i[2]-n[2]),f=[h*m-l*d,l*c-o*m,o*d-h*c];if(St(f)>this.epsilon)return f;let u=[c,d,m],p=[o,h,l],v=Ct(n,i,e),x=Ct(n,r,s),g=Vt(x,u),w=Vt(p,v);if(f=[g[0]+w[0],g[1]+w[1],g[2]+w[2]],St(f)>this.epsilon)return f;let M=Ft(n,i,e,t),b=Ft(n,r,s,a);g=Vt(p,M),w=Vt(b,u);let R=Vt(x,v);return f=[g[0]+w[0]+R[0],g[1]+w[1]+R[1],g[2]+w[2]+R[2]],St(f)>this.epsilon?f:(g=Vt(b,v),w=Vt(x,M),f=[g[0]+w[0],g[1]+w[1],g[2]+w[2]],St(f)>this.epsilon?f:Vt(b,M))}}function xt(t){return 0<=t&&t<=1}class gt{constructor(t,e,i){const n=1e3*Number.EPSILON,r=n*n;if(Math.abs(t)<=n*Math.abs(e)+r*Math.abs(i))Math.abs(e)>n*Math.abs(i)?(this.roots=1,this.t1=-i/e):0==i?(this.roots=1,this.t1=0):this.roots=0;else{let r=.5*e/t,s=e*r;if(Math.abs(s)<=n*Math.abs(i)){let e=-i/t;e>=0?(this.roots=2,this.t2=Math.sqrt(e),this.t1=-this.t2):this.roots=0}else{let t=-2*i/s;if(t>-1){this.roots=2;let e=r*function(t){return t/(Math.sqrt(1+t)+1)}(t),i=-e-2*r;i<=e?(this.t1=i,this.t2=e):(this.t1=e,this.t2=i)}else-1==t?(this.roots=1,this.t1=this.t2=-r):this.roots=0}}}}class wt extends ut{constructor(t,e,i,n,r){if(super(),this.controlpoints=t,this.CenterIndex=e,this.MaterialIndex=i,n&&r)this.Min=n,this.Max=r;else{let t=this.Bounds(this.controlpoints);this.Min=t[0],this.Max=t[1]}}Bounds(t){let e=Array(3),i=Array(3),n=t.length,r=Array(n);for(let h=0;h<3;++h){for(let e=0;e<n;++e)r[e]=t[e][h];let l,c;if(l=c=r[0],4==n){l=Math.min(l,r[3]),c=Math.max(c,r[3]);let t=(s=r[0],a=r[1],o=r[2],[r[3]-s+3*(a-o),2*(s+o)-4*a,a-s]),e=new gt(t[0],t[1],t[2]);if(0!=e.roots&&xt(e.t1)){let t=Bt(r[0],r[1],r[2],r[3],e.t1);l=Math.min(l,t),c=Math.max(c,t)}if(2==e.roots&&xt(e.t2)){let t=Bt(r[0],r[1],r[2],r[3],e.t2);l=Math.min(l,t),c=Math.max(c,t)}}else{let t=r[1];l=Math.min(l,t),c=Math.max(c,t)}e[h]=l,i[h]=c}var s,a,o;return[[e[0],e[1],e[2]],[i[0],i[1],i[2]]]}setMaterialIndex(){this.setMaterial(Z,Te)}processLine(t){let e=t[0],i=t[1];if(!this.offscreen([e,i])){let t=[0,0,1];this.data.indices.push(this.data.vertex(e,t)),this.data.indices.push(this.data.vertex(i,t)),this.append()}}process(t){if(2==t.length)return this.processLine(t);let e=t[0],i=t[1],n=t[2],r=t[3],s=this.normal(Dt(e,i),Ct(e,i,n)),a=this.normal(Dt(n,r),Ct(r,n,i)),o=this.data.vertex(e,s),h=this.data.vertex(r,a);this.Render(t,o,h),this.data.indices.length>0&&this.append()}append(){Z.append(this.data)}notRendered(){Z.rendered=!1}Render(t,e,i){let n=t[0],r=t[1],s=t[2],a=t[3];if(zt(n,r,s,a)<this.res2)this.offscreen([n,a])||(this.data.indices.push(e),this.data.indices.push(i));else{if(this.offscreen(t))return;let o=[.5*(n[0]+r[0]),.5*(n[1]+r[1]),.5*(n[2]+r[2])],h=[.5*(r[0]+s[0]),.5*(r[1]+s[1]),.5*(r[2]+s[2])],l=[.5*(s[0]+a[0]),.5*(s[1]+a[1]),.5*(s[2]+a[2])],c=[.5*(o[0]+h[0]),.5*(o[1]+h[1]),.5*(o[2]+h[2])],d=[.5*(h[0]+l[0]),.5*(h[1]+l[1]),.5*(h[2]+l[2])],m=[.5*(c[0]+d[0]),.5*(c[1]+d[1]),.5*(c[2]+d[2])],f=[n,o,c,m],u=[m,d,l,a],p=this.normal(function(t,e,i,n){return[i[0]+n[0]-t[0]-e[0],i[1]+n[1]-t[1]-e[1],i[2]+n[2]-t[2]-e[2]]}(n,r,s,a),function(t,e,i,n){return[3*t[0]-5*e[0]+i[0]+n[0],3*t[1]-5*e[1]+i[1]+n[1],3*t[2]-5*e[2]+i[2]+n[2]]}(n,r,s,a)),v=this.data.vertex(m,p);this.Render(f,e,v),this.Render(u,v,i)}}normal(t,e){let i=Ut(t,t),n=Ut(t,e);return[i*e[0]-n*t[0],i*e[1]-n*t[1],i*e[2]-n*t[2]]}}class Mt extends ut{constructor(t,e,i){super(),this.controlpoint=t,this.width=e,this.CenterIndex=0,this.MaterialIndex=i,this.Min=t,this.Max=t}setMaterialIndex(){this.setMaterial(K,Re)}process(t){this.data.indices.push(this.data.vertex0(this.controlpoint,this.width)),this.append()}append(){K.append(this.data)}notRendered(){K.rendered=!1}}class bt extends ut{constructor(t,e){super(),this.CenterIndex=t,this.MaterialIndex=e,this.Min=this.Bounds(F,Math.min),this.Max=this.Bounds(F,Math.max),this.controlpoints=F,this.Normals=z,this.Colors=H,this.Indices=X,this.transparent=c[this.MaterialIndex].diffuse[3]<1}Bounds(t,e){let i=Array(3),n=t.length,r=Array(n);for(let s=0;s<3;++s){for(let e=0;e<n;++e)r[e]=t[e][s];i[s]=pt(r,e)}return[i[0],i[1],i[2]]}setMaterialIndex(){this.transparent?this.setMaterial(tt,Ie):this.setMaterial(et,Ee)}process(t){this.data.vertices=new Array(6*t.length),it=this.Colors.length>0?-1-it:1+it;for(let e=0,i=this.Indices.length;e<i;++e){let i=this.Indices[e],n=i[0],r=t[n[0]],s=t[n[1]],a=t[n[2]];if(!this.offscreen([r,s,a])){let t=i.length>1?i[1]:n;if(t&&0!=t.length||(t=n),this.Colors.length>0){let e=i.length>2?i[2]:n;e&&0!=e.length||(e=n);let o=this.Colors[e[0]],h=this.Colors[e[1]],l=this.Colors[e[2]];this.transparent|=o[3]+h[3]+l[3]<765,0==V?(this.data.iVertex(n[0],r,this.Normals[t[0]],o),this.data.iVertex(n[1],s,this.Normals[t[1]],h),this.data.iVertex(n[2],a,this.Normals[t[2]],l)):(this.data.iVertex(n[0],r,this.Normals[t[0]],o),this.data.iVertex(n[1],s,this.Normals[t[1]],h),this.data.iVertex(n[1],s,this.Normals[t[1]],h),this.data.iVertex(n[2],a,this.Normals[t[2]],l),this.data.iVertex(n[2],a,this.Normals[t[2]],l),this.data.iVertex(n[0],r,this.Normals[t[0]],o))}else 0==V?(this.data.iVertex(n[0],r,this.Normals[t[0]]),this.data.iVertex(n[1],s,this.Normals[t[1]]),this.data.iVertex(n[2],a,this.Normals[t[2]])):(this.data.iVertex(n[0],r,this.Normals[t[0]]),this.data.iVertex(n[1],s,this.Normals[t[1]]),this.data.iVertex(n[1],s,this.Normals[t[1]]),this.data.iVertex(n[2],a,this.Normals[t[2]]),this.data.iVertex(n[2],a,this.Normals[t[2]]),this.data.iVertex(n[0],r,this.Normals[t[0]]))}}this.data.nvertices=t.length,this.data.indices.length>0&&this.append()}append(){this.transparent?tt.append(this.data):et.append(this.data)}notRendered(){this.transparent?tt.rendered=!1:et.rendered=!1}}function Rt(){M=-Math.tan(.5*o.angleOfView)*o.maxBound[2],_.x=_.y=0,_.z=.5*(o.minBound[2]+o.maxBound[2]),x=v=o.zoom0,S.zmin=o.minBound[2],S.zmax=o.maxBound[2],P.x=P.y=0,Oe(),U=!0,Ne()}let Tt=0,yt=1,At=2,Et=3,It=4;function Lt(e=[]){let i=lt(t,vertex,t.VERTEX_SHADER,e),n=lt(t,fragment,t.FRAGMENT_SHADER,e),r=t.createProgram();return t.attachShader(r,i),t.attachShader(r,n),t.bindAttribLocation(r,Tt,"position"),t.bindAttribLocation(r,yt,"normal"),t.bindAttribLocation(r,At,"materialIndex"),t.bindAttribLocation(r,Et,"color"),t.bindAttribLocation(r,It,"width"),t.linkProgram(r),t.getProgramParameter(r,t.LINK_STATUS)||alert("Could not initialize shaders"),r}class Nt{constructor(t,e,i,n){this.m0=.5*(t+e);let r=.5*(e+i);this.m2=.5*(i+n),this.m3=.5*(this.m0+r),this.m4=.5*(r+this.m2),this.m5=.5*(this.m3+this.m4)}}class Ot{constructor(t,e,i,n){this.m0=[.5*(t[0]+e[0]),.5*(t[1]+e[1]),.5*(t[2]+e[2])];let r=.5*(e[0]+i[0]),s=.5*(e[1]+i[1]),a=.5*(e[2]+i[2]);this.m2=[.5*(i[0]+n[0]),.5*(i[1]+n[1]),.5*(i[2]+n[2])],this.m3=[.5*(this.m0[0]+r),.5*(this.m0[1]+s),.5*(this.m0[2]+a)],this.m4=[.5*(r+this.m2[0]),.5*(s+this.m2[1]),.5*(a+this.m2[2])],this.m5=[.5*(this.m3[0]+this.m4[0]),.5*(this.m3[1]+this.m4[1]),.5*(this.m3[2]+this.m4[2])]}}class _t{constructor(t){this.l003=t[0];let e=t[1],i=t[2],n=t[3],r=t[4],s=t[5];this.r300=t[6];let a=t[7],o=t[8];this.u030=t[9],this.u021=.5*(this.u030+s),this.u120=.5*(this.u030+o);let h=.5*(s+i),l=.5*(o+r),c=.5*(o+a),d=.5*(i+r);this.l012=.5*(i+this.l003);let m=.5*(r+n);this.r210=.5*(a+this.r300),this.l102=.5*(this.l003+e);let f=.5*(e+n);this.r201=.5*(n+this.r300),this.u012=.5*(this.u021+h),this.u210=.5*(this.u120+c),this.l021=.5*(h+this.l012);let u=.5*l+.25*(r+e);this.r120=.5*(c+this.r210);let p=.5*d+.25*(r+a),v=.25*(s+r)+.5*m;this.l201=.5*(this.l102+f),this.r102=.5*(f+this.r201),this.l210=.5*(p+this.l201),this.r012=.5*(p+this.r102),this.l300=.5*(this.l201+this.r102),this.r021=.5*(v+this.r120),this.u201=.5*(this.u210+v),this.r030=.5*(this.u210+this.r120),this.u102=.5*(this.u012+u),this.l120=.5*(this.l021+u),this.l030=.5*(this.u012+this.l021),this.l111=.5*(d+this.l102),this.r111=.5*(m+this.r210),this.u111=.5*(this.u021+l),this.c111=.25*(h+c+f+r)}}function Pt(t){let e=1/(Math.sqrt(t[0]*t[0]+t[1]*t[1]+t[2]*t[2])||1);return[t[0]*e,t[1]*e,t[2]*e]}function St(t){return t[0]*t[0]+t[1]*t[1]+t[2]*t[2]}function Ut(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function Vt(t,e){return[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]]}function Bt(t,e,i,n,r){let s=1-r,a=s*s;return a*s*t+r*(3*(a*e+r*s*i)+r*r*n)}function Dt(t,e){return[e[0]-t[0],e[1]-t[1],e[2]-t[2]]}function Ct(t,e,i){return[3*(t[0]+i[0])-6*e[0],3*(t[1]+i[1])-6*e[1],3*(t[2]+i[2])-6*e[2]]}function Ft(t,e,i,n){return[n[0]-t[0]+3*(e[0]-i[0]),n[1]-t[1]+3*(e[1]-i[1]),n[2]-t[2]+3*(e[2]-i[2])]}function zt(t,e,i,n){let r=[1/3*(n[0]-t[0]),1/3*(n[1]-t[1]),1/3*(n[2]-t[2])];return Math.max(St([e[0]-r[0]-t[0],e[1]-r[1]-t[1],e[2]-r[2]-t[2]]),St([n[0]-r[0]-i[0],n[1]-r[1]-i[1],n[2]-r[2]-i[2]]))}function Ht(t,e,i,n){let r=[e[0]-t[0],e[1]-t[1],e[2]-t[2]],s=[n[0]-i[0],n[1]-i[1],n[2]-i[2]];return Math.max(St(Vt(r,Pt(s))),St(Vt(s,Pt(r))))/9}function Xt(t){return[Math.min(t[0][0],t[1][0],t[2][0],t[3][0],t[4][0],t[5][0],t[6][0],t[7][0]),Math.min(t[0][1],t[1][1],t[2][1],t[3][1],t[4][1],t[5][1],t[6][1],t[7][1]),Math.min(t[0][2],t[1][2],t[2][2],t[3][2],t[4][2],t[5][2],t[6][2],t[7][2])]}function Gt(t){return[Math.max(t[0][0],t[1][0],t[2][0],t[3][0],t[4][0],t[5][0],t[6][0],t[7][0]),Math.max(t[0][1],t[1][1],t[2][1],t[3][1],t[4][1],t[5][1],t[6][1],t[7][1]),Math.max(t[0][2],t[1][2],t[2][2],t[3][2],t[4][2],t[5][2],t[6][2],t[7][2])]}function Wt(t){ae||oe(),B=!0,D=t.clientX,C=t.clientY}let jt,kt,Yt=!1;function $t(t){return Math.hypot(t[0].pageX-t[1].pageX,t[0].pageY-t[1].pageY)}function qt(t){t.preventDefault(),ae||oe();let e=t.targetTouches;ue=pe=Yt=!1,fe||(1!=e.length||B||(kt=(new Date).getTime(),touchId=e[0].identifier,D=e[0].pageX,C=e[0].pageY),2!=e.length||B||(touchId=e[0].identifier,jt=$t(e),Yt=!0))}function Kt(t){B=!1}function Zt(t,e,i,n,r){if(t==i&&e==n)return;let[s,a]=function(t,e){let i=ne(t),n=ne(e),r=Ut(i,n);return[r>1?0:r<-1?f:Math.acos(r),Pt(Vt(i,n))]}([t,-e],[i,-n]);mat4.fromRotation(O,2*r*R*s/v,a),mat4.multiply(T,O,T)}function Qt(t,e,i,n){let r=1/v;P.x+=(i-t)*r*s,P.y-=(n-e)*r*a}function Jt(t,e,i,n){o.orthographic?Qt(t,e,i,n):(_.x+=(i-t)*(S.xmax-S.xmin),_.y-=(n-e)*(S.ymax-S.ymin))}function te(){var t,e;t=A,e=T,mat4.fromTranslation(O,[_.x,_.y,_.z]),mat4.invert(N,O),mat4.multiply(t,e,N),mat4.multiply(t,O,t),mat4.translate(A,A,[_.x,_.y,0]),mat3.fromMat4(L,A),mat3.invert(I,L),mat4.multiply(E,y,A)}function ee(){let t=Math.sqrt(Number.MAX_VALUE),e=1/t;v<=e&&(v=e),v>=t&&(v=t),(1.5*v<x||v>1.5*x)&&(U=!0,x=v)}function ie(t){let e=o.zoomStep*a*t;const i=Math.log(.1*Number.MAX_VALUE)/Math.log(o.zoomFactor);Math.abs(e)<i&&(v*=o.zoomFactor**e,ee())}function ne(t){let e=t[0],i=t[1],n=Math.hypot(e,i);return n>1&&(denom=1/n,e*=denom,i*=denom),[e,i,Math.sqrt(Math.max(1-i*i-e*e,0))]}function re(t,e,i,n){ie(e-n)}function se(t,e,i,n=1){let r;switch(i){case 1:r=Zt;break;case 2:r=Qt;break;case 3:r=re;break;case 4:r=Jt;break;default:r=(t,e,i,n)=>{}}r((D-s)/s,(C-a)/a,(t-s)/s,(e-a)/a,n),D=t,C=e,Oe(),Ne()}let ae=0;function oe(){ae=1,o.canvas.addEventListener("wheel",de,!1)}function he(){let t,e,i;[t,e,i]=function(){let t=Array(3),e=Array(3),i=Array(3),n=_.x,r=_.y,s=.5*(S.zmin+S.zmax);for(let a=0;a<3;++a){let h=0,l=0,c=0,d=4*a;for(let t=0;t<4;++t){let e=4*t,i=T[e],a=T[e+1],m=T[e+2],f=T[e+3],u=o.Transform[d+t];h+=u*(f-n*i-r*a-s*m),c+=u*a,l+=u*(f-n*i-r*a)}t[a]=h,e[a]=c,i[a]=l}return[t,e,i]}();let n=o.orthographic?" orthographic(":" perspective(",r="".padStart(n.length),s="currentprojection=\n"+n+"camera=("+t+"),\n"+r+"up=("+e+"),\n"+r+"target=("+i+"),\n"+r+"zoom="+v*o.initialZoom/o.zoom0;return o.orthographic||(s+=",\n"+r+"angle="+2*Math.atan(Math.tan(.5*o.angleOfView)/v)/u),0==g&&0==w||(s+=",\n"+r+"viewportshift=("+g+","+w+")"),o.orthographic||(s+=",\n"+r+"autoadjust=false"),s+=");\n",window.parent.asyProjection=!0,s}function le(t){if(ae||oe(),o.embedded&&ae&&27==t.keyCode)return ae=0,void o.canvas.removeEventListener("wheel",de,!1);let e=[];switch(t.key){case"x":e=[1,0,0];break;case"y":e=[0,1,0];break;case"z":e=[0,0,1];break;case"h":mat4.identity(T),Rt(),window.top.asyWebApplication&&window.top.asyWebApplication.setProjection(""),window.parent.asyProjection=!1;break;case"m":++V,3==V&&(V=0),2!=V&&(o.embedded||st(),rt(o.ibl)),U=!0,Ne();break;case"+":case"=":case">":v*=o.zoomFactor,ce();break;case"-":case"_":case"<":v/=o.zoomFactor,ce();break;case"c":window.top.asyWebApplication||prompt("Ctrl+c Enter to copy currentprojection to clipboard; then append to asy file:",he())}e.length>0&&(mat4.rotate(T,T,.1,e),te(),Ne())}function ce(){ee(),Oe(),Ne()}function de(t){t.preventDefault(),t.deltaY<0?v*=o.zoomFactor:v/=o.zoomFactor,ce()}function me(t){if(!B)return;let e,i=t.clientX,n=t.clientY;e=t.getModifierState("Control")?2:t.getModifierState("Shift")?3:t.getModifierState("Alt")?4:1,se(i,n,e)}let fe=!1,ue=!1,pe=!1;function ve(t){if(t.preventDefault(),fe)return;let e=t.targetTouches;if(!Yt&&1==e.length&&touchId==e[0].identifier){let t=e[0].pageX,i=e[0].pageY,n=t-D,r=i-C,s=n*n+r*r<=o.shiftHoldDistance*o.shiftHoldDistance;if(s&&!ue&&!pe&&(new Date).getTime()-kt>o.shiftWaitTime&&(navigator.vibrate&&window.navigator.vibrate(o.vibrateTime),ue=!0),ue)se(t,i,2);else if(!s){pe=!0,se(e[0].pageX,e[0].pageY,1,.5)}}if(Yt&&!ue&&2==e.length&&touchId==e[0].identifier){let t=$t(e),i=t-jt;fe=!0,i*=o.zoomPinchFactor,i>o.zoomPinchCap&&(i=o.zoomPinchCap),i<-o.zoomPinchCap&&(i=-o.zoomPinchCap),ie(i/b),jt=t,ue=pe=fe=!1,Oe(),Ne()}}let xe,ge,we,Me,be=[];function Re(){dt(K,xe),K.clear()}function Te(){dt(Z,ge),Z.clear()}function ye(){dt(Q,ge),Q.clear()}function Ae(){dt(J,we),J.clear()}function Ee(){dt(et,Me),et.rendered=!1,et.clear()}function Ie(){let e=tt.indices;if(V>0)return dt(tt,Me,e),void tt.clear();if(e.length>0){!function(t){let e=A[2],i=A[6],n=A[10];be.length=t.length;for(let r=0;r<t.length;++r){let s=6*r;be[r]=e*t[s]+i*t[s+1]+n*t[s+2]}}(tt.vertices);let i=e.length/3,n=Array(i).fill().map((t,e)=>e);n.sort((function(t,i){let n=3*t;Ia=e[n],Ib=e[n+1],Ic=e[n+2];let r=3*i;return IA=e[r],IB=e[r+1],IC=e[r+2],be[Ia]+be[Ib]+be[Ic]<be[IA]+be[IB]+be[IC]?-1:1}));let r=Array(e.length);for(let t=0;t<i;++t){let i=3*n[t];r[3*t]=e[i],r[3*t+1]=e[i+1],r[3*t+2]=e[i+2]}t.depthMask(!1),dt(tt,Me,r),tt.rendered=!1,t.depthMask(!0)}tt.clear()}function Le(){Re(),Te(),ye(),Ae(),Ee(),Ie(),requestAnimationFrame(Le)}function Ne(){o.embedded&&(i.width=o.canvasWidth,i.height=o.canvasHeight,_e()),t.clearColor(o.background[0],o.background[1],o.background[2],o.background[3]),t.clear(t.COLOR_BUFFER_BIT|t.DEPTH_BUFFER_BIT);for(const t of h)t.render();Le(),o.embedded&&(n.clearRect(0,0,o.canvasWidth,o.canvasHeight),n.drawImage(i,0,0)),0==V&&(U=!1)}function Oe(){!function(t,e,i,n){let r=t/e;g=(i/t+o.viewportShift[0])*v,w=(n/e+o.viewportShift[1])*v;let s=1/v;if(o.orthographic){let t=o.maxBound[0]-o.minBound[0],e=o.maxBound[1]-o.minBound[1];if(t<e*r){let t=.5*e*r*s,i=2*t*g,n=e*s*w;S.xmin=-t-i,S.xmax=t-i,S.ymin=o.minBound[1]*s-n,S.ymax=o.maxBound[1]*s-n}else{let e=.5*t*s/r,i=t*s*g,n=2*e*w;S.xmin=o.minBound[0]*s-i,S.xmax=o.maxBound[0]*s-i,S.ymin=-e-n,S.ymax=e-n}}else{let t=M*s,e=t*r,i=2*e*g,n=2*t*w;S.xmin=-e-i,S.xmax=e-i,S.ymin=-t-n,S.ymax=t-n}}(o.canvasWidth,o.canvasHeight,P.x,P.y),(o.orthographic?mat4.ortho:mat4.frustum)(y,S.xmin,S.xmax,S.ymin,S.ymax,-S.zmax,-S.zmin),te(),window.top.asyWebApplication&&window.top.asyWebApplication.setProjection(he())}function _e(){t.viewportWidth=o.canvasWidth,t.viewportHeight=o.canvasHeight,t.viewport(.5*(o.canvas.width-o.canvasWidth),.5*(o.canvas.height-o.canvasHeight),o.canvasWidth,o.canvasHeight),t.scissor(0,0,o.canvas.width,o.canvas.height)}function Pe(t,e){t>void 0&&(t=void 0),e>void 0&&(e=void 0),P.x*=t/o.canvasWidth,P.y*=e/o.canvasHeight,o.canvasWidth=t,o.canvasHeight=e,o.embedded&&(o.canvas.width=i.width=o.canvasWidth,o.canvas.height=i.height=o.canvasHeight),b=Math.hypot(o.canvasWidth,o.canvasHeight),s=.5*o.canvas.width,a=.5*o.canvas.height,R=1+8*Math.hypot(o.viewportMargin[0],o.viewportMargin[1])/b,_e(),Oe(),U=!0}function Se(){if(o.zoom0=o.initialZoom,window.top.asyWebApplication&&""==window.top.asyWebApplication.getProjection()&&(window.parent.asyProjection=!1),o.absolute&&!o.embedded)o.canvasWidth=o.canvasWith0*window.devicePixelRatio,o.canvasHeight=o.canvasHeight0*window.devicePixelRatio;else{let t=o.canvasWith0/o.canvasHeight0;o.canvasWidth=Math.max(window.innerWidth-10,10),o.canvasHeight=Math.max(window.innerHeight-10,10),!o.orthographic&&!window.parent.asyProjection&&o.canvasWidth<o.canvasHeight*t&&(o.zoom0*=o.canvasWidth/(o.canvasHeight*t))}o.canvas.width=o.canvasWidth,o.canvas.height=o.canvasHeight;window.innerWidth,window.innerHeight;let t=1/o.zoom0;o.viewportShift[0]*=t,o.viewportShift[1]*=t,Pe(o.canvasWidth,o.canvasHeight),Rt()}class Ue{constructor(t,e){if(this.center=t,e){let t=e[0],i=e[1];this.ct=Math.cos(t),this.st=Math.sin(t),this.cp=Math.cos(i),this.sp=Math.sin(i)}}T0(t){return[t[0]+this.center[0],t[1]+this.center[1],t[2]+this.center[2]]}T(t){let e=t[0],i=t[1],n=t[2],r=e*this.ct+n*this.st;return[r*this.cp-i*this.sp+this.center[0],r*this.sp+i*this.cp+this.center[1],-e*this.st+n*this.ct+this.center[2]]}}function Ve(t,e,i){let n=[t(e),t([e[0],e[1],i[2]]),t([e[0],i[1],e[2]]),t([e[0],i[1],i[2]]),t([i[0],e[1],e[2]]),t([i[0],e[1],i[2]]),t([i[0],i[1],e[2]]),t(i)];return[Xt(n),Gt(n)]}let Be=4/3*(Math.sqrt(2)-1);async function De(t){return(await fetch(t)).arrayBuffer()}function Ce(t){return t.getBytes().filter((t,e)=>e%4!=3)}function Fe(e,i,n=t.RGB16F){let r=e.width(),s=e.height(),a=t.createTexture();return t.activeTexture(t.TEXTURE0+i),t.bindTexture(t.TEXTURE_2D,a),t.pixelStorei(t.UNPACK_ALIGNMENT,1),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texImage2D(t.TEXTURE_2D,0,n,r,s,0,t.RGB,t.FLOAT,Ce(e)),a}window.webGLStart=function(){o.canvas=document.getElementById("Asymptote"),o.embedded=window.top.document!=document,ht(),t.enable(t.BLEND),t.blendFunc(t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA),t.enable(t.DEPTH_TEST),t.enable(t.SCISSOR_TEST),o.canvas.onmousedown=Wt,document.onmouseup=Kt,document.onmousemove=me,o.canvas.onkeydown=le,o.embedded||oe(),o.canvas.addEventListener("touchstart",qt,!1),o.canvas.addEventListener("touchend",Kt,!1),o.canvas.addEventListener("touchcancel",Kt,!1),o.canvas.addEventListener("touchleave",Kt,!1),o.canvas.addEventListener("touchmove",ve,!1),document.addEventListener("keydown",le,!1),o.canvasWith0=o.canvasWidth,o.canvasHeight0=o.canvasHeight,mat4.identity(T),0!=window.innerWidth&&0!=window.innerHeight&&Se(),window.addEventListener("resize",Se,!1),o.ibl&&async function(){let e=o.imageURL+o.image+"/";function i(t){return new Promise(e=>setTimeout(e,t))}for(;!Module.EXRLoader;)await i(0);promises=[De(o.imageURL+"refl.exr").then(t=>{let e=new Module.EXRLoader(t);j=Fe(e,0)}),De(e+"diffuse.exr").then(t=>{let e=new Module.EXRLoader(t);W=Fe(e,1)})],refl_promise=[],refl_promise.push(De(e+"refl0.exr"));for(let t=1;t<=8;++t)refl_promise.push(De(e+"refl"+t+"w.exr"));finished_promise=Promise.all(refl_promise).then(e=>{let i=t.createTexture();t.activeTexture(t.TEXTURE0+2),t.pixelStorei(t.UNPACK_ALIGNMENT,1),t.bindTexture(t.TEXTURE_2D,i),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAX_LEVEL,e.length-1),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR_MIPMAP_LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texParameterf(t.TEXTURE_2D,t.TEXTURE_MIN_LOD,0),t.texParameterf(t.TEXTURE_2D,t.TEXTURE_MAX_LOD,8);for(let i=0;i<e.length;++i){let n=new Module.EXRLoader(e[i]);t.texImage2D(t.TEXTURE_2D,i,t.RGB16F,n.width(),n.height(),0,t.RGB,t.FLOAT,Ce(n))}G=i}),promises.push(finished_promise),await Promise.all(promises)}().then(k).then(Rt)},window.light=function(t,e){l.push(new nt(t,e))},window.material=function(t,e,i,n,r,s){c.push(new Y(t,e,i,n,r,s))},window.patch=function(t,e,i,n){h.push(new vt(t,e,i,n))},window.curve=function(t,e,i){h.push(new wt(t,e,i))},window.pixel=function(t,e,i){h.push(new Mt(t,e,i))},window.triangles=function(t,e){h.push(new bt(t,e)),window.Positions=F=[],window.Normals=z=[],window.Colors=H=[],window.Indices=X=[]},window.sphere=function(t,e,i,n,r){let s,a,o,l,c,d,m=.524670512339254,f=.595936986722291,u=.954967051233925,p=.0820155480083437,v=.996685028842544,x=.0549670512339254,g=.998880711874577,w=.0405017186586849,M=[[[1,0,0],[1,0,m],[f,0,u],[p,0,v],[1,Be,0],[1,Be,m],[f,Be*f,u],[p,Be*p,v],[Be,1,0],[Be,1,m],[Be*f,f,u],[Be*p,p,v],[0,1,0],[0,1,m],[0,f,u],[0,p,v]],[[p,0,v],[p,Be*p,v],[x,0,g],[Be*p,p,v],[w,w,1],[.05*Be,0,1],[0,p,v],[0,x,g],[0,.05*Be,1],[0,0,1]]],b=new Ue(t,r);function R(t){let e=Array(t.length);for(let i=0;i<t.length;++i){let n=t[i];e[i]=c([s*n[0],a*n[1],o*n[2]])}return e}r?(l=1,d=0,c=b.T.bind(b)):(l=-1,d=-e,c=b.T0.bind(b));let T=Ve(c,[-e,-e,d],[e,e,e]),y=T[0],A=T[1];for(let t=-1;t<=1;t+=2){s=t*e;for(let t=-1;t<=1;t+=2){a=t*e;for(let t=l;t<=1;t+=2){o=t*e;for(let t=0;t<2;++t)h.push(new vt(R(M[t]),i,n,null,y,A))}}}},window.disk=function(t,e,i,n,r){let s=1-2*Be/3,a=[[1,0,0],[1,-Be,0],[Be,-1,0],[0,-1,0],[1,Be,0],[s,0,0],[0,-s,0],[-Be,-1,0],[Be,1,0],[0,s,0],[-s,0,0],[-1,-Be,0],[0,1,0],[-Be,1,0],[-1,Be,0],[-1,0,0]],o=new Ue(t,r),l=Ve(o.T.bind(o),[-e,-e,0],[e,e,0]);h.push(new vt(function(t){let i=Array(t.length);for(let n=0;n<t.length;++n){let r=t[n];i[n]=o.T([e*r[0],e*r[1],0])}return i}(a),i,n,null,l[0],l[1]))},window.cylinder=function(t,e,i,n,r,s,a){let o,l,c=[[1,0,0],[1,0,1/3],[1,0,2/3],[1,0,1],[1,Be,0],[1,Be,1/3],[1,Be,2/3],[1,Be,1],[Be,1,0],[Be,1,1/3],[Be,1,2/3],[Be,1,1],[0,1,0],[0,1,1/3],[0,1,2/3],[0,1,1]],d=new Ue(t,s);function m(t){let e=Array(t.length);for(let n=0;n<t.length;++n){let r=t[n];e[n]=d.T([o*r[0],l*r[1],i*r[2]])}return e}let f=Ve(d.T.bind(d),[-e,-e,0],[e,e,i]),u=f[0],p=f[1];for(let t=-1;t<=1;t+=2){o=t*e;for(let t=-1;t<=1;t+=2)l=t*e,h.push(new vt(m(c),n,r,null,u,p))}if(a){let e=d.T([0,0,i]);h.push(new wt([t,e],n,r,t,e))}},window.tube=function(t,e,i,n,r){let s=function(t,e,i,n,r){class s{constructor(t,e,i){this.p=t,this.r=e,this.t=i,this.s=Vt(i,e)}}let a=Number.EPSILON*Math.max(St(t),St(e),St(i),St(n));function o(r){if(1==r){let r=[n[0]-i[0],n[1]-i[1],n[2]-i[2]];return St(r)>a?Pt(r):(r=[2*i[0]-e[0]-n[0],2*i[1]-e[1]-n[1],2*i[2]-e[2]-n[2]],St(r)>a?Pt(r):[n[0]-t[0]+3*(e[0]-i[0]),n[1]-t[1]+3*(e[1]-i[1]),n[2]-t[2]+3*(e[2]-i[2])])}let s=[n[0]-t[0]+3*(e[0]-i[0]),n[1]-t[1]+3*(e[1]-i[1]),n[2]-t[2]+3*(e[2]-i[2])],o=[2*(t[0]+i[0])-4*e[0],2*(t[1]+i[1])-4*e[1],2*(t[2]+i[2])-4*e[2]],h=[e[0]-t[0],e[1]-t[1],e[2]-t[2]],l=r*r,c=[s[0]*l+o[0]*r+h[0],s[1]*l+o[1]*r+h[1],s[2]*l+o[2]*r+h[2]];return St(c)>a?Pt(c):(l=2*r,c=[s[0]*l+o[0],s[1]*l+o[1],s[2]*l+o[2]],St(c)>a?Pt(c):Pt(s))}let h=Array(r.length),l=[e[0]-t[0],e[1]-t[1],e[2]-t[2]];St(l)<a&&(l=[t[0]-2*e[0]+i[0],t[1]-2*e[1]+i[1],t[2]-2*e[2]+i[2]],St(l)<a&&(l=[n[0]-t[0]+3*(e[0]-i[0]),n[1]-t[1]+3*(e[1]-i[1]),n[2]-t[2]+3*(e[2]-i[2])])),l=Pt(l);let c=function(t){let e=Vt(t,[0,1,0]),i=Number.EPSILON*St(t);return St(e)>i?Pt(e):(e=Vt(t,[0,0,1]),St(e)>i?Pt(e):[1,0,0])}(l);h[0]=new s(t,c,l);for(let a=1;a<r.length;++a){let l=h[a-1],c=r[a],d=1-c,m=d*d,f=m*d,u=3*c;m*=u,d*=u*c;let p=c*c*c,v=[f*t[0]+m*e[0]+d*i[0]+p*n[0],f*t[1]+m*e[1]+d*i[1]+p*n[1],f*t[2]+m*e[2]+d*i[2]+p*n[2]],x=[v[0]-l.p[0],v[1]-l.p[1],v[2]-l.p[2]];if(0!=x[0]||0!=x[1]||0!=x[2]){let t=l.r,e=Pt(x),i=l.t,n=Ut(e,i),r=[i[0]-2*n*e[0],i[1]-2*n*e[1],i[2]-2*n*e[2]];i=o(c);let d=2*Ut(e,t),m=[t[0]-d*e[0],t[1]-d*e[1],t[2]-d*e[2]],f=Pt([i[0]-r[0],i[1]-r[1],i[2]-r[2]]),u=2*Ut(f,m);m=[m[0]-u*f[0],m[1]-u*f[1],m[2]-u*f[2]],h[a]=new s(v,Pt(m),Pt(i))}else h[a]=h[a-1]}return h}(t[0],t[1],t[2],t[3],[0,1/3,2/3,1]),a=Be*e,o=[[e,0],[e,a],[a,e],[0,e]];function l(e,r,a,l){let c=Array(16);for(let i=0;i<4;++i){let n=s[i],h=n.r[0],d=n.s[0],m=h*e+d*r,f=h*a+d*l;h=n.r[1],d=n.s[1];let u=h*e+d*r,p=h*a+d*l;h=n.r[2],d=n.s[2];let v=h*e+d*r,x=h*a+d*l,g=t[i],w=g[0];w1=g[1],w2=g[2];for(let t=0;t<4;++t){let e=o[t],n=e[0],r=e[1];c[4*i+t]=[m*n+f*r+w,u*n+p*r+w1,v*n+x*r+w2]}}h.push(new vt(c,i,n))}l(1,0,0,1),l(0,-1,1,0),l(-1,0,0,-1),l(0,1,-1,0),r&&h.push(new wt(t,i,n))},window.Positions=F,window.Normals=z,window.Colors=H,window.Indices=X}();