TextGeometry.js 1.3 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. ExtrudeGeometry
  19. } from 'three';
  20. class TextGeometry extends ExtrudeGeometry {
  21. constructor( text, parameters = {} ) {
  22. const font = parameters.font;
  23. if ( font === undefined ) {
  24. super(); // generate default extrude geometry
  25. } else {
  26. const shapes = font.generateShapes( text, parameters.size );
  27. // translate parameters to ExtrudeGeometry API
  28. parameters.depth = parameters.height !== undefined ? parameters.height : 50;
  29. // defaults
  30. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  31. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  32. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  33. super( shapes, parameters );
  34. }
  35. this.type = 'TextGeometry';
  36. }
  37. }
  38. export { TextGeometry };