diff options
Diffstat (limited to 'js/lib/geom')
-rwxr-xr-x | js/lib/geom/circle.js | 72 | ||||
-rwxr-xr-x | js/lib/geom/geom-obj.js | 79 | ||||
-rwxr-xr-x | js/lib/geom/line.js | 53 | ||||
-rwxr-xr-x | js/lib/geom/rectangle.js | 87 |
4 files changed, 269 insertions, 22 deletions
diff --git a/js/lib/geom/circle.js b/js/lib/geom/circle.js index 4b155b4c..fec62308 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,65 @@ 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 | var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ); | ||
639 | if (!strokeMat) { | ||
640 | console.log( "object material not found in library: " + strokeMaterialName ); | ||
641 | strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); | ||
642 | } | ||
643 | else | ||
644 | strokeMat = strokeMat.dup(); | ||
645 | this._strokeMaterial = strokeMat; | ||
646 | |||
647 | var fillMat = MaterialsModel.getMaterial( fillMaterialName ); | ||
648 | if (!fillMat) { | ||
649 | console.log( "object material not found in library: " + fillMaterialName ); | ||
650 | fillMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); | ||
651 | } | ||
652 | else | ||
653 | fillMat = fillMat.dup(); | ||
654 | this._fillMaterial = fillMat; | ||
655 | }; | ||
656 | |||
657 | |||
658 | this.export = function() | ||
659 | { | ||
602 | var rtnStr = "type: " + this.geomType() + "\n"; | 660 | var rtnStr = "type: " + this.geomType() + "\n"; |
603 | 661 | ||
604 | rtnStr += "xoff: " + this._xOffset + "\n"; | 662 | rtnStr += "xoff: " + this._xOffset + "\n"; |
@@ -627,7 +685,7 @@ var Circle = function GLCircle() { | |||
627 | if (this._strokeMaterial) { | 685 | if (this._strokeMaterial) { |
628 | rtnStr += this._strokeMaterial.getName(); | 686 | rtnStr += this._strokeMaterial.getName(); |
629 | } else { | 687 | } else { |
630 | rtnStr += "flatMaterial"; | 688 | rtnStr += MaterialsModel.getDefaultMaterialName(); |
631 | } | 689 | } |
632 | 690 | ||
633 | rtnStr += "\n"; | 691 | rtnStr += "\n"; |
@@ -636,7 +694,7 @@ var Circle = function GLCircle() { | |||
636 | if (this._fillMaterial) { | 694 | if (this._fillMaterial) { |
637 | rtnStr += this._fillMaterial.getName(); | 695 | rtnStr += this._fillMaterial.getName(); |
638 | } else { | 696 | } else { |
639 | rtnStr += "flatMaterial"; | 697 | rtnStr += MaterialsModel.getDefaultMaterialName(); |
640 | } | 698 | } |
641 | rtnStr += "\n"; | 699 | rtnStr += "\n"; |
642 | 700 | ||
@@ -675,7 +733,7 @@ var Circle = function GLCircle() { | |||
675 | var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ); | 733 | var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ); |
676 | if (!strokeMat) { | 734 | if (!strokeMat) { |
677 | console.log( "object material not found in library: " + strokeMaterialName ); | 735 | console.log( "object material not found in library: " + strokeMaterialName ); |
678 | strokeMat = MaterialsModel.exportFlatMaterial(); | 736 | strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); |
679 | } | 737 | } |
680 | 738 | ||
681 | this._strokeMaterial = strokeMat; | 739 | this._strokeMaterial = strokeMat; |
@@ -683,7 +741,7 @@ var Circle = function GLCircle() { | |||
683 | var fillMat = MaterialsModel.getMaterial( fillMaterialName ); | 741 | var fillMat = MaterialsModel.getMaterial( fillMaterialName ); |
684 | if (!fillMat) { | 742 | if (!fillMat) { |
685 | console.log( "object material not found in library: " + fillMaterialName ); | 743 | console.log( "object material not found in library: " + fillMaterialName ); |
686 | fillMat = MaterialsModel.exportFlatMaterial(); | 744 | fillMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); |
687 | } | 745 | } |
688 | this._fillMaterial = fillMat; | 746 | this._fillMaterial = fillMat; |
689 | 747 | ||
diff --git a/js/lib/geom/geom-obj.js b/js/lib/geom/geom-obj.js index a64980e0..a4813326 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 | ||
7 | var MaterialsModel = require("js/models/materials-model").MaterialsModel; | 7 | var MaterialsModel = require("js/models/materials-model").MaterialsModel; |
8 | /* | ||
8 | var FlatMaterial = require("js/lib/rdge/materials/flat-material").FlatMaterial; | 9 | var FlatMaterial = require("js/lib/rdge/materials/flat-material").FlatMaterial; |
9 | var LinearGradientMaterial = require("js/lib/rdge/materials/linear-gradient-material").LinearGradientMaterial; | 10 | var LinearGradientMaterial = require("js/lib/rdge/materials/linear-gradient-material").LinearGradientMaterial; |
10 | var RadialGradientMaterial = require("js/lib/rdge/materials/radial-gradient-material").RadialGradientMaterial; | 11 | var RadialGradientMaterial = require("js/lib/rdge/materials/radial-gradient-material").RadialGradientMaterial; |
@@ -25,6 +26,7 @@ var TwistMaterial = require("js/lib/rdge/materials/twist-material").TwistMateria | |||
25 | var JuliaMaterial = require("js/lib/rdge/materials/julia-material").JuliaMaterial; | 26 | var JuliaMaterial = require("js/lib/rdge/materials/julia-material").JuliaMaterial; |
26 | var KeleidoscopeMaterial = require("js/lib/rdge/materials/keleidoscope-material").KeleidoscopeMaterial; | 27 | var KeleidoscopeMaterial = require("js/lib/rdge/materials/keleidoscope-material").KeleidoscopeMaterial; |
27 | var MandelMaterial = require("js/lib/rdge/materials/mandel-material").MandelMaterial; | 28 | var MandelMaterial = require("js/lib/rdge/materials/mandel-material").MandelMaterial; |
29 | */ | ||
28 | 30 | ||
29 | /////////////////////////////////////////////////////////////////////// | 31 | /////////////////////////////////////////////////////////////////////// |
30 | // Class GLGeomObj | 32 | // Class GLGeomObj |
@@ -265,6 +267,83 @@ var GeomObj = function GLGeomObj() { | |||
265 | return fillMaterial; | 267 | return fillMaterial; |
266 | }; | 268 | }; |
267 | 269 | ||
270 | this.exportMaterialsJSON = function() | ||
271 | { | ||
272 | var jObj; | ||
273 | if (this._materialArray && this._materialNodeArray) | ||
274 | { | ||
275 | var nMats = this._materialArray.length; | ||
276 | if (nMats > 0) | ||
277 | { | ||
278 | var arr = []; | ||
279 | |||
280 | for (var i=0; i<nMats; i++) | ||
281 | { | ||
282 | var matObj = | ||
283 | { | ||
284 | 'materialNodeName' : this._materialNodeArray[i].name, | ||
285 | 'material' : this._materialArray[i].exportJSON(), | ||
286 | 'type' : this._materialTypeArray[i] | ||
287 | } | ||
288 | arr.push( matObj ); | ||
289 | } | ||
290 | |||
291 | jObj = | ||
292 | { | ||
293 | 'nMaterials' : nMats, | ||
294 | 'materials' : arr | ||
295 | }; | ||
296 | } | ||
297 | } | ||
298 | |||
299 | return jObj; | ||
300 | } | ||
301 | |||
302 | this.importMaterialsJSON = function( jObj ) | ||
303 | { | ||
304 | var nMaterials = jObj.nMaterials; | ||
305 | var matArray = jObj.materials; | ||
306 | for (var i=0; i<nMaterials; i++) | ||
307 | { | ||
308 | var mat; | ||
309 | var matObj = matArray[i].material; | ||
310 | var shaderName = matObj.material; | ||
311 | switch (shaderName) | ||
312 | { | ||
313 | case "flat": | ||
314 | case "radialGradient": | ||
315 | case "linearGradient": | ||
316 | case "bumpMetal": | ||
317 | case "uber": | ||
318 | case "plasma": | ||
319 | case "deform": | ||
320 | case "water": | ||
321 | case "tunnel": | ||
322 | case "reliefTunnel": | ||
323 | case "squareTunnel": | ||
324 | case "twist": | ||
325 | case "fly": | ||
326 | case "julia": | ||
327 | case "mandel": | ||
328 | case "star": | ||
329 | case "zinvert": | ||
330 | case "keleidoscope": | ||
331 | case "radialBlur": | ||