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 35ebadb9..a64980e0 100755
--- a/js/lib/geom/geom-obj.js
+++ b/js/lib/geom/geom-obj.js
@@ -159,22 +159,61 @@ var GeomObj = function GLGeomObj() {
159 // Methods 159 // Methods
160 /////////////////////////////////////////////////////////////////////// 160 ///////////////////////////////////////////////////////////////////////
161 this.setMaterialColor = function(c, type) { 161 this.setMaterialColor = function(c, type) {
162 if (type == "fill") { 162 var i = 0,
163 this._fillColor = c.slice(0); 163 nMats = 0;
164 if(c.gradientMode) {
165 // Gradient support
166 if (this._materialArray && this._materialTypeArray) {
167 nMats = this._materialArray.length;
168 }
169
170 var stops = [],
171 colors = c.color;
172
173 var len = colors.length;
174 // TODO - Current shaders only support 4 color stops
175 if(len > 4) {
176 len = 4;
177 }
178
179 for(var n=0; n<len; n++) {
180 var position = colors[n].position/100;
181 var cs = colors[n].value;
182 var stop = [cs.r/255, cs.g/255, cs.b/255, cs.a];
183 stops.push(stop);
184
185 if (nMats === this._materialTypeArray.length) {
186 for (i=0; i<nMats; i++) {
187 if (this._materialTypeArray[i] == type) {
188 this._materialArray[i].setProperty( "color"+(n+1), stop.slice(0) );
189 this._materialArray[i].setProperty( "colorStop"+(n+1), position );
190 }
191 }
192 }
193 }
194 if (type === "fill") {
195 this._fillColor = c;
196 } else {
197 this._strokeColor = c;
198 }
164 } else { 199 } else {
165 this._strokeColor = c.slice(0); 200 if (type === "fill") {
166 } 201 this._fillColor = c.slice(0);
202 } else {
203 this._strokeColor = c.slice(0);
204 }
167 205
168 if (this._materialArray && this._materialTypeArray) { 206 if (this._materialArray && this._materialTypeArray) {
169 var nMats = this._materialArray.length; 207 nMats = this._materialArray.length;
170 if (nMats === this._materialTypeArray.length) { 208 if (nMats === this._materialTypeArray.length) {
171 for (var i=0; i<nMats; i++) { 209 for (i=0; i<nMats; i++) {
172 if (this._materialTypeArray[i] == type) { 210 if (this._materialTypeArray[i] == type) {
173 this._materialArray[i].setProperty( "color", c.slice(0) ); 211 this._materialArray[i].setProperty( "color", c.slice(0) );
212 }
174 } 213 }
175 } 214 }
176 } 215 }
177 } 216 }
178 217
179 var world = this.getWorld(); 218 var world = this.getWorld();
180 if (world) { 219 if (world) {
@@ -192,14 +231,15 @@ var GeomObj = function GLGeomObj() {
192 231
193 if (strokeMaterial) { 232 if (strokeMaterial) {
194 strokeMaterial.init( this.getWorld() ); 233 strokeMaterial.init( this.getWorld() );
195 if(this._strokeColor) {
196 strokeMaterial.setProperty("color", this._strokeColor);
197 }
198 } 234 }
199 235
200 this._materialArray.push( strokeMaterial ); 236 this._materialArray.push( strokeMaterial );
201 this._materialTypeArray.push( "stroke" ); 237 this._materialTypeArray.push( "stroke" );
202 238
239 if(this._strokeColor) {
240 this.setStrokeColor(this._strokeColor);
241 }
242
203 return strokeMaterial; 243 return strokeMaterial;
204 }; 244 };
205 245
@@ -213,15 +253,15 @@ var GeomObj = function GLGeomObj() {
213 253
214 if (fillMaterial) { 254 if (fillMaterial) {
215 fillMaterial.init( this.getWorld() ); 255 fillMaterial.init( this.getWorld() );
216 //if(!this.getFillMaterial() && this._fillColor)
217 if (this._fillColor) {
218 fillMaterial.setProperty("color", this._fillColor);
219 }
220 } 256 }
221 257
222 this._materialArray.push( fillMaterial ); 258 this._materialArray.push( fillMaterial );
223 this._materialTypeArray.push( "fill" ); 259 this._materialTypeArray.push( "fill" );
224 260
261 if (this._fillColor) {
262 this.setFillColor(this._fillColor);
263 }
264
225 return fillMaterial; 265 return fillMaterial;
226 }; 266 };
227 267
@@ -354,6 +394,49 @@ var GeomObj = function GLGeomObj() {
354 return rtnStr; 394 return rtnStr;
355 }; 395 };
356 396
397 // 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
398 // 255,0,0,1@0;0,255,0,1@33;0,0,255,1@100
399 this.gradientToString = function(colors) {
400 var rtnStr = "";
401 if(colors && colors.length) {
402 var c = colors[0],
403 len = colors.length;
404
405 rtnStr += String(c.value.r + "," + c.value.g + "," + c.value.b + "," + c.value.a + "@" + c.position);
406 for(var i=1; i<len; i++) {
407 c = colors[i];
408 rtnStr += ";" + String(c.value.r + "," + c.value.g + "," + c.value.b + "," + c.value.a + "@" + c.position);
409 }
410 }
411 return rtnStr;
412 };
413
414 // Given a gradientStr "255,0,0,1@0;0,255,0,1@33;0,0,255,1@100" will return:
415 // colors array [{position:0, value:{r:255, g:0, b:0, a:1}},
416 // {position:33, value:{r:0, g:255, b:0, a:1}},
417 // {position:100, value:{r:0, g:0, b:255, a:1}}
418 // ]
419 this.stringToGradient = function(gradientStr) {
420 var rtnArr = [];
421
422 var i,
423 len,
424 stops,
425 stop,
426 c;
427
428 stops = gradientStr.split(";");
429 len = stops.length;
430 for(i=0; i<len; i++)
431 {
432 stop = stops[i].split("@");
433 c = stop[0].split(",");
434 rtnArr.push({ position: Number(stop[1]), value:{r:Number(c[0]), g:Number(c[1]), b:Number(c[2]), a:Number(c[3])} });
435 }
436
437 return rtnArr;
438 };
439
357 /* 440 /*
358 this.export = function() { 441 this.export = function() {
359 var rtnStr; 442 var rtnStr;