diff options
Diffstat (limited to 'js/lib/rdge/materials/linear-gradient-material.js')
-rwxr-xr-x | js/lib/rdge/materials/linear-gradient-material.js | 434 |
1 files changed, 434 insertions, 0 deletions
diff --git a/js/lib/rdge/materials/linear-gradient-material.js b/js/lib/rdge/materials/linear-gradient-material.js new file mode 100755 index 00000000..2c52c67d --- /dev/null +++ b/js/lib/rdge/materials/linear-gradient-material.js | |||
@@ -0,0 +1,434 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | |||
7 | var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser; | ||
8 | var Material = require("js/lib/rdge/materials/material").Material; | ||
9 | |||
10 | var LinearGradientMaterial = function LinearGradientMaterial() { | ||
11 | /////////////////////////////////////////////////////////////////////// | ||
12 | // Instance variables | ||
13 | /////////////////////////////////////////////////////////////////////// | ||
14 | this._name = "LinearGradientMaterial"; | ||
15 | this._shaderName = "linearGradient"; | ||
16 | |||
17 | this._color1 = [1,0,0,1]; | ||
18 | this._color2 = [0,1,0,1]; | ||
19 | this._color3 = [0,0,1,1]; | ||
20 | this._color4 = [0,1,1,1]; | ||
21 | this._colorStop1 = 0.0; | ||
22 | this._colorStop2 = 0.3; | ||
23 | this._colorStop3 = 0.6; | ||
24 | this._colorStop4 = 1.0; | ||
25 | // this._colorCount = 4; | ||
26 | this._angle = 0.0; // the shader takes [cos(a), sin(a)] | ||
27 | |||
28 | /////////////////////////////////////////////////////////////////////// | ||
29 | // Property Accessors | ||
30 | /////////////////////////////////////////////////////////////////////// | ||
31 | this.getShaderName = function() { | ||
32 | return this._shaderName; | ||
33 | }; | ||
34 | |||
35 | this.getName = function() { | ||
36 | return this._name; | ||
37 | }; | ||
38 | |||
39 | this.getColor1 = function() { | ||
40 | return this._color1; | ||
41 | }; | ||
42 | |||
43 | this.setColor1 = function(c) { | ||
44 | this._color1 = c.slice(); | ||
45 | |||
46 | if (this._shader && this._shader['default']) { | ||
47 | this._shader['default'].u_color1.set(c); | ||
48 | } | ||
49 | }; | ||
50 | |||
51 | this.getColor2 = function() { | ||
52 | return this._color2; | ||
53 | }; | ||
54 | |||
55 | this.setColor2 = function(c) { | ||
56 | this._color2 = c.slice(); | ||
57 | |||
58 | if (this._shader && this._shader['default']) { | ||
59 | this._shader['default'].u_color2.set(c); | ||
60 | } | ||
61 | }; | ||
62 | |||
63 | this.getColor3 = function() { | ||
64 | return this._color3; | ||
65 | }; | ||
66 | |||
67 | this.setColor3 = function(c) { | ||
68 | this._color3 = c.slice(); | ||
69 | |||
70 | if (this._shader && this._shader['default']) { | ||
71 | this._shader['default'].u_color3.set(c); | ||
72 | } | ||
73 | }; | ||
74 | |||
75 | this.getColor4 = function() { | ||
76 | return this._color4; | ||
77 | }; | ||
78 | |||
79 | this.setColor4 = function(c) { | ||
80 | this._color4 = c.slice(); | ||
81 | |||
82 | if (this._shader && this._shader['default']) { | ||
83 | this._shader['default'].u_color4.set(c); | ||
84 | } | ||
85 | }; | ||
86 | |||
87 | this.getColorStop1 = function() { | ||
88 | return this._colorStop1; | ||
89 | }; | ||
90 | |||
91 | this.setColorStop1 = function(s) { | ||
92 | this._colorStop1 = s; | ||
93 | |||
94 | if (this._shader && this._shader['default']) { | ||
95 | this._shader['default'].u_colorStop1.set([s]); | ||
96 | } | ||
97 | }; | ||
98 | |||
99 | this.getColorStop2 = function() { | ||
100 | return this._colorStop2; | ||
101 | }; | ||
102 | |||
103 | this.setColorStop2 = function(s) { | ||
104 | this._colorStop2 = s; | ||
105 | |||
106 | if (this._shader && this._shader['default']) { | ||
107 | this._shader['default'].u_colorStop2.set([s]); | ||
108 | } | ||
109 | }; | ||
110 | |||
111 | this.getColorStop3 = function() { | ||
112 | return this._colorStop3; | ||
113 | }; | ||
114 | |||
115 | this.setColorStop3 = function(s) { | ||
116 | this._colorStop3 = s; | ||
117 | |||
118 | if (this._shader && this._shader['default']) { | ||
119 | this._shader['default'].u_colorStop3.set([s]); | ||
120 | } | ||
121 | } | ||
122 | |||
123 | this.getColorStop4 = function() { | ||
124 | return this._colorStop4; | ||
125 | }; | ||
126 | |||
127 | this.setColorStop4 = function(s) { | ||
128 | this._colorStop4 = s; | ||
129 | |||
130 | if (this._shader && this._shader['default']) { | ||
131 | this._shader['default'].u_colorStop4.set([s]); | ||
132 | } | ||
133 | }; | ||
134 | |||
135 | // this.getColorCount = function() { return this._colorCount; }; | ||
136 | // this.setColorCount = function(c) { this._colorCount = c; | ||
137 | // if (this._shader && this._shader['default']) | ||
138 | // this._shader['default'].u_colorCount.set([c]); | ||
139 | // }; | ||
140 | |||
141 | this.getAngle = function() { | ||
142 | return this._angle; | ||
143 | }; | ||
144 | |||
145 | this.setAngle = function(a) { | ||
146 | this._angle = a; | ||
147 | |||
148 | if (this._shader && this._shader['default']) { | ||
149 | this._shader['default'].u_cos_sin_angle.set([Math.cos(a), Math.sin(a)]); | ||
150 | } | ||
151 | }; | ||
152 | |||
153 | this.isAnimated = function() { | ||
154 | return false; | ||
155 | }; | ||
156 | |||
157 | /////////////////////////////////////////////////////////////////////// | ||
158 | // Material Property Accessors | ||
159 | /////////////////////////////////////////////////////////////////////// | ||
160 | this._propNames = ["color1", "color2", "color3", "color4", "colorStop1", "colorStop2", "colorStop3", "colorStop4", "angle"]; | ||
161 | this._propLabels = ["Color 1", "Color 2", "Color 3", "Color 4", "Color Stop 1", "Color Stop 2", "Color Stop 3", "Color Stop 4", "Angle"]; | ||
162 | this._propTypes = ["color", "color", "color", "color", "float", "float", "float", "float", "float"]; | ||
163 | this._propValues = []; | ||
164 | |||
165 | this._propValues[ this._propNames[0] ] = this._color1.slice(0); | ||
166 | this._propValues[ this._propNames[1] ] = this._color2.slice(0); | ||
167 | this._propValues[ this._propNames[2] ] = this._color3.slice(0); | ||
168 | this._propValues[ this._propNames[3] ] = this._color4.slice(0); | ||
169 | |||
170 | this._propValues[ this._propNames[4] ] = this._colorStop1; | ||
171 | this._propValues[ this._propNames[5] ] = this._colorStop2; | ||
172 | this._propValues[ this._propNames[6] ] = this._colorStop3; | ||
173 | this._propValues[ this._propNames[7] ] = this._colorStop4; | ||
174 | |||
175 | this._propValues[ this._propNames[8] ] = this._angle; | ||
176 | |||
177 | this.setProperty = function( prop, value ) { | ||
178 | if (prop === "color") prop = "color1"; | ||
179 | |||
180 | // make sure we have legitimate imput | ||
181 | var ok = this.validateProperty( prop, value ); | ||
182 | if (!ok) { | ||
183 | console.log( "invalid property in Linear Gradient Material" + prop + " : " + value ); | ||
184 | } | ||
185 | |||
186 | switch (prop) | ||
187 | { | ||
188 | case "color1": this.setColor1( value ); break; | ||
189 | case "color2": this.setColor2( value ); break; | ||
190 | case "color3": this.setColor3( value ); break; | ||
191 | case "color4": this.setColor4( value ); break; | ||
192 | case "colorStop1": this.setColorStop1( value ); break; | ||
193 | case "colorStop2": this.setColorStop2( value ); break; | ||
194 | case "colorStop3": this.setColorStop3( value ); break; | ||
195 | case "colorStop4": this.setColorStop4( value ); break; | ||
196 | case "angle": this.setAngle( value ); break; | ||
197 | } | ||
198 | }; | ||
199 | |||
200 | /////////////////////////////////////////////////////////////////////// | ||
201 | // Methods | ||
202 | /////////////////////////////////////////////////////////////////////// | ||
203 | // duplcate method requirde | ||
204 | this.dup = function() { return new LinearGradientMaterial(); }; | ||
205 | |||
206 | this.init = function( world ) { | ||
207 | this.setWorld( world ); | ||
208 | |||
209 | // set up the shader | ||
210 | this._shader = new jshader(); | ||
211 | this._shader.def = linearGradientMaterialDef; | ||
212 | this._shader.init(); | ||
213 | |||
214 | // set up the material node | ||
215 | this._materialNode = createMaterialNode( this.getShaderName() ); | ||