Skip to content

Commit 416016e

Browse files
committed
Added MoveTo curve construct for path jumping.
1 parent 966d0e4 commit 416016e

3 files changed

Lines changed: 79 additions & 12 deletions

File tree

v3/src/paths/MoveTo.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
var Class = require('../utils/Class');
2+
var Vector2 = require('../math/Vector2');
3+
4+
var MoveTo = new Class({
5+
6+
initialize:
7+
8+
function MoveTo (x, y)
9+
{
10+
// Skip length calcs in paths
11+
this.active = false;
12+
13+
this.p0 = new Vector2(x, y);
14+
},
15+
16+
getPoint: function (t, out)
17+
{
18+
if (out === undefined) { out = new Vector2(); }
19+
20+
return out.copy(this.p0);
21+
},
22+
23+
getPointAt: function (u, out)
24+
{
25+
return this.getPoint(u, out);
26+
},
27+
28+
getResolution: function ()
29+
{
30+
return 1;
31+
},
32+
33+
getLength: function ()
34+
{
35+
return 0;
36+
},
37+
38+
toJSON: function ()
39+
{
40+
return {
41+
type: 'MoveTo',
42+
points: [
43+
this.p0.x, this.p0.y
44+
]
45+
};
46+
}
47+
48+
});
49+
50+
module.exports = MoveTo;

v3/src/paths/Path.js

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var CubicBezierCurve = require('./curves/cubicbezier/CubicBezierCurve');
55
var EllipseCurve = require('./curves/ellipse/EllipseCurve');
66
var GameObjectFactory = require('../scene/plugins/GameObjectFactory');
77
var LineCurve = require('./curves/line/LineCurve');
8+
var MoveTo = require('./MoveTo');
89
var SplineCurve = require('./curves/spline/SplineCurve');
910
var Vector2 = require('../math/Vector2');
1011

@@ -31,6 +32,11 @@ var Path = new Class({
3132
this.startPoint = new Vector2(x, y);
3233
},
3334

35+
moveTo: function (x, y)
36+
{
37+
this.add(new MoveTo(x, y));
38+
},
39+
3440
// Creates a line curve from the previous end point to x/y
3541
lineTo: function (x, y)
3642
{
@@ -99,6 +105,13 @@ var Path = new Class({
99105
return this.add(ellipse);
100106
},
101107

108+
circleTo: function (radius, clockwise, rotation)
109+
{
110+
if (clockwise === undefined) { clockwise = false; }
111+
112+
return this.ellipseTo(radius, radius, 0, 360, clockwise, rotation);
113+
},
114+
102115
toJSON: function ()
103116
{
104117
var out = [];
@@ -179,8 +192,6 @@ var Path = new Class({
179192
var curveLengths = this.getCurveLengths();
180193
var i = 0;
181194

182-
// To think about boundaries points.
183-
184195
while (i < curveLengths.length)
185196
{
186197
if (curveLengths[i] >= d)
@@ -201,10 +212,6 @@ var Path = new Class({
201212
return null;
202213
},
203214

204-
// We cannot use the default THREE.Curve getPoint() with getLength() because in
205-
// THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
206-
// getPoint() depends on getLength
207-
208215
getLength: function ()
209216
{
210217
var lens = this.getCurveLengths();
@@ -215,15 +222,11 @@ var Path = new Class({
215222
// cacheLengths must be recalculated.
216223
updateArcLengths: function ()
217224
{
218-
this.needsUpdate = true;
219-
this.cacheLengths = null;
225+
this.cacheLengths = [];
220226

221227
this.getCurveLengths();
222228
},
223229

224-
// Compute lengths and cache them
225-
// We cannot overwrite getLengths() because UtoT mapping uses it.
226-
227230
getCurveLengths: function ()
228231
{
229232
// We use cache values if curves and cache array are same length
@@ -281,6 +284,11 @@ var Path = new Class({
281284
{
282285
var curve = this.curves[i];
283286

287+
if (!curve.active)
288+
{
289+
continue;
290+
}
291+
284292
var resolution = curve.getResolution(divisions);
285293

286294
var pts = curve.getPoints(resolution);
@@ -313,7 +321,14 @@ var Path = new Class({
313321
{
314322
for (var i = 0; i < this.curves.length; i++)
315323
{
316-
this.curves[i].draw(graphics, pointsTotal);
324+
var curve = this.curves[i];
325+
326+
if (!curve.active)
327+
{
328+
continue;
329+
}
330+
331+
curve.draw(graphics, pointsTotal);
317332
}
318333

319334
return graphics;

v3/src/paths/curves/Curve.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ var Curve = new Class({
2525
this.cacheArcLengths = [];
2626

2727
this.needsUpdate = true;
28+
29+
this.active = true;
2830
},
2931

3032
getBounds: function (out)

0 commit comments

Comments
 (0)