diff options
Diffstat (limited to 'js/tools')
-rwxr-xr-x | js/tools/Translate3DToolBase.js | 175 | ||||
-rwxr-xr-x | js/tools/TranslateObject3DTool.js | 22 | ||||
-rwxr-xr-x | js/tools/modifier-tool-base.js | 27 |
3 files changed, 130 insertions, 94 deletions
diff --git a/js/tools/Translate3DToolBase.js b/js/tools/Translate3DToolBase.js index 4dca6313..4799b840 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,10 +68,6 @@ 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 | ||
@@ -81,6 +79,7 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, | |||
81 | } | 79 | } |
82 | else | 80 | else |
83 | { | 81 | { |
82 | console.log( "modifyElements delta: " + delta ); | ||
84 | this._translateGlobally(transMat); | 83 | this._translateGlobally(transMat); |
85 | } | 84 | } |
86 | } | 85 | } |
@@ -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,14 +147,23 @@ 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 ); | ||
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 | ||
@@ -174,24 +185,27 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, | |||
174 | // glmat4.multiply(curMat, qMat, curMat); | 185 | // glmat4.multiply(curMat, qMat, curMat); |
175 | // | 186 | // |
176 | // viewUtils.setMatrixForElement( elt, curMat, true); | 187 | // viewUtils.setMatrixForElement( elt, curMat, true); |
177 | curMat[12] += transMat[12]; | 188 | curMat[12] += transMat[12]; |
178 | curMat[13] += transMat[13]; | 189 | curMat[13] += transMat[13]; |
179 | curMat[14] += transMat[14]; | 190 | curMat[14] += transMat[14]; |
180 | viewUtils.setMatrixForElement( elt, curMat, true); | 191 | viewUtils.setMatrixForElement( elt, curMat, true); |
181 | 192 | ||
182 | if(shouldUpdateStartMat) | 193 | if(shouldUpdateStartMat) |
183 | { | 194 | { |
195 | //console.log( "\t\tshouldUpdateStartMat" ); | ||
184 | this._targets[i].mat = curMat; | 196 | this._targets[i].mat = curMat; |
185 | } | 197 | } |
186 | } | 198 | } |
187 | } | 199 | } |
188 | }, | 200 | }, |
189 | 201 | ||
190 | _updateTargets: { | 202 | _updateTargets: { |
191 | value: function(addToUndoStack) { | 203 | value: function(addToUndoStack) |
192 | var newStyles = [], | 204 | { |
193 | previousStyles = [], | 205 | //console.log( "_updateTargets" ); |
194 | len = this.application.ninja.selectedElements.length; | 206 | var newStyles = [], |
207 | previousStyles = [], | ||
208 | len = this.application.ninja.selectedElements.length; | ||
195 | this._targets = []; | 209 | this._targets = []; |
196 | for(var i = 0; i < len; i++) | 210 | for(var i = 0; i < len; i++) |
197 | { | 211 | { |
@@ -201,47 +215,47 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, | |||
201 | var curMatInv = glmat4.inverse(curMat, []); | 215 | var curMatInv = glmat4.inverse(curMat, []); |
202 | 216 | ||
203 | this._targets.push({elt:elt, mat:curMat, matInv:curMatInv}); | 217 | this._targets.push({elt:elt, mat:curMat, matInv:curMatInv}); |
204 | if(addToUndoStack) | 218 | if(addToUndoStack) |
205 | { | 219 | { |
206 | var previousStyleStr = {dist:this._undoArray[i].dist, mat:MathUtils.scientificToDecimal(this._undoArray[i].mat.slice(0), 5)}; | 220 | var previousStyleStr = {dist:this._undoArray[i].dist, mat:MathUtils.scientificToDecimal(this._undoArray[i].mat.slice(0), 5)}; |
207 | 221 | ||
208 | var newStyleStr = {dist:viewUtils.getPerspectiveDistFromElement(elt), mat:MathUtils.scientificToDecimal(curMat, 5)}; | 222 | var newStyleStr = {dist:viewUtils.getPerspectiveDistFromElement(elt), mat:MathUtils.scientificToDecimal(curMat, 5)}; |
209 | 223 | ||
210 | previousStyles.push(previousStyleStr); | 224 | previousStyles.push(previousStyleStr); |
211 | newStyles.push(newStyleStr); | 225 | newStyles.push(newStyleStr); |
212 | } | 226 | } |
213 | } | 227 | } |
214 | if(addToUndoStack) | 228 | if(addToUndoStack) |
215 | { | 229 | { |
216 | ElementsMediator.set3DProperties(this.application.ninja.selectedElements, | 230 | ElementsMediator.set3DProperties(this.application.ninja.selectedElements, |
217 | newStyles, | 231 | newStyles, |
218 | "Change", | 232 | "Change", |
219 | "translateTool", | 233 | "translateTool", |
220 | previousStyles | 234 | previousStyles |
221 | ); | 235 | ); |
222 | if(this._origin && this._delta) | 236 | if(this._origin && this._delta) |
223 | { | 237 | { |
224 | if(this._handleMode !== null) | 238 | if(this._handleMode !== null) |
225 | { | 239 | { |
226 | this._origin[this._handleMode] += this._delta; | 240 | this._origin[this._handleMode] += this._delta; |
227 | } | 241 | } |
228 | else | 242 | else |
229 | { | 243 | { |
230 | this._origin[0] += this._delta[0]; | 244 | this._origin[0] += this._delta[0]; |
231 | this._origin[1] += this._delta[1]; | 245 | this._origin[1] += this._delta[1]; |
232 | } | 246 | } |
233 | } | 247 | } |
234 | this._delta = null; | 248 | this._delta = null; |
235 | } | 249 | } |
236 | // Save previous value for undo/redo | 250 | // Save previous value for undo/redo |
237 | this._undoArray = []; | 251 | this._undoArray = []; |
238 | for(i = 0, len = this._targets.length; i < len; i++) | 252 | for(i = 0, len = this._targets.length; i < len; i++) |
239 | { | 253 | { |
240 | var elt = this._targets[i].elt; | 254 | var elt = this._targets[i].elt; |
241 | var _mat = viewUtils.getMatrixFromElement(elt); | 255 | var _mat = viewUtils.getMatrixFromElement(elt); |
242 | var _dist = viewUtils.getPerspectiveDistFromElement(elt); | 256 | var _dist = viewUtils.getPerspectiveDistFromElement(elt); |
243 | this._undoArray.push({mat:_mat, dist:_dist}); | 257 | this._undoArray.push({mat:_mat, dist:_dist}); |
244 | } | 258 | } |
245 | 259 | ||
246 | } | 260 | } |
247 | }, | 261 | }, |
@@ -291,27 +305,27 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, | |||
291 | } | 305 | } |
292 | else | 306 | else |
293 | { | 307 | { |
294 | if(this._origin) | 308 | if(this._origin) |
295 | { | 309 | { |
296 | if(this._delta) | 310 | if(this._delta) |
297 | { | 311 | { |
298 | if(this._handleMode !== null) | 312 | if(this._handleMode !== null) |
299 | { | 313 | { |
300 | // this._origin[this._handleMode] = this._delta; | 314 | // this._origin[this._handleMode] = this._delta; |
301 | } | 315 | } |
302 | else | 316 | else |
303 | { | 317 |