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.js156
1 files changed, 116 insertions, 40 deletions
diff --git a/js/lib/geom/geom-obj.js b/js/lib/geom/geom-obj.js
index a64980e0..3c4e4bbf 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,97 @@ 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 && this.getWorld().isWebGL())
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 "raiders":
306 case "tunnel":
307 case "reliefTunnel":
308 case "squareTunnel":
309 case "twist":
310 case "fly":
311 case "julia":
312 case "mandel":
313 case "star":
314 case "zinvert":
315 case "keleidoscope":
316 case "radialBlur":
317 case "pulse":
318 mat = MaterialsModel.getMaterialByShader( shaderName );
319 if (mat) mat = mat.dup();
320 break;
321
322 default:
323 console.log( "material type: " + shaderName + " is not supported" );
324 break;
325 }
326
327 if (mat)
328 {
329 mat.importJSON( matObj );
330 this._materialArray.push( mat );
331 this._materialTypeArray.push( matObj.type );
332 var type = matArray[i].type;
333 if (type == "fill") this._fillMaterial = mat;
334 else this._strokeMaterial = mat;
335 }
336 }
337 }
338
268 this.exportMaterials = function() 339 this.exportMaterials = function()
269 { 340 {
270 var rtnStr = ""; 341 var rtnStr = "";
@@ -296,26 +367,31 @@ var GeomObj = function GLGeomObj() {
296 var materialType = this.getPropertyFromString( "material: ", importStr ); 367 var materialType = this.getPropertyFromString( "material: ", importStr );
297 switch (materialType) 368 switch (materialType)
298 { 369 {
299 case "flat": mat = new FlatMaterial(); break; 370 case "flat":
300 case "radialGradient": mat = new RadialGradientMaterial(); break; 371 case "radialGradient":
301 case "linearGradient": mat = new LinearGradientMaterial(); break; 372 case "linearGradient":
302 case "bumpMetal": mat = new BumpMetalMaterial(); break; 373 case "bumpMetal":
303 case "uber": mat = new UberMaterial(); break; 374 case "uber":
304 case "plasma": mat = new PlasmaMaterial(); break; 375 case "plasma":
305 case "deform": mat = new DeformMaterial(); break; 376 case "deform":
306 case "water": mat = new WaterMaterial(); break; 377 case "water":
307 case "tunnel": mat = new TunnelMaterial(); break; 378 case "paris":
308 case "reliefTunnel": mat = new ReliefTunnelMaterial(); break; 379 case "raiders":
309 case "squareTunnel": mat = new SquareTunnelMaterial(); break; 380 case "tunnel":
310 case "twist": mat = new TwiseMaterial(); break; 381 case "reliefTunnel":
311 case "fly": mat = new FlyMaterial(); break; 382 case "squareTunnel":
312 case "julia": mat = new JuliaMaterial(); break; 383 case "twist":
313 case "mandel": mat = new MandelMaterial(); break; 384 case "fly":
314 case "star": mat = new StarMaterial(); break; 385 case "julia":
315 case "zinvert": mat = new ZInvertMaterial(); break; 386 case "mandel":
316 case "keleidoscope": mat = new KeleidoscopeMaterial(); break; 387 case "star":
317 case "radialBlur": mat = new RadialBlurMaterial(); break; 388 case "zinvert":
318 case "pulse": mat = new PulseMaterial(); break; 389 case "keleidoscope":
390 case "radialBlur":
391 case "pulse":
392 mat = MaterialsModel.getMaterialByShader( materialType );
393 if (mat) mat = mat.dup();
394 break;
319 395
320 default: 396 default:
321 console.log( "material type: " + materialType + " is not supported" ); 397 console.log( "material type: " + materialType + " is not supported" );