|
@@ -22,7 +22,6 @@ THREE.Path.prototype = Object.create( THREE.CurvePath.prototype );
|
|
|
THREE.Path.prototype.constructor = THREE.Path;
|
|
|
|
|
|
THREE.PathActions = {
|
|
|
-
|
|
|
MOVE_TO: 'moveTo',
|
|
|
LINE_TO: 'lineTo',
|
|
|
QUADRATIC_CURVE_TO: 'quadraticCurveTo', // Bezier quadratic curve
|
|
@@ -41,9 +40,9 @@ THREE.Path.prototype.fromPoints = function ( vectors ) {
|
|
|
|
|
|
this.moveTo( vectors[ 0 ].x, vectors[ 0 ].y );
|
|
|
|
|
|
- for ( var v = 1, vlen = vectors.length; v < vlen; v ++ ) {
|
|
|
+ for ( var i = 1, l = vectors.length; i < l; i ++ ) {
|
|
|
|
|
|
- this.lineTo( vectors[ v ].x, vectors[ v ].y );
|
|
|
+ this.lineTo( vectors[ i ].x, vectors[ i ].y );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -83,18 +82,19 @@ THREE.Path.prototype.quadraticCurveTo = function( aCPx, aCPy, aX, aY ) {
|
|
|
var x0 = lastargs[ lastargs.length - 2 ];
|
|
|
var y0 = lastargs[ lastargs.length - 1 ];
|
|
|
|
|
|
- var curve = new THREE.QuadraticBezierCurve( new THREE.Vector2( x0, y0 ),
|
|
|
- new THREE.Vector2( aCPx, aCPy ),
|
|
|
- new THREE.Vector2( aX, aY ) );
|
|
|
+ var curve = new THREE.QuadraticBezierCurve(
|
|
|
+ new THREE.Vector2( x0, y0 ),
|
|
|
+ new THREE.Vector2( aCPx, aCPy ),
|
|
|
+ new THREE.Vector2( aX, aY )
|
|
|
+ );
|
|
|
+
|
|
|
this.curves.push( curve );
|
|
|
|
|
|
this.actions.push( { action: THREE.PathActions.QUADRATIC_CURVE_TO, args: args } );
|
|
|
|
|
|
};
|
|
|
|
|
|
-THREE.Path.prototype.bezierCurveTo = function( aCP1x, aCP1y,
|
|
|
- aCP2x, aCP2y,
|
|
|
- aX, aY ) {
|
|
|
+THREE.Path.prototype.bezierCurveTo = function( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
|
|
|
|
|
|
var args = Array.prototype.slice.call( arguments );
|
|
|
|
|
@@ -103,10 +103,13 @@ THREE.Path.prototype.bezierCurveTo = function( aCP1x, aCP1y,
|
|
|
var x0 = lastargs[ lastargs.length - 2 ];
|
|
|
var y0 = lastargs[ lastargs.length - 1 ];
|
|
|
|
|
|
- var curve = new THREE.CubicBezierCurve( new THREE.Vector2( x0, y0 ),
|
|
|
- new THREE.Vector2( aCP1x, aCP1y ),
|
|
|
- new THREE.Vector2( aCP2x, aCP2y ),
|
|
|
- new THREE.Vector2( aX, aY ) );
|
|
|
+ var curve = new THREE.CubicBezierCurve(
|
|
|
+ new THREE.Vector2( x0, y0 ),
|
|
|
+ new THREE.Vector2( aCP1x, aCP1y ),
|
|
|
+ new THREE.Vector2( aCP2x, aCP2y ),
|
|
|
+ new THREE.Vector2( aX, aY )
|
|
|
+ );
|
|
|
+
|
|
|
this.curves.push( curve );
|
|
|
|
|
|
this.actions.push( { action: THREE.PathActions.BEZIER_CURVE_TO, args: args } );
|
|
@@ -120,7 +123,7 @@ THREE.Path.prototype.splineThru = function( pts /*Array of Vector*/ ) {
|
|
|
|
|
|
var x0 = lastargs[ lastargs.length - 2 ];
|
|
|
var y0 = lastargs[ lastargs.length - 1 ];
|
|
|
- //---
|
|
|
+
|
|
|
var npts = [ new THREE.Vector2( x0, y0 ) ];
|
|
|
Array.prototype.push.apply( npts, pts );
|
|
|
|
|
@@ -133,8 +136,7 @@ THREE.Path.prototype.splineThru = function( pts /*Array of Vector*/ ) {
|
|
|
|
|
|
// FUTURE: Change the API or follow canvas API?
|
|
|
|
|
|
-THREE.Path.prototype.arc = function ( aX, aY, aRadius,
|
|
|
- aStartAngle, aEndAngle, aClockwise ) {
|
|
|
+THREE.Path.prototype.arc = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
|
|
|
|
|
|
var lastargs = this.actions[ this.actions.length - 1 ].args;
|
|
|
var x0 = lastargs[ lastargs.length - 2 ];
|
|
@@ -145,28 +147,24 @@ THREE.Path.prototype.arc = function ( aX, aY, aRadius,
|
|
|
|
|
|
};
|
|
|
|
|
|
- THREE.Path.prototype.absarc = function ( aX, aY, aRadius,
|
|
|
- aStartAngle, aEndAngle, aClockwise ) {
|
|
|
+ THREE.Path.prototype.absarc = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
|
|
|
|
|
|
this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
|
|
|
|
|
|
};
|
|
|
|
|
|
-THREE.Path.prototype.ellipse = function ( aX, aY, xRadius, yRadius,
|
|
|
- aStartAngle, aEndAngle, aClockwise, aRotation ) {
|
|
|
+THREE.Path.prototype.ellipse = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
|
|
|
|
|
|
var lastargs = this.actions[ this.actions.length - 1 ].args;
|
|
|
var x0 = lastargs[ lastargs.length - 2 ];
|
|
|
var y0 = lastargs[ lastargs.length - 1 ];
|
|
|
|
|
|
- this.absellipse( aX + x0, aY + y0, xRadius, yRadius,
|
|
|
- aStartAngle, aEndAngle, aClockwise, aRotation );
|
|
|
+ this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
-THREE.Path.prototype.absellipse = function ( aX, aY, xRadius, yRadius,
|
|
|
- aStartAngle, aEndAngle, aClockwise, aRotation ) {
|
|
|
+THREE.Path.prototype.absellipse = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
|
|
|
|
|
|
var args = [
|
|
|
aX, aY,
|
|
@@ -175,8 +173,8 @@ THREE.Path.prototype.absellipse = function ( aX, aY, xRadius, yRadius,
|
|
|
aClockwise,
|
|
|
aRotation || 0 // aRotation is optional.
|
|
|
];
|
|
|
- var curve = new THREE.EllipseCurve( aX, aY, xRadius, yRadius,
|
|
|
- aStartAngle, aEndAngle, aClockwise, aRotation );
|
|
|
+
|
|
|
+ var curve = new THREE.EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
|
|
|
this.curves.push( curve );
|
|
|
|
|
|
var lastPoint = curve.getPoint( 1 );
|
|
@@ -225,17 +223,15 @@ THREE.Path.prototype.getPoints = function( divisions, closedPath ) {
|
|
|
|
|
|
var points = [];
|
|
|
|
|
|
- var i, il, item, action, args;
|
|
|
var cpx, cpy, cpx2, cpy2, cpx1, cpy1, cpx0, cpy0,
|
|
|
- laste, j,
|
|
|
- t, tx, ty;
|
|
|
+ laste, tx, ty;
|
|
|
|
|
|
- for ( i = 0, il = this.actions.length; i < il; i ++ ) {
|
|
|
+ for ( var i = 0, l = this.actions.length; i < l; i ++ ) {
|
|
|
|
|
|
- item = this.actions[ i ];
|
|
|
+ var item = this.actions[ i ];
|
|
|
|
|
|
- action = item.action;
|
|
|
- args = item.args;
|
|
|
+ var action = item.action;
|
|
|
+ var args = item.args;
|
|
|
|
|
|
switch ( action ) {
|
|
|
|
|
@@ -275,9 +271,9 @@ THREE.Path.prototype.getPoints = function( divisions, closedPath ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- for ( j = 1; j <= divisions; j ++ ) {
|
|
|
+ for ( var j = 1; j <= divisions; j ++ ) {
|
|
|
|
|
|
- t = j / divisions;
|
|
|
+ var t = j / divisions;
|
|
|
|
|
|
tx = THREE.Shape.Utils.b2( t, cpx0, cpx1, cpx );
|
|
|
ty = THREE.Shape.Utils.b2( t, cpy0, cpy1, cpy );
|
|
@@ -316,9 +312,9 @@ THREE.Path.prototype.getPoints = function( divisions, closedPath ) {
|
|
|
}
|
|
|
|
|
|
|
|
|
- for ( j = 1; j <= divisions; j ++ ) {
|
|
|
+ for ( var j = 1; j <= divisions; j ++ ) {
|
|
|
|
|
|
- t = j / divisions;
|
|
|
+ var t = j / divisions;
|
|
|
|
|
|
tx = THREE.Shape.Utils.b3( t, cpx0, cpx1, cpx2, cpx );
|
|
|
ty = THREE.Shape.Utils.b3( t, cpy0, cpy1, cpy2, cpy );
|
|
@@ -342,7 +338,7 @@ THREE.Path.prototype.getPoints = function( divisions, closedPath ) {
|
|
|
|
|
|
var spline = new THREE.SplineCurve( spts );
|
|
|
|
|
|
- for ( j = 1; j <= n; j ++ ) {
|
|
|
+ for ( var j = 1; j <= n; j ++ ) {
|
|
|
|
|
|
points.push( spline.getPointAt( j / n ) );
|
|
|
|
|
@@ -361,9 +357,9 @@ THREE.Path.prototype.getPoints = function( divisions, closedPath ) {
|
|
|
var angle;
|
|
|
var tdivisions = divisions * 2;
|
|
|
|
|
|
- for ( j = 1; j <= tdivisions; j ++ ) {
|
|
|
+ for ( var j = 1; j <= tdivisions; j ++ ) {
|
|
|
|
|
|
- t = j / tdivisions;
|
|
|
+ var t = j / tdivisions;
|
|
|
|
|
|
if ( ! aClockwise ) {
|
|
|
|
|
@@ -402,15 +398,15 @@ THREE.Path.prototype.getPoints = function( divisions, closedPath ) {
|
|
|
|
|
|
var cos, sin;
|
|
|
if ( aRotation !== 0 ) {
|
|
|
-
|
|
|
+
|
|
|
cos = Math.cos( aRotation );
|
|
|
sin = Math.sin( aRotation );
|
|
|
|
|
|
}
|
|
|
|
|
|
- for ( j = 1; j <= tdivisions; j ++ ) {
|
|
|
+ for ( var j = 1; j <= tdivisions; j ++ ) {
|
|
|
|
|
|
- t = j / tdivisions;
|
|
|
+ var t = j / tdivisions;
|
|
|
|
|
|
if ( ! aClockwise ) {
|
|
|
|
|
@@ -481,16 +477,14 @@ THREE.Path.prototype.toShapes = function( isCCW, noHoles ) {
|
|
|
|
|
|
function extractSubpaths( inActions ) {
|
|
|
|
|
|
- var i, il, item, action, args;
|
|
|
-
|
|
|
var subPaths = [], lastPath = new THREE.Path();
|
|
|
|
|
|
- for ( i = 0, il = inActions.length; i < il; i ++ ) {
|
|
|
+ for ( var i = 0, l = inActions.length; i < l; i ++ ) {
|
|
|
|
|
|
- item = inActions[ i ];
|
|
|
+ var item = inActions[ i ];
|
|
|
|
|
|
- args = item.args;
|
|
|
- action = item.action;
|
|
|
+ var args = item.args;
|
|
|
+ var action = item.action;
|
|
|
|
|
|
if ( action === THREE.PathActions.MOVE_TO ) {
|
|
|
|
|
@@ -523,7 +517,7 @@ THREE.Path.prototype.toShapes = function( isCCW, noHoles ) {
|
|
|
|
|
|
var shapes = [];
|
|
|
|
|
|
- for ( var i = 0, il = inSubpaths.length; i < il; i ++ ) {
|
|
|
+ for ( var i = 0, l = inSubpaths.length; i < l; i ++ ) {
|
|
|
|
|
|
var tmpPath = inSubpaths[ i ];
|
|
|
|
|
@@ -636,9 +630,7 @@ THREE.Path.prototype.toShapes = function( isCCW, noHoles ) {
|
|
|
newShapes[ mainIdx ] = undefined;
|
|
|
newShapeHoles[ mainIdx ] = [];
|
|
|
|
|
|
- var i, il;
|
|
|
-
|
|
|
- for ( i = 0, il = subPaths.length; i < il; i ++ ) {
|
|
|
+ for ( var i = 0, l = subPaths.length; i < l; i ++ ) {
|
|
|
|
|
|
tmpPath = subPaths[ i ];
|
|
|
tmpPoints = tmpPath.getPoints();
|
|
@@ -682,13 +674,16 @@ THREE.Path.prototype.toShapes = function( isCCW, noHoles ) {
|
|
|
betterShapeHoles[ sIdx ] = [];
|
|
|
|
|
|
}
|
|
|
+
|
|
|
for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
|
|
|
|
|
|
var sho = newShapeHoles[ sIdx ];
|
|
|
+
|
|
|
for ( var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
|
|
|
|
|
|
var ho = sho[ hIdx ];
|
|
|
var hole_unassigned = true;
|
|
|
+
|
|
|
for ( var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
|
|
|
|
|
|
if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
|
|
@@ -727,13 +722,15 @@ THREE.Path.prototype.toShapes = function( isCCW, noHoles ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- var tmpHoles, j, jl;
|
|
|
- for ( i = 0, il = newShapes.length; i < il; i ++ ) {
|
|
|
+ var tmpHoles;
|
|
|
+
|
|
|
+ for ( var i = 0, il = newShapes.length; i < il; i ++ ) {
|
|
|
|
|
|
tmpShape = newShapes[ i ].s;
|
|
|
shapes.push( tmpShape );
|
|
|
tmpHoles = newShapeHoles[ i ];
|
|
|
- for ( j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
|
|
|
+
|
|
|
+ for ( var j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
|
|
|
|
|
|
tmpShape.holes.push( tmpHoles[ j ].h );
|
|
|
|