-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCindy3D.js
More file actions
72 lines (71 loc) · 40.7 KB
/
Cindy3D.js
File metadata and controls
72 lines (71 loc) · 40.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
(function(){
var C;function D(a){this.message=a}D.prototype.toString=function(){return this.message};
function aa(a,b,c){this.handle=a.createProgram();a.g&&(b="#version 300 es\n"+b.replace(/attribute/g,"in").replace(/varying/g,"out"),c="#version 300 es\n"+c.replace(/varying/g,"in").replace(/gl_FragColor/g,"FragColor").replace(/texture2D/g,"texture").replace(/precision highp float;/g,"precision highp float;\n#define webgl2 true\nout vec4 FragColor;"));this.h=ca(this,a,a.VERTEX_SHADER,b);this.g=ca(this,a,a.FRAGMENT_SHADER,c);b=this.handle;a.linkProgram(b);if(!a.getProgramParameter(b,a.LINK_STATUS))throw new D("Error linking shader:\n"+
a.getProgramInfoLog(b));a.validateProgram(b);if(!a.getProgramParameter(b,a.VALIDATE_STATUS))throw new D("Error validating shader:\n"+a.getProgramInfoLog(b));let e=this.handle,f,g;var p;let k={},l;let n;c=a.getProgramParameter(e,a.ACTIVE_UNIFORMS);for(b=0;b<c;++b)if(f=a.getActiveUniform(e,b),null!==f&&(g=f.name.replace(/\]/g,""))){for(l=k;null!==(p=/[.\[]/.exec(g));){var h=g.substr(0,p.index);l.hasOwnProperty(h)?l=l[h]:"."===p[0]?l=l[h]={}:l=l[h]=[];g=g.substr(p.index+1)}if(1<f.size){p=f.size;n=Array(p);
for(h=0;h<p;++h){var d=f.name+"["+h+"]";d=da(this,a,d,f);n[h]=d}l[g]=n}else d=da(this,a,f.name,f),l[g]=d}this.uniform=k}function ca(a,b,c,e){c=b.createShader(c);b.shaderSource(c,e);b.compileShader(c);if(!b.getShaderParameter(c,b.COMPILE_STATUS))throw console.warn(e.split("\n")),new D("Error compiling shader:\n"+b.getShaderInfoLog(c));b.attachShader(a.handle,c);return c}aa.prototype.use=function(a){a.useProgram(this.handle);return this};
function ea(a,b){b.detachShader(a.handle,a.h);b.deleteShader(a.h);b.detachShader(a.handle,a.g);b.deleteShader(a.g);b.deleteProgram(a.handle)}
function da(a,b,c,e){a=b.getUniformLocation(a.handle,c);switch(e.type){case b.FLOAT:return b.uniform1fv.bind(b,a);case b.FLOAT_VEC2:return b.uniform2fv.bind(b,a);case b.FLOAT_VEC3:return b.uniform3fv.bind(b,a);case b.FLOAT_VEC4:return b.uniform4fv.bind(b,a);case b.BOOL:case b.INT:case b.SAMPLER_2D:case b.SAMPLER_CUBE:return b.uniform1iv.bind(b,a);case b.BOOL_VEC2:case b.INT_VEC2:return b.uniform2iv.bind(b,a);case b.BOOL_VEC3:case b.INT_VEC3:return b.uniform3iv.bind(b,a);case b.BOOL_VEC4:case b.INT_VEC4:return b.uniform4iv.bind(b,
a);case b.FLOAT_MAT2:return b.uniformMatrix2fv.bind(b,a,!1);case b.FLOAT_MAT3:return b.uniformMatrix3fv.bind(b,a,!1);case b.FLOAT_MAT4:return b.uniformMatrix4fv.bind(b,a,!1);default:throw new D("Unknown data type for uniform "+c);}};function fa(a){let b=a[0],c=a[1];a=a[2];let e=1/Math.sqrt(b*b+c*c+a*a);return[e*b,e*c,e*a]}function E(a){let b=1/a[3];return[b*a[0],b*a[1],b*a[2]]}function ia(a,b){return[a*b[0],a*b[1],a*b[2]]}function F(a,b){return[a[0]-b[0],a[1]-b[1],a[2]-b[2]]}function ja(a,b){return[a[0]+b[0],a[1]+b[1],a[2]+b[2]]}function ka(a,b){return[a[0]+b[0],a[1]+b[1],a[2]+b[2],a[3]+b[3]]}function la(a,b){return[a[1]*b[2]-a[2]*b[1],a[2]*b[0]-a[0]*b[2],a[0]*b[1]-a[1]*b[0]]}
function G(a,b){return[a[0]*b[0]+a[1]*b[4]+a[2]*b[8]+a[3]*b[12],a[0]*b[1]+a[1]*b[5]+a[2]*b[9]+a[3]*b[13],a[0]*b[2]+a[1]*b[6]+a[2]*b[10]+a[3]*b[14],a[0]*b[3]+a[1]*b[7]+a[2]*b[11]+a[3]*b[15],a[4]*b[0]+a[5]*b[4]+a[6]*b[8]+a[7]*b[12],a[4]*b[1]+a[5]*b[5]+a[6]*b[9]+a[7]*b[13],a[4]*b[2]+a[5]*b[6]+a[6]*b[10]+a[7]*b[14],a[4]*b[3]+a[5]*b[7]+a[6]*b[11]+a[7]*b[15],a[8]*b[0]+a[9]*b[4]+a[10]*b[8]+a[11]*b[12],a[8]*b[1]+a[9]*b[5]+a[10]*b[9]+a[11]*b[13],a[8]*b[2]+a[9]*b[6]+a[10]*b[10]+a[11]*b[14],a[8]*b[3]+a[9]*b[7]+
a[10]*b[11]+a[11]*b[15],a[12]*b[0]+a[13]*b[4]+a[14]*b[8]+a[15]*b[12],a[12]*b[1]+a[13]*b[5]+a[14]*b[9]+a[15]*b[13],a[12]*b[2]+a[13]*b[6]+a[14]*b[10]+a[15]*b[14],a[12]*b[3]+a[13]*b[7]+a[14]*b[11]+a[15]*b[15]]}function ma(a,b,c){a=E(a);return fa(la(F(E(b),a),F(E(c),a)))};function na(a,b){this.width=a;this.height=b;this.fieldOfView=Math.PI/360*45;this.zNear=.1;this.zFar=100;this.updatePerspective();this.setCamera([0,0,5],[0,0,0],[0,1,0])}na.prototype.updatePerspective=function(){let a=1/Math.tan(this.fieldOfView),b=this.zNear-this.zFar;this.projectionMatrix=[a*this.height/this.width,0,0,0,0,a,0,0,0,0,(this.zFar+this.zNear)/b,-1,0,0,2*this.zFar*this.zNear/b,0]};
na.prototype.setCamera=function(a,b,c){a=F(a,b);var e=a[0];let f=a[1],g=a[2];this.viewDist=Math.sqrt(e*e+f*f+g*g);a=fa(a);c=fa(la(c,a));e=la(a,c);c=[c[0],e[0],a[0],c[1],e[1],a[1],c[2],e[2],a[2]];c=[c[4]*c[8]-c[5]*c[7],c[2]*c[7]-c[1]*c[8],c[1]*c[5]-c[2]*c[4],c[5]*c[6]-c[3]*c[8],c[0]*c[8]-c[2]*c[6],c[2]*c[3]-c[0]*c[5],c[3]*c[7]-c[4]*c[6],c[1]*c[6]-c[0]*c[7],c[0]*c[4]-c[1]*c[3]];b=[c[0]*b[0]+c[1]*b[1]+c[2]*b[2],c[3]*b[0]+c[4]*b[1]+c[5]*b[2],c[6]*b[0]+c[7]*b[1]+c[8]*b[2]];this.modelMatrix=[c[0],c[1],
c[2],-b[0],c[3],c[4],c[5],-b[1],c[6],c[7],c[8],-b[2],0,0,0,1];this.viewMatrix=[1,0,0,0,0,1,0,0,0,0,1,-this.viewDist,0,0,0,1];this.mvMatrix=G(this.viewMatrix,this.modelMatrix)};function oa(a,b,c){var e=.01*b,f=.01*c;c=Math.cos(e);b=Math.cos(f);e=Math.sin(e);f=Math.sin(f);a.modelMatrix=G(G([c,0,e,0,0,1,0,0,-e,0,c,0,0,0,0,1],[1,0,0,0,0,b,-f,0,0,f,b,0,0,0,0,1]),a.modelMatrix);a.mvMatrix=G(a.viewMatrix,a.modelMatrix)}
function pa(a,b,c){let e=.002*a.viewDist;a.modelMatrix=G([1,0,0,e*b,0,1,0,-e*c,0,0,1,0,0,0,0,1],a.modelMatrix);a.mvMatrix=G(a.viewMatrix,a.modelMatrix)}function qa(a,b){a.viewDist*=Math.pow(1.01,b);a.viewMatrix=[1,0,0,0,0,1,0,0,0,0,1,-a.viewDist,0,0,0,1];a.mvMatrix=G(a.viewMatrix,a.modelMatrix)}function ra(a,b){let c=Math.cos(b);b=Math.sin(b);a.modelMatrix=G([c,-b,0,0,b,c,0,0,0,0,1,0,0,0,0,1],a.modelMatrix);a.mvMatrix=G(a.viewMatrix,a.modelMatrix)};function sa(a){return{color:a,alpha:1,m:60,size:.05}}function J(a){return{color:a.color,alpha:a.alpha,m:a.m,size:a.size}};function ta(a,b,c,e){function f(l){g.removeEventListener("webglcontextcreationerror",f,!1);l.statusMessage&&(p=l.statusMessage)}let g=document.getElementById(a);if(!g)throw new D("No canvas element with id "+a);let p="Unknown";g.addEventListener("webglcontextcreationerror",f,!1);"undefined"!==typeof CindyJS._pluginRegistry.CindyXR&&(b.xrCompatible=!0);a=null;var k=document.createElement("canvas");window.WebGL2RenderingContext&&k.getContext("webgl2")&&(a=g.getContext("webgl2",b),a.g=!0,console.log("Loaded WebGL 2.0."));
a||(k=document.createElement("canvas"),window.WebGLRenderingContext&&g.getContext("webgl")&&(a=g.getContext("webgl",b),console.log("Loaded WebGL 1.0."),/[?&]frag_depth=0/.test(window.location.search)?this.C=null:(this.C=a.getExtension("EXT_frag_depth"))||console.log("EXT_frag_depth extension not supported.")));a||(a=g.getContext("experimental-webgl",b));if(!a)throw new D("Could not obtain a WebGL context.\nReason: "+p);g.removeEventListener("webglcontextcreationerror",f,!1);a.depthFunc(a.LEQUAL);
a.blendFunc(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA);this.canvas=g;this.width=g.width;this.height=g.height;this.gl=a;this.g=1;c&&c.W&&(this.g=c.W|0,1>this.g&&(this.g=1));if(1!==this.g){b=this.width*this.height*this.g;for(c=64;c*c<b;)c*=2;this.l=this.j=c;this.D=a.createTexture();a.bindTexture(a.TEXTURE_2D,this.D);a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MAG_FILTER,a.LINEAR);a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MIN_FILTER,a.LINEAR_MIPMAP_LINEAR);a.hint(a.GENERATE_MIPMAP_HINT,a.NICEST);a.texImage2D(a.TEXTURE_2D,
0,a.RGB,this.l,this.j,0,a.RGB,a.UNSIGNED_BYTE,null);a.generateMipmap(a.TEXTURE_2D);a.bindTexture(a.TEXTURE_2D,null);this.P=a.createRenderbuffer();a.bindRenderbuffer(a.RENDERBUFFER,this.P);a.renderbufferStorage(a.RENDERBUFFER,a.DEPTH_COMPONENT16,this.l,this.j);a.bindRenderbuffer(a.RENDERBUFFER,null);this.R=a.createFramebuffer();a.bindFramebuffer(a.FRAMEBUFFER,this.R);a.framebufferTexture2D(a.FRAMEBUFFER,a.COLOR_ATTACHMENT0,a.TEXTURE_2D,this.D,0);a.framebufferRenderbuffer(a.FRAMEBUFFER,a.DEPTH_ATTACHMENT,
a.RENDERBUFFER,this.P);b=a.checkFramebufferStatus(a.FRAMEBUFFER);if(b!==a.FRAMEBUFFER_COMPLETE)throw new D("Failed to create supersampling framebuffer. glCheckFramebufferStatus returned "+b);a.bindFramebuffer(a.FRAMEBUFFER,null);this.L=a.createBuffer();a.bindBuffer(a.ARRAY_BUFFER,this.L);a.bufferData(a.ARRAY_BUFFER,new Float32Array([1,1,1,1,-1,1,0,1,1,-1,1,0,-1,-1,0,0]),a.STATIC_DRAW);this.H=new aa(a,"precision highp float;\n\nattribute vec4 aPos;\nvarying vec2 vPos;\n\nvoid main(){\nvPos=aPos.zw;\ngl_Position=vec4(aPos.xy,0,1);\n}\n",
"precision highp float;\n\nuniform sampler2D uTexture;\nvarying vec2 vPos;\n\nvoid main(){\ngl_FragColor=texture2D(uTexture,vPos);\n}\n");this.F=a.getAttribLocation(this.H.handle,"aPos")}else this.l=this.width,this.j=this.height;this.B=new ua;this.K="uniform vec3 uAmbient;\nuniform mat4 uModelViewMatrix;\n\nvarying vec4 vColor;\nvarying float vShininess;\nvarying float vSpecularReflectiveness;\n\nvec4 gColor;\nvec3 gPos;\nvec3 gEye;\nvec3 gNormal;\nvec3 gAccumDiffuse;\nvec3 gAccumSpecular;\n\nvoid commonLight(in vec4 lightPos,out vec3 lightDir,\nout float diffuseFactor,out float specularFactor){\nvec3 halfVector;\nfloat specularDot;\n\nlightDir=normalize(lightPos.xyz-lightPos.w*gPos);\nhalfVector=normalize(lightDir+gEye);\ndiffuseFactor=max(0.0,dot(gNormal,lightDir));\nspecularDot=max(0.0,dot(gNormal,halfVector));\n\n\nif(diffuseFactor==0.0)\nspecularFactor=0.0;\nelse\nspecularFactor=pow(specularDot,vShininess) *vSpecularReflectiveness;\n}\n\nvec4 flipY(in vec4 v){\nreturn vec4(v.x, -v.y,v.z,v.w);\n}\n\nvoid pointLight(in vec4 lightPos,in vec3 diffuse,in vec3 specular){\nvec3 lightDir;\nfloat diffuseFactor;\nfloat specularFactor;\n\ncommonLight(lightPos,lightDir,diffuseFactor,specularFactor);\n\n\ngAccumDiffuse +=diffuse*diffuseFactor;\ngAccumSpecular+=specular*specularFactor;\n}\n\nvoid cameraPointLight(in vec4 lightPos,in vec3 diffuse,in vec3 specular){\npointLight(flipY(lightPos),diffuse,specular);\n}\n\nvoid worldPointLight(in vec4 lightPos,in vec3 diffuse,in vec3 specular){\npointLight(-uModelViewMatrix*lightPos,diffuse,specular);\n}\n\nvoid spotLight(\nin vec4 lightPos,in vec4 spotPos,in float spotCosCutoff,\nin float spotExponent,in vec3 diffuse,in vec3 specular)\n{\nvec3 lightDir;\nfloat diffuseFactor;\nfloat specularFactor;\nvec3 spotDir;\nfloat spotCosAngle;\nfloat spotAttenuation;\n\ncommonLight(lightPos,lightDir,diffuseFactor,specularFactor);\n\nspotDir=lightPos.w*spotPos.xyz-spotPos.w*lightPos.xyz;\nspotCosAngle=dot(-lightDir,normalize(spotDir));\nspotAttenuation=\nstep(spotCosCutoff,spotCosAngle) *pow(spotCosAngle,spotExponent);\n\n\ngAccumDiffuse +=spotAttenuation*diffuse*diffuseFactor;\ngAccumSpecular+=spotAttenuation*specular*specularFactor;\n}\n\nvoid cameraSpotLight(\nin vec4 lightPos,in vec4 spotPos,in float spotCosCutoff,\nin float spotExponent,in vec3 diffuse,in vec3 specular)\n{\nspotLight(\nflipY(lightPos),flipY(spotPos),\nspotCosCutoff,spotExponent,diffuse,specular);\n}\n\nvoid worldSpotLight(\nin vec4 lightPos,in vec4 spotPos,in float spotCosCutoff,\nin float spotExponent,in vec3 diffuse,in vec3 specular)\n{\nspotLight(\n-uModelViewMatrix*lightPos, -uModelViewMatrix*spotPos,\nspotCosCutoff,spotExponent,diffuse,specular);\n}\n"+
va(this.B)+"\n\n\n\n\n\nvoid shade(in vec3 position,in vec3 normal){\n\ngAccumDiffuse=vec3(0.0);\ngAccumSpecular=vec3(0.0);\n\n\ngPos=position;\ngEye= -normalize(position);\ngNormal=sign(dot(gEye,normal))*normal;\n\n\nlightScene();\n\n\n\nvec3 color= (uAmbient+gAccumDiffuse) *gColor.xyz\n+gAccumSpecular;\n\ncolor=clamp(color,0.0,1.0);\ngl_FragColor=vec4(color.xyz,gColor.w);\n}\n";this.camera=new na(this.width,this.height);this.spheres=new K(this);this.cylinders=new L(this);this.triangles=new wa(this);
this.A=J(O.I);this.u=J(O.line);this.s=J(O.J);this.T=[];this.backgroundColor=[1,1,1,1];e||(e=function(l,n,h,d){l.addEventListener(n,h,!!d)});new xa(e,this.canvas,this.camera,this)}var O={I:J(sa([1,0,0])),line:J(sa([0,0,1])),J:J(sa([0,1,0]))};ta.prototype.clear=function(){this.spheres.clear();this.cylinders.clear();this.triangles.clear()};
ta.prototype.v=function(){this.B.h&&(this.K="uniform vec3 uAmbient;\nuniform mat4 uModelViewMatrix;\n\nvarying vec4 vColor;\nvarying float vShininess;\nvarying float vSpecularReflectiveness;\n\nvec4 gColor;\nvec3 gPos;\nvec3 gEye;\nvec3 gNormal;\nvec3 gAccumDiffuse;\nvec3 gAccumSpecular;\n\nvoid commonLight(in vec4 lightPos,out vec3 lightDir,\nout float diffuseFactor,out float specularFactor){\nvec3 halfVector;\nfloat specularDot;\n\nlightDir=normalize(lightPos.xyz-lightPos.w*gPos);\nhalfVector=normalize(lightDir+gEye);\ndiffuseFactor=max(0.0,dot(gNormal,lightDir));\nspecularDot=max(0.0,dot(gNormal,halfVector));\n\n\nif(diffuseFactor==0.0)\nspecularFactor=0.0;\nelse\nspecularFactor=pow(specularDot,vShininess) *vSpecularReflectiveness;\n}\n\nvec4 flipY(in vec4 v){\nreturn vec4(v.x, -v.y,v.z,v.w);\n}\n\nvoid pointLight(in vec4 lightPos,in vec3 diffuse,in vec3 specular){\nvec3 lightDir;\nfloat diffuseFactor;\nfloat specularFactor;\n\ncommonLight(lightPos,lightDir,diffuseFactor,specularFactor);\n\n\ngAccumDiffuse +=diffuse*diffuseFactor;\ngAccumSpecular+=specular*specularFactor;\n}\n\nvoid cameraPointLight(in vec4 lightPos,in vec3 diffuse,in vec3 specular){\npointLight(flipY(lightPos),diffuse,specular);\n}\n\nvoid worldPointLight(in vec4 lightPos,in vec3 diffuse,in vec3 specular){\npointLight(-uModelViewMatrix*lightPos,diffuse,specular);\n}\n\nvoid spotLight(\nin vec4 lightPos,in vec4 spotPos,in float spotCosCutoff,\nin float spotExponent,in vec3 diffuse,in vec3 specular)\n{\nvec3 lightDir;\nfloat diffuseFactor;\nfloat specularFactor;\nvec3 spotDir;\nfloat spotCosAngle;\nfloat spotAttenuation;\n\ncommonLight(lightPos,lightDir,diffuseFactor,specularFactor);\n\nspotDir=lightPos.w*spotPos.xyz-spotPos.w*lightPos.xyz;\nspotCosAngle=dot(-lightDir,normalize(spotDir));\nspotAttenuation=\nstep(spotCosCutoff,spotCosAngle) *pow(spotCosAngle,spotExponent);\n\n\ngAccumDiffuse +=spotAttenuation*diffuse*diffuseFactor;\ngAccumSpecular+=spotAttenuation*specular*specularFactor;\n}\n\nvoid cameraSpotLight(\nin vec4 lightPos,in vec4 spotPos,in float spotCosCutoff,\nin float spotExponent,in vec3 diffuse,in vec3 specular)\n{\nspotLight(\nflipY(lightPos),flipY(spotPos),\nspotCosCutoff,spotExponent,diffuse,specular);\n}\n\nvoid worldSpotLight(\nin vec4 lightPos,in vec4 spotPos,in float spotCosCutoff,\nin float spotExponent,in vec3 diffuse,in vec3 specular)\n{\nspotLight(\n-uModelViewMatrix*lightPos, -uModelViewMatrix*spotPos,\nspotCosCutoff,spotExponent,diffuse,specular);\n}\n"+va(this.B)+
"\n\n\n\n\n\nvoid shade(in vec3 position,in vec3 normal){\n\ngAccumDiffuse=vec3(0.0);\ngAccumSpecular=vec3(0.0);\n\n\ngPos=position;\ngEye= -normalize(position);\ngNormal=sign(dot(gEye,normal))*normal;\n\n\nlightScene();\n\n\n\nvec3 color= (uAmbient+gAccumDiffuse) *gColor.xyz\n+gAccumSpecular;\n\ncolor=clamp(color,0.0,1.0);\ngl_FragColor=vec4(color.xyz,gColor.w);\n}\n",ya(this.spheres,this),ya(this.cylinders,this),ya(this.triangles,this));if(1===this.g)za(this);else{let a=this.gl;a.bindFramebuffer(a.FRAMEBUFFER,
this.R);za(this);a.bindFramebuffer(a.FRAMEBUFFER,null);a.viewport(0,0,this.width,this.height);a.disable(a.DEPTH_TEST);a.bindTexture(a.TEXTURE_2D,this.D);a.generateMipmap(a.TEXTURE_2D);a.bindBuffer(a.ARRAY_BUFFER,this.L);a.enableVertexAttribArray(this.F);a.vertexAttribPointer(this.F,4,a.FLOAT,!1,16,0);this.H.use(a);this.H.uniform.uTexture([0]);a.drawArrays(a.TRIANGLE_STRIP,0,4);a.disableVertexAttribArray(this.F);a.bindTexture(a.TEXTURE_2D,null)}this.gl.flush()};
function za(a){let b=a.gl,c="undefined"!==typeof CindyJS._pluginRegistry.CindyLeap,e="undefined"!==typeof CindyJS._pluginRegistry.CindyXR;e||b.viewport(0,0,a.l,a.j);b.clearColor.apply(b,a.backgroundColor);b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT);a.spheres.o&&a.cylinders.o&&a.triangles.o?(b.disable(b.BLEND),b.depthMask(!0),b.enable(b.DEPTH_TEST)):(b.disable(b.DEPTH_TEST),b.enable(b.BLEND),b.depthMask(!1));let f=1;c?CindyJS._pluginRegistry.CindyLeap.leapPreRender(a.camera):e&&(f=CindyJS._pluginRegistry.CindyXR.xrGetNumViews(),
CindyJS._pluginRegistry.CindyXR.xrPreRender(b,a.camera));for(let g=0;g<f;g++)e&&CindyJS._pluginRegistry.CindyXR.xrUpdateCindy3DCamera(b,g,a.camera),a.spheres.o&&a.cylinders.o&&a.triangles.o?(b.disable(b.BLEND),b.depthMask(!0),b.enable(b.DEPTH_TEST),Aa(a,!0)):(b.disable(b.DEPTH_TEST),b.enable(b.BLEND),b.depthMask(!1),Aa(a,!1),Aa(a,!1),b.depthMask(!0),b.enable(b.DEPTH_TEST),Aa(a,!1));c?CindyJS._pluginRegistry.CindyLeap.leapPostRender(a.camera):e&&CindyJS._pluginRegistry.CindyXR.xrPostRender(b,a.camera);
"undefined"!==typeof a.externalRenderHook&&a.externalRenderHook(b)}function Aa(a,b){b||a.spheres.v(a,1);a.triangles.v(a);a.cylinders.v(a);a.spheres.v(a,-1)}ta.prototype.h=function(a){a.uProjectionMatrix(this.camera.projectionMatrix);var b=this.camera.mvMatrix;a.uModelViewMatrix([b[0],b[4],b[8],b[12],b[1],b[5],b[9],b[13],b[2],b[6],b[10],b[14],b[3],b[7],b[11],b[15]]);b=this.B;a.uAmbient(b.S);for(let c=0;c<b.g.length;++c)b.g[c]&&Ba(b.g[c],a,c)};function xa(a,b,c,e){this.canvas=b;this.camera=c;this.l=e;this.j=this.h=Number.NaN;this.g=!1;this.touches=new Map;a(b,"mousedown",this.Y.bind(this));a(b,"mousemove",this.$.bind(this));a(b,"mouseup",this.aa.bind(this));a(b,"mouseleave",this.Z.bind(this));a(b,"wheel",this.fa.bind(this));a(b,"touchstart",this.ea.bind(this));a(b,"touchend",this.ca.bind(this));a(b,"touchcancel",this.ba.bind(this));a(b,"touchmove",this.da.bind(this))}C=xa.prototype;
C.Y=function(a){0===a.button&&(this.g=!0);if(void 0===a.buttons?this.g:a.buttons&1)this.h=a.clientX,this.j=a.clientY};
C.$=function(a){if(void 0===a.buttons?this.g:a.buttons&1){if(!isNaN(this.h)){var b=a.clientX-this.h,c=a.clientY-this.j;if(a.shiftKey){var e=this.camera,f=-.01*b,g=-.01*c;c=Math.cos(f);b=Math.cos(g);f=Math.sin(f);g=Math.sin(g);let p=[1,0,0,0,0,1,0,0,0,0,1,e.viewDist,0,0,0,1];e.mvMatrix=G(G([c,0,f,0,0,1,0,0,-f,0,c,0,0,0,0,1],[1,0,0,0,0,b,-g,0,0,g,b,0,0,0,0,1]),e.mvMatrix);e.modelMatrix=G(p,e.mvMatrix)}else a.altKey||a.ctrlKey||a.metaKey?pa(this.camera,b,c):oa(this.camera,b,c);this.l.v()}this.h=a.clientX;
this.j=a.clientY}};C.aa=function(a){0===a.button&&(this.g=!1)};C.Z=function(){this.g=!1;this.h=this.j=Number.NaN};C.fa=function(a){let b=a.deltaY;if(b){if(a.shiftKey)ra(this.camera,-.01*b);else if(a.altKey||a.ctrlKey||a.metaKey){var c=this.camera;c.modelMatrix=G([1,0,0,0,0,1,0,0,0,0,1,-.02*c.viewDist*b,0,0,0,1],c.modelMatrix);c.mvMatrix=G(c.viewMatrix,c.modelMatrix)}else qa(this.camera,b);this.l.v()}a.preventDefault()};
C.ea=function(a){a.preventDefault();a=a.changedTouches;for(let b=0;b<a.length;++b){let c=a[b];this.touches.set(c.identifier,{x:c.clientX,y:c.clientY})}};C.ca=function(a){a.preventDefault();a=a.changedTouches;for(let b=0;b<a.length;++b)this.touches.delete(a[b].identifier)};C.ba=function(a){a.preventDefault();a=a.changedTouches;for(let b=0;b<a.length;++b)this.touches.delete(a[b].identifier)};
C.da=function(a){a.preventDefault();var b=a.targetTouches;if(1===b.length){var c=b[0];b=this.touches.get(c.identifier);oa(this.camera,c.clientX-b.x,c.clientY-b.y);this.l.v()}else if(2===b.length){c=b[0];var e=b[1],f=this.touches.get(c.identifier),g=this.touches.get(e.identifier),p=this.canvas.getBoundingClientRect();b=this.canvas.clientLeft+p.left+.5*this.camera.width;p=this.canvas.clientTop+p.top+.5*this.camera.height;let k=.5*(f.x+g.x+1),l=.5*(f.y+g.y+1);pa(this.camera,b-k,p-l);let n=f.x-g.x;f=
f.y-g.y;g=Math.hypot(n,f);let h=Math.atan2(f,n);k=.5*(c.clientX+e.clientX+1);l=.5*(c.clientY+e.clientY+1);n=c.clientX-e.clientX;f=c.clientY-e.clientY;c=Math.atan2(f,n);qa(this.camera,g-Math.hypot(n,f));ra(this.camera,h-c);pa(this.camera,k-b,l-p);this.l.v()}b=a.changedTouches;for(a=0;a<b.length;++a)c=b[a],e=this.touches.get(c.identifier),e.x=c.clientX,e.y=c.clientY};function ua(){this.S=[0,0,0];this.g=[new Ca([0,0,0,1],[1,1,1],[1,1,1])];this.h=!1}function Da(a,b,c){a.h=!c!==!a.g[b]||!!c&&a.g[b].type!==c.type;a.g[b]=c}function va(a){let b="",c="";for(let e=0;e<a.g.length;++e)a.g[e]&&(b+=Ea(a.g[e],e),c+=Fa(a.g[e],e));return b+"void lightScene() {\n"+c+"}"}function Ga(a,b){this.type=a;this.g=b}Ga.prototype.h={uDiffuse:"vec3",uSpecular:"vec3",uLightPos:"vec4",uSpotPos:"vec4",uSpotCosCutoff:"float",uSpotExponent:"float"};
function Fa(a,b){return" "+a.type+"("+a.g.map(c=>c+b).join(", ")+");\n"}function Ea(a,b){return a.g.map(c=>"uniform "+a.h[c]+" "+c+b+";\n").join("")}function Ba(a,b,c){a.g.forEach(e=>b[e+c](a[e]))}function Ca(a,b,c){this.uLightPos=a;this.uDiffuse=b;this.uSpecular=c}Ca.prototype=new Ga("cameraPointLight",["uLightPos","uDiffuse","uSpecular"]);function Ha(a,b,c){this.uLightPos=a;this.uDiffuse=b;this.uSpecular=c}Ha.prototype=new Ga("worldPointLight",["uLightPos","uDiffuse","uSpecular"]);
const Ia={camera:Ca,world:Ha};function Ja(a,b,c,e,f,g){this.uLightPos=a;this.uSpotPos=b;this.uSpotCosCutoff=[c];this.uSpotExponent=[e];this.uDiffuse=f;this.uSpecular=g}Ja.prototype=new Ga("cameraSpotLight","uLightPos uSpotPos uSpotCosCutoff uSpotExponent uDiffuse uSpecular".split(" "));function Ka(a,b,c,e,f,g){this.uLightPos=a;this.uSpotPos=b;this.uSpotCosCutoff=[c];this.uSpotExponent=[e];this.uDiffuse=f;this.uSpecular=g}Ka.prototype=new Ga("worldSpotLight","uLightPos uSpotPos uSpotCosCutoff uSpotExponent uDiffuse uSpecular".split(" "));
const La={camera:Ja,world:Ka};function Ma(a,b){let c=a.length,e=b.length,f=Math.max.apply(null,b)+1;this.H=a;this.numAttributes=c;this.numVertices=f;this.C=b;this.numElements=e;this.itemLength=4*f*c;this.vertexByteCount=16*c;this.itemAttribByteCount=a=f*this.vertexByteCount;this.itemTotalByteCount=a+e*this.l;this.maxCount=Math.floor(65536/a)}Ma.prototype.l=2;
function Na(a,b,c){a.mode=b;a.count=0;a.o=!0;a.g=16;a.data=new ArrayBuffer(16*a.itemTotalByteCount);a.dataAttribs=new Float32Array(a.data,0,16*a.itemLength);b=new Uint16Array(a.data,16*a.itemAttribByteCount);a.h=b;let e,f,g=0,p,k=a.C;for(e=0;16>e;++e)for(p=e*a.numVertices,f=0;f<k.length;++f)b[g++]=k[f]+p;a.K=c.gl.createBuffer();a.L=c.gl.createBuffer();a.F=-1;a.j=null;ya(a,c)}
function ya(a,b){let c=b.gl;null!==a.j&&ea(a.j,c);let e=["precision highp float;\nvarying float vShininess;\nvarying float vSpecularReflectiveness;",a.O].join("\n"),f=["precision highp float;",b.K,a.M].join("\n");b.C&&(f="#extension GL_EXT_frag_depth : enable\n"+f);a.j=new aa(c,e,f);let g=a.j.handle;a.D=a.H.map(p=>c.getAttribLocation(g,p))}
function Oa(a,b){if(b.length!==a.itemLength)throw new D("Wrong number of attributes given");if(a.count==a.g){let c=2*a.g,e,f,g,p,k,l,n,h=a.C;c>a.maxCount&&(a.g<a.maxCount?c=a.maxCount:(a.l=4,a.itemTotalByteCount=a.itemAttribByteCount+a.numElements*a.l,a.maxCount=Math.floor(Math.pow(2,32)/a.itemAttribByteCount)));e=new ArrayBuffer(c*a.itemTotalByteCount);f=new Float32Array(e,0,c*a.itemLength);2===a.l?g=new Uint16Array(e,c*a.itemAttribByteCount):g=new Uint32Array(e,c*a.itemAttribByteCount);f.set(a.dataAttribs);
g.set(a.h);l=a.h.length;for(p=a.g;p<c;++p)for(n=p*a.numVertices,k=0;k<h.length;++k)g[l++]=h[k]+n;a.g=c;a.data=e;a.dataAttribs=f;a.h=g}a.dataAttribs.set(b,a.count++*a.itemLength)}
function Pa(a,b,c){if(0!==a.count){var e=a.j,f=e.uniform;e.use(b);c(f);b.bindBuffer(b.ARRAY_BUFFER,a.K);b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,a.L);a.F!==a.g?(b.bufferData(b.ARRAY_BUFFER,a.dataAttribs,b.STATIC_DRAW),b.bufferData(b.ELEMENT_ARRAY_BUFFER,a.h,b.STATIC_DRAW),a.F=a.g):b.bufferSubData(b.ARRAY_BUFFER,0,new Float32Array(a.data,0,a.count*a.itemLength));for(c=0;c<a.numAttributes;++c)e=a.D[c],b.enableVertexAttribArray(e),b.vertexAttribPointer(e,4,b.FLOAT,!1,a.vertexByteCount,16*c);c=b.UNSIGNED_SHORT;
a.h instanceof Uint32Array&&(c=b.UNSIGNED_INT,b.getExtension("OES_element_index_uint"));b.drawElements(a.mode,a.numElements*a.count,c,0);for(c=0;c<a.numAttributes;++c)b.disableVertexAttribArray(a.D[c])}}Ma.prototype.clear=function(){this.count=0;this.o=!0};function K(a){Na(this,a.gl.TRIANGLES,a)}K.prototype=new Ma(["aCenter","aColor","aRelativeShininessRadius"],[0,1,2,2,1,3]);K.prototype.O="uniform mat4 uProjectionMatrix;\n\nuniform mat4 uModelViewMatrix;\n\nattribute vec4 aCenter;\n\nattribute vec4 aColor;\n\nattribute vec4 aRelativeShininessRadius;\n\nvarying vec3 vViewSpacePos;\n\nvarying vec3 vViewSpaceCenter;\n\nvarying vec4 vColor;\n\nvarying float vRadius;\n\n\n\n\nvoid main(){\n\nvec4 viewPosHom=uModelViewMatrix*aCenter;\nvViewSpaceCenter=viewPosHom.xyz/viewPosHom.w;\nvec3 dir=normalize(-vViewSpaceCenter);\nvec3 right=normalize(cross(dir,vec3(0,1,0)));\nvec3 up=normalize(cross(right,dir));\n\n\nvColor=aColor;\nvShininess=aRelativeShininessRadius.z;\nvSpecularReflectiveness= (1.0-pow(0.95,vShininess));\nvRadius=aRelativeShininessRadius.w;\n\n\nvViewSpacePos=vViewSpaceCenter+\nvRadius*(right*aRelativeShininessRadius.x+\nup*aRelativeShininessRadius.y+dir);\n\n\ngl_Position=uProjectionMatrix*vec4(vViewSpacePos,1);\n}\n";
K.prototype.M="uniform mat4 uProjectionMatrix;\n\nvec3 sphere(in vec3 ray,in vec3 center,in float radius,in float face){\n\nvec3 dir=normalize(ray);\n\n\n\n\nfloat b=dot(center,dir);\nfloat c=dot(center,center) -radius*radius;\nfloat d=b*b-c;\nif(d<0.0)discard;\nfloat lambda=b+face*sqrt(d);\nif(lambda<0.0)discard;\n\n\nreturn lambda*dir;\n}\n\nvoid finish(in vec3 pos,in vec3 normal){\nshade(pos,normal);\nvec4 projPoint=uProjectionMatrix*vec4(pos,1);\n#ifdef webgl2\ngl_FragDepth= (projPoint.z/projPoint.w+1.0) /2.0;\n#else\n#ifdef GL_EXT_frag_depth\ngl_FragDepthEXT= (projPoint.z/projPoint.w+1.0) /2.0;\n#endif\n#endif\n}\n\n\nuniform float sphereMode;\n\n\nvarying vec3 vViewSpacePos;\n\nvarying vec3 vViewSpaceCenter;\n\nvarying float vRadius;\n\n\n\n\nvoid main(){\ngColor=vColor;\nvec3 pointOnSphere=\nsphere(vViewSpacePos,vViewSpaceCenter,vRadius,sphereMode);\nvec3 normal=normalize(pointOnSphere-vViewSpaceCenter);\nfinish(pointOnSphere,normal);\n}\n";
K.prototype.add=function(a,b,c){let e=a[0],f=a[1],g=a[2];a=a[3];var p=c.color;let k=c.m,l=p[0],n=p[1];p=p[2];c=c.alpha;1>c&&(this.o=!1);Oa(this,[e,f,g,a,l,n,p,c,1,1,k,b,e,f,g,a,l,n,p,c,-1,1,k,b,e,f,g,a,l,n,p,c,1,-1,k,b,e,f,g,a,l,n,p,c,-1,-1,k,b])};K.prototype.v=function(a,b){Pa(this,a.gl,c=>{a.h(c);c.sphereMode([b])})};function L(a){Na(this,a.gl.TRIANGLE_STRIP,a)}L.prototype=new Ma(["aPoint1","aPoint2","aColor","aRelativeRadius","aShininess"],[0,0,2,4,6,7,2,3,1,7,5,4,1,0,2,2]);L.prototype.O="uniform mat4 uProjectionMatrix;\n\nuniform mat4 uModelViewMatrix;\n\nattribute vec4 aPoint1;\n\nattribute vec4 aPoint2;\n\nattribute vec4 aColor;\n\nattribute vec4 aRelativeRadius;\n\nattribute vec4 aShininess;\n\nvarying vec3 vPoint1;\n\nvarying vec3 vPoint2;\n\nvarying vec3 vPos;\n\nvarying vec4 vColor;\n\nvarying float vRadius;\n\n\n\n\nvoid main(){\n\nvec4 hom;\nhom=uModelViewMatrix*aPoint1;\nvPoint1=hom.xyz/hom.w;\nhom=uModelViewMatrix*aPoint2;\nvPoint2=hom.xyz/hom.w;\nvec3 dir=normalize(vPoint2-vPoint1);\n\n\nvec3 d2,d3;\nif(abs(dir.x) <abs(dir.y))\nd2=vec3(1,0,0);\nelse\nd2=vec3(0,1,0);\nd2=normalize(cross(dir,d2));\nd3=normalize(cross(dir,d2));\n\nvPos=aRelativeRadius.w*(mat3(dir,d2,d3)*aRelativeRadius.xyz)\n+0.5*((vPoint2+vPoint1) +aRelativeRadius.x*(vPoint2-vPoint1));\n\n\nvColor=aColor;\nvShininess=aShininess.x;\nvSpecularReflectiveness= (1.0-pow(0.95,vShininess));\nvRadius=aRelativeRadius.w;\n\n\ngl_Position=uProjectionMatrix*vec4(vPos,1);\n}\n";
L.prototype.M="uniform mat4 uProjectionMatrix;\n\nvec3 sphere(in vec3 ray,in vec3 center,in float radius,in float face){\n\nvec3 dir=normalize(ray);\n\n\n\n\nfloat b=dot(center,dir);\nfloat c=dot(center,center) -radius*radius;\nfloat d=b*b-c;\nif(d<0.0)discard;\nfloat lambda=b+face*sqrt(d);\nif(lambda<0.0)discard;\n\n\nreturn lambda*dir;\n}\n\nvoid finish(in vec3 pos,in vec3 normal){\nshade(pos,normal);\nvec4 projPoint=uProjectionMatrix*vec4(pos,1);\n#ifdef webgl2\ngl_FragDepth= (projPoint.z/projPoint.w+1.0) /2.0;\n#else\n#ifdef GL_EXT_frag_depth\ngl_FragDepthEXT= (projPoint.z/projPoint.w+1.0) /2.0;\n#endif\n#endif\n}\n\nvarying vec3 vPoint1;\n\nvarying vec3 vPoint2;\n\nvarying vec3 vPos;\n\nvarying float vRadius;\n\nvec3 endcaps(in float mu,inout vec3 pos){\nvec3 center;\nif(mu<0.0){\ncenter=vPoint1;\n}else if(mu>1.0){\ncenter=vPoint2;\n}else{\nreturn(1.0-mu)*vPoint1+mu*vPoint2;\n}\npos=sphere(vPos,center,vRadius, -1.0);\nreturn center;\n}\n\n\n\n\nvoid main(){\ngColor=vColor;\n\n\n\nvec3 ba=vPoint2-vPoint1;\nvec3 u=ba/dot(ba,ba);\nvec3 v=vPos-dot(vPos,ba)*u;\nvec3 w=dot(vPoint1,ba)*u-vPoint1;\nfloat a=dot(v,v);\nfloat b=2.0*dot(v,w);\nfloat c=dot(w,w) -vRadius*vRadius;\nfloat d=b*b-4.0*a*c;\nif(d<0.0)\ndiscard;\nfloat lambda= (b+sqrt(d))/(-2.0*a);\nvec3 pointOnSurface=lambda*vPos;\nfloat mu=dot(pointOnSurface-vPoint1,u);\nvec3 center=endcaps(mu,pointOnSurface);\nvec3 normal=normalize(pointOnSurface-center);\nfinish(pointOnSurface,normal);\n}\n";
L.prototype.add=function(a,b,c){let e=a[0],f=a[1],g=a[2];a=a[3];let p=b[0],k=b[1],l=b[2];b=b[3];var n=c.color;let h=c.m,d=c.size,m=n[0],q=n[1];n=n[2];c=c.alpha;1>c&&(this.o=!1);Oa(this,[e,f,g,a,p,k,l,b,m,q,n,c,1,1,1,d,h,0,0,0,e,f,g,a,p,k,l,b,m,q,n,c,1,1,-1,d,h,0,0,0,e,f,g,a,p,k,l,b,m,q,n,c,1,-1,1,d,h,0,0,0,e,f,g,a,p,k,l,b,m,q,n,c,1,-1,-1,d,h,0,0,0,e,f,g,a,p,k,l,b,m,q,n,c,-1,1,1,d,h,0,0,0,e,f,g,a,p,k,l,b,m,q,n,c,-1,1,-1,d,h,0,0,0,e,f,g,a,p,k,l,b,m,q,n,c,-1,-1,1,d,h,0,0,0,e,f,g,a,p,k,l,b,m,q,n,c,-1,
-1,-1,d,h,0,0,0])};L.prototype.v=function(a){if(0!==this.count){var b=a.gl;b.enable(b.CULL_FACE);b.cullFace(b.BACK);Pa(this,b,a.h.bind(a));b.disable(b.CULL_FACE)}};function wa(a){Na(this,a.gl.TRIANGLES,a)}wa.prototype=new Ma(["aPos","aNormalAndShininess","aColor"],[0,1,2]);C=wa.prototype;C.O="uniform mat4 uProjectionMatrix;\nuniform mat4 uModelViewMatrix;\n\nattribute vec4 aPos;\nattribute vec4 aNormalAndShininess;\nattribute vec4 aColor;\n\nvarying vec4 vPos;\nvarying vec4 vNormal;\nvarying vec4 vColor;\n\nvoid main(){\nvPos=uModelViewMatrix*aPos;\ngl_Position=uProjectionMatrix*vPos;\nvNormal=uModelViewMatrix*vec4(aNormalAndShininess.xyz,0.0);\nvShininess=aNormalAndShininess.w;\nvSpecularReflectiveness= (1.0-pow(0.95,vShininess));\nvColor=aColor;\n}\n";
C.M="uniform mat4 uProjectionMatrix;\n\nvec3 sphere(in vec3 ray,in vec3 center,in float radius,in float face){\n\nvec3 dir=normalize(ray);\n\n\n\n\nfloat b=dot(center,dir);\nfloat c=dot(center,center) -radius*radius;\nfloat d=b*b-c;\nif(d<0.0)discard;\nfloat lambda=b+face*sqrt(d);\nif(lambda<0.0)discard;\n\n\nreturn lambda*dir;\n}\n\nvoid finish(in vec3 pos,in vec3 normal){\nshade(pos,normal);\nvec4 projPoint=uProjectionMatrix*vec4(pos,1);\n#ifdef webgl2\ngl_FragDepth= (projPoint.z/projPoint.w+1.0) /2.0;\n#else\n#ifdef GL_EXT_frag_depth\ngl_FragDepthEXT= (projPoint.z/projPoint.w+1.0) /2.0;\n#endif\n#endif\n}\n\nvarying vec4 vPos;\nvarying vec4 vNormal;\n\nuniform bool uTextured;\nuniform sampler2D uTexture;\n\nvoid main(){\nif(uTextured)\ngColor=texture2DProj(uTexture,vColor.xyz);\nelse\ngColor=vColor;\nfinish(vPos.xyz/vPos.w,normalize(vNormal.xyz));\n}\n";
function Q(a,b,c,e,f,g,p,k){var l=k.color;let n=k.m,h=l[0],d=l[1];l=l[2];k=k.alpha;1>k&&(a.o=!1);Oa(a,[b[0],b[1],b[2],b[3],f[0],f[1],f[2],n,h,d,l,k,c[0],c[1],c[2],c[3],g[0],g[1],g[2],n,h,d,l,k,e[0],e[1],e[2],e[3],p[0],p[1],p[2],n,h,d,l,k])}function Qa(a,b,c,e,f,g,p,k,l,n,h){let d=h.m;h=h.alpha;1>h&&(a.o=!1);Oa(a,[b[0],b[1],b[2],b[3],f[0],f[1],f[2],d,k[0],k[1],k[2],h,c[0],c[1],c[2],c[3],g[0],g[1],g[2],d,l[0],l[1],l[2],h,e[0],e[1],e[2],e[3],p[0],p[1],p[2],d,n[0],n[1],n[2],h])}
function Ra(a,b,c){if(3==b.length){var e=b[0],f=b[1];b=b[2];var g=ma(e,f,b);Q(a,e,f,b,g,g,g,c)}else{e=b.length;var p=Array(e+2);g=[0,0,0];for(f=0;f<e;++f)p[f]=E(b[f]);p[e]=p[0];p[e+1]=p[1];for(f=1;f<=e;++f)g=ja(g,la(F(p[f],p[f-1]),F(p[f],p[f+1])));if(4==e)Q(a,b[0],b[1],b[3],g,g,g,c),Q(a,b[3],b[1],b[2],g,g,g,c);else{p=[0,0,0,0];var k=b[e-1];for(f=0;f<e;++f)p=ka(p,b[f]);for(f=0;f<e;++f)Q(a,k,b[f],p,g,g,g,c),k=b[f]}}}
function Va(a,b,c,e){if(3==b.length)Q(a,b[0],b[1],b[2],c[0],c[1],c[2],e);else if(4==b.length)Q(a,b[0],b[1],b[3],c[0],c[1],c[3],e),Q(a,b[3],b[1],b[2],c[3],c[1],c[2],e);else{var f=b.length,g,p=[0,0,0,0],k=[0,0,0];for(g=0;g<f;++g)p=ka(p,b[g]),k=ja(k,c[g]);var l=b[f-1],n=c[f-1];for(g=0;g<f;++g)Q(a,l,b[g],p,n,c[g],k,e),l=b[g],n=c[g]}}C.i=null;C.N=null;C.G=null;C.U=null;C.V=null;
C.v=function(a){const b=a.gl;if(this.i){if(this.i.ready){this.i.X&&this.i.X();null===this.N&&(this.N=b.createTexture());var c=this.i.width,e=this.i.height;c=Wa(c);e=Wa(e);b.activeTexture(b.TEXTURE0);b.bindTexture(b.TEXTURE_2D,this.N);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_S,b.REPEAT);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,b.REPEAT);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,b.LINEAR);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,b.LINEAR_MIPMAP_LINEAR);b.hint(b.GENERATE_MIPMAP_HINT,
b.NICEST);if(this.i.live||this.U!==this.i||this.V!==this.i.generation){this.U=this.i;this.V=this.i.generation;var f=this.i.img;if(c!==this.i.width||e!==this.i.height)this.G||(this.G=document.createElement("canvas"),this.G.width=c,this.G.height=e),f=this.G.getContext("2d"),f.clearRect(0,0,c,e),f.drawImage(this.i.img,0,0,c,e),f=this.G;b.texImage2D(b.TEXTURE_2D,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,f);b.generateMipmap(b.TEXTURE_2D)}Pa(this,b,g=>{a.h(g);g.uTextured([!0]);g.uTexture([0])});b.bindTexture(b.TEXTURE_2D,
null)}}else Pa(this,b,g=>{a.h(g);g.uTextured([!1])})};function Wa(a){if(0===(a&a-1))return a;let b=1;for(;b<a;)b*=2;return b};let S={};function T(a){return"list"!==a.ctype?(console.log("argument is not a list"),null):a.value}function U(a,b=[0,0,0,0],c=3){a=T(a);if(null===a)return b;b=a.map(X);b.length>c+1&&(console.log("Coordinate vector too long."),b=b.slice(0,c+1));for(;b.length<c;)b.push(0);b.length===c&&b.push(1);return b}function Xa(a,b=[0,0,0]){a=T(a);if(null===a)return b;b=a.map(X);3<b.length&&(console.log("Coordinate vector too long."),b=b.slice(0,3));for(;3>b.length;)b.push(0);return b}
function Ya(a,b=[0,0,0,0]){a=Xa(a,b);a!==b&&(a[3]=0);return a}function Y(a,b=[.5,.5,.5]){if("number"===a.ctype){let c=Z(0,1,a);if(!isNaN(c))return[c,c,c]}a=T(a);return null===a?b:3!=a.length?(console.log("Not an RGB color vector"),b):a.map(c=>Z(0,1,c))}function X(a,b=Number.NaN){if("number"!==a.ctype)return console.log("argument is not a number"),b;a=a.value;b=a.real;0!==a.imag&&console.log("complex number is not real");return b}
function Za(a,b=Number.NaN){if("number"!==a.ctype)return console.log("argument is not a number"),b;b=a.value;a=b.real;b=b.imag;0!==b&&console.log("complex number is not real");b=Math.round(a);b!==a&&console.log("number is not an integer");return b}function Z(a,b,c,e=Number.NaN){c=X(c,e);return c<a?a:c>b?b:c}S.toString=function(a,b=null){if("string"===a.ctype)return a.value;console.log("argument is not a string");return b};
function $a(a,b=null){var c=["camera","world"];a=S.toString(a,b);if(a!==b&&-1!==c.indexOf(a))return a;console.log("argument is not one of "+c.join(", "));return b};let ab={};
function bb(a){function b(d,m){let q,u;for(q in d)(u=m[q])?u(l(d[q])):console.log("Modifier "+q+" not supported")}function c(d,m,q=null){let u=d.color,t=d.alpha,r=d.m,v=d.size;d={color:w=>u=Y(w),alpha:w=>t=Z(0,1,w),shininess:w=>r=Z(0,128,w),size:w=>v=.05*X(w)};let y;if(q)for(y in q)d[y]=q[y];b(m,d);return{color:u,alpha:t,m:r,size:v}}function e(d){h.s.alpha=Z(0,1,l(d[0]),1);return k}function f(d,m,q,u,t){let r=0;for(let v=1;v<d;++v){for(let y=1;y<m;++y)t(r,r+1,r+m+1,r+m),++r;q&&t(r,r+1-m,r+1,r+m);
++r}if(u){for(d=1;d<m;++d)t(r,r+1,d,d-1),++r;q&&t(r,r+1-m,0,m-1)}}function g(d,m,q,u,t,r,v,y,w){var z=null===v?()=>w.color:"perface"===y?A=>v[A]:(A,P)=>v[P];f(d,m,q,u,(A,P,V,M)=>{var N=h.triangles;var B=[t[A],t[P],t[V],t[M]],H=[r[A],r[P],r[V],r[M]];A=[z(A,A),z(A,P),z(A,V),z(A,M)];3==B.length?N=Qa(N,B[0],B[1],B[2],H[0],H[1],H[2],A[0],A[1],A[2],w):(4==B.length?(Qa(N,B[0],B[1],B[3],H[0],H[1],H[3],A[0],A[1],A[3],w),Qa(N,B[3],B[1],B[2],H[3],H[1],H[2],A[3],A[1],A[2],w)):console.error("addPolygonWithNormalsAndColors not supported for more than 4 corners"),
N=void 0);return N})}function p(d,m){function q(x,I){x=la(F(x,N),F(I,N));B[0]+=x[0];B[1]+=x[1];B[2]+=x[2];++H}let u=Za(l(d[0])),t=Za(l(d[1])),r=T(l(d[2])).map(x=>U(x)),v="perface",y="pervertex",w="open",z=null,A=null,P=null,V=c(h.s,m,{normaltype:x=>v=S.toString(x,v).toLowerCase(),colortype:x=>y=S.toString(x,y).toLowerCase(),topology:x=>w=S.toString(x,w).toLowerCase(),colors:x=>z=T(x).map(I=>Y(I)),uv:x=>A=T(x).map(I=>U(I,[0,0,0],2)),texture:x=>P=a.getImage(x,!0)});if(r.length!==u*t)return k;null!==
P&&null!=A&&(h.triangles.i=P,h.triangles.o=!1,z=A,y="pervertex");if(null!==z&&z.length!==u*t)return k;m="closerows"===w||"closeboth"===w;let M="closecolumns"===w||"closeboth"===w,N=null,B=null,H=0;if(4===d.length){d=T(l(d[3])).map(x=>Xa(x));if(d.length!==u*t)return k;g(u,t,m,M,r,d,z,y,V)}else if("pervertex"===v){d=Array(u*t);let x=u*t,I=r.map(E);for(let R=0,ha=0;R<u;++R)for(let ba=0;ba<t;++ba){var W=ha+x;N=I[ha];let Sa=I[(W-1)%x],Ta=I[(W+1)%x],Ua=I[(W-t)%x];W=I[(W+t)%x];B=[0,0,0];H=0;(M||0<R)&&(m||
0<ba)&&q(Sa,Ua);(M||R+1<u)&&(m||0<ba)&&q(W,Sa);(M||R+1<u)&&(m||ba+1<t)&&q(Ta,W);(M||0<R)&&(m||ba+1<t)&&q(Ua,Ta);d[ha++]=ia(4/H,B)}g(u,t,m,M,r,d,z,y,V)}else f(u,t,m,M,(x,I,R,ha)=>Ra(h.triangles,[r[x],r[I],r[R],r[ha]],V));return k}let k=a.nada,l=a.evaluate,n=a.defineFunction,h;n("begin3d",0,function(d,m){let q="Cindy3D",u={},t={};b(m,{name:r=>q=S.toString(r,q),antialias:r=>{"boolean"===r.ctype?r=r.value:(console.log("argument is not boolean"),r=!1);return u.antialias=r},supersample:r=>t.W=X(r,1)});
(h=ab[q])||(ab[q]=h=new ta(q,u,t,a.addAutoCleaningEventListener));h.clear();return k});n("end3d",0,function(){h.v();h=null;return k});n("gsave3d",0,function(){h.T.push({I:J(h.A),line:J(h.u),J:J(h.s)});return k});n("grestore3d",0,function(){var d=h.T;0<d.length?(d=d.pop(),h.A=d.I,h.u=d.line,h.s=d.J):(h.A=J(O.I),h.u=J(O.line),h.s=J(O.J));return k});n("color3d",1,function(d){if(d=Y(l(d[0]),null))h.A.color=d,h.u.color=d,h.s.color=d;return k});n("pointcolor3d",1,function(d){if(d=Y(l(d[0]),null))h.A.color=
d;return k});n("linecolor3d",1,function(d){if(d=Y(l(d[0]),null))h.u.color=d;return k});n("surfacecolor3d",1,function(d){if(d=Y(l(d[0]),null))h.s.color=d;return k});n("alpha3d",1,e);n("surfacealpha3d",1,e);n("shininess3d",1,function(d){d=Z(0,128,l(d[0]));isNaN(d)||(h.A.m=d,h.u.m=d,h.s.m=d);return k});n("pointshininess3d",1,function(d){d=Z(0,128,l(d[0]));isNaN(d)||(h.A.m=d);return k});n("lineshininess3d",1,function(d){d=Z(0,128,l(d[0]));isNaN(d)||(h.u.m=d);return k});n("surfaceshininess3d",1,function(d){d=
Z(0,128,l(d[0]));isNaN(d)||(h.s.m=d);return k});n("size3d",1,function(d){d=.05*X(l(d[0]),-1);0<=d&&(h.A.size=d,h.u.size=d);return k});n("pointsize3d",1,function(d){d=.05*X(l(d[0]),-1);0<=d&&(h.A.size=d);return k});n("linesize3d",1,function(d){d=.05*X(l(d[0]),-1);0<=d&&(h.u.size=d);return k});n("draw3d",1,function(d,m){d=U(l(d[0]));m=c(h.A,m);h.spheres.add(d,m.size,m);return k});n("draw3d",2,function(d,m){let q=U(l(d[0]));d=U(l(d[1]));m=c(h.u,m);h.cylinders.add(q,d,m);return k});n("connect3d",1,function(d,
m){d=T(l(d[0]));m=c(h.u,m);if(2>d.length)return k;let q=U(d[0]);for(let u=1;u<d.length;++u){let t=U(d[u]);h.cylinders.add(q,t,m);q=t}return k});n("drawpoly3d",1,function(d,m){d=T(l(d[0]));m=c(h.u,m);if(2>d.length)return k;let q=U(d[d.length-1]);for(let u=0;u<d.length;++u){let t=U(d[u]);h.cylinders.add(q,t,m);q=t}return k});n("fillpoly3d",1,function(d,m){d=T(l(d[0]));m=c(h.s,m);if(2>d.length)return k;d=d.map(q=>U(q));Ra(h.triangles,d,m);return k});n("fillpoly3d",2,function(d,m){var q=T(l(d[0]));d=
T(l(d[1]));m=c(h.s,m);if(2>q.length||q.length!=d.length)return k;q=q.map(u=>U(u));d=d.map(u=>Xa(u));Va(h.triangles,q,d,m);return k});n("fillcircle3d",3,function(){return k});n("drawsphere3d",2,function(d,m){let q=U(l(d[0]));d=X(l(d[1]));m=c(h.s,m);h.spheres.add(q,d,m);return k});n("mesh3d",3,function(d,m){return p(d,m)});n("mesh3d",4,function(d,m){return p(d,m)});n("triangle3d",1,function(d,m){d=T(l(d[0])).map(y=>U(y));let q=null,u=null,t=null,r=null;m=c(h.s,m,{colors:y=>r=T(y).map(w=>Y(w)),uv:y=>
q=T(y).map(w=>U(w,[0,0,0],2)),texture:y=>u=S.toString(y),normals:y=>t=T(y).map(w=>Xa(w))});if(!d||3!==d.length)return k;if(null!==u&&null!==q){var v=a.getImage(u);if(!v)return console.log("No such texture image: "+u),k;h.triangles.i=v;h.triangles.o=!1;r=q}if(null!==r&&3!==r.length||null!==t&&3!==t.length)return k;r||(r=[m.color,m.color,m.color]);t||(v=ma(d[0],d[1],d[2]),t=[v,v,v]);Qa(h.triangles,d[0],d[1],d[2],t[0],t[1],t[2],r[0],r[1],r[2],m);return k});n("background3d",1,function(d){if(d=Y(l(d[0]),
null))d.push(1),h.backgroundColor=d;return k});n("lookat3d",3,function(d){let m=U(l(d[0]),null),q=U(l(d[1]),null);d=Xa(l(d[2]),null);m&&q&&d&&h.camera.setCamera(E(m),E(q),d);return k});n("fieldofview3d",1,function(d){d=Z(.01,3.13,l(d[0]),0);0<d&&(h.camera.fieldOfView=d,h.camera.updatePerspective());return k});n("depthrange3d",2,function(d){let m=X(l(d[0]),-1);d=X(l(d[1]),-1);0<=m&&d>m&&(h.camera.zNear=m,h.camera.zFar=d,h.camera.updatePerspective());return k});n("renderhints3d",0,function(){return k});
n("pointlight3d",1,function(d,m){d=Za(l(d[0]),0);let q=[0,0,0,1],u=[1,1,1],t=[1,1,1],r="camera";b(m,{position:v=>q=U(v,q),diffuse:v=>u=Y(v,u),specular:v=>t=Y(v,t),frame:v=>r=$a(v,r)});Da(h.B,d,new Ia[r](q,u,t));return k});n("directionallight3d",1,function(d,m){d=Za(l(d[0]),0);let q=[0,-1,0,0],u=[1,1,1],t=[1,1,1],r="camera";b(m,{direction:v=>q=Ya(v,q),diffuse:v=>u=Y(v,u),specular:v=>t=Y(v,t),frame:v=>r=$a(v,r)});Da(h.B,d,new Ia[r](q,u,t));return k});n("spotlight3d",1,function(d,m){d=Za(l(d[0]),0);
let q=[0,0,0,1],u=[0,-1,0,0],t=Math.PI/4,r=0,v=[1,1,1],y=[1,1,1],w="camera";b(m,{position:z=>q=U(z,q),direction:z=>u=Ya(z,u),cutoffangle:z=>t=Z(0,Math.PI,z,t),exponent:z=>r=X(z,r),diffuse:z=>v=Y(z,v),specular:z=>y=Y(z,y),frame:z=>w=$a(z,w)});Da(h.B,d,new La[w](q,u,Math.cos(t),r,v,y));return k});n("disablelight3d",1,function(d){d=Za(l(d[0]),0);Da(h.B,d,null);return k});n("ambientlight3d",1,function(d){if(d=Y(l(d[0])))h.B.S=d;return k})}bb.instances=ab;CindyJS.registerPlugin(1,"Cindy3D",bb);
}).call(this);//# sourceMappingURL=Cindy3D.js.map