diff options
Diffstat (limited to 'js/lib/geom')
-rwxr-xr-x | js/lib/geom/brush-stroke.js | 12 | ||||
-rwxr-xr-x | js/lib/geom/circle.js | 94 | ||||
-rwxr-xr-x | js/lib/geom/geom-obj.js | 442 | ||||
-rwxr-xr-x | js/lib/geom/line.js | 70 | ||||
-rwxr-xr-x | js/lib/geom/rectangle.js | 110 |
5 files changed, 181 insertions, 547 deletions
diff --git a/js/lib/geom/brush-stroke.js b/js/lib/geom/brush-stroke.js index 22209815..26ac42e9 100755 --- a/js/lib/geom/brush-stroke.js +++ b/js/lib/geom/brush-stroke.js | |||
@@ -711,18 +711,6 @@ var BrushStroke = function GLBrushStroke() { | |||
711 | this.update(); //after this, the stroke is ready to be rendered | 711 | this.update(); //after this, the stroke is ready to be rendered |
712 | }; | 712 | }; |
713 | 713 | ||
714 | |||
715 | this.export = function() { | ||
716 | var jsonObject = this.exportJSON(); | ||
717 | var stringified = JSON.stringify(jsonObject); | ||
718 | return "type: " + this.geomType() + "\n" + stringified; | ||
719 | }; | ||
720 | |||
721 | this.import = function( importStr ) { | ||
722 | var jsonObject = JSON.parse(importStr); | ||
723 | this.importJSON(jsonObject); | ||
724 | } | ||
725 | |||
726 | this.collidesWithPoint = function (x, y, z) { | 714 | this.collidesWithPoint = function (x, y, z) { |
727 | if (x < this._BBoxMin[0]) return false; | 715 | if (x < this._BBoxMin[0]) return false; |
728 | if (x > this._BBoxMax[0]) return false; | 716 | if (x > this._BBoxMax[0]) return false; |
diff --git a/js/lib/geom/circle.js b/js/lib/geom/circle.js index e8c94b64..4bf37474 100755 --- a/js/lib/geom/circle.js +++ b/js/lib/geom/circle.js | |||
@@ -636,100 +636,6 @@ var Circle = function GLCircle() { | |||
636 | this.importMaterialsJSON( jObj.materials ); | 636 | this.importMaterialsJSON( jObj.materials ); |
637 | }; | 637 | }; |
638 | 638 | ||
639 | |||
640 | this.export = function() | ||
641 | { | ||
642 | var rtnStr = "type: " + this.geomType() + "\n"; | ||
643 | |||
644 | rtnStr += "xoff: " + this._xOffset + "\n"; | ||
645 | rtnStr += "yoff: " + this._yOffset + "\n"; | ||
646 | rtnStr += "width: " + this._width + "\n"; | ||
647 | rtnStr += "height: " + this._height + "\n"; | ||
648 | rtnStr += "strokeWidth: " + this._strokeWidth + "\n"; | ||
649 | rtnStr += "innerRadius: " + this._innerRadius + "\n"; | ||
650 | rtnStr += "strokeStyle: " + this._strokeStyle + "\n"; | ||
651 | |||
652 | if(this._strokeColor.gradientMode) { | ||
653 | rtnStr += "strokeGradientMode: " + this._strokeColor.gradientMode + "\n"; | ||
654 | rtnStr += "strokeColor: " + this.gradientToString(this._strokeColor.color) + "\n"; | ||
655 | } else { | ||
656 | rtnStr += "strokeColor: " + String(this._strokeColor) + "\n"; | ||
657 | } | ||
658 | |||
659 | if(this._fillColor.gradientMode) { | ||
660 | rtnStr += "fillGradientMode: " + this._fillColor.gradientMode + "\n"; | ||
661 | rtnStr += "fillColor: " + this.gradientToString(this._fillColor.color) + "\n"; | ||
662 | } else { | ||
663 | rtnStr += "fillColor: " + String(this._fillColor) + "\n"; | ||
664 | } | ||
665 | |||
666 | rtnStr += "strokeMat: "; | ||
667 | if (this._strokeMaterial) { | ||
668 | rtnStr += this._strokeMaterial.getName(); | ||
669 | } else { | ||
670 | rtnStr += MaterialsModel.getDefaultMaterialName(); | ||
671 | } | ||
672 | |||
673 | rtnStr += "\n"; | ||
674 | |||
675 | rtnStr += "fillMat: "; | ||
676 | if (this._fillMaterial) { | ||
677 | rtnStr += this._fillMaterial.getName(); | ||
678 | } else { | ||
679 | rtnStr += MaterialsModel.getDefaultMaterialName(); | ||
680 | } | ||
681 | rtnStr += "\n"; | ||
682 | |||
683 | rtnStr += this.exportMaterials(); | ||
684 | |||
685 | return rtnStr; | ||
686 | }; | ||
687 | |||
688 | this.import = function( importStr ) { | ||
689 | this._xOffset = Number( this.getPropertyFromString( "xoff: ", importStr ) ); | ||
690 | this._yOffset = Number( this.getPropertyFromString( "yoff: ", importStr ) ); | ||
691 | this._width = Number( this.getPropertyFromString( "width: ", importStr ) ); | ||
692 | this._height = Number( this.getPropertyFromString( "height: ", importStr ) ); | ||
693 | this._strokeWidth = Number( this.getPropertyFromString( "strokeWidth: ", importStr ) ); | ||
694 | this._innerRadius = Number( this.getPropertyFromString( "innerRadius: ", importStr ) ); | ||
695 | this._strokeStyle = this.getPropertyFromString( "strokeStyle: ", importStr ); | ||
696 | var strokeMaterialName = this.getPropertyFromString( "strokeMat: ", importStr ); | ||
697 | var fillMaterialName = this.getPropertyFromString( "fillMat: ", importStr ); | ||
698 | if(importStr.indexOf("fillGradientMode: ") < 0) { | ||
699 | this._fillColor = eval( "[" + this.getPropertyFromString( "fillColor: ", importStr ) + "]" ); | ||
700 | } else { | ||
701 | this._fillColor = {}; | ||
702 | this._fillColor.gradientMode = this.getPropertyFromString( "fillGradientMode: ", importStr ); | ||
703 | this._fillColor.color = this.stringToGradient(this.getPropertyFromString( "fillColor: ", importStr )); | ||
704 | } | ||
705 | |||
706 | if(importStr.indexOf("strokeGradientMode: ") < 0) | ||
707 | { | ||
708 | this._strokeColor = eval( "[" + this.getPropertyFromString( "strokeColor: ", importStr ) + "]" ); | ||
709 | } else { | ||
710 | this._strokeColor = {}; | ||
711 | this._strokeColor.gradientMode = this.getPropertyFromString( "strokeGradientMode: ", importStr ); | ||
712 | this._strokeColor.color = this.stringToGradient(this.getPropertyFromString( "strokeColor: ", importStr )); | ||
713 | } | ||
714 | |||
715 | var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ); | ||
716 | if (!strokeMat) { | ||
717 | console.log( "object material not found in library: " + strokeMaterialName ); | ||
718 | strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); | ||
719 | } | ||
720 | |||
721 | this._strokeMaterial = strokeMat; | ||
722 | |||
723 | var fillMat = MaterialsModel.getMaterial( fillMaterialName ); | ||
724 | if (!fillMat) { | ||
725 | console.log( "object material not found in library: " + fillMaterialName ); | ||
726 | fillMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); | ||
727 | } | ||
728 | this._fillMaterial = fillMat; | ||
729 | |||
730 | this.importMaterials( importStr ); | ||
731 | }; | ||
732 | |||
733 | this.collidesWithPoint = function( x, y ) { | 639 | this.collidesWithPoint = function( x, y ) { |
734 | // if(x < this._xOffset) return false; | 640 | // if(x < this._xOffset) return false; |
735 | // if(x > (this._xOffset + this._width)) return false; | 641 | // if(x > (this._xOffset + this._width)) return false; |
diff --git a/js/lib/geom/geom-obj.js b/js/lib/geom/geom-obj.js index f1aa9f8a..bb5b4a9a 100755 --- a/js/lib/geom/geom-obj.js +++ b/js/lib/geom/geom-obj.js | |||
@@ -14,19 +14,19 @@ var GeomObj = function GLGeomObj() { | |||
14 | /////////////////////////////////////////////////////////////////////// | 14 | /////////////////////////////////////////////////////////////////////// |
15 | // Constants | 15 | // Constants |
16 | /////////////////////////////////////////////////////////////////////// | 16 | /////////////////////////////////////////////////////////////////////// |
17 | this.GEOM_TYPE_RECTANGLE = 1; | 17 | this.GEOM_TYPE_RECTANGLE = 1; |
18 | this.GEOM_TYPE_CIRCLE = 2; | 18 | this.GEOM_TYPE_CIRCLE = 2; |
19 | this.GEOM_TYPE_LINE = 3; | 19 | this.GEOM_TYPE_LINE = 3; |
20 | this.GEOM_TYPE_PATH = 4; | 20 | this.GEOM_TYPE_PATH = 4; |
21 | this.GEOM_TYPE_CUBIC_BEZIER = 5; | 21 | this.GEOM_TYPE_CUBIC_BEZIER = 5; |
22 | this.GEOM_TYPE_BRUSH_STROKE = 6; | 22 | this.GEOM_TYPE_BRUSH_STROKE = 6; |
23 | this.GEOM_TYPE_UNDEFINED = -1; | 23 | this.GEOM_TYPE_UNDEFINED = -1; |
24 | 24 | ||
25 | // Needed for calculating dashed/dotted strokes | 25 | // Needed for calculating dashed/dotted strokes |
26 | this.DASH_LENGTH = 0.15; | 26 | this.DASH_LENGTH = 0.15; |
27 | this.DOT_LENGTH = 0.05; | 27 | this.DOT_LENGTH = 0.05; |
28 | this.GAP_LENGTH = 0.05; | 28 | this.GAP_LENGTH = 0.05; |
29 | 29 | ||
30 | /////////////////////////////////////////////////////////////////////// | 30 | /////////////////////////////////////////////////////////////////////// |
31 | // Instance variables | 31 | // Instance variables |
32 | /////////////////////////////////////////////////////////////////////// | 32 | /////////////////////////////////////////////////////////////////////// |
@@ -40,109 +40,111 @@ var GeomObj = function GLGeomObj() { | |||
40 | this.m_world = null; | 40 | this.m_world = null; |
41 | 41 | ||
42 | // stroke and fill colors | 42 | // stroke and fill colors |
43 | this._strokeColor = [0,0,0,0]; | 43 | this._strokeColor = [0, 0, 0, 0]; |
44 | this._fillColor = [0,0,0,0]; | 44 | this._fillColor = [0, 0, 0, 0]; |
45 | 45 | ||
46 | // stroke and fill materials | 46 | // stroke and fill materials |
47 | this._fillMaterial = null; | 47 | this._fillMaterial = null; |
48 | this._strokeMaterial = null; | 48 | this._strokeMaterial = null; |
49 | 49 | ||
50 | // array of primitives - used in RDGE | 50 | // array of primitives - used in RDGE |
51 | this._primArray = []; | 51 | this._primArray = []; |
52 | this._materialNodeArray = []; | 52 | this._materialNodeArray = []; |
53 | this._materialArray = []; | 53 | this._materialArray = []; |
54 | this._materialTypeArray = []; | 54 | this._materialTypeArray = []; |
55 | 55 | ||
56 | // the transform node used by RDGE | 56 | // the transform node used by RDGE |
57 | this._trNode = null; | 57 | this._trNode = null; |
58 | 58 | ||
59 | /////////////////////////////////////////////////////////////////////// | 59 | /////////////////////////////////////////////////////////////////////// |
60 | // Property accessors | 60 | // Property accessors |
61 | /////////////////////////////////////////////////////////////////////// | 61 | /////////////////////////////////////////////////////////////////////// |
62 | this.setWorld = function( world ) { | 62 | this.setWorld = function (world) { |
63 | this.m_world = world; | 63 | this.m_world = world; |
64 | }; | 64 | }; |
65 | 65 | ||
66 | this.getWorld = function() { | 66 | this.getWorld = function () { |
67 | return this.m_world; | 67 | return this.m_world; |
68 | }; | 68 | }; |
69 | 69 | ||
70 | this.getMatrix = function() { | 70 | this.getMatrix = function () { |
71 | return this._matrix.slice(0); | 71 | return this._matrix.slice(0); |
72 | }; | 72 | }; |
73 | 73 | ||
74 | this.setMatrix = function(m) { | 74 | this.setMatrix = function (m) { |
75 | this._matrix = m.slice(0); | 75 | this._matrix = m.slice(0); |
76 | }; | 76 | }; |
77 | 77 | ||
78 | this.setNext = function( next ) { | 78 | this.setNext = function (next) { |
79 | this._next = next; | 79 | this._next = next; |
80 | }; | 80 | }; |
81 | 81 | ||
82 | this.getNext = function() { | 82 | this.getNext = function () { |
83 | return this._next; | 83 | return this._next; |
84 | }; |