diff options
Diffstat (limited to 'js/tools')
-rwxr-xr-x | js/tools/Rotate3DToolBase.js | 27 | ||||
-rwxr-xr-x | js/tools/Translate3DToolBase.js | 115 |
2 files changed, 120 insertions, 22 deletions
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, { | |||
43 | } | 43 | } |
44 | }, | 44 | }, |
45 | 45 | ||
46 | HandleMouseMove: { | ||
47 | value: function(event) { | ||
48 | if(this._escape) { | ||
49 | this._escape = false; | ||
50 | this.isDrawing = true; | ||
51 | } | ||
52 | |||
53 | if(this.isDrawing) { | ||
54 | this._hasDraw = true; // Flag for position of element | ||
55 | this.doDraw(event); | ||
56 | } else { | ||
57 | this._showFeedbackOnMouseMove(event); | ||
58 | if(this._canSnap) | ||
59 | { | ||
60 | this.doSnap(event); | ||
61 | } | ||
62 | } | ||
63 | |||
64 | this.DrawHandles(this._delta); | ||
65 | |||
66 | if(this._canSnap) | ||
67 | { | ||
68 | snapManager.drawLastHit(); | ||
69 | } | ||
70 | } | ||
71 | }, | ||
72 | |||
46 | modifyElements: { | 73 | modifyElements: { |
47 | value: function(data, event) { | 74 | value: function(data, event) { |
48 | var mat, | 75 | var mat, |
diff --git a/js/tools/Translate3DToolBase.js b/js/tools/Translate3DToolBase.js index a39dafad..41dbb3ae 100755 --- a/js/tools/Translate3DToolBase.js +++ b/js/tools/Translate3DToolBase.js | |||
@@ -296,42 +296,113 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, | |||
296 | viewUtils.popViewportObj(); | 296 | viewUtils.popViewportObj(); |
297 | ctr[2] = 0; | 297 | ctr[2] = 0; |
298 | 298 | ||
299 | // var ctrOffset = item.elementModel.props3D.m_transformCtr; | ||
300 | // if(ctrOffset) | ||
301 | // { | ||
302 | // ctr = vecUtils.vecAdd(3, ctr, ctrOffset); | ||
303 | // } | ||
304 | |||
305 | this._origin = viewUtils.localToGlobal(ctr, item); | 299 | this._origin = viewUtils.localToGlobal(ctr, item); |
306 | } | 300 | } |
307 | else | 301 | else |
308 | { | 302 | { |
309 | if(this._origin) | 303 | this._origin = undefined; |
304 | this._origin = this.calculateMultiSelOrigin(); | ||
305 | } | ||
306 | } | ||
307 | } | ||
308 | }, | ||
309 | |||
310 | captureSelectionDrawn: { | ||
311 | value: function(event){ | ||
312 | this._origin = null; | ||
313 | this._targets = []; | ||
314 | this._startOriginArray = null; | ||
315 | |||
316 | var len = this.application.ninja.selectedElements.length; | ||
317 | if(len) | ||
318 | { | ||
319 | if(len === 1) | ||
320 | { | ||
321 | this.target = this.application.ninja.selectedElements[0]; | ||
322 | drawUtils.addElement(this.target); | ||
323 | |||
324 | viewUtils.pushViewportObj( this.target ); | ||
325 | var eltCtr = viewUtils.getCenterOfProjection(); | ||
326 | eltCtr[2] = 0; | ||
327 | viewUtils.popViewportObj(); | ||
328 | |||
329 | var ctrOffset = this.target.elementModel.props3D.m_transformCtr; | ||
330 | if(ctrOffset) | ||
331 | { | ||
332 | eltCtr[2] = 0; | ||
333 | eltCtr = vecUtils.vecAdd(3, eltCtr, ctrOffset); | ||
334 | } | ||
335 | |||
336 | this._origin = viewUtils.localToGlobal(eltCtr, this.target); | ||
337 | console.log( "Rotate3DToolBase.captureSelectionDrawn _origin: " + this._origin ); | ||
338 | this._updateTargets(); | ||
339 | //this._setTransformOrigin(false); | ||
340 | } | ||
341 | else | ||
342 | { | ||
343 | this.target = this.application.ninja.currentDocument.documentRoot; | ||
344 | //this._origin = drawUtils._selectionCtr.slice(0); | ||
345 | //this._origin[0] += this.application.ninja.stage.userContentLeft; | ||
346 | //this._origin[1] += this.application.ninja.stage.userContentTop; | ||
347 | this._updateTargets(); | ||
348 | this._origin = this.calculateMultiSelOrigin(); | ||
349 | //this._setTransformOrigin(true); | ||
350 | } | ||
351 | } | ||
352 | else | ||
353 | { | ||
354 | this.target = null; | ||
355 | } | ||
356 | this.DrawHandles(); | ||
357 | |||
358 | if(event) | ||
359 | { | ||
360 | this.eventManager.removeEventListener("selectionDrawn", this, true); | ||
361 | } | ||
362 | } | ||
363 | }, | ||
364 | |||
365 | calculateMultiSelOrigin: | ||
366 | { | ||
367 | value: function() | ||
368 | { | ||
369 | var minPt, maxPt, i,j; | ||
370 | this._startOriginArray = []; | ||
371 | var len = this.application.ninja.selectedElements.length; | ||
372 | for (i = 0; i < len; i++) | ||
373 | { | ||
374 | // get the next element and localToGlobal matrix | ||
375 | elt = this._targets[i].elt; | ||
376 | var l2g = this._targets[i].l2g; | ||
377 | |||
378 | // get the element bounds in 'plane' space | ||
379 | bounds = viewUtils.getElementViewBounds3D( elt ); | ||
380 | for (j=0; j<4; j++) | ||
381 | { | ||
382 | var localPt = bounds[j]; | ||
383 | //var pt = MathUtils.transformAndDivideHomogeneousPoint( localPt, l2g ); | ||
384 | var pt = viewUtils.localToStageWorld( localPt, elt ); | ||
385 | if (!minPt) | ||
310 | { | 386 | { |
311 | if(this._delta) | 387 | minPt = pt.slice(); |
312 | { | 388 | maxPt = pt.slice(); |
313 | if(this._handleMode !== null) | ||
314 | { | ||
315 | // this._origin[this._handleMode] = this._delta; | ||
316 | } | ||
317 | else | ||
318 | { | ||
319 | this._origin[0] += this._delta[0]; | ||
320 | this._origin[1] += this._delta[1]; | ||
321 | } | ||
322 | } | ||
323 | } | 389 | } |
324 | else | 390 | else |
325 | { | 391 | { |
326 | this._origin = drawUtils._selectionCtr.slice(0); | 392 | minPt[0] = Math.min(minPt[0],pt[0]); minPt[1] = Math.min(minPt[1],pt[1]); minPt[2] = Math.min(minPt[2],pt[2]); |
327 | this._origin[0] += this.application.ninja.stage.userContentLeft; | 393 | maxPt[0] = Math.max(maxPt[0],pt[0]); maxPt[1] = Math.max(maxPt[1],pt[1]); maxPt[2] = Math.max(maxPt[2],pt[2]); |
328 | this._origin[1] += this.application.ninja.stage.userContentTop; | ||
329 | } | 394 | } |
330 | } | 395 | } |
331 | } | 396 | } |
397 | var stageWorldCtr = [ 0.5*(minPt[0] + maxPt[0]), 0.5*(minPt[1] + maxPt[1]), 0.5*(minPt[2] + maxPt[2]) ]; | ||
398 | var globalCtr = MathUtils.transformAndDivideHomogeneousPoint( stageWorldCtr, viewUtils.getStageWorldToGlobalMatrix() ); | ||
399 | console.log( "resetting _origin to: " + this._origin ); | ||
400 | |||
401 | return globalCtr; | ||
332 | } | 402 | } |
333 | }, | 403 | }, |
334 | 404 | ||
405 | |||
335 | DrawHandles: { | 406 | DrawHandles: { |
336 | value: function (delta) { | 407 | value: function (delta) { |
337 | this.application.ninja.stage.clearDrawingCanvas(); | 408 | this.application.ninja.stage.clearDrawingCanvas(); |