TextGeometry.js 2.0 KB

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