aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/pulse-material.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/rdge/materials/pulse-material.js')
-rw-r--r--js/lib/rdge/materials/pulse-material.js68
1 files changed, 12 insertions, 56 deletions
diff --git a/js/lib/rdge/materials/pulse-material.js b/js/lib/rdge/materials/pulse-material.js
index 2075d1ff..f26aa16c 100644
--- a/js/lib/rdge/materials/pulse-material.js
+++ b/js/lib/rdge/materials/pulse-material.js
@@ -66,9 +66,8 @@ var PulseMaterial = function PulseMaterial() {
66 /////////////////////////////////////////////////////////////////////// 66 ///////////////////////////////////////////////////////////////////////
67 // Methods 67 // Methods
68 /////////////////////////////////////////////////////////////////////// 68 ///////////////////////////////////////////////////////////////////////
69 // duplcate method requirde 69 // duplicate method required
70 this.dup = function( world ) 70 this.dup = function( world ) {
71 {
72 // save the world 71 // save the world
73 if (world) this.setWorld( world ); 72 if (world) this.setWorld( world );
74 73
@@ -86,8 +85,7 @@ var PulseMaterial = function PulseMaterial() {
86 return newMat; 85 return newMat;
87 }; 86 };
88 87
89 this.init = function( world ) 88 this.init = function( world ) {
90 {
91 // save the world 89 // save the world
92 if (world) this.setWorld( world ); 90 if (world) this.setWorld( world );
93 91
@@ -96,12 +94,12 @@ var PulseMaterial = function PulseMaterial() {
96 this._dTime = 0.01; 94 this._dTime = 0.01;
97 95
98 // set up the shader 96 // set up the shader
99 this._shader = new jshader(); 97 this._shader = new RDGE.jshader();
100 this._shader.def = pulseMaterialDef; 98 this._shader.def = pulseMaterialDef;
101 this._shader.init(); 99 this._shader.init();
102 100
103 // set up the material node 101 // set up the material node
104 this._materialNode = createMaterialNode("pulseMaterial" + "_" + world.generateUniqueNodeID()); 102 this._materialNode = RDGE.createMaterialNode("pulseMaterial" + "_" + world.generateUniqueNodeID());
105 this._materialNode.setShader(this._shader); 103 this._materialNode.setShader(this._shader);
106 104
107 this._time = 0; 105 this._time = 0;
@@ -120,12 +118,12 @@ var PulseMaterial = function PulseMaterial() {
120 var material = this._materialNode; 118 var material = this._materialNode;
121 if (material) { 119 if (material) {
122 var technique = material.shaderProgram['default']; 120 var technique = material.shaderProgram['default'];
123 var renderer = g_Engine.getContext().renderer; 121 var renderer = RDGE.globals.engine.getContext().renderer;
124 if (renderer && technique) { 122 if (renderer && technique) {
125 var texMapName = this._propValues[this._propNames[0]]; 123 var texMapName = this._propValues[this._propNames[0]];
126 var wrap = 'REPEAT', mips = true; 124 var wrap = 'REPEAT', mips = true;
127 var tex = this.loadTexture( texMapName, wrap, mips ); 125 var tex = this.loadTexture( texMapName, wrap, mips );
128 126
129 if (tex) { 127 if (tex) {
130 technique.u_tex0.set( tex ); 128 technique.u_tex0.set( tex );
131 } 129 }
@@ -139,7 +137,7 @@ var PulseMaterial = function PulseMaterial() {
139 if (material) 137 if (material)
140 { 138 {
141 var technique = material.shaderProgram['default']; 139 var technique = material.shaderProgram['default'];
142 var renderer = g_Engine.getContext().renderer; 140 var renderer = RDGE.globals.engine.getContext().renderer;
143 if (renderer && technique) { 141 if (renderer && technique) {
144 if (this._shader && this._shader['default']) { 142 if (this._shader && this._shader['default']) {
145 this._shader['default'].u_time.set( [this._time] ); 143 this._shader['default'].u_time.set( [this._time] );
@@ -155,7 +153,7 @@ var PulseMaterial = function PulseMaterial() {
155 var material = this._materialNode; 153 var material = this._materialNode;
156 if (material) { 154 if (material) {
157 var technique = material.shaderProgram['default']; 155 var technique = material.shaderProgram['default'];
158 var renderer = g_Engine.getContext().renderer; 156 var renderer = RDGE.globals.engine.getContext().renderer;
159 if (renderer && technique) { 157 if (renderer && technique) {
160 technique.u_resolution.set( res ); 158 technique.u_resolution.set( res );
161 } 159 }
@@ -176,64 +174,22 @@ var PulseMaterial = function PulseMaterial() {
176 return jObj; 174 return jObj;
177 }; 175 };
178 176
179 this.importJSON = function( jObj ) 177 this.importJSON = function( jObj ) {
180 {
181 if (this.getShaderName() != jObj.material) throw new Error( "ill-formed material" ); 178 if (this.getShaderName() != jObj.material) throw new Error( "ill-formed material" );
182 this.setName( jObj.name ); 179 this.setName( jObj.name );
183 180
184 try { 181 try {
185 this._propValues[this._propNames[0]] = jObj.texture; 182 this._propValues[this._propNames[0]] = jObj.texture;
186 this._texMap = jObj.texture; 183 this._texMap = jObj.texture;
187 if (jObj.dTime) 184 if (jObj.dTime) {
188 this._dTime = jObj.dTime; 185 this._dTime = jObj.dTime;
186 }
189 } 187 }
190 catch (e) 188 catch (e)
191 { 189 {
192 throw new Error( "could not import material: " + jObj ); 190 throw new Error( "could not import material: " + jObj );
193 } 191 }
194 }
195
196
197 this.export = function() {
198 // every material needs the base type and instance name
199 var exportStr = "material: " + this.getShaderName() + "\n";
200 exportStr += "name: " + this.getName() + "\n";
201
202 var world = this.getWorld();
203 if (!world)
204 throw new Error( "no world in material.export, " + this.getName() );
205
206 var texMapName = this._propValues[this._propNames[0]];
207 exportStr += "texture: " +texMapName + "\n";
208
209 // every material needs to terminate like this
210 exportStr += "endMaterial\n";
211
212 return exportStr;
213 }; 192 };
214
215 this.import = function( importStr ) {
216 var pu = new MaterialParser( importStr );
217 var material = pu.nextValue( "material: " );
218 if (material != this.getShaderName()) throw new Error( "ill-formed material" );
219 this.setName( pu.nextValue( "name: ") );
220
221 var rtnStr;
222 try {
223 this._propValues[this._propNames[0]] = pu.nextValue( "texture: " );
224
225 var endKey = "endMaterial\n";
226 var index = importStr.indexOf( endKey );
227 index += endKey.length;
228 rtnStr = importStr.substr( index );
229 }
230 catch (e)
231 {
232 throw new Error( "could not import material: " + importStr );
233 }
234
235 return rtnStr;
236 }
237}; 193};
238 194
239/////////////////////////////////////////////////////////////////////////////////////// 195///////////////////////////////////////////////////////////////////////////////////////