aboutsummaryrefslogtreecommitdiff
path: root/js/lib/geom/geom-obj.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/geom/geom-obj.js')
-rwxr-xr-xjs/lib/geom/geom-obj.js154
1 files changed, 114 insertions, 40 deletions
diff --git a/js/lib/geom/geom-obj.js b/js/lib/geom/geom-obj.js
index a64980e0..dbef4859 100755
--- a/js/lib/geom/geom-obj.js
+++ b/js/lib/geom/geom-obj.js
@@ -5,26 +5,6 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
5</copyright> */ 5</copyright> */
6 6
7var MaterialsModel = require("js/models/materials-model").MaterialsModel; 7var MaterialsModel = require("js/models/materials-model").MaterialsModel;
8var FlatMaterial = require("js/lib/rdge/materials/flat-material").FlatMaterial;
9var LinearGradientMaterial = require("js/lib/rdge/materials/linear-gradient-material").LinearGradientMaterial;
10var RadialGradientMaterial = require("js/lib/rdge/materials/radial-gradient-material").RadialGradientMaterial;
11var BumpMetalMaterial = require("js/lib/rdge/materials/bump-metal-material").BumpMetalMaterial;
12var UberMaterial = require("js/lib/rdge/materials/uber-material").UberMaterial;
13var RadialBlurMaterial = require("js/lib/rdge/materials/radial-blur-material").RadialBlurMaterial;
14var PlasmaMaterial = require("js/lib/rdge/materials/plasma-material").PlasmaMaterial;
15var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial;
16var TunnelMaterial = require("js/lib/rdge/materials/tunnel-material").TunnelMaterial;
17var ReliefTunnelMaterial = require("js/lib/rdge/materials/relief-tunnel-material").ReliefTunnelMaterial;
18var SquareTunnelMaterial = require("js/lib/rdge/materials/square-tunnel-material").SquareTunnelMaterial;
19var FlyMaterial = require("js/lib/rdge/materials/fly-material").FlyMaterial;
20var WaterMaterial = require("js/lib/rdge/materials/water-material").WaterMaterial;
21var ZInvertMaterial = require("js/lib/rdge/materials/z-invert-material").ZInvertMaterial;
22var DeformMaterial = require("js/lib/rdge/materials/deform-material").DeformMaterial;
23var StarMaterial = require("js/lib/rdge/materials/star-material").StarMaterial;
24var TwistMaterial = require("js/lib/rdge/materials/twist-material").TwistMaterial;
25var JuliaMaterial = require("js/lib/rdge/materials/julia-material").JuliaMaterial;
26var KeleidoscopeMaterial = require("js/lib/rdge/materials/keleidoscope-material").KeleidoscopeMaterial;
27var MandelMaterial = require("js/lib/rdge/materials/mandel-material").MandelMaterial;
28 8
29/////////////////////////////////////////////////////////////////////// 9///////////////////////////////////////////////////////////////////////
30// Class GLGeomObj 10// Class GLGeomObj
@@ -265,6 +245,96 @@ var GeomObj = function GLGeomObj() {
265 return fillMaterial; 245 return fillMaterial;
266 }; 246 };
267 247
248 this.exportMaterialsJSON = function()
249 {
250 var jObj;
251 if (this._materialArray && this._materialNodeArray)
252 {
253 var nMats = this._materialArray.length;
254 if (nMats > 0)
255 {
256 var arr = [];
257
258 for (var i=0; i<nMats; i++)
259 {
260 var matObj =
261 {
262 'materialNodeName' : this._materialNodeArray[i].name,
263 'material' : this._materialArray[i].exportJSON(),
264 'type' : this._materialTypeArray[i]
265 }
266 arr.push( matObj );
267 }
268
269 jObj =
270 {
271 'nMaterials' : nMats,
272 'materials' : arr
273 };
274 }
275 }
276
277 return jObj;
278 }
279
280 this.importMaterialsJSON = function( jObj )
281 {
282 this._materialArray = [];
283 this._materialTypeArray = [];
284
285 if (!jObj) return;
286
287 var nMaterials = jObj.nMaterials;
288 var matArray = jObj.materials;
289 for (var i=0; i<nMaterials; i++)
290 {
291 var mat;
292 var matObj = matArray[i].material;
293 var shaderName = matObj.material;
294 switch (shaderName)
295 {
296 case "flat":
297 case "radialGradient":
298 case "linearGradient":
299 case "bumpMetal":
300 case "uber":
301 case "plasma":
302 case "deform":
303 case "water":
304 case "paris":
305 case "tunnel":
306 case "reliefTunnel":
307 case "squareTunnel":
308 case "twist":
309 case "fly":
310 case "julia":
311 case "mandel":
312 case "star":
313 case "zinvert":
314 case "keleidoscope":
315 case "radialBlur":
316 case "pulse":
317 mat = MaterialsModel.getMaterialByShader( shaderName );
318 if (mat) mat = mat.dup();
319 break;
320
321 default:
322 console.log( "material type: " + shaderName + " is not supported" );
323 break;
324 }
325
326 if (mat)
327 {
328 mat.importJSON( matObj );
329 this._materialArray.push( mat );
330 this._materialTypeArray.push( matObj.type );
331 var type = matArray[i].type;
332 if (type == "fill") this._fillMaterial = mat;
333 else this._strokeMaterial = mat;
334 }
335 }
336 }
337
268 this.exportMaterials = function() 338 this.exportMaterials = function()
269 { 339 {
270 var rtnStr = ""; 340 var rtnStr = "";
@@ -296,26 +366,30 @@ var GeomObj = function GLGeomObj() {
296 var materialType = this.getPropertyFromString( "material: ", importStr ); 366 var materialType = this.getPropertyFromString( "material: ", importStr );
297 switch (materialType) 367 switch (materialType)
298 { 368 {
299 case "flat": mat = new FlatMaterial(); break; 369 case "flat":
300 case "radialGradient": mat = new RadialGradientMaterial(); break; 370 case "radialGradient":
301 case "linearGradient": mat = new LinearGradientMaterial(); break; 371 case "linearGradient":
302 case "bumpMetal": mat = new BumpMetalMaterial(); break; 372 case "bumpMetal":
303 case "uber": mat = new UberMaterial(); break; 373 case "uber":
304 case "plasma": mat = new PlasmaMaterial(); break; 374 case "plasma":
305 case "deform": mat = new DeformMaterial(); break; 375 case "deform":
306 case "water": mat = new WaterMaterial(); break; 376 case "water":
307 case "tunnel": mat = new TunnelMaterial(); break; 377 case "paris":
308 case "reliefTunnel": mat = new ReliefTunnelMaterial(); break; 378 case "tunnel":
309 case "squareTunnel": mat = new SquareTunnelMaterial(); break; 379 case "reliefTunnel":
310 case "twist": mat = new TwiseMaterial(); break; 380 case "squareTunnel":
311 case "fly": mat = new FlyMaterial(); break; 381 case "twist":
312 case "julia": mat = new JuliaMaterial(); break; 382 case "fly":
313 case "mandel": mat = new MandelMaterial(); break; 383 case "julia":
314 case "star": mat = new StarMaterial(); break; 384 case "mandel":
315 case "zinvert": mat = new ZInvertMaterial(); break; 385 case "star":
316 case "keleidoscope": mat = new KeleidoscopeMaterial(); break; 386 case "zinvert":
317 case "radialBlur": mat = new RadialBlurMaterial(); break; 387 case "keleidoscope":
318 case "pulse": mat = new PulseMaterial(); break; 388 case "radialBlur":
389 case "pulse":
390 mat = MaterialsModel.getMaterialByShader( materialType );
391 if (mat) mat = mat.dup();
392 break;
319 393
320 default: 394 default:
321 console.log( "material type: " + materialType + " is not supported" ); 395 console.log( "material type: " + materialType + " is not supported" );