aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/radial-gradient-material.js
diff options
context:
space:
mode:
authorValerio Virgillito2012-07-09 14:35:44 -0700
committerValerio Virgillito2012-07-09 14:35:44 -0700
commit84b3327bd92faafab7954b5eb64c7abe24a3fe13 (patch)
tree3f56cbed2f08c5a81ea79eaf0bcb9bd031d8a627 /js/lib/rdge/materials/radial-gradient-material.js
parentc0a42c56f768a873ba637f5b86d5f6a84d4a3312 (diff)
parent40c6eb2c06b34f65a74d59ef9687251952858bab (diff)
downloadninja-84b3327bd92faafab7954b5eb64c7abe24a3fe13.tar.gz
Merge branch 'normalize' of https://github.com/kriskowal/ninja-internal
Conflicts: js/components/gradientpicker.reel/gradientpicker.js js/components/tools-properties/text-properties.reel/text-properties.js js/document/views/base.js js/document/views/design.js js/helper-classes/3D/StageLine.js js/helper-classes/3D/draw-utils.js js/lib/drawing/world.js js/lib/geom/circle.js js/lib/geom/line.js js/lib/geom/rectangle.js js/lib/geom/shape-primitive.js js/lib/rdge/materials/bump-metal-material.js js/lib/rdge/materials/flag-material.js js/lib/rdge/materials/fly-material.js js/lib/rdge/materials/julia-material.js js/lib/rdge/materials/keleidoscope-material.js js/lib/rdge/materials/mandel-material.js js/lib/rdge/materials/material.js js/lib/rdge/materials/plasma-material.js js/lib/rdge/materials/pulse-material.js js/lib/rdge/materials/radial-gradient-material.js js/lib/rdge/materials/taper-material.js js/lib/rdge/materials/twist-vert-material.js js/lib/rdge/materials/water-material.js js/panels/Materials/materials-library-panel.reel/materials-library-panel.html js/panels/Materials/materials-library-panel.reel/materials-library-panel.js js/panels/Materials/materials-popup.reel/materials-popup.html js/panels/Materials/materials-popup.reel/materials-popup.js js/tools/LineTool.js Signed-off-by: Valerio Virgillito <valerio@motorola.com>
Diffstat (limited to 'js/lib/rdge/materials/radial-gradient-material.js')
-rwxr-xr-xjs/lib/rdge/materials/radial-gradient-material.js166
1 files changed, 83 insertions, 83 deletions
diff --git a/js/lib/rdge/materials/radial-gradient-material.js b/js/lib/rdge/materials/radial-gradient-material.js
index 6ce28ae4..f1094771 100755
--- a/js/lib/rdge/materials/radial-gradient-material.js
+++ b/js/lib/rdge/materials/radial-gradient-material.js
@@ -47,17 +47,17 @@ var RadialGradientMaterial = function RadialGradientMaterial() {
47 this._defaultColorStop2 = 0.3; 47 this._defaultColorStop2 = 0.3;
48 this._defaultColorStop3 = 0.6; 48 this._defaultColorStop3 = 0.6;
49 this._defaultColorStop4 = 1.0; 49 this._defaultColorStop4 = 1.0;
50 // this._defaultColorCount = 4; 50 // this._defaultColorCount = 4;
51 51
52 this._textureTransform = [1,0,0, 0,1,0, 0,0,1]; 52 this._textureTransform = [1,0,0, 0,1,0, 0,0,1];
53 53
54 /////////////////////////////////////////////////////////////////////// 54 ///////////////////////////////////////////////////////////////////////
55 // Property Accessors 55 // Property Accessors
56 /////////////////////////////////////////////////////////////////////// 56 ///////////////////////////////////////////////////////////////////////
57
58 57
59 this.isAnimated = function () { return false; }; 58
60 this.getShaderDef = function() { return radialGradientMaterialDef; }; 59 this.isAnimated = function () { return false; };
60 this.getShaderDef = function() { return radialGradientMaterialDef; };
61 61
62 /////////////////////////////////////////////////////////////////////// 62 ///////////////////////////////////////////////////////////////////////
63 // Material Property Accessors 63 // Material Property Accessors
@@ -95,12 +95,12 @@ var RadialGradientMaterial = function RadialGradientMaterial() {
95 this._materialNode.setShader(this._shader); 95 this._materialNode.setShader(this._shader);
96 96
97 // set the shader values in the shader 97 // set the shader values in the shader
98 this._shader['default'].u_texTransform.set( this._textureTransform ); 98 this._shader['default'].u_texTransform.set( this._textureTransform );
99 this.setShaderValues(); 99 this.setShaderValues();
100 }; 100 };
101 101
102 this.resetToDefault = function() 102 this.resetToDefault = function()
103 { 103 {
104 this._propValues[this._propNames[0]] = this._defaultColor1.slice(0); 104 this._propValues[this._propNames[0]] = this._defaultColor1.slice(0);
105 this._propValues[this._propNames[1]] = this._defaultColor2.slice(0); 105 this._propValues[this._propNames[1]] = this._defaultColor2.slice(0);
106 this._propValues[this._propNames[2]] = this._defaultColor3.slice(0); 106 this._propValues[this._propNames[2]] = this._defaultColor3.slice(0);
@@ -119,36 +119,36 @@ var RadialGradientMaterial = function RadialGradientMaterial() {
119 119
120 this.fitToBounds = function( bounds ) 120 this.fitToBounds = function( bounds )
121 { 121 {
122 if (bounds) 122 if (bounds)
123 { 123 {
124 var dx = Math.abs( bounds[3] - bounds[0] ), 124 var dx = Math.abs( bounds[3] - bounds[0] ),
125 dy = Math.abs( bounds[4] - bounds[1] ); 125 dy = Math.abs( bounds[4] - bounds[1] );
126 if (dy == 0) dy = 1.0; 126 if (dy == 0) dy = 1.0;
127 if (dx == 0) dx = 1.0; 127 if (dx == 0) dx = 1.0;
128 var xScale = 2.0, yScale = 2.0; 128 var xScale = 2.0, yScale = 2.0;
129 if (dx > dy) 129 if (dx > dy)
130 yScale *= dy/dx; 130 yScale *= dy/dx;
131 else 131 else
132 xScale *= dx/dy; 132 xScale *= dx/dy;
133 133
134 // build the matrix - the translation to the origin, the scale, 134 // build the matrix - the translation to the origin, the scale,
135 // and the translation back to the center (hard coded at (0.5, 0.5) for now). 135 // and the translation back to the center (hard coded at (0.5, 0.5) for now).
136 // the matrix is build directly instead of with matrix multiplications 136 // the matrix is build directly instead of with matrix multiplications
137 // for efficiency, not to mention that the multiplication function does 137 // for efficiency, not to mention that the multiplication function does
138 // not exist for mat3's. 138 // not exist for mat3's.
139 // the matrix as laid out below looks transposed - order is columnwise. 139 // the matrix as laid out below looks transposed - order is columnwise.
140 var xCtr = 0.5, yCtr = 0.5; 140 var xCtr = 0.5, yCtr = 0.5;
141 this._textureTransform = [ 141 this._textureTransform = [
142 xScale, 0.0, 0.0, 142 xScale, 0.0, 0.0,
143 0.0, yScale, 0.0, 143 0.0, yScale, 0.0,
144 xCtr*(1-xScale), yCtr*(1 - yScale), 1.0 144 xCtr*(1-xScale), yCtr*(1 - yScale), 1.0
145 ]; 145 ];
146 146
147 if (this._shader && this._shader['default']) 147 if (this._shader && this._shader['default'])
148 this._shader['default'].u_texTransform.set( this._textureTransform ); 148 this._shader['default'].u_texTransform.set( this._textureTransform );
149 149
150 } 150 }
151 }; 151 };
152 152
153 this.fitToPrimitiveArray = function( primArray ) 153 this.fitToPrimitiveArray = function( primArray )
154 { 154 {
@@ -180,10 +180,10 @@ var RadialGradientMaterial = function RadialGradientMaterial() {
180 this.fitToBounds( bounds ); 180 this.fitToBounds( bounds );
181 }; 181 };
182 182
183 this.customExport = function( jObj ) 183 this.customExport = function( jObj )
184 { 184 {
185 jObj.u_texTransform = this._textureTransform.slice(); 185 jObj.u_texTransform = this._textureTransform.slice();
186 return jObj; 186 return jObj;
187 }; 187 };
188 188
189 // Only Linear Gradient and Radial Gradient have gradient data. 189 // Only Linear Gradient and Radial Gradient have gradient data.
@@ -203,12 +203,12 @@ var RadialGradientMaterial = function RadialGradientMaterial() {
203 color = this.getProperty('u_color'+i); 203 color = this.getProperty('u_color'+i);
204 colorStr = Math.round(color[0] * 255) + ', ' + Math.round(color[1] * 255) + ', ' + Math.round(color[2] * 255) + ', ' + Math.round(color[3] * 100); 204 colorStr = Math.round(color[0] * 255) + ', ' + Math.round(color[1] * 255) + ', ' + Math.round(color[2] * 255) + ', ' + Math.round(color[3] * 100);
205 css += ', rgba(' + colorStr + ') ' + Math.round(this.getProperty('u_colorStop'+i)*100) + '%'; 205 css += ', rgba(' + colorStr + ') ' + Math.round(this.getProperty('u_colorStop'+i)*100) + '%';
206 } 206 }
207 207
208 css += ')'; 208 css += ')';
209 209
210 return css; 210 return css;
211 }; 211};
212 212
213 this.setGradientData = function(colors) { 213 this.setGradientData = function(colors) {
214 var len = colors.length; 214 var len = colors.length;
@@ -234,48 +234,48 @@ var RadialGradientMaterial = function RadialGradientMaterial() {
234// shader spec (can also be loaded from a .JSON file, or constructed at runtime) 234// shader spec (can also be loaded from a .JSON file, or constructed at runtime)
235var radialGradientMaterialDef = 235var radialGradientMaterialDef =
236{ 'shaders': 236{ 'shaders':
237 { 237 {
238 'defaultVShader': "assets/shaders/radialGradient.vert.glsl", 238 'defaultVShader': "assets/shaders/radialGradient.vert.glsl",
239 'defaultFShader': "assets/shaders/radialGradient.frag.glsl" 239 'defaultFShader': "assets/shaders/radialGradient.frag.glsl"
240 }, 240 },
241 'techniques': 241 'techniques':
242 { 242 {
243 'default': 243 'default':
244 [ 244 [
245 { 245 {
246 'vshader': 'defaultVShader', 246 'vshader': 'defaultVShader',
247 'fshader': 'defaultFShader', 247 'fshader': 'defaultFShader',
248 // attributes 248 // attributes
249 'attributes': 249 'attributes':
250 { 250 {
251 'vert': { 'type': 'vec3' }, 251 'vert': { 'type': 'vec3' },
252 'normal': { 'type': 'vec3' }, 252 'normal': { 'type': 'vec3' },
253 'texcoord': { 'type': 'vec2' } 253 'texcoord': { 'type': 'vec2' }
254 }, 254 },
255 // parameters 255 // parameters
256 'params': 256 'params':
257 { 257 {
258 'u_color1': { 'type': 'vec4' }, 258 'u_color1': { 'type': 'vec4' },
259 'u_color2': { 'type': 'vec4' }, 259 'u_color2': { 'type': 'vec4' },
260 'u_color3': { 'type': 'vec4' }, 260 'u_color3': { 'type': 'vec4' },
261 'u_color4': { 'type': 'vec4' }, 261 'u_color4': { 'type': 'vec4' },
262 'u_colorStop1': { 'type': 'float' }, 262 'u_colorStop1': { 'type': 'float' },
263 'u_colorStop2': { 'type': 'float' }, 263 'u_colorStop2': { 'type': 'float' },
264 'u_colorStop3': { 'type': 'float' }, 264 'u_colorStop3': { 'type': 'float' },
265 'u_colorStop4': { 'type': 'float' }, 265 'u_colorStop4': { 'type': 'float' },
266 'u_texTransform': { 'type' : 'mat3' }