From f931c48a7d0bcf1222cf05787e3294839ed0b9fb Mon Sep 17 00:00:00 2001 From: Pushkar Joshi Date: Wed, 29 Feb 2012 09:47:41 -0800 Subject: resample the brush stroke so we don't have gaps if the path is drawn rapidly, and, allow to change the stroke color, and, more efficient stroke rendering by drawing translated radial gradients (instead of creating new gradients for each stroke sample) --- js/helper-classes/RDGE/GLBrushStroke.js | 74 ++++++++++++++++++++++++++------- 1 file changed, 58 insertions(+), 16 deletions(-) (limited to 'js/helper-classes/RDGE') diff --git a/js/helper-classes/RDGE/GLBrushStroke.js b/js/helper-classes/RDGE/GLBrushStroke.js index 8fb6ab25..52ac79f5 100755 --- a/js/helper-classes/RDGE/GLBrushStroke.js +++ b/js/helper-classes/RDGE/GLBrushStroke.js @@ -34,6 +34,9 @@ function GLBrushStroke() { this._strokeMaterial; this._strokeStyle = "Solid"; + //the wetness of the brush (currently this is multiplied to the square of the stroke width, but todo should be changed + this._WETNESS_FACTOR = 0.010625;//0.0625; + //drawing context this._world = null; @@ -69,21 +72,23 @@ function GLBrushStroke() { this.getPoint = function (index) { return this._Points[index]; } this.addPoint = function (pt) { - //add the point if it is some epsilon away from the previous point - var doAddPoint=true; + //add the point only if it is some epsilon away from the previous point var numPoints = this._Points.length; if (numPoints>0) { + var threshold = this._WETNESS_FACTOR*this._strokeWidth*this._strokeWidth; var prevPt = this._Points[numPoints-1]; var diffPt = [prevPt[0]-pt[0], prevPt[1]-pt[1]]; var diffPtMag = diffPt[0]*diffPt[0] + diffPt[1]*diffPt[1]; - if (diffPtMag<16)//TODO hook this up to the variable that measures flow/wetness of the paint brush...a smaller number-> more samples - doAddPoint=false; - } - if (doAddPoint) { + if (diffPtMag>threshold){ + this._Points.push(pt); + this._dirty=true; + } + }else{ this._Points.push(pt); this._dirty=true; } } + this.insertPoint = function(pt, index){ this._Points.splice(index, 0, pt); this._dirty=true;} this.isDirty = function(){return this._dirty;} this.makeDirty = function(){this._dirty=true;} @@ -127,10 +132,39 @@ function GLBrushStroke() { this.computeMetaGeometry = function(){ if (this._dirty){ + var numPoints = this._Points.length; + + //**** add samples to the path if needed...linear interpolation for now + if (numPoints>1) { + var threshold = this._WETNESS_FACTOR*this._strokeWidth*this._strokeWidth; + var prevPt = this._Points[0]; + var prevIndex = 0; + for (var i=1;ithreshold){ + //insert points along the prev. to current point + var numNewPoints = Math.floor(distance/threshold); + for (var j=0;j