From 2a8a41711052bb557271c27f82faba8dd13fd880 Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Wed, 7 Mar 2012 06:12:34 -0800 Subject: preliminary support for setting gradients on webgl shapes. Signed-off-by: Nivesh Rajbhandari --- js/lib/geom/geom-obj.js | 65 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 52 insertions(+), 13 deletions(-) (limited to 'js/lib/geom/geom-obj.js') diff --git a/js/lib/geom/geom-obj.js b/js/lib/geom/geom-obj.js index c5880843..726c3595 100755 --- a/js/lib/geom/geom-obj.js +++ b/js/lib/geom/geom-obj.js @@ -138,22 +138,61 @@ var GeomObj = function GLGeomObj() { // Methods /////////////////////////////////////////////////////////////////////// this.setMaterialColor = function(c, type) { - if (type == "fill") { - this._fillColor = c.slice(0); + if(c.gradientMode) { + var nMats = 0; + if (this._materialArray && this._materialTypeArray) { + 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 --- js/lib/geom/geom-obj.js | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) (limited to 'js/lib/geom/geom-obj.js') diff --git a/js/lib/geom/geom-obj.js b/js/lib/geom/geom-obj.js index 726c3595..1ea74475 100755 --- a/js/lib/geom/geom-obj.js +++ b/js/lib/geom/geom-obj.js @@ -138,8 +138,10 @@ var GeomObj = function GLGeomObj() { // Methods /////////////////////////////////////////////////////////////////////// this.setMaterialColor = function(c, type) { + var i = 0, + nMats = 0; if(c.gradientMode) { - var nMats = 0; + // Gradient support if (this._materialArray && this._materialTypeArray) { nMats = this._materialArray.length; } @@ -160,7 +162,7 @@ var GeomObj = function GLGeomObj() { stops.push(stop); if (nMats === this._materialTypeArray.length) { - for (var i=0; i --- js/lib/geom/geom-obj.js | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'js/lib/geom/geom-obj.js') diff --git a/js/lib/geom/geom-obj.js b/js/lib/geom/geom-obj.js index 1ea74475..fb1cb246 100755 --- a/js/lib/geom/geom-obj.js +++ b/js/lib/geom/geom-obj.js @@ -305,6 +305,49 @@ var GeomObj = function GLGeomObj() { return rtnStr; }; + // Gradient stops for rgba(255,0,0,1) at 0%; rgba(0,255,0,1) at 33%; rgba(0,0,255,1) at 100% will return + // 255,0,0,1@0;0,255,0,1@33;0,0,255,1@100 + this.gradientToString = function(colors) { + var rtnStr = ""; + if(colors && colors.length) { + var c = colors[0], + len = colors.length; + + rtnStr += String(c.value.r + "," + c.value.g + "," + c.value.b + "," + c.value.a + "@" + c.position); + for(var i=1; i