diff options
author | Nivesh Rajbhandari | 2012-03-12 16:19:44 -0700 |
---|---|---|
committer | Nivesh Rajbhandari | 2012-03-12 16:19:44 -0700 |
commit | 2ac9a855724cc4ccf147ce4130a733a84cc647c3 (patch) | |
tree | 0ea2eb5581fad03d93e3b37e7a289bc294af2b90 /js/lib/geom/geom-obj.js | |
parent | 2c6339a9191033c937c2bac3e181c2bc380f4c48 (diff) | |
download | ninja-2ac9a855724cc4ccf147ce4130a733a84cc647c3.tar.gz |
Support import/export of gradient materials. This fixes the eyedropper not being able to sample gradient colors from WebGL shapes.
Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com>
Diffstat (limited to 'js/lib/geom/geom-obj.js')
-rwxr-xr-x | js/lib/geom/geom-obj.js | 43 |
1 files changed, 43 insertions, 0 deletions
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() { | |||
305 | return rtnStr; | 305 | return rtnStr; |
306 | }; | 306 | }; |
307 | 307 | ||
308 | // 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 | ||
309 | // 255,0,0,1@0;0,255,0,1@33;0,0,255,1@100 | ||
310 | this.gradientToString = function(colors) { | ||
311 | var rtnStr = ""; | ||
312 | if(colors && colors.length) { | ||
313 | var c = colors[0], | ||
314 | len = colors.length; | ||
315 | |||
316 | rtnStr += String(c.value.r + "," + c.value.g + "," + c.value.b + "," + c.value.a + "@" + c.position); | ||
317 | for(var i=1; i<len; i++) { | ||
318 | c = colors[i]; | ||
319 | rtnStr += ";" + String(c.value.r + "," + c.value.g + "," + c.value.b + "," + c.value.a + "@" + c.position); | ||
320 | } | ||
321 | } | ||
322 | return rtnStr; | ||
323 | }; | ||
324 | |||
325 | // Given a gradientStr "255,0,0,1@0;0,255,0,1@33;0,0,255,1@100" will return: | ||
326 | // colors array [{position:0, value:{r:255, g:0, b:0, a:1}}, | ||
327 | // {position:33, value:{r:0, g:255, b:0, a:1}}, | ||
328 | // {position:100, value:{r:0, g:0, b:255, a:1}} | ||
329 | // ] | ||
330 | this.stringToGradient = function(gradientStr) { | ||
331 | var rtnArr = []; | ||
332 | |||
333 | var i, | ||
334 | len, | ||
335 | stops, | ||
336 | stop, | ||
337 | c; | ||
338 | |||
339 | stops = gradientStr.split(";"); | ||
340 | len = stops.length; | ||
341 | for(i=0; i<len; i++) | ||
342 | { | ||
343 | stop = stops[i].split("@"); | ||
344 | c = stop[0].split(","); | ||
345 | rtnArr.push({ position: Number(stop[1]), value:{r:Number(c[0]), g:Number(c[1]), b:Number(c[2]), a:Number(c[3])} }); | ||
346 | } | ||
347 | |||
348 | return rtnArr; | ||
349 | }; | ||
350 | |||
308 | /* | 351 | /* |
309 | this.export = function() { | 352 | this.export = function() { |
310 | var rtnStr; | 353 | var rtnStr; |