提交 eb17987e 编写于 作者: Z zz85

New Bevel algorithm, TextPath, TextGeometry updated

上级 b72d731c
......@@ -4,7 +4,10 @@
**/
THREE.ExtrudeGeometry = function( shapes, options ) {
if( typeof( shapes ) == "undefined" ) {
shapes = [];
}
THREE.Geometry.call( this );
shapes = shapes instanceof Array ? shapes : [ shapes ];
......@@ -12,8 +15,9 @@ THREE.ExtrudeGeometry = function( shapes, options ) {
var s=0, sl = shapes.length, shape;
for (;s<sl;s++) {
shape = shapes[s];
console.log(shape);
//console.log(shape);
this.addShape( shape, options );
}
......@@ -29,7 +33,7 @@ THREE.ExtrudeGeometry.prototype.addShape = function( shape, options ) {
var amount = options.amount !== undefined ? options.amount : 100;
var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6; // 10
var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 10; // 10
var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness; // 8
var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true; // false
......@@ -264,15 +268,15 @@ THREE.ExtrudeGeometry.prototype.addShape = function( shape, options ) {
// Loop bevelSegments, 1 for the front, 1 for the back
for ( b = bevelSegments; b > 0; b -- ) {
for ( b = 0; b < bevelSegments; b ++ ) {
//for ( b = bevelSegments; b > 0; b -- ) {
t = b / bevelSegments;
z = bevelThickness * t;
z = bevelThickness * ( 1-t);
// Formula could probably be simplified
//bs = bevelSize * (Math.sin ((1-t) * Math.PI/2 )) ; //bevelSize * t ;
bs = bevelSize * (1-t) ;
//z = bevelThickness * t;
bs = bevelSize * (Math.sin ((t) * Math.PI/2 )) ; // curved
//bs = bevelSize * t ; // linear
// contract shape
for ( i = 0, il = contour.length; i < il; i++ ) {
......@@ -284,8 +288,7 @@ THREE.ExtrudeGeometry.prototype.addShape = function( shape, options ) {
}
console.log(bs);
// expand holes
for ( h = 0, hl = holes.length; h < hl; h++ ) {
......@@ -306,17 +309,17 @@ THREE.ExtrudeGeometry.prototype.addShape = function( shape, options ) {
}
bs = bevelSize;
// Back facing vertices
for ( i = 0; i < vlen; i ++ ) {
vert = vertices[ i ];
//v( vert.x, vert.y, 0 );
//vert = vertices[ i ];
vert = scalePt2(vertices[ i ], verticesMovements[i], bs);
if ( !extrudeByPath ) {
vert = scalePt2(vert, verticesMovements[i], bs);
v( vert.x, vert.y, 0 );
} else {
......@@ -336,10 +339,11 @@ THREE.ExtrudeGeometry.prototype.addShape = function( shape, options ) {
for ( i = 0; i < vlen; i ++ ) {
vert = vertices[ i ];
//vert = vertices[ i ];
vert = scalePt2(vertices[ i ], verticesMovements[i], bs);
if ( !extrudeByPath ) {
vert = scalePt2(vert, verticesMovements[i], bs);
v( vert.x, vert.y, amount / steps * s );
} else {
......@@ -355,17 +359,20 @@ THREE.ExtrudeGeometry.prototype.addShape = function( shape, options ) {
// Add bevel segments planes
for ( b = 1; b <= bevelSegments; b ++ ) {
//for ( b = 1; b <= bevelSegments; b ++ ) {
for ( b = bevelSegments-1; b >= 0; b -- ) {
t = b / bevelSegments;
z = bevelThickness * t;
bs = bevelSize * ( 1-Math.sin ( ( 1 - t ) * Math.PI/2 ) );
z = bevelThickness * (1-t);
//bs = bevelSize * ( 1-Math.sin ( ( 1 - t ) * Math.PI/2 ) );
bs = bevelSize * Math.sin ( t * Math.PI/2 ) ;
// contract shape
for ( i = 0, il = contour.length; i < il; i++ ) {
vert = scalePt( contour[ i ], contourCentroid, bs, false );
vert = scalePt2(contour[i], contourMovements[i], bs);
//vert = scalePt( contour[ i ], contourCentroid, bs, false );
v( vert.x, vert.y, amount + z);
}
......@@ -375,10 +382,12 @@ THREE.ExtrudeGeometry.prototype.addShape = function( shape, options ) {
for ( h = 0, hl = holes.length; h < hl; h++ ) {
ahole = holes[ h ];
oneHoleMovements = holesMovements[h];
for ( i = 0, il = ahole.length; i < il; i++ ) {
vert = scalePt( ahole[ i ], holesCentroids[h], bs, true );
//vert = scalePt( ahole[ i ], holesCentroids[h], bs, true );
vert = scalePt2(ahole[i], oneHoleMovements[i], bs);
if ( !extrudeByPath ) {
......
......@@ -747,13 +747,14 @@ THREE.Path.prototype.toShapes = function() {
}
console.log(subPaths);
//console.log(subPaths);
if (subPaths.length ==0) return [];
var holesFirst = !THREE.Shape.Utils.isClockWise(subPaths[0].getPoints());
var tmpShape, shapes = [];
var tmpPath;
console.log("Holes first", holesFirst);
//console.log("Holes first", holesFirst);
if (holesFirst) {
tmpShape = new THREE.Shape();
......@@ -768,11 +769,11 @@ THREE.Path.prototype.toShapes = function() {
shapes.push(tmpShape);
tmpShape = new THREE.Shape();
console.log('cw', i);
//console.log('cw', i);
} else {
tmpShape.holes.push(tmpPath);
console.log('ccw', i);
//console.log('ccw', i);
}
......@@ -799,7 +800,7 @@ THREE.Path.prototype.toShapes = function() {
shapes.push(tmpShape);
}
console.log("shape", shapes);
//console.log("shape", shapes);
return shapes;
};
......@@ -35,35 +35,18 @@
*
*/
THREE.TextGeometry = function ( text, parameters ) {
THREE.Geometry.call( this );
THREE.TextPath = function ( text, parameters ) {
THREE.Path.call( this );
this.parameters = parameters || {};
this.set( text );
};
/*
var text3d = new TextGeometry(text);
FactoryStyle
var text3d = FontUtils.createText(text);
var textPath = new TextPath(text);
var textShapes = textPath.toShapes();
var text3d = new ExtrudeGeometry(textShapes, options);
var textShapes = FontUtils.getTextShapes(text);
text3d = new ExtrudeGeometry(textShapes, options);
*/
THREE.TextGeometry.prototype = new THREE.Geometry();
THREE.TextGeometry.prototype.constructor = THREE.TextGeometry;
THREE.TextGeometry.prototype.set = function ( text, parameters ) {
THREE.TextPath.prototype.set = function ( text, parameters ) {
this.text = text;
var parameters = parameters || this.parameters;
......@@ -92,7 +75,9 @@ THREE.TextGeometry.prototype.set = function ( text, parameters ) {
};
THREE.TextGeometry.prototype.get = function () {
THREE.TextPath.prototype.toShapes = function () {
// Get a Font data json object
......@@ -104,18 +89,51 @@ THREE.TextGeometry.prototype.get = function () {
for (var p=0, pl = paths.length; p<pl; p++) {
shapes = shapes.concat(paths[p].toShapes());
}
return shapes;
//console.log(path);
//console.log(fontShapes);
// Either find actions or curves.
var text3d = new THREE.ExtrudeGeometry( shapes , { amount: 20, bevelEnabled:true, bevelThickness:3 } );
// TOFIX: Fillet Cap
// FIX HOLES
return text3d;
//var text3d = new THREE.ExtrudeGeometry( shapes , { amount: 20, bevelEnabled:true, bevelThickness:3 } );
//return text3d;
};
THREE.TextGeometry = function ( text, parameters ) {
var textPath = new THREE.TextPath(text, parameters );
var textShapes = textPath.toShapes();
console.log("params", parameters);
THREE.ExtrudeGeometry.call( this, textShapes, parameters);
};
/*
var text3d = new TextGeometry(text);
FactoryStyle
var text3d = FontUtils.createText(text);
var textPath = new TextPath(text);
var textShapes = textPath.toShapes();
var text3d = new ExtrudeGeometry(textShapes, options);
var textShapes = FontUtils.getTextShapes(text);
text3d = new ExtrudeGeometry(textShapes, options);
*/
THREE.TextGeometry.prototype = new THREE.ExtrudeGeometry();
THREE.TextGeometry.prototype.constructor = THREE.TextGeometry;
THREE.FontUtils = {
faces : {},
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册