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 f522ce09d98bbb2812ed25bb942597d854d71a1c Mon Sep 17 00:00:00 2001 From: hwc487 Date: Wed, 11 Apr 2012 16:01:33 -0700 Subject: Rotate3D tool changes --- js/helper-classes/3D/hit-record.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 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 96f87c24..6094dae1 100755 --- a/js/helper-classes/3D/hit-record.js +++ b/js/helper-classes/3D/hit-record.js @@ -320,13 +320,22 @@ var HitRecord = exports.HitRecord = Object.create(Object.prototype, 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) + if (MathUtils.fpSign(dist) != 0) { err = true; console.log( "**** transform error 3 ***** " + dist + ", localPt: " + localPt ); } - if (!err) console.log( "no hitRecord error" ); + var objToStageWorld = viewUtils.getObjToStageWorldMatrix( elt, true ); + var test4 = MathUtils.transformAndDivideHomogeneousPoint( localPt, objToStageWorld ); + dist = vecUtils.vecDist(3, test4, stageWorldPt); + if (MathUtils.fpSign(dist) != 0) + { + err = true; + console.log( "**** transform error 4 ***** " + dist + ", localPt: " + localPt ); + } + + //if (!err) console.log( "no hitRecord error" ); } } }); -- cgit v1.2.3 From 521df0ed9242efff45715998837068c87aca7efd Mon Sep 17 00:00:00 2001 From: hwc487 Date: Fri, 13 Apr 2012 11:12:40 -0700 Subject: 3D Rotate changes --- js/helper-classes/3D/draw-utils.js | 48 +++++++++++++++++++++++++------------- js/helper-classes/3D/view-utils.js | 7 ------ 2 files changed, 32 insertions(+), 23 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 c7c1c08d..a200268e 100755 --- a/js/helper-classes/3D/draw-utils.js +++ b/js/helper-classes/3D/draw-utils.js @@ -774,13 +774,14 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { else { // get the plane from the first element to compare against the other elements + var dot; var flat = true; - var plane = this.viewUtils.getElementPlane( eltArray[0] ); + var plane = this.viewUtils.getUnprojectedElementPlane( eltArray[0] ); for (i=1; 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