aboutsummaryrefslogtreecommitdiff
path: root/js/tools/Translate3DToolBase.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/tools/Translate3DToolBase.js')
-rwxr-xr-xjs/tools/Translate3DToolBase.js158
1 files changed, 56 insertions, 102 deletions
diff --git a/js/tools/Translate3DToolBase.js b/js/tools/Translate3DToolBase.js
index e4f1fb99..04359567 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
@@ -74,7 +73,7 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase,
74 var transMat = Matrix.Translation( delta ); 73 var transMat = Matrix.Translation( delta );
75 74
76 //console.log( "Translate: " + delta ); 75 //console.log( "Translate: " + delta );
77 if(this._inLocalMode && (this._targets.length === 1) ) 76 if(this._inLocalMode && (this.application.ninja.selectedElements.length === 1) )
78 { 77 {
79 this._translateLocally(transMat); 78 this._translateLocally(transMat);
80 } 79 }
@@ -86,45 +85,32 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase,
86 }, 85 },
87 86
88 87
89 Reset : { 88 Reset: {
90 value : function() 89 value: function() {
91 { 90 var mat, iMat, dist, mod3dObject = [], self = this;
92 var item, 91
93 mat, 92 this.application.ninja.selectedElements.forEach(function(element) {
94 dist, 93 // Reset to the identity matrix
95 newStyles = [], 94 //item = this.application.ninja.selectedElements[i];
96 previousStyles = [], 95 iMat = Matrix.I(4);
97 len = this.application.ninja.selectedElements.length; 96 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; 97 mat[12] = 0;
104 mat[13] = 0; 98 mat[13] = 0;
105 mat[14] = 0; 99 mat[14] = 0;
106 100
107 dist = ElementsMediator.getPerspectiveDist(item); 101 dist = ElementsMediator.getPerspectiveDist(element);
108 102
109 var previousStyleStr = {dist:dist, mat:item.mat}; 103 var previousStyleStr = {dist:dist, mat:element.elementModel.getProperty("mat")};
104 var newStyleStr = {dist:dist, mat:iMat};
110 105
111 var newStyleStr = {dist:dist, mat:mat}; 106 mod3dObject.push({element:element, properties:newStyleStr, previousProperties: previousStyleStr});
112 107 });
113 previousStyles.push(previousStyleStr);
114 newStyles.push(newStyleStr);
115 }
116 108
117 ElementsMediator.set3DProperties(this.application.ninja.selectedElements, 109 ElementsMediator.set3DProperties(mod3dObject, "Change", "rotateTool");
118 newStyles,
119 "Change",
120 "translateTool",
121 previousStyles
122 );
123 110
124 this.isDrawing = false; 111 this.isDrawing = false;
125 this.endDraw(event); 112 this.endDraw(event);
126 113
127
128 // Need to force stage to draw immediately so the new selection center is calculated 114 // Need to force stage to draw immediately so the new selection center is calculated
129 this.application.ninja.stage.draw(); 115 this.application.ninja.stage.draw();
130 // And captureSelectionDrawn to draw the transform handles 116 // And captureSelectionDrawn to draw the transform handles
@@ -151,111 +137,79 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase,
151 value: function (transMat) { 137 value: function (transMat) {
152 //console.log( "_translateGlobally, startMat: " + this._startMat + ", transMat: " + transMat ); 138 //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 self = this,
155 i = 0,
156 item,
157 elt,
158 curMat = viewUtils.getMatrixFromElement( this._target ), 141 curMat = viewUtils.getMatrixFromElement( this._target ),
159 matInv = glmat4.inverse(this._startMat, []), 142 matInv = glmat4.inverse(this._startMat, []),
160 nMat = glmat4.multiply(transMat, this._startMat, [] ), 143 nMat = glmat4.multiply(transMat, this._startMat, [] );
161 qMat = glmat4.multiply(matInv, nMat, []); 144// qMat = glmat4.multiply(matInv, nMat, []);
162 145
163 if (this._mode === 1) 146 if(this._mode === 1) {
164 {
165 var curInv = glmat4.inverse( curMat, [] ); 147 var curInv = glmat4.inverse( curMat, [] );
166 transMat = glmat4.multiply( nMat, curInv, [] ); 148 transMat = glmat4.multiply( nMat, curInv, [] );
167 } 149 }
168 150
169 var shouldUpdateStartMat = true; 151 var shouldUpdateStartMat = true;
170 152
171 if(this._clickedOnStage) 153 if(this._clickedOnStage) {
172 {
173 shouldUpdateStartMat = false; 154 shouldUpdateStartMat = false;
174 } 155 } else if(this._mode !== 1) {
175 else if(this._mode !== 1)
176 {
177 this._startMat = nMat; 156 this._startMat = nMat;
178 } 157 }
179 158
180 for(i = 0; i < len; i++) 159 this.application.ninja.selectedElements.forEach(function(element) {
181 { 160 curMat = element.elementModel.getProperty("mat").slice(0);
182 item = this._targets[i];
183 elt = item.elt;
184 curMat = item.mat.slice(0);
185 161
186// glmat4.multiply(curMat, qMat, curMat); 162// glmat4.multiply(curMat, qMat, curMat);
187// 163// viewUtils.setMatrixForElement( elt, curMat, true);
188// viewUtils.setMatrixForElement( elt, curMat, true);
189 curMat[12] += transMat[12]; 164 curMat[12] += transMat[12];
190 curMat[13] += transMat[13]; 165 curMat[13] += transMat[13];
191 curMat[14] += transMat[14]; 166 curMat[14] += transMat[14];
192 viewUtils.setMatrixForElement( elt, curMat, true);
193 167
194 if(shouldUpdateStartMat) 168 viewUtils.setMatrixForElement(element, curMat, true);
195 { 169
170 if(shouldUpdateStartMat) {
196 //console.log( "\t\tshouldUpdateStartMat" ); 171 //console.log( "\t\tshouldUpdateStartMat" );
197 this._targets[i].mat = curMat; 172 element.elementModel.setProperty("mat", curMat);
198 } 173 }
199 } 174
175 });
200 } 176 }
201 }, 177 },
202 178
203 _updateTargets: { 179 _updateTargets: {
204 value: function(addToUndoStack) { 180 value: function(addToUndo) {
205// console.log( "_updateTargets" ); 181 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 182
214 var curMat = viewUtils.getMatrixFromElement(elt); 183 this.application.ninja.selectedElements.forEach(function(element) {
215 var curMatInv = glmat4.inverse(curMat, []); 184 if(addToUndo) {
185 var previousMat = element.elementModel.getProperty("mat").slice(0);
186 var previousStyleStr = {dist:element.elementModel.getProperty("dist"), mat:MathUtils.scientificToDecimal(previousMat, 5)};
187 var newStyleStr = {dist:viewUtils.getPerspectiveDistFromElement(element), mat:MathUtils.scientificToDecimal(viewUtils.getMatrixFromElement(element), 5)};
216 188
217 this._targets.push({elt:elt, mat:curMat, matInv:curMatInv}); 189 mod3dObject.push({element:element, properties:newStyleStr, previousProperties: previousStyleStr});
218 if(addToUndoStack)
219 {
220 var previousStyleStr = {dist:this._undoArray[i].dist, mat:MathUtils.scientificToDecimal(this._undoArray[i].mat.slice(0), 5)};
221
222 var newStyleStr = {dist:viewUtils.getPerspectiveDistFromElement(elt), mat:MathUtils.scientificToDecimal(curMat, 5)};
223 190
224 previousStyles.push(previousStyleStr);
225 newStyles.push(newStyleStr);
226 } 191 }
227 } 192 });
228 if(addToUndoStack) 193
229 { 194 if(addToUndo) {
230 ElementsMediator.set3DProperties(this.application.ninja.selectedElements, 195 ElementsMediator.set3DProperties(mod3dObject, "Change", "translateTool");
231 newStyles, 196
232 "Change", 197 if(this._origin && this._delta) {
233 "translateTool", 198 if(this._handleMode !== null) {
234 previousStyles
235 );
236 if(this._origin && this._delta)
237 {
238 if(this._handleMode !== null)
239 {
240 this._origin[this._handleMode] += this._delta; 199 this._origin[this._handleMode] += this._delta;
241 } 200 } else {
242 else
243 {
244 this._origin[0] += this._delta[0]; 201 this._origin[0] += this._delta[0];
245 this._origin[1] += this._delta[1]; 202 this._origin[1] += this._delta[1];
246 } 203 }
247 } 204 }
205
248 this._delta = null; 206 this._delta = null;
249 }