summaryrefslogtreecommitdiff
path: root/graphics/asymptote/base
diff options
context:
space:
mode:
Diffstat (limited to 'graphics/asymptote/base')
-rw-r--r--graphics/asymptote/base/asy-mode.el15
-rw-r--r--graphics/asymptote/base/graph3.asy104
-rw-r--r--graphics/asymptote/base/grid3.asy5
-rw-r--r--graphics/asymptote/base/map.asy62
-rw-r--r--graphics/asymptote/base/mapArray.asy2
-rw-r--r--graphics/asymptote/base/plain_boxes.asy28
-rw-r--r--graphics/asymptote/base/plain_picture.asy39
-rw-r--r--graphics/asymptote/base/plain_prethree.asy4
-rw-r--r--graphics/asymptote/base/plain_scaling.asy26
-rw-r--r--graphics/asymptote/base/plain_shipout.asy11
-rw-r--r--graphics/asymptote/base/simplex2.asy310
-rw-r--r--graphics/asymptote/base/slide.asy13
-rw-r--r--graphics/asymptote/base/three.asy52
-rw-r--r--graphics/asymptote/base/three_surface.asy166
-rw-r--r--graphics/asymptote/base/v3dheadertypes.asy2
-rw-r--r--graphics/asymptote/base/v3dtypes.asy2
-rw-r--r--graphics/asymptote/base/webgl/asygl.js4
17 files changed, 661 insertions, 184 deletions
diff --git a/graphics/asymptote/base/asy-mode.el b/graphics/asymptote/base/asy-mode.el
index 9f6eda793c..7b6d6f5c36 100644
--- a/graphics/asymptote/base/asy-mode.el
+++ b/graphics/asymptote/base/asy-mode.el
@@ -1600,5 +1600,20 @@ If optional argument Force is t then force compilation."
(asy-master-tex-view 'lasy-view-pdf-via-ps2pdf t t))
(define-key asy-mode-map (kbd "<C-M-S-return>") 'asy-master-tex-view-ps2pdf-f)
+;; Integrate with flycheck
+(with-eval-after-load 'flycheck
+ (flycheck-define-command-checker 'asy
+ "Syntax checking of asymptote files."
+ :command (append
+ (split-string (concat asy-command-location asy-command))
+ '("-noV" "-o" temporary-file-name source))
+ :error-patterns
+ ;; filename.asy: 123.45: warning: message
+ ;; filename.asy: 123.45: error message
+ '((warning line-start (file-name) ":" (* space) line (? ?\. column) ": warning: " (message) line-end)
+ (error line-start (file-name) ":" (* space) line (? ?\. column) ": " (message) line-end))
+ :modes '(asy-mode))
+ (add-to-list 'flycheck-checkers 'asy))
+
(provide `asy-mode)
;;; asy-mode.el ends here
diff --git a/graphics/asymptote/base/graph3.asy b/graphics/asymptote/base/graph3.asy
index b9b872f451..7a55ef863d 100644
--- a/graphics/asymptote/base/graph3.asy
+++ b/graphics/asymptote/base/graph3.asy
@@ -68,7 +68,7 @@ triple ticklabelshift(triple align, pen p=currentpen)
// Signature of routines that draw labelled paths with ticks and tick labels.
typedef void ticks3(picture, transform3, Label, path3, path3, pen,
arrowbar3, margin3, ticklocate, int[], bool opposite=false,
- bool primary=true);
+ bool primary=true, projection P);
// Label a tick on a frame.
void labeltick(picture pic, transform3 T, path3 g,
@@ -164,7 +164,8 @@ ticks3 Ticks3(int sign, Label F="", ticklabel ticklabel=null,
{
return new void(picture pic, transform3 t, Label L, path3 g, path3 g2, pen p,
arrowbar3 arrow, margin3 margin, ticklocate locate,
- int[] divisor, bool opposite, bool primary) {
+ int[] divisor, bool opposite, bool primary,
+ projection P=currentprojection) {
// Use local copy of context variables:
int Sign=opposite ? -1 : 1;
int sign=Sign*sign;
@@ -261,17 +262,18 @@ ticks3 Ticks3(int sign, Label F="", ticklabel ticklabel=null,
return new void(picture pic, transform3 T, Label L,
path3 g, path3 g2, pen p,
arrowbar3 arrow, margin3 margin=NoMargin3, ticklocate locate,
- int[] divisor, bool opposite, bool primary) {
+ int[] divisor, bool opposite, bool primary,
+ projection P=currentprojection) {
path3 G=T*g;
real limit=Step == 0 ? axiscoverage*arclength(G) : 0;
tickvalues values=modify(generateticks(sign,F,ticklabel,N,n,Step,step,
Size,size,identity(),1,
- project(G,currentprojection),
+ project(G,P),
limit,p,locate,divisor,
opposite));
Ticks3(sign,F,ticklabel,beginlabel,endlabel,values.major,values.minor,
values.N,begin,end,Size,size,extend,pTick,ptick)
- (pic,T,L,g,g2,p,arrow,margin,locate,divisor,opposite,primary);
+ (pic,T,L,g,g2,p,arrow,margin,locate,divisor,opposite,primary,P);
};
}
@@ -279,7 +281,8 @@ ticks3 NoTicks3()
{
return new void(picture pic, transform3 T, Label L, path3 g,
path3, pen p, arrowbar3 arrow, margin3 margin,
- ticklocate, int[], bool opposite, bool primary) {
+ ticklocate, int[], bool opposite, bool primary,
+ projection P=currentprojection) {
path3 G=T*g;
if(primary) draw(pic,margin(G,p).g,p,arrow,margin);
else draw(pic,G,p);
@@ -478,9 +481,10 @@ void axis(picture pic=currentpicture, Label L="", path3 g, path3 g2=nullpath3,
divisor=copy(divisor);
locate=locate.copy();
- pic.add(new void (picture f, transform3 t, transform3 T, triple, triple) {
+ pic.add(new void (picture f, transform3 t, transform3 T,
+ projection P, triple, triple) {
picture d;
- ticks(d,t,L,g,g2,p,arrow,margin,locate,divisor,opposite,true);
+ ticks(d,t,L,g,g2,p,arrow,margin,locate,divisor,opposite,true,P);
add(f,t*T*inverse(t)*d);
},above=above);
@@ -522,12 +526,13 @@ void xaxis3At(picture pic=currentpicture, Label L="", axis axis,
real xmin=-infinity, real xmax=infinity, pen p=currentpen,
ticks3 ticks=NoTicks3,
arrowbar3 arrow=None, margin3 margin=NoMargin3, bool above=true,
- bool opposite=false, bool opposite2=false, bool primary=true)
+ bool opposite=false, bool opposite2=false, bool primary=true,
+ projection P=currentprojection)
{
int type=axis.type;
int type2=axis.type2;
triple dir=axis.align.dir3 == O ?
- defaultdir(Y,Z,X,opposite^opposite2,currentprojection) : axis.align.dir3;
+ defaultdir(Y,Z,X,opposite^opposite2,P) : axis.align.dir3;
Label L=L.copy();
if(L.align.dir3 == O && L.align.dir == 0) L.align(opposite ? -dir : dir);
@@ -536,8 +541,8 @@ void xaxis3At(picture pic=currentpicture, Label L="", axis axis,
real y2,z2;
int[] divisor=copy(axis.xdivisor);
- pic.add(new void(picture f, transform3 t, transform3 T, triple lb,
- triple rt) {
+ pic.add(new void(picture f, transform3 t, transform3 T, projection P,
+ triple lb, triple rt) {
transform3 tinv=inverse(t);
triple a=xmin == -infinity ? tinv*(lb.x-min3(p).x,ytrans(t,y),
ztrans(t,z)) : (xmin,y,z);
@@ -573,7 +578,7 @@ void xaxis3At(picture pic=currentpicture, Label L="", axis axis,
ticks(d,t,L,a--b,finite(y0) && finite(z0) ? a2--b2 : nullpath3,
p,arrow,margin,
ticklocate(a.x,b.x,pic.scale.x,Dir(dir)),divisor,
- opposite,primary);
+ opposite,primary,P);
add(f,t*T*tinv*d);
},above=above);
@@ -621,7 +626,7 @@ void xaxis3At(picture pic=currentpicture, Label L="", axis axis,
ticks(d,pic.scaling3(warn=false),L,
(a.x,0,0)--(b.x,0,0),(a2.x,0,0)--(b2.x,0,0),p,arrow,margin,
ticklocate(a.x,b.x,pic.scale.x,Dir(dir)),divisor,
- opposite,primary);
+ opposite,primary,P);
frame f;
if(L.s != "") {
Label L0=L.copy();
@@ -655,12 +660,13 @@ void yaxis3At(picture pic=currentpicture, Label L="", axis axis,
real ymin=-infinity, real ymax=infinity, pen p=currentpen,
ticks3 ticks=NoTicks3,
arrowbar3 arrow=None, margin3 margin=NoMargin3, bool above=true,
- bool opposite=false, bool opposite2=false, bool primary=true)
+ bool opposite=false, bool opposite2=false, bool primary=true,
+ projection P=currentprojection)
{
int type=axis.type;
int type2=axis.type2;
triple dir=axis.align.dir3 == O ?
- defaultdir(X,Z,Y,opposite^opposite2,currentprojection) : axis.align.dir3;
+ defaultdir(X,Z,Y,opposite^opposite2,P) : axis.align.dir3;
Label L=L.copy();
if(L.align.dir3 == O && L.align.dir == 0) L.align(opposite ? -dir : dir);
@@ -669,8 +675,8 @@ void yaxis3At(picture pic=currentpicture, Label L="", axis axis,
real x2,z2;
int[] divisor=copy(axis.ydivisor);
- pic.add(new void(picture f, transform3 t, transform3 T, triple lb,
- triple rt) {
+ pic.add(new void(picture f, transform3 t, transform3 T, projection P,
+ triple lb, triple rt) {
transform3 tinv=inverse(t);
triple a=ymin == -infinity ? tinv*(xtrans(t,x),lb.y-min3(p).y,
ztrans(t,z)) : (x,ymin,z);
@@ -706,7 +712,7 @@ void yaxis3At(picture pic=currentpicture, Label L="", axis axis,
ticks(d,t,L,a--b,finite(x0) && finite(z0) ? a2--b2 : nullpath3,
p,arrow,margin,
ticklocate(a.y,b.y,pic.scale.y,Dir(dir)),divisor,
- opposite,primary);
+ opposite,primary,P);
add(f,t*T*tinv*d);
},above=above);
@@ -754,7 +760,7 @@ void yaxis3At(picture pic=currentpicture, Label L="", axis axis,
ticks(d,pic.scaling3(warn=false),L,
(0,a.y,0)--(0,b.y,0),(0,a2.y,0)--(0,a2.y,0),p,arrow,margin,
ticklocate(a.y,b.y,pic.scale.y,Dir(dir)),divisor,
- opposite,primary);
+ opposite,primary,P);
frame f;
if(L.s != "") {
Label L0=L.copy();
@@ -788,12 +794,13 @@ void zaxis3At(picture pic=currentpicture, Label L="", axis axis,
real zmin=-infinity, real zmax=infinity, pen p=currentpen,
ticks3 ticks=NoTicks3,
arrowbar3 arrow=None, margin3 margin=NoMargin3, bool above=true,
- bool opposite=false, bool opposite2=false, bool primary=true)
+ bool opposite=false, bool opposite2=false, bool primary=true,
+ projection P=currentprojection)
{
int type=axis.type;
int type2=axis.type2;
triple dir=axis.align.dir3 == O ?
- defaultdir(X,Y,Z,opposite^opposite2,currentprojection) : axis.align.dir3;
+ defaultdir(X,Y,Z,opposite^opposite2,P) : axis.align.dir3;
Label L=L.copy();
if(L.align.dir3 == O && L.align.dir == 0) L.align(opposite ? -dir : dir);
@@ -802,8 +809,8 @@ void zaxis3At(picture pic=currentpicture, Label L="", axis axis,
real x2,y2;
int[] divisor=copy(axis.zdivisor);
- pic.add(new void(picture f, transform3 t, transform3 T, triple lb,
- triple rt) {
+ pic.add(new void(picture f, transform3 t, transform3 T, projection P,
+ triple lb, triple rt) {
transform3 tinv=inverse(t);
triple a=zmin == -infinity ? tinv*(xtrans(t,x),ytrans(t,y),
lb.z-min3(p).z) : (x,y,zmin);
@@ -839,7 +846,7 @@ void zaxis3At(picture pic=currentpicture, Label L="", axis axis,
ticks(d,t,L,a--b,finite(x0) && finite(y0) ? a2--b2 : nullpath3,
p,arrow,margin,
ticklocate(a.z,b.z,pic.scale.z,Dir(dir)),divisor,
- opposite,primary);
+ opposite,primary,P);
add(f,t*T*tinv*d);
},above=above);
@@ -887,7 +894,7 @@ void zaxis3At(picture pic=currentpicture, Label L="", axis axis,
ticks(d,pic.scaling3(warn=false),L,
(0,0,a.z)--(0,0,b.z),(0,0,a2.z)--(0,0,a2.z),p,arrow,margin,
ticklocate(a.z,b.z,pic.scale.z,Dir(dir)),divisor,
- opposite,primary);
+ opposite,primary,P);
frame f;
if(L.s != "") {
Label L0=L.copy();
@@ -945,7 +952,8 @@ void autoscale3(picture pic=currentpicture, axis axis)
void xaxis3(picture pic=currentpicture, Label L="", axis axis=YZZero,
real xmin=-infinity, real xmax=infinity, pen p=currentpen,
ticks3 ticks=NoTicks3,
- arrowbar3 arrow=None, margin3 margin=NoMargin3, bool above=false)
+ arrowbar3 arrow=None, margin3 margin=NoMargin3, bool above=false,
+ projection P=currentprojection)
{
if(xmin > xmax) return;
@@ -1001,7 +1009,8 @@ void xaxis3(picture pic=currentpicture, Label L="", axis axis=YZZero,
bool back=false;
if(axis.type == Both) {
- triple v=currentprojection.normal;
+ projection P=centered(P,pic);
+ triple v=P.normal;
back=dot((0,pic.userMax().y-pic.userMin().y,0),v)*sgn(v.z) > 0;
}
@@ -1019,7 +1028,8 @@ void xaxis3(picture pic=currentpicture, Label L="", axis axis=YZZero,
void yaxis3(picture pic=currentpicture, Label L="", axis axis=XZZero,
real ymin=-infinity, real ymax=infinity, pen p=currentpen,
ticks3 ticks=NoTicks3,
- arrowbar3 arrow=None, margin3 margin=NoMargin3, bool above=false)
+ arrowbar3 arrow=None, margin3 margin=NoMargin3, bool above=false,
+ projection P=currentprojection)
{
if(ymin > ymax) return;
@@ -1076,7 +1086,8 @@ void yaxis3(picture pic=currentpicture, Label L="", axis axis=XZZero,
bool back=false;
if(axis.type == Both) {
- triple v=currentprojection.normal;
+ projection P=centered(P,pic);
+ triple v=P.normal;
back=dot((pic.userMax().x-pic.userMin().x,0,0),v)*sgn(v.z) > 0;
}
@@ -1094,7 +1105,8 @@ void yaxis3(picture pic=currentpicture, Label L="", axis axis=XZZero,
void zaxis3(picture pic=currentpicture, Label L="", axis axis=XYZero,
real zmin=-infinity, real zmax=infinity, pen p=currentpen,
ticks3 ticks=NoTicks3,
- arrowbar3 arrow=None, margin3 margin=NoMargin3, bool above=false)
+ arrowbar3 arrow=None, margin3 margin=NoMargin3, bool above=false,
+ projection P=currentprojection)
{
if(zmin > zmax) return;
@@ -1150,7 +1162,8 @@ void zaxis3(picture pic=currentpicture, Label L="", axis axis=XYZero,
bool back=false;
if(axis.type == Both) {
- triple v=currentprojection.vector();
+ projection P=centered(P,pic);
+ triple v=P.vector();
back=dot((pic.userMax().x-pic.userMin().x,0,0),v)*sgn(v.y) > 0;
}
@@ -1200,11 +1213,12 @@ void axes3(picture pic=currentpicture,
bool extend=false,
triple min=(-infinity,-infinity,-infinity),
triple max=(infinity,infinity,infinity),
- pen p=currentpen, arrowbar3 arrow=None, margin3 margin=NoMargin3)
+ pen p=currentpen, arrowbar3 arrow=None, margin3 margin=NoMargin3,
+ projection P=currentprojection)
{
- xaxis3(pic,xlabel,YZZero(extend),min.x,max.x,p,arrow,margin);
- yaxis3(pic,ylabel,XZZero(extend),min.y,max.y,p,arrow,margin);
- zaxis3(pic,zlabel,XYZero(extend),min.z,max.z,p,arrow,margin);
+ xaxis3(pic,xlabel,YZZero(extend),min.x,max.x,p,arrow,margin,P);
+ yaxis3(pic,ylabel,XZZero(extend),min.y,max.y,p,arrow,margin,P);
+ zaxis3(pic,zlabel,XYZero(extend),min.z,max.z,p,arrow,margin,P);
}
triple Scale(picture pic=currentpicture, triple v)
@@ -1659,7 +1673,7 @@ surface surface(picture pic=currentpicture, triple[][] f, bool[][] cond={})
surface s=surface(count);
s.index=new int[nx][ny];
- int k=-1;
+ int k=0;
for(int i=0; i < nx; ++i) {
bool[] condi,condp;
if(!all) {
@@ -1670,13 +1684,15 @@ surface surface(picture pic=currentpicture, triple[][] f, bool[][] cond={})
triple[] fp=f[i+1];
int[] indexi=s.index[i];
for(int j=0; j < ny; ++j) {
- if(all || (condi[j] && condi[j+1] && condp[j] && condp[j+1]))
- s.s[++k]=patch(new triple[] {
+ if(all || (condi[j] && condi[j+1] && condp[j] && condp[j+1])) {
+ s.s[k]=patch(new triple[] {
Scale(pic,fi[j]),
Scale(pic,fp[j]),
Scale(pic,fp[j+1]),
Scale(pic,fi[j+1])});
- indexi[j]=k;
+ indexi[j]=k;
+ ++k;
+ }
}
}
@@ -2062,11 +2078,13 @@ surface surface(picture pic=currentpicture, triple f(pair z),
surface s=surface(sx.length);
s.index=new int[nu][nv];
- int k=-1;
+ int k=0;
for(int i=0; i < nu; ++i) {
int[] indexi=s.index[i];
- for(int j=0; j < nv; ++j)
- indexi[j]=++k;
+ for(int j=0; j < nv; ++j) {
+ indexi[j]=k;
+ ++k;
+ }
}
for(int k=0; k < sx.length; ++k) {
diff --git a/graphics/asymptote/base/grid3.asy b/graphics/asymptote/base/grid3.asy
index 62807847ae..412992f6c4 100644
--- a/graphics/asymptote/base/grid3.asy
+++ b/graphics/asymptote/base/grid3.asy
@@ -193,7 +193,8 @@ void grid3(picture pic=currentpicture,
grid3routines gridroutinej=gridroutine[j];
for(int i=0; i < gridroutinej.length; ++i) {
grid3 gt=gridroutinej[i](pic);
- pic.add(new void(picture f, transform3 t, transform3 T, triple, triple) {
+ pic.add(new void(picture f, transform3 t, transform3 T,
+ projection P, triple, triple) {
picture d;
ticks3 ticks=Ticks3(1,F="%",ticklabel=null,
beginlabel=false,endlabel=false,
@@ -202,7 +203,7 @@ void grid3(picture pic=currentpicture,
Size=0,size=0,extend=true,
pTick=pGrid,ptick=pgrid);
ticks(d,t,"",gt.axea,gt.axeb,nullpen,None,NoMargin3,gt.locate,
- gt.bds.divisor,opposite=true,primary=false);
+ gt.bds.divisor,opposite=true,primary=false,P);
add(f,t*T*inverse(t)*d);
},above=above);
addPath(pic,gt.axea,pGrid);
diff --git a/graphics/asymptote/base/map.asy b/graphics/asymptote/base/map.asy
index 2b2277b956..06c61f7b4b 100644
--- a/graphics/asymptote/base/map.asy
+++ b/graphics/asymptote/base/map.asy
@@ -1,40 +1,36 @@
-// Create a struct <name> parameterized by types <key> and <value>,
-// that maps keys to values, defaulting to the value in <default>.
-void mapTemplate(string name, string key, string value, string default)
-{
- type(key,"Key");
- type(value,"Value");
- eval("Value default="+default,true);
+typedef import(Key, Value);
- eval("
- struct keyValue {
- Key key;
- Value T;
- void operator init(Key key) {
- this.key=key;
- }
- void operator init(Key key, Value T) {
- this.key=key;
- this.T=T;
- }
+struct keyValue {
+ Key key;
+ Value value;
+ void operator init(Key key) {
+ this.key=key;
}
+ void operator init(Key key, Value value) {
+ this.key=key;
+ this.value=value;
+ }
+}
- struct map {
- keyValue[] M;
- bool operator < (keyValue a, keyValue b) {return a.key < b.key;}
+// Map keys to values, defaulting to the value default.
- void add(Key key, Value T) {
- keyValue m=keyValue(key,T);
- M.insert(search(M,m,operator <)+1,m);
- }
- Value lookup(Key key) {
- int i=search(M,keyValue(key),operator <);
- if(i >= 0 && M[i].key == key) return M[i].T;
- return default;
- }
+struct map {
+ keyValue[] M;
+ int Default;
+
+ void operator init(Value Default) {
+ this.Default=Default;
}
-",true);
- type("map",name);
-}
+ bool operator < (keyValue a, keyValue b) {return a.key < b.key;}
+ void add(Key key, Value value) {
+ keyValue m=keyValue(key,value);
+ M.insert(search(M,m,operator <)+1,m);
+ }
+ Value lookup(Key key) {
+ int i=search(M,keyValue(key),operator <);
+ if(i >= 0 && M[i].key == key) return M[i].value;
+ return Default;
+ }
+}
diff --git a/graphics/asymptote/base/mapArray.asy b/graphics/asymptote/base/mapArray.asy
index 5a499b8c68..d6d75e9861 100644
--- a/graphics/asymptote/base/mapArray.asy
+++ b/graphics/asymptote/base/mapArray.asy
@@ -6,4 +6,4 @@ Dst[] map(MapType f, Src[] a) {
return sequence(
new Dst(int i) {return f(a[i]);},
a.length);
-} \ No newline at end of file
+}
diff --git a/graphics/asymptote/base/plain_boxes.asy b/graphics/asymptote/base/plain_boxes.asy
index 9576caff55..0b6746736a 100644
--- a/graphics/asymptote/base/plain_boxes.asy
+++ b/graphics/asymptote/base/plain_boxes.asy
@@ -1,3 +1,12 @@
+void fillbox(frame dest, path g, pen p=currentpen, filltype filltype=NoFill, bool above=true)
+{
+ if(above == false) {
+ frame F;
+ filltype.fill(F,g,p);
+ prepend(dest,F);
+ } else filltype.fill(dest,g,p);
+}
+
// Draw and/or fill a box on frame dest using the dimensions of frame src.
path box(frame dest, frame src=dest, real xmargin=0, real ymargin=xmargin,
pen p=currentpen, filltype filltype=NoFill, bool above=true)
@@ -6,11 +15,7 @@ path box(frame dest, frame src=dest, real xmargin=0, real ymargin=xmargin,
int sign=filltype == NoFill ? 1 : -1;
pair h=0.5*sign*(max(p)-min(p));
path g=box(min(src)-h-z,max(src)+h+z);
- frame F;
- if(above == false) {
- filltype.fill(F,g,p);
- prepend(dest,F);
- } else filltype.fill(dest,g,p);
+ fillbox(dest,g,p,filltype,above);
return g;
}
@@ -28,12 +33,7 @@ path roundbox(frame dest, frame src=dest, real xmargin=0, real ymargin=xmargin,
(dw,b)--(a-dw,b){right}..{down}
(a,b-dw)--(a,dw){down}..{left}
(a-dw,0)--(dw,0){left}..{up}cycle);
-
- frame F;
- if(above == false) {
- filltype.fill(F,g,p);
- prepend(dest,F);
- } else filltype.fill(dest,g,p);
+ fillbox(dest,g,p,filltype,above);
return g;
}
@@ -47,11 +47,7 @@ path ellipse(frame dest, frame src=dest, real xmargin=0, real ymargin=xmargin,
int sign=filltype == NoFill ? 1 : -1;
pair h=0.5*sign*(max(p)-min(p));
path g=ellipse(0.5*(M+m),factor*D.x+h.x+xmargin,factor*D.y+h.y+ymargin);
- frame F;
- if(above == false) {
- filltype.fill(F,g,p);
- prepend(dest,F);
- } else filltype.fill(dest,g,p);
+ fillbox(dest,g,p,filltype,above);
return g;
}
diff --git a/graphics/asymptote/base/plain_picture.asy b/graphics/asymptote/base/plain_picture.asy
index 13619e80ab..8c1fbd99f9 100644
--- a/graphics/asymptote/base/plain_picture.asy
+++ b/graphics/asymptote/base/plain_picture.asy
@@ -1,5 +1,4 @@
// Pre picture <<<1
-import plain_scaling;
import plain_bounds;
include plain_prethree;
@@ -222,6 +221,8 @@ struct picture { // <<<1
node3[] nodes3;
bool uptodate=true;
+ bool queueErase=false;
+ bool queueErase3=false;
struct bounds3 {
coords3 point,min,max;
@@ -286,6 +287,8 @@ struct picture { // <<<1
// Erase the current picture, retaining bounds.
void clear() {
+ queueErase=nodes.length > 0;
+ queueErase3=nodes3.length > 0;
nodes.delete();
nodes3.delete();
legend.delete();
@@ -730,7 +733,7 @@ struct picture { // <<<1
add(new void(frame f, transform t) {
picture opic=new picture;
d(opic,t);
- add(f,opic.fit(identity()));
+ add(f,opic.fit(identity));
},exact);
}
@@ -742,12 +745,12 @@ struct picture { // <<<1
},exact,above);
}
- void add(void d(picture, transform3, transform3, triple, triple),
+ void add(void d(picture, transform3, transform3, projection, triple, triple),
bool exact=false, bool above=true) {
add(new void(frame f, transform3 t, transform3 T, picture pic2,
projection P, triple lb, triple rt) {
picture opic=new picture;
- d(opic,t,T,lb,rt);
+ d(opic,t,T,P,lb,rt);
add(f,opic.fit3(identity4,pic2,P));
},exact,above);
}
@@ -1131,6 +1134,26 @@ pair size(picture pic, bool user=false)
return t*M-t*m;
}
+// Return a projection adjusted to view center of pic from specified direction.
+projection centered(projection P, picture pic=currentpicture) {
+ projection P=P.copy();
+ if(P.autoadjust && P.center) {
+ triple min=pic.userMin3();
+ triple max=pic.userMax3();
+ if(min != max) {
+ triple target=0.5*(max+min);
+ if(pic.keepAspect)
+ P.camera=target+P.vector();
+ else
+ P.camera=target+realmult(unit(P.vector()),max-min);
+ P.target=target;
+ P.normal=P.vector();
+ P.calculate();
+ }
+ }
+ return P;
+}
+
// Frame Alignment <<<
pair rectify(pair dir)
{
@@ -1587,13 +1610,11 @@ void add(picture src, bool group=true, filltype filltype=NoFill,
currentpicture.add(src,group,filltype,above);
}
-// Fit the picture src using the identity transformation (so user
-// coordinates and truesize coordinates agree) and add it about the point
-// position to picture dest.
+// Fit the picture src and add it about the point position to picture dest.
void add(picture dest, picture src, pair position, bool group=true,
filltype filltype=NoFill, bool above=true)
{
- add(dest,src.fit(identity()),position,group,filltype,above);
+ add(dest,src.fit(),position,group,filltype,true);
}
void add(picture src, pair position, bool group=true, filltype filltype=NoFill,
@@ -1607,7 +1628,7 @@ void fill(pair origin, picture pic=currentpicture, path[] g, pen p=currentpen)
{
picture opic;
fill(opic,g,p);
- add(pic,opic,origin);
+ add(pic,opic.fit(identity),origin);
}
void postscript(picture pic=currentpicture, string s)
diff --git a/graphics/asymptote/base/plain_prethree.asy b/graphics/asymptote/base/plain_prethree.asy
index 8866396255..fefa1e5104 100644
--- a/graphics/asymptote/base/plain_prethree.asy
+++ b/graphics/asymptote/base/plain_prethree.asy
@@ -143,7 +143,7 @@ struct projection {
static private real sqrtEpsilon = sqrt(realEpsilon);
// Move the camera so that the box(m,M) rotated about target will always
- // lie in front of the clipping plane.
+ // lie in front of the far clipping plane.
bool adjust(triple m, triple M) {
triple v=camera-target;
real d=distance(m,M);
@@ -161,7 +161,7 @@ projection currentprojection;
struct light {
real[][] diffuse;
- real[][] specular; // For PRC only
+ real[][] specular;
pen background=nullpen; // Background color of the 3D canvas.
real specularfactor;
triple[] position; // Only directional lights are currently implemented.
diff --git a/graphics/asymptote/base/plain_scaling.asy b/graphics/asymptote/base/plain_scaling.asy
index 4c6beae655..dc21462c8e 100644
--- a/graphics/asymptote/base/plain_scaling.asy
+++ b/graphics/asymptote/base/plain_scaling.asy
@@ -192,8 +192,6 @@ real max(real M, scaling s, coord[] c) {
return M;
}
-import simplex;
-
/*
Calculate the sizing constants for the given array and maximum size.
Solve the two-variable linear programming problem using the simplex method.
@@ -203,19 +201,16 @@ import simplex;
*/
real calculateScaling(string dir, coord[] m, coord[] M, real size,
bool warn=true) {
- real[][] A;
- real[] b;
- real[] c=new real[] {-1,0,0};
+ from simplex2 access problem;
+ problem p=new problem;
void addMinCoord(coord c) {
// (a*user + b) + truesize >= 0:
- A.push(new real[] {c.user,1,-1});
- b.push(-c.truesize);
+ p.addRestriction(c.user,1,c.truesize);
}
void addMaxCoord(coord c) {
// (a*user + b) + truesize <= size:
- A.push(new real[] {-c.user,-1,1});
- b.push(c.truesize-size);
+ p.addRestriction(-c.user,-1,size-c.truesize);
}
for (int i=0; i < m.length; ++i)
@@ -223,17 +218,16 @@ real calculateScaling(string dir, coord[] m, coord[] M, real size,
for (int i=0; i < M.length; ++i)
addMaxCoord(M[i]);
- int[] s=array(A.length,1);
- simplex S=simplex(c,A,s,b);
-
- if(S.case == S.OPTIMAL) {
- return S.x[0];
- } else if(S.case == S.UNBOUNDED) {
+ if(p.rows.length == 2) return 1; // Don't warn if there are no constraints
+ int status=p.optimize();
+ if(status == problem.OPTIMAL) {
+ // TODO: Could just be return a;
+ return scaling.build(p.a(),p.b()).a;
+ } else if(status == problem.UNBOUNDED) {
if(warn) warning("unbounded",dir+" scaling in picture unbounded");
return 0;
} else {
if(!warn) return 1;
-
bool userzero(coord[] coords) {
for(var coord : coords)
if(coord.user != 0) return false;
diff --git a/graphics/asymptote/base/plain_shipout.asy b/graphics/asymptote/base/plain_shipout.asy
index a001ce045c..0fd1b71c7a 100644
--- a/graphics/asymptote/base/plain_shipout.asy
+++ b/graphics/asymptote/base/plain_shipout.asy
@@ -122,7 +122,8 @@ void shipout(string prefix=defaultfilename, picture pic=currentpicture,
string options="", string script="",
light light=currentlight, projection P=currentprojection)
{
- pic.uptodate=true;
+ projection P=centered(P,pic);
+
if(!uptodate()) {
bool inlinetex=settings.inlinetex;
bool prc=prc(format) || settings.v3d;
@@ -139,7 +140,7 @@ void shipout(string prefix=defaultfilename, picture pic=currentpicture,
settings.inlinetex=settings.inlineimage;
}
frame f;
- transform t=pic.calculateTransform();
+ transform t=empty3 ? pic.calculateTransform() : identity;
if(currentpicture.fitter == null) {
pen background=currentlight.background;
if(settings.outformat == "html" && background == nullpen)
@@ -152,10 +153,14 @@ void shipout(string prefix=defaultfilename, picture pic=currentpicture,
else
f=pic.fit(prefix,format,view=view,options,script,light,P);
- if(!prconly() && (!pic.empty2() || settings.render == 0 || prc || empty3))
+ if(!prconly() && (!pic.empty2() || settings.render == 0 || prc ||
+ pic.queueErase)) {
shipout(prefix,orientation(f),format,wait,view,t);
+ pic.queueErase=false;
+ }
settings.inlinetex=inlinetex;
}
+ pic.uptodate=true;
}
void newpage(picture pic=currentpicture)
diff --git a/graphics/asymptote/base/simplex2.asy b/graphics/asymptote/base/simplex2.asy
new file mode 100644
index 0000000000..e8d073ef0b
--- /dev/null
+++ b/graphics/asymptote/base/simplex2.asy
@@ -0,0 +1,310 @@
+/*****
+ * simplex.asy
+ * Andy Hammerlindl 2004/07/27
+ *
+ * Solves the two-variable linear programming problem using the simplex method.
+ * This problem is specialized in that the second variable, "b", does not have
+ * a non-negativity condition, and the first variable, "a", is the quantity
+ * being maximized.
+ * Correct execution of the algorithm also assumes that the coefficient of "b"
+ * will be +1 or -1 in every added restriction, and that the problem can be
+ * initialized to a valid state by pivoting b with one of the slack
+ * variables. This assumption may in fact be incorrect.
+ *****/
+
+struct problem {
+ typedef int var;
+ static var VAR_A = 0;
+ static var VAR_B = 1;
+
+ static int OPTIMAL = -1;
+ static var UNBOUNDED = -2;
+ static int INVALID = -3;
+
+ struct row {
+ real c, t[];
+ }
+
+ // The variables of the rows.
+ // Initialized for the two variable problem.
+ var[] v = {VAR_A, VAR_B};
+
+ // The rows of equalities.
+ row rowA() {
+ row r = new row;
+ r.c = 0;
+ r.t = new real[] {1, 0};
+ return r;
+ }
+ row rowB() {
+ row r = new row;
+ r.c = 0;
+ r.t = new real[] {0, 1};
+ return r;
+ }
+ row[] rows = {rowA(), rowB()};
+
+ // The number of original variables.
+ int n = rows.length;
+
+ // Pivot the variable v[col] with vp.
+ void pivot(int col, var vp)
+ {
+ var vc=v[col];
+
+ // Recalculate rows v[col] and vp for the pivot-swap.
+ row rvc = rows[vc], rvp = rows[vp];
+ real factor=1/rvp.t[col]; // NOTE: Handle rvp.t[col] == 0 case.
+ rvc.c=-rvp.c*factor;
+ rvp.c=0;
+ rvc.t=-rvp.t*factor;
+ rvp.t *= 0;
+ rvc.t[col]=factor;
+ rvp.t[col]=1;
+
+ var a=min(vc,vp);
+ var b=max(vc,vp);
+
+ // Recalculate the rows other than the two used for the above pivot.
+ for (var i = 0; i < a; ++i) {
+ row r=rows[i];
+ real m = r.t[col];
+ r.c += m*rvc.c;
+ r.t += m*rvc.t;
+ r.t[col]=m*factor;
+ }
+ for (var i = a+1; i < b; ++i) {
+ row r=rows[i];
+ real m = r.t[col];
+ r.c += m*rvc.c;
+ r.t += m*rvc.t;
+ r.t[col]=m*factor;
+ }
+ for (var i = b+1; i < rows.length; ++i) {
+ row r=rows[i];
+ real m = r.t[col];
+ r.c += m*rvc.c;
+ r.t += m*rvc.t;
+ r.t[col]=m*factor;
+ }
+
+ // Relabel the vars.
+ v[col] = vp;
+ }
+
+ // As b does not have a non-negativity condition, it must initially be
+ // pivoted out for a variable that does. This selects the initial
+ // variable to pivot with b. It also assumes that there is a valid
+ // solution with a == 0 to the linear programming problem, and if so, it
+ // picks a pivot to get to that state. In our case, a == 0 corresponds to
+ // a picture with the user coordinates shrunk down to zero, and if that
+ // doesn't fit, nothing will.
+ //
+ // If b has a minimal value, choose a pivot that will give b its minimal
+ // value. Otherwise, if b has maximal value, choose a pivot to give b its
+ // maximal value.
+ var initVar()
+ {
+ real min;
+ var argmin;
+ var i=2;
+ for (; i < rows.length; ++i) {
+ row r=rows[i];
+ if (r.t[VAR_B] > 0) {
+ min=r.c/r.t[VAR_B];
+ argmin=i;
+ break;
+ }
+ }
+ for (; i < rows.length; ++i) {
+ row r=rows[i];
+ if (r.t[VAR_B] > 0) {
+ real val=r.c/r.t[VAR_B];
+ if (val < min) {
+ min=val;
+ argmin=i;
+ }
+ }
+ }
+
+ if(argmin != 0) return argmin;
+
+ real max;
+ var argmax;
+ var i=2;
+ for (; i < rows.length; ++i) {
+ row r=rows[i];
+ if (r.t[VAR_B] < 0) {
+ max=r.c/r.t[VAR_B];
+ argmax=i;
+ break;
+ }
+ }
+
+ for (; i < rows.length; ++i) {
+ row r=rows[i];
+ if (r.t[VAR_B] < 0) {
+ real val=r.c/r.t[VAR_B];
+ if (val > max) {
+ max=val;
+ argmax=i;
+ }
+ }
+ }
+
+ if(argmax != 0) return argmax;
+
+ return UNBOUNDED;
+ }
+
+ // Initialize the linear program problem by moving into an acceptable state
+ // this assumes that b is unrestrained and is the second variable.
+ // NOTE: Works in limited cases, may be bug-ridden.
+ void init()
+ {
+ // Find the lowest constant term in the equations.
+ var lowest = 0;
+ for (var i = 2; i < rows.length; ++i) {
+ if (rows[i].c < rows[lowest].c)
+ lowest = i;
+ }
+
+ // Pivot if necessary.
+ if (lowest != 0)
+ pivot(VAR_B, lowest);
+ }
+
+ // Selects a column to pivot on. Returns OPTIMAL if the current state is
+ // optimal. Assumes we are optimizing the first row.
+ int selectColumn()
+ {
+ int i=find(rows[0].t > 0,1);
+ return (i >= 0) ? i : OPTIMAL;
+ }
+
+ // Select the new variable associated with a pivot on the column given.
+ // Returns UNBOUNDED if the space is unbounded.
+ var selectVar(int col)
+ {
+ // We assume that the first two vars (a and b) once swapped out, won't be
+ // swapped back in. This finds the variable which gives the tightest
+ // non-negativity condition restricting our optimization. This turns
+ // out to be the max of c/t[col]. Note that as c is positive, and
+ // t[col] is negative, all c/t[col] will be negative, so we are finding
+ // the smallest in magnitude.
+ var vp=UNBOUNDED;
+ real max=0;
+ int i=2;
+ for (; i < rows.length; ++i) {
+ row r=rows[i];
+ if(r.c < 0) r.c=0; // Fix any numerical precision error
+ if(r.t[col] < 0) {
+ max=r.c/r.t[col]; vp=i;
+ break;
+ }
+ }
+ for (; i < rows.length; ++i) {
+ row r=rows[i];
+ if(r.c < 0) r.c=0; // Fix any numerical precision error
+ if(r.c < max*r.t[col]) {
+ max=r.c/r.t[col]; vp=i;
+ }
+ }
+
+ return vp;
+ }
+
+ // Checks that the rows are in a valid state.
+ bool valid()
+ {
+ // Checks that constants are valid.
+ bool validConstants() {
+ for (int i = 0; i < rows.length; ++i)
+ // Do not test the row for b, as it does not have a non-negativity
+ // condition.
+ if (i != VAR_B && rows[i].c < 0)
+ return false;
+ return true;
+ }
+
+ // Check a variable to see if its row is simple.
+ // NOTE: Simple rows could be optimized out, since they are not really
+ // used.
+ bool validVar(int col) {
+
+ var vc = v[col];
+ row rvc = rows[vc];
+
+ if (rvc.c != 0)
+ return false;
+ for (int i = 0; i < n; ++i)
+ if (rvc.t[i] != (i == col ? 1 : 0))
+ return false;
+
+ return true;
+ }
+
+ if (!validConstants()) {
+ return false;
+ }
+ for (int i = 0; i < n; ++i)
+ if (!validVar(i)) {
+ return false;
+ }
+
+ return true;
+ }
+
+
+ // Perform the algorithm to find the optimal solution. Returns OPTIMAL,
+ // UNBOUNDED, or INVALID (if no solution is possible).
+ int optimize()
+ {
+ // Put into a valid state to begin and pivot b out.
+ var iv=initVar();
+ if (iv == UNBOUNDED)
+ return iv;
+ pivot(VAR_B, iv);
+
+ if (!valid())
+ return INVALID;
+
+ while(true) {
+ int col = selectColumn();
+
+ if (col == OPTIMAL)
+ return col;
+ var vp = selectVar(col);
+
+ if (vp == UNBOUNDED)
+ return vp;
+
+ pivot(col, vp);
+ }
+
+ // Shouldn't reach here.
+ return INVALID;
+ }
+
+ // Add a restriction to the problem:
+ // t1*a + t2*b + c >= 0
+ void addRestriction(real t1, real t2, real c)
+ {
+ row r = new row;
+ r.c = c;
+ r.t = new real[] {t1, t2};
+ rows.push(r);
+ }
+
+ // Return the value of a computed.
+ real a()
+ {
+ return rows[VAR_A].c;
+ }
+
+ // Return the value of b computed.
+ real b()
+ {
+ return rows[VAR_B].c;
+ }
+}
diff --git a/graphics/asymptote/base/slide.asy b/graphics/asymptote/base/slide.asy
index a695953768..15a2189704 100644
--- a/graphics/asymptote/base/slide.asy
+++ b/graphics/asymptote/base/slide.asy
@@ -17,6 +17,8 @@ real pageheight=-2pagemargin;
bool landscape=orientation == Landscape || orientation == Seascape;
if(landscape) {
+ usepackage("geometry");
+ texpreamble("\geometry{landscape}");
orientation=Portrait;
pagewidth += settings.paperheight;
pageheight += settings.paperwidth;
@@ -401,21 +403,26 @@ void display(string s, string caption="", pair align=S, pen p=itempen,
void figure(string[] s, string options="", real margin=0,
string[] captions=new string[], string caption="",
+ string[] url=new string[],
pair align=S, pen p=itempen, pen figuremattpen=figuremattpen,
bool final=true)
{
string[] S;
for(int i=0; i < s.length; ++i) {
S[i]=graphic(s[i],options);
+ if(i < url.length && url[i] != "")
+ S[i]="\href{"+url[i]+"/"+s[i]+".html}{"+S[i]+"}";
}
display(S,margin,captions,caption,align,itempen,figuremattpen,final);
}
-void figure(string s, string options="", string caption="", pair align=S,
+void figure(string s, string options="", string caption="",
+ string url="", pair align=S,
pen p=itempen, pen figuremattpen=figuremattpen, bool final=true)
{
- figure(new string[] {s},options,caption,align,p,figuremattpen,final);
+ figure(new string[] {s},options,caption,new string[] {url},align,p,
+ figuremattpen,final);
}
void multifigure(string[] slist, string options="", string caption="",
@@ -581,7 +588,7 @@ void bibliography(string name)
real hmargin,vmargin;
if(pdf()) {
hmargin=1;
- vmargin=0;
+ vmargin=0.5;
} else {
hmargin=1.5;
vmargin=1;
diff --git a/graphics/asymptote/base/three.asy b/graphics/asymptote/base/three.asy
index cde32f6acb..343ca72067 100644
--- a/graphics/asymptote/base/three.asy
+++ b/graphics/asymptote/base/three.asy
@@ -46,21 +46,21 @@ restricted interaction Billboard=interaction(1);
struct render
{
- // PRC parameters:
- real compression; // lossy compression parameter (0=no compression)
+ real compression; // lossy PRC compression parameter (0=no compression)
real granularity; // PRC rendering granularity
- bool closed; // use one-sided rendering?
- bool tessellate; // use tessellated mesh to store straight patches?
+ bool closed; // use one-sided PRC rendering?
- bool3 merge; // merge nodes before rendering, for faster but
- // lower quality PRC rendering (the value default means
+ bool tessellate; // use tessellated mesh to store straight patches
+
+ bool3 merge; // merge PRC nodes before rendering, for faster but
+ // lower quality rendering (the value default means
// merge opaque patches only).
int sphere; // PRC sphere type (PRCsphere or NURBSsphere).
// General parameters:
- real margin; // shrink amount for rendered openGL viewport, in bp.
+ real margin; // shrink amount for rendered OpenGL viewport, in bp.
bool partnames; // assign part name indices to compound objects
bool defaultnames; // assign default names to unnamed objects
interaction interaction; // billboard interaction mode
@@ -346,7 +346,7 @@ projection perspective(real x, real y, real z, triple up=Z, triple target=O,
projection orthographic(triple camera, triple up=Z, triple target=O,
real zoom=1, pair viewportshift=0,
- bool showtarget=true, bool center=false)
+ bool showtarget=true, bool center=true)
{
return projection(camera,up,target,zoom,viewportshift,showtarget,
center=center,new transformation(triple camera, triple up,
@@ -356,7 +356,7 @@ projection orthographic(triple camera, triple up=Z, triple target=O,
projection orthographic(real x, real y, real z, triple up=Z,
triple target=O, real zoom=1, pair viewportshift=0,
- bool showtarget=true, bool center=false)
+ bool showtarget=true, bool center=true)
{
return orthographic((x,y,z),up,target,zoom,viewportshift,showtarget,
center=center);
@@ -2679,10 +2679,10 @@ struct scene
warn=false;
}
- if(P.absolute)
- this.P=P.copy();
- else if(P.showtarget)
- draw(pic,P.target,nullpen);
+ this.P=P.copy();
+
+ if(!P.absolute && P.showtarget && !pic.empty3())
+ draw(pic,this.P.target,nullpen);
t=pic.scaling(xsize3,ysize3,zsize3,keepAspect,warn);
adjusted=false;
@@ -2690,14 +2690,9 @@ struct scene
triple M=pic.max(t);
if(!P.absolute) {
- this.P=t*P;
+ this.P=t*this.P;
if(this.P.autoadjust || this.P.infinity)
adjusted=adjusted | this.P.adjust(m,M);
- if(this.P.center && settings.render != 0) {
- triple target=0.5*(m+M);
- this.P.target=target;
- this.P.calculate();
- }
}
bool scale=xsize != 0 || ysize != 0;
@@ -2893,16 +2888,18 @@ object embed(string prefix=outprefix(), string label=prefix,
triple margin=(S.viewportmargin.x,S.viewportmargin.y,0);
M += margin;
m -= margin;
- } else if(M.z >= 0) abort("camera too close");
+ } else if(M.z >= 0 && !S.pic2.empty()) abort("camera too close");
if(primitive())
format=settings.v3d ? "v3d" : settings.outformat;
+ transform3 s=inv*shift(0,0,zcenter);
+
shipout3(prefix,f,preview ? nativeformat() : format,
S.width-defaultrender.margin,S.height-defaultrender.margin,
P.infinity ? 0 : 2aTan(Tan(0.5*P.angle)*P.zoom),
P.zoom,m,M,P.viewportshift,S.viewportmargin,
- tinv*inv*shift(0,0,zcenter),Light.background(),Light.position,
+ tinv*s,s,Light.background(),Light.position,
Light.diffuse,Light.specular,
view && !preview);
if(settings.v3d) {
@@ -3038,12 +3035,15 @@ currentpicture.fitter=new frame(string prefix, picture pic, string format,
light light, projection P) {
frame f;
bool empty3=pic.empty3();
- if(!empty3) f=embedder(new object(string prefix, string format) {
- return embed(prefix=prefix,pic,format,xsize,ysize,keepAspect,view,
- options,script,light,P);
- },prefix,format,view,light);
+ if(!empty3 || pic.queueErase3) {
+ f=embedder(new object(string prefix, string format) {
+ return embed(prefix=prefix,pic,format,xsize,ysize,keepAspect,view,
+ options,script,light,P);
+ },prefix,format,view,light);
+ pic.queueErase3=false;
+ }
- if(is3D(format) || empty3)
+ if(is3D(format) || pic.queueErase || settings.render == 0)
add(f,pic.fit2(xsize,ysize,keepAspect));
return f;
};
diff --git a/graphics/asymptote/base/three_surface.asy b/graphics/asymptote/base/three_surface.asy
index c54b0cc490..d5e9ac47a6 100644
--- a/graphics/asymptote/base/three_surface.asy
+++ b/graphics/asymptote/base/three_surface.asy
@@ -409,14 +409,15 @@ struct patch {
// A constructor for a triangle or convex quadrilateral.
void operator init(triple[] external, triple[] internal=new triple[],
pen[] colors=new pen[], bool3 planar=default) {
- init();
-
straight=true;
if(colors.length != 0)
this.colors=copy(colors);
if(external.length == 3) {
+ triangular=true;
+ this.planar=true;
+ init();
P=new triple[][] {
{external[0]},
{interp(external[0],external[1],1/3),
@@ -426,9 +427,8 @@ struct patch {
{external[1],interp(external[1],external[2],1/3),
interp(external[1],external[2],2/3),external[2]}
};
- planar=true;
- triangular=true;
} else {
+ init();
if(internal.length == 0 && planar == default)
this.planar=normal(external) != O;
else this.planar=planar;
@@ -788,10 +788,11 @@ struct surface {
}
void operator init(triple[][][] P, pen[][] colors=new pen[][],
+ bool3 straight=false,
bool3 planar=default, bool triangular=false) {
s=sequence(new patch(int i) {
- return patch(P[i],colors.length == 0 ? new pen[] : colors[i],planar,
- triangular);
+ return patch(P[i],colors.length == 0 ? new pen[] : colors[i],
+ straight,planar,triangular);
},P.length);
}
@@ -1420,6 +1421,7 @@ void _draw(frame f, path3 g, triple center=O, material m,
int computeNormals(triple[] v, int[][] vi, triple[] n, int[][] ni)
{
triple lastnormal=O;
+ n.delete();
for(int i=0; i < vi.length; ++i) {
int[] vii=vi[i];
int[] nii=ni[i];
@@ -1433,7 +1435,7 @@ int computeNormals(triple[] v, int[][] vi, triple[] n, int[][] ni)
return ni.length;
}
-// Draw triangles on a frame.
+// Draw a triangle group on a frame.
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)
@@ -1480,21 +1482,25 @@ void draw(frame f, triple[] v, int[][] vi,
render.interaction.type);
}
-// Draw triangles on a picture.
+// Draw a triangle group on a picture.
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 normals=ni.length > 0;
- if(!normals) {
- ni=new int[vi.length][3];
- normals=computeNormals(v,vi,n,ni) > 0;
- }
bool colors=pi.length > 0;
+ // TODO: copy inputs
+
pic.add(new void(frame f, transform3 t, picture pic, projection P) {
triple[] v=t*v;
- triple[] n=t*n;
+ bool normals=ni.length > 0;
+ if(normals) {
+ transform3 T=transpose(inverse(shiftless(t)));
+ n=sequence(new triple(int i) {return unit(T*n[i]);},n.length) ;
+ } else {
+ ni=new int[vi.length][3];
+ normals=computeNormals(v,vi,n,ni) > 0;
+ }
if(is3D()) {
render Render=render(render,interaction(render.interaction,
@@ -1539,9 +1545,11 @@ void draw(picture pic=currentpicture, triple[] v, int[][] vi,
}
},true);
- for(int[] vii : vi)
- for(int viij : vii)
- pic.addPoint(v[viij]);
+ for(int[] vii : vi) {
+ pic.addPoint(v[vii[0]]);
+ pic.addPoint(v[vii[1]]);
+ pic.addPoint(v[vii[2]]);
+ }
}
void tensorshade(transform t=identity(), frame f, patch s,
@@ -1684,6 +1692,112 @@ void draw(transform t=identity(), frame f, surface s, int nu=1, int nv=1,
draw(t,f,s,nu,nv,surfacepen,meshpen,light,meshlight,name,render,P);
}
+// draw a triangle group on a frame for the tessellation of a surface
+// containing indexed patches.
+void drawTessellation(frame f, surface s,
+ material surfacepen=currentpen, pen meshpen=nullpen,
+ light light=currentlight, light meshlight=nolight,
+ string name="", render render=defaultrender)
+{
+ int nU=s.index.length;
+ if(nU == 0) return;
+ int nV=s.index[0].length;
+ if(nV == 0) return;
+
+ int N=(nU+1)*(nV+1);
+ triple[] v=new triple[N];
+ triple[] n=new triple[N];
+
+ bool colors=s.s[0].colors.length > 0;
+ pen[] p;
+ if(colors)
+ p=new pen[N];
+
+ int index(int i,int j) {return (nV+1)*i+j;}
+
+ int k=0;
+ for(int U=0; U < nU; ++U) {
+ for(int V=0; V < nV; ++V) {
+ patch q=s.s[s.index[U][V]];
+ v[k]=q.P[0][0];
+ n[k]=unit(q.normal00());
+ if(colors)
+ p[k]=q.colors[0];
+ ++k;
+ }
+ patch q=s.s[s.index[U][nV-1]];
+ v[k]=q.P[0][3];
+ n[k]=unit(q.normal01());
+ if(colors)
+ p[k]=q.colors[3];
+ ++k;
+ }
+
+ for(int V=0; V < nV; ++V) {
+ patch q=s.s[s.index[nU-1][V]];
+ v[k]=q.P[3][0];
+ n[k]=unit(q.normal10());
+ if(colors)
+ p[k]=q.colors[1];
+ ++k;
+ }
+ patch q=s.s[s.index[nU-1][nV-1]];
+ v[k]=q.P[3][3];
+ n[k]=unit(q.normal11());
+ if(colors)
+ p[k]=q.colors[2];
+ ++k;
+
+ int[][] vi=new int[nU*nV][];
+ int k=0;
+ for(int i=0; i < nU; ++i) {
+ for(int j=0; j < nV; ++j) {
+ vi[k]=new int[] {index(i,j),index(i+1,j),index(i+1,j+1)};
+ ++k;
+ vi[k]=new int[] {index(i,j),index(i+1,j+1),index(i,j+1)};
+ ++k;
+ }
+ }
+
+ draw(f,v,vi,n,vi,surfacepen,p,colors ? vi : new int[][],light);
+
+ if(!invisible(meshpen)) {
+ if(is3D()) meshpen=thin()+squarecap+meshpen;
+ bool group=name != "" || render.defaultnames;
+ for(int k=0; k < s.s.length; ++k) {
+ patch q=s.s[k];
+ if(group)
+ begingroup3(f,meshname(name),render);
+ draw(f,q.P[0][0]--q.P[3][0]--q.P[3][3]--q.P[0][3]--cycle,
+ meshpen,meshlight,partname(k,render),render);
+ if(group)
+ endgroup3(f);
+ }
+ }
+}
+
+// draw a triangle group on a picture for the tessellation of a surface
+// containing indexed patches.
+void drawTessellation(picture pic=currentpicture, surface s,
+ material surfacepen=currentpen, pen meshpen=nullpen,
+ light light=currentlight, light meshlight=nolight,
+ string name="", render render=defaultrender)
+{
+ pic.add(new void(frame f, transform3 t, picture, projection) {
+ drawTessellation(f,t*s,surfacepen,meshpen,light,meshlight,name,render);
+ },true);
+
+ pic.addPoint(min(s));
+ pic.addPoint(max(s));
+
+ if(!invisible(meshpen)) {
+ for(int k=0; k < s.s.length; ++k) {
+ patch q=s.s[k];
+ addPath(pic,q.P[0][0]--q.P[3][0]--q.P[3][3]--q.P[0][3]--cycle,meshpen);
+ }
+ }
+}
+
void draw(picture pic=currentpicture, surface s, int nu=1, int nv=1,
material[] surfacepen, pen[] meshpen=nullpens,
light light=currentlight, light meshlight=nolight, string name="",
@@ -1691,12 +1805,8 @@ void draw(picture pic=currentpicture, surface s, int nu=1, int nv=1,
{
if(s.empty()) return;
- bool cyclic=surfacepen.cyclic;
surfacepen=copy(surfacepen);
- surfacepen.cyclic=cyclic;
- cyclic=meshpen.cyclic;
meshpen=copy(meshpen);
- meshpen.cyclic=cyclic;
pic.add(new void(frame f, transform3 t, picture pic, projection P) {
surface S=t*s;
@@ -1738,11 +1848,15 @@ void draw(picture pic=currentpicture, surface s, int nu=1, int nv=1,
light light=currentlight, light meshlight=nolight, string name="",
render render=defaultrender)
{
- material[] surfacepen={surfacepen};
- pen[] meshpen={meshpen};
- surfacepen.cyclic=true;
- meshpen.cyclic=true;
- draw(pic,s,nu,nv,surfacepen,meshpen,light,meshlight,name,render);
+ if(render.tessellate && s.index.length > 0 && settings.render != 0) {
+ drawTessellation(pic,s,surfacepen,meshpen,light,meshlight,name,render);
+ } else {
+ material[] surfacepen={surfacepen};
+ surfacepen.cyclic=true;
+ pen[] meshpen={meshpen};
+ meshpen.cyclic=true;
+ draw(pic,s,nu,nv,surfacepen,meshpen,light,meshlight,name,render);
+ }
}
void draw(picture pic=currentpicture, surface s, int nu=1, int nv=1,
diff --git a/graphics/asymptote/base/v3dheadertypes.asy b/graphics/asymptote/base/v3dheadertypes.asy
index 0118208970..d8a2ebd7b4 100644
--- a/graphics/asymptote/base/v3dheadertypes.asy
+++ b/graphics/asymptote/base/v3dheadertypes.asy
@@ -1,6 +1,6 @@
// Enum class for v3dheadertypes
// AUTO-GENERATED from v3dheadertypes.csv
-// Generated at 2024-03-23 21:31:00
+// Generated at 2024-08-15 05:44:42+00:00
struct v3dheadertypes
{
diff --git a/graphics/asymptote/base/v3dtypes.asy b/graphics/asymptote/base/v3dtypes.asy
index b808b2ae44..89bd3c20fd 100644
--- a/graphics/asymptote/base/v3dtypes.asy
+++ b/graphics/asymptote/base/v3dtypes.asy
@@ -1,6 +1,6 @@
// Enum class for v3dtypes
// AUTO-GENERATED from v3dtypes.csv
-// Generated at 2024-03-23 21:31:00
+// Generated at 2024-08-15 05:44:42+00:00
struct v3dtypes
{
diff --git a/graphics/asymptote/base/webgl/asygl.js b/graphics/asymptote/base/webgl/asygl.js
index b5f77299a6..5b9fbfa649 100644
--- a/graphics/asymptote/base/webgl/asygl.js
+++ b/graphics/asymptote/base/webgl/asygl.js
@@ -1,6 +1,6 @@
/*@license
AsyGL: Render Bezier patches and triangles via subdivision with WebGL.
- Copyright 2019-2022: John C. Bowman and Supakorn "Jamie" Rassameemasmuang
+ Copyright 2019-2024: John C. Bowman and Supakorn "Jamie" Rassameemasmuang
University of Alberta
This program is free software; you can redistribute it and/or modify
@@ -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(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}();
+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,C=null,D=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")),ge=Nt(pixelOpt),we=Nt(materialOpt),Me=Nt(colorOpt),be=Nt(transparentOpt)}function st(){t.deleteProgram(be),t.deleteProgram(Me),t.deleteProgram(we),t.deleteProgram(ge)}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=ge,i.materialShader=we,i.colorShader=Me,i.transparentShader=be}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,ge=i.pixelShader,we=i.materialShader,Me=i.colorShader,be=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!=ge;!function(e,i){let n=i==ge;t.useProgram(i),t.enableVertexAttribArray(yt),n&&t.enableVertexAttribArray(Lt);let r=!n&&l.length>0;r&&t.enableVertexAttribArray(At);t.enableVertexAttribArray(Et),i.projViewMatUniform=t.getUniformLocation(i,"projViewMat"),i.viewMatUniform=t.getUniformLocation(i,"viewMat"),i.normMatUniform=t.getUniformLocation(i,"normMat"),(i==Me||i==be)&&t.enableVertexAttribArray(It);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(yt,3,t.FLOAT,!1,r?24:16,0),r?l.length>0&&t.vertexAttribPointer(At,3,t.FLOAT,!1,24,12):t.vertexAttribPointer(Lt,1,t.FLOAT,!1,16,12),e.materialsBuffer=ct(new Int16Array(e.materialIndices),e.materialsBuffer,s),t.vertexAttribPointer(Et,1,t.SHORT,!1,2,0),i!=Me&&i!=be||(e.colorsBuffer=ct(new Float32Array(e.colors),e.colorsBuffer,s),t.vertexAttribPointer(It,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,r=[0,0,0,0]){let s=6*t;this.vertices[s]=e[0],this.vertices[s+1]=e[1],this.vertices[s+2]=e[2],this.vertices[s+3]=i[0],this.vertices[s+4]=i[1],this.vertices[s+5]=i[2],this.materialIndices[t]=it;let a=4*t;this.colors[a]=r[0],this.colors[a+1]=r[1],this.colors[a+2]=r[2],this.colors[a+3]=r[3],n&&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]<4:t<3}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,Le):this.color?this.setMaterial(J,Ee):this.setMaterial(Q,Ae)}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 Ot(t[0],t[1],t[2],t[3]),a=new Ot(t[4],t[5],t[6],t[7]),o=new Ot(t[8],t[9],t[10],t[11]),h=new Ot(t[12],t[13],t[14],t[15]),l=new Ot(t[0],t[4],t[8],t[12]),c=new Ot(s.m0,a.m0,o.m0,h.m0),d=new Ot(s.m3,a.m3,o.m3,h.m3),m=new Ot(s.m5,a.m5,o.m5,h.m5),f=new Ot(s.m4,a.m4,o.m4,h.m4),u=new Ot(s.m2,a.m2,o.m2,h.m2),p=new Ot(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 Pt(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,Ut([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=St(Bt([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=Bt([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=Bt([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=St([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);Ut(s)<this.epsilon&&(s=this.normal(i,t[2],t[1],e,t[13],t[14],r),Ut(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);Ut(a)<this.epsilon&&(a=this.normal(e,t[4],t[8],n,t[11],t[7],i),Ut(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);Ut(o)<this.epsilon&&(o=this.normal(n,t[13],t[14],r,t[2],t[1],e),Ut(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(Ut(h)<this.epsilon&&(h=this.normal(r,t[11],t[7],i,t[4],t[8],n),Ut(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 _t(g,t[1],t[2],w),R=new _t(t[4],t[5],t[6],t[7]),T=new _t(t[8],t[9],t[10],t[11]),y=new _t(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]);Ut(I)<=this.epsilon&&(I=this.normal(A[12],A[13],A[14],A[15],A[2],A[1],A[0]),Ut(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]);Ut(L)<=this.epsilon&&(L=this.normal(E[3],E[2],E[1],E[0],E[13],E[14],E[15]),Ut(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=Ht(M,t[13],t[14],b)<this.res2){let t=St(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=Ht(g,t[1],t[2],w)<this.res2){let t=St(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 _t(g,t[4],t[8],M),R=new _t(t[1],t[5],t[9],t[13]),T=new _t(t[2],t[6],t[10],t[14]),y=new _t(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]);Ut(I)<=this.epsilon&&(I=this.normal(A[0],A[4],A[8],A[12],A[11],A[7],A[3]),Ut(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]);Ut(L)<=this.epsilon&&(L=this.normal(E[15],E[11],E[7],E[3],E[4],E[8],E[12]),Ut(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=Ht(g,t[4],t[8],M)<this.res2){let t=St(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=Ht(b,t[11],t[7],w)<this.res2){let t=St(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 _t(g,t[1],t[2],w),T=new _t(t[4],t[5],t[6],t[7]),y=new _t(t[8],t[9],t[10],t[11]),A=new _t(M,t[13],t[14],b),E=new _t(g,t[4],t[8],M),I=new _t(R.m0,T.m0,y.m0,A.m0),L=new _t(R.m3,T.m3,y.m3,A.m3),N=new _t(R.m5,T.m5,y.m5,A.m5),O=new _t(R.m4,T.m4,y.m4,A.m4),_=new _t(R.m2,T.m2,y.m2,A.m2),P=new _t(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],C=S[15],D=this.normal(S[0],S[4],S[8],S[12],S[13],S[14],S[15]);Ut(D)<this.epsilon&&(D=this.normal(S[0],S[4],S[8],S[12],S[11],S[7],S[3]),Ut(D)<this.epsilon&&(D=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]);Ut(F)<this.epsilon&&(F=this.normal(U[12],U[13],U[14],U[15],U[2],U[1],U[0]),Ut(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]);Ut(z)<this.epsilon&&(z=this.normal(V[15],V[11],V[7],V[3],V[4],V[8],V[12]),Ut(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]);Ut(H)<this.epsilon&&(H=this.normal(B[3],B[2],B[1],B[0],B[13],B[14],B[15]),Ut(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],C,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=Ht(g,t[4],t[8],M)<this.res2){let t=St(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=Ht(M,t[13],t[14],b)<this.res2){let t=St(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=Ht(b,t[11],t[7],w)<this.res2){let t=St(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=Ht(g,t[1],t[2],w)<this.res2){let t=St(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,D,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(C,X,M);this.Render(S,e,b,A,y,s,W,C,Y,l,!1,!1,m,f,t,M,w),this.Render(U,b,i,R,A,W,a,j,C,l,c,!1,!1,t,u,x,M),this.Render(V,A,R,n,T,C,j,o,k,!1,c,d,!1,M,x,p,g),this.Render(B,y,A,T,r,Y,C,k,h,!1,!1,d,m,w,M,g,v)}else{let t=this.vertex(W,D),f=this.vertex(j,F),u=this.vertex(k,z),p=this.vertex(Y,H),v=this.vertex(C,X);this.Render(S,e,t,v,p,s,W,C,Y,l,!1,!1,m),this.Render(U,t,i,f,v,W,a,j,C,l,c,!1,!1),this.Render(V,v,f,n,u,C,j,o,k,!1,c,d,!1),this.Render(B,p,v,u,r,Y,C,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])],C=[.5*(A[0]+N[0]),.5*(A[1]+N[1]),.5*(A[2]+N[2])],D=[.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]+D[0]),.5*(V[1]+D[1]),.5*(V[2]+D[2])],Z=[.5*(C[0]+D[0]),.5*(C[1]+D[1]),.5*(C[2]+D[2])],Q=[.5*(V[0]+C[0]),.5*(V[1]+C[1]),.5*(V[2]+C[2])],J=[f,P,N,X,[.5*(L[0]+P[0]),.5*(L[1]+P[1]),.5*(L[2]+P[2])],C,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=Ht(w,M,b,R)<this.res2){let t=St(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=Ht(f,p,g,R)<this.res2){let t=St(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=Ht(f,u,v,w)<this.res2){let t=St(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=Xt(e,n,i,r);s=Math.max(s,Ht(e,t[4],t[8],n)),s=Math.max(s,Ht(t[1],t[5],t[9],t[13])),s=Math.max(s,Ht(i,t[7],t[11],r)),s=Math.max(s,Ht(t[2],t[6],t[10],t[14]));let a=Xt(e,i,n,r);return a=Math.max(a,Ht(e,t[1],t[2],i)),a=Math.max(a,Ht(t[4],t[5],t[6],t[7])),a=Math.max(a,Ht(t[8],t[9],t[10],t[11])),a=Math.max(a,Ht(n,t[13],t[14],r)),[s,a]}Distance3(t){let e=t[0],i=t[4],n=t[6],r=t[9],s=Ut([(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,Ht(e,t[1],t[3],n)),s=Math.max(s,Ht(e,t[2],t[5],r)),Math.max(s,Ht(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 Ut(r)>this.epsilon?r:(r=Ft(t,e,i),Ut(r)>this.epsilon?r:zt(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(Ut(f)>this.epsilon)return f;let u=[c,d,m],p=[o,h,l],v=Ft(n,i,e),x=Ft(n,r,s),g=Bt(x,u),w=Bt(p,v);if(f=[g[0]+w[0],g[1]+w[1],g[2]+w[2]],Ut(f)>this.epsilon)return f;let M=zt(n,i,e,t),b=zt(n,r,s,a);g=Bt(p,M),w=Bt(b,u);let R=Bt(x,v);return f=[g[0]+w[0]+R[0],g[1]+w[1]+R[1],g[2]+w[2]+R[2]],Ut(f)>this.epsilon?f:(g=Bt(b,v),w=Bt(x,M),f=[g[0]+w[0],g[1]+w[1],g[2]+w[2]],Ut(f)>this.epsilon?f:Bt(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=Ct(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=Ct(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,ye)}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),Ft(e,i,n)),a=this.normal(Dt(n,r),Ft(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(Ht(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=Vt(t,t),n=Vt(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,Te)}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.controlpoints=window.Positions,this.Normals=window.Normals,this.Colors=window.Colors,this.Indices=window.Indices,this.transparent=c[this.MaterialIndex].diffuse[3]<1,this.Min=this.Bounds(this.controlpoints,Math.min),this.Max=this.Bounds(this.controlpoints,Math.max)}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,Le):this.setMaterial(et,Ie)}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]],o=!this.offscreen([r,s,a]),h=i.length>1?i[1]:n;if(h&&0!=h.length||(h=n),this.Colors.length>0){let t=i.length>2?i[2]:n;t&&0!=t.length||(t=n);let e=this.Colors[t[0]],l=this.Colors[t[1]],c=this.Colors[t[2]];this.transparent|=e[3]+l[3]+c[3]<3,0==V?(this.data.iVertex(n[0],r,this.Normals[h[0]],o,e),this.data.iVertex(n[1],s,this.Normals[h[1]],o,l),this.data.iVertex(n[2],a,this.Normals[h[2]],o,c)):(this.data.iVertex(n[0],r,this.Normals[h[0]],o,e),this.data.iVertex(n[1],s,this.Normals[h[1]],o,l),this.data.iVertex(n[1],s,this.Normals[h[1]],o,l),this.data.iVertex(n[2],a,this.Normals[h[2]],o,c),this.data.iVertex(n[2],a,this.Normals[h[2]],o,c),this.data.iVertex(n[0],r,this.Normals[h[0]],o,e))}else 0==V?(this.data.iVertex(n[0],r,this.Normals[h[0]],o),this.data.iVertex(n[1],s,this.Normals[h[1]],o),this.data.iVertex(n[2],a,this.Normals[h[2]],o)):(this.data.iVertex(n[0],r,this.Normals[h[0]],o),this.data.iVertex(n[1],s,this.Normals[h[1]],o),this.data.iVertex(n[1],s,this.Normals[h[1]],o),this.data.iVertex(n[2],a,this.Normals[h[2]],o),this.data.iVertex(n[2],a,this.Normals[h[2]],o),this.data.iVertex(n[0],r,this.Normals[h[0]],o))}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,_e(),U=!0,Oe()}function Tt(){mat4.identity(T),Rt(),window.top.asyWebApplication&&window.top.asyWebApplication.setProjection(""),window.parent.asyProjection=!1}let yt=0,At=1,Et=2,It=3,Lt=4;function Nt(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,yt,"position"),t.bindAttribLocation(r,At,"normal"),t.bindAttribLocation(r,Et,"materialIndex"),t.bindAttribLocation(r,It,"color"),t.bindAttribLocation(r,Lt,"width"),t.linkProgram(r),t.getProgramParameter(r,t.LINK_STATUS)||alert("Could not initialize shaders"),r}class Ot{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 _t{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 Pt{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 St(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 Ut(t){return t[0]*t[0]+t[1]*t[1]+t[2]*t[2]}function Vt(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function Bt(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 Ct(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 Ft(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 zt(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 Ht(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(Ut([e[0]-r[0]-t[0],e[1]-r[1]-t[1],e[2]-r[2]-t[2]]),Ut([n[0]-r[0]-i[0],n[1]-r[1]-i[1],n[2]-r[2]-i[2]]))}function Xt(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(Ut(Bt(r,St(s))),Ut(Bt(s,St(r))))/9}function Gt(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 Wt(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 jt(t){oe||he(),B=!0,C=t.clientX,D=t.clientY}let kt,Yt,$t=!1;function qt(t){return Math.hypot(t[0].pageX-t[1].pageX,t[0].pageY-t[1].pageY)}function Kt(t){t.preventDefault(),oe||he();let e=t.targetTouches;pe=ve=$t=!1,ue||(1!=e.length||B||(Yt=(new Date).getTime(),touchId=e[0].identifier,C=e[0].pageX,D=e[0].pageY),2!=e.length||B||(touchId=e[0].identifier,kt=qt(e),$t=!0))}function Zt(t){B=!1}function Qt(t,e,i,n,r){if(t==i&&e==n)return;let[s,a]=function(t,e){let i=re(t),n=re(e),r=Vt(i,n);return[r>1?0:r<-1?f:Math.acos(r),St(Bt(i,n))]}([t,-e],[i,-n]);mat4.fromRotation(O,2*r*R*s/v,a),mat4.multiply(T,O,T)}function Jt(t,e,i,n){let r=1/v;P.x+=(i-t)*r*s,P.y-=(n-e)*r*a}function te(t,e,i,n){o.orthographic?Jt(t,e,i,n):(_.x+=(i-t)*(S.xmax-S.xmin),_.y-=(n-e)*(S.ymax-S.ymin))}function ee(){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 ie(){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 ne(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,ie())}function re(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 se(t,e,i,n){ne(e-n)}function ae(t,e,i,n=1){let r;switch(i){case 1:r=Qt;break;case 2:r=Jt;break;case 3:r=se;break;case 4:r=te;break;default:r=(t,e,i,n)=>{}}r((C-s)/s,(D-a)/a,(t-s)/s,(e-a)/a,n),C=t,D=e,_e(),Oe()}let oe=0;function he(){oe=1,o.canvas.addEventListener("wheel",me,!1)}function le(){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 ce(t){if(oe||he(),o.embedded&&oe&&27==t.keyCode)return oe=0,void o.canvas.removeEventListener("wheel",me,!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":Tt();break;case"m":++V,3==V&&(V=0),2!=V&&(o.embedded||st(),rt(o.ibl)),U=!0,Oe();break;case"+":case"=":case">":v*=o.zoomFactor,de();break;case"-":case"_":case"<":v/=o.zoomFactor,de();break;case"c":window.top.asyWebApplication||prompt("Ctrl+c Enter to copy currentprojection to clipboard; then append to asy file:",le())}e.length>0&&(mat4.rotate(T,T,.1,e),ee(),Oe())}function de(){ie(),_e(),Oe()}function me(t){t.preventDefault(),t.deltaY<0?v*=o.zoomFactor:v/=o.zoomFactor,de()}function fe(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,ae(i,n,e)}let ue=!1,pe=!1,ve=!1;function xe(t){if(t.preventDefault(),ue)return;let e=t.targetTouches;if(!$t&&1==e.length&&touchId==e[0].identifier){let t=e[0].pageX,i=e[0].pageY,n=t-C,r=i-D,s=n*n+r*r<=o.shiftHoldDistance*o.shiftHoldDistance;if(s&&!pe&&!ve&&(new Date).getTime()-Yt>o.shiftWaitTime&&(navigator.vibrate&&window.navigator.vibrate(o.vibrateTime),pe=!0),pe)ae(t,i,2);else if(!s){ve=!0,ae(e[0].pageX,e[0].pageY,1,.5)}}if($t&&!pe&&2==e.length&&touchId==e[0].identifier){let t=qt(e),i=t-kt;ue=!0,i*=o.zoomPinchFactor,i>o.zoomPinchCap&&(i=o.zoomPinchCap),i<-o.zoomPinchCap&&(i=-o.zoomPinchCap),ne(i/b),kt=t,pe=ve=ue=!1,_e(),Oe()}}let ge,we,Me,be,Re=[];function Te(){dt(K,ge),K.clear()}function ye(){dt(Z,we),Z.clear()}function Ae(){dt(Q,we),Q.clear()}function Ee(){dt(J,Me),J.clear()}function Ie(){dt(et,be),et.rendered=!1,et.clear()}function Le(){let e=tt.indices;if(V>0)return dt(tt,be,e),void tt.clear();if(e.length>0){!function(t){let e=A[2],i=A[6],n=A[10];Re.length=t.length;for(let r=0;r<t.length;++r){let s=6*r;Re[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],Re[Ia]+Re[Ib]+Re[Ic]<Re[IA]+Re[IB]+Re[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,be,r),tt.rendered=!1,t.depthMask(!0)}tt.clear()}function Ne(){Te(),ye(),Ae(),Ee(),Ie(),Le(),requestAnimationFrame(Ne)}function Oe(){o.embedded&&(i.width=o.canvasWidth,i.height=o.canvasHeight,Pe()),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();Ne(),o.embedded&&(n.clearRect(0,0,o.canvasWidth,o.canvasHeight),n.drawImage(i,0,0)),0==V&&(U=!1)}function _e(){!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),ee(),window.top.asyWebApplication&&window.top.asyWebApplication.setProjection(le())}function Pe(){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 Se(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,Pe(),_e(),U=!0}function Ue(){if(o.zoom0=o.initialZoom,window.top.asyWebApplication&&""==window.top.asyWebApplication.getProjection()&&(window.parent.asyProjection=!1),o.absolute&&!o.embedded)o.canvasWidth=o.canvasWidth0*window.devicePixelRatio,o.canvasHeight=o.canvasHeight0*window.devicePixelRatio;else{let t=o.canvasWidth0/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,Se(o.canvasWidth,o.canvasHeight),Rt()}class Ve{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 Be(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[Gt(n),Wt(n)]}let Ce=4/3*(Math.sqrt(2)-1);async function De(t){return(await fetch(t)).arrayBuffer()}function Fe(t){return t.getBytes().filter((t,e)=>e%4!=3)}function ze(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,Fe(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=jt,document.onmouseup=Zt,document.onmousemove=fe,o.canvas.onkeydown=ce,o.embedded||he(),o.canvas.addEventListener("touchstart",Kt,!1),o.canvas.addEventListener("touchend",Zt,!1),o.canvas.addEventListener("touchcancel",Zt,!1),o.canvas.addEventListener("touchleave",Zt,!1),o.canvas.addEventListener("touchmove",xe,!1),document.addEventListener("keydown",ce,!1),o.canvasWidth0=o.canvasWidth,o.canvasHeight0=o.canvasHeight,mat4.identity(T),0!=window.innerWidth&&0!=window.innerHeight&&Ue(),window.addEventListener("resize",Ue,!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=ze(e,0)}),De(e+"diffuse.exr").then(t=>{let e=new Module.EXRLoader(t);W=ze(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,Fe(n))}G=i}),promises.push(finished_promise),await Promise.all(promises)}().then(k).then(Rt),Tt()},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,Ce,0],[1,Ce,m],[f,Ce*f,u],[p,Ce*p,v],[Ce,1,0],[Ce,1,m],[Ce*f,f,u],[Ce*p,p,v],[0,1,0],[0,1,m],[0,f,u],[0,p,v]],[[p,0,v],[p,Ce*p,v],[x,0,g],[Ce*p,p,v],[w,w,1],[.05*Ce,0,1],[0,p,v],[0,x,g],[0,.05*Ce,1],[0,0,1]]],b=new Ve(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=Be(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*Ce/3,a=[[1,0,0],[1,-Ce,0],[Ce,-1,0],[0,-1,0],[1,Ce,0],[s,0,0],[0,-s,0],[-Ce,-1,0],[Ce,1,0],[0,s,0],[-s,0,0],[-1,-Ce,0],[0,1,0],[-Ce,1,0],[-1,Ce,0],[-1,0,0]],o=new Ve(t,r),l=Be(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,Ce,0],[1,Ce,1/3],[1,Ce,2/3],[1,Ce,1],[Ce,1,0],[Ce,1,1/3],[Ce,1,2/3],[Ce,1,1],[0,1,0],[0,1,1/3],[0,1,2/3],[0,1,1]],d=new Ve(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=Be(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=Bt(i,e)}}let a=Number.EPSILON*Math.max(Ut(t),Ut(e),Ut(i),Ut(n));function o(r){if(1==r){let r=[n[0]-i[0],n[1]-i[1],n[2]-i[2]];return Ut(r)>a?St(r):(r=[2*i[0]-e[0]-n[0],2*i[1]-e[1]-n[1],2*i[2]-e[2]-n[2]],Ut(r)>a?St(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 Ut(c)>a?St(c):(l=2*r,c=[s[0]*l+o[0],s[1]*l+o[1],s[2]*l+o[2]],Ut(c)>a?St(c):St(s))}let h=Array(r.length),l=[e[0]-t[0],e[1]-t[1],e[2]-t[2]];Ut(l)<a&&(l=[t[0]-2*e[0]+i[0],t[1]-2*e[1]+i[1],t[2]-2*e[2]+i[2]],Ut(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=St(l);let c=function(t){let e=Bt(t,[0,1,0]),i=Number.EPSILON*Ut(t);return Ut(e)>i?St(e):(e=Bt(t,[0,0,1]),Ut(e)>i?St(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=St(x),i=l.t,n=Vt(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*Vt(e,t),m=[t[0]-d*e[0],t[1]-d*e[1],t[2]-d*e[2]],f=St([i[0]-r[0],i[1]-r[1],i[2]-r[2]]),u=2*Vt(f,m);m=[m[0]-u*f[0],m[1]-u*f[1],m[2]-u*f[2]],h[a]=new s(v,St(m),St(i))}else h[a]=h[a-1]}return h}(t[0],t[1],t[2],t[3],[0,1/3,2/3,1]),a=Ce*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}();