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.js82
1 files changed, 29 insertions, 53 deletions
diff --git a/js/lib/rdge/materials/pulse-material.js b/js/lib/rdge/materials/pulse-material.js
index 81db36c6..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,24 +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 /*
130 var glTex = new GLTexture( this.getWorld() );
131 var prevWorld = this.findPreviousWorld();
132 if (prevWorld)
133 {
134 var srcCanvas = prevWorld.getCanvas();
135 tex = glTex.loadFromCanvas( srcCanvas );
136 }
137 else
138 tex = glTex.loadFromFile( texMapName, wrap, mips );
139 */
140
141 if (tex) { 127 if (tex) {
142 technique.u_tex0.set( tex ); 128 technique.u_tex0.set( tex );
143 } 129 }
@@ -151,7 +137,7 @@ var PulseMaterial = function PulseMaterial() {
151 if (material) 137 if (material)
152 { 138 {
153 var technique = material.shaderProgram['default']; 139 var technique = material.shaderProgram['default'];
154 var renderer = g_Engine.getContext().renderer; 140 var renderer = RDGE.globals.engine.getContext().renderer;
155 if (renderer && technique) { 141 if (renderer && technique) {
156 if (this._shader && this._shader['default']) { 142 if (this._shader && this._shader['default']) {
157 this._shader['default'].u_time.set( [this._time] ); 143 this._shader['default'].u_time.set( [this._time] );
@@ -167,53 +153,43 @@ var PulseMaterial = function PulseMaterial() {
167 var material = this._materialNode; 153 var material = this._materialNode;
168 if (material) { 154 if (material) {
169 var technique = material.shaderProgram['default']; 155 var technique = material.shaderProgram['default'];
170 var renderer = g_Engine.getContext().renderer; 156 var renderer = RDGE.globals.engine.getContext().renderer;
171 if (renderer && technique) { 157 if (renderer && technique) {
172 technique.u_resolution.set( res ); 158 technique.u_resolution.set( res );
173 } 159 }
174 } 160 }
175 }; 161 };
176 162
177 this.export = function() { 163 // JSON export
178 // every material needs the base type and instance name 164 this.exportJSON = function()
179 var exportStr = "material: " + this.getShaderName() + "\n"; 165 {
180 exportStr += "name: " + this.getName() + "\n"; 166 var jObj =
181 167 {
182 var world = this.getWorld(); 168 'material' : this.getShaderName(),
183 if (!world) 169 'name' : this.getName(),
184 throw new Error( "no world in material.export, " + this.getName() ); 170 'texture' : this._propValues[this._propNames[0]],
185 171 'dTime' : this._dTime
186 var texMapName = this._propValues[this._propNames[0]]; 172 };
187 exportStr += "texture: " +texMapName + "\n";
188
189 // every material needs to terminate like this
190 exportStr += "endMaterial\n";
191 173
192 return exportStr; 174 return jObj;
193 }; 175 };
194 176
195 this.import = function( importStr ) { 177 this.importJSON = function( jObj ) {
196 var pu = new MaterialParser( importStr ); 178 if (this.getShaderName() != jObj.material) throw new Error( "ill-formed material" );
197 var material = pu.nextValue( "material: " ); 179 this.setName( jObj.name );
198 if (material != this.getShaderName()) throw new Error( "ill-formed material" );
199 this.setName( pu.nextValue( "name: ") );
200 180
201 var rtnStr;
202 try { 181 try {
203 this._propValues[this._propNames[0]] = pu.nextValue( "texture: " ); 182 this._propValues[this._propNames[0]] = jObj.texture;
204 183 this._texMap = jObj.texture;
205 var endKey = "endMaterial\n"; 184 if (jObj.dTime) {
206 var index = importStr.indexOf( endKey ); 185 this._dTime = jObj.dTime;
207 index += endKey.length; 186 }
208 rtnStr = importStr.substr( index );
209 } 187 }
210 catch (e) 188 catch (e)
211 { 189 {
212 throw new Error( "could not import material: " + importStr ); 190 throw new Error( "could not import material: " + jObj );
213 } 191 }
214 192 };
215 return rtnStr;
216 }
217}; 193};
218 194
219/////////////////////////////////////////////////////////////////////////////////////// 195///////////////////////////////////////////////////////////////////////////////////////