From 22cbc9644b79df60b3f6336f9563debd47fb3ea1 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Thu, 28 Jun 2012 11:44:15 -0700 Subject: Added capability to split a mesh into multiiple parts to avoid buffer overflow situations. --- js/lib/rdge/materials/linear-gradient-material.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'js/lib/rdge/materials/linear-gradient-material.js') diff --git a/js/lib/rdge/materials/linear-gradient-material.js b/js/lib/rdge/materials/linear-gradient-material.js index 7e53db84..f5c54726 100755 --- a/js/lib/rdge/materials/linear-gradient-material.js +++ b/js/lib/rdge/materials/linear-gradient-material.js @@ -79,6 +79,25 @@ var LinearGradientMaterial = function LinearGradientMaterial() { this.setShaderValues(); this.update( 0 ); }; + + this.resetToDefault = function() + { + this._propValues[this._propNames[0]] = this._color1.slice(0); + this._propValues[this._propNames[1]] = this._color2.slice(0); + this._propValues[this._propNames[2]] = this._color3.slice(0); + this._propValues[this._propNames[3]] = this._color4.slice(0); + + this._propValues[this._propNames[4]] = this._colorStop1; + this._propValues[this._propNames[5]] = this._colorStop2; + this._propValues[this._propNames[6]] = this._colorStop3; + this._propValues[this._propNames[7]] = this._colorStop4; + + this._propValues[this._propNames[8]] = [ Math.cos(this._angle), Math.sin(this._angle) ]; + + var nProps = this._propNames.length; + for (var i=0; i --- js/lib/rdge/materials/linear-gradient-material.js | 50 +++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'js/lib/rdge/materials/linear-gradient-material.js') diff --git a/js/lib/rdge/materials/linear-gradient-material.js b/js/lib/rdge/materials/linear-gradient-material.js index 7e53db84..d26143de 100755 --- a/js/lib/rdge/materials/linear-gradient-material.js +++ b/js/lib/rdge/materials/linear-gradient-material.js @@ -79,6 +79,56 @@ var LinearGradientMaterial = function LinearGradientMaterial() { this.setShaderValues(); this.update( 0 ); }; + + // Only Linear Gradient and Radial Gradients support gradients; + this.gradientType = "linear"; + + this.getGradientData = function() { + var angle = Math.round(this._angle*180/Math.PI), + color, + colorStr, + css = "-webkit-gradient(linear, " + angle + "deg"; + + // TODO - Angle is not supported in -webkit-gradient syntax, so just default to across: + css = '-webkit-gradient(linear, left top, right top'; + + // TODO - Also, Color Model requires from and to in the gradient string + color = this.getProperty('u_color1'); + colorStr = Math.round(color[0] * 255) + ', ' + Math.round(color[1] * 255) + ', ' + Math.round(color[2] * 255) + ', ' + Math.round(color[3] * 100); + css += ', from(rgba(' + colorStr + '))'; + + for (var i=2; i < 4; i++) { + color = this.getProperty('u_color'+i); + colorStr = Math.round(color[0] * 255) + ', ' + Math.round(color[1] * 255) + ', ' + Math.round(color[2] * 255) + ', ' + Math.round(color[3] * 100); + css += ', color-stop(' + this.getProperty('u_colorStop'+i) + ', rgba(' + colorStr + '))'; + } + + color = this.getProperty('u_color4'); + colorStr = Math.round(color[0] * 255) + ', ' + Math.round(color[1] * 255) + ', ' + Math.round(color[2] * 255) + ', ' + Math.round(color[3] * 100); + css += ', to(rgba(' + colorStr + '))'; + + css += ')'; + + return css; + }; + + // Only Linear Gradient and Radial Gradient have gradient data. + this.setGradientData = function(colors) { + var len = colors.length; + // TODO - Current shaders only support 4 color stops + if (len > 4) { + len = 4; + } + + for (var n = 0; n < len; n++) { + var position = colors[n].position/100; + var cs = colors[n].value; + var stop = [cs.r/255, cs.g/255, cs.b/255, cs.a]; + + this.setProperty("u_color" + (n + 1), stop.slice(0)); + this.setProperty("u_colorStop" + (n + 1), position); + } + }; }; /////////////////////////////////////////////////////////////////////////////////////// -- cgit v1.2.3 From fdbec324dad4ab33d97282ab021d2c1661bc097c Mon Sep 17 00:00:00 2001 From: Kris Kowal Date: Mon, 9 Jul 2012 16:27:52 -0700 Subject: BSD License --- js/lib/rdge/materials/linear-gradient-material.js | 27 ++++++++++++----------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'js/lib/rdge/materials/linear-gradient-material.js') diff --git a/js/lib/rdge/materials/linear-gradient-material.js b/js/lib/rdge/materials/linear-gradient-material.js index e1d31a42..f8b77a63 100755 --- a/js/lib/rdge/materials/linear-gradient-material.js +++ b/js/lib/rdge/materials/linear-gradient-material.js @@ -1,24 +1,25 @@ /* -Copyright (c) 2012, Motorola Mobility, Inc +Copyright (c) 2012, Motorola Mobility LLC. All Rights Reserved. -BSD License. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Motorola Mobility nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. +* Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of Motorola Mobility LLC nor the names of its + contributors may be used to endorse or promote products derived from this + software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS @@ -26,7 +27,7 @@ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + */ var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser; var Material = require("js/lib/rdge/materials/material").Material; @@ -117,7 +118,7 @@ var LinearGradientMaterial = function LinearGradientMaterial() { this._propValues[this._propNames[7]] = this._colorStop4; this._propValues[this._propNames[8]] = [ Math.cos(this._angle), Math.sin(this._angle) ]; - + var nProps = this._propNames.length; for (var i=0; i