diff options
author | Jonathan Duran | 2012-03-06 17:08:55 -0800 |
---|---|---|
committer | Jonathan Duran | 2012-03-06 17:08:55 -0800 |
commit | bb6a1d82b2884b410f5859cc0c2cafd380acbe6a (patch) | |
tree | 6ec3e960a0c38ce8fd88c9bc17f5227d072ebe76 /js/helper-classes/backup-delete/GLBrushStroke.js | |
parent | 2815adfd7c19b3dff89dc3e1bda9af8d30dca8d6 (diff) | |
parent | 2e3943a8f751ec572066f168b58464c24b9f29e5 (diff) | |
download | ninja-bb6a1d82b2884b410f5859cc0c2cafd380acbe6a.tar.gz |
Merge branch 'refs/heads/NINJAmaster' into TimelineUber
Diffstat (limited to 'js/helper-classes/backup-delete/GLBrushStroke.js')
-rwxr-xr-x | js/helper-classes/backup-delete/GLBrushStroke.js | 397 |
1 files changed, 397 insertions, 0 deletions
diff --git a/js/helper-classes/backup-delete/GLBrushStroke.js b/js/helper-classes/backup-delete/GLBrushStroke.js new file mode 100755 index 00000000..5d773c2d --- /dev/null +++ b/js/helper-classes/backup-delete/GLBrushStroke.js | |||
@@ -0,0 +1,397 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | |||
7 | // Todo: This entire class should be converted to a module | ||
8 | var VecUtils = require("js/helper-classes/3D/vec-utils").VecUtils; | ||
9 | |||
10 | /////////////////////////////////////////////////////////////////////// | ||
11 | // Class GLBrushStroke | ||
12 | // representation a sequence points (polyline) created by brush tool. | ||
13 | // Derived from class GLGeomObj | ||
14 | /////////////////////////////////////////////////////////////////////// | ||
15 | function GLBrushStroke() { | ||
16 | /////////////////////////////////////////////////// | ||
17 | // Instance variables | ||
18 | /////////////////////////////////////////////////// | ||
19 | this._Points = []; | ||
20 | this._BBoxMin = [0, 0, 0]; | ||
21 | this._BBoxMax = [0, 0, 0]; | ||
22 | this._dirty = true; | ||
23 | |||
24 | //whether or not to use the canvas drawing to stroke/fill | ||
25 | this._useCanvasDrawing = true; | ||
26 | |||
27 | //the X and Y location of this subpath's canvas in stage world space of Ninja | ||
28 | this._canvasX = 0; | ||
29 | this._canvasY = 0; | ||
30 | |||
31 | //stroke information | ||
32 | this._strokeWidth = 0.0; | ||
33 | this._strokeColor = [0.4, 0.4, 0.4, 1.0]; | ||
34 | this._strokeMaterial; | ||
35 | this._strokeStyle = "Solid"; | ||
36 | |||
37 | //the wetness of the brush (currently this is multiplied to the square of the stroke width, but todo should be changed to not depend on stroke width entirely | ||
38 | //smaller value means more samples for the path | ||
39 | this._WETNESS_FACTOR = 0.25; | ||
40 | |||
41 | //prevent extremely long paths that can take a long time to render | ||
42 | this._MAX_ALLOWED_SAMPLES = 500; | ||
43 | |||
44 | //drawing context | ||
45 | this._world = null; | ||
46 | |||
47 | //tool that owns this brushstroke | ||
48 | this._drawingTool = null; | ||
49 | this._planeMat = null; | ||
50 | this._planeMatInv = null; | ||
51 | this._planeCenter = null; | ||
52 | |||
53 | // initialize the inherited members | ||
54 | this.inheritedFrom = GLGeomObj; | ||
55 | this.inheritedFrom(); | ||
56 | |||
57 | ///////////////////////////////////////////////////////// | ||
58 | // Property Accessors/Setters | ||
59 | ///////////////////////////////////////////////////////// | ||
60 | this.setWorld = function (world) { this._world = world; } | ||
61 | this.getWorld = function () { return this._world; } | ||
62 | this.geomType = function () { return this.GEOM_TYPE_CUBIC_BEZIER; } | ||
63 | this.setDrawingTool = function (tool) {this._drawingTool = tool;} | ||
64 | this.getDrawingTool = function () {return this._drawingTool;} | ||
65 | this.setPlaneMatrix = function(planeMat){this._planeMat = planeMat;} | ||
66 | this.setPlaneMatrixInverse = function(planeMatInv){this._planeMatInv = planeMatInv;} | ||
67 | this.setPlaneCenter = function(pc){this._planeCenter = pc;} | ||
68 | |||
69 | this.getCanvasX = function(){return this._canvasX;} | ||
70 | this.getCanvasY = function(){return this._canvasY;} | ||
71 | this.setCanvasX = function(cx){this._canvasX=cx;} | ||
72 | this.setCanvasY = function(cy){this._canvasY=cy;} | ||
73 | |||
74 | |||
75 | this.getNumPoints = function () { return this._Points.length; } | ||
76 | this.getPoint = function (index) { return this._Points[index]; } | ||
77 | this.addPoint = function (pt) | ||
78 | { | ||
79 | //add the point only if it is some epsilon away from the previous point | ||
80 | var numPoints = this._Points.length; | ||
81 | if (numPoints>0) { | ||
82 | var threshold = this._WETNESS_FACTOR*this._strokeWidth; | ||
83 | var prevPt = this._Points[numPoints-1]; | ||
84 | var diffPt = [prevPt[0]-pt[0], prevPt[1]-pt[1]]; | ||
85 | var diffPtMag = Math.sqrt(diffPt[0]*diffPt[0] + diffPt[1]*diffPt[1]); | ||
86 | if (diffPtMag>threshold){ | ||
87 | this._Points.push(pt); | ||
88 | this._dirty=true; | ||
89 | } | ||
90 | }else{ | ||
91 | this._Points.push(pt); | ||
92 | this._dirty=true; | ||
93 | } | ||
94 | } | ||
95 | |||
96 | this.insertPoint = function(pt, index){ this._Points.splice(index, 0, pt); this._dirty=true;} | ||
97 | this.isDirty = function(){return this._dirty;} | ||
98 | this.makeDirty = function(){this._dirty=true;} | ||
99 | |||
100 | this.getBBoxMin = function () { return this._BBoxMin; } | ||
101 | this.getBBoxMax = function () { return this._BBoxMax; } | ||
102 | |||
103 | this.getStrokeWidth = function () { return this._strokeWidth; } | ||
104 | this.setStrokeWidth = function (w) { this._strokeWidth = w; this._dirty=true;} | ||
105 | this.getStrokeMaterial = function () { return this._strokeMaterial; } | ||
106 | this.setStrokeMaterial = function (m) { this._strokeMaterial = m; } | ||
107 | this.getStrokeColor = function () { return this._strokeColor; } | ||
108 | this.setStrokeColor = function (c) { this._strokeColor = c; } | ||
109 | this.getStrokeStyle = function () { return this._strokeStyle; } | ||
110 | this.setStrokeStyle = function (s) { this._strokeStyle = s; } | ||
111 | |||
112 | this.setWidth = function () { }//NO-OP for now | ||
113 | this.setHeight = function () {}//NO-OP for now | ||
114 | |||
115 | |||
116 | //remove and return anchor at specified index, return null on error | ||
117 | this.removePoint = function (index) { | ||
118 | var retAnchor = null; | ||
119 | if (index < this._Points.length) { | ||
120 | retPt = this._Points.splice(index, 1); | ||
121 | this._dirty=true; | ||
122 | } | ||
123 | return retPoint; | ||
124 | } | ||
125 | |||
126 | //remove all the points | ||
127 | this.clear = function () { this._Points = []; this._dirty=true;} | ||
128 | |||
129 | this.translate = function (tx, ty, tz) { | ||
130 | for (var i=0;i<this._Points.length;i++){ | ||
131 | this._Points[i][0]+=tx; | ||
132 | this._Points[i][1]+=ty; | ||
133 | this._Points[i][2]+=tz; | ||
134 | } | ||
135 | } | ||
136 | |||
137 | this.computeMetaGeometry = function(){ | ||
138 | if (this._dirty){ | ||
139 | var numPoints = this._Points.length; | ||
140 | |||
141 | //**** add samples to the path if needed...linear interpolation for now | ||
142 | if (numPoints>1) { | ||
143 | var threshold = this._WETNESS_FACTOR*this._strokeWidth; | ||
144 | var prevPt = this._Points[0]; | ||
145 | var prevIndex = 0; | ||
146 | for (var i=1;i<numPoints;i++){ | ||
147 | var pt = this._Points[i]; | ||
148 | var diff = [pt[0]-prevPt[0], pt[1]-prevPt[1]]; | ||
149 | var distance = Math.sqrt(diff[0]*diff[0]+diff[1]*diff[1]); | ||
150 | if (distance>threshold){ | ||
151 | //insert points along the prev. to current point | ||
152 | var numNewPoints = Math.floor(distance/threshold); | ||
153 | for (var j=0;j<numNewPoints;j++){ | ||
154 | var param = (j+1)/(numNewPoints+1); | ||
155 | var newpt = [prevPt[0]+ diff[0]*param, prevPt[1]+ diff[1]*param]; | ||
156 | //insert new point before point i | ||
157 | this._Points.splice(i, 0, [newpt[0], newpt[1], 0]); | ||
158 | i++; | ||
159 | } | ||
160 | this._dirty=true; | ||
161 | } | ||
162 | prevPt=pt; | ||
163 | //update numPoints to match the new length | ||
164 | numPoints = this._Points.length; | ||
165 | |||
166 | //end this function if the numPoints has gone above the max. size specified | ||
167 | if (numPoints> this._MAX_ALLOWED_SAMPLES){ | ||
168 | console.log("leaving the resampling because numPoints is greater than limit:"+this._MAX_ALLOWED_SAMPLES); | ||
169 | break; | ||
170 | } | ||
171 | } | ||
172 | } | ||
173 | |||
174 | // *** compute the bounding box ********* | ||
175 | this._BBoxMin = [Infinity, Infinity, Infinity]; | ||
176 | this._BBoxMax = [-Infinity, -Infinity, -Infinity]; | ||
177 | numPoints = this._Points.length; | ||
178 | if (numPoints === 0) { | ||
179 | this._BBoxMin = [0, 0, 0]; | ||
180 | this._BBoxMax = [0, 0, 0]; | ||
181 | } else { | ||
182 | for (var i=0;i<numPoints;i++){ | ||
183 | var pt = this._Points[i]; | ||
184 | for (var d = 0; d < 3; d++) { | ||
185 | if (this._BBoxMin[d] > pt[d]) { | ||
186 | this._BBoxMin[d] = pt[d]; | ||
187 | } | ||
188 | if (this._BBoxMax[d] < pt[d]) { | ||
189 | this._BBoxMax[d] = pt[d]; | ||
190 | } | ||
191 | }//for every dimension d from 0 to 2 | ||
192 | } | ||
193 | } | ||
194 | //increase the bbox given the stroke width | ||
195 | for (var d = 0; d < 3; d++) { | ||
196 | this._BBoxMin[d]-= this._strokeWidth/2; | ||
197 | this._BBoxMax[d]+= this._strokeWidth/2; | ||
198 | }//for every dimension d from 0 to 2 | ||
199 | } | ||
200 | this._dirty = false; | ||
201 | } | ||
202 | |||
203 | this.buildBuffers = function () { | ||
204 | return; //no need to do anything for now | ||
205 | }//buildBuffers() | ||
206 | |||
207 | //render | ||
208 | // specify how to render the subpath in Canvas2D | ||
209 | this.render = function () { | ||
210 | // get the world | ||