diff options
Diffstat (limited to 'js/tools/Rotate3DToolBase.js')
-rwxr-xr-x | js/tools/Rotate3DToolBase.js | 229 |
1 files changed, 102 insertions, 127 deletions
diff --git a/js/tools/Rotate3DToolBase.js b/js/tools/Rotate3DToolBase.js index d08b3a31..6bd92353 100755 --- a/js/tools/Rotate3DToolBase.js +++ b/js/tools/Rotate3DToolBase.js | |||
@@ -14,14 +14,17 @@ var Montage = require("montage/core/core").Montage, | |||
14 | viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils, | 14 | viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils, |
15 | vecUtils = require("js/helper-classes/3D/vec-utils").VecUtils, | 15 | vecUtils = require("js/helper-classes/3D/vec-utils").VecUtils, |
16 | drawUtils = require("js/helper-classes/3D/draw-utils").DrawUtils, | 16 | drawUtils = require("js/helper-classes/3D/draw-utils").DrawUtils, |
17 | ElementsMediator = require("js/mediators/element-mediator").ElementMediator, | 17 | ElementsMediator = require("js/mediators/element-mediator").ElementMediator; |
18 | Rectangle = require("js/helper-classes/3D/rectangle").Rectangle; | ||
19 | 18 | ||
20 | exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { | 19 | exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { |
21 | _canSnap: { value: false }, | 20 | _canSnap: { value: false }, |
22 | 21 | ||
23 | _inLocalMode: { value: true, enumerable: true }, | 22 | _inLocalMode: { value: true, enumerable: true }, |
24 | 23 | ||
24 | rotateStage: { | ||
25 | value: false | ||
26 | }, | ||
27 | |||
25 | drawWithoutSnapping: | 28 | drawWithoutSnapping: |
26 | { | 29 | { |
27 | value: function(event) | 30 | value: function(event) |
@@ -103,6 +106,7 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { | |||
103 | this._startOriginArray[0] = viewOrigin; | 106 | this._startOriginArray[0] = viewOrigin; |
104 | //console.log( "Rotate3DToolBase.modifyElements, _startOriginArray[0]: " + this._startOriginArray[0] ); | 107 | //console.log( "Rotate3DToolBase.modifyElements, _startOriginArray[0]: " + this._startOriginArray[0] ); |
105 | } | 108 | } |
109 | |||
106 | this.downPoint.x = pt1.x; | 110 | this.downPoint.x = pt1.x; |
107 | this.downPoint.y = pt1.y; | 111 | this.downPoint.y = pt1.y; |
108 | this.downPoint.z = pt1.z; | 112 | this.downPoint.z = pt1.z; |
@@ -172,8 +176,7 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { | |||
172 | } | 176 | } |
173 | } | 177 | } |
174 | 178 | ||
175 | 179 | if(this._inLocalMode && (this.application.ninja.selectedElements.length === 1 || this.rotateStage) ) | |
176 | if(this._inLocalMode && (this._targets.length === 1) ) | ||
177 | { | 180 | { |
178 | console.log( "modifyElements: rotateLocally " ); | 181 | console.log( "modifyElements: rotateLocally " ); |
179 | this._rotateLocally(mat); | 182 | this._rotateLocally(mat); |
@@ -190,12 +193,15 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { | |||
190 | 193 | ||
191 | _rotateLocally: { | 194 | _rotateLocally: { |
192 | value: function (rotMat) { | 195 | value: function (rotMat) { |
193 | var len = this._targets.length; | 196 | var selectedElements = this.application.ninja.selectedElements; |
194 | for(var i = 0; i < len; i++) | 197 | |
195 | { | 198 | if(this.rotateStage) { |
196 | var item = this._targets[i]; | 199 | selectedElements = [this.application.ninja.currentDocument.documentRoot]; |
197 | var elt = item.elt; | 200 | } |
198 | var curMat = item.mat; | 201 | var len = selectedElements.length; |
202 | for(var i = 0; i < len; i++) { | ||
203 | var elt = selectedElements[i]; | ||
204 | var curMat = elt.elementModel.getProperty("mat"); | ||
199 | 205 | ||
200 | // pre-translate by the transformation center | 206 | // pre-translate by the transformation center |
201 | var tMat = Matrix.I(4); | 207 | var tMat = Matrix.I(4); |
@@ -228,12 +234,10 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { | |||
228 | 234 | ||
229 | _rotateGlobally: { | 235 | _rotateGlobally: { |
230 | value: function (rotMat) { | 236 | value: function (rotMat) { |
231 | var len = this._targets.length; | 237 | var len = this.application.ninja.selectedElements.length; |
232 | for(var i = 0; i < len; i++) | 238 | for(var i = 0; i < len; i++) { |
233 | { | 239 | var elt = this.application.ninja.selectedElements[i].elementModel.getProperty("elt"); |
234 | var item = this._targets[i]; | 240 | var curMat = this.application.ninja.selectedElements[i].elementModel.getProperty("mat"); |
235 | var elt = item.elt; | ||
236 | var curMat = item.mat; | ||
237 | 241 | ||
238 | // pre-translate by the transformation center | 242 | // pre-translate by the transformation center |
239 | var tMat = Matrix.I(4); | 243 | var tMat = Matrix.I(4); |
@@ -258,7 +262,7 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { | |||
258 | 262 | ||
259 | glmat4.multiply(mat, curMat, mat); | 263 | glmat4.multiply(mat, curMat, mat); |
260 | 264 | ||
261 | viewUtils.setMatrixForElement( elt, mat, true ); | 265 | viewUtils.setMatrixForElement(this.application.ninja.selectedElements[i], mat, true ); |
262 | } | 266 | } |
263 | } | 267 | } |
264 | }, | 268 | }, |
@@ -299,7 +303,6 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { | |||
299 | captureSelectionDrawn: { | 303 | captureSelectionDrawn: { |
300 | value: function(event){ | 304 | value: function(event){ |
301 | this._origin = null; | 305 | this._origin = null; |
302 | this._targets = []; | ||
303 | this._startOriginArray = null; | 306 | this._startOriginArray = null; |
304 | 307 | ||
305 | var len = this.application.ninja.selectedElements.length; | 308 | var len = this.application.ninja.selectedElements.length; |
@@ -323,7 +326,7 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { | |||
323 | } | 326 | } |
324 | 327 | ||
325 | this._origin = viewUtils.localToGlobal(eltCtr, this.target); | 328 | this._origin = viewUtils.localToGlobal(eltCtr, this.target); |
326 | console.log( "Rotate3DToolBase.captureSelectionDrawn _origin: " + this._origin ); | 329 | //console.log( "Rotate3DToolBase.captureSelectionDrawn _origin: " + this._origin ); |
327 | this._updateTargets(); | 330 | this._updateTargets(); |
328 | this._setTransformOrigin(false); | 331 | this._setTransformOrigin(false); |
329 | } | 332 | } |
@@ -335,7 +338,7 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { | |||
335 | //this._origin[1] += this.application.ninja.stage.userContentTop; | 338 | //this._origin[1] += this.application.ninja.stage.userContentTop; |
336 | this._updateTargets(); | 339 | this._updateTargets(); |
337 | this._origin = this.calculateMultiSelOrigin(); | 340 | this._origin = this.calculateMultiSelOrigin(); |
338 | this._setTransformOrigin(true); | 341 | this._setTransformOrigin(true); |
339 | } | 342 | } |
340 | } | 343 | } |
341 | else | 344 | else |
@@ -358,18 +361,11 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { | |||
358 | */ | 361 | */ |
359 | 362 | ||
360 | _updateTargets: { | 363 | _updateTargets: { |
361 | value: function(addToUndoStack) { | 364 | value: function(addToUndo) { |
362 | console.log( "Rotate3DToolBase._updateTargets" ); | 365 | var mod3dObject = [], |
363 | var newStyles = [], | 366 | self = this; |
364 | previousStyles = [], | ||
365 | len = this.application.ninja.selectedElements.length; | ||
366 | this._targets = []; | ||
367 | for(var i = 0; i < len; i++) | ||
368 | { | ||
369 | var elt = this.application.ninja.selectedElements[i]; | ||
370 | // this._initProps3D(elt); | ||
371 | |||
372 | 367 | ||
368 | this.application.ninja.selectedElements.forEach(function(element) { | ||
373 | var curMat = viewUtils.getMatrixFromElement(elt); | 369 | var curMat = viewUtils.getMatrixFromElement(elt); |
374 | var curMatInv = glmat4.inverse(curMat, []); | 370 | var curMatInv = glmat4.inverse(curMat, []); |
375 | 371 | ||
@@ -382,36 +378,31 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { | |||
382 | var g2lMat = glmat4.inverse( l2gMat, [] ); | 378 | var g2lMat = glmat4.inverse( l2gMat, [] ); |
383 | eltCtr = MathUtils.transformAndDivideHomogeneousPoint( eltCtr, l2gMat ); | 379 | eltCtr = MathUtils.transformAndDivideHomogeneousPoint( eltCtr, l2gMat ); |
384 | 380 | ||
385 | this._targets.push({elt:elt, mat:curMat, matInv:curMatInv, ctr:eltCtr, l2g:l2gMat, g2l:g2lMat}); | 381 | element.elementModel.setProperty("ctr", eltCtr); |
386 | 382 | element.elementModel.setProperty("mat", curMat); | |
387 | if(addToUndoStack) | 383 | element.elementModel.setProperty("matInv", curMatInv); |
388 | { | 384 | element.elementModel.setProperty("l2g", l2gMat); |
389 | var previousStyleStr = {dist:this._undoArray[i].dist, mat:MathUtils.scientificToDecimal(this._undoArray[i].mat.slice(0), 5)}; | 385 | element.elementModel.setProperty("g2l", g2lMat); |
390 | 386 | ||
391 | var newStyleStr = {dist:viewUtils.getPerspectiveDistFromElement(elt), mat:MathUtils.scientificToDecimal(curMat, 5)}; | 387 | if(addToUndo) { |
388 | var previousMat = element.elementModel.getProperty("mat").slice(0); | ||
389 | var previousStyleStr = {dist:element.elementModel.getProperty("dist"), mat:MathUtils.scientificToDecimal(previousMat, 5)}; | ||
390 | var newStyleStr = {dist:viewUtils.getPerspectiveDistFromElement(element), mat:MathUtils.scientificToDecimal(viewUtils.getMatrixFromElement(element), 5)}; | ||
392 | 391 | ||
393 | previousStyles.push(previousStyleStr); | 392 | mod3dObject.push({element:element, properties:newStyleStr, previousProperties: previousStyleStr}); |
394 | newStyles.push(newStyleStr); | ||
395 | } | 393 | } |
394 | |||
395 | }); | ||
396 | |||
397 | if(addToUndo) { | ||
398 | ElementsMediator.set3DProperties(mod3dObject, "Change", "rotateTool"); | ||
396 | } | 399 | } |
397 | if(addToUndoStack) | 400 | |
398 | { | 401 | this.application.ninja.selectedElements.forEach(function(element) { |
399 | ElementsMediator.set3DProperties(this.application.ninja.selectedElements, | 402 | element.elementModel.setProperty("mat", viewUtils.getMatrixFromElement(element)); |
400 | newStyles, | 403 | element.elementModel.setProperty("matInv", glmat4.inverse(element.elementModel.getProperty("mat"), [])); |
401 | "Change", | 404 | element.elementModel.setProperty("dist", viewUtils.getPerspectiveDistFromElement(element)); |
402 | "rotateTool", | 405 | }); |
403 | previousStyles | ||
404 | ); | ||
405 | } | ||
406 | // Save previous value for undo/redo | ||
407 | this._undoArray = []; | ||
408 | for(i = 0, len = this._targets.length; i < len; i++) | ||
409 | { | ||
410 | var elt = this._targets[i].elt; | ||
411 | var _mat = viewUtils.getMatrixFromElement(elt); | ||
412 | var _dist = viewUtils.getPerspectiveDistFromElement(elt); | ||
413 | this._undoArray.push({mat:_mat, dist:_dist}); | ||
414 | } | ||
415 | } | 406 | } |
416 | }, | 407 | }, |
417 | 408 | ||
@@ -425,8 +416,8 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { | |||
425 | for (i = 0; i < len; i++) | 416 | for (i = 0; i < len; i++) |
426 | { | 417 | { |
427 | // get the next element and localToGlobal matrix | 418 | // get the next element and localToGlobal matrix |
428 | elt = this._targets[i].elt; | 419 | elt = this.application.ninja.selectedElements[i]; |
429 | var l2g = this._targets[i].l2g; | 420 | var l2g = |