From 9d885aae7a17b4fc731a41f6b1ac8840092b83ac Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Mon, 12 Mar 2012 17:06:05 -0700 Subject: Fixing snapping bugs in Selection, translate and rotate tools. We should show snap marker on mouse move for selection tool prior to mousing down as well. We should create drag plane parallel to the view and where the user moused down. Signed-off-by: Nivesh Rajbhandari --- js/helper-classes/3D/snap-manager.js | 12 ++++++++++-- js/tools/SelectionTool.js | 23 +++++++++++++---------- js/tools/Translate3DToolBase.js | 1 - js/tools/TranslateObject3DTool.js | 2 +- js/tools/modifier-tool-base.js | 12 ++++++------ 5 files changed, 30 insertions(+), 20 deletions(-) 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 diff --git a/js/tools/SelectionTool.js b/js/tools/SelectionTool.js index 6d8ff175..13a04944 100755 --- a/js/tools/SelectionTool.js +++ b/js/tools/SelectionTool.js @@ -16,6 +16,7 @@ var Montage = require("montage/core/core").Montage, var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, { drawingFeedback: { value: { mode: "Draw2D", type: "" } }, + _inLocalMode: { value: false}, // This tool should always use global mode for translations _canOperateOnStage: { value: true}, _isSelecting: {value: false, writable:true}, _shiftMove: { value: 10}, @@ -34,14 +35,12 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, { value: function () { if(this._targets && this._targets.length) { - // TODO - drawUtils's elementPlanes check in drawSelectionBounds doesn't seem to work, - // so temporary workaround to simply check if all elements have identity matrix - // TODO - Eventually, this should instead check if all the selected items are on the view plane var len = this._targets.length; + var plane = this.application.ninja.stage.stageDeps.snapManager.getDragPlane(); for(var i = 0; i < len; i++) { - var mat = this._targets[i].mat; - if(!MathUtils.isIdentityMatrix(mat)) + var elt = this._targets[i].elt; + if(!this.application.ninja.stage.stageDeps.snapManager.elementIsOnPlane(elt, plane)) { return false; } @@ -123,14 +122,14 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, { this.doDraw(event); } else { this._showFeedbackOnMouseMove(event); - // if(this._canSnap) - // { - // this.doSnap(event); - // } + if(this._canSnap) + { + this.doSnap(event); + } } this.DrawHandles(this._delta); - if(this._canSnap && this._isDrawing) + if(this._canSnap) { this.application.ninja.stage.stageDeps.snapManager.drawLastHit(); } @@ -704,6 +703,10 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, { */ _showFeedbackOnMouseMove : { value: function (event) { + if(!this._showTransformHandles) + { + return; + } if(this._target && this._handles) { var len = this._handles.length; diff --git a/js/tools/Translate3DToolBase.js b/js/tools/Translate3DToolBase.js index 3d9191da..24a68ad1 100755 --- a/js/tools/Translate3DToolBase.js +++ b/js/tools/Translate3DToolBase.js @@ -10,7 +10,6 @@ Subclass TranslateObject3DTool will translate the object that was clicked. var Montage = require("montage/core/core").Montage, ModifierToolBase = require("js/tools/modifier-tool-base").ModifierToolBase, toolHandleModule = require("js/stage/tool-handle"), - snapManager = require("js/helper-classes/3D/snap-manager").SnapManager, viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils, vecUtils = require("js/helper-classes/3D/vec-utils").VecUtils, drawUtils = require("js/helper-classes/3D/draw-utils").DrawUtils, diff --git a/js/tools/TranslateObject3DTool.js b/js/tools/TranslateObject3DTool.js index 5157e39c..92b9b2f7 100755 --- a/js/tools/TranslateObject3DTool.js +++ b/js/tools/TranslateObject3DTool.js @@ -103,7 +103,7 @@ exports.TranslateObject3DTool = Object.create(Translate3DToolBase, { } else { - this._dragPlane = snapManager.setupDragPlanes( hitRec ); + this._dragPlane = snapManager.setupDragPlanes( hitRec, true ); } } diff --git a/js/tools/modifier-tool-base.js b/js/tools/modifier-tool-base.js index 7892d015..80f7d758 100755 --- a/js/tools/modifier-tool-base.js +++ b/js/tools/modifier-tool-base.js @@ -171,7 +171,7 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { // } // else // { - this._dragPlane = snapManager.setupDragPlanes( hitRec ); + this._dragPlane = snapManager.setupDragPlanes( hitRec, true ); // } } @@ -828,14 +828,14 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { this.doDraw(event); } else { this._showFeedbackOnMouseMove(event); -// if(this._canSnap) -// { -// this.doSnap(event); -// } + if(this._canSnap) + { + this.doSnap(event); + } } this.DrawHandles(this._delta); - if(this._canSnap && this._isDrawing) + if(this._canSnap) { snapManager.drawLastHit(); } -- cgit v1.2.3 From 90e2f71d730fb4f4ec07b40d2c2569e6c46e8a1c Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Mon, 12 Mar 2012 17:10:19 -0700 Subject: Fixing selection tool when moving multiple selection in 3d mode. Signed-off-by: Nivesh Rajbhandari --- js/tools/SelectionTool.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/js/tools/SelectionTool.js b/js/tools/SelectionTool.js index 13a04944..5f48f74d 100755 --- a/js/tools/SelectionTool.js +++ b/js/tools/SelectionTool.js @@ -451,7 +451,10 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, { if(this._use3DMode) { curMat = item.mat; - glmat4.multiply(curMat, qMat, curMat); + + curMat[12] += transMat[12]; + curMat[13] += transMat[13]; + curMat[14] += transMat[14]; viewUtils.setMatrixForElement( elt, curMat, true); this._targets[i].mat = curMat; } -- cgit v1.2.3 From 44669fc4401eeb8a211b7485d2c20015fc6c477e Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Tue, 13 Mar 2012 15:22:57 -0700 Subject: Fixed drawing of multiple selection bounds when in flat case. Signed-off-by: Nivesh Rajbhandari --- js/helper-classes/3D/draw-utils.js | 136 +++++++++++-------------------------- 1 file changed, 39 insertions(+), 97 deletions(-) diff --git a/js/helper-classes/3D/draw-utils.js b/js/helper-classes/3D/draw-utils.js index 59da411f..1c00f7ea 100755 --- a/js/helper-classes/3D/draw-utils.js +++ b/js/helper-classes/3D/draw-utils.js @@ -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(); -- cgit v1.2.3