TextGeometry.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * Text = 3D Text
  3. *
  4. * parameters = {
  5. * font: <THREE.Font>, // font
  6. *
  7. * size: <float>, // size of the text
  8. * height: <float>, // thickness to extrude text
  9. * curveSegments: <int>, // number of points on the curves
  10. *
  11. * bevelEnabled: <bool>, // turn on bevel
  12. * bevelThickness: <float>, // how deep into text bevel goes
  13. * bevelSize: <float>, // how far from text outline (including bevelOffset) is bevel
  14. * bevelOffset: <float> // how far from text outline does bevel start
  15. * }
  16. */
  17. import {
  18. BufferGeometry,
  19. ExtrudeGeometry
  20. } from '../../../build/three.module.js';
  21. class TextGeometry extends ExtrudeGeometry {
  22. constructor( text, parameters = {} ) {
  23. const font = parameters.font;
  24. if ( ! ( font && font.isFont ) ) {
  25. console.error( 'THREE.TextGeometry: font parameter is not an instance of THREE.Font.' );
  26. return new BufferGeometry();
  27. }
  28. const shapes = font.generateShapes( text, parameters.size );
  29. // translate parameters to ExtrudeGeometry API
  30. parameters.depth = parameters.height !== undefined ? parameters.height : 50;
  31. // defaults
  32. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  33. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  34. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  35. super( shapes, parameters );
  36. this.type = 'TextGeometry';
  37. }
  38. }
  39. export { TextGeometry };