aboutsummaryrefslogtreecommitdiff
path: root/js/tools
diff options
context:
space:
mode:
Diffstat (limited to 'js/tools')
-rwxr-xr-xjs/tools/Rotate3DToolBase.js236
-rwxr-xr-xjs/tools/RotateObject3DTool.js141
-rwxr-xr-xjs/tools/RotateStage3DTool.js7
-rwxr-xr-xjs/tools/Translate3DToolBase.js133
-rwxr-xr-xjs/tools/TranslateObject3DTool.js1
-rwxr-xr-xjs/tools/modifier-tool-base.js17
6 files changed, 463 insertions, 72 deletions
diff --git a/js/tools/Rotate3DToolBase.js b/js/tools/Rotate3DToolBase.js
index 2e121b0b..6bd92353 100755
--- a/js/tools/Rotate3DToolBase.js
+++ b/js/tools/Rotate3DToolBase.js
@@ -46,25 +46,70 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
46 } 46 }
47 }, 47 },
48 48
49 HandleMouseMove: {
50 value: function(event) {
51 if(this._escape) {
52 this._escape = false;
53 this.isDrawing = true;
54 }
55
56 if(this.isDrawing) {
57 this._hasDraw = true; // Flag for position of element
58 this.doDraw(event);
59 } else {
60 this._showFeedbackOnMouseMove(event);
61 if(this._canSnap)
62 {
63 this.doSnap(event);
64 }
65 }
66
67 this.DrawHandles(this._delta);
68
69 if(this._canSnap)
70 {
71 snapManager.drawLastHit();
72 }
73 }
74 },
75
49 modifyElements: { 76 modifyElements: {
50 value: function(data, event) { 77 value: function(data, event) {
51 var mat, angle, pt0 = data.pt0, pt1 = data.pt1; 78 var mat,
52 79 angle,
53 if(this._handleMode !== null) { 80 pt0 = data.pt0,
54 if(this._activateOriginHandle) { 81 pt1 = data.pt1;
55 // move the transform origin handle 82
56 var dx = pt1.x - pt0.x; 83 if(this._handleMode !== null)
57 var dy = pt1.y - pt0.y; 84 {
58 this._origin[0] += dx; 85 if(this._activateOriginHandle)
59 this._origin[1] += dy; 86 {
60 87 // move the transform origin handle directly to the snap point (pt1)
61 if( this.rotateStage || (this.application.ninja.selectedElements.length === 1)) { 88 this._origin[0] = pt1.x;
62 this._startOriginArray[0][0] += dx; 89 this._origin[1] = pt1.y;
63 this._startOriginArray[0][1] += dy; 90 this._origin[2] = pt1.z;
91
92 var sw2gMat = viewUtils.getStageWorldToGlobalMatrix();
93 var g2swMat = glmat4.inverse( sw2gMat, [] );
94 var swOrigin = MathUtils.transformAndDivideHomogeneousPoint( this._origin, g2swMat );
95 //console.log( "modifyElements, _origin: " + this._origin + ", in stageWorld: " + swOrigin );
96
97 var len = this._targets.length;
98 if(len === 1)
99 {
100 var g2lMat = this._targets[0].g2l;
101 var localOrigin = MathUtils.transformAndDivideHomogeneousPoint( this._origin, g2lMat );
102 var elt = this._targets[0].elt;
103 viewUtils.pushViewportObj( elt );
104 var viewOrigin = viewUtils.screenToView( localOrigin[0], localOrigin[1], localOrigin[2] );
105 viewUtils.popViewportObj();
106 this._startOriginArray[0] = viewOrigin;
107 //console.log( "Rotate3DToolBase.modifyElements, _startOriginArray[0]: " + this._startOriginArray[0] );
64 } 108 }
65 109
66 this.downPoint.x = pt1.x; 110 this.downPoint.x = pt1.x;
67 this.downPoint.y = pt1.y; 111 this.downPoint.y = pt1.y;
112 this.downPoint.z = pt1.z;
68 this.DrawHandles(); 113 this.DrawHandles();
69 return; 114 return;
70 } 115 }
@@ -133,6 +178,7 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
133 178
134 if(this._inLocalMode && (this.application.ninja.selectedElements.length === 1 || this.rotateStage) ) 179 if(this._inLocalMode && (this.application.ninja.selectedElements.length === 1 || this.rotateStage) )
135 { 180 {
181 console.log( "modifyElements: rotateLocally " );
136 this._rotateLocally(mat); 182 this._rotateLocally(mat);
137 } 183 }
138 else 184 else
@@ -154,12 +200,14 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
154 } 200 }
155 var len = selectedElements.length; 201 var len = selectedElements.length;
156 for(var i = 0; i < len; i++) { 202 for(var i = 0; i < len; i++) {
157 var elt = selectedElements[i].elementModel.getProperty("elt"); 203 var elt = selectedElements[i];
158 var curMat = selectedElements[i].elementModel.getProperty("mat"); 204 var curMat = elt.elementModel.getProperty("mat");
159 205
160 // pre-translate by the transformation center 206 // pre-translate by the transformation center
161 var tMat = Matrix.I(4); 207 var tMat = Matrix.I(4);
162 208
209 // _startOriginArray is the location of the center of rotation
210 // in view space of the element.
163 var transformCtr = this._startOriginArray[i]; 211 var transformCtr = this._startOriginArray[i];
164 212
165 tMat[12] = transformCtr[0]; 213 tMat[12] = transformCtr[0];
@@ -179,7 +227,7 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
179 glmat4.multiply(mat, tMat, mat); 227 glmat4.multiply(mat, tMat, mat);
180 228
181 // while moving, set inline style to improve performance 229 // while moving, set inline style to improve performance
182 viewUtils.setMatrixForElement(selectedElements[i], mat, true ); 230 viewUtils.setMatrixForElement( elt, mat, true );
183 } 231 }
184 } 232 }
185 }, 233 },
@@ -197,6 +245,8 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
197 var transformCtr = this._startOriginArray[i].slice(0); 245 var transformCtr = this._startOriginArray[i].slice(0);
198 transformCtr = MathUtils.transformPoint(transformCtr, curMat); 246 transformCtr = MathUtils.transformPoint(transformCtr, curMat);
199 247
248 console.log( "modifyElements: rotateGlobally, ctr: " + transformCtr );
249
200 tMat[12] = transformCtr[0]; 250 tMat[12] = transformCtr[0];
201 tMat[13] = transformCtr[1]; 251 tMat[13] = transformCtr[1];
202 tMat[14] = transformCtr[2]; 252 tMat[14] = transformCtr[2];
@@ -265,6 +315,7 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
265 315
266 viewUtils.pushViewportObj( this.target ); 316 viewUtils.pushViewportObj( this.target );
267 var eltCtr = viewUtils.getCenterOfProjection(); 317 var eltCtr = viewUtils.getCenterOfProjection();
318 eltCtr[2] = 0;
268 viewUtils.popViewportObj(); 319 viewUtils.popViewportObj();
269 320
270 var ctrOffset = this.target.elementModel.props3D.m_transformCtr; 321 var ctrOffset = this.target.elementModel.props3D.m_transformCtr;
@@ -275,16 +326,18 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
275 } 326 }
276 327
277 this._origin = viewUtils.localToGlobal(eltCtr, this.target); 328 this._origin = viewUtils.localToGlobal(eltCtr, this.target);
329 //console.log( "Rotate3DToolBase.captureSelectionDrawn _origin: " + this._origin );
278 this._updateTargets(); 330 this._updateTargets();
279 this._setTransformOrigin(false); 331 this._setTransformOrigin(false);
280 } 332 }
281 else 333 else
282 { 334 {
283 this.target = this.application.ninja.currentDocument.documentRoot; 335 this.target = this.application.ninja.currentDocument.documentRoot;
284 this._origin = drawUtils._selectionCtr.slice(0); 336 //this._origin = drawUtils._selectionCtr.slice(0);
285 this._origin[0] += this.application.ninja.stage.userContentLeft; 337 //this._origin[0] += this.application.ninja.stage.userContentLeft;
286 this._origin[1] += this.application.ninja.stage.userContentTop; 338 //this._origin[1] += this.application.ninja.stage.userContentTop;
287 this._updateTargets(); 339 this._updateTargets();
340 this._origin = this.calculateMultiSelOrigin();
288 this._setTransformOrigin(true); 341 this._setTransformOrigin(true);
289 } 342 }
290 } 343 }
@@ -301,17 +354,35 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
301 } 354 }
302 }, 355 },
303 356
357 /*
358 _updateHandlesOrigin: {
359 value: function () { }
360 },
361 */
362
304 _updateTargets: { 363 _updateTargets: {
305 value: function(addToUndo) { 364 value: function(addToUndo) {
306 var mod3dObject = [], self = this; 365 var mod3dObject = [],
366 self = this;
307 367
308 this.application.ninja.selectedElements.forEach(function(element) { 368 this.application.ninja.selectedElements.forEach(function(element) {
309 viewUtils.pushViewportObj(element); 369 var curMat = viewUtils.getMatrixFromElement(elt);
370 var curMatInv = glmat4.inverse(curMat, []);
371
372 viewUtils.pushViewportObj( elt );
310 var eltCtr = viewUtils.getCenterOfProjection(); 373 var eltCtr = viewUtils.getCenterOfProjection();
311 viewUtils.popViewportObj(); 374 viewUtils.popViewportObj();
312 eltCtr = viewUtils.localToGlobal(eltCtr, element); 375
376 // cache the local to global and global to local matrices
377 var l2gMat = viewUtils.getLocalToGlobalMatrix( elt );
378 var g2lMat = glmat4.inverse( l2gMat, [] );
379 eltCtr = MathUtils.transformAndDivideHomogeneousPoint( eltCtr, l2gMat );
313 380
314 element.elementModel.setProperty("ctr", eltCtr); 381 element.elementModel.setProperty("ctr", eltCtr);
382 element.elementModel.setProperty("mat", curMat);
383 element.elementModel.setProperty("matInv", curMatInv);
384 element.elementModel.setProperty("l2g", l2gMat);
385 element.elementModel.setProperty("g2l", g2lMat);
315 386
316 if(addToUndo) { 387 if(addToUndo) {
317 var previousMat = element.elementModel.getProperty("mat").slice(0); 388 var previousMat = e