From e065244ac75d1d0f25fd5c75cb58e714a13fe16b Mon Sep 17 00:00:00 2001 From: Jonathan Duran Date: Wed, 14 Mar 2012 08:59:17 -0700 Subject: Squashed commit of the following: merge master into timeline Signed-off-by: Jonathan Duran --- js/helper-classes/3D/draw-utils.js | 140 ++++++++++------------------------- js/helper-classes/3D/math-utils.js | 5 +- js/helper-classes/3D/snap-manager.js | 12 ++- 3 files changed, 55 insertions(+), 102 deletions(-) (limited to 'js/helper-classes/3D') diff --git a/js/helper-classes/3D/draw-utils.js b/js/helper-classes/3D/draw-utils.js index 63e7799a..1c00f7ea 100755 --- a/js/helper-classes/3D/draw-utils.js +++ b/js/helper-classes/3D/draw-utils.js @@ -139,8 +139,8 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { handleCloseDocument:{ value: function() { if(this.application.ninja.documentController._documents.length === 0){ - this._eltArray = []; - this._planesArray = []; + this._eltArray = null; + this._planesArray = null; } } }, @@ -721,8 +721,17 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { drawSelectionBounds : { value: function( eltArray ) { this._selectionCtr = null; + var len = eltArray.length, + i, + j, + bounds, + bounds3D, + pt, + tmpPt, + ssMat, + elt; - if (eltArray.length == 0) return; + if (len === 0) return; var context = this._drawingContext; if (!context) return; @@ -731,18 +740,19 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { context.lineWidth = 2; // handle the single element case - if (eltArray.length == 1) + // TODO - Currently, the stage draws its own selection bounds for single selection case + if (len === 1) { // single selection case //console.log( "single selection" ); - var elt = eltArray[0]; + elt = eltArray[0]; this.viewUtils.pushViewportObj( elt ); // get the element bounds in world space - var bounds3D = this.viewUtils.getElementViewBounds3D( elt ); - for (var j=0; j<4; j++) { + bounds3D = this.viewUtils.getElementViewBounds3D( elt ); + for (j=0; j<4; j++) { bounds3D[j] = this.viewUtils.localToGlobal( bounds3D[j], elt ); } @@ -766,19 +776,12 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { } else { - // the multiple selection case. - //console.log( "multiple selection" ); - - // we set the root to "the world". - var saveRoot = this.viewUtils.getRootElement(); - this.viewUtils.setRootElement( this.viewUtils.getStageElement() ); - // get the plane from the first element to compare against the other elements var flat = true; var plane = this.viewUtils.getElementPlane( eltArray[0] ); - for (var i=1; i 0) || (right > 0)) ? dark : light; context.beginPath(); if ((front > 0) || (right > 0)) { context.beginPath(); -// p = this.viewUtils.localToGlobal( [x1, y0, z1], this._sourceSpaceElt ); context.moveTo( p[0], p[1] ); -// p = this.viewUtils.localToGlobal( [x1, y1, z1], this._sourceSpaceElt ); context.lineTo( p[0], p[1] ); p = this.viewUtils.localToGlobal2( [x1, y0, z1], ssMat ); context.moveTo( p[0], p[1] ); p = this.viewUtils.localToGlobal2( [x1, y1, z1], ssMat ); context.lineTo( p[0], p[1] ); context.closePath(); context.stroke(); @@ -973,8 +937,6 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { //context.strokeStyle = ((right > 0) || (back > 0)) ? dark : light; context.beginPath(); if ((right > 0) || (back > 0)) { context.beginPath(); -// p = this.viewUtils.localToGlobal( [x1, y0, z0], this._sourceSpaceElt ); context.moveTo( p[0], p[1] ); -// p = this.viewUtils.localToGlobal( [x1, y1, z0], this._sourceSpaceElt ); context.lineTo( p[0], p[1] ); p = this.viewUtils.localToGlobal2( [x1, y0, z0], ssMat ); context.moveTo( p[0], p[1] ); p = this.viewUtils.localToGlobal2( [x1, y1, z0], ssMat ); context.lineTo( p[0], p[1] ); context.closePath(); context.stroke(); @@ -983,8 +945,6 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { //context.strokeStyle = ((back > 0) || (left > 0)) ? dark : light; context.beginPath(); if ((back > 0) || (left > 0)) { context.beginPath(); -// p = this.viewUtils.localToGlobal( [x0, y0, z0], this._sourceSpaceElt ); context.moveTo( p[0], p[1] ); -// p = this.viewUtils.localToGlobal( [x0, y1, z0], this._sourceSpaceElt ); context.lineTo( p[0], p[1] ); p = this.viewUtils.localToGlobal2( [x0, y0, z0], ssMat ); context.moveTo( p[0], p[1] ); p = this.viewUtils.localToGlobal2( [x0, y1, z0], ssMat ); context.lineTo( p[0], p[1] ); context.closePath(); context.stroke(); @@ -993,8 +953,6 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { //context.strokeStyle = ((left > 0) || (front > 0)) ? dark : light; context.beginPath(); if ((left > 0) || (front > 0)) { context.beginPath(); -// p = this.viewUtils.localToGlobal( [x0, y0, z1], this._sourceSpaceElt ); context.moveTo( p[0], p[1] ); -// p = this.viewUtils.localToGlobal( [x0, y1, z1], this._sourceSpaceElt ); context.lineTo( p[0], p[1] ); p = this.viewUtils.localToGlobal2( [x0, y0, z1], ssMat ); context.moveTo( p[0], p[1] ); p = this.viewUtils.localToGlobal2( [x0, y1, z1], ssMat ); context.lineTo( p[0], p[1] ); context.closePath(); context.stroke(); @@ -1004,8 +962,6 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { //context.strokeStyle = ((front > 0) || (top > 0)) ? dark : light; context.beginPath(); if ((front > 0) || (top > 0)) { context.beginPath(); -// p = this.viewUtils.localToGlobal( [x0, y0, z1], this._sourceSpaceElt ); context.moveTo( p[0], p[1] ); -// p = this.viewUtils.localToGlobal( [x1, y0, z1], this._sourceSpaceElt ); context.lineTo( p[0], p[1] ); p = this.viewUtils.localToGlobal2( [x0, y0, z1], ssMat ); context.moveTo( p[0], p[1] ); p = this.viewUtils.localToGlobal2( [x1, y0, z1], ssMat ); context.lineTo( p[0], p[1] ); context.closePath(); context.stroke(); @@ -1014,8 +970,6 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { //context.strokeStyle = ((top > 0) || (back > 0)) ? dark : light; context.beginPath(); if ((top > 0) || (back > 0)) { context.beginPath(); -// p = this.viewUtils.localToGlobal( [x0, y0, z0], this._sourceSpaceElt ); context.moveTo( p[0], p[1] ); -// p = this.viewUtils.localToGlobal( [x1, y0, z0], this._sourceSpaceElt ); context.lineTo( p[0], p[1] ); p = this.viewUtils.localToGlobal2( [x0, y0, z0], ssMat ); context.moveTo( p[0], p[1] ); p = this.viewUtils.localToGlobal2( [x1, y0, z0], ssMat ); context.lineTo( p[0], p[1] ); context.closePath(); context.stroke(); @@ -1024,8 +978,6 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { //context.strokeStyle = ((back > 0) || (bottom > 0)) ? dark : light; context.beginPath(); if ((back > 0) || (bottom > 0)) { context.beginPath(); -// p = this.viewUtils.localToGlobal( [x0, y1, z0], this._sourceSpaceElt ); context.moveTo( p[0], p[1] ); -// p = this.viewUtils.localToGlobal( [x1, y1, z0], this._sourceSpaceElt ); context.lineTo( p[0], p[1] ); p = this.viewUtils.localToGlobal2( [x0, y1, z0], ssMat ); context.moveTo( p[0], p[1] ); p = this.viewUtils.localToGlobal2( [x1, y1, z0], ssMat ); context.lineTo( p[0], p[1] ); context.closePath(); context.stroke(); @@ -1034,8 +986,6 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { //context.strokeStyle = ((bottom > 0) || (front > 0)) ? dark : light; context.beginPath(); if ((bottom > 0) || (front > 0)) { context.beginPath(); -// p = this.viewUtils.localToGlobal( [x0, y1, z1], this._sourceSpaceElt ); context.moveTo( p[0], p[1] ); -// p = this.viewUtils.localToGlobal( [x1, y1, z1], this._sourceSpaceElt ); context.lineTo( p[0], p[1] ); p = this.viewUtils.localToGlobal2( [x0, y1, z1], ssMat ); context.moveTo( p[0], p[1] ); p = this.viewUtils.localToGlobal2( [x1, y1, z1], ssMat ); context.lineTo( p[0], p[1] ); context.closePath(); context.stroke(); @@ -1044,8 +994,6 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { // and the remaining lines - varying Z if ((top > 0) || (right > 0)) { context.beginPath(); -// p = this.viewUtils.localToGlobal( [x1, y0, z0], this._sourceSpaceElt ); context.moveTo( p[0], p[1] ); -// p = this.viewUtils.localToGlobal( [x1, y0, z1], this._sourceSpaceElt ); context.lineTo( p[0], p[1] ); p = this.viewUtils.localToGlobal2( [x1, y0, z0], ssMat ); context.moveTo( p[0], p[1] ); p = this.viewUtils.localToGlobal2( [x1, y0, z1], ssMat ); context.lineTo( p[0], p[1] ); context.closePath(); context.stroke(); @@ -1054,8 +1002,6 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { //context.strokeStyle = ((right > 0) || (bottom > 0)) ? dark : light; context.beginPath(); if ((right > 0) || (bottom > 0)) { context.beginPath(); -// p = this.viewUtils.localToGlobal( [x1, y1, z0], this._sourceSpaceElt ); context.moveTo( p[0], p[1] ); -// p = this.viewUtils.localToGlobal( [x1, y1, z1], this._sourceSpaceElt ); context.lineTo( p[0], p[1] ); p = this.viewUtils.localToGlobal2( [x1, y1, z0], ssMat ); context.moveTo( p[0], p[1] ); p = this.viewUtils.localToGlobal2( [x1, y1, z1], ssMat ); context.lineTo( p[0], p[1] ); context.closePath(); context.stroke(); @@ -1064,8 +1010,6 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { //context.strokeStyle = ((bottom > 0) || (left > 0)) ? dark : light; context.beginPath(); if ((bottom > 0) || (left > 0)) { context.beginPath(); -// p = this.viewUtils.localToGlobal( [x0, y1, z0], this._sourceSpaceElt ); context.moveTo( p[0], p[1] ); -// p = this.viewUtils.localToGlobal( [x0, y1, z1], this._sourceSpaceElt ); context.lineTo( p[0], p[1] ); p = this.viewUtils.localToGlobal2( [x0, y1, z0], ssMat ); context.moveTo( p[0], p[1] ); p = this.viewUtils.localToGlobal2( [x0, y1, z1], ssMat ); context.lineTo( p[0], p[1] ); context.closePath(); context.stroke(); @@ -1074,8 +1018,6 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { //context.strokeStyle = ((left > 0) || (top > 0)) ? dark : light; context.beginPath(); if ((left > 0) || (top > 0)) { context.beginPath(); -// p = this.viewUtils.localToGlobal( [x0, y0, z0], this._sourceSpaceElt ); context.moveTo( p[0], p[1] ); -// p = this.viewUtils.localToGlobal( [x0, y0, z1], this._sourceSpaceElt ); context.lineTo( p[0], p[1] ); p = this.viewUtils.localToGlobal2( [x0, y0, z0], ssMat ); context.moveTo( p[0], p[1] ); p = this.viewUtils.localToGlobal2( [x0, y0, z1], ssMat ); context.lineTo( p[0], p[1] ); context.closePath(); context.stroke(); diff --git a/js/helper-classes/3D/math-utils.js b/js/helper-classes/3D/math-utils.js index 562a6e73..2f0283a9 100755 --- a/js/helper-classes/3D/math-utils.js +++ b/js/helper-classes/3D/math-utils.js @@ -729,7 +729,10 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { // the area of the polygon is the length of the normal var area = VecUtils.vecMag(3, normal ); if (this.fpSign(area) != 0) - vec3.scale(normal, 1.0/area); + { + //vec3.scale(normal, 1.0/area); + normal = VecUtils.vecNormalize(3, normal, 1.0); + } return normal; } diff --git a/js/helper-classes/3D/snap-manager.js b/js/helper-classes/3D/snap-manager.js index cf8a91db..1caacd00 100755 --- a/js/helper-classes/3D/snap-manager.js +++ b/js/helper-classes/3D/snap-manager.js @@ -1978,12 +1978,20 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { }, setupDragPlanes : { - value: function( hitRec ) { + value: function( hitRec, inGlobalMode ) { // get the location of the point in stage world space var elt = hitRec.getElt(); var localPt = hitRec.getLocalPoint(); var planeMat = hitRec.getPlaneMatrix(); - var stageWorldPt = viewUtils.postViewToStageWorld( MathUtils.transformPoint(localPt,planeMat), elt ); + var stageWorldPt; + if(inGlobalMode) + { + stageWorldPt = MathUtils.transformPoint(localPt,planeMat); + } + else + { + stageWorldPt = viewUtils.postViewToStageWorld( MathUtils.transformPoint(localPt,planeMat), elt ); + } /* // get a working plane parallel to the current working plane through the stage world point -- cgit v1.2.3