diff options
Diffstat (limited to 'js/tools/Translate3DToolBase.js')
-rwxr-xr-x | js/tools/Translate3DToolBase.js | 133 |
1 files changed, 106 insertions, 27 deletions
diff --git a/js/tools/Translate3DToolBase.js b/js/tools/Translate3DToolBase.js index 04359567..bf07e89e 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,24 +136,33 @@ 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 selectedElements = this.application.ninja.selectedElements; | ||
141 | if(this.rotateStage) { | ||
142 | selectedElements = [this.application.ninja.currentDocument.documentRoot]; | ||
143 | } | ||
144 | |||
140 | var self = this, | 145 | var self = this, |
141 | curMat = viewUtils.getMatrixFromElement( this._target ), | 146 | target = selectedElements[0], |
147 | curMat = viewUtils.getMatrixFromElement( target ), | ||
142 | matInv = glmat4.inverse(this._startMat, []), | 148 | matInv = glmat4.inverse(this._startMat, []), |
143 | nMat = glmat4.multiply(transMat, this._startMat, [] ); | 149 | nMat = glmat4.multiply(transMat, this._startMat, [] ); |
144 | // qMat = glmat4.multiply(matInv, nMat, []); | 150 | // qMat = glmat4.multiply(matInv, nMat, []); |
145 | 151 | ||
146 | if(this._mode === 1) { | 152 | if(this._mode === 1) { |
153 | if (len > 1) curMat = target.elementModel.getProperty("mat").slice(); | ||
147 | var curInv = glmat4.inverse( curMat, [] ); | 154 | var curInv = glmat4.inverse( curMat, [] ); |
148 | transMat = glmat4.multiply( nMat, curInv, [] ); | 155 | transMat = glmat4.multiply( nMat, curInv, [] ); |
149 | } | 156 | } |
150 | 157 | ||
151 | var shouldUpdateStartMat = true; | 158 | var shouldUpdateStartMat = true; |
152 | 159 | ||
153 | if(this._clickedOnStage) { | 160 | if(this._clickedOnStage || ((this._handleMode === 2) && (this._targets.length > 1))) |
161 | { | ||
154 | shouldUpdateStartMat = false; | 162 | shouldUpdateStartMat = false; |
155 | } else if(this._mode !== 1) { | 163 | } |
164 | else if(this._mode !== 1) | ||
165 | { | ||
156 | this._startMat = nMat; | 166 | this._startMat = nMat; |
157 | } | 167 | } |
158 | 168 | ||
@@ -249,42 +259,108 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, | |||
249 | viewUtils.popViewportObj(); | 259 | viewUtils.popViewportObj(); |
250 | ctr[2] = 0; | 260 | ctr[2] = 0; |
251 | 261 | ||
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); | 262 | this._origin = viewUtils.localToGlobal(ctr, item); |
259 | } | 263 | } |
260 | else | 264 | else |
261 | { | 265 | { |
262 | if(this._origin) | 266 | this._origin = undefined; |
263 | { | 267 | this._origin = this.calculateMultiSelOrigin(); |
264 | if(this._delta) | 268 | } |
265 | { | 269 | } |
266 | if(this._handleMode !== null) | 270 | } |
267 | { | 271 | }, |
268 | // this._origin[this._handleMode] = this._delta; | 272 | |
269 | } | 273 | captureSelectionDrawn: { |
270 | else | 274 | value: function(event){ |
271 | { | 275 | this._origin = null; |
272 | this._origin[0] += this._delta[0]; | 276 | this._targets = []; |
273 | this._origin[1] += this._delta[1]; | 277 | this._startOriginArray = null; |
274 | } | 278 | |
275 | } | 279 | var len = this.application.ninja.selectedElements.length; |
280 | if(len) { | ||
281 | if(len === 1) { | ||
282 | this.target = this.application.ninja.selectedElements[0]; | ||
283 | drawUtils.addElement(this.target); | ||
284 | |||
285 | viewUtils.pushViewportObj( this.target ); | ||
286 | var eltCtr = viewUtils.getCenterOfProjection(); | ||
287 | eltCtr[2] = 0; | ||
288 | viewUtils.popViewportObj(); | ||
289 | |||
290 | var ctrOffset = this.target.elementModel.props3D.m_transformCtr; | ||
291 | if(ctrOffset) { | ||
292 | eltCtr[2] = 0; | ||
293 | eltCtr = vecUtils.vecAdd(3, eltCtr, ctrOffset); | ||
276 | } | 294 | } |
295 | |||
296 | this._origin = viewUtils.localToGlobal(eltCtr, this.target); | ||
297 | console.log( "Rotate3DToolBase.captureSelectionDrawn _origin: " + this._origin ); | ||
298 | this._updateTargets(); | ||
299 | //this._setTransformOrigin(false); | ||
300 | } | ||
301 | else { | ||
302 | this.target = this.application.ninja.currentDocument.documentRoot; | ||
303 | //this._origin = drawUtils._selectionCtr.slice(0); | ||
304 | //this._origin[0] += this.application.ninja.stage.userContentLeft; | ||
305 | //this._origin[1] += this.application.ninja.stage.userContentTop; | ||
306 | this._updateTargets(); | ||
307 | this._origin = this.calculateMultiSelOrigin(); | ||
308 | //this._setTransformOrigin(true); | ||
309 | } | ||
310 | } | ||
311 | else { | ||
312 | this.target = null; | ||
313 | } | ||
314 | this.DrawHandles(); | ||
315 | |||
316 | if(event) | ||
317 | { | ||
318 | this.eventManager.removeEventListener("selectionDrawn", this, true); | ||
319 | } | ||
320 | } | ||
321 | }, | ||
322 | |||
323 | calculateMultiSelOrigin: | ||
324 | { | ||
325 | value: function() | ||
326 | { | ||
327 | var minPt, maxPt, i,j; | ||
328 | this._startOriginArray = []; | ||
329 | var len = this.application.ninja.selectedElements.length; | ||
330 | for (i = 0; i < len; i++) | ||
331 | { | ||
332 | // get the next element and localToGlobal matrix | ||
333 | elt = this._targets[i].elt; | ||
334 | var l2g = this._targets[i].l2g; | ||
335 | |||
336 | // get the element bounds in 'plane' space | ||
337 | bounds = viewUtils.getElementViewBounds3D( elt ); | ||
338 | for (j=0; j<4; j++) | ||
339 | { | ||
340 | var localPt = bounds[j]; | ||
341 | //var pt = MathUtils.transformAndDivideHomogeneousPoint( localPt, l2g ); | ||
342 | var pt = viewUtils.localToStageWorld( localPt, elt ); | ||
343 | if (!minPt) | ||
344 | { | ||
345 | minPt = pt.slice(); | ||
346 | maxPt = pt.slice(); | ||
347 | } | ||
277 | else | 348 | else |
278 | { | 349 | { |
279 | this._origin = drawUtils._selectionCtr.slice(0); | 350 | 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; | 351 | 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 | } | 352 | } |
283 | } | 353 | } |
284 | } | 354 | } |
355 | var stageWorldCtr = [ 0.5*(minPt[0] + maxPt[0]), 0.5*(minPt[1] + maxPt[1]), 0.5*(minPt[2] + maxPt[2]) ]; | ||
356 | var globalCtr = MathUtils.transformAndDivideHomogeneousPoint( stageWorldCtr, viewUtils.getStageWorldToGlobalMatrix() ); | ||
357 | console.log( "resetting _origin to: " + this._origin ); | ||
358 | |||
359 | return globalCtr; | ||
285 | } | 360 | } |
286 | }, | 361 | }, |
287 | 362 | ||
363 | |||
288 | DrawHandles: { | 364 | DrawHandles: { |
289 | value: function (delta) { | 365 | value: function (delta) { |
290 | this.application.ninja.stage.clearDrawingCanvas(); | 366 | this.application.ninja.stage.clearDrawingCanvas(); |
@@ -322,6 +398,9 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, | |||
322 | this._updateHandlesOrigin(); | 398 | this._updateHandlesOrigin(); |
323 | var base = this._origin.slice(0); | 399 | var base = this._origin.slice(0); |
324 | 400 | ||
401 | // if (this.isDrawing) | ||
402 | // console.log( "handle origin: " + base ); | ||
403 | |||
325 | var len = this.application.ninja.selectedElements.length; | 404 | var len = this.application.ninja.selectedElements.length; |
326 | var lMode = this._inLocalMode; | 405 | var lMode = this._inLocalMode; |
327 | if(len === 1) | 406 | if(len === 1) |