-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathgeometryangle.min.js
More file actions
1 lines (1 loc) · 29.8 KB
/
Copy pathgeometryangle.min.js
File metadata and controls
1 lines (1 loc) · 29.8 KB
1
FSS={FRONT:0,BACK:1,DOUBLE:2,SVGNS:"http://www.w3.org/2000/svg"};FSS.Array=typeof Float32Array==="function"?Float32Array:Array;FSS.Utils={isNumber:function(a){return !isNaN(parseFloat(a))&&isFinite(a)}};(function(){var b=0;var c=["ms","moz","webkit","o"];for(var a=0;a<c.length&&!window.requestAnimationFrame;++a){window.requestAnimationFrame=window[c[a]+"RequestAnimationFrame"];window.cancelAnimationFrame=window[c[a]+"CancelAnimationFrame"]||window[c[a]+"CancelRequestAnimationFrame"]}if(!window.requestAnimationFrame){window.requestAnimationFrame=function(h,d){var f=new Date().getTime();var e=Math.max(0,16-(f-b));var g=window.setTimeout(function(){h(f+e)},e);b=f+e;return g}}if(!window.cancelAnimationFrame){window.cancelAnimationFrame=function(d){clearTimeout(d)}}}());Math.PIM2=Math.PI*2;Math.PID2=Math.PI/2;Math.randomInRange=function(b,a){return b+(a-b)*Math.random()};Math.clamp=function(c,b,a){c=Math.max(c,b);c=Math.min(c,a);return c};FSS.Vector3={create:function(a,d,c){var b=new FSS.Array(3);this.set(b,a,d,c);return b},clone:function(c){var b=this.create();this.copy(b,c);return b},set:function(b,a,d,c){b[0]=a||0;b[1]=d||0;b[2]=c||0;return this},setX:function(b,a){b[0]=a||0;return this},setY:function(a,b){a[1]=b||0;return this},setZ:function(a,b){a[2]=b||0;return this},copy:function(c,b){c[0]=b[0];c[1]=b[1];c[2]=b[2];return this},add:function(c,b){c[0]+=b[0];c[1]+=b[1];c[2]+=b[2];return this},addVectors:function(e,d,c){e[0]=d[0]+c[0];e[1]=d[1]+c[1];e[2]=d[2]+c[2];return this},addScalar:function(b,a){b[0]+=a;b[1]+=a;b[2]+=a;return this},subtract:function(c,b){c[0]-=b[0];c[1]-=b[1];c[2]-=b[2];return this},subtractVectors:function(e,d,c){e[0]=d[0]-c[0];e[1]=d[1]-c[1];e[2]=d[2]-c[2];return this},subtractScalar:function(b,a){b[0]-=a;b[1]-=a;b[2]-=a;return this},multiply:function(c,b){c[0]*=b[0];c[1]*=b[1];c[2]*=b[2];return this},multiplyVectors:function(e,d,c){e[0]=d[0]*c[0];e[1]=d[1]*c[1];e[2]=d[2]*c[2];return this},multiplyScalar:function(b,a){b[0]*=a;b[1]*=a;b[2]*=a;return this},divide:function(c,b){c[0]/=b[0];c[1]/=b[1];c[2]/=b[2];return this},divideVectors:function(e,d,c){e[0]=d[0]/c[0];e[1]=d[1]/c[1];e[2]=d[2]/c[2];return this},divideScalar:function(b,a){if(a!==0){b[0]/=a;b[1]/=a;b[2]/=a}else{b[0]=0;b[1]=0;b[2]=0}return this},cross:function(d,c){var b=d[0];var f=d[1];var e=d[2];d[0]=f*c[2]-e*c[1];d[1]=e*c[0]-b*c[2];d[2]=b*c[1]-f*c[0];return this},crossVectors:function(e,d,c){e[0]=d[1]*c[2]-d[2]*c[1];e[1]=d[2]*c[0]-d[0]*c[2];e[2]=d[0]*c[1]-d[1]*c[0];return this},min:function(b,a){if(b[0]<a){b[0]=a}if(b[1]<a){b[1]=a}if(b[2]<a){b[2]=a}return this},max:function(b,a){if(b[0]>a){b[0]=a}if(b[1]>a){b[1]=a}if(b[2]>a){b[2]=a}return this},clamp:function(c,b,a){this.min(c,b);this.max(c,a);return this},limit:function(d,b,a){var c=this.length(d);if(b!==null&&c<b){this.setLength(d,b)}else{if(a!==null&&c>a){this.setLength(d,a)}}return this},dot:function(d,c){return d[0]*c[0]+d[1]*c[1]+d[2]*c[2]},normalise:function(a){return this.divideScalar(a,this.length(a))},negate:function(a){return this.multiplyScalar(a,-1)},distanceSquared:function(f,d){var g=f[0]-d[0];var e=f[1]-d[1];var c=f[2]-d[2];return g*g+e*e+c*c},distance:function(d,c){return Math.sqrt(this.distanceSquared(d,c))},lengthSquared:function(b){return b[0]*b[0]+b[1]*b[1]+b[2]*b[2]},length:function(b){return Math.sqrt(this.lengthSquared(b))},setLength:function(c,a){var b=this.length(c);if(b!==0&&a!==b){this.multiplyScalar(c,a/b)}return this},floor:function(a){a[0]=Math.floor(a[0]);a[1]=Math.floor(a[1]);a[2]=Math.floor(a[2]);return a}};FSS.Vector4={create:function(a,e,d,c){var b=new FSS.Array(4);this.set(b,a,e,d);return b},set:function(c,a,e,d,b){c[0]=a||0;c[1]=e||0;c[2]=d||0;c[3]=b||0;return this},setX:function(b,a){b[0]=a||0;return this},setY:function(a,b){a[1]=b||0;return this},setZ:function(a,b){a[2]=b||0;return this},setW:function(b,a){b[3]=a||0;return this},add:function(c,b){c[0]+=b[0];c[1]+=b[1];c[2]+=b[2];c[3]+=b[3];return this},multiplyVectors:function(e,d,c){e[0]=d[0]*c[0];e[1]=d[1]*c[1];e[2]=d[2]*c[2];e[3]=d[3]*c[3];return this},multiplyScalar:function(b,a){b[0]*=a;b[1]*=a;b[2]*=a;b[3]*=a;return this},min:function(b,a){if(b[0]<a){b[0]=a}if(b[1]<a){b[1]=a}if(b[2]<a){b[2]=a}if(b[3]<a){b[3]=a}return this},max:function(b,a){if(b[0]>a){b[0]=a}if(b[1]>a){b[1]=a}if(b[2]>a){b[2]=a}if(b[3]>a){b[3]=a}return this},clamp:function(c,b,a){this.min(c,b);this.max(c,a);return this}};FSS.Color=function(a,b){this.rgba=[];this.color=a||"#000000";this.opacity=FSS.Utils.isNumber(b)?b:1;this.set(this.color,this.opacity)};FSS.Color.prototype={set:function(a,c){if(a.indexOf("#")===-1){if(a.indexOf("rgb(")===0){var e=a.indexOf(",");this.rgba[0]=parseInt(a.substr(4,e));this.rgba[1]=parseInt(a.substr(e+1,a.indexOf(",",e)));this.rgba[2]=parseInt(a.substr(a.indexOf(",",e+1)+1,a.indexOf(")")));this.rgba[3]=1}else{if(a.indexOf("rgba(")===0){var e=a.indexOf(",");var b=a.indexOf(",",e+1);this.rgba[0]=parseInt(a.substr(5,e));this.rgba[1]=parseInt(a.substr(e+1,b));this.rgba[2]=parseInt(a.substr(a.indexOf(",",e+1)+1,a.indexOf(",",b)));this.rgba[3]=parseFloat(a.substr(a.indexOf(",",b+1)+1,a.indexOf(")")))}}}else{a=a.replace("#","");var d=a.length/3;this.rgba[0]=parseInt(a.substring(d*0,d*1),16)/255;this.rgba[1]=parseInt(a.substring(d*1,d*2),16)/255;this.rgba[2]=parseInt(a.substring(d*2,d*3),16)/255;this.rgba[3]=FSS.Utils.isNumber(c)?c:this.rgba[3]}return this},format:function(){return"rgba("+this.rgba[0]+","+this.rgba[1]+","+this.rgba[2]+","+this.rgba[3]+")"}};FSS.Object=function(){this.position=FSS.Vector3.create()};FSS.Object.prototype={setPosition:function(a,c,b){FSS.Vector3.set(this.position,a,c,b);return this}};FSS.Light=function(b,a){FSS.Object.call(this);this.ambient=new FSS.Color(b||"#FFFFFF");this.diffuse=new FSS.Color(a||"#FFFFFF");this.ray=FSS.Vector3.create()};FSS.Light.prototype=Object.create(FSS.Object.prototype);FSS.Vertex=function(a,c,b){this.position=FSS.Vector3.create(a,c,b)};FSS.Vertex.prototype={setPosition:function(a,c,b){FSS.Vector3.set(this.position,a,c,b);return this}};FSS.Triangle=function(e,d,f){this.a=e||new FSS.Vertex();this.b=d||new FSS.Vertex();this.c=f||new FSS.Vertex();this.vertices=[this.a,this.b,this.c];this.u=FSS.Vector3.create();this.v=FSS.Vector3.create();this.centroid=FSS.Vector3.create();this.normal=FSS.Vector3.create();this.color=new FSS.Color();this.polygon=document.createElementNS(FSS.SVGNS,"polygon");this.polygon.setAttributeNS(null,"stroke-linejoin","round");this.polygon.setAttributeNS(null,"stroke-miterlimit","1");this.polygon.setAttributeNS(null,"stroke-width","1");this.computeCentroid();this.computeNormal()};FSS.Triangle.prototype={computeCentroid:function(){this.centroid[0]=this.a.position[0]+this.b.position[0]+this.c.position[0];this.centroid[1]=this.a.position[1]+this.b.position[1]+this.c.position[1];this.centroid[2]=this.a.position[2]+this.b.position[2]+this.c.position[2];FSS.Vector3.divideScalar(this.centroid,3);return this},computeNormal:function(){FSS.Vector3.subtractVectors(this.u,this.b.position,this.a.position);FSS.Vector3.subtractVectors(this.v,this.c.position,this.a.position);FSS.Vector3.crossVectors(this.normal,this.u,this.v);FSS.Vector3.normalise(this.normal);return this}};FSS.Geometry=function(){this.vertices=[];this.triangles=[];this.dirty=false};FSS.Geometry.prototype={update:function(){if(this.dirty){var a,b;for(a=this.triangles.length-1;a>=0;a--){b=this.triangles[a];b.computeCentroid();b.computeNormal()}this.dirty=false}return this}};FSS.Plane=function(a,p,e,n){FSS.Geometry.call(this);this.width=a||100;this.height=p||100;this.segments=e||4;this.slices=n||4;this.segmentWidth=this.width/this.segments;this.sliceHeight=this.height/this.slices;var k,i,o,m,j,h,f,d,g=[],c=this.width*-0.5,b=this.height*0.5;for(k=0;k<=this.segments;k++){g.push([]);for(i=0;i<=this.slices;i++){f=new FSS.Vertex(c+k*this.segmentWidth,b-i*this.sliceHeight);g[k].push(f);this.vertices.push(f)}}for(k=0;k<this.segments;k++){for(i=0;i<this.slices;i++){o=g[k+0][i+0];m=g[k+0][i+1];j=g[k+1][i+0];h=g[k+1][i+1];t0=new FSS.Triangle(o,m,j);t1=new FSS.Triangle(j,m,h);this.triangles.push(t0,t1)}}};FSS.Plane.prototype=Object.create(FSS.Geometry.prototype);FSS.Material=function(b,a){this.ambient=new FSS.Color(b||"rgba(68,68,68, 1)");this.diffuse=new FSS.Color(a||"rgba(255,255,255, 1)");this.slave=new FSS.Color()};FSS.Mesh=function(b,a){FSS.Object.call(this);this.geometry=b||new FSS.Geometry();this.material=a||new FSS.Material();this.side=FSS.FRONT;this.visible=true};FSS.Mesh.prototype=Object.create(FSS.Object.prototype);FSS.Mesh.prototype.update=function(e,d){var j,h,c,f,a,b;b=e.length;this.geometry.update();if(d){for(j=this.geometry.triangles.length-1;j>=0;j--){h=this.geometry.triangles[j];FSS.Vector4.set(h.color.rgba);for(c=e.length-1;c>=0;c--){f=e[c];FSS.Vector3.subtractVectors(f.ray,f.position,h.centroid);FSS.Vector3.normalise(f.ray);a=FSS.Vector3.dot(h.normal,f.ray);if(this.side===FSS.FRONT){a=Math.max(a,0)}else{if(this.side===FSS.BACK){a=Math.abs(Math.min(a,0))}else{if(this.side===FSS.DOUBLE){a=Math.max(Math.abs(a),0)}}}for(var g=0;g<3;g++){this.material.slave.rgba[g]=(((1/b)*this.material.ambient.rgba[g])*((1/b)*f.ambient.rgba[g]))/128;if(g!==3){this.material.slave.rgba[g]=Math.round(this.material.slave.rgba[g])}}FSS.Vector4.add(h.color.rgba,this.material.slave.rgba);for(var g=0;g<3;g++){this.material.slave.rgba[g]=((1/b)*this.material.diffuse.rgba[g]*(1/b)*f.diffuse.rgba[g])/128;if(g!==3){this.material.slave.rgba[g]=Math.round(this.material.slave.rgba[g])}}for(var g=0;g<3;g++){this.material.slave.rgba[g]=Math.round(this.material.slave.rgba[g]*a)}FSS.Vector4.add(h.color.rgba,this.material.slave.rgba)}FSS.Vector4.clamp(h.color.rgba,0,255);h.color.rgba[3]=this.material.diffuse.rgba[3]}}return this};FSS.Scene=function(){this.meshes=[];this.lights=[]};FSS.Scene.prototype={add:function(a){if(a instanceof FSS.Mesh&&!~this.meshes.indexOf(a)){this.meshes.push(a)}else{if(a instanceof FSS.Light&&!~this.lights.indexOf(a)){this.lights.push(a)}}return this},remove:function(a){if(a instanceof FSS.Mesh&&~this.meshes.indexOf(a)){this.meshes.splice(this.meshes.indexOf(a),1)}else{if(a instanceof FSS.Light&&~this.lights.indexOf(a)){this.lights.splice(this.lights.indexOf(a),1)}}return this}};FSS.Renderer=function(){this.width=0;this.height=0;this.halfWidth=0;this.halfHeight=0};FSS.Renderer.prototype={setSize:function(b,a){if(this.width===b&&this.height===a){return}this.width=b;this.height=a;this.halfWidth=this.width*0.5;this.halfHeight=this.height*0.5;return this},clear:function(){return this},render:function(a){return this}};FSS.CanvasRenderer=function(){FSS.Renderer.call(this);this.element=document.createElement("canvas");this.element.style.zIndex="-100";this.element.style.pointerEvents="none";this.context=this.element.getContext("2d");this.setSize(this.element.width,this.element.height)};FSS.CanvasRenderer.prototype=Object.create(FSS.Renderer.prototype);FSS.CanvasRenderer.prototype.setSize=function(b,a){FSS.Renderer.prototype.setSize.call(this,b,a);this.element.width=b;this.element.height=a;this.context.setTransform(1,0,0,1,0,0);return this};FSS.CanvasRenderer.prototype.clear=function(){FSS.Renderer.prototype.clear.call(this);this.context.clearRect(0,0,this.width,this.height);return this};var opacity=[];FSS.CanvasRenderer.prototype.render=function(f){FSS.Renderer.prototype.render.call(this,f);var b,k,j,g,d;var h=2*Math.PI;this.clear();this.context.lineJoin="round";this.context.lineWidth=0;for(b=f.meshes.length-1;b>=0;b--){k=f.meshes[b];if(typeof opacity[b]=="undefined"){opacity[b]=[]}if(k.visible){k.update(f.lights,true);for(j=k.geometry.triangles.length-1;j>=0;j--){var a=Date.now();if(typeof opacity[b][j]==="undefined"){opacity[b][j]={};opacity[b][j].step=FSS.Vector3.create(Math.randomInRange(0.2,1),Math.randomInRange(0.2,1),Math.randomInRange(0.2,1));opacity[b][j].time=Math.randomInRange(0,Math.PIM2);opacity[b][j].line=0}else{opacity[b][j].line=Math.sin(opacity[b][j].time+opacity[b][j].step[0]*a*(f.LINE.fluctuationSpeed/100))*f.LINE.fluctuationIntensity;opacity[b][j].vertex=Math.sin(opacity[b][j].time+opacity[b][j].step[0]*a*(f.VERTEX.fluctuationSpeed/100))*f.VERTEX.fluctuationIntensity;opacity[b][j].mesh=Math.sin(opacity[b][j].time+opacity[b][j].step[0]*a*(f.MESH.fluctuationSpeed/100))*f.MESH.fluctuationIntensity}g=k.geometry.triangles[j];if(f.MESH.draw!==false){i=g.color.rgba;d="rgba("+i[0]+","+i[1]+", "+i[2]+","+i[3]+")";this.context.beginPath();this.context.moveTo(g.a.position[0],g.a.position[1]);this.context.lineTo(g.b.position[0],g.b.position[1]);this.context.lineTo(g.c.position[0],g.c.position[1]);this.context.closePath();this.context.fillStyle=d;this.context.fill()}if(f.LINE.draw!==false){var i=new FSS.Color(f.LINE.fill);i=i.rgba;i[3]=i[3]*(1-opacity[b][j].line);i="rgba("+i[0]+","+i[1]+", "+i[2]+","+i[3]+")";this.context.beginPath();this.context.moveTo(g.a.position[0],g.a.position[1]);this.context.lineTo(g.b.position[0],g.b.position[1]);this.context.lineWidth=f.LINE.thickness;this.context.fillStyle=i;this.context.fill();this.context.strokeStyle=i;this.context.stroke()}if(f.VERTEX.draw!==false){var i=new FSS.Color(f.VERTEX.fill);i=i.rgba;i[3]=i[3]*(1-opacity[b][j].vertex);i="rgba("+i[0]+","+i[1]+", "+i[2]+","+i[3]+")";var e=new FSS.Color(f.VERTEX.strokeColor);e=e.rgba;e[3]=e[3]*(1-opacity[b][j].vertex);e="rgba("+e[0]+","+e[1]+", "+e[2]+","+e[3]+")";this.context.beginPath();this.context.arc(g.a.position[0],g.a.position[1],f.VERTEX.radius,0,h,false);this.context.fillStyle=i;this.context.fill();this.context.lineWidth=f.VERTEX.strokeWidth;this.context.strokeStyle=e;this.context.stroke()}}}}return this};FSS.WebGLRenderer=function(){FSS.Renderer.call(this);this.element=document.createElement("canvas");this.element.style.display="block";this.vertices=null;this.lights=null;var a={preserveDrawingBuffer:false,premultipliedAlpha:true,antialias:true,stencil:true,alpha:true};this.gl=this.getContext(this.element,a);this.unsupported=!this.gl;if(this.unsupported){return"WebGL is not supported by your browser."}else{this.gl.clearColor(0,0,0,0);this.gl.enable(this.gl.DEPTH_TEST);this.setSize(this.element.width,this.element.height)}};FSS.WebGLRenderer.prototype=Object.create(FSS.Renderer.prototype);FSS.WebGLRenderer.prototype.getContext=function(b,d){var c=false;try{if(!(c=b.getContext("experimental-webgl",d))){throw"Error creating WebGL context."}}catch(a){console.error(a)}return c};FSS.WebGLRenderer.prototype.setSize=function(b,a){FSS.Renderer.prototype.setSize.call(this,b,a);if(this.unsupported){return}this.element.width=b;this.element.height=a;this.gl.viewport(0,0,b,a);return this};FSS.WebGLRenderer.prototype.clear=function(){FSS.Renderer.prototype.clear.call(this);if(this.unsupported){return}this.gl.clear(this.gl.COLOR_BUFFER_BIT|this.gl.DEPTH_BUFFER_BIT);return this};FSS.WebGLRenderer.prototype.render=function(u){FSS.Renderer.prototype.render.call(this,u);if(this.unsupported){return}var k,a,j,c,p,n,d,i,q,o,x,b,g=false,w=u.lights.length,f,h,s,r,e=0;this.clear();if(this.lights!==w){this.lights=w;if(this.lights>0){this.buildProgram(w)}else{return}}if(!!this.program){for(k=u.meshes.length-1;k>=0;k--){a=u.meshes[k];if(a.geometry.dirty){g=true}a.update(u.lights,false);e+=a.geometry.triangles.length*3}if(g||this.vertices!==e){this.vertices=e;for(i in this.program.attributes){o=this.program.attributes[i];o.data=new FSS.Array(e*o.size);f=0;for(k=u.meshes.length-1;k>=0;k--){a=u.meshes[k];for(j=0,c=a.geometry.triangles.length;j<c;j++){p=a.geometry.triangles[j];for(h=0,s=p.vertices.length;h<s;h++){vertex=p.vertices[h];switch(i){case"side":this.setBufferData(f,o,a.side);break;case"position":this.setBufferData(f,o,vertex.position);break;case"centroid":this.setBufferData(f,o,p.centroid);break;case"normal":this.setBufferData(f,o,p.normal);break;case"ambient":this.setBufferData(f,o,a.material.ambient.rgba);break;case"diffuse":this.setBufferData(f,o,a.material.diffuse.rgba);break}f++}}}this.gl.bindBuffer(this.gl.ARRAY_BUFFER,o.buffer);this.gl.bufferData(this.gl.ARRAY_BUFFER,o.data,this.gl.DYNAMIC_DRAW);this.gl.enableVertexAttribArray(o.location);this.gl.vertexAttribPointer(o.location,o.size,this.gl.FLOAT,false,0,0)}}this.setBufferData(0,this.program.uniforms.resolution,[this.width,this.height,this.width]);for(n=w-1;n>=0;n--){d=u.lights[n];this.setBufferData(n,this.program.uniforms.lightPosition,d.position);this.setBufferData(n,this.program.uniforms.lightAmbient,d.ambient.rgba);this.setBufferData(n,this.program.uniforms.lightDiffuse,d.diffuse.rgba)}for(q in this.program.uniforms){o=this.program.uniforms[q];b=o.location;x=o.data;switch(o.structure){case"3f":this.gl.uniform3f(b,x[0],x[1],x[2]);break;case"3fv":this.gl.uniform3fv(b,x);break;case"4fv":this.gl.uniform4fv(b,x);break}}}this.gl.drawArrays(this.gl.TRIANGLES,0,this.vertices);return this};FSS.WebGLRenderer.prototype.setBufferData=function(b,a,d){if(FSS.Utils.isNumber(d)){a.data[b*a.size]=d}else{for(var c=d.length-1;c>=0;c--){a.data[b*a.size+c]=d[c]}}};FSS.WebGLRenderer.prototype.buildProgram=function(d){if(this.unsupported){return}var i=FSS.WebGLRenderer.VS(d);var f=FSS.WebGLRenderer.FS(d);var a=i+f;if(!!this.program&&this.program.code===a){return}var e=this.gl.createProgram();var h=this.buildShader(this.gl.VERTEX_SHADER,i);var b=this.buildShader(this.gl.FRAGMENT_SHADER,f);this.gl.attachShader(e,h);this.gl.attachShader(e,b);this.gl.linkProgram(e);if(!this.gl.getProgramParameter(e,this.gl.LINK_STATUS)){var g=this.gl.getError();var c=this.gl.getProgramParameter(e,this.gl.VALIDATE_STATUS);console.error("Could not initialise shader.\nVALIDATE_STATUS: "+c+"\nERROR: "+g);return null}this.gl.deleteShader(b);this.gl.deleteShader(h);e.code=a;e.attributes={side:this.buildBuffer(e,"attribute","aSide",1,"f"),position:this.buildBuffer(e,"attribute","aPosition",3,"v3"),centroid:this.buildBuffer(e,"attribute","aCentroid",3,"v3"),normal:this.buildBuffer(e,"attribute","aNormal",3,"v3"),ambient:this.buildBuffer(e,"attribute","aAmbient",4,"v4"),diffuse:this.buildBuffer(e,"attribute","aDiffuse",4,"v4")};e.uniforms={resolution:this.buildBuffer(e,"uniform","uResolution",3,"3f",1),lightPosition:this.buildBuffer(e,"uniform","uLightPosition",3,"3fv",d),lightAmbient:this.buildBuffer(e,"uniform","uLightAmbient",4,"4fv",d),lightDiffuse:this.buildBuffer(e,"uniform","uLightDiffuse",4,"4fv",d)};this.program=e;this.gl.useProgram(this.program);return e};FSS.WebGLRenderer.prototype.buildShader=function(a,c){if(this.unsupported){return}var b=this.gl.createShader(a);this.gl.shaderSource(b,c);this.gl.compileShader(b);if(!this.gl.getShaderParameter(b,this.gl.COMPILE_STATUS)){console.error(this.gl.getShaderInfoLog(b));return null}return b};FSS.WebGLRenderer.prototype.buildBuffer=function(c,f,d,e,b,g){var a={buffer:this.gl.createBuffer(),size:e,structure:b,data:null};switch(f){case"attribute":a.location=this.gl.getAttribLocation(c,d);break;case"uniform":a.location=this.gl.getUniformLocation(c,d);break}if(!!g){a.data=new FSS.Array(g*e)}return a};FSS.WebGLRenderer.VS=function(a){var b=["precision mediump float;","#define LIGHTS "+a,"attribute float aSide;","attribute vec3 aPosition;","attribute vec3 aCentroid;","attribute vec3 aNormal;","attribute vec4 aAmbient;","attribute vec4 aDiffuse;","uniform vec3 uResolution;","uniform vec3 uLightPosition[LIGHTS];","uniform vec4 uLightAmbient[LIGHTS];","uniform vec4 uLightDiffuse[LIGHTS];","varying vec4 vColor;","void main() {","vColor = vec4(0.0);","vec3 position = aPosition / uResolution * 2.0;","for (int i = 0; i < LIGHTS; i++) {","vec3 lightPosition = uLightPosition[i];","vec4 lightAmbient = uLightAmbient[i];","vec4 lightDiffuse = uLightDiffuse[i];","vec3 ray = normalize(lightPosition - aCentroid);","float illuminance = dot(aNormal, ray);","if (aSide == 0.0) {","illuminance = max(illuminance, 0.0);","} else if (aSide == 1.0) {","illuminance = abs(min(illuminance, 0.0));","} else if (aSide == 2.0) {","illuminance = max(abs(illuminance), 0.0);","}","vColor += aAmbient * lightAmbient;","vColor += aDiffuse * lightDiffuse * illuminance;","}","vColor = clamp(vColor, 0.0, 1.0);","gl_Position = vec4(position, 1.0);","}"].join("\n");return b};FSS.WebGLRenderer.FS=function(a){var b=["precision mediump float;","varying vec4 vColor;","void main() {","gl_FragColor = vColor;","}"].join("\n");return b};FSS.SVGRenderer=function(){FSS.Renderer.call(this);this.element=document.createElementNS(FSS.SVGNS,"svg");this.element.setAttribute("xmlns",FSS.SVGNS);this.element.setAttribute("version","1.1");this.element.style.display="block";this.setSize(300,150)};FSS.SVGRenderer.prototype=Object.create(FSS.Renderer.prototype);FSS.SVGRenderer.prototype.setSize=function(b,a){FSS.Renderer.prototype.setSize.call(this,b,a);this.element.setAttribute("width",b);this.element.setAttribute("height",a);return this};FSS.SVGRenderer.prototype.clear=function(){FSS.Renderer.prototype.clear.call(this);for(var a=this.element.childNodes.length-1;a>=0;a--){this.element.removeChild(this.element.childNodes[a])}return this};FSS.SVGRenderer.prototype.render=function(f){FSS.Renderer.prototype.render.call(this,f);var a,g,b,e,d,c;for(a=f.meshes.length-1;a>=0;a--){g=f.meshes[a];if(g.visible){g.update(f.lights,true);for(b=g.geometry.triangles.length-1;b>=0;b--){e=g.geometry.triangles[b];if(e.polygon.parentNode!==this.element){this.element.appendChild(e.polygon)}d=this.formatPoint(e.a)+" ";d+=this.formatPoint(e.b)+" ";d+=this.formatPoint(e.c);c=this.formatStyle(e.color.format());e.polygon.setAttributeNS(null,"points",d);e.polygon.setAttributeNS(null,"style",c)}}}return this};FSS.SVGRenderer.prototype.formatPoint=function(a){return(a.position[0])+","+(a.position[1])};FSS.SVGRenderer.prototype.formatStyle=function(a){var b="fill:"+a+";";b+="stroke:"+a+";";return b};(function(){$.fn.Geometryangle=function(g){var e=[];var f=$(this);var b=f.length,c;for(var d=0;d<b;d++){c=f[d];e[e.length]=a(g,c)}return(e.length==1?e[0]:e)};var a=function(r,W){r=r||{};var M={},B=[{}],Z={},A={};var w=function(k){var ab=[[],[]];var aa=[M,B];$.each(aa,function(ac){$.each(aa[ac],function(ae,ag){if(typeof k.getAttribute("data-fss-"[ae])!=="undefined"&&typeof k.getAttribute("data-fss-"+[ae])!==false){try{ab[ac][ae]=$.parseJSON(k.getAttribute("data-fss-"+[ae]));return true}catch(af){}if(typeof ab[ac][ae]!=="object"){ab[ac][ae]=k.getAttribute("data-fss-"+[ae])}}});var ad=(typeof k.getAttribute("data-fss")!=="undefined"&&typeof k.getAttribute("data-fss")!==false?$.parseJSON(k.getAttribute("data-fss")):[]);$.extend(true,ab[ac],ad)});return ab};var q=function(k){try{var aa=k.split("(")}catch(ab){return}if(typeof aa[1]!=="undefined"){aa=aa[1].split(")")[0].split(",");return"rgb("+aa[0]+","+aa[1]+","+aa[2]+")"}return};var J={width:1.2,height:1.2,depth:10,columns:undefined,columns_auto:true,rows:undefined,rows_auto:true,zoom:1,xRange:0.8,yRange:0.1,zRange:1,ambient:"rgba(85, 85, 85, 1)",diffuse:"rgba(255, 255, 255, 1)",background:"rgb(255, 255, 255)",speed:0.0002,fluctuationSpeed:0.5,fluctuationIntensity:0,onRender:function(){},floorPosition:false,draw:true};var K={radius:0,fill:"rgba(0, 0, 0, 0)",fluctuationSpeed:0.5,fluctuationIntensity:0,strokeWidth:0,strokeColor:"rgba(0, 0, 0, 0)",draw:false};var E={fill:"rgba(0, 0, 0, 0)",thickness:1,fluctuationIntensity:0,fluctuationSpeed:0.5,draw:false};var Y={count:1,xyScalar:1,zOffset:100,ambient:"rgba(255,0,102, 1)",diffuse:"rgba(255,136,0, 1)",speed:0.01,gravity:1200,dampening:0.95,minLimit:10,maxLimit:null,minDistance:20,maxDistance:400,autopilot:false,draw:false,bounds:FSS.Vector3.create(),step:FSS.Vector3.create(Math.randomInRange(0.2,1),Math.randomInRange(0.2,1),Math.randomInRange(0.2,1))};var i=W;var h=function(ab){ab.mesh=ab.mesh||M;ab.lights=ab.lights||B;ab.vertex=ab.vertex||Z;ab.line=ab.line||A;M=$.extend(true,J,M,ab.mesh);Z=$.extend(true,K,Z,ab.vertex);A=$.extend(true,E,A,ab.line);for(var aa=0;aa<B.length;aa++){B[aa]=$.extend(true,Y,B[aa],ab.lights[aa])}var k=w(i);M=$.extend(true,k[0],M);M.columns_auto=(typeof ab.mesh.columns==="undefined");M.rows_auto=(typeof ab.mesh.rows==="undefined")};h({mesh:J,line:E,vertex:K,lights:[Y]});h(r);var G=document.createElement("div");G.style.position="absolute";G.style.left="0";G.style.right="0";G.style.top="0";G.style.bottom="0";G.style.background=M.background;G.style.zIndex="-100";G.setAttribute("class","fss-output");i.insertBefore(G,null);var X="webgl";var L="canvas";var C="svg";var n={renderer:L};var x={show:true};var R,y=Date.now();var c=FSS.Vector3.create();var Q=FSS.Vector3.create();var I=document.getElementById("ui");var H,z,u,o,U;var m,p,S;var P,T;function t(){g();j();N();s();v();f.resize(G.offsetWidth,G.offsetHeight);V()}function g(){m=new FSS.WebGLRenderer();p=new FSS.CanvasRenderer();S=new FSS.SVGRenderer();O(n.renderer)}function O(k){if(H){}switch(k){case X:H=m;break;case L:H=p;break;case C:H=S;break}H.setSize(G.offsetWidth,G.offsetHeight);G.insertBefore(H.element,null);var aa=window.getComputedStyle(i);if(aa.getPropertyValue("position")=="static"||aa.getPropertyValue("position").length==0){i.style.position="relative"}}function j(){z=new FSS.Scene();z.VERTEX=Z;z.LINE=A;z.MESH=M}function N(){z.remove(u);H.clear();o=new FSS.Plane(M.width*H.width,M.height*H.height,M.columns,M.rows);U=new FSS.Material(M.ambient,M.diffuse);u=new FSS.Mesh(o,U);z.add(u);var k,aa;for(k=o.vertices.length-1;k>=0;k--){aa=o.vertices[k];aa.anchor=FSS.Vector3.floor(FSS.Vector3.clone(aa.position));aa.step=FSS.Vector3.create(Math.randomInRange(0.2,1),Math.randomInRange(0.2,1),Math.randomInRange(0.2,1));aa.time=Math.randomInRange(0,Math.PIM2)}}function s(){var aa,k;for(aa=z.lights.length-1;aa>=0;aa--){k=z.lights[aa];z.remove(k)}H.clear();for(aa=0;aa<B.length;aa++){for(var ab=0;ab<B[aa].count;ab++){k=new FSS.Light(B[aa].ambient,B[aa].diffuse);z.add(k);k.mass=Math.randomInRange(0.5,1);k.velocity=FSS.Vector3.create();k.acceleration=FSS.Vector3.create();k.force=FSS.Vector3.create();k.ring=document.createElementNS(FSS.SVGNS,"circle");k.ring.setAttributeNS(null,"stroke",k.ambient);k.ring.setAttributeNS(null,"stroke-width","0.5");k.ring.setAttributeNS(null,"fill","none");k.ring.setAttributeNS(null,"r","10");k.core=document.createElementNS(FSS.SVGNS,"circle");k.core.setAttributeNS(null,"fill",k.diffuseHex);k.core.setAttributeNS(null,"r","4")}}}var f={resize:function(ad,k){if(typeof ad=="undefined"||typeof ad===undefined){ad=i.width()}if(typeof k=="undefined"||typeof k===undefined){k=i.height()}var ab=ad/1000;var aa=k/1000;var ac=Math.round(ab*10)*M.zoom;var ae=Math.round(aa*10)*M.zoom;M.columns=(M.columns_auto===true?ac:M.columns);M.rows=(M.rows_auto===true?ae:M.rows);H.setSize(ad,k);FSS.Vector3.set(c,H.halfWidth,H.halfHeight);N()},update:function(ab){h(ab);z.vertex=Z;z.line=A;for(aa=0,l=z.meshes.length;aa<l;aa++){z.meshes[aa].material.ambient.set(M.ambient);z.meshes[aa].material.diffuse.set(M.diffuse)}if(o.width!==M.width*H.width){N()}if(o.height!==M.height*H.height){N()}if(o.segments!==M.columns){N()}if(o.slices!==M.rows){N()}var k=0;for(l=0;l<B.length;l++){for(var aa=0;aa<B[l].count;aa++){light=z.lights[k];light.ambient.set(B[l].ambient);light=z.lights[k];light.diffuse.set(B[l].diffuse);k++}}if(z.lights.length!==k){s()}},animateValues:function(k){var ag=document.body,af=document.documentElement,aa=((window.pageYOffset||af.scrollTop)-(af.clientTop||0));var ai=Math.max(ag.scrollHeight,ag.offsetHeight,af.clientHeight,af.scrollHeight,af.offsetHeight);var ab=k.length;var ai=Math.round(ai/ab);var ae=Math.floor(aa/ai);var ah=aa%ai/ai;var ad=k[ae];var ac=k[(ae+1)%ab];var aj=[];for(var ae=0;ae<ad.length;ae++){aj[ae]=ad[ae]+((ac[ae]-ad[ae])*ah);if(ae!==3){aj[ae]=Math.round(aj[ae])}}return aj},formatRGBA:function(k){var aa="rgba("+k[0]+","+k[1]+","+k[2]+","+k[3]+")";return aa}};function V(){R=Date.now()-y;F();D();requestAnimationFrame(V)}function F(){var ad,ac,aa,af,ah,ak,aj,ag=M.depth/2;var ae=0;var ab=FSS.Vector3.floor(FSS.Vector3.create(H.halfWidth,H.halfHeight,0));for(af=0;af<B.length;af++){for(var ai=0;ai<B[af].count;ai++){ah=z.lights[ae];FSS.Vector3.copy(B[af].bounds,c);FSS.Vector3.multiplyScalar(B[af].bounds,B[af].xyScalar);FSS.Vector3.setZ(Q,B[af].zOffset);if(B[af].autopilot&&typeof B[af].position==="undefined"){ad=Math.sin(B[af].step[0]*R*B[af].speed);ac=Math.cos(B[af].step[1]*R*B[af].speed);FSS.Vector3.set(Q,B[af].bounds[0]*ad,B[af].bounds[1]*ac,B[af].zOffset)}FSS.Vector3.setZ(ah.position,B[af].zOffset);if(typeof B[af].position!=="undefined"){FSS.Vector3.set(ah.position);FSS.Vector3.add(ah.position,FSS.Vector3.create(B[af].position[0],B[af].position[1],B[af].zOffset))}else{var k=Math.clamp(FSS.Vector3.distanceSquared(ah.position,Q),B[af].minDistance,B[af].maxDistance);var al=B[af].gravity*ah.mass/k;FSS.Vector3.subtractVectors(ah.force,Q,ah.position);FSS.Vector3.normalise(ah.force);FSS.Vector3.multiplyScalar(ah.force,al);FSS.Vector3.set(ah.acceleration);FSS.Vector3.add(ah.acceleration,ah.force);FSS.Vector3.add(ah.velocity,ah.acceleration);FSS.Vector3.multiplyScalar(ah.velocity,B[af].dampening);FSS.Vector3.limit(ah.velocity,B[af].minLimit,B[af].maxLimit);FSS.Vector3.add(ah.position,ah.velocity)}ae++}}for(ak=o.vertices.length-1;ak>=0;ak--){aj=o.vertices[ak];ad=Math.sin(aj.time+aj.step[0]*R*M.speed);ac=Math.cos(aj.time+aj.step[1]*R*M.speed);aa=Math.sin(aj.time+aj.step[2]*R*M.speed);aj.position=FSS.Vector3.create(M.xRange*o.segmentWidth*ad,M.yRange*o.sliceHeight*ac,M.zRange*ag*aa-ag);if(M.positionFloor===true){aj.position=FSS.Vector3.floor(aj.position)}FSS.Vector3.add(aj.position,aj.anchor);FSS.Vector3.add(aj.position,ab)}o.dirty=true}function D(){H.render(z);if(B.draw){var aa,ac,ab,k;for(aa=z.lights.length-1;aa>=0;aa--){k=z.lights[aa];ac=k.position[0];ab=k.position[1];switch(n.renderer){case L:H.context.lineWidth=0.5;H.context.beginPath();H.context.arc(ac,ab,10,0,Math.PIM2);H.context.strokeStyle=k.ambient;H.context.stroke();H.context.beginPath();H.context.arc(ac,ab,4,0,Math.PIM2);H.context.fillStyle=k.diffuse;H.context.fill();break;case C:k.core.setAttributeNS(null,"fill",k.diffuse);k.core.setAttributeNS(null,"cx",ac);k.core.setAttributeNS(null,"cy",ab);H.element.appendChild(k.core);k.ring.setAttributeNS(null,"stroke",k.ambient);k.ring.setAttributeNS(null,"cx",ac);k.ring.setAttributeNS(null,"cy",ab);H.element.appendChild(k.ring);break}}}M.onRender(z,H.context)}function v(){if(window.attachEvent){window.addEventHandler=window.attachEvent}window.addEventListener("resize",d,false);i.addEventListener("click",e,false);i.addEventListener("mousemove",b,true)}function e(k){FSS.Vector3.set(Q,k.x,k.y);B.autopilot=!B.autopilot}function b(k){console.log(k);FSS.Vector3.set(Q,k.x,k.y)}function d(k){f.resize(i.offsetWidth,i.offsetHeight);D()}t();return f}})();