aboutsummaryrefslogtreecommitdiff
path: root/js/tools/TranslateObject3DTool.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/tools/TranslateObject3DTool.js')
-rwxr-xr-xjs/tools/TranslateObject3DTool.js55
1 files changed, 43 insertions, 12 deletions
diff --git a/js/tools/TranslateObject3DTool.js b/js/tools/TranslateObject3DTool.js
index 92b9b2f7..8edf1fee 100755
--- a/js/tools/TranslateObject3DTool.js
+++ b/js/tools/TranslateObject3DTool.js
@@ -4,18 +4,28 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. 4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5</copyright> */ 5</copyright> */
6 6
7var Translate3DToolBase = require("js/tools/Translate3DToolBase").Translate3DToolBase, 7var Montage = require("montage/core/core").Montage,
8 Translate3DToolBase = require("js/tools/Translate3DToolBase").Translate3DToolBase,
8 drawUtils = require("js/helper-classes/3D/draw-utils").DrawUtils, 9 drawUtils = require("js/helper-classes/3D/draw-utils").DrawUtils,
10 vecUtils = require("js/helper-classes/3D/vec-utils").VecUtils,
9 viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils, 11 viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils,
10 snapManager = require("js/helper-classes/3D/snap-manager").SnapManager; 12 snapManager = require("js/helper-classes/3D/snap-manager").SnapManager;
11 13
12exports.TranslateObject3DTool = Object.create(Translate3DToolBase, { 14exports.TranslateObject3DTool = Montage.create(Translate3DToolBase, {
13 _toolID: { value: "translateObject3DTool" }, 15 _toolID: { value: "translateObject3DTool" },
14 _canOperateOnStage: { value: true }, 16 _canOperateOnStage: { value: true },
15 17
18 _initializeToolHandles: {
19 value: function() {
20 this._inLocalMode = (this.options.selectedMode === "rotateLocally");
21 }
22 },
23
16 initializeSnapping : { 24 initializeSnapping : {
17 value : function(event) 25 value : function(event)
18 { 26 {
27// console.log( "initializeSnapping" );
28
19 this._mouseDownHitRec = null; 29 this._mouseDownHitRec = null;
20 this._mouseUpHitRec = null; 30 this._mouseUpHitRec = null;
21 31
@@ -32,20 +42,19 @@ exports.TranslateObject3DTool = Object.create(Translate3DToolBase, {
32 this._snapToGrid = snapManager.gridSnapEnabledAppLevel(); 42 this._snapToGrid = snapManager.gridSnapEnabledAppLevel();
33 43
34 this._dragPlane = null; 44 this._dragPlane = null;
45 this._clickedOnStage = false;
35 var do3DSnap = true; 46 var do3DSnap = true;
36 47
37 if(this._handleMode === null) 48 if(this._handleMode === null)
38 { 49 {
39// this.doSelection(event);
40
41 snapManager.enableElementSnap ( true ); 50 snapManager.enableElementSnap ( true );
42 snapManager.enableGridSnap ( true ); 51 snapManager.enableGridSnap ( true );
43 } 52 }
44 else 53 else
45 { 54 {
46 this._delta = 0; 55 this._delta = null;
47 // special case for z-translation 56 // special case for z-translation
48 if( this._handleMode && (this._handleMode === 2) ) 57 if(this._handleMode === 2)
49 { 58 {
50 this._dragPlane = viewUtils.getNormalToUnprojectedElementPlane(this._target); 59 this._dragPlane = viewUtils.getNormalToUnprojectedElementPlane(this._target);
51 snapManager.setupDragPlaneFromPlane(this._dragPlane); 60 snapManager.setupDragPlaneFromPlane(this._dragPlane);
@@ -65,11 +74,25 @@ exports.TranslateObject3DTool = Object.create(Translate3DToolBase, {
65 // a snap on the mouse down 74 // a snap on the mouse down
66 var hitRec = snapManager.snap(point.x, point.y, do3DSnap); 75 var hitRec = snapManager.snap(point.x, point.y, do3DSnap);
67 76
68 // TODO - Check that hitRec's element matches element that browser says we clicked on 77 if(this._handleMode === 2)
69 var elt = this.application.ninja.stage.GetElement(event);
70 if(elt !== hitRec.getElement())
71 { 78 {
72 hitRec = snapManager.findHitRecordForElement(elt); 79 // translate z doesn't snap to element so hitRec's element will always be different
80 // from what the browser says we clicked on. So, skip this check.
81 }
82 else
83 {
84 // Check that hitRec's element matches element that browser says we clicked on
85 // TODO - This is still not working when using a handle that is on top of an
86 // element that is not currently selected
87 var elt = this.application.ninja.stage.GetSelectableElement(event);
88 if(elt && (elt !== hitRec.getElement()))
89 {
90 hitRec = snapManager.findHitRecordForElement(elt);
91 }
92 if(elt === this.application.ninja.currentSelectedContainer)
93 {
94 this._clickedOnStage = true;
95 }
73 } 96 }
74 97
75 // we don't want to snap to selected objects during the drag 98 // we don't want to snap to selected objects during the drag
@@ -91,8 +114,11 @@ exports.TranslateObject3DTool = Object.create(Translate3DToolBase, {
91 snapManager.enableSnapAlign( snapManager.snapAlignEnabledAppLevel() ); 114 snapManager.enableSnapAlign( snapManager.snapAlignEnabledAppLevel() );
92 } 115 }
93 116
94 // parameterize the snap point on the target 117 if(this._handleMode === 2)
95 this._snapParam = this.parameterizeSnap( hitRec ); 118 this.clickedObject = this._target;
119
120 // parameterize the snap point on the target
121 this._snapParam = this.parameterizeSnap( hitRec );
96 122
97 if(!this._dragPlane) 123 if(!this._dragPlane)
98 { 124 {
@@ -108,6 +134,11 @@ exports.TranslateObject3DTool = Object.create(Translate3DToolBase, {
108 134
109 } 135 }
110 136
137 // only do quadrant snapping if the 4 corners of the element are in the drag plane
138
139 var sign = MathUtils.fpSign( vecUtils.vecDot(3,this._dragPlane,[0,0,1]) + this._dragPlane[3] - 1.0);
140 this._shouldUseQuadPt = (sign == 0);
141
111 var wpHitRec = hitRec.convertToWorkingPlane( this._dragPlane ); 142 var wpHitRec = hitRec.convertToWorkingPlane( this._dragPlane );
112 this._mouseDownHitRec = wpHitRec; 143 this._mouseDownHitRec = wpHitRec;
113 this._mouseUpHitRec = null; 144 this._mouseUpHitRec = null;