diff options
Diffstat (limited to 'js/lib/rdge/materials/pulse-material.js')
-rw-r--r-- | js/lib/rdge/materials/pulse-material.js | 55 |
1 files changed, 42 insertions, 13 deletions
diff --git a/js/lib/rdge/materials/pulse-material.js b/js/lib/rdge/materials/pulse-material.js index 89cbaea4..47059533 100644 --- a/js/lib/rdge/materials/pulse-material.js +++ b/js/lib/rdge/materials/pulse-material.js | |||
@@ -101,7 +101,7 @@ var PulseMaterial = function PulseMaterial() { | |||
101 | this._shader.init(); | 101 | this._shader.init(); |
102 | 102 | ||
103 | // set up the material node | 103 | // set up the material node |
104 | this._materialNode = RDGE.createMaterialNode("pulseMaterial"); | 104 | this._materialNode = RDGE.createMaterialNode("pulseMaterial" + "_" + world.generateUniqueNodeID()); |
105 | this._materialNode.setShader(this._shader); | 105 | this._materialNode.setShader(this._shader); |
106 | 106 | ||
107 | this._time = 0; | 107 | this._time = 0; |
@@ -126,18 +126,6 @@ var PulseMaterial = function PulseMaterial() { | |||
126 | var wrap = 'REPEAT', mips = true; | 126 | var wrap = 'REPEAT', mips = true; |
127 | var tex = this.loadTexture( texMapName, wrap, mips ); | 127 | var tex = this.loadTexture( texMapName, wrap, mips ); |
128 | 128 | ||
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) { | 129 | if (tex) { |
142 | technique.u_tex0.set( tex ); | 130 | technique.u_tex0.set( tex ); |
143 | } | 131 | } |
@@ -174,11 +162,50 @@ var PulseMaterial = function PulseMaterial() { | |||
174 | } | 162 | } |
175 | }; | 163 | }; |
176 | 164 | ||
165 | // JSON export | ||
166 | this.exportJSON = function() | ||
167 | { | ||
168 | var jObj = | ||
169 | { | ||
170 | 'material' : this.getShaderName(), | ||
171 | 'name' : this.getName(), | ||
172 | 'texture' : this._propValues[this._propNames[0]], | ||
173 | 'dTime' : this._dTime | ||
174 | }; | ||
175 | |||
176 | return jObj; | ||
177 | }; | ||
178 | |||
179 | this.importJSON = function( jObj ) { | ||
180 | if (this.getShaderName() != jObj.material) throw new Error( "ill-formed material" ); | ||
181 | this.setName( jObj.name ); | ||
182 | |||
183 | try { | ||
184 | this._propValues[this._propNames[0]] = jObj.texture; | ||
185 | this._texMap = jObj.texture; | ||
186 | if (jObj.dTime) { | ||
187 | this._dTime = jObj.dTime; | ||
188 | } | ||
189 | } | ||
190 | catch (e) | ||
191 | { | ||
192 | throw new Error( "could not import material: " + jObj ); | ||
193 | } | ||
194 | }; | ||
195 | |||
196 | |||
177 | this.export = function() { | 197 | this.export = function() { |
178 | // every material needs the base type and instance name | 198 | // every material needs the base type and instance name |
179 | var exportStr = "material: " + this.getShaderName() + "\n"; | 199 | var exportStr = "material: " + this.getShaderName() + "\n"; |
180 | exportStr += "name: " + this.getName() + "\n"; | 200 | exportStr += "name: " + this.getName() + "\n"; |
181 | 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 | |||
182 | // every material needs to terminate like this | 209 | // every material needs to terminate like this |
183 | exportStr += "endMaterial\n"; | 210 | exportStr += "endMaterial\n"; |
184 | 211 | ||
@@ -193,6 +220,8 @@ var PulseMaterial = function PulseMaterial() { | |||
193 | 220 | ||
194 | var rtnStr; | 221 | var rtnStr; |
195 | try { | 222 | try { |
223 | this._propValues[this._propNames[0]] = pu.nextValue( "texture: " ); | ||
224 | |||
196 | var endKey = "endMaterial\n"; | 225 | var endKey = "endMaterial\n"; |
197 | var index = importStr.indexOf( endKey ); | 226 | var index = importStr.indexOf( endKey ); |
198 | index += endKey.length; | 227 | index += endKey.length; |