diff options
author | hwc487 | 2012-03-21 15:17:58 -0700 |
---|---|---|
committer | hwc487 | 2012-03-21 15:17:58 -0700 |
commit | eb59a523258cad3351cba9bf8de986e90a8e5b1c (patch) | |
tree | 98d07254f11e983631f27fe2d76b1c03a8646abf /js/models | |
parent | 6b6fa1ec7d39057ce937f090b2965c09f1930070 (diff) | |
download | ninja-eb59a523258cad3351cba9bf8de986e90a8e5b1c.tar.gz |
Added material library data to the canvas data.
Diffstat (limited to 'js/models')
-rwxr-xr-x | js/models/materials-model.js | 53 |
1 files changed, 30 insertions, 23 deletions
diff --git a/js/models/materials-model.js b/js/models/materials-model.js index 9c692f45..291f7567 100755 --- a/js/models/materials-model.js +++ b/js/models/materials-model.js | |||
@@ -174,36 +174,47 @@ exports.MaterialsModel = Montage.create(Component, { | |||
174 | }, | 174 | }, |
175 | 175 | ||
176 | exportMaterials: { | 176 | exportMaterials: { |
177 | value: function() { | 177 | value: function() |
178 | 178 | { | |
179 | var exportStr = "MaterialLibrary: \n"; | 179 | var matArray = []; |
180 | |||
181 | var nMats = this._materials.length; | 180 | var nMats = this._materials.length; |
182 | |||
183 | for (var i=0; i<nMats; i++) { | 181 | for (var i=0; i<nMats; i++) { |
184 | var material = this._materials[i]; | 182 | var material = this._materials[i]; |
185 | exportStr += material.export(); | 183 | var matObj = material.exportJSON(); |
184 | matArray.push( matObj ); | ||
186 | } | 185 | } |
187 | 186 | ||
188 | exportStr += "endMatLib\n"; | 187 | var jObj = |
189 | return exportStr; | 188 | { |
189 | 'materialLibrary': 1.0, | ||
190 | 'materials': matArray | ||
191 | }; | ||
192 | |||
193 | // prepend an identifiable string to aid parsing when the | ||
194 | // material model is loaded. | ||
195 | var jStr = "materialLibrary;" + JSON.stringify( jObj ); | ||
196 | |||
197 | return jStr; | ||
190 | } | 198 | } |
191 | }, | 199 | }, |
192 | 200 | ||
193 | importMaterials: { | 201 | importMaterials: { |
194 | value: function( importStr ) { | 202 | value: function( jObj ) |
203 | { | ||
204 | // make sure we have some materials to import before doing anything | ||
205 | var matArray = jObj.materials; | ||
206 | if (!matArray) return; | ||
207 | |||
195 | // we replace allmaterials, so remove anything | 208 | // we replace allmaterials, so remove anything |
196 | // that is currently there. | 209 | // that is currently there. |
197 | this.clearAllMaterials(); | 210 | this.clearAllMaterials(); |
198 | 211 | ||
199 | var pu = new MaterialParser( importStr ); | 212 | var nMats = matArray.length; |
200 | 213 | for (var i=0; i<nMats; i++) | |
201 | var type = pu.nextValue( "material: ", "\n", false ); | 214 | { |
202 | 215 | var mat = null; | |
203 | while (type) { | 216 | var jMatObj = matArray[i]; |
204 | 217 | var type = jMatObj.material; | |
205 | var mat = null; | ||
206 | |||
207 | switch (type) | 218 | switch (type) |
208 | { | 219 | { |
209 | case "flat": mat = new FlatMaterial(); break; | 220 | case "flat": mat = new FlatMaterial(); break; |
@@ -233,20 +244,16 @@ exports.MaterialsModel = Montage.create(Component, { | |||
233 | 244 | ||
234 | default: | 245 | default: |
235 | throw new Error( "Unrecognized material type: " + type ); | 246 | throw new Error( "Unrecognized material type: " + type ); |
236 | pu.advancePastToken( "endMaterial\n" ); | ||
237 | break; | 247 | break; |
238 | } | 248 | } |
239 | 249 | ||
240 | if (mat) { | 250 | if (mat) { |
241 | importStr = mat.import( importStr ); | 251 | importStr = mat.importJSON( jMatObj ); |
242 | pu._strBuffer = importStr; | ||
243 | this.addMaterial( mat ); | 252 | this.addMaterial( mat ); |
244 | } | 253 | } |
245 | |||
246 | type = pu.nextValue( "material: ", "\n", false ); | ||
247 | } | 254 | } |
248 | 255 | ||
249 | return pu._strBuffer; | 256 | return; |
250 | } | 257 | } |
251 | } | 258 | } |
252 | 259 | ||