aboutsummaryrefslogtreecommitdiff
path: root/js/tools/Rotate3DToolBase.js
diff options
context:
space:
mode:
authorhwc4872012-04-19 13:01:43 -0700
committerhwc4872012-04-19 13:01:43 -0700
commite6a20fe64574763483dc602bd759278ccf5e5e68 (patch)
tree69defe7200206f0257fe90697136fadef59d521e /js/tools/Rotate3DToolBase.js
parentae7eb87564632ce7c676bd728b8ff2710ff0bb83 (diff)
parent9284c19f076dec3b47ece7dc7bcd22d74e4246c3 (diff)
downloadninja-e6a20fe64574763483dc602bd759278ccf5e5e68.tar.gz
Merge branch 'master' of github.com:Motorola-Mobility/ninja-internal into Textures
Conflicts: js/lib/drawing/world.js js/lib/geom/geom-obj.js js/lib/rdge/materials/cloud-material.js js/lib/rdge/materials/deform-material.js js/lib/rdge/materials/flat-material.js js/lib/rdge/materials/material.js js/lib/rdge/materials/pulse-material.js js/lib/rdge/materials/relief-tunnel-material.js js/lib/rdge/materials/square-tunnel-material.js js/lib/rdge/materials/star-material.js js/lib/rdge/materials/taper-material.js js/lib/rdge/materials/tunnel-material.js js/lib/rdge/materials/twist-material.js js/lib/rdge/materials/twist-vert-material.js js/lib/rdge/materials/uber-material.js js/lib/rdge/materials/water-material.js js/lib/rdge/materials/z-invert-material.js
Diffstat (limited to 'js/tools/Rotate3DToolBase.js')
-rwxr-xr-xjs/tools/Rotate3DToolBase.js205
1 files changed, 82 insertions, 123 deletions
diff --git a/js/tools/Rotate3DToolBase.js b/js/tools/Rotate3DToolBase.js
index b04e8b0a..2e121b0b 100755
--- a/js/tools/Rotate3DToolBase.js
+++ b/js/tools/Rotate3DToolBase.js
@@ -21,6 +21,10 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
21 21
22 _inLocalMode: { value: true, enumerable: true }, 22 _inLocalMode: { value: true, enumerable: true },
23 23
24 rotateStage: {
25 value: false
26 },
27
24 drawWithoutSnapping: 28 drawWithoutSnapping:
25 { 29 {
26 value: function(event) 30 value: function(event)
@@ -44,27 +48,21 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
44 48
45 modifyElements: { 49 modifyElements: {
46 value: function(data, event) { 50 value: function(data, event) {
47 var mat, 51 var mat, angle, pt0 = data.pt0, pt1 = data.pt1;
48 angle,
49 pt0 = data.pt0,
50 pt1 = data.pt1;
51 52
52 if(this._handleMode !== null) 53 if(this._handleMode !== null) {
53 { 54 if(this._activateOriginHandle) {
54 if(this._activateOriginHandle)
55 {
56 // move the transform origin handle 55 // move the transform origin handle
57 var dx = pt1.x - pt0.x; 56 var dx = pt1.x - pt0.x;
58 var dy = pt1.y - pt0.y; 57 var dy = pt1.y - pt0.y;
59 this._origin[0] += dx; 58 this._origin[0] += dx;
60 this._origin[1] += dy; 59 this._origin[1] += dy;
61 60
62 var len = this._targets.length; 61 if( this.rotateStage || (this.application.ninja.selectedElements.length === 1)) {
63 if(len === 1)
64 {
65 this._startOriginArray[0][0] += dx; 62 this._startOriginArray[0][0] += dx;
66 this._startOriginArray[0][1] += dy; 63 this._startOriginArray[0][1] += dy;
67 } 64 }
65
68 this.downPoint.x = pt1.x; 66 this.downPoint.x = pt1.x;
69 this.downPoint.y = pt1.y; 67 this.downPoint.y = pt1.y;
70 this.DrawHandles(); 68 this.DrawHandles();
@@ -133,7 +131,7 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
133 } 131 }
134 } 132 }
135 133
136 if(this._inLocalMode && (this._targets.length === 1) ) 134 if(this._inLocalMode && (this.application.ninja.selectedElements.length === 1 || this.rotateStage) )
137 { 135 {
138 this._rotateLocally(mat); 136 this._rotateLocally(mat);
139 } 137 }
@@ -149,12 +147,15 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
149 147
150 _rotateLocally: { 148 _rotateLocally: {
151 value: function (rotMat) { 149 value: function (rotMat) {
152 var len = this._targets.length; 150 var selectedElements = this.application.ninja.selectedElements;
153 for(var i = 0; i < len; i++) 151
154 { 152 if(this.rotateStage) {
155 var item = this._targets[i]; 153 selectedElements = [this.application.ninja.currentDocument.documentRoot];
156 var elt = item.elt; 154 }
157 var curMat = item.mat; 155 var len = selectedElements.length;
156 for(var i = 0; i < len; i++) {
157 var elt = selectedElements[i].elementModel.getProperty("elt");
158 var curMat = selectedElements[i].elementModel.getProperty("mat");
158 159
159 // pre-translate by the transformation center 160 // pre-translate by the transformation center
160 var tMat = Matrix.I(4); 161 var tMat = Matrix.I(4);
@@ -178,19 +179,17 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
178 glmat4.multiply(mat, tMat, mat); 179 glmat4.multiply(mat, tMat, mat);
179 180
180 // while moving, set inline style to improve performance 181 // while moving, set inline style to improve performance
181 viewUtils.setMatrixForElement( elt, mat, true ); 182 viewUtils.setMatrixForElement(selectedElements[i], mat, true );
182 } 183 }
183 } 184 }
184 }, 185 },
185 186
186 _rotateGlobally: { 187 _rotateGlobally: {
187 value: function (rotMat) { 188 value: function (rotMat) {
188 var len = this._targets.length; 189 var len = this.application.ninja.selectedElements.length;
189 for(var i = 0; i < len; i++) 190 for(var i = 0; i < len; i++) {
190 { 191 var elt = this.application.ninja.selectedElements[i].elementModel.getProperty("elt");
191 var item = this._targets[i]; 192 var curMat = this.application.ninja.selectedElements[i].elementModel.getProperty("mat");
192 var elt = item.elt;
193 var curMat = item.mat;
194 193
195 // pre-translate by the transformation center 194 // pre-translate by the transformation center
196 var tMat = Matrix.I(4); 195 var tMat = Matrix.I(4);
@@ -213,7 +212,7 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
213 212
214 glmat4.multiply(mat, curMat, mat); 213 glmat4.multiply(mat, curMat, mat);
215 214
216 viewUtils.setMatrixForElement( elt, mat, true ); 215 viewUtils.setMatrixForElement(this.application.ninja.selectedElements[i], mat, true );
217 } 216 }
218 } 217 }
219 }, 218 },
@@ -254,7 +253,6 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
254 captureSelectionDrawn: { 253 captureSelectionDrawn: {
255 value: function(event){ 254 value: function(event){
256 this._origin = null; 255 this._origin = null;
257 this._targets = [];
258 this._startOriginArray = null; 256 this._startOriginArray = null;
259 257
260 var len = this.application.ninja.selectedElements.length; 258 var len = this.application.ninja.selectedElements.length;
@@ -262,7 +260,7 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
262 { 260 {
263 if(len === 1) 261 if(len === 1)
264 { 262 {
265 this.target = this.application.ninja.selectedElements[0]._element; 263 this.target = this.application.ninja.selectedElements[0];
266 drawUtils.addElement(this.target); 264 drawUtils.addElement(this.target);
267 265
268 viewUtils.pushViewportObj( this.target ); 266 viewUtils.pushViewportObj( this.target );
@@ -304,103 +302,79 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
304 }, 302 },
305 303
306 _updateTargets: { 304 _updateTargets: {
307 value: function(addToUndoStack) { 305 value: function(addToUndo) {
308 var newStyles = [], 306 var mod3dObject = [], self = this;
309 previousStyles = [],
310 len = this.application.ninja.selectedElements.length;
311 this._targets = [];
312 for(var i = 0; i < len; i++)
313 {
314 var elt = this.application.ninja.selectedElements[i]._element;
315// this._initProps3D(elt);
316
317
318 var curMat = viewUtils.getMatrixFromElement(elt);
319 var curMatInv = glmat4.inverse(curMat, []);
320 307
321 viewUtils.pushViewportObj( elt ); 308 this.application.ninja.selectedElements.forEach(function(element) {
309 viewUtils.pushViewportObj(element);
322 var eltCtr = viewUtils.getCenterOfProjection(); 310 var eltCtr = viewUtils.getCenterOfProjection();
323 viewUtils.popViewportObj(); 311 viewUtils.popViewportObj();
312 eltCtr = viewUtils.localToGlobal(eltCtr, element);
324 313
325 eltCtr = viewUtils.localToGlobal(eltCtr, elt); 314 element.elementModel.setProperty("ctr", eltCtr);
326 315
327 this._targets.push({elt:elt, mat:curMat, matInv:curMatInv, ctr:eltCtr}); 316 if(addToUndo) {
328 if(addToUndoStack) 317 var previousMat = element.elementModel.getProperty("mat").slice(0);
329 { 318 var previousStyleStr = {dist:element.elementModel.getProperty("dist"), mat:MathUtils.scientificToDecimal(previousMat, 5)};
330 var previousStyleStr = {dist:this._undoArray[i].dist, mat:MathUtils.scientificToDecimal(this._undoArray[i].mat.slice(0), 5)}; 319 var newStyleStr = {dist:viewUtils.getPerspectiveDistFromElement(element), mat:MathUtils.scientificToDecimal(viewUtils.getMatrixFromElement(element), 5)};
331
332 var newStyleStr = {dist:viewUtils.getPerspectiveDistFromElement(elt), mat:MathUtils.scientificToDecimal(curMat, 5)};
333 320
334 previousStyles.push(previousStyleStr); 321 mod3dObject.push({element:element, properties:newStyleStr, previousProperties: previousStyleStr});
335 newStyles.push(newStyleStr);
336 } 322 }
323
324 });
325
326 if(addToUndo) {
327 ElementsMediator.set3DProperties(mod3dObject, "Change", "rotateTool");
337 } 328 }
338 if(addToUndoStack) 329
339 { 330 this.application.ninja.selectedElements.forEach(function(element) {
340 ElementsMediator.set3DProperties(this.application.ninja.selectedElements, 331 element.elementModel.setProperty("mat", viewUtils.getMatrixFromElement(element));
341 newStyles, 332 element.elementModel.setProperty("matInv", glmat4.inverse(element.elementModel.getProperty("mat"), []));
342 "Change", 333 element.elementModel.setProperty("dist", viewUtils.getPerspectiveDistFromElement(element));
343 "rotateTool", 334 });
344 previousStyles
345 );
346 }
347 // Save previous value for undo/redo
348 this._undoArray = [];
349 for(i = 0, len = this._targets.length; i < len; i++)
350 {
351 var elt = this._targets[i].elt;
352 var _mat = viewUtils.getMatrixFromElement(elt);
353 var _dist = viewUtils.getPerspectiveDistFromElement(elt);
354 this._undoArray.push({mat:_mat, dist:_dist});
355 }