Browse Source

Fixed bevel but yet another problem

zz85 14 years ago
parent
commit
7dbf0554fd

+ 22 - 58
src/extras/geometries/ExtrudeGeometry.js

@@ -29,7 +29,7 @@ THREE.ExtrudeGeometry.prototype.addShape = function( shape, options ) {
 
 
 	var amount = options.amount !== undefined ? options.amount : 100;
 	var amount = options.amount !== undefined ? options.amount : 100;
 
 
-	var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 8; // 10
+	var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6; // 10
 	var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness; // 8 
 	var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness; // 8 
 	var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true; // false
 	var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true; // false
 	var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
 	var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
@@ -177,72 +177,39 @@ THREE.ExtrudeGeometry.prototype.addShape = function( shape, options ) {
 
 
 	
 	
 	function getBevelVec(pt_i, pt_j, pt_k) {
 	function getBevelVec(pt_i, pt_j, pt_k) {
+		
 		var anglea = Math.atan2(pt_j.y - pt_i.y, pt_j.x - pt_i.x);
 		var anglea = Math.atan2(pt_j.y - pt_i.y, pt_j.x - pt_i.x);
 		var angleb = Math.atan2(pt_k.y - pt_i.y, pt_k.x - pt_i.x);
 		var angleb = Math.atan2(pt_k.y - pt_i.y, pt_k.x - pt_i.x);
-		//var anglea = Math.atan2(pt_i.y - pt_j.y, pt_i.x - pt_j.x);
-		//var angleb = Math.atan2(pt_i.y - pt_k.y, pt_i.x - pt_k.x);
-		//if (anglea < 0 ) anglea += Math.PI * 2;
-		/*
-		if (angleb <= 0 ) {
-			angleb += Math.PI * 2;
-			console.log('ping');
+		
+		if ( anglea > angleb) {
+			angleb += Math.PI*2;
 		}
 		}
-		*/
 		
 		
 		
 		
-		x = Math.cos(anglea) + Math.cos(angleb);
-		y = Math.sin(anglea) + Math.sin(angleb);
-		anglec = Math.atan2(y,x);
+		// var anglea = Math.atan2(pt_i.y - pt_j.y, pt_i.x - pt_j.x);
+		// 	var angleb = Math.atan2(pt_i.y - pt_k.y, pt_i.x - pt_k.x);
+		// 	
+		// 	console.log('>?', anglea > angleb);
+		// 	
+		// 	if ( anglea < angleb) {
+		// 		angleb += Math.PI*2;
+		// 	}
 		
 		
 		
 		
-		console.log('angle1', anglea * RAD_TO_DEGREES,'angle2', angleb * RAD_TO_DEGREES, 'anglec', anglec *RAD_TO_DEGREES);
+		//x = Math.cos(anglea) + Math.cos(angleb);
+		//y = Math.sin(anglea) + Math.sin(angleb);
+		//anglec = Math.atan2(y,x);
 		
 		
-		/*
-		x = bevelSize * Math.cos(anglec);
-		y = bevelSize * Math.sin(anglec);
 		
 		
-		var vec = new THREE.Vector2(x,y).divideScalar(bevelSize);
-		*/
+		anglec = (anglea + angleb ) / 2;
+				
+		//console.log('angle1', anglea * RAD_TO_DEGREES,'angle2', angleb * RAD_TO_DEGREES, 'anglec', anglec *RAD_TO_DEGREES);
 		
 		
 		var x = Math.cos(anglec);
 		var x = Math.cos(anglec);
 		var y = Math.sin(anglec);
 		var y = Math.sin(anglec);
-		
-		// Check quadrants?
-		console.log(x,y,'x,y');
-		
-		/*
-		var quad1 = Math.PI/2;
-		var quad2 = Math.PI;
-		var quad3 = Math.PI * 3/2
-		var quad4 = Math.PI * 2
-		
-		anglec %= quad4;
-		if (anglec < 0 ) anglec += quad4;
-		console.log('>0', anglec * RAD_TO_DEGREES);
 	
 	
-		if (anglec < quad1) {
-
-			
-		} else
-		if (anglec < quad2) {
-			x = -x;
-			
-		} else if (anglec < quad3) {
-			y = -y;
-			x = -x;
-		} else if (anglec < quad4) {
-			
-			y = -y;
-		} else {
-			console.log("die");
-			
-			
-		}
-		*/
-		
-		var vec = new THREE.Vector2(x,y);
+		var vec = new THREE.Vector2(x,y).normalize();
 		
 		
-		console.log('xy', x, y, vec, pt_i.x +x , pt_i.y + y);
 		return vec;
 		return vec;
 	}
 	}
 	
 	
@@ -253,9 +220,8 @@ THREE.ExtrudeGeometry.prototype.addShape = function( shape, options ) {
 		if (k==il) k = 0;
 		if (k==il) k = 0;
 		
 		
 		//  (j)---(i)---(k)
 		//  (j)---(i)---(k)
-		console.log('i,j,k', i, j , k)
+		// console.log('i,j,k', i, j , k)
 
 
-		
 		var pt_i = contour[ i ];
 		var pt_i = contour[ i ];
 		var pt_j = contour[ j ];
 		var pt_j = contour[ j ];
 		var pt_k = contour[ k ];
 		var pt_k = contour[ k ];
@@ -266,7 +232,7 @@ THREE.ExtrudeGeometry.prototype.addShape = function( shape, options ) {
 	}
 	}
 	
 	
 	var holesMovements = [], oneHoleMovements;
 	var holesMovements = [], oneHoleMovements;
-	// expand holes
+	
 	for ( h = 0, hl = holes.length; h < hl; h++ ) {
 	for ( h = 0, hl = holes.length; h < hl; h++ ) {
 
 
 		ahole = holes[h];
 		ahole = holes[h];
@@ -278,10 +244,8 @@ THREE.ExtrudeGeometry.prototype.addShape = function( shape, options ) {
 			if (k==il) k = 0;
 			if (k==il) k = 0;
 
 
 			//  (j)---(i)---(k)
 			//  (j)---(i)---(k)
-
 			oneHoleMovements[i]= getBevelVec(ahole[ i ], ahole[ j ], ahole[ k ] );
 			oneHoleMovements[i]= getBevelVec(ahole[ i ], ahole[ j ], ahole[ k ] );
 
 
-
 		}
 		}
 		
 		
 		holesMovements.push(oneHoleMovements);
 		holesMovements.push(oneHoleMovements);

+ 8 - 2
src/extras/geometries/Path.js

@@ -710,7 +710,7 @@ THREE.Path.prototype.toShapes = function() {
 		action = item.action;
 		action = item.action;
 		
 		
 		if (action==THREE.PathActions.MOVE_TO) {
 		if (action==THREE.PathActions.MOVE_TO) {
-			if (lastPath.actions!=0) {
+			if (lastPath.actions.length!=0) {
 				
 				
 				subPaths.push(lastPath);
 				subPaths.push(lastPath);
 				lastPath = new THREE.Path();
 				lastPath = new THREE.Path();
@@ -721,7 +721,7 @@ THREE.Path.prototype.toShapes = function() {
 		
 		
 	}
 	}
 	
 	
-	if (lastPath.actions!=0) {	
+	if (lastPath.actions.length!=0) {	
 	
 	
 		subPaths.push(lastPath);
 		subPaths.push(lastPath);
 		
 		
@@ -733,6 +733,8 @@ THREE.Path.prototype.toShapes = function() {
 	var tmpShape, shapes = [];
 	var tmpShape, shapes = [];
 	var tmpPath;
 	var tmpPath;
 	
 	
+	console.log("Holes first", holesFirst);
+	
 	if (holesFirst) {
 	if (holesFirst) {
 		tmpShape = new THREE.Shape();
 		tmpShape = new THREE.Shape();
 		for ( i=0, il = subPaths.length; i<il; i++) {
 		for ( i=0, il = subPaths.length; i<il; i++) {
@@ -746,8 +748,12 @@ THREE.Path.prototype.toShapes = function() {
 				shapes.push(tmpShape);
 				shapes.push(tmpShape);
 				tmpShape = new THREE.Shape();
 				tmpShape = new THREE.Shape();
 				
 				
+				console.log('cw', i);
+				
 			} else {
 			} else {
 				tmpShape.holes.push(tmpPath);
 				tmpShape.holes.push(tmpPath);
+				console.log('ccw', i);
+				
 			}
 			}
 		
 		
 		}
 		}

+ 39 - 18
src/extras/geometries/TextGeometry.js

@@ -44,6 +44,22 @@ THREE.TextGeometry = function ( text, 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.Geometry();
 THREE.TextGeometry.prototype = new THREE.Geometry();
 THREE.TextGeometry.prototype.constructor = THREE.TextGeometry;
 THREE.TextGeometry.prototype.constructor = THREE.TextGeometry;
 
 
@@ -73,19 +89,6 @@ THREE.TextGeometry.prototype.set = function ( text, parameters ) {
 
 
 	THREE.FontUtils.bezelSize = bezelSize;
 	THREE.FontUtils.bezelSize = bezelSize;
 
 
-	// Get a Font data json object
-
-	var data = THREE.FontUtils.drawText( text );
-	
-	var path = data.path;
-	
-	//path.debug(document.getElementById("boo"));
-	
-	this.fontShapes = path.toShapes();
-	console.log(path);
-	//console.log(fontShapes);
-	
-	// Either find actions or curves.
 	
 	
 	
 	
 	
 	
@@ -94,8 +97,26 @@ THREE.TextGeometry.prototype.set = function ( text, parameters ) {
 };
 };
 
 
 THREE.TextGeometry.prototype.get = function () {
 THREE.TextGeometry.prototype.get = function () {
-	var text3d = new THREE.ExtrudeGeometry( this.fontShapes , { amount: 20, bevelEnabled:false, bevelThickness:3	} );
+	
+	
+	// Get a Font data json object
+
+	var data = THREE.FontUtils.drawText( this.text );
+	
+	var paths = data.paths;
+	var shapes = [];
+	for (var p=0, pl = paths.length; p<pl; p++) {
+		shapes = shapes.concat(paths[p].toShapes());
+	}
+
+	//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
 	// TOFIX: Fillet Cap
+	// FIX HOLES
 	return text3d;	
 	return text3d;	
 };
 };
 
 
@@ -505,14 +526,14 @@ THREE.FontUtils = {
 
 
 		var fontPaths = [];
 		var fontPaths = [];
 
 
-		var path = new THREE.Path();
+		
 		for ( i = 0; i < length; i++ ) {
 		for ( i = 0; i < length; i++ ) {
-			
+			var path = new THREE.Path();
 			var ret = this.extractGlyphPoints( chars[ i ], face, scale, offset, path );
 			var ret = this.extractGlyphPoints( chars[ i ], face, scale, offset, path );
 			offset += ret.offset;
 			offset += ret.offset;
 			characterPts.push( ret.points );
 			characterPts.push( ret.points );
 			allPts = allPts.concat( ret.points );
 			allPts = allPts.concat( ret.points );
-			//fontPaths.push( ret.path );
+			fontPaths.push( ret.path );
 			
 			
 		}
 		}
 		
 		
@@ -529,7 +550,7 @@ THREE.FontUtils = {
 
 
 		var extract = this.extractPoints( allPts, characterPts );
 		var extract = this.extractPoints( allPts, characterPts );
 		extract.contour = allPts;
 		extract.contour = allPts;
-		extract.path = path;
+		extract.paths = fontPaths;
 
 
 		var bezelPoints = [];
 		var bezelPoints = [];