From babfa5f1ca4f702920d81d7e12a90b12ffbf42d8 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Thu, 10 May 2012 16:53:18 -0700 Subject: Fixed an inaccuracy snapping to the stage. --- js/helper-classes/3D/snap-manager.js | 139 +++++++++++++++++++---------------- js/helper-classes/3D/view-utils.js | 5 ++ 2 files changed, 81 insertions(+), 63 deletions(-) (limited to 'js/helper-classes') diff --git a/js/helper-classes/3D/snap-manager.js b/js/helper-classes/3D/snap-manager.js index 6766ac7f..27a95941 100755 --- a/js/helper-classes/3D/snap-manager.js +++ b/js/helper-classes/3D/snap-manager.js @@ -230,64 +230,19 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { else parentPt = [xScreen, yScreen, 0.0]; - var eyePt = []; - var vec = viewUtils.parentToChildVec(parentPt, stage, eyePt); - if (vec) - { - // activate the drag working plane - if (!snap3D && this.hasDragPlane()) - this.activateDragPlane(); - - // project to the working plane - var currentWorkingPlane = workingPlane.slice(0); - var wp = currentWorkingPlane.slice(0); - var mat = viewUtils.getMatrixFromElement(stage); - wp = MathUtils.transformPlane(wp, mat); - var projPt = MathUtils.vecIntersectPlane(eyePt, vec, wp); - if (projPt) - { - // the local point gets stored in the coordinate space of the plane - var wpMat = drawUtils.getPlaneToWorldMatrix(currentWorkingPlane, MathUtils.getPointOnPlane(currentWorkingPlane)); - projPt[3] = 1.0; - //var planeToViewMat = mat.multiply(wpMat); - var planeToViewMat = glmat4.multiply(mat, wpMat, []); - //var viewToPlaneMat = planeToViewMat.inverse(); - var viewToPlaneMat = glmat4.inverse( planeToViewMat, [] ); - var planePt = projPt.slice(0); - planePt[3] = 1.0; - //planePt = viewToPlaneMat.multiply(planePt); - planePt = glmat4.multiplyVec3( viewToPlaneMat, planePt ); - - // get the screen position of the projected point - viewUtils.setViewportObj(stage); - var offset = viewUtils.getElementOffset(stage); - offset[2] = 0; - var scrPt = viewUtils.viewToScreen(projPt); - //scrPt = scrPt.add(offset); - scrPt = vecUtils.vecAdd(3, scrPt, offset); - - // create the hit record - var hitRec = Object.create(HitRecord);//new HitRecord(); - hitRec.setLocalPoint(planePt); - hitRec.setPlaneMatrix( wpMat ); - hitRec.setScreenPoint(scrPt); - hitRec.setPlane(currentWorkingPlane); - hitRec.setType( hitRec.SNAP_TYPE_STAGE ); - hitRec.setElt( stage ); - if (quadPt) hitRec.setUseQuadPoint( true ); - - // try snapping to the 3D grid, or to the stage boundaries if the grid is not displayed - if (this.gridSnapEnabled()) - this.snapToGrid( hitRec ); - - // save the hit record - hitRecArray.push( hitRec ); - - // restore the original working plane - if (!snap3D && this.hasDragPlane()) - this.deactivateDragPlane(); - } - } + var hitRec = this.snapToStage( parentPt, quadPt ); + + // try snapping to the 3D grid, or to the stage boundaries if the grid is not displayed + if (this.gridSnapEnabled()) + this.snapToGrid( hitRec ); + + // save the hit record + hitRecArray.push( hitRec ); + + // restore the original working plane + if (!snap3D && this.hasDragPlane()) + this.deactivateDragPlane(); + } //if (hitRecArray.length == 0) var rtnHit; @@ -312,6 +267,62 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { } }, + snapToStage: + { + value: function( scrPt, quadPt ) + { + var stage = this.getStage(); + var l2g = viewUtils.getLocalToGlobalMatrix( stage ); + var g2l = glmat4.inverse( l2g, [] ); + + var pt0 = scrPt.slice(), pt1 = scrPt.slice(); + pt0[2] = 0.0; pt1[2] = 10; + + var localPt0 = MathUtils.transformAndDivideHomogeneousPoint( pt0, g2l ), + localPt1 = MathUtils.transformAndDivideHomogeneousPoint( pt1, g2l ); + + var stageWorldPt0 = viewUtils.localToStageWorld( localPt0, stage ), + stageWorldPt1 = viewUtils.localToStageWorld( localPt1, stage ); + var vec = vecUtils.vecSubtract( 3, stageWorldPt1, stageWorldPt0 ); + + var ptOnWorkingPlane = MathUtils.vecIntersectPlane(stageWorldPt0, vec, workingPlane); + + var wpMat = drawUtils.getPlaneToWorldMatrix(workingPlane, MathUtils.getPointOnPlane(workingPlane)), + wpMatInv = glmat4.inverse( wpMat, [] ); + var localPt = MathUtils.transformPoint( ptOnWorkingPlane, wpMatInv ); + + // create the hit record + var hitRec = Object.create(HitRecord); + hitRec.setLocalPoint( localPt ); + hitRec.setPlaneMatrix( wpMat ); + hitRec.setScreenPoint(scrPt); + hitRec.setPlane(workingPlane); + hitRec.setType( hitRec.SNAP_TYPE_STAGE ); + hitRec.setElt( stage ); + if (quadPt) hitRec.setUseQuadPoint( true ); + + // DEBUG CODE + // check that the point is on the working plane + var tmpStageWorldPt = hitRec.calculateStageWorldPoint(); + var err = vecUtils.vecDot(3, tmpStageWorldPt, workingPlane) + workingPlane[3]; + if (MathUtils.fpSign(err) !== 0) + console.log( "snapToStage (function) not on working plane: " + err ); + ////////////////////////////////////////////////////////////////////// + + var calculatedScreenPt = hitRec.calculateScreenPoint(); + hitRec.setScreenPoint(calculatedScreenPt); + + // DEBUG CODE + // check that the point is on the working plane + var err2 = vecUtils.vecDist(2, calculatedScreenPt, scrPt ); + if (MathUtils.fpSign(err2) !== 0) + console.log( "snapToStage (function) error in screen point: " + err2 ); + ////////////////////////////////////////////////////////////////////// + + return hitRec; + } + }, + snapToGrid : { value: function( hitRec ) { @@ -481,7 +492,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { this._elementCache = null; } - //console.log( "clear 2D cache" ); + console.log( "clear 2D cache" ); } }, @@ -494,7 +505,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { this.hLoadElementCache( stage, plane, 0 ); this._isCacheInvalid = false; - //console.log( "2D cache loaded with " + this._elementCache.length + " elements" ); + console.log( "2D cache loaded with " + this._elementCache.length + " elements" ); } }, @@ -1779,7 +1790,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { if (hSnap && vSnap) { - //console.log( "\tmerge 1" ); + console.log( "\tmerge 1" ); // intersect the 2 lines on the plane var hPt = hSnap.getLocalPoint(), @@ -1828,7 +1839,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { if (hSnap && vSnap) { - //console.log( "\tmerge 2" ); + console.log( "\tmerge 2" ); // intersect the 2 lines on the plane var hPt = hSnap.getLocalPoint(), @@ -1881,7 +1892,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { if (hSnap && vSnap) { - //console.log( "merge edge" ); + console.log( "merge edge" ); var hPt = hSnap.getLocalPoint(), vPt = vSnap.getLocalPoint(); @@ -1945,6 +1956,8 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { //this._globalToStageWorldMat = this._stageWorldToGlobalMat.inverse(); this._globalToStageWorldMat = glmat4.inverse( this._stageWorldToGlobalMat, [] ); + console.log( "setupDragPlane: " + this._dragPlane ); + // load the 2D elements this.load2DCache( this._dragPlane ); } diff --git a/js/helper-classes/3D/view-utils.js b/js/helper-classes/3D/view-utils.js index 919f7c50..48d4cacf 100755 --- a/js/helper-classes/3D/view-utils.js +++ b/js/helper-classes/3D/view-utils.js @@ -288,6 +288,11 @@ exports.ViewUtils = Montage.create(Component, { value: function( localPt, elt ) { this.pushViewportObj( elt ); var viewPt = this.screenToView( localPt[0], localPt[1], localPt[2] ); + if ((elt == null) || (elt === this._stageElement)) + { + this.popViewportObj(); + return viewPt; + } var mat = this.getMatrixFromElement( elt ); var worldPt = MathUtils.transformPoint( viewPt, mat ); var stageWorldPt = this.postViewToStageWorld( worldPt, elt ); -- cgit v1.2.3 From 753765b604c954cea782d129e4ddd6a0ff42b2b9 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Mon, 14 May 2012 09:22:00 -0700 Subject: removed some console output. --- js/helper-classes/3D/snap-manager.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'js/helper-classes') diff --git a/js/helper-classes/3D/snap-manager.js b/js/helper-classes/3D/snap-manager.js index 346ad014..99ef5006 100755 --- a/js/helper-classes/3D/snap-manager.js +++ b/js/helper-classes/3D/snap-manager.js @@ -492,7 +492,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { this._elementCache = null; } - console.log( "clear 2D cache" ); + //console.log( "clear 2D cache" ); } }, @@ -505,7 +505,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { this.hLoadElementCache( stage, plane, 0 ); this._isCacheInvalid = false; - console.log( "2D cache loaded with " + this._elementCache.length + " elements" ); + //console.log( "2D cache loaded with " + this._elementCache.length + " elements" ); } }, @@ -1956,7 +1956,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { //this._globalToStageWorldMat = this._stageWorldToGlobalMat.inverse(); this._globalToStageWorldMat = glmat4.inverse( this._stageWorldToGlobalMat, [] ); - console.log( "setupDragPlane: " + this._dragPlane ); + //console.log( "setupDragPlane: " + this._dragPlane ); // load the 2D elements this.load2DCache( this._dragPlane ); -- cgit v1.2.3 From 904c7bfb65bb04400a0f63af1156cd9341958935 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Mon, 14 May 2012 15:11:22 -0700 Subject: Drag plane not being set. Injection from a recent checkin of mine. --- js/helper-classes/3D/snap-manager.js | 3 +++ js/helper-classes/3D/view-utils.js | 8 -------- 2 files changed, 3 insertions(+), 8 deletions(-) (limited to 'js/helper-classes') diff --git a/js/helper-classes/3D/snap-manager.js b/js/helper-classes/3D/snap-manager.js index 99ef5006..9bbbcf29 100755 --- a/js/helper-classes/3D/snap-manager.js +++ b/js/helper-classes/3D/snap-manager.js @@ -230,6 +230,9 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { else parentPt = [xScreen, yScreen, 0.0]; + if (!snap3D && this._hasDragPlane) + this.activateDragPlane(); + var hitRec = this.snapToStage( parentPt, quadPt ); // try snapping to the 3D grid, or to the stage boundaries if the grid is not displayed diff --git a/js/helper-classes/3D/view-utils.js b/js/helper-classes/3D/view-utils.js index 48d4cacf..00124900 100755 --- a/js/helper-classes/3D/view-utils.js +++ b/js/helper-classes/3D/view-utils.js @@ -156,14 +156,6 @@ exports.ViewUtils = Montage.create(Component, { viewDir = MathUtils.transformVector( [0,0,1], stageInv ); } - /* - if (elt === stage) - { - xVec = [1,0,0]; - yVec = [0,1,0]; - } - */ - var plane; var xDot, yDot, zDot; switch (axis) -- cgit v1.2.3 From 00a2452d8158fdab00eec4bd5891b753c0b0ccf5 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Mon, 14 May 2012 15:58:39 -0700 Subject: removed console output. --- js/helper-classes/3D/snap-manager.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'js/helper-classes') diff --git a/js/helper-classes/3D/snap-manager.js b/js/helper-classes/3D/snap-manager.js index 9bbbcf29..97901d50 100755 --- a/js/helper-classes/3D/snap-manager.js +++ b/js/helper-classes/3D/snap-manager.js @@ -1793,7 +1793,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { if (hSnap && vSnap) { - console.log( "\tmerge 1" ); + //console.log( "\tmerge 1" ); // intersect the 2 lines on the plane var hPt = hSnap.getLocalPoint(), @@ -1842,7 +1842,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { if (hSnap && vSnap) { - console.log( "\tmerge 2" ); + //console.log( "\tmerge 2" ); // intersect the 2 lines on the plane var hPt = hSnap.getLocalPoint(), @@ -1895,7 +1895,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { if (hSnap && vSnap) { - console.log( "merge edge" ); + //console.log( "merge edge" ); var hPt = hSnap.getLocalPoint(), vPt = vSnap.getLocalPoint(); @@ -2052,7 +2052,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { var z = s0[2]; var typeStr = hitRec.getTypeString(); - console.log( "\ttype: " + typeStr + ", screen point z: " + hitRec.getScreenPoint()[2] + ", calculated z: " + z ); + //console.log( "\ttype: " + typeStr + ", screen point z: " + hitRec.getScreenPoint()[2] + ", calculated z: " + z ); } } } -- cgit v1.2.3 From b72c5f72ea5df4aa164350e1ba66fd1b4e23369d Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Thu, 17 May 2012 23:07:48 -0700 Subject: removing all stageDeps for drawing classes. Signed-off-by: Valerio Virgillito --- js/helper-classes/3D/draw-utils.js | 2 +- js/helper-classes/3D/snap-manager.js | 13 ++------- js/helper-classes/3D/view-utils.js | 53 ++++++++++++++---------------------- 3 files changed, 24 insertions(+), 44 deletions(-) (limited to 'js/helper-classes') diff --git a/js/helper-classes/3D/draw-utils.js b/js/helper-classes/3D/draw-utils.js index a6d2d899..a8bc16ef 100755 --- a/js/helper-classes/3D/draw-utils.js +++ b/js/helper-classes/3D/draw-utils.js @@ -138,7 +138,7 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { l, t, plane, - elt + elt; for(i=0; i --- js/helper-classes/3D/draw-utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/helper-classes') diff --git a/js/helper-classes/3D/draw-utils.js b/js/helper-classes/3D/draw-utils.js index a8bc16ef..bf48a723 100755 --- a/js/helper-classes/3D/draw-utils.js +++ b/js/helper-classes/3D/draw-utils.js @@ -124,7 +124,7 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { this._eltArray = []; this._planesArray = []; this.setDrawingSurfaceElement(stage.canvas); - this.setSourceSpaceElement( stage.stageDeps.currentStage ); + this.setSourceSpaceElement( this.application.ninja.currentDocument.documentRoot); this.setWorkingPlane( [0,0,1,0] ); //Loop through all the top-level children of the current document and call drawUtils.addElement on them -- cgit v1.2.3 From 084bb924bc3c3a6ad1e2e21099399bba4d473fed Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Fri, 18 May 2012 00:41:31 -0700 Subject: fixing some snapping bugs Signed-off-by: Valerio Virgillito --- js/helper-classes/3D/snap-manager.js | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'js/helper-classes') diff --git a/js/helper-classes/3D/snap-manager.js b/js/helper-classes/3D/snap-manager.js index 7194524e..e22ac3ad 100755 --- a/js/helper-classes/3D/snap-manager.js +++ b/js/helper-classes/3D/snap-manager.js @@ -456,6 +456,13 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { } }, + reload2DCache: { + value: function() { + this.clear2DCache(); + this.load2DCache(workingPlane); + } + }, + clear2DCache : { value : function() { // clear the 2D cache flags in the objects -- cgit v1.2.3 From 66edf78c7e5df11218ef733686965beab05c7c7d Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Fri, 18 May 2012 14:01:00 -0700 Subject: fixing a scrolling issue when multiple documents are switched Signed-off-by: Valerio Virgillito --- js/helper-classes/3D/view-utils.js | 9 --------- 1 file changed, 9 deletions(-) (limited to 'js/helper-classes') diff --git a/js/helper-classes/3D/view-utils.js b/js/helper-classes/3D/view-utils.js index 20f61be1..75530af3 100755 --- a/js/helper-classes/3D/view-utils.js +++ b/js/helper-classes/3D/view-utils.js @@ -1303,15 +1303,6 @@ exports.ViewUtils = Montage.create(Component, { // MISCELLANEOUS // event.layerX/Y: var pt = viewUtils.getMousePoint(event); - getStageDimension: { - value: function() - { - var width = parseInt(this.application.ninja.stage.documentRoot.elementModel.stageDimension.style.getProperty("width")); - var height= parseInt(this.application.ninja.stage.documentRoot.elementModel.stageDimension.style.getProperty("height")); - return[width,height]; - } - }, - getStage: { value: function() { -- cgit v1.2.3