diff options
author | Ananya Sen | 2012-04-23 10:53:45 -0700 |
---|---|---|
committer | Ananya Sen | 2012-04-23 10:53:45 -0700 |
commit | 6e2d8c8b7e981de2a7ede45d707614307e811cad (patch) | |
tree | 94d5455c90439548c89d811a03d675e94cf5d27c /js/tools/Translate3DToolBase.js | |
parent | 2fafe26f74f342388b97960e7a58e3f45d8d961f (diff) | |
parent | 5a0331fc26fcc2cdc6200086109e34440a2dec6a (diff) | |
download | ninja-6e2d8c8b7e981de2a7ede45d707614307e811cad.tar.gz |
Merge branch 'refs/heads/ninja-internal-master' into Codeview-improvements
Diffstat (limited to 'js/tools/Translate3DToolBase.js')
-rwxr-xr-x | js/tools/Translate3DToolBase.js | 134 |
1 files changed, 105 insertions, 29 deletions
diff --git a/js/tools/Translate3DToolBase.js b/js/tools/Translate3DToolBase.js index 04359567..f81ce6d6 100755 --- a/js/tools/Translate3DToolBase.js +++ b/js/tools/Translate3DToolBase.js | |||
@@ -70,6 +70,7 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, | |||
70 | this._delta = delta.slice(0); | 70 | this._delta = delta.slice(0); |
71 | } | 71 | } |
72 | 72 | ||
73 | //console.log( "modifyElements delta: " + delta ); | ||
73 | var transMat = Matrix.Translation( delta ); | 74 | var transMat = Matrix.Translation( delta ); |
74 | 75 | ||
75 | //console.log( "Translate: " + delta ); | 76 | //console.log( "Translate: " + delta ); |
@@ -135,28 +136,35 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, | |||
135 | 136 | ||
136 | _translateGlobally: { | 137 | _translateGlobally: { |
137 | value: function (transMat) { | 138 | value: function (transMat) { |
138 | //console.log( "_translateGlobally, startMat: " + this._startMat + ", transMat: " + transMat ); | ||
139 | //console.log( "_translateGlobally, transMat: " + transMat ); | 139 | //console.log( "_translateGlobally, transMat: " + transMat ); |
140 | var self = this, | 140 | var selectedElements = this.application.ninja.selectedElements; |
141 | curMat = viewUtils.getMatrixFromElement( this._target ), | 141 | |
142 | var len = selectedElements.length, | ||
143 | self = this, | ||
144 | target = selectedElements[0], | ||
145 | curMat = viewUtils.getMatrixFromElement( target ), | ||
142 | matInv = glmat4.inverse(this._startMat, []), | 146 | matInv = glmat4.inverse(this._startMat, []), |
143 | nMat = glmat4.multiply(transMat, this._startMat, [] ); | 147 | nMat = glmat4.multiply(transMat, this._startMat, [] ); |
144 | // qMat = glmat4.multiply(matInv, nMat, []); | 148 | // qMat = glmat4.multiply(matInv, nMat, []); |
145 | 149 | ||
146 | if(this._mode === 1) { | 150 | if(this._mode === 1) { |
151 | if (len > 1) curMat = target.elementModel.getProperty("mat").slice(); | ||
147 | var curInv = glmat4.inverse( curMat, [] ); | 152 | var curInv = glmat4.inverse( curMat, [] ); |
148 | transMat = glmat4.multiply( nMat, curInv, [] ); | 153 | transMat = glmat4.multiply( nMat, curInv, [] ); |
149 | } | 154 | } |
150 | 155 | ||
151 | var shouldUpdateStartMat = true; | 156 | var shouldUpdateStartMat = true; |
152 | 157 | ||
153 | if(this._clickedOnStage) { | 158 | if(this._clickedOnStage || ((this._handleMode === 2) && (len > 1))) |
159 | { | ||
154 | shouldUpdateStartMat = false; | 160 | shouldUpdateStartMat = false; |
155 | } else if(this._mode !== 1) { | 161 | } |
162 | else if(this._mode !== 1) | ||
163 | { | ||
156 | this._startMat = nMat; | 164 | this._startMat = nMat; |
157 | } | 165 | } |
158 | 166 | ||
159 | this.application.ninja.selectedElements.forEach(function(element) { | 167 | selectedElements.forEach(function(element) { |
160 | curMat = element.elementModel.getProperty("mat").slice(0); | 168 | curMat = element.elementModel.getProperty("mat").slice(0); |
161 | 169 | ||
162 | // glmat4.multiply(curMat, qMat, curMat); | 170 | // glmat4.multiply(curMat, qMat, curMat); |
@@ -249,42 +257,107 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, | |||
249 | viewUtils.popViewportObj(); | 257 | viewUtils.popViewportObj(); |
250 | ctr[2] = 0; | 258 | ctr[2] = 0; |
251 | 259 | ||
252 | // var ctrOffset = item.elementModel.props3D.m_transformCtr; | ||
253 | // if(ctrOffset) | ||
254 | // { | ||
255 | // ctr = vecUtils.vecAdd(3, ctr, ctrOffset); | ||
256 | // } | ||
257 | |||
258 | this._origin = viewUtils.localToGlobal(ctr, item); | 260 | this._origin = viewUtils.localToGlobal(ctr, item); |
259 | } | 261 | } |
260 | else | 262 | else |
261 | { | 263 | { |
262 | if(this._origin) | 264 | this._origin = undefined; |
263 | { | 265 | this._origin = this.calculateMultiSelOrigin(); |
264 | if(this._delta) | 266 | } |
265 | { | 267 | } |
266 | if(this._handleMode !== null) | 268 | } |
267 | { | 269 | }, |
268 | // this._origin[this._handleMode] = this._delta; | 270 | |
269 | } | 271 | captureSelectionDrawn: { |
270 | else | 272 | value: function(event){ |
271 | { | 273 | this._origin = null; |
272 | this._origin[0] += this._delta[0]; | 274 | this._startOriginArray = null; |
273 | this._origin[1] += this._delta[1]; | 275 | |
274 | } | 276 | var len = this.application.ninja.selectedElements.length; |
275 | } | 277 | if(len) { |
278 | if(len === 1) { | ||
279 | this.target = this.application.ninja.selectedElements[0]; | ||
280 | drawUtils.addElement(this.target); | ||
281 | |||
282 | viewUtils.pushViewportObj( this.target ); | ||
283 | var eltCtr = viewUtils.getCenterOfProjection(); | ||
284 | eltCtr[2] = 0; | ||
285 | viewUtils.popViewportObj(); | ||
286 | |||
287 | var ctrOffset = this.target.elementModel.props3D.m_transformCtr; | ||
288 | if(ctrOffset) { | ||
289 | eltCtr[2] = 0; | ||
290 | eltCtr = vecUtils.vecAdd(3, eltCtr, ctrOffset); | ||
276 | } | 291 | } |
292 | |||
293 | this._origin = viewUtils.localToGlobal(eltCtr, this.target); | ||
294 | // console.log( "Rotate3DToolBase.captureSelectionDrawn _origin: " + this._origin ); | ||
295 | this._updateTargets(); | ||
296 | //this._setTransformOrigin(false); | ||
297 | } | ||
298 | else { | ||
299 | this.target = this.application.ninja.currentDocument.documentRoot; | ||
300 | //this._origin = drawUtils._selectionCtr.slice(0); | ||
301 | //this._origin[0] += this.application.ninja.stage.userContentLeft; | ||
302 | //this._origin[1] += this.application.ninja.stage.userContentTop; | ||
303 | this._updateTargets(); | ||
304 | this._origin = this.calculateMultiSelOrigin(); | ||
305 | //this._setTransformOrigin(true); | ||
306 | } | ||
307 | } | ||
308 | else { | ||
309 | this.target = null; | ||
310 | } | ||
311 | this.DrawHandles(); | ||
312 | |||
313 | if(event) | ||
314 | { | ||
315 | this.eventManager.removeEventListener("selectionDrawn", this, true); | ||
316 | } | ||
317 | } | ||
318 | }, | ||
319 | |||
320 | calculateMultiSelOrigin: | ||
321 | { | ||
322 | value: function() | ||
323 | { | ||
324 | var minPt, maxPt, i,j; | ||
325 | this._startOriginArray = []; | ||
326 | var len = this.application.ninja.selectedElements.length; | ||
327 | for (i = 0; i < len; i++) | ||
328 | { | ||
329 | // get the next element and localToGlobal matrix | ||
330 | var elt = this.application.ninja.selectedElements[i]; | ||
331 | var l2g = elt.elementModel.getProperty("l2g"); | ||
332 | |||
333 | // get the element bounds in 'plane' space | ||
334 | var bounds = viewUtils.getElementViewBounds3D( elt ); | ||
335 | for (j=0; j<4; j++) | ||
336 | { | ||
337 | var localPt = bounds[j]; | ||
338 | //var pt = MathUtils.transformAndDivideHomogeneousPoint( localPt, l2g ); | ||
339 | var pt = viewUtils.localToStageWorld( localPt, elt ); | ||
340 | if (!minPt) | ||
341 | { | ||
342 | minPt = pt.slice(); | ||
343 | maxPt = pt.slice(); | ||
344 | } | ||
277 | else | 345 | else |
278 | { | 346 | { |
279 | this._origin = drawUtils._selectionCtr.slice(0); | 347 | minPt[0] = Math.min(minPt[0],pt[0]); minPt[1] = Math.min(minPt[1],pt[1]); minPt[2] = Math.min(minPt[2],pt[2]); |
280 | this._origin[0] += this.application.ninja.stage.userContentLeft; | 348 | maxPt[0] = Math.max(maxPt[0],pt[0]); maxPt[1] = Math.max(maxPt[1],pt[1]); maxPt[2] = Math.max(maxPt[2],pt[2]); |
281 | this._origin[1] += this.application.ninja.stage.userContentTop; | ||
282 | } | 349 | } |
283 | } | 350 | } |
284 | } | 351 | } |
352 | var stageWorldCtr = [ 0.5*(minPt[0] + maxPt[0]), 0.5*(minPt[1] + maxPt[1]), 0.5*(minPt[2] + maxPt[2]) ]; | ||
353 | var globalCtr = MathUtils.transformAndDivideHomogeneousPoint( stageWorldCtr, viewUtils.getStageWorldToGlobalMatrix() ); | ||
354 | // console.log( "resetting _origin to: " + this._origin ); | ||
355 | |||
356 | return globalCtr; | ||
285 | } | 357 | } |
286 | }, | 358 | }, |
287 | 359 | ||
360 | |||
288 | DrawHandles: { | 361 | DrawHandles: { |
289 | value: function (delta) { | 362 | value: function (delta) { |
290 | this.application.ninja.stage.clearDrawingCanvas(); | 363 | this.application.ninja.stage.clearDrawingCanvas(); |
@@ -322,6 +395,9 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, | |||
322 | this._updateHandlesOrigin(); | 395 | this._updateHandlesOrigin(); |
323 | var base = this._origin.slice(0); | 396 | var base = this._origin.slice(0); |
324 | 397 | ||
398 | // if (this.isDrawing) | ||
399 | // console.log( "handle origin: " + base ); | ||
400 | |||
325 | var len = this.application.ninja.selectedElements.length; | 401 | var len = this.application.ninja.selectedElements.length; |
326 | var lMode = this._inLocalMode; | 402 | var lMode = this._inLocalMode; |
327 | if(len === 1) | 403 | if(len === 1) |