aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes
diff options
context:
space:
mode:
Diffstat (limited to 'js/helper-classes')
-rwxr-xr-xjs/helper-classes/3D/draw-utils.js136
1 files changed, 39 insertions, 97 deletions
diff --git a/js/helper-classes/3D/draw-utils.js b/js/helper-classes/3D/draw-utils.js
index 59da411f..1c00f7ea 100755
--- a/js/helper-classes/3D/draw-utils.js
+++ b/js/helper-classes/3D/draw-utils.js
@@ -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 819
828 if (!rect) 820 if (!rect)
829 { 821 {
@@ -837,30 +829,18 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
837 } 829 }
838 } 830 }
839 831
840 // restore the rootct 832 // draw the rectangle
841 this.viewUtils.setRootElement (saveRoot );
842
843 // draw the reectangle
844 context.beginPath(); 833 context.beginPath();
845 834
846 var pt4 = MathUtils.makeDimension4(rect.getPoint(3)); 835 pt = MathUtils.makeDimension3(rect.getPoint(3));
847 var viewPt = glmat4.multiplyVec3( planeToWorld, pt4, [] );
848 MathUtils.makeDimension3( viewPt );
849// var pt = this.viewUtils.localToGlobal( viewPt, this._sourceSpaceElt );
850 var pt = this.viewUtils.localToGlobal2(viewPt, ssMat);
851 836
852 var bounds3D = [[0,0], [0,0], [0,0], [0,0]]; 837 bounds3D = [[0,0], [0,0], [0,0], [0,0]];
853 this._selectionCtr = pt.slice(0); 838 this._selectionCtr = pt.slice(0);
854 839
855 context.moveTo( pt[0], pt[1] ); 840 context.moveTo( pt[0], pt[1] );
856 for (var i=0; i<4; i++) 841 for (i=0; i<4; i++)
857 { 842 {
858 pt4 = MathUtils.makeDimension4(rect.getPoint(i)); 843 pt = rect.getPoint(i);
859 //viewPt = planeToWorld.multiply( pt4 );
860 viewPt = glmat4.multiplyVec3( planeToWorld, pt4, [] );
861 MathUtils.makeDimension3( viewPt );
862// pt = this.viewUtils.localToGlobal( viewPt, this._sourceSpaceElt );
863 pt = this.viewUtils.localToGlobal2( viewPt, ssMat );
864 context.lineTo( pt[0], pt[1] ); 844 context.lineTo( pt[0], pt[1] );
865 bounds3D[i] = pt.slice(0); 845 bounds3D[i] = pt.slice(0);
866 } 846 }
@@ -870,8 +850,6 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
870 var dir = vecUtils.vecSubtract(2, bounds3D[1], bounds3D[3]); 850 var dir = vecUtils.vecSubtract(2, bounds3D[1], bounds3D[3]);
871 var ctr = vecUtils.vecNormalize(2, dir, vecUtils.vecDist(2, bounds3D[1], bounds3D[3])/2); 851 var ctr = vecUtils.vecNormalize(2, dir, vecUtils.vecDist(2, bounds3D[1], bounds3D[3])/2);
872 852
873// this._selectionCtr[0] += ctr[0] - window.stageManager.userContentLeft;
874// this._selectionCtr[1] += ctr[1] - window.stageManager.userContentTop;
875 this._selectionCtr[0] += ctr[0] - this.application.ninja.stage.userContentLeft; 853 this._selectionCtr[0] += ctr[0] - this.application.ninja.stage.userContentLeft;
876 this._selectionCtr[1] += ctr[1] - this.application.ninja.stage.userContentTop; 854 this._selectionCtr[1] += ctr[1] - this.application.ninja.stage.userContentTop;
877 } 855 }
@@ -879,16 +857,19 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
879 { 857 {
880 var minPt, maxPt; 858 var minPt, maxPt;
881 859
882 for (var i=0; i<eltArray.length; i++) 860 // we set the root to "the world".
861 var saveRoot = this.viewUtils.getRootElement();
862 this.viewUtils.setRootElement( this.viewUtils.getStageElement() );
863 ssMat = this.viewUtils.getLocalToGlobalMatrix( this._sourceSpaceElt );
864
865 for (i=0; i<len; i++)
883 { 866 {
884 var elt = eltArray[i]; 867 elt = eltArray[i];
885 var bounds = this.viewUtils.getElementViewBounds3D( elt ); 868 bounds = this.viewUtils.getElementViewBounds3D( elt );
886 var eltMat = this.viewUtils.getLocalToGlobalMatrix( elt ); 869 var eltMat = this.viewUtils.getLocalToGlobalMatrix( elt );
887 for (var j=0; j<4; j++) 870 for (j=0; j<4; j++)
888 { 871 {
889 //var pt = worldToPlane.multiply( MathUtils.makeDimension4( this.viewUtils.localToGlobal( bounds[j], elt )) ); 872 pt = this.viewUtils.localToGlobal2( bounds[j], eltMat );
890// var pt = this.viewUtils.localToGlobal( bounds[j], elt );
891 var pt = this.viewUtils.localToGlobal2( bounds[j], eltMat );
892 if (!minPt) 873 if (!minPt)
893 { 874 {
894 minPt = pt.slice(0); 875 minPt = pt.slice(0);
@@ -925,15 +906,6 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
925 906
926 // get the 8 corners of the parallelpiped in world space