aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/3D
diff options
context:
space:
mode:
Diffstat (limited to 'js/helper-classes/3D')
-rwxr-xr-xjs/helper-classes/3D/draw-utils.js79
-rwxr-xr-xjs/helper-classes/3D/hit-record.js55
-rwxr-xr-xjs/helper-classes/3D/snap-manager.js19
-rwxr-xr-xjs/helper-classes/3D/view-utils.js81
4 files changed, 156 insertions, 78 deletions
diff --git a/js/helper-classes/3D/draw-utils.js b/js/helper-classes/3D/draw-utils.js
index a5428ea3..7bd77c3a 100755
--- a/js/helper-classes/3D/draw-utils.js
+++ b/js/helper-classes/3D/draw-utils.js
@@ -111,6 +111,7 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
111 this.eventManager.addEventListener("elementAdded", this, false); 111 this.eventManager.addEventListener("elementAdded", this, false);
112 this.eventManager.addEventListener("elementsRemoved", this, false); 112 this.eventManager.addEventListener("elementsRemoved", this, false);
113 this.eventManager.addEventListener("elementChange", this, false); 113 this.eventManager.addEventListener("elementChange", this, false);
114 this.eventManager.addEventListener("elementChanging", this, false);
114 this.eventManager.addEventListener("closeDocument", this, false); 115 this.eventManager.addEventListener("closeDocument", this, false);
115 this.eventManager.addEventListener("elementReplaced", this, false); 116 this.eventManager.addEventListener("elementReplaced", this, false);
116 } 117 }
@@ -227,20 +228,26 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
227 // TODO - Check why handleElementChange is being fired before handleAddElement 228 // TODO - Check why handleElementChange is being fired before handleAddElement
228 handleElementChange: { 229 handleElementChange: {
229 value: function(event) { 230 value: function(event) {
230 if(!event.detail || !event.detail.data) 231 this._elementChangeHelper(event);
231 { 232 }
233 },
234
235 handleElementChanging: {
236 value: function(event) {
237 this._elementChangeHelper(event);
238 }
239 },
240
241 _elementChangeHelper: {
242 value: function(event) {
243 if(!event.detail || !event.detail.data) {
232 return; 244 return;
233 } 245 }
234 var els = event.detail.data.els; 246 var els = event.detail.data.els;
235 if(els && this._shouldUpdatePlanes(event.detail.data.prop)) 247 if(els && this._shouldUpdatePlanes(event.detail.data.prop)) {
236 { 248 var len = els.length;
237 var len = els.length, 249 for(var i=0; i < len; i++) {
238 i = 0, 250 if(els[i].elementModel.props3D.elementPlane) {
239 item;
240
241 for(i=0; i < len; i++) {
242 if(els[i].elementModel.props3D.elementPlane)
243 {
244 els[i].elementModel.props3D.elementPlane.init(); 251 els[i].elementModel.props3D.elementPlane.init();
245 } 252 }
246 } 253 }
@@ -796,20 +803,21 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
796 context.stroke(); 803 context.stroke();
797 804
798 this._selectionCtr = MathUtils.getCenterFromBounds(3, bounds3D); 805 this._selectionCtr = MathUtils.getCenterFromBounds(3, bounds3D);
799 console.log("selection center, single elt case - ", this._selectionCtr); 806// console.log("selection center, single elt case - ", this._selectionCtr);
800 807
801 this.viewUtils.popViewportObj(); 808 this.viewUtils.popViewportObj();
802 } 809 }
803 else 810 else
804 { 811 {
805 // 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;
806 var flat = true; 814 var flat = true;
807 var plane = this.viewUtils.getElementPlane( eltArray[0] ); 815 var plane = this.viewUtils.getUnprojectedElementPlane( eltArray[0] );
808 for (i=1; i<len; i++) 816 for (i=1; i<len; i++)
809 { 817 {
810 elt = eltArray[i]; 818 elt = eltArray[i];
811 var plane2 = this.viewUtils.getElementPlane( elt ); 819 var plane2 = this.viewUtils.getUnprojectedElementPlane( elt );
812 var dot = MathUtils.dot3(plane,plane2); 820 dot = Math.abs( MathUtils.dot3(plane,plane2) );
813 if (MathUtils.fpCmp(dot, 1) != 0) 821 if (MathUtils.fpCmp(dot, 1) != 0)
814 { 822 {
815 flat = false; 823 flat = false;
@@ -825,6 +833,19 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
825 } 833 }
826 } 834 }
827 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
828 // 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
829 if (flat) 850 if (flat)
830 { 851 {
@@ -836,12 +857,12 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
836 857
837 // get the element bounds in 'plane' space 858 // get the element bounds in 'plane' space
838 bounds = this.viewUtils.getElementViewBounds3D( elt ); 859 bounds = this.viewUtils.getElementViewBounds3D( elt );
839 ssMat = this.viewUtils.getLocalToGlobalMatrix( elt ); 860 ssMat = this.viewUtils.getLocalToGlobalMatrix( elt );
840 for (j=0; j<4; j++) 861 for (j=0; j<4; j++)
841 { 862 {
842 var localPt = bounds[j]; 863 var localPt = bounds[j];
843 tmpPt = this.viewUtils.localToGlobal2(localPt, ssMat); 864 tmpPt = this.viewUtils.localToGlobal2(localPt, ssMat);
844 pt = tmpPt; 865 pt = tmpPt;
845 866
846 if (!rect) 867 if (!rect)
847 { 868 {
@@ -858,7 +879,7 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
858 // draw the rectangle 879 // draw the rectangle
859 context.beginPath(); 880 context.beginPath();
860 881
861 pt = MathUtils.makeDimension3(rect.getPoint(3)); 882 pt = MathUtils.makeDimension3(rect.getPoint(3));
862 883
863 bounds3D = [[0,0], [0,0], [0,0], [0,0]]; 884 bounds3D = [[0,0], [0,0], [0,0], [0,0]];
864 this._selectionCtr = pt.slice(0); 885 this._selectionCtr = pt.slice(0);
@@ -866,7 +887,7 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
866 context.moveTo( pt[0], pt[1] ); 887 context.moveTo( pt[0], pt[1] );
867 for (i=0; i<4; i++) 888 for (i=0; i<4; i++)
868 { 889 {
869 pt = rect.getPoint(i); 890 pt = rect.getPoint(i);
870 context.lineTo( pt[0], pt[1] ); 891 context.lineTo( pt[0], pt[1] );
871 bounds3D[i] = pt.slice(0); 892 bounds3D[i] = pt.slice(0);
872 } 893 }
@@ -883,19 +904,21 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
883 { 904 {
884 var minPt, maxPt; 905 var minPt, maxPt;
885 906
886 // we set the root to "the world". 907 // we set the root to "the world".
887 var saveRoot = this.viewUtils.getRootElement(); 908 var saveRoot = this.viewUtils.getRootElement();
888 this.viewUtils.setRootElement( this.viewUtils.getStageElement() ); 909 this.viewUtils.setRootElement( this.viewUtils.getStageElement() );
889 ssMat = this.viewUtils.getLocalToGlobalMatrix( this._sourceSpaceElt ); 910 ssMat = this.viewUtils.getLocalToGlobalMatrix( this._sourceSpaceElt );
890 911
891 for (i=0; i<len; i++) 912 for (i=0; i<len; i++)
892 { 913 {
893 elt = eltArray[i]; 914 elt = eltArray[i];
894 bounds = this.viewUtils.getElementViewBounds3D( elt ); 915 bounds = this.viewUtils.getElementViewBounds3D( elt );
895 var eltMat = this.viewUtils.getLocalToGlobalMatrix( elt ); 916 var eltMat = this.viewUtils.getLocalToGlobalMatrix( elt );
896 for (j=0; j<4; j++) 917 for (j=0; j<4; j++)
897 { 918 {
898 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] );
899 if (!minPt) 922 if (!minPt)
900 { 923 {
901 minPt = pt.slice(0); 924 minPt = pt.slice(0);
@@ -932,7 +955,7 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
932 955
933 // get the 8 corners of the parallelpiped in world space 956 // get the 8 corners of the parallelpiped in world space
934 var wc = new Array(); // wc == world cube 957 var wc = new Array(); // wc == world cube
935 wc.push( this.viewUtils.localToGlobal2( [x0,y0,z1], ssMat ) ); 958 wc.push( this.viewUtils.localToGlobal2( [x0,y0,z1], ssMat ) );
936 wc.push( this.viewUtils.localToGlobal2( [x0,y1,z1], ssMat ) ); 959 wc.push( this.viewUtils.localToGlobal2( [x0,y1,z1], ssMat ) );
937 wc.push( this.viewUtils.localToGlobal2( [x1,y1,z1], ssMat ) ); 960 wc.push( this.viewUtils.localToGlobal2( [x1,y1,z1], ssMat ) );
938 wc.push( this.viewUtils.localToGlobal2( [x1,y0,z1], ssMat ) ); 961 wc.push( this.viewUtils.localToGlobal2( [x1,y0,z1], ssMat ) );
@@ -963,7 +986,7 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
963 //context.strokeStyle = ((right > 0) || (back > 0)) ? dark : light; context.beginPath(); 986 //context.strokeStyle = ((right > 0) || (back > 0)) ? dark : light; context.beginPath();
964 if ((right > 0) || (back > 0)) { 987 if ((right > 0) || (back > 0)) {
965 context.beginPath(); 988 context.beginPath();
966 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] );
967 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] );
968 context.closePath(); context.stroke(); 991 context.closePath()