diff options
Diffstat (limited to 'js/tools/Translate3DToolBase.js')
-rwxr-xr-x | js/tools/Translate3DToolBase.js | 255 |
1 files changed, 165 insertions, 90 deletions
diff --git a/js/tools/Translate3DToolBase.js b/js/tools/Translate3DToolBase.js index e4f1fb99..41dbb3ae 100755 --- a/js/tools/Translate3DToolBase.js +++ b/js/tools/Translate3DToolBase.js | |||
@@ -71,9 +71,9 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, | |||
71 | this._delta = delta.slice(0); | 71 | this._delta = delta.slice(0); |
72 | } | 72 | } |
73 | 73 | ||
74 | //console.log( "modifyElements delta: " + delta ); | ||
74 | var transMat = Matrix.Translation( delta ); | 75 | var transMat = Matrix.Translation( delta ); |
75 | 76 | ||
76 | //console.log( "Translate: " + delta ); | ||
77 | if(this._inLocalMode && (this._targets.length === 1) ) | 77 | if(this._inLocalMode && (this._targets.length === 1) ) |
78 | { | 78 | { |
79 | this._translateLocally(transMat); | 79 | this._translateLocally(transMat); |
@@ -149,26 +149,28 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, | |||
149 | 149 | ||
150 | _translateGlobally: { | 150 | _translateGlobally: { |
151 | value: function (transMat) { | 151 | value: function (transMat) { |
152 | //console.log( "_translateGlobally, startMat: " + this._startMat + ", transMat: " + transMat ); | 152 | //console.log( "_translateGlobally, transMat: " + transMat ); |
153 | //console.log( "_translateGlobally, transMat: " + transMat ); | 153 | //console.log( "_translateGlobally, startMat: " + this._startMat + ", transMat: " + transMat[12] + ", " + transMat[13] + ", " + transMat[14] ); |
154 | var len = this._targets.length, | 154 | var len = this._targets.length, |
155 | i = 0, | 155 | i = 0, |
156 | item, | 156 | item, |
157 | elt, | 157 | elt, |
158 | curMat = viewUtils.getMatrixFromElement( this._target ), | 158 | curMat = viewUtils.getMatrixFromElement( this._target ), |
159 | matInv = glmat4.inverse(this._startMat, []), | 159 | matInv = glmat4.inverse(this._startMat, []), |
160 | nMat = glmat4.multiply(transMat, this._startMat, [] ), | 160 | nMat = glmat4.multiply(transMat, this._startMat, [] ), |
161 | qMat = glmat4.multiply(matInv, nMat, []); | 161 | qMat = glmat4.multiply(matInv, nMat, []); |
162 | 162 | ||
163 | if (this._mode === 1) | 163 | if (this._mode === 1) |
164 | { | 164 | { |
165 | var curInv = glmat4.inverse( curMat, [] ); | 165 | if (len > 1) curMat = this._targets[0].mat.slice(); |
166 | transMat = glmat4.multiply( nMat, curInv, [] ); | 166 | var curInv = glmat4.inverse( curMat, [] ); |
167 | } | 167 | transMat = glmat4.multiply( nMat, curInv, [] ); |
168 | } | ||
168 | 169 | ||
169 | var shouldUpdateStartMat = true; | 170 | var shouldUpdateStartMat = true; |
170 | 171 | ||
171 | if(this._clickedOnStage) | 172 | //if (this._clickedOnStage) |
173 | if(this._clickedOnStage || ((this._handleMode === 2) && (this._targets.length > 1))) | ||
172 | { | 174 | { |
173 | shouldUpdateStartMat = false; | 175 | shouldUpdateStartMat = false; |
174 | } | 176 | } |
@@ -186,26 +188,25 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, | |||
186 | // glmat4.multiply(curMat, qMat, curMat); | 188 | // glmat4.multiply(curMat, qMat, curMat); |
187 | // | 189 | // |
188 | // viewUtils.setMatrixForElement( elt, curMat, true); | 190 | // viewUtils.setMatrixForElement( elt, curMat, true); |
189 | curMat[12] += transMat[12]; | 191 | curMat[12] += transMat[12]; |
190 | curMat[13] += transMat[13]; | 192 | curMat[13] += transMat[13]; |
191 | curMat[14] += transMat[14]; | 193 | curMat[14] += transMat[14]; |
192 | viewUtils.setMatrixForElement( elt, curMat, true); | 194 | viewUtils.setMatrixForElement( elt, curMat, true); |
193 | 195 | ||
194 | if(shouldUpdateStartMat) | 196 | if(shouldUpdateStartMat) |
195 | { | 197 | { |
196 | //console.log( "\t\tshouldUpdateStartMat" ); | 198 | //console.log( "\t\tshouldUpdateStartMat" ); |
197 | this._targets[i].mat = curMat; | 199 | this._targets[i].mat = curMat; |
198 | } | 200 | } |
199 | } | 201 | } |
200 | } | 202 | } |
201 | }, | 203 | }, |
202 | 204 | ||
203 | _updateTargets: { | 205 | _updateTargets: { |
204 | value: function(addToUndoStack) { | 206 | value: function(addToUndoStack) { |
205 | // console.log( "_updateTargets" ); | 207 | var newStyles = [], |
206 | var newStyles = [], | 208 | previousStyles = [], |
207 | previousStyles = [], | 209 | len = this.application.ninja.selectedElements.length; |
208 | len = this.application.ninja.selectedElements.length; | ||
209 | this._targets = []; | 210 | this._targets = []; |
210 | for(var i = 0; i < len; i++) | 211 | for(var i = 0; i < len; i++) |
211 | { | 212 | { |
@@ -215,47 +216,47 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, | |||
215 | var curMatInv = glmat4.inverse(curMat, []); | 216 | var curMatInv = glmat4.inverse(curMat, []); |
216 | 217 | ||
217 | this._targets.push({elt:elt, mat:curMat, matInv:curMatInv}); | 218 | this._targets.push({elt:elt, mat:curMat, matInv:curMatInv}); |
218 | if(addToUndoStack) | 219 | if(addToUndoStack) |
219 | { | 220 | { |
220 | 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)}; |
221 | 222 | ||
222 | var newStyleStr = {dist:viewUtils.getPerspectiveDistFromElement(elt), mat:MathUtils.scientificToDecimal(curMat, 5)}; | 223 | var newStyleStr = {dist:viewUtils.getPerspectiveDistFromElement(elt), mat:MathUtils.scientificToDecimal(curMat, 5)}; |
223 | 224 | ||
224 | previousStyles.push(previousStyleStr); | 225 | previousStyles.push(previousStyleStr); |
225 | newStyles.push(newStyleStr); | 226 | newStyles.push(newStyleStr); |
226 | } | 227 | } |
227 | } | 228 | } |
228 | if(addToUndoStack) | 229 | if(addToUndoStack) |
229 | { | 230 | { |
230 | ElementsMediator.set3DProperties(this.application.ninja.selectedElements, | 231 | ElementsMediator.set3DProperties(this.application.ninja.selectedElements, |
231 | newStyles, | 232 | newStyles, |
232 | "Change", | 233 | "Change", |
233 | "translateTool", | 234 | "translateTool", |
234 | previousStyles | 235 | previousStyles |
235 | ); | 236 | ); |
236 | if(this._origin && this._delta) | 237 | if(this._origin && this._delta) |
237 | { | 238 | { |
238 | if(this._handleMode !== null) | 239 | if(this._handleMode !== null) |
239 | { | 240 | { |
240 | this._origin[this._handleMode] += this._delta; | 241 | this._origin[this._handleMode] += this._delta; |
241 | } | 242 | } |
242 | else | 243 | else |
243 | { | 244 | { |
244 | this._origin[0] += this._delta[0]; | 245 | this._origin[0] += this._delta[0]; |
245 | this._origin[1] += this._delta[1]; | 246 | this._origin[1] += this._delta[1]; |
246 | } | 247 | } |
247 | } | 248 | } |
248 | this._delta = null; | 249 | this._delta = null; |
249 | } | 250 | } |
250 | // Save previous value for undo/redo | 251 | // Save previous value for undo/redo |
251 | this._undoArray = []; | 252 | this._undoArray = []; |
252 | for(i = 0, len = this._targets.length; i < len; i++) | 253 | for(i = 0, len = this._targets.length; i < len; i++) |
253 | { | 254 | { |
254 | var elt = this._targets[i].elt; | 255 | var elt = this._targets[i].elt; |
255 | var _mat = viewUtils.getMatrixFromElement(elt); | 256 | var _mat = viewUtils.getMatrixFromElement(elt); |
256 | var _dist = viewUtils.getPerspectiveDistFromElement(elt); | 257 | var _dist = viewUtils.getPerspectiveDistFromElement(elt); |
257 | this._undoArray.push({mat:_mat, dist:_dist}); | 258 | this._undoArray.push({mat:_mat, dist:_dist}); |
258 | } | 259 | } |
259 | 260 | ||
260 | } | 261 | } |
261 | }, | 262 | }, |
@@ -295,42 +296,113 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, | |||
295 | viewUtils.popViewportObj(); | 296 | viewUtils.popViewportObj(); |
296 | ctr[2] = 0; | 297 | ctr[2] = 0; |
297 | 298 | ||
298 | // var ctrOffset = item.elementModel.props3D.m_transformCtr; | ||
299 | // if(ctrOffset) | ||
300 | // { | ||
301 | // ctr = vecUtils.vecAdd(3, ctr, ctrOffset); | ||
302 | // } | ||
303 | |||
304 | this._origin = viewUtils.localToGlobal(ctr, item); | 299 | this._origin = viewUtils.localToGlobal(ctr, item); |
305 | } | 300 | } |
306 | else | 301 | else |
307 | { | 302 | { |
308 | if(this._origin) | 303 | this._origin = undefined; |
309 | { | 304 | this._origin = this.calculateMultiSelOrigin(); |
310 | if(this._delta) | 305 | } |
311 | { | 306 | } |
312 | if(this._handleMode !== null) | 307 | } |
313 | { | 308 | }, |
314 | // this._origin[this._handleMode] = this._delta; | 309 | |
315 | } | 310 | captureSelectionDrawn: { |
316 | else | 311 | value: function(event){ |
317 | { | 312 | this._origin = null; |
318 | this._origin[0] += this._delta[0]; | 313 | this._targets = []; |
319 | this._origin[1] += this._delta[1]; | 314 | this._startOriginArray = null; |
320 | } | 315 | |
321 | } | 316 | var len = this.application.ninja.selectedElements.length; |
322 | } | 317 | if(len) |
323 | else | 318 | { |
319 | if(len === 1) | ||
320 | { | ||
321 | this.target = this.application.ninja.selectedElements[0]; | ||
322 | drawUtils.addElement(this.target); | ||
323 |