aboutsummaryrefslogtreecommitdiff
path: root/js/lib/geom
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/geom')
-rwxr-xr-xjs/lib/geom/circle.js54
-rwxr-xr-xjs/lib/geom/geom-obj.js154
-rwxr-xr-xjs/lib/geom/line.js44
-rwxr-xr-xjs/lib/geom/rectangle.js67
4 files changed, 258 insertions, 61 deletions
diff --git a/js/lib/geom/circle.js b/js/lib/geom/circle.js
index 4b155b4c..d48bf98b 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();
@@ -598,7 +598,47 @@ var Circle = function GLCircle() {
598 } 598 }
599 }; 599 };
600 600
601 this.export = function() { 601 this.exportJSON = function()
602 {
603 var jObj =
604 {
605 'type' : this.geomType(),
606 'xoff' : this._xOffset,
607 'yoff' : this._yOffset,
608 'width' : this._width,
609 'height' : this._height,
610 'strokeWidth' : this._strokeWidth,
611 'strokeColor' : this._strokeColor,
612 'fillColor' : this._fillColor,
613 'innerRadius' : this._innerRadius,
614 'strokeStyle' : this._strokeStyle,
615 'strokeMat' : this._strokeMaterial ? this._strokeMaterial.getName() : MaterialsModel.getDefaultMaterialName(),
616 'fillMat' : this._fillMaterial ? this._fillMaterial.getName() : MaterialsModel.getDefaultMaterialName(),
617 'materials' : this.exportMaterialsJSON()
618 };
619
620 return jObj;
621 };
622
623 this.importJSON = function( jObj )
624 {
625 this._xOffset = jObj.xoff;
626 this._yOffset = jObj.yoff;
627 this._width = jObj.width;
628 this._height = jObj.height;
629 this._strokeWidth = jObj.strokeWidth;
630 this._strokeColor = jObj.strokeColor;
631 this._fillColor = jObj.fillColor;
632 this._innerRadius = jObj.innerRadius;
633 this._strokeStyle = jObj.strokeStyle;
634 var strokeMaterialName = jObj.strokeMat;
635 var fillMaterialName = jObj.fillMat;
636 this.importMaterialsJSON( jObj.materials );
637 };
638
639
640 this.export = function()
641 {
602 var rtnStr = "type: " + this.geomType() + "\n"; 642 var rtnStr = "type: " + this.geomType() + "\n";
603 643
604 rtnStr += "xoff: " + this._xOffset + "\n"; 644 rtnStr += "xoff: " + this._xOffset + "\n";
@@ -627,7 +667,7 @@ var Circle = function GLCircle() {
627 if (this._strokeMaterial) { 667 if (this._strokeMaterial) {
628 rtnStr += this._strokeMaterial.getName(); 668 rtnStr += this._strokeMaterial.getName();
629 } else { 669 } else {
630 rtnStr += "flatMaterial"; 670 rtnStr += MaterialsModel.getDefaultMaterialName();
631 } 671 }
632 672
633 rtnStr += "\n"; 673 rtnStr += "\n";
@@ -636,7 +676,7 @@ var Circle = function GLCircle() {
636 if (this._fillMaterial) { 676 if (this._fillMaterial) {
637 rtnStr += this._fillMaterial.getName(); 677 rtnStr += this._fillMaterial.getName();
638 } else { 678 } else {
639 rtnStr += "flatMaterial"; 679 rtnStr += MaterialsModel.getDefaultMaterialName();
640 } 680 }
641 rtnStr += "\n"; 681 rtnStr += "\n";
642 682
@@ -675,7 +715,7 @@ var Circle = function GLCircle() {
675 var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ); 715 var strokeMat = MaterialsModel.getMaterial( strokeMaterialName );
676 if (!strokeMat) { 716 if (!strokeMat) {
677 console.log( "object material not found in library: " + strokeMaterialName ); 717 console.log( "object material not found in library: " + strokeMaterialName );
678 strokeMat = MaterialsModel.exportFlatMaterial(); 718 strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() );
679 } 719 }
680 720
681 this._strokeMaterial = strokeMat; 721 this._strokeMaterial = strokeMat;
@@ -683,7 +723,7 @@ var Circle = function GLCircle() {
683 var fillMat = MaterialsModel.getMaterial( fillMaterialName ); 723 var fillMat = MaterialsModel.getMaterial( fillMaterialName );
684 if (!fillMat) { 724 if (!fillMat) {
685 console.log( "object material not found in library: " + fillMaterialName ); 725 console.log( "object material not found in library: " + fillMaterialName );
686 fillMat = MaterialsModel.exportFlatMaterial(); 726 fillMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() );
687 } 727 }
688 this._fillMaterial = fillMat; 728 this._fillMaterial = fillMat;
689 729
diff --git a/js/lib/geom/geom-obj.js b/js/lib/geom/geom-obj.js
index a64980e0..a87bdbf5 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 && 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 "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: