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.js157
1 files changed, 117 insertions, 40 deletions
diff --git a/js/lib/geom/geom-obj.js b/js/lib/geom/geom-obj.js
index a64980e0..f1aa9f8a 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
@@ -39,6 +19,7 @@ var GeomObj = function GLGeomObj() {
39 this.GEOM_TYPE_LINE = 3; 19 this.GEOM_TYPE_LINE = 3;
40 this.GEOM_TYPE_PATH = 4; 20 this.GEOM_TYPE_PATH = 4;
41 this.GEOM_TYPE_CUBIC_BEZIER = 5; 21 this.GEOM_TYPE_CUBIC_BEZIER = 5;
22 this.GEOM_TYPE_BRUSH_STROKE = 6;
42 this.GEOM_TYPE_UNDEFINED = -1; 23 this.GEOM_TYPE_UNDEFINED = -1;
43 24
44 // Needed for calculating dashed/dotted strokes 25 // Needed for calculating dashed/dotted strokes
@@ -265,6 +246,97 @@ var GeomObj = function GLGeomObj() {
265 return fillMaterial; 246 return fillMaterial;
266 }; 247 };
267 248
249 this.exportMaterialsJSON = function()
250 {
251 var jObj;
252 if (this._materialArray && this._materialNodeArray && this.getWorld().isWebGL())
253 {
254 var nMats = this._materialArray.length;
255 if (nMats > 0)
256 {
257 var arr = [];
258
259 for (var i=0; i<nMats; i++)
260 {
261 var matObj =
262 {
263 'materialNodeName' : this._materialNodeArray[i].name,
264 'material' : this._materialArray[i].exportJSON(),
265 'type' : this._materialTypeArray[i]
266 }
267 arr.push( matObj );
268 }
269
270 jObj =
271 {
272 'nMaterials' : nMats,
273 'materials' : arr
274 };
275 }
276 }
277
278 return jObj;
279 }
280
281 this.importMaterialsJSON = function( jObj )
282 {
283 this._materialArray = [];
284 this._materialTypeArray = [];
285
286 if (!jObj) return;
287
288 var nMaterials = jObj.nMaterials;
289 var matArray = jObj.materials;
290 for (var i=0; i<nMaterials; i++)
291 {
292 var mat;
293 var matObj = matArray[i].material;
294 var shaderName = matObj.material;
295 switch (shaderName)
296 {
297 case "flat":
298 case "radialGradient":
299 case "linearGradient":
300 case "bumpMetal":
301 case "uber":
302 case "plasma":
303 case "deform":
304 case "water":
305 case "paris":
306 case "raiders":
307 case "tunnel":
308 case "reliefTunnel":
309 case "squareTunnel":
310 case "twist":
311 case "fly":
312 case "julia":
313 case "mandel":
314 case "star":
315 case "zinvert":
316 case "keleidoscope":
317 case "radialBlur":
318 case "pulse":
319 mat = MaterialsModel.getMaterialByShader( shaderName );
320 if (mat) mat = mat.dup();
321 break;
322
323 default:
324 console.log( "material type: " + shaderName + " is not supported" );
325 break;
326 }
327
328 if (mat)
329 {
330 mat.importJSON( matObj );
331 this._materialArray.push( mat );
332 this._materialTypeArray.push( matObj.type );
333 var type = matArray[i].type;
334 if (type == "fill") this._fillMaterial = mat;
335 else this._strokeMaterial = mat;
336 }
337 }
338 }
339
268 this.exportMaterials = function() 340 this.exportMaterials = function()
269 { 341 {
270 var rtnStr = ""; 342 var rtnStr = "";
@@ -296,26 +368,31 @@ var GeomObj = function GLGeomObj() {
296 var materialType = this.getPropertyFromString( "material: ", importStr ); 368 var materialType = this.getPropertyFromString( "material: ", importStr );
297 switch (materialType) 369 switch (materialType)
298 { 370 {
299 case "flat": mat = new FlatMaterial(); break; 371 case "flat":
300 case "radialGradient": mat = new RadialGradientMaterial(); break; 372 case "radialGradient":
301 case "linearGradient": mat = new LinearGradientMaterial(); break; 373 case "linearGradient":
302 case "bumpMetal": mat = new BumpMetalMaterial(); break; 374 case "bumpMetal":
303 case "uber": mat = new UberMaterial(); break; 375 case "uber":
304 case "plasma": mat = new PlasmaMaterial(); break; 376 case "plasma":
305 case "deform": mat = new DeformMaterial(); break; 377 case "deform":
306 case "water": mat = new WaterMaterial(); break; 378 case "water":
307 case "tunnel": mat = new TunnelMaterial(); break; 379 case "paris":
308 case "reliefTunnel": mat = new ReliefTunnelMaterial(); break; 380 case "raiders":
309 case "squareTunnel": mat = new SquareTunnelMaterial(); break; 381 case "tunnel":
310 case "twist": mat = new TwiseMaterial(); break; 382 case "reliefTunnel":
311 case "fly": mat = new FlyMaterial(); break; 383 case "squareTunnel":
312 case "julia": mat = new JuliaMaterial(); break; 384 case "twist":
313 case "mandel": mat = new MandelMaterial(); break; 385 case "fly":
314 case "star": mat = new StarMaterial(); break; 386 case "julia":
315 case "zinvert": mat = new ZInvertMaterial(); break; 387 case "mandel":
316 case "keleidoscope": mat = new KeleidoscopeMaterial(); break; 388 case "star":
317 case "radialBlur": mat = new RadialBlurMaterial(); break; 389 case "zinvert":
318 case "pulse": mat = new PulseMaterial(); break; 390 case "keleidoscope":
391 case "radialBlur":
392 case "pulse":
393 mat = MaterialsModel.getMaterialByShader( materialType );
394 if (mat) mat = mat.dup();
395 break;
319 396
320 default: 397 default:
321 console.log( "material type: " + materialType + " is not supported" ); 398 console.log( "material type: " + materialType + " is not supported" );