aboutsummaryrefslogtreecommitdiff
path: root/js/tools
diff options
context:
space:
mode:
Diffstat (limited to 'js/tools')
-rwxr-xr-xjs/tools/Rotate3DToolBase.js195
-rwxr-xr-xjs/tools/RotateObject3DTool.js141
-rwxr-xr-xjs/tools/RotateStage3DTool.js8
-rwxr-xr-xjs/tools/Translate3DToolBase.js255
-rwxr-xr-xjs/tools/TranslateObject3DTool.js1
-rwxr-xr-xjs/tools/modifier-tool-base.js20
6 files changed, 494 insertions, 126 deletions
diff --git a/js/tools/Rotate3DToolBase.js b/js/tools/Rotate3DToolBase.js
index 696408bf..d08b3a31 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
19exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { 20exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
20 _canSnap: { value: false }, 21 _canSnap: { value: false },
@@ -42,6 +43,33 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
42 } 43 }
43 }, 44 },
44 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
45 modifyElements: { 73 modifyElements: {
46 value: function(data, event) { 74 value: function(data, event) {
47 var mat, 75 var mat,
@@ -53,20 +81,31 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
53 { 81 {
54 if(this._activateOriginHandle) 82 if(this._activateOriginHandle)
55 { 83 {
56 // move the transform origin handle 84 // move the transform origin handle directly to the snap point (pt1)
57 var dx = pt1.x - pt0.x; 85 this._origin[0] = pt1.x;
58 var dy = pt1.y - pt0.y; 86 this._origin[1] = pt1.y;
59 this._origin[0] += dx; 87 this._origin[2] = pt1.z;
60 this._origin[1] += dy; 88
89 var sw2gMat = viewUtils.getStageWorldToGlobalMatrix();
90 var g2swMat = glmat4.inverse( sw2gMat, [] );
91 var swOrigin = MathUtils.transformAndDivideHomogeneousPoint( this._origin, g2swMat );
92 //console.log( "modifyElements, _origin: " + this._origin + ", in stageWorld: " + swOrigin );
61 93
62 var len = this._targets.length; 94 var len = this._targets.length;
63 if(len === 1) 95 if(len === 1)
64 { 96 {
65 this._startOriginArray[0][0] += dx; 97 var g2lMat = this._targets[0].g2l;
66 this._startOriginArray[0][1] += dy; 98 var localOrigin = MathUtils.transformAndDivideHomogeneousPoint( this._origin, g2lMat );
99 var elt = this._targets[0].elt;
100 viewUtils.pushViewportObj( elt );
101 var viewOrigin = viewUtils.screenToView( localOrigin[0], localOrigin[1], localOrigin[2] );
102 viewUtils.popViewportObj();
103 this._startOriginArray[0] = viewOrigin;
104 //console.log( "Rotate3DToolBase.modifyElements, _startOriginArray[0]: " + this._startOriginArray[0] );
67 } 105 }
68 this.downPoint.x = pt1.x; 106 this.downPoint.x = pt1.x;
69 this.downPoint.y = pt1.y; 107 this.downPoint.y = pt1.y;
108 this.downPoint.z = pt1.z;
70 this.DrawHandles(); 109 this.DrawHandles();
71 return; 110 return;
72 } 111 }
@@ -133,8 +172,10 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
133 } 172 }
134 } 173 }
135 174
175
136 if(this._inLocalMode && (this._targets.length === 1) ) 176 if(this._inLocalMode && (this._targets.length === 1) )
137 { 177 {
178 console.log( "modifyElements: rotateLocally " );
138 this._rotateLocally(mat); 179 this._rotateLocally(mat);
139 } 180 }
140 else 181 else
@@ -159,6 +200,8 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
159 // pre-translate by the transformation center 200 // pre-translate by the transformation center
160 var tMat = Matrix.I(4); 201 var tMat = Matrix.I(4);
161 202
203 // _startOriginArray is the location of the center of rotation
204 // in view space of the element.
162 var transformCtr = this._startOriginArray[i]; 205 var transformCtr = this._startOriginArray[i];
163 206
164 tMat[12] = transformCtr[0]; 207 tMat[12] = transformCtr[0];
@@ -198,6 +241,8 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
198 var transformCtr = this._startOriginArray[i].slice(0); 241 var transformCtr = this._startOriginArray[i].slice(0);
199 transformCtr = MathUtils.transformPoint(transformCtr, curMat); 242 transformCtr = MathUtils.transformPoint(transformCtr, curMat);
200 243
244 console.log( "modifyElements: rotateGlobally, ctr: " + transformCtr );
245
201 tMat[12] = transformCtr[0]; 246 tMat[12] = transformCtr[0];
202 tMat[13] = transformCtr[1]; 247 tMat[13] = transformCtr[1];
203 tMat[14] = transformCtr[2]; 248 tMat[14] = transformCtr[2];
@@ -267,6 +312,7 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
267 312
268 viewUtils.pushViewportObj( this.target ); 313 viewUtils.pushViewportObj( this.target );
269 var eltCtr = viewUtils.getCenterOfProjection(); 314 var eltCtr = viewUtils.getCenterOfProjection();
315 eltCtr[2] = 0;
270 viewUtils.popViewportObj(); 316 viewUtils.popViewportObj();
271 317
272 var ctrOffset = this.target.elementModel.props3D.m_transformCtr; 318 var ctrOffset = this.target.elementModel.props3D.m_transformCtr;
@@ -277,17 +323,19 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
277 } 323 }
278 324
279 this._origin = viewUtils.localToGlobal(eltCtr, this.target); 325 this._origin = viewUtils.localToGlobal(eltCtr, this.target);
326 console.log( "Rotate3DToolBase.captureSelectionDrawn _origin: " + this._origin );
280 this._updateTargets(); 327 this._updateTargets();
281 this._setTransformOrigin(false); 328 this._setTransformOrigin(false);
282 } 329 }
283 else 330 else
284 { 331 {
285 this.target = this.application.ninja.currentDocument.documentRoot; 332 this.target = this.application.ninja.currentDocument.documentRoot;
286 this._origin = drawUtils._selectionCtr.slice(0); 333 //this._origin = drawUtils._selectionCtr.slice(0);
287 this._origin[0] += this.application.ninja.stage.userContentLeft; 334 //this._origin[0] += this.application.ninja.stage.userContentLeft;
288 this._origin[1] += this.application.ninja.stage.userContentTop; 335 //this._origin[1] += this.application.ninja.stage.userContentTop;
289 this._updateTargets(); 336 this._updateTargets();
290 this._setTransformOrigin(true); 337 this._origin = this.calculateMultiSelOrigin();
338 this._setTransformOrigin(true);
291 } 339 }
292 } 340 }
293 else 341 else
@@ -303,8 +351,15 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
303 } 351 }
304 }, 352 },
305 353
354 /*
355 _updateHandlesOrigin: {
356 value: function () { }
357 },
358 */
359
306 _updateTargets: { 360 _updateTargets: {
307 value: function(addToUndoStack) { 361 value: function(addToUndoStack) {
362 console.log( "Rotate3DToolBase._updateTargets" );
308 var newStyles = [], 363 var newStyles = [],
309 previousStyles = [], 364 previousStyles = [],
310 len = this.application.ninja.selectedElements.length; 365 len = this.application.ninja.selectedElements.length;
@@ -322,10 +377,14 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
322 var eltCtr = viewUtils.getCenterOfProjection(); 377 var eltCtr = viewUtils.getCenterOfProjection();
323 viewUtils.popViewportObj(); 378 viewUtils.popViewportObj();
324 379
325 eltCtr = viewUtils.localToGlobal(eltCtr, elt); 380 // cache the local to global and global to local matrices
381 var l2gMat = viewUtils.getLocalToGlobalMatrix( elt );
382 var g2lMat = glmat4.inverse( l2gMat, [] );
383 eltCtr = MathUtils.transformAndDivideHomogeneousPoint( eltCtr, l2gMat );
326 384
327 this._targets.push({elt:elt, mat:curMat, matInv:curMatInv, ctr:eltCtr}); 385 this._targets.push({elt:elt, mat:curMat, matInv:curMatInv, ctr:eltCtr, l2g:l2gMat, g2l:g2lMat});
328 if(addToUndoStack) 386
387 if(addToUndoStack)
329 { 388 {
330 var previousStyleStr = {dist:this._undoArray[i].dist, mat:MathUtils.scientificToDecimal(this._undoArray[i].mat.slice(0), 5)}; 389 var previousStyleStr = {dist:this._undoArray[i].dist, mat:MathUtils.scientificToDecimal(this._undoArray[i].mat.slice(0), 5)};
331 390
@@ -356,12 +415,54 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
356 } 415 }
357 }, 416 },
358 417
418 calculateMultiSelOrigin:
419 {
420 value: function()
421 {
422 var minPt, maxPt, i,j;
423 this._startOriginArray = [];
424 var len = this.application.ninja.selectedElements.length;
425 for (i = 0; i < len; i++)
426 {
</