diff options
Diffstat (limited to 'js/helper-classes')
42 files changed, 675 insertions, 549 deletions
diff --git a/js/helper-classes/3D/draw-utils.js b/js/helper-classes/3D/draw-utils.js index 63e7799a..1c00f7ea 100755 --- a/js/helper-classes/3D/draw-utils.js +++ b/js/helper-classes/3D/draw-utils.js | |||
@@ -139,8 +139,8 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { | |||
139 | handleCloseDocument:{ | 139 | handleCloseDocument:{ |
140 | value: function() { | 140 | value: function() { |
141 | if(this.application.ninja.documentController._documents.length === 0){ | 141 | if(this.application.ninja.documentController._documents.length === 0){ |
142 | this._eltArray = []; | 142 | this._eltArray = null; |
143 | this._planesArray = []; | 143 | this._planesArray = null; |
144 | } | 144 | } |
145 | } | 145 | } |
146 | }, | 146 | }, |
@@ -721,8 +721,17 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { | |||
721 | drawSelectionBounds : { | 721 | drawSelectionBounds : { |
722 | value: function( eltArray ) { | 722 | value: function( eltArray ) { |
723 | this._selectionCtr = null; | 723 | this._selectionCtr = null; |
724 | var len = eltArray.length, | ||
725 | i, | ||
726 | j, | ||
727 | bounds, | ||
728 | bounds3D, | ||
729 | pt, | ||
730 | tmpPt, | ||
731 | ssMat, | ||
732 | elt; | ||
724 | 733 | ||
725 | if (eltArray.length == 0) return; | 734 | if (len === 0) return; |
726 | var context = this._drawingContext; | 735 | var context = this._drawingContext; |
727 | if (!context) return; | 736 | if (!context) return; |
728 | 737 | ||
@@ -731,18 +740,19 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { | |||
731 | context.lineWidth = 2; | 740 | context.lineWidth = 2; |
732 | 741 | ||
733 | // handle the single element case | 742 | // handle the single element case |
734 | if (eltArray.length == 1) | 743 | // TODO - Currently, the stage draws its own selection bounds for single selection case |
744 | if (len === 1) | ||
735 | { | 745 | { |
736 | // single selection case | 746 | // single selection case |
737 | //console.log( "single selection" ); | 747 | //console.log( "single selection" ); |
738 | 748 | ||
739 | var elt = eltArray[0]; | 749 | elt = eltArray[0]; |
740 | 750 | ||
741 | this.viewUtils.pushViewportObj( elt ); | 751 | this.viewUtils.pushViewportObj( elt ); |
742 | 752 | ||
743 | // get the element bounds in world space | 753 | // get the element bounds in world space |
744 | var bounds3D = this.viewUtils.getElementViewBounds3D( elt ); | 754 | bounds3D = this.viewUtils.getElementViewBounds3D( elt ); |
745 | for (var j=0; j<4; j++) { | 755 | for (j=0; j<4; j++) { |
746 | bounds3D[j] = this.viewUtils.localToGlobal( bounds3D[j], elt ); | 756 | bounds3D[j] = this.viewUtils.localToGlobal( bounds3D[j], elt ); |
747 | } | 757 | } |
748 | 758 | ||
@@ -766,19 +776,12 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { | |||
766 | } | 776 | } |
767 | else | 777 | else |
768 | { | 778 | { |
769 | // the multiple selection case. | ||
770 | //console.log( "multiple selection" ); | ||
771 | |||
772 | // we set the root to "the world". | ||
773 | var saveRoot = this.viewUtils.getRootElement(); | ||
774 | this.viewUtils.setRootElement( this.viewUtils.getStageElement() ); | ||
775 | |||
776 | // get the plane from the first element to compare against the other elements | 779 | // get the plane from the first element to compare against the other elements |
777 | var flat = true; | 780 | var flat = true; |
778 | var plane = this.viewUtils.getElementPlane( eltArray[0] ); | 781 | var plane = this.viewUtils.getElementPlane( eltArray[0] ); |
779 | for (var i=1; i<eltArray.length; i++) | 782 | for (i=1; i<len; i++) |
780 | { | 783 | { |
781 | var elt = eltArray[i]; | 784 | elt = eltArray[i]; |
782 | var plane2 = this.viewUtils.getElementPlane( elt ); | 785 | var plane2 = this.viewUtils.getElementPlane( elt ); |
783 | var dot = MathUtils.dot3(plane,plane2); | 786 | var dot = MathUtils.dot3(plane,plane2); |
784 | if (MathUtils.fpCmp(dot, 1) != 0) | 787 | if (MathUtils.fpCmp(dot, 1) != 0) |
@@ -796,34 +799,23 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { | |||
796 | } | 799 | } |
797 | } | 800 | } |
798 | 801 | ||
799 | // construct a matrix from world space to 'plane' space | ||
800 | var ptOnPlane = this.viewUtils.localToGlobal( [0,0,0], eltArray[0]); | ||
801 | var planeToWorld = this.getPlaneToWorldMatrix( plane, ptOnPlane ); | ||
802 | //var worldToPlane = planeToWorld.inverse(); | ||
803 | var worldToPlane = glmat4.inverse(planeToWorld, []); | ||
804 | |||
805 | var ssMat = this.viewUtils.getLocalToGlobalMatrix( this._sourceSpaceElt ); | ||
806 | // if all the elements share the same plane, draw the 2D rectangle | 802 | // if all the elements share the same plane, draw the 2D rectangle |
807 | if (flat) | 803 | if (flat) |
808 | { | 804 | { |
809 | // make a 2D rectangle on the plane | 805 | // make a 2D rectangle on the plane |
810 | var rect; | 806 | var rect; |
811 | for (var i=0; i<eltArray.length; i++) | 807 | for (i=0; i<len; i++) |
812 | { | 808 | { |
813 | var elt = eltArray[i]; | 809 | elt = eltArray[i]; |
814 | 810 | ||
815 | // get the element bounds in 'plane' space | 811 | // get the element bounds in 'plane' space |
816 | var bounds = this.viewUtils.getElementViewBounds3D( elt ); | 812 | bounds = this.viewUtils.getElementViewBounds3D( elt ); |
817 | for (var j=0; j<4; j++) | 813 | ssMat = this.viewUtils.getLocalToGlobalMatrix( elt ); |
814 | for (j=0; j<4; j++) | ||
818 | { | 815 | { |
819 | // var gPt = MathUtils.makeDimension4( this.viewUtils.localToGlobal( bounds[j], elt ) ); | ||
820 | // //var pt = worldToPlane.multiply( gPt ); | ||
821 | // var pt = glmat4.multiplyVec3( worldToPlane, gPt, [] ); | ||
822 | // var tmpPt = glmat4.multiplyVec3( planeToWorld, pt, [] ); | ||
823 | |||
824 | var localPt = bounds[j]; | 816 | var localPt = bounds[j]; |
825 | var tmpPt = this.viewUtils.localToGlobal2(localPt, ssMat); | 817 | tmpPt = this.viewUtils.localToGlobal2(localPt, ssMat); |
826 | var pt = glmat4.multiplyVec3( worldToPlane, tmpPt, [] ); | 818 | pt = tmpPt; |
827 |