aboutsummaryrefslogtreecommitdiff
path: root/js/tools/modifier-tool-base.js
diff options
context:
space:
mode:
authorPushkar Joshi2012-04-17 14:49:18 -0700
committerPushkar Joshi2012-04-17 14:49:18 -0700
commitdf903a01e14134cadf109b733d09c6eadfa3966b (patch)
tree2351f1c05b2f852053fa0be533072088a9ad4e7c /js/tools/modifier-tool-base.js
parent036cf034e124dbc1f4893e90f7c6d240904a3faf (diff)
parentcacb4a21825818af392c2949967b0f3c1df509c5 (diff)
downloadninja-df903a01e14134cadf109b733d09c6eadfa3966b.tar.gz
Merge branch 'master' into pentool
Conflicts: js/tools/PenTool.js
Diffstat (limited to 'js/tools/modifier-tool-base.js')
-rwxr-xr-xjs/tools/modifier-tool-base.js64
1 files changed, 30 insertions, 34 deletions
diff --git a/js/tools/modifier-tool-base.js b/js/tools/modifier-tool-base.js
index 46bb2e87..8cd21a29 100755
--- a/js/tools/modifier-tool-base.js
+++ b/js/tools/modifier-tool-base.js
@@ -9,8 +9,8 @@ var Montage = require("montage/core/core").Montage,
9 snapManager = require("js/helper-classes/3D/snap-manager").SnapManager, 9 snapManager = require("js/helper-classes/3D/snap-manager").SnapManager,
10 viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils, 10 viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils,
11 vecUtils = require("js/helper-classes/3D/vec-utils").VecUtils, 11 vecUtils = require("js/helper-classes/3D/vec-utils").VecUtils,
12 drawUtils = require("js/helper-classes/3D/draw-utils").DrawUtils, 12 drawUtils = require("js/helper-classes/3D/draw-utils").DrawUtils;
13 Properties3D = ("js/models/properties-3d").Properties3D; 13// Properties3D = ("js/models/properties-3d").Properties3D;
14 14
15exports.ModifierToolBase = Montage.create(DrawingTool, { 15exports.ModifierToolBase = Montage.create(DrawingTool, {
16 16
@@ -25,6 +25,7 @@ exports.ModifierToolBase = Montage.create(DrawingTool, {
25 _snapParam: { value: null }, 25 _snapParam: { value: null },
26 _snapIndex: { value: -1 }, 26 _snapIndex: { value: -1 },
27 _useQuadPt: { value: false }, 27 _useQuadPt: { value: false },
28 _shouldUseQuadPt: { value: false },
28 29
29 // we set snapping capabilities depending on the tool. 30 // we set snapping capabilities depending on the tool.
30 // The following variables are set in a tool's initializeSnapping method called on mouse down. 31 // The following variables are set in a tool's initializeSnapping method called on mouse down.
@@ -124,8 +125,7 @@ exports.ModifierToolBase = Montage.create(DrawingTool, {
124// } 125// }
125// } 126// }
126 127
127 128 if(this.application.ninja.selectedElements.length)
128 if(this._targets)
129 { 129 {
130 var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, 130 var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas,
131 new WebKitPoint(event.pageX, event.pageY)); 131 new WebKitPoint(event.pageX, event.pageY));
@@ -141,11 +141,10 @@ exports.ModifierToolBase = Montage.create(DrawingTool, {
141 } 141 }
142 142
143 // we don't want to snap to selected objects during the drag 143 // we don't want to snap to selected objects during the drag
144 var len = this._targets.length; 144 this.application.ninja.selectedElements.forEach(function(element) {
145 for(var i=0; i<len; i++) 145 snapManager.addToAvoidList(element);
146 { 146 });
147 snapManager.addToAvoidList( this._targets[i].elt ); 147
148 }
149 if (hitRec) 148 if (hitRec)
150 { 149 {
151 // disable snap attributes 150 // disable snap attributes
@@ -175,6 +174,10 @@ exports.ModifierToolBase = Montage.create(DrawingTool, {
175// } 174// }
176 } 175 }
177 176
177 // only do quadrant snapping if the 4 corners of the element are in the drag plane
178 var sign = MathUtils.fpSign( vecUtils.vecDot(3,this._dragPlane,[0,0,1]) + this._dragPlane[3] - 1.0);
179 this._shouldUseQuadPt = (sign == 0)
180
178 var wpHitRec = hitRec.convertToWorkingPlane( this._dragPlane ); 181 var wpHitRec = hitRec.convertToWorkingPlane( this._dragPlane );
179 this._mouseDownHitRec = wpHitRec; 182 this._mouseDownHitRec = wpHitRec;
180 this._mouseUpHitRec = null; 183 this._mouseUpHitRec = null;
@@ -236,6 +239,7 @@ exports.ModifierToolBase = Montage.create(DrawingTool, {
236 } 239 }
237 } 240 }
238 241
242 //console.log( "ParameterizeSnap: " + paramPt );
239 return paramPt; 243 return paramPt;
240 } 244 }
241 }, 245 },
@@ -284,14 +288,16 @@ exports.ModifierToolBase = Montage.create(DrawingTool, {
284 y = x0 + ty*dy, 288 y = x0 + ty*dy,
285 z = 0.0; 289 z = 0.0;
286 var localPt = [x,y,z]; 290 var localPt = [x,y,z];
291
287 globalPt = viewUtils.localToGlobal( localPt, elt ); 292 globalPt = viewUtils.localToGlobal( localPt, elt );
288 293
289 // add in the delta 294 // add in the delta
290 var hitPt = this.GetObjectHitPoint(); 295 var hitPt = this.GetObjectHitPoint();
291 var scrPt = viewUtils.localToGlobal( hitPt, this._clickedObject ); 296 var scrPt = viewUtils.localToGlobal( hitPt, this._clickedObject );
292 var delta = [xEvent-scrPt[0], yEvent-scrPt[1]]; 297 var delta = [xEvent-scrPt[0], yEvent-scrPt[1], 0-scrPt[2]];
293 globalPt[0] += delta[0]; 298 globalPt[0] += delta[0];
294 globalPt[1] += delta[1]; 299 globalPt[1] += delta[1];
300 globalPt[2] += delta[2];
295 } 301 }
296 302
297 return globalPt; 303 return globalPt;
@@ -396,7 +402,7 @@ exports.ModifierToolBase = Montage.create(DrawingTool, {
396 { 402 {
397 var index = this._snapIndex; 403 var index = this._snapIndex;
398 var pt0; 404 var pt0;
399 var useViewPoint = (this._inLocalMode && (this._targets.length === 1)); 405 var useViewPoint = (this._inLocalMode && (this.application.ninja.selectedElements.length === 1));
400 if (this._useQuadPt) 406 if (this._useQuadPt)
401 { 407 {
402 pt0 = this.GetQuadrantPoint(useViewPoint); 408 pt0 = this.GetQuadrantPoint(useViewPoint);
@@ -448,6 +454,7 @@ exports.ModifierToolBase = Montage.create(DrawingTool, {
448 { 454 {
449 this.isDrawing = true; 455 this.isDrawing = true;
450 this.application.ninja.stage.showSelectionBounds = false; 456 this.application.ninja.stage.showSelectionBounds = false;
457 this._updateTargets();
451 458
452 if(this._canSnap) 459 if(this._canSnap)
453 { 460 {
@@ -517,7 +524,7 @@ exports.ModifierToolBase = Montage.create(DrawingTool, {
517 524
518 // do the snap 525 // do the snap
519 var quadPt; 526 var quadPt;
520 if (mouseIsDown) 527 if (mouseIsDown && !do3DSnap && this._shouldUseQuadPt && (this._handleMode === null) && (this._mode === 0))
521 quadPt = this.GetQuadrantSnapPoint(x,y); 528 quadPt = this.GetQuadrantSnapPoint(x,y);
522 var hitRec = snapManager.snap(x, y, do3DSnap, quadPt ); 529 var hitRec = snapManager.snap(x, y, do3DSnap, quadPt );
523 530
@@ -682,25 +689,6 @@ exports.ModifierToolBase = Montage.create(DrawingTool, {
682 }, 689 },
683 690
684 _startMat: { value: Matrix.I(4) }, 691 _startMat: { value: Matrix.I(4) },
685
686 _targets: { value: null },
687 targets:
688 {
689 get: function () {
690 return this._targets;
691 },
692 set: function (value) {
693 this._targets = value;
694 if (value !== null && value.length)
695 {
696 this.target = value[0];
697 }
698 else
699 {
700 this.target = null;
701 }
702 }
703 },
704 692
705 _undoArray: { value: [] }, 693 _undoArray: { value: [] },
706 694
@@ -743,7 +731,6 @@ exports.ModifierToolBase = Montage.create(DrawingTool, {
743 } else { 731 } else {
744 this.eventManager.removeEventListener("selectionChange", this, true); 732 this.eventManager.removeEventListener("selectionChange", this, true);
745 this.application.ninja.stage._iframeContainer.removeEventListener("scroll", this, false); 733 this.application.ninja.stage._iframeContainer.removeEventListener("scroll", this, false);
746 this._targets = [];
747 734
748 // Clean up 735 // Clean up
749 NJevent("disableStageMove"); 736 NJevent("disableStageMove");
@@ -757,6 +744,11 @@ exports.ModifierToolBase = Montage.create(DrawingTool, {
757 snapManager.enableGridSnap( snapManager.gridSnapEnabledAppLevel() ); 744 snapManager.enableGridSnap( snapManager.gridSnapEnabledAppLevel() );
758 this.eventManager.removeEventListener( "toolOptionsChange", this, false); 745 this.eventManager.removeEventListener( "toolOptionsChange", this, false);
759 this.eventManager.removeEventListener( "toolDoubleClick", this, false); 746 this.eventManager.removeEventListener( "toolDoubleClick", this, false);
747
748 if (this._targetedElement) {
749 this._targetedElement.classList.remove("active-element-outline");
750 this._targetedElement = null;
751 }
760 } 752 }
761 } 753 }
762 }, 754 },
@@ -769,7 +761,6 @@ exports.ModifierToolBase = Montage.create(DrawingTool, {
769 761
770 captureSelectionDrawn: { 762 captureSelectionDrawn: {
771 value: function(event){ 763 value: function(event){
772 this._targets = [];
773 this._origin = null; 764 this._origin = null;
774 this._delta = null; 765 this._delta = null;
775 766
@@ -785,7 +776,7 @@ exports.ModifierToolBase = Montage.create(DrawingTool, {
785 { 776 {
786 this.target = this.application.ninja.currentDocument.documentRoot; 777 this.target = this.application.ninja.currentDocument.documentRoot;
787 } 778 }
788 this._updateTargets(); 779// this._updateTargets();
789 } 780 }
790 else 781 else
791 { 782 {
@@ -806,6 +797,8 @@ exports.ModifierToolBase = Montage.create(DrawingTool, {
806 HandleLeftButtonDown: { 797 HandleLeftButtonDown: {
807 value: function(event) { 798 value: function(event) {
808 799
800// console.log( "modifier-tool-base.HandleLeftButtonDown" );
801
809 var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, new WebKitPoint(event.pageX, event.pageY)); 802 var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, new WebKitPoint(event.pageX, event.pageY));
810 this.downPoint.x = point.x; 803 this.downPoint.x = point.x;
811 this.downPoint.y = point.y; 804 this.downPoint.y = point.y;
@@ -816,7 +809,10 @@ exports.ModifierToolBase = Montage.create(Drawin