artproject/klein.js
Andy Tudhope 75c1f0692d Updates
2018-02-12 13:51:32 +02:00

4 lines
25 KiB
JavaScript

/*empire.studio - Design & Strategy*/
/* eslint-disable */
var Ops=Ops||{};Ops.Gl=Ops.Gl||{},Ops.Anim=Ops.Anim||{},Ops.Json3d=Ops.Json3d||{},Ops.Devices=Ops.Devices||{},Ops.Gl.Matrix=Ops.Gl.Matrix||{},Ops.Gl.Meshes=Ops.Gl.Meshes||{},Ops.Gl.Shader=Ops.Gl.Shader||{},Ops.Devices.Mouse=Ops.Devices.Mouse||{},Ops.Gl.MainLoop=function(){function e(){function e(){h&&(h.style.display="block")}function n(){h&&(h.style.display="none")}if(t.patch.cgl.canvas.addEventListener("mouseleave",n),t.patch.cgl.canvas.addEventListener("mouseenter",e),s.get()){if(!h){h=document.createElement("div");var r=t.patch.cgl.canvas.parentElement;r&&r.appendChild(h),h.addEventListener("mouseenter",e),h.addEventListener("click",function(e){CABLES.UI&&!e.shiftKey?gui.cycleRendererSize():c.fullScreen()})}h.style.padding="10px",h.style.position="absolute",h.style.right="5px",h.style.top="5px",h.style.width="20px",h.style.height="20px",h.style.cursor="pointer",h.style["border-radius"]="40px",h.style.background="#444",h.style["z-index"]="9999",h.style.display="none",h.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Capa_1" x="0px" y="0px" viewBox="0 0 490 490" style="width:20px;height:20px;" xml:space="preserve" width="512px" height="512px"><g><path d="M173.792,301.792L21.333,454.251v-80.917c0-5.891-4.776-10.667-10.667-10.667C4.776,362.667,0,367.442,0,373.333V480 c0,5.891,4.776,10.667,10.667,10.667h106.667c5.891,0,10.667-4.776,10.667-10.667s-4.776-10.667-10.667-10.667H36.416 l152.459-152.459c4.093-4.237,3.975-10.99-0.262-15.083C184.479,297.799,177.926,297.799,173.792,301.792z" fill="#FFFFFF"/><path d="M480,0H373.333c-5.891,0-10.667,4.776-10.667,10.667c0,5.891,4.776,10.667,10.667,10.667h80.917L301.792,173.792 c-4.237,4.093-4.354,10.845-0.262,15.083c4.093,4.237,10.845,4.354,15.083,0.262c0.089-0.086,0.176-0.173,0.262-0.262 L469.333,36.416v80.917c0,5.891,4.776,10.667,10.667,10.667s10.667-4.776,10.667-10.667V10.667C490.667,4.776,485.891,0,480,0z" fill="#FFFFFF"/><path d="M36.416,21.333h80.917c5.891,0,10.667-4.776,10.667-10.667C128,4.776,123.224,0,117.333,0H10.667 C4.776,0,0,4.776,0,10.667v106.667C0,123.224,4.776,128,10.667,128c5.891,0,10.667-4.776,10.667-10.667V36.416l152.459,152.459 c4.237,4.093,10.99,3.975,15.083-0.262c3.992-4.134,3.992-10.687,0-14.82L36.416,21.333z" fill="#FFFFFF"/><path d="M480,362.667c-5.891,0-10.667,4.776-10.667,10.667v80.917L316.875,301.792c-4.237-4.093-10.99-3.976-15.083,0.261 c-3.993,4.134-3.993,10.688,0,14.821l152.459,152.459h-80.917c-5.891,0-10.667,4.776-10.667,10.667s4.776,10.667,10.667,10.667 H480c5.891,0,10.667-4.776,10.667-10.667V373.333C490.667,367.442,485.891,362.667,480,362.667z" fill="#FFFFFF"/></g></svg>'}else h&&(h.style.display="none",h.remove(),h=null)}Op.apply(this,arguments);var t=this,n=t.inValue("FPS Limit",0),r=t.outFunction("trigger"),o=t.outValue("width"),a=t.outValue("height"),i=(t.inValueBool("Reduce FPS loading"),t.inValueBool("Clear",!0)),s=t.inValueBool("Fullscreen Button",!1),l=t.inValueBool("Active",!0),d=t.inValueBool("Hires Displays",!1);d.onChange=function(){d.get()?t.patch.cgl.pixelDensity=window.devicePixelRatio:t.patch.cgl.pixelDensity=1,t.patch.cgl.updateSize(),CABLES.UI&&gui.setLayout()};var c=t.patch.cgl,u=0,g=0;t.patch.cgl||t.uiAttr({error:"No webgl cgl context"});var v=vec3.create();vec3.set(v,0,0,0);var P=vec3.create();vec3.set(P,0,0,-2),s.onChange=e,setTimeout(e,100);var h=null;n.onChange=function(){t.patch.config.fpsLimit=n.get()||0},t.onDelete=function(){c.gl.clearColor(0,0,0,0),c.gl.clear(c.gl.COLOR_BUFFER_BIT|c.gl.DEPTH_BUFFER_BIT),t.patch.removeOnAnimFrame(t)},t.patch.loading.setOnFinishedLoading(function(e){t.patch.config.fpsLimit=n.get()}),t.onAnimFrame=function(e){if(l.get()&&!c.aborted&&0!==c.canvas.clientWidth&&0!==c.canvas.clientHeight){if(t.patch.loading.getProgress()<1&&(t.patch.config.fpsLimit=5),-1==c.canvasWidth)return void c.setCanvas(t.patch.config.glCanvasId);(c.canvasWidth!=o.get()||c.canvasHeight!=a.get())&&(o.set(c.canvasWidth),a.set(c.canvasHeight)),CABLES.now()-g>1e3&&(CGL.fpsReport=CGL.fpsReport||[],t.patch.loading.getProgress()>=1&&0!==g&&CGL.fpsReport.push(u),u=0,g=CABLES.now()),CGL.MESH.lastShader=null,CGL.MESH.lastMesh=null,c.renderStart(c,v,P),i.get()&&(c.gl.clearColor(0,0,0,1),c.gl.clear(c.gl.COLOR_BUFFER_BIT|c.gl.DEPTH_BUFFER_BIT)),r.trigger(),CGL.MESH.lastMesh&&CGL.MESH.lastMesh.unBind(),CGL.Texture.previewTexture&&(CGL.Texture.texturePreviewer||(CGL.Texture.texturePreviewer=new CGL.Texture.texturePreview(c)),CGL.Texture.texturePreviewer.render(CGL.Texture.previewTexture)),c.renderEnd(c),c.frameStore.phong||(c.frameStore.phong={}),u++}}},Ops.Gl.MainLoop.prototype=new CABLES.Op,Ops.Gl.Shader.ShaderMaterial=function(){function e(){h=!0,o()}function t(){h&&o(),u.setShader(P),n(),d.trigger(),u.setPreviousShader()}function n(){for(var e=0;e<v.length;e++)u.gl.activeTexture(u.gl.TEXTURE0+e+3),u.gl.bindTexture(u.gl.TEXTURE_2D,v[e].get().tex)}function r(e){var t=0;for(t=0;t<g.length;t++)if(g[t].name==e)return!0;for(t=0;t<v.length;t++)if(v[t].name==e)return!0;return!1}function o(){h=!1,a.log("shader update!"),P.bindTextures=n,P.setSource(l.get(),s.get()),P.compile();var e=u.gl.getProgramParameter(P.getProgram(),u.gl.ACTIVE_UNIFORMS),t=0,o=0;for(t=0;e>t;t++){var i=u.gl.getActiveUniform(P.getProgram(),t);if(!r(i.name))if(5126==i.type){var d=a.inValue(i.name,d,0);d.onChange=function(e){e.uniform.needsUpdate=!0,e.uniform.setValue(e.get())},g.push(d),d.uniform=new CGL.Uniform(P,"f",i.name,d)}else if(35678==i.type){var p=a.inObject(i.name);p.uniform=new CGL.Uniform(P,"t",i.name,3+o),v.push(p),o++}}for(t=0;t<g.length;t++)g[t].uniform.needsUpdate=!0;CABLES.UI&&gui.patch().showOpParams(a),console.log(2),c.set(null),c.set(P)}Op.apply(this,arguments);var a=this;a.name="ShaderMaterial";var i=a.addInPort(new Port(a,"render",OP_PORT_TYPE_FUNCTION)),s=a.addInPort(new Port(a,"fragment",OP_PORT_TYPE_VALUE,{display:"editor",editorSyntax:"glsl"})),l=a.addInPort(new Port(a,"vertex",OP_PORT_TYPE_VALUE,{display:"editor",editorSyntax:"glsl"})),d=a.addOutPort(new Port(a,"trigger",OP_PORT_TYPE_FUNCTION)),c=a.outObject("Shader"),u=a.patch.cgl,g=[],v=[],P=new CGL.Shader(u,"shaderMaterial");P.glslVersion=0,s.set(P.getDefaultFragmentShader()),l.set(P.getDefaultVertexShader()),s.onChange=e,l.onChange=e,i.onTriggered=t;var h=!0;o()},Ops.Gl.Shader.ShaderMaterial.prototype=new CABLES.Op,Ops.Anim.RelativeTime=function(){function e(){o.set(t.patch.freeTimer.get()*r.get())}Op.apply(this,arguments);var t=this;t.name="RelativeTime";var n=t.inFunction("exe"),r=t.inValue("Multiply",1),o=t.outValue("result");n.onTriggered=e,e()},Ops.Anim.RelativeTime.prototype=new CABLES.Op,Ops.Devices.Mouse.Mouse=function(){function e(e,t){if(f.get()){var n=I.canvas.width,r=I.canvas.height;M==document.body&&(n=M.clientWidth,r=M.clientHeight),c.set((e/n*2-1)*w.get()),u.set((t/r*2-1)*w.get())}else c.set(e*w.get()),u.set(t*w.get())}function t(){b=_.get(),0>=b&&(b=.01);var t=Math.abs(A-y),n=Math.round(t/b,0);y=A>y?y+n:y-n;var r=Math.abs(V-U),o=Math.round(r/b,0);U=V>U?U+o:U-o,e(y,U)}function n(e){v.trigger()}function r(e){R=0,F=0,b=100,"Canvas"==T.get()&&E.get()&&(A=I.canvas.width/2,V=I.canvas.height/2),p.set(!1),g.set(!1)}function o(t){p.set(!0),m.get()?(0!=R&&0!=F&&(S=t.offsetX-R,G=t.offsetY-F),R=t.offsetX,F=t.offsetY,A+=S,V+=G,V>460&&(V=460)):("Canvas"==T.get()?(S=t.offsetX,G=t.offsetY):(S=t.clientX,G=t.clientY),E.get()?(A=S,V=C.get()?M.clientHeight-G:G):C.get()?e(S,M.clientHeight-G):e(S,G))}function a(e){g.set(!0),e.touches&&e.touches.length>0&&Y(e.touches[0])}function i(e){g.set(!1),B()}function s(){M.removeEventListener("touchend",i),M.removeEventListener("touchstart",a),M.removeEventListener("click",n),M.removeEventListener("mousemove",o),M.removeEventListener("mouseleave",r),M.removeEventListener("mousedown",Y),M.removeEventListener("mouseup",B),M.removeEventListener("mouseenter",N),M.removeEventListener("contextmenu",D),M=null}function l(){M&&s(),M=I.canvas,"Document"==T.get()&&(M=document.body),M.addEventListener("touchend",i),M.addEventListener("touchstart",a),M.addEventListener("click",n),M.addEventListener("mousemove",o),M.addEventListener("mouseleave",r),M.addEventListener("mousedown",Y),M.addEventListener("mouseup",B),M.addEventListener("mouseenter",N),M.addEventListener("contextmenu",D)}Op.apply(this,arguments);var d=this,c=d.addOutPort(new Port(d,"x",OP_PORT_TYPE_VALUE)),u=d.addOutPort(new Port(d,"y",OP_PORT_TYPE_VALUE)),g=d.addOutPort(new Port(d,"button down",OP_PORT_TYPE_VALUE)),v=d.addOutPort(new Port(d,"click",OP_PORT_TYPE_FUNCTION)),P=d.addOutPort(new Port(d,"Button Up",OP_PORT_TYPE_FUNCTION)),h=d.addOutPort(new Port(d,"click right",OP_PORT_TYPE_FUNCTION)),p=d.addOutPort(new Port(d,"mouseOver",OP_PORT_TYPE_VALUE)),m=d.addInPort(new Port(d,"relative",OP_PORT_TYPE_VALUE,{display:"bool"})),f=d.addInPort(new Port(d,"normalize",OP_PORT_TYPE_VALUE,{display:"bool"})),O=d.inValueBool("Active",!0),E=d.addInPort(new Port(d,"smooth",OP_PORT_TYPE_VALUE,{display:"bool"})),_=d.addInPort(new Port(d,"smoothSpeed",OP_PORT_TYPE_VALUE)),T=d.addInPort(new Port(d,"Area",OP_PORT_TYPE_VALUE,{display:"dropdown",values:["Canvas","Document"]})),L=d.addOutPort(new Port(d,"button",OP_PORT_TYPE_VALUE)),w=d.addInPort(new Port(d,"multiply",OP_PORT_TYPE_VALUE)),C=d.inValueBool("flip y",!0);T.set("Canvas"),w.set(1);var x=0;_.set(20);var I=d.patch.cgl,M=null;E.onValueChanged=function(){E.get()?x=setInterval(t,5):x&&clearTimeout(x)};var y=0,U=0,A=I.canvas.width/2,V=I.canvas.height/2;y=A,U=V,c.set(A),u.set(V);var R=0,F=0,S=0,G=0;l(),T.onValueChanged=l;var b=0,N=function(e){g.set(!1),p.set(!0),b=_.get()},Y=function(e){L.set(e.which),g.set(!0)},B=function(e){L.set(0),g.set(!1),P.trigger()},D=function(e){h.trigger(),e.preventDefault()};m.onChange=function(){S=0,G=0},O.onChange=function(){M&&s(),O.get()&&l()},d.onDelete=function(){s()},l()},Ops.Devices.Mouse.Mouse.prototype=new CABLES.Op,Ops.Gl.Meshes.FullscreenRectangle=function(){function e(){var e=l.getViewPort().slice();if(e[2]!=u||e[3]!=g){var t=0,n=0;u=e[2],g=e[3],c.vertices=new Float32Array([t+u,n+g,0,t,n+g,0,t+u,n,0,t,n,0]),a.get()?c.texCoords=new Float32Array([1,0,0,0,1,1,0,1]):c.texCoords=new Float32Array([1,1,0,1,1,0,0,0]),c.verticesIndices=new Float32Array([0,1,2,3,1,2]),d?d.setGeom(c):d=new CGL.Mesh(l,c)}}Op.apply(this,arguments);var t=this,n={};n.shader_frag="\nuniform sampler2D tex;\nIN vec2 texCoord;\n\nprecision highp float;\n\nvoid main()\n{\n gl_FragColor = texture2D(tex,vec2(texCoord.x,(1.0-texCoord.y)));\n\n}\n//sdsdsd",n.shader_vert="{{MODULES_HEAD}}\n\nIN vec3 vPosition;\nUNI mat4 projMatrix;\nUNI mat4 mvMatrix;\n\nOUT vec2 texCoord;\nIN vec2 attrTexCoord;\n\nvoid main()\n{\n vec4 pos=vec4(vPosition, 1.0);\n\n texCoord=attrTexCoord;\n\n\n gl_Position = projMatrix * mvMatrix * pos;\n}\n";var r=t.addInPort(new Port(t,"render",OP_PORT_TYPE_FUNCTION)),o=t.addInPort(new Port(t,"Center in Canvas",OP_PORT_TYPE_VALUE,{display:"bool"})),a=t.inValueBool("Flip Y"),i=t.inTexture("Texture"),s=t.addOutPort(new Port(t,"trigger",OP_PORT_TYPE_FUNCTION)),l=t.patch.cgl,d=null,c=new CGL.Geometry("fullscreen rectangle"),u=0,g=0;o.onChange=e,a.onChange=e;var v=null;i.onChange=function(){var e=i.get();v=null,e&&(v=new CGL.Shader(l,"MinimalMaterial"),v.setModules(["MODULE_VERTEX_POSITION","MODULE_COLOR","MODULE_BEGIN_FRAG"]),v.setSource(n.shader_vert,n.shader_frag),new CGL.Uniform(v,"t","tex",0))},r.onTriggered=function(){if((l.getViewPort()[2]!=u||l.getViewPort()[3]!=g)&&e(),l.pushPMatrix(),mat4.identity(l.pMatrix),mat4.ortho(l.pMatrix,0,u,g,0,-10,1e3),l.pushMvMatrix(),mat4.identity(l.mvMatrix),l.pushViewMatrix(),mat4.identity(l.vMatrix),o.get()){var t=0,n=0;u<l.canvasWidth&&(t=(l.canvasWidth-u)/2),g<l.canvasHeight&&(n=(l.canvasHeight-g)/2),l.setViewPort(t,n,u,g)}v?(i.get()&&(l.gl.activeTexture(l.gl.TEXTURE0),l.gl.bindTexture(l.gl.TEXTURE_2D,i.get().tex)),d.render(v)):d.render(l.getShader()),l.gl.clear(l.gl.DEPTH_BUFFER_BIT),l.popPMatrix(),l.popMvMatrix(),l.popViewMatrix(),s.trigger()}},Ops.Gl.Meshes.FullscreenRectangle.prototype=new CABLES.Op,Ops.Json3d.Json3dMesh=function(){function e(){return f?void("no"!=m.get()&&("smooth"==m.get()&&f.calculateNormals(),"flat"==m.get()&&(f.unIndex(),f.calculateNormals()),console.log("normals!"))):void console.log("calc normals: no geom!")}function t(){x&&a(),g.get()&&(l.pushMvMatrix(),mat4.multiply(l.mvMatrix,l.mvMatrix,L),E&&E.render(l.getShader()),l.popMvMatrix(),h.trigger())}function n(){x=!0}function r(){if(0!==P.get()){var e=P.get()/w.maxAxis;vec3.set(C,e,e,e)}else vec3.set(C,1,1,1);mat4.identity(L),mat4.scale(L,L,C)}function o(e){if(CABLES.UI){var t='<div class="panel">';O&&(t+="Mesh "+(T+1)+" of "+O.meshes.length+"<br/>",t+="<br/>"),e&&(t+=(e.verticesIndices||[]).length/3+" faces <br/>",t+=(e.vertices||[]).length/3+" vertices <br/>",t+=(e.texCoords||[]).length/2+" texturecoords <br/>",t+=(e.vertexNormals||[]).length/3+" normals <br/>",t+=(e.tangents||[]).length/3+" tangents <br/>",t+=(e.biTangents||[]).length/3+" bitangents <br/>"),t+="</div>",s.uiAttr({info:t})}}function a(){E=null;var t=Math.floor(u.get());if(!O||t!=t||!isNumeric(t)||0>t||t>=O.meshes.length)return void s.uiAttr({warning:"mesh not found - index out of range "});if(T=t,jsonMesh=O.meshes[t],!jsonMesh)return E=null,void s.uiAttr({warning:"mesh not found"});s.uiAttribs.warning="";f=CGL.Geometry.json2geom(jsonMesh),v.get()&&f.center(),w=f.getBounds(),r(),o(f),e(),p.set(f),E=new CGL.Mesh(l,f),x=!1,_[t]=E,console.log("set mesh done"),s.uiAttr({warning:null})}function i(){function e(){CABLES.ajax(s.patch.getFilePath(c.get()),function(e,n,r){if(e)return CABLES.UI&&s.uiAttr({error:"could not load file..."}),console.error("ajax error:",e),void s.patch.loading.finished(t);CABLES.UI&&s.uiAttr({error:null});try{O=JSON.parse(n)}catch(o){return CABLES.UI&&s.uiAttr({error:"could not load file..."}),void s.patch.loading.finished(t)}x=!0,s.patch.loading.finished(t),CABLES.UI&&gui.jobs().finish("loading3d"+t)})}if(c.get()){T=-1;var t=s.patch.loading.start("json3dFile",c.get());CABLES.UI?gui.jobs().start({id:"loading3d"+t,title:"loading 3d data"},e):e()}}Op.apply(this,arguments);var s=this,l=this.patch.cgl;new CABLES.Variable;l.frameStore.currentScene=null;var d=s.inFunction("Render"),c=this.addInPort(new Port(this,"file",OP_PORT_TYPE_VALUE,{display:"file",type:"string",filter:"mesh"})),u=s.inValueInt("Mesh Index",0),g=s.inValueBool("Draw",!0),v=s.inValueBool("Center Mesh",!0),P=s.inValue("Size",1),h=this.addOutPort(new Port(this,"trigger",OP_PORT_TYPE_FUNCTION)),p=s.outObject("Geometry"),m=s.inValueSelect("Calculate Normals",["no","smooth","flat"],"no"),f=null,O=null,E=null,_=[],T=-1,L=mat4.create(),w={},C=vec3.fromValues(1,1,1);d.onTriggered=t,c.onChange=i,v.onChange=n,u.onChange=n,m.onChange=n,P.onChange=r;var x=!0},Ops.Json3d.Json3dMesh.prototype=new CABLES.Op,Ops.Gl.Shader.WireframeMaterial=function(){function e(){g&&(i.get()?g.define("WIREFRAME_FILL"):g.removeDefine("WIREFRAME_FILL"))}Op.apply(this,arguments);var t=this,n=t.patch.cgl,r=t.addInPort(new Port(t,"render",OP_PORT_TYPE_FUNCTION)),o=t.addOutPort(new Port(t,"trigger",OP_PORT_TYPE_FUNCTION)),a=t.addInPort(new Port(t,"enable depth testing",OP_PORT_TYPE_VALUE,{display:"bool"}));a.set(!0);var i=t.addInPort(new Port(t,"fill",OP_PORT_TYPE_VALUE,{display:"bool"}));i.set(!0),i.onChange=function(){e()};var s=t.addInPort(new Port(t,"width",OP_PORT_TYPE_VALUE,{display:"range"}));s.set(.25),s.onValueChanged=function(){v.setValue(s.get())};var l=t.addInPort(new Port(t,"opacity",OP_PORT_TYPE_VALUE,{display:"range"}));if(l.set(1),l.onValueChanged=function(){P.setValue(l.get())},1!=n.glVersion||n.gl.getExtension("OES_standard_derivatives")?t.uiAttr({error:null}):t.uiAttr({error:"no oes standart derivatives!"}),1==n.glVersion)var d="".endl()+"{{MODULES_HEAD}}".endl()+"IN vec3 vPosition;".endl()+"IN vec3 attrBaycentric;".endl()+"UNI mat4 projMatrix;".endl()+"UNI mat4 modelMatrix;".endl()+"UNI mat4 viewMatrix;".endl()+"OUT vec3 baycentric;".endl()+"IN vec2 attrTexCoord;".endl()+"OUT vec2 texCoord;".endl();else var d="".endl()+"{{MODULES_HEAD}}".endl()+"IN vec3 vPosition;".endl()+"IN vec3 attrBaycentric;".endl()+"UNI mat4 projMatrix;".endl()+"UNI mat4 modelMatrix;".endl()+"UNI mat4 viewMatrix;".endl()+"OUT vec3 baycentric;".endl()+"IN vec2 attrTexCoord;".endl()+"OUT vec2 texCoord;".endl();d+="".endl()+"void main()".endl()+"{".endl()+" texCoord=attrTexCoord;".endl()+" baycentric=attrBaycentric;".endl()+" vec4 pos = vec4( vPosition, 1. );".endl()+" {{MODULE_VERTEX_POSITION}}".endl()+" gl_Position = projMatrix * viewMatrix * modelMatrix * pos;".endl()+"}";var c="";c=1==n.glVersion?"".endl()+"IN vec3 baycentric;".endl():"".endl()+"IN vec3 baycentric;".endl(),c+="".endl()+"UNI float width;".endl()+"UNI float opacity;".endl()+"UNI float r,g,b;".endl()+"UNI float fr,fg,fb;".endl()+"".endl()+"float edgeFactor()".endl()+"{".endl()+" vec3 d = fwidth(baycentric);".endl()+" vec3 a3 = smoothstep(vec3(0.0), d*width*4.0, baycentric);".endl()+" return min(min(a3.x, a3.y), a3.z);".endl()+"}".endl()+"void main()".endl()+"{".endl()+" vec4 col;".endl()+" #ifdef WIREFRAME_FILL".endl()+" float v=opacity*(1.0-edgeFactor())*0.95;".endl()+" vec3 wire = vec3(fr, fg, fb);".endl()+" col.rgb = vec3(r, g, b);".endl()+" col.rgb = mix(wire,col.rgb,v);".endl()+" col.a = opacity;".endl()+" #endif".endl()+" #ifndef WIREFRAME_FILL".endl()+" col = vec4(r,g,b, opacity*(1.0-edgeFactor())*0.95);".endl()+" #endif".endl(),c+="outColor=col;",c+="".endl()+"}";var u=function(){!0!==a.get()?n.gl.disable(n.gl.DEPTH_TEST):n.gl.enable(n.gl.DEPTH_TEST),n.setShader(g),o.trigger(),n.setPreviousShader(),!0!==a.get()&&n.gl.enable(n.gl.DEPTH_TEST)},g=new CGL.Shader(n,"Wireframe Material");n.glVersion>1&&(g.glslVersion=300);var v=new CGL.Uniform(g,"f","width",s.get()),P=new CGL.Uniform(g,"f","opacity",l.get());1==n.glVersion&&g.enableExtension("OES_standard_derivatives"),g.setSource(d,c),g.setModules(["MODULE_VERTEX_POSITION","MODULE_COLOR","MODULE_BEGIN_FRAG"]),g.wireframe=!0,e();var h=t.addInPort(new Port(t,"diffuse r",OP_PORT_TYPE_VALUE,{display:"range",colorPick:"true"}));h.onValueChanged=function(){h.uniform?h.uniform.setValue(h.get()):h.uniform=new CGL.Uniform(g,"f","r",h.get())};var p=t.addInPort(new Port(t,"diffuse g",OP_PORT_TYPE_VALUE,{display:"range"}));p.onValueChanged=function(){p.uniform?p.uniform.setValue(p.get()):p.uniform=new CGL.Uniform(g,"f","g",p.get())};var m=t.addInPort(new Port(t,"diffuse b",OP_PORT_TYPE_VALUE,{display:"range"}));m.onValueChanged=function(){m.uniform?m.uniform.setValue(m.get()):m.uniform=new CGL.Uniform(g,"f","b",m.get())},h.set(Math.random()),p.set(Math.random()),m.set(Math.random());var f=t.addInPort(new Port(t,"Fill R",OP_PORT_TYPE_VALUE,{display:"range",colorPick:"true"}));f.uniform=new CGL.Uniform(g,"f","fr",f);var O=t.addInPort(new Port(t,"Fill G",OP_PORT_TYPE_VALUE,{display:"range"}));O.uniform=new CGL.Uniform(g,"f","fg",O);var E=t.addInPort(new Port(t,"Fill B",OP_PORT_TYPE_VALUE,{display:"range"}));E.uniform=new CGL.Uniform(g,"f","fb",E),f.set(0),O.set(0),E.set(0),r.onTriggered=u,u()},Ops.Gl.Shader.WireframeMaterial.prototype=new CABLES.Op,Ops.Gl.Matrix.OrbitControls=function(){function e(){q%=2*Math.PI,J%=2*Math.PI,k=p.get()*Math.PI*2,H=h.get()-.5,Y=m.get(),R=r(H)}function t(){Z=10*O.get()+1}function n(e,t){return e+(t-e)/Z}function r(e){Y<v.get()*f.get()&&(Y=v.get()*f.get()),Y>P.get()*f.get()&&(Y=P.get()*f.get()),y.set(Y*f.get());var t=0,n=vec3.create();return t=360*e/2*CGL.DEG2RAD,vec3.set(n,Math.cos(t)*Y*f.get(),Math.sin(t)*Y*f.get(),0),n}function o(e){if(N){var t=e.clientX,n=e.clientY,o=(t-B)*x.get(),a=(n-D)*I.get();Q&&(o=e.movementX*f.get(),a=e.movementY*f.get()),3==e.which&&L.get()?(b[2]+=.01*o*f.get(),b[1]+=.01*a*f.get()):2==e.which&&w.get()?(Y+=.05*a,R=r(H)):(k+=.003*o,H+=.002*a,E.get()&&(H>.5&&(H=.5),-.5>H&&(H=-.5))),B=t,D=n}}function a(e){if(B=e.clientX,D=e.clientY,N=!0,Q){var t=u.patch.cgl.canvas;t.requestPointerLock=t.requestPointerLock||t.mozRequestPointerLock||t.webkitRequestPointerLock,t.requestPointerLock?t.requestPointerLock():console.log("no t found"),document.addEventListener("pointerlockchange",s,!1),document.addEventListener("mozpointerlockchange",s,!1),document.addEventListener("webkitpointerlockchange",s,!1)}}function i(){N=!1,Q&&(document.removeEventListener("pointerlockchange",s,!1),document.removeEventListener("mozpointerlockchange",s,!1),document.removeEventListener("webkitpointerlockchange",s,!1),document.exitPointerLock&&document.exitPointerLock(),document.removeEventListener("mousemove",o,!1))}function s(){var e=u.patch.cgl.canvas;(document.pointerLockElement===e||document.mozPointerLockElement===e||document.webkitPointerLockElement===e)&&(document.addEventListener("mousemove",o,!1),console.log("listening..."))}function l(e){}function d(){K.addEventListener("mousemove",o),K.addEventListener("mousedown",a),K.addEventListener("mouseup",i),K.addEventListener("mouseleave",i),K.addEventListener("mouseenter",l),K.addEventListener("contextmenu",function(e){e.preventDefault()}),K.addEventListener("wheel",$),K.addEventListener("touchmove",ne),K.addEventListener("touchstart",ee),K.addEventListener("touchend",te)}function c(){K&&(K.removeEventListener("mousemove",o),K.removeEventListener("mousedown",a),K.removeEventListener("mouseup",i),K.removeEventListener("mouseleave",i),K.removeEventListener("mouseenter",i),K.removeEventListener("wheel",$),K.removeEventListener("touchmove",ne),K.removeEventListener("touchstart",ee),K.removeEventListener("touchend",te))}Op.apply(this,arguments);var u=this,g=u.addInPort(new Port(u,"render",OP_PORT_TYPE_FUNCTION)),v=u.addInPort(new Port(u,"min distance",OP_PORT_TYPE_VALUE)),P=u.addInPort(new Port(u,"max distance",OP_PORT_TYPE_VALUE)),h=u.addInPort(new Port(u,"initial axis y",OP_PORT_TYPE_VALUE,{display:"range"})),p=u.addInPort(new Port(u,"initial axis x",OP_PORT_TYPE_VALUE,{display:"range"})),m=u.inValue("initial radius",5),f=u.addInPort(new Port(u,"mul",OP_PORT_TYPE_VALUE)),O=u.inValueSlider("Smoothness",1),E=u.addInPort(new Port(u,"restricted",OP_PORT_TYPE_VALUE,{display:"bool"})),_=u.inValueBool("Active",!0),T=u.inFunctionButton("Reset"),L=u.inValueBool("Allow Panning",!0),w=u.inValueBool("Allow Zooming",!0),C=u.inValueBool("Pointerlock",!1),x=u.inValue("Speed X",1),I=u.inValue("Speed Y",1),M=u.addOutPort(new Port(u,"trigger",OP_PORT_TYPE_FUNCTION)),y=u.addOutPort(new Port(u,"radius",OP_PORT_TYPE_VALUE)),U=u.addOutPort(new Port(u,"Rot Y",OP_PORT_TYPE_VALUE)),A=u.addOutPort(new Port(u,"Rot X",OP_PORT_TYPE_VALUE));E.set(!0),f.set(1),v.set(.05),P.set(99999),h.set(.5),p.set(0),T.onTriggered=e;var V=u.patch.cgl,R=vec3.create(),F=vec3.create(),S=vec3.create(),G=mat4.create(),b=vec3.create(),N=!1,Y=5;y.set(Y);var B=0,D=0,k=0,H=0;vec3.set(S,0,0,0),vec3.set(F,0,1,0);var X=vec3.create(),j=vec3.create(),z=vec3.create(),W=vec3.create(),q=0,J=0,Z=1,K=null;t(),u.onDelete=c;var Q=!1;C.onChange=function(){Q=C.get(),console.log("doLockPointer",Q)},O.onChange=t,g.onTriggered=function(){V.pushViewMatrix(),q=n(q,k),J=n(J,H),U.set(180*(J+.5)),A.set(180*q),R=r(J),vec3.add(X,R,b),vec3.add(z,S,b),j[0]=n(j[0],X[0]),j[1]=n(j[1],X[1]),j[2]=n(j[2],X[2]),W[0]=n(W[0],z[0]),W[1]=n(W[1],z[1]),W[2]=n(W[2],z[2]),mat4.lookAt(G,j,W,F),mat4.rotate(G,G,q,F),mat4.multiply(V.vMatrix,V.vMatrix,G),M.trigger(),V.popViewMatrix()},m.onValueChange(function(){Y=m.get()}),p.onValueChange(function(){k=p.get()*Math.PI*2}),h.onValueChange(function(){H=h.get()-.5,R=r(H)});var $=function(e){if(w.get()){var t=.06*CGL.getWheelSpeed(e);Y+=1.2*parseFloat(t),R=r(H),e.preventDefault()}},ee=function(e){Q=!1,e.touches&&e.touches.length>0&&a(e.touches[0])},te=function(e){Q=!1,i()},ne=function(e){Q=!1,e.touches&&e.touches.length>0&&o(e.touches[0])};_.onChange=function(){_.get()?d():c()},this.setElement=function(e){c(),K=e,d()},R=r(0),this.setElement(V.canvas),d()},Ops.Gl.Matrix.OrbitControls.prototype=new CABLES.Op,Ops.Anim.SineAnim=function(){function e(){r.set(i.get()*Math.sin(t.patch.freeTimer.get()*a.get()+o.get()))}Op.apply(this,arguments);var t=this,n=t.addInPort(new Port(t,"exe",OP_PORT_TYPE_FUNCTION)),r=t.addOutPort(new Port(t,"result")),o=t.addInPort(new Port(t,"phase",OP_PORT_TYPE_VALUE)),a=t.addInPort(new Port(t,"frequency",OP_PORT_TYPE_VALUE)),i=t.addInPort(new Port(t,"amplitude",OP_PORT_TYPE_VALUE));a.set(1),i.set(1),o.set(1),n.onTriggered=e,e()},Ops.Anim.SineAnim.prototype=new CABLES.Op,Ops.Gl.Matrix.Transform=function(){function e(){m=!1,(0!==a.get()||0!==i.get()||0!==s.get())&&(m=!0),vec3.set(v,a.get(),i.get(),s.get()),f=!1}function t(){p=!1,0!==l.get()&&(p=!0),vec3.set(P,l.get(),l.get(),l.get()),O=!1}Op.apply(this,arguments);var n=this,r=n.addInPort(new Port(n,"render",OP_PORT_TYPE_FUNCTION)),o=n.addOutPort(new Port(n,"trigger",OP_PORT_TYPE_FUNCTION)),a=n.addInPort(new Port(n,"posX"),0),i=n.addInPort(new Port(n,"posY"),0),s=n.addInPort(new Port(n,"posZ"),0),l=n.addInPort(new Port(n,"scale")),d=n.addInPort(new Port(n,"rotX")),c=n.addInPort(new Port(n,"rotY")),u=n.addInPort(new Port(n,"rotZ")),g=n.patch.cgl,v=vec3.create(),P=vec3.create(),h=mat4.create();mat4.identity(h);var p=!1,m=!1,f=!0,O=!0,E=!0;l.setUiAttribs({divider:!0}),r.onTriggered=function(){var r=!1;f&&(e(),r=!0),O&&(t(),r=!0),E&&(r=!0),r&&_(),g.pushMvMatrix(),mat4.multiply(g.mvMatrix,g.mvMatrix,h),o.trigger(),g.popMvMatrix(),CABLES.UI&&gui.patch().isCurrentOp(n)&&gui.setTransformGizmo({posX:a,posY:i,posZ:s})},n.transform3d=function(){return{pos:[a,i,s]}};var _=function(){mat4.identity(h),m&&mat4.translate(h,h,v),0!==d.get()&&mat4.rotateX(h,h,d.get()*CGL.DEG2RAD),0!==c.get()&&mat4.rotateY(h,h,c.get()*CGL.DEG2RAD),0!==u.get()&&mat4.rotateZ(h,h,u.get()*CGL.DEG2RAD),p&&mat4.scale(h,h,P),E=!1},T=function(){f=!0},O=function(){O=!0},E=function(){E=!0};d.onChange=E,c.onChange=E,u.onChange=E,l.onChange=O,a.onChange=T,i.onChange=T,s.onChange=T,d.set(0),c.set(0),u.set(0),l.set(1),a.set(0),i.set(0),s.set(0),_()},Ops.Gl.Matrix.Transform.prototype=new CABLES.Op;