diff options
Diffstat (limited to 'js/tools')
-rwxr-xr-x | js/tools/Rotate3DToolBase.js | 161 | ||||
-rwxr-xr-x | js/tools/RotateObject3DTool.js | 141 | ||||
-rwxr-xr-x | js/tools/Translate3DToolBase.js | 177 | ||||
-rwxr-xr-x | js/tools/TranslateObject3DTool.js | 1 | ||||
-rwxr-xr-x | js/tools/modifier-tool-base.js | 20 |
5 files changed, 388 insertions, 112 deletions
diff --git a/js/tools/Rotate3DToolBase.js b/js/tools/Rotate3DToolBase.js index 696408bf..e65dc842 100755 --- a/js/tools/Rotate3DToolBase.js +++ b/js/tools/Rotate3DToolBase.js | |||
@@ -14,7 +14,8 @@ var Montage = require("montage/core/core").Montage, | |||
14 | viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils, | 14 | viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils, |
15 | vecUtils = require("js/helper-classes/3D/vec-utils").VecUtils, | 15 | vecUtils = require("js/helper-classes/3D/vec-utils").VecUtils, |
16 | drawUtils = require("js/helper-classes/3D/draw-utils").DrawUtils, | 16 | drawUtils = require("js/helper-classes/3D/draw-utils").DrawUtils, |
17 | ElementsMediator = require("js/mediators/element-mediator").ElementMediator; | 17 | ElementsMediator = require("js/mediators/element-mediator").ElementMediator, |
18 | Rectangle = require("js/helper-classes/3D/rectangle").Rectangle; | ||
18 | 19 | ||
19 | exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { | 20 | exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { |
20 | _canSnap: { value: false }, | 21 | _canSnap: { value: false }, |
@@ -56,17 +57,31 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { | |||
56 | // move the transform origin handle | 57 | // move the transform origin handle |
57 | var dx = pt1.x - pt0.x; | 58 | var dx = pt1.x - pt0.x; |
58 | var dy = pt1.y - pt0.y; | 59 | var dy = pt1.y - pt0.y; |
60 | var dz = pt1.z - pt0.z; | ||
61 | |||
59 | this._origin[0] += dx; | 62 | this._origin[0] += dx; |
60 | this._origin[1] += dy; | 63 | this._origin[1] += dy; |
64 | this._origin[2] += dz; | ||
65 | console.log( "modifyElements, _origin: " + this._origin ); | ||
61 | 66 | ||
62 | var len = this._targets.length; | 67 | var len = this._targets.length; |
63 | if(len === 1) | 68 | if(len === 1) |
64 | { | 69 | { |
65 | this._startOriginArray[0][0] += dx; | 70 | // this._startOriginArray[0][0] += dx; |
66 | this._startOriginArray[0][1] += dy; | 71 | // this._startOriginArray[0][1] += dy; |
72 | // this._startOriginArray[0][2] += dz; | ||
73 | var g2lMat = this._targets[0].g2l; | ||
74 | var localOrigin = MathUtils.transformAndDivideHomogeneousPoint( this._origin, g2lMat ); | ||
75 | var elt = this._targets[0].elt; | ||
76 | viewUtils.pushViewportObj( elt ); | ||
77 | var viewOrigin = viewUtils.screenToView( localOrigin[0], localOrigin[1], localOrigin[2] ); | ||
78 | viewUtils.popViewportObj(); | ||
79 | this._startOriginArray[0] = viewOrigin; | ||
80 | //console.log( "Rotate3DToolBase.modifyElements, _startOriginArray[0]: " + this._startOriginArray[0] ); | ||
67 | } | 81 | } |
68 | this.downPoint.x = pt1.x; | 82 | this.downPoint.x = pt1.x; |
69 | this.downPoint.y = pt1.y; | 83 | this.downPoint.y = pt1.y; |
84 | this.downPoint.z = pt1.z; | ||
70 | this.DrawHandles(); | 85 | this.DrawHandles(); |
71 | return; | 86 | return; |
72 | } | 87 | } |
@@ -133,8 +148,10 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { | |||
133 | } | 148 | } |
134 | } | 149 | } |
135 | 150 | ||
151 | |||
136 | if(this._inLocalMode && (this._targets.length === 1) ) | 152 | if(this._inLocalMode && (this._targets.length === 1) ) |
137 | { | 153 | { |
154 | console.log( "modifyElements: rotateLocally " ); | ||
138 | this._rotateLocally(mat); | 155 | this._rotateLocally(mat); |
139 | } | 156 | } |
140 | else | 157 | else |
@@ -159,6 +176,8 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { | |||
159 | // pre-translate by the transformation center | 176 | // pre-translate by the transformation center |
160 | var tMat = Matrix.I(4); | 177 | var tMat = Matrix.I(4); |
161 | 178 | ||
179 | // _startOriginArray is the location of the center of rotation | ||
180 | // in view space of the element. | ||
162 | var transformCtr = this._startOriginArray[i]; | 181 | var transformCtr = this._startOriginArray[i]; |
163 | 182 | ||
164 | tMat[12] = transformCtr[0]; | 183 | tMat[12] = transformCtr[0]; |
@@ -198,6 +217,8 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { | |||
198 | var transformCtr = this._startOriginArray[i].slice(0); | 217 | var transformCtr = this._startOriginArray[i].slice(0); |
199 | transformCtr = MathUtils.transformPoint(transformCtr, curMat); | 218 | transformCtr = MathUtils.transformPoint(transformCtr, curMat); |
200 | 219 | ||
220 | console.log( "modifyElements: rotateGlobally, ctr: " + transformCtr ); | ||
221 | |||
201 | tMat[12] = transformCtr[0]; | 222 | tMat[12] = transformCtr[0]; |
202 | tMat[13] = transformCtr[1]; | 223 | tMat[13] = transformCtr[1]; |
203 | tMat[14] = transformCtr[2]; | 224 | tMat[14] = transformCtr[2]; |
@@ -267,6 +288,7 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { | |||
267 | 288 | ||
268 | viewUtils.pushViewportObj( this.target ); | 289 | viewUtils.pushViewportObj( this.target ); |
269 | var eltCtr = viewUtils.getCenterOfProjection(); | 290 | var eltCtr = viewUtils.getCenterOfProjection(); |
291 | eltCtr[2] = 0; | ||
270 | viewUtils.popViewportObj(); | 292 | viewUtils.popViewportObj(); |
271 | 293 | ||
272 | var ctrOffset = this.target.elementModel.props3D.m_transformCtr; | 294 | var ctrOffset = this.target.elementModel.props3D.m_transformCtr; |
@@ -277,17 +299,19 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { | |||
277 | } | 299 | } |
278 | 300 | ||
279 | this._origin = viewUtils.localToGlobal(eltCtr, this.target); | 301 | this._origin = viewUtils.localToGlobal(eltCtr, this.target); |
302 | console.log( "Rotate3DToolBase.captureSelectionDrawn _origin: " + this._origin ); | ||
280 | this._updateTargets(); | 303 | this._updateTargets(); |
281 | this._setTransformOrigin(false); | 304 | this._setTransformOrigin(false); |
282 | } | 305 | } |
283 | else | 306 | else |
284 | { | 307 | { |
285 | this.target = this.application.ninja.currentDocument.documentRoot; | 308 | this.target = this.application.ninja.currentDocument.documentRoot; |
286 | this._origin = drawUtils._selectionCtr.slice(0); | 309 | //this._origin = drawUtils._selectionCtr.slice(0); |
287 | this._origin[0] += this.application.ninja.stage.userContentLeft; | 310 | //this._origin[0] += this.application.ninja.stage.userContentLeft; |
288 | this._origin[1] += this.application.ninja.stage.userContentTop; | 311 | //this._origin[1] += this.application.ninja.stage.userContentTop; |
289 | this._updateTargets(); | 312 | this._updateTargets(); |
290 | this._setTransformOrigin(true); | 313 | this._origin = this.calculateMultiSelOrigin(); |
314 | this._setTransformOrigin(true); | ||
291 | } | 315 | } |
292 | } | 316 | } |
293 | else | 317 | else |
@@ -303,8 +327,15 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { | |||
303 | } | 327 | } |
304 | }, | 328 | }, |
305 | 329 | ||
330 | /* | ||
331 | _updateHandlesOrigin: { | ||
332 | value: function () { } | ||
333 | }, | ||
334 | */ | ||
335 | |||
306 | _updateTargets: { | 336 | _updateTargets: { |
307 | value: function(addToUndoStack) { | 337 | value: function(addToUndoStack) { |
338 | console.log( "Rotate3DToolBase._updateTargets" ); | ||
308 | var newStyles = [], | 339 | var newStyles = [], |
309 | previousStyles = [], | 340 | previousStyles = [], |
310 | len = this.application.ninja.selectedElements.length; | 341 | len = this.application.ninja.selectedElements.length; |
@@ -322,10 +353,14 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { | |||
322 | var eltCtr = viewUtils.getCenterOfProjection(); | 353 | var eltCtr = viewUtils.getCenterOfProjection(); |
323 | viewUtils.popViewportObj(); | 354 | viewUtils.popViewportObj(); |
324 | 355 | ||
325 | eltCtr = viewUtils.localToGlobal(eltCtr, elt); | 356 | // cache the local to global and global to local matrices |
357 | var l2gMat = viewUtils.getLocalToGlobalMatrix( elt ); | ||
358 | var g2lMat = glmat4.inverse( l2gMat, [] ); | ||
359 | eltCtr = MathUtils.transformAndDivideHomogeneousPoint( eltCtr, l2gMat ); | ||
326 | 360 | ||
327 | this._targets.push({elt:elt, mat:curMat, matInv:curMatInv, ctr:eltCtr}); | 361 | this._targets.push({elt:elt, mat:curMat, matInv:curMatInv, ctr:eltCtr, l2g:l2gMat, g2l:g2lMat}); |
328 | if(addToUndoStack) | 362 | |
363 | if(addToUndoStack) | ||
329 | { | 364 | { |
330 | var previousStyleStr = {dist:this._undoArray[i].dist, mat:MathUtils.scientificToDecimal(this._undoArray[i].mat.slice(0), 5)}; | 365 | var previousStyleStr = {dist:this._undoArray[i].dist, mat:MathUtils.scientificToDecimal(this._undoArray[i].mat.slice(0), 5)}; |
331 | 366 | ||
@@ -356,12 +391,54 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { | |||
356 | } | 391 | } |
357 | }, | 392 | }, |
358 | 393 | ||
394 | calculateMultiSelOrigin: | ||
395 | { | ||
396 | value: function() | ||
397 | { | ||
398 | var minPt, maxPt, i,j; | ||
399 | this._startOriginArray = []; | ||
400 | var len = this.application.ninja.selectedElements.length; | ||
401 | for (i = 0; i < len; i++) | ||
402 | { | ||
403 | // get the next element and localToGlobal matrix | ||
404 | elt = this._targets[i].elt; | ||
405 | var l2g = this._targets[i].l2g; | ||
406 | |||
407 | // get the element bounds in 'plane' space | ||
408 | bounds = viewUtils.getElementViewBounds3D( elt ); | ||
409 | for (j=0; j<4; j++) | ||
410 | { | ||
411 | var localPt = bounds[j]; | ||
412 | //var pt = MathUtils.transformAndDivideHomogeneousPoint( localPt, l2g ); | ||
413 | var pt = viewUtils.localToStageWorld( localPt, elt ); | ||
414 | if (!minPt) | ||
415 | { | ||
416 | minPt = pt.slice(); | ||
417 | maxPt = pt.slice(); | ||
418 | } | ||
419 | else | ||
420 | { | ||
421 | minPt[0] = Math.min(minPt[0],pt[0]); minPt[1] = Math.min(minPt[1],pt[1]); minPt[2] = Math.min(minPt[2],pt[2]); | ||
422 | maxPt[0] = Math.max(maxPt[0],pt[0]); maxPt[1] = Math.max(maxPt[1],pt[1]); maxPt[2] = Math.max(maxPt[2],pt[2]); | ||
423 | } | ||
424 | } | ||
425 | } | ||
426 | var stageWorldCtr = [ 0.5*(minPt[0] + maxPt[0]), 0.5*(minPt[1] + maxPt[1]), 0.5*(minPt[2] + maxPt[2]) ]; | ||
427 | var globalCtr = MathUtils.transformAndDivideHomogeneousPoint( stageWorldCtr, viewUtils.getStageWorldToGlobalMatrix() ); | ||
428 | console.log( "resetting _origin to: " + this._origin ); | ||
429 | |||
430 | return globalCtr; | ||
431 | } | ||
432 | }, | ||
433 | |||
359 | _setTransformOrigin: { | 434 | _setTransformOrigin: { |
360 | value: function(shouldUpdateCenter) { | 435 | value: function(shouldUpdateCenter) { |
361 | if(!this._origin) | 436 | if(!this._origin) |