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;b1){for(b=0;b2)for(3===a.length&&this._strokePolyIndices.push(a[0]),b=0;bMath.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;gb;b++)c=a[b],c[0]e&&(e=c[0]),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;i2){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;i0){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;df;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;cb;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);