From 27c1ba250a7db26cf24dd456d20af9ff1649e638 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Mon, 23 Apr 2012 17:04:48 -0700 Subject: canvas interaction --- js/helper-classes/3D/snap-manager.js | 274 ++++++++++++++--------------------- 1 file changed, 108 insertions(+), 166 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 cd8cc102..2c975985 100755 --- a/js/helper-classes/3D/snap-manager.js +++ b/js/helper-classes/3D/snap-manager.js @@ -1077,7 +1077,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { var hitRec = this.snapToScreenBounds( elt, globalScrPt, bounds, bounds3D ); // see if we can snap to a contained geometry object - if (hitRec && this.getGLWorld(elt) && !this.isARectangle(elt)) + if (hitRec && this.getGLWorld(elt)) // && !this.isARectangle(elt)) { var localPt = hitRec.calculateElementWorldPoint(); if (hitRec.getType() != hitRec.SNAP_TYPE_ELEMENT) @@ -1320,193 +1320,135 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { } }, - snapToContainedElement : + doSnapToContainedElement: { value: function( eyePt, dir, glObj, hitRec, targetScrPt ) { var rtnVal = false; - var elt = hitRec.getElement(); + var elt = hitRec.getElt(); var world = glObj.getWorld(); - switch (glObj.geomType()) + + var nearVrt = glObj.getNearVertex( eyePt, dir ); + if (nearVrt) { - case glObj.GEOM_TYPE_RECTANGLE: - break; + var viewPt = this.GLToView(nearVrt, world ); + var mat = viewUtils.getMatrixFromElement( elt ); + var worldPt = MathUtils.transformPoint( viewPt, mat ); - case glObj.GEOM_TYPE_CIRCLE: + viewUtils.pushViewportObj( elt ); + var scrPt = viewUtils.viewToScreen( worldPt ); + var offset = viewUtils.getElementOffset( elt ); + MathUtils.makeDimension3( offset ); + var parentPt = vecUtils.vecAdd(3, scrPt, offset ); + var globalPt = viewUtils.localToGlobal( parentPt, elt.offsetParent ); + + var dist = vecUtils.vecDist(2, globalPt, targetScrPt ); + if (dist < this.ELEMENT_VERTEX_HIT_RAD) + { + console.log( "hit a vertex" ); + + // check if the distance is less than + // the distance on the current hit record + if (dist <= vecUtils.vecDist(2, targetScrPt, hitRec.getScreenPoint() )) { - var nearVrt = glObj.getNearVertex( eyePt, dir ); - if (nearVrt) - { - var viewPt = this.GLToView(nearVrt, world ); - var mat = viewUtils.getMatrixFromElement( elt ); - var worldPt = MathUtils.transformPoint( viewPt, mat ); - - viewUtils.pushViewportObj( elt ); - var scrPt = viewUtils.viewToScreen( worldPt ); - var offset = viewUtils.getElementOffset( elt ); - MathUtils.makeDimension3( offset ); - var parentPt = vecUtils.vecAdd(3, scrPt, offset ); - var globalPt = viewUtils.localToGlobal( parentPt, elt.offsetParent ); - - var dist = vecUtils.vecDist(2, globalPt, targetScrPt ); - if (dist < this.ELEMENT_VERTEX_HIT_RAD) - { - // check if the distance is less than - // the distance on the current hit record - if (dist <= vecUtils.vecDist(2, targetScrPt, hitRec.getScreenPoint() )) - { - hitRec.setScreenPoint( globalPt ); - //var localMatInv = hitRec.getPlaneMatrix().inverse(); - var localMatInv = glmat4.inverse( hitRec.getPlaneMatrix(), []); - viewUtils.pushViewportObj( hitRec.getElement() ); - var localPt = viewUtils.screenToView( scrPt[0], scrPt[1], scrPt[2] ); - viewUtils.popViewportObj(); - localPt = MathUtils.transformPoint( localPt, localMatInv ); - hitRec.setLocalPoint( localPt ); - hitRec.setType( hitRec.SNAP_TYPE_CONTAINED_ELEMENT ); - - rtnVal = true; - } - } - } // if (nearVrt) + console.log( "rejected - further than existing snap" ); + + hitRec.setScreenPoint( globalPt ); + //var localMatInv = hitRec.getPlaneMatrix().inverse(); + var localMatInv = glmat4.inverse( hitRec.getPlaneMatrix(), []); + viewUtils.pushViewportObj( hitRec.getElement() ); + var localPt = viewUtils.screenToView( scrPt[0], scrPt[1], scrPt[2] ); + viewUtils.popViewportObj(); + localPt = MathUtils.transformPoint( localPt, localMatInv ); + hitRec.setLocalPoint( localPt ); + hitRec.setType( hitRec.SNAP_TYPE_CONTAINED_ELEMENT ); - if (!rtnVal) - { - var nearPt = glObj.getNearPoint( eyePt, dir ); - if (nearPt) - { - var viewPt = this.GLToView(nearPt, world ); - var mat = viewUtils.getMatrixFromElement( elt ); - var worldPt = MathUtils.transformPoint( viewPt, mat ); - - viewUtils.pushViewportObj( elt ); - var scrPt = viewUtils.viewToScreen( worldPt ); - var offset = viewUtils.getElementOffset( elt ); - MathUtils.makeDimension3( offset ); - var parentPt = vecUtils.vecAdd(3, scrPt, offset ); - var globalPt = viewUtils.localToGlobal( parentPt, elt.offsetParent ); - - var dist = vecUtils.vecDist(2, globalPt, targetScrPt ); - if (dist < this.ELEMENT_EDGE_HIT_RAD) - { - // check if the distance is less than - // the distance on the current hit record - //var dist2 = vecUtils.vecDist(2, targetScrPt, hitRec.getScreenPoint() ); - //if (dist <= dist2+1 ) - { - hitRec.setScreenPoint( globalPt ); - //var localMatInv = hitRec.getPlaneMatrix().inverse(); - var localMatInv = glmat4.inverse( hitRec.getPlaneMatrix(), []); - viewUtils.pushViewportObj( hitRec.getElement() ); - var localPt = viewUtils.screenToView( scrPt[0], scrPt[1], scrPt[2] ); - viewUtils.popViewportObj(); - localPt = MathUtils.transformPoint( localPt, localMatInv ); - hitRec.setLocalPoint( localPt ); - hitRec.setType( hitRec.SNAP_TYPE_CONTAINED_ELEMENT ); - - rtnVal = true; - } - } - } - } // if (!rtnVal) + rtnVal = true; + } + } + } - if (!rtnVal && glObj.containsPoint( eyePt, dir )) + if (!rtnVal) + { + var nearPt = glObj.getNearPoint( eyePt, dir ); + if (nearPt) + { + var viewPt = this.GLToView(nearPt, world ); + var mat = viewUtils.getMatrixFromElement( elt ); + var worldPt = MathUtils.transformPoint( viewPt, mat ); + + viewUtils.pushViewportObj( elt ); + var scrPt = viewUtils.viewToScreen( worldPt ); + var offset = viewUtils.getElementOffset( elt ); + MathUtils.makeDimension3( offset ); + var parentPt = vecUtils.vecAdd(3, scrPt, offset ); + var globalPt = viewUtils.localToGlobal( parentPt, elt.offsetParent ); + + var dist = vecUtils.vecDist(2, globalPt, targetScrPt ); + if (dist < this.ELEMENT_EDGE_HIT_RAD) + { + console.log( "hit an edge" ); + + // check if the distance is less than + // the distance on the current hit record + //var dist2 = vecUtils.vecDist(2, targetScrPt, hitRec.getScreenPoint() ); + //if (dist <= dist2+1 ) { + hitRec.setScreenPoint( globalPt ); + //var localMatInv = hitRec.getPlaneMatrix().inverse(); + var localMatInv = glmat4.inverse( hitRec.getPlaneMatrix(), []); + viewUtils.pushViewportObj( hitRec.getElement() ); + var localPt = viewUtils.screenToView( scrPt[0], scrPt[1], scrPt[2] ); + viewUtils.popViewportObj(); + localPt = MathUtils.transformPoint( localPt, localMatInv ); + hitRec.setLocalPoint( localPt ); + hitRec.setType( hitRec.SNAP_TYPE_CONTAINED_ELEMENT ); + rtnVal = true; } } + } + } // if (!rtnVal) + + if (!rtnVal && glObj.containsPoint( eyePt, dir )) + { + rtnVal = true; + } + + return rtnVal; + } + }, + + snapToContainedElement : + { + value: function( eyePt, dir, glObj, hitRec, targetScrPt ) + { + var rtnVal = false; + var elt = hitRec.getElement(); + + var world = glObj.getWorld(); + switch (glObj.geomType()) + { + case glObj.GEOM_TYPE_RECTANGLE: + if ((glObj.getWidth() != world.getViewportWidth()) || (glObj.getHeight() != world.getViewportHeight())) + rtnVal = this.doSnapToContainedElement( eyePt, dir, glObj, hitRec, targetScrPt ); + break; + + case glObj.GEOM_TYPE_CIRCLE: + rtnVal = this.doSnapToContainedElement( eyePt, dir, glObj, hitRec, targetScrPt ); break; case glObj.GEOM_TYPE_LINE: case glObj.GEOM_TYPE_PATH: // Snapping not implemented for these type, but don't throw an error... break; - case glObj.GEOM_TYPE_BRUSH_STROKE: + + case glObj.GEOM_TYPE_BRUSH_STROKE: break; //don't throw error because snapping not yet implemented - case glObj.GEOM_TYPE_CUBIC_BEZIER: - { - var nearVrt = glObj.getNearVertex( eyePt, dir ); - if (nearVrt) - { - var viewPt = this.GLToView(nearVrt, world ); - var mat = viewUtils.getMatrixFromElement( elt ); - var worldPt = MathUtils.transformPoint( viewPt, mat ); - - viewUtils.pushViewportObj( elt ); - var scrPt = viewUtils.viewToScreen( worldPt ); - var offset = viewUtils.getElementOffset( elt ); - MathUtils.makeDimension3( offset ); - var parentPt = vecUtils.vecAdd(3, scrPt, offset ); - var globalPt = viewUtils.localToGlobal( parentPt, elt.offsetParent ); - - var dist = vecUtils.vecDist(2, globalPt, targetScrPt ); - if (dist < this.ELEMENT_VERTEX_HIT_RAD) - { - // check if the distance is less than - // the distance on the current hit record - if (dist <= vecUtils.vecDist(2, targetScrPt, hitRec.getScreenPoint() )) - { - hitRec.setScreenPoint( globalPt ); - //var localMatInv = hitRec.getPlaneMatrix().inverse(); - var localMatInv = glmat4.inverse( hitRec.getPlaneMatrix(), []); - viewUtils.pushViewportObj( hitRec.getElement() ); - var localPt = viewUtils.screenToView( scrPt[0], scrPt[1], scrPt[2] ); - viewUtils.popViewportObj(); - localPt = MathUtils.transformPoint( localPt, localMatInv ); - hitRec.setLocalPoint( localPt ); - hitRec.setType( hitRec.SNAP_TYPE_CONTAINED_ELEMENT ); - - rtnVal = true; - } - } - } // if (nearVrt) - - if (!rtnVal) - { - var nearPt = glObj.getNearPoint( eyePt, dir ); - if (nearPt) - { - var viewPt = this.GLToView(nearPt, world ); - var mat = viewUtils.getMatrixFromElement( elt ); - var worldPt = MathUtils.transformPoint( viewPt, mat ); - - viewUtils.pushViewportObj( elt ); - var scrPt = viewUtils.viewToScreen( worldPt ); - var offset = viewUtils.getElementOffset( elt ); - MathUtils.makeDimension3( offset ); - var parentPt = vecUtils.vecAdd(3, scrPt, offset ); - var globalPt = viewUtils.localToGlobal( parentPt, elt.offsetParent ); - - var dist = vecUtils.vecDist(2, globalPt, targetScrPt ); - if (dist < this.ELEMENT_EDGE_HIT_RAD) - { - // check if the distance is less than - // the distance on the current hit record - //var dist2 = vecUtils.vecDist(2, targetScrPt, hitRec.getScreenPoint() ); - //if (dist <= dist2+1 ) - { - hitRec.setScreenPoint( globalPt ); - //var localMatInv = hitRec.getPlaneMatrix().inverse(); - var localMatInv = glmat4.inverse( hitRec.getPlaneMatrix(), []); - viewUtils.pushViewportObj( hitRec.getElement() ); - var localPt = viewUtils.screenToView( scrPt[0], scrPt[1], scrPt[2] ); - viewUtils.popViewportObj(); - localPt = MathUtils.transformPoint( localPt, localMatInv ); - hitRec.setLocalPoint( localPt ); - hitRec.setType( hitRec.SNAP_TYPE_CONTAINED_ELEMENT ); - - rtnVal = true; - } - } - } - } // if (!rtnVal) - - if (!rtnVal && glObj.containsPoint( eyePt, dir )) - { - rtnVal = true; - } - } + + case glObj.GEOM_TYPE_CUBIC_BEZIER: + rtnVal = this.doSnapToContainedElement( eyePt, dir, glObj, hitRec, targetScrPt ); break; default: throw new Error( "invalid GL geometry type: " + glObj.geomType() ); -- cgit v1.2.3 From 4b83774cdbfbf30add9a8fa2f11b1c4ff35179fa Mon Sep 17 00:00:00 2001 From: hwc487 Date: Thu, 26 Apr 2012 12:50:57 -0700 Subject: canvas interaction --- js/helper-classes/3D/snap-manager.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 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 2c975985..dcfd5ddc 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, { { // see if we can snap to a contained geometry object - if (hitRec && this.getGLWorld(elt) && !this.isARectangle(elt)) + if (hitRec && this.getGLWorld(elt)) // && !this.isARectangle(elt)) { var localPt = hitRec.calculateElementWorldPoint(); if (hitRec.getType() != hitRec.SNAP_TYPE_ELEMENT) @@ -1346,13 +1346,13 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { var dist = vecUtils.vecDist(2, globalPt, targetScrPt ); if (dist < this.ELEMENT_VERTEX_HIT_RAD) { - console.log( "hit a vertex" ); + //console.log( "hit a vertex" ); // check if the distance is less than // the distance on the current hit record - if (dist <= vecUtils.vecDist(2, targetScrPt, hitRec.getScreenPoint() )) + //if (dist <= vecUtils.vecDist(2, targetScrPt, hitRec.getScreenPoint() )) { - console.log( "rejected - further than existing snap" ); + //console.log( "rejected - further than existing snap" ); hitRec.setScreenPoint( globalPt ); //var localMatInv = hitRec.getPlaneMatrix().inverse(); @@ -1388,7 +1388,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { var dist = vecUtils.vecDist(2, globalPt, targetScrPt ); if (dist < this.ELEMENT_EDGE_HIT_RAD) { - console.log( "hit an edge" ); + //console.log( "hit an edge" ); // check if the distance is less than // the distance on the current hit record -- cgit v1.2.3 From e73fba18b095f0c270f5d954e5993c155b488c73 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Fri, 27 Apr 2012 13:52:40 -0700 Subject: Creating shapes in a container --- js/helper-classes/3D/snap-manager.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'js/helper-classes') diff --git a/js/helper-classes/3D/snap-manager.js b/js/helper-classes/3D/snap-manager.js index dcfd5ddc..7fc492a5 100755 --- a/js/helper-classes/3D/snap-manager.js +++ b/js/helper-classes/3D/snap-manager.js @@ -1011,7 +1011,8 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { } // hit test the current object var hit; - if (depth > 0) // don't snap to the root + var snapToStage = ((depth === 0) && (elt === this.application.ninja.currentSelectedContainer) && (elt.nodeName === 'CANVAS')); + if ((depth > 0) || snapToStage) // don't snap to the root unles we are working inside a canvas { // if the element is in the 2D cache snapping is done there if (elt.elementModel && !elt.elementModel.isIn2DSnapCache) -- cgit v1.2.3 From c534f70e9af920d252d0d94151c9d6f884283b81 Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Tue, 1 May 2012 07:01:44 -0700 Subject: Get working plane grid to draw for new stage web template workflow. Signed-off-by: Nivesh Rajbhandari --- js/helper-classes/3D/draw-utils.js | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 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 7bd77c3a..f7b02485 100755 --- a/js/helper-classes/3D/draw-utils.js +++ b/js/helper-classes/3D/draw-utils.js @@ -583,17 +583,24 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { // get a point that lies on the plane var ptOnPlane = MathUtils.getPointOnPlane(this._workingPlane); + // define the grid parameters + var width, + height, + nLines = 10; + + if(this.application.ninja.documentController.webTemplate) { + width = this.application.ninja.currentDocument.documentRoot.scrollWidth; + height = this.application.ninja.currentDocument.documentRoot.scrollHeight; + } else { + width = this.snapManager.getStageWidth(); + height = this.snapManager.getStageHeight(); + } // get a matrix from working plane space to the world var mat = this.getPlaneToWorldMatrix(zAxis, ptOnPlane); - var tMat = Matrix.Translation( [0.5*this.snapManager.getStageWidth(), 0.5*this.snapManager.getStageHeight(),0] ); + var tMat = Matrix.Translation( [0.5*width, 0.5*height, 0] ); //mat = tMat.multiply(mat); glmat4.multiply( tMat, mat, mat); - // define the grid parameters - var width = this.snapManager.getStageWidth(), - height = this.snapManager.getStageHeight(); - var nLines = 10; - // the positioning of the grid may depend on the view direction. var stage = this.snapManager.getStage(); var viewMat = this.viewUtils.getMatrixFromElement(stage); @@ -662,6 +669,7 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { var offset = this.viewUtils.getElementOffset(this._sourceSpaceElt); offset[2] = 0; this.viewUtils.setViewportObj(this._sourceSpaceElt); + var sourceSpaceMat = this.viewUtils.getLocalToGlobalMatrix( this._sourceSpaceElt ); for (var i = 0; i < nLines; i++) { // transform the points from working plane space to world space //var t0 = mat.multiply(p0), @@ -671,8 +679,10 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { // transform from world space to global screen space if (this._sourceSpaceElt) { - t0 = this.viewUtils.localToGlobal(t0, this._sourceSpaceElt); - t1 = this.viewUtils.localToGlobal(t1, this._sourceSpaceElt); +// t0 = this.viewUtils.localToGlobal(t0, this._sourceSpaceElt); +// t1 = this.viewUtils.localToGlobal(t1, this._sourceSpaceElt); + t0 = this.viewUtils.localToGlobal2(t0, sourceSpaceMat); + t1 = this.viewUtils.localToGlobal2(t1, sourceSpaceMat); } // create a line from the endpoints -- cgit v1.2.3 From 84eec0ae4352c9f6e5986529cc70eed726d97a88 Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Tue, 1 May 2012 09:29:49 -0700 Subject: webTemplate var gets reset to false, so must check for new stage template differently. Signed-off-by: Nivesh Rajbhandari --- js/helper-classes/3D/draw-utils.js | 3 ++- 1 file changed, 2 insertions(+), 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 f7b02485..81a740e0 100755 --- a/js/helper-classes/3D/draw-utils.js +++ b/js/helper-classes/3D/draw-utils.js @@ -588,7 +588,8 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { height, nLines = 10; - if(this.application.ninja.documentController.webTemplate) { +// if(this.application.ninja.documentController.webTemplate) { + if(this.application.ninja.currentDocument.documentRoot.id !== "UserContent") { width = this.application.ninja.currentDocument.documentRoot.scrollWidth; height = this.application.ninja.currentDocument.documentRoot.scrollHeight; } else { -- cgit v1.2.3 From d262bb9b0c49b7bcb9fd1b429abcf6d38b39ddf6 Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Tue, 1 May 2012 16:40:22 -0700 Subject: Offset side and top working planes by half the stage width/height. Signed-off-by: Nivesh Rajbhandari --- js/helper-classes/3D/snap-manager.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 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 7fc492a5..f4bfc12b 100755 --- a/js/helper-classes/3D/snap-manager.js +++ b/js/helper-classes/3D/snap-manager.js @@ -1617,7 +1617,11 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { if (x > y) { if (x > z) { plane[0] = 1; - plane[3] = this.getStageWidth() / 2.0; + if(this.application.ninja.currentDocument.documentRoot.id !== "UserContent") { + plane[3] = stage.scrollWidth / 2.0; + } else { + plane[3] = this.getStageWidth() / 2.0; + } if (dir[0] > 0) plane[3] = -plane[3]; change = !drawUtils.drawYZ; drawUtils.drawXY = drawUtils.drawXZ = false; @@ -1635,7 +1639,11 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { else { if (y > z) { plane[1] = 1; - plane[3] = this.getStageHeight() / 2.0; + if(this.application.ninja.currentDocument.documentRoot.id !== "UserContent") { + plane[3] = stage.scrollHeight / 2.0; + } else { + plane[3] = this.getStageHeight() / 2.0; + } if (dir[1] > 0) plane[3] = -plane[3]; change = !drawUtils.drawXZ; drawUtils.drawXY = drawUtils.drawYZ = false; -- cgit v1.2.3 From 0f16c5ea0d08a740f553284c436bb3e589fb1357 Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Tue, 1 May 2012 16:49:29 -0700 Subject: Draw a red outline around the stage for reference when rotating stage. Signed-off-by: Nivesh Rajbhandari --- js/helper-classes/3D/draw-utils.js | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 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 81a740e0..88830964 100755 --- a/js/helper-classes/3D/draw-utils.js +++ b/js/helper-classes/3D/draw-utils.js @@ -651,6 +651,21 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { this._lineColor = saveColor; this._drawingContext.lineWidth = saveLineWidth; + if(this.application.ninja.currentDocument.documentRoot.id !== "UserContent") { + // draw an outline around the body + var stagePt = MathUtils.getPointOnPlane([0,0,1,0]); + var stageMat = this.getPlaneToWorldMatrix([0,0,1], stagePt); + // glmat4.multiply( tMat, stageMat, stageMat); + pt0 = [0, 0, 0]; + pt1 = [0, height, 0]; + delta = [width, 0, 0]; + this.drawGridLines(pt0, pt1, delta, stageMat, 2); + pt0 = [0, 0, 0]; + pt1 = [width, 0, 0]; + delta = [0, height, 0]; + this.drawGridLines(pt0, pt1, delta, stageMat, 2); + } + // draw the lines this.redrawGridLines(); @@ -752,12 +767,27 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { this._drawingContext.lineWidth = 0.25; // draw the lines - var nLines = this._gridLineArray.length; + var line, + nLines = this._gridLineArray.length; + if(this.application.ninja.currentDocument.documentRoot.id !== "UserContent") { + nLines = this._gridLineArray.length-4; + } + for (var i = 0; i < nLines; i++) { - var line = this._gridLineArray[i]; + line = this._gridLineArray[i]; this.drawIntersectedLine(line, this._drawingContext); } + if(this.application.ninja.currentDocument.documentRoot.id !== "UserContent") { + this._lineColor = "red"; + i = nLines; + nLines += 4; + for (; i < nLines; i++) { + line = this._gridLineArray[i]; + this.drawIntersectedLine(line, this._drawingContext); + } + } + this.popState(); } }, -- cgit v1.2.3 From 9eeb03e8bb86a4462609d3a18b528daa1516b91c Mon Sep 17 00:00:00 2001 From: hwc487 Date: Mon, 7 May 2012 13:57:18 -0700 Subject: fixes for 2D and 3D translation. --- js/helper-classes/3D/snap-manager.js | 4 ++ js/helper-classes/3D/view-utils.js | 80 ++++++++++++++++++++++++++++-------- 2 files changed, 67 insertions(+), 17 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 f4bfc12b..6766ac7f 100755 --- a/js/helper-classes/3D/snap-manager.js +++ b/js/helper-classes/3D/snap-manager.js @@ -1957,6 +1957,8 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { var localPt = hitRec.getLocalPoint(); var planeMat = hitRec.getPlaneMatrix(); var stageWorldPt; + + /* if(inGlobalMode) { stageWorldPt = MathUtils.transformPoint(localPt,planeMat); @@ -1965,6 +1967,8 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { { stageWorldPt = viewUtils.postViewToStageWorld( MathUtils.transformPoint(localPt,planeMat), elt ); } + */ + stageWorldPt = viewUtils.postViewToStageWorld( MathUtils.transformPoint(localPt,planeMat), elt ); /* // get a working plane parallel to the current working plane through the stage world point diff --git a/js/helper-classes/3D/view-utils.js b/js/helper-classes/3D/view-utils.js index 40a19b90..919f7c50 100755 --- a/js/helper-classes/3D/view-utils.js +++ b/js/helper-classes/3D/view-utils.js @@ -124,35 +124,81 @@ exports.ViewUtils = Montage.create(Component, { } }, - getNormalToUnprojectedElementPlane: { - value: function( elt ) { - var mat = this.getMatrixFromElement(elt); + /* + * This method will return a normal to a plane containing the Z axis and either the + * x or y axis of the element. + */ + getNormalToUnprojectedElementPlane: + { + value: function( elt, axis, localMode ) + { + var objMat = this.getMatrixFromElement(elt); + var objMatInv = glmat4.inverse( objMat, [] ); - var xVec = [mat[0], mat[1], mat[2], mat[3]]; - var yVec = [mat[4], mat[5], mat[6], mat[7]]; + var xVec = [1,0,0]; + var yVec = [0,1,0]; + var zVec = [0,0,1]; var stage = this.application.ninja.currentDocument.documentRoot; var stageMat = this.getMatrixFromElement(stage); - var stagePlane = [stageMat[8], stageMat[9], stageMat[10], stageMat[11]]; + var mat = glmat4.multiply( stageMat, objMat, [] ); + + var viewDir; + if (localMode) + { + var matInv = glmat4.inverse( mat, [] ); + viewDir = MathUtils.transformVector( [0,0,1], matInv ); + } + else + { + var stageInv = glmat4.inverse( stageMat, [] ); + viewDir = MathUtils.transformVector( [0,0,1], stageInv ); + } + + /* 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)); + var plane; + var xDot, yDot, zDot; + switch (axis) + { + case 0: + yDot = Math.abs(vecUtils.vecDot(3, yVec, viewDir)); + zDot = Math.abs(vecUtils.vecDot(3, zVec, viewDir)); + if(yDot > zDot) + plane = vecUtils.vecCross( 3, zVec, xVec ); + else + plane = vecUtils.vecCross( 3, yVec, xVec ); + break; + + case 1: + xDot = Math.abs(vecUtils.vecDot(3, yVec, viewDir)); + zDot = Math.abs(vecUtils.vecDot(3, zVec, viewDir)); + if(xDot > zDot) + plane = vecUtils.vecCross( 3, zVec, yVec ); + else + plane = vecUtils.vecCross( 3, xVec, yVec ); + break; + break; + + case 2: + xDot = Math.abs(vecUtils.vecDot(3, xVec, viewDir)); + yDot = Math.abs(vecUtils.vecDot(3, yVec, viewDir)); + + if(xDot > yDot) + plane = vecUtils.vecCross( 3, yVec, zVec ); + else + plane = vecUtils.vecCross( 3, xVec, zVec ); + break; + } - var plane; - if(xDot > yDot) - { - plane = xVec; - } - else - { - plane = yVec; - } + if (localMode) plane = MathUtils.transformVector( plane, objMat ); // The translation value is a point on the plane this.pushViewportObj( elt ); -- cgit v1.2.3