From a7b7377c03d688245a11002b466b0d435456d617 Mon Sep 17 00:00:00 2001 From: zz85 Date: Tue, 2 Aug 2011 04:17:58 +0800 Subject: [PATCH] Added curve segments parameter passing. defaults to 6 --- src/extras/geometries/Curve.js | 52 ++++++++---------------- src/extras/geometries/ExtrudeGeometry.js | 13 ++++-- src/extras/geometries/Shape.js | 20 ++++----- 3 files changed, 37 insertions(+), 48 deletions(-) diff --git a/src/extras/geometries/Curve.js b/src/extras/geometries/Curve.js index 0b4b501d..6c913ecb 100644 --- a/src/extras/geometries/Curve.js +++ b/src/extras/geometries/Curve.js @@ -430,29 +430,23 @@ THREE.Curve.create = function(constructor, getpointfunc) { THREE.LineCurve3 = THREE.Curve.create( - function ( x1, y1, z1, x2, y2, z2 ) { + function ( v1, v2 ) { - this.x1 = x1; - this.y1 = y1; - this.z1 = z1; - - this.x2 = x2; - this.y2 = y2; - this.z2 = z2; + this.v1 = v1; + this.v2 = v2; }, function ( t ) { - - var dx = this.x2 - this.x1; - var dy = this.y2 - this.y1; - var dz = this.z2 - this.z1; - var tx = this.x1 + dx * t; - var ty = this.y1 + dy * t; - var tz = this.z1 + dz * t; + var r = new THREE.Vector3(); + + + r.sub(v2, v1); // diff + r.multiplyScalar(t); + r.addSelf(this.v1); - return new THREE.Vector3( tx, ty, tz ); + return r; } ); @@ -463,21 +457,11 @@ THREE.LineCurve3 = THREE.Curve.create( **************************************************************/ THREE.QuadraticBezierCurve3 = THREE.Curve.create( - function ( x0, y0, z0, - x1, y1, z1, - x2, y2, z2 ) { // Qn should we use 2 Vector3 instead? + function ( v0, v1, v2 ) { // Qn should we use 2 Vector3 instead? - this.x0 = x0; - this.y0 = y0; - this.z0 = z0; - - this.x1 = x1; - this.y1 = y1; - this.z1 = z1; - - this.x2 = x2; - this.y2 = y2; - this.z2 = z2; + this.v0 = v0; + this.v1 = v1; + this.v2 = v2; }, @@ -485,11 +469,11 @@ THREE.QuadraticBezierCurve3 = THREE.Curve.create( var tx, ty, tz; - tx = THREE.Shape.Utils.b2( t, this.x0, this.x1, this.x2 ); - ty = THREE.Shape.Utils.b2( t, this.y0, this.y1, this.y2 ); - tz = THREE.Shape.Utils.b2( t, this.z0, this.z1, this.z2 ); + tx = THREE.Shape.Utils.b2( t, this.v0.x, this.v1.x, this.v2.x ); + ty = THREE.Shape.Utils.b2( t, this.v0.y, this.v1.y, this.v2.y ); + tz = THREE.Shape.Utils.b2( t, this.v0.z, this.v1.z, this.v2.z ); - return new THREE.Vector2( tx, ty, tz ); + return new THREE.Vector3( tx, ty, tz ); } ); diff --git a/src/extras/geometries/ExtrudeGeometry.js b/src/extras/geometries/ExtrudeGeometry.js index 9b0bcdf6..13b7fcb9 100644 --- a/src/extras/geometries/ExtrudeGeometry.js +++ b/src/extras/geometries/ExtrudeGeometry.js @@ -21,6 +21,8 @@ THREE.ExtrudeGeometry = function( shapes, options ) { + // var startTime = Date.now(); + if( typeof( shapes ) == "undefined" ) { shapes = []; @@ -41,6 +43,9 @@ THREE.ExtrudeGeometry = function( shapes, options ) { this.addShape( shape, options ); } + + // console.log( "faces", this.faces.length, "vertices", this.vertices.length ); + // console.log( "took", ( Date.now() - startTime ) ); }; @@ -50,7 +55,7 @@ THREE.ExtrudeGeometry.prototype.constructor = THREE.ExtrudeGeometry; THREE.ExtrudeGeometry.prototype.addShape = function( shape, options ) { - //var startTime = Date.now(); + var amount = options.amount !== undefined ? options.amount : 100; @@ -59,7 +64,8 @@ THREE.ExtrudeGeometry.prototype.addShape = function( shape, options ) { var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3; var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true; // false - + + var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 2; var steps = options.steps !== undefined ? options.steps : 1; @@ -96,7 +102,7 @@ THREE.ExtrudeGeometry.prototype.addShape = function( shape, options ) { var shapesOffset = this.vertices.length; - var shapePoints = shape.extractAllPoints(); // use shape.extractAllSpacedPoints() for points with equal divisions + var shapePoints = shape.extractAllPoints(curveSegments); // use shape.extractAllSpacedPoints() for points with equal divisions var vertices = shapePoints.shape; var holes = shapePoints.holes; @@ -630,7 +636,6 @@ THREE.ExtrudeGeometry.prototype.addShape = function( shape, options ) { this.computeFaceNormals(); //this.computeVertexNormals(); - //console.log( "took", ( Date.now() - startTime ) ); function v( x, y, z ) { diff --git a/src/extras/geometries/Shape.js b/src/extras/geometries/Shape.js index 98e269ae..ef789ce1 100644 --- a/src/extras/geometries/Shape.js +++ b/src/extras/geometries/Shape.js @@ -30,14 +30,14 @@ THREE.Shape.prototype.extrude = function ( options ) { // Get points of holes -THREE.Shape.prototype.getPointsHoles = function () { +THREE.Shape.prototype.getPointsHoles = function (segments) { var i, il = this.holes.length, holesPts = []; for ( i = 0; i < il; i ++ ) { - holesPts[ i ] = this.holes[ i ].getPoints(); + holesPts[ i ] = this.holes[ i ].getPoints(segments); } @@ -47,13 +47,13 @@ THREE.Shape.prototype.getPointsHoles = function () { // Get points of holes (spaced by regular distance) -THREE.Shape.prototype.getSpacedPointsHoles = function () { +THREE.Shape.prototype.getSpacedPointsHoles = function (segments) { var i, il = this.holes.length, holesPts = []; for ( i = 0; i < il; i ++ ) { - holesPts[ i ] = this.holes[ i ].getSpacedPoints(); + holesPts[ i ] = this.holes[ i ].getSpacedPoints(segments); } @@ -64,12 +64,12 @@ THREE.Shape.prototype.getSpacedPointsHoles = function () { // Get points of shape and holes (keypoints based on segments parameter) -THREE.Shape.prototype.extractAllPoints = function () { +THREE.Shape.prototype.extractAllPoints = function (segments) { return { - shape: this.getPoints(), - holes: this.getPointsHoles() + shape: this.getPoints(segments), + holes: this.getPointsHoles(segments) }; @@ -77,12 +77,12 @@ THREE.Shape.prototype.extractAllPoints = function () { // Get points of shape and holes (spaced by regular distance) -THREE.Shape.prototype.extractAllSpacedPoints = function () { +THREE.Shape.prototype.extractAllSpacedPoints = function (segments) { return { - shape: this.getSpacedPoints(), - holes: this.getSpacedPointsHoles() + shape: this.getSpacedPoints(segments), + holes: this.getSpacedPointsHoles(segments) };