diff options
Diffstat (limited to 'js')
-rwxr-xr-x | js/helper-classes/3D/draw-utils.js | 48 | ||||
-rwxr-xr-x | js/helper-classes/3D/view-utils.js | 7 | ||||
-rwxr-xr-x | js/tools/Rotate3DToolBase.js | 155 | ||||
-rwxr-xr-x | js/tools/modifier-tool-base.js | 6 |
4 files changed, 152 insertions, 64 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 | } |
diff --git a/js/helper-classes/3D/view-utils.js b/js/helper-classes/3D/view-utils.js index 392de0be..f803a274 100755 --- a/js/helper-classes/3D/view-utils.js +++ b/js/helper-classes/3D/view-utils.js | |||
@@ -112,13 +112,6 @@ exports.ViewUtils = Montage.create(Component, { | |||
112 | var mat = this.getMatrixFromElement(elt); | 112 | var mat = this.getMatrixFromElement(elt); |
113 | var plane = [mat[8], mat[9], mat[10], mat[11]]; | 113 | var plane = [mat[8], mat[9], mat[10], mat[11]]; |
114 | 114 | ||
115 | var stage = this.application.ninja.currentDocument.documentRoot; | ||
116 | if (elt === stage) | ||
117 | { | ||
118 | xVec = [1,0,0]; | ||
119 | yVec = [0,1,0]; | ||
120 | } | ||
121 | |||
122 | // The translation value is a point on the plane | 115 | // The translation value is a point on the plane |
123 | this.pushViewportObj( elt ); | 116 | this.pushViewportObj( elt ); |
124 | var ptOnPlane = this.getCenterOfProjection(); | 117 | var ptOnPlane = this.getCenterOfProjection(); |
diff --git a/js/tools/Rotate3DToolBase.js b/js/tools/Rotate3DToolBase.js index e0c5abcb..402023ff 100755 --- a/js/tools/Rotate3DToolBase.js +++ b/js/tools/Rotate3DToolBase.js | |||
@@ -14,7 +14,8 @@ var Montage = require("montage/core/core").Montage, | |||
14 | viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils, | 14 | viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils, |
15 | vecUtils = require("js/helper-classes/3D/vec-utils").VecUtils, | 15 | vecUtils = require("js/helper-classes/3D/vec-utils").VecUtils, |
16 | drawUtils = require("js/helper-classes/3D/draw-utils").DrawUtils, | 16 | drawUtils = require("js/helper-classes/3D/draw-utils").DrawUtils, |
17 | ElementsMediator = require("js/mediators/element-mediator").ElementMediator; | 17 | ElementsMediator = require("js/mediators/element-mediator").ElementMediator, |
18 | Rectangle = require("js/helper-classes/3D/rectangle").Rectangle; | ||
18 | 19 | ||
19 | exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { | 20 | exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { |
20 | _canSnap: { value: false }, | 21 | _canSnap: { value: false }, |
@@ -61,14 +62,22 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { | |||
61 | this._origin[0] += dx; | 62 | this._origin[0] += dx; |
62 | this._origin[1] += dy; | 63 | this._origin[1] += dy; |
63 | this._origin[2] += dz; | 64 | this._origin[2] += dz; |
65 | console.log( "modifyElements, _origin: " + this._origin ); | ||
64 | 66 | ||
65 | var len = this._targets.length; | 67 | var len = this._targets.length; |
66 | if(len === 1) | 68 | if(len === 1) |
67 | { | 69 | { |
68 | this._startOriginArray[0][0] += dx; | 70 | // this._startOriginArray[0][0] += dx; |
69 | this._startOriginArray[0][1] += dy; | 71 | // this._startOriginArray[0][1] += dy; |
70 | this._startOriginArray[0][2] += dz; | 72 | // this._startOriginArray[0][2] += dz; |
71 | console.log( "Rotate3DToolBase.modifyElements, _startOriginArray[0]: " + this._startOriginArray[0] ); | 73 | var g2lMat = this._targets[0].g2l; |
74 | var localOrigin = MathUtils.transformAndDivideHomogeneousPoint( this._origin, g2lMat ); | ||
75 | var elt = this._targets[0].elt; | ||
76 | viewUtils.pushViewportObj( elt ); | ||
77 | var viewOrigin = viewUtils.screenToView( localOrigin[0], localOrigin[1], localOrigin[2] ); | ||
78 | viewUtils.popViewportObj(); | ||
79 | this._startOriginArray[0] = viewOrigin; | ||
80 | //console.log( "Rotate3DToolBase.modifyElements, _startOriginArray[0]: " + this._startOriginArray[0] ); | ||