diff options
Diffstat (limited to 'js/tools/Rotate3DToolBase.js')
-rwxr-xr-x | js/tools/Rotate3DToolBase.js | 316 |
1 files changed, 158 insertions, 158 deletions
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, | |||
41 | ElementsMediator = require("js/mediators/element-mediator").ElementMediator; | 41 | ElementsMediator = require("js/mediators/element-mediator").ElementMediator; |
42 | 42 | ||
43 | exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { | 43 | exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { |
44 | _canSnap: { value: false }, | 44 | _canSnap: { value: false }, |
45 | 45 | ||
46 | _inLocalMode: { value: true, enumerable: true }, | 46 | _inLocalMode: { value: true, enumerable: true }, |
47 | 47 | ||
@@ -59,20 +59,20 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { | |||
59 | selectedElements = [this.application.ninja.currentDocument.model.documentRoot]; | 59 | selectedElements = [this.application.ninja.currentDocument.model.documentRoot]; |
60 | } | 60 | } |
61 | 61 | ||
62 | this._mouseDownHitRec = null; | 62 | this._mouseDownHitRec = null; |
63 | this._mouseUpHitRec = null; | 63 | this._mouseUpHitRec = null; |
64 | 64 | ||
65 | snapManager.clearAvoidList(); | 65 | snapManager.clearAvoidList(); |
66 | snapManager.clearDragPlane(); | 66 | snapManager.clearDragPlane(); |
67 | 67 | ||
68 | // the translate tool does snap align to the bounds of the object only. | 68 | // the translate tool does snap align to the bounds of the object only. |
69 | // turn off snap align to the cursor. This needs to be re-enabled in the mouse up method | 69 | // turn off snap align to the cursor. This needs to be re-enabled in the mouse up method |
70 | snapManager.enableSnapAlign( false ); | 70 | snapManager.enableSnapAlign( false ); |
71 | 71 | ||
72 | // snap to element and snap to grid are conditionally enabled based | 72 | // snap to element and snap to grid are conditionally enabled based |
73 | // on the snap results of the mouse down. enable everything for the first snap | 73 | // on the snap results of the mouse down. enable everything for the first snap |
74 | this._snapToElements = snapManager.elementSnapEnabledAppLevel(); | 74 | this._snapToElements = snapManager.elementSnapEnabledAppLevel(); |
75 | this._snapToGrid = snapManager.gridSnapEnabledAppLevel(); | 75 | this._snapToGrid = snapManager.gridSnapEnabledAppLevel(); |
76 | 76 | ||
77 | this._dragPlane = null; | 77 | this._dragPlane = null; |
78 | this._clickedOnStage = false; | 78 | this._clickedOnStage = false; |
@@ -80,8 +80,8 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { | |||
80 | 80 | ||
81 | if(this._handleMode === null) | 81 | if(this._handleMode === null) |
82 | { | 82 | { |
83 | snapManager.enableElementSnap ( true ); | 83 | snapManager.enableElementSnap ( true ); |
84 | snapManager.enableGridSnap ( true ); | 84 | snapManager.enableGridSnap ( true ); |
85 | } | 85 | } |
86 | // else | 86 | // else |
87 | // { | 87 | // { |
@@ -93,8 +93,8 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { | |||
93 | // snapManager.setupDragPlaneFromPlane(this._dragPlane); | 93 | // snapManager.setupDragPlaneFromPlane(this._dragPlane); |
94 | // do3DSnap = false; | 94 | // do3DSnap = false; |
95 | 95 | ||
96 | // snapManager.enableElementSnap ( false ); | 96 | // snapManager.enableElementSnap ( false ); |
97 | // snapManager.enableGridSnap ( false ); | 97 | // snapManager.enableGridSnap ( false ); |
98 | // } | 98 | // } |
99 | // } | 99 | // } |
100 | 100 | ||
@@ -103,9 +103,9 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { | |||
103 | var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, | 103 | var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, |
104 | new WebKitPoint(event.pageX, event.pageY)); | 104 | new WebKitPoint(event.pageX, event.pageY)); |
105 | 105 | ||
106 | // do the snap before setting up the avoid list to allow | 106 | // do the snap before setting up the avoid list to allow |
107 | // a snap on the mouse down | 107 | // a snap on the mouse down |
108 | var hitRec = snapManager.snap(point.x, point.y, do3DSnap); | 108 | var hitRec = snapManager.snap(point.x, point.y, do3DSnap); |
109 | 109 | ||
110 | // if(this._handleMode === 2) | 110 | // if(this._handleMode === 2) |
111 | // { | 111 | // { |
@@ -134,18 +134,18 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { | |||
134 | // { | 134 | // { |
135 | // snapManager.addToAvoidList( this._targets[i].elt ); | 135 | // snapManager.addToAvoidList( this._targets[i].elt ); |
136 | // } | 136 | // } |
137 | if (hitRec) | 137 | if (hitRec) |
138 | { | 138 | { |
139 | // disable snap attributes | 139 | // disable snap attributes |
140 | if (hitRec.getType() == hitRec.SNAP_TYPE_ELEMENT) | 140 | if (hitRec.getType() == hitRec.SNAP_TYPE_ELEMENT) |
141 | { | 141 | { |
142 | this._snapToElements = false; | 142 | this._snapToElements = false; |
143 | this._snapToGrid = false; | 143 | this._snapToGrid = false; |
144 | } | 144 | } |
145 | else if (hitRec.getType() == hitRec.SNAP_TYPE_ELEMENT_CENTER) | 145 | else if (hitRec.getType() == hitRec.SNAP_TYPE_ELEMENT_CENTER) |
146 | { | 146 | { |
147 | snapManager.enableSnapAlign( snapManager.snapAlignEnabledAppLevel() ); | 147 | snapManager.enableSnapAlign( snapManager.snapAlignEnabledAppLevel() ); |
148 | } | 148 | } |
149 | 149 | ||
150 | if(this._handleMode === 0) | 150 | if(this._handleMode === 0) |
151 | this.clickedObject = this._target; | 151 | this.clickedObject = this._target; |
@@ -170,20 +170,20 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { | |||
170 | // no quadrant snapping for the rotate tool | 170 | // no quadrant snapping for the rotate tool |
171 | this._shouldUseQuadPt = false; | 171 | this._shouldUseQuadPt = false; |
172 | 172 | ||
173 | var wpHitRec = hitRec.convertToWorkingPlane( this._dragPlane ); | 173 | var wpHitRec = hitRec.convertToWorkingPlane( this._dragPlane ); |
174 | this._mouseDownHitRec = wpHitRec; | 174 | this._mouseDownHitRec = wpHitRec; |
175 | this._mouseUpHitRec = null; | 175 | this._mouseUpHitRec = null; |
176 | 176 | ||
177 | var pt = hitRec.getScreenPoint(); | 177 | var pt = hitRec.getScreenPoint(); |
178 | this.downPoint.x = pt[0]; | 178 | this.downPoint.x = pt[0]; |
179 | this.downPoint.y = pt[1]; | 179 | this.downPoint.y = pt[1]; |
180 | this.downPoint.z = pt[2]; | 180 | this.downPoint.z = pt[2]; |
181 | 181 | ||
182 | // TODO - need to figure out snapManager dependency by drawUtils. | 182 | // TODO - need to figure out snapManager dependency by drawUtils. |
183 | // For now, bypassing by calling snapManager.drawLastHit(); | 183 | // For now, bypassing by calling snapManager.drawLastHit(); |
184 | // drawUtils.refreshDisplay(); | 184 | // drawUtils.refreshDisplay(); |
185 | // snapManager.drawLastHit(); | 185 | // snapManager.drawLastHit(); |
186 | } | 186 | } |
187 | } | 187 | } |
188 | else | 188 | else |
189 | { | 189 | { |
@@ -231,9 +231,9 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { | |||
231 | } | 231 | } |
232 | } | 232 | } |
233 | 233 | ||
234 | this.DrawHandles(this._delta); | 234 | this.DrawHandles(this._delta); |
235 | 235 | ||
236 | if(this._canSnap) | 236 | if(this._canSnap) |
237 | { | 237 | { |
238 | snapManager.drawLastHit(); | 238 | snapManager.drawLastHit(); |
239 | } | 239 | } |
@@ -261,23 +261,23 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { | |||
261 | this._origin[1] = pt1.y; | 261 | this._origin[1] = pt1.y; |
262 | this._origin[2] = pt1.z; | 262 | this._origin[2] = pt1.z; |
263 | 263 | ||
264 | var sw2gMat = viewUtils.getStageWorldToGlobalMatrix(); | 264 | var sw2gMat = viewUtils.getStageWorldToGlobalMatrix(); |
265 | var g2swMat = glmat4.inverse( sw2gMat, [] ); | 265 | var g2swMat = glmat4.inverse( sw2gMat, [] ); |
266 | var swOrigin = MathUtils.transformAndDivideHomogeneousPoint( this._origin, g2swMat ); | 266 | var swOrigin = MathUtils.transformAndDivideHomogeneousPoint( this._origin, g2swMat ); |
267 | //console.log( "modifyElements, _origin: " + this._origin + ", in stageWorld: " + swOrigin ); | 267 | //console.log( "modifyElements, _origin: " + this._origin + ", in stageWorld: " + swOrigin ); |
268 | 268 | ||
269 | var len = selectedElements.length; | 269 | var len = selectedElements.length; |
270 | if(len === 1) | 270 | if(len === 1) |
271 | { | 271 | { |
272 | var elt = selectedElements[0]; | 272 | var elt = selectedElements[0]; |
273 | var g2lMat = elt.elementModel.getProperty("g2l"); | 273 | var g2lMat = elt.elementModel.getProperty("g2l"); |
274 | var localOrigin = MathUtils.transformAndDivideHomogeneousPoint( this._origin, g2lMat ); | 274 | var localOrigin = MathUtils.transformAndDivideHomogeneousPoint( this._origin, g2lMat ); |
275 | 275 | ||
276 | viewUtils.pushViewportObj( elt ); | 276 | viewUtils.pushViewportObj( elt ); |
277 | var viewOrigin = viewUtils.screenToView( localOrigin[0], localOrigin[1], localOrigin[2] ); | 277 | var viewOrigin = viewUtils.screenToView( localOrigin[0], localOrigin[1], localOrigin[2] ); |
278 | viewUtils.popViewportObj(); | 278 | viewUtils.popViewportObj(); |
279 | this._startOriginArray[0] = viewOrigin; | 279 | this._startOriginArray[0] = viewOrigin; |
280 | //console.log( "Rotate3DToolBase.modifyElements, _startOriginArray[0]: " + this._startOriginArray[0] ); | 280 | //console.log( "Rotate3DToolBase.modifyElements, _startOriginArray[0]: " + this._startOriginArray[0] ); |
281 | } | 281 | } |
282 | 282 | ||
283 | this.downPoint.x = pt1.x; | 283 | this.downPoint.x = pt1.x; |
@@ -351,7 +351,7 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { | |||
351 | 351 | ||
352 | if(this._inLocalMode && (this.application.ninja.selectedElements.length === 1 || this.rotateStage) ) | 352 | if(this._inLocalMode && (this.application.ninja.selectedElements.length === 1 || this.rotateStage) ) |
353 | { | 353 | { |
354 | // console.log( "modifyElements: rotateLocally " ); | 354 | // console.log( "modifyElements: rotateLocally " ); |
355 | this._rotateLocally(mat); | 355 | this._rotateLocally(mat); |
356 | } | 356 | } |
357 | else | 357 | else |
@@ -379,8 +379,8 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { | |||
379 | // pre-translate by the transformation center | 379 | // pre-translate by the transformation center |
380 | var tMat = Matrix.I(4); | 380 | var tMat = Matrix.I(4); |
381 | 381 | ||
382 | // _startOriginArray is the location of the center of rotation | 382 | // _startOriginArray is the location of the center of rotation |
383 | // in view space of the element. | 383 | // in view space of the element. |
384 | var transformCtr = this._startOriginArray[i]; | 384 | var transformCtr = this._startOriginArray[i]; |
385 | 385 | ||
386 | tMat[12] = transformCtr[0]; | 386 | tMat[12] = transformCtr[0]; |
@@ -418,7 +418,7 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { | |||
418 | var transformCtr = this._startOriginArray[i].slice(0); | 418 | var transformCtr = this._startOriginArray[i].slice(0); |
419 | transformCtr = MathUtils.transformPoint(transfor |