diff options
author | Jose Antonio Marquez | 2012-04-24 10:06:53 -0700 |
---|---|---|
committer | Jose Antonio Marquez | 2012-04-24 10:06:53 -0700 |
commit | 4c15e77bdb7f4e0558f3749994a8a37b207b97ae (patch) | |
tree | 593ab4917fb5cc3ef8ee36822b56c6edd30c33a5 /js/tools/Translate3DToolBase.js | |
parent | 36d50b6599ab98559c76e1fe57b1bb131c4433da (diff) | |
parent | 55e6d621b9555abac06ab4adff44dfe29a78ec4e (diff) | |
download | ninja-4c15e77bdb7f4e0558f3749994a8a37b207b97ae.tar.gz |
Merge branch 'refs/heads/Ninja-Internal' into Document
Diffstat (limited to 'js/tools/Translate3DToolBase.js')
-rwxr-xr-x | js/tools/Translate3DToolBase.js | 276 |
1 files changed, 153 insertions, 123 deletions
diff --git a/js/tools/Translate3DToolBase.js b/js/tools/Translate3DToolBase.js index e4f1fb99..f81ce6d6 100755 --- a/js/tools/Translate3DToolBase.js +++ b/js/tools/Translate3DToolBase.js | |||
@@ -21,8 +21,7 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, | |||
21 | _clickedOnStage: { value: false }, | 21 | _clickedOnStage: { value: false }, |
22 | 22 | ||
23 | HandleDoubleClick : { | 23 | HandleDoubleClick : { |
24 | value : function() | 24 | value : function() { |
25 | { | ||
26 | } | 25 | } |
27 | }, | 26 | }, |
28 | 27 | ||
@@ -71,10 +70,11 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, | |||
71 | this._delta = delta.slice(0); | 70 | this._delta = delta.slice(0); |
72 | } | 71 | } |
73 | 72 | ||
73 | //console.log( "modifyElements delta: " + delta ); | ||
74 | var transMat = Matrix.Translation( delta ); | 74 | var transMat = Matrix.Translation( delta ); |
75 | 75 | ||
76 | //console.log( "Translate: " + delta ); | 76 | //console.log( "Translate: " + delta ); |
77 | if(this._inLocalMode && (this._targets.length === 1) ) | 77 | if(this._inLocalMode && (this.application.ninja.selectedElements.length === 1) ) |
78 | { | 78 | { |
79 | this._translateLocally(transMat); | 79 | this._translateLocally(transMat); |
80 | } | 80 | } |
@@ -86,45 +86,32 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, | |||
86 | }, | 86 | }, |
87 | 87 | ||
88 | 88 | ||
89 | Reset : { | 89 | Reset: { |
90 | value : function() | 90 | value: function() { |
91 | { | 91 | var mat, iMat, dist, mod3dObject = [], self = this; |
92 | var item, | 92 | |
93 | mat, | 93 | this.application.ninja.selectedElements.forEach(function(element) { |
94 | dist, | 94 | // Reset to the identity matrix |
95 | newStyles = [], | 95 | //item = this.application.ninja.selectedElements[i]; |
96 | previousStyles = [], | 96 | iMat = Matrix.I(4); |
97 | len = this.application.ninja.selectedElements.length; | 97 | mat = ElementsMediator.getMatrix(element); |
98 | for(var i = 0; i < len; i++) | ||
99 | { | ||
100 | // Reset to the identity matrix but retain the rotation values | ||
101 | item = this.application.ninja.selectedElements[i]; | ||
102 | mat = ElementsMediator.getMatrix(item); | ||
103 | mat[12] = 0; | 98 | mat[12] = 0; |
104 | mat[13] = 0; | 99 | mat[13] = 0; |
105 | mat[14] = 0; | 100 | mat[14] = 0; |
106 | 101 | ||
107 | dist = ElementsMediator.getPerspectiveDist(item); | 102 | dist = ElementsMediator.getPerspectiveDist(element); |
108 | 103 | ||
109 | var previousStyleStr = {dist:dist, mat:item.mat}; | 104 | var previousStyleStr = {dist:dist, mat:element.elementModel.getProperty("mat")}; |
105 | var newStyleStr = {dist:dist, mat:iMat}; | ||
110 | 106 | ||
111 | var newStyleStr = {dist:dist, mat:mat}; | 107 | mod3dObject.push({element:element, properties:newStyleStr, previousProperties: previousStyleStr}); |
108 | }); | ||
112 | 109 | ||
113 | previousStyles.push(previousStyleStr); | 110 | ElementsMediator.set3DProperties(mod3dObject, "Change", "rotateTool"); |
114 | newStyles.push(newStyleStr); | ||
115 | } | ||
116 | |||
117 | ElementsMediator.set3DProperties(this.application.ninja.selectedElements, | ||
118 | newStyles, | ||
119 | "Change", | ||
120 | "translateTool", | ||
121 | previousStyles | ||
122 | ); | ||
123 | 111 | ||
124 | this.isDrawing = false; | 112 | this.isDrawing = false; |
125 | this.endDraw(event); | 113 | this.endDraw(event); |
126 | 114 | ||
127 | |||
128 | // Need to force stage to draw immediately so the new selection center is calculated | 115 | // Need to force stage to draw immediately so the new selection center is calculated |
129 | this.application.ninja.stage.draw(); | 116 | this.application.ninja.stage.draw(); |
130 | // And captureSelectionDrawn to draw the transform handles | 117 | // And captureSelectionDrawn to draw the transform handles |
@@ -149,26 +136,26 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, | |||
149 | 136 | ||
150 | _translateGlobally: { | 137 | _translateGlobally: { |
151 | value: function (transMat) { | 138 | value: function (transMat) { |
152 | //console.log( "_translateGlobally, startMat: " + this._startMat + ", transMat: " + transMat ); | ||
153 | //console.log( "_translateGlobally, transMat: " + transMat ); | 139 | //console.log( "_translateGlobally, transMat: " + transMat ); |
154 | var len = this._targets.length, | 140 | var selectedElements = this.application.ninja.selectedElements; |
155 | i = 0, | 141 | |
156 | item, | 142 | var len = selectedElements.length, |
157 | elt, | 143 | self = this, |
158 | curMat = viewUtils.getMatrixFromElement( this._target ), | 144 | target = selectedElements[0], |
145 | curMat = viewUtils.getMatrixFromElement( target ), | ||
159 | matInv = glmat4.inverse(this._startMat, []), | 146 | matInv = glmat4.inverse(this._startMat, []), |
160 | nMat = glmat4.multiply(transMat, this._startMat, [] ), | 147 | nMat = glmat4.multiply(transMat, this._startMat, [] ); |
161 | qMat = glmat4.multiply(matInv, nMat, []); | 148 | // qMat = glmat4.multiply(matInv, nMat, []); |
162 | 149 | ||
163 | if (this._mode === 1) | 150 | if(this._mode === 1) { |
164 | { | 151 | if (len > 1) curMat = target.elementModel.getProperty("mat").slice(); |
165 | var curInv = glmat4.inverse( curMat, [] ); | 152 | var curInv = glmat4.inverse( curMat, [] ); |
166 | transMat = glmat4.multiply( nMat, curInv, [] ); | 153 | transMat = glmat4.multiply( nMat, curInv, [] ); |
167 | } | 154 | } |
168 | 155 | ||
169 | var shouldUpdateStartMat = true; | 156 | var shouldUpdateStartMat = true; |
170 | 157 | ||
171 | if(this._clickedOnStage) | 158 | if(this._clickedOnStage || ((this._handleMode === 2) && (len > 1))) |
172 | { | 159 | { |
173 | shouldUpdateStartMat = false; | 160 | shouldUpdateStartMat = false; |
174 | } | 161 | } |
@@ -177,85 +164,60 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, | |||
177 | this._startMat = nMat; | 164 | this._startMat = nMat; |
178 | } | 165 | } |
179 | 166 | ||
180 | for(i = 0; i < len; i++) | 167 | selectedElements.forEach(function(element) { |
181 | { | 168 | curMat = element.elementModel.getProperty("mat").slice(0); |
182 | item = this._targets[i]; | ||
183 | elt = item.elt; | ||
184 | curMat = item.mat.slice(0); | ||
185 | 169 | ||
186 | // glmat4.multiply(curMat, qMat, curMat); | 170 | // glmat4.multiply(curMat, qMat, curMat); |
187 | // | 171 | // viewUtils.setMatrixForElement( elt, curMat, true); |
188 | // viewUtils.setMatrixForElement( elt, curMat, true); | ||
189 | curMat[12] += transMat[12]; | 172 | curMat[12] += transMat[12]; |
190 | curMat[13] += transMat[13]; | 173 | curMat[13] += transMat[13]; |
191 | curMat[14] += transMat[14]; | 174 | curMat[14] += transMat[14]; |
192 | viewUtils.setMatrixForElement( elt, curMat, true); | ||
193 | 175 | ||
194 | if(shouldUpdateStartMat) | 176 | viewUtils.setMatrixForElement(element, curMat, true); |
195 | { | 177 | |
178 | if(shouldUpdateStartMat) { | ||
196 | //console.log( "\t\tshouldUpdateStartMat" ); | 179 | //console.log( "\t\tshouldUpdateStartMat" ); |
197 | this._targets[i].mat = curMat; | 180 | element.elementModel.setProperty("mat", curMat); |
198 | } | 181 | } |
199 | } | 182 | |
183 | }); | ||
200 | } | 184 | } |
201 | }, | 185 | }, |
202 | 186 | ||
203 | _updateTargets: { | 187 | _updateTargets: { |
204 | value: function(addToUndoStack) { | 188 | value: function(addToUndo) { |
205 | // console.log( "_updateTargets" ); | 189 | var mod3dObject = [], self = this; |
206 | var newStyles = [], | ||
207 | previousStyles = [], | ||
208 | len = this.application.ninja.selectedElements.length; | ||
209 | this._targets = []; | ||
210 | for(var i = 0; i < len; i++) | ||
211 | { | ||
212 | var elt = this.application.ninja.selectedElements[i]; | ||
213 | 190 | ||
214 | var curMat = viewUtils.getMatrixFromElement(elt); | 191 | this.application.ninja.selectedElements.forEach(function(element) { |
215 | var curMatInv = glmat4.inverse(curMat, []); | 192 | if(addToUndo) { |
216 | 193 | var previousMat = element.elementModel.getProperty("mat").slice(0); | |
217 | this._targets.push({elt:elt, mat:curMat, matInv:curMatInv}); | 194 | var previousStyleStr = {dist:element.elementModel.getProperty("dist"), mat:MathUtils.scientificToDecimal(previousMat, 5)}; |
218 | if(addToUndoStack) | 195 | var newStyleStr = {dist:viewUtils.getPerspectiveDistFromElement(element), mat:MathUtils.scientificToDecimal(viewUtils.getMatrixFromElement(element), 5)}; |
219 | { | ||
220 | var previousStyleStr = {dist:this._undoArray[i].dist, mat:MathUtils.scientificToDecimal(this._undoArray[i].mat.slice(0), 5)}; | ||
221 | 196 | ||
222 | var newStyleStr = {dist:viewUtils.getPerspectiveDistFromElement(elt), mat:MathUtils.scientificToDecimal(curMat, 5)}; | 197 | mod3dObject.push({element:element, properties:newStyleStr, previousProperties: previousStyleStr}); |
223 | 198 | ||
224 | previousStyles.push(previousStyleStr); | ||
225 | newStyles.push(newStyleStr); | ||
226 | } | 199 | } |
227 | } | 200 | }); |
228 | if(addToUndoStack) | 201 | |
229 | { | 202 | if(addToUndo) { |
230 | ElementsMediator.set3DProperties(this.application.ninja.selectedElements, | 203 | ElementsMediator.set3DProperties(mod3dObject, "Change", "translateTool"); |
231 | newStyles, | 204 | |
232 | "Change", | 205 | if(this._origin && this._delta) { |
233 | "translateTool", | 206 | if(this._handleMode !== null) { |
234 | previousStyles | ||
235 | ); | ||
236 | if(this._origin && this._delta) | ||