mirror of
https://github.com/status-im/artproject.git
synced 2025-02-22 20:58:14 +00:00
10 lines
141 KiB
JavaScript
10 lines
141 KiB
JavaScript
/*empire.studio - Design & Strategy*/
|
|
function arrayWriteToEnd(t,e){for(var i=1;i<t.length;i++)t[i-1]=t[i];t[t.length-1]=e}function isNumeric(t){return!isNaN(parseFloat(t))&&isFinite(t)}function ajaxRequest(t,e){var i=new XMLHttpRequest;i.open("GET",t,!0),i.responseType="arraybuffer",i.onload=function(t){e(t.target.response)},i.send()}function float32Concat(t,e){t instanceof Float32Array||(t=new Float32Array(t)),e instanceof Float32Array||(e=new Float32Array(e));var i=t.length,r=new Float32Array(i+e.length);return r.set(t),r.set(e,i),r}var CABLES=CABLES||{};CABLES.generateUUID=function(){var t=(new Date).getTime(),e="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var i=(t+16*Math.random())%16|0;return t=Math.floor(t/16),("x"==e?i:3&i|8).toString(16)});return e},CABLES.smoothStep=function(t){var e=Math.max(0,Math.min(1,(t-0)/1));return t=e*e*(3-2*e)},CABLES.smootherStep=function(t){var e=Math.max(0,Math.min(1,(t-0)/1));return t=e*e*e*(e*(6*e-15)+10)},CABLES.map=function(t,e,i,r,s,n){if(t>=i)return s;if(e>=t)return r;var o=!1,a=Math.min(e,i),h=Math.max(e,i);a!=e&&(o=!0);var l=!1,u=Math.min(r,s),c=Math.max(r,s);u!=r&&(l=!0);var g=0,p=0;return g=o?(h-t)*(c-u)/(h-a):(t-a)*(c-u)/(h-a),p=l?c-g:g+u,n?1==n?(t=Math.max(0,Math.min(1,(p-r)/(s-r))),r+t*t*(3-2*t)*(s-r)):2==n?(t=Math.max(0,Math.min(1,(p-r)/(s-r))),r+t*t*t*(t*(6*t-15)+10)*(s-r)):p:p},Math.randomSeed=1,Math.seededRandom=function(t,e){0===Math.randomSeed&&(Math.randomSeed=999*Math.random()),t=t||1,e=e||0,Math.randomSeed=(9301*Math.randomSeed+49297)%233280;var i=Math.randomSeed/233280;return e+i*(t-e)},String.prototype.startsWith=function(t){return 0===this.indexOf(t)},String.prototype.endsWith=function(t){return this.match(t+"$")==t},CABLES.jsonp=function(t,e){CABLES.jsonpCounter=CABLES.jsonpCounter||0,CABLES.jsonpCounter++;var i=CABLES.jsonpCounter;console.log("making jsonp request..."),CABLES["jsonpFunc"+i]=function(t){console.log(t),e(!1,t)};var r="?";t.indexOf(r)>-1&&(r="&");var s=document.createElement("script");s.setAttribute("src",t+r+"callback=CABLES.jsonpFunc"+i),document.body.appendChild(s)},CABLES.ajaxSync=function(t,e,i,r,s){CABLES.ajaxIntern(t,e,i,r,s,!1)},CABLES.ajax=function(t,e,i,r,s,n){CABLES.ajaxIntern(t,e,i,r,s,!0,n)},CABLES.ajaxIntern=function(t,e,i,r,s,n){var o;try{o=new XMLHttpRequest}catch(a){}o.onreadystatechange=function(){4==o.readyState&&e(!1,o.responseText,o)},o.addEventListener("progress",function(t){}),o.open(i?i.toUpperCase():"GET",t,n),r?(o.setRequestHeader("Content-type",s?s:"application/x-www-form-urlencoded"),o.send(r)):o.send()},String.prototype.endl=function(){return this+"\n"};var arrayContains=function(t,e){for(var i=t.length;i--;)if(t[i]===e)return!0;return!1};CGL=CGL||{},CGL.DEG2RAD=Math.PI/180,CGL.RAD2DEG=180/Math.PI,CGL.onLoadingAssetsFinished=null,CGL.isWindows=-1!=window.navigator.userAgent.indexOf("Windows"),CGL.getWheelSpeed=function(t){var e;if(t.wheelDelta)e=t.wheelDelta%120-0==-0?t.wheelDelta/120:t.wheelDelta/30,e*=-1.5,CGL.isWindows&&(e*=2);else{var i=t.deltaY?t.deltaY:t.detail;e=-(i%3?10*i:i/3),e*=-3}return e>20&&(e=20),-20>e&&(e=-20),e},CABLES.Browser=function(t){function e(t){i=!0,console.log("browser report canceled...")}var i=!1,r="hidden";r in document?document.addEventListener("visibilitychange",e):(r="mozHidden")in document?document.addEventListener("mozvisibilitychange",e):(r="webkitHidden")in document?document.addEventListener("webkitvisibilitychange",e):(r="msHidden")in document?document.addEventListener("msvisibilitychange",e):"onfocusin"in document?document.onfocusin=document.onfocusout=e:window.onpageshow=window.onpagehide=window.onfocus=window.onblur=e;var s={nVer:navigator.appVersion,nAgt:navigator.userAgent,browserName:navigator.appName,fullVersion:parseFloat(navigator.appVersion),majorVersion:parseInt(navigator.appVersion,10),lang:navigator.language,platform:navigator.platform,sizeScreen:[window.screen.availHeight,window.screen.availWidth],sizeWindow:[window.screen.height,window.screen.width]};this.sendReport=function(e){if(!i){if(!t)return void console.log("report canceled - no projectid");s.gl={renderer:"unknown",sizeCanvas:[e.cgl.canvas.width,e.cgl.canvas.height]};var r=e.cgl.gl.getExtension("WEBGL_debug_renderer_info");r&&(s.gl.renderer=e.cgl.gl.getParameter(r.UNMASKED_RENDERER_WEBGL),s.gl.vendor=e.cgl.gl.getParameter(r.UNMASKED_VENDOR_WEBGL));var n=e.cgl.gl.getSupportedExtensions();n&&(s.gl.extensions=n),CGL.fpsReport&&CGL.fpsReport.length>1&&(CGL.fpsReport.splice(0,1),s.gl.fps=CGL.fpsReport,CABLES.api.post("report/"+t,{report:s}))}}};var CGL=CGL||{};CGL.Framebuffer=function(t,e,i,r){var s=t,n=s.gl.getExtension("WEBGL_depth_texture")||s.gl.getExtension("WEBKIT_WEBGL_depth_texture")||s.gl.getExtension("MOZ_WEBGL_depth_texture")||s.gl.DEPTH_TEXTURE;n||console.error("no depth texture support");var o=e||512,a=i||512;r=r||{isFloatingPointTexture:!1};var h=new CGL.Texture(s,{isFloatingPointTexture:r.isFloatingPointTexture,filter:CGL.Texture.FILTER_LINEAR,wrap:CGL.Texture.CLAMP_TO_EDGE}),l=null;n&&(l=new CGL.Texture(s,{isDepthTexture:!0}));var u=s.gl.createFramebuffer(),c=s.gl.createRenderbuffer();this.getWidth=function(){return o},this.getHeight=function(){return a},this.getTextureColor=function(){return h},this.getTextureDepth=function(){return l},this.setFilter=function(t){h.filter=t,h.setSize(o,a)},this.setSize=function(t,e){if(2>t&&(t=2),2>e&&(e=2),o=t,a=e,CGL.profileFrameBuffercreate++,s.gl.bindFramebuffer(s.gl.FRAMEBUFFER,u),s.gl.bindRenderbuffer(s.gl.RENDERBUFFER,c),h.setSize(o,a),l&&l.setSize(o,a),n&&s.gl.renderbufferStorage(s.gl.RENDERBUFFER,s.gl.DEPTH_COMPONENT16,o,a),s.gl.framebufferTexture2D(s.gl.FRAMEBUFFER,s.gl.COLOR_ATTACHMENT0,s.gl.TEXTURE_2D,h.tex,0),n&&(s.gl.framebufferRenderbuffer(s.gl.FRAMEBUFFER,s.gl.DEPTH_ATTACHMENT,s.gl.RENDERBUFFER,c),s.gl.framebufferTexture2D(s.gl.FRAMEBUFFER,s.gl.DEPTH_ATTACHMENT16,s.gl.TEXTURE_2D,l.tex,0)),!s.gl.isFramebuffer(u))throw"Invalid framebuffer";var i=s.gl.checkFramebufferStatus(s.gl.FRAMEBUFFER);switch(i){case s.gl.FRAMEBUFFER_COMPLETE:break;case s.gl.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw console.log("FRAMEBUFFER_INCOMPLETE_ATTACHMENT...",o,a,h.tex,c),new Error("Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_ATTACHMENT");case s.gl.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw console.log("FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT"),new Error("Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT");case s.gl.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw console.log("FRAMEBUFFER_INCOMPLETE_DIMENSIONS"),new Error("Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_DIMENSIONS");case s.gl.FRAMEBUFFER_UNSUPPORTED:throw console.log("FRAMEBUFFER_UNSUPPORTED"),new Error("Incomplete framebuffer: FRAMEBUFFER_UNSUPPORTED");default:throw console.log("incomplete framebuffer",i),new Error("Incomplete framebuffer: "+i)}s.gl.bindTexture(s.gl.TEXTURE_2D,null),s.gl.bindRenderbuffer(s.gl.RENDERBUFFER,null),s.gl.bindFramebuffer(s.gl.FRAMEBUFFER,null)},this.renderStart=function(){s.pushMvMatrix(),s.gl.bindFramebuffer(s.gl.FRAMEBUFFER,u),s.pushFrameBuffer(u),s.pushPMatrix(),s.gl.viewport(0,0,o,a),s.gl.clearColor(0,0,0,0),s.gl.clear(s.gl.COLOR_BUFFER_BIT|s.gl.DEPTH_BUFFER_BIT)},this.renderEnd=function(){s.popPMatrix(),s.gl.bindFramebuffer(s.gl.FRAMEBUFFER,s.popFrameBuffer()),s.popMvMatrix(),s.resetViewPort()},this["delete"]=function(){h["delete"](),l&&l["delete"](),s.gl.deleteRenderbuffer(c),s.gl.deleteFramebuffer(u)},this.setSize(o,a)};var CGL=CGL||{};CGL.Framebuffer2=function(t,e,i,r){this._cgl=t,this._width=0,this._height=0,this._colorRenderbuffer=null,this._depthRenderbuffer=null,this._frameBuffer=null,this._colorBuffer=null,this._options=r||{isFloatingPointTexture:!1},this._options.hasOwnProperty("depth")||(this._options.depth=!0),this._options.hasOwnProperty("multisampling")||(this._options.multisampling=!0,this._options.multisamplingSamples=2),this._texture=new CGL.Texture(t,{isFloatingPointTexture:this._options.isFloatingPointTexture,filter:CGL.Texture.FILTER_LINEAR});var s=CGL.Texture.FILTER_NEAREST;this._options.shadowMap&&(s=CGL.Texture.FILTER_LINEAR),this._textureDepth=new CGL.Texture(t,{isDepthTexture:!0,filter:s,shadowMap:this._options.shadowMap||!1}),this.setSize(e||512,i||512)},CGL.Framebuffer2.prototype.getWidth=function(){return this._width},CGL.Framebuffer2.prototype.getHeight=function(){return this._height},CGL.Framebuffer2.prototype.getTextureColor=function(){return this._texture},CGL.Framebuffer2.prototype.getTextureDepth=function(){return this._textureDepth},CGL.Framebuffer2.prototype.setFilter=function(t){this._texture.filter=t,this._texture.setSize(this._width,this._height)},CGL.Framebuffer2.prototype["delete"]=function(){this._texture["delete"](),this._textureDepth["delete"](),this._cgl.gl.deleteRenderbuffer(this._colorRenderbuffer),this._cgl.gl.deleteRenderbuffer(this._depthRenderbuffer),this._cgl.gl.deleteFramebuffer(this._frameBuffer),this._cgl.gl.deleteFramebuffer(this._colorBuffer)},CGL.Framebuffer2.prototype.setSize=function(t,e){this._width=Math.floor(t),this._height=Math.floor(e),CGL.profileFrameBuffercreate++,this._frameBuffer&&(this._cgl.gl.deleteRenderbuffer(this._colorRenderbuffer),this._cgl.gl.deleteRenderbuffer(this._depthRenderbuffer),this._cgl.gl.deleteFramebuffer(this._frameBuffer),this._cgl.gl.deleteFramebuffer(this._colorBuffer)),this._frameBuffer=this._cgl.gl.createFramebuffer(),this._colorBuffer=this._cgl.gl.createFramebuffer();var i=this._options.depth;i&&this._texture.setSize(this._width,this._height),i&&this._textureDepth.setSize(this._width,this._height),this._colorRenderbuffer=this._cgl.gl.createRenderbuffer(),i&&(this._depthRenderbuffer=this._cgl.gl.createRenderbuffer());this._cgl.gl.getExtension("EXT_color_buffer_float");if(this._cgl.gl.bindFramebuffer(this._cgl.gl.FRAMEBUFFER,this._frameBuffer),this._cgl.gl.bindRenderbuffer(this._cgl.gl.RENDERBUFFER,this._colorRenderbuffer),this._options.isFloatingPointTexture?this._options.multisampling?this._cgl.gl.renderbufferStorageMultisample(this._cgl.gl.RENDERBUFFER,this._options.multisamplingSamples,this._cgl.gl.RGBA32F,this._width,this._height):this._cgl.gl.renderbufferStorage(this._cgl.gl.RENDERBUFFER,this._cgl.gl.RGBA32F,this._width,this._height):this._options.multisampling?this._cgl.gl.renderbufferStorageMultisample(this._cgl.gl.RENDERBUFFER,this._options.multisamplingSamples,this._cgl.gl.RGBA8,this._width,this._height):this._cgl.gl.renderbufferStorage(this._cgl.gl.RENDERBUFFER,this._cgl.gl.RGBA8,this._width,this._height),this._cgl.gl.framebufferRenderbuffer(this._cgl.gl.FRAMEBUFFER,this._cgl.gl.COLOR_ATTACHMENT0,this._cgl.gl.RENDERBUFFER,this._colorRenderbuffer),i&&(this._cgl.gl.bindRenderbuffer(this._cgl.gl.RENDERBUFFER,this._depthRenderbuffer),this._options.isFloatingPointTexture?this._options.multisampling?this._cgl.gl.renderbufferStorageMultisample(this._cgl.gl.RENDERBUFFER,this._options.multisamplingSamples,this._cgl.gl.DEPTH_COMPONENT32F,this._width,this._height):this._cgl.gl.renderbufferStorage(this._cgl.gl.RENDERBUFFER,this._cgl.gl.DEPTH_COMPONENT32F,this._width,this._height):this._options.multisampling?this._cgl.gl.renderbufferStorageMultisample(this._cgl.gl.RENDERBUFFER,this._options.multisamplingSamples,this._cgl.gl.DEPTH_COMPONENT32F,this._width,this._height):this._cgl.gl.renderbufferStorage(this._cgl.gl.RENDERBUFFER,this._cgl.gl.DEPTH_COMPONENT32F,this._width,this._height),this._cgl.gl.framebufferRenderbuffer(this._cgl.gl.FRAMEBUFFER,this._cgl.gl.DEPTH_ATTACHMENT,this._cgl.gl.RENDERBUFFER,this._depthRenderbuffer)),this._cgl.gl.bindFramebuffer(this._cgl.gl.FRAMEBUFFER,null),this._cgl.gl.bindFramebuffer(this._cgl.gl.FRAMEBUFFER,this._colorBuffer),this._cgl.gl.framebufferTexture2D(this._cgl.gl.FRAMEBUFFER,this._cgl.gl.COLOR_ATTACHMENT0,this._cgl.gl.TEXTURE_2D,this._texture.tex,0),i&&this._cgl.gl.framebufferTexture2D(this._cgl.gl.FRAMEBUFFER,this._cgl.gl.DEPTH_ATTACHMENT,this._cgl.gl.TEXTURE_2D,this._textureDepth.tex,0),!this._cgl.gl.isFramebuffer(this._colorBuffer))throw"Invalid framebuffer";var r=this._cgl.gl.checkFramebufferStatus(this._cgl.gl.FRAMEBUFFER);switch(r){case this._cgl.gl.FRAMEBUFFER_COMPLETE:break;case this._cgl.gl.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw console.log("FRAMEBUFFER_INCOMPLETE_ATTACHMENT..."),new Error("Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_ATTACHMENT");case this._cgl.gl.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw console.log("FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT"),new Error("Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT");case this._cgl.gl.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw console.log("FRAMEBUFFER_INCOMPLETE_DIMENSIONS"),new Error("Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_DIMENSIONS");case this._cgl.gl.FRAMEBUFFER_UNSUPPORTED:throw console.log("FRAMEBUFFER_UNSUPPORTED"),new Error("Incomplete framebuffer: FRAMEBUFFER_UNSUPPORTED");default:throw console.log("incomplete framebuffer",r),new Error("Incomplete framebuffer: "+r)}this._cgl.gl.bindFramebuffer(this._cgl.gl.FRAMEBUFFER,null),this._cgl.gl.bindRenderbuffer(this._cgl.gl.RENDERBUFFER,null)},CGL.Framebuffer2.prototype.renderStart=function(){this._cgl.pushMvMatrix(),this._cgl.gl.bindFramebuffer(this._cgl.gl.FRAMEBUFFER,this._frameBuffer),this._cgl.pushFrameBuffer(this._frameBuffer),this._cgl.pushPMatrix(),this._cgl.gl.viewport(0,0,this._width,this._height),this._cgl.gl.clearColor(0,0,0,0),this._cgl.gl.clear(this._cgl.gl.COLOR_BUFFER_BIT|this._cgl.gl.DEPTH_BUFFER_BIT)},CGL.Framebuffer2.prototype.renderEnd=function(){this._cgl.popPMatrix(),this._cgl.gl.bindFramebuffer(this._cgl.gl.READ_FRAMEBUFFER,this._frameBuffer),this._cgl.gl.bindFramebuffer(this._cgl.gl.DRAW_FRAMEBUFFER,this._colorBuffer),this._cgl.gl.clearBufferfv(this._cgl.gl.COLOR,0,[0,0,0,1]),this._cgl.gl.blitFramebuffer(0,0,this._width,this._height,0,0,this._width,this._height,this._cgl.gl.COLOR_BUFFER_BIT|this._cgl.gl.DEPTH_BUFFER_BIT,this._cgl.gl.NEAREST),this._cgl.gl.bindFramebuffer(this._cgl.gl.FRAMEBUFFER,this._cgl.popFrameBuffer()),this._cgl.popMvMatrix(),this._cgl.resetViewPort()},CGL.Geometry=function(t){this.name=t,this.faceVertCount=3,this._vertices=[],this.verticesIndices=[],this.texCoords=new Float32Array,this.texCoordsIndices=[],this.vertexNormals=[],this.baycentrics=[],this.morphTargets=[],this.vertexColors=[],this._indexed=!0,Object.defineProperty(this,"vertices",{get:function(){return this._vertices},set:function(t){this.setVertices(t)}})},CGL.Geometry.prototype.clear=function(){this._indexed=!0,this.vertices=new Float32Array([]),this.verticesIndices.length=0,this.texCoords=new Float32Array([]),this.texCoordsIndices.length=0,this.vertexNormals.length=0},CGL.Geometry.prototype.setVertices=function(t){this._vertices=t instanceof Float32Array?t:new Float32Array(t)},CGL.Geometry.prototype.setTexCoords=function(t){this.texCoords=t instanceof Float32Array?t:new Float32Array(t)},CGL.Geometry.prototype.testIndices=function(){for(var t=!1,e=0;e<this.verticesIndices.length;e++)(this.verticesIndices[3*e+0]>=this._vertices.length/3||this.verticesIndices[3*e+1]>=this._vertices.length/3||this.verticesIndices[3*e+2]>=this._vertices.length/3)&&(t=!0,console.log("index error!"))},CGL.Geometry.prototype.calcNormals=function(t){var e={};t||this.unIndex(),this.calculateNormals(e)},CGL.Geometry.prototype.setPointVertices=function(t){if(t.length%3!==0)return void console.error("CGL MESH : SetPointVertices: Array must be multiple of three.");for(this.vertices=t instanceof Float32Array?t:new Float32Array(t),this.texCoords instanceof Float32Array||(this.texCoords=new Float32Array(t.length/3*2)),this.verticesIndices.length=t.length/3,i=0;i<t.length/3;i++)this.verticesIndices[i]=i,this.texCoords[2*i]=0,this.texCoords[2*i+1]=0},CGL.Geometry.prototype.merge=function(t){if(t){var e=this.verticesIndices.length,i=this.vertices.length/3;this.verticesIndices.length=this.verticesIndices.length+t.verticesIndices.length;for(var r=0;r<t.verticesIndices.length;r++)this.verticesIndices[e+r]=t.verticesIndices[r]+i;this.vertices=float32Concat(this.vertices,t.vertices),this.texCoords=float32Concat(this.texCoords,t.texCoords),this.vertexNormals=float32Concat(this.vertexNormals,t.vertexNormals)}},CGL.Geometry.prototype.copy=function(){var t=0,e=new CGL.Geometry;for(e.faceVertCount=this.faceVertCount,e.setVertices(this._vertices.slice(0)),e.verticesIndices.length=this.verticesIndices.length,t=0;t<this.verticesIndices.length;t++)e.verticesIndices[t]=this.verticesIndices[t];for(e.texCoords=new Float32Array(this.texCoords.length),t=0;t<this.texCoords.length;t++)e.texCoords[t]=this.texCoords[t];for(e.texCoordsIndices.length=this.texCoordsIndices.length,t=0;t<this.texCoordsIndices.length;t++)e.texCoordsIndices[t]=this.texCoordsIndices[t];for(e.vertexNormals.length=this.vertexNormals.length,t=0;t<this.vertexNormals.length;t++)e.vertexNormals[t]=this.vertexNormals[t];for(e.baycentrics.length=this.baycentrics.length,t=0;t<this.baycentrics.length;t++)e.baycentrics[t]=this.baycentrics[t];for(e.morphTargets.length=this.morphTargets.length,t=0;t<this.morphTargets.length;t++)e.morphTargets[t]=this.morphTargets[t];for(e.vertexColors.length=this.vertexColors.length,t=0;t<this.vertexColors.length;t++)e.vertexColors[t]=this.vertexColors[t];return e},CGL.Geometry.prototype.calculateNormals=function(t){function e(e){return vec3.subtract(i,e[0],e[1]),vec3.subtract(r,e[0],e[2]),vec3.cross(s,i,r),vec3.normalize(s,s),t&&t.forceZUp&&s[2]<0&&(s[0]*=-1,s[1]*=-1,s[2]*=-1),s}var i=vec3.create(),r=vec3.create(),s=vec3.create();this.getVertexVec=function(t){var e=[0,0,0];return e[0]=this.vertices[3*t+0],e[1]=this.vertices[3*t+1],e[2]=this.vertices[3*t+2],e};var n=0;for(this.vertexNormals instanceof Float32Array&&this.vertexNormals.length==this.vertices.length||(this.vertexNormals=new Float32Array(this.vertices.length)),n=0;n<this.vertices.length;n++)this.vertexNormals[n]=0;var o=[];for(o.length=this.verticesIndices.length/3,n=0;n<this.verticesIndices.length;n+=3){var a=[this.getVertexVec(this.verticesIndices[n+0]),this.getVertexVec(this.verticesIndices[n+1]),this.getVertexVec(this.verticesIndices[n+2])];o[n/3]=e(a),this.vertexNormals[3*this.verticesIndices[n+0]+0]+=o[n/3][0],this.vertexNormals[3*this.verticesIndices[n+0]+1]+=o[n/3][1],this.vertexNormals[3*this.verticesIndices[n+0]+2]+=o[n/3][2],this.vertexNormals[3*this.verticesIndices[n+1]+0]+=o[n/3][0],this.vertexNormals[3*this.verticesIndices[n+1]+1]+=o[n/3][1],this.vertexNormals[3*this.verticesIndices[n+1]+2]+=o[n/3][2],this.vertexNormals[3*this.verticesIndices[n+2]+0]+=o[n/3][0],this.vertexNormals[3*this.verticesIndices[n+2]+1]+=o[n/3][1],this.vertexNormals[3*this.verticesIndices[n+2]+2]+=o[n/3][2]}for(n=0;n<this.verticesIndices.length;n+=3)for(var h=0;3>h;h++){var l=[this.vertexNormals[3*this.verticesIndices[n+h]+0],this.vertexNormals[3*this.verticesIndices[n+h]+1],this.vertexNormals[3*this.verticesIndices[n+h]+2]];vec3.normalize(l,l),this.vertexNormals[3*this.verticesIndices[n+h]+0]=l[0],this.vertexNormals[3*this.verticesIndices[n+h]+1]=l[1],this.vertexNormals[3*this.verticesIndices[n+h]+2]=l[2]}},CGL.Geometry.prototype.isIndexed=function(){return this._indexed},CGL.Geometry.prototype.unIndex=function(){this._indexed=!1;var t=[],e=[],r=[],s=0;for(this.vertexNormals.length=0,i=0;i<this.verticesIndices.length;i+=3)t.push(this.vertices[3*this.verticesIndices[i+0]+0]),t.push(this.vertices[3*this.verticesIndices[i+0]+1]),t.push(this.vertices[3*this.verticesIndices[i+0]+2]),this.texCoords?(r.push(this.texCoords[2*this.verticesIndices[i+0]+0]),r.push(this.texCoords[2*this.verticesIndices[i+0]+1])):(r.push(0),r.push(0)),e.push(s),s++,t.push(this.vertices[3*this.verticesIndices[i+1]+0]),t.push(this.vertices[3*this.verticesIndices[i+1]+1]),t.push(this.vertices[3*this.verticesIndices[i+1]+2]),this.texCoords?(r.push(this.texCoords[2*this.verticesIndices[i+1]+0]),r.push(this.texCoords[2*this.verticesIndices[i+1]+1])):(r.push(0),r.push(0)),e.push(s),s++,t.push(this.vertices[3*this.verticesIndices[i+2]+0]),t.push(this.vertices[3*this.verticesIndices[i+2]+1]),t.push(this.vertices[3*this.verticesIndices[i+2]+2]),this.texCoords?(r.push(this.texCoords[2*this.verticesIndices[i+2]+0]),r.push(this.texCoords[2*this.verticesIndices[i+2]+1])):(r.push(0),r.push(0)),e.push(s),s++;this.vertices=t,this.texCoords=r,this.verticesIndices=e},CGL.Geometry.prototype.calcBaycentric=function(){for(this.baycentrics.length=this.vertices.length,i=0;i<this.vertices.length;i++)this.baycentrics[i]=0;var t=0;for(i=0;i<this.vertices.length;i+=3)this.baycentrics[i+t]=1,t++,3==t&&(t=0)},CGL.Geometry.prototype.getBounds=function(){var t={maxX:-Number.MAX_VALUE,maxY:-Number.MAX_VALUE,maxZ:-Number.MAX_VALUE,minX:Number.MAX_VALUE,minY:Number.MAX_VALUE,minZ:Number.MAX_VALUE},e=0;for(e=0;e<this.vertices.length;e+=3)this.vertices[e+0]==this.vertices[e+0]&&(t.maxX=Math.max(t.maxX,this.vertices[e+0]),t.maxY=Math.max(t.maxY,this.vertices[e+1]),t.maxZ=Math.max(t.maxZ,this.vertices[e+2]),t.minX=Math.min(t.minX,this.vertices[e+0]),t.minY=Math.min(t.minY,this.vertices[e+1]),t.minZ=Math.min(t.minZ,this.vertices[e+2]));return t.x=Math.abs(t.maxX)+Math.abs(t.minX),t.y=Math.abs(t.maxY)+Math.abs(t.minY),t.z=Math.abs(t.maxZ)+Math.abs(t.minZ),t.maxAxis=Math.max(t.z,Math.max(t.x,t.y)),t},CGL.Geometry.prototype.center=function(t,e,r){void 0===t&&(t=!0,e=!0,r=!0);var s=this.getBounds(),n=[s.minX+(s.maxX-s.minX)/2,s.minY+(s.maxY-s.minY)/2,s.minZ+(s.maxZ-s.minZ)/2];for(i=0;i<this.vertices.length;i+=3)this.vertices[i+0]==this.vertices[i+0]&&(t&&(this.vertices[i+0]-=n[0]),e&&(this.vertices[i+1]-=n[1]),r&&(this.vertices[i+2]-=n[2]));return n},CGL.Geometry.prototype.mapTexCoords2d=function(){var t=this.getBounds(),e=this.vertices.length/3;this.texCoords.length=2*e;for(var i=0;e>i;i++){var r=this.vertices[3*i+0],s=this.vertices[3*i+1];this.texCoords[2*i+0]=r/(t.maxX-t.minX)/2+.5,this.texCoords[2*i+1]=1-s/(t.maxY-t.minY)/2+.5}},CGL.Geometry.buildFromFaces=function(t){for(var e=[],i=[],r=0;r<t.length;r+=3){for(var s=t[r+0],n=t[r+1],o=t[r+2],a=[-1,-1,-1],h=0;e>h;h+=3)e[h+0]==s[0]&&e[h+1]==s[1]&&e[h+2]==s[2]&&(a[0]=h/3),e[h+0]==n[0]&&e[h+1]==n[1]&&e[h+2]==n[2]&&(a[1]=h/3),e[h+0]==o[0]&&e[h+1]==o[1]&&e[h+2]==o[2]&&(a[2]=h/3);-1==a[0]&&(e.push(s[0],s[1],s[2]),a[0]=(e.length-1)/3),-1==a[1]&&(e.push(n[0],n[1],n[2]),a[1]=(e.length-1)/3),-1==a[2]&&(e.push(o[0],o[1],o[2]),a[2]=(e.length-1)/3),i.push(parseInt(a[0],10)),i.push(parseInt(a[1],10)),i.push(parseInt(a[2],10))}var l=new CGL.Geometry;return l.vertices=e,l.verticesIndices=i,l},CGL.Geometry.json2geom=function(t){var e=new CGL.Geometry;e.verticesIndices=[],e.vertices=JSON.parse(JSON.stringify(t.vertices)),e.vertexNormals=t.normals||[],e.vertexColors=t.colors||[],e.tangents=t.tangents||[],e.biTangents=t.bitangents||[],t.texturecoords&&e.setTexCoords(t.texturecoords[0]),console.log(e.texCoords),e.verticesIndices.length=3*t.faces.length;for(var i=0;i<t.faces.length;i++)e.verticesIndices[3*i]=t.faces[i][0],e.verticesIndices[3*i+1]=t.faces[i][1],e.verticesIndices[3*i+2]=t.faces[i][2];return e},CABLES=CABLES||{},CABLES.WebAudio=CABLES.WebAudio||{},CGL.Marker=function(t){var e=new CGL.Geometry("marker");e.setPointVertices([1e-5,0,0,1,0,0,0,1e-5,0,0,1,0,0,0,1e-5,0,0,1]);var i=new CGL.Mesh(t,e,t.gl.LINES);i.setGeom(e);var r=new CGL.Shader(t,"markermaterial"),s="".endl()+"precision highp float;".endl()+"IN vec3 axisColor;".endl()+"void main()".endl()+"{".endl()+" vec4 col=vec4(axisColor,1.0);".endl()+" outColor = col;".endl()+"}",n="".endl()+"IN vec3 vPosition;".endl()+"UNI mat4 projMatrix;".endl()+"UNI mat4 mvMatrix;".endl()+"OUT vec3 axisColor;".endl()+"void main()".endl()+"{".endl()+" vec4 pos=vec4(vPosition, 1.0);".endl()+" if(pos.x!=0.0)axisColor=vec3(1.0,0.3,0.0);".endl()+" if(pos.y!=0.0)axisColor=vec3(0.0,1.0,0.2);".endl()+" if(pos.z!=0.0)axisColor=vec3(0.0,0.5,1.0);".endl()+" gl_Position = projMatrix * mvMatrix * pos;".endl()+"}";r.setSource(n,s),this._vScale=vec3.create(),this.draw=function(t){var e=2;t.pushMvMatrix(),t.setShader(r),vec3.set(this._vScale,e,e,e),mat4.scale(t.mvMatrix,t.mvMatrix,this._vScale),t.gl.disable(t.gl.DEPTH_TEST),i.render(t.getShader()),t.gl.enable(t.gl.DEPTH_TEST),t.setPreviousShader(),t.popMvMatrix()}},CGL.WirePoint=function(t,e){function i(){var e=[],i=24,s=0,n=0,o=.5;for(s=0;s<=Math.round(i);s++)n=360/Math.round(i)*s*CGL.DEG2RAD,e.push(Math.cos(n)*o),e.push(0),e.push(Math.sin(n)*o);for(s=0;s<=Math.round(i);s++)n=360/Math.round(i)*s*CGL.DEG2RAD,e.push(Math.cos(n)*o),e.push(Math.sin(n)*o),e.push(0);for(s=0;s<=Math.round(i);s++)n=360/Math.round(i)*s*CGL.DEG2RAD,e.push(0),e.push(Math.cos(n)*o),e.push(Math.sin(n)*o);t.gl.bindBuffer(t.gl.ARRAY_BUFFER,r),t.gl.bufferData(t.gl.ARRAY_BUFFER,new Float32Array(e),t.gl.STATIC_DRAW),r.itemSize=3,r.numItems=e.length/r.itemSize}var r=t.gl.createBuffer(),s=vec3.create();this.render=function(t,e){t.pushModelMatrix(),vec3.set(s,e,e,e),mat4.scale(t.mvMatrix,t.mvMatrix,s);var i=t.getShader();i.bind(),t.gl.bindBuffer(t.gl.ARRAY_BUFFER,r),t.gl.vertexAttribPointer(i.getAttrVertexPos(),r.itemSize,t.gl.FLOAT,!1,0,0),t.gl.enableVertexAttribArray(i.getAttrVertexPos()),t.gl.bindBuffer(t.gl.ARRAY_BUFFER,r),t.gl.drawArrays(t.gl.LINE_STRIP,0,r.numItems),t.popModelMatrix()},i()},CGL.WireCube=function(t){function e(){var e=[];e.push(-1,-1,1),e.push(1,-1,1),e.push(1,1,1),e.push(-1,1,1),e.push(-1,-1,1),e.push(-1,-1,-1),e.push(1,-1,-1),e.push(1,1,-1),e.push(-1,1,-1),e.push(-1,-1,-1),e.push(-1,-1,-1),e.push(-1,1,-1),e.push(-1,1,1),e.push(-1,-1,1),e.push(-1,-1,-1),e.push(1,-1,-1),e.push(1,1,-1),e.push(1,1,1),e.push(1,-1,1),e.push(1,-1,-1),t.gl.bindBuffer(t.gl.ARRAY_BUFFER,i),t.gl.bufferData(t.gl.ARRAY_BUFFER,new Float32Array(e),t.gl.STATIC_DRAW),i.itemSize=3,i.numItems=e.length/i.itemSize}var i=t.gl.createBuffer(),r=vec3.create();this.render=function(t,e,s,n){t.pushModelMatrix(),vec3.set(r,e||1,s||1,n||1),mat4.scale(t.mvMatrix,t.mvMatrix,r);var o=t.getShader();o.bind(),t.gl.bindBuffer(t.gl.ARRAY_BUFFER,i),t.gl.vertexAttribPointer(o.getAttrVertexPos(),i.itemSize,t.gl.FLOAT,!1,0,0),t.gl.enableVertexAttribArray(o.getAttrVertexPos()),t.gl.bindBuffer(t.gl.ARRAY_BUFFER,i),t.gl.drawArrays(t.gl.LINE_STRIP,0,i.numItems),t.popModelMatrix()},e()};var CGL=CGL||{};CGL.MESH=CGL.MESH||{},CGL.MESH.lastShader=null,CGL.MESH.lastMesh=null,CGL.Mesh=function(t,e,i){this._cgl=t,this._bufVertexAttrib=null,this._bufVerticesIndizes=this._cgl.gl.createBuffer(),this._attributes=[],this._attributes=[],this._geom=null,this.numInstances=0,this._glPrimitive=i,this.addVertexNumbers=!1,this.feedBackAttributes=[],this.setGeom(e),this._feedBacks=[],this._feedBacksChanged=!1,this._transformFeedBackLoc=-1,this._lastAttrUpdate=0},CGL.Mesh.prototype.updateVertices=function(t){this.setAttribute(CGL.SHADERVAR_VERTEX_POSITION,t.vertices,3)},CGL.Mesh.prototype.setAttributePointer=function(t,e,i,r){for(var s=0;s<this._attributes.length;s++)this._attributes[s].name==t&&(this._attributes[s].pointer||(this._attributes[s].pointer=[]),this._attributes[s].pointer.push({loc:-1,name:e,stride:i,offset:r}))},CGL.Mesh.prototype.addAttribute=CGL.Mesh.prototype.updateAttribute=CGL.Mesh.prototype.setAttribute=function(t,e,i,r){var s=null,n=null,o=!1;"function"==typeof r&&(n=r),"object"==typeof r&&(r.cb&&(n=r.cb),r.instanced&&(o=r.instanced)),e instanceof Float32Array?s=e:(s=new Float32Array(e),CGL.profileNonTypedAttrib++,CGL.profileNonTypedAttribNames=this._geom.name+" "+t+" ");var a=e.length/i;0===a&&console.warn("CGL_MESH: num items in attribute "+t+" is ZERO");for(var h=0;h<this._attributes.length;h++)if(this._attributes[h].name==t)return this._attributes[h].numItems=a,this._cgl.gl.bindBuffer(this._cgl.gl.ARRAY_BUFFER,this._attributes[h].buffer),this._cgl.gl.bufferData(this._cgl.gl.ARRAY_BUFFER,s,this._cgl.gl.DYNAMIC_DRAW),this._attributes[h];var l=this._cgl.gl.createBuffer();this._cgl.gl.bindBuffer(this._cgl.gl.ARRAY_BUFFER,l),this._cgl.gl.bufferData(this._cgl.gl.ARRAY_BUFFER,s,this._cgl.gl.DYNAMIC_DRAW);var u=this._cgl.gl.FLOAT;r&&r.type&&(u=r.type);var c={loc:-1,buffer:l,name:t,cb:n,itemSize:i,numItems:a,startItem:0,instanced:o,type:u};for(t==CGL.SHADERVAR_VERTEX_POSITION&&(this._bufVertexAttrib=c),this._attributes.push(c),h=0;h<this._attributes.length;h++)this._attributes[h].loc=-1;return c},CGL.Mesh.prototype.getAttributes=function(){return this._attributes},CGL.Mesh.prototype.updateTexCoords=function(t){t.texCoords&&t.texCoords.length>0&&this.setAttribute(CGL.SHADERVAR_VERTEX_TEXCOORD,t.texCoords,2)},CGL.Mesh.prototype._setVertexNumbers=function(){var t=this._geom.vertices.length/3;if(!this._verticesNumbers||this._verticesNumbers.length!=t){for(this._verticesNumbers=new Float32Array(t),i=0;i<t;i++)this._verticesNumbers[i]=i;this.setAttribute(CGL.SHADERVAR_VERTEX_NUMBER,this._verticesNumbers,1,function(e,i,r){r.uniformNumVertices||(r.uniformNumVertices=new CGL.Uniform(r,"f","numVertices",t)),r.uniformNumVertices.setValue(t)})}},CGL.Mesh.prototype.setVertexIndices=function(t){t.length>0?(this._cgl.gl.bindBuffer(this._cgl.gl.ELEMENT_ARRAY_BUFFER,this._bufVerticesIndizes),this.vertIndicesTyped=t instanceof Uint16Array?t:new Uint16Array(t),this._cgl.gl.bufferData(this._cgl.gl.ELEMENT_ARRAY_BUFFER,this.vertIndicesTyped,this._cgl.gl.DYNAMIC_DRAW),this._bufVerticesIndizes.itemSize=1,this._bufVerticesIndizes.numItems=t.length):this._bufVerticesIndizes.numItems=0},CGL.Mesh.prototype.setGeom=function(t){this._geom=t,CGL.MESH.lastShader=null,CGL.MESH.lastMesh=null,CGL.profileMeshSetGeom++,this.meshChanged()||this.unBind();this._attributes.length=0,this.updateVertices(this._geom),this.setVertexIndices(this._geom.verticesIndices),this._geom.vertexNormals.length>0&&this.setAttribute("attrVertNormal",this._geom.vertexNormals,3),this.updateTexCoords(this._geom),this._geom.hasOwnProperty("tangents")&&this._geom.tangents&&this._geom.tangents.length>0&&this.setAttribute("attrTangent",this._geom.tangents,3),this._geom.hasOwnProperty("biTangents")&&this._geom.biTangents&&this._geom.biTangents.length>0&&this.setAttribute("attrBiTangent",this._geom.biTangents,3),this._geom.vertexColors.length>0&&this.setAttribute("attrVertColor",this._geom.vertexColors,4),this.addVertexNumbers&&this._setVertexNumbers()},CGL.Mesh.prototype._preBind=function(t){for(i=0;i<this._attributes.length;i++)this._attributes[i].cb&&this._attributes[i].cb(this._attributes[i],this._geom,t)},CGL.Mesh.prototype._bind=function(t){if(t.lastCompile>this._lastAttrUpdate)for(this._lastAttrUpdate=t.lastCompile,i=0;i<this._attributes.length;i++)this._attributes[i].loc=-1;for(i=0;i<this._attributes.length;i++){var e=this._attributes[i];if(-1==e.loc&&(e.loc=this._cgl.gl.getAttribLocation(t.getProgram(),e.name)),-1!=e.loc)if(this._cgl.gl.enableVertexAttribArray(e.loc),this._cgl.gl.bindBuffer(this._cgl.gl.ARRAY_BUFFER,e.buffer),e.instanced||"instMat"==e.name)e.itemSize<=4&&(this._cgl.gl.vertexAttribPointer(e.loc,e.itemSize,e.type,!1,4*e.itemSize,0),this._cgl.gl.vertexAttribDivisor(e.loc,1)),16==e.itemSize&&(this._cgl.gl.vertexAttribPointer(e.loc,4,e.type,!1,64,0),this._cgl.gl.enableVertexAttribArray(e.loc+1),this._cgl.gl.vertexAttribPointer(e.loc+1,4,e.type,!1,64,16),this._cgl.gl.enableVertexAttribArray(e.loc+2),this._cgl.gl.vertexAttribPointer(e.loc+2,4,e.type,!1,64,32),this._cgl.gl.enableVertexAttribArray(e.loc+3),this._cgl.gl.vertexAttribPointer(e.loc+3,4,e.type,!1,64,48),this._cgl.gl.vertexAttribDivisor(e.loc,1),this._cgl.gl.vertexAttribDivisor(e.loc+1,1),this._cgl.gl.vertexAttribDivisor(e.loc+2,1),this._cgl.gl.vertexAttribDivisor(e.loc+3,1));else{if(this._cgl.gl.vertexAttribPointer(e.loc,e.itemSize,e.type,!1,4*e.itemSize,0),e.pointer)for(var r=0;r<e.pointer.length;r++){var s=e.pointer[r];-1==s.loc&&(s.loc=this._cgl.gl.getAttribLocation(t.getProgram(),s.name)),this._cgl.gl.enableVertexAttribArray(s.loc),this._cgl.gl.vertexAttribPointer(s.loc,e.itemSize,e.type,!1,s.stride,s.offset)}this.bindFeedback(e)}}0!==this._bufVerticesIndizes.numItems&&this._cgl.gl.bindBuffer(this._cgl.gl.ELEMENT_ARRAY_BUFFER,this._bufVerticesIndizes)},CGL.Mesh.prototype.unBind=function(t){for(this._cgl.lastMesh=null,this._cgl.lastMeshShader=null,i=0;i<this._attributes.length;i++)(this._attributes[i].instanced||"instMat"==this._attributes[i].name)&&(this._attributes[i].itemSize<=4?this._cgl.gl.vertexAttribDivisor(this._attributes[i].loc,0):(this._cgl.gl.vertexAttribDivisor(this._attributes[i].loc,0),
|
|
this._cgl.gl.vertexAttribDivisor(this._attributes[i].loc+1,0),this._cgl.gl.vertexAttribDivisor(this._attributes[i].loc+2,0),this._cgl.gl.vertexAttribDivisor(this._attributes[i].loc+3,0),this._cgl.gl.disableVertexAttribArray(this._attributes[i].loc+1),this._cgl.gl.disableVertexAttribArray(this._attributes[i].loc+2),this._cgl.gl.disableVertexAttribArray(this._attributes[i].loc+3))),-1!=this._attributes[i].loc&&this._cgl.gl.disableVertexAttribArray(this._attributes[i].loc)},CGL.Mesh.prototype.meshChanged=function(){return this._cgl.lastMesh&&this._cgl.lastMesh!=this},CGL.Mesh.hadError=!1,CGL.Mesh.prototype.printDebug=function(t){if(!CGL.Mesh.hadError){var e=this._cgl.gl.getError();if(e!=this._cgl.gl.NO_ERROR){CGL.Mesh.hadError=!0,e==this._cgl.gl.OUT_OF_MEMORY&&console.log("OUT_OF_MEMORY"),e==this._cgl.gl.INVALID_ENUM&&console.log("INVALID_ENUM"),e==this._cgl.gl.INVALID_OPERATION&&console.log("INVALID_OPERATION"),e==this._cgl.gl.INVALID_FRAMEBUFFER_OPERATION&&console.log("INVALID_FRAMEBUFFER_OPERATION"),e==this._cgl.gl.INVALID_VALUE&&console.log("INVALID_VALUE"),e==this._cgl.gl.CONTEXT_LOST_WEBGL&&console.log("CONTEXT_LOST_WEBGL"),e==this._cgl.gl.NO_ERROR&&console.log("NO_ERROR"),console.error("mesh error"),console.log("shader:",t.name),console.log("geom:",this._geom.name),console.log("verts:",this._geom.vertices.length),this._geom.tangents&&console.log("tangents:",this._geom.tangents.length),console.log("texCoords:",this._geom.texCoords.length),console.log("texCoords indizes:",this._geom.texCoordsIndices.length),console.log("indizes:",this._geom.verticesIndices.length);for(var i=0,r=0;r<this._geom.verticesIndices.length;r++)i=Math.max(this._geom.verticesIndices[r],i);console.log("max index",i),console.log("get error: ",e),t.printStats()}}},CGL.Mesh.prototype.setNumVertices=function(t){this._bufVertexAttrib.numItems=t},CGL.Mesh.prototype.render=function(t){if(t){t.wireframe&&this._geom.isIndexed()&&(console.log("unindex"),this._geom.unIndex(),this._geom.calcBaycentric(),this.setGeom(this._geom),this.setAttribute("attrBaycentric",this._geom.baycentrics,3));var e=!1;(CGL.MESH.lastMesh!=this||CGL.MESH.lastShader!=t)&&(e=!0,CGL.MESH.lastMesh&&CGL.MESH.lastShader&&CGL.MESH.lastMesh.unBind(CGL.MESH.lastShader)),CGL.MESH.lastMesh&&CGL.MESH.lastShader||(e=!0),e&&this._preBind(t),t.bind(),t.bindTextures&&t.bindTextures(),e&&this._bind(t),this.addVertexNumbers&&this._setVertexNumbers(),CGL.MESH.lastMesh=this,CGL.MESH.lastShader=t;var i=this._cgl.gl.TRIANGLES;void 0!==this._glPrimitive&&(i=this._glPrimitive),null!==t.glPrimitive&&(i=t.glPrimitive),this.hasFeedbacks()?this.drawFeedbacks(t,i):0===this._bufVerticesIndizes.numItems?this._cgl.gl.drawArrays(i,this._bufVertexAttrib.startItem,this._bufVertexAttrib.numItems-this._bufVertexAttrib.startItem):0===this.numInstances?this._cgl.gl.drawElements(i,this._bufVerticesIndizes.numItems,this._cgl.gl.UNSIGNED_SHORT,0):this._cgl.gl.drawElementsInstanced(i,this._bufVerticesIndizes.numItems,this._cgl.gl.UNSIGNED_SHORT,0,this.numInstances)}},CGL.Mesh.prototype.dispose=function(){},CGL.Mesh.prototype.hasFeedbacks=function(){return this._feedBacks.length>0},CGL.Mesh.prototype.removeFeedbacks=function(t){this._feedbacks&&(this._feedbacks.length=0,this._feedBacksChanged=!0)},CGL.Mesh.prototype.setAttributeFeedback=function(){},CGL.Mesh.prototype.setFeedback=function(t,e,i){var r={nameOut:e},s=!1;this.unBindFeedbacks();for(var n=0;n<this._feedBacks.length;n++)this._feedBacks[n].nameOut==e&&(r=this._feedBacks[n],s=!0);return s||(this._feedBacksChanged=!0),r.initialArr=i,r.attrib=t,r.outBuffer&&this._cgl.gl.deleteBuffer(r.outBuffer),r.outBuffer=this._cgl.gl.createBuffer(),this._cgl.gl.bindBuffer(this._cgl.gl.ARRAY_BUFFER,r.outBuffer),this._cgl.gl.bufferData(this._cgl.gl.ARRAY_BUFFER,r.initialArr,this._cgl.gl.STATIC_DRAW),this._cgl.gl.bindBuffer(this._cgl.gl.ARRAY_BUFFER,r.attrib.buffer),this._cgl.gl.bufferData(this._cgl.gl.ARRAY_BUFFER,r.initialArr,this._cgl.gl.STATIC_DRAW),s||this._feedBacks.push(r),r},CGL.Mesh.prototype.bindFeedback=function(t){if(this._feedBacks&&0!==this._feedBacks.length){-1==this._transformFeedBackLoc&&(this._transformFeedBackLoc=this._cgl.gl.createTransformFeedback()),this._cgl.gl.bindTransformFeedback(this._cgl.gl.TRANSFORM_FEEDBACK,this._transformFeedBackLoc);for(var e=!1,i=0;i<this._feedBacks.length;i++){var r=this._feedBacks[i];r.attrib==t&&(e=!0,this._cgl.gl.bindBufferBase(this._cgl.gl.TRANSFORM_FEEDBACK_BUFFER,i,r.outBuffer))}}},CGL.Mesh.prototype.drawFeedbacks=function(t,e){var i=0;if(this._feedBacksChanged){var r=[];for(this._cgl.gl.bindTransformFeedback(this._cgl.gl.TRANSFORM_FEEDBACK,this._transformFeedBackLoc),i=0;i<this._feedBacks.length;i++)r.push(this._feedBacks[i].nameOut);return t.setFeedbackNames(r),console.log("feedbacknames",r),t.compile(),this._feedBacksChanged=!1,this._cgl.gl.bindTransformFeedback(this._cgl.gl.TRANSFORM_FEEDBACK,null),void console.log("changed finished")}this._cgl.gl.beginTransformFeedback(this.glPrimitive),this._cgl.gl.drawArrays(e,0,this._feedBacks[0].attrib.numItems),this._cgl.gl.endTransformFeedback(),this.unBindFeedbacks(),this.feedBacksSwapBuffers()},CGL.Mesh.prototype.unBindFeedbacks=function(){for(i=0;i<this._feedBacks.length;i++)this._cgl.gl.bindBufferBase(this._cgl.gl.TRANSFORM_FEEDBACK_BUFFER,i,null);this._cgl.gl.bindTransformFeedback(this._cgl.gl.TRANSFORM_FEEDBACK,null)},CGL.Mesh.prototype.feedBacksSwapBuffers=function(){for(var t=0;t<this._feedBacks.length;t++){var e=this._feedBacks[t].attrib.buffer;this._feedBacks[t].attrib.buffer=this._feedBacks[t].outBuffer,this._feedBacks[t].outBuffer=e}};var CGL=CGL||{};CGL.profileShaderBinds=0,CGL.profileUniformCount=0,CGL.profileShaderCompiles=0,CGL.profileVideosPlaying=0,CGL.SHADERVAR_VERTEX_POSITION="vPosition",CGL.SHADERVAR_VERTEX_NUMBER="attrVertIndex",CGL.SHADERVAR_VERTEX_TEXCOORD="attrTexCoord",CGL.Shader=function(t,e){if(!t)throw"shader constructed without cgl";var i=this,r=e||"unknown";this.glslVersion=0,t.glVersion>1&&(this.glslVersion=300),this._program=null;var s=[],n=[];this._needsRecompile=!0;var o=t;this._cgl=t;var a=null,h=null,l=null,u=null,c=null,g=null,p=null,d=-1;this._modGroupCount=0,this._feedBackNames=[],this.glPrimitive=null,this.offScreenPass=!1,this._extensions=[],this.srcVert=this.getDefaultVertexShader(),this.srcFrag=this.getDefaultFragmentShader(),this.lastCompile=0;var f=[],_=[],E=0;this.getCgl=function(){return o},this.setSource=function(t,e){this.srcVert=t,this.srcFrag=e,this._needsRecompile=!0},this.enableExtension=function(t){this._needsRecompile=!0,this._extensions.push(t)},this.define=function(t,e){e||(e="");for(var i=0;i<n.length;i++)if(n[i][0]==t)return n[i][1]=e,void(this._needsRecompile=!0);n.push([t,e]),this._needsRecompile=!0},this.getDefine=function(t){for(var e=0;e<n.length;e++)if(n[e][0]==t)return n[e][1];return null},this.hasDefine=function(t){for(var e=0;e<n.length;e++)if(n[e][0]==t)return!0},this.removeDefine=function(t,e){for(var i=0;i<n.length;i++)if(n[i][0]==t)return n.splice(i,1),void(this._needsRecompile=!0)},this.getUniform=function(t){for(var e=0;e<s.length;e++)if(s[e].getName()==t)return s[e];return null},this.removeUniform=function(t){for(var e=0;e<s.length;e++)s[e].getName()==t&&s.splice(e,1);this._needsRecompile=!0},this.addUniform=function(t){s.push(t),this._needsRecompile=!0},this.getAttrVertexPos=function(){return d},this.hasTextureUniforms=function(){for(var t=0;t<s.length;t++)if("t"==s[t].getType())return!0;return!1},this.printStats=function(){var t=o.gl.getProgramParameter(this._program,o.gl.ACTIVE_UNIFORMS),e=o.gl.getProgramParameter(this._program,o.gl.ACTIVE_ATTRIBUTES),i={35664:"FLOAT_VEC2",35665:"FLOAT_VEC3",35666:"FLOAT_VEC4",35667:"INT_VEC2",35668:"INT_VEC3",35669:"INT_VEC4",35670:"BOOL",35671:"BOOL_VEC2",35672:"BOOL_VEC3",35673:"BOOL_VEC4",35674:"FLOAT_MAT2",35675:"FLOAT_MAT3",35676:"FLOAT_MAT4",35678:"SAMPLER_2D",35680:"SAMPLER_CUBE",5120:"BYTE",5121:"UNSIGNED_BYTE",5122:"SHORT",5123:"UNSIGNED_SHORT",5124:"INT",5125:"UNSIGNED_INT",5126:"FLOAT"},r=0,s={uniformCount:0,attributeCount:0};for(console.log("shader uniforms"),r=0;t>r;r++){var n=o.gl.getActiveUniform(this._program,r);n.typeName=i[n.type],console.log(" ",r,n.name,n.typeName),s.uniformCount+=n.size}for(r=0;e>r;r++){var a=o.gl.getActiveAttrib(this._program,r);a.typeName=i[a.type],console.log(" ",r,a.name,a.typeName),s.attributeCount+=a.size}console.log(s)},this.compile=function(){CGL.profileShaderCompiles++,CGL.profileShaderCompileName=r;var t="";if(this._extensions)for(o=0;o<this._extensions.length;o++)t+="#extension GL_OES_standard_derivatives : enable".endl();var e="",o=0;for(o=0;o<n.length;o++)e+="#define "+n[o][0]+" "+n[o][1]+"".endl();for(o=0;o<s.length;o++)s[o].resetLoc();i.hasTextureUniforms()&&(e+="#define HAS_TEXTURES".endl());var h="",l="";300==i.glslVersion?(h="#version 300 es".endl()+"// ".endl()+"// vertex shader "+r.endl()+"// ".endl()+"precision highp float;".endl()+"".endl()+"#define texture2D texture".endl()+"#define UNI uniform".endl()+"#define IN in".endl()+"#define OUT out".endl(),l="#version 300 es".endl()+"// ".endl()+"// fragment shader "+r.endl()+"// ".endl()+"precision highp float;".endl()+"".endl()+"#define texture2D texture".endl()+"#define IN in".endl()+"#define UNI uniform".endl()+"out vec4 outColor;".endl()+"#define gl_FragColor outColor".endl()):(l="".endl()+"// ".endl()+"// fragment shader "+r.endl()+"// ".endl()+"#define outColor gl_FragColor".endl()+"#define IN varying".endl()+"#define UNI uniform".endl(),h="".endl()+"// ".endl()+"// vertex shader "+r.endl()+"// ".endl()+"#define OUT varying".endl()+"#define IN attribute".endl()+"#define UNI uniform".endl()),-1==l.indexOf("precision")&&(l="precision highp float;".endl()+l),-1==h.indexOf("precision")&&(h="precision highp float;".endl()+h),h=t+h+e+i.srcVert,l=t+l+e+i.srcFrag;var u="",c="";for(_.sort(function(t,e){return t.group-e.group}),_.sort(function(t,e){return t.priority||0-e.priority||0}),o=0;o<f.length;o++){for(var g="",p="",d=0;d<_.length;d++)_[d].name==f[o]&&(_[d].srcBodyVert&&(u+="\n//---- MOD: "+_[d].group+": "+_[d].title+" ------\n\n"),_[d].srcBodyFrag&&(c+="\n//---- MOD: "+_[d].group+": "+_[d].title+" ------\n\n"),_[d].srcHeadVert&&(g+="\n\n//---- MOD: "+_[d].title+" ------\n"),_[d].srcHeadFrag&&(p+="\n\n//---- MOD: "+_[d].title+" ------\n"),g+=_[d].srcBodyVert||"",p+=_[d].srcBodyFrag||"",u+=_[d].srcHeadVert||"",c+=_[d].srcHeadFrag||"",_[d].srcBodyVert&&(u+="\n//---- end mod ------\n"),_[d].srcBodyFrag&&(c+="\n//---- end mod ------\n"),_[d].srcHeadVert&&(g+="\n//---- end mod ------\n"),_[d].srcHeadFrag&&(p+="\n//---- end mod ------\n"),g=g.replace(/{{mod}}/g,_[d].prefix),p=p.replace(/{{mod}}/g,_[d].prefix),u=u.replace(/{{mod}}/g,_[d].prefix),c=c.replace(/{{mod}}/g,_[d].prefix),g=g.replace(/MOD_/g,_[d].prefix),p=p.replace(/MOD_/g,_[d].prefix),u=u.replace(/MOD_/g,_[d].prefix),c=c.replace(/MOD_/g,_[d].prefix));h=h.replace("{{"+f[o]+"}}",g),l=l.replace("{{"+f[o]+"}}",p)}if(h=h.replace("{{MODULES_HEAD}}",u),l=l.replace("{{MODULES_HEAD}}",c),i._program)for(i._program=A(h,l),a=null,o=0;o<s.length;o++)s[o].resetLoc();else i._program=A(h,l);i.finalShaderFrag=l,i.finalShaderVert=h,CGL.MESH.lastMesh=null,CGL.MESH.lastShader=null,i._needsRecompile=!1,i.lastCompile=CABLES.now()},this.bind=function(){var t=0;if(CGL.MESH.lastShader=this,CGL.profileShaderBinds++,(!this._program||this._needsRecompile)&&i.compile(),!a)for(d=o.gl.getAttribLocation(this._program,CGL.SHADERVAR_VERTEX_POSITION),a=o.gl.getUniformLocation(this._program,"projMatrix"),h=o.gl.getUniformLocation(this._program,"mvMatrix"),u=o.gl.getUniformLocation(this._program,"viewMatrix"),l=o.gl.getUniformLocation(this._program,"modelMatrix"),c=o.gl.getUniformLocation(this._program,"camPos"),g=o.gl.getUniformLocation(this._program,"normalMatrix"),p=o.gl.getUniformLocation(this._program,"inverseViewMatrix"),t=0;t<s.length;t++)s[t].needsUpdate=!0;for(o.currentProgram!=this._program&&(o.gl.useProgram(this._program),o.currentProgram=this._program),t=0;t<s.length;t++)s[t].needsUpdate&&s[t].updateValue();if(o.gl.uniformMatrix4fv(a,!1,o.pMatrix),u){o.gl.uniformMatrix4fv(u,!1,o.vMatrix),o.gl.uniformMatrix4fv(l,!1,o.mvMatrix);var e=mat4.create();mat4.invert(e,o.vMatrix),o.gl.uniform3f(c,e[12],e[13],e[14])}else{var r=mat4.create();mat4.mul(r,o.vMatrix,o.mvMatrix),o.gl.uniformMatrix4fv(h,!1,r)}if(p){var n=mat4.create();mat4.invert(n,o.vMatrix),o.gl.uniformMatrix4fv(p,!1,n)}if(g){var f=mat4.create();mat4.mul(f,o.vMatrix,o.mvMatrix),mat4.invert(f,f),mat4.transpose(f,f),o.gl.uniformMatrix4fv(g,!1,f)}};var L=function(t){i._feedBackNames.length>0&&o.gl.transformFeedbackVaryings(t,i._feedBackNames,o.gl.SEPARATE_ATTRIBS),o.gl.linkProgram(t);o.gl.getProgramInfoLog(t);o.gl.getProgramParameter(t,o.gl.LINK_STATUS)||(console.error(r+" shader linking fail..."),console.log("srcFrag",i.srcFrag),console.log("srcVert",i.srcVert),console.log(r+" programinfo: ",o.gl.getProgramInfoLog(t)),console.log("--------------------------------------"),console.log(i),console.log("--------------------------------------"),r="errorshader",i.setSource(CGL.Shader.getDefaultVertexShader(),CGL.Shader.getErrorFragmentShader()))},A=function(t,e){var r=o.gl.createProgram();return i.vshader=CGL.Shader.createShader(o,t,o.gl.VERTEX_SHADER,i),i.fshader=CGL.Shader.createShader(o,e,o.gl.FRAGMENT_SHADER,i),o.gl.attachShader(r,i.vshader),o.gl.attachShader(r,i.fshader),L(r),r};this.removeModule=function(t){for(var e=0;e<_.length;e++)if(_[e].id==t.id||!_[e]){_.splice(e,1);break}this._needsRecompile=!0},this.addModule=function(t,e){return t.id=CABLES.generateUUID(),t.numId=E,t.num=_.length,t.group=e?e.group:this._modGroupCount++,t.prefix="mod"+t.group,_.push(t),this._needsRecompile=!0,E++,t},this.getNumModules=function(){return _.length},this.setModules=function(t){f=t},this.setModules(["MODULE_VERTEX_POSITION","MODULE_COLOR","MODULE_BEGIN_FRAG"]),this.getCurrentModules=function(){return _}},CGL.Shader.prototype.getProgram=function(){return this._program},CGL.Shader.prototype.setFeedbackNames=function(t){this._needsRecompile=!0,this._feedBackNames=t},CGL.Shader.prototype.getDefaultVertexShader=CGL.Shader.getDefaultVertexShader=function(){return"".endl()+"{{MODULES_HEAD}}".endl()+"IN vec3 vPosition;".endl()+"IN vec2 attrTexCoord;".endl()+"IN vec3 attrVertNormal;".endl()+"OUT vec2 texCoord;".endl()+"OUT vec3 norm;".endl()+"UNI mat4 projMatrix;".endl()+"UNI mat4 mvMatrix;".endl()+"UNI mat4 modelMatrix;".endl()+"void main()".endl()+"{".endl()+" texCoord=attrTexCoord;".endl()+" norm=attrVertNormal;".endl()+" vec4 pos=vec4(vPosition, 1.0);".endl()+" {{MODULE_VERTEX_POSITION}}".endl()+" gl_Position = projMatrix * mvMatrix * pos;".endl()+"}"},CGL.Shader.prototype.getDefaultFragmentShader=CGL.Shader.getDefaultFragmentShader=function(t,e,i){return void 0==t&&(t=.5,e=.5,i=.5),"".endl()+"{{MODULES_HEAD}}".endl()+"void main()".endl()+"{".endl()+" vec4 col=vec4("+t+","+e+","+i+",1.0);".endl()+" {{MODULE_COLOR}}".endl()+" outColor = col;".endl()+"}"},CGL.Shader.getErrorFragmentShader=function(){return"".endl()+"void main()".endl()+"{".endl()+" float g=mod(gl_FragCoord.y+gl_FragCoord.x,0.02)*50.0;".endl()+" if(g>0.5)g=0.4;".endl()+" else g=0.0;".endl()+" outColor = vec4( 1.0, g, 0.0, 1.0);".endl()+"}"},CGL.Shader.createShader=function(t,e,i,r){function s(t){var e=[],i=t.split("\n");for(var r in i){var s=i[r].split(":");parseInt(s[2],10)&&e.push(parseInt(s[2],10))}return e}var n=t.gl.createShader(i);if(t.gl.shaderSource(n,e),t.gl.compileShader(n),!t.gl.getShaderParameter(n,t.gl.COMPILE_STATUS)){console.log("compile status: "),i==t.gl.VERTEX_SHADER&&console.log("VERTEX_SHADER"),i==t.gl.FRAGMENT_SHADER&&console.log("FRAGMENT_SHADER"),console.warn(t.gl.getShaderInfoLog(n));var o=t.gl.getShaderInfoLog(n),a=s(o),h='<div class="shaderErrorCode">',l=e.match(/^.*((\r\n|\n|\r)|$)/gm);for(var u in l){var c=parseInt(u,10)+1,g=c+": "+l[u];console.log(g);var p=!1;for(var d in a)a[d]==c&&(p=!0);p&&(h+='<span class="error">'),h+=g,p&&(h+="</span>")}console.warn(o),o=o.replace(/\n/g,"<br/>"),h=o+"<br/>"+h+"<br/><br/>",CABLES.UI?CABLES.UI.MODAL.showError("shader error "+name,h):console.log("shader error "+name,h),h+="</div>",name="errorshader",r.setSource(CGL.Shader.getDefaultVertexShader(),CGL.Shader.getErrorFragmentShader())}return n},CGL.Uniform=function(t,e,i,r){this._loc=-1,this._type=e,this._name=i,this._shader=t,this._value=1e-5,this._oldValue=null,this._port=null,this._shader.addUniform(this),this.needsUpdate=!0,"3f[]"==e&&(this.set=this.setValue=this.setValueArray3F.bind(this),this.updateValue=this.updateValueArray3F.bind(this)),"f"==e&&(this.set=this.setValue=this.setValueF.bind(this),this.updateValue=this.updateValueF.bind(this)),"i"==e&&(this.set=this.setValue=this.setValueI.bind(this),this.updateValue=this.updateValueI.bind(this)),"b"==e&&(this.set=this.setValue=this.setValueBool.bind(this),this.updateValue=this.updateValueBool.bind(this)),"4f"==e&&(this.set=this.setValue=this.setValue4F.bind(this),this.updateValue=this.updateValue4F.bind(this)),"3f"==e&&(this.set=this.setValue=this.setValue3F.bind(this),this.updateValue=this.updateValue3F.bind(this)),"2f"==e&&(this.set=this.setValue=this.setValue2F.bind(this),this.updateValue=this.updateValue2F.bind(this)),"t"==e&&(this.set=this.setValue=this.setValueT.bind(this),this.updateValue=this.updateValueT.bind(this)),"m4"==e&&(this.set=this.setValue=this.setValueM4.bind(this),this.updateValue=this.updateValueM4.bind(this)),"object"==typeof r&&r instanceof CABLES.Port?(this._port=r,this._value=this._port.get(),this._port.onValueChanged=this.updateFromPort.bind(this)):this._value=r,this.setValue(this._value),this.needsUpdate=!0},CGL.Uniform.prototype.getType=function(){return this._type},CGL.Uniform.prototype.getName=function(){return this._name},CGL.Uniform.prototype.getValue=function(){return this._value},CGL.Uniform.prototype.resetLoc=function(){this._loc=-1,this.needsUpdate=!0},CGL.Uniform.prototype.bindTextures=function(){},CGL.Uniform.prototype.getLoc=function(){return this._loc},CGL.Uniform.prototype.updateFromPort=function(){this.setValue(this._port.get())},CGL.Uniform.prototype.updateValueF=function(){-1==this._loc?this._loc=this._shader.getCgl().gl.getUniformLocation(this._shader.getProgram(),this._name):this.needsUpdate=!1,this._shader.getCgl().gl.uniform1f(this._loc,this._value),CGL.profileUniformCount++},CGL.Uniform.prototype.setValueF=function(t){t!=this._value&&(this.needsUpdate=!0,this._value=t)},CGL.Uniform.prototype.updateValueI=function(){-1==this._loc?this._loc=this._shader.getCgl().gl.getUniformLocation(this._shader.getProgram(),this._name):this.needsUpdate=!1,this._shader.getCgl().gl.uniform1i(this._loc,this._value),CGL.profileUniformCount++},CGL.Uniform.prototype.setValueI=function(t){t!=this._value&&(this.needsUpdate=!0,this._value=t)},CGL.Uniform.prototype.updateValueBool=function(){-1==this._loc?this._loc=this._shader.getCgl().gl.getUniformLocation(this._shader.getProgram(),this._name):this.needsUpdate=!1,this._shader.getCgl().gl.uniform1i(this._loc,this._value?1:0),CGL.profileUniformCount++},CGL.Uniform.prototype.setValueBool=function(t){t!=this._value&&(this.needsUpdate=!0,this._value=t)},CGL.Uniform.prototype.setValueArray3F=function(t){this.needsUpdate=!0,this._value=t},CGL.Uniform.prototype.updateValueArray3F=function(){-1==this._loc?this._loc=this._shader.getCgl().gl.getUniformLocation(this._shader.getProgram(),this._name):this.needsUpdate=!1,this._value&&(this._shader.getCgl().gl.uniform3fv(this._loc,this._value),CGL.profileUniformCount++)},CGL.Uniform.prototype.updateValue3F=function(){this._value&&(-1==this._loc&&(this._loc=this._shader.getCgl().gl.getUniformLocation(this._shader.getProgram(),this._name),CGL.profileShaderGetUniform++,CGL.profileShaderGetUniformName=this._name),this._shader.getCgl().gl.uniform3f(this._loc,this._value[0],this._value[1],this._value[2]),this.needsUpdate=!1,CGL.profileUniformCount++)},CGL.Uniform.prototype.setValue3F=function(t){t&&(this._oldValue?(t[0]!=this._oldValue[0]||t[1]!=this._oldValue[1]||t[2]!=this._oldValue[2])&&(this._oldValue[0]=t[0],this._oldValue[1]=t[1],this._oldValue[2]=t[2],this.needsUpdate=!0):(this._oldValue=[t[0]-1,1,2],this.needsUpdate=!0),this._value=t)},CGL.Uniform.prototype.updateValue2F=function(){this._value&&(-1==this._loc&&(this._loc=this._shader.getCgl().gl.getUniformLocation(this._shader.getProgram(),this._name),CGL.profileShaderGetUniform++,CGL.profileShaderGetUniformName=this._name),this._shader.getCgl().gl.uniform2f(this._loc,this._value[0],this._value[1]),this.needsUpdate=!1,CGL.profileUniformCount++)},CGL.Uniform.prototype.setValue2F=function(t){t&&(this._oldValue?(t[0]!=this._oldValue[0]||t[1]!=this._oldValue[1])&&(this._oldValue[0]=t[0],this._oldValue[1]=t[1],this.needsUpdate=!0):(this._oldValue=[t[0]-1,1],this.needsUpdate=!0),this._value=t)},CGL.Uniform.prototype.updateValueT=function(){-1==this._loc&&(this._loc=this._shader.getCgl().gl.getUniformLocation(this._shader.getProgram(),this._name),CGL.profileShaderGetUniform++,CGL.profileShaderGetUniformName=this._name,-1==this._loc&&console.log("texture this._loc unknown!!")),CGL.profileUniformCount++,this._shader.getCgl().gl.uniform1i(this._loc,this._value),this.needsUpdate=!1},CGL.Uniform.prototype.setValueT=function(t){this.needsUpdate=!0,this._value=t},CGL.Uniform.prototype.updateValue4F=function(){-1==this._loc&&(this._loc=this._shader.getCgl().gl.getUniformLocation(this._shader.getProgram(),this._name),CGL.profileShaderGetUniform++),this._shader.getCgl().gl.uniform4f(this._loc,this._value[0],this._value[1],this._value[2],this._value[3]),CGL.profileUniformCount++},CGL.Uniform.prototype.setValue4F=function(t){this.needsUpdate=!0,this._value=t},CGL.Uniform.prototype.updateValueM4=function(){-1==this._loc&&(this._loc=this._shader.getCgl().gl.getUniformLocation(this._shader.getProgram(),this._name),CGL.profileShaderGetUniform++,CGL.profileShaderGetUniformName=this._name),this._shader.getCgl().gl.uniformMatrix4fv(this._loc,!1,this._value),CGL.profileUniformCount++},CGL.Uniform.prototype.setValueM4=function(t){this.needsUpdate=!0,this._value=t};var CGL=CGL||{};CGL.State=function(){var t=this,e=[],i=[],r=[],s=[],n=[null],o=[0,0,0,0];this.glVersion=0,this.temporaryTexture=null,this.frameStore={},this.gl=null,this.pMatrix=mat4.create(),this.mvMatrix=mat4.create(),this.vMatrix=mat4.create(),this.canvas=null,this.pixelDensity=1,mat4.identity(t.mvMatrix),mat4.identity(t.vMatrix);var a=new CGL.Shader(this,"simpleshader"),h=a,l=[];this.addEventListener=function(t,e){"resize"==t&&l.push(e)},this.removeEventListener=function(t,e){if("resize"==t)for(var i in l)if(l[i]==e)return void l.splice(i,1)},this.setCanvas=function(e){if(CGL.TextureEffectMesh=CGL.TextureEffectMesh||null,this.canvas=document.getElementById(e),this.patch.config.canvas||(this.patch.config.canvas={}),this.patch.config.canvas.hasOwnProperty("preserveDrawingBuffer")||(this.patch.config.canvas.preserveDrawingBuffer=this.patch.config.canvas.preserveDrawingBuffer),this.patch.config.canvas.hasOwnProperty("premultipliedAlpha")||(this.patch.config.canvas.premultipliedAlpha=this.patch.config.canvas.premultipliedAlpha),this.patch.config.canvas.hasOwnProperty("alpha")||(this.patch.config.canvas.alpha=this.patch.config.canvas.alpha),this.patch.config.canvas.hasOwnProperty("antialias")||(this.patch.config.canvas.antialias=this.patch.config.canvas.antialias),this.gl=this.canvas.getContext("webgl2"),this.gl?this.glVersion=2:(this.gl=this.canvas.getContext("webgl")||this.canvas.getContext("experimental-webgl"),this.glVersion=1),!this.gl)return this.patch.config.onError&&this.patch.config.onError("NO_WEBGL","sorry, could not initialize WebGL. Please check if your Browser supports WebGL."),void(this.aborted=!0);var i=(this.gl.getExtension("GL_OES_standard_derivatives"),this.gl.getExtension("ANGLE_instanced_arrays")||this.gl);i.vertexAttribDivisorANGLE&&(this.gl.vertexAttribDivisor=i.vertexAttribDivisorANGLE.bind(i),this.gl.drawElementsInstanced=i.drawElementsInstancedANGLE.bind(i)),t.updateSize()},this.updateSize=function(){this.canvas.width=this.canvasWidth=this.canvas.clientWidth*this.pixelDensity,this.canvas.height=this.canvasHeight=this.canvas.clientHeight*this.pixelDensity},this.canvasWidth=-1,this.canvasHeight=-1;var u=-1,c=-1;this.getViewPort=function(){return o},this.resetViewPort=function(){this.gl.viewport(o[0],o[1],o[2],o[3])},this.setViewPort=function(t,e,i,r){o[0]=Math.round(t),o[1]=Math.round(e),o[2]=Math.round(i),o[3]=Math.round(r),this.gl.viewport(o[0],o[1],o[2],o[3])},this.beginFrame=function(){CABLES.UI&&(gui.preview.render(),CABLES.UI.patchPreviewer&&CABLES.UI.patchPreviewer.render()),t.setShader(a)},this.screenShot=function(t,e){e&&(this.gl.clearColor(1,1,1,1),this.gl.colorMask(!1,!1,!1,!0),this.gl.clear(this.gl.COLOR_BUFFER_BIT),this.gl.colorMask(!0,!0,!0,!0)),this.canvas.toBlob(function(e){t?t(e):console.log("no screenshot callback...")}.bind(this))},this.endFrame=function(){if(t.setPreviousShader(),i.length>0&&console.warn("view matrix stack length !=0 at end of rendering..."),e.length>0&&console.warn("mvmatrix stack length !=0 at end of rendering..."),r.length>0&&console.warn("pmatrix stack length !=0 at end of rendering..."),s.length>0&&console.warn("shaderStack length !=0 at end of rendering..."),e.length=0,i.length=0,r.length=0,s.length=0,u!=t.canvasWidth||c!=t.canvasHeight){u=t.canvasWidth,c=t.canvasHeight,this.setSize(t.canvasWidth,t.canvasHeight),this.updateSize();for(var n=0;n<l.length;n++)l[n]()}},this.getShader=function(){if(h&&(!this.frameStore||!0===this.frameStore.renderOffscreen==h.offScreenPass==!0))return h;for(var t=s.length-1;t>=0;t--)if(s[t]&&this.frameStore.renderOffscreen==s[t].offScreenPass)return s[t]},this.getDefaultShader=function(){return a},this.setShader=function(t){s.push(t),h=t},this.setPreviousShader=function(){if(0===s.length)throw"Invalid shader stack pop!";s.pop(),h=s[s.length-1]},this.pushFrameBuffer=function(t){n.push(t)},this.popFrameBuffer=function(){return 1==n.length?null:(n.pop(),n[n.length-1])},this.pushViewMatrix=function(){var e=mat4.clone(t.vMatrix);i.push(e)},this.popViewMatrix=function(){if(0===i.length)throw"Invalid view popMatrix!";t.vMatrix=i.pop()},this.pushMvMatrix=function(){var i=mat4.clone(t.mvMatrix);e.push(i)},this.popMvMatrix=function(){if(0===e.length)throw"Invalid modelview popMatrix!";t.mvMatrix=e.pop()},this.popModelMatrix=this.popMvMatrix,this.pushModelMatrix=this.pushMvMatrix,this.modelMatrix=function(){return t.mvMatrix},this.pushPMatrix=function(){var e=mat4.create();mat4.copy(e,t.pMatrix),r.push(e)},this.popPMatrix=function(){if(0===r.length)throw"Invalid projection popMatrix!";t.pMatrix=r.pop()};var g=vec3.create();vec3.set(g,0,0,2);var p=vec3.create();vec3.set(p,0,0,0),this.renderStart=function(t,e,i){e||(e=p),i||(i=g),t.gl.enable(t.gl.DEPTH_TEST),t.gl.clearColor(0,0,0,0),t.gl.clear(t.gl.COLOR_BUFFER_BIT|t.gl.DEPTH_BUFFER_BIT),t.setViewPort(0,0,t.canvasWidth,t.canvasHeight),mat4.perspective(t.pMatrix,45,t.canvasWidth/t.canvasHeight,.1,1e3),t.pushPMatrix(),t.pushMvMatrix(),t.pushViewMatrix(),mat4.identity(t.mvMatrix),mat4.identity(t.vMatrix),mat4.translate(t.mvMatrix,t.mvMatrix,e),mat4.translate(t.vMatrix,t.vMatrix,i),t.gl.enable(t.gl.BLEND),t.gl.blendEquationSeparate(t.gl.FUNC_ADD,t.gl.FUNC_ADD),t.gl.blendFuncSeparate(t.gl.SRC_ALPHA,t.gl.ONE_MINUS_SRC_ALPHA,t.gl.ONE,t.gl.ONE_MINUS_SRC_ALPHA),t.beginFrame()},this.renderEnd=function(t,e){t.popViewMatrix(),t.popMvMatrix(),t.popPMatrix(),t.endFrame()},this.setTexture=function(t,e){this.gl.activeTexture(this.gl.TEXTURE0+t),this.gl.bindTexture(this.gl.TEXTURE_2D,e)},this.fullScreen=function(){this.canvas.requestFullscreen?this.canvas.requestFullscreen():this.canvas.mozRequestFullScreen?this.canvas.mozRequestFullScreen():this.canvas.webkitRequestFullscreen?this.canvas.webkitRequestFullscreen():this.canvas.msRequestFullscreen&&this.canvas.msRequestFullscreen()},this.setSize=function(t,e){this.canvas.style.width=t+"px",this.canvas.style.height=e+"px",this.canvas.width=t*this.pixelDensity,this.canvas.height=e*this.pixelDensity,this.updateSize()},this._resizeToWindowSize=function(){console.log("width",window.innerWidth),this.setSize(window.innerWidth,window.innerHeight),t.updateSize()},this.setAutoResizeToWindow=function(t){t?(window.addEventListener("resize",this._resizeToWindowSize.bind(this)),this._resizeToWindowSize()):window.removeEventListener("resize",this._resizeToWindowSize.bind(this))},this.printError=function(t){var e=this.gl.getError();if(e!=this.gl.NO_ERROR){var i="";e==this.gl.OUT_OF_MEMORY&&(i="OUT_OF_MEMORY"),e==this.gl.INVALID_ENUM&&(i="INVALID_ENUM"),e==this.gl.INVALID_OPERATION&&(i="INVALID_OPERATION"),e==this.gl.INVALID_FRAMEBUFFER_OPERATION&&(i="INVALID_FRAMEBUFFER_OPERATION"),e==this.gl.INVALID_VALUE&&(i="INVALID_VALUE"),e==this.gl.CONTEXT_LOST_WEBGL&&(i="CONTEXT_LOST_WEBGL"),e==this.gl.NO_ERROR&&(i="NO_ERROR"),console.log("gl error: ",t,e,i)}},this.saveScreenshot=function(t,e,i,r){function s(t,e,i){return Array(e-String(t).length+1).join(i||"0")+t}this.patch.renderOneFrame();var n=$("#glcanvas").attr("width"),o=$("#glcanvas").attr("height");i&&($("#glcanvas").attr("width",i),n=i),r&&($("#glcanvas").attr("height",r),o=r);var a=new Date,h=String(a.getFullYear())+String(a.getMonth()+1)+String(a.getDate())+"_"+s(a.getHours(),2)+s(a.getMinutes(),2)+s(a.getSeconds(),2);t?t+=".png":t="cables_"+h+".png",this.patch.cgl.doScreenshotClearAlpha=$("#render_removeAlpha").is(":checked"),this.patch.cgl.screenShot(function(i){$("#glcanvas").attr("width",n),$("#glcanvas").attr("height",o),this.onScreenShot=null;var r=document.createElement("a");r.setAttribute("download",t),r.setAttribute("href",URL.createObjectURL(i)),document.body.appendChild(r),r.click(),e&&e(i)}.bind(this),!0)}};var CGL=CGL||{};CGL.DEFAULT_TEXTURE_SIZE=8,CGL.Texture=function(t,e){if(!t)throw"no cgl";this._cgl=t,this.tex=this._cgl.gl.createTexture(),this.width=0,this.height=0,this.flip=!0,this.shadowMap=!1,this.filter=CGL.Texture.FILTER_NEAREST,this.wrap=CGL.Texture.CLAMP_TO_EDGE,this.texTarget=this._cgl.gl.TEXTURE_2D,e&&e.type&&(this.texTarget=e.type),this.textureType=CGL.Texture.TYPE_DEFAULT,this.unpackAlpha=!0,this._fromData=!0,this.name="unknown",e?(this.name=e.name||this.name,e.isDepthTexture&&(this.textureType=CGL.Texture.TYPE_DEPTH),e.isFloatingPointTexture&&(this.textureType=CGL.Texture.TYPE_FLOAT),"textureType"in e&&(this.textureType=e.textureType),"filter"in e&&(this.filter=e.filter),"wrap"in e&&(this.wrap=e.wrap),"unpackAlpha"in e&&(this.unpackAlpha=e.unpackAlpha),"flip"in e&&(this.flip=e.flip),"shadowMap"in e&&(this.shadowMap=e.shadowMap)):e={width:CGL.DEFAULT_TEXTURE_SIZE,height:CGL.DEFAULT_TEXTURE_SIZE},this.setSize(e.width,e.height)},CGL.Texture.prototype.compareSettings=function(t){return t?t.width==this.width&&t.height==this.height&&t.filter==this.filter&&t.wrap==this.wrap&&t.textureType==this.textureType&&t.unpackAlpha==this.unpackAlpha&&t.flip==this.flip:!1},CGL.Texture.prototype.clone=function(){var t=new CGL.Texture(this._cgl,{filter:this.filter,wrap:this.wrap,textureType:this.textureType,unpackAlpha:this.unpackAlpha,flip:this.flip,width:this.width,height:this.height});return this.compareSettings(t)||(console.error("Cloned texture settings do not compare!"),console.log(this),console.log(t)),t},CGL.Texture.prototype.setSize=function(t,e){if((t!=t||0>=t||!t)&&(t=CGL.DEFAULT_TEXTURE_SIZE),(e!=e||0>=e||!e)&&(e=CGL.DEFAULT_TEXTURE_SIZE),t=Math.floor(t),e=Math.floor(e),this.width!=t||this.height!=e){this.width=t,this.height=e,this._cgl.gl.bindTexture(this.texTarget,this.tex),CGL.profileTextureResize++;var i=null;if(this.textureType==CGL.Texture.TYPE_FLOAT&&(this.filter=CGL.Texture.FILTER_NEAREST),this._setFilter(),this.textureType==CGL.Texture.TYPE_FLOAT){if(1==this._cgl.glVersion&&!this._cgl.gl.getExtension("OES_texture_float"))throw"no floating point texture extension";1==this._cgl.glVersion?this._cgl.gl.texImage2D(this.texTarget,0,this._cgl.gl.RGBA,t,e,0,this._cgl.gl.RGBA,this._cgl.gl.FLOAT,null):this._cgl.gl.texImage2D(this.texTarget,0,this._cgl.gl.RGBA32F,t,e,0,this._cgl.gl.RGBA,this._cgl.gl.FLOAT,null);
|
|
|
|
}else if(this.textureType==CGL.Texture.TYPE_DEPTH){var r=this._cgl.gl.DEPTH_COMPONENT;1!=this._cgl.glVersion&&(r=this._cgl.gl.DEPTH_COMPONENT32F),this._cgl.gl.texImage2D(this.texTarget,0,r,t,e,0,this._cgl.gl.DEPTH_COMPONENT,this._cgl.gl.FLOAT,null)}else this._cgl.gl.texImage2D(this.texTarget,0,this._cgl.gl.RGBA,t,e,0,this._cgl.gl.RGBA,this._cgl.gl.UNSIGNED_BYTE,i);2!=this._cgl.glVersion&&!this.isPowerOfTwo()||this.filter!=CGL.Texture.FILTER_MIPMAP||this._cgl.gl.generateMipmap(this.texTarget),this._cgl.gl.bindTexture(this.texTarget,null)}},CGL.Texture.prototype.initFromData=function(t,e,i,r,s){this.filter=r,this.wrap=s,this.width=e,this.height=i,this._fromData=!0,this._cgl.gl.bindTexture(this.texTarget,this.tex),this._cgl.gl.texImage2D(this.texTarget,0,this._cgl.gl.RGBA,e,i,0,this._cgl.gl.RGBA,this._cgl.gl.UNSIGNED_BYTE,t),this._setFilter(),2!=this._cgl.glVersion&&!this.isPowerOfTwo()||this.filter!=CGL.Texture.FILTER_MIPMAP||this._cgl.gl.generateMipmap(this.texTarget),this._cgl.gl.bindTexture(this.texTarget,null)},CGL.Texture.prototype.initTexture=function(t,e){this._fromData=!1,e&&(this.unpackAlpha=e.unpackAlpha||this.unpackAlpha),this._cgl.gl.pixelStorei(this._cgl.gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL,this.unpackAlpha),t.width&&(this.width=t.width),t.height&&(this.height=t.height),e&&(this.filter=e),this._cgl.gl.bindTexture(this.texTarget,this.tex),this._cgl.gl.pixelStorei(this._cgl.gl.UNPACK_FLIP_Y_WEBGL,!this.flip),this._cgl.gl.texImage2D(this.texTarget,0,this._cgl.gl.RGBA,this._cgl.gl.RGBA,this._cgl.gl.UNSIGNED_BYTE,this.image),this._setFilter(),2!=this._cgl.glVersion&&!this.isPowerOfTwo()||this.filter!=CGL.Texture.FILTER_MIPMAP||this._cgl.gl.generateMipmap(this.texTarget),this._cgl.gl.bindTexture(this.texTarget,null),this._cgl.gl.pixelStorei(this._cgl.gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1)},CGL.Texture.prototype["delete"]=function(){CGL.profileTextureDelete++,this._cgl.gl.deleteTexture(this.tex)},CGL.Texture.prototype.isPowerOfTwo=function(){return CGL.Texture.isPowerOfTwo(this.width)&&CGL.Texture.isPowerOfTwo(this.height)},CGL.Texture.prototype.printInfo=function(){console.log(this.getInfo())},CGL.Texture.prototype.getInfoReadable=function(){var t=this.getInfo(),e="";t.name=t.name.substr(0,t.name.indexOf("?rnd="));for(var i in t)e+="* "+i+": **"+t[i]+"**\n";return e},CGL.Texture.prototype.getInfo=function(){var t={};t.name=this.name,t["power of two"]=this.isPowerOfTwo(),t.size=this.width+" x "+this.height;var e=this.texTarget;return this.texTarget==this._cgl.gl.TEXTURE_2D&&(e="TEXTURE_2D"),t.target=e,t.unpackAlpha=this.unpackAlpha,t.textureType=this.textureType==CGL.Texture.TYPE_FLOAT?"TYPE_FLOAT":this.textureType==CGL.Texture.TYPE_DEPTH?"TYPE_DEPTH":this.textureType==CGL.Texture.TYPE_DEFAULT?"TYPE_DEFAULT":"UNKNOWN",t.wrap=this.wrap==CGL.Texture.WRAP_CLAMP_TO_EDGE?"CLAMP_TO_EDGE":this.wrap==CGL.Texture.WRAP_REPEAT?"WRAP_REPEAT":this.wrap==CGL.Texture.WRAP_MIRRORED_REPEAT?"WRAP_MIRRORED_REPEAT":"UNKNOWN",t.filter=this.filter==CGL.Texture.FILTER_NEAREST?"FILTER_NEAREST":this.filter==CGL.Texture.FILTER_LINEAR?"FILTER_LINEAR":this.filter==CGL.Texture.FILTER_MIPMAP?"FILTER_MIPMAP":"UNKNOWN",t},CGL.Texture.prototype._setFilter=function(){if(this._fromData||this._cgl.gl.pixelStorei(this._cgl.gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL,this.unpackAlpha),this.shadowMap&&(console.log("shadowmap tex"),this._cgl.gl.texParameteri(this._cgl.gl.TEXTURE_2D,this._cgl.gl.TEXTURE_COMPARE_MODE,this._cgl.gl.COMPARE_REF_TO_TEXTURE),this._cgl.gl.texParameteri(this._cgl.gl.TEXTURE_2D,this._cgl.gl.TEXTURE_COMPARE_FUNC,this._cgl.gl.LEQUAL)),1!=this._cgl.glVersion||this.isPowerOfTwo())if(this.wrap==CGL.Texture.WRAP_CLAMP_TO_EDGE&&(this._cgl.gl.texParameteri(this.texTarget,this._cgl.gl.TEXTURE_WRAP_S,this._cgl.gl.CLAMP_TO_EDGE),this._cgl.gl.texParameteri(this.texTarget,this._cgl.gl.TEXTURE_WRAP_T,this._cgl.gl.CLAMP_TO_EDGE)),this.wrap==CGL.Texture.WRAP_REPEAT&&(this._cgl.gl.texParameteri(this.texTarget,this._cgl.gl.TEXTURE_WRAP_S,this._cgl.gl.REPEAT),this._cgl.gl.texParameteri(this.texTarget,this._cgl.gl.TEXTURE_WRAP_T,this._cgl.gl.REPEAT)),this.wrap==CGL.Texture.WRAP_MIRRORED_REPEAT&&(this._cgl.gl.texParameteri(this.texTarget,this._cgl.gl.TEXTURE_WRAP_S,this._cgl.gl.MIRRORED_REPEAT),this._cgl.gl.texParameteri(this.texTarget,this._cgl.gl.TEXTURE_WRAP_T,this._cgl.gl.MIRRORED_REPEAT)),this.filter==CGL.Texture.FILTER_NEAREST)this._cgl.gl.texParameteri(this.texTarget,this._cgl.gl.TEXTURE_MAG_FILTER,this._cgl.gl.NEAREST),this._cgl.gl.texParameteri(this.texTarget,this._cgl.gl.TEXTURE_MIN_FILTER,this._cgl.gl.NEAREST);else if(this.filter==CGL.Texture.FILTER_LINEAR)this._cgl.gl.texParameteri(this.texTarget,this._cgl.gl.TEXTURE_MIN_FILTER,this._cgl.gl.LINEAR),this._cgl.gl.texParameteri(this.texTarget,this._cgl.gl.TEXTURE_MAG_FILTER,this._cgl.gl.LINEAR);else{if(this.filter!=CGL.Texture.FILTER_MIPMAP){console.log("unknown texture filter!",this.filter);var t=new Error;throw t}this._cgl.gl.texParameteri(this.texTarget,this._cgl.gl.TEXTURE_MAG_FILTER,this._cgl.gl.LINEAR),this._cgl.gl.texParameteri(this.texTarget,this._cgl.gl.TEXTURE_MIN_FILTER,this._cgl.gl.LINEAR_MIPMAP_LINEAR)}else this._cgl.gl.texParameteri(this.texTarget,this._cgl.gl.TEXTURE_MAG_FILTER,this._cgl.gl.NEAREST),this._cgl.gl.texParameteri(this.texTarget,this._cgl.gl.TEXTURE_MIN_FILTER,this._cgl.gl.NEAREST),this._cgl.gl.texParameteri(this.texTarget,this._cgl.gl.TEXTURE_WRAP_S,this._cgl.gl.CLAMP_TO_EDGE),this._cgl.gl.texParameteri(this.texTarget,this._cgl.gl.TEXTURE_WRAP_T,this._cgl.gl.CLAMP_TO_EDGE),this.filter=CGL.Texture.FILTER_NEAREST,this.wrap=CGL.Texture.WRAP_CLAMP_TO_EDGE},CGL.Texture.load=function(t,e,i,r){var s=t.patch.loading.start("texture",e),n=new CGL.Texture(t);return n.name=e,CABLES.UI&&gui.jobs().start({id:"loadtexture"+s,title:"loading texture ("+e+")"}),n.image=new Image,n.image.crossOrigin="",r&&r.hasOwnProperty("filter")&&(n.filter=r.filter),r&&r.hasOwnProperty("flip")&&(n.flip=r.flip),r&&r.hasOwnProperty("wrap")&&(n.wrap=r.wrap),r&&r.hasOwnProperty("unpackAlpha")&&(n.unpackAlpha=r.unpackAlpha),n.image.onabort=n.image.onerror=function(e){t.patch.loading.finished(s);var r={error:!0};i&&i(r)},n.image.onload=function(e){n.initTexture(n.image),t.patch.loading.finished(s),CABLES.UI&&gui.jobs().finish("loadtexture"+s),i&&i()},n.image.src=e,n},CGL.tempTexture=null,CGL.tempTextureEmpty=null,CGL.Texture.getTempTexture=function(t){return CGL.tempTexture||(CGL.tempTexture=CGL.Texture.getTemporaryTexture(t,256,CGL.Texture.FILTER_LINEAR,CGL.Texture.REPEAT)),CGL.tempTexture},CGL.Texture.getEmptyTexture=function(t){if(CGL.tempTexture)return CGL.tempTexture;var e=new CGL.Texture(t),i=new Uint8Array(256);return e.initFromData(i,8,8,CGL.Texture.FILTER_NEAREST,CGL.Texture.WRAP_REPEAT),e},CGL.Texture.getTemporaryTexture=function(t,e,i,r){for(var s=new CGL.Texture(t),n=[],o=0;e>o;o++)for(var a=0;e>a;a++)32>(a+o)%64?(n.push(200+o/e*25+a/e*25),n.push(200+o/e*25+a/e*25),n.push(200+o/e*25+a/e*25)):(n.push(40+o/e*25+a/e*25),n.push(40+o/e*25+a/e*25),n.push(40+o/e*25+a/e*25)),n.push(255);var h=new Uint8Array(n);return s.initFromData(h,e,e,i,r),s},CGL.Texture.createFromImage=function(t,e,i){var r=new CGL.Texture(t,i);return r.flip=!1,r.image=e,r.width=e.width,r.height=e.height,r.initTexture(e,i.filter),r},CGL.Texture.fromImage=function(t,e,i,r){console.error("deprecated texture from image...");var s=new CGL.Texture(t);return s.flip=!1,i&&(s.filter=i),r&&(s.wrap=r),s.image=e,s.initTexture(e),s},CGL.Texture.isPowerOfTwo=function(t){return 1==t||2==t||4==t||8==t||16==t||32==t||64==t||128==t||256==t||512==t||1024==t||2048==t||4096==t||8192==t||16384==t},CGL.Texture.FILTER_NEAREST=0,CGL.Texture.FILTER_LINEAR=1,CGL.Texture.FILTER_MIPMAP=2,CGL.Texture.WRAP_REPEAT=0,CGL.Texture.WRAP_MIRRORED_REPEAT=1,CGL.Texture.WRAP_CLAMP_TO_EDGE=2,CGL.Texture.TYPE_DEFAULT=0,CGL.Texture.TYPE_DEPTH=1,CGL.Texture.TYPE_FLOAT=2;var CGL=CGL||{};CGL.TextureEffect=function(t,e){this._cgl=t,t.TextureEffectMesh||this.createMesh(),this._textureSource=null,this._textureTarget=null,this._frameBuf=this._cgl.gl.createFramebuffer(),this._frameBuf2=this._cgl.gl.createFramebuffer(),this._renderbuffer=this._cgl.gl.createRenderbuffer(),this._renderbuffer2=this._cgl.gl.createRenderbuffer(),this.switched=!1,this.depth=!1},CGL.TextureEffect.prototype.setSourceTexture=function(t){null===t?(this._textureSource=new CGL.Texture(this._cgl),this._textureSource.setSize(16,16)):this._textureSource=t,this._textureSource.compareSettings(this._textureTarget)||(this._textureTarget&&this._textureTarget["delete"](),this._textureTarget=this._textureSource.clone(),CGL.profileEffectBuffercreate++,this._cgl.gl.bindFramebuffer(this._cgl.gl.FRAMEBUFFER,this._frameBuf),this._cgl.gl.bindRenderbuffer(this._cgl.gl.RENDERBUFFER,this._renderbuffer),this.depth&&this._cgl.gl.renderbufferStorage(this._cgl.gl.RENDERBUFFER,this._cgl.gl.DEPTH_COMPONENT16,this._textureSource.width,this._textureSource.height),this._cgl.gl.framebufferTexture2D(this._cgl.gl.FRAMEBUFFER,this._cgl.gl.COLOR_ATTACHMENT0,this._cgl.gl.TEXTURE_2D,this._textureTarget.tex,0),this.depth&&this._cgl.gl.framebufferRenderbuffer(this._cgl.gl.FRAMEBUFFER,this._cgl.gl.DEPTH_ATTACHMENT,this._cgl.gl.RENDERBUFFER,this._renderbuffer),this._cgl.gl.bindTexture(this._cgl.gl.TEXTURE_2D,null),this._cgl.gl.bindRenderbuffer(this._cgl.gl.RENDERBUFFER,null),this._cgl.gl.bindFramebuffer(this._cgl.gl.FRAMEBUFFER,null),this._cgl.gl.bindFramebuffer(this._cgl.gl.FRAMEBUFFER,this._frameBuf2),this._cgl.gl.bindRenderbuffer(this._cgl.gl.RENDERBUFFER,this._renderbuffer2),this.depth&&this._cgl.gl.renderbufferStorage(this._cgl.gl.RENDERBUFFER,this._cgl.gl.DEPTH_COMPONENT16,this._textureSource.width,this._textureSource.height),this._cgl.gl.framebufferTexture2D(this._cgl.gl.FRAMEBUFFER,this._cgl.gl.COLOR_ATTACHMENT0,this._cgl.gl.TEXTURE_2D,this._textureSource.tex,0),this.depth&&this._cgl.gl.framebufferRenderbuffer(this._cgl.gl.FRAMEBUFFER,this._cgl.gl.DEPTH_ATTACHMENT,this._cgl.gl.RENDERBUFFER,this._renderbuffer2),this._cgl.gl.bindTexture(this._cgl.gl.TEXTURE_2D,null),this._cgl.gl.bindRenderbuffer(this._cgl.gl.RENDERBUFFER,null),this._cgl.gl.bindFramebuffer(this._cgl.gl.FRAMEBUFFER,null))},CGL.TextureEffect.prototype.startEffect=function(){return this._textureTarget?(this.switched=!1,this._cgl.gl.disable(this._cgl.gl.DEPTH_TEST),this._cgl.pushMvMatrix(),this._cgl.pushPMatrix(),this._cgl.gl.viewport(0,0,this.getCurrentTargetTexture().width,this.getCurrentTargetTexture().height),mat4.perspective(this._cgl.pMatrix,45,this.getCurrentTargetTexture().width/this.getCurrentTargetTexture().height,.1,1100),this._cgl.pushPMatrix(),mat4.identity(this._cgl.pMatrix),this._cgl.pushViewMatrix(),mat4.identity(this._cgl.vMatrix),this._cgl.pushMvMatrix(),void mat4.identity(this._cgl.mvMatrix)):void console.log("effect has no target")},CGL.TextureEffect.prototype.endEffect=function(){this._cgl.gl.enable(this._cgl.gl.DEPTH_TEST),this._cgl.popMvMatrix(),this._cgl.popPMatrix(),this._cgl.popMvMatrix(),this._cgl.popViewMatrix(),this._cgl.popPMatrix(),this._cgl.resetViewPort()},CGL.TextureEffect.prototype.bind=function(){return null===this._textureSource?void console.log("no base texture set!"):void(this.switched?(this._cgl.gl.bindFramebuffer(this._cgl.gl.FRAMEBUFFER,this._frameBuf2),this._cgl.pushFrameBuffer(this._frameBuf2)):(this._cgl.gl.bindFramebuffer(this._cgl.gl.FRAMEBUFFER,this._frameBuf),this._cgl.pushFrameBuffer(this._frameBuf)))},CGL.TextureEffect.prototype.finish=function(){return null===this._textureSource?void console.log("no base texture set!"):(this._cgl.TextureEffectMesh.render(this._cgl.getShader()),this._cgl.gl.bindFramebuffer(this._cgl.gl.FRAMEBUFFER,this._cgl.popFrameBuffer()),void(this.switched=!this.switched))},CGL.TextureEffect.prototype.getCurrentTargetTexture=function(){return this.switched?this._textureSource:this._textureTarget},CGL.TextureEffect.prototype.getCurrentSourceTexture=function(){return this.switched?this._textureTarget:this._textureSource},CGL.TextureEffect.prototype["delete"]=function(){this._textureTarget&&this._textureTarget["delete"](),this._textureSource&&this._textureSource["delete"](),this._cgl.gl.deleteRenderbuffer(this._renderbuffer),this._cgl.gl.deleteFramebuffer(this._frameBuf)},CGL.TextureEffect.prototype.createMesh=function(){var t=new CGL.Geometry("textureEffect rect");t.vertices=[1,1,0,-1,1,0,1,-1,0,-1,-1,0],t.texCoords=[1,1,0,1,1,0,0,0],t.verticesIndices=[0,1,2,2,1,3],this._cgl.TextureEffectMesh=new CGL.Mesh(this._cgl,t)},CGL.TextureEffect.checkOpInEffect=function(t){return t.patch.cgl.currentTextureEffect||t.uiAttribs.error?t.patch.cgl.currentTextureEffect&&t.uiAttribs.error?(t.uiAttr({error:null}),!0):t.patch.cgl.currentTextureEffect?!0:t.patch.cgl.currentTextureEffect?!0:!1:(t.uiAttr({error:'This op must be a child of a texture effect! More infos <a href="https://docs.cables.gl/image_composition/image_composition.html" target="_blank">here</a>.'}),!1)},CGL.TextureEffect.getBlendCode=function(){return"".endl()+"vec3 _blend(vec3 base,vec3 blend)".endl()+"{".endl()+" vec3 colNew=blend;".endl()+" #ifdef BM_MULTIPLY".endl()+" colNew=base*blend;".endl()+" #endif".endl()+" #ifdef BM_MULTIPLY_INV".endl()+" colNew=base* vec3(1.0)-blend;".endl()+" #endif".endl()+" #ifdef BM_AVERAGE".endl()+" colNew=((base + blend) / 2.0);".endl()+" #endif".endl()+" #ifdef BM_ADD".endl()+" colNew=min(base + blend, vec3(1.0));".endl()+" #endif".endl()+" #ifdef BM_SUBSTRACT".endl()+" colNew=max(base + blend - vec3(1.0), vec3(0.0));".endl()+" #endif".endl()+" #ifdef BM_DIFFERENCE".endl()+" colNew=abs(base - blend);".endl()+" #endif".endl()+" #ifdef BM_NEGATION".endl()+" colNew=(vec3(1.0) - abs(vec3(1.0) - base - blend));".endl()+" #endif".endl()+" #ifdef BM_EXCLUSION".endl()+" colNew=(base + blend - 2.0 * base * blend);".endl()+" #endif".endl()+" #ifdef BM_LIGHTEN".endl()+" colNew=max(blend, base);".endl()+" #endif".endl()+" #ifdef BM_DARKEN".endl()+" colNew=min(blend, base);".endl()+" #endif".endl()+" #ifdef BM_OVERLAY".endl()+" #define BlendOverlayf(base, blend) (base < 0.5 ? (2.0 * base * blend) : (1.0 - 2.0 * (1.0 - base) * (1.0 - blend)))".endl()+" colNew=vec3(BlendOverlayf(base.r, blend.r),BlendOverlayf(base.g, blend.g),BlendOverlayf(base.b, blend.b));".endl()+" #endif".endl()+" #ifdef BM_SCREEN".endl()+" #define BlendScreenf(base, blend) (1.0 - ((1.0 - base) * (1.0 - blend)))".endl()+" colNew=vec3(BlendScreenf(base.r, blend.r),BlendScreenf(base.g, blend.g),BlendScreenf(base.b, blend.b));".endl()+" #endif".endl()+" #ifdef BM_SOFTLIGHT".endl()+" #define BlendSoftLightf(base, blend) ((blend < 0.5) ? (2.0 * base * blend + base * base * (1.0 - 2.0 * blend)) : (sqrt(base) * (2.0 * blend - 1.0) + 2.0 * base * (1.0 - blend)))".endl()+" colNew=vec3(BlendSoftLightf(base.r, blend.r),BlendSoftLightf(base.g, blend.g),BlendSoftLightf(base.b, blend.b));".endl()+" #endif".endl()+" #ifdef BM_HARDLIGHT".endl()+" #define BlendOverlayf(base, blend) (base < 0.5 ? (2.0 * base * blend) : (1.0 - 2.0 * (1.0 - base) * (1.0 - blend)))".endl()+" colNew=vec3(BlendOverlayf(base.r, blend.r),BlendOverlayf(base.g, blend.g),BlendOverlayf(base.b, blend.b));".endl()+" #endif".endl()+" #ifdef BM_COLORDODGE".endl()+" #define BlendColorDodgef(base, blend) ((blend == 1.0) ? blend : min(base / (1.0 - blend), 1.0))".endl()+" colNew=vec3(BlendColorDodgef(base.r, blend.r),BlendColorDodgef(base.g, blend.g),BlendColorDodgef(base.b, blend.b));".endl()+" #endif".endl()+" #ifdef BM_COLORBURN".endl()+" #define BlendColorBurnf(base, blend) ((blend == 0.0) ? blend : max((1.0 - ((1.0 - base) / blend)), 0.0))".endl()+" colNew=vec3(BlendColorBurnf(base.r, blend.r),BlendColorBurnf(base.g, blend.g),BlendColorBurnf(base.b, blend.b));".endl()+" #endif".endl()+" return colNew;".endl()+"}"},CGL.TextureEffect.onChangeBlendSelect=function(t,e){"normal"==e?t.define("BM_NORMAL"):t.removeDefine("BM_NORMAL"),"multiply"==e?t.define("BM_MULTIPLY"):t.removeDefine("BM_MULTIPLY"),"multiply invert"==e?t.define("BM_MULTIPLY_INV"):t.removeDefine("BM_MULTIPLY_INV"),"average"==e?t.define("BM_AVERAGE"):t.removeDefine("BM_AVERAGE"),"add"==e?t.define("BM_ADD"):t.removeDefine("BM_ADD"),"substract"==e?t.define("BM_SUBSTRACT"):t.removeDefine("BM_SUBSTRACT"),"difference"==e?t.define("BM_DIFFERENCE"):t.removeDefine("BM_DIFFERENCE"),"negation"==e?t.define("BM_NEGATION"):t.removeDefine("BM_NEGATION"),"exclusion"==e?t.define("BM_EXCLUSION"):t.removeDefine("BM_EXCLUSION"),"lighten"==e?t.define("BM_LIGHTEN"):t.removeDefine("BM_LIGHTEN"),"darken"==e?t.define("BM_DARKEN"):t.removeDefine("BM_DARKEN"),"overlay"==e?t.define("BM_OVERLAY"):t.removeDefine("BM_OVERLAY"),"screen"==e?t.define("BM_SCREEN"):t.removeDefine("BM_SCREEN"),"softlight"==e?t.define("BM_SOFTLIGHT"):t.removeDefine("BM_SOFTLIGHT"),"hardlight"==e?t.define("BM_HARDLIGHT"):t.removeDefine("BM_HARDLIGHT"),"color dodge"==e?t.define("BM_COLORDODGE"):t.removeDefine("BM_COLORDODGE"),"color burn"==e?t.define("BM_COLORBURN"):t.removeDefine("BM_COLORBURN")},CGL.TextureEffect.AddBlendSelect=function(t,e){var i=t.inValueSelect(e,["normal","lighten","darken","multiply","multiply invert","average","add","substract","difference","negation","exclusion","overlay","screen","color dodge","color burn","softlight","hardlight"],"normal");return i};var CABLES=CABLES||{};CABLES.Link=function(t){this.portIn=null,this.portOut=null,this.scene=t,this.activityCounter=0},CABLES.Link.prototype.setValue=function(t){void 0===t?this._setValue():this.portIn.set(t)},CABLES.Link.prototype.activity=function(){this.activityCounter++},CABLES.Link.prototype._setValue=function(){if(!this.portOut)return void this.remove();var t=this.portOut.get();t==t&&(this.portIn.type!=OP_PORT_TYPE_FUNCTION&&this.activity(),this.portIn.get()!==t?this.portIn.set(t):this.portIn.changeAlways&&this.portIn.set(t))},CABLES.Link.prototype.getOtherPort=function(t){return t==this.portIn?this.portOut:this.portIn},CABLES.Link.prototype.remove=function(){this.portIn&&this.portIn.removeLink(this),this.portOut&&this.portOut.removeLink(this),this.scene&&this.scene.onUnLink(this.portIn,this.portOut),this.portIn&&this.portIn.type==OP_PORT_TYPE_OBJECT&&this.portIn.set(null),this.portIn=null,this.portOut=null,this.scene=null},CABLES.Link.prototype.link=function(t,e){return CABLES.Link.canLink(t,e)?(t.direction==PORT_DIR_IN?(this.portIn=t,this.portOut=e):(this.portIn=e,this.portOut=t),t.addLink(this),e.addLink(this),this.setValue(),t.onLink&&t.onLink(this),void(e.onLink&&e.onLink(this))):(console.log("cannot link ports!"),!1)},CABLES.Link.prototype.getSerialized=function(){var t={};return t.portIn=this.portIn.getName(),t.portOut=this.portOut.getName(),t.objIn=this.portIn.parent.id,t.objOut=this.portOut.parent.id,t},CABLES.Link.canLinkText=function(t,e){if(t.direction==e.direction){var i="(out)";return e.direction==PORT_DIR_IN&&(i="(in)"),"can not link: same direction"+i}return t.parent==e.parent?"can not link: same op":t.type!=OP_PORT_TYPE_DYNAMIC&&e.type!=OP_PORT_TYPE_DYNAMIC&&t.type!=e.type?"can not link: different type":t?e?t.direction==PORT_DIR_IN&&t.isAnimated()?"can not link: is animated":e.direction==PORT_DIR_IN&&e.isAnimated()?"can not link: is animated":t.isLinkedTo(e)?"ports already linked":t.canLink&&!t.canLink(e)||e.canLink&&!e.canLink(t)?"Incompatible":"can link":"can not link: port 2 invalid":"can not link: port 1 invalid"},CABLES.Link.canLink=function(t,e){return t&&e?t.type==OP_PORT_TYPE_DYNAMIC||e.type==OP_PORT_TYPE_DYNAMIC?!0:t.direction==PORT_DIR_IN&&t.isAnimated()?!1:e.direction==PORT_DIR_IN&&e.isAnimated()?!1:t.isLinkedTo(e)?!1:t.direction==e.direction?!1:t.type!=e.type?!1:t.parent==e.parent?!1:t.canLink&&!t.canLink(e)?!1:e.canLink&&!e.canLink(t)?!1:!0:!1};var OP_PORT_TYPE_VALUE=0,OP_PORT_TYPE_FUNCTION=1,OP_PORT_TYPE_OBJECT=2,OP_PORT_TYPE_TEXTURE=2,OP_PORT_TYPE_ARRAY=3,OP_PORT_TYPE_DYNAMIC=4,Ops={},CABLES=CABLES||{};CABLES.Helpers=CABLES.Helpers||{},CABLES.Helpers.isArray=function(t){return"[object Array]"===Object.prototype.toString.call(t)},CABLES.Op=function(){this.data={},this.objName="",this.portsOut=[],this.portsIn=[],this.uiAttribs={},this.enabled=!0,this.patch=arguments[0],this.name=arguments[1],this.errors={},this.name&&(this.name=this.name.split(".")[this.name.split(".").length-1]),this.id=CABLES.generateUUID(),this.onAddPort=null,this.onCreate=null,this.onResize=null,this.onLoaded=null,this.onDelete=null,this.onUiAttrChange=null,this._instances=null},CABLES.Op.prototype.clearUiAttrib=function(t){var e={};e.name=null,this.uiAttrib(e)},CABLES.Op.prototype.setTitle=function(t){this.name=t,this.uiAttr({title:t})},CABLES.Op.prototype.setUiAttrib=CABLES.Op.prototype.uiAttr=function(t){this.uiAttribs||(this.uiAttribs={});for(var e in t)this.uiAttribs[e]=t[e];this.onUiAttrChange&&this.onUiAttrChange(t)},CABLES.Op.prototype.getName=function(){return this.name},CABLES.Op.prototype.addOutPort=function(t){return t.direction=PORT_DIR_OUT,t.parent=this,this.portsOut.push(t),this.onAddPort&&this.onAddPort(t),t},CABLES.Op.prototype.hasPort=function(t){for(var e in this.portsIn)if(this.portsIn[e].getName()==t)return!0;return!1},CABLES.Op.prototype.hasDynamicPort=function(){var t=0;for(t in this.portsIn){if(this.portsIn[t].type==OP_PORT_TYPE_DYNAMIC)return!0;if("dyn"==this.portsIn[t].getName())return!0}for(t in this.portsOut){if(this.portsOut[t].type==OP_PORT_TYPE_DYNAMIC)return!0;if("dyn"==this.portsOut[t].getName())return!0}return!1},CABLES.Op.prototype.addInPort=function(t){return t.direction=PORT_DIR_IN,t.parent=this,this.portsIn.push(t),this.onAddPort&&this.onAddPort(t),t},CABLES.Op.prototype.inFunction=function(t,e){var i=this.addInPort(new Port(this,t,OP_PORT_TYPE_FUNCTION));return void 0!==e&&i.set(e),i},CABLES.Op.prototype.inFunctionButton=function(t,e){var i=this.addInPort(new Port(this,t,OP_PORT_TYPE_FUNCTION,{display:"button"}));return void 0!==e&&i.set(e),i},CABLES.Op.prototype.inValue=function(t,e){var i=this.addInPort(new Port(this,t,OP_PORT_TYPE_VALUE));return void 0!==e&&(i.set(e),i.defaultValue=e),i},CABLES.Op.prototype.inValueBool=function(t,e){var i=this.addInPort(new Port(this,t,OP_PORT_TYPE_VALUE,{display:"bool"}));return void 0!==e&&(i.set(e),i.defaultValue=e),i},CABLES.Op.prototype.inValueString=function(t,e){var i=this.addInPort(new Port(this,t,OP_PORT_TYPE_VALUE,{type:"string"}));return i.value="",void 0!==e&&(i.set(e),i.defaultValue=e),i},CABLES.Op.prototype.inValueText=function(t,e){var i=this.addInPort(new Port(this,t,OP_PORT_TYPE_VALUE,{type:"string",display:"text"}));return i.value="",void 0!==e&&(i.set(e),i.defaultValue=e),i},CABLES.Op.prototype.inValueSelect=function(t,e,i){var r=this.addInPort(new Port(this,t,OP_PORT_TYPE_VALUE,{display:"dropdown",hidePort:!0,values:e}));return void 0!==i&&(r.set(i),r.defaultValue=i),r},CABLES.Op.prototype.inValueInt=function(t,e){var i=this.addInPort(new Port(this,t,OP_PORT_TYPE_VALUE,{increment:"integer"}));return void 0!==e&&(i.set(e),i.defaultValue=e),i},CABLES.Op.prototype.inFile=function(t,e,i){var r=this.addInPort(new Port(this,t,OP_PORT_TYPE_VALUE,{display:"file",filter:e}));return void 0!==i&&(r.set(i),r.defaultValue=i),r},CABLES.Op.prototype.inTexture=function(t,e){var i=this.addInPort(new Port(this,t,OP_PORT_TYPE_OBJECT,{preview:!0}));return void 0!==e&&i.set(e),i},CABLES.Op.prototype.inObject=function(t,e,i){var r=this.addInPort(new Port(this,t,OP_PORT_TYPE_OBJECT,i));return void 0!==e&&r.set(e),r},CABLES.Op.prototype.inArray=function(t,e){var i=this.addInPort(new Port(this,t,OP_PORT_TYPE_ARRAY));return void 0!==e&&i.set(e),i},CABLES.Op.prototype.inValueSlider=function(t,e){var i=this.addInPort(new Port(this,t,OP_PORT_TYPE_VALUE,{display:"range"}));return void 0!==e&&(i.set(e),i.defaultValue=e),i},CABLES.Op.prototype.outFunction=function(t,e){var i=this.addOutPort(new Port(this,t,OP_PORT_TYPE_FUNCTION));return void 0!==e&&i.set(e),i},CABLES.Op.prototype.outValue=function(t,e){var i=this.addOutPort(new Port(this,t,OP_PORT_TYPE_VALUE));return void 0!==e&&i.set(e),i},CABLES.Op.prototype.outValueBool=function(t,e){var i=this.addOutPort(new Port(this,t,OP_PORT_TYPE_VALUE,{display:"bool"}));return i.set(void 0!==e?e:!1),i},CABLES.Op.prototype.outValueString=function(t,e){var i=this.addOutPort(new Port(this,t,OP_PORT_TYPE_VALUE));return void 0!==e&&i.set(e),i},CABLES.Op.prototype.outObject=function(t,e){var i=this.addOutPort(new Port(this,t,OP_PORT_TYPE_OBJECT));return void 0!==e&&i.set(e),i.ignoreValueSerialize=!0,i},CABLES.Op.prototype.outArray=function(t,e){var i=this.addOutPort(new Port(this,t,OP_PORT_TYPE_ARRAY));return void 0!==e&&i.set(e),i.ignoreValueSerialize=!0,i},CABLES.Op.prototype.outTexture=function(t,e){var i=this.addOutPort(new Port(this,t,OP_PORT_TYPE_OBJECT,{preview:!0}));return void 0!==e&&i.set(e),i.ignoreValueSerialize=!0,i},CABLES.Op.prototype.inDynamic=function(t,e,i,r){var s=new Port(this,t,OP_PORT_TYPE_DYNAMIC,i);return s.shouldLink=function(t,i){if(e&&CABLES.Helpers.isArray(e)){for(var r=0;r<e.length;r++){if(t==this&&i.type===e[r])return!0;if(i==this&&t.type===e[r])return!0}return!1}return!0},this.addInPort(s),void 0!==r&&(s.set(r),s.defaultValue=r),s},CABLES.Op.prototype.printInfo=function(){for(var t=0;t<this.portsIn.length;t++)console.log("in: "+this.portsIn[t].getName());for(var e in this.portsOut)console.log("out: "+this.portsOut[e].getName())},CABLES.Op.prototype.markChilds=function(){this.marked=!0;for(var t in this.portsOut)for(var e in this.portsOut[t].links)this.portsOut[t].parent.marked=!0,this.portsOut[t].links[e].portIn.parent!=this&&this.portsOut[t].links[e].portIn.parent.markChilds()},CABLES.Op.prototype.deleteChilds=function(){var t=[];for(var e in this.portsOut)for(var i in this.portsOut[e].links)this.portsOut[e].links[i].portIn.parent!=this&&(this.portsOut[e].parent!=this&&t.push(this.portsOut[e].parent),t.push(this.portsOut[e].links[i].portIn.parent),this.portsOut[e].links[i].portIn.parent.deleteChilds());for(var r in t)this.patch.deleteOp(t[r].id)},CABLES.Op.prototype.removeLinks=function(){for(var t=0;t<this.portsIn.length;t++)this.portsIn[t].removeLinks();for(var e in this.portsOut)this.portsOut[e].removeLinks()},CABLES.Op.prototype.countFittingPorts=function(t){var e=0;for(var i in this.portsOut)CABLES.Link.canLink(t,this.portsOut[i])&&e++;for(var r in this.portsIn)CABLES.Link.canLink(t,this.portsIn[r])&&e++;return e},CABLES.Op.prototype.findFittingPort=function(t){for(var e in this.portsOut)if(CABLES.Link.canLink(t,this.portsOut[e]))return this.portsOut[e];for(var i in this.portsIn)if(CABLES.Link.canLink(t,this.portsIn[i]))return this.portsIn[i]},CABLES.Op.prototype.getSerialized=function(){var t={};t.name=this.getName(),t.objName=this.objName,t.id=this.id,t.uiAttribs=this.uiAttribs,t.portsIn=[],t.portsOut=[];for(var e=0;e<this.portsIn.length;e++)t.portsIn.push(this.portsIn[e].getSerialized());for(var i in this.portsOut)t.portsOut.push(this.portsOut[i].getSerialized());return t},CABLES.Op.prototype.getFistOutPortByType=function(t){for(var e in this.portsOut)if(this.portsOut[e].type==t)return this.portsOut[e]},CABLES.Op.prototype.getPortByName=function(t){for(var e in this.portsIn)if(this.portsIn[e].getName()==t)return this.portsIn[e];for(var i in this.portsOut)if(this.portsOut[i].getName()==t)return this.portsOut[i]},CABLES.Op.prototype.getPort=function(t){return this.getPortByName(t)},CABLES.Op.prototype.updateAnims=function(){for(var t=0;t<this.portsIn.length;t++)this.portsIn[t].updateAnim()},CABLES.Op.prototype.log=function(){this.patch.silent||Function.prototype.apply.apply(console.log,[console,arguments])},CABLES.Op.prototype.undoUnLinkTemporary=function(){if(this.shakeLink&&this.shakeLink.remove(),this.shakeLink=null,this.oldLinks){for(var t=0;t<this.oldLinks.length;t++)this.patch.link(this.oldLinks[t]["in"].parent,this.oldLinks[t]["in"].getName(),this.oldLinks[t].out.parent,this.oldLinks[t].out.getName());this.oldLinks.length=0}},CABLES.Op.prototype.unLink=function(){for(var t in this.portsOut)this.portsOut[t].removeLinks();for(var e in this.portsIn)this.portsIn[e].removeLinks()};var unLinkTempReLinkP1=null,unLinkTempReLinkP2=null;CABLES.Op.prototype.unLinkTemporary=function(){var t=!0,e=0;this.shakeLink=null,this.oldLinks=[],t&&this.portsIn.length>0&&this.portsIn[0].isLinked()&&this.portsOut.length>0&&this.portsOut[0].isLinked()&&this.portsIn[0].getType()==this.portsOut[0].getType()&&(unLinkTempReLinkP1=this.portsIn[0].links[0].getOtherPort(this.portsIn[0]),unLinkTempReLinkP2=this.portsOut[0].links[0].getOtherPort(this.portsOut[0]));for(var i in this.portsIn)for(e=0;e<this.portsIn[i].links.length;e++)this.oldLinks.push({"in":this.portsIn[i].links[e].portIn,out:this.portsIn[i].links[e].portOut});for(var r in this.portsOut)for(e=0;e<this.portsOut[r].links.length;e++)this.oldLinks.push({"in":this.portsOut[r].links[e].portIn,out:this.portsOut[r].links[e].portOut});this.unLink(),unLinkTempReLinkP1&&unLinkTempReLinkP2&&(this.shakeLink=this.patch.link(unLinkTempReLinkP1.parent,unLinkTempReLinkP1.getName(),unLinkTempReLinkP2.parent,unLinkTempReLinkP2.getName()))},CABLES.Op.prototype.profile=function(t){for(var e in this.portsIn)this.portsIn[e]._onTriggered=this.portsIn[e]._onTriggeredProfiling},CABLES.Op.prototype.findParent=function(t){for(var e in this.portsIn)if(this.portsIn[e].isLinked()){if(this.portsIn[e].links[0].portOut.parent.objName==t)return this.portsIn[e].links[0].portOut.parent;var i=null;if(i=this.portsIn[e].links[0].portOut.parent.findParent(t))return i}return null},CABLES.Op.prototype.cleanUp=function(){if(this._instances){for(var t=0;t<this._instances.length;t++)this._instances[t].onDelete&&this._instances[t].onDelete();this._instances.length=0}},CABLES.Op.prototype.instanced=function(t){if(0===this.patch.instancing.numCycles())return!1;var e=0,i=0;if(!this._instances||this._instances.length!=this.patch.instancing.numCycles()){for(this._instances||(this._instances=[]),console.log("creating instances of ",this.objName,this.patch.instancing.numCycles(),this._instances.length),this._instances.length=this.patch.instancing.numCycles(),e=0;e<this._instances.length;e++){this._instances[e]=this.patch.createOp(this.objName,!0),this._instances[e].instanced=function(){return!1},this._instances[e].uiAttr(this.uiAttribs);for(var r=0;r<this.portsOut.length;r++)this.portsOut[r].type==OP_PORT_TYPE_FUNCTION&&(this._instances[e].getPortByName(this.portsOut[r].name).trigger=this.portsOut[r].trigger.bind(this.portsOut[r]))}for(i=0;i<this.portsIn.length;i++)this.portsIn[i].onChange=null,this.portsIn[i].onValueChanged=null}var s=null;for(i=0;i<this.portsIn.length;i++)(this.portsIn[i].type==OP_PORT_TYPE_VALUE||this.portsIn[i].type==OP_PORT_TYPE_ARRAY)&&this._instances[this.patch.instancing.index()].portsIn[i].set(this.portsIn[i].get()),this.portsIn[i].type==OP_PORT_TYPE_FUNCTION&&this._instances[this.patch.instancing.index()].portsIn[i].name==t.name&&(s=this._instances[this.patch.instancing.index()].portsIn[i]);for(s.onTriggered(),i=0;i<this.portsOut.length;i++)this.portsOut[i].type==OP_PORT_TYPE_VALUE&&this.portsOut[i].set(this._instances[this.patch.instancing.index()].portsOut[i].get());return!0},CABLES.Op.prototype.initInstancable=function(){},CABLES.Op.prototype.setValues=function(t){for(var e in t){var i=this.getPortByName(e);i?i.set(t[e]):console.log("op.setValues: port not found:",e)}},CABLES.Op.prototype.error=function(t,e){this.errors[t]=e,null==e&&delete this.errors[t];var i="";for(var r in this.errors)i+="- "+this.errors[r]+"<br/>";this.uiAttr({error:i})},CABLES.Op.isSubpatchOp=function(t){return"Ops.Ui.Patch"==t||"Ops.Ui.SubPatch"==t};var Op=CABLES.Op,CABLES=CABLES||{};CABLES.Patch=function(t){this.ops=[],this.settings={},this.timer=new CABLES.Timer,this.freeTimer=new CABLES.Timer,this.animFrameOps=[],this.animFrameCallbacks=[],this.gui=!1,this.silent=!1,this.profiler=null,this.onLoadStart=null,this.onLoadEnd=null,this.aborted=!1,this.loading=new CABLES.LoadingStatus,this._volumeListeners=[],this._paused=!1,this._frameNum=0,
|
|
this.instancing=new CABLES.Instancing,this.onOneFrameRendered=null,this.config=t||{glCanvasResizeToWindow:!1,glCanvasId:"glcanvas",prefixAssetPath:"",silent:!1,onError:null,onFinishedLoading:null,onFirstFrameRendered:null,fpsLimit:0},this.config.prefixAssetPath||(this.config.prefixAssetPath=""),this.config.masterVolume||(this.config.masterVolume=1),this._variables={},this._variableListeners=[],this.vars={},t&&t.vars&&(this.vars=t.vars),this.cgl=new CGL.State,this.cgl.patch=this,this.cgl.setCanvas(this.config.glCanvasId),this.config.glCanvasResizeToWindow===!0&&this.cgl.setAutoResizeToWindow(!0),this.loading.setOnFinishedLoading(this.config.onFinishedLoading),this.cgl.aborted&&(this.aborted=!0),this.cgl.silent&&(this.silent=!0),this.freeTimer.play(),this.exec(),this.aborted||(this.config.patch?(this.deSerialize(this.config.patch),this.timer.play()):this.config.patchFile&&(CABLES.ajax(this.config.patchFile,function(t,e){var i=JSON.parse(e);if(t){return console.error("err",t),console.error("data",i),void console.error("data",i.msg)}this.deSerialize(i)}.bind(this)),this.timer.play()))},CABLES.Patch.prototype.isPlaying=function(){return!this._paused},CABLES.Patch.prototype.renderOneFrame=function(){this._paused=!0,this._renderOneFrame=!0,this.exec(),this._renderOneFrame=!1},CABLES.Patch.prototype.pause=function(){this._paused=!0,this.freeTimer.pause()},CABLES.Patch.prototype.resume=function(){this._paused&&(this._paused=!1,this.freeTimer.play(),this.exec())},CABLES.Patch.prototype.setVolume=function(t){this.config.masterVolume=t;for(var e=0;e<this._volumeListeners.length;e++)this._volumeListeners[e].onMasterVolumeChanged(t)},CABLES.Patch.prototype.getFilePath=function(t){if(!t)return t;if(0===t.indexOf("https:")||0===t.indexOf("http:"))return t;t=t.replace("//","/");var e=this.config.prefixAssetPath+t+(this.config.suffixAssetPath||"");return e},CABLES.Patch.prototype.clear=function(){for(this.cgl.TextureEffectMesh=null,this.animFrameOps.length=0,this.timer=new CABLES.Timer;this.ops.length>0;)this.deleteOp(this.ops[0].id)},CABLES.Patch.getOpClass=function(t){var e=t.split("."),i=null;try{return 2==e.length?i=window[e[0]][e[1]]:3==e.length?i=window[e[0]][e[1]][e[2]]:4==e.length?i=window[e[0]][e[1]][e[2]][e[3]]:5==e.length?i=window[e[0]][e[1]][e[2]][e[3]][e[4]]:6==e.length?i=window[e[0]][e[1]][e[2]][e[3]][e[4]][e[5]]:7==e.length?i=window[e[0]][e[1]][e[2]][e[3]][e[4]][e[5]][e[6]]:8==e.length?i=window[e[0]][e[1]][e[2]][e[3]][e[4]][e[5]][e[6]][e[7]]:9==e.length?i=window[e[0]][e[1]][e[2]][e[3]][e[4]][e[5]][e[6]][e[7]][e[8]]:10==e.length&&(i=window[e[0]][e[1]][e[2]][e[3]][e[4]][e[5]][e[6]][e[7]][e[8]][e[9]]),i}catch(r){return null}},CABLES.Patch.prototype.createOp=function(t){var e=t.split("."),i=null;try{var r=CABLES.Patch.getOpClass(t);if(!r)throw CABLES.UI&&CABLES.UI.MODAL.showError("unknown op","unknown op: "+t),console.error("unknown op: "+t),"unknown op: "+t;2==e.length?i=new window[e[0]][e[1]](this,t):3==e.length?i=new window[e[0]][e[1]][e[2]](this,t):4==e.length?i=new window[e[0]][e[1]][e[2]][e[3]](this,t):5==e.length?i=new window[e[0]][e[1]][e[2]][e[3]][e[4]](this,t):6==e.length?i=new window[e[0]][e[1]][e[2]][e[3]][e[4]][e[5]](this,t):7==e.length?i=new window[e[0]][e[1]][e[2]][e[3]][e[4]][e[5]][e[6]](this,t):8==e.length?i=new window[e[0]][e[1]][e[2]][e[3]][e[4]][e[5]][e[6]][e[7]](this,t):9==e.length?i=new window[e[0]][e[1]][e[2]][e[3]][e[4]][e[5]][e[6]][e[7]][e[8]](this,t):10==e.length?i=new window[e[0]][e[1]][e[2]][e[3]][e[4]][e[5]][e[6]][e[7]][e[8]][e[9]](this,t):console.log("parts.length",e.length)}catch(s){if(console.error("instancing error "+t),!CABLES.UI)throw CABLES.api&&CABLES.api.sendErrorReport(s),console.log(s),console.log(s.stacktrace),"instancing error "+t;CABLES.UI.MODAL.showOpException(s,t)}return i&&(i.objName=t,i.patch=this),i},CABLES.Patch.prototype.addOp=function(t,e){if(!t||-1==t.indexOf("."))return void CABLES.UI.MODAL.showError("could not create op","op unknown");var i=this.createOp(t);return i&&(i.uiAttr(e),i.onCreate&&i.onCreate(),i.hasOwnProperty("onAnimFrame")&&this.animFrameOps.push(i),i.hasOwnProperty("onMasterVolumeChanged")&&this._volumeListeners.push(i),this.ops.push(i),this.onAdd&&this.onAdd(i)),i},CABLES.Patch.prototype.addOnAnimFrame=function(t){this.animFrameOps.push(t)},CABLES.Patch.prototype.removeOnAnimFrame=function(t){for(var e=0;e<this.animFrameOps.length;e++)if(this.animFrameOps[e]==t)return void this.animFrameOps.splice(e,1)},CABLES.Patch.prototype.addOnAnimFrameCallback=function(t){this.animFrameCallbacks.push(t)},CABLES.Patch.prototype.removeOnAnimCallback=function(t){for(var e=0;e<this.animFrameCallbacks.length;e++)if(this.animFrameCallbacks[e]==t)return void this.animFrameCallbacks.splice(e,1)},CABLES.Patch.prototype.deleteOp=function(t,e){for(var i in this.ops)if(this.ops[i].id==t){var r=this.ops[i],s=null,n=null;if(r){e&&this.ops[i].portsIn.length>0&&this.ops[i].portsIn[0].isLinked()&&this.ops[i].portsOut.length>0&&this.ops[i].portsOut[0].isLinked()&&this.ops[i].portsIn[0].getType()==this.ops[i].portsOut[0].getType()&&(s=this.ops[i].portsIn[0].links[0].getOtherPort(this.ops[i].portsIn[0]),n=this.ops[i].portsOut[0].links[0].getOtherPort(this.ops[i].portsOut[0]));var o=this.ops[i];o.removeLinks(),this.onDelete(o),this.ops.splice(i,1),o.onDelete&&o.onDelete(),o.cleanUp(),null!==s&&null!==n&&this.link(s.parent,s.getName(),n.parent,n.getName())}}},CABLES.Patch.prototype.getFrameNum=function(){return this._frameNum};var frameNext=0,frameInterval=0,lastFrameTime=0,wasdelayed=!0;CABLES.Patch.prototype.renderFrame=function(t){this.timer.update(),this.freeTimer.update();for(var e=this.timer.getTime(),i=0;i<this.animFrameCallbacks.length;++i)this.animFrameCallbacks[i]&&this.animFrameCallbacks[i](e,this._frameNum);for(var i=0;i<this.animFrameOps.length;++i)this.animFrameOps[i].onAnimFrame&&this.animFrameOps[i].onAnimFrame(e);this._frameNum++,1==this._frameNum&&this.config.onFirstFrameRendered&&this.config.onFirstFrameRendered()},CABLES.Patch.prototype.exec=function(t){if(this._renderOneFrame||!this._paused&&!this.aborted){this.config.fpsLimit=this.config.fpsLimit||0,this.config.fpsLimit&&(frameInterval=1e3/this.config.fpsLimit);var e=CABLES.now(),i=e-frameNext;if(CABLES.UI&&(CABLES.UI.capturer&&CABLES.UI.capturer.capture(this.cgl.canvas),!this._renderOneFrame&&e-lastFrameTime>500&&0!==lastFrameTime&&!wasdelayed))return lastFrameTime=0,setTimeout(this.exec.bind(this),500),CABLES.UI&&$("#delayed").show(),void(wasdelayed=!0);(this._renderOneFrame||0===this.config.fpsLimit||i>frameInterval||wasdelayed)&&(this.renderFrame(),frameInterval&&(frameNext=e-i%frameInterval),lastFrameTime=CABLES.now()),wasdelayed&&(CABLES.UI&&$("#delayed").hide(),wasdelayed=!1),this._renderOneFrame&&this.onOneFrameRendered&&(this.onOneFrameRendered(),this._renderOneFrame=!1),requestAnimationFrame(this.exec.bind(this))}},CABLES.Patch.prototype.link=function(t,e,i,r){if(t&&i){var s=t.getPort(e),n=i.getPort(r);if(!s)return void console.warn("port not found! "+e);if(!n)return void console.warn("port not found! "+r+" of "+i.name);if(!s.shouldLink(s,n)||!n.shouldLink(s,n))return!1;if(CABLES.Link.canLink(s,n)){var o=new CABLES.Link(this);return o.link(s,n),this.onLink(s,n),o}}},CABLES.Patch.prototype.onAdd=function(t){},CABLES.Patch.prototype.onDelete=function(t){},CABLES.Patch.prototype.onLink=function(t,e){},CABLES.Patch.prototype.onUnLink=function(t,e){},CABLES.Patch.prototype.serialize=function(t){var e={};e.ops=[],e.settings=this.settings;for(var i in this.ops)e.ops.push(this.ops[i].getSerialized());return t?e:JSON.stringify(e)},CABLES.Patch.prototype.getOpById=function(t){for(var e in this.ops)if(this.ops[e].id==t)return this.ops[e]},CABLES.Patch.prototype.getOpsByName=function(t){var e=[];for(var i in this.ops)this.ops[i].name==t&&e.push(this.ops[i]);return e},CABLES.Patch.prototype.getOpsByObjName=function(t){var e=[];for(var i in this.ops)this.ops[i].objName==t&&e.push(this.ops[i]);return e},CABLES.Patch.prototype.loadLib=function(t){CABLES.ajaxSync("/ui/libs/"+t+".js",function(t,e){var i=document.createElement("script");i.type="text/javascript",i.text=e,document.getElementsByTagName("head")[0].appendChild(i)},"GET")},CABLES.Patch.prototype.reloadOp=function(t,e){var i=0,r=[];for(var s in this.ops)if(this.ops[s].objName==t){i++;var n=this.ops[s];n.deleted=!0;var o=this,a=this.addOp(t,n.uiAttribs);r.push(a);var h,l;for(h in n.portsIn)if(0===n.portsIn[h].links.length)a.getPort(n.portsIn[h].name).set(n.portsIn[h].get());else for(;n.portsIn[h].links.length;){var u=n.portsIn[h].links[0].portIn.name,c=n.portsIn[h].links[0].portOut.name,g=n.portsIn[h].links[0].portOut.parent;n.portsIn[h].links[0].remove(),l=o.link(a,u,g,c),l.setValue()}for(h in n.portsOut)for(;n.portsOut[h].links.length;){var p=n.portsOut[h].links[0].portOut.name,d=n.portsOut[h].links[0].portIn.name,f=n.portsOut[h].links[0].portIn.parent;n.portsOut[h].links[0].remove(),l=o.link(a,p,f,d),l.setValue()}this.deleteOp(n.id)}e(i,r)},CABLES.Patch.prototype.getSubPatchOps=function(t){var e=[];for(var i in this.ops)this.ops[i].uiAttribs&&this.ops[i].uiAttribs.subPatch==t&&e.push(this.ops[i]);return e},CABLES.Patch.prototype.getSubPatchOp=function(t,e){for(var i in this.ops)if(this.ops[i].uiAttribs&&this.ops[i].uiAttribs.subPatch==t&&this.ops[i].objName==e)return this.ops[i];return!1},CABLES.Patch.prototype.deSerialize=function(t,e){function i(t,e,i,r){var s=!1;s||n.link(n.getOpById(t),i,n.getOpById(e),r)}if(!this.aborted){var r=this.loading.start("core","deserialize");this.onLoadStart&&this.onLoadStart();var s=null;CABLES.StopWatch&&(s=new CABLES.StopWatch("deserialize")),"string"==typeof t&&(t=JSON.parse(t));var n=this;s&&s.stop("jsonparse"),this.settings=t.settings,s&&s.stop("add ops..");var o=new CABLES.Requirements(this);for(var a in t.ops){var h=CABLES.now(),l=this.addOp(t.ops[a].objName,t.ops[a].uiAttribs);if(o.checkOp(l),l){l.id=t.ops[a].id,e&&(l.id=CABLES.generateUUID());for(var u in t.ops[a].portsIn){var c=t.ops[a].portsIn[u],g=l.getPort(c.name);if(!g||"bool"!=g.uiAttribs.display&&"bool"!=g.uiAttribs.type||isNaN(c.value)||(c.value=!0===c.value),g&&void 0!==c.value&&g.type!=OP_PORT_TYPE_TEXTURE&&g.set(c.value),c.animated&&g.setAnimated(c.animated),c.anim){g.anim||(g.anim=new CABLES.TL.Anim),c.anim.loop&&(g.anim.loop=c.anim.loop);for(var p in c.anim.keys)g.anim.keys.push(new CABLES.TL.Key(c.anim.keys[p]))}}for(var d in t.ops[a].portsOut){var f=l.getPort(t.ops[a].portsOut[d].name);f&&f.type!=OP_PORT_TYPE_TEXTURE&&t.ops[a].portsOut[d].hasOwnProperty("value")&&f.set(t.ops[a].portsOut[d].value)}}var _=Math.round(100*(CABLES.now()-h))/100;_>10&&console.warn("long op init ",t.ops[a].objName,_)}s&&s.stop("onloaded valueset");for(var E in this.ops)this.ops[E].onLoadedValueSet&&(this.ops[E].onLoadedValueSet(),this.ops[E].onLoadedValueSet=null);if(s&&s.stop("create links"),t.ops)for(a=0;a<t.ops.length;a++)if(t.ops[a].portsIn)for(var L=0;L<t.ops[a].portsIn.length;L++)if(t.ops[a].portsIn[L].links)for(var A=0;A<t.ops[a].portsIn[L].links.length;A++)t.ops[a].portsIn[L].links[A]&&i(t.ops[a].portsIn[L].links[A].objIn,t.ops[a].portsIn[L].links[A].objOut,t.ops[a].portsIn[L].links[A].portIn,t.ops[a].portsIn[L].links[A].portOut);s&&s.stop("onloaded");for(var E in this.ops)this.ops[E].onLoaded&&(this.ops[E].onLoaded(),this.ops[E].onLoaded=null);s&&s.stop("finished"),this.loading.finished(r),this.onLoadEnd&&this.onLoadEnd()}},CABLES.Patch.prototype.profile=function(t){this.profiler=new CABLES.Profiler;for(var e in this.ops)this.ops[e].profile(t)},CABLES.Patch.Variable=function(t,e){this._name=t,this._changeListeners=[],this.setValue(e)},CABLES.Patch.Variable.prototype.getValue=function(){return this._v},CABLES.Patch.Variable.prototype.getName=function(){return this._name},CABLES.Patch.Variable.prototype.setValue=function(t){this._v=t;for(var e=0;e<this._changeListeners.length;e++)this._changeListeners[e](t)},CABLES.Patch.Variable.prototype.addListener=function(t){this._changeListeners.push(t)},CABLES.Patch.Variable.prototype.removeListener=function(t){var e=this._changeListeners.indexOf(t);this._changeListeners.splice(e,1)},CABLES.Patch.prototype.addVariableListener=function(t){this._variableListeners.push(t)},CABLES.Patch.prototype._callVariableListener=function(t){for(var e=0;e<this._variableListeners.length;e++)this._variableListeners[e]()},CABLES.Patch.prototype.setVarValue=function(t,e){return this._variables.hasOwnProperty(t)?this._variables[t].setValue(e):(this._variables[t]=new CABLES.Patch.Variable(t,e),this._callVariableListener()),this._variables[t]},CABLES.Patch.prototype.getVarValue=function(t,e){return this._variables.hasOwnProperty(t)?this._variables[t].getValue():void 0},CABLES.Patch.prototype.getVar=function(t,e){return this._variables.hasOwnProperty(t)?this._variables[t]:void 0},CABLES.Patch.prototype.getVars=function(){return this._variables};var PORT_DIR_IN=0,PORT_DIR_OUT=1,CABLES=CABLES||{};CABLES.Port=function(t,e,i,r){this.data={},this.direction=PORT_DIR_IN,this.id=CABLES.generateUUID(),this.parent=t,this.links=[],this.value=0,this.name=e,this.type=i||OP_PORT_TYPE_VALUE,this.uiAttribs=r||{},this.anim=null;this.onLink=null,this.defaultValue=null,this._uiActiveState=!0,this.ignoreValueSerialize=!1,this.onLinkChanged=null,this.crashed=!0,this._valueBeforeLink=null,this._lastAnimFrame=-1,this._animated=!1,this.onValueChanged=null,this.onTriggered=null,this.onUiActiveStateChange=null,this.changeAlways=!1,this._warnedDeprecated=!1,this.onUiAttrChange=null,Object.defineProperty(this,"val",{get:function(){return this._warnedDeprecated=!0,this.get()},set:function(t){this.setValue(t),this._warnedDeprecated=!0}})},CABLES.Port.prototype.onAnimToggle=function(){},CABLES.Port.prototype._onAnimToggle=function(){this.onAnimToggle()},CABLES.Port.prototype.hidePort=function(){this.setUiAttribs({hidePort:!0})},CABLES.Port.prototype.setUiAttribs=function(t){this.uiAttribs||(this.uiAttribs={});for(var e in t)this.uiAttribs[e]=t[e];this.onUiAttrChange&&this.onUiAttrChange(t)},CABLES.Port.prototype.get=function(){return this._animated&&this._lastAnimFrame!=this.parent.patch.getFrameNum()&&(this._lastAnimFrame=this.parent.patch.getFrameNum(),this.value=this.anim.getValue(this.parent.patch.timer.getTime()),oldAnimVal=this.value,this.forceChange()),this.value},CABLES.Port.prototype.set=CABLES.Port.prototype.setValue=function(t){if(void 0!==t&&this.parent.enabled&&(t!=this.value||this.changeAlways||this.type==OP_PORT_TYPE_TEXTURE||this.type==OP_PORT_TYPE_ARRAY)){if(this._animated)this.anim.setValue(this.parent.patch.timer.getTime(),t);else try{this.value=t,this.forceChange()}catch(e){this.crashed=!0,this.setValue=function(t){},this.onTriggered=function(){},console.log("exception!"),console.error("onvaluechanged exception cought",e),console.log(e.stack),console.log("exception in: "+this.parent.name),CABLES.UI&&CABLES.UI.MODAL.showException(e,this.parent)}if(this.direction==PORT_DIR_OUT)for(var i=0;i<this.links.length;++i)this.links[i].setValue()}},CABLES.Port.prototype.updateAnim=function(){this._animated&&(this.value=this.get(),(oldAnimVal!=this.value||this.changeAlways)&&(oldAnimVal=this.value,this.forceChange()),oldAnimVal=this.value)},CABLES.Port.prototype.forceChange=function(){this.onChange?this.onChange(this,this.value):this.onValueChanged&&this.onValueChanged(this,this.value)},CABLES.Port.prototype.getTypeString=function(){return this.type==OP_PORT_TYPE_VALUE?"Value":this.type==OP_PORT_TYPE_FUNCTION?"Function":this.type==OP_PORT_TYPE_OBJECT?"Object":this.type==OP_PORT_TYPE_DYNAMIC?"Dynamic":this.type==OP_PORT_TYPE_ARRAY?"Array":"Unknown"},CABLES.Port.prototype.getSerialized=function(){var t={};if(t.name=this.getName(),this.ignoreValueSerialize||0!==this.links.length||(t.value=this.value),this._animated&&(t.animated=!0),this.anim&&(t.anim=this.anim.getSerialized()),this.direction==PORT_DIR_IN&&this.links.length>0){t.links=[];for(var e in this.links)this.links[e].portIn&&this.links[e].portOut&&t.links.push(this.links[e].getSerialized())}return t},CABLES.Port.prototype.shouldLink=function(){return!0},CABLES.Port.prototype.removeLinks=function(){for(;this.links.length>0;)this.links[0].remove()},CABLES.Port.prototype.removeLink=function(t){for(var e in this.links)this.links[e]==t&&this.links.splice(e,1);this.direction==PORT_DIR_IN&&this.setValue(this.type==OP_PORT_TYPE_VALUE?this._valueBeforeLink||0:this._valueBeforeLink||null),this.onLinkChanged&&this.onLinkChanged()},CABLES.Port.prototype.getName=function(){return this.name},CABLES.Port.prototype.addLink=function(t){this._valueBeforeLink=this.value,this.links.push(t),this.onLinkChanged&&this.onLinkChanged()},CABLES.Port.prototype.getLinkTo=function(t){for(var e in this.links)if(this.links[e].portIn==t||this.links[e].portOut==t)return this.links[e]},CABLES.Port.prototype.removeLinkTo=function(t){for(var e in this.links)if(this.links[e].portIn==t||this.links[e].portOut==t)return this.links[e].remove(),void(this.onLinkChanged&&this.onLinkChanged())},CABLES.Port.prototype.isLinkedTo=function(t){for(var e in this.links)if(this.links[e].portIn==t||this.links[e].portOut==t)return!0;return!1},CABLES.Port.prototype.trigger=function(){if(0!==this.links.length&&this.parent.enabled)try{for(var t=0;t<this.links.length;++t)this.links[t].portIn&&this.links[t].portIn._onTriggered(),this.links[t].activity()}catch(e){this.parent.enabled=!1,CABLES.UI&&CABLES.UI.MODAL.showException(e,this.parent),console.log("exception!"),console.error("ontriggered exception cought",e),console.log(e.stack),console.log("exception in: "+this.parent.name)}},CABLES.Port.prototype.call=function(){console.log("call deprecated - use trigger() "),this.trigger()},CABLES.Port.prototype.execute=function(){console.log("### execute port: "+this.getName(),this.goals.length)},CABLES.Port.prototype.setAnimated=function(t){this._animated!=t&&(this._animated=t,this._animated&&!this.anim&&(this.anim=new CABLES.TL.Anim),this._onAnimToggle())},CABLES.Port.prototype.toggleAnim=function(t){this._animated=!this._animated,this._animated&&!this.anim&&(this.anim=new CABLES.TL.Anim),this.setAnimated(this._animated),this._onAnimToggle()},CABLES.Port.prototype.getType=function(){return this.type},CABLES.Port.prototype.isLinked=function(){return this.links.length>0},CABLES.Port.prototype.isAnimated=function(){return this._animated},CABLES.Port.prototype._onTriggered=function(){this.parent.updateAnims(),this.parent.enabled&&this.onTriggered&&this.onTriggered()},CABLES.Port.prototype._onTriggeredProfiling=function(){this.parent.updateAnims(),this.parent.patch.profiler.add("port",this),this.parent.enabled&&this.onTriggered&&this.onTriggered(),this.parent.patch.profiler.add("port",null)},CABLES.Port.prototype.onValueChange=function(t){this.onChange=t},CABLES.Port.prototype.getUiActiveState=function(){return this._uiActiveState},CABLES.Port.prototype.setUiActiveState=function(t){_uiActiveState=t,this.onUiActiveStateChange&&this.onUiActiveStateChange()};var Port=CABLES.Port;CABLES=CABLES||{},CABLES.Profiler=function(){var t={},e=null,i=0;this.getItems=function(){return t},this.clear=function(){t={}},this.add=function(r,s){null!==e&&(s&&s.id==e||t[e]&&(t[e].timeUsed+=performance.now()-i,(!t[e].peakTime||CABLES.now()-t[e].peakTime>5e3)&&(t[e].peak>1&&s&&console.log("PEAK ",s.parent.objName),t[e].peak=0,t[e].peakTime=CABLES.now()),t[e].peak=Math.max(t[e].peak,performance.now()-i))),null!==s?(t[s.id]||(t[s.id]={numTriggers:0,timeUsed:0}),t[s.id].numTriggers++,t[s.id].title=s.parent.name+" "+s.name,e=s.id,i=performance.now()):e=null},this.print=function(){console.log("--------");for(var e in t)console.log(t[e].title+": "+t[e].numTriggers+" / "+t[e].timeUsed)}},CABLES=CABLES||{},CABLES.EMBED=CABLES.EMBED||{},CABLES.EMBED.addPatch=function(t,e){var i=t,r=CABLES.generateUUID();if("string"==typeof t&&(r=t,i=document.getElementById(r),!i))return void console.error(r+" Polyshape Container Element not found!");var s=document.createElement("canvas");return s.id="glcanvas_"+r,s.width=i.clientWidth,s.height=i.clientHeight,window.addEventListener("resize",function(){this.setAttribute("width",i.clientWidth),this.height=i.clientHeight}.bind(s)),i.appendChild(s),e=e||{},e.glCanvasId=s.id,e.onError||(e.onError=function(t){console.log(t)}),CABLES.patch=new CABLES.Patch(e),s};var CABLES=CABLES||{};CABLES.Instancing=function(){this._loops=[],this._indizes=[],this._index=0},CABLES.Instancing.prototype.pushLoop=function(t){this._loops.push(Math.abs(Math.floor(t))),this._indizes.push(this._index)},CABLES.Instancing.prototype.popLoop=function(){this._loops.pop(),this._index=this._indizes.pop(),0===this._loops.length&&(this._index=0)},CABLES.Instancing.prototype.numLoops=function(){return this._loops.length},CABLES.Instancing.prototype.numCycles=function(){if(0===this._loops.length)return 0;for(var t=this._loops[0],e=1;e<this._loops.length;e++)t*=this._loops[e];return t},CABLES.Instancing.prototype.inLoop=function(){return this._loops.length>0},CABLES.Instancing.prototype.increment=function(){this._index++},CABLES.Instancing.prototype.index=function(){return this._index};var CABLES=CABLES||{};CABLES.TL=CABLES.TL||{},CABLES.TL.EASING_LINEAR=0,CABLES.TL.EASING_ABSOLUTE=1,CABLES.TL.EASING_SMOOTHSTEP=2,CABLES.TL.EASING_SMOOTHERSTEP=3,CABLES.TL.EASING_BEZIER=4,CABLES.TL.EASING_CUBIC_IN=5,CABLES.TL.EASING_CUBIC_OUT=6,CABLES.TL.EASING_CUBIC_INOUT=7,CABLES.TL.EASING_EXPO_IN=8,CABLES.TL.EASING_EXPO_OUT=9,CABLES.TL.EASING_EXPO_INOUT=10,CABLES.TL.EASING_SIN_IN=11,CABLES.TL.EASING_SIN_OUT=12,CABLES.TL.EASING_SIN_INOUT=13,CABLES.TL.EASING_BACK_IN=14,CABLES.TL.EASING_BACK_OUT=15,CABLES.TL.EASING_BACK_INOUT=16,CABLES.TL.EASING_ELASTIC_IN=17,CABLES.TL.EASING_ELASTIC_OUT=18,CABLES.TL.EASING_BOUNCE_IN=19,CABLES.TL.EASING_BOUNCE_OUT=21,CABLES.TL.EASING_QUART_IN=22,CABLES.TL.EASING_QUART_OUT=23,CABLES.TL.EASING_QUART_INOUT=24,CABLES.TL.EASING_QUINT_IN=25,CABLES.TL.EASING_QUINT_OUT=26,CABLES.TL.EASING_QUINT_INOUT=27,CABLES.TL.Key=function(t){this.time=0,this.value=0,this.ui={},this.onChange=null,this._easing=0,this.bezTime=.5,this.bezValue=0,this.bezTimeIn=-.5,this.bezValueIn=0,this.cb=null,this.cbTriggered=!1;this.setEasing(CABLES.TL.EASING_LINEAR),this.set(t)},CABLES.TL.Key.linear=function(t,e,i){return parseFloat(e.value)+parseFloat(i.value-e.value)*t},CABLES.TL.Key.easeLinear=function(t,e){return CABLES.TL.Key.linear(t,this,e)},CABLES.TL.Key.easeAbsolute=function(t,e){return this.value},CABLES.TL.Key.easeExpoIn=function(t,e){return t=Math.pow(2,10*(t-1)),CABLES.TL.Key.linear(t,this,e)},CABLES.TL.Key.easeExpoOut=function(t,e){return t=-Math.pow(2,-10*t)+1,CABLES.TL.Key.linear(t,this,e)},CABLES.TL.Key.easeExpoInOut=function(t,e){return t*=2,1>t?t=.5*Math.pow(2,10*(t-1)):(t--,t=.5*(-Math.pow(2,-10*t)+2)),CABLES.TL.Key.linear(t,this,e)},CABLES.TL.Key.easeSinIn=function(t,e){return t=-1*Math.cos(t*Math.PI/2)+1,CABLES.TL.Key.linear(t,this,e)},CABLES.TL.Key.easeSinOut=function(t,e){return t=Math.sin(t*Math.PI/2),CABLES.TL.Key.linear(t,this,e)},CABLES.TL.Key.easeSinInOut=function(t,e){return t=-.5*(Math.cos(Math.PI*t)-1),CABLES.TL.Key.linear(t,this,e)},CABLES.TL.Key.easeCubicIn=function(t,e){return t=t*t*t,CABLES.TL.Key.linear(t,this,e)},CABLES.TL.Key.easeInQuint=function(t,e){return t=t*t*t*t*t,CABLES.TL.Key.linear(t,this,e)},CABLES.TL.Key.easeOutQuint=function(t,e){return t=(t-=1)*t*t*t*t+1,CABLES.TL.Key.linear(t,this,e)},CABLES.TL.Key.easeInOutQuint=function(t,e){return t=(t/=.5)<1?.5*t*t*t*t*t:.5*((t-=2)*t*t*t*t+2),CABLES.TL.Key.linear(t,this,e)},CABLES.TL.Key.easeInQuart=function(t,e){return t=t*t*t*t,CABLES.TL.Key.linear(t,this,e)},CABLES.TL.Key.easeOutQuart=function(t,e){return t=-1*((t-=1)*t*t*t-1),CABLES.TL.Key.linear(t,this,e)},CABLES.TL.Key.easeInOutQuart=function(t,e){return t=(t/=.5)<1?.5*t*t*t*t:-.5*((t-=2)*t*t*t-2),CABLES.TL.Key.linear(t,this,e)},CABLES.TL.Key.bounce=function(t){return t=(t/=1)<1/2.75?7.5625*t*t:2/2.75>t?7.5625*(t-=1.5/2.75)*t+.75:2.5/2.75>t?7.5625*(t-=2.25/2.75)*t+.9375:7.5625*(t-=2.625/2.75)*t+.984375},CABLES.TL.Key.easeInBounce=function(t,e){return CABLES.TL.Key.linear(CABLES.TL.Key.bounce(t),this,e)},CABLES.TL.Key.easeOutBounce=function(t,e){return CABLES.TL.Key.linear(CABLES.TL.Key.bounce(t),this,e)},CABLES.TL.Key.easeInElastic=function(t,e){var i=1.70158,r=0,s=1,n=0,o=1,a=1;return 0===t?t=n:1==(t/=o)?t=n+a:(r||(r=.3*o),s<Math.abs(a)?(s=a,i=r/4):i=r/(2*Math.PI)*Math.asin(a/s),t=-(s*Math.pow(2,10*(t-=1))*Math.sin(2*(t*o-i)*Math.PI/r))+n),CABLES.TL.Key.linear(t,this,e)},CABLES.TL.Key.easeOutElastic=function(t,e){var i=1.70158,r=0,s=1,n=0,o=1,a=1;return 0===t?t=n:1==(t/=o)?t=n+a:(r||(r=.3*o),s<Math.abs(a)?(s=a,i=r/4):i=r/(2*Math.PI)*Math.asin(a/s),t=s*Math.pow(2,-10*t)*Math.sin(2*(t*o-i)*Math.PI/r)+a+n),CABLES.TL.Key.linear(t,this,e)},CABLES.TL.Key.easeInBack=function(t,e){var i=1.70158;return t=t*t*((i+1)*t-i),CABLES.TL.Key.linear(t,this,e)},CABLES.TL.Key.easeOutBack=function(t,e){var i=1.70158;return t=(t=t/1-1)*t*((i+1)*t+i)+1,CABLES.TL.Key.linear(t,this,e)},CABLES.TL.Key.easeInOutBack=function(t,e){var i=1.70158,r=.5;return t=(t/=.5)<1?r*t*t*(((i*=1.525)+1)*t-i):r*((t-=2)*t*(((i*=1.525)+1)*t+i)+2),CABLES.TL.Key.linear(t,this,e)},CABLES.TL.Key.easeCubicOut=function(t,e){return t--,t=t*t*t+1,CABLES.TL.Key.linear(t,this,e)},CABLES.TL.Key.easeCubicInOut=function(t,e){return t*=2,1>t?t=.5*t*t*t:(t-=2,t=.5*(t*t*t+2)),CABLES.TL.Key.linear(t,this,e)},CABLES.TL.Key.easeSmoothStep=function(t,e){var i=Math.max(0,Math.min(1,t));return t=i*i*(3-2*i),CABLES.TL.Key.linear(t,this,e)},CABLES.TL.Key.easeSmootherStep=function(t,e){var i=Math.max(0,Math.min(1,(t-0)/1));return t=i*i*i*(i*(6*i-15)+10),CABLES.TL.Key.linear(t,this,e)},CABLES.TL.Key.prototype.setEasing=function(t){this._easing=t,this._easing==CABLES.TL.EASING_ABSOLUTE?this.ease=CABLES.TL.Key.easeAbsolute:this._easing==CABLES.TL.EASING_SMOOTHSTEP?this.ease=CABLES.TL.Key.easeSmoothStep:this._easing==CABLES.TL.EASING_SMOOTHERSTEP?this.ease=CABLES.TL.Key.easeSmootherStep:this._easing==CABLES.TL.EASING_CUBIC_IN?this.ease=CABLES.TL.Key.easeCubicIn:this._easing==CABLES.TL.EASING_CUBIC_OUT?this.ease=CABLES.TL.Key.easeCubicOut:this._easing==CABLES.TL.EASING_CUBIC_INOUT?this.ease=CABLES.TL.Key.easeCubicInOut:this._easing==CABLES.TL.EASING_EXPO_IN?this.ease=CABLES.TL.Key.easeExpoIn:this._easing==CABLES.TL.EASING_EXPO_OUT?this.ease=CABLES.TL.Key.easeExpoOut:this._easing==CABLES.TL.EASING_EXPO_INOUT?this.ease=CABLES.TL.Key.easeExpoInOut:this._easing==CABLES.TL.EASING_SIN_IN?this.ease=CABLES.TL.Key.easeSinIn:this._easing==CABLES.TL.EASING_SIN_OUT?this.ease=CABLES.TL.Key.easeSinOut:this._easing==CABLES.TL.EASING_SIN_INOUT?this.ease=CABLES.TL.Key.easeSinInOut:this._easing==CABLES.TL.EASING_BACK_OUT?this.ease=CABLES.TL.Key.easeOutBack:this._easing==CABLES.TL.EASING_BACK_IN?this.ease=CABLES.TL.Key.easeInBack:this._easing==CABLES.TL.EASING_BACK_INOUT?this.ease=CABLES.TL.Key.easeInOutBack:this._easing==CABLES.TL.EASING_ELASTIC_IN?this.ease=CABLES.TL.Key.easeInElastic:this._easing==CABLES.TL.EASING_ELASTIC_OUT?this.ease=CABLES.TL.Key.easeOutElastic:this._easing==CABLES.TL.EASING_BOUNCE_IN?this.ease=CABLES.TL.Key.easeInBounce:this._easing==CABLES.TL.EASING_BOUNCE_OUT?this.ease=CABLES.TL.Key.easeOutBounce:this._easing==CABLES.TL.EASING_QUART_OUT?this.ease=CABLES.TL.Key.easeOutQuart:this._easing==CABLES.TL.EASING_QUART_IN?this.ease=CABLES.TL.Key.easeInQuart:this._easing==CABLES.TL.EASING_QUART_INOUT?this.ease=CABLES.TL.Key.easeInOutQuart:this._easing==CABLES.TL.EASING_QUINT_OUT?this.ease=CABLES.TL.Key.easeOutQuint:this._easing==CABLES.TL.EASING_QUINT_IN?this.ease=CABLES.TL.Key.easeInQuint:this._easing==CABLES.TL.EASING_QUINT_INOUT?this.ease=CABLES.TL.Key.easeInOutQuint:this._easing==CABLES.TL.EASING_BEZIER?(updateBezier=!0,this.ease=CABLES.TL.Key.easeBezier):(this._easing=CABLES.TL.EASING_LINEAR,this.ease=CABLES.TL.Key.easeLinear)},CABLES.TL.Key.prototype.trigger=function(){this.cb(),this.cbTriggered=!0},CABLES.TL.Key.prototype.setValue=function(t){this.value=t,updateBezier=!0,null!==this.onChange&&this.onChange()},CABLES.TL.Key.prototype.set=function(t){t&&(t.e&&this.setEasing(t.e),t.cb&&(this.cb=t.cb,this.cbTriggered=!1),t.b&&(this.bezTime=t.b[0],this.bezValue=t.b[1],this.bezTimeIn=t.b[2],this.bezValueIn=t.b[3],updateBezier=!0),t.hasOwnProperty("t")&&(this.time=t.t),t.hasOwnProperty("time")&&(this.time=t.time),t.hasOwnProperty("v")?this.value=t.v:t.hasOwnProperty("value")&&(this.value=t.value)),null!==this.onChange&&this.onChange()},CABLES.TL.Key.prototype.getSerialized=function(){var t={};return t.t=this.time,t.v=this.value,t.e=this._easing,this._easing==CABLES.TL.EASING_BEZIER&&(t.b=[this.bezTime,this.bezValue,this.bezTimeIn,this.bezValueIn]),t},CABLES.TL.Key.prototype.getEasing=function(){return this._easing},CABLES.TL.Anim=function(t){this.keys=[],this.onChange=null,this.stayInTimeline=!1,this.loop=!1,this.defaultEasing=CABLES.TL.EASING_LINEAR,this.onLooped=null,this._timesLooped=0,this._needsSort=!1},CABLES.TL.Anim.prototype.hasEnded=function(t){return 0===this.keys.length?!0:this.keys[this.keys.length-1].time<=t?!0:!1},CABLES.TL.Anim.prototype.isRising=function(t){if(this.hasEnded(t))return!1;var e=this.getKeyIndex(t);return this.keys[e].value<this.keys[e+1].value?!0:!1},CABLES.TL.Anim.prototype.clear=function(t){var e=0;t&&(e=this.getValue(t)),this.keys.length=0,t&&this.setValue(t,e)},CABLES.TL.Anim.prototype.sortKeys=function(){this.keys.sort(function(t,e){return parseFloat(t.time)-parseFloat(e.time)}),this._needsSort=!1},CABLES.TL.Anim.prototype.getLength=function(){return 0===this.keys.length?0:this.keys[this.keys.length-1].time},CABLES.TL.Anim.prototype.getKeyIndex=function(t){for(var e=0,i=0;i<this.keys.length;i++)if(t>=this.keys[i].time&&(e=i),this.keys[i].time>t)return e;return e},CABLES.TL.Anim.prototype.setValue=function(t,e,i){var r=!1;for(var s in this.keys)if(this.keys[s].time==t){r=this.keys[s],this.keys[s].setValue(e),this.keys[s].cb=i;break}r||this.keys.push(new CABLES.TL.Key({time:t,value:e,e:this.defaultEasing,cb:i})),this.onChange&&this.onChange(),this._needsSort=!0},CABLES.TL.Anim.prototype.getSerialized=function(){var t={};t.keys=[],t.loop=this.loop;for(var e in this.keys)t.keys.push(this.keys[e].getSerialized());return t},CABLES.TL.Anim.prototype.getKey=function(t){var e=this.getKeyIndex(t);return this.keys[e]},CABLES.TL.Anim.prototype.getNextKey=function(t){var e=this.getKeyIndex(t)+1;return e>=this.keys.length&&(e=this.keys.length-1),this.keys[e]},CABLES.TL.Anim.prototype.isFinished=function(t){return this.keys.length<=0?!0:t>this.keys[this.keys.length-1].time},CABLES.TL.Anim.prototype.isStarted=function(t){return this.keys.length<=0?!1:t>=this.keys[0].time},CABLES.TL.Anim.prototype.getValue=function(t){if(0===this.keys.length)return 0;if(this._needsSort&&this.sortKeys(),t<this.keys[0].time)return this.keys[0].value;var e=this.keys.length-1;if(this.loop&&t>this.keys[e].time){var i=t/this.keys[e].time;i>this._timesLooped&&(this._timesLooped++,this.onLooped&&this.onLooped()),t=(t-this.keys[0].time)%(this.keys[e].time-this.keys[0].time),t+=this.keys[0].time}var r=this.getKeyIndex(t);if(r>=e)return this.keys[e].cb&&!this.keys[e].cbTriggered&&this.keys[e].trigger(),this.keys[e].value;var s=parseInt(r,10)+1,n=this.keys[r],o=this.keys[s];if(n.cb&&!n.cbTriggered&&n.trigger(),!o)return-1;var a=(t-n.time)/(o.time-n.time);return n.ease(a,o)},CABLES.TL.Anim.prototype.addKey=function(t){void 0===t.time?console.log("key time undefined, ignoring!"):this.keys.push(t)},CABLES.TL.Anim.prototype.easingFromString=function(t){return"linear"==t?CABLES.TL.EASING_LINEAR:"absolute"==t?CABLES.TL.EASING_ABSOLUTE:"smoothstep"==t?CABLES.TL.EASING_SMOOTHSTEP:"smootherstep"==t?CABLES.TL.EASING_SMOOTHERSTEP:"Cubic In"==t?CABLES.TL.EASING_CUBIC_IN:"Cubic Out"==t?CABLES.TL.EASING_CUBIC_OUT:"Cubic In Out"==t?CABLES.TL.EASING_CUBIC_INOUT:"Expo In"==t?CABLES.TL.EASING_EXPO_IN:"Expo Out"==t?CABLES.TL.EASING_EXPO_OUT:"Expo In Out"==t?CABLES.TL.EASING_EXPO_INOUT:"Sin In"==t?CABLES.TL.EASING_SIN_IN:"Sin Out"==t?CABLES.TL.EASING_SIN_OUT:"Sin In Out"==t?CABLES.TL.EASING_SIN_INOUT:"Back In"==t?CABLES.TL.EASING_BACK_IN:"Back Out"==t?CABLES.TL.EASING_BACK_OUT:"Back In Out"==t?CABLES.TL.EASING_BACK_INOUT:"Elastic In"==t?CABLES.TL.EASING_ELASTIC_IN:"Elastic Out"==t?CABLES.TL.EASING_ELASTIC_OUT:"Bounce In"==t?CABLES.TL.EASING_BOUNCE_IN:"Bounce Out"==t?CABLES.TL.EASING_BOUNCE_OUT:"Quart Out"==t?CABLES.TL.EASING_QUART_OUT:"Quart In"==t?CABLES.TL.EASING_QUART_IN:"Quart In Out"==t?CABLES.TL.EASING_QUART_INOUT:"Quint Out"==t?CABLES.TL.EASING_QUINT_OUT:"Quint In"==t?CABLES.TL.EASING_QUINT_IN:"Quint In Out"==t?CABLES.TL.EASING_QUINT_INOUT:void 0;
|
|
|
|
},CABLES.TL.Anim.prototype.createPort=function(t,e,i){var r=t.addInPort(new Port(t,e,OP_PORT_TYPE_VALUE,{display:"dropdown",values:["linear","absolute","smoothstep","smootherstep","Cubic In","Cubic Out","Cubic In Out","Expo In","Expo Out","Expo In Out","Sin In","Sin Out","Sin In Out","Quart In","Quart Out","Quart In Out","Quint In","Quint Out","Quint In Out","Back In","Back Out","Back In Out","Elastic In","Elastic Out","Elastic In Out","Bounce In","Bounce Out"]}));return r.set("linear"),r.defaultValue="linear",r.onChange=function(){this.defaultEasing=this.easingFromString(r.get()),i&&i()}.bind(this),r},CABLES.TL.Anim.slerpQuaternion=function(t,e,i,r,s,n){CABLES.TL.Anim.slerpQuaternion.q1||(CABLES.TL.Anim.slerpQuaternion.q1=quat.create(),CABLES.TL.Anim.slerpQuaternion.q2=quat.create());var o=i.getKeyIndex(t),a=parseInt(i.getKeyIndex(t))+1;if(a>=i.keys.length&&(a=i.keys.length-1),o==a)quat.set(e,i.keys[o].value,r.keys[o].value,s.keys[o].value,n.keys[o].value);else{var h=i.keys[o].time,l=i.keys[a].time,u=(t-h)/(l-h);quat.set(CABLES.TL.Anim.slerpQuaternion.q1,i.keys[o].value,r.keys[o].value,s.keys[o].value,n.keys[o].value),quat.set(CABLES.TL.Anim.slerpQuaternion.q2,i.keys[a].value,r.keys[a].value,s.keys[a].value,n.keys[a].value),quat.slerp(e,CABLES.TL.Anim.slerpQuaternion.q1,CABLES.TL.Anim.slerpQuaternion.q2,u)}return e},CABLES=CABLES||{},CABLES.InertiaAnim=function(t){this._inVelocity=0,this._lastVal=0,this._lastTime=0,this.value=0,this._cb=t,this.INERTIA_SCROLL_FACTOR=3.5,this.INERTIA_ACCELERATION=.95,this._firstTime=!0,this.bounds=null},CABLES.InertiaAnim.prototype.updateSmooth=function(){this.value+=this._inVelocity*this.INERTIA_SCROLL_FACTOR,this._inVelocity*=this.INERTIA_ACCELERATION,this._cb&&this._cb(this.value),Math.abs(this._inVelocity)<.1&&(clearInterval(this._smoothInterval),this._inVelocity=0)},CABLES.InertiaAnim.prototype.get=function(){return this.value},CABLES.InertiaAnim.prototype.release=function(){clearInterval(this._smoothInterval),this._smoothInterval=setInterval(this.updateSmooth.bind(this),16.7),this._firstTime=!0},CABLES.InertiaAnim.prototype.set=function(t){this._firstTime&&(clearInterval(this._smoothInterval),this.value=t,this._lastTime=CABLES.now(),this._firstTime=!1);var e=t-this.value;this._inVelocity=e/(CABLES.now()-this._lastTime+1e-7),this.value=t,this._cb&&this._cb(this.value),this._lastTime=CABLES.now()},CABLES.LoadingStatus=function(){var t={},e=[],i=0;this.setOnFinishedLoading=function(t){e.push(t)},this.getProgress=function(){return i},this.checkStatus=function(){console.log("--------");var r=0,s=0;for(var n in t)s++,t[n].finished||(r++,console.log(t[n].type+": "+t[n].finished+": "+t[n].name));if(i=(s-r)/s,CGL.onLoadingAssetsFinished&&(console.error("CGL.onLoadingAssetsFinished is deprecated, please use config parameter onFinishedLoading with scene/patch constructor"),setTimeout(e,200)),0===r)for(var o=0;o<e.length;o++)setTimeout(e[o],200)},this.finished=function(e){t[e]&&(t[e].finished=!0),this.checkStatus()},this.start=function(e,i){var r=CABLES.generateUUID();return console.log("start loading",i),t[r]={id:r,type:e,name:i,finished:!1},r}},log=function(){Function.prototype.apply.apply(console.log,[console,arguments])},log.warn=function(){Function.prototype.apply.apply(console.warn,[console,arguments])};var CABLES=CABLES||{};CABLES.PACO_CLEAR=0,CABLES.PACO_VALUECHANGE=1,CABLES.PACO_OP_DELETE=2,CABLES.PACO_UNLINK=3,CABLES.PACO_LINK=4,CABLES.PACO_LOAD=5,CABLES.PACO_OP_CREATE=6,CABLES.PACO_OP_ENABLE=7,CABLES.PACO_OP_DISABLE=8,CABLES.togglePacoRenderer=function(){var t=CABLES.UI.userSettings.get("pacoRenderer")||!1;CABLES.UI.userSettings.set("pacoRenderer",!t),document.location.reload()},CABLES.showPacoRenderer=function(){},CABLES.PatchConnectionReceiver=function(t,e,i){this._patch=t,this.connector=i?i:new CABLES.PatchConnectorBroadcastChannel,this.connector.receive(this)},CABLES.PatchConnectionReceiver.prototype._receive=function(t){var e={};if(e=t.event?t:JSON.parse(t.data),e.event==CABLES.PACO_OP_CREATE){console.log("op create: data.vars.objName");var i=this._patch.addOp(e.vars.objName);i.id=e.vars.opId}else if(e.event==CABLES.PACO_LOAD)console.log("load patch....."),this._patch.clear(),this._patch.deSerialize(e.vars.patch);else if(e.event==CABLES.PACO_CLEAR)this._patch.clear(),console.log("clear");else if(e.event==CABLES.PACO_OP_DELETE)console.log("op delete"),this._patch.deleteOp(e.vars.op,!0);else if(e.event==CABLES.PACO_OP_ENABLE){var i=this._patch.getOpById(e.vars.op);i&&(i.enabled=!0)}else if(e.event==CABLES.PACO_OP_DISABLE){var i=this._patch.getOpById(e.vars.op);i&&(i.enabled=!1)}else if(e.event==CABLES.PACO_UNLINK){var r=this._patch.getOpById(e.vars.op1),s=this._patch.getOpById(e.vars.op2),n=r.getPort(e.vars.port1),o=s.getPort(e.vars.port2);n.removeLinkTo(o)}else if(e.event==CABLES.PACO_LINK){var r=this._patch.getOpById(e.vars.op1),s=this._patch.getOpById(e.vars.op2);this._patch.link(r,e.vars.port1,s,e.vars.port2)}else if(e.event==CABLES.PACO_VALUECHANGE){var i=this._patch.getOpById(e.vars.op),a=i.getPort(e.vars.port);a.set(e.vars.v)}else console.log("unknown patchConnectionEvent!",t)},CABLES.PatchConnectionSender=function(t,e){this.connectors=[],this.connectors.push(new CABLES.PatchConnectorBroadcastChannel)},CABLES.PatchConnectionSender.prototype.send=function(t,e){for(var i=0;i<this.connectors.length;i++)this.connectors[i].send(t,e)},CABLES.PatchConnectorBroadcastChannel=function(){window.BroadcastChannel&&(this.bc=new BroadcastChannel("test_channel"))},CABLES.PatchConnectorBroadcastChannel.prototype.receive=function(t){this.bc&&(console.log("init"),this.bc.onmessage=t._receive.bind(t))},CABLES.PatchConnectorBroadcastChannel.prototype.send=function(t,e){if(this.bc){var i={};i.event=t,i.vars=e,this.bc.postMessage(JSON.stringify(i))}},CABLES.PatchConnectorSocketIO=function(){this._socket=io("localhost:5712"),console.log("socket io paco..."),this._socket.emit("channel",{name:"hund"}),this._socket.on("connect",function(){console.log("CONNECTED")}),this._socket.on("reconnect_error",function(){console.log("reconnect_error")}),this._socket.on("connect_error",function(){console.log("connect_error")}),this._socket.on("error",function(){console.log("socket error")})},CABLES.PatchConnectorSocketIO.prototype.receive=function(t){this._socket.on("event",function(e){console.log("socket io receive",e),t._receive(e.data)})},CABLES.PatchConnectorSocketIO.prototype.send=function(t,e){console.log("send socketio");var i={};i.event=t,i.vars=e,this._socket.emit("event",{msg:"paco event",event:t,data:i})};var CABLES=CABLES||{};CABLES.Requirements=function(t){this._patch=t,this.result=[]},CABLES.Requirements.MIDI=0,CABLES.Requirements.POINTERLOCK=1,CABLES.Requirements.WEBAUDIO=2,CABLES.Requirements.WEBGL2=3,CABLES.Requirements.infos=[],CABLES.Requirements.infos[CABLES.Requirements.POINTERLOCK]={title:"pointerLock",caniuse:"https://caniuse.com/#search=pointerlock"},CABLES.Requirements.infos[CABLES.Requirements.MIDI]={title:"midi API",caniuse:"https://caniuse.com/#search=midi"},CABLES.Requirements.infos[CABLES.Requirements.WEBAUDIO]={title:"web audio",caniuse:"https://caniuse.com/#search=webaudio"},CABLES.Requirements.infos[CABLES.Requirements.WEBGL2]={title:"WebGL 2"},CABLES.Requirements.prototype.checkRequirement=function(t,e){switch(this.result=[],t){case CABLES.Requirements.WEBGL2:return e.patch.cgl.glVersion>=2;case CABLES.Requirements.POINTERLOCK:return"exitPointerLock"in document;case CABLES.Requirements.MIDI:return"MIDIAccess"in window;case CABLES.Requirements.WEBAUDIO:var i=!1;return window.audioContext&&(i=!0),!i&&("webkitAudioContext"in window||"AudioContext"in window)&&(i=!0),i}},CABLES.Requirements.prototype.checkOp=function(t){if(t&&t.requirements)for(var e=0;e<t.requirements.length;e++){var i=t.requirements[e];if(!this.result[i]){var r=this.checkRequirement(i,t);if(!r){t.patch.cgl&&t.patch.cgl.canvas&&t.patch.cgl.canvas.remove();var s=CABLES.Requirements.infos[i].title;throw CABLES.Requirements.infos[i].caniuse&&(s='<a href="'+CABLES.Requirements.infos[i].caniuse+'" target="_blank">'+CABLES.Requirements.infos[i].title+" ("+t.objName+")</a>"),"this browser does not meet requirement: "+CABLES.Requirements.infos[i].title+" ("+t.objName+")"}this.result[i]={success:r,info:CABLES.Requirements.infos[i]}}}};var CABLES=CABLES||{};CABLES.Variable=function(){var t=null,e=[];this.onChanged=function(t){e.push(t)},this.getValue=function(){return t},this.setValue=function(e){t=e,i()};var i=function(){for(var t=0;t<e.length;t++)e[t]()}},window.performance=window.performance||{offset:Date.now(),now:function(){return Date.now()-this.offset}},CABLES.internalNow=function(){return window.performance.now()},CABLES.now=function(){return CABLES.internalNow()},CABLES.Timer=function(){this._timeStart=CABLES.internalNow(),this._timeOffset=0,this._currentTime=0,this._lastTime=0,this._paused=!0,this._delay=0,this._eventsPaused=!1,this.overwriteTime=-1,this.cbPlayPause=[],this.cbTimeChange=[]},CABLES.Timer.prototype._getTime=function(){return this._lastTime=(CABLES.internalNow()-this._timeStart)/1e3,this._lastTime+this._timeOffset},CABLES.Timer.prototype._eventPlayPause=function(){if(!this._eventsPaused)for(var t in this.cbPlayPause)this.cbPlayPause[t]()},CABLES.Timer.prototype._eventTimeChange=function(){if(!this._eventsPaused)for(var t in this.cbTimeChange)this.cbTimeChange[t]()},CABLES.Timer.prototype.setDelay=function(t){this._delay=t,this._eventTimeChange()},CABLES.Timer.prototype.isPlaying=function(){return!this._paused},CABLES.Timer.prototype.update=function(){return this._paused?void 0:(this._currentTime=this._getTime(),this._currentTime)},CABLES.Timer.prototype.getMillis=function(){return 1e3*this.get()},CABLES.Timer.prototype.get=CABLES.Timer.prototype.getTime=function(){return this.overwriteTime>=0?this.overwriteTime-this._delay:this._currentTime-this._delay},CABLES.Timer.prototype.togglePlay=function(){this._paused?this.play():this.pause()},CABLES.Timer.prototype.setTime=function(t){0>t&&(t=0),this._timeStart=CABLES.internalNow(),this._timeOffset=t,this._currentTime=t,this._eventTimeChange()},CABLES.Timer.prototype.setOffset=function(t){this._currentTime+t<0?(this._timeStart=CABLES.internalNow(),this._timeOffset=0,this._currentTime=0):(this._timeOffset+=t,this._currentTime=this._lastTime+this._timeOffset),this._eventTimeChange()},CABLES.Timer.prototype.play=function(){this._timeStart=CABLES.internalNow(),this._paused=!1,this._eventPlayPause()},CABLES.Timer.prototype.pause=function(){this._timeOffset=this._currentTime,this._paused=!0,this._eventPlayPause()},CABLES.Timer.prototype.pauseEvents=function(t){this._eventsPaused=t},CABLES.Timer.prototype.onPlayPause=function(t){t&&"function"==typeof t&&this.cbPlayPause.push(t)},CABLES.Timer.prototype.onTimeChange=function(t){t&&"function"==typeof t&&this.cbTimeChange.push(t)},CABLES=CABLES||{},CABLES.WebAudio=CABLES.WebAudio||{},CABLES.WebAudio.createAudioContext=function(t){return window.AudioContext=window.AudioContext||window.webkitAudioContext,window.AudioContext?(window.audioContext||(window.audioContext=new AudioContext),window.Tone&&!CABLES.WebAudio.toneJsInitialized&&(Tone.setContext(window.audioContext),CABLES.WebAudio.toneJsInitialized=!0)):t.patch.config.onError("NO_WEBAUDIO","Web Audio is not supported in this browser."),window.audioContext},CABLES.WebAudio.createAudioInPort=function(t,e,i,r){if(!t||!e||!i)return void t.log("ERROR: createAudioInPort needs three parameters, op, portName and audioNode");r||(r=0),t.webAudio=t.webAudio||{},t.webAudio.audioInPorts=t.webAudio.audioInPorts||[];var s=t.inObject(e);return s.webAudio={},s.webAudio.previousAudioInNode=null,s.webAudio.audioNode=i,t.webAudio.audioInPorts[e]=s,s.onChange=function(){var e=s.get();if(e)try{e.connect(s.webAudio.audioNode,0,r)}catch(i){t.log("Error: Failed to connect web audio node!",i),t.log("port.webAudio.audioNode",s.webAudio.audioNode),t.log("audioInNode: ",e),t.log("inputChannelIndex:",r),console.log("audioInNode.connect: ",e.connect)}else if(s.webAudio.previousAudioInNode)try{s.webAudio.previousAudioInNode.disconnect(s.webAudio.audioNode,0,r)}catch(i){console.log(i),t.log("Node to call disconnect on: ",s.webAudio.previousAudioInNode),t.log("its disconnect function: ",s.webAudio.previousAudioInNode.disconnect),t.log("Node to disconnect: ",s.webAudio.audioNode),t.log("inputChannelIndex: ",r);try{s.webAudio.previousAudioInNode.disconnect(s.webAudio.audioNode)}catch(i){t.log("Disconnecting without in/out-port-index also did not work ",i)}}s.webAudio.previousAudioInNode=e},s},CABLES.WebAudio.replaceNodeInPort=function(t,e,i){var r=t.webAudio.previousAudioInNode;if(r&&r.disconnect){try{r.disconnect(e)}catch(s){op.log("Warning: Could not disconnect")}t.webAudio.audioNode=i;try{r.connect(i)}catch(s){op.log("Warning: Could not connect to new node")}}},CABLES.WebAudio.createAudioOutPort=function(t,e,i){if(!t||!e||!i)return void t.log("ERROR: createAudioOutPort needs three parameters, op, portName and audioNode");var r=t.outObject(e);return r.set(i),r},CABLES.WebAudio.createAudioParamInPort=function(t,e,i,r,s){if(!t||!e||!i)return t.log("ERROR: createAudioParamInPort needs three parameters, op, portName and audioNode"),t&&t.name&&t.log("opname: ",t.name),t.log("portName",e),void t.log("audioNode: ",i);t.webAudio=t.webAudio||{},t.webAudio.audioInPorts=t.webAudio.audioInPorts||[];var n=t.inDynamic(e,[OP_PORT_TYPE_VALUE,OP_PORT_TYPE_OBJECT],r,s);return n.webAudio={},n.webAudio.previousAudioInNode=null,n.webAudio.audioNode=i,t.webAudio.audioInPorts[e]=n,n.onChange=function(){var e=n.get(),i=n.webAudio.audioNode;if(void 0!=e)if("object"==typeof e&&e.connect){try{e.connect(i)}catch(r){t.log(r)}n.webAudio.previousAudioInNode=e}else{if(i._param&&i._param.minValue&&i._param.maxValue)if(e>=i._param.minValue&&e<=i._param.maxValue)try{i.value=e}catch(r){t.log("Possible AudioParam problem: ",r)}else t.log("Warning: The value for an audio parameter is out of range!");else if(i.minValue&&i.maxValue)if(e>=i.minValue&&e<=i.maxValue)try{i.value=e}catch(r){t.log("Possible AudioParam problem: ",r)}else t.log("Warning: The value for an audio parameter is out of range!");else try{i.value=e}catch(r){t.log("Possible AudioParam problem: ",r)}if(n.webAudio.previousAudioInNode&&n.webAudio.previousAudioInNode.disconnect){try{n.webAudio.previousAudioInNode.disconnect(i)}catch(r){console.log(r)}n.webAudio.previousAudioInNode=void 0}}else n.webAudio.previousAudioInNode},n},CABLES.WebAudio.loadAudioFile=function(t,e,i,r){var s=CABLES.WebAudio.createAudioContext(),n=t.loading.start("audio",e);CABLES.UI&&gui.jobs().start({id:"loadaudio"+n,title:" loading audio ("+e+")"});var o=new XMLHttpRequest;e&&(o.open("GET",e,!0),o.responseType="arraybuffer",o.onload=function(){t.loading.finished(n),CABLES.UI&&gui.jobs().finish("loadaudio"+n),s.decodeAudioData(o.response,i,r)},o.send())},CABLES.WebAudio.isValidToneTime=function(t){try{{new Tone.Time(t)}}catch(e){return!1}return!0},CABLES.WebAudio.isValidToneNote=function(t){try{Tone.Frequency(t)}catch(e){return!1}return!0};
|
|
//# sourceMappingURL=cables.min.js.map
|