aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/radial-gradient-material.js
diff options
context:
space:
mode:
authorhwc4872012-06-12 10:28:26 -0700
committerhwc4872012-06-12 10:28:26 -0700
commitd4ca478ad313c6c20834e410ba14ad3a5e7b20bf (patch)
tree28e44c5ab1b2f9dbfd32aedba51402ac2d26a0ff /js/lib/rdge/materials/radial-gradient-material.js
parentdb2bb0ab5d2747f0d07878e3b8a7d2d10c755110 (diff)
downloadninja-d4ca478ad313c6c20834e410ba14ad3a5e7b20bf.tar.gz
Material cleanup & bug fixes.
Diffstat (limited to 'js/lib/rdge/materials/radial-gradient-material.js')
-rwxr-xr-xjs/lib/rdge/materials/radial-gradient-material.js274
1 files changed, 23 insertions, 251 deletions
diff --git a/js/lib/rdge/materials/radial-gradient-material.js b/js/lib/rdge/materials/radial-gradient-material.js
index 67a85041..b5ffd01a 100755
--- a/js/lib/rdge/materials/radial-gradient-material.js
+++ b/js/lib/rdge/materials/radial-gradient-material.js
@@ -15,201 +15,49 @@ var RadialGradientMaterial = function RadialGradientMaterial() {
15 this._name = "RadialGradientMaterial"; 15 this._name = "RadialGradientMaterial";
16 this._shaderName = "radialGradient"; 16 this._shaderName = "radialGradient";
17 17
18 this._color1 = [1, 0, 0, 1]; 18 this._defaultColor1 = [1, 0, 0, 1];
19 this._color2 = [0, 1, 0, 1]; 19 this._defaultColor2 = [0, 1, 0, 1];
20 this._color3 = [0, 0, 1, 1]; 20 this._defaultColor3 = [0, 0, 1, 1];
21 this._color4 = [0, 1, 1, 1]; 21 this._defaultColor4 = [0, 1, 1, 1];
22 this._colorStop1 = 0.0; 22 this._defaultColorStop1 = 0.0;
23 this._colorStop2 = 0.3; 23 this._defaultColorStop2 = 0.3;
24 this._colorStop3 = 0.6; 24 this._defaultColorStop3 = 0.6;
25 this._colorStop4 = 1.0; 25 this._defaultColorStop4 = 1.0;
26 // this._colorCount = 4; 26 // this._defaultColorCount = 4;
27 27
28 this._textureTransform = [1,0,0, 0,1,0, 0,0,1]; 28 this._textureTransform = [1,0,0, 0,1,0, 0,0,1];
29 29
30 /////////////////////////////////////////////////////////////////////// 30 ///////////////////////////////////////////////////////////////////////
31 // Property Accessors 31 // Property Accessors
32 /////////////////////////////////////////////////////////////////////// 32 ///////////////////////////////////////////////////////////////////////
33 this.getName = function () { 33
34 return this._name;
35 };
36
37 this.getShaderName = function () {
38 return this._shaderName;
39 };
40
41 this.getColor1 = function () {
42 return this._color1;
43 };
44
45 this.setColor1 = function (c) {
46 this._color1 = c.slice();
47 this._propValues[this._propNames[0]] = this._color1.slice(0);
48 if (this._shader && this._shader['default']) {
49 this._shader['default'].u_color1.set(c);
50 }
51 };
52
53 this.getColor2 = function () {
54 return this._color2;
55 };
56
57 this.setColor2 = function (c) {
58 this._color2 = c.slice();
59 this._propValues[this._propNames[1]] = this._color2.slice(0);
60 if (this._shader && this._shader['default']) {
61 this._shader['default'].u_color2.set(c);
62 }
63
64 };
65
66 this.getColor3 = function () {
67 return this._color3;
68 };
69
70 this.setColor3 = function (c) {
71 this._color3 = c.slice();
72 this._propValues[this._propNames[2]] = this._color3.slice(0);
73 if (this._shader && this._shader['default']) {
74 this._shader['default'].u_color3.set(c);
75 }
76 };
77
78 this.getColor4 = function () {
79 return this._color4;
80 };
81
82 this.setColor4 = function (c) {
83 this._color4 = c.slice();
84 this._propValues[this._propNames[3]] = this._color4.slice(0);
85 if (this._shader && this._shader['default']) {
86 this._shader['default'].u_color4.set(c);
87 }
88 };
89
90 this.getColorStop1 = function () {
91 return this._colorStop1;
92 };
93
94 this.setColorStop1 = function (s) {
95 this._colorStop1 = s;
96 if (this._shader && this._shader['default']) {
97 this._shader['default'].u_colorStop1.set([s]);
98 }
99 };
100
101 this.getColorStop2 = function () {
102 return this._colorStop2;
103 };
104
105 this.setColorStop2 = function (s) {
106 this._colorStop2 = s;
107 if (this._shader && this._shader['default']) {
108 this._shader['default'].u_colorStop2.set([s]);
109 }
110 };
111
112 this.getColorStop3 = function () {
113 return this._colorStop3;
114 };
115
116 this.setColorStop3 = function (s) {
117 this._colorStop3 = s;
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 if (this._shader && this._shader['default']) {
130 this._shader['default'].u_colorStop4.set([s]);
131 }
132 };
133
134 this.getColorCount = function () {
135 return this._colorCount;
136 };
137
138 this.setColorCount = function (c) {
139 this._colorCount = c;
140 if (this._shader && this._shader['default']) {
141 this._shader['default'].u_colorCount.set([c]);
142 }
143 };
144
145 this.isAnimated = function () {
146 return false;
147 };
148 34
35 this.isAnimated = function () { return false; };
36 this.getShaderDef = function() { return radialGradientMaterialDef; };
149 37
150 /////////////////////////////////////////////////////////////////////// 38 ///////////////////////////////////////////////////////////////////////
151 // Material Property Accessors 39 // Material Property Accessors
152 /////////////////////////////////////////////////////////////////////// 40 ///////////////////////////////////////////////////////////////////////
153 this._propNames = ["color1", "color2", "color3", "color4", "colorStop1", "colorStop2", "colorStop3", "colorStop4" ]; 41 this._propNames = ["u_color1", "u_color2", "u_color3", "u_color4", "u_colorStop1", "u_colorStop2", "u_colorStop3", "u_colorStop4" ];
154 this._propLabels = ["Color 1", "Color 2", "Color 3", "Color 4", "Color Stop 1", "Color Stop 2", "Color Stop 3", "Color Stop 4" ]; 42 this._propLabels = ["Color 1", "Color 2", "Color 3", "Color 4", "Color Stop 1", "Color Stop 2", "Color Stop 3", "Color Stop 4" ];
155 this._propTypes = ["color", "color", "color", "color", "float", "float", "float", "float" ]; 43 this._propTypes = ["color", "color", "color", "color", "float", "float", "float", "float" ];
156 this._propValues = []; 44 this._propValues = [];
157 45
158 this._propValues[this._propNames[0]] = this._color1.slice(0); 46 this._propValues[this._propNames[0]] = this._defaultColor1.slice(0);
159 this._propValues[this._propNames[1]] = this._color2.slice(0); 47 this._propValues[this._propNames[1]] = this._defaultColor2.slice(0);
160 this._propValues[this._propNames[2]] = this._color3.slice(0); 48 this._propValues[this._propNames[2]] = this._defaultColor3.slice(0);
161 this._propValues[this._propNames[3]] = this._color4.slice(0); 49 this._propValues[this._propNames[3]] = this._defaultColor4.slice(0);
162 50
163 this._propValues[this._propNames[4]] = this._colorStop1; 51 this._propValues[this._propNames[4]] = this._defaultColorStop1;
164 this._propValues[this._propNames[5]] = this._colorStop2; 52 this._propValues[this._propNames[5]] = this._defaultColorStop2;
165 this._propValues[this._propNames[6]] = this._colorStop3; 53 this._propValues[this._propNames[6]] = this._defaultColorStop3;
166 this._propValues[this._propNames[7]] = this._colorStop4; 54 this._propValues[this._propNames[7]] = this._defaultColorStop4;
167
168 this.setProperty = function (prop, value) {
169 if (prop === "color") prop = "color1";
170
171 // make sure we have legitimate imput
172 var ok = this.validateProperty(prop, value);
173 if (!ok) {
174 console.log("invalid property in Radial Gradient Material:" + prop + " : " + value);
175 }
176
177 switch (prop) {
178 case "color1": this.setColor1(value); break;
179 case "color2": this.setColor2(value); break;
180 case "color3": this.setColor3(value); break;
181 case "color4": this.setColor4(value); break;
182 case "colorStop1": this.setColorStop1(value); break;
183 case "colorStop2": this.setColorStop2(value); break;
184 case "colorStop3": this.setColorStop3(value); break;
185 case "colorStop4": this.setColorStop4(value); break;
186 }
187
188 //this.updateValuesInShader();
189 };
190 /////////////////////////////////////////////////////////////////////// 55 ///////////////////////////////////////////////////////////////////////
191 56
192 57
193 /////////////////////////////////////////////////////////////////////// 58 ///////////////////////////////////////////////////////////////////////
194 // Methods 59 // Methods