aboutsummaryrefslogtreecommitdiff
path: root/js/lib/geom/brush-stroke.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/geom/brush-stroke.js')
-rwxr-xr-xjs/lib/geom/brush-stroke.js80
1 files changed, 52 insertions, 28 deletions
diff --git a/js/lib/geom/brush-stroke.js b/js/lib/geom/brush-stroke.js
index 9c8822a7..d849e3d7 100755
--- a/js/lib/geom/brush-stroke.js
+++ b/js/lib/geom/brush-stroke.js
@@ -20,10 +20,10 @@ var BrushStroke = function GLBrushStroke() {
20 /////////////////////////////////////////////////// 20 ///////////////////////////////////////////////////
21 // Instance variables 21 // Instance variables
22 /////////////////////////////////////////////////// 22 ///////////////////////////////////////////////////
23 this._Points = []; //current state of points in stage-world space (may be different from input) 23 this._Points = []; //current state of points in stage-world space (may be different from input)
24 this._OrigPoints = []; //copy of input points without any smoothing 24 this._LocalPoints = []; //_Points in local coordinates...do this before rendering the points in the canvas
25 this._LocalPoints = []; //_Points in local coordinates...do this before rendering the points in the canvas 25 this._OrigLocalPoints = []; //copy of input points without any smoothing
26 this._stageWorldCenter = [0,0,0]; //coordinate for the canvas midPoint: a 3D vector in stage world space 26 this._stageWorldCenter = [0,0,0]; //coordinate for the canvas midPoint: a 3D vector in stage world space
27 this._BBoxMin = [0, 0, 0]; 27 this._BBoxMin = [0, 0, 0];
28 this._BBoxMax = [0, 0, 0]; 28 this._BBoxMax = [0, 0, 0];
29 this._isDirty = true; 29 this._isDirty = true;
@@ -79,7 +79,7 @@ var BrushStroke = function GLBrushStroke() {
79 }; 79 };
80 80
81 this.geomType = function () { 81 this.geomType = function () {
82 return this.GEOM_TYPE_CUBIC_BEZIER; 82 return this.GEOM_TYPE_BRUSH_STROKE;
83 }; 83 };
84 84
85 this.setDrawingTool = function (tool) { 85 this.setDrawingTool = function (tool) {
@@ -107,7 +107,10 @@ var BrushStroke = function GLBrushStroke() {
107 }; 107 };
108 108
109 this.getNumPoints = function () { 109 this.getNumPoints = function () {
110 return this._Points.length; 110 if (this._LocalPoints.length)
111 return this._LocalPoints.length;
112 else
113 return this._Points.length;
111 }; 114 };
112 115
113 this.getPoint = function (index) { 116 this.getPoint = function (index) {
@@ -283,7 +286,7 @@ var BrushStroke = function GLBrushStroke() {
283 //remove all the points 286 //remove all the points
284 this.clear = function () { 287 this.clear = function () {
285 this._Points = []; 288 this._Points = [];
286 this._OrigPoints = []; 289 this._OrigLocalPoints = [];
287 this._isDirty=true; 290 this._isDirty=true;
288 this._isInit = false; 291 this._isInit = false;
289 }; 292 };
@@ -404,13 +407,13 @@ var BrushStroke = function GLBrushStroke() {
404 this._updateBoundingBox(); //compute the bbox to obtain the width and height used below 407 this._updateBoundingBox(); //compute the bbox to obtain the width and height used below
405 var halfwidth = 0.5*(this._BBoxMax[0]-this._BBoxMin[0]); 408 var halfwidth = 0.5*(this._BBoxMax[0]-this._BBoxMin[0]);
406 var halfheight = 0.5*(this._BBoxMax[1]-this._BBoxMin[1]); 409 var halfheight = 0.5*(this._BBoxMax[1]-this._BBoxMin[1]);
407 this._OrigPoints = []; 410 this._OrigLocalPoints = [];
408 for (i=0;i<numPoints;i++) { 411 for (i=0;i<numPoints;i++) {
409 this._LocalPoints[i][0]+= halfwidth; 412 this._LocalPoints[i][0]+= halfwidth;
410 this._LocalPoints[i][1]+= halfheight; 413 this._LocalPoints[i][1]+= halfheight;
411 414
412 //store the original points 415 //store the original points
413 this._OrigPoints.push([this._LocalPoints[i][0],this._LocalPoints[i][1],this._LocalPoints[i][2]]); 416 this._OrigLocalPoints .push([this._LocalPoints[i][0],this._LocalPoints[i][1],this._LocalPoints[i][2]]);
414 } 417 }
415 //update the bbox with the same adjustment as was made for the local points above 418 //update the bbox with the same adjustment as was made for the local points above
416 this._BBoxMax[0]+= halfwidth;this._BBoxMin[0]+= halfwidth; 419 this._BBoxMax[0]+= halfwidth;this._BBoxMin[0]+= halfwidth;
@@ -452,7 +455,7 @@ var BrushStroke = function GLBrushStroke() {
452 this._doSmoothing = function() { 455 this._doSmoothing = function() {
453 var numPoints = this._LocalPoints.length; 456 var numPoints = this._LocalPoints.length;
454 if (this._strokeDoSmoothing && numPoints>1) { 457 if (this._strokeDoSmoothing && numPoints>1) {
455 this._copyCoordinates3D(this._OrigPoints, this._LocalPoints); 458 this._copyCoordinates3D(this._OrigLocalPoints , this._LocalPoints);
456 //iterations of Laplacian smoothing (setting the points to the average of their neighbors) 459 //iterations of Laplacian smoothing (setting the points to the average of their neighbors)
457 var numLaplacianIterations = this._strokeAmountSmoothing; 460 var numLaplacianIterations = this._strokeAmountSmoothing;
458 for (var n=0;n<numLaplacianIterations;n++){ 461 for (var n=0;n<numLaplacianIterations;n++){
@@ -648,20 +651,32 @@ var BrushStroke = function GLBrushStroke() {
648 651
649 this.exportJSON = function(){ 652 this.exportJSON = function(){
650 var retObject= new Object(); 653 var retObject= new Object();
651 retObject.geomType = this.geomType(); 654 //the type of this object
652 retObject.points = this._Points; 655 retObject.type = this.geomType();
653 retObject.planeCenter = this._planeCenter; 656 retObject.geomType = retObject.type;
654 retObject.planeMat = this._planeMat; 657
655 retObject.planeMatInv = this._planeMatInv; 658 //the geometry for this object
659 retObject.localPoints = this._LocalPoints.slice(0);
660 this._copyCoordinates3D(this._LocalPoints, retObject.localPoints); //todo is this necessary in addition to the slice(0) above?
661 retObject.origLocalPoints = this._OrigLocalPoints.slice(0);
662 this._copyCoordinates3D(this._OrigLocalPoints, retObject.origLocalPoints); //todo <ditto>
663
664 retObject.stageWorldCenter = [this._stageWorldCenter[0],this._stageWorldCenter[1],this._stageWorldCenter[2]];
665 retObject.planeMat = [this._planeMat[0],this._planeMat[1],this._planeMat[2],this._planeMat[3]];
666 retObject.planeMatInv = [this._planeMatInv[0],this._planeMatInv[1],this._planeMatInv[2],this._planeMatInv[3]];
667 retObject.dragPlane = [this._dragPlane[0],this._dragPlane[1],this._dragPlane[2],this._dragPlane[3]];
668
669 //stroke appearance properties
656 retObject.strokeWidth = this._strokeWidth; 670 retObject.strokeWidth = this._strokeWidth;
657 retObject.strokeColor = this._strokeColor; 671 retObject.strokeColor = this._strokeColor;
658 retObject.secondStrokeColor = this._secondStrokeColor;
659 retObject.strokeHardness = this._strokeHardness; 672 retObject.strokeHardness = this._strokeHardness;
660 retObject.strokeDoSmoothing = this._strokeDoSmoothing;
661 retObject.strokeUseCalligraphic = this._strokeUseCalligraphic; 673 retObject.strokeUseCalligraphic = this._strokeUseCalligraphic;
662 retObject.strokeAngle = this._strokeAngle; 674 retObject.strokeAngle = this._strokeAngle;
675
676 //stroke smoothing properties
677 retObject.strokeDoSmoothing = this._strokeDoSmoothing;
663 retObject.strokeAmountSmoothing = this._strokeAmountSmoothing; 678 retObject.strokeAmountSmoothing = this._strokeAmountSmoothing;
664 retObject.addedSamples = this._addedSamples; 679
665 return retObject; 680 return retObject;
666 }; 681 };
667 682
@@ -669,22 +684,31 @@ var BrushStroke = function GLBrushStroke() {
669 if (this.geomType()!== jo.geomType){ 684 if (this.geomType()!== jo.geomType){
670 return; 685 return;
671 } 686 }
672 this._Points = jo.points.splice(0); //todo is this splice necessary? 687 //the geometry for this object
673 this._planeCenter = jo.planeCenter; 688 this._LocalPoints = jo.localPoints.slice(0);
674 this._planeMat = jo.planeMat; 689 this._copyCoordinates3D(jo.localPoints, this._LocalPoints); //todo is this necessary in addition to the slice(0) above?
675 this._planeMatInv = jo.planeMatInv ; 690 this._OrigLocalPoints = jo.origLocalPoints.slice(0);
691 this._copyCoordinates3D(jo.origLocalPoints, this._OrigLocalPoints); //todo <ditto>
692
693 this._stageWorldCenter = [jo.stageWorldCenter[0],jo.stageWorldCenter[1],jo.stageWorldCenter[2]];
694 this._planeMat = [jo.planeMat[0], jo.planeMat[1],jo.planeMat[2],jo.planeMat[3]];
695 this._planeMatInv = [jo.planeMatInv[0],jo.planeMatInv[1],jo.planeMatInv[2],jo.planeMatInv[3]];
696 this._dragPlane = [jo.dragPlane[0],jo.dragPlane[1],jo.dragPlane[2],jo.dragPlane[3]];
697
698 //stroke appearance properties
676 this._strokeWidth = jo.strokeWidth; 699 this._strokeWidth = jo.strokeWidth;
677 this._strokeColor = jo.strokeColor; 700 this._strokeColor = jo.strokeColor;
678 this._secondStrokeColor = jo.secondStrokeColor;
679 this._strokeHardness = jo.strokeHardness; 701 this._strokeHardness = jo.strokeHardness;
680 this._strokeDoSmoothing = jo.strokeDoSmoothing;
681 this._strokeUseCalligraphic = jo.strokeUseCalligraphic; 702 this._strokeUseCalligraphic = jo.strokeUseCalligraphic;
682 this._strokeAngle = jo.strokeAngle; 703 this._strokeAngle = jo.strokeAngle;
704
705 //stroke smoothing properties
706 this._strokeDoSmoothing = jo.strokeDoSmoothing;
683 this._strokeAmountSmoothing = jo.strokeAmountSmoothing; 707 this._strokeAmountSmoothing = jo.strokeAmountSmoothing;
684 this._addedSamples = jo.addedSamples;
685 708
686 //force a re-computation of meta-geometry before rendering 709 this._isInit = true; //do not re-initialize this brush stroke
687 this._isDirty = true; 710 this._isDirty = true; //force a re-computation of meta-geometry before rendering
711 this.update(); //after this, the stroke is ready to be rendered
688 }; 712 };
689 713
690 714