aboutsummaryrefslogtreecommitdiff
path: root/js/lib
diff options
context:
space:
mode:
authorJose Antonio Marquez2012-04-26 11:07:09 -0700
committerJose Antonio Marquez2012-04-26 11:07:09 -0700
commitd193e087bf24b538b6d88ae501b4b6e9781f501b (patch)
tree9a735388752f575fddf72240803c385316ff5c43 /js/lib
parent7f5eb2105c2e5e0970072af88fa90baded7e55d6 (diff)
parentbcc8f8616f5ad4bf310928da6cbc01da12f6e468 (diff)
downloadninja-d193e087bf24b538b6d88ae501b4b6e9781f501b.tar.gz
Merge branch 'refs/heads/Ninja-Internal' into FileIO
Diffstat (limited to 'js/lib')
-rwxr-xr-xjs/lib/drawing/world.js7
-rwxr-xr-xjs/lib/geom/anchor-point.js4
-rwxr-xr-xjs/lib/geom/brush-stroke.js16
-rwxr-xr-xjs/lib/geom/sub-path.js853
4 files changed, 328 insertions, 552 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/anchor-point.js b/js/lib/geom/anchor-point.js
index 0e9f65ea..d254681c 100755
--- a/js/lib/geom/anchor-point.js
+++ b/js/lib/geom/anchor-point.js
@@ -221,6 +221,10 @@ GLAnchorPoint.prototype.getNext = function() {
221 return [this._nextX, this._nextY, this._nextZ]; 221 return [this._nextX, this._nextY, this._nextZ];
222}; 222};
223 223
224GLAnchorPoint.prototype.getAllPos = function() {
225 return [[this._prevX, this._prevY, this._prevZ],[this._x, this._y, this._z],[this._nextX, this._nextY, this._nextZ]];
226};
227
224//return the square of distance from passed in point to the anchor position 228//return the square of distance from passed in point to the anchor position
225GLAnchorPoint.prototype.getDistanceSq = function (x, y, z) { 229GLAnchorPoint.prototype.getDistanceSq = function (x, y, z) {
226 return (this._x - x) * (this._x - x) + (this._y - y) * (this._y - y) + (this._z - z) * (this._z - z); 230 return (this._x - x) * (this._x - x) + (this._y - y) * (this._y - y) + (this._z - z) * (this._z - z);
diff --git a/js/lib/geom/brush-stroke.js b/js/lib/geom/brush-stroke.js
index 743dab85..efd21c4a 100755
--- a/js/lib/geom/brush-stroke.js
+++ b/js/lib/geom/brush-stroke.js
@@ -416,7 +416,7 @@ var BrushStroke = function GLBrushStroke() {
416 this._LocalPoints[i][1]+= halfheight; 416 this._LocalPoints[i][1]+= halfheight;
417 417
418 //store the original points 418 //store the original points
419 this._OrigLocalPoints .push([this._LocalPoints[i][0],this._LocalPoints[i][1],this._LocalPoints[i][2]]); 419 this._OrigLocalPoints.push([this._LocalPoints[i][0],this._LocalPoints[i][1],this._LocalPoints[i][2]]);
420 } 420 }
421 //update the bbox with the same adjustment as was made for the local points above 421 //update the bbox with the same adjustment as was made for the local points above
422 this._BBoxMax[0]+= halfwidth;this._BBoxMin[0]+= halfwidth; 422 this._BBoxMax[0]+= halfwidth;this._BBoxMin[0]+= halfwidth;
@@ -544,6 +544,10 @@ var BrushStroke = function GLBrushStroke() {
544 var bboxWidth = bboxMax[0] - bboxMin[0]; 544 var bboxWidth = bboxMax[0] - bboxMin[0];
545 var bboxHeight = bboxMax[1] - bboxMin[1]; 545 var bboxHeight = bboxMax[1] - bboxMin[1];
546 546
547 if (!this._canvas){
548 //set the canvas by querying the world
549 this._canvas = this.getWorld().getCanvas();
550 }
547 if (this._canvas) { 551 if (this._canvas) {
548 var newLeft = Math.round(this._stageWorldCenter[0] - 0.5 * bboxWidth); 552 var newLeft = Math.round(this._stageWorldCenter[0] - 0.5 * bboxWidth);
549 var newTop = Math.round(this._stageWorldCenter[1] - 0.5 * bboxHeight); 553 var newTop = Math.round(this._stageWorldCenter[1] - 0.5 * bboxHeight);
@@ -553,7 +557,7 @@ var BrushStroke = function GLBrushStroke() {
553 557
554 CanvasController.setProperty(this._canvas, "width", bboxWidth+"px"); 558 CanvasController.setProperty(this._canvas, "width", bboxWidth+"px");
555 CanvasController.setProperty(this._canvas, "height", bboxHeight+"px"); 559 CanvasController.setProperty(this._canvas, "height", bboxHeight+"px");
556 this._canvas.elementModel.shapeModel.GLWorld.setViewportFromCanvas(this._canvas); 560 //this._canvas.elementModel.shapeModel.GLWorld.setViewportFromCanvas(this._canvas);
557 } 561 }
558 562
559 563
@@ -665,8 +669,8 @@ var BrushStroke = function GLBrushStroke() {
665 this._copyCoordinates3D(this._OrigLocalPoints, retObject.origLocalPoints); //todo <ditto> 669 this._copyCoordinates3D(this._OrigLocalPoints, retObject.origLocalPoints); //todo <ditto>
666 670
667 retObject.stageWorldCenter = [this._stageWorldCenter[0],this._stageWorldCenter[1],this._stageWorldCenter[2]]; 671 retObject.stageWorldCenter = [this._stageWorldCenter[0],this._stageWorldCenter[1],this._stageWorldCenter[2]];
668 retObject.planeMat = [this._planeMat[0],this._planeMat[1],this._planeMat[2],this._planeMat[3]]; 672 retObject.planeMat = this._planeMat;
669 retObject.planeMatInv = [this._planeMatInv[0],this._planeMatInv[1],this._planeMatInv[2],this._planeMatInv[3]]; 673 retObject.planeMatInv = this._planeMatInv;
670 retObject.dragPlane = [this._dragPlane[0],this._dragPlane[1],this._dragPlane[2],this._dragPlane[3]]; 674 retObject.dragPlane = [this._dragPlane[0],this._dragPlane[1],this._dragPlane[2],this._dragPlane[3]];
671 675
672 //stroke appearance properties 676 //stroke appearance properties
@@ -694,8 +698,8 @@ var BrushStroke = function GLBrushStroke() {
694 this._copyCoordinates3D(jo.origLocalPoints, this._OrigLocalPoints); //todo <ditto> 698 this._copyCoordinates3D(jo.origLocalPoints, this._OrigLocalPoints); //todo <ditto>
695 699
696 this._stageWorldCenter = [jo.stageWorldCenter[0],jo.stageWorldCenter[1],jo.stageWorldCenter[2]]; 700 this._stageWorldCenter = [jo.stageWorldCenter[0],jo.stageWorldCenter[1],jo.stageWorldCenter[2]];
697 this._planeMat = [jo.planeMat[0], jo.planeMat[1],jo.planeMat[2],jo.planeMat[3]]; 701 this._planeMat = jo.planeMat;
698 this._planeMatInv = [jo.planeMatInv[0],jo.planeMatInv[1],jo.planeMatInv[2],jo.planeMatInv[3]]; 702 this._planeMatInv = jo.planeMatInv;
699 this._dragPlane = [jo.dragPlane[0],jo.dragPlane[1],jo.dragPlane[2],jo.dragPlane[3]]; 703 this._dragPlane = [jo.dragPlane[0],jo.dragPlane[1],jo.dragPlane[2],jo.dragPlane[3]];
700 704
701 //stroke appearance properties 705 //stroke appearance properties
diff --git a/js/lib/geom/sub-path.js b/js/lib/geom/sub-path.js
index 7046673e..56c94df3 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,42 @@ 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];
37 this._canvasCenterLocalCoord = [0,0,0];
38
50 this._isClosed = false; 39 this._isClosed = false;
51 40
52 this._samples = []; //polyline representation of this curve 41 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) 42 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 43 this._anchorSampleIndex = []; //index within _Samples corresponding to anchor points
55
56 this._UnprojectedAnchors = [];
57 44
58 //initially set the _dirty bit so we will construct samples 45 //initially set the _dirty bit so we will re-construct _Anchors and _Samples
59 this._dirty = true; 46 this._dirty = true;
60 47
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 48 //stroke information
72 this._strokeWidth = 0.0; 49 this._strokeWidth = 1.0;
73 this._strokeColor = [0.4, 0.4, 0.4, 1.0]; 50 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]; 51 this._fillColor = [1.0, 1.0, 1.0, 0.0];
80 this._fillMaterial = null;
81 this._DISPLAY_ANCHOR_RADIUS = 5; 52 this._DISPLAY_ANCHOR_RADIUS = 5;
53
82 //drawing context 54 //drawing context
83 this._world = null; 55 this._world = null;
56 this._canvas = null; //todo this might be unnecessary (but faster) since we can get it from the world
84 57
85 //tool that owns this subpath 58 //tool that owns this subpath
86 this._drawingTool = null; 59 this._drawingTool = null;
87 this._planeMat = null;
88 this._planeMatInv = null;
89 this._planeCenter = null;
90 60
91 //used to query what the user selected, OR-able for future extensions 61 //used to query what the user selected, OR-able for future extensions
92 this.SEL_NONE = 0; //nothing was selected 62 this.SEL_NONE = 0; //nothing was selected
@@ -98,8 +68,6 @@ var GLSubpath = function GLSubpath() {
98 this._selectedAnchorIndex = -1; 68 this._selectedAnchorIndex = -1;
99 69
100 this._SAMPLING_EPSILON = 0.5; //epsilon used for sampling the curve 70 this._SAMPLING_EPSILON = 0.5; //epsilon used for sampling the curve
101 this._DEFAULT_STROKE_WIDTH = 20; //use only if stroke width not sp