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.js291
1 files changed, 121 insertions, 170 deletions
diff --git a/js/helper-classes/3D/snap-manager.js b/js/helper-classes/3D/snap-manager.js
index cd8cc102..f4bfc12b 100755
--- a/js/helper-classes/3D/snap-manager.js
+++ b/js/helper-classes/3D/snap-manager.js
@@ -948,7 +948,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
948 { 948 {
949 949
950 // see if we can snap to a contained geometry object 950 // see if we can snap to a contained geometry object
951 if (hitRec && this.getGLWorld(elt) && !this.isARectangle(elt)) 951 if (hitRec && this.getGLWorld(elt)) // && !this.isARectangle(elt))
952 { 952 {
953 var localPt = hitRec.calculateElementWorldPoint(); 953 var localPt = hitRec.calculateElementWorldPoint();
954 if (hitRec.getType() != hitRec.SNAP_TYPE_ELEMENT) 954 if (hitRec.getType() != hitRec.SNAP_TYPE_ELEMENT)
@@ -1011,7 +1011,8 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
1011 } 1011 }
1012 // hit test the current object 1012 // hit test the current object
1013 var hit; 1013 var hit;
1014 if (depth > 0) // don't snap to the root 1014 var snapToStage = ((depth === 0) && (elt === this.application.ninja.currentSelectedContainer) && (elt.nodeName === 'CANVAS'));
1015 if ((depth > 0) || snapToStage) // don't snap to the root unles we are working inside a canvas
1015 { 1016 {
1016 // if the element is in the 2D cache snapping is done there 1017 // if the element is in the 2D cache snapping is done there
1017 if (elt.elementModel && !elt.elementModel.isIn2DSnapCache) 1018 if (elt.elementModel && !elt.elementModel.isIn2DSnapCache)
@@ -1077,7 +1078,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
1077 var hitRec = this.snapToScreenBounds( elt, globalScrPt, bounds, bounds3D ); 1078 var hitRec = this.snapToScreenBounds( elt, globalScrPt, bounds, bounds3D );
1078 1079
1079 // see if we can snap to a contained geometry object 1080 // see if we can snap to a contained geometry object
1080 if (hitRec && this.getGLWorld(elt) && !this.isARectangle(elt)) 1081 if (hitRec && this.getGLWorld(elt)) // && !this.isARectangle(elt))
1081 { 1082 {
1082 var localPt = hitRec.calculateElementWorldPoint(); 1083 var localPt = hitRec.calculateElementWorldPoint();
1083 if (hitRec.getType() != hitRec.SNAP_TYPE_ELEMENT) 1084 if (hitRec.getType() != hitRec.SNAP_TYPE_ELEMENT)
@@ -1320,193 +1321,135 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
1320 } 1321 }
1321 }, 1322 },
1322 1323
1323 snapToContainedElement : 1324 doSnapToContainedElement:
1324 { 1325 {
1325 value: function( eyePt, dir, glObj, hitRec, targetScrPt ) 1326 value: function( eyePt, dir, glObj, hitRec, targetScrPt )
1326 { 1327 {
1327 var rtnVal = false; 1328 var rtnVal = false;
1328 var elt = hitRec.getElement();
1329 1329
1330 var elt = hitRec.getElt();
1330 var world = glObj.getWorld(); 1331 var world = glObj.getWorld();
1331 switch (glObj.geomType()) 1332
1333 var nearVrt = glObj.getNearVertex( eyePt, dir );
1334 if (nearVrt)
1332 { 1335 {
1333 case glObj.GEOM_TYPE_RECTANGLE: 1336 var viewPt = this.GLToView(nearVrt, world );
1334 break; 1337 var mat = viewUtils.getMatrixFromElement( elt );
1338 var worldPt = MathUtils.transformPoint( viewPt, mat );
1335 1339
1336 case glObj.GEOM_TYPE_CIRCLE: 1340 viewUtils.pushViewportObj( elt );
1341 var scrPt = viewUtils.viewToScreen( worldPt );
1342 var offset = viewUtils.getElementOffset( elt );
1343 MathUtils.makeDimension3( offset );
1344 var parentPt = vecUtils.vecAdd(3, scrPt, offset );
1345 var globalPt = viewUtils.localToGlobal( parentPt, elt.offsetParent );
1346
1347 var dist = vecUtils.vecDist(2, globalPt, targetScrPt );
1348 if (dist < this.ELEMENT_VERTEX_HIT_RAD)
1349 {
1350 //console.log( "hit a vertex" );
1351
1352 // check if the distance is less than
1353 // the distance on the current hit record
1354 //if (dist <= vecUtils.vecDist(2, targetScrPt, hitRec.getScreenPoint() ))
1337 { 1355 {
1338 var nearVrt = glObj.getNearVertex( eyePt, dir ); 1356 //console.log( "rejected - further than existing snap" );
1339 if (nearVrt) 1357
1340 { 1358 hitRec.setScreenPoint( globalPt );
1341 var viewPt = this.GLToView(nearVrt, world ); 1359 //var localMatInv = hitRec.getPlaneMatrix().inverse();
1342 var mat = viewUtils.getMatrixFromElement( elt ); 1360 var localMatInv = glmat4.inverse( hitRec.getPlaneMatrix(), []);
1343 var worldPt = MathUtils.transformPoint( viewPt, mat ); 1361 viewUtils.pushViewportObj( hitRec.getElement() );
1344 1362 var localPt = viewUtils.screenToView( scrPt[0], scrPt[1], scrPt[2] );
1345 viewUtils.pushViewportObj( elt ); 1363 viewUtils.popViewportObj();
1346 var scrPt = viewUtils.viewToScreen( worldPt ); 1364 localPt = MathUtils.transformPoint( localPt, localMatInv );
1347 var offset = viewUtils.getElementOffset( elt ); 1365 hitRec.setLocalPoint( localPt );
1348 MathUtils.makeDimension3( offset ); 1366 hitRec.setType( hitRec.SNAP_TYPE_CONTAINED_ELEMENT );
1349 var parentPt = vecUtils.vecAdd(3, scrPt, offset );
1350 var globalPt = viewUtils.localToGlobal( parentPt, elt.offsetParent );
1351
1352 var dist = vecUtils.vecDist(2, globalPt, targetScrPt );
1353 if (dist < this.ELEMENT_VERTEX_HIT_RAD)
1354 {
1355 // check if the distance is less than
1356 // the distance on the current hit record
1357 if (dist <= vecUtils.vecDist(2, targetScrPt, hitRec.getScreenPoint() ))
1358 {
1359 hitRec.setScreenPoint( globalPt );
1360 //var localMatInv = hitRec.getPlaneMatrix().inverse();
1361 var localMatInv = glmat4.inverse( hitRec.getPlaneMatrix(), []);
1362 viewUtils.pushViewportObj( hitRec.getElement() );
1363 var localPt = viewUtils.screenToView( scrPt[0], scrPt[1], scrPt[2] );
1364 viewUtils.popViewportObj();
1365 localPt = MathUtils.transformPoint( localPt, localMatInv );
1366 hitRec.setLocalPoint( localPt );
1367 hitRec.setType( hitRec.SNAP_TYPE_CONTAINED_ELEMENT );
1368
1369 rtnVal = true;
1370 }
1371 }
1372 } // if (nearVrt)
1373 1367
1374 if (!rtnVal) 1368 rtnVal = true;
1375 { 1369 }
1376 var nearPt = glObj.getNearPoint( eyePt, dir ); 1370 }
1377 if (nearPt) 1371 }
1378 {
1379 var viewPt = this.GLToView(nearPt, world );
1380 var mat = viewUtils.getMatrixFromElement( elt );
1381 var worldPt = MathUtils.transformPoint( viewPt, mat );
1382
1383 viewUtils.pushViewportObj( elt );
1384 var scrPt = viewUtils.viewToScreen( worldPt );
1385 var offset = viewUtils.getElementOffset( elt );
1386 MathUtils.makeDimension3( offset );
1387 var parentPt = vecUtils.vecAdd(3, scrPt, offset );
1388 var globalPt = viewUtils.localToGlobal( parentPt, elt.offsetParent );
1389
1390 var dist = vecUtils.vecDist(2, globalPt, targetScrPt );
1391 if (dist < this.ELEMENT_EDGE_HIT_RAD)
1392 {
1393 // check if the distance is less than
1394 // the distance on the current hit record
1395 //var dist2 = vecUtils.vecDist(2, targetScrPt, hitRec.getScreenPoint() );
1396 //if (dist <= dist2+1 )
1397 {
1398 hitRec.setScreenPoint( globalPt );
1399 //var localMatInv = hitRec.getPlaneMatrix().inverse();
1400 var localMatInv = glmat4.inverse( hitRec.getPlaneMatrix(), []);
1401 viewUtils.pushViewportObj( hitRec.getElement() );
1402 var localPt = viewUtils.screenToView( scrPt[0], scrPt[1], scrPt[2] );
1403 viewUtils.popViewportObj();
1404 localPt = MathUtils.transformPoint( localPt, localMatInv );
1405 hitRec.setLocalPoint( localPt );
1406 hitRec.setType( hitRec.SNAP_TYPE_CONTAINED_ELEMENT );
1407
1408 rtnVal = true;
1409 }
1410 }
1411 }
1412 } // if (!rtnVal)
1413 1372
1414 if (!rtnVal && glObj.containsPoint( eyePt, dir )) 1373 if (!rtnVal)
1374 {
1375 var nearPt = glObj.getNearPoint( eyePt, dir );
1376 if (nearPt)
1377 {
1378 var viewPt = this.GLToView(nearPt, world );
1379 var mat = viewUtils.getMatrixFromElement( elt );
1380 var worldPt = MathUtils.transformPoint( viewPt, mat );
1381
1382 viewUtils.pushViewportObj( elt );
1383 var scrPt = viewUtils.viewToScreen( worldPt );
1384 var offset = viewUtils.getElementOffset( elt );
1385 MathUtils.makeDimension3( offset );
1386 var parentPt = vecUtils.vecAdd(3, scrPt, offset );
1387 var globalPt = viewUtils.localToGlobal( parentPt, elt.offsetParent );
1388
1389 var dist = vecUtils.vecDist(2, globalPt, targetScrPt );
1390 if (dist < this.ELEMENT_EDGE_HIT_RAD)
1391 {
1392 //console.log( "hit an edge" );
1393
1394 // check if the distance is less than
1395 // the distance on the current hit record
1396 //var dist2 = vecUtils.vecDist(2, targetScrPt, hitRec.getScreenPoint() );
1397 //if (dist <= dist2+1 )
1415