aboutsummaryrefslogtreecommitdiff
path: root/js/lib/geom
diff options
context:
space:
mode:
authorhwc4872012-03-16 12:26:30 -0700
committerhwc4872012-03-16 12:26:30 -0700
commita0d23354802ebc6b437698acb4b18d3395d47cd1 (patch)
treea0081c079c9fc557e10a828db9adeed5a91d5a72 /js/lib/geom
parent57d4a82977a1f0e809511fe894886f88581d9615 (diff)
downloadninja-a0d23354802ebc6b437698acb4b18d3395d47cd1.tar.gz
Conversion to JSON based file IO for canvas2D and WebGL rendering
Diffstat (limited to 'js/lib/geom')
-rwxr-xr-xjs/lib/geom/circle.js72
-rwxr-xr-xjs/lib/geom/geom-obj.js79
-rwxr-xr-xjs/lib/geom/line.js53
-rwxr-xr-xjs/lib/geom/rectangle.js87
4 files changed, 269 insertions, 22 deletions
diff --git a/js/lib/geom/circle.js b/js/lib/geom/circle.js
index f94d4e6b..7d1a3452 100755
--- a/js/lib/geom/circle.js
+++ b/js/lib/geom/circle.js
@@ -53,13 +53,13 @@ var Circle = function GLCircle() {
53 if(strokeMaterial){ 53 if(strokeMaterial){
54 this._strokeMaterial = strokeMaterial; 54 this._strokeMaterial = strokeMaterial;
55 } else { 55 } else {
56 this._strokeMaterial = MaterialsModel.exportFlatMaterial(); 56 this._strokeMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() );
57 } 57 }
58 58
59 if(fillMaterial) { 59 if(fillMaterial) {
60 this._fillMaterial = fillMaterial; 60 this._fillMaterial = fillMaterial;
61 } else { 61 } else {
62 this._fillMaterial = MaterialsModel.exportFlatMaterial(); 62 this._fillMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() );
63 } 63 }
64 64
65 this.exportMaterials(); 65 this.exportMaterials();
@@ -551,7 +551,65 @@ var Circle = function GLCircle() {
551 } 551 }
552 }; 552 };
553 553
554 this.export = function() { 554 this.exportJSON = function()
555 {
556 var jObj =
557 {
558 'type' : this.geomType(),
559 'xoff' : this._xOffset,
560 'yoff' : this._yOffset,
561 'width' : this._width,
562 'height' : this._height,
563 'strokeWidth' : this._strokeWidth,
564 'strokeColor' : this._strokeColor,
565 'fillColor' : this._fillColor,
566 'innerRadius' : this._innerRadius,
567 'strokeStyle' : this._strokeStyle,
568 'strokeMat' : this._strokeMaterial ? this._strokeMaterial.getName() : MaterialsModel.getDefaultMaterialName(),
569 'fillMat' : this._fillMaterial ? this._fillMaterial.getName() : MaterialsModel.getDefaultMaterialName(),
570 'materials' : this.exportMaterialsJSON()
571 };
572
573 return jObj;
574 };
575
576 this.importJSON = function( jObj )
577 {
578 this._xOffset = jObj.xoff;
579 this._yOffset = jObj.yoff;
580 this._width = jObj.width;
581 this._height = jObj.height;
582 this._strokeWidth = jObj.strokeWidth;
583 this._strokeColor = jObj.strokeColor;
584 this._fillColor = jObj.fillColor;
585 this._innerRadius = jObj.innerRadius;
586 this._strokeStyle = jObj.strokeStyle;
587 var strokeMaterialName = jObj.strokeMat;
588 var fillMaterialName = jObj.fillMat;
589 this.importMaterialsJSON( jObj.materials );
590
591 var strokeMat = MaterialsModel.getMaterial( strokeMaterialName );
592 if (!strokeMat) {
593 console.log( "object material not found in library: " + strokeMaterialName );
594 strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() );
595 }
596 else
597 strokeMat = strokeMat.dup();
598 this._strokeMaterial = strokeMat;
599
600 var fillMat = MaterialsModel.getMaterial( fillMaterialName );
601 if (!fillMat) {
602 console.log( "object material not found in library: " + fillMaterialName );
603 fillMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() );
604 }
605 else
606 fillMat = fillMat.dup();
607 this._fillMaterial = fillMat;
608 };
609
610
611 this.export = function()
612 {
555 var rtnStr = "type: " + this.geomType() + "\n"; 613 var rtnStr = "type: " + this.geomType() + "\n";
556 614
557 rtnStr += "xoff: " + this._xOffset + "\n"; 615 rtnStr += "xoff: " + this._xOffset + "\n";
@@ -568,7 +626,7 @@ var Circle = function GLCircle() {
568 if (this._strokeMaterial) { 626 if (this._strokeMaterial) {
569 rtnStr += this._strokeMaterial.getName(); 627 rtnStr += this._strokeMaterial.getName();
570 } else { 628 } else {
571 rtnStr += "flatMaterial"; 629 rtnStr += MaterialsModel.getDefaultMaterialName();
572 } 630 }
573 631
574 rtnStr += "\n"; 632 rtnStr += "\n";
@@ -577,7 +635,7 @@ var Circle = function GLCircle() {
577 if (this._fillMaterial) { 635 if (this._fillMaterial) {
578 rtnStr += this._fillMaterial.getName(); 636 rtnStr += this._fillMaterial.getName();
579 } else { 637 } else {
580 rtnStr += "flatMaterial"; 638 rtnStr += MaterialsModel.getDefaultMaterialName();
581 } 639 }
582 rtnStr += "\n"; 640 rtnStr += "\n";
583 641
@@ -602,7 +660,7 @@ var Circle = function GLCircle() {
602 var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ); 660 var strokeMat = MaterialsModel.getMaterial( strokeMaterialName );
603 if (!strokeMat) { 661 if (!strokeMat) {
604 console.log( "object material not found in library: " + strokeMaterialName ); 662 console.log( "object material not found in library: " + strokeMaterialName );
605 strokeMat = MaterialsModel.exportFlatMaterial(); 663 strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() );
606 } 664 }
607 665
608 this._strokeMaterial = strokeMat; 666 this._strokeMaterial = strokeMat;
@@ -610,7 +668,7 @@ var Circle = function GLCircle() {
610 var fillMat = MaterialsModel.getMaterial( fillMaterialName ); 668 var fillMat = MaterialsModel.getMaterial( fillMaterialName );
611 if (!fillMat) { 669 if (!fillMat) {
612 console.log( "object material not found in library: " + fillMaterialName ); 670 console.log( "object material not found in library: " + fillMaterialName );
613 fillMat = MaterialsModel.exportFlatMaterial(); 671 fillMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() );
614 } 672 }
615 this._fillMaterial = fillMat; 673 this._fillMaterial = fillMat;
616 674
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
7var MaterialsModel = require("js/models/materials-model").MaterialsModel; 7var MaterialsModel = require("js/models/materials-model").MaterialsModel;
8/*
8var FlatMaterial = require("js/lib/rdge/materials/flat-material").FlatMaterial; 9var FlatMaterial = require("js/lib/rdge/materials/flat-material").FlatMaterial;
9var LinearGradientMaterial = require("js/lib/rdge/materials/linear-gradient-material").LinearGradientMaterial; 10var LinearGradientMaterial = require("js/lib/rdge/materials/linear-gradient-material").LinearGradientMaterial;
10var RadialGradientMaterial = require("js/lib/rdge/materials/radial-gradient-material").RadialGradientMaterial; 11var RadialGradientMaterial = require("js/lib/rdge/materials/radial-gradient-material").RadialGradientMaterial;
@@ -25,6 +26,7 @@ var TwistMaterial = require("js/lib/rdge/materials/twist-material").TwistMateria
25var JuliaMaterial = require("js/lib/rdge/materials/julia-material").JuliaMaterial; 26var JuliaMaterial = require("js/lib/rdge/materials/julia-material").JuliaMaterial;
26var KeleidoscopeMaterial = require("js/lib/rdge/materials/keleidoscope-material").KeleidoscopeMaterial; 27var KeleidoscopeMaterial = require("js/lib/rdge/materials/keleidoscope-material").KeleidoscopeMaterial;
27var MandelMaterial = require("js/lib/rdge/materials/mandel-material").MandelMaterial; 28var 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