diff --git a/src/pixi/core/Matrix.js b/src/pixi/core/Matrix.js index 1f5a67a..5414ca7 100644 --- a/src/pixi/core/Matrix.js +++ b/src/pixi/core/Matrix.js @@ -291,3 +291,5 @@ return dest; }; + +PIXI.identityMatrix = PIXI.mat3.create(); diff --git a/src/pixi/core/Matrix.js b/src/pixi/core/Matrix.js index 1f5a67a..5414ca7 100644 --- a/src/pixi/core/Matrix.js +++ b/src/pixi/core/Matrix.js @@ -291,3 +291,5 @@ return dest; }; + +PIXI.identityMatrix = PIXI.mat3.create(); diff --git a/src/pixi/display/DisplayObject.js b/src/pixi/display/DisplayObject.js index 76cacac..17dae50 100644 --- a/src/pixi/display/DisplayObject.js +++ b/src/pixi/display/DisplayObject.js @@ -184,6 +184,7 @@ */ this._bounds = new PIXI.Rectangle(0, 0, 1, 1); this._currentBounds = null; + this._mask = null; /* * MOUSE Callbacks @@ -436,6 +437,21 @@ return PIXI.EmptyRectangle; }; +PIXI.DisplayObject.prototype.getLocalBounds = function() +{ + var matrixCache = this.worldTransform; + + this.worldTransform = PIXI.identityMatrix; + + this.updateTransform(); + + var bounds = this.getBounds(); + + this.worldTransform = matrixCache; + + return bounds; +}; + PIXI.DisplayObject.prototype._renderWebGL = function(renderSession) { diff --git a/src/pixi/core/Matrix.js b/src/pixi/core/Matrix.js index 1f5a67a..5414ca7 100644 --- a/src/pixi/core/Matrix.js +++ b/src/pixi/core/Matrix.js @@ -291,3 +291,5 @@ return dest; }; + +PIXI.identityMatrix = PIXI.mat3.create(); diff --git a/src/pixi/display/DisplayObject.js b/src/pixi/display/DisplayObject.js index 76cacac..17dae50 100644 --- a/src/pixi/display/DisplayObject.js +++ b/src/pixi/display/DisplayObject.js @@ -184,6 +184,7 @@ */ this._bounds = new PIXI.Rectangle(0, 0, 1, 1); this._currentBounds = null; + this._mask = null; /* * MOUSE Callbacks @@ -436,6 +437,21 @@ return PIXI.EmptyRectangle; }; +PIXI.DisplayObject.prototype.getLocalBounds = function() +{ + var matrixCache = this.worldTransform; + + this.worldTransform = PIXI.identityMatrix; + + this.updateTransform(); + + var bounds = this.getBounds(); + + this.worldTransform = matrixCache; + + return bounds; +}; + PIXI.DisplayObject.prototype._renderWebGL = function(renderSession) { diff --git a/src/pixi/display/DisplayObjectContainer.js b/src/pixi/display/DisplayObjectContainer.js index 8ea753c..fb07d11 100644 --- a/src/pixi/display/DisplayObjectContainer.js +++ b/src/pixi/display/DisplayObjectContainer.js @@ -39,14 +39,15 @@ /* Object.defineProperty(PIXI.DisplayObjectContainer.prototype, 'width', { get: function() { - return this.scale.x * this.getBounds().width; + return this.scale.x * this.getLocalBounds().width; }, set: function(value) { - this.scale.x = value / (this.getBounds().width/this.scale.x); + this.scale.x = value / (this.getLocalBounds().width/this.scale.x); this._width = value; } }); */ + /** * The height of the displayObjectContainer, setting this will actually modify the scale to acheive the value set * @@ -57,10 +58,10 @@ /* Object.defineProperty(PIXI.DisplayObjectContainer.prototype, 'height', { get: function() { - return this.scale.y * this.getBounds().height; + return this.scale.y * this.getLocalBounds().height; }, set: function(value) { - this.scale.y = value / (this.getBounds().height/this.scale.y); + this.scale.y = value / (this.getLocalBounds().height/this.scale.y); this._height = value; } }); @@ -159,7 +160,7 @@ } else { - throw new Error('Both the supplied DisplayObjects must be a child of the caller ' + this); + throw new Error('The supplied DisplayObjects must be a child of the caller ' + this); } }; @@ -341,3 +342,5 @@ renderSession.maskManager.popMask(renderSession.context); } }; + + diff --git a/src/pixi/core/Matrix.js b/src/pixi/core/Matrix.js index 1f5a67a..5414ca7 100644 --- a/src/pixi/core/Matrix.js +++ b/src/pixi/core/Matrix.js @@ -291,3 +291,5 @@ return dest; }; + +PIXI.identityMatrix = PIXI.mat3.create(); diff --git a/src/pixi/display/DisplayObject.js b/src/pixi/display/DisplayObject.js index 76cacac..17dae50 100644 --- a/src/pixi/display/DisplayObject.js +++ b/src/pixi/display/DisplayObject.js @@ -184,6 +184,7 @@ */ this._bounds = new PIXI.Rectangle(0, 0, 1, 1); this._currentBounds = null; + this._mask = null; /* * MOUSE Callbacks @@ -436,6 +437,21 @@ return PIXI.EmptyRectangle; }; +PIXI.DisplayObject.prototype.getLocalBounds = function() +{ + var matrixCache = this.worldTransform; + + this.worldTransform = PIXI.identityMatrix; + + this.updateTransform(); + + var bounds = this.getBounds(); + + this.worldTransform = matrixCache; + + return bounds; +}; + PIXI.DisplayObject.prototype._renderWebGL = function(renderSession) { diff --git a/src/pixi/display/DisplayObjectContainer.js b/src/pixi/display/DisplayObjectContainer.js index 8ea753c..fb07d11 100644 --- a/src/pixi/display/DisplayObjectContainer.js +++ b/src/pixi/display/DisplayObjectContainer.js @@ -39,14 +39,15 @@ /* Object.defineProperty(PIXI.DisplayObjectContainer.prototype, 'width', { get: function() { - return this.scale.x * this.getBounds().width; + return this.scale.x * this.getLocalBounds().width; }, set: function(value) { - this.scale.x = value / (this.getBounds().width/this.scale.x); + this.scale.x = value / (this.getLocalBounds().width/this.scale.x); this._width = value; } }); */ + /** * The height of the displayObjectContainer, setting this will actually modify the scale to acheive the value set * @@ -57,10 +58,10 @@ /* Object.defineProperty(PIXI.DisplayObjectContainer.prototype, 'height', { get: function() { - return this.scale.y * this.getBounds().height; + return this.scale.y * this.getLocalBounds().height; }, set: function(value) { - this.scale.y = value / (this.getBounds().height/this.scale.y); + this.scale.y = value / (this.getLocalBounds().height/this.scale.y); this._height = value; } }); @@ -159,7 +160,7 @@ } else { - throw new Error('Both the supplied DisplayObjects must be a child of the caller ' + this); + throw new Error('The supplied DisplayObjects must be a child of the caller ' + this); } }; @@ -341,3 +342,5 @@ renderSession.maskManager.popMask(renderSession.context); } }; + + diff --git a/src/pixi/primitives/Graphics.js b/src/pixi/primitives/Graphics.js index 7e9be3a..3b0bca0 100644 --- a/src/pixi/primitives/Graphics.js +++ b/src/pixi/primitives/Graphics.js @@ -65,12 +65,24 @@ this.currentPath = {points:[]}; this._webGL = []; + + this.isMask = false; }; // constructor PIXI.Graphics.prototype = Object.create( PIXI.DisplayObjectContainer.prototype ); PIXI.Graphics.prototype.constructor = PIXI.Graphics; +Object.defineProperty(PIXI.Graphics.prototype, 'cacheAsBitmap', { + get: function() { + return this._cacheAsBitmap + }, + set: function(value) { + this._cacheAsBitmap = value; + } +}); + + /** * Specifies a line style used for subsequent calls to Graphics methods such as the lineTo() method or the drawCircle() method. * @@ -240,29 +252,34 @@ // if the sprite is not visible or the alpha is 0 then no need to render this element if(this.visible === false || this.alpha === 0 || this.isMask === true)return; - - - renderSession.spriteBatch.stop(); - - if(this._mask)renderSession.maskManager.pushMask(this.mask, renderSession); - if(this._filters)renderSession.filterManager.pushFilter(this._filterBlock); - - // check blend mode - if(this.blendMode !== renderSession.spriteBatch.currentBlendMode) + if(this._cacheAsBitmap) { - this.spriteBatch.currentBlendMode = this.blendMode; - var blendModeWebGL = PIXI.blendModesWebGL[renderSession.spriteBatch.currentBlendMode]; - this.spriteBatch.gl.blendFunc(blendModeWebGL[0], blendModeWebGL[1]); - } - - PIXI.WebGLGraphics.renderGraphics(this, renderSession); - - if(this._filters)renderSession.filterManager.popFilter(); - if(this._mask)renderSession.maskManager.popMask(renderSession); - - renderSession.drawCount++; - renderSession.spriteBatch.start(); + } + else + { + renderSession.spriteBatch.stop(); + + if(this._mask)renderSession.maskManager.pushMask(this.mask, renderSession); + if(this._filters)renderSession.filterManager.pushFilter(this._filterBlock); + + // check blend mode + if(this.blendMode !== renderSession.spriteBatch.currentBlendMode) + { + this.spriteBatch.currentBlendMode = this.blendMode; + var blendModeWebGL = PIXI.blendModesWebGL[renderSession.spriteBatch.currentBlendMode]; + this.spriteBatch.gl.blendFunc(blendModeWebGL[0], blendModeWebGL[1]); + } + + PIXI.WebGLGraphics.renderGraphics(this, renderSession); + + if(this._filters)renderSession.filterManager.popFilter(); + if(this._mask)renderSession.maskManager.popMask(renderSession); + + renderSession.drawCount++; + + renderSession.spriteBatch.start(); + } }; PIXI.Graphics.prototype._renderCanvas = function(renderSession) diff --git a/src/pixi/core/Matrix.js b/src/pixi/core/Matrix.js index 1f5a67a..5414ca7 100644 --- a/src/pixi/core/Matrix.js +++ b/src/pixi/core/Matrix.js @@ -291,3 +291,5 @@ return dest; }; + +PIXI.identityMatrix = PIXI.mat3.create(); diff --git a/src/pixi/display/DisplayObject.js b/src/pixi/display/DisplayObject.js index 76cacac..17dae50 100644 --- a/src/pixi/display/DisplayObject.js +++ b/src/pixi/display/DisplayObject.js @@ -184,6 +184,7 @@ */ this._bounds = new PIXI.Rectangle(0, 0, 1, 1); this._currentBounds = null; + this._mask = null; /* * MOUSE Callbacks @@ -436,6 +437,21 @@ return PIXI.EmptyRectangle; }; +PIXI.DisplayObject.prototype.getLocalBounds = function() +{ + var matrixCache = this.worldTransform; + + this.worldTransform = PIXI.identityMatrix; + + this.updateTransform(); + + var bounds = this.getBounds(); + + this.worldTransform = matrixCache; + + return bounds; +}; + PIXI.DisplayObject.prototype._renderWebGL = function(renderSession) { diff --git a/src/pixi/display/DisplayObjectContainer.js b/src/pixi/display/DisplayObjectContainer.js index 8ea753c..fb07d11 100644 --- a/src/pixi/display/DisplayObjectContainer.js +++ b/src/pixi/display/DisplayObjectContainer.js @@ -39,14 +39,15 @@ /* Object.defineProperty(PIXI.DisplayObjectContainer.prototype, 'width', { get: function() { - return this.scale.x * this.getBounds().width; + return this.scale.x * this.getLocalBounds().width; }, set: function(value) { - this.scale.x = value / (this.getBounds().width/this.scale.x); + this.scale.x = value / (this.getLocalBounds().width/this.scale.x); this._width = value; } }); */ + /** * The height of the displayObjectContainer, setting this will actually modify the scale to acheive the value set * @@ -57,10 +58,10 @@ /* Object.defineProperty(PIXI.DisplayObjectContainer.prototype, 'height', { get: function() { - return this.scale.y * this.getBounds().height; + return this.scale.y * this.getLocalBounds().height; }, set: function(value) { - this.scale.y = value / (this.getBounds().height/this.scale.y); + this.scale.y = value / (this.getLocalBounds().height/this.scale.y); this._height = value; } }); @@ -159,7 +160,7 @@ } else { - throw new Error('Both the supplied DisplayObjects must be a child of the caller ' + this); + throw new Error('The supplied DisplayObjects must be a child of the caller ' + this); } }; @@ -341,3 +342,5 @@ renderSession.maskManager.popMask(renderSession.context); } }; + + diff --git a/src/pixi/primitives/Graphics.js b/src/pixi/primitives/Graphics.js index 7e9be3a..3b0bca0 100644 --- a/src/pixi/primitives/Graphics.js +++ b/src/pixi/primitives/Graphics.js @@ -65,12 +65,24 @@ this.currentPath = {points:[]}; this._webGL = []; + + this.isMask = false; }; // constructor PIXI.Graphics.prototype = Object.create( PIXI.DisplayObjectContainer.prototype ); PIXI.Graphics.prototype.constructor = PIXI.Graphics; +Object.defineProperty(PIXI.Graphics.prototype, 'cacheAsBitmap', { + get: function() { + return this._cacheAsBitmap + }, + set: function(value) { + this._cacheAsBitmap = value; + } +}); + + /** * Specifies a line style used for subsequent calls to Graphics methods such as the lineTo() method or the drawCircle() method. * @@ -240,29 +252,34 @@ // if the sprite is not visible or the alpha is 0 then no need to render this element if(this.visible === false || this.alpha === 0 || this.isMask === true)return; - - - renderSession.spriteBatch.stop(); - - if(this._mask)renderSession.maskManager.pushMask(this.mask, renderSession); - if(this._filters)renderSession.filterManager.pushFilter(this._filterBlock); - - // check blend mode - if(this.blendMode !== renderSession.spriteBatch.currentBlendMode) + if(this._cacheAsBitmap) { - this.spriteBatch.currentBlendMode = this.blendMode; - var blendModeWebGL = PIXI.blendModesWebGL[renderSession.spriteBatch.currentBlendMode]; - this.spriteBatch.gl.blendFunc(blendModeWebGL[0], blendModeWebGL[1]); - } - - PIXI.WebGLGraphics.renderGraphics(this, renderSession); - - if(this._filters)renderSession.filterManager.popFilter(); - if(this._mask)renderSession.maskManager.popMask(renderSession); - - renderSession.drawCount++; - renderSession.spriteBatch.start(); + } + else + { + renderSession.spriteBatch.stop(); + + if(this._mask)renderSession.maskManager.pushMask(this.mask, renderSession); + if(this._filters)renderSession.filterManager.pushFilter(this._filterBlock); + + // check blend mode + if(this.blendMode !== renderSession.spriteBatch.currentBlendMode) + { + this.spriteBatch.currentBlendMode = this.blendMode; + var blendModeWebGL = PIXI.blendModesWebGL[renderSession.spriteBatch.currentBlendMode]; + this.spriteBatch.gl.blendFunc(blendModeWebGL[0], blendModeWebGL[1]); + } + + PIXI.WebGLGraphics.renderGraphics(this, renderSession); + + if(this._filters)renderSession.filterManager.popFilter(); + if(this._mask)renderSession.maskManager.popMask(renderSession); + + renderSession.drawCount++; + + renderSession.spriteBatch.start(); + } }; PIXI.Graphics.prototype._renderCanvas = function(renderSession) diff --git a/src/pixi/renderers/webgl/WebGLRenderer.js b/src/pixi/renderers/webgl/WebGLRenderer.js index 41e6165..cfb175c 100644 --- a/src/pixi/renderers/webgl/WebGLRenderer.js +++ b/src/pixi/renderers/webgl/WebGLRenderer.js @@ -102,6 +102,7 @@ // this.renderSession = {}; this.renderSession.gl = this.gl; + this.renderSession.drawCount = 0; this.renderSession.shaderManager = this.shaderManager; this.renderSession.maskManager = this.maskManager; this.renderSession.filterManager = this.filterManager;