aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhwc4872012-04-02 15:40:25 -0700
committerhwc4872012-04-02 15:40:25 -0700
commitdc9650af5760b1f93d6e93a383eabceacfdc0ad8 (patch)
tree6f34187aa4670cfceb276d5b2504d192652847dc
parent7805cc9c59d218ae9fe9cf3fac4fcec1fdf10fae (diff)
downloadninja-dc9650af5760b1f93d6e93a383eabceacfdc0ad8.tar.gz
Snapping fixes.
-rwxr-xr-xjs/lib/geom/line.js70
-rwxr-xr-xjs/tools/Translate3DToolBase.js25
-rwxr-xr-xjs/tools/TranslateObject3DTool.js21
-rwxr-xr-xjs/tools/modifier-tool-base.js14
4 files changed, 41 insertions, 89 deletions
diff --git a/js/lib/geom/line.js b/js/lib/geom/line.js
index e839e229..1848218d 100755
--- a/js/lib/geom/line.js
+++ b/js/lib/geom/line.js
@@ -140,76 +140,6 @@ var Line = function GLLine( world, xOffset, yOffset, width, height, slope, strok
140 this.importMaterialsJSON( jObj.materials ); 140 this.importMaterialsJSON( jObj.materials );
141 }; 141 };
142 142
143 this.export = function() {
144 var rtnStr = "type: " + this.geomType() + "\n";
145
146 rtnStr += "xoff: " + this._xOffset + "\n";
147 rtnStr += "yoff: " + this._yOffset + "\n";
148 rtnStr += "width: " + this._width + "\n";
149 rtnStr += "height: " + this._height + "\n";
150 rtnStr += "xAdj: " + this._xAdj + "\n";
151 rtnStr += "yAdj: " + this._yAdj + "\n";
152 rtnStr += "strokeWidth: " + this._strokeWidth + "\n";
153
154 if(this._strokeColor.gradientMode) {
155 rtnStr += "strokeGradientMode: " + this._strokeColor.gradientMode + "\n";
156 rtnStr += "strokeColor: " + this.gradientToString(this._strokeColor.color) + "\n";
157 } else {
158 rtnStr += "strokeColor: " + String(this._strokeColor) + "\n";
159 }
160
161 rtnStr += "strokeStyle: " + this._strokeStyle + "\n";
162 rtnStr += "slope: " + String(this._slope) + "\n";
163
164 rtnStr += "strokeMat: ";
165 if (this._strokeMaterial) {
166 rtnStr += this._strokeMaterial.getName();
167 } else {
168 rtnStr += MaterialsModel.getDefaultMaterialName();
169 }
170
171 rtnStr += "\n";
172 return rtnStr;
173 };
174
175 this.import = function( importStr ) {
176 this._xOffset = Number( this.getPropertyFromString( "xoff: ", importStr ) );
177 this._yOffset = Number( this.getPropertyFromString( "yoff: ", importStr ) );
178 this._width = Number( this.getPropertyFromString( "width: ", importStr ) );
179 this._height = Number( this.getPropertyFromString( "height: ", importStr ) );
180 this._xAdj = Number( this.getPropertyFromString( "xAdj: ", importStr ) );
181 this._yAdj = Number( this.getPropertyFromString( "yAdj: ", importStr ) );
182 this._strokeWidth = Number( this.getPropertyFromString( "strokeWidth: ", importStr ) );
183 var slope = this.getPropertyFromString( "slope: ", importStr );
184
185 if(isNaN(Number(slope))) {
186 this._slope = slope;
187 } else {
188 this._slope = Number(slope);
189 }
190
191 var strokeMaterialName = this.getPropertyFromString( "strokeMat: ", importStr );
192 this._strokeStyle = this.getPropertyFromString( "strokeStyle: ", importStr );
193
194 if(importStr.indexOf("strokeGradientMode: ") < 0)
195 {
196 this._strokeColor = eval( "[" + this.getPropertyFromString( "strokeColor: ", importStr ) + "]" );
197 } else {
198 this._strokeColor = {};
199 this._strokeColor.gradientMode = this.getPropertyFromString( "strokeGradientMode: ", importStr );
200 this._strokeColor.color = this.stringToGradient(this.getPropertyFromString( "strokeColor: ", importStr ));
201 }
202
203 var strokeMat = MaterialsModel.getMaterial( strokeMaterialName );
204 if (!strokeMat) {
205 console.log( "object material not found in library: " + strokeMaterialName );
206 strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() );
207 }
208
209 this._strokeMaterial = strokeMat;
210
211 };
212
213 /////////////////////////////////////////////////////////////////////// 143 ///////////////////////////////////////////////////////////////////////
214 // Methods 144 // Methods
215 /////////////////////////////////////////////////////////////////////// 145 ///////////////////////////////////////////////////////////////////////
diff --git a/js/tools/Translate3DToolBase.js b/js/tools/Translate3DToolBase.js
index 07b6d04d..18e2b610 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,15 +68,12 @@ 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
76 var transMat = Matrix.Translation( delta ); 74 var transMat = Matrix.Translation( delta );
77 75
76 //console.log( "Translate: " + delta );
78 if(this._inLocalMode && (this._targets.length === 1) ) 77 if(this._inLocalMode && (this._targets.length === 1) )
79 { 78 {
80 this._translateLocally(transMat); 79 this._translateLocally(transMat);
@@ -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,22 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase,
145 147
146 _translateGlobally: { 148 _translateGlobally: {
147 value: function (transMat) { 149 value: function (transMat) {
150 //console.log( "_translateGlobally, startMat: " + this._startMat + ", transMat: " + transMat );
151 //console.log( "_translateGlobally, 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 var curInv = glmat4.inverse( curMat, [] );
164 transMat = glmat4.multiply( nMat, curInv, [] );
165 }
156 166
157 var shouldUpdateStartMat = true; 167 var shouldUpdateStartMat = true;
158 168
@@ -181,6 +191,7 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase,
181 191
182 if(shouldUpdateStartMat) 192 if(shouldUpdateStartMat)
183 { 193 {
194 //console.log( "\t\tshouldUpdateStartMat" );
184 this._targets[i].mat = curMat; 195 this._targets[i].mat = curMat;
185 } 196 }
186 } 197 }
@@ -188,7 +199,9 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase,
188 }, 199 },
189 200
190 _updateTargets: { 201 _updateTargets: {
191 value: function(addToUndoStack) { 202 value: function(addToUndoStack)
203 {
204 console.log( "_updateTargets" );
192 var newStyles = [], 205 var newStyles = [],
193 previousStyles = [], 206 previousStyles = [],
194 len = this.application.ninja.selectedElements.length; 207 len = this.application.ninja.selectedElements.length;
diff --git a/js/tools/TranslateObject3DTool.js b/js/tools/TranslateObject3DTool.js
index 60633e74..7163f005 100755
--- a/js/tools/TranslateObject3DTool.js
+++ b/js/tools/TranslateObject3DTool.js
@@ -16,6 +16,8 @@ exports.TranslateObject3DTool = Object.create(Translate3DToolBase, {
16 initializeSnapping : { 16 initializeSnapping : {
17 value : function(event) 17 value : function(event)
18 { 18 {
19 console.log( "initializeSnapping" );
20
19 this._mouseDownHitRec = null; 21 this._mouseDownHitRec = null;
20 this._mouseUpHitRec = null; 22 this._mouseUpHitRec = null;
21 23
@@ -37,8 +39,6 @@ exports.TranslateObject3DTool = Object.create(Translate3DToolBase, {
37 39
38 if(this._handleMode === null) 40 if(this._handleMode === null)
39 { 41 {
40// this.doSelection(event);
41
42 snapManager.enableElementSnap ( true ); 42 snapManager.enableElementSnap ( true );
43 snapManager.enableGridSnap ( true ); 43 snapManager.enableGridSnap ( true );
44 } 44 }
@@ -107,16 +107,10 @@ exports.TranslateObject3DTool = Object.create(Translate3DToolBase, {
107 } 107 }
108 108
109 if(this._handleMode === 2) 109 if(this._handleMode === 2)
110 {
111 // TODO - not sure how to parameterize point in z-translate mode
112 this.clickedObject = this._target; 110 this.clickedObject = this._target;
113 this._snapParam = [0, 0, 0]; 111
114 } 112 // parameterize the snap point on the target
115 else 113 this._snapParam = this.parameterizeSnap( hitRec );
116 {
117 // parameterize the snap point on the target