diff options
Diffstat (limited to 'js/helper-classes/backup-delete/GLBrushStroke.js')
-rwxr-xr-x | js/helper-classes/backup-delete/GLBrushStroke.js | 561 |
1 files changed, 0 insertions, 561 deletions
diff --git a/js/helper-classes/backup-delete/GLBrushStroke.js b/js/helper-classes/backup-delete/GLBrushStroke.js deleted file mode 100755 index 26c922a3..00000000 --- a/js/helper-classes/backup-delete/GLBrushStroke.js +++ /dev/null | |||
@@ -1,561 +0,0 @@ | |||
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._secondStrokeColor = this._strokeColor; | ||
35 | this._strokeHardness = 100; | ||
36 | this._strokeMaterial; | ||
37 | this._strokeStyle = "Solid"; | ||
38 | |||
39 | //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 | ||
40 | //smaller value means more samples for the path | ||
41 | this._WETNESS_FACTOR = 0.25; | ||
42 | |||
43 | //prevent extremely long paths that can take a long time to render | ||
44 | this._MAX_ALLOWED_SAMPLES = 5000; | ||
45 | |||
46 | //drawing context | ||
47 | this._world = null; | ||
48 | |||
49 | //tool that owns this brushstroke | ||
50 | this._drawingTool = null; | ||
51 | this._planeMat = null; | ||
52 | this._planeMatInv = null; | ||
53 | this._planeCenter = null; | ||
54 | |||
55 | // initialize the inherited members | ||
56 | this.inheritedFrom = GLGeomObj; | ||
57 | this.inheritedFrom(); | ||
58 | |||
59 | ///////////////////////////////////////////////////////// | ||
60 | // Property Accessors/Setters | ||
61 | ///////////////////////////////////////////////////////// | ||
62 | this.setWorld = function (world) { this._world = world; } | ||
63 | this.getWorld = function () { return this._world; } | ||
64 | this.geomType = function () { return this.GEOM_TYPE_CUBIC_BEZIER; } | ||
65 | this.setDrawingTool = function (tool) {this._drawingTool = tool;} | ||
66 | this.getDrawingTool = function () {return this._drawingTool;} | ||
67 | this.setPlaneMatrix = function(planeMat){this._planeMat = planeMat;} | ||
68 | this.setPlaneMatrixInverse = function(planeMatInv){this._planeMatInv = planeMatInv;} | ||
69 | this.setPlaneCenter = function(pc){this._planeCenter = pc;} | ||
70 | |||
71 | this.getCanvasX = function(){return this._canvasX;} | ||
72 | this.getCanvasY = function(){return this._canvasY;} | ||
73 | this.setCanvasX = function(cx){this._canvasX=cx;} | ||
74 | this.setCanvasY = function(cy){this._canvasY=cy;} | ||
75 | |||
76 | |||
77 | this.getNumPoints = function () { return this._Points.length; } | ||
78 | this.getPoint = function (index) { return this._Points[index]; } | ||
79 | this.addPoint = function (pt) | ||
80 | { | ||
81 | //add the point only if it is some epsilon away from the previous point | ||
82 | var numPoints = this._Points.length; | ||
83 | if (numPoints>0) { | ||
84 | var threshold = 1;//this._WETNESS_FACTOR*this._strokeWidth; | ||
85 | var prevPt = this._Points[numPoints-1]; | ||
86 | var diffPt = [prevPt[0]-pt[0], prevPt[1]-pt[1]]; | ||
87 | var diffPtMag = Math.sqrt(diffPt[0]*diffPt[0] + diffPt[1]*diffPt[1]); | ||
88 | if (diffPtMag>threshold){ | ||
89 | this._Points.push(pt); | ||
90 | this._dirty=true; | ||
91 | } | ||
92 | }else{ | ||
93 | this._Points.push(pt); | ||
94 | this._dirty=true; | ||
95 | } | ||
96 | } | ||
97 | |||
98 | this.insertPoint = function(pt, index){ this._Points.splice(index, 0, pt); this._dirty=true;} | ||
99 | this.isDirty = function(){return this._dirty;} | ||
100 | this.makeDirty = function(){this._dirty=true;} | ||
101 | |||
102 | this.getBBoxMin = function () { return this._BBoxMin; } | ||
103 | this.getBBoxMax = function () { return this._BBoxMax; } | ||
104 | |||
105 | this.getStrokeWidth = function () { return this._strokeWidth; } | ||
106 | this.setStrokeWidth = function (w) { this._strokeWidth = w; this._dirty=true;} | ||
107 | this.getStrokeMaterial = function () { return this._strokeMaterial; } | ||
108 | this.setStrokeMaterial = function (m) { this._strokeMaterial = m; } | ||
109 | this.getStrokeColor = function () { return this._strokeColor; } | ||
110 | this.setStrokeColor = function (c) { this._strokeColor = c; } | ||
111 | this.setSecondStrokeColor = function(c){this._secondStrokeColor=c;} | ||
112 | this.setStrokeHardness = function(h){this._strokeHardness=h;} | ||
113 | this.getStrokeStyle = function () { return this._strokeStyle; } | ||
114 | this.setStrokeStyle = function (s) { this._strokeStyle = s; } | ||
115 | |||
116 | this.setWidth = function () { }//NO-OP for now | ||
117 | this.setHeight = function () {}//NO-OP for now | ||
118 | |||
119 | |||
120 | //remove and return anchor at specified index, return null on error | ||
121 | this.removePoint = function (index) { | ||
122 | var retAnchor = null; | ||
123 | if (index < this._Points.length) { | ||
124 | retPt = this._Points.splice(index, 1); | ||
125 | this._dirty=true; | ||
126 | } | ||
127 | return retPoint; | ||
128 | } | ||
129 | |||
130 | //remove all the points | ||
131 | this.clear = function () { this._Points = []; this._dirty=true;} | ||
132 | |||
133 | this.translate = function (tx, ty, tz) { | ||
134 | for (var i=0;i<this._Points.length;i++){ | ||
135 | this._Points[i][0]+=tx; | ||
136 | this._Points[i][1]+=ty; | ||
137 | this._Points[i][2]+=tz; | ||
138 | } | ||
139 | } | ||
140 | |||
141 | this.computeMetaGeometry = function(){ | ||
142 | if (this._dirty){ | ||
143 | var numPoints = this._Points.length; | ||
144 | |||
145 | //**** add samples to the path if needed...linear interpolation for now | ||
146 | //if (numPoints>1) { | ||
147 | if (0){ | ||
148 | var threshold = this._WETNESS_FACTOR*this._strokeWidth; | ||
149 | var prevPt = this._Points[0]; | ||
150 | var prevIndex = 0; | ||
151 | for (var i=1;i<numPoints;i++){ | ||
152 | var pt = this._Points[i]; | ||
153 | var diff = [pt[0]-prevPt[0], pt[1]-prevPt[1]]; | ||
154 | var distance = Math.sqrt(diff[0]*diff[0]+diff[1]*diff[1]); | ||
155 | if (distance>threshold){ | ||
156 | //insert points along the prev. to current point | ||
157 | var numNewPoints = Math.floor(distance/threshold); | ||
158 | for (var j=0;j<numNewPoints;j++){ | ||
159 | var param = (j+1)/(numNewPoints+1); | ||
160 | var newpt = [prevPt[0]+ diff[0]*param, prevPt[1]+ diff[1]*param]; | ||
161 | //insert new point before point i | ||
162 | this._Points.splice(i, 0, [newpt[0], newpt[1], 0]); | ||
163 | i++; | ||
164 | } | ||
165 | this._dirty=true; | ||
166 | } | ||
167 | prevPt=pt; | ||
168 | //update numPoints to match the new length | ||
169 | numPoints = this._Points.length; | ||
170 | |||
171 | //end this function if the numPoints has gone above the max. size specified | ||
172 | if (numPoints> this._MAX_ALLOWED_SAMPLES){ | ||
173 | console.log("leaving the resampling because numPoints is greater than limit:"+this._MAX_ALLOWED_SAMPLES); | ||
174 | break; | ||
175 | } | ||
176 | } | ||
177 | } | ||
178 | |||
179 | //**** add samples to the long sections of the path --- Catmull-Rom spline interpolation | ||
180 | if (numPoints>1) { | ||
181 | var numInsertedPoints = 0; | ||
182 | var threshold = 5;//0.25*this._strokeWidth; //this determines whether a segment between two sample is too long | ||
183 | var prevPt = this._Points[0]; | ||
184 | for (var i=1;i<numPoints;i++){ | ||
185 | var pt = this._Points[i]; | ||
186 | var diff = [pt[0]-prevPt[0], pt[1]-prevPt[1]]; | ||
187 | var distance = Math.sqrt(diff[0]*diff[0]+diff[1]*diff[1]); | ||
188 | if (distance>threshold){ | ||
189 | //build the control polygon for the Catmull-Rom spline (prev. 2 points and next 2 points) | ||
190 | var prev = (i===1) ? i-1 : i-2; | ||
191 | var next = (i===numPoints-1) ? i : i+1; | ||
192 | var ctrlPts = [this._Points[prev], this._Points[i-1], this._Points[i], this._Points[next]]; | ||
193 | //insert points along the prev. to current point | ||
194 | var numNewPoints = Math.floor(distance/threshold); | ||
195 | for (var j=0;j<numNewPoints;j++){ | ||
196 | var param = (j+1)/(numNewPoints+1); | ||
197 | var newpt = this._CatmullRomSplineInterpolate(ctrlPts, param); | ||
198 | //insert new point before point i | ||
199 | this._Points.splice(i, 0, newpt); | ||
200 | i++; | ||
201 | numInsertedPoints++; | ||
202 | } | ||
203 | this._dirty=true; | ||
204 | } | ||
205 | prevPt=pt; | ||
206 | //update numPoints to match the new length | ||
207 | numPoints = this._Points.length; | ||
208 | |||
209 | //end this function if the numPoints has gone above the max. size specified | ||
210 | if (numPoints> this._MAX_ALLOWED_SAMPLES){ | ||
211 | console.log("leaving the resampling because numPoints is greater than limit:"+this._MAX_ALLOWED_SAMPLES); | ||
212 | break; | ||
213 | } | ||
214 | } | ||
215 | console.log("Inserted "+numInsertedPoints+" additional CatmullRom points"); | ||
216 | } |