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

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

上级 d330d5b6
...@@ -16,161 +16,149 @@ THREE.CurvePath = function () { ...@@ -16,161 +16,149 @@ THREE.CurvePath = function () {
}; };
THREE.CurvePath.prototype = Object.create( THREE.Curve.prototype ); THREE.CurvePath.prototype = Object.assign( Object.create( THREE.Curve.prototype ), {
THREE.CurvePath.prototype.constructor = THREE.CurvePath;
THREE.CurvePath.prototype.add = function ( curve ) { constructor: THREE.CurvePath,
this.curves.push( curve ); 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() { },
// TODO Test closePath: function () {
// and verify for vector3 (needs to implement equals)
// Add a line curve if start and end of lines are not connected
var startPoint = this.curves[ 0 ].getPoint( 0 );
var endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
if ( ! startPoint.equals( endPoint ) ) { // TODO Test
// and verify for vector3 (needs to implement equals)
// Add a line curve if start and end of lines are not connected
var startPoint = this.curves[ 0 ].getPoint( 0 );
var endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
this.curves.push( new THREE.LineCurve( endPoint, startPoint ) ); if ( ! startPoint.equals( endPoint ) ) {
} this.curves.push( new THREE.LineCurve( endPoint, startPoint ) );
}; }
// 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 // To get accurate point with reference to
// 2. Locate and identify type of curve // entire path distance at time t,
// 3. Get t for the curve // following has to be done:
// 4. Return curve.getPointAt(t')
THREE.CurvePath.prototype.getPoint = function( 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')
var d = t * this.getLength(); getPoint: function ( t ) {
var curveLengths = this.getCurveLengths();
var i = 0;
// To think about boundaries points. var d = t * this.getLength();
var curveLengths = this.getCurveLengths();
var i = 0;
while ( i < curveLengths.length ) { // To think about boundaries points.
if ( curveLengths[ i ] >= d ) { while ( i < curveLengths.length ) {
var diff = curveLengths[ i ] - d; if ( curveLengths[ i ] >= d ) {
var curve = this.curves[ i ];
var u = 1 - diff / curve.getLength(); var diff = curveLengths[ i ] - d;
var curve = this.curves[ i ];
return curve.getPointAt( u ); var u = 1 - diff / curve.getLength();
} return curve.getPointAt( u );
i ++; }
} i ++;
return null; }
// loop where sum != 0, sum > d , sum+1 <d return null;
}; // 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 // We cannot use the default THREE.Curve getPoint() with getLength() because in
// THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
// getPoint() depends on getLength // getPoint() depends on getLength
THREE.CurvePath.prototype.getLength = function() { getLength: function () {
var lens = this.getCurveLengths(); var lens = this.getCurveLengths();
return lens[ lens.length - 1 ]; return lens[ lens.length - 1 ];
}; },
// Compute lengths and cache them // Compute lengths and cache them
// We cannot overwrite getLengths() because UtoT mapping uses it. // 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 // We use cache values if curves and cache array are same length
if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) { if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
return this.cacheLengths; return this.cacheLengths;
} }
// Get length of sub-curve // Get length of sub-curve
// Push sums into cached array // Push sums into cached array
var lengths = [], sums = 0; var lengths = [], sums = 0;
for ( var i = 0, l = this.curves.length; i < l; i ++ ) { for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
sums += this.curves[ i ].getLength(); sums += this.curves[ i ].getLength();
lengths.push( sums ); lengths.push( sums );
} }
this.cacheLengths = lengths; this.cacheLengths = lengths;
return lengths; return lengths;
}; },
/**************************************************************
* Create Geometries Helpers
**************************************************************/
/// Generate geometry from path points (for Line or Points objects)
/************************************************************** createPointsGeometry: function ( divisions ) {
* Create Geometries Helpers
**************************************************************/
/// Generate geometry from path points (for Line or Points objects) var pts = this.getPoints( divisions );
return this.createGeometry( pts );
THREE.CurvePath.prototype.createPointsGeometry = function( divisions ) { },
var pts = this.getPoints( divisions ); // Generate geometry from equidistant sampling along the path
return this.createGeometry( pts );
}; createSpacedPointsGeometry: function ( divisions ) {
// Generate geometry from equidistant sampling along the path var pts = this.getSpacedPoints( divisions );
return this.createGeometry( pts );
THREE.CurvePath.prototype.createSpacedPointsGeometry = function( divisions ) { },
var pts = this.getSpacedPoints( divisions ); createGeometry: function ( points ) {
return this.createGeometry( pts );
}; var geometry = new THREE.Geometry();
THREE.CurvePath.prototype.createGeometry = function( points ) { for ( var i = 0, l = points.length; i < l; i ++ ) {
var geometry = new THREE.Geometry(); var point = points[ i ];
geometry.vertices.push( new THREE.Vector3( point.x, point.y, point.z || 0 ) );
for ( var i = 0, l = points.length; i < l; i ++ ) { }
var point = points[ i ]; return geometry;
geometry.vertices.push( new THREE.Vector3( point.x, point.y, point.z || 0 ) );
} }
return geometry; } );
};
...@@ -9,9 +9,7 @@ THREE.Font = function ( data ) { ...@@ -9,9 +9,7 @@ THREE.Font = function ( data ) {
}; };
THREE.Font.prototype = { Object.assign( THREE.Font.prototype, {
constructor: THREE.Font,
generateShapes: function ( text, size, divisions ) { generateShapes: function ( text, size, divisions ) {
...@@ -163,4 +161,4 @@ THREE.Font.prototype = { ...@@ -163,4 +161,4 @@ THREE.Font.prototype = {
} }
}; } );
此差异已折叠。
...@@ -17,57 +17,57 @@ THREE.Shape = function () { ...@@ -17,57 +17,57 @@ THREE.Shape = function () {
}; };
THREE.Shape.prototype = Object.create( THREE.Path.prototype ); THREE.Shape.prototype = Object.assign( Object.create( THREE.Path.prototype ), {
THREE.Shape.prototype.constructor = THREE.Shape;
// Convenience method to return ExtrudeGeometry constructor: THREE.Shape,
THREE.Shape.prototype.extrude = function ( options ) { // Convenience method to return ExtrudeGeometry
return new THREE.ExtrudeGeometry( this, options ); extrude: function ( options ) {
}; return new THREE.ExtrudeGeometry( this, options );
// Convenience method to return ShapeGeometry },
THREE.Shape.prototype.makeGeometry = function ( options ) { // Convenience method to return ShapeGeometry
return new THREE.ShapeGeometry( this, 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 = []; var holesPts = [];
for ( var i = 0, l = this.holes.length; i < l; i ++ ) { for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
holesPts[ i ] = this.holes[ i ].getPoints( divisions ); holesPts[ i ] = this.holes[ i ].getPoints( divisions );
} }
return holesPts; return holesPts;
}; },
// Get points of shape and holes (keypoints based on segments parameter)
// Get points of shape and holes (keypoints based on segments parameter) extractAllPoints: function ( divisions ) {
THREE.Shape.prototype.extractAllPoints = function ( divisions ) { return {
return { shape: this.getPoints( divisions ),
holes: this.getPointsHoles( divisions )
shape: this.getPoints( divisions ), };
holes: this.getPointsHoles( divisions )
}; },
}; extractPoints: function ( divisions ) {
THREE.Shape.prototype.extractPoints = function ( divisions ) { return this.extractAllPoints( divisions );
return this.extractAllPoints( divisions ); }
}; } );
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册