mirror of
https://github.com/ysoftdevs/pf2016.git
synced 2026-01-15 08:14:04 +01:00
1 line
20 KiB
JavaScript
1 line
20 KiB
JavaScript
Kiwi.Plugins.Primitives={name:"Primitives",version:"1.0.4",minimumKiwiVersion:"1.3.0"},Kiwi.PluginManager.register(Kiwi.Plugins.Primitives),Kiwi.Plugins.Primitives.create=function(a){},Kiwi.Plugins.Primitives.Polygon=function(a){var b=a.state;this._initProperties(),Kiwi.Entity.call(this,b,0,0),this.parseParams(a),this.game.renderOption===Kiwi.RENDERER_WEBGL&&(this.glRenderer=this.game.renderer.requestSharedRenderer("PrimitiveRenderer"),this.atlas=this.glRenderer.getAtlas()),this.rebuildBounds()},Kiwi.extend(Kiwi.Plugins.Primitives.Polygon,Kiwi.Entity),Object.defineProperty(Kiwi.Plugins.Primitives.Polygon.prototype,"indices",{get:function(){return this._indices},set:function(a){var b;if(this._indices=[],a.length>2)for(b=0;b<a.length;b++)this._indices.push(a[b])}}),Object.defineProperty(Kiwi.Plugins.Primitives.Polygon.prototype,"vertices",{get:function(){return this._vertices},set:function(a){var b;for(this._vertices=[],b=0;b<a.length;b++)this._vertices.push([a[b][0],a[b][1]])}}),Object.defineProperty(Kiwi.Plugins.Primitives.Polygon.prototype,"strokeIndices",{get:function(){return this._strokeIndices},set:function(a){var b;if(this._strokeIndices=[],a.length>1){for(b=0;b<a.length;b++)this._strokeIndices.push(a[b]);this.createstroke(this._strokeIndices,this._vertices)}}}),Object.defineProperty(Kiwi.Plugins.Primitives.Polygon.prototype,"strokePolyIndices",{get:function(){return this._strokePolyIndices},set:function(a){var b;if(this._strokePolyIndices=[],a.length>2)for(3===a.length&&this._strokePolyIndices.push(a[0]),b=0;b<a.length;b++)this._strokePolyIndices.push(a[b])}}),Object.defineProperty(Kiwi.Plugins.Primitives.Polygon.prototype,"strokePolyVertices",{get:function(){return this._strokePolyVertices},set:function(a){var b;for(this._strokePolyVertices=[],b=0;b<a.length;b++)this._strokePolyVertices.push([a[b][0],a[b][1]])}}),Kiwi.Plugins.Primitives.Polygon.prototype._buildMiter=function(a,b){var c,d,e,f,g,h,i,j,k,l,m,n,o=[],p=[],q=b[0];return j=a[0].distanceTo(a[1]),k=b[0].distanceTo(b[1]),l=Math.min(j,k),h=Math.atan2(a[1].y-a[0].y,a[1].x-a[0].x),i=Math.atan2(b[1].y-b[0].y,b[1].x-b[0].x),h=Kiwi.Utils.GameMath.normalizeAngle(h),i=Kiwi.Utils.GameMath.normalizeAngle(i),d=i-h,d>Math.PI?d=2*Math.PI-d:d<-Math.PI&&(d=2*-Math.PI-d),d*=.5,Math.abs(h-i)>Math.PI&&(i>h?h+=2*Math.PI:i+=2*Math.PI),c=Kiwi.Utils.GameMath.normalizeAngle(.5*(h+i)),e=Math.cos(c),f=-Math.sin(c),g=this.strokeWidth/(2*Math.cos(d)),g>l&&(g=l),m=new Kiwi.Geom.Point(f*g,e*g),n=new Kiwi.Geom.Point(f*-g,e*-g),m.x+=q.x,m.y+=q.y,n.x+=q.x,n.y+=q.y,o=[0,1,0,1],p=[[m.x,m.y],[n.x,n.y]],{indices:o,vertices:p}},Kiwi.Plugins.Primitives.Polygon.prototype._buildStroke=function(a,b){var c,d,e,f,g,h,i,j,k,l=[],m=0,n=a.length,o=[];if(n>1){for(i=new Kiwi.Geom.Point(b[a[0]][0],b[a[0]][1]),j=new Kiwi.Geom.Point(b[a[1]][0],b[a[1]][1]),h=this._buildMiter([i,j],[i,j]),l=l.concat(h.indices),o=o.concat(h.vertices),m+=h.vertices.length,f=1;n-1>f;f++){for(i=new Kiwi.Geom.Point(b[a[f-1]][0],b[a[f-1]][1]),j=new Kiwi.Geom.Point(b[a[f]][0],b[a[f]][1]),k=new Kiwi.Geom.Point(b[a[f+1]][0],b[a[f+1]][1]),h=this._buildMiter([i,j],[j,k]),g=0;g<h.indices.length;g++)h.indices[g]+=m;l=l.concat(h.indices),o=o.concat(h.vertices),m+=h.vertices.length}for(e=a.length-1,c=b[a[e]][0]-b[a[e-1]][0],d=b[a[e]][1]-b[a[e-1]][1],i=new Kiwi.Geom.Point(b[a[e]][0],b[a[e]][1]),j=new Kiwi.Geom.Point(b[a[e]][0]+c,b[a[e]][1]+d),h=this._buildMiter([i,j],[i,j]),g=0;g<h.indices.length;g++)h.indices[g]+=m;return l=l.concat(h.indices),o=o.concat(h.vertices),{indices:l,vertices:o}}return null},Kiwi.Plugins.Primitives.Polygon.prototype.clone=function(){var a={color:this.color,indices:this._indices,state:this.state,strokeColor:this.strokeColor,strokeIndices:this._strokeIndices,vertices:this._vertices,x:this.x,y:this.y,rotation:this.rotation,scaleX:this.scaleX,scaleY:this.scaleY,anchorPointX:this.anchorPointX,anchorPointY:this.anchorPointY,alpha:this.alpha,visible:this.visible};return new Kiwi.Plugins.Primitives.Polygon(a)},Kiwi.Plugins.Primitives.Polygon.prototype.computeMinMaxXY=function(a){var b,c,d=a.length,e=0,f=0,g=0,h=0;for(b=0;d>b;b++)c=a[b],c[0]<g&&(g=c[0]),c[0]>e&&(e=c[0]),c[1]<h&&(h=c[1]),c[1]>f&&(f=c[1]);return{maxX:e,maxY:f,minX:g,minY:h}},Kiwi.Plugins.Primitives.Polygon.prototype.combine=function(a,b){if("undefined"==typeof b&&(b=!0),this.poly===this)return!1;var c,d=this.transform.getConcatenatedMatrix().invert(),e=a.transform.getConcatenatedMatrix(),f=new Kiwi.Geom.Point(0,0),g=a.indices.length,h=a.vertices.length,j=a.strokePolyIndices.length,k=a.strokePolyVertices.length;if(g>2){for(c=this._vertices.length,this._indices.length>0&&(this._indices.push(this._indices[this._indices.length-1]),this._indices.push(a.indices[0]+c)),i=0;i<g;i++)this._indices.push(a.indices[i]+c);for(i=0;i<h;i++)f.setTo(a.vertices[i][0]-a.anchorPointX,a.vertices[i][1]-a.anchorPointY),f=e.transformPoint(f),f=d.transformPoint(f),this._vertices.push([f.x+this.anchorPointX,f.y+this.anchorPointY])}if(j>2){for(c=this._strokePolyVertices.length,this._strokePolyIndices.length>0&&(this._strokePolyIndices.push(this._strokePolyIndices[this._strokePolyIndices.length-1]),this._strokePolyIndices.push(a.strokePolyIndices[0]+c)),i=0;i<j;i++)this._strokePolyIndices.push(a.strokePolyIndices[i]+c);for(i=0;i<k;i++)f.setTo(a.strokePolyVertices[i][0]-a.anchorPointX,a.strokePolyVertices[i][1]-a.anchorPointY),f=e.transformPoint(f),f=d.transformPoint(f),this._strokePolyVertices.push([f.x+this.anchorPointX,f.y+this.anchorPointY])}return b&&a.destroy(),!0},Kiwi.Plugins.Primitives.Polygon.prototype.complain=function(a){Kiwi.Log.log("#primitive","Primitive Error encountered:",a)},Kiwi.Plugins.Primitives.Polygon.prototype.createstroke=function(){var a=this._buildStroke(this.strokeIndices,this.vertices);a&&(this.strokePolyIndices=a.indices,this.strokePolyVertices=a.vertices)},Kiwi.Plugins.Primitives.Polygon.prototype._initProperties=function(){this.glRenderer=void 0,this._indices=null,this._vertices=null,this._strokeIndices=null,this._strokePolyIndices=null,this._strokePolyVertices=null,this._p0=new Kiwi.Geom.Point(0,0),this._p1=new Kiwi.Geom.Point(0,0),this._p2=new Kiwi.Geom.Point(0,0),this._color=new Kiwi.Utils.Color,this._strokeColor=new Kiwi.Utils.Color},Kiwi.Plugins.Primitives.Polygon.prototype.objType=function(){return"Primitive Polygon"},Object.defineProperty(Kiwi.Plugins.Primitives.Polygon.prototype,"color",{get:function(){return[this._color.rNorm,this._color.gNorm,this._color.bNorm]},set:function(a){this._color.set.apply(this._color,a)}}),Object.defineProperty(Kiwi.Plugins.Primitives.Polygon.prototype,"strokeColor",{get:function(){return[this._strokeColor.rNorm,this._strokeColor.gNorm,this._strokeColor.bNorm]},set:function(a){this._strokeColor.set.apply(this._strokeColor,a)}}),Kiwi.Plugins.Primitives.Polygon.prototype.parseParams=function(a){return"undefined"!=typeof a.color?Kiwi.Utils.Common.isArray(a.color)?this.color=a.color:this._color.set(a.color):this.color=[.5,.5,.5],this.drawFill="undefined"!=typeof a.drawFill?a.drawFill:!0,this.drawStroke="undefined"!=typeof a.drawStroke?a.drawStroke:!0,this.enableInput=a.enableInput===!0,this.indices=a.indices||[],this.vertices=a.vertices||[],"undefined"!=typeof a.strokeColor?Kiwi.Utils.Common.isArray(a.strokeColor)?this.strokeColor=a.strokeColor:this._strokeColor.set(a.strokeColor):this.strokeColor=[0,0,0],this.strokeWidth="number"==typeof a.strokeWidth?a.strokeWidth:1,this.strokeIndices=a.strokeIndices||[],this.strokePolyIndices=this._strokePolyIndices||[],this.strokePolyVertices=this._strokePolyVertices||[],this.alpha="number"==typeof a.alpha?a.alpha:1,this.anchorPointX="number"==typeof a.anchorPointX?a.anchorPointX:void 0,this.anchorPointY="number"==typeof a.anchorPointY?a.anchorPointY:void 0,this.rotation="number"==typeof a.rotation?a.rotation:0,"undefined"==typeof a.scaleX&&"undefined"==typeof a.scaleY?this.scale="number"==typeof a.scale?a.scale:1:(this.scaleX="number"==typeof a.scaleX?a.scaleX:1,this.scaleY="number"==typeof a.scaleY?a.scaleY:1),this.visible="boolean"==typeof a.visible?a.visible:!0,this.x="number"==typeof a.x?a.x:0,this.y="number"==typeof a.y?a.y:0,this.parseStrict()},Kiwi.Plugins.Primitives.Polygon.prototype.parseStrict=function(){var a;if(isNaN(this.strokeWidth))return this.complain("strokeWidth is not a number"),!1;if(!Kiwi.Utils.Common.isArray(this.indices))return this.complain("Could not parse indices: Not an array"),!1;for(a=0;a<this.indices.length;a++){if(isNaN(this.indices[a]))return this.complain("Index "+a+" is not a number"),!1;if(this.indices[a]%1!==0)return this.complain("Index"+a+" is not an integer"),!1}if(!Kiwi.Utils.Common.isArray(this.strokeIndices))return this.complain("Could not parse strokeIndices: Not an array"),!1;for(a=0;a<this.strokeIndices.length;a++){if(isNaN(this.strokeIndices[a]))return this.complain("Stroke Index "+a+" is not a number"),!1;if(this.strokeIndices[a]%1!==0)return this.complain("Stroke Index"+a+" is not an integer"),!1}if(!Kiwi.Utils.Common.isArray(this.vertices))return this.complain("Could not parse indices: Not an array"),!1;for(a=0;a<this.vertices.length;a++){if(!Kiwi.Utils.Common.isArray(this.vertices[a]))return this.complain("Vertex "+a+" is not an array"),!1;if(isNaN(this.vertices[a][0]))return this.complain("Vertex "+a+".x is not a number"),!1;if(isNaN(this.vertices[a][1]))return this.complain("Vertex "+a+".y is not a number"),!1}return!0},Kiwi.Plugins.Primitives.Polygon.prototype.rebuildBounds=function(){var a=this.computeMinMaxXY(this._vertices);this.width=a.maxX-a.minX,this.height=a.maxY-a.minY,"undefined"==typeof this.anchorPointX&&(this.anchorPointX=a.maxX-.5*this.width),"undefined"==typeof this.anchorPointY&&(this.anchorPointY=a.maxY-.5*this.height),this.box=this.components.add(new Kiwi.Components.Box(this,this.x+a.minX,this.x+a.minY,this.width,this.height)),this.box.hitbox=new Kiwi.Geom.Rectangle(a.minX,a.minY,this.width,this.height),this.input=this.components.add(new Kiwi.Components.Input(this,this.box,this.enableInput)),this.atlas&&(this.atlas.cells[0].hitboxes[0]={x:0,y:0,w:this.width,h:this.height})},Kiwi.Plugins.Primitives.Polygon.prototype.render=function(a){var b,c,d,e=this._indices.length;if(Kiwi.Entity.prototype.render.call(this,a),this.alpha>0){b=this.game.stage.ctx,b.save(),this.alpha<=1&&(b.globalAlpha=this.alpha);var f=this.transform,g=f.getConcatenatedMatrix();if(b.transform(g.a,g.b,g.c,g.d,g.tx,g.ty),this.drawFill&&this._indices.length>2){for(b.fillStyle="rgb("+this._color.r255+","+this._color.g255+","+this._color.b255+")",this._p1.setTo(this._vertices[this._indices[1]][0]-f.anchorPointX,this._vertices[this._indices[1]][1]-f.anchorPointY),this._p2.setTo(this._vertices[this._indices[0]][0]-f.anchorPointX,this._vertices[this._indices[0]][1]-f.anchorPointY),b.beginPath(),c=2;e>c;c++)this._p0.setTo(this._vertices[this._indices[c]][0]-f.anchorPointX,this._vertices[this._indices[c]][1]-f.anchorPointY),b.moveTo(this._p0.x,this._p0.y),b.lineTo(this._p1.x,this._p1.y),b.lineTo(this._p2.x,this._p2.y),d=this._p2,this._p2=this._p1,this._p1=this._p0,this._p0=d;b.closePath(),b.fill()}if(this.drawStroke&&this._strokePolyIndices.length>2){for(e=this._strokePolyIndices.length,b.fillStyle="rgb("+this._strokeColor.r255+","+this._strokeColor.g255+","+this._strokeColor.b255+")",this._p1.setTo(this._strokePolyVertices[this._strokePolyIndices[1]][0]-f.anchorPointX,this._strokePolyVertices[this._strokePolyIndices[1]][1]-f.anchorPointY),this._p2.setTo(this._strokePolyVertices[this._strokePolyIndices[0]][0]-f.anchorPointX,this._strokePolyVertices[this._strokePolyIndices[0]][1]-f.anchorPointY),b.beginPath(),c=2;e>c;c++)this._p0.setTo(this._strokePolyVertices[this._strokePolyIndices[c]][0]-f.anchorPointX,this._strokePolyVertices[this._strokePolyIndices[c]][1]-f.anchorPointY),b.moveTo(this._p0.x,this._p0.y),b.lineTo(this._p1.x,this._p1.y),b.lineTo(this._p2.x,this._p2.y),d=this._p2,this._p2=this._p1,this._p1=this._p0,this._p0=d;b.closePath(),b.fill()}b.restore()}},Kiwi.Plugins.Primitives.Polygon.prototype.renderGL=function(a){this.alpha>0&&(this.drawFill&&this.glRenderer.addToBatch(a,this,this._indices,this._vertices,this.color),this.drawStroke&&this.glRenderer.addToBatch(a,this,this._strokePolyIndices,this._strokePolyVertices,this.strokeColor))},Kiwi.Plugins.Primitives.Polygon.prototype.shatter=function(){var a,b,c,d,e,f,g,h,i,j=[0,1,2],k=new Kiwi.Group(this.state);for(d=0;d<this._indices.length-2;d++)g=this._vertices[this._indices[d]],h=this._vertices[this._indices[d+1]],i=this._vertices[this._indices[d+2]],a=Math.sqrt(Math.pow(g[0]-h[0],2)+Math.pow(g[1]-h[1],2)),b=Math.sqrt(Math.pow(g[0]-i[0],2)+Math.pow(g[1]-i[1],2)),c=Math.sqrt(Math.pow(h[0]-i[0],2)+Math.pow(h[1]-i[1],2)),0!==a&&0!==b&&0!==c&&(e={indices:j,vertices:[g,h,i],state:this.state,color:this.color,x:this.x,y:this.y,rotation:this.rotation,scaleX:this.scaleX,scaleY:this.scaleY,anchorPointX:this.anchorPointX,anchorPointY:this.anchorPointY},f=new Kiwi.Plugins.Primitives.Polygon(e).clone(),k.addChild(f));return this.parent&&this.parent.addChildBefore(k,this),this.destroy(),k},Kiwi.Plugins.Primitives.Polygon.prototype.update=function(){Kiwi.Entity.prototype.update.call(this),this.input.update()},Kiwi.Plugins.Primitives.Ellipse=function(a){var b,c,d=8,e=0,f=0;for("undefined"==typeof a.segments&&(a.segments=32),"undefined"!=typeof a.radius&&(a.width=2*a.radius,a.height=2*a.radius),"number"!=typeof a.width&&(a.width=d),"number"!=typeof a.height&&(a.height=d),a.centerOnTransform||(e=.5*a.width,f=.5*a.height),a.indices=[],a.vertices=[],a.strokeIndices=[],c=0;c<a.segments;c++)a.indices.push(c),a.indices.push(a.segments),a.indices.push((c+1)%a.segments),b=2*Math.PI*c/a.segments,a.vertices.push([.5*a.width*Math.cos(b)+e,.5*a.height*Math.sin(b)+f]),a.strokeIndices.push(c);a.vertices.push([e,f]),a.strokeIndices.push(0),a.radiusPointer&&a.strokeIndices.push(a.segments),Kiwi.Plugins.Primitives.Polygon.call(this,a)},Kiwi.extend(Kiwi.Plugins.Primitives.Ellipse,Kiwi.Plugins.Primitives.Polygon),Kiwi.Plugins.Primitives.Line=function(a){var b;if(a.vertices=[],a.strokeIndices=[],a.drawFill=!1,a.drawStroke=!0,a.points)for(b=0;b<a.points.length;b++)a.vertices.push(a.points[b]),a.strokeIndices.push(b);Kiwi.Plugins.Primitives.Polygon.call(this,a)},Kiwi.extend(Kiwi.Plugins.Primitives.Line,Kiwi.Plugins.Primitives.Polygon),Kiwi.Plugins.Primitives.NullAtlas=function(){this.cells=[{hitboxes:[]}]},Kiwi.Plugins.Primitives.NullAtlas.prototype.enableGL=function(){},Kiwi.Plugins.Primitives.Rectangle=function(a){var b=8;a.indices=[0,1,2,3],a.strokeIndices=[0,1,3,2,0],"undefined"==typeof a.width&&(a.width=b),"undefined"==typeof a.height&&(a.height=b),a.centerOnTransform?a.vertices=[[.5*-a.width,.5*-a.height],[.5*a.width,.5*-a.height],[.5*-a.width,.5*a.height],[.5*a.width,.5*a.height]]:a.vertices=[[0,0],[a.width,0],[0,a.height],[a.width,a.height]],Kiwi.Plugins.Primitives.Polygon.call(this,a)},Kiwi.extend(Kiwi.Plugins.Primitives.Rectangle,Kiwi.Plugins.Primitives.Polygon),Kiwi.Renderers.PrimitiveRenderer=function(a,b){this.bufferItemSize=6,this.indices=[],this.nullAtlas=new Kiwi.Plugins.Primitives.NullAtlas,this._tempPoint=new Kiwi.Geom.Point(0,0),this._maxItems=1e3,this._vertexBuffer=new Kiwi.Renderers.GLArrayBuffer(a,this.bufferItemSize),this._indexBuffer=new Kiwi.Renderers.GLElementArrayBuffer(a,1,[]),Kiwi.Renderers.Renderer.call(this,a,b,!0),this.setShaderPair("PrimitiveShader")},Kiwi.extend(Kiwi.Renderers.PrimitiveRenderer,Kiwi.Renderers.Renderer),Kiwi.Renderers.PrimitiveRenderer.prototype.getAtlas=function(){return this.nullAtlas},Kiwi.Renderers.PrimitiveRenderer.prototype.enable=function(a,b){Kiwi.Renderers.Renderer.prototype.enable.call(this,a,b),this.shaderPair=this.shaderManager.requestShader(a,this._shaderPairName,!0),a.uniform2fv(this.shaderPair.uniforms.uResolution.location,b.stageResolution),a.uniformMatrix3fv(this.shaderPair.uniforms.uCamMatrix.location,!1,b.camMatrix)},Kiwi.Renderers.PrimitiveRenderer.prototype.disable=function(a){a.disableVertexAttribArray(this.shaderPair.attributes.aXY),a.disableVertexAttribArray(this.shaderPair.attributes.aRGBA)},Kiwi.Renderers.PrimitiveRenderer.prototype.clear=function(a,b){this._vertexBuffer.clear(),a.uniformMatrix3fv(this.shaderPair.uniforms.uCamMatrix.location,!1,b.camMatrix)},Kiwi.Renderers.PrimitiveRenderer.prototype.updateStageResolution=function(a,b){a.uniform2fv(this.shaderPair.uniforms.uResolution.location,b)},Kiwi.Renderers.PrimitiveRenderer.prototype.setShaderPair=function(a){"string"==typeof a&&(this._shaderPairName=a)},Kiwi.Renderers.PrimitiveRenderer.prototype.addToBatch=function(a,b,c,d,e){var f,g=c.length,h=this._vertexBuffer.items.length/this.bufferItemSize,i=d.length,j=b.transform,k=j.getConcatenatedMatrix();for(f=0;i>f;f++)this._tempPoint.setTo(d[f][0]-j.anchorPointX,d[f][1]-j.anchorPointY),this._tempPoint=k.transformPoint(this._tempPoint),this._vertexBuffer.items.push(this._tempPoint.x,this._tempPoint.y,e[0],e[1],e[2],b.alpha);for(this.indices.length>0&&(this.indices.push(this.indices[this.indices.length-1]),this.indices.push(c[0]+h)),f=0;g>f;f++)this.indices.push(c[f]+h)},Kiwi.Renderers.PrimitiveRenderer.prototype.draw=function(a){var b=0,c=4,d=this.bufferItemSize*c;this._vertexBuffer.uploadBuffer(a,this._vertexBuffer.items),a.enableVertexAttribArray(this.shaderPair.attributes.aXY),a.vertexAttribPointer(this.shaderPair.attributes.aXY,c,a.FLOAT,!1,d,b),b+=2*c,a.enableVertexAttribArray(this.shaderPair.attributes.aRGBA),a.vertexAttribPointer(this.shaderPair.attributes.aRGBA,c,a.FLOAT,!1,d,b),this._indexBuffer.indices=this.indices,this._indexBuffer.refresh(a),a.bindBuffer(a.ELEMENT_ARRAY_BUFFER,this._indexBuffer.buffer),a.drawElements(a.TRIANGLE_STRIP,this._indexBuffer.numItems,a.UNSIGNED_SHORT,0),this.indices=[]},Kiwi.Shaders.PrimitiveShader=function(){Kiwi.Shaders.ShaderPair.call(this),this.attributes={aXY:null,aRGBA:null},this.uniforms={uCamMatrix:{type:"mat3"},uResolution:{type:"2fv"}},this.vertSource=["attribute vec2 aXY;","attribute vec4 aRGBA;","uniform mat3 uCamMatrix;","uniform vec2 uResolution;","varying vec4 vRGBA;","void main(void) {"," vec2 pos = ( uCamMatrix * vec3( aXY, 1 ) ).xy; "," gl_Position = vec4( ( pos / uResolution * 2.0 - 1.0 ) *"," vec2(1 , -1 ), 0, 1 );"," vRGBA = aRGBA;","}"],this.fragSource=["precision mediump float;","varying vec4 vRGBA;","void main(void) {"," gl_FragColor = vRGBA;","}"]},Kiwi.extend(Kiwi.Shaders.PrimitiveShader,Kiwi.Shaders.ShaderPair),Kiwi.Shaders.PrimitiveShader.prototype.init=function(a){Kiwi.Shaders.ShaderPair.prototype.init.call(this,a),this.attributes.aXY=a.getAttribLocation(this.shaderProgram,"aXY"),this.attributes.aRGBA=a.getAttribLocation(this.shaderProgram,"aRGBA"),this.initUniforms(a)},Kiwi.Plugins.Primitives.Star=function(a){var b,c,d,e=8,f=0,g=0;for("undefined"==typeof a.segments&&(a.segments=32),"undefined"!=typeof a.radius&&(a.width=2*a.radius,a.height=2*a.radius),"number"!=typeof a.width&&(a.width=e),"number"!=typeof a.height&&(a.height=e),a.centerOnTransform||(f=.5*a.width,g=.5*a.height),"number"!=typeof a.spikeLength&&(a.spikeLength=1),"number"!=typeof a.spikeRandom&&(a.spikeRandom=0),a.indices=[],a.vertices=[],a.strokeIndices=[],c=0;c<a.segments;c++)a.indices.push(c),a.indices.push(a.segments),a.indices.push((c+1)%a.segments),b=2*Math.PI*c/a.segments,a.vertices.push([.5*a.width*Math.cos(b)+f,.5*a.height*Math.sin(b)+g]),a.strokeIndices.push(c,c+1+a.segments);for(a.vertices.push([f,g]),c=0;c<a.segments;c++)a.indices.push(c),a.indices.push(a.segments+c+1),a.indices.push((c+1)%a.segments),b=2*Math.PI*(c+.5)/a.segments,d=(1+Math.random()*a.spikeRandom)*(a.spikeLength+1)*.5,a.vertices.push([a.width*Math.cos(b)*d+f,a.height*Math.sin(b)*d+g]);a.strokeIndices.push(0),Kiwi.Plugins.Primitives.Polygon.call(this,a),this.anchorPointX=a.anchorPointX||f,this.anchorPointY=a.anchorPointY||g},Kiwi.extend(Kiwi.Plugins.Primitives.Star,Kiwi.Plugins.Primitives.Polygon),Kiwi.Plugins.Primitives.Triangle=function(a){var b,c=8;if(a.indices=[0,1,2],a.strokeIndices=[0,1,2,0],a.vertices=[],a.points)for(b=0;3>b;b++)a.points[b]?a.vertices.push(a.points[b]):a.vertices.push([0,0]);else a.vertices.push([0,0],[0,c],[c,0]);Kiwi.Plugins.Primitives.Polygon.call(this,a)},Kiwi.extend(Kiwi.Plugins.Primitives.Triangle,Kiwi.Plugins.Primitives.Polygon); |