Prechádzať zdrojové kódy

committing text fix changes not pushed :(

zz85 14 rokov pred
rodič
commit
afe9d3b593
2 zmenil súbory, kde vykonal 81 pridanie a 66 odobranie
  1. 11 19
      examples/webgl_geometry_text.html
  2. 70 47
      src/extras/geometries/Text.js

+ 11 - 19
examples/webgl_geometry_text.html

@@ -45,17 +45,17 @@
 		 <script type="text/javascript" src="../src/extras/geometries/Text.js"></script> 
             <!--  
         
-         <script type="text/javascript" src="helvetiker-normal-normal.js"></script>
          http://canvas-text.googlecode.com/svn-history/r41/trunk/faces/dejavu_serif-normal-normal.js
   optimer-normal-normal.js
   gentilis-normal-normal
   http://canvas-text.googlecode.com/svn-history/r41/trunk/faces/helvetiker-normal-normal.js
-http://canvas-text.googlecode.com/svn-history/r41/trunk/faces/dejavu_sans-normal-normal.js
+	http://canvas-text.googlecode.com/svn-history/r41/trunk/faces/dejavu_sans-normal-normal.js
 
 	http://canvas-text.googlecode.com/svn-history/r41/trunk/faces/optimer-normal-normal.js
 	http://canvas-text.googlecode.com/svn-history/r41/trunk/faces/gentilis-normal-normal.js
+	optimer-bold-normal
   -->
-	<script type="text/javascript" src="http://canvas-text.googlecode.com/svn-history/r41/trunk/faces/optimer-normal-normal.js"></script>
+	<script type="text/javascript" src="http://canvas-text.googlecode.com/svn-history/r41/trunk/faces/gentilis-normal-normal.js"></script>
 
         	<script type="text/javascript" src="js/helvetiker-normal-normal.js"></script>
 		<script type="text/javascript">
@@ -94,12 +94,7 @@ http://canvas-text.googlecode.com/svn-history/r41/trunk/faces/dejavu_sans-normal
 
 				scene = new THREE.Scene();
 
-				// text
-
-			
-
-				
-                
+                //THREE.FontUtils.weight = "bold";
                 
 				// Materials
 				
@@ -167,13 +162,15 @@ http://canvas-text.googlecode.com/svn-history/r41/trunk/faces/dejavu_sans-normal
                    theText = hash;
                   }
                 
-				//var
-				   text3d = new THREE.Text(theText, {
+				textParams = {
 						size: 80, 
 						height:40,
 						curveSegments:2,
-						font: "optimer"
-					});//dejavu sans
+						font: "gentilis" //gentilis helvetiker
+					};
+				
+				//var
+				   text3d = new THREE.Text(theText, textParams);//dejavu sans
 					
                 //MEsh Normal MeshBasic
                 //MeshPhongMaterial MeshLambertMaterial MeshPhongMaterial
@@ -315,12 +312,7 @@ http://canvas-text.googlecode.com/svn-history/r41/trunk/faces/dejavu_sans-normal
 					*/
 					
 					scene.removeChild(text);
-					 text3d = new THREE.Text(effectController.text, {
-							size: 80, 
-							height:40,
-							curveSegments:2,
-							font: "helvetiker" //"helvetiker"
-						});
+					 text3d = new THREE.Text(effectController.text, textParams);
 					text = new THREE.Mesh( text3d, textMaterial)
 					scene.addChild(text);
 					

+ 70 - 47
src/extras/geometries/Text.js

@@ -181,7 +181,7 @@ THREE.FontUtils = {
 	},
 
 
