/*@license AsyGL: Render Bezier patches and triangles via subdivision with WebGL. Copyright 2019-2022: John C. Bowman and Supakorn "Jamie" Rassameemasmuang University of Alberta This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ /*@license for gl-matrix mat3 and mat4 functions: Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 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)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;t0&&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;sthis.X&&(this.X=h),lthis.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=-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;e0&&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]0&&this.append()}Render3(t,e,i,n,r,s,a,o,h,l,c,d,m){if(this.Distance3(t)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;e0&&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)0?-1-it:1+it;for(let e=0,i=this.Indices.length;e1?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*v1.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)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;re);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]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.canvasWidthe%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;ia?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)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