diff options
author | John Mayhew | 2012-07-09 17:28:24 -0700 |
---|---|---|
committer | John Mayhew | 2012-07-09 17:28:24 -0700 |
commit | 770bcb52422742ff741a88a75ecefbeb90bc9247 (patch) | |
tree | 64cb3e09a8daeb340261dd7f3869c73f7b90b643 /js/lib/rdge/materials/radial-gradient-material.js | |
parent | 8c5ecaf90062f9e030386f338bdc19fd62b826c8 (diff) | |
parent | 2b2b5fbb4b6a786daa4e9d4ee9eba9ac78924842 (diff) | |
download | ninja-770bcb52422742ff741a88a75ecefbeb90bc9247.tar.gz |
Merge branch 'master' of github.com:Motorola-Mobility/ninja-internal
Conflicts:
manifest.json
Diffstat (limited to 'js/lib/rdge/materials/radial-gradient-material.js')
-rwxr-xr-x | js/lib/rdge/materials/radial-gradient-material.js | 269 |
1 files changed, 179 insertions, 90 deletions
diff --git a/js/lib/rdge/materials/radial-gradient-material.js b/js/lib/rdge/materials/radial-gradient-material.js index 6a5a9e9a..f99b78de 100755 --- a/js/lib/rdge/materials/radial-gradient-material.js +++ b/js/lib/rdge/materials/radial-gradient-material.js | |||
@@ -1,24 +1,25 @@ | |||
1 | /* <copyright> | 1 | /* <copyright> |
2 | Copyright (c) 2012, Motorola Mobility, Inc | 2 | Copyright (c) 2012, Motorola Mobility LLC. |
3 | All Rights Reserved. | 3 | All Rights Reserved. |
4 | BSD License. | ||
5 | 4 | ||
6 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met: | 6 | modification, are permitted provided that the following conditions are met: |
8 | 7 | ||
9 | - Redistributions of source code must retain the above copyright notice, | 8 | * Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. | 9 | this list of conditions and the following disclaimer. |
11 | - Redistributions in binary form must reproduce the above copyright | 10 | |
12 | notice, this list of conditions and the following disclaimer in the | 11 | * Redistributions in binary form must reproduce the above copyright notice, |
13 | documentation and/or other materials provided with the distribution. | 12 | this list of conditions and the following disclaimer in the documentation |
14 | - Neither the name of Motorola Mobility nor the names of its contributors | 13 | and/or other materials provided with the distribution. |
15 | may be used to endorse or promote products derived from this software | 14 | |
16 | without specific prior written permission. | 15 | * Neither the name of Motorola Mobility LLC nor the names of its |
16 | contributors may be used to endorse or promote products derived from this | ||
17 | software without specific prior written permission. | ||
17 | 18 | ||
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
@@ -47,17 +48,17 @@ var RadialGradientMaterial = function RadialGradientMaterial() { | |||
47 | this._defaultColorStop2 = 0.3; | 48 | this._defaultColorStop2 = 0.3; |
48 | this._defaultColorStop3 = 0.6; | 49 | this._defaultColorStop3 = 0.6; |
49 | this._defaultColorStop4 = 1.0; | 50 | this._defaultColorStop4 = 1.0; |
50 | // this._defaultColorCount = 4; | 51 | // this._defaultColorCount = 4; |
51 | 52 | ||
52 | this._textureTransform = [1,0,0, 0,1,0, 0,0,1]; | 53 | this._textureTransform = [1,0,0, 0,1,0, 0,0,1]; |
53 | 54 | ||
54 | /////////////////////////////////////////////////////////////////////// | 55 | /////////////////////////////////////////////////////////////////////// |
55 | // Property Accessors | 56 | // Property Accessors |
56 | /////////////////////////////////////////////////////////////////////// | 57 | /////////////////////////////////////////////////////////////////////// |
57 | |||
58 | 58 | ||
59 | this.isAnimated = function () { return false; }; | 59 | |
60 | this.getShaderDef = function() { return radialGradientMaterialDef; }; | 60 | this.isAnimated = function () { return false; }; |
61 | this.getShaderDef = function() { return radialGradientMaterialDef; }; | ||
61 | 62 | ||
62 | /////////////////////////////////////////////////////////////////////// | 63 | /////////////////////////////////////////////////////////////////////// |
63 | // Material Property Accessors | 64 | // Material Property Accessors |
@@ -95,49 +96,137 @@ var RadialGradientMaterial = function RadialGradientMaterial() { | |||
95 | this._materialNode.setShader(this._shader); | 96 | this._materialNode.setShader(this._shader); |
96 | 97 | ||
97 | // set the shader values in the shader | 98 | // set the shader values in the shader |
98 | this._shader['default'].u_texTransform.set( this._textureTransform ); | 99 | this._shader['default'].u_texTransform.set( this._textureTransform ); |
99 | this.setShaderValues(); | 100 | this.setShaderValues(); |
100 | }; | 101 | }; |
101 | 102 | ||
102 | this.fitToPrimitive = function( prim ) | 103 | this.resetToDefault = function() |
104 | { | ||
105 | this._propValues[this._propNames[0]] = this._defaultColor1.slice(0); | ||
106 | this._propValues[this._propNames[1]] = this._defaultColor2.slice(0); | ||
107 | this._propValues[this._propNames[2]] = this._defaultColor3.slice(0); | ||
108 | this._propValues[this._propNames[3]] = this._defaultColor4.slice(0); | ||
109 | |||
110 | this._propValues[this._propNames[4]] = this._defaultColorStop1; | ||
111 | this._propValues[this._propNames[5]] = this._defaultColorStop2; | ||
112 | this._propValues[this._propNames[6]] = this._defaultColorStop3; | ||
113 | this._propValues[this._propNames[7]] = this._defaultColorStop4; | ||
114 | |||
115 | var nProps = this._propNames.length; | ||
116 | for (var i=0; i<nProps; i++) { | ||
117 | this.setProperty( this._propNames[i], this._propValues[this._propNames[i]] ); | ||
118 | } | ||
119 | }; | ||
120 | |||
121 | this.fitToBounds = function( bounds ) | ||
103 | { | 122 | { |
104 | var bounds = ShapePrimitive.getBounds( prim ); | 123 | if (bounds) |
105 | if (bounds) | 124 | { |
125 | var dx = Math.abs( bounds[3] - bounds[0] ), | ||
126 | dy = Math.abs( bounds[4] - bounds[1] ); | ||
127 | if (dy == 0) dy = 1.0; | ||
128 | if (dx == 0) dx = 1.0; | ||
129 | var xScale = 2.0, yScale = 2.0; | ||
130 | if (dx > dy) | ||
131 | yScale *= dy/dx; | ||
132 | else | ||
133 | xScale *= dx/dy; | ||
134 | |||
135 | // build the matrix - the translation to the origin, the scale, | ||
136 | // and the translation back to the center (hard coded at (0.5, 0.5) for now). | ||
137 | // the matrix is build directly instead of with matrix multiplications | ||
138 | // for efficiency, not to mention that the multiplication function does | ||
139 | // not exist for mat3's. | ||
140 | // the matrix as laid out below looks transposed - order is columnwise. | ||
141 | var xCtr = 0.5, yCtr = 0.5; | ||
142 | this._textureTransform = [ | ||
143 | xScale, 0.0, 0.0, | ||
144 | 0.0, yScale, 0.0, | ||
145 | xCtr*(1-xScale), yCtr*(1 - yScale), 1.0 | ||
146 | ]; | ||
147 | |||
148 | if (this._shader && this._shader['default']) | ||
149 | this._shader['default'].u_texTransform.set( this._textureTransform ); | ||
150 | |||
151 | } | ||
152 | }; | ||
153 | |||
154 | this.fitToPrimitiveArray = function( primArray ) | ||
155 | { | ||
156 | if (!primArray) return; | ||
157 | var nPrims = primArray.length; | ||
158 | if (nPrims == 0) return; | ||
159 | var bounds = ShapePrimitive.getBounds( primArray[0] ); | ||
160 | for (var i=1; i<nPrims; i++) | ||
106 | { | 161 | { |
107 | var dx = Math.abs( bounds[3] - bounds[0] ), | 162 | var prim = primArray[i]; |
108 | dy = Math.abs( bounds[4] - bounds[1] ); | 163 | var b2 = ShapePrimitive.getBounds( prim ); |
109 | if (dy == 0) dy = 1.0; | 164 | |
110 | if (dx == 0) dx = 1.0; | 165 | // [xMin, yMin, zMin, xMax, yMax, zMax] |
111 | var xScale = 2.0, yScale = 2.0; | 166 | if (b2[0] < bounds[0]) bounds[0] = b2[0]; |
112 | if (dx > dy) | 167 | if (b2[1] < bounds[1]) bounds[1] = b2[1]; |
113 | yScale *= dy/dx; | 168 | if (b2[2] < bounds[2]) bounds[2] = b2[2]; |
114 | else | ||
115 | xScale *= dx/dy; | ||
116 | |||
117 | // build the matrix - the translation to the origin, the scale, | ||
118 | // and the translation back to the center (hard coded at (0.5, 0.5) for now). | ||
119 | // the matrix is build directly instead of with matrix multiplications | ||
120 | // for efficiency, not to mention that the multiplication function does | ||
121 | // not exist for mat3's. | ||
122 | // the matrix as laid out below looks transposed - order is columnwise. | ||
123 | var xCtr = 0.5, yCtr = 0.5; | ||
124 | this._textureTransform = [ | ||
125 | xScale, 0.0, 0.0, | ||
126 | 0.0, yScale, 0.0, | ||
127 | xCtr*(1-xScale), yCtr*(1 - yScale), 1.0 | ||
128 | ]; | ||
129 | |||
130 | if (this._shader && this._shader['default']) | ||
131 | this._shader['default'].u_texTransform.set( this._textureTransform ); | ||
132 | 169 | ||
170 | if (b2[3] > bounds[3]) bounds[3] = b2[3]; | ||
171 | if (b2[4] > bounds[4]) bounds[4] = b2[4]; | ||
172 | if (b2[5] > bounds[5]) bounds[5] = b2[5]; | ||
133 | } | 173 | } |
174 | |||
175 | this.fitToBounds( bounds ); | ||
134 | }; | 176 | }; |
135 | 177 | ||
136 | this.customExport = function( jObj ) | 178 | this.fitToPrimitive = function( prim ) |
137 | { | 179 | { |
138 | jObj.u_texTransform = this._textureTransform.slice(); | 180 | var bounds = ShapePrimitive.getBounds( prim ); |
139 | return jObj; | 181 | this.fitToBounds( bounds ); |
140 | } | 182 | }; |
183 | |||
184 | this.customExport = function( jObj ) | ||
185 | { | ||
186 | jObj.u_texTransform = this._textureTransform.slice(); | ||
187 | return jObj; | ||
188 | }; | ||
189 | |||
190 | // Only Linear Gradient and Radial Gradient have gradient data. | ||
191 | this.gradientType = "radial"; | ||
192 | |||