diff options
Diffstat (limited to 'js/tools/Translate3DToolBase.js')
-rwxr-xr-x | js/tools/Translate3DToolBase.js | 111 |
1 files changed, 82 insertions, 29 deletions
diff --git a/js/tools/Translate3DToolBase.js b/js/tools/Translate3DToolBase.js index 24a68ad1..07b6d04d 100755 --- a/js/tools/Translate3DToolBase.js +++ b/js/tools/Translate3DToolBase.js | |||
@@ -18,6 +18,7 @@ var Montage = require("montage/core/core").Montage, | |||
18 | exports.Translate3DToolBase = Montage.create(ModifierToolBase, | 18 | exports.Translate3DToolBase = Montage.create(ModifierToolBase, |
19 | { | 19 | { |
20 | _inLocalMode: { value: true, enumerable: true }, | 20 | _inLocalMode: { value: true, enumerable: true }, |
21 | _clickedOnStage: { value: false }, | ||
21 | 22 | ||
22 | HandleDoubleClick : { | 23 | HandleDoubleClick : { |
23 | value : function() | 24 | value : function() |
@@ -47,17 +48,33 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, | |||
47 | delta[1] = 0; | 48 | delta[1] = 0; |
48 | break; | 49 | break; |
49 | } | 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 | } | ||
50 | 59 | ||
51 | this._updateDelta(delta, this._handleMode); | ||
52 | } | 60 | } |
53 | else if(this._mode === 1) | 61 | else |
54 | { | 62 | { |
55 | delta[2] = delta[1]; | 63 | if(this._mode === 1) |
56 | delta[0] = 0; | 64 | { |
57 | 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); | ||
58 | } | 74 | } |
59 | 75 | ||
60 | var transMat = Matrix.Translation( delta ); | 76 | var transMat = Matrix.Translation( delta ); |
77 | |||
61 | if(this._inLocalMode && (this._targets.length === 1) ) | 78 | if(this._inLocalMode && (this._targets.length === 1) ) |
62 | { | 79 | { |
63 | this._translateLocally(transMat); | 80 | this._translateLocally(transMat); |
@@ -139,7 +156,7 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, | |||
139 | 156 | ||
140 | var shouldUpdateStartMat = true; | 157 | var shouldUpdateStartMat = true; |
141 | 158 | ||
142 | if(this._clickedObject === this.application.ninja.currentDocument.documentRoot) | 159 | if(this._clickedOnStage) |
143 | { | 160 | { |
144 | shouldUpdateStartMat = false; | 161 | shouldUpdateStartMat = false; |
145 | } | 162 | } |
@@ -152,11 +169,15 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, | |||
152 | { | 169 | { |
153 | item = this._targets[i]; | 170 | item = this._targets[i]; |
154 | elt = item.elt; | 171 | elt = item.elt; |
155 | curMat = item.mat; | 172 | curMat = item.mat.slice(0); |
156 | |||
157 | glmat4.multiply(curMat, qMat, curMat); | ||
158 | 173 | ||
159 | 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); | ||
160 | 181 | ||
161 | if(shouldUpdateStartMat) | 182 | if(shouldUpdateStartMat) |
162 | { | 183 | { |
@@ -198,6 +219,19 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, | |||
198 | "translateTool", | 219 | "translateTool", |
199 | previousStyles | 220 | previousStyles |
200 | ); | 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; | ||
201 | } | 235 | } |
202 | // Save previous value for undo/redo | 236 | // Save previous value for undo/redo |
203 | this._undoArray = []; | 237 | this._undoArray = []; |
@@ -232,7 +266,7 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, | |||
232 | } | 266 | } |
233 | }, | 267 | }, |
234 | 268 | ||
235 | _getHandlesOrigin: { | 269 | _updateHandlesOrigin: { |
236 | value: function () { | 270 | value: function () { |
237 | var ctr; | 271 | var ctr; |
238 | 272 | ||
@@ -243,30 +277,43 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, | |||
243 | { | 277 | { |
244 | var item = this._target; | 278 | var item = this._target; |
245 | viewUtils.pushViewportObj( item ); | 279 | viewUtils.pushViewportObj( item ); |
246 | var ctr = viewUtils.getCenterOfProjection(); | 280 | ctr = viewUtils.getCenterOfProjection(); |
247 | viewUtils.popViewportObj(); | 281 | viewUtils.popViewportObj(); |
248 | ctr[2] = 0; | 282 | ctr[2] = 0; |
249 | 283 | ||
250 | var ctrOffset = item.elementModel.props3D.m_transformCtr; | 284 | // var ctrOffset = item.elementModel.props3D.m_transformCtr; |
251 | if(ctrOffset) | 285 | // if(ctrOffset) |
252 | { | 286 | // { |
253 | ctr = vecUtils.vecAdd(3, ctr, ctrOffset); | 287 | // ctr = vecUtils.vecAdd(3, ctr, ctrOffset); |
254 | } | 288 | // } |
255 | 289 | ||
256 | ctr = viewUtils.localToGlobal(ctr, item); | 290 | this._origin = viewUtils.localToGlobal(ctr, item); |
257 | } | 291 | } |
258 | else | 292 | else |
259 | { | 293 | { |
260 | ctr = drawUtils._selectionCtr.slice(0); | 294 | if(this._origin) |
261 | ctr[0] += this.application.ninja.stage.userContentLeft; | 295 | { |
262 | ctr[1] += this.application.ninja.stage.userContentTop; | 296 | if(this._delta) |
263 | 297 | { | |
264 | // ctr[0] += this.m_deltaPoint[0]; | 298 | if(this._handleMode !== null) |
265 | // 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 | } | ||
266 | } | 315 | } |
267 | } | 316 | } |
268 | |||
269 | return ctr; | ||
270 | } | 317 | } |
271 | }, | 318 | }, |
272 | 319 | ||
@@ -304,7 +351,9 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, | |||
304 | 351 | ||
305 | // Draw tool handles | 352 | // Draw tool handles |
306 | 353 | ||
307 | var base = this._getHandlesOrigin(); | 354 | this._updateHandlesOrigin(); |
355 | var base = this._origin.slice(0); | ||
356 | |||
308 | var len = this.application.ninja.selectedElements.length; | 357 | var len = this.application.ninja.selectedElements.length; |
309 | var lMode = this._inLocalMode; | 358 | var lMode = this._inLocalMode; |
310 | if(len === 1) | 359 | if(len === 1) |
@@ -334,14 +383,18 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, | |||
334 | this._handles[1]._strokeStyle = 'rgba(0, 255, 0, 0.2)'; | 383 | this._handles[1]._strokeStyle = 'rgba(0, 255, 0, 0.2)'; |
335 | break; | 384 | break; |
336 | } | 385 | } |
386 | if( delta && (len > 1) ) | ||
387 | { | ||
388 | base[this._handleMode] += ~~delta; | ||
389 | } | ||
337 | } | 390 | } |
338 | this._handles[0].draw(base, item, lMode); | 391 | this._handles[0].draw(base, item, lMode); |
339 | this._handles[1].draw(base, item, lMode); | 392 | this._handles[1].draw(base, item, lMode); |
340 | this._handles[2].draw(base, item, lMode); | 393 | this._handles[2].draw(base, item, lMode); |
341 | 394 | ||
342 | if(delta) | 395 | if(delta && (this._handleMode !== null)) |
343 | { | 396 | { |
344 | this._handles[this._handleMode].drawDelta(delta); | 397 | this._handles[this._handleMode].drawDelta(~~delta); |
345 | } | 398 | } |
346 | 399 | ||
347 | this._handles[0]._strokeStyle = 'rgba(255, 0, 0, 1)'; | 400 | this._handles[0]._strokeStyle = 'rgba(255, 0, 0, 1)'; |