From 8966fc4903f0eec61816d9b9bdbcac9b7d99c320 Mon Sep 17 00:00:00 2001 From: Armen Kesablyan Date: Mon, 2 Jul 2012 13:19:00 -0700 Subject: Bug: Font Name & Size not updating text tool Signed-off-by: Armen Kesablyan --- js/tools/TextTool.js | 1 - 1 file changed, 1 deletion(-) (limited to 'js/tools') diff --git a/js/tools/TextTool.js b/js/tools/TextTool.js index aa79b8bc..ffaa4f24 100755 --- a/js/tools/TextTool.js +++ b/js/tools/TextTool.js @@ -168,7 +168,6 @@ exports.TextTool = Montage.create(DrawingTool, { if(wasSelected) { NJevent("enableStageMove"); - this.options.defineInitialProperties(); this.application.ninja.stage.stageDeps.snapManager.setupDragPlaneFromPlane( workingPlane ); } else { this.selectedElement = null; -- cgit v1.2.3 From 648ee61ae84216d0236e0dbc211addc13b2cfa3a Mon Sep 17 00:00:00 2001 From: Kris Kowal Date: Fri, 6 Jul 2012 11:52:06 -0700 Subject: Expand tabs --- js/tools/BrushTool.js | 2 +- js/tools/EyedropperTool.js | 22 +- js/tools/FillTool.js | 14 +- js/tools/InkBottleTool.js | 12 +- js/tools/LineTool.js | 24 +- js/tools/OvalTool.js | 16 +- js/tools/PanTool.js | 628 ++++++++++++++-------------- js/tools/PenTool.js | 2 +- js/tools/RectTool.js | 6 +- js/tools/Rotate3DToolBase.js | 316 +++++++------- js/tools/RotateStage3DTool.js | 20 +- js/tools/SelectionTool.js | 70 ++-- js/tools/ShapeTool.js | 178 ++++---- js/tools/ToolBase.js | 2 +- js/tools/Translate3DToolBase.js | 426 +++++++++---------- js/tools/TranslateObject3DTool.js | 80 ++-- js/tools/ZoomTool.js | 314 +++++++------- js/tools/drawing-tool-base.js | 850 +++++++++++++++++++------------------- js/tools/drawing-tool.js | 4 +- js/tools/modifier-tool-base.js | 774 +++++++++++++++++----------------- 20 files changed, 1880 insertions(+), 1880 deletions(-) (limited to 'js/tools') diff --git a/js/tools/BrushTool.js b/js/tools/BrushTool.js index 8861d226..d8a2fde0 100644 --- a/js/tools/BrushTool.js +++ b/js/tools/BrushTool.js @@ -29,7 +29,7 @@ POSSIBILITY OF SUCH DAMAGE. */ var ShapeTool = require("js/tools/ShapeTool").ShapeTool; -var ShapesController = require("js/controllers/elements/shapes-controller").ShapesController; +var ShapesController = require("js/controllers/elements/shapes-controller").ShapesController; var DrawingToolBase = require("js/tools/drawing-tool-base").DrawingToolBase; var defaultEventManager = require("montage/core/event/event-manager").defaultEventManager; var Montage = require("montage/core/core").Montage; diff --git a/js/tools/EyedropperTool.js b/js/tools/EyedropperTool.js index e9831d71..452c46d1 100755 --- a/js/tools/EyedropperTool.js +++ b/js/tools/EyedropperTool.js @@ -49,20 +49,20 @@ exports.EyedropperTool = Montage.create(toolBase, { Configure: { value: function ( doActivate ) - { - if (doActivate) - { + { + if (doActivate) + { NJevent("enableStageMove"); - } - else - { + } + else + { NJevent("disableStageMove"); this._deleteImageDataCanvas(); this._isMouseDown = false; this._elementUnderMouse = null; this._previousColor = null; this._color = null; - } + } } }, @@ -78,7 +78,7 @@ exports.EyedropperTool = Montage.create(toolBase, { HandleMouseMove: { value : function (event) - { + { if(this._escape) { this._isMouseDown = false; @@ -90,12 +90,12 @@ exports.EyedropperTool = Montage.create(toolBase, { { this._updateColorFromPoint(event); } - } - }, + } + }, HandleLeftButtonUp: { value : function (event) { - { + { this._isMouseDown = false; if(this._escape) diff --git a/js/tools/FillTool.js b/js/tools/FillTool.js index d779c655..b6f244e1 100755 --- a/js/tools/FillTool.js +++ b/js/tools/FillTool.js @@ -40,13 +40,13 @@ var Montage = require("montage/core/core").Montage, ShapesController = require("js/controllers/elements/shapes-controller").ShapesController; exports.FillTool = Montage.create(ModifierToolBase, { - _canSnap: { value: false }, - _canColor: { value: true }, - _targetedElement: { value: null }, + _canSnap: { value: false }, + _canColor: { value: true }, + _targetedElement: { value: null }, HandleMouseMove: { value : function (event) - { + { var obj = this.application.ninja.stage.getElement(event, true); var cursor = "url('images/cursors/fill.png') 14 14, default"; var canColor = true; @@ -78,13 +78,13 @@ exports.FillTool = Montage.create(ModifierToolBase, { } this.application.ninja.stage.drawingCanvas.style.cursor = cursor; this._canColor = canColor; - } - }, + } + }, HandleLeftButtonUp: { value : function () { //if(this._isDrawing) - { + { this.application.ninja.stage.clearDrawingCanvas(); this._hasDraw = false; this._isDrawing = false; diff --git a/js/tools/InkBottleTool.js b/js/tools/InkBottleTool.js index 3762641b..d8f06204 100755 --- a/js/tools/InkBottleTool.js +++ b/js/tools/InkBottleTool.js @@ -33,13 +33,13 @@ var Montage = require("montage/core/core").Montage, ElementsMediator = require("js/mediators/element-mediator").ElementMediator; exports.InkBottleTool = Montage.create(ModifierToolBase, { - _canSnap: { value: false }, - _canColor: { value: true }, + _canSnap: { value: false }, + _canColor: { value: true }, _targetedElement: { value: null }, HandleMouseMove: { value : function (event) - { + { var obj = this.application.ninja.stage.getElement(event, true); var cursor = "url('images/cursors/ink.png') 6 11, default"; var canColor = true; @@ -72,13 +72,13 @@ exports.InkBottleTool = Montage.create(ModifierToolBase, { } this.application.ninja.stage.drawingCanvas.style.cursor = cursor; this._canColor = canColor; - } - }, + } + }, HandleLeftButtonUp: { value : function () { //if(this._isDrawing) - { + { this.application.ninja.stage.clearDrawingCanvas(); this._hasDraw = false; this._isDrawing = false; diff --git a/js/tools/LineTool.js b/js/tools/LineTool.js index 89f33a16..b0681af7 100755 --- a/js/tools/LineTool.js +++ b/js/tools/LineTool.js @@ -28,23 +28,23 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -var Montage = require("montage/core/core").Montage, +var Montage = require("montage/core/core").Montage, ShapeTool = require("js/tools/ShapeTool").ShapeTool, DrawingToolBase = require("js/tools/drawing-tool-base").DrawingToolBase, NJUtils = require("js/lib/NJUtils").NJUtils, TagTool = require("js/tools/TagTool").TagTool, - ShapesController = require("js/controllers/elements/shapes-controller").ShapesController, + ShapesController = require("js/controllers/elements/shapes-controller").ShapesController, ShapeModel = require("js/models/shape-model").ShapeModel; var Line = require("js/lib/geom/line").Line; var MaterialsModel = require("js/models/materials-model").MaterialsModel; exports.LineTool = Montage.create(ShapeTool, { - _toolID: { value: "lineTool" }, - _imageID: { value: "lineToolImg" }, - _toolImageClass: { value: "lineToolUp" }, - _selectedToolImageClass: { value: "lineToolDown" }, - _toolTipText: { value: "Line Tool (L)" }, + _toolID: { value: "lineTool" }, + _imageID: { value: "lineToolImg" }, + _toolImageClass: { value: "lineToolUp" }, + _selectedToolImageClass: { value: "lineToolDown" }, + _toolTipText: { value: "Line Tool (L)" }, _tmpDrawIndex : { value : 1, writable:true}, @@ -174,9 +174,9 @@ exports.LineTool = Montage.create(ShapeTool, { dx, dy; - if (hitRec0 && hitRec1) { - var p0 = hitRec0.getLocalPoint(), - p1 = hitRec1.getLocalPoint(); + if (hitRec0 && hitRec1) { + var p0 = hitRec0.getLocalPoint(), + p1 = hitRec1.getLocalPoint(); dx = Math.floor(p0[0] - p1[0]); dy = Math.floor(p0[1] - p1[1]); @@ -246,7 +246,7 @@ exports.LineTool = Montage.create(ShapeTool, { }, RenderShape: { - value: function (w, h, planeMat, midPt, canvas, slope, xAdj, yAdj) + value: function (w, h, planeMat, midPt, canvas, slope, xAdj, yAdj) { var strokeStyleIndex = this.options.strokeStyleIndex; @@ -268,7 +268,7 @@ exports.LineTool = Montage.create(ShapeTool, { { strokeMaterial = Object.create(MaterialsModel.getMaterial(strokeM)); } - strokeColor = ShapesController.getMaterialColor(strokeM) || strokeColor; + strokeColor = ShapesController.getMaterialColor(strokeM) || strokeColor; } var world = this.getGLWorld(canvas, this.options.use3D); diff --git a/js/tools/OvalTool.js b/js/tools/OvalTool.js index 94e4745e..e6451a75 100755 --- a/js/tools/OvalTool.js +++ b/js/tools/OvalTool.js @@ -28,25 +28,25 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -var Montage = require("montage/core/core").Montage, +var Montage = require("montage/core/core").Montage, ShapeTool = require("js/tools/ShapeTool").ShapeTool, - ShapesController = require("js/controllers/elements/shapes-controller").ShapesController; + ShapesController = require("js/controllers/elements/shapes-controller").ShapesController; var Circle = require("js/lib/geom/circle").Circle; var MaterialsModel = require("js/models/materials-model").MaterialsModel; exports.OvalTool = Montage.create(ShapeTool, { - _toolID: { value: "ovalTool" }, - _imageID: { value: "ovalToolImg" }, - _toolImageClass: { value: "ovalToolUp" }, - _selectedToolImageClass: { value: "ovalToolDown" }, - _toolTipText: { value: "Oval Tool (O)" }, + _toolID: { value: "ovalTool" }, + _imageID: { value: "ovalToolImg" }, + _toolImageClass: { value: "ovalToolUp" }, + _selectedToolImageClass: { value: "ovalToolDown" }, + _toolTipText: { value: "Oval Tool (O)" }, _selectedToolClass:{value:"ovalToolSpecificProperties"}, _ovalView : { value: null, writable: true}, RenderShape: { - value: function (w, h, planeMat, midPt, canvas) + value: function (w, h, planeMat, midPt, canvas) { if( (Math.floor(w) === 0) || (Math.floor(h) === 0) ) { diff --git a/js/tools/PanTool.js b/js/tools/PanTool.js index 6b3dbdbb..11345ad9 100755 --- a/js/tools/PanTool.js +++ b/js/tools/PanTool.js @@ -38,33 +38,33 @@ var Montage = require("montage/core/core").Montage, exports.PanTool = Montage.create(toolBase, { - _localPt :{value: [0,0] , writable:true}, - _worldPt :{value: [0,0] , writable:true}, - _globalPt :{value: [0,0] , writable:true}, - _globalToUCWorld :{value: [] , writable:true}, - _lastGPt :{value: [0,0], writable:true}, - _lastY :{value: 0, writable:true}, + _localPt :{value: [0,0] , writable:true}, + _worldPt :{value: [0,0] , writable:true}, + _globalPt :{value: [0,0] , writable:true}, + _globalToUCWorld :{value: [] , writable:true}, + _lastGPt :{value: [0,0], writable:true}, + _lastY :{value: 0, writable:true}, - _maxHorizontalScroll: {value: 0, writable:true}, - _maxVerticalScroll: {value: 0, writable:true}, + _maxHorizontalScroll: {value: 0, writable:true}, + _maxVerticalScroll: {value: 0, writable:true}, Configure: { value: function ( doActivate ) - { - if (doActivate) - { - NJevent("enableStageMove"); - this.eventManager.addEventListener( "toolDoubleClick", this, false); - this.application.ninja.stage.canvas.addEventListener("mousewheel", this, false); - this.activate(); - } - else - { - NJevent("disableStageMove"); + { + if (doActivate) + { + NJevent("enableStageMove"); + this.eventManager.addEventListener( "toolDoubleClick", this, false); + this.application.ninja.stage.canvas.addEventListener("mousewheel", this, false); + this.activate(); + } + else + { + NJevent("disableStageMove"); this.eventManager.removeEventListener( "toolDoubleClick", this, false); - this.application.ninja.stage.canvas.removeEventListener("mousewheel", this, false); - this.deactivate(); - } + this.application.ninja.stage.canvas.removeEventListener("mousewheel", this, false); + this.deactivate(); + } } }, @@ -87,23 +87,23 @@ exports.PanTool = Montage.create(toolBase, }, HandleMouseMove: - { + { value : function (event) - { - this.mouseMove( event ); - } - }, + { + this.mouseMove( event ); + } + }, HandleLeftButtonUp: - { + { value : function ( event ) - { + { //if(this._isDrawing) - { - // do one final mouse move to update the scrollbars - this.mouseUp( event ); + { + // do one final mouse move to update the scrollbars + this.mouseUp( event ); - this.application.ninja.stage.clearDrawingCanvas(); + this.application.ninja.stage.clearDrawingCanvas(); this._hasDraw = false; this._isDrawing = false; this.isDrawing = false; @@ -114,248 +114,248 @@ exports.PanTool = Montage.create(toolBase, HandleKeyPress: { value: function(event) { if(event.altKey) - { + { this._altKeyDown = true; } - else if (event.shiftKey) - { - if (!this._shiftKeyDown) - { - this._shiftKeyDown = true; - this._shiftPt = this._lastGPt.slice(); - } - } + else if (event.shiftKey) + { + if (!this._shiftKeyDown) + { + this._shiftKeyDown = true; + this._shiftPt = this._lastGPt.slice(); + } + } } }, HandleKeyUp: { value: function(event) { if(event.keyCode === Keyboard.ALT) - { + { this._altKeyDown = false; } - else if (event.keyCode === Keyboard.SHIFT) - { - this._shiftKeyDown = false; - } + else if (event.keyCode === Keyboard.SHIFT) + { + this._shiftKeyDown = false; + } } }, handleToolDoubleClick: - { + { value: function () - { - var uc = this.application.ninja.currentDocument.model.documentRoot; - var ucMat = viewUtils.getMatrixFromElement(uc); + { + var uc = this.application.ninja.currentDocument.model.documentRoot; + var ucMat = viewUtils.getMatrixFromElement(uc); - var noTrans = ucMat.slice(); - noTrans[12] = 0; noTrans[13] = 0; noTrans[14] = 0; - var ucMatInv = glmat4.inverse( ucMat, [] ); - var deltaMat = glmat4.multiply( noTrans, ucMatInv, [] ); + var noTrans = ucMat.slice(); + noTrans[12] = 0; noTrans[13] = 0; noTrans[14] = 0; + var ucMatInv = glmat4.inverse( ucMat, [] ); + var deltaMat = glmat4.multiply( noTrans, ucMatInv, [] ); this.application.ninja.stage.centerStage(); - this.applyDeltaMat( deltaMat ); + this.applyDeltaMat( deltaMat ); } }, handleMousewheel : - { + { value:function(event) - { - var zoom = this.application.ninja.documentBar.zoomFactor/100.0; - if (!zoom) zoom = 1.0; + { + var zoom = this.application.ninja.documentBar.zoomFactor/100.0; + if (!zoom) zoom = 1.0; - var delta = 0; - if (event.wheelDelta) - delta = 10*event.wheelDelta/120; - //console.log( "delta: " + delta ); + var delta = 0; + if (event.wheelDelta) + delta = 10*event.wheelDelta/120; + //console.log( "delta: " + delta ); this.application.ninja.currentDocument.model.views.design.document.body.scrollLeft += delta; - delta *= zoom; + delta *= zoom; - var uc = this.application.ninja.currentDocument.model.documentRoot; - var ucMat = viewUtils.getMatrixFromElement(uc); - var offset = viewUtils.getElementOffset( uc ); - //console.log( "uc offset: " + offset[0] ); - - var localToGlobalMat = viewUtils.getLocalToGlobalMatrix( uc ); - var globalToLocalMat = glmat4.inverse( localToGlobalMat, []); - - var w = uc.offsetWidth, - h = uc.offsetHeight; - if(uc.width) - w = uc.width; - if(uc.height) - h = uc.height; - var localPt = [ w/2, h/2, 0]; - var globalPt = MathUtils.transformAndDivideHomogeneousPoint( localPt, localToGlobalMat ); - this.doMouseDown( { x:globalPt[0], y:globalPt[1] } ); - - globalPt[0] += delta; - this._isDrawing = true; - this.doMouseMove( { x:globalPt[0], y:globalPt[1] } ); - this._isDrawing = false; + var uc = this.application.ninja.currentDocument.model.documentRoot; + var ucMat = viewUtils.getMatrixFromElement(uc); + var offset = viewUtils.getElementOffset( uc ); + //console.log( "uc offset: " + offset[0] ); + + var localToGlobalMat = viewUtils.getLocalToGlobalMatrix( uc ); + var globalToLocalMat = glmat4.inverse( localToGlobalMat, []); + + var w = uc.offsetWidth, + h = uc.offsetHeight; + if(uc.width) + w = uc.width; + if(uc.height) + h = uc.height; + var localPt = [ w/2, h/2, 0]; + var globalPt = MathUtils.transformAndDivideHomogeneousPoint( localPt, localToGlobalMat ); + this.doMouseDown( { x:globalPt[0], y:globalPt[1] } ); + + globalPt[0] += delta; + this._isDrawing = true; + this.doMouseMove( { x:globalPt[0], y:globalPt[1] } ); + this._isDrawing = false; } }, - ///////////////////////////////////////////////////////////////////// - // Simple tool API - activate: - { - value: function() - { - //console.log( "PanTool.activate" ); - } - }, - - deactivate: - { - value: function() - { - //console.log( "PanTool.deactivate" ); - } - }, - - mouseDown: - { - value: function( event ) - { - //console.log( "PanTool.mouseDown" ); - if (!this.application.ninja.currentDocument) return; + ///////////////////////////////////////////////////////////////////// + // Simple tool API + activate: + { + value: function() + { + //console.log( "PanTool.activate" ); + } + }, + + deactivate: + { + value: function() + { + //console.log( "PanTool.deactivate" ); + } + }, + + mouseDown: + { + value: function( event ) + { + //console.log( "PanTool.mouseDown" ); + if (!this.application.ninja.currentDocument) return; var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, new WebKitPoint(event.pageX, event.pageY)); - this.doMouseDown( point ); - } - }, - - - doMouseDown: - { - value: function( point ) - { - //var tmpPt, tmpPt2, tmpPt3, tmpPt4, tmpMat, tmpMat2; // DEBUG. (see use of these points below) - var hitRec = snapManager.snap( point.x, point.y, true ); - if (hitRec) - { - //console.log( "hit: " + hitRec.getElement().id ); - var globalPt = [point.x, point.y]; - var elt = hitRec.getElement(); - if (elt) - { - // get the userContent object (stage) and its matrix - var userContent = this.application.ninja.currentDocument.model.documentRoot; - var ucMat = viewUtils.getMatrixFromElement(userContent); - - var localToGlobalMat = viewUtils.getLocalToGlobalMatrix( elt ); - var globalToLocalMat = glmat4.inverse( localToGlobalMat, []); - - if (elt != userContent) - this._localPt = hitRec.calculateElementPreTransformScreenPoint(); - else - { - var localPt = hitRec.calculateElementWorldPoint(); - viewUtils.pushViewportObj( userContent ); - var cop = viewUtils.getCenterOfProjection(); - this._localPt = [cop[0] + localPt[0], cop[1] + localPt[1], localPt[2]]; - viewUtils.popViewportObj(); - } + this.doMouseDown( point ); + } + }, + + + doMouseDown: + { + value: function( point ) + { + //var tmpPt, tmpPt2, tmpPt3, tmpPt4, tmpMat, tmpMat2; // DEBUG. (see use of these points below) + var hitRec = snapManager.snap( point.x, point.y, true ); + if (hitRec) + { + //console.log( "hit: " + hitRec.getElement().id ); + var globalPt = [point.x, point.y]; + var elt = hitRec.getElement(); + if (elt) + { + // get the userContent object (stage) and its matrix + var userContent = this.application.ninja.currentDocument.model.documentRoot; + var ucMat = viewUtils.getMatrixFromElement(userContent); + + var localToGlobalMat = viewUtils.getLocalToGlobalMatrix( elt ); + var globalToLocalMat = glmat4.inverse( localToGlobalMat, []); + + if (elt != userContent) + this._localPt = hitRec.calculateElementPreTransformScreenPoint(); + else + { + var localPt = hitRec.calculateElementWorldPoint(); + viewUtils.pushViewportObj( userContent ); + var cop = viewUtils.getCenterOfProjection(); + this._localPt = [cop[0] + localPt[0], cop[1] + localPt[1], localPt[2]]; + viewUtils.popViewportObj(); + } this._localPt[0] = Math.round(this._localPt[0]); this._localPt[1] = Math.round(this._localPt[1]); - this._globalPt = MathUtils.transformAndDivideHomogeneousPoint( this._localPt, localToGlobalMat ); - var tmpLocal = MathUtils.transformAndDivideHomogeneousPoint( this._globalPt, globalToLocalMat ); - - this._lastGPt = this._globalPt.slice(); - this._shiftPt = this._lastGPt.slice(); - this._lastY = this._lastGPt[1]; - - // set up the matrices we will be needing - var eltToStageWorldMat = glmat4.multiply( ucMat, viewUtils.getObjToStageWorldMatrix(elt, true), []); - this._worldPt = MathUtils.transformAndDivideHomogeneousPoint( this._localPt, eltToStageWorldMat ); -// console.log( "screenPt: " + globalPt ); -// console.log( "_worldPt: " + this._worldPt ); -// console.log( "_localPt: " + this._localPt ); -// console.log( "_globalPt: " + this._globalPt ); -// console.log( "hit localPt: " + hitRec.calculateElementPreTransformScreenPoint() ); - - // get a matrix from user content world space to the screen - viewUtils.pushViewportObj( userContent ); - var cop = viewUtils.getCenterOfProjection(); - var pDist = viewUtils.getPerspectiveDistFromElement(userContent); - var projMat = glmat4.scale(Matrix.I(4), [pDist,pDist,pDist], []); - projMat[11] = -1; - projMat[15] = 1400; - var v2s = Matrix.Translation([cop[0], cop[1], 0]); - var ucWorldToGlobal = glmat4.multiply( v2s, projMat, [] ); - var offset = viewUtils.getElementOffset( userContent ); - var offMat = Matrix.Translation([offset[0], offset[1], 0]); - glmat4.multiply( offMat, ucWorldToGlobal, ucWorldToGlobal ); - this._globalToUCWorld = glmat4.inverse(ucWorldToGlobal, []); - viewUtils.popViewportObj(); - - /* - tmpPt = MathUtils.transformAndDivideHomogeneousPoint( this._globalPt, this._globalToUCWorld ); // DEBUG - tmpPt should equal this._worldPt - tmpPt2 = MathUtils.transformAndDivideHomogeneousPoint( this._worldPt, ucWorldToGlobal ); // DEBUG - tmpPt2 should equal globalPt - tmpPt3 = viewUtils.localToGlobal( this._localPt, elt ); - tmpPt4 = MathUtils.transformAndDivideHomogeneousPoint( tmpPt3, this._globalToUCWorld ); - tmpMat = glmat4.multiply(ucWorldToGlobal, eltToStageWorldMat, []); - tmpMat2 = viewUtils.getLocalToGlobalMatrix( elt ); - */ - } - } - } - }, - - mouseMove: - { - value: function( event ) - { + this._globalPt = MathUtils.transformAndDivideHomogeneousPoint( this._localPt, localToGlobalMat ); + var tmpLocal = MathUtils.transformAndDivideHomogeneousPoint( this._globalPt, globalToLocalMat ); + + this._lastGPt = this._globalPt.slice(); + this._shiftPt = this._lastGPt.slice(); + this._lastY = this._lastGPt[1]; + + // set up the matrices we will be needing + var eltToStageWorldMat = glmat4.multiply( ucMat, viewUtils.getObjToStageWorldMatrix(elt, true), []); + this._worldPt = MathUtils.transformAndDivideHomogeneousPoint( this._localPt, eltToStageWorldMat ); +// console.log( "screenPt: " + globalPt ); +// console.log( "_worldPt: " + this._worldPt ); +// console.log( "_localPt: " + this._localPt ); +// console.log( "_globalPt: " + this._globalPt ); +// console.log( "hit localPt: " + hitRec.calculateElementPreTransformScreenPoint() ); + + // get a matrix from user content world space to the screen + viewUtils.pushViewportObj( userContent ); + var cop = viewUtils.getCenterOfProjection(); + var pDist = viewUtils.getPerspectiveDistFromElement(userContent); + var projMat = glmat4.scale(Matrix.I(4), [pDist,pDist,pDist], []); + projMat[11] = -1; + projMat[15] = 1400; + var v2s = Matrix.Translation([cop[0], cop[1], 0]); + var ucWorldToGlobal = glmat4.multiply( v2s, projMat, [] ); + var offset = viewUtils.getElementOffset( userContent ); + var offMat = Matrix.Translation([offset[0], offset[1], 0]); + glmat4.multiply( offMat, ucWorldToGlobal, ucWorldToGlobal ); + this._globalToUCWorld = glmat4.inverse(ucWorldToGlobal, []); + viewUtils.popViewportObj(); + + /* + tmpPt = MathUtils.transformAndDivideHomogeneousPoint( this._globalPt, this._globalToUCWorld ); // DEBUG - tmpPt should equal this._worldPt + tmpPt2 = MathUtils.transformAndDivideHomogeneousPoint( this._worldPt, ucWorldToGlobal ); // DEBUG - tmpPt2 should equal globalPt + tmpPt3 = viewUtils.localToGlobal( this._localPt, elt ); + tmpPt4 = MathUtils.transformAndDivideHomogeneousPoint( tmpPt3, this._globalToUCWorld ); + tmpMat = glmat4.multiply(ucWorldToGlobal, eltToStageWorldMat, []); + tmpMat2 = viewUtils.getLocalToGlobalMatrix( elt ); + */ + } + } + } + }, + + mouseMove: + { + value: function( event ) + { var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, new WebKitPoint(event.pageX, event.pageY)); - this.doMouseMove( point ); - - } - }, - - doMouseMove: - { - value: function( point ) - { - if (this._isDrawing) - { - // get the global screen point - var gPt = [point.x, point.y, this._globalPt[2]], + this.doMouseMove( point ); + + } + }, + + doMouseMove: + { + value: function( point ) + { + if (this._isDrawing) + { + // get the global screen point + var gPt = [point.x, point.y, this._globalPt[2]], dx, dy; - if (this._altKeyDown) - { - dy = 5*(point.y - this._lastY); - this._globalPt[2] += dy; - gPt = [this._lastGPt[0], this._lastGPt[1], this._globalPt[2]]; - } - else if (this._shiftKeyDown) - { - dx = Math.abs( this._shiftPt[0] - gPt[0] ); - dy = Math.abs( this._shiftPt[1] - gPt[1] ); - - if (dx >= dy) - gPt[1] = this._shiftPt[1]; - else - gPt[0] = this._shiftPt[0]; - } - - // update the scrollbars - var deltaGPt = vecUtils.vecSubtract(2, gPt, this._lastGPt); - this._lastGPt = gPt.slice(); - this._lastY = point.y; + if (this._altKeyDown) + { + dy = 5*(point.y - this._lastY); + this._globalPt[2] += dy; + gPt = [this._lastGPt[0], this._lastGPt[1], this._globalPt[2]]; + } + else if (this._shiftKeyDown) + { + dx = Math.abs( this._shiftPt[0] - gPt[0] ); + dy = Math.abs( this._shiftPt[1] - gPt[1] ); + + if (dx >= dy) + gPt[1] = this._shiftPt[1]; + else + gPt[0] = this._shiftPt[0]; + } + + // update the scrollbars + var deltaGPt = vecUtils.vecSubtract(2, gPt, this._lastGPt); + this._lastGPt = gPt.slice(); + this._lastY = point.y; var limitX = false; var limitY = false; - var oldLeft = this.application.ninja.currentDocument.model.views.design.document.body.scrollLeft, - oldTop = this.application.ninja.currentDocument.model.views.design.document.body.scrollTop, + var oldLeft = this.application.ninja.currentDocument.model.views.design.document.body.scrollLeft, + oldTop = this.application.ninja.currentDocument.model.views.design.document.body.scrollTop, newLeft = oldLeft - deltaGPt[0], newTop = oldTop - deltaGPt[1]; if((newLeft < 0) || (newLeft > this._maxHorizontalScroll)) @@ -368,93 +368,93 @@ exports.PanTool = Montage.create(toolBase, } this.application.ninja.currentDocument.model.views.design.document.body.scrollLeft -= deltaGPt[0]; this.application.ninja.currentDocument.model.views.design.document.body.scrollTop -= deltaGPt[1]; - deltaGPt[0] = oldLeft - this.application.ninja.currentDocument.model.views.design.document.body.scrollLeft; - deltaGPt[1] = oldTop - this.application.ninja.currentDocument.model.views.design.document.body.scrollTop; - - gPt[0] -= deltaGPt[0]; - gPt[1] -= deltaGPt[1]; - - this.updateGlobalToUCWorldMatrix(); - - var wPt = MathUtils.transformAndDivideHomogeneousPoint( gPt, this._globalToUCWorld ); - var delta = vecUtils.vecSubtract( 3, wPt, this._worldPt ); - - if (!this._altKeyDown) - delta[2] = 0; - - // limit the change - var ucMat = viewUtils.getMatrixFromElement(this.application.ninja.currentDocument.model.documentRoot); - var tooMuch = false; - if ((ucMat[12] > 12000) && (delta[0] > 0)) tooMuch = true; - if ((ucMat[12] < -12000) && (delta[0] < 0)) tooMuch = true; - if ((ucMat[13] > 12000) && (delta[1] > 0)) tooMuch = true; - if ((ucMat[13] < -12000) && (delta[1] < 0)) tooMuch = true; - if ((ucMat[14] > 12000) && (delta[2] > 0)) tooMuch = true; - if ((ucMat[14] < -12000) && (delta[2] < 0)) tooMuch = true; - if (tooMuch) - { - this._isDrawing = false; - delta = [0,0,0]; - } - else - this._worldPt = wPt; + deltaGPt[0] = oldLeft - this.application.ninja.currentDocument.model.views.design.document.body.scrollLeft; + deltaGPt[1] = oldTop - this.application.ninja.currentDocument.model.views.design.document.body.scrollTop; + + gPt[0] -= deltaGPt[0]; + gPt[1] -= deltaGPt[1]; + + this.updateGlobalToUCWorldMatrix(); + + var wPt = MathUtils.transformAndDivideHomogeneousPoint( gPt, this._globalToUCWorld ); + var delta = vecUtils.vecSubtract( 3, wPt, this._worldPt ); + + if (!this._altKeyDown) + delta[2] = 0; + + // limit the change + var ucMat = viewUtils.getMatrixFromElement(this.application.ninja.currentDocument.model.documentRoot); + var tooMuch = false; + if ((ucMat[12] > 12000) && (delta[0] > 0)) tooMuch = true; + if ((ucMat[12] < -12000) && (delta[0] < 0)) tooMuch = true; + if ((ucMat[13] > 12000) && (delta[1] > 0)) tooMuch = true; + if ((ucMat[13] < -12000) && (delta[1] < 0)) tooMuch = true; + if ((ucMat[14] > 12000) && (delta[2] > 0)) tooMuch = true; + if ((ucMat[14] < -12000) && (delta[2] < 0)) tooMuch = true; + if (tooMuch) + { + this._isDrawing = false; + delta = [0,0,0]; + } + else + this._worldPt = wPt; if(limitX) delta[0] = 0; if(limitY) delta[1] = 0; - // update everything - var transMat = Matrix.Translation( delta ); - this.applyDeltaMat( transMat ); - } - } - }, - - mouseUp: - { - value: function( event ) - { - //console.log( "PanTool.mouseUp" ); - this.application.ninja.stage.updatedStage = true; - } - }, - - applyDeltaMat: - { - value: function( transMat ) - { - // update the user content matrix - var uc = this.application.ninja.currentDocument.model.documentRoot; - var ucMat = viewUtils.getMatrixFromElement(uc); - var newUCMat = glmat4.multiply( transMat, ucMat, [] ); - viewUtils.setMatrixForElement( uc, newUCMat ); - - // redraw everything - this.application.ninja.stage.updatedStage = true; - } - }, - - updateGlobalToUCWorldMatrix: - { - value: function() - { - // get the userContent object - var userContent = this.application.ninja.currentDocument.model.documentRoot; - - // get a matrix from user content world space to the screen - viewUtils.pushViewportObj( userContent ); - var cop = viewUtils.getCenterOfProjection(); - var pDist = viewUtils.getPerspectiveDistFromElement(userContent); - var projMat = glmat4.scale(Matrix.I(4), [pDist,pDist,pDist], []); - projMat[11] = -1; - projMat[15] = 1400; - var v2s = Matrix.Translation([cop[0], cop[1], 0]); - var ucWorldToGlobal = glmat4.multiply( v2s, projMat, [] ); - var offset = viewUtils.getElementOffset( userContent ); - var offMat = Matrix.Translation([offset[0], offset[1], 0]); - glmat4.multiply( offMat, ucWorldToGlobal, ucWorldToGlobal ); - this._globalToUCWorld = glmat4.inverse(ucWorldToGlobal, []); - viewUtils.popViewportObj(); - } - } + // update everything + var transMat = Matrix.Translation( delta ); + this.applyDeltaMat( transMat ); + } + } + }, + + mouseUp: + { + value: function( event ) + { + //console.log( "PanTool.mouseUp" ); + this.application.ninja.stage.updatedStage = true; + } + }, + + applyDeltaMat: + { + value: function( transMat ) + { + // update the user content matrix + var uc = this.application.ninja.currentDocument.model.documentRoot; + var ucMat = viewUtils.getMatrixFromElement(uc); + var newUCMat = glmat4.multiply( transMat, ucMat, [] ); + viewUtils.setMatrixForElement( uc, newUCMat ); + + // redraw everything + this.application.ninja.stage.updatedStage = true; + } + }, + + updateGlobalToUCWorldMatrix: + { + value: function() + { + // get the userContent object + var userContent = this.application.ninja.currentDocument.model.documentRoot; + + // get a matrix from user content world space to the screen + viewUtils.pushViewportObj( userContent ); + var cop = viewUtils.getCenterOfProjection(); + var pDist = viewUtils.getPerspectiveDistFromElement(userContent); + var projMat = glmat4.scale(Matrix.I(4), [pDist,pDist,pDist], []); + projMat[11] = -1; + projMat[15] = 1400; + var v2s = Matrix.Translation([cop[0], cop[1], 0]); + var ucWorldToGlobal = glmat4.multiply( v2s, projMat, [] ); + var offset = viewUtils.getElementOffset( userContent ); + var offMat = Matrix.Translation([offset[0], offset[1], 0]); + glmat4.multiply( offMat, ucWorldToGlobal, ucWorldToGlobal ); + this._globalToUCWorld = glmat4.inverse(ucWorldToGlobal, []); + viewUtils.popViewportObj(); + } + } } ); diff --git a/js/tools/PenTool.js b/js/tools/PenTool.js index 25423f76..c22e3bc0 100755 --- a/js/tools/PenTool.js +++ b/js/tools/PenTool.js @@ -29,7 +29,7 @@ POSSIBILITY OF SUCH DAMAGE. */ var ShapeTool = require("js/tools/ShapeTool").ShapeTool; -var ShapesController = require("js/controllers/elements/shapes-controller").ShapesController; +var ShapesController = require("js/controllers/elements/shapes-controller").ShapesController; var DrawingToolBase = require("js/tools/drawing-tool-base").DrawingToolBase; var defaultEventManager = require("montage/core/event/event-manager").defaultEventManager; var Montage = require("montage/core/core").Montage; diff --git a/js/tools/RectTool.js b/js/tools/RectTool.js index babd623a..82db3c7a 100755 --- a/js/tools/RectTool.js +++ b/js/tools/RectTool.js @@ -28,9 +28,9 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -var Montage = require("montage/core/core").Montage, +var Montage = require("montage/core/core").Montage, ShapeTool = require("js/tools/ShapeTool").ShapeTool, - ShapesController = require("js/controllers/elements/shapes-controller").ShapesController; + ShapesController = require("js/controllers/elements/shapes-controller").ShapesController; var Rectangle = require("js/lib/geom/rectangle").Rectangle; var MaterialsModel = require("js/models/materials-model").MaterialsModel; @@ -63,7 +63,7 @@ exports.RectTool = Montage.create(ShapeTool, { _buttons: {enumerable: false,value: { hexinput: [] , lockbutton: []}}, RenderShape: { - value: function (w, h, planeMat, midPt, canvas) + value: function (w, h, planeMat, midPt, canvas) { if( (Math.floor(w) === 0) || (Math.floor(h) === 0) ) { diff --git a/js/tools/Rotate3DToolBase.js b/js/tools/Rotate3DToolBase.js index 60dcdc6a..6e805e28 100755 --- a/js/tools/Rotate3DToolBase.js +++ b/js/tools/Rotate3DToolBase.js @@ -41,7 +41,7 @@ var Montage = require("montage/core/core").Montage, ElementsMediator = require("js/mediators/element-mediator").ElementMediator; exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { - _canSnap: { value: false }, + _canSnap: { value: false }, _inLocalMode: { value: true, enumerable: true }, @@ -59,20 +59,20 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { selectedElements = [this.application.ninja.currentDocument.model.documentRoot]; } - this._mouseDownHitRec = null; - this._mouseUpHitRec = null; + this._mouseDownHitRec = null; + this._mouseUpHitRec = null; - snapManager.clearAvoidList(); - snapManager.clearDragPlane(); + 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 ); + // 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(); + // 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; @@ -80,8 +80,8 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { if(this._handleMode === null) { - snapManager.enableElementSnap ( true ); - snapManager.enableGridSnap ( true ); + snapManager.enableElementSnap ( true ); + snapManager.enableGridSnap ( true ); } // else // { @@ -93,8 +93,8 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { // snapManager.setupDragPlaneFromPlane(this._dragPlane); // do3DSnap = false; -// snapManager.enableElementSnap ( false ); -// snapManager.enableGridSnap ( false ); +// snapManager.enableElementSnap ( false ); +// snapManager.enableGridSnap ( false ); // } // } @@ -103,9 +103,9 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { 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); + // 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) // { @@ -134,18 +134,18 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { // { // snapManager.addToAvoidList( this._targets[i].elt ); // } - if (hitRec) - { - // disable snap attributes - if (hitRec.getType() == hitRec.SNAP_TYPE_ELEMENT) - { - this._snapToElements = false; - this._snapToGrid = false; - } - else if (hitRec.getType() == hitRec.SNAP_TYPE_ELEMENT_CENTER) - { - snapManager.enableSnapAlign( snapManager.snapAlignEnabledAppLevel() ); - } + if (hitRec) + { + // disable snap attributes + if (hitRec.getType() == hitRec.SNAP_TYPE_ELEMENT) + { + this._snapToElements = false; + this._snapToGrid = false; + } + else if (hitRec.getType() == hitRec.SNAP_TYPE_ELEMENT_CENTER) + { + snapManager.enableSnapAlign( snapManager.snapAlignEnabledAppLevel() ); + } if(this._handleMode === 0) this.clickedObject = this._target; @@ -170,20 +170,20 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { // no quadrant snapping for the rotate tool this._shouldUseQuadPt = false; - var wpHitRec = hitRec.convertToWorkingPlane( this._dragPlane ); - this._mouseDownHitRec = wpHitRec; - this._mouseUpHitRec = null; + var wpHitRec = hitRec.convertToWorkingPlane( this._dragPlane ); + this._mouseDownHitRec = wpHitRec; + this._mouseUpHitRec = null; - var pt = hitRec.getScreenPoint(); - this.downPoint.x = pt[0]; - this.downPoint.y = pt[1]; - this.downPoint.z = pt[2]; + var pt = hitRec.getScreenPoint(); + this.downPoint.x = pt[0]; + this.downPoint.y = pt[1]; + this.downPoint.z = pt[2]; // TODO - need to figure out snapManager dependency by drawUtils. // For now, bypassing by calling snapManager.drawLastHit(); -// drawUtils.refreshDisplay(); +// drawUtils.refreshDisplay(); // snapManager.drawLastHit(); - } + } } else { @@ -231,9 +231,9 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { } } - this.DrawHandles(this._delta); + this.DrawHandles(this._delta); - if(this._canSnap) + if(this._canSnap) { snapManager.drawLastHit(); } @@ -261,23 +261,23 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { this._origin[1] = pt1.y; this._origin[2] = pt1.z; - 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 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 = selectedElements.length; if(len === 1) { var elt = selectedElements[0]; - var g2lMat = elt.elementModel.getProperty("g2l"); - var localOrigin = MathUtils.transformAndDivideHomogeneousPoint( this._origin, g2lMat ); - - 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] ); + var g2lMat = elt.elementModel.getProperty("g2l"); + var localOrigin = MathUtils.transformAndDivideHomogeneousPoint( this._origin, g2lMat ); + + 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; @@ -351,7 +351,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 @@ -379,8 +379,8 @@ 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. + // _startOriginArray is the location of the center of rotation + // in view space of the element. var transformCtr = this._startOriginArray[i]; tMat[12] = transformCtr[0]; @@ -418,7 +418,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]; @@ -488,7 +488,7 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { viewUtils.pushViewportObj( this.target ); var eltCtr = viewUtils.getCenterOfProjection(); - eltCtr[2] = 0; + eltCtr[2] = 0; viewUtils.popViewportObj(); var ctrOffset = this.target.elementModel.props3D.m_transformCtr; @@ -499,7 +499,7 @@ exports.Rotate3DToolBase = 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); } @@ -510,7 +510,7 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { //this._origin[0] += this.application.ninja.stage.userContentLeft; //this._origin[1] += this.application.ninja.stage.userContentTop; this._updateTargets(); - this._origin = this.calculateMultiSelOrigin(); + this._origin = this.calculateMultiSelOrigin(); this._setTransformOrigin(true); } } @@ -527,16 +527,16 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { } }, - /* - _updateHandlesOrigin: { - value: function () { } - }, - */ + /* + _updateHandlesOrigin: { + value: function () { } + }, + */ _updateTargets: { value: function(addToUndo) { var mod3dObject = [], - self = this; + self = this; this.application.ninja.selectedElements.forEach(function(element) { var curMat = viewUtils.getMatrixFromElement(element); @@ -546,16 +546,16 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { var eltCtr = viewUtils.getCenterOfProjection(); viewUtils.popViewportObj(); - // cache the local to global and global to local matrices - var l2gMat = viewUtils.getLocalToGlobalMatrix( element ); - var g2lMat = glmat4.inverse( l2gMat, [] ); - eltCtr = MathUtils.transformAndDivideHomogeneousPoint( eltCtr, l2gMat ); + // cache the local to global and global to local matrices + var l2gMat = viewUtils.getLocalToGlobalMatrix( element ); + var g2lMat = glmat4.inverse( l2gMat, [] ); + eltCtr = MathUtils.transformAndDivideHomogeneousPoint( eltCtr, l2gMat ); element.elementModel.setProperty("ctr", eltCtr); - element.elementModel.setProperty("mat", curMat); - element.elementModel.setProperty("matInv", curMatInv); - element.elementModel.setProperty("l2g", l2gMat); - element.elementModel.setProperty("g2l", g2lMat); + element.elementModel.setProperty("mat", curMat); + element.elementModel.setProperty("matInv", curMatInv); + element.elementModel.setProperty("l2g", l2gMat); + element.elementModel.setProperty("g2l", g2lMat); if(addToUndo) { var previousMat = element.elementModel.getProperty("mat").slice(0); @@ -579,45 +579,45 @@ 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 - var elt = this.application.ninja.selectedElements[i]; - var l2g = elt.elementModel.getProperty("l2g"); - - // get the element bounds in 'plane' space - var 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; - } - }, + 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 + var elt = this.application.ninja.selectedElements[i]; + var l2g = elt.elementModel.getProperty("l2g"); + + // get the element bounds in 'plane' space + var 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) { @@ -626,19 +626,19 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { } var elt, - element, - eltCtr, - ctrOffset, - matInv; + element, + eltCtr, + ctrOffset, + matInv; if(this.rotateStage || (this.application.ninja.selectedElements.length === 1)) { - if(this.rotateStage) { - element = this.application.ninja.currentDocument.model.documentRoot; + if(this.rotateStage) { + element = this.application.ninja.currentDocument.model.documentRoot; } else { element = this.application.ninja.selectedElements[0]; } - if(shouldUpdateCenter) { + if(shouldUpdateCenter) { // eltCtr = element.elementModel.getProperty("ctr"); // ctrOffset = vecUtils.vecSubtract(3, this._origin, eltCtr); @@ -653,8 +653,8 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { if(!ctrOffset) { ctrOffset = [0,0,0]; } - this._startOriginArray[0] = ctrOffset; - } + this._startOriginArray[0] = ctrOffset; + } } else { /* this._startOriginArray = []; @@ -666,25 +666,25 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { 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; + */ + + // Update transform ctr for all elements if transform origin was modified + if (!this._origin) this._origin = this.calculateMultiSelOrigin(); + var globalCtr = this._origin; var len = this.application.ninja.selectedElements.length; - for (var i=0; i