aboutsummaryrefslogtreecommitdiff
path: root/js/lib/geom
diff options
context:
space:
mode:
authorNivesh Rajbhandari2012-03-07 06:12:34 -0800
committerNivesh Rajbhandari2012-03-07 06:12:34 -0800
commit2a8a41711052bb557271c27f82faba8dd13fd880 (patch)
treec79664c2f7b5ce3c22b423376903d9338a0865e2 /js/lib/geom
parentb047a9414cc07f2cb20dbfd7240ca9b0bfdc231d (diff)
downloadninja-2a8a41711052bb557271c27f82faba8dd13fd880.tar.gz
preliminary support for setting gradients on webgl shapes.
Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com>
Diffstat (limited to 'js/lib/geom')
-rwxr-xr-xjs/lib/geom/geom-obj.js65
1 files changed, 52 insertions, 13 deletions
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() {
138 // Methods 138 // Methods
139 /////////////////////////////////////////////////////////////////////// 139 ///////////////////////////////////////////////////////////////////////
140 this.setMaterialColor = function(c, type) { 140 this.setMaterialColor = function(c, type) {
141 if (type == "fill") { 141 if(c.gradientMode) {
142 this._fillColor = c.slice(0); 142 var nMats = 0;
143 if (this._materialArray && this._materialTypeArray) {
144 nMats = this._materialArray.length;
145 }
146
147 var stops = [],
148 colors = c.color;
149
150 var len = colors.length;
151 // TODO - Current shaders only support 4 color stops
152 if(len > 4) {
153 len = 4;
154 }
155
156 for(var n=0; n<len; n++) {
157 var position = colors[n].position/100;
158 var cs = colors[n].value;
159 var stop = [cs.r/255, cs.g/255, cs.b/255, cs.a];
160 stops.push(stop);
161
162 if (nMats === this._materialTypeArray.length) {
163 for (var i=0; i<nMats; i++) {
164 if (this._materialTypeArray[i] == type) {
165 this._materialArray[i].setProperty( "color"+(n+1), stop.slice(0) );
166 this._materialArray[i].setProperty( "colorStop"+(n+1), position );
167 }
168 }
169 }
170 }
171// if (type == "fill") {
172// this._fillColor = c.slice(0);
173// } else {
174// this._strokeColor = c.slice(0);
175// }
143 } else { 176 } else {
144 this._strokeColor = c.slice(0); 177 if (type == "fill") {
145 } 178 this._fillColor = c.slice(0);
179 } else {
180 this._strokeColor = c.slice(0);
181 }
146 182
147 if (this._materialArray && this._materialTypeArray) { 183 if (this._materialArray && this._materialTypeArray) {
148 var nMats = this._materialArray.length; 184 var nMats = this._materialArray.length;
149 if (nMats === this._materialTypeArray.length) { 185 if (nMats === this._materialTypeArray.length) {
150 for (var i=0; i<nMats; i++) { 186 for (var i=0; i<nMats; i++) {
151 if (this._materialTypeArray[i] == type) { 187 if (this._materialTypeArray[i] == type) {
152 this._materialArray[i].setProperty( "color", c.slice(0) ); 188 this._materialArray[i].setProperty( "color", c.slice(0) );
189 }
153 } 190 }
154 } 191 }
155 } 192 }
156 } 193 }
194
195
157 196
158 var world = this.getWorld(); 197 var world = this.getWorld();
159 if (world) { 198 if (world) {