aboutsummaryrefslogtreecommitdiff
path: root/js/lib/geom/geom-obj.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/geom/geom-obj.js')
-rwxr-xr-xjs/lib/geom/geom-obj.js123
1 files changed, 103 insertions, 20 deletions
diff --git a/js/lib/geom/geom-obj.js b/js/lib/geom/geom-obj.js
index 2a5b0641..a4813326 100755
--- a/js/lib/geom/geom-obj.js
+++ b/js/lib/geom/geom-obj.js
@@ -161,22 +161,61 @@ var GeomObj = function GLGeomObj() {
161 // Methods 161 // Methods
162 /////////////////////////////////////////////////////////////////////// 162 ///////////////////////////////////////////////////////////////////////
163 this.setMaterialColor = function(c, type) { 163 this.setMaterialColor = function(c, type) {
164 if (type == "fill") { 164 var i = 0,
165 this._fillColor = c.slice(0); 165 nMats = 0;
166 if(c.gradientMode) {
167 // Gradient support
168 if (this._materialArray && this._materialTypeArray) {
169 nMats = this._materialArray.length;
170 }
171
172 var stops = [],
173 colors = c.color;
174
175 var len = colors.length;
176 // TODO - Current shaders only support 4 color stops
177 if(len > 4) {
178 len = 4;
179 }
180
181 for(var n=0; n<len; n++) {
182 var position = colors[n].position/100;
183 var cs = colors[n].value;
184 var stop = [cs.r/255, cs.g/255, cs.b/255, cs.a];
185 stops.push(stop);
186
187 if (nMats === this._materialTypeArray.length) {
188 for (i=0; i<nMats; i++) {
189 if (this._materialTypeArray[i] == type) {
190 this._materialArray[i].setProperty( "color"+(n+1), stop.slice(0) );
191 this._materialArray[i].setProperty( "colorStop"+(n+1), position );
192 }
193 }
194 }
195 }
196 if (type === "fill") {
197 this._fillColor = c;
198 } else {
199 this._strokeColor = c;
200 }
166 } else { 201 } else {
167 this._strokeColor = c.slice(0); 202 if (type === "fill") {
168 } 203 this._fillColor = c.slice(0);
204 } else {
205 this._strokeColor = c.slice(0);
206 }
169 207
170 if (this._materialArray && this._materialTypeArray) { 208 if (this._materialArray && this._materialTypeArray) {
171 var nMats = this._materialArray.length; 209 nMats = this._materialArray.length;
172 if (nMats === this._materialTypeArray.length) { 210 if (nMats === this._materialTypeArray.length) {
173 for (var i=0; i<nMats; i++) { 211 for (i=0; i<nMats; i++) {
174 if (this._materialTypeArray[i] == type) { 212 if (this._materialTypeArray[i] == type) {
175 this._materialArray[i].setProperty( "color", c.slice(0) ); 213 this._materialArray[i].setProperty( "color", c.slice(0) );
214 }
176 } 215 }
177 } 216 }
178 } 217 }
179 } 218 }
180 219
181 var world = this.getWorld(); 220 var world = this.getWorld();
182 if (world) { 221 if (world) {
@@ -194,14 +233,15 @@ var GeomObj = function GLGeomObj() {
194 233
195 if (strokeMaterial) { 234 if (strokeMaterial) {
196 strokeMaterial.init( this.getWorld() ); 235 strokeMaterial.init( this.getWorld() );
197 if(this._strokeColor) {
198 strokeMaterial.setProperty("color", this._strokeColor);
199 }
200 } 236 }
201 237
202 this._materialArray.push( strokeMaterial ); 238 this._materialArray.push( strokeMaterial );
203 this._materialTypeArray.push( "stroke" ); 239 this._materialTypeArray.push( "stroke" );
204 240
241 if(this._strokeColor) {
242 this.setStrokeColor(this._strokeColor);
243 }
244
205 return strokeMaterial; 245 return strokeMaterial;
206 }; 246 };
207 247
@@ -215,15 +255,15 @@ var GeomObj = function GLGeomObj() {
215 255
216 if (fillMaterial) { 256 if (fillMaterial) {
217 fillMaterial.init( this.getWorld() ); 257 fillMaterial.init( this.getWorld() );
218 //if(!this.getFillMaterial() && this._fillColor)
219 if (this._fillColor) {
220 fillMaterial.setProperty("color", this._fillColor);
221 }
222 } 258 }
223 259
224 this._materialArray.push( fillMaterial ); 260 this._materialArray.push( fillMaterial );
225 this._materialTypeArray.push( "fill" ); 261 this._materialTypeArray.push( "fill" );
226 262
263 if (this._fillColor) {
264 this.setFillColor(this._fillColor);
265 }
266
227 return fillMaterial; 267 return fillMaterial;
228 }; 268 };
229 269
@@ -433,6 +473,49 @@ var GeomObj = function GLGeomObj() {
433 return rtnStr; 473 return rtnStr;
434 }; 474 };
435 475
476 // 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
477 // 255,0,0,1@0;0,255,0,1@33;0,0,255,1@100
478 this.gradientToString = function(colors) {
479 var rtnStr = "";
480 if(colors && colors.length) {
481 var c = colors[0],
482 len = colors.length;
483
484 rtnStr += String(c.value.r + "," + c.value.g + "," + c.value.b + "," + c.value.a + "@" + c.position);
485 for(var i=1; i<len; i++) {
486 c = colors[i];
487 rtnStr += ";" + String(c.value.r + "," + c.value.g + "," + c.value.b + "," + c.value.a + "@" + c.position);
488 }
489 }
490 return rtnStr;
491 };
492
493 // Given a gradientStr "255,0,0,1@0;0,255,0,1@33;0,0,255,1@100" will return:
494 // colors array [{position:0, value:{r:255, g:0, b:0, a:1}},
495 // {position:33, value:{r:0, g:255, b:0, a:1}},
496 // {position:100, value:{r:0, g:0, b:255, a:1}}
497 // ]
498 this.stringToGradient = function(gradientStr) {
499 var rtnArr = [];
500
501 var i,
502 len,
503 stops,
504 stop,
505 c;
506
507 stops = gradientStr.split(";");
508 len = stops.length;
509 for(i=0; i<len; i++)
510 {
511 stop = stops[i].split("@");
512 c = stop[0].split(",");
513 rtnArr.push({ position: Number(stop[1]), value:{r:Number(c[0]), g:Number(c[1]), b:Number(c[2]), a:Number(c[3])} });
514 }
515
516 return rtnArr;
517 };
518
436 /* 519 /*
437 this.export = function() { 520 this.export = function() {
438 var rtnStr; 521 var rtnStr;