diff options
author | hwc487 | 2012-03-16 12:26:30 -0700 |
---|---|---|
committer | hwc487 | 2012-03-16 12:26:30 -0700 |
commit | a0d23354802ebc6b437698acb4b18d3395d47cd1 (patch) | |
tree | a0081c079c9fc557e10a828db9adeed5a91d5a72 /js/lib/geom/geom-obj.js | |
parent | 57d4a82977a1f0e809511fe894886f88581d9615 (diff) | |
download | ninja-a0d23354802ebc6b437698acb4b18d3395d47cd1.tar.gz |
Conversion to JSON based file IO for canvas2D and WebGL rendering
Diffstat (limited to 'js/lib/geom/geom-obj.js')
-rwxr-xr-x | js/lib/geom/geom-obj.js | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/js/lib/geom/geom-obj.js b/js/lib/geom/geom-obj.js index 35ebadb9..2a5b0641 100755 --- a/js/lib/geom/geom-obj.js +++ b/js/lib/geom/geom-obj.js | |||
@@ -5,6 +5,7 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
5 | </copyright> */ | 5 | </copyright> */ |
6 | 6 | ||
7 | var MaterialsModel = require("js/models/materials-model").MaterialsModel; | 7 | var MaterialsModel = require("js/models/materials-model").MaterialsModel; |
8 | /* | ||
8 | var FlatMaterial = require("js/lib/rdge/materials/flat-material").FlatMaterial; | 9 | var FlatMaterial = require("js/lib/rdge/materials/flat-material").FlatMaterial; |
9 | var LinearGradientMaterial = require("js/lib/rdge/materials/linear-gradient-material").LinearGradientMaterial; | 10 | var LinearGradientMaterial = require("js/lib/rdge/materials/linear-gradient-material").LinearGradientMaterial; |
10 | var RadialGradientMaterial = require("js/lib/rdge/materials/radial-gradient-material").RadialGradientMaterial; | 11 | var RadialGradientMaterial = require("js/lib/rdge/materials/radial-gradient-material").RadialGradientMaterial; |
@@ -25,6 +26,7 @@ var TwistMaterial = require("js/lib/rdge/materials/twist-material").TwistMateria | |||
25 | var JuliaMaterial = require("js/lib/rdge/materials/julia-material").JuliaMaterial; | 26 | var JuliaMaterial = require("js/lib/rdge/materials/julia-material").JuliaMaterial; |
26 | var KeleidoscopeMaterial = require("js/lib/rdge/materials/keleidoscope-material").KeleidoscopeMaterial; | 27 | var KeleidoscopeMaterial = require("js/lib/rdge/materials/keleidoscope-material").KeleidoscopeMaterial; |
27 | var MandelMaterial = require("js/lib/rdge/materials/mandel-material").MandelMaterial; | 28 | var MandelMaterial = require("js/lib/rdge/materials/mandel-material").MandelMaterial; |
29 | */ | ||
28 | 30 | ||
29 | /////////////////////////////////////////////////////////////////////// | 31 | /////////////////////////////////////////////////////////////////////// |
30 | // Class GLGeomObj | 32 | // Class GLGeomObj |
@@ -225,6 +227,83 @@ var GeomObj = function GLGeomObj() { | |||
225 | return fillMaterial; | 227 | return fillMaterial; |
226 | }; | 228 | }; |
227 | 229 | ||
230 | this.exportMaterialsJSON = function() | ||
231 | { | ||
232 | var jObj; | ||
233 | if (this._materialArray && this._materialNodeArray) | ||
234 | { | ||
235 | var nMats = this._materialArray.length; | ||
236 | if (nMats > 0) | ||
237 | { | ||
238 | var arr = []; | ||
239 | |||
240 | for (var i=0; i<nMats; i++) | ||
241 | { | ||
242 | var matObj = | ||
243 | { | ||
244 | 'materialNodeName' : this._materialNodeArray[i].name, | ||
245 | 'material' : this._materialArray[i].exportJSON(), | ||
246 | 'type' : this._materialTypeArray[i] | ||
247 | } | ||
248 | arr.push( matObj ); | ||
249 | } | ||
250 | |||
251 | jObj = | ||
252 | { | ||
253 | 'nMaterials' : nMats, | ||
254 | 'materials' : arr | ||
255 | }; | ||
256 | } | ||
257 | } | ||
258 | |||
259 | return jObj; | ||
260 | } | ||
261 | |||
262 | this.importMaterialsJSON = function( jObj ) | ||
263 | { | ||
264 | var nMaterials = jObj.nMaterials; | ||
265 | var matArray = jObj.materials; | ||
266 | for (var i=0; i<nMaterials; i++) | ||
267 | { | ||
268 | var mat; | ||
269 | var matObj = matArray[i].material; | ||
270 | var shaderName = matObj.material; | ||
271 | switch (shaderName) | ||
272 | { | ||
273 | case "flat": | ||
274 | case "radialGradient": | ||
275 | case "linearGradient": | ||
276 | case "bumpMetal": | ||
277 | case "uber": | ||
278 | case "plasma": | ||
279 | case "deform": | ||
280 | case "water": | ||
281 | case "tunnel": | ||
282 | case "reliefTunnel": | ||
283 | case "squareTunnel": | ||
284 | case "twist": | ||
285 | case "fly": | ||
286 | case "julia": | ||
287 | case "mandel": | ||
288 | case "star": | ||
289 | case "zinvert": | ||
290 | case "keleidoscope": | ||
291 | case "radialBlur": | ||
292 | case "pulse": | ||
293 | mat = MaterialsModel.getMaterialByShader( shaderName ); | ||
294 | if (mat) mat = mat.dup(); | ||
295 | break; | ||
296 | |||
297 | default: | ||
298 | console.log( "material type: " + materialType + " is not supported" ); | ||
299 | break; | ||
300 | } | ||
301 | |||
302 | if (mat) | ||
303 | mat.importJSON( matObj ); | ||
304 | } | ||
305 | } | ||
306 | |||
228 | this.exportMaterials = function() | 307 | this.exportMaterials = function() |
229 | { | 308 | { |
230 | var rtnStr = ""; | 309 | var rtnStr = ""; |