aboutsummaryrefslogtreecommitdiff
path: root/js/tools
diff options
context:
space:
mode:
Diffstat (limited to 'js/tools')
-rwxr-xr-xjs/tools/Rotate3DToolBase.js155
-rwxr-xr-xjs/tools/modifier-tool-base.js6
2 files changed, 120 insertions, 41 deletions
diff --git a/js/tools/Rotate3DToolBase.js b/js/tools/Rotate3DToolBase.js
index e0c5abcb..402023ff 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 },
@@ -61,14 +62,22 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
61 this._origin[0] += dx; 62 this._origin[0] += dx;
62 this._origin[1] += dy; 63 this._origin[1] += dy;
63 this._origin[2] += dz; 64 this._origin[2] += dz;
65 console.log( "modifyElements, _origin: " + this._origin );
64 66
65 var len = this._targets.length; 67 var len = this._targets.length;
66 if(len === 1) 68 if(len === 1)
67 { 69 {
68 this._startOriginArray[0][0] += dx; 70// this._startOriginArray[0][0] += dx;
69 this._startOriginArray[0][1] += dy; 71// this._startOriginArray[0][1] += dy;
70 this._startOriginArray[0][2] += dz; 72// this._startOriginArray[0][2] += dz;
71 console.log( "Rotate3DToolBase.modifyElements, _startOriginArray[0]: " + this._startOriginArray[0] ); 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] );
72 } 81 }
73 this.downPoint.x = pt1.x; 82 this.downPoint.x = pt1.x;
74 this.downPoint.y = pt1.y; 83 this.downPoint.y = pt1.y;
@@ -139,8 +148,10 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
139 } 148 }
140 } 149 }
141 150
151
142 if(this._inLocalMode && (this._targets.length === 1) ) 152 if(this._inLocalMode && (this._targets.length === 1) )
143 { 153 {
154 console.log( "modifyElements: rotateLocally " );
144 this._rotateLocally(mat); 155 this._rotateLocally(mat);
145 } 156 }
146 else 157 else
@@ -166,22 +177,9 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
166 var tMat = Matrix.I(4); 177 var tMat = Matrix.I(4);
167 178
168 // _startOriginArray is the location of the center of rotation 179 // _startOriginArray is the location of the center of rotation
169 // in view space of the element. It is currently calculated during the drag 180 // in view space of the element.
170 // using delta's in global screen space, hence wrong.
171 // We can put the transformCenter back in element view space here, however
172 // it would be (much) more efficient to cache the localToGlobal and
173 // globalToLocal matrices.
174 var transformCtr = this._startOriginArray[i]; 181 var transformCtr = this._startOriginArray[i];
175 182
176 var localToGlobalMat = viewUtils.getLocalToGlobalMatrix( elt );
177 var globalToLocalMat = glmat4.inverse( localToGlobalMat, [] );
178 var newTransformCtr = MathUtils.transformAndDivideHomogeneousPoint( this._origin, globalToLocalMat );
179 viewUtils.pushViewportObj( elt );
180 newTransformCtr = viewUtils.screenToView( newTransformCtr[0], newTransformCtr[1], newTransformCtr[2] );
181 viewUtils.popViewportObj( elt );
182 //console.log( "transformCtr: " + newTransformCtr );
183 transformCtr = newTransformCtr;
184
185 tMat[12] = transformCtr[0]; 183 tMat[12] = transformCtr[0];
186 tMat[13] = transformCtr[1]; 184 tMat[13] = transformCtr[1];
187 tMat[14] = transformCtr[2]; 185 tMat[14] = transformCtr[2];
@@ -219,6 +217,8 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
219 var transformCtr = this._startOriginArray[i].slice(0); 217 var transformCtr = this._startOriginArray[i].slice(0);
220 transformCtr = MathUtils.transformPoint(transformCtr, curMat); 218 transformCtr = MathUtils.transformPoint(transformCtr, curMat);
221 219
220 console.log( "modifyElements: rotateGlobally, ctr: " + transformCtr );
221
222 tMat[12] = transformCtr[0]; 222 tMat[12] = transformCtr[0];
223 tMat[13] = transformCtr[1]; 223 tMat[13] = transformCtr[1];
224 tMat[14] = transformCtr[2]; 224 tMat[14] = transformCtr[2];
@@ -306,11 +306,12 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
306 else 306 else
307 { 307 {
308 this.target = this.application.ninja.currentDocument.documentRoot; 308 this.target = this.application.ninja.currentDocument.documentRoot;
309 this._origin = drawUtils._selectionCtr.slice(0); 309 //this._origin = drawUtils._selectionCtr.slice(0);
310 this._origin[0] += this.application.ninja.stage.userContentLeft; 310 //this._origin[0] += this.application.ninja.stage.userContentLeft;
311 this._origin[1] += this.application.ninja.stage.userContentTop; 311 //this._origin[1] += this.application.ninja.stage.userContentTop;
312 this._updateTargets(); 312 this._updateTargets();
313 this._setTransformOrigin(true); 313 this._origin = this.calculateMultiSelOrigin();
314 this._setTransformOrigin(true);
314 } 315 }
315 } 316 }
316 else 317 else
@@ -326,8 +327,15 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
326 } 327 }
327 }, 328 },
328 329
330 /*
331 _updateHandlesOrigin: {
332 value: function () { }
333 },
334 */
335
329 _updateTargets: { 336 _updateTargets: {
330 value: function(addToUndoStack) { 337 value: function(addToUndoStack) {
338 console.log( "Rotate3DToolBase._updateTargets" );
331 var newStyles = [], 339 var newStyles = [],
332 previousStyles = [], 340 previousStyles = [],
333 len = this.application.ninja.selectedElements.length; 341 len = this.application.ninja.selectedElements.length;
@@ -345,10 +353,14 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
345 var eltCtr = viewUtils.getCenterOfProjection(); 353 var eltCtr = viewUtils.getCenterOfProjection();
346 viewUtils.popViewportObj(); 354 viewUtils.popViewportObj();
347 355
348 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 );
349 360
350 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});
351 if(addToUndoStack) 362
363 if(addToUndoStack)
352 { 364 {
353 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)};
354 366
@@ -379,12 +391,54 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
379 } 391 }
380 }, 392 },
381 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
382 _setTransformOrigin: { 434 _setTransformOrigin: {
383 value: function(shouldUpdateCenter) { 435 value: function(shouldUpdateCenter) {
384 if(!this._origin) 436 if(!this._origin)
385 { 437 {
386 return; 438 return;
387 } 439 }
440 console.log( "_setTransformOrigin, _activateOriginHandle: " + this._activateOriginHandle );
441
388 var len = this._targets.length; 442 var len = this._targets.length;
389 var elt, 443 var elt,
390 eltCtr, 444 eltCtr,
@@ -396,13 +450,14 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
396 450
397 if(shouldUpdateCenter) 451 if(shouldUpdateCenter)
398 { 452 {
399 eltCtr = this._targets[0].ctr; 453// eltCtr = this._targets[0].ctr;
400 ctrOffset = vecUtils.vecSubtract(3, this._origin, eltCtr); 454// c