aboutsummaryrefslogtreecommitdiff
path: root/js/lib/geom
diff options
context:
space:
mode:
authorNivesh Rajbhandari2012-04-25 13:34:04 -0700
committerNivesh Rajbhandari2012-04-25 13:34:04 -0700
commit32a24988add5ba0ecf80caa31871cdd90e3eea5b (patch)
treefbf05f2dfc91e57ab9598046ff16798ea0ae1966 /js/lib/geom
parent60d6346a78fb5257eaf36f17a5fcb764a342c012 (diff)
parentd3a6350163ada5644d34ed8d5c2a00cef4db2afc (diff)
downloadninja-32a24988add5ba0ecf80caa31871cdd90e3eea5b.tar.gz
Merge branch 'refs/heads/ninja-internal' into WebGLMaterials
Diffstat (limited to 'js/lib/geom')
-rwxr-xr-xjs/lib/geom/anchor-point.js4
-rwxr-xr-xjs/lib/geom/brush-stroke.js19
-rwxr-xr-xjs/lib/geom/geom-obj.js3
-rwxr-xr-xjs/lib/geom/line.js2
-rwxr-xr-xjs/lib/geom/sub-path.js853
5 files changed, 330 insertions, 551 deletions
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 26ac42e9..efd21c4a 100755
--- a/js/lib/geom/brush-stroke.js
+++ b/js/lib/geom/brush-stroke.js
@@ -44,6 +44,9 @@ var BrushStroke = function GLBrushStroke() {
44 this._strokeAngle = 0; 44 this._strokeAngle = 0;
45 this._strokeAmountSmoothing = 0; 45 this._strokeAmountSmoothing = 0;
46 46
47 // currently, brush does not support a fill region
48 this.canFill = false;
49
47 //threshold that tells us whether two samples are too far apart 50 //threshold that tells us whether two samples are too far apart
48 this._MAX_SAMPLE_DISTANCE_THRESHOLD = 5; 51 this._MAX_SAMPLE_DISTANCE_THRESHOLD = 5;
49 52
@@ -413,7 +416,7 @@ var BrushStroke = function GLBrushStroke() {
413 this._LocalPoints[i][1]+= halfheight; 416 this._LocalPoints[i][1]+= halfheight;
414 417
415 //store the original points 418 //store the original points
416 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]]);
417 } 420 }
418 //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
419 this._BBoxMax[0]+= halfwidth;this._BBoxMin[0]+= halfwidth; 422 this._BBoxMax[0]+= halfwidth;this._BBoxMin[0]+= halfwidth;
@@ -541,6 +544,10 @@ var BrushStroke = function GLBrushStroke() {
541 var bboxWidth = bboxMax[0] - bboxMin[0]; 544 var bboxWidth = bboxMax[0] - bboxMin[0];
542 var bboxHeight = bboxMax[1] - bboxMin[1]; 545 var bboxHeight = bboxMax[1] - bboxMin[1];
543 546
547 if (!this._canvas){
548 //set the canvas by querying the world
549 this._canvas = this.getWorld().getCanvas();
550 }
544 if (this._canvas) { 551 if (this._canvas) {
545 var newLeft = Math.round(this._stageWorldCenter[0] - 0.5 * bboxWidth); 552 var newLeft = Math.round(this._stageWorldCenter[0] - 0.5 * bboxWidth);
546 var newTop = Math.round(this._stageWorldCenter[1] - 0.5 * bboxHeight); 553 var newTop = Math.round(this._stageWorldCenter[1] - 0.5 * bboxHeight);
@@ -550,7 +557,7 @@ var BrushStroke = function GLBrushStroke() {
550 557
551 CanvasController.setProperty(this._canvas, "width", bboxWidth+"px"); 558 CanvasController.setProperty(this._canvas, "width", bboxWidth+"px");
552 CanvasController.setProperty(this._canvas, "height", bboxHeight+"px"); 559 CanvasController.setProperty(this._canvas, "height", bboxHeight+"px");
553 this._canvas.elementModel.shapeModel.GLWorld.setViewportFromCanvas(this._canvas); 560 //this._canvas.elementModel.shapeModel.GLWorld.setViewportFromCanvas(this._canvas);
554 } 561 }
555 562
556 563
@@ -662,8 +669,8 @@ var BrushStroke = function GLBrushStroke() {
662 this._copyCoordinates3D(this._OrigLocalPoints, retObject.origLocalPoints); //todo <ditto> 669 this._copyCoordinates3D(this._OrigLocalPoints, retObject.origLocalPoints); //todo <ditto>
663 670
664 retObject.stageWorldCenter = [this._stageWorldCenter[0],this._stageWorldCenter[1],this._stageWorldCenter[2]]; 671 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]]; 672 retObject.planeMat = this._planeMat;
666 retObject.planeMatInv = [this._planeMatInv[0],this._planeMatInv[1],this._planeMatInv[2],this._planeMatInv[3]]; 673 retObject.planeMatInv = this._planeMatInv;
667 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]];
668 675
669 //stroke appearance properties 676 //stroke appearance properties
@@ -691,8 +698,8 @@ var BrushStroke = function GLBrushStroke() {
691 this._copyCoordinates3D(jo.origLocalPoints, this._OrigLocalPoints); //todo <ditto> 698 this._copyCoordinates3D(jo.origLocalPoints, this._OrigLocalPoints); //todo <ditto>
692 699
693 this._stageWorldCenter = [jo.stageWorldCenter[0],jo.stageWorldCenter[1],jo.stageWorldCenter[2]]; 700 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]]; 701 this._planeMat = jo.planeMat;
695 this._planeMatInv = [jo.planeMatInv[0],jo.planeMatInv[1],jo.planeMatInv[2],jo.planeMatInv[3]]; 702 this._planeMatInv = jo.planeMatInv;
696 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]];
697 704
698 //stroke appearance properties 705 //stroke appearance properties
diff --git a/js/lib/geom/geom-obj.js b/js/lib/geom/geom-obj.js
index 2cde8a75..f2991bdb 100755
--- a/js/lib/geom/geom-obj.js
+++ b/js/lib/geom/geom-obj.js
@@ -47,6 +47,9 @@ var GeomObj = function GLGeomObj() {
47 this._fillMaterial = null; 47 this._fillMaterial = null;
48 this._strokeMaterial = null; 48 this._strokeMaterial = null;
49 49
50 // Shapes (such as lines) that don't support fill should set this to false
51 this.canFill = true;
52
50 // array of primitives - used in RDGE 53 // array of primitives - used in RDGE
51 this._primArray = []; 54 this._primArray = [];
52 this._materialNodeArray = []; 55 this._materialNodeArray = [];
diff --git a/js/lib/geom/line.js b/js/lib/geom/line.js
index 8ee39098..bb198d83 100755
--- a/js/lib/geom/line.js
+++ b/js/lib/geom/line.js
@@ -33,6 +33,8 @@ var Line = function GLLine( world, xOffset, yOffset, width, height, slope, strok
33 this._scaleX = 1.0; 33 this._scaleX = 1.0;
34 this._scaleY = 1.0; 34 this._scaleY = 1.0;
35 35
36 this.canFill = false;
37
36 if (arguments.length > 0) { 38 if (arguments.length > 0) {
37 this._width = width; 39 this._width = width;
38 this._height = height; 40 this._height = height;
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