aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/linear-gradient-material.js
diff options
context:
space:
mode:
authorhwc4872012-06-07 17:07:21 -0700
committerhwc4872012-06-07 17:07:21 -0700
commitdb2bb0ab5d2747f0d07878e3b8a7d2d10c755110 (patch)
tree7e3ca8a757aa0c28ccdbef2e773f54a5cfc13a98 /js/lib/rdge/materials/linear-gradient-material.js
parent6c994c4b90023cecf4fd0caafb404b859fe28f54 (diff)
downloadninja-db2bb0ab5d2747f0d07878e3b8a7d2d10c755110.tar.gz
Material cleanup
Diffstat (limited to 'js/lib/rdge/materials/linear-gradient-material.js')
-rwxr-xr-xjs/lib/rdge/materials/linear-gradient-material.js252
1 files changed, 8 insertions, 244 deletions
diff --git a/js/lib/rdge/materials/linear-gradient-material.js b/js/lib/rdge/materials/linear-gradient-material.js
index 2df76d61..80824ee3 100755
--- a/js/lib/rdge/materials/linear-gradient-material.js
+++ b/js/lib/rdge/materials/linear-gradient-material.js
@@ -31,136 +31,14 @@ var LinearGradientMaterial = function LinearGradientMaterial() {
31 /////////////////////////////////////////////////////////////////////// 31 ///////////////////////////////////////////////////////////////////////
32 // Property Accessors 32 // Property Accessors
33 /////////////////////////////////////////////////////////////////////// 33 ///////////////////////////////////////////////////////////////////////
34 this.getShaderName = function () { 34 this.getShaderDef = function() { return linearGradientMaterialDef; }
35 return this._shaderName;
36 };
37
38 this.getName = function () {
39 return this._name;
40 };
41
42 this.getColor1 = function () {
43 return this._color1;
44 };
45
46 this.setColor1 = function (c) {
47 this._color1 = c.slice();
48 this._propValues[this._propNames[0]] = this._color1.slice(0);
49
50 if (this._shader && this._shader['default']) {
51 this._shader['default'].u_color1.set(c);
52 }
53 };
54
55 this.getColor2 = function () {
56 return this._color2;
57 };
58
59 this.setColor2 = function (c) {
60 this._color2 = c.slice();
61 this._propValues[this._propNames[1]] = this._color2.slice(0);
62
63 if (this._shader && this._shader['default']) {
64 this._shader['default'].u_color2.set(c);
65 }
66 };
67
68 this.getColor3 = function () {
69 return this._color3;
70 };
71
72 this.setColor3 = function (c) {
73 this._color3 = c.slice();
74 this._propValues[this._propNames[2]] = this._color3.slice(0);
75
76 if (this._shader && this._shader['default']) {
77 this._shader['default'].u_color3.set(c);
78 }
79 };
80
81 this.getColor4 = function () {
82 return this._color4;
83 };
84
85 this.setColor4 = function (c) {
86 this._color4 = c.slice();
87 this._propValues[this._propNames[3]] = this._color4.slice(0);
88
89 if (this._shader && this._shader['default']) {
90 this._shader['default'].u_color4.set(c);
91 }
92 };
93
94 this.getColorStop1 = function () {
95 return this._colorStop1;
96 };
97
98 this.setColorStop1 = function (s) {
99 this._colorStop1 = s;
100
101 if (this._shader && this._shader['default']) {
102 this._shader['default'].u_colorStop1.set([s]);
103 }
104 };
105
106 this.getColorStop2 = function () {
107 return this._colorStop2;
108 };
109
110 this.setColorStop2 = function (s) {
111 this._colorStop2 = s;
112
113 if (this._shader && this._shader['default']) {
114 this._shader['default'].u_colorStop2.set([s]);
115 }
116 };
117
118 this.getColorStop3 = function () {
119 return this._colorStop3;
120 };
121
122 this.setColorStop3 = function (s) {
123 this._colorStop3 = s;
124
125 if (this._shader && this._shader['default']) {
126 this._shader['default'].u_colorStop3.set([s]);
127 }
128 };
129
130 this.getColorStop4 = function () {
131 return this._colorStop4;
132 };
133
134 this.setColorStop4 = function (s) {
135 this._colorStop4 = s;
136
137 if (this._shader && this._shader['default']) {
138 this._shader['default'].u_colorStop4.set([s]);
139 }
140 };
141
142 this.getAngle = function () {
143 return this._angle;
144 };
145
146 this.setAngle = function (a) {
147 this._angle = a;
148
149 if (this._shader && this._shader['default']) {
150 this._shader['default'].u_cos_sin_angle.set([Math.cos(a), Math.sin(a)]);
151 }
152 };
153
154 this.isAnimated = function () {
155 return false;
156 };
157 35
158 /////////////////////////////////////////////////////////////////////// 36 ///////////////////////////////////////////////////////////////////////
159 // Material Property Accessors 37 // Material Property Accessors
160 /////////////////////////////////////////////////////////////////////// 38 ///////////////////////////////////////////////////////////////////////
161 this._propNames = ["color1", "color2", "color3", "color4", "colorStop1", "colorStop2", "colorStop3", "colorStop4", "angle"]; 39 this._propNames = ["u_color1", "u_color2", "u_color3", "u_color4", "u_colorStop1", "u_colorStop2", "u_colorStop3", "u_colorStop4", "u_cos_sin_angle"];
162 this._propLabels = ["Color 1", "Color 2", "Color 3", "Color 4", "Color Stop 1", "Color Stop 2", "Color Stop 3", "Color Stop 4", "Angle"]; 40 this._propLabels = ["Color 1", "Color 2", "Color 3", "Color 4", "Color Stop 1", "Color Stop 2", "Color Stop 3", "Color Stop 4", "Angle"];
163 this._propTypes = ["color", "color", "color", "color", "float", "float", "float", "float", "float"]; 41 this._propTypes = ["color", "color", "color", "color", "float", "float", "float", "float", "vector2d"];
164 this._propValues = []; 42 this._propValues = [];
165 43
166 this._propValues[this._propNames[0]] = this._color1.slice(0); 44 this._propValues[this._propNames[0]] = this._color1.slice(0);
@@ -173,49 +51,12 @@ var LinearGradientMaterial = function LinearGradientMaterial() {
173 this._propValues[this._propNames[6]] = this._colorStop3; 51 this._propValues[this._propNames[6]] = this._colorStop3;
174 this._propValues[this._propNames[7]] = this._colorStop4; 52 this._propValues[this._propNames[7]] = this._colorStop4;
175 53
176 this._propValues[this._propNames[8]] = this._angle; 54 this._propValues[this._propNames[8]] = [ Math.cos(this._angle), Math.sin(this._angle) ];
177
178 this.setProperty = function (prop, value) {
179 if (prop === "color") prop = "color1";
180
181 // make sure we have legitimate imput
182 var ok = this.validateProperty(prop, value);
183 if (!ok) {
184 console.log("invalid property in Linear Gradient Material" + prop + " : " + value);
185 }
186
187 switch (prop) {
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 55
200 /////////////////////////////////////////////////////////////////////// 56 ///////////////////////////////////////////////////////////////////////
201 // Methods 57 // Methods
202 /////////////////////////////////////////////////////////////////////// 58 ///////////////////////////////////////////////////////////////////////
203 // duplcate method requirde 59 // duplcate method requirde
204 this.dup = function () {
205 // allocate a new material
206 var newMat = new LinearGradientMaterial();
207
208 // copy over the current values;
209 var propNames = [], propValues = [], propTypes = [], propLabels = [];
210 this.getAllProperties( propNames, propValues, propTypes, propLabels);
211 var n = propNames.length;
212 for (var i=0; i<n; i++) {
213 newMat.setProperty( propNames[i], propValues[i] );
214 }
215 newMat._textureTransform = this._textureTransform.slice();
216
217 return newMat;
218 };
219 60
220 this.init = function (world) { 61 this.init = function (world) {
221 this.setWorld(world); 62 this.setWorld(world);
@@ -229,91 +70,14 @@ var LinearGradientMaterial = function LinearGradientMaterial() {
229 this._materialNode = RDGE.createMaterialNode(this.getShaderName() + "_" + world.generateUniqueNodeID()); 70 this._materialNode = RDGE.createMaterialNode(this.getShaderName() + "_" + world.generateUniqueNodeID());
230 this._materialNode.setShader(this._shader); 71 this._materialNode.setShader(this._shader);
231 72
232 // send the current values to the shader
233 this.updateShaderValues();
234
235 //console.log( "**** LinearGradientMaterial initialized" );
236 };