diff options
Diffstat (limited to 'js/tools')
-rwxr-xr-x | js/tools/PenTool.js | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/js/tools/PenTool.js b/js/tools/PenTool.js index 0e3bd15c..ec63771a 100755 --- a/js/tools/PenTool.js +++ b/js/tools/PenTool.js | |||
@@ -71,6 +71,10 @@ exports.PenTool = Montage.create(ShapeTool, { | |||
71 | // todo this might be unnecessary as we can get this from element mediator (but that may be slow) | 71 | // todo this might be unnecessary as we can get this from element mediator (but that may be slow) |
72 | _selectedSubpathPlaneMat: { value: null, writable: true }, | 72 | _selectedSubpathPlaneMat: { value: null, writable: true }, |
73 | 73 | ||
74 | //bbox of the selected subpath in local coordinates | ||
75 | // (used for id-ing when the local center has shifted, i.e. the bbox of the subpath has grown) | ||
76 | _selectedSubpathLocalCenter: {value: null, writable: true}, | ||
77 | |||
74 | //the center of the subpath center in stageworld space | 78 | //the center of the subpath center in stageworld space |
75 | _selectedSubpathCanvasCenter: {value: null, writable: true}, | 79 | _selectedSubpathCanvasCenter: {value: null, writable: true}, |
76 | 80 | ||
@@ -208,6 +212,7 @@ exports.PenTool = Montage.create(ShapeTool, { | |||
208 | this._selectedSubpath = new SubPath(); | 212 | this._selectedSubpath = new SubPath(); |
209 | this._selectedSubpathCanvas = null; | 213 | this._selectedSubpathCanvas = null; |
210 | this._selectedSubpathPlaneMat = null; | 214 | this._selectedSubpathPlaneMat = null; |
215 | this._selectedSubpathLocalCenter = null; | ||
211 | this._isNewPath = true; | 216 | this._isNewPath = true; |
212 | 217 | ||
213 | if (this._entryEditMode === this.ENTRY_SELECT_PATH){ | 218 | if (this._entryEditMode === this.ENTRY_SELECT_PATH){ |
@@ -758,6 +763,7 @@ exports.PenTool = Montage.create(ShapeTool, { | |||
758 | for (d=0;d<3;d++){ | 763 | for (d=0;d<3;d++){ |
759 | if (bboxMax[d]-bboxMin[d]>this._MAX_CANVAS_DIMENSION){ | 764 | if (bboxMax[d]-bboxMin[d]>this._MAX_CANVAS_DIMENSION){ |
760 | canvasTooLarge = true; | 765 | canvasTooLarge = true; |
766 | break; | ||
761 | } | 767 | } |
762 | } | 768 | } |
763 | if (canvasTooLarge){ | 769 | if (canvasTooLarge){ |
@@ -773,11 +779,26 @@ exports.PenTool = Montage.create(ShapeTool, { | |||
773 | 779 | ||
774 | //convert the midpoint of this bbox to stage world space | 780 | //convert the midpoint of this bbox to stage world space |
775 | var bboxMid = VecUtils.vecInterpolate(3, bboxMin, bboxMax, 0.5); | 781 | var bboxMid = VecUtils.vecInterpolate(3, bboxMin, bboxMax, 0.5); |
782 | |||
783 | //sandwich the planeMat between with the translation to the previous center of the canvas in local space and its inverse | ||
784 | var centerDisp = VecUtils.vecSubtract(3, bboxMid, this._selectedSubpathLocalCenter); | ||
785 | var tMat = Matrix.Translation([centerDisp[0], centerDisp[1],centerDisp[2]]); | ||
786 | var tInvMat = Matrix.Translation([-centerDisp[0], -centerDisp[1], -centerDisp[2]]); | ||
787 | var newMat = Matrix.I(4); | ||
788 | glmat4.multiply( tInvMat, this._selectedSubpathPlaneMat, newMat); | ||
789 | glmat4.multiply( newMat, tMat, newMat); | ||
790 | this._selectedSubpathPlaneMat = newMat; | ||
791 | ViewUtils.setMatrixForElement(this._selectedSubpathCanvas, newMat, true); | ||
792 | |||
793 | |||
776 | //this._selectedSubpathCanvasCenter = ViewUtils.localToStageWorld(bboxMid, this._selectedSubpathCanvas); | 794 | //this._selectedSubpathCanvasCenter = ViewUtils.localToStageWorld(bboxMid, this._selectedSubpathCanvas); |
777 | var localToStageWorldMat = ViewUtils.getLocalToStageWorldMatrix(this._selectedSubpathCanvas, false, false); | 795 | var localToStageWorldMat = ViewUtils.getLocalToStageWorldMatrix(this._selectedSubpathCanvas, false, false); |
778 | this._selectedSubpathCanvasCenter = MathUtils.transformAndDivideHomogeneousPoint(bboxMid, localToStageWorldMat); | 796 | this._selectedSubpathCanvasCenter = MathUtils.transformAndDivideHomogeneousPoint(bboxMid, localToStageWorldMat); |
779 | this._selectedSubpathCanvasCenter[0]+= xAdjustment; | 797 | this._selectedSubpathCanvasCenter[0]+= xAdjustment; |
780 | this._selectedSubpathCanvasCenter[1]+= yAdjustment; | 798 | this._selectedSubpathCanvasCenter[1]+= yAdjustment; |
799 | |||
800 | |||
801 | |||
781 | } else { | 802 | } else { |
782 | //compute the bbox in stage-world space (the points are already in stage world space) | 803 | //compute the bbox in stage-world space (the points are already in stage world space) |
783 | this._selectedSubpath.createSamples(true); | 804 | this._selectedSubpath.createSamples(true); |
@@ -786,7 +807,7 @@ exports.PenTool = Montage.create(ShapeTool, { | |||
786 | this._selectedSubpathCanvasCenter = VecUtils.vecInterpolate(3, bboxMin, bboxMax, 0.5); | 807 | this._selectedSubpathCanvasCenter = VecUtils.vecInterpolate(3, bboxMin, bboxMax, 0.5); |
787 | 808 | ||
788 | //convert the path points into local coordinates by multiplying by the inverse of the plane mat | 809 | //convert the path points into local coordinates by multiplying by the inverse of the plane mat |
789 | for (i=0;i<numAnchors;i++){ | 810 | for (i=0;i<numAnchors;i++) { |
790 | currAnchor = this._selectedSubpath.getAnchor(i); | 811 | currAnchor = this._selectedSubpath.getAnchor(i); |
791 | swPos = [currAnchor.getPosX()-xAdjustment,currAnchor.getPosY()-yAdjustment,currAnchor.getPosZ()]; | 812 | swPos = [currAnchor.getPosX()-xAdjustment,currAnchor.getPosY()-yAdjustment,currAnchor.getPosZ()]; |
792 | swPrev = [currAnchor.getPrevX()-xAdjustment,currAnchor.getPrevY()-yAdjustment,currAnchor.getPrevZ()]; | 813 | swPrev = [currAnchor.getPrevX()-xAdjustment,currAnchor.getPrevY()-yAdjustment,currAnchor.getPrevZ()]; |
@@ -801,11 +822,16 @@ exports.PenTool = Montage.create(ShapeTool, { | |||
801 | } | 822 | } |
802 | } | 823 | } |
803 | 824 | ||
804 | //todo MISSING: sandwich the planeMat between with the translation to the previous center of the canvas in local space and its inverse | 825 | |
805 | 826 | ||
806 | this._selectedSubpath.makeDirty(); | 827 | this._selectedSubpath.makeDirty(); |
807 | this._selectedSubpath.createSamples(false); | 828 | this._selectedSubpath.createSamples(false); |
808 | this._selectedSubpath.offsetPerBBoxMin(); | 829 | this._selectedSubpath.offsetPerBBoxMin(); |
830 | bboxMin = this._selectedSubpath.getBBoxMin(); | ||
831 | bboxMax = this._selectedSubpath.getBBoxMax(); | ||
832 | |||
833 | //compute and store the center of the bbox in local space | ||
834 | this._selectedSubpathLocalCenter = VecUtils.vecInterpolate(3, bboxMin, bboxMax, 0.5); | ||
809 | } | 835 | } |
810 | }, | 836 | }, |
811 | 837 | ||