aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xjs/helper-classes/3D/draw-utils.js48
-rwxr-xr-xjs/helper-classes/3D/hit-record.js55
-rwxr-xr-xjs/helper-classes/3D/snap-manager.js2
-rwxr-xr-xjs/helper-classes/3D/view-utils.js35
-rwxr-xr-xjs/tools/Rotate3DToolBase.js161
-rwxr-xr-xjs/tools/RotateObject3DTool.js141
-rwxr-xr-xjs/tools/Translate3DToolBase.js177
-rwxr-xr-xjs/tools/TranslateObject3DTool.js1
-rwxr-xr-xjs/tools/modifier-tool-base.js20
9 files changed, 497 insertions, 143 deletions
diff --git a/js/helper-classes/3D/draw-utils.js b/js/helper-classes/3D/draw-utils.js
index a5428ea3..42e0cfa9 100755
--- a/js/helper-classes/3D/draw-utils.js
+++ b/js/helper-classes/3D/draw-utils.js
@@ -803,13 +803,14 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
803 else 803 else
804 { 804 {
805 // get the plane from the first element to compare against the other elements 805 // get the plane from the first element to compare against the other elements
806 var dot;
806 var flat = true; 807 var flat = true;
807 var plane = this.viewUtils.getElementPlane( eltArray[0] ); 808 var plane = this.viewUtils.getUnprojectedElementPlane( eltArray[0] );
808 for (i=1; i<len; i++) 809 for (i=1; i<len; i++)
809 { 810 {
810 elt = eltArray[i]; 811 elt = eltArray[i];
811 var plane2 = this.viewUtils.getElementPlane( elt ); 812 var plane2 = this.viewUtils.getUnprojectedElementPlane( elt );
812 var dot = MathUtils.dot3(plane,plane2); 813 dot = Math.abs( MathUtils.dot3(plane,plane2) );
813 if (MathUtils.fpCmp(dot, 1) != 0) 814 if (MathUtils.fpCmp(dot, 1) != 0)
814 { 815 {
815 flat = false; 816 flat = false;
@@ -825,6 +826,19 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
825 } 826 }
826 } 827 }
827 828
829 // if all of the planes are aligned, check if they are aligned with the view direction
830 if (flat)
831 {
832 var stage = this.application.ninja.currentDocument.documentRoot;
833 var stageMat = this.viewUtils.getMatrixFromElement(stage);
834 var viewDir = [ stageMat[8], stageMat[9], stageMat[10] ];
835 viewDir = vecUtils.vecNormalize( 3, viewDir );
836 dot = Math.abs( MathUtils.dot3(plane,viewDir) );
837 if (MathUtils.fpCmp(dot, 1) != 0)
838 flat = false;
839 }
840 console.log( "drawSelectionBounds, flat: " + flat );
841
828 // if all the elements share the same plane, draw the 2D rectangle 842 // if all the elements share the same plane, draw the 2D rectangle
829 if (flat) 843 if (flat)
830 { 844 {
@@ -836,12 +850,12 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
836 850
837 // get the element bounds in 'plane' space 851 // get the element bounds in 'plane' space
838 bounds = this.viewUtils.getElementViewBounds3D( elt ); 852 bounds = this.viewUtils.getElementViewBounds3D( elt );
839 ssMat = this.viewUtils.getLocalToGlobalMatrix( elt ); 853 ssMat = this.viewUtils.getLocalToGlobalMatrix( elt );
840 for (j=0; j<4; j++) 854 for (j=0; j<4; j++)
841 { 855 {
842 var localPt = bounds[j]; 856 var localPt = bounds[j];
843 tmpPt = this.viewUtils.localToGlobal2(localPt, ssMat); 857 tmpPt = this.viewUtils.localToGlobal2(localPt, ssMat);
844 pt = tmpPt; 858 pt = tmpPt;
845 859
846 if (!rect) 860 if (!rect)
847 { 861 {
@@ -858,7 +872,7 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
858 // draw the rectangle 872 // draw the rectangle
859 context.beginPath(); 873 context.beginPath();
860 874
861 pt = MathUtils.makeDimension3(rect.getPoint(3)); 875 pt = MathUtils.makeDimension3(rect.getPoint(3));
862 876
863 bounds3D = [[0,0], [0,0], [0,0], [0,0]]; 877 bounds3D = [[0,0], [0,0], [0,0], [0,0]];
864 this._selectionCtr = pt.slice(0); 878 this._selectionCtr = pt.slice(0);
@@ -866,7 +880,7 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
866 context.moveTo( pt[0], pt[1] ); 880 context.moveTo( pt[0], pt[1] );
867 for (i=0; i<4; i++) 881 for (i=0; i<4; i++)
868 { 882 {
869 pt = rect.getPoint(i); 883 pt = rect.getPoint(i);
870 context.lineTo( pt[0], pt[1] ); 884 context.lineTo( pt[0], pt[1] );
871 bounds3D[i] = pt.slice(0); 885 bounds3D[i] = pt.slice(0);
872 } 886 }
@@ -883,19 +897,21 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
883 { 897 {
884 var minPt, maxPt; 898 var minPt, maxPt;
885 899
886 // we set the root to "the world". 900 // we set the root to "the world".
887 var saveRoot = this.viewUtils.getRootElement(); 901 var saveRoot = this.viewUtils.getRootElement();
888 this.viewUtils.setRootElement( this.viewUtils.getStageElement() ); 902 this.viewUtils.setRootElement( this.viewUtils.getStageElement() );
889 ssMat = this.viewUtils.getLocalToGlobalMatrix( this._sourceSpaceElt ); 903 ssMat = this.viewUtils.getLocalToGlobalMatrix( this._sourceSpaceElt );
890 904
891 for (i=0; i<len; i++) 905 for (i=0; i<len; i++)
892 { 906 {
893 elt = eltArray[i]; 907 elt = eltArray[i];
894 bounds = this.viewUtils.getElementViewBounds3D( elt ); 908 bounds = this.viewUtils.getElementViewBounds3D( elt );
895 var eltMat = this.viewUtils.getLocalToGlobalMatrix( elt ); 909 var eltMat = this.viewUtils.getLocalToGlobalMatrix( elt );
896 for (j=0; j<4; j++) 910 for (j=0; j<4; j++)
897 { 911 {
898 pt = this.viewUtils.localToGlobal2( bounds[j], eltMat ); 912 pt = this.viewUtils.localToGlobal2( bounds[j], eltMat );
913 var tmpPt = this.viewUtils.localToStageWorld(bounds[j], elt);
914 tmpPt = this.viewUtils.screenToView( tmpPt[0], tmpPt[1], tmpPt[2] );
899 if (!minPt) 915 if (!minPt)
900 { 916 {
901 minPt = pt.slice(0); 917 minPt = pt.slice(0);
@@ -932,7 +948,7 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
932 948
933 // get the 8 corners of the parallelpiped in world space 949 // get the 8 corners of the parallelpiped in world space
934 var wc = new Array(); // wc == world cube 950 var wc = new Array(); // wc == world cube
935 wc.push( this.viewUtils.localToGlobal2( [x0,y0,z1], ssMat ) ); 951 wc.push( this.viewUtils.localToGlobal2( [x0,y0,z1], ssMat ) );
936 wc.push( this.viewUtils.localToGlobal2( [x0,y1,z1], ssMat ) ); 952 wc.push( this.viewUtils.localToGlobal2( [x0,y1,z1], ssMat ) );
937 wc.push( this.viewUtils.localToGlobal2( [x1,y1,z1], ssMat ) ); 953 wc.push( this.viewUtils.localToGlobal2( [x1,y1,z1], ssMat ) );
938 wc.push( this.viewUtils.localToGlobal2( [x1,y0,z1], ssMat ) ); 954 wc.push( this.viewUtils.localToGlobal2( [x1,y0,z1], ssMat ) );
@@ -963,7 +979,7 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
963 //context.strokeStyle = ((right > 0) || (back > 0)) ? dark : light; context.beginPath(); 979 //context.strokeStyle = ((right > 0) || (back > 0)) ? dark : light; context.beginPath();
964 if ((right > 0) || (back > 0)) { 980 if ((right > 0) || (back > 0)) {
965 context.beginPath(); 981 context.beginPath();
966 p = this.viewUtils.localToGlobal2( [x1, y0, z0], ssMat ); context.moveTo( p[0], p[1] ); 982 p = this.viewUtils.localToGlobal2( [x1, y0, z0], ssMat ); context.moveTo( p[0], p[1] );
967 p = this.viewUtils.localToGlobal2( [x1, y1, z0], ssMat ); context.lineTo( p[0], p[1] ); 983 p = this.viewUtils.localToGlobal2( [x1, y1, z0], ssMat ); context.lineTo( p[0], p[1] );
968 context.closePath(); context.stroke(); 984 context.closePath(); context.stroke();
969 } 985 }
diff --git a/js/helper-classes/3D/hit-record.js b/js/helper-classes/3D/hit-record.js
index 265bf2a4..d72e33bd 100755
--- a/js/helper-classes/3D/hit-record.js
+++ b/js/helper-classes/3D/hit-record.js
@@ -292,6 +292,59 @@ var HitRecord = exports.HitRecord = Object.create(Object.prototype,
292 292
293 return str; 293 return str;
294 } 294 }
295 } 295 },
296
297 test:
298 {
299 value: function()
300 {
301 var elt = this.getElement();
302 var stage = viewUtils.getStage();
303 if (elt === stage) return;
304
305 var localPt = this.calculateElementPreTransformScreenPoint();
306 var stageWorldPt = this.calculateStageWorldPoint();
307 var globalPt = this.getScreenPoint();
308 var err = false;
309
310 var test1 = viewUtils.localToGlobal( localPt, elt );
311 var dist = vecUtils.vecDist(3, test1, globalPt);
312 if (MathUtils.fpSign(dist) != 0)
313 {
314 err = true;
315 console.log( "**** transform error 1 ***** " + dist + ", localPt: " + localPt );
316 }
317
318 var stageWorldToGlobal = viewUtils.getStageWorldToGlobalMatrix();
319 var test2 = MathUtils.transformAndDivideHomogeneousPoint( stageWorldPt, stageWorldToGlobal );
320 dist = vecUtils.vecDist(3, test2, globalPt);
321 if (MathUtils.fpSign(dist) != 0)
322 {
323 err = true;
324 console.log( "**** transform error 2 ***** " + dist + ", localPt: " + localPt );
325 }
326
327 var localToGlobal = viewUtils.getLocalToGlobalMatrix( elt );
328 var globalToLocal = glmat4.inverse( localToGlobal, [] );
329 var test3 = MathUtils.transformAndDivideHomogeneousPoint( globalPt, globalToLocal );
330 dist = vecUtils.vecDist(3, test3, localPt);
331 if (MathUtils.fpSign(dist) != 0)
332 {
333 err = true;
334 console.log( "**** transform error 3 ***** " + dist + ", localPt: " + localPt );
335 }
336
337 var objToStageWorld = viewUtils.getObjToStageWorldMatrix( elt, true );
338 var test4 = MathUtils.transformAndDivideHomogeneousPoint( localPt, objToStageWorld );
339 dist = vecUtils.vecDist(3, test4, stageWorldPt);