diff options
Diffstat (limited to 'js/helper-classes/3D/snap-manager.js')
-rwxr-xr-x | js/helper-classes/3D/snap-manager.js | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/js/helper-classes/3D/snap-manager.js b/js/helper-classes/3D/snap-manager.js index 8eafa7e9..5735a145 100755 --- a/js/helper-classes/3D/snap-manager.js +++ b/js/helper-classes/3D/snap-manager.js | |||
@@ -124,6 +124,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { | |||
124 | initialize: { | 124 | initialize: { |
125 | value: function() { | 125 | value: function() { |
126 | this.eventManager.addEventListener("elementsRemoved", this, false); | 126 | this.eventManager.addEventListener("elementsRemoved", this, false); |
127 | this.eventManager.addEventListener("elementReplaced", this, false); | ||
127 | } | 128 | } |
128 | }, | 129 | }, |
129 | 130 | ||
@@ -170,15 +171,19 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { | |||
170 | if(Array.isArray(elements)) { | 171 | if(Array.isArray(elements)) { |
171 | elements = Array.prototype.slice.call(elements, 0); | 172 | elements = Array.prototype.slice.call(elements, 0); |
172 | elements.forEach(function(element) { | 173 | elements.forEach(function(element) { |
173 | element = element._element || element; | ||
174 | self.removeElementFrom2DCache(element); | 174 | self.removeElementFrom2DCache(element); |
175 | }); | 175 | }); |
176 | } else { | 176 | } else { |
177 | this.removeElementFrom2DCache(elements._element || elements); | 177 | this.removeElementFrom2DCache(elements); |
178 | } | 178 | } |
179 | } | 179 | } |
180 | }, | 180 | }, |
181 | 181 | ||
182 | handleElementReplaced: { | ||
183 | value: function(event) { | ||
184 | this._isCacheInvalid = true; | ||
185 | } | ||
186 | }, | ||
182 | 187 | ||
183 | setCurrentStage: { | 188 | setCurrentStage: { |
184 | value: function(stage) { | 189 | value: function(stage) { |
@@ -224,7 +229,9 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { | |||
224 | parentPt = [quadPt[0], quadPt[1], 0.0]; | 229 | parentPt = [quadPt[0], quadPt[1], 0.0]; |
225 | else | 230 | else |
226 | parentPt = [xScreen, yScreen, 0.0]; | 231 | parentPt = [xScreen, yScreen, 0.0]; |
227 | var vec = viewUtils.parentToChildVec(parentPt, stage); | 232 | |
233 | var eyePt = []; | ||
234 | var vec = viewUtils.parentToChildVec(parentPt, stage, eyePt); | ||
228 | if (vec) | 235 | if (vec) |
229 | { | 236 | { |
230 | // activate the drag working plane | 237 | // activate the drag working plane |
@@ -236,7 +243,6 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { | |||
236 | var wp = currentWorkingPlane.slice(0); | 243 | var wp = currentWorkingPlane.slice(0); |
237 | var mat = viewUtils.getMatrixFromElement(stage); | 244 | var mat = viewUtils.getMatrixFromElement(stage); |
238 | wp = MathUtils.transformPlane(wp, mat); | 245 | wp = MathUtils.transformPlane(wp, mat); |
239 | var eyePt = viewUtils.getEyePoint(); | ||
240 | var projPt = MathUtils.vecIntersectPlane(eyePt, vec, wp); | 246 | var projPt = MathUtils.vecIntersectPlane(eyePt, vec, wp); |
241 | if (projPt) | 247 | if (projPt) |
242 | { | 248 | { |
@@ -300,7 +306,8 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { | |||
300 | this.deactivateDragPlane(); | 306 | this.deactivateDragPlane(); |
301 | 307 | ||
302 | this.setLastHit( rtnHit ); | 308 | this.setLastHit( rtnHit ); |
303 | //rtnHit.test(); // DEBUG CODE. REMOVE THIS | 309 | |
310 | rtnHit.test(); // DEBUG CODE. REMOVE THIS | ||
304 | return rtnHit; | 311 | return rtnHit; |
305 | } | 312 | } |
306 | }, | 313 | }, |
@@ -705,8 +712,8 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { | |||
705 | var wp = currentWorkingPlane.slice(0); | 712 | var wp = currentWorkingPlane.slice(0); |
706 | var mat = viewUtils.getMatrixFromElement(stage); | 713 | var mat = viewUtils.getMatrixFromElement(stage); |
707 | wp = MathUtils.transformPlane(wp, mat); | 714 | wp = MathUtils.transformPlane(wp, mat); |
708 | var eyePt = viewUtils.getEyePoint(); | 715 | var eyePt = []; |
709 | var vec = viewUtils.parentToChildVec(gPt, stage); | 716 | var vec = viewUtils.parentToChildVec(gPt, stage, eyePt); |
710 | var projPt = MathUtils.vecIntersectPlane(eyePt, vec, wp); | 717 | var projPt = MathUtils.vecIntersectPlane(eyePt, vec, wp); |
711 | var wpMat = drawUtils.getPlaneToWorldMatrix(currentWorkingPlane, MathUtils.getPointOnPlane(currentWorkingPlane)); | 718 | var wpMat = drawUtils.getPlaneToWorldMatrix(currentWorkingPlane, MathUtils.getPointOnPlane(currentWorkingPlane)); |
712 | projPt[3] = 1.0; | 719 | projPt[3] = 1.0; |
@@ -1063,8 +1070,9 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { | |||
1063 | // Snapping is done in screen space, so convert the bounds from | 1070 | // Snapping is done in screen space, so convert the bounds from |
1064 | // local element space to global screen space | 1071 | // local element space to global screen space |
1065 | var bounds3D = new Array(); | 1072 | var bounds3D = new Array(); |
1073 | var eltMat = viewUtils.getLocalToGlobalMatrix( elt ); | ||
1066 | for (var i=0; i<4; i++) | 1074 | for (var i=0; i<4; i++) |
1067 | bounds3D[i] = viewUtils.localToGlobal( bounds[i], elt ); | 1075 | bounds3D[i] = viewUtils.localToGlobal2(bounds[i], eltMat); |
1068 | 1076 | ||
1069 | var hitRec = this.snapToScreenBounds( elt, globalScrPt, bounds, bounds3D ); | 1077 | var hitRec = this.snapToScreenBounds( elt, globalScrPt, bounds, bounds3D ); |
1070 | 1078 | ||
@@ -1348,7 +1356,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { | |||
1348 | var offset = viewUtils.getElementOffset( elt ); | 1356 | var offset = viewUtils.getElementOffset( elt ); |
1349 | MathUtils.makeDimension3( offset ); | 1357 | MathUtils.makeDimension3( offset ); |
1350 | var parentPt = vecUtils.vecAdd(3, scrPt, offset ); | 1358 | var parentPt = vecUtils.vecAdd(3, scrPt, offset ); |
1351 | var globalPt = viewUtils.localToGlobal( parentPt, elt.parentElement ); | 1359 | var globalPt = viewUtils.localToGlobal( parentPt, elt.offsetParent ); |
1352 | 1360 | ||
1353 | var dist = vecUtils.vecDist(2, globalPt, targetScrPt ); | 1361 | var dist = vecUtils.vecDist(2, globalPt, targetScrPt ); |
1354 | if (dist < this.ELEMENT_VERTEX_HIT_RAD) | 1362 | if (dist < this.ELEMENT_VERTEX_HIT_RAD) |
@@ -1386,7 +1394,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { | |||
1386 | var offset = viewUtils.getElementOffset( elt ); | 1394 | var offset = viewUtils.getElementOffset( elt ); |
1387 | MathUtils.makeDimension3( offset ); | 1395 | MathUtils.makeDimension3( offset ); |
1388 | var parentPt = vecUtils.vecAdd(3, scrPt, offset ); | 1396 | var parentPt = vecUtils.vecAdd(3, scrPt, offset ); |
1389 | var globalPt = viewUtils.localToGlobal( parentPt, elt.parentElement ); | 1397 | var globalPt = viewUtils.localToGlobal( parentPt, elt.offsetParent ); |
1390 | 1398 | ||
1391 | var dist = vecUtils.vecDist(2, globalPt, targetScrPt ); | 1399 | var dist = vecUtils.vecDist(2, globalPt, targetScrPt ); |
1392 | if (dist < this.ELEMENT_EDGE_HIT_RAD) | 1400 | if (dist < this.ELEMENT_EDGE_HIT_RAD) |
@@ -1439,7 +1447,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { | |||
1439 | var offset = viewUtils.getElementOffset( elt ); | 1447 | var offset = viewUtils.getElementOffset( elt ); |
1440 | MathUtils.makeDimension3( offset ); | 1448 | MathUtils.makeDimension3( offset ); |
1441 | var parentPt = vecUtils.vecAdd(3, scrPt, offset ); | 1449 | var parentPt = vecUtils.vecAdd(3, scrPt, offset ); |
1442 | var globalPt = viewUtils.localToGlobal( parentPt, elt.parentElement ); | 1450 | var globalPt = viewUtils.localToGlobal( parentPt, elt.offsetParent ); |
1443 | 1451 | ||
1444 | var dist = vecUtils.vecDist(2, globalPt, targetScrPt ); | 1452 | var dist = vecUtils.vecDist(2, globalPt, targetScrPt ); |
1445 | if (dist < this.ELEMENT_VERTEX_HIT_RAD) | 1453 | if (dist < this.ELEMENT_VERTEX_HIT_RAD) |
@@ -1477,7 +1485,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { | |||
1477 | var offset = viewUtils.getElementOffset( elt ); | 1485 | var offset = viewUtils.getElementOffset( elt ); |
1478 | MathUtils.makeDimension3( offset ); | 1486 | MathUtils.makeDimension3( offset ); |
1479 | var parentPt = vecUtils.vecAdd(3, scrPt, offset ); | 1487 | var parentPt = vecUtils.vecAdd(3, scrPt, offset ); |
1480 | var globalPt = viewUtils.localToGlobal( parentPt, elt.parentElement ); | 1488 | var globalPt = viewUtils.localToGlobal( parentPt, elt.offsetParent ); |
1481 | 1489 | ||
1482 | var dist = vecUtils.vecDist(2, globalPt, targetScrPt ); | 1490 | var dist = vecUtils.vecDist(2, globalPt, targetScrPt ); |
1483 | if (dist < this.ELEMENT_EDGE_HIT_RAD) | 1491 | if (dist < this.ELEMENT_EDGE_HIT_RAD) |