TextPath.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /**
  2. * @author zz85 / http://www.lab4games.net/zz85/blog
  3. *
  4. * TextPath - not sure if there's much use for this class.
  5. only thing it has it .toShapes() which can be removed by refactoring.
  6. *
  7. **/
  8. THREE.TextPath = function ( text, parameters ) {
  9. THREE.Path.call( this );
  10. this.parameters = parameters || {};
  11. this.set( text );
  12. };
  13. THREE.TextPath.prototype.set = function ( text, parameters ) {
  14. parameters = parameters || this.parameters;
  15. this.text = text;
  16. var size = parameters.size !== undefined ? parameters.size : 100;
  17. var curveSegments = parameters.curveSegments !== undefined ? parameters.curveSegments: 4;
  18. var font = parameters.font !== undefined ? parameters.font : "helvetiker";
  19. var weight = parameters.weight !== undefined ? parameters.weight : "normal";
  20. var style = parameters.style !== undefined ? parameters.style : "normal";
  21. THREE.FontUtils.size = size;
  22. THREE.FontUtils.divisions = curveSegments;
  23. THREE.FontUtils.face = font;
  24. THREE.FontUtils.weight = weight;
  25. THREE.FontUtils.style = style;
  26. };
  27. THREE.TextPath.prototype.toShapes = function () {
  28. // Get a Font data json object
  29. var data = THREE.FontUtils.drawText( this.text );
  30. var paths = data.paths;
  31. var shapes = [];
  32. for ( var p = 0, pl = paths.length; p < pl; p ++ ) {
  33. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  34. }
  35. return shapes;
  36. };