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 1a197832..f285f24a 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
@@ -352,6 +392,49 @@ var GeomObj = function GLGeomObj() {
352 return rtnStr; 392 return rtnStr;
353 }; 393 };
354 394
395 // 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
396 // 255,0,0,1@0;0,255,0,1@33;0,0,255,1@100
397 this.gradientToString = function(colors) {
398 var rtnStr = "";
399 if(colors && colors.length) {
400 var c = colors[0],
401 len = colors.length;
402
403 rtnStr += String(c.value.r + "," + c.value.g + "," + c.value.b + "," + c.value.a + "@" + c.position);
404 for(var i=1; i<len; i++) {
405 c = colors[i];
406 rtnStr += ";" + String(c.value.r + "," + c.value.g + "," + c.value.b + "," + c.value.a + "@" + c.position);
407 }
408 }
409 return rtnStr;
410 };
411
412 // Given a gradientStr "255,0,0,1@0;0,255,0,1@33;0,0,255,1@100" will return:
413 // colors array [{position:0, value:{r:255, g:0, b:0, a:1}},
414 // {position:33, value:{r:0, g:255, b:0, a:1}},
415 // {position:100, value:{r:0, g:0, b:255, a:1}}
416 // ]
417 this.stringToGradient = function(gradientStr) {
418 var rtnArr = [];
419
420 var i,
421 len,
422 stops,
423 stop,
424 c;
425
426 stops = gradientStr.split(";");
427 len = stops.length;
428 for(i=0; i<len; i++)
429 {
430 stop = stops[i].split("@");
431 c = stop[0].split(",");
432 rtnArr.push({ position: Number(stop[1]), value:{r:Number(c[0]), g:Number(c[1]), b:Number(c[2]), a:Number(c[3])} });
433 }
434
435 return rtnArr;
436 };
437
355 /* 438 /*
356 this.export = function() { 439 this.export = function() {
357 var rtnStr; 440 var rtnStr;