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.js61
-rwxr-xr-xjs/helper-classes/3D/snap-manager.js291
2 files changed, 172 insertions, 180 deletions
diff --git a/js/helper-classes/3D/draw-utils.js b/js/helper-classes/3D/draw-utils.js
index 7bd77c3a..88830964 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);
@@ -643,6 +651,21 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
643 this._lineColor = saveColor; 651 this._lineColor = saveColor;
644 this._drawingContext.lineWidth = saveLineWidth; 652 this._drawingContext.lineWidth = saveLineWidth;
645 653
654 if(this.application.ninja.currentDocument.documentRoot.id !== "UserContent") {
655 // draw an outline around the body
656 var stagePt = MathUtils.getPointOnPlane([0,0,1,0]);
657 var stageMat = this.getPlaneToWorldMatrix([0,0,1], stagePt);
658 // glmat4.multiply( tMat, stageMat, stageMat);
659 pt0 = [0, 0, 0];
660 pt1 = [0, height, 0];
661 delta = [width, 0, 0];
662 this.drawGridLines(pt0, pt1, delta, stageMat, 2);
663 pt0 = [0, 0, 0];
664 pt1 = [width, 0, 0];
665 delta = [0, height, 0];
666 this.drawGridLines(pt0, pt1, delta, stageMat, 2);
667 }
668
646 // draw the lines 669 // draw the lines
647 this.redrawGridLines(); 670 this.redrawGridLines();
648 671
@@ -662,6 +685,7 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
662 var offset = this.viewUtils.getElementOffset(this._sourceSpaceElt); 685 var offset = this.viewUtils.getElementOffset(this._sourceSpaceElt);
663 offset[2] = 0; 686 offset[2] = 0;
664 this.viewUtils.setViewportObj(this._sourceSpaceElt); 687 this.viewUtils.setViewportObj(this._sourceSpaceElt);
688 var sourceSpaceMat = this.viewUtils.getLocalToGlobalMatrix( this._sourceSpaceElt );
665 for (var i = 0; i < nLines; i++) { 689 for (var i = 0; i < nLines; i++) {
666 // transform the points from working plane space to world space 690 // transform the points from working plane space to world space
667 //var t0 = mat.multiply(p0), 691 //var t0 = mat.multiply(p0),
@@ -671,8 +695,10 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
671 695
672 // transform from world space to global screen space 696 // transform from world space to global screen space
673 if (this._sourceSpaceElt) { 697 if (this._sourceSpaceElt) {
674 t0 = this.viewUtils.localToGlobal(t0, this._sourceSpaceElt); 698// t0 = this.viewUtils.localToGlobal(t0, this._sourceSpaceElt);
675 t1 = this.viewUtils.localToGlobal(t1, this._sourceSpaceElt); 699// t1 = this.viewUtils.localToGlobal(t1, this._sourceSpaceElt);
700 t0 = this.viewUtils.localToGlobal2(t0, sourceSpaceMat);
701 t1 = this.viewUtils.localToGlobal2(t1, sourceSpaceMat);
676 } 702 }
677 703
678 // create a line from the endpoints 704 // create a line from the endpoints
@@ -741,12 +767,27 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
741 this._drawingContext.lineWidth = 0.25; 767 this._drawingContext.lineWidth = 0.25;
742 768
743 // draw the lines 769 // draw the lines
744 var nLines = this._gridLineArray.length; 770 var line,
771 nLines = this._gridLineArray.length;
772 if(this.application.ninja.currentDocument.documentRoot.id !== "UserContent") {
773 nLines = this._gridLineArray.length-4;
774 }
775
745 for (var i = 0; i < nLines; i++) { 776 for (var i = 0; i < nLines; i++) {
746 var line = this._gridLineArray[i]; 777 line = this._gridLineArray[i];
747 this.drawIntersectedLine(line, this._drawingContext); 778 this.drawIntersectedLine(line, this._drawingContext);
748 } 779 }
749 780
781 if(this.application.ninja.currentDocument.documentRoot.id !== "UserContent") {
782 this._lineColor = "red";
783 i = nLines;
784 nLines += 4;
785 for (; i < nLines; i++) {
786 line = this._gridLineArray[i];
787 this.drawIntersectedLine(line, this._drawingContext);
788 }
789 }
790
750 this.popState(); 791 this.popState();
751 } 792 }
752 }, 793 },
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