From 878743cbbb75f2fc84855ca27779597b67ab1a95 Mon Sep 17 00:00:00 2001 From: Pushkar Joshi Date: Mon, 2 Apr 2012 15:25:00 -0700 Subject: render the pen path with local coordinates, but use stage world coordinates to position the canvas on which the path is rendered AND add data-montage- to the ids in the pen and brush reels AND fix a bug with pen stroke transparency not working --- js/helper-classes/3D/view-utils.js | 1 - 1 file changed, 1 deletion(-) (limited to 'js/helper-classes/3D') diff --git a/js/helper-classes/3D/view-utils.js b/js/helper-classes/3D/view-utils.js index a72b7906..f60b953a 100755 --- a/js/helper-classes/3D/view-utils.js +++ b/js/helper-classes/3D/view-utils.js @@ -242,7 +242,6 @@ exports.ViewUtils = Montage.create(Component, { var worldPt = MathUtils.transformPoint( viewPt, mat ); var stageWorldPt = this.postViewToStageWorld( worldPt, elt ); this.popViewportObj(); - return stageWorldPt; } }, -- cgit v1.2.3 From 96bfeee2e6b735b87e8482d6e2cf24d5224c6417 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Thu, 5 Apr 2012 17:03:14 -0700 Subject: translate3DObject tool fixes. --- js/helper-classes/3D/hit-record.js | 46 +++++++++++++++++++++++++++++++++++- js/helper-classes/3D/snap-manager.js | 1 + js/helper-classes/3D/view-utils.js | 45 ++++++++++++++++++----------------- 3 files changed, 69 insertions(+), 23 deletions(-) (limited to 'js/helper-classes/3D') diff --git a/js/helper-classes/3D/hit-record.js b/js/helper-classes/3D/hit-record.js index 2c60adc6..96f87c24 100755 --- a/js/helper-classes/3D/hit-record.js +++ b/js/helper-classes/3D/hit-record.js @@ -284,6 +284,50 @@ var HitRecord = exports.HitRecord = Object.create(Object.prototype, return str; } - } + }, + + test: + { + value: function() + { + var elt = this.getElement(); + var stage = viewUtils.getStage(); + if (elt === stage) return; + + var localPt = this.calculateElementPreTransformScreenPoint(); + var stageWorldPt = this.calculateStageWorldPoint(); + var globalPt = this.getScreenPoint(); + var err = false; + + var test1 = viewUtils.localToGlobal( localPt, elt ); + var dist = vecUtils.vecDist(3, test1, globalPt); + if (MathUtils.fpSign(dist) != 0) + { + err = true; + console.log( "**** transform error 1 ***** " + dist + ", localPt: " + localPt ); + } + + var stageWorldToGlobal = viewUtils.getStageWorldToGlobalMatrix(); + var test2 = MathUtils.transformAndDivideHomogeneousPoint( stageWorldPt, stageWorldToGlobal ); + dist = vecUtils.vecDist(3, test2, globalPt); + if (MathUtils.fpSign(dist) != 0) + { + err = true; + console.log( "**** transform error 2 ***** " + dist + ", localPt: " + localPt ); + } + + var localToGlobal = viewUtils.getLocalToGlobalMatrix( elt ); + var globalToLocal = glmat4.inverse( localToGlobal, [] ); + var test3 = MathUtils.transformAndDivideHomogeneousPoint( globalPt, globalToLocal ); + dist = vecUtils.vecDist(3, test3, localPt); + if (MathUtils.fpSign( vecUtils.vecDist(3, test3, localPt)) != 0) + { + err = true; + console.log( "**** transform error 3 ***** " + dist + ", localPt: " + localPt ); + } + + if (!err) console.log( "no hitRecord error" ); + } + } }); diff --git a/js/helper-classes/3D/snap-manager.js b/js/helper-classes/3D/snap-manager.js index 9f6b9ed1..8eafa7e9 100755 --- a/js/helper-classes/3D/snap-manager.js +++ b/js/helper-classes/3D/snap-manager.js @@ -300,6 +300,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { this.deactivateDragPlane(); this.setLastHit( rtnHit ); + //rtnHit.test(); // DEBUG CODE. REMOVE THIS return rtnHit; } }, diff --git a/js/helper-classes/3D/view-utils.js b/js/helper-classes/3D/view-utils.js index a72b7906..392de0be 100755 --- a/js/helper-classes/3D/view-utils.js +++ b/js/helper-classes/3D/view-utils.js @@ -112,6 +112,13 @@ exports.ViewUtils = Montage.create(Component, { var mat = this.getMatrixFromElement(elt); var plane = [mat[8], mat[9], mat[10], mat[11]]; + var stage = this.application.ninja.currentDocument.documentRoot; + if (elt === stage) + { + xVec = [1,0,0]; + yVec = [0,1,0]; + } + // The translation value is a point on the plane this.pushViewportObj( elt ); var ptOnPlane = this.getCenterOfProjection(); @@ -137,6 +144,12 @@ exports.ViewUtils = Montage.create(Component, { var stageMat = this.getMatrixFromElement(stage); var stagePlane = [stageMat[8], stageMat[9], stageMat[10], stageMat[11]]; + if (elt === stage) + { + xVec = [1,0,0]; + yVec = [0,1,0]; + } + var xDot = Math.abs(vecUtils.vecDot(3, xVec, stagePlane)); var yDot = Math.abs(vecUtils.vecDot(3, yVec, stagePlane)); @@ -788,35 +801,23 @@ exports.ViewUtils = Montage.create(Component, { } }, - getStageWorldToGlobalMatrix: { - value: function() { + getStageWorldToGlobalMatrix: + { + value: function() + { var stage = this.application.ninja.currentDocument.documentRoot; this.pushViewportObj( stage ); - - // get the matrix to the parent - var mat = Matrix.I(4); - //var projMat = Matrix.I(4).multiply( this.getPerspectiveDistFromElement(stage) ); - var p = this.getPerspectiveDistFromElement(stage); - var projMat = glmat4.scale( Matrix.I(4), [p,p,p], [] ); - projMat[11] = -1; + + // put the point into screen space of the stage - requires + // a translation to the top/left only var cop = this.getCenterOfProjection(); var v2s = Matrix.Translation([cop[0], cop[1], 0]); - //mat = v2s.multiply( projMat ); - mat = glmat4.multiply( v2s, projMat, [] ); - - // offset to the parent - var offset = this.getElementOffset( stage ); - var offMat = Matrix.Translation([offset[0], offset[1], 0]); - //mat = offMat.multiply( mat ); - glmat4.multiply( offMat, mat, mat ); - this.popViewportObj(); - // var mat2 = this.getLocalToGlobalMatrix( stage.parentElement ); - var mat2 = this.getLocalToGlobalMatrix( this._rootElement ); - //var mat = mat2.multiply( mat ); - glmat4.multiply( mat2, mat, mat ); + // append the localToGlobal matrix of the stage. + var mat = this.getLocalToGlobalMatrix( stage ); + glmat4.multiply( mat, v2s ); return mat; } -- cgit v1.2.3 From f492c816575f990429f4540c9a3eb60c28a89623 Mon Sep 17 00:00:00 2001 From: Pushkar Joshi Date: Fri, 6 Apr 2012 10:53:27 -0700 Subject: complete version of the code for rendering selected subpath anchor points and path overlay (code needs cleanup)...still buggy if creating new paths --- js/helper-classes/3D/view-utils.js | 71 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) (limited to 'js/helper-classes/3D') diff --git a/js/helper-classes/3D/view-utils.js b/js/helper-classes/3D/view-utils.js index f60b953a..35f4a568 100755 --- a/js/helper-classes/3D/view-utils.js +++ b/js/helper-classes/3D/view-utils.js @@ -787,6 +787,7 @@ exports.ViewUtils = Montage.create(Component, { } }, + /* getStageWorldToGlobalMatrix: { value: function() { var stage = this.application.ninja.currentDocument.documentRoot; @@ -820,6 +821,26 @@ exports.ViewUtils = Montage.create(Component, { return mat; } }, + */ + getStageWorldToGlobalMatrix: + { + value: function() + { + var stage = this.application.ninja.currentDocument.documentRoot; + + this.pushViewportObj( stage ); + // put the point into screen space of the stage - requires + // a translation to the top/left only + var cop = this.getCenterOfProjection(); + var v2s = Matrix.Translation([cop[0], cop[1], 0]); + this.popViewportObj(); + + // append the localToGlobal matrix of the stage. + var mat = this.getLocalToGlobalMatrix( stage ); + glmat4.multiply( mat, v2s ); + return mat; + } + }, localScreenToLocalWorld: { value: function( objPt, elt ) { @@ -967,6 +988,56 @@ exports.ViewUtils = Montage.create(Component, { } }, + getLocalToStageWorldMatrix: { + value: function( elt, shouldProject, shouldLocalTransform ) { + var mat = Matrix.I(4); + while (elt) + { + this.pushViewportObj( elt ); + var cop = this.getCenterOfProjection(); + var s2v = Matrix.Translation([-cop[0], -cop[1], 0]); + var objMat = this.getMatrixFromElement( elt ); + var projMat; + if(shouldProject) + { + //projMat = Matrix.I(4).multiply( this.getPerspectiveDistFromElement(elt) ); + var pDist = this.getPerspectiveDistFromElement(elt); + var projMat = glmat4.scale(Matrix.I(4), [pDist,pDist,pDist], []); + projMat[11] = -1; + projMat[15] = 1400; + } + var v2s = Matrix.Translation([cop[0], cop[1], 0]); + this.popViewportObj(); + + // multiply all the matrices together + //mat = s2v.multiply( mat ); + glmat4.multiply( s2v, mat, mat ); + if (elt === this._stageElement) break; + //mat = objMat.multiply( mat ); + if (shouldLocalTransform) { + glmat4.multiply( objMat, mat, mat ); + } + if(shouldProject) + { + //mat = projMat.multiply( mat ); + glmat4.multiply( projMat, mat, mat ); + } + //mat = v2s.multiply( mat ); + glmat4.multiply( v2s, mat, mat ); + + // offset to the parent + var offset = this.getElementOffset( elt ); + var offMat = Matrix.Translation([offset[0], offset[1], 0]); + //mat = offMat.multiply( mat ); + glmat4.multiply( offMat, mat, mat ); + + elt = elt.parentElement; + } + + return mat; + } + }, + getUpVectorFromMatrix: { value: function( mat ) { //var inv = mat.inverse(); -- cgit v1.2.3 From dae3041e6b8269da3d593a44c09e2288bb434a02 Mon Sep 17 00:00:00 2001 From: Pushkar Joshi Date: Mon, 9 Apr 2012 15:55:10 -0700 Subject: snapping feedback for pen tool, correct for subpaths that may lie on rotated canvas, and with a rotated view --- js/helper-classes/3D/vec-utils.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'js/helper-classes/3D') diff --git a/js/helper-classes/3D/vec-utils.js b/js/helper-classes/3D/vec-utils.js index 4eacd856..0916c840 100755 --- a/js/helper-classes/3D/vec-utils.js +++ b/js/helper-classes/3D/vec-utils.js @@ -113,6 +113,25 @@ var VecUtils = exports.VecUtils = Object.create(Object.prototype, } }, + vecDistSq : { + value: function( dimen, a, b ) { + var sum; + + if ((a.length < dimen) || (b.length < dimen)) + { + throw new Error( "dimension error in VecUtils.vecDistSq" ); + } + + var sum = 0.0; + for (var i=0; i 0) || (back > 0)) ? dark : light; context.beginPath(); if ((right > 0) || (back > 0)) { context.beginPath(); - p = this.viewUtils.localToGlobal2( [x1, y0, z0], ssMat ); context.moveTo( p[0], p[1] ); + p = this.viewUtils.localToGlobal2( [x1, y0, z0], ssMat ); context.moveTo( p[0], p[1] ); p = this.viewUtils.localToGlobal2( [x1, y1, z0], ssMat ); context.lineTo( p[0], p[1] ); context.closePath(); context.stroke(); } diff --git a/js/helper-classes/3D/view-utils.js b/js/helper-classes/3D/view-utils.js index 392de0be..f803a274 100755 --- a/js/helper-classes/3D/view-utils.js +++ b/js/helper-classes/3D/view-utils.js @@ -112,13 +112,6 @@ exports.ViewUtils = Montage.create(Component, { var mat = this.getMatrixFromElement(elt); var plane = [mat[8], mat[9], mat[10], mat[11]]; - var stage = this.application.ninja.currentDocument.documentRoot; - if (elt === stage) - { - xVec = [1,0,0]; - yVec = [0,1,0]; - } - // The translation value is a point on the plane this.pushViewportObj( elt ); var ptOnPlane = this.getCenterOfProjection(); -- cgit v1.2.3 From 642d7b45446894a2f3038dcc07a867b260968256 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Fri, 13 Apr 2012 13:48:07 -0700 Subject: 3D rotation --- js/helper-classes/3D/snap-manager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/helper-classes/3D') diff --git a/js/helper-classes/3D/snap-manager.js b/js/helper-classes/3D/snap-manager.js index 5735a145..14a621d0 100755 --- a/js/helper-classes/3D/snap-manager.js +++ b/js/helper-classes/3D/snap-manager.js @@ -307,7 +307,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { this.setLastHit( rtnHit ); - rtnHit.test(); // DEBUG CODE. REMOVE THIS + //rtnHit.test(); // DEBUG CODE. REMOVE THIS return rtnHit; } }, -- cgit v1.2.3 From d6d72e8f519f3eb69374eb233149d3dfde2e5558 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Tue, 17 Apr 2012 09:45:57 -0700 Subject: Allow snapping to unselected objects --- js/helper-classes/3D/snap-manager.js | 9 --------- 1 file changed, 9 deletions(-) (limited to 'js/helper-classes/3D') diff --git a/js/helper-classes/3D/snap-manager.js b/js/helper-classes/3D/snap-manager.js index 14a621d0..cd8cc102 100755 --- a/js/helper-classes/3D/snap-manager.js +++ b/js/helper-classes/3D/snap-manager.js @@ -1088,15 +1088,6 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { localPt = MathUtils.transformPoint( localPt, inv ); var hitContained = false; hitContained = this.snapToContainedElements( hitRec, localPt, globalScrPt ); - - // disable snapping to element bounds when the object isnot selected - if (!hitContained && !this.application.ninja.selectionController.isObjectSelected(elt)) - { - if ((hitRec.getType() == hitRec.SNAP_TYPE_ELEMENT_EDGE) || - (hitRec.getType() == hitRec.SNAP_TYPE_ELEMENT_VERTEX) || - (hitRec.getType() == hitRec.SNAP_TYPE_ELEMENT)) - hitRec = null; - } } return hitRec; -- cgit v1.2.3 From f11ed767396996c236bb8ef0e5f89fedddcaa0d7 Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Tue, 17 Apr 2012 13:27:40 -0700 Subject: Grid should redraw on elementChanging as well as elementChange. Signed-off-by: Nivesh Rajbhandari --- js/helper-classes/3D/draw-utils.js | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'js/helper-classes/3D') diff --git a/js/helper-classes/3D/draw-utils.js b/js/helper-classes/3D/draw-utils.js index a5428ea3..ec8eea0f 100755 --- a/js/helper-classes/3D/draw-utils.js +++ b/js/helper-classes/3D/draw-utils.js @@ -111,6 +111,7 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { this.eventManager.addEventListener("elementAdded", this, false); this.eventManager.addEventListener("elementsRemoved", this, false); this.eventManager.addEventListener("elementChange", this, false); + this.eventManager.addEventListener("elementChanging", this, false); this.eventManager.addEventListener("closeDocument", this, false); this.eventManager.addEventListener("elementReplaced", this, false); } @@ -227,20 +228,26 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { // TODO - Check why handleElementChange is being fired before handleAddElement handleElementChange: { value: function(event) { - if(!event.detail || !event.detail.data) - { + this._elementChangeHelper(event); + } + }, + + handleElementChanging: { + value: function(event) { + this._elementChangeHelper(event); + } + }, + + _elementChangeHelper: { + value: function(event) { + if(!event.detail || !event.detail.data) { return; } var els = event.detail.data.els; - if(els && this._shouldUpdatePlanes(event.detail.data.prop)) - { - var len = els.length, - i = 0, - item; - - for(i=0; i < len; i++) { - if(els[i].elementModel.props3D.elementPlane) - { + if(els && this._shouldUpdatePlanes(event.detail.data.prop)) { + var len = els.length; + for(var i=0; i < len; i++) { + if(els[i].elementModel.props3D.elementPlane) { els[i].elementModel.props3D.elementPlane.init(); } } -- cgit v1.2.3 From 7b3ef287f248c07602aefa3ba2cc907e0d16493a Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Wed, 18 Apr 2012 13:42:18 -0700 Subject: Fixing some more merge issues. Signed-off-by: Nivesh Rajbhandari --- js/helper-classes/3D/draw-utils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'js/helper-classes/3D') diff --git a/js/helper-classes/3D/draw-utils.js b/js/helper-classes/3D/draw-utils.js index 42e0cfa9..039f5bb3 100755 --- a/js/helper-classes/3D/draw-utils.js +++ b/js/helper-classes/3D/draw-utils.js @@ -796,7 +796,7 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { context.stroke(); this._selectionCtr = MathUtils.getCenterFromBounds(3, bounds3D); - console.log("selection center, single elt case - ", this._selectionCtr); +// console.log("selection center, single elt case - ", this._selectionCtr); this.viewUtils.popViewportObj(); } @@ -837,7 +837,7 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { if (MathUtils.fpCmp(dot, 1) != 0) flat = false; } - console.log( "drawSelectionBounds, flat: " + flat ); +// console.log( "drawSelectionBounds, flat: " + flat ); // if all the elements share the same plane, draw the 2D rectangle if (flat) -- cgit v1.2.3