aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-rwxr-xr-xjs/document/html-document.js6
-rwxr-xr-xjs/helper-classes/3D/snap-manager.js2
-rwxr-xr-xjs/lib/drawing/world.js6
-rwxr-xr-xjs/lib/geom/brush-stroke.js80
-rwxr-xr-xjs/lib/geom/geom-obj.js1
5 files changed, 67 insertions, 28 deletions
diff --git a/js/document/html-document.js b/js/document/html-document.js
index 8f9d2870..42a7d537 100755
--- a/js/document/html-document.js
+++ b/js/document/html-document.js
@@ -340,6 +340,12 @@ exports.HTMLDocument = Montage.create(TextDocument, {
340 shapeModel.slope = root._slope; 340 shapeModel.slope = root._slope;
341 break; 341 break;
342 342
343 case root.GEOM_TYPE_BRUSH_STROKE:
344 elementModel.selection = "BrushStroke";
345 elementModel.pi = "BrushStrokePi";
346 break;
347
348
343 default: 349 default:
344 console.log( "geometry type not supported for file I/O, " + root.geomType()); 350 console.log( "geometry type not supported for file I/O, " + root.geomType());
345 break; 351 break;
diff --git a/js/helper-classes/3D/snap-manager.js b/js/helper-classes/3D/snap-manager.js
index a755e9e2..5b467b41 100755
--- a/js/helper-classes/3D/snap-manager.js
+++ b/js/helper-classes/3D/snap-manager.js
@@ -1411,6 +1411,8 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
1411 case glObj.GEOM_TYPE_PATH: 1411 case glObj.GEOM_TYPE_PATH:
1412 // Snapping not implemented for these type, but don't throw an error... 1412 // Snapping not implemented for these type, but don't throw an error...
1413 break; 1413 break;
1414 case glObj.GEOM_TYPE_BRUSH_STROKE:
1415 break; //don't throw error because snapping not yet implemented
1414 case glObj.GEOM_TYPE_CUBIC_BEZIER: 1416 case glObj.GEOM_TYPE_CUBIC_BEZIER:
1415 { 1417 {
1416 var nearVrt = glObj.getNearVertex( eyePt, dir ); 1418 var nearVrt = glObj.getNearVertex( eyePt, dir );
diff --git a/js/lib/drawing/world.js b/js/lib/drawing/world.js
index 781695b6..1552178d 100755
--- a/js/lib/drawing/world.js
+++ b/js/lib/drawing/world.js
@@ -931,6 +931,7 @@ World.prototype.importObjectsJSON = function( jObj, parentGeomObj )
931World.prototype.importObjectJSON = function( jObj, parentGeomObj ) 931World.prototype.importObjectJSON = function( jObj, parentGeomObj )
932{ 932{
933 var type = jObj.type; 933 var type = jObj.type;
934 var BrushStroke = require("js/lib/geom/brush-stroke").BrushStroke;
934 935
935 var obj; 936 var obj;
936 switch (type) 937 switch (type)
@@ -950,6 +951,11 @@ World.prototype.importObjectJSON = function( jObj, parentGeomObj )
950 obj.importJSON( jObj ); 951 obj.importJSON( jObj );
951 break; 952 break;
952 953
954 case 6: //brush stroke
955 obj = new BrushStroke();
956 obj.importJSON(jObj);
957 break;
958
953 default: 959 default:
954 throw new Error( "Unrecognized object type: " + type ); 960 throw new Error( "Unrecognized object type: " + type );
955 break; 961 break;
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