aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/flag-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/flag-material.js
parent6c994c4b90023cecf4fd0caafb404b859fe28f54 (diff)
downloadninja-db2bb0ab5d2747f0d07878e3b8a7d2d10c755110.tar.gz
Material cleanup
Diffstat (limited to 'js/lib/rdge/materials/flag-material.js')
-rw-r--r--js/lib/rdge/materials/flag-material.js110
1 files changed, 5 insertions, 105 deletions
diff --git a/js/lib/rdge/materials/flag-material.js b/js/lib/rdge/materials/flag-material.js
index aaf36ebf..a8c319e4 100644
--- a/js/lib/rdge/materials/flag-material.js
+++ b/js/lib/rdge/materials/flag-material.js
@@ -32,7 +32,7 @@ var FlagMaterial = function FlagMaterial() {
32 /////////////////////////////////////////////////////////////////////// 32 ///////////////////////////////////////////////////////////////////////
33 // all defined in parent PulseMaterial.js 33 // all defined in parent PulseMaterial.js
34 // load the local default value 34 // load the local default value
35 this._propNames = ["texmap", "wavewidth", "waveheight", "speed" ]; 35 this._propNames = ["u_tex0", "u_waveWidth", "u_waveHeight", "u_speed" ];
36 this._propLabels = ["Texture map", "Wave Width", "Wave Height", "Speed" ]; 36 this._propLabels = ["Texture map", "Wave Width", "Wave Height", "Speed" ];
37 this._propTypes = ["file", "float", "float", "float" ]; 37 this._propTypes = ["file", "float", "float", "float" ];
38 this._propValues = []; 38 this._propValues = [];
@@ -45,75 +45,14 @@ var FlagMaterial = function FlagMaterial() {
45 45
46 // a material can be animated or not. default is not. 46 // a material can be animated or not. default is not.
47 // Any material needing continuous rendering should override this method 47 // Any material needing continuous rendering should override this method
48 this.isAnimated = function() { return true; }; 48 this.isAnimated = function() { return true; };
49 this.getShaderDef = function() { return flagMaterialDef; }
49 50
50 /////////////////////////////////////////////////////////////////////// 51 ///////////////////////////////////////////////////////////////////////
51 // Methods 52 // Methods
52 /////////////////////////////////////////////////////////////////////// 53 ///////////////////////////////////////////////////////////////////////
53 // duplcate method requirde 54 // duplcate method requirde
54 55
55 this.setProperty = function( prop, value )
56 {
57 // make sure we have legitimate imput
58 var ok = this.validateProperty( prop, value );
59 if (!ok) {
60 console.log( "invalid property in Radial Gradient Material:" + prop + " : " + value );
61 }
62
63 switch (prop)
64 {
65 case "texmap":
66 this.setTextureMap(value);
67 break;
68
69 case "wavewidth":
70 this._waveWidth = value;
71 this._propValues[ this._propNames[1] ] = this._waveWidth;
72 this.updateParameters();
73 break;
74
75 case "waveheight":
76 this._waveHeight = value;
77 this._propValues[ this._propNames[2] ] = this._waveHeight;
78 this.updateParameters();
79 break;
80
81 case "speed":
82 this._speed = value;
83 this._propValues[ this._propNames[3] ] = this._speed;
84 this.updateParameters();
85 break;
86
87 case "color":
88 break;
89 }
90 };
91
92
93 this.updateParameters = function()
94 {
95 this._propValues[ this._propNames[1] ] = this._waveWidth;
96 this._propValues[ this._propNames[2] ] = this._waveHeight;
97 this._propValues[ this._propNames[3] ] = this._speed;
98
99 var material = this._materialNode;
100 if (material)
101 {
102 var technique = material.shaderProgram['default'];
103 var renderer = RDGE.globals.engine.getContext().renderer;
104 if (renderer && technique)
105 {
106
107 if (this._shader && this._shader['default']) {
108 this._shader['default'].u_speed.set( [this._speed] );
109 this._shader['default'].u_waveWidth.set( [this._waveWidth] );
110 this._shader['default'].u_waveHeight.set( [this._waveHeight] );
111 }
112 }
113 }
114 };
115
116
117 this.init = function( world ) 56 this.init = function( world )
118 { 57 {
119 // save the world 58 // save the world
@@ -129,52 +68,13 @@ var FlagMaterial = function FlagMaterial() {
129 this._materialNode.setShader(this._shader); 68 this._materialNode.setShader(this._shader);
130 69
131 this._time = 0; 70 this._time = 0;
132 if (this._shader && this._shader['default']) { 71 if (this._shader && this._shader['default'])
133 this._shader['default'].u_time.set( [this._time] ); 72 this._shader['default'].u_time.set( [this._time] );
134 this._shader['default'].u_waveWidth.set( [this._propValues[ this._propNames[1] ]] );
135 this._shader['default'].u_waveHeight.set( [this._propValues[ this._propNames[2] ]] );
136 }
137
138 // set up the texture
139 var texMapName = this._propValues[this._propNames[0]];
140 this._glTex = new Texture( world, texMapName );
141 73
142 // set the shader values in the shader 74 // set the shader values in the shader
143 this.updateParameters(); 75 this.setShaderValues();
144 this.updateTexture();
145 this.update( 0 ); 76 this.update( 0 );
146 } 77 }
147
148 this.exportJSON = function () {
149 var jObj =
150 {
151 'material' : this.getShaderName(),
152 'name' : this.getName(),
153
154 'texMap' : this._propValues[this._propNames[0]],
155 'waveWidth' : this._propValues[this._propNames[1]],
156 'waveHeight' : this._propValues[this._propNames[2]],
157 'speed' : this._propValues[this._propNames[3]]
158 };
159
160 return jObj;
161 };
162
163 this.importJSON = function (jObj) {
164 if (this.getShaderName() != jObj.material) throw new Error("ill-formed material");
165 this.setName(jObj.name);
166
167 try {
168
169 this._texMap = this._propValues[this._propNames[0]] = jObj.texMap;
170 this._waveWidth = this._propValues[this._propNames[1]] = jObj.waveWidth;
171 this._waveHeight = this._propValues[this._propNames[2]] = jObj.waveHeight;
172 this._speed = this._propValues[this._propNames[3]] = jObj.speed;
173 }
174 catch (e) {
175 throw new Error("could not import material: " + importStr);
176 }
177 };
178}; 78};
179 79
180/////////////////////////////////////////////////////////////////////////////////////// 80///////////////////////////////////////////////////////////////////////////////////////