aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/3D
diff options
context:
space:
mode:
Diffstat (limited to 'js/helper-classes/3D')
-rwxr-xr-xjs/helper-classes/3D/draw-utils.js27
-rwxr-xr-xjs/helper-classes/3D/snap-manager.js279
2 files changed, 130 insertions, 176 deletions
diff --git a/js/helper-classes/3D/draw-utils.js b/js/helper-classes/3D/draw-utils.js
index 7bd77c3a..81a740e0 100755
--- a/js/helper-classes/3D/draw-utils.js
+++ b/js/helper-classes/3D/draw-utils.js
@@ -583,17 +583,25 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
583 // get a point that lies on the plane 583 // get a point that lies on the plane
584 var ptOnPlane = MathUtils.getPointOnPlane(this._workingPlane); 584 var ptOnPlane = MathUtils.getPointOnPlane(this._workingPlane);
585 585
586 // define the grid parameters
587 var width,
588 height,
589 nLines = 10;
590
591// if(this.application.ninja.documentController.webTemplate) {
592 if(this.application.ninja.currentDocument.documentRoot.id !== "UserContent") {
593 width = this.application.ninja.currentDocument.documentRoot.scrollWidth;
594 height = this.application.ninja.currentDocument.documentRoot.scrollHeight;
595 } else {
596 width = this.snapManager.getStageWidth();
597 height = this.snapManager.getStageHeight();
598 }
586 // get a matrix from working plane space to the world 599 // get a matrix from working plane space to the world
587 var mat = this.getPlaneToWorldMatrix(zAxis, ptOnPlane); 600 var mat = this.getPlaneToWorldMatrix(zAxis, ptOnPlane);
588 var tMat = Matrix.Translation( [0.5*this.snapManager.getStageWidth(), 0.5*this.snapManager.getStageHeight(),0] ); 601 var tMat = Matrix.Translation( [0.5*width, 0.5*height, 0] );
589 //mat = tMat.multiply(mat); 602 //mat = tMat.multiply(mat);
590 glmat4.multiply( tMat, mat, mat); 603 glmat4.multiply( tMat, mat, mat);
591 604
592 // define the grid parameters
593 var width = this.snapManager.getStageWidth(),
594 height = this.snapManager.getStageHeight();
595 var nLines = 10;
596
597 // the positioning of the grid may depend on the view direction. 605 // the positioning of the grid may depend on the view direction.
598 var stage = this.snapManager.getStage(); 606 var stage = this.snapManager.getStage();
599 var viewMat = this.viewUtils.getMatrixFromElement(stage); 607 var viewMat = this.viewUtils.getMatrixFromElement(stage);
@@ -662,6 +670,7 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
662 var offset = this.viewUtils.getElementOffset(this._sourceSpaceElt); 670 var offset = this.viewUtils.getElementOffset(this._sourceSpaceElt);
663 offset[2] = 0; 671 offset[2] = 0;
664 this.viewUtils.setViewportObj(this._sourceSpaceElt); 672 this.viewUtils.setViewportObj(this._sourceSpaceElt);
673 var sourceSpaceMat = this.viewUtils.getLocalToGlobalMatrix( this._sourceSpaceElt );
665 for (var i = 0; i < nLines; i++) { 674 for (var i = 0; i < nLines; i++) {
666 // transform the points from working plane space to world space 675 // transform the points from working plane space to world space
667 //var t0 = mat.multiply(p0), 676 //var t0 = mat.multiply(p0),
@@ -671,8 +680,10 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
671 680
672 // transform from world space to global screen space 681 // transform from world space to global screen space
673 if (this._sourceSpaceElt) { 682 if (this._sourceSpaceElt) {
674 t0 = this.viewUtils.localToGlobal(t0, this._sourceSpaceElt); 683// t0 = this.viewUtils.localToGlobal(t0, this._sourceSpaceElt);
675 t1 = this.viewUtils.localToGlobal(t1, this._sourceSpaceElt); 684// t1 = this.viewUtils.localToGlobal(t1, this._sourceSpaceElt);
685 t0 = this.viewUtils.localToGlobal2(t0, sourceSpaceMat);
686 t1 = this.viewUtils.localToGlobal2(t1, sourceSpaceMat);
676 } 687 }
677 688
678 // create a line from the endpoints 689 // create a line from the endpoints
diff --git a/js/helper-classes/3D/snap-manager.js b/js/helper-classes/3D/snap-manager.js
index cd8cc102..7fc492a5 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 );