aboutsummaryrefslogtreecommitdiff
path: root/js/tools/Rotate3DToolBase.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/tools/Rotate3DToolBase.js')
-rwxr-xr-xjs/tools/Rotate3DToolBase.js184
1 files changed, 65 insertions, 119 deletions
diff --git a/js/tools/Rotate3DToolBase.js b/js/tools/Rotate3DToolBase.js
index 696408bf..ae1856e8 100755
--- a/js/tools/Rotate3DToolBase.js
+++ b/js/tools/Rotate3DToolBase.js
@@ -44,27 +44,22 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
44 44
45 modifyElements: { 45 modifyElements: {
46 value: function(data, event) { 46 value: function(data, event) {
47 var mat, 47 var mat, angle, pt0 = data.pt0, pt1 = data.pt1;
48 angle,
49 pt0 = data.pt0,
50 pt1 = data.pt1;
51 48
52 if(this._handleMode !== null) 49 if(this._handleMode !== null) {
53 { 50 if(this._activateOriginHandle) {
54 if(this._activateOriginHandle)
55 {
56 // move the transform origin handle 51 // move the transform origin handle
57 var dx = pt1.x - pt0.x; 52 var dx = pt1.x - pt0.x;
58 var dy = pt1.y - pt0.y; 53 var dy = pt1.y - pt0.y;
59 this._origin[0] += dx; 54 this._origin[0] += dx;
60 this._origin[1] += dy; 55 this._origin[1] += dy;
61 56
62 var len = this._targets.length; 57
63 if(len === 1) 58 if(this.application.ninja.selectedElements.length === 1) {
64 {
65 this._startOriginArray[0][0] += dx; 59 this._startOriginArray[0][0] += dx;
66 this._startOriginArray[0][1] += dy; 60 this._startOriginArray[0][1] += dy;
67 } 61 }
62
68 this.downPoint.x = pt1.x; 63 this.downPoint.x = pt1.x;
69 this.downPoint.y = pt1.y; 64 this.downPoint.y = pt1.y;
70 this.DrawHandles(); 65 this.DrawHandles();
@@ -133,7 +128,7 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
133 } 128 }
134 } 129 }
135 130
136 if(this._inLocalMode && (this._targets.length === 1) ) 131 if(this._inLocalMode && (this.application.ninja.selectedElements.length === 1) )
137 { 132 {
138 this._rotateLocally(mat); 133 this._rotateLocally(mat);
139 } 134 }
@@ -149,12 +144,10 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
149 144
150 _rotateLocally: { 145 _rotateLocally: {
151 value: function (rotMat) { 146 value: function (rotMat) {
152 var len = this._targets.length; 147 var len = this.application.ninja.selectedElements.length;
153 for(var i = 0; i < len; i++) 148 for(var i = 0; i < len; i++) {
154 { 149 var elt = this.application.ninja.selectedElements[i].elementModel.getProperty("elt");
155 var item = this._targets[i]; 150 var curMat = this.application.ninja.selectedElements[i].elementModel.getProperty("mat");
156 var elt = item.elt;
157 var curMat = item.mat;
158 151
159 // pre-translate by the transformation center 152 // pre-translate by the transformation center
160 var tMat = Matrix.I(4); 153 var tMat = Matrix.I(4);
@@ -178,19 +171,17 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
178 glmat4.multiply(mat, tMat, mat); 171 glmat4.multiply(mat, tMat, mat);
179 172
180 // while moving, set inline style to improve performance 173 // while moving, set inline style to improve performance
181 viewUtils.setMatrixForElement( elt, mat, true ); 174 viewUtils.setMatrixForElement(this.application.ninja.selectedElements[i], mat, true );
182 } 175 }
183 } 176 }
184 }, 177 },
185 178
186 _rotateGlobally: { 179 _rotateGlobally: {
187 value: function (rotMat) { 180 value: function (rotMat) {
188 var len = this._targets.length; 181 var len = this.application.ninja.selectedElements.length;
189 for(var i = 0; i < len; i++) 182 for(var i = 0; i < len; i++) {
190 { 183 var elt = this.application.ninja.selectedElements[i].elementModel.getProperty("elt");
191 var item = this._targets[i]; 184 var curMat = this.application.ninja.selectedElements[i].elementModel.getProperty("mat");
192 var elt = item.elt;
193 var curMat = item.mat;
194 185
195 // pre-translate by the transformation center 186 // pre-translate by the transformation center
196 var tMat = Matrix.I(4); 187 var tMat = Matrix.I(4);
@@ -213,7 +204,7 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
213 204
214 glmat4.multiply(mat, curMat, mat); 205 glmat4.multiply(mat, curMat, mat);
215 206
216 viewUtils.setMatrixForElement( elt, mat, true ); 207 viewUtils.setMatrixForElement(this.application.ninja.selectedElements[i], mat, true );
217 } 208 }
218 } 209 }
219 }, 210 },
@@ -254,7 +245,6 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
254 captureSelectionDrawn: { 245 captureSelectionDrawn: {
255 value: function(event){ 246 value: function(event){
256 this._origin = null; 247 this._origin = null;
257 this._targets = [];
258 this._startOriginArray = null; 248 this._startOriginArray = null;
259 249
260 var len = this.application.ninja.selectedElements.length; 250 var len = this.application.ninja.selectedElements.length;
@@ -304,103 +294,75 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
304 }, 294 },
305 295
306 _updateTargets: { 296 _updateTargets: {
307 value: function(addToUndoStack) { 297 value: function(addToUndo) {
308 var newStyles = [], 298 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];
315// this._initProps3D(elt);
316 299
317 300 this.application.ninja.selectedElements.forEach(function(element) {
318 var curMat = viewUtils.getMatrixFromElement(elt); 301 viewUtils.pushViewportObj(element);
319 var curMatInv = glmat4.inverse(curMat, []);
320
321 viewUtils.pushViewportObj( elt );
322 var eltCtr = viewUtils.getCenterOfProjection(); 302 var eltCtr = viewUtils.getCenterOfProjection();
323 viewUtils.popViewportObj(); 303 viewUtils.popViewportObj();
304 eltCtr = viewUtils.localToGlobal(eltCtr, element);
324 305
325 eltCtr = viewUtils.localToGlobal(eltCtr, elt); 306 element.elementModel.setProperty("ctr", eltCtr);
326 307
327 this._targets.push({elt:elt, mat:curMat, matInv:curMatInv, ctr:eltCtr}); 308 if(addToUndo) {
328 if(addToUndoStack) 309 var previousMat = element.elementModel.getProperty("mat").slice(0);
329 { 310 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)}; 311 var newStyleStr = {dist:viewUtils.getPerspectiveDistFromElement(element), mat:MathUtils.scientificToDecimal(viewUtils.getMatrixFromElement(element), 5)};
331 312
332 var newStyleStr = {dist:viewUtils.getPerspectiveDistFromElement(elt), mat:MathUtils.scientificToDecimal(curMat, 5)}; 313 mod3dObject.push({element:element, properties:newStyleStr, previousProperties: previousStyleStr});
333
334 previousStyles.push(previousStyleStr);
335 newStyles.push(newStyleStr);
336 } 314 }
315
316 });
317
318 if(addToUndo) {
319 ElementsMediator.set3DProperties(mod3dObject, "Change", "rotateTool");
337 } 320 }
338 if(addToUndoStack) 321
339 { 322 this.application.ninja.selectedElements.forEach(function(element) {
340 ElementsMediator.set3DProperties(this.application.ninja.selectedElements, 323 element.elementModel.setProperty("mat", viewUtils.getMatrixFromElement(element));
341 newStyles, 324 element.elementModel.setProperty("matInv", glmat4.inverse(element.elementModel.getProperty("mat"), []));
342 "Change", 325 element.elementModel.setProperty("dist", viewUtils.getPerspectiveDistFromElement(element));
343 "rotateTool", 326 });
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 }
356 } 327 }
357 }, 328 },
358 329
359 _setTransformOrigin: { 330 _setTransformOrigin: {
360 value: function(shouldUpdateCenter) { 331 value: function(shouldUpdateCenter) {
361 if(!this._origin) 332 if(!this._origin) {
362 {
363 return; 333 return;
364 } 334 }
365 var len = this._targets.length; 335
366 var elt, 336 var elt, eltCtr, ctrOffset, matInv;
367 eltCtr, 337
368 ctrOffset, 338 if(this.application.ninja.selectedElements.length === 1) {
369 matInv;
370 if( len === 1)
371 {
372 elt = this._target; 339 elt = this._target;
373 340
374 if(shouldUpdateCenter) 341 if(shouldUpdateCenter) {
375 { 342 console.log("get crt");
376 eltCtr = this._targets[0].ctr; 343 eltCtr = this.application.ninja.selectedElements[0].elementModel.getProperty("ctr");
377 ctrOffset = vecUtils.vecSubtract(3, this._origin, eltCtr); 344 ctrOffset = vecUtils.vecSubtract(3, this._origin, eltCtr);
378 345
379 matInv = this._targets[0].matInv;