aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorPushkar Joshi2012-04-18 09:47:26 -0700
committerPushkar Joshi2012-04-18 09:47:26 -0700
commit38ae1158abe94f917dbf375e73e1a9f0f68a61e8 (patch)
tree8f18fbe86a257472202ff92250737ee541b7c9cf /js
parent5bac19550ae74bb5561d1e1fbb55bdac8c5e3dd1 (diff)
downloadninja-38ae1158abe94f917dbf375e73e1a9f0f68a61e8.tar.gz
allow drawing polylines in YZ and XZ planes as well as XY. In those planes, still have bug with shift when the bbox of the path grows (due to missing translation)
Diffstat (limited to 'js')
-rwxr-xr-xjs/lib/geom/sub-path.js6
-rwxr-xr-xjs/tools/PenTool.js28
2 files changed, 29 insertions, 5 deletions
diff --git a/js/lib/geom/sub-path.js b/js/lib/geom/sub-path.js
index 7e11bb33..2ecafa1c 100755
--- a/js/lib/geom/sub-path.js
+++ b/js/lib/geom/sub-path.js
@@ -95,6 +95,11 @@ var GLSubpath = function GLSubpath() {
95 } 95 }
96 this.createSamples(false); //dirty bit checked in this function...will generate a polyline representation 96 this.createSamples(false); //dirty bit checked in this function...will generate a polyline representation
97 97
98 var numPoints = this._Samples.length;
99 if (numPoints === 0){
100 return; //nothing to do for empty paths
101 }
102
98 //figure the size of the area we will draw into 103 //figure the size of the area we will draw into
99 var bboxWidth=0, bboxHeight=0; 104 var bboxWidth=0, bboxHeight=0;
100 bboxWidth = this._BBoxMax[0] - this._BBoxMin[0]; 105 bboxWidth = this._BBoxMax[0] - this._BBoxMin[0];
@@ -142,7 +147,6 @@ var GLSubpath = function GLSubpath() {
142 147
143 148
144 ctx.beginPath(); 149 ctx.beginPath();
145 var numPoints = this._Samples.length;
146 ctx.moveTo(this._Samples[0][0],this._Samples[0][1]); 150 ctx.moveTo(this._Samples[0][0],this._Samples[0][1]);
147 for (var i=0;i<numPoints;i++){ 151 for (var i=0;i<numPoints;i++){
148 ctx.lineTo(this._Samples[i][0],this._Samples[i][1]); 152 ctx.lineTo(this._Samples[i][0],this._Samples[i][1]);
diff --git a/js/tools/PenTool.js b/js/tools/PenTool.js
index 8abb41ef..0e3bd15c 100755
--- a/js/tools/PenTool.js
+++ b/js/tools/PenTool.js
@@ -726,17 +726,23 @@ exports.PenTool = Montage.create(ShapeTool, {
726 }, 726 },
727 727
728 //prepare the selected subpath 728 //prepare the selected subpath
729 // convert the anchor points to stage world space (assume that's already the case if there is no subpath canvas)
730 // compute the center of the future canvas of this subpath in stage world space 729 // compute the center of the future canvas of this subpath in stage world space
731 // convert the anchor points from stage world to local space of the canvas 730 // compute local coordinates for the subpath (in case it does not have a canvas)
732 PrepareSelectedSubpathForRendering: { 731 PrepareSelectedSubpathForRendering: {
733 value: function(){ 732 value: function(){
734 var i=0,d=0; 733 var i=0,d=0;
735 var currAnchor = null; 734 var currAnchor = null;
736 var xAdjustment = snapManager.getStageWidth()*0.5; 735 var xAdjustment = snapManager.getStageWidth()*0.5;
737 var yAdjustment = snapManager.getStageHeight()*0.5; 736 var yAdjustment = snapManager.getStageHeight()*0.5;
737 var swPos=null, swPrev=null, swNext=null;
738 var localPos=null, localPrev=null, localNext=null;
738 739
739 var numAnchors = this._selectedSubpath.getNumAnchors(); 740 var numAnchors = this._selectedSubpath.getNumAnchors();
741 if (numAnchors<2){
742 return;//nothing to do
743 }
744 this._selectedSubpath.makeDirty();
745
740 var bboxMin=null, bboxMax=null; 746 var bboxMin=null, bboxMax=null;
741 if (this._selectedSubpathCanvas) { 747 if (this._selectedSubpathCanvas) {
742 //if there already is a subpath canvas, it means the anchor points are in local space 748 //if there already is a subpath canvas, it means the anchor points are in local space
@@ -779,10 +785,24 @@ exports.PenTool = Montage.create(ShapeTool, {
779 bboxMax = this._selectedSubpath.getBBoxMax(); 785 bboxMax = this._selectedSubpath.getBBoxMax();
780 this._selectedSubpathCanvasCenter = VecUtils.vecInterpolate(3, bboxMin, bboxMax, 0.5); 786 this._selectedSubpathCanvasCenter = VecUtils.vecInterpolate(3, bboxMin, bboxMax, 0.5);
781 787
782 //todo convert the path points into local coordinates 788 //convert the path points into local coordinates by multiplying by the inverse of the plane mat
783 789 for (i=0;i<numAnchors;i++){
790 currAnchor = this._selectedSubpath.getAnchor(i);
791 swPos = [currAnchor.getPosX()-xAdjustment,currAnchor.getPosY()-yAdjustment,currAnchor.getPosZ()];
792 swPrev = [currAnchor.getPrevX()-xAdjustment,currAnchor.getPrevY()-yAdjustment,currAnchor.getPrevZ()];
793 swNext = [currAnchor.getNextX()-xAdjustment,currAnchor.getNextY()-yAdjustment,currAnchor.getNextZ()];
794 var planeMatInv = glmat4.inverse(this._selectedSubpathPlaneMat, []);
795 localPos = MathUtils.transformAndDivideHomogeneousPoint(swPos, planeMatInv);
796 localPrev = MathUtils.transformAndDivideHomogeneousPoint(swPrev, planeMatInv);
797 localNext = MathUtils.transformAndDivideHomogeneousPoint(swNext, planeMatInv);
798 currAnchor.setPos(localPos[0],localPos[1],localPos[2]);
799 currAnchor.setPrevPos(localPrev[0],localPrev[1],localPrev[2]);
800 currAnchor.setNextPos(localNext[0],localNext[1],localNext[2]);
801 }
784 } 802 }
785 803
804 //todo MISSING: sandwich the planeMat between with the translation to the previous center of the canvas in local space and its inverse
805
786 this._selectedSubpath.makeDirty(); 806 this._selectedSubpath.makeDirty();
787 this._selectedSubpath.createSamples(false); 807 this._selectedSubpath.createSamples(false);
788 this._selectedSubpath.offsetPerBBoxMin(); 808 this._selectedSubpath.offsetPerBBoxMin();