فهرست منبع

Updated text example with normals hack to be able to use smooth shading also for unbeveled geometry.

alteredq 14 سال پیش
والد
کامیت
76b8032e1a
1فایلهای تغییر یافته به همراه27 افزوده شده و 1 حذف شده
  1. 27 1
      examples/webgl_geometry_text.html

+ 27 - 1
examples/webgl_geometry_text.html

@@ -386,6 +386,7 @@
 			}
 
 			function createText() {
+
 				textGeo = new THREE.TextGeometry( text, {
 
 					size: size,
@@ -403,13 +404,38 @@
 					bend: bend,
 
 					material: textMaterialFront,
-					extrudeMaterial: bevelEnabled ? textMaterialSide : textMaterialFront
+					extrudeMaterial: textMaterialSide
 
 				});
 
 				textGeo.computeBoundingBox();
 				textGeo.computeVertexNormals();
 
+				// "fix" side normals by removing z-component of normals for side faces
+				// (this doesn't work well for beveled geometry as then we lose nice curvature around z-axis)
+
+				if ( ! bevelEnabled ) {
+
+					for ( var i = 0; i < textGeo.faces.length; i ++ ) {
+
+						var face = textGeo.faces[ i ];
+
+						if ( face.materials[ 0 ].id == textMaterialSide.id ) {
+
+							for ( var j = 0; j < face.vertexNormals.length; j ++ ) {
+
+								face.vertexNormals[ j ].z = 0;
+								face.vertexNormals[ j ].normalize();
+
+							}
+
+						}
+
+
+					}
+
+				}
+
 				var centerOffset = -0.5 * ( textGeo.boundingBox.x[ 1 ] - textGeo.boundingBox.x[ 0 ] );
 
 				textMesh1 = new THREE.Mesh( textGeo, faceMaterial );