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

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

上级 d330d5b6
......@@ -16,161 +16,149 @@ 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,
this.curves.push( curve );
add: function ( 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
};
*/
this.curves.push( curve );
THREE.CurvePath.prototype.closePath = function() {
},
// 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 );
closePath: function () {
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
// 2. Locate and identify type of curve
// 3. Get t for the curve
// 4. Return curve.getPointAt(t')
// To get accurate point with reference to
// entire path distance at time t,
// following has to be done:
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();
var curveLengths = this.getCurveLengths();
var i = 0;
getPoint: function ( t ) {
// 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;
var curve = this.curves[ i ];
if ( curveLengths[ i ] >= d ) {
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
// 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 ];
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
// 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
// Push sums into cached array
// Get length of sub-curve
// 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();
lengths.push( sums );
sums += this.curves[ i ].getLength();
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)
/**************************************************************
* Create Geometries Helpers
**************************************************************/
createPointsGeometry: function ( divisions ) {
/// 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 );
return this.createGeometry( pts );
// Generate geometry from equidistant sampling along the path
};
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 );
return this.createGeometry( pts );
createGeometry: function ( points ) {
};
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 ];
geometry.vertices.push( new THREE.Vector3( point.x, point.y, point.z || 0 ) );
return geometry;
}
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 = {
}
};
} );
此差异已折叠。
......@@ -17,57 +17,57 @@ 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
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.
先完成此消息的编辑!
想要评论请 注册