aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/3D/snap-manager.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/helper-classes/3D/snap-manager.js')
-rwxr-xr-xjs/helper-classes/3D/snap-manager.js29
1 files changed, 18 insertions, 11 deletions
diff --git a/js/helper-classes/3D/snap-manager.js b/js/helper-classes/3D/snap-manager.js
index 9f6b9ed1..02e81a62 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 {
@@ -704,8 +710,8 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
704 var wp = currentWorkingPlane.slice(0); 710 var wp = currentWorkingPlane.slice(0);
705 var mat = viewUtils.getMatrixFromElement(stage); 711 var mat = viewUtils.getMatrixFromElement(stage);
706 wp = MathUtils.transformPlane(wp, mat); 712 wp = MathUtils.transformPlane(wp, mat);
707 var eyePt = viewUtils.getEyePoint(); 713 var eyePt = [];
708 var vec = viewUtils.parentToChildVec(gPt, stage); 714 var vec = viewUtils.parentToChildVec(gPt, stage, eyePt);
709 var projPt = MathUtils.vecIntersectPlane(eyePt, vec, wp); 715 var projPt = MathUtils.vecIntersectPlane(eyePt, vec, wp);
710 var wpMat = drawUtils.getPlaneToWorldMatrix(currentWorkingPlane, MathUtils.getPointOnPlane(currentWorkingPlane)); 716 var wpMat = drawUtils.getPlaneToWorldMatrix(currentWorkingPlane, MathUtils.getPointOnPlane(currentWorkingPlane));
711 projPt[3] = 1.0; 717 projPt[3] = 1.0;
@@ -1062,8 +1068,9 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
1062 // Snapping is done in screen space, so convert the bounds from 1068 // Snapping is done in screen space, so convert the bounds from
1063 // local element space to global screen space 1069 // local element space to global screen space
1064 var bounds3D = new Array(); 1070 var bounds3D = new Array();
1071 var eltMat = viewUtils.getLocalToGlobalMatrix( elt );
1065 for (var i=0; i<4; i++) 1072 for (var i=0; i<4; i++)
1066 bounds3D[i] = viewUtils.localToGlobal( bounds[i], elt ); 1073 bounds3D[i] = viewUtils.localToGlobal2(bounds[i], eltMat);
1067 1074
1068 var hitRec = this.snapToScreenBounds( elt, globalScrPt, bounds, bounds3D ); 1075 var hitRec = this.snapToScreenBounds( elt, globalScrPt, bounds, bounds3D );
1069 1076
@@ -1347,7 +1354,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
1347 var offset = viewUtils.getElementOffset( elt ); 1354 var offset = viewUtils.getElementOffset( elt );
1348 MathUtils.makeDimension3( offset ); 1355 MathUtils.makeDimension3( offset );
1349 var parentPt = vecUtils.vecAdd(3, scrPt, offset ); 1356 var parentPt = vecUtils.vecAdd(3, scrPt, offset );
1350 var globalPt = viewUtils.localToGlobal( parentPt, elt.parentElement ); 1357 var globalPt = viewUtils.localToGlobal( parentPt, elt.offsetParent );
1351 1358
1352 var dist = vecUtils.vecDist(2, globalPt, targetScrPt ); 1359 var dist = vecUtils.vecDist(2, globalPt, targetScrPt );
1353 if (dist < this.ELEMENT_VERTEX_HIT_RAD) 1360 if (dist < this.ELEMENT_VERTEX_HIT_RAD)
@@ -1385,7 +1392,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
1385 var offset = viewUtils.getElementOffset( elt ); 1392 var offset = viewUtils.getElementOffset( elt );
1386 MathUtils.makeDimension3( offset ); 1393 MathUtils.makeDimension3( offset );
1387 var parentPt = vecUtils.vecAdd(3, scrPt, offset ); 1394 var parentPt = vecUtils.vecAdd(3, scrPt, offset );
1388 var globalPt = viewUtils.localToGlobal( parentPt, elt.parentElement ); 1395 var globalPt = viewUtils.localToGlobal( parentPt, elt.offsetParent );
1389 1396
1390 var dist = vecUtils.vecDist(2, globalPt, targetScrPt ); 1397 var dist = vecUtils.vecDist(2, globalPt, targetScrPt );
1391 if (dist < this.ELEMENT_EDGE_HIT_RAD) 1398 if (dist < this.ELEMENT_EDGE_HIT_RAD)
@@ -1438,7 +1445,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
1438 var offset = viewUtils.getElementOffset( elt ); 1445 var offset = viewUtils.getElementOffset( elt );
1439 MathUtils.makeDimension3( offset ); 1446 MathUtils.makeDimension3( offset );
1440 var parentPt = vecUtils.vecAdd(3, scrPt, offset ); 1447 var parentPt = vecUtils.vecAdd(3, scrPt, offset );
1441 var globalPt = viewUtils.localToGlobal( parentPt, elt.parentElement ); 1448 var globalPt = viewUtils.localToGlobal( parentPt, elt.offsetParent );
1442 1449
1443 var dist = vecUtils.vecDist(2, globalPt, targetScrPt ); 1450 var dist = vecUtils.vecDist(2, globalPt, targetScrPt );
1444 if (dist < this.ELEMENT_VERTEX_HIT_RAD) 1451 if (dist < this.ELEMENT_VERTEX_HIT_RAD)
@@ -1476,7 +1483,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
1476 var offset = viewUtils.getElementOffset( elt ); 1483 var offset = viewUtils.getElementOffset( elt );
1477 MathUtils.makeDimension3( offset ); 1484 MathUtils.makeDimension3( offset );
1478 var parentPt = vecUtils.vecAdd(3, scrPt, offset ); 1485 var parentPt = vecUtils.vecAdd(3, scrPt, offset );
1479 var globalPt = viewUtils.localToGlobal( parentPt, elt.parentElement ); 1486 var globalPt = viewUtils.localToGlobal( parentPt, elt.offsetParent );
1480 1487
1481 var dist = vecUtils.vecDist(2, globalPt, targetScrPt ); 1488 var dist = vecUtils.vecDist(2, globalPt, targetScrPt );
1482 if (dist < this.ELEMENT_EDGE_HIT_RAD) 1489 if (dist < this.ELEMENT_EDGE_HIT_RAD)