TextGeometry.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /**
  2. * @author zz85 / http://www.lab4games.net/zz85/blog
  3. * @author alteredq / http://alteredqualia.com/
  4. *
  5. * Text = 3D Text
  6. *
  7. * parameters = {
  8. * font: <THREE.Font>, // font
  9. *
  10. * size: <float>, // size of the text
  11. * height: <float>, // thickness to extrude text
  12. * curveSegments: <int>, // number of points on the curves
  13. *
  14. * bevelEnabled: <bool>, // turn on bevel
  15. * bevelThickness: <float>, // how deep into text bevel goes
  16. * bevelSize: <float> // how far from text outline is bevel
  17. * }
  18. */
  19. import { Geometry } from '../core/Geometry.js';
  20. import { ExtrudeBufferGeometry } from './ExtrudeGeometry.js';
  21. // TextGeometry
  22. function TextGeometry( text, parameters ) {
  23. Geometry.call( this );
  24. this.type = 'TextGeometry';
  25. this.parameters = {
  26. text: text,
  27. parameters: parameters
  28. };
  29. this.fromBufferGeometry( new TextBufferGeometry( text, parameters ) );
  30. this.mergeVertices();
  31. }
  32. TextGeometry.prototype = Object.create( Geometry.prototype );
  33. TextGeometry.prototype.constructor = TextGeometry;
  34. // TextBufferGeometry
  35. function TextBufferGeometry( text, parameters ) {
  36. parameters = parameters || {};
  37. var font = parameters.font;
  38. if ( ! ( font && font.isFont ) ) {
  39. console.error( 'THREE.TextGeometry: font parameter is not an instance of THREE.Font.' );
  40. return new Geometry();
  41. }
  42. var shapes = font.generateShapes( text, parameters.size );
  43. // translate parameters to ExtrudeGeometry API
  44. parameters.depth = parameters.height !== undefined ? parameters.height : 50;
  45. // defaults
  46. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  47. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  48. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  49. ExtrudeBufferGeometry.call( this, shapes, parameters );
  50. this.type = 'TextBufferGeometry';
  51. }
  52. TextBufferGeometry.prototype = Object.create( ExtrudeBufferGeometry.prototype );
  53. TextBufferGeometry.prototype.constructor = TextBufferGeometry;
  54. export { TextGeometry, TextBufferGeometry };