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 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'js/tools/Rotate3DToolBase.js') 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 ) { -- cgit v1.2.3 From f91e64235eb03c889ff4f5577c3e3480cd0d787f Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Fri, 13 Apr 2012 00:30:19 -0700 Subject: removing _undo array and _targets array and use object instead of matching arrays to set properties Signed-off-by: Valerio Virgillito --- js/tools/Rotate3DToolBase.js | 184 +++++++++++++++---------------------------- 1 file changed, 65 insertions(+), 119 deletions(-) (limited to 'js/tools/Rotate3DToolBase.js') diff --git a/js/tools/Rotate3DToolBase.js b/js/tools/Rotate3DToolBase.js index 696408bf..ae1856e8 100755 --- a/js/tools/Rotate3DToolBase.js +++ b/js/tools/Rotate3DToolBase.js @@ -44,27 +44,22 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { modifyElements: { value: function(data, event) { - var mat, - angle, - pt0 = data.pt0, - pt1 = data.pt1; + var mat, angle, pt0 = data.pt0, pt1 = data.pt1; - if(this._handleMode !== null) - { - if(this._activateOriginHandle) - { + if(this._handleMode !== null) { + if(this._activateOriginHandle) { // move the transform origin handle var dx = pt1.x - pt0.x; var dy = pt1.y - pt0.y; this._origin[0] += dx; this._origin[1] += dy; - var len = this._targets.length; - if(len === 1) - { + + if(this.application.ninja.selectedElements.length === 1) { this._startOriginArray[0][0] += dx; this._startOriginArray[0][1] += dy; } + this.downPoint.x = pt1.x; this.downPoint.y = pt1.y; this.DrawHandles(); @@ -133,7 +128,7 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { } } - if(this._inLocalMode && (this._targets.length === 1) ) + if(this._inLocalMode && (this.application.ninja.selectedElements.length === 1) ) { this._rotateLocally(mat); } @@ -149,12 +144,10 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { _rotateLocally: { value: function (rotMat) { - var len = this._targets.length; - for(var i = 0; i < len; i++) - { - var item = this._targets[i]; - var elt = item.elt; - var curMat = item.mat; + var len = this.application.ninja.selectedElements.length; + for(var i = 0; i < len; i++) { + var elt = this.application.ninja.selectedElements[i].elementModel.getProperty("elt"); + var curMat = this.application.ninja.selectedElements[i].elementModel.getProperty("mat"); // pre-translate by the transformation center var tMat = Matrix.I(4); @@ -178,19 +171,17 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { glmat4.multiply(mat, tMat, mat); // while moving, set inline style to improve performance - viewUtils.setMatrixForElement( elt, mat, true ); + viewUtils.setMatrixForElement(this.application.ninja.selectedElements[i], mat, true ); } } }, _rotateGlobally: { value: function (rotMat) { - var len = this._targets.length; - for(var i = 0; i < len; i++) - { - var item = this._targets[i]; - var elt = item.elt; - var curMat = item.mat; + var len = this.application.ninja.selectedElements.length; + for(var i = 0; i < len; i++) { + var elt = this.application.ninja.selectedElements[i].elementModel.getProperty("elt"); + var curMat = this.application.ninja.selectedElements[i].elementModel.getProperty("mat"); // pre-translate by the transformation center var tMat = Matrix.I(4); @@ -213,7 +204,7 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { glmat4.multiply(mat, curMat, mat); - viewUtils.setMatrixForElement( elt, mat, true ); + viewUtils.setMatrixForElement(this.application.ninja.selectedElements[i], mat, true ); } } }, @@ -254,7 +245,6 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { captureSelectionDrawn: { value: function(event){ this._origin = null; - this._targets = []; this._startOriginArray = null; var len = this.application.ninja.selectedElements.length; @@ -304,103 +294,75 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { }, _updateTargets: { - value: function(addToUndoStack) { - var newStyles = [], - previousStyles = [], - len = this.application.ninja.selectedElements.length; - this._targets = []; - for(var i = 0; i < len; i++) - { - var elt = this.application.ninja.selectedElements[i]; -// this._initProps3D(elt); + value: function(addToUndo) { + var mod3dObject = [], self = this; - - var curMat = viewUtils.getMatrixFromElement(elt); - var curMatInv = glmat4.inverse(curMat, []); - - viewUtils.pushViewportObj( elt ); + this.application.ninja.selectedElements.forEach(function(element) { + viewUtils.pushViewportObj(element); var eltCtr = viewUtils.getCenterOfProjection(); viewUtils.popViewportObj(); + eltCtr = viewUtils.localToGlobal(eltCtr, element); - eltCtr = viewUtils.localToGlobal(eltCtr, elt); + element.elementModel.setProperty("ctr", eltCtr); - this._targets.push({elt:elt, mat:curMat, matInv:curMatInv, ctr:eltCtr}); - if(addToUndoStack) - { - var previousStyleStr = {dist:this._undoArray[i].dist, mat:MathUtils.scientificToDecimal(this._undoArray[i].mat.slice(0), 5)}; + if(addToUndo) { + var previousMat = element.elementModel.getProperty("mat").slice(0); + var previousStyleStr = {dist:element.elementModel.getProperty("dist"), mat:MathUtils.scientificToDecimal(previousMat, 5)}; + var newStyleStr = {dist:viewUtils.getPerspectiveDistFromElement(element), mat:MathUtils.scientificToDecimal(viewUtils.getMatrixFromElement(element), 5)}; - var newStyleStr = {dist:viewUtils.getPerspectiveDistFromElement(elt), mat:MathUtils.scientificToDecimal(curMat, 5)}; - - previousStyles.push(previousStyleStr); - newStyles.push(newStyleStr); + mod3dObject.push({element:element, properties:newStyleStr, previousProperties: previousStyleStr}); } + + }); + + if(addToUndo) { + ElementsMediator.set3DProperties(mod3dObject, "Change", "rotateTool"); } - if(addToUndoStack) - { - ElementsMediator.set3DProperties(this.application.ninja.selectedElements, - newStyles, - "Change", - "rotateTool", - previousStyles - ); - } - // 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}); - } + + this.application.ninja.selectedElements.forEach(function(element) { + element.elementModel.setProperty("mat", viewUtils.getMatrixFromElement(element)); + element.elementModel.setProperty("matInv", glmat4.inverse(element.elementModel.getProperty("mat"), [])); + element.elementModel.setProperty("dist", viewUtils.getPerspectiveDistFromElement(element)); + }); } }, _setTransformOrigin: { value: function(shouldUpdateCenter) { - if(!this._origin) - { + if(!this._origin) { return; } - var len = this._targets.length; - var elt, - eltCtr, - ctrOffset, - matInv; - if( len === 1) - { + + var elt, eltCtr, ctrOffset, matInv; + + if(this.application.ninja.selectedElements.length === 1) { elt = this._target; - if(shouldUpdateCenter) - { - eltCtr = this._targets[0].ctr; + if(shouldUpdateCenter) { + console.log("get crt"); + eltCtr = this.application.ninja.selectedElements[0].elementModel.getProperty("ctr"); ctrOffset = vecUtils.vecSubtract(3, this._origin, eltCtr); - matInv = this._targets[0].matInv; + matInv = this.application.ninja.selectedElements[0].elementModel.getProperty("matInv"); ctrOffset = MathUtils.transformVector(ctrOffset, matInv); elt.elementModel.props3D.m_transformCtr = ctrOffset; - } - else - { + } else { this._startOriginArray = []; - var ctrOffset = this._target.elementModel.props3D.m_transformCtr; - if(!ctrOffset) - { + ctrOffset = this._target.elementModel.props3D.m_transformCtr; + if(!ctrOffset) { ctrOffset = [0,0,0]; } } this._startOriginArray[0] = ctrOffset; - } - else - { + } else { // Update transform ctr for all elements if transform origin was modified this._startOriginArray = []; + var len = this.application.ninja.selectedElements.length; for (var i = 0; i < len; i++) { - elt = this._targets[i].elt; - eltCtr = this._targets[i].ctr; + eltCtr = this.application.ninja.selectedElements[i].elementModel.getProperty("ctr"); ctrOffset = vecUtils.vecSubtract(3, this._origin, eltCtr); - matInv = this._targets[i].matInv; + matInv = this.application.ninja.selectedElements[i].elementModel.getProperty("matInv"); ctrOffset = MathUtils.transformVector(ctrOffset, matInv); this._startOriginArray[i] = ctrOffset; @@ -434,43 +396,27 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { } }, - Reset : { - value : function() - { - var item, - mat, - dist, - newStyles = [], - previousStyles = [], - len = this.application.ninja.selectedElements.length, - iMat; - for(var i = 0; i < len; i++) - { + Reset: { + value: function() { + var mat, iMat, dist, mod3dObject = [], self = this; + + this.application.ninja.selectedElements.forEach(function(element) { // Reset to the identity matrix - item = this.application.ninja.selectedElements[i]; iMat = Matrix.I(4); - mat = ElementsMediator.getMatrix(item); + mat = ElementsMediator.getMatrix(element); // iMat[12] = mat[12]; // iMat[13] = mat[13]; // iMat[14] = mat[14]; - dist = ElementsMediator.getPerspectiveDist(item); + dist = ElementsMediator.getPerspectiveDist(element); var previousStyleStr = {dist:dist, mat:mat}; - var newStyleStr = {dist:dist, mat:iMat}; - previousStyles.push(previousStyleStr); - newStyles.push(newStyleStr); - - } + mod3dObject.push({element:element, properties:newStyleStr, previousProperties: previousStyleStr}); + }); - ElementsMediator.set3DProperties(this.application.ninja.selectedElements, - newStyles, - "Change", - "rotateTool", - previousStyles - ); + ElementsMediator.set3DProperties(mod3dObject, "Change", "rotateTool"); this.isDrawing = false; this.endDraw(event); -- cgit v1.2.3 From 0a5504ebe8ada3ff19ff9bbf4d1ee820e1ba90d1 Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Fri, 13 Apr 2012 01:17:08 -0700 Subject: clear console log Signed-off-by: Valerio Virgillito --- js/tools/Rotate3DToolBase.js | 1 - 1 file changed, 1 deletion(-) (limited to 'js/tools/Rotate3DToolBase.js') diff --git a/js/tools/Rotate3DToolBase.js b/js/tools/Rotate3DToolBase.js index ae1856e8..9f23040f 100755 --- a/js/tools/Rotate3DToolBase.js +++ b/js/tools/Rotate3DToolBase.js @@ -339,7 +339,6 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { elt = this._target; if(shouldUpdateCenter) { - console.log("get crt"); eltCtr = this.application.ninja.selectedElements[0].elementModel.getProperty("ctr"); ctrOffset = vecUtils.vecSubtract(3, this._origin, eltCtr); -- cgit v1.2.3 From 521df0ed9242efff45715998837068c87aca7efd Mon Sep 17 00:00:00 2001 From: hwc487 Date: Fri, 13 Apr 2012 11:12:40 -0700 Subject: 3D Rotate changes --- js/tools/Rotate3DToolBase.js | 155 ++++++++++++++++++++++++++++++++----------- 1 file changed, 115 insertions(+), 40 deletions(-) (limited to 'js/tools/Rotate3DToolBase.js') diff --git a/js/tools/Rotate3DToolBase.js b/js/tools/Rotate3DToolBase.js index e0c5abcb..402023ff 100755 --- a/js/tools/Rotate3DToolBase.js +++ b/js/tools/Rotate3DToolBase.js @@ -14,7 +14,8 @@ var Montage = require("montage/core/core").Montage, 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, - ElementsMediator = require("js/mediators/element-mediator").ElementMediator; + ElementsMediator = require("js/mediators/element-mediator").ElementMediator, + Rectangle = require("js/helper-classes/3D/rectangle").Rectangle; exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { _canSnap: { value: false }, @@ -61,14 +62,22 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { this._origin[0] += dx; this._origin[1] += dy; this._origin[2] += dz; + console.log( "modifyElements, _origin: " + this._origin ); 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._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; + viewUtils.pushViewportObj( elt ); + var viewOrigin = viewUtils.screenToView( localOrigin[0], localOrigin[1], localOrigin[2] ); + viewUtils.popViewportObj(); + this._startOriginArray[0] = viewOrigin; + //console.log( "Rotate3DToolBase.modifyElements, _startOriginArray[0]: " + this._startOriginArray[0] ); } this.downPoint.x = pt1.x; this.downPoint.y = pt1.y; @@ -139,8 +148,10 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { } } + if(this._inLocalMode && (this._targets.length === 1) ) { + console.log( "modifyElements: rotateLocally " ); this._rotateLocally(mat); } else @@ -166,22 +177,9 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { 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. + // in view space of the element. 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]; @@ -219,6 +217,8 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { var transformCtr = this._startOriginArray[i].slice(0); transformCtr = MathUtils.transformPoint(transformCtr, curMat); + console.log( "modifyElements: rotateGlobally, ctr: " + transformCtr ); + tMat[12] = transformCtr[0]; tMat[13] = transformCtr[1]; tMat[14] = transformCtr[2]; @@ -306,11 +306,12 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { 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._origin = drawUtils._selectionCtr.slice(0); + //this._origin[0] += this.application.ninja.stage.userContentLeft; + //this._origin[1] += this.application.ninja.stage.userContentTop; this._updateTargets(); - this._setTransformOrigin(true); + this._origin = this.calculateMultiSelOrigin(); + this._setTransformOrigin(true); } } else @@ -326,8 +327,15 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { } }, + /* + _updateHandlesOrigin: { + value: function () { } + }, + */ + _updateTargets: { value: function(addToUndoStack) { + console.log( "Rotate3DToolBase._updateTargets" ); var newStyles = [], previousStyles = [], len = this.application.ninja.selectedElements.length; @@ -345,10 +353,14 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { var eltCtr = viewUtils.getCenterOfProjection(); viewUtils.popViewportObj(); - eltCtr = viewUtils.localToGlobal(eltCtr, elt); + // 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}); - if(addToUndoStack) + this._targets.push({elt:elt, mat:curMat, matInv:curMatInv, ctr:eltCtr, l2g:l2gMat, g2l:g2lMat}); + + if(addToUndoStack) { var previousStyleStr = {dist:this._undoArray[i].dist, mat:MathUtils.scientificToDecimal(this._undoArray[i].mat.slice(0), 5)}; @@ -379,12 +391,54 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { } }, + 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) + { + minPt = pt.slice(); + maxPt = pt.slice(); + } + else + { + 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; + } + }, + _setTransformOrigin: { value: function(shouldUpdateCenter) { if(!this._origin) { return; } + console.log( "_setTransformOrigin, _activateOriginHandle: " + this._activateOriginHandle ); + var len = this._targets.length; var elt, eltCtr, @@ -396,13 +450,14 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { if(shouldUpdateCenter) { - eltCtr = this._targets[0].ctr; - ctrOffset = vecUtils.vecSubtract(3, this._origin, eltCtr); +// eltCtr = this._targets[0].ctr; +// ctrOffset = vecUtils.vecSubtract(3, this._origin, eltCtr); - matInv = this._targets[0].matInv; - ctrOffset = MathUtils.transformVector(ctrOffset, matInv); +// matInv = this._targets[0].matInv; +// ctrOffset = MathUtils.transformVector(ctrOffset, matInv); - elt.elementModel.props3D.m_transformCtr = ctrOffset; +// elt.elementModel.props3D.m_transformCtr = ctrOffset; + elt.elementModel.props3D.m_transformCtr = this._startOriginArray[0].slice(); } else { @@ -412,21 +467,41 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { { ctrOffset = [0,0,0]; } + this._startOriginArray[0] = ctrOffset; } - this._startOriginArray[0] = ctrOffset; } else { - // Update transform ctr for all elements if transform origin was modified - this._startOriginArray = []; - for (var i = 0; i < len; i++) { + /* + this._startOriginArray = []; + for (var i = 0; i < len; i++) { + elt = this._targets[i].elt; + eltCtr = this._targets[i].ctr; + ctrOffset = vecUtils.vecSubtract(3, this._origin, eltCtr); + matInv = this._targets[i].matInv; + ctrOffset = MathUtils.transformVector(ctrOffset, matInv); + this._startOriginArray[i] = ctrOffset; + } + */ + + // 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 --- js/tools/Rotate3DToolBase.js | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'js/tools/Rotate3DToolBase.js') diff --git a/js/tools/Rotate3DToolBase.js b/js/tools/Rotate3DToolBase.js index 9f23040f..2e121b0b 100755 --- a/js/tools/Rotate3DToolBase.js +++ b/js/tools/Rotate3DToolBase.js @@ -21,6 +21,10 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { _inLocalMode: { value: true, enumerable: true }, + rotateStage: { + value: false + }, + drawWithoutSnapping: { value: function(event) @@ -54,8 +58,7 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { this._origin[0] += dx; this._origin[1] += dy; - - if(this.application.ninja.selectedElements.length === 1) { + if( this.rotateStage || (this.application.ninja.selectedElements.length === 1)) { this._startOriginArray[0][0] += dx; this._startOriginArray[0][1] += dy; } @@ -128,7 +131,7 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { } } - if(this._inLocalMode && (this.application.ninja.selectedElements.length === 1) ) + if(this._inLocalMode && (this.application.ninja.selectedElements.length === 1 || this.rotateStage) ) { this._rotateLocally(mat); } @@ -144,10 +147,15 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { _rotateLocally: { value: function (rotMat) { - var len = this.application.ninja.selectedElements.length; + var selectedElements = this.application.ninja.selectedElements; + + if(this.rotateStage) { + selectedElements = [this.application.ninja.currentDocument.documentRoot]; + } + var len = selectedElements.length; for(var i = 0; i < len; i++) { - var elt = this.application.ninja.selectedElements[i].elementModel.getProperty("elt"); - var curMat = this.application.ninja.selectedElements[i].elementModel.getProperty("mat"); + var elt = selectedElements[i].elementModel.getProperty("elt"); + var curMat = selectedElements[i].elementModel.getProperty("mat"); // pre-translate by the transformation center var tMat = Matrix.I(4); @@ -171,7 +179,7 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { glmat4.multiply(mat, tMat, mat); // while moving, set inline style to improve performance - viewUtils.setMatrixForElement(this.application.ninja.selectedElements[i], mat, true ); + viewUtils.setMatrixForElement(selectedElements[i], mat, true ); } } }, @@ -333,16 +341,21 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { return; } - var elt, eltCtr, ctrOffset, matInv; + var elt, element, eltCtr, ctrOffset, matInv; - if(this.application.ninja.selectedElements.length === 1) { + if(this.rotateStage || (this.application.ninja.selectedElements.length === 1)) { elt = this._target; if(shouldUpdateCenter) { - eltCtr = this.application.ninja.selectedElements[0].elementModel.getProperty("ctr"); + if(this.rotateStage) { + element = this.application.ninja.currentDocument.documentRoot; + } else { + element = this.application.ninja.selectedElements[0]; + } + eltCtr = element.elementModel.getProperty("ctr"); ctrOffset = vecUtils.vecSubtract(3, this._origin, eltCtr); - matInv = this.application.ninja.selectedElements[0].elementModel.getProperty("matInv"); + matInv = element.elementModel.getProperty("matInv"); ctrOffset = MathUtils.transformVector(ctrOffset, matInv); elt.elementModel.props3D.m_transformCtr = ctrOffset; -- 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 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'js/tools/Rotate3DToolBase.js') 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; -- 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 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'js/tools/Rotate3DToolBase.js') 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, -- 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 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'js/tools/Rotate3DToolBase.js') 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 --- js/tools/Rotate3DToolBase.js | 143 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) (limited to 'js/tools/Rotate3DToolBase.js') 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 = viewUtils.getNormalToUnprojectedElementPlane(this._target); +// snapManager.setupDragPlaneFromPlane(this._dragPlane); +// do3DSnap = false; + +// snapManager.enableElementSnap ( false ); +// snapManager.enableGridSnap ( false ); +// } +// } + + if (selectedElements.length) + { + 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