TextGeometry.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /**
  2. * @author zz85 / http://www.lab4games.net/zz85/blog
  3. * @author alteredq / http://alteredqualia.com/
  4. *
  5. * For creating 3D text geometry in three.js
  6. *
  7. * Text = 3D Text
  8. *
  9. * parameters = {
  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. * font: <string>, // font name
  15. * weight: <string>, // font weight (normal, bold)
  16. * style: <string>, // font style (normal, italics)
  17. *
  18. * bevelEnabled: <bool>, // turn on bevel
  19. * bevelThickness: <float>, // how deep into text bevel goes
  20. * bevelSize: <float>, // how far from text outline is bevel
  21. * }
  22. *
  23. */
  24. /* Usage Examples
  25. // TextGeometry wrapper
  26. var text3d = new TextGeometry( text, options );
  27. // Complete manner
  28. var textShapes = THREE.FontUtils.generateShapes( text, options );
  29. var text3d = new ExtrudeGeometry( textShapes, options );
  30. */
  31. THREE.TextGeometry = function ( text, parameters ) {
  32. parameters = parameters || {};
  33. var textShapes = THREE.FontUtils.generateShapes( text, parameters );
  34. // translate parameters to ExtrudeGeometry API
  35. parameters.amount = parameters.height !== undefined ? parameters.height : 50;
  36. // defaults
  37. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  38. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  39. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  40. THREE.ExtrudeGeometry.call( this, textShapes, parameters );
  41. this.type = 'TextGeometry';
  42. };
  43. THREE.TextGeometry.prototype = Object.create( THREE.ExtrudeGeometry.prototype );
  44. THREE.TextGeometry.prototype.constructor = THREE.TextGeometry;