TextPath.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * @author zz85 / http://www.lab4games.net/zz85/blog
  3. *
  4. * TextPath
  5. *
  6. **/
  7. THREE.TextPath = function ( text, parameters ) {
  8. THREE.Path.call( this );
  9. this.parameters = parameters || {};
  10. this.set( text );
  11. };
  12. THREE.TextPath.prototype.set = function ( text, parameters ) {
  13. this.text = text;
  14. var parameters = parameters || this.parameters;
  15. var size = parameters.size !== undefined ? parameters.size : 100;
  16. var curveSegments = parameters.curveSegments !== undefined ? parameters.curveSegments: 4;
  17. var font = parameters.font !== undefined ? parameters.font : "helvetiker";
  18. var weight = parameters.weight !== undefined ? parameters.weight : "normal";
  19. var style = parameters.style !== undefined ? parameters.style : "normal";
  20. THREE.FontUtils.size = size;
  21. THREE.FontUtils.divisions = curveSegments;
  22. THREE.FontUtils.face = font;
  23. THREE.FontUtils.weight = weight;
  24. THREE.FontUtils.style = style;
  25. };
  26. THREE.TextPath.prototype.toShapes = function () {
  27. // Get a Font data json object
  28. var data = THREE.FontUtils.drawText( this.text );
  29. var paths = data.paths;
  30. var shapes = [];
  31. for ( var p = 0, pl = paths.length; p < pl; p ++ ) {
  32. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  33. }
  34. return shapes;
  35. //console.log(path);
  36. //console.log(fontShapes);
  37. // Either find actions or curves.
  38. //var text3d = new THREE.ExtrudeGeometry( shapes , { amount: 20, bevelEnabled:true, bevelThickness:3 } );
  39. //return text3d;
  40. };
粤ICP备19079148号