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