From 8423cceac4f45f3d08d92ae969d17d488674717f Mon Sep 17 00:00:00 2001 From: hwc487 Date: Mon, 2 Apr 2012 16:28:09 -0700 Subject: Translate 3D fix for multi-selection Z translation --- js/tools/Translate3DToolBase.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'js/tools') diff --git a/js/tools/Translate3DToolBase.js b/js/tools/Translate3DToolBase.js index 18e2b610..bd2b3af1 100755 --- a/js/tools/Translate3DToolBase.js +++ b/js/tools/Translate3DToolBase.js @@ -147,8 +147,8 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, _translateGlobally: { value: function (transMat) { - //console.log( "_translateGlobally, startMat: " + this._startMat + ", transMat: " + transMat ); //console.log( "_translateGlobally, transMat: " + transMat ); + //console.log( "_translateGlobally, startMat: " + this._startMat + ", transMat: " + transMat ); var len = this._targets.length, i = 0, item, @@ -160,6 +160,7 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, if (this._mode === 1) { + if (len > 1) curMat = this._targets[0].mat.slice(); var curInv = glmat4.inverse( curMat, [] ); transMat = glmat4.multiply( nMat, curInv, [] ); } -- cgit v1.2.3 From b6fa38e2680ccce73f4a195f9adffa552f1d237c Mon Sep 17 00:00:00 2001 From: hwc487 Date: Wed, 4 Apr 2012 12:37:43 -0700 Subject: turned off translation handles during a multi-object drag. --- js/tools/Translate3DToolBase.js | 175 ++++++++++++++++++++-------------------- js/tools/modifier-tool-base.js | 13 ++- 2 files changed, 100 insertions(+), 88 deletions(-) (limited to 'js/tools') diff --git a/js/tools/Translate3DToolBase.js b/js/tools/Translate3DToolBase.js index bd2b3af1..32132c9a 100755 --- a/js/tools/Translate3DToolBase.js +++ b/js/tools/Translate3DToolBase.js @@ -73,13 +73,13 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, var transMat = Matrix.Translation( delta ); - //console.log( "Translate: " + delta ); if(this._inLocalMode && (this._targets.length === 1) ) { this._translateLocally(transMat); } else { + console.log( "modifyElements delta: " + delta ); this._translateGlobally(transMat); } } @@ -147,23 +147,23 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, _translateGlobally: { value: function (transMat) { - //console.log( "_translateGlobally, transMat: " + transMat ); - //console.log( "_translateGlobally, startMat: " + this._startMat + ", transMat: " + transMat ); + //console.log( "_translateGlobally, transMat: " + transMat ); + //console.log( "_translateGlobally, startMat: " + this._startMat + ", transMat: " + transMat ); var len = this._targets.length, i = 0, item, elt, curMat = viewUtils.getMatrixFromElement( this._target ), - matInv = glmat4.inverse(this._startMat, []), - nMat = glmat4.multiply(transMat, this._startMat, [] ), - qMat = glmat4.multiply(matInv, nMat, []); - - if (this._mode === 1) - { - if (len > 1) curMat = this._targets[0].mat.slice(); - var curInv = glmat4.inverse( curMat, [] ); - transMat = glmat4.multiply( nMat, curInv, [] ); - } + matInv = glmat4.inverse(this._startMat, []), + nMat = glmat4.multiply(transMat, this._startMat, [] ), + qMat = glmat4.multiply(matInv, nMat, []); + + if (this._mode === 1) + { + if (len > 1) curMat = this._targets[0].mat.slice(); + var curInv = glmat4.inverse( curMat, [] ); + transMat = glmat4.multiply( nMat, curInv, [] ); + } var shouldUpdateStartMat = true; @@ -185,27 +185,27 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, // glmat4.multiply(curMat, qMat, curMat); // // viewUtils.setMatrixForElement( elt, curMat, true); - curMat[12] += transMat[12]; - curMat[13] += transMat[13]; - curMat[14] += transMat[14]; - viewUtils.setMatrixForElement( elt, curMat, true); + curMat[12] += transMat[12]; + curMat[13] += transMat[13]; + curMat[14] += transMat[14]; + viewUtils.setMatrixForElement( elt, curMat, true); if(shouldUpdateStartMat) { - //console.log( "\t\tshouldUpdateStartMat" ); + //console.log( "\t\tshouldUpdateStartMat" ); this._targets[i].mat = curMat; } } } }, - _updateTargets: { + _updateTargets: { value: function(addToUndoStack) - { - console.log( "_updateTargets" ); - var newStyles = [], - previousStyles = [], - len = this.application.ninja.selectedElements.length; + { + //console.log( "_updateTargets" ); + var newStyles = [], + previousStyles = [], + len = this.application.ninja.selectedElements.length; this._targets = []; for(var i = 0; i < len; i++) { @@ -215,47 +215,47 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, var curMatInv = glmat4.inverse(curMat, []); this._targets.push({elt:elt, mat:curMat, matInv:curMatInv}); - if(addToUndoStack) - { - var previousStyleStr = {dist:this._undoArray[i].dist, mat:MathUtils.scientificToDecimal(this._undoArray[i].mat.slice(0), 5)}; + if(addToUndoStack) + { + var previousStyleStr = {dist:this._undoArray[i].dist, mat:MathUtils.scientificToDecimal(this._undoArray[i].mat.slice(0), 5)}; - var newStyleStr = {dist:viewUtils.getPerspectiveDistFromElement(elt), mat:MathUtils.scientificToDecimal(curMat, 5)}; + var newStyleStr = {dist:viewUtils.getPerspectiveDistFromElement(elt), mat:MathUtils.scientificToDecimal(curMat, 5)}; - previousStyles.push(previousStyleStr); - newStyles.push(newStyleStr); - } + previousStyles.push(previousStyleStr); + newStyles.push(newStyleStr); + } } if(addToUndoStack) { - ElementsMediator.set3DProperties(this.application.ninja.selectedElements, - newStyles, - "Change", - "translateTool", - previousStyles - ); - if(this._origin && this._delta) - { - if(this._handleMode !== null) - { - this._origin[this._handleMode] += this._delta; - } - else - { - this._origin[0] += this._delta[0]; - this._origin[1] += this._delta[1]; - } - } - this._delta = null; - } - // Save previous value for undo/redo - this._undoArray = []; - for(i = 0, len = this._targets.length; i < len; i++) - { - var elt = this._targets[i].elt; - var _mat = viewUtils.getMatrixFromElement(elt); - var _dist = viewUtils.getPerspectiveDistFromElement(elt); - this._undoArray.push({mat:_mat, dist:_dist}); - } + ElementsMediator.set3DProperties(this.application.ninja.selectedElements, + newStyles, + "Change", + "translateTool", + previousStyles + ); + if(this._origin && this._delta) + { + if(this._handleMode !== null) + { + this._origin[this._handleMode] += this._delta; + } + else + { + this._origin[0] += this._delta[0]; + this._origin[1] += this._delta[1]; + } + } + this._delta = null; + } + // Save previous value for undo/redo + this._undoArray = []; + for(i = 0, len = this._targets.length; i < len; i++) + { + var elt = this._targets[i].elt; + var _mat = viewUtils.getMatrixFromElement(elt); + var _dist = viewUtils.getPerspectiveDistFromElement(elt); + this._undoArray.push({mat:_mat, dist:_dist}); + } } }, @@ -305,27 +305,27 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, } else { - if(this._origin) - { - if(this._delta) - { - if(this._handleMode !== null) - { + if(this._origin) + { + if(this._delta) + { + if(this._handleMode !== null) + { // this._origin[this._handleMode] = this._delta; - } - else - { - this._origin[0] += this._delta[0]; - this._origin[1] += this._delta[1]; - } - } - } - else - { - this._origin = drawUtils._selectionCtr.slice(0); - this._origin[0] += this.application.ninja.stage.userContentLeft; - this._origin[1] += this.application.ninja.stage.userContentTop; - } + } + else + { + this._origin[0] += this._delta[0]; + this._origin[1] += this._delta[1]; + } + } + } + else + { + this._origin = drawUtils._selectionCtr.slice(0); + this._origin[0] += this.application.ninja.stage.userContentLeft; + this._origin[1] += this.application.ninja.stage.userContentTop; + } } } } @@ -364,10 +364,13 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, } // Draw tool handles - - this._updateHandlesOrigin(); + + this._updateHandlesOrigin(); var base = this._origin.slice(0); +// if (this.isDrawing) +// console.log( "handle origin: " + base ); + var len = this.application.ninja.selectedElements.length; var lMode = this._inLocalMode; if(len === 1) @@ -397,10 +400,10 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, this._handles[1]._strokeStyle = 'rgba(0, 255, 0, 0.2)'; break; } - if( delta && (len > 1) ) - { - base[this._handleMode] += ~~delta; - } + if( delta && (len > 1) ) + { + base[this._handleMode] += ~~delta; + } } this._handles[0].draw(base, item, lMode); this._handles[1].draw(base, item, lMode); diff --git a/js/tools/modifier-tool-base.js b/js/tools/modifier-tool-base.js index 07b28747..e684f58a 100755 --- a/js/tools/modifier-tool-base.js +++ b/js/tools/modifier-tool-base.js @@ -852,8 +852,10 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { } } - this.DrawHandles(this._delta); - if(this._canSnap) + if (!this._isDrawing || (this.application.ninja.selectedElements.length == 1)) + this.DrawHandles(this._delta); + + if(this._canSnap) { snapManager.drawLastHit(); } @@ -892,6 +894,13 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { this._delta = null; } this.endDraw(event); + + this.application.ninja.stage.draw(); + if (this._targets && (this._targets.length > 1)) + { + this._origin = null; + this._updateHandlesOrigin(); + } this.DrawHandles(); } }, -- cgit v1.2.3 From 16f62ca09cc428043e8fef8bdeea11a989e62bc0 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Wed, 4 Apr 2012 16:29:16 -0700 Subject: Cap fix for vecUtils. --- js/tools/TranslateObject3DTool.js | 3 ++- js/tools/modifier-tool-base.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'js/tools') diff --git a/js/tools/TranslateObject3DTool.js b/js/tools/TranslateObject3DTool.js index 7163f005..867bec7f 100755 --- a/js/tools/TranslateObject3DTool.js +++ b/js/tools/TranslateObject3DTool.js @@ -7,6 +7,7 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot var Translate3DToolBase = require("js/tools/Translate3DToolBase").Translate3DToolBase, drawUtils = require("js/helper-classes/3D/draw-utils").DrawUtils, viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils, + vecUtils = require("js/helper-classes/3D/vec-utils").VecUtils, snapManager = require("js/helper-classes/3D/snap-manager").SnapManager; exports.TranslateObject3DTool = Object.create(Translate3DToolBase, { @@ -128,7 +129,7 @@ exports.TranslateObject3DTool = Object.create(Translate3DToolBase, { // only do quadrant snapping if the 4 corners of the element are in the drag plane - var sign = MathUtils.fpSign( VecUtils.vecDot(3,this._dragPlane,[0,0,1]) + this._dragPlane[3] - 1.0); + var sign = MathUtils.fpSign( vecUtils.vecDot(3,this._dragPlane,[0,0,1]) + this._dragPlane[3] - 1.0); this._shouldUseQuadPt = (sign == 0); var wpHitRec = hitRec.convertToWorkingPlane( this._dragPlane ); diff --git a/js/tools/modifier-tool-base.js b/js/tools/modifier-tool-base.js index e684f58a..b6589cba 100755 --- a/js/tools/modifier-tool-base.js +++ b/js/tools/modifier-tool-base.js @@ -177,7 +177,7 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { } // only do quadrant snapping if the 4 corners of the element are in the drag plane - var sign = MathUtils.fpSign( VecUtils.vecDot(3,this._dragPlane,[0,0,1]) + this._dragPlane[3] - 1.0); + var sign = MathUtils.fpSign( vecUtils.vecDot(3,this._dragPlane,[0,0,1]) + this._dragPlane[3] - 1.0); this._shouldUseQuadPt = (sign == 0) var wpHitRec = hitRec.convertToWorkingPlane( this._dragPlane ); -- cgit v1.2.3 From 96bfeee2e6b735b87e8482d6e2cf24d5224c6417 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Thu, 5 Apr 2012 17:03:14 -0700 Subject: translate3DObject tool fixes. --- js/tools/Translate3DToolBase.js | 7 ++++--- js/tools/modifier-tool-base.js | 2 ++ 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'js/tools') diff --git a/js/tools/Translate3DToolBase.js b/js/tools/Translate3DToolBase.js index 4799b840..2276178c 100755 --- a/js/tools/Translate3DToolBase.js +++ b/js/tools/Translate3DToolBase.js @@ -71,6 +71,7 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, this._delta = delta.slice(0); } + //console.log( "modifyElements delta: " + delta ); var transMat = Matrix.Translation( delta ); if(this._inLocalMode && (this._targets.length === 1) ) @@ -79,7 +80,6 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, } else { - console.log( "modifyElements delta: " + delta ); this._translateGlobally(transMat); } } @@ -148,7 +148,7 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, _translateGlobally: { value: function (transMat) { //console.log( "_translateGlobally, transMat: " + transMat ); - //console.log( "_translateGlobally, startMat: " + this._startMat + ", transMat: " + transMat ); + //console.log( "_translateGlobally, startMat: " + this._startMat + ", transMat: " + transMat[12] + ", " + transMat[13] + ", " + transMat[14] ); var len = this._targets.length, i = 0, item, @@ -167,7 +167,8 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, var shouldUpdateStartMat = true; - if(this._clickedOnStage) + //if (this._clickedOnStage) + if(this._clickedOnStage || ((this._handleMode === 2) && (this._targets.length > 1))) { shouldUpdateStartMat = false; } diff --git a/js/tools/modifier-tool-base.js b/js/tools/modifier-tool-base.js index 2c9b484e..f9fd001c 100755 --- a/js/tools/modifier-tool-base.js +++ b/js/tools/modifier-tool-base.js @@ -405,6 +405,7 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { var index = this._snapIndex; var pt0; var useViewPoint = (this._inLocalMode && (this._targets.length === 1)); + //console.log( "useViewPoint: " + useViewPoint ); if (this._useQuadPt) { pt0 = this.GetQuadrantPoint(useViewPoint); @@ -427,6 +428,7 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { pt1 = MathUtils.transformPoint( pt1, this._startMat ); } + //console.log( "getMousePoints, useViewPoint: " + useViewPoint + ", " + pt0 + " => " + pt1 ); return {pt0:pt0, pt1:pt1}; } else -- cgit v1.2.3 From f522ce09d98bbb2812ed25bb942597d854d71a1c Mon Sep 17 00:00:00 2001 From: hwc487 Date: Wed, 11 Apr 2012 16:01:33 -0700 Subject: Rotate3D tool changes --- js/tools/Rotate3DToolBase.js | 38 ++++++++++- js/tools/RotateObject3DTool.js | 141 ++++++++++++++++++++++++++++++++++++++++- js/tools/modifier-tool-base.js | 1 + 3 files changed, 178 insertions(+), 2 deletions(-) (limited to 'js/tools') diff --git a/js/tools/Rotate3DToolBase.js b/js/tools/Rotate3DToolBase.js index eb2cdba4..e0c5abcb 100755 --- a/js/tools/Rotate3DToolBase.js +++ b/js/tools/Rotate3DToolBase.js @@ -56,17 +56,23 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { // move the transform origin handle var dx = pt1.x - pt0.x; var dy = pt1.y - pt0.y; + var dz = pt1.z - pt0.z; + this._origin[0] += dx; this._origin[1] += dy; + this._origin[2] += dz; var len = this._targets.length; if(len === 1) { this._startOriginArray[0][0] += dx; this._startOriginArray[0][1] += dy; + this._startOriginArray[0][2] += dz; + console.log( "Rotate3DToolBase.modifyElements, _startOriginArray[0]: " + this._startOriginArray[0] ); } this.downPoint.x = pt1.x; this.downPoint.y = pt1.y; + this.downPoint.z = pt1.z; this.DrawHandles(); return; } @@ -159,8 +165,23 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { // pre-translate by the transformation center var tMat = Matrix.I(4); + // _startOriginArray is the location of the center of rotation + // in view space of the element. It is currently calculated during the drag + // using delta's in global screen space, hence wrong. + // We can put the transformCenter back in element view space here, however + // it would be (much) more efficient to cache the localToGlobal and + // globalToLocal matrices. var transformCtr = this._startOriginArray[i]; + var localToGlobalMat = viewUtils.getLocalToGlobalMatrix( elt ); + var globalToLocalMat = glmat4.inverse( localToGlobalMat, [] ); + var newTransformCtr = MathUtils.transformAndDivideHomogeneousPoint( this._origin, globalToLocalMat ); + viewUtils.pushViewportObj( elt ); + newTransformCtr = viewUtils.screenToView( newTransformCtr[0], newTransformCtr[1], newTransformCtr[2] ); + viewUtils.popViewportObj( elt ); + //console.log( "transformCtr: " + newTransformCtr ); + transformCtr = newTransformCtr; + tMat[12] = transformCtr[0]; tMat[13] = transformCtr[1]; tMat[14] = transformCtr[2]; @@ -267,6 +288,7 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { viewUtils.pushViewportObj( this.target ); var eltCtr = viewUtils.getCenterOfProjection(); + eltCtr[2] = 0; viewUtils.popViewportObj(); var ctrOffset = this.target.elementModel.props3D.m_transformCtr; @@ -277,6 +299,7 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { } this._origin = viewUtils.localToGlobal(eltCtr, this.target); + console.log( "Rotate3DToolBase.captureSelectionDrawn _origin: " + this._origin ); this._updateTargets(); this._setTransformOrigin(false); } @@ -533,6 +556,7 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { */ _showFeedbackOnMouseMove : { value: function (event) { + this._canSnap = false; if(this._target && this._handles) { var len = this._handles.length; @@ -550,7 +574,8 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { this.application.ninja.stage.drawingCanvas.style.cursor = "move"; this._handleMode = i; this._activateOriginHandle = true; - return; + this._canSnap = true; + return; } else if(c === 2) { @@ -569,6 +594,16 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { } }, + getMousePoints: { + value: function() + { + var pt0 = { x:this.downPoint.x, y:this.downPoint.y, z:this.downPoint.z }; + var pt1 = { x:this.upPoint.x, y:this.upPoint.y, z:this.upPoint.z }; + + return {pt0:pt0, pt1:pt1}; + } + }, + DrawHandles: { value: function (angle) { this.application.ninja.stage.clearDrawingCanvas(); @@ -594,6 +629,7 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { viewUtils.pushViewportObj( this.application.ninja.currentDocument.documentRoot ); } var base = this._origin; + //console.log( "Rotate3DToolBase.DrawHandles, base: " + base ); if( (this._handleMode !== null) && !this._activateOriginHandle ) { diff --git a/js/tools/RotateObject3DTool.js b/js/tools/RotateObject3DTool.js index 72af6eff..7b4ec083 100755 --- a/js/tools/RotateObject3DTool.js +++ b/js/tools/RotateObject3DTool.js @@ -4,7 +4,9 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. */ -var Montage = require("montage/core/core").Montage; +var Montage = require("montage/core/core").Montage, + viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils, + snapManager = require("js/helper-classes/3D/snap-manager").SnapManager; var Rotate3DToolBase = require("js/tools/Rotate3DToolBase").Rotate3DToolBase; var toolHandleModule = require("js/stage/tool-handle"); @@ -54,6 +56,143 @@ exports.RotateObject3DTool = Montage.create(Rotate3DToolBase, { } }, + initializeSnapping : { + value : function(event) + { + console.log( "initializeSnapping" ); + + this._mouseDownHitRec = null; + this._mouseUpHitRec = null; + + snapManager.clearAvoidList(); + snapManager.clearDragPlane(); + + // the translate tool does snap align to the bounds of the object only. + // turn off snap align to the cursor. This needs to be re-enabled in the mouse up method + snapManager.enableSnapAlign( false ); + + // snap to element and snap to grid are conditionally enabled based + // on the snap results of the mouse down. enable everything for the first snap + this._snapToElements = snapManager.elementSnapEnabledAppLevel(); + this._snapToGrid = snapManager.gridSnapEnabledAppLevel(); + + this._dragPlane = null; + this._clickedOnStage = false; + var do3DSnap = true; + + if(this._handleMode === null) + { + snapManager.enableElementSnap ( true ); + snapManager.enableGridSnap ( true ); + } +// else +// { +// this._delta = null; + // special case for z-translation +// if(this._handleMode === 0) +// { +// this._dragPlane = viewUtils.getNormalToUnprojectedElementPlane(this._target); +// snapManager.setupDragPlaneFromPlane(this._dragPlane); +// do3DSnap = false; + +// snapManager.enableElementSnap ( false ); +// snapManager.enableGridSnap ( false ); +// } +// } + + if (this._targets) + { + var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, + new WebKitPoint(event.pageX, event.pageY)); + + // do the snap before setting up the avoid list to allow + // a snap on the mouse down + var hitRec = snapManager.snap(point.x, point.y, do3DSnap); + +// if(this._handleMode === 2) +// { +// // translate z doesn't snap to element so hitRec's element will always be different +// // from what the browser says we clicked on. So, skip this check. +// } +// else +// { +// // Check that hitRec's element matches element that browser says we clicked on +// // TODO - This is still not working when using a handle that is on top of an +// // element that is not currently selected +// var elt = this.application.ninja.stage.GetSelectableElement(event); +// if(elt && (elt !== hitRec.getElement())) +// { +// hitRec = snapManager.findHitRecordForElement(elt); +// } +// if(elt === this.application.ninja.currentSelectedContainer) +// { +// this._clickedOnStage = true; +// } +// } + + // we don't want to snap to selected objects during the drag +// var len = this._targets.length; +// for(var i=0; i 1)) { - this._origin = null; + //this._origin = null; this._updateHandlesOrigin(); } this.DrawHandles(); } }, + _updateHandlesOrigin: { + value: function () { } + }, + handleToolDoubleClick: { value: function(event) { if(!this._target) -- cgit v1.2.3 From 642d7b45446894a2f3038dcc07a867b260968256 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Fri, 13 Apr 2012 13:48:07 -0700 Subject: 3D rotation --- js/tools/Rotate3DToolBase.js | 19 ++++++++----------- js/tools/Translate3DToolBase.js | 5 ----- 2 files changed, 8 insertions(+), 16 deletions(-) (limited to 'js/tools') diff --git a/js/tools/Rotate3DToolBase.js b/js/tools/Rotate3DToolBase.js index e65dc842..880eefc4 100755 --- a/js/tools/Rotate3DToolBase.js +++ b/js/tools/Rotate3DToolBase.js @@ -54,22 +54,19 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { { if(this._activateOriginHandle) { - // move the transform origin handle - var dx = pt1.x - pt0.x; - var dy = pt1.y - pt0.y; - var dz = pt1.z - pt0.z; + // move the transform origin handle directly to the snap point (pt1) + this._origin[0] = pt1.x; + this._origin[1] = pt1.y; + this._origin[2] = pt1.z; - this._origin[0] += dx; - this._origin[1] += dy; - this._origin[2] += dz; - console.log( "modifyElements, _origin: " + this._origin ); + var sw2gMat = viewUtils.getStageWorldToGlobalMatrix(); + var g2swMat = glmat4.inverse( sw2gMat, [] ); + var swOrigin = MathUtils.transformAndDivideHomogeneousPoint( this._origin, g2swMat ); + //console.log( "modifyElements, _origin: " + this._origin + ", in stageWorld: " + swOrigin ); var len = this._targets.length; if(len === 1) { -// this._startOriginArray[0][0] += dx; -// this._startOriginArray[0][1] += dy; -// this._startOriginArray[0][2] += dz; var g2lMat = this._targets[0].g2l; var localOrigin = MathUtils.transformAndDivideHomogeneousPoint( this._origin, g2lMat ); var elt = this._targets[0].elt; diff --git a/js/tools/Translate3DToolBase.js b/js/tools/Translate3DToolBase.js index ac98d018..a39dafad 100755 --- a/js/tools/Translate3DToolBase.js +++ b/js/tools/Translate3DToolBase.js @@ -204,11 +204,6 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, _updateTargets: { value: function(addToUndoStack) { - { - { -// console.log( "_updateTargets" ); - console.log( "_updateTargets" ); - //console.log( "_updateTargets" ); var newStyles = [], previousStyles = [], len = this.application.ninja.selectedElements.length; -- cgit v1.2.3 From a62cfc5976b03a9b6c7ee2f308312319b6b0e142 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Mon, 16 Apr 2012 10:34:14 -0700 Subject: 3D translation fixes --- js/tools/Rotate3DToolBase.js | 27 ++++++++++ js/tools/Translate3DToolBase.js | 115 ++++++++++++++++++++++++++++++++-------- 2 files changed, 120 insertions(+), 22 deletions(-) (limited to 'js/tools') diff --git a/js/tools/Rotate3DToolBase.js b/js/tools/Rotate3DToolBase.js index 880eefc4..d08b3a31 100755 --- a/js/tools/Rotate3DToolBase.js +++ b/js/tools/Rotate3DToolBase.js @@ -43,6 +43,33 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { } }, + HandleMouseMove: { + value: function(event) { + if(this._escape) { + this._escape = false; + this.isDrawing = true; + } + + if(this.isDrawing) { + this._hasDraw = true; // Flag for position of element + this.doDraw(event); + } else { + this._showFeedbackOnMouseMove(event); + if(this._canSnap) + { + this.doSnap(event); + } + } + + this.DrawHandles(this._delta); + + if(this._canSnap) + { + snapManager.drawLastHit(); + } + } + }, + modifyElements: { value: function(data, event) { var mat, diff --git a/js/tools/Translate3DToolBase.js b/js/tools/Translate3DToolBase.js index a39dafad..41dbb3ae 100755 --- a/js/tools/Translate3DToolBase.js +++ b/js/tools/Translate3DToolBase.js @@ -296,42 +296,113 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, viewUtils.popViewportObj(); ctr[2] = 0; -// var ctrOffset = item.elementModel.props3D.m_transformCtr; -// if(ctrOffset) -// { -// ctr = vecUtils.vecAdd(3, ctr, ctrOffset); -// } - this._origin = viewUtils.localToGlobal(ctr, item); } else { - if(this._origin) + this._origin = undefined; + this._origin = this.calculateMultiSelOrigin(); + } + } + } + }, + + captureSelectionDrawn: { + value: function(event){ + this._origin = null; + this._targets = []; + this._startOriginArray = null; + + var len = this.application.ninja.selectedElements.length; + if(len) + { + if(len === 1) + { + this.target = this.application.ninja.selectedElements[0]; + drawUtils.addElement(this.target); + + viewUtils.pushViewportObj( this.target ); + var eltCtr = viewUtils.getCenterOfProjection(); + eltCtr[2] = 0; + viewUtils.popViewportObj(); + + var ctrOffset = this.target.elementModel.props3D.m_transformCtr; + if(ctrOffset) + { + eltCtr[2] = 0; + eltCtr = vecUtils.vecAdd(3, eltCtr, ctrOffset); + } + + this._origin = viewUtils.localToGlobal(eltCtr, this.target); + console.log( "Rotate3DToolBase.captureSelectionDrawn _origin: " + this._origin ); + this._updateTargets(); + //this._setTransformOrigin(false); + } + else + { + this.target = this.application.ninja.currentDocument.documentRoot; + //this._origin = drawUtils._selectionCtr.slice(0); + //this._origin[0] += this.application.ninja.stage.userContentLeft; + //this._origin[1] += this.application.ninja.stage.userContentTop; + this._updateTargets(); + this._origin = this.calculateMultiSelOrigin(); + //this._setTransformOrigin(true); + } + } + else + { + this.target = null; + } + this.DrawHandles(); + + if(event) + { + this.eventManager.removeEventListener("selectionDrawn", this, true); + } + } + }, + + calculateMultiSelOrigin: + { + value: function() + { + var minPt, maxPt, i,j; + this._startOriginArray = []; + var len = this.application.ninja.selectedElements.length; + for (i = 0; i < len; i++) + { + // get the next element and localToGlobal matrix + elt = this._targets[i].elt; + var l2g = this._targets[i].l2g; + + // get the element bounds in 'plane' space + bounds = viewUtils.getElementViewBounds3D( elt ); + for (j=0; j<4; j++) + { + var localPt = bounds[j]; + //var pt = MathUtils.transformAndDivideHomogeneousPoint( localPt, l2g ); + var pt = viewUtils.localToStageWorld( localPt, elt ); + if (!minPt) { - if(this._delta) - { - if(this._handleMode !== null) - { -// this._origin[this._handleMode] = this._delta; - } - else - { - this._origin[0] += this._delta[0]; - this._origin[1] += this._delta[1]; - } - } + minPt = pt.slice(); + maxPt = pt.slice(); } else { - this._origin = drawUtils._selectionCtr.slice(0); - this._origin[0] += this.application.ninja.stage.userContentLeft; - this._origin[1] += this.application.ninja.stage.userContentTop; + minPt[0] = Math.min(minPt[0],pt[0]); minPt[1] = Math.min(minPt[1],pt[1]); minPt[2] = Math.min(minPt[2],pt[2]); + maxPt[0] = Math.max(maxPt[0],pt[0]); maxPt[1] = Math.max(maxPt[1],pt[1]); maxPt[2] = Math.max(maxPt[2],pt[2]); } } } + var stageWorldCtr = [ 0.5*(minPt[0] + maxPt[0]), 0.5*(minPt[1] + maxPt[1]), 0.5*(minPt[2] + maxPt[2]) ]; + var globalCtr = MathUtils.transformAndDivideHomogeneousPoint( stageWorldCtr, viewUtils.getStageWorldToGlobalMatrix() ); + console.log( "resetting _origin to: " + this._origin ); + + return globalCtr; } }, + DrawHandles: { value: function (delta) { this.application.ninja.stage.clearDrawingCanvas(); -- cgit v1.2.3 From 19115d65a309ccbeab8e07d426ac398dae8a9d68 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Mon, 16 Apr 2012 13:10:27 -0700 Subject: snapping for stage rotation tool --- js/tools/RotateStage3DTool.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'js/tools') diff --git a/js/tools/RotateStage3DTool.js b/js/tools/RotateStage3DTool.js index f5cc4040..c0808de3 100755 --- a/js/tools/RotateStage3DTool.js +++ b/js/tools/RotateStage3DTool.js @@ -72,9 +72,11 @@ exports.RotateStage3DTool = Montage.create(Rotate3DToolBase, { var eltCtr = viewUtils.getCenterOfProjection(); viewUtils.popViewportObj(); - eltCtr = viewUtils.localToGlobal(eltCtr, elt); - - this._targets.push({elt:elt, mat:curMat, matInv:curMatInv, ctr:eltCtr}); + // cache the local to global and global to local matrices + var l2gMat = viewUtils.getLocalToGlobalMatrix( elt ); + var g2lMat = glmat4.inverse( l2gMat, [] ); + eltCtr = MathUtils.transformAndDivideHomogeneousPoint( eltCtr, l2gMat ); + this._targets.push({elt:elt, mat:curMat, matInv:curMatInv, ctr:eltCtr, l2g:l2gMat, g2l:g2lMat}); ElementsMediator.setMatrix(elt, curMat, false, "rotateStage3DTool"); } -- cgit v1.2.3 From 7b3ef287f248c07602aefa3ba2cc907e0d16493a Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Wed, 18 Apr 2012 13:42:18 -0700 Subject: Fixing some more merge issues. Signed-off-by: Nivesh Rajbhandari --- js/tools/Rotate3DToolBase.js | 31 +++++++++++++++++++------------ js/tools/RotateObject3DTool.js | 11 ++++++++--- js/tools/Translate3DToolBase.js | 21 +++++++++------------ 3 files changed, 36 insertions(+), 27 deletions(-) (limited to 'js/tools') diff --git a/js/tools/Rotate3DToolBase.js b/js/tools/Rotate3DToolBase.js index 6bd92353..04bdc946 100755 --- a/js/tools/Rotate3DToolBase.js +++ b/js/tools/Rotate3DToolBase.js @@ -80,6 +80,11 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { pt0 = data.pt0, pt1 = data.pt1; + var selectedElements = this.application.ninja.selectedElements; + if(this.rotateStage) { + selectedElements = [this.application.ninja.currentDocument.documentRoot]; + } + if(this._handleMode !== null) { if(this._activateOriginHandle) @@ -94,12 +99,13 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { var swOrigin = MathUtils.transformAndDivideHomogeneousPoint( this._origin, g2swMat ); //console.log( "modifyElements, _origin: " + this._origin + ", in stageWorld: " + swOrigin ); - var len = this._targets.length; + var len = selectedElements.length; if(len === 1) { - var g2lMat = this._targets[0].g2l; + var elt = selectedElements[0]; + var g2lMat = elt.elementModel.getProperty("g2l"); var localOrigin = MathUtils.transformAndDivideHomogeneousPoint( this._origin, g2lMat ); - var elt = this._targets[0].elt; + viewUtils.pushViewportObj( elt ); var viewOrigin = viewUtils.screenToView( localOrigin[0], localOrigin[1], localOrigin[2] ); viewUtils.popViewportObj(); @@ -178,7 +184,7 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { if(this._inLocalMode && (this.application.ninja.selectedElements.length === 1 || this.rotateStage) ) { - console.log( "modifyElements: rotateLocally " ); +// console.log( "modifyElements: rotateLocally " ); this._rotateLocally(mat); } else @@ -245,7 +251,7 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { var transformCtr = this._startOriginArray[i].slice(0); transformCtr = MathUtils.transformPoint(transformCtr, curMat); - console.log( "modifyElements: rotateGlobally, ctr: " + transformCtr ); +// console.log( "modifyElements: rotateGlobally, ctr: " + transformCtr ); tMat[12] = transformCtr[0]; tMat[13] = transformCtr[1]; @@ -366,15 +372,15 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { self = this; this.application.ninja.selectedElements.forEach(function(element) { - var curMat = viewUtils.getMatrixFromElement(elt); + var curMat = viewUtils.getMatrixFromElement(element); var curMatInv = glmat4.inverse(curMat, []); - viewUtils.pushViewportObj( elt ); + viewUtils.pushViewportObj( element ); var eltCtr = viewUtils.getCenterOfProjection(); viewUtils.popViewportObj(); // cache the local to global and global to local matrices - var l2gMat = viewUtils.getLocalToGlobalMatrix( elt ); + var l2gMat = viewUtils.getLocalToGlobalMatrix( element ); var g2lMat = glmat4.inverse( l2gMat, [] ); eltCtr = MathUtils.transformAndDivideHomogeneousPoint( eltCtr, l2gMat ); @@ -416,11 +422,11 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { for (i = 0; i < len; i++) { // get the next element and localToGlobal matrix - elt = this.application.ninja.selectedElements[i]; + var elt = this.application.ninja.selectedElements[i]; var l2g = elt.elementModel.getProperty("l2g"); // get the element bounds in 'plane' space - bounds = viewUtils.getElementViewBounds3D( elt ); + var bounds = viewUtils.getElementViewBounds3D( elt ); for (j=0; j<4; j++) { var localPt = bounds[j]; @@ -440,7 +446,7 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { } var stageWorldCtr = [ 0.5*(minPt[0] + maxPt[0]), 0.5*(minPt[1] + maxPt[1]), 0.5*(minPt[2] + maxPt[2]) ]; var globalCtr = MathUtils.transformAndDivideHomogeneousPoint( stageWorldCtr, viewUtils.getStageWorldToGlobalMatrix() ); - console.log( "resetting _origin to: " + this._origin ); +// console.log( "resetting _origin to: " + this._origin ); return globalCtr; } @@ -498,7 +504,8 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { // Update transform ctr for all elements if transform origin was modified if (!this._origin) this._origin = this.calculateMultiSelOrigin(); var globalCtr = this._origin; - for (i=0; i 1))) + if(this._clickedOnStage || ((this._handleMode === 2) && (len > 1))) { shouldUpdateStartMat = false; } @@ -166,7 +164,7 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, this._startMat = nMat; } - this.application.ninja.selectedElements.forEach(function(element) { + selectedElements.forEach(function(element) { curMat = element.elementModel.getProperty("mat").slice(0); // glmat4.multiply(curMat, qMat, curMat); @@ -273,7 +271,6 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, captureSelectionDrawn: { value: function(event){ this._origin = null; - this._targets = []; this._startOriginArray = null; var len = this.application.ninja.selectedElements.length; @@ -294,7 +291,7 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, } this._origin = viewUtils.localToGlobal(eltCtr, this.target); - console.log( "Rotate3DToolBase.captureSelectionDrawn _origin: " + this._origin ); +// console.log( "Rotate3DToolBase.captureSelectionDrawn _origin: " + this._origin ); this._updateTargets(); //this._setTransformOrigin(false); } @@ -330,11 +327,11 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, for (i = 0; i < len; i++) { // get the next element and localToGlobal matrix - elt = this._targets[i].elt; - var l2g = this._targets[i].l2g; + var elt = this.application.ninja.selectedElements[i]; + var l2g = elt.elementModel.getProperty("l2g"); // get the element bounds in 'plane' space - bounds = viewUtils.getElementViewBounds3D( elt ); + var bounds = viewUtils.getElementViewBounds3D( elt ); for (j=0; j<4; j++) { var localPt = bounds[j]; @@ -354,7 +351,7 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, } var stageWorldCtr = [ 0.5*(minPt[0] + maxPt[0]), 0.5*(minPt[1] + maxPt[1]), 0.5*(minPt[2] + maxPt[2]) ]; var globalCtr = MathUtils.transformAndDivideHomogeneousPoint( stageWorldCtr, viewUtils.getStageWorldToGlobalMatrix() ); - console.log( "resetting _origin to: " + this._origin ); +// console.log( "resetting _origin to: " + this._origin ); return globalCtr; } -- cgit v1.2.3 From 1f2d84716ddca3cfc9e5457f67ec1b007b3455a8 Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Wed, 18 Apr 2012 15:48:20 -0700 Subject: Moving initialzeSnapping routine from RotateObject3DTool tool to Rotate3DToolBase so Rotate Stage uses the same code. Signed-off-by: Nivesh Rajbhandari --- js/tools/Rotate3DToolBase.js | 143 +++++++++++++++++++++++++++++++++++++++++ js/tools/RotateObject3DTool.js | 142 ---------------------------------------- 2 files changed, 143 insertions(+), 142 deletions(-) (limited to 'js/tools') diff --git a/js/tools/Rotate3DToolBase.js b/js/tools/Rotate3DToolBase.js index 04bdc946..4fa8657e 100755 --- a/js/tools/Rotate3DToolBase.js +++ b/js/tools/Rotate3DToolBase.js @@ -25,6 +25,149 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { value: false }, + initializeSnapping : { + value : function(event) + { +// console.log( "initializeSnapping" ); + + var selectedElements = this.application.ninja.selectedElements; + if(this.rotateStage) { + selectedElements = [this.application.ninja.currentDocument.documentRoot]; + } + + this._mouseDownHitRec = null; + this._mouseUpHitRec = null; + + snapManager.clearAvoidList(); + snapManager.clearDragPlane(); + + // the translate tool does snap align to the bounds of the object only. + // turn off snap align to the cursor. This needs to be re-enabled in the mouse up method + snapManager.enableSnapAlign( false ); + + // snap to element and snap to grid are conditionally enabled based + // on the snap results of the mouse down. enable everything for the first snap + this._snapToElements = snapManager.elementSnapEnabledAppLevel(); + this._snapToGrid = snapManager.gridSnapEnabledAppLevel(); + + this._dragPlane = null; + this._clickedOnStage = false; + var do3DSnap = true; + + if(this._handleMode === null) + { + snapManager.enableElementSnap ( true ); + snapManager.enableGridSnap ( true ); + } +// else +// { +// this._delta = null; + // special case for z-translation +// if(this._handleMode === 0) +// { +// this._dragPlane