aboutsummaryrefslogtreecommitdiff
path: root/js/lib
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib')
-rwxr-xr-xjs/lib/drawing/world.js7
-rwxr-xr-xjs/lib/geom/brush-stroke.js16
-rwxr-xr-xjs/lib/geom/sub-path.js830
3 files changed, 300 insertions, 553 deletions
diff --git a/js/lib/drawing/world.js b/js/lib/drawing/world.js
index 945c9883..1a391338 100755
--- a/js/lib/drawing/world.js
+++ b/js/lib/drawing/world.js
@@ -866,7 +866,7 @@ World.prototype.importObjectJSON = function( jObj, parentGeomObj )
866{ 866{
867 var type = jObj.type; 867 var type = jObj.type;
868 var BrushStroke = require("js/lib/geom/brush-stroke").BrushStroke; 868 var BrushStroke = require("js/lib/geom/brush-stroke").BrushStroke;
869 869 var SubPath = require("js/lib/geom/sub-path").SubPath;
870 var obj; 870 var obj;
871 switch (type) 871 switch (type)
872 { 872 {
@@ -885,6 +885,11 @@ World.prototype.importObjectJSON = function( jObj, parentGeomObj )
885 obj.importJSON( jObj ); 885 obj.importJSON( jObj );
886 break; 886 break;
887 887
888 case 5: //cubic bezier
889 obj = new SubPath();
890 obj.importJSON(jObj);
891 break;
892
888 case 6: //brush stroke 893 case 6: //brush stroke
889 obj = new BrushStroke(); 894 obj = new BrushStroke();
890 obj.importJSON(jObj); 895 obj.importJSON(jObj);
diff --git a/js/lib/geom/brush-stroke.js b/js/lib/geom/brush-stroke.js
index 26ac42e9..8c5ffef3 100755
--- a/js/lib/geom/brush-stroke.js
+++ b/js/lib/geom/brush-stroke.js
@@ -413,7 +413,7 @@ var BrushStroke = function GLBrushStroke() {
413 this._LocalPoints[i][1]+= halfheight; 413 this._LocalPoints[i][1]+= halfheight;
414 414
415 //store the original points 415 //store the original points
416 this._OrigLocalPoints .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]]);
417 } 417 }
418 //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
419 this._BBoxMax[0]+= halfwidth;this._BBoxMin[0]+= halfwidth; 419 this._BBoxMax[0]+= halfwidth;this._BBoxMin[0]+= halfwidth;
@@ -541,6 +541,10 @@ var BrushStroke = function GLBrushStroke() {
541 var bboxWidth = bboxMax[0] - bboxMin[0]; 541 var bboxWidth = bboxMax[0] - bboxMin[0];
542 var bboxHeight = bboxMax[1] - bboxMin[1]; 542 var bboxHeight = bboxMax[1] - bboxMin[1];
543 543
544 if (!this._canvas){
545 //set the canvas by querying the world
546 this._canvas = this.getWorld().getCanvas();
547 }
544 if (this._canvas) { 548 if (this._canvas) {
545 var newLeft = Math.round(this._stageWorldCenter[0] - 0.5 * bboxWidth); 549 var newLeft = Math.round(this._stageWorldCenter[0] - 0.5 * bboxWidth);
546 var newTop = Math.round(this._stageWorldCenter[1] - 0.5 * bboxHeight); 550 var newTop = Math.round(this._stageWorldCenter[1] - 0.5 * bboxHeight);
@@ -550,7 +554,7 @@ var BrushStroke = function GLBrushStroke() {
550 554
551 CanvasController.setProperty(this._canvas, "width", bboxWidth+"px"); 555 CanvasController.setProperty(this._canvas, "width", bboxWidth+"px");
552 CanvasController.setProperty(this._canvas, "height", bboxHeight+"px"); 556 CanvasController.setProperty(this._canvas, "height", bboxHeight+"px");
553 this._canvas.elementModel.shapeModel.GLWorld.setViewportFromCanvas(this._canvas); 557 //this._canvas.elementModel.shapeModel.GLWorld.setViewportFromCanvas(this._canvas);
554 } 558 }
555 559
556 560
@@ -662,8 +666,8 @@ var BrushStroke = function GLBrushStroke() {
662 this._copyCoordinates3D(this._OrigLocalPoints, retObject.origLocalPoints); //todo <ditto> 666 this._copyCoordinates3D(this._OrigLocalPoints, retObject.origLocalPoints); //todo <ditto>
663 667
664 retObject.stageWorldCenter = [this._stageWorldCenter[0],this._stageWorldCenter[1],this._stageWorldCenter[2]]; 668 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]]; 669 retObject.planeMat = this._planeMat;
666 retObject.planeMatInv = [this._planeMatInv[0],this._planeMatInv[1],this._planeMatInv[2],this._planeMatInv[3]]; 670 retObject.planeMatInv = this._planeMatInv;
667 retObject.dragPlane = [this._dragPlane[0],this._dragPlane[1],this._dragPlane[2],this._dragPlane[3]]; 671 retObject.dragPlane = [this._dragPlane[0],this._dragPlane[1],this._dragPlane[2],this._dragPlane[3]];
668 672
669 //stroke appearance properties 673 //stroke appearance properties
@@ -691,8 +695,8 @@ var BrushStroke = function GLBrushStroke() {
691 this._copyCoordinates3D(jo.origLocalPoints, this._OrigLocalPoints); //todo <ditto> 695 this._copyCoordinates3D(jo.origLocalPoints, this._OrigLocalPoints); //todo <ditto>
692 696
693 this._stageWorldCenter = [jo.stageWorldCenter[0],jo.stageWorldCenter[1],jo.stageWorldCenter[2]]; 697 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]]; 698 this._planeMat = jo.planeMat;
695 this._planeMatInv = [jo.planeMatInv[0],jo.planeMatInv[1],jo.planeMatInv[2],jo.planeMatInv[3]]; 699 this._planeMatInv = jo.planeMatInv;
696 this._dragPlane = [jo.dragPlane[0],jo.dragPlane[1],jo.dragPlane[2],jo.dragPlane[3]]; 700 this._dragPlane = [jo.dragPlane[0],jo.dragPlane[1],jo.dragPlane[2],jo.dragPlane[3]];
697 701
698 //stroke appearance properties 702 //stroke appearance properties
diff --git a/js/lib/geom/sub-path.js b/js/lib/geom/sub-path.js
index 7046673e..7e11bb33 100755
--- a/js/lib/geom/sub-path.js
+++ b/js/lib/geom/sub-path.js
@@ -11,29 +11,6 @@ var GeomObj = require("js/lib/geom/geom-obj").GeomObj;
11var AnchorPoint = require("js/lib/geom/anchor-point").AnchorPoint; 11var AnchorPoint = require("js/lib/geom/anchor-point").AnchorPoint;
12var MaterialsModel = require("js/models/materials-model").MaterialsModel; 12var MaterialsModel = require("js/models/materials-model").MaterialsModel;
13 13
14// TODO Those function do not seems to be used. We should remove them
15function SubpathOffsetPoint(pos, mapPos) {
16 this.Pos = [pos[0],pos[1],pos[2]];
17 this.CurveMapPos = [mapPos[0], mapPos[1], mapPos[2]];
18}
19
20function SubpathOffsetTriangle(v0, v1, v2) {
21 this.v0 = v0;
22 this.v1 = v1;
23 this.v2 = v2;
24 this.n = [0,0,1]; //replace with the actual cross product later
25}
26
27function sortNumberAscending(a,b){
28 return a-b;
29}
30function sortNumberDescending(a,b){
31 return b-a;
32}
33function SegmentIntersections(){
34 this.paramArray = [];
35}
36
37/////////////////////////////////////////////////////////////////////// 14///////////////////////////////////////////////////////////////////////
38// Class GLSubpath 15// Class GLSubpath
39// representation a sequence of cubic bezier curves. 16// representation a sequence of cubic bezier curves.
@@ -44,49 +21,40 @@ var GLSubpath = function GLSubpath() {
44 /////////////////////////////////////////////////// 21 ///////////////////////////////////////////////////
45 // Instance variables 22 // Instance variables
46 /////////////////////////////////////////////////// 23 ///////////////////////////////////////////////////
24
25 // NOTE:
26 // This class contains functionality to store piecewise cubic bezier paths.
27 // The coordinates of the paths are always in local, canvas space.
28 // That is, the Z coordinate can be ignored (for now), and the paths are essentially in 2D.
29 // All coordinates of the '_Samples' should lie within [0,0] and [width, height],
30 // where width and height refer to the dimensions of the canvas for this path.
31 // Whenever the the canvas dimensions change, the coordinates of the anchor points
32 // and _Samples must be re-computed.
33
47 this._Anchors = []; 34 this._Anchors = [];
48 this._BBoxMin = [0, 0, 0]; 35 this._BBoxMin = [0, 0, 0];
49 this._BBoxMax = [0, 0, 0]; 36 this._BBoxMax = [0, 0, 0];
50 this._isClosed = false; 37 this._isClosed = false;
51 38
52 this._samples = []; //polyline representation of this curve 39 this._Samples = []; //polyline representation of this curve in canvas space
53 this._sampleParam = []; //parametric distance of samples, within [0, N], where N is # of Bezier curves (=# of anchor points if closed, =#anchor pts -1 if open) 40 this._sampleParam = []; //parametric distance of samples, within [0, N], where N is # of Bezier curves (=# of anchor points if closed, =#anchor pts -1 if open)
54 this._anchorSampleIndex = []; //index within _samples corresponding to anchor points 41 this._anchorSampleIndex = []; //index within _Samples corresponding to anchor points
55
56 this._UnprojectedAnchors = [];
57 42
58 //initially set the _dirty bit so we will construct samples 43 //initially set the _dirty bit so we will re-construct _Anchors and _Samples
59 this._dirty = true; 44 this._dirty = true;
60 45
61 //whether or not to use the canvas drawing to stroke/fill
62 this._useCanvasDrawing = true;
63
64 //the canvas that will draw this subpath
65 this._canvas = null;
66
67 //the X and Y location of this subpath's canvas in stage world space of Ninja
68 this._canvasX = 0;
69 this._canvasY = 0;
70
71 //stroke information 46 //stroke information
72 this._strokeWidth = 0.0; 47 this._strokeWidth = 1.0;
73 this._strokeColor = [0.4, 0.4, 0.4, 1.0]; 48 this._strokeColor = [0.4, 0.4, 0.4, 1.0];
74 this._strokeMaterial = null
75 this._strokeStyle = "Solid";
76 this._materialAmbient = [0.2, 0.2, 0.2, 1.0];
77 this._materialDiffuse = [0.4, 0.4, 0.4, 1.0];
78 this._materialSpecular = [0.4, 0.4, 0.4, 1.0];
79 this._fillColor = [1.0, 1.0, 1.0, 0.0]; 49 this._fillColor = [1.0, 1.0, 1.0, 0.0];
80 this._fillMaterial = null;
81 this._DISPLAY_ANCHOR_RADIUS = 5; 50 this._DISPLAY_ANCHOR_RADIUS = 5;
51
82 //drawing context 52 //drawing context
83 this._world = null; 53 this._world = null;
54 this._canvas = null; //todo this might be unnecessary (but faster) since we can get it from the world
84 55
85 //tool that owns this subpath 56 //tool that owns this subpath
86 this._drawingTool = null; 57 this._drawingTool = null;
87 this._planeMat = null;
88 this._planeMatInv = null;
89 this._planeCenter = null;
90 58
91 //used to query what the user selected, OR-able for future extensions 59 //used to query what the user selected, OR-able for future extensions
92 this.SEL_NONE = 0; //nothing was selected 60 this.SEL_NONE = 0; //nothing was selected
@@ -98,8 +66,6 @@ var GLSubpath = function GLSubpath() {
98 this._selectedAnchorIndex = -1; 66 this._selectedAnchorIndex = -1;
99 67
100 this._SAMPLING_EPSILON = 0.5; //epsilon used for sampling the curve 68 this._SAMPLING_EPSILON = 0.5; //epsilon used for sampling the curve
101 this._DEFAULT_STROKE_WIDTH = 20; //use only if stroke width not specified
102 this._MAX_OFFSET_ANGLE = 10; //max angle (in degrees) between consecutive vectors from curve to offset path
103 69
104 // (current GeomObj complains if buildBuffers/render is added to GLSubpath prototype) 70 // (current GeomObj complains if buildBuffers/render is added to GLSubpath prototype)
105 //buildBuffers 71 //buildBuffers
@@ -115,36 +81,34 @@ var GLSubpath = function GLSubpath() {
115 // get the world 81 // get the world
116 var world = this.getWorld(); 82 var world = this.getWorld();
117 if (!world) throw( "null world in subpath render" ); 83 if (!world) throw( "null world in subpath render" );
118 84 if (!this._canvas){
119 // get the context 85 //set the canvas by querying the world
86 this._canvas = this.getWorld().getCanvas();
87 }
88 // get the context
120 var ctx = world.get2DContext(); 89 var ctx = world.get2DContext();
121 if (!ctx) throw ("null context in subpath render") 90 if (!ctx) throw ("null context in subpath render");
122 91
123 var numAnchors = this.getNumAnchors(); 92 var numAnchors = this.getNumAnchors();
124 if (numAnchors === 0) { 93 if (numAnchors === 0) {