aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/3D/draw-utils.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/helper-classes/3D/draw-utils.js')
-rwxr-xr-xjs/helper-classes/3D/draw-utils.js48
1 files changed, 32 insertions, 16 deletions
diff --git a/js/helper-classes/3D/draw-utils.js b/js/helper-classes/3D/draw-utils.js
index c7c1c08d..a200268e 100755
--- a/js/helper-classes/3D/draw-utils.js
+++ b/js/helper-classes/3D/draw-utils.js
@@ -774,13 +774,14 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
774 else 774 else
775 { 775 {
776 // get the plane from the first element to compare against the other elements 776 // get the plane from the first element to compare against the other elements
777 var dot;
777 var flat = true; 778 var flat = true;
778 var plane = this.viewUtils.getElementPlane( eltArray[0] ); 779 var plane = this.viewUtils.getUnprojectedElementPlane( eltArray[0] );
779 for (i=1; i<len; i++) 780 for (i=1; i<len; i++)
780 { 781 {
781 elt = eltArray[i]; 782 elt = eltArray[i];
782 var plane2 = this.viewUtils.getElementPlane( elt ); 783 var plane2 = this.viewUtils.getUnprojectedElementPlane( elt );
783 var dot = MathUtils.dot3(plane,plane2); 784 dot = Math.abs( MathUtils.dot3(plane,plane2) );
784 if (MathUtils.fpCmp(dot, 1) != 0) 785 if (MathUtils.fpCmp(dot, 1) != 0)
785 { 786 {
786 flat = false; 787 flat = false;
@@ -796,6 +797,19 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
796 } 797 }
797 } 798 }
798 799
800 // if all of the planes are aligned, check if they are aligned with the view direction
801 if (flat)
802 {
803 var stage = this.application.ninja.currentDocument.documentRoot;
804 var stageMat = this.viewUtils.getMatrixFromElement(stage);
805 var viewDir = [ stageMat[8], stageMat[9], stageMat[10] ];
806 viewDir = vecUtils.vecNormalize( 3, viewDir );
807 dot = Math.abs( MathUtils.dot3(plane,viewDir) );
808 if (MathUtils.fpCmp(dot, 1) != 0)
809 flat = false;
810 }
811 console.log( "drawSelectionBounds, flat: " + flat );
812
799 // if all the elements share the same plane, draw the 2D rectangle 813 // if all the elements share the same plane, draw the 2D rectangle
800 if (flat) 814 if (flat)
801 { 815 {
@@ -807,12 +821,12 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
807 821
808 // get the element bounds in 'plane' space 822 // get the element bounds in 'plane' space
809 bounds = this.viewUtils.getElementViewBounds3D( elt ); 823 bounds = this.viewUtils.getElementViewBounds3D( elt );
810 ssMat = this.viewUtils.getLocalToGlobalMatrix( elt ); 824 ssMat = this.viewUtils.getLocalToGlobalMatrix( elt );
811 for (j=0; j<4; j++) 825 for (j=0; j<4; j++)
812 { 826 {
813 var localPt = bounds[j]; 827 var localPt = bounds[j];
814 tmpPt = this.viewUtils.localToGlobal2(localPt, ssMat); 828 tmpPt = this.viewUtils.localToGlobal2(localPt, ssMat);
815 pt = tmpPt; 829 pt = tmpPt;
816 830
817 if (!rect) 831 if (!rect)
818 { 832 {
@@ -829,7 +843,7 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
829 // draw the rectangle 843 // draw the rectangle
830 context.beginPath(); 844 context.beginPath();
831 845
832 pt = MathUtils.makeDimension3(rect.getPoint(3)); 846 pt = MathUtils.makeDimension3(rect.getPoint(3));
833 847
834 bounds3D = [[0,0], [0,0], [0,0], [0,0]]; 848 bounds3D = [[0,0], [0,0], [0,0], [0,0]];
835 this._selectionCtr = pt.slice(0); 849 this._selectionCtr = pt.slice(0);
@@ -837,7 +851,7 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
837 context.moveTo( pt[0], pt[1] ); 851 context.moveTo( pt[0], pt[1] );
838 for (i=0; i<4; i++) 852 for (i=0; i<4; i++)
839 { 853 {
840 pt = rect.getPoint(i); 854 pt = rect.getPoint(i);
841 context.lineTo( pt[0], pt[1] ); 855 context.lineTo( pt[0], pt[1] );
842 bounds3D[i] = pt.slice(0); 856 bounds3D[i] = pt.slice(0);
843 } 857 }
@@ -854,19 +868,21 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
854 { 868 {
855 var minPt, maxPt; 869 var minPt, maxPt;
856 870
857 // we set the root to "the world". 871 // we set the root to "the world".
858 var saveRoot = this.viewUtils.getRootElement(); 872 var saveRoot = this.viewUtils.getRootElement();
859 this.viewUtils.setRootElement( this.viewUtils.getStageElement() ); 873 this.viewUtils.setRootElement( this.viewUtils.getStageElement() );
860 ssMat = this.viewUtils.getLocalToGlobalMatrix( this._sourceSpaceElt ); 874 ssMat = this.viewUtils.getLocalToGlobalMatrix( this._sourceSpaceElt );
861 875
862 for (i=0; i<len; i++) 876 for (i=0; i<len; i++)
863 { 877 {
864 elt = eltArray[i]; 878 elt = eltArray[i];
865 bounds = this.viewUtils.getElementViewBounds3D( elt ); 879 bounds = this.viewUtils.getElementViewBounds3D( elt );
866 var eltMat = this.viewUtils.getLocalToGlobalMatrix( elt ); 880 var eltMat = this.viewUtils.getLocalToGlobalMatrix( elt );
867 for (j=0; j<4; j++) 881 for (j=0; j<4; j++)
868 { 882 {
869 pt = this.viewUtils.localToGlobal2( bounds[j], eltMat ); 883 pt = this.viewUtils.localToGlobal2( bounds[j], eltMat );
884 var tmpPt = this.viewUtils.localToStageWorld(bounds[j], elt);
885 tmpPt = this.viewUtils.screenToView( tmpPt[0], tmpPt[1], tmpPt[2] );
870 if (!minPt) 886 if (!minPt)
871 { 887 {
872 minPt = pt.slice(0); 888 minPt = pt.slice(0);
@@ -903,7 +919,7 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
903 919
904 // get the 8 corners of the parallelpiped in world space 920 // get the 8 corners of the parallelpiped in world space
905 var wc = new Array(); // wc == world cube 921 var wc = new Array(); // wc == world cube
906 wc.push( this.viewUtils.localToGlobal2( [x0,y0,z1], ssMat ) ); 922 wc.push( this.viewUtils.localToGlobal2( [x0,y0,z1], ssMat ) );
907 wc.push( this.viewUtils.localToGlobal2( [x0,y1,z1], ssMat ) ); 923 wc.push( this.viewUtils.localToGlobal2( [x0,y1,z1], ssMat ) );
908 wc.push( this.viewUtils.localToGlobal2( [x1,y1,z1], ssMat ) ); 924 wc.push( this.viewUtils.localToGlobal2( [x1,y1,z1], ssMat ) );
909 wc.push( this.viewUtils.localToGlobal2( [x1,y0,z1], ssMat ) ); 925 wc.push( this.viewUtils.localToGlobal2( [x1,y0,z1], ssMat ) );
@@ -934,7 +950,7 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
934 //context.strokeStyle = ((right > 0) || (back > 0)) ? dark : light; context.beginPath(); 950 //context.strokeStyle = ((right > 0) || (back > 0)) ? dark : light; context.beginPath();
935 if ((right > 0) || (back > 0)) { 951 if ((right > 0) || (back > 0)) {
936 context.beginPath(); 952 context.beginPath();
937 p = this.viewUtils.localToGlobal2( [x1, y0, z0], ssMat ); context.moveTo( p[0], p[1] ); 953 p = this.viewUtils.localToGlobal2( [x1, y0, z0], ssMat ); context.moveTo( p[0], p[1] );
938 p = this.viewUtils.localToGlobal2( [x1, y1, z0], ssMat ); context.lineTo( p[0], p[1] ); 954 p = this.viewUtils.localToGlobal2( [x1, y1, z0], ssMat ); context.lineTo( p[0], p[1] );
939 context.closePath(); context.stroke(); 955 context.closePath(); context.stroke();
940 } 956 }