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