TextGeometry.js 1.4 KB

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