diff options
Diffstat (limited to 'js/tools/Translate3DToolBase.js')
-rwxr-xr-x | js/tools/Translate3DToolBase.js | 178 |
1 files changed, 98 insertions, 80 deletions
diff --git a/js/tools/Translate3DToolBase.js b/js/tools/Translate3DToolBase.js index 4dca6313..2276178c 100755 --- a/js/tools/Translate3DToolBase.js +++ b/js/tools/Translate3DToolBase.js | |||
@@ -29,6 +29,8 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, | |||
29 | modifyElements : { | 29 | modifyElements : { |
30 | value : function(data, event) | 30 | value : function(data, event) |
31 | { | 31 | { |
32 | //console.log( "modifyElements, data: " + data.pt0 + " => " + data.pt1 ); | ||
33 | |||
32 | // form the translation vector and post translate the matrix by it. | 34 | // form the translation vector and post translate the matrix by it. |
33 | var delta = vecUtils.vecSubtract( 3, data.pt1, data.pt0 ); | 35 | var delta = vecUtils.vecSubtract( 3, data.pt1, data.pt0 ); |
34 | if(this._handleMode !== null) | 36 | if(this._handleMode !== null) |
@@ -66,13 +68,10 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, | |||
66 | delta[0] = 0; | 68 | delta[0] = 0; |
67 | delta[1] = 0; | 69 | delta[1] = 0; |
68 | } | 70 | } |
69 | else | ||
70 | { | ||
71 | delta[2] = 0; | ||
72 | } | ||
73 | this._delta = delta.slice(0); | 71 | this._delta = delta.slice(0); |
74 | } | 72 | } |
75 | 73 | ||
74 | //console.log( "modifyElements delta: " + delta ); | ||
76 | var transMat = Matrix.Translation( delta ); | 75 | var transMat = Matrix.Translation( delta ); |
77 | 76 | ||
78 | if(this._inLocalMode && (this._targets.length === 1) ) | 77 | if(this._inLocalMode && (this._targets.length === 1) ) |
@@ -134,6 +133,9 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, | |||
134 | // We will only translate single elements locally | 133 | // We will only translate single elements locally |
135 | _translateLocally: { | 134 | _translateLocally: { |
136 | value: function (transMat) { | 135 | value: function (transMat) { |
136 | //console.log( "_translateLocally, startMat: " + this._startMat ); | ||
137 | //console.log( "_translateLocally, transMat: " + transMat ); | ||
138 | //console.log( "_translateLocally, startMat: " + this._startMat + ", transMat: " + transMat ); | ||
137 | var mat = glmat4.multiply(this._startMat, transMat, []); | 139 | var mat = glmat4.multiply(this._startMat, transMat, []); |
138 | viewUtils.setMatrixForElement( this._target, mat, true ); | 140 | viewUtils.setMatrixForElement( this._target, mat, true ); |
139 | if(this._mode !== 1) | 141 | if(this._mode !== 1) |
@@ -145,18 +147,28 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, | |||
145 | 147 | ||
146 | _translateGlobally: { | 148 | _translateGlobally: { |
147 | value: function (transMat) { | 149 | value: function (transMat) { |
150 | //console.log( "_translateGlobally, transMat: " + transMat ); | ||
151 | //console.log( "_translateGlobally, startMat: " + this._startMat + ", transMat: " + transMat[12] + ", " + transMat[13] + ", " + transMat[14] ); | ||
148 | var len = this._targets.length, | 152 | var len = this._targets.length, |
149 | i = 0, | 153 | i = 0, |
150 | item, | 154 | item, |
151 | elt, | 155 | elt, |
152 | curMat, | 156 | curMat = viewUtils.getMatrixFromElement( this._target ), |
153 | matInv = glmat4.inverse(this._startMat, []), | 157 | matInv = glmat4.inverse(this._startMat, []), |
154 | nMat = glmat4.multiply(transMat, this._startMat, [] ), | 158 | nMat = glmat4.multiply(transMat, this._startMat, [] ), |
155 | qMat = glmat4.multiply(matInv, nMat, []); | 159 | qMat = glmat4.multiply(matInv, nMat, []); |
160 | |||
161 | if (this._mode === 1) | ||
162 | { | ||
163 | if (len > 1) curMat = this._targets[0].mat.slice(); | ||
164 | var curInv = glmat4.inverse( curMat, [] ); | ||
165 | transMat = glmat4.multiply( nMat, curInv, [] ); | ||
166 | } | ||
156 | 167 | ||
157 | var shouldUpdateStartMat = true; | 168 | var shouldUpdateStartMat = true; |
158 | 169 | ||
159 | if(this._clickedOnStage) | 170 | //if (this._clickedOnStage) |
171 | if(this._clickedOnStage || ((this._handleMode === 2) && (this._targets.length > 1))) | ||
160 | { | 172 | { |
161 | shouldUpdateStartMat = false; | 173 | shouldUpdateStartMat = false; |
162 | } | 174 | } |
@@ -174,24 +186,27 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, | |||
174 | // glmat4.multiply(curMat, qMat, curMat); | 186 | // glmat4.multiply(curMat, qMat, curMat); |
175 | // | 187 | // |
176 | // viewUtils.setMatrixForElement( elt, curMat, true); | 188 | // viewUtils.setMatrixForElement( elt, curMat, true); |
177 | curMat[12] += transMat[12]; | 189 | curMat[12] += transMat[12]; |
178 | curMat[13] += transMat[13]; | 190 | curMat[13] += transMat[13]; |
179 | curMat[14] += transMat[14]; | 191 | curMat[14] += transMat[14]; |
180 | viewUtils.setMatrixForElement( elt, curMat, true); | 192 | viewUtils.setMatrixForElement( elt, curMat, true); |
181 | 193 | ||
182 | if(shouldUpdateStartMat) | 194 | if(shouldUpdateStartMat) |
183 | { | 195 | { |
196 | //console.log( "\t\tshouldUpdateStartMat" ); | ||
184 | this._targets[i].mat = curMat; | 197 | this._targets[i].mat = curMat; |
185 | } | 198 | } |
186 | } | 199 | } |
187 | } | 200 | } |
188 | }, | 201 | }, |
189 | 202 | ||
190 | _updateTargets: { | 203 | _updateTargets: { |
191 | value: function(addToUndoStack) { | 204 | value: function(addToUndoStack) |
192 | var newStyles = [], | 205 | { |
193 | previousStyles = [], | 206 | //console.log( "_updateTargets" ); |
194 | len = this.application.ninja.selectedElements.length; | 207 | var newStyles = [], |
208 | previousStyles = [], | ||
209 | len = this.application.ninja.selectedElements.length; | ||
195 | this._targets = []; | 210 | this._targets = []; |
196 | for(var i = 0; i < len; i++) | 211 | for(var i = 0; i < len; i++) |
197 | { | 212 | { |
@@ -201,47 +216,47 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, | |||
201 | var curMatInv = glmat4.inverse(curMat, []); | 216 | var curMatInv = glmat4.inverse(curMat, []); |
202 | 217 | ||
203 | this._targets.push({elt:elt, mat:curMat, matInv:curMatInv}); | 218 | this._targets.push({elt:elt, mat:curMat, matInv:curMatInv}); |
204 | if(addToUndoStack) | 219 | if(addToUndoStack) |
205 | { | 220 | { |
206 | var previousStyleStr = {dist:this._undoArray[i].dist, mat:MathUtils.scientificToDecimal(this._undoArray[i].mat.slice(0), 5)}; | 221 | var previousStyleStr = {dist:this._undoArray[i].dist, mat:MathUtils.scientificToDecimal(this._undoArray[i].mat.slice(0), 5)}; |
207 | 222 | ||
208 | var newStyleStr = {dist:viewUtils.getPerspectiveDistFromElement(elt), mat:MathUtils.scientificToDecimal(curMat, 5)}; | 223 | var newStyleStr = {dist:viewUtils.getPerspectiveDistFromElement(elt), mat:MathUtils.scientificToDecimal(curMat, 5)}; |
209 | 224 | ||
210 | previousStyles.push(previousStyleStr); | 225 | previousStyles.push(previousStyleStr); |
211 | newStyles.push(newStyleStr); | 226 | newStyles.push(newStyleStr); |
212 | } | 227 | } |
213 | } | 228 | } |
214 | if(addToUndoStack) | 229 | if(addToUndoStack) |
215 | { | 230 | { |
216 | ElementsMediator.set3DProperties(this.application.ninja.selectedElements, | 231 | ElementsMediator.set3DProperties(this.application.ninja.selectedElements, |
217 | newStyles, | 232 | newStyles, |
218 | "Change", | 233 | "Change", |
219 | "translateTool", | 234 | "translateTool", |
220 | previousStyles | 235 | previousStyles |
221 | ); | 236 | ); |
222 | if(this._origin && this._delta) | 237 | if(this._origin && this._delta) |
223 | { | 238 | { |
224 | if(this._handleMode !== null) | 239 | if(this._handleMode !== null) |
225 | { | 240 | { |
226 | this._origin[this._handleMode] += this._delta; | 241 | this._origin[this._handleMode] += this._delta; |
227 | } | 242 | } |
228 | else | 243 | else |
229 | { | 244 | { |
230 | this._origin[0] += this._delta[0]; | 245 | this._origin[0] += this._delta[0]; |
231 | this._origin[1] += this._delta[1]; | 246 | this._origin[1] += this._delta[1]; |
232 | } | 247 | } |
233 | } | 248 | } |
234 | this._delta = null; | 249 | this._delta = null; |
235 | } | 250 | } |
236 | // Save previous value for undo/redo | 251 | // Save previous value for undo/redo |
237 | this._undoArray = []; | 252 | this._undoArray = []; |
238 | for(i = 0, len = this._targets.length; i < len; i++) | 253 | for(i = 0, len = this._targets.length; i < len; i++) |
239 | { | 254 | { |
240 | var elt = this._targets[i].elt; | 255 | var elt = this._targets[i].elt; |
241 | var _mat = viewUtils.getMatrixFromElement(elt); | 256 | var _mat = viewUtils.getMatrixFromElement(elt); |
242 | var _dist = viewUtils.getPerspectiveDistFromElement(elt); | 257 | var _dist = viewUtils.getPerspectiveDistFromElement(elt); |
243 | this._undoArray.push({mat:_mat, dist:_dist}); | 258 | this._undoArray.push({mat:_mat, dist:_dist}); |
244 | } | 259 | } |
245 | 260 | ||
246 | } | 261 | } |
247 | }, | 262 | }, |
@@ -291,27 +306,27 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, | |||
291 | } | 306 | } |
292 | else | 307 | else |
293 | { | 308 | { |
294 | if(this._origin) | 309 | if(this._origin) |
295 | { | 310 | { |
296 | if(this._delta) | 311 | if(this._delta) |
297 | { | 312 | { |
298 | if(this._handleMode !== null) | 313 | if(this._handleMode !== null) |
299 | { | 314 | { |
300 | // this._origin[this._handleMode] = this._delta; | 315 | // this._origin[this._handleMode] = this._delta; |
301 | } | 316 | } |
302 | else | 317 | else |
303 | { | 318 | { |
304 | this._origin[0] += this._delta[0]; | 319 |