diff options
Diffstat (limited to 'js/lib/rdge/materials/pulse-material.js')
-rw-r--r-- | js/lib/rdge/materials/pulse-material.js | 69 |
1 files changed, 12 insertions, 57 deletions
diff --git a/js/lib/rdge/materials/pulse-material.js b/js/lib/rdge/materials/pulse-material.js index 4ba5110e..eedccf71 100644 --- a/js/lib/rdge/materials/pulse-material.js +++ b/js/lib/rdge/materials/pulse-material.js | |||
@@ -76,9 +76,8 @@ var PulseMaterial = function PulseMaterial() | |||
76 | /////////////////////////////////////////////////////////////////////// | 76 | /////////////////////////////////////////////////////////////////////// |
77 | // Methods | 77 | // Methods |
78 | /////////////////////////////////////////////////////////////////////// | 78 | /////////////////////////////////////////////////////////////////////// |
79 | // duplcate method requirde | 79 | // duplicate method required |
80 | this.dup = function( world ) | 80 | this.dup = function( world ) { |
81 | { | ||
82 | // save the world | 81 | // save the world |
83 | if (world) this.setWorld( world ); | 82 | if (world) this.setWorld( world ); |
84 | 83 | ||
@@ -96,8 +95,7 @@ var PulseMaterial = function PulseMaterial() | |||
96 | return newMat; | 95 | return newMat; |
97 | }; | 96 | }; |
98 | 97 | ||
99 | this.init = function( world ) | 98 | this.init = function( world ) { |
100 | { | ||
101 | // save the world | 99 | // save the world |
102 | if (world) this.setWorld( world ); | 100 | if (world) this.setWorld( world ); |
103 | 101 | ||
@@ -106,12 +104,12 @@ var PulseMaterial = function PulseMaterial() | |||
106 | this._dTime = 0.01; | 104 | this._dTime = 0.01; |
107 | 105 | ||
108 | // set up the shader | 106 | // set up the shader |
109 | this._shader = new jshader(); | 107 | this._shader = new RDGE.jshader(); |
110 | this._shader.def = pulseMaterialDef; | 108 | this._shader.def = pulseMaterialDef; |
111 | this._shader.init(); | 109 | this._shader.init(); |
112 | 110 | ||
113 | // set up the material node | 111 | // set up the material node |
114 | this._materialNode = createMaterialNode("pulseMaterial" + "_" + world.generateUniqueNodeID()); | 112 | this._materialNode = RDGE.createMaterialNode("pulseMaterial" + "_" + world.generateUniqueNodeID()); |
115 | this._materialNode.setShader(this._shader); | 113 | this._materialNode.setShader(this._shader); |
116 | 114 | ||
117 | this._time = 0; | 115 | this._time = 0; |
@@ -133,7 +131,7 @@ var PulseMaterial = function PulseMaterial() | |||
133 | var material = this._materialNode; | 131 | var material = this._materialNode; |
134 | if (material) { | 132 | if (material) { |
135 | var technique = material.shaderProgram['default']; | 133 | var technique = material.shaderProgram['default']; |
136 | var renderer = g_Engine.getContext().renderer; | 134 | var renderer = RDGE.globals.engine.getContext().renderer; |
137 | if (renderer && technique) { | 135 | if (renderer && technique) { |
138 | var wrap = 'REPEAT', mips = true; | 136 | var wrap = 'REPEAT', mips = true; |
139 | var tex; | 137 | var tex; |
@@ -143,7 +141,7 @@ var PulseMaterial = function PulseMaterial() | |||
143 | this._glTex.render(); | 141 | this._glTex.render(); |
144 | tex = this._glTex.getTexture(); | 142 | tex = this._glTex.getTexture(); |
145 | } | 143 | } |
146 | 144 | ||
147 | if (tex) { | 145 | if (tex) { |
148 | technique.u_tex0.set( tex ); | 146 | technique.u_tex0.set( tex ); |
149 | } | 147 | } |
@@ -171,7 +169,7 @@ var PulseMaterial = function PulseMaterial() | |||
171 | if (material) | 169 | if (material) |
172 | { | 170 | { |
173 | var technique = material.shaderProgram['default']; | 171 | var technique = material.shaderProgram['default']; |
174 | var renderer = g_Engine.getContext().renderer; | 172 | var renderer = RDGE.globals.engine.getContext().renderer; |
175 | if (renderer && technique) | 173 | if (renderer && technique) |
176 | { | 174 | { |
177 | if (this._glTex) | 175 | if (this._glTex) |
@@ -198,7 +196,7 @@ var PulseMaterial = function PulseMaterial() | |||
198 | var material = this._materialNode; | 196 | var material = this._materialNode; |
199 | if (material) { | 197 | if (material) { |
200 | var technique = material.shaderProgram['default']; | 198 | var technique = material.shaderProgram['default']; |
201 | var renderer = g_Engine.getContext().renderer; | 199 | var renderer = RDGE.globals.engine.getContext().renderer; |
202 | if (renderer && technique) { | 200 | if (renderer && technique) { |
203 | technique.u_resolution.set( res ); | 201 | technique.u_resolution.set( res ); |
204 | } | 202 | } |
@@ -219,65 +217,22 @@ var PulseMaterial = function PulseMaterial() | |||
219 | return jObj; | 217 | return jObj; |
220 | }; | 218 | }; |
221 | 219 | ||
222 | this.importJSON = function( jObj ) | 220 | this.importJSON = function( jObj ) { |
223 | { | ||
224 | if (this.getShaderName() != jObj.material) throw new Error( "ill-formed material" ); | 221 | if (this.getShaderName() != jObj.material) throw new Error( "ill-formed material" ); |
225 | this.setName( jObj.name ); | 222 | this.setName( jObj.name ); |
226 | 223 | ||
227 | try { | 224 | try { |
228 | this._propValues[this._propNames[0]] = jObj.texture; | 225 | this._propValues[this._propNames[0]] = jObj.texture; |
229 | this._texMap = jObj.texture; | 226 | this._texMap = jObj.texture; |
230 | if (jObj.dTime) | 227 | if (jObj.dTime) { |
231 | this._dTime = jObj.dTime; | 228 | this._dTime = jObj.dTime; |
229 | } | ||
232 | } | 230 | } |
233 | catch (e) | 231 | catch (e) |
234 | { | 232 | { |
235 | throw new Error( "could not import material: " + jObj ); | 233 | throw new Error( "could not import material: " + jObj ); |
236 | } | 234 | } |
237 | } | ||
238 | |||
239 | /* | ||
240 | this.export = function() { | ||
241 | // every material needs the base type and instance name | ||
242 | var exportStr = "material: " + this.getShaderName() + "\n"; | ||
243 | exportStr += "name: " + this.getName() + "\n"; | ||
244 | |||
245 | var world = this.getWorld(); | ||
246 | if (!world) | ||
247 | throw new Error( "no world in material.export, " + this.getName() ); | ||
248 | |||
249 | var texMapName = this._propValues[this._propNames[0]]; | ||
250 | exportStr += "texture: " +texMapName + "\n"; | ||
251 | |||
252 | // every material needs to terminate like this | ||
253 | exportStr += "endMaterial\n"; | ||
254 | |||
255 | return exportStr; | ||
256 | }; | 235 | }; |
257 | |||
258 | this.import = function( importStr ) { | ||
259 | var pu = new MaterialParser( importStr ); | ||
260 | var material = pu.nextValue( "material: " ); | ||
261 | if (material != this.getShaderName()) throw new Error( "ill-formed material" ); | ||
262 | this.setName( pu.nextValue( "name: ") ); | ||
263 | |||
264 | var rtnStr; | ||
265 | try { | ||
266 | this._propValues[this._propNames[0]] = pu.nextValue( "texture: " ); | ||
267 | |||
268 | var endKey = "endMaterial\n"; | ||
269 | var index = importStr.indexOf( endKey ); | ||
270 | index += endKey.length; | ||
271 | rtnStr = importStr.substr( index ); | ||
272 | } | ||
273 | catch (e) | ||
274 | { | ||
275 | throw new Error( "could not import material: " + importStr ); | ||
276 | } | ||
277 | |||
278 | return rtnStr; | ||
279 | } | ||
280 | */ | ||
281 | }; | 236 | }; |
282 | 237 | ||
283 | /////////////////////////////////////////////////////////////////////////////////////// | 238 | /////////////////////////////////////////////////////////////////////////////////////// |