From ac27d538af33ca8d67d3d88729f49c05793afda7 Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Mon, 9 Jul 2012 11:43:36 -0700 Subject: PI, drawing and editing fixes for shapes and materials. IKNinja-1841 - Cannot change webgl shape with LinearGradient and RadialGradient to solid color. IKNINJA-1851 - Cannot draw webgl shapes with Linear/RadialGradient material. IKNINJA-1864 - PI doesn't update the color of shape if WebGL material switches to Flat. IKNINJA-1886 - Gradient edits not applied to WebGL Stage object. Signed-off-by: Nivesh Rajbhandari --- js/lib/geom/circle.js | 20 +++++++++++++++++--- js/lib/geom/geom-obj.js | 25 ++++--------------------- js/lib/geom/line.js | 13 +++++++++++-- js/lib/geom/rectangle.js | 17 +++++++++++++++-- 4 files changed, 47 insertions(+), 28 deletions(-) (limited to 'js/lib/geom') diff --git a/js/lib/geom/circle.js b/js/lib/geom/circle.js index 086c1058..848ae10d 100755 --- a/js/lib/geom/circle.js +++ b/js/lib/geom/circle.js @@ -61,14 +61,28 @@ exports.Circle = Object.create(GeomObj, { } else { this._strokeMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); } - if (strokeColor && this._strokeMaterial.hasProperty( "color" )) this._strokeMaterial.setProperty( "color", this._strokeColor ); + + if(strokeColor) { + if(this._strokeMaterial.hasProperty("color")) { + this._strokeMaterial.setProperty( "color", this._strokeColor ); + } else if (this._strokeMaterial && (this._strokeMaterial.gradientType === this._strokeColor.gradientMode)) { + this._strokeMaterial.setGradientData(this._strokeColor.color); + } + } if(fillMaterial) { this._fillMaterial = fillMaterial.dup(); } else { - this._fillMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); + this._fillMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); + } + + if(fillColor) { + if(this._fillMaterial.hasProperty("color")) { + this._fillMaterial.setProperty( "color", this._fillColor ); + } else if (this._fillMaterial && (this._fillMaterial.gradientType === this._fillColor.gradientMode)) { + this._fillMaterial.setGradientData(this._fillColor.color); + } } - if (fillColor && this._fillMaterial.hasProperty( "color" )) this._fillMaterial.setProperty( "color", this._fillColor ); } }, diff --git a/js/lib/geom/geom-obj.js b/js/lib/geom/geom-obj.js index 3a7a5619..66f557dd 100755 --- a/js/lib/geom/geom-obj.js +++ b/js/lib/geom/geom-obj.js @@ -191,27 +191,10 @@ exports.GeomObj = Object.create(Object.prototype, { nMats = this._materialArray.length; } - var stops = [], - colors = c.color; - - var len = colors.length; - // TODO - Current shaders only support 4 color stops - if (len > 4) { - len = 4; - } - - for (var n = 0; n < len; n++) { - var position = colors[n].position / 100; - var cs = colors[n].value; - var stop = [cs.r / 255, cs.g / 255, cs.b / 255, cs.a]; - stops.push(stop); - - if (nMats === this._materialTypeArray.length) { - for (i = 0; i < nMats; i++) { - if (this._materialTypeArray[i] == type) { - this._materialArray[i].setProperty("color" + (n + 1), stop.slice(0)); - this._materialArray[i].setProperty("colorStop" + (n + 1), position); - } + if (nMats === this._materialTypeArray.length) { + for (i = 0; i < nMats; i++) { + if (this._materialTypeArray[i] == type) { + this._materialArray[i].setGradientData(c.color); } } } diff --git a/js/lib/geom/line.js b/js/lib/geom/line.js index a016d7a3..f782f2a8 100755 --- a/js/lib/geom/line.js +++ b/js/lib/geom/line.js @@ -63,8 +63,17 @@ exports.Line = Object.create(GeomObj, { this._materialSpecular = [0.4, 0.4, 0.4, 1.0]; if(strokeMaterial) { - this._strokeMaterial = strokeMaterial; - if (strokeColor && this._strokeMaterial.hasProperty( "color" )) this._strokeMaterial.setProperty( "color", this._strokeColor ); + this._strokeMaterial = strokeMaterial.dup(); + } else { + this._strokeMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); + } + + if(strokeColor) { + if(this._strokeMaterial.hasProperty("color")) { + this._strokeMaterial.setProperty( "color", this._strokeColor ); + } else if (this._strokeMaterial && (this._strokeMaterial.gradientType === this._strokeColor.gradientMode)) { + this._strokeMaterial.setGradientData(this._strokeColor.color); + } } } }, diff --git a/js/lib/geom/rectangle.js b/js/lib/geom/rectangle.js index 81a8556d..3e4c469a 100755 --- a/js/lib/geom/rectangle.js +++ b/js/lib/geom/rectangle.js @@ -77,15 +77,28 @@ exports.Rectangle = Object.create(GeomObj, { } else { this._strokeMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); } - if (strokeColor && this._strokeMaterial.hasProperty( "color" )) this._strokeMaterial.setProperty( "color", this._strokeColor ); + if(strokeColor) { + if(this._strokeMaterial.hasProperty("color")) { + this._strokeMaterial.setProperty( "color", this._strokeColor ); + } else if (this._strokeMaterial && (this._strokeMaterial.gradientType === this._strokeColor.gradientMode)) { + this._strokeMaterial.setGradientData(this._strokeColor.color); + } + } if(fillMaterial) { this._fillMaterial = fillMaterial.dup(); } else { this._fillMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); } - if (fillColor && this._fillMaterial.hasProperty( "color" )) this._fillMaterial.setProperty( "color", this._fillColor ); + + if(fillColor) { + if(this._fillMaterial.hasProperty("color")) { + this._fillMaterial.setProperty( "color", this._fillColor ); + } else if (this._fillMaterial && (this._fillMaterial.gradientType === this._fillColor.gradientMode)) { + this._fillMaterial.setGradientData(this._fillColor.color); + } + } } }, -- cgit v1.2.3