提交 6b53488f 编写于 作者: M Mr.doob

*Path: Implemented Object.assign(). See #8838.

上级 d330d5b6
......@@ -16,24 +16,17 @@ THREE.CurvePath = function () {
};
THREE.CurvePath.prototype = Object.create( THREE.Curve.prototype );
THREE.CurvePath.prototype.constructor = THREE.CurvePath;
THREE.CurvePath.prototype = Object.assign( Object.create( THREE.Curve.prototype ), {
THREE.CurvePath.prototype.add = function ( curve ) {
constructor: THREE.CurvePath,
add: function ( curve ) {
this.curves.push( curve );
};
},
/*
THREE.CurvePath.prototype.checkConnection = function() {
// TODO
// If the ending of curve is not connected to the starting
// or the next curve, then, this is not a real path
};
*/
THREE.CurvePath.prototype.closePath = function() {
closePath: function () {
// TODO Test
// and verify for vector3 (needs to implement equals)
......@@ -47,18 +40,18 @@ THREE.CurvePath.prototype.closePath = function() {
}
};
},
// To get accurate point with reference to
// entire path distance at time t,
// following has to be done:
// To get accurate point with reference to
// entire path distance at time t,
// following has to be done:
// 1. Length of each sub path have to be known
// 2. Locate and identify type of curve
// 3. Get t for the curve
// 4. Return curve.getPointAt(t')
// 1. Length of each sub path have to be known
// 2. Locate and identify type of curve
// 3. Get t for the curve
// 4. Return curve.getPointAt(t')
THREE.CurvePath.prototype.getPoint = function( t ) {
getPoint: function ( t ) {
var d = t * this.getLength();
var curveLengths = this.getCurveLengths();
......@@ -87,28 +80,23 @@ THREE.CurvePath.prototype.getPoint = function( t ) {
// loop where sum != 0, sum > d , sum+1 <d
};
/*
THREE.CurvePath.prototype.getTangent = function( t ) {
};
*/
},
// We cannot use the default THREE.Curve getPoint() with getLength() because in
// THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
// getPoint() depends on getLength
// We cannot use the default THREE.Curve getPoint() with getLength() because in
// THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
// getPoint() depends on getLength
THREE.CurvePath.prototype.getLength = function() {
getLength: function () {
var lens = this.getCurveLengths();
return lens[ lens.length - 1 ];
};
},
// Compute lengths and cache them
// We cannot overwrite getLengths() because UtoT mapping uses it.
// Compute lengths and cache them
// We cannot overwrite getLengths() because UtoT mapping uses it.
THREE.CurvePath.prototype.getCurveLengths = function() {
getCurveLengths: function () {
// We use cache values if curves and cache array are same length
......@@ -134,33 +122,31 @@ THREE.CurvePath.prototype.getCurveLengths = function() {
return lengths;
};
},
/**************************************************************
/**************************************************************
* Create Geometries Helpers
**************************************************************/
/// Generate geometry from path points (for Line or Points objects)
/// Generate geometry from path points (for Line or Points objects)
THREE.CurvePath.prototype.createPointsGeometry = function( divisions ) {
createPointsGeometry: function ( divisions ) {
var pts = this.getPoints( divisions );
return this.createGeometry( pts );
};
},
// Generate geometry from equidistant sampling along the path
// Generate geometry from equidistant sampling along the path
THREE.CurvePath.prototype.createSpacedPointsGeometry = function( divisions ) {
createSpacedPointsGeometry: function ( divisions ) {
var pts = this.getSpacedPoints( divisions );
return this.createGeometry( pts );
};
},
THREE.CurvePath.prototype.createGeometry = function( points ) {
createGeometry: function ( points ) {
var geometry = new THREE.Geometry();
......@@ -173,4 +159,6 @@ THREE.CurvePath.prototype.createGeometry = function( points ) {
return geometry;
};
}
} );
......@@ -9,9 +9,7 @@ THREE.Font = function ( data ) {
};
THREE.Font.prototype = {
constructor: THREE.Font,
Object.assign( THREE.Font.prototype, {
generateShapes: function ( text, size, divisions ) {
......@@ -163,4 +161,4 @@ THREE.Font.prototype = {
}
};
} );
......@@ -18,15 +18,16 @@ THREE.Path = function ( points ) {
};
THREE.Path.prototype = Object.create( THREE.CurvePath.prototype );
THREE.Path.prototype.constructor = THREE.Path;
THREE.Path.prototype = Object.assign( Object.create( THREE.CurvePath.prototype ), {
// TODO Clean up PATH API
constructor: THREE.Path,
// Create path using straight lines to connect all points
// - vectors: array of Vector2
// TODO Clean up PATH API
THREE.Path.prototype.fromPoints = function ( vectors ) {
// Create path using straight lines to connect all points
// - vectors: array of Vector2
fromPoints: function ( vectors ) {
this.moveTo( vectors[ 0 ].x, vectors[ 0 ].y );
......@@ -36,17 +37,15 @@ THREE.Path.prototype.fromPoints = function ( vectors ) {
}
};
// startPath() endPath()?
},
THREE.Path.prototype.moveTo = function ( x, y ) {
moveTo: function ( x, y ) {
this.actions.push( { action: 'moveTo', args: [ x, y ] } );
};
},
THREE.Path.prototype.lineTo = function ( x, y ) {
lineTo: function ( x, y ) {
var lastargs = this.actions[ this.actions.length - 1 ].args;
......@@ -58,9 +57,9 @@ THREE.Path.prototype.lineTo = function ( x, y ) {
this.actions.push( { action: 'lineTo', args: [ x, y ] } );
};
},
THREE.Path.prototype.quadraticCurveTo = function( aCPx, aCPy, aX, aY ) {
quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
var lastargs = this.actions[ this.actions.length - 1 ].args;
......@@ -77,9 +76,9 @@ THREE.Path.prototype.quadraticCurveTo = function( aCPx, aCPy, aX, aY ) {
this.actions.push( { action: 'quadraticCurveTo', args: [ aCPx, aCPy, aX, aY ] } );
};
},
THREE.Path.prototype.bezierCurveTo = function( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
var lastargs = this.actions[ this.actions.length - 1 ].args;
......@@ -97,9 +96,9 @@ THREE.Path.prototype.bezierCurveTo = function( aCP1x, aCP1y, aCP2x, aCP2y, aX, a
this.actions.push( { action: 'bezierCurveTo', args: [ aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ] } );
};
},
THREE.Path.prototype.splineThru = function( pts /*Array of Vector*/ ) {
splineThru: function ( pts /*Array of Vector*/ ) {
var args = Array.prototype.slice.call( arguments );
......@@ -116,11 +115,9 @@ THREE.Path.prototype.splineThru = function( pts /*Array of Vector*/ ) {
this.actions.push( { action: 'splineThru', args: args } );
};
// FUTURE: Change the API or follow canvas API?
},
THREE.Path.prototype.arc = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
arc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
var lastargs = this.actions[ this.actions.length - 1 ].args;
var x0 = lastargs[ lastargs.length - 2 ];
......@@ -129,15 +126,15 @@ THREE.Path.prototype.arc = function ( aX, aY, aRadius, aStartAngle, aEndAngle, a
this.absarc( aX + x0, aY + y0, aRadius,
aStartAngle, aEndAngle, aClockwise );
};
},
THREE.Path.prototype.absarc = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
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 ) {
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 ];
......@@ -145,10 +142,9 @@ THREE.Path.prototype.ellipse = function ( aX, aY, xRadius, yRadius, aStartAngle,
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 ) {
absellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
var args = [
aX, aY,
......@@ -167,9 +163,9 @@ THREE.Path.prototype.absellipse = function ( aX, aY, xRadius, yRadius, aStartAng
this.actions.push( { action: 'ellipse', args: args } );
};
},
THREE.Path.prototype.getSpacedPoints = function ( divisions ) {
getSpacedPoints: function ( divisions ) {
if ( ! divisions ) divisions = 40;
......@@ -191,11 +187,9 @@ THREE.Path.prototype.getSpacedPoints = function ( divisions ) {
return points;
};
/* Return an array of vectors based on contour of the path */
},
THREE.Path.prototype.getPoints = function( divisions ) {
getPoints: function ( divisions ) {
divisions = divisions || 12;
......@@ -440,21 +434,9 @@ THREE.Path.prototype.getPoints = function( divisions ) {
return points;
};
//
// Breaks path into shapes
//
// Assumptions (if parameter isCCW==true the opposite holds):
// - solid shapes are defined clockwise (CW)
// - holes are defined counterclockwise (CCW)
//
// If parameter noHoles==true:
// - all subPaths are regarded as solid shapes
// - definition order CW/CCW has no relevance
//
},
THREE.Path.prototype.toShapes = function( isCCW, noHoles ) {
toShapes: function ( isCCW, noHoles ) {
function extractSubpaths( inActions ) {
......@@ -722,4 +704,6 @@ THREE.Path.prototype.toShapes = function( isCCW, noHoles ) {
return shapes;
};
}
} );
......@@ -17,28 +17,27 @@ THREE.Shape = function () {
};
THREE.Shape.prototype = Object.create( THREE.Path.prototype );
THREE.Shape.prototype.constructor = THREE.Shape;
THREE.Shape.prototype = Object.assign( Object.create( THREE.Path.prototype ), {
// Convenience method to return ExtrudeGeometry
constructor: THREE.Shape,
THREE.Shape.prototype.extrude = function ( options ) {
// Convenience method to return ExtrudeGeometry
extrude: function ( options ) {
return new THREE.ExtrudeGeometry( this, options );
};
},
// Convenience method to return ShapeGeometry
// Convenience method to return ShapeGeometry
THREE.Shape.prototype.makeGeometry = function ( options ) {
makeGeometry: function ( options ) {
return new THREE.ShapeGeometry( this, options );
};
},
// Get points of holes
THREE.Shape.prototype.getPointsHoles = function ( divisions ) {
getPointsHoles: function ( divisions ) {
var holesPts = [];
......@@ -50,12 +49,11 @@ THREE.Shape.prototype.getPointsHoles = function ( divisions ) {
return holesPts;
};
},
// Get points of shape and holes (keypoints based on segments parameter)
// Get points of shape and holes (keypoints based on segments parameter)
THREE.Shape.prototype.extractAllPoints = function ( divisions ) {
extractAllPoints: function ( divisions ) {
return {
......@@ -64,10 +62,12 @@ THREE.Shape.prototype.extractAllPoints = function ( divisions ) {
};
};
},
THREE.Shape.prototype.extractPoints = function ( divisions ) {
extractPoints: function ( divisions ) {
return this.extractAllPoints( divisions );
};
}
} );
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册