From dde27659a9028c131884f0654f01206347512a81 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Tue, 19 Jun 2012 16:32:42 -0700 Subject: Added logic to handle grid drawing where grid line starts on an object boundary --- js/helper-classes/3D/StageLine.js | 309 ++++++++++++++++++++++---------------- 1 file changed, 177 insertions(+), 132 deletions(-) (limited to 'js') diff --git a/js/helper-classes/3D/StageLine.js b/js/helper-classes/3D/StageLine.js index b86673d1..23e8cf5b 100755 --- a/js/helper-classes/3D/StageLine.js +++ b/js/helper-classes/3D/StageLine.js @@ -184,138 +184,183 @@ var StageLine = exports.StageLine = Object.create(Object.prototype, { }, doCoplanarIntersection: { - value: function( plane ) - { - // get the boundary points for the plane - var boundaryPts = plane.getBoundaryPoints(); - var planeEq = plane.getPlaneEq(); - - if (plane.isBackFacing()) - { - var tmp; - tmp = boundaryPts[0]; boundaryPts[0] = boundaryPts[3]; boundaryPts[3] = tmp; - tmp = boundaryPts[1]; boundaryPts[1] = boundaryPts[2]; boundaryPts[2] = tmp; - } - - var pt0 = this.getPoint0(), - pt1 = this.getPoint1(); - - // keep a couple flags to prevent counting crossings twice in edge cases - var gotEnter = false, - gotExit = false; - - var bp1 = boundaryPts[3]; - for (var i=0; i<4; i++) - { - var bp0 = bp1; - bp1 = boundaryPts[i]; - var vec = vecUtils.vecSubtract(3, bp1, bp0); - var nrm = vecUtils.vecCross(3, vec, planeEq); - nrm[3] = -vecUtils.vecDot(3, bp0, nrm); - - var d0 = vecUtils.vecDot(3, nrm, pt0) + nrm[3], - d1 = vecUtils.vecDot(3, nrm, pt1) + nrm[3]; - - var s0 = MathUtils.fpSign(d0), - s1 = MathUtils.fpSign(d1); - - if (s0 != s1) - { - var t = Math.abs(d0)/( Math.abs(d0) + Math.abs(d1) ); - if ( (MathUtils.fpSign(t) >= 0) && (MathUtils.fpCmp(t,1.0) <= 0)) - { - // get the point where the line crosses the edge of the element plane - var pt = MathUtils.interpolateLine3D(pt0, pt1, t ); - - // we know that the line crosses the infinite extension of the edge. Determine - // if that crossing is within the bounds of the edge - var dot0 = vecUtils.vecDot(3, vecUtils.vecSubtract(3,pt, bp0), vec), - dot1 = vecUtils.vecDot(3, vecUtils.vecSubtract(3,pt, bp1), vec); - if ((MathUtils.fpSign(dot0) > 0) && (MathUtils.fpSign(dot1) < 0)) - { - // determine if the line is entering or exiting - if (s0 <= 0) // entering - { - if (!gotEnter) - { - gotEnter = true; - this.addIntersection( plane, t, 1 ); - } - } - else if (s0 > 0) // exiting - { - if (!gotExit) - { - gotExit = true; - this.addIntersection( plane, t, -1 ); - } - } - else // s0 == 0 - { - // TODO - } - } - else if ((MathUtils.fpSign(dot0) == 0) && (MathUtils.fpSign(dot1) < 0)) - { - var j = i - 2; - if (j < 0) j += 4; - var bp = boundaryPts[j]; - - var v0 = vecUtils.vecSubtract( 3, bp, bp0 ), - v1 = vec; - - if (s0 <= 0) - { - var v = vecUtils.vecSubtract(3, pt1, pt0); - if ((MathUtils.fpSign(vecUtils.vecCross(3, v0,v)) > 0) && (MathUtils.fpSign(vecUtils.vecCross(3, v,v1)) > 0)) - { - gotEnter = true; - this.addIntersection( plane, t, 1 ); - } - } - else if (s0 > 0) - { - var v = vecUtils.vecSubtract(3, pt0, pt1); // note the reversed order from the previous case - if ((MathUtils.fpSign(vecUtils.vecCross(3, v0,v)) > 0) && (MathUtils.fpSign(vecUtils.vecCross(3, v,v1)) > 0)) - { - gotEnter = true; - this.addIntersection( plane, t, -1 ); - } - } - } - else if ((MathUtils.fpSign(dot0) > 0) && (MathUtils.fpSign(dot1) == 0)) - { - var j = (i + 1) % 4; - var bp = boundaryPts[j]; - - var v1 = vec.slice(0), - v0 = vecUtils.vecSubtract( 3, bp, bp1 ), - v1 = vecUtils.vecNegate(3, v1); - - if (s0 <= 0) - { - var v = vecUtils.vecSubtract(3, pt1, pt0); - if ((MathUtils.fpSign(vecUtils.vecCross(3, v0,v)) < 0) && (MathUtils.fpSign(vecUtils.vecCross(3, v,v1)) < 0)) - { - gotEnter = true; - this.addIntersection( plane, t, 1 ); - } - } - else if (s0 > 0) - { - var v = vecUtils.vecSubtract(3, pt0, pt1); // note the reversed order from the previous case - if ((MathUtils.fpSign(vecUtils.vecCross(3, v0,v)) > 0) && (MathUtils.fpSign(vecUtils.vecCross(3, v,v1)) > 0)) - { - gotEnter = true; - this.addIntersection( plane, t, -1 ); - } - } - } - } - } - } - } - }, + value: function( plane ) + { + // get the boundary points for the plane + var boundaryPts = plane.getBoundaryPoints(); + var planeEq = plane.getPlaneEq(); + + if (plane.isBackFacing()) + { + var tmp; + tmp = boundaryPts[0]; boundaryPts[0] = boundaryPts[3]; boundaryPts[3] = tmp; + tmp = boundaryPts[1]; boundaryPts[1] = boundaryPts[2]; boundaryPts[2] = tmp; + } + + var pt0 = this.getPoint0(), + pt1 = this.getPoint1(); + + // keep a couple flags to prevent counting crossings twice in edge cases + var gotEnter = false, + gotExit = false; + + var bp1 = boundaryPts[3]; + for (var i=0; i<4; i++) + { + var bp0 = bp1; + bp1 = boundaryPts[i]; + var vec = vecUtils.vecSubtract(3, bp1, bp0); + var nrm = vecUtils.vecCross(3, vec, planeEq); + nrm[3] = -vecUtils.vecDot(3, bp0, nrm); + + var d0 = vecUtils.vecDot(3, nrm, pt0) + nrm[3], + d1 = vecUtils.vecDot(3, nrm, pt1) + nrm[3]; + + var s0 = MathUtils.fpSign(d0), + s1 = MathUtils.fpSign(d1); + + if (s0 != s1) + { + var t = Math.abs(d0)/( Math.abs(d0) + Math.abs(d1) ); + if (t == 0) + { + if (s1 > 0) // entering the material from the beginning of the line that is to be drawn + { + // see if the start point of the line is at a corner of the bounded plane + var lineDir = vecUtils.vecSubtract(3, pt1, pt0); + vecUtils.vecNormalize(3, lineDir); + var dist = vecUtils.vecDist( 3, pt0, bp1 ); + var bp2, bv0, bv1, cross1, cross2, cross3; + if ( MathUtils.fpSign(dist) == 0) + { + bp2 = boundaryPts[(i+1) % 4]; + bv0 = vecUtils.vecSubtract(3, bp2, bp1); + bv1 = vecUtils.vecSubtract(3, bp0, bp1); + cross1 = vecUtils.vecCross(3, bv0, lineDir); + cross2 = vecUtils.vecCross(3, lineDir, bv1); + cross3 = vecUtils.vecCross(3, bv0, bv1); + if ( (MathUtils.fpSign(vecUtils.vecDot(3, cross1, cross3)) == 0) && (MathUtils.fpSign(vecUtils.vecDot(3, cross2, cross3)) == 0)) + { + gotEnter = true; + this.addIntersection( plane, t, 1 ); + } + } + else if (MathUtils.fpSign( vecUtils.vecDist(3, pt0, bp0)) === 0) + { + bp2 = boundaryPts[(i+2) % 4]; + bv0 = vecUtils.vecSubtract(3, bp2, bp0); + bv1 = vecUtils.vecSubtract(3, bp1, bp0); + cross1 = vecUtils.vecCross(3, bv0, lineDir); + cross2 = vecUtils.vecCross(3, lineDir, bv1); + cross3 = vecUtils.vecCross(3, bv0, bv1); + if ( (MathUtils.fpSign(vecUtils.vecDot(3, cross1, cross3)) == 0) && (MathUtils.fpSign(vecUtils.vecDot(3, cross2, cross3)) == 0)) + { + gotEnter = true; + this.addIntersection( plane, t, 1 ); + } + } + else + { + // check if the line is on the edge of the boundary or goes to the interior + gotEnter = true; + this.addIntersection( plane, t, 1 ); + } + } + } + else if ( (MathUtils.fpSign(t) > 0) && (MathUtils.fpCmp(t,1.0) <= 0)) + { + // get the point where the line crosses the edge of the element plane + var pt = MathUtils.interpolateLine3D(pt0, pt1, t ); + + // we know that the line crosses the infinite extension of the edge. Determine + // if that crossing is within the bounds of the edge + var dot0 = vecUtils.vecDot(3, vecUtils.vecSubtract(3,pt, bp0), vec), + dot1 = vecUtils.vecDot(3, vecUtils.vecSubtract(3,pt, bp1), vec); + if ((MathUtils.fpSign(dot0) > 0) && (MathUtils.fpSign(dot1) < 0)) + { + // determine if the line is entering or exiting + if (s0 <= 0) // entering + { + if (!gotEnter) + { + gotEnter = true; + this.addIntersection( plane, t, 1 ); + } + } + else if (s0 > 0) // exiting + { + if (!gotExit) + { + gotExit = true; + this.addIntersection( plane, t, -1 ); + } + } + else // s0 == 0 + { + // TODO + } + } + else if ((MathUtils.fpSign(dot0) == 0) && (MathUtils.fpSign(dot1) < 0)) + { + var j = i - 2; + if (j < 0) j += 4; + var bp = boundaryPts[j]; + + var v0 = vecUtils.vecSubtract( 3, bp, bp0 ), + v1 = vec; + + if (s0 <= 0) + { + var v = vecUtils.vecSubtract(3, pt1, pt0); + if ((MathUtils.fpSign(vecUtils.vecCross(3, v0,v)) > 0) && (MathUtils.fpSign(vecUtils.vecCross(3, v,v1)) > 0)) + { + gotEnter = true; + this.addIntersection( plane, t, 1 ); + } + } + else if (s0 > 0) + { + var v = vecUtils.vecSubtract(3, pt0, pt1); // note the reversed order from the previous case + if ((MathUtils.fpSign(vecUtils.vecCross(3, v0,v)) > 0) && (MathUtils.fpSign(vecUtils.vecCross(3, v,v1)) > 0)) + { + gotEnter = true; + this.addIntersection( plane, t, -1 ); + } + } + } + else if ((MathUtils.fpSign(dot0) > 0) && (MathUtils.fpSign(dot1) == 0)) + { + var j = (i + 1) % 4; + var bp = boundaryPts[j]; + + var v1 = vec.slice(0), + v0 = vecUtils.vecSubtract( 3, bp, bp1 ), + v1 = vecUtils.vecNegate(3, v1); + + if (s0 <= 0) + { + var v = vecUtils.vecSubtract(3, pt1, pt0); + if ((MathUtils.fpSign(vecUtils.vecCross(3, v0,v)) < 0) && (MathUtils.fpSign(vecUtils.vecCross(3, v,v1)) < 0)) + { + gotEnter = true; + this.addIntersection( plane, t, 1 ); + } + } + else if (s0 > 0) + { + var v = vecUtils.vecSubtract(3, pt0, pt1); // note the reversed order from the previous case + if ((MathUtils.fpSign(vecUtils.vecCross(3, v0,v)) > 0) && (MathUtils.fpSign(vecUtils.vecCross(3, v,v1)) > 0)) + { + gotEnter = true; + this.addIntersection( plane, t, -1 ); + } + } + } + } + } + } + } + }, removeIntersections: { value: function() -- cgit v1.2.3 From 22e664cdbb4bdf54cde87c0c3223e321e18ea372 Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Tue, 19 Jun 2012 21:34:35 -0700 Subject: IKNINJA-1671 - GIO: 3D rotate widget is offset from the object when rotated in negative space. I fixed this temporarily by disabling the auto stage scroll calculations when we modify matrices. The correct fix will be to update any matrices and local2Global caches if we update the stage's padding (which I'm doing in a separate fix for a single draw cycle for the stage, but that fix is not ready yet). Signed-off-by: Nivesh Rajbhandari --- js/helper-classes/3D/draw-utils.js | 46 +++++++++++++++++++++++--------------- js/tools/SelectionTool.js | 17 +++++++++++++- 2 files changed, 44 insertions(+), 19 deletions(-) (limited to 'js') diff --git a/js/helper-classes/3D/draw-utils.js b/js/helper-classes/3D/draw-utils.js index 6a84c86b..177c844f 100755 --- a/js/helper-classes/3D/draw-utils.js +++ b/js/helper-classes/3D/draw-utils.js @@ -247,18 +247,18 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { // TODO - Check why handleElementChange is being fired before handleAddElement handleElementChange: { value: function(event) { - this._elementChangeHelper(event); + this._elementChangeHelper(event, false); } }, handleElementChanging: { value: function(event) { - this._elementChangeHelper(event); + this._elementChangeHelper(event, true); } }, _elementChangeHelper: { - value: function(event) { + value: function(event, isChanging) { if(!event.detail || !event.detail.data) { return; } @@ -273,35 +273,45 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { l, t, plane, - changed = false; + changed = false, + adjustStagePadding = !isChanging || (event.detail.data.prop !== "matrix"); for(var i=0; i < len; i++) { plane = els[i].elementModel.props3D.elementPlane; if(plane) { plane.init(); - l = plane._rect.m_left - docLeft; - t = plane._rect.m_top - docTop; - if(l < minLeft) { - minLeft = l; - } - if(t < minTop) { - minTop = t; + if(adjustStagePadding) { + l = plane._rect.m_left - docLeft; + t = plane._rect.m_top - docTop; + if(l < minLeft) { + minLeft = l; + } + if(t < minTop) { + minTop = t; + } } } } - if(minLeft !== stage.userPaddingLeft) { - stage.userPaddingLeft = minLeft; - changed = true; - } - if(minTop !== stage.userPaddingTop) { - stage.userPaddingTop = minTop; - changed = true; + if(adjustStagePadding) { + if(minLeft !== stage.userPaddingLeft) { + stage.userPaddingLeft = minLeft; + changed = true; + } + if(minTop !== stage.userPaddingTop) { + stage.userPaddingTop = minTop; + changed = true; + } } if(!changed) { this.drawWorkingPlane(); this.draw3DCompass(); } + + // TODO - Remove this once all stage drawing is consolidated into a single draw cycle + if(!isChanging) { + this.application.ninja.toolsData.selectedToolInstance.captureSelectionDrawn(null); + } } } }, diff --git a/js/tools/SelectionTool.js b/js/tools/SelectionTool.js index 8b644d4a..8c3a9a25 100755 --- a/js/tools/SelectionTool.js +++ b/js/tools/SelectionTool.js @@ -47,6 +47,20 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, { } }, + _areElementsIn2D : { + value: function () { + if(this.application.ninja.selectedElements.length) { + var len = this.application.ninja.selectedElements.length; + for(var i = 0; i < len; i++) { + if(!MathUtils.isIdentityMatrix(this.application.ninja.selectedElements[i].elementModel.getProperty("mat"))) { + return false; + } + } + } + return true; + } + }, + startDraw: { value: function(event) { this.drawData = null; @@ -70,7 +84,8 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, { if(this._canSnap) { this.initializeSnapping(event); - this._use3DMode = !this._areElementsOnSamePlane(); +// this._use3DMode = !this._areElementsOnSamePlane(); + this._use3DMode = !this._areElementsIn2D(); // console.log("use3DMode = " + this._use3DMode); } else -- cgit v1.2.3 From 7ca20cc617fb1f9d6d692b27e8bbb74f69693dcd Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Wed, 20 Jun 2012 11:30:06 -0700 Subject: Fixes: IKNINJA-1448 Improving logic on calculating position of the color stops in the gradient picker. --- .../gradientpicker.reel/gradientpicker.js | 67 +++++++--------------- 1 file changed, 20 insertions(+), 47 deletions(-) (limited to 'js') diff --git a/js/components/gradientpicker.reel/gradientpicker.js b/js/components/gradientpicker.reel/gradientpicker.js index 7fd5d918..6071f3c6 100755 --- a/js/components/gradientpicker.reel/gradientpicker.js +++ b/js/components/gradientpicker.reel/gradientpicker.js @@ -52,6 +52,11 @@ exports.GradientPicker = Montage.create(Component, { }, //////////////////////////////////////////////////////////////////// // + _trackData: { + value: {width: 0, x: 0, y: 0} + }, + //////////////////////////////////////////////////////////////////// + // prepareForDraw: { value: function() { // @@ -62,7 +67,7 @@ exports.GradientPicker = Montage.create(Component, { willDraw: { value: function() { //Getting component views from layout - this.element._trackWidth = parseInt(getComputedStyle(this.trackChips).getPropertyCSSValue('width').cssText); + this._trackData.width = parseInt(getComputedStyle(this.trackChips).getPropertyCSSValue('width').cssText); //TODO: Fix events and remove this hack this.trackCover.addEventListener('mouseover', function () { if (!this._updating) { @@ -83,13 +88,13 @@ exports.GradientPicker = Montage.create(Component, { // draw: { value: function() { - // + //Checking for mode to assign radio value if (this.mode === 'linear') { this.radioLinear.checked = 'true'; } else if (this.mode === 'radial') { this.radioRadial.checked = 'true'; } - // + //Checkign for value to initialize stops if (!this.value) { this.addDefaultStops(); } else { @@ -104,35 +109,17 @@ exports.GradientPicker = Montage.create(Component, { // didDraw: { value: function() { - // + //Adding event listener for stops this.trackMain.addEventListener('click', this, false); - - - - - - //////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////// - //TODO: Determing a better way to get screen position - var element = this.trackMain; - this.element._trackX = 0, this.element._trackY = 0; - // - while (element && !isNaN(element.offsetLeft) && !isNaN(element.offsetTop)) { - this.element._trackX += element.offsetLeft - element.scrollLeft; - this.element._trackY += element.offsetTop - element.scrollTop; - element = element.parentNode; - } - //////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////// - - //This is forever changing, not sure why - //console.log(this.element._trackX, this.element._trackY); - - + //Getting position of track + var point = webkitConvertPointFromNodeToPage(this.trackMain, new WebKitPoint(0, 0)); + //Setting position of track to calculate movement + this._trackData.x = point.x; + this._trackData.y = point.y; } }, //////////////////////////////////////////////////////////////////// - // + //Default stops funtion (reset) addDefaultStops: { value: function() { this.addStop({color: {mode: 'rgb', value: {r: 255, g: 255, b: 255, a: 1, css: 'rgb(255, 255, 255)'}}, percent: 0}, true); @@ -223,24 +210,10 @@ exports.GradientPicker = Montage.create(Component, { } else if (percent>100) { percent = 100; } - - - - - //////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////// - //TODO: toggling visibility because of a browser bug - stop.style.visibility = 'hidden'; //TODO: To be removed - var adj = (parseInt(getComputedStyle(stop).getPropertyCSSValue('width').cssText)*percent/100)/this.element._trackWidth; + // + var adj = (parseInt(getComputedStyle(stop).getPropertyCSSValue('width').cssText)*percent/100)/this._trackData.width; stop.style.left = Math.round(percent-Math.round(adj*100))+'%'; stop.button.stopPosition = percent; - stop.style.visibility = 'visible'; //TODO: To be removed - //////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////// - - - - } catch (e) { //TEMP } @@ -292,15 +265,15 @@ exports.GradientPicker = Montage.create(Component, { // this.application.ninja.colorController.colorPopupManager.hideColorChipPopup(); // - if ((e._event.y+this.hack.y) > this.element._trackY+70 || (e._event.y+this.hack.y) < this.element._trackY) { + if (e._event.y > this._trackData.y+70 || e._event.y < this._trackData.y) { this.removeStop(this.currentStop); } // - if (this.currentStop.button.stopPosition !== Math.round(((e._event.x+this.hack.x)-(this.element._trackX-23))/this.element._trackWidth*100)) { + if (this.currentStop.button.stopPosition !== Math.round((e._event.x-this._trackData.x)/this._trackData.width*100)) { this.trackCover.style.display = 'block'; } // - this.positionStop(this.currentStop, Math.round(((e._event.x+this.hack.x)-(this.element._trackX-23))/this.element._trackWidth*100)); + this.positionStop(this.currentStop, Math.round((e._event.x-this._trackData.x)/this._trackData.width*100)); } }, //////////////////////////////////////////////////////////////////// -- cgit v1.2.3 From 6a0a5f6e7dec5e8ced6e228e7bbfcc1181f46c26 Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Wed, 20 Jun 2012 11:55:55 -0700 Subject: Fix for error when using ZoomTool. Signed-off-by: Nivesh Rajbhandari --- js/helper-classes/3D/draw-utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js') diff --git a/js/helper-classes/3D/draw-utils.js b/js/helper-classes/3D/draw-utils.js index 177c844f..8ddd0d52 100755 --- a/js/helper-classes/3D/draw-utils.js +++ b/js/helper-classes/3D/draw-utils.js @@ -309,7 +309,7 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { } // TODO - Remove this once all stage drawing is consolidated into a single draw cycle - if(!isChanging) { + if(!isChanging && this.application.ninja.toolsData.selectedToolInstance.captureSelectionDrawn) { this.application.ninja.toolsData.selectedToolInstance.captureSelectionDrawn(null); } } -- cgit v1.2.3