aboutsummaryrefslogtreecommitdiff
path: root/js/tools/Translate3DToolBase.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/tools/Translate3DToolBase.js')
-rwxr-xr-xjs/tools/Translate3DToolBase.js112
1 files changed, 82 insertions, 30 deletions
diff --git a/js/tools/Translate3DToolBase.js b/js/tools/Translate3DToolBase.js
index 3d9191da..07b6d04d 100755
--- a/js/tools/Translate3DToolBase.js
+++ b/js/tools/Translate3DToolBase.js
@@ -10,7 +10,6 @@ Subclass TranslateObject3DTool will translate the object that was clicked.
10var Montage = require("montage/core/core").Montage, 10var Montage = require("montage/core/core").Montage,
11 ModifierToolBase = require("js/tools/modifier-tool-base").ModifierToolBase, 11 ModifierToolBase = require("js/tools/modifier-tool-base").ModifierToolBase,
12 toolHandleModule = require("js/stage/tool-handle"), 12 toolHandleModule = require("js/stage/tool-handle"),
13 snapManager = require("js/helper-classes/3D/snap-manager").SnapManager,
14 viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils, 13 viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils,
15 vecUtils = require("js/helper-classes/3D/vec-utils").VecUtils, 14 vecUtils = require("js/helper-classes/3D/vec-utils").VecUtils,
16 drawUtils = require("js/helper-classes/3D/draw-utils").DrawUtils, 15 drawUtils = require("js/helper-classes/3D/draw-utils").DrawUtils,
@@ -19,6 +18,7 @@ var Montage = require("montage/core/core").Montage,
19exports.Translate3DToolBase = Montage.create(ModifierToolBase, 18exports.Translate3DToolBase = Montage.create(ModifierToolBase,
20{ 19{
21 _inLocalMode: { value: true, enumerable: true }, 20 _inLocalMode: { value: true, enumerable: true },
21 _clickedOnStage: { value: false },
22 22
23 HandleDoubleClick : { 23 HandleDoubleClick : {
24 value : function() 24 value : function()
@@ -48,17 +48,33 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase,
48 delta[1] = 0; 48 delta[1] = 0;
49 break; 49 break;
50 } 50 }
51 if( (this.application.ninja.selectedElements.length > 1) && this._clickedOnStage )
52 {
53 this._delta = ~~(delta[this._handleMode]);
54 }
55 else
56 {
57 this._delta += ~~(delta[this._handleMode]);
58 }
51 59
52 this._updateDelta(delta, this._handleMode);
53 } 60 }
54 else if(this._mode === 1) 61 else
55 { 62 {
56 delta[2] = delta[1]; 63 if(this._mode === 1)
57 delta[0] = 0; 64 {
58 delta[1] = 0; 65 delta[2] = delta[1];
66 delta[0] = 0;
67 delta[1] = 0;
68 }
69 else
70 {
71 delta[2] = 0;
72 }
73 this._delta = delta.slice(0);
59 } 74 }
60 75
61 var transMat = Matrix.Translation( delta ); 76 var transMat = Matrix.Translation( delta );
77
62 if(this._inLocalMode && (this._targets.length === 1) ) 78 if(this._inLocalMode && (this._targets.length === 1) )
63 { 79 {
64 this._translateLocally(transMat); 80 this._translateLocally(transMat);
@@ -140,7 +156,7 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase,
140 156
141 var shouldUpdateStartMat = true; 157 var shouldUpdateStartMat = true;
142 158
143 if(this._clickedObject === this.application.ninja.currentDocument.documentRoot) 159 if(this._clickedOnStage)
144 { 160 {
145 shouldUpdateStartMat = false; 161 shouldUpdateStartMat = false;
146 } 162 }
@@ -153,11 +169,15 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase,
153 { 169 {
154 item = this._targets[i]; 170 item = this._targets[i];
155 elt = item.elt; 171 elt = item.elt;
156 curMat = item.mat; 172 curMat = item.mat.slice(0);
157
158 glmat4.multiply(curMat, qMat, curMat);
159 173
160 viewUtils.setMatrixForElement( elt, curMat, true); 174// glmat4.multiply(curMat, qMat, curMat);
175//
176// viewUtils.setMatrixForElement( elt, curMat, true);
177 curMat[12] += transMat[12];
178 curMat[13] += transMat[13];
179 curMat[14] += transMat[14];
180 viewUtils.setMatrixForElement( elt, curMat, true);
161 181
162 if(shouldUpdateStartMat) 182 if(shouldUpdateStartMat)
163 { 183 {
@@ -199,6 +219,19 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase,
199 "translateTool", 219 "translateTool",
200 previousStyles 220 previousStyles
201 ); 221 );
222 if(this._origin && this._delta)
223 {
224 if(this._handleMode !== null)
225 {
226 this._origin[this._handleMode] += this._delta;
227 }
228 else
229 {
230 this._origin[0] += this._delta[0];
231 this._origin[1] += this._delta[1];
232 }
233 }
234 this._delta = null;
202 } 235 }
203 // Save previous value for undo/redo 236 // Save previous value for undo/redo
204 this._undoArray = []; 237 this._undoArray = [];
@@ -233,7 +266,7 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase,
233 } 266 }
234 }, 267 },
235 268
236 _getHandlesOrigin: { 269 _updateHandlesOrigin: {
237 value: function () { 270 value: function () {
238 var ctr; 271 var ctr;
239 272
@@ -244,30 +277,43 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase,
244 { 277 {
245 var item = this._target; 278 var item = this._target;
246 viewUtils.pushViewportObj( item ); 279 viewUtils.pushViewportObj( item );
247 var ctr = viewUtils.getCenterOfProjection(); 280 ctr = viewUtils.getCenterOfProjection();
248 viewUtils.popViewportObj(); 281 viewUtils.popViewportObj();
249 ctr[2] = 0; 282 ctr[2] = 0;
250 283
251 var ctrOffset = item.elementModel.props3D.m_transformCtr; 284// var ctrOffset = item.elementModel.props3D.m_transformCtr;
252 if(ctrOffset) 285// if(ctrOffset)
253 { 286// {
254 ctr = vecUtils.vecAdd(3, ctr, ctrOffset); 287// ctr = vecUtils.vecAdd(3, ctr, ctrOffset);
255 } 288// }
256 289
257 ctr = viewUtils.localToGlobal(ctr, item); 290 this._origin = viewUtils.localToGlobal(ctr, item);
258 } 291 }
259 else 292 else
260 { 293 {
261 ctr = drawUtils._selectionCtr.slice(0); 294 if(this._origin)
262 ctr[0] += this.application.ninja.stage.userContentLeft; 295 {
263 ctr[1] += this.application.ninja.stage.userContentTop; 296 if(this._delta)
264 297 {
265// ctr[0] += this.m_deltaPoint[0]; 298 if(this._handleMode !== null)
266// ctr[1] += this.m_deltaPoint[1]; 299 {
300// this._origin[this._handleMode] = this._delta;
301 }
302 else
303 {
304 this._origin[0] += this._delta[0];
305 this._origin[1] += this._delta[1];
306 }
307 }
308 }
309 else
310 {
311 this._origin = drawUtils._selectionCtr.slice(0);
312 this._origin[0] += this.application.ninja.stage.userContentLeft;
313 this._origin[1] += this.application.ninja.stage.userContentTop;
314 }
267 } 315 }
268 } 316 }
269
270 return ctr;
271 } 317 }
272 }, 318 },
273 319
@@ -305,7 +351,9 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase,
305 351
306 // Draw tool handles 352 // Draw tool handles
307 353
308 var base = this._getHandlesOrigin(); 354 this._updateHandlesOrigin();
355 var base = this._origin.slice(0);
356
309 var len = this.application.ninja.selectedElements.length; 357 var len = this.application.ninja.selectedElements.length;
310 var lMode = this._inLocalMode; 358 var lMode = this._inLocalMode;
311 if(len === 1) 359 if(len === 1)
@@ -335,14 +383,18 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase,
335 this._handles[1]._strokeStyle = 'rgba(0, 255, 0, 0.2)'; 383 this._handles[1]._strokeStyle = 'rgba(0, 255, 0, 0.2)';
336 break; 384 break;
337 } 385 }
386 if( delta && (len > 1) )
387 {
388 base[this._handleMode] += ~~delta;
389 }
338 } 390 }
339 this._handles[0].draw(base, item, lMode); 391 this._handles[0].draw(base, item, lMode);
340 this._handles[1].draw(base, item, lMode); 392 this._handles[1].draw(base, item, lMode);
341 this._handles[2].draw(base, item, lMode); 393 this._handles[2].draw(base, item, lMode);
342 394
343 if(delta) 395 if(delta && (this._handleMode !== null))
344 { 396 {
345 this._handles[this._handleMode].drawDelta(delta); 397 this._handles[this._handleMode].drawDelta(~~delta);
346 } 398<