-	extractPoints : function(points) {
+	extractPoints : function(points, characters) {
 	    // Quick Exit
 	    if (points.length <3) {
 			// throw new exception("")
@@ -191,53 +191,74 @@ THREE.FontUtils = {
 		}
     
 		// Try to split shapes and holes.
-		var all = [], point, shape;
+		var all, point, shape;
     
 	    var isolatedShapes = [];
-	
-	    // Use a quick hashmap for locating duplicates
-		for (var p in points) {
-			point = points[p];
-			all.push(point.x +","+ point.y);
-		}
-	
-	
-	
-		var firstPt = all[0];
-		var endPt = all.slice(1).indexOf(firstPt);
-	
-		if (endPt < all.length) {
-			endPt ++;
-			shape = points.slice(0, endPt);
-		}
-	
-		holes = [];
-    
-		while (endPt < all.length) {
-			firstIndex = endPt+1;
-			firstPt = all[firstIndex];
-			endPt = all.slice(firstIndex+1).indexOf(firstPt) + firstIndex;
-			if (endPt <= firstIndex ) break; 
 		
-			var contours = points.slice(firstIndex, endPt+1);
+		for (var c in characters) {
+			points = characters[c];
+			
+			
+			all = [];
+		    // Use a quick hashmap for locating duplicates
+			for (var p in points) {
+				point = points[p];
+				all.push(point.x +","+ point.y);
+			}
+			
+			var firstPt, endPt, holes;
+			
+			// We check the first loop whether its CW or CCW direction to determine
+			// whether its shapes or holes first
+			endPt = all.slice(1).indexOf(all[0]);
+			var shapesFirst = this.Triangulate.area(points.slice(0, endPt+1))<0;
+			
+			//console.log(points.length, "shapesFirst",shapesFirst);
+		
+			holes = [];
+			endPt = -1;
+    
+			while (endPt < all.length) {
+				firstIndex = endPt+1;
+				firstPt = all[firstIndex];
+				endPt = all.slice(firstIndex+1).indexOf(firstPt) + firstIndex;
+				if (endPt <= firstIndex ) break; 
 		
-			if (this.Triangulate.area(contours)<0) {
-	            isolatedShapes.push({shape: shape, holes: holes});
-				// Save the old shapes, then work on new additional seperated shape
+				var contours = points.slice(firstIndex, endPt+1);
+			
+				if (shapesFirst) {
+					if (this.Triangulate.area(contours)<0) {
+						// we got new isolated shape
+						if (firstIndex>0) {
+			            	isolatedShapes.push({shape: shape, holes: holes});
+						}
+						// Save the old shapes, then work on new additional seperated shape
             
-	            shape = contours;
-	            holes = [];
+			            shape = contours;
+			            holes = [];
             
-			} else {
-	            holes.push(contours);
-			}
-        
-			endPt++;		
+					} else {
+			            holes.push(contours);
+					}
+				} else {
+					if (this.Triangulate.area(contours)<0) {		            
+			            
+						isolatedShapes.push({shape: contours, holes: holes});
+			            holes = [];
+            
+					} else {
+			            holes.push(contours);
+					}
+				}
+				endPt++;
 		
-		}
+			}
     
-	    isolatedShapes.push({shape: shape, holes: holes});
-	
+			if (shapesFirst) {
+		    	isolatedShapes.push({shape: shape, holes: holes});
+			}
+		}
+		
 		//console.log("isolatedShapes", isolatedShapes);
 	
     
@@ -365,7 +386,7 @@ THREE.FontUtils = {
 	},
 
 	drawText : function(text) {
-	    pts = [];
+	    var characterpts = [], pts = [];
 	
 	    // RenderText
 	    var face = this.getFace(),
@@ -374,17 +395,18 @@ THREE.FontUtils = {
 	        chars = String(text).split(''), 
 	        length = chars.length;
 	    for (i = 0; i < length; i++) {
-	      offset += this.extractGlyphPoints(chars[i], face, scale, offset); 
+	     	ret = this.extractGlyphPoints(chars[i], face, scale, offset); 
+			offset += ret.offset;
+			characterpts.push(ret.points);
+			pts = pts.concat(ret.points);
 	    }
-    
-	    // get the width 
+    	// get the width 
 	    width = offset/2;
 	    for (var p in pts) {
 	        pts[p].x -= width;
 	    }
 	
-	    var extract = this.extractPoints(pts);
-    
+	    var extract = this.extractPoints(pts, characterpts);
 	    extract.contour = pts;
 	    return extract;
     
@@ -439,6 +461,7 @@ THREE.FontUtils = {
 	extractGlyphPoints : function(c, face, scale, offset){
 	      var i, cpx, cpy, outline, action, length,
 	          glyph = face.glyphs[c] || face.glyphs[ctxt.options.fallbackCharacter];
+			var pts = [];
     
 	      if (!glyph) return;
   
@@ -514,7 +537,7 @@ THREE.FontUtils = {
 	          }
 	        }
 	      }
-	      return glyph.ha*scale;
+	      return { offset: glyph.ha*scale, points:pts };
 	    }