aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/3D
diff options
context:
space:
mode:
authorValerio Virgillito2012-04-23 15:58:27 -0700
committerValerio Virgillito2012-04-23 15:58:27 -0700
commit4ab2a55ba2175c72f859c428122a166f8af74140 (patch)
tree3f383cb4b9e92dcb7f80eed62ff6cbc467062448 /js/helper-classes/3D
parent3f8f224170937d498d3a03c706494408a6b4bf1d (diff)
parent5a0331fc26fcc2cdc6200086109e34440a2dec6a (diff)
downloadninja-4ab2a55ba2175c72f859c428122a166f8af74140.tar.gz
Merge branch 'refs/heads/master' into stage-document-architecture
Diffstat (limited to 'js/helper-classes/3D')
-rwxr-xr-xjs/helper-classes/3D/draw-utils.js50
-rwxr-xr-xjs/helper-classes/3D/hit-record.js55
-rwxr-xr-xjs/helper-classes/3D/snap-manager.js11
-rwxr-xr-xjs/helper-classes/3D/view-utils.js35
4 files changed, 110 insertions, 41 deletions
diff --git a/js/helper-classes/3D/draw-utils.js b/js/helper-classes/3D/draw-utils.js
index ec8eea0f..7bd77c3a 100755
--- a/js/helper-classes/3D/draw-utils.js
+++ b/js/helper-classes/3D/draw-utils.js
@@ -803,20 +803,21 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
803 context.stroke(); 803 context.stroke();
804 804
805 this._selectionCtr = MathUtils.getCenterFromBounds(3, bounds3D); 805 this._selectionCtr = MathUtils.getCenterFromBounds(3, bounds3D);
806 console.log("selection center, single elt case - ", this._selectionCtr); 806// console.log("selection center, single elt case - ", this._selectionCtr);
807 807
808 this.viewUtils.popViewportObj(); 808 this.viewUtils.popViewportObj();
809 } 809 }
810 else 810 else
811 { 811 {
812 // get the plane from the first element to compare against the other elements 812 // get the plane from the first element to compare against the other elements
813 var dot;
813 var flat = true; 814 var flat = true;
814 var plane = this.viewUtils.getElementPlane( eltArray[0] ); 815 var plane = this.viewUtils.getUnprojectedElementPlane( eltArray[0] );
815 for (i=1; i<len; i++) 816 for (i=1; i<len; i++)
816 { 817 {
817 elt = eltArray[i]; 818 elt = eltArray[i];
818 var plane2 = this.viewUtils.getElementPlane( elt ); 819 var plane2 = this.viewUtils.getUnprojectedElementPlane( elt );
819 var dot = MathUtils.dot3(plane,plane2); 820 dot = Math.abs( MathUtils.dot3(plane,plane2) );
820 if (MathUtils.fpCmp(dot, 1) != 0) 821 if (MathUtils.fpCmp(dot, 1) != 0)
821 { 822 {
822 flat = false; 823 flat = false;
@@ -832,6 +833,19 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
832 } 833 }
833 } 834 }
834 835
836 // if all of the planes are aligned, check if they are aligned with the view direction
837 if (flat)
838 {
839 var stage = this.application.ninja.currentDocument.documentRoot;
840 var stageMat = this.viewUtils.getMatrixFromElement(stage);
841 var viewDir = [ stageMat[8], stageMat[9], stageMat[10] ];
842 viewDir = vecUtils.vecNormalize( 3, viewDir );
843 dot = Math.abs( MathUtils.dot3(plane,viewDir) );
844 if (MathUtils.fpCmp(dot, 1) != 0)
845 flat = false;
846 }
847// console.log( "drawSelectionBounds, flat: " + flat );
848
835 // if all the elements share the same plane, draw the 2D rectangle 849 // if all the elements share the same plane, draw the 2D rectangle
836 if (flat) 850 if (flat)
837 { 851 {
@@ -843,12 +857,12 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
843 857
844 // get the element bounds in 'plane' space 858 // get the element bounds in 'plane' space
845 bounds = this.viewUtils.getElementViewBounds3D( elt ); 859 bounds = this.viewUtils.getElementViewBounds3D( elt );
846 ssMat = this.viewUtils.getLocalToGlobalMatrix( elt ); 860 ssMat = this.viewUtils.getLocalToGlobalMatrix( elt );
847 for (j=0; j<4; j++) 861 for (j=0; j<4; j++)
848 { 862 {
849 var localPt = bounds[j]; 863 var localPt = bounds[j];
850 tmpPt = this.viewUtils.localToGlobal2(localPt, ssMat); 864 tmpPt = this.viewUtils.localToGlobal2(localPt, ssMat);
851 pt = tmpPt; 865 pt = tmpPt;
852 866
853 if (!rect) 867 if (!rect)
854 { 868 {
@@ -865,7 +879,7 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
865 // draw the rectangle 879 // draw the rectangle
866 context.beginPath(); 880 context.beginPath();
867 881
868 pt = MathUtils.makeDimension3(rect.getPoint(3)); 882 pt = MathUtils.makeDimension3(rect.getPoint(3));
869 883
870 bounds3D = [[0,0], [0,0], [0,0], [0,0]]; 884 bounds3D = [[0,0], [0,0], [0,0], [0,0]];
871 this._selectionCtr = pt.slice(0); 885 this._selectionCtr = pt.slice(0);
@@ -873,7 +887,7 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
873 context.moveTo( pt[0], pt[1] ); 887 context.moveTo( pt[0], pt[1] );
874 for (i=0; i<4; i++) 888 for (i=0; i<4; i++)
875 { 889 {
876 pt = rect.getPoint(i); 890 pt = rect.getPoint(i);
877 context.lineTo( pt[0], pt[1] ); 891 context.lineTo( pt[0], pt[1] );
878 bounds3D[i] = pt.slice(0); 892 bounds3D[i] = pt.slice(0);
879 } 893 }
@@ -890,19 +904,21 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
890 { 904 {
891 var minPt, maxPt; 905 var minPt, maxPt;
892 906
893 // we set the root to "the world". 907 // we set the root to "the world".
894 var saveRoot = this.viewUtils.getRootElement(); 908 var saveRoot = this.viewUtils.getRootElement();
895 this.viewUtils.setRootElement( this.viewUtils.getStageElement() ); 909 this.viewUtils.setRootElement( this.viewUtils.getStageElement() );
896 ssMat = this.viewUtils.getLocalToGlobalMatrix( this._sourceSpaceElt ); 910 ssMat = this.viewUtils.getLocalToGlobalMatrix( this._sourceSpaceElt );
897 911
898 for (i=0; i<len; i++) 912 for (i=0; i<len; i++)
899 { 913 {
900 elt = eltArray[i]; 914 elt = eltArray[i];
901 bounds = this.viewUtils.getElementViewBounds3D( elt ); 915 bounds = this.viewUtils.getElementViewBounds3D( elt );
902 var eltMat = this.viewUtils.getLocalToGlobalMatrix( elt ); 916 var eltMat = this.viewUtils.getLocalToGlobalMatrix( elt );
903 for (j=0; j<4; j++) 917 for (j=0; j<4; j++)
904 { 918 {
905 pt = this.viewUtils.localToGlobal2( bounds[j], eltMat ); 919 pt = this.viewUtils.localToGlobal2( bounds[j], eltMat );
920 var tmpPt = this.viewUtils.localToStageWorld(bounds[j], elt);
921 tmpPt = this.viewUtils.screenToView( tmpPt[0], tmpPt[1], tmpPt[2] );
906 if (!minPt) 922 if (!minPt)
907 { 923 {
908 minPt = pt.slice(0); 924 minPt = pt.slice(0);
@@ -939,7 +955,7 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
939 955
940 // get the 8 corners of the parallelpiped in world space 956 // get the 8 corners of the parallelpiped in world space
941 var wc = new Array(); // wc == world cube 957 var wc = new Array(); // wc == world cube
942 wc.push( this.viewUtils.localToGlobal2( [x0,y0,z1], ssMat ) ); 958 wc.push( this.viewUtils.localToGlobal2( [x0,y0,z1], ssMat ) );
943 wc.push( this.viewUtils.localToGlobal2( [x0,y1,z1], ssMat ) ); 959 wc.push( this.viewUtils.localToGlobal2( [x0,y1,z1], ssMat ) );
944 wc.push( this.viewUtils.localToGlobal2( [x1,y1,z1], ssMat ) ); 960 wc.push( this.viewUtils.localToGlobal2( [x1,y1,z1], ssMat ) );
945 wc.push( this.viewUtils.localToGlobal2( [x1,y0,z1], ssMat ) ); 961 wc.push( this.viewUtils.localToGlobal2( [x1,y0,z1], ssMat ) );
@@ -970,7 +986,7 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
970 //context.strokeStyle = ((right > 0) || (back > 0)) ? dark : light; context.beginPath(); 986 //context.strokeStyle = ((right > 0) || (back > 0)) ? dark : light; context.beginPath();
971 if ((right > 0) || (back > 0)) { 987 if ((right > 0) || (back > 0)) {
972 context.beginPath(); 988 context.beginPath();
973 p = this.viewUtils.localToGlobal2( [x1, y0, z0], ssMat ); context.moveTo( p[0], p[1] ); 989 p = this.viewUtils.localToGlobal2( [x1, y0, z0], ssMat ); context.moveTo( p[0], p[1] );
974 p = this.viewUtils.localToGlobal2( [x1, y1, z0], ssMat ); context.lineTo( p[0], p[1] ); 990 p = this.viewUtils.localToGlobal2( [x1, y1, z0], ssMat ); context.lineTo( p[0], p[1] );
975 context.closePath(); context.stroke(); 991 context.closePath(); context.stroke();
976 } 992 }
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